@@ -98,15 +98,19 @@ GuideColoursteps <- ggproto(
9898 return (Guide $ extract_key(scale , aesthetic ))
9999 }
100100
101- parsed <- parse_binned_breaks(scale , breaks , even.steps )
101+ parsed <- parse_binned_breaks(scale , breaks )
102102 if (is.null(parsed )) {
103103 return (parsed )
104104 }
105105 limits <- parsed $ limits
106106 breaks <- parsed $ breaks
107107
108108 key <- data_frame0(!! aesthetic : = scale $ map(breaks ))
109- key $ .value <- seq_along(breaks )
109+ if (even.steps ) {
110+ key $ .value <- seq_along(breaks )
111+ } else {
112+ key $ .value <- breaks
113+ }
110114 key $ .label <- scale $ get_labels(breaks )
111115
112116 if (breaks [1 ] %in% limits ) {
@@ -117,35 +121,34 @@ GuideColoursteps <- ggproto(
117121 key [[1 ]][nrow(key )] <- NA
118122 }
119123 # To avoid having to recalculate these variables in other methods, we
120- # attach these as attributes. It might not be very elegant, but it works.
121- attr( key , " limits " ) <- parsed $ limits
122- attr(key , " bin_at " ) <- parsed $ bin_at
123- return ( key )
124+ # attach the parsed values as attributes. It might not be very elegant,
125+ # but it works.
126+ attr(key , " parsed " ) <- parsed
127+ key
124128 },
125129
126130 extract_decor = function (scale , aesthetic , key ,
127131 reverse = FALSE , even.steps = TRUE ,
128132 nbin = 100 , alpha = NA ,... ) {
133+
134+ parsed <- attr(key , " parsed" )
135+ breaks <- parsed $ breaks %|| % scale $ get_breaks()
136+ limits <- parsed $ limits %|| % scale $ get_limits()
137+
138+ breaks <- sort(unique0(c(limits , breaks )))
139+ n <- length(breaks )
140+ bin_at <- parsed $ bin_at %|| % ((breaks [- 1 ] + breaks [- n ]) / 2 )
141+
129142 if (even.steps ) {
130- bin_at <- attr(key , " bin_at" , TRUE )
131- bar <- data_frame0(
132- colour = alpha(scale $ map(bin_at ), alpha ),
133- min = seq_along(bin_at ) - 1 ,
134- max = seq_along(bin_at ),
135- .size = length(bin_at )
136- )
137- } else {
138- breaks <- unique(sort(c(scale $ get_limits(), scale $ get_breaks())))
139- n <- length(breaks )
140- bin_at <- (breaks [- 1 ] + breaks [- n ]) / 2
141- bar <- data_frame0(
142- colour = alpha(scale $ map(bin_at ), alpha ),
143- min = head(breaks , - 1 ),
144- max = tail(breaks , - 1 ),
145- .size = length(bin_at )
146- )
143+ breaks <- seq_len(n ) - 1L
147144 }
148- return (bar )
145+
146+ data_frame0(
147+ colour = alpha(scale $ map(bin_at ), alpha ),
148+ min = breaks [- n ],
149+ max = breaks [- 1 ],
150+ .size = length(bin_at )
151+ )
149152 },
150153
151154 extract_params = function (scale , params , direction = " vertical" , title = waiver(), ... ) {
@@ -166,7 +169,7 @@ GuideColoursteps <- ggproto(
166169
167170 if (show.limits ) {
168171 key <- params $ key
169- limits <- attr(key , " limits " , TRUE ) %|| % scale $ get_limits()
172+ limits <- attr(key , " parsed " ) $ limits %|| % scale $ get_limits()
170173 key <- key [c(NA , seq_len(nrow(key )), NA ), , drop = FALSE ]
171174 n <- nrow(key )
172175 key $ .value [c(1 , n )] <- range(params $ decor $ min , params $ decor $ max )
0 commit comments