Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an element to top of a group element

Tags:

d3.js

After joning data with my group I would like the elements in the enter selection to be added to a group (g-element) on top/highest up. Default is to append to the bottom.

The reason for this is that I want the object to visually appear below the all ready visible objects.

I know I can order and sort but I thought there might be an easier/better way to do this. I have done several manual things only to later find out "Oooh, they included a smart way to do that, EASILY."

like image 500
GusOst Avatar asked Mar 18 '13 18:03

GusOst


2 Answers

D3 does have an insert method: https://github.com/mbostock/d3/wiki/Selections#wiki-insert

like image 59
Nick Briggs Avatar answered Oct 30 '22 07:10

Nick Briggs


Excerpt from Reference

For instance, insert("div", ":first-child") will prepend child div nodes to the current selection.

https://github.com/mbostock/d3/wiki/Selections#wiki-insert

like image 39
n1nj4 Avatar answered Oct 30 '22 07:10

n1nj4