@@ -2406,8 +2406,8 @@ const createScatterplot = (
24062406
24072407 /**
24082408 * Zoom to an area specified as a rectangle
2409- * @param {import('./types').Rect } rect - The rectangle to zoom to
2410- * @param {import('./types').ScatterplotMethodOptions['draw '] } options
2409+ * @param {import('./types').Rect } rect - The rectangle to zoom to in normalized device coordinates
2410+ * @param {import('./types').ScatterplotMethodOptions['zoomToArea '] } options
24112411 * @returns {Promise<void> }
24122412 */
24132413 const zoomToArea = ( rect , options = { } ) =>
@@ -2419,12 +2419,14 @@ const createScatterplot = (
24192419 // we would have to do `Math.atan(1 / camera.view[5])`
24202420 const vFOV = 2 * Math . atan ( 1 ) ;
24212421
2422+ const aspectRatio = viewAspectRatio / dataAspectRatio ;
2423+
24222424 const distance =
2423- rect . height * viewAspectRatio > rect . width
2425+ rect . height * aspectRatio >= rect . width
24242426 ? // Distance is based on the height of the bounding box
24252427 rect . height / 2 / Math . tan ( vFOV / 2 )
24262428 : // Distance is based on the width of the bounding box
2427- rect . width / 2 / Math . tan ( ( vFOV * viewAspectRatio ) / 2 ) ;
2429+ rect . width / 2 / Math . tan ( vFOV / 2 ) / aspectRatio ;
24282430
24292431 if ( options . transition ) {
24302432 camera . config ( { isFixed : true } ) ;
@@ -2474,9 +2476,9 @@ const createScatterplot = (
24742476
24752477 /**
24762478 * Zoom to a location specified in normalized devide coordinates.
2477- * @param {number[] } target - The camera target
2479+ * @param {number[] } target - The camera target given in normalized device coordinates
24782480 * @param {number } distance - The camera distance
2479- * @param {import('./types').ScatterplotMethodOptions['draw '] } options
2481+ * @param {import('./types').ScatterplotMethodOptions['zoomToLocation '] } options
24802482 * @returns {Promise<void> }
24812483 */
24822484 const zoomToLocation = ( target , distance , options = { } ) =>
@@ -2505,7 +2507,7 @@ const createScatterplot = (
25052507
25062508 /**
25072509 * Zoom to the origin
2508- * @param {import('./types').ScatterplotMethodOptions['draw '] } options
2510+ * @param {import('./types').ScatterplotMethodOptions['zoomToLocation '] } options
25092511 * @returns {Promise<void> }
25102512 */
25112513 const zoomToOrigin = ( options = { } ) => zoomToLocation ( [ 0 , 0 ] , 1 , options ) ;
0 commit comments