Published
Edited
Sep 27, 2022
Fork of Time Zones
Insert cell
Insert cell
Insert cell
map = html`<svg viewBox="0 2 ${width} ${height - 4}" stroke-linejoin="round">
${zones.map(f => svg`
<path d="${path(f)}" fill="${color(f.properties.zone)}">
<title>${f.properties.places}
${f.properties.time_zone}</title>
</path>
`)}
<g pointer-events="none">
<path d="${path(mesh)}" fill="none" stroke="#000" />
<path d="${path(land)}" fill-opacity="0.1" />
<path d="${path(graticule)}" stroke="#000" stroke-opacity="0.15" fill="none" />
</g>
</svg>`
Insert cell
color = d3.scaleSequential(d3.extent(zones, f => f.properties.zone), d3.interpolateRdBu)
Insert cell
projection = d3.geoMiller()
Insert cell
path = d3.geoPath(projection)
Insert cell
width = 975
Insert cell
height = {
const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, outline)).bounds(outline);
const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
return dy;
}
Insert cell
outline = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule().stepMinor([15, 10])()
Insert cell
timezones = FileAttachment("timezones.json").json()
Insert cell
zones = topojson.feature(timezones, timezones.objects.timezones).features
Insert cell
mesh = topojson.mesh(timezones, timezones.objects.timezones)
Insert cell
land = FileAttachment("land-50m.json").json().then(topology => topojson.feature(topology, topology.objects.land))
Insert cell
import {ramp} from "@mbostock/color-ramp"
Insert cell
d3 = require("d3@6", "d3-geo-projection@2")
Insert cell
topojson = require("topojson-client@3")
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