diff --git a/package.json b/package.json index adbf61a528..5db4426a65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vega", - "version": "1.2.1", + "version": "1.3.0", "description": "Vega Runtime", "keywords": [ "vega", diff --git a/src/_config.js b/src/_config.js index ab83861f7c..c8763af95e 100644 --- a/src/_config.js +++ b/src/_config.js @@ -18,6 +18,7 @@ vg.config.axis = { ticks: 10, padding: 3, axisColor: "#000", + gridColor: "#ccc", tickColor: "#000", tickLabelColor: "#000", axisWidth: 1, diff --git a/src/_package.js b/src/_package.js index 33b5d453b5..39708dfa79 100644 --- a/src/_package.js +++ b/src/_package.js @@ -1,7 +1,7 @@ var vg = {}; // semantic versioning -vg.version = '1.2.1'; +vg.version = '1.3.0'; // type checking functions var toString = Object.prototype.toString; diff --git a/src/canvas/marks.js b/src/canvas/marks.js index bc2949e7e5..073d991914 100644 --- a/src/canvas/marks.js +++ b/src/canvas/marks.js @@ -379,26 +379,32 @@ vg.canvas.marks = (function() { function drawGroup(g, scene, bounds) { if (!scene.items.length) return; - var items = scene.items, group, + var items = scene.items, group, axes, renderer = this, gx, gy, i, n, j, m; drawRect(g, scene, bounds); for (i=0, n=items.length; i "+tag).data(data), + s = id + " > " + tag, + m = p.selectAll(s).data(data), e = m.enter().append(tag); - if (tag !== "g") { + if (notG) { p.style("pointer-events", evts); e.each(function(d) { (d.mark ? d : d[0])._svg = this; }); } else { - e.append("rect") - .attr("class", "background") - .style("pointer-events", evts); + e.append("rect").attr("class","background").style("pointer-events",evts); } m.exit().remove(); m.each(attr); - if (tag !== "g") { - m.each(style); - } else { - p.selectAll(id+" > "+tag+" > rect.background") - .each(group_bg).each(style); - } + if (notG) m.each(style); + else p.selectAll(s+" > rect.background").each(group_bg).each(style); + + return p; } - function drawGroup(g, scene, index) { - var renderer = this; - - drawMark(g, scene, index, "group_", "g", group); + function drawGroup(g, scene, index, prefix) { + var p = drawMark(g, scene, index, prefix || "group_", "g", group), + c = p.node().childNodes, n = c.length, i, j, m; + + for (i=0; i "+tag).data(data), + s = id + " > " + tag, + m = p.selectAll(s).data(data), e = m.enter().append(tag); - if (tag !== "g") { + if (notG) { p.style("pointer-events", evts); e.each(function(d) { (d.mark ? d : d[0])._svg = this; }); } else { - e.append("rect") - .attr("class", "background") - .style("pointer-events", evts); + e.append("rect").attr("class","background").style("pointer-events",evts); } m.exit().remove(); m.each(attr); - if (tag !== "g") { - m.each(style); - } else { - p.selectAll(id+" > "+tag+" > rect.background") - .each(group_bg).each(style); - } + if (notG) m.each(style); + else p.selectAll(s+" > rect.background").each(group_bg).each(style); + + return p; } - function drawGroup(g, scene, index) { - var renderer = this; - - drawMark(g, scene, index, "group_", "g", group); - - var x = g.select(".group_"+index).node(), i, n, j, m; - for (i=0, n=x.childNodes.length; i=0&&(e=e.slice(s.length)),require("fs").readFile(e,n)}function l(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 p(e,t,n){i=[];if(n&&t.length>1){var r=d(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.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)?"["+e.map(t.str)+"]":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){n=n||t.identity;var r=[],i;for(var s=0;sthis.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.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=s,t.lineWidth=a,t.lineCap=(u=n.strokeCap)!=undefined?u:"butt",t.stroke(),n.bounds.expand(a)))}function p(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=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 v(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=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 m(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=u,e.lineWidth=f,e.strokeText(s.text,x,y));s.angle&&e.restore()}}function w(e,t,n,r){var i=t.x+(t.dx||0),s=t.y+(t.dy||0),o=e.measureText(t.text).width,u=t.fontSize,a=t.align,f=t.baseline,l,c,h,p,d;return a==="center"?i-=o/2:a==="right"&&(i-=o),f==="top"?s+=u/5:f==="bottom"?s-=u:f==="middle"?s=s-u/2+u/10:s-=4*u/5,n.set(i,s,i+o,s+u),!r&&t.angle&&n.rotate(t.angle*Math.PI/180,t.x,t.y),n}function E(e){return function(t,n,r){p(e,t,n,r)}}function S(e){return function(t,n,r){if(!n.items.length)return;if(r&&!r.intersects(n.items[0].bounds))return;h(e,t,n.items[0],n.items)}}function T(e,t,n){if(!t.items.length)return;var r=t.items,i,s=this,o,u,a,f,l,c;d(e,t,n);for(a=0,f=r.length;a=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 k(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),M.area(e,o,n,r)?o[0]:!1)}function L(e,t,n,r,i,s){return!1}function A(e,t,n,r,i,s){return!1}function O(e){return function(t,n,r,i,s,o){return C(e,t,n,r,i,s,o)}}function _(e,t,n,r,i,s){if(!t.fontSize)return!1;if(!t.angle)return!0;e.font=g(t);var u=w(e,t,o,!0),a=-t.angle*Math.PI/180,f=Math.cos(a),l=Math.sin(a),n=t.x,r=t.y,c=f*i-l*s+(n-n*f+r*l),h=l*i+f*s+(r-n*l-r*f);return u.contains(c,h)}var n=t.canvas.path.parse,r=t.canvas.path.render,i=Math.sqrt(3),s=Math.tan(30*Math.PI/180),o=new t.Bounds,M={text:_,rect:function(e,t,n,r){return!0},image:function(e,t,n,r){return!0},arc:function(e,t,n,r){return u(e,t),e.isPointInPath(n,r)},area:function(e,t,n,r){return l(e,t),e.isPointInPath(n,r)},path:function(e,t,n,r){return a(e,t),e.isPointInPath(n,r)},symbol:function(e,t,n,r){return f(e,t),e.isPointInPath(n,r)}};return{draw:{group:T,area:S(l),line:S(c),arc:E(u),path:E(a),symbol:E(f),rect:d,rule:v,text:b,image:m,drawOne:S,drawAll:E},pick:{group:N,area:k,line:L,arc:O(M.arc),path:O(M.path),symbol:O(M.symbol),rect:O(M.rect),rule:A,text:O(M.text),image:O(M.image),pickAll:C}}}(),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 v(e){var t=e.mark?e:e[0],n,r,i,s,o;for(n=0,r=d.length;n "+i).data(a),p=h.enter().append(i);i!=="g"?(l.style("pointer-events",f),p.each(function(e){(e.mark?e:e[0])._svg=this})):p.append("rect").attr("class","background").style("pointer-events",f),h.exit().remove(),h.each(s),i!=="g"?h.each(v):l.selectAll(c+" > "+i+" > rect.background").each(S).each(v)}function M(t,n,r){var i=this;O(t,n,r,"group_","g",k);var s=t.select(".group_"+r).node(),o,u,a,f;for(o=0,u=s.childNodes.length;o=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=o(e)?e:t.config.baseURL+e,i=u(r)?f:l;i(r,n)}else a(e,n)};var i=/^[A-Za-z]+\:\/\//,s="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;lo&&(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;var n=e.value!==undefined?t.str(e.value):"item.datum.data";e.field!==undefined&&(n="item.datum["+t.field(e.field).map(t.str).join("][")+"]");if(e.scale!==undefined){var r="group.scales['"+e.scale+"']";e.band?n=r+".rangeBand()":n=r+"("+n+")"}return"("+(e.mult?e.mult+" * ":"")+n+")"+(e.offset?" + "+e.offset:"")}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=i[o.data]||s,a=t.accessor(o.field),n.domain(t.unique(u,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){var l,c,h;l=[null,null],n.domain!==undefined&&(t.isArray(n.domain)?l=n.domain.slice():t.isObject(n.domain)?(c=a[n.domain.data]||f,t.array(n.domain.field).forEach(function(n,r){n=t.accessor(n),l[0]=e.min([l[0],e.min(c,n)]),l[1]=e.max([l[1],e.max(c,n)])})):l=n.domain),n.domainMin!==undefined&&(t.isObject(n.domainMin)?(l[0]=null,c=a[n.domainMin.data]||f,t.array(n.domainMin.field).forEach(function(n,r){n=t.accessor(n),l[0]=e.min([l[0],e.min(c,n)])})):l[0]=n.domainMin),n.domainMax!==undefined&&(t.isObject(n.domainMax)?(l[1]=null,c=a[n.domainMax.data]||f,t.array(n.domainMax.field).forEach(function(n,r){n=t.accessor(n),l[1]=e.max([l[1],e.max(c,n)])})):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?"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;c1&&(u=1),a=r.ease(u);for(f=0,l=r.length;f1?+t:s,u=n>0?+arguments[n]:s,N},N.tickPadding=function(e){return arguments.length?(a=+e,N):a},N.tickSubdivide=function(e){return arguments.length?(d=+e,N):d},N.offset=function(e){return arguments.length?(r=e,N):f},N.majorTickProperties=function(e){return arguments.length?(S=e,N):S},N.minorTickProperties=function(e){return arguments.length?(x=e,N):x},N.tickLabelProperties=function(e){return arguments.length?(E=e,N):E},N.domainProperties=function(e){return arguments.length?(T=e,N):T},N};var c="bottom",h={top:1,right:1,bottom: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;i0?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 +vg=function(e){function r(e){t.config.isNode?process.stderr.write(e+"\n"):console.log(e)}function o(e){return i.test(e)}function u(e){return e.indexOf(s)===0}function a(n,r){t.log("LOAD: "+n),e.xhr(n,function(e,t){t&&(t=t.responseText),r(e,t)})}function f(e,n){t.log("LOAD FILE: "+e);var r=e.indexOf(s);r>=0&&(e=e.slice(s.length)),require("fs").readFile(e,n)}function l(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 p(e,t,n){i=[];if(n&&t.length>1){var r=d(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.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)?"["+e.map(t.str)+"]":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){n=n||t.identity;var r=[],i;for(var s=0;sthis.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.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=s,t.lineWidth=a,t.lineCap=(u=n.strokeCap)!=undefined?u:"butt",t.stroke(),n.bounds.expand(a)))}function p(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=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 v(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=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 m(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=u,e.lineWidth=f,e.strokeText(s.text,x,y));s.angle&&e.restore()}}function w(e,t,n,r){var i=t.x+(t.dx||0),s=t.y+(t.dy||0),o=e.measureText(t.text).width,u=t.fontSize,a=t.align,f=t.baseline,l,c,h,p,d;return a==="center"?i-=o/2:a==="right"&&(i-=o),f==="top"?s+=u/5:f==="bottom"?s-=u:f==="middle"?s=s-u/2+u/10:s-=4*u/5,n.set(i,s,i+o,s+u),!r&&t.angle&&n.rotate(t.angle*Math.PI/180,t.x,t.y),n}function E(e){return function(t,n,r){p(e,t,n,r)}}function S(e){return function(t,n,r){if(!n.items.length)return;if(r&&!r.intersects(n.items[0].bounds))return;h(e,t,n.items[0],n.items)}}function T(e,t,n){if(!t.items.length)return;var r=t.items,i,s,o=this,u,a,f,l,c,h;d(e,t,n);for(f=0,l=r.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 k(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),M.area(e,o,n,r)?o[0]:!1)}function L(e,t,n,r,i,s){return!1}function A(e,t,n,r,i,s){return!1}function O(e){return function(t,n,r,i,s,o){return C(e,t,n,r,i,s,o)}}function _(e,t,n,r,i,s){if(!t.fontSize)return!1;if(!t.angle)return!0;e.font=g(t);var u=w(e,t,o,!0),a=-t.angle*Math.PI/180,f=Math.cos(a),l=Math.sin(a),n=t.x,r=t.y,c=f*i-l*s+(n-n*f+r*l),h=l*i+f*s+(r-n*l-r*f);return u.contains(c,h)}var n=t.canvas.path.parse,r=t.canvas.path.render,i=Math.sqrt(3),s=Math.tan(30*Math.PI/180),o=new t.Bounds,M={text:_,rect:function(e,t,n,r){return!0},image:function(e,t,n,r){return!0},arc:function(e,t,n,r){return u(e,t),e.isPointInPath(n,r)},area:function(e,t,n,r){return l(e,t),e.isPointInPath(n,r)},path:function(e,t,n,r){return a(e,t),e.isPointInPath(n,r)},symbol:function(e,t,n,r){return f(e,t),e.isPointInPath(n,r)}};return{draw:{group:T,area:S(l),line:S(c),arc:E(u),path:E(a),symbol:E(f),rect:d,rule:v,text:b,image:m,drawOne:S,drawAll:E},pick:{group:N,area:k,line:L,arc:O(M.arc),path:O(M.path),symbol:O(M.symbol),rect:O(M.rect),rule:A,text:O(M.text),image:O(M.image),pickAll:C}}}(),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 v(e){var t=e.mark?e:e[0],n,r,i,s,o;for(n=0,r=d.length;n "+s,m=h.selectAll(d).data(a),g=m.enter().append(s);return c?(h.style("pointer-events",f),g.each(function(e){(e.mark?e:e[0])._svg=this})):g.append("rect").attr("class","background").style("pointer-events",f),m.exit().remove(),m.each(o),c?m.each(v):h.selectAll(d+" > rect.background").each(k).each(v),h}function M(t,n,r,i){var s=O(t,n,r,i||"group_","g",C),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=o(e)?e:t.config.baseURL+e,i=u(r)?f:l;i(r,n)}else a(e,n)};var i=/^[A-Za-z]+\:\/\//,s="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;lo&&(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;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 r="group.scales['"+e.scale+"']";e.band?n=r+".rangeBand()":n=r+"("+n+")"}return"("+(e.mult?e.mult+" * ":"")+n+")"+(e.offset?" + "+e.offset:"")}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=i[o.data]||s,a=t.accessor(o.field),n.domain(t.unique(u,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){var l,c,h;l=[null,null],n.domain!==undefined&&(t.isArray(n.domain)?l=n.domain.slice():t.isObject(n.domain)?(c=a[n.domain.data]||f,t.array(n.domain.field).forEach(function(n,r){n=t.accessor(n),l[0]=e.min([l[0],e.min(c,n)]),l[1]=e.max([l[1],e.max(c,n)])})):l=n.domain),n.domainMin!==undefined&&(t.isObject(n.domainMin)?(l[0]=null,c=a[n.domainMin.data]||f,t.array(n.domainMin.field).forEach(function(n,r){n=t.accessor(n),l[0]=e.min([l[0],e.min(c,n)])})):l[0]=n.domainMin),n.domainMax!==undefined&&(t.isObject(n.domainMax)?(l[1]=null,c=a[n.domainMax.data]||f,t.array(n.domainMax.field).forEach(function(n,r){n=t.accessor(n),l[1]=e.max([l[1],e.max(c,n)])})):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?"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;c1&&(u=1),a=r.ease(u);for(f=0,l=r.length;f1?+t:u,f=n>0?+arguments[n]:u,M},M.tickPadding=function(e){return arguments.length?(l=+e,M):l},M.tickSubdivide=function(e){return arguments.length?(g=+e,M):g},M.offset=function(e){return arguments.length?(r=e,M):d},M.layer=function(e){return arguments.length?(s=e,M):s},M.grid=function(e){return arguments.length?(o=e,M):o},M.gridLineProperties=function(e){return arguments.length?(x=e,M):x},M.majorTickProperties=function(e){return arguments.length?(L=e,M):L},M.minorTickProperties=function(e){return arguments.length?(A=e,M):A},M.tickLabelProperties=function(e){return arguments.length?(k=e,M):k},M.domainProperties=function(e){return arguments.length?(O=e,M):O},M};var c="bottom",h={top:1,right:1,bottom:1,left:1},m={bottom:"center",top:"center",left:"right",right:"left"},g={bottom:"top",top:"bottom",left:"middle",right:"middle"};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;i0?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