diff --git a/src/component/dataZoom/AxisProxy.ts b/src/component/dataZoom/AxisProxy.ts index 11d5f6c742..f4c8138cd1 100644 --- a/src/component/dataZoom/AxisProxy.ts +++ b/src/component/dataZoom/AxisProxy.ts @@ -27,7 +27,7 @@ import { Dictionary } from '../../util/types'; // TODO Polar? import DataZoomModel from './DataZoomModel'; import { AxisBaseModel } from '../../coord/AxisBaseModel'; -import { unionAxisExtentFromData } from '../../coord/axisHelper'; +import { getDataDimensionsOnAxis, unionAxisExtentFromData } from '../../coord/axisHelper'; import { ensureScaleRawExtentInfo } from '../../coord/scaleRawExtentInfo'; import { getAxisMainType, isCoordSupported, DataZoomAxisDimension } from './helper'; import { SINGLE_REFERRING } from '../../util/model'; @@ -297,7 +297,9 @@ class AxisProxy { each(seriesModels, function (seriesModel) { let seriesData = seriesModel.getData(); - const dataDims = seriesData.mapDimensionsAll(axisDim); + // Use the same dimensions as axis extent calculation. Stacked series + // are rendered by their stack result dimension, not the original value dimension. + const dataDims = getDataDimensionsOnAxis(seriesData, axisDim); if (!dataDims.length) { return; diff --git a/test/toolbox-dataZoom-stack-area.html b/test/toolbox-dataZoom-stack-area.html new file mode 100644 index 0000000000..f7f70b30a6 --- /dev/null +++ b/test/toolbox-dataZoom-stack-area.html @@ -0,0 +1,137 @@ + + + +
+ + + + + + + + + + + diff --git a/test/ut/spec/component/dataZoom/AxisProxy.test.ts b/test/ut/spec/component/dataZoom/AxisProxy.test.ts new file mode 100644 index 0000000000..2c0d03ed17 --- /dev/null +++ b/test/ut/spec/component/dataZoom/AxisProxy.test.ts @@ -0,0 +1,121 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import { createChart, getECModel } from '../../../core/utHelper'; +import { EChartsType } from '../../../../../src/echarts'; + + +describe('dataZoom/AxisProxy', function () { + + let chart: EChartsType; + beforeEach(function () { + chart = createChart(); + }); + + afterEach(function () { + chart.dispose(); + }); + + function setToolboxStackedLineOption(filterMode?: 'filter' | 'weakFilter' | 'empty') { + chart.setOption({ + toolbox: { + feature: { + dataZoom: filterMode + ? {filterMode: filterMode} + : {} + } + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: ['Mon', 'Tue', 'Wed'] + }, + yAxis: { + scale: true + }, + series: [{ + type: 'line', + stack: 'total', + data: [100, 100, 100] + }, { + type: 'line', + stack: 'total', + areaStyle: {}, + data: [1, 2, 3] + }] + }); + } + + it('keeps stacked line data when toolbox dataZoom injects value-axis filtering', function () { + setToolboxStackedLineOption(); + + const data = getECModel(chart).getSeriesByIndex(1).getData(); + const stackResultDim = data.getCalculationInfo('stackResultDimension'); + expect(data.count()).toEqual(3); + expect(data.get(stackResultDim, 0)).toEqual(101); + }); + + it('keeps stacked line data when toolbox dataZoom uses weakFilter', function () { + setToolboxStackedLineOption('weakFilter'); + + const data = getECModel(chart).getSeriesByIndex(1).getData(); + const stackResultDim = data.getCalculationInfo('stackResultDimension'); + expect(data.count()).toEqual(3); + expect(data.get(stackResultDim, 0)).toEqual(101); + }); + + it('empties stacked line data by stack result dimension', function () { + chart.setOption({ + xAxis: { + type: 'category', + boundaryGap: false, + data: ['Mon', 'Tue', 'Wed'] + }, + yAxis: { + scale: true + }, + dataZoom: { + yAxisIndex: 0, + filterMode: 'empty', + startValue: 102, + endValue: 103 + }, + series: [{ + type: 'line', + stack: 'total', + data: [100, 100, 100] + }, { + type: 'line', + stack: 'total', + areaStyle: {}, + data: [1, 2, 3] + }] + }); + + const data = getECModel(chart).getSeriesByIndex(1).getData(); + const stackResultDim = data.getCalculationInfo('stackResultDimension'); + expect(data.count()).toEqual(3); + expect(isNaN(data.get(stackResultDim, 0) as number)).toEqual(true); + expect(data.get(stackResultDim, 1)).toEqual(102); + expect(data.get(stackResultDim, 2)).toEqual(103); + expect(data.get('y', 1)).toEqual(2); + expect(data.get('y', 2)).toEqual(3); + }); + +});