I am simply trying add and remove elements (nodes/circles) using d3 on a SVG element. However, my code keeps generating the following exception.
Uncaught TypeError: Cannot read property 'ownerSVGElement' of null at d3_mousePoint (VM2163 d3.js:1127) at d3.mouse (VM2163 d3.js:1122) at moved (VM2163 d3.js:1177) at VM2163 d3.js:1084 d3_mousePoint @ VM2163 d3.js:1127 d3.mouse @ VM2163 d3.js:1122 moved @ VM2163 d3.js:1177 (anonymous) @ VM2163 d3.js:1084
The problem seems to be with adding dragging behavior to the elements because if I remove .call(someDragFunction)
then adding and removing elements doesn't generate that exception (but then, of course, I can't drag those elements around the SVG canvas).
An example is shown here http://plnkr.co/edit/DnSBXSjXhQ2AJsGYvWxE?. If you click "+node" and click on the SVG box, a node will be drawn. If you click "-node" and click on a node/circle drawn, that node will be removed. Only when the last node is attempted to be removed does the exception show.
Any ideas on what I'm doing wrong? Btw, I'm using D3 v3.5.3.