Public
Edited
Jan 1, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
height: y.range()[1],
width,
marginLeft: 100,
x: {
grid: true
},
y: {
reverse: true,
type: "time"
},
marks: [
Plot.ruleY(data, { x1: 4, x2: 22, y: (d) => d.date, stroke: "#b0bec5" }),
Plot.ruleY(data, {
x1: (d) => d.sunriseHour,
x2: (d) => d.sunsetHour,
y: (d) => d.date,
stroke: "#ffc107",
strokeWidth: 2
})
]
})
Insert cell
formatDate = d3.timeFormat("%Y-%m-%d")
Insert cell
data = days.map(dateInfo)
Insert cell
x = d3.scaleLinear().domain([4, 22]).range([0, 400])
Insert cell
y = d3
.scaleTime()
.domain([dateStart, dateEnd])
.range([0, 365 * 4])
Insert cell
lat = 49.2065
Insert cell
lon = -122.9624
Insert cell
function dateInfo(date) {
const sun = suncalc.getTimes(date, lat, lon);
return {
date,
sunrise: sun.sunrise,
sunset: sun.sunset,
sunsetHour: dateToHours(sun.sunset),
sunriseHour: dateToHours(sun.sunrise)
};
}
Insert cell
dateStart = startOfYear(date)
Insert cell
dateEnd = endOfYear(date)
Insert cell
Insert cell
Insert cell
startOfYear = (date) => d3.timeYear.floor(date)
Insert cell
endOfYear = (date) => d3.timeYear.ceil(date)
Insert cell
dateToHours = (d) => d.getHours() + d.getMinutes() / 60 + d.getSeconds() / 3600
Insert cell
suncalc = require("suncalc")
Insert cell
days.map(dateInfo)
Insert cell
suncalc.getTimes(days[4], lat, lon)
Insert cell
Insert cell
import { getUserCoordinates } from "@pnavarrc/get-user-coordinates"
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