Public
Edited
Jun 7, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const select = data.slice(selectIdx, selectIdx + 1),
neighbors = [
data[obj.twoNeighbors[selectIdx].a],
data[obj.twoNeighbors[selectIdx].b]
];

return Plot.plot({
aspectRatio: 1.0,
color: { legend: true, scheme: "Blues" },
x: { nice: true },
y: { nice: true },
marks: [
Plot.dot(data, { x: "x", y: "y", fill: "gray", opacity: 0.5 }),
Plot.dot(select, { x: "x", y: "y", fill: "red" }),
Plot.dot(neighbors, { x: "x", y: "y", fill: "blue" }),
Plot.frame()
]
});
}
Insert cell
obj = {
const tic = new Date(),
delaunay = d3.Delaunay.from(data.map((d) => [d.x, d.y])),
twoNeighbors = [];

var neighbors;

data.map((d, i) => {
neighbors = [...delaunay.neighbors(i)].sort(
(a, b) => dist(data[a], d) - dist(data[b], d)
);
twoNeighbors.push({ i, a: neighbors[0], b: neighbors[1] });
});

const cost = new Date() - tic;
return { delaunay, twoNeighbors, cost, costUnit: "milliseconds" };
}
Insert cell
data = {
button;
const data = [];

for (let i = 0; i < num; ++i) {
data.push(rndPnt(i));
}

return data;
}
Insert cell
rndPnt = (i = 0) => {
const x = rnd(),
y = rnd();

return { i, x, y };
}
Insert cell
dist = (a, b) => {
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}
Insert cell
rnd = d3.randomUniform(0, 1)
Insert cell
d3 = require("d3")
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