-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrows.html
37 lines (33 loc) · 1014 Bytes
/
arrows.html
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
<svg id="network" width="600" height="380">
<defs>
<marker
id="triangle"
viewBox="0 0 10 10"
refX="20"
refY="5"
markerUnits="strokeWidth"
markerWidth="8"
markerHeight="8"
orient="auto"
>
<path d="M 0 0 L 10 5 L 0 10 z" fill="rgba(0,0,0,0.2)" />
</marker>
</defs>
</svg>
<script type="module">
import { network } from "https://cdn.jsdelivr.net/npm/@gramex/network@2";
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
// Load the data
const data = await fetch("flare.json").then((r) => r.json());
var root = d3.hierarchy(data);
// Create the network
const graph = network("#network", {
links: root.links(),
nodes: root.descendants(),
d3,
});
// Style the network
const color = d3.scaleOrdinal(d3.schemeCategory10);
graph.nodes.attr("fill", (d) => color(d.depth)).attr("r", (d) => 10 - d.depth * 2);
graph.links.attr("stroke", "rgba(0,0,0,0.2)").attr("marker-end", "url(#triangle)");
</script>