Skip to content

Commit 96dc40a

Browse files
committed
fix: ensure view aspect ratio is updated before the scales on resize
1 parent 0865120 commit 96dc40a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.14.1
2+
3+
- Fix: ensure view aspect ratio is updated before the scales are updated on resize
4+
15
## 1.14.0
26

37
- Feat: expose a flag indicating a view change for events `draw`, `drawing`, and `view`

src/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,12 +1368,14 @@ const createScatterplot = (
13681368
}
13691369
};
13701370

1371-
const setCurrentHeight = (newCurrentHeight) => {
1371+
const setCurrentHeight = (newCurrentHeight, skipScaleUpdates) => {
13721372
currentHeight = Math.max(1, newCurrentHeight);
13731373
canvas.height = Math.floor(currentHeight * window.devicePixelRatio);
13741374
if (yScale) {
13751375
yScale.range([currentHeight, 0]);
1376-
updateScales();
1376+
if (!skipScaleUpdates) {
1377+
updateScales();
1378+
}
13771379
}
13781380
};
13791381

@@ -1448,12 +1450,14 @@ const createScatterplot = (
14481450
pointOutlineWidth = +newPointOutlineWidth;
14491451
};
14501452

1451-
const setCurrentWidth = (newCurrentWidth) => {
1453+
const setCurrentWidth = (newCurrentWidth, skipScaleUpdates) => {
14521454
currentWidth = Math.max(1, newCurrentWidth);
14531455
canvas.width = Math.floor(currentWidth * window.devicePixelRatio);
14541456
if (xScale) {
14551457
xScale.range([0, currentWidth]);
1456-
updateScales();
1458+
if (!skipScaleUpdates) {
1459+
updateScales();
1460+
}
14571461
}
14581462
};
14591463

@@ -4195,24 +4199,25 @@ const createScatterplot = (
41954199
};
41964200

41974201
const resizeHandler = () => {
4198-
camera.refresh();
41994202
const autoWidth = width === AUTO;
42004203
const autoHeight = height === AUTO;
42014204
if (autoWidth || autoHeight) {
42024205
const { width: newWidth, height: newHeight } =
42034206
canvas.getBoundingClientRect();
42044207

42054208
if (autoWidth) {
4206-
setCurrentWidth(newWidth);
4209+
setCurrentWidth(newWidth, true);
42074210
}
42084211

42094212
if (autoHeight) {
4210-
setCurrentHeight(newHeight);
4213+
setCurrentHeight(newHeight, true);
42114214
}
42124215

42134216
updateViewAspectRatio();
4217+
updateScales();
42144218
draw = true;
42154219
}
4220+
camera.refresh();
42164221
};
42174222

42184223
/**

0 commit comments

Comments
 (0)