!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-dataflow"),require("vega-util"),require("d3-array"),require("vega-statistics"),require("vega-projection"),require("d3-geo"),require("d3-color"),require("vega-canvas")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-array","vega-statistics","vega-projection","d3-geo","d3-color","vega-canvas"],t):t(((e=e||self).vega=e.vega||{},e.vega.transforms={}),e.vega,e.vega,e.d3,e.vega,e.vega,e.d3,e.d3,e.vega)}(this,(function(e,t,n,r,a,i,o,u,s){"use strict";function l(){}const f=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function c(){var e=1,t=1,r=u;function a(e,t){return t.map(t=>i(e,t))}function i(n,a){var i=[],u=[];return function(n,r,a){var i,u,s,l,c,d,m=new Array,p=new Array;i=u=-1,l=n[0]>=r,f[l<<1].forEach(h);for(;++i=r,f[s|l<<1].forEach(h);f[l<<0].forEach(h);for(;++u=r,c=n[u*e]>=r,f[l<<1|c<<2].forEach(h);++i=r,d=c,c=n[u*e+i+1]>=r,f[s|l<<1|c<<2|d<<3].forEach(h);f[l|c<<3].forEach(h)}i=-1,c=n[u*e]>=r,f[c<<2].forEach(h);for(;++i=r,f[c<<2|d<<3].forEach(h);function h(e){var t,n,r=[e[0][0]+i,e[0][1]+u],s=[e[1][0]+i,e[1][1]+u],l=o(r),f=o(s);(t=p[l])?(n=m[f])?(delete p[t.end],delete m[n.start],t===n?(t.ring.push(s),a(t.ring)):m[t.start]=p[n.end]={start:t.start,end:n.end,ring:t.ring.concat(n.ring)}):(delete p[t.end],t.ring.push(s),p[t.end=f]=t):(t=m[f])?(n=p[l])?(delete m[t.start],delete p[n.end],t===n?(t.ring.push(s),a(t.ring)):m[n.start]=p[t.end]={start:n.start,end:t.end,ring:n.ring.concat(t.ring)}):(delete m[t.start],t.ring.unshift(r),m[t.start=l]=t):m[l]=p[f]={start:l,end:f,ring:[r,s]}}f[c<<3].forEach(h)}(n,a,(function(e){r(e,n,a),function(e){var t=0,n=e.length,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];for(;++t0?i.push([e]):u.push(e)})),u.forEach((function(e){for(var t,n=0,r=i.length;n0&&o0&&u0&&o>0||n.error("invalid size"),e=i,t=o,a},a.smooth=function(e){return arguments.length?(r=e?u:l,a):r===u},a}function d(e,t){for(var n,r=-1,a=t.length;++rr!=m>r&&n<(d-l)*(r-f)/(m-f)+l&&(a=-a)}return a}function p(e,t,n){var r,a,i,o;return function(e,t,n){return(t[0]-e[0])*(n[1]-e[1])==(n[0]-e[0])*(t[1]-e[1])}(e,t,n)&&(a=e[r=+(e[0]===t[0])],i=n[r],o=t[r],a<=i&&i<=o||o<=i&&i<=a)}function h(e,t,a){return function(i){var o=n.extent(i),u=a?Math.min(o[0],0):o[0],s=o[1],l=s-u,f=t?r.tickStep(u,s,e):l/(e+1);return r.range(f,s,f)}}function y(e){t.Transform.call(this,null,e)}function g(e,t,n,r,a){const i=e.x1||0,o=e.y1||0,u=t*n<0;function s(e){e.forEach(l)}function l(e){u&&e.reverse(),e.forEach(f)}function f(e){e[0]=(e[0]-i)*t+r,e[1]=(e[1]-o)*n+a}return function(e){return e.coordinates.forEach(s),e}}function v(e,t,n){const r=e>=0?e:a.bandwidthNRD(t,n);return Math.round((Math.sqrt(4*r*r+1)-1)/2)}function b(e){return n.isFunction(e)?e:n.constant(+e)}function x(){var e=e=>e[0],t=e=>e[1],a=n.one,i=[-1,-1],o=960,u=500,s=2;function l(n,l){const f=v(i[0],n,e)>>s,c=v(i[1],n,t)>>s,d=f?f+2:0,m=c?c+2:0,p=2*d+(o>>s),h=2*m+(u>>s),y=new Float32Array(p*h),g=new Float32Array(p*h);let b=y;n.forEach(n=>{const r=d+(+e(n)>>s),i=m+(+t(n)>>s);r>=0&&r=0&&i0&&c>0?(E(p,h,y,g,f),D(p,h,g,y,c),E(p,h,y,g,f),D(p,h,g,y,c),E(p,h,y,g,f),D(p,h,g,y,c)):f>0?(E(p,h,y,g,f),E(p,h,g,y,f),E(p,h,y,g,f),b=g):c>0&&(D(p,h,y,g,c),D(p,h,g,y,c),D(p,h,y,g,c),b=g);let x=l?Math.pow(2,-2*s):1/r.sum(b);for(let e=0,t=p*h;e>s),y2:m+(u>>s)}}return l.x=function(t){return arguments.length?(e=b(t),l):e},l.y=function(e){return arguments.length?(t=b(e),l):t},l.weight=function(e){return arguments.length?(a=b(e),l):a},l.size=function(e){if(!arguments.length)return[o,u];var t=Math.ceil(e[0]),r=Math.ceil(e[1]);return t>=0||t>=0||n.error("invalid size"),o=t,u=r,l},l.cellSize=function(e){return arguments.length?((e=+e)>=1||n.error("invalid cell size"),s=Math.floor(Math.log(e)/Math.LN2),l):1<=a&&(t>=i&&(u-=n[t-i+o*e]),r[t-a+o*e]=u/Math.min(t+1,e-1+i-t,i))}function D(e,t,n,r,a){const i=1+(a<<1);for(let o=0;o=a&&(u>=i&&(s-=n[o+(u-i)*e]),r[o+(u-a)*e]=s/Math.min(u+1,t-1+i-u,i))}function z(e){t.Transform.call(this,null,e)}y.Definition={type:"Isocontour",metadata:{generates:!0},params:[{name:"field",type:"field"},{name:"thresholds",type:"number",array:!0},{name:"levels",type:"number"},{name:"nice",type:"boolean",default:!1},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"zero",type:"boolean",default:!0},{name:"smooth",type:"boolean",default:!0},{name:"scale",type:"number",expr:!0},{name:"translate",type:"number",array:!0,expr:!0},{name:"as",type:"string",null:!0,default:"contour"}]},n.inherits(y,t.Transform).transform=function(e,a){if(this.value&&!a.changed()&&!e.modified())return a.StopPropagation;var i=a.fork(a.NO_SOURCE|a.NO_FIELDS),o=a.materialize(a.SOURCE).source,u=e.field||n.identity,s=c().smooth(!1!==e.smooth),l=e.thresholds||function(e,t,n){const a=h(n.levels||10,n.nice,!1!==n.zero);return"shared"!==n.resolve?a:a(e.map(e=>r.max(t(e).values)))}(o,u,e),f=null===e.as?null:e.as||"contour",d=[];return o.forEach(r=>{const a=u(r),i=s.size([a.width,a.height])(a.values,n.isArray(l)?l:l(a.values));!function(e,t,r,a){let i=a.scale||t.scale,o=a.translate||t.translate;n.isFunction(i)&&(i=i(r,a));n.isFunction(o)&&(o=o(r,a));if((1===i||null==i)&&!o)return;const u=(n.isNumber(i)?i:i[0])||1,s=(n.isNumber(i)?i:i[1])||1,l=o&&o[0]||0,f=o&&o[1]||0;e.forEach(g(t,u,s,l,f))}(i,a,r,e),i.forEach(e=>{d.push(t.rederive(r,t.ingest(null!=f?{[f]:e}:e)))})}),this.value&&(i.rem=this.value),this.value=i.source=i.add=d,i},z.Definition={type:"KDE2D",metadata:{generates:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"weight",type:"field"},{name:"groupby",type:"field",array:!0},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number",array:!0,length:2},{name:"counts",type:"boolean",default:!1},{name:"as",type:"string",default:"grid"}]};var S=n.inherits(z,t.Transform);const R=["x","y","weight","size","cellSize","bandwidth"];function w(e,t){return R.forEach(n=>null!=t[n]?e[n](t[n]):0),e}function j(e){t.Transform.call(this,null,e)}S.transform=function(e,r){if(this.value&&!r.changed()&&!e.modified())return r.StopPropagation;var a,i=r.fork(r.NO_SOURCE|r.NO_FIELDS),o=function(e,t){var n,r,a,i,o,u,s=[],l=e=>e(i);if(null==t)s.push(e);else for(n={},r=0,a=e.length;rt.ingest(function(e,t){for(let n=0;ne(n,t),r.dep=A(e)):e?r=n.constant(e):(r=e=>e.$value/e.$max||0,r.dep=!0);return r}(e.opacity,e),f=function(e,t){let r;n.isFunction(e)?(r=n=>u.rgb(e(n,t)),r.dep=A(e)):r=n.constant(u.rgb(e||"#888"));return r}(e.color,e),c=e.as||"image",d={$x:0,$y:0,$value:0,$max:i?r.max(a.map(e=>r.max(o(e).values))):0};return a.forEach(e=>{const t=o(e),a=n.extend({},e,d);i||(a.$max=r.max(t.values||[])),e[c]=function(e,t,r,a){const i=e.width,o=e.height,u=e.x1||0,l=e.y1||0,f=e.x2||i,c=e.y2||o,d=e.values,m=d?e=>d[e]:n.zero,p=s.canvas(f-u,c-l),h=p.getContext("2d"),y=h.getImageData(0,0,f-u,c-l),g=y.data;for(let e=l,n=0;ee.concat(function(e){return e.type===M?e.features:n.array(e).filter(e=>null!=e).map(e=>e.type===O?e:{type:O,geometry:e})}(t)),[])}}(t.fit);t.extent?e.fitExtent(t.extent,r):t.size&&e.fitSize(t.size,r)}(r,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)},e.contour=j,e.geojson=F,e.geopath=T,e.geopoint=C,e.geoshape=_,e.graticule=q,e.heatmap=P,e.isocontour=y,e.kde2d=z,e.projection=N,Object.defineProperty(e,"__esModule",{value:!0})}));