Published
Edited
Apr 22, 2020
8 stars
Insert cell
Insert cell
Insert cell
layers = [{id: "layer1", loc: "layer1Loc", org: "layer1Org", color:'purple'}, {id:"layer2", loc:"layer2Loc", org: "layer2Org", color: 'red'}, {id:"layer3", loc:"layer2Loc", org: "layer2Org", color: 'blue'}]
Insert cell
data = FileAttachment("ona.json").json()
Insert cell
height = 600
Insert cell
color = {
const scale = d3.scaleOrdinal(d3.schemeCategory10);
return d => 'rgb(38, 166, 154)';
// return d => scale(d.loc);
}
Insert cell
drag = simulation => {
function dragstarted(d) {
console.log("d is ", d, d3.event);
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
console.log("dragged is ", dragged);
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
d3 = require("d3@5")
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