text: // Copyright 2015 Olaf Frohn https://github.com/ofrohn, see LICENSE
  !function(){function t(t){var e=I(f,t);return e[0]*=P,e[2]*=P,[e[0]+z.h,-e[2]+z.v]}function e(t){d3.select("#ae").style("background",function(){return"ae"===t?N:A}),d3.select("#ai").style("background",function(){return"ai"===t?N:A}),d3.select("#ei").style("background",function(){return"ei"===t?N:A}),H.translate([E.invert(S[2]),E.invert(S[0])]),a()}function a(){if(P=H.scale(),d3.event&&d3.event.sourceEvent&&"wheel"!==d3.event.sourceEvent.type){var t=H.translate();S=[E(t[1]),0,E(t[0])]}f=q(S),u.clearRect(0,0,m+2*v.h,y+2*v.v);for(var e in h)h[e](u);for(var a=0;a<T.length;a++)o(T[a]);if(w){for(u.textAlign="center",u.textBaseline="middle",u.font=d,u.globalAlpha=.7,a=0;a<F.length;a++){var n=F[a];u.fillStyle=n.col,c(n.n,n.pos)}u.globalAlpha=1}}function r(t){m=t-2*v.h,y=t-2*v.v,x=m/2,z={h:x+v.h,v:x+v.h},j.ap.range([-x,x]),j.ep.range([-x,x]),j.ip.range([-x,x]),E.domain([-x,x])}function o(e){u.fillStyle=e.col;var a=t(e.pos);u.beginPath(),u.arc(a[0],a[1],e.r,0,2*Math.PI),u.closePath(),u.fill()}function i(e){var a;u.beginPath();for(var n=0;n<e.length;n++)a=t(e[n]),0===n?u.moveTo(a[0],a[1]):u.lineTo(a[0],a[1]);u.stroke()}function c(e,a,n){var r=t(a);n?(u.save(),u.translate(r[0],r[1]),u.rotate(Math.PI/2),u.fillText(e,0,0),u.restore()):u.fillText(e,r[0],r[1])}function s(t,e){return null!==t&&hasOwnProperty.call(t,e)}function l(t){var e=255*(parseFloat(t.astar)+.3)*2;0>e&&(e=0),e>255&&(e=255);var a=255-e,n=255*(parseFloat(t.iz)+.5)*1.42;return 0>n&&(n=0),n>255&&(n=255),t.iz<0&&(e*=1+parseFloat(t.iz)),"rgb("+Math.floor(e)+","+Math.floor(255-n)+","+Math.floor(a)+")"}var f,u,h,b={version:"0.1",svg:null},g="ast-proper14.csv",k="./data/",p=14,d="12px sans-serif",v={h:40,v:20},m=640-2*v.h,y=640-2*v.v,x=m/2,z={h:x+v.h,v:x+v.h},P=.9,w=!0,M={ae:[0,0,0],ai:[90,0,0],ei:[0,0,-90]},S=M.ae,A="rgba(255,255,255,0.1)",N="rgba(255,255,255,0.3)",T=[],F=[],j={ap:d3.scale.linear().domain([2,3.7]).range([-x,x]),ep:d3.scale.linear().domain([0,.3]).range([-x,x]),ip:d3.scale.linear().domain([0,.3]).range([-x,x])},E=d3.scale.linear().domain([-x,x]).range([-90,90]),H=d3.behavior.zoom().center([0,0]).scaleExtent([.7,3]).scale(P).on("zoom",a);b.display=function(t){t&&(s(t,"width")&&r(t.width),s(t,"datapath")&&(k=t.datapath)),u=d3.select("#map").append("canvas").attr("width",m+2*v.h).attr("height",y+2*v.v).call(H).node().getContext("2d");var n=d3.select("#map").append("div").attr("class","ctrl").html("Show ");n.append("button").attr("class","button").style("background",N).attr("id","ae").html("a vs. e").on("click",function(){S=M.ae,e("ae")}),n.append("button").attr("class","button").attr("id","ai").html("a vs. sin i").on("click",function(){S=M.ai,e("ai")}),n.append("button").attr("class","button").attr("id","ei").html("e vs. sin i").on("click",function(){S=M.ei,e("ei")}),n.append("button").attr("class","button").attr("id","names").html("No Names").on("click",function(){w=!w,d3.select("#names").html(function(){return w?"No Names":"Names"}),a()}),h={x:R().scale(j.ap).ticks(17).tickPadding(6).title("aₚ / AU"),y:R().scale(j.ep).orient(["left","front"]).ticks(12).tickPadding(6).title("eₚ"),z:R().scale(j.ip).orient(["bottom","left"]).ticks(12).tickPadding(6).title("sin iₚ"),x1:R().scale(j.ap).orient(["top","front"]).ticks(0).dash([2,4]),x2:R().scale(j.ap).orient(["bottom","back"]).ticks(0).dash([2,4]),x3:R().scale(j.ap).orient(["top","back"]).ticks(0).dash([2,4]),y1:R().scale(j.ep).orient(["right","front"]).ticks(0).dash([2,4]),y2:R().scale(j.ep).orient(["left","back"]).ticks(0).dash([2,4]),y3:R().scale(j.ep).orient(["right","back"]).ticks(0).dash([2,4]),z1:R().scale(j.ip).orient(["top","left"]).ticks(0).dash([2,4]),z2:R().scale(j.ip).orient(["bottom","right"]).ticks(0).dash([2,4]),z3:R().scale(j.ip).orient(["top","right"]).ticks(0).dash([2,4])},H.translate([E.invert(S[0]),E.invert(S[2])]),d3.csv(k+g,function(t,e){if(t)return console.log(t);for(var n in e)s(e,n)&&T.push(D(e[n]));a()}),d3.csv(k+"families.csv",function(t,e){if(t)return console.log(t);for(var n in e)s(e,n)&&F.push(L(e[n]));a()})};var I=function(t,e){for(var a=[],n=0;3>n;n++){for(var r=0,o=0;3>o;o++)r+=t[n][o]*e[o];a[n]=r}return a},B=function(t,e){for(var a=[],n=0;3>n;n++){a[n]=[];for(var r=0;3>r;r++){for(var o=0,i=0;3>i;i++)o+=e[n][i]*t[i][r];a[n][r]=o}}return a},q=function(t){return B(C("z",t[2]),C("x",t[0]))},C=function(t,e){var a=-e*Math.PI/180,n=Math.cos(a),r=Math.sin(a);switch(t){case"x":return[[1,0,0],[0,n,r],[0,-r,n]];case"y":return[[n,0,-r],[0,1,0],[r,0,n]];case"z":return[[n,r,0],[-r,n,0],[0,0,1]]}},D=function(t){var e,a=j.ap(t.ap),n=j.ep(t.ep),r=j.ip(t.sinip),o=l(t);return e=t.H&&""!==t.H?Math.sqrt(p+1-t.H):.9,{pos:[a,n,r],col:o,r:e}},L=function(t){var e=j.ap(t.ap),a=j.ep(t.ep),r=j.ip(t.sinip);return col="#fff",n=t.Name,{pos:[e,a,r],col:col,n:n}},O={bottomfront:1,topfront:1,bottomback:1,topback:1,bottomleft:1,topleft:1,bottomright:1,topright:1,leftfront:1,rightfront:1,leftback:1,rightback:1},R=function(){function t(t){t.strokeStyle=m,t.lineWidth=y,t.textAlign="center",t.textBaseline="middle",t.setLineDash(z);var r=e(s);if(i(r),t.fillStyle=m,""!==p){t.font=v;var l=o.range(),f=(l[0]+l[1])/2,g=a(f,h),x=n(g,h);c(p,x)}if(0!==b){t.font=d;var P=o.ticks(b);P.forEach(function(t,e){var r=o(t);if(tick=a(r),i(tick),e%k===0){var s=n(tick,u);c(t,s)}})}}function e(t){var e,a=x,n=o.range();switch(t.join("")){case"bottomfront":e=[[n[0],-a,-a],[n[1],-a,-a]];break;case"topfront":e=[[n[0],a,-a],[n[1],a,-a]];break;case"bottomback":e=[[n[0],-a,a],[n[1],-a,a]];break;case"topback":e=[[n[0],a,a],[n[1],a,a]];break;case"bottomleft":e=[[-a,n[0],-a],[-a,n[1],-a]];break;case"topleft":e=[[a,n[0],-a],[a,n[1],-a]];break;case"bottomright":e=[[-a,n[0],a],[-a,n[1],a]];break;case"topright":e=[[a,n[0],a],[a,n[1],a]];break;case"leftfront":e=[[-a,-a,n[0]],[-a,-a,n[1]]];break;case"rightfront":e=[[a,-a,n[0]],[a,-a,n[1]]];break;case"leftback":e=[[-a,a,n[0]],[-a,a,n[1]]];break;case"rightback":e=[[a,a,n[0]],[a,a,n[1]]];break;default:e=[]}return e}function a(t){var e,a=x,n=l,r=f;switch(s.join("")){case"bottomfront":e=[[t,-a+n,-a+n],[t,-a-r,-a-r]];break;case"topfront":e=[[t,a-n,-a-n],[t,a+r,-a+r]];break;case"bottomback":e=[[t,-a+n,a+n],[t,-a-r,a-r]];break;case"topback":e=[[t,a-n,a-n],[t,a+r,a+r]];break;case"bottomleft":e=[[-a+n,t,-a+n],[-a-r,t,-a-r]];break;case"topleft":e=[[a-n,t,-a-n],[a+r,t,-a+r]];break;case"bottomright":e=[[-a+n,t,a+n],[-a-r,t,a-r]];break;case"topright":e=[[a-n,t,a-n],[a+r,t,a+r]];break;case"leftfront":e=[[-a+n,-a+n,t],[-a-r,-a-r,t]];break;case"rightfront":e=[[a-n,-a-n,t],[a+r,-a+r,t]];break;case"leftback":e=[[-a+n,a+n,t],[-a-r,a-r,t]];break;case"rightback":e=[[a-n,a-n,t],[a+r,a+r,t]];break;default:e=[]}return e}function n(t,e){var a=t[1];switch(s.join("")){case"bottomfront":case"bottomback":a[1]-=e,a[2]-=e;break;case"topfront":case"topback":a[1]+=e,a[2]+=e;break;case"bottomleft":case"bottomright":a[0]-=e,a[2]-=e;break;case"topleft":case"topright":a[0]+=e,a[2]+=e;break;case"leftfront":case"leftback":a[0]-=e,a[1]-=e;break;case"rightfront":case"rightback":a[0]+=e,a[1]+=e;break;default:a=[]}return a}var r,o=d3.scale.linear(),s=["bottom","front"],l=5,f=5,u=4,h=14,b=[],g=null,k=5,p="",d="10px sans-serif",v="14px sans-serif",m="#fff",y=1,z=[];return t.scale=function(e){return arguments.length?(o=e,t):o},t.orient=function(e){return arguments.length?(e.join("")in O&&(s=e),t):s},t.ticks=function(){return arguments.length?(b=Array.prototype.slice.call(arguments),t):b},t.tickValues=function(e){return arguments.length?(g=e,t):g},t.tickFormat=function(e){return arguments.length?(r=e,t):r},t.tickSize=function(e){var a=arguments.length;return a?(l=+e,f=+arguments[a-1],t):l},t.innerTickSize=function(e){return arguments.length?(l=+e,t):l},t.outerTickSize=function(e){return arguments.length?(f=+e,t):f},t.tickPadding=function(e){return arguments.length?(u=+e,t):u},t.titlePadding=function(e){return arguments.length?(h=+e,t):h},t.tickSubdivide=function(){return arguments.length&&t},t.dash=function(e){return arguments.length?(z=e,t):z},t.values=function(e){return arguments.length?(k=+e,t):k},t.title=function(e){return arguments.length?(p=e,t):p},t.font=function(e){return arguments.length?(d=e,t):d},t.titleFont=function(e){return arguments.length?(v=e,t):v},t};this.Asteroids=b}();