-
preety.sehrawatSeptember 18, 2017 at 4:43 am #8051
Hi,
Thanks for this wonderful product. But now i am in a soup.
I want to trim the data labels on the basis of its immediate child visibility.
For ex:- If d.depth == 0 i.e only rool node is visible on the screen then my label will remain as it is, but if my d.depth ==1 i.e now all the immediate child nodes of root node is visible on the screen then the label of my root node will get trimmed because it is too long and same will continue in the case of nodes which are depth 1 if depth 2 nodes are visible all labels of depth 1 get trimmed.Kindly help me out.
Thanks in advance!!
Preety
vizulySeptember 18, 2017 at 9:05 am #8052Hello Pretty,
The Tree supports a label function in viz.label(); You can pass in your own function that will determine how to trim labels. For instance for your use case you may do something like this:
viz.label(function (d) {
if (d.children) {
return String(d.myLabel).substr(0,5);
}
});I hope that helps to point you in the right direction. Also you can adjust he spacing between branches by adjusting the size of the tree or adjust the span between nodes by explicitly setting viz.fixedSpan(mySpanInPixels).
Cheers,
Tom
preety.sehrawatSeptember 18, 2017 at 9:33 am #8053Hi Tom,
Thank you so much i have tried
viz.label(function (d) {
if (d.children) {
return trimLabel(d.key); // where trimLabel is trimming my label if its length is 15 or greater than it
}
});but it didn’t really help. After applying it my labels are not visible now.
Please suggest am i doing anything wrong?Regards
PreetyvizulySeptember 18, 2017 at 10:22 am #8054Hello Pretty,
Oops, I forgot the else part of the if clause.
viz.label(function (d) { if (d.children) { return trimLabel(d.key); } else { return d.key } });
This function will format a label for each node based on the logic you write.
– Tom
-
|
You must be logged in to reply to this topic.