javascript - Manipulate d3.js pack layout with HTML5 Range Input -
i have http://jsfiddle.net/thechrisjordan/p4fwm/11/, i'm manipulating d3 pack layout html5 slider. working except how nodes ordered when updatevis() called.
this code pretty straight forward: i'm creating layout, , slider emits event causes layout update.
what i'm hoping achieve same behavior have child nodes remain in same general areas in pack change size. can see, reposition here.
it looks issue line 69 pack.nodes(data); called. i've dug d3 source can't figure out how prevent reordering (and may not possible...).
i suppose alternative try , squeeze pack layout force layout.
i'm brand new d3 , grateful insight here.
if understood you're asking do, i'm pretty sure doable. here's fiddle; added rgb fun keep track of circles.
this done using pack layout's sort() method, ensures they're laid out in persistent order. achieve it, had assign index value each of objects declared (and optional rgb color):
data.children.foreach(function(d, i) { d.index = i; d.fill = ['#c33','#3c3','#33c'][i]; }); then it's matter of using index sort:
var pack = d3.layout.pack() .size([diameter - 4, diameter - 4]) .sort(function(a,b) { return d3.ascending(a.index, b.index); }) // <--- .value(function(d) { return d.size; }); hope helped.
Comments
Post a Comment