Skip to content

Added tests for multiline text support #261

Open
ANAMASGARD wants to merge 4 commits intomasterfrom
multiline-text-support-221
Open

Added tests for multiline text support #261
ANAMASGARD wants to merge 4 commits intomasterfrom
multiline-text-support-221

Conversation

@ANAMASGARD
Copy link
Copy Markdown
Contributor

@ANAMASGARD ANAMASGARD commented Oct 21, 2025

Add Multi-line Text Support Throughout animint2

Fixes #221

This PR enables newline characters (\n) to work in all text elements of animint2 visualizations. Users can now create multi-line text in plot titles, axis labels, legend titles, and geom_text labels.

What Now Works:
✅ Plot titles - ggtitle("Line 1\nLine 2")
✅ X-axis titles - xlab("X Axis\nSubtitle")
✅ Y-axis titles - ylab("Y Axis\nSubtitle")
✅ Legend titles - scale_color_discrete(name="Legend\nTitle")
✅ Text labels - geom_text(aes(label="Text\nLabel"))
✅ Tooltips - Already worked, still works (backward compatible)

Below is the screenshots of the scripts i ran locally to verify the test locally they fail as aspected
Screenshot From 2025-10-21 19-08-38
Screenshot From 2025-10-21 19-08-44

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Add Multi-line Text Support Throughout animint2

Fixes #221

Summary

This PR enables newline characters (\n) to work in all text elements of animint2 visualizations, not just tooltips. Users can now create multi-line text in plot titles, axis labels, legend titles, and geom_text labels.

What Now Works

Plot titles - ggtitle("Line 1\nLine 2")
X-axis titles - xlab("X Axis\nSubtitle")
Y-axis titles - ylab("Y Axis\nSubtitle")
Legend titles - scale_color_discrete(name="Legend\nTitle")
Text labels - geom_text(aes(label="Text\nLabel"))
Tooltips - Already worked, still works (backward compatible)

Visual Verification

The screenshot below demonstrates multi-line text working correctly in all contexts:

Screenshot From 2025-10-21 19-30-47

Example Usage

library(animint2)

data <- data.frame(
  x = 1:5,
  y = 1:5,
  group = c("A", "B", "C", "A", "B"),
  label = c("Single", "Two\nLines", "Three\nLines\nHere", "Text", "Label")
)

viz <- animint(
  plot1 = ggplot(data, aes(x, y, color = group, label = label)) +
    geom_point(size = 5) +
    geom_text(vjust = -1) +
    ggtitle("Multi-line Test\nIssue #221 Demonstration") +
    xlab("X Axis\n(Horizontal Position)") +
    ylab("Y Axis\n(Vertical Position)") +
    scale_color_discrete(name = "Data Group\n(Click to Select)")
)

animint2dir(viz, "output-dir")

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 21, 2025

No obvious timing issues in HEAD=multiline-text-support-221
Comparison Plot

Generated via commit 0875c09

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 4 minutes and 25 seconds
Installing different package versions 57 seconds
Running and plotting the test cases 3 minutes and 41 seconds

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Ran tests locally - all 19 multiline text tests pass successfully. The test failures shown are due to missing optional packages (mapproj, sp, XML) and GitHub API permissions, not related to this PR. Sir can you please help me figure out on how to pass the JS_Coverage test suite .

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 21, 2025

To get this PR to close the corresponding issue, please add

Closes #221

on its own line, in the first comment of the PR.

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 21, 2025

looks like a step in the right direction, thanks!
however here #261 (comment) the second line of the overall title "Issue #221 Demonstration" is going into the plotting area.
Can you please add a test which makes sure the bottom of this title element is above the plotting area? (it should fail for the current code)

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 21, 2025

Also in #261 (comment) it seems like there is an inconsistency between the X and Y axes.

  • there is almost no space between the Y axis title (Vertical Position) and the Y axis ticks (2 3 4)
  • there is a big space between the X axis title (X Axis) and the X axis tick (3).

can this be adjusted to be more consistent please?
also it should be consistent with the case of single line X/y axis title, as below from https://5-merge--animint-manual-en.netlify.app/ch06/#aes-tooltip which was created with current master
image

Copy link
Copy Markdown
Collaborator

@tdhock tdhock left a comment

