Skip to content

Commit 5387835

Browse files
committed
change to stackPercent boolean instead of stackStrategy percent
1 parent d733bc4 commit 5387835

File tree

8 files changed

+45
-49
lines changed

8 files changed

+45
-49
lines changed

src/component/tooltip/seriesFormatTooltip.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
TooltipMarkupSection
2828
} from './tooltipMarkup';
2929
import { retrieveRawValue } from '../../data/helper/dataProvider';
30-
import { isNameSpecified, getStackStrategy } from '../../util/model';
30+
import { isNameSpecified } from '../../util/model';
3131

3232

3333
export function defaultSeriesFormatTooltip(opt: {
@@ -65,9 +65,9 @@ export function defaultSeriesFormatTooltip(opt: {
6565
const dimInfo = data.getDimensionInfo(tooltipDims[0]);
6666
sortParam = inlineValue = retrieveRawValue(data, dataIndex, tooltipDims[0]);
6767
inlineValueType = dimInfo.type;
68-
const stackStrategy = getStackStrategy(series);
69-
if (stackStrategy === 'percent') {
70-
// Append the normalized value (as a percent of the total stack) when 'percent' stackStrategy is used.
68+
const isPercentStackEnabled = data.getCalculationInfo('isPercentStackEnabled');
69+
if (isPercentStackEnabled) {
70+
// Append the normalized value (as a percent of the total stack) when stackPercent is true.
7171
const stackResultDim = data.getCalculationInfo('stackResultDimension');
7272
const stackedOverDim = data.getCalculationInfo('stackedOverDimension');
7373
const stackTop = data.get(stackResultDim, dataIndex) as number;

src/data/SeriesData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export interface DataCalculationInfo<SERIES_MODEL> {
135135
stackedOverDimension: DimensionName;
136136
stackResultDimension: DimensionName;
137137
stackedOnSeries?: SERIES_MODEL;
138+
isPercentStackEnabled?: boolean;
138139
}
139140

140141
// -----------------------------

src/data/helper/dataStackHelper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function enableDataStack(
6969
| 'isStackedByIndex'
7070
| 'stackedOverDimension'
7171
| 'stackResultDimension'
72+
| 'isPercentStackEnabled'
7273
> {
7374
opt = opt || {};
7475
let byIndex = opt.byIndex;
@@ -192,7 +193,8 @@ export function enableDataStack(
192193
stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
193194
isStackedByIndex: byIndex,
194195
stackedOverDimension: stackedOverDimension,
195-
stackResultDimension: stackResultDimension
196+
stackResultDimension: stackResultDimension,
197+
isPercentStackEnabled: seriesModel.get('stackPercent'),
196198
};
197199
}
198200

src/layout/barGrid.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,13 @@ export function createProgressiveLayout(seriesType: string): StageHandler {
487487
const isLarge = isInLargeMode(seriesModel);
488488
const barMinHeight = seriesModel.get('barMinHeight') || 0;
489489

490-
// Determine stacked dimensions and account for stackStrategy.
490+
// Determine stacked dimensions.
491491
const stackResultDim = data.getCalculationInfo('stackResultDimension');
492492
const stackedDimIdx = stackResultDim && data.getDimensionIndex(stackResultDim);
493493
const stackedOverDim = data.getCalculationInfo('stackedOverDimension');
494494
const stackedOverDimIdx = stackedOverDim && data.getDimensionIndex(stackedOverDim);
495-
const stackStrategy = seriesModel.get('stackStrategy');
496-
const isPercentStack = stackStrategy === 'percent';
497-
const stacked = isPercentStack
495+
const isPercentStackEnabled = seriesModel.get('stackPercent');
496+
const stacked = isPercentStackEnabled
498497
|| (isDimensionStacked(data, valueDim) && !!data.getCalculationInfo('stackedOnSeries'));
499498

500499
// Layout info.
@@ -524,13 +523,13 @@ export function createProgressiveLayout(seriesType: string): StageHandler {
524523
// Because of the barMinHeight, we can not use the value in
525524
// stackResultDimension directly.
526525
if (stacked) {
527-
if (isPercentStack) {
528-
// For 'percent' stackStrategy, use the normalized bottom edge (stackedOverDimension)
526+
if (isPercentStackEnabled) {
527+
// When percentStack is true, use the normalized bottom edge (stackedOverDimension)
529528
// as the start value of the bar segment.
530529
stackStartValue = store.get(stackedOverDimIdx, dataIndex);
531530
}
532531
else {
533-
// For standard (non-percent) stackStrategy, subtract the original value from the
532+
// For standard (non-percent) stack, subtract the original value from the
534533
// stacked total to compute the bar segment's start value.
535534
stackStartValue = +value - (store.get(valueDimIdx, dataIndex) as number);
536535
}

src/processor/dataStack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export default function dataStack(ecModel: GlobalModel) {
6666
});
6767

6868
stackInfoMap.each(function (stackInfoList) {
69-
const isPercentStack = stackInfoList.some((info) => info.seriesModel.get('stackStrategy') === 'percent');
70-
if (isPercentStack) {
69+
const isPercentStackEnabled = stackInfoList.some((info) => info.seriesModel.get('stackPercent'));
70+
if (isPercentStackEnabled) {
7171
calculatePercentStack(stackInfoList);
7272
}
7373
else {

src/util/model.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ import {
4545
Payload,
4646
OptionId,
4747
OptionName,
48-
InterpolatableValue,
49-
SeriesStackOptionMixin
48+
InterpolatableValue
5049
} from './types';
5150
import { Dictionary } from 'zrender/src/core/types';
5251
import SeriesModel from '../model/Series';
@@ -1094,8 +1093,4 @@ export function interpolateRawValues(
10941093
}
10951094
return interpolated;
10961095
}
1097-
}
1098-
1099-
export function getStackStrategy(series: SeriesModel): SeriesStackOptionMixin['stackStrategy'] | undefined {
1100-
return (series.get as (path: string) => unknown)('stackStrategy') as SeriesStackOptionMixin['stackStrategy'];
1101-
}
1096+
}

src/util/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,8 @@ export interface SeriesLargeOptionMixin {
16781678
}
16791679
export interface SeriesStackOptionMixin {
16801680
stack?: string
1681-
stackStrategy?: 'samesign' | 'all' | 'positive' | 'negative' | 'percent';
1681+
stackStrategy?: 'samesign' | 'all' | 'positive' | 'negative';
1682+
stackPercent?: boolean;
16821683
}
16831684

16841685
export type StackInfo = Pick<
@@ -1688,6 +1689,7 @@ export type StackInfo = Pick<
16881689
| 'stackedByDimension'
16891690
| 'stackResultDimension'
16901691
| 'stackedOverDimension'
1692+
| 'isPercentStackEnabled'
16911693
> & {
16921694
data: SeriesData
16931695
seriesModel: SeriesModel<SeriesOption & SeriesStackOptionMixin>

test/percent-stack.html

Lines changed: 24 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)