Newer
Older
{
"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"config":{"background":"#ffffff"},
"width": 500,
"height": 500,
"padding": 0,
"autosize": "none",
"signals": [
{ "name": "cx", "update": "width / 2" },
{ "name": "cy", "update": "height / 2" },
{ "name": "nodeRadius", "value": 8,
"bind": {"input": "range", "min": 1, "max": 50, "step": 1} },
{ "name": "nodeCharge", "value": -30,
"bind": {"input": "range", "min":-100, "max": 10, "step": 1} },
{ "name": "linkDistance", "value": 30,
"bind": {"input": "range", "min": 5, "max": 100, "step": 1} },
{ "name": "static", "value": true,
"bind": {"input": "checkbox"} },
{ "description": "throttles the number of nodes rendered; 77 covers 'all'",
"name": "numNodes", "value": 200 },
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
{
"description": "State variable for active node fix status.",
"name": "fix", "value": 0,
"on": [
{
"events": "symbol:mouseout[!event.buttons], window:mouseup",
"update": "0"
},
{
"events": "symbol:mouseover",
"update": "fix || 1"
},
{
"events": "[symbol:mousedown, window:mouseup] > window:mousemove!",
"update": "2", "force": true
}
]
},
{
"description": "Graph node most recently interacted with.",
"name": "node", "value": null,
"on": [
{
"events": "symbol:mouseover",
"update": "fix === 1 ? item() : node"
}
]
},
{
"description": "Flag to restart Force simulation upon data changes.",
"name": "restart", "value": false,
"on": [
{"events": {"signal": "fix"}, "update": "fix > 1"}
]
}
],
"data": [
{
"name": "node-data",
"url": "data/miserables.small.json",
"format": {"type": "json", "property": "nodes"}
"url": "data/miserables.small.json",
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
"format": {"type": "json", "property": "links"},
"transform": [
]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"range": {"scheme": "category20"}
}
],
"marks": [
{
"name": "nodes",
"type": "symbol",
"zindex": 1,
"from": {"data": "node-data"},
"on": [
{
"trigger": "fix",
"modify": "node",
"values": "fix === 1 ? {fx:node.x, fy:node.y} : {fx:x(), fy:y()}"
},
{
"trigger": "!fix",
"modify": "node", "values": "{fx: null, fy: null}"
}
],
"encode": {
"enter": {
"fill": {"scale": "color", "field": "group"},
"stroke": {"value": "white"}
},
"update": {
"size": {"signal": "2 * nodeRadius * nodeRadius"},
"cursor": {"value": "pointer"}
}
},
"transform": [
{
"type": "force",
"iterations": 300,
"restart": {"signal": "restart"},
"static": {"signal": "static"},
"forces": [
{"force": "center", "x": {"signal": "cx"}, "y": {"signal": "cy"}},
{"force": "collide", "radius": {"signal": "nodeRadius"}},
{"force": "nbody", "strength": {"signal": "nodeCharge"}},
{"force": "link", "links": "link-data", "distance": {"signal": "linkDistance"}}
]
}
]
},
{
"type": "path",
"from": {"data": "link-data"},
"interactive": false,
"encode": {
"update": {
"stroke": {"value": "#ccc"},
"strokeWidth": {"value": 0.5}
}
},
"transform": [
{
"type": "linkpath", "shape": "line",
"sourceX": "datum.source.x", "sourceY": "datum.source.y",
"targetX": "datum.target.x", "targetY": "datum.target.y"
}
]
}
]
}