diff --git a/README.md b/README.md index d73edf1..c4029e7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## phylotree.js +# phylotree.js A JavaScript interactive viewer of [phylogenetic trees](https://en.wikipedia.org/wiki/Phylogenetic_tree), written as an extension of the [D3](http://d3js.org) [hierarchy layout](https://github.com/mbostock/d3/wiki/Hierarchy-Layout). It generates high quality SVG vector graphics, allows a great degree of customizability (CSS or JavaScript callbacks), and comes with a lot of *built-in* convenicence features. @@ -25,8 +25,12 @@ Key features 1. A [gallery of examples](http://bl.ocks.org/spond) is a good place to learn different ways that phylotree.js can be used to display and annotate the trees. 2. A [full-featured web application](http://veg.github.io/phylotree.js/index.html) based on phylotree.js, implemented in [index.html](index.html). -3. phylotree.js is also used by the 2015 revision of the [datamonkey.org server](http://test.datamonkey.org) for molecular sequence analyis. +3. phylotree.js is also used by the 2015 revision of the [datamonkey.org server](http://test.datamonkey.org) for molecular sequence analysis. ## Dependencies See [bower.json](bower.json) for dependencies. + +## Tests + +Run tests using `mocha`. \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..440d96c --- /dev/null +++ b/test.js @@ -0,0 +1,51 @@ +var path = require("path"), + jsdom = require("jsdom"), + should = require("should"); + +describe('Phylotree', function(){ + + before(function(done){ + jsdom.env({ + file: path.join(__dirname, "index.html"), + features: { + FetchExternalResources: ["script"], + ProcessExternalResources: ["script"] + }, + done: function(err, window){ + global.window = window; + global.tree = window.tree; + done(); + } + }); + }); + + it('Create an instance of a tree.', function(){ + window.should.have.properties('tree'); + }); + + it('Equal scaling factor when invoking spacing functions.', function(){ + function is_leaf(node){ return node.name && node.name != 'root';} + var original_spacing = tree.spacing_y(), + original_ys = {}, + scaling_factor = 0, + scaled_coordinates; + + tree.get_nodes().forEach(function(node) { + if(is_leaf(node)) original_ys[node.name] = node.y + }); + + tree.spacing_y(original_spacing/2).update(); + tree.get_nodes().forEach(node => { + if(is_leaf(node) && !scaling_factor){ + scaling_factor = original_ys[node.name]/node.y; + scaling_factor.should.not.be.approximately(1, 1e-1); + } + if(is_leaf(node)){ + rescaled_y = scaling_factor*node.y; + original_y = original_ys[node.name]; + rescaled_y.should.be.approximately(original_y, 1e-8); + } + }); + }); + +});