-
Notifications
You must be signed in to change notification settings - Fork 1
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
Vertical layout -- a different approach #111
Conversation
Rather than wrapping `prepare_chart()` in a tryCatch and setting aes defaults outside the function, move the default aes handling to inside the function. This actually allows for much cleaner code, as we can utilize the function `on.exit()` instead of `tryCatch()`.
removes the subfn `construct_layout`, reintegrating these components into the main function. Delays the call to `prepare_chart()` and creation of `vp.plotbox` until the plot is actually used. This is in preparation for delaying the calculation of plotbox size. Integrates the `prepare_chart` subfn directly into `grob_plot`.
and new calculation forplotbox height adjusting for the height of the new bottom caption bottom.
`vert_mode` is, for the time being, interpreted from the existing `title_width` argument. grobs are now added to a list `grobs` rather than specified individually, so that the `final_plot` can be constructed dynamically (e.g. with or without unnecessary grobs) without complex code.
`grobs$title` and `grobs$caption` now only created in horizontal/traditional mode, while `grobs$caption_bottom` now only created in vertical mode. New `safe_grobHeight` subfn takes a list object (eg `grobs$this_grob`) and returns 0 bigpts if `this_grob` does not exist in list `grobs`. Otherwise, it returns `grid::grobHeight()`.
I'm not sure what was going on with the incorrect plot sizing when `legend_shift = TRUE`, but I traced the break back to when I had redefined plotbox_height as a complex height object that incldued some bigpts and the `grobHeight(grobs$caption_bottom)`. This commit modifies the `safe_grobHeight()` fn to convert `grobHeights` into other units (mainly, bigpts) and return them as unitless objects. This allowed me to revert to Daniel's original code for calculating the `plot_height` and generating the `built` object. This also allowed me to simplify the other code that refers to `grobHeight()`s.
references to `final_plot` are now `finished_graphic` to clarify that the "plot" is the thing drawn in the "plotbox" -- the "graphic" is the assembly of grobs that represent the finished product.
`prepare_chart()` is now `prepare_plot()` to continue to align terms
This is ready for review and testing. This makes a variety of under-the-hood improvements to
There's enough change under the hood here -- and we now can more officially say we support no-sidebar graphics -- that I'm suggesting we update version to 1.1.0. But I'm flexible. Sample outputs(
|
to enable horizontal caption alignment, deprecate `caption_valign` in favor of new arg `caption_align` that takes a numeric 0 to 1 and is passed directly to left caption grob's `valign` argument and bottom caption grob's `halign` argument. This prevents the addition of a `caption_halign` argument, and more completely utilizes the underlying functionality `textbox_grob()`'s valign and halign arguments (ie user can now pass 0.5 for center alignment).
Minor changes
create news.md
Just a reminder that we'll need to:
|
Also, the old figure numbering was a complete mess
title_width must range from 0 to width/2. caption_align from 0 to 1.
Changes in capitalization and line breaks for consistency
R/finalize_plot.R
Outdated
) | ||
} | ||
|
||
# in vertical mode, and if caption exists, create bottom caption box (but no title) |
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.
I understand the rationale for this - however, I think that it may be helpful in the future to have the ability to have a title in the vertical layout, potentially above the bar (which was what I had implemented, however jankily, in #109 ). It would create some more complexity, because then you need to have an adjustment to the top line positioning - although I think we could accomplish that with a similar use of the safe_grobheight function you've developed (that one is nice, by the way). Not an urgent function, but something to think about for the future.
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.
Agreed. My apologies for missing that part of your work in #109. With safe_grobHeight()
and the new conditional grob build framework, it shouldn't be hard to install an alternate title grob above the topline. It would be really easy, I think... if a new grob top_title (or maybe we change to title_vert
and caption_vert
) gets created before the topline does, the topline height could be set to the top margin plus safe_grobheight(top_title)
...
If you wanted to put together a PR that (re)implements this, I don't see a reason not to implement it.
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.
I made some minor formatting tweaks and have one suggestion for future functionality (adding titles to vertical layouts) which others may have different ideas on. I think that this is a great upgrade to the function, though - great work, @matthewstern .
@matthewstern @nmpeterson I'm not sure what has happened here - the Windows checks are failing on GitHub, but are not failing when I run them on my computer. The error seems to have something to do with a package called |
Hmm and it's not the result of my commit, since the check still fails when I reverted it. Not sure what's up. |
@dlcomeaux, thanks for looking! I ran into a similar issue with the auto-checks a few PRs ago. It looks like the package Considering the Mac check passes (and Windows checks pass on both our computers, I think it's reasonable to merge this and re-check the master branch in a few days to verify no issues. Does that seem reasonable? (@nmpeterson) EDIT: I love that the check is failing because of a package that enables significance brackets... so arcane. |
I'm re-running the jobs right now. If they fail again, I do think it's fine to force the merge. As @matthewstern noted, these issues can crop up occasionally when the virtual machines are setting up their R environment (which is done from scratch each time a job is run) and new versions of dependency packages have recently been added to CRAN but the compiled binaries for those packages are not yet ready. Edit: aaaaand it failed. |
FWIW the pkgdown build also failed after merging, due maybe to a similar issue in package "broom"? https://github.com/CMAP-REPOS/cmapplot/runs/1972107044 Hopefully both issues will resolve themselves in the coming days. |
It's pillar, actually. Note the CRAN page currently lists the version as 1.5.0 but the binaries are still 1.4.7. We can re-run the jobs when the binary versions match the package version. |
This is inspired by #109 but takes a different approach, in which I adjust the overall flow of the finalize_plot() function to account for the new needs placed on it. My goal is to reduce redundancies to near zero and keep the function highly legible.
This is a work-in-progress. I'm trying to keep the commit descriptions clear, but I'll eventually update this post with a clear description about what this tinkers with.EDIT: I think I have succeeded. This PR nets only a few new lines of code (not counting NEWS.md), but both adds features and eliminates redundancy. Detailed changes down below in this comment.