Skip to content

Commit f973292

Browse files
authored
Create radial-tree-layout.vg.json
1 parent b6a7314 commit f973292

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

ex/radial-tree-layout.vg.json

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"$schema": "https://vega.github.io/schema/vega/v5.json",
3+
"description": "An example of a radial layout for a node-link diagram of hierarchical data.",
4+
"width": 720,
5+
"height": 720,
6+
"padding": 5,
7+
"autosize": "none",
8+
9+
"signals": [
10+
{
11+
"name": "labels", "value": true,
12+
"bind": {"input": "checkbox"}
13+
},
14+
{
15+
"name": "radius", "value": 280,
16+
"bind": {"input": "range", "min": 20, "max": 600}
17+
},
18+
{
19+
"name": "extent", "value": 360,
20+
"bind": {"input": "range", "min": 0, "max": 360, "step": 1}
21+
},
22+
{
23+
"name": "rotate", "value": 0,
24+
"bind": {"input": "range", "min": 0, "max": 360, "step": 1}
25+
},
26+
{
27+
"name": "layout", "value": "tidy",
28+
"bind": {"input": "radio", "options": ["tidy", "cluster"]}
29+
},
30+
{
31+
"name": "links", "value": "line",
32+
"bind": {
33+
"input": "select",
34+
"options": ["line", "curve", "diagonal", "orthogonal"]
35+
}
36+
},
37+
{ "name": "originX", "update": "width / 2" },
38+
{ "name": "originY", "update": "height / 2" }
39+
],
40+
41+
"data": [
42+
{
43+
"name": "tree",
44+
"url": "data/flare.json",
45+
"transform": [
46+
{
47+
"type": "stratify",
48+
"key": "id",
49+
"parentKey": "parent"
50+
},
51+
{
52+
"type": "tree",
53+
"method": {"signal": "layout"},
54+
"size": [1, {"signal": "radius"}],
55+
"as": ["alpha", "radius", "depth", "children"]
56+
},
57+
{
58+
"type": "formula",
59+
"expr": "(rotate + extent * datum.alpha + 270) % 360",
60+
"as": "angle"
61+
},
62+
{
63+
"type": "formula",
64+
"expr": "PI * datum.angle / 180",
65+
"as": "radians"
66+
},
67+
{
68+
"type": "formula",
69+
"expr": "inrange(datum.angle, [90, 270])",
70+
"as": "leftside"
71+
},
72+
{
73+
"type": "formula",
74+
"expr": "originX + datum.radius * cos(datum.radians)",
75+
"as": "x"
76+
},
77+
{
78+
"type": "formula",
79+
"expr": "originY + datum.radius * sin(datum.radians)",
80+
"as": "y"
81+
}
82+
]
83+
},
84+
{
85+
"name": "links",
86+
"source": "tree",
87+
"transform": [
88+
{ "type": "treelinks" },
89+
{
90+
"type": "linkpath",
91+
"shape": {"signal": "links"}, "orient": "radial",
92+
"sourceX": "source.radians", "sourceY": "source.radius",
93+
"targetX": "target.radians", "targetY": "target.radius"
94+
}
95+
]
96+
}
97+
],
98+
99+
"scales": [
100+
{
101+
"name": "color",
102+
"type": "linear",
103+
"range": {"scheme": "magma"},
104+
"domain": {"data": "tree", "field": "depth"},
105+
"zero": true
106+
}
107+
],
108+
109+
"marks": [
110+
{
111+
"type": "path",
112+
"from": {"data": "links"},
113+
"encode": {
114+
"update": {
115+
"x": {"signal": "originX"},
116+
"y": {"signal": "originY"},
117+
"path": {"field": "path"},
118+
"stroke": {"value": "#ccc"}
119+
}
120+
}
121+
},
122+
{
123+
"type": "symbol",
124+
"from": {"data": "tree"},
125+
"encode": {
126+
"enter": {
127+
"size": {"value": 100},
128+
"stroke": {"value": "#fff"}
129+
},
130+
"update": {
131+
"x": {"field": "x"},
132+
"y": {"field": "y"},
133+
"fill": {"scale": "color", "field": "depth"}
134+
}
135+
}
136+
},
137+
{
138+
"type": "text",
139+
"from": {"data": "tree"},
140+
"encode": {
141+
"enter": {
142+
"text": {"field": "name"},
143+
"fontSize": {"value": 9},
144+
"baseline": {"value": "middle"}
145+
},
146+
"update": {
147+
"x": {"field": "x"},
148+
"y": {"field": "y"},
149+
"dx": {"signal": "(datum.leftside ? -1 : 1) * 6"},
150+
"angle": {"signal": "datum.leftside ? datum.angle - 180 : datum.angle"},
151+
"align": {"signal": "datum.leftside ? 'right' : 'left'"},
152+
"opacity": {"signal": "labels ? 1 : 0"}
153+
}
154+
}
155+
}
156+
]
157+
}

0 commit comments

Comments
 (0)