-
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: chart.options changeData problem (#4936)
- Loading branch information
1 parent
e8ac19a
commit 99bdec2
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
__tests__/integration/api-chart-options-change-data.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,26 @@ | ||
import { chartOptionsChangeData as render } from '../plots/api/chart-options-change-data'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { sleep } from './utils/sleep'; | ||
import './utils/useSnapshotMatchers'; | ||
import './utils/useCustomFetch'; | ||
|
||
describe('chart.options.changeData', () => { | ||
const canvas = createNodeGCanvas(800, 500); | ||
|
||
it('chart.options.changeData should rerender expected chart', async () => { | ||
const { finished, button, chart } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
button.dispatchEvent(new CustomEvent('click')); | ||
await new Promise<void>((resolve) => chart.on('afterrender', resolve)); | ||
const dir = `${__dirname}/snapshots/api`; | ||
await sleep(20); | ||
await expect(canvas).toMatchCanvasSnapshot(dir, render.name); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartOptionsChangeData(context) { | ||
const { container, canvas } = context; | ||
|
||
const button = document.createElement('button'); | ||
button.innerText = 'Update Data'; | ||
button.style.display = 'block'; | ||
container.appendChild(button); | ||
|
||
const div = document.createElement('div'); | ||
container.appendChild(div); | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container, | ||
canvas, | ||
}); | ||
|
||
chart.options({ | ||
type: 'interval', | ||
coordinate: { type: 'theta' }, | ||
transform: [{ type: 'stackY' }], | ||
data: [ | ||
{ genre: 'Sports', sold: 275 }, | ||
{ genre: 'Strategy', sold: 115 }, | ||
{ genre: 'Action', sold: 120 }, | ||
{ genre: 'Shooter', sold: 350 }, | ||
{ genre: 'Other', sold: 150 }, | ||
], | ||
encode: { | ||
y: 'sold', | ||
color: 'genre', | ||
}, | ||
animate: { | ||
enter: { | ||
type: 'waveIn', | ||
}, | ||
}, | ||
}); | ||
|
||
const finished = chart.render(); | ||
|
||
button.onclick = () => { | ||
chart.changeData([ | ||
{ genre: 'Sports', sold: 275 }, | ||
{ genre: 'Strategy', sold: 115 }, | ||
]); | ||
}; | ||
|
||
return { chart, finished, button }; | ||
} |
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