Public
Edited
Oct 26, 2023
1 fork
15 stars
Insert cell
Insert cell
{
const r = 22.5;
const margin = 2.2 * r;
const height = width / 2;
const hexbin = d3
.hexbin()
.extent([
[2 * r, 2 * r],
[width - 2 * r, height - 2 * r]
])
.radius(r);
const hexbin1 = d3
.hexbin()
.extent([
[2 * r, 2 * r],
[2 * r, 2 * r]
])
.radius(r);

return html`<svg viewBox="0 0 ${width} ${height}" stroke-width="0.5">
<rect fill="none" stroke="#333" stroke-dasharray="5 3"
x=${margin} y=${margin} width=${width - 2 * margin} height=${height - 2 * margin}></rect>
<path fill="none" stroke="#ccc" d="${hexbin.mesh()}"></path>

<g font-family="sans-serif" font-size=12>
${hexbin
.centers()
.map(
([x, y], i) =>
svg`<text transform="translate(${x},${y})" dy="0.38em" text-anchor="middle">${i}</text>`
)}
</g>
<path fill="none" stroke="red" stroke-width=2 d="${hexbin1.mesh()}"></path>
</svg>`;
}
Insert cell
d3 = require("d3-hexbin@0.2")
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