Published
Edited
Jan 29, 2021
Insert cell
md`# Chord Diagram Playground`
Insert cell
Insert cell
radius = size / 2;
Insert cell
innerRadius = outerRadius - innerRadiusWidth;
Insert cell
outerRadius = size * 0.5 - outerRadiusWidth
Insert cell
viewof size = slider({min: 50, max: 600, step:10, title: "Size:"})
Insert cell
viewof outerRadiusWidth = slider({ min: 0, max: 20, step: 2, title: "Outer Radius width:"})
Insert cell
viewof innerRadiusWidth = slider({min:1 , max: 10, step: 2, title: "Inner Radius width:"})
Insert cell
viewof padAngle = slider({min: 0, max: 0.3, step:0.01, title: "PadAngle:"})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chord = d3.chordDirected()
// .padAngle(10 / innerRadius)
.padAngle(padAngle)
.sortSubgroups(d3.descending)
.sortChords(d3.descending)
Insert cell
ribbon = d3.ribbon()
.radius(innerRadius)
// .padAngle(1 / innerRadius)
Insert cell
arc = d3.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius)
Insert cell
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)] += value;
return matrix;
}
Insert cell
names = Array.from(new Set(data.flatMap(d => [d.source, d.target])))
Insert cell
Insert cell
md`## Library`
Insert cell
d3 = require("d3@6")
Insert cell
import {slider, radio, text, select, color} from '@jashkenas/inputs'
Insert cell
md`## Reference
`
Insert cell
md`## TODOs
- add label
- color palette
- color gradient
- animated
`
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more