Skip to content

Commit 9a1140f

Browse files
committed
Fix options types and zoomToArea() for non-standard aspect ratios
1 parent 4da1015 commit 9a1140f

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.9.5
2+
3+
- Fix: option types of `zoomToLocation`, `zoomToOrigin`, `zoomToArea`
4+
- Fix: ensure `zoomToArea` works in cases where `aspectRatio` is not equal to `1`
5+
16
## 1.9.4
27

38
- Fix: `scatterplot.draw(newPoints, { preventFilterReset })` should preserves the filter ([Jupyter-Scatter#134](https://github.com/flekschas/jupyter-scatter/issues/134))

src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/types.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ export interface ScatterplotMethodOptions {
197197
transitionDuration: number;
198198
transitionEasing: (t: number) => number;
199199
}>;
200+
zoomToArea: Partial<{
201+
transition: boolean;
202+
transitionDuration: number;
203+
transitionEasing: (t: number) => number;
204+
}>;
205+
zoomToLocation: Partial<{
206+
transition: boolean;
207+
transitionDuration: number;
208+
transitionEasing: (t: number) => number;
209+
}>;
200210
}
201211

202212
export type Events = import('pub-sub-es').Event<

0 commit comments

Comments
 (0)