Skip to content

shadcn.io is an independent project built on shadcn/ui

Voronoi Catchments Map Block for Svelte

Paris cut into one cell per delivery hub, the ground nearer it than any other, shaded by share of residents. Close or add a hub and the cells redraw.

On this page5 sections
UI library: Ark UI

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

See who each site really serves, with this Voronoi catchments map for Svelte with Ark UI. Panierly, a grocery delivery service, has seven hubs in real Paris neighbourhoods on a live Map that follows your theme, and the city is cut into one cell per hub: the ground nearer that hub than any other, computed in the file and clipped to the city's boundary. About a thousand dots, each some 2,000 residents scattered round the arrondissements by their approximate populations, are counted into the cells, and each cell is shaded in the chart ramp by its share of residents, with the legend under the map. Close a hub from the list and its neighbours take its ground; press Add a hub and click inside Paris to open up to three more, and every cell, share and bar redraws at once. Choosing a hub, from its row, its letter on the map or its cell, outlines the cell and fills the card with its residents, share, area and the distance to the nearest hub; Reset brings back the seven. Built from Map, Button and Guides. For delivery, retail and franchise planning, and any network that splits a city by distance.

FAQ

How are the cells drawn?

Each open hub starts with the whole city's boundary, then clipTo cuts it along the halfway line to every other open hub, keeping the side nearer its own. What remains is its Voronoi cell. East-west distances are shortened to Paris's latitude first, so the halfway lines are true on the ground. The cells are worked out again on every change, which takes a moment for ten hubs.

Where do the residents and their shares come from?

From a seeded sample in the file: for each arrondissement, one dot for every 2,000 of its approximate residents, scattered round its homes and kept inside the city. A dot belongs to its nearest open hub, which is the same as falling in that hub's cell, and a hub's share is its dots over all of them. The figures are rounded and the sample is invented; in your app, count real addresses or census blocks instead.

How do I add or close a hub?

Each hub in the list has a button beside it: close a hub and its cell goes to its neighbours, press it again to reopen. Add a hub turns the pointer into a crosshair; click inside the city's line to open a new hub there, up to three, and remove it from the list. The last open hub can't be closed. Nothing is saved, and a polite message gives the new count and the hub that serves the most.

Does a cell show who can be reached fastest?

No: it goes by straight-line distance, which ignores the river, the rails and one-way streets. That is a fair first cut for planning, and the same picture with travel times needs a routing service's matrix of times to every resident point.

Can I use it without a mouse?

Choosing, closing, reopening and removing hubs are all buttons in the list, and the zoom buttons and the map (arrows, plus and minus) work from the keyboard. Placing a new hub needs a click or a tap on the map, since it is a point you choose by eye.

How does it look on a phone?

The map comes first with the Add a hub bar over it and the legend under it, then the hub list and the hub's card. Scrolling over the map scrolls the page; use two fingers to move it, or hold Ctrl or ⌘ and scroll to zoom on a computer.