Public
Edited
Dec 23
Insert cell
Insert cell
{
// Parameters
const cols = 10; // Number of columns (axial q)
const rows = 10; // Number of rows (axial r)
const radius = 20; // Radius of hexagons
let bins = [];

// Generate axial coordinates
for (let q = 0; q < cols; q++) {
for (let r = 0; r < rows; r++) {
bins.push([q + 1, r + 1]);
}
}

bins = [
[4, 1],
[5, 2],
[5, 3],
[6, 4]
];

return Plot.plot({
x: { type: "identity", axis: null },
y: { type: "identity", axis: null },
marks: [
Plot.hexagon(bins, {
r: radius, // Hexagon radius
x: ([i, j]) => radius * (2 * i + (j % 2)), // Horizontal position
y: ([i, j]) => radius * Math.sqrt(3) * j // Vertical position
})
]
});
}
Insert cell
d3.cross(d3.range(2, 16), d3.range(2, 11))
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more