Skip to content

Instantly share code, notes, and snippets.

@emepyc
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save emepyc/fcf93328bd73d849ac9d to your computer and use it in GitHub Desktop.

Select an option

Save emepyc/fcf93328bd73d849ac9d to your computer and use it in GitHub Desktop.
branch lengths

The scale method specifies if the tree should be rendered using the tree's branch lengths or not (true by default). Branch lengths are computed taking the branch_length property of the tree object. This is normally set automatically when your input is a newick formatted tree that includes branch lengths. If scale is set to false, branch lengths are ignored and the tree will display in an isometric layout (all paths from leaves to root having the same length).

<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" href="http://emepyc.github.io/tnt/v0/tnt.css" type="text/css" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://emepyc.github.io/tnt/v0/tnt.min.js"></script>
<script src="theme.js"></script>
</head>
<body>
<div id="mytree"></div>
<script>
deploy (document.getElementById("mytree"));
</script>
</body>
function deploy (div) {
// toggle for branch lengths
var sel = d3.select(div)
.append("select")
.on ("change", function () {
tree_vis.layout().scale(this.value === "use_branch_lengths");
tree_vis.update();
})
sel
.append("option")
.attr("value", "use_branch_lengths")
.text("Use branch lengths");
sel
.append("option")
.attr("value", "ignore_branch_lengths")
.text("Ignore branch lengths");
var tree_vis = tnt.tree()
.data (tnt.tree.parse_newick(newick))
.layout (tnt.tree.layout.vertical()
.width(650)
)
.label (tnt.tree.label.text()
.height(20)
);
tree_vis(div);
}
// The tree to plot
var newick = "(((((((((Homo_sapiens:0.0067,Pan_troglodytes:0.006667):0.00225,Pongo_abelii:0.018318):0.00717,Nomascus_leucogenys:0.025488):0.00717,(Macaca_mulatta:0.007853,Papio_hamadryas:0.007637):0.029618):0.021965,Callithrix_jacchus:0.066131):0.05759,Tarsius_syrichta:0.137823):0.011062,(Microcebus_murinus:0.092749,Otolemur_garnettii:0.129725):0.035463):0.015494,Tupaia_belangeri:0.186203):0.004937,(((((Mus_musculus:0.084509,Rattus_norvegicus:0.091589):0.197773,Dipodomys_ordii:0.211609):0.022992,Cavia_porcellus:0.225629):0.01015,Ictidomys_tridecemlineatus:0.148468):0.025746,(Oryctolagus_cuniculus:0.114227,Ochotona_princeps:0.201069):0.101463):0.015313);";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment