score:1

Accepted answer

jsfiddle

You called draw method multiple times, so you have to treat it carefully.

Only newly added nodes are supposed to be added image and circle tags, so you should change

mNode = svg.selectAll(".node")
            .data(mNodesData)
            .enter()
            .append("g")
            .attr("class", "node").
            merge(mNode);

to

var newNodes = svg.selectAll(".node")
            .data(mNodesData)
            .enter()
            .append("g")
            .attr("class", "node");

mNode=newNodes.merge(mNode);

and change

var nodeCircle = mNode.append("circle")

to

var nodeCircle = newNodes.append("circle")

And image related code are supposed to be changed in same manner.


Related Query