Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.3 — Choropleths and Symbol Maps
Data Visualization · Example 3 of 3

Zoom the map without growing the stations

The zoom is moved by code here (svg.call(zoom.transform, ...)). A wheel, a double click and a pinch call the same handler.

A choropleth colours each area by a value, and a symbol map puts a circle on each place. Both are easy to draw and easy to get wrong: totals follow size, classes decide the colours, a circle's area (not its radius) must show the value, and zoom must not grow the symbols.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 4 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add a legend to the choropleth: four squares with the class ranges (scale.thresholds() gives the breaks of a quantize scale).

02

Write circleRadius(value, max, maxRadius) that returns 0 for missing, zero or negative values, and a square-root scaled radius otherwise.

Explain it without notes

01

Why is a choropleth of total rides less useful than one of rides per dock?

02

How do quantize, quantile and threshold scales differ, and when does each mislead?

03

Why must a circle's radius be the square root of the value?

04

How do you stop circles growing when the map zooms?

Zoom the map without growing the stations

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

start                      | k 1.0 | x,y 0,0 | r in the file 5.00 | r on screen 5.0
zoom 4x on Quay            | k 4.0 | x,y -713,-703 | r in the file 1.25 | r on screen 5.0
ask for 20x (limit is 8)   | k 8.0 | x,y -1636,-1576 | r in the file 0.63 | r on screen 5.0
move the centre to the corner | k 8.0 | x,y 0,0 | r in the file 0.63 | r on screen 5.0
reset                      | k 1.0 | x,y 0,0 | r in the file 5.00 | r on screen 5.0