-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart-auto-fit-width.ts
51 lines (41 loc) · 1.2 KB
/
chart-auto-fit-width.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Chart } from '../../../src';
export function chartAutoFitWidth(context) {
const { container, canvas } = context;
// button
const button = document.createElement('button');
button.innerText = 'Change Wrapper Container';
container.appendChild(button);
// wrapperDiv
const wrapperDiv = document.createElement('div');
wrapperDiv.style.width = '800px';
wrapperDiv.style.height = '500px';
container.appendChild(wrapperDiv);
const chart = new Chart({
container: wrapperDiv,
autoFit: true,
width: 200,
canvas,
});
chart.data([
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
]);
chart
.interval()
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre')
.axis({ x: { animate: false }, y: { animate: false } });
const finished = chart.render();
let resolve;
const fitted = new Promise((r) => (resolve = r));
button.onclick = () => {
wrapperDiv.style.width = '400px';
wrapperDiv.style.height = '500px';
chart.forceFit().then(resolve);
};
return { chart, button, finished, fitted };
}