Motion
How D3 transitions really run, how to ease and time them, keep bars recognisable when the data changes, draw lines on, and respect people who want less motion.
Until now, every change of data made the chart jump. In this phase you make it move, and you learn what moving means inside the browser: D3 does not animate anything itself. It schedules small steps on a clock and writes a new attribute value in each step.
You learn when motion helps (it shows where something went) and when it only gets in the way. You choose easing and timing, keep each bar the same element across updates so the eye can follow it, handle updates that arrive in the middle of an animation, and draw lines on from left to right. You also write your own animation loop, and you make every one of these respect the person who has asked their device for less motion.
At the end the dashboard's station bars slide, grow and shrink when the month changes, the rides line draws itself once on load, and one small file decides how much motion everyone gets.
Phase 9 · the story
Tomás, founder
“When I switch the month, the bars jump, and I lose track of which station is which.”
Before the board meeting, Tomás flips the dashboard from June to July. The station chart redraws in one frame. The bars have new lengths, the order is different, and he cannot say whether Lantern went up or Quay went down. He has to read every name again.
"It's like someone shuffled the cards while I blinked," he says. Priya agrees: the numbers are right, but the picture does not tell her what changed. Meera adds a different worry. Her cousin gets dizzy from screen animation and switched it off in the system settings. Whatever the team adds must obey that setting.
In this phase the team learns how transitions work, how to keep each station's bar the same element so it slides to its new place, and how to give the person who wants less motion exactly what they asked for. By the end, Tomás can watch Lantern climb from fifth to first.
In this phase
You will learn
- Animate any attribute, style or text with a D3 transition, and say what happens inside it
- Keep a bar the same element across updates, and handle updates that arrive mid-animation
- Draw a line on from left to right and animate shapes whose point counts differ
- Respect prefers-reduced-motion and pause animation loops when the page is hidden
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/stations-bar.js
- src/charts/rides-line.js
- src/utils/motion.js
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.