SVG pointer accuracy and binned calendar heatmap - #27
Draft
gillkyle wants to merge 2 commits into
Draft
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Problem
Responsive width charts inside a fixed-height card, flex/grid shrinking, or weird padding can make the SVG and CSS viewports mismatch.
Pointer hit-testing mapped browser coordinates from the SVG element's full bounding box directly into chart coordinates. When the CSS viewport and SVG
viewBoxhave different aspect ratios, the defaultpreserveAspectRatio="xMidYMid meet"centers the rendered scene with letterboxed space around it. Treating that empty space as chart space shifts hover and focus selection—by nearly one calendar row in this example.Fix
Use the SVG screen matrix instead of assuming the bounding box matches the painted scene:
getScreenCTM()describes the complete scene-to-viewport transform, including scale, centering, CSS/SVG transforms, and letterboxing. Applying its inverse returns the pointer to the correct scene coordinate. The existing bounds calculation remains as a fallback for incomplete DOM environments.This is the established approach used by D3
pointer, D3's implementation, and Airbnb visxlocalPointGeneric. See also MDN onpreserveAspectRatioandgetScreenCTM().Example
Adds Token use calendar heatmap, a responsive interaction case that also demonstrates
binTimeXdaily token/session aggregation, explicit UTC bins, transform lineage, calendar layout, keyboard focus, and a mark-anchored portal tooltip.You can see in this little recording how my cursor tracks the row below it because there's like ~13px of space above and below the container due to the SVG
viewBoxstuff.CleanShot.2026-07-31.at.21.21.54.mp4
Verification
typecheck, 654 tests, package/catalog/docs checks, bundle check, and browser verification at 320/640/960px widths all pass.