Published
Edited
May 30, 2021
6 stars
Also listed in…
Plot Experiments
Insert cell
Insert cell
nodes = [
{ id: "SRI", x: 0, y: 10 },
{ id: "UCSB", x: 1, y: 1 },
{ id: "UCLA", x: 8, y: 0 },
{ id: "UTAH", x: 36, y: 17 }
]
Insert cell
lookup = {
const index = new Map(nodes.map(d => [d.id, d]));
return id => index.get(id);
}
Insert cell
Insert cell
Insert cell
Insert cell
function project([id1, id2]) {
const {x: x1, y: y1} = lookup(id1);
const {x: x2, y: y2} = lookup(id2);
return {x1, y1, x2, y2};
}
Insert cell
Insert cell
Plot.plot({
inset: 50,
x: {axis: null},
y: {axis: null},
marks: [
Plot.link(links.map(project), {
x1: "x1", y1: "y1", x2: "x2", y2: "y2"
}),
Plot.dot(nodes, {x: "x", y: "y", fill: "black"}),
Plot.text(nodes, {x: "x", y: "y", text: "id", dy: 16, dx: -12})
],
width: 300,
height: 220
})
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