Skip to content

Phase 3: touch-friendly region selection on the scatter plot - #463

Open
JeffreyBLewis wants to merge 1 commit into
touch-tooltips-districtfrom
touch-scatter-selection
Open

Phase 3: touch-friendly region selection on the scatter plot#463
JeffreyBLewis wants to merge 1 commit into
touch-tooltips-districtfrom
touch-scatter-selection

Conversation

@JeffreyBLewis

Copy link
Copy Markdown
Collaborator

Summary

Stacks on #462 so this diff only shows the new commit, `df6382d`. Implements Phase 3 (#450).

Member selection on the DW-NOMINATE scatter plot is normally a drag-rectangle brush, which has no touch equivalent. Before writing anything new, checked what already works: tapping a single point to select it already works fine on touch, since a tap synthesizes a click event and the existing click-to-select handler just uses `d3.mouse()`, which works the same regardless of input device. That didn't need fixing.

What's actually missing is selecting an arbitrary rectangle of multiple members, which needs a genuine drag gesture. Added a "Select region" toggle (visible only on `(pointer: coarse)` devices -- mouse/trackpad users keep dragging) that arms a two-tap mode: tap one corner, tap the opposite corner, and the code computes the same min/max rectangle a drag would produce and applies it through the chart's own existing `.brush().extent(...).event(scb)` call -- same mechanism the single-point path already uses. Tapping the toggle again while armed cancels.

Applied identically to `congress.js`/`congress.tpl` and `voteCharts.js`/`vote.tpl`, since both duplicate the same click-to-select scatter code.

Test plan

Verified with headless Chromium (Playwright), added as permanent checks in the scratch suite:

  • Region-select via two taps produces the exact same member selection (by data-count) as a real mouse drag-brush between the same NOMINATE coordinates -- 178/178 and 100/100 matched exactly, on both pages
  • Toggle hidden on desktop, visible on touch (iPhone 13 emulation)
  • Canceling mid-selection resets the button without applying a selection; normal tap-to-select-one-point still works immediately after
  • Existing single-tap-select and mouse drag-brush behavior unchanged
  • Full existing 41-check suite still passes
  • Manual check on an actual touch device, if you get a chance

Also fixed in review before committing: a markup slip from an earlier edit on `vote.tpl` had replaced the `

` closing tag instead of preserving it. Browsers auto-close an unclosed `

`, so it had no functional effect (every test above passed against the broken markup too), but it was still wrong and is fixed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_013KJMYfgTNsxrmjHZpZKAHT

Member selection on the DW-NOMINATE scatter plot is normally a drag-
rectangle brush, which has no touch equivalent (D3 v3's brush stack is
mouse-only). Before writing anything new, checked what already works on
touch: tapping a single point to select it already works fine, since a
tap synthesizes a click event the same as a mouse would, and the
existing click-to-select-one-point handler (in both congress.js and
voteCharts.js) just uses d3.mouse() on that click, which behaves
identically regardless of input device. That's not what needed fixing.

What's missing is a way to select an arbitrary rectangle of multiple
members, which does need a genuine drag gesture. Added a "Select region"
toggle button (visible only on coarse-pointer devices via a
`(pointer: coarse)` media query -- mouse/trackpad users already have
drag) that arms a two-tap mode: tap once for a corner, tap again for the
opposite corner, and the code computes the same min/max rectangle a drag
would have produced and applies it via the chart's own
`.brush().extent(...).event(scb)` call, identical to what the existing
single-point path already does. Tapping the toggle again while armed
cancels without completing a selection.

Applied identically to congress.js/congress.tpl (whole-chamber roster)
and voteCharts.js/vote.tpl (single-vote breakdown), since both duplicate
the same click-to-select scatter code.

Verified with headless Chromium (Playwright), added as permanent checks:
- Region-select via two taps produces the *exact same* member selection
  (by data-count) as a real mouse drag-brush between the same two
  NOMINATE coordinates, on both congress.js and voteCharts.js -- 178/178
  and 100/100 members matched exactly
- The toggle is hidden on desktop (pointer:fine) and visible on touch
  (iPhone 13 emulation)
- Canceling mid-selection resets the button and doesn't apply a
  selection; a normal tap-to-select-one-point still works immediately
  afterward
- Existing single-tap-select and mouse drag-brush behavior confirmed
  unchanged
- Full existing 41-check suite still passes

Also fixed a markup slip from an earlier edit pass on vote.tpl: the
button insertion had replaced the `<h4>` heading's closing tag instead
of preserving it. Caught in review before commit -- browsers auto-close
an unclosed `<h4>` so it had no visible/functional effect (confirmed:
every test above passed against the broken markup too), but it was
still wrong and is fixed here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013KJMYfgTNsxrmjHZpZKAHT
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.

1 participant