@@ -1345,8 +1345,8 @@ function minZoom() {
13451345 let parentElement = svgElement . parentNode ;
13461346 return Math . min (
13471347 1 ,
1348- parentElement . clientWidth / ( maxXCoordinate + 10 ) ,
1349- parentElement . clientHeight / ( maxYCoordinate + 10 )
1348+ parentElement . clientWidth / maxXCoordinate ,
1349+ parentElement . clientHeight / ( maxYCoordinate + RAIL_SPACE )
13501350 ) ;
13511351}
13521352
@@ -1378,20 +1378,33 @@ function alignSVG() {
13781378 function configureZoomBounds ( ) {
13791379 // Configure panning and zooming, given the SVG parent's size on the page.
13801380
1381- svg . attr ( "height" , maxYCoordinate - minYCoordinate + RAIL_SPACE * 2 ) ;
1381+ svg . attr ( "height" , parentElement . clientHeight ) ;
13821382 svg . attr ( "width" , parentElement . clientWidth ) ;
13831383
1384+ let minScaleFactor = minZoom ( ) ;
1385+
13841386 // We need to set an extent here because auto-determination of the region
13851387 // to zoom breaks on the React testing jsdom
1388+ //
1389+ // We also need the translate extent to always be larger than the zoom
1390+ // extent. See <https://stackoverflow.com/a/53784776>.
1391+ //
1392+ // Really we would like to say that, given the zoom level, some part of the
1393+ // drawing should always be on the screen. But that requires redefining the
1394+ // translate extent (the area that d3 stops us from seeing out of) to be
1395+ // smaller when zoomed in and larger when zoomed out. We can't let the
1396+ // translate extent ever be smaller than the viewport at any zoom level, or
1397+ // d3 will lock it to the center along that axis but content will go out of
1398+ // bounds on the SVG image download.
13861399 zoom
13871400 . extent ( [
13881401 [ 0 , 0 ] ,
13891402 [ parentElement . clientWidth , parentElement . clientHeight ] ,
13901403 ] )
1391- . scaleExtent ( [ minZoom ( ) , 8 ] )
1404+ . scaleExtent ( [ minScaleFactor , 8 ] )
13921405 . translateExtent ( [
13931406 [ 0 , minYCoordinate - RAIL_SPACE ] ,
1394- [ maxXCoordinate , maxYCoordinate + RAIL_SPACE ] ,
1407+ [ Math . max ( maxXCoordinate , parentElement . clientWidth / minScaleFactor ) , Math . max ( maxYCoordinate , parentElement . clientHeight / minScaleFactor ) ] ,
13951408 ] ) ;
13961409 }
13971410
0 commit comments