The structure of the linked example is like this:
<svg:g class="node">
<svg:image class="circle"/>
<svg:text class="nodetext"/>
</svg:g>
<svg:g class="node">
<svg:image class="circle"/>
<svg:text class="nodetext"/>
</svg:g>
…
This, while each text element is drawn on top of its corresponding
circle, it's possible that the circle for a later node could be drawn
on top of the label for an earlier node. You could change the
structure to be like this:
<svg:g class="circle">
<svg:image/>
<svg:image/>
…
</svg:g>
<svg:g class="nodetext">
<svg:text/>
<svg:text/>
…
</svg:g>
This will require changing how you create the nodes (using selectAll
twice), and how you update the nodes. Though, you can merge the two
selections together for update:
node = vis.selectAll("g.circle image, g.nodetext text");
You'd also need to change the CSS a bit.
Mike
That'd be great, but as far as I know it's not supported by any browser vendors.
Mike
appendChildnewChild to the end
of the list of children of this node. If the newChild
is already in the tree, it is first removed.
insertBeforenewChild before
the existing child node refChild. If
refChild is null, insert
newChild at the end of the list of children.newChild is a DocumentFragment
object, all of its children are inserted, in the same order, before
refChild. If the newChild is already in
the tree, it is first removed.
https://github.com/mbostock/d3/wiki/Selections#sort
This can be used to control the render order; see the implementation:
https://github.com/mbostock/d3/blob/master/src/core/selection.js#L510
Mike