Published
Edited
Sep 18, 2020
4 forks
14 stars
Insert cell
Insert cell
Insert cell
import { hexdata } from '@enjalot/purpleair-historical-data'
Insert cell
hexdata
Insert cell
groupedData = d3.group(hexdata, d => d.day)
Insert cell
times = Array.from(groupedData.keys())
Insert cell
timeData = groupedData.get(currentTime)
Insert cell
import { Scrubber } from '@mbostock/scrubber'
Insert cell
Insert cell
Insert cell
Insert cell
mapSVG = svg`<svg width=${width} height=${height}></svg>`
Insert cell
Insert cell
projection = d3.geoAlbersUsa().fitSize([width, height], california[0]) // magically fits map geography to width/height!
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
path = d3.geoPath(projection)
Insert cell
colorPM1 = d3.scaleLinear()
.domain([0,50, 100, 150, 200, 250])
.range(["green", "yellow", "orange", "red", "maroon", "maroon"])
Insert cell
function render(svg) {
let svgSelection = d3.select(svg);
svgSelection.selectAll('path')
.data(california)
.join('path')
.attr('d', f => path(f))
.attr('stroke', 'grey')
.attr('fill', 'none');
svgSelection.selectAll('circle')
.data(timeData)
.join('circle')
.attr('cx', d => projection([d.lng, d.lat])[0])
.attr('cy', d => projection([d.lng, d.lat])[1])
.attr('fill', d => colorPM1(d.pm1))
.attr('r', 3);
return svgSelection;
}
Insert cell
render(mapSVG)
Insert cell
height = 400
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