/
selection_heatmap.vg.json
188 lines (188 loc) · 5.35 KB
/
selection_heatmap.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
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"style": "cell",
"data": [
{
"name": "highlight_store",
"transform": [{"type": "collect", "sort": {"field": "_vgsid_"}}]
},
{
"name": "source_0",
"values": [
{"actual": "A", "predicted": "A", "count": 13},
{"actual": "A", "predicted": "B", "count": 0},
{"actual": "A", "predicted": "C", "count": 0},
{"actual": "B", "predicted": "A", "count": 0},
{"actual": "B", "predicted": "B", "count": 10},
{"actual": "B", "predicted": "C", "count": 6},
{"actual": "C", "predicted": "A", "count": 0},
{"actual": "C", "predicted": "B", "count": 0},
{"actual": "C", "predicted": "C", "count": 9}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{"type": "identifier", "as": "_vgsid_"},
{
"type": "filter",
"expr": "isValid(datum[\"count\"]) && isFinite(+datum[\"count\"])"
}
]
}
],
"signals": [
{"name": "x_step", "value": 40},
{"name": "width", "update": "bandspace(domain('x').length, 0, 0) * x_step"},
{"name": "y_step", "value": 40},
{
"name": "height",
"update": "bandspace(domain('y').length, 0, 0) * y_step"
},
{
"name": "unit",
"value": {},
"on": [
{"events": "mousemove", "update": "isTuple(group()) ? group() : unit"}
]
},
{
"name": "highlight",
"update": "vlSelectionResolve(\"highlight_store\", \"union\", true, true)"
},
{
"name": "highlight_tuple",
"on": [
{
"events": [{"source": "scope", "type": "click"}],
"update": "datum && item().mark.marktype !== 'group' && indexof(item().mark.role, 'legend') < 0 ? {unit: \"\", _vgsid_: (item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]} : null",
"force": true
},
{"events": [{"source": "view", "type": "dblclick"}], "update": "null"}
]
},
{
"name": "highlight_toggle",
"value": false,
"on": [
{
"events": [{"source": "scope", "type": "click"}],
"update": "event.shiftKey"
},
{"events": [{"source": "view", "type": "dblclick"}], "update": "false"}
]
},
{
"name": "highlight_modify",
"on": [
{
"events": {"signal": "highlight_tuple"},
"update": "modify(\"highlight_store\", highlight_toggle ? null : highlight_tuple, highlight_toggle ? null : true, highlight_toggle ? highlight_tuple : null)"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "rect",
"style": ["rect"],
"interactive": true,
"from": {"data": "data_0"},
"encode": {
"update": {
"strokeWidth": {"value": 2},
"fill": {"scale": "fill", "field": "count"},
"stroke": [
{
"test": "length(data(\"highlight_store\")) && vlSelectionIdTest(\"highlight_store\", datum)",
"value": "black"
},
{"value": null}
],
"opacity": [
{
"test": "!length(data(\"highlight_store\")) || vlSelectionIdTest(\"highlight_store\", datum)",
"value": 1
},
{"value": 0.5}
],
"zindex": [
{
"test": "!length(data(\"highlight_store\")) || vlSelectionIdTest(\"highlight_store\", datum)",
"value": 1
},
{"value": 0}
],
"description": {
"signal": "\"predicted: \" + (isValid(datum[\"predicted\"]) ? datum[\"predicted\"] : \"\"+datum[\"predicted\"]) + \"; actual: \" + (isValid(datum[\"actual\"]) ? datum[\"actual\"] : \"\"+datum[\"actual\"]) + \"; count: \" + (format(datum[\"count\"], \"\"))"
},
"x": {"scale": "x", "field": "predicted"},
"width": {"scale": "x", "band": 1},
"y": {"scale": "y", "field": "actual"},
"height": {"scale": "y", "band": 1}
}
}
}
],
"scales": [
{
"name": "x",
"type": "band",
"domain": {"data": "data_0", "field": "predicted", "sort": true},
"range": {"step": {"signal": "x_step"}},
"paddingInner": 0,
"paddingOuter": 0
},
{
"name": "y",
"type": "band",
"domain": {"data": "data_0", "field": "actual", "sort": true},
"range": {"step": {"signal": "y_step"}},
"paddingInner": 0,
"paddingOuter": 0
},
{
"name": "fill",
"type": "linear",
"domain": {"data": "data_0", "field": "count"},
"range": "heatmap",
"interpolate": "hcl",
"zero": false
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "predicted",
"labelAlign": "right",
"labelAngle": 270,
"labelBaseline": "middle",
"zindex": 1
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "actual",
"zindex": 1
}
],
"legends": [
{
"fill": "fill",
"gradientLength": {"signal": "clamp(height, 64, 200)"},
"title": "count",
"encode": {"gradient": {"update": {"opacity": {"value": 1}}}}
}
],
"config": {
"range": {"ramp": {"scheme": "yellowgreenblue"}},
"axis": {"domain": false}
}
}