Skip to content
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

breaks_pretty() will return zero-range limit #455

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix #446.

Briefly, it ensures that breaks_pretty() with zero-range x returns the one limit.

In more detail, the precedence of #446 is as follows:

transform_time()$breaks is breaks_pretty().
breaks_pretty() uses pretty()
pretty.Date() uses grDevices:::prettyDate()

The only time {scales} can intercept is during breaks_pretty(). I've tried passing different options to pretty() to preserve some formatting advantages: they don't work. I've settled on just returning the limit because it is not unreasonable to assume that if you want to label one and only one thing, the label should be at the thing you want rather than at some 'pretty' location you don't have data for.

Reprex from issue:

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales
limits <- lubridate::as_datetime("2010-08-03 00:50:50")
limits <- c(limits, limits)

trans  <- transform_time()
breaks <- trans$breaks(limits)
labels <- trans$format(breaks)
labels
#> [1] "2010-08-03 00:50:50"

Created on 2024-10-07 with reprex v2.1.1

@thomasp85 thomasp85 merged commit 05f519b into r-lib:main Oct 21, 2024
12 checks passed
@thomasp85
Copy link
Member

Thanks

@teunbrand teunbrand deleted the zero_width_breaks_pretty branch October 21, 2024 13:17
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.

Label formatting in transform_time() with zero-width limits
2 participants