Skip to content

Commit 8a081b1

Browse files
committed
Don't consider negative domain as valid in log/sqrt scale
1 parent d517714 commit 8a081b1

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

packages/app/src/providers/mock/mock-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export function makeMockFile(): GroupWithChildren {
137137
valueId: 'twoD',
138138
attributes: [scalar('_FillValue', 400)],
139139
}),
140+
array('twoD_neg'),
140141
array('twoD_bigint'),
141142
array('twoD_cplx'),
142143
array('twoD_compound', {

packages/lib/src/vis/shared/ViewportCenterer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ function ViewportCenterer() {
1717
});
1818

1919
useEffect(() => {
20+
// On resize, move camera to the latest saved viewport center coordinates
2021
if (viewportCenter.current) {
21-
// On resize, move camera to the latest saved viewport center coordinates
22-
moveCameraTo(dataToWorld(viewportCenter.current));
22+
const newPos = dataToWorld(viewportCenter.current);
23+
24+
// Ignore previous center if no longer valid with current scale
25+
if (Number.isFinite(newPos.x) && Number.isFinite(newPos.y)) {
26+
moveCameraTo(newPos);
27+
}
2328
}
2429
}, [viewportCenter, moveCameraTo, dataToWorld, camera]);
2530

packages/shared/src/mock-values.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const mockValues = {
174174
[20, 41],
175175
);
176176
},
177+
twoD_neg: () => ndarray(range(-10, 0), [1, 10]),
177178
threeD,
178179
threeD_cplx: () =>
179180
ndarray(

packages/shared/src/vis-utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,17 @@ export function getValidDomainForScale(
167167
}
168168

169169
const { min, max, positiveMin, strictPositiveMin } = bounds;
170-
if (scaleType === ScaleType.Log && min * max <= 0) {
171-
// Clamp domain minimum to first positive value,
172-
// or return `undefined` if domain is not unsupported: `[-x, 0]`
170+
171+
if (scaleType === ScaleType.Log && min <= 0) {
173172
return Number.isFinite(strictPositiveMin)
174-
? [strictPositiveMin, max]
175-
: undefined;
173+
? [strictPositiveMin, max] // clamp min to first strictly positive value, if any
174+
: undefined; // can't make valid domain - e.g. [-5, -2], [-10, 0]
176175
}
177176

178-
if (scaleType === ScaleType.Sqrt && min * max < 0) {
179-
return [positiveMin, max];
177+
if (scaleType === ScaleType.Sqrt && min < 0) {
178+
return Number.isFinite(positiveMin)
179+
? [positiveMin, max] // clamp min to first positive value, if any
180+
: undefined; // can't make valid domain - e.g. [-5, -2]
180181
}
181182

182183
return [min, max];

0 commit comments

Comments
 (0)