forked from vega/vega
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vega.min.js
3 lines (3 loc) · 74.4 KB
/
vega.min.js
1
2
3
vg=function(e){function r(e,t,n){var r=0,s=e.split(i);return n?e=(s=s.reverse()).filter(function(e){return r+=e.length,r<=t}).reverse():e=s.filter(function(e){return r+=e.length,r<=t}),e.length?e.join("").trim():s[0].slice(0,t)}function s(e){t.config.isNode?process.stderr.write(e+"\n"):console.log(e)}function f(e){return u.test(e)}function l(e){return e.indexOf(a)===0}function c(n,r){t.log("LOAD: "+n),e.xhr(n,function(e,t){t&&(t=t.responseText),r(e,t)})}function h(e,n){t.log("LOAD FILE: "+e);var r=e.indexOf(a);r>=0&&(e=e.slice(a.length)),require("fs").readFile(e,n)}function p(e,n){t.log("LOAD HTTP: "+e);var r=require("http").request(e,function(e){var t=0,r=new Buffer(parseInt(e.headers["content-length"],10));e.on("error",function(e){n(e,null)}),e.on("data",function(e){e.copy(r,t),t+=e.length}),e.on("end",function(){n(null,r)})});r.on("error",function(e){n(e)}),r.end()}function v(e,t,n){i=[];if(n&&t.length>1){var r=m(e.domain()),i,s=-1,o=t.length,u=(t[1]-t[0])/++n,a,f;while(++s<o)for(a=n;--a>0;)(f=+t[s]-a*u)>=r[0]&&i.push(f);for(--s,a=0;++a<n&&(f=+t[s]+a*u)<r[1];)i.push(f)}return i}function m(e){var t=e[0],n=e[e.length-1];return t<n?[t,n]:[n,t]}function g(e){return e.rangeExtent?e.rangeExtent():m(e.range())}function E(e,n,r,i,s,o){s=Math.max(s,0)+o;if(e==="left"||e==="top")s*=-1;e==="top"||e==="bottom"?(t.extend(n.properties.enter,{x:r,y:{value:s}}),t.extend(n.properties.update,{x:i,y:{value:s},align:{value:"center"},baseline:{value:w[e]}})):(t.extend(n.properties.enter,{x:{value:s},y:r}),t.extend(n.properties.update,{x:{value:s},y:i,align:{value:b[e]},baseline:{value:"middle"}}))}function S(e,n,r,i,s){var o=e==="left"||e==="top"?-1:1;s===Infinity?s=e==="top"||e==="bottom"?{group:"height",mult:-o}:{group:"width",mult:-o}:s={value:o*s},e==="top"||e==="bottom"?(t.extend(n.properties.enter,{x:r,y:{value:0},y2:s}),t.extend(n.properties.update,{x:i,y:{value:0},y2:s}),t.extend(n.properties.exit,{x:i})):(t.extend(n.properties.enter,{x:{value:0},x2:s,y:r}),t.extend(n.properties.update,{x:{value:0},x2:s,y:i}),t.extend(n.properties.exit,{y:i}))}function T(e,n,r,i){var s=~~((r[1]-r[0])/2),o=e==="top"||e==="left"?-1:1;e==="bottom"||e==="top"?t.extend(n.properties.update,{x:{value:s},y:{value:o*i},angle:{value:0}}):t.extend(n.properties.update,{x:{value:o*i},y:{value:s},angle:{value:-90}})}function N(e,t,n,r){var i;if(e==="top"||e==="left")r=-1*r;e==="bottom"||e==="top"?i="M"+n[0]+","+r+"V0H"+n[1]+"V"+r:i="M"+r+","+n[0]+"H0V"+n[1]+"H"+r,t.properties.update.path={value:i}}function C(e,t,n){var r=n?{}:e,i=e.mark.def.offset,s=e.mark.def.orient,o=t.width,u=t.height;e.width=o,e.height=u;switch(s){case"left":r.x=-i,r.y=0;break;case"right":r.x=o+i,r.y=0;break;case"bottom":r.x=0,r.y=u+i;break;case"top":r.x=0,r.y=-i;break;default:r.x=0,r.y=0}n&&n.interpolate(e,r)}function k(){return{type:"rule",interactive:!1,key:"data",properties:{enter:{stroke:{value:t.config.axis.tickColor},strokeWidth:{value:t.config.axis.tickWidth},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function L(){return{type:"text",interactive:!1,key:"data",properties:{enter:{fill:{value:t.config.axis.tickLabelColor},font:{value:t.config.axis.tickLabelFont},fontSize:{value:t.config.axis.tickLabelFontSize},opacity:{value:1e-6},text:{field:"label"}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function A(){return{type:"text",interactive:!1,properties:{enter:{font:{value:t.config.axis.titleFont},fontSize:{value:t.config.axis.titleFontSize},fontWeight:{value:t.config.axis.titleFontWeight},fill:{value:t.config.axis.titleColor},align:{value:"center"},baseline:{value:"middle"},text:{field:"data"}},update:{}}}}function O(){return{type:"path",interactive:!1,properties:{enter:{x:{value:.5},y:{value:.5},stroke:{value:t.config.axis.axisColor},strokeWidth:{value:t.config.axis.axisWidth}},update:{}}}}function _(e,t,n){var r=n?{}:e,i=e.mark.def.offset,s=e.mark.def.orient,o=t.width,u=100;r.x=.5,r.y=.5;switch(s){case"left":r.x+=-i-u;break;case"right":r.x+=o+i}n&&n.interpolate(e,r)}function D(e,t,n,r,i){var s=e.properties.enter;t&&(s.size={scale:t.scaleName,field:"data"}),n&&(s.shape={scale:n.scaleName,field:"data"}),r&&(s.fill={scale:r.scaleName,field:"data"}),i&&(s.stroke={scale:i.scaleName,field:"data"})}function P(){var e=t.config.legend;return{type:"text",interactive:!1,key:"data",properties:{enter:{x:{value:0},y:{value:0},fill:{value:e.titleColor},font:{value:e.titleFont},fontSize:{value:e.titleFontSize},fontWeight:{value:e.titleFontWeight},baseline:{value:"top"},text:{field:"data"},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function H(){var e=t.config.legend;return{type:"symbol",interactive:!1,key:"data",properties:{enter:{x:{field:"offset",mult:.5},y:{scale:"legend",field:"index"},shape:{value:e.symbolShape},size:{value:e.symbolSize},stroke:{value:e.symbolColor},strokeWidth:{value:e.symbolStrokeWidth},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function B(){var e=t.config.legend;return{type:"text",interactive:!1,key:"data",properties:{enter:{x:{field:"offset",offset:5},y:{scale:"legend",field:"index"},fill:{value:e.labelColor},font:{value:e.labelFont},fontSize:{value:e.labelFontSize},align:{value:e.labelAlign},baseline:{value:e.labelBaseline},text:{field:"label"},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function j(){var e=t.config.legend;return{type:"rect",interactive:!1,properties:{enter:{x:{value:0},y:{value:0},width:{value:e.gradientWidth},height:{value:e.gradientHeight},stroke:{value:e.gradientStrokeColor},strokeWidth:{value:e.gradientStrokeWidth},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}function F(){var e=t.config.legend;return{type:"text",interactive:!1,key:"data",properties:{enter:{x:{scale:"legend",field:"data"},y:{value:20},dy:{value:2},fill:{value:e.labelColor},font:{value:e.labelFont},fontSize:{value:e.labelFontSize},align:{field:"align"},baseline:{value:"top"},text:{field:"label"},opacity:{value:1e-6}},exit:{opacity:{value:1e-6}},update:{opacity:{value:1}}}}}var t={};t.version="1.3.0";var n=Object.prototype.toString;t.isObject=function(e){return e===Object(e)},t.isFunction=function(e){return n.call(e)=="[object Function]"},t.isString=function(e){return n.call(e)=="[object String]"},t.isArray=Array.isArray||function(e){return n.call(e)=="[object Array]"},t.isNumber=function(e){return n.call(e)=="[object Number]"},t.isBoolean=function(e){return n.call(e)=="[object Boolean]"},t.number=function(e){return+e},t.boolean=function(e){return!!e},t.identity=function(e){return e},t.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},t.duplicate=function(e){return JSON.parse(JSON.stringify(e))},t.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},[])},t.accessor=function(e){var n;return t.isFunction(e)||e==null?e:t.isString(e)&&(n=t.field(e)).length>1?function(e){return n.reduce(function(e,t){return e[t]},e)}:function(t){return t[e]}},t.comparator=function(e){var n=[];return e===undefined&&(e=[]),e=t.array(e).map(function(e){var r=1;return e[0]==="-"?(r=-1,e=e.slice(1)):e[0]==="+"&&(r=1,e=e.slice(1)),n.push(r),t.accessor(e)}),function(t,r){var i,s,o,u,a;for(i=0,s=e.length;i<s;++i){o=e[i],u=o(t),a=o(r);if(u<a)return-1*n[i];if(u>a)return n[i]}return 0}},t.cmp=function(e,t){return e<t?-1:e>t?1:0},t.numcmp=function(e,t){return e-t},t.array=function(e){return e!=null?t.isArray(e)?e:[e]:[]},t.values=function(e){return t.isObject(e)&&!t.isArray(e)&&e.values?e.values:e},t.str=function(e){return t.isArray(e)?"["+str.map(e)+"]":t.isObject(e)?JSON.stringify(e):t.isString(e)?"'"+e+"'":e},t.keys=function(e){var t=[];for(var n in e)t.push(n);return t},t.unique=function(e,n,r){if(!t.isArray(e)||e.length==0)return[];n=n||t.identity,r=r||[];for(var i,s=0,o=e.length;s<o;++s)i=n(e[s]),r.indexOf(i)<0&&r.push(i);return r},t.minIndex=function(e,n){if(!t.isArray(e)||e.length==0)return-1;n=n||t.identity;var r=0,i=n(e[0]),s=i;for(var o=1,u=e.length;o<u;++o)s=n(e[o]),s<i&&(i=s,r=o);return r},t.maxIndex=function(e,n){if(!t.isArray(e)||e.length==0)return-1;n=n||t.identity;var r=0,i=n(e[0]),s=i;for(var o=1,u=e.length;o<u;++o)s=n(e[o]),s>i&&(i=s,r=o);return r},t.truncate=function(e,t,n,i,s){var o=e.length;if(o<=t)return e;s=s||"...";var u=Math.max(0,t-s.length);switch(n){case"left":return s+(i?r(e,u,1):e.slice(o-u));case"middle":case"center":var a=Math.ceil(u/2),f=Math.floor(u/2);return(i?r(e,a):e.slice(0,a))+s+(i?r(e,f,1):e.slice(o-f));default:return(i?r(e,u):e.slice(0,u))+s}};var i=/([\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u2028\u2029\u3000\uFEFF])/;t.log=function(e){s("[Vega Log] "+e)},t.error=function(e){e="[Vega Err] "+e,s(e),typeof alert!="undefined"&&alert(e)},t.config={},t.config.isNode=typeof exports!="undefined"&&this.exports!==exports,t.config.baseURL="",t.config.svgNamespace='version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"',t.config.axis={orient:"bottom",ticks:10,padding:3,axisColor:"#000",gridColor:"#d8d8d8",tickColor:"#000",tickLabelColor:"#000",axisWidth:1,tickWidth:1,tickSize:6,tickLabelFontSize:11,tickLabelFont:"sans-serif",titleColor:"#000",titleFont:"sans-serif",titleFontSize:11,titleFontWeight:"bold",titleOffset:35},t.config.legend={orient:"right",offset:10,padding:3,gradientStrokeColor:"#888",gradientStrokeWidth:1,gradientHeight:16,gradientWidth:100,labelColor:"#000",labelFontSize:10,labelFont:"sans-serif",labelAlign:"left",labelBaseline:"middle",labelOffset:8,symbolShape:"circle",symbolSize:50,symbolColor:"#888",symbolStrokeWidth:1,titleColor:"#000",titleFont:"sans-serif",titleFontSize:11,titleFontWeight:"bold"},t.config.color={rgb:[128,128,128],lab:[50,0,0],hcl:[0,0,50],hsl:[0,0,.5]},t.config.range={category10:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],category20:["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],shapes:["circle","cross","diamond","square","triangle-down","triangle-up"]},t.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.encloses=function(e){return e&&this.x1<=e.x1&&this.x2>=e.x2&&this.y1<=e.y1&&this.y2>=e.y2},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}(),t.Gradient=function(){function e(e){this.id="grad_"+o++,this.type=e||"linear",this.stops=[],this.x1=0,this.x2=1,this.y1=0,this.y2=0}var t=e.prototype;return t.stop=function(e,t){return this.stops.push({offset:e,color:t}),this},e}();var o=0;t.canvas={},t.canvas.path=function(){function r(t){var r=[],i,s,o;t=t.slice().replace(n[0],"###$1").split(n[1]).slice(1);for(var u=0,a,f,l=t.length;u<l;u++){i=t[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=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 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(e,n,r,s){var o,u=null,a=0,f=0,l=0,c=0,h,p,d,v,m=new t.Bounds;r==undefined&&(r=0),s==undefined&&(s=0),e.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],e.lineTo(a+r,f+s),m.add(a,f);break;case"L":a=o[1],f=o[2],e.lineTo(a+r,f+s),m.add(a,f);break;case"h":a+=o[1],e.lineTo(a+r,f+s),m.add(a,f);break;case"H":a=o[1],e.lineTo(a+r,f+s),m.add(a,f);break;case"v":f+=o[1],e.lineTo(a+r,f+s),m.add(a,f);break;case"V":f=o[1],e.lineTo(a+r,f+s),m.add(a,f);break;case"m":a+=o[1],f+=o[2],e.moveTo(a+r,f+s),m.add(a,f);break;case"M":a=o[1],f=o[2],e.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],e.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],e.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,e.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,e.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],e.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],e.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,e.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,e.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(e,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(e,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":e.closePath()}u=o}return m.translate(r,s)}var e={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}}(),t.canvas.marks=function(){function a(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(),f(o,u,i,s,n,r)}function f(e,n,r,s,o,u){var a,f,l,c,h,p,d,v,m,g=Infinity,y=-Infinity,b=Infinity,w=-Infinity,E=[e,n],S=e-e%i+i;for(var f=0;f<4&&S<n;++f,S+=i)E.push(S);for(f=0,l=E.length;f<l;++f)a=E[f],c=Math.cos(a),p=r*c,v=s*c,h=Math.sin(a),d=r*h,m=s*h,g=Math.min(g,p,v),y=Math.max(y,p,v),b=Math.min(b,d,m),w=Math.max(w,d,m);return(new t.Bounds).set(o+g,u+b,o+y,u+w)}function l(e,t){return r(e,n(t.path),t.x,t.y)}function c(e,n){e.beginPath();var r=n.size!=undefined?n.size:100,i=n.x,u=n.y,a,f,l,c,h=new t.Bounds;if(n.shape==undefined||n.shape==="circle")return a=Math.sqrt(r/Math.PI),e.arc(i,u,a,0,2*Math.PI,0),e.closePath(),h.set(i-a,u-a,i+a,u+a);switch(n.shape){case"cross":a=Math.sqrt(r/5)/2,f=3*a,e.moveTo(i-f,u-a),e.lineTo(i-a,u-a),e.lineTo(i-a,u-f),e.lineTo(i+a,u-f),e.lineTo(i+a,u-a),e.lineTo(i+f,u-a),e.lineTo(i+f,u+a),e.lineTo(i+a,u+a),e.lineTo(i+a,u+f),e.lineTo(i-a,u+f),e.lineTo(i-a,u+a),e.lineTo(i-f,u+a),h.set(i-f,u-f,i+u,u+f);break;case"diamond":c=Math.sqrt(r/(2*o)),l=c*o,e.moveTo(i,u-c),e.lineTo(i+l,u),e.lineTo(i,u+c),e.lineTo(i-l,u),h.set(i-l,u-c,i+l,u+c);break;case"square":f=Math.sqrt(r),a=f/2,e.rect(i-a,u-a,f,f),h.set(i-a,u-a,i+a,u+a);break;case"triangle-down":l=Math.sqrt(r/s),c=l*s/2,e.moveTo(i,u+c),e.lineTo(i+l,u-c),e.lineTo(i-l,u-c),h.set(i-l,u-c,i+l,u+c);break;case"triangle-up":l=Math.sqrt(r/s),c=l*s/2,e.moveTo(i,u-c),e.lineTo(i+l,u+c),e.lineTo(i-l,u+c),h.set(i-l,u-c,i+l,u+c)}return e.closePath(),h}function h(t,i){var s=e.svg.area().x(function(e){return e.x}).y1(function(e){return e.y}).y0(function(e){return e.y+e.height}),o=i[0];return o.interpolate&&s.interpolate(o.interpolate),o.tension!=undefined&&s.tension(o.tension),r(t,n(s(i)))}function p(t,i){var s=e.svg.line().x(function(e){return e.x}).y(function(e){return e.y}),o=i[0];return o.interpolate&&s.interpolate(o.interpolate),o.tension!=undefined&&s.tension(o.tension),r(t,n(s(i)))}function d(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=k(t,n,i),t.fill()),s&&(a=(a=n.strokeWidth)!=undefined?a:1,a>0&&(t.globalAlpha=o*(n.strokeOpacity==null?1:n.strokeOpacity),t.strokeStyle=k(t,n,s),t.lineWidth=a,t.lineCap=(u=n.strokeCap)!=undefined?u:"butt",t.stroke(),n.bounds.expand(a)))}function v(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;d(e,t,o,o)}}function m(e,n,r){if(!n.items.length)return;var i=n.items,s,o,u,a,f,l,c,h;for(var p=0,d=i.length;p<d;++p){s=i[p];if(r&&!r.intersects(s.bounds))continue;c=s.x||0,h=s.y||0,s.bounds=(s.bounds||new t.Bounds).set(c,h,c+s.width,h+s.height),a=s.opacity==null?1:s.opacity;if(a==0)return;if(o=s.fill)e.globalAlpha=a*(s.fillOpacity==null?1:s.fillOpacity),e.fillStyle=k(e,s,o),e.fillRect(c,h,s.width,s.height);if(u=s.stroke)l=(l=s.strokeWidth)!=undefined?l:1,l>0&&(e.globalAlpha=a*(s.strokeOpacity==null?1:s.strokeOpacity),e.strokeStyle=k(e,s,u),e.lineWidth=l,e.lineCap=(f=s.strokeCap)!=undefined?f:"butt",e.strokeRect(c,h,s.width,s.height),s.bounds.expand(l))}}function g(e,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;l=s.x||0,c=s.y||0,h=s.x2!==undefined?s.x2:l,p=s.y2!==undefined?s.y2:c,s.bounds=(s.bounds||new t.Bounds).set(l,c,h,p),u=s.opacity==null?1:s.opacity;if(u==0)return;if(o=s.stroke)f=(f=s.strokeWidth)!=undefined?f:1,f>0&&(e.globalAlpha=u*(s.strokeOpacity==null?1:s.strokeOpacity),e.strokeStyle=k(e,s,o),e.lineWidth=f,e.lineCap=(a=s.strokeCap)!=undefined?a:"butt",e.beginPath(),e.moveTo(l,c),e.lineTo(h,p),e.stroke(),s.bounds.expand(f))}}function b(e,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 t.Bounds).set(f,l,f+c,l+h),o.image.loaded&&(e.globalAlpha=(p=o.opacity)!=undefined?p:1,e.drawImage(o.image,f,l,c,h))}}function w(e){return(e.fontStyle?e.fontStyle+" ":"")+(e.fontVariant?e.fontVariant+" ":"")+(e.fontWeight?e.fontWeight+" ":"")+(e.fontSize!=null?e.fontSize+"px ":"11px ")+(e.font||"sans-serif")}function E(e,n,r){if(!n.items.length)return;var i=n.items,s,o,u,a,f,l,c,h;for(var p=0,d=i.length;p<d;++p){s=i[p];if(r&&!r.intersects(s.bounds))continue;e.font=w(s),e.textAlign=s.align||"left",e.textBaseline=s.baseline||"alphabetic",s.bounds=S(e,s,s.bounds||new t.Bounds),a=s.opacity==null?1:s.opacity;if(a==0)return;s.angle?(e.save(),e.translate(s.x,s.y),e.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(o=s.fill)e.globalAlpha=a*(s.fillOpacity==null?1:s.fillOpacity),e.fillStyle=k(e,s,o),e.fillText(s.text,x,y);if(u=s.stroke)f=(f=s.strokeWidth)!=undefined?f:1,f>0&&(e.globalAlpha=a*(s.strokeOpacity==null?1:s.strokeOpacity),e.strokeStyle=k(s,u),e.lineWidth=f,e.strokeText(s.text,x,y));s.angle&&(s.bounds.rotate(s.angle*Math.PI/180,s.x,s.y),e.restore()),s.bounds.expand(1)}}function S(e,t,n){var r=t.x+(t.dx||0),i=t.y+(t.dy||0),s=e.measureText(t.text).width,o=t.fontSize||11,u=t.align,a=t.baseline;return u==="center"?r-=s/2:u==="right"&&(r-=s),a==="top"?i+=o/5:a==="bottom"?i-=o:a==="middle"?i=i-o/2+o/10:i-=4*o/5,n.set(r,i,r+s,i+o)}function T(e){return function(t,n,r){v(e,t,n,r)}}function N(e){return function(t,n,r){if(!n.items.length)return;if(r&&!r.intersects(n.items[0].bounds))return;d(e,t,n.items[0],n.items)}}function C(e,t,n){if(!t.items.length)return;var r=t.items,i,s,o,u=this,a,f,l,c,h,p;m(e,t,n);for(l=0,c=r.length;l<c;++l){i=r[l],s=i.axisItems||[],o=i.legendItems||[],a=i.x||0,f=i.y||0,e.save(),e.translate(a,f),n&&n.translate(-a,-f);for(h=0,p=s.length;h<p;++h)s[h].def.layer==="back"&&u.draw(e,s[h],n);for(h=0,p=i.items.length;h<p;++h)u.draw(e,i.items[h],n);for(h=0,p=s.length;h<p;++h)s[h].def.layer!=="back"&&u.draw(e,s[h],n);for(h=0,p=o.length;h<p;++h)u.draw(e,o[h],n);n&&n.translate(a,f),e.restore()}}function k(e,t,n){return n.id?L(e,n,t.bounds):n}function L(e,t,n){var r=n.width(),i=n.height(),s=n.x1+t.x1*r,o=n.y1+t.y1*i,u=n.x1+t.x2*r,a=n.y1+t.y2*i,f=e.createLinearGradient(s,o,u,a),l=t.stops,c,h;for(c=0,h=l.length;c<h;++c)f.addColorStop(l[c].offset,l[c].color);return f}function A(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?O(H.rect,e,t,n,r,i,s):!1}function O(e,t,n,r,i,s,o){if(!n.items.length)return!1;var u,a,f;t._ratio!==1&&(r*=t._ratio,i*=t._ratio);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 M(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:(e._ratio!==1&&(n*=e._ratio,r*=e._ratio),H.area(e,o,n,r)?o[0]:!1)}function _(e,t,n,r,i,s){return!1}function D(e,t,n,r,i,s){return!1}function P(e){return function(t,n,r,i,s,o){return O(e,t,n,r,i,s,o)}}function B(e,t,n,r,i,s){if(!t.fontSize)return!1;if(!t.angle)return!0;e.font=w(t);var o=S(e,t,u),a=-t.angle*Math.PI/180,f=Math.cos(a),l=Math.sin(a),n=t.x,r=t.y,c=f*i-l*s+(n-n*f+r*l),h=l*i+f*s+(r-n*l-r*f);return o.contains(c,h)}var n=t.canvas.path.parse,r=t.canvas.path.render,i=Math.PI/2,s=Math.sqrt(3),o=Math.tan(30*Math.PI/180),u=new t.Bounds,H={text:B,rect:function(e,t,n,r){return!0},image:function(e,t,n,r){return!0},arc:function(e,t,n,r){return a(e,t),e.isPointInPath(n,r)},area:function(e,t,n,r){return h(e,t),e.isPointInPath(n,r)},path:function(e,t,n,r){return l(e,t),e.isPointInPath(n,r)},symbol:function(e,t,n,r){return c(e,t),e.isPointInPath(n,r)}};return{draw:{group:C,area:N(h),line:N(p),arc:T(a),path:T(l),symbol:T(c),rect:m,rule:g,text:E,image:b,drawOne:N,drawAll:T},pick:{group:A,area:M,line:_,arc:P(H.arc),path:P(H.path),symbol:P(H.symbol),rect:P(H.rect),rule:D,text:P(H.text),image:P(H.image),pickAll:O}}}(),t.canvas.Renderer=function(){function i(e,t){var n=window.devicePixelRatio||1,r=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1,i=n/r;if(n!==r){var s=e.width,o=e.height;e.setAttribute("width",s*i),e.setAttribute("height",o*i),e.style.width=s+"px",e.style.height=o+"px"}return i}function s(e){var n=new t.Bounds(e.bounds);while((e=e.mark.group)!=null)n.translate(e.x||0,e.y||0);return n}function o(e){return e?t.array(e).reduce(function(e,t){return e.union(s(t))},new t.Bounds):null}function u(e,n){var r=null;return n&&(r=(new t.Bounds(n)).round(),e.beginPath(),e.rect(r.x1,r.y1,r.width(),r.height()),e.clip()),r}var n=function(){this._ctx=null,this._el=null,this._imgload=0},r=n.prototype;return r.initialize=function(t,n,r,s){this._el=t,this._width=n,this._height=r,this._padding=s;if(!t)return this;var o=e.select(t).selectAll("canvas.marks").data([1]);o.enter().append("canvas").attr("class","marks"),o.attr("width",n+s.left+s.right).attr("height",r+s.top+s.bottom);var u;return this._ctx=o.node().getContext("2d"),this._ctx._ratio=u=i(o.node(),this._ctx)||1,this._ctx.setTransform(u,0,0,u,u*s.left,u*s.top),this},r.context=function(e){return e?(this._ctx=e,this):this._ctx},r.element=function(){return this._el},r.pendingImages=function(){return this._imgload},r.render=function(e,t){var n=this._ctx,r=this._padding,i=this._width+r.left+r.right,s=this._height+r.top+r.bottom,a=null,f;this._scene=e,n.save(),a=u(n,o(t)),n.clearRect(-r.left,-r.top,i,s),this.draw(n,e,a),t&&(n.restore(),n.save(),f=u(n,o(t)),a.encloses(f)||(n.clearRect(-r.left,-r.top,i,s),this.draw(n,e,f))),n.restore(),this._scene=null},r.draw=function(e,n,r){var i=n.marktype,s=t.canvas.marks.draw[i];s.call(this,e,n,r)},r.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)},r.loadImage=function(e){var n=this,r=n._scene,i=null;return n._imgload+=1,t.config.isNode?(i=new(require("canvas").Image),t.data.load(e,function(e,r){if(e){t.error(e);return}i.src=r,i.loaded=!0,n._imgload-=1})):(i=new Image,i.onload=function(){t.log("LOAD IMAGE: "+e),i.loaded=!0,n._imgload-=1,n.renderAsync(r)},i.src=e),i},n}(),t.canvas.Handler=function(){function s(e){var t=e.indexOf(".");return t<0?e:e.slice(0,t)}var n=function(e,t){this._active=null,this._handlers={},e&&this.initialize(e),t&&this.model(t)},r=n.prototype;r.initialize=function(t,n,s){this._el=e.select(t).node(),this._canvas=e.select(t).select("canvas.marks").node(),this._padding=n,this._obj=s||null;var o=this._canvas,u=this;return i.forEach(function(e){o.addEventListener(e,function(t){r[e].call(u,t)})}),this},r.model=function(e){return arguments.length?(this._model=e,this):this._model},r.handlers=function(){var e=this._handlers;return t.keys(e).reduce(function(t,n){return e[n].reduce(function(e,t){return e.push(t),e},t)},[])};var i=["mousedown","mouseup","click","dblclick","wheel","keydown","keypress","keyup","mousewheel"];return i.forEach(function(e){r[e]=function(t){this.fire(e,t)}}),i.push("mousemove"),i.push("mouseout"),r.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)},r.mouseout=function(e){this._active&&this.fire("mouseout",e),this._active=null},r.DOMMouseScroll=function(e){this.fire("mousewheel",e)},r.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)},r.on=function(e,t){var n=s(e),r=this._handlers;return r=r[n]||(r[n]=[]),r.push({type:e,handler:t}),this},r.off=function(e,t){var n=s(e),r=this._handlers[n];if(!r)return;for(var i=r.length;--i>=0;){if(r[i].type!==e)continue;(!t||r[i].handler===t)&&r.splice(i,1)}return this},r.context=function(){return this._canvas.getContext("2d")},r.pick=function(e,n,r,i,s){var o=this.context(),u=e.marktype,a=t.canvas.marks.pick[u];return a.call(this,o,e,n,r,i,s)},n}(),t.svg={},t.svg.marks=function(){function n(e){return e.x||0}function r(e){return e.y||0}function i(e){return e.y+e.height||0}function s(e){return e.key}function o(e){return e.size==null?100:e.size}function u(e){return e.shape||"circle"}function m(e){var n=e.mark?e:e[0],r,i,s,o,u;for(r=0,i=v.length;r<i;++r)s=v[r],o=d[s],u=n[s],u==null?o==="fill"?this.style.setProperty(o,"none",null):this.style.removeProperty(o):(u.id&&(t.svg._cur._defs[u.id]=u,u="url(#"+u.id+")"),this.style.setProperty(o,u,null))}function g(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",a(e))}function y(e){var t=e[0];f.interpolate(t.interpolate||"linear").tension(t.tension==undefined?.7:t.tension),this.setAttribute("d",f(e))}function b(e){var t=e[0];l.interpolate(t.interpolate||"linear").tension(t.tension==undefined?.7:t.tension),this.setAttribute("d",l(e))}function w(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",e.path)}function E(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 S(e){var t=e.x||0,n=e.y||0;this.setAttribute("x1",t),this.setAttribute("y1",n),this.setAttribute("x2",e.x2!==undefined?e.x2:t),this.setAttribute("y2",e.y2!==undefined?e.y2:n)}function x(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")"),this.setAttribute("d",c(e))}function T(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 N(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 C(e){var t=e.x||0,n=e.y||0,r=e.dx||0,i=e.dy||0,s=e.angle||0,o=p[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",N(e),null)}function k(e){var t=e.x||0,n=e.y||0;this.setAttribute("transform","translate("+t+","+n+")")}function L(e){var t=e.width||0,n=e.height||0;this.setAttribute("width",t),this.setAttribute("height",n)}function A(e,t,n){return function(r,i,s){O(r,i,s,"mark_",e,t,n)}}function O(t,n,r,i,s,o,u){var a=u?[n.items]:n.items,f=n.interactive===!1?"none":null,l=t.node().childNodes,c=s!=="g",p=(p=l[r+1])?e.select(p):t.append("g").attr("id","g"+ ++h),d="#"+p.attr("id"),v=d+" > "+s,g=p.selectAll(v).data(a),y=g.enter().append(s);return c?(p.style("pointer-events",f),y.each(function(e){(e.mark?e:e[0])._svg=this})):y.append("rect").attr("class","background").style("pointer-events",f),g.exit().remove(),g.each(o),c?g.each(m):p.selectAll(v+" > rect.background").each(L).each(m),p}function M(t,n,r,i){var s=O(t,n,r,i||"group_","g",k),o=s.node().childNodes,u=o.length,a,f,l;for(a=0;a<u;++a){var c=o[a].__data__.items,h=o[a].__data__.legendItems||[],p=o[a].__data__.axisItems||[],d=e.select(o[a]),v=0;for(f=0,l=p.length;f<l;++f)p[f].def.layer==="back"&&M.call(this,d,p[f],v++,"axis_");for(f=0,l=c.length;f<l;++f)this.draw(d,c[f],v++);for(f=0,l=p.length;f<l;++f)p[f].def.layer!=="back"&&M.call(this,d,p[f],v++,"axis_");for(f=0,l=h.length;f<l;++f)M.call(this,d,h[f],v++,"legend_")}}var a=e.svg.arc(),f=e.svg.area().x(n).y1(r).y0(i),l=e.svg.line().x(n).y(r),c=e.svg.symbol().type(u).size(o),h=0,p={left:"start",center:"middle",right:"end"},d={fill:"fill",fillOpacity:"fill-opacity",stroke:"stroke",strokeWidth:"stroke-width"
,strokeOpacity:"stroke-opacity",opacity:"opacity"},v=t.keys(d);return{update:{group:E,area:y,line:b,arc:g,path:w,symbol:x,rect:E,rule:S,text:C,image:T},nested:{area:!0,line:!0},style:m,draw:{group:M,area:A("path",y,!0),line:A("path",b,!0),arc:A("path",g),path:A("path",w),symbol:A("path",x),rect:A("rect",E),rule:A("line",S),text:A("text",C),image:A("image",T),draw:A}}}(),t.svg.Renderer=function(){var n=function(){this._svg=null,this._ctx=null,this._el=null,this._defs={}},r=n.prototype;return r.initialize=function(t,n,r,i){return this._el=t,this._width=n,this._height=r,this._padding=i,e.select(t).select("svg.marks").remove(),this._svg=e.select(t).append("svg").attr("class","marks").attr("width",n+i.left+i.right).attr("height",r+i.top+i.bottom),this._ctx=this._svg.append("g").attr("transform","translate("+i.left+","+i.top+")"),this},r.context=function(){return this._ctx},r.element=function(){return this._el},r.updateDefs=function(){var n=this._svg,r=this._defs,i=t.keys(r),s=n.select("defs"),o;if(i.length===0){s.remove();return}s.empty()&&(s=n.insert("defs",":first-child")),o=s.selectAll("linearGradient").data(i,t.identity),o.enter().append("linearGradient").attr("id",t.identity),o.exit().remove(),o.each(function(t){var n=r[t],i=e.select(this);i.attr({x1:n.x1,x2:n.x2,y1:n.y1,y2:n.y2}),stop=i.selectAll("stop").data(n.stops),stop.enter().append("stop"),stop.exit().remove(),stop.attr("offset",function(e){return e.offset}).attr("stop-color",function(e){return e.color})})},r.render=function(e,n){t.svg._cur=this,n?this.renderItems(t.array(n)):this.draw(this._ctx,e,-1),this.updateDefs(),delete t.svg._cur},r.renderItems=function(e){var n,r,i,s,o,u,a=t.svg.marks;for(o=0,u=e.length;o<u;++o)n=e[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)},r.draw=function(e,n,r){var i=n.marktype,s=t.svg.marks.draw[i];s.call(this,e,n,r)},n}(),t.svg.Handler=function(){function r(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 i(e){var t=e.indexOf(".");return t<0?e:e.slice(0,t)}var n=function(e,t){this._active=null,this._handlers={},e&&this.initialize(e),t&&this.model(t)},s=n.prototype;return s.initialize=function(t,n,r){return this._el=e.select(t).node(),this._svg=e.select(t).select("svg.marks").node(),this._padding=n,this._obj=r||null,this},s.model=function(e){return arguments.length?(this._model=e,this):this._model},s.handlers=function(){var e=this._handlers;return t.keys(e).reduce(function(t,n){return e[n].reduce(function(e,t){return e.push(t),e},t)},[])},s.on=function(t,n){var s=i(t),o=this._handlers,u=e.select(this._svg).node(),a={type:t,handler:n,svg:r.call(this,n)};return o=o[s]||(o[s]=[]),o.push(a),u.addEventListener(s,a.svg),this},s.off=function(t,n){var r=i(t),s=this._handlers[r],o=e.select(this._svg).node();if(!s)return;for(var u=s.length;--u>=0;){if(s[u].type!==t)continue;if(!n||s[u].handler===n)o.removeEventListener(r,s[u].svg),s.splice(u,1)}return this},n}(),t.data={},t.data.ingest=function(e,t){return{data:e,index:t}},t.data.mapper=function(e){return function(t){return t.forEach(e),t}},t.data.size=function(e,n){return e=t.isArray(e)?e:[0,e],e=e.map(function(e){return typeof e=="string"?n[e]:e}),e},t.data.load=function(e,n){if(t.config.isNode){var r=f(e)?e:t.config.baseURL+e,i=l(r)?h:p;i(r,n)}else c(e,n)};var u=/^[A-Za-z]+\:\/\//,a="file://";t.data.read=function(){function i(e,t){var r=t&&t.type||"json";return e=n[r](e,t),t&&t.parse&&s(e,t.parse),e}function s(e,n){var i=t.keys(n),s=i.map(function(e){return r[n[e]]}),o,u,a,f,l;for(u=0,f=e.length;u<f;++u){o=e[u];for(a=0,l=i.length;a<l;++a)o[i[a]]=s[a](o[i[a]])}}var n={},r={number:t.number,"boolean":t.boolean,date:Date.parse};return n.json=function(e,n){var r=JSON.parse(e);return n&&n.property&&(r=t.accessor(n.property)(r)),r},n.csv=function(t,n){var r=e.csv.parse(t);return r},n.tsv=function(t,n){var r=e.tsv.parse(t);return r},i.formats=n,i.parse=s,i}(),t.data.array=function(){function n(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 n.fields=function(r){return e=t.array(r).map(t.accessor),n},n},t.data.copy=function(){var e=t.accessor("data"),n=[],r=null,i=t.data.mapper(function(t){var i=e(t),s,o,u=n,a=r||n;for(s=0,o=n.length;s<o;++s)t[a[s]]=i[n[s]];return t});return i.from=function(n){return e=t.accessor(n),i},i.fields=function(e){return n=t.array(e),i},i.as=function(e){return r=t.array(e),i},i},t.data.facet=function(){function r(t){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:n?t.slice():t}),n&&o.values.sort(n),r;for(l=0,f=t.length;l<f;++l){for(h=0,u=[],a="";h<e.length;++h)p=e[h](t[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(t[l])}if(n)for(l=0,f=s.length;l<f;++l)s[l].values.sort(n);return r}var e=[],n=null;return r.keys=function(n){return e=t.array(n).map(t.accessor),r},r.sort=function(e){return n=t.comparator(e),r},r},t.data.filter=function(){function n(t){return e?t.filter(e):t}var e=null;return n.test=function(r){return e=t.isFunction(r)?r:t.parse.expr(r),n},n},t.data.fold=function(){function i(t){var i=[],s,o,u,a,f=e.length;for(o=0,a=t.length;o<a;++o){s=t[o];for(u=0;u<f;++u){var l={index:i.length,data:s.data};l[r.key]=e[u],l[r.value]=n[u](s),i.push(l)}}return i}var e=[],n=[],r={key:"key",value:"value"};return i.fields=function(r){return e=t.array(r),n=e.map(t.accessor),i},i.output=function(e){return t.keys(r).forEach(function(t){e[t]!==undefined&&(r[t]=e[t])}),i},i},t.data.force=function(){function l(e,i,s){n.size(t.data.size(a,s)).nodes(e),r&&i[r]&&n.links(i[r]),n.start();for(var o=0;o<u;++o)n.tick();return n.stop(),e}var n=e.layout.force(),r=null,i=20,s=1,o=-30,u=500,a=["width","height"],f=["friction","theta","gravity","alpha"];return l.links=function(e){return r=e,l},l.size=function(e){return a=e,l},l.linkDistance=function(e){return i=typeof e=="number"?e:t.accessor(e),n.linkDistance(i),l},l.linkStrength=function(e){return s=typeof e=="number"?e:t.accessor(e),n.linkStrength(s),l},l.charge=function(e){return o=typeof e=="number"?e:t.accessor(e),n.charge(o),l},l.iterations=function(e){return u=e,l},f.forEach(function(e){l[e]=function(t){return n[e](t),l}}),l},t.data.formula=function(){return function(){var e=null,n=t.identity,r=t.data.mapper(function(t){return e&&(t[e]=n.call(null,t)),t});return r.field=function(t){return e=t,r},r.expr=function(e){return n=t.isFunction(e)?e:t.parse.expr(e),r},r}}(),t.data.geo=function(){function r(){var r={},i="mercator",s=e.geo[i](),o=t.identity,u=t.identity,a={x:"x",y:"y"},f=t.data.mapper(function(e){var t=[u(e),o(e)],n=s(t);return e[a.x]=n[0],e[a.y]=n[1],e});return f.func=function(){return s},f.projection=function(t){if(i!==t){i=t,s=e.geo[i]();for(var n in r)s[n](r[n])}return f},n.forEach(function(e){f[e]=function(t){return r[e]=t,s[e](t),f}}),f.lon=function(e){return u=t.accessor(e),f},f.lat=function(e){return o=t.accessor(e),f},f.output=function(e){return t.keys(a).forEach(function(t){e[t]!==undefined&&(a[t]=e[t])}),e},f}var n=["center","scale","translate","rotate","precision","clipAngle"];return r.params=n,r}(),t.data.geopath=function(){var n=e.geo.path().projection(e.geo.mercator()),r="mercator",i=t.identity,s={},o={path:"path"},u=t.data.mapper(function(e){return e[o.path]=n(i(e)),e});return u.projection=function(t){if(r!==t){r=t;var i=e.geo[r]();for(var o in s)i[o](s[o]);n.projection(i)}return u},t.data.geo.params.forEach(function(e){u[e]=function(t){return s[e]=t,n.projection()[e](t),u}}),u.value=function(e){return i=t.accessor(e),u},u.output=function(e){return t.keys(o).forEach(function(t){e[t]!==undefined&&(o[t]=e[t])}),e},u},t.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(t){var n=l[e];return t.forEach(function(e){e[s.path]=n(e)}),t}var e="line",n=t.accessor("source"),r=t.accessor("target"),i=.2,s={path:"path"},l={line:o,curve:u,diagonal:a,diagonalX:a,diagonalY:f};return c.shape=function(t){return e=t,c},c.tension=function(e){return i=e,c},c.source=function(e){return n=t.accessor(e),c},c.target=function(e){return r=t.accessor(e),c},c.output=function(e){return t.keys(s).forEach(function(t){e[t]!==undefined&&(s[t]=e[t])}),c},c},t.data.pie=function(){function a(t){var n=t.map(function(e,t){return+r(e)}),a=i,f=(s-i)/e.sum(n),l=e.range(t.length);return o&&l.sort(function(e,t){return n[e]-n[t]}),l.forEach(function(e){var r;t[e].value=r=n[e],t[e][u.startAngle]=a,t[e][u.endAngle]=a+=r*f}),t}var n=function(){return 1},r=n,i=0,s=2*Math.PI,o=!1,u={startAngle:"startAngle",endAngle:"endAngle"};return a.sort=function(e){return o=e,a},a.value=function(e){return r=e?t.accessor(e):n,a},a.startAngle=function(e){return i=Math.PI*e/180,a},a.endAngle=function(e){return s=Math.PI*e/180,a},a.output=function(e){return t.keys(u).forEach(function(t){e[t]!==undefined&&(u[t]=e[t])}),a},a},t.data.slice=function(){function r(r){r=t.values(r);if(e==="min")r=[r[t.minIndex(r,n)]];else if(e==="max")r=[r[t.maxIndex(r,n)]];else if(e==="median"){var i=r.slice().sort(function(e,t){return e=n(e),t=n(t),e<t?-1:e>t?1:0});r=[r[~~(i.length/2)]]}else{var s=t.array(e);r=r.slice(s[0],s[1])}return r}var e=null,n=t.accessor("data");return r.by=function(t){return e=t,r},r.field=function(e){return n=t.accessor(e),r},r},t.data.sort=function(){function n(n){n=t.isArray(n)?n:n.values||[],n.sort(e);for(var r=0,i=n.length;r<i;++r)n[r].index=r;return n}var e=null;return n.by=function(r){return e=t.comparator(r),n},n},t.data.stack=function(){function u(e){var t=o.y0,r=o.y1,i=o.cy;return n.out(function(e,n,s){e.datum&&(e.datum[t]=n,e.datum[r]=s+n,e.datum[i]=n+s/2)})(a(e)),e}function a(e){var n=t.values(e),s=[],o=[],u,a,f,l,c,h,p,d,v;for(a=0,f=n.length;a<f;++a){u=t.values(n[a]);for(l=0,c=u.length;l<c;++l)s.push({x:r(u[l]),y:i(u[l]),z:a,datum:u[l]});o.push([])}s.sort(function(e,t){return e.x<t.x?-1:e.x>t.x?1:e.z<t.z?-1:e.z>t.z?1:0});for(v=s[0].x,a=0,l=0,h=0,f=s.length;h<f;++h){p=s[h];if(p.x!==v){while(a<o.length)o[a++].push({x:l,y:0});v=p.x,a=0,l+=1}while(p.z>a)o[a++].push({x:l,y:0});p.x=l,o[a++].push(p)}while(a<o.length)o[a++].push({x:l,y:0});return o}var n=e.layout.stack(),r=t.accessor("index"),i=t.accessor("data"),s=["offset","order"],o={y0:"y2",y1:"y",cy:"cy"};return u.point=function(e){return r=t.accessor(e),u},u.height=function(e){return i=t.accessor(e),u},s.forEach(function(e){u[e]=function(t){return n[e](t),u}}),u.output=function(t){return e.keys(o).forEach(function(e){t[e]!==undefined&&(o[e]=t[e])}),u},u},t.data.stats=function(){function i(i){var s=+Infinity,o=-Infinity,u=0,a=0,f=0,l,c,h,p,d=(t.isArray(i)?i:i.values||[]).map(e);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=t.isArray(i)?{}:i;return n&&(d.sort(t.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(t.isArray(e)?[e]:e.values||[]).map(i)}var e=t.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 e=t.accessor(n),s},s.output=function(e){return t.keys(r).forEach(function(t){e[t]!==undefined&&(r[t]=e[t])}),s},s},t.data.treemap=function(){function u(e,s,u){e=n.size(t.data.size(i,u)).value(r).nodes(e);var a=t.keys(o),f=a.length;return e.forEach(function(e){var t,n;for(var r=0;r<f;++r)t=a[r],t!==o[t]&&(n=e[t],delete e[t],e[o[t]]=n)}),e}var n=e.layout.treemap().children(function(e){return e.values}),r=t.accessor("data"),i=["width","height"],s=["round","sticky","ratio","padding"],o={x:"x",y:"y",dx:"width",dy:"height"};return u.size=function(e){return i=e,u},u.value=function(e){return r=t.accessor(e),u},s.forEach(function(e){u[e]=function(t){return n[e](t),u}}),u.output=function(e){return t.keys(o).forEach(function(t){e[t]!==undefined&&(o[t]=e[t])}),u},u},t.data.truncate=function(){var e=t.accessor("data"),n="truncate",r="right",i="...",s=!0,o=100,u=t.data.mapper(function(u){var a=t.truncate(e(u),o,r,s,i);return u[n]=a,u});return u.value=function(n){return e=t.accessor(n),u},u.as=function(e){return n=e,u},u.limit=function(e){return o=+e,u},u.position=function(e){return r=e,u},u.ellipsis=function(e){return i=e+"",u},u.wordBreak=function(e){return s=!!e,u},u},t.data.unique=function(){function r(r){return t.unique(r,e).map(function(e){var t={};return t[n]=e,t})}var e=null,n="field";return r.field=function(n){return e=t.accessor(n),r},r.as=function(e){return n=e,r},r},t.data.wordcloud=function(){function f(e,u,f){function l(r,i){var o=n.size(),u=o[0]/2,f=o[1]/2,l=t.keys(a),c,h,p,d,v,m=l.length;e.sort(function(e,t){return s(t)-s(e)});for(p=0,d=r.length;p<d;++p){h=e[p];for(v=0;v<m;++v)c=l[v],h[a[c]]=r[p][c],c==="x"&&(h[a.x]+=u),c==="y"&&(h[a.y]+=f)}}return n.size(t.data.size(i,f)).text(r).fontSize(s).rotate(o).words(e).on("end",l).start(),e}var n=e.layout.cloud().size([900,500]),r=t.accessor("data"),i=["width","height"],s=function(){return 14},o=function(){return 0},u=["font","fontStyle","fontWeight","padding"],a={x:"x",y:"y",size:"fontSize",font:"font",rotate:"angle"};return f.text=function(e){return r=t.accessor(e),f},f.size=function(e){return i=e,f},f.fontSize=function(e){return s=t.accessor(e),f},f.rotate=function(e){var n;return t.isObject(e)&&!Array.isArray(e)?e.random!==undefined?(n=(n=e.random)?t.array(n):[0],o=function(){return n[~~(Math.random()*n.length-1e-5)]}):e.alternate!==undefined&&(n=(n=e.alternate)?t.array(n):[0],o=function(e,t){return n[t%n.length]}):o=t.accessor(field),f},u.forEach(function(e){f[e]=function(t){return n[e](t),f}}),f.output=function(e){return t.keys(a).forEach(function(t){e[t]!==undefined&&(a[t]=e[t])}),f},f},t.data.zip=function(){function o(t,o){var u=o[e],a=u.length,f,l,c,h,p;s&&(p={},u.forEach(function(e){p[s(e)]=e}));for(c=0,h=t.length;c<h;++c)l=t[c],l[n]=p?(f=p[r(l)])!=null?f:i:u[c%a];return t}var e=null,n="zip",r=t.accessor("data"),i=undefined,s=null;return o["with"]=function(t){return e=t,o},o["default"]=function(e){return i=e,o},o.as=function(e){return n=e,o},o.key=function(e){return r=t.accessor(e),o},o.withKey=function(e){return s=t.accessor(e),o},o},t.parse={},t.parse.axes=function(){function r(e,n,r){(e||[]).forEach(function(e,s){n[s]=n[s]||t.scene.axis(),i(e,s,n[s],r)})}function i(r,i,s,o){r.scale!==undefined&&s.scale(o[r.scale]),s.orient(r.orient||n[r.type]),s.offset(r.offset||0),s.layer(r.layer||"front"),s.grid(r.grid||!1),s.title(r.title||null),s.titleOffset(r.titleOffset!=null?r.titleOffset:t.config.axis.titleOffset),s.tickValues(r.values||null),s.tickFormat(r.format?e.format(r.format):null),s.tickSubdivide(r.subdivide||0),s.tickPadding(r.tickPadding||t.config.axis.padding);var u=[];if(r.tickSize!==undefined)for(var a=0;a<3;++a)u.push(r.tickSize);else{var f=t.config.axis.tickSize;u=[f,f,f]}r.tickSizeMajor!=null&&(u[0]=r.tickSizeMajor),r.tickSizeMinor!=null&&(u[1]=r.tickSizeMinor),r.tickSizeEnd!=null&&(u[2]=r.tickSizeEnd),u.length&&s.tickSize.apply(s,u);if(r.ticks!=null){var l=t.isArray(r.ticks)?r.ticks:[r.ticks];s.ticks.apply(s,l)}else s.ticks(t.config.axis.ticks);var c=r.properties;c&&c.ticks?(s.majorTickProperties(c.majorTicks?t.extend({},c.ticks,c.majorTicks):c.ticks),s.minorTickProperties(c.minorTicks?t.extend({},c.ticks,c.minorTicks):c.ticks)):(s.majorTickProperties(c&&c.majorTicks||{}),s.minorTickProperties(c&&c.minorTicks||{})),s.tickLabelProperties(c&&c.labels||{}),s.titleProperties(c&&c.title||{}),s.gridLineProperties(c&&c.grid||{}),s.domainProperties(c&&c.axis||{})}var n={x:"bottom",y:"left",top:"top",bottom:"bottom",left:"left",right:"right"};return r}(),t.parse.data=function(e,n){function s(e){return function(s,o){s?t.error("LOADING FAILED: "+e.url):r.load[e.name]=t.data.read(o.toString(),e.format),--i===0&&n()}}var r={defs:e,load:{},flow:{},source:{}},i=0;return(e||[]).forEach(function(e){e.url&&(i+=1,t.data.load(e.url,s(e))),e.values&&(e.format&&e.format.parse&&t.data.read.parse(e.values,e.format.parse),r.load[e.name]=e.values);if(e.source){var n=r.source[e.source]||(r.source[e.source]=[]);n.push(e.name)}e.transform&&(r.flow[e.name]=t.parse.dataflow(e))}),i===0&&setTimeout(n,1),r},t.parse.dataflow=function(e){var n=(e.transform||[]).map(t.parse.transform);return n.length?function(e,t,r){return n.reduce(function(e,n){return n(e,t,r)},e)}:t.identity},t.parse.expr=function(){var e={E:"Math.E",LN2:"Math.LN2",LN10:"Math.LN10",LOG2E:"Math.LOG2E",LOG10E:"Math.LOG10E",PI:"Math.PI",SQRT1_2:"Math.SQRT1_2",SQRT2:"Math.SQRT2"},t={abs:"Math.abs",acos:"Math.acos",asin:"Math.asin",atan:"Math.atan",atan2:"Math.atan2",ceil:"Math.ceil",cos:"Math.cos",exp:"Math.exp",floor:"Math.floor",log:"Math.log",max:"Math.max",min:"Math.min",pow:"Math.pow",random:"Math.random",round:"Math.round",sin:"Math.sin",sqrt:"Math.sqrt",tan:"Math.tan"},n=/([\"\']|[\=\<\>\~\&\|\?\:\+\-\/\*\%\!\^\,\;\[\]\{\}\(\) ]+)/;return function(r){var i=r.split(n),s,o,u,a,f,l;for(f=0,l=0,u=0,a=i.length;u<a;++u){var s=i[u];if(s==="'"){l||(f=!f);continue}if(s==='"'){f||(l=!l);continue}if(l||f)continue;e[s]&&(i[u]=e[s]),t[s]&&(o=i[u+1])&&o[0]==="("&&(i[u]=t[s])}return Function("d","return ("+i.join("")+");")}}(),t.parse.legends=function(){function n(e,n,i){(e||[]).forEach(function(e,s){n[s]=n[s]||t.scene.legend(),r(e,s,n[s],i)})}function r(t,n,r,i){r.size(t.size?i[t.size]:null),r.shape(t.shape?i[t.shape]:null),r.fill(t.fill?i[t.fill]:null),r.stroke(t.stroke?i[t.stroke]:null),t.orient&&r.orient(t.orient),t.offset!=null&&r.offset(t.offset),r.title(t.title||null),r.values(t.values||null),r.format(t.format!==undefined?e.format(t.format):null);var s=t.properties;r.titleProperties(s&&s.title||{}),r.labelProperties(s&&s.labels||{}),r.legendProperties(s&&s.legend||{}),r.symbolProperties(s&&s.symbols||{}),r.gradientProperties(s&&s.gradient||{})}return n}(),t.parse.mark=function(e){var n=e.properties,r=e.marks;t.keys(n).forEach(function(e){n[e]=t.parse.properties(n[e])}),e.delay&&(e.delay=t.parse.properties({delay:e.delay}));if(e.from){var i=e.from.data,s=t.parse.dataflow(e.from);e.from=function(e,n,r){var o=t.scene.data(i?e[i]:null,r);return s(o,e,n)}}return r&&(e.marks=r.map(t.parse.mark)),e},t.parse.marks=function(e,n,r){return{type:"group",width:n,height:r,scales:e.scales||[],axes:e.axes||[],legends:e.legends||[],marks:(e.marks||[]).map(t.parse.mark)}},t.parse.padding=function(e){if(t.isObject(e))return e;var n=t.isNumber(e)?e:20;return{top:n,left:n,right:n,bottom:n}},t.parse.properties=function(){function e(e){var r="",i=t.keys(e),s,o,u,a,f={};r+="var o = trans ? {} : item;\n";for(s=0,o=i.length;s<o;++s)a=e[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(e){if(e==null)return null;if(e.c)return r("hcl",e.h,e.c,e.l);if(e.h||e.s)return r("hsl",e.h,e.s,e.l);if(e.l||e.a)return r("lab",e.l,e.a,e.b);if(e.r||e.g||e.b)return r("rgb",e.r,e.g,e.b);var n=e.value!==undefined?t.str(e.value):"item.datum.data";e.group!==undefined&&(n="group."+e.group),e.field!==undefined&&(n="item.datum["+t.field(e.field).map(t.str).join("][")+"]");if(e.scale!==undefined){var i="group.scales['"+e.scale+"']";e.band?n=i+".rangeBand()":n=i+"("+n+")"}return"("+(e.mult?e.mult+" * ":"")+n+")"+(e.offset?" + "+e.offset:"")}function r(e,r,i,s){var o=r?n(r):t.config.color[e][0],u=i?n(i):t.config.color[e][1],a=s?n(s):t.config.color[e][2];return"(d3."+e+"("+[o,u,a].join(",")+') + "")'}return e}(),t.parse.scales=function(){function f(e,t,n,r){return(e||[]).reduce(function(e,t){var i=t.name,s=i+":prev";return e[i]=l(t,e[i],n,r),e[s]=e[s]||e[i],e},t||{})}function l(e,n,i,s){var o=c(e,n),u=o.type===r?h:p,a=d(e,s),f=t.values(s.datum);return u(e,o,a,i,f),o}function c(r,i){var s=r.type||n;if(!i||s!==i.type){var o=a[s]||e.scale[s];o||t.error("Unrecognized scale type: "+s),(i=o()).type=s,i.scaleName=r.name}return i}function h(e,n,r,i,s){var o,u,a,f;o=e.domain,t.isArray(o)?n.domain(o):t.isObject(o)&&(u=e.domain.fields||t.array(e.domain),a=u.reduce(function(e,n){var r=i[n.data]||s,o=t.accessor(n.field);return t.unique(r,o,e)},[]),e.sort&&a.sort(t.cmp),n.domain(a)),f=typeof r[0]=="string",f||r.length>2?n.range(r):e.points?n.rangePoints(r,e.padding||0):e.round||e.round===undefined?n.rangeRoundBands(r,e.padding||0):n.rangeBands(r,e.padding||0)}function p(n,r,u,a,f){function p(n,r,i){var s=a[n.data]||f;t.array(n.field).forEach(function(n,o){n=t.accessor(n),r&&(l[0]=e.min([l[0],e.min(s,n)])),i&&(l[1]=e.max([l[1],e.max(s,n)]))})}var l,c,h;l=[null,null],n.domain!==undefined&&(t.isArray(n.domain)?l=n.domain.slice():t.isObject(n.domain)?(c=n.domain.fields||t.array(n.domain),c.forEach(function(e){p(e,1,1)})):l=n.domain),n.domainMin!==undefined&&(t.isObject(n.domainMin)?(l[0]=null,c=n.domainMin.fields||t.array(n.domainMin),c.forEach(function(e){p(e,1,0)})):l[0]=n.domainMin),n.domainMax!==undefined&&(t.isObject(n.domainMax)?(l[1]=null,c=n.domainMax.fields||t.array(n.domainMax),c.forEach(function(e){p(e,0,1)})):l[1]=n.domainMax),n.type!==i&&n.type!==o&&(n.zero||n.zero===undefined)&&(l[0]=Math.min(0,l[0]),l[1]=Math.max(0,l[1])),r.domain(l),n.range==="height"&&(u=u.reverse()),r[n.round&&r.rangeRound?"rangeRound":"range"](u),n.exponent&&n.type===s&&r.exponent(n.exponent),n.clamp&&r.clamp(!0),n.nice&&(n.type===o?(h=e.time[n.nice],h||t.error("Unrecognized interval: "+h),r.nice(h)):r.nice())}function d(e,n){var r=[null,null];if(e.range!==undefined)if(typeof e.range=="string")if(u[e.range])r=[0,n[e.range]];else{if(!t.config.range[e.range])return t.error("Unrecogized range: "+e.range),r;r=t.config.range[e.range]}else t.isArray(e.range)?r=e.range:r=[0,e.range];e.rangeMin!==undefined&&(r[0]=e.rangeMin),e.rangeMax!==undefined&&(r[1]=e.rangeMax);if(e.reverse!==undefined){var i=e.reverse;t.isObject(i)&&(i=t.accessor(i.field)(n.datum)),i&&(r=r.reverse())}return r}var n="linear",r="ordinal",i="log",s="pow",o="time",u={width:1,height:1},a={time:e.time.scale,utc:e.time.scale.utc};return f}(),t.parse.spec=function(n,r,i){function s(e){e=t.duplicate(e);var n=e.width||500,s=e.height||500,o=e.viewport||null,u={width:n,height:s,viewport:o,padding:t.parse.padding(e.padding),marks:t.parse.marks(e,n,s),data:t.parse.data(e.data,function(){r(a)})},a=i(u)}i=i||t.ViewFactory,t.isObject(n)?s(n):e.json(n,function(e,n){e?t.error(e):s(n)})},t.parse.transform=function(e){var n=t.data[e.type]();return t.keys(e).forEach(function(t){if(t==="type")return;n[t](e[t])}),n},t.scene={},t.scene.GROUP="group",t.scene.ENTER=0,t.scene.UPDATE=1,t.scene.EXIT=2,t.scene.DEFAULT_DATA={sentinel:1},t.scene.data=function(e,n){var r=t.scene.DEFAULT_DATA;return e=t.values(e||n||[r]),e===r&&(e=[r]),e},t.scene.Item=function(){function e(e){this.mark=e}var t=e.prototype;return t.hasPropertySet=function(e){var t=this.mark.def.properties;return t&&t[e]!=null},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}(),t.scene.item=function(e){return new t.scene.Item(e)},t.scene.build=function(){function u(e,r,i,s){var o=t.scene.data(e.from?e.from(r,i,s):null,s);return i=a(e,i),i.items=f(e,o,i),c(e,i),e.type===n&&l(e,r,i),i}function a(e,t){return t=t||{},t.def=e,t.marktype=e.type,t.interactive=e.interactive!==!1,t}function f(e,n,o){var u=h(e.key),a=o.items||[],f=[],l={},c,p,d,v,m,g;for(c=0,d=a.length;c<d;++c)v=a[c],v.status=s,u&&(l[v.key]=v);for(c=0,d=n.length;c<d;++c)m=n[c],p=c,v=u?l[p=u(m)]:a[c],g=v?!1:(v=t.scene.item(o),!0),v.status=g?r:i,v.datum=m,v.key=p,f.push(v);for(c=0,d=a.length;c<d;++c)v=a[c],v.status===s&&(v.key=u?v.key:f.length,f.push(v));return f}function l(e,t,n){var r=n.items,i=e.marks,s,o,a,f,l,c;for(s=0,o=r.length;s<o;++s){c=r[s];if(c.scales)for(l in c.scales)l.indexOf(":prev")<0&&(c.scales[l+":prev"]=c.scales[l].copy());c.items=c.items||[];for(a=0,f=i.length;a<f;++a)c.items[a]=u(i[a],t,c.items[a],c.datum),c.items[a].group=c}}function c(t,n){t.duration&&(n.duration=t.duration),t.ease&&(n.ease=e.ease(t.ease));if(t.delay){var r=n.items,i=n.group,s=r.length,o;for(o=0;o<s;++o)t.delay.call(this,r[o],i)}}function h(e){if(e==null)return null;var n=t.array(e).map(t.accessor);return function(e){for(var t="",r=0,i=n.length;r<i;++r)r>0&&(t+="|"),t+=String(n[r](e));return t}}var n=t.scene.GROUP,r=t.scene.ENTER,i=t.scene.UPDATE,s=t.scene.EXIT,o={sentinel:1};return u}(),t.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(e,n,r,i,s){s=t.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(t,n,r,i,s){f.call(this,t,n.items,r,i,s),n.marktype===e&&a.call(this,n,r,t,i,s)}function a(e,n,r,i,s){var o,a,f,l,c,h,p,d,v,m,g,y;for(o=0,a=e.items.length;o<a;++o){c=e.items[o],h=c.scales||(c.scales=t.extend({},r.scales)),n.scales&&t.parse.scales(n.scales,h,this._data,c),n.axes&&(p=c.axes||(c.axes=[]),d=c.axisItems||(c.axisItems=[]),t.parse.axes(n.axes,p,c.scales),p.forEach(function(e,n){v=e.def(),d[n]=t.scene.build(v,this._data,d[n]),u.call(this,c,c.axisItems[n],v,i)}));for(f=0,l=c.items.length;f<l;++f)u.call(this,c,c.items[f],n.marks[f],i,s);n.legends&&(m=c.legends||(c.legends=[]),g=c.legendItems||(c.legendItems=[]),t.parse.legends(n.legends,m,c.scales),m.forEach(function(e,n){y=e.def(),g[n]=t.scene.build(y,this._data,g[n]),u.call(this,c,c.legendItems[n],y,i)}))}}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 e=t.scene.GROUP,n=t.scene.ENTER,r=t.scene.UPDATE,i=t.scene.EXIT;return s}(),t.scene.Transition=function(){function n(t,n){this.duration=t||500,this.ease=n&&e.ease(n)||e.ease("cubic-in-out"),this.updates={next:null}}function i(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 r=n.prototype;return r.interpolate=function(t,n){var r,i,s,o,u=null;for(r in n)i=t[r],s=n[r],i!==s&&(o=e.interpolate(i,s),o.property=r,(u||(u=[])).push(o));return o&&(u.item=t,u.ease=t.mark.ease||this.ease,u.next=this.updates.next,this.updates.next=u),this},r.start=function(n){var r=this,s=r.updates,o=s.next;for(;o!=null;s=o,o=s.next)o.item.status===t.scene.EXIT&&(o.remove=!0);r.callback=n,e.timer(function(e){return i.call(r,e)})},n}(),t.scene.transition=function(e,n){return new t.scene.Transition(e,n)},t.scene.axis=function(){function B(e){var r,s,o;e.type==="ordinal"?(r={scale:e.scaleName,offset:.5+e.rangeBand()/2},s=r):(r={scale:e.scaleName,offset:.5},s={scale:e.scaleName+":prev",offset:.5}),o=g(e);var u=k(),a=k(),p=k(),d=L(),v=O(),m=A();u.properties.enter.stroke={value:t.config.axis.gridColor},S(n,u,s,r,Infinity),S(n,a,s,r,f),S(n,p,s,r,l),E(n,d,s,r,f,h),N(n,v,o,c),T(n,m,o,i),t.extend(u.properties.update,w),t.extend(a.properties.update,M),t.extend(p.properties.update,_),t.extend(d.properties.update,x),t.extend(v.properties.update,P),t.extend(m.properties.update,D);var y=[u,a,p,d,v,m];return{type:"group",interactive:!1,properties:{update:C},marks:y.map(t.parse.mark)}}var e,n=t.config.axis.orient,r=0,i=t.config.axis.titleOffset,s=null,o="front",u=!1,a=null,f=t.config.axis.tickSize,l=t.config.axis.tickSize,c=t.config.axis.tickSize,h=t.config.axis.padding,p=null,m=null,y=0,b=[t.config.axis.ticks],w={},x={},M={},_={},D={},P={},H={};return H.def=function(){var i=s=B(e),f=p==null?e.ticks?e.ticks.apply(e,b):e.domain():p,l=v(e,f,y).map(t.data.ingest);f=f.map(t.data.ingest);var c=m==null?e.tickFormat?e.tickFormat.apply(e,b):String:m;f.forEach(function(e){e.label=c(e.data)});var h=a?[a].map(t.data.ingest):[];return i.marks[0].from=function(){return u?f:[]},i.marks[1].from=function(){return f},i.marks[2].from=function(){return l},i.marks[3].from=i.marks[1].from,i.marks[4].from=function(){return[1]},i.marks[5].from=function(){return h},i.offset=r,i.orient=n,i.layer=o,i},H.scale=function(t){return arguments.length?(e=t,H):e},H.orient=function(e){return arguments.length?(n=e in d?e+"":t.config.axis.orient,H):n},H.title=function(e){return arguments.length?(a=e,H):a},H.ticks=function(){return arguments.length?(b=arguments,H):b},H.tickValues=function(e){return arguments.length?(p=e,H):p},H.tickFormat=function(e){return arguments.length?(m=e,H):m},H.tickSize=function(e,t){if(!arguments.length)return f;var n=arguments.length-1;return f=+e,l=n>1?+t:f,c=n>0?+arguments[n]:f,H},H.tickPadding=function(e){return arguments.length?(h=+e,H):h},H.tickSubdivide=function(e){return arguments.length?(y=+e,H):y},H.offset=function(e){return arguments.length?(r=+e,H):p},H.titleOffset=function(e){return arguments.length?(i=+e,H):i},H.layer=function(e){return arguments.length?(o=e,H):o},H.grid=function(e){return arguments.length?(u=e,H):u},H.gridLineProperties=function(e){return arguments.length?(w=e,H):w},H.majorTickProperties=function(e){return arguments.length?(M=e,H):M},H.minorTickProperties=function(e){return arguments.length?(_=e,H):_},H.tickLabelProperties=function(e){return arguments.length?(x=e,H):x},H.titleProperties=function(e){return arguments.length?(D=e,H):D},H.domainProperties=function(e){return arguments.length?(P=e,H):P},H};var d={top:1,right:1,bottom:1,left:1},b={bottom:"center",top:"center",left:"right",right:"left"},w={bottom:"top",top:"bottom",left:"middle",right:"middle"};t.scene.legend=function(){function E(e){return e==="ordinal"||e==="quantize"||e==="quantile"||e==="threshold"}function S(l){var c=x(n,r,i,s),p=(u==null?l.ticks?l.ticks.apply(l,d):l.domain():u).map(t.data.ingest),v=a==null?l.tickFormat?l.tickFormat.apply(l,d):String:a,m,g,w,E=5,S=e.range(p.length);n?(g=p.map(function(e){return Math.sqrt(n(e.data))}),w=e.max(g),g=g.reduce(function(e,t,n,r){return n>0&&(e[n]=e[n-1]+r[n-1]/2+E),e[n]+=t/2,e},[0]).map(Math.round)):(w=Math.round(Math.sqrt(t.config.legend.symbolSize)),g=o||(m=b.fontSize)&&m.value+E||t.config.legend.labelFontSize+E,g=S.map(function(e,t){return Math.round(w/2+t*g)}));var T=h,N;f&&(N=y.fontSize,T+=5+(N&&N.value||t.config.legend.titleFontSize));for(var C=0,k=g.length;C<k;++C)g[C]+=T;var l={name:"legend",type:"ordinal",domain:S,range:g},L=(f?[f]:[]).map(t.data.ingest);return p.forEach(function(e){e.label=v(e.data),e.offset=w}),c.scales=[l],c.marks[0].from=function(){return L},c.marks[1].from=function(){return p},c.marks[2].from=c.marks[1].from,c}function x(e,n,r,i){var s=P(),o=H(),u=B();return D(o,e,n,r,i),t.extend(s.properties.update,y),t.extend(o.properties.update,m),t.extend(u.properties.update,b),s.properties.enter.x.value+=h,s.properties.enter.y.value+=h,u.properties.enter.x.offset+=h+1,o.properties.enter.x.offset=h+1,{type:"group",interactive:!1,properties:{enter:t.parse.properties(v),update:_},marks:[s,o,u].map(t.parse.mark)}}function T(e){var n=N(e),r=e.domain(),i=r.map(t.data.ingest),s=g.width&&g.width.value||t.config.legend.gradientWidth,o=a==null?e.tickFormat?e.tickFormat.apply(e,d):String:a,u={name:"legend",type:e.type,round:!0,zero:!1,domain:[r[0],r[r.length-1]],range:[h,s+h]};e.type==="pow"&&(u.exponent=e.exponent());var l=(f?[f]:[]).map(t.data.ingest);return i.forEach(function(e,t){e.label=o(e.data),e.align=t==i.length-1?"right":t==0?"left":"center"}),n.scales=[u],n.marks[0].from=function(){return l},n.marks[1].from=function(){return[1]},n.marks[2].from=function(){return i},n}function N(e){var n=P(),r=j(),i=F(),s=new t.Gradient
,o=e.domain(),u=o[0],a=o[o.length-1],l=e.copy().domain([u,a]).range([0,1]),c=e.type!=="linear"&&e.ticks?e.ticks.call(e,15):o;u!==c[0]&&c.unshift(u),a!==c[c.length-1]&&c.push(a);for(var p=0,d=c.length;p<d;++p)s.stop(l(c[p]),e(c[p]));r.properties.enter.fill={value:s},t.extend(n.properties.update,y),t.extend(r.properties.update,g),t.extend(i.properties.update,b);var m=r.properties,w=g.height,E=w&&w.value||m.enter.height.value;i.properties.enter.y.value=E;if(f){var S=n.properties,x=y.fontSize,T=4+(x&&x.value||S.enter.fontSize.value);r.properties.enter.y.value+=T,i.properties.enter.y.value+=T}return n.properties.enter.x.value+=h,n.properties.enter.y.value+=h,r.properties.enter.x.value+=h,r.properties.enter.y.value+=h,i.properties.enter.y.value+=h,{type:"group",interactive:!1,properties:{enter:t.parse.properties(v),update:_},marks:[n,r,i].map(t.parse.mark)}}var n=null,r=null,i=null,s=null,o=null,u=null,a=null,f=undefined,l="right",c=t.config.legend.offset,h=t.config.legend.padding,p,d=[5],v={},m={},g={},y={},b={},w={},p=null;return w.def=function(){var e=n||r||i||s;return p=e!==i&&e!==s||!!E(e.type)?S(e):T(e),p.orient=l,p.offset=c,p},w.size=function(e){return arguments.length?(n=e,w):n},w.shape=function(e){return arguments.length?(r=e,w):r},w.fill=function(e){return arguments.length?(i=e,w):i},w.stroke=function(e){return arguments.length?(s=e,w):s},w.title=function(e){return arguments.length?(f=e,w):f},w.format=function(e){return arguments.length?(a=e,w):a},w.spacing=function(e){return arguments.length?(o=+e,w):o},w.orient=function(e){return arguments.length?(l=e in M?e+"":t.config.legend.orient,w):l},w.offset=function(e){return arguments.length?(c=+e,w):c},w.values=function(e){return arguments.length?(u=e,w):u},w.legendProperties=function(e){return arguments.length?(v=e,w):v},w.symbolProperties=function(e){return arguments.length?(m=e,w):m},w.gradientProperties=function(e){return arguments.length?(g=e,w):g},w.labelProperties=function(e){return arguments.length?(b=e,w):b},w.titleProperties=function(e){return arguments.length?(y=e,w):y},w};var M={right:1,left:1};return t.Model=function(){function e(){this._defs=null,this._data={},this._scene=null}var n=e.prototype;return n.defs=function(e){return arguments.length?(this._defs=e,this):this._defs},n.data=function(e){if(!arguments.length)return this._data;var n=this._defs.data.flow||{},r=this._defs.data.defs.map(t.accessor("name")),i,s,o,u,a;for(i=0,o=r.length;i<o;++i){if(!e[u=r[i]])continue;this._data[u]=n[u]?n[u](e[u],this._data,this._defs.marks):e[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.width=e),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.height=e),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 e=this,n=e._data,r=e._defs.marks;return e._scene=t.scene.build.call(e,r,n,e._scene),e._scene.items[0].width=r.width,e._scene.items[0].height=r.height,e._scene.interactive=!1,this},n.encode=function(e,n,r){var i=this,s=i._scene,o=i._defs;return t.scene.encode.call(i,s,o.marks,e,n,r),this},e}(),t.View=function(){var n=function(e,n,r){this._el=null,this._build=!1,this._model=new t.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=t.canvas,e&&this.initialize(e)},r=n.prototype;return r.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},r.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},r.padding=function(e){return arguments.length?(this._padding!==e&&(this._padding=e,this._el&&this.initialize(this._el.parentNode)),this):this._padding},r.viewport=function(e){return arguments.length?(this._viewport!==e&&(this._viewport=e,this._el&&this.initialize(this._el.parentNode)),this):this._viewport},r.renderer=function(e){return arguments.length?(e==="canvas"&&(e=t.canvas),e==="svg"&&(e=t.svg),this._io!==e&&(this._io=e,this._renderer=null,this._el&&this.initialize(this._el.parentNode),this._build&&this.render()),this):this._io},r.defs=function(e){return arguments.length?(this._model.defs(e),this):this._model.defs()},r.data=function(e){if(!arguments.length)return this._model.data();var n=t.keys(e).reduce(function(n,r){return n[r]=e[r].map(t.data.ingest),n},{});return this._model.data(n),this._build=!1,this},r.model=function(e){return arguments.length?(this._model!==e&&(this._model=e,this._handler&&this._handler.model(e)),this):this._model},r.initialize=function(t){var n=this,r,i=n._width,s=n._height,o=n._padding;return e.select(t).select("div.vega").remove(),this._el=t=e.select(t).append("div").attr("class","vega").style("position","relative").node(),n._viewport&&e.select(t).style("width",(n._viewport[0]||i)+"px").style("height",(n._viewport[1]||s)+"px").style("overflow","auto"),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},r.render=function(e){return this._renderer.render(this._model.scene(),e),this},r.on=function(){return this._handler.on.apply(this._handler,arguments),this},r.off=function(){return this._handler.off.apply(this._handler,arguments),this},r.update=function(e){e=e||{};var n=this,r=e.duration?t.scene.transition(e.duration,e.ease):null;return n._build=n._build||(n._model.build(),!0),n._model.encode(r,e.props,e.items),r?r.start(function(e){n._renderer.render(n._model.scene(),e)}):n.render(e.items),n},n}(),t.ViewFactory=function(e){return function(n){n=n||{};var r=(new t.View).width(e.width).height(e.height).padding(e.padding).viewport(e.viewport).renderer(n.renderer||"canvas").defs(e);return e.data.load&&r.data(e.data.load),n.data&&r.data(n.data),n.el&&r.initialize(n.el),n.hover!==!1&&r.on("mouseover",function(e,t){t.hasPropertySet("hover")&&this.update({props:"hover",items:t})}).on("mouseout",function(e,t){t.hasPropertySet("hover")&&this.update({props:"update",items:t})}),r}},t.Spec=function(){var e=function(e){this.spec={width:500,height:500,padding:0,data:[],scales:[],axes:[],marks:[]},e&&t.extend(this.spec,e)},n=e.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(e,n){return n?n.name=e:n=t.isString(e)?{name:e}:e,this.spec.data.push(n),this},n.scale=function(e,n){return n?n.name=e:n=t.isString(e)?{name:e}:e,this.spec.scales.push(n),this},n.axis=function(e){return this.spec.axes.push(e),this},n.mark=function(e,n){n?n.type=e:n={type:e},n.properties={},this.spec.marks.push(n);var r=this;return{from:function(e,r){return n.from=r?(r.data=e,r):t.isString(e)?{data:e}:e,this},prop:function(e,r){return n.properties[e]=t.keys(r).reduce(function(e,n){var i=r[n];return e[n]=t.isObject(i)?i:{value:i},e},{}),this},done:function(){return r}}},n.parse=function(e){t.parse.spec(this.spec,e)},n.json=function(){return this.spec},e}(),t.spec=function(e){return new t.Spec(e)},t.headless={},t.headless.View=function(){var n=function(e,n,r,i){this._canvas=null,this._type=i,this._el="body",this._build=!1,this._model=new t.Model,this._width=e||500,this._height=n||500,this._padding=r||{top:0,left:0,bottom:0,right:0},this._renderer=new t[i].Renderer,this.initialize()},r=n.prototype;return r.el=function(e){return arguments.length?(this._el!==e&&(this._el=e,this.initialize()),this):this._el},r.width=function(e){return arguments.length?(this._width!==e&&(this._width=e,this.initialize(),this._model.width(e)),this):this._width},r.height=function(e){return arguments.length?(this._height!==e&&(this._height=e,this.initialize(),this._model.height(this._height)),this):this._height},r.padding=function(e){return arguments.length?(this._padding!==e&&(this._padding=e,this.initialize()),this):this._padding},r.viewport=function(){return arguments.length?this:null},r.defs=function(e){return arguments.length?(this._model.defs(e),this):this._model.defs()},r.data=function(e){if(!arguments.length)return this._model.data();var n=t.keys(e).reduce(function(n,r){return n[r]=e[r].map(t.data.ingest),n},{});return this._model.data(n),this._build=!1,this},r.renderer=function(){return this._renderer},r.canvas=function(){return this._canvas},r.canvasAsync=function(e){function n(){t.pendingImages()===0?(this.render(),e(this._canvas)):setTimeout(n,10)}var t=this._renderer;t.pendingImages()>0?n():e(this._canvas)},r.svg=function(){if(this._type!=="svg")return null;var n=this._padding,r=this._width+(n?n.left+n.right:0),i=this._height+(n?n.top+n.bottom:0),s=e.select(this._el).select("svg").node().innerHTML.replace(/ href=/g," xlink:href=");return'<svg width="'+r+'" '+'height="'+i+'" '+t.config.svgNamespace+">"+s+"</svg>"},r.initialize=function(){var e=this._width,t=this._height,n=this._padding;return this._type==="svg"?this.initSVG(e,t,n):this.initCanvas(e,t,n),this},r.initCanvas=function(e,t,n){var r=require("canvas"),i=e+n.left+n.right,s=t+n.top+n.bottom,o=this._canvas=new r(i,s),u=o.getContext("2d");u.setTransform(1,0,0,1,n.left,n.top),this._renderer.initialize(null,e,t,n),this._renderer.context(u)},r.initSVG=function(e,t,n){var r=e+n.left+n.right,i=t+n.top+n.bottom;this._renderer.initialize(this._el,e,t,n)},r.render=function(e){return this._renderer.render(this._model.scene(),e),this},r.update=function(e){e=e||{};var t=this;return t._build=t._build||(t._model.build(),!0),t._model.encode(null,e.props,e.items),t.render(e.items),t},n}(),t.headless.View.Factory=function(e){return function(n){n=n||{};var r=e.width,i=e.height,s=e.padding,o=n.renderer||"canvas",u=(new t.headless.View(r,i,s,o)).defs(e);return e.data.load&&u.data(e.data.load),n.data&&u.data(n.data),u}},t.headless.render=function(e,n){function r(t){try{var r=t({data:e.data,renderer:e.renderer}).update();e.renderer==="svg"?n(null,{svg:r.svg()}):r.canvasAsync(function(e){n(null,{canvas:e})})}catch(i){n(i,null)}}t.parse.spec(e.spec,r,t.headless.View.Factory)},t}(d3);