-
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(animation): update non-transform attribute and replace node witho…
…ut animation (#5019) * fix(animation): update non-transform attribute (close: #4953) * fix(animation): non animation replace node (close: #5006) * fix: ci
- Loading branch information
Showing
11 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
__tests__/integration/api-chart-render-update-attribute.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,32 @@ | ||
import { chartRenderUpdateAttributes as render } from '../plots/api/chart-render-update-attributes'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import './utils/useCustomFetch'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('chart.render', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createNodeGCanvas(800, 500); | ||
|
||
it('chart.render() should update attribute without animation', async () => { | ||
const { finished, chart, refreshed, refreshed1, button, ...rest } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
// To lineDash | ||
button.dispatchEvent(new CustomEvent('click')); | ||
await refreshed; | ||
await expect(canvas).toMatchCanvasSnapshot(dir, 'step0'); | ||
|
||
// Reset | ||
button.dispatchEvent(new CustomEvent('click')); | ||
await refreshed1; | ||
await expect(canvas).toMatchCanvasSnapshot(dir, 'step1'); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
__tests__/integration/api-chart-render-update-non-animation.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 { chartRenderUpdateNonAnimation as render } from '../plots/api/chart-render-update-non-animation'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import './utils/useCustomFetch'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('chart.render', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createNodeGCanvas(800, 500); | ||
|
||
it('chart.render() should update non animation node.', async () => { | ||
const { finished, chart, refreshed, button, ...rest } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
|
||
button.dispatchEvent(new CustomEvent('click')); | ||
await refreshed; | ||
await expect(canvas).toMatchCanvasSnapshot(dir, 'step0'); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
Binary file added
BIN
+11.7 KB
__tests__/integration/snapshots/api/chart-render-update-attributes/step0.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 added
BIN
+13.7 KB
__tests__/integration/snapshots/api/chart-render-update-attributes/step1.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 added
BIN
+9.45 KB
__tests__/integration/snapshots/api/chart-render-update-non-animation/step0.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartRenderUpdateAttributes(context) { | ||
const { container, canvas } = context; | ||
|
||
// button | ||
const button = document.createElement('button'); | ||
button.innerText = 'Rerender'; | ||
container.appendChild(button); | ||
|
||
// wrapperDiv | ||
const wrapperDiv = document.createElement('div'); | ||
container.appendChild(wrapperDiv); | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container: wrapperDiv, | ||
canvas, | ||
}); | ||
|
||
const options = { | ||
type: 'line', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/aapl.csv', | ||
transform: [{ type: 'slice', start: 0, end: 10 }], | ||
}, | ||
encode: { | ||
x: 'date', | ||
y: 'close', | ||
}, | ||
axis: { x: false }, | ||
}; | ||
|
||
chart.options(options); | ||
|
||
const finished = chart.render(); | ||
|
||
let resolve; | ||
let resolve1; | ||
const refreshed = new Promise((r) => (resolve = r)); | ||
const refreshed1 = new Promise((r) => (resolve1 = r)); | ||
|
||
let lineDash = false; | ||
button.onclick = () => { | ||
if (lineDash) { | ||
chart.options({ | ||
...options, | ||
style: { | ||
lineDash: null, | ||
}, | ||
}); | ||
lineDash = false; | ||
chart.render().then(resolve1); | ||
} else { | ||
chart.options({ | ||
...options, | ||
style: { | ||
lineDash: [5, 4], | ||
}, | ||
}); | ||
lineDash = true; | ||
chart.render().then(resolve); | ||
} | ||
}; | ||
|
||
return { chart, button, finished, refreshed, refreshed1 }; | ||
} |
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,53 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartRenderUpdateNonAnimation(context) { | ||
const { container, canvas } = context; | ||
|
||
// button | ||
const button = document.createElement('button'); | ||
button.innerText = 'Rerender'; | ||
container.appendChild(button); | ||
|
||
// wrapperDiv | ||
const wrapperDiv = document.createElement('div'); | ||
container.appendChild(wrapperDiv); | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container: wrapperDiv, | ||
canvas, | ||
}); | ||
|
||
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', | ||
}, | ||
animate: false, | ||
}; | ||
|
||
chart.options(options); | ||
|
||
const finished = chart.render(); | ||
|
||
let resolve; | ||
const refreshed = new Promise((r) => (resolve = r)); | ||
|
||
button.onclick = () => { | ||
chart.options({ | ||
...options, | ||
type: 'point', | ||
}); | ||
chart.render().then(resolve); | ||
}; | ||
|
||
return { chart, button, finished, refreshed }; | ||
} |
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
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