javascript - d3.js collapsible force diagram - assigning unique ID's to identical nodes -


i have nice collapsible force layout collapsed in beginning taken http://bl.ocks.org/mbostock/1093130.

here example: http://plnkr.co/edit/rqh8sd?p=preview

it works when nodes have unique names (http://plnkr.co/edit/e1n6asbm5vfx2vjgpkko?p=preview), nodes have same name (unfortunately need that), collapsing not work properly.

anyone able me assign unique ids identical names of nodes? believe piece of code make trick not know insert it.

node.each(function(d,i){ // use iterate through   d.uniqueid = uniquenode + i; } 

i tried issue solved @ previous thread d3.js collapsible force layout, collapsed default - not successful.

any appreciated!

doing make nodes unique should work. i'd recommend doing after flatten nodes, before insert them force directed graph:

function update(d) {

var nodes = flatten(root),     links = d3.layout.tree().links(nodes);  nodes.each(function(d, i) { d.uniqueid = i; });  // restart force layout. force     .nodes(nodes)     .links(links)     .start(); 

you'll need update key function when using .data() on nodes

  // update nodes   node = node.data(nodes, function(d) { return d.uniqueid; }); 

you need take note however, if change data bindings might wrong. if insert new value, push indexes off 1, potentially causing data join wrong elements in future.

a possible different way of solving problem might change key function @ id of direct parent (or parents) too.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -