Published
Edited
Dec 3, 2019
1 fork
3 stars
Insert cell
Insert cell
viewof canvas = {
const W = width, H = width * 2 / 3;
const canvas = DOM.element("canvas")
canvas.width = W * devicePixelRatio;
canvas.height = H * devicePixelRatio;
canvas.style.width = W + 'px';
canvas.style.height = H + 'px';
canvas.value = canvas.getContext('2d')
canvas.value.scale(devicePixelRatio, devicePixelRatio);
return canvas
}
Insert cell
draw = {
canvas.strokeStyle = '#333'
canvas.beginPath()
path(geojson)
canvas.stroke()
}
Insert cell
// reflectY reverses the y direction so that the data doesn't appear to be upside down
projection = d3.geoIdentity()
.reflectY(true)
.fitSize([width, width * 2/3], geojson)
Insert cell
geojson = topojson.mesh(counties, counties.objects.census_blocks_2000_bay_area_2227)
Insert cell
path = d3.geoPath(projection).context(canvas)
Insert cell
counties = d3.json("https://gist.githubusercontent.com/clhenrick/217705080810957e773136e9208d403e/raw/b428a62adbf0b81d29e821a4c881aa46c03aea6c/counties.json")
Insert cell
topojson = require("topojson")
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