-
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.
fix(event): emit events for extended shape (#5290)
- Loading branch information
Showing
4 changed files
with
72 additions
and
4 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,32 @@ | ||
import { chartOnTextClick as render } from '../plots/api/chart-on-text-click'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
import { dispatchFirstElementEvent, createPromise } from './utils/event'; | ||
import './utils/useSnapshotMatchers'; | ||
import { ChartEvent } from '../../src'; | ||
|
||
describe('chart.on', () => { | ||
const canvas = createDOMGCanvas(640, 480); | ||
const { finished, chart } = render({ canvas }); | ||
|
||
chart.off(); | ||
|
||
it('chart.on("text:click", callback) should provide datum for item element', async () => { | ||
await finished; | ||
const [fired, resolve] = createPromise(); | ||
chart.on(`text:${ChartEvent.CLICK}`, resolve); | ||
dispatchFirstElementEvent(canvas, 'click', { detail: 1 }); | ||
await fired; | ||
}); | ||
|
||
it('chart.on("element:click", callback) should provide datum for item element', async () => { | ||
await finished; | ||
const [fired, resolve] = createPromise(); | ||
chart.on(`element:${ChartEvent.CLICK}`, resolve); | ||
dispatchFirstElementEvent(canvas, '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,24 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartOnTextClick(context) { | ||
const { container, canvas } = context; | ||
|
||
const chart = new Chart({ theme: 'classic', container, canvas }); | ||
|
||
chart.text().style({ | ||
x: 290, // 像素坐标 | ||
y: 200, // 像素坐标 | ||
text: 'hello', | ||
textAlign: 'center', | ||
fontSize: 60, | ||
textBaseline: 'middle', | ||
}); | ||
|
||
chart.on('element:click', () => console.log('click element')); | ||
|
||
chart.on('text:click', () => console.log('click text')); | ||
|
||
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