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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more