-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_links.html
More file actions
308 lines (244 loc) · 9.15 KB
/
process_links.html
File metadata and controls
308 lines (244 loc) · 9.15 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #ccc;
}
.node text {
pointer-events: none;
font: 12px sans-serif;
}
</style>
<body>
<script src="file:///Users/rp/code/crell/apps/crell_web/priv/www/js/d3.v3.min.js"></script>
<script>
import {chart} from "@d3/zoomable-sunburst"
chart = {
// Specify the chart’s dimensions.
const width = 928;
const height = width;
const radius = width / 6;
// Create the color scale.
const color = d3.scaleOrdinal(d3.quantize(d3.interpolateRainbow, data.children.length + 1));
// Compute the layout.
const hierarchy = d3.hierarchy(data)
.sum(d => d.value)
.sort((a, b) => b.value - a.value);
const root = d3.partition()
.size([2 * Math.PI, hierarchy.height + 1])
(hierarchy);
root.each(d => d.current = d);
// Create the arc generator.
const arc = d3.arc()
.startAngle(d => d.x0)
.endAngle(d => d.x1)
.padAngle(d => Math.min((d.x1 - d.x0) / 2, 0.005))
.padRadius(radius * 1.5)
.innerRadius(d => d.y0 * radius)
.outerRadius(d => Math.max(d.y0 * radius, d.y1 * radius - 1))
// Create the SVG container.
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, width])
.style("font", "10px sans-serif");
// Append the arcs.
const path = svg.append("g")
.selectAll("path")
.data(root.descendants().slice(1))
.join("path")
.attr("fill", d => { while (d.depth > 1) d = d.parent; return color(d.data.name); })
.attr("fill-opacity", d => arcVisible(d.current) ? (d.children ? 0.6 : 0.4) : 0)
.attr("pointer-events", d => arcVisible(d.current) ? "auto" : "none")
.attr("d", d => arc(d.current));
// Make them clickable if they have children.
path.filter(d => d.children)
.style("cursor", "pointer")
.on("click", clicked);
const format = d3.format(",d");
path.append("title")
.text(d => `${d.ancestors().map(d => d.data.name).reverse().join("/")}\n${format(d.value)}`);
const label = svg.append("g")
.attr("pointer-events", "none")
.attr("text-anchor", "middle")
.style("user-select", "none")
.selectAll("text")
.data(root.descendants().slice(1))
.join("text")
.attr("dy", "0.35em")
.attr("fill-opacity", d => +labelVisible(d.current))
.attr("transform", d => labelTransform(d.current))
.text(d => d.data.name);
const parent = svg.append("circle")
.datum(root)
.attr("r", radius)
.attr("fill", "none")
.attr("pointer-events", "all")
.on("click", clicked);
// Handle zoom on click.
function clicked(event, p) {
parent.datum(p.parent || root);
root.each(d => d.target = {
x0: Math.max(0, Math.min(1, (d.x0 - p.x0) / (p.x1 - p.x0))) * 2 * Math.PI,
x1: Math.max(0, Math.min(1, (d.x1 - p.x0) / (p.x1 - p.x0))) * 2 * Math.PI,
y0: Math.max(0, d.y0 - p.depth),
y1: Math.max(0, d.y1 - p.depth)
});
const t = svg.transition().duration(750);
// Transition the data on all arcs, even the ones that aren’t visible,
// so that if this transition is interrupted, entering arcs will start
// the next transition from the desired position.
path.transition(t)
.tween("data", d => {
const i = d3.interpolate(d.current, d.target);
return t => d.current = i(t);
})
.filter(function(d) {
return +this.getAttribute("fill-opacity") || arcVisible(d.target);
})
.attr("fill-opacity", d => arcVisible(d.target) ? (d.children ? 0.6 : 0.4) : 0)
.attr("pointer-events", d => arcVisible(d.target) ? "auto" : "none")
.attrTween("d", d => () => arc(d.current));
label.filter(function(d) {
return +this.getAttribute("fill-opacity") || labelVisible(d.target);
}).transition(t)
.attr("fill-opacity", d => +labelVisible(d.target))
.attrTween("transform", d => () => labelTransform(d.current));
}
function arcVisible(d) {
return d.y1 <= 3 && d.y0 >= 1 && d.x1 > d.x0;
}
function labelVisible(d) {
return d.y1 <= 3 && d.y0 >= 1 && (d.y1 - d.y0) * (d.x1 - d.x0) > 0.03;
}
function labelTransform(d) {
const x = (d.x0 + d.x1) / 2 * 180 / Math.PI;
const y = (d.y0 + d.y1) / 2 * radius;
return `rotate(${x - 90}) translate(${y},0) rotate(${x < 180 ? 0 : 180})`;
}
return svg.node();
}
data = FileAttachment("file:///Users/rp/code/crell/process_links.json").json()
</script>
<script>
// var width = 1920,
// height = 1200;
// var color = d3.scale.category20();
// var force = d3.layout.force()
// .linkDistance(300)
// .size([width, height]);
// // .charge(-120)
// var svg = d3.select("body").append("svg")
// .attr("width", width)
// .attr("height", height);
// d3.json("http://localhost:9876/crell_process_info", function(error, graph) {
// force.nodes(graph.nodes)
// .links(graph.links)
// .start();
// //Create all the line svgs but without locations yet
// var link = svg.selectAll(".link")
// .data(graph.links)
// .enter().append("line")
// .attr("class", "link")
// .style("stroke-width", function (d) {
// return Math.sqrt(d.value);
// });
// //Do the same with the circles for the nodes - no
// //Changed
// var node = svg.selectAll(".node")
// .data(graph.nodes)
// .enter().append("g")
// .attr("class", "node")
// .call(force.drag)
// .on('dblclick', connectedNodes); //Added code
// node.append("circle")
// .attr("r", 8)
// .style("fill", function (d) {
// return color(d.group);
// })
// node.append("text")
// .attr("dx", 10)
// .attr("dy", ".35em")
// .text(function(d) { return d.name })
// .style("stroke", "black");
// // collision:
// var padding = 1, // separation between circles
// radius=8;
// function collide(alpha) {
// var quadtree = d3.geom.quadtree(graph.nodes);
// return function(d) {
// var rb = 2*radius + padding,
// nx1 = d.x - rb,
// nx2 = d.x + rb,
// ny1 = d.y - rb,
// ny2 = d.y + rb;
// quadtree.visit(function(quad, x1, y1, x2, y2) {
// if (quad.point && (quad.point !== d)) {
// var x = d.x - quad.point.x,
// y = d.y - quad.point.y,
// l = Math.sqrt(x * x + y * y);
// if (l < rb) {
// l = (l - rb) / l * alpha;
// d.x -= x *= l;
// d.y -= y *= l;
// quad.point.x += x;
// quad.point.y += y;
// }
// }
// return x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1;
// });
// };
// }
// //Now we are giving the SVGs co-ordinates - the force layout is generating the co-ordinates which this code is using to update the attributes of the SVG elements
// force.on("tick", function () {
// link
// .attr("x1", function (d) { return d.source.x; })
// .attr("y1", function (d) { return d.source.y; })
// .attr("x2", function (d) { return d.target.x; })
// .attr("y2", function (d) { return d.target.y; });
// d3.selectAll("circle")
// .attr("cx", function (d) { return d.x; })
// .attr("cy", function (d) { return d.y; });
// d3.selectAll("text")
// .attr("x", function (d) { return d.x; })
// .attr("y", function (d) { return d.y; });
// //node.each(collide(0.5)); //Added
// });
// // // h - highlighting
// //Toggle stores whether the highlighting is on
// var toggle = 0;
// //Create an array logging what is connected to what
// var linkedByIndex = {};
// for (i = 0; i < graph.nodes.length; i++) {
// linkedByIndex[i + "," + i] = 1;
// };
// graph.links.forEach(function (d) {
// linkedByIndex[d.source.index + "," + d.target.index] = 1;
// });
// //This function looks up whether a pair are neighbours
// function neighboring(a, b) {
// return linkedByIndex[a.index + "," + b.index];
// }
// function connectedNodes() {
// if (toggle == 0) {
// //Reduce the opacity of all but the neighbouring nodes
// d = d3.select(this).node().__data__;
// node.style("opacity", function (o) {
// return neighboring(d, o) | neighboring(o, d) ? 1 : 0.1;
// });
// link.style("opacity", function (o) {
// return d.index==o.source.index | d.index==o.target.index ? 1 : 0.1;
// });
// //Reduce the op
// toggle = 1;
// } else {
// //Put them back to opacity=1
// node.style("opacity", 1);
// link.style("opacity", 1);
// toggle = 0;
// }
// }
// });
</script>