Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variable branch lengths in tree layout #213

Closed
jdidion opened this issue Jul 5, 2011 · 10 comments
Closed

Allow variable branch lengths in tree layout #213

jdidion opened this issue Jul 5, 2011 · 10 comments
Milestone

Comments

@jdidion
Copy link

jdidion commented Jul 5, 2011

I would love to use D3 for creating phylogenetic trees. A phylogenetic tree is basically a hierarchical tree where each node specifies its distance from its parent, and this distance must be reflected by the length of the branch. If there is currently a way to do this with D3, I can't figure it out.

As a side note, the standard format for phylogenetic trees is Newick (http://en.wikipedia.org/wiki/Newick_format). I would be happy to write a function to transform a Newick tree to an appropriate JSON object that could then be used with D3. This would open up D3 to be used by the bioinformatics community and possibly get you some citations in scientific publications when people create trees using D3.

@mbostock
Copy link
Member

mbostock commented Jul 5, 2011

@jasondavies has implemented phylogenetic trees using D3, using the Newick format even. See his example:

http://www.jasondavies.com/tree-of-life/

@mbostock mbostock closed this as completed Jul 5, 2011
@jasondavies
Copy link
Contributor

Yep, it uses https://github.com/jasondavies/newick.js, let me know if you have any questions!

@jdidion
Copy link
Author

jdidion commented Jul 5, 2011

This is cool, and I'm glad to see there's a newick class for javascript (nice work Jason!). However, the tree does not appear to be honoring the branch lengths defined in life.txt. At every level of the tree, the children are displayed as equidistant from the parent when this is not actually the case.

Also, I'd like to draw a radial (unrooted) tree rather than a circular one, but the radial-tree example doesn't seem to work if I use the JSON object created by newick.js rather than the flare.json object.

Thanks for the help!

@mbostock mbostock reopened this Jul 5, 2011
@jasondavies
Copy link
Contributor

Ah, excellent point. Turns out it was quite easy to adjust to take into account the branch lengths from the tree data:

function phylo(n, offset) {
  if (n.data && n.data.length != null)
    offset += n.data.length * 115;
  n.y = offset;
  if (n.children)
    n.children.forEach(function(n) {
      phylo(n, offset);
    });
}

Here we are overwriting the y values from the cluster layout with our own, derived from the parsed data.

I've updated http://www.jasondavies.com/tree-of-life/ to show how this works.

@jdidion
Copy link
Author

jdidion commented Jul 7, 2011

This is great, Jason. However, I'd like to leave the bug open as what I really want is a radial tree with variable branch lengths. I know this is not trivial as I've already wasted a day trying to figure out how to implement it. I got it working to a point (I basically had to translate the x/y values from "distance from root" to "distance from parent") but for trees with more than one or two levels of depth the branches and labels start overlapping. I think a new layout or a significant refactoring of the base hierarchy layout would be required. From a user perspective, the easiest might be to have a method similar to separation that controls the distance between length of a link (i.e. distance between parent and child).

@jdidion jdidion closed this as completed Jul 7, 2011
@jdidion jdidion reopened this Jul 7, 2011
@jasondavies
Copy link
Contributor

Yes, a configurable radial (or y) separation, along with a configurable radial distance could indeed be useful for users instead of having to roll their own. I will put up an example of how this might look when I get a chance.

@KoRMaK
Copy link

KoRMaK commented Jun 6, 2012

Along these lines, is there a way to increase the branch lengths? I don't mind if they are all the same length, I just need to increase each of mine by some pixels. I've been reading all over but can't figure it out. Any help would be much appreciated!

@pavo
Copy link

pavo commented Dec 17, 2012

Kueda has implemented circular dendrograms http://bl.ocks.org/1036776.

@Chris-Eisenhart
Copy link

Hmm this seems to be implemented with the d3 heirarchy class 'cluster' not the d3 heirarchy class 'tree'. I am trying to do variable link lengths on the 'tree' layout, any suggestions?

@mbostock
Copy link
Member

Here’s a newer example using the cluster layout:

screen shot 2015-11-30 at 2 38 17 pm

You can’t apply the same strategy with the “tidy” tree layout because that algorithm assumes that the tree is layered (i.e., each node at a given depth in the tree shares the same y-position in the resulting layout). See #2571 and d3-flextree for an implementation of a non-layered trees, as in Drawing Non-layered Tidy Trees in Linear Time by A.J. van der Ploeg.

@mbostock mbostock closed this as completed Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants