Published
Edited
Jun 22, 2022
49 stars
Insert cell
Insert cell
Insert cell
Insert cell
nodes = poissonDiscSampler(width, height, 12)
Insert cell
distance = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1])
Insert cell
function graph(nodes) {
const graph = { sources: [], targets: [], costs: [] },
n = nodes.length,
delaunay = d3.Delaunay.from(nodes);

delaunay.halfedges.forEach((ei, ej) => {
if (ei > ej) {
const i = delaunay.triangles[ei],
j = delaunay.triangles[ej],
cost = distance(nodes[i], nodes[j]);

graph.sources.push(i);
graph.targets.push(j);
graph.costs.push(cost);

graph.sources.push(j);
graph.targets.push(i);
graph.costs.push(cost);
}
});

return graph;
}
Insert cell
groupColor = d3.scaleOrdinal(d3.schemeDark2.concat(d3.schemePastel2))
Insert cell
centers = origins.map(i => nodes[i])
Insert cell
origins = Array.from({ length: 15 }, () => (Math.random() * nodes.length) | 0)
Insert cell
import {
drag,
draw_starting_points,
draw_connections
} with { origins, graph, height, mutable nodes } from "@fil/mobility-landscapes"
Insert cell
import { poissonDiscSampler } from "@fil/2d-point-distributions"
Insert cell
import { shortest_tree } from "@fil/dijkstra"
Insert cell
height = Math.min(width, 600)
Insert cell
d3 = require("d3@5", "d3-delaunay@6", "d3-tricontour@1")
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