-
vinayaksangarJuly 20, 2017 at 11:36 pm #8030
Hi Tom .
Thanks for support .I am working on your tree and my requirement required such that
each node has two properties one score and one weight. I want to modify the tree such that
1)colour of links represent the score range (as between 2 and 4 is pink etc)
2) weight represents thickness (e.g. n1 has two children n2(30% weight) n3(70% weight))
(n1->n3 edge should be thicker than n1->n2 edge)Presently i am able to modify tree such that link colors represent score but thickness is also based on score .
I want to add the 2nd requirement
What i am thinking is to
1) First add a property named value2 in below function in file viz/weightedTree.jsvizuly.viz.weighted_tree = function (parent) { // This is the object that provides pseudo "protected" properties that the vizuly.viz function helps create var scope={}; var properties = { "data" : null, .... } as below
“value” : null,/* This stores score */
/**
* dynamic function that returns the appropriate label for a given node.
* @type {Function}
* @default function (d,i) { return d; }
*/
“value1” : null,/* This stores weight */
/**
* dynamic function that returns the appropriate label for a given node.
* @type {Function}
* @default function (d,i) { return d; }
*/`2) Then to pass the weight property here in weightedTree.js file
viz.data(data)
.width(600)
.height(600)
.children(function (d) { return d.values })
.key(function (d) { return d.id })
.value(function (d) {
return Number(d[“agg_” + valueField]) })
// The property of the datum that will be used for the branch and node size
.fixedSpan(-1)
// fixedSpan > 0 will use this pixel value for horizontal spread versus auto size based on viz width
.branchPadding(.07)
.label(function (d) {
// returns label for each node.
return trimLabel(d.key || (d[‘Level’ + d.depth]))})
.on(“measure”,onMeasure)
.on(“mouseover”,onMouseOver)
.on(“mouseout”,onMouseOut)
.on(“click”,onClick);<code></code>as below
.value(function (d) { //This passes score return Number(d["agg_" + valueField]) }) .value1(function (d) { // This passes weight return Number(d["agg_weight"]) })
3) Then change the below function in viz/weightedTree.js
var nodeRadius = function (node) { //Set max size/2 for root node. if (node.depth == 0) return nodeScale.range()[1]/2; nodeScale.domain([minValues[node.depth],maxValues[node.depth]]); return nodeScale(scope.value(node)); }
If i am correct I have few queries
1) Am I correct?
2) What changes should i do in the 3rd step How to modify nodeRadius function to use value1 property which holds weight.What is the purpose of scaling???Where are minValues[node.depth] calculated.
3) Do i need to make some changes in theme/weightedTree.js
Thanks Tom .
Fan Of Your CodingvizulyJuly 26, 2017 at 8:08 am #8034Hello,
Sorry for the delayed response.
You are definitely on the right track. It sounds like you already have the color working correctly, and you just need to update the code in Step 3.
Simply replace the scope.value with scope.value1 function. Additionally you will want to modify this code in the
measure()
function to use the scope.value1 (versus scope.value) function.for (var i=1; i < maxDepth+1; i++) { var vals = nodes.filter(function (d) { return d.depth == i}); maxValues[i] = d3.max(vals, function (d) { return scope.value1(d)}); minValues[i] = d3.min(vals, function (d) { return scope.value1(d)}); }
Good Luck,
Tom
-
|
You must be logged in to reply to this topic.