Public
Edited
Feb 28, 2023
1 fork
1 star
Insert cell
Insert cell
heatmap = Plot.plot({
projection: {
type: "mercator",
domain: rewind(hexes)
},
marks: [
Plot.geo(rewind(hexes), {
fill: (d) => d3.interpolateBlues(d.properties.value),
stroke: "#aaa",
strokeWidth: 0.5
}),
Plot.geo(points, {
fill: (d) => (d.properties.selected ? "#FF8319" : "#666"),
r: 1.75
})
],
height: 400,
width: 800
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
points = {
// generate random points
let pts = turf.randomPoint(pointCount, { bbox: [2.27, 48.86, 2.4, 48.9] });
// flag 20% as "selected"
pts.features.forEach(
(f, i) =>
(f.properties = {
selected: i <= pointCount * selectPercent ? true : false
})
);
return pts;
}
Insert cell
Insert cell
selectedLayer = {
// assign h3id to each point, reduce to counts by id
const allhex = points.features
.filter((d) => d.properties.selected)
.map((d) => {
const [lng, lat] = d.geometry.coordinates;
return h3.latLngToCell(lat, lng, h3res);
})
.reduce((layer, hex) => {
if (layer[hex]) {
layer[hex] += 1;
} else {
layer[hex] = 1;
}
return layer;
}, {});

const max = d3.max(Object.values(allhex));
const min = d3.min(Object.values(allhex));

// normalize counts to 0-1, return the object
return Object.fromEntries(
Object.entries(allhex).map(([hex, value]) => [
hex,
(value - min) / (max - min)
])
);
}
Insert cell
Insert cell
hexes = geojson2h3.h3SetToFeatureCollection(
Object.keys(selectedLayer),
(hex) => ({
value: selectedLayer[hex]
})
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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