Skip to content

Commit 448ee0d

Browse files
authored
refactor(bullet): 调整 bullet 的 style api (#1790)
* fix: 调整bullet的style api * refactor: 调整api(style)为(bulletStyle)
1 parent feb7541 commit 448ee0d

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Bullet } from '../../../../src';
2+
import { bulletData } from '../../../data/bullet';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('bulletStyle*label', () => {
6+
it('bulletStyle', () => {
7+
const bullet = new Bullet(createDiv('bulletStyle bullet'), {
8+
width: 400,
9+
height: 100,
10+
data: bulletData,
11+
measureField: 'measures',
12+
rangeField: 'ranges',
13+
targetField: 'target',
14+
xField: 'title',
15+
bulletStyle: {
16+
range: {
17+
fillOpacity: 0.65,
18+
},
19+
target: {
20+
stroke: '#ddd',
21+
},
22+
},
23+
});
24+
25+
bullet.render();
26+
27+
const chart = bullet.chart;
28+
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries;
29+
30+
const rangeElements = rangeGeometry.elements[0];
31+
expect(rangeElements.shape.attr('fillOpacity')).toBe(0.65);
32+
33+
expect(measureGeometry.getAdjust('stack')).toMatchObject({
34+
xField: 'title',
35+
yField: 'measures',
36+
});
37+
38+
const targetElements = targetGeometry.elements[0];
39+
expect(targetElements.shape.attr('stroke')).toBe('#ddd');
40+
});
41+
});

examples/bullet/basic/API.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bulletPlot.render();
7373

7474
### 图形样式
7575

76-
#### style
76+
#### bulletStyle
7777

7878
**可选**, _object_
7979

examples/bullet/basic/API.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bulletPlot.render();
7373

7474
### 图形样式
7575

76-
#### style
76+
#### bulletStyle
7777

7878
**可选**, _object_
7979

src/plots/bullet/adaptor.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { transformData } from './utils';
1313
*/
1414
function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
1515
const { chart, options } = params;
16-
const { style, targetField, rangeField, measureField, xField, color, layout, size } = options;
16+
const { bulletStyle, targetField, rangeField, measureField, xField, color, layout, size } = options;
1717
// 处理数据
1818
const { min, max, ds } = transformData(options);
1919

@@ -43,7 +43,7 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
4343
isStack: true,
4444
interval: {
4545
color: color?.range,
46-
style: style?.range,
46+
style: bulletStyle?.range,
4747
size: size?.range,
4848
},
4949
},
@@ -61,7 +61,7 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
6161
isStack: true,
6262
interval: {
6363
color: color?.measure,
64-
style: style?.measure,
64+
style: bulletStyle?.measure,
6565
size: size?.measure,
6666
},
6767
},
@@ -76,7 +76,7 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
7676
seriesField: 'tKey',
7777
point: {
7878
color: color?.target,
79-
style: style?.target,
79+
style: bulletStyle?.target,
8080
size: isNumber(size?.target) ? Number(size.target) / 2 : size.target,
8181
shape: layout === 'horizontal' ? 'line' : 'hyphen',
8282
},

src/plots/bullet/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Bullet extends Plot<BulletOptions> {
2525
measure: 20,
2626
target: 20,
2727
},
28-
style: {
28+
bulletStyle: {
2929
range: {
3030
fillOpacity: 0.5,
3131
},

src/plots/bullet/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export interface BulletOptions extends Omit<Options, 'color' | 'label' | 'style'
3030
/** color 包含了 measure,target,range */
3131
readonly color?: BulletAttr<ColorAttr>;
3232

33-
/** style 包含了 measure,target,range */
34-
readonly style?: BulletAttr<StyleAttr>;
33+
/** bulletStyle 包含了 measure,target,range */
34+
readonly bulletStyle?: BulletAttr<StyleAttr>;
3535

3636
/** layout 方向选择*/
3737
layout?: 'horizontal' | 'vertical';

0 commit comments

Comments
 (0)