First, there is no "dblclick"
typename for drag.on
, which is not the same of selection.on
. Hence your error:
Error: unknown type: dblclick
The only valid typenames are: "start"
, "drag"
and "end"
. That said, your code should not work, be it v5 or v6.
The rest of this answer deals with another major problem with D3 v6:
As specified in the API, selection.on()
in D3 version 6 passes the event as the first argument:
When a specified event is dispatched on a selected element, the specified listener will be evaluated for the element, being passed the current event (event) and the current datum (d), with this as the current DOM element (event.currentTarget)
Therefore, your function should be:
function dblclick(_, d) {
d.fx = null;
d.fy = null;
}
Here, the _
is just a JavaScript convention telling us that the first parameter (the event) is never used.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…