Published
Edited
Mar 20, 2020
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
origins = (replay,
Array.from({ length: 5 }, () => (Math.random() * nodes.length) | 0))
Insert cell
nodes = FileAttachment("nodes_grand_lyon.json").json()
Insert cell
edges = FileAttachment("paths_grand_lyon.json").json()
Insert cell
Insert cell
Insert cell
function createGraph(edges) {
const graph = { sources: [], targets: [], costs: [] };
edges.forEach(({ u, v, length }, i) => {
const cost = length;

graph.sources.push(u);
graph.targets.push(v);
graph.costs.push(cost);

graph.sources.push(v);
graph.targets.push(u);
graph.costs.push(cost);
});

return graph;
}
Insert cell
graph = createGraph(edges)
Insert cell
import { shortest_tree } from "@fil/dijkstra"
Insert cell
tree = shortest_tree({ graph, origins })
Insert cell
Insert cell
pts = nodes.map(d => projection([d.x, d.y]))
Insert cell
Insert cell
projection = d3.geoMercator().fitExtent([[10, 10], [width - 10, height - 10]], {
type: "MultiPoint",
coordinates: nodes.map(d => [d.x, d.y])
})
Insert cell
Insert cell
color = (replay, d3.scaleOrdinal(d3.schemeCategory10))
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
height = width * 0.9
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