Skip to content

Commit 50a815a

Browse files
authored
fix(#2573): 修复雷达图设置 point state 状态样式不生效 (#2577)
* feat(radar): 雷达图辅助元素 point 默认继承主元素 state 设置(非 mix) * test(issue-2573): 增加单测
1 parent 2c8ce43 commit 50a815a

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

__tests__/bugs/issue-2573-spec.ts

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Radar } from '../../src';
2+
import { SERIES_DATA } from '../data/radar';
3+
import { createDiv } from '../utils/dom';
4+
5+
describe('#2573', () => {
6+
const data = SERIES_DATA;
7+
const radar = new Radar(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data,
11+
xField: 'name',
12+
yField: 'value',
13+
seriesField: 'type',
14+
radius: 0.8,
15+
color: ['red', 'orange'],
16+
state: {
17+
default: {
18+
style: {
19+
stroke: 'red',
20+
},
21+
},
22+
active: {
23+
style: {
24+
stroke: 'green',
25+
},
26+
},
27+
},
28+
point: {},
29+
});
30+
31+
radar.render();
32+
33+
it('radar point 设置 state 状态样式不生效', () => {
34+
radar.setState('default', (datum) => datum['name'] === data[0].name);
35+
expect(radar.chart.geometries[1].elements[0].shape.attr('stroke')).toBe('red');
36+
37+
radar.setState('active', (datum) => datum['name'] === data[0].name);
38+
expect(radar.chart.geometries[1].elements[0].shape.attr('stroke')).toBe('green');
39+
});
40+
41+
it('point state 优先级高', () => {
42+
radar.update({
43+
point: {
44+
state: {
45+
default: {
46+
style: {
47+
stroke: 'blue',
48+
},
49+
},
50+
active: {
51+
style: {
52+
stroke: 'orange',
53+
},
54+
},
55+
},
56+
},
57+
});
58+
radar.setState('default', (datum) => datum['name'] === data[0].name);
59+
expect(radar.chart.geometries[1].elements[0].shape.attr('stroke')).toBe('blue');
60+
61+
radar.setState('active', (datum) => datum['name'] === data[0].name);
62+
expect(radar.chart.geometries[1].elements[0].shape.attr('stroke')).toBe('orange');
63+
});
64+
65+
afterAll(() => {
66+
radar.destroy();
67+
});
68+
});

docs/common/point-style.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
| shape | \_string \| Function\_ | The shape of the data point, support callback way, example: `shape: (x, y, series) => string` |
55
| size | _number \| Function_ | The size of the data point, support callback way, example: `size: (x, y, series) => number` |
66
| style | _object \| Function_ | Data point style, support callback way, example: `style: (x, y, series) => object` |
7-
| state | _object_ | State styles of point, setting style of specify state。Refer to [_state_](#state)` |
7+
| state | _object_ | State styles of point, setting style of specify state。Refer to [_state_](#state) |

docs/common/point-style.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
| shape | _string \| Function_ | 数据点形状,也可以支持回调的方式设置,回调参数为 `shape: (x, y, series) => string` |
55
| size | _number \| Function_ | 数据点大小,也可以支持回调的方式设置,回调参数为 `size: (x, y, series) => number` |
66
| style | _object \| Function_ | 数据点样式,也可以支持回调的方式设置,回调参数为 `style: (x, y, series) => object` |
7-
| state | _object_ | 数据点状态样式,设置对应状态的样式。详细参考 [_state_](#state)` |
7+
| state | _object_ | 数据点状态样式,设置对应状态的样式。详细参考 [_state_](#state) |

src/plots/radar/adaptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ function geometry(params: Params<RadarOptions>): Params<RadarOptions> {
1212
const { chart, options } = params;
1313
const { data, lineStyle, color, point: pointOptions, area: areaOptions } = options;
1414

15-
const pointState = pointOptions?.state;
16-
1715
chart.data(data);
1816

1917
// 雷达图 主 geometry
@@ -45,6 +43,8 @@ function geometry(params: Params<RadarOptions>): Params<RadarOptions> {
4543
tooltip: false,
4644
},
4745
});
46+
// 优先使用 point.state, 其次取主元素的 state 状态样式配置
47+
const pointState = pointOptions?.state || options.state;
4848
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
4949

5050
line(primary);

src/types/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Datum, Data } from './common';
33

44
export type State = Types.StateOption;
55

6-
/** 状态名称,G2 Element 开放 'active' | 'inactive' | 'selected' 三种状态 */
7-
export type StateName = 'active' | 'inactive' | 'selected';
6+
/** 状态名称,G2 Element 开放 'active' | 'inactive' | 'selected' | 'default' 四种状态 */
7+
export type StateName = 'active' | 'inactive' | 'selected' | 'default';
88

99
/** 状态条件 */
1010
export type StateCondition = (data: Datum | Data) => boolean;

0 commit comments

Comments
 (0)