-
JerryDecember 19, 2016 at 11:48 pm #6820
Hey Tom,
Your visualization is great. I am using the weighted tree to present my data. I want ask how to sort the nodes in each level by key(string) or agg_value.
Thank you
vizulyDecember 20, 2016 at 1:54 pm #6827Hi Jerry,
That is a good question.
The primary layout for the tree is generated by D3, but I suspect we could sort the children for each branch.
The place I would start is in the refreshData() function at line 170 in the viz/weightedtree.js file. Specifically there is a nested function called setChildren(), where it sets a default x/y position. I would try to apply whatever sort you want to the children at this place and see if D3 respects the array sort order (which I think it will.)
Good luck and let me know what you find out.
– Tom
vizulyDecember 21, 2016 at 11:27 am #6832Hi Jerry,
This question had been nagging me, so I dug into the code a little bit because I recall D3 having native support for this function. Here is the solution.
Add this code to the end of the
measure()
function in viz/weightedtree.js. This will sort the nodes by the current value in ascending order. You can modify to the sort to meet your particular needs.tree.sort(function (a,b) { if (scope.value(a) > scope.value(b)) { return 1 } else if (scope.value(a) < scope.value(b)) { return -1 } else return 0; })
– Tom
JerryDecember 21, 2016 at 12:14 pm #6834Hi Tom,
I was struggling with the solution yet, you helped a lot.
Thank you so much.Jerry
-
|
You must be logged in to reply to this topic.