Skip to content

Commit

Permalink
feat: add transformRatioLocale config for transformRatio text in fu…
Browse files Browse the repository at this point in the history
…nnel tooltip, #3704
  • Loading branch information
xiaoluoHe committed Feb 19, 2025
1 parent 3a09d67 commit d0222b2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "feat: add `transformRatioLocale` config for transformRatio text in funnel tooltip, #3704",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
4 changes: 4 additions & 0 deletions docs/assets/option/en/series/funnel.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ Min length of guide line. Default is 20px. Supported since version `1.12.7`
###${prefix} state(Object)

{{ use: mark-state-style() }}

#${prefix} transformRatioLocale(String)

Supported since version `1.13.6`, the built-in tooltip text for the funnel chart conversion layer is set to "Conversion Rate" by default in Chinese.
4 changes: 4 additions & 0 deletions docs/assets/option/zh/series/funnel.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@
###${prefix} state(Object)

{{ use: mark-state-style() }}

#${prefix} transformRatioLocale(String)

`1.13.6`版本支持,漏斗图转化层的 tooltip 内置文案,默认为“转化率”中文。
3 changes: 2 additions & 1 deletion packages/vchart/src/chart/funnel/funnel-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class FunnelChartSpecTransformer<T extends IFunnelChartSpec> extends Base
'minSize',
'gap',
'isCone',
'range'
'range',
'transformRatioLocale'
]);

return series;
Expand Down
6 changes: 6 additions & 0 deletions packages/vchart/src/series/funnel/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export interface IFunnelSeriesSpec extends ISeriesSpec, IAnimationSpec<FunnelMar
* @since 1.10.1
*/
heightRatio?: number;
/**
* 漏斗图转化率文案,用于转化层 tooltip key 的显示内容
* @since 1.13.5
* @default '转化率'
* */
transformRatioLocale?: string;
/**
* 漏斗层样式
*/
Expand Down
13 changes: 9 additions & 4 deletions packages/vchart/src/series/funnel/tooltip-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import type { TooltipHandlerParams } from '../../component/tooltip/interface';
import type { Datum } from '@visactor/vgrammar-core';

export class FunnelSeriesTooltipHelper extends BaseSeriesTooltipHelper implements ISeriesTooltipHelper {
private _transformRatioLocale;

constructor(series: IFunnelSeries) {
super(series);
this._transformRatioLocale = series.getSpec()?.transformRatioLocale ?? `转化率`;
}

dimensionTooltipTitleCallback = (datum: Datum, params?: TooltipHandlerParams) => {
const series = this.series as IFunnelSeries;
if (params?.mark?.name === SeriesMarkNameEnum.transform) {
// TODO: i18n
return `转化率`;
return this._transformRatioLocale;
}
return this._getDimensionData(datum) ?? datum.properties?.[`${series.getCategoryField()}`];
};
Expand All @@ -26,8 +32,7 @@ export class FunnelSeriesTooltipHelper extends BaseSeriesTooltipHelper implement

markTooltipKeyCallback = (datum: Datum, params?: TooltipHandlerParams) => {
if (params?.mark?.name === SeriesMarkNameEnum.transform) {
// TODO: i18n
return `转化率`;
return this._transformRatioLocale;
}
const { dimensionFields, seriesFields } = this._seriesCacheInfo;
const subDimensionField = dimensionFields[dimensionFields.length - 1];
Expand Down

0 comments on commit d0222b2

Please sign in to comment.