-
Notifications
You must be signed in to change notification settings - Fork 0
/
st.min.js
2 lines (2 loc) · 45.1 KB
/
st.min.js
1
2
!function(){function t(){return{opts:{title:"",src:[],anno:[],x:"x",y:"y",xlimits:[],ylimits:[],annoTypes:[],annoTexts:[]},raw:{gxlim:[Number.MAX_VALUE,Number.MIN_VALUE],gylim:[Number.MAX_VALUE,Number.MIN_VALUE],ids:{},series:[],minima:0,annoGroups:{}},title:function(t){return t&&"string"==typeof t?this.opts.title=t:console.log("Invalid title option."),this},y:function(t){return t&&"string"==typeof t?this.opts.y=t:console.log("Invalid y accessor option."),this},xlimits:function(t){return t&&t instanceof Array?this.opts.xlimits=t:console.log("Invalid x domain limits."),this},ylimits:function(t){return t&&t instanceof Array?this.opts.ylimits=t:console.log("Invalid y domain limits."),this},add:function(t,s){t instanceof Array?!s||s instanceof Array?(this.opts.src.push.apply(this.opts.src,t),this.opts.anno.push.apply(this.opts.anno,s)):console.log("Raw data and annotation data must be of the same type."):(this.opts.src.push(t),this.opts.anno.push(s))},annotationColumn:function(t,s){t.toUpperCase()in n.annotation?(this.opts.annoTypes.push(t),this.opts.annoTexts.push(s)):console.log("Unknown annotation type: "+t)},remove:function(t){var s=[];if(!t&&0!==t){for(var e in this.raw.ids)s.push(e);return this.raw.ids={},this.raw.series=[],this.raw.gxlim=[Number.MAX_VALUE,Number.MIN_VALUE],this.raw.gylim=[Number.MAX_VALUE,Number.MIN_VALUE],s}t instanceof Array?t.sort():t=[t];for(e in t){var a=t[e];if(isNaN(a)){for(var e in this.raw.series)if(this.raw.series[e].id===a){this.raw.series.splice(e,1),s.push(this.raw.ids[a]),delete this.raw.ids[a];break}}else if(a-e<this.raw.series.length){var i=this.raw.series.splice(a-e,1);s.push(i[0].id),delete this.raw.ids[i[0].id]}}return 0===this.raw.series.length&&(this.raw.gxlim=[Number.MAX_VALUE,Number.MIN_VALUE],this.raw.gylim=[Number.MAX_VALUE,Number.MIN_VALUE]),s},id:function(t){return this.raw.series[t].id},titleat:function(t){return this.raw.series[t].title},accs:function(t){return this.raw.series[t].accs},push:function(t){var s=this,e=[];for(var a in this.opts.src)"string"!=typeof this.opts.src[a]?this.fetch(this.opts.src[a],this.opts.anno[a]):e.push(this.fetch(this.opts.src[a],this.opts.anno[a]));$.when.apply($,e).done(function(){s.opts.src.length&&(s.opts.src=[],s.opts.anno=[],s.raw.gxlim[0]===s.raw.gxlim[1]&&(s.raw.gxlim[0]-=s.raw.gxlim[0]/100,s.raw.gxlim[1]+=s.raw.gxlim[1]/100),s.raw.gylim[0]===s.raw.gylim[1]&&(s.raw.gylim[0]-=s.raw.gylim[0]/100,s.raw.gylim[1]+=s.raw.gylim[1]/100),t())})},fetch:function(t,s){var e=this,a=null;if("string"==typeof t)a="string"==typeof s&&s?$.when($.get(t),$.get(s)).fail(function(){console.log("Fetch failed for: "+t+"\n"+s)}).then(function(t,s){if("string"==typeof t&&(t=$.parseJSON(t)),t[0]instanceof Array)for(var a in t[0])e.seriesfetch(t[0][a],s[0][a]);else e.seriesfetch(t[0],s[0])}):$.when($.get(t)).fail(function(){console.log("Fetch failed for: "+t)}).then(function(t){if("string"==typeof t&&(t=$.parseJSON(t)),t instanceof Array){s||(s=[]);for(var a in t)e.seriesfetch(t[a],s[a])}else e.seriesfetch(t,s)});else if("string"==typeof s&&s)a=$.when($.get(s)).fail(function(){console.log("Fetch failed for: "+s)}).then(function(a){if(t instanceof Array){s||(s=[]);for(var i in t)e.seriesfetch(t[i],a[i])}else e.seriesfetch(t,a)});else if(t instanceof Array)for(var i in t)e.seriesfetch(t[i],s[i]);else e.seriesfetch(t,s);return a},reset:function(){for(var t in this.raw.series){var s=this.raw.series[t];s.size=[0,s.data.length,0]}}}}function s(t,s,e,a){var i=[];return i=2===e.length?isNaN(e[0])&&isNaN(e[1])?[s[e[0]],s[e[1]]]:"number"==typeof e[0]&&"number"==typeof e[1]?[e[0],e[1]]:a&&""!==a?d3.extent(t,function(t){return t[a]}):d3.extent(t):a&&""!==a?d3.extent(t,function(t){return t[a]}):d3.extent(t),i[0]=parseFloat(i[0]),i[1]=parseFloat(i[1]),i}function e(){return{opts:{title:"",xlabel:"",ylabel:"",xreverse:!1,yreverse:!1,legend:!1,labels:!1,margins:[80,80,80,120]},data:null,timeout:null,colors:n.util.colors(),mol2svg:n.util.mol2svg(250,250),title:function(t){return t&&"string"==typeof t?this.opts.title=t:console.log("Invalid title option."),this},xlabel:function(t){return t&&"string"==typeof t?this.opts.xlabel=t:console.log("Invalid x-axis label option."),this},ylabel:function(t){return t&&"string"==typeof t?this.opts.ylabel=t:console.log("Invalid y-axis label option."),this},xreverse:function(t){return t&&"boolean"==typeof t?this.opts.xreverse=t:console.log("Invalid x-axis reverse option."),this},yreverse:function(t){return t&&"boolean"==typeof t?this.opts.yreverse=t:console.log("Invalid y-axis reverse option."),this},legend:function(t){return t&&"boolean"==typeof t?this.opts.legend=t:console.log("Invalid legend option."),this},labels:function(t){return t&&"boolean"==typeof t?this.opts.labels=t:console.log("Invalid labels option."),this},margins:function(t){return t&&t instanceof Array&&4===t.length?this.opts.margins=t:console.log("Invalid margins array."),this},render:function(t){this.target=t;var s=this.opts.margins;if(this.width=$(t).width()-s[1]-s[3],this.height=$(t).height()-s[0]-s[2],this.width<=0)return void console.log("Invalid chart width: "+this.width);if(this.height<=0)return void console.log("Invalid chart height: "+this.height);var e=this;if(this.panel=d3.select(t).append("svg:svg").attr("class","st-base").attr("width",this.width+s[1]+s[3]).attr("height",this.height+s[0]+s[2]).on("mousedown.zoom",function(){e.mouseDown(this)}).on("mousemove.zoom",function(){e.mouseMove(this)}).on("mouseup.zoom",function(){e.mouseUp()}).on("mouseout",function(){e.mouseOut(this)}).on("dblclick.zoom",function(){e.mouseDbl(this)}),this.canvas=this.panel.append("svg:g").attr("transform","translate("+s[3]+","+s[0]+")"),this.canvas.append("svg:clipPath").attr("id","clip-"+this.target).append("svg:rect").attr("x",0).attr("y",0).attr("width",this.width).attr("height",this.height),this.selection=this.canvas.append("svg:rect").attr("class","st-selection").attr("clip-path","url(#clip-"+this.target+")").attr("x",0).attr("y",0).attr("width",0).attr("height",0).style("pointer-events","none").attr("display","none"),this.scales={},this.scales.x=this.opts.xreverse?d3.scale.linear().domain([1,0]).range([0,this.width]):d3.scale.linear().domain([0,1]).range([0,this.width]),this.scales.y=this.opts.yreverse?d3.scale.linear().domain([1,0]).range([this.height,0]):d3.scale.linear().domain([0,1]).range([this.height,0]),$("#st-tooltips").length?this.tooltips=d3.select("#st-tooltips"):(this.tooltips=d3.select("body").append("div").attr("width",$(t).width()).attr("height",$(t).height()).style("pointer-events","none").attr("id","st-tooltips").style("position","absolute").style("opacity",0),this.tooltips.append("div").attr("id","tooltips-meta").style("height","50%").style("width","100%"),this.tooltips.append("div").attr("id","tooltips-mol").style("height","50%").style("width","100%")),"function"==typeof this.behavior&&this.behavior(),this.renderAxes(),this.opts.title&&0!==this.opts.title.length&&(s[0]<20?console.log("Not enough space for chart title: increase top margin (min 20)"):this.panel.append("text").attr("class","st-title").attr("x",s[3]+this.width/2).attr("y",.75*s[0]).attr("text-anchor","middle").attr("font-size","large").text(this.opts.title)),this.opts.labels){if(s[1]<60)return void console.log("Not enough space for label option: increase right margin (min 60)");var i=this.canvas.append("g").attr("id","st-options");i.append("text").attr("x",this.width).attr("y",this.height-this.height/4).text("Options");var n=i.append("g");n.append("svg:circle").attr("cx",this.width+5).attr("cy",this.height-this.height/5).attr("r",2).style("fill","#333333").style("stroke","#333333"),n.append("text").attr("x",this.width+12).attr("y",this.height-this.height/5+2).text("Labels").attr("id","st-label").style("cursor","pointer"),n.on("mousedown",function(){var t=d3.select(this);"none"===t.style("stroke")?t.style("stroke","#333333"):t.style("stroke","none"),a(e)})}},renderAxes:function(){var t=this.opts.margins,s=d3.format(".4g"),e=d3.format(",.2g");this.xaxis=d3.svg.axis().scale(this.scales.x).ticks(6).tickSubdivide(!0).tickFormat(s).orient("bottom"),this.yaxis=d3.svg.axis().scale(this.scales.y).ticks(4).tickFormat(e).orient("left"),this.canvas.append("svg:g").attr("class","st-xaxis").attr("transform","translate(0,"+this.height+")").call(this.xaxis),this.canvas.append("svg:g").attr("class","st-yaxis").attr("transform","translate(-25, 0)").call(this.yaxis),""!==this.opts.xlabel&&this.panel.select(".st-xaxis").append("text").text(this.opts.xlabel).attr("text-anchor","middle").attr("x",this.width/2).attr("y",t[2]/2),""!==this.opts.ylabel&&this.panel.select(".st-yaxis").append("text").text(this.opts.ylabel).attr("transform","rotate (-90)").attr("text-anchor","middle").attr("x",0-this.height/2).attr("y",0-t[3]/2)},renderlabels:function(t){if(this.opts.labels){var s=this.panel.select("#st-label");if("none"===s.style("stroke")||!this.data)return void this.canvas.selectAll(".st-labels").remove();var e=[this.scales.x.invert(0),this.scales.x.invert(this.width)];e=n.util.domain(this.scales.x,e);var a,i,r=50,o=Math.ceil(this.width/r),l=Math.abs(e[1]-e[0])/(o-1),h=[],c=d3.format(".2f");this.data.raw.minima?(i=10,a=function(t,s){return t>s}):(i=-5,a=function(t,s){return s>t});for(var d=0,p=0,u=0;u<t.length;u++){var f=t[u],v=this.data.accs(u),g=f[0];d+=f.length;for(var m=1;m<f.length;m++){var x=f[m],y=g[v[0]],w=g[v[1]],p=p+w;if(a(x[v[1]],w)){var b=Math.floor((y-e[0])/l),A=h[b];A?a(A[v[1]],w)&&(h[b]=g):h[b]=g}g=x}}p/=d,this.canvas.selectAll(".st-labels").remove();var k=this.canvas.append("g").attr("class","st-labels").attr("text-anchor","middle"),O=0,I=0;for(var u in h)if(h[u]&&a(p,h[u][v[1]])){var y=h[u][v[0]],M=this.scales.x(y),z=this.scales.y(h[u][v[1]]);if(Math.abs(M-O)<20&&Math.abs(z-I)<20){O=M,I=z;continue}O=M,I=z;var F="#333333";0>z&&(z=0,F="gray"),k.append("text").attr("x",M).attr("y",z+i).style("fill",F).text(c(y))}}},rendergroups:function(){if(0!==Object.keys(this.data.raw.annoGroups).length){var t=this,s=this.canvas.select("#st-options"),e=0;null===s[0][0]?(s=this.canvas.append("g").attr("id","st-options"),s.append("text").attr("x",this.width).attr("y",this.height-this.height/4).text("Options")):e=15;var a=s.append("g");a.append("svg:circle").attr("cx",this.width+5).attr("cy",this.height-this.height/5+e).attr("r",2).style("fill","#333333").style("stroke","#333333"),a.append("text").attr("x",this.width+12).attr("y",this.height-this.height/5+2+e).text("Groups").attr("id","st-groups").style("cursor","pointer"),a.on("mouseup",function(){var s=d3.select(this);if("none"===s.style("stroke")){s.style("stroke","#333333");var e=d3.select(t.target).append("div").attr("id","st-popup").style("left",d3.event.pageX+5+"px").style("top",d3.event.pageY+5+"px").style("opacity",.9).style("background-color","white"),a=[];for(var i in t.data.raw.annoGroups)a.push(i);e.append("ul").selectAll("li").data(a).enter().append("li").style("display","block").style("cursor","pointer").html(function(s){return t.data.raw.annoGroups[s]?"<strong>"+s+"</strong>":s}).on("mousedown",function(e){for(i in t.data.raw.annoGroups)i!=e||t.data.raw.annoGroups[e]?t.data.raw.annoGroups[i]=0:t.data.raw.annoGroups[e]=1;t.mouseDbl(),s.style("stroke","none"),$("#st-popup").remove()})}else s.style("stroke","none"),$("#st-popup").remove()})}},mouseDown:function(t){var s=d3.mouse(t),e=this.opts.margins[3],a=this.opts.margins[0];this.panel.select(".st-selection").attr("x",s[0]-e).attr("xs",s[0]-e).attr("y",s[1]-a).attr("ys",s[1]-a).attr("width",1).attr("height",1).attr("display","inline")},mouseMove:function(t){var s=this.panel.select(".st-selection");if("inline"===s.attr("display")){var e=d3.mouse(t)[0]-this.opts.margins[3],a=d3.mouse(t)[1]-this.opts.margins[0],i=parseInt(s.attr("width"),10),n=parseInt(s.attr("height"),10),r=e-parseInt(s.attr("x"),10),o=a-parseInt(s.attr("y"),10),l=parseInt(s.attr("xs"),10),h=parseInt(s.attr("ys"),10);0>r&&0>o||i>2*r&&n>2*o?(s.attr("x",e),s.attr("width",l-e),s.attr("y",a),s.attr("height",h-a)):0>r||i>2*r?(s.attr("x",e),s.attr("width",l-e),s.attr("height",o)):0>o||n>2*o?(s.attr("y",a),s.attr("height",h-a),s.attr("width",r)):(s.attr("width",r),s.attr("height",o))}},mouseUp:function(){var t=5,s=this.panel.select(".st-selection");if(parseInt(s.attr("width"))>t&&parseInt(s.attr("height"))>t){var e=parseFloat(s.attr("x")),i=parseFloat(s.attr("y")),n=parseFloat(s.attr("width")),r=parseFloat(s.attr("height"));if(n=this.scales.x.invert(e+n),r=this.scales.y.invert(i+r),e=this.scales.x.invert(e),i=this.scales.y.invert(i),this.data){var o=this.data.raw.gylim[0];o>r&&(r=o)}this.scales.x.domain([e,n]).nice(),this.scales.y.domain([r,i]).nice(),s.attr("display","none"),this.canvas.select(".st-xaxis").call(this.xaxis),this.canvas.select(".st-yaxis").call(this.yaxis),a(this)}else s.attr("display","none")},mouseOut:function(t){var s=this.panel.select(".st-selection"),e=d3.mouse(t)[0],a=d3.mouse(t)[1];(0>e||0>a||e>$(this.target).width()||a>$(this.target).height())&&s.attr("display","none")},mouseDbl:function(t){if(t){var s=d3.mouse(t)[0]-this.opts.margins[3],e=d3.mouse(t)[1]-this.opts.margins[0];if(0>s||s>this.width||0>e||e>this.height)return}if(null===this.data){var i=n.util.domain(this.scales.x,[0,1]),r=n.util.domain(this.scales.y,[0,1]);return this.scales.x.domain(i).nice(),this.scales.y.domain(r).nice(),this.canvas.select(".st-xaxis").call(this.xaxis),void this.canvas.select(".st-yaxis").call(this.yaxis)}var o=n.util.domain(this.scales.x,this.data.raw.gxlim),l=n.util.domain(this.scales.y,this.data.raw.gylim);this.scales.x.domain(o).nice(),this.scales.y.domain(l).nice(),this.canvas.select(".st-xaxis").call(this.xaxis),this.canvas.select(".st-yaxis").call(this.yaxis),this.data.reset(),a(this)},mouseOverAction:function(t,s,e,a){this.tooltips.style("display","inline"),this.tooltips.transition().duration(300).style("opacity",.9);var i=d3.format(".2f");this.tooltips.style("left",d3.event.pageX+10+"px").style("top",d3.event.pageY-10+"px").style("opacity",.9).style("border","dashed").style("border-width","1px").style("padding","3px").style("border-radius","10px").style("z-index","10").style("background-color","white");var r=i(s[e[0]]),o=i(s[e[1]]);d3.selectAll("#tooltips-meta").html(this.opts.xlabel+": "+r+"<br/>"+this.opts.ylabel+": "+o+"<br/>");var l=this;if(a&&""!==a&&s.annos){if(!(a in s.annos))return;var h=s.annos[a],c=d3.selectAll("#tooltips-meta").html();for(var d in h.tooltip)c+=d+": "+h.tooltip[d]+"<br/>";if(d3.selectAll("#tooltips-meta").html(c+"<br/>"),!h.tooltipmol)return;var p=n.util.spinner("#tooltips-meta");this.timeout=setTimeout(function(){var t=[];d3.selectAll("#tooltips-mol").style("display","none");for(var s in h.tooltipmol){var e="#tooltips-mol-"+s;d3.selectAll("#tooltips-mol").append("div").attr("id","tooltips-mol-"+s).style("float","left").style("height","100%").style("width","50%"),d3.selectAll(e).html("<em>"+s+"</em><br/>");var a=l.mol2svg.draw(h.tooltipmol[s],e);t.push(a)}$.when.apply($,t).done(function(){p.css("display","none"),d3.selectAll("#tooltips-mol").style("display","inline")}).fail(function(){p.css("display","none")})},500)}else d3.selectAll("#tooltips-mol").html("")},mouseOutAction:function(){clearTimeout(this.timeout),d3.selectAll("#tooltips-mol").html(""),this.tooltips.transition().duration(300).style("opacity",0),this.tooltips.style("display","none")},renderLegend:function(){d3.select(this.target).select(".st-legend").remove();var t=d3.select(this.target).append("div").attr("class","st-legend").style("top",-(this.height+this.opts.margins[2])+"px").style("left",this.width+this.opts.margins[3]+"px").style("width",this.opts.margins[1]+"px").style("height",this.height/2-30+"px").style("position","relative");t=t.append("div").style("position","absolute").style("overflow","scroll").style("top","0px").style("left","0px").style("width",this.opts.margins[1]+30+"px").style("bottom","-30px");for(var s=this.colors,e=this,a=this.data.raw.series.length,i=t.append("svg:svg").attr("height",20*a+"px"),n=0;a>n;n++){var r=this.data.raw.series[n].id,o=this.data.raw.series[n].title,l=i.append("g").attr("stid",r).style("cursor","pointer");l.append("svg:rect").attr("x",5).attr("y",function(){return 20*n}).attr("width",10).attr("height",10).style("fill",function(){return s.get(r)}),l.append("text").attr("x",20).attr("y",function(){return 20*n+9}).text(function(){return o}),l.on("mouseover",function(){d3.select(this).style("fill","red");var t=d3.select(this).attr("stid");e.canvas.selectAll("."+t).style("stroke-width",2);for(var s in e.data.raw.ids)s!==t&&e.canvas.selectAll("."+s).style("opacity",.1)}),l.on("mouseout",function(){d3.select(this).style("fill","black");var t=d3.select(this).attr("stid");e.canvas.selectAll("."+t).style("stroke-width",1);for(var s in e.data.raw.ids)s!==t&&e.canvas.selectAll("."+s).style("opacity",1)})}},load:function(t){if(!t)return void console.log("Missing data object.");if("function"!=typeof t.push||"function"!=typeof t.add||"function"!=typeof t.remove)return void console.log("Invalid data object.");var s=this;this.data=t;var e=t.add;t.add=function(){try{e.apply(this,arguments),s.data.push(function(){s.xscale(),s.yscale(),s.canvas.select(".st-xaxis").call(s.xaxis),s.canvas.select(".st-yaxis").call(s.yaxis),a(s),s.rendergroups(),s.opts.legend&&s.renderLegend()})}catch(t){console.log("Data load failed: "+t)}};var i=t.remove;t.remove=function(){var t=i.apply(this,arguments);for(var e in t)s.colors.remove(t[e]),s.canvas.selectAll("."+t[e]).remove();s.opts.legend&&s.renderLegend()}}}}function a(t){if("function"==typeof t.renderdata&&"function"==typeof t.renderlabels&&null!==t.data)try{var s=t.renderdata();t.renderlabels(s)}catch(e){t.data.remove(),console.log("Error rendering the data: "+e)}}function i(t){var s=d3.behavior.zoom().y(t.scales.y).center([0,t.scales.y(0)]).on("zoom",function(){a(t)});t.panel.call(s).on("mousedown.zoom",function(){t.mouseDown(this)}).on("mousemove.zoom",function(){t.mouseMove(this)}).on("mouseup.zoom",function(){t.mouseUp()}).on("mouseout",function(){t.mouseOut(this)}).on("dblclick.zoom",function(){t.mouseDbl(this)})}var n={version:"0.0.3"};n.util={},n.util.cache=function(){var t={},s=[],e=function(t){return"[object Object]"===t.toString()?$.param(t):t.toString()},a=function(e,a){-1===s.indexOf(e)&&s.push(e),t[e]=a},i=function(s){return t.hasOwnProperty(s)},n=function(s){var e;return void 0!==t[s]&&(e="[object Object]"===t[s].toString()?$.extend(!0,{},t[s]):t[s]),e},r=function(t){return e(t)};return{add:a,get:n,getKey:r,exists:i}},n.util.colors=function(){var t={0:"red",1:"blue",2:"green",3:"orange",4:"yellow",5:"black"},s={};s.size=function(){var t,s=-1;for(t in this)this.hasOwnProperty(t)&&s++;return s};var e=function(t){if(s[t])return s[t];var e=i();return s[t]=e,s[t]},a=function(t){s[t]&&delete s[t]},i=function(){var e=Object.keys(t).length,a=s.size(),i=a%e;return t[i]};return{get:e,remove:a}},n.util.hashcode=function(t){var s,e,a,i=0;if(0==t.length)return i;for(s=0,a=t.length;a>s;s++)e=t.charCodeAt(s),i=(i<<5)-i+e,i|=0;return i},n.util.domain=function(t,s){var e=t.domain();return e[0]>e[1]?[s[1],s[0]]:[s[0],s[1]]},n.util.mol2svg=function(t,s){var e=t||200,a=s||200,i=null,r=null,o=0,l=n.util.cache(),h=function(t,s){var e,a=d3.select(s),i=l.getKey(t);if(l.exists(i)){var n=l.get(i);c(n,a)}else e=$.when($.get(t)).fail(function(){console.log("Request failed for: "+t)}).then(function(t){l.add(i,t);try{c(t,a)}catch(s){console.log("Mol2Svg Error:"+s),a.html("")}});return e},c=function(t,s){var e=t.split(/\r\n|\n/),a=e[3].match(/\d+/g),i=parseFloat(a[0]),n=parseFloat(a[1]),r=d(e,i),l=p(e,i,n);u(e,r,i+n);var h=f(r,s);v(r,l,h),g(r,o,h)},d=function(t,s){for(var e=[],a=4,i=a;s+a>i;i++){var n=t[i].match(/-*\d+\.\d+|\w+/g);e.push({x:parseFloat(n[0]),y:parseFloat(n[1]),symbol:n[3],mass:0,charge:0})}return e},p=function(t,s,e){for(var a=[],i=4,n=s+i;s+e+i>n;n++){var r=t[n].match(/\d+/g);a.push({a1:parseInt(r[0])-1,a2:parseInt(r[1])-1,order:parseInt(r[2]),stereo:parseInt(r[3])})}return a},u=function(t,s,e){for(var a=4,i=e+a;i<t.length;i++)if(-1!==t[i].indexOf("M ISO"))for(var n=t[i].match(/-*\d+/g),r=0,o=1;r<n[0];r++,o+=2)s[n[o]-1].mass=parseInt(n[o+1],10);else if(-1!==t[i].indexOf("M CHG"))for(var n=t[i].match(/-*\d+/g),r=0,o=1;r<n[0];r++,o+=2)s[n[o]-1].charge=parseInt(n[o+1],10)},f=function(t,s){var n=d3.extent(t,function(t){return t.x}),o=d3.extent(t,function(t){return t.y}),l=[20,20,20,20],h=e-l[1]-l[3],c=a-l[0]-l[2],d=(n[1]-n[0])/(o[1]-o[0]);d>1?c/=d:h*=d,i=d3.scale.linear().domain([n[0],n[1]]).range([0,h]),r=d3.scale.linear().domain([o[0],o[1]]).range([c,0]);var p=s.append("svg:svg").attr("width",h+l[1]+l[3]).attr("height",c+l[0]+l[2]).append("svg:g").attr("transform","translate("+l[3]+","+l[0]+")");return p},v=function(t,s,e){for(var a=0;a<s.length;a++){var n=t[s[a].a1],l=t[s[a].a2],h=l.x-n.x,c=l.y-n.y,d=Math.sqrt(h*h+c*c),p=h/d*.2,u=c/d*.2,f=n.x+p,v=n.y+u,g=l.x-p,A=l.y-u;o+=m(i(f),r(v),i(g),r(A));var k,O,I,M=[];if(1===s[a].order)if(1===s[a].stereo){var z=m(f,v,g,A);k=.1,O=k*(A-v)/z,I=k*(f-g)/z,M=[[f,v],[g+O,A+I],[g-O,A-I]],e.append("svg:path").style("fill","black").style("stroke-width",1).attr("d",y(M))}else if(6===s[a].stereo){k=.2,O=k*(A-v)/d,I=k*(f-g)/d;for(var F=g+O-f,N=A+I-v,T=g-O-f,$=A-I-v,L=.05;1>=L;L+=.15)M.push([f+F*L,v+N*L],[f+T*L,v+$*L]);e.append("svg:path").style("fill","none").style("stroke-width",1).attr("d",w(M)).attr("stroke","black")}else if(4===s[a].stereo){k=.2,O=k*(A-v)/d,I=k*(f-g)/d;for(var F=g+O-f,N=A+I-v,T=g-O-f,$=A-I-v,L=.05;1>=L;L+=.1)M.push(M.length%2===0?[f+F*L,v+N*L]:[f+T*L,v+$*L]);e.append("svg:path").attr("d",b(M)).attr("fill","none").style("stroke-width",1).attr("stroke","black")}else M=[[f,v],[g,A]],e.append("svg:path").attr("d",x(M)).attr("stroke-width","1").attr("stroke-linecap","round").attr("stroke-linejoin","round").attr("stroke","black");else 2===s[a].order?(k=.1,O=k*(A-v)/d,I=k*(f-g)/d,M=[[f+O,v+I],[g+O,A+I],[f-O,v-I],[g-O,A-I]],e.append("svg:path").attr("d",x(M)).attr("stroke-width","1").style("fill","none").attr("stroke-linecap","round").attr("stroke-linejoin","round").attr("stroke","black")):3===s[a].order&&(k=.15,O=k*(A-v)/d,I=k*(f-g)/d,M=[[f,v],[g,A],[f+O,v+I],[g+O,A+I],[f-O,v-I],[g-O,A-I]],e.append("svg:path").attr("d",x(M)).attr("stroke-width","1").attr("stroke-linecap","round").attr("stroke-linejoin","round").attr("stroke","black"))}o/=s.length},g=function(t,s,e){for(var a=0;a<t.length;a++){var n=t[a],o=d3.rgb(A[n.symbol]),l=e.append("svg:g").attr("transform","translate("+i(n.x)+","+r(n.y)+")");if(l.append("svg:circle").attr("r",Math.ceil(s/3)).attr("fill","white").attr("opacity","1"),l.append("text").attr("dy",Math.ceil(s/4.5)).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size",Math.ceil(s/1.5)).attr("fill",o).text(n.symbol),0!==n.charge){var h=n.charge;h=0>h?-1===h?"-":h+"-":1===h?"+":h+"+",l.append("text").attr("dx",1*Math.ceil(s/3)).attr("dy",-1*Math.ceil(s/4.5)).attr("text-anchor","left").attr("font-family","sans-serif").attr("fill",o).attr("font-size",Math.ceil(s/3)).text(h)}0!==n.mass&&l.append("text").attr("dx",-2*Math.ceil(s/3)).attr("dy",-1*Math.ceil(s/4.5)).attr("text-anchor","left").attr("font-family","sans-serif").attr("font-size",Math.ceil(s/3)).attr("fill",o).text(n.mass)}},m=function(t,s,e,a){return Math.sqrt((e-t)*(e-t)+(a-s)*(a-s))},x=d3.svg.line().interpolate(function(t){for(var s=t[0][0]+","+t[0][1],e=1;e<t.length;e++)s+=e%2===0?"M"+t[e][0]+","+t[e][1]:"L"+t[e][0]+","+t[e][1];return s}).x(function(t){return i(t[0])}).y(function(t){return r(t[1])}),y=d3.svg.line().x(function(t){return i(t[0])}).y(function(t){return r(t[1])}),w=d3.svg.line().interpolate(function(t){for(var s=t[0][0]+","+t[0][1],e=1;e<t.length;e++)s+=e%2===0?"M"+t[e][0]+","+t[e][1]:"L"+t[e][0]+","+t[e][1];return s}).x(function(t){return i(t[0])}).y(function(t){return r(t[1])}),b=d3.svg.line().interpolate("cardinal").x(function(t){return i(t[0])}).y(function(t){return r(t[1])}),A={H:"#000000",He:"#FFC0CB",Li:"#B22222",B:"#00FF00",C:"#000000",N:"#8F8FFF",O:"#F00000",F:"#DAA520",Na:"#0000FF",Mg:"#228B22",Al:"#808090",Si:"#DAA520",P:"#FFA500",S:"#FFC832",Cl:"#00FF00",Ca:"#808090",Ti:"#808090",Cr:"#808090",Mn:"#808090",Fe:"#FFA500",Ni:"#A52A2A",Cu:"#A52A2A",Zn:"#A52A2A",Br:"#A52A2A",Ag:"#808090",I:"#A020F0",Ba:"#FFA500",Au:"#DAA520"};return{draw:h}},n.util.spinner=function(t){return $(".st-spinner").length?$(".st-spinner"):($(t).append('<div class="st-spinner"><div class="st-bounce1"></div><div class="st-bounce2"></div><div class="st-bounce3"></div></div>'),$(".st-spinner"))},n.util.compare=function(t){var s=function(s,e){return s[t]<e[t]?-1:s[t]>e[t]?1:0};return s},n.annotation={TOOLTIP:"tooltip",TOOLTIP_MOL:"tooltip_mol",ANNOTATION:"annotation",ANNOTATION_COLOR:"annotation_color"},n.parser={},n.parser.jdx=function(t,s){d3.text(t,function(t){var e,a,i,n,r="##",o="END",l="XYDATA",h="(X++(Y..Y))",c="YFACTOR",d="FIRSTX",p="LASTX",u=[],f={},v=!1,g=[],m=t.split(/\r\n|\r|\n/g);for(var x in m){var y=m[x];if(0===y.indexOf(r)){if(e=y.split(/=\s(.*)/),e.length<2)continue;a=e[0].slice(2),n=e[1].split(/\$\$(.*)/)[0].trim(),a===l&&n===h?v=!0:a===o?(v&&(parseFloat(f[d])>parseFloat(f[p])&&g.reverse(),f[i]=g,u.push(f),f={},v=!1,g=[]),v=!1):f[a]=n,i=a}else if(v)for(var w=y.match(/(\+|-)*\d+\.*\d*/g),b=1;b<w.length;b++){var A=f[c]*w[b];g.push(A)}}s(u)})},n.data={},n.data.set=function(){var e=t();return e.x=function(t){return t&&"string"==typeof t?this.opts.x=t:console.log("Invalid y accessor option."),this},e.get=function(t,s){var e=[],a=[s.invert(0),s.invert(t)];a=n.util.domain(s,a);for(var i in this.raw.series){var r=this.raw.series[i],o=[];for(var l in r.data){var h=r.x(l);h>=a[0]&&h<=a[1]&&o.push(r.data[l])}e.push(o)}return e},e.bin=function(t,s,e){var a=[],i=[s.invert(0),s.invert(t)];i=n.util.domain(s,i);var r=1,o=0;for(var l in this.raw.series){var h=this.raw.series[l].size;h[2]=Math.ceil(t/r),o<h[2]&&(o=h[2])}var c=Math.abs(i[1]-i[0])/(o-1);for(var l in this.raw.series){for(var d=this.raw.series[l],p=d.data.length,h=d.size,u=[],f=0;h[0]>0;){var v=d.x(h[0]);if(v<i[0])break;h[0]-=1}for(;h[1]<p;){var v=d.x(h[1]);if(v>i[1])break;h[1]+=1}for(var g=h[0];g<h[1];g++){var v=d.x(g);if(v<i[0])h[0]=g;else{if(v>i[1]){h[1]=g;break}var m=Math.floor((v-i[0])/c),x=u[m-f],y=d.data[g];x?e?x[d.accs[1]]<y[d.accs[1]]?u[m-f]=x:(x.annos&&!y.annos&&(y.annos=x.annos),u[m-f]=y):Math.abs(x[d.accs[1]])>Math.abs(y[d.accs[1]])?u[m-f]=x:(x.annos&&!y.annos&&(y.annos=x.annos),u[m-f]=y):(f=m-u.length,u[m-f]=y)}}f>0&&(h[2]=u.length),d.size=h,a.push(u)}return a},e.seriesfetch=function(t,a){var i=n.util.hashcode((new Date).getTime()*Math.random()+"");i="st"+i;var r=t[e.opts.title],o=[],l=[],h=[],c=this.opts.x,d=this.opts.y;if(r&&0!==r.length||(r=i),i in this.raw.ids)return void console.log("SpeckTackle: Non unique identifier: "+i);var p="";-1!==c.lastIndexOf(".")&&(p=c.substr(0,c.lastIndexOf(".")),c=c.substr(c.lastIndexOf(".")+1),d=d.substr(d.lastIndexOf(".")+1));var u=""===p?t:t[p];if(!(u instanceof Array)){var f=[];for(var v in u[c]){var g={};g[c]=u[c][v],g[d]=u[d][v],f.push(g)}u=f}if(o=s(u,t,this.opts.xlimits,c),l=s(u,t,this.opts.ylimits,d),h=[0,u.length,0],a){u.sort(n.util.compare(c));var m=d3.bisector(function(t){return t[c]}).left,x=this.opts.annoTypes.length;for(var v in a)if(a[v].length-2===x){var y=a[v][0];y in this.raw.annoGroups||(this.raw.annoGroups[y]=0);var w=a[v][1],b=m(u,w);if(-1!==b&&w===u[b][c]){var A=u[b];A.annos||(A.annos={});var k=A.annos;y in k||(k[y]={});for(var O=k[y],I=0;x>I;I++){var M=this.opts.annoTypes[I],z=a[v][I+2];M===n.annotation.ANNOTATION?O.annotation=z:M===n.annotation.TOOLTIP?(O.tooltip||(O.tooltip={}),O.tooltip[this.opts.annoTexts[I]]=z):M===n.annotation.TOOLTIP_MOL&&""!==z&&(O.tooltipmol||(O.tooltipmol={}),O.tooltipmol[this.opts.annoTexts[I]]=z)}}}}o[0]<this.raw.gxlim[0]&&(this.raw.gxlim[0]=o[0]),l[0]<this.raw.gylim[0]&&(this.raw.gylim[0]=l[0]),o[1]>this.raw.gxlim[1]&&(this.raw.gxlim[1]=o[1]),l[1]>this.raw.gylim[1]&&(this.raw.gylim[1]=l[1]),this.raw.ids[i]=!0,this.raw.series.push({id:i,title:r,xlim:o,ylim:l,accs:[c,d],size:h,data:u,x:function(t){return this.data[t][this.accs[0]]},y:function(t){return this.data[t][this.accs[1]]}})},e},n.data.array=function(){var e=t();return e.get=function(t,s){var e=[],a=[s.invert(0),s.invert(t)];a=n.util.domain(s,a);for(var i in this.raw.series){for(var r=this.raw.series[i],o=r.data.length,l=(r.xlim[1]-r.xlim[0])/o,h=r.size,c=[];r.size[0]>0;){var d=r.size[0]*l+r.xlim[0];if(d<a[0])break;r.size[0]-=1}for(;r.size[1]<o;){var d=r.size[1]*l+r.xlim[0];if(d>a[1])break;r.size[1]+=1}for(var p=r.size[0];p<r.size[1];p++){var d=p*l+r.xlim[0];if(d<a[0])h[0]=p;else{if(d>a[1]){h[1]=p;break}var u=r.data[p],f={x:d};f[r.accs[1]]=u,c.push(f)}}r.size=h,e.push(c)}return e},e.bin=function(t,s,e){var a=[],i=[s.invert(0),s.invert(t)];i=n.util.domain(s,i);var r=1,o=0;for(var l in this.raw.series){var h=this.raw.series[l].size;h[2]=Math.ceil(t/r),o<h[2]&&(o=h[2])}var c=Math.abs(i[1]-i[0])/(o-1);for(var l in this.raw.series){for(var d=this.raw.series[l],p=d.data.length,u=(d.xlim[1]-d.xlim[0])/p,h=d.size,f=[],v=0;d.size[0]>0;){var g=d.size[0]*u+d.xlim[0];if(g<i[0])break;d.size[0]-=1}for(;d.size[1]<p;){var g=d.size[1]*u+d.xlim[0];if(g>i[1])break;d.size[1]+=1}for(var m=d.size[0];m<d.size[1];m++){var g=m*u+d.xlim[0];if(g<i[0])h[0]=m;else{if(g>i[1]){h[1]=m;break}var x=Math.floor((g-i[0])/c),y=f[x-v],w=d.data[m];if(y)if(e)if(y[d.accs[1]]<w)f[x-v]=y;else{var b={x:g};b[d.accs[1]]=w;var A=f[x-v];A.annos&&(b.annos=f[x-v].annos),f[x-v]=b}else if(Math.abs(y[d.accs[1]])>Math.abs(w))f[x-v]=y;else{var b={x:g};b[d.accs[1]]=w;var A=f[x-v];A.annos&&(b.annos=A.annos),f[x-v]=b}else v=x-f.length,f[x-v]={x:g},f[x-v][d.accs[1]]=w;if(d.annos&&Object.keys(d.annos).length&&m in d.annos&&!f[x-v].annos){var k=f[x-v],O=d.annos[m],I=O[0];I in this.raw.annoGroups||(this.raw.annoGroups[I]=0),k.annos||(k.annos={});var M=k.annos;I in M||(M[I]={});for(var z=M[I],F=0;F<O.length;F++){var N=this.opts.annoTypes[F],T=O[F+2];N===n.annotation.ANNOTATION?z.annotation=T:N===n.annotation.TOOLTIP?(z.tooltip||(z.tooltip={}),z.tooltip[this.opts.annoTexts[F]]=T):N===n.annotation.TOOLTIP_MOL&&""!==T&&(z.tooltipmol||(z.tooltipmol={}),z.tooltipmol[this.opts.annoTexts[F]]=T)}f[x-v]=k}}}v>0&&(h[2]=f.length),d.size=h,a.push(f)}return a},e.seriesfetch=function(t,e){var a=n.util.hashcode((new Date).getTime()*Math.random()+"");a="st"+a;var i=t[this.opts.title],r=[],o=[],l=[],h="x",c=this.opts.y;if(i&&0!==i.length||(i=a),a in this.raw.ids)return void console.log("SpeckTackle: Non unique identifier: "+a);var d=""===c?t:t[c];r=s(d,t,this.opts.xlimits,h),o=s(d,t,this.opts.ylimits),l=[0,d.length,0];var p={};if(e){var u=this.opts.annoTypes.length;for(var f in e)if(e[f].length-2===u){var v=e[f][1];v<l[1]&&(p[v]=e[f])}}r[0]<this.raw.gxlim[0]&&(this.raw.gxlim[0]=r[0]),o[0]<this.raw.gylim[0]&&(this.raw.gylim[0]=o[0]),r[1]>this.raw.gxlim[1]&&(this.raw.gxlim[1]=r[1]),o[1]>this.raw.gylim[1]&&(this.raw.gylim[1]=o[1]),this.raw.ids[a]=!0,this.raw.series.push({id:a,title:i,xlim:r,ylim:o,accs:[h,c],size:l,annos:p,data:d,x:function(t){return t},y:function(t){return this.data[t][this.accs[1]]}})},e},n.chart={},n.chart.series=function(){var t=e();return t.xscale=function(){var t=this.data.raw.gxlim;this.opts.xreverse&&(t=[t[1],t[0]]),this.scales.x.domain(t).nice()},t.yscale=function(){this.scales.y.domain(this.data.raw.gylim).nice()},t.behavior=function(){this.xpointer=this.panel.append("text").attr("x",this.opts.margins[3]).attr("y",this.opts.margins[0]).attr("font-size","x-small").text("");var t=this,s=d3.format(".4g");this.plotted=[],this.panel.on("mousemove",function(){var e=d3.mouse(this)[0]-t.opts.margins[3],a=t.scales.x.invert(e),i=t.scales.x.domain();if(t.opts.xreverse)var n=function(){return a<i[0]&&a>=i[1]};else var n=function(){return a>=i[0]&&a<i[1]};if(n()){t.xpointer.text("x = "+s(a));for(var r=0;r<t.plotted.length;r++){var o=t.data.accs(r),l=d3.bisector(function(t){return t[o[0]]}).left,h=l(t.plotted[r],a);h>t.plotted[r].length-1&&(h=t.plotted[r].length-1);var c=t.plotted[r][h];
if(c){var d=t.scales.y(c[o[1]]);0>d?d=0:d>t.height&&(d=t.height),t.canvas.select("."+t.data.id(r)+"focus").attr("display","inline").attr("transform","translate("+t.scales.x(c[o[0]])+","+d+")")}}}else{t.xpointer.text("");for(var r=0;r<t.plotted.length;r++)t.canvas.select("."+t.data.id(r)+"focus").attr("display","none")}})},t.renderdata=function(){var t=this.data.bin(this.width,this.scales.x);this.plotted=t;for(var s=this,e=0;e<t.length;e++){var a=t[e],i=this.data.id(e),n=this.data.accs(e),r=this.colors.get(i),o=d3.svg.line().interpolate("cardinal-open").x(function(t){return s.scales.x(t[n[0]])}).y(function(t){return s.scales.y(t[n[1]])});this.canvas.selectAll("."+i).remove();var l=this.canvas.append("g").attr("class",i);l.append("svg:path").attr("clip-path","url(#clip-"+this.target+")").style("stroke",r).style("fill","none").style("stroke-width",1).attr("d",o(a)),l.append("svg:circle").attr("class",i+"focus").style("stroke",r).style("fill","none").attr("r",3).attr("cx",0).attr("cy",0).attr("display","none"),l.selectAll("."+i+".circle").data(a).enter().append("svg:circle").attr("clip-path","url(#clip-"+this.target+")").style("fill",r).style("stroke",r).attr("opacity",0).attr("r",3).attr("cx",function(t){return s.scales.x(t[n[0]])}).attr("cy",function(t){return s.scales.y(t[n[1]])}).on("mouseover",function(t){d3.select(this).attr("opacity",.8),s.mouseOverAction(this,t,n)}).on("mouseout",function(){d3.select(this).attr("opacity","0"),s.mouseOutAction()})}return t},t},n.chart.ms=function(){var t=e();return t.xscale=function(){this.scales.x.domain(this.data.raw.gxlim).nice()},t.yscale=function(){this.scales.y.domain(this.data.raw.gylim).nice()},t.behavior=function(){},t.renderdata=function(){var t=this.data.bin(this.width,this.scales.x),s="";for(var e in this.data.raw.annoGroups)if(this.data.raw.annoGroups[e]){s=e;break}for(var a=this,i=0;i<t.length;i++){var n=t[i],r=this.data.id(i),o=this.data.accs(i),l=a.colors.get(r);this.canvas.selectAll("."+r).remove();var h=this.canvas.append("g").attr("class",r);h.selectAll("."+r+".line").data(n).enter().append("svg:line").attr("clip-path","url(#clip-"+this.target+")").attr("x1",function(t){return a.scales.x(t[o[0]])}).attr("y1",function(t){return a.scales.y(t[o[1]])}).attr("x2",function(t){return a.scales.x(t[o[0]])}).attr("y2",a.scales.y(0)).style("stroke",l).each(function(t){if(t.annos){if(!(s in t.annos))return;h.append("text").attr("class",r+".anno").attr("x",a.scales.x(t[o[0]])).attr("y",a.scales.y(t[o[1]])-5).attr("text-anchor","middle").attr("font-size","small").attr("fill",l).text(t.annos[s].annotation)}}).on("mouseover",function(t){d3.select(this).attr("stroke-width",2),a.mouseOverAction(this,t,o,s)}).on("mouseout",function(){d3.select(this).attr("stroke-width",null),a.mouseOutAction()})}return this.canvas.selectAll(".zeroline").remove(),this.data.raw.gylim[0]<0&&this.canvas.append("svg:line").attr("class","zeroline").attr("clip-path","url(#clip-"+this.target+")").attr("x1",this.scales.x(this.data.raw.gxlim[0])).attr("y1",this.scales.y(0)).attr("x2",this.scales.x(this.data.raw.gxlim[1])).attr("y2",this.scales.y(0)).style("stroke","#333333"),t},t},n.chart.ir=function(){var t=e();return t.xscale=function(){this.scales.x.domain([this.data.raw.gxlim[1],this.data.raw.gxlim[0]]).nice()},t.yscale=function(){this.scales.y.domain(this.data.raw.gylim).nice()},t.behavior=function(){this.scales.x.domain([1,0]),this.xpointer=this.panel.append("text").attr("x",this.opts.margins[3]).attr("y",this.opts.margins[0]).attr("font-size","x-small").text("");var t=this,s=d3.format(".4g");this.plotted=[],this.panel.on("mousemove",function(){var e=d3.mouse(this)[0]-t.opts.margins[3],a=t.scales.x.invert(e),i=t.scales.x.domain();if(a<i[0]&&a>=i[1]){t.xpointer.text("x = "+s(a));for(var n=0;n<t.plotted.length;n++){var r=t.data.accs(n),o=d3.bisector(function(t){return t[r[0]]}).left,l=o(t.plotted[n],a);l>t.plotted[n].length-1&&(l=t.plotted[n].length-1);var h=t.plotted[n][l];if(h){var c=t.scales.y(h[r[1]]);0>c?c=0:c>t.height&&(c=t.height),t.canvas.select("."+t.data.id(n)+"focus").attr("display","inline").attr("transform","translate("+t.scales.x(h[r[0]])+","+c+")")}}}else{t.xpointer.text("");for(var n=0;n<t.plotted.length;n++)t.canvas.select("."+t.data.id(n)+"focus").attr("display","none")}})},t.renderdata=function(){var t=this.data.bin(this.width,this.scales.x,!0),s="";for(var e in this.data.raw.annoGroups)if(this.data.raw.annoGroups[e]){s=e;break}this.data.raw.minima=1,this.plotted=t;for(var a=this,i=0;i<t.length;i++){var n=t[i],r=this.data.id(i),o=this.data.accs(i),l=this.colors.get(r),h=d3.svg.line().interpolate("cardinal-open").x(function(t){return a.scales.x(t[o[0]])}).y(function(t){return a.scales.y(t[o[1]])});this.canvas.selectAll("."+r).remove();var c=this.canvas.append("g").attr("class",r);c.append("svg:path").attr("clip-path","url(#clip-"+this.target+")").style("stroke",l).style("fill","none").attr("d",h(n)),c.append("svg:circle").attr("class",r+"focus").style("stroke",l).style("fill","none").attr("r",3).attr("cx",0).attr("cy",0).attr("display","none"),c.selectAll("."+r+".circle").data(n).enter().append("svg:circle").attr("clip-path","url(#clip-"+this.target+")").style("fill",l).style("stroke",l).attr("opacity",0).attr("r",3).attr("cx",function(t){return a.scales.x(t[o[0]])}).attr("cy",function(t){return a.scales.y(t[o[1]])}).each(function(t){if(t.annos){if(!(s in t.annos))return;c.append("text").attr("class",r+".anno").attr("x",a.scales.x(t[o[0]])).attr("y",a.scales.y(t[o[1]])+20).attr("text-anchor","middle").attr("font-size","small").attr("fill",l).text(t.annos[s].annotation)}}).on("mouseover",function(t){d3.select(this).attr("opacity",.8),a.mouseOverAction(this,t,o,s)}).on("mouseout",function(){d3.select(this).attr("opacity","0"),a.mouseOutAction()})}return t},t},n.chart.nmr=function(){var t=e();return t.render=function(t){this.target=t;var s=this.opts.margins;if(this.width=$(t).width()-s[1]-s[3],this.height=$(t).height()-s[0]-s[2],this.width<=0)return void console.log("Invalid chart width: "+this.width);if(this.height<=0)return void console.log("Invalid chart height: "+this.height);var e=this;if(this.scales={x:d3.scale.linear().domain([1,0]).range([0,this.width]),y:d3.scale.linear().range([this.height,0])},this.panel=d3.select(t).append("svg:svg").attr("class","st-base").attr("width",this.width+s[1]+s[3]).attr("height",this.height+s[0]+s[2]),i(e),this.canvas=this.panel.append("svg:g").attr("transform","translate("+s[3]+","+s[0]+")"),this.canvas.append("svg:clipPath").attr("id","clip-"+this.target).append("svg:rect").attr("x",0).attr("y",0).attr("width",this.width).attr("height",this.height),this.selection=this.canvas.append("svg:rect").attr("class","st-selection").attr("clip-path","url(#clip-"+this.target+")").attr("x",0).attr("y",0).attr("width",0).attr("height",0).style("pointer-events","none").attr("display","none"),this.renderAxes(),this.opts.title&&0!==this.opts.title.length&&(s[0]<20?console.log("Not enough space for chart title: increase top margin (min 20)"):this.panel.append("text").attr("class","st-title").attr("x",s[3]+this.width/2).attr("y",.75*s[0]).attr("text-anchor","middle").attr("font-size","large").text(this.opts.title)),this.opts.labels){if(s[1]<60)return void console.log("Not enough space for label option: increase right margin (min 60)");var n=this.canvas.append("g").attr("id","st-options");n.append("text").attr("x",this.width).attr("y",this.height-this.height/4).text("Options");var r=n.append("g");r.append("svg:circle").attr("cx",this.width+5).attr("cy",this.height-this.height/5).attr("r",2).style("fill","#333333").style("stroke","#333333"),r.append("text").attr("x",this.width+12).attr("y",this.height-this.height/5+2).text("Labels").attr("id","st-label").style("cursor","pointer"),r.on("mousedown",function(){var t=d3.select(this);"none"===t.style("stroke")?t.style("stroke","#333333"):t.style("stroke","none"),a(e)})}return this},t.xscale=function(){this.scales.x.domain([this.data.raw.gxlim[1],this.data.raw.gxlim[0]]).nice()},t.yscale=function(){this.scales.y.domain(this.data.raw.gylim)},t.renderAxes=function(){var t=this.opts.margins,s=d3.format(".4g");this.xaxis=d3.svg.axis().scale(this.scales.x).ticks(6).tickSubdivide(!0).tickFormat(s).orient("bottom"),this.canvas.append("svg:g").attr("class","st-xaxis").attr("transform","translate(0,"+this.height+")").call(this.xaxis),""!==this.opts.xlabel&&this.panel.select(".st-xaxis").append("text").text(this.opts.xlabel).attr("text-anchor","middle").attr("x",this.width/2).attr("y",t[2]/2)},t.mouseDown=function(t){var s=d3.mouse(t),e=this.opts.margins[3];this.panel.select(".st-selection").attr("x",s[0]-e).attr("xs",s[0]-e).attr("width",1).attr("height",this.height).attr("display","inline")},t.mouseMove=function(t){var s=this.panel.select(".st-selection");if("inline"===s.attr("display")){var e=d3.mouse(t)[0]-this.opts.margins[3],a=parseInt(s.attr("width"),10),i=e-parseInt(s.attr("x"),10),n=parseInt(s.attr("xs"),10);1>i&&a>2*i?(s.attr("x",e),s.attr("width",n-e)):s.attr("width",i)}},t.mouseUp=function(){var t=5,s=this.panel.select(".st-selection");if(parseInt(s.attr("width"))>t){var e=parseFloat(s.attr("x")),i=parseFloat(s.attr("width"));i=this.scales.x.invert(e+i),e=this.scales.x.invert(e),this.scales.x.domain([e,i]).nice(),s.attr("display","none"),this.canvas.select(".st-xaxis").call(this.xaxis),a(this)}else s.attr("display","none")},t.mouseDbl=function(t){if(t){var s=d3.mouse(t)[0]-this.opts.margins[3],e=d3.mouse(t)[1]-this.opts.margins[0];if(0>s||s>this.width||0>e||e>this.height)return}return null===this.data?(this.scales.x.domain([1,0]).nice(),this.scales.y.domain([0,1]).nice(),void this.canvas.select(".st-xaxis").call(this.xaxis)):(this.scales.x.domain([this.data.raw.gxlim[1],this.data.raw.gxlim[0]]).nice(),this.scales.y.domain(this.data.raw.gylim),this.canvas.select(".st-xaxis").call(this.xaxis),void a(this))},t.load=function(t){if(!t)return void console.log("Missing data object.");if("function"!=typeof t.push||"function"!=typeof t.add||"function"!=typeof t.remove)return void console.log("Invalid data object.");var s=this;this.data=t;var e=t.add;t.add=function(){e.apply(this,arguments),s.data.push(function(){s.xscale(),s.yscale(),i(s),s.canvas.select(".st-xaxis").call(s.xaxis),a(s),s.rendergroups(),s.opts.legend&&s.renderLegend()})};var n=t.remove;t.remove=function(){var t=n.apply(this,arguments);for(var e in t)s.colors.remove(t[e]),s.canvas.selectAll("."+t[e]).remove();s.opts.legend&&s.renderLegend()}},t.renderdata=function(){var t=this.data.bin(this.width,this.scales.x),s="";for(var e in this.data.raw.annoGroups)if(this.data.raw.annoGroups[e]){s=e;break}for(var a=this,i=0;i<t.length;i++){var n=t[i],r=this.data.id(i),o=this.data.accs(i),l=d3.svg.line().x(function(t){return a.scales.x(t[o[0]])}).y(function(t){return a.scales.y(t[o[1]])});this.canvas.selectAll("."+r).remove();var h=this.canvas.append("g").attr("class",r);h.append("svg:path").attr("clip-path","url(#clip-"+this.target+")").style("stroke",this.colors.get(r)).style("fill","none").style("stroke-width",1).attr("d",l(n)),h.data(n).each(function(t){if(t.annos){if(!(s in t.annos))return;h.append("text").attr("class",r+".anno").attr("x",a.scales.x(t[o[0]])).attr("y",a.scales.y(t[o[1]])-5).attr("text-anchor","middle").attr("font-size","small").attr("fill",color).text(t.annos[s].annotation)}})}return t},t},n.chart.nmr2d=function(){var t=e();return t.xscale=function(){this.scales.x.domain([this.data.raw.gxlim[1],this.data.raw.gxlim[0]]).nice()},t.yscale=function(){this.scales.y.domain([this.data.raw.gylim[1],this.data.raw.gylim[0]]).nice()},t.behavior=function(){this.scales.x.domain([1,0]),this.scales.y.domain([1,0]);var t=this.canvas.append("svg:rect").attr("class","st-selection").attr("y",0).attr("width",1).attr("height",this.height).style("pointer-events","none").attr("visibility","hidden"),s=this.canvas.append("svg:rect").attr("class","st-selection").attr("x",0).attr("width",this.width).attr("height",1).style("pointer-events","none").attr("visibility","hidden"),e=this;d3.select(".st-base").on("mousemove",function(){var a=d3.mouse(this)[0]-e.opts.margins[3],i=d3.mouse(this)[1]-e.opts.margins[0];0>a||a>e.width||0>i||i>e.height?(t.attr("visibility","hidden"),s.attr("visibility","hidden")):(t.attr("x",a),s.attr("y",i),t.attr("visibility","visible"),s.attr("visibility","visible"))}).append("svg:rect").attr("class","st-mouse-capture").style("visibility","hidden").attr("x",0).attr("y",0).attr("width",this.width).attr("height",this.height)},t.renderAxes=function(){var t=this.opts.margins,s=d3.format(".3g");this.xaxis=d3.svg.axis().scale(this.scales.x).ticks(6).tickSubdivide(!0).tickFormat(s).tickSize(-this.height).tickPadding(5).orient("bottom"),this.yaxis=d3.svg.axis().scale(this.scales.y).ticks(6).tickFormat(s).tickSize(-this.width).tickPadding(5).orient("right"),this.canvas.append("svg:g").attr("class","st-xaxis").attr("transform","translate(0,"+this.height+")").call(this.xaxis),this.canvas.append("svg:g").attr("class","st-yaxis").attr("transform","translate("+this.width+",0)").call(this.yaxis),""!==this.opts.xlabel&&d3.select(".st-xaxis").append("text").text(this.opts.xlabel).attr("text-anchor","middle").attr("x",this.width/2).attr("y",t[2]/2),""!==this.opts.ylabel&&d3.select(".st-yaxis").append("text").text(this.opts.ylabel).attr("transform","rotate (-90)").attr("text-anchor","middle").attr("x",0-this.height/2).attr("y",t[1]/2)},t.renderdata=function(){for(var t=this.data.get(this.width,this.scales.x),s=this,e=0;e<t.length;e++){var a=t[e],i=this.data.id(e),n=this.data.accs(e);this.canvas.selectAll("."+i).remove();var r=this.canvas.append("g").attr("class",i);r.selectAll("."+i+".circle").data(a).enter().append("svg:circle").attr("clip-path","url(#clip-"+this.target+")").style("fill",this.colors.get(i)).style("stroke",this.colors.get(i)).attr("r",3).attr("cx",function(t){return s.scales.x(t[n[0]])}).attr("cy",function(t){return s.scales.y(t[n[1]])}).on("mouseover",function(t){s.mouseOverAction(this,t,n)}).on("mouseout",function(){s.mouseOutAction()})}},t},"function"==typeof define&&define.amd?define(n):"object"==typeof module&&module.exports?module.exports=n:this.st=n}();