d3-visualize
Version:
d3-view components for data visualization
1 lines • 89.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-let"),require("d3-collection"),require("d3-view"),require("d3-dsv"),require("d3-array"),require("d3-time-format"),require("d3-dispatch"),require("d3-transition"),require("d3-selection"),require("d3-format"),require("d3-color")):"function"==typeof define&&define.amd?define(["exports","d3-let","d3-collection","d3-view","d3-dsv","d3-array","d3-time-format","d3-dispatch","d3-transition","d3-selection","d3-format","d3-color"],e):e(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,e,i,n,r,a,o,s,l,u,d,c){"use strict";var f="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var h,p=(function(t,e){!function(t){function e(t){return t}function i(t,e){for(var i=0,n=e.length,r=new Array(n);i<n;++i)r[i]=t[e[i]];return r}z.version="1.3.12",z.permute=i;var n=z.bisect=r(e);function r(t){function e(e,i,n,r){for(;n<r;){var a=n+r>>>1;i<t(e[a])?r=a:n=a+1}return n}return e.right=e,e.left=function(e,i,n,r){for(;n<r;){var a=n+r>>>1;t(e[a])<i?n=a+1:r=a}return n},e}function a(t){function e(t,e,n){for(var r=n-e,a=1+(r>>>1);--a>0;)i(t,a,r,e);return t}function i(e,i,n,r){for(var a,o=e[--r+i],s=t(o);(a=i<<1)<=n&&(a<n&&t(e[r+a])>t(e[r+a+1])&&a++,!(s<=t(e[r+a])));)e[r+i]=e[r+a],i=a;e[r+i]=o}return e.sort=function(t,e,n){for(var r,a=n-e;--a>0;)r=t[e],t[e]=t[e+a],t[e+a]=r,i(t,1,a,e);return t},e}function o(t){var e=a(t);return function(i,n,r,a){var o,s,l,u=new Array(a=Math.min(r-n,a));for(s=0;s<a;++s)u[s]=i[n++];if(e(u,0,a),n<r){o=t(u[0]);do{t(l=i[n])>o&&(u[0]=l,o=t(e(u,0,a)[0]))}while(++n<r)}return u}}function s(t){return function(e,i,n){for(var r=i+1;r<n;++r){for(var a=r,o=e[r],s=t(o);a>i&&t(e[a-1])>s;--a)e[a]=e[a-1];e[a]=o}return e}}function l(t){var e=s(t);function i(n,r,a){return(a-r<u?e:function(e,n,r){var a,o=(r-n)/6|0,s=n+o,l=r-1-o,u=n+r-1>>1,d=u-o,c=u+o,f=e[s],h=t(f),p=e[d],g=t(p),m=e[u],v=t(m),y=e[c],x=t(y),b=e[l],w=t(b);h>g&&(a=f,f=p,p=a,a=h,h=g,g=a);x>w&&(a=y,y=b,b=a,a=x,x=w,w=a);h>v&&(a=f,f=m,m=a,a=h,h=v,v=a);g>v&&(a=p,p=m,m=a,a=g,g=v,v=a);h>x&&(a=f,f=y,y=a,a=h,h=x,x=a);v>x&&(a=m,m=y,y=a,a=v,v=x,x=a);g>w&&(a=p,p=b,b=a,a=g,g=w,w=a);g>v&&(a=p,p=m,m=a,a=g,g=v,v=a);x>w&&(a=y,y=b,b=a,a=x,x=w,w=a);var k=p,z=g,S=y,_=x;e[s]=f,e[d]=e[n],e[u]=m,e[c]=e[r-1],e[l]=b;var M=n+1,A=r-2,O=z<=_&&z>=_;if(O)for(var P=M;P<=A;++P){var E=e[P],T=t(E);if(T<z)P!==M&&(e[P]=e[M],e[M]=E),++M;else if(T>z)for(;;){var C=t(e[A]);if(!(C>z)){if(C<z){e[P]=e[M],e[M++]=e[A],e[A--]=E;break}e[P]=e[A],e[A--]=E;break}A--}}else for(var P=M;P<=A;P++){var E=e[P],T=t(E);if(T<z)P!==M&&(e[P]=e[M],e[M]=E),++M;else if(T>_)for(;;){var C=t(e[A]);if(!(C>_)){C<z?(e[P]=e[M],e[M++]=e[A],e[A--]=E):(e[P]=e[A],e[A--]=E);break}if(--A<P)break}}if(e[n]=e[M-1],e[M-1]=k,e[r-1]=e[A+1],e[A+1]=S,i(e,n,M-1),i(e,A+2,r),O)return e;if(M<s&&A>l){for(var W;(W=t(e[M]))<=z&&W>=z;)++M;for(;(C=t(e[A]))<=_&&C>=_;)--A;for(var P=M;P<=A;P++){var E=e[P],T=t(E);if(T<=z&&T>=z)P!==M&&(e[P]=e[M],e[M]=E),M++;else if(T<=_&&T>=_)for(;;){var C=t(e[A]);if(!(C<=_&&C>=_)){C<z?(e[P]=e[M],e[M++]=e[A],e[A--]=E):(e[P]=e[A],e[A--]=E);break}if(--A<P)break}}}return i(e,M,A+1)})(n,r,a)}return i}n.by=r,(z.heap=a(e)).by=a,(z.heapselect=o(e)).by=o,(z.insertionsort=s(e)).by=s,(z.quicksort=l(e)).by=l;var u=32,d=g,c=g,f=g,h=function(t,e){var i=t.length;for(;i<e;)t[i++]=0;return t},p=function(t,e){if(e>32)throw new Error("invalid array width!");return t};function g(t){for(var e=new Array(t),i=-1;++i<t;)e[i]=0;return e}function m(t){return[0,t.length]}function v(){return null}function y(){return 0}function x(t){return t+1}function b(t){return t-1}function w(t){return function(e,i){return e+ +t(i)}}function k(t){return function(e,i){return e-t(i)}}function z(){var t={add:A,remove:function(){for(var t=S(s,s),e=[],i=0,n=0;i<s;++i)f[i]?t[i]=n++:e.push(i);g.forEach(function(t){t(0,[],e)}),M.forEach(function(e){e(t)});for(var a,i=0,n=0;i<s;++i)(a=f[i])&&(i!==n&&(f[n]=a,r[n]=r[i]),++n);r.length=n;for(;s>n;)f[--s]=0},dimension:function(t){var d,A,O,P,E,T={filter:function(t){return null==t?G():Array.isArray(t)?L(t):"function"==typeof t?N(t):V(t)},filterExact:V,filterRange:L,filterFunction:N,filterAll:G,top:function(t){var e,i=[],n=$;for(;--n>=H&&t>0;)f[e=A[n]]||(i.push(r[e]),--t);return i},bottom:function(t){var e,i=[],n=H;for(;n<$&&t>0;)f[e=A[n]]||(i.push(r[e]),--t),n++;return i},group:K,groupAll:function(){var t=K(v),e=t.all;return delete t.all,delete t.top,delete t.order,delete t.orderNatural,delete t.size,t.value=function(){return e()[0].value},t},dispose:I,remove:I},C=~u&-~u,W=~C,j=l(function(t){return O[t]}),D=m,F=[],q=[],H=0,$=0;z.unshift(Y),z.push(R),M.push(B),u|=C,(c>=32?!C:u&-(1<<c))&&(f=p(f,c<<=1));function Y(e,n,r){O=e.map(t),P=j(function(t){for(var e=S(t,t),i=-1;++i<t;)e[i]=i;return e}(r),0,r),O=i(O,P);var a,o=D(O),l=o[0],u=o[1];if(E)for(a=0;a<r;++a)E(O[a],a)||(f[P[a]+n]|=C);else{for(a=0;a<l;++a)f[P[a]+n]|=C;for(a=u;a<r;++a)f[P[a]+n]|=C}if(!n)return d=O,A=P,H=l,void($=u);var c=d,h=A,p=0,g=0;for(d=new Array(s),A=S(s,s),a=0;p<n&&g<r;++a)c[p]<O[g]?(d[a]=c[p],A[a]=h[p++]):(d[a]=O[g],A[a]=P[g++]+n);for(;p<n;++p,++a)d[a]=c[p],A[a]=h[p];for(;g<r;++g,++a)d[a]=O[g],A[a]=P[g]+n;o=D(d),H=o[0],$=o[1]}function R(t,e,i){F.forEach(function(t){t(O,P,e,i)}),O=P=null}function B(t){for(var e,i=0,n=0;i<s;++i)f[e=A[i]]&&(i!==n&&(d[n]=d[i]),A[n]=t[e],++n);for(d.length=n;n<s;)A[n++]=0;var r=D(d);H=r[0],$=r[1]}function X(t){var e=t[0],i=t[1];if(E)return E=null,U(function(t,n){return e<=n&&n<i}),H=e,$=i,T;var n,r,a,o=[],s=[];if(e<H)for(n=e,r=Math.min(H,i);n<r;++n)f[a=A[n]]^=C,o.push(a);else if(e>H)for(n=H,r=Math.min(e,$);n<r;++n)f[a=A[n]]^=C,s.push(a);if(i>$)for(n=Math.max(e,$),r=i;n<r;++n)f[a=A[n]]^=C,o.push(a);else if(i<$)for(n=Math.max(H,i),r=$;n<r;++n)f[a=A[n]]^=C,s.push(a);return H=e,$=i,g.forEach(function(t){t(C,o,s)}),T}function V(t){return X((e=n,i=t,D=function(t){var n=t.length;return[e.left(t,i,0,n),e.right(t,i,0,n)]})(d));var e,i}function L(t){return X((e=n,r=(i=t)[0],a=i[1],D=function(t){var i=t.length;return[e.left(t,r,0,i),e.left(t,a,0,i)]})(d));var e,i,r,a}function G(){return X((D=m)(d))}function N(t){return D=m,U(E=t),H=0,$=s,T}function U(t){var e,i,n,r=[],a=[];for(e=0;e<s;++e)!(f[i=A[e]]&C)^!!(n=t(d[e],e))&&(n?(f[i]&=W,r.push(i)):(f[i]|=C,a.push(i)));g.forEach(function(t){t(C,r,a)})}function K(t){var i={top:function(t){var e=u(G(),0,n.length,t);return c.sort(e,0,e.length)},all:G,reduce:N,reduceCount:U,reduceSum:function(t){return N(w(t),k(t),y)},order:K,orderNatural:function(){return K(e)},size:function(){return T},dispose:I,remove:I};q.push(i);var n,l,u,c,m,z,O,P=8,E=_(P),T=0,j=v,D=v,H=!0,$=t===v;function Y(e,i,a,o){var u,d,c,y,x,b,w=n,k=S(T,E),z=m,M=O,A=T,C=0,F=0;for(H&&(z=M=v),n=new Array(T),T=0,l=A>1?h(l,s):S(s,E),A&&(c=(d=w[0]).key);F<o&&!((y=t(e[F]))>=y);)++F;for(;F<o;){for(d&&c<=y?(x=d,b=c,k[C]=T,(d=w[++C])&&(c=d.key)):(x={key:y,value:M()},b=y),n[T]=x;!(y>b||(l[u=i[F]+a]=T,f[u]&W||(x.value=z(x.value,r[u])),++F>=o));)y=t(e[F]);q()}for(;C<A;)n[k[C]=T]=w[C++],q();if(T>C)for(C=0;C<a;++C)l[C]=k[l[C]];function q(){++T===E&&(k=p(k,P<<=1),l=p(l,P),E=_(P))}u=g.indexOf(j),T>1?(j=B,D=V):(!T&&$&&(T=1,n=[{key:null,value:M()}]),1===T?(j=X,D=L):(j=v,D=v),l=null),g[u]=j}function R(){if(T>1){for(var t=T,e=n,i=S(t,t),r=0,a=0;r<s;++r)f[r]&&(i[l[a]=l[r]]=1,++a);for(n=[],T=0,r=0;r<t;++r)i[r]&&(i[r]=T++,n.push(e[r]));if(T>1)for(var r=0;r<a;++r)l[r]=i[l[r]];else l=null;g[g.indexOf(j)]=T>1?(D=V,j=B):1===T?(D=L,j=X):D=j=v}else if(1===T){if($)return;for(var r=0;r<s;++r)if(f[r])return;n=[],T=0,g[g.indexOf(j)]=j=D=v}}function B(t,e,i){if(t!==C&&!H){var a,o,s,u;for(a=0,s=e.length;a<s;++a)f[o=e[a]]&W||((u=n[l[o]]).value=m(u.value,r[o]));for(a=0,s=i.length;a<s;++a)(f[o=i[a]]&W)===t&&((u=n[l[o]]).value=z(u.value,r[o]))}}function X(t,e,i){if(t!==C&&!H){var a,o,s,l=n[0];for(a=0,s=e.length;a<s;++a)f[o=e[a]]&W||(l.value=m(l.value,r[o]));for(a=0,s=i.length;a<s;++a)(f[o=i[a]]&W)===t&&(l.value=z(l.value,r[o]))}}function V(){var t,e;for(t=0;t<T;++t)n[t].value=O();for(t=0;t<s;++t)f[t]&W||((e=n[l[t]]).value=m(e.value,r[t]))}function L(){var t,e=n[0];for(e.value=O(),t=0;t<s;++t)f[t]&W||(e.value=m(e.value,r[t]))}function G(){return H&&(D(),H=!1),n}function N(t,e,n){return m=t,z=e,O=n,H=!0,i}function U(){return N(x,b,y)}function K(t){function e(e){return t(e.value)}return u=o(e),c=a(e),i}function I(){var t=g.indexOf(j);return t>=0&&g.splice(t,1),(t=F.indexOf(Y))>=0&&F.splice(t,1),(t=M.indexOf(R))>=0&&M.splice(t,1),i}return arguments.length<1&&(t=e),g.push(j),F.push(Y),M.push(R),Y(d,A,0,s),U().orderNatural()}function I(){q.forEach(function(t){t.dispose()});var t=z.indexOf(Y);return t>=0&&z.splice(t,1),(t=z.indexOf(R))>=0&&z.splice(t,1),(t=M.indexOf(B))>=0&&M.splice(t,1),u&=W,G()}return Y(r,0,s),R(r,0,s),T},groupAll:function(){var t,e,i,n,a={reduce:d,reduceCount:c,reduceSum:function(t){return d(w(t),k(t),y)},value:function(){o&&(function(){var i;for(t=n(),i=0;i<s;++i)f[i]||(t=e(t,r[i]))}(),o=!1);return t},dispose:h,remove:h},o=!0;function l(i,n){var a;if(!o)for(a=n;a<s;++a)f[a]||(t=e(t,r[a]))}function u(n,a,s){var l,u,d;if(!o){for(l=0,d=a.length;l<d;++l)f[u=a[l]]||(t=e(t,r[u]));for(l=0,d=s.length;l<d;++l)f[u=s[l]]===n&&(t=i(t,r[u]))}}function d(t,r,s){return e=t,i=r,n=s,o=!0,a}function c(){return d(x,b,y)}function h(){var t=g.indexOf(u);return t>=0&&g.splice(t),(t=z.indexOf(l))>=0&&z.splice(t),a}return g.push(u),z.push(l),l(r,0),c()},size:function(){return s}},r=[],s=0,u=0,c=8,f=d(0),g=[],z=[],M=[];function A(e){var i=s,n=e.length;return n&&(r=r.concat(e),f=h(f,s+=n),z.forEach(function(t){t(e,i,n)})),t}return arguments.length?A(arguments[0]):t}function S(t,e){return(e<257?d:e<65537?c:f)(t)}function _(t){return 8===t?256:16===t?65536:4294967296}"undefined"!=typeof Uint8Array&&(d=function(t){return new Uint8Array(t)},c=function(t){return new Uint16Array(t)},f=function(t){return new Uint32Array(t)},h=function(t,e){if(t.length>=e)return t;var i=new t.constructor(e);return i.set(t),i},p=function(t,e){var i;switch(e){case 16:i=c(t.length);break;case 32:i=f(t.length);break;default:throw new Error("invalid array width!")}return i.set(t),i}),t.crossfilter=z}(e||f)}(h={exports:{}},h.exports),h.exports).crossfilter;function g(t){return function(e){return e[t]}}function m(t,i){!e.isArray(t)&&arguments.length||(t={store:i,data:t||[],dimensions:{}}),Object.defineProperties(this,{_inner:{get:function(){return t}},store:{get:function(){return t.store}},data:{get:function(){return t.data}},dimensions:{get:function(){return t.dimensions}},type:{get:function(){return"dataframe"}},columns:{get:function(){var e,i;return t.columns||(t.columns=(e=t.data,i=new Set,e.forEach(function(t){Object.keys(t).forEach(function(t){return i.add(t)})}),Array.from(i).sort())),t.columns}}})}m.prototype={constructor:m,dataFrame:function(){return this},size:function(){return this.data.length},new:function(t){return e.isArray(t)?new m(t,null,this.store):new m(this._inner,t)},cf:function(){return this._inner.cf||(this._inner.cf=p(this.data)),this._inner.cf},dimension:function(t,e,i){1===arguments.length&&(i=!0);var n=this.dimensions[t];if(n){if(i)return n;n.dispose()}return e||(e=g(t)),this.dimensions[t]=this.cf().dimension(e),this.dimensions[t]},sortby:function(t,e){return this.new(this.dimension(t).top(e||1/0))},pivot:function(t,e,i,n){var r=this.dimension(t).group();return n||(n="total"),this.new(r.reduce(a(1),a(-1),Object).all().map(function(t){return t.value}));function a(r){var a=void 0,o=void 0;return function(s,l){return a=""+l[e],o=r*l[i],s[t]=l[t],a in s?s[a]+=o:s[a]=o,n in s?s[n]+=o:s[n]=o,s}}},add:function(){},map:function(t){return this.new(this.data.map(t))}};var v={schema:{type:"object",description:"array of data",properties:{data:{type:"array",description:"array of data"}}},initialise:function(t){this._data=t.data},getConfig:function(t){return e.isArray(t)?{data:t}:e.isObject(t)&&e.isArray(t.data)?t:void 0},getData:function(){return this.asFrame(this._data)}},y="[d3-data-source]";function x(t){n.viewProviders.logger.warn(y+" "+t)}var b=["http","https","ws","wss"];var w=i.set(["text/plain","text/csv","application/vnd.ms-excel"]),k={schema:{type:"object",description:"Remote data resource",properties:{url:{type:"string",description:"url for fetching data"}}},getConfig:function(t){return i=t,e.isString(i)&&b.indexOf(i.split("://")[0])>-1?{url:t}:e.isObject(t)&&t.url?t:void 0;var i},initialise:function(t){this.url=t.url},getData:function(){var t=n.viewProviders.fetch,e=this;return t?t(this.url).then(z).then(function(t){return e.asFrame(t)}):(x("fetch provider not available, cannot submit"),[])}};function z(t){var e=(t.headers.get("content-type")||"").split(";")[0];return w.has(e)?t.text().then(r.csvParse):"text/tab-separated-values"===e?t.text().then(r.tsvParse):"application/json"===e?t.json():(x("Cannot load content type '"+e+"'"),[])}var S={schema:{type:"object",description:"Composite data source for combining data together",properties:{source:{type:"array",description:"Array of data sources keys",item:{type:"string"}},expression:{type:"string",description:"expression to evaluate, must return a data frame or a Promise"}}},initialise:function(t){this.source=t.source,this.expression=t.expression?n.viewExpression(t.expression):null},getConfig:function(t){if(e.isObject(t)&&t.source)return e.isArray(t.source)||(t.source=[t.source]),t},getData:function(t){var i=this.store,n=this.source,r=this.expression,a=this;return Promise.all(n.map(function(e){return i.getData(e,t)})).then(function(o){var s=void 0;if(1===o.length?s=o[0]:a.config.merge?s=a.mergeFrames(o):(s=new _(i),o.forEach(function(t,e){s.frames.set(n[e],t)})),r){var l=i.model.$child(e.assign({},t,{frame:s}));s=r.eval(l)}return e.isPromise(s)?s.then(function(t){return a.asFrame(t)}):a.asFrame(s)})},mergeFrames:function(t){return t[0]}};function _(t){this.frames=i.map(),Object.defineProperties(this,{store:{get:function(){return t}},type:{get:function(){return"frameCollection"}}})}_.prototype={new:function(t){return new m(t,this.store)},dataFrame:function(){for(var t=this.frames.values(),e=0;e<t.length;++e)if("dataframe"===t[e].type)return t[e]}};var M={schema:{type:"object",description:"Expression to evaluate by the data store",properties:{expression:{type:"string",description:"expression to evaluate, must return a data frame or a Promise"}}},initialise:function(t){this.expression=n.viewExpression(t.expression)},getConfig:function(t){if(e.isObject(t)&&t.expression)return t},getData:function(t){var i=this,n=this.store.model.$child(t),r=this.expression.eval(n);return e.isPromise(r)?r.then(function(t){return i.asFrame(t)}):i.asFrame(r)}};function A(t){var e=t.transform,i=t.schema||{},r=n.viewProviders.jsonValidator?n.viewProviders.jsonValidator(t.schema):O;function a(t){return r.validate(t)?function(i){return e(i,t)}:r.logError()}return i.type||(i.type="object"),a.schema=i,a}var O={validate:function(){return!0}},P=A({schema:{description:"The filter transform removes objects from a data frame based on a provided filter expression",properties:{expr:{type:"string"}},required:["expr"]},transform:function(t,e){var i=n.viewExpression(e.expr);return t.data.reduce(function(e,n,r){return i.safeEval({d:n,index:r,frame:t})&&e.push(n),e},[])}}),E="[d3-visualize]";function T(t,e){n.viewProviders.logger.warn(E+" "+t),e&&n.viewProviders.logger.error(e.stack)}var C=i.map({count:j,max:a.max,min:a.min,sum:a.sum,mean:a.mean,median:a.median,variance:a.variance,deviation:a.deviation}),W=i.map({count:function(t){return t+1},sum:function(t,e){return t+e},max:Math.max,min:Math.min});function j(t,e){return t.reduce(function(t,i){return void 0!==e(i)&&(t+=1),t},0)}var D={dataSource:null,size:{width:null,height:"70%"},dateFormat:"%d-%b-%y"},F={date:function(t){return o.utcParse(t.dateFormat||D.dateFormat)},number:function(){return parseFloat}},q=A({shema:{description:"map a field values into another type",properties:{fields:{type:"object"},dateFormat:{type:"string"}},required:["fields"]},transform:function(t,n){var r=[],a=void 0,o=void 0;return i.map(n.fields).each(function(t,i){e.isString(t)&&(t={type:t}),(o=F[t.type])?r.push([i,o(t)]):T("Cannot convert field "+i+" to type "+t.type)}),r.length&&(t=t.map(function(t){for(a=0;a<r.length;++a)t[r[a][0]]=r[a][1](t[r[a][0]]);return t})),t}});function H(t,e,i){return void 0!==i&&(t=Math.min(t,i)),void 0===e?t:Math.max(t,e)}var $=.999999,Y=A({shema:{description:"Create moving average series from existing one. The new series override the existing one unless the as array is provided",properties:{method:{type:"string"},alpha:{type:"number"},period:{type:"number"},fields:{type:"array",items:{type:"string"}},as:{type:"array",items:{type:"string"}}},required:["fields"]},transform:function(t,e){var i=e.as||[],n=e.method||"ema",r=void 0,a=void 0,o=void 0;e.fields.forEach(function(s,l){if(r=i[l]||s,"sma"===n){var u=Math.max(e.period||10,1),d=[],c=[];t.data.forEach(function(t,e){a=t[s],d.length===u&&(a-=c.splice(0,1)[0]),c.push(a),e&&(a+=d[d.length-1]),d.push(a),t[r]=a/d.length})}else{var f=H(e.alpha||.5,1-$,$);t.data.forEach(function(t,e){a=t[s],o=e?f*o+(1-f)*a:a,t[r]=o})}})}}),R=A({schema:{description:"Group entries which are below a given aggregate cutoff",properties:{field:{type:"string"},cutoff:{type:"number"}},required:["field","cutoff"]},transform:function(t,e){var i=g(e.field),n=a.sum(t.data,i),r=[],o=0;return t.dimension(e.field).bottom(1/0).reduce(function(t,a){return(o+=i(a))/n<e.cutoff?r.push(a):r?(r.push(a),(a={label:"other",children:r})[e.field]=o,r=null,t.push(a)):t.push(a),t},[])}}),B=A({schema:{description:"Perfrom a difference for a group of fields along a dimension. It is possible to perform a difference for different groups",properties:{dimension:{type:"string"},period:{type:"integer",minimum:1},fields:{type:"array",items:{type:"string"}},as:{type:"array",items:{type:"string"}},groupby:{type:"string"}},required:["dimension","fields"]},transform:function(t,i){var n=i.as||[],r=i.period||1,a=[];if(i.groupby){var o=t.dimension(i.groupby);o.group().all().forEach(function(e){return s(t.new(o.filterAll().filter(e.key).top(1/0)))})}else s(t.new());return a;function s(t){var o=t.dimension(i.dimension),s=i.fields.reduce(function(t,e){return t[e]=0,t},{}),l=[],u=void 0,d=void 0;o.top(1/0).forEach(function(t,o){u=e.assign({},t),l.push(t),d=o>r?l.splice(0,1)[0]:s,i.fields.forEach(function(e,i){t[n[i]||e]=t[e]-d[e]}),a.push(u)})}}}),X=e.assign(i.map({filter:P,aggregate:function(t){var i,n,r,a=t.fields,o=t.ops,s=t.as,l=t.groupby;return a||o?e.isArray(a)?(o||(o="count"),e.isString(o)&&(i=a.length,n=o,(r=new Array(i)).fill(n),o=r),e.isArray(o)?(o.length<a.length&&T("Aggregate transforms expects an ops array with same length as fields"),s||(s=[]),e.isArray(s)?function(t){var e,i,n,r,u,d,c,f=[];return l?(n=t,r=void 0,u=void 0,d=void 0,c=a.map(function(t,e){return u=o[e],d=W.get("count"),u&&((d=W.get(u))||(d=W.get("count"),T("Operation "+u+" is not supported, use count"))),{field:t,as:s[e]||t,op:d}}),n.dimension(l).group().reduce(function(t,e){return c.reduce(function(t,i){return r=0,i.as in t&&(r=t[i.as]),t[i.as]=i.op(r,e[i.field]),t},t)},null,Object).all().map(function(t){return t.value[l]=t.key,t.value})):(a.forEach(function(n,r){e=o[r],i=j,e&&((i=C.get(e))||(i=j,T("Operation "+o[r]+" is not supported, use count"))),f.push({label:s[r]||n,data:i(t.data,function(t){return t[n]})})}),f)}:T("Aggregate transform expects an array of as fields")):T("Aggregate transform expects an array of ops")):T("Aggregate transforms expect an array of fields"):function(t){var e=void 0;return t.data.reduce(function(t,i){for(e in i)e in t?t[e]+=1:t[e]=1;return t},{})}},mapfields:q,timeseries:function(t){var e=t.sortby,i=t.groupby;return e||T('timeseries transform requires a "sortby" entry'),function(t){if(e){if(i){var n,r=t.dimension(i),a=r.group().top(1/0),o=t.new([]);return a.forEach(function(i){n=t.new(r.filterExact(i.key).top(1/0)).dimension(e).group().top(1/0),o.series.set(i.key,t.new(n).dimension("key").top(1/0))}),o}return t.new(t.dimension(e).top(1/0))}return t}},crossfilter:function(t){var i=t.fields,n=t.query;return e.isArray(i)?e.isArray(n)?n.length!=i.length?T("crossfilter transform expects an query array with same length as fields"):function(t){var r=void 0,a=void 0;return i.forEach(function(i,o){a=n[o],e.isString(a)&&(a=t.store.eval(a)),r=t.dimension(i).filterAll(),a&&r.filter(a)}),r?t.new(r.top(1/0)):t}:T("crossfilter transform expects an array of query"):T("crossfilter transform expects an array of fields")},movingaverage:Y,groupsmall:R,diff:B}),{add:function(t,e){this.set(t,A(e))}});function V(t,i){return i?function t(i,n,r){e.isArray(r)?i=i.new(r):r&&(i=r);if(n.length){var a=n.splice(0,1)[0],o=a?a(i):null;return e.isPromise(o)?o.then(function(e){return t(i,n,e)}):t(i,n,o)}return i}(t,i.slice()):t}var L=s.dispatch("init","data","remove"),G={schema:{properties:{}},getConfig:function(){},initialise:function(){},getData:function(){},addTransforms:function(t){var i=this,n=void 0;t&&(e.isArray(t)||(t=[t]),t.forEach(function(t){(n=X.get(t.type))?i.transforms.push(n(t)):T('Transform type "'+t.type+'" not known')}))},asFrame:function(t){return t&&!e.isArray(t)&&t.constructor!==m&&(t=[t]),e.isArray(t)&&(t=new m(t=t.map(function(t){return t.constructor!==Object&&(t={data:t}),t}),this.store)),V(t,this.transforms)}},N=e.assign(i.map(),{events:L,add:function(t,i){function n(i,n){var r,a,o,s,l,u;r=this,a=t,o=i,l=(s=n).dataName(e.pop(o,"name")),u=[],Object.defineProperties(r,{name:{get:function(){return l}},store:{get:function(){return s}},type:{get:function(){return a}},transforms:{get:function(){return u}},config:{get:function(){return o}}}),r.initialise(o),r.addTransforms(e.pop(o,"transforms")),s.sources.set(l,r),L.call("init",void 0,r)}return n.prototype=e.assign({},G,i),n.prototype.constructor=n,this.set(t,n),n},create:function(t,e){for(var i,n=this.values(),r=0;r<n.length;++r)if(i=n[r].prototype.getConfig(t))return new n[r](i,e)}});function U(t){var r=i.map();Object.defineProperties(this,{sources:{get:function(){return r}}}),this.transforms=e.assign({},X),this.dataCount=0,this.model=t&&e.isFunction(t.$child)?t:n.viewModel(t)}N.add("array",v),N.add("remote",k),N.add("composite",S),N.add("expression",M),U.prototype={size:function(){return this.sources.size()},addSources:function(t){if(e.isString(t)&&(t={source:t}),e.isArray(t)){var i=this;return t.map(function(t){return N.create(t,i)})}if(t)return N.create(t,this)},addTransforms:function(t){e.assign(this.transforms,t)},source:function(t,e){if(1===arguments.length)return this.sources.get(t);if(null===e){var i=this.sources.get(t);return this.sources.remove(t),L.call("remove",this,i),i}return this.sources.set(t,e),this},clearCache:function(){this.sources.each(function(t){delete t.cachedFrame})},getData:function(t,i){var n=this.sources.get(t);if(!n)throw new Error('data source "'+t+'" not available in datastore');if(n.cachedFrame)return Promise.resolve(n.cachedFrame);var r=n.getData(i);return e.isPromise(r)||(r=Promise.resolve(r)),r.then(function(t){return n.config.cache&&(n.cachedFrame=t),n.lastFrame=t,L.call("data",n.store,n,t),t})},eval:function(t,e){var i=this.model.$child(e);return i.dataStore=this,n.viewExpression(t).safeEval(i)},onData:function(t,e){var i=this,n=t.split(".")[0],r=this.sources.get(n);r&&r.lastFrame&&e(r.lastFrame),L.on("data."+t,function(t,r){t.store===i&&t.name===n&&e(r)})},dataName:function(t){return this.dataCount++,t?""+t:this.source("default")?"source"+this.dataCount:"default"}};var K=400,I="75%";function Z(t,e){return"string"==typeof t&&t.indexOf("%")===t.length-1?(i=.01*parseFloat(t)*e,n?Math.round(i*(n=Math.pow(10,n)))/n:Math.round(i)):+t;var i,n}function J(t,e){var i={width:e.width,height:e.height};return i.width||(i.width=function(t){var e=Q(t,"width");if(e)return i=e,n=i.getBoundingClientRect().width,r=u.select(i),a=tt(r.style("padding-left")),o=tt(r.style("padding-right")),n-a-o;var i,n,r,a,o}(t),i.width?i.widthElement=Q(t,"width"):i.width=K),i.height||(i.height=function(t){var e=Q(t,"width");if(e)return i=e,n=i.getBoundingClientRect().height,r=u.select(i),a=tt(r.style("padding-top")),o=tt(r.style("padding-bottom")),n-a-o;var i,n,r,a,o}(t),i.height?i.heightElement=Q(t,"height"):i.height=I),i.height=H(Z(i.height,i.width),void 0,window.innerHeight),i}function Q(t,e){for(var i=t.node?t.node():t;i&&"BODY"!==i.tagName;){if(i.getBoundingClientRect()[e])return i;i=i.parentNode}}function tt(t){return t&&"px"==t.substring(t.length-2)?+t.substring(0,t.length-2):0}function et(t){if(e.isArray(t))return t.map(et);if(e.isObject(t)){var i={};for(var n in t)i[n]=et(t[n]);return i}return t}var it=["visual","container"],nt={live:[],types:{},papers:{},options:D,schema:{title:"Visualize Specification Language",type:"object",definitions:{size:{oneOf:[{type:"number",description:"size in pixels",minimum:0},{type:"string",description:"Size as a percentage"}]}}},events:s.dispatch("before-init","after-init","resize","before-draw","after-draw")};var rt={initialise:function(){},draw:function(){},redraw:function(t){if(this.drawing){var e=this,i="after-draw."+this.toString();nt.events.on(i,function(){nt.events.on(i,null),e.redraw(t)})}else this.drawing=this.draw(t);return this.drawing},destroy:function(){},toString:function(){return this.visualType+"-"+this.model.uid},getModel:function(t){t||(t=this.visualType);var i=this.model[t];if(!i&&t in D){var n=e.pop(this.options,t),r=this;this.visualParent?i=this.visualParent.getModel(t).$child(n):(i=this.model.$new(D[t])).$update(n),this.model[t]=i,i.$on(function(){return r.redraw(!1)})}return i},idname:function(t){return t||(t=this.visualType),t+"-"+this.model.uid},modelProperty:function(t,e){var i=this.getModel()[t];return void 0===i?e[t]:i},dim:function(t,e,i,n){return H(Z(t,e),i,n)},pop:function(t){if(t){var e=t.live.indexOf(this);e>-1&&t.live.splice(e,1)}},getVisualSchema:function(t){var i=this.options.visuals?this.options.visuals[t]:null,n=this.visualParent;if(n&&e.isString(i)?(t=i,i=n.getVisualSchema(t)):n&&!i&&(i=n.getVisualSchema(t)),e.isObject(i))return et(i)}};function at(t,i){var r=e.pop(i,"schema");function a(e,i,r,a){Object.defineProperties(this,{visualType:{get:function(){return t}},isViz:{get:function(){return-1===it.indexOf(t)}},visualRoot:{get:function(){return this.visualParent?this.visualParent.visualRoot:this}},name:{get:function(){return this.toString()}}}),this.visualParent=r,this.model=r?r.model.$new():a||n.viewModel(),this.options=i||{},this.drawing=!1,nt.events.call("before-init",void 0,this),this.initialise(e),nt.events.call("after-init",void 0,this)}return r&&(nt.options[t]=function(t){var e,i,n={},r=void 0,a=void 0,o=void 0;for(o in t)(a=t[o]).$ref&&(e=a.$ref,i=e.split("/"),a=nt.schema.definitions[i[i.length-1]]||{}),r=a.default,n[o]=void 0===r?null:r;return n}(r),nt.schema.definitions[t]={type:"object",properties:e.assign({data:{$ref:"#/definitions/data"}},r)}),a.prototype=e.assign({},n.viewBase,rt,i),a.prototype.constructor=a,nt.types[t]=a,a}var ot=at("visual",{schema:{render:{type:"string",enum:["canvas","svg"],default:"svg"},width:{description:"Width of the visual",$refs:"#/definitions/size"},height:{description:"Height of the visual",$refs:"#/definitions/size",default:"70%"}},initialise:function(t){if(!t)throw new Error("HTMLElement required by visual group");if(this.visualParent&&"container"!==this.visualParent.visualType)throw new Error("Visual parent can be a container only");this.select(t).select(".paper").node()||this.select(t).append("div").classed("paper",!0),Object.defineProperties(this,{element:{get:function(){return t}},paperElement:{get:function(){return this.sel.select(".paper")}},sel:{get:function(){return this.select(t)}},size:{get:function(){return[this.width,this.height]}}}),this.sel.classed("d3-visual",!0),this.layers=[],this.drawCount=0,nt.live.push(this),t.__visual__=this,this.visualParent&&this.visualParent.live.push(this)},activate:function(){this.layers.forEach(function(t){return t.activate()})},deactivate:function(){this.layers.forEach(function(t){return t.deactivate()})},getVisual:function(){return this},draw:function(t){if(this.drawing)return T(this.toString()+" already drawing"),this.drawing;this.drawCount?(this.drawCount++,this.clear()):(this.drawCount=1,this.fit());var e=this;return nt.events.call("before-draw",void 0,this),Promise.all(this.layers.map(function(e){return e.redraw(t)})).then(function(){delete e.drawing,nt.events.call("after-draw",void 0,e)},function(t){delete e.drawing,T("Could not draw "+e.toString()+": "+t,t)})},clear:function(){},addVisual:function(t){var i=e.pop(t,"type"),n=nt.types[i];if(n)return new n(this.element,t,this);T('Cannot add visual "'+i+'", not available')},fit:function(){return this.resize(null,!0),this},resize:function(t,e){t||(t=J(this.element.parentNode||this.element,this.getModel()));var i=this.size;return(e||i[0]!==t.width||i[1]!==t.height)&&(e||this.logDebug("resizing"),this.width=t.width,this.height=t.height,this.paperElement.style("height",this.height+"px"),nt.events.call("resize",void 0,this),e||this.draw(!1)),this},paper:function(){var t=this.__paper,e=this.getModel().render;if(t&&t.paperType===e)return t;var i=nt.papers[e];if(!i)throw new Error("Unknown paper "+e);return t=new i(this),this.__paper=t,t},getPaperGroup:function(t){return this.paper().group(t)},destroy:function(){this.pop(this.visualParent),this.pop(nt)}});e.inBrowser&&new MutationObserver(function(t){var e=void 0,i=void 0;t.forEach(function(t){if((e=t.removedNodes)&&e.length)for(var n=0;n<e.length;++n)(i=e[n]).querySelectorAll&&(i.__visual__?st.call(i):u.select(i).selectAll(".d3-visual").each(st))})}).observe(document.documentElement,{childList:!0,subtree:!0});function st(){var t=this.__visual__;t?(t.destroy(),t.logDebug("removed from DOM, "+nt.live.length+" live visuals left")):T("d3-visual without __visual__ object")}function lt(t){var i,r,a;n.viewProviders.visualPlugins&&(i=n.viewProviders.visualPlugins,r=void 0,a=void 0,Object.keys(i).forEach(function(t){r=i[t].options,a=i[t].prototype,r&&(nt.options[t]=r),a&&e.assign(ut,a)}),n.viewProviders.visualPlugins=null);for(var o=[{},ut,dt],s=1;s<arguments.length;++s)o.push(arguments[s]);return at(t,e.assign.apply(void 0,o))}var ut={$:null,initialise:function(t){var i=this.visualParent;if(void 0!==this.options.active?this.active=e.pop(this.options,"active"):this.active=!0,i){if(!i.layers)throw new Error("visual parent of "+this.visualType+" does not have layers")}else this.visualParent=i=new ot(t,this.options,null,this.model),this.model=i.model.$new(),this.options={};i.layers.push(this)},paper:function(){if(this.paperType){if(!this._paper){var t=nt.papers[this.paperType];if(!t)throw new Error("Unknown paper "+this.paperType);this._paper=new t(this)}return this._paper}return this.visualParent.paper()},activate:function(t){return this.active||(this.active=!0,this.group().transition(this.model.uid).on("end",function(){t&&t()}).style("opacity",1)),this},deactivate:function(t){return this.active&&(this.active=!1,this.group().transition(this.model.uid).on("end",function(){t&&t()}).style("opacity",0)),this},getVisual:function(){return this.visualParent.getVisual()},group:function(t){var e=this.visualType+"-"+this.model.uid,i=this.visualParent.getPaperGroup(e);return t&&t!==this.visualType?this.paper().childGroup(i,t):i},translate:function(t,i){return e.isFunction(t)?function(e){return"translate("+(t(e)||0)+", "+(i(e)||0)+")"}:"translate("+t+", "+i+")"},getD3:function(t,e){return this.$[""+t+e[0].toUpperCase()+e.substring(1)]},displayError:function(){}},dt={draw:function(t){var e=this;if(this.drawing)return T(this.toString()+" already drawing"),this.drawing;var i=this,r=this.doDraw;if(this.paper().size(this.boundingBox(!0)),this.active){if(nt.events.call("before-draw",void 0,this),!1!==t||!this._drawArgs)return Promise.all([this.requires?n.viewProviders.require.apply(void 0,this.requires):[],this.getData()]).then(function(t){delete i.drawing;var n=t[1];return!!n&&(e.$=t[0],e.frame=n,r.apply(i),nt.events.call("after-draw",void 0,i),!0)},function(t){return delete i.drawing,i.logWarn("Could not draw "+i.toString()+": "+t),i.logError(t),e.displayError(t),!1});delete i.drawing,r.apply(i,this._drawArgs),nt.events.call("after-draw",void 0,i)}}};function ct(t,i){function r(e,i){var n=this.initialise(e,i);Object.defineProperties(this,{element:{get:function(){return n}},sel:{get:function(){return this.select(n)}},paperType:{get:function(){return t}}})}return r.prototype=e.assign({},n.viewBase,ft,i),nt.papers[t]=r,r}var ft={initialise:function(){},transition:function(){},size:function(t){return this.sel.attr("width",t.width).attr("height",t.height),this},group:function(t,e){return this.childGroup(this.sel,t,e)},childGroup:function(t,e,i){e||(e="main");var n=t.selectAll("."+e).data([0]).enter().append("g").classed(e,!0);return i&&n.attr("transform",i).merge().attr("transform",i),t.select("."+e)},dim:function(t){return t}},ht=ct("svg",{initialise:function(t,e){e||t.model.uid;var i=t.paperElement.select("svg#"+e);return i.size()||(i=t.paperElement.append("svg").attr("id",e).classed(t.visualType,!0).style("position","absolute")),i.node()}}),pt=ct("div",{initialise:function(t){var e=t.model.uid,i=t.visualParent,n=i.paperElement.select("div#"+e);return n.size()||(n=i.paperElement.append("div").attr("id",e).classed(i.visualType,!0).style("position","absolute")),n.node()},size:function(t){return this.sel.style("width",t.width+"px").style("height",t.height+"px"),this},childGroup:function(t,e){return e||(e="main"),t.selectAll("."+e).data([0]).enter().append("div").classed(e,!0),t.select("."+e)}});ut.getScale=function(t){e.isString(t)&&(t={type:t});var i,n,r=this.getD3("scale",t.type)();return i=r,((n=t).$events?n.$events.keys():Object.keys(n)).forEach(function(t){e.isFunction(i[t])&&i[t](n[t])}),i},D.menu={display:!1,height:"8%",maxHeight:50,minHeight:20},nt.events.on("after-init.menu",function(t){"visual"===t.visualType&&(t.getModel("menu").display&&(t.menu=t.sel.insert("nav",":first-child").classed("d3-nav navbar p-1",!0),t.menu.append("h4").classed("title",!0)))}),nt.events.on("before-draw.menu",function(t){var e,i,n;t&&t.menu&&(i=(e=t).getModel("menu"),n=e.dim(i.height,e.height,i.minHeight,i.maxHeight),e.menu.style("height",n+"px"))}),e.assign(nt.schema.definitions,{data:{type:"array",items:{$ref:"#/definitions/dataSource"}},dataSource:{oneOf:N.values().map(function(t){var e=t.prototype.schema;return e.properties.transforms={$ref:"#/definitions/transforms"},e})}}),ut.getData=function(){var t=this.model.data;if(t)try{return this.dataStore.getData(t,{$visual:this})}catch(t){return void this.logError(t)}else this.logWarn("no data name - cannot get data")},ut.getContext=function(t){return this.dataStore.model.$child(t)},nt.events.on("before-init.data",function(t){t.isViz&&(t.data=e.pop(t.options,"data"))}),nt.events.on("after-init.data",function(t){Object.defineProperties(t,{dataStore:{get:function(){return t.model.root.dataStore}}}),t.isViz?function(t){var i=t.dataStore,n=e.pop(t,"data");if(!n)return;e.isString(n)&&(n={source:n});n.name||(n.name=t.model.uid);(n=i.addSources(n))?t.model.$set("data",n.name):t.logWarn("could not create data source "+n.name)}(t):function(t){var i=t.dataStore,n=e.pop(t.options,"data");i||(i=new U(t.getModel("dataContext")),t.model.root.dataStore=i);i.addSources(n)}(t)});var gt=i.map();function mt(t,e){var i=gt.get(t);return i||(i=d.format(t),gt.set(t,i)),2==arguments.length?i(e):i}var vt=i.map();function yt(t,e){var i=vt.get(t);return i||(i=o.timeFormat(t),vt.set(t,i)),2==arguments.length?i(e):i}if(nt.options.dataContext={$format:mt,$formatTime:yt},ut.format=function(t){var e=this.dataStore.eval(t);if(e)return e;try{return mt(t)}catch(e){return yt(t)}},nt.options.font={size:"3%",minSize:10,maxSize:20,stroke:"#333",family:null},ut.font=function(t,e){e=e||this.getModel("font");var i=this.getModel(),n=this.dim(e.size,t.height,e.minSize,e.maxSize);return i.fontSizeMultiplier&&(n*=i.fontSizeMultiplier),n},D.resizeDelay||(D.resizeDelay=200),e.inBrowser){var xt=n.viewDebounce(function(){nt.live.forEach(function(t){return t.resize()})},D.resizeDelay);u.select(window).on("resize.visuals",xt)}D.title={text:null,size:"3%",minSize:15,maxSize:25,offset:["10%",0]},nt.events.on("before-init.title",function(t){var i=t.options.title;e.isString(i)&&(t.options.title={text:i})}),nt.events.on("after-draw.title",function(t){var e,i,n,r,a,o,s=t.getModel("title"),l=t;if("visual"===l.visualType)delete l.__title;else{if(!t.isViz)return;l=t.visualParent}if(s.text)if(l.menu&&!l.__title)l.__title=s,i=s,o=(e=l).menu.style("height"),n=+o.substring(0,o.length-2),r=i.maxSize?Math.min(n-4,i.maxSize):n-4,a=e.dim(i.size,e.width,i.minSize,r),e.menu.select(".title").html(i.text).style("font-size",a+"px").style("line-height",n+"px");else if(t.isViz){var u=t.boundingBox(!0),d=t.getModel("font"),c=s.stroke||d.stroke,f=t.font(u,s),h=t.group().selectAll("text.chartitle").data([s.text]),p=t.dim(s.offset[0],u.vizHeight),g=t.dim(s.offset[1],u.vizWidth),m=t.translate(u.margin.left+u.innerWidth/2+g,p);h.enter().append("text").classed("chartitle",!0).attr("transform",m).style("text-anchor","middle").style("font-size",f).style("fill",c).text(function(t){return t}).merge(h).transition().attr("transform",m).style("font-size",f).style("fill",c).text(function(t){return t})}});var bt=["top","bottom","left","right"],wt=["left","right"];function kt(t,i){var n=i.options[t];void 0===n||e.isObject(n)||(i.options[t]=Mt(n||0))}function zt(t,e,i){return bt.reduce(function(n,r){return n[r]=Z(t[r],wt.indexOf(r)>-1?e:i),n},{})}function St(t){delete t.__boundingBox,e.isArray(t.layers)&&t.layers.forEach(St)}function _t(){return{width:this.innerWidth,height:this.innerHeight,margin:Mt(0),padding:Mt(0),total:Mt(0),innerWidth:this.innerWidth,innerHeight:this.innerHeight,$nomargins:this.$nomargins}}function Mt(t){return{left:t,right:t,top:t,bottom:t}}D.margin={top:20,bottom:20,left:20,right:20},D.padding={top:0,bottom:0,left:0,right:0},ut.boundingBox=function(t){if(t&&St(this),!this.__boundingBox){var e=this.visualParent.width,i=this.visualParent.height,n=zt(this.getModel("padding"),e,i),r=e-n.left-n.right,a=i-n.top-n.bottom,o=zt(this.getModel("margin"),r,a),s=bt.reduce(function(t,e){return t[e]=o[e]+n[e],t},{});this.__boundingBox={margin:o,padding:n,total:s,width:e,height:i,vizWidth:r,vizHeight:a,innerWidth:e-s.left-s.right,innerHeight:i-s.top-s.bottom,$nomargins:_t}}return this.__boundingBox},nt.events.on("after-init.margin",function(t){t.margin=kt("margin",t),t.padding=kt("padding",t)}),nt.events.on("before-draw.margin",function(t){t.isViz&&St(t)});var At={ticks:5,tickSize:6,tickSizeOuter:null,rotate:null,ancor:"end",format:null,timeFormat:"%Y-%m-%d",stroke:"#333",hide:null,title:null,titleRotate:null,titleOffset:.7};function Ot(t,e,i){t.select("path.domain").attr("stroke",e.stroke);var n=t.selectAll("text").attr("fill",e.stroke);if(e.hide){var r=i.range();Math.abs(r[0]-r[r.length-1])<e.hide?t.style("opacity",0):t.style("opacity",1)}e.rotate&&n.attr("transform","rotate("+e.rotate+")").style("text-anchor",e.ancor)}nt.options.xAxis=e.assign({location:"bottom"},At),nt.options.yAxis=e.assign({location:"left"},At),ut.getAxis=function(t,e){return this.getD3("axis",t)(e)},ut.xAxis1=function(t,e,i,n){var r=this.getModel("xAxis"),a=this._axis(t,e,r,n),o=this.group("x-axis");return this.applyTransform(o,this.translateAxis(t,i)),Ot(o.transition(this.transition("x-axis")).call(a),r,e),r.title&&this.axisTitle(o,t,e,i,r),o},ut.yAxis1=function(t,e,i,n){var r=this.getModel("yAxis"),a=this._axis(t,e,r,n),o=this.group("y-axis");return this.applyTransform(o,this.translateAxis(t,i)),Ot(o.transition(this.transition("x-axis")).call(a),r,e),r.title&&this.axisTitle(o,t,e,i,r),o},ut.axisTitle=function(t,e,i,n,r){var a=t.selectAll("text.title").data([r.title]),o=r.titleRotate||0,s=0,l=0;o||"right"!==e&&"left"!==e||(o=-90),"left"==e&&(s=-r.titleOffset*n.margin.left,l=n.innerHeight/2);var u="translate("+s+","+l+") rotate("+o+")",d=this.font(n);a.enter().append("text").classed("title",!0).attr("transform",u).style("text-anchor","middle").style("font-size",d).style("fill",r.stroke).text(function(t){return t}).merge(a).transition().attr("transform",u).style("font-size",d).style("fill",r.stroke).text(function(t){return t})},ut.translateAxis=function(t,e){return"top"===t||"left"===t?this.translate(e.margin.left,e.margin.top):"bottom"===t?this.translate(e.margin.left,e.margin.top+e.innerHeight):this.translate(e.margin.left+e.innerWidth,e.margin.top)},ut._axis=function(t,i,n,r){var a=this.getAxis(t,i).tickSize(n.tickSize);return null!==n.tickSizeOuter&&a.tickSizeOuter(n.tickSizeOuter),e.isDate(r)?a.tickFormat(o.timeFormat(n.timeFormat)):null!==n.format&&a.tickFormat(this.format(n.format)),a.ticks(n.ticks)},ut.getSymbol=function(t){return this.$.symbol().type(this.getD3("symbol",t))},ut.getCurve=function(t){return this.getD3("curve",t)},ut.getStack=function(){var t=this.getModel(),e=this.$.stack();return t.stack&&(t.stackOrder&&e.order(this.getD3("stack",t.stackOrder)),t.stackOffset&&e.offset(this.getD3("stack",t.stackOffset))),e};var Pt=i.map();D.color={scale:"cool",scaleMinPoints:6,scaleOffset:0,stroke:"#333",strokeOpacity:1,fillOpacity:1},Pt.set("viridis",function(t){return t.scaleSequential(t.interpolateViridis)}),Pt.set("inferno",function(t){return t.scaleSequential(t.interpolateInferno)}),Pt.set("magma",function(t){return t.scaleSequential(t.interpolateMagma)}),Pt.set("plasma",function(t){return t.scaleSequential(t.interpolatePlasma)}),Pt.set("warm",function(t){return t.scaleSequential(t.interpolateWarm)}),Pt.set("cool",function(t){return t.scaleSequential(t.interpolateCool)}),Pt.set("rainbow",function(t){return t.scaleSequential(t.interpolateRainbow)}),Pt.set("cubehelix",function(t){return t.scaleSequential(t.interpolateCubehelixDefault)}),ut.getColorScale=function(t){return Pt.get(t)(this.$)},ut.colors=function(t,i){var n=this.getModel("color"),r=!1,o=void 0,s=void 0;if(e.isArray(n.scale))s=this.getScale("ordinal").range(n.scale);else{if(!(o=this.getColorScale(n.scale)))throw new Error("Unknown scale "+n.scale);e.isObject(o)||(o={scale:o}),void 0===o.minPoints&&(o.minPoints=n.scaleMinPoints),s=o.scale,r=o.reversed}if(e.isFunction(s.interpolator)){var l=n.scaleOffset,u=t+l,d=Math.max(u,o.minPoints),f=r?[d-1,0]:[0,d-1];s.domain(f);var h=void 0;return a.range(l,Math.min(u,d)).map(function(t){return(h=c.color(s(t))).opacity=i,h})}var p=s.range().slice();r&&p.reverse();for(var g=void 0,m=void 0,v=void 0,y=0;y<n.scaleOffset;++y)p.push(p.shift());return a.range(t).map(function(){return g=p.shift(),m=c.color(g),v=c.color(g),m.opacity=i,p.push(""+v.brighter(.2)),m})},ut.fill=function(t){var e=this.getModel("color"),i=this.modelProperty("fillOpacity",e),n=this.colors(t.length,i);function r(t,e){return n[e]}return r.colors=n,r},ut.stroke=function(t){var e=this.getModel("color"),i=this.modelProperty("strokeOpacity",e),n=this.colors(t.length,i);function r(t,e){return n[e]}return r.colors=n,r},ut.linearGradient=function(t,e,i,n){var r=this.paper().sel,a=r.select("defs");a.node()||(a=r.append("defs"));var o=a.selectAll("#"+n).data([0]),s=c.color(t);s.opacity=.1,o.enter().append("linearGradient").attr("id",n).attr("x1","0%").attr("y1","0%").attr("x2","vertical"===i?"0%":"100%").attr("y2","vertical"===i?"100%":"0%");var l=a.select("#"+n).selectAll("stop").data([{offset:"0%",color:t},{offset:"100%",color:s}]);return l.enter().append("stop").merge(l).attr("offset",function(t){return t.offset}).attr("stop-color",function(t){return t.color}),"url(#"+n+")"},D.legend={location:"top-right",orient:"vertical",fontSize:"3%",title:"",titleWidth:"20%",labelFormat:null,titleMinWidth:30,titleMaxWidth:60,minFontSize:10,maxFontSize:20,offset:[10,10],shapeWidth:15,shapeHeight:15,hide:300},ut.getLegend=function(t){return this.getD3("legend",t)},ut.legend=function(t,i){var n=this.getModel(),r=this.getModel("legend"),a=this.getModel("font"),o=e.pop(t,"type")||n.legendType,s=Math.max(i.vizHeight,i.vizWidth),l=this.dim(r.fontSize,s,r.minFontSize,r.maxFontSize),u=this.getLegend(o);if(r.location){if(!u)return T("Could not load legend "+o);if(u=u().orient(r.orient),r.title&&(u.title(r.title),r.titleWidth)){var d=this.dim(r.titleWidth,s,r.titleMinWidth,r.titleMaxWidth);u.titleWidth(d)}r.labelFormat&&u.labelFormat(r.labelFormat),u.shapeWidth(r.shapeWidth).shapeHeight(r.shapeHeight);for(var c in t)u[c](t[c]);var f=this.group("legend").style("font-size",l+"px").html("").call(u),h=f.node().getBBox(),p=Et.get(r.location).call(this,h,i,r),g=this.translate(p.x,p.y);f.selectAll("text").style("fill",r.stroke||a.stroke),this.applyTransform(f,g),r.hide&&(s<r.hide?f.style("opacity",0):f.style("opacity",1))}};var Et=i.map({top:function(t,e,i){var n=this.dim(i.offset[1],e.vizHeight);return{x:e.margin.left+(e.innerWidth-t.width)/2,y:n}},bottom:function(t,e,i){var n=this.dim(i.offset[1],e.vizHeight);return{x:e.margin.left+(e.innerWidth-t.width)/2,y:e.vizHeight-t.height-n}},right:function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth);return{x:e.vizWidth-t.width-n,y:e.margin.top+(e.innerHeight-t.height)/2}},left:function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth);return{x:e.margin.left-n,y:e.margin.top+(e.innerHeight-t.height)/2}},"top-left":function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth),r=this.dim(i.offset[1],e.vizHeight);return{x:e.margin.left+(e.innerWidth-t.width)/2+n,y:r}},"top-right":function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth),r=this.dim(i.offset[1],e.vizHeight);return{x:e.vizWidth-t.width-n,y:r}},"bottom-left":function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth),r=this.dim(i.offset[1],e.vizHeight);return{x:t.width+n,y:e.vizHeight-t.height-r}},"bottom-right":function(t,e,i){var n=this.dim(i.offset[0],e.vizWidth),r=this.dim(i.offset[1],e.vizHeight);return{x:e.vizWidth-t.width-n,y:e.vizHeight-t.height-r}}});function Tt(t){return function(){return t}}function Ct(t){return e.isFunction(t)?t:Tt(t)}function Wt(t){return t}var jt=i.map({darker:function(){function t(t,e){var i=t.getModel("mouse"),n=c.color(e.style("fill")),r=n.darker(i.darkerFactor),a=e.node();a.__mouse_over__.fill=n,e.style("fill",r)}return t.out=function(t,e){var i=e.node().__mouse_over__.fill;i&&e.style("fill",i)},t}(),fill:function(){function t(t,e){var i=t.getModel("mouse"),n=c.color(e.style("fill")),r=e.node();r.__mouse_over__.fill=n,e.transition().style("fill",i.fillColor)}return t.out=function(t,e){var i=e.node().__mouse_over__.fill;i&&e.transition().style("fill",i)},t}()});nt.options.mouse={over:["darker"],darkerFactor:.5,fillColor:"#addd8e"},ut.mouseOver=function(){var t=this,e=this.getModel("mouse");return function(i,n){this.__mouse_over__||(this.__mouse_over__={});var r=t.select(this),a=void 0;e.over.forEach(function(e){(a=jt.get(e))?a(t,r,i,n):T("Unknown mouse strategy "+e)})}},ut.mouseOut=function(){var t=this,e=this.getModel("mouse");return function(i,n){this.__mouse_over__||(this.__mouse_over__={});var r=t.select(this),a=void 0;e.over.forEach(function(e){(a=jt.get(e))?a.out(t,r,i,n):T("Unknown mouse strategy "+e)})}},nt.options.tooltip={location:"top",offset:[10,10],html:""},e.inBrowser?ut.tooltip=function(){var t=Ct("top"),e=Ct([0,0]),n=Ct(" "),r=null,a=null,o=i.map({top:function(t,e){var i=c(t);return{left:i.n.x-r.offsetWidth/2,top:i.n.y-r.offsetHeight-e[1]}},bottom:function(t,e,i){return{top:e.total.left+(e.innerWidth-t.width)/2,left:e.height-t.height-i.offsetY}},right:function(t,e){var i=c(t);return{left:i.e.x+e[0],top:i.e.y-r.offsetHeight/2}},left:function(t,e,i){return{x:e.total.left+(e.innerWidth-t.width)/2,y:i.offsetY}},"top-left":function(t,e,i){return{x:e.total.left+(e.innerWidth-t.width)/2,y:i.offsetY}},"top-right":function(t,e,i){return{x:e.width-t.width-i.offsetX,y:i.offsetY}},"bottom-left":function(t,e,i){return{x:e.total.left+(e.innerWidth-t.width)/2,y:e.height-t.height-i.offsetY}},"bottom-right":function(t,e,i){return{x:e.total.left+(e.innerWidth-t.width)/2,y:e.height-t.height-i.offsetY}}}),s=o.keys();function l(){return null===r&&(r=u.select(document.body).append("div").classed("d3-tooltip",!0).style("position","absolute").style("top",0).style("opacity",0).style("pointer-events","none").style("box-sizing","border-box").node(),a=u.select(document.body).append("svg").style("opacity",0).style("pointer-events","none").node().createSVGPoint()),u.select(r)}function d(){}return d.show=function(i){var r,a=Array.prototype.slice.call(arguments),u=l(),c=n.apply(this,a)||"",f=e.apply(this,a),h=t.apply(this,a),p=document.documentElement.scrollTop||document.body.scrollTop,g=document.documentElement.scrollLeft||document.body.scrollLeft;u.html(c).style("opacity",1).style("pointer-events","all");for(var m=s.length;m--;)u.classed(s[m],!1);return r=o.get(h).call(this,i,f),u.classed(h,!0).style("top",r.top+p+"px").style("left",r.left+g+"px"),d},d.hide=function(){return l().style("opacity",0).style("pointer-events","none"),d},d.location=function(e){return arguments.length?(t=null===e?e:Ct(e),d):t},d.html=function(t){return arguments.length?(n=null===t?t:Ct(t),d):n},d.offset=function(t){return arguments.length?(e=null==t?t:Ct(t),d):e},d;function c(t){for(;null==t.getScreenCTM&&null==t.parentNode;)t=t.parentNode;var e={},i=t.getScreenCTM(),n=t.getBBox(),r=n.width,o=n.height,s=n.x,l=n.y;return a.x=s,a.y=l,e.nw=a.matrixTransform(i),a.x+=r,e.ne=a.matrixTransform(i),a.y+=o,e.se=a.matrixTransform(i),a.x-=r,e.sw=a.matrixTransform(i),a.y-=o/2,e.w=a.matrixTransform(i),a.x+=r,e.e=a.matrixTransform(i),a.x-=r/2,a.y-=o/2,e.n=a.matrixTransform(i),a.y+=o,e.s=a.matrixTransform(i),e}}():ut.tooltip=Wt,jt.set("tooltip",function(){function t(t,e,i,n){var r=t.tooltipHtml(e,i,n);if(r){var a=t.getModel("tooltip");t.tooltip.location(a.location).offset(a.offset).html(r).show(e.node())}}return t.out=function(t){t.tooltip.hide()},t}()),ut.tooltipHtml=function(t,e,i){var n=this.getModel("tooltip");if(n.html)return this.dataStore.eval(n.html,{d:e,index:i,model:this.getModel()})},nt.options.expa