{
const updates = [];
const chart = Plot.plot({
width,
height,
projection,
marks: [
Plot.sphere({ fill: "white", render }),
Plot.geo([land50, land110], {
fill: "currentColor",
render: renderAlternative
}),
Plot.sphere({ render }),
Plot.line([[0, 0], [10, 10]], { stroke: "red", curve: "auto", render }),
Plot.graticule({render}),
Plot.frame({ stroke: "none", pointerEvents: "all" })
]
});
function tester(projection, X, Y) {
let visible;
const stream = projection.stream({point() { visible = true; }});
return (i) => ((visible = false), stream.point(X[i], Y[i]), visible);
}
function render(i, s, v, d, c, n) {
const index = d3.range((v.geometry??v.x).length);
let g = n(index, s, v, d, c);
if (v.x && v.y &&!this.curve) {
const X = v.channels.x.value;
const Y = v.channels.y.value;
updates.push(() => {
i = index.filter(tester(projection, X, Y));
for (const j of i) [v.x[j], v.y[j]] = projection([X[j], Y[j]]);
g.replaceWith((g = n(i, s, v, d, c)));
});
} else {
updates.push(() => g.replaceWith((g = n(i, s, v, d, c))));
}
return g;
}
function renderAlternative(i, s, v, d, c, n) {
let g = n([0], s, v, d, c);
updates.push((active) => g.replaceWith((g = n([active], s, v, d, c))));
return g;
}
return d3
.select(chart)
.call(
zoom(projection)
.on("zoom.render", () => updates.forEach((update) => update(1)))
.on("end.render", () => updates.forEach((update) => update(0)))
)
.node();
}