Published
Edited
Oct 31, 2021
Insert cell
Insert cell
Insert cell
Insert cell
rename = name => name.substring(name.indexOf(".") + 1, name.lastIndexOf("."))
Insert cell
names = Array.from(new Set(data.flatMap(d => [d.source, d.target]))).sort(d3.ascending)
Insert cell
matrix = {
const index = new Map(names.map((name, i) => [name, i]));
const matrix = Array.from(index, () => new Array(names.length).fill(0));
for (const { source, target, value } of data)
matrix[index.get(source)][index.get(target)] += Math.abs(value);
return matrix;
}
Insert cell
chord = d3.chordDirected()
.padAngle(10 / innerRadius)
.sortSubgroups(d3.descending)
.sortChords(d3.descending)
Insert cell
arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius)
Insert cell
ribbon = d3.ribbonArrow()
.radius(innerRadius - 1)
.padAngle(1 / innerRadius)
Insert cell
color = (d) => d3.scaleSequential(d3.interpolateRdYlGn)(d / 1100 + 0.5)
Insert cell
outerRadius = innerRadius + 10
Insert cell
innerRadius = Math.min(width, height) * 0.5 - 400
Insert cell
height = width
Insert cell
d3 = require("d3@6")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more