-
BlairApril 4, 2018 at 12:46 pm #8904
Hey,
While trying to build a weighted tree I noticed that the viz() function is not correctly building the .children and related tree properties. I am using the demo code to get it up and running in my environment.
At the point I have data.values, those values are identical to the demo found on your website. But after running the viz.data()… chain the .children and x/y properties are not set like in the demo.
Any idea where I have gone wrong? I’ve copied the required libraries out of the source code
This is within an Angular 4 app
buildTreeVisual() { var data = {}; var root = this; d3.csv("../assets/data/weightedtree_federal_budget.csv", function (csv) { data['values'] = root.prepData(csv); var blob = JSON.stringify(data); let viz = vizuly.viz.weighted_tree(document.getElementById("viz_container")); //Here we create three vizuly themes for each radial progress component. //A theme manages the look and feel of the component output. You can only have //one component active per theme, so we bind each theme to the corresponding component. let theme = vizuly.theme.weighted_tree(viz).skin(vizuly.skin.WEIGHTED_TREE_AXIIS); viz.data(data) .width(600) .height(600) .children(function (a) { return a['values']; }) .key(function (a) { return a['id']; }) .value(function (a) { return 10; }) .fixedSpan(-1) .branchPadding(0.7) .label(function (a) { return root.trimLabel(a['key'] || a['Level' + a.depth]) }); viz.toggleNode(data['values'][0]); }); }
BlairApril 4, 2018 at 12:52 pm #8905I should also mention there are no console errors until .toggleNode is called
That error is “ERROR TypeError: Cannot set property ‘depth’ of undefined”
vizulyApril 4, 2018 at 12:54 pm #8906Hi Blair,
Thanks for the question.
The weighted tree can sometimes be a bit of a bear to debug due to the hierarchal data it represents, and having to manually validate those data structures. I don’t see anything obvious in your code that would create a problem. Although the ‘root = this’ is a little odd. You may want to set that to an new object like ‘root = {}’
What I typically do in situations like this, is either start with a known data set that works correctly (it appears you are doing that, but using the federal budget data). Alternatively I start with a super simply data set that you could debug by hand. Say a 2 level tree with three nodes, one parent and two children and then go from there.
I wish I had something more insightful to offer. If you get more detailed error info I will do my best to help.
Cheers,
Tom
BlairApril 4, 2018 at 1:00 pm #8908Hi Tom,
Thanks for the quick reply!
I was having a look at the basic demo, which had an extra line for viz.update(). Adding this is now rendering the tree
My next quick question is, is there an easy way to open all nodes?
Cheers
vizulyApril 4, 2018 at 1:05 pm #8909Hi Blair,
Check out the toggleNode code inside the src/viz/weightedtree.js function that will show you what it is doing to ‘toggle’ a node, which is essentially making sure all parent nodes have a valid ‘children’ property (versus ‘_children’).
You will want to make a recursive function that goes through all parent/children and doe the same thing as the toggleNode function (making sure just to open the nodes, versus closing open ones.) You can do this in the test container, but the appropriate place would be in the src/viz/weightedtree.js component file.
Cheers,
Tom
-
|
You must be logged in to reply to this topic.