Skip to content

Commit 8ac5549

Browse files
authored
refactor(bullet): 子弹图升级下 & 修复 axis 配置失效 (#2228)
* refactor(bullet): 重构下子弹图的 adaptor 使用通用的 scale adaptor 来处理 fix: 修复子弹图 axis 在没有配置 meta 的时候,axis配置如 tickCount 等失效 * docs(demo): 子弹图 demo 的优化 * docs(bullet): 子弹图 api 文档优化 目前 color 应该只支持 string 或 string[], 不支持回调 * test: 添加测试用例 * fix: demo 的引用路径问题 * test(bullet): 增加测试用例 * docs(bullet): 子弹图默认关闭 x 轴line & 补充子弹图图表指引
1 parent ee48895 commit 8ac5549

File tree

22 files changed

+430
-167
lines changed

22 files changed

+430
-167
lines changed

__tests__/unit/plots/bullet/axis-spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ import { bulletData } from '../../../data/bullet';
33
import { createDiv } from '../../../utils/dom';
44

55
describe('axis bullet', () => {
6+
it('axis without meta', () => {
7+
const bullet = new Bullet(createDiv('axis*meta bullet'), {
8+
width: 400,
9+
height: 100,
10+
data: bulletData,
11+
measureField: 'measures',
12+
rangeField: 'ranges',
13+
targetField: 'target',
14+
xField: 'title',
15+
yAxis: { tickCount: 10 },
16+
});
17+
18+
bullet.render();
19+
const measureGeometry = bullet.chart.geometries[1];
20+
expect(measureGeometry.scales.measures.tickCount).toBe(10);
21+
22+
bullet.destroy();
23+
});
624
it('axis*meta', () => {
725
const rangeColors = ['#FFB1AC', '#FFDBA2', '#B4EBBF'];
826
const bullet = new Bullet(createDiv('axis*meta bullet'), {

__tests__/unit/plots/bullet/index-spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ describe('bullet', () => {
1616

1717
bullet.render();
1818

19+
expect(bullet.type).toBe('bullet');
20+
1921
const chart = bullet.chart;
2022

2123
expect(chart.getController('legend').getComponents().length).toEqual(0);
24+
// 默认关闭 showMarkers
25+
// @ts-ignore
26+
expect(chart.getController('tooltip').getTooltipCfg().showMarkers).toEqual(false);
2227
// @ts-ignore
2328
expect(chart.options.axes.ranges).toEqual(false);
2429
// @ts-ignore
@@ -291,4 +296,30 @@ describe('bullet', () => {
291296

292297
bullet.destroy();
293298
});
299+
300+
it('meta', () => {
301+
const bullet = new Bullet(createDiv(), {
302+
width: 400,
303+
height: 100,
304+
data: [{ title: '数学', ranges: [30, 50, 100], measures: [120], target: 85 }],
305+
measureField: 'measures',
306+
rangeField: 'ranges',
307+
targetField: 'target',
308+
xField: 'title',
309+
meta: {
310+
measures: { max: 100 },
311+
},
312+
});
313+
314+
bullet.render();
315+
expect(bullet.chart.getScaleByField('measures').max).toBe(100);
316+
317+
bullet.update({
318+
meta: {
319+
measures: { max: 90, maxLimit: 120 },
320+
},
321+
});
322+
expect(bullet.chart.getScaleByField('measures').max).toBe(120);
323+
expect(bullet.chart.getScaleByField('measures').maxLimit).toBe(120);
324+
});
294325
});

docs/api/plots/bullet.en.md

+48-48
Original file line numberDiff line numberDiff line change
@@ -17,82 +17,51 @@ order: 10
1717

1818
`markdown:docs/common/meta.en.md`
1919

20-
```ts
21-
const data = [
22-
{
23-
title: '满意度',
24-
ranges: [100],
25-
measures: [80],
26-
target: 85,
27-
},
28-
];
29-
30-
const bulletPlot = new Bullet('container', {
31-
data,
32-
measureField: 'measures',
33-
rangeField: 'ranges',
34-
targetField: 'target',
35-
xField: 'title',
36-
});
37-
38-
bulletPlot.render();
39-
```
40-
4120
#### measureField
4221

43-
<description>**required** _number[]_</description>
22+
<description>**required** _string_</description>
4423

4524
使用数据条的长度,实际数值的设置字段,表示实际数值。
4625

4726
#### rangeField
4827

49-
<description>**required** _number[]_</description>
28+
<description>**required** _string_</description>
5029

5130
使用背景色条的长度的设置字段,表示区间范围。
5231

5332
#### targetField
5433

55-
<description>**required** _number_</description>
34+
<description>**required** _string_</description>
5635

5736
使用测量标记的刻度轴位置的设置字段,表示目标值。
5837

59-
#### layout
38+
#### xField
6039

61-
<description>**optional** _'horizontal' | 'vertical'_ _default:_ 'horizontal'</description>
40+
<description>**optional** _string_</description>
6241

63-
表示子弹图方向
42+
用于区分不同的类型,适用于分组子弹图
6443

6544
### Geometry Style
6645

67-
#### bulletStyle
68-
69-
<description>**optional** _object_</description>
70-
71-
设置子弹图各图形 style 属性。
46+
#### layout
7247

73-
| 细分配置 | 类型 | 功能描述 | 默认配置 |
74-
| -------- | ----------- | ------------ | -------------------- |
75-
| range | _StyleAttr_ | 区间背景样式 | { fillOpacity: 0.5 } |
76-
| measure | _StyleAttr_ | 实际值样式 ||
77-
| target | _StyleAttr_ | 目标值样式 ||
48+
<description>**optional** _'horizontal' | 'vertical'_ _default:_ 'horizontal'</description>
7849

79-
`markdown:docs/common/shape-style.en.md`
50+
表示子弹图方向。
8051

81-
### color
52+
#### color
8253

8354
<description>**optional** _object_</description>
8455

8556
设置子弹图各图形 color 属性。
8657

8758
| 细分配置 | 类型 | 功能描述 | 默认配置 |
8859
| -------- | ----------- | ------------ | -------- |
89-
| range | _colorAttr_ | 区间背景颜色 ||
90-
| measure | _colorAttr_ | 实际值颜色 ||
91-
| target | _colorAttr_ | 目标值颜色 ||
92-
93-
`markdown:docs/common/color.en.md`
60+
| range | _string\|string[]_ | 区间背景颜色 ||
61+
| measure | _string\|string[]_ | 实际值颜色 ||
62+
| target | _string\|string[]_ | 目标值颜色 ||
9463

95-
### size
64+
#### size
9665

9766
<description>**optional** _object_</description>
9867

@@ -108,7 +77,29 @@ bulletPlot.render();
10877
type SizeAttr = number | [number, number] | ((datum: Datum) => number);
10978
```
11079

111-
### label
80+
#### bulletStyle
81+
82+
<description>**optional** _object_</description>
83+
84+
设置子弹图各图形 style 属性。
85+
86+
| 细分配置 | 类型 | 功能描述 | 默认配置 |
87+
| -------- | ----------- | ------------ | -------------------- |
88+
| range | _StyleAttr_ | 区间背景样式 | { fillOpacity: 0.5 } |
89+
| measure | _StyleAttr_ | 实际值样式 ||
90+
| target | _StyleAttr_ | 目标值样式 ||
91+
92+
```plain
93+
type StyleAttr = ShapeStyle | ((datum: object) => ShapeStyle);
94+
```
95+
96+
`ShapeStyle` 结构可以参考:
97+
98+
`markdown:docs/common/shape-style.en.md`
99+
100+
### Plot Components
101+
102+
#### label
112103

113104
<description>**optional** _object_</description>
114105

@@ -122,10 +113,19 @@ type SizeAttr = number | [number, number] | ((datum: Datum) => number);
122113

123114
`markdown:docs/common/label.en.md`
124115

125-
### Plot Components
116+
#### tooltip
117+
118+
`markdown:docs/common/tooltip.en.md`
119+
120+
#### axis
121+
122+
Same for xAxis and yAxis.
123+
124+
`markdown:docs/common/axis.en.md`
126125

127-
`markdown:docs/common/component.en.md`
126+
#### legend
128127

128+
`markdown:docs/common/legend.en.md`
129129
### Event
130130

131131
`markdown:docs/common/events.en.md`

docs/api/plots/bullet.zh.md

+49-50
Original file line numberDiff line numberDiff line change
@@ -17,82 +17,51 @@ order: 10
1717

1818
`markdown:docs/common/meta.zh.md`
1919

20-
```ts
21-
const data = [
22-
{
23-
title: '满意度',
24-
ranges: [100],
25-
measures: [80],
26-
target: 85,
27-
},
28-
];
29-
30-
const bulletPlot = new Bullet('container', {
31-
data,
32-
measureField: 'measures',
33-
rangeField: 'ranges',
34-
targetField: 'target',
35-
xField: 'title',
36-
});
37-
38-
bulletPlot.render();
39-
```
40-
4120
#### measureField
4221

43-
<description>**required** _number[]_</description>
22+
<description>**required** _string_</description>
4423

4524
使用数据条的长度,实际数值的设置字段,表示实际数值。
4625

4726
#### rangeField
4827

49-
<description>**required** _number[]_</description>
28+
<description>**required** _string_</description>
5029

5130
使用背景色条的长度的设置字段,表示区间范围。
5231

5332
#### targetField
5433

55-
<description>**required** _number_</description>
34+
<description>**required** _string_</description>
5635

5736
使用测量标记的刻度轴位置的设置字段,表示目标值。
5837

59-
#### layout
38+
#### xField
6039

61-
<description>**optional** _'horizontal' | 'vertical'_ _default:_ 'horizontal'</description>
40+
<description>**optional** _string_</description>
6241

63-
表示子弹图方向
42+
用于区分不同的类型,适用于分组子弹图
6443

6544
### 图形样式
6645

67-
#### bulletStyle
68-
69-
<description>**optional** _object_</description>
70-
71-
设置子弹图各图形 style 属性。
46+
#### layout
7247

73-
| 细分配置 | 类型 | 功能描述 | 默认配置 |
74-
| -------- | ----------- | ------------ | -------------------- |
75-
| range | _StyleAttr_ | 区间背景样式 | { fillOpacity: 0.5 } |
76-
| measure | _StyleAttr_ | 实际值样式 ||
77-
| target | _StyleAttr_ | 目标值样式 ||
48+
<description>**optional** _'horizontal' | 'vertical'_ _default:_ 'horizontal'</description>
7849

79-
`markdown:docs/common/shape-style.zh.md`
50+
表示子弹图方向。
8051

81-
### color
52+
#### color
8253

8354
<description>**optional** _object_</description>
8455

8556
设置子弹图各图形 color 属性。
8657

8758
| 细分配置 | 类型 | 功能描述 | 默认配置 |
8859
| -------- | ----------- | ------------ | -------- |
89-
| range | _colorAttr_ | 区间背景颜色 ||
90-
| measure | _colorAttr_ | 实际值颜色 ||
91-
| target | _colorAttr_ | 目标值颜色 ||
92-
93-
`markdown:docs/common/color.zh.md`
60+
| range | _string\|string[]_ | 区间背景颜色 ||
61+
| measure | _string\|string[]_ | 实际值颜色 ||
62+
| target | _string\|string[]_ | 目标值颜色 ||
9463

95-
### size
64+
#### size
9665

9766
<description>**optional** _object_</description>
9867

@@ -108,7 +77,29 @@ bulletPlot.render();
10877
type SizeAttr = number | [number, number] | ((datum: Datum) => number);
10978
```
11079

111-
### label
80+
#### bulletStyle
81+
82+
<description>**optional** _object_</description>
83+
84+
设置子弹图各图形 style 属性。
85+
86+
| 细分配置 | 类型 | 功能描述 | 默认配置 |
87+
| -------- | ----------- | ------------ | -------------------- |
88+
| range | _StyleAttr_ | 区间背景样式 | { fillOpacity: 0.5 } |
89+
| measure | _StyleAttr_ | 实际值样式 ||
90+
| target | _StyleAttr_ | 目标值样式 ||
91+
92+
```plain
93+
type StyleAttr = ShapeStyle | ((datum: object) => ShapeStyle);
94+
```
95+
96+
`ShapeStyle` 结构可以参考:
97+
98+
`markdown:docs/common/shape-style.zh.md`
99+
100+
### 图表组件
101+
102+
#### label
112103

113104
<description>**optional** _object_</description>
114105

@@ -122,9 +113,19 @@ type SizeAttr = number | [number, number] | ((datum: Datum) => number);
122113

123114
`markdown:docs/common/label.zh.md`
124115

125-
### 图表组件
116+
#### tooltip
117+
118+
`markdown:docs/common/tooltip.zh.md`
126119

127-
`markdown:docs/common/component.zh.md`
120+
#### axis
121+
122+
xAxis、yAxis 配置相同(由于 DualAxes 是双轴, yAxis 类型是数组类型)。
123+
124+
`markdown:docs/common/axis.zh.md`
125+
126+
#### 图例
127+
128+
`markdown:docs/common/legend.zh.md`
128129

129130
### 事件
130131

@@ -134,8 +135,6 @@ type SizeAttr = number | [number, number] | ((datum: Datum) => number);
134135

135136
`markdown:docs/common/chart-methods.zh.md`
136137

137-
138-
139138
### 图表主题
140139

141140
`markdown:docs/common/theme.zh.md`

0 commit comments

Comments
 (0)