-
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(tooltip): multi chart when mounting to body (#5283)
- Loading branch information
Showing
4 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
__tests__/integration/api-chart-tooltip-multi-chart.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,29 @@ | ||
import { chartTooltipMultiChart as render } from '../plots/api/chart-tooltip-multi-chart'; | ||
import { dispatchFirstElementEvent } from './utils/event'; | ||
import './utils/useSnapshotMatchers'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
|
||
describe('chart.interaction.tooltip', () => { | ||
const canvas1 = createDOMGCanvas(640, 480); | ||
const canvas2 = createDOMGCanvas(640, 480); | ||
|
||
it('tooltip should not be shared if mount to body.', async () => { | ||
const { finished0, finished1 } = render({ | ||
canvas1, | ||
canvas2, | ||
container: document.createElement('div'), | ||
}); | ||
await Promise.all([finished0, finished1]); | ||
|
||
dispatchFirstElementEvent(canvas1, 'pointerover'); | ||
dispatchFirstElementEvent(canvas2, 'pointerover'); | ||
expect( | ||
Array.from(document.body.getElementsByClassName('g2-tooltip')).length, | ||
).toBe(2); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas1?.destroy(); | ||
canvas2?.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,51 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartTooltipMultiChart(context) { | ||
const { container, canvas1, canvas2 } = context; | ||
|
||
const options = { | ||
type: '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', | ||
y: 'sold', | ||
}, | ||
interaction: { tooltip: { mount: 'body' } }, | ||
}; | ||
|
||
// View0 | ||
const view0Container = document.createElement('div'); | ||
container.appendChild(view0Container); | ||
|
||
const view0 = new Chart({ | ||
theme: 'classic', | ||
container: view0Container, | ||
canvas: canvas1, | ||
}); | ||
|
||
view0.options(options); | ||
|
||
const finished0 = view0.render(); | ||
|
||
// View1. | ||
const view1Container = document.createElement('div'); | ||
container.appendChild(view1Container); | ||
|
||
const view1 = new Chart({ | ||
theme: 'classic', | ||
container: view1Container, | ||
canvas: canvas2, | ||
}); | ||
|
||
view1.options(options); | ||
|
||
const finished1 = view1.render(); | ||
|
||
return { finished0, finished1 }; | ||
} |
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