Skip to content

Commit 0e7b171

Browse files
committed
Change minor_breaks interface
To pass in both limits and major breaks. This will make it much easier to create useful families of minor break functions in scales. Fixes #3583
1 parent 6f5ffea commit 0e7b171

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

R/scale-.r

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#' - `waiver()` for the default breaks (one minor break between
2525
#' each major break)
2626
#' - A numeric vector of positions
27-
#' - A function that given the limits returns a vector of minor breaks.
27+
#' - A function passed the limits and major breaks, which should return a
28+
#' vector of minor breaks.
2829
#' @param labels One of:
2930
#' - `NULL` for no labels
3031
#' - `waiver()` for the default labels computed by the
@@ -613,8 +614,15 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
613614
breaks <- self$trans$minor_breaks(b, limits, n)
614615
}
615616
} else if (is.function(self$minor_breaks)) {
616-
# Find breaks in data space, and convert to numeric
617-
breaks <- self$minor_breaks(self$trans$inverse(limits))
617+
breaks_fun <- self$minor_breaks
618+
619+
if (length(formals(breaks_fun)) == 1) {
620+
# Old API just gets limits
621+
breaks <- breaks_fun(self$trans$inverse(limits))
622+
} else {
623+
# New API gets limits and breaks
624+
breaks <- breaks_fun(self$trans$inverse(limits), b)
625+
}
618626
breaks <- self$trans$transform(breaks)
619627
} else {
620628
breaks <- self$trans$transform(self$minor_breaks)

man/continuous_scale.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_continuous.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_gradient.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_size.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)