-
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(shape): update group shape without animation (#5514)
- Loading branch information
Showing
6 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
__tests__/integration/api-chart-change-size-custom-shape.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,25 @@ | ||
import { chartChangeSizeCustomShape as render } from '../plots/api/chart-change-size-custom-shape'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { sleep } from './utils/sleep'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('mark.changeSize', () => { | ||
const canvas = createNodeGCanvas(640, 480); | ||
|
||
it('mark.changeSize(width, height) 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('afterchangesize', 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,63 @@ | ||
import { Chart, register } from '../../../src'; | ||
|
||
export function chartChangeSizeCustomShape(context) { | ||
const { container, canvas } = context; | ||
|
||
const button = document.createElement('button'); | ||
button.innerText = 'Update Size'; | ||
button.style.display = 'block'; | ||
container.appendChild(button); | ||
|
||
const div = document.createElement('div'); | ||
container.appendChild(div); | ||
|
||
register('shape.interval.triangle', (style, context) => { | ||
const { document } = context; | ||
return (P, value, defaults) => { | ||
const { color: defaultColor } = defaults; | ||
const [p0, p1, p2, p3] = P; | ||
const pm = [(p0[0] + p1[0]) / 2, p0[1]]; | ||
const { color = defaultColor } = value; | ||
const group = document.createElement('g'); | ||
const polygon = document.createElement('polygon', { | ||
style: { | ||
...style, | ||
fill: color, | ||
points: [pm, p2, p3], | ||
}, | ||
}); | ||
group.appendChild(polygon); | ||
return group; | ||
}; | ||
}); | ||
|
||
const chart = new Chart({ | ||
container: div, | ||
canvas, | ||
}); | ||
|
||
chart | ||
.interval() | ||
.data([ | ||
{ genre: 'Sports', sold: 275 }, | ||
{ genre: 'Strategy', sold: 115 }, | ||
{ genre: 'Action', sold: 120 }, | ||
{ genre: 'Shooter', sold: 350 }, | ||
{ genre: 'Infantry', sold: 220 }, | ||
{ genre: 'Logistics', sold: 330 }, | ||
{ genre: 'Other', sold: 150 }, | ||
]) | ||
.encode('x', 'genre') | ||
.encode('y', 'sold') | ||
.encode('color', 'genre') | ||
.style('shape', 'triangle') | ||
.animate(false); | ||
|
||
const finished = chart.render(); | ||
|
||
button.onclick = () => { | ||
chart.changeSize(400, 300); | ||
}; | ||
|
||
return { chart, button, 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