From 67bf694a90a4c5a80fd06803c17a62800aab2624 Mon Sep 17 00:00:00 2001 From: Anton Kuznetsov Date: Fri, 15 Nov 2024 16:59:52 +0400 Subject: [PATCH] Chart: valueAxis should not restore visualRange on dataSource update (T1262610) (#28375) Co-authored-by: Alexander Kozlovskiy --- packages/devextreme/js/viz/axes/base_axis.js | 13 +++++--- .../chart.visualRangeUpdate.tests.js | 6 ++-- .../DevExpress.viz.charts/zoomAndPan.tests.js | 33 +++++++++++++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/devextreme/js/viz/axes/base_axis.js b/packages/devextreme/js/viz/axes/base_axis.js index f3bd3815797e..2d245e1614d6 100644 --- a/packages/devextreme/js/viz/axes/base_axis.js +++ b/packages/devextreme/js/viz/axes/base_axis.js @@ -1171,10 +1171,15 @@ Axis.prototype = { if(!this.isArgumentAxis) { const viewport = this.getViewport(); - if(!isDefined(viewport.startValue) && - !isDefined(viewport.endValue) && - !isDefined(viewport.length)) { - return RESET; + const isViewportNotDefined = !isDefined(viewport.startValue) && !isDefined(viewport.endValue) && !isDefined(viewport.length); + + if(isViewportNotDefined) { + const visualRange = this.visualRange(); + const isVisualRangeNotDefined = !isDefined(visualRange.startValue) && !isDefined(visualRange.endValue); + + if(isVisualRangeNotDefined) { + return RESET; + } } } diff --git a/packages/devextreme/testing/tests/DevExpress.viz.charts/chart.visualRangeUpdate.tests.js b/packages/devextreme/testing/tests/DevExpress.viz.charts/chart.visualRangeUpdate.tests.js index e071e09e60c3..d228ebc50de2 100644 --- a/packages/devextreme/testing/tests/DevExpress.viz.charts/chart.visualRangeUpdate.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.viz.charts/chart.visualRangeUpdate.tests.js @@ -2881,7 +2881,8 @@ QUnit.test('AdjustOnZoom true - show adjusted value range for every argument ran let [chart, onOptionChanged] = this.createChart({ adjustOnZoom: true, dataSource, - argumentAxis: { visualRange: [2, 4] } + argumentAxis: { visualRange: [2, 4] }, + valueAxis: { visualRangeUpdateMode: 'reset' }, }); onOptionChanged.resetHistory(); @@ -2955,7 +2956,8 @@ QUnit.test('AdjustOnZoom false - show full value range for every argument range let [chart, onOptionChanged] = this.createChart({ adjustOnZoom: false, dataSource, - argumentAxis: { visualRange: [2, 4] } + argumentAxis: { visualRange: [2, 4] }, + valueAxis: { visualRangeUpdateMode: 'reset' }, }); onOptionChanged.resetHistory(); diff --git a/packages/devextreme/testing/tests/DevExpress.viz.charts/zoomAndPan.tests.js b/packages/devextreme/testing/tests/DevExpress.viz.charts/zoomAndPan.tests.js index ee625aa6091a..65bc33c3f653 100644 --- a/packages/devextreme/testing/tests/DevExpress.viz.charts/zoomAndPan.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.viz.charts/zoomAndPan.tests.js @@ -2599,8 +2599,7 @@ QUnit.test('Pinch zoom. Big chart rendering time on start and small time in the QUnit.module('Misc', environment); -// T1049139 -QUnit.test('visualRange updating after zoomming', function(assert) { +QUnit.test('argument axis should not restore visual range on dataSource update (T1049139)', function(assert) { const dataSource = [{ arg: 1960, val: 10, }, { arg: 2020, val: 20, }]; const chart = this.createChart({ dataSource, @@ -2629,6 +2628,36 @@ QUnit.test('visualRange updating after zoomming', function(assert) { assert.strictEqual(Math.floor(visualRange.endValue), 2018); }); +QUnit.test('value axis should not restore visual range on dataSource update (T1262610)', function(assert) { + const dataSource = [{ arg: 2000, val: 10, }, { arg: 2010, val: 20, }]; + const chart = this.createChart({ + dataSource, + legend: { + visible: false, + }, + series: { type: 'bar' }, + valueAxis: { + visualRangeUpdateMode: 'keep', + visualRange: { + startValue: 5, + endValue: 25, + } + }, + zoomAndPan: { + valueAxis: 'both', + } + }); + + this.pointer.start({ x: 200, y: 250 }).wheel(10); + dataSource.push({ arg: 2020, val: 15 }); + chart.option('dataSource', dataSource); + + const visualRange = chart.getValueAxis().visualRange(); + + assert.strictEqual(Math.floor(visualRange.startValue), 6); + assert.strictEqual(Math.floor(visualRange.endValue), 24); +}); + QUnit.test('Do nothing if no actions allowed', function(assert) { const onZoomStart = sinon.spy(); const onZoomEnd = sinon.spy();