This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch PR/plainheart_fix/alignTicks-precision in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 18bedbb5a8f1f71784cb0b31e1eaed27e0595204 Author: 100pah <[email protected]> AuthorDate: Fri Mar 6 21:16:17 2026 +0800 fix: Temporarily fix incorrect stack base dimension selection when both axes are value axes. --- src/chart/helper/createSeriesData.ts | 4 +- src/coord/CoordinateSystem.ts | 3 +- src/coord/cartesian/Cartesian2D.ts | 10 +++- src/data/helper/dataStackHelper.ts | 23 +++++++- src/model/referHelper.ts | 8 +-- test/bar-polar-multi-series-radial.html | 6 +- test/bar-stack.html | 98 +++++++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+), 15 deletions(-) diff --git a/src/chart/helper/createSeriesData.ts b/src/chart/helper/createSeriesData.ts index a15490643..7ee0f5539 100644 --- a/src/chart/helper/createSeriesData.ts +++ b/src/chart/helper/createSeriesData.ts @@ -23,7 +23,7 @@ import prepareSeriesDataSchema from '../../data/helper/createDimensions'; import {getDimensionTypeByAxis} from '../../data/helper/dimensionHelper'; import {getDataItemValue} from '../../util/model'; import CoordinateSystem from '../../core/CoordinateSystem'; -import {getCoordSysInfoBySeries} from '../../model/referHelper'; +import {getCoordSysInfoBySeries, SeriesModelCoordSysInfo} from '../../model/referHelper'; import { createSourceFromSeriesDataOption, Source } from '../../data/Source'; import {enableDataStack} from '../../data/helper/dataStackHelper'; import {makeSeriesEncodeForAxisCoordSys} from '../../data/helper/sourceHelper'; @@ -40,7 +40,7 @@ import SeriesDimensionDefine from '../../data/SeriesDimensionDefine'; function getCoordSysDimDefs( seriesModel: SeriesModel, - coordSysInfo: ReturnType<typeof getCoordSysInfoBySeries> + coordSysInfo: SeriesModelCoordSysInfo ) { const coordSysName = seriesModel.get('coordinateSystem'); const registeredCoordSys = CoordinateSystem.get(coordSysName); diff --git a/src/coord/CoordinateSystem.ts b/src/coord/CoordinateSystem.ts index c5e825308..9a444e60c 100644 --- a/src/coord/CoordinateSystem.ts +++ b/src/coord/CoordinateSystem.ts @@ -190,8 +190,7 @@ export interface CoordinateSystem { getAxis?: (dim?: DimensionName) => Axis; /** - * FIXME: It may introduce inconsistency with `Series['getBaseAxis']`. - * `CoordinateSystem['getBaseAxis']` probably should not exist. + * FIXME: Remove this method? See details in `Cartesian2D['getBaseAxis']` */ getBaseAxis?: () => Axis; diff --git a/src/coord/cartesian/Cartesian2D.ts b/src/coord/cartesian/Cartesian2D.ts index 071f83b4d..2636e40e2 100644 --- a/src/coord/cartesian/Cartesian2D.ts +++ b/src/coord/cartesian/Cartesian2D.ts @@ -91,8 +91,14 @@ class Cartesian2D extends Cartesian<Axis2D> implements CoordinateSystem { * Base axis will be used on stacking and series such as 'bar', 'pictorialBar', etc. */ getBaseAxis(): Axis2D { - // PENGING: Should we allow bar series to specify a base axis when - // both axes are type "value", rather than force to xAxis? + // FIXME: + // (1) We should allow series (e.g., bar) to specify a base axis when + // both axes are type "value", rather than force to xAxis or angleAxis. + // NOTE: At present BoxplotSeries has its own overide `getBaseAxis`. + // `CoordinateSystem['getBaseAxis']` probably should not exist, since it + // may introduce inconsistency with `Series['getBaseAxis']`. + // (2) "base axis" info is required in "createSeriesData" stage for "stack", + // (see `dataStackHelper.ts` for details). Currently it is hard coded there. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x'); diff --git a/src/data/helper/dataStackHelper.ts b/src/data/helper/dataStackHelper.ts index f10f7af1d..206d47fc4 100644 --- a/src/data/helper/dataStackHelper.ts +++ b/src/data/helper/dataStackHelper.ts @@ -93,6 +93,11 @@ export function enableDataStack( let stackedDimInfo: SeriesDimensionDefine; let stackResultDimension: string; let stackedOverDimension: string; + let allDimTypesAreNotOrdinalAndTime = true; + + function dimTypeIsNotOrdinalAndTime(dimensionInfo: SeriesDimensionDefine): boolean { + return dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time'; + } each(dimensionDefineList, function (dimensionInfo, index) { if (isString(dimensionInfo)) { @@ -100,7 +105,12 @@ export function enableDataStack( name: dimensionInfo as string } as SeriesDimensionDefine; } + if (!dimTypeIsNotOrdinalAndTime(dimensionInfo)) { + allDimTypesAreNotOrdinalAndTime = false; + } + }); + each(dimensionDefineList, function (dimensionInfo: SeriesDimensionDefine, index) { if (mayStack && !dimensionInfo.isExtraCoord) { // Find the first ordinal dimension as the stackedByDimInfo. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) { @@ -108,8 +118,17 @@ export function enableDataStack( } // Find the first stackable dimension as the stackedDimInfo. if (!stackedDimInfo - && dimensionInfo.type !== 'ordinal' - && dimensionInfo.type !== 'time' + && dimTypeIsNotOrdinalAndTime(dimensionInfo) + // FIXME: + // This rule MUST be consistent with `Cartesian2D['getBaseAxis']` and `Polar['getBaseAxis']` + // Need refactor - merge them! + // See comments in `Cartesian2D['getBaseAxis']` for details. + && (!allDimTypesAreNotOrdinalAndTime + || ( + dimensionInfo.coordDim !== 'x' + && dimensionInfo.coordDim !== 'angle' + ) + ) && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim) ) { stackedDimInfo = dimensionInfo; diff --git a/src/model/referHelper.ts b/src/model/referHelper.ts index e9010a983..c612c5eb6 100644 --- a/src/model/referHelper.ts +++ b/src/model/referHelper.ts @@ -61,7 +61,7 @@ import { AxisModelExtendedInCreator } from '../coord/axisModelCreator'; * } */ -class CoordSysInfo { +export class SeriesModelCoordSysInfo { coordSysName: string; @@ -84,14 +84,14 @@ type FetcherAxisModel = & Pick<AxisModelExtendedInCreator, 'getOrdinalMeta'>; type Fetcher = ( seriesModel: SeriesModel, - result: CoordSysInfo, + result: SeriesModelCoordSysInfo, axisMap: HashMap<FetcherAxisModel>, categoryAxisMap: HashMap<FetcherAxisModel> ) => void; -export function getCoordSysInfoBySeries(seriesModel: SeriesModel) { +export function getCoordSysInfoBySeries(seriesModel: SeriesModel): SeriesModelCoordSysInfo { const coordSysName = seriesModel.get('coordinateSystem') as SupportedCoordSys; - const result = new CoordSysInfo(coordSysName); + const result = new SeriesModelCoordSysInfo(coordSysName); const fetch = fetchers[coordSysName]; if (fetch) { fetch(seriesModel, result, result.axisMap, result.categoryAxisMap); diff --git a/test/bar-polar-multi-series-radial.html b/test/bar-polar-multi-series-radial.html index ec2bbb00d..5185b2551 100644 --- a/test/bar-polar-multi-series-radial.html +++ b/test/bar-polar-multi-series-radial.html @@ -34,7 +34,7 @@ under the License. </style> - <div id="main_multiple_bar_category_angle_axis"></div> + <!-- <div id="main_multiple_bar_category_angle_axis"></div> --> <div id="main_multiple_bar_value_angle_axis"></div> @@ -86,7 +86,7 @@ under the License. height: 500, }); - chart.on('click', function (params) { + chart && chart.on('click', function (params) { console.log(params); }); }); @@ -213,7 +213,7 @@ under the License. }] }); - chart.on('click', function (params) { + chart && chart.on('click', function (params) { console.log(params); }); }); diff --git a/test/bar-stack.html b/test/bar-stack.html index 51ce177f2..09d278098 100644 --- a/test/bar-stack.html +++ b/test/bar-stack.html @@ -39,6 +39,7 @@ under the License. <div id="main2_source_format_original"></div> <div id="main2_dataset"></div> <div id="main3"></div> + <div id="main_bar_stack_on_value_or_time_axis"></div> @@ -725,6 +726,103 @@ under the License. + <script> + + require([ + 'echarts', + // 'data/flight.json' + // 'theme/dark.js', // auto register if load. + ], function (echarts /*, data */) { + var _ctx = { + stack: true, + xAxisType: 'value', + }; + + function createOption() { + var option = { + xAxis: { + type: _ctx.xAxisType, + }, + yAxis: { + }, + legend: { + top: 5, + }, + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'shadow', + } + }, + series: [{ + type: 'bar', + name: 'A', + symbolSize: 50, + itemStyle: {barBorderRadius: 3}, + label: {show: true, position: 'top'}, + data: [[1, 200], [100, 400], [500, 150]] + }, { + type: 'bar', + name: 'B', + symbolSize: 50, + itemStyle: {barBorderRadius: 3}, + label: {show: true, position: 'top'}, + data: [[1, 200], [100, 200], [500, 50]] + }, { + type: 'bar', + name: 'C', + symbolSize: 50, + itemStyle: {barBorderRadius: 3}, + label: {show: true, position: 'top'}, + data: [[1, 200], [100, 300], [500, 100]] + }] + }; + if (_ctx.stack) { + option.series.forEach(function (item) { + item.stack = 'a'; + }); + } + + return option; + } + + function updateChart() { + chart.setOption(createOption(), {notMerge: true}); + } + + var chart = testHelper.create(echarts, 'main_bar_stack_on_value_or_time_axis', { + title: [ + 'bar stack on value/time axis', + ], + option: createOption(), + + inputsStyle: 'compact', + inputs: [{ + type: 'select', + text: 'stack:', + values: [true, false], + onchange() { + _ctx.stack = this.value; + updateChart(); + } + }, { + type: 'select', + text: 'xAxisType:', + values: [_ctx.xAxisType, 'time'], + onchange() { + _ctx.xAxisType = this.value; + updateChart(); + } + }] + + }); // End of `testHelper.create` + + }); // End of `require` + </script> + + + + </body> </html> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
