Command Palette

Search for a command to run...

Hectal
Phase 8Intermediate9 of 19 in Data Visualization

Interaction

Pointer events, tooltips that stay on screen, finding the nearest point, filters, brushing and zooming, and charts that talk to each other, on a phone as well.

A chart you can only look at answers one question. A chart you can point at answers the next one too: what happened on that day, which station is this, what if I zoom into June. This phase adds the questions a reader asks while looking.

You start with what the browser really sends when someone moves a mouse, touches a screen or presses Tab, and with the hidden traps in it: thin lines that are hard to hit, hover that does not exist on a phone, tooltips that fall off the edge of the screen. Then you build the pieces: tooltips, the nearest-point search, highlighting and filtering, d3.brush and d3.zoom, and views that update each other.

At the end the Lumen dashboard becomes an explorer: a crosshair tooltip on the rides line, a brush that picks a range of dates, and station bars that follow the brush. Every interaction also works by touch and by keyboard.

Phase 8 · the story

Priya, operations lead

“I want to point at a day on the chart and see its numbers, and do the same on my phone in the depot.”

The dashboard now draws the year as a line, but Priya has a habit: she points. In the Monday meeting she puts a finger on the dip in August and asks "what was that?". The chart answers only if someone reads the date off the axis and looks the number up in the spreadsheet.

She also works from the depot with a phone, where there is no mouse. "If it only works when I hover, it does not work for me," she says. And she wants to select a few weeks and see which stations were busy in them.

In this phase the team adds tooltips, a crosshair that finds the nearest day, a brush to pick dates and bars that react to the pick. By the end Priya can point at a day, drag across a month and see the stations change, with a finger, a mouse or the keyboard.

In this phase

You will learn

  • Handle mouse, touch and pen with one set of pointer events, and turn pointer positions into data values
  • Build tooltips that stay on screen and work by tap and by keyboard, and find the nearest point without the silent wrong answer
  • Filter and highlight from one state object, and use d3.brush and d3.zoom with their limits
  • Link several charts to one selection, and keep the selection in the URL

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/parts/tooltip.js
  • src/charts/rides-line.js
  • src/charts/stations-bar.js
  • src/main.js
0/7 · 0%
7 topics ~3 h 15 code blocks & diagrams
Start with the first topic
1
8.1

Pointer Events on Charts

Pointer events give one set of events for mouse, finger and pen. This topic shows how to turn a pointer position into chart coordinates, why thin lines are hard to hit, and why hover cannot be the only way to reach a number.

20 min 2 code practice

2
8.2

Tooltips

A tooltip shows the exact numbers of one mark on demand. This topic builds one that stays on screen, opens by tap and by keyboard focus, shows missing values honestly, and never holds the only copy of a number.

27 min 3 code practice

3
8.3

Finding the Nearest Point

A pointer is never exactly on a data point. A bisector finds the nearest day on sorted data in a few steps, a Delaunay triangulation finds the nearest dot of a scatter plot, and unsorted data gives a wrong answer with no error.

23 min 3 code practice

4
8.4

Highlight, Filter and Legend Toggles

Highlighting dims everything except one thing, filtering takes things out. Keep all the changing facts in one state object, draw from it in one function, and decide in advance what the chart says when every item is filtered out.

25 min 2 code practice

5
8.5

Brushing and Zooming

A brush selects a range by dragging, and a zoom changes what part of the chart you see. This topic shows the event shapes d3.brush and d3.zoom really send, how to turn them into dates, what the limits do and do not stop, and how to avoid a chart that steals the page's scroll.

23 min 2 code practice

6
8.6

Linked Views

Linked views react to one shared selection. A tiny store with get, set and subscribe is enough: views never talk to each other, bursts of changes are batched, and the selection can live in the URL if every incoming value is checked.

21 min 2 code practice

7
8.7

Build: An Interactive Rides Explorer

The dashboard becomes an explorer. A crosshair tooltip answers "what happened that day" by mouse, tap and arrow keys, a brush (or three buttons) picks dates, and the station bars follow the selection.

47 min 1 code practice

Practise this phase

Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.