fix: facet-aware Pointer and HTMLTooltip positioning#509
Merged
Conversation
…ning computeScales() creates fx/fy band scales with empty ranges because getScaleRange() has no case for these scale names. This made fn() calls return NaN, preventing custom components from using fx/fy scales for facet-aware positioning (labels, tooltips, annotations). After computeScales() returns, create fresh band scales for fx/fy with the correct range ([0, plotWidth] / [0, plotHeight]) and padding config matching FacetGrid's layout. Fresh scales are needed because d3 band scales created with range([]) have corrupted internal ordinal mappings. Closes #498 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace fragile DOM-walking and flat tree arrays with keyed tree map and scale-based facet detection. Pointer and HTMLTooltip now search only the hovered facet's quadtrees instead of all trees, preventing cross-facet false matches. - Add invertBand, facetKey, findFacetFromDOM, detectFacet helpers - Refactor Pointer.svelte to use keyed SvelteMap<facetKey, Quadtree[]> - Refactor HTMLTooltip.svelte to use scale-based offsets instead of getBoundingClientRect diffs - Fix HTMLTooltip event listener cleanup mismatch (mouseleave vs pointerleave) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ Deploy Preview for svelteplot ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This was referenced Feb 28, 2026
Contributor
|
@copilot can you resolve the conflicts? |
Contributor
`fix/tooltip-facet-positioning` conflicted with `main` in two example
files where both sides modified the same `Map.get()` spread lines
differently — the branch dropped `?? {}`, while `main` replaced it with
`as object`.
## Changes
- **`shift-map.svelte`** — adopt `main`'s `as object` cast over the
branch's bare spread
- **`spike-map.svelte`** — same resolution
```svelte
<!-- before (branch) -->
...electionByFips.get(Number(feat.id))
<!-- after (resolved) -->
...(electionByFips.get(Number(feat.id)) as object)
```
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gka <617518+gka@users.noreply.github.com>
## Summary Stacked on #509. - Removed erroneous `+ marginLeft` / `+ marginTop` from mouse-to-SVG coordinate conversion in `Pointer.svelte` and `HTMLTooltip.svelte` - The quadtree already stores points in scale-range space (which includes margins via `projectX`/`projectY`), so adding margins again caused a double offset that prevented point selection when margins > 0 - Added a regression test with `margin: 20` that fails before the fix and passes after ## Test plan - [x] New test: `selects nearest point with non-zero margins` (margin=20, verifies point is found) - [x] All 705 existing tests pass - [x] `pnpm check` clean - [x] `pnpm lint` clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #500.
trees[]array with a keyedSvelteMap<facetKey, Quadtree[]>so only the hovered facet's trees are searchedgetBoundingClientRect()offset computation with scale-based offsets usingplot.scales.fx.fn(fxValue)(available after fix: give usePlot().scales.fx/fy valid ranges for facet-aware positioning #500)groupFacetsAndZproduces groups in data-encounter order whileFacetGriditerates domain order; keyed map decouples lookup from array orderingremoveEventListener('mouseleave')but registration usedaddEventListener('pointerleave'); both now usepointerleaveNew shared helpers (
src/lib/helpers/facets.ts)facetKey(fx, fy)JSON.stringifykey for(fxValue, fyValue)pairsinvertBand(scale, domain, pixel)d3.scaleBand(no native.invert())findFacetFromDOM(target)g.facet, readdata-facet-x/yattributesdetectFacet(evt, plot){ fxValue, fyValue, offsetX, offsetY }Test plan
invertBand— 5 unit tests (first/second band, out of range, single domain, padding)facetKey— 6 unit tests (same values, different values, null, boolean, null vs "null", numeric)pnpm check— 0 errorspnpm lint— clean🤖 Generated with Claude Code