Converting a D3.js forcediagram from version 5 to 6.1, I write:
let drag = simulation => {
function dragstarted(event, d) {
if (!event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(event,d) {
d.fx = event.x;
d.fy = event.y;
}
function dragended(event,d) {
if (!event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
// release of fixed positions
function dblclick(d) {
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended)
.on("dblclick", dblclick);
However, I am getting the error on dblclick: Uncaught (in promise) Error: unknown type: dblclick d3.min.js:2:9279
The code is copied from: https://observablehq.com/@d3/force-directed-graph?collection=@d3/d3-force. Only the dblclick is added. It is working in version 5, but as a separate function.
How can I add dblclick in version 6.1 of D3.js the correct way?
See Question&Answers more detail:os