JavaScript InfoVis Toolkit SpaceTree node order

395 views Asked by At

I am using the InfoVis SpaceTree to visualize a tree. The complete tree is loaded in one call to the loadJSON method. Each node's children are already in the correct order. But the nodes do not display in the order they are defined in the data structure, i.e. according to their array index.

How can I make them display in the right order? Any help would be greatly appreciated.

1

There are 1 answers

0
Michael Cho On

The tree does not display nodes based on their order in the JSON data structure / array index.

Instead, it is based on the 'id' attribute, which is used as the key for storing nodes in an internal hash (well, technically an object). Note it is a hash and not an array, so the order is irrelevant.

A node with id 100 will always be displayed before a node with id 101. If you want your node's children to display in a particular order, make sure your child nodes are sorted by id.