feat: support Plotly SVG scatter point highlighting (#533)#547
feat: support Plotly SVG scatter point highlighting (#533)#547jooyoungseo wants to merge 4 commits intomainfrom
Conversation
Enhance scatter trace position extraction to support SVG elements that use transform translate or cx/cy attributes instead of x/y attributes. This fixes highlighting for Plotly scatter plots where markers use transform="translate(x, y)" for positioning. https://claude.ai/code/session_01G8aSXXDCkdRL7ym57XQueM
PR Review: feat: support Plotly SVG scatter point highlighting (#533)This is a focused, well-scoped fix that cleanly extends scatter highlight support to Plotly SVGs. The extraction of Issues1. Behavioral Change: Partial Coordinates Now ExcludedThe original code handled x and y independently: // Old: elements with ONLY x (no y) still went into xGroups
if (!Number.isNaN(x)) { xGroups.get(x)!.push(element); }
if (!Number.isNaN(y)) { yGroups.get(y)!.push(element); }The new code skips elements entirely if This is almost certainly the correct behavior (a point without both coordinates is useless for grouping), but worth confirming no real-world matplotlib or Plotly SVGs emit partial attributes that this would silently discard. 2. No Tests for the New Code Path
At minimum, unit tests for
3. Minor:
|
Enhance getElementPosition to comprehensively handle all SVG rendering backends that maidr supports: - x/y attributes: matplotlib <use>, <rect>, <image>, <text> - cx/cy attributes: D3/Bokeh <circle>, <ellipse> - translate(x,y): Plotly <path>/<g> with two-arg translate - translate(x): single-arg translate (y defaults to 0) - matrix(a,b,c,d,e,f): SVG matrix transform (e,f = translation) - getBoundingClientRect fallback: <path> with absolute d coords, <polygon>, or any other SVG element type Also fix regex patterns to avoid super-linear backtracking flagged by eslint regexp/no-super-linear-backtracking rule. https://claude.ai/code/session_01G8aSXXDCkdRL7ym57XQueM
Follow-up Review: Coordinate System Bug in
|
| Issue | Severity | Fix |
|---|---|---|
getBoundingClientRect() returns viewport coords, not SVG user space coords |
High — can silently produce wrong groupings | Use getBBox() instead |
matrix() is handled (previous review was wrong) |
✅ No action needed | — |
| No unit tests for new methods | Medium | Add tests for each branch |
| Rounding inconsistency | Low — resolves when switching to getBBox() |
Addressed by above fix |
The translate and matrix regex logic looks correct. The attribute-based priority order is sensible. The main concern is the coordinate space mismatch in the fallback path.
…istency Replace getBoundingClientRect() with getBBox() in the bounding box fallback method. getBoundingClientRect returns viewport pixel coordinates while x/y and cx/cy extraction methods return SVG user-space coordinates. This mismatch would cause incorrect element grouping when different extraction paths are used. getBBox() operates in SVG user space, ensuring consistent coordinates across all extraction methods. https://claude.ai/code/session_01G8aSXXDCkdRL7ym57XQueM
PR Review Update: Current State of the DiffThis is a follow-up pass on the current diff after the two previous review comments. Here's an updated assessment. Status of Previously Raised Issues✅ Coordinate system bug — already resolved in current diffThe second review comment raised a high-severity bug about const bbox = (element as SVGGraphicsElement).getBBox();
return {
x: bbox.x + bbox.width / 2,
y: bbox.y + bbox.height / 2,
};This is correct — consistent with the other three extraction paths. No action needed.
|
| Item | Status |
|---|---|
Coordinate system bug (getBBox vs getBoundingClientRect) |
✅ Already fixed in current diff |
matrix() transform support |
✅ Handled correctly |
instanceof vs as cast in getPositionFromBoundingBox |
|
| Regex permissiveness | ℹ️ Low-severity, no incorrect behavior |
| No unit tests for new methods | |
| No E2E spec for scatter plots | ℹ️ Nice-to-have follow-up |
The logic is sound and the fix addresses a real gap in Plotly SVG support. The instanceof guard is a minor improvement worth making. Unit tests for getElementPosition (covering x/y, cx/cy, translate, matrix, and null cases) remain the primary ask before this is merge-ready.
|
Will re-create new pr. There are quite a few new regeressions cc: @jooyoungseo |
Enhance scatter trace position extraction to support SVG elements that
use transform translate or cx/cy attributes instead of x/y attributes.
This fixes highlighting for Plotly scatter plots where markers use
transform="translate(x, y)" for positioning.
https://claude.ai/code/session_01G8aSXXDCkdRL7ym57XQueM