-
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): disableNative (#5236)
- Loading branch information
Showing
10 changed files
with
250 additions
and
30 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
__tests__/integration/api-chart-emit-click-tooltip.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,41 @@ | ||
import { chartEmitClickTooltip as render } from '../plots/api/chart-emit-click-tooltip'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import { dispatchFirstElementEvent, dispatchPlotEvent } from './utils/event'; | ||
import './utils/useSnapshotMatchers'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
|
||
describe('chart.emit', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createDOMGCanvas(640, 480); | ||
|
||
it('chart.tooltip should disable native events.', async () => { | ||
const { finished } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
// Disable native events. | ||
dispatchFirstElementEvent(canvas, 'pointerover'); | ||
|
||
await expect(canvas).toMatchDOMSnapshot(dir, 'step0', { | ||
selector: '.g2-tooltip', | ||
}); | ||
|
||
// Click item to show tooltip. | ||
dispatchFirstElementEvent(canvas, 'click', { detail: 1 }); | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step1', { | ||
selector: '.g2-tooltip', | ||
}); | ||
|
||
// Click plot to hide tooltip. | ||
dispatchPlotEvent(canvas, 'click', { detail: 1 }); | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step2', { | ||
selector: '.g2-tooltip', | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
__tests__/integration/snapshots/api/chart-emit-click-tooltip/step0.html
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 @@ | ||
null |
46 changes: 46 additions & 0 deletions
46
__tests__/integration/snapshots/api/chart-emit-click-tooltip/step1.html
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,46 @@ | ||
<div | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
class="g2-tooltip" | ||
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: Roboto-Regular; left: 115.93137230592615px; top: 289.8214318411691px;" | ||
> | ||
<div | ||
class="g2-tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
Sports | ||
</div> | ||
<ul | ||
class="g2-tooltip-list" | ||
style="margin: 0px; list-style-type: none; padding: 0px;" | ||
> | ||
<li | ||
class="g2-tooltip-list-item" | ||
data-index="0" | ||
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;" | ||
> | ||
<span | ||
class="g2-tooltip-list-item-name" | ||
style="display: flex; align-items: center; max-width: 216px;" | ||
> | ||
<span | ||
class="g2-tooltip-list-item-marker" | ||
style="background: rgb(91, 143, 249); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="g2-tooltip-list-item-name-label" | ||
title="sold" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
sold | ||
</span> | ||
</span> | ||
<span | ||
class="g2-tooltip-list-item-value" | ||
title="275" | ||
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
275 | ||
</span> | ||
</li> | ||
</ul> | ||
</div>; |
46 changes: 46 additions & 0 deletions
46
__tests__/integration/snapshots/api/chart-emit-click-tooltip/step2.html
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,46 @@ | ||
<div | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
class="g2-tooltip" | ||
style="pointer-events: none; position: absolute; visibility: hidden; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: Roboto-Regular; left: 115.93137230592615px; top: 289.8214318411691px;" | ||
> | ||
<div | ||
class="g2-tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
Sports | ||
</div> | ||
<ul | ||
class="g2-tooltip-list" | ||
style="margin: 0px; list-style-type: none; padding: 0px;" | ||
> | ||
<li | ||
class="g2-tooltip-list-item" | ||
data-index="0" | ||
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;" | ||
> | ||
<span | ||
class="g2-tooltip-list-item-name" | ||
style="display: flex; align-items: center; max-width: 216px;" | ||
> | ||
<span | ||
class="g2-tooltip-list-item-marker" | ||
style="background: rgb(91, 143, 249); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="g2-tooltip-list-item-name-label" | ||
title="sold" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
sold | ||
</span> | ||
</span> | ||
<span | ||
class="g2-tooltip-list-item-value" | ||
title="275" | ||
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
275 | ||
</span> | ||
</li> | ||
</ul> | ||
</div>; |
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,40 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartEmitClickTooltip(context) { | ||
const { container, canvas } = context; | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container: container, | ||
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', { disableNative: true }); | ||
|
||
const finished = chart.render(); | ||
|
||
chart.on('element:click', ({ data }) => { | ||
chart.emit('tooltip:show', { data }); | ||
}); | ||
|
||
chart.on('plot:click', () => { | ||
chart.emit('tooltip:hide'); | ||
}); | ||
|
||
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
25 changes: 25 additions & 0 deletions
25
site/examples/interaction/interaction/demo/tooltip-click.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,25 @@ | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
theme: 'classic', | ||
autoFit: true, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data({ | ||
type: 'fetch', | ||
value: | ||
'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv', | ||
}) | ||
.encode('x', 'letter') | ||
.encode('y', 'frequency') | ||
.axis('y', { labelFormatter: '.0%' }) | ||
.interaction('tooltip', { disableNative: true }); // Disable pointerover and pointerout events. | ||
|
||
chart.on('element:click', ({ data }) => chart.emit('tooltip:show', { data })); | ||
|
||
chart.on('plot:click', () => chart.emit('tooltip:hide')); | ||
|
||
chart.render(); |
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