Published
Edited
Jun 3, 2020
Insert cell
Insert cell
Insert cell
Insert cell
pathLength = line.querySelector("polyline").getTotalLength()
Insert cell
calculatedLength = d3.sum(d3.pairs(points).map(pair => pointDist(...pair)))
Insert cell
difference = pathLength - calculatedLength
Insert cell
lineSegments = 1000
Insert cell
points = d3.range(lineSegments).map(_ => ({
x: +(Math.random() * 200).toFixed(1),
y: +(Math.random() * 200).toFixed(1)
}))
Insert cell
function pointDist(p1, p2) {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2))
}
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