Maps, Hierarchies and Networks
Draw the stations on a map of Ardenvale, the fleet as a treemap and the busiest routes as a network, with D3's geo, hierarchy, force and chord tools.
Some data has a shape that is not a line or a set of bars. Places sit on a map. A fleet splits into districts, stations and bike types, like boxes inside boxes. Stations are joined by routes, like beads on strings. D3 has a tool for each: d3-geo for maps, d3-hierarchy for boxes inside boxes, d3-force and d3-chord for connections.
You start with the file formats (GeoJSON and TopoJSON) and the one bug that makes a map fill the whole world. Then projections, colour maps and symbol maps, trees and treemaps, force-directed networks, and flows between districts. Every example uses Lumen's made-up island, Ardenvale, so you can check every number yourself.
At the end you build the station map of the dashboard (districts and river from TopoJSON, stations sized by docks and coloured by free bikes) and a treemap of the fleet.
Phase 13 · the story
Priya, operations lead
“I want to see our stations on a map of Ardenvale, so I can tell at a glance which part of the island is running out of bikes.”
At 8:15 on a June morning Priya has a list: 25 stations, each with a number of free bikes. The list says Rope Walk has 7 and Quay has 12. It does not say where those places are, or that the three emptiest stations are next to each other on the west side.
Tomás asks a different question in the same meeting: "How many bikes do we own, and where?" Arjun adds a third: "Which routes carry the most trips? I want to know where to put a new station." A table answers each question, but slowly. A map, a set of boxes and a network answer them in a glance.
In this phase the team learns the three drawing tools behind those pictures. By the end the dashboard has a map of Ardenvale with every station on it, and a treemap that shows the whole fleet.
In this phase
You will learn
- Read GeoJSON and TopoJSON, and fix a polygon that fills the whole world
- Project longitude and latitude to pixels, and fit a map to its box
- Colour districts and size symbols honestly, and draw trees, treemaps, networks and flows
- Build the dashboard's station map and fleet treemap
You write code in
In your Vite project lumen-dashboard/ (run npm run dev), and in the editor on this page
Files you touch
- src/charts/station-map.js
- src/charts/fleet-treemap.js
- src/main.js
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.