Public
Edited
Oct 21, 2023
Insert cell
Insert cell
twindragonChart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, w, h]);

const g = svg.append("g")
.attr("cursor", "grab");

g.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", (d) => parseFloat(d.x) + 0.55*w)
.attr("cy", (d) => -parseFloat(d.y) + 0.375*h)
.attr("r", radius)
.attr("fill", (d, i) => colors(parseInt(d.dark)));
svg.call(d3.zoom()
.extent([[0, 0], [h, h]])
.scaleExtent([1, 22])
.on("zoom", zoomed));

svg.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));

function dragstarted() {
d3.select(this).raise();
g.attr("cursor", "grabbing");
}

function dragged(event, d) {
d3.select(this).attr("cx", d.x = event.x).attr("cy", d.y = event.y);
}

function dragended() {
g.attr("cursor", "grab");
}

function zoomed({transform}) {
g.attr("transform", transform);
}

return svg.node();
}
Insert cell
h = 80
Insert cell
w = 55
Insert cell
Insert cell
Insert cell
colors = d3.scaleQuantize()
.domain([0,11])
.range(clrs);
Insert cell
data = FileAttachment("twindragon-final@4.csv").csv({ typed: true })
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