-
Notifications
You must be signed in to change notification settings - Fork 592
/
bar_axis_space_saving.vg.json
112 lines (112 loc) · 2.74 KB
/
bar_axis_space_saving.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
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Bar Chart with a spacing-saving y-axis",
"background": "white",
"padding": 5,
"width": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"url": "data/cars.json",
"format": {"type": "json"},
"transform": [
{
"type": "aggregate",
"groupby": ["Origin"],
"ops": ["count"],
"fields": [null],
"as": ["__count"]
}
]
}
],
"signals": [
{"name": "y_step", "value": 50},
{"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"}
],
"marks": [
{
"name": "marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "source_0"},
"encode": {
"update": {
"cornerRadiusTopRight": {"value": 2},
"cornerRadiusBottomRight": {"value": 2},
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "bar"},
"description": {
"signal": "\"Number of Cars: \" + (format(datum[\"__count\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])"
},
"x": {"scale": "x", "field": "__count"},
"x2": {"scale": "x", "value": 0},
"y": {"scale": "y", "field": "Origin", "offset": 5, "band": 0.25},
"height": {"signal": "max(0.25, 0.5 * bandwidth('y'))"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {"data": "source_0", "field": "__count"},
"range": [0, {"signal": "width"}],
"nice": true,
"zero": true
},
{
"name": "y",
"type": "band",
"domain": {"data": "source_0", "field": "Origin", "sort": true},
"range": {"step": {"signal": "y_step"}},
"padding": 0
}
],
"axes": [
{
"scale": "y",
"orient": "left",
"bandPosition": 0,
"grid": true,
"gridScale": "x",
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "Number of Cars",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Origin",
"bandPosition": 0,
"domain": false,
"labelAlign": "left",
"labelBaseline": "middle",
"labelOffset": -15,
"labelPadding": -5,
"ticks": false,
"titleAlign": "left",
"titleX": 5,
"titleY": -5,
"titleAngle": 0,
"zindex": 0
}
]
}