Skip to content

Commit b32a920

Browse files
authored
feat: 增加再次点击取消高亮状态 (#2138)
1 parent 0891d4a commit b32a920

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

packages/f2/src/components/elementLink/withElementLink.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default (View) => {
2929
const highlightsData = data.filter((record) => {
3030
return condition(record[field], record);
3131
});
32+
if (!highlightsData.length) return;
3233
elements.push({
3334
highlightsData,
3435
field,

packages/f2/src/components/legend/withLegend.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export default (View) => {
286286
}
287287

288288
const { field, tickValue } = dataItem;
289-
const { filtered: prevFiltered } = this.state;
289+
const { filtered: prevFiltered, highlighted: preHighlighted } = this.state;
290290
const filtered = {
291291
...prevFiltered,
292292
[tickValue]: !prevFiltered[tickValue],
@@ -301,7 +301,7 @@ export default (View) => {
301301
});
302302
} else if (clickMode === 'element-link') {
303303
const highlighted = {
304-
[tickValue]: true,
304+
[tickValue]: !preHighlighted[tickValue],
305305
};
306306
this.setState({
307307
highlighted,
19.5 KB
Loading
17.9 KB
Loading

packages/f2/test/components/elementLink/index.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,36 @@ describe('element-link', () => {
3535
await delay(100);
3636
expect(context).toMatchImageSnapshot();
3737
});
38+
39+
it('toggle highlight', async () => {
40+
const context = createContext('toggle highlight', {
41+
height: '300px',
42+
width: '400px',
43+
});
44+
45+
const { props } = (
46+
<Canvas context={context}>
47+
<Chart data={data}>
48+
<Axis field="year" />
49+
<Axis field="value" />
50+
<Interval x="year" y="value" color="type" adjust="stack" />
51+
<ElementLink field="type" />
52+
<Legend position="top" clickMode="element-link" />
53+
</Chart>
54+
</Canvas>
55+
);
56+
const canvas = new Canvas(props);
57+
await canvas.render();
58+
59+
await delay(500);
60+
61+
await gestureSimulator(context.canvas, 'click', { x: 150, y: 30 });
62+
await delay(100);
63+
expect(context).toMatchImageSnapshot();
64+
65+
await gestureSimulator(context.canvas, 'click', { x: 150, y: 30 });
66+
await delay(100);
67+
68+
expect(context).toMatchImageSnapshot();
69+
});
3870
});

0 commit comments

Comments
 (0)