diff --git a/src/headless/View.js b/src/headless/View.js index 7d6d719295..74f6307cd3 100644 --- a/src/headless/View.js +++ b/src/headless/View.js @@ -53,6 +53,11 @@ vg.headless.View = (function() { return this; }; + prototype.viewport = function() { + if (!arguments.length) return null; + return this; + }; + prototype.defs = function(defs) { if (!arguments.length) return this._model.defs(); this._model.defs(defs); diff --git a/vega.js b/vega.js index 62eb798b3c..4e564d714c 100644 --- a/vega.js +++ b/vega.js @@ -5769,6 +5769,11 @@ vg.headless = {};vg.headless.View = (function() { return this; }; + prototype.viewport = function() { + if (!arguments.length) return null; + return this; + }; + prototype.defs = function(defs) { if (!arguments.length) return this._model.defs(); this._model.defs(defs); diff --git a/vega.min.js b/vega.min.js index 35aa887957..2f95fc5bc7 100644 --- a/vega.min.js +++ b/vega.min.js @@ -1,3 +1,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(++s0;)(f=+t[s]-a*u)>=r[0]&&i.push(f);for(--s,a=0;++a1?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;ia)return n[i]}return 0}},t.cmp=function(e,t){return et?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;si&&(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 ethis.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.x1this.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.x2e.x2||this.y2e.y2)},t.contains=function(e,t){return!(ethis.x2||tthis.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;up)for(var d=1,v=f.length;d1&&(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;B0&&(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;i0&&(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;d0&&(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;u0&&(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=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=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 "+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=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;u0?"|":"")+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;lt?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;rt.x?1:e.zt.z?1:0});for(v=s[0].x,a=0,l=0,h=0,f=s.length;ha)o[a++].push({x:l,y:0});p.x=l,o[a++].push(p)}while(ao&&(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\~\&\|\?\:\+\-\/\*\%\!\^\,\;\[\]\{\}\(\) ]+)/;return function(r){var i=r.split(n),s,o,u,a,f,l;for(f=0,l=0,u=0,a=i.length;u0?"\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;c0&&(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;o1&&(u=1),a=r.ease(u);for(f=0,l=r.length;f1?+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;C0?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'"+s+""},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); \ No newline at end of file +,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;p0?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'"+s+""},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); \ No newline at end of file