Skip to content

Commit d29d00f

Browse files
authored
feat(pie): support spider-label (#1601)
* feat(pie): support spider-label * feat(example): 更新 spider-label 的截图
1 parent 61b40b5 commit d29d00f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

examples/pie/basic/demo/meta.json

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
},
2121
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*ZztJQa4RLwoAAAAAAAAAAABkARQnAQ"
2222
},
23+
{
24+
"filename": "outer-label.ts",
25+
"title": {
26+
"zh": "饼图-外部图形标签",
27+
"en": "Pie chart - outter label"
28+
},
29+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*ZztJQa4RLwoAAAAAAAAAAABkARQnAQ"
30+
},
31+
{
32+
"filename": "spider-label.ts",
33+
"title": {
34+
"zh": "饼图-蜘蛛布局标签",
35+
"en": "Pie chart - spider label"
36+
},
37+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*QyXPRK-URmUAAAAAAAAAAAAAARQnAQ"
38+
},
2339
{
2440
"filename": "pie-state.ts",
2541
"title": {
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Pie } from '@antv/g2plot';
2+
3+
const data = [
4+
{ type: '分类一', value: 27 },
5+
{ type: '分类二', value: 25 },
6+
{ type: '分类三', value: 18 },
7+
{ type: '分类四', value: 15 },
8+
{ type: '分类五', value: 10 },
9+
{ type: '其他', value: 5 },
10+
];
11+
12+
const piePlot = new Pie('container', {
13+
appendPadding: 10,
14+
data,
15+
angleField: 'value',
16+
colorField: 'type',
17+
radius: 0.8,
18+
label: {
19+
type: 'spider',
20+
content: '{name}\n{percentage}',
21+
},
22+
});
23+
24+
piePlot.render();

src/plots/pie/adaptor.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Params } from '../../core/adaptor';
33
import { legend, tooltip, interaction, animation, theme, state, annotation } from '../../adaptor/common';
44
import { Data } from '../../types';
55
import { flow, LEVEL, log, template } from '../../utils';
6-
import { Annotation } from '../../types/annotation';
76
import { interval } from '../../adaptor/geometries';
87
import { PieOptions } from './types';
98
import { getTotalValue } from './utils';
@@ -147,10 +146,12 @@ function label(params: Params<PieOptions>): Params<PieOptions> {
147146
const LABEL_TYPE_MAP = {
148147
inner: 'pie-inner',
149148
outer: 'pie',
149+
spider: 'pie',
150150
};
151151
const LABEL_LAYOUT_TYPE_MAP = {
152152
inner: '',
153153
outer: 'pie-outer',
154+
spider: 'pie-spider',
154155
};
155156
const labelType = LABEL_TYPE_MAP[labelCfg.type] || 'pie';
156157
const labelLayoutType = LABEL_LAYOUT_TYPE_MAP[labelCfg.type] || 'pie-outer';

0 commit comments

Comments
 (0)