Choose a reason for hiding this comment

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

please add tests then fix

ANAMASGARD added a commit that referenced this pull request Oct 22, 2025
Tests check:
- plot title doesn't overlap with plot area
- x-axis and y-axis spacing is consistent
- multiline spacing matches single-line baseline

Tests currently fail, demonstrating the bugs in current code.
Addresses feedback on PR #261.
ANAMASGARD added a commit that referenced this pull request Oct 22, 2025
Two fixes:
1. Add 5px margin below title to prevent overlap with plot area
2. Use same base spacing (30px) for both X and Y axis labels

Both axes now have consistent spacing, and multiline titles
stay above the plot area.

Addresses feedback on PR #261.
@ANAMASGARD ANAMASGARD requested a review from tdhock October 22, 2025 13:58
Comment thread inst/htmljs/animint.js Outdated
Copy link
Copy Markdown
Collaborator

@tdhock tdhock left a comment

Choose a reason for hiding this comment

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

please simplify height/width calculation

@ANAMASGARD ANAMASGARD requested a review from tdhock October 22, 2025 16:22
Comment thread inst/htmljs/animint.js Outdated
@ANAMASGARD ANAMASGARD requested a review from tdhock October 23, 2025 12:38
Comment thread tests/testthat/test-multiline-spacing.R Outdated
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 23, 2025

can you please post an updated screen shot?

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Updated screenshot after spacing fixes:
Screenshot From 2025-10-23 20-06-25

@ANAMASGARD ANAMASGARD requested a review from tdhock October 23, 2025 15:18
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Oct 27, 2025

can you please test increasing and decreasing font size?

#64 (comment)

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

ANAMASGARD commented Nov 7, 2025

Sir @tdhock Fixed the axis title font size issue.

Axis titles now scale correctly with theme(text=element_text(size=30)).

Changes:
R/z_animint.R :- Extract axis title sizes from theme
inst/htmljs/animint.js :- Apply those sizes to axis title text elements

Tested with different font sizes (10, 30, 50) - all working locally on my system .

Please Sir review it and give your feedback !!!

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock
The problem was axis titles didn't scale with theme(text=element_text(size=30)). Added extraction of axis title sizes from theme in R and use them in the renderer. Previous tests failed because we weren't testing this specific case, so I added 2 new tests to cover it. Also added PR#261 to NEWS.md. All tests pass locally now.

Please give your feedback !!!

Comment thread inst/htmljs/animint.js Outdated
Comment thread inst/htmljs/animint.js Outdated
Comment thread inst/htmljs/animint.js Outdated
Comment thread inst/htmljs/animint.js Outdated
Copy link
Copy Markdown
Collaborator

@tdhock tdhock left a comment

Choose a reason for hiding this comment

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

please revise and explain

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

ANAMASGARD commented Nov 7, 2025

Sir @tdhock I have fixed all code style issues :=>

  • 2-space indentation
  • Removed blank lines
  • Documented lineHeight (1.2em = standard SVG line spacing)
  • Kept .each() because D3 needs it for element selection
  • Both <br/> splitting and forEach loops needed: <br/> is intermediate format from R, forEach creates actual tspan elements SVG can render

All tests passed locally on my system .

@ANAMASGARD ANAMASGARD requested a review from tdhock November 7, 2025 16:32
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Nov 8, 2025

to understand why the test cases fail, you should try running them line by line under chromote, after tests_init(), and then look at the output in the remote controlled web browser window https://github.com/animint/animint2/wiki/Testing

ANAMASGARD added a commit that referenced this pull request Nov 8, 2025
The xtitle text element was missing the transform attribute, which caused
renderer tests to fail with 'subscript out of bounds' errors when trying
to access xtitle.attrs[["transform"]].

Added transform='translate(0,0)' to match ytitle and plottitle elements,
ensuring consistent structure for all title elements.

This fixes test failures in:
- test-renderer1-facet-space.R (line 42)
- test-renderer1-facet-trivial.R (line 32)

Addresses maintainer feedback from PR #261.
Comment thread tests/testthat/test-compiler-multiline-text.R Outdated
Comment thread tests/testthat/test-compiler-multiline-text.R Outdated
@ANAMASGARD ANAMASGARD requested a review from tdhock November 11, 2025 16:44
Comment thread tests/testthat/test-renderer1-multiline-spacing.R Outdated
@ANAMASGARD ANAMASGARD requested a review from tdhock November 12, 2025 07:29
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Nov 14, 2025

