Skip to content

Allow truncating SVG in AppNodeText #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ptgolden
Copy link
Member

Labels in the phenogrid were previously rendered as <text> SVG elements, rather than <AppNodeText> Vue elements which whitelist certain markup. This replaces those text elements with AppNodeText elements.

An issue, though, is that labels were previously truncated based on their bare text length. So the string 'label<b>with bolded</b>' might be truncated to 'label<b' or 'label<b>with bo' rather than 'label with bo' (where "with bo" would be bolded).

This PR fixes that bug by truncating text according to its length as it appears in rendered SVG.

Fixes the bug mentioned in #943 (comment).

Copy link

netlify bot commented Jan 30, 2025

Deploy Preview for monarch-app ready!

Name Link
🔨 Latest commit 9813cf2
🔍 Latest deploy log https://app.netlify.com/sites/monarch-app/deploys/67ffb8a433fe720007735d60
😎 Deploy Preview https://deploy-preview-945--monarch-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.39%. Comparing base (4c248f0) to head (9813cf2).
Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #945      +/-   ##
==========================================
+ Coverage   70.97%   71.39%   +0.42%     
==========================================
  Files          91       92       +1     
  Lines        3128     3188      +60     
==========================================
+ Hits         2220     2276      +56     
- Misses        908      912       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ptgolden ptgolden added this to the 2025-03 Release milestone Mar 11, 2025
@ptgolden ptgolden self-assigned this Mar 11, 2025
@ptgolden ptgolden force-pushed the truncating-app-node-text branch from 877ffa1 to b7cc485 Compare March 25, 2025 20:15
Additionally, use AppNodeText for SVG labels
@ptgolden ptgolden force-pushed the truncating-app-node-text branch from b7cc485 to a7982af Compare March 25, 2025 20:19
@sagehrke sagehrke requested a review from varun-divya March 25, 2025 20:32
@ptgolden
Copy link
Member Author

ptgolden commented Apr 8, 2025

I am going to add several test cases before continuing

This commit does two main things.

First, it almost completely dials back the difference between rendering
HTML and SVG. Instead of recreating HTML elements (<b>, <i>, <sup>) with
styled <tspan> elements in SVG, it just includes those elements as HTML
in a <foreignObject> tag.

Part of the reason I did this is that there were strange cross-browser
differences in how superscripted text was being truncated. For some
reason, the code for detecting character positions (see the code that
was removed with `getStartPositionOfChar` and `getCharNumAtPosition`)
stopped working when `dy` was set on a tspan in some browsers.

There was also the issue that the SVG equivalents to the HTML elements
were always sliiightly different.

---

Second, and following from that, I was able to get rid of a lot of the
complexities that went with treating rendering SVG and HTML differently.
The new logic is much more simple: the text of the label is retrieved
via `innerHtml`, then a whitelist of tags is escaped (i.e. replacing
`&lt;` with `<` and `&gt;` with `>`).

The only SVG specific logic (besides wrapping the container in a
<foreignObject>) is replacing <sup> tags with <span> tags styled as
superscript. (Again, because of cross-browser rendering issues, which
are commented in the code).
Copy link
Collaborator

@amc-corey-cox amc-corey-cox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change! This makes it much simpler and we don't have to rely as much on our own internal logic. This both solves the bug and makes the whole thing easier to understand and maintain.

@amc-corey-cox
Copy link
Collaborator

Waiting to merge until you make that last small fix.

@sagehrke
Copy link
Member

sagehrke commented Jul 8, 2025

@ptgolden this is going to have conflicts now with all the updates @varun-divya has done. If it still needs to happen, please work with her to get the conflicts resolved. Thanks!

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.

3 participants