viewof stroke = {
const height = 500;
const context = DOM.context2d(width, height);
const curve = d3.curveCatmullRom(context);
function dragsubject() {
return [];
}
function dragged() {
const stroke = d3.event.subject;
stroke.push([d3.event.x, d3.event.y]);
context.clearRect(0, 0, width, height);
context.beginPath();
curve.lineStart()
for (let i = 0; i < stroke.length; ++i) {
curve.point(...stroke[i]);
}
curve.lineEnd();
context.stroke();
context.canvas.value = stroke;
context.canvas.dispatchEvent(new CustomEvent("input"));
}
d3.select(context.canvas).call(d3.drag()
.container(context.canvas)
.subject(dragsubject)
.on("start drag", dragged));
return context.canvas;
}