=l-c)d=c,f=l;else{let e=Math.max(c-d,Math.min(l-f,0));d+=e,f+=e}let p=u?f:d,m=u?d:f;return[this._axisValue(i,p),this._axisValue(i,m)]},_clampView(e,t={}){let n=this._viewFrom(e,this.view0),r={};for(let e of this._axisIds()){let[i,a]=this._axisRange(e,n);r[e]=this._clampAxisRange(e,i,a,t.anchors?.[e]??.5)}return this._copyView({ranges:r})},_zoomAxes(){return new Set(this._axisPolicy(`zoom_axes`))},_zoomBy(e,t=!1,n=e<1?`zoom_in`:`zoom_out`){let r=this._viewAnim?this._viewAnim.target:this.view,i=this._zoomAxes(),a=Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e,r)]]));for(let t of i){let[n,r]=a[t],i=this._zoomAxisRange(t,n,r,e,.5);i&&(a[t]=i)}this._setView({ranges:a},{animate:t,source:n,phase:`end`,interactionId:++this._interactionSeq})},_zoomAxisRange(e,t,n,r,i){let a=this._axis(e),o=this._axisCoord(a,t),s=this._axisCoord(a,n);if(![o,s].every(Number.isFinite)||o===s)return null;let c=o+i*(s-o);if(r<1){let e=Math.max(Math.abs(c),1e-30)*1e-12;if(Math.abs((s-o)*r)1&&this.view0){let t=this._axisRange(e,this.view0),n=this._axisCoord(a,t[0]),r=this._axisCoord(a,t[1]),o=Math.abs(r-n);if([n,r].every(Number.isFinite)&&o>0&&Math.abs(u-l)>o){let e=o*Math.sign(u-l);return[this._axisValue(a,c-i*e),this._axisValue(a,c+(1-i)*e)]}}return[this._axisValue(a,l),this._axisValue(a,u)]},_zoomAt(e,t,n,r=!1,i=120,a={}){let o=this._viewAnim?this._viewAnim.target:this.view,s=Array.isArray(a.axes)?new Set(a.axes.filter(e=>this._zoomAxes().has(e))):this._zoomAxes(),c=Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e,o)]])),l={};for(let r of s){let i=this._axisDim(r)===`x`?t:n,[a,o]=c[r],s=this._zoomAxisRange(r,a,o,e,i);s&&(c[r]=s),l[r]=i}return this._setView({ranges:c},{animate:r,duration:i,anchors:l,source:a.source||`wheel_zoom`,phase:a.phase||`update`,interactionId:a.interactionId})},_queueWheelZoom(e,t,n,r=null){if(!Number.isFinite(e)||e<=0)return;clearTimeout(this._wheelZoomEndTimer),this._wheelZoomEndTimer=null;let i=Array.isArray(r)?r.join(`,`):``;if(this._wheelGesture&&this._wheelGesture.scopeKey!==i){let e=this._wheelGesture;this._wheelGesture=null,e.axes.size&&this._emitViewChange(`wheel_zoom`,{axes:[...e.axes],phase:`end`,interactionId:e.interactionId})}this._wheelGesture||={interactionId:++this._interactionSeq,axes:new Set,scopeKey:i},this._pendingWheelZoom||={factor:1,fx:t,fy:n,interactionId:this._wheelGesture.interactionId,axes:[],axesScope:r},this._pendingWheelZoom.factor*=e,this._pendingWheelZoom.fx=t,this._pendingWheelZoom.fy=n,this._pendingWheelZoom.axesScope=r,!this._wheelZoomRaf&&(this._wheelZoomRaf=requestAnimationFrame(()=>{this._wheelZoomRaf=null;let e=this._pendingWheelZoom;if(this._pendingWheelZoom=null,!(!e||this._destroyed)){e.axes=this._zoomAt(e.factor,e.fx,e.fy,!1,120,{source:`wheel_zoom`,phase:`update`,interactionId:e.interactionId,axes:e.axesScope||void 0})||[];for(let t of e.axes)this._wheelGesture?.axes.add(t);clearTimeout(this._wheelZoomEndTimer),this._wheelZoomEndTimer=setTimeout(()=>{let e=this._wheelGesture;this._wheelGesture=null,!(this._destroyed||!e||!e.axes.size)&&this._emitViewChange(`wheel_zoom`,{axes:[...e.axes],phase:`end`,interactionId:e.interactionId})},90)}}))},_zoomToBox(e,t,n=!1,r={}){let i=this._zoomAxes(),a={};for(let n of[`x`,`y`]){let r=this._axis(n),[i,o]=this._axisRange(n),s=this._axisCoord(r,i),c=this._axisCoord(r,o),l=this._axisCoord(r,e[n===`x`?0:1]),u=this._axisCoord(r,t[n===`x`?0:1]);if(![s,c,l,u].every(Number.isFinite)||s===c)return[];a[n]=[(l-s)/(c-s),(u-s)/(c-s)]}let o=Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e)]])),s={};for(let e of i){let t=this._axis(e),[n,r]=o[e],i=this._axisCoord(t,n),c=this._axisCoord(t,r),[l,u]=a[this._axisDim(e)],d=i+l*(c-i),f=i+u*(c-i),p=Math.max(Math.abs(d),Math.abs(f),1e-30)*1e-12;if(!Number.isFinite(d)||!Number.isFinite(f)||Math.abs(f-d)[e,[...this._axisRange(e)]]));for(let e of n||this._resetAxisPolicy())r[e]=[...this._axisRange(e,this.view0)];return this._setView({ranges:r},{animate:e,source:t,phase:`end`,interactionId:++this._interactionSeq})},_exportConfig(){let e=this.spec&&this.spec.export;return e&&typeof e==`object`?e:{}},_exportFilename(e){let t=this._exportConfig().filename;return typeof t==`string`&&t?`${t}.${e}`:`${String(this.spec.title||`xy-chart`).trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`xy-chart`}.${e}`},_downloadExport(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.style.display=`none`,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),0)},_exportSvgMarkup(){this._drawNow?.(),this.gl?.finish?.();let e=this.size.w,t=this.size.h,n=this.root.cloneNode(!0);n.style.width=`${e}px`,n.style.height=`${t}px`,n.style.margin=`0`,n.setAttribute(`xmlns`,`http://www.w3.org/1999/xhtml`);let r=getComputedStyle(this.root),i=[`color`,`font-family`,`font-size`,`font-style`,`font-weight`,`letter-spacing`,`line-height`],a=[`--chart-bg`,`--chart-text`,`--chart-grid`,`--chart-axis`,`--chart-tooltip-bg`,`--chart-tooltip-text`,`--chart-legend-bg`,`--chart-badge-bg`,`--chart-badge-text`,`--chart-modebar-bg`,`--chart-modebar-active`,`--chart-selection`,`--chart-selection-fill`,`--chart-zoom-selection`,`--chart-zoom-selection-fill`,`--chart-crosshair`,`--chart-annotation-text`,`--chart-cursor`,`--chart-cursor-pan`];for(let e=0;ee.remove());let c=document.createElement(`style`);return c.textContent=w,n.prepend(c),``},_exportSvg(){let e=this._exportSvgMarkup();this._downloadExport(new Blob([e],{type:`image/svg+xml;charset=utf-8`}),this._exportFilename(`svg`))},_exportPng(){return this._exportRaster(`png`)},_exportRaster(e){let t=this._exportSvgMarkup(),n=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`,r=new Image,i=this._exportConfig(),a={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`}[e];return a?new Promise((t,o)=>{r.onload=()=>{let n=Number.isFinite(i.scale)&&i.scale>0?i.scale:Math.max(1,window.devicePixelRatio||1),s=document.createElement(`canvas`);s.width=Math.round(this.size.w*n),s.height=Math.round(this.size.h*n);let c=s.getContext(`2d`),l=typeof i.background==`string`&&i.background!==`auto`?i.background:null,u=l===`transparent`||l===`none`;e===`jpeg`?(c.fillStyle=l&&!u?l:`#ffffff`,c.fillRect(0,0,s.width,s.height)):l&&!u&&(c.fillStyle=l,c.fillRect(0,0,s.width,s.height)),c.scale(n,n),c.drawImage(r,0,0,this.size.w,this.size.h);let d=Number.isFinite(i.quality)?Math.min(1,Math.max(.01,i.quality/100)):.9;s.toBlob(n=>{if(!n){o(Error(`${e.toUpperCase()} encoding returned no data`));return}let r=n.type===`image/jpeg`?`jpg`:n.type===`image/webp`?`webp`:`png`;this._downloadExport(n,this._exportFilename(r)),t()},a,e===`png`?void 0:d)},r.onerror=()=>{o(Error(`chart SVG could not be rasterized`))},r.src=n}):Promise.reject(Error(`unsupported raster export ${e}`))},_exportCsvText(){let e=[[`trace`,`name`,`kind`,`index`,`x`,`y`,`x0`,`x1`,`y0`,`y1`,`value`]],t=e=>Number.isFinite(e)?e:``;for(let n of this.gpuTraces||[]){let r=n.trace||{},i=[r.id??``,r.name??``,r.kind??``];if(n._cpuRect){let r=n._cpuRect,a=Math.min(r.x0.length,r.x1.length,r.y0.length,r.y1.length);for(let n=0;n{let t=String(e??``),n=t.split(`"`).join(`""`);return t.includes(`,`)||t.includes(`"`)||t.includes(`\r`)||t.includes(`
+}`;function je(e,t,n){let r=new Float64Array(n-1),i=new Float64Array(n);for(let i=0;i0?(t[i+1]-t[i])/n:0}i[0]=r[0],i[n-1]=r[n-2];for(let e=1;e9){let o=3/Math.sqrt(a);i[e]=o*t*r[e],i[e+1]=o*n*r[e]}}return i}function Me(e,t,n,r,i){if(r<3)return null;let a=Math.max(1,Math.min(16,Math.floor(i/r)));if(a<=1)return null;for(let i=0;i0&&e[i]0){let e=p*p,a=e*p,c=2*a-3*e+1,l=a-2*e+p,m=-2*a+3*e,h=a-e;u[f]=c*t[i]+l*r*o[i]+m*t[i+1]+h*r*o[i+1],d&&(d[f]=c*n[i]+l*r*s[i]+m*n[i+1]+h*r*s[i+1])}else u[f]=t[i],d&&(d[f]=n[i]);f++}}return l[f]=e[r-1],u[f]=t[r-1],d&&(d[f]=n[r-1]),{x:l,y:u,extra:d,n:c}}var Ne=2e5,Pe=1.15;function R(e,t,n=140){if(t==null||n<=0||e._prefersReducedMotion())return 1;let r=Math.min(1,Math.max(0,(e._now()-t)/n));return r*r*(3-2*r)}function Fe(e,t){let n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Float32Array(n.length),i=Math.log1p(Math.max(0,t||0));if(i>0)for(let e=0;e0&&(r[e]=Math.expm1(n[e]/255*i));return r}function Ie(e){return e.slice?e.slice():new Float32Array(e)}function z(e,t,n,r,i,a){let o=new Uint8Array(n.length),s=Math.log1p(Math.max(0,a||0));if(s>0)for(let e=0;e0&&Number.isFinite(t)&&(o[e]=Math.max(1,Math.min(255,Math.round(255*Math.log1p(t)/s))))}e.bindTexture(e.TEXTURE_2D,t);let c=e.getParameter(e.UNPACK_ALIGNMENT);e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,r,i,0,e.RED,e.UNSIGNED_BYTE,o),e.pixelStorei(e.UNPACK_ALIGNMENT,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}function Le(e,t){if(!Number.isFinite(t)||t<=0)return e.densityNormMax=0,0;let n=Number.isFinite(e.densityNormMax)&&e.densityNormMax>0?e.densityNormMax:t,r=t>n?n*.3+t*.7:Math.max(t,n*.86);return e.densityNormMax=r,r}function Re(e,t,n,r){if(!t.density||!t.density.grid||!Number.isFinite(r)||r<=0){t._densityNormAnim=null;return}let i=Math.abs(Math.log(Math.max(n,1e-12)/Math.max(r,1e-12)));if(e._prefersReducedMotion()||i<.02){t._densityNormAnim=null,t.density.normMax=r,t.densityNormMax=r,z(e.gl,t.density.tex,t.density.grid,t.density.w,t.density.h,r);return}t._densityNormAnim={start:n,target:r,startedAt:e._now(),duration:r.004||i>=1)&&(r.normMax=o,t.densityNormMax=o,z(e.gl,r.tex,r.grid,r.w,r.h,o)),i<1){e.draw();return}r.normMax=n.target,t.densityNormMax=n.target,t._densityNormAnim=null}function B(e){return Math.abs((e.xRange[1]-e.xRange[0])*(e.yRange[1]-e.yRange[0]))}function Be(e){return e?Math.abs((e.x1-e.x0)*(e.y1-e.y0)):0}function Ve(e,t){if(!e||!t)return!1;let n=(t.x0+t.x1)/2,r=(t.y0+t.y1)/2;return n>=Math.min(e.x0,e.x1)&&n<=Math.max(e.x0,e.x1)&&r>=Math.min(e.y0,e.y1)&&r<=Math.max(e.y0,e.y1)}function He(e,t){let n=t.densityCache||(t.density?[t.density]:[]),r=null,i=null;for(let t of n)!t||!t.tex||((!i||B(t)>B(i))&&(i=t),e._viewInsideRange(t.xRange,t.yRange)&&(!r||B(t)1200||!Ve(n.win,r))return!1;let i=Be(n.win),a=Be(r);if(!Number.isFinite(i)||!Number.isFinite(a)||i<=0)return!1;let o=Number.isFinite(n.visible)?n.visible:n.n;return!Number.isFinite(o)||o<=0?!1:o*Math.max(1,a/i)<=Ne*Pe}function We(e,t){return t===e.density||t===e.prevDensity||t===e._densitySwitchPrev||t===e._shownDensity||t===e._homeDensity}function V(e,t,n){if(!(!n||!n.tex))for(n._stamp=++e._densityStamp,t.densityCache||=[],t.densityCache.includes(n)||t.densityCache.push(n);t.densityCache.length>8;){let n=-1;for(let e=0;en.channels&&n.channels[e],u=Number(o.trace.style&&o.trace.style.artist_alpha);if(l(`opacity`)||l(`artist_alpha`)||l(`stroke_width`)||l(`symbol`)||Number.isFinite(u)){let t=new Float32Array(o.n*4);for(let e=0;e{let s=l(n);if(!s)return;let c=s.dtype===`u8`?e._asU8(r[s.buf]):e._asF32(r[s.buf]),u=s.components||1;for(let e=0;e=i.x0&&t<=i.x1&&u>=i.y0&&u<=i.y1&&(l[e]=1)}else if(i.mode===`poly`&&Array.isArray(i.points)&&i.points.length>=3){let e=i.points;for(let i=0;iu!=s>u&&t<(o-i)*(u-a)/(s-a)+i&&(d=!d)}d&&(l[i]=1)}}else return;e._applySelMask(t,l)}function qe(e,t){let n=t.drill;if(!n)return;let r=e.gl;e._deleteVaos(n);for(let e of[n.xBuf,n.yBuf,n.cBuf,n.rgbaBuf,n.sBuf,n.styleBuf,n.strokeBuf,n.selBuf,n.dBuf])e&&r.deleteBuffer(e);t.drill=null,t._drillFadeStart=null,t._drillExitFadeStart=null,t._drillWasInside=!1,t._drillShownAlpha=null,t._drillDying=!1,t._drillDiedInsideWin=!1,e._hoverId=-1,e._lastRow=null,e._updatePickable()}function Je(e,t){t.drill&&(t._drillDying=!0,t._drillDiedInsideWin=e._viewInside(t.drill.win),Qe(e,t))}function Ye(e,t){(t._drillExitFadeStart===void 0||t._drillExitFadeStart===null)&&(t._drillExitFadeStart=e._now());let n=R(e,t._drillExitFadeStart,H);return n>=1&&(t._drillExitFadeStart=null),n}var Xe=140,H=120;function U(e){return .5-Math.sin(Math.asin(1-2*Math.min(1,Math.max(0,e)))/3)}function Ze(e,t){return t._drillExitFadeStart==null?t._drillFadeStart==null?t._drillShownAlpha==null?+!!t._drillWasInside:t._drillShownAlpha:R(e,t._drillFadeStart,Xe):1-R(e,t._drillExitFadeStart,H)}function W(e,t){let n=Ze(e,t);t._drillShownAlpha=n,t._drillExitFadeStart=null,t._drillFadeStart=n>=1?null:e._now()-Xe*U(n)}function Qe(e,t){if(t._drillExitFadeStart!=null)return;let n=Ze(e,t);t._drillShownAlpha=n,t._drillFadeStart=null,t._drillExitFadeStart=e._now()-H*U(1-n)}function $e(e,t,n,r){Je(e,t);let i=n.density,a=i.enc===`log-u8`?Fe(r[i.buf],i.max):Ie(e._asF32(r[i.buf])),o=Le(t,i.max),s=e._prefersReducedMotion()?i.max:o;t.densityNormMax=s,t.prevDensity=t.density,t._densityFadeStart=e._now(),t.density={w:i.w,h:i.h,max:i.max,normMax:s,colormap:i.colormap||t.density.colormap,color:i.color?x(e.root,i.color,[.3,.47,.66,1]):t.density.color,xRange:i.x_range,yRange:i.y_range,grid:a,tex:e._uploadGrid(a,i.w,i.h,s),lut:t.density.lut},Object.prototype.hasOwnProperty.call(i,`sample`)&&e._applyDensitySample(t,i.sample,r),Re(e,t,s,i.max),V(e,t,t.density)}function et(e,t,n,r=1){if(n!==t._shownDensity){if(n===t._densitySwitchPrev&&t._densitySwitchFadeStart!=null){let n=R(e,t._densitySwitchFadeStart,140);t._densitySwitchFadeStart=e._now()-140*U(1-n)}else t._densitySwitchFadeStart=e._now();t._densitySwitchPrev=t._shownDensity,t._shownDensity=n}let i=t._densitySwitchPrev,a=i&&i.tex?R(e,t._densitySwitchFadeStart,140):1;if(a<1){e._drawDensity(t,i,(1-a)*r),e._drawDensity(t,n,a*r),e.draw();return}a>=1&&(t.prevDensity===t._densitySwitchPrev&&(t.prevDensity=null),t._densitySwitchPrev=null,t._densitySwitchFadeStart=null,n===t.density&&(t._densityFadeStart=null)),e._drawDensity(t,n,r)}function tt(e,t,n,r,i,a){ze(e,t);let o=t.drill;o&&t._drillDying&&!t._drillDiedInsideWin&&e._viewInside(o.win)&&(t._drillDying=!1,W(e,t),t._drillWasInside=!0);let s=o&&!t._drillDying&&e._viewInside(o.win),c=He(e,t);if(s){(!t._drillWasInside||t._drillExitFadeStart!=null)&&W(e,t),t._drillWasInside=!0,t._drillExitFadeStart=null;let s=R(e,t._drillFadeStart);t._drillShownAlpha=s,t._shownDensity=s<1?c:null,t._densitySwitchPrev=null,t._densitySwitchFadeStart=null,s<1&&c&&c.tex?(e._drawDensity(t,c,1-s),e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis),s),e.draw()):(t._drillFadeStart=null,e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis)))}else if(c&&c.tex){if(Ue(e,t,o)){W(e,t);let s=R(e,t._drillFadeStart);t._drillShownAlpha=s,s<1?(e._drawDensity(t,c,1-s),e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis),s),e.draw()):(t._drillFadeStart=null,e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis))),e._viewAnim&&e.draw();return}let s=o&&t._drillWasInside;s&&Qe(e,t);let l=s?Ye(e,t):1;o&&(t._drillShownAlpha=s&&l<1?1-l:0),s&&l<1?(et(e,t,c,l),e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis),1-l),e.draw()):(t._drillDying?qe(e,t):s&&(t._drillWasInside=!1),et(e,t,c),e._drawDensitySample(t,n,r,i,a))}else o&&e._drawPoints(o,e._map(o.xMeta,n,r,o.xAxis),e._map(o.yMeta,i,a,o.yAxis))}var G={build:(e,t,n,r)=>e._buildRectMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis),o=t.trace.kind===`histogram`?[0,0,e._edgePadForValue(0,i,a,e.canvas.height),0]:[0,0,0,0];e._drawRects(t,e._map(t.x0Meta,n,r,t.xAxis),e._map(t.x1Meta,n,r,t.xAxis),e._map(t.y0Meta,i,a,t.yAxis),e._map(t.y1Meta,i,a,t.yAxis),o)},refreshColor:(e,t)=>{t.colorMode||(t.color=x(e.root,t.trace.style.color,t.color)),e._rectMarkStyleGpu(t,t.trace)}},nt={build:(e,t,n,r)=>e._buildBarMark(t,n,r),draw:(e,t)=>{if(!t.trace.bar){G.draw(e,t);return}let n=t.orientation===1,r=n?t.yAxis:t.xAxis,i=n?t.xAxis:t.yAxis,[a,o]=e._axisRange(r),[s,c]=e._axisRange(i),l=e._map(t.posMeta,a,o,r),u=e._map(t.value1Meta,s,c,i),d=t.value0Mode===1?e._map(t.value0Meta,s,c,i):null,f=t.value0Mode===0?e._mapConst(t.value0Const,s,c,i):null,p=t.value0Mode===0?e._edgePadForValue(t.value0Const,s,c,n?e.canvas.width:e.canvas.height):0;e._drawBars(t,l,u,d,f,p)},refreshColor:(e,t)=>{t.colorMode||(t.color=x(e.root,t.trace.style.color,t.color)),e._rectMarkStyleGpu(t,t.trace)}},K={build:(e,t,n,r)=>e._buildSegmentMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis);e._drawSegments(t,e._map(t.x0Meta,n,r,t.xAxis),e._map(t.y0Meta,i,a,t.yAxis))},refreshColor:(e,t)=>{t.colorMode||(t.color=x(e.root,t.trace.style.color,t.color))}},rt={build:(e,t,n,r)=>e._buildAreaMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis),o=e._map(t.xMeta,n,r,t.xAxis),s=e._map(t.yMeta,i,a,t.yAxis);if(e._drawArea(t,o,s,e._map(t.baseMeta,i,a,t.yAxis)),(t.trace.style.line_width??0)>0&&(e._drawLine(t,o,s,t.lineColor,t.trace.style.line_width,t.trace.style.line_opacity??1),t.trace.style.stroke_perimeter)){let n=t.yBuf,r=t.yMeta,i=t._dashY;t.yBuf=t.baseBuf,t.yMeta=t.baseMeta,t._dashY=t._cpu.base,e._drawLine(t,o,s,t.lineColor,t.trace.style.line_width,t.trace.style.line_opacity??1),t.yBuf=n,t.yMeta=r,t._dashY=i}},refreshColor:(e,t)=>{t.color=x(e.root,t.trace.style.color,t.color),t.lineColor=x(e.root,t.trace.style.line_color||t.trace.style.color,t.lineColor||t.color),t.grad=e._resolveMarkFill(t.trace.style,t.color)}},q={histogram:G,box:G,violin:G,errorbar:K,stem:K,box_whisker:K,box_median:K,contour:K,segments:K,triangle_mesh:{build:(e,t,n,r)=>e._buildMeshMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis);e._drawMesh(t,e._map(t.x0Meta,n,r,t.xAxis),e._map(t.y0Meta,i,a,t.yAxis))},refreshColor:(e,t)=>{t.colorMode===0&&t.trace.color&&(t.color=x(e.root,t.trace.color.color,t.color));let n=t.trace.style||{};t.meshStroke=x(e.root,n.stroke||`transparent`,[0,0,0,0])}},error_band:rt,hexbin:{build:(e,t,n,r)=>e._buildHexbinMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis);e._drawMesh(t,e._map(t.x0Meta,n,r,t.xAxis),e._map(t.y0Meta,i,a,t.yAxis))},refreshColor:(e,t)=>{t.colorMode===0&&t.trace.color&&(t.color=x(e.root,t.trace.color.color,t.color));let n=t.trace.style||{};t.meshStroke=x(e.root,n.stroke||`transparent`,[0,0,0,0])}},bar:nt,column:nt,heatmap:{build:(e,t,n,r)=>e._buildHeatmapMark(t,n,r),draw:(e,t)=>e._drawHeatmap(t)},scatter:{build:(e,t,n,r)=>e._buildScatterMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis);e._drawPoints(t,e._map(t.xMeta,n,r,t.xAxis),e._map(t.yMeta,i,a,t.yAxis))},pointPick:!0,retainCpu:!0,refreshColor:(e,t)=>{t.colorMode===0&&t.trace.color&&(t.color=x(e.root,t.trace.color.color,t.color)),e._pointMarkStyle(t,t.trace)}},line:{build:(e,t,n,r)=>e._buildLineMark(t,n,r),draw:(e,t)=>{let[n,r]=e._axisRange(t.xAxis),[i,a]=e._axisRange(t.yAxis);e._drawLine(t,e._map(t.xMeta,n,r,t.xAxis),e._map(t.yMeta,i,a,t.yAxis))},refreshColor:(e,t)=>{t.color=x(e.root,t.trace.style.color,t.color)}},area:rt};function J(e){return q[e]||q.scatter}var Y={l:62,r:14,t:10,b:42},X=18,it=24,at=8,ot=0,st=`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;`,ct=new Set([`animation-iteration-count`,`aspect-ratio`,`border-image-outset`,`border-image-slice`,`border-image-width`,`column-count`,`flex`,`flex-grow`,`flex-shrink`,`font-weight`,`line-height`,`opacity`,`order`,`orphans`,`tab-size`,`widows`,`z-index`,`zoom`,`fill-opacity`,`flood-opacity`,`stop-opacity`,`stroke-miterlimit`,`stroke-opacity`]),Z={views:new Set,seq:1,hiddenReleaseChannel:null,hiddenReleaseQueue:[],frameId:null,channel:null,foreign:null,_announcedLive:-1,_crossFrameReady:!1,_rebalanceScheduled:!1,budget(){let e=typeof window<`u`?window.XY_CONTEXT_BUDGET:null;return Number.isFinite(e)&&e>=1?Math.floor(e):12},register(e){this._initCrossFrame(),this.views.add(e)},unregister(e){e._ctxPendingReservation=!1,this.views.delete(e),this._announceLive()},reserve(e){let t=[],n=0;for(let r of this.views)r!==e&&r.gl&&!r._glLost&&!r._destroyed&&t.push(r),r!==e&&r._ctxPendingReservation&&!r._destroyed&&(n+=1);let r=!e._ctxPendingReservation;e._ctxPendingReservation=!0;let i=t.length+n+ +!!r-this.budget();if(i<=0)return;let a=t.filter(e=>!e._ctxVisible).sort((e,t)=>(e._ctxSeenSeq||0)-(t._ctxSeenSeq||0));for(let e of a){if(i<=0)break;e._releaseContext()&&--i}if(i<=0)return;let o=t.filter(e=>e._ctxVisible).sort((e,t)=>(e._ctxSeenSeq||0)-(t._ctxSeenSeq||0));for(let e of o){if(i<=0)break;e._releaseContext()&&--i}},acquired(e){e._ctxPendingReservation=!1,this._rebalance(),this._announceLive()},cancel(e){e._ctxPendingReservation=!1},_initCrossFrame(){if(!this._crossFrameReady&&(this._crossFrameReady=!0,this.foreign=new Map,!(typeof BroadcastChannel>`u`)))try{this.frameId=`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,this.channel=new BroadcastChannel(`xy-webgl-context-governor`),this.channel.onmessage=e=>this._onForeignMessage(e.data),this._post({t:`hello`,id:this.frameId}),typeof window<`u`&&window.addEventListener&&(window.addEventListener(`pagehide`,()=>this._post({t:`bye`,id:this.frameId})),window.addEventListener(`pageshow`,e=>{!e||!e.persisted||(this.foreign.clear(),this._announcedLive=-1,this._post({t:`hello`,id:this.frameId}),this._announceLive(!0))}))}catch{this.channel=null}},_post(e){try{this.channel&&this.channel.postMessage(e)}catch{}},_onForeignMessage(e){!e||!this.foreign||e.id===this.frameId||(e.t===`live`?(this.foreign.set(e.id,e.n|0),this._rebalance()):e.t===`hello`?this._announceLive(!0):e.t===`bye`&&this.foreign.delete(e.id))},localLive(){let e=0;for(let t of this.views)t.gl&&!t._glLost&&!t._destroyed&&(e+=1);return e},foreignLive(){let e=0;if(this.foreign)for(let t of this.foreign.values())e+=t;return e},_announceLive(e=!1){if(!this.channel)return;let t=this.localLive();!e&&t===this._announcedLive||(this._announcedLive=t,this._post({t:`live`,id:this.frameId,n:t}))},_rebalance(){if(this.localLive()+this.foreignLive()-this.budget()<=0)return;let e=null;for(let t of this.views)t.gl&&!t._glLost&&!t._destroyed&&!t._ctxVisible&&(!e||(t._ctxSeenSeq||0)<(e._ctxSeenSeq||0))&&(e=t);!e||!e._releaseContext()||this.localLive()+this.foreignLive()-this.budget()>0&&!this._rebalanceScheduled&&(this._rebalanceScheduled=!0,setTimeout(()=>{this._rebalanceScheduled=!1,this._rebalance()},0))},scheduleHiddenReleases(){if(this.hiddenReleaseChannel!==null)return;this.hiddenReleaseQueue=Array.from(this.views);let e=new MessageChannel;this.hiddenReleaseChannel=e,e.port1.onmessage=()=>{if(typeof document>`u`||document.visibilityState!==`hidden`){this.cancelHiddenReleases();return}let t=null;for(;this.hiddenReleaseQueue.length&&!t;){let e=this.hiddenReleaseQueue.shift();!e._destroyed&&e.gl&&!e._glLost&&!e.gl.isContextLost()&&(t=e)}if(!t){this.cancelHiddenReleases();return}t._releaseContext(),e.port2.postMessage(null)},e.port2.postMessage(null)},cancelHiddenReleases(){this.hiddenReleaseChannel?.port1.close(),this.hiddenReleaseChannel?.port2.close(),this.hiddenReleaseChannel=null,this.hiddenReleaseQueue=[]}};function lt(e){if(typeof window>`u`||!e.getBoundingClientRect)return!0;let t=e.getBoundingClientRect();if(!t.width&&!t.height)return!1;let n=window.innerHeight||0,r=window.innerWidth||0;return t.bottom>-.25*n&&t.top<1.25*n&&t.right>-.25*r&&t.left<1.25*r}var Q=class{constructor(e,t,n,r){if(t.protocol!==5)throw e.textContent=`xy: protocol mismatch (client speaks 5, kernel sent ${t.protocol}). Update the xy package and restart the kernel.`,Error(`protocol mismatch`);this.spec=t,this.interaction=t.interaction||{},this.markStyle=t.mark_style||{},this.axes=this._normalizeAxes(t),this.comm=r,this.seq=0,this._densityStamp=0,this._viewRequestBurstStart=null,this._viewAnim=null,this._animRaf=null,this._dataAnim=null,this._dataAnimRaf=null,this._transitionOldTraces=null,this._transitionView=null,this._wheelZoomRaf=null,this._pendingWheelZoom=null,this._lastLabelDraw=null,this._lutCache=new Map,this._listeners=[],this._glPrograms=[],this._progCache=new Map,this._bufSeq=0,this._destroyed=!1,this._resizeRaf=null,this._pendingResize=null,this._resizeNeedsMeasure=!1,this._hoverId=-1,this._hoverTarget=null,this._viewEventRaf=null,this._linkedSource=`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,this.dragMode=`none`,this._interactionSeq=0,this.fluid=t.width===`100%`,this.fluidH=t.height===`100%`;let i=this.fluid||this.fluidH?e.getBoundingClientRect():null,a=this.fluid?Math.round(i.width)||640:t.width,o=this.fluidH?Math.round(i.height)||420:t.height;this.size={w:Math.max(this.fluid?120:48,a),h:Math.max(this.fluidH?120:48,o)},this._layout(),this._buildDom(e),this.theme=S(this.root),this._themeStale=!this.root.isConnected,this._payload=n,this._glLost=!1,this._ctxReleasedExt=null,this._ctxReleases=0,this._ctxRecoveries=0,this._ctxLostPending=!1,this._ctxRecoverRequested=!1,this._ctxVisible=lt(e),Z.register(this),this._ctxVisible&&(this._ctxSeenSeq=Z.seq++),this._contextLossCount=0,this._contextRestoreCount=0,this._contextRecoveryError=null;try{this._initGl(n)}catch(e){throw Z.unregister(this),String(e&&e.message||e)===`webgl2 unavailable`&&(this.root.textContent=`xy: WebGL2 unavailable in this browser.`),e}if(this.canvas.dataset.xyCtx=`live`,this.view0=this._clampView({ranges:Object.fromEntries(Object.entries(this.axes).map(([e,t])=>[e,[...t.range]]))}),this.view=this._copyView(this.view0),this.dragMode=this._resolveDefaultDragAction(),this._initA11y(),this.root.dataset.xyContextState=`ready`,this._initContextLossRecovery(),this._armContextVisibilityWatch(),this._initViewState(),this._initInteraction(),this._buildModebar(this.root),this._initAxisBands(),(this.fluid||this.fluidH)&&typeof ResizeObserver<`u`&&(this._ro=new ResizeObserver(e=>{let t=e[e.length-1].contentRect;(t.width||t.height)&&this._queueResize(t.width,t.height)}),this._ro.observe(this.root)),this._armVisibilityResizeWatch(),this._armDprWatch(),this._initLinkedCharts(),this._themeWatch=window.matchMedia(`(prefers-color-scheme: dark)`),this._onScheme=()=>this.refreshTheme(),this._themeWatch.addEventListener?.(`change`,this._onScheme),typeof MutationObserver<`u`){this._themeMutationObserver=new MutationObserver(()=>this.refreshTheme());for(let e=this.root;e;e=e.parentElement)this._themeMutationObserver.observe(e,{attributes:!0,attributeFilter:[`class`,`style`]})}this._unsubscribeComm=r?r.onMessage((e,t)=>this._onKernelMsg(e,t)):null,this._startEntranceAnimation?this._startEntranceAnimation():this.draw()}_layout(){let e=this.size.w<520,t=Array.isArray(this.spec.padding)?this.spec.padding:null,n=this.spec.colorbar,r=n&&n.orientation!==`horizontal`,i=n&&n.orientation===`horizontal`,a=this.fluid&&e&&t,o=t?a?Math.min(t[3],46):t[3]:e?46:Y.l;this._compactVerticalColorbar=!!(this.fluid&&e&&r);let s=r?this._compactVerticalColorbar?34:86+(n.label?18:0):0,c=i?38+(n.label?16:0):0,l=(t?a?Math.min(t[1],8):t[1]:e?8:Y.r)+s,u=t?t[0]:e?6:Y.t,d=(t?t[2]:e?36:Y.b)+c,f=Object.values(this.axes||{}).some(e=>e&&String(e.id||``).startsWith(`x`)&&e.side!==`top`&&this._axisTickLabelStrategy(e)!==`none`);this._bottomAxisRoom=f?e?36:Y.b:0;let p=Object.values(this.axes||{}).some(e=>e&&String(e.id||``).startsWith(`x`)&&e.side===`top`&&this._axisTickLabelStrategy(e)!==`none`)?e?26:32:0,m=u+(this.spec.title?e?26:30:0)+p,h=Object.values(this.axes||{}).filter(e=>e&&String(e.id||``).startsWith(`y`)&&e.side===`right`&&this._axisTickLabelStrategy(e)!==`none`);this._rightAxisRoom=h.length?e?42:54:0;let g=l+this._rightAxisRoom;this.plot={x:o,y:m,w:Math.max(40,this.size.w-o-g),h:Math.max(40,this.size.h-m-d)}}_normalizeAxes(e){let t={...e.axes||{}};e.x_axis&&(t.x=e.x_axis),e.y_axis&&(t.y=e.y_axis);for(let[e,n]of Object.entries(t))n&&typeof n==`object`&&!n.id&&(n.id=e);return t}_axis(e){let t=e||`x`;return this.axes[t]||(String(t).startsWith(`y`)?this.axes.y:this.axes.x)||{}}_axisDim(e){return String(e||`x`).startsWith(`y`)?`y`:`x`}_axisMode(e){return+(this._axis(e).scale===`log`)}_axisIds(){return Object.keys(this.axes||{})}_copyView(e){let t={};for(let n of this._axisIds()){let r=e?.ranges?.[n]||this._axis(n).range||[0,1];t[n]=[Number(r[0]),Number(r[1])]}let n=t.x||[0,1],r=t.y||[0,1];return{ranges:t,x0:n[0],x1:n[1],y0:r[0],y1:r[1]}}_viewFrom(e,t=this.view){let n={};for(let r of this._axisIds()){let i=e?.ranges?.[r]||(r===`x`&&e?.x0!==void 0?[e.x0,e.x1]:null)||(r===`y`&&e?.y0!==void 0?[e.y0,e.y1]:null)||t?.ranges?.[r]||this._axis(r).range||[0,1];n[r]=[Number(i[0]),Number(i[1])]}return this._copyView({ranges:n})}_axisPolicy(e){let t=this.interaction?.[e];if(!Array.isArray(t)||!t.length)return this._axisIds();let n=new Set(this._axisIds());return[...new Set(t.filter(e=>n.has(e)))]}_resetAxisPolicy(){if(Array.isArray(this.interaction?.reset_axes))return this._axisPolicy(`reset_axes`);let e=[];return this._interactionFlag(`pan`,!0)&&e.push(...this._axisPolicy(`pan_axes`)),this._interactionFlag(`zoom`,!0)&&e.push(...this._axisPolicy(`zoom_axes`)),[...new Set(e)]}_axisContained(e){return!this._interactionFlag(`navigation`,!0)||!this._interactionFlag(`zoom`,!0)||!this._axisPolicy(`zoom_axes`).includes(e)?!1:!this._interactionFlag(`pan`,!0)||!this._axisPolicy(`pan_axes`).includes(e)}_resolveDefaultDragAction(){let e=typeof this.interaction?.default_drag_action==`string`?this.interaction.default_drag_action:`auto`,t=this._interactionFlag(`navigation`,!0),n=t&&this._interactionFlag(`pan`,!0),r=t&&this._interactionFlag(`zoom`,!0)&&this._interactionFlag(`box_zoom`,!0),i=this._pickable&&this._interactionFlag(`select`,!0)&&this._interactionFlag(`brush`,!0);return e===`auto`?n?`pan`:r?`zoom`:i?`select`:`none`:e===`pan`?n?`pan`:this._resolveDefaultDragActionFallback():e===`zoom`?r?`zoom`:this._resolveDefaultDragActionFallback():e.startsWith(`select`)?i?e:this._resolveDefaultDragActionFallback():e===`none`?`none`:this._resolveDefaultDragActionFallback()}_resolveDefaultDragActionFallback(){let e=this.interaction.default_drag_action;this.interaction.default_drag_action=`auto`;let t=this._resolveDefaultDragAction();return this.interaction.default_drag_action=e,t}_axisCoord(e,t){let n=Number(t);return Number.isFinite(n)?e&&e.scale===`log`?n>0?Math.log10(n):NaN:n:NaN}_axisValue(e,t){return e&&e.scale===`log`?10**t:t}_axisRange(e,t=this.view){let n=t?.ranges?.[e];if(Array.isArray(n))return[n[0],n[1]];if(e===`x`&&t)return[t.x0,t.x1];if(e===`y`&&t)return[t.y0,t.y1];let r=this._axis(e).range||[0,1];return[Number(r[0]),Number(r[1])]}_axisTicks(e,t){let n=this._axis(e),[r,i]=this._axisRange(e);if(Array.isArray(n.tick_values)){let e=Math.min(r,i),t=Math.max(r,i),a=n.tick_values.map(Number).filter(n=>Number.isFinite(n)&&n>=e&&n<=t);return{ticks:a,labels:a,step:a.length>1?Math.abs(a[1]-a[0]):1}}return n.kind===`time`?ee(r,i,t):n.kind===`category`?A(r,i,n.categories||[],t):n.scale===`log`?k(r,i,t):O(r,i,t)}_axisTickText(e,t,n){if(Array.isArray(e.tick_values)&&Array.isArray(e.tick_labels)){let n=e.tick_values.findIndex(e=>Number(e)===Number(t));if(n>=0&&n0?Math.max(1,Math.min(200,r)):t}_dataPx(e,t){let n=this._axisDim(e),r=this._axis(e),[i,a]=this._axisRange(e),o=this._axisCoord(r,i),s=this._axisCoord(r,a),c=this._axisCoord(r,t);return![o,s,c].every(Number.isFinite)||s===o?NaN:n===`x`?this.plot.x+(c-o)/(s-o)*this.plot.w:this.plot.y+(1-(c-o)/(s-o))*this.plot.h}_listen(e,t,n,r){return e.addEventListener(t,n,r),this._listeners.push({target:e,type:t,handler:n,options:r}),n}_interactionFlag(e,t=!1){let n=this.interaction&&this.interaction[e];return n===void 0?t:n===!0}_eventView(e=`view`){return{ranges:Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e)]])),x0:this.view.x0,x1:this.view.x1,y0:this.view.y0,y1:this.view.y1,source:e}}_dispatchChartEvent(e,t){!this.root||typeof CustomEvent!=`function`||this.root.dispatchEvent(new CustomEvent(`xy:${e}`,{detail:t,bubbles:!0,composed:!0}))}_emitViewChange(e=`view`,t={}){if(this._destroyed)return;let n=t.broadcast!==!1;this._pendingViewEvent={source:e,broadcast:n,axes:Array.isArray(t.axes)?[...t.axes]:[],phase:t.phase||`end`,interaction_id:t.interactionId??++this._interactionSeq},!this._viewEventRaf&&(this._viewEventRaf=requestAnimationFrame(()=>{this._viewEventRaf=null;let t=this._pendingViewEvent||{source:e,broadcast:n};this._pendingViewEvent=null;let r={...this._eventView(t.source),axes:t.axes,phase:t.phase,interaction_id:t.interaction_id};this._dispatchChartEvent(`view_change`,r),this.comm&&(t.phase===`end`||!this.comm.wantsViewChange||this.comm.wantsViewChange())&&this.comm.send({type:`view_change`,...r}),t.broadcast&&this._broadcastLinkedView(r)}))}_initLinkedCharts(){let e=this.interaction&&this.interaction.link_group;!e||typeof BroadcastChannel!=`function`||(this._linkAxes=this._axisPolicy(`link_axes`),this._linkChannel=new BroadcastChannel(`xy:${e}`),this._linkChannel.onmessage=e=>{let t=e.data||{};if(t.source===this._linkedSource)return;if(this._interactionFlag(`link_select`)&&t.selection){let e=t.selection;if(e.clear)this._clearSelection({broadcast:!1,dispatch:!1});else if(e.polygon)this._stateSelection={polygon:e.polygon.map(e=>[...e])},this._selectLocalPolygon(e.polygon,{dispatch:!1});else if(e.range){let{x0:t,x1:n,y0:r,y1:i}=e.range;[t,n,r,i].every(Number.isFinite)&&(this._stateSelection={range:{x0:t,x1:n,y0:r,y1:i}},this._selectLocal(t,n,r,i,{dispatch:!1}))}return}if(!t.view||t.source===this._linkedSource)return;let n=t.view.ranges||{},r=Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e)]]));for(let e of this._linkAxes){let i=n[e]||(e===`x`?[t.view.x0,t.view.x1]:null)||(e===`y`?[t.view.y0,t.view.y1]:null);Array.isArray(i)&&i.length===2&&i.every(Number.isFinite)&&(r[e]=[Number(i[0]),Number(i[1])])}this._setView({ranges:r},{animate:!1,source:`linked`,phase:`end`,broadcast:!1})})}_broadcastLinkedView(e){if(!this._linkChannel)return;let t=(e.axes||[]).filter(e=>this._linkAxes.includes(e));if(!t.length)return;let n=Object.fromEntries(t.map(t=>[t,e.ranges[t]]));this._linkChannel.postMessage({source:this._linkedSource,view:{...e,axes:t,ranges:n}})}_broadcastLinkedSelection(e){!this._linkChannel||!this._interactionFlag(`link_select`)||this._linkChannel.postMessage({source:this._linkedSource,selection:e})}setView(e,t={}){return this._setView({ranges:e},{animate:t.animate===!0,source:`programmatic`,phase:`end`,interactionId:++this._interactionSeq,broadcast:t.broadcast===!0})}resetView(e={}){return this._resetView(e.animate!==!1,`reset`)}_applyClass(e,t){if(typeof t==`string`)for(let n of t.split(/\s+/).filter(Boolean))try{e.classList.add(n)}catch{}}_stylePropertyName(e){return e.startsWith(`--`)?e:e.replace(/_/g,`-`).replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}_stylePropertyValue(e,t){return typeof t==`number`?Number.isFinite(t)?e.startsWith(`--`)||ct.has(e)?String(t):`${t}px`:null:String(t)}_applyStyle(e,t){if(!(!t||typeof t!=`object`||Array.isArray(t)))for(let[n,r]of Object.entries(t)){if(typeof n!=`string`||typeof r!=`string`&&typeof r!=`number`)continue;let t=this._stylePropertyName(n),i=this._stylePropertyValue(t,r);i!=null&&e.style.setProperty(t,i)}}_applySlot(e,t){e&&e.dataset&&(e.dataset.xySlot=t);let n=this.spec.dom;!n||typeof n!=`object`||(t===`root`&&this._applyClass(e,n.class_name),n.class_names&&typeof n.class_names==`object`&&this._applyClass(e,n.class_names[t]),t===`root`&&this._applyStyle(e,n.style),n.styles&&typeof n.styles==`object`&&this._applyStyle(e,n.styles[t]))}_slotStyleValue(e,t){let n=this.spec.dom?.styles,r=n&&typeof n==`object`?n[e]:null;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=this._stylePropertyName(t);for(let e of Object.keys(r))if(this._stylePropertyName(e)===i)return r[e];return null}_syncContainerSize(){this._destroyed||!(this.fluid||this.fluidH)||!this.root||this._queueResize(null,null,!0)}_queueResize(e=null,t=null,n=!1){this._destroyed||((e||t)&&(this._pendingResize={cssW:e,cssH:t}),n&&(this._resizeNeedsMeasure=!0),!this._resizeRaf&&(this._resizeRaf=requestAnimationFrame(()=>{this._resizeRaf=null;let e=this._pendingResize;if(this._pendingResize=null,this._resizeNeedsMeasure&&this.root){let t=this.root.getBoundingClientRect();(t.width||t.height)&&(e={cssW:t.width,cssH:t.height})}this._resizeNeedsMeasure=!1,e&&(e.cssW||e.cssH)&&this._resize(e.cssW,e.cssH)})))}_armVisibilityResizeWatch(){if(!(this.fluid||this.fluidH))return;let e=()=>{this._destroyed||this._syncContainerSize()};this._listen(window,`resize`,e),this._listen(window,`pageshow`,e),this._listen(document,`visibilitychange`,e),typeof IntersectionObserver<`u`&&(this._io=new IntersectionObserver(t=>{t.some(e=>e.isIntersecting||e.intersectionRatio>0)&&e()}),this._io.observe(this.root))}_markStateValue(e,t,n=null){let r=this.markStyle&&typeof this.markStyle==`object`?this.markStyle[e]:null;return!r||typeof r!=`object`||Array.isArray(r)?n:Object.prototype.hasOwnProperty.call(r,t)?r[t]:n}_markStateNumber(e,t,n){let r=this._markStateValue(e,t,n);return typeof r!=`number`||!Number.isFinite(r)?n:r}_markStatePaint(e,t,n){let r=this._markStateValue(e,t,n);return typeof r==`string`?r:n}_armDprWatch(){if(typeof window.matchMedia!=`function`)return;this._dprMq?.removeEventListener?.(`change`,this._onDprChange);let e=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);this._onDprChange=()=>{this._destroyed||(this._resize(this.size.w,this.size.h),this._armDprWatch())},e.addEventListener?.(`change`,this._onDprChange,{once:!0}),this._dprMq=e}_initContextLossRecovery(){this._listen(this.canvas,`webglcontextlost`,e=>{if(e.preventDefault(),this._destroyed)return;let t=this.canvas.dataset.xyCtx===`released`;if(this._glLost&&!t)return;this._glLost=!0,this._ctxLostPending=!1,t||(this.canvas.dataset.xyCtx=`lost`),Z._announceLive(),this._contextLossCount+=1,this._contextRecoveryError=null,this.root.dataset.xyContextState=`lost`,this.seq+=1,this._raf&&cancelAnimationFrame(this._raf),this._raf=null,this._wheelZoomRaf&&cancelAnimationFrame(this._wheelZoomRaf),this._wheelZoomRaf=null,this._pendingWheelZoom=null,clearTimeout(this._wheelZoomEndTimer),this._wheelZoomEndTimer=null,this._wheelGesture=null,this._dataAnimRaf&&cancelAnimationFrame(this._dataAnimRaf),this._dataAnimRaf=null,this._dataAnim&&this._emitAnimationLifecycle?.(`end`,this._dataAnim.phase,{cancelled:!0}),this._dataAnim=null,this._transitionOldTraces=null,this._transitionView=null,this.view0&&(this.view={...this.view0}),this._cancelViewAnimation(),clearTimeout(this._viewTimer),this._viewTimer=null,clearTimeout(this._rebinTimer),this._rebinTimer=null,this._viewRequestBurstStart=null,this._dispatchChartEvent(`context_lost`,{loss_count:this._contextLossCount});let n=typeof document>`u`||!document.visibilityState||document.visibilityState===`visible`;!t&&this._ctxVisible&&n&&setTimeout(()=>{!this._destroyed&&this._glLost&&this.canvas.dataset.xyCtx===`lost`&&this._ctxVisible&&this._recoverContext()},0),t&&this._ctxRecoverRequested&&!this._destroyed&&this._ctxVisible&&(this._ctxRecoverRequested=!1,setTimeout(()=>{!this._destroyed&&this._glLost&&this._ctxVisible&&this._recoverContext()},0))}),this._listen(this.canvas,`webglcontextrestored`,()=>{if(!(this._destroyed||this._contextRecoveryError)){this._lutCache.clear(),this.pickFbo=null,this.pickTex=null;try{this._initGl(this._payload),this._glLost=!1,this._drawNow(),this._assertContextFrameReady(`restore`)}catch(e){if(this._glLost=!0,this.canvas.dataset.xyCtx=`lost`,this.root.dataset.xyContextState=`lost`,!this.gl||this.gl.isContextLost()||String(e&&e.message||e).includes(`shader compile: null`)||String(e&&e.message||e).startsWith(`WebGL error `)){this._contextRecoveryError=null,this._scheduleContextRecovery();return}this._contextRecoveryError=e,this.root.dataset.xyContextState=`failed`;try{this._destroyGlResources()}catch{}this.gl=null,this._dispatchChartEvent(`context_restore_failed`,{loss_count:this._contextLossCount,message:e instanceof Error?e.message:String(e)}),this.root.textContent=`xy: WebGL2 context could not be restored.`;return}this._contextRestoreCount+=1,this._contextRecoveryError=null,this._ctxRecoveryDelay=0,this.canvas.dataset.xyCtx=`live`,this.root.dataset.xyContextState=`ready`,Z._announceLive(),this._scheduleViewRequest(this.view,{delay:0}),this._dropContextSnapshot(),this._dispatchChartEvent(`context_restored`,{loss_count:this._contextLossCount,restore_count:this._contextRestoreCount})}})}_releaseContext(){if(this._destroyed||!this.gl||this._glLost||this.gl.isContextLost())return!1;let e=this.gl.getExtension(`WEBGL_lose_context`);return e?(this._snapshotBeforeRelease(),this._ctxReleasedExt=e,this._ctxReleases+=1,this._glLost=!0,this._ctxLostPending=!0,this.canvas.dataset.xyCtx=`released`,this._raf&&cancelAnimationFrame(this._raf),this._raf=null,e.loseContext(),Z._announceLive(),!0):!1}_snapshotBeforeRelease(){try{this._raf&&cancelAnimationFrame(this._raf),this._raf=null,this._rafKeepPick=!0,this._drawNow();let e=this._ctxSnapshot;e||(e=this._ctxSnapshot=document.createElement(`canvas`),e.dataset.xyCtxSnapshot=``),e.width=this.canvas.width,e.height=this.canvas.height,e.style.cssText=this.canvas.style.cssText,e.style.pointerEvents=`none`;let t=this.gl,n=this.canvas.width,r=this.canvas.height;t.finish();let i=new Uint8Array(n*r*4);t.readPixels(0,0,n,r,t.RGBA,t.UNSIGNED_BYTE,i);let a=e.getContext(`2d`),o=a.createImageData(n,r),s=o.data;for(let e=0;e0&&e<255){let t=255/e;n=Math.min(255,Math.round(n*t)),r=Math.min(255,Math.round(r*t)),a=Math.min(255,Math.round(a*t))}s[o]=n,s[o+1]=r,s[o+2]=a,s[o+3]=e}}a.putImageData(o,0,0),this.canvas.before(e),this.canvas.style.visibility=`hidden`}catch{this._dropContextSnapshot()}}_dropContextSnapshot(){this.canvas.style.visibility=``,this._ctxSnapshot&&this._ctxSnapshot.remove(),this._ctxSnapshot=null}_recoverContext(){if(!(this._destroyed||!this._glLost)){if(this._ctxReleasedExt&&this._ctxLostPending){this._ctxRecoverRequested=!0;return}if(this._ctxRecoveries+=1,this._ctxReleasedExt){let e=this._ctxReleasedExt;this._ctxReleasedExt=null;try{Z.reserve(this),e.restoreContext();return}catch{Z.cancel(this)}}this._rebuildEvictedContext()}}_assertContextFrameReady(e){if(!this.gl||(this.gl.finish(),this.gl.isContextLost()))throw Error(`context lost during ${e} draw`);let t=this.gl.getError();if(t!==this.gl.NO_ERROR)throw Error(`WebGL error ${t} during ${e} draw`)}_scheduleContextRecovery(){if(this._ctxRecoveryTimer||this._destroyed||!this._ctxVisible||typeof document<`u`&&document.visibilityState&&document.visibilityState!==`visible`)return;let e=this._ctxRecoveryDelay||50;this._ctxRecoveryDelay=Math.min(1e3,e*2),this._ctxRecoveryTimer=setTimeout(()=>{this._ctxRecoveryTimer=null,this._glLost&&!this._destroyed&&this._ctxVisible&&this._recoverContext()},e)}_rebuildEvictedContext(){if(this.gl&&!this.gl.isContextLost())try{this.gl.getExtension(`WEBGL_lose_context`)?.loseContext()}catch{}let e=this.canvas.cloneNode(!1);for(let t of this._listeners)t.target===this.canvas&&(this.canvas.removeEventListener(t.type,t.handler,t.options),e.addEventListener(t.type,t.handler,t.options),t.target=e);this.canvas.replaceWith(e),this.canvas=e,this._glLost=!1,this._lutCache.clear(),this.pickFbo=null,this.pickTex=null;try{this._initGl(this._payload),this._glLost=!1,this._drawNow(),this._assertContextFrameReady(`rebuild`)}catch{this._glLost=!0,this.canvas.dataset.xyCtx=`lost`,this._scheduleContextRecovery();return}this._ctxRecoveryDelay=0,this.canvas.dataset.xyCtx=`live`,Z._announceLive(),this._scheduleViewRequest(this.view,{delay:0}),this._dropContextSnapshot()}_armContextVisibilityWatch(){if(this._listen(this.root,`pointerenter`,()=>{this._glLost&&!this._destroyed&&this._recoverContext()}),typeof document<`u`&&this._listen(document,`visibilitychange`,()=>{if(document.visibilityState===`hidden`){Z.scheduleHiddenReleases();return}Z.cancelHiddenReleases(),document.visibilityState===`visible`&&this._ctxVisible&&this._glLost&&!this._destroyed&&this._recoverContext()}),typeof IntersectionObserver>`u`){this._ctxVisible=!0;return}this._ctxIo=new IntersectionObserver(e=>{let t=e[e.length-1];this._ctxVisible=t.isIntersecting||t.intersectionRatio>0,this._ctxVisible?(this._ctxSeenSeq=Z.seq++,this._glLost&&!this._destroyed&&this._recoverContext(),this._healStaleTheme()&&this.draw()):this._destroyed||Z._rebalance()},{rootMargin:`25% 0px 25% 0px`}),this._ctxIo.observe(this.root)}_resize(e,t){let n=this.fluid&&e?Math.max(120,Math.round(e)):this.size.w,r=this.fluidH&&t?Math.max(120,Math.round(t)):this.size.h,i=window.devicePixelRatio||1;if(n===this.size.w&&r===this.size.h&&i===this.dpr)return;this.dpr=i,this.size.w=n,this.size.h=r,this._layout();let a=this.plot;this.root.style.setProperty(`--xy-legend-max-width`,Math.max(40,a.w-12)+`px`),this.root.style.setProperty(`--xy-legend-max-height`,Math.max(40,a.h-12)+`px`),this.canvas.style.left=a.x+`px`,this.canvas.style.top=a.y+`px`,this.canvas.style.width=a.w+`px`,this.canvas.style.height=a.h+`px`,this.canvas.width=a.w*this.dpr,this.canvas.height=a.h*this.dpr,this.chrome.style.width=this.size.w+`px`,this.chrome.style.height=this.size.h+`px`,this.chrome.width=this.size.w*this.dpr,this.chrome.height=this.size.h*this.dpr,this.overlay.style.width=this.size.w+`px`,this.overlay.style.height=this.size.h+`px`,this.overlay.width=this.size.w*this.dpr,this.overlay.height=this.size.h*this.dpr;for(let e of this._legends||[])this._positionLegend(e,e.dataset.xyLegendLoc||`upper right`);this._positionReductionBadges(),this._positionColorbar(),this._fitModebar(),this._layoutAxisBands(),this._pickDirty=!0,this._raf&&cancelAnimationFrame(this._raf),this._raf=null,this._drawNow(),this._scheduleViewRequest()}_buildDom(e){let t=this.spec,n=document.createElement(`div`);n.className=`xy`,n.style.cssText=`position:relative;width:${this.fluid?`100%`:this.size.w+`px`};height:${this.fluidH?`100%`:this.size.h+`px`};--xy-legend-max-width:${Math.max(40,this.plot.w-12)}px;--xy-legend-max-height:${Math.max(40,this.plot.h-12)}px;`+(this.fluidH?`min-height:120px;`:``)+`font:12px system-ui,sans-serif;user-select:none;`,this._applySlot(n,`root`),(n.style.background||n.style.backgroundColor)&&(n.dataset.xyOwnBg=``),e.appendChild(n),this.root=n,T(n);let r;do r=`xy-a11y-${++ot}`;while(document.getElementById(`${r}-summary`)||document.getElementById(`${r}-live`));if(n.setAttribute(`role`,`region`),n.setAttribute(`aria-label`,t.title?`Chart: ${t.title}`:`Interactive chart`),this.a11ySummary=document.createElement(`div`),this.a11ySummary.id=`${r}-summary`,this.a11ySummary.style.cssText=st,n.setAttribute(`aria-describedby`,this.a11ySummary.id),n.appendChild(this.a11ySummary),this.a11yLive=document.createElement(`div`),this.a11yLive.id=`${r}-live`,this.a11yLive.setAttribute(`role`,`status`),this.a11yLive.setAttribute(`aria-live`,`polite`),this.a11yLive.setAttribute(`aria-atomic`,`true`),this.a11yLive.style.cssText=st,n.appendChild(this.a11yLive),t.title){let e=document.createElement(`div`);e.textContent=t.title,e.style.cssText=`position:absolute;top:6px;left:0;right:0;`,this._applySlot(e,`title`),n.appendChild(e)}this.chrome=document.createElement(`canvas`),this.chrome.style.cssText=`position:absolute;inset:0;pointer-events:none;`,this._applySlot(this.chrome,`chrome`),n.appendChild(this.chrome),this.canvas=document.createElement(`canvas`),this.canvas.style.cssText=`position:absolute;left:${this.plot.x}px;top:${this.plot.y}px;width:${this.plot.w}px;height:${this.plot.h}px;touch-action:none;`,this._applySlot(this.canvas,`canvas`),this.canvas.tabIndex=0,this.canvas.setAttribute(`role`,`img`),this.canvas.setAttribute(`aria-describedby`,this.a11ySummary.id),n.appendChild(this.canvas),this.overlay=document.createElement(`canvas`),this.overlay.style.cssText=`position:absolute;inset:0;pointer-events:none;`,n.appendChild(this.overlay),this.labels=document.createElement(`div`),this.labels.style.cssText=`position:absolute;inset:0;pointer-events:none;`,this._applySlot(this.labels,`labels`),n.appendChild(this.labels),this.tooltip=document.createElement(`div`),this.tooltip.style.cssText=`position:absolute;display:none;pointer-events:none;z-index:5;`,this._applySlot(this.tooltip,`tooltip`),this.tooltip.setAttribute(`aria-hidden`,`true`),n.appendChild(this.tooltip),this._buildLegend(n),this._buildColorbar(n),this._buildReductionBadges(n)}_a11yAxisSummary(e,t){let n=this._axis(e),r=n.label?`${t} axis (${n.label})`:`${t} axis`;if(n.kind===`category`){let e=Array.isArray(n.categories)?n.categories:[];if(!e.length)return`${r} uses categories.`;let t=e.slice(0,6).map(e=>String(e)),i=e.length-t.length,a=i>0?`, and ${i} more`:``;return`${r} has ${e.length} categories: ${t.join(`, `)}${a}.`}let i=n.range||[];return i.length<2?null:`${r} ranges from ${P(i[0],n.kind)} to ${P(i[1],n.kind)}.`}_a11ySummaryText(){let e=Array.isArray(this.spec.traces)?this.spec.traces:[],t=[this.spec.title?`${this.spec.title}.`:`Interactive chart.`];t.push(`${e.length} data series.`);let n=e.map(e=>e&&e.name).filter(Boolean).slice(0,6);n.length&&t.push(`Series: ${n.join(`, `)}.`);let r=this._a11yAxisSummary(`x`,`X`),i=this._a11yAxisSummary(`y`,`Y`);return r&&t.push(r),i&&t.push(i),t.join(` `)}_initA11y(){if(!this.a11ySummary||!this.canvas)return;this.a11ySummary.textContent=this._a11ySummaryText();let e=this._pickable?` Use Arrow keys to explore data points in series data order; Home and End jump to the first and last point; Escape closes the readout.`:``;this.canvas.setAttribute(`aria-label`,`Plot area.${e}`)}_compactInt(e){let t=Number(e);return Number.isFinite(t)?Math.round(t).toLocaleString():`0`}_positionReductionBadges(){if(!this._badges)return;let e=this.size.w-(this.plot.x+this.plot.w),t=this.size.h-(this.plot.y+this.plot.h);this._badges.style.right=`${e+6}px`,this._badges.style.bottom=`${t+6}px`}_reductionBadgeItems(){let e=[],t=this.gpuTraces&&this.gpuTraces.length?this.gpuTraces:this.spec.traces||[];for(let n of t){let t=n.trace||n;if(t.tier!==`density`||!t.density)continue;let r=n.sampleOverlay&&n.sampleOverlay.sample?n.sampleOverlay.sample:t.density.sample;r&&Number(r.n)>0&&e.push(`sampled ${this._compactInt(r.n)} of ${this._compactInt(r.visible)}`),n._sampleRebinned&&e.push(`zoom re-binned from sample`),t.density.channels_dropped&&e.push(`aggregated channels`)}return e}_refreshReductionBadges(){if(!this._badges)return;let e=this._reductionBadgeItems();this._badges.textContent=``,this._badges.hidden=e.length===0;for(let t of e){let e=document.createElement(`div`);e.textContent=t,this._applySlot(e,`badge_item`),this._badges.appendChild(e)}this._positionReductionBadges()}_buildReductionBadges(e){let t=this._reductionBadgeItems(),n=(this.spec.traces||[]).some(e=>e.tier===`density`);if(!t.length&&!n)return;let r=document.createElement(`div`);r.style.cssText=`position:absolute;display:flex;flex-direction:column;align-items:flex-end;pointer-events:none;z-index:4;`,this._applySlot(r,`badge`),e.appendChild(r),this._badges=r,this._refreshReductionBadges()}_buildLegend(e){let t=this.spec;this._legends=[];let n=[];if(t.show_legend!==!1){for(let e of t.traces)if(e.tier===`density`)n.push({swatch:`gradient`,cmap:e.density.colormap,name:e.name||`density`});else if(e.color&&e.color.mode===`categorical`)e.color.categories.forEach((t,r)=>n.push({swatch:e.color.palette[r],name:t,symbol:e.kind===`scatter`?e.style?.symbol||`circle`:null,style:e.style||{}}));else if(e.color&&e.color.mode===`continuous`)n.push({swatch:`gradient`,cmap:e.color.colormap,name:e.name||`value`});else if(e.name){let t=e.color&&e.color.color||e.style&&e.style.color,r=[`line`,`segments`,`step`,`stairs`,`errorbar`].includes(e.kind);n.push({swatch:t,name:e.name,symbol:e.kind===`scatter`?e.style?.symbol||`circle`:null,line:r,style:e.style||{}})}n.length&&this._legendBox(e,n,t.legend||{})}for(let n of t.extra_legends||[]){let t=(n.items||[]).map(e=>({swatch:e.style&&e.style.color,name:e.name,symbol:e.kind===`scatter`?e.style?.symbol||`circle`:null,line:[`line`,`segments`,`step`,`stairs`,`errorbar`].includes(e.kind),style:e.style||{}}));t.length&&this._legendBox(e,t,n)}}_legendBox(e,t,n){let r=document.createElement(`div`),i=n.loc||`upper right`,a=Math.max(1,Number(n.ncols)||1),o=a>1;if(r.style.cssText=`position:absolute;display:grid;grid-template-columns:repeat(${o?a:1},max-content);overflow:auto;`,r.dataset.xyLegendLoc=i,this._positionLegend(r,i),this._applySlot(r,`legend`),n.title){let e=document.createElement(`div`);e.textContent=String(n.title),e.style.fontWeight=`600`,e.style.gridColumn=`1 / span ${o?a:1}`,r.appendChild(e)}for(let e of t){let t=document.createElement(`div`);this._applySlot(t,`legend_item`);let n=document.createElement(`span`);n.style.display=`inline-block`,n.style.verticalAlign=`-1px`;let i=e.swatch;if(e.swatch===`gradient`)i=`linear-gradient(90deg,${g(e.cmap).map(e=>`rgb(${e[0]},${e[1]},${e[2]})`).join(`,`)})`,n.style.background=i;else if(e.symbol){let t=`http://www.w3.org/2000/svg`,r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 18 14`),r.setAttribute(`width`,`18`),r.setAttribute(`height`,`14`);let a=document.createElementNS(t,`path`),o={square:`M4.5 2.5h9v9h-9z`,diamond:`M9 2l5 5-5 5-5-5z`,thin_diamond:`M9 2l3 5-3 5-3-5z`,triangle:`M9 2l-5 10h10z`,triangle_down:`M9 12L4 2h10z`,triangle_left:`M4 7L14 2v10z`,triangle_right:`M14 7L4 2v10z`,plus_line:`M9 2v10M4 7h10`,x_line:`M5 3l8 8M13 3l-8 8`,cross:`M7.5 2h3v3.5H14v3h-3.5V12h-3V8.5H4v-3h3.5z`,x:`M5.5 2L9 5.5 12.5 2 14 3.5 10.5 7 14 10.5 12.5 12 9 8.5 5.5 12 4 10.5 7.5 7 4 3.5z`,pentagon:`M9 2.5L13.28 5.61 11.65 10.64H6.35L4.72 5.61z`,hexagon:`M9 2L13.3 4.5v5L9 12l-4.3-2.5v-5z`,star:`M9 2l1.5 3.1 3.5.5-2.5 2.5.6 3.5L9 10l-3.1 1.6.6-3.5L4 5.6l3.5-.5z`},s=E(this.root,i);e.symbol===`circle`||e.symbol===`point`||e.symbol===`pixel`?e.symbol===`pixel`?a.setAttribute(`d`,`M8.5 6.5h1v1h-1z`):a.setAttribute(`d`,`M9 ${e.symbol===`point`?4.75:2.5}a${e.symbol===`point`?2.25:4.5} ${e.symbol===`point`?2.25:4.5} 0 1 0 0 ${e.symbol===`point`?4.5:9}a${e.symbol===`point`?2.25:4.5} ${e.symbol===`point`?2.25:4.5} 0 1 0 0 -${e.symbol===`point`?4.5:9}`):a.setAttribute(`d`,o[e.symbol]||o.square),a.setAttribute(`fill`,e.symbol.endsWith(`_line`)?`none`:s),a.setAttribute(`stroke`,s),a.setAttribute(`stroke-width`,String(e.style?.stroke_width||1)),r.appendChild(a),n.appendChild(r),n.style.width=`18px`,n.style.height=`14px`}else if(e.line){let t=`http://www.w3.org/2000/svg`,r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 22 12`),r.setAttribute(`width`,`22`),r.setAttribute(`height`,`12`);let a=document.createElementNS(t,`line`);a.setAttribute(`x1`,`1`),a.setAttribute(`y1`,`6`),a.setAttribute(`x2`,`21`),a.setAttribute(`y2`,`6`),a.setAttribute(`stroke`,E(this.root,i)),a.setAttribute(`stroke-width`,String(e.style?.width??1.5)),e.style?.dash&&e.style.dash.length&&a.setAttribute(`stroke-dasharray`,e.style.dash.join(` `)),r.appendChild(a),n.appendChild(r),n.style.width=`22px`,n.style.height=`12px`}else n.style.background=E(this.root,i);this._applySlot(n,`legend_swatch`),t.appendChild(n),t.appendChild(document.createTextNode(e.name)),r.appendChild(t)}return e.appendChild(r),this._legends.push(r),r}_positionLegend(e,t){if(!e)return;let n=this.size.w-(this.plot.x+this.plot.w),r=t.includes(`left`)?`left`:t.includes(`right`)?`right`:`center`,i=t.includes(`upper`)?`upper`:t.includes(`lower`)?`lower`:`center`,a=r===`left`?this.plot.x+6:r===`center`?this.plot.x+this.plot.w/2:null,o=r===`right`?n+6:null,s=i===`upper`?this.plot.y+6:i===`center`?this.plot.y+this.plot.h/2:null,c=i===`lower`?this.size.h-(this.plot.y+this.plot.h)+6:null;e.style.setProperty(`--xy-legend-left`,a==null?`auto`:a+`px`),e.style.setProperty(`--xy-legend-right`,o==null?`auto`:o+`px`),e.style.setProperty(`--xy-legend-top`,s==null?`auto`:s+`px`),e.style.setProperty(`--xy-legend-bottom`,c==null?`auto`:c+`px`);let l=r===`center`?`-50%`:`0`,u=i===`center`?`-50%`:`0`;e.style.setProperty(`--xy-legend-transform`,`translate(${l},${u})`)}_buildColorbar(e){let t=this.spec.colorbar;if(!t)return;let n=document.createElement(`div`),r=t.orientation===`horizontal`;n.style.cssText=`position:absolute;pointer-events:none;z-index:4;`,this._applySlot(n,`colorbar`);let i=document.createElement(`div`),a=Math.max(0,Number(t.levels)||0),o;if(a>0){let e=_(t.colormap||`viridis`),n=[];for(let t=0;t`rgb(${e[0]},${e[1]},${e[2]})`).join(`,`)})`}i.style.cssText=r?`position:absolute;inset:0 0 auto 0;height:${X}px;`:`position:absolute;inset:0 auto 0 0;width:${X}px;`,i.style.setProperty(`--xy-colorbar-gradient`,o),this._applySlot(i,`colorbar_bar`),n.appendChild(i);let s=t.domain||[0,1],c=Number(s[0]),l=Number(s[1]),u=l-c||1,d=O(c,l,8),f=Array.isArray(t.ticks),p=f?t.ticks:d.ticks,m=d.step;for(let e of p){let t=Number(e);if(!Number.isFinite(t)||tMath.max(c,l))continue;let i=document.createElement(`span`);i.textContent=f?re(t):N(t,m);let a=(t-c)/u;i.style.cssText=r?`position:absolute;left:${100*a}%;top:20px;transform:translateX(-50%);white-space:nowrap;`:`position:absolute;left:23px;top:${100*(1-a)}%;transform:translateY(-50%);white-space:nowrap;`,this._applySlot(i,`colorbar_tick`),n.appendChild(i)}if(t.label){let e=document.createElement(`span`);e.textContent=String(t.label),e.style.cssText=r?`position:absolute;left:50%;top:36px;transform:translateX(-50%);white-space:nowrap;`:`position:absolute;left:58px;top:50%;writing-mode:vertical-rl;transform:translateY(-50%) rotate(180deg);white-space:nowrap;`,this._applySlot(e,`colorbar_title`),n.appendChild(e)}n.title=`${t.label?t.label+`: `:``}${s[0]} – ${s[1]}`,e.appendChild(n),this._colorbar=n,this._colorbarHorizontal=r,this._positionColorbar()}_positionColorbar(){if(!this._colorbar)return;let e=this._colorbarHorizontal,t=!e&&this._compactVerticalColorbar,n=t?at:it;this._colorbar.style.left=(e?this.plot.x:this.plot.x+this.plot.w+this._rightAxisRoom+n)+`px`,this._colorbar.style.top=(e?this.plot.y+this.plot.h+(this._bottomAxisRoom||8):this.plot.y)+`px`,this._colorbar.style.width=(e?this.plot.w:t?X:66)+`px`,this._colorbar.style.height=(e?50:Math.max(24,this.plot.h))+`px`,this._colorbar.dataset.xyCompact=t?`true`:`false`;for(let e of this._colorbar.querySelectorAll(`[data-xy-slot="colorbar_tick"], [data-xy-slot="colorbar_title"]`))e.hidden=t}_initGl(e){let t=window.devicePixelRatio||1;this.dpr=t,this.canvas.width=this.plot.w*t,this.canvas.height=this.plot.h*t,this.chrome.width=this.size.w*t,this.chrome.height=this.size.h*t,this.chrome.style.width=this.size.w+`px`,this.chrome.style.height=this.size.h+`px`,this.overlay.width=this.size.w*t,this.overlay.height=this.size.h*t,this.overlay.style.width=this.size.w+`px`,this.overlay.style.height=this.size.h+`px`,Z.reserve(this);let n=this.canvas.getContext(`webgl2`,{antialias:!1,premultipliedAlpha:!0,alpha:!0});if(!n)throw Z.cancel(this),Error(`webgl2 unavailable`);this.gl=n,Z.acquired(this),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA),this._progCache=new Map,this._glPrograms=this._progCache,this.quad=n.createBuffer(),this.quad._fcId=++this._bufSeq,n.bindBuffer(n.ARRAY_BUFFER,this.quad),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),n.STATIC_DRAW),this.quadVao=n.createVertexArray(),n.bindVertexArray(this.quadVao),n.enableVertexAttribArray(F.a_corner),n.vertexAttribPointer(F.a_corner,2,n.FLOAT,!1,0,0),n.vertexAttribDivisor(F.a_corner,0),n.bindVertexArray(null),this.gpuTraces=this.spec.traces.map(t=>this._buildTrace(e,t)),this._updatePickable()}_updatePickable(){this._pickable=this.gpuTraces.some(e=>J(e.trace.kind).pointPick&&(e.tier!==`density`||e.drill)),this._pickable&&!this.pickFbo&&this._initPickTarget(),this._syncModebarSelect?.()}_prog(e,t,n){let r=this._progCache.get(e);return r||(r=le(this.gl,t,n),this._progCache.set(e,r)),r}get pointProg(){return this._prog(`point`,ue,de)}get pointSimpleProg(){return this._prog(`point-simple`,fe,pe)}get lineProg(){return this._prog(`line`,ye,be)}get segmentProg(){return this._prog(`segment`,xe,Se)}get meshProg(){return this._prog(`mesh`,Ce,we)}get areaProg(){return this._prog(`area`,Ee,De)}get rectProg(){return this._prog(`rect`,Oe,Ae)}get barProg(){return this._prog(`bar`,ke,Ae)}get pickProg(){return this._prog(`pick`,me,he)}get densityProg(){return this._prog(`density`,ge,_e)}get heatmapProg(){return this._prog(`heatmap`,ge,ve)}_lut(e){if(this._lutCache.has(e))return this._lutCache.get(e);let t=this.gl,n=t.createTexture();return t.bindTexture(t.TEXTURE_2D,n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,256,1,0,t.RGBA,t.UNSIGNED_BYTE,_(e)),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this._lutCache.set(e,n),n}_paletteLut(e){let t=`pal:`+e.join(`,`);if(this._lutCache.has(t))return this._lutCache.get(t);let n=this.gl,r=new Uint8Array(256*4);for(let t=0;t<256;t++){let n=b(e[t%e.length]);r[t*4]=n[0]*255,r[t*4+1]=n[1]*255,r[t*4+2]=n[2]*255,r[t*4+3]=255}let i=n.createTexture();return n.bindTexture(n.TEXTURE_2D,i),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,256,1,0,n.RGBA,n.UNSIGNED_BYTE,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this._lutCache.set(t,i),i}_buildTrace(e,t){this.gl;let n={trace:t,tier:t.tier,color:[.3,.47,.66,1],xAxis:typeof t.x_axis==`string`?t.x_axis:`x`,yAxis:typeof t.y_axis==`string`?t.y_axis:`y`};if(t.tier===`density`){let r=t.density,i=this.spec.columns[r.buf],a=this._columnView(e,i),o=r.enc===`log-u8`?Fe(a,r.max):a;return n.densityNormMax=r.max,n.density={w:r.w,h:r.h,max:r.max,normMax:r.max,colormap:r.colormap,color:r.color?x(this.root,r.color,[.3,.47,.66,1]):null,xRange:r.x_range,yRange:r.y_range,grid:Ie(o),tex:this._uploadGrid(o,r.w,r.h,r.max),lut:this._lut(r.colormap)},n.sampleOverlay=this._buildDensitySample(t,r.sample,e),n._shownDensity=n.density,V(this,n,n.density),n}if(J(t.kind).build(this,n,t,e),t.keys&&Number.isInteger(t.keys.lo)&&Number.isInteger(t.keys.hi)){let r=this._columnView(e,this.spec.columns[t.keys.lo]),i=this._columnView(e,this.spec.columns[t.keys.hi]),a=Math.min(n.n||0,r.length,i.length);n._transitionKeys=Array(a),n._transitionKeyIndex=new Map;for(let e=0;et.channels&&t.channels[e],a=Number(t.style&&t.style.artist_alpha);if(i(`opacity`)||i(`artist_alpha`)||i(r)||i(`symbol`)||Number.isFinite(a)){let t=new Float32Array(e.n*4);for(let n=0;n{let s=i(r);if(!s)return;let c=this._columnView(n,this.spec.columns[s.buf]);for(let n=0;n1?t[n*r+1]:t[n*r])*this.dpr;e.radiusBuf=this._upload(i)}t.stroke&&t.stroke.mode===`direct_rgba`&&(e.strokeBuf=this._upload(this._columnView(n,this.spec.columns[t.stroke.buf])))}_buildScatterMark(e,t,n){this._buildXY(e,t,n),e.colorMode=0,e.color=x(this.root,t.color&&t.color.color,[.3,.47,.66,1]),t.color&&t.color.mode===`continuous`?(e.colorMode=1,e._cpu.color=this._columnView(n,this.spec.columns[t.color.buf]),e.cBuf=this._upload(e._cpu.color),e.lut=this._lut(t.color.colormap)):t.color&&t.color.mode===`categorical`?(e.colorMode=2,e._cpu.color=this._columnView(n,this.spec.columns[t.color.buf]),e.cBuf=this._upload(e._cpu.color),e.lut=this._paletteLut(t.color.palette)):t.color&&t.color.mode===`direct_rgba`&&(e.colorMode=3,e._cpu.rgba=this._columnView(n,this.spec.columns[t.color.buf]),e.rgbaBuf=this._upload(e._cpu.rgba)),e.sizeMode=0,e.size=t.size&&t.size.size||4,e.sizeRange=[2,18],t.size&&t.size.mode===`continuous`&&(e.sizeMode=1,e._cpu.size=this._columnView(n,this.spec.columns[t.size.buf]),e.sBuf=this._upload(e._cpu.size),e.sizeRange=t.size.range_px),this._buildInstanceStyleChannels(e,t,n,`stroke_width`),this._pointMarkStyle(e,t)}_pointMarkStyle(e,t){let n=t.style||{};e.symbol={circle:0,square:1,diamond:2,triangle:3,cross:4,hexagon:5,pentagon:6,star:7,triangle_down:8,triangle_left:9,triangle_right:10,x:11,point:12,pixel:13,thin_diamond:14,plus_line:15,x_line:16}[n.symbol]||0,e.pointStrokeWidth=Number(n.stroke_width)||0,e.pointStrokeFace=!n.stroke&&(!t.stroke||t.stroke.mode===`match_fill`),e.pointStroke=n.stroke?x(this.root,n.stroke,[e.color[0],e.color[1],e.color[2],1]):null}_sampleTraceSpec(e,t){return{id:e.id,kind:`scatter`,name:e.name,style:t.style||e.style||{},tier:`sampled`,x:t.x&&t.x.col,y:t.y&&t.y.col,x_axis:e.x_axis,y_axis:e.y_axis,color:t.color,size:t.size,stroke:t.stroke,channels:t.channels}}_buildDensitySample(e,t,n){if(!t||!t.x||!t.y||t.x.col===void 0||t.y.col===void 0)return null;let r=this._sampleTraceSpec(e,t),i={trace:r,tier:`sampled`,xAxis:typeof e.x_axis==`string`?e.x_axis:`x`,yAxis:typeof e.y_axis==`string`?e.y_axis:`y`};return this._buildScatterMark(i,r,n),i.win={x0:t.x_range[0],x1:t.x_range[1],y0:t.y_range[0],y1:t.y_range[1]},i.sample={n:t.n,visible:t.visible},i}_destroyDensitySample(e){let t=e&&e.sampleOverlay;if(!(!t||!this.gl)){for(let e of[t.xBuf,t.yBuf,t.cBuf,t.rgbaBuf,t.sBuf,t.styleBuf,t.strokeBuf,t.selBuf,t.dBuf])e&&this.gl.deleteBuffer(e);e.sampleOverlay=null}}_applyDensitySample(e,t,n){if(this._destroyDensitySample(e),!t||!t.x||!t.y||t.x.buf===void 0||t.y.buf===void 0){this._refreshReductionBadges();return}let r=this.gl,i={id:e.trace.id,kind:`scatter`,name:e.trace.name,style:t.style||e.trace.style||{},tier:`sampled`,x_axis:e.trace.x_axis,y_axis:e.trace.y_axis,color:t.color,size:t.size,stroke:t.stroke,channels:t.channels},a={trace:i,tier:`sampled`,xAxis:e.xAxis,yAxis:e.yAxis,xBuf:r.createBuffer(),yBuf:r.createBuffer(),xMeta:{offset:t.x.offset,scale:t.x.scale},yMeta:{offset:t.y.offset,scale:t.y.scale},n:Math.min(t.x.len,t.y.len),win:{x0:t.x_range[0],x1:t.x_range[1],y0:t.y_range[0],y1:t.y_range[1]},sample:{n:t.n,visible:t.visible},selActive:!1,colorMode:0,color:x(this.root,t.color&&t.color.color,[.3,.47,.66,1]),sizeMode:0,size:t.size&&t.size.size||4,sizeRange:[2,18]};if(r.bindBuffer(r.ARRAY_BUFFER,a.xBuf),r.bufferData(r.ARRAY_BUFFER,this._asF32(n[t.x.buf]),r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,a.yBuf),r.bufferData(r.ARRAY_BUFFER,this._asF32(n[t.y.buf]),r.STATIC_DRAW),t.color&&t.color.buf!==void 0){a.colorMode=t.color.mode===`continuous`?1:t.color.mode===`categorical`?2:3;let e=t.color.dtype===`u8`?this._asU8(n[t.color.buf]):this._asF32(n[t.color.buf]),i=a.colorMode===3?`rgbaBuf`:`cBuf`;a[i]=r.createBuffer(),a[i]._fcType=e instanceof Uint8Array?r.UNSIGNED_BYTE:r.FLOAT,r.bindBuffer(r.ARRAY_BUFFER,a[i]),r.bufferData(r.ARRAY_BUFFER,e,r.STATIC_DRAW),a.colorMode!==3&&(a.lut=t.color.mode===`continuous`?this._lut(t.color.colormap):this._paletteLut(t.color.palette))}t.size&&t.size.mode===`continuous`&&(a.sizeMode=1,a.sBuf=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,a.sBuf),r.bufferData(r.ARRAY_BUFFER,this._asF32(n[t.size.buf]),r.STATIC_DRAW),a.sizeRange=t.size.range_px);let o=e=>t.channels&&t.channels[e],s=Number(i.style&&i.style.artist_alpha);if(o(`opacity`)||o(`artist_alpha`)||o(`stroke_width`)||o(`symbol`)||Number.isFinite(s)){let e=new Float32Array(a.n*4);for(let t=0;t{let s=o(t);if(!s)return;let c=s.dtype===`u8`?this._asU8(n[s.buf]):this._asF32(n[s.buf]),l=s.components||1;for(let t=0;tI(n,e,t);if(!t){n.uniform1i(r(`u_gradMode`),0);return}n.uniform1i(r(`u_gradMode`),t.mode),n.uniform1i(r(`u_gradDir`),t.dir),n.uniform1i(r(`u_gradCount`),t.count),n.uniform1fv(r(`u_gradPos`),t.pos),n.uniform4fv(r(`u_gradColor`),t.colors)}_fillOpacity(e,t=1){return Number(e.opacity??t)*Number(e.fill_opacity??1)}_strokeOpacity(e,t=1){return Number(e.opacity??t)*Number(e.stroke_opacity??1)}_setRectStyleUniforms(e,t){let n=this.gl,r=t=>I(n,e,t);n.uniform2f(r(`u_res`),this.canvas.width,this.canvas.height);let i=t.cornerRadius||[0,0];n.uniform2f(r(`u_radius`),i[0]*this.dpr,i[1]*this.dpr),n.uniform1f(r(`u_strokeWidth`),(t.strokeWidth||0)*this.dpr);let a=t.strokeColor||[0,0,0,0];n.uniform4f(r(`u_stroke`),a[0],a[1],a[2],a[3]),n.uniform1i(r(`u_strokeMode`),t.strokeBuf?1:t.strokeMatchFill?2:0),n.uniform1f(r(`u_strokeOpacity`),this._strokeOpacity(t.trace.style||{})),this._setGradientUniforms(e,t.grad)}_rectMarkStyleGpu(e,t){let n=t.style||{},r=n.corner_radius;e.cornerRadius=Array.isArray(r)?[Number(r[0])||0,Number(r[1])||0]:[Number(r)||0,Number(r)||0],e.strokeWidth=Number(n.stroke_width)||0,e.strokeMatchFill=!!(t.stroke&&t.stroke.mode===`match_fill`);let i=[e.color[0],e.color[1],e.color[2],1];e.strokeColor=n.stroke?x(this.root,n.stroke,i):i,e.grad=this._resolveMarkFill(n,e.color)}_smoothArrays(e,t,n,r,i){return!e.style||e.style.curve!==`smooth`?null:Me(t,n,r||null,i,32768)}_stepArrays(e,t,n,r){let i=e.style&&e.style.step;if(!i||r<2)return null;let a=i===`mid`?3:2,o=1+(r-1)*a,s=new Float32Array(o),c=new Float32Array(o);s[0]=t[0],c[0]=n[0];let l=1;for(let e=1;ethis._columnView(n,this.spec.columns[e])):this._columnView(n,this.spec.columns[r.buf]);e.heatmap={w:r.w,h:r.h,xRange:r.x_range,yRange:r.y_range,colormap:r.colormap,truecolor:i,tex:i?this._uploadRgbaGrid(a,r.w,r.h):this._uploadHeatmapGrid(a,r.w,r.h),lut:i?null:this._lut(r.colormap)},i||(e._cpuHeatmap={grid:a})}_uploadRgbaGrid(e,t,n){let r=this.gl,i=r.createTexture(),a=new Uint8Array(t*n*4);for(let r=0;rr.byteLength)throw RangeError(`column extends past chart payload`);if(c%s!==0)throw RangeError(`column is misaligned`);return t.dtype===`u8`?new Uint8Array(r.buffer,c,a):t.dtype===`u32`?new Uint32Array(r.buffer,c,a):new Float32Array(r.buffer,c,a)}_upload(e){let t=this.gl,n=t.createBuffer();return n._fcId=++this._bufSeq,n._fcType=e instanceof Uint8Array?t.UNSIGNED_BYTE:t.FLOAT,t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW),n}_bindVao(e,t,n,r){let i=this.gl;e._vaos||=new Map;let a=n.join(`|`),o=e._vaos.get(t);if(!o||o.sig!==a){o&&i.deleteVertexArray(o.vao);let n=i.createVertexArray();i.bindVertexArray(n),r(),o={vao:n,sig:a},e._vaos.set(t,o)}else i.bindVertexArray(o.vao)}_deleteVaos(e){if(!e||!e._vaos)return;let t=this.gl;if(t)for(let{vao:n}of e._vaos.values())t.deleteVertexArray(n);e._vaos=null}_vaoAttr(e,t,n,r,i=1,a=!1){let o=this.gl;o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e),o.vertexAttribPointer(e,i,t._fcType||o.FLOAT,a,0,n),o.vertexAttribDivisor(e,r)}_initPickTarget(){let e=this.gl;this.pickTex=e.createTexture(),this._allocPickTex(),this.pickFbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.pickFbo),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.pickTex,0),e.bindFramebuffer(e.FRAMEBUFFER,null),this._pickDirty=!0}_allocPickTex(){let e=this.gl;e.bindTexture(e.TEXTURE_2D,this.pickTex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,this.canvas.width,this.canvas.height,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),this._pickW=this.canvas.width,this._pickH=this.canvas.height}_map(e,t,n,r=null){if(!r)return[2/((n-t)*e.scale),(e.offset-t)/(n-t)*2-1];let i=this._axis(r),a=this._axisCoord(i,t),o=this._axisCoord(i,n);if(![a,o].every(Number.isFinite)||o===a)return[0,-2];let s=2/(o-a);return[s,-1-a*s]}_mapConst(e,t,n,r=null){if(!r)return(e-t)/(n-t)*2-1;let i=this._axis(r),a=this._axisCoord(i,e),o=this._axisCoord(i,t),s=this._axisCoord(i,n);return![a,o,s].every(Number.isFinite)||s===o?-2:(a-o)/(s-o)*2-1}_edgePadForValue(e,t,n,r){if(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||n===t)return 0;let i=Math.abs(n-t)*1e-10+1e-12,a=Math.max(1,r||1),o=Math.max(2,Math.ceil(this.dpr||1));return Math.abs(e-t)<=i?-(2*o)/a:Math.abs(e-n)<=i?2*o/a:0}_setAxisUniforms(e,t,n,r){let i=this.gl,a=t=>I(i,e,t);i.uniform2f(a(`${t}meta`),n&&Number.isFinite(n.offset)?n.offset:0,n&&n.scale?n.scale:1),i.uniform1i(a(`${t}mode`),this._axisMode(r))}draw(e=!1){if(!(this._destroyed||this._glLost||!this.gl)){if(this._updateZoomMenuLabel?.(),this._raf){this._rafKeepPick=this._rafKeepPick&&e;return}this._rafKeepPick=e,this._raf=requestAnimationFrame(()=>{this._raf=null,!this._destroyed&&this._drawNow()})}}_drawNow(){if(this._destroyed||!this.gl||this._glLost)return;this._healStaleTheme();let e=this.gl,{x0:t,x1:n,y0:r,y1:i}=this.view;e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.canvas.width,this.canvas.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);let a=e=>{if(e.tier===`density`){let[t,n]=this._axisRange(e.xAxis),[r,i]=this._axisRange(e.yAxis);tt(this,e,t,n,r,i);return}J(e.trace.kind).draw(this,e,t,n,r,i)};for(let e of this._transitionOldTraces||[])a(e);for(let e of this.gpuTraces)a(e);this._drawHoverState(),this._repositionTooltip(),this._rafKeepPick||(this._pickDirty=!0),this._rafKeepPick=!1,this._drawChrome(),this._renderLassoSelection?.()}_now(){return performance.now()}_canDrawSimplePoints(e){return e.colorMode===0&&e.sizeMode===0&&!e.selActive&&!e.rgbaBuf&&!e.styleBuf&&!e.strokeBuf&&(e.symbol||0)===0&&(e.pointStrokeWidth||0)<=0&&Math.max(e.lodBlendShown??0,e.lodBlend??0)<=.001}_drawPoints(e,t,n,r=1){r*=e._transitionOpacity??1;let i=e._transitionScale??1;if(this._canDrawSimplePoints(e)){this._drawSimplePoints(e,t,n,r);return}let a=this.gl,o=this.pointProg;a.useProgram(o);let s=e=>I(a,o,e);a.uniform2f(s(`u_xmap`),t[0],t[1]),a.uniform2f(s(`u_ymap`),n[0],n[1]),this._setAxisUniforms(o,`u_x`,e.xMeta,e.xAxis),this._setAxisUniforms(o,`u_y`,e.yMeta,e.yAxis),a.uniform1f(s(`u_dpr`),this.dpr);let c=!!(e._transitionPrevXBuf&&e._transitionPrevYBuf);a.uniform1i(s(`u_transitionActive`),+!!c),a.uniform1f(s(`u_transitionProgress`),e._transitionPositionProgress??1),a.uniform1f(s(`u_size`),e.size*i),a.uniform1i(s(`u_sizeMode`),e.sizeMode),a.uniform2f(s(`u_sizeRange`),e.sizeRange[0]*i,e.sizeRange[1]*i),a.uniform1i(s(`u_colorMode`),e.colorMode);let l=this._fillOpacity(e.trace.style,.8)*r;a.uniform1f(s(`u_opacity`),l),a.uniform1f(s(`u_selectedOpacity`),this._markStateNumber(`selected`,`opacity`,1)),a.uniform1f(s(`u_unselectedOpacity`),this._markStateNumber(`unselected`,`opacity`,.12));let u=(e,t)=>{let n=t?x(this.root,t,[0,0,0,1]):null;a.uniform4f(e,n?n[0]:0,n?n[1]:0,n?n[2]:0,+!!n)};u(s(`u_selColor`),this._markStateValue(`selected`,`color`)),u(s(`u_unselColor`),this._markStateValue(`unselected`,`color`));let[d,f,p,m]=e.color;a.uniform4f(s(`u_color`),d,f,p,m),a.uniform1i(s(`u_symbol`),e.symbol||0);let h=e.pointStroke;a.uniform1f(s(`u_ptStrokeWidth`),(e.pointStrokeWidth||0)*this.dpr),a.uniform1i(s(`u_ptStrokeFace`),+!!e.pointStrokeFace),a.uniform1i(s(`u_strokeMode`),+!!e.strokeBuf),a.uniform1f(s(`u_strokeOpacity`),this._strokeOpacity(e.trace.style,.8)*r),a.uniform4f(s(`u_ptStroke`),h?h[0]:0,h?h[1]:0,h?h[2]:0,h?h[3]:0),a.uniform1i(s(`u_selActive`),+!!e.selActive);let g=e.colorMode!==0&&e.cBuf,_=e.sizeMode===1&&e.sBuf,v=e.selActive&&e.selBuf,y=e.colorMode===3&&e.rgbaBuf,b=!!e.styleBuf,S=!!e.strokeBuf;e.lut&&(a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,e.lut),a.uniform1i(s(`u_lut`),0));let C=e.lodBlend??0,w=e.lodBlendShown??C;if(Math.abs(w-C)>.005&&!this._prefersReducedMotion()){let t=this._now(),n=e._blendTick?Math.min(100,t-e._blendTick):16;e._blendTick=t,w+=(C-w)*(1-Math.exp(-n/90)),e.lodBlendShown=w,this.draw()}else e.lodBlendShown=w=C,e._blendTick=0;a.uniform1f(s(`u_dblend`),w);let T=w>.001&&e.dBuf&&e.dlut;T&&(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,e.dlut)),a.uniform1i(s(`u_dlut`),1),this._bindVao(e,`points`,[e.xBuf._fcId,e.yBuf._fcId,g?e.cBuf._fcId:0,_?e.sBuf._fcId:0,v?e.selBuf._fcId:0,T?e.dBuf._fcId:0,c?e._transitionPrevXBuf._fcId:0,c?e._transitionPrevYBuf._fcId:0,y?e.rgbaBuf._fcId:0,b?e.styleBuf._fcId:0,S?e.strokeBuf._fcId:0],()=>{this._vaoAttr(F.ax,e.xBuf,0,0),this._vaoAttr(F.ay,e.yBuf,0,0),g&&this._vaoAttr(F.a_cval,e.cBuf,0,0),_&&this._vaoAttr(F.a_sval,e.sBuf,0,0),v&&this._vaoAttr(F.a_sel,e.selBuf,0,0),T&&this._vaoAttr(F.a_dval,e.dBuf,0,0),c&&(this._vaoAttr(F.a_prevx,e._transitionPrevXBuf,0,0),this._vaoAttr(F.a_prevy,e._transitionPrevYBuf,0,0)),y&&this._vaoAttr(F.a_rgba,e.rgbaBuf,0,0,4,!0),b&&this._vaoAttr(F.a_style,e.styleBuf,0,0,4),S&&this._vaoAttr(F.a_stroke,e.strokeBuf,0,0,4,!0)}),g||a.vertexAttrib1f(F.a_cval,0),_||a.vertexAttrib1f(F.a_sval,.5),v||a.vertexAttrib1f(F.a_sel,1),T||a.vertexAttrib1f(F.a_dval,0),y||a.vertexAttrib4f(F.a_rgba,d,f,p,m),b||a.vertexAttrib4f(F.a_style,1,-1,-1,-1),S||a.vertexAttrib4f(F.a_stroke,d,f,p,m),a.drawArrays(a.POINTS,0,e.n)}_drawSimplePoints(e,t,n,r=1){let i=this.gl,a=this.pointSimpleProg;i.useProgram(a);let o=e=>I(i,a,e);i.uniform2f(o(`u_xmap`),t[0],t[1]),i.uniform2f(o(`u_ymap`),n[0],n[1]),this._setAxisUniforms(a,`u_x`,e.xMeta,e.xAxis),this._setAxisUniforms(a,`u_y`,e.yMeta,e.yAxis),i.uniform1f(o(`u_dpr`),this.dpr);let s=!!(e._transitionPrevXBuf&&e._transitionPrevYBuf);i.uniform1i(o(`u_transitionActive`),+!!s),i.uniform1f(o(`u_transitionProgress`),e._transitionPositionProgress??1),i.uniform1f(o(`u_size`),e.size*(e._transitionScale??1));let[c,l,u,d]=e.color;i.uniform4f(o(`u_color`),c,l,u,d*this._fillOpacity(e.trace.style,.8)*r),this._bindVao(e,`points-simple`,[e.xBuf._fcId,e.yBuf._fcId,s?e._transitionPrevXBuf._fcId:0,s?e._transitionPrevYBuf._fcId:0],()=>{this._vaoAttr(F.ax,e.xBuf,0,0),this._vaoAttr(F.ay,e.yBuf,0,0),s&&(this._vaoAttr(F.a_prevx,e._transitionPrevXBuf,0,0),this._vaoAttr(F.a_prevy,e._transitionPrevYBuf,0,0))}),i.drawArrays(i.POINTS,0,e.n)}_drawHoverState(){let e=this._hoverTarget;if(!e||!e.g)return;let t=e.g;if(t.trace.kind!==`scatter`||t.tier===`density`||!Number.isInteger(e.index)||e.index<0||e.index>=t.n)return;let[n,r]=this._axisRange(t.xAxis),[i,a]=this._axisRange(t.yAxis);this._drawHoverPoint(t,e.index,this._map(t.xMeta,n,r,t.xAxis),this._map(t.yMeta,i,a,t.yAxis))}_drawHoverPoint(e,t,n,r){let i=this.gl,a=this.pointProg;i.useProgram(a);let o=e=>I(i,a,e);i.uniform2f(o(`u_xmap`),n[0],n[1]),i.uniform2f(o(`u_ymap`),r[0],r[1]),this._setAxisUniforms(a,`u_x`,e.xMeta,e.xAxis),this._setAxisUniforms(a,`u_y`,e.yMeta,e.yAxis);let s=Math.max((e.size||4)*1.75,(e.size||4)+5),c=Math.max(0,this._markStateNumber(`hover`,`size`,s)),l=Math.max(0,Math.min(1,this._markStateNumber(`hover`,`opacity`,.95))),u=x(this.root,this._markStatePaint(`hover`,`color`,`rgba(15,23,42,.92)`),[.06,.09,.16,.92]);i.uniform1f(o(`u_dpr`),this.dpr),i.uniform1f(o(`u_size`),c),i.uniform1i(o(`u_sizeMode`),0),i.uniform2f(o(`u_sizeRange`),c,c),i.uniform1i(o(`u_colorMode`),0),i.uniform1f(o(`u_opacity`),l),i.uniform1f(o(`u_selectedOpacity`),1),i.uniform1f(o(`u_unselectedOpacity`),1),i.uniform4f(o(`u_color`),u[0],u[1],u[2],1),i.uniform1i(o(`u_selActive`),0),i.uniform1f(o(`u_dblend`),0),this._bindVao(e,`hover`,[e.xBuf._fcId,e.yBuf._fcId],()=>{this._vaoAttr(F.ax,e.xBuf,0,0),this._vaoAttr(F.ay,e.yBuf,0,0)}),i.vertexAttrib1f(F.a_cval,0),i.vertexAttrib1f(F.a_sval,.5),i.vertexAttrib1f(F.a_sel,1),i.vertexAttrib1f(F.a_dval,0),i.drawArrays(i.POINTS,t,1)}_drawDensity(e,t,n=1){let r=this.gl,i=t||e.density;if(!i||!i.tex||!r.isTexture(i.tex))return;n*=e._transitionOpacity??1;let a=this.densityProg;r.useProgram(a);let o=e=>I(r,a,e),{x0:s,x1:c,y0:l,y1:u}=this.view,[d,f]=this._axisRange(e.xAxis),[p,m]=this._axisRange(e.yAxis);r.uniform4f(o(`u_view`),d??s,f??c,p??l,m??u),r.uniform1i(o(`u_xmode`),this._axisMode(e.xAxis)),r.uniform1i(o(`u_ymode`),this._axisMode(e.yAxis)),r.uniform4f(o(`u_gridRange`),i.xRange[0],i.xRange[1],i.yRange[0],i.yRange[1]),r.uniform1f(o(`u_opacity`),this._fillOpacity(e.trace.style)*n);let h=i.color;r.uniform1i(o(`u_constantColor`),+!!h),r.uniform4f(o(`u_color`),...h||[1,1,1,1]),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,i.tex),r.uniform1i(o(`u_grid`),0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,i.lut),r.uniform1i(o(`u_lut`),1),r.bindVertexArray(this.quadVao),r.drawArrays(r.TRIANGLE_STRIP,0,4)}_drawHeatmap(e){let t=e.heatmap;if(!t)return;let n=this.gl,r=this.heatmapProg;n.useProgram(r);let i=e=>I(n,r,e),{x0:a,x1:o,y0:s,y1:c}=this.view,[l,u]=this._axisRange(e.xAxis),[d,f]=this._axisRange(e.yAxis);n.uniform4f(i(`u_view`),l??a,u??o,d??s,f??c),n.uniform1i(i(`u_xmode`),this._axisMode(e.xAxis)),n.uniform1i(i(`u_ymode`),this._axisMode(e.yAxis));let p=(l??a)>(u??o),m=(d??s)>(f??c);n.uniform4f(i(`u_gridRange`),t.xRange[+!!p],t.xRange[+!p],t.yRange[+!!m],t.yRange[+!m]),n.uniform1f(i(`u_opacity`),this._fillOpacity(e.trace.style)*(e._transitionOpacity??1)),n.uniform1i(i(`u_truecolor`),+!!t.truecolor),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,t.tex),n.uniform1i(i(`u_grid`),0),t.truecolor||(n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,t.lut),n.uniform1i(i(`u_lut`),1)),n.bindVertexArray(this.quadVao),n.drawArrays(n.TRIANGLE_STRIP,0,4)}_drawLine(e,t,n,r=null,i=null,a=null){if(e.n<2)return;let o=this.gl;o.useProgram(this.lineProg);let s=e=>I(o,this.lineProg,e);o.uniform2f(s(`u_xmap`),t[0],t[1]),o.uniform2f(s(`u_ymap`),n[0],n[1]),this._setAxisUniforms(this.lineProg,`u_x`,e.xMeta,e.xAxis),this._setAxisUniforms(this.lineProg,`u_y`,e.yMeta,e.yAxis),o.uniform2f(s(`u_res`),this.canvas.width,this.canvas.height);let c=!!(e._transitionPrevXBuf&&e._transitionPrevYBuf);o.uniform1i(s(`u_transitionActive`),+!!c),o.uniform1f(s(`u_transitionProgress`),e._transitionPositionProgress??1);let l=Math.max(0,Math.min(1,e._transitionReveal??1));o.uniform1f(s(`u_revealProgress`),l),o.uniform1f(s(`u_revealSegments`),e.n-1),o.uniform1f(s(`u_width`),(i??e.trace.style.width??1.5)*this.dpr);let[u,d,f,p]=r||e.color,m=this._strokeOpacity(e.trace.style)*(a??1)*(e._transitionOpacity??1);o.uniform4f(s(`u_color`),u,d,f,p*m);let h=this._lineDash(e);this._bindVao(e,`line`,[e.xBuf._fcId,e.yBuf._fcId,h?e._lenBuf._fcId:0,c?e._transitionPrevXBuf._fcId:0,c?e._transitionPrevYBuf._fcId:0],()=>{this._vaoAttr(F.ax0,e.xBuf,0,1),this._vaoAttr(F.ax1,e.xBuf,4,1),this._vaoAttr(F.ay0,e.yBuf,0,1),this._vaoAttr(F.ay1,e.yBuf,4,1),h&&(this._vaoAttr(F.a_len0,e._lenBuf,0,1),this._vaoAttr(F.a_len1,e._lenBuf,4,1)),c&&(this._vaoAttr(F.a_prevx,e._transitionPrevXBuf,0,1),this._vaoAttr(F.a_prevy,e._transitionPrevYBuf,0,1),this._vaoAttr(F.a_prevx1,e._transitionPrevXBuf,4,1),this._vaoAttr(F.a_prevy1,e._transitionPrevYBuf,4,1))});let g=Math.max(0,Math.min(e.n-1,Math.ceil((e.n-1)*l)));o.drawArraysInstanced(o.TRIANGLE_STRIP,0,4,g)}_drawSegments(e,t,n){if(e.n<1)return;let r=this.gl,i=this.segmentProg;r.useProgram(i);let a=e=>I(r,i,e);r.uniform2f(a(`u_xmap`),t[0],t[1]),r.uniform2f(a(`u_ymap`),n[0],n[1]),this._setAxisUniforms(i,`u_x0`,e.x0Meta,e.xAxis),this._setAxisUniforms(i,`u_x1`,e.x1Meta,e.xAxis),this._setAxisUniforms(i,`u_y0`,e.y0Meta,e.yAxis),this._setAxisUniforms(i,`u_y1`,e.y1Meta,e.yAxis),r.uniform2f(a(`u_res`),this.canvas.width,this.canvas.height),r.uniform1f(a(`u_width`),(e.trace.style.width??1.5)*this.dpr),r.uniform1f(a(`u_animationProgress`),e._transitionScale??1);let[o,s,c,l]=e.color;r.uniform4f(a(`u_color`),o,s,c,l),r.uniform1f(a(`u_opacity`),this._strokeOpacity(e.trace.style)*(e._transitionOpacity??1)),r.uniform1i(a(`u_colorMode`),e.colorMode||0);let u=this._segmentDash(e,i);e.colorMode&&e.lut&&(r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,e.lut),r.uniform1i(a(`u_lut`),0)),this._bindVao(e,`segment`,[e.x0Buf._fcId,e.x1Buf._fcId,e.y0Buf._fcId,e.y1Buf._fcId,e.colorMode&&e.cBuf?e.cBuf._fcId:0,e.rgbaBuf?e.rgbaBuf._fcId:0,e.styleBuf?e.styleBuf._fcId:0,u?e._segmentDashOffsetBuf._fcId:0,u?e._segmentDashDirBuf._fcId:0],()=>{this._vaoAttr(F.ax0,e.x0Buf,0,1),this._vaoAttr(F.ax1,e.x1Buf,0,1),this._vaoAttr(F.ay0,e.y0Buf,0,1),this._vaoAttr(F.ay1,e.y1Buf,0,1),e.colorMode&&e.cBuf&&this._vaoAttr(F.a_cval,e.cBuf,0,1),e.rgbaBuf&&this._vaoAttr(F.a_rgba,e.rgbaBuf,0,1,4,!0),e.styleBuf&&this._vaoAttr(F.a_style,e.styleBuf,0,1,4),u&&(this._vaoAttr(F.a_dash0,e._segmentDashOffsetBuf,0,1),this._vaoAttr(F.a_dashDir,e._segmentDashDirBuf,0,1))}),e.cBuf||r.vertexAttrib1f(F.a_cval,0),e.rgbaBuf||r.vertexAttrib4f(F.a_rgba,o,s,c,l),e.styleBuf||r.vertexAttrib4f(F.a_style,1,-1,-1,-1);let d=Math.max(0,Math.min(e.n,Math.ceil(e.n*(e._transitionReveal??1))));r.drawArraysInstanced(r.TRIANGLE_STRIP,0,4,d)}_segmentDash(e,t){let n=this.gl,r=e=>I(n,t,e),i=e.trace.style&&e.trace.style.dash,a=e._segmentCpu;if(!i||!i.length||!a)return n.uniform1i(r(`u_dashCount`),0),!1;let o=e.n,s=e._segmentDashOffsets?.length===o?e._segmentDashOffsets:e._segmentDashOffsets=new Float32Array(o),c=e._segmentDashDirections?.length===o?e._segmentDashDirections:e._segmentDashDirections=new Float32Array(o),l=Array(o),u=Array(o),d=new Float32Array(o),f=new Map,p=(e,t)=>{let n=f.get(e);n?n.push(t):f.set(e,[t])},m=(e,t)=>`${Math.round(e*1e3)},${Math.round(t*1e3)}`,h=this.dpr;for(let t=0;t{let t=e,n=0;for(;;){let e=(f.get(t)||[]).find(e=>!g[e]);if(e===void 0)break;g[e]=1,l[e]===t?(s[e]=n,c[e]=1,t=u[e]):(s[e]=n+d[e],c[e]=-1,t=l[e]),n+=d[e]}};for(let[e,t]of f)t.length===1&&_(e);for(let e=0;ee?(n.bindBuffer(n.ARRAY_BUFFER,e),n.bufferData(n.ARRAY_BUFFER,t,n.DYNAMIC_DRAW),e):this._upload(t);e._segmentDashOffsetBuf=v(e._segmentDashOffsetBuf,s),e._segmentDashDirBuf=v(e._segmentDashDirBuf,c);let y=new Float32Array(8),b=Math.min(i.length,8),x=0;for(let e=0;eI(r,i,e);r.uniform2f(a(`u_xmap`),t[0],t[1]),r.uniform2f(a(`u_ymap`),n[0],n[1]);for(let t of[`x0`,`x1`,`x2`])this._setAxisUniforms(i,`u_`+t,e[t+`Meta`],e.xAxis);for(let t of[`y0`,`y1`,`y2`])this._setAxisUniforms(i,`u_`+t,e[t+`Meta`],e.yAxis);r.uniform1i(a(`u_colorMode`),e.colorMode||0),r.uniform1f(a(`u_opacity`),this._fillOpacity(e.trace.style)),r.uniform4f(a(`u_color`),e.color[0],e.color[1],e.color[2],e.color[3]);let o=e.meshStroke||[0,0,0,0];r.uniform4f(a(`u_stroke`),o[0],o[1],o[2],o[3]),r.uniform1f(a(`u_strokeWidth`),e.meshStrokeWidth||0),r.uniform1i(a(`u_strokeMode`),e.strokeBuf?1:e.strokeMatchFill?2:0),r.uniform1f(a(`u_strokeOpacity`),this._strokeOpacity(e.trace.style)),e.colorMode&&e.lut&&(r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,e.lut),r.uniform1i(a(`u_lut`),0));let s=[`x0`,`x1`,`x2`,`y0`,`y1`,`y2`].map(t=>e[t+`Buf`]._fcId);s.push(e.cBuf?e.cBuf._fcId:0,e.rgbaBuf?e.rgbaBuf._fcId:0,e.styleBuf?e.styleBuf._fcId:0,e.strokeBuf?e.strokeBuf._fcId:0),this._bindVao(e,`mesh`,s,()=>{for(let t of[`x0`,`x1`,`x2`,`y0`,`y1`,`y2`])this._vaoAttr(F[`a`+t],e[t+`Buf`],0,1);e.cBuf&&this._vaoAttr(F.a_cval,e.cBuf,0,1),e.rgbaBuf&&this._vaoAttr(F.a_rgba,e.rgbaBuf,0,1,4,!0),e.styleBuf&&this._vaoAttr(F.a_style,e.styleBuf,0,1,4),e.strokeBuf&&this._vaoAttr(F.a_stroke,e.strokeBuf,0,1,4,!0)}),e.cBuf||r.vertexAttrib1f(F.a_cval,0),e.rgbaBuf||r.vertexAttrib4f(F.a_rgba,...e.color),e.styleBuf||r.vertexAttrib4f(F.a_style,1,-1,-1,-1),e.strokeBuf||r.vertexAttrib4f(F.a_stroke,...o),r.drawArraysInstanced(r.TRIANGLES,0,3,e.n)}_lineDash(e){let t=this.gl,n=e=>I(t,this.lineProg,e),r=e.trace.style&&e.trace.style.dash;if(!r||!r.length||!e._dashX)return t.uniform1i(n(`u_dashCount`),0),!1;let i=e.n;(!e._lenArr||e._lenArr.length!==i)&&(e._lenArr=new Float32Array(i));let a=e._lenArr,o=this.dpr,s=this._dataPx(e.xAxis,this._decodeValue(e._dashX,e.xMeta,0)),c=this._dataPx(e.yAxis,this._decodeValue(e._dashY,e.yMeta,0)),l=0;a[0]=0;for(let t=1;tI(i,a,e);i.uniform2f(o(`u_xmap`),t[0],t[1]),i.uniform2f(o(`u_ymap`),n[0],n[1]),i.uniform2f(o(`u_bmap`),r[0],r[1]),this._setAxisUniforms(a,`u_x`,e.xMeta,e.xAxis),this._setAxisUniforms(a,`u_y`,e.yMeta,e.yAxis),this._setAxisUniforms(a,`u_b`,e.baseMeta,e.yAxis);let s=Math.max(0,Math.min(1,e._transitionReveal??1));i.uniform1f(o(`u_revealProgress`),s),i.uniform1f(o(`u_revealSegments`),e.n-1);let[c,l,u,d]=e.color;i.uniform4f(o(`u_color`),c,l,u,d*this._fillOpacity(e.trace.style,.35)*(e._transitionOpacity??1)),i.uniform2f(o(`u_res`),this.canvas.width,this.canvas.height),this._setGradientUniforms(a,e.grad),this._bindVao(e,`area`,[e.xBuf._fcId,e.yBuf._fcId,e.baseBuf._fcId],()=>{this._vaoAttr(F.ax0,e.xBuf,0,1),this._vaoAttr(F.ax1,e.xBuf,4,1),this._vaoAttr(F.ay0,e.yBuf,0,1),this._vaoAttr(F.ay1,e.yBuf,4,1),this._vaoAttr(F.ab0,e.baseBuf,0,1),this._vaoAttr(F.ab1,e.baseBuf,4,1)});let f=Math.max(0,Math.min(e.n-1,Math.ceil((e.n-1)*s)));i.drawArraysInstanced(i.TRIANGLE_STRIP,0,4,f)}_drawRects(e,t,n,r,i,a=[0,0,0,0]){if(!e.n)return;let o=this.gl,s=this.rectProg;o.useProgram(s);let c=e=>I(o,s,e);o.uniform2f(c(`u_x0map`),t[0],t[1]),o.uniform2f(c(`u_x1map`),n[0],n[1]),o.uniform2f(c(`u_y0map`),r[0],r[1]),o.uniform2f(c(`u_y1map`),i[0],i[1]),this._setAxisUniforms(s,`u_x0`,e.x0Meta,e.xAxis),this._setAxisUniforms(s,`u_x1`,e.x1Meta,e.xAxis),this._setAxisUniforms(s,`u_y0`,e.y0Meta,e.yAxis),this._setAxisUniforms(s,`u_y1`,e.y1Meta,e.yAxis),o.uniform1i(c(`u_xmode`),this._axisMode(e.xAxis)),o.uniform1i(c(`u_ymode`),this._axisMode(e.yAxis)),o.uniform4f(c(`u_edgePad`),a[0],a[1],a[2],a[3]);let[l,u,d,f]=e.color;o.uniform4f(c(`u_color`),l,u,d,f),o.uniform1f(c(`u_opacity`),this._fillOpacity(e.trace.style)*(e._transitionOpacity??1)),o.uniform1i(c(`u_colorMode`),e.colorMode||0),this._setRectStyleUniforms(s,e);let p=!!e.cBuf,m=!!e.rgbaBuf,h=!!e.styleBuf,g=!!e.strokeBuf,_=!!e.radiusBuf;p&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,e.lut),o.uniform1i(c(`u_lut`),0)),this._bindVao(e,`rects`,[e.x0Buf._fcId,e.x1Buf._fcId,e.y0Buf._fcId,e.y1Buf._fcId,p?e.cBuf._fcId:0,m?e.rgbaBuf._fcId:0,h?e.styleBuf._fcId:0,g?e.strokeBuf._fcId:0,_?e.radiusBuf._fcId:0],()=>{this._vaoAttr(F.ax0,e.x0Buf,0,1),this._vaoAttr(F.ax1,e.x1Buf,0,1),this._vaoAttr(F.ay0,e.y0Buf,0,1),this._vaoAttr(F.ay1,e.y1Buf,0,1),p&&this._vaoAttr(F.a_cval,e.cBuf,0,1),m&&this._vaoAttr(F.a_rgba,e.rgbaBuf,0,1,4,!0),h&&this._vaoAttr(F.a_style,e.styleBuf,0,1,4),g&&this._vaoAttr(F.a_stroke,e.strokeBuf,0,1,4,!0),_&&this._vaoAttr(F.a_radius,e.radiusBuf,0,1,2)}),p||o.vertexAttrib1f(F.a_cval,0),m||o.vertexAttrib4f(F.a_rgba,l,u,d,f),h||o.vertexAttrib4f(F.a_style,1,-1,-1,-1),g||o.vertexAttrib4f(F.a_stroke,...e.strokeColor||e.color),_||o.vertexAttrib2f(F.a_radius,-1,-1),o.drawArraysInstanced(o.TRIANGLE_STRIP,0,4,e.n)}_drawBars(e,t,n,r,i,a=0){if(!e.n)return;let o=this.gl,s=this.barProg;o.useProgram(s);let c=e=>I(o,s,e);o.uniform2f(c(`u_pmap`),t[0],t[1]),o.uniform2f(c(`u_v1map`),n[0],n[1]),o.uniform2f(c(`u_v0map`),r?r[0]:1,r?r[1]:0);let l=e.orientation===1?e.yAxis:e.xAxis,u=e.orientation===1?e.xAxis:e.yAxis;this._setAxisUniforms(s,`u_p`,e.posMeta,l),this._setAxisUniforms(s,`u_v1`,e.value1Meta,u),this._setAxisUniforms(s,`u_v0`,e.value0Meta,u),o.uniform1i(c(`u_pmode`),this._axisMode(l)),o.uniform1i(c(`u_vmode`),this._axisMode(u)),o.uniform1f(c(`u_width`),e.width),o.uniform1i(c(`u_orientation`),e.orientation),o.uniform1i(c(`u_v0Mode`),e.value0Mode),o.uniform1f(c(`u_v0Const`),i??0),o.uniform1f(c(`u_v0EdgePad`),a),o.uniform1f(c(`u_animationProgress`),e._transitionGrow??1);let d=!!(e._transitionPrevPosBuf&&e._transitionPrevValue1Buf&&e._transitionPrevValue0Buf);o.uniform1i(c(`u_transitionActive`),+!!d),o.uniform1f(c(`u_transitionProgress`),e._transitionPositionProgress??1),o.uniform1f(c(`u_prevWidth`),e._transitionPrevWidth??e.width);let[f,p,m,h]=e.color;o.uniform4f(c(`u_color`),f,p,m,h),o.uniform1f(c(`u_opacity`),this._fillOpacity(e.trace.style)*(e._transitionOpacity??1)),o.uniform1i(c(`u_colorMode`),e.colorMode||0),this._setRectStyleUniforms(s,e);let g=e.value0Mode===1&&e.value0Buf,_=!!e.cBuf,v=!!e.rgbaBuf,y=!!e.styleBuf,b=!!e.strokeBuf,x=!!e.radiusBuf;_&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,e.lut),o.uniform1i(c(`u_lut`),0)),this._bindVao(e,`bars`,[e.posBuf._fcId,e.value1Buf._fcId,g?e.value0Buf._fcId:0,_?e.cBuf._fcId:0,d?e._transitionPrevPosBuf._fcId:0,d?e._transitionPrevValue1Buf._fcId:0,d?e._transitionPrevValue0Buf._fcId:0,v?e.rgbaBuf._fcId:0,y?e.styleBuf._fcId:0,b?e.strokeBuf._fcId:0,x?e.radiusBuf._fcId:0],()=>{this._vaoAttr(F.a_pos,e.posBuf,0,1),this._vaoAttr(F.a_v1,e.value1Buf,0,1),g&&this._vaoAttr(F.a_v0,e.value0Buf,0,1),_&&this._vaoAttr(F.a_cval,e.cBuf,0,1),d&&(this._vaoAttr(F.a_prevx,e._transitionPrevPosBuf,0,1),this._vaoAttr(F.a_prevy,e._transitionPrevValue1Buf,0,1),this._vaoAttr(F.a_prevx1,e._transitionPrevValue0Buf,0,1)),v&&this._vaoAttr(F.a_rgba,e.rgbaBuf,0,1,4,!0),y&&this._vaoAttr(F.a_style,e.styleBuf,0,1,4),b&&this._vaoAttr(F.a_stroke,e.strokeBuf,0,1,4,!0),x&&this._vaoAttr(F.a_radius,e.radiusBuf,0,1,2)}),g||o.vertexAttrib1f(F.a_v0,0),_||o.vertexAttrib1f(F.a_cval,0),v||o.vertexAttrib4f(F.a_rgba,f,p,m,h),y||o.vertexAttrib4f(F.a_style,1,-1,-1,-1),b||o.vertexAttrib4f(F.a_stroke,...e.strokeColor||e.color),x||o.vertexAttrib2f(F.a_radius,-1,-1),o.drawArraysInstanced(o.TRIANGLE_STRIP,0,4,e.n)}_dataPxX(e){return this._dataPx(`x`,e)}_dataPxY(e){return this._dataPx(`y`,e)}_styleNumber(e,t,n){if(!e||typeof e!=`object`)return n;let r=Number(e[t]);return Number.isFinite(r)?r:n}_axisStyleNumber(e,t,n){return this._styleNumber(e&&e.style,t,n)}_axisStylePaint(e,t,n){let r=e&&typeof e.style==`object`?e.style:null;return E(this.root,r&&r[t],n)}_axisStyleValue(e,t){let n=e&&typeof e.style==`object`?e.style:null;return n&&Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}_axisGridDash(e){let t=String(this._axisStyleValue(e,`grid_dash`)||`solid`);return t===`dashed`?[6,4]:t===`dotted`?[1,3]:t===`dashdot`?[6,3,1,3]:[]}_axisTickLabelStrategy(e){let t=String(e&&e.tick_label_strategy||`auto`).replace(/-/g,`_`);return[`auto`,`hide`,`rotate`,`stagger`,`none`,`off`].includes(t)?t:`auto`}_axisTickLabelAnchor(e){let t=e&&e.tick_label_anchor!==void 0?e.tick_label_anchor:this._axisStyleValue(e,`tick_label_anchor`);if(t==null)return null;let n=String(t).toLowerCase();return n===`start`||n===`left`?`start`:n===`end`||n===`right`?`end`:n===`center`||n===`middle`?`center`:null}_axisTickLabelAngle(e){let t=Number(e?e.tick_label_angle:void 0);return Number.isFinite(t)?t:null}_axisTickLabelMinGap(e,t){let n=Number(e?e.tick_label_min_gap:void 0);return Number.isFinite(n)&&n>=0?n:t===`x`?8:4}_estimateTickLabel(e,t){let n=String(e||``);return{w:Math.max(t*.7,n.length*t*.62),h:t*1.2}}_tickLabelExtent(e,t,n){let r=this._estimateTickLabel(e.text,n),i=Math.abs(Number(e.angle||0))*Math.PI/180;return t===`y`?Math.abs(Math.sin(i))*r.w+Math.abs(Math.cos(i))*r.h:Math.abs(Math.cos(i))*r.w+Math.abs(Math.sin(i))*r.h}_tickLabelsCollide(e,t,n,r,i=`center`){let a=new Map;for(let t of e){let e=Number(t.row||0);a.has(e)||a.set(e,[]),a.get(e).push(t)}for(let e of a.values()){if(e.sort((e,t)=>e.pos-t.pos),t===`x`&&i!==`center`){for(let t=1;tt%a===0);if(!this._tickLabelsCollide(o,t,n,r,i))return o}return e.slice(0,1)}_layoutTickLabels(e,t,n){let r=this._axisTickLabelStrategy(e);if(r===`none`||r===`off`)return[];if(n.length<=1){let t=this._axisTickLabelAngle(e);return n.map(e=>({...e,angle:t===null?0:t,row:0}))}let i=Math.max(8,this._axisStyleNumber(e,`tick_label_size`,this._axisStyleNumber(e,`tick_size`,11))),a=this._axisTickLabelMinGap(e,t),o=t===`x`?this._axisTickLabelAnchor(e)??`center`:`center`,s=this._axisTickLabelAngle(e),c=s===null?0:s,l=n.map(e=>({...e,angle:c,row:0})),u=r;if(u===`auto`){if(!this._tickLabelsCollide(l,t,i,a,o))return l;u=t===`x`&&e.kind===`category`&&n.length<=16?`rotate`:t===`x`&&n.length<=24?`stagger`:`hide`}let d=l;if(u===`rotate`&&t===`x`){let t=s===null?e.side===`top`?35:-35:s;d=n.map(e=>({...e,angle:t,row:0}))}else u===`stagger`&&t===`x`&&(d=n.map((e,t)=>({...e,angle:c,row:t%2})));return this._tickLabelsCollide(d,t,i,a,o)&&(d=this._downsampleTickLabels(d,t,i,a,o)),d}_xTickLabelTransform(e,t){let n=Number(t||0),r=e&&e.side===`top`?`top`:`bottom`,i=this._axisTickLabelAnchor(e);if(i){let e=i===`end`?`-100%`:i===`start`?`0%`:`-50%`,t=i===`end`?`right`:i===`start`?`left`:`center`;return{transform:`translateX(${e}) rotate(${n}deg)`,origin:`${t} ${r===`top`?`bottom`:`top`}`}}if(n===0)return{transform:`translateX(-50%)`,origin:r===`top`?`bottom center`:`top center`};let a=r===`bottom`&&n<0||r===`top`&&n>0,o=r===`top`?`bottom`:`top`;return{transform:`${a?`translateX(-100%) `:``}rotate(${n}deg)`,origin:`${o} ${a?`right`:`left`}`}}_axisLabelCss(e,t,n){let r=e&&e.label_position,i=r!=null,a=e&&Number.isFinite(Number(e.label_offset)),o=e&&Number.isFinite(Number(e.label_angle));if(!i&&!a&&!o)return{css:n,style:null};if(r&&typeof r==`object`&&!Array.isArray(r))return{css:`font-weight:500;white-space:nowrap;`,style:r};let s=this.plot,c=String(i?r:`center`).replace(/-/g,`_`),l=c.startsWith(`inside_`),u=l?c.slice(7):c,d=a?Number(e.label_offset):0,f=e&&e.side,p=u===`start`?0:u===`end`?1:.5;if(t===`x`){let t=s.x+s.w*p,n=f===`top`?s.y-34:s.y+s.h+24,r=f===`top`?s.y+12:s.y+s.h-12;return{css:`left:${t}px;top:${(l?r:n)+(f===`top`?l?d:-d:l?-d:d)}px;transform:translateX(${u===`start`?0:u===`end`?-100:-50}%) rotate(${o?Number(e.label_angle):0}deg);transform-origin:center;font-weight:500;white-space:nowrap;`,style:null}}let m=f===`right`?s.x+s.w+40:10,h=f===`right`?s.x+s.w-12:s.x+12;return{css:`left:${(l?h:m)+(f===`right`?l?-d:d:l?d:-d)}px;top:${s.y+s.h*(1-p)}px;transform:translate(-50%,-50%) rotate(${o?Number(e.label_angle):f===`right`?90:-90}deg);transform-origin:center;font-weight:500;white-space:nowrap;`,style:null}}_drawChrome(){let e=this.spec,t=this.dpr,n=this.chrome.getContext(`2d`);n.setTransform(t,0,0,t,0,0),n.clearRect(0,0,this.size.w,this.size.h);let r=this._now(),i=this._viewAnim?80:0,a=i===0||this._lastLabelDraw===null||r-this._lastLabelDraw>=i;a&&(this.labels.textContent=``,this._lastLabelDraw=r);let o=this.plot;this.theme.bg&&(n.fillStyle=C(this.theme.bg),n.fillRect(o.x,o.y,o.w,o.h));let s=this._axis(`x`),c=this._axis(`y`),l=Object.values(this.axes).filter(e=>e&&e.id!==`x`&&String(e.id||``).startsWith(`x`)),u=Object.values(this.axes).filter(e=>e&&e.id!==`y`&&String(e.id||``).startsWith(`y`)),d=this._axisTickLabelStrategy(s)===`none`,f=this._axisTickLabelStrategy(c)===`none`,p=this._axisTicks(`x`,this._axisTickTarget(`x`,Math.max(3,o.w/(s.kind===`time`?90:80)))),m=this._axisTicks(`y`,this._axisTickTarget(`y`,Math.max(3,o.h/45))),h=e=>Math.min(o.x+o.w-.5,Math.max(o.x+.5,Math.round(e)+.5)),g=e=>Math.min(o.y+o.h-.5,Math.max(o.y+.5,Math.round(e)+.5));n.strokeStyle=this._axisStylePaint(s,`grid_color`,this.theme.grid),n.lineWidth=Math.max(.5,this._axisStyleNumber(s,`grid_width`,1)),n.globalAlpha=this._axisStyleNumber(s,`grid_opacity`,1),n.setLineDash(this._axisGridDash(s)),n.beginPath();for(let e of d?[]:p.ticks){let t=this._dataPx(`x`,e);if(!Number.isFinite(t))continue;let r=h(t);n.moveTo(r,o.y),n.lineTo(r,o.y+o.h)}n.stroke(),n.strokeStyle=this._axisStylePaint(c,`grid_color`,this.theme.grid),n.lineWidth=Math.max(.5,this._axisStyleNumber(c,`grid_width`,1)),n.globalAlpha=this._axisStyleNumber(c,`grid_opacity`,1),n.setLineDash(this._axisGridDash(c)),n.beginPath();for(let e of f?[]:m.ticks){let t=this._dataPx(`y`,e);if(!Number.isFinite(t))continue;let r=g(t);n.moveTo(o.x,r),n.lineTo(o.x+o.w,r)}n.stroke(),n.globalAlpha=1,n.setLineDash([]);let _=this.overlay.getContext(`2d`);if(_.setTransform(t,0,0,t,0,0),_.clearRect(0,0,this.size.w,this.size.h),this._drawAnnotationShapes(_),a){let t=(e,t,n,r,i,a=`axis_color`)=>{let o=document.createElement(`div`);o.style.cssText=`position:absolute;left:${t}px;top:${n}px;width:${r}px;height:${i}px;background:${this._axisStylePaint(e,a,this.theme.axis)};pointer-events:none;`,this.labels.appendChild(o)},n=Array.isArray(e.frame_sides)?e.frame_sides:[s.side||`bottom`,c.side||`left`];if(!f){let e=Math.max(1,this._axisStyleNumber(c,`axis_width`,1));n.includes(`left`)&&t(c,o.x,o.y,e,o.h),n.includes(`right`)&&t(c,o.x+o.w-e,o.y,e,o.h)}if(!d){let e=Math.max(1,this._axisStyleNumber(s,`axis_width`,1));n.includes(`top`)&&t(s,o.x,o.y,o.w,e),n.includes(`bottom`)&&t(s,o.x,o.y+o.h-e,o.w,e)}for(let e of l){if(this._axisTickLabelStrategy(e)===`none`)continue;let n=Math.max(1,this._axisStyleNumber(e,`axis_width`,1)),r=e.side===`top`?o.y:o.y+o.h-n;t(e,o.x,r,o.w,n)}for(let e of u){if(this._axisTickLabelStrategy(e)===`none`)continue;let n=Math.max(1,this._axisStyleNumber(e,`axis_width`,1));t(e,e.side===`left`?o.x:o.x+o.w-n,o.y,n,o.h)}let r=e=>{let t=Math.max(0,this._axisStyleNumber(e,`tick_length`,0)),n=Math.max(.5,this._axisStyleNumber(e,`tick_width`,1)),r=String(this._axisStyleValue(e,`tick_direction`)||`out`);return r===`in`?{inward:t,outward:0,width:n}:r===`inout`?{inward:t/2,outward:t/2,width:n}:{inward:0,outward:t,width:n}};if(!d){let e=r(s),n=s.side||`bottom`,i=n===`top`?o.y:o.y+o.h;for(let r of p.ticks){let a=this._dataPx(`x`,r);if(!Number.isFinite(a)||ao.x+o.w+1)continue;let c=n===`top`?i-e.outward:i-e.inward;t(s,a-e.width/2,c,e.width,e.inward+e.outward,`tick_color`)}}if(!f){let e=r(c),n=c.side||`left`,i=n===`right`?o.x+o.w:o.x;for(let r of m.ticks){let a=this._dataPx(`y`,r);!Number.isFinite(a)||ao.y+o.h+1||t(c,n===`right`?i-e.inward:i-e.outward,a-e.width/2,e.inward+e.outward,e.width,`tick_color`)}}for(let e of l){if(this._axisTickLabelStrategy(e)===`none`)continue;let n=this._axisTicks(e.id,this._axisTickTarget(e.id,Math.max(3,o.w/(e.kind===`time`?90:80)))),i=r(e),a=e.side||`bottom`,s=a===`top`?o.y:o.y+o.h;for(let r of n.ticks){let n=this._dataPx(e.id,r);if(!Number.isFinite(n)||no.x+o.w+1)continue;let c=a===`top`?s-i.outward:s-i.inward;t(e,n-i.width/2,c,i.width,i.inward+i.outward,`tick_color`)}}for(let e of u){if(this._axisTickLabelStrategy(e)===`none`)continue;let n=this._axisTicks(e.id,this._axisTickTarget(e.id,Math.max(3,o.h/45))),i=r(e),a=e.side||`right`,s=a===`right`?o.x+o.w:o.x;for(let r of n.ticks){let n=this._dataPx(e.id,r);!Number.isFinite(n)||no.y+o.h+1||t(e,a===`right`?s-i.inward:s-i.outward,n-i.width/2,i.inward+i.outward,i.width,`tick_color`)}}}let v=(e,t,n,r=`tick`,i=null)=>{if(!a)return;let o=document.createElement(`div`);o.textContent=e,o.dataset.xyLabelKind=r,o.dataset.xyAxis=n&&n.id!==void 0?String(n.id):``,o.dataset.xyAxisSide=n&&n.side?String(n.side):``;let s=r===`label`?`label_color`:this._axisStyleValue(n,`tick_label_color`)===void 0?`tick_color`:`tick_label_color`,c=r===`label`?`label_size`:this._axisStyleValue(n,`tick_label_size`)===void 0?`tick_size`:`tick_label_size`,l=``;this._axisStyleValue(n,s)!==void 0&&(l=`color:${this._axisStylePaint(n,s,this.theme.label)};`);let u=``;this._axisStyleValue(n,c)!==void 0&&(u=`font-size:${Math.max(8,this._axisStyleNumber(n,c,11))}px;`),o.style.cssText=`position:absolute;line-height:1.2;white-space:nowrap;${l}${u}${t}`,this._applySlot(o,r===`label`?`axis_title`:`tick_label`),this._applyStyle(o,i),this.labels.appendChild(o)},y=[];for(let e of p.labels||p.ticks){let t=this._dataPx(`x`,e);if(to.x+o.w+1)continue;let n=this._axisTickText(s,e,p.step);y.push({pos:t,text:n})}let b=this._axisStyleNumber(s,`tick_label_size`,this._axisStyleNumber(s,`tick_size`,11));for(let e of this._layoutTickLabels(s,`x`,y)){let t=Number(e.row||0)*(Math.max(8,b)+4),n=s.side===`top`?o.y-18-t:o.y+o.h+6+t,r=this._xTickLabelTransform(s,e.angle);v(e.text,`left:${e.pos}px;top:${n}px;transform:${r.transform};transform-origin:${r.origin};`,s)}for(let e of l){let t=this._axisTicks(e.id,this._axisTickTarget(e.id,Math.max(3,o.w/(e.kind===`time`?90:80)))),n=[];for(let r of t.labels||t.ticks){let i=this._dataPx(e.id,r);io.x+o.w+1||n.push({pos:i,text:this._axisTickText(e,r,t.step)})}for(let t of this._layoutTickLabels(e,`x`,n)){let n=this._axisStyleNumber(e,`tick_label_size`,this._axisStyleNumber(e,`tick_size`,11)),r=Number(t.row||0)*(Math.max(8,n)+4),i=e.side===`top`?o.y-18-r:o.y+o.h+6+r,a=this._xTickLabelTransform(e,t.angle);v(t.text,`left:${t.pos}px;top:${i}px;transform:${a.transform};transform-origin:${a.origin};`,e)}if(e.label&&this._axisTickLabelStrategy(e)!==`none`){let t=e.side===`top`?o.y-34:o.y+o.h+24,n=`left:${o.x+o.w/2}px;top:${t}px;transform:translateX(-50%);font-weight:500;`,r=this._axisLabelCss(e,`x`,n);v(e.label,r.css,e,`label`,r.style)}}let x=[];for(let e of m.labels||m.ticks){let t=this._dataPx(`y`,e);if(to.y+o.h+1)continue;let n=this._axisTickText(c,e,m.step);x.push({pos:t,text:n})}let S=(e,t,n)=>{let r=t?o.x+o.w+8:o.x-8,i=this._axisTickLabelAnchor(e)??(t?`start`:`end`),a=i===`end`?`-100%`:i===`start`?`0%`:`-50%`,s=i===`end`?`right`:i===`start`?`left`:`center`;return`left:${r}px;top:${n.pos}px;transform:translate(${a},-50%) rotate(${Number(n.angle||0)}deg);transform-origin:${s} center;`};for(let e of this._layoutTickLabels(c,`y`,x))v(e.text,S(c,c.side===`right`,e),c);for(let e of u){let t=this._axisTicks(e.id,this._axisTickTarget(e.id,Math.max(3,o.h/45))),n=[];for(let r of t.labels||t.ticks){let i=this._dataPx(e.id,r);if(io.y+o.h+1)continue;let a=this._axisTickText(e,r,t.step);n.push({pos:i,text:a})}for(let t of this._layoutTickLabels(e,`y`,n))v(t.text,S(e,e.side!==`left`,t),e);if(e.label&&this._axisTickLabelStrategy(e)!==`none`){let t=e.side===`left`?`left:10px;top:${o.y+o.h/2}px;transform:rotate(-90deg) translateX(50%);transform-origin:left;font-weight:500;`:`left:${o.x+o.w+40}px;top:${o.y+o.h/2}px;transform:rotate(90deg) translateX(-50%);transform-origin:left;font-weight:500;`,n=this._axisLabelCss(e,`y`,t);v(e.label,n.css,e,`label`,n.style)}}if(e.x_axis.label&&!d){let t=s.side===`top`?o.y-34:o.y+o.h+24,n=`left:${o.x+o.w/2}px;top:${t}px;transform:translateX(-50%);font-weight:500;`,r=this._axisLabelCss(s,`x`,n);v(e.x_axis.label,r.css,s,`label`,r.style)}if(e.y_axis.label&&!f){let t=c.side===`right`?`left:${o.x+o.w+40}px;top:${o.y+o.h/2}px;transform:rotate(90deg) translateX(-50%);transform-origin:left;font-weight:500;`:`left:10px;top:${o.y+o.h/2}px;transform:rotate(-90deg) translateX(50%);transform-origin:left;font-weight:500;`,n=this._axisLabelCss(c,`y`,t);v(e.y_axis.label,n.css,c,`label`,n.style)}this._drawAnnotationLabels(a)}_interactionTransitionActive(){let e=e=>e!=null;return!!this._viewAnim||this.gpuTraces.some(t=>e(t._densityFadeStart)||e(t._densitySwitchFadeStart)||e(t._drillFadeStart)||e(t._drillExitFadeStart)||!!t._densityNormAnim)}_renderPick(){let e=this.gl;(this._pickW!==this.canvas.width||this._pickH!==this.canvas.height)&&this._allocPickTex(),e.bindFramebuffer(e.FRAMEBUFFER,this.pickFbo),e.viewport(0,0,this.canvas.width,this.canvas.height),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);let{x0:t,x1:n,y0:r,y1:i}=this.view,a=this.pickProg;e.useProgram(a);let o=t=>I(e,a,t);e.uniform1f(o(`u_dpr`),this.dpr);let s=1;for(let t of this.gpuTraces){let n=t.tier===`density`?t.drill&&!t._drillDying&&this._viewInside(t.drill.win)?t.drill:null:J(t.trace.kind).pointPick?t:null;if(!n||!n.n||s+n.n>2147483647){t.pickBase=-1,t.pickCount=0;continue}let[r,i]=this._axisRange(n.xAxis||t.xAxis),[c,l]=this._axisRange(n.yAxis||t.yAxis),u=this._map(n.xMeta,r,i,n.xAxis||t.xAxis),d=this._map(n.yMeta,c,l,n.yAxis||t.yAxis);e.uniform2f(o(`u_xmap`),u[0],u[1]),e.uniform2f(o(`u_ymap`),d[0],d[1]),this._setAxisUniforms(a,`u_x`,n.xMeta,n.xAxis||t.xAxis),this._setAxisUniforms(a,`u_y`,n.yMeta,n.yAxis||t.yAxis),e.uniform1f(o(`u_size`),n.size),e.uniform1i(o(`u_sizeMode`),n.sizeMode),e.uniform2f(o(`u_sizeRange`),n.sizeRange[0],n.sizeRange[1]);let f=!!(n._transitionPrevXBuf&&n._transitionPrevYBuf);e.uniform1i(o(`u_transitionActive`),+!!f),e.uniform1f(o(`u_transitionProgress`),n._transitionPositionProgress??1),e.uniform1i(o(`u_pick_base`),s),t.pickBase=s,t.pickCount=n.n;let p=n.sizeMode===1&&n.sBuf;this._bindVao(n,`pick`,[n.xBuf._fcId,n.yBuf._fcId,p?n.sBuf._fcId:0,f?n._transitionPrevXBuf._fcId:0,f?n._transitionPrevYBuf._fcId:0],()=>{this._vaoAttr(F.ax,n.xBuf,0,0),this._vaoAttr(F.ay,n.yBuf,0,0),p&&this._vaoAttr(F.a_sval,n.sBuf,0,0),f&&(this._vaoAttr(F.a_prevx,n._transitionPrevXBuf,0,0),this._vaoAttr(F.a_prevy,n._transitionPrevYBuf,0,0))}),p||e.vertexAttrib1f(F.a_sval,.5),e.drawArrays(e.POINTS,0,n.n),s+=n.n}e.enable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,null),this._pickDirty=!1}_pickAt(e,t){if(!this._pickable||this._glLost||!this.gl||this.gl.isContextLost())return null;if(this._pickDirty)try{this._renderPick()}catch(e){if(!this.gl||this.gl.isContextLost())return null;throw e}let n=this.gl,r=Math.round(e*this.dpr),i=Math.round((this.plot.h-t)*this.dpr);if(r<0||i<0||r>=this.canvas.width||i>=this.canvas.height)return null;let a=new Uint8Array(4);n.bindFramebuffer(n.FRAMEBUFFER,this.pickFbo),n.readPixels(r,i,1,1,n.RGBA,n.UNSIGNED_BYTE,a),n.bindFramebuffer(n.FRAMEBUFFER,null);let o=a[0]+a[1]*256+a[2]*65536+a[3]*16777216;if(o===0)return null;let s=this.gpuTraces.find(e=>e.pickBase>0&&o>=e.pickBase&&o=e.length?NaN:e[n]/(t.scale||1)+t.offset}_dataFromCanvas(e,t,n=`x`,r=`y`){let[i,a]=this._axisRange(n),[o,s]=this._axisRange(r),c=this._axis(n),l=this._axis(r),u=this._axisCoord(c,i),d=this._axisCoord(c,a),f=this._axisCoord(l,o),p=this._axisCoord(l,s);return[u,d,f,p].every(Number.isFinite)?[this._axisValue(c,u+e/this.plot.w*(d-u)),this._axisValue(l,p-t/this.plot.h*(p-f))]:[NaN,NaN]}_nearestCpuIndex(e,t){let n=e&&e._cpu;if(!n||!n.x||!n.x.length)return-1;let r=n.xMeta||e.xMeta,i=this._axis(e.xAxis),a=this._axisCoord(i,t),o=-1,s=1/0,c=Math.min(n.x.length,e.n||n.x.length);for(let t=0;t=l&&t<=u&&Math.abs(n-s)<=e.width/2)return{trace:e.trace.id,index:o,g:e,synthetic:!0}}else if(Math.abs(t-a)<=e.width/2&&n>=l&&n<=u)return{trace:e.trace.id,index:o,g:e,synthetic:!0}}return null}_rectHover(e,t,n){let r=e._cpuRect,i=Math.min(r.x0.length,r.x1.length,r.y0.length,r.y1.length,e.n||r.x0.length);for(let a=0;a=Math.min(i,o)&&t<=Math.max(i,o)&&n>=Math.min(s,c)&&n<=Math.max(s,c))return{trace:e.trace.id,index:a,g:e,synthetic:!0}}return null}_heatmapHover(e,t,n){let r=e.heatmap;if(!r||!e._cpuHeatmap)return null;let[i,a]=r.xRange,[o,s]=r.yRange;if(ta||ns)return null;let[c,l]=this._axisRange(e.xAxis)??[this.view.x0,this.view.x1],[u,d]=this._axisRange(e.yAxis)??[this.view.y0,this.view.y1],f=(c??this.view.x0)>(l??this.view.x1)?a-t:t-i,p=(u??this.view.y0)>(d??this.view.y1)?s-n:n-o,m=Math.min(r.w-1,Math.max(0,Math.floor(f/(a-i)*r.w))),h=Math.min(r.h-1,Math.max(0,Math.floor(p/(s-o)*r.h)));return{trace:e.trace.id,index:h*r.w+m,g:e,heatmap:{row:h,col:m},synthetic:!0}}_drawKeepPick(){this.draw(!0)}_hover(e){if(this._a11yKeyboardReadout=null,this._interactionTransitionActive()){let e=this._hoverId!==-1;this._hoverId=-1,this._hoverTarget=null,this._lastHoverXY=null,this._pickSeq=(this._pickSeq||0)+1,this._hideTooltip(),e&&this.draw();return}let t=this.canvas.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=this._pickAt(n,r)||this._hoverAt(n,r);if(!i){let e=this._hoverId!==-1;this._hoverId=-1,this._hoverTarget=null,this._lastHoverXY=null,this._pickSeq=(this._pickSeq||0)+1,this._hideTooltip(),e&&this._drawKeepPick();return}let a=i.trace*1e9+i.index;if(this._lastHoverXY={clientX:e.clientX,clientY:e.clientY},a===this._hoverId){this._tooltipAnchor||this._renderTooltip(this._lastRow,e.clientX,e.clientY);return}this._hoverId=a,this._hoverTarget=i,this._showTooltip(i,e.clientX,e.clientY),this._drawKeepPick()}_asF32(e){return e instanceof ArrayBuffer?new Float32Array(e):e.byteOffset%4==0?new Float32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)):new Float32Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength))}_asU8(e){return e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}_asU32(e){return e instanceof ArrayBuffer?new Uint32Array(e):e.byteOffset%4==0?new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)):new Uint32Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength))}_applyTheme(){this.theme=S(this.root),this._themeStale=!this.root.isConnected;for(let e of this.gpuTraces)J(e.trace.kind).refreshColor?.(this,e)}refreshTheme(){this._destroyed||(this._applyTheme(),this.draw())}_healStaleTheme(){return!this._themeStale||!this.root.isConnected?!1:(this._applyTheme(),!0)}destroy(){if(this._destroyed)return;this._destroyed=!0,this._dataAnim&&this._emitAnimationLifecycle?.(`end`,this._dataAnim.phase,{cancelled:!0}),Z.unregister(this),this._ctxIo?.disconnect(),this._ctxIo=null,clearTimeout(this._ctxRecoveryTimer),this._ctxRecoveryTimer=null,clearTimeout(this._rebinTimer),this._rebinWorker&&=(this._rebinWorker.terminate(),this._rebinWorker._fcUrl&&URL.revokeObjectURL(this._rebinWorker._fcUrl),null),this._ro?.disconnect(),this._io?.disconnect(),this._io=null,this._themeWatch?.removeEventListener?.(`change`,this._onScheme),this._themeMutationObserver?.disconnect(),this._themeMutationObserver=null,this._dprMq?.removeEventListener?.(`change`,this._onDprChange),this._dprMq=null,this._unsubscribeComm?.(),this._unsubscribeComm=null;for(let{target:e,type:t,handler:n,options:r}of this._listeners.splice(0))e.removeEventListener(t,n,r);clearTimeout(this._viewTimer),this._viewTimer=null,this._viewEventRaf&&cancelAnimationFrame(this._viewEventRaf),this._viewEventRaf=null,this._wheelZoomRaf&&cancelAnimationFrame(this._wheelZoomRaf),this._wheelZoomRaf=null,this._pendingWheelZoom=null,clearTimeout(this._wheelZoomEndTimer),this._wheelZoomEndTimer=null,this._wheelGesture=null,this._linkChannel?.close?.(),this._linkChannel=null,this._raf&&cancelAnimationFrame(this._raf),this._raf=null,this._resizeRaf&&cancelAnimationFrame(this._resizeRaf),this._resizeRaf=null,this._pendingResize=null,this._resizeNeedsMeasure=!1,this._cancelViewAnimation(),this._dataAnimRaf&&cancelAnimationFrame(this._dataAnimRaf),this._dataAnimRaf=null,this._dataAnim=null,this._destroyTransitionOldTraces?.(),this._destroyGlResources();let e=this.gl&&this.gl.getExtension(`WEBGL_lose_context`);e&&e.loseContext(),this.gl=null,this.root.remove()}_deleteBuffers(e,t){let n=this.gl;if(!n||!e)return;let r=new Set;for(let i of t){let t=e[i];t&&!r.has(t)&&(r.add(t),n.deleteBuffer(t)),e[i]=null}}_destroyTraceResources(e,t){if(!e)return;this._destroyDensitySample(e),this._deleteVaos(e),this._deleteVaos(e.drill),this._deleteBuffers(e,[`xBuf`,`yBuf`,`cBuf`,`sBuf`,`selBuf`,`baseBuf`,`x0Buf`,`x1Buf`,`x2Buf`,`y0Buf`,`y1Buf`,`y2Buf`,`posBuf`,`value1Buf`,`value0Buf`,`_transitionPrevXBuf`,`_transitionPrevYBuf`,`_transitionPrevPosBuf`,`_transitionPrevValue1Buf`,`_transitionPrevValue0Buf`]),this._deleteBuffers(e.drill,[`xBuf`,`yBuf`,`cBuf`,`sBuf`,`selBuf`,`dBuf`]);let n=[];e.heatmap&&n.push(e.heatmap.tex);for(let t of e.densityCache||[])n.push(t&&t.tex);e.density&&n.push(e.density.tex),e._shownDensity&&n.push(e._shownDensity.tex);for(let e of n)e&&!t.has(e)&&(t.add(e),this.gl.deleteTexture(e));e.drill=null,e.density=null,e._shownDensity=null,e.densityCache=[],e.heatmap=null,e._cpu=null}_destroyGlResources(){let e=this.gl;if(!e)return;let t=new Set;for(let e of this.gpuTraces||[])this._destroyTraceResources(e,t);for(let n of this._lutCache.values())n&&!t.has(n)&&(t.add(n),e.deleteTexture(n));this._lutCache.clear(),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTex&&!t.has(this.pickTex)&&e.deleteTexture(this.pickTex),this.pickFbo=null,this.pickTex=null,this.quad&&e.deleteBuffer(this.quad),this.quad=null,this.quadVao&&e.deleteVertexArray(this.quadVao),this.quadVao=null;for(let t of this._progCache?this._progCache.values():[])t&&e.deleteProgram(t);this._progCache&&this._progCache.clear(),this._glPrograms=this._progCache,this.gpuTraces=[]}},ut=new Set([`color`,`label_color`,`label_opacity`,`opacity`,`width`,`head_size`,`head_style`,`tail_style`,`shaft_width_start`,`shaft_width_end`,`curve`,`angle_a`,`angle_b`,`gap_start`,`gap_end`,`start_offset`,`label_clear`,`dash`,`span_start`,`span_end`,`size`,`symbol`,`stroke_color`,`stroke_width`,`coordinate_space`]);function dt(e,t){if(typeof e.label_clear!=`string`)return 0;let n=e.label_clear.split(`,`).map(Number);if(n.length!==4||n.some(e=>!Number.isFinite(e)||e<0))return 0;let[r,i,a,o]=n,[s,c]=t,l=s>1e-9?i/s:s<-1e-9?r/-s:1/0,u=c>1e-9?o/c:c<-1e-9?a/-c:1/0,d=Math.min(l,u);return Number.isFinite(d)?d:0}function ft(e,t,n,r,i){let a=e=>Number.isFinite(Number(e))?Number(e):null;if(typeof i.start_offset==`string`){let n=i.start_offset.split(`,`).map(Number);n.length===2&&n.every(Number.isFinite)&&(e+=n[0],t+=n[1])}let o=a(i.angle_a),s=a(i.angle_b),c=a(i.curve),l=null,u=null;if(o!==null&&s!==null){let i=-o*Math.PI/180,a=-s*Math.PI/180,c=Math.cos(i)*Math.sin(a)-Math.sin(i)*Math.cos(a);if(Math.abs(c)>1e-6){let o=((n-e)*Math.sin(a)-(r-t)*Math.cos(a))/c;l=e+o*Math.cos(i),u=t+o*Math.sin(i)}}else if(c){let i=n-e,a=r-t;l=(e+n)/2+c*a,u=(t+r)/2-c*i}let d=(e,t,n,r)=>{let i=Math.hypot(n-e,r-t)||1;return[(n-e)/i,(r-t)/i]},f=l===null?d(e,t,n,r):d(e,t,l,u),p=l===null?d(n,r,e,t):d(n,r,l,u),m=Math.max(0,a(i.gap_start)||0,dt(i,f)),h=Math.max(0,a(i.gap_end)||0),g=Math.hypot(n-e,r-t),_=m+h0)||e.length<2)return e;let n=e.slice(),r=t;for(;n.length>=2;){let[e,t]=n[n.length-2],[i,a]=n[n.length-1],o=Math.hypot(i-e,a-t);if(o>r){let s=1-r/o;return n[n.length-1]=[e+s*(i-e),t+s*(a-t)],n}r-=o,n.pop()}return n}function ht(e,t,n){let r=[],i=[],a=e.length;for(let o=0;o0&&e.stroke(),e.restore()},_drawArrowLine(e,t,n,r,i,a){if(![t,n,r,i].every(Number.isFinite))return;let o=ft(t,n,r,i,a);e.save(),e.globalAlpha=this._styleNumber(a,`opacity`,1),e.strokeStyle=this._annotationPaint(a,[.4,.44,.52,1]),e.fillStyle=e.strokeStyle,e.lineWidth=Math.max(.5,this._styleNumber(a,`width`,1.5)),e.setLineDash(Array.isArray(a.dash)?a.dash:typeof a.dash==`string`?a.dash.split(`,`).map(Number):[]);let s=Number(a.shaft_width_start),c=Number(a.shaft_width_end),l=a.head_style||`triangle`,u=Math.max(4,this._styleNumber(a,`head_size`,8));if(Number.isFinite(s)||Number.isFinite(c)){let t=pt(o);l===`triangle`&&(t=mt(t,u*Math.cos(Math.PI/6)));let n=ht(t,Number.isFinite(s)?s:1,Number.isFinite(c)?c:1);e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=1;t[a-i*Math.cos(s-e*Math.PI/6),o-i*Math.sin(s-e*Math.PI/6)],[l,u]=c(1),[d,f]=c(-1);if(r===`v`){e.moveTo(l,u),e.lineTo(a,o),e.lineTo(d,f),e.stroke();return}e.moveTo(a,o),e.lineTo(l,u),e.lineTo(d,f),e.closePath(),e.fill()},_drawAnnotationShapes(e){let t=Array.isArray(this.spec.annotations)?this.spec.annotations:[];if(!t.length)return;let n=this.plot;e.save(),e.beginPath(),e.rect(n.x,n.y,n.w,n.h),e.clip();for(let r of t){let t=r&&typeof r.style==`object`?r.style:{};if(r.kind===`band`){let i=r.axis===`x`,a=i?this._dataPxX(Number(r.start)):this._dataPxY(Number(r.start)),o=i?this._dataPxX(Number(r.end)):this._dataPxY(Number(r.end));if(!Number.isFinite(a)||!Number.isFinite(o))continue;let s=Math.max(i?n.x:n.y,Math.min(a,o)),c=Math.min(i?n.x+n.w:n.y+n.h,Math.max(a,o));if(c<=s)continue;e.save(),e.globalAlpha=this._styleNumber(t,`opacity`,.14),e.fillStyle=this._annotationPaint(t,[.39,.45,.55,1]);let l=Math.max(0,Math.min(1,Number(t.span_start)||0)),u=t.span_end===void 0?1:Number(t.span_end),d=Math.max(l,Math.min(1,Number.isFinite(u)?u:1));i?e.fillRect(s,n.y+(1-d)*n.h,c-s,(d-l)*n.h):e.fillRect(n.x+l*n.w,s,(d-l)*n.w,c-s),e.restore()}else if(r.kind===`rule`){let i=r.axis===`x`,a=i?this._dataPxX(Number(r.value)):this._dataPxY(Number(r.value));if(!Number.isFinite(a)||i&&(an.x+n.w+1)||!i&&(an.y+n.h+1))continue;let o=Math.round(a)+.5;e.save(),e.globalAlpha=this._styleNumber(t,`opacity`,1),e.strokeStyle=this._annotationPaint(t,[.4,.44,.52,1]),e.lineWidth=Math.max(.5,this._styleNumber(t,`width`,1.5)),e.setLineDash(Array.isArray(t.dash)?t.dash:typeof t.dash==`string`?t.dash.split(`,`).map(Number):[]),e.beginPath();let s=Math.max(0,Math.min(1,Number(t.span_start)||0)),c=t.span_end===void 0?1:Number(t.span_end),l=Math.max(s,Math.min(1,Number.isFinite(c)?c:1));i?(e.moveTo(o,n.y+(1-l)*n.h),e.lineTo(o,n.y+(1-s)*n.h)):(e.moveTo(n.x+s*n.w,o),e.lineTo(n.x+l*n.w,o)),e.stroke(),e.restore()}else if(r.kind===`arrow`)this._drawArrowLine(e,this._dataPxX(Number(r.x0)),this._dataPxY(Number(r.y0)),this._dataPxX(Number(r.x1)),this._dataPxY(Number(r.y1)),t);else if(r.kind===`callout`){let n=this._dataPxX(Number(r.x)),i=this._dataPxY(Number(r.y)),a=Number.isFinite(Number(r.dx))?Number(r.dx):0,o=Number.isFinite(Number(r.dy))?Number(r.dy):0;this._drawArrowLine(e,n+a,i+o,n,i,t)}else r.kind===`marker`&&this._drawAnnotationMarker(e,this._dataPxX(Number(r.x)),this._dataPxY(Number(r.y)),t,r)}e.restore()},_drawAnnotationLabels(e){if(!e)return;let t=Array.isArray(this.spec.annotations)?this.spec.annotations:[];if(!t.length)return;let n=this.plot;for(let e of t){let t=typeof e.text==`string`?e.text:``;if(!t)continue;let r=e&&typeof e.style==`object`?e.style:{},i=null,a=null,o=null;if(e.kind===`text`)r.coordinate_space===`axes_fraction`?(i=n.x+Number(e.x)*n.w,a=n.y+(1-Number(e.y))*n.h):r.coordinate_space===`figure_fraction`?(i=Number(e.x)*this.size.w,a=(1-Number(e.y))*this.size.h):r.coordinate_space===`yaxis_transform`?(i=n.x+Number(e.x)*n.w,a=this._dataPxY(Number(e.y))):r.coordinate_space===`xaxis_transform`?(i=this._dataPxX(Number(e.x)),a=n.y+(1-Number(e.y))*n.h):(i=this._dataPxX(Number(e.x)),a=this._dataPxY(Number(e.y)));else if(e.kind===`rule`)e.axis===`x`?(i=this._dataPxX(Number(e.value)),a=n.y+6):(i=n.x+n.w-6,a=this._dataPxY(Number(e.value)));else if(e.kind===`band`)e.axis===`x`?(i=(this._dataPxX(Number(e.start))+this._dataPxX(Number(e.end)))/2,a=n.y+6):(i=n.x+n.w-6,a=(this._dataPxY(Number(e.start))+this._dataPxY(Number(e.end)))/2);else if(e.kind===`arrow`){let t=this._dataPxX(Number(e.x0)),n=this._dataPxY(Number(e.y0)),r=this._dataPxX(Number(e.x1)),s=this._dataPxY(Number(e.y1));i=(t+r)/2,a=(n+s)/2;let c=Math.hypot(r-t,s-n);c>1e-6&&(o=[-(s-n)/c,(r-t)/c],o[1]>0&&(o=[-o[0],-o[1]]))}else(e.kind===`callout`||e.kind===`marker`)&&(i=this._dataPxX(Number(e.x)),a=this._dataPxY(Number(e.y)));if(!Number.isFinite(i)||!Number.isFinite(a)||in.x+n.w+24||an.y+n.h+24)continue;let s=document.createElement(`div`);s.textContent=t;let c=Number.isFinite(Number(e.dx))?Number(e.dx):0,l=Number.isFinite(Number(e.dy))?Number(e.dy):0,u=e.anchor,d=String(r.vertical_align||``);e.kind===`rule`||e.kind===`band`?e.axis===`x`?(!u&&e.kind===`band`&&(u=`middle`),d||=`top`):(u||=`end`,!d&&e.kind===`band`&&(d=`middle`)):e.kind===`arrow`&&(u||=`middle`,d||=`middle`);let f=u===`middle`?`-50%`:u===`end`?`-100%`:`0px`,p=Number.isFinite(Number(r.rotation))?(Number(r.rotation)%360+360)%360:0,m=d===`center`||d===`middle`?`-50%`:d===`bottom`?`-100%`:d===`top`?`0px`:`calc(-100% + 0.35em)`,h=`translate(${f},${m})`;if(p===90||p===270){let e=p===270;h=`rotate(${e?90:-90}deg) translate(${d===`center`||d===`middle`?`-50%`:d===`top`?e?`0`:`-100%`:d===`bottom`?e?`-100%`:`0`:e?`0`:`-100%`},${u===`middle`?`-50%`:u===`end`?e?`0`:`-100%`:e?`-100%`:`0`})`}else p&&(h=`rotate(${-p}deg) translate(${f},${m})`);s.style.cssText=`position:absolute;left:${i+c}px;top:${a+l}px;transform:${h};transform-origin:0 0;pointer-events:none;white-space:pre-line;text-align:center;width:max-content;`,this._applySlot(s,`annotation_label`),this._applyClass(s,e.class_name);let g=e.kind!==`text`&&e.kind!==`callout`,_={};for(let[t,n]of Object.entries(r)){if(t===`opacity`&&e.kind===`text`){_[t]=n;continue}ut.has(t)||g&&t===`opacity`||(_[t]=n)}if(this._applyStyle(s,_),r&&(r.label_color||r.color)&&(s.style.color=this._annotationLabelPaint(r,this.theme.label)),r&&r.label_opacity!==void 0){let e=Number(r.label_opacity);Number.isFinite(e)&&(s.style.opacity=String(Math.max(0,Math.min(1,e))))}this.labels.appendChild(s);let v=getComputedStyle(s),y=(e,t)=>(parseFloat(e)||0)+(parseFloat(t)||0),b=y(v.paddingLeft,v.borderLeftWidth),x=y(v.paddingRight,v.borderRightWidth),S=y(v.paddingTop,v.borderTopWidth),C=y(v.paddingBottom,v.borderBottomWidth);if((b||x||S||C)&&p!==90&&p!==270){let e=f===`-100%`?x:f===`-50%`?0:-b,t=m===`-50%`?0:m===`0px`?-S:C;s.style.transform=`${p?`rotate(${-p}deg) `:``}translate(calc(${f} + ${e}px), calc(${m} + ${t}px))`}let w=o&&this.labels.getBoundingClientRect();if(o&&w.width>0){let e=w.width/this.size.w,t=s.getBoundingClientRect(),n=t.width/e/2*Math.abs(o[0])+t.height/e/2*Math.abs(o[1])+3;i+=o[0]*n,a+=o[1]*n,s.style.left=`${i+c}px`,s.style.top=`${a+l}px`}let T=this.labels.getBoundingClientRect();if(T.width>0){let e=T.width/this.size.w,t=s.getBoundingClientRect(),n=t.right>T.right?T.right-t.right:t.leftT.bottom?T.bottom-t.bottom:t.top=0&&t=0&&tt.trace===e.trace)||r[0];if(!t||!Number.isFinite(Number(t.trace)))continue;let i=this.gpuTraces.find(e=>e.trace.id===t.trace);if(!i)continue;let a=Number.isInteger(e.index)&&t.trace===e.trace?e.index:-1;!i._cpuHeatmap&&(a<0||!i._cpu||!i._cpu.x||a>=i._cpu.x.length)&&(a=this._nearestCpuIndex(i,e.x));let[o,s]=this._sourceValue(i,t,a);o!==void 0&&(e[n]=o,s!==void 0&&(e[`${n}_kind`]=s))}},_denormalizeUnit(e,t){let n=Number(e);if(!Number.isFinite(n)||!Array.isArray(t)||t.length<2)return n;let r=Number(t[0]),i=Number(t[1]);return!Number.isFinite(r)||!Number.isFinite(i)?n:r+n*(i-r)},_defaultTooltipLines(e){let t=[];return e.x!==void 0&&t.push(`x: ${P(e.x,e.x_kind)}`),e.y!==void 0&&t.push(`y: ${P(e.y,e.y_kind)}`),e.color_value!==void 0&&t.push(`color: ${P(e.color_value)}`),e.color_category!==void 0&&t.push(`${e.color_category}`),e.size_value!==void 0&&t.push(`size: ${P(e.size_value)}`),t.length||t.push(`#${e.index}`),t},_tooltipLookup(e,t){let n=this.spec.tooltip&&this.spec.tooltip.aliases||{},r=e[t]===void 0?n[t]:t;return!r||e[r]===void 0?[void 0,void 0]:[e[r],e[`${r}_kind`]]},_formatTooltipValue(e,t,n){let r=ae(e,n);return r===null?P(e,t):r},_tooltipLines(e){let t=this.spec.tooltip||{};if(!t.title&&!Array.isArray(t.fields))return this._defaultTooltipLines(e);let n=t.format||{},r=[];if(typeof t.title==`string`){let i=t.title.replace(/\{([^}]+)\}/g,(t,r)=>{let[i,a]=this._tooltipLookup(e,r);return i===void 0?``:this._formatTooltipValue(i,a,n[r])});i&&r.push(i)}if(Array.isArray(t.fields))for(let i of t.fields){if(typeof i!=`string`)continue;let[t,a]=this._tooltipLookup(e,i);t!==void 0&&r.push(`${i}: ${this._formatTooltipValue(t,a,n[i])}`)}return r.length?r:this._defaultTooltipLines(e)},_setTooltipAnchor(e,t,n,r){let i=e.g;if(!i){this._tooltipAnchor=null;return}let a=i.xAxis||`x`,o=i.yAxis||`y`,s=t.x,c=t.y;if(!Number.isFinite(s)||!Number.isFinite(c)){let e=this.canvas.getBoundingClientRect();[s,c]=this._dataFromCanvas(n-e.left,r-e.top,a,o)}this._tooltipAnchor=Number.isFinite(s)&&Number.isFinite(c)?{xAxis:a,yAxis:o,x:s,y:c}:null,this._tooltipAnchor&&!this._tooltipAnchorPx()&&(this._tooltipAnchor=null)},_tooltipAnchorPx(){let e=this._tooltipAnchor;if(!e)return null;let t=this._dataPx(e.xAxis,e.x),n=this._dataPx(e.yAxis,e.y),r=this.plot;return!Number.isFinite(t)||!Number.isFinite(n)||tr.x+r.w||nr.y+r.h?null:{lx:t,ly:n}},_hideTooltip(){this.tooltip.style.display=`none`,this._tooltipAnchor=null},_repositionTooltip(){if(!this._tooltipAnchor)return;let e=this._tooltipAnchorPx();if(!e){this.tooltip.style.display=`none`;return}this.tooltip.style.display=`block`,this._placeTooltip(e.lx,e.ly)},_placeTooltip(e,t){let n=this.tooltip.offsetWidth,r=this.tooltip.offsetHeight,i=Math.max(4,this.size.w-n-4),a=Math.max(4,Math.min(e+12,i)),o=t+12,s=t-r-12,c=o+r<=this.size.h-4?o:Math.max(4,s);this.tooltip.style.left=a+`px`,this.tooltip.style.top=c+`px`},_renderTooltip(e,t,n,r={}){if(!e||this.spec.show_tooltip===!1){this._hideTooltip();return}let i=this._tooltipLines(e);if(this._customTooltip||(this.tooltip.textContent=``,i.forEach((e,t)=>{t&&this.tooltip.appendChild(document.createElement(`br`)),this.tooltip.appendChild(document.createTextNode(e))})),this.a11yLive&&r.announce!==!1){let e=this._a11yKeyboardReadout,t=i.join(`, `),n=e?`Point ${e.flat+1} of ${e.total}. ${t}`:t;this.a11yLive.textContent!==n&&(this.a11yLive.textContent=n)}this.tooltip.style.display=`block`;let a=this._tooltipAnchorPx();if(a)this._placeTooltip(a.lx,a.ly);else if(this._tooltipAnchor)this.tooltip.style.display=`none`;else{let e=this.root.getBoundingClientRect();this._placeTooltip(t-e.left,n-e.top)}}}),Object.assign(Q.prototype,{_initInteraction(){let e=this.canvas,t=null,n=null;this.selRect=document.createElement(`div`),this.selRect.style.cssText=`position:absolute;display:none;pointer-events:none;z-index:4;`,this._applySlot(this.selRect,`selection`),this.root.appendChild(this.selRect),this.selLasso=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this.selLasso.style.cssText=`position:absolute;display:none;pointer-events:none;z-index:4;overflow:visible;`,this.selLasso.dataset.xySelectionLassoOverlay=``,this.selLassoPath=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),this.selLassoPath.dataset.xySelectionLasso=``,this.selLasso.appendChild(this.selLassoPath),this.selLassoHandles=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),this.selLassoHandles.dataset.xySelectionLassoHandles=``,this.selLasso.appendChild(this.selLassoHandles),this.root.appendChild(this.selLasso),this._lassoPolygon=null;let r=null,i=t=>{if(!r||t.pointerId!==r.pointerId||!this._lassoPolygon)return;let n=e.getBoundingClientRect(),i=Math.max(0,Math.min(n.width,t.clientX-n.left)),a=Math.max(0,Math.min(n.height,t.clientY-n.top));this._lassoPolygon[r.index]=this._dataFromCanvas(i,a),this._renderLassoSelection(),t.preventDefault(),t.stopPropagation()};this._listen(this.selLasso,`pointerdown`,e=>{let t=e.target.closest?.(`[data-xy-selection-lasso-handle]`);if(!t||!this._lassoPolygon)return;let n=Number(t.dataset.xySelectionLassoHandle);if(!(!Number.isInteger(n)||!this._lassoPolygon[n])){r={index:n,pointerId:e.pointerId,original:[...this._lassoPolygon[n]],handle:t},t.dataset.xyActive=``,this._hideTooltip();try{this.selLasso.setPointerCapture(e.pointerId)}catch{}e.preventDefault(),e.stopPropagation()}}),this._listen(this.selLasso,`pointermove`,i),this._listen(this.selLasso,`pointerup`,e=>{if(!r||e.pointerId!==r.pointerId)return;i(e);let t=r.handle;r=null,delete t.dataset.xyActive,this._lassoPolygon&&this._sendSelectPolygon(this._lassoPolygon)}),this._listen(this.selLasso,`pointercancel`,e=>{!r||e.pointerId!==r.pointerId||(this._lassoPolygon&&(this._lassoPolygon[r.index]=r.original),delete r.handle.dataset.xyActive,r=null,this._lassoPolygon&&this._renderLassoSelection(),e.stopPropagation())}),this._interactionFlag(`crosshair`)&&(this.crosshairX=document.createElement(`div`),this.crosshairX.style.cssText=`position:absolute;display:none;pointer-events:none;z-index:3;width:1px;`,this._applySlot(this.crosshairX,`crosshair_x`),this.root.appendChild(this.crosshairX),this.crosshairY=document.createElement(`div`),this.crosshairY.style.cssText=`position:absolute;display:none;pointer-events:none;z-index:3;height:1px;`,this._applySlot(this.crosshairY,`crosshair_y`),this.root.appendChild(this.crosshairY));let a=(t,n)=>{let r=e.getBoundingClientRect();return this._dataFromCanvas(t-r.left,n-r.top)},o=(t,n)=>{let r=e.getBoundingClientRect(),i=Math.max(0,Math.min(r.width,t-r.left)),a=Math.max(0,Math.min(r.height,n-r.top));return{x:r.left+i,y:r.top+a,data:this._dataFromCanvas(i,a)}};this._listen(e,`pointerdown`,r=>{this._cancelViewAnimation();let i=this._interactionFlag(`pan`,!0),s=this._interactionFlag(`zoom`,!0),c=this._interactionFlag(`navigation`,!0),l=this._interactionFlag(`box_zoom`,!0),u=this._interactionFlag(`brush`,!0)&&this._interactionFlag(`select`,!0),d=this.dragMode.startsWith(`select`)?this.dragMode:null,f=(r.shiftKey||d)&&u&&this._pickable?r.shiftKey?`select`:d:this.dragMode===`zoom`&&c&&s&&l?`zoom`:null;if(f){let t=f.startsWith(`select`)&&this._lassoPolygon?this._lassoPolygon.map(e=>[...e]):null;f.startsWith(`select`)&&this._clearLassoOverlay();let i=f===`select-lasso`?o(r.clientX,r.clientY):null,s=i?i.data:a(r.clientX,r.clientY);n={mode:f,sx:r.clientX,sy:r.clientY,d0:s,points:i?[i]:null,previousLasso:t};try{e.setPointerCapture(r.pointerId)}catch{}this._hideTooltip();return}if(this.dragMode===`pan`&&c&&i){t={px:r.clientX,py:r.clientY,view:this._copyView(this.view),moved:!1,interactionId:++this._interactionSeq,axes:[...new Set([...this._axisPolicy(`pan_axes`),...this._axisIds().filter(e=>this._axisContained(e))])],changedAxes:[]};try{e.setPointerCapture(r.pointerId)}catch{}this._hideTooltip()}}),this._listen(e,`pointermove`,e=>{if(n){this._updateBand(n,e);return}if(t){t.moved=!0;let n=Object.fromEntries(this._axisIds().map(e=>[e,[...this._axisRange(e,t.view)]]));for(let r of t.axes){let i=this._axis(r),[a,o]=this._axisRange(r,t.view),s=this._axisCoord(i,a),c=this._axisCoord(i,o);if(![s,c].every(Number.isFinite)||s===c)continue;let l=this._axisDim(r),u=l===`x`?this.plot.w:this.plot.h,d=(l===`x`?e.clientX-t.px:e.clientY-t.py)/u*(c-s),f=l===`x`?-d:d;n[r]=[this._axisValue(i,s+f),this._axisValue(i,c+f)]}let r=this._setView({ranges:n},{source:`pan_drag`,phase:`update`,interactionId:t.interactionId});t.changedAxes=[...new Set([...t.changedAxes,...r])];return}this._updateCrosshair(e),this._hover(e)}),this._listen(e,`pointerup`,e=>{if(n){n.mode===`select-lasso`&&this._updateBand(n,e),this.selRect.style.display=`none`,this.selLasso.style.display=`none`;let t=a(e.clientX,e.clientY);if(n.mode===`select-lasso`?n.points.length>=3:Math.abs(e.clientX-n.sx)>3||Math.abs(e.clientY-n.sy)>3){if(n.mode===`zoom`&&this._interactionFlag(`zoom`,!0))this._zoomToBox(n.d0,t,!0,{source:`box_zoom`,phase:`end`,interactionId:++this._interactionSeq});else if(n.mode===`select-lasso`)if(n.points.length>=3){let e=this._simplifyLassoPoints(n.points);this._sendSelectPolygon(e.map(e=>e.data))}else n.previousLasso&&(this._lassoPolygon=n.previousLasso,this._renderLassoSelection());else{let e=n.d0;n.mode===`select-x`?(e=[n.d0[0],this.view.y0],t[1]=this.view.y1):n.mode===`select-y`&&(e=[this.view.x0,n.d0[1]],t[0]=this.view.x1),this._sendSelect(e,t)}this._ignoreNextClick=!0}else n.previousLasso&&(this._lassoPolygon=n.previousLasso,this._renderLassoSelection());n=null;return}t&&t.moved&&(this._ignoreNextClick=!0,t.changedAxes.length&&this._emitViewChange(`pan_drag`,{axes:t.changedAxes,phase:`end`,interactionId:t.interactionId})),t&&!t.moved&&this._hideTooltip(),t=null}),this._listen(e,`pointercancel`,()=>{this.selRect.style.display=`none`,this.selLasso.style.display=`none`,n?.previousLasso&&(this._lassoPolygon=n.previousLasso,this._renderLassoSelection()),n=null,t=null}),this._listen(e,`pointerleave`,()=>this._pointerHoverExit()),this._listen(document,`pointerover`,e=>{!this._lastHoverXY||this._a11yKeyboardReadout||this.root.contains(e.target)||this._pointerHoverExit()}),this._listen(e,`click`,e=>this._click(e)),this._listen(e,`wheel`,t=>{if(!this._interactionFlag(`navigation`,!0)||!this._interactionFlag(`zoom`,!0)||!this._interactionFlag(`wheel_zoom`,!0))return;t.preventDefault();let n=1.0015**t.deltaY,r=e.getBoundingClientRect(),i=(t.clientX-r.left)/r.width,a=1-(t.clientY-r.top)/r.height;this._queueWheelZoom(n,i,a)},{passive:!1}),this._listen(e,`dblclick`,()=>{this._interactionFlag(`navigation`,!0)&&this._interactionFlag(`double_click_reset`,!0)&&this._resetView(!0,`reset`)}),this._listen(e,`keydown`,e=>{e.key===`Escape`&&(n||t)&&(this.selRect.style.display=`none`,this.selLasso.style.display=`none`,n=null,t=null,e.preventDefault(),e.stopImmediatePropagation())}),this._listen(e,`keydown`,e=>this._onA11yKey(e))},_pointerHoverExit(){let e=this._hoverId!==-1;this._hoverId=-1,this._hoverTarget=null,this._lastHoverXY=null,this._a11yKeyboardReadout=null,this._pickSeq=(this._pickSeq||0)+1,this._hideTooltip(),this._hideCrosshair(),this._interactionFlag(`hover`)&&this._dispatchChartEvent(`leave`,{view:this._eventView(`leave`),active:!1}),e&&this._drawKeepPick()},_a11yPointGroups(){return(this.gpuTraces||[]).filter(e=>J(e.trace.kind).pointPick&&e.tier!==`density`&&e._cpu&&e._cpu.x&&e._cpu.y&&Math.min(e._cpu.x.length,e._cpu.y.length)>0)},_onA11yKey(e){let t={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1}[e.key],n=e.key===`Enter`||e.key===` `;if(t===void 0&&e.key!==`Home`&&e.key!==`End`&&e.key!==`Escape`&&!n)return;if(n){if(!this._interactionFlag(`click`)||!this._hoverTarget)return;e.preventDefault();let t=this._hoverTarget,n=this.canvas.getBoundingClientRect(),r=this._lastHoverXY?.clientX??n.left,i=this._lastHoverXY?.clientY??n.top,a={x:r-n.left,y:i-n.top},o={shift:e.shiftKey===!0,alt:e.altKey===!0,ctrl:e.ctrlKey===!0,meta:e.metaKey===!0},s={row:this._localRow?this._localRow(t):null,trace:t.trace,index:t.index,screen:a,modifiers:o,view:this._eventView(`click`)};if(this._dispatchChartEvent(`click`,s),this.comm){let e={type:`click`,trace:t.trace,index:t.index,screen:a,modifiers:o},n=t.g;n&&n.tier===`density`&&n.drill&&n.drill.seq!==void 0&&(e.drill_seq=n.drill.seq),this.comm.send(e)}return}if(e.key===`Escape`){e.preventDefault();let t=this._hoverId!==-1;this._hideTooltip(),this._hoverId=-1,this._hoverTarget=null,this._lastHoverXY=null,this._a11yKeyboardReadout=null,this._pickSeq=(this._pickSeq||0)+1,this.a11yLive&&(this.a11yLive.textContent=`Readout closed.`),t&&this._interactionFlag(`hover`)&&this._dispatchChartEvent(`leave`,{view:this._eventView(`leave`),active:!1}),t&&this._drawKeepPick();return}if(e.preventDefault(),this._interactionTransitionActive())return;let r=this._a11yPointGroups(),i=r.reduce((e,t)=>e+Math.min(t._cpu.x.length,t._cpu.y.length),0);if(!i)return;let a=Number.isInteger(this._a11yPointIndex)?this._a11yPointIndex:-1;a=e.key===`Home`?0:e.key===`End`?i-1:a<0?t>0?0:i-1:Math.max(0,Math.min(i-1,a+t)),this._a11yPointIndex=a;let o=a,s=r[0];for(let e of r){let t=Math.min(e._cpu.x.length,e._cpu.y.length);if(ot.width||i<0||i>t.height){this._hideCrosshair();return}let a=e.clientX-n.left,o=e.clientY-n.top;this.crosshairX.style.display=`block`,this.crosshairX.style.left=a+`px`,this.crosshairX.style.top=this.plot.y+`px`,this.crosshairX.style.height=this.plot.h+`px`,this.crosshairY.style.display=`block`,this.crosshairY.style.left=this.plot.x+`px`,this.crosshairY.style.top=o+`px`,this.crosshairY.style.width=this.plot.w+`px`},_hideCrosshair(){this.crosshairX&&(this.crosshairX.style.display=`none`),this.crosshairY&&(this.crosshairY.style.display=`none`)},_click(e){if(this._ignoreNextClick){this._ignoreNextClick=!1;return}if(!this._interactionFlag(`click`))return;let t=this.canvas.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,[i,a]=this._dataFromCanvas(n,r),o=this._pickAt(n,r)||this._hoverAt(n,r),s={x:i,y:a,view:this._eventView(`click`),row:o&&this._localRow?this._localRow(o):null,trace:o?o.trace:null,index:o?o.index:null};if(this._dispatchChartEvent(`click`,s),o&&this.comm){let t={type:`click`,trace:o.trace,index:o.index,screen:{x:n,y:r},modifiers:{shift:e.shiftKey===!0,alt:e.altKey===!0,ctrl:e.ctrlKey===!0,meta:e.metaKey===!0}},i=o.g;i&&i.tier===`density`&&i.drill&&i.drill.seq!==void 0&&(t.drill_seq=i.drill.seq),this.comm.send(t)}},_updateBand(e,t){let n=this.canvas.getBoundingClientRect(),r=this.root.getBoundingClientRect();if(e.mode===`select-lasso`){let i=e.points[e.points.length-1],a=Math.max(0,Math.min(n.width,t.clientX-n.left)),o=Math.max(0,Math.min(n.height,t.clientY-n.top)),s=n.left+a,c=n.top+o;e.points.length<2048&&Math.hypot(s-i.x,c-i.y)>=3&&e.points.push({x:s,y:c,data:this._dataFromCanvas(a,o)});let l=e.points.map(e=>[Math.max(this.plot.x,Math.min(this.plot.x+this.plot.w,e.x-r.left)),Math.max(this.plot.y,Math.min(this.plot.y+this.plot.h,e.y-r.top))]);this.selLasso.style.display=`block`,this.selLasso.style.inset=`0`,this.selLasso.setAttribute(`width`,String(this.root.clientWidth)),this.selLasso.setAttribute(`height`,String(this.root.clientHeight)),this.selLassoPath.setAttribute(`d`,l.map((e,t)=>`${t?`L`:`M`}${e[0]} ${e[1]}`).join(` `)+` Z`);return}let i=Math.min(e.sx,t.clientX)-r.left,a=Math.min(e.sy,t.clientY)-r.top,o=Math.abs(t.clientX-e.sx),s=Math.abs(t.clientY-e.sy),c=this.plot.x,l=this.plot.y,u=Math.min(i+o,c+this.plot.w),d=Math.min(a+s,l+this.plot.h),f=Math.max(i,c),p=Math.max(a,l),m=u,h=d;e.mode===`select-x`&&(p=l,h=l+this.plot.h),e.mode===`select-y`&&(f=c,m=c+this.plot.w),this.selRect.dataset.xyBand=e.mode===`zoom`?`zoom`:`select`,this.selRect.style.display=`block`,this.selRect.style.left=f+`px`,this.selRect.style.top=p+`px`,this.selRect.style.width=Math.max(0,m-f)+`px`,this.selRect.style.height=Math.max(0,h-p)+`px`},_simplifyLassoPoints(e,t=6,n=16){let r=e.filter(e=>e&&Number.isFinite(e.x)&&Number.isFinite(e.y));if(r.length>3){let e=r[0],n=r[r.length-1];Math.hypot(e.x-n.x,e.y-n.y)<=t&&r.pop()}if(r.length<=3)return r.slice();let i=(e,t,n)=>{let r=n.x-t.x,i=n.y-t.y;if(r===0&&i===0)return(e.x-t.x)**2+(e.y-t.y)**2;let a=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/(r*r+i*i))),o=t.x+a*r,s=t.y+a*i;return(e.x-o)**2+(e.y-s)**2},a=e=>{let t=new Uint8Array(r.length);t[0]=1,t[r.length-1]=1;let n=[[0,r.length-1]],a=e*e;for(;n.length;){let[e,o]=n.pop(),s=-1,c=a;for(let t=e+1;tc&&(s=t,c=n)}s>=0&&(t[s]=1,n.push([e,s],[s,o]))}return r.filter((e,n)=>t[n])},o=a(t);if(o.length<3&&(o=[r[0],r[Math.floor(r.length/2)],r[r.length-1]]),o.length>n){let e=t,i=Math.max(t,1);for(let t=0;t<16&&o.length>n;t++)e=i,i*=2,o=a(i);for(let t=0;t<12;t++){let t=(e+i)/2,r=a(t);r.length>n?e=t:(i=t,o=r)}o.length<3&&(o=[r[0],r[Math.floor(r.length/2)],r[r.length-1]])}return o},_clearLassoOverlay(){this._lassoPolygon=null,this.selLasso&&(this.selLasso.style.display=`none`,this.selLassoPath?.removeAttribute(`d`),this.selLassoHandles?.replaceChildren())},_renderLassoSelection(){let e=this._lassoPolygon;if(!this.selLasso||!this.selLassoPath||!this.selLassoHandles||!Array.isArray(e)||e.length<3)return;let[t,n]=this._axisRange(`x`),[r,i]=this._axisRange(`y`),a=this._axis(`x`),o=this._axis(`y`),s=this._axisCoord(a,t),c=this._axisCoord(a,n),l=this._axisCoord(o,r),u=this._axisCoord(o,i);if(![s,c,l,u].every(Number.isFinite)||s===c||l===u)return;let d=e.map(e=>{let t=this._axisCoord(a,e[0]),n=this._axisCoord(o,e[1]),r=this.plot.x+(t-s)/(c-s)*this.plot.w,i=this.plot.y+(u-n)/(u-l)*this.plot.h;return[Math.max(this.plot.x,Math.min(this.plot.x+this.plot.w,r)),Math.max(this.plot.y,Math.min(this.plot.y+this.plot.h,i))]});if(d.flat().every(Number.isFinite)){for(this.selLasso.style.display=`block`,this.selLasso.style.inset=`0`,this.selLasso.setAttribute(`width`,String(this.root.clientWidth)),this.selLasso.setAttribute(`height`,String(this.root.clientHeight)),this.selLassoPath.setAttribute(`d`,d.map((e,t)=>`${t?`L`:`M`}${e[0]} ${e[1]}`).join(` `)+` Z`);this.selLassoHandles.childElementCountd.length;)this.selLassoHandles.lastElementChild.remove();[...this.selLassoHandles.children].forEach((e,t)=>{e.dataset.xySelectionLassoHandle=String(t),e.setAttribute(`cx`,String(d[t][0])),e.setAttribute(`cy`,String(d[t][1])),e.setAttribute(`aria-label`,`Lasso point ${t+1}`)})}},_sendSelect(e,t,n={}){this._clearLassoOverlay();let r=Math.min(e[0],t[0]),i=Math.max(e[0],t[0]),a=Math.min(e[1],t[1]),o=Math.max(e[1],t[1]),s={x0:r,x1:i,y0:a,y1:o};this._historyRecord({source:n.source,interactionId:n.interactionId,history:n.history}),this._stateSelection={range:{...s}},this._lastBrush={mode:`box`,x0:r,x1:i,y0:a,y1:o},this._broadcastLinkedSelection({range:s}),this._dispatchChartEvent(`brush`,{range:s,view:this._eventView(`brush`)}),this.comm?this.comm.send({type:`select`,x0:r,x1:i,y0:a,y1:o}):this._selectLocal(r,i,a,o)},_sendSelectPolygon(e,t={}){if(!Array.isArray(e)||e.length<3)return;let n=e.map(e=>[e[0],e[1]]);n.every(e=>e.every(Number.isFinite))&&(this._historyRecord({source:t.source,interactionId:t.interactionId,history:t.history}),this._stateSelection={polygon:n.map(e=>[...e])},this._lassoPolygon=n,this._lastBrush={mode:`poly`,points:n},this._broadcastLinkedSelection({polygon:n}),this._renderLassoSelection(),this._dispatchChartEvent(`brush`,{polygon:n,view:this._eventView(`brush`)}),this.comm?this.comm.send({type:`select_polygon`,points:n}):this._selectLocalPolygon(n))},_selectLocalPolygon(e,t={}){let n=e.map(e=>e[0]),r=e.map(e=>e[1]),i=Math.min(...n),a=Math.max(...n),o=Math.min(...r),s=Math.max(...r),c=(t,n)=>{let r=!1;for(let i=0,a=e.length-1;in!=l>n&&t<(c-o)*(n-s)/(l-s)+o&&(r=!r)}return r},l=0;for(let e of this.gpuTraces){if(!e._cpu||e.tier===`density`)continue;let t=e._cpu.x,n=e._cpu.y,r=e._cpu.xMeta||e.xMeta,u=e._cpu.yMeta||e.yMeta,d=r.offset,f=r.scale||1,p=u.offset,m=u.scale||1,h=new Float32Array(e.n),g=0;for(let r=0;r