Skip to content

WIP: Fix panel.margin with positive values (#180)#286

Open
ANAMASGARD wants to merge 15 commits into
masterfrom
fix-panel-margin-positive-values
Open

WIP: Fix panel.margin with positive values (#180)#286
ANAMASGARD wants to merge 15 commits into
masterfrom
fix-panel-margin-positive-values

Conversation

@ANAMASGARD
Copy link
Copy Markdown
Contributor

FIXES #180

Current Status

Tests failing (6/22) - this commit demonstrates the bug exists.

Problem Identified

pt.to.lines() returns constant 0.25 for all inputs instead of converting the actual value.

Current behavior:

  • grid::unit(2, "lines") returns 0.25 (expected: 2)
  • grid::unit(1, "cm") returns 0.25 (expected: ~2.86)
  • grid::unit(0, "lines") returns 0.25 (expected: 0)

Test Output

Screenshot From 2025-12-23 09-58-26

Tests demonstrate:
- pt.to.lines() returns 0.25 for all inputs (should vary)
- Zero values incorrectly return 0.25 instead of 0
- Positive values (2 lines, 1 cm) return 0.25 instead of correct conversion .
Issue #180 asked for test coverage of positive panel.margin values.
Added tests for lines, cm, and pt units. All tests pass - the
feature already works, just needed proper test coverage.

Fixes #180
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

What I Did

Added comprehensive test coverage for panel.margin with positive values (issue #180).

I added tests for:

  • Positive values in lines: grid::unit(2, "lines")
  • Positive values in cm: grid::unit(1, "cm")
  • Positive values in pt: grid::unit(12, "pt")
  • Comparison between zero and positive values

Test Results

  • All 22 tests pass
Screenshot From 2025-12-23 12-26-13

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.02%. Comparing base (a4220df) to head (ac826e8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #286   +/-   ##
=======================================
  Coverage   73.02%   73.02%           
=======================================
  Files         164      164           
  Lines        8837     8837           
=======================================
  Hits         6453     6453           
  Misses       2384     2384           
Flag Coverage Δ
javascript 81.23% <ø> (ø)
r 69.14% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock The R_coverage check is failing on an unrelated test
(test-compiler-ghpages.R:63) that expects 1 TSV file but finds 2.

This appears unrelated to panel.margin since my PR only adds test coverage
and doesn't modify any compilation or TSV generation code.

Sir can you please review the PR and guide me on what should I be doing next .

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Feb 27, 2026

can you please post screenshots?

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 a renderer test

Comment thread tests/testthat/test-panel-margin-positive.R Outdated
@ANAMASGARD ANAMASGARD force-pushed the fix-panel-margin-positive-values branch from 7ba8e0d to 75b34d0 Compare March 9, 2026 07:42
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Hi @tdhock, I've addressed all your feedback :-

Screenshots :-

  • Before (panel.margin = 0):
Screenshot From 2026-03-09 12-40-05
  • After (panel.margin = 2 lines):
Screenshot From 2026-03-09 12-40-22
  • Local renderer test run (PASS 5):
Screenshot From 2026-03-09 12-56-42

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock this is a pre-existing infrastructure issue , it has nothing to do with the code changes I ahve made , please review .

Error ('test-compiler-ghpages.R:59:3'): ...
Error in file(con, "r"): cannot open the connection
└─base::readLines(README.md)

@ANAMASGARD ANAMASGARD requested a review from tdhock March 9, 2026 09:42
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Mar 10, 2026

looks good
does it work for facet_wrap and horizontal spacing too?

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Merged latest master and fixed the CI failure.

Root cause: GitHub's merge commit left duplicate Version: fields in DESCRIPTION (branch had 2026.4.17, master had 2026.4.28), which caused pak::lockfile_create to fail before any tests ran.

Fix: Resolved merge conflicts — single Version: 2026.5.29 in DESCRIPTION, NEWS entry moved to top under that version (keeping master's 2026.4.28 / PR#292 and 2026.3.8 / PR#311 entries).

Local verification:

  • test-panel-margin-positive.R: 20/20 pass
  • test-renderer1-panel-margin.R (with chromote): 20/20 pass — vertical/horizontal facet_grid and facet_wrap spacing assertions all green

This PR remains test-only (no R/JS code changes); pt.to.lines(unit(n, "lines")) already returns the correct value on master.

@tdhock — could you please dismiss the earlier "changes requested" and approve? Renderer tests + facet_wrap/horizontal coverage are in place, and screenshots were posted earlier (margin 0 vs 2 lines).

Fixes #180

Merge left two Version fields (2026.4.17 and 2026.4.28), which caused
pak::lockfile_create to fail before tests ran. Use single Version
2026.5.29 and update NEWS accordingly.
@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented May 29, 2026

can you please post an example code and screenshot for horizontal spacing?

Comment thread NEWS.md Outdated
@ANAMASGARD ANAMASGARD requested a review from tdhock June 3, 2026 02:13
Thanks @ANAMASGARD; document supported units (lines recommended).
Add inst/examples/panel-margin-issue-180.R for horizontal facet_grid
0 vs 2 lines (screenshots posted on PR separately).
@ANAMASGARD ANAMASGARD force-pushed the fix-panel-margin-positive-values branch from ae2eb02 to a83d4e6 Compare June 3, 2026 02:22
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock,

Here’s the horizontal panel.margin example for #180 / PR #286.

Panels are side by side: facet_grid(. ~ Species).

  • 0 lines — columns are tight (see screenshot 1).
  • 2 lines — more space between columns (see screenshot 2).
    Example code is on the branch in inst/examples/panel-margin-issue-180.R. Short version:
library(animint2)
make_plot <- function(n) list(
  plot1 = ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
    geom_point() + facet_grid(. ~ Species) + theme_bw() +
    theme(panel.margin = grid::unit(n, "lines"))
)
animint2dir(make_plot(0), "issue180_horizontal_margin0")
animint2dir(make_plot(2), "issue180_horizontal_margin2")

Units: best to use "lines". "pt" is converted; "cm" is not real cm in the browser (treated like a line count). Pixels aren’t used.

NEWS.md is updated (thanks, units, example). Renderer tests cover this in test-renderer1-panel-margin.R.

Then in the same comment or the next one, attach the two images and add:

Screenshot 1 -> panel.margin = 0 lines
Tight columns; little space between facets.
Screenshot From 2026-06-03 07-47-40

Screenshot 2 -> panel.margin = 2 lines
Wider gaps between the three species columns.
Screenshot From 2026-06-03 07-47-55

Comment thread NEWS.md Outdated
Comment on lines +6 to +11
**Supported units:** The renderer uses `panel_margin_lines` (via `pt.to.lines()`
in `parsePlot()`). Use **`"lines"`** for predictable spacing (`grid::unit(n,
"lines")` → `n` line-heights in the browser). **`"pt"`** / **`"points"`** are
converted with the ggplot2 default scale (~5.5 pt → 0.25 lines). Other units
(`"cm"`, `"mm"`, etc.) pass through as a numeric value interpreted as a line
count, not a physical conversion. Pixels are not used directly.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please delete or clarify.
if only lines are supported then we should error for other units?

Drop the long units block ; kept tests and
example pointer for issue.
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock I have removed the long Supported units paragraph from NEWS (Option A). The 2026.5.29 entry now only has the regression-test note, thanks, and the link to panel-margin-issue-180.R.

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.

theme(panel.margin=grid::unit(positive_number, "lines")) should work

2 participants