3

I've got a force-directed graph with labels on the nodes. In order to keep everything organized, I am keeping each circle/label pair inside a <g> element.

The tricky part is that on a doubleclick of the node, I am adding more points to the graph, and running this function again - what that means is that I start getting duplicate text elements.

Is there a way to put the append("text") inside the same enter() scope but make it append as a sibling of the circle instead of as a child?

I looked at this answer, which helpd me understand what I should be doing, but I don't know how to get both appends to be siblings... D3js force duplicate nodes on enter()

            node.enter().append("g")
                .attr("class", "node")
                .call(drag)
                .append("circle")
                .attr("r", 10)
                .style("fill", function(d) {
                    return publisherScale(d.publisher);
                })
                .style("stroke", "rgba(255,255,255,.8)");

            node.append("text")
                .attr("dy", ".35em")
                .attr("dx", 10)
                .style("font-size", nominal_text_size + "px")
                .text(function(d) {
                    return '\u2002' + d.name
                });
Community
  • 1
  • 1
Charles Bandes
  • 795
  • 8
  • 21

0 Answers0