Published
Edited
Dec 2, 2020
Importers
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const root = partition(data);
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
const g = svg
.append("g")
.attr("transform", `translate(${width / 2}, ${height / 2 - innerRadius})`);
g.selectAll("path")
.data(
root.descendants().filter(d => {
return d.depth && d.x1 - d.x0 > 0.002;
})
)
.join("path")
.attr("d", arc)
.attr("stroke", "#fff")
.attr("fill", d => color(d.data.name));
return svg.node();
}
Insert cell
height = 400
Insert cell
r = perimeter / (2 * Math.PI)
Insert cell
perimeter = width
Insert cell
perimeterDifference = d3.scaleLinear().range([perimeter, 0.1])
Insert cell
diff = perimeterDifference(t)
Insert cell
innerRadius = r * (perimeter / diff) - r
Insert cell
wedgeAngle = diff / r
Insert cell
arc = d3
.arc()
.startAngle(d => angle(d.x0))
.endAngle(d => angle(d.x1))
.innerRadius(d => radius(d.y0))
.outerRadius(d => radius(d.y1))
Insert cell
radius = d3.scaleSqrt().range([innerRadius, innerRadius + r])
Insert cell
angle = d3
.scaleLinear()
.range([Math.PI + wedgeAngle / 2, Math.PI - wedgeAngle / 2])
Insert cell
partition = data =>
d3.partition()(
d3
.hierarchy(data)
.sum(d => d.value)
.sort((a, b) => b.value - a.value)
)
Insert cell
d3 = require("d3@6")
Insert cell
import { Scrubber } from "@mbostock/scrubber"
Insert cell
import { data, color } from "@kerryrodden/sequences-sunburst"
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