Direct labels that move apart, with leader lines
Westpark's line starts in May because defined skips its zero months. Remove the spread call (use ends instead of placed) to see the labels overlap. Look at Westpark's name: spreading pushes it below the axis line, the problem the last Pro note warns about.
A chart must explain its own colours, shapes and sizes. d3.symbol draws marker shapes, legends are small charts built with the same scales, and direct labels put the names on the lines themselves so the reader needs no lookup.
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.
Make sizeLegend(values, sizeFn) that returns the d text for each value, using d3.symbolCircle.
Give every station symbol in the first example a hover title with the station name, its district and its docks.
Explain it without notes
What is the size argument of d3.symbol?
Why build a legend from the same scales as the chart?
What is a direct label and when does it stop working?
Preview
Console
Nothing logged yet.Expected console output
smallest gap between line ends: 1.3 px | labels need 13
after spreading: 13.0 px
labels moved: Old Town by 9.1px, Riverside by 9.5px, Hillcrest by 21.2px, Westpark by 11.7px