@@ -98,15 +98,19 @@ GuideColoursteps <- ggproto(
98
98
return (Guide $ extract_key(scale , aesthetic ))
99
99
}
100
100
101
- parsed <- parse_binned_breaks(scale , breaks , even.steps )
101
+ parsed <- parse_binned_breaks(scale , breaks )
102
102
if (is.null(parsed )) {
103
103
return (parsed )
104
104
}
105
105
limits <- parsed $ limits
106
106
breaks <- parsed $ breaks
107
107
108
108
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
+ }
110
114
key $ .label <- scale $ get_labels(breaks )
111
115
112
116
if (breaks [1 ] %in% limits ) {
@@ -117,35 +121,34 @@ GuideColoursteps <- ggproto(
117
121
key [[1 ]][nrow(key )] <- NA
118
122
}
119
123
# 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
124
128
},
125
129
126
130
extract_decor = function (scale , aesthetic , key ,
127
131
reverse = FALSE , even.steps = TRUE ,
128
132
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
+
129
142
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
147
144
}
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
+ )
149
152
},
150
153
151
154
extract_params = function (scale , params , direction = " vertical" , title = waiver(), ... ) {
@@ -166,7 +169,7 @@ GuideColoursteps <- ggproto(
166
169
167
170
if (show.limits ) {
168
171
key <- params $ key
169
- limits <- attr(key , " limits " , TRUE ) %|| % scale $ get_limits()
172
+ limits <- attr(key , " parsed " ) $ limits %|| % scale $ get_limits()
170
173
key <- key [c(NA , seq_len(nrow(key )), NA ), , drop = FALSE ]
171
174
n <- nrow(key )
172
175
key $ .value [c(1 , n )] <- range(params $ decor $ min , params $ decor $ max )
0 commit comments