Published
Edited
Mar 11, 2019
3 stars
Insert cell
Insert cell
Insert cell
map = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
context.beginPath(),
path(graticule),
(context.strokeStyle = "#ccc"),
context.stroke();
context.beginPath(), path(land), (context.fillStyle = "#000"), context.fill();
context.beginPath(),
path({ type: "Polygon", coordinates: [days.map(d => sunAtTime(d))] }),
(context.strokeStyle = "#f00"),
context.stroke();
context.beginPath(),
path({ type: "Point", coordinates: sun }),
(context.fillStyle = "#f00"),
context.fill();
context.beginPath(),
path(sphere),
(context.strokeStyle = "#000"),
context.stroke();
return context.canvas;
}
Insert cell
Insert cell
height = width
Insert cell
Insert cell
projection = d3
.geoOrthographic()
.rotate([-sun[0], -sun[1]])
//.rotate([-sunAtTime(days[110])[0], -sunAtTime(days[110])[1]])
.fitExtent([[1, 1], [width - 1, height - 1]], sphere)
.precision(0.1)
Insert cell
timeOfYear = {
let time = new Date(2019, 0, 1, 12);
let i = 0;
while (true) {
yield Promises.delay(
0,
new Date(time.getTime() + (++i % 365) * 24 * 60 * 60 * 1000)
);
}
}
Insert cell
sun = sunAtTime(timeOfYear)
Insert cell
sunAtTime = function(timeOfYear) {
const time = new Date(timeOfYear);
const day = new Date(+time).setUTCHours(0, 0, 0, 0);
const t = solar.century(time);
const x = ((day - time) / 864e5) * 360 - 180 - solar.equationOfTime(t) / 4;
const y = solar.declination(t);
return [x % 360, y];
}
Insert cell
sphere = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
world = fetch("https://cdn.jsdelivr.net/npm/world-atlas@1/world/50m.json").then(response => response.json())
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3-geo@1")
Insert cell
solar = require("solar-calculator@0.3/dist/solar-calculator.min.js")
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