Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Jan 13, 2024
1 parent 1982b6c commit ccaeaf6
Show file tree
Hide file tree
Showing 22 changed files with 2,310 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/density.R
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ bw_fallback = function(f, x, ..., call = caller_env()) {
(e.g., {.fun density_histogram}, {.code stat_slab(density = 'histogram')},
or {.fun stat_histinterval}) may better represent the data."
),
class = "ggdist_warn_bandwidth_fallback",
class = "ggdist_bandwidth_fallback_warning",
call = call,
parent = e
)
Expand Down
2 changes: 1 addition & 1 deletion R/distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ distr_set_sample = function(dist, value) {
} else if (inherits(dist, "distribution")) {
old_class = oldClass(dist)
dist = unclass(dist)
dist[[1]][["x"]] = value
dist[[1]] = distr_set_sample(dist[[1]], value)
class(dist) = old_class
} else if (inherits(dist, c("dist_sample", "ggdist__weighted_sample"))) {
dist[["x"]] = value
Expand Down
2 changes: 1 addition & 1 deletion R/geom.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ get_orientation = function(flipped_aes) {
# function (for convenience): these are variables (typically aesthetics)
# that differ depending on whether the geom's orientation is horizontal
# or vertical. They are named assuming a horizontal orientation.
globalVariables(c("height", "y", "ymin", "ymax", "yend", "x", "xmin", "xmax", "xend","x.range","y.range"))
globalVariables(c("width.", "height", "y", "ymin", "ymax", "yend", "x", "xmin", "xmax", "xend","x.range","y.range"))
define_orientation_variables = function(orientation) {
f = parent.frame()

Expand Down
8 changes: 5 additions & 3 deletions R/geom_dotsinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ makeContent.dots_grob = function(x) {
c(y, "side", "justification", "scale"),
function(d) {
if (nrow(unique(d)) > 1) {
cli_abort(c(
cli_abort(
"Cannot draw a subguide for the dot count axis when multiple dots
geometries with different parameters are drawn on the same axis."
))
geometries with different parameters are drawn on the same axis.",
class = "ggdist_incompatible_subguides"
)
}
d = d[1, ]

Expand Down Expand Up @@ -215,6 +216,7 @@ draw_slabs_dots = function(self, s_data, panel_params, coord,

# slab thickness is fixed to 1 for dotplots
s_data$thickness = 1
subguide_params = NULL
c(s_data, subguide_params) %<-% rescale_slab_thickness(
s_data, orientation, normalize, na.rm, name = "geom_dotsinterval"
)
Expand Down
7 changes: 4 additions & 3 deletions R/geom_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ draw_slabs = function(self, s_data, panel_params, coord,
dlply_(subguide_params, c(y, "side", "justification", "scale"), function(d) {
d$group = NULL
if (nrow(unique(d)) > 1) {
cli_abort(c(
cli_abort(
"Cannot draw a subguide for the thickness axis when multiple slabs
with different normalizations are drawn on the same axis."
))
with different normalizations are drawn on the same axis.",
class = "ggdist_incompatible_subguides"
)
}

# construct a viewport such that the guide drawn in this viewport
Expand Down
1 change: 1 addition & 0 deletions R/geom_spike.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ draw_slabs_spike = function(self, s_data, panel_params, coord,
# remove missing values - unlike slabinterval, thickness NAs not allowed here
s_data = ggplot2::remove_missing(s_data, na.rm, "thickness", name = "geom_spike")

subguide_params = NULL
c(s_data, subguide_params) %<-% rescale_slab_thickness(
s_data, orientation, normalize, na.rm, name = "geom_spike"
)
Expand Down
5 changes: 4 additions & 1 deletion R/scale_thickness.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ vec_arith.ggdist_thickness.ggdist_thickness <- function(op, x, y, ...) {

incompatible = !(use_x | use_y)
if (any(incompatible)) {
cli_abort("incompatible <thickness> bounds at locations {which(incompatible)}")
cli_abort(
"incompatible <thickness> bounds at locations {which(incompatible)}",
class = "ggdist_incompatible_thickness_bounds"
)
}

x_bound[use_y] = y_bound[use_y]
Expand Down
4 changes: 2 additions & 2 deletions R/stat_spike.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ check_at = function(at, call = parent.frame()) {
"x" = "{.arg at} is a {.cls {class(at)}}.",
"i" = "See the {.arg at} parameter of {.fun ggdist::stat_spike}."
),
class = "ggdist_param_at_invalid",
class = "ggdist_invalid_at_param",
call = call
)
}
Expand All @@ -195,7 +195,7 @@ check_at = function(at, call = parent.frame()) {
"x" = "{if (length(wrong_type_i) > 1) 'For example, '}{.code at[[{i}]]} is a {.cls {class(at[[i]])}}.",
"i" = "See the {.arg at} parameter of {.fun ggdist::stat_spike}."
),
class = "ggdist_param_at_invalid",
class = "ggdist_invalid_at_param",
call = call
)
}
Expand Down
1 change: 1 addition & 0 deletions R/subguide.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ subguide_axis = auto_partial(name = "subguide_axis", function(

title_element = calc_element(paste0("axis.title.", y), theme)
title_margin = max(title_element$margin)
title_element$margin = margin(0, 0, 0, 0)
title_grob = element_grob(title_element, label = title)
title_width = grob_width(title_grob)

Expand Down
Loading

0 comments on commit ccaeaf6

Please sign in to comment.