Skip to content

Highlight and toggle chart lines from the legend (fix #15) - #484

Merged
stephaniehobson merged 4 commits into
339--line-gapsfrom
15--legend-highlight
Nov 13, 2026
Merged

stephaniehobson merged 4 commits into
339--line-gapsfrom
15--legend-highlight

Conversation

@stephaniehobson

Copy link
Copy Markdown
Collaborator

One-line summary

Highlight a chart line while its legend entry is hovered or focused, and hide or show the line by clicking it.

Significant changes and points to review

  • Legend entries are now <button aria-pressed> elements, styled to look as before. Three specs now find them by .legend-entry instead of .legend span.
  • Hovering or focusing an entry fades every other line on that chart to 15% opacity.
  • Clicking an entry hides its line, dots, and hover points. The entry stays in the legend, struck through and faded, so it can be clicked back.
  • The y-axis rescales to the lines that are shown. The x-axis and every line's color stay fixed.
  • The last line with data can't be hidden; its entry is disabled.
  • Hidden and highlighted populations live in ChartContainer.jsx state. They reset when the data changes, such as on a region change, since another region can have different populations.

Issue / Bugzilla link

#15

Testing

Run npm install and npm run build:css first, then npm start.

  • On http://localhost:3000/dashboard/usage-behavior, hover each Top Languages legend entry and check that the other lines fade
  • Click "en-US" and check that its line disappears, its entry is struck through, and the y-axis rescales to the smaller languages
  • Click "en-US" again and check that the line comes back
  • Hide every line but one and check that the last entry can't be clicked
  • Tab to a legend entry and check that focus highlights its line and Enter or Space toggles it
  • Hide a line, change the region, and check that every line is shown again

This comment was marked as outdated.

This comment was marked as outdated.

Highlighting a population rebuilt the plot, so the readout a click had
pinned disappeared as soon as the pointer reached the legend. The fade
is now applied to the SVG already drawn, and ObservablePlot redraws only
when what the chart is drawn from changes.

Hover and keyboard focus are tracked separately, so moving the pointer
off a focused entry, or blurring a hovered one, no longer clears its
highlight. A population with no points shown can't be highlighted, since
doing so faded every line.

This comment was marked as outdated.

Highlighting a legend entry renders the chart again, and on a chart
with more than eleven populations each render ran distinctColors, which
takes several milliseconds, for a palette it had already made.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because an unpublished finding identifies insufficient text contrast in enabled controls used to restore hidden lines.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@stephaniehobson
stephaniehobson marked this pull request as ready for review November 13, 2026 16:06
@stephaniehobson
stephaniehobson merged commit e7edcfe into main Nov 13, 2026
8 checks passed
@stephaniehobson
stephaniehobson deleted the 15--legend-highlight branch November 13, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants