Skip to content

Commit

Permalink
Chart: Negative values are not displayed when multiple value axes are…
Browse files Browse the repository at this point in the history
… synchronized to zero ( T1193670 ) (#26217)
  • Loading branch information
AlexanderMoiseev authored Dec 8, 2023
1 parent 0748b8b commit 3aa80ed
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/viz/chart_components/multi_axes_synchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,28 @@ function updateMinorTicks(axesInfo) {
});
}

function allAxesValuesOnSameSideFromZero(axesInfo) {
let allPositive = true;
let allNegative = true;

axesInfo.forEach((axis) => {
if(axis.oldMinValue > 0 || axis.oldMaxValue > 0) {
allNegative = false;
}

if(axis.oldMinValue < 0 || axis.oldMaxValue < 0) {
allPositive = false;
}
});

return allPositive || allNegative;
}

function correctPaddings(axesInfo, paddings) {
if(!allAxesValuesOnSameSideFromZero(axesInfo)) {
return paddings;
}

return axesInfo.reduce((prev, info) => {
const inverted = info.inverted;
const { start, end } = info.axis.getCorrectedValuesToZero(info.minValue, info.maxValue);
Expand Down
54 changes: 54 additions & 0 deletions testing/tests/DevExpress.viz.charts/chart.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,60 @@ QUnit.test('Chart with large scale break. No ticks in break', function(assert) {
}
});

QUnit.test('negative values should be displayed after multiple axes are synchronized to zero(T1193670)', function(assert) {
const chart = this.createChart({
commonSeriesSettings: {
argumentField: 'arg',
type: 'bar',
},
series: [{
type: 'bar',
valueField: 'val1',
}, {
type: 'spline',
valueField: 'val2',
axis: 'secondAxis',
}],
valueAxis: [{
synchronizedValue: 0,
name: 'firstAxis',
}, {
name: 'secondAxis',
position: 'right',
synchronizedValue: 0
}],
dataSource: [{
arg: 'a',
val1: 1,
val2: 1
}, {
arg: 'b',
val1: 2,
val2: 2
}, {
arg: 'c',
val1: 1,
val2: -1
}, {
arg: 'd',
val1: 3,
val2: 3
}, {
arg: 'e',
val1: 1,
val2: 1
}],
});

const firstAxis = chart.getValueAxis('firstAxis').visualRange();
const secondAxis = chart.getValueAxis('secondAxis').visualRange();

assert.strictEqual(firstAxis.startValue, -1.5);
assert.strictEqual(firstAxis.endValue, 3.5);
assert.strictEqual(secondAxis.startValue, -1.5);
assert.strictEqual(secondAxis.endValue, 3.5);
});

QUnit.test('Dispose unused axes (T1042940)', function(assert) {
this.$container.css({ width: '1000px', height: '600px' });

Expand Down

0 comments on commit 3aa80ed

Please sign in to comment.