Published
Edited
Dec 2, 2019
1 star
Insert cell
Insert cell
chart = {
const width = 960;
const height = 600;
const center = d3.geoCentroid(hex_data);
const scale = 7000;
const offset = [width/2, height/2];
const projection = d3.geoEquirectangular().scale(scale).center(center)
.translate(offset);
const path = d3.geoPath().projection(projection);
const colorScale = d3.scaleSequential()
.domain([d3.max(hex_data.features, d => d.properties.total), d3.min(hex_data.features, d => d.properties.total)])
.interpolator(d3.interpolateInferno);
const svg = d3.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto");
svg.append("g")
.selectAll("path")
.data(hex_data.features)
.enter().append("path")
.attr("d", path)
.attr("stroke", "white")
.attr("stroke-width", "1.5")
.attr("fill", function(d){return colorScale(+d.properties.total)});
console.log(d3.max(hex_data.features, d => d.properties.total));
return svg.node();
}
Insert cell
hex_data = fetch("https://raw.githubusercontent.com/mschmidty/datasets/master/geo/co_precip_hex.geojson")
.then(function(response){
return response.json()
})
Insert cell
d3 = require("d3@5")
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