-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
cars3-line-brush-axis.ts
87 lines (85 loc) · 2.1 KB
/
cars3-line-brush-axis.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
import { G2Spec } from '../../../src';
import { AXIS_HOT_AREA_CLASS_NAME } from '../../../src/interaction/brushAxisHighlight';
import { brush } from './penguins-point-brush';
export function cars3LineBrushAxis(): G2Spec {
const position = [
'economy (mpg)',
'cylinders',
'displacement (cc)',
'power (hp)',
'weight (lb)',
'0-60 mph (s)',
'year',
];
return {
type: 'view',
height: 800,
coordinate: { type: 'parallel', transform: [{ type: 'transpose' }] },
children: [
{
type: 'line',
data: {
type: 'fetch',
value: 'data/cars3.csv',
},
encode: {
position,
color: 'cylinders',
},
style: {
lineWidth: 1.5,
strokeOpacity: 0.4,
},
scale: {
color: { palette: 'brBG', offset: (t) => 1 - t },
},
legend: false,
state: {
inactive: { stroke: 'grey', opacity: 0.5 },
},
axis: Object.fromEntries(
Array.from({ length: position.length }, (_, i) => [
`position${i === 0 ? '' : i}`,
{
zIndex: 1,
line: true,
tick: true,
labelStroke: '#fff',
labelLineWidth: 5,
labelFontSize: 10,
labelStrokeLineJoin: 'round',
titleStroke: '#fff',
titleFontSize: 10,
titleLineWidth: 5,
titleStrokeLineJoin: 'round',
lineStroke: 'black',
tickStroke: 'black',
lineLineWidth: 1,
},
]),
),
},
],
interaction: {
brushAxisHighlight: true,
tooltip: { series: false },
},
};
}
cars3LineBrushAxis.steps = ({ canvas }) => {
const { document } = canvas;
const axes = document.getElementsByClassName(AXIS_HOT_AREA_CLASS_NAME);
const [, axis1, axis2] = axes;
return [
{
changeState: () => {
brush(axis1, 50, 60, 400, 60);
},
},
{
changeState: () => {
brush(axis2, 200, 60, 300, 60);
},
},
];
};