"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[5299],{885299:(t,e,r)=>{r.r(e),r.d(e,{DEFAULT_MAX_ZOOM:()=>c,DEFAULT_POINT_RADIUS:()=>b,default:()=>C});var i=r(667294),o=r(45697),s=r.n(o),n=r(490530),a=r(281458);function l(t,e){let r,i=e;return r=e?Math.round(t*(i=10**i))/i:Math.round(t),r}function g(t,e,r){const i=e*(Math.PI/180);return l(t/(40075.16*Math.cos(i)/2**(r+9)),2)}var d=r(135944);const h={aggregation:s().string,compositeOperation:s().string,dotRadius:s().number,lngLatAccessor:s().func,locations:s().arrayOf(s().object).isRequired,pointRadiusUnit:s().string,renderWhileDragging:s().bool,rgb:s().arrayOf(s().oneOfType([s().string,s().number])),zoom:s().number};class p extends i.PureComponent{constructor(t){super(t),this.redraw=this.redraw.bind(this)}drawText(t,e,r={}){const{fontHeight:i=0,label:o="",radius:s=0,rgb:n=[0,0,0],shadow:a=!1}=r,l=1.8*s,g=.2126*n[1]+.7152*n[2]+.0722*n[3];t.globalCompositeOperation="source-over",t.fillStyle=g<=110?"white":"black",t.font=`${i}px sans-serif`,t.textAlign="center",t.textBaseline="middle",a&&(t.shadowBlur=15,t.shadowColor=g<=110?"black":"");const d=t.measureText(o).width;if(d>l){const e=i/d;t.font=e*l+"px sans-serif"}const{compositeOperation:h}=this.props;t.fillText(o,e[0],e[1]),t.globalCompositeOperation=h,t.shadowBlur=0,t.shadowColor=""}redraw({width:t,height:e,ctx:r,isDragging:i,project:o}){const{aggregation:s,compositeOperation:n,dotRadius:a,lngLatAccessor:d,locations:h,pointRadiusUnit:p,renderWhileDragging:u,rgb:c,zoom:b}=this.props,m=a,w=[];h.forEach(((t,e)=>{t.properties.cluster&&(w[e]=((t,e)=>{const r=t.point_count;if(!e)return r;if("sum"===e||"min"===e||"max"===e)return t[e];const{sum:i}=t,o=i/r;if("mean"===e)return Math.round(100*o)/100;const{squaredSum:s}=t,n=s/r-(i/r)**2;return"var"===e?Math.round(100*n)/100:"stdev"===e?Math.round(100*Math.sqrt(n))/100:r})(t.properties,s))}),this);const f=Math.max(...w.filter((t=>!Number.isNaN(t))));r.clearRect(0,0,t,e),r.globalCompositeOperation=n,!u&&i||!h||h.forEach((function(i,s){const n=o(d(i)),a=[l(n[0],1),l(n[1],1)];if(a[0]+m>=0&&a[0]-m<t&&a[1]+m>=0&&a[1]-m<e)if(r.beginPath(),i.properties.cluster){let t=w[s];const e=l((t/f)**.5*m,1),i=l(.5*e,1),[o,n]=a,g=r.createRadialGradient(o,n,e,o,n,0);g.addColorStop(1,`rgba(${c[1]}, ${c[2]}, ${c[3]}, 0.8)`),g.addColorStop(0,`rgba(${c[1]}, ${c[2]}, ${c[3]}, 0)`),r.arc(a[0],a[1],e,0,2*Math.PI),r.fillStyle=g,r.fill(),Number.isFinite(parseFloat(t))&&(t>=1e4?t=`${Math.round(t/1e3)}k`:t>=1e3&&(t=Math.round(t/100)/10+"k"),this.drawText(r,a,{fontHeight:i,label:t,radius:e,rgb:c,shadow:!0}))}else{const t=m/6,e=i.properties.radius,o=i.properties.metric;let s,n=null===e?t:e;if(null!==e){const t=d(i)[1];"Kilometers"===p?(s=`${l(n,2)}km`,n=g(n,t,b)):"Miles"===p&&(s=`${l(n,2)}mi`,n=g(1.60934*n,t,b))}null!==o&&(s=Number.isFinite(parseFloat(o))?l(o,2):o),n||(n=t),r.arc(a[0],a[1],l(n,1),0,2*Math.PI),r.fillStyle=`rgb(${c[1]}, ${c[2]}, ${c[3]})`,r.fill(),void 0!==s&&this.drawText(r,a,{fontHeight:l(n,1),label:s,radius:n,rgb:c,shadow:!1})}}),this)}render(){return(0,d.tZ)(n.s0,{redraw:this.redraw})}}p.propTypes=h,p.defaultProps={compositeOperation:"source-over",dotRadius:4,lngLatAccessor:t=>[t[0],t[1]],renderWhileDragging:!0};const u=p,c=16,b=60,m={width:s().number,height:s().number,aggregatorName:s().string,clusterer:s().object,globalOpacity:s().number,hasCustomMetric:s().bool,mapStyle:s().string,mapboxApiKey:s().string.isRequired,onViewportChange:s().func,pointRadius:s().number,pointRadiusUnit:s().string,renderWhileDragging:s().bool,rgb:s().array,bounds:s().array},w={width:400,height:400,globalOpacity:1,onViewportChange:()=>{},pointRadius:b,pointRadiusUnit:"Pixels"};class f extends i.Component{constructor(t){super(t);const{width:e,height:r,bounds:i}=this.props,o=new a.Z({width:e,height:r}).fitBounds(i),{latitude:s,longitude:n,zoom:l}=o;this.state={viewport:{longitude:n,latitude:s,zoom:l}},this.handleViewportChange=this.handleViewportChange.bind(this)}handleViewportChange(t){this.setState({viewport:t});const{onViewportChange:e}=this.props;e(t)}render(){const{width:t,height:e,aggregatorName:r,clusterer:i,globalOpacity:o,mapStyle:s,mapboxApiKey:a,pointRadius:l,pointRadiusUnit:g,renderWhileDragging:h,rgb:p,hasCustomMetric:c,bounds:b}=this.props,{viewport:m}=this.state,w=void 0!==m.isDragging&&m.isDragging,f=.5*t/100,C=.5*e/100,y=[b[0][0]-f,b[0][1]-C,b[1][0]+f,b[1][1]+C],M=i.getClusters(y,Math.round(m.zoom));return(0,d.tZ)(n.ZP,{...m,mapStyle:s,width:t,height:e,mapboxApiAccessToken:a,onViewportChange:this.handleViewportChange,preserveDrawingBuffer:!0,children:(0,d.tZ)(u,{...m,isDragging:w,locations:M,dotRadius:l,pointRadiusUnit:g,rgb:p,globalOpacity:o,compositeOperation:"screen",renderWhileDragging:h,aggregation:c?r:null,lngLatAccessor:t=>{const{coordinates:e}=t.geometry;return[e[0],e[1]]}})})}}f.propTypes=m,f.defaultProps=w;const C=f}}]);
//# sourceMappingURL=23bb701f484aaa4f2d27.chunk.js.map