@@ -185,14 +185,10 @@ function renderChart({
185
185
)
186
186
187
187
// Each group gets a transparent rect covering the full band (using paddedScale.step())
188
- barGroups
188
+ const outerBars = barGroups
189
189
.append (' rect' )
190
190
.attr (' fill' , ' transparent' )
191
191
.attr (' pointer-events' , ' all' )
192
- .attr (' x' , 0 )
193
- .attr (' y' , (d ) => vertical ? y (d .value ) - groupOffset : 0 )
194
- .attr (' width' , (d ) => vertical ? paddedScale .step () : y (d .value ) + groupOffset )
195
- .attr (' height' , (d ) => vertical ? height - y (d .value ) + groupOffset : paddedScale .step ())
196
192
197
193
// Append the colored bar rect inside each group.
198
194
// We now offset it by groupOffset so its left edge is at paddedScale(d.key)
@@ -204,12 +200,22 @@ function renderChart({
204
200
205
201
if (! animate ) {
206
202
if (vertical ) {
203
+ outerBars
204
+ .attr (' x' , 0 )
205
+ .attr (' y' , (d ) => y (d .value ) - groupOffset )
206
+ .attr (' width' , paddedScale .step ())
207
+ .attr (' height' , (d ) => height - y (d .value ) + groupOffset )
207
208
bars
208
209
.attr (' x' , groupOffset )
209
210
.attr (' y' , (d ) => y (d .value ))
210
211
.attr (' width' , paddedScale .bandwidth ())
211
212
.attr (' height' , (d ) => height - y (d .value ))
212
213
} else {
214
+ outerBars
215
+ .attr (' x' , 0 )
216
+ .attr (' y' , 0 )
217
+ .attr (' width' , (d ) => y (d .value ) + groupOffset )
218
+ .attr (' height' , paddedScale .step ())
213
219
bars
214
220
.attr (' x' , 0 )
215
221
.attr (' y' , groupOffset )
@@ -219,6 +225,16 @@ function renderChart({
219
225
} else {
220
226
// Animate the bars
221
227
if (vertical ) {
228
+ outerBars
229
+ .attr (' x' , 0 )
230
+ .attr (' y' , height )
231
+ .attr (' width' , paddedScale .step ())
232
+ .attr (' height' , 0 )
233
+ .transition ()
234
+ .duration (800 )
235
+ .delay ((_ , i ) => i * 100 )
236
+ .attr (' y' , (d ) => y (d .value ) - groupOffset )
237
+ .attr (' height' , (d ) => height - y (d .value ) + groupOffset )
222
238
bars
223
239
.attr (' x' , groupOffset )
224
240
.attr (' y' , height )
@@ -230,6 +246,15 @@ function renderChart({
230
246
.attr (' y' , (d ) => y (d .value ))
231
247
.attr (' height' , (d ) => height - y (d .value ))
232
248
} else {
249
+ outerBars
250
+ .attr (' x' , 0 )
251
+ .attr (' y' , 0 )
252
+ .attr (' width' , 0 )
253
+ .attr (' height' , paddedScale .step ())
254
+ .transition ()
255
+ .duration (800 )
256
+ .delay ((_ , i ) => i * 100 )
257
+ .attr (' width' , (d ) => y (d .value ) + groupOffset )
233
258
bars
234
259
.attr (' x' , 0 )
235
260
.attr (' y' , groupOffset )
@@ -285,6 +310,8 @@ function renderChart({
285
310
.style (' height' , ` ${height }px ` )
286
311
.style (' outline' , ' 1px solid blue' )
287
312
.style (' pointer-events' , ' none' )
313
+ outerBars
314
+ .style (' outline' , ' 1px solid green' )
288
315
}
289
316
}
290
317
0 commit comments