How can we use D3.js, d3-delaunay, to create a Voronoi background? The guide from the official page is really hard to follow. The example page is even worst. For example:
view = {
const context = DOM.context2d(width, height);
context.clearRect(0, 0, width, height);
context.fillStyle = "black";
context.beginPath();
voronoi.delaunay.renderPoints(context, 1);
context.fill();
context.lineWidth = 1.5;
const segments = voronoi.render().split(/M/).slice(1);
let i = 0;
for (const e of segments) {
context.beginPath();
context.strokeStyle = d3.hsl(360 * Math.random(), 0.7, 0.5);
context.stroke(new Path2D("M" + e));
if (i++ % 5 === 0) yield context.canvas;
}
}
There is no other basic code structure - importing D3, declaring variables, and targeting an HTML element. How do apply and use this view object then?
I have looked around online. Still can't find any reliable guide for d3-delaunay. Any ideas?
EDIT:
I just want to use d3-delaunay on a web page, plain HTML with classic JS, without anything from Observerable HQ. But the documentation from D3.js is tightly coupled with Observable HQ. So I have no idea how to get d3-delaunay to work at all.
The creator or the team of D3.js never seems to care much about how unfriendly and counter-intuitive Observerable HQ is for some users. Platforms like Codepen are great. But how can a platform like Observerable HQ is ever conceived and created? It creates another BIG unnecessary obstacle layer on a JavaScript library.