Skip to content

Commit

Permalink
fix(pie-statistic): 修复中心文本类型定义 & 样式问题
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Aug 19, 2020
1 parent b4dc4fe commit 7edd0e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
23 changes: 14 additions & 9 deletions src/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
content: '',
};

const contentFormatter = get(content, 'formatter');
const getStatisticData = (data: Data) => ({
title: '总计',
value: getTotalValue(data, angleField),
});

if (title !== false) {
let titleLineHeight = get(title, 'style.lineHeight');
Expand All @@ -202,10 +205,7 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
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(
Expand All @@ -214,6 +214,9 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
offsetY: content === false ? 0 : -titleLineHeight,
// append-info
key: 'statistic',
style: {
textAlign: 'center',
},
},
title
),
Expand All @@ -225,14 +228,13 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
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(
Expand All @@ -242,6 +244,9 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
offsetY: title === false ? 0 : valueLineHeight,
// append-info
key: 'statistic',
style: {
textAlign: 'center',
},
},
content
),
Expand Down
33 changes: 18 additions & 15 deletions src/plots/pie/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7edd0e6

Please sign in to comment.