Skip to content

Commit ef3c181

Browse files
committed
pass percent value in series label params
1 parent 77c288c commit ef3c181

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

src/component/tooltip/seriesFormatTooltip.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export function defaultSeriesFormatTooltip(opt: {
7676
// this series gives its individual contribution.
7777
if (!isNaN(stackTop) && !isNaN(stackBottom)) {
7878
const percentValue = stackTop - stackBottom;
79-
inlineValue = `${inlineValue} (${percentValue.toFixed(1)}%)`;
79+
const formattedPercentValue = `${Number.parseFloat(percentValue.toFixed(2))}%`;
80+
inlineValue = `${inlineValue} (${formattedPercentValue})`;
8081
}
8182
}
8283
}

src/model/mixin/dataFormat.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class DataFormatMixin {
7272
const isSeries = mainType === 'series';
7373
const userOutput = data.userOutput && data.userOutput.get();
7474

75-
return {
75+
const params: CallbackDataParams = {
7676
componentType: mainType,
7777
componentSubType: this.subType,
7878
componentIndex: this.componentIndex,
@@ -93,6 +93,20 @@ export class DataFormatMixin {
9393
// Param name list for mapping `a`, `b`, `c`, `d`, `e`
9494
$vars: ['seriesName', 'name', 'value']
9595
};
96+
97+
const isPercentStackEnabled = data.getCalculationInfo('isPercentStackEnabled');
98+
if (isPercentStackEnabled) {
99+
// Include the normalized value when stackPercent is true.
100+
const stackResultDim = data.getCalculationInfo('stackResultDimension');
101+
const stackedOverDim = data.getCalculationInfo('stackedOverDimension');
102+
const stackTop = data.get(stackResultDim, dataIndex) as number;
103+
const stackBottom = data.get(stackedOverDim, dataIndex) as number;
104+
if (!isNaN(stackTop) && !isNaN(stackBottom)) {
105+
const fullPercentValue = stackTop - stackBottom;
106+
params.percent = Math.round(fullPercentValue * 100) / 100;
107+
}
108+
}
109+
return params;
96110
}
97111

98112
/**

src/util/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,4 +1093,4 @@ export function interpolateRawValues(
10931093
}
10941094
return interpolated;
10951095
}
1096-
}
1096+
}

src/util/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ export interface CallbackDataParams {
702702
marker?: TooltipMarker;
703703
status?: DisplayState;
704704
dimensionIndex?: number;
705-
percent?: number; // Only for chart like 'pie'
705+
percent?: number; // Only for chart like 'pie' or when 'stackPercent' is used.
706706

707707
// Param name list for mapping `a`, `b`, `c`, `d`, `e`
708708
$vars: string[];

test/percent-stack.html

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

0 commit comments

Comments
 (0)