"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[8623],{88623:(t,e,r)=>{r.r(e),r.d(e,{DEFAULT_MAX_ZOOM:()=>b,DEFAULT_POINT_RADIUS:()=>m,default:()=>y});var i=r(73126),o=r(67294),s=r(45697),n=r.n(s),a=r(90530),l=r(81458);function g(t,e){let r,i=e;return r=e?Math.round(t*(i=10**i))/i:Math.round(t),r}function p(t,e,r){const i=e*(Math.PI/180);return g(t/(40075.16*Math.cos(i)/2**(r+9)),2)}var d=r(11965);const h={aggregation:n().string,compositeOperation:n().string,dotRadius:n().number,lngLatAccessor:n().func,locations:n().arrayOf(n().object).isRequired,pointRadiusUnit:n().string,renderWhileDragging:n().bool,rgb:n().arrayOf(n().oneOfType([n().string,n().number])),zoom:n().number};class u extends o.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 p=t.measureText(o).width;if(p>l){const e=i/p;t.font=e*l+"px sans-serif"}const{compositeOperation:d}=this.props;t.fillText(o,e[0],e[1]),t.globalCompositeOperation=d,t.shadowBlur=0,t.shadowColor=""}redraw({width:t,height:e,ctx:r,isDragging:i,project:o}){const{aggregation:s,compositeOperation:n,dotRadius:a,lngLatAccessor:l,locations:d,pointRadiusUnit:h,renderWhileDragging:u,rgb:c,zoom:b}=this.props,m=a,w=[];d.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||!d||d.forEach((function(i,s){const n=o(l(i)),a=[g(n[0],1),g(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=g((t/f)**.5*m,1),i=g(.5*e,1),[o,n]=a,l=r.createRadialGradient(o,n,e,o,n,0);l.addColorStop(1,`rgba(${c[1]}, ${c[2]}, ${c[3]}, 0.8)`),l.addColorStop(0,`rgba(${c[1]}, ${c[2]}, ${c[3]}, 0)`),r.arc(a[0],a[1],e,0,2*Math.PI),r.fillStyle=l,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=l(i)[1];"Kilometers"===h?(s=`${g(n,2)}km`,n=p(n,t,b)):"Miles"===h&&(s=`${g(n,2)}mi`,n=p(1.60934*n,t,b))}null!==o&&(s=Number.isFinite(parseFloat(o))?g(o,2):o),n||(n=t),r.arc(a[0],a[1],g(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:g(n,1),label:s,radius:n,rgb:c,shadow:!1})}}),this)}render(){return(0,d.tZ)(a.s0,{redraw:this.redraw})}}u.propTypes=h,u.defaultProps={compositeOperation:"source-over",dotRadius:4,lngLatAccessor:t=>[t[0],t[1]],renderWhileDragging:!0};const c=u,b=16,m=60,w={width:n().number,height:n().number,aggregatorName:n().string,clusterer:n().object,globalOpacity:n().number,hasCustomMetric:n().bool,mapStyle:n().string,mapboxApiKey:n().string.isRequired,onViewportChange:n().func,pointRadius:n().number,pointRadiusUnit:n().string,renderWhileDragging:n().bool,rgb:n().array,bounds:n().array},f={width:400,height:400,globalOpacity:1,onViewportChange:()=>{},pointRadius:m,pointRadiusUnit:"Pixels"};class C extends o.Component{constructor(t){super(t);const{width:e,height:r,bounds:i}=this.props,o=new l.Z({width:e,height:r}).fitBounds(i),{latitude:s,longitude:n,zoom:a}=o;this.state={viewport:{longitude:n,latitude:s,zoom:a}},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:o,globalOpacity:s,mapStyle:n,mapboxApiKey:l,pointRadius:g,pointRadiusUnit:p,renderWhileDragging:h,rgb:u,hasCustomMetric:b,bounds:m}=this.props,{viewport:w}=this.state,f=void 0!==w.isDragging&&w.isDragging,C=.5*t/100,y=.5*e/100,M=[m[0][0]-C,m[0][1]-y,m[1][0]+C,m[1][1]+y],x=o.getClusters(M,Math.round(w.zoom));return(0,d.tZ)(a.ZP,(0,i.Z)({},w,{mapStyle:n,width:t,height:e,mapboxApiAccessToken:l,onViewportChange:this.handleViewportChange,preserveDrawingBuffer:!0}),(0,d.tZ)(c,(0,i.Z)({},w,{isDragging:f,locations:x,dotRadius:g,pointRadiusUnit:p,rgb:u,globalOpacity:s,compositeOperation:"screen",renderWhileDragging:h,aggregation:b?r:null,lngLatAccessor:t=>{const{coordinates:e}=t.geometry;return[e[0],e[1]]}})))}}C.propTypes=w,C.defaultProps=f;const y=C}}]);
//# sourceMappingURL=6b055b540bd395735419.chunk.js.map