Skip to content

Commit 9dad6d3

Browse files
Chart: fix set visualRangeUpdateMode (T1315301) (24_2) (#31931)
1 parent ce65168 commit 9dad6d3

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

packages/devextreme/js/__internal/viz/chart_components/m_advanced_chart.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ export const AdvancedChart = BaseChart.inherit({
711711

712712
index = _isDefined(index) ? parseInt(index[0], 10) : index;
713713

714-
if (fullName.indexOf('visualRange') > 0) {
714+
if (fullName.split('.').indexOf('visualRange') > 0) {
715715
if (type(value) !== 'object') {
716716
value = wrapVisualRange(fullName, value) ?? value;
717717
}
@@ -832,16 +832,17 @@ export const AdvancedChart = BaseChart.inherit({
832832
_optionChanged(arg) {
833833
if (!this._optionChangedLocker) {
834834
const optionName = 'visualRange';
835-
let axes;
836-
const isDirectOption = arg.fullName.indexOf(optionName) > 0 ? true
835+
const isDirectOption = arg.fullName.split('.').indexOf(optionName) > 0 ? true
837836
: this.getPartialChangeOptionsName(arg).indexOf(optionName) > -1 ? false : undefined;
838837

839838
if (_isDefined(isDirectOption)) {
840-
axes = this._getAxesByOptionPath(arg, isDirectOption, optionName);
839+
const axes: (typeof Axis)[] = this._getAxesByOptionPath(arg, isDirectOption, optionName);
841840

842841
if (axes) {
843842
if (axes.length > 1 || isArray(arg.value)) {
844-
axes.forEach((a, index) => setAxisVisualRangeByOption(arg, a, isDirectOption, index));
843+
axes.forEach((a, index: number) => {
844+
setAxisVisualRangeByOption(arg, a, isDirectOption, index);
845+
});
845846
} else if (axes.length === 1) {
846847
setAxisVisualRangeByOption(arg, axes[0], isDirectOption);
847848
}

packages/devextreme/testing/tests/DevExpress.viz.charts/chart.integration.tests.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,53 @@ QUnit.test('Set the visualRange option by the different ways', function(assert)
10311031
assert.deepEqual(chart.option('valueAxis._customVisualRange'), { length: 2 });
10321032
});
10331033

1034+
QUnit.test('visualRangeUpdateMode change should not corrupt _customVisualRange causing incorrect visualRange on subsequent axis rerender (T1315301)', function(assert) {
1035+
this.$container.css({ width: '1000px', height: '600px' });
1036+
const dataSource = [{
1037+
arg: 1,
1038+
val: 4
1039+
}, {
1040+
arg: 2,
1041+
val: 5
1042+
}, {
1043+
arg: 5,
1044+
val: 7
1045+
}, {
1046+
arg: 8,
1047+
val: 3
1048+
}, {
1049+
arg: 11,
1050+
val: 8
1051+
}];
1052+
1053+
const chart = this.createChart({
1054+
size: {
1055+
width: 1000,
1056+
height: 600
1057+
},
1058+
dataSource: dataSource,
1059+
series: { type: 'bar' },
1060+
valueAxis: {
1061+
visualRangeUpdateMode: 'auto',
1062+
}
1063+
});
1064+
1065+
const initialVisualRange = chart.option('valueAxis.visualRange');
1066+
1067+
chart.option('valueAxis.visualRangeUpdateMode', 'keep');
1068+
1069+
assert.strictEqual(chart.option('valueAxis.visualRangeUpdateMode'), 'keep', 'visualRangeUpdateMode has changed to "keep"');
1070+
assert.deepEqual(chart.option('valueAxis.visualRange'), initialVisualRange, 'visualRange remains unchanged');
1071+
assert.deepEqual(chart.option('valueAxis._customVisualRange'), undefined, '_customVisualRange not set');
1072+
1073+
chart.option('commonAxisSettings.title', 'custom');
1074+
1075+
assert.strictEqual(chart.option('valueAxis.visualRangeUpdateMode'), 'keep', 'visualRangeUpdateMode is still "keep" after rerender');
1076+
assert.strictEqual(chart.option('commonAxisSettings.title'), 'custom', 'commonAxisSettings.title was successfully changed');
1077+
assert.deepEqual(chart.option('valueAxis.visualRange'), initialVisualRange, 'visualRange remains correct after axis rerender');
1078+
assert.deepEqual(chart.option('valueAxis._customVisualRange'), undefined, '_customVisualRange not set');
1079+
});
1080+
10341081
QUnit.test('Reload dataSource - visualRange option should be changed', function(assert) {
10351082
this.$container.css({ width: '1000px', height: '600px' });
10361083
const visualRangeChanged = sinon.spy();

0 commit comments

Comments
 (0)