Skip to content

Commit

Permalink
Handle hashing in train()
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jul 9, 2023
1 parent 35a03d9 commit 08bfdb8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
11 changes: 6 additions & 5 deletions R/guide-.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ Guide <- ggproto(
return(NULL)
}
params$decor <- inject(self$extract_decor(scale, !!!params))
self$extract_params(scale, params, self$hashables, ...)
params <- self$extract_params(scale, params, ...)
# Make hash
# TODO: Maybe we only need the hash on demand during merging?
params$hash <- hash(lapply(unname(self$hashables), eval_tidy, data = params))
params
},

# Setup parameters that are only available after training
# TODO: Maybe we only need the hash on demand during merging?
extract_params = function(scale, params, hashables, ...) {
# Make hash
params$hash <- hash(lapply(unname(hashables), eval_tidy, data = params))
extract_params = function(scale, params, ...) {
params
},

Expand Down
4 changes: 2 additions & 2 deletions R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ GuideAxis <- ggproto(
ticks_length = "axis.ticks.length"
),

extract_params = function(scale, params, hashables, ...) {
extract_params = function(scale, params, ...) {
params$name <- paste0(params$name, "_", params$aesthetic)
Guide$extract_params(scale, params, hashables)
params
},

extract_decor = function(scale, aesthetic, position, key, cap = "none", ...) {
Expand Down
5 changes: 2 additions & 3 deletions R/guide-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ GuideBins <- ggproto(
return(key)
},

extract_params = function(scale, params, hashables,
extract_params = function(scale, params,
title = waiver(), direction = NULL, ...) {

show.limits <- params$show.limits %||% scale$show.limits %||% FALSE
Expand Down Expand Up @@ -320,8 +320,7 @@ GuideBins <- ggproto(
"not {.val {params$label.position}}."
))
}

Guide$extract_params(scale, params, hashables)
params
},

setup_params = function(params) {
Expand Down
4 changes: 2 additions & 2 deletions R/guide-colorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ GuideColourbar <- ggproto(
return(bar)
},

extract_params = function(scale, params, hashables,
extract_params = function(scale, params,
title = waiver(), direction = "vertical", ...) {
params$title <- scale$make_title(
params$title %|W|% scale$name %|W|% title
Expand Down Expand Up @@ -374,7 +374,7 @@ GuideColourbar <- ggproto(
c(0.5, params$nbin - 0.5) / params$nbin,
limits
)
Guide$extract_params(scale, params, hashables)
params
},

merge = function(self, params, new_guide, new_params) {
Expand Down
4 changes: 2 additions & 2 deletions R/guide-colorsteps.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ GuideColoursteps <- ggproto(
return(bar)
},

extract_params = function(scale, params, hashables, ...) {
extract_params = function(scale, params, ...) {

if (params$even.steps) {
params$nbin <- nbin <- sum(!is.na(params$key[[1]])) + 1
Expand Down Expand Up @@ -177,6 +177,6 @@ GuideColoursteps <- ggproto(
params$key <- key
}

GuideColourbar$extract_params(scale, params, hashables, ...)
GuideColourbar$extract_params(scale, params, ...)
}
)
5 changes: 2 additions & 3 deletions R/guide-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ GuideLegend <- ggproto(
title.align = "legend.title.align"
),

extract_params = function(scale, params, hashables,
extract_params = function(scale, params,
title = waiver(), direction = NULL, ...) {
params$title <- scale$make_title(
params$title %|W|% scale$name %|W|% title
Expand All @@ -273,8 +273,7 @@ GuideLegend <- ggproto(
if (isTRUE(params$reverse %||% FALSE)) {
params$key <- params$key[nrow(params$key):1, , drop = FALSE]
}

Guide$extract_params(scale, params, hashables)
params
},

merge = function(self, params, new_guide, new_params) {
Expand Down
8 changes: 4 additions & 4 deletions man/ggplot2-ggproto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 08bfdb8

Please sign in to comment.