Skip to content

Commit 2468149

Browse files
authored
feat: 饼图支持配置坐标系 startAngle 和 endAngle (#2164)
* feat(pie): 饼图支持设置坐标系起始角度和结束角度 * docs(demo): 增加四分之一圆的demo & 调整饼图 demo * test: 添加饼图startAngle & endAngle的单测 * docs: 添加饼图 startAngle & endAngle 的 api 文档 * docs(demo): 移除多余的 demo & 添加 demo 截图
1 parent 223473d commit 2468149

File tree

10 files changed

+114
-61
lines changed

10 files changed

+114
-61
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Pie } from '../../../../src';
2+
import { POSITIVE_NEGATIVE_DATA } from '../../../data/common';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('pie', () => {
6+
it('set startAngle & endAngle', () => {
7+
const pie = new Pie(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data: POSITIVE_NEGATIVE_DATA,
11+
angleField: 'value',
12+
colorField: 'type',
13+
radius: 0.8,
14+
startAngle: 0,
15+
endAngle: Math.PI,
16+
});
17+
18+
pie.render();
19+
20+
const coodinate = pie.chart.getCoordinate();
21+
expect(coodinate.startAngle).toBe(0);
22+
expect(coodinate.endAngle).toBe(Math.PI);
23+
24+
pie.destroy();
25+
});
26+
});

docs/api/plots/pie.en.md

+20
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ piePlot.render();
6767

6868
饼图的半径,原点为画布中心。配置值域为 (0,1],1 代表饼图撑满绘图区域。
6969

70+
#### innerRadius
71+
72+
<description>**optional** _number_</description>
73+
74+
饼图的内半径,原点为画布中心。配置值域为 (0,1]
75+
76+
#### startAngle
77+
78+
<description>**optional** _number_</description>
79+
80+
配置坐标系的起始角度。
81+
82+
#### endAngle
83+
84+
<description>**optional** _number_</description>
85+
86+
配置坐标系的结束角度。
87+
88+
<playground rid="quarter-circle" path="pie/basic/demo/quarter-circle.ts"></playground>
89+
7090
`markdown:docs/common/color.en.md`
7191

7292
#### pieStyle

docs/api/plots/pie.zh.md

+19
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ piePlot.render();
6767

6868
饼图的半径,原点为画布中心。配置值域为 (0,1],1 代表饼图撑满绘图区域。
6969

70+
#### innerRadius
71+
72+
<description>**optional** _number_</description>
73+
74+
饼图的内半径,原点为画布中心。配置值域为 (0,1]
75+
#### startAngle
76+
77+
<description>**optional** _number_</description>
78+
79+
配置坐标系的起始角度。
80+
81+
#### endAngle
82+
83+
<description>**optional** _number_</description>
84+
85+
配置坐标系的结束角度。
86+
87+
<playground rid="quarter-circle" path="pie/basic/demo/quarter-circle.ts"></playground>
88+
7089
`markdown:docs/common/color.zh.md`
7190

7291
#### statistic ✨

examples/pie/basic/demo/meta.json

+6-14
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
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 plot - outer label"
28-
},
29-
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*ZztJQa4RLwoAAAAAAAAAAABkARQnAQ"
30-
},
3123
{
3224
"filename": "spider-label.ts",
3325
"title": {
@@ -37,26 +29,26 @@
3729
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*QyXPRK-URmUAAAAAAAAAAAAAARQnAQ"
3830
},
3931
{
40-
"filename": "pie-state.ts",
32+
"filename": "quarter-circle.ts",
4133
"title": {
42-
"zh": "饼图-设置条件状态",
43-
"en": "Pie plot - set condition state"
34+
"zh": "四分之一圆",
35+
"en": "Quarter circle pie"
4436
},
45-
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*y8zjS5DZib8AAAAAAAAAAAAAARQnAQ"
37+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/bzXrKEyk6T/f334d3fa-4494-41b7-9260-c469588555a6.png"
4638
},
4739
{
4840
"filename": "legend-interaction.ts",
4941
"title": {
5042
"zh": "饼图-图例交互",
51-
"en": "Pie interaction - with legend action"
43+
"en": "Pie interaction with legend action"
5244
},
5345
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*xZtSQocP4kYAAAAAAAAAAAAAARQnAQ"
5446
},
5547
{
5648
"filename": "pie-texture.ts",
5749
"title": {
5850
"en": "Pie plot fill with texture",
59-
"zh": "饼图-带纹理"
51+
"zh": "带纹理的饼图"
6052
},
6153
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/SUQSZupP5X/c2076423-44ca-41d2-b8fa-a221b6a8fcf2.png"
6254
}

examples/pie/basic/demo/pie-state.ts

-44
This file was deleted.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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: 1,
18+
// 设置圆弧起始角度
19+
startAngle: Math.PI,
20+
endAngle: Math.PI * 1.5,
21+
label: {
22+
type: 'inner',
23+
offset: '-8%',
24+
content: '{name}',
25+
style: { fontSize: 18 },
26+
},
27+
interactions: [{ type: 'element-active' }],
28+
pieStyle: {
29+
lineWidth: 0,
30+
},
31+
});
32+
33+
piePlot.render();

examples/pie/basic/demo/spider-label.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const piePlot = new Pie('container', {
1414
data,
1515
angleField: 'value',
1616
colorField: 'type',
17-
radius: 0.8,
17+
radius: 0.75,
1818
label: {
1919
type: 'spider',
2020
labelHeight: 28,

examples/pie/donut/demo/meta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"filename": "basic.ts",
99
"title": {
10-
"zh": "环图",
10+
"zh": "基础环图",
1111
"en": "Basic donut plot"
1212
},
1313
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*65WIQK5T4c8AAAAAAAAAAAAAARQnAQ"

src/plots/pie/adaptor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ function meta(params: Params<PieOptions>): Params<PieOptions> {
8989
*/
9090
function coordinate(params: Params<PieOptions>): Params<PieOptions> {
9191
const { chart, options } = params;
92-
const { radius, innerRadius } = options;
92+
const { radius, innerRadius, startAngle, endAngle } = options;
9393

9494
chart.coordinate({
9595
type: 'theta',
9696
cfg: {
9797
radius,
9898
innerRadius,
99+
startAngle,
100+
endAngle,
99101
},
100102
});
101103

src/plots/pie/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface PieOptions extends Options {
1919
readonly label?: Label;
2020
/** 饼图图形样式 */
2121
readonly pieStyle?: StyleAttr;
22+
// 设置扇形图
23+
/** 圆环的开始角度 */
24+
readonly startAngle?: number;
25+
/** 圆环的结束角度 */
26+
readonly endAngle?: number;
2227
/**
2328
* 指标卡组件: 显示在环图中心,可以代替tooltip,显示环图数据的总计值和各项数据
2429
* 启用 statistic 组件的同时将自动关闭tooltip

0 commit comments

Comments
 (0)