D3 TypeError: link.exit is not a link.exit () function. Remove (); What am I doing wrong?

I am doing a D3 tree layout. I've looked all over and it seems that this error appears when you have no DOM bound data and are trying to delete it. I ensured not only that there is data in there, but I also made sure that the data changes by doing a count in the reference array before and after I change it.

Here is the problem code from my update function.

    link = linkElements.selectAll("path.link") //link elements is dom object that holds my links
    .data(links).enter().append("path")
    .attr("class", "link")
    .attr("d", diagonal);

    link.exit().remove();

      

It's pretty much the same as in many examples, but I see this all the time:

TypeError: link.exit is not a function

link.exit().remove();

      

What's happening? I am doing something similar with nodes. I cannot remove anything from the tree.

+3


source to share


1 answer


Note what link

gets assigned:

link = linkElements.selectAll("path.link")
  .data(links)
.enter() // <----- THIS
  .append("path")
  .attr("class", "link")
  .attr("d", diagonal);

      

So link

is a selection containing newly added nodes resulting from a subsample enter()

, so by definition it has no subsection exit()

.



What you need (and probably need to) be assigned link

to the whole data-bound selection, andand then :

link = linkElements.selectAll("path.link")
  .data(links);// link assigned
link.enter() // <----- THIS
  .append("path")
  .attr("class", "link")
  .attr("d", diagonal);
link.exit().remove(); // no more errors!

      

+10


source







All Articles