Skip to content

Commit f71d346

Browse files
committed
use helper
1 parent 38b0e3f commit f71d346

File tree

6 files changed

+52
-34
lines changed

6 files changed

+52
-34
lines changed

R/geom-bar.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ GeomBar <- ggproto("GeomBar", GeomRect,
130130
# limits, not just those for which x and y are outside the limits
131131
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),
132132

133-
default_aes = aes(!!!GeomRect$default_aes, width = NULL),
133+
default_aes = aes(!!!GeomRect$default_aes, width = 0.9),
134134

135135
setup_params = function(data, params) {
136136
params$flipped_aes <- has_flipped_aes(data, params)
@@ -139,14 +139,13 @@ GeomBar <- ggproto("GeomBar", GeomRect,
139139

140140
extra_params = c("just", "na.rm", "orientation"),
141141

142-
setup_data = function(data, params) {
142+
setup_data = function(self, data, params) {
143143
data$flipped_aes <- params$flipped_aes
144144
data <- flip_data(data, params$flipped_aes)
145-
data$width <- data$width %||%
146-
params$width %||% (min(vapply(
147-
split(data$x, data$PANEL, drop = TRUE),
148-
resolution, numeric(1), zero = FALSE
149-
)) * 0.9)
145+
data <- compute_data_size(
146+
data, size = params$width,
147+
default = self$default_aes$width, zero = FALSE
148+
)
150149
data$just <- params$just %||% 0.5
151150
data <- transform(data,
152151
ymin = pmin(y, 0), ymax = pmax(y, 0),

R/geom-boxplot.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,21 @@ geom_boxplot <- function(mapping = NULL, data = NULL,
176176
#' @export
177177
GeomBoxplot <- ggproto("GeomBoxplot", Geom,
178178

179-
# need to declare `width` here in case this geom is used with a stat that
180-
# doesn't have a `width` parameter (e.g., `stat_identity`).
181-
extra_params = c("na.rm", "width", "orientation", "outliers"),
179+
extra_params = c("na.rm", "orientation", "outliers"),
182180

183181
setup_params = function(data, params) {
184182
params$flipped_aes <- has_flipped_aes(data, params)
185183
params
186184
},
187185

188-
setup_data = function(data, params) {
186+
setup_data = function(self, data, params) {
189187
data$flipped_aes <- params$flipped_aes
190188
data <- flip_data(data, params$flipped_aes)
191-
data$width <- data$width %||%
192-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
193-
189+
data <- compute_data_size(
190+
data, params$width,
191+
default = self$default_aes$width,
192+
zero = FALSE, discrete = TRUE
193+
)
194194
if (isFALSE(params$outliers)) {
195195
data$outliers <- NULL
196196
}
@@ -331,7 +331,8 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
331331
weight = 1, colour = from_theme(col_mix(ink, paper, 0.2)),
332332
fill = from_theme(paper), size = from_theme(pointsize),
333333
alpha = NA, shape = from_theme(pointshape), linetype = from_theme(bordertype),
334-
linewidth = from_theme(borderwidth)
334+
linewidth = from_theme(borderwidth),
335+
width = 0.9
335336
),
336337

337338
required_aes = c("x|y", "lower|xlower", "upper|xupper", "middle|xmiddle", "ymin|xmin", "ymax|xmax"),

R/geom-dotplot.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,16 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
194194
alpha = NA,
195195
stroke = from_theme(borderwidth * 2),
196196
linetype = from_theme(linetype),
197-
weight = 1
197+
weight = 1,
198+
width = 0.9
198199
),
199200

200-
setup_data = function(data, params) {
201-
data$width <- data$width %||%
202-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
201+
setup_data = function(self, data, params) {
202+
data <- compute_data_size(
203+
data, params$width,
204+
default = self$default_aes$width,
205+
zero = FALSE, discrete = TRUE
206+
)
203207

204208
# Set up the stacking function and range
205209
if (is.null(params$stackdir) || params$stackdir == "up") {

R/geom-errorbar.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
3333
colour = from_theme(ink),
3434
linewidth = from_theme(linewidth),
3535
linetype = from_theme(linetype),
36-
width = 0.5,
36+
width = 0.9,
3737
alpha = NA
3838
),
3939

@@ -47,17 +47,21 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
4747

4848
extra_params = c("na.rm", "orientation"),
4949

50-
setup_data = function(data, params) {
50+
setup_data = function(self, data, params) {
5151
data$flipped_aes <- params$flipped_aes
5252
data <- flip_data(data, params$flipped_aes)
53-
data$width <- data$width %||%
54-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
53+
data <- compute_data_size(
54+
data, params$width,
55+
default = self$default_aes$width,
56+
zero = FALSE, discrete = TRUE
57+
)
5558
data <- transform(data,
5659
xmin = x - width / 2, xmax = x + width / 2, width = NULL
5760
)
5861
flip_data(data, params$flipped_aes)
5962
},
6063

64+
# Note: `width` is vestigial
6165
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
6266
width = NULL, flipped_aes = FALSE) {
6367
data <- check_linewidth(data, snake_class(self))

R/geom-tile.R

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ geom_tile <- function(mapping = NULL, data = NULL,
109109
GeomTile <- ggproto("GeomTile", GeomRect,
110110
extra_params = c("na.rm"),
111111

112-
setup_data = function(data, params) {
113-
114-
data$width <- data$width %||% params$width %||%
115-
stats::ave(data$x, data$PANEL, FUN = function(x) resolution(x, FALSE, TRUE))
116-
data$height <- data$height %||% params$height %||%
117-
stats::ave(data$y, data$PANEL, FUN = function(y) resolution(y, FALSE, TRUE))
112+
setup_data = function(self, data, params) {
118113

114+
data <- compute_data_size(
115+
data, params$width,
116+
default = self$default_aes$width,
117+
panels = "by", target = "width",
118+
zero = FALSE, discrete = TRUE
119+
)
120+
data <- compute_data_size(
121+
data, params$height,
122+
default = self$default_aes$height,
123+
panels = "by", target = "height",
124+
zero = FALSE, discrete = TRUE
125+
)
119126
transform(data,
120127
xmin = x - width / 2, xmax = x + width / 2, width = NULL,
121128
ymin = y - height / 2, ymax = y + height / 2, height = NULL
@@ -127,7 +134,7 @@ GeomTile <- ggproto("GeomTile", GeomRect,
127134
colour = NA,
128135
linewidth = from_theme(0.4 * borderwidth),
129136
linetype = from_theme(bordertype),
130-
alpha = NA, width = NA, height = NA
137+
alpha = NA, width = 1, height = 1
131138
),
132139

133140
required_aes = c("x", "y"),

R/geom-violin.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ GeomViolin <- ggproto("GeomViolin", Geom,
131131

132132
extra_params = c("na.rm", "orientation", "lineend", "linejoin", "linemitre"),
133133

134-
setup_data = function(data, params) {
134+
setup_data = function(self, data, params) {
135135
data$flipped_aes <- params$flipped_aes
136136
data <- flip_data(data, params$flipped_aes)
137-
data$width <- data$width %||%
138-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
137+
data <- compute_data_size(
138+
data, params$width,
139+
default = self$default_aes$width
140+
)
139141
# ymin, ymax, xmin, and xmax define the bounding rectangle for each group
140142
data <- dapply(data, "group", transform,
141143
xmin = x - width / 2,
@@ -203,7 +205,8 @@ GeomViolin <- ggproto("GeomViolin", Geom,
203205
fill = from_theme(paper),
204206
linewidth = from_theme(borderwidth),
205207
linetype = from_theme(bordertype),
206-
alpha = NA
208+
alpha = NA,
209+
width = 0.9
207210
),
208211

209212
required_aes = c("x", "y"),

0 commit comments

Comments
 (0)