-
Notifications
You must be signed in to change notification settings - Fork 34
Fixing tooltip='two\nlines' data not rendering issue #220
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
Conversation
|
I investigated into this issue, and saw that there are two files - geom.r and z-animint-helpers.r write.table(some.lines, tmp,
col.names=FALSE,
quote=FALSE, row.names=FALSE, sep="\t")With quote=FALSE, any string written to the TSV is unquoted. This becomes a problem because the JS side uses d3.tsv to read per-chunk TSVs. If the TSV contains a newline inside a field, it gets split into multiple lines. That breaks the tabular layout, and D3 mis-parses the rows. As a result, points can disappear an example is : viz<-list(
p1=ggplot()+
geom_point(aes(
x, x, tooltip=x, color=x),
size=5,
data.frame(x=c("one line", "two\nlines", "three\nlines\nhere")))
)the generated tsv for this is as follows : Here the "two\nlines" point is split across rows, which causes it to disappear. When I changed those write.table calls to use quote=TRUE, the TSV instead looks like this:
This way, the newline stays inside the quoted string, and D3 reads the whole field correctly. The "two\nlines" point then renders properly, with the tooltip showing \n as a space as follows: Screen.Recording.2025-09-01.at.7.26.43.PM.mov |
|
Now the newline survives serialization, but the browser’s default rendering (and/or the way the tooltip is inserted into the DOM) collapses it into a single space. This happens not because the code explicitly replaces \n with a space, but because HTML collapses newlines by default. We have a few options:
Could you advise which approach we should go with? |
|
Thanks for investigating! |
|
You mentioned that converting |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #220 +/- ##
=======================================
Coverage 77.70% 77.70%
=======================================
Files 164 164
Lines 8777 8778 +1
Branches 553 564 +11
=======================================
+ Hits 6820 6821 +1
Misses 1957 1957
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
the tooltips now support for example the following code: viz<-list(
p1=ggplot()+
geom_point(aes(
x, x, tooltip=x, color=x),
size=5,
data.frame(x=c("one line", "two\nlines", "three\nlines\nhere")))
)
animint2dir(viz, "label-aligned")produces Screen.Recording.2025-09-03.at.2.05.23.PM.mov |
|
great thanks! please increase version number and add an item to NEWS and then I will merge. |
| mouseX = d3.event.pageX; | ||
| mouseY = d3.event.pageY; | ||
| } | ||
| var safeHtml = String(content).replace(/\n/g, '<br/>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
great thanks! |



fixing #219