-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event): label click event (#6012)
Co-authored-by: shield2018 <>
- Loading branch information
1 parent
ed5e780
commit fb0911c
Showing
6 changed files
with
88 additions
and
7 deletions.
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,27 @@ | ||
import { chartOnLabelClick as render } from '../plots/api/chart-on-label-click'; | ||
import { ChartEvent } from '../../src'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { dispatchFirstShapeEvent, createPromise } from './utils/event'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('chart.on', () => { | ||
const canvas = createNodeGCanvas(640, 480); | ||
const { finished, chart } = render({ canvas }); | ||
|
||
chart.off(); | ||
|
||
it('chart.on("label:click", callback) should provide datum for item element', async () => { | ||
await finished; | ||
const [fired, resolve] = createPromise(); | ||
chart.on(`label:${ChartEvent.CLICK}`, (event) => { | ||
expect(event.data).toEqual({ data: { text: 'A', value: 12000, c: 's' } }); | ||
resolve(); | ||
}); | ||
dispatchFirstShapeEvent(canvas, 'label', 'click', { detail: 1 }); | ||
await fired; | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartOnLabelClick(context) { | ||
const { container, canvas } = context; | ||
const data = [ | ||
{ text: 'A', value: 12000, c: 's' }, | ||
{ text: 'B', value: 9800 }, | ||
{ text: 'C', value: 6789 }, | ||
{ text: 'D', value: 4569 }, | ||
]; | ||
const chart = new Chart({ container, canvas }); | ||
chart | ||
.interval() | ||
.data(data) | ||
.encode('x', 'text') | ||
.encode('y', 'value') | ||
.legend(false) | ||
.label({ | ||
text: 'label', | ||
cursor: 'pointer', | ||
}); | ||
|
||
chart.on('label:click', (e) => console.log('click label', e, e.data)); | ||
|
||
const finished = chart.render(); | ||
|
||
return { chart, finished }; | ||
} |
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
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
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
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