/
interactive_point_init.vg.json
204 lines (204 loc) · 5.29 KB
/
interactive_point_init.vg.json
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{
"name": "CylYr_store",
"values": [
{
"unit": "",
"fields": [
{"type": "E", "field": "Cylinders"},
{"type": "E", "field": "Year"}
],
"values": [4, 1981]
},
{
"unit": "",
"fields": [
{"type": "E", "field": "Cylinders"},
{"type": "E", "field": "Year"}
],
"values": [8, 1972]
}
]
},
{
"name": "source_0",
"url": "data/cars.json",
"format": {"type": "json"},
"transform": [
{"type": "formula", "expr": "year(datum.Year)", "as": "Year"},
{
"type": "filter",
"expr": "isValid(datum[\"Horsepower\"]) && isFinite(+datum[\"Horsepower\"]) && isValid(datum[\"Miles_per_Gallon\"]) && isFinite(+datum[\"Miles_per_Gallon\"])"
}
]
}
],
"signals": [
{
"name": "unit",
"value": {},
"on": [
{"events": "mousemove", "update": "isTuple(group()) ? group() : unit"}
]
},
{
"name": "CylYr",
"update": "vlSelectionResolve(\"CylYr_store\", \"union\", true, true)"
},
{
"name": "CylYr_tuple",
"on": [
{
"events": [{"source": "scope", "type": "click"}],
"update": "datum && item().mark.marktype !== 'group' && indexof(item().mark.role, 'legend') < 0 ? {unit: \"\", fields: CylYr_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"Cylinders\"], (item().isVoronoi ? datum.datum : datum)[\"Year\"]]} : null",
"force": true
},
{"events": [{"source": "view", "type": "dblclick"}], "update": "null"}
]
},
{
"name": "CylYr_tuple_fields",
"value": [
{"type": "E", "field": "Cylinders"},
{"type": "E", "field": "Year"}
]
},
{
"name": "CylYr_toggle",
"value": false,
"on": [
{
"events": [{"source": "scope", "type": "click"}],
"update": "event.shiftKey"
},
{"events": [{"source": "view", "type": "dblclick"}], "update": "false"}
]
},
{
"name": "CylYr_modify",
"on": [
{
"events": {"signal": "CylYr_tuple"},
"update": "modify(\"CylYr_store\", CylYr_toggle ? null : CylYr_tuple, CylYr_toggle ? null : true, CylYr_toggle ? CylYr_tuple : null)"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "symbol",
"style": ["circle"],
"interactive": true,
"from": {"data": "source_0"},
"encode": {
"update": {
"opacity": {"value": 0.7},
"fill": [
{
"test": "!length(data(\"CylYr_store\")) || vlSelectionTest(\"CylYr_store\", datum)",
"scale": "color",
"field": "Origin"
},
{"value": "grey"}
],
"ariaRoleDescription": {"value": "circle"},
"description": {
"signal": "\"Horsepower: \" + (format(datum[\"Horsepower\"], \"\")) + \"; Miles_per_Gallon: \" + (format(datum[\"Miles_per_Gallon\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])"
},
"x": {"scale": "x", "field": "Horsepower"},
"y": {"scale": "y", "field": "Miles_per_Gallon"},
"shape": {"value": "circle"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {"data": "source_0", "field": "Horsepower"},
"range": [0, {"signal": "width"}],
"nice": true,
"zero": true
},
{
"name": "y",
"type": "linear",
"domain": {"data": "source_0", "field": "Miles_per_Gallon"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "source_0", "field": "Origin", "sort": true},
"range": "category"
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"gridScale": "x",
"grid": true,
"tickCount": {"signal": "ceil(height/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "Horsepower",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Miles_per_Gallon",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
],
"legends": [
{
"fill": "color",
"symbolType": "circle",
"title": "Origin",
"encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}}
}
]
}