@@ -97,6 +97,7 @@ function renderChart({
97
97
98
98
// Compute a constant offset to center the colored bar inside its full band.
99
99
const groupOffset = (paddedScale .step () - paddedScale .bandwidth ()) / 2
100
+ const heightPadding = 24
100
101
101
102
// For the axes, use the paddedScale so ticks remain centered on the bars.
102
103
svg
@@ -202,9 +203,9 @@ function renderChart({
202
203
if (vertical ) {
203
204
outerBars
204
205
.attr (' x' , 0 )
205
- .attr (' y' , (d ) => y (d .value ) - groupOffset )
206
+ .attr (' y' , (d ) => Math . max ( 0 , y (d .value ) - heightPadding ) )
206
207
.attr (' width' , paddedScale .step ())
207
- .attr (' height' , (d ) => height - y (d .value ) + groupOffset )
208
+ .attr (' height' , (d ) => height - Math . max ( 0 , y (d .value ) - heightPadding ) )
208
209
bars
209
210
.attr (' x' , groupOffset )
210
211
.attr (' y' , (d ) => y (d .value ))
@@ -214,7 +215,7 @@ function renderChart({
214
215
outerBars
215
216
.attr (' x' , 0 )
216
217
.attr (' y' , 0 )
217
- .attr (' width' , (d ) => y (d .value ) + groupOffset )
218
+ .attr (' width' , (d ) => Math . min ( width , y (d .value ) + heightPadding ) )
218
219
.attr (' height' , paddedScale .step ())
219
220
bars
220
221
.attr (' x' , 0 )
@@ -233,8 +234,8 @@ function renderChart({
233
234
.transition ()
234
235
.duration (800 )
235
236
.delay ((_ , i ) => i * 100 )
236
- .attr (' y' , (d ) => y (d .value ) - groupOffset )
237
- .attr (' height' , (d ) => height - y (d .value ) + groupOffset )
237
+ .attr (' y' , (d ) => Math . max ( 0 , y (d .value ) - heightPadding ) )
238
+ .attr (' height' , (d ) => height - Math . max ( 0 , y (d .value ) - heightPadding ) )
238
239
bars
239
240
.attr (' x' , groupOffset )
240
241
.attr (' y' , height )
@@ -254,7 +255,7 @@ function renderChart({
254
255
.transition ()
255
256
.duration (800 )
256
257
.delay ((_ , i ) => i * 100 )
257
- .attr (' width' , (d ) => y (d .value ) + groupOffset )
258
+ .attr (' width' , (d ) => Math . min ( width , y (d .value ) + heightPadding ) )
258
259
bars
259
260
.attr (' x' , 0 )
260
261
.attr (' y' , groupOffset )
0 commit comments