-
dvpavan153November 20, 2017 at 3:00 pm #8100
Hi,
I have tried to use two vizuly trees on the same page, but only one is clickable. I cannot toggle both 🙁
Here is my code,
In index.html
=============Here I have created two divs,
<div class=”container” style=”width:100%”>
<div id=”viz_container” class=”z-depth-3″>
</div>
</div><div class=”container” style=”width:100%”>
<div id=”viz_container1″ class=”z-depth-3″>
</div>
</div>
</div><script>
viz_container = d3.selectAll(“#viz_container”)
.style(“width”, screenWidth + “px”)
.style(“height”, screenHeight + “px”);viz_container1 = d3.selectAll(“#viz_container1”)
.style(“width”, screenWidth + “px”)
.style(“height”, screenHeight + “px”);//here I am calling two functions for the data
loadData();
loadData1();
</script>In weightedtree.js (This is the first js file for tree 1)
==================function loadData() {
data.values = prepData(some parameters);
initialize();
}function initialize() {
viz = vizuly.viz.weighted_tree(document.getElementById(“viz_container”)); //here I have passed viz_container id.theme = vizuly.theme.weighted_tree(viz).skin(vizuly.skin.WEIGHTED_TREE_AXIIS);
viz.data(data)
.width(600)
.height(600)
.children(function(d) {
return d.values
})
.key(function(d) {
return d.id
})
.value(function(d) {
return Number(10);
})
.fixedSpan(-1)
.label(function(d) {
return trimLabel(d.key)
})
.on(“measure”, onMeasure)
.on(“mouseover”, onMouseOver)
.on(“mouseout”, onMouseOut)
.on(“click”, onClick);changeSize(d3.select(“#currentDisplay”).attr(“item_value”));
// Open up some of the tree branches.
viz.toggleNode(data.values[0]);
}function onClick(g, d, i) {
viz.toggleNode(d);
}In weighted_tree1.js
==================== (This is the second js file for tree 2. I have copied the above code and just changed the container id and some function names )function loadData1() { //loading different data
data.values = prepData1(some parameters);
initialize1();
}function initialize1() {
viz = vizuly.viz.weighted_tree(document.getElementById(“viz_container1”)); //passing the second div’s idtheme = vizuly.theme.weighted_tree(viz).skin(vizuly.skin.WEIGHTED_TREE_AXIIS);
viz.data(data) // Expects hierarchical array of objects.
.width(600) // Width of component
.height(600) // Height of component
.children(function(d) {
return d.values
})
.key(function(d) {
return d.id
})
.value(function(d) {
return Number(10);
})
.fixedSpan(-1) // fixedSpan > 0 will use this pixel value for horizontal spread versus auto size based on viz width
.label(function(d) {
return trimLabel(d.key)
})
.on(“measure”, onMeasure1)
.on(“mouseover”, onMouseOver1)
.on(“mouseout”, onMouseOut1)
.on(“click”, onClick1);changeSize(d3.select(“#currentDisplay”).attr(“item_value”));
// Open up some of the tree branches.
viz.toggleNode(data.values[0]);
}//We can capture click events and respond to them
function onClick1(g, d, i) {
viz.toggleNode(d);
}Note: I have created two functions but used the same variable viz. Tried using viz1 but didn’t work ! 🙁
Need: Both trees are to be independent. They are being loaded with different sets of data.
Issues:
1) Only one of the trees is being clickable. In both the onClick and onClick1 functions, I have the same code viz.toggleNode.
I have tried giving different names like
viz1 = vizuly.viz.weighted_tree(document.getElementById(“viz_container1”));
viz1.data;
viz1.toggleNode;but this didnot work. Always throws an error, cannot set depth of undefined at function g() in vizuly_weightedtree.min.js
at var b = D(r).reverse() // here r is undefined2) I have tried using another approach, having two functions
viz = vizuly.viz.weighted_tree(“viz_container”) and
viz1 = vizuly.viz.weighted_tree1(“viz_container1”). One for each tree.It said vizuly.viz.weighted_tree is not a function.
Please let me know the best possible way to draw two decision trees on one page and both should be toggled independently.
Note: the mouseover, mouseout functions are working independently for each tree flawlessly.
Only the onClick function is not fully functional. Please help me at your earliest convenience.
Note: I have used only one “Vizuly_core.min.js” in common for both the trees.Thank You.
Expecting an early reply from you.Regards,
PavanvizulyNovember 20, 2017 at 3:10 pm #8101Hello Pavan,
Thanks for the detailed description of the problem. You should definitely be able to run two tree’s side by side.
We need to use two different variables like viz and viz1 as you tried. You only need to reference one vizuly_core_min.js file.
This should work:
var viz = vizuly.viz.weighted_tree(document.getElementById(‘#viz_container’));
var viz1 = vizuly.viz.weighted_tree(document.getElementById(‘#viz_container1’));I am not sure why you are getting the error you are, perhaps it has to do with another part of how you are setting variables. A couple things to look for are making sure you are using two different data objects (they can be the same data values, but need to be distinct objects, not references to each other.) Also make sure the data is valid for each.
This is a little difficult to troubleshoot without seeing how you structure all of your code. Another suggestion is to bring all of the code into one file just to get it working, and once you have it working you can then refactor it into different .js files. If you are able to post a public example I can take a closer look at it and try to debug it.
Cheers,
Tom
dvpavan153November 20, 2017 at 8:18 pm #8102Hi,
Thank you for the reply.
I have tried to create jsfiddle/pluker link, but with too many library files to be included, the attempt was not successful.
I have created a google drive link with the source code,
https://drive.google.com/open?id=1KBNqxqOY9bBOeZ7f67MpTTcX3BSKQqZy
Please find my source code, I have tried using a variable name viz1, but it throws an error. In the code I have shared, I have used the same variable “viz”. In this case, only one tree can be toggled. Please verify and kindly let me know how to fix this issue.
Thanks once again.
Regards,
Pavan.vizulyNovember 21, 2017 at 8:54 am #8104Hello Pavan,
I took a look at your code and debugged it and found the problem. But a few things first.
1) I recommend you refactor the code and remove all of the demo container items that came with the example as they are making things more confusing. Try reading our Basic Example article http://vizuly.io/basic-example/. If you strip out this extra code it will make things a LOT easier for you to debug.
2) You will need to make sure you have unique variables and functions for each viz, theme, data, and mouseover/out/click events. Like viz and viz1, theme and theme1, data and data1. onMouseClick, onMouseClick1 etc.. Right now you just have one set and they are operating on each other when the user clicks etc.
The issue you were having with the ‘r is undefined when calling viz1.toggleNode() is that you need to call update before doing that, so the tree has rendered.
So something like this:
viz1.update().toggleNode(data1.values[0]))
It took me a little while to trace the problem, but if you do as I suggest above it should make things a lot easier.
Thanks,
Tom
dvpavan153November 21, 2017 at 1:50 pm #8105Dear Tom,
First of all, Thank you so much for your valuable feedback.
1) As you suggested in the first point, I have removed all the unnecessary content from my code.
2) I have created variables as you suggested like viz, viz1, theme, theme1 and dataarray, data1array. I have completely commented out / removed the onclick, onmouseover etc functionalities for now.
3) My only intention now is to first draw the two trees with two different datasets using the above-mentioned variables.
Approach for the first tree, at function, initialize(),
viz.data(dataarray) // Expects hierarchical array of objects.
.width(600) // Width of component
.height(600) // Height of component
.children(function(d) {
return d.values
}) // Denotes the property that holds child object array
.key(function(d) {
return d.id
}) // Unique key
.value(function(d) {
return Number(10);
}) // Returning some random number
.fixedSpan(-1) // fixedSpan > 0 will use this pixel value for horizontal spread versus auto size based on viz width
.label(function(d) {
if (d.depth == 0) {
return trimLabel(“Zoo Health: ” + d.values[0].childProp_Health); //Label for root node
} // returns label for each node.
return trimLabel(d.key)
})Approach for the second tree, at function, initialize1(),
viz1.data(data1array) // Expects hierarchical array of objects.
.width(600) // Width of component
.height(600) // Height of component
.children(function(d) {
return d.values
}) // Denotes the property that holds child object array
.key(function(d) {
return d.id
}) // Unique key
.value(function(d) {
return Number(10);
}) // Returning some random number
.fixedSpan(-1) // fixedSpan > 0 will use this pixel value for horizontal spread versus auto size based on viz width
.label(function(d) {
if (d.depth == 0) {
return trimLabel(“Zoo Health: ” + d.values[0].childProp_Health); //Label for root node
} // returns label for each node.
return trimLabel(d.key)
})Issue: The children, key, label functions work flawlessly for the first tree, they are not giving expected output for the second. As a result, I can’t even draw the second tree in this approach.
I am sharing the google drive link with updated code,
https://drive.google.com/open?id=12ksFkjnc_Y6z8_-ROTS_aNTANVhh933IMy intention here is if the two trees can be drawn initially with this separate variable approach, I will focus further on the onclick, onmouseover etc events to make my tree fully functional.
Once again, Thank you for your time and effort for providing me the necessary feedback. It means a lot to me.
Regards,
PavanvizulyNovember 21, 2017 at 2:03 pm #8106Hello Pavan,
Thank you for the kinds words. It is very refreshing when someone acknowledges the effort people put in to help them with open source software. So many times people who use (and don’t contribute to) open source software have an expectation that the author should just provide free support no matter what and don’t recognize it is a volunteer effort.
So I took a look at your latest code – which is much cleaner and easier to follow 🙂 Once you get things working you can refactor it to remove a lot of the duplicated code and make it even tighter.
I played around your code, and was able to quickly determine that the problem is in the data itself for the second visualization. I was able to clone your first data set and pass it to the second visualization and both trees rendered correctly. My suggestion is for you debug the second data structure you are building and make sure the data is in the correct hierarchy – as there is something off in it.
Let me know what you find!
Cheer,
Tom
dvpavan153November 21, 2017 at 2:36 pm #8107Dear Tom,
I’m so glad to let you know that all the suggestions you gave me worked for good and my tree is fully functional.
In future, if anyone visits this space with the question, “Can we use two trees on the same page”?
The answer for that is a big “YESSSSSS, of course !” and here is the proof,
https://drive.google.com/open?id=1_IOLjzsX_QlC-8tRrUSnRqm-6JIKGOFx
Thanks a lot, Tom!
Regards,
Pavan.vizulyNovember 21, 2017 at 2:49 pm #8108Hello Pavan,
So glad you got it working!
I am working on Vizuly 2.0 which should be released the first part of next year. One of the improvements is streamlined test containers and integrated themes. This will reduce the number of files you need to manage and make getting start with your own project much easier, as you can take the example project right from the download and start integrating it into your application without all of the demo code attached to it.
Cheers,
Tom
-
|
You must be logged in to reply to this topic.