From ddcf2bc711f5245354745e5b9a02a2e2609bf2ce Mon Sep 17 00:00:00 2001 From: AlexanderMoiseev Date: Fri, 8 Dec 2023 20:07:11 +0400 Subject: [PATCH] Chart: Negative values are not displayed when multiple value axes are synchronized to zero ( T1193670 ) (#26193) --- .../multi_axes_synchronizer.js | 21 ++++++++ .../chart.integration.tests.js | 54 +++++++++++++++++++ 2 files changed, 75 insertions(+) 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 1a90761fcb41..508708535690 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' });