Skip to content

Commit f63a8eb

Browse files
committed
projection.stream for x and y
1 parent 587420d commit f63a8eb

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
@@ -18,15 +18,14 @@ import {isObject} from "./options.js";
1818
// - conic equal area?
1919
// - conic equidistant?
2020
// - transverse mercator?
21-
// - allow configuration of rotation?
2221
// - allow configuration of parallels?
2322
// - camelCase or hypen-separated?
2423
// - more named projections?
2524
// - apply x and y scales as linear projection by default?
2625
// - disallow non-default projection if x and y scales exist?
2726
export function maybeProjection(projection, dimensions) {
2827
if (projection == null) return;
29-
if (typeof projection === "function") return projection;
28+
if (typeof projection.stream === "function") return projection;
3029
const {width, height} = dimensions;
3130
let rotate, scale, precision;
3231
if (isObject(projection)) {
@@ -74,11 +73,16 @@ export function maybeProjection(projection, dimensions) {
7473
export function applyProjection(values, projection) {
7574
const {x, y} = values;
7675
const n = x.length;
77-
const X = (values.x = new Float64Array(n));
78-
const Y = (values.y = new Float64Array(n));
79-
for (let i = 0; i < n; ++i) {
80-
const p = projection([x[i], y[i]]);
81-
if (p) (X[i] = p[0]), (Y[i] = p[1]);
82-
else X[i] = Y[i] = NaN;
76+
const X = (values.x = new Float64Array(n).fill(NaN));
77+
const Y = (values.y = new Float64Array(n).fill(NaN));
78+
let i;
79+
const stream = projection.stream({
80+
point(x, y) {
81+
X[i] = x;
82+
Y[i] = y;
83+
}
84+
});
85+
for (i = 0; i < n; ++i) {
86+
stream.point(x[i], y[i]);
8387
}
8488
}

0 commit comments

Comments
 (0)