Public
Edited
Apr 3, 2023
3 forks
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hex = ({ x, y }) => ({
type: "Polygon",
coordinates: [
Array.from({ length: 7 }, (_, i) => {
const a = (Math.PI * i) / 3;
const r = Math.sqrt(3) / 3;
return [
+(x + Math.sin(a) * r).toFixed(10), // rounding to avoid floating point error & vertex mismatch
+(y + Math.cos(a) * r).toFixed(10)
];
})
]
})
Insert cell
topo = topojson.topology(
Object.fromEntries(
d3.rollup(
data,
(v) => ({
type: "GeometryCollection",
geometries: v.map(hex)
}),
(d) => d.color
)
)
)
Insert cell
merged = Object.entries(topo.objects).map(([color, e]) => [
color,
topojson.merge(topo, e.geometries)
])
Insert cell
topojson = require("topojson-client@3", "topojson-server@3")
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