text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vega-dataflow"),require("vega-scenegraph"),require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-scenegraph","vega-util"],e):e((t.vega=t.vega||{},t.vega.transforms={}),t.vega,t.vega,t.vega)}(this,function(t,e,W,c){"use strict";var M="top",w="left",T="right",E="bottom",p="top-left",v="top-right",k="bottom-left",z="bottom-right",B="start",D="end",C="group",F="axis",G="legend",H="row-header",L="row-footer",R="row-title",U="column-header",V="column-footer",J="column-title",_="padding",O="symbol",S="fit",j="fit-x",q="fit-y",A="pad",I="none",K="all",N="each",Q="column",X="row";function n(t){e.Transform.call(this,null,t)}function d(t,e,n){return e(t.bounds.clear(),t,n)}c.inherits(n,e.Transform).transform=function(t,e){var n,r=e.dataflow,a=t.mark,o=a.marktype,i=W.Marks[o],u=i.bound,s=a.bounds;return i.nested?(a.items.length&&r.dirty(a.items[0]),s=d(a,u),a.items.forEach(function(t){t.bounds.clear().union(s)})):o===C||t.modified()?(e.visit(e.MOD,function(t){r.dirty(t)}),s.clear(),a.items.forEach(function(t){s.union(d(t,u))}),a.role===G&&e.reflow()):(n=e.changed(e.REM),e.visit(e.ADD,function(t){s.union(d(t,u))}),e.visit(e.MOD,function(t){n=n||s.alignsWith(t.bounds),r.dirty(t),s.union(d(t,u))}),n&&(s.clear(),a.items.forEach(function(t){s.union(t.bounds)}))),W.boundClip(a),e.modifies("bounds")};var o=":vega_identifier:";function r(t){e.Transform.call(this,0,t)}function a(t){e.Transform.call(this,null,t)}function i(t){e.Transform.call(this,null,t)}r.Definition={type:"Identifier",metadata:{modifies:!0},params:[{name:"as",type:"string",required:!0}]},c.inherits(r,e.Transform).transform=function(t,e){var n=function(t){var e=t._signals[o];e||(t._signals[o]=e=t.add(0));return e}(e.dataflow),r=n.value,a=t.as;return e.visit(e.ADD,function(t){t[a]||(t[a]=++r)}),n.set(this.value=r),e},c.inherits(a,e.Transform).transform=function(t,e){var n,r,a,o=this.value;o||((o=e.dataflow.scenegraph().mark(t.markdef,(r=(n=t).groups,a=n.parent,r&&1===r.size?r.get(Object.keys(r.object)[0]):r&&a?r.lookup(a):null),t.index)).group.context=t.context,t.context.group||(t.context.group=o.group),o.source=this,o.clip=t.clip,o.interactive=t.interactive,this.value=o);var i=o.marktype===C?W.GroupItem:W.Item;return e.visit(e.ADD,function(t){i.call(t,o)}),(t.modified("clip")||t.modified("interactive"))&&(o.clip=t.clip,o.interactive=!!t.interactive,o.zdirty=!0,e.reflow()),o.items=e.source,e};var u=c.inherits(i,e.Transform),f={parity:function(t){return t.filter(function(t,e){return e%2?t.opacity=0:1})},greedy:function(t){var n;return t.filter(function(t,e){return e&&s(n.bounds,t.bounds)?t.opacity=0:(n=t,1)})}};function s(t,e){return!(t.x2-1<e.x1||t.x1+1>e.x2||t.y2-1<e.y1||t.y1+1>e.y2)}function h(t){for(var e,n=1,r=t.length,a=t[0].bounds;n<r;a=e,++n)if(s(a,e=t[n].bounds))return!0}function m(t){var e=t.bounds;return 1<e.width()&&1<e.height()}function y(t){return t.forEach(function(t){t.opacity=1}),t}function b(t,e){return t.reflow(e.modified()).modifies("opacity")}function l(t){e.Transform.call(this,null,t)}function Y(t,e){for(var n=0,r=t.length;n<r;++n)e.push(t[n])}function Z(t){return{x1:0,y1:0,x2:t.width||0,y2:t.height||0}}function $(t){var e=t.bounds.clone();return e.empty()?e.set(0,0,0,0):e.translate(-(t.x||0),-(t.y||0))}function tt(t,e){return"x1"===e?t.x||0:"y1"===e?t.y||0:"x2"===e?(t.x||0)+(t.width||0):"y2"===e?(t.y||0)+(t.height||0):void 0}function et(t,e){return t.bounds[e]}function nt(t,e,n){var r=c.isObject(t)?t[e]:t;return null!=r?r:void 0!==n?n:0}function rt(t){return t<0?Math.ceil(-t):0}function x(t,e,n){var r,a,o,i,u,s,d,l,c,f,h,m,y=function(t){for(var e,n,r=t.items,a=r.length,o=0,i={marks:[],rowheaders:[],rowfooters:[],colheaders:[],colfooters:[],rowtitle:null,coltitle:null};o<a;++o)if(n=(e=r[o]).items,e.marktype===C)switch(e.role){case F:case G:break;case H:Y(n,i.rowheaders);break;case L:Y(n,i.rowfooters);break;case U:Y(n,i.colheaders);break;case V:Y(n,i.colfooters);break;case R:i.rowtitle=n[0];break;case J:i.coltitle=n[0];break;default:Y(n,i.marks)}return i}(e),b=y.marks,x="flush"===n.bounds,g=x?Z:$,p=new W.Bounds(0,0,0,0),v=nt(n.align,Q),k=nt(n.align,X),M=nt(n.padding,Q),w=nt(n.padding,X),T=n.offset,E=e.columns||n.columns||b.length,z=E<0?1:Math.ceil(b.length/E),B=z*E,D=[],_=[],O=0,S=[],j=[],q=0,A=b.length;for(a=0;a<E;++a)_[a]=0;for(a=0;a<z;++a)j[a]=0;for(a=0;a<A;++a)u=g(b[a]),o=a%E,i=~~(a/E),d=Math.ceil(g(b[a]).x2),l=Math.ceil(g(b[a]).y2),O=Math.max(O,d),q=Math.max(q,l),_[o]=Math.max(_[o],d),j[i]=Math.max(j[i],l),D.push(M+rt(u.x1)),S.push(w+rt(u.y1)),t.dirty(b[a]);for(a=0;a<A;++a)a%E==0&&(D[a]=0),a<E&&(S[a]=0);if(v===N)for(o=1;o<E;++o){for(m=0,a=o;a<A;a+=E)m<D[a]&&(m=D[a]);for(a=o;a<A;a+=E)D[a]=m+_[o-1]}else if(v===K){for(a=m=0;a<A;++a)a%E&&m<D[a]&&(m=D[a]);for(a=0;a<A;++a)a%E&&(D[a]=m+O)}else for(v=!1,o=1;o<E;++o)for(a=o;a<A;a+=E)D[a]+=_[o-1];if(k===N)for(i=1;i<z;++i){for(m=0,r=(a=i*E)+E;a<r;++a)m<S[a]&&(m=S[a]);for(a=i*E;a<r;++a)S[a]=m+j[i-1]}else if(k===K){for(m=0,a=E;a<A;++a)m<S[a]&&(m=S[a]);for(a=E;a<A;++a)S[a]=m+q}else for(k=!1,i=1;i<z;++i)for(r=(a=i*E)+E;a<r;++a)S[a]+=j[i-1];for(a=c=0;a<A;++a)d=(s=b[a]).x||0,s.x=c=D[a]+(a%E?c:0),s.bounds.translate(c-d,0);for(o=0;o<E;++o)for(f=0,a=o;a<A;a+=E)l=(s=b[a]).y||0,s.y=f+=S[a],s.bounds.translate(0,f-l);if(nt(n.center,Q)&&1<z&&v)for(a=0;a<A;++a)s=b[a],0<(c=(u=v===K?O:_[a%E])-g(s).x2)&&(s.x+=d=c/2,s.bounds.translate(d,0));if(nt(n.center,X)&&1!==E&&k)for(a=0;a<A;++a)s=b[a],0<(f=(u=k===K?q:j[~~(a/E)])-g(s).y2)&&(s.y+=l=f/2,s.bounds.translate(0,l));for(a=0;a<A;++a)b[a].mark.bounds.clear();for(a=0;a<A;++a)s=b[a],t.dirty(s),p.union(s.mark.bounds.union(s.bounds));function I(t,e){return Math.floor(Math.min(t,e))}function P(t,e){return Math.ceil(Math.max(t,e))}g=x?tt:et,h=nt(n.headerBand,X,null),c=at(t,y.rowheaders,b,E,z,-nt(T,"rowHeader"),I,0,g,"x1",0,E,1,h),h=nt(n.headerBand,Q,null),f=at(t,y.colheaders,b,E,E,-nt(T,"columnHeader"),I,1,g,"y1",0,1,E,h),h=nt(n.footerBand,X,null),at(t,y.rowfooters,b,E,z,nt(T,"rowFooter"),P,0,g,"x2",E-1,E,1,h),h=nt(n.footerBand,Q,null),at(t,y.colfooters,b,E,E,nt(T,"columnFooter"),P,1,g,"y2",B-E,1,E,h),y.rowtitle&&(m=c-nt(T,"rowTitle"),h=nt(n.titleBand,X,.5),ot(t,y.rowtitle,m,0,p,h)),y.coltitle&&(m=f-nt(T,"columnTitle"),h=nt(n.titleBand,Q,.5),ot(t,y.coltitle,m,1,p,h))}function at(t,e,n,r,a,o,i,u,s,d,l,c,f,h){var m,y,b,x,g,p,v,k,M,w=n.length,T=0,E=0;if(!w)return T;for(m=l;m<w;m+=c)n[m]&&(T=i(T,s(n[m],d)));if(!e.length)return T;for(e.length>a&&(t.warn("Grid headers exceed limit: "+a),e=e.slice(0,a)),T+=o,y=0,x=e.length;y<x;++y)t.dirty(e[y]),e[y].mark.bounds.clear();for(m=l,y=0,x=e.length;y<x;++y,m+=c){for(g=(p=e[y]).mark.bounds,b=m;0<=b&&null==(v=n[b]);b-=f);M=u?(k=null==h?v.x:Math.round(v.bounds.x1+h*v.bounds.width()),T):(k=T,null==h?v.y:Math.round(v.bounds.y1+h*v.bounds.height())),g.union(p.bounds.translate(k-(p.x||0),M-(p.y||0))),p.x=k,p.y=M,t.dirty(p),E=i(E,g[d])}return E}function ot(t,e,n,r,a,o){if(e){t.dirty(e);var i=n,u=n;r?i=Math.round(a.x1+o*a.width()):u=Math.round(a.y1+o*a.height()),e.bounds.translate(i-(e.x||0),u-(e.y||0)),e.mark.bounds.clear().union(e.bounds),e.x=i,e.y=u,t.dirty(e)}}u.transform=function(t,e){var n,r,a=f[t.method]||f.parity,o=e.materialize(e.SOURCE).source;if(o){if(!t.method)return t.modified("method")&&(y(o),e=b(e,t)),e;if(t.sort&&(o=o.slice().sort(t.sort)),"greedy"===t.method&&(o=o.filter(m)),n=y(o),e=b(e,t),3<=n.length&&h(n)){for(;3<=(n=a(n)).length&&h(n););n.length<3&&!c.peek(o).opacity&&(1<n.length&&(c.peek(n).opacity=0),c.peek(o).opacity=1)}var i,u,s,d,l;return t.boundScale&&0<=t.boundTolerance&&(i=t.boundScale,u=t.boundOrient,s=+t.boundTolerance,d=i.range(),l=new W.Bounds,u===M||u===E?l.set(d[0],-1/0,d[1],1/0):l.set(-1/0,d[0],1/0,d[1]),l.expand(s||1),r=function(t){return l.encloses(t.bounds)},o.forEach(function(t){r(t)||(t.opacity=0)})),e}},c.inherits(l,e.Transform).transform=function(t,e){var n=e.dataflow;if(e.visit(e.ALL,function(t){n.dirty(t)}),e.fields&&e.fields.zindex){var r=e.source&&e.source[0];r&&(r.mark.zdirty=!0)}};var P=.5,it=new W.Bounds;function g(t){e.Transform.call(this,null,t)}function ut(t,e,n){return t[e]===n?0:(t[e]=n,1)}function st(t,e,n,r){var a,o,i,u,s=e.items[0],d=s.datum,l=d.orient,c=(u=+(i=d).grid,[i.ticks?u++:-1,i.labels?u++:-1,u+ +i.domain]),f=s.range,h=s.offset,m=s.position,y=s.minExtent,b=s.maxExtent,x=d.title&&s.items[c[2]].items[0],g=s.titlePadding,p=s.bounds,v=0,k=0;switch(it.clear().union(p),p.clear(),-1<(a=c[0])&&p.union(s.items[a].bounds),-1<(a=c[1])&&p.union(s.items[a].bounds),l){case M:v=m||0,k=-h,o=Math.max(y,Math.min(b,-p.y1)),x&&(o=dt(x,o,g,0,-1,p)),p.add(0,-o).add(f,0);break;case w:v=-h,k=m||0,o=Math.max(y,Math.min(b,-p.x1)),x&&(o=dt(x,o,g,1,-1,p)),p.add(-o,0).add(0,f);break;case T:v=n+h,k=m||0,o=Math.max(y,Math.min(b,p.x2)),x&&(o=dt(x,o,g,1,1,p)),p.add(0,0).add(o,f);break;case E:v=m||0,k=r+h,o=Math.max(y,Math.min(b,p.y2)),x&&(o=dt(x,o,g,0,1,p)),p.add(0,0).add(f,o);break;default:v=s.x,k=s.y}return W.boundStroke(p.translate(v,k),s),ut(s,"x",v+P)|ut(s,"y",k+P)&&(s.bounds=it,t.dirty(s),s.bounds=p,t.dirty(s)),s.mark.bounds.clear().union(p)}function dt(t,e,n,r,a,o){var i=t.bounds,u=0,s=0;return t.auto?(e+=n,r?u=(t.x||0)-(t.x=a*e):s=(t.y||0)-(t.y=a*e),i.translate(-u,-s),t.mark.bounds.set(i.x1,i.y1,i.x2,i.y2),r?(o.add(0,i.y1).add(0,i.y2),e+=i.width()):(o.add(i.x1,0).add(i.x2,0),e+=i.height())):o.union(i),e}function lt(t,e,n,r,a,o,i){var u,s,d,l,c,f=e.items[0],h=f.datum,m=h.orient,y=f.offset,b=f.bounds,x=0,g=0;switch(m===M||m===E?(d=a,x=n[m]):m!==w&&m!==T||(d=r,g=n[m]),it.clear().union(b),b.clear(),f.items.forEach(function(t){b.union(t.bounds)}),u=2*f.padding-1,s=2*f.padding-1,b.empty()||(u=Math.ceil(b.width()+u),s=Math.ceil(b.height()+s)),h.type===O&&(l=f.items[0].items[0].items[0].items,c=l.reduce(function(t,e){return t[e.column]=Math.max(e.bounds.x2-e.x,t[e.column]||0),t},{}),l.forEach(function(t){t.width=c[t.column],t.height=t.bounds.y2-t.y})),m){case w:x-=n.leftWidth+y-Math.floor(d.x1),n.left+=s+n.margin;break;case T:x+=y+Math.ceil(d.x2),n.right+=s+n.margin;break;case M:g-=s+y-Math.floor(d.y1),n.top+=u+n.margin;break;case E:g+=y+Math.ceil(d.y2),n.bottom+=u+n.margin;break;case p:x+=y,g+=y;break;case v:x+=o-u-y,g+=y;break;case k:x+=y,g+=i-s-y;break;case z:x+=o-u-y,g+=i-s-y;break;default:x=f.x,g=f.y}return W.boundStroke(b.set(x,g,x+u,g+s),f),ut(f,"x",x)|ut(f,"width",u)|ut(f,"y",g)|ut(f,"height",s)&&(f.bounds=it,t.dirty(f),f.bounds=b,t.dirty(f)),f.mark.bounds.clear().union(b)}c.inherits(g,e.Transform).transform=function(e,t){var n=t.dataflow;return e.mark.items.forEach(function(t){e.layout&&x(n,t,e.layout),function(t,e,n){var r,a,o,i,u,s,d=e.items,l=Math.max(0,e.width||0),c=Math.max(0,e.height||0),f=(new W.Bounds).set(0,0,l,c),h=f.clone(),m=f.clone(),y=[];for(u=0,s=d.length;u<s;++u)switch((a=d[u]).role){case F:void 0,b=a.items[0].datum.orient,(i=b===w||b===T?h:m).union(st(t,a,l,c));break;case"title":r=a;break;case G:y.push(a);break;case"frame":case"scope":case H:case L:case R:case U:case V:case J:h.union(a.bounds),m.union(a.bounds);break;default:f.union(a.bounds)}var b;if(y.length)for(o={leftWidth:(g=t,p=y,p.reduce(function(t,e){var n=e.items[0];if(function(t,e,n){var r=e.padding-n.x,a=e.padding-n.y;if(e.datum.title){var o=e.items[1].items[0];a+=e.titlePadding+o.fontSize}(r||a)&&(n.x+=r,n.y+=a,n.bounds.translate(r,a),n.mark.bounds.translate(r,a),t.dirty(n))}(g,n,n.items[0].items[0]),n.datum.orient===w){var r=it.clear();n.items.forEach(function(t){r.union(t.bounds)}),t=Math.max(t,Math.ceil(r.width()+2*n.padding-1))}return t},0)),margin:n.legendMargin||8,left:0,right:0,top:0,bottom:0},u=0,s=y.length;u<s;++u)if(i=lt(t,y[u],o,h,m,l,c),n.autosize&&n.autosize.type===S){var x=y[u].items[0].datum.orient;x===w||x===T?f.add(i.x1,0).add(i.x2,0):x!==M&&x!==E||f.add(0,i.y1).add(0,i.y2)}else f.union(i);var g,p;f.union(h).union(m),r&&f.union(function(t,e,n,r,a){var o,i=e.items[0],u=i.orient,s=i.frame,d=i.anchor,l=i.offset,c=i.bounds,f=0,h=u===w||u===T?r:n,m=0,y=0;s!==C?h=u===w?(f=a.y2,a.y1):u===T?(f=a.y1,a.y2):(f=a.x1,a.x2):u===w&&(f=r,h=0);switch(o=d===B?f:d===D?h:(f+h)/2,it.clear().union(c),u){case M:m=o,y=a.y1-l;break;case w:m=a.x1-l,y=o;break;case T:m=a.x2+l,y=o;break;case E:m=o,y=a.y2+l;break;default:m=i.x,y=i.y}c.translate(m-i.x,y-i.y),ut(i,"x",m)|ut(i,"y",y)&&(i.bounds=it,t.dirty(i),i.bounds=c,t.dirty(i));return e.bounds.clear().union(c)}(t,r,l,c,f));!function(t,e,n,r){var a=r.autosize||{},o=a.type,i=t._width,u=t._height,s=t.padding();if(t._autosize<1||!o)return;var d=Math.max(0,e.width||0),l=Math.max(0,Math.ceil(-n.x1)),c=Math.max(0,Math.ceil(n.x2-d)),f=Math.max(0,e.height||0),h=Math.max(0,Math.ceil(-n.y1)),m=Math.max(0,Math.ceil(n.y2-f));a.contains===_&&(i-=s.left+s.right,u-=s.top+s.bottom);o===I?(h=l=0,d=i,f=u):o===S?(d=Math.max(0,i-l-c),f=Math.max(0,u-h-m)):o===j?(d=Math.max(0,i-l-c),u=f+h+m):o===q?(i=d+l+c,f=Math.max(0,u-h-m)):o===A&&(i=d+l+c,u=f+h+m);t._resizeView(i,u,d,f,[l,h],a.resize)}(t,e,f,n)}(n,t,e)}),e.modified()&&t.reflow(),t},t.bound=n,t.identifier=r,t.mark=a,t.overlap=i,t.render=l,t.viewlayout=g,Object.defineProperty(t,"__esModule",{value:!0})});