Skip to content

Commit 15e1603

Browse files
ntscshen沈杨
and
沈杨
authored
feat: 玫瑰图新增 startAngle、endAngle (#2350)
Co-authored-by: 沈杨 <[email protected]>
1 parent 2f5b0e8 commit 15e1603

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Rose } from '../../../../src';
2+
import { salesByArea } from '../../../data/sales';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('rose', () => {
6+
it('set startAngle & endAngle', () => {
7+
const rose = new Rose(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data: salesByArea,
11+
xField: 'area',
12+
yField: 'sales',
13+
seriesField: 'area',
14+
radius: 0.8,
15+
startAngle: 0,
16+
endAngle: Math.PI,
17+
});
18+
19+
rose.render();
20+
21+
const coordinate = rose.chart.getCoordinate();
22+
const { startAngle, endAngle } = coordinate;
23+
expect(startAngle).toBe(0);
24+
expect(endAngle).toBe(Math.PI);
25+
26+
rose.destroy();
27+
});
28+
});

docs/api/plots/rose.en.md

+12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ The radius of the rose with the origin being the center of the canvas. The confi
101101

102102
The radius of the hollow circle inside the rose is the same as radius.
103103

104+
#### startAngle
105+
106+
<description>**optional** _number_ _default:_ `(Math.PI * 0) / 180`</description>
107+
108+
The starting Angle of the disk.
109+
110+
#### endAngle
111+
112+
<description>**optional** _number_ _default:_ `(Math.PI * 180) / 180`</description>
113+
114+
The termination Angle of the disk.
115+
104116
`markdown:docs/common/color.en.md`
105117

106118
#### sectorStyle

docs/api/plots/rose.zh.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const rosePlot = new Rose('container', {
6969
piePlot.render();
7070
```
7171

72-
#### seriesField
72+
#### seriesField
7373

7474
<description>**optional** _string_</description>
7575

@@ -89,21 +89,33 @@ piePlot.render();
8989

9090
### 图形样式
9191

92-
#### radius
92+
#### radius
9393

9494
<description>**optional** _number_</description>
9595

9696
玫瑰图的半径,原点为画布中心。配置值域为 (0,1],1 代表玫瑰图撑满绘图区域。
9797

98-
#### innerRadius
98+
#### innerRadius
9999

100100
<description>**optional** _number_</description>
101101

102102
玫瑰图内部空心圆的半径,规则与 radius 一致。
103103

104+
#### startAngle
105+
106+
<description>**optional** _number_ _default:_ `(Math.PI * 0) / 180`</description>
107+
108+
配置坐标系的起始角度。
109+
110+
#### endAngle
111+
112+
<description>**optional** _number_ _default:_ `(Math.PI * 180) / 180`</description>
113+
114+
配置坐标系的结束角度。
115+
104116
`markdown:docs/common/color.zh.md`
105117

106-
#### sectorStyle
118+
#### sectorStyle
107119

108120
<description>**optional** _object | Function_</description>
109121

src/plots/rose/adaptor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ export function legend(params: Params<RoseOptions>): Params<RoseOptions> {
9292
*/
9393
function coordinate(params: Params<RoseOptions>): Params<RoseOptions> {
9494
const { chart, options } = params;
95-
const { radius, innerRadius } = options;
95+
const { radius, innerRadius, startAngle, endAngle } = options;
9696

9797
chart.coordinate({
9898
type: 'polar',
9999
cfg: {
100100
radius,
101101
innerRadius,
102+
startAngle,
103+
endAngle,
102104
},
103105
});
104106

src/plots/rose/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface RoseOptions extends Options {
1818
readonly radius?: number;
1919
/** 内部空心圆的半径,规则与 radius 一致 */
2020
readonly innerRadius?: number;
21+
/** 玫瑰图开始角度 */
22+
readonly startAngle?: number;
23+
/** 玫瑰图结束角度 */
24+
readonly endAngle?: number;
2125
/**
2226
* 设置扇形样式。sectorStyle 中的fill会覆盖 color 的配置
2327
* sectorStyle 可以直接指定,也可以通过 callback 的方式,根据数据为每个扇形切片指定单独的样式

0 commit comments

Comments
 (0)