Public
Edited
Nov 21, 2023
Insert cell
Insert cell
Insert cell
{
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.left + margin.right);

const clipPathLookup = {};
svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.selectAll('clipPath')
.data(nodes.filter(d => d.depth == 1), d => d.data.key)
.join("clipPath")
.attr("id", d => {
const uid = DOM.uid("clip");
clipPathLookup[d.data.key] = uid;
return uid.id;
})
.append("path")
.attr('d', d => "M" + d.polygon.join("L") + "Z");

const voronoi = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
.selectAll('path')
.data(nodes.filter(d => d.depth == 2), d => d.data.id)
.join("path")
.attr('d', d => "M" + d.polygon.join("L") + "Z")
.style('fill', d => colorScale(d.data.region))
.attr("clip-path", d => clipPathLookup[d.data.parent])
.attr("stroke", "#fff")
.style("cursor", "pointer");

svg
.append("g")
.selectAll("text")
.data(nodes.filter(d => d.depth == 2), d => d.data.id)
.join(
enter =>
enter
.append('text')
.attr("x", d => d.polygon.site.x)
.attr("y", d => d.polygon.site.y)
.attr("text-anchor", "middle")
.attr("font-size", "0.8rem")
.text(d => d.data.region),
update => update.attr("fill", d => console.log("Hello"))
);

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
height = 400

Insert cell
Insert cell
data = FileAttachment("test@1.csv").csv({typed: true})
Insert cell
filterData = data.filter(d => d.metric == selectMetric)
Insert cell
Insert cell
d3
.nest()
.key(d => d.metric)
.entries(filterData)
Insert cell
line = d3.line().curve(d3.curveBasisClosed)
Insert cell
Insert cell
seed = new Math.seedrandom(20);
Insert cell
voronoiTreeMap = d3.voronoiTreemap()
.prng(seed)
.clip([[0,0], [width, 0], [width, height], [0, height]])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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