fix: give usePlot().scales.fx/fy valid ranges for facet-aware positioning#500
Merged
fix: give usePlot().scales.fx/fy valid ranges for facet-aware positioning#500
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>
✅ Deploy Preview for svelteplot ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This was referenced Feb 28, 2026
gka
approved these changes
Mar 2, 2026
gka
added a commit
that referenced
this pull request
Mar 2, 2026
## Summary Stacked on #500. - **Pointer searched ALL quadtrees** instead of only the hovered facet's trees — replaced flat `trees[]` array with a keyed `SvelteMap<facetKey, Quadtree[]>` so only the hovered facet's trees are searched - **HTMLTooltip positioned via bounding rect diffs** — replaced fragile `getBoundingClientRect()` offset computation with scale-based offsets using `plot.scales.fx.fn(fxValue)` (available after #500) - **Tree array index ≠ facet index** — `groupFacetsAndZ` produces groups in data-encounter order while `FacetGrid` iterates domain order; keyed map decouples lookup from array ordering - **HTMLTooltip event listener leak** — cleanup called `removeEventListener('mouseleave')` but registration used `addEventListener('pointerleave')`; both now use `pointerleave` ### New shared helpers (`src/lib/helpers/facets.ts`) | Helper | Purpose | |--------|---------| | `facetKey(fx, fy)` | Stable `JSON.stringify` key for `(fxValue, fyValue)` pairs | | `invertBand(scale, domain, pixel)` | Invert a `d3.scaleBand` (no native `.invert()`) | | `findFacetFromDOM(target)` | Walk DOM up to `g.facet`, read `data-facet-x/y` attributes | | `detectFacet(evt, plot)` | DOM walk first, band-inversion fallback; returns `{ fxValue, fyValue, offsetX, offsetY }` | ## Test plan - [x] `invertBand` — 5 unit tests (first/second band, out of range, single domain, padding) - [x] `facetKey` — 6 unit tests (same values, different values, null, boolean, null vs "null", numeric) - [x] Faceted Pointer — 4 tests (facet A isolation, facet B isolation, non-faceted regression, empty data) - [x] HTMLTooltip — 4 tests (facet A datum, facet B datum, non-faceted regression, pointerleave) - [x] All 704 existing tests pass - [x] `pnpm check` — 0 errors - [x] `pnpm lint` — clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: gka <617518+gka@users.noreply.github.com> Co-authored-by: Gregor Aisch <gka@users.noreply.github.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
usePlot().scales.fx/fyhad empty ranges ([]), makingfn()calls returnNaN— preventing custom overlay components from using fx/fy scales for facet-aware positioning (labels, tooltips, annotations)computeScales()returns incomputePlotState(), create freshscaleBandinstances for fx/fy with correct range ([0, plotWidth]/[0, plotHeight]) and padding matching FacetGrid's layoutrange([])have corrupted internal ordinal mappings that can't be recovered by later setting the rangeCloses #498
Test plan
facet-padding.test.ts,dot-faceted.test.svelte.ts)svelte-checkpasses (0 errors)🤖 Generated with Claude Code