How To Select All D.data.id Ends In A Specified Word In A D3.tree Code?
After receiving an answer in my last question, I could modify a d3.tree code in a desired way. Kindly, imagine I have the following flare.csv file A A.A A.A.B A.A.C A.B A.B.C A.C
Solution 1:
If you want to colour red the nodes that end with data
, just split the string:
var array = d.data.id.split(".");
And check for the last element. In the case of your hypothetical CSV:
return !d.parent ? "blue" : array[array.length-1] === "B" ? "red" : "black";
This will colour red any ID ending in B
.
And in the case of the real bl.ocks (regarding your pre-edit question):
.style("fill", function(d){
var array = d.data.id.split(".");
return !d.parent ? "blue" : array[array.length-1] === "data" ? "red" : "black";
})
Here is the updated bl.ocks: https://bl.ocks.org/anonymous/bb3ff95151d3252597d52c917489dda2
Solution 2:
Not the best answer, but alternatively you could...
Add logical operators to the ternary conditions to include other indices.
.style("fill", function(d){
return !d.parent ? "blue" : (d.data.id === "A.D.B" || d.data.id === "A.D.D") ? "red" :
"black";
})
Post a Comment for "How To Select All D.data.id Ends In A Specified Word In A D3.tree Code?"