Public
Edited
Oct 26, 2023
18 forks
48 stars
Insert cell
Insert cell
visiblePoints
Insert cell
function tester(projection) {
let visible;
const stream = projection.stream({point() { visible = true; }});
return ([x, y]) => (visible = false, stream.point(x, y), visible);
}
Insert cell
viewof visiblePoints = {
const context = DOM.context2d(width, height);

const projection = d3.geoOrthographic()
.fitExtent([[-1, -1], [width + 1, height + 1]], sphere)
.clipExtent([[-1, -1], [width + 1, height + 1]])
.rotate([0, -30]);

const path = d3.geoPath(projection, context)
.pointRadius(1.5);

function render() {
context.clearRect(0, 0, width, height);

context.beginPath();
path(graticule);
context.lineWidth = 0.5;
context.strokeStyle = "#aaa";
context.stroke();

context.beginPath();
path(land);
context.fillStyle = "#ddd";
context.fill();

context.beginPath();
path(sphere);
context.lineWidth = 1.5;
context.strokeStyle = "#000";
context.stroke();

context.beginPath();
path({type: "MultiPoint", coordinates: points});
context.fillStyle = "#000";
context.fill();

context.canvas.value = points.filter(tester(projection));
context.canvas.dispatchEvent(new CustomEvent("input"));
}

return d3.select(context.canvas)
.call(zoom(projection).on("zoom.render", render))
.call(render)
.node();
}
Insert cell
height = width
Insert cell
sphere = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
points = (await FileAttachment("airports.csv").csv()).map(({longitude, latitude}) => [+longitude, +latitude])
Insert cell
land = FileAttachment("land-110m.json").json().then(world => topojson.feature(world, world.objects.land))
Insert cell
import {zoom} from "@d3/versor-zooming"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more