-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart-emit-brush-highlight-axis-cross.ts
69 lines (57 loc) · 1.5 KB
/
chart-emit-brush-highlight-axis-cross.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
65
66
67
68
69
import { Chart } from '../../../src';
export function chartEmitBrushHighlightAxisCross(context) {
const { container, canvas } = context;
// button
const button1 = document.createElement('button');
button1.innerText = 'Highlight';
container.appendChild(button1);
const button2 = document.createElement('button');
button2.innerText = 'Reset';
container.appendChild(button2);
// wrapperDiv
const wrapperDiv = document.createElement('div');
container.appendChild(wrapperDiv);
const chart = new Chart({
container: wrapperDiv,
canvas,
});
chart.options({
type: 'point',
data: {
type: 'fetch',
value: 'data/penguins.csv',
},
encode: {
color: 'species',
x: 'culmen_length_mm',
y: 'culmen_depth_mm',
},
state: { inactive: { stroke: 'gray', opacity: 0.5 } },
interaction: {
brushAxisHighlight: true,
},
});
const finished = chart.render();
chart.on('brushAxis:highlight', (event) => {
const { data, nativeEvent } = event;
if (nativeEvent) console.log('brushAxis:highlight', data);
});
chart.on('brushAxis:remove', (event) => {
const { data, nativeEvent } = event;
if (nativeEvent) console.log('brushAxis:remove', data);
});
button1.onclick = () => {
chart.emit('brushAxis:highlight', {
data: {
selection: [
[40, 50],
[14, 18],
],
},
});
};
button2.onclick = () => {
chart.emit('brushAxis:remove', {});
};
return { chart, finished };
}