-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart-render-update-attributes.ts
64 lines (53 loc) · 1.43 KB
/
chart-render-update-attributes.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
52
53
54
55
56
57
58
59
60
61
62
63
64
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({
container: wrapperDiv,
canvas,
});
const xy = { x: 'date', y: 'close' };
const options = {
type: 'line',
data: {
type: 'fetch',
value: 'data/aapl.csv',
transform: [{ type: 'slice', start: 0, end: 10 }],
},
encode: { ...xy, color: 'red' },
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,
encode: { ...xy, color: 'red' },
style: { lineDash: null },
});
lineDash = false;
chart.render().then(resolve1);
} else {
chart.options({
...options,
encode: { ...xy, color: undefined },
style: { lineDash: [5, 4] },
});
lineDash = true;
chart.render().then(resolve);
}
};
return { chart, button, finished, refreshed, refreshed1 };
}