-
Notifications
You must be signed in to change notification settings - Fork 44
test: add regression tests for issue #279 (facet_wrap spacing with custom height) #288
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
ANAMASGARD
wants to merge
25
commits into
master
Choose a base branch
from
fix-issue-279-facet-height-spacing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e2211ad
test: add regression test for issue #279 facet_wrap spacing
ANAMASGARD 31acddd
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD a659929
fix #279: set SVG display:block to eliminate inline whitespace below …
ANAMASGARD 260c26f
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 98f7efa
fix CI: use robust SVG id extraction to avoid matrix dimension error
ANAMASGARD f4b796e
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 3d0a90f
Merge branch 'master' into fix-issue-279-facet-height-spacing
tdhock 74c745a
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 74b3f42
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD e19b3b5
test: addresses Sir tdhock review comments for issue #279
ANAMASGARD c48f242
ci: trigger GitHub Actions
ANAMASGARD acce7a2
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 6a99013
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 6f2a5fe
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 4112796
test: address review feedback and guard display:block fix for #279
ANAMASGARD bdc834f
fix: robust SVG id extraction after display:block attrs change
ANAMASGARD 246f9a3
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 0d1a83d
test: use getStyleValue and get_element_bbox for issue #279
ANAMASGARD da904bc
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD d7d25c1
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD ab5483f
test: address tdhock review for issue #279
ANAMASGARD 417dc31
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 905fc4e
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD 15eb57a
fix #279: document SVG display:block and bump version
ANAMASGARD 4bac89a
Merge branch 'master' into fix-issue-279-facet-height-spacing
ANAMASGARD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/testthat/test-issue-279-facet-wrap-custom-height-spacing.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| test_that("facet_wrap SVG height is proportional to theme_animint height, no excess space (#279)", { | ||
| task_data <- data.frame( | ||
| x = rep(1:5, 5), | ||
| y = rep(1:5, 5), | ||
| task_id = rep(c("sonar", "spam", "vowel", "waveform", "zip"), each = 5) | ||
| ) | ||
| n_facets <- length(unique(task_data$task_id)) | ||
| default_theme_height <- 400 | ||
| custom_theme_height <- 600 | ||
| svg_xpath <- "//svg[@id='plot_plot']" | ||
| svg_sel <- "svg#plot_plot" | ||
| parent_sel <- "td:has(> svg#plot_plot)" | ||
| base_plot <- ggplot() + | ||
| geom_point(aes(x, y), data = task_data) + | ||
| facet_wrap(~ task_id, ncol = 1) + | ||
| theme_bw() | ||
| viz_list <- list( | ||
| default = animint(plot = base_plot), | ||
| custom = animint(plot = base_plot + theme_animint(height = custom_theme_height)) | ||
| ) | ||
|
Comment on lines
+17
to
+20
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use animint() instead of list() ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced list(plot = ...) with animint(plot = ...) |
||
| heights <- list() | ||
| for (viz_name in names(viz_list)) { | ||
| info <- animint2HTML(viz_list[[viz_name]]) | ||
| svg_node <- getNodeSet(info$html, svg_xpath) | ||
| expect_equal(length(svg_node), 1L) | ||
| svg_attrs <- xmlAttrs(svg_node[[1]]) | ||
| display <- getStyleValue(info$html, svg_xpath, "display") | ||
| expect_equal(display, "block", | ||
| label = "plot SVG should have inline display:block to prevent whitespace below it") | ||
| svg_box <- get_element_bbox(svg_sel) | ||
| parent_box <- get_element_bbox(parent_sel) | ||
| bottom_gap <- (parent_box$top + parent_box$height) - (svg_box$top + svg_box$height) | ||
| expect_lte(bottom_gap, 1, | ||
| label = "no excess rendered gap below plot SVG (issue #279)") | ||
| heights[[viz_name]] <- as.numeric(svg_attrs[["height"]]) | ||
| } | ||
| expect_lt(heights$default, default_theme_height * n_facets) | ||
| expect_lt(heights$custom, custom_theme_height * n_facets, | ||
| label = sprintf( | ||
| "SVG height should not be %d*num_facets — regression from issue #279", | ||
| custom_theme_height)) | ||
| expect_gt(heights$custom, heights$default) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why do we need to add display block?
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.
Plot SVGs are inline by default, so the browser leaves a little space under them for text descenders. That shows up as whitespace below the plot (#279). Setting display: block removes that gap without changing facet layout. Locally the gap was about 5px without it and 1px with it. Also added NEWS and a DESCRIPTION version bump.
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.
ok, if I understand correctly, display: block reduces the space between svgs? is that when there are multiple ggplots or multiple facet panels? can this PR work without the display: block? or is adding that necessary to get it to work? if it is necessary, please explain why in NEWS? If not, please remove from this PR.