forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperatures-line-marker.ts
60 lines (58 loc) · 1.55 KB
/
temperatures-line-marker.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
import { CustomEvent } from '@antv/g';
import { G2Spec, PLOT_CLASS_NAME } from '../../../src';
import { temperatures } from '../../data/temperatures';
export function temperatureLineMarker(): G2Spec {
return {
type: 'line',
data: temperatures,
encode: {
x: 'month',
y: 'temperature',
color: 'city',
},
interaction: {
tooltip: {
render: (event, { items }) => {
const target = event.target;
const format = (item) => `${item.name}: ${item.value}`;
if (target.className === 'g2-tooltip-marker') {
const color = target.style.fill;
const item = items.find((i) => i.color === color);
return format(item);
}
return items.map(format).join('<br>');
},
},
},
};
}
temperatureLineMarker.steps = ({ canvas }) => {
const { document } = canvas;
const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[0];
return [
{
changeState: async () => {
plot.dispatchEvent(
new CustomEvent('pointermove', {
offsetX: 200,
offsetY: 300,
}),
);
},
},
{
changeState: async () => {
const marker = plot.getElementsByClassName('g2-tooltip-marker')[0];
const bbox = marker.getBBox();
const x = bbox.x + bbox.width / 2;
const y = bbox.y + bbox.height / 2;
marker.dispatchEvent(
new CustomEvent('pointermove', {
offsetX: x,
offsetY: y,
}),
);
},
},
];
};