please click Resolve conversation so reviewers can see which things you have already fixed.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.68%. Comparing base (543d0d9) to head (0875c09).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #261      +/-   ##
==========================================
- Coverage   73.09%   72.68%   -0.42%     
==========================================
  Files         164      165       +1     
  Lines        8769     8834      +65     
==========================================
+ Hits         6410     6421      +11     
- Misses       2359     2413      +54     
Flag Coverage Δ
javascript 81.15% <100.00%> (+0.37%) ⬆️
r 68.72% <100.00%> (-0.85%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Nov 27, 2025

please post updated screenshot

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Updated screenshot showing multiline text support working correctly:

Screenshot From 2025-11-28 21-13-10
  • 3-line plot title does not overlap plot area
  • X/Y axis titles with consistent multiline spacing
  • Legend title with multiline support
  • geom_text labels with multiline text

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Nov 28, 2025

this looks better.
like I wrote before #261 (comment) there is still the inconsistency between the amount of white space in X and Y axes. (Y has no space but X space is large)
please fix so that they are more consistent.

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Feb 27, 2026

please post new screenshot

ANAMASGARD added a commit to ANAMASGARD/animint2 that referenced this pull request Mar 2, 2026
Tests check:
- plot title doesn't overlap with plot area
- x-axis and y-axis spacing is consistent
- multiline spacing matches single-line baseline

Tests currently fail, demonstrating the bugs in current code.
Addresses feedback on PR animint#261.
ANAMASGARD added a commit to ANAMASGARD/animint2 that referenced this pull request Mar 2, 2026
Two fixes:
1. Add 5px margin below title to prevent overlap with plot area
2. Use same base spacing (30px) for both X and Y axis labels

Both axes now have consistent spacing, and multiline titles
stay above the plot area.

Addresses feedback on PR animint#261.
ANAMASGARD added a commit to ANAMASGARD/animint2 that referenced this pull request Mar 2, 2026
The xtitle text element was missing the transform attribute, which caused
renderer tests to fail with 'subscript out of bounds' errors when trying
to access xtitle.attrs[["transform"]].

Added transform='translate(0,0)' to match ytitle and plottitle elements,
ensuring consistent structure for all title elements.

This fixes test failures in:
- test-renderer1-facet-space.R (line 42)
- test-renderer1-facet-trivial.R (line 32)

Addresses maintainer feedback from PR animint#261.
ANAMASGARD added a commit that referenced this pull request Mar 11, 2026
Tests check:
- plot title doesn't overlap with plot area
- x-axis and y-axis spacing is consistent
- multiline spacing matches single-line baseline

Tests currently fail, demonstrating the bugs in current code.
Addresses feedback on PR #261.
ANAMASGARD added a commit that referenced this pull request Mar 11, 2026
Two fixes:
1. Add 5px margin below title to prevent overlap with plot area
2. Use same base spacing (30px) for both X and Y axis labels

Both axes now have consistent spacing, and multiline titles
stay above the plot area.

Addresses feedback on PR #261.
ANAMASGARD added a commit that referenced this pull request Mar 11, 2026
The xtitle text element was missing the transform attribute, which caused
renderer tests to fail with 'subscript out of bounds' errors when trying
to access xtitle.attrs[["transform"]].

Added transform='translate(0,0)' to match ytitle and plottitle elements,
ensuring consistent structure for all title elements.

This fixes test failures in:
- test-renderer1-facet-space.R (line 42)
- test-renderer1-facet-trivial.R (line 32)

Addresses maintainer feedback from PR #261.
@ANAMASGARD ANAMASGARD force-pushed the multiline-text-support-221 branch 2 times, most recently from 080c5b6 to a51683d Compare March 11, 2026 07:07
@ANAMASGARD ANAMASGARD force-pushed the multiline-text-support-221 branch from a51683d to ccd5367 Compare March 12, 2026 01:31
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock the spacing is now consistent. Please review and give feedback .
Screenshot From 2026-03-12 06-58-47

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.

line breaks in various text elements

2 participants