Skip to content

Commit 3b4c3a9

Browse files
committed
use field to store params to update
1 parent 5272850 commit 3b4c3a9

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

R/scale-.R

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ Scale <- ggproto("Scale", NULL,
532532
)
533533
},
534534

535+
updatable_params = c(
536+
"aesthetics", "scale_name", "palette", "name", "breaks", "labels",
537+
"limits", "expand", "na.value", "guide", "position", "call",
538+
"super"
539+
),
540+
535541
update = function(self, params) {
536542
check_update_params(self, params)
537543
inject(self$new(!!!params))
@@ -560,16 +566,7 @@ check_breaks_labels <- function(breaks, labels, call = NULL) {
560566
}
561567

562568
check_update_params <- function(scale, params) {
563-
if (inherits(scale, "ScaleContinuous")) {
564-
args <- fn_fmls_names(continuous_scale)
565-
} else if (inherits(scale, "ScaleDiscrete")) {
566-
args <- fn_fmls_names(discrete_scale)
567-
} else if (inherits(scale, "ScaleBinned")) {
568-
args <- fn_fmls_names(binned_scale)
569-
} else {
570-
# We don't know what valid parameters are of custom scale types
571-
return(invisible(NULL))
572-
}
569+
args <- scale$updatable_params
573570
extra <- setdiff(names(params), args)
574571
if (length(extra) == 0) {
575572
return(invisible(NULL))
@@ -902,6 +899,11 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
902899
)
903900
},
904901

902+
updatable_params = c(
903+
Scale$updatable_params,
904+
"minor_breaks", "n.breaks", "rescaler", "oob", "transform"
905+
),
906+
905907
update = function(self, params) {
906908
check_update_params(self, params)
907909
# We may need to update limits when previously transformed and
@@ -1145,6 +1147,11 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
11451147
)
11461148
},
11471149

1150+
updatable_params = c(
1151+
Scale$updatable_params,
1152+
"minor_breaks", "na.translate", "drop"
1153+
),
1154+
11481155
new = function(self, aesthetics = NULL, palette = NULL, limits = NULL, call = caller_call(),
11491156
range = DiscreteRange$new(),
11501157
..., super = NULL) {
@@ -1416,6 +1423,12 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
14161423
major_source = major, minor_source = NULL)
14171424
},
14181425

1426+
updatable_params = c(
1427+
Scale$updatable_params,
1428+
"rescaler", "oob", "n.breaks", "nice.breaks",
1429+
"right", "transform", "show.limits"
1430+
),
1431+
14191432
new = function(self, ..., super = NULL) {
14201433
ggproto_parent(ScaleContinuous, self)$new(..., super = super %||% self)
14211434
}

0 commit comments

Comments
 (0)