From 7edd0e68128c44267ad5e24227fc4b49dcbe6d5f Mon Sep 17 00:00:00 2001 From: kasmine <736929286@qq.com> Date: Wed, 19 Aug 2020 11:58:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(pie-statistic):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E6=96=87=E6=9C=AC=E7=B1=BB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=20&=20=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plots/pie/adaptor.ts | 23 ++++++++++++++--------- src/plots/pie/types.ts | 33 ++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/plots/pie/adaptor.ts b/src/plots/pie/adaptor.ts index 6b6188a1edd..a9b3e2249dd 100644 --- a/src/plots/pie/adaptor.ts +++ b/src/plots/pie/adaptor.ts @@ -189,7 +189,10 @@ function annotation(params: Params): Params { content: '', }; - const contentFormatter = get(content, 'formatter'); + const getStatisticData = (data: Data) => ({ + title: '总计', + value: getTotalValue(data, angleField), + }); if (title !== false) { let titleLineHeight = get(title, 'style.lineHeight'); @@ -202,10 +205,7 @@ function annotation(params: Params): Params { type: 'text', position: ['50%', '50%'], content: (filterData: Data) => { - const statisticData = { - title: '总计', - value: getTotalValue(filterData, angleField), - }; + const statisticData = getStatisticData(filterData); return titleFormatter ? titleFormatter(statisticData, filterData) : statisticData.title; }, ...deepMix( @@ -214,6 +214,9 @@ function annotation(params: Params): Params { offsetY: content === false ? 0 : -titleLineHeight, // append-info key: 'statistic', + style: { + textAlign: 'center', + }, }, title ), @@ -225,14 +228,13 @@ function annotation(params: Params): Params { if (!valueLineHeight) { valueLineHeight = get(content, 'style.fontSize', 20); } + const contentFormatter = get(content, 'formatter'); + statisticContent = { type: 'text', position: ['50%', '50%'], content: (filterData: Data) => { - const statisticData = { - title: '总计', - value: getTotalValue(filterData, angleField), - }; + const statisticData = getStatisticData(filterData); return contentFormatter ? contentFormatter(statisticData, filterData) : statisticData.value; }, ...deepMix( @@ -242,6 +244,9 @@ function annotation(params: Params): Params { offsetY: title === false ? 0 : valueLineHeight, // append-info key: 'statistic', + style: { + textAlign: 'center', + }, }, content ), diff --git a/src/plots/pie/types.ts b/src/plots/pie/types.ts index 266f50d69d0..19d29c693f5 100644 --- a/src/plots/pie/types.ts +++ b/src/plots/pie/types.ts @@ -12,22 +12,25 @@ export type StatisticData = { */ type Statistic = Readonly<{ /** 自定义 title 标签 */ - title?: { - formatter?: (item: StatisticData, data: LooseObject | LooseObject[]) => string; - rotate?: number; - offsetX?: number; - offsetY?: number; - style?: ShapeStyle; - }; + title?: + | boolean + | { + formatter?: (item: StatisticData, data: LooseObject | LooseObject[]) => string; + rotate?: number; + offsetX?: number; + offsetY?: number; + style?: ShapeStyle; + }; /** 自定义 content 内容 */ - content?: { - formatter?: (item: StatisticData, data: LooseObject | LooseObject[]) => string; - rotate?: number; - offsetX?: number; - offsetY?: number; - style?: ShapeStyle; - }; - // todo 提供 htmlContent 的方式,自由定制中心文本 + content?: + | boolean + | { + formatter?: (item: StatisticData, data: LooseObject | LooseObject[]) => string; + rotate?: number; + offsetX?: number; + offsetY?: number; + style?: ShapeStyle; + }; }>; export interface PieOptions extends Options {