Published
Edited
Dec 12, 2018
Insert cell
Insert cell
function getPositions (time) {
return data.map(d => [d[0] + d[2] * time, d[1] + d[3] * time]);
}
Insert cell
function getBounds (positions) {
let [xMax, xMin, yMax, yMin] = [-Infinity, Infinity, -Infinity, Infinity];
for (let row of positions) {
let [x, y] = row;
xMax = Math.max(x, xMax);
xMin = Math.min(x, xMin);
yMax = Math.max(y, yMax);
yMin = Math.min(y, yMin);
}
return [xMax, xMin, yMax, yMin];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getSpread (positions) {
let [xMax, xMin, yMax, yMin] = getBounds(positions);
return (xMax - xMin) + (yMax - yMin);
}
Insert cell
spreadMinimizedAtTime = {
let time = 10000;
let spread = getSpread(getPositions(time));
let lastSpread = spread;
while (spread <= lastSpread) {
time++;
lastSpread = spread;
spread = getSpread(getPositions(time));
}
return time - 1;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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