@@ -587,40 +587,34 @@ modeBarButtons.hoverClosestGeo = {
587587} ;
588588
589589function handleGeo ( gd , ev ) {
590- var button = ev . currentTarget ;
591- var attr = button . getAttribute ( 'data-attr' ) ;
592- var val = button . getAttribute ( 'data-val' ) || true ;
593- var fullLayout = gd . _fullLayout ;
594- var geoIds = fullLayout . _subplots . geo || [ ] ;
590+ const button = ev . currentTarget ;
591+ const attr = button . getAttribute ( 'data-attr' ) ;
592+ const val = button . getAttribute ( 'data-val' ) || true ;
593+ const fullLayout = gd . _fullLayout ;
594+ const geoIds = fullLayout . _subplots . geo || [ ] ;
595595
596- for ( var i = 0 ; i < geoIds . length ; i ++ ) {
597- var id = geoIds [ i ] ;
598- var geoLayout = fullLayout [ id ] ;
596+ for ( const id of geoIds ) {
597+ const geoLayout = fullLayout [ id ] ;
599598
600599 if ( attr === 'zoom' ) {
601- var scale = geoLayout . projection . scale ;
602- var minscale = geoLayout . projection . minscale ;
603- var maxscale = geoLayout . projection . maxscale === - 1 ? Infinity : geoLayout . projection . maxscale ;
604- var max = Math . max ( minscale , maxscale ) ;
605- var min = Math . min ( minscale , maxscale ) ;
606- var newScale = val === 'in' ? 2 * scale : 0.5 * scale ;
607-
608- // make sure the scale is within the min/max bounds
609- if ( newScale > max ) {
610- newScale = max ;
611- } else if ( newScale < min ) {
612- newScale = min ;
613- }
600+ const { minscale, scale } = geoLayout . projection ;
601+ const maxscale = geoLayout . projection . maxscale ?? Infinity ;
602+ // swap if user supplied min > max so clamping is well-defined
603+ const min = Math . min ( minscale , maxscale ) ;
604+ const max = Math . max ( minscale , maxscale ) ;
605+ let newScale = val === 'in' ? 2 * scale : 0.5 * scale ;
606+
607+ // clamp to [min, max]
608+ if ( newScale > max ) newScale = max ;
609+ else if ( newScale < min ) newScale = min ;
614610
615611 if ( newScale !== scale ) {
616612 Registry . call ( '_guiRelayout' , gd , id + '.projection.scale' , newScale ) ;
617613 }
618614 }
619615 }
620616
621- if ( attr === 'reset' ) {
622- resetView ( gd , 'geo' ) ;
623- }
617+ if ( attr === 'reset' ) resetView ( gd , 'geo' ) ;
624618}
625619
626620modeBarButtons . hoverClosestPie = {
0 commit comments