-
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: tooltip interaction emit events when body hide (#5157)
* feat: tooltip interaction support showContent params * fix: ci --------- Co-authored-by: MiniPear <pearminipro@gmail.com>
- Loading branch information
1 parent
7bf049c
commit b8491c3
Showing
4 changed files
with
121 additions
and
16 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
__tests__/integration/api-chart-emit-item-tooltip-hide-content.spec.ts
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,31 @@ | ||
import { chartEmitItemTooltipHideContent as render } from '../plots/api/chart-emit-item-tooltip-hide-content'; | ||
import './utils/useSnapshotMatchers'; | ||
import { | ||
dispatchFirstElementEvent, | ||
createPromise, | ||
receiveExpectData, | ||
} from './utils/event'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
|
||
describe('chart.emit', () => { | ||
const canvas = createDOMGCanvas(800, 500); | ||
|
||
it('chart.tooltip hide body should emit events.', async () => { | ||
const { finished, chart, clear } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
clear(); | ||
|
||
// chart.on("tooltip:hide") should be called when hiding tooltip. | ||
const [tooltipHided, resolveHide] = createPromise(); | ||
chart.on('tooltip:hide', receiveExpectData(resolveHide, null)); | ||
dispatchFirstElementEvent(canvas, 'pointerout'); | ||
await tooltipHided; | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
__tests__/plots/api/chart-emit-item-tooltip-hide-content.ts
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,70 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartEmitItemTooltipHideContent(context) { | ||
const { container, canvas } = context; | ||
|
||
// wrapperDiv | ||
const wrapperDiv = document.createElement('div'); | ||
container.appendChild(wrapperDiv); | ||
|
||
// button | ||
const button = document.createElement('button'); | ||
button.innerText = 'Hide tooltip'; | ||
container.appendChild(button); | ||
|
||
// p | ||
const p = document.createElement('p'); | ||
p.innerText = ''; | ||
container.appendChild(p); | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container: wrapperDiv, | ||
canvas, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data([ | ||
{ genre: 'Sports', sold: 275 }, | ||
{ genre: 'Strategy', sold: 115 }, | ||
{ genre: 'Action', sold: 120 }, | ||
{ genre: 'Shooter', sold: 350 }, | ||
{ genre: 'Other', sold: 150 }, | ||
]) | ||
.encode('x', 'genre') | ||
.encode('y', 'sold') | ||
.encode('color', 'genre') | ||
.interaction('tooltip', { | ||
body: false, | ||
}); | ||
|
||
const finished = chart.render(); | ||
|
||
finished.then((chart) => | ||
chart.emit('tooltip:show', { | ||
data: { data: { sold: 115 } }, | ||
}), | ||
); | ||
|
||
chart.on('tooltip:show', ({ data }) => { | ||
p.innerText = JSON.stringify(data); | ||
}); | ||
|
||
const hide = () => (p.innerText = 'null'); | ||
|
||
chart.on('tooltip:hide', hide); | ||
|
||
button.onclick = () => { | ||
chart.emit('tooltip:hide'); | ||
}; | ||
|
||
return { | ||
chart, | ||
button, | ||
finished, | ||
clear: () => { | ||
chart.off('tooltip:hide', hide); | ||
}, | ||
}; | ||
} |
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