Example of TnT Tree with different node sizes.
Last active
January 12, 2016 16:38
-
-
Save emepyc/f36dcd3cd215ad1302c9 to your computer and use it in GitHub Desktop.
Different node sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<link rel="stylesheet" href="http://tntvis.github.io/tnt.tree/build/tnt.tree.css" type="text/css" /> | |
<style> | |
#mydiv { | |
margin-top : 50px; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://tntvis.github.io/tnt.tree/build/tnt.tree.min.js"></script> | |
<script src="node_size.js"></script> | |
</head> | |
<body> | |
<div id="mydiv"></div> | |
<script> | |
node_size(document.getElementById("mydiv")); | |
</script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var node_size = function (div) { | |
var scale = d3.scale.linear() | |
.domain(extent(species_data, "Protein-coding genes")) | |
.range([2, 10]); | |
var node_size = function (node) { | |
if (node.node_name()) { | |
return scale(species_data[node.node_name()]['Protein-coding genes']); | |
} | |
return 2; | |
}; | |
var tree = tnt.tree() | |
.data(tnt.tree.parse_newick(newick)) | |
.node_display(tnt.tree.node_display.circle() | |
.size(node_size) | |
.fill("white") | |
) | |
.layout(tnt.tree.layout.vertical() | |
.width(700) | |
.scale(true) | |
) | |
.label(tnt.tree.label.text() | |
.fontsize(12) | |
.text(function (node) { | |
return node.node_name(); | |
}) | |
); | |
tree(div); | |
}; | |
function extent (data, attr) { | |
var min; | |
var max; | |
for (var sp in species_data) { | |
if (species_data.hasOwnProperty(sp)) { | |
if ((species_data[sp] !== undefined) && (species_data[sp][attr] !== undefined)) { | |
var val = species_data[sp][attr]; | |
if ((min === undefined) || (val < min)) min = val; | |
if ((max === undefined) || (val > max)) max = val; | |
} | |
} | |
} | |
return [min, max]; | |
} | |
var newick = "(((((((Mus musculus:0.0845,Rattus norvegicus:0.0916):0.2567,Oryctolagus cuniculus:0.2157):0.0153,(((((Pan troglodytes:0.0067,Homo sapiens:0.0067):0.0022,Gorilla gorilla:0.0088):0.0097,Pongo abelii:0.0183):0.0143,Macaca mulatta:0.0375):0.0220,Callithrix jacchus:0.0661):0.0891):0.0206,(((Felis catus:0.0986,Canis familiaris:0.1025):0.0498,Equus caballus:0.1094):0.0107,((Ovis aries:0.0618,Bos taurus:0.0618):0.0869,Sus scrofa:0.1073):0.0403):0.0329):0.2584,Monodelphis domestica:0.3408):0.0717,Ornithorhynchus anatinus:0.4566):0.1095,(((Gallus gallus:0.0414,Meleagris gallopavo:0.0414):0.1242,Taeniopygia guttata:0.1715):0.3044,Anolis carolinensis:0.4989):0.1700)"; | |
var species_data = { | |
'Homo sapiens' : { | |
'Chromosome pairs' : 23, | |
'Protein-coding genes' : 20805, | |
'Genome length' : 3.1, | |
'Ensembl date' : new Date(2001, 07), | |
'Cuteness factor' : 6 | |
}, | |
'Tetraodon nigroviridis' : { | |
'Chromosome pairs' : 21, | |
'Protein-coding genes' : 19602, | |
'Genome length' : 0.36, | |
'Ensembl date' : new Date(2004, 09), | |
'Cuteness factor' : 10 | |
}, | |
'Monodelphis domestica' : { | |
'Chromosome pairs' : 11, | |
'Protein-coding genes' : 21327, | |
'Genome length' : 3.6, | |
'Ensembl date' : new Date(2005, 11), | |
'Cuteness factor' : 9 | |
}, | |
'Mus musculus' : { | |
'Chromosome pairs' : 20, | |
'Protein-coding genes' : 23148, | |
'Genome length' : 2.7, | |
'Ensembl date' : new Date(2002,01), | |
'Cuteness factor' : 7 | |
}, | |
'Ornithorhynchus anatinus' : { | |
'Chromosome pairs' : 26, | |
'Protein-coding genes' : 21698, | |
'Genome length' : 2.1, | |
'Ensembl date' : new Date(2006,12), | |
'Cuteness factor' : 9 | |
}, | |
'Pan troglodytes' : { | |
'Chromosome pairs' : 24, | |
'Protein-coding genes' : 18759, | |
'Genome length' : 3.3, | |
'Ensembl date' : new Date(2004,05), | |
'Cuteness factor' : 6 | |
}, | |
'Macaca mulatta' : { | |
'Chromosome pairs' : 21, | |
'Protein-coding genes' : 21905, | |
'Genome length' : 3.1, | |
'Ensembl date' : new Date(2005,12), | |
'Cuteness factor' : 6 | |
}, | |
'Ovis aries' : { | |
'Chromosome pairs' : 27, | |
'Protein-coding genes' : 20921, | |
'Genome length' : 2.6, | |
'Ensembl date' : new Date(2013,12), | |
'Cuteness factor' : 6 | |
}, | |
'Sus scrofa' : { | |
'Chromosome pairs' : 19, | |
'Protein-coding genes' : 21630, | |
'Genome length' : 2.8, | |
'Ensembl date' : new Date(2009,09), | |
'Cuteness factor' : 5 | |
}, | |
'Ciona intestinalis' : { | |
'Chromosome pairs' : 14, | |
'Protein-coding genes' : 16658, | |
'Genome length' : 0.1, | |
'Ensembl date' : new Date(2005,05), | |
'Cuteness factor' : 3 | |
}, | |
'Rattus norvegicus' : { | |
'Chromosome pairs' : 21, | |
'Protein-coding genes' : 22941, | |
'Genome length' : 2.9, | |
'Ensembl date' : new Date(2002,11), | |
'Cuteness factor' : 5 | |
}, | |
'Anolis carolinensis' : { | |
'Chromosome pairs' : 14, | |
'Protein-coding genes' : 18596, | |
'Genome length' : 1.8, | |
'Ensembl date' : new Date(2009,03), | |
'Cuteness factor' : 7 | |
}, | |
'Bos taurus' : { | |
'Chromosome pairs' : 30, | |
'Protein-coding genes' : 19994, | |
'Genome length' : 2.7, | |
'Ensembl date' : new Date(2005,07), | |
'Cuteness factor' : 6 | |
}, | |
'Pongo abelii' : { | |
'Chromosome pairs' : 24, | |
'Protein-coding genes' : 20424, | |
'Genome length' : 3.4, | |
'Ensenbl date' : new Date(2011,04), | |
'Cuteness factor' : 8 | |
}, | |
'Callithrix jacchus' : { | |
'Chromosome pairs' : 23, | |
'Protein-coding genes' : 20993, | |
'Genome length' : 2.9, | |
'Ensembl date' : new Date(2009,09), | |
'Cuteness factor' : 8 | |
}, | |
'Equus caballus' : { | |
'Chromosome pairs' : 32, | |
'Protein-coding genes' : 20449, | |
'Genome length' : 2.5, | |
'Ensembl date' : new Date(2008,03), | |
'Cuteness factor' : 6 | |
}, | |
'Taeniopygia guttata' : { | |
'Chromosome pairs' : 40, | |
'Protein-coding genes' : 17488, | |
'Genome length' : 1.2, | |
'Ensembl date' : new Date(2009,03), | |
'Cuteness factor' : 8 | |
}, | |
'Gasterosteus aculeatus' : { | |
'Chromosome pairs' : 22, | |
'Protein-coding genes' : 20787, | |
'Genome length' : 0.46, | |
'Ensembl date' : new Date(2006,08), | |
'Cuteness factor' : 3 | |
}, | |
'Gallus gallus' : { | |
'Chromosome pairs' : 39, | |
'Protein-coding genes' : 15508, | |
'Genome length' : 1, | |
'Ensembl date' : new Date(2004,06), | |
'Cuteness factor' : 4 | |
}, | |
'Felis catus' : { | |
'Chromosome pairs' : 19, | |
'Protein-coding genes' : 19493, | |
'Genome length' : 2.5, | |
'Ensembl date' : new Date(2007,02), | |
'Cuteness factor' : 9 | |
}, | |
'Gorilla gorilla' : { | |
'Chromosome pairs' : 24, | |
'Protein-coding genes' : 20962, | |
'Genome length' : 3, | |
'Ensembl date' : new Date(2008,12), | |
'Cuteness factor' : 4 | |
}, | |
'Oryctolagus cuniculus' : { | |
'Chromosome pairs' : 22, | |
'Protein-coding genes' : 19293, | |
'Genome length' : 2.7, | |
'Ensembl date' : new Date(2006,08), | |
'Cuteness factor' : 10 | |
}, | |
'Meleagris gallopavo' : { | |
'Chromosome pairs' : 40, | |
'Protein-coding genes' : 14125, | |
'Genome length' : 1.1, | |
'Ensembl date' : new Date(2010,03), | |
'Cuteness factor' : 2 | |
}, | |
'Canis familiaris' : { | |
'Chromosome pairs' : 39, | |
'Protein-coding genes' : 19856, | |
'Genome length' : 2.4, | |
'Ensembl date' : new Date(2004,12), | |
'Cuteness factor' : 6 | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment