forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather-line-legend-mark.ts
106 lines (104 loc) · 2.42 KB
/
weather-line-legend-mark.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { G2Spec } from '../../../src';
import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter';
import { weather } from '../../data/weather';
import { step } from './utils';
export function weatherLineLegendMark(): G2Spec {
const labelByValue = {
'#EE6666': 'Temperature',
'#5470C6': 'Evaporation',
'#91CC75': 'Precipitation',
};
const markerByValue = {
'#EE6666': 'line',
'#5470C6': 'rect',
'#91CC75': 'line',
};
return {
type: 'view',
data: weather,
children: [
{
type: 'line',
encode: {
x: 'Month',
y: 'Temperature',
color: '#EE6666',
shape: 'smooth',
},
scale: {
y: { independent: true, domainMax: 30 },
},
axis: {
y: {
title: 'Temperature (°C)',
grid: false,
titleFill: '#EE6666',
},
},
},
{
type: 'interval',
encode: {
x: 'Month',
y: 'Evaporation',
color: '#5470C6',
},
scale: {
y: { independent: true, domainMax: 200 },
},
style: {
fillOpacity: 0.8,
},
axis: {
y: {
title: 'Evaporation (°C)',
grid: null,
titleFill: '#5470C6',
},
},
},
{
type: 'line',
encode: {
x: 'Month',
y: 'Precipitation',
color: '#91CC75',
},
scale: {
y: { independent: true },
},
style: {
lineWidth: 2,
lineDash: [2, 2],
},
axis: {
y: {
position: 'right',
title: 'Precipitation (ml)',
grid: false,
titleFill: '#91CC75',
},
},
},
{
type: 'legends',
scale: {
color: {
type: 'ordinal',
independent: true,
domain: ['#EE6666', '#91CC75', '#5470C6'],
range: ['#EE6666', '#91CC75', '#5470C6'],
},
},
itemMarker: (d) => markerByValue[d],
labelFormatter: (d) => labelByValue[d],
},
],
};
}
weatherLineLegendMark.steps = ({ canvas }) => {
const { document } = canvas;
const elements = document.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME);
const [, , e2] = elements;
return [step(e2, 'click'), step(e2, 'click')];
};