tnt.tree
Version:
TnT tree display
1 lines • 28.8 kB
JavaScript
!function t(e,n,r){function i(o,l){if(!n[o]){if(!e[o]){var u="function"==typeof require&&require;if(!l&&u)return u(o,!0);if(a)return a(o,!0);throw new Error("Cannot find module '"+o+"'")}var c=n[o]={exports:{}};e[o][0].call(c.exports,function(t){var n=e[o][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[o].exports}for(var a="function"==typeof require&&require,o=0;o<r.length;o++)i(r[o]);return i}({1:[function(t,e,n){"undefined"==typeof tnt&&(e.exports=tnt={}),tnt.tree=t("./index.js"),tnt.tree.node=t("tnt.tree.node"),tnt.tree.parse_newick=t("tnt.newick").parse_newick,tnt.tree.parse_nhx=t("tnt.newick").parse_nhx},{"./index.js":2,"tnt.newick":8,"tnt.tree.node":10}],2:[function(t,e,n){e.exports=tree=t("./src/index.js");var r=t("biojs-events");r.mixin(tree)},{"./src/index.js":17,"biojs-events":3}],3:[function(t,e,n){var r=t("backbone-events-standalone");r.onAll=function(t,e){return this.on("all",t,e),this},r.oldMixin=r.mixin,r.mixin=function(t){r.oldMixin(t);for(var e=["onAll"],n=0;n<e.length;n++){var i=e[n];t[i]=this[i]}return t},e.exports=r},{"backbone-events-standalone":5}],4:[function(t,e,n){!function(){function t(){return{keys:Object.keys||function(t){if("object"!=typeof t&&"function"!=typeof t||null===t)throw new TypeError("keys() called on a non-object");var e,n=[];for(e in t)t.hasOwnProperty(e)&&(n[n.length]=e);return n},uniqueId:function(t){var e=++u+"";return t?t+e:e},has:function(t,e){return o.call(t,e)},each:function(t,e,n){if(null!=t)if(a&&t.forEach===a)t.forEach(e,n);else if(t.length===+t.length)for(var r=0,i=t.length;i>r;r++)e.call(n,t[r],r,t);else for(var o in t)this.has(t,o)&&e.call(n,t[o],o,t)},once:function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}}}}var r,i=this,a=Array.prototype.forEach,o=Object.prototype.hasOwnProperty,l=Array.prototype.slice,u=0,c=t();r={on:function(t,e,n){if(!d(this,"on",t,[e,n])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);return r.push({callback:e,context:n,ctx:n||this}),this},once:function(t,e,n){if(!d(this,"once",t,[e,n])||!e)return this;var r=this,i=c.once(function(){r.off(t,i),e.apply(this,arguments)});return i._callback=e,this.on(t,i,n)},off:function(t,e,n){var r,i,a,o,l,u,s,f;if(!this._events||!d(this,"off",t,[e,n]))return this;if(!t&&!e&&!n)return this._events={},this;for(o=t?[t]:c.keys(this._events),l=0,u=o.length;u>l;l++)if(t=o[l],a=this._events[t]){if(this._events[t]=r=[],e||n)for(s=0,f=a.length;f>s;s++)i=a[s],(e&&e!==i.callback&&e!==i.callback._callback||n&&n!==i.context)&&r.push(i);r.length||delete this._events[t]}return this},trigger:function(t){if(!this._events)return this;var e=l.call(arguments,1);if(!d(this,"trigger",t,e))return this;var n=this._events[t],r=this._events.all;return n&&f(n,e),r&&f(r,arguments),this},stopListening:function(t,e,n){var r=this._listeners;if(!r)return this;var i=!e&&!n;"object"==typeof e&&(n=this),t&&((r={})[t._listenerId]=t);for(var a in r)r[a].off(e,n,this),i&&delete this._listeners[a];return this}};var s=/\s+/,d=function(t,e,n,r){if(!n)return!0;if("object"==typeof n){for(var i in n)t[e].apply(t,[i,n[i]].concat(r));return!1}if(s.test(n)){for(var a=n.split(s),o=0,l=a.length;l>o;o++)t[e].apply(t,[a[o]].concat(r));return!1}return!0},f=function(t,e){var n,r=-1,i=t.length,a=e[0],o=e[1],l=e[2];switch(e.length){case 0:for(;++r<i;)(n=t[r]).callback.call(n.ctx);return;case 1:for(;++r<i;)(n=t[r]).callback.call(n.ctx,a);return;case 2:for(;++r<i;)(n=t[r]).callback.call(n.ctx,a,o);return;case 3:for(;++r<i;)(n=t[r]).callback.call(n.ctx,a,o,l);return;default:for(;++r<i;)(n=t[r]).callback.apply(n.ctx,e)}},h={listenTo:"on",listenToOnce:"once"};c.each(h,function(t,e){r[e]=function(e,n,r){var i=this._listeners||(this._listeners={}),a=e._listenerId||(e._listenerId=c.uniqueId("l"));return i[a]=e,"object"==typeof n&&(r=this),e[t](n,r,this),this}}),r.bind=r.on,r.unbind=r.off,r.mixin=function(t){var e=["on","once","off","trigger","stopListening","listenTo","listenToOnce","bind","unbind"];return c.each(e,function(e){t[e]=this[e]},this),t},"undefined"!=typeof n?("undefined"!=typeof e&&e.exports&&(n=e.exports=r),n.BackboneEvents=r):"function"==typeof define&&"object"==typeof define.amd?define(function(){return r}):i.BackboneEvents=r}(this)},{}],5:[function(t,e,n){e.exports=t("./backbone-events-standalone")},{"./backbone-events-standalone":4}],6:[function(t,e,n){e.exports=t("./src/api.js")},{"./src/api.js":7}],7:[function(t,e,n){var r=function(t){var e=function(){var t=[];return t.add_batch=function(e){t.unshift(e)},t.update=function(e,n){for(var r=0;r<t.length;r++)for(var i in t[r])if(i===e)return t[r][i]=n,!0;return!1},t.add=function(e,n){if(t.update(e,n));else{var r={};r[e]=n,t.add_batch(r)}},t.get=function(e){for(var n=0;n<t.length;n++)for(var r in t[n])if(r===e)return t[n][r]},t},n=e(),r=function(){};r.check=function(e,n,i){if(!(e instanceof Array))return"function"==typeof e?e.check(n,i):t[e].check(n,i),r;for(var a=0;a<e.length;a++)r.check(e[a],n,i)},r.transform=function(e,n){if(!(e instanceof Array))return"function"==typeof e?e.transform(n):t[e].transform(n),r;for(var i=0;i<e.length;i++)r.transform(e[i],n)};var i=function(e,r){var i=[],a=[],o=r.on_getter||function(){return n.get(e)},l=r.on_setter||function(t){for(var r=0;r<a.length;r++)t=a[r](t);for(var o=0;o<i.length;o++)if(!i[o].check(t)){var l=i[o].msg||"Value "+t+" doesn't seem to be valid for this method";throw l}n.add(e,t)},u=function(e){return arguments.length?(l(e),t):o()};u.check=function(t,e){return arguments.length?(i.push({check:t,msg:e}),this):i},u.transform=function(t){return arguments.length?(a.push(t),this):a},t[e]=u},a=function(t,e){if("object"==typeof t){n.add_batch(t);for(var r in t)i(r,e)}else n.add(t,e.default_value),i(t,e)};return r.getset=function(t,e){return a(t,{default_value:e}),r},r.get=function(t,e){var n=function(){throw"Method defined only as a getter (you are trying to use it as a setter"};return a(t,{default_value:e,on_setter:n}),r},r.set=function(t,e){var n=function(){throw"Method defined only as a setter (you are trying to use it as a getter"};return a(t,{default_value:e,on_getter:n}),r},r.method=function(e,n){if("object"==typeof e)for(var i in e)t[i]=e[i];else t[e]=n;return r},r};e.exports=n=r},{}],8:[function(t,e,n){e.exports=t("./src/newick.js")},{"./src/newick.js":9}],9:[function(t,e,n){e.exports={parse_newick:function(t){for(var e,n=[],r={},i=t.split(/\s*(;|\(|\)|,|:)\s*/),a=0;a<i.length;a++){var o=i[a];switch(o){case"(":e={},r.children=[e],n.push(r),r=e;break;case",":e={},n[n.length-1].children.push(e),r=e;break;case")":r=n.pop();break;case":":break;default:var l=i[a-1];")"==l||"("==l||","==l?r.name=o:":"==l&&(r.branch_length=parseFloat(o))}}return r},parse_nhx:function(t){for(var e,n=[],r={},i=t.split(/\s*(;|\(|\)|\[|\]|,|:|=)\s*/),a=0;a<i.length;a++){var o=i[a];switch(o){case"(":e={},r.children=[e],n.push(r),r=e;break;case",":e={},n[n.length-1].children.push(e),r=e;break;case")":r=n.pop();break;case":":break;default:var l=i[a-1];if(")"==l||"("==l||","==l)r.name=o;else if(":"==l){isNaN(o)||(r.branch_length=parseFloat(o))}else if("="==l){var u=i[a-2];switch(u){case"D":r.duplication=o;break;case"G":r.gene_id=o;break;case"T":r.taxon_id=o;break;default:r[i[a-2]]=o}}else;}}return r}}},{}],10:[function(t,e,n){var r=t("./src/node.js");e.exports=n=r},{"./src/node.js":15}],11:[function(t,e,n){e.exports=t("./src/index.js")},{"./src/index.js":12}],12:[function(t,e,n){var r=t("./utils.js");r.reduce=t("./reduce.js"),e.exports=n=r},{"./reduce.js":13,"./utils.js":14}],13:[function(t,e,n){var r=function(){var t=5,e="val",n=function(t,e){return e>t?.2*e>=e-t:.2*t>=t-e},r=function(t){return t},i=function(t){if(!t.length)return t;var e=l(t),n=r(e);return n},a=function(t,n){if(n.sort(function(t,n){return t[e]-n[e]}),n.length%2)t[e]=n[~~(n.length/2)][e];else{var r=~~(n.length/2)-1;t[e]=(n[r][e]+n[r+1][e])/2}return t},o=function(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},l=function(e){if(0===t)return e;for(var n=[],r=0;r<e.length;r++){var i=t>r?0:r-t,l=r>e.length-t?e.length:r+t;n[r]=a(o(e[r]),e.slice(i,l+1))}return n};return i.reducer=function(t){return arguments.length?(r=t,i):r},i.redundant=function(t){return arguments.length?(n=t,i):n},i.value=function(t){return arguments.length?(e=t,i):e},i.smooth=function(e){return arguments.length?(t=e,i):t},i},i=function(){var t=r().value("start"),e="end",n=function(n,r){return{object:{start:n.object[t.value()],end:r[e]},value:r[e]}};return t.reducer(function(r){for(var i=t.value(),a=t.redundant(),o=[],l={object:r[0],value:r[0][e]},u=1;u<r.length;u++)a(r[u][i],l.value)?l=n(l,r[u]):(o.push(l.object),l.object=r[u],l.value=r[u].end);return o.push(l.object),o}),r.join=function(e){return arguments.length?(n=e,t):n},r.value2=function(n){return arguments.length?(e=n,t):e},t},a=function(){var t=r();return t.reducer(function(e){for(var n=t.redundant(),r=t.value(),i=[],a=e[0],o=1;o<e.length-1;o++)n(e[o][r],a[r])||(i.push(a),a=e[o]);return i.push(a),i.push(e[e.length-1]),i}),t};e.exports=r,e.exports.line=a,e.exports.block=i},{}],14:[function(t,e,n){e.exports={iterator:function(t){var e=t||0,n=function(){return e++};return n},script_path:function(t){var e=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),n=new RegExp(e+"$"),r=new RegExp("(.*)"+e+"$"),i=document.getElementsByTagName("script"),a="";if(void 0!==i)for(var o in i)if(i[o].src&&i[o].src.match(n))return i[o].src.replace(r,"$1");return a},defer_cancel:function(t,e){var n,r=function(){var r=Array.prototype.slice.call(arguments),i=this;clearTimeout(n),n=setTimeout(function(){t.apply(i,r)},e)};return r}}},{}],15:[function(t,e,n){var r=t("tnt.api"),i=t("tnt.utils").iterator,a=function(t){"use strict";var e=function(){},n=r(e),o=function(t,e){if(e(t),void 0!==t.children)for(var n=0;n<t.children.length;n++)o(t.children[n],e)},l=function(){var e=i(1);o(t,function(t){void 0===t._id&&(t._id=e())})},u=function(t){if(void 0!==t&&void 0!==t.children)for(var e=0;e<t.children.length;e++)t.children[e]._parent=t,u(t.children[e])},c=function(t){o(t,function(t){var e;if(void 0===t._parent)t._root_dist=0;else{var e=0;t.branch_length&&(e=t.branch_length),t._root_dist=e+t._parent._root_dist}})};e.data=function(n){return arguments.length?(t=n,l(),u(t),c(t),e):t},e.data(t),n.method("find_all",function(t,n){var r=[];return e.apply(function(e){t(e)&&r.push(e)}),r}),n.method("find_node",function(n,r){if(n(e))return e;if(void 0!==t.children)for(var i=0;i<t.children.length;i++){var o=a(t.children[i]).find_node(n,r);if(o)return o}if(r&&void 0!==t._children)for(var l=0;l<t._children.length;l++){a(t._children[l]).find_node(n,r);var o=a(t._children[l]).find_node(n,r);if(o)return o}}),n.method("find_node_by_name",function(t,n){return e.find_node(function(e){return e.node_name()===t},n)}),n.method("toggle",function(){if(t)if(t.children){var n=0;e.apply(function(t){t.n_hidden()||0;n+=(t.n_hidden()||0)+1}),e.n_hidden(n-1),t._children=t.children,t.children=void 0}else e.n_hidden(0),t.children=t._children,t._children=void 0;return this}),n.method("is_collapsed",function(){return void 0!==t._children&&void 0===t.children});var s=function(t,e){if(t=t.data(),e=e.data(),void 0===t._parent)return!1;for(t=t._parent;;){if(void 0===t)return!1;if(t===e)return!0;t=t._parent}};n.method("lca",function(t){if(1===t.length)return t[0];for(var e=t[0],n=1;n<t.length;n++)e=d(e,t[n]);return e});var d=function(t,e){return t.data()===e.data()?t:s(t,e)?e:d(t,e.parent())};n.method("n_hidden",function(t){return arguments.length?(e.property("_hidden",t),e):e.property("_hidden")}),n.method("get_all_nodes",function(t){var n=[];return e.apply(function(t){n.push(t)},t),n}),n.method("get_all_leaves",function(t){var n=[];return e.apply(function(e){e.is_leaf(t)&&n.push(e)},t),n}),n.method("upstream",function(t){t(e);var n=e.parent();void 0!==n&&n.upstream(t)}),n.method("subtree",function(e,n){void 0===n&&(n=!1);for(var r={},i=0;i<e.length;i++){var o=e[i];void 0!==o&&o.upstream(function(t){var e=t.id();void 0===r[e]&&(r[e]=0),r[e]++})}var l=function(t){var e=0;if(void 0===t.children)return!1;for(var n=0;n<t.children.length;n++){var i=t.children[n]._id;r[i]>0&&e++}return 1===e},u={};return f(t,u,0,function(t){var e=t._id,i=r[e];return i>0?l(t)&&!n?!1:!0:!1}),a(u.children[0])});var f=function(t,e,n,r){if(void 0!==t)if(r(t)){var i=h(t,n);if(void 0===e.children&&(e.children=[]),e.children.push(i),void 0===t.children)return;for(var a=0;a<t.children.length;a++)f(t.children[a],i,0,r)}else{if(void 0===t.children)return;n+=t.branch_length||0;for(var a=0;a<t.children.length;a++)f(t.children[a],e,n,r)}},h=function(t,e){var n={};for(var r in t)"children"!==r&&"_children"!==r&&"_parent"!==r&&"depth"!==r&&t.hasOwnProperty(r)&&(n[r]=t[r]);return void 0!==n.branch_length&&void 0!==e&&(n.branch_length+=e),n};return n.method("present",function(t){var n=!1;return e.apply(function(e){t(e)===!0&&(n=!0)}),n}),n.method("sort",function(e){if(void 0!==t.children){for(var n=[],r=0;r<t.children.length;r++)n.push(a(t.children[r]));n.sort(e),t.children=[];for(var r=0;r<n.length;r++)t.children.push(n[r].data());for(var r=0;r<t.children.length;r++)a(t.children[r]).sort(e)}}),n.method("flatten",function(t){if(e.is_leaf())return e;var n,r=e.data(),i=h(r);t?(n=e.get_all_nodes(),n.shift()):n=e.get_all_leaves(),i.children=[];for(var o=0;o<n.length;o++)delete n[o].children,i.children.push(h(n[o].data()));return a(i)}),n.method("apply",function(n,r){if(void 0===r&&(r=!1),n(e),void 0!==t.children)for(var i=0;i<t.children.length;i++){var o=a(t.children[i]);o.apply(n,r)}if(void 0!==t._children&&r)for(var l=0;l<t._children.length;l++){var o=a(t._children[l]);o.apply(n,r)}}),n.method("property",function(n,r){return 1===arguments.length?"function"==typeof n?n(t):t[n]:("function"==typeof n&&n(t,r),t[n]=r,e)}),n.method("is_leaf",function(e){return e?void 0===t.children&&void 0===t._children:void 0===t.children}),n.method("id",function(){return e.property("_id")}),n.method("node_name",function(){return e.property("name")}),n.method("branch_length",function(){return e.property("branch_length")}),n.method("root_dist",function(){return e.property("_root_dist")}),n.method("children",function(e){var n=[];if(t.children)for(var r=0;r<t.children.length;r++)n.push(a(t.children[r]));if(t._children&&e)for(var i=0;i<t._children.length;i++)n.push(a(t._children[i]));if(0!==n.length)return n}),n.method("parent",function(){return void 0!==t._parent?a(t._parent):void 0}),e};e.exports=n=a},{"tnt.api":6,"tnt.utils":11}],16:[function(t,e,n){var r=t("tnt.api"),i={};i.diagonal=function(){var t=function(e){var r=e.source,i=e.target,a=((r.x+i.x)/2,(r.y+i.y)/2,[r,{x:i.x,y:r.y},i]);return a=a.map(t.projection()),t.path()(a,n.call(this,a))},e=(r(t).getset("projection").getset("path"),function(t,e){var n,r=2*Math.PI,i=r/4,a=t[0]>=0?t[1]>=0?1:2:t[1]>=0?4:3,o=Math.abs(Math.asin(t[1]/e));switch(a){case 1:n=i-o;break;case 2:n=i+o;break;case 3:n=2*i+i-o;break;case 4:n=3*i+o}return n}),n=function(t){var n=t[0],r=t[1],i=(t[2],Math.sqrt(n[0]*n[0]+n[1]*n[1])),a=e(n,i),o=e(r,i),l=Math.abs(o-a)>Math.PI?a>=o:o>a;return{radius:i,clockwise:l}};return t},i.diagonal.vertical=function(){var t=function(t,e){var n=t[0],r=t[1],i=t[2],a=2e5;return"M"+n+" A"+[a,a]+" 0 0,0 "+r+"M"+r+"L"+i},e=function(t){return[t.y,t.x]};return i.diagonal().path(t).projection(e)},i.diagonal.radial=function(){var t=function(t,e){var n=t[0],r=t[1],i=t[2],a=e.radius,o=e.clockwise;return o?"M"+n+" A"+[a,a]+" 0 0,0 "+r+"M"+r+"L"+i:"M"+r+" A"+[a,a]+" 0 0,0 "+n+"M"+r+"L"+i},e=function(t){var e=t.y,n=(t.x-90)/180*Math.PI;return[e*Math.cos(n),e*Math.sin(n)]};return i.diagonal().path(t).projection(e)},e.exports=n=i.diagonal},{"tnt.api":6}],17:[function(t,e,n){var r=t("./tree.js");r.label=t("./label.js"),r.diagonal=t("./diagonal.js"),r.layout=t("./layout.js"),r.node_display=t("./node_display.js"),e.exports=n=r},{"./diagonal.js":16,"./label.js":18,"./layout.js":19,"./node_display.js":20,"./tree.js":21}],18:[function(t,e,n){var r=t("tnt.api"),i={};i.label=function(){"use strict";var t=d3.dispatch("click","dblclick","mouseover","mouseout"),e=function(n,r,i){if("function"!=typeof n)throw n;e.display().call(this,n,r).attr("class","tnt_tree_label").attr("transform",function(t){var a=e.transform()(n,r);return"translate ("+(a.translate[0]+i)+" "+a.translate[1]+")rotate("+a.rotate+")"}).on("click",function(){t.click.call(this,n)}).on("dblclick",function(){t.dblclick.call(this,n)}).on("mouseover",function(){t.mouseover.call(this,n)}).on("mouseout",function(){t.mouseout.call(this,n)})};r(e).getset("width",function(){throw"Need a width callback"}).getset("height",function(){throw"Need a height callback"}).getset("display",function(){throw"Need a display callback"}).getset("transform",function(){throw"Need a transform callback"});return d3.rebind(e,t,"on")},i.label.text=function(){var t=i.label();r(t).getset("fontsize",10).getset("fontweight","normal").getset("color","#000").getset("text",function(t){return t.data().name});return t.display(function(e,n){var r=d3.select(this).append("text").attr("text-anchor",function(t){return"radial"===n?t.x%360<180?"start":"end":"start"}).text(function(){return t.text()(e)}).style("font-size",function(){return d3.functor(t.fontsize())(e)+"px"}).style("font-weight",function(){return d3.functor(t.fontweight())(e)}).style("fill",d3.functor(t.color())(e));return r}),t.transform(function(e,n){var r=e.data(),i={translate:[5,5],rotate:0};return"radial"===n&&(i.translate[1]=i.translate[1]-(r.x%360<180?0:t.fontsize()),i.rotate=r.x%360<180?0:180),i}),t.width(function(e){var n=d3.select("body").append("svg").attr("height",0).style("visibility","hidden"),r=n.append("text").style("font-size",d3.functor(t.fontsize())(e)+"px").text(t.text()(e)),i=r.node().getBBox().width;return n.remove(),i}),t.height(function(e){return d3.functor(t.fontsize())(e)}),t},i.label.img=function(){var t=i.label();r(t).getset("src",function(){});return t.display(function(e,n){if(t.src()(e)){var r=d3.select(this).append("image").attr("width",t.width()()).attr("height",t.height()()).attr("xlink:href",t.src()(e));return r}return d3.select(this).append("text").text("")}),t.transform(function(e,n){var r=e.data(),i={translate:[10,-t.height()()/2],rotate:0};return"radial"===n&&(i.translate[0]=i.translate[0]+(r.x%360<180?0:t.width()()),i.translate[1]=i.translate[1]+(r.x%360<180?0:t.height()()),i.rotate=r.x%360<180?0:180),i}),t},i.label.composite=function(){var t=[],e=function(e,n,r){for(var i=0,a=0;a<t.length;a++){var o=t[a];!function(t){o.transform(function(e,n){var r=o._super_.transform()(e,n),i={translate:[t+r.translate[0],r.translate[1]],rotate:r.rotate};return i})}(i),i+=10,i+=o.width()(e),o.call(this,e,n,r)}},n=r(e);return n.method("add_label",function(n,i){return n._super_={},r(n._super_).get("transform",n.transform()),t.push(n),e}),n.method("width",function(){return function(e){for(var n=0,r=0;r<t.length;r++)n+=parseInt(t[r].width()(e)),n+=parseInt(t[r]._super_.transform()(e).translate[0]);return n}}),n.method("height",function(){return function(e){for(var n=0,r=0;r<t.length;r++){var i=t[r].height()(e);i>n&&(n=i)}return n}}),e},e.exports=n=i.label},{"tnt.api":6}],19:[function(t,e,n){var r=t("tnt.api"),i=t("./diagonal.js"),a={};a.layout=function(){var t=function(){},e=d3.layout.cluster().sort(null).value(function(t){return t.length}).separation(function(){return 1}),n=r(t).getset("scale",!0).getset("max_leaf_label_width",0).method("cluster",e).method("yscale",function(){throw"yscale is not defined in the base object"}).method("adjust_cluster_size",function(){throw"adjust_cluster_size is not defined in the base object"}).method("width",function(){throw"width is not defined in the base object"}).method("height",function(){throw"height is not defined in the base object"});return n.method("scale_branch_lengths",function(e){if(t.scale()!==!1){var n=e.nodes,r=e.tree,i=n.map(function(t){return t._root_dist}),a=t.yscale(i);r.apply(function(t){t.property("y",a(t.root_dist()))})}}),t},a.layout.vertical=function(){var t=a.layout();t.type="vertical";var e=r(t).getset("width",360).get("translate_vis",[20,20]).method("diagonal",i.vertical).method("transform_node",function(t){return"translate("+t.y+","+t.x+")"});return e.method("height",function(t){return t.n_leaves*t.label_height}),e.method("yscale",function(e){return d3.scale.linear().domain([0,d3.max(e)]).range([0,t.width()-20-t.max_leaf_label_width()])}),e.method("adjust_cluster_size",function(e){var n=t.height(e),r=t.width()-t.max_leaf_label_width()-t.translate_vis()[0]-e.label_padding;return t.cluster.size([n,r]),t}),t},a.layout.radial=function(){var t=a.layout();t.type="radial";var e=360,n=e/2,o={width:360},l=r(t).getset(o).getset("translate_vis",[n,n]).method("transform_node",function(t){return"rotate("+(t.x-90)+")translate("+t.y+")"}).method("diagonal",i.radial).method("height",function(){return o.width});return t.width.transform(function(e){return n=e/2,t.cluster.size([360,n]),t.translate_vis([n,n]),e}),l.method("yscale",function(t){return d3.scale.linear().domain([0,d3.max(t)]).range([0,n])}),l.method("adjust_cluster_size",function(e){return n=t.width()/2-t.max_leaf_label_width()-20,t.cluster.size([360,n]),t}),t},e.exports=n=a.layout},{"./diagonal.js":16,"tnt.api":6}],20:[function(t,e,n){var r=t("tnt.api"),i={};i.node_display=function(){"use strict";var t=function(e){var n,r=d3.select(this).select(".tnt_tree_node_proxy");if(null===r[0][0]){d3.functor(t.size())(e);n=d3.select(this).append("rect").attr("class","tnt_tree_node_proxy")}else n=r;t.display().call(this,e);var i=this.getBBox();n.attr("x",i.x).attr("y",i.y).attr("width",i.width).attr("height",i.height)},e=r(t).getset("size",4.4).getset("fill","black").getset("stroke","black").getset("stroke_width","1px").getset("display",function(){throw"display is not defined in the base object"});return e.method("reset",function(){d3.select(this).selectAll("*:not(.tnt_tree_node_proxy)").remove()}),t},i.node_display.circle=function(){var t=i.node_display();return t.display(function(e){d3.select(this).append("circle").attr("r",function(n){return d3.functor(t.size())(e)}).attr("fill",function(n){return d3.functor(t.fill())(e)}).attr("stroke",function(n){return d3.functor(t.stroke())(e)}).attr("stroke-width",function(n){return d3.functor(t.stroke_width())(e)}).attr("class","tnt_node_display_elem")}),t},i.node_display.square=function(){var t=i.node_display();return t.display(function(e){var n=d3.functor(t.size())(e);d3.select(this).append("rect").attr("x",function(t){return-n}).attr("y",function(t){return-n}).attr("width",function(t){return 2*n}).attr("height",function(t){return 2*n}).attr("fill",function(n){return d3.functor(t.fill())(e)}).attr("stroke",function(n){return d3.functor(t.stroke())(e)}).attr("stroke-width",function(n){return d3.functor(t.stroke_width())(e)}).attr("class","tnt_node_display_elem")}),t},i.node_display.triangle=function(){var t=i.node_display();return t.display(function(e){var n=d3.functor(t.size())(e);d3.select(this).append("polygon").attr("points",-n+",0 "+n+","+-n+" "+n+","+n).attr("fill",function(n){return d3.functor(t.fill())(e)}).attr("stroke",function(n){return d3.functor(t.stroke())(e)}).attr("stroke-width",function(n){return d3.functor(t.stroke_width())(e)}).attr("class","tnt_node_display_elem")}),t},e.exports=n=i.node_display},{"tnt.api":6}],21:[function(t,e,n){var r=t("tnt.api"),i=t("tnt.tree.node"),a=function(){"use strict";var t,e,n,o,l,u,c=d3.dispatch("click","dblclick","mouseover","mouseout"),s={duration:500,node_display:a.node_display.circle(),label:a.label.text(),layout:a.layout.vertical(),branch_color:"black",id:function(t){return t._id}},d="cubic-in-out",f={tree:void 0,data:void 0,nodes:void 0,links:void 0},h={tree:void 0,data:void 0,nodes:void 0,links:void 0},v=function(t){e=d3.select(t).attr("id");var r=d3.select(t).append("div").style("width",s.layout.width()+"px").attr("class","tnt_groupDiv"),f=s.layout.cluster,_=h.tree.get_all_leaves().length,g=function(t){for(var e=0,n=t.get_all_leaves(),r=0;r<n.length;r++){var i=s.label.width()(n[r])+d3.functor(s.node_display.size())(n[r]);i>e&&(e=i)}return e},y=function(t){for(var e=0,n=t.get_all_leaves(),r=0;r<n.length;r++){var i=2*d3.functor(s.node_display.size())(n[r]),a=d3.functor(s.label.height())(n[r]);e=d3.max([e,i,a])}return e},m=g(h.tree);s.layout.max_leaf_label_width(m);var b=y(h.tree),k={n_leaves:_,label_height:b,label_padding:15};s.layout.adjust_cluster_size(k);var x=s.layout.diagonal(),w=s.layout.transform_node;n=r.append("svg").attr("width",s.layout.width()).attr("height",s.layout.height(k)+30).attr("fill","none"),o=n.append("g").attr("id","tnt_st_"+e).attr("transform","translate("+s.layout.translate_vis()[0]+","+s.layout.translate_vis()[1]+")"),h.nodes=f.nodes(h.data),s.layout.scale_branch_lengths(h),h.links=f.links(h.nodes),l=o.append("g").attr("class","links"),u=o.append("g").attr("class","nodes");var j=l.selectAll("path.tnt_tree_link").data(h.links,function(t){return s.id(t.target)});j.enter().append("path").attr("class","tnt_tree_link").attr("id",function(t){return"tnt_tree_link_"+e+"_"+s.id(t.target)}).style("stroke",function(t){return d3.functor(s.branch_color)(i(t.source),i(t.target))}).attr("d",x);var z=u.selectAll("g.tnt_tree_node").data(h.nodes,function(t){return s.id(t)}),M=z.enter().append("g").attr("class",function(t){return t.children?0===t.depth?"root tnt_tree_node":"inner tnt_tree_node":"leaf tnt_tree_node"}).attr("id",function(t){return"tnt_tree_node_"+e+"_"+t._id}).attr("transform",w);M.each(function(t){s.node_display.call(this,i(t))}),M.each(function(t){s.label.call(this,i(t),s.layout.type,d3.functor(s.node_display.size())(i(t)))}),M.on("click",function(t){var e=i(t);a.trigger("node:click",e),c.click.call(this,e)}),M.on("dblclick",function(t){var e=i(t);a.trigger("node:dblclick",e),c.dblclick.call(this,e)}),M.on("mouseover",function(t){var e=i(t);a.trigger("node:hover",i(t)),c.mouseover.call(this,e)}),M.on("mouseout",function(t){var e=i(t);a.trigger("node:mouseout",i(t)),c.mouseout.call(this,e)}),p.method("update",function(){r.style("width",s.layout.width()+"px"),n.attr("width",s.layout.width());var t=s.layout.cluster,f=s.layout.diagonal(),p=s.layout.transform_node,_=g(h.tree);s.layout.max_leaf_label_width(_);var m=y(h.tree),b=h.tree.get_all_leaves().length,k={n_leaves:b,label_height:m,label_padding:15};s.layout.adjust_cluster_size(k),n.transition().duration(s.duration).ease(d).attr("height",s.layout.height(k)+30),o.transition().duration(s.duration).attr("transform","translate("+s.layout.translate_vis()[0]+","+s.layout.translate_vis()[1]+")"),h.nodes=t.nodes(h.data),s.layout.scale_branch_lengths(h),h.links=t.links(h.nodes);var x=l.selectAll("path.tnt_tree_link").data(h.links,function(t){return s.id(t.target)}),w=u.selectAll("g.tnt_tree_node").data(h.nodes,function(t){return s.id(t)});x.exit().remove();x.enter().append("path").attr("class","tnt_tree_link").attr("id",function(t){return"tnt_tree_link_"+e+"_"+s.id(t.target)}).attr("stroke",function(t){return d3.functor(s.branch_color)(i(t.source),i(t.target))}).attr("d",f),x.transition().ease(d).duration(s.duration).attr("d",f);var j=w.enter().append("g").attr("class",function(t){return t.children?0===t.depth?"root tnt_tree_node":"inner tnt_tree_node":"leaf tnt_tree_node"}).attr("id",function(t){return"tnt_tree_node_"+e+"_"+t._id}).attr("transform",p);w.exit().remove(),j.on("click",function(t){var e=i(t);a.trigger("node:click",e),c.click.call(this,e)}),j.on("dblclick",function(t){var e=i(t);a.trigger("node:dblclick",e),c.dblclick.call(this,e)}),j.on("mouseover",function(t){var e=i(t);a.trigger("node:hover",i(t)),c.mouseover.call(this,e)}),j.on("mouseout",function(t){var e=i(t);a.trigger("node:mouseout",i(t)),c.mouseout.call(this,e)}),v.update_nodes(),w.transition().ease(d).duration(s.duration).attr("transform",p)}),p.method("update_nodes",function(){var t=u.selectAll("g.tnt_tree_node");t.each(function(){s.node_display.reset.call(this)}),t.each(function(t){s.node_display.call(this,i(t))}),t.each(function(t){s.label.call(this,i(t),s.layout.type,d3.functor(s.node_display.size())(i(t)))})})},p=r(v).getset(s);return p.method("data",function(t){if(!arguments.length)return f.data;f.data=t,h.data=t;var e=i(f.data);return v.root(e),a.trigger("data:hasChanged",f.data),this}),p.method("root",function(t){return arguments.length?(f.tree=t,h.tree=f.tree,this):h.tree}),p.method("subtree",function(t,e){var n=f.tree.subtree(t,e);return h.data=n.data(),h.tree=n,this}),p.method("focus_node",function(e,n){var r=v.root().find_node(function(t){return e.id()===t.id()});return t=r,v.subtree(r.get_all_leaves(),n),this}),p.method("has_focus",function(e){return void 0!==t&&t.id()===e.id()}),p.method("release_focus",function(){return v.data(f.data),t=void 0,this}),d3.rebind(v,c,"on")};e.exports=n=a},{"tnt.api":6,"tnt.tree.node":10}]},{},[1]);