Skip to main content
100%

Hilbert Tiles

✓ Published0🌍 Public
Mmbostock
Last edited Feb 8, 2016
Created on Sep 25, 2010

This example uses a Hilbert curve to lay out a grid of colored tiles, demonstrating how a space-filling curve preserves spatial locality compared to a sequential layout. The map, built with Polymaps, renders rainbow-colored tiles whose hue is derived from the Hilbert index of each tile’s position, so adjacent tiles always display adjacent colors in the spectrum, even as the user zooms and pans. The code defines a custom Hilbert function, applies it in a Polymaps layer to generate SVG rectangles, and computes their fill colors with a custom HSL-to-RGB conversion.

AI-generated description

Say you have a bunch of things, like thousands of photos from your digital camera. What if you wanted to look at them all at once? A typical user interface might order the photos chronologically by column and then by row, which does a decent job of grouping related photos together... But, if you have thousands of photos, the rows may be hundreds of photos long, and it is impossible to zoom in on a group of related photos!

An alternative that better preserves locality is a space-filling curve, such as the Hilbert curve. These curves can be used to place related things next to each other in space, avoiding those huge gaps across rows you see with sequential layout.

This example demonstrates the effect of using a Hilbert curve for layout with Polymaps by generating rainbow-colored tiles. As you can see, each tile is surrounded by its adjacent colors in the rainbow, even as you zoom in and out. In contrast, the sequential layout only preserves locality in one dimension.

gpl-3.0 Licensed

Similar vizzes