/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/gl-heatmap2d@1.1.1/heatmap.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";module.exports=createHeatmap2D;var bsearch=require("binary-search-bounds"),iota=require("iota-array"),pool=require("typedarray-pool"),createShader=require("gl-shader"),createBuffer=require("gl-buffer"),shaders=require("./lib/shaders");function GLHeatmap2D(e,t,r,i,s,a,o){this.plot=e,this.shader=t,this.pickShader=r,this.positionBuffer=i,this.weightBuffer=s,this.colorBuffer=a,this.idBuffer=o,this.xData=[],this.yData=[],this.shape=[0,0],this.bounds=[1/0,1/0,-1/0,-1/0],this.pickOffset=0}var proto=GLHeatmap2D.prototype,WEIGHTS=[0,0,1,0,0,1,1,0,1,1,0,1];function createHeatmap2D(e,t){var r=e.gl,i=new GLHeatmap2D(e,createShader(r,shaders.vertex,shaders.fragment),createShader(r,shaders.pickVertex,shaders.pickFragment),createBuffer(r),createBuffer(r),createBuffer(r),createBuffer(r));return i.update(t),e.addObject(i),i}proto.draw=function(){var e=[1,0,0,0,1,0,0,0,1];return function(){var t=this.plot,r=this.shader,i=this.bounds,s=this.numVertices;if(!(s<=0)){var a=t.gl,o=t.dataBox,h=i[2]-i[0],f=i[3]-i[1],p=o[2]-o[0],n=o[3]-o[1];e[0]=2*h/p,e[4]=2*f/n,e[6]=2*(i[0]-o[0])/p-1,e[7]=2*(i[1]-o[1])/n-1,r.bind();var u=r.uniforms;u.viewTransform=e,u.shape=this.shape;var d=r.attributes;this.positionBuffer.bind(),d.position.pointer(),this.weightBuffer.bind(),d.weight.pointer(a.UNSIGNED_BYTE,!1),this.colorBuffer.bind(),d.color.pointer(a.UNSIGNED_BYTE,!0),a.drawArrays(a.TRIANGLES,0,s)}}}(),proto.drawPick=function(){var e=[1,0,0,0,1,0,0,0,1],t=[0,0,0,0];return function(r){var i=this.plot,s=this.pickShader,a=this.bounds,o=this.numVertices;if(!(o<=0)){var h=i.gl,f=i.dataBox,p=a[2]-a[0],n=a[3]-a[1],u=f[2]-f[0],d=f[3]-f[1];e[0]=2*p/u,e[4]=2*n/d,e[6]=2*(a[0]-f[0])/u-1,e[7]=2*(a[1]-f[1])/d-1;for(var l=0;l<4;++l)t[l]=r>>8*l&255;this.pickOffset=r,s.bind();var c=s.uniforms;c.viewTransform=e,c.pickOffset=t,c.shape=this.shape;var v=s.attributes;return this.positionBuffer.bind(),v.position.pointer(),this.weightBuffer.bind(),v.weight.pointer(h.UNSIGNED_BYTE,!1),this.idBuffer.bind(),v.pickId.pointer(h.UNSIGNED_BYTE,!1),h.drawArrays(h.TRIANGLES,0,o),r+this.shape[0]*this.shape[1]}}}(),proto.pick=function(e,t,r){var i=this.pickOffset,s=this.shape[0]*this.shape[1];if(r<i||r>=i+s)return null;var a=r-i,o=this.xData,h=this.yData;return{object:this,pointId:a,dataCoord:[o[a%this.shape[0]],h[a/this.shape[0]|0]]}},proto.update=function(e){var t=(e=e||{}).shape||[0,0],r=e.x||iota(t[0]),i=e.y||iota(t[1]),s=e.z||new Float32Array(t[0]*t[1]),a=!1!==e.zsmooth;this.xData=r,this.yData=i;var o,h,f,p,n=e.colorLevels||[0],u=e.colorValues||[0,0,0,1],d=n.length,l=this.bounds;a?(o=l[0]=r[0],h=l[1]=i[0],f=l[2]=r[r.length-1],p=l[3]=i[i.length-1]):(o=l[0]=r[0]+(r[1]-r[0])/2,h=l[1]=i[0]+(i[1]-i[0])/2,f=l[2]=r[r.length-1]+(r[r.length-1]-r[r.length-2])/2,p=l[3]=i[i.length-1]+(i[i.length-1]-i[i.length-2])/2);var c=1/(f-o),v=1/(p-h),B=t[0],g=t[1];this.shape=[B,g];var b=(a?(B-1)*(g-1):B*g)*(WEIGHTS.length>>>1);this.numVertices=b;for(var m=pool.mallocUint8(4*b),S=pool.mallocFloat32(2*b),w=pool.mallocUint8(2*b),D=pool.mallocUint32(b),E=0,G=a?B-1:B,I=a?g-1:g,T=0;T<I;++T){var k,y;a?(k=v*(i[T]-h),y=v*(i[T+1]-h)):(k=T<g-1?v*(i[T]-(i[T+1]-i[T])/2-h):v*(i[T]-(i[T]-i[T-1])/2-h),y=T<g-1?v*(i[T]+(i[T+1]-i[T])/2-h):v*(i[T]+(i[T]-i[T-1])/2-h));for(var H=0;H<G;++H){var N,x;a?(N=c*(r[H]-o),x=c*(r[H+1]-o)):(N=H<B-1?c*(r[H]-(r[H+1]-r[H])/2-o):c*(r[H]-(r[H]-r[H-1])/2-o),x=H<B-1?c*(r[H]+(r[H+1]-r[H])/2-o):c*(r[H]+(r[H]-r[H-1])/2-o));for(var U=0;U<WEIGHTS.length;U+=2){var q,L,O,A,V=WEIGHTS[U],W=WEIGHTS[U+1],Y=s[a?(T+W)*B+(H+V):T*B+H],_=bsearch.le(n,Y);if(_<0)q=u[0],L=u[1],O=u[2],A=u[3];else if(_===d-1)q=u[4*d-4],L=u[4*d-3],O=u[4*d-2],A=u[4*d-1];else{var j=(Y-n[_])/(n[_+1]-n[_]),F=1-j,z=4*_,R=4*(_+1);q=F*u[z]+j*u[R],L=F*u[z+1]+j*u[R+1],O=F*u[z+2]+j*u[R+2],A=F*u[z+3]+j*u[R+3]}m[4*E]=255*q,m[4*E+1]=255*L,m[4*E+2]=255*O,m[4*E+3]=255*A,S[2*E]=.5*N+.5*x,S[2*E+1]=.5*k+.5*y,w[2*E]=V,w[2*E+1]=W,D[E]=T*B+H,E+=1}}}this.positionBuffer.update(S),this.weightBuffer.update(w),this.colorBuffer.update(m),this.idBuffer.update(D),pool.free(S),pool.free(m),pool.free(w),pool.free(D)},proto.dispose=function(){this.shader.dispose(),this.pickShader.dispose(),this.positionBuffer.dispose(),this.weightBuffer.dispose(),this.colorBuffer.dispose(),this.idBuffer.dispose(),this.plot.removeObject(this)};
//# sourceMappingURL=/sm/e7e3717d48a0a3005bbbce40ca3161addb33a8901a846a02fdf8f6de40acfea3.map