Published
Edited
Sep 1, 2020
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chartp03
Insert cell
hex = hexbytime.get(time2)
Insert cell
import {hexdata, hexbytime, california, countyShapes} from "@enjalot/purpleair-historical-data"
Insert cell
// Choose a couple counties that define the extent I care about
countyExtent = ({
type: "FeatureCollection",
// features: countyShapes.features.filter(d => (
// d.properties.name == "Tehama" ||
// d.properties.name == "San Benito") && d.id.slice(0,2) == "06")
features: countyShapes.features.filter(d => (
d.properties.name == "Marin" ||
d.properties.name == "Alameda") && d.id.slice(0,2) == "06")
// features: countyShapes.features.filter(d => (
// d.properties.name == "Marin" ||
// d.properties.name == "Santa Clara") && d.id.slice(0,2) == "06")

})
Insert cell
projection.scale()
Insert cell
originalScale = 25355.18980109889
Insert cell
scaleRatio = projection.scale() / originalScale
Insert cell
projection = d3.geoAlbersUsa()
.fitSize([width, height], countyExtent)
Insert cell
pixelRadius = 10 * scaleRatio
Insert cell
hexbin = d3.hexbin().extent([[0, 0], [width, height]]).radius(pixelRadius)
Insert cell
dayExtent = d3.extent(hexdata, d => d.day)
Insert cell
days =
d3.timeHour
.range(new Date(dayExtent[0]*1000), new Date(dayExtent[1]*1000))
.map(d => +d/1000)

Insert cell
height = 500
Insert cell
colorPM1 = d3.scaleLinear()
.domain([0,50, 100, 150, 200, 250])
.range(["green", "yellow", "orange", "red", "maroon", "maroon"])
Insert cell
opacityPM1 = d3.scaleLinear()
.domain([0,50, 100, 150, 200, 250])
.range([0.1, 0.5, 0.75, 0.9, 0.9, 0.9])
Insert cell
colorP03 = d3.scaleLinear()
.domain([1,1000, 5000, 10000, 20000, 25000])
// .range(["green", "yellow", "orange", "red", "maroon", "maroon"])
.range(["#eee", "#ccc", "#aaa", "#888", "#666", "#444", "#111"])
Insert cell
opacityP03 = d3.scaleLinear()
.domain([1,1000, 5000, 10000, 20000, 25000])
.range([0.1, 0.5, 0.75, 0.9, 0.9, 0.9])
Insert cell
timeFormat = d3.timeFormat("%Y-%m-%d %H:%M")
Insert cell
import {Scrubber} from "@mbostock/scrubber"
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
d3 = require("d3@6.0.0-rc.3", "d3-hexbin@0.2")
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