Fix tex hover label name truncation and rotated label placement by SergeyAxiomatic · Pull Request #8138 · plotly/plotly.js · GitHub
Skip to content

Fix tex hover label name truncation and rotated label placement - #8138

Open
SergeyAxiomatic wants to merge 3 commits into
plotly:mainfrom
SergeyAxiomatic:fix/hover-mathjax-name-and-y-followups
Open

SergeyAxiomatic wants to merge 3 commits into
plotly:mainfrom
SergeyAxiomatic:fix/hover-mathjax-name-and-y-followups

Conversation

@SergeyAxiomatic

Copy link
Copy Markdown
Contributor

Follow-up to #8051, fixing two problems @Lexachoc reported there (#8051 (comment) and the comment before it).

What changed

Tex trace names were truncated by hoverlabel.namelength. A trace name that is a single tex expression was cut to namelength (default 15) before the pure-tex check ran. That removed the closing $, so a long formula was never typeset and showed up as $\alpha_{1c}.... Setting hoverlabel.namelength: -1 worked around it. plainText in hover.js now skips truncation when the whole string is one tex expression; plain-text names are still truncated.

Tex was misplaced in rotated hover labels. With hovermode: 'y' and more than one trace, hover labels are rotated. positionMathGroup measured the typeset glyphs with getBoundingClientRect, which returns the larger screen-space box of the rotated shape (for example 75x116 for a glyph group that is really about 75x14), so the math group landed tens of pixels from its label. It now measures in the group's own coordinates when an ancestor is rotated (getBBox times the SVG's letterbox scale). When nothing is rotated it uses the same measurement as before, so titles, annotations and unrotated hover labels are unaffected.

Reproduction

Both reproduce on main with the mock from the linked comment, minus the hoverlabel styling from #8115. For the second one, hover near the top point with hovermode: 'y' so that several labels are shown and rotated.

Tests

New cases in test/jasmine/bundle_tests/mathjax_test.js:

  • a long pure-tex name is not truncated (fails on main);
  • a long pure-tex name in a hovertemplate <extra> is not truncated (already passed; guards that path);
  • a plain-text name is still truncated;
  • the tex name stays centred in its name box for rotated labels in hovermode: 'y' (fails on main, off by about 73px).

karma start test/jasmine/karma.conf.js --bundleTest=mathjax_test.js --nowatch passes 20/20, and npm run test-jasmine -- svg_text_utils hover legend annotations --nowatch passes 456/456. I also checked the rotated case in the browser before and after.

Not included

Tex in unified hover is still limited to rows that are a single tex expression. That is the existing scope from #8051, not something this change affects.

🤖 Generated with Claude Code

SergeyAxiomatic and others added 3 commits October 21, 2026 00:35
Two follow-ups to plotly#8051, reported on that PR:

- A trace name that is a single tex expression was cut to
  hoverlabel.namelength (default 15) before the pure-tex check, which
  dropped the closing $ so it was never typeset. Skip truncation for
  pure-tex names.
- In hovermode 'y' with several traces the labels are rotated, and
  positionMathGroup measured the glyphs with getBoundingClientRect, which
  is the larger screen-space box of the rotated shape, so the math landed
  far from its label. Measure in the group's own coordinates when an
  ancestor is rotated.

The draftlog file name carries a placeholder PR number to be renamed once
the PR is opened.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Measuring the typeset glyphs in their own coordinates when an ancestor is
rotated also moved the rotated ternary axis titles, which go through
convertToTspans and failed the ternary-mathjax image baselines. Only
repositionMathGroup (used by hover labels) opts in now; convertToTspans
measures exactly as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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