@wafertools/wafermap 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +24 -3
  2. package/README.md +2 -2
  3. package/dist/packages/canvas-adapter/charts/commonality.js +4 -1
  4. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +5 -0
  5. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  8. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  9. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  10. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  11. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  12. package/dist/packages/canvas-adapter/sweepEditor.js +1 -1
  13. package/dist/packages/canvas-adapter/toCanvas.d.ts +1 -0
  14. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  15. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  16. package/dist/packages/canvas-adapter/userGuideHtml.js +44 -28
  17. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  18. package/dist/packages/canvas-adapter/version.js +1 -1
  19. package/dist/packages/core/compact.js +2 -2
  20. package/dist/packages/core/dieTable.js +1 -1
  21. package/dist/packages/stats/commonality.d.ts +37 -4
  22. package/dist/packages/stats/commonality.js +1 -1
  23. package/dist/packages/stats/dieRegions.d.ts +2 -0
  24. package/dist/packages/stats/dieRegions.js +1 -1
  25. package/dist/packages/stats/examplePicks.d.ts +6 -0
  26. package/dist/packages/stats/examplePicks.js +1 -1
  27. package/dist/packages/stats/groupEffects.d.ts +66 -0
  28. package/dist/packages/stats/groupEffects.js +1 -0
  29. package/dist/packages/stats/plotData.js +1 -1
  30. package/dist/packages/stats/renderFindingsReport.js +1 -1
  31. package/dist/packages/stats/renderSummaryReport.js +7 -7
  32. package/dist/packages/stats/reportHtml.js +18 -13
  33. package/dist/packages/stats/sweep.d.ts +3 -3
  34. package/dist/packages/stats/sweepXFromName.js +1 -1
  35. package/dist/packages/stats/synthesis.d.ts +13 -0
  36. package/dist/packages/stats/synthesis.js +1 -1
  37. package/package.json +1 -1
@@ -1 +1 @@
1
- import{fontPx as Ot}from"./toolbar.js";import{findTestDef as Ee,buildMapTitle as He}from"../renderer/buildView.js";import{niceStep as Et,compactTickIndices as mo}from"../renderer/axisTicks.js";import{sortBinsForDisplay as uo}from"../stats/binPareto.js";import{affineInvert as po,affineVector as Ge}from"../core/transforms.js";import{asList as xo,compareNatural as Mo,maxOf as te,minOf as Xe}from"../core/utils.js";import{resolveValueColorFn as yo}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as bo}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ye,SPEC_FAIL_LOW as To,SPEC_FAIL_HIGH as $e,contrastTextColor as we}from"../renderer/colorMap.js";import{fmt as Ve,fmtColorbarAxis as Ke}from"../renderer/fmt.js";import{resolveCanvasTheme as So}from"./canvasTheme.js";import{hitGridDims as ko}from"./hitGrid.js";const Lo=5,ze=4;function qe(f,e,F,g,l){f.moveTo(e,F+l*g),f.lineTo(e-g*.9,F-l*g*.6),f.lineTo(e+g*.9,F-l*g*.6),f.closePath()}const Ao=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),_o=new Set(["hardBin","softBin","metadata"]),ct=()=>`${Ot(-2)}px system-ui, sans-serif`,Ue=3,ee=2,Co=6,Ro=20,Po=()=>`600 ${Ot()}px system-ui, sans-serif`,Je=36,be=()=>`${Ot(-1)}px system-ui, sans-serif`,je=()=>`600 ${Ot(-1)}px system-ui, sans-serif`,oe=128,Bo=()=>`${Ot(-2)}px system-ui, sans-serif`,Ze=4,K=17,Q=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const ne=28,At=5,yt=8,Qe=15,ve=12,to=6;export function toCanvas(f,e,F={}){return drawMapCanvas(f,e,F)}export function drawMapCanvas(f,e,F={}){const g=So(f.parentElement??f),{padding:l=16,showColorbar:P=!0,markFailingDies:q=!1,colorbarWidth:m=16,background:Y=g.background,legendPosition:N="default",legendOffset:U,showAxes:J=!1,diePitchMm:B,viewport:$,activeBin:H,hoverBin:v,afterDies:Ht,fallbackFormat:_t,minRightReserve:Gt,hbinDefs:mt,sbinDefs:Ct,metadataFields:Xt,showTitle:nt=!0}=F,ut=xo(H),G=Math.floor(f.clientWidth||f.width),j=Math.floor(f.clientHeight||f.height),Rt=G>=BIN_LEGEND_MIN_CANVAS_W&&j>=BIN_LEGEND_MIN_CANVAS_H,It=P&&Rt&&Ao.has(e.plotMode)&&e.passFailDisplay==="off",Dt=P&&Rt&&_o.has(e.plotMode),ht=P&&Rt&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),dt=Dt||ht,Yt=Dt&&e.plotMode!=="metadata"&&e.binCounts?uo(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],$t=Dt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(Mo)].map(o=>[o,e.metadataCounts.get(o)??0]):[],gt=[];if(ht&&e.passFailDisplay==="test"){const o=e.passFailCounts;gt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),gt.push({key:-2,color:$e,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ht){const o=e.specCounts,c=Ee(e.testDefs,e.activeTest);gt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),c?.limitHigh!==void 0&&gt.push({key:-2,color:$e,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),c?.limitLow!==void 0&&gt.push({key:-3,color:To,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const wt=ht?gt.length:e.plotMode==="metadata"?$t.length:Yt.length,et=(f.ownerDocument.defaultView??window).devicePixelRatio??1;if(G<=0||j<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const st=N!=="default"?N:G<BIN_LEGEND_ADAPT_FLOATING?"floating":G<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",y=st==="default"||st==="compact",rt=st==="left",z=st==="bottom",bt=st==="top",Tt=st==="floating",St=st==="compact"||st==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,Te=Math.floor((j-2*l)/K),Se=wt>Te?Te-1:wt,ke=dt&&z?Se*K:0,se=dt&&bt?Se*K:0,le=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",ie=Ee(e.testDefs,e.activeTest),Le=le?"Count":ie?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Ae=le?void 0:ie?.unit,[Wt,Ft]=e.valueRange,ae=o=>String(Math.round(o)),no=e.logScale||e.allIntegerValues?void 0:Et(Math.max(0,Ft-Wt)*Je/Math.max(1,j))||void 0,ce=e.allIntegerValues?ae:Ke(Ft,Le,Ae,_t,no).edgeFmt;let re=0;if(It){const o=f.getContext("2d");o.font=ct();const c=[ce(Wt),ce(Ft)];Wt<0&&c.push(ce(-Math.max(Math.abs(Wt),Math.abs(Ft))));for(const x of c)re=Math.max(re,o.measureText(x).width)}const _e=Math.max(Ro,Math.ceil(re)+Ue+ee+Co-l),fe=It?m+_e+8:dt&&y?St:0,he=dt&&rt?St:0,de=J?32:0,Vt=J?36:0,so=Gt!=null?Math.max(fe,Gt):fe,lo=G-2*l-so-Vt-he,Ce=j-2*l-de-ke-se;f.width=Math.round(G*et),f.height=Math.round(j*et);const t=f.getContext("2d");t.scale(et,et),t.fillStyle=Y,t.fillRect(0,0,G,j);const ot=e.hoverPoints;if(!ot.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Kt=e.rectangles[0],ge=Kt?Kt.width/2:0,me=Kt?Kt.height/2:0,zt=e.dieBounds,Re=(zt?.minX??0)-ge,io=(zt?.maxX??0)+ge,ao=(zt?.minY??0)-me,Pe=(zt?.maxY??0)+me,Be=io-Re,Ie=Pe-ao;let lt,it,C;if($)({originX:lt,originY:it,ppm:C}=$);else{const c=e.notchDir,x=c&&c.y>.1?13:0,u=c&&c.y<-.1?13:0,k=c&&c.x<-.1?13:0,p=c&&c.x>.1?13:0,h=lo-k-p,i=Ce-x-u;C=Math.min(h/Be,i/Ie),lt=l+Vt+he+k+(h-Be*C)/2-Re*C,it=l+se+x+(i-Ie*C)/2+Pe*C}const qt=$?.snapDist??Math.max(ge,me,1)*1.5,Ut=lt+e.waferCenter.x*C,co=it-e.waferCenter.y*C,ue=e.waferRadius*C,pt=o=>{const c=Math.abs(o-co);return c>=ue?0:Math.sqrt(ue*ue-c*c)},kt=(o,c,x,u,k,p,h=Po(),i=g.text)=>{if(!o)return;t.save(),t.fillStyle=i,t.font=h,t.textAlign=u,t.textBaseline=k;const a=u==="right"?c-p:p-c;let n=o;if(a>8&&t.measureText(n).width>a){for(;n.length>1&&t.measureText(n+"\u2026").width>a;)n=n.slice(0,-1);n=n+"\u2026"}a>8&&t.fillText(n,c,x),t.restore()};t.save(),t.setTransform(C*et,0,0,-C*et,lt*et,it*et);const xt=1/C;let Jt=!1;const ro=1/(C*et),jt=e.rectangles.length>0&&e.dieGap*C*et<1;if(e.rectangles.length>0){const o=new Map;for(const h of e.rectangles){const i=String(h.fill);let a=o.get(i);a||(a=[],o.set(i,a)),a.push(h)}const c=C*et,x=lt*et,u=it*et,k=e.dieGap/2;jt&&(t.save(),t.setTransform(1,0,0,1,0,0));for(const[h,i]of o){t.fillStyle=h;for(let a=0;a<i.length;a+=PATH_SHAPES){t.beginPath();const n=Math.min(i.length,a+PATH_SHAPES);for(let s=a;s<n;s++){const d=i[s];if(jt){const L=d.width/2+k,b=d.height/2+k,I=2*L*c>=ze?1:0,Z=2*b*c>=ze?1:0,tt=Math.round(x+(d.x-L)*c),D=Math.max(tt+1,Math.round(x+(d.x+L)*c)-I),R=Math.round(u-(d.y+b)*c),Lt=Math.max(R+1,Math.round(u-(d.y-b)*c)-Z);t.rect(tt,R,D-tt,Lt-R)}else t.rect(d.x-d.width/2,d.y-d.height/2,d.width,d.height)}t.fill()}}if(jt&&t.restore(),!jt){t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*ro,t.lineCap="square";const h=oo.get(e.rectangles)??outlineSegments(e.rectangles);oo.set(e.rectangles,h);const i=PATH_SHAPES*4;for(let a=0;a<h.length;a+=i){t.beginPath();const n=Math.min(h.length,a+i);for(let s=a;s<n;s+=4)t.moveTo(h[s],h[s+1]),t.lineTo(h[s+2],h[s+3]);t.stroke()}t.lineCap="butt"}if(q){const h=e.rectangles.filter(i=>i.binFail);if(h.length>0){const i=new Map;for(const a of h){const n=we(String(a.fill));let s=i.get(n);s||(s=[],i.set(n,s)),s.push(a)}t.save(),t.lineCap="butt";for(const[a,n]of i){t.strokeStyle=a,t.globalAlpha=.55,t.lineWidth=Math.max(.6*xt,Math.min(n[0].width,n[0].height)*.1);for(const s of n){const d=s.width/2,L=s.height/2,b=Math.max(1.6*xt,Math.min(s.width,s.height)/3);t.save(),t.beginPath(),t.rect(s.x-d,s.y-L,s.width,s.height),t.clip(),t.beginPath();for(let I=-(d+L);I<=d+L;I+=b)t.moveTo(s.x-d+I,s.y-L),t.lineTo(s.x-d+I+s.height,s.y+L);t.stroke(),t.restore()}}t.restore()}}const p=e.rectangles.filter(h=>h.specMark);if(Jt=p.length>0&&Math.min(p[0].width,p[0].height)<Lo*xt,p.length>0&&!Jt){const h=new Map;for(const a of p){const n=we(String(a.fill)),s=`${a.specMark}|${n}`;let d=h.get(s);d||(d=[],h.set(s,d)),d.push(a)}const i=2.5*xt;t.lineJoin="round";for(const[a,n]of h){const[s,d]=a.split("|"),L=d==="#000000"?"#ffffff":"#000000",b=s==="failHigh"?1:-1,I=Math.min(n[0].width,n[0].height),Z=Math.max(2.5*xt,I*.3);t.beginPath();for(const tt of n)qe(t,tt.x,tt.y,Z,b);t.strokeStyle=L,t.lineWidth=i,t.stroke(),t.fillStyle=d,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const c of o.points){for(let x=0;x<c.length;x++)x===0?t.moveTo(c[x].x,c[x].y):t.lineTo(c[x].x,c[x].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*xt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*xt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*xt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*C,c=it-e.waferCenter.y*C,x=e.notchDir.x,u=-e.notchDir.y,k=e.waferRadius*C,p=4,h=9,i=5,a=o+x*(k+p),n=c+u*(k+p),s=a+x*h,d=n+u*h,L={x:-u,y:x},b=l+Vt+he,I=G-l-fe,Z=l+se,tt=j-l-ke-de;t.save(),t.beginPath(),t.rect(b,Z,I-b,tt-Z),t.clip(),t.beginPath(),t.moveTo(a,n),t.lineTo(s+L.x*i,d+L.y*i),t.lineTo(s-L.x*i,d-L.y*i),t.closePath(),t.fillStyle=g.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let De=0;if(e.rectangles.length>0){let o=1;for(const p of e.texts)p.role!=="indicator"&&p.text.length>o&&(o=p.text.length);const c=e.rectangles[0].width*C,x=e.rectangles[0].height*C,u=Math.min(c,x),k=c/o;De=Math.max(8,Math.min(64,Math.round(Math.min(u*.55,k*1.8))))}for(const o of e.texts){const c=lt+o.x*C,x=it-o.y*C;t.font=`${o.role==="indicator"?o.fontSize:De}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,c,x)}if(t.restore(),Ht?.(t,{originX:lt,originY:it,ppm:C},{background:Y,text:g.text}),J&&Io(t,G,j,lt,it,C,l,de,Vt,B,e.gridToScreen,e.rotation,g,e.compact),It){const o=yo(e.valueColorScheme,e.reverseValueScheme),c=_e,x=Ce,u=Math.round(x*.75),k=l+Math.round((x-u)/2),p=G-l-m-c,h=Wt,i=Ft,a=i-h,n=e.plotMode==="stackedSoftBins"?Ct:mt,{primary:s,secondary:d,note:L}=nt?He(e,_t,n):{primary:"",secondary:"",note:void 0};if(nt){const r=Math.max(k-6,l+11),E=Ut+Math.max(pt(r),pt(r-12))+8;kt(s,G-l,r,"right","bottom",E)}let b=k+u+4;const I=r=>Ut+Math.max(pt(r),pt(r+12))+8,Z=e.logScale&&h>0?Math.log10(h):0,tt=e.logScale&&i>0?Math.log10(i)-Z:1,D=r=>e.logScale?(1-(Math.log10(r)-Z)/tt)*u:(1-(r-h)/a)*u;for(let r=0;r<oe;r++){const E=1-r/(oe-1),X=k+r/oe*u,M=u/oe+1;t.fillStyle=o(E),t.fillRect(p,X,m,M)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(p,k,m,u),t.fillStyle=g.text,t.font=ct(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const R=Ue,Lt=Je,ft=14;let w;const O=e.logScale&&tt>0?Do(h,i,u,Lt,ft,Z,tt):e.allIntegerValues?(()=>{const r=Math.max(1,Et(a*Lt/u)),E=[],X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const W=(1-(M-h)/a)*u;W>ft&&W<u-ft&&E.push(Math.round(M))}return E})():(()=>{const r=a>0?Et(a*Lt/u):0,E=[];if(r>0){w=r;const X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const W=(1-(M-h)/a)*u;W>ft&&W<u-ft&&E.push(M)}}return E})(),T=ie,_=le,S=Ke(i,Le,Ae,_t,w),V=e.allIntegerValues?ae:S.tickFmt,A=e.allIntegerValues?ae:S.edgeFmt;t.textBaseline="middle";for(const r of O){const E=k+D(r);t.beginPath(),t.moveTo(p+m,E),t.lineTo(p+m+R,E),t.stroke(),t.fillText(V(r),p+m+R+ee,E)}if(t.beginPath(),t.moveTo(p+m,k),t.lineTo(p+m+R,k),t.stroke(),t.textBaseline="top",t.fillText(A(i),p+m+R+ee,k),t.beginPath(),t.moveTo(p+m,k+u),t.lineTo(p+m+R,k+u),t.stroke(),t.textBaseline="bottom",t.fillText(A(h),p+m+R+ee,k+u),!_&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0)){const r=[],E=e.colorbarRangeMode==="spec";for(const[X,M]of[[T.limitLow,"Lo limit"],[T.limitHigh,"Hi limit"]]){if(X===void 0||e.logScale&&X<=0)continue;const W=D(X);!E&&(W<-ft||W>u+ft)||r.push({value:X,label:M,py:Math.max(0,Math.min(u,W))})}if(r.length>0){t.save(),t.font=ct(),t.textAlign="right",t.textBaseline="middle";for(const{py:X,label:M}of r){const W=k+X;if(E||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(p,W),t.lineTo(p+m,W),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(p,W),t.lineTo(p+m,W),t.stroke()),t.fillStyle=g.text,t.fillText(M,p-3,W),Jt)continue;const Pt=M==="Hi limit"?-1:1,Bt=4,vt=p-3-t.measureText(M).width-Bt-4;t.beginPath(),qe(t,vt,W,Bt,Pt),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=g.text,t.fill()}t.restore()}}if(!_){const r=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;r&&(t.save(),t.fillStyle=g.text,t.font=je(),t.textAlign="right",t.textBaseline="top",t.fillText(r,G-l,b),t.restore(),b+=15)}Jt&&(t.save(),t.fillStyle=g.text,t.font=je(),t.textAlign="right",t.textBaseline="top",t.fillText("\u25BD\u25B3 limit marks: zoom in",G-l,b),t.restore(),b+=15),nt&&d&&(kt(d,G-l,b,"right","top",I(b),be(),g.text),b+=15),nt&&L&&kt(L,G-l,b,"right","top",I(b),be(),g.text)}const pe=[];let at;if(dt){const o=st==="compact",c=e.plotMode==="softBin"?Ct:mt,x=c?new Map(c.map(n=>[n.bin,n])):null,u=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,k=n=>u.get(n)??bo,p=(n,s)=>{const d=t.measureText(n).width,L=o?0:t.measureText(String(s)).width,b=Q+At+d+(L?ne:0);return{labelWidth:d,countWidth:L,totalWidth:b}},h=Xt?.find(n=>n.key===e.activeMetadataKey),i=ht?gt.map(n=>{const s=o?n.compactLabel:n.label;return{key:n.key,color:n.color,count:n.count,label:s,tooltipLabel:n.tooltip,...p(s,n.count)}}):e.plotMode==="metadata"?$t.map(([n,s])=>{const L=h?.values?.find(Z=>Z.value===n)?.label??n,b=o?n:L,I=e.metadataColorMap?.get(n)??"#d6d9dd";return{key:n,color:I,count:s,label:b,tooltipLabel:`${L} \xB7 ${s} dies`,...p(b,s)}}):Yt.map(([n,s])=>{const d=x?.get(n),L=d?.name?`${n} \xB7 ${d.name}`:`Bin ${n}`,b=o?String(n):L;return{key:n,color:k(n),count:s,label:b,tooltipLabel:`${L} \xB7 ${s} dies`,...p(b,s)}}),a=G-l*2;if(i.length>0){const n=Tt?yt*2+(nt?Qe:0):nt&&!bt?ve+to:0,s=Math.max(1,Math.floor((j-2*l-n)/K));let d=i.length,L=1,b=d*K,I=[],Z=0;const tt=z||bt;if(tt){const w=te(i.map(T=>T.totalWidth)),O=Math.max(1,Math.min(i.length,Math.floor((a+8)/(w+8))));for(let T=O;T>=1;T--){const _=Math.ceil(i.length/T);if(_>s)continue;const S=new Array(T).fill(0);for(let A=0;A<i.length;A++){const r=A%T;S[r]=Math.max(S[r],i[A].totalWidth)}if(S.reduce((A,r)=>A+r,0)+(T-1)*8<=a||T===1){L=T,I=S,d=_,b=_*K;break}}}else d=Math.min(i.length,s),b=d*K,i.length>s&&(Z=i.length-(s-1)),I=[St];let D,R;if(Tt){const w=te(i.map(r=>Q+At+t.measureText(r.label).width+ne)),O=Math.ceil(w);I=[O];const T=nt?Qe:0,_=O+yt*2,S=b+T+yt*2,V=U?.x??0,A=U?.y??0;D=Math.min(Math.max(G-l-_+V,l),G-l-_),R=Math.min(Math.max(j-l-S+A,l),j-l-S),at={x:D,y:R,w:_,h:S},t.save(),t.globalAlpha=.92,t.fillStyle=g.surface,t.fillRect(D,R,_,S),t.globalAlpha=1,t.strokeStyle=g.axisLine,t.lineWidth=1,t.strokeRect(D,R,_,S),t.restore(),D+=yt,R+=yt+T}else z?(D=l,R=j-l-b):bt?(D=l,R=l):rt?(D=l+4,R=Math.max(l+Math.round((j-2*l-b)/2),l+n)):(D=G-l-St+4,R=Math.max(l+Math.round((j-2*l-b)/2),l+n));if(nt){const w=e.plotMode==="softBin"?Ct:mt,{primary:O,secondary:T,note:_}=He(e,_t,w),S=to,V=[T,_].filter(M=>!!M),A=(M,W,Pt)=>V.forEach((Bt,vt)=>kt(Bt,M,W+vt*16,"left","top",Pt(W+vt*16),be(),g.text)),r=M=>Ut-Math.max(pt(M),pt(M-12))-8,E=M=>y?G-l:r(M),X=Tt?at.y+at.h:R+b;if(bt){const M=X+S;kt(O,D,M,"left","top",Ut-Math.max(pt(M),pt(M+12))-8),A(D,M+16,r)}else if(Tt)kt(O,at.x+yt,at.y+yt,"left","top",at.x+at.w-yt),A(at.x,X+S,()=>at.x+at.w);else{const M=Math.max(R-S,l+ve);kt(O,D,M,"left","bottom",E(M)),A(D,X+S,E)}}t.save(),t.font=ct();const Lt=tt?8:0,ft=(w,O)=>{if(t.measureText(w).width<=O)return w;let T=0,_=w.length;const S="\u2026",V=t.measureText(S).width;for(;T<_;){const A=T+_+1>>1;t.measureText(w.slice(0,A)).width+V<=O?T=A:_=A-1}return T===0?S:w.slice(0,T)+S};if(tt){let w=0;for(let O=0;O<d;O++){let T=D;for(let _=0;_<L;_++){const S=i[w++];if(!S)break;const V=ut.includes(S.key),A=!V&&S.key===v,r=T,E=T+Q+At,X=R+O*K+K/2,M=R+O*K+Math.round((K-Q)/2),W=I[_]-Q-At-ne;A&&(t.fillStyle=g.hoverRow,t.fillRect(T,R+O*K,I[_],K)),t.fillStyle=S.color,t.fillRect(r,M,Q,Q),t.strokeStyle=V?g.accent:"rgba(0,0,0,0.25)",t.lineWidth=V?2:.75,t.strokeRect(r,M,Q,Q),t.fillStyle=V?g.accent:g.text,t.font=V?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(S.label,W),E,X),t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(S.count),T+I[_]-2,X),pe.push({bin:S.key,x:T,y:R+O*K,w:I[_],h:K,label:S.tooltipLabel}),T+=I[_]+Lt}}}else{const w=I[0],O=st!=="compact",T=w-Q-At-(O?ne:0),_=D+w-2;let S=i;Z>0&&(S=i.slice(0,s-1));let V=R;for(const A of S){const r=ut.includes(A.key),E=!r&&A.key===v,X=D,M=D+Q+At,W=V+K/2,Pt=V+Math.round((K-Q)/2),Bt=A.label;E&&(t.fillStyle=g.hoverRow,t.fillRect(D-3,V,w+3,K)),t.fillStyle=A.color,t.fillRect(X,Pt,Q,Q),t.strokeStyle=r?g.accent:"rgba(0,0,0,0.25)",t.lineWidth=r?2:.75,t.strokeRect(X,Pt,Q,Q),t.fillStyle=r?g.accent:g.text,t.font=r?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(Bt,T),M,W),(O||Tt)&&(t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(A.count),_,W)),pe.push({bin:A.key,x:D,y:V,w,h:K,label:A.tooltipLabel}),V+=K}Z>0&&(t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${Z} more`,D+Q+At,V+K/2))}}i.length>0&&t.restore()}const fo={originX:lt,originY:it,ppm:C,snapDist:qt},We=e.rectangles[0]?.width??1,Fe=e.rectangles[0]?.height??1,Mt=e.dieBounds,Zt=Mt?Mt.minX:ot.length?Xe(ot.map(o=>o.x)):0,Qt=Mt?Mt.minY:ot.length?Xe(ot.map(o=>o.y)):0,ho=Mt?Mt.maxX:ot.length?te(ot.map(o=>o.x)):1,go=Mt?Mt.maxY:ot.length?te(ot.map(o=>o.y)):1,{cellW:xe,cellH:Me,nCols:Nt,nRows:ye}=ko(ho-Zt,go-Qt,We*1.5,Fe*1.5,ot.length),Ne=Array.from({length:Nt*ye},()=>[]);for(let o=0;o<ot.length;o++){const c=Math.floor((ot[o].x-Zt)/xe),x=Math.floor((ot[o].y-Qt)/Me),u=Number.isFinite(c)?Math.max(0,Math.min(Nt-1,c)):0,k=Number.isFinite(x)?Math.max(0,Math.min(ye-1,x)):0;Ne[k*Nt+u].push(o)}function Oe(o,c,x){const u=Math.max(0,Math.floor((o-x-Zt)/xe)),k=Math.min(Nt-1,Math.floor((o+x-Zt)/xe)),p=Math.max(0,Math.floor((c-x-Qt)/Me)),h=Math.min(ye-1,Math.floor((c+x-Qt)/Me)),i=[];for(let a=p;a<=h;a++)for(let n=u;n<=k;n++)for(const s of Ne[a*Nt+n])i.push(s);return i}return{hitTarget:{getDieAtPoint(o,c){const x=(o-lt)/C,u=(it-c)/C,k=Math.max(We,Fe);for(const i of Oe(x,u,k)){const a=e.rectangles[i];if(a&&Math.abs(x-a.x)<=a.width/2&&Math.abs(u-a.y)<=a.height/2)return e.dies[i]??null}let p=null,h=qt*qt;for(const i of Oe(x,u,qt)){const a=ot[i].x-x,n=ot[i].y-u,s=a*a+n*n;s<h&&(h=s,p=e.dies[i]??null)}return p}},viewport:fo,binLegendRows:pe,legendBox:at}}function Io(f,e,F,g,l,P,q,m,Y,N,U,J,B,$){f.save(),f.font=Bo(),f.fillStyle=B.text,f.strokeStyle=B.axisLine,f.lineWidth=.5;const H=F-m+4,v=q+Y-4,Ht=po(U),_t=Ge(Ht,1,0),Gt=Ge(Ht,0,1),mt=1e-9;function Ct(y){return N?Math.abs(y.y)<mt&&Math.abs(y.x)>mt?{pitch:N.x,sign:Math.sign(y.x),axis:"x"}:Math.abs(y.x)<mt&&Math.abs(y.y)>mt?{pitch:N.y,sign:Math.sign(y.y),axis:"y"}:null:null}function Xt(y,rt){if(!$||!y)return null;const z=y.axis==="x"?$.columns:$.rows,bt=y.axis==="x"?$.columnBreaks:$.rowBreaks,Tt=y.axis==="x"?$.centreColumn:$.centreRow;return mo(z.length,bt,y.pitch*P,rt).map(St=>({mm:y.sign*(St-Tt)*y.pitch,label:String(z[St])}))}const nt=Ct(_t),ut=Ct(Gt);function G(y){return nt?Math.round(y*nt.sign/nt.pitch):y}function j(y){return ut?Math.round(y*ut.sign/ut.pitch):y}function Rt(y){if(!y)return Et(50/P);const rt=50/(y*P);return Math.max(1,Math.round(rt))*y}const It=nt?.pitch,Dt=ut?.pitch,ht=Rt(It),dt=Rt(Dt);f.textAlign="center",f.textBaseline="top";const Yt=Math.ceil((q-g)/P/ht)*ht,$t=(e-q-g)/P,gt=Xt(nt,36)??eo(Yt,$t,ht,y=>N?String(G(y)):Ve(y));for(const{mm:y,label:rt}of gt){const z=g+y*P;z<q||z>e-q||(f.beginPath(),f.moveTo(z,H-Ze),f.lineTo(z,H),f.stroke(),f.fillText(rt,z,H+2))}f.textAlign="right",f.textBaseline="middle";const wt=Math.ceil((l-(F-q))/P/dt)*dt,et=(l-q)/P,st=Xt(ut,16)??eo(wt,et,dt,y=>N?String(j(y)):Ve(y));for(const{mm:y,label:rt}of st){const z=l-y*P;z<q||z>F-q||(f.beginPath(),f.moveTo(v,z),f.lineTo(v+Ze,z),f.stroke(),f.fillText(rt,v-2,z))}f.restore()}function eo(f,e,F,g){const l=[];for(let P=f;P<=e;P+=F)l.push({mm:P,label:g(P)});return l}function Do(f,e,F,g,l,P,q){const m=[],Y=q;if(Y<1){const B=Et((e-f)*g/F);if(B>0){const $=Math.ceil(f/B)*B;for(let H=$;H<=e+B*1e-6;H+=B){if(H<=f||H>=e)continue;const v=(1-(Math.log10(H)-P)/q)*F;v>l&&v<F-l&&m.push(H)}}return m}const N=Y<3?[1,2,5]:[1],U=Math.floor(Math.log10(f)),J=Math.ceil(Math.log10(e));for(let B=U;B<=J;B++)for(const $ of N){const H=$*Math.pow(10,B);if(H<=f||H>=e)continue;const v=(1-(Math.log10(H)-P)/q)*F;v>l&&v<F-l&&m.push(H)}return m}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";export const PATH_SHAPES=256;const oo=new WeakMap;export function outlineSegments(f){const e=m=>Math.round(m*1e6),F=new Map,g=new Map,l=(m,Y,N,U)=>{const J=e(Y);let B=m.get(J);B||m.set(J,B={at:Y,spans:[]}),B.spans.push([N,U])};for(const m of f){const Y=m.x-m.width/2,N=m.x+m.width/2,U=m.y-m.height/2,J=m.y+m.height/2;l(F,U,Y,N),l(F,J,Y,N),l(g,Y,U,J),l(g,N,U,J)}const P=[],q=(m,Y)=>{for(const{at:N,spans:U}of m.values()){U.sort(($,H)=>$[0]-H[0]);let[J,B]=U[0];for(let $=1;$<U.length;$++){const[H,v]=U[$];e(H)<=e(B)?v>B&&(B=v):(Y(N,J,B),J=H,B=v)}Y(N,J,B)}};return q(F,(m,Y,N)=>P.push(Y,m,N,m)),q(g,(m,Y,N)=>P.push(m,Y,m,N)),Float64Array.from(P)}
1
+ import{fontPx as Xt}from"./toolbar.js";import{findTestDef as Xe,buildMapTitle as Ye}from"../renderer/buildView.js";import{niceStep as Yt,compactTickIndices as uo}from"../renderer/axisTicks.js";import{sortBinsForDisplay as po}from"../stats/binPareto.js";import{affineInvert as xo,affineVector as $e}from"../core/transforms.js";import{asList as Mo,compareNatural as bo,maxOf as se,minOf as we}from"../core/utils.js";import{resolveValueColorFn as yo}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as To}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ve,SPEC_FAIL_LOW as So,SPEC_FAIL_HIGH as Ke,contrastTextColor as ze}from"../renderer/colorMap.js";import{fmt as qe,fmtColorbarAxis as Ue}from"../renderer/fmt.js";import{resolveCanvasTheme as ko}from"./canvasTheme.js";import{hitGridDims as Lo}from"./hitGrid.js";const Ao=5,Je=4;function je(f,e,q,m,s){f.moveTo(e,q+s*m),f.lineTo(e-m*.9,q-s*m*.6),f.lineTo(e+m*.9,q-s*m*.6),f.closePath()}const _o=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),Co=new Set(["hardBin","softBin","metadata"]),ct=()=>`${Xt(-2)}px system-ui, sans-serif`,Ze=3,le=2,Ro=6,Po=20,Bo=()=>`600 ${Xt()}px system-ui, sans-serif`,Qe=36,Ae=()=>`${Xt(-1)}px system-ui, sans-serif`,ve=()=>`600 ${Xt(-1)}px system-ui, sans-serif`,ie=128,Do=()=>`${Xt(-2)}px system-ui, sans-serif`,to=4,z=17,Z=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_MAP_GAP=12;const eo=8;export const BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const ae=28,Tt=5,pt=8,oo=15,no=12,so=6;export function toCanvas(f,e,q={}){return drawMapCanvas(f,e,q)}export function drawMapCanvas(f,e,q={}){const m=ko(f.parentElement??f),{padding:s=16,showColorbar:D=!0,markFailingDies:rt=!1,colorbarWidth:d=16,background:Y=m.background,legendPosition:_="default",legendOffset:U,showAxes:H=!1,diePitchMm:W,viewport:et,activeBin:$,hoverBin:J,afterDies:Pt,fallbackFormat:dt,minRightReserve:Bt,hbinDefs:Dt,sbinDefs:It,metadataFields:St,showTitle:st=!0}=q,Nt=Mo($),R=Math.floor(f.clientWidth||f.width),G=Math.floor(f.clientHeight||f.height),Wt=R>=BIN_LEGEND_MIN_CANVAS_W&&G>=BIN_LEGEND_MIN_CANVAS_H,Et=D&&Wt&&_o.has(e.plotMode)&&e.passFailDisplay==="off",kt=D&&Wt&&Co.has(e.plotMode),xt=D&&Wt&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),Mt=kt||xt,Lt=kt&&e.plotMode!=="metadata"&&e.binCounts?po(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],At=kt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(bo)].map(o=>[o,e.metadataCounts.get(o)??0]):[],ht=[];if(xt&&e.passFailDisplay==="test"){const o=e.passFailCounts;ht.push({key:-1,color:Ve,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),ht.push({key:-2,color:Ke,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(xt){const o=e.specCounts,c=Xe(e.testDefs,e.activeTest);ht.push({key:-1,color:Ve,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),c?.limitHigh!==void 0&&ht.push({key:-2,color:Ke,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),c?.limitLow!==void 0&&ht.push({key:-3,color:So,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const $t=xt?ht.length:e.plotMode==="metadata"?At.length:Lt.length,v=(f.ownerDocument.defaultView??window).devicePixelRatio??1;if(R<=0||G<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const nt=_!=="default"?_:R<BIN_LEGEND_ADAPT_FLOATING?"floating":R<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",wt=nt==="default"||nt==="compact",Vt=nt==="left",b=nt==="bottom",ot=nt==="top",w=nt==="floating",_t=nt==="compact"||nt==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,Kt=Math.floor((G-2*s)/z),Ft=$t>Kt?Kt-1:$t,ce=Mt&&b?Ft*z+eo:0,zt=Mt&&ot?Ft*z+eo:0,re=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",fe=Xe(e.testDefs,e.activeTest),_e=re?"Count":fe?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Ce=re?void 0:fe?.unit,[Ot,Ht]=e.valueRange,he=o=>String(Math.round(o)),ao=e.logScale||e.allIntegerValues?void 0:Yt(Math.max(0,Ht-Ot)*Qe/Math.max(1,G))||void 0,de=e.allIntegerValues?he:Ue(Ht,_e,Ce,dt,ao).edgeFmt;let ge=0;if(Et){const o=f.getContext("2d");o.font=ct();const c=[de(Ot),de(Ht)];Ot<0&&c.push(de(-Math.max(Math.abs(Ot),Math.abs(Ht))));for(const x of c)ge=Math.max(ge,o.measureText(x).width)}const Re=Math.max(Po,Math.ceil(ge)+Ze+le+Ro-s),me=Et?d+Re+8:Mt&&wt?_t+BIN_LEGEND_MAP_GAP:0,qt=Mt&&Vt?_t+BIN_LEGEND_MAP_GAP:0,ue=H?32:0,Ut=H?36:0,Pe=Bt!=null?Math.max(me,Bt):me,co=R-2*s-Pe-Ut-qt,Be=G-2*s-ue-ce-zt;f.width=Math.round(R*v),f.height=Math.round(G*v);const t=f.getContext("2d");t.scale(v,v),t.fillStyle=Y,t.fillRect(0,0,R,G);const tt=e.hoverPoints;if(!tt.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Jt=e.rectangles[0],pe=Jt?Jt.width/2:0,xe=Jt?Jt.height/2:0,jt=e.dieBounds,Me=(jt?.minX??0)-pe,De=(jt?.maxX??0)+pe,Ie=(jt?.minY??0)-xe,be=(jt?.maxY??0)+xe,Ne=De-Me,We=be-Ie;let lt,it,P;if(et)({originX:lt,originY:it,ppm:P}=et);else{const c=e.notchDir,x=c&&c.y>.1?13:0,u=c&&c.y<-.1?13:0,k=c&&c.x<-.1?13:0,p=c&&c.x>.1?13:0,h=co-k-p,i=Be-x-u;P=Math.min(h/Ne,i/We),lt=s+Ut+qt+k+(h-Ne*P)/2-Me*P,it=s+zt+x+(i-We*P)/2+be*P}const Zt=et?.snapDist??Math.max(pe,xe,1)*1.5,Qt=lt+e.waferCenter.x*P,ro=it-e.waferCenter.y*P,ye=e.waferRadius*P,gt=o=>{const c=Math.abs(o-ro);return c>=ye?0:Math.sqrt(ye*ye-c*c)},bt=(o,c,x,u,k,p,h=Bo(),i=m.text)=>{if(!o)return;t.save(),t.fillStyle=i,t.font=h,t.textAlign=u,t.textBaseline=k;const a=u==="right"?c-p:p-c;let n=o;if(a>8&&t.measureText(n).width>a){for(;n.length>1&&t.measureText(n+"\u2026").width>a;)n=n.slice(0,-1);n=n+"\u2026"}a>8&&t.fillText(n,c,x),t.restore()};t.save(),t.setTransform(P*v,0,0,-P*v,lt*v,it*v);const mt=1/P;let vt=!1;const fo=1/(P*v),te=e.rectangles.length>0&&e.dieGap*P*v<1;if(e.rectangles.length>0){const o=new Map;for(const h of e.rectangles){const i=String(h.fill);let a=o.get(i);a||(a=[],o.set(i,a)),a.push(h)}const c=P*v,x=lt*v,u=it*v,k=e.dieGap/2;te&&(t.save(),t.setTransform(1,0,0,1,0,0));for(const[h,i]of o){t.fillStyle=h;for(let a=0;a<i.length;a+=PATH_SHAPES){t.beginPath();const n=Math.min(i.length,a+PATH_SHAPES);for(let l=a;l<n;l++){const g=i[l];if(te){const L=g.width/2+k,y=g.height/2+k,I=2*L*c>=Je?1:0,j=2*y*c>=Je?1:0,Q=Math.round(x+(g.x-L)*c),N=Math.max(Q+1,Math.round(x+(g.x+L)*c)-I),B=Math.round(u-(g.y+y)*c),yt=Math.max(B+1,Math.round(u-(g.y-y)*c)-j);t.rect(Q,B,N-Q,yt-B)}else t.rect(g.x-g.width/2,g.y-g.height/2,g.width,g.height)}t.fill()}}if(te&&t.restore(),!te){t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*fo,t.lineCap="square";const h=io.get(e.rectangles)??outlineSegments(e.rectangles);io.set(e.rectangles,h);const i=PATH_SHAPES*4;for(let a=0;a<h.length;a+=i){t.beginPath();const n=Math.min(h.length,a+i);for(let l=a;l<n;l+=4)t.moveTo(h[l],h[l+1]),t.lineTo(h[l+2],h[l+3]);t.stroke()}t.lineCap="butt"}if(rt){const h=e.rectangles.filter(i=>i.binFail);if(h.length>0){const i=new Map;for(const a of h){const n=ze(String(a.fill));let l=i.get(n);l||(l=[],i.set(n,l)),l.push(a)}t.save(),t.lineCap="butt";for(const[a,n]of i){t.strokeStyle=a,t.globalAlpha=.55,t.lineWidth=Math.max(.6*mt,Math.min(n[0].width,n[0].height)*.1);for(const l of n){const g=l.width/2,L=l.height/2,y=Math.max(1.6*mt,Math.min(l.width,l.height)/3);t.save(),t.beginPath(),t.rect(l.x-g,l.y-L,l.width,l.height),t.clip(),t.beginPath();for(let I=-(g+L);I<=g+L;I+=y)t.moveTo(l.x-g+I,l.y-L),t.lineTo(l.x-g+I+l.height,l.y+L);t.stroke(),t.restore()}}t.restore()}}const p=e.rectangles.filter(h=>h.specMark);if(vt=p.length>0&&Math.min(p[0].width,p[0].height)<Ao*mt,p.length>0&&!vt){const h=new Map;for(const a of p){const n=ze(String(a.fill)),l=`${a.specMark}|${n}`;let g=h.get(l);g||(g=[],h.set(l,g)),g.push(a)}const i=2.5*mt;t.lineJoin="round";for(const[a,n]of h){const[l,g]=a.split("|"),L=g==="#000000"?"#ffffff":"#000000",y=l==="failHigh"?1:-1,I=Math.min(n[0].width,n[0].height),j=Math.max(2.5*mt,I*.3);t.beginPath();for(const Q of n)je(t,Q.x,Q.y,j,y);t.strokeStyle=L,t.lineWidth=i,t.stroke(),t.fillStyle=g,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const c of o.points){for(let x=0;x<c.length;x++)x===0?t.moveTo(c[x].x,c[x].y):t.lineTo(c[x].x,c[x].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*mt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*mt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*mt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*P,c=it-e.waferCenter.y*P,x=e.notchDir.x,u=-e.notchDir.y,k=e.waferRadius*P,p=4,h=9,i=5,a=o+x*(k+p),n=c+u*(k+p),l=a+x*h,g=n+u*h,L={x:-u,y:x},y=s+Ut+qt,I=R-s-me,j=s+zt,Q=G-s-ce-ue;t.save(),t.beginPath(),t.rect(y,j,I-y,Q-j),t.clip(),t.beginPath(),t.moveTo(a,n),t.lineTo(l+L.x*i,g+L.y*i),t.lineTo(l-L.x*i,g-L.y*i),t.closePath(),t.fillStyle=m.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let Ee=0;if(e.rectangles.length>0){let o=1;for(const p of e.texts)p.role!=="indicator"&&p.text.length>o&&(o=p.text.length);const c=e.rectangles[0].width*P,x=e.rectangles[0].height*P,u=Math.min(c,x),k=c/o;Ee=Math.max(8,Math.min(64,Math.round(Math.min(u*.55,k*1.8))))}for(const o of e.texts){const c=lt+o.x*P,x=it-o.y*P;t.font=`${o.role==="indicator"?o.fontSize:Ee}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,c,x)}if(t.restore(),Pt?.(t,{originX:lt,originY:it,ppm:P},{background:Y,text:m.text}),H&&Io(t,R,G,lt,it,P,s,ue,Ut,{left:s+qt,right:R-s-Pe,top:s+zt,bottom:G-s-ce},{minX:Me,maxX:De,minY:Ie,maxY:be},W,e.gridToScreen,e.rotation,m,e.compact),Et){const o=yo(e.valueColorScheme,e.reverseValueScheme),c=Re,x=Be,u=Math.round(x*.75),k=s+Math.round((x-u)/2),p=R-s-d-c,h=Ot,i=Ht,a=i-h,n=e.plotMode==="stackedSoftBins"?It:Dt,{primary:l,secondary:g,note:L}=st?Ye(e,dt,n):{primary:"",secondary:"",note:void 0};if(st){const r=Math.max(k-6,s+11),O=Qt+Math.max(gt(r),gt(r-12))+8;bt(l,R-s,r,"right","bottom",O)}let y=k+u+4;const I=r=>Qt+Math.max(gt(r),gt(r+12))+8,j=e.logScale&&h>0?Math.log10(h):0,Q=e.logScale&&i>0?Math.log10(i)-j:1,N=r=>e.logScale?(1-(Math.log10(r)-j)/Q)*u:(1-(r-h)/a)*u;for(let r=0;r<ie;r++){const O=1-r/(ie-1),X=k+r/ie*u,M=u/ie+1;t.fillStyle=o(O),t.fillRect(p,X,d,M)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(p,k,d,u),t.fillStyle=m.text,t.font=ct(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const B=Ze,yt=Qe,ft=14;let V;const F=e.logScale&&Q>0?No(h,i,u,yt,ft,j,Q):e.allIntegerValues?(()=>{const r=Math.max(1,Yt(a*yt/u)),O=[],X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const E=(1-(M-h)/a)*u;E>ft&&E<u-ft&&O.push(Math.round(M))}return O})():(()=>{const r=a>0?Yt(a*yt/u):0,O=[];if(r>0){V=r;const X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const E=(1-(M-h)/a)*u;E>ft&&E<u-ft&&O.push(M)}}return O})(),T=fe,C=re,S=Ue(i,_e,Ce,dt,V),K=e.allIntegerValues?he:S.tickFmt,A=e.allIntegerValues?he:S.edgeFmt;t.textBaseline="middle";for(const r of F){const O=k+N(r);t.beginPath(),t.moveTo(p+d,O),t.lineTo(p+d+B,O),t.stroke(),t.fillText(K(r),p+d+B+le,O)}if(t.beginPath(),t.moveTo(p+d,k),t.lineTo(p+d+B,k),t.stroke(),t.textBaseline="top",t.fillText(A(i),p+d+B+le,k),t.beginPath(),t.moveTo(p+d,k+u),t.lineTo(p+d+B,k+u),t.stroke(),t.textBaseline="bottom",t.fillText(A(h),p+d+B+le,k+u),!C&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0)){const r=[],O=e.colorbarRangeMode==="spec";for(const[X,M]of[[T.limitLow,"Lo limit"],[T.limitHigh,"Hi limit"]]){if(X===void 0||e.logScale&&X<=0)continue;const E=N(X);!O&&(E<-ft||E>u+ft)||r.push({value:X,label:M,py:Math.max(0,Math.min(u,E))})}if(r.length>0){t.save(),t.font=ct(),t.textAlign="right",t.textBaseline="middle";for(const{py:X,label:M}of r){const E=k+X;if(O||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(p,E),t.lineTo(p+d,E),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(p,E),t.lineTo(p+d,E),t.stroke()),t.fillStyle=m.text,t.fillText(M,p-3,E),vt)continue;const Ct=M==="Hi limit"?-1:1,Rt=4,ne=p-3-t.measureText(M).width-Rt-4;t.beginPath(),je(t,ne,E,Rt,Ct),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=m.text,t.fill()}t.restore()}}if(!C){const r=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;r&&(t.save(),t.fillStyle=m.text,t.font=ve(),t.textAlign="right",t.textBaseline="top",t.fillText(r,R-s,y),t.restore(),y+=15)}vt&&(t.save(),t.fillStyle=m.text,t.font=ve(),t.textAlign="right",t.textBaseline="top",t.fillText("\u25BD\u25B3 limit marks: zoom in",R-s,y),t.restore(),y+=15),st&&g&&(bt(g,R-s,y,"right","top",I(y),Ae(),m.text),y+=15),st&&L&&bt(L,R-s,y,"right","top",I(y),Ae(),m.text)}const Te=[];let at;if(Mt){const o=nt==="compact",c=e.plotMode==="softBin"?It:Dt,x=c?new Map(c.map(n=>[n.bin,n])):null,u=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,k=n=>u.get(n)??To,p=(n,l)=>{const g=t.measureText(n).width,L=o?0:t.measureText(String(l)).width,y=Z+Tt+g+(L?ae:0);return{labelWidth:g,countWidth:L,totalWidth:y}},h=St?.find(n=>n.key===e.activeMetadataKey),i=xt?ht.map(n=>{const l=o?n.compactLabel:n.label;return{key:n.key,color:n.color,count:n.count,label:l,tooltipLabel:n.tooltip,...p(l,n.count)}}):e.plotMode==="metadata"?At.map(([n,l])=>{const L=h?.values?.find(j=>j.value===n)?.label??n,y=o?n:L,I=e.metadataColorMap?.get(n)??"#d6d9dd";return{key:n,color:I,count:l,label:y,tooltipLabel:`${L} \xB7 ${l} dies`,...p(y,l)}}):Lt.map(([n,l])=>{const g=x?.get(n),L=g?.name?`${n} \xB7 ${g.name}`:`Bin ${n}`,y=o?String(n):L;return{key:n,color:k(n),count:l,label:y,tooltipLabel:`${L} \xB7 ${l} dies`,...p(y,l)}}),a=R-s*2;if(i.length>0){const n=w?pt*2+(st?oo:0):st&&!ot?no+so:0,l=Math.max(1,Math.floor((G-2*s-n)/z));let g=i.length,L=1,y=g*z,I=[],j=0;const Q=b||ot;if(Q){const V=se(i.map(T=>T.totalWidth)),F=Math.max(1,Math.min(i.length,Math.floor((a+8)/(V+8))));for(let T=F;T>=1;T--){const C=Math.ceil(i.length/T);if(C>l)continue;const S=new Array(T).fill(0);for(let A=0;A<i.length;A++){const r=A%T;S[r]=Math.max(S[r],i[A].totalWidth)}if(S.reduce((A,r)=>A+r,0)+(T-1)*8<=a||T===1){L=T,I=S,g=C,y=C*z;break}}}else g=Math.min(i.length,l),y=g*z,i.length>l&&(j=i.length-(l-1)),I=[_t];let N,B;if(w){const V=se(i.map(r=>Z+Tt+t.measureText(r.label).width+ae)),F=Math.ceil(V);I=[F];const T=st?oo:0,C=F+pt*2,S=y+T+pt*2,K=U?.x??0,A=U?.y??0;N=Math.min(Math.max(R-s-C+K,s),R-s-C),B=Math.min(Math.max(G-s-S+A,s),G-s-S),at={x:N,y:B,w:C,h:S},t.save(),t.globalAlpha=.92,t.fillStyle=m.surface,t.fillRect(N,B,C,S),t.globalAlpha=1,t.strokeStyle=m.axisLine,t.lineWidth=1,t.strokeRect(N,B,C,S),t.restore(),N+=pt,B+=pt+T}else b?(N=s,B=G-s-y):ot?(N=s,B=s):Vt?(N=s,B=Math.max(s+Math.round((G-2*s-y)/2),s+n)):(N=R-s-_t+4,B=Math.max(s+Math.round((G-2*s-y)/2),s+n));if(st){const V=e.plotMode==="softBin"?It:Dt,{primary:F,secondary:T,note:C}=Ye(e,dt,V),S=so,K=[T,C].filter(M=>!!M),A=(M,E,Ct)=>K.forEach((Rt,ne)=>bt(Rt,M,E+ne*16,"left","top",Ct(E+ne*16),Ae(),m.text)),r=M=>Qt-Math.max(gt(M),gt(M-12))-8,O=M=>wt?R-s:r(M),X=w?at.y+at.h:B+y;if(ot){const M=X+S;bt(F,N,M,"left","top",Qt-Math.max(gt(M),gt(M+12))-8),A(N,M+16,r)}else if(w)bt(F,at.x+pt,at.y+pt,"left","top",at.x+at.w-pt),A(at.x,X+S,()=>at.x+at.w);else{const M=Math.max(B-S,s+no);bt(F,N,M,"left","bottom",O(M)),A(N,X+S,O)}}t.save(),t.font=ct();const yt=Q?8:0,ft=(V,F)=>{if(t.measureText(V).width<=F)return V;let T=0,C=V.length;const S="\u2026",K=t.measureText(S).width;for(;T<C;){const A=T+C+1>>1;t.measureText(V.slice(0,A)).width+K<=F?T=A:C=A-1}return T===0?S:V.slice(0,T)+S};if(Q){let V=0;for(let F=0;F<g;F++){let T=N;for(let C=0;C<L;C++){const S=i[V++];if(!S)break;const K=Nt.includes(S.key),A=!K&&S.key===J,r=T,O=T+Z+Tt,X=B+F*z+z/2,M=B+F*z+Math.round((z-Z)/2),E=I[C]-Z-Tt-ae;A&&(t.fillStyle=m.hoverRow,t.fillRect(T,B+F*z,I[C],z)),t.fillStyle=S.color,t.fillRect(r,M,Z,Z),t.strokeStyle=K?m.accent:"rgba(0,0,0,0.25)",t.lineWidth=K?2:.75,t.strokeRect(r,M,Z,Z),t.fillStyle=K?m.accent:m.text,t.font=K?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(S.label,E),O,X),t.fillStyle=m.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(S.count),T+I[C]-2,X),Te.push({bin:S.key,x:T,y:B+F*z,w:I[C],h:z,label:S.tooltipLabel}),T+=I[C]+yt}}}else{const V=I[0],F=nt!=="compact",T=V-Z-Tt-(F?ae:0),C=N+V-2;let S=i;j>0&&(S=i.slice(0,l-1));let K=B;for(const A of S){const r=Nt.includes(A.key),O=!r&&A.key===J,X=N,M=N+Z+Tt,E=K+z/2,Ct=K+Math.round((z-Z)/2),Rt=A.label;O&&(t.fillStyle=m.hoverRow,t.fillRect(N-3,K,V+3,z)),t.fillStyle=A.color,t.fillRect(X,Ct,Z,Z),t.strokeStyle=r?m.accent:"rgba(0,0,0,0.25)",t.lineWidth=r?2:.75,t.strokeRect(X,Ct,Z,Z),t.fillStyle=r?m.accent:m.text,t.font=r?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(Rt,T),M,E),(F||w)&&(t.fillStyle=m.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(A.count),C,E)),Te.push({bin:A.key,x:N,y:K,w:V,h:z,label:A.tooltipLabel}),K+=z}j>0&&(t.fillStyle=m.textMuted,t.font=ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${j} more`,N+Z+Tt,K+z/2))}}i.length>0&&t.restore()}const ho={originX:lt,originY:it,ppm:P,snapDist:Zt},Fe=e.rectangles[0]?.width??1,Oe=e.rectangles[0]?.height??1,ut=e.dieBounds,ee=ut?ut.minX:tt.length?we(tt.map(o=>o.x)):0,oe=ut?ut.minY:tt.length?we(tt.map(o=>o.y)):0,go=ut?ut.maxX:tt.length?se(tt.map(o=>o.x)):1,mo=ut?ut.maxY:tt.length?se(tt.map(o=>o.y)):1,{cellW:Se,cellH:ke,nCols:Gt,nRows:Le}=Lo(go-ee,mo-oe,Fe*1.5,Oe*1.5,tt.length),He=Array.from({length:Gt*Le},()=>[]);for(let o=0;o<tt.length;o++){const c=Math.floor((tt[o].x-ee)/Se),x=Math.floor((tt[o].y-oe)/ke),u=Number.isFinite(c)?Math.max(0,Math.min(Gt-1,c)):0,k=Number.isFinite(x)?Math.max(0,Math.min(Le-1,x)):0;He[k*Gt+u].push(o)}function Ge(o,c,x){const u=Math.max(0,Math.floor((o-x-ee)/Se)),k=Math.min(Gt-1,Math.floor((o+x-ee)/Se)),p=Math.max(0,Math.floor((c-x-oe)/ke)),h=Math.min(Le-1,Math.floor((c+x-oe)/ke)),i=[];for(let a=p;a<=h;a++)for(let n=u;n<=k;n++)for(const l of He[a*Gt+n])i.push(l);return i}return{hitTarget:{getDieAtPoint(o,c){const x=(o-lt)/P,u=(it-c)/P,k=Math.max(Fe,Oe);for(const i of Ge(x,u,k)){const a=e.rectangles[i];if(a&&Math.abs(x-a.x)<=a.width/2&&Math.abs(u-a.y)<=a.height/2)return e.dies[i]??null}let p=null,h=Zt*Zt;for(const i of Ge(x,u,Zt)){const a=tt[i].x-x,n=tt[i].y-u,l=a*a+n*n;l<h&&(h=l,p=e.dies[i]??null)}return p}},viewport:ho,binLegendRows:Te,legendBox:at}}function Io(f,e,q,m,s,D,rt,d,Y,_,U,H,W,et,$,J){f.save(),f.font=Do(),f.fillStyle=$.text,f.strokeStyle=$.axisLine,f.lineWidth=.5;const Pt=_.bottom-d+rt+4,dt=_.left+Y-4,Bt=xo(W),Dt=$e(Bt,1,0),It=$e(Bt,0,1),St=1e-9;function st(b){return H?Math.abs(b.y)<St&&Math.abs(b.x)>St?{pitch:H.x,sign:Math.sign(b.x),axis:"x"}:Math.abs(b.x)<St&&Math.abs(b.y)>St?{pitch:H.y,sign:Math.sign(b.y),axis:"y"}:null:null}function Nt(b,ot){if(!J||!b)return null;const w=b.axis==="x"?J.columns:J.rows,_t=b.axis==="x"?J.columnBreaks:J.rowBreaks,Kt=b.axis==="x"?J.centreColumn:J.centreRow;return uo(w.length,_t,b.pitch*D,ot).map(Ft=>({mm:b.sign*(Ft-Kt)*b.pitch,label:String(w[Ft])}))}const R=st(Dt),G=st(It);function Wt(b){return R?Math.round(b*R.sign/R.pitch):b}function Et(b){return G?Math.round(b*G.sign/G.pitch):b}function kt(b){if(!b)return Yt(50/D);const ot=50/(b*D);return Math.max(1,Math.round(ot))*b}const xt=R?.pitch,Mt=G?.pitch,Lt=kt(xt),At=kt(Mt);f.textAlign="center",f.textBaseline="top";const ht=Math.ceil(Math.max((_.left-m)/D,U.minX)/Lt)*Lt,$t=Math.min((_.right-m)/D,U.maxX),v=Nt(R,36)??lo(ht,$t,Lt,b=>H?String(Wt(b)):qe(b));for(const{mm:b,label:ot}of v){const w=m+b*D;w<_.left||w>_.right||(f.beginPath(),f.moveTo(w,Pt-to),f.lineTo(w,Pt),f.stroke(),f.fillText(ot,w,Pt+2))}f.textAlign="right",f.textBaseline="middle";const nt=Math.ceil(Math.max((s-(_.bottom-d))/D,U.minY)/At)*At,wt=Math.min((s-_.top)/D,U.maxY),Vt=Nt(G,16)??lo(nt,wt,At,b=>H?String(Et(b)):qe(b));for(const{mm:b,label:ot}of Vt){const w=s-b*D;w<_.top||w>_.bottom-d||(f.beginPath(),f.moveTo(dt,w),f.lineTo(dt+to,w),f.stroke(),f.fillText(ot,dt-2,w))}f.restore()}function lo(f,e,q,m){const s=[];for(let D=f;D<=e;D+=q)s.push({mm:D,label:m(D)});return s}function No(f,e,q,m,s,D,rt){const d=[],Y=rt;if(Y<1){const W=Yt((e-f)*m/q);if(W>0){const et=Math.ceil(f/W)*W;for(let $=et;$<=e+W*1e-6;$+=W){if($<=f||$>=e)continue;const J=(1-(Math.log10($)-D)/rt)*q;J>s&&J<q-s&&d.push($)}}return d}const _=Y<3?[1,2,5]:[1],U=Math.floor(Math.log10(f)),H=Math.ceil(Math.log10(e));for(let W=U;W<=H;W++)for(const et of _){const $=et*Math.pow(10,W);if($<=f||$>=e)continue;const J=(1-(Math.log10($)-D)/rt)*q;J>s&&J<q-s&&d.push($)}return d}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";export const PATH_SHAPES=256;const io=new WeakMap;export function outlineSegments(f){const e=d=>Math.round(d*1e6),q=new Map,m=new Map,s=(d,Y,_,U)=>{const H=e(Y);let W=d.get(H);W||d.set(H,W={at:Y,spans:[]}),W.spans.push([_,U])};for(const d of f){const Y=d.x-d.width/2,_=d.x+d.width/2,U=d.y-d.height/2,H=d.y+d.height/2;s(q,U,Y,_),s(q,H,Y,_),s(m,Y,U,H),s(m,_,U,H)}const D=[],rt=(d,Y)=>{for(const{at:_,spans:U}of d.values()){U.sort((et,$)=>et[0]-$[0]);let[H,W]=U[0];for(let et=1;et<U.length;et++){const[$,J]=U[et];e($)<=e(W)?J>W&&(W=J):(Y(_,H,W),H=$,W=J)}Y(_,H,W)}};return rt(q,(d,Y,_)=>D.push(Y,d,_,d)),rt(m,(d,Y,_)=>D.push(d,Y,d,_)),Float64Array.from(D)}