-
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(interaction): emit more brush and tooltip events
- Loading branch information
Showing
46 changed files
with
645 additions
and
47 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
__tests__/integration/api-chart-emit-enable-disable-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,103 @@ | ||
import './utils/useSnapshotMatchers'; | ||
import { Chart } from '../../src'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
import { sleep } from './utils/sleep'; | ||
import { dispatchFirstElementEvent, dispatchPlotEvent } from './utils/event'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
|
||
const data = [ | ||
{ date: '2007-04-23', close: 93.24 }, | ||
{ date: '2007-04-24', close: 95.35 }, | ||
{ date: '2007-04-25', close: 98.84 }, | ||
{ date: '2007-04-26', close: 99.92 }, | ||
{ date: '2007-04-29', close: 99.8 }, | ||
{ date: '2007-05-01', close: 99.47 }, | ||
{ date: '2007-05-02', close: 100.39 }, | ||
{ date: '2007-05-03', close: 100.4 }, | ||
{ date: '2007-05-04', close: 100.81 }, | ||
{ date: '2007-05-07', close: 103.92 }, | ||
]; | ||
|
||
function renderBar({ canvas, container }) { | ||
const chart = new Chart({ canvas, container }); | ||
chart.options({ | ||
type: 'interval', | ||
data, | ||
encode: { x: 'date', y: 'close' }, | ||
}); | ||
const finished = chart.render(); | ||
return { chart, finished }; | ||
} | ||
|
||
function renderLine({ canvas, container }) { | ||
const chart = new Chart({ canvas, container }); | ||
chart.options({ | ||
type: 'line', | ||
data, | ||
encode: { x: 'date', y: 'close' }, | ||
}); | ||
const finished = chart.render(); | ||
return { chart, finished }; | ||
} | ||
|
||
describe('chart.emit', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase( | ||
'chartEmitEnableDisableTooltip', | ||
)}`; | ||
const barCanvas = createDOMGCanvas(640, 480); | ||
const lineCanvas = createDOMGCanvas(640, 480); | ||
|
||
it('chart.emit enable item tooltip.', async () => { | ||
const { finished, chart } = renderBar({ | ||
canvas: barCanvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
chart.emit('tooltip:disable'); | ||
await sleep(20); | ||
|
||
dispatchFirstElementEvent(barCanvas, 'pointerover'); | ||
await expect(barCanvas).toMatchDOMSnapshot(dir, 'step0', { | ||
selector: '.g2-tooltip', | ||
}); | ||
|
||
chart.emit('tooltip:enable'); | ||
|
||
dispatchFirstElementEvent(barCanvas, 'pointerover'); | ||
await expect(barCanvas).toMatchDOMSnapshot(dir, 'step1', { | ||
selector: '.g2-tooltip', | ||
}); | ||
}); | ||
|
||
it('chart.emit enable series tooltip.', async () => { | ||
const { finished, chart } = renderLine({ | ||
canvas: lineCanvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
chart.emit('tooltip:disable'); | ||
dispatchPlotEvent(lineCanvas, 'pointermove', { | ||
offsetX: 100, | ||
offsetY: 100, | ||
}); | ||
await expect(lineCanvas).toMatchDOMSnapshot(dir, 'step2', { | ||
selector: '.g2-tooltip', | ||
}); | ||
|
||
chart.emit('tooltip:enable'); | ||
dispatchPlotEvent(lineCanvas, 'pointermove', { | ||
offsetX: 100, | ||
offsetY: 100, | ||
}); | ||
await expect(lineCanvas).toMatchDOMSnapshot(dir, 'step3', { | ||
selector: '.g2-tooltip', | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
barCanvas?.destroy(); | ||
lineCanvas?.destroy(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
__tests__/integration/api-chart-on-brush-highlight-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,38 @@ | ||
import { chartOnBrushHighlightTooltip as render } from '../plots/api/chart-on-brush-highlight-tooltip'; | ||
import { brush, dragMask } from '../plots/interaction/penguins-point-brush'; | ||
import './utils/useSnapshotMatchers'; | ||
import { PLOT_CLASS_NAME } from '../../src'; | ||
import { createPromise } from './utils/event'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
import { sleep } from './utils/sleep'; | ||
|
||
describe('chart.on', () => { | ||
const canvas = createDOMGCanvas(640, 480); | ||
|
||
it('chart.on should on brush events.', async () => { | ||
const { finished, chart } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
const { document: gDocument } = canvas; | ||
const plot = gDocument.getElementsByClassName(PLOT_CLASS_NAME)[0]; | ||
|
||
const [start, resolveStart] = createPromise(); | ||
chart.on('brush:start', resolveStart); | ||
brush(plot, 100, 100, 300, 300); | ||
await start; | ||
await sleep(20); | ||
|
||
const [update, resolveUpdate] = createPromise(); | ||
chart.on('brush:end', resolveUpdate); | ||
dragMask(plot, 30, 30, 60, 60); | ||
await update; | ||
await sleep(20); | ||
}); | ||
|
||
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
1 change: 1 addition & 0 deletions
1
__tests__/integration/snapshots/api/chart-emit-enable-disable-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-enable-disable-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: 10px; top: 10px;" | ||
> | ||
<div | ||
class="g2-tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
2007-04-23 | ||
</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(23, 131, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="g2-tooltip-list-item-name-label" | ||
title="close" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
close | ||
</span> | ||
</span> | ||
<span | ||
class="g2-tooltip-list-item-value" | ||
title="93.24" | ||
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;" | ||
> | ||
93.24 | ||
</span> | ||
</li> | ||
</ul> | ||
</div> |
46 changes: 46 additions & 0 deletions
46
__tests__/integration/snapshots/api/chart-emit-enable-disable-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: 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: 10px; top: 10px;" | ||
> | ||
<div | ||
class="g2-tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
2007-04-23 | ||
</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(23, 131, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="g2-tooltip-list-item-name-label" | ||
title="close" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
close | ||
</span> | ||
</span> | ||
<span | ||
class="g2-tooltip-list-item-value" | ||
title="93.24" | ||
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;" | ||
> | ||
93.24 | ||
</span> | ||
</li> | ||
</ul> | ||
</div> |
46 changes: 46 additions & 0 deletions
46
__tests__/integration/snapshots/api/chart-emit-enable-disable-tooltip/step3.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: 10px; top: 10px;" | ||
> | ||
<div | ||
class="g2-tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
2007-04-23 | ||
</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(23, 131, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="g2-tooltip-list-item-name-label" | ||
title="close" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
close | ||
</span> | ||
</span> | ||
<span | ||
class="g2-tooltip-list-item-value" | ||
title="93.24" | ||
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;" | ||
> | ||
93.24 | ||
</span> | ||
</li> | ||
</ul> | ||
</div> |
Binary file modified
BIN
+90 Bytes
(100%)
__tests__/integration/snapshots/api/chart-on-focus-context/step2-context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+795 Bytes
(120%)
__tests__/integration/snapshots/api/chart-on-focus-context/step2-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-90 Bytes
(99%)
__tests__/integration/snapshots/api/chart-on-focus-context/step5-context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-424 Bytes
(94%)
__tests__/integration/snapshots/api/chart-on-focus-context/step5-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.8 KB
(100%)
...integration/snapshots/interaction/penguins-point-brush-handle-custom/step10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.93 KB
(100%)
...integration/snapshots/interaction/penguins-point-brush-handle-custom/step11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.16 KB
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+659 Bytes
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.18 KB
(98%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+625 Bytes
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.3 KB
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-139 Bytes
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.91 KB
(100%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4.98 KB
(94%)
.../integration/snapshots/interaction/penguins-point-brush-handle-custom/step9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.99 KB
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+950 Bytes
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+580 Bytes
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.23 KB
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.75 KB
(98%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+327 Bytes
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.39 KB
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-285 Bytes
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.6 KB
(100%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.21 KB
(96%)
__tests__/integration/snapshots/interaction/penguins-point-brush/step9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.