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