pole = function ({ geometry = (d) => d, minRadius = 0, poleRatio = 1, ...options } = {}) {
const precision = 1;
return Plot.initializer(
options,
(data, facets, channels, scales, dimensions, { projection }) => {
const G = Plot.valueof(data, geometry).map((d) =>
d3.geoProject(d, projection)
);
const n = G.length;
const X = new Float64Array(n).fill(NaN);
const Y = new Float64Array(n);
const R = new Float64Array(n);
for (let i = 0; i < n; ++i) {
const { type, coordinates } =
G[i].type === "Feature" ? G[i].geometry : G[i];
const c =
type === "MultiPolygon"
? d3.greatest(
coordinates.map((polygon) => polylabelratio(polygon, precision, poleRatio)),
(c) => c.distance
)
: type === "Polygon"
? polylabelratio(coordinates, precision, poleRatio)
: [null, null];
if ((R[i] = c.distance) > minRadius) {
[X[i], Y[i]] = c;
}
}
return {
data,
facets,
channels: {
x: { value: X, source: null },
y: { value: Y, source: null },
r: { value: R, source: null }
}
};
}
);
}