Skip to content

Commit

Permalink
feat(v2/pie-demo): 饼图 demo 的优化 (#1424)
Browse files Browse the repository at this point in the history
* feat(v2/pie-demo): 饼图 demo 的优化

* fix(typings): 修改 legend 的类型定义

* refactor(v2/pie): 设置中心指标卡默认样式,删除不必要的常量文件
  • Loading branch information
visiky authored and BBSQQ committed Aug 25, 2020
1 parent 510f6a5 commit e2d56ad
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 88 deletions.
2 changes: 0 additions & 2 deletions examples/pie/basic/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const data = [
];

const piePlot = new Pie('container', {
width: 400,
height: 300,
appendPadding: 10,
data,
angleField: 'value',
Expand Down
49 changes: 0 additions & 49 deletions examples/pie/basic/demo/custom-label.ts

This file was deleted.

8 changes: 0 additions & 8 deletions examples/pie/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*ahB1Qp7T-C8AAAAAAAAAAABkARQnAQ"
},
{
"filename": "custom-label.ts",
"title": {
"en": "customize pie chart",
"zh": "个性化标签饼图"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_f5c722/afts/img/A*sqwJRIEzdQ0AAAAAAAAAAABkARQnAQ"
},
{
"filename": "pie-texture.ts",
"title": {
Expand Down
2 changes: 0 additions & 2 deletions examples/pie/basic/demo/outer-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const data = [
];

const piePlot = new Pie('container', {
width: 400,
height: 300,
appendPadding: 10,
data,
angleField: 'value',
Expand Down
2 changes: 0 additions & 2 deletions examples/pie/basic/demo/pie-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const data = [
];

const piePlot = new Pie('container', {
width: 400,
height: 300,
appendPadding: 10,
data,
angleField: 'sold',
Expand Down
2 changes: 0 additions & 2 deletions examples/pie/donut/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const data = [
];

const piePlot = new Pie('container', {
width: 400,
height: 300,
appendPadding: 10,
data,
angleField: 'value',
Expand Down
8 changes: 4 additions & 4 deletions examples/pie/donut/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
},
"demos": [
{
"filename": "basic.js",
"filename": "basic.ts",
"title": {
"zh": "环图",
"en": "basic Donut chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*wmldRZZj9lIAAAAAAAAAAABkARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*jbeVTpgzCVAAAAAAAAAAAABkARQnAQ"
},
{
"filename": "statistics.js",
"filename": "statistics.ts",
"title": {
"zh": "环图 - 带统计指标卡",
"en": "Donut chart with statistics"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*ZztJQa4RLwoAAAAAAAAAAABkARQnAQ"
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*U9D_Sr55LEMAAAAAAAAAAABkARQnAQ"
}
]
}
15 changes: 10 additions & 5 deletions examples/pie/donut/demo/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ const data = [
];

const piePlot = new Pie('container', {
width: 400,
height: 300,
appendPadding: 10,
data,
angleField: 'value',
colorField: 'type',
radius: 0.8,
innerRadius: 0.64,
label: {
type: 'outer',
content: '{name} {percentage}',
type: 'inner',
offset: -35,
autoRotate: false,
content: '{value}',
style: {
fill: '#333',
stroke: '#fff',
strokeWidth: 1,
},
},
statistic: {
title: {
formatter: () => 'Total',
formatter: () => '总计',
},
},
// 添加 中心统计文本 交互
Expand Down
7 changes: 0 additions & 7 deletions src/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { deepMix, each, every, filter, get, isFunction, isString, isNil } from '
import { Params } from '../../core/adaptor';
import { legend, tooltip, interaction, animation, theme } from '../../adaptor/common';
import { flow, LEVEL, log, template } from '../../utils';
import { StatisticContentStyle, StatisticTitleStyle } from './constants';
import { PieOptions } from './types';
import { getStatisticData } from './utils';

Expand Down Expand Up @@ -208,8 +207,6 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
...deepMix(
{},
{
// default config
style: StatisticTitleStyle,
offsetY: content === false ? 0 : -titleLineHeight,
// append-info
key: 'statistic',
Expand All @@ -231,8 +228,6 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
...deepMix(
{},
{
// default config
style: StatisticContentStyle,
// 居中
offsetY: title === false ? 0 : valueLineHeight,
// append-info
Expand All @@ -244,8 +239,6 @@ function annotation(params: Params<PieOptions>): Params<PieOptions> {
}

annotationOptions.push(statisticTitle, statisticContent);

chart.render();
}

/** 自定义 annotation */
Expand Down
6 changes: 0 additions & 6 deletions src/plots/pie/constants.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/plots/pie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,28 @@ export class Pie extends Plot<PieOptions> {
*/
protected getDefaultOptions(): Partial<PieOptions> {
return {
legend: {
position: 'right',
},
tooltip: {
shared: false,
showTitle: false,
showMarkers: false,
},
/** 饼图样式 */
pieStyle: {
stroke: 'white',
lineWidth: 1,
},
/** 饼图中心文本默认样式 */
statistic: {
title: {
style: { fontSize: 14, fontWeight: 300, fill: '#4D4D4D', textAlign: 'center' },
},
content: {
style: { fontSize: 21, fontWeight: 'bold', fill: '#4D4D4D', textAlign: 'center' },
},
},
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/types/legend.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export type Legend = {};
import { LegendCfg } from '@antv/g2/lib/interface';

export type Legend = boolean | LegendCfg;

0 comments on commit e2d56ad

Please sign in to comment.