veg / phylotree.js

Interactive viewer of phylogenetic trees
http://phylotree.hyphy.org
MIT License
168 stars 72 forks source link

change node color #404

Closed tothuhien closed 2 years ago

tothuhien commented 2 years ago

I've just started to use phylotree.js and I want to change the color of the internal nodes but failed. Here is an example of the code I have:

var tree_newick = response.tree
var tree = d3.layout.phylotree().svg(d3.select(#tree_display))
tree(tree_newick).style_nodes((element, node) => {
                        element.style("fill","blue")
})
.layout()

but it just changes the color of the tip labels into blue. How to change the color of the circles representing the internal nodes? Thank you very much for your help. Hien

spond commented 2 years ago

Dear @tothuhien,

element will return a d3 selector for the <g> SVG element for this node. You can change node color by selecting all the circles contained in that element, by changing

element.style("fill","blue")

to

element.selectAll ("circle").style("fill","blue") 

Otherwise "fill" applies to <g> and is overridden by individual element styles for the children of <g>.

Best, Sergei

tothuhien commented 2 years ago

Thank you for your explanation, it works perfectly. Very much appreciated! Hien