-
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 (close: #4953)
- Loading branch information
Showing
5 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
__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,31 @@ | ||
import { chartRenderUpdateAttributes as render } from '../plots/api/chart-render-update-attributes'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('chart.options.autoFit', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createNodeGCanvas(800, 500); | ||
|
||
it('chart({ autoFit: true }) should fit parent container', 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(); | ||
}); | ||
}); |
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,67 @@ | ||
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', | ||
}, | ||
}; | ||
|
||
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
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