Skip to content

Commit

Permalink
Fixed #18110, maxPadding was ingored when softMin set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Januchta authored and TorsteinHonsi committed May 12, 2023
1 parent 48a3742 commit 6481ca2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
34 changes: 34 additions & 0 deletions samples/unit-tests/axis/softmin-softmax/demo.js
Expand Up @@ -45,6 +45,40 @@ QUnit.test('softMin and softMax', function (assert) {
chart.series[0].setData([-100, -101, -102]);

assert.strictEqual(chart.yAxis[0].max, 100, 'Soft max should be respected');

let { min, max } = chart.yAxis[0];
let diff = max - min;

chart.yAxis[0].update({
softMin: undefined,
minPadding: 0.5
});

assert.strictEqual(
chart.yAxis[0].min,
min - diff / 2,
'Min padding should be added when when soft max set, #18110'
);

chart.yAxis[0].update({
softMin: -200,
softMax: undefined
});

min = chart.yAxis[0].min;
max = chart.yAxis[0].max;
diff = max - min;

chart.yAxis[0].update({
minPadding: 0,
maxPadding: 0.5
});

assert.strictEqual(
chart.yAxis[0].max,
max + diff / 2,
'Max padding should be added when when soft min set, #18110'
);
});

QUnit.test('softMax combined with ceiling (#6359)', function (assert) {
Expand Down
39 changes: 20 additions & 19 deletions ts/Core/Axis/Axis.ts
Expand Up @@ -1726,6 +1726,22 @@ class Axis {
// adjust min and max for the minimum range
axis.adjustForMinRange();

// Handle options for floor, ceiling, softMin and softMax (#6359)
if (!isNumber(axis.userMin)) {
if (
isNumber(options.softMin) && options.softMin < (axis.min as any)
) {
axis.min = hardMin = options.softMin; // #6894
}
}
if (!isNumber(axis.userMax)) {
if (
isNumber(options.softMax) && options.softMax > (axis.max as any)
) {
axis.max = hardMax = options.softMax; // #6894
}
}

// Pad the values to get clear of the chart's edges. To avoid
// tickInterval taking the padding into account, we do this after
// computing tick interval (#1337).
Expand All @@ -1748,26 +1764,11 @@ class Axis {
}
}

// Handle options for floor, ceiling, softMin and softMax (#6359)
if (!isNumber(axis.userMin)) {
if (
isNumber(options.softMin) && options.softMin < (axis.min as any)
) {
axis.min = hardMin = options.softMin; // #6894
}
if (isNumber(options.floor)) {
axis.min = Math.max(axis.min as any, options.floor);
}
if (!isNumber(axis.userMin) && isNumber(options.floor)) {
axis.min = Math.max(axis.min as any, options.floor);
}
if (!isNumber(axis.userMax)) {
if (
isNumber(options.softMax) && options.softMax > (axis.max as any)
) {
axis.max = hardMax = options.softMax; // #6894
}
if (isNumber(options.ceiling)) {
axis.max = Math.min(axis.max as any, options.ceiling);
}
if (!isNumber(axis.userMax) && isNumber(options.ceiling)) {
axis.max = Math.min(axis.max as any, options.ceiling);
}

// When the threshold is soft, adjust the extreme value only if the data
Expand Down

0 comments on commit 6481ca2

Please sign in to comment.