Skip to content

Commit fc75219

Browse files
committed
more robustness for projections when coordinates are passed as strings instead of numbers
1 parent 6a44fa5 commit fc75219

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/projection.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ export function Projection(
7777
const [[x0, y0], [x1, y1]] = geoPath(projection).bounds(domain);
7878
const k = Math.min(dx / (x1 - x0), dy / (y1 - y0));
7979
if (k > 0) {
80-
tx -= (k * (x0 + x1) - dx) / 2;
81-
ty -= (k * (y0 + y1) - dy) / 2;
82-
const {stream: affine} = geoTransform({
83-
point(x, y) {
84-
this.stream.point(x * k + tx, y * k + ty);
85-
}
86-
});
87-
return {stream: (s) => projection.stream(affine(s))};
80+
const cx = (k * (x0 + x1) - dx) / 2;
81+
const cy = (k * (y0 + y1) - dy) / 2;
82+
if (isFinite(cx + cy)) {
83+
tx -= cx;
84+
ty -= cy;
85+
const {stream: affine} = geoTransform({
86+
point(x, y) {
87+
this.stream.point(x * k + tx, y * k + ty);
88+
}
89+
});
90+
return {stream: (s) => projection.stream(affine(s))};
91+
}
8892
}
8993
warn(`The projection could not be fit to the specified domain. Using the default scale.`);
9094
}

0 commit comments

Comments
 (0)