@@ -305,6 +305,7 @@ export class Sankey<
305305 const transform = event . transform
306306 const sourceEvent = event . sourceEvent as WheelEvent | MouseEvent | TouchEvent | undefined
307307 const zoomMode = config . zoomMode || SankeyZoomMode . XY
308+ const bleed = this . _bleedCached
308309
309310 // Zoom pivots
310311 const minX = min ( nodes , d => d . x0 ) ?? 0
@@ -330,7 +331,6 @@ export class Sankey<
330331 this . _zoomScale = [ hNext , vNext ]
331332
332333 // Pointer-centric compensation: keep the point under cursor fixed
333- const bleed = this . _bleedCached
334334 const pos = sourceEvent ? pointer ( sourceEvent , this . g . node ( ) ) : [ this . _width / 2 , this . _height / 2 ]
335335
336336 // Invert current mapping to get layout coordinates under pointer
@@ -354,6 +354,16 @@ export class Sankey<
354354 if ( zoomMode !== SankeyZoomMode . X ) this . _pan [ 1 ] += dy
355355 }
356356
357+ // Horizontal Pan Constraint
358+ const maxX = max ( nodes , d => d . x1 ) ?? 0
359+ const viewportWidth = this . getWidth ( ) - bleed . left - bleed . right
360+ this . _pan [ 0 ] = clamp ( this . _pan [ 0 ] , viewportWidth - maxX , minX )
361+
362+ // Vertical Pan Constraint
363+ const maxY = max ( nodes , d => d . y1 ) ?? 0
364+ const viewportHeight = this . getHeight ( ) - bleed . top - bleed . bottom
365+ this . _pan [ 1 ] = clamp ( this . _pan [ 1 ] , viewportHeight - maxY , minY )
366+
357367 // Update last zoom state
358368 this . _prevZoomTransform . k = transform . k
359369 this . _prevZoomTransform . x = transform . x
0 commit comments