Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(chord): 修复和弦图 state 设置不生效 (#2633)
* fix(chord): 修复和弦图 state 设置不生效 同 dual-axes 存在多view的情况 * test(chord): 补充和弦图单测
- Loading branch information
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Chord } from '../../../../src'; | ||
import { createDiv } from '../../../utils/dom'; | ||
import { simulateMouseEvent } from '../../../utils/event'; | ||
import { populationMovementData as DATA } from '../../../data/chord-population'; | ||
|
||
describe('chord: state', () => { | ||
const plot = new Chord(createDiv(), { | ||
height: 500, | ||
data: DATA, | ||
sourceField: 'source', | ||
targetField: 'target', | ||
weightField: 'value', | ||
}); | ||
|
||
plot.render(); | ||
|
||
it('set state', async () => { | ||
plot.render(); | ||
|
||
plot.setState('selected', (data) => (data as any).name === DATA[0].source); | ||
expect(plot.getStates().length).toBe(1); | ||
|
||
plot.chart.views[1].geometries[0].elements[0].setState('selected', false); | ||
expect(plot.getStates().length).toBe(0); | ||
|
||
plot.chart.views[1].geometries[0].elements[0].setState('selected', true); | ||
expect(plot.getStates().length).toBe(1); | ||
|
||
// 取消 selected | ||
plot.setState('selected', (data) => (data as any).name === DATA[0].source, false); | ||
expect(plot.getStates().length).toBe(0); | ||
}); | ||
|
||
it('interactions + getState', () => { | ||
plot.update({ interactions: [{ type: 'element-active' }] }); | ||
|
||
expect(plot.getStates().length).toBe(0); | ||
// edge view | ||
const element = plot.chart.views[0].geometries[0].elements[0]; | ||
simulateMouseEvent(element.shape, 'mouseenter'); | ||
expect(plot.getStates().length).toBe(1); | ||
expect(plot.getStates()[0].data).toMatchObject({ source: DATA[0].source }); | ||
expect(plot.getStates()[0].state).toBe('active'); | ||
}); | ||
|
||
afterAll(() => { | ||
plot.destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters