diff --git a/js/viz/chart_components/multi_axes_synchronizer.js b/js/viz/chart_components/multi_axes_synchronizer.js index ceac4cbdc7ae..0bf6d3ccb6d6 100644 --- a/js/viz/chart_components/multi_axes_synchronizer.js +++ b/js/viz/chart_components/multi_axes_synchronizer.js @@ -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); diff --git a/testing/tests/DevExpress.viz.charts/chart.integration.tests.js b/testing/tests/DevExpress.viz.charts/chart.integration.tests.js index 9a1e2c807cdb..0fd7ad885584 100644 --- a/testing/tests/DevExpress.viz.charts/chart.integration.tests.js +++ b/testing/tests/DevExpress.viz.charts/chart.integration.tests.js @@ -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' });