{"size": 57208, "ext": "js", "max_stars_repo_path": "mtm.min.js", "max_stars_repo_name": "talinwind/MetaTreeMap", "max_stars_repo_stars_event_min_datetime": "2016-08-08T02:45:40.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-08T02:45:40.000Z", "max_issues_repo_path": "mtm.min.js", "max_issues_repo_name": "talinwind/MetaTreeMap", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mtm.min.js", "max_forks_repo_name": "talinwind/MetaTreeMap", "max_forks_repo_forks_event_min_datetime": "2018-06-02T23:18:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-02T23:18:17.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 9534.6666666667, "max_line_length": 56998, "alphanum_fraction": 0.6743112851}
/*
MetaTreeMap Copyright (c) 2015-2016, Maxime HEBRARD for Laboratory for Integrated Bioinformatics, RIKEN, Japan.
All rights reserved.
see: https://github.com/mhebrard/MetaTreeMap/LICENSE for full details.
*/
!function(){function E(e){return new Promise(function(t){var n=document.createElement("script");n.type="text/javascript",n.src=e,n.onload=function(){return t(e+" loaded")},document.getElementById("mtm-mods").appendChild(n)})}function S(e,t){return new Promise(function(n){var r=document.createElement("link");r.rel="stylesheet",r.href=e,r.crossorigin="anonymous",t&&(r.id=t),r.onload=function(){return n(e+" loaded")},document.getElementById("mtm-mods").appendChild(r)})}function x(e){return new Promise(function(t){if(!e)return n?t("current config use"):(n={treemap:{display:!0,width:700,height:500},table:{display:!0,width:700,height:500},options:{hierarchy:"rugged",zoom:"fluid",proportion:"sample",cutoff_rank:"genus",colored:"taxon",colored_rank:"init",upper:"colored",palette:"brewer",background:"black",labelled:"taxon",labelled_rank:"init",pattern:"#N ##S",font:14}},t("default config loaded"));d3.json(e.data,function(e){return n=e,t("config file loaded")})})}function T(e){d3.select("#mtm-samples").text("");var t=d3.select("#mtm-samples").append("ul").attr("class","list-unstyled"),n=[],s=[],u=Promise.resolve(n);if(!e||e.length==0)u=u.then(function(){return Promise.reject(new Error("no data file"))});else{r={name:"root",children:[],data:{hits:0,rank:"no rank",sample:0,color:"#ccc"},id:"1"},i=[r.id],o=[r];for(var a=0;a<e.length;a++)e[a].name?(t.append("li").text("#"+(a+1)+"."+e[a].name.replace(/\.[^/.]+$/,"")),s.push(e[a].data)):(t.append("li").text("#"+(a+1)+"."+e[a].replace(/\.[^/.]+$/,"").replace(/.*\//,"")),s.push(e[a]));s.forEach(function(e,t){u=u.then(function(n){return N(e,t,n)})}),u=u.then(function(e){return e})}return u}function N(e,t,n){return new Promise(function(r){d3.json(e,function(e){return n[t+1]=e.data.sum,C(e,"",t+1),r(n)})})}function C(e,n,r){e.id=(""+e.id).replace(/\s+/g,"_"),e.data.rank=="no rank"&&n!=""&&(e.data.rank=n.data.rank);var s,u=i.indexOf(e.id);if(u>-1){s=o[u];if(n!=""&&t.indexOf(n.data.rank)>t.indexOf(s.parent.data.rank)){s.parent.children.splice(s.parent.children.indexOf(s),1);var a=o[i.indexOf(n.id)];a.children.push(s)}}else{var a=o[i.indexOf(n.id)];s={name:e.name,children:[],parent:a,data:{hits:0,rank:e.data.rank,sample:0},id:e.id},a.children.push(s),i.push(s.id),o.push(s)}if(e.data.assigned!="0"){var f={name:e.name,children:[],data:{hits:+e.data.assigned,rank:e.data.rank,sample:r,percent:+e.data.assigned*100/v[r]},id:e.id};s.children.push(f)}if(e.children.length>0)for(var l in e.children)C(e.children[l],e,r,v)}function k(e,t){e.data.count=t.map(function(e){return 0});if(e.children.length>0)for(var n in e.children){var r=k(e.children[n],t);for(var i in r)e.data.count[i]+=r[i]}return e.data.count[e.data.sample]+=e.data.hits,e.data.hits=e.data.count.reduce(function(e,t){return e+t},0),e.data.percent=+e.data.hits*100/t[e.data.sample],e.data.count}function L(){return new Promise(function(e){var t=[];t=["rugged","flat"],t.indexOf(n.options.hierarchy)==0?n.options.hierarchy=!0:t.indexOf(n.options.hierarchy)==1&&(n.options.hierarchy=!1),t=["fluid","sticky"],t.indexOf(n.options.zoom)==0?n.options.zoom=!0:t.indexOf(n.options.zoom)==1&&(n.options.zoom=!1),t=["sample","hits","taxon"],t.indexOf(n.options.proportion)<0&&alert("please set config.options.proportion: "+t.toString()),t=["taxon","rank","sample","majority"],t.indexOf(n.options.colored)<0&&alert("please set config.options.colored: "+t.toString()),t=["colored","grayed"],t.indexOf(n.options.upper)==0?n.options.upper=!0:t.indexOf(n.options.upper)==1&&(n.options.upper=!1),t=["brewer","d3"],t.indexOf(n.options.palette)==0?n.options.palette=p[0][1]:t.indexOf(n.options.palette)==1&&(n.options.palette=p[1][1]),t=["black","white"],t.indexOf(n.options.background)==0?n.options.background=!0:t.indexOf(n.options.background)==1&&(n.options.background=!1),t=["taxon","rank","no"],t.indexOf(n.options.labelled)<0&&alert("please set config.options.labelled: "+t.toString()),e("Config checked")})}function A(){return new Promise(function(e){if(!d3.select("#mtm-mods").attr("data-hidden")){var t=d3.select("#mtm-mods").attr("data-hidden",!0);t.append("style").attr("type","text/css").text("<!--	#mtm-tip{position:absolute;z-index:3;background-color:#888;border:1px solid #000;border-radius:.2em;padding:3px;white-space:nowrap;font-family:'Source Code Pro','Lucida Console',Monaco,monospace;font-size:14px;pointer-events:none;opacity:0}\n.mtm-table table{border-collapse:collapse;width:100%;}\n.mtm-menu button{font-size:14px !important;}\n.mtm-menu .dropdown {float:left;margin-left:4px;}\n.mtm-menu .dropdown .form-control {display:inline-flex !important;}\n.mtm-menu .dropdown .input-group {display:inline-flex !important;}\n.mtm-menu .dropdown .input-group-addon {width:auto !important;}\n.mtm-table td,th {padding:0px 0px 0px 5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}\n	-->"),t.append("div").attr("id","mtm-tip"),t.append("div").attr("id","mtm-canvas").style("display","none"),t.append("div").attr("id","mtm-samples").style("display","none");var r=t.append("div").attr("id","mtm-modal").attr("class","modal fade").append("div").attr("class","modal-dialog").append("div").attr("class","modal-content"),i=r.append("div").attr("class","modal-header");i.append("button").attr("class","close").attr("type","button").attr("data-dismiss","modal").append("span").html("&times;"),i.append("h4").attr("class","modal-title").attr("id","mtm-modal-title");var s=r.append("div").attr("class","modal-body").attr("id","mtm-modal-body")}d3.selectAll(".mtm-menu").html(""),d3.selectAll(".mtm-treemap").html(""),d3.selectAll(".mtm-table").html(""),u=!1,a=!1,I(),n.table.display&&R(),n.treemap.display&&q(),e("Layout ready")})}function O(){f=r,_(r),M(),l=rt(r,[]),J(),n.table.display&&(u?K(u):K(r)),n.treemap.display&&n.options.zoom&&(a=n.options.cutoff_rank!="init"?u:r);var e=l.reduce(function(e,t){return e.indexOf(t.id)<0&&e.push(t.id),e},[]);h=d3.scale.ordinal().range(n.options.palette.split(/\s*,\s*/)).domain(e),u?nt(u):nt(r),Q()}function M(){if(n.options.cutoff_rank!="init"){var e=t.indexOf(n.options.cutoff_rank),i=t.indexOf(f.data.rank);e<=i&&(i++,n.options.cutoff_rank=t[i],d3.select("#mtm-bar-cutoff").node().value=n.options.cutoff_rank,e=i),u=D(e,r,r),_(u);var s=c.nodes().filter(function(e){return e.id==f.id&&e.data.sample==f.data.sample});f=s[0]}else u=!1}function _(e){n.treemap.display&&(v=+n.treemap.height-20,d=+n.treemap.width),c=d3.layout.treemap().size([d,v]).round(!1).sticky(!0).padding(function(){return n.options.hierarchy?2:0}).value(H(n.options.proportion));var t=c.nodes(e);m=d3.scale.linear().range([0,d]),g=d3.scale.linear().range([0,v])}function D(e,n,r){var i={name:r.name,children:[],data:{hits:+r.data.hits,rank:r.data.rank,sample:r.data.sample,percent:r.data.percent,color:r.data.color,count:r.data.count.slice(0)},id:r.id};if(t.indexOf(r.data.rank)==e)P(i,n,r.data.count);else{var s=r.data.count.map(function(e){return 0});if(r.children&&r.children.length>0){for(var o in r.children)if(r.children[o].data.sample==0){var u=t.indexOf(r.children[o].data.rank);u>e?s=s.map(function(e,t){return e+r.children[o].data.count[t]}):i.children.push(D(e,n,r.children[o]))}else s[r.children[o].data.sample]+=r.children[o].data.hits;P(i,n,s)}}return i}function P(e,t,n){for(var r in n)n[r]>0&&e.children.push({name:e.name,id:e.id,children:[],data:{hits:n[r],rank:e.data.rank,sample:r,percent:n[r]*100/t.data.count[r],color:e.data.color,count:e.data.count.map(function(e,t){return t==r?e:0})}})}function H(e){var t;return e=="sample"?t=B:e=="hits"?t=j:e=="taxon"?t=F:(console.log("WARN: unvalide size mode"),t=B),t}function B(e){return e.data.percent}function j(e){return e.data.hits}function F(e){return 1}function I(){var i;i=d3.select(".mtm-menu").style("display","inline-block"),i.empty()&&(i=d3.select("body").append("div").attr("class","mtm-menu").style("display","none")),i.style("width")=="0px"&&i.style("width","100%");var s=i.append("nav").attr("class","navbar navbar-default").append("div").attr("class","container-fluid");list=s.append("div").attr("id","mtm-barmenu"),list.append("div").attr("class","dropdown").append("button").attr("type","button").attr("class","btn btn-default navbar-btn").attr("id","mtm-info").append("span").attr("class","glyphicon glyphicon-info-sign"),$("#mtm-info").popover({html:!0,content:function(){return $("#mtm-samples").html()},title:"Samples:"}),$("#mtm-info").tooltip({placement:"bottom",title:"Click to see sample names"}),$("#mtm-info").on({click:function(){$("#mtm-info").tooltip("hide")}}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-import"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Import <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu").style("width","350px").style("padding","5px"),d=o.append("li").attr("class","form-inline").style("white-space","nowrap").style("overflow","hidden").style("text-overflow","ellipsis"),d.append("label").text("Data File (JSON)").style("width","190px"),v=d.append("label").attr("class","btn btn-default").attr("id","mtm-data-btn").style("width","90px"),v.text("Browse..."),v.append("input").attr("type","file").style("display","none").attr("id","mtm-data-input").attr("name","dataFiles[]").property("multiple",!0).on("change",function(){var e=[];for(var t=0;t<this.files.length;t++)e.push(this.files[t].name);d3.select("#mtm-data-help").text(e.join(","))}),$("#mtm-data-btn").on({click:function(){$("#mtm-bar-import")[0].closable=!1}}),d.append("label").attr("class","help-block small").attr("id","mtm-data-help").style("display","inline"),d=o.append("li").attr("class","form-inline").style("white-space","nowrap").style("overflow","hidden").style("text-overflow","ellipsis"),d.append("label").text("Configuration File (JSON)").style("width","190px"),v=d.append("label").attr("class","btn btn-default").attr("id","mtm-config-btn").style("width","90px"),v.text("Browse..."),v.append("input").attr("type","file").style("display","none").attr("id","mtm-config-input").attr("name","confFiles[]").property("multiple",!0).on("change",function(){var e=[];for(var t=0;t<this.files.length;t++)e.push(this.files[t].name);d3.select("#mtm-config-help").text(e.join(","))}),$("#mtm-config-btn").on({click:function(){$("#mtm-bar-import")[0].closable=!1}}),d.append("label").attr("class","help-block small").attr("id","mtm-config-help").style("display","inline"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","190px"),d.append("button").attr("class","btn btn-primary").attr("type","button").style("width","90px").text("Load").on("click",function(){var t=d3.select("#mtm-data-input").node().files,n=[];for(var r=0;r<t.length;r++)n.push({name:t[r].name,data:URL.createObjectURL(t[r])});var t=d3.select("#mtm-config-input").node().files,i="";t[0]&&(i={name:t[0].name,data:URL.createObjectURL(t[0])}),e.load(n,i)}),d=o.append("li").attr("class","divider"),d=o.append("li").attr("class","form-inline"),d.append("label").text("Convert Data File").style("width","190px"),v=d.append("label").attr("class","btn btn-default").attr("id","mtm-convert").style("width","90px").attr("data-toggle","modal").attr("data-target","#mtm-modal"),v.text("Format..."),$("#mtm-convert").on({click:function(){$("#mtm-bar-import")[0].closable=!1,W("convert")}}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-colors"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Colors <span class='caret'></span>");var o=item.append("ul").attr("class","dropdown-menu").style("width","300px").style("padding","5px"),d=o.append("li").attr("class","form-inline");d.append("label").style("width","120px").text("Color By");var v=d.append("select").attr("class","form-control").attr("id","mtm-bar-colored").style("width","120px");v.append("option").attr("value","taxon").text("Taxon"),v.append("option").attr("value","rank").text("Rank"),v.append("option").attr("value","sample").text("Sample"),v.append("option").attr("value","majority").text("Majority"),v.property("value",n.options.colored),v.on("change",function(){n.options.colored=this.value,d3.select("#mtm-bar-colored-block").classed("in",function(){return n.options.colored=="rank"?!0:!1}),Q()}),$("#mtm-bar-colored").on({click:function(){$("#mtm-bar-colors")[0].closable=!1}}),d=o.append("li").attr("class","collapse").attr("id","mtm-bar-colored-block");var m=d.append("div").attr("class","form-inline");m.append("label").style("width","120px").text("Phylogenic Rank"),v=m.append("select").style("width","160px").attr("class","form-control").attr("id","mtm-bar-colored-rank"),v.append("option").attr("value","init").text("Select...");for(var g in t)v.append("option").attr("value",t[g]).text(t[g]);v.property("value",n.options.colored_rank),v.on("change",function(){n.options.colored_rank=this.value,Q()}),$("#mtm-bar-colored-rank").on({click:function(){$("#mtm-bar-colors")[0].closable=!1}}),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","120px").text("Upper Ranks"),m.append("input").attr("type","checkbox").attr("id","mtm-bar-upper").attr("data-toggle","toggle").attr("data-on","colored").attr("data-off","grayed").attr("data-width","80").property("checked",function(){return n.options.upper}),$("#mtm-bar-upper").on({change:function(){$("#mtm-bar-colors")[0].closable=!1,n.options.upper=d3.select("#mtm-bar-upper").property("checked"),Q()}}),d=o.append("li").attr("class","divider"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Palette"),v=d.append("select").attr("class","form-control").attr("id","mtm-bar-palette").style("width","120px");for(var g in p)v.append("option").attr("value",p[g][1]).text(p[g][0]);v.property("value",n.options.palette),v.on("change",function(){n.options.palette=this.value,h=d3.scale.ordinal().range(n.options.palette.split(/\s*,\s*/)),Q()}),$("#mtm-bar-palette").on({click:function(){$("#mtm-bar-colors")[0].closable=!1}}),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Background"),d.append("input").attr("type","checkbox").attr("id","mtm-bar-background").attr("data-toggle","toggle").attr("data-on","black").attr("data-off","white").attr("data-width","80").property("checked",function(){return n.options.background}),$("#mtm-bar-background").on({change:function(){$("#mtm-bar-colors")[0].closable=!1,n.options.background=d3.select("#mtm-bar-background").property("checked"),d3.selectAll(".mtm-bg").attr("fill",function(){return n.options.background?"#000":"#FFF"}),d3.selectAll(".mtm-header rect").style("stroke",function(){return n.options.background?"#000":"#FFF"}),d3.selectAll(".mtm-view rect").style("stroke",function(){return n.options.background?"#000":"#FFF"}),d3.select(".mtm-table").style("background-color",function(){return n.options.background?"#000":"#FFF"})}}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-labels"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Labels <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu").style("width","300px").style("padding","5px"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Label By"),v=d.append("select").attr("class","form-control").attr("id","mtm-bar-labelled").style("width","120px"),v.append("option").attr("value","taxon").text("Taxon"),v.append("option").attr("value","rank").text("Rank"),v.append("option").attr("value","no").text("No Label"),v.property("value",n.options.labelled),v.on("change",function(){n.options.labelled=this.value,d3.select("#mtm-bar-labelled-block").classed("in",function(){return n.options.labelled=="rank"?!0:!1}),V(f)}),$("#mtm-bar-labelled").on({click:function(){$("#mtm-bar-labels")[0].closable=!1}}),d=o.append("li").attr("class","collapse").attr("id","mtm-bar-labelled-block"),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","120px").text("Phylogenic Rank"),v=m.append("select").style("width","160px").attr("class","form-control").attr("id","mtm-bar-labelled-rank"),v.append("option").attr("value","init").text("Select...");for(var g in t)v.append("option").attr("value",t[g]).text(t[g]);v.property("value",n.options.labelled_rank),v.on("change",function(){n.options.labelled_rank=this.value,V(f)}),$("#mtm-bar-labelled-rank").on({click:function(){$("#mtm-bar-labels")[0].closable=!1}}),d=o.append("li").attr("class","divider"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Font Size"),v=d.append("select").attr("class","form-control").attr("id","mtm-bar-font").style("width","120px");for(var y=8;y<40;y+=2)v.append("option").attr("value",y).text(y);v.property("value",n.options.font),v.on("change",function(){n.options.font=this.value,d3.selectAll(".mtm").style("font-size",n.options.font+"px"),d3.select("#mtm-tip").style("font-size",n.options.font+"px"),V(f)}),$("#mtm-bar-font").on({click:function(){$("#mtm-bar-labels")[0].closable=!1}}),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Label Format"),d.append("input").attr("type","text").style("width","120px").attr("class","form-control").attr("id","mtm-bar-pattern").attr("value",n.options.pattern).on("change",function(){n.options.pattern=this.value,V(f)}),$("#mtm-bar-pattern").on({click:function(){$("#mtm-bar-labels")[0].closable=!1}}),d=o.append("li"),d.append("label").style("width","120px").text("Formatting Tags:"),d.append("label").text("#N:"),d.append("span").text("Taxon Name"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#I:"),d.append("span").text("NCBI Taxonomy ID"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#H:"),d.append("span").text("Number Of Hits"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#R:"),d.append("span").text("Phylogenic Rank"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#S:"),d.append("span").text("Sample Number"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#P:"),d.append("span").text("% By Sample"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("#V:"),d.append("span").text("% By View"),d=o.append("li"),d.append("label").style("width","120px"),d.append("label").text("\\\\:"),d.append("span").text("Break line"),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-treemap"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Treemap <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu").style("width","300px").style("padding","5px"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Hierarchy"),d.append("input").attr("type","checkbox").attr("id","mtm-bar-hierarchy").attr("data-toggle","toggle").attr("data-on","rugged").attr("data-off","flat").attr("data-width","80").property("checked",function(){return n.options.hierarchy}),$("#mtm-bar-hierarchy").on({change:function(){$("#mtm-bar-treemap")[0].closable=!1,n.options.hierarchy=d3.select("#mtm-bar-hierarchy").property("checked"),c.padding(function(){return n.options.hierarchy?2:0}),u?c.nodes(u):c.nodes(r),nt(f)}}),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Zoom Transition"),d.append("input").attr("type","checkbox").attr("id","mtm-bar-zoom").attr("data-toggle","toggle").attr("data-on","fluid").attr("data-off","sticky").attr("data-width","80").property("checked",function(){return n.options.zoom}),$("#mtm-bar-zoom").on({change:function(){$("#mtm-bar-treemap")[0].closable=!1,n.options.zoom=d3.select("#mtm-bar-zoom").property("checked"),n.options.zoom?a=u?u:r:(a=!1,u?_(u):_(r)),nt(f)}}),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Proportion By"),v=d.append("select").attr("class","form-control").attr("id","mtm-bar-proportion").style("width","120px"),v.append("option").attr("value","sample").text("Sample"),v.append("option").attr("value","hits").text("Hits"),v.append("option").attr("value","taxon").text("Taxon"),v.property("value",n.options.proportion),v.on("change",function(){n.options.proportion=this.value,c.value(H(n.options.proportion)),u?c.nodes(u):c.nodes(r),nt(f)}),$("#mtm-bar-proportion").on({click:function(){$("#mtm-bar-treemap")[0].closable=!1}}),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","120px").text("Rank Cutoff:");var v=d.append("select").style("width","160px").attr("class","form-control").attr("id","mtm-bar-cutoff");v.append("option").attr("value","init").text("Select...");for(var g in t)v.append("option").attr("value",t[g]).text(t[g]);v.property("value",n.options.cutoff_rank),v.on("change",function(){n.options.cutoff_rank=this.value,M(),u?K(u):K(r),n.options.zoom&&(a=u?u:r),Q(),nt(f)}),$("#mtm-bar-cutoff").on({click:function(){$("#mtm-bar-treemap")[0].closable=!1}}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-layout"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Layout <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu").style("width","190px").style("padding","5px"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","90px").text("Treemap"),d.append("input").attr("type","checkbox").attr("id","mtm-bar-treemap-display").attr("data-toggle","toggle").attr("data-on","display").attr("data-off","hide").attr("data-width","80").property("checked",function(){return n.treemap.display}),$("#mtm-bar-treemap-display").on({change:function(){$("#mtm-bar-layout")[0].closable=!1,n.treemap.display=d3.select("#mtm-bar-treemap-display").property("checked"),d3.select("#mtm-bar-treemap-block").classed("in",n.treemap.display)}}),d=o.append("li").attr("class","collapse").attr("id","mtm-bar-treemap-block").classed("in",n.treemap.display),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","90px").text("Width (px)"),m.append("input").attr("type","text").style("width","80px").attr("class","form-control").attr("id","mtm-bar-treemap-width").attr("value",n.treemap.width).on("change",function(){n.treemap.width=this.value}),$("#mtm-bar-treemap-width").on({click:function(){$("#mtm-bar-layout")[0].closable=!1}}),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","90px").text("Height (px)"),m.append("input").attr("type","text").style("width","80px").attr("class","form-control").attr("id","mtm-bar-treemap-height").attr("value",n.treemap.height).on("change",function(){n.treemap.height=this.value}),d=o.append("li").attr("class","divider"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","90px").text("Table"),d.append("input").attr("type","checkbox").attr("id","mtm-bar-table-display").attr("data-toggle","toggle").attr("data-on","display").attr("data-off","hide").attr("data-width","80").property("checked",function(){return n.table.display}),$("#mtm-bar-table-display").on({change:function(){$("#mtm-bar-layout")[0].closable=!1,n.table.display=d3.select("#mtm-bar-table-display").property("checked"),d3.select("#mtm-bar-table-block").classed("in",n.table.display)}}),d=o.append("li").attr("class","collapse").attr("id","mtm-bar-table-block").classed("in",n.table.display),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","90px").text("Width (px)"),m.append("input").attr("type","text").style("width","80px").attr("class","form-control").attr("id","mtm-bar-table-width").attr("value",n.table.width).on("change",function(){n.table.width=this.value}),$("#mtm-bar-table-width").on({click:function(){$("#mtm-bar-layout")[0].closable=!1}}),m=d.append("div").attr("class","form-inline"),m.append("label").style("width","90px").text("Height (px)"),m.append("input").attr("type","text").style("width","80px").attr("class","form-control").attr("id","mtm-bar-table-height").attr("value",n.table.height).on("change",function(){n.table.height=this.value}),d=o.append("li").attr("class","divider"),d=o.append("li").attr("class","form-inline"),d.append("label").style("width","90px"),d.append("button").attr("class","btn btn-primary").attr("type","button").style("width","80px").text("Load").on("click",function(){A(),O()}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-export"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("Export <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu"),d=o.append("li").append("a").attr("href","#").text("Data file in JSON format").on("click",function(){return e.save("json")}),d=o.append("li").append("a").attr("href","#").text("Treemap image in SVG format").on("click",function(){return e.save("svg")}),d=o.append("li").append("a").attr("href","#").text("Treemap image in PNG format").on("click",function(){return e.save("png")}),d=o.append("li").append("a").attr("href","#").text("Table data in TSV format").on("click",function(){return e.save("txt")}),d=o.append("li").append("a").attr("href","#").text("Configuration file in JSON format").on("click",function(){return e.save("config")}),item=list.append("div").attr("class","dropdown mtm-dropdown").attr("id","mtm-bar-about"),item.append("button").attr("type","button").attr("data-toggle","dropdown").attr("class","btn btn-default navbar-btn dropdown-toggle").html("About <span class='caret'></span>"),o=item.append("ul").attr("class","dropdown-menu").style("width","160px").style("padding","5px"),d=o.append("li").append("a").attr("href","http://metasystems.riken.jp/visualization/treemap/html/documentation.htm").attr("target","mtm-doc").text("User Guide"),d=o.append("li").append("a").attr("href","http://metasystems.riken.jp/visualization/treemap/html/feedback.htm").attr("target","mtm-feedback").text("Feedback"),d=o.append("li").append("a").attr("href","#").attr("data-toggle","modal").attr("data-target","#mtm-modal").text("Examples").on("click",function(){return W("examples")}),d=o.append("li").append("a").attr("href","#").attr("data-toggle","modal").attr("data-target","#mtm-modal").text("About MTM").on("click",function(){return W("about")}),item=list.append("div").attr("class","dropdown navbar-btn").append("div").attr("class","input-group btn-group"),item.append("div").attr("class","input-group-addon").attr("data-toggle","tooltip").attr("data-placement","bottom").attr("title","Go to node").append("span").attr("class","glyphicon glyphicon-search"),item.append("button").attr("type","button").attr("class","btn btn-default").on("click",function(){return u?nt(u):nt(r)}).attr("data-toggle","tooltip").attr("data-placement","bottom").attr("data-container","#mtm-barmenu").attr("title","Go to root node").text("Root"),item.append("button").attr("type","button").attr("class","btn btn-default").on("click",function(){return f.parent?tt(f.parent):nt(f)}).attr("data-toggle","tooltip").attr("data-placement","bottom").attr("data-container","#mtm-barmenu").attr("title","Go to parent node").text("Parent");var v=item.append("select").attr("class","selectpicker").attr("data-live-search","true").attr("data-width","120px");v.on("change",function(){var e=this.value<0?r:l[this.value];if(u){var t=rt(u,[]).filter(function(t){return t.id==e.id&&t.data.sample==0});t.length>0?f=t[0]:(f=e,M(),u?K(u):K(r),n.options.zoom&&(a=u?u:r))}else f=e;Q(),nt(f)}),$(function(){$('[data-toggle="toggle"]').bootstrapToggle()}),$(function(){$('[data-toggle="popover"]').popover()}),$(function(){$('[data-toggle="tooltip"]').tooltip({trigger:"hover"})}),$(function(){$(".selectpicker").selectpicker()}),$(".mtm-dropdown").on({"show.bs.dropdown":function(){this.closable=!0},"hide.bs.dropdown":function(){return this.closable?!0:(this.closable=!0,!1)}}),$("body").on("click",function(e){$("#mtm-info,#mtm-pattern").each(function(){!$(this).is(e.target)&&$(this).has(e.target).length===0&&$(".popover").has(e.target).length===0&&$(this).popover("hide")})})}function q(){var e=d3.select(".mtm-treemap").append("svg").attr("class","mtm").attr("height",n.treemap.height).attr("width",n.treemap.width).style("font-family","'Source Code Pro','Lucida Console',Monaco,monospace").style("font-size",n.options.font+"px").style("display","inline-block").style("position","relative").style("z-index","1");e.append("rect").attr("width","100%").attr("height","100%").attr("fill",function(){return n.options.background?"#000":"#FFF"}).attr("class","mtm-bg"),e.append("g").attr("transform","translate(1,20)").classed("mtm-view",!0),e.append("g").attr("transform","translate(1,20)").classed("mtm-labels",!0);var t=e.append("g").attr("transform","translate(1,20)").classed("mtm-header",!0).style("font-size","14px");t.append("rect").attr("y",-20).attr("width",n.treemap.width).attr("height",20).style("fill","#888").style("stroke",function(){return n.options.background?"#000":"#FFF"}).style("cursor","pointer"),t.append("text").attr("x",6).attr("y",-16).attr("dy",".75em").style("pointer-events","none").text("Data loading..."),e.append("rect").classed("mtm-hl",!0).style("stroke","#000").style("stroke-width","5").style("fill","none").style("pointer-events","none")}function R(){console.log(n.table.height,n.table.width);var e=d3.select(".mtm-table").append("div").attr("class","mtm").style("height",n.table.height+"px").style("width",n.table.width+"px").style("overflow","auto").style("font-family","'Source Code Pro','Lucida Console',Monaco,monospace").style("font-size",n.options.font+"px").style("background-color",function(){return n.options.background?"#000":"#FFF"}).style("display","inline-block").style("position","relative").style("z-index","1"),t=e.append("div").style("background-color","#888").append("table").style("table-layout","fixed").append("tr").classed("mtm-header",!0);t.append("th").style("width","40%").text("Node"),t.append("th").style("text-align","right").text("Taxon_ID"),t.append("th").style("text-align","right").text("Hits"),t.append("th").style("text-align","right").text("%/View"),t.append("th").style("text-align","right").html("%/Sample&nbsp;"),t.append("th").style("text-align","left").text("Rank"),t.append("th").style("width","20px").text("");var r=e.append("div").style("height",n.table.height-t.node().offsetHeight+"px").style("overflow","auto").attr("class","mtm-scrollable").append("table").style("table-layout","fixed").classed("mtm-view",!0).classed("mtm-labels",!0).style("table-layout","fixed")}function U(e,t){e=="show"?d3.select("#mtm-tip").datum(t).style("opacity",1).html(function(e){return e.name+"<br/>Taxonomy ID: "+(+e.id>0?e.id:"")+"<br/>Rank: "+e.data.rank+"<br/>"+ut(e.data.hits)+" hits"+"<br/>"+e.data.percent.toFixed(2)+"% of sample "+e.data.sample+"<br/>"+(e.value*100/f.value).toFixed(2)+"% of the view"}):e=="hide"?d3.select("#mtm-tip").style("opacity",0):d3.select("#mtm-tip").style("top",d3.event.pageY+10+"px").style("left",d3.event.pageX+10+"px")}function z(e){w==e?w="":w=e}function W(t){if(t=="convert")d3.select("#mtm-modal-title").text("Convert Data File"),d3.select("#mtm-modal-body").text(""),e.convertor("mtm-modal-body");else if(t=="examples"){d3.select("#mtm-modal-title").text("Example Data Files");var n=d3.select("#mtm-modal-body").text("").append("ul").attr("class","list-unstyled");n.append("li").append("label").text("#1. HuFS: Human gut - 30 years old male").attr("width","210px");var r=n.append("li").attr("class","btn-group");r.append("a").attr("href","http://www.ncbi.nlm.nih.gov/pubmed/17916580").attr("class","btn btn-default").attr("target","cite").text("Citation"),r.append("a").attr("href","http://metagenomics.anl.gov/metagenomics.cgi?page=MetagenomeOverview&metagenome=4525311.3").attr("class","btn btn-default").attr("target","rast").text("Data Source"),r.append("a").attr("href","./data/HuFS.json").attr("class","btn btn-default").attr("target","rast").text("Data File"),n.append("li").append("label").text("#2. HuFU: Human gut - 7 months old female").attr("width","210px"),r=n.append("li").attr("class","btn-group"),r.append("a").attr("href","http://www.ncbi.nlm.nih.gov/pubmed/17916580").attr("class","btn btn-default").attr("target","cite").text("Citation"),r.append("a").attr("href","http://metagenomics.anl.gov/metagenomics.cgi?page=MetagenomeOverview&metagenome=4525314.3").attr("class","btn btn-default").attr("target","rast").text("Data Source"),r.append("a").attr("href","./data/HuFU.json").attr("class","btn btn-default").attr("target","rast").text("Data File")}else if(t=="about"){d3.select("#mtm-modal-title").text("About MetaTreeMap");var n=d3.select("#mtm-modal-body").text("").append("ul").attr("class","list-unstyled"),r=n.append("li");r.append("strong").text("MetaTreeMap version "),r.append("strong").text(function(){return e.version}),r.append("strong").text(" is under the "),r.append("a").attr("href","./LICENSE").attr("target","_blank").text("BSD License");var r=n.append("li");r.append("strong").text("Development: "),r.append("a").attr("href","http://metasystems.riken.jp/wiki/Maxime_Hebrard").attr("target","_blank").text("Maxime Hebrard");var r=n.append("li");r.append("span").text("The following libraries are used, with thanks to their authors:");var i=r.append("ul");i.append("li").append("a").attr("href","https://d3js.org/").attr("target","_blank").text("D3"),i.append("li").append("a").attr("href","http://colorbrewer2.org/").attr("target","_blank").text("ColorBrewer2"),i.append("li").append("a").attr("href","https://jquery.com/").attr("target","_blank").text("jQuery"),i.append("li").append("a").attr("href","http://getbootstrap.com/").attr("target","_blank").text("Bootstrap"),i.append("li").append("a").attr("href","http://www.bootstraptoggle.com/").attr("target","_blank").text("Bootstrap Toggle"),i.append("li").append("a").attr("href","https://silviomoreto.github.io/bootstrap-select/").attr("target","_blank").text("Bootstrap-select"),i.append("li").append("a").attr("href","https://www.google.com/fonts/specimen/Source+Code+Pro").attr("target","_blank").text("Source Code Pro");var r=n.append("li");r.append("strong").text("Source code "),r.append("span").text("available on "),r.append("a").attr("href","https://github.com/mhebrard/MetaTreeMap").attr("target","_blank").text("GitHub");var r=n.append("li");r.append("strong").text("Download "),r.append("span").text("minified version "),r.append("a").attr("href","./mtm.min.js").attr("target","_blank").text("Here");var r=n.append("li");r.append("strong").text("Reference: "),r.append("span").html("MetaTreeMap: an alternative visualization method for displaying metagenomic phylogenic trees. Hebrard M, Taylor TD. <i>PLOS One</i> 11(6):e0158261. (June 23, 2016) "),r.append("a").attr("href","http://www.ncbi.nlm.nih.gov/pubmed/27336370").attr("target","_blank").text("PMID 27336370")}}function X(e){m.domain([e.x,e.x+e.dx]),g.domain([e.y,e.y+e.dy]);var t=n.options.zoom?1:d/e.dx,r=n.options.zoom?1:v/e.dy,i;n.options.hierarchy?i=c.nodes().filter(function(e){return e.parent&&t*e.dx-1>0&&r*e.dy-1>0}):i=c.nodes().filter(function(e){return!e.children&&t*e.dx-1>0&&r*e.dy-1>0});var s=d3.select(".mtm-treemap").select(".mtm-view").selectAll("rect").data(i,function(e){return e.id+e.data.sample});s.enter().insert("rect").attr("class",function(e){return"v"+e.id+e.data.sample}).style("stroke",function(){return n.options.background?"#000":"#FFF"}).style("fill",function(e){return e.data.color}).style("cursor","pointer").attr("transform","translate(0,0)").attr("width",0).attr("height",0).on("click",function(e){w==""&&(et(e,!1),U("hide",e),tt(e))}).on("mouseover",function(e){et(e,!0),U("show",e)}).on("mouseout",function(e){et(e,!1),U("hide",e)}).on("mousemove",function(e){U("move")}).on("touchstart",z),s.transition().duration(1500).attr("transform",function(e){return"translate("+m(e.x)+","+g(e.y)+")"}).attr("width",function(e){return t*e.dx-1}).attr("height",function(e){return r*e.dy-1}),s.exit().remove()}function V(e){function y(e,t){var n,u,a,f,l=s*e.dx-1,c=o*e.dy-1;l<c?m(e.x+e.dx/2)-t*i>m(e.x)+i?(n=m(e.x+e.dx/2)-t*i,u=g(e.y)+r,a=n,f=g(e.y+e.dy)-r):n=u=a=f=0:g(e.y+e.dy/2)+t*i<g(e.y)+c-i?(n=m(e.x)+r,u=g(e.y+e.dy/2)+t*i,a=m(e.x+e.dx)-r,f=u):n=u=a=f=0;var h=d3.svg.line().x(function(e){return e[0]}).y(function(e){return e[1]}).interpolate("linear");return h([[n,u],[a,f]])}var r=Math.round(n.options.font*.6),i=Math.round(n.options.font*1.3),s=n.options.zoom?1:d/e.dx,o=n.options.zoom?1:v/e.dy,u=[],a=t.indexOf(n.options.labelled_rank);n.options.labelled!="no"&&(n.options.labelled=="rank"&&a!=-1?u=Y(a,e,e):u=c.nodes(e).filter(function(e){return!e.children})),u=u.filter(function(e){var t=s*e.dx-1,n=o*e.dy-1;if(t>0&&n>0&&(t<n&&t>i&&g(e.y+e.dy)-g(e.y)-2*r>0||t>n&&n>i&&m(e.x+e.dx)-m(e.x)-2*r>0))return e});var l=n.options.pattern.split("\\\\"),h=d3.select(".mtm-treemap").select(".mtm-labels").selectAll(".mtm-label").data(u,function(e){return e.id+e.data.sample});h.enter().append("g").attr("class","mtm-label"),h.exit().remove();var p=h.selectAll("path").data(function(e){return l.map(function(t){return e})});p.enter().append("path").attr("id",function(e,t){return"map"+e.id+e.data.sample+t}).style("opacity",0).attr("d","M0,0L0,0"),p.transition().duration(1500).attr("d",function(e,t){return y(e,t)}),p.exit().remove(),p=h.selectAll("text").data(function(e){return l.map(function(t,n){return[e,n]})}),p.enter().append("text").attr("text-anchor","left").attr("dy","0.5ex").style("pointer-events","none").append("textPath").attr("xlink:href",function(e){return"#map"+e[0].id+e[0].data.sample+e[1]}),p.selectAll("textPath").html(function(e){var t=l[e[1]];return t=t.replace(/#N/g,e[0].name),t=t.replace(/#I/g,e[0].id),t=t.replace(/#H/g,ut(e[0].data.hits)),t=t.replace(/#P/g,e[0].data.percent.toFixed(2)),t=t.replace(/#V/g,(e[0].value*100/f.value).toFixed(2)),t=t.replace(/#R/g,e[0].data.rank),t=t.replace(/#S/g,e[0].data.sample),t}),p.exit().remove()}function J(){var e=d3.select(".selectpicker").selectAll("option").data(l,function(e){return e.id});e.enter().append("option").attr("value",function(e,t){return t}).text(function(e){return e.name}),e.exit().remove(),d3.select(".selectpicker").insert("option",":first-child").attr("value",-1).property("selected",!0).text("Search..."),$(".selectpicker").selectpicker("refresh")}function K(e){var n=d3.select(".mtm-table").select(".mtm-view").html(""),r=rt(e,[]);n.selectAll("tr").data(r).enter().append("tr").attr("class",function(e){return"v"+e.id+e.data.sample}).on("mouseover",function(e){et(e,!0),U("show",e)}).on("mouseout",function(e){et(e,!1),U("hide",e)}).on("mousemove",function(e){U("move")}).selectAll("td").data(["name","id","hits","percent","sample","rank"]).enter().append("td").attr("class",function(e){return e}),n.selectAll(".name").data(r).style("width","40%").style("cursor","pointer").append("span").style("padding-left",function(e){return+Math.max(e.depth,e.children?t.indexOf(e.data.rank):t.indexOf(e.data.rank)+1)*4+"px"}).html(function(e){return"<span class='glyphicon'>&nbsp;</span>"}).append("span").on("click",function(e){return et(e,!1),tt(e)}).text(function(e){return e.name}),n.selectAll(".id").data(r).style("text-align","right").append("span").filter(function(e){return+e.id>0}).append("a").attr("href",function(e){return"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id="+e.id}).attr("target","taxonomy").text(function(e){return e.id}),n.selectAll(".hits").data(r).style("text-align","right").append("span").text(function(e){return ut(e.data.hits)}),n.selectAll(".percent").data(r).style("text-align","right").append("span"),n.selectAll(".sample").data(r).style("text-align","right").append("span").html(function(e){return e.data.percent.toFixed(2)+"%/"+e.data.sample+"&nbsp;"}),n.selectAll(".rank").data(r).append("span").text(function(e){return e.data.rank}),n.selectAll("tr").filter(function(e){return e.children}).select(".glyphicon").on("click",function(e){return it(e)})}function Q(){rank=t.indexOf(n.options.colored_rank);var e;n.options.colored=="rank"&&rank!=-1?(G(rank,r,r),n.options.cutoff_rank!="init"&&G(rank,u,u),e=function(e){return e.data.color}):n.options.colored=="majority"?e=function(e){return e.children?e.data.color=h(e.data.count.indexOf(Math.max.apply(null,e.data.count))):e.data.color=h(e.parent.data.count.indexOf(Math.max.apply(null,e.parent.data.count))),e.data.color}:n.options.colored=="sample"?e=function(e){return e.data.color=h(e.data.sample),e.data.color}:e=function(e){return e.data.color=h(e.id),e.data.color},n.table.display&&d3.select(".mtm-table").select(".mtm-view").selectAll("tr").style("background-color",function(t){return e(t)}),n.treemap.display&&d3.select(".mtm-treemap").select(".mtm-view").selectAll("rect").style("fill",function(t){return e(t)})}function G(e,r,i){if(i.children&&i.children.length>0)for(var s in i.children){var o=t.indexOf(i.children[s].data.rank);o>e?rt(i.children[s],[]).forEach(function(e){e.data.color=h("sub"+i.id)}):o==e?rt(i.children[s],[]).forEach(function(e){e.data.color=h(i.children[s].id)}):(n.options.upper?i.children[s].data.color=h(i.children[s].id):i.children[s].data.color="#ccc",G(e,r,i.children[s]))}}function Y(e,n,r){var i=[];if(e<=t.indexOf(n.data.rank))i.push(n);else if(r.children&&r.children.length>0)for(var s in r.children){var o=t.indexOf(r.children[s].data.rank);o>=e?i.push(r.children[s]):i=i.concat(Y(e,n,r.children[s]))}else t.indexOf(r.data.rank)<e&&i.push(r);return i}function Z(e,n,r){var i=[[],[],[]];if(r.children&&r.children.length>0)for(var s in r.children){var o=t.indexOf(r.children[s].data.rank);o>=e?(i[2]=i[2].concat(rt(r.children[s],[])),i[0].push(r.children[s])):(i[1].push(r.children[s]),subList=Z(e,n,r.children[s]),i[0]=i[0].concat(subList[0]),i[1]=i[1].concat(subList[1]),i[2]=i[2].concat(subList[2]))}return i}function et(e,t){if(t){var n=d/f.dx,r=v/f.dy;d3.selectAll("rect.v"+e.id+e.data.sample).style("fill",function(e){return d3.hsl(e.data.color).darker(1)}),d3.selectAll("tr.v"+e.id+e.data.sample).style("background-color",function(e){return d3.hsl(e.data.color).darker(1)}),c.nodes().indexOf(e)>0&&(e.data.sample==0?d3.selectAll(".mtm-hl").attr("x",m(e.x)+1+2).attr("y",g(e.y)+20+2).attr("width",n*e.dx-5).attr("height",r*e.dy-5):d3.selectAll(".mtm-hl").attr("x",m(e.parent.x)+1+2).attr("y",g(e.parent.y)+20+2).attr("width",n*e.parent.dx-5).attr("height",r*e.parent.dy-5))}else d3.selectAll("rect.v"+e.id+e.data.sample).style("fill",function(e){return d3.hsl(e.data.color)}),d3.selectAll("tr.v"+e.id+e.data.sample).style("background-color",function(e){return d3.hsl(e.data.color)}),d3.selectAll(".mtm-hl").attr("x",0).attr("y",0).attr("width",0).attr("height",0)}function tt(e){e==f?e.parent&&(e.parent.data.hits==e.data.hits?(f=e.parent,tt(e.parent)):nt(e.parent)):e.children?e.children[0].data.hits==e.data.hits?tt(e.children[0]):nt(e):nt(e.parent)}function nt(e){f=e,e.parent?(d3.selectAll(".mtm-root").classed("mtm-on",!1),d3.selectAll(".mtm-root").classed("mtm-off",!0)):(d3.selectAll(".mtm-root").classed("mtm-on",!0),d3.selectAll(".mtm-root").classed("mtm-off",!1)),d3.select(".mtm-treemap").select(".mtm-header").datum(e).on("click",function(e){w==""&&(et(e,!1),U("hide",e),tt(e))}).on("mouseover",function(e){et(e,!1),U("show",e)}).on("mouseout",function(e){et(e,!1),U("hide",e)}).on("mousemove",function(e){U("move")}).on("touchstart",z).select("text").text(function(e){return e.name}),n.options.zoom&&(_(e),Q()),n.treemap.display&&(X(e),V(e));if(n.table.display){var t=d3.select(".mtm-table").select(".mtm-labels").selectAll("tr");t.selectAll(".percent").text("-"),t.data(rt(e,[]),function(e){return"t"+e.id+e.data.sample}).selectAll(".percent").text(function(t){return(t.value*100/e.value).toFixed(2)+"%"});if(n.options.labelled=="rank"&&rank!=-1){var i=u?Z(rank,u,u):Z(rank,r,r);t.data(i[2],function(e){return"v"+e.id+e.data.sample}).style("display","none"),t.data(i[0],function(e){return"v"+e.id+e.data.sample}).style("display","table-row").select(".glyphicon").attr("class","glyphicon glyphicon-expand"),t.data(i[1],function(e){return"v"+e.id+e.data.sample}).style("display","table-row").select(".glyphicon").attr("class","glyphicon glyphicon-collapse-down")}else t.style("display","table-row").select(".glyphicon").attr("class","glyphicon glyphicon-collapse-down");t.filter(function(e){return!e.children}).select(".glyphicon").attr("class","glyphicon glyphicon-unchecked")}}function rt(e,t){return e!=r&&t.push(e),e.children&&e.children.forEach(function(e){t=rt(e,t)}),t}function it(e){var t=d3.select(".mtm-table").select(".v"+e.id+e.data.sample).select(".glyphicon");if(t.classed("glyphicon glyphicon-collapse-down")){t.attr("class","glyphicon glyphicon-expand");if(e.children)for(var n in e.children)st(e.children[n])}else{t.attr("class","glyphicon glyphicon-collapse-down");if(e.children)for(var n in e.children)ot(e.children[n])}}function st(e){d3.select(".mtm-table").selectAll(".v"+e.id+e.data.sample).style("display","none");if(e.children)for(var t in e.children)st(e.children[t])}function ot(e){var t=d3.select(".mtm-table").select(".v"+e.id+e.data.sample).style("display","table-row");if(t.select(".glyphicon").classed("glyphicon-collapse-down")&&e.children)for(var n in e.children)ot(e.children[n])}function ut(e){return Number(e).toLocaleString("en")}function at(t,n,r){if(e.verbose){var i=d3.select("#mtm-error").style("display","block");i.classed("alert")||i.attr("class","alert alert-"+n),i.append("li").text(r)}return Promise.reject(new Error(r+" ("+t+")"))}function ft(e,t){if(e.children&&e.children.length>0){var n;t?e.data.hits==t.data.sum?(t.name=e.name,t.data.rank=e.data.rank,t.id=e.id,n=t):(n={name:e.name,children:[],data:{assigned:0,sum:e.data.hits,rank:e.data.rank},id:e.id},t.children.push(n)):(n={name:e.name,children:[],data:{assigned:0,sum:e.data.hits,rank:e.data.rank},id:e.id},out=n);for(var r in e.children)ft(e.children[r],n)}else t.data.assigned=t.data.assigned+e.data.hits}function lt(e,t){d3.select("#mtm-canvas").append("a").attr("download",e).attr("href",t).node().click()}function ct(e){var t=e.name+"	"+(+e.id>0?e.id:"")+"	"+e.data.hits+"	"+(e.data.hits*100/r.data.hits).toFixed(1)+"	"+e.data.sample+"	"+e.data.rank+"\n";if(e.children&&e.children.length>0)for(var n in e.children)t+=ct(e.children[n]);return t}function ht(e){e.value=="json"?(d3.select("#mtm-fieldhead").html("Object Properties <small>(Specify corresponding field names in your dataset)<small>"),d3.select("[name=mtm-tid]").attr("value","id"),d3.select("[name=mtm-tname]").attr("value","name"),d3.select("[name=mtm-hits]").attr("value","data.assigned"),d3.select("#mtm-headrow").style("display","none")):e.value=="tab"&&(d3.select("#mtm-fieldhead").html("Column Index <small>(Specify the column of the field in your dataset)</small>"),d3.select("[name=mtm-tid]").attr("value","1"),d3.select("[name=mtm-tname]").attr("value","2"),d3.select("[name=mtm-hits]").attr("value","3"),d3.select("#mtm-headrow").style("display","table-row"))}function pt(){var e=d3.select("[name=mtm-format]:checked").node().value,t=d3.select("#mtm-convert").node().files[0];r={name:"root",children:[],data:{assigned:0,rank:"no rank"},id:1},i=[r.id],o=[r];var n=[];d3.text("./data/taxonomy.tsv",function(i){i.split("\n").forEach(function(e){var t=e.split("	");n[+t[0]]={id:+t[0],parent:+t[1],rank:t[2],name:t[3]}});if(e=="json"){var s=d3.select("[name=mtm-tid]").node().value.split("."),o=d3.select("[name=mtm-tname]").node().value.split("."),u=d3.select("[name=mtm-hits]").node().value.split(".");d3.json(URL.createObjectURL(t),function(e){vt(n,e,s,o,u),yt(e),mt(e);var r="data:text/json;charset=utf8;filename=output.json,"+encodeURIComponent(JSON.stringify(out));lt(t.name.replace(/.[^.]*$/,"")+"_metabin.json",r)})}else if(e=="tab"){var s=+d3.select("[name=mtm-tid]").node().value-1,o=+d3.select("[name=mtm-tname]").node().value-1,u=+d3.select("[name=mtm-hits]").node().value-1,a=d3.select("[name=mtm-head]").property("checked");d3.text(URL.createObjectURL(t),function(e){var i=e.split(/\r?\n/),f;a?f=1:f=0;for(f;f<i.length;f++)if(i[f]!=""){var l=i[f].split("	");l[s]==0&&(n[0]={id:l[o],parent:1,rank:"no rank",name:l[o]}),dt(n,l[s],l[u])}yt(r);var c="data:text/json;charset=utf8;filename=output.json,"+encodeURIComponent(JSON.stringify(r));lt(t.name.replace(/.[^.]*$/,"")+"_metabin.json",c)})}})}function dt(e,t,n){var r=e[t],s,u,a,f=i.indexOf(r.id);f>-1?(a=!1,s=o[f],s.data.assigned=n):(a=!0,s={name:r.name,children:[],data:{assigned:n,rank:r.rank},id:r.id},i.push(s.id),o.push(s));if(r.parent!=r.id){var f=i.indexOf(r.parent);f>-1?u=o[f]:u=dt(e,r.parent,0),a&&u.children.push(s)}return s}function vt(e,t,n,r,i){t.data||(t.data={}),t.data.assigned=gt(t,i),t.id=gt(t,n),+t.id==0||!e[+t.id]?(t.name=gt(t,r),t.data.rank="no rank"):(t.name=e[+t.id].name,t.data.rank=e[+t.id].rank);if(t.children.length>0)for(var s in t.children)vt(e,t.children[s],n,r,i)}function mt(e,t){var n={name:e.name,children:[],data:{assigned:e.data.assigned,sum:e.data.sum,rank:e.data.rank},id:e.id};t?t.children.push(n):out=n;for(var r in e.children)mt(e.children[r],n)}function gt(e,t){var n=0,r=e;while(t[n])r=r[t[n]],n++;return r}function yt(e){e.data.sum=+e.data.assigned;if(e.children.length>0)for(var t in e.children){var n=yt(e.children[t]);e.data.sum+=n}return+e.data.sum}var e={version:"3.4"};e.verbose=!0;var t=["no rank","superkingdom","kingdom","subkingdom","superphylum","phylum","subphylum","superclass","class","subclass","infraclass","superorder","order","suborder","infraorder","parvorder","superfamily","family","subfamily","tribe","subtribe","genus","subgenus","species group","species subgroup","species","subspecies","varietas","forma"],n,r,i,o,u,a,f,l,c,h="",p=[["brewer","#8dd3c7,#ffffb3,#bebada,#fb8072,#80b1d3,#fdb462,#b3de69,#fccde5,#d9d9d9,#bc80bd,#ccebc5,#ffed6f"],["d3","#1f77b4,#aec7e8,#ff7f0e,#ffbb78,#2ca02c,#98df8a,#d62728,#ff9896,#9467bd,#c5b0d5,#8c564b,#c49c94,#e377c2,#f7b6d2,#7f7f7f,#c7c7c7,#bcbd22,#dbdb8d,#17becf,#9edae5"]],d=1,v=1,m,g,y=1,b=1,w="";e.load=function(t,n){if(!document.getElementById("mtm-mods")){var i=document.createElement("div");i.id="mtm-mods";var s=document.getElementsByTagName("body")[0];s.firstChild?s.insertBefore(i,s.firstChild):s.appendChild(i),i=document.createElement("div"),i.id="mtm-error",s.firstChild?s.insertBefore(i,s.firstChild):s.appendChild(i)}var o=[];Promise.resolve().then(function(){return window.jQuery||o.push(E("http://code.jquery.com/jquery-1.12.0.min.js")),Promise.all(o)}).catch(function(e){at(e,"danger","mtm.load.jQuery: jQuery is in trouble")}).then(function(){o=[];if(!$.fn.modal||!$.fn.modal.Constructor.VERSION)o.push(S("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css")),o.push(E("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"));return window.d3||o.push(E("https://d3js.org/d3.v3.min.js")),Promise.all(o)}).catch(function(e){at(e,"danger","mtm.load.bootstrap: bootstrap is in trouble")}).then(function(){console.log("mtm",e.version),console.log("jQ",jQuery.fn.jquery),console.log("bootstrap",$.fn.modal.Constructor.VERSION),console.log("d3",d3.version)}).catch(function(e){at(e,"danger","mtm.load.version: Some libraries are missing")}).then(function(){return o=[],d3.select("#mtm-mods").attr("data-subs")||(d3.select("#mtm-mods").attr("data-subs",!0),o.push(S("http://fonts.googleapis.com/css?family=Source+Code+Pro:600")),o.push(S("https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css")),o.push(E("https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js")),o.push(S("https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css")),o.push(E("https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"))),Promise.all(o)}).catch(function(e){at(e,"danger","mtm.load.modules: Some modules are missing")}).then(function(){return x(n)}).catch(function(e){at(e,"danger","mtm.load.config: Config file is in trouble")}).then(function(){return Promise.all([L(),A()])}).catch(function(e){at(e,"danger","mtm.load.layout: Cannot initiate layout")}).then(function(){return T(t)}).then(function(e){e[0]=e.reduce(function(e,t){return+e+ +t}),k(r,e),console.log("skeleton",r),O()},function(e){at(e,"warning","mtm.load.data: Data file is missing")})},e.save=function(e){d3.select("#mtm-canvas").html("");if(e=="json"){ft(r);var t="data:text/json;charset=utf8;filename=output.json,"+encodeURIComponent(JSON.stringify(out));lt("tree.json",t)}else if(e=="svg"){var i=d3.select("svg").attr("version",1.1).attr("xmlns","http://www.w3.org/2000/svg").attr(":xmlns:xlink","http://www.w3.org/1999/xlink").node().outerHTML,t="data:image/svg+xml;charset=utf8;filename=treemap.svg,"+encodeURIComponent(i);lt("treemap.svg",t)}else if(e=="png"){var s=d3.select("svg"),o=d3.select("body").append("canvas").attr("width",s.attr("width")).attr("height",s.attr("height")).style("display","none").node(),u=o.getContext("2d"),i=s.attr("version",1.1).attr("xmlns","http://www.w3.org/2000/svg").attr(":xmlns:xlink","http://www.w3.org/1999/xlink").node().outerHTML,a=new Image;a.onload=function(){u.drawImage(a,0,0);var e=o.toDataURL().replace("image/png","application/octet-stream");lt("treemap.png",e)},a.src="data:image/svg+xml;base64,"+btoa(i)}else if(e=="txt"){var f="Name	TaxonomyID	Hits	Percentage	Sample	Rank\n";f+=ct(r);var t="data:text/tab-separated-values;charset=utf8;filename=table.txt,"+encodeURIComponent(f);lt("table.txt",t)}else if(e=="config"){var t="data:text/json;charset=utf8;filename=mtm-config.json,"+encodeURIComponent(JSON.stringify(n));lt("mtm-config.json",t)}},e.convertor=function(e){var t=d3.select("#"+e),n=t.append("form"),r=n.append("div").attr("class","form-inline").style("white-space","nowrap").style("overflow","hidden").style("text-overflow","ellipsis");r.append("label").text("Data File").style("width","90px"),s=r.append("label").attr("class","btn btn-default").attr("id","mtm-convert-data"),s.text("Browse..."),s.append("input").attr("type","file").style("display","none").attr("id","mtm-convert").attr("name","mtm-convertFile").on("change",function(){d3.select("#mtm-convert-help").text(this.files[0].name)}),$("#mtm-convert-data").on({click:function(){$("#"+e)[0].closable=!1}}),r.append("label").attr("class","help-block small").attr("id","mtm-convert-help").style("display","inline"),r=n.append("div").attr("class","form-inline"),r.append("label").text("Format").style("width","90px");var i=r.append("label").attr("class","radio-inline");i.append("input").attr("type","radio").property("checked",!0).attr("name","mtm-format").attr("value","json").on("click",function(){ht(this)}),i.append("span").text("Other JSON");var i=r.append("label").attr("class","radio-inline");i.append("input").attr("type","radio").attr("name","mtm-format").attr("value","tab").on("click",function(){ht(this)}),i.append("span").text("Tabular (TSV)"),r=n.append("div").attr("class","form-inline"),r.append("label").text("Fields").style("width","90px"),r.append("label").attr("id","mtm-fieldhead").html("Object Properties <small>(Specify corresponding field names in your dataset)<small>"),r=n.append("div").attr("class","form-inline"),r.append("label").text("Taxon ID").style("width","90px"),r.append("input").attr("type","text").attr("class","form-control").attr("name","mtm-tid").attr("value","id"),r=n.append("div").attr("class","form-inline"),r.append("label").text("Taxon Name").style("width","90px"),r.append("input").attr("type","text").attr("class","form-control").attr("name","mtm-tname").attr("value","name"),r=n.append("div").attr("class","form-inline"),r.append("label").text("Hits").style("width","90px"),r.append("input").attr("type","text").attr("class","form-control").attr("name","mtm-hits").attr("value","data.assigned"),r=n.append("div").attr("class","form-inline").attr("id","mtm-headrow").style("display","none"),r.append("label").text("Header").style("width","90px");var i=r.append("label").attr("class","checkbox-inline");i.append("input").attr("type","checkbox").attr("name","mtm-head").attr("value","false"),i.append("span").text("Ignore 1st Line"),r=n.append("div").attr("class","form-inline"),r.append("button").attr("class","btn btn-primary").attr("type","button").style("width","90px").text("Convert").on("click",function(){pt()}),$("#"+e).on({"show.bs.modal":function(){this.closable=!0},"hide.bs.modal":function(){return this.closable?!0:(this.closable=!0,!1)}})},typeof define=="function"&&define.amd?define("mtm",e):typeof module=="object"&&module.exports&&(module.exports=e),this.mtm=e}();