@@ -220,33 +220,50 @@ export class StackedBar<Datum> extends XYComponentCore<Datum, StackedBarConfigIn
220220 const x = - barWidth / 2
221221 const width = barWidth
222222
223+ // --- Spacing between stacked items ---
224+ const stackSpacing = config . stackSpacing || 0
225+ let hWithSpacing = h
226+ let yWithSpacing = y
227+ // Only apply spacing between inner segments (not at base or top)
228+ const isInnerStack = accessorIndex > 0 && accessorIndex < this . getAccessors ( ) . length
229+ if ( ! isEntering && stackSpacing > 0 && isInnerStack ) {
230+ if ( this . isVertical ( ) ) {
231+ hWithSpacing = Math . max ( 0 , h - stackSpacing )
232+ yWithSpacing = y + ( isNegative ? - stackSpacing / 2 : stackSpacing / 2 )
233+ } else {
234+ hWithSpacing = Math . max ( 0 , h - stackSpacing )
235+ yWithSpacing = y + ( isNegative ? - stackSpacing / 2 : stackSpacing / 2 )
236+ }
237+ }
238+
223239 const cornerRadius = config . roundedCorners
224240 ? isNumber ( config . roundedCorners ) ? + config . roundedCorners : width / 2
225241 : 0
226- const cornerRadiusClamped = clamp ( cornerRadius , 0 , Math . min ( height , width ) / 2 )
242+ const cornerRadiusClamped = clamp ( cornerRadius , 0 , Math . min ( hWithSpacing , width ) / 2 )
227243 const isNorthDirected = this . yScale . range ( ) [ 0 ] > this . yScale . range ( ) [ 1 ]
228244
245+ const allCornersRounded = stackSpacing > 0 && ! ! config . roundedCorners
229246 return roundedRectPath ( {
230- x : this . isVertical ( ) ? x : y - h ,
231- y : this . isVertical ( ) ? y + ( isNorthDirected ? 0 : - h ) : x ,
232- w : this . isVertical ( ) ? width : h ,
233- h : this . isVertical ( ) ? h : width ,
234- tl : isEnding && ( this . isVertical ( )
247+ x : this . isVertical ( ) ? x : yWithSpacing - hWithSpacing ,
248+ y : this . isVertical ( ) ? yWithSpacing + ( isNorthDirected ? 0 : - hWithSpacing ) : x ,
249+ w : this . isVertical ( ) ? width : hWithSpacing ,
250+ h : this . isVertical ( ) ? hWithSpacing : width ,
251+ tl : allCornersRounded || ( isEnding && ( this . isVertical ( )
235252 ? ( ! isNegative && isNorthDirected ) || ( isNegative && ! isNorthDirected )
236253 : isNegative
237- ) ,
238- tr : isEnding && ( this . isVertical ( )
254+ ) ) ,
255+ tr : allCornersRounded || ( isEnding && ( this . isVertical ( )
239256 ? ( ! isNegative && isNorthDirected ) || ( isNegative && ! isNorthDirected )
240257 : ! isNegative
241- ) ,
242- br : isEnding && ( this . isVertical ( )
258+ ) ) ,
259+ br : allCornersRounded || ( isEnding && ( this . isVertical ( )
243260 ? ( isNegative && isNorthDirected ) || ( ! isNegative && ! isNorthDirected )
244261 : ! isNegative
245- ) ,
246- bl : isEnding && ( this . isVertical ( )
262+ ) ) ,
263+ bl : allCornersRounded || ( isEnding && ( this . isVertical ( )
247264 ? ( isNegative && isNorthDirected ) || ( ! isNegative && ! isNorthDirected )
248265 : isNegative
249- ) ,
266+ ) ) ,
250267 r : cornerRadiusClamped ,
251268 } )
252269 }
0 commit comments