Public
Edited
Dec 14, 2022
Paused
1 fork
15 stars
Contour Labels (canvas)Coordinated mapsgeoformatSmall circle testKruskal MazeAll the geoshapesReprojecting Vector TilesCloud ContoursHello h3-jsClipping AlbersTranslucent EarthThe truth about the Mercator projectionUsing d3-inertia with observableMercator projection of a Mercator globeD3 Vector Tiles (WIP)Finding intersections between the graticule and the clip sphere of the stereographic projection, method 2Plate tectonicsAnother hex mapEquateur & tropiquesTissot's indicatrixDistance to shoreMultiPolygon clippingSouth Africa’s medial axisSpherical intersectionVolcano Semis (points circulaires)Pencil Airocean45° mapNetCDFBlue noise sphereRubber DymaxionSpherical quasi-random (R2) distributionAutomated label placement (countries)Automated label placement (France)Automated label placement (cities)d3.geoIntersectArcDelaunay.findTriangled3-geo-voronoi and gridded dataElevation vtk.jsMapfillKrigingSpherical HeatmapReproject elevation tiles — detailReproject elevation tiles — worldFisheye Conformal MapSpherical KDE InterpolationSpherical kernel interpolation with nearest neighborsShepard’s methodModified Shepard’s methodSpherical contoursGeo Voronoi interpolationBlurry contoursHow much warmer? (BBC)H3 hexagons & geoContoursHillshading & supersamplingH3 odditiesManhattan VoronoiManhattan Voronoi IIGeoJSON feature editorColorized Manhattan Spanning Treelegra mapslegra country mapsThe complex logarithm projectionCountries small multipleThe 2D approximate Newton-Raphson methodOceanAttitudeCount visible objectsThe Gray-Fuller spatial gridGray-Fuller grid metricsGray-Fuller grid odditiesSpherical smallest-circle problemBounding CirclesCountries Enclosing CirclesFullscreen Seamless Zoomable Map TilesMap Pan & ZoomSpherical EllipsesSynchronized projectionsThe closest countryTriangular tiling of icosahedronHello, polygon-clippingCorées / KoreasHello, procedural-glHello, placekeyZoom World ChoroplethClipping spherical polygonsSpherical phyllotaxisFour-color world map with ClingoHello, jsgeoda!The Sun’s analemmaWorld of squaresWorld of squares (spherical)A map of AfricaTagged bordersClipped geoVoronoiBlue noise sphere IISpherical Perlin NoiseSpherical Delaunay triangulationDynamic simplificationRewindPlot: Voronoi labels
AoC 12: shortest path under constraints
Hello, pixi.jsFlight PathsRay out of a convex hullDistance to a segment
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// part 2
bestA = d3.least(
Array.from(state.costs, (cost, i) => ({ cost, i })),
({ cost, i }) => (V[i] === 0 ? cost : Infinity)
)
Insert cell
state.costs
Insert cell
state.time
Insert cell
state.perf // performance.now
Insert cell
state.costs[terrain[backwards ? "start" : "end"]]
Insert cell
w = input.split("\n")[0].length
Insert cell
h = input.split("\n").length
Insert cell
terrain = {
let start, end;
const V = Array.from(input.replaceAll("\n", ""));
for (let i = 0; i < V.length; ++i) {
if (V[i] === "S") (start = i), (V[i] = "a"); // start S is a
else if (V[i] === "E") (end = i), (V[i] = "z"); // end E is z
V[i] = V[i].charCodeAt(0) - 97;
}
return { V, start, end };
}
Insert cell
V = terrain.V
Insert cell
// Compute these contours once, rather than thousands of rect elements with Plot.cell
contours = d3.contours().size([w, h]).thresholds(25).smooth(false)(V)
Insert cell
state = {
const [S, E] = backwards
? [terrain.end, terrain.start]
: [terrain.start, terrain.end];

// The tree is just here to draw on the map, but not needed for the computation.
function walk(tree, active) {
let node = d3.least(active, (d) =>
Math.hypot((d % w) - (E % w), ((d / w) | 0) - ((E / w) | 0))
);
const path = [node];
while (tree.has(node)) path.push((node = tree.get(node)));
return path;
}

const tree = new Map();
// Tested with a priority queue and A* in https://observablehq.com/@fil/advent-of-code-12@506;
// and it doesn't help
const active = new Set([S]);
const costs = new Array(V.length).fill(Infinity);
costs[S] = 0;

let t = 0;
const t0 = performance.now();
do {
const node = active.values().next().value; // get first
active.delete(node);
const x = node % w;
const y = (node / w) | 0;
for (const nei of [
x > 0 && node - 1,
x < w - 1 && node + 1,
y > 0 && node - w,
y < h - 1 && node + w
]) {
// ignore neighbor outside the map
if (nei === false) continue;

// acceptable neighbor: max 1 step _up_
if ((backwards ? -1 : 1) * (V[nei] - V[node]) <= 1) {
const c = costs[node] + 1;
if (c < costs[nei]) {
costs[nei] = c;
active.add(nei);
tree.set(nei, node);
}
}
}
if (++t % steps === 0) {
yield { costs, active, tree, time: t, walk: walk(tree, active) };
}
} while (active.size);
const perf = performance.now() - t0;
yield { costs, active, tree, time: t, walk: walk(tree, [E]), perf };
}
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more