forked from vega/vega
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vega.min.js
2 lines (2 loc) · 48.9 KB
/
vega.min.js
1
2
vg=function(){var e={};e.version="1.0.0";var t=Object.prototype.toString;return e.isObject=function(e){return e===Object(e)},e.isFunction=function(e){return t.call(e)=="[object Function]"},e.isString=function(e){return t.call(e)=="[object String]"},e.isArray=Array.isArray||function(e){return t.call(e)=="[object Array]"},e.isNumber=function(e){return t.call(e)=="[object Number]"},e.isBoolean=function(e){return t.call(e)=="[object Boolean]"},e.number=function(e){return+e},e.boolean=function(e){return!!e},e.identity=function(e){return e},e.extend=function(e){for(var t,n,r=1,i=arguments.length;r<i;++r){t=arguments[r];for(n in t)e[n]=t[n]}return e},e.duplicate=function(e){return JSON.parse(JSON.stringify(e))},e.field=function(e){return e.split("\\.").map(function(e){return e.split(".")}).reduce(function(e,t){return e.length&&(e[e.length-1]+="."+t.shift()),e.push.apply(e,t),e},[])},e.accessor=function(t){var n;return e.isFunction(t)||t==null?t:e.isString(t)&&(n=e.field(t)).length>1?function(e){return n.reduce(function(e,t){return e[t]},e)}:function(e){return e[t]}},e.comparator=function(t){var n=[];return t===undefined&&(t=[]),t=e.array(t).map(function(t){var r=1;return t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(r=1,t=t.slice(1)),n.push(r),e.accessor(t)}),function(e,r){var i,s,o,u,a;for(i=0,s=t.length;i<s;++i){o=t[i],u=o(e),a=o(r);if(u<a)return-1*n[i];if(u>a)return n[i]}return 0}},e.numcmp=function(e,t){return e-t},e.array=function(t){return t!=null?e.isArray(t)?t:[t]:[]},e.values=function(t){return e.isObject(t)&&!e.isArray(t)&&t.values?t.values:t},e.str=function(t){return e.isArray(t)?"["+t.map(e.str)+"]":e.isString(t)?"'"+t+"'":t},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t},e.unique=function(t,n){n=n||e.identity;var r=[],i;for(var s=0;s<t.length;++s)i=n(t[s]),r.indexOf(i)<0&&r.push(i);return r},e.category10=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],e.category20=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],e.shapes=["circle","cross","diamond","square","triangle-down","triangle-up"],e.log=function(e){console.log(e)},e.error=function(e){console.log(e),alert(e)},e.Bounds=function(){var e=function(e){this.clear(),e&&this.union(e)},t=e.prototype;return t.clear=function(){return this.x1=+Number.MAX_VALUE,this.y1=+Number.MAX_VALUE,this.x2=-Number.MAX_VALUE,this.y2=-Number.MAX_VALUE,this},t.set=function(e,t,n,r){return this.x1=e,this.y1=t,this.x2=n,this.y2=r,this},t.add=function(e,t){return e<this.x1&&(this.x1=e),t<this.y1&&(this.y1=t),e>this.x2&&(this.x2=e),t>this.y2&&(this.y2=t),this},t.expand=function(e){return this.x1-=e,this.y1-=e,this.x2+=e,this.y2+=e,this},t.round=function(){return this.x1=Math.floor(this.x1),this.y1=Math.floor(this.y1),this.x2=Math.ceil(this.x2),this.y2=Math.ceil(this.y2),this},t.translate=function(e,t){return this.x1+=e,this.x2+=e,this.y1+=t,this.y2+=t,this},t.rotate=function(e,t,n){var r=Math.cos(e),i=Math.sin(e),s=t-t*r+n*i,o=n-t*i-n*r,u=this.x1,a=this.x2,f=this.y1,l=this.y2;return this.clear().add(r*u-i*f+s,i*u+r*f+o).add(r*u-i*l+s,i*u+r*l+o).add(r*a-i*f+s,i*a+r*f+o).add(r*a-i*l+s,i*a+r*l+o)},t.union=function(e){return e.x1<this.x1&&(this.x1=e.x1),e.y1<this.y1&&(this.y1=e.y1),e.x2>this.x2&&(this.x2=e.x2),e.y2>this.y2&&(this.y2=e.y2),this},t.intersects=function(e){return e&&!(this.x2<e.x1||this.x1>e.x2||this.y2<e.y1||this.y1>e.y2)},t.contains=function(e,t){return!(e<this.x1||e>this.x2||t<this.y1||t>this.y2)},t.width=function(){return this.x2-this.x1},t.height=function(){return this.y2-this.y1},e}(),e.canvas={},e.canvas.path=function(){function r(e){var r=[],i,s,o;e=e.slice().replace(n[0],"###$1").split(n[1]).slice(1);for(var u=0,a,f,l=e.length;u<l;u++){i=e[u],s=i.slice(1).trim().replace(n[2],"$1###-").split(n[3]),f=[i.charAt(0)];for(var a=0,c=s.length;a<c;a++)o=parseFloat(s[a]),isNaN(o)||f.push(o);var h=f[0].toLowerCase(),p=t[h];if(f.length-1>p)for(var d=1,v=f.length;d<v;d+=p)r.push([f[0]].concat(f.slice(d,d+p)));else r.push(f)}return r}function i(e,t,n,r,i,s,o){var u=r[0],a=r[1],c=r[2],h=r[3],p=r[4],d=r[5],v=r[6],m=f(d,v,u,a,h,p,c,t,n);for(var g=0;g<m.length;g++){var y=l.apply(null,m[g]);e.bezierCurveTo.apply(e,y),i.add(y[0]-s,y[1]-o),i.add(y[2]-s,y[3]-o),i.add(y[4]-s,y[5]-o)}}function f(e,t,n,r,i,o,f,l,c){a=u.call(arguments);if(s[a])return s[a];var h=f*(Math.PI/180),p=Math.sin(h),d=Math.cos(h);n=Math.abs(n),r=Math.abs(r);var v=d*(l-e)*.5+p*(c-t)*.5,m=d*(c-t)*.5-p*(l-e)*.5,g=v*v/(n*n)+m*m/(r*r);g>1&&(g=Math.sqrt(g),n*=g,r*=g);var y=d/n,b=p/n,w=-p/r,E=d/r,S=y*l+b*c,x=w*l+E*c,T=y*e+b*t,N=w*e+E*t,C=(T-S)*(T-S)+(N-x)*(N-x),k=1/C-.25;k<0&&(k=0);var L=Math.sqrt(k);o==i&&(L=-L);var A=.5*(S+T)-L*(N-x),O=.5*(x+N)+L*(T-S),M=Math.atan2(x-O,S-A),_=Math.atan2(N-O,T-A),D=_-M;D<0&&o==1?D+=2*Math.PI:D>0&&o==0&&(D-=2*Math.PI);var P=Math.ceil(Math.abs(D/(Math.PI*.5+.001))),H=[];for(var B=0;B<P;B++){var j=M+B*D/P,F=M+(B+1)*D/P;H[B]=[A,O,j,F,n,r,p,d]}return s[a]=H}function l(e,t,n,r,i,s,f,l){a=u.call(arguments);if(o[a])return o[a];var c=l*i,h=-f*s,p=f*i,d=l*s,v=Math.cos(n),m=Math.sin(n),g=Math.cos(r),y=Math.sin(r),b=.5*(r-n),w=Math.sin(b*.5),E=8/3*w*w/Math.sin(b),S=e+v-E*m,x=t+m+E*v,T=e+g,N=t+y,C=T+E*y,k=N-E*g;return o[a]=[c*S+h*x,p*S+d*x,c*C+h*k,p*C+d*k,c*T+h*N,p*T+d*N]}function c(t,n,r,s){var o,u=null,a=0,f=0,l=0,c=0,h,p,d,v,m=new e.Bounds;r==undefined&&(r=0),s==undefined&&(s=0),t.beginPath();for(var g=0,y=n.length;g<y;++g){o=n[g];switch(o[0]){case"l":a+=o[1],f+=o[2],t.lineTo(a+r,f+s),m.add(a,f);break;case"L":a=o[1],f=o[2],t.lineTo(a+r,f+s),m.add(a,f);break;case"h":a+=o[1],t.lineTo(a+r,f+s),m.add(a,f);break;case"H":a=o[1],t.lineTo(a+r,f+s),m.add(a,f);break;case"v":f+=o[1],t.lineTo(a+r,f+s),m.add(a,f);break;case"V":f=o[1],t.lineTo(a+r,f+s),m.add(a,f);break;case"m":a+=o[1],f+=o[2],t.moveTo(a+r,f+s),m.add(a,f);break;case"M":a=o[1],f=o[2],t.moveTo(a+r,f+s),m.add(a,f);break;case"c":h=a+o[5],p=f+o[6],l=a+o[3],c=f+o[4],t.bezierCurveTo(a+o[1]+r,f+o[2]+s,l+r,c+s,h+r,p+s),m.add(a+o[1],f+o[2]),m.add(l,c),m.add(h,p),a=h,f=p;break;case"C":a=o[5],f=o[6],l=o[3],c=o[4],t.bezierCurveTo(o[1]+r,o[2]+s,l+r,c+s,a+r,f+s),m.add(o[1],o[2]),m.add(l,c),m.add(a,f);break;case"s":h=a+o[3],p=f+o[4],l=2*a-l,c=2*f-c,t.bezierCurveTo(l+r,c+s,a+o[1]+r,f+o[2]+s,h+r,p+s),m.add(l,c),m.add(a+o[1],f+o[2]),m.add(h,p),l=a+o[1],c=f+o[2],a=h,f=p;break;case"S":h=o[3],p=o[4],l=2*a-l,c=2*f-c,t.bezierCurveTo(l+r,c+s,o[1]+r,o[2]+s,h+r,p+s),a=h,f=p,m.add(o[1],o[2]),m.add(l,c),m.add(h,p),l=o[1],c=o[2];break;case"q":h=a+o[3],p=f+o[4],l=a+o[1],c=f+o[2],t.quadraticCurveTo(l+r,c+s,h+r,p+s),a=h,f=p,m.add(l,c),m.add(h,p);break;case"Q":h=o[3],p=o[4],t.quadraticCurveTo(o[1]+r,o[2]+s,h+r,p+s),a=h,f=p,l=o[1],c=o[2],m.add(l,c),m.add(h,p);break;case"t":h=a+o[1],p=f+o[2],u[0].match(/[QqTt]/)===null?(l=a,c=f):u[0]==="t"?(l=2*a-d,c=2*f-v):u[0]==="q"&&(l=2*a-l,c=2*f-c),d=l,v=c,t.quadraticCurveTo(l+r,c+s,h+r,p+s),a=h,f=p,l=a+o[1],c=f+o[2],m.add(l,c),m.add(h,p);break;case"T":h=o[1],p=o[2],l=2*a-l,c=2*f-c,t.quadraticCurveTo(l+r,c+s,h+r,p+s),a=h,f=p,m.add(l,c),m.add(h,p);break;case"a":i(t,a+r,f+s,[o[1],o[2],o[3],o[4],o[5],o[6]+a+r,o[7]+f+s],m,r,s),a+=o[6],f+=o[7];break;case"A":i(t,a+r,f+s,[o[1],o[2],o[3],o[4],o[5],o[6]+r,o[7]+s],m,r,s),a=o[6],f=o[7];break;case"z":case"Z":t.closePath()}u=o}return m.translate(r,s)}var t={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},n=[/([MLHVCSQTAZmlhvcsqtaz])/g,/###/,/(\d)-/g,/\s|,|###/],s={},o={},u=Array.prototype.join,a;return{parse:r,render:c}}(),e.canvas.marks=function(){function o(t,n){var r=n.x||0,i=n.y||0,s=n.innerRadius||0,o=n.outerRadius||0,u=(n.startAngle||0)-Math.PI/2,a=(n.endAngle||0)-Math.PI/2;return t.beginPath(),s===0?t.moveTo(r,i):t.arc(r,i,s,u,a,0),t.arc(r,i,o,a,u,1),t.closePath(),(new e.Bounds).set(r-o,i-o,r+o,i+o)}function u(e,r){return n(e,t(r.path),r.x,r.y)}function a(t,n){t.beginPath();var s=n.size!=undefined?n.size:100,o=n.x,u=n.y,a,f,l,c,h=new e.Bounds;if(n.shape==undefined||n.shape==="circle")return a=Math.sqrt(s/Math.PI),t.arc(o,u,a,0,2*Math.PI,0),t.closePath(),h.set(o-a,u-a,o+a,u+a);switch(n.shape){case"cross":a=Math.sqrt(s/5)/2,f=3*a,t.moveTo(o-f,u-a),t.lineTo(o-a,u-a),t.lineTo(o-a,u-f),t.lineTo(o+a,u-f),t.lineTo(o+a,u-a),t.lineTo(o+f,u-a),t.lineTo(o+f,u+a),t.lineTo(o+a,u+a),t.lineTo(o+a,u+f),t.lineTo(o-a,u+f),t.lineTo(o-a,u+a),t.lineTo(o-f,u+a),h.set(o-f,u-f,o+u,u+f);break;case"diamond":c=Math.sqrt(s/(2*i)),l=c*i,t.moveTo(o,u-c),t.lineTo(o+l,u),t.lineTo(o,u+c),t.lineTo(o-l,u),h.set(o-l,u-c,o+l,u+c);break;case"square":f=Math.sqrt(s),a=f/2,t.rect(o-a,u-a,f,f),h.set(o-a,u-a,o+a,u+a);break;case"triangle-down":l=Math.sqrt(s/r),c=l*r/2,t.moveTo(o,u+c),t.lineTo(o+l,u-c),t.lineTo(o-l,u-c),h.set(o-l,u-c,o+l,u+c);break;case"triangle-up":l=Math.sqrt(s/r),c=l*r/2,t.moveTo(o,u-c),t.lineTo(o+l,u+c),t.lineTo(o-l,u+c),h.set(o-l,u-c,o+l,u+c)}return t.closePath(),h}function f(e,r){var i=d3.svg.area().x(function(e){return e.x}).y1(function(e){return e.y}).y0(function(e){return e.y+e.height}),s=r[0];return s.interpolate&&i.interpolate(s.interpolate),s.tension!=undefined&&i.tension(s.tension),n(e,t(i(r)))}function l(e,r){var i=d3.svg.line().x(function(e){return e.x}).y(function(e){return e.y}),s=r[0];return s.interpolate&&i.interpolate(s.interpolate),s.tension!=undefined&&i.tension(s.tension),n(e,t(i(r)))}function c(e,t,n,r){var i=n.fill,s=n.stroke,o,u,a;n.bounds=e(t,r),o=n.opacity==null?1:n.opacity;if(o==0||!i&&!s)return;i&&(t.globalAlpha=o*(n.fillOpacity==null?1:n.fillOpacity),t.fillStyle=i,t.fill()),s&&(a=(a=n.strokeWidth)!=undefined?a:1,a>0&&(t.globalAlpha=o*(n.strokeOpacity==null?1:n.strokeOpacity),t.strokeStyle=s,t.lineWidth=a,t.lineCap=(u=n.strokeCap)!=undefined?u:"butt",t.stroke(),n.bounds.expand(a)))}function h(e,t,n,r){var i,s,o;for(i=0,s=n.items.length;i<s;++i){o=n.items[i];if(r&&!r.intersects(o.bounds))continue;c(e,t,o,o)}}function p(t,n,r){if(!n.items.length)return;var i=n.items,s,o,u,a,f,l,c,h,p;for(var d=0,v=i.length;d<v;++d){s=i[d];if(r&&!r.intersects(s.bounds))continue;h=s.x||0,p=s.y||0,s.bounds=(s.bounds||new e.Bounds).set(h,p,h+s.width,p+s.height),f=s.opacity==null?1:s.opacity;if(f==0)return;if(u=s.fill)t.globalAlpha=f*(s.fillOpacity==null?1:s.fillOpacity),t.fillStyle=u,t.fillRect(h,p,s.width,s.height);if(a=s.stroke)c=(c=s.strokeWidth)!=undefined?c:1,c>0&&(t.globalAlpha=f*(s.strokeOpacity==null?1:s.strokeOpacity),t.strokeStyle=a,t.lineWidth=c,t.lineCap=(l=s.strokeCap)!=undefined?l:"butt",t.strokeRect(h,p,s.width,s.height),s.bounds.expand(c))}}function d(t,n,r){if(!n.items.length)return;var i=this,s=n.items,o;for(var u=0,a=s.length;u<a;++u){o=s[u];if(r&&!r.intersects(o.bounds))continue;if(!o.image||o.image.url!==o.url)o.image=i.loadImage(o.url),o.image.url=o.url;var f,l,c,h,p;c=o.width||o.image&&o.image.width||0,h=o.height||o.image&&o.image.height||0,f=o.x-(o.align==="center"?c/2:o.align==="right"?c:0),l=o.y-(o.baseline==="middle"?h/2:o.baseline==="bottom"?h:0),o.bounds=(o.bounds||new e.Bounds).set(f,l,f+c,l+h),t.globalAlpha=(p=o.opacity)!=undefined?p:1,t.drawImage(o.image,f,l,c,h)}}function v(e){return(e.fontStyle?e.fontStyle+" ":"")+(e.fontVariant?e.fontVariant+" ":"")+(e.fontWeight?e.fontWeight+" ":"")+(e.fontSize!=undefined?e.fontSize+"px ":"11px ")+(e.font||"sans-serif")}function m(t,n,r){if(!n.items.length)return;var i=n.items,s,o,u,a,f,l,c,h,p;for(var d=0,m=i.length;d<m;++d){s=i[d];if(r&&!r.intersects(s.bounds))continue;t.font=v(s),t.textAlign=s.align||"left",t.textBaseline=s.baseline||"alphabetic",s.bounds=g(t,s,s.bounds||new e.Bounds).expand(1),f=s.opacity==null?1:s.opacity;if(f==0)return;s.angle?(t.save(),t.translate(s.x,s.y),t.rotate(s.angle*Math.PI/180),x=s.dx||0,y=s.dy||0):(x=s.x+(s.dx||0),y=s.y+(s.dy||0));if(u=s.fill)t.globalAlpha=f*(s.fillOpacity==null?1:s.fillOpacity),t.fillStyle=u,t.fillText(s.text,x,y);if(a=s.stroke)l=(l=s.strokeWidth)!=undefined?l:1,l>0&&(t.globalAlpha=f*(s.strokeOpacity==null?1:s.strokeOpacity),t.strokeStyle=a,t.lineWidth=l,t.strokeText(s.text,x,y));s.angle&&t.restore()}}function g(e,t,n,r){var i=t.x+(t.dx||0),s=t.y+(t.dy||0),o=e.measureText(t.text).width,u=t.fontSize,a=t.align,f=t.baseline,l,c,h,p,d;return a==="center"?i-=o/2:a==="right"&&(i-=o),f==="top"?s+=u/5:f==="bottom"?s-=u:f==="middle"?s=s-u/2+u/10:s-=4*u/5,n.set(i,s,i+o,s+u),!r&&t.angle&&n.rotate(t.angle*Math.PI/180,t.x,t.y),n}function b(e){return function(t,n,r){h(e,t,n,r)}}function w(e){return function(t,n,r){if(!n.items.length)return;if(r&&!r.intersects(n.items[0].bounds))return;c(e,t,n.items[0],n.items)}}function E(e,t,n){if(!t.items.length)return;var r=t.items,i,s=this,o,u;p(e,t,n);for(var a=0,f=r.length;a<f;++a){i=r[a],o=i.x||0,u=i.y||0,e.save(),e.translate(o,u),n&&n.translate(-o,-u);for(var l=0,c=i.items.length;l<c;++l)s.draw(e,i.items[l],n);n&&n.translate(o,u),e.restore()}}function S(e,t,n,r,i,s){if(t.items.length===0||t.bounds&&!t.bounds.contains(i,s))return!1;var o=t.items,u,a,f,l,c,h=this;for(var p=0,d=o.length;p<d;++p){a=o[p],l=a.x||0,c=a.y||0,e.save(),e.translate(l,c);for(var v=0,m=a.items.length;v<m;++v){u=a.items[v];if(u.interactive===!1)continue;f=h.pick(u,n,r,i-l,s-c);if(f)return e.restore(),f}e.restore()}return t.interactive?T(L.rect,e,t,n,r,i,s):!1}function T(e,t,n,r,i,s,o){if(!n.items.length)return!1;var u,a,f;for(f=n.items.length;--f>=0;){u=n.items[f],a=u.bounds;if(a&&!a.contains(s,o)||!a)continue;if(e(t,u,r,i,s,o))return u}return!1}function N(e,t,n,r,i,s){if(!t.items.length)return!1;var o=t.items,u,a,f,l,c,h,p,d;return a=o[0].bounds,a&&!a.contains(i,s)?!1:L.area(e,o,n,r)?o[0]:!1}function C(e,t,n,r,i,s){return!1}function k(e){return function(t,n,r,i,s,o){return T(e,t,n,r,i,s,o)}}function A(e,t,n,r,i,o){if(!t.fontSize)return!1;if(!t.angle)return!0;e.font=v(t);var u=g(e,t,s,!0),a=-t.angle*Math.PI/180,f=Math.cos(a),l=Math.sin(a),n=t.x,r=t.y,c=f*i-l*o+(n-n*f+r*l),h=l*i+f*o+(r-n*l-r*f);return u.contains(c,h)}var t=e.canvas.path.parse,n=e.canvas.path.render,r=Math.sqrt(3),i=Math.tan(30*Math.PI/180),s=new e.Bounds,L={text:A,rect:function(e,t,n,r){return!0},image:function(e,t,n,r){return!0},arc:function(e,t,n,r){return o(e,t),e.isPointInPath(n,r)},area:function(e,t,n,r){return f(e,t),e.isPointInPath(n,r)},path:function(e,t,n,r){return u(e,t),e.isPointInPath(n,r)},symbol:function(e,t,n,r){return a(e,t),e.isPointInPath(n,r)}};return{draw:{group:E,area:w(f),line:w(l),arc:b(o),path:b(u),symbol:b(a),rect:p,text:m,image:d,drawOne:w,drawAll:b},pick:{group:S,area:N,line:C,arc:k(L.arc),path:k(L.path),symbol:k(L.symbol),rect:k(L.rect),text:k(L.text),image:k(L.image),pickAll:T}}}(),e.canvas.Renderer=function(){function r(t){var n=new e.Bounds(t.bounds);while((t=t.mark.group)!=null)n.translate(t.x||0,t.y||0);return n}function i(t){return t?e.array(t).reduce(function(e,t){return e.union(r(t))},new e.Bounds):null}function s(t,n){var r=null;return n&&(r=(new e.Bounds(n)).round(),t.beginPath(),t.rect(r.x1,r.y1,r.width(),r.height()),t.clip()),r}var t=function(){this._ctx=null,this._el=null},n=t.prototype;return n.initialize=function(e,t,n,r){this._el=e,this._width=t,this._height=n,this._padding=r;var i=d3.select(e).selectAll("canvas.marks").data([1]);return i.enter().append("canvas").attr("class","marks"),i.attr("width",t+r.left+r.right).attr("height",n+r.top+r.bottom),this._ctx=i.node().getContext("2d"),this._ctx.setTransform(1,0,0,1,r.left,r.top),this},n.context=function(){return this._ctx},n.element=function(){return this._el},n.render=function(e,t){var n=this._ctx,r=this._padding,o=this._width+r.left+r.right,u=this._width+r.top+r.bottom,a=null;this._scene=e,n.save(),a=s(n,i(t)),n.clearRect(-r.left,-r.top,o,u),this.draw(n,e,a),t&&(n.restore(),n.save(),a=s(n,i(t)),n.clearRect(-r.left,-r.top,o,u),this.draw(n,e,a)),n.restore(),this._scene=null},n.draw=function(t,n,r){var i=n.marktype,s=e.canvas.marks.draw[i];s.call(this,t,n,r)},n.renderAsync=function(e){var t=this;t._async_id&&clearTimeout(t._async_id),t._async_id=setTimeout(function(){t.render(e),delete t._async_id},50)},n.loadImage=function(t){var n=this,r=this._scene,i=new Image;return i.onload=function(){e.log("LOAD IMAGE: "+this.src),n.renderAsync(r)},i.src=t,i},t}(),e.canvas.Handler=function(){function i(e){var t=e.indexOf(".");return t<0?e:e.slice(0,t)}var t=function(e,t){this._active=null,this._handlers={},e&&this.initialize(e),t&&this.model(t)},n=t.prototype;n.initialize=function(e,t,i){this._el=d3.select(e).node(),this._canvas=d3.select(e).select("canvas.marks").node(),this._padding=t,this._obj=i||null;var s=this._canvas,o=this;return r.forEach(function(e){s.addEventListener(e,function(t){n[e].call(o,t)})}),this},n.model=function(e){return arguments.length?(this._model=e,this):this._model},n.handlers=function(){var t=this._handlers;return e.keys(t).reduce(function(e,n){return t[n].reduce(function(e,t){return e.push(t),e},e)},[])};var r=["mousedown","mouseup","click","dblclick","wheel","keydown","keypress","keyup","mousewheel"];return r.forEach(function(e){n[e]=function(t){this.fire(e,t)}}),r.push("mousemove"),r.push("mouseout"),n.mousemove=function(e){var t=this._padding,n=e.target.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top,s=this._active,o=this.pick(this._model.scene(),r,i,r-t.left,i-t.top);if(o===s){this.fire("mousemove",e);return}s&&this.fire("mouseout",e),this._active=o,o&&this.fire("mouseover",e)},n.mouseout=function(e){this._active&&this.fire("mouseout",e),this._active=null},n.DOMMouseScroll=function(e){this.fire("mousewheel",e)},n.fire=function(e,t){var n=this._active,r=this._handlers[e];if(n&&r)for(var i=0,s=r.length;i<s;++i)r[i].handler.call(this._obj,t,n)},n.on=function(e,t){var n=i(e),r=this._handlers;return r=r[n]||(r[n]=[]),r.push({type:e,handler:t}),this},n.off=function(e,t){var n=i(e),r=this._handlers[n];if(!r)return;for(var s=r.length;--s>=0;){if(r[s].type!==e)continue;(!t||r[s].handler===t)&&r.splice(s,1)}return this},n.context=function(){return this._canvas.getContext("2d")},n.pick=function(t,n,r,i,s){var o=this.context(),u=t.marktype,a=e.canvas.marks.pick[u];return a.call(this,o,t,n,r,i,s)},t}(),e.svg={},e.svg.marks=function(){function t(e){return e.x||0}function n(e){return e.y||0}function r(e){return e.y+e.height||0}function i(e){return e.key}function s(e){return e.size==null?100:e.size}function o(e){return e.shape||"circle"}function d(e){var t=e.mark?e:e[0],n,r,i,s,o;for(n=0,r=p.length;n<r;++n)i=p[n],s=h[i],o=t[i],o==null?s==="fill"?this.style.setProperty(s,"none",null):this.style.removeProperty(s):this.style.setProperty(s,o,null)}function v(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",u(e))}function m(e){var t=e[0];a.interpolate(t.interpolate||"linear").tension(t.tension==undefined?.7:t.tension),this.setAttribute("d",a(e))}function g(e){var t=e[0];f.interpolate(t.interpolate||"linear").tension(t.tension==undefined?.7:t.tension),this.setAttribute("d",f(e))}function y(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",e.path)}function b(e){this.setAttribute("x",e.x||0),this.setAttribute("y",e.y||0),this.setAttribute("width",e.width||0),this.setAttribute("height",e.height||0)}function w(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",l(e))}function E(e){var t=e.width||e.image&&e.image.width||0,n=e.height||e.image&&e.image.height||0,r=e.x-(e.align==="center"?t/2:e.align==="right"?t:0),i=e.y-(e.baseline==="middle"?n/2:e.baseline==="bottom"?n:0);this.setAttributeNS("http://www.w3.org/1999/xlink","href",e.url),this.setAttribute("x",r),this.setAttribute("y",i),this.setAttribute("width",t),this.setAttribute("height",n)}function S(e){return(e.fontStyle?e.fontStyle+" ":"")+(e.fontVariant?e.fontVariant+" ":"")+(e.fontWeight?e.fontWeight+" ":"")+(e.fontSize!=undefined?e.fontSize+"px ":"11px ")+(e.font||"sans-serif")}function x(e){var t=e.x||0,n=e.y||0,r=e.dx||0,i=e.dy||0,s=e.angle||0,o=c[e.align||"left"],u=e.baseline==="top"?".9em":e.baseline==="middle"?".35em":0;this.setAttribute("x",t+r),this.setAttribute("y",n+i),this.setAttribute("dy",i),this.setAttribute("text-anchor",o),s?this.setAttribute("transform","rotate("+s+" "+t+","+n+")"):this.removeAttribute("transform"),u?this.setAttribute("dy",u):this.removeAttribute("dy"),this.textContent=e.text,this.style.setProperty("font",S(e),null)}function T(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")")}function N(e,t,n){return function(r,i,s){k(r,i,s,"mark_",e,t,n)}}function k(e,t,n,r,i,s,o){var u=r+n,a=o?[t.items]:t.items,f=e.select("."+u);f.empty()&&(f=e.append("g").attr("id","g"+ ++C).attr("class",u));var l="#"+f.attr("id"),c=f.selectAll(l+" > "+i).data(a),h=c.enter().append(i);i!=="g"&&(f.style("pointer-events",t.interactive===!1?"none":null),h.each(function(e){(e.mark?e:e[0])._svg=this})),c.exit().remove(),c.each(s),i!=="g"&&c.each(d)}function L(e,t,n){var r=this;k(e,t,n,"mark_","rect",b),k(e,t,n,"group_","g",T);var i=e.select(".group_"+n).node(),s,o,u,a;for(var s=0,o=i.childNodes.length;s<o;++s){var f=d3.select(i.childNodes[s]),l=i.childNodes[s].__data__.items;for(var u=0,a=l.length;u<a;++u)r.draw(f,l[u],u)}}var u=d3.svg.arc(),a=d3.svg.area().x(t).y1(n).y0(r),f=d3.svg.line().x(t).y(n),l=d3.svg.symbol().type(o).size(s),c={left:"start",center:"middle",right:"end"},h={fill:"fill",fillOpacity:"fill-opacity",stroke:"stroke",strokeWidth:"stroke-width",strokeOpacity:"stroke-opacity",opacity:"opacity"},p=e.keys(h),C=0;return{update:{group:b,area:m,line:g,arc:v,path:y,symbol:w,rect:b,text:x,image:E},nested:{area:!0,line:!0},style:d,draw:{group:L,area:N("path",m,!0),line:N("path",g,!0),arc:N("path",v),path:N("path",y),symbol:N("path",w),rect:N("rect",b),text:N("text",x),image:N("image",E),draw:N}}}(),e.svg.Renderer=function(){var t=function(){this._ctx=null,this._el=null},n=t.prototype;return n.initialize=function(e,t,n,r){this._el=e,this._width=t,this._height=n,this._padding=r,d3.select(e).select("svg.marks").remove();var i=d3.select(e).append("svg").attr("class","marks").attr("width",t+r.left+r.right).attr("height",n+r.top+r.bottom);return this._ctx=i.append("g").attr("transform","translate("+r.left+","+r.top+")"),this},n.context=function(){return this._ctx},n.element=function(){return this._el},n.render=function(t,n){n?this.renderItems(e.array(n)):this.draw(this._ctx,t,0)},n.renderItems=function(t){var n,r,i,s,o,u,a=e.svg.marks;for(o=0,u=t.length;o<u;++o)n=t[o],r=n._svg,i=n.mark.marktype,n=a.nested[i]?n.mark.items:n,a.update[i].call(r,n),a.style.call(r,n)},n.draw=function(t,n,r){var i=n.marktype,s=e.svg.marks.draw[i];s.call(this,t,n,r)},t}(),e.svg.Handler=function(){function n(e){var t=this;return function(n){var r=n.target,i=r.__data__;i&&(i=i.mark?i:i[0],e.call(t._obj,n,i))}}function r(e){var t=e.indexOf(".");return t<0?e:e.slice(0,t)}var t=function(e,t){this._active=null,this._handlers={},e&&this.initialize(e),t&&this.model(t)},i=t.prototype;return i.initialize=function(e,t,n){return this._el=d3.select(e).node(),this._svg=d3.select(e).select("svg.marks").node(),this._padding=t,this._obj=n||null,this},i.model=function(e){return arguments.length?(this._model=e,this):this._model},i.handlers=function(){var t=this._handlers;return e.keys(t).reduce(function(e,n){return t[n].reduce(function(e,t){return e.push(t),e},e)},[])},i.on=function(e,t){var i=r(e),s=this._handlers,o=d3.select(this._svg).node(),u={type:e,handler:t,svg:n.call(this,t)};return s=s[i]||(s[i]=[]),s.push(u),o.addEventListener(i,u.svg),this},i.off=function(e,t){var n=r(e),i=this._handlers[n],s=d3.select(this._svg).node();if(!i)return;for(var o=i.length;--o>=0;){if(i[o].type!==e)continue;if(!t||i[o].handler===t)s.removeEventListener(n,i[o].svg),i.splice(o,1)}return this},t}(),e.data={},e.data.ingest=function(e,t){return{data:e,index:t}},e.data.mapper=function(e){return function(t){return t.forEach(e),t}},e.data.size=function(e,t){return e=Array.isArray(e)?e:[0,e],e=e.map(function(e){return typeof e=="string"?t[e]:e}),e},e.data.read=function(){function r(e,n){var r=n&&n.type||"json";return t[r](e,n)}function i(t,r){var i=e.keys(r),s=i.map(function(e){return n[r[e]]}),o,u,a,f,l;for(u=0,f=t.length;u<f;++u){o=t[u];for(a=0,l=i.length;a<l;++a)o[i[a]]=s[a](o[i[a]])}}var t={},n={number:e.number,"boolean":e.boolean};return t.json=function(t,n){var r=JSON.parse(t);return n&&n.property&&(r=e.accessor(n.property)(r)),r},t.csv=function(e,t){var n=d3.csv.parse(e);return t.parse&&i(n,t.parse),n},t.tsv=function(e,t){var n=d3.tsv.parse(e);return t.parse&&i(n,t.parse),n},r.formats=t,r}(),e.data.array=function(){function n(e){return e.map(function(e){var n=[];for(var r=0,i=t.length;r<i;++r)n.push(t[r](e));return n})}var t=[];return n.fields=function(r){return t=e.array(r).map(e.accessor),n},n},e.data.copy=function(){var t=e.accessor("data"),n=[],r=null,i=e.data.mapper(function(e){var i=t(e),s,o,u=n,a=r||n;for(s=0,o=n.length;s<o;++s)e[a[s]]=i[n[s]];return e});return i.from=function(n){return t=e.accessor(n),i},i.fields=function(t){return n=e.array(t),i},i.as=function(t){return r=e.array(t),i},i},e.data.facet=function(){function r(e){var r={key:"",keys:[],values:[]},i={},s=r.values,o,u,a,f,l,c,h,p,d;if(t.length===0)return s.push(o={key:"",keys:[],index:0,values:n?e:e.slice()}),n&&o.values.sort(n),r;for(l=0,f=e.length;l<f;++l){for(h=0,u=[],a="";h<t.length;++h)p=t[h](e[l]),u.push(p),a+=(h>0?"|":"")+String(p);o=i[a],o===undefined&&s.push(o=i[a]={key:a,keys:u,index:s.length,values:[]}),o.values.push(e[l])}if(n)for(l=0,f=s.length;l<f;++l)s[l].values.sort(n);return r}var t=[],n=null;return r.keys=function(n){return t=e.array(n).map(e.accessor),r},r.sort=function(t){return n=e.comparator(t),r},r},e.data.filter=function(){function n(e){return t?e.filter(t):e}var t=null;return n.test=function(r){return t=e.isFunction(r)?r:new Function("d","return "+r),n},n},e.data.fold=function(){function i(e){var i=[],s,o,u,a,f=t.length;for(o=0,a=e.length;o<a;++o){s=e[o];for(u=0;u<f;++u){var l={index:i.length,data:s.data};l[r.key]=t[u],l[r.value]=n[u](s),i.push(l)}}return i}var t=[],n=[],r={key:"key",value:"value"};return i.fields=function(r){return t=e.array(r),n=t.map(e.accessor),i},i.output=function(t){return e.keys(r).forEach(function(e){t[e]!==undefined&&(r[e]=t[e])}),i},i},e.data.force=function(){function f(r,i,s){t.size(e.data.size(u,s)).nodes(r),n&&i[n]&&t.links(i[n]),t.start();for(var a=0;a<o;++a)t.tick();return t.stop(),r}var t=d3.layout.force(),n=null,r=20,i=1,s=-30,o=500,u=["width","height"],a=["friction","theta","gravity","alpha"];return f.links=function(e){return n=e,f},f.size=function(e){return u=e,f},f.linkDistance=function(n){return r=typeof n=="number"?n:e.accessor(n),t.linkDistance(r),f},f.linkStrength=function(n){return i=typeof n=="number"?n:e.accessor(n),t.linkStrength(i),f},f.charge=function(n){return s=typeof n=="number"?n:e.accessor(n),t.charge(s),f},f.iterations=function(e){return o=e,f},a.forEach(function(e){f[e]=function(n){return t[e](n),f}}),f},e.data.geo=function(){function n(){var n={},r="mercator",i=d3.geo[r](),s=e.identity,o=e.identity,u={x:"x",y:"y"},a=e.data.mapper(function(e){var t=[o(e),s(e)],n=i(t);return e[u.x]=n[0],e[u.y]=n[1],e});return a.func=function(){return i},a.projection=function(e){if(r!==e){r=e,i=d3.geo[r]();for(var t in n)i[t](n[t])}return a},t.forEach(function(e){a[e]=function(t){return n[e]=t,i[e](t),a}}),a.lon=function(t){return o=e.accessor(t),a},a.lat=function(t){return s=e.accessor(t),a},a.output=function(t){return e.keys(u).forEach(function(e){t[e]!==undefined&&(u[e]=t[e])}),t},a}var t=["center","scale","translate","rotate","precision","clipAngle"];return n.params=t,n}(),e.data.geopath=function(){var t=d3.geo.path(),n="mercator",r=e.identity,i={},s={path:"path"},o=e.data.mapper(function(e){return e[s.path]=t(r(e)),e});return o.projection=function(e){if(n!==e){n=e;var r=d3.geo[n]();for(var s in i)r[s](i[s]);t.projection(r)}return o},e.data.geo.params.forEach(function(e){o[e]=function(n){return i[e]=n,t.projection()[e](n),o}}),o.value=function(t){return r=e.accessor(t),o},o.output=function(t){return e.keys(s).forEach(function(e){t[e]!==undefined&&(s[e]=t[e])}),t},o},e.data.link=function(){function o(e){var t=n(e),i=r(e);return"M"+t.x+","+t.y+"L"+i.x+","+i.y}function u(e){var t=n(e),s=r(e),o=s.x-t.x,u=s.y-t.y,a=i*(o+u),f=i*(u-o);return"M"+t.x+","+t.y+"C"+(t.x+a)+","+(t.y+f)+" "+(s.x+f)+","+(s.y-a)+" "+s.x+","+s.y}function a(e){var t=n(e),i=r(e),s=(t.x+i.x)/2;return"M"+t.x+","+t.y+"C"+s+","+t.y+" "+s+","+i.y+" "+i.x+","+i.y}function f(e){var t=n(e),i=r(e),s=(t.y+i.y)/2;return"M"+t.x+","+t.y+"C"+t.x+","+s+" "+i.x+","+s+" "+i.x+","+i.y}function c(e){var n=l[t];return e.forEach(function(e){e[s.path]=n(e)}),e}var t="line",n=e.accessor("source"),r=e.accessor("target"),i=.2,s={path:"path"},l={line:o,curve:u,diagonal:a,diagonalX:a,diagonalY:f};return c.shape=function(e){return t=e,c},c.tension=function(e){return i=e,c},c.source=function(t){return n=e.accessor(t),c},c.target=function(t){return r=e.accessor(t),c},c.output=function(t){return e.keys(s).forEach(function(e){t[e]!==undefined&&(s[e]=t[e])}),c},c},e.data.pie=function(){function u(e){var t=e.map(function(e,t){return+n(e)}),u=r,a=(i-r)/d3.sum(t),f=d3.range(e.length);return s&&f.sort(function(e,n){return t[e]-t[n]}),f.forEach(function(n){var r;e[n].value=r=t[n],e[n][o.startAngle]=u,e[n][o.endAngle]=u+=r*a}),e}var t=function(){return 1},n=t,r=0,i=2*Math.PI,s=!1,o={startAngle:"startAngle",endAngle:"endAngle"};return u.sort=function(e){return s=e,u},u.value=function(r){return n=r?e.accessor(r):t,u},u.startAngle=function(e){return r=Math.PI*e/180,u},u.endAngle=function(e){return i=Math.PI*e/180,u},u.output=function(t){return e.keys(o).forEach(function(e){t[e]!==undefined&&(o[e]=t[e])}),u},u},e.data.sort=function(){function n(n){n=e.isArray(n)?n:n.values||[],n.sort(t);for(var r=0,i=n.length;r<i;++r)n[r].index=r;return n}var t=null;return n.by=function(r){return t=e.comparator(r),n},n},e.data.stack=function(){function o(e){var i=s.y0,o=s.y1;return t.x(n).y(r).out(function(e,t,n){e[i]=t,e[o]=n+t})(e.values)}var t=d3.layout.stack().values(function(e){return e.values}),n=null,r=null,i=["offset","order"],s={y0:"y2",y1:"y"};return o.point=function(t){return n=e.accessor(t),o},o.height=function(t){return r=e.accessor(t),o},i.forEach(function(e){o[e]=function(n){return t[e](n),o}}),o.output=function(e){return d3.keys(s).forEach(function(t){e[t]!==undefined&&(s[t]=e[t])}),o},o},e.data.stats=function(){function i(i){var s=+Infinity,o=-Infinity,u=0,a=0,f=0,l,c,h,p,d=(e.isArray(i)?i:i.values||[]).map(t);for(l=0,c=d.length;l<c;++l)h=d[l],h<s&&(s=h),h>o&&(o=h),u+=h,p=h-a,a+=p/(l+1),f+=p*(h-a);f/=c-1;var v=e.isArray(i)?{}:i;return n&&(d.sort(e.numcmp),l=d.length>>1,v[r.median]=d.length%2?d[l]:(d[l-1]+d[l])/2),v[r.count]=c,v[r.min]=s,v[r.max]=o,v[r.sum]=u,v[r.mean]=a,v[r.variance]=f,v[r.stdev]=Math.sqrt(f),v}function s(e){return(Array.isArray(e)?[e]:e.values||[]).map(i)}var t=e.accessor("data"),n=!1,r={count:"count",min:"min",max:"max",sum:"sum",mean:"mean",variance:"variance",stdev:"stdev",median:"median"};return s.median=function(e){return n=e||!1,s},s.value=function(n){return t=e.accessor(n),s},s.output=function(t){return e.keys(r).forEach(function(e){t[e]!==undefined&&(r[e]=t[e])}),s},s},e.data.treemap=function(){function o(i,o,u){i=t.size(e.data.size(r,u)).value(n).nodes(i);var a=e.keys(s),f=a.length;return i.forEach(function(e){var t,n;for(var r=0;r<f;++r)t=a[r],t!==s[t]&&(n=e[t],delete e[t],e[s[t]]=n)}),i}var t=d3.layout.treemap().children(function(e){return e.values}),n=e.accessor("data"),r=["width","height"],i=["round","sticky","ratio","padding"],s={x:"x",y:"y",dx:"width",dy:"height"};return o.size=function(e){return r=e,o},o.value=function(t){return n=e.accessor(t),o},i.forEach(function(e){o[e]=function(n){return t[e](n),o}}),o.output=function(t){return e.keys(s).forEach(function(e){t[e]!==undefined&&(s[e]=t[e])}),o},o},e.data.unique=function(){function r(r){return e.unique(r,t).map(function(e){var t={};return t[n]=e,t})}var t=null,n="field";return r.field=function(n){return t=e.accessor(n),r},r.as=function(e){return n=e,r},r},e.data.wordcloud=function(){function a(o,a,f){function l(n,r){var s=t.size(),a=s[0]/2,f=s[1]/2,l=e.keys(u),c,h,p,d,v,m=l.length;o.sort(function(e,t){return i(t)-i(e)});for(p=0,d=n.length;p<d;++p){h=o[p];for(v=0;v<m;++v)c=l[v],h[u[c]]=n[p][c],c==="x"&&(h[u.x]+=a),c==="y"&&(h[u.y]+=f)}}return t.size(e.data.size(r,f)).text(n).fontSize(i).rotate(s).words(o).on("end",l).start(),o}var t=d3.layout.cloud().size([900,500]),n=e.accessor("data"),r=["width","height"],i=function(){return 14},s=function(){return 0},o=["font","fontStyle","fontWeight","padding"],u={x:"x",y:"y",size:"fontSize",font:"font",rotate:"angle"};return a.text=function(t){return n=e.accessor(t),a},a.size=function(e){return r=
e,a},a.fontSize=function(t){return i=e.accessor(t),a},a.rotate=function(t){var n;return e.isObject(t)&&!Array.isArray(t)?t.random!==undefined?(n=(n=t.random)?e.array(n):[0],s=function(){return n[~~(Math.random()*n.length-1e-5)]}):t.alternate!==undefined&&(n=(n=t.alternate)?e.array(n):[0],s=function(e,t){return n[t%n.length]}):s=e.accessor(field),a},o.forEach(function(e){a[e]=function(n){return t[e](n),a}}),a.output=function(t){return e.keys(u).forEach(function(e){t[e]!==undefined&&(u[e]=t[e])}),a},a},e.data.zip=function(){function s(e,s){var o=s[t],u,a,f,l;i&&(l={},o.forEach(function(e){l[i(e)]=e}));for(a=0,f=e.length;a<f;++a)u=e[a],u[n]=l?l[r(u)]:o[a];return e}var t=null,n="zip",r=e.accessor("data"),i=null;return s["with"]=function(e){return t=e,s},s.as=function(e){return n=e,s},s.key=function(t){return r=e.accessor(t),s},s.withKey=function(t){return i=e.accessor(t),s},s},e.parse={},e.parse.axes=function(){function t(e,t,r){(e||[]).forEach(function(e,i){t[i]=t[i]||d3.svg.axis(),n(e,i,t[i],r)})}function n(t,n,r,i){t.scale!==undefined&&(r.scale(i[t.scale]),r.scaleName=t.scale);var s=t.orient||e[t.type];r.orient(s),t.values!==undefined&&r.tickValues(t.values),t.format!==undefined&&r.tickFormat(d3.format(t.format)),t.subdivide!==undefined&&r.tickSubdivide(t.subdivide),t.tickPadding!==undefined&&r.tickPadding(t.tickPadding);var o=[];if(t.tickSize!==undefined)for(var u=0;u<3;++u)o.push(t.tickSize);else o=[6,6,6];t.tickSizeMajor!==undefined&&(o[0]=t.tickSizeMajor),t.tickSizeMinor!==undefined&&(o[1]=t.tickSizeMinor),t.tickSizeEnd!==undefined&&(o[2]=t.tickSizeEnd),o.length&&r.tickSize.apply(r,o);if(t.ticks!==undefined){var a=Array.isArray(t.ticks)?t.ticks:[t.ticks];r.ticks.apply(r,a)}t.offset&&(r.offset=t.offset)}var e={x:"bottom",y:"left",top:"top",bottom:"bottom",left:"left",right:"right"};return t}(),e.parse.data=function(t,n){function s(t){return function(s,o){s?e.error("LOADING ERROR: "+t.url):r.load[t.name]=e.data.read(o.responseText,t.format),--i===0&&n()}}var r={defs:t,load:{},flow:{},source:{}},i=0;return(t||[]).forEach(function(t){t.url&&(i+=1,e.log("LOADING: "+t.url),d3.xhr(t.url,s(t))),t.values&&(r.load[t.name]=t.values);if(t.source){var n=r.source[t.source]||(r.source[t.source]=[]);n.push(t.name)}t.transform&&(r.flow[t.name]=e.parse.dataflow(t))}),i===0&&setTimeout(n,1),r},e.parse.dataflow=function(t){var n=(t.transform||[]).map(e.parse.transform);return n.length?function(e,t,r){return n.reduce(function(e,n){return n(e,t,r)},e)}:e.identity},e.parse.marks=function(){function t(n){var r=n.properties,i=n.marks;e.keys(r).forEach(function(t){r[t]=e.parse.properties(r[t])}),n.delay&&(n.delay=e.parse.properties({delay:n.delay}));if(n.from){var s=n.from.data,o=e.parse.dataflow(n.from);n.from=function(t,n,r){var i=e.scene.data(s?t[s]:null,r);return o(i,t,n)}}return i&&(n.marks=i.map(t)),n}return function(n){return{type:"group",width:n.width,height:n.height,axes:n.axes,scales:n.scales,marks:e.duplicate(n.marks).map(t)}}}(),e.parse.properties=function(){function t(t){var r="",i=e.keys(t),s,o,u,a,f={};r+="var o = trans ? {} : item;\n";for(s=0,o=i.length;s<o;++s)a=t[u=i[s]],r+=s>0?"\n ":" ",r+="o."+u+" = "+n(a)+";",f[u]=!0;return f.x2&&(r+="\n if (o.x > o.x2) { var t = o.x; o.x = o.x2; o.x2 = t; };",r+="\n o.width = (o.x2 - o.x);"),f.y2&&(r+="\n if (o.y > o.y2) { var t = o.y; o.y = o.y2; o.y2 = t; };",r+="\n o.height = (o.y2 - o.y);"),r+="if (trans) trans.interpolate(item, o);",Function("item","group","trans",r)}function n(t){if(t==null)return null;var n=t.value!==undefined?e.str(t.value):"item.datum.data";t.field!==undefined&&(n="item.datum["+e.field(t.field).map(e.str).join("][")+"]");if(t.scale!==undefined){var r="group.scales['"+t.scale+"']";t.band?n=r+".rangeBand()":n=r+"("+n+")"}return"("+(t.mult?t.mult+" * ":"")+n+")"+(t.offset?" + "+t.offset:"")}return t}(),e.parse.scales=function(){function u(e,t,n,r){return(e||[]).reduce(function(e,t){return e[t.name]=a(t,e[t.name],n,r),e},t||{})}function a(r,i,s,o){var u=r.type||t,a=i||d3.scale[u](),h=c(r,o),p=u===n?f:l,d=e.values(o.datum);return p(r,a,h,s,d),a}function f(t,n,r,i,s){var o,u,a,f;o=t.domain,Array.isArray(o)?n.domain(o):e.isObject(o)&&(u=i[o.data]||s,a=e.accessor(o.field),n.domain(e.unique(u,a))),f=typeof r[0]=="string",f||r.length>2?n.range(r):t.points?n.rangePoints(r,t.padding||0):t.round||t.round===undefined?n.rangeRoundBands(r,t.padding||0):n.rangeBands(r,t.padding||0)}function l(t,n,s,o,u){var a,f,l;a=[null,null],t.domain!==undefined&&(Array.isArray(t.domain)?a=t.domain.slice():e.isObject(t.domain)?(f=o[t.domain.data]||u,l=e.accessor(t.domain.field),a[0]=d3.min(f,l),a[1]=d3.max(f,l)):a=t.domain),t.domainMin!==undefined&&(e.isObject(t.domainMin)?(f=o[t.domainMin.data]||u,l=e.accessor(t.domainMin.field),a[0]=d3.min(f,l)):a[0]=t.domainMin),t.domainMax!==undefined&&(e.isObject(t.domainMax)?(f=o[t.domainMax.data]||u,l=e.accessor(t.domainMax.field),a[1]=d3.max(f,l)):a[1]=t.domainMax),t.type!==r&&(t.zero||t.zero===undefined)&&(a[0]=Math.min(0,a[0]),a[1]=Math.max(0,a[1])),n.domain(a),t.range=="height"&&(s=s.reverse()),n[t.round?"rangeRound":"range"](s),t.clamp&&n.clamp(!0),t.nice&&n.nice(),t.exponent&&t.type===i&&n.exponent(t.exponent)}function c(t,n){var r=[null,null];if(t.range!==undefined)if(typeof t.range=="string")if(s[t.range])r=[0,n[t.range]];else{if(!o[t.range])return e.error("Unrecogized range: "+t.range),r;r=e[t.range]}else Array.isArray(t.range)?r=t.range:r=[0,t.range];t.rangeMin!==undefined&&(r[0]=t.rangeMin),t.rangeMax!==undefined&&(r[1]=t.rangeMax);if(t.reverse!==undefined){var i=t.reverse;e.isObject(i)&&(i=e.accessor(i.field)(n.datum)),i&&(r=r.reverse())}return r}var t="linear",n="ordinal",r="log",i="pow",s={width:1,height:1},o={category10:1,category20:1,shapes:1};return u}(),e.parse.spec=function(t,n){function r(t){var r={marks:e.parse.marks(t),data:e.parse.data(t.data,function(){n(s)})},s=function(n){var s=(new e.View).width(t.width||500).height(t.height||500).padding(i(t.padding)).viewport(t.viewport||null).renderer(n.renderer||"canvas").initialize(n.el).defs(r).data(r.data.load).data(n.data);return n.hover!==!1&&s.on("mouseover",function(e,t){this.update({props:"hover",items:t})}).on("mouseout",function(e,t){this.update({props:"update",items:t})}),s}}function i(t){if(e.isObject(t))return t;var n=e.isNumber(t)?t:20;return{top:n,left:n,right:n,bottom:n}}e.isObject(t)?r(t):d3.json(t,function(t,n){t?e.error(t):r(n)})},e.parse.transform=function(t){var n=e.data[t.type]();return e.keys(t).forEach(function(e){if(e==="type")return;n[e](t[e])}),n},e.scene={},e.scene.GROUP="group",e.scene.ENTER=0,e.scene.UPDATE=1,e.scene.EXIT=2,e.scene.DEFAULT_DATA={sentinel:1},e.scene.data=function(t,n){var r=e.scene.DEFAULT_DATA;return t=e.values(t||n||[r]),t===r&&(t=[r]),t},e.scene.Item=function(){function e(e){this.mark=e}var t=e.prototype;return t.cousin=function(e,t){if(e===0)return this;e=e||-1;var n=this.mark,r=n.group,i=t==null?n.items.indexOf(this):t,s=r.items.indexOf(n)+e;return r.items[s].items[i]},t.sibling=function(e){if(e===0)return this;e=e||-1;var t=this.mark,n=t.items.indexOf(this)+e;return t.items[n]},t.remove=function(){var e=this,t=e.mark.items,n=t.indexOf(e);return n>=0&&(n===t.length-1?t.pop():t.splice(n,1)),e},e}(),e.scene.item=function(t){return new e.scene.Item(t)},e.scene.build=function(){function o(n,r,i,s){var o=e.scene.data(n.from?n.from(r,i,s):null,s);return i=u(n,i),i.items=a(n,o,i),l(n,i),n.type===t&&f(n,r,i),i}function u(e,t){return t=t||{},t.def=e,t.marktype=e.type,t.interactive=e.interactive!==!1,t}function a(t,s,o){var u=c(t.key),a=o.items||[],f=[],l={},h,p,d,v,m,g;for(h=0,d=a.length;h<d;++h)v=a[h],v.status=i,u&&(l[v.key]=v);for(h=0,d=s.length;h<d;++h)m=s[h],p=h,v=u?l[p=u(m)]:a[h],g=v?!1:(v=e.scene.item(o),!0),v.status=g?n:r,v.datum=m,v.key=p,f.push(v);for(h=0,d=a.length;h<d;++h)v=a[h],v.status===i&&(v.key=u?v.key:f.length,f.push(v));return f}function f(e,t,n){var r=n.items,i=e.marks,s,u,a,f,l;for(s=0,u=r.length;s<u;++s){l=r[s],l.items=l.items||[];for(a=0,f=i.length;a<f;++a)l.items[a]=o(i[a],t,l.items[a],l.datum),l.items[a].group=l}}function l(e,t){e.duration&&(t.duration=e.duration),e.ease&&(t.ease=d3.ease(e.ease));if(e.delay){var n=t.items,r=t.group,i=n.length,s;for(s=0;s<i;++s)e.delay.call(this,n[s],r)}}function c(t){return t?e.accessor(t):null}var t=e.scene.GROUP,n=e.scene.ENTER,r=e.scene.UPDATE,i=e.scene.EXIT,s={sentinel:1};return o}(),e.scene.encode=function(){function s(e,t,n,r,i){return r&&i?o.call(this,e,t,n,r,i):u.call(this,e,e,t,n,r),e}function o(t,n,r,i,s){s=e.array(s);var o,u,a,f,l,c;for(o=0,u=s.length;o<u;++o)a=s[o],f=a.mark.group||null,l=a.mark.def.properties,c=l&&l[i],c&&c.call(this,a,f,r)}function u(e,n,r,i,s){f.call(this,e,n.items,r,i,s),n.marktype===t&&a.call(this,n,r,e,i,s)}function a(t,n,r,i,s){var o,a,f,l,c,h,p;for(o=0,a=t.items.length;o<a;++o){c=t.items[o],h=c.scales||(c.scales=e.extend({},r.scales)),n.scales&&e.parse.scales(n.scales,h,this._data,c),n.axes&&(p=c.axes||(c.axes=[]),e.parse.axes(n.axes,p,c.scales));for(f=0,l=c.items.length;f<l;++f)u.call(this,c,c.items[f],n.marks[f],i,s)}}function f(e,t,s,o,u){if(s.properties==null)return;var a=s.properties,f=a.enter,l=a.update,c=a.exit,h,p,d,v;if(u&&(v=a[u])){for(h=0,p=t.length;h<p;++h)v.call(this,t[h],e,o);return}for(h=0;h<t.length;++h)d=t[h],d.status===n&&(f&&f.call(this,d,e),d.status=r),d.status!==i&&l&&l.call(this,d,e,o),d.status===i&&(c&&o&&c.call(this,d,e,o),o||t[h--].remove())}var t=e.scene.GROUP,n=e.scene.ENTER,r=e.scene.UPDATE,i=e.scene.EXIT;return s}(),e.scene.Transition=function(){function t(e,t){this.duration=e||500,this.ease=t&&d3.ease(t)||d3.ease("cubic-in-out"),this.updates={next:null}}function r(e){var t=this.updates,n=t,r=n.next,i=this.duration,s,o,u,a,f,l,c=!0;for(;r!=null;n=r,r=n.next){s=r.item,o=s.delay||0,u=(e-o)/i;if(u<0){c=!1;continue}u>1&&(u=1),a=r.ease(u);for(f=0,l=r.length;f<l;++f)s[r[f].property]=r[f](a);u===1?(r.remove&&s.remove(),n.next=r.next,r=n):c=!1}return this.callback(),c}var n=t.prototype;return n.interpolate=function(e,t){var n,r,i,s,o=null;for(n in t)r=e[n],i=t[n],r!==i&&(s=d3.interpolate(r,i),s.property=n,(o||(o=[])).push(s));return s&&(o.item=e,o.ease=e.mark.ease||this.ease,o.next=this.updates.next,this.updates.next=o),this},n.start=function(t){var n=this,i=n.updates,s=i.next;for(;s!=null;i=s,s=i.next)s.item.status===e.scene.EXIT&&(s.remove=!0);n.callback=t,d3.timer(function(e){return r.call(n,e)})},t}(),e.scene.transition=function(t,n){return new e.scene.Transition(t,n)},e.Axes=function(){function r(t,n,i,s){var o,u,a,f,l,c,h,p;for(o=0,a=t.items.length;o<a;++o){l=t.items[o],h=n+(l.x||0),p=i+(l.y||0);if(f=l.axes)for(u=0;u<f.length;++u)s.push({axis:f[u],group:l,x:h,y:p});for(c=l.items,u=0;u<c.length;++u)c[u].marktype===e.scene.GROUP&&r(c[u],h,p,s)}return s}var t=function(){this._svg=null,this._el=null,this._init=!1},n=t.prototype;return n.initialize=function(e,t,n,r){this._el=e,this._width=t,this._height=n,this._padding=r;var i=d3.select(e).selectAll("svg.axes").data([1]);i.enter().append("svg").style("pointer-events","none"),i.attr("class","axes").attr("width",t+r.left+r.right).attr("height",n+r.top+r.bottom).style({position:"absolute",left:0,top:0});var s=i.selectAll("g").data([1]);return s.enter().append("g"),s.attr("transform","translate("+r.left+","+r.top+")"),this._init=!1,this},n.element=function(){return this._el},n.update=function(e,t,n){t=t||0,n=n||"cubic-in-out";var i=this._init;this._init=!0;var s=d3.select(this._el).selectAll("svg.axes").select("g"),o=r(e.scene(),0,0,[]);i||s.selectAll("g.axis").data(o).enter().append("g").attr("class",function(e,t){return"axis axis-"+t});var u=t&&i?s.transition(t).ease(n):s,a=this._width,f=this._height;u.selectAll("g.axis").attr("transform",function(e,t){var n=e.axis.offset||0,r=e.group.width||a,i=e.group.height||f,s;switch(e.axis.orient()){case"left":s=[-n,0];break;case"right":s=[r+n,0];break;case"bottom":s=[0,i+n];break;case"top":s=[0,-n];break;default:s=[0,0]}return"translate("+(s[0]+e.x)+", "+(s[1]+e.y)+")"}).each(function(e){e.axis.scale(e.group.scales[e.axis.scaleName]);var n=d3.select(this);(t&&i?n.transition().duration(t):n).call(e.axis)})},t}(),e.Model=function(){function t(){this._defs=null,this._data={},this._scene=null}var n=t.prototype;return n.defs=function(e){return arguments.length?(this._defs=e,this):this._defs},n.data=function(t){if(!arguments.length)return this._data;var n=this._defs.data.flow||{},r=this._defs.data.defs.map(e.accessor("name")),i,s,o,u,a;for(i=0,o=r.length;i<o;++i){if(!t[u=r[i]])continue;this._data[u]=n[u]?n[u](t[u],this._data,this._defs.marks):t[u],a=this._defs.data.source[u]||[];for(s=0;s<a.length;++s)this._data[a[s]]=n[a[s]]?n[a[s]](this._data[u],this._data,this._defs.marks):this._data[u]}return this},n.width=function(e){return this._defs&&this._defs.marks&&(this._defs.marks.width=e),this._scene&&(this._scene.items[0].width=e),this},n.height=function(e){return this._defs&&this._defs.marks&&(this._defs.marks.height=e),this._scene&&(this._scene.items[0].height=e),this},n.scene=function(e){return arguments.length?(this._scene=e,this):this._scene},n.build=function(){var t=this,n=t._data,r=t._defs.marks;return t._scene=e.scene.build.call(t,r,n,t._scene),t._scene.items[0].width=r.width,t._scene.items[0].height=r.height,t._scene.interactive=!1,this},n.encode=function(t,n,r){var i=this,s=i._scene,o=i._defs;return e.scene.encode.call(i,s,o.marks,t,n,r),this},t}(),e.View=function(){var t=function(t,n,r){this._el=null,this._build=!1,this._model=new e.Model,this._width=n||500,this._height=r||500,this._padding={top:0,left:0,bottom:0,right:0},this._viewport=null,this._renderer=null,this._handler=null,this._io=e.canvas,t&&this.initialize(t)},n=t.prototype;return n.width=function(e){return arguments.length?(this._width!==e&&(this._width=e,this._el&&this.initialize(this._el.parentNode),this._model.width(e)),this):this._width},n.height=function(e){return arguments.length?(this._height!==e&&(this._height=e,this._el&&this.initialize(this._el.parentNode),this._model.height(this._height)),this):this._height},n.padding=function(e){return arguments.length?(this._padding!==e&&(this._padding=e,this._el&&this.initialize(this._el.parentNode)),this):this._padding},n.viewport=function(e){return arguments.length?(this._viewport!==e&&(this._viewport=e,this._el&&this.initialize(this._el.parentNode)),this):this._viewport},n.renderer=function(t){return arguments.length?(t==="canvas"&&(t=e.canvas),t==="svg"&&(t=e.svg),this._io!==t&&(this._io=t,this._renderer=null,this._el&&this.initialize(this._el.parentNode),this._build&&this.render()),this):this._io},n.defs=function(e){return arguments.length?(this._model.defs(e),this):this._model.defs()},n.data=function(t){if(!arguments.length)return this._model.data();var n=e.keys(t).reduce(function(n,r){return n[r]=t[r].map(e.data.ingest),n},{});return this._model.data(n),this._build=!1,this},n.model=function(e){return arguments.length?(this._model!==e&&(this._model=e,this._handler&&this._handler.model(e)),this):this._model},n.initialize=function(t){var n=this,r,i=n._width,s=n._height,o=n._padding;return d3.select(t).select("div.vega").remove(),this._el=t=d3.select(t).append("div").attr("class","vega").style("position","relative").node(),n._viewport&&d3.select(t).style("width",(n._viewport[0]||i)+"px").style("height",(n._viewport[1]||s)+"px").style("overflow","auto"),n._axes=(n._axes||new e.Axes).initialize(t,i,s,o),n._renderer=(n._renderer||new this._io.Renderer).initialize(t,i,s,o),r=n._handler,n._handler=(new this._io.Handler).initialize(t,o,n).model(n._model),r&&r.handlers().forEach(function(e){n._handler.on(e.type,e.handler)}),this},n.render=function(e){return this._axes.update(this._model),this._renderer.render(this._model.scene(),e),this},n.on=function(){return this._handler.on.apply(this._handler,arguments),this},n.off=function(){return this._handler.off.apply(this._handler,arguments),this},n.update=function(t){t=t||{};var n=this,r=t.duration?e.scene.transition(t.duration,t.ease):null;return n._build=n._build||(n._model.build(),!0),n._model.encode(r,t.props,t.items),r?(r.start(function(e){n._renderer.render(n._model.scene(),e)}),this._axes.update(this._model,t.duration,t.ease)):n.render(t.items),n},t}(),e.Spec=function(){var t=function(t){this.spec={width:500,height:500,padding:0,data:[],scales:[],axes:[],marks:[]},t&&e.extend(this.spec,t)},n=t.prototype;return n.width=function(e){return this.spec.width=e,this},n.height=function(e){return this.spec.height=e,this},n.padding=function(e){return this.spec.padding=e,this},n.viewport=function(e){return this.spec.viewport=e,this},n.data=function(t,n){return n?n.name=t:n=e.isString(t)?{name:t}:t,this.spec.data.push(n),this},n.scale=function(t,n){return n?n.name=t:n=e.isString(t)?{name:t}:t,this.spec.scales.push(n),this},n.axis=function(e){return this.spec.axes.push(e),this},n.mark=function(t,n){n?n.type=t:n={type:t},n.properties={},this.spec.marks.push(n);var r=this;return{from:function(t,r){return n.from=r?(r.data=t,r):e.isString(t)?{data:t}:t,this},prop:function(t,r){return n.properties[t]=e.keys(r).reduce(function(t,n){var i=r[n];return t[n]=e.isObject(i)?i:{value:i},t},{}),this},done:function(){return r}}},n.parse=function(t){e.parse.spec(this.spec,t)},n.json=function(){return this.spec},t}(),e.spec=function(t){return new e.Spec(t)},e}();