@wafertools/wafermap 0.34.0 → 0.35.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 (64) hide show
  1. package/CHANGELOG.md +60 -1
  2. package/README.md +2 -2
  3. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +1 -1
  4. package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +17 -2
  7. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +6 -1
  11. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  13. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  14. package/dist/packages/canvas-adapter/dataTab.d.ts +6 -0
  15. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  16. package/dist/packages/canvas-adapter/dieList.js +6 -6
  17. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  18. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  19. package/dist/packages/canvas-adapter/identityHeader.d.ts +4 -1
  20. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  21. package/dist/packages/canvas-adapter/insightsTab.d.ts +3 -1
  22. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  23. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  24. package/dist/packages/canvas-adapter/plotTab.d.ts +3 -0
  25. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  26. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +8 -0
  27. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  28. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +8 -0
  29. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  30. package/dist/packages/canvas-adapter/summaryPanel.d.ts +8 -3
  31. package/dist/packages/canvas-adapter/summaryPanel.js +2 -2
  32. package/dist/packages/canvas-adapter/sweepEditor.js +1 -1
  33. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  34. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  35. package/dist/packages/canvas-adapter/userGuideHtml.js +21 -7
  36. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  37. package/dist/packages/canvas-adapter/version.js +1 -1
  38. package/dist/packages/core/index.d.ts +1 -1
  39. package/dist/packages/core/index.js +1 -1
  40. package/dist/packages/core/reticle.d.ts +20 -0
  41. package/dist/packages/core/reticle.js +1 -1
  42. package/dist/packages/core/wafer.d.ts +15 -0
  43. package/dist/packages/core/wafer.js +1 -1
  44. package/dist/packages/renderer/buildWaferMap.js +1 -1
  45. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  46. package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
  47. package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
  48. package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
  49. package/dist/packages/renderer/derivedTests/parser.js +2 -2
  50. package/dist/packages/stats/dieRegions.d.ts +42 -0
  51. package/dist/packages/stats/dieRegions.js +1 -0
  52. package/dist/packages/stats/facets.d.ts +8 -0
  53. package/dist/packages/stats/facets.js +1 -1
  54. package/dist/packages/stats/index.d.ts +2 -1
  55. package/dist/packages/stats/index.js +1 -1
  56. package/dist/packages/stats/metadataColumns.js +1 -1
  57. package/dist/packages/stats/plotData.d.ts +1 -1
  58. package/dist/packages/stats/plotData.js +1 -1
  59. package/dist/packages/stats/plotSpec.d.ts +1 -1
  60. package/dist/packages/stats/plotSpec.js +1 -1
  61. package/dist/packages/stats/regions.d.ts +9 -0
  62. package/dist/packages/stats/regions.js +1 -1
  63. package/dist/packages/stats/reportHtml.js +1 -1
  64. package/package.json +1 -1
@@ -1 +1 @@
1
- import{parseRegionKey as T}from"../../stats/regions.js";import{yieldFill as q}from"./palette.js";import{fontPx as v}from"../toolbar.js";import{cardShell as $,resolveChartCanvasColors as j,observeResize as z,growCardToFitContent as G,setChartGrow as L,isExpandedCard as O,bodyRoom as Y,renderEmptyState as _,prepareCanvas as B}from"./chartShell.js";const w=320,Q=220,E={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function X(e,a,n,h,f,o){e.beginPath(),e.moveTo(a+o,n),e.arcTo(a+h,n,a+h,n+f,o),e.arcTo(a+h,n+f,a,n+f,o),e.arcTo(a,n+f,a,n,o),e.arcTo(a,n,a+h,n,o),e.closePath()}function W(e,a,n,h,f,o){e.font=`${v(-1)}px system-ui, sans-serif`;const u=e.measureText(h).width;e.font="700 11px system-ui, sans-serif";const p=e.measureText(f).width,c=Math.max(u,p)+12,y=30;e.fillStyle=o.bg,X(e,a-c/2,n-y/2,c,y,4),e.fill(),e.strokeStyle=o.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=o.textMuted,e.font=`${v(-1)}px system-ui, sans-serif`,e.fillText(h,a,n-7),e.fillStyle=o.text,e.font="700 11px system-ui, sans-serif",e.fillText(f,a,n+7)}export function renderRegionYieldDiagram(e){const{mode:a,rows:n,onSaveImage:h}=e,f=e.title??(a==="ring"?"Ring yield":"Quadrant yield"),{card:o,body:u}=$(f,h,e.ownerDocument);L(o,"square");const p=n.length>0;if(!p)return _(u,"No bin data available for regional yield."),{card:o,hasData:p,destroy:()=>{}};Object.assign(u.style,{display:"flex",justifyContent:"center",alignItems:"center"});const c=o.ownerDocument.createElement("canvas");Object.assign(c.style,{display:"block",flex:"none"}),u.appendChild(c);let y={cx:0,cy:0,R:0};function C(){const g=Math.max(Q,Math.min(u.clientWidth||w,w));G(o,u,g);const d=O(o)?Math.max(g,Math.floor(Math.min(u.clientWidth,Y(o,u,c)))):g,P=B(c,o,d,d);if(!P)return;const{ctx:t}=P,m=j(o),S=q,s=d/2,i=d/2,M=d/2-34;if(y={cx:s,cy:i,R:M},a==="ring"){const l=n.length;for(let r=0;r<l;r++){const b=r/l*M,I=(r+1)/l*M;t.beginPath(),t.arc(s,i,I,0,2*Math.PI),t.arc(s,i,b,0,2*Math.PI,!0),t.closePath(),t.fillStyle=S(n[r].yieldPercent),t.fill(),t.strokeStyle=m.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(s,i,M,0,2*Math.PI),t.strokeStyle=m.text,t.lineWidth=1.5,t.stroke();for(let r=0;r<l;r++){const b=(r+.5)/l*M,I=-Math.PI/2+r/l*2*Math.PI,R=s+Math.cos(I)*b,k=i+Math.sin(I)*b;W(t,R,k,n[r].label,`${n[r].yieldPercent.toFixed(1)}%`,m)}}else{for(const l of n){const r=T(l.key).quadrant,b=r?E[r]:void 0;if(!b)continue;const[I,R]=b;t.beginPath(),t.moveTo(s,i),t.arc(s,i,M,I,R),t.closePath(),t.fillStyle=S(l.yieldPercent),t.fill(),t.strokeStyle=m.border,t.lineWidth=1,t.stroke();const k=(I+R)/2,N=s+Math.cos(k)*M*.6,F=i+Math.sin(k)*M*.6;W(t,N,F,l.label,`${l.yieldPercent.toFixed(1)}%`,m)}t.beginPath(),t.arc(s,i,M,0,2*Math.PI),t.strokeStyle=m.text,t.lineWidth=1.5,t.stroke()}}function A(g,d){const P=g-y.cx,t=d-y.cy,m=Math.hypot(P,t);if(!(m<=y.R))return null;if(a==="ring")return n[Math.min(n.length-1,Math.floor(m/y.R*n.length))]??null;const S=(Math.atan2(t,P)+2*Math.PI)%(2*Math.PI);return n.find(s=>{const i=E[T(s.key).quadrant??""];return!!i&&S>=i[0]&&S<i[1]})??null}e.onSelectRegion&&(c.style.cursor="pointer",c.addEventListener("click",g=>{const d=c.getBoundingClientRect(),P=A(g.clientX-d.left,g.clientY-d.top);P&&e.onSelectRegion(P,g)}));const D=z(o,()=>C());return C(),{card:o,hasData:p,destroy:()=>D.disconnect()}}
1
+ import{parseRegionKey as D,parseReticleCellKey as G}from"../../stats/regions.js";import{yieldFill as H}from"./palette.js";import{fontPx as L}from"../toolbar.js";import{escHtml as _}from"../../core/utils.js";import{makeTooltip as K,positionChartTooltip as Q,cardShell as Z,resolveChartCanvasColors as U,observeResize as z,growCardToFitContent as J,setChartGrow as V,isExpandedCard as x,bodyRoom as ee,renderEmptyState as te,prepareCanvas as ne}from"./chartShell.js";const N=320,oe=220,q={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function Y(e,r,o,m,M,l){e.beginPath(),e.moveTo(r+l,o),e.arcTo(r+m,o,r+m,o+M,l),e.arcTo(r+m,o+M,r,o+M,l),e.arcTo(r,o+M,r,o,l),e.arcTo(r,o,r+m,o,l),e.closePath()}function W(e,r,o,m,M,l){e.font=`${L(-1)}px system-ui, sans-serif`;const b=e.measureText(m).width;e.font="700 11px system-ui, sans-serif";const C=e.measureText(M).width,y=Math.max(b,C)+12,w=30;e.fillStyle=l.bg,Y(e,r-y/2,o-w/2,y,w,4),e.fill(),e.strokeStyle=l.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=l.textMuted,e.font=`${L(-1)}px system-ui, sans-serif`,e.fillText(m,r,o-7),e.fillStyle=l.text,e.font="700 11px system-ui, sans-serif",e.fillText(M,r,o+7)}function le(e,r,o,m,M){e.font="700 11px system-ui, sans-serif";const l=e.measureText(m).width+8;e.fillStyle=M.bg,Y(e,r-l/2,o-8,l,16,3),e.fill(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=M.text,e.fillText(m,r,o+.5)}export function renderRegionYieldDiagram(e){const{mode:r,rows:o,onSaveImage:m}=e,M=e.title??(r==="ring"?"Ring yield":r==="quadrant"?"Quadrant yield":"Reticle cell yield"),{card:l,body:b}=Z(M,m,e.ownerDocument);V(l,"square");const C=o.length>0;if(!C)return te(b,"No bin data available for regional yield."),{card:l,hasData:C,destroy:()=>{}};Object.assign(b.style,{display:"flex",justifyContent:"center",alignItems:"center"});const y=l.ownerDocument.createElement("canvas");Object.assign(y.style,{display:"block",flex:"none"}),b.appendChild(y);let w={cx:0,cy:0,R:0};const E=new Map;let S=0,P=0;if(r==="reticleCell"){for(const n of o){const i=G(n.key);i&&(E.set(`${i.column},${i.row}`,n),S=Math.max(S,i.column+1),P=Math.max(P,i.row+1))}S=Math.max(S,e.grid?.width??0),P=Math.max(P,e.grid?.height??0)}let k={x0:0,y0:0,side:0};const T=K(l);function B(n,i,c,t){const s=Math.max(4,Math.floor(Math.min((i-40)/S,(i-40)/P))),f=Math.round((i-s*S)/2),a=Math.round((i-s*P)/2);k={x0:f,y0:a,side:s};for(let I=0;I<P;I++)for(let u=0;u<S;u++){const h=f+u*s,d=a+(P-1-I)*s,g=E.get(`${u},${I}`);n.fillStyle=g?t(g.yieldPercent):c.bg,n.fillRect(h,d,s,s),n.strokeStyle=c.border,n.lineWidth=1,n.strokeRect(h+.5,d+.5,s-1,s-1),!(!g||s<30)&&(s>=54?W(n,h+s/2,d+s/2,`(${u}, ${I})`,`${g.yieldPercent.toFixed(1)}%`,c):le(n,h+s/2,d+s/2,`${g.yieldPercent.toFixed(0)}%`,c))}n.strokeStyle=c.text,n.lineWidth=1.5,n.strokeRect(f+.5,a+.5,s*S-1,s*P-1)}function F(){const n=Math.max(oe,Math.min(b.clientWidth||N,N));J(l,b,n);const i=x(l)?Math.max(n,Math.floor(Math.min(b.clientWidth,ee(l,b,y)))):n,c=ne(y,l,i,i);if(!c)return;const{ctx:t}=c,p=U(l),s=H;if(r==="reticleCell"){B(t,i,p,s);return}const f=i/2,a=i/2,u=i/2-34;if(w={cx:f,cy:a,R:u},r==="ring"){const h=o.length;for(let d=0;d<h;d++){const g=d/h*u,R=(d+1)/h*u;t.beginPath(),t.arc(f,a,R,0,2*Math.PI),t.arc(f,a,g,0,2*Math.PI,!0),t.closePath(),t.fillStyle=s(o[d].yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke();for(let d=0;d<h;d++){const g=(d+.5)/h*u,R=-Math.PI/2+d/h*2*Math.PI,$=f+Math.cos(R)*g,v=a+Math.sin(R)*g;W(t,$,v,o[d].label,`${o[d].yieldPercent.toFixed(1)}%`,p)}}else{for(const h of o){const d=D(h.key).quadrant,g=d?q[d]:void 0;if(!g)continue;const[R,$]=g;t.beginPath(),t.moveTo(f,a),t.arc(f,a,u,R,$),t.closePath(),t.fillStyle=s(h.yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke();const v=(R+$)/2,X=f+Math.cos(v)*u*.6,j=a+Math.sin(v)*u*.6;W(t,X,j,h.label,`${h.yieldPercent.toFixed(1)}%`,p)}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke()}}function A(n,i){if(r==="reticleCell"){const f=Math.floor((n-k.x0)/k.side),a=Math.floor((i-k.y0)/k.side);return k.side<=0||f<0||f>=S||a<0||a>=P?null:E.get(`${f},${P-1-a}`)??null}const c=n-w.cx,t=i-w.cy,p=Math.hypot(c,t);if(!(p<=w.R))return null;if(r==="ring")return o[Math.min(o.length-1,Math.floor(p/w.R*o.length))]??null;const s=(Math.atan2(t,c)+2*Math.PI)%(2*Math.PI);return o.find(f=>{const a=q[D(f.key).quadrant??""];return!!a&&s>=a[0]&&s<a[1]})??null}y.addEventListener("mousemove",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);if(!c){T.style.display="none";return}T.innerHTML=`<strong>${_(c.label)}</strong><br>${c.yieldPercent.toFixed(1)}% yield (${c.passDies} of ${c.n} dies)`+(e.onSelectRegion?"<br><em>click to chart or tabulate these dies</em>":""),T.style.display="block",Q(T,l,n.clientX,n.clientY)}),y.addEventListener("mouseleave",()=>{T.style.display="none"}),e.onSelectRegion&&(y.style.cursor="pointer",y.addEventListener("click",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);c&&e.onSelectRegion(c,n)}));const O=z(l,()=>F());return F(),{card:l,hasData:C,destroy:()=>O.disconnect()}}
@@ -1 +1 @@
1
- import{NO_DATA_FILL as Ne}from"../../renderer/colorMap.js";import{escHtml as Z,maxOf as se,minOf as Re}from"../../core/utils.js";import{fmt as He}from"../../renderer/fmt.js";import{categorical as st}from"./palette.js";import{buildScatterData as lt,buildScatterDataGrouped as at}from"../../stats/scatter.js";import{pearsonOfPairs as rt}from"../../stats/correlation.js";import{buildFacetTable as ct}from"../../stats/facets.js";import{SPACE as D,RADIUS as dt,fontPx as z,FONT as ge,CLR as ee}from"../toolbar.js";import{fitTicks as Fe}from"../../renderer/axisTicks.js";import{wirePointInteractions as ft}from"./pointInteractions.js";import{cardShell as mt,observeResize as ut,makeTooltip as pt,attachChartTip as xt,makeTestSelect as ht,makeWaferSelect as bt,chartFillHeight as gt,applyCanvasFlow as yt,drawAxisUnit as wt,resolveChartCanvasColors as St,makeAxisFormat as le,horizontalTickSpacing as Tt,VERTICAL_TICK_SPACING_PX as kt,makeSeriesLegendItem as Mt,prepareCanvas as vt,drawOffAxisLimits as _e,limitLines as Lt,hasBothLimitKinds as Ct,makeLimitsSelect as Ot,stackLabelRows as je,strokeLimitLine as Ge,fillTextOnHalo as Xe}from"./chartShell.js";const u=52,At=16,c=16,Pt=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(x){return x===void 0?NO_BIN_CATEGORY:String(x)}export function binCategories(x){const te=new Set;let k=!1;for(const N of x)N.hbin===void 0?k=!0:te.add(N.hbin);const L=Array.from(te).sort((N,ae)=>N-ae).map(String);return k&&L.push(NO_BIN_CATEGORY),L}export function renderScatterPanel(x){const{title:te="Test scatter",items:k,testDefs:L,binColors:N,onSaveImage:ae,groups:_}=x,{card:l,body:R,controlsRow:re}=mt(te,ae,x.ownerDocument),ne=L.filter(e=>e.testNumber!==void 0),C=!!(_&&_.length>0),ye=(_??[]).map(e=>e.key),Ye=new Map(ye.map((e,n)=>[e,n]));let f=x.xTestNumber??ne[0]?.testNumber??null,w=x.yTestNumber??ne[1]?.testNumber??f,j=null;const we=()=>j!==null?k[j]?[k[j]]:[]:k;function Se(e,n,o){const a=l.ownerDocument.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:D.xs,fontSize:ge.body,color:ee.label});const g=l.ownerDocument.createElement("span");g.textContent=e;const r=ht(ne,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:l.ownerDocument});return a.append(g,r),{wrap:a,select:r}}const{wrap:Ue,select:Ke}=Se("X:",f,e=>{f=e,K()}),{wrap:Ve,select:qe}=Se("Y:",w,e=>{w=e,K()});re.append(Ue,Ve);let O=x.axisPrefs??{clipOutliers:!1};const Te=l.ownerDocument.createElement("span");re.appendChild(Te);function ke(){const e=[f,w].map(n=>L.find(o=>o.testNumber===n));Te.replaceChildren(...e.some(Ct)?[Ot(O.limits??"both",n=>{O={...O,limits:n},x.onAxisPrefsChange?.(O),v()},l.ownerDocument)]:[])}!C&&k.length>1&&re.appendChild(bt(k,j,e=>{j=e,K()},{ownerDocument:l.ownerDocument}));const H=l.ownerDocument.createElement("div");H.dataset.wmapCaption="1",Object.assign(H.style,{color:ee.warnText,background:ee.warnBg,border:`1px solid ${ee.warnBorder}`,borderRadius:dt.control,padding:`${D.xs} ${D.md}`,fontSize:ge.body,marginBottom:D.xs,display:"none"}),l.insertBefore(H,R);function Me(){const e=C?[]:ct(we(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(H.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,H.style.display=""):H.style.display="none"}Me();const oe=l.ownerDocument.createElement("div");oe.dataset.wmapCaption="1",Object.assign(oe.style,{color:ee.label,fontSize:ge.body,marginBottom:D.xs}),l.insertBefore(oe,R);function G(){const e=(C?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter")+(fe?` \xB7 click a point to ${Ce}`:"")+(de?M.size>0?` \xB7 ${M.size.toLocaleString()} selected (click empty space to clear)`:" \xB7 drag to select dies":""),n=h.size===0?b:b.filter(g=>h.has(B(g))),{r:o,n:a}=rt(n);oe.textContent=o===null?`${e} \xB7 n = ${a.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${a.toLocaleString()}`}const B=e=>C?e.group??"\u2014":binCategoryOf(e.hbin),ve=e=>C?st(Ye.get(e)??0):e===NO_BIN_CATEGORY?Ne:N?.get(Number(e))??Ne,ce=e=>C?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,h=new Set,X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:D.sm,marginTop:D.md,marginBottom:D.xl}),R.appendChild(X);const A=l.ownerDocument.createElement("canvas");A.style.display="block",A.style.cursor="crosshair",R.appendChild(A);const Le=pt(l);let b=[],y=0,P=1,S=0,E=1,Y=[],ie=null;const M=new Set,de=x.onSelect,fe=x.onOpen,Ce=x.openActionLabel??"open this wafer",Oe=new Map;for(const e of[...k,...(_??[]).flatMap(n=>n.items)])e.waferIndex!==void 0&&e.label&&Oe.set(e.waferIndex,e.label);function U(e){const n=L.find(o=>o.testNumber===e);return{unit:n?.unit,lines:Lt(n,O.limits)}}function Ae(){const e=R.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=gt(l,R,A,n);return{w:e,h:o,plotW:Math.max(10,e-u-At),plotH:Math.max(10,o-c-Pt)}}const me=new Map;function Pe(){for(const[e,n]of me){const o=h.has(e);n.setState({selected:o,dimmed:h.size>0&&!o})}}function $e(e){X.innerHTML="",me.clear(),h.clear();for(const n of e){const o=Mt(ce(n),ve(n),l.ownerDocument),a=o.el;a.dataset.cat=n,me.set(n,o),xt(a,l,Le,`${ce(n)} \u2014 click to filter`),a.addEventListener("click",()=>{h.has(n)?h.delete(n):h.add(n),Pe(),G(),v()}),X.appendChild(a)}Pe()}function v(){yt(A,X);const e=St(l),n=P-y,o=E-S,{w:a,h:g,plotW:r,plotH:s}=Ae(),W=vt(A,l,a,g);if(!W)return;const{ctx:t}=W;if(b.length===0){Y=[],t.font=`${z()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",a/2,g/2);return}t.font=`${z(-1)}px system-ui, sans-serif`;const T=f!==null?U(f).unit:void 0,V=Fe(y,P,r,Tt(t,Math.max(Math.abs(y),Math.abs(P)),T)),q=Fe(S,E,s,()=>kt),ue=le(Math.max(Math.abs(y),Math.abs(P)),f!==null?U(f).unit:void 0,V.step||void 0),pe=le(Math.max(Math.abs(S),Math.abs(E)),w!==null?U(w).unit:void 0,q.step||void 0);t.font=`${z(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of V.ticks){const d=u+(m-y)/n*r;t.beginPath(),t.moveTo(d,c),t.lineTo(d,c+s),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(ue.tick(m),d,c+s+4)}for(const m of q.ticks){const d=c+(1-(m-S)/o)*s;t.beginPath(),t.moveTo(u,d),t.lineTo(u+r,d),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(pe.tick(m),u-4,d)}ue.unitLabel&&wt(t,ue.unitLabel,u+r/2,c+s+24,e.textMuted),pe.unitLabel&&(t.save(),t.font=`${z(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,c+s/2),t.rotate(-Math.PI/2),t.fillText(`(${pe.unitLabel})`,0,0),t.restore());const J=h.size===0?b:b.filter(m=>h.has(B(m))),De=J.length>5e3?Math.ceil(J.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(J.length/De))),Y=[];for(let m=0;m<J.length;m+=De){const d=J[m],$=u+(d.x-y)/n*r,I=c+(1-(d.y-S)/o)*s;Y.push({p:d,cx:$,cy:I}),t.beginPath(),t.arc($,I,2.5,0,Math.PI*2),t.fillStyle=ve(B(d)),t.fill()}t.globalAlpha=1;const xe=ie?Y.find(m=>m.p===ie):void 0;if(xe&&(t.beginPath(),t.arc(xe.cx,xe.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),M.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let m=0;for(const d of M){if(h.size>0&&!h.has(B(d)))continue;if(++m>5e3)break;const $=u+(d.x-y)/n*r,I=c+(1-(d.y-S)/o)*s;t.beginPath(),t.arc($,I,4,0,Math.PI*2),t.stroke()}}if(f!==null&&w!==null){const m=U(f),d=U(w);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${z(-1)}px system-ui, sans-serif`,t.textBaseline="top";const $=z(-1)+2,I=m.lines.filter(i=>i.value>=y&&i.value<=P).map(i=>{const p=u+(i.value-y)/n*r;return{l:i,cx:p,start:p+2,end:p+2+t.measureText(i.label).width}}),Be=je(I);I.forEach(({l:i,cx:p},Q)=>{Ge(t,i,e.limitLine,p,c,p,c+s),t.textAlign="left",Xe(t,i.label,p+2,c+2+Be[Q]*$,e.bg)});const he=d.lines.filter(i=>i.value>=S&&i.value<=E).map(i=>{const p=c+(1-(i.value-S)/o)*s;return{l:i,cy:p,start:p+2,end:p+2+z(-1)}}),nt=je(he,1),ot=se(he.map(i=>t.measureText(i.l.label).width))+8;he.forEach(({l:i,cy:p},Q)=>{Ge(t,i,e.limitLine,u,p,u+r,p),t.textAlign="left",Xe(t,i.label,u+3+nt[Q]*ot,p+2,e.bg)});const Ee=(i,p,Q)=>i.filter(F=>F.value<p||F.value>Q).map(F=>({value:F.value,label:F.label,side:F.value<p?"lo":"hi"})),We={left:u,right:u+r,top:c,bottom:c+s},be=Ee(m.lines,y,P),ze=c+(I.length?(se(Be)+1)*$:0),it=Math.max(be.filter(i=>i.side==="lo").length,be.filter(i=>i.side==="hi").length);_e(t,be,{...We,top:ze},"horizontal",e.limitLine,i=>le(Math.abs(i),m.unit).tick(i),e.bg),_e(t,Ee(d.lines,S,E),{...We,top:ze+it*$},"vertical",e.limitLine,i=>le(Math.abs(i),d.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(u,c),t.lineTo(u,c+s),t.moveTo(u,c+s),t.lineTo(u+r,c+s),t.stroke()}function K(){if(ie=null,M.clear(),Me(),ke(),ne.length<2||f===null||w===null){b=[],$e([]),G(),v();return}b=C?at(_,f,w):lt(we(),f,w);let e;if(C){const n=new Set(b.map(B));e=ye.filter(o=>n.has(o))}else e=binCategories(b);if($e(e),G(),b.length>0){const n=b.map(T=>T.x),o=b.map(T=>T.y),a=Re(n),g=se(n),r=Re(o),s=se(o),W=(g-a)*.05||1,t=(s-r)*.05||1;y=a-W,P=g+W,S=r-t,E=s+t}v()}const Ie=e=>!!fe&&e.waferIndex!==void 0;function Je(e){const n=L.find(s=>s.testNumber===f),o=L.find(s=>s.testNumber===w),a=e.waferIndex!==void 0?Oe.get(e.waferIndex):void 0,g=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,g].filter(Boolean).join(" \xB7 ");return(r?`<strong>${Z(r)}</strong><br>`:"")+Z(`${n?.name??"X"}: ${He(e.x,n?.unit)}`)+"<br>"+Z(`${o?.name??"Y"}: ${He(e.y,o?.unit)}`)+"<br>"+Z(ce(B(e)))+(Ie(e)?`<br><em>click to ${Z(Ce)}</em>`:"")}const Qe=ft({card:l,canvas:A,tooltip:Le,drawn:()=>Y,describe:Je,clickable:Ie,onOpen:e=>{f!==null&&fe(e.waferIndex,f)},onHover:e=>{ie=e,v()},select:de?{pick:({x0:e,y0:n,x1:o,y1:a})=>{const{plotW:g,plotH:r}=Ae(),s=P-y,W=E-S;return(h.size===0?b:b.filter(T=>h.has(B(T)))).filter(T=>{const V=u+(T.x-y)/s*g,q=c+(1-(T.y-S)/W)*r;return V>=e&&V<=o&&q>=n&&q<=a})},onPicked:(e,n)=>{M.clear();for(const o of e)M.add(o);G(),v(),e.length>0&&f!==null&&de(e,n,A,f)},onClear:()=>{M.clear(),G(),v()},hasSelection:()=>M.size>0}:void 0}),Ze=ut(l,()=>v());K();function et(e,n){f=e,w=n,Ke.value=String(e),qe.value=String(n),K()}function tt(e){if((e.limits??"both")===(O.limits??"both")){O=e;return}O=e,ke(),v()}return{card:l,setXY:et,setAxisPrefs:tt,destroy:()=>{Ze.disconnect(),Qe.destroy()}}}
1
+ import{NO_DATA_FILL as Fe}from"../../renderer/colorMap.js";import{escHtml as Z,maxOf as se,minOf as _e}from"../../core/utils.js";import{fmt as je}from"../../renderer/fmt.js";import{categorical as dt}from"./palette.js";import{buildScatterData as ft,buildScatterDataGrouped as mt}from"../../stats/scatter.js";import{pearsonOfPairs as ut}from"../../stats/correlation.js";import{buildFacetTable as pt}from"../../stats/facets.js";import{SPACE as B,RADIUS as xt,fontPx as N,FONT as ge,CLR as ee}from"../toolbar.js";import{fitTicks as Ge}from"../../renderer/axisTicks.js";import{wirePointInteractions as ht}from"./pointInteractions.js";import{placeClearOf as Xe,cardShell as bt,observeResize as yt,makeTooltip as gt,attachChartTip as wt,makeTestSelect as St,makeWaferSelect as Tt,chartFillHeight as kt,applyCanvasFlow as Mt,drawAxisUnit as vt,resolveChartCanvasColors as Ct,makeAxisFormat as le,horizontalTickSpacing as Lt,VERTICAL_TICK_SPACING_PX as Ot,makeSeriesLegendItem as At,prepareCanvas as Pt,drawOffAxisLimits as Ye,limitLines as $t,hasBothLimitKinds as It,makeLimitsSelect as Dt,stackLabelRows as Ue,strokeLimitLine as Ke,fillTextOnHalo as Ve}from"./chartShell.js";const p=52,Bt=16,c=16,Et=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(x){return x===void 0?NO_BIN_CATEGORY:String(x)}export function binCategories(x){const te=new Set;let v=!1;for(const R of x)R.hbin===void 0?v=!0:te.add(R.hbin);const O=Array.from(te).sort((R,ae)=>R-ae).map(String);return v&&O.push(NO_BIN_CATEGORY),O}export function renderScatterPanel(x){const{title:te="Test scatter",items:v,testDefs:O,binColors:R,onSaveImage:ae,groups:_}=x,{card:l,body:H,controlsRow:re}=bt(te,ae,x.ownerDocument),ne=O.filter(e=>e.testNumber!==void 0),A=!!(_&&_.length>0),we=(_??[]).map(e=>e.key),qe=new Map(we.map((e,n)=>[e,n]));let f=x.xTestNumber??ne[0]?.testNumber??null,w=x.yTestNumber??ne[1]?.testNumber??f,j=null;const Se=()=>j!==null?v[j]?[v[j]]:[]:v;function Te(e,n,o){const a=l.ownerDocument.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:B.xs,fontSize:ge.body,color:ee.label});const y=l.ownerDocument.createElement("span");y.textContent=e;const r=St(ne,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:l.ownerDocument});return a.append(y,r),{wrap:a,select:r}}const{wrap:Je,select:Qe}=Te("X:",f,e=>{f=e,K()}),{wrap:Ze,select:et}=Te("Y:",w,e=>{w=e,K()});re.append(Je,Ze);let P=x.axisPrefs??{clipOutliers:!1};const ke=l.ownerDocument.createElement("span");re.appendChild(ke);function Me(){const e=[f,w].map(n=>O.find(o=>o.testNumber===n));ke.replaceChildren(...e.some(It)?[Dt(P.limits??"both",n=>{P={...P,limits:n},x.onAxisPrefsChange?.(P),L()},l.ownerDocument)]:[])}!A&&v.length>1&&re.appendChild(Tt(v,j,e=>{j=e,K()},{ownerDocument:l.ownerDocument}));const F=l.ownerDocument.createElement("div");F.dataset.wmapCaption="1",Object.assign(F.style,{color:ee.warnText,background:ee.warnBg,border:`1px solid ${ee.warnBorder}`,borderRadius:xt.control,padding:`${B.xs} ${B.md}`,fontSize:ge.body,marginBottom:B.xs,display:"none"}),l.insertBefore(F,H);function ve(){const e=A?[]:pt(Se(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(F.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,F.style.display=""):F.style.display="none"}ve();const oe=l.ownerDocument.createElement("div");oe.dataset.wmapCaption="1",Object.assign(oe.style,{color:ee.label,fontSize:ge.body,marginBottom:B.xs}),l.insertBefore(oe,H);function G(){const e=(A?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter")+(fe?` \xB7 click a point to ${Oe}`:"")+(de?C.size>0?` \xB7 ${C.size.toLocaleString()} selected (click empty space to clear)`:" \xB7 drag to select dies":""),n=h.size===0?b:b.filter(y=>h.has(E(y))),{r:o,n:a}=ut(n);oe.textContent=o===null?`${e} \xB7 n = ${a.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${a.toLocaleString()}`}const E=e=>A?e.group??"\u2014":binCategoryOf(e.hbin),Ce=e=>A?dt(qe.get(e)??0):e===NO_BIN_CATEGORY?Fe:R?.get(Number(e))??Fe,ce=e=>A?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,h=new Set,X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:B.sm,marginTop:B.md,marginBottom:B.xl}),H.appendChild(X);const $=l.ownerDocument.createElement("canvas");$.style.display="block",$.style.cursor="crosshair",H.appendChild($);const Le=gt(l);let b=[],g=0,I=1,S=0,W=1,Y=[],ie=null;const C=new Set,de=x.onSelect,fe=x.onOpen,Oe=x.openActionLabel??"open this wafer",Ae=new Map;for(const e of[...v,...(_??[]).flatMap(n=>n.items)])e.waferIndex!==void 0&&e.label&&Ae.set(e.waferIndex,e.label);function U(e){const n=O.find(o=>o.testNumber===e);return{unit:n?.unit,lines:$t(n,P.limits)}}function Pe(){const e=H.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=kt(l,H,$,n);return{w:e,h:o,plotW:Math.max(10,e-p-Bt),plotH:Math.max(10,o-c-Et)}}const me=new Map;function $e(){for(const[e,n]of me){const o=h.has(e);n.setState({selected:o,dimmed:h.size>0&&!o})}}function Ie(e){X.innerHTML="",me.clear(),h.clear();for(const n of e){const o=At(ce(n),Ce(n),l.ownerDocument),a=o.el;a.dataset.cat=n,me.set(n,o),wt(a,l,Le,`${ce(n)} \u2014 click to filter`),a.addEventListener("click",()=>{h.has(n)?h.delete(n):h.add(n),$e(),G(),L()}),X.appendChild(a)}$e()}function L(){Mt($,X);const e=Ct(l),n=I-g,o=W-S,{w:a,h:y,plotW:r,plotH:s}=Pe(),z=Pt($,l,a,y);if(!z)return;const{ctx:t}=z;if(b.length===0){Y=[],t.font=`${N()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",a/2,y/2);return}t.font=`${N(-1)}px system-ui, sans-serif`;const M=f!==null?U(f).unit:void 0,V=Ge(g,I,r,Lt(t,Math.max(Math.abs(g),Math.abs(I)),M)),q=Ge(S,W,s,()=>Ot),ue=le(Math.max(Math.abs(g),Math.abs(I)),f!==null?U(f).unit:void 0,V.step||void 0),pe=le(Math.max(Math.abs(S),Math.abs(W)),w!==null?U(w).unit:void 0,q.step||void 0);t.font=`${N(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of V.ticks){const d=p+(m-g)/n*r;t.beginPath(),t.moveTo(d,c),t.lineTo(d,c+s),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(ue.tick(m),d,c+s+4)}for(const m of q.ticks){const d=c+(1-(m-S)/o)*s;t.beginPath(),t.moveTo(p,d),t.lineTo(p+r,d),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(pe.tick(m),p-4,d)}ue.unitLabel&&vt(t,ue.unitLabel,p+r/2,c+s+24,e.textMuted),pe.unitLabel&&(t.save(),t.font=`${N(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,c+s/2),t.rotate(-Math.PI/2),t.fillText(`(${pe.unitLabel})`,0,0),t.restore());const J=h.size===0?b:b.filter(m=>h.has(E(m))),Be=J.length>5e3?Math.ceil(J.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(J.length/Be))),Y=[];for(let m=0;m<J.length;m+=Be){const d=J[m],T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;Y.push({p:d,cx:T,cy:D}),t.beginPath(),t.arc(T,D,2.5,0,Math.PI*2),t.fillStyle=Ce(E(d)),t.fill()}t.globalAlpha=1;const xe=ie?Y.find(m=>m.p===ie):void 0;if(xe&&(t.beginPath(),t.arc(xe.cx,xe.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),C.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let m=0;for(const d of C){if(h.size>0&&!h.has(E(d)))continue;if(++m>5e3)break;const T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;t.beginPath(),t.arc(T,D,4,0,Math.PI*2),t.stroke()}}if(f!==null&&w!==null){const m=U(f),d=U(w);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${N(-1)}px system-ui, sans-serif`,t.textBaseline="top";const T=N(-1)+2,D=m.lines.filter(i=>i.value>=g&&i.value<=I).map(i=>{const u=p+(i.value-g)/n*r;return{l:i,cx:u,start:u+2,end:u+2+t.measureText(i.label).width}}),Ee=Ue(D),We=[];D.forEach(({l:i,cx:u,start:Q,end:k},ye)=>{Ke(t,i,e.limitLine,u,c,u,c+s),t.textAlign="left";const He=c+2+Ee[ye]*T,ct=Xe(We,{x0:Q,x1:k,y0:He,y1:He+T},T);Ve(t,i.label,u+2,ct.y0,e.bg)});const he=d.lines.filter(i=>i.value>=S&&i.value<=W).map(i=>{const u=c+(1-(i.value-S)/o)*s;return{l:i,cy:u,start:u+2,end:u+2+N(-1)}}),lt=Ue(he,1),at=se(he.map(i=>t.measureText(i.l.label).width))+8;he.forEach(({l:i,cy:u},Q)=>{Ke(t,i,e.limitLine,p,u,p+r,u),t.textAlign="left";const k=p+3+lt[Q]*at,ye=Xe(We,{x0:k,x1:k+t.measureText(i.label).width,y0:u+2,y1:u+2+T},T);Ve(t,i.label,k,ye.y0,e.bg)});const ze=(i,u,Q)=>i.filter(k=>k.value<u||k.value>Q).map(k=>({value:k.value,label:k.label,side:k.value<u?"lo":"hi"})),Ne={left:p,right:p+r,top:c,bottom:c+s},be=ze(m.lines,g,I),Re=c+(D.length?(se(Ee)+1)*T:0),rt=Math.max(be.filter(i=>i.side==="lo").length,be.filter(i=>i.side==="hi").length);Ye(t,be,{...Ne,top:Re},"horizontal",e.limitLine,i=>le(Math.abs(i),m.unit).tick(i),e.bg),Ye(t,ze(d.lines,S,W),{...Ne,top:Re+rt*T},"vertical",e.limitLine,i=>le(Math.abs(i),d.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(p,c),t.lineTo(p,c+s),t.moveTo(p,c+s),t.lineTo(p+r,c+s),t.stroke()}function K(){if(ie=null,C.clear(),ve(),Me(),ne.length<2||f===null||w===null){b=[],Ie([]),G(),L();return}b=A?mt(_,f,w):ft(Se(),f,w);let e;if(A){const n=new Set(b.map(E));e=we.filter(o=>n.has(o))}else e=binCategories(b);if(Ie(e),G(),b.length>0){const n=b.map(M=>M.x),o=b.map(M=>M.y),a=_e(n),y=se(n),r=_e(o),s=se(o),z=(y-a)*.05||1,t=(s-r)*.05||1;g=a-z,I=y+z,S=r-t,W=s+t}L()}const De=e=>!!fe&&e.waferIndex!==void 0;function tt(e){const n=O.find(s=>s.testNumber===f),o=O.find(s=>s.testNumber===w),a=e.waferIndex!==void 0?Ae.get(e.waferIndex):void 0,y=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,y].filter(Boolean).join(" \xB7 ");return(r?`<strong>${Z(r)}</strong><br>`:"")+Z(`${n?.name??"X"}: ${je(e.x,n?.unit)}`)+"<br>"+Z(`${o?.name??"Y"}: ${je(e.y,o?.unit)}`)+"<br>"+Z(ce(E(e)))+(De(e)?`<br><em>click to ${Z(Oe)}</em>`:"")}const nt=ht({card:l,canvas:$,tooltip:Le,drawn:()=>Y,describe:tt,clickable:De,onOpen:e=>{f!==null&&fe(e.waferIndex,f)},onHover:e=>{ie=e,L()},select:de?{pick:({x0:e,y0:n,x1:o,y1:a})=>{const{plotW:y,plotH:r}=Pe(),s=I-g,z=W-S;return(h.size===0?b:b.filter(M=>h.has(E(M)))).filter(M=>{const V=p+(M.x-g)/s*y,q=c+(1-(M.y-S)/z)*r;return V>=e&&V<=o&&q>=n&&q<=a})},onPicked:(e,n)=>{C.clear();for(const o of e)C.add(o);G(),L(),e.length>0&&f!==null&&de(e,n,$,f)},onClear:()=>{C.clear(),G(),L()},hasSelection:()=>C.size>0}:void 0}),ot=yt(l,()=>L());K();function it(e,n){f=e,w=n,Qe.value=String(e),et.value=String(n),K()}function st(e){if((e.limits??"both")===(P.limits??"both")){P=e;return}P=e,Me(),L()}return{card:l,setXY:it,setAxisPrefs:st,destroy:()=>{ot.disconnect(),nt.destroy()}}}
@@ -1 +1 @@
1
- import{buildTestPassRateData as F,hasJudgeableTests as N}from"../../stats/testPassRate.js";import{categorical as B,QUANTITY as I}from"./palette.js";import{SPACE as _,FONT as H,CLR as L}from"../toolbar.js";import{cardShell as k,makeTooltip as A,makeSegmented as O,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as j}from"./groupedBarPlot.js";import{escHtml as f}from"../../core/utils.js";const M=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(i){const{groups:b,testDefs:h,onSaveImage:$}=i,p=i.ownerDocument??document,C=b.flatMap(t=>t.items.flatMap(o=>o.dies??[])),m=["spec","testFlag","functional"].filter(t=>N(h,t,C));let s=m[0]??"spec";const T=t=>U[t],{card:n,heading:P,body:c,controlsRow:R}=k(T(s),$,p);n.style.alignSelf="start",m.length>1&&R.appendChild(O(m.map(t=>[t,K[t]]),s,t=>{s=t,P.textContent=T(s),S()},p));const r=p.createElement("div");r.dataset.wmapCaption="1",Object.assign(r.style,{color:L.label,fontSize:H.body,marginBottom:_.sm}),n.insertBefore(r,c);const D=A(n);let g=null;function S(){if(g?.destroy(),g=null,c.innerHTML="",m.length===0){r.textContent="",y(c,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const t=F(b,h,s);if(t.rows.length===0){r.textContent="",y(c,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const o=t.groups.length>1,v=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(r.textContent=v+(o?" \xB7 one bar per group":"")+" \xB7 worst first"+(i.onSelectTest?" \xB7 click a test to chart or tabulate the dies that fail it":""),t.disagreementDies){const e=p.createElement("span");e.textContent=` \xB7 ${t.disagreementDies.toLocaleString()} die${t.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(e.style,{color:L.warnText}),r.appendChild(e)}const u=t.rows,x=e=>o?B(e):I;g=j(n,c,D,{rows:u.map(e=>({label:e.label,bars:e.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:e.overall.passRatePercent===null?"\u2014":`${e.overall.passRatePercent.toFixed(1)}%`})),groups:t.groups,labelWidth:M,maxVisibleRows:G,showLegend:o,maxLabelChars:14,emptyBarText:"no data",colorOf:x,onRowClick:i.onSelectTest?(e,l,a)=>i.onSelectTest({testNumber:u[e].testNumber,label:u[e].label,kind:s},a):void 0,tooltipHtml:(e,l)=>{const a=u[e],d=a.byGroup[l],w=o?` \xB7 ${f(String(t.groups[l]))}`:"";if(d.passRatePercent===null)return`<strong>${f(a.label)}</strong>${w}<br>no dies with a verdict`;const E=s==="spec"&&!o&&(a.failLowDies||a.failHighDies)?`<br>${a.failLowDies??0} below the low limit \xB7 ${a.failHighDies??0} above the high limit`:"";return`<strong>${f(a.label)}</strong>${w}<br>${d.passRatePercent.toFixed(1)}% pass<br>${d.passDies.toLocaleString()} pass \xB7 ${d.failDies.toLocaleString()} fail \xB7 n = ${d.totalDies.toLocaleString()}`+E}})}return S(),{card:n,destroy:()=>{g?.destroy(),D.remove(),n.remove()}}}
1
+ import{buildTestPassRateData as F,hasJudgeableTests as E}from"../../stats/testPassRate.js";import{categorical as I,QUANTITY as B}from"./palette.js";import{SPACE as _,FONT as H,CLR as L}from"../toolbar.js";import{cardShell as A,makeTooltip as O,makeSegmented as j,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as k}from"./groupedBarPlot.js";import{escHtml as f}from"../../core/utils.js";const M=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},J={spec:"Judged from each die's measured value against the test's limits",testFlag:"The pass or fail the tester recorded for each die",functional:"Tests that only pass or fail and have no measured value"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(i){const{groups:h,testDefs:b,onSaveImage:v}=i,p=i.ownerDocument??document,$=h.flatMap(e=>e.items.flatMap(o=>o.dies??[])),m=["spec","testFlag","functional"].filter(e=>E(b,e,$));let s=m[0]??"spec";const T=e=>U[e],{card:n,heading:C,body:c,controlsRow:P}=A(T(s),v,p);n.style.alignSelf="start",m.length>1&&P.appendChild(j(m.map(e=>[e,K[e],J[e]]),s,e=>{s=e,C.textContent=T(s),S()},p));const r=p.createElement("div");r.dataset.wmapCaption="1",Object.assign(r.style,{color:L.label,fontSize:H.body,marginBottom:_.sm}),n.insertBefore(r,c);const D=O(n);let g=null;function S(){if(g?.destroy(),g=null,c.innerHTML="",m.length===0){r.textContent="",y(c,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const e=F(h,b,s);if(e.rows.length===0){r.textContent="",y(c,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const o=e.groups.length>1,R=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(r.textContent=R+(o?" \xB7 one bar per group":"")+" \xB7 worst first"+(i.onSelectTest?" \xB7 click a test to chart or tabulate the dies that fail it":""),e.disagreementDies){const t=p.createElement("span");t.textContent=` \xB7 ${e.disagreementDies.toLocaleString()} die${e.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(t.style,{color:L.warnText}),r.appendChild(t)}const u=e.rows,x=t=>o?I(t):B;g=k(n,c,D,{rows:u.map(t=>({label:t.label,bars:t.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:t.overall.passRatePercent===null?"\u2014":`${t.overall.passRatePercent.toFixed(1)}%`})),groups:e.groups,labelWidth:M,maxVisibleRows:G,showLegend:o,maxLabelChars:14,emptyBarText:"no data",colorOf:x,onRowClick:i.onSelectTest?(t,l,a)=>i.onSelectTest({testNumber:u[t].testNumber,label:u[t].label,kind:s},a):void 0,tooltipHtml:(t,l)=>{const a=u[t],d=a.byGroup[l],w=o?` \xB7 ${f(String(e.groups[l]))}`:"";if(d.passRatePercent===null)return`<strong>${f(a.label)}</strong>${w}<br>no dies with a verdict`;const N=s==="spec"&&!o&&(a.failLowDies||a.failHighDies)?`<br>${a.failLowDies??0} below the low limit \xB7 ${a.failHighDies??0} above the high limit`:"";return`<strong>${f(a.label)}</strong>${w}<br>${d.passRatePercent.toFixed(1)}% pass<br>${d.passDies.toLocaleString()} pass \xB7 ${d.failDies.toLocaleString()} fail \xB7 n = ${d.totalDies.toLocaleString()}`+N}})}return S(),{card:n,destroy:()=>{g?.destroy(),D.remove(),n.remove()}}}
@@ -1,4 +1,5 @@
1
1
  import type { Die } from '../core/dies.js';
2
+ import { type FacetCuration } from '../stats/facets.js';
2
3
  import { type MetadataFieldDef, type TestDef } from '../renderer/buildWaferMap.js';
3
4
  import { type DieListDisplayOptions } from './dieList.js';
4
5
  import { type SaveTextHandler } from './toolbar.js';
@@ -19,6 +20,7 @@ export interface DataItem {
19
20
  export declare const DATA_VIEWS: ReadonlyArray<{
20
21
  key: DataView;
21
22
  label: string;
23
+ hint: string;
22
24
  }>;
23
25
  /** Rows Excel can open. A file with more is still valid; the reader is told. */
24
26
  export declare const EXCEL_ROW_LIMIT = 1048576;
@@ -55,6 +57,8 @@ export interface DataSectionDeps {
55
57
  dieListOptions?: DieListDisplayOptions;
56
58
  /** Label/order hints for die metadata columns, e.g. `WaferMapResult.metadataFields`. */
57
59
  metadataFields?: MetadataFieldDef[];
60
+ /** The host's own wafer attributes (`attributes` on the render options): the Wafers table names its columns by them. */
61
+ attributes?: Record<string, FacetCuration>;
58
62
  /** A die row was clicked: show that die on its map. When set, Dies rows are clickable and say so. */
59
63
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
60
64
  /** A wafer row was clicked: open that wafer. When set, Wafers rows are clickable and say so. */
@@ -97,6 +101,8 @@ export interface DataTablesInput {
97
101
  /** The wafers' ring count (`WaferMapResult.ringCount`): ring and quadrant columns use it. Required, never defaulted. */
98
102
  ringCount: number;
99
103
  metadataFields?: MetadataFieldDef[];
104
+ /** The host's own wafer attributes, for the Wafers table's column names. */
105
+ attributes?: Record<string, FacetCuration>;
100
106
  /** A die row clicked: show that die on its map. The caller closes the table around it. */
101
107
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
102
108
  dieListOptions?: DieListDisplayOptions;
@@ -1 +1 @@
1
- import{isYieldEligibleDie as W}from"../core/dies.js";import{testValue as O}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{prettyKey as z}from"../core/utils.js";import{tableToTsv as N}from"../core/tableCsv.js";import{commonMetadata as H}from"../stats/facets.js";import{buildYieldData as Y}from"../stats/yield.js";import{isParametricTest as k}from"../renderer/buildWaferMap.js";import{fmt as G}from"../renderer/fmt.js";import{testLabel as R}from"../renderer/testLabel.js";import{resolveDieColumns as U}from"./dieList.js";import{createVirtualTable as V}from"./virtualTable.js";import{exportCsv as E}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as j,SPACE as C,controlStyle as K,wireControlHover as A,wireTooltip as $}from"./toolbar.js";import{buildTestSection as q,buildFunctionalTestSection as X}from"./summaryPanel.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics"},{key:"dies",label:"Dies"},{key:"wafers",label:"Wafers"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,i,s=i+"s")=>`${e.toLocaleString()} ${e===1?i:s}`;export function renderDataSection(e){const{doc:i}=e,s=i.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=i.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),s.appendChild(c);const p=i.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),s.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),r=F(i,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(r.el);let d;switch(e.view){case"dies":d=Q(e);break;case"wafers":d=Z(e);break;default:d=J(e)}let u=()=>{};if(e.view==="dies"){const f=F(i,"Export format",[{key:"wide",label:"Wide"},{key:"long",label:"Long"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),d.actions?.setLayout?.(t),u()});$(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const l=i.createElement("span");Object.assign(l.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const o=i.createElement("span");o.textContent="Export format:",Object.assign(o.style,{color:y.label,fontSize:L.body}),l.append(o,f.el),c.appendChild(l)}if(d.actions){const f=d.actions,l=i.createElement("div");l.style.flex="1",c.appendChild(l);const o=B(i,"Export CSV");o.dataset.wmapDataExport="1",o.addEventListener("click",()=>{if(o.disabled)return;const m=o.textContent,h=f.exportCsv();h&&(o.disabled=!0,o.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=m}))});const t=B(i,"Copy");t.dataset.wmapDataCopy="1",f.copyText?($(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=i.defaultView?.navigator?.clipboard;if(!h)return;const w=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",i.defaultView?.setTimeout(()=>{t.textContent=w},1500)}).catch(()=>{})})):(t.disabled=!0,$(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,o);const a=i.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),s.insertBefore(a,p)}return p.appendChild(d.el),{card:s,destroy:()=>d.destroy()}}function J(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const r of g){if(p){const u=i.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${r.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),s.appendChild(u)}const d=e.buildStatistics(r.items);c.push(d.destroy);for(const u of d.cards)s.appendChild(u)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:y.label,fontSize:L.body})),{el:s,destroy:()=>{for(const r of c)r()}}}function Q(e){const{doc:i,items:s}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,r=[];let d=!1;for(const n of s){n.wafer&&(d=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),r.push(b)}if(r.length===0)return M(i,"No dies to show.");const{columns:u,visibleColumns:f}=U(r,e.allTestDefs,{...e.dieListOptions,metadataFields:e.metadataFields,extraColumn:s.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:d?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:s.some(n=>n.wafer)?H(s.map(n=>({metadata:n.wafer?.metadata}))):void 0,ownerDocument:i}),l=f.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&k(n.test),...n.test!==void 0&&k(n.test)?{sortKey:b=>O(b,n.test.testNumber)}:{}})),o=V({columns:l,rows:r,ariaLabel:`Dies (${r.length})`,ownerDocument:i,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});o.el.style.maxHeight="70vh",o.el.style.minHeight="240px";const t=e.population?`-${e.population.fileTag}`:"",a=u.filter(n=>n.test!==void 0),m=u.filter(n=>n.test===void 0),h=r.length*u.length,w=r.length*a.length,x=()=>u.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),v=()=>[...m.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>R(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*_(){for(const n of o.orderedRows())for(const b of a){const S=(b.csvGet??b.get)(n);S===""||S===void 0||S===null||(yield{die:n,test:b.test,value:S})}}let T=e.diesLayout==="long"&&a.length>0;const P=()=>T?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(r.length,"row")} \xD7 ${D(u.length,"column")}`+(r.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:o.el,destroy:()=>o.destroy(),actions:{note:()=>`${D(r.length,"die")} ${e.population?.phrase??`on ${D(s.length,"wafer")}`}. ${P()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{T=n==="long"&&a.length>0},exportCsv:()=>T?E(v(),_(),`die-list-long${t}.csv`,e.onSaveText,{rowCount:w}):E(x(),o.orderedRows(),`die-list${t}.csv`,e.onSaveText,{rowCount:r.length}),copyText:h<=COPY_CELL_LIMIT?()=>N(x(),o.orderedRows()):null}}}function Z(e){const{doc:i,items:s}=e;if(s.length===0)return M(i,"No wafers to show.");const c=s.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=Y([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),r=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(x=>x.testNumber===a.testNumber);if(m)return m.mean;let h=0,w=0;for(const x of t.item.dies){if(!W(x))continue;const v=O(x,a.testNumber);v!==void 0&&Number.isFinite(v)&&(h++,w+=v)}return h?w/h:void 0},d=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:z(t),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>W(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${R(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>r(a,t),show:a=>{const m=r(a,t);return m===void 0?"":G(m,t.unit)},numeric:!0}))],u=d.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=V({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:i,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const l=()=>d.map(t=>({header:t.header,get:t.cell})),o=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${o}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>E(l(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*d.length<=COPY_CELL_LIMIT?()=>N(l(),f.orderedRows()):null}}}function M(e,i){const s=e.createElement("div");return s.textContent=i,Object.assign(s.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:s,destroy:()=>{}}}function B(e,i){const s=e.createElement("button");return s.type="button",s.textContent=i,Object.assign(s.style,{fontSize:L.body,padding:"3px 10px",borderRadius:j.control,...K("outlined"),background:y.menuBg}),A(s),s}function F(e,i,s,c,p,g){const r=e.createElement("div");r.setAttribute("role","radiogroup"),r.setAttribute("aria-label",i),Object.assign(r.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:j.control,overflow:"hidden"});const d=[];let u=c;const f=()=>{for(const l of d){const o=l.dataset[p]===u;l.setAttribute("aria-checked",String(o)),l.tabIndex=o?0:-1,Object.assign(l.style,{background:o?y.bgActive:"transparent",color:o?y.iconActive:y.label,fontWeight:o?"600":"400"})}};for(const l of s){const o=e.createElement("button");o.type="button",o.textContent=l.label,o.dataset[p]=l.key,o.setAttribute("role","radio"),Object.assign(o.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),A(o,"bare"),o.addEventListener("click",()=>{u!==l.key&&g(l.key)}),d.push(o),r.appendChild(o)}return f(),r.addEventListener("keydown",l=>{if(l.key!=="ArrowLeft"&&l.key!=="ArrowRight")return;const o=d.indexOf(e.activeElement);if(o<0)return;l.preventDefault();const t=d[(o+(l.key==="ArrowRight"?1:-1)+d.length)%d.length];t.click(),t.focus()}),{el:r,set:l=>{u=l,f()}}}export function renderDataTables(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],r=g.filter(k),d=e.views??(c.length>1?["statistics","dies","wafers"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=d.includes(e.view)?e.view:d[0],l="wide",o=null;const t=()=>{o?.destroy(),o=renderDataSection({doc:i,items:c,testDefs:r,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:d,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(v=>v.dies),h=[],w=q(m,r,void 0,void 0,e.onSaveText,u,a.map(v=>({dies:v.dies})),void 0,"full");w&&h.push(w);const x=X(m,g,void 0,e.onSaveText,u);return x&&h.push(x),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:l,onDiesLayoutChange:a=>{l=a}}),s.replaceChildren(o.card)};return t(),{el:s,destroy:()=>o?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","dies","wafers"]:["statistics","dies"]})}
1
+ import{isYieldEligibleDie as O}from"../core/dies.js";import{testValue as W}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as z}from"../stats/facets.js";import{tableToTsv as A}from"../core/tableCsv.js";import{commonMetadata as H}from"../stats/facets.js";import{buildYieldData as Y}from"../stats/yield.js";import{isParametricTest as E}from"../renderer/buildWaferMap.js";import{fmt as G}from"../renderer/fmt.js";import{testLabel as N}from"../renderer/testLabel.js";import{resolveDieColumns as U}from"./dieList.js";import{createVirtualTable as R}from"./virtualTable.js";import{exportCsv as $}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as V,SPACE as C,controlStyle as K,wireControlHover as j,wireTooltip as T}from"./toolbar.js";import{buildTestSection as q,buildFunctionalTestSection as X}from"./summaryPanel.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,i,s=i+"s")=>`${e.toLocaleString()} ${e===1?i:s}`;export function renderDataSection(e){const{doc:i}=e,s=i.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=i.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),s.appendChild(c);const p=i.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),s.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),l=F(i,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(l.el);let d;switch(e.view){case"dies":d=Q(e);break;case"wafers":d=Z(e);break;default:d=J(e)}let u=()=>{};if(e.view==="dies"){const f=F(i,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),d.actions?.setLayout?.(t),u()});T(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const r=i.createElement("span");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const o=i.createElement("span");o.textContent="Export format:",Object.assign(o.style,{color:y.label,fontSize:L.body}),r.append(o,f.el),c.appendChild(r)}if(d.actions){const f=d.actions,r=i.createElement("div");r.style.flex="1",c.appendChild(r);const o=B(i,"Export CSV");o.dataset.wmapDataExport="1",o.addEventListener("click",()=>{if(o.disabled)return;const m=o.textContent,h=f.exportCsv();h&&(o.disabled=!0,o.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=m}))});const t=B(i,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(T(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=i.defaultView?.navigator?.clipboard;if(!h)return;const w=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",i.defaultView?.setTimeout(()=>{t.textContent=w},1500)}).catch(()=>{})})):(t.disabled=!0,T(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,o);const a=i.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),s.insertBefore(a,p)}return p.appendChild(d.el),{card:s,destroy:()=>d.destroy()}}function J(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const l of g){if(p){const u=i.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${l.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),s.appendChild(u)}const d=e.buildStatistics(l.items);c.push(d.destroy);for(const u of d.cards)s.appendChild(u)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:y.label,fontSize:L.body})),{el:s,destroy:()=>{for(const l of c)l()}}}function Q(e){const{doc:i,items:s}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,l=[];let d=!1;for(const n of s){n.wafer&&(d=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),l.push(b)}if(l.length===0)return M(i,"No dies to show.");const{columns:u,visibleColumns:f}=U(l,e.allTestDefs,{...e.dieListOptions,metadataFields:e.metadataFields,extraColumn:s.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:d?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:s.some(n=>n.wafer)?H(s.map(n=>({metadata:n.wafer?.metadata}))):void 0,ownerDocument:i}),r=f.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&E(n.test),...n.test!==void 0&&E(n.test)?{sortKey:b=>W(b,n.test.testNumber)}:{}})),o=R({columns:r,rows:l,ariaLabel:`Dies (${l.length})`,ownerDocument:i,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});o.el.style.maxHeight="70vh",o.el.style.minHeight="240px";const t=e.population?`-${e.population.fileTag}`:"",a=u.filter(n=>n.test!==void 0),m=u.filter(n=>n.test===void 0),h=l.length*u.length,w=l.length*a.length,x=()=>u.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),v=()=>[...m.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>N(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*_(){for(const n of o.orderedRows())for(const b of a){const S=(b.csvGet??b.get)(n);S===""||S===void 0||S===null||(yield{die:n,test:b.test,value:S})}}let k=e.diesLayout==="long"&&a.length>0;const P=()=>k?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(l.length,"row")} \xD7 ${D(u.length,"column")}`+(l.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:o.el,destroy:()=>o.destroy(),actions:{note:()=>`${D(l.length,"die")} ${e.population?.phrase??`on ${D(s.length,"wafer")}`}. ${P()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{k=n==="long"&&a.length>0},exportCsv:()=>k?$(v(),_(),`die-list-long${t}.csv`,e.onSaveText,{rowCount:w}):$(x(),o.orderedRows(),`die-list${t}.csv`,e.onSaveText,{rowCount:l.length}),copyText:h<=COPY_CELL_LIMIT?()=>A(x(),o.orderedRows()):null}}}function Z(e){const{doc:i,items:s}=e;if(s.length===0)return M(i,"No wafers to show.");const c=s.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=Y([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),l=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(x=>x.testNumber===a.testNumber);if(m)return m.mean;let h=0,w=0;for(const x of t.item.dies){if(!O(x))continue;const v=W(x,a.testNumber);v!==void 0&&Number.isFinite(v)&&(h++,w+=v)}return h?w/h:void 0},d=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:z(t,e.attributes),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>O(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${N(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>l(a,t),show:a=>{const m=l(a,t);return m===void 0?"":G(m,t.unit)},numeric:!0}))],u=d.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=R({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:i,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const r=()=>d.map(t=>({header:t.header,get:t.cell})),o=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${o}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>$(r(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*d.length<=COPY_CELL_LIMIT?()=>A(r(),f.orderedRows()):null}}}function M(e,i){const s=e.createElement("div");return s.textContent=i,Object.assign(s.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:s,destroy:()=>{}}}function B(e,i){const s=e.createElement("button");return s.type="button",s.textContent=i,Object.assign(s.style,{fontSize:L.body,padding:"3px 10px",borderRadius:V.control,...K("outlined"),background:y.menuBg}),j(s),s}function F(e,i,s,c,p,g){const l=e.createElement("div");l.setAttribute("role","radiogroup"),l.setAttribute("aria-label",i),Object.assign(l.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:V.control,overflow:"hidden"});const d=[];let u=c;const f=()=>{for(const r of d){const o=r.dataset[p]===u;r.setAttribute("aria-checked",String(o)),r.tabIndex=o?0:-1,Object.assign(r.style,{background:o?y.bgActive:"transparent",color:o?y.iconActive:y.label,fontWeight:o?"600":"400"})}};for(const r of s){const o=e.createElement("button");r.hint&&T(o,r.hint),o.type="button",o.textContent=r.label,o.dataset[p]=r.key,o.setAttribute("role","radio"),Object.assign(o.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(o,"bare"),o.addEventListener("click",()=>{u!==r.key&&g(r.key)}),d.push(o),l.appendChild(o)}return f(),l.addEventListener("keydown",r=>{if(r.key!=="ArrowLeft"&&r.key!=="ArrowRight")return;const o=d.indexOf(e.activeElement);if(o<0)return;r.preventDefault();const t=d[(o+(r.key==="ArrowRight"?1:-1)+d.length)%d.length];t.click(),t.focus()}),{el:l,set:r=>{u=r,f()}}}export function renderDataTables(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],l=g.filter(E),d=e.views??(c.length>1?["statistics","dies","wafers"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=d.includes(e.view)?e.view:d[0],r="wide",o=null;const t=()=>{o?.destroy(),o=renderDataSection({doc:i,items:c,testDefs:l,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:d,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,attributes:e.attributes,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(v=>v.dies),h=[],w=q(m,l,void 0,void 0,e.onSaveText,u,a.map(v=>({dies:v.dies})),void 0,"full");w&&h.push(w);const x=X(m,g,void 0,e.onSaveText,u);return x&&h.push(x),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:r,onDiesLayoutChange:a=>{r=a}}),s.replaceChildren(o.card)};return t(),{el:s,destroy:()=>o?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","dies","wafers"]:["statistics","dies"]})}
@@ -1,12 +1,12 @@
1
- import{requireRingCount as F}from"../core/ringCount.js";import{hasPosition as T,isPositionedDie as M}from"../core/dies.js";import{testsPresent as K,testValue as I}from"../core/dieTable.js";import{classifyDie as z}from"../core/classify.js";import{isParametricTest as B,getTestPassStatus as y}from"../renderer/buildWaferMap.js";import{resolveMetadataColumns as O}from"../stats/metadataColumns.js";import{LEADING as N,TRACKING as W,wireControlHover as j,controlStyle as V,SPACE as G,RADIUS as P,FONT as w,CLR as c}from"./toolbar.js";import{exportCsv as Y}from"./tableExport.js";import{fmt as _}from"../renderer/fmt.js";import{testLabel as L,markedTestLabel as H,derivedFields as U,derivedKeyText as X,derivedTestSource as q,isDerivedTest as Q,DERIVED_KEY as J}from"../renderer/testLabel.js";const $=(t,r)=>r?`${t} (${r})`:t,Z=5e4,k=new WeakSet;export function ensureStylesInjected(t){if(k.has(t))return;k.add(t);const r=t.createElement("style");r.textContent=`
1
+ import{requireRingCount as K}from"../core/ringCount.js";import{hasPosition as D,isPositionedDie as M}from"../core/dies.js";import{testsPresent as G,testValue as T}from"../core/dieTable.js";import{DIE_REGIONS as O,DIE_REGION_KEYS as P}from"../stats/dieRegions.js";import{isParametricTest as _,getTestPassStatus as E}from"../renderer/buildWaferMap.js";import{resolveMetadataColumns as z}from"../stats/metadataColumns.js";import{LEADING as N,TRACKING as B,wireControlHover as W,controlStyle as j,SPACE as V,RADIUS as k,FONT as w,CLR as f}from"./toolbar.js";import{exportCsv as Y}from"./tableExport.js";import{fmt as U}from"../renderer/fmt.js";import{testLabel as L,markedTestLabel as H,derivedFields as X,derivedKeyText as q,derivedTestSource as J,isDerivedTest as Q,DERIVED_KEY as Z}from"../renderer/testLabel.js";const $=(t,r)=>r?`${t} (${r})`:t,ee=5e4,F=new WeakSet;export function ensureStylesInjected(t){if(F.has(t))return;F.add(t);const r=t.createElement("style");r.textContent=`
2
2
  .wmap-dielist-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
3
3
  .wmap-dielist-th {
4
4
  text-align: left; padding: 4px 8px; position: sticky; top: 0;
5
- background: ${c.panelBg}; color: ${c.label}; font-weight: 600;
6
- border-bottom: 1px solid ${c.menuBorder}; white-space: nowrap;
5
+ background: ${f.panelBg}; color: ${f.label}; font-weight: 600;
6
+ border-bottom: 1px solid ${f.menuBorder}; white-space: nowrap;
7
7
  }
8
8
  .wmap-dielist-td {
9
- padding: 4px 8px; color: ${c.text};
10
- border-bottom: 1px solid ${c.menuBorder}; white-space: nowrap;
9
+ padding: 4px 8px; color: ${f.text};
10
+ border-bottom: 1px solid ${f.menuBorder}; white-space: nowrap;
11
11
  }
12
- `,t.head.appendChild(r)}function d(t,r,n,i){const l=t.createElement(r);return n&&Object.assign(l.style,n),i!==void 0&&(l.textContent=i),l}function ee(t){return T(t)?String(t.x):""}function te(t){return T(t)?String(t.y):""}function ne(t,r){return r!==void 0?r.filter(n=>n.testNumber!==void 0):K(t,"values").map(n=>({testNumber:n,name:L(void 0,n)}))}function ie(t,r,n){if(!r)return;const i=F(n,"the die list"),l=new Map;for(const m of t){if(!M(m))continue;const C=r(m);C&&l.set(m,z(m,C,{ringCount:i}))}return l.size>0?l:void 0}export function resolveDieColumns(t,r,n={}){const i=ne(t,r),l=ie(t,n.getWafer,n),m=t.some(e=>e.edgeExcluded===!0),C=[...n.extraColumn?[n.extraColumn.label]:[],"X","Y","Ring","Quadrant","Edge excluded","Site","Hard bin","Soft bin",...i.map(e=>$(L(e,e.testNumber),e.unit))],{columns:p,truncatedKeys:v}=O({dies:t,waferMetadata:n.waferMetadata,metadataFields:n.metadataFields,dieKeys:n.metadataColumns,waferKeys:n.waferMetadataColumns==="none"?"none":void 0,waferPlacement:n.waferMetadataColumns??"csv",reservedLabels:C}),a=[...n.extraColumn?[{label:n.extraColumn.label,get:e=>n.extraColumn.get(e)??""}]:[],{label:"X",get:ee},{label:"Y",get:te},...l?[{label:"Ring",get:e=>{const x=l.get(e);return x?String(x.ring):""}},{label:"Quadrant",get:e=>l.get(e)?.quadrant??""}]:[],...m?[{label:"Edge excluded",get:e=>e.edgeExcluded?"Yes":"No"}]:[],{label:"Site",get:e=>e.siteNum!==void 0?String(e.siteNum):""},{label:"Hard bin",get:e=>e.hbin!==void 0?String(e.hbin):""},{label:"Soft bin",get:e=>e.sbin!==void 0?String(e.sbin):""},...i.map(e=>{const x=!B(e);return{test:e,label:$(H(e,e.testNumber),e.unit),...Q(e)?{csvLabel:`${$(L(e,e.testNumber),e.unit)} [derived from ${q(e)??J}]`}:{},get:s=>{if(x){const u=y(s,e.testNumber,e);return u===void 0?"":u?"PASS":"FAIL"}const g=I(s,e.testNumber);if(g!==void 0)return _(g,e.unit);const h=y(s,e.testNumber,e);return h===void 0?"":h?"PASS":"FAIL"},csvGet:s=>{if(x){const u=y(s,e.testNumber,e);return u===void 0?"":u?"PASS":"FAIL"}const g=I(s,e.testNumber);if(g!==void 0)return g;const h=y(s,e.testNumber,e);return h===void 0?"":h?"PASS":"FAIL"}}}),...p.map(e=>({label:e.label,get:e.get,csvOnly:e.csvOnly}))],E=a.filter(e=>!e.csvOnly);return{columns:a,visibleColumns:E,testColumns:i,truncatedKeys:v}}export function buildDieListSection(t,r,n={}){if(!t.length)return null;const i=n.ownerDocument??document;ensureStylesInjected(i);const l=n.maxRows??Z,m=Math.max(0,t.length-l),C=m>0?t.slice(0,l):t,p=d(i,"div",{display:"flex",flexDirection:"column",gap:G.md,flex:"1",minHeight:"0",minWidth:"0"}),v=d(i,"div",{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:"0"});v.appendChild(d(i,"div",{fontSize:w.meta,fontWeight:"700",letterSpacing:W,textTransform:"uppercase",color:c.label},n.title??`Die list (${t.length})`));const a=d(i,"button",{fontSize:w.body,padding:"3px 8px",borderRadius:P.control,...V("outlined"),background:c.menuBg},"Export CSV");a.type="button",j(a),v.appendChild(a),p.appendChild(v),n.note&&p.appendChild(d(i,"div",{fontSize:w.body,color:c.label,lineHeight:N.base,flexShrink:"0"},n.note));const{columns:E,visibleColumns:e,testColumns:x,truncatedKeys:s}=resolveDieColumns(t,r,n),g=X(x.map(o=>({label:H(o,o.testNumber),...U(o)})));g&&p.appendChild(d(i,"div",{fontSize:w.body,color:c.label,lineHeight:N.base,flexShrink:"0"},g));const h=d(i,"div",{overflow:"auto",flex:"1",minHeight:"0",minWidth:"0",border:`1px solid ${c.menuBorder}`,borderRadius:P.control,...n.maxHeight?{maxHeight:n.maxHeight}:{}}),u=i.createElement("table");u.className="wmap-dielist-table",u.setAttribute("aria-label",n.title??`Die list (${t.length} dies)`);const A=d(i,"thead"),D=d(i,"tr");for(const o of e){const f=i.createElement("th");f.className="wmap-dielist-th",f.scope="col",f.textContent=o.label,D.appendChild(f)}A.appendChild(D),u.appendChild(A);const R=d(i,"tbody");for(const o of C){const f=d(i,"tr");for(const b of e){const S=i.createElement("td");S.className="wmap-dielist-td",S.textContent=b.get(o),f.appendChild(S)}R.appendChild(f)}if(u.appendChild(R),h.appendChild(u),p.appendChild(h),m>0||s.length>0){const o=[];m>0&&o.push(`Showing the first ${l.toLocaleString()} of ${t.length.toLocaleString()} dies. The CSV export contains all ${t.length.toLocaleString()}.`),s.length>0&&o.push(`${s.length} further metadata field${s.length===1?"":"s"} not shown.`),p.appendChild(d(i,"div",{fontSize:w.body,color:c.label,lineHeight:N.base,flexShrink:"0"},o.join(" ")))}return a.addEventListener("click",()=>{if(a.disabled)return;const o=a.textContent,f=Y(E.map(b=>({header:b.csvLabel??b.label,get:b.csvGet??b.get})),t,"die-list.csv",n.onSaveText,{onProgress:(b,S)=>{a.textContent=S?`Exporting ${Math.floor(100*b/S)}%`:`Exporting ${b.toLocaleString()} rows`}});f&&(a.disabled=!0,a.setAttribute("aria-busy","true"),f.catch(()=>{}).finally(()=>{a.disabled=!1,a.removeAttribute("aria-busy"),a.textContent=o}))}),p}
12
+ `,t.head.appendChild(r)}function c(t,r,n,l){const s=t.createElement(r);return n&&Object.assign(s.style,n),l!==void 0&&(s.textContent=l),s}function te(t){return D(t)?String(t.x):""}function ne(t){return D(t)?String(t.y):""}function le(t,r){return r!==void 0?r.filter(n=>n.testNumber!==void 0):G(t,"values").map(n=>({testNumber:n,name:L(void 0,n)}))}function re(t,r,n){if(!r)return[];const l=K(n,"the die list"),s=[];for(const v of P){const p=O[v],u=i=>({wafer:r(i),ringCount:l});if(!t.some(i=>M(i)&&p.valueOf(i,u(i))!==void 0))continue;const h=new Map,o=i=>{let e=h.get(i);return e===void 0&&(e=p.valueOf(i,u(i))??"",h.set(i,e)),e};s.push({label:p.label,get:o,...p.rawOf?{csvGet:i=>p.rawOf(i,u(i))??""}:{}})}return s}export function resolveDieColumns(t,r,n={}){const l=le(t,r),s=re(t,n.getWafer,n),v=t.some(e=>e.edgeExcluded===!0),p=[...n.extraColumn?[n.extraColumn.label]:[],"X","Y",...P.map(e=>O[e].label),"Edge excluded","Site","Hard bin","Soft bin",...l.map(e=>$(L(e,e.testNumber),e.unit))],{columns:u,truncatedKeys:h}=z({dies:t,waferMetadata:n.waferMetadata,metadataFields:n.metadataFields,dieKeys:n.metadataColumns,waferKeys:n.waferMetadataColumns==="none"?"none":void 0,waferPlacement:n.waferMetadataColumns??"csv",reservedLabels:p}),o=[...n.extraColumn?[{label:n.extraColumn.label,get:e=>n.extraColumn.get(e)??""}]:[],{label:"X",get:te},{label:"Y",get:ne},...s,...v?[{label:"Edge excluded",get:e=>e.edgeExcluded?"Yes":"No"}]:[],{label:"Site",get:e=>e.siteNum!==void 0?String(e.siteNum):""},{label:"Hard bin",get:e=>e.hbin!==void 0?String(e.hbin):""},{label:"Soft bin",get:e=>e.sbin!==void 0?String(e.sbin):""},...l.map(e=>{const y=!_(e);return{test:e,label:$(H(e,e.testNumber),e.unit),...Q(e)?{csvLabel:`${$(L(e,e.testNumber),e.unit)} [derived from ${J(e)??Z}]`}:{},get:d=>{if(y){const m=E(d,e.testNumber,e);return m===void 0?"":m?"PASS":"FAIL"}const x=T(d,e.testNumber);if(x!==void 0)return U(x,e.unit);const C=E(d,e.testNumber,e);return C===void 0?"":C?"PASS":"FAIL"},csvGet:d=>{if(y){const m=E(d,e.testNumber,e);return m===void 0?"":m?"PASS":"FAIL"}const x=T(d,e.testNumber);if(x!==void 0)return x;const C=E(d,e.testNumber,e);return C===void 0?"":C?"PASS":"FAIL"}}}),...u.map(e=>({label:e.label,get:e.get,csvOnly:e.csvOnly}))],i=o.filter(e=>!e.csvOnly);return{columns:o,visibleColumns:i,testColumns:l,truncatedKeys:h}}export function buildDieListSection(t,r,n={}){if(!t.length)return null;const l=n.ownerDocument??document;ensureStylesInjected(l);const s=n.maxRows??ee,v=Math.max(0,t.length-s),p=v>0?t.slice(0,s):t,u=c(l,"div",{display:"flex",flexDirection:"column",gap:V.md,flex:"1",minHeight:"0",minWidth:"0"}),h=c(l,"div",{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:"0"});h.appendChild(c(l,"div",{fontSize:w.meta,fontWeight:"700",letterSpacing:B,textTransform:"uppercase",color:f.label},n.title??`Die list (${t.length})`));const o=c(l,"button",{fontSize:w.body,padding:"3px 8px",borderRadius:k.control,...j("outlined"),background:f.menuBg},"Export CSV");o.type="button",W(o),h.appendChild(o),u.appendChild(h),n.note&&u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},n.note));const{columns:i,visibleColumns:e,testColumns:y,truncatedKeys:d}=resolveDieColumns(t,r,n),x=q(y.map(a=>({label:H(a,a.testNumber),...X(a)})));x&&u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},x));const C=c(l,"div",{overflow:"auto",flex:"1",minHeight:"0",minWidth:"0",border:`1px solid ${f.menuBorder}`,borderRadius:k.control,...n.maxHeight?{maxHeight:n.maxHeight}:{}}),m=l.createElement("table");m.className="wmap-dielist-table",m.setAttribute("aria-label",n.title??`Die list (${t.length} dies)`);const A=c(l,"thead"),I=c(l,"tr");for(const a of e){const b=l.createElement("th");b.className="wmap-dielist-th",b.scope="col",b.textContent=a.label,I.appendChild(b)}A.appendChild(I),m.appendChild(A);const R=c(l,"tbody");for(const a of p){const b=c(l,"tr");for(const g of e){const S=l.createElement("td");S.className="wmap-dielist-td",S.textContent=g.get(a),b.appendChild(S)}R.appendChild(b)}if(m.appendChild(R),C.appendChild(m),u.appendChild(C),v>0||d.length>0){const a=[];v>0&&a.push(`Showing the first ${s.toLocaleString()} of ${t.length.toLocaleString()} dies. The CSV export contains all ${t.length.toLocaleString()}.`),d.length>0&&a.push(`${d.length} further metadata field${d.length===1?"":"s"} not shown.`),u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},a.join(" ")))}return o.addEventListener("click",()=>{if(o.disabled)return;const a=o.textContent,b=Y(i.map(g=>({header:g.csvLabel??g.label,get:g.csvGet??g.get})),t,"die-list.csv",n.onSaveText,{onProgress:(g,S)=>{o.textContent=S?`Exporting ${Math.floor(100*g/S)}%`:`Exporting ${g.toLocaleString()} rows`}});b&&(o.disabled=!0,o.setAttribute("aria-busy","true"),b.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=a}))}),u}
@@ -1,10 +1,13 @@
1
1
  import type { Die } from '../core/dies.js';
2
+ import type { FacetCuration } from '../stats/facets.js';
2
3
  import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
3
4
  import type { DrilldownSource, DrilldownItem } from './chartPopulation.js';
4
5
  import type { PlotStore } from './plotStore.js';
5
6
  export type { DrilldownSource, DrilldownItem };
6
7
  /** What the targets can draw on — the host's chart definitions and hooks. */
7
8
  export interface DrilldownContext {
9
+ /** The host's own wafer attributes, so a plot opened on a selection offers and names them as Insights does. */
10
+ attributes?: Record<string, FacetCuration>;
8
11
  /** The reader's saved plots: each is a row in the menu, opened on the selection. */
9
12
  plots?: PlotStore;
10
13
  onSaveImage?: SaveImageHandler;
@@ -1 +1 @@
1
- import{isYieldEligibleDie as P}from"../core/dies.js";import{testValue as k}from"../core/dieTable.js";import{isParametricTest as C}from"../renderer/buildWaferMap.js";import{buildSweepData as x}from"../stats/sweep.js";import{plotToSweep as L}from"../stats/plotSpec.js";import{renderHistogramPanel as O}from"./charts/histogram.js";import{renderCapabilityPanel as W}from"./charts/capability.js";import{openChartExpandModal as A,populationPhrase as D}from"./charts/chartShell.js";import{buildCheckMenuEl as F,createToolbarHelpers as V,getTooltip as H,menuLayerFor as j,wireMenuA11y as q,CLR as z,FONT as B,SPACE as M,openReparentedModal as _,controlStyle as K,wireControlHover as U}from"./toolbar.js";import{requireRingCount as Y}from"../core/ringCount.js";import{defaultPlot as G,defaultSweep as J,fieldCatalogue as Q,plotTitle as X,resolvePlot as Z}from"../stats/plotData.js";import{newPlotId as y}from"../stats/plotSpec.js";import{sourceFromPoints as ee,toPlotItems as S}from"./plotItems.js";const E=30,g=e=>e.items.flatMap(t=>t.dies);function te(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>P(n))}))}function N(e,t,n){return(e.testDefs??[]).filter(C).map(l=>l.testNumber).filter(l=>{let o=0;for(const s of t){const u=k(s,l);if(u!==void 0&&Number.isFinite(u)&&++o>=n)return!0}return!1})}function $(e,t,n,l,o,s){const u=e.ownerDocument,a=u.createElement("div"),f=u.createElement("span");f.textContent=n,f.dataset.wmapPopulation="1",Object.assign(a.style,{color:z.label,fontSize:B.body,marginBottom:M.sm,display:"flex",alignItems:"center",gap:M.lg,flexWrap:"wrap"}),a.appendChild(f);let h=null;if(s){const c=u.createElement("button");c.type="button",c.textContent=s.label,c.dataset[s.hook]="1",Object.assign(c.style,K("outlined")),U(c),c.addEventListener("click",()=>s.run(()=>h?.close())),a.appendChild(c)}const i=e.querySelector("[data-wmap-chart-expand]")?.parentElement;i?.parentElement===e?i.after(a):e.prepend(a),h=A(e,t,{anchor:l,onClosed:o})}function ne(e,t){const n=g(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(o=>P(o))?x(n,t.testDefs,e).series.some(o=>o.points.some(s=>s.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function oe(e,t,n){const l=te(e),o=g(e).length,s=l.flatMap(r=>r.dies),u=D(s.length,o,e.population),a=(e.testDefs??[]).filter(C),f=n.ownerDocument,h=(r,p)=>e.notMeasuredReason?e.notMeasuredReason:s.length===0?"These dies are all partial or edge-excluded, which charts leave out":N(e,s,r).length>0?null:p,i={section:"Distributions",label:"Value histogram",unavailable:h(1,"These dies have no parametric test values"),open:()=>{let r=e.activeTest??a[0]?.testNumber;const p=O({title:"Value histogram",items:l,testDefs:a,selectedTestNumber:e.activeTest,onTestChange:m=>{r=m},onSaveImage:t.onSaveImage,ownerDocument:f}),d=I(e,t,n),b=d&&r!==void 0?{label:"Edit as new plot",hook:"wmapEditAsPlot",run:m=>{const w=a.find(v=>v.testNumber===r);m(),d({id:y(),chart:"histogram",fields:{y:{test:r,...w?.name?{name:w.name}:{}},color:{none:!0}}},!0)()}}:void 0;$(p.card,`Value histogram \u2014 ${u}`,`Population: ${u}`,n,()=>p.destroy(),b)}},c={section:"Distributions",label:"Process capability",unavailable:h(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const r=W({title:"Process capability",items:l,testDefs:a,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:f}),p=s.length<E?` \xB7 fewer than ${E} dies, so each Ppk is a rough estimate`:"";$(r.card,`Process capability \u2014 ${u}`,`Population: ${u}${p}`,n,()=>r.destroy())}};return[i,c]}function I(e,t,n){const l=t.plots;if(!l)return null;const o=n.ownerDocument,s=S(e.items),u={testDefs:e.testDefs},a=g(e),f=D(a.length,a.length,e.population),h=D(a.filter(i=>P(i)).length,a.length,e.population);return(i,c)=>()=>{const r=i.chart==="sweep",p=r?h:f;import("./plotModal.js").then(({openPlotEditor:d})=>d({doc:o,anchor:n,store:l,plot:i,draft:c,items:s,ctx:u,population:p,rawPopulation:e.population,title:`${c?r?"New sweep":"New plot":r?"Sweep":"Plot"} \u2014 ${p}`,chart:{onSaveImage:t.onSaveImage,onSelectPoints:(b,m,w)=>{const v=ee(b,s,e.testDefs);v&&openDrilldownMenu(m,w,v,t)}}}))}}function se(e,t,n){const l=t.plots,o=I(e,t,n);if(!l||!o)return[];const s=S(e.items),u={testDefs:e.testDefs},a=g(e),f=e.notMeasuredReason??(a.length===0?"Nothing is selected":null),h=l.get().map(p=>{const d=L(p);if(d)return{section:"Plots",label:d.title,unavailable:ne(d,e),open:o(p,!1)};const b=Z(p,s,u);return{section:"Plots",label:X(b)||"Plot",unavailable:f??b.issues[0]??(b.plotted===0?"No die here has the values this plot needs":null),open:o(p,!1)}}),i=Q(s,u),c=i.some(p=>p.group==="Tests");h.push({section:"Plots",label:"New plot\u2026",unavailable:f??(c?null:"These dies have no parametric test values"),open:o(G(i,y()),!0)});const r=(e.testDefs??[]).filter(p=>C(p));return h.push({section:"Plots",label:"New sweep\u2026",unavailable:f??(r.length>0?null:"These dies have no parametric test values"),open:o(J(e.testDefs??[],y()),!0)}),h}function le(e,t,n){const l=g(e),o=e.notMeasuredReason??(l.length===0?"Nothing is selected":null),s=l.length,u=D(s,s,e.population),a=(f,h)=>()=>{import("./dataTab.js").then(({renderSelectionTables:i})=>{const c=n.ownerDocument;let r;const p=i({doc:c,ringCount:Y(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:f,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(b,m)=>{r?.(),t.onLocateDie(b,m)}:void 0}),d=_([p.el],{title:`${h} \u2014 ${u}`,anchor:n,ownerDocument:c,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:p.destroy});d?r=()=>d.close():p.destroy()})};return[{section:"Tables",label:"Dies",unavailable:o,open:a("dies","Dies")},{section:"Tables",label:"Test statistics",unavailable:o??(N(e,l,1).length>0?null:"These dies have no parametric test values"),open:a("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:o,open:a("wafers","Wafers")}]:[]]}function ae(e,t,n){return[...oe(e,t,n),...se(e,t,n),...le(e,t,n)]}const T=new WeakMap;export function openDrilldownMenu(e,t,n,l){const o=t.ownerDocument,s=o.defaultView??window;T.get(o)?.();const u=ae(n,l,t),a=[];if(l.narrower){const{label:m,source:w,ctx:v}=l.narrower,R={label:`${l.narrower.backLabel??"All selected"} \u2014 ${D(g(n).length,g(n).length,n.population)}`,source:n,ctx:l};a.push({section:"Dies"}),a.push({label:m,active:!1,action:!0,enabled:!0,onClick:()=>{d(),openDrilldownMenu(e,t,w,{...v??l,narrower:R})}})}let f;for(const m of u)m.section!==f&&(a.push({section:m.section}),f=m.section),a.push({label:m.label,active:!1,action:!0,enabled:m.unavailable===null,disabledHint:m.unavailable??void 0,onClick:()=>{d(),m.open()}});const{makeMenuSection:h}=V(H(o)),i=F(new DOMRect(e.x,e.y-4,0,0),a,{makeMenuSection:h},s),c=g(n).length;i.setAttribute("role","menu"),i.setAttribute("aria-label",`Open a chart or table of ${D(c,c,n.population)}`),i.dataset.wmapDrilldownMenu="1",j(t).appendChild(i);const r=i.getBoundingClientRect();r.bottom>s.innerHeight-4&&(i.style.top=`${Math.max(4,e.y-r.height)}px`),r.right>s.innerWidth-4&&(i.style.left=`${Math.max(4,s.innerWidth-r.width-4)}px`);let p=!1;function d(){p||(p=!0,i.remove(),o.removeEventListener("pointerdown",b,!0),s.removeEventListener("blur",d),T.get(o)===d&&T.delete(o))}function b(m){i.contains(m.target)||d()}return o.addEventListener("pointerdown",b,!0),s.addEventListener("blur",d),q(i,t,d),T.set(o,d),d}
1
+ import{isYieldEligibleDie as P}from"../core/dies.js";import{testValue as k}from"../core/dieTable.js";import{isParametricTest as C}from"../renderer/buildWaferMap.js";import{buildSweepData as L}from"../stats/sweep.js";import{plotToSweep as x}from"../stats/plotSpec.js";import{renderHistogramPanel as O}from"./charts/histogram.js";import{renderCapabilityPanel as W}from"./charts/capability.js";import{openChartExpandModal as A,populationPhrase as D}from"./charts/chartShell.js";import{buildCheckMenuEl as F,createToolbarHelpers as V,getTooltip as H,menuLayerFor as j,wireMenuA11y as q,CLR as z,FONT as B,SPACE as M,openReparentedModal as _,controlStyle as K,wireControlHover as U}from"./toolbar.js";import{requireRingCount as Y}from"../core/ringCount.js";import{defaultPlot as G,defaultSweep as J,fieldCatalogue as Q,plotTitle as X,resolvePlot as Z}from"../stats/plotData.js";import{newPlotId as y}from"../stats/plotSpec.js";import{sourceFromPoints as ee,toPlotItems as S}from"./plotItems.js";const E=30,g=e=>e.items.flatMap(t=>t.dies);function te(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>P(n))}))}function N(e,t,n){return(e.testDefs??[]).filter(C).map(a=>a.testNumber).filter(a=>{let o=0;for(const s of t){const d=k(s,a);if(d!==void 0&&Number.isFinite(d)&&++o>=n)return!0}return!1})}function $(e,t,n,a,o,s){const d=e.ownerDocument,l=d.createElement("div"),f=d.createElement("span");f.textContent=n,f.dataset.wmapPopulation="1",Object.assign(l.style,{color:z.label,fontSize:B.body,marginBottom:M.sm,display:"flex",alignItems:"center",gap:M.lg,flexWrap:"wrap"}),l.appendChild(f);let h=null;if(s){const c=d.createElement("button");c.type="button",c.textContent=s.label,c.dataset[s.hook]="1",Object.assign(c.style,K("outlined")),U(c),c.addEventListener("click",()=>s.run(()=>h?.close())),l.appendChild(c)}const i=e.querySelector("[data-wmap-chart-expand]")?.parentElement;i?.parentElement===e?i.after(l):e.prepend(l),h=A(e,t,{anchor:a,onClosed:o})}function ne(e,t){const n=g(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(o=>P(o))?L(n,t.testDefs,e).series.some(o=>o.points.some(s=>s.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function oe(e,t,n){const a=te(e),o=g(e).length,s=a.flatMap(r=>r.dies),d=D(s.length,o,e.population),l=(e.testDefs??[]).filter(C),f=n.ownerDocument,h=(r,p)=>e.notMeasuredReason?e.notMeasuredReason:s.length===0?"These dies are all partial or edge-excluded, which charts leave out":N(e,s,r).length>0?null:p,i={section:"Distributions",label:"Value histogram",unavailable:h(1,"These dies have no parametric test values"),open:()=>{let r=e.activeTest??l[0]?.testNumber;const p=O({title:"Value histogram",items:a,testDefs:l,selectedTestNumber:e.activeTest,onTestChange:m=>{r=m},onSaveImage:t.onSaveImage,ownerDocument:f}),u=I(e,t,n),b=u&&r!==void 0?{label:"Edit as new plot",hook:"wmapEditAsPlot",run:m=>{const w=l.find(v=>v.testNumber===r);m(),u({id:y(),chart:"histogram",fields:{y:{test:r,...w?.name?{name:w.name}:{}},color:{none:!0}}},!0)()}}:void 0;$(p.card,`Value histogram \u2014 ${d}`,`Population: ${d}`,n,()=>p.destroy(),b)}},c={section:"Distributions",label:"Process capability",unavailable:h(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const r=W({title:"Process capability",items:a,testDefs:l,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:f}),p=s.length<E?` \xB7 fewer than ${E} dies, so each Ppk is a rough estimate`:"";$(r.card,`Process capability \u2014 ${d}`,`Population: ${d}${p}`,n,()=>r.destroy())}};return[i,c]}function I(e,t,n){const a=t.plots;if(!a)return null;const o=n.ownerDocument,s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=D(l.length,l.length,e.population),h=D(l.filter(i=>P(i)).length,l.length,e.population);return(i,c)=>()=>{const r=i.chart==="sweep",p=r?h:f;import("./plotModal.js").then(({openPlotEditor:u})=>u({doc:o,anchor:n,store:a,plot:i,draft:c,items:s,ctx:d,population:p,rawPopulation:e.population,title:`${c?r?"New sweep":"New plot":r?"Sweep":"Plot"} \u2014 ${p}`,chart:{onSaveImage:t.onSaveImage,onSelectPoints:(b,m,w)=>{const v=ee(b,s,e.testDefs);v&&openDrilldownMenu(m,w,v,t)}}}))}}function se(e,t,n){const a=t.plots,o=I(e,t,n);if(!a||!o)return[];const s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=e.notMeasuredReason??(l.length===0?"Nothing is selected":null),h=a.get().map(p=>{const u=x(p);if(u)return{section:"Plots",label:u.title,unavailable:ne(u,e),open:o(p,!1)};const b=Z(p,s,d);return{section:"Plots",label:X(b)||"Plot",unavailable:f??b.issues[0]??(b.plotted===0?"No die here has the values this plot needs":null),open:o(p,!1)}}),i=Q(s,d),c=i.some(p=>p.group==="Tests");h.push({section:"Plots",label:"New plot\u2026",unavailable:f??(c?null:"These dies have no parametric test values"),open:o(G(i,y()),!0)});const r=(e.testDefs??[]).filter(p=>C(p));return h.push({section:"Plots",label:"New sweep\u2026",unavailable:f??(r.length>0?null:"These dies have no parametric test values"),open:o(J(e.testDefs??[],y()),!0)}),h}function ae(e,t,n){const a=g(e),o=e.notMeasuredReason??(a.length===0?"Nothing is selected":null),s=a.length,d=D(s,s,e.population),l=(f,h)=>()=>{import("./dataTab.js").then(({renderSelectionTables:i})=>{const c=n.ownerDocument;let r;const p=i({doc:c,ringCount:Y(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:f,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(b,m)=>{r?.(),t.onLocateDie(b,m)}:void 0}),u=_([p.el],{title:`${h} \u2014 ${d}`,anchor:n,ownerDocument:c,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:p.destroy});u?r=()=>u.close():p.destroy()})};return[{section:"Tables",label:"Dies",unavailable:o,open:l("dies","Dies")},{section:"Tables",label:"Test statistics",unavailable:o??(N(e,a,1).length>0?null:"These dies have no parametric test values"),open:l("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:o,open:l("wafers","Wafers")}]:[]]}function le(e,t,n){return[...oe(e,t,n),...se(e,t,n),...ae(e,t,n)]}const T=new WeakMap;export function openDrilldownMenu(e,t,n,a){const o=t.ownerDocument,s=o.defaultView??window;T.get(o)?.();const d=le(n,a,t),l=[];if(a.narrower){const{label:m,source:w,ctx:v}=a.narrower,R={label:`${a.narrower.backLabel??"All selected"} \u2014 ${D(g(n).length,g(n).length,n.population)}`,source:n,ctx:a};l.push({section:"Dies"}),l.push({label:m,active:!1,action:!0,enabled:!0,onClick:()=>{u(),openDrilldownMenu(e,t,w,{...v??a,narrower:R})}})}let f;for(const m of d)m.section!==f&&(l.push({section:m.section}),f=m.section),l.push({label:m.label,active:!1,action:!0,enabled:m.unavailable===null,disabledHint:m.unavailable??void 0,onClick:()=>{u(),m.open()}});const{makeMenuSection:h}=V(H(o)),i=F(new DOMRect(e.x,e.y-4,0,0),l,{makeMenuSection:h},s),c=g(n).length;i.setAttribute("role","menu"),i.setAttribute("aria-label",`Open a chart or table of ${D(c,c,n.population)}`),i.dataset.wmapDrilldownMenu="1",j(t).appendChild(i);const r=i.getBoundingClientRect();r.bottom>s.innerHeight-4&&(i.style.top=`${Math.max(4,e.y-r.height)}px`),r.right>s.innerWidth-4&&(i.style.left=`${Math.max(4,s.innerWidth-r.width-4)}px`);let p=!1;function u(){p||(p=!0,i.remove(),o.removeEventListener("pointerdown",b,!0),s.removeEventListener("blur",u),T.get(o)===u&&T.delete(o))}function b(m){i.contains(m.target)||u()}return o.addEventListener("pointerdown",b,!0),s.addEventListener("blur",u),q(i,t,u),T.set(o,u),u}
@@ -1,9 +1,12 @@
1
1
  import type { WaferMetadata } from '../core/metadata.js';
2
+ import { type FacetCuration } from '../stats/facets.js';
2
3
  export interface IdentityHeaderLotStack {
3
4
  lotSize: number;
4
5
  aggrMethod?: string;
5
6
  }
6
7
  export interface IdentityHeaderOptions {
8
+ /** The host's own wafer attributes (`attributes` on the render options): what each field is called. */
9
+ attributes?: Record<string, FacetCuration>;
7
10
  /** Present when the host result is a lot-stack aggregation rather than a
8
11
  * single wafer — the metadata panel then leads with wafer count + method
9
12
  * instead of a (nonexistent) single waferId. */
@@ -56,7 +59,7 @@ export declare function createMetaPanelEl(doc: Document): HTMLDivElement;
56
59
  * wafer has no metadata to show. The fixed-label counterpart of
57
60
  * `createIdentityHeader`, for views whose label never changes.
58
61
  */
59
- export declare function attachExpandableMetadata(doc: Document, toggleEl: HTMLElement, label: string, metadata: WaferMetadata | null | undefined): HTMLDivElement | null;
62
+ export declare function attachExpandableMetadata(doc: Document, toggleEl: HTMLElement, label: string, metadata: WaferMetadata | null | undefined, attributes?: Record<string, FacetCuration>): HTMLDivElement | null;
60
63
  export declare function collapsedLabel(meta: WaferMetadata, lotStack: IdentityHeaderLotStack | undefined): string | undefined;
61
64
  export declare function createIdentityHeader(label: string, metadata: WaferMetadata | null | undefined, opts?: IdentityHeaderOptions): IdentityHeaderController;
62
65
  //# sourceMappingURL=identityHeader.d.ts.map
@@ -1 +1 @@
1
- import{metadataEntries as v,buildCompactMetadataRows as $}from"./summaryPanel.js";import{prettyKey as M}from"../stats/facets.js";import{SHADOW as j,LEADING as E,SPACE as C,FONT as g,CLR as x,RADIUS as L,Z_ABOVE as H,wireExpandToggle as z,wireControlHover as P}from"./toolbar.js";export function createMetaPanelEl(i){const e=i.createElement("div");return Object.assign(e.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:H,background:x.menuBg,borderBottom:`1px solid ${x.menuBorder}`,boxShadow:j.menu,padding:`${C.md} ${C.lg}`,fontSize:g.body,display:"none"}),e}export function attachExpandableMetadata(i,e,s,t){const d=t??{};if(v(d).length===0)return null;const a=i.createElement("span");Object.assign(a.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0"}),a.textContent="\u25BE",e.appendChild(a),Object.assign(e.style,{cursor:"pointer",borderRadius:L.control}),P(e,"bare");const r=createMetaPanelEl(i);r.dataset.wmapCardMetaPanel="1";const c=$(d);return c&&r.appendChild(c),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-label",`Wafer info for ${s||"this card"}. Click to expand.`),z(e,o=>{a.textContent=o?"\u25B4":"\u25BE",e.setAttribute("aria-expanded",String(o)),r.style.display=o?"block":"none"}),r}export function collapsedLabel(i,e){if(e)return e.aggrMethod?`${e.lotSize} wafers \xB7 ${e.aggrMethod}`:`${e.lotSize} wafers`;if(i.lot&&i.waferId!==void 0&&i.waferId!==""){const s=String(i.lot),t=String(i.waferId);return t.includes(s)?t:`${s} \xB7 ${t}`}for(const s of["lot","waferId","product","testProgram"]){const t=i[s];if(t!=null&&t!=="")return String(t)}}export function createIdentityHeader(i,e,s={}){let t=i,d=e??{},a=s.lotStack,r=!1,c=!1;const o=s.ownerDocument??document,n=o.createElement("div");Object.assign(n.style,{display:"flex",alignItems:"center",gap:C.xs,minWidth:"0"});const h=o.createElement("span");Object.assign(h.style,{fontWeight:"700",fontSize:g.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),n.appendChild(h);const w=o.createElement("span");Object.assign(w.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0",display:"none"}),n.appendChild(w);const A=4,p=o.createElement("span");Object.assign(p.style,{fontSize:g.body,color:x.label,whiteSpace:"nowrap",overflow:"hidden",flexShrink:"0",display:"none",marginLeft:C.sm}),n.appendChild(p);const f=createMetaPanelEl(o);f.dataset.wmapMetaPanel="1";function S(){return v(d).length>0||!!a}function I(){return a?[]:v(d).filter(([,l])=>!t.includes(l))}function W(){return n.clientWidth?h.scrollWidth>h.clientWidth||p.scrollWidth>p.clientWidth||n.scrollWidth>n.clientWidth:!0}function m(){h.textContent=t;const l=I();p.textContent=l.map(([b,y])=>`${M(b)}: ${y}`).join(" \xB7 "),p.style.display=l.length>0?"":"none",c=l.length>0&&l.length<=A&&!W(),p.style.display=c?"":"none";const u=S()&&!c;if(w.style.display=u?"":"none",n.style.cursor=u?"pointer":"",u||(r=!1),w.textContent=r?"\u25B4":"\u25BE",f.style.display=r?"block":"none",u?(n.setAttribute("aria-expanded",String(r)),n.setAttribute("aria-label",`Wafer info: ${t||"this wafer"}. ${r?"Click to collapse.":"Click to expand."}`)):(n.removeAttribute("aria-expanded"),n.removeAttribute("aria-label")),f.innerHTML="",r){if(a){const y=o.createElement("div");Object.assign(y.style,{fontWeight:"600",marginBottom:"3px"}),y.textContent=a.aggrMethod?`${a.lotSize} wafers stacked \xB7 ${a.aggrMethod}`:`${a.lotSize} wafers stacked`,f.appendChild(y)}const b=$(d);b&&f.appendChild(b)}}const k=z(n,l=>{!S()||c||(r=l,m())});m();const O=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>m());return O?.observe(n),{wrap:n,metaPanel:f,update(l,u,b){t=l,d=u??{},a=b,m()},isEmpty(){return!t&&!S()},collapse(){r&&(r=!1,m())},destroy(){O?.disconnect(),k.destroy(),n.remove(),f.remove()}}}
1
+ import{metadataEntries as v,buildCompactMetadataRows as $}from"./summaryPanel.js";import{attributeLabel as M}from"../stats/facets.js";import{SHADOW as L,LEADING as E,SPACE as C,FONT as g,CLR as x,RADIUS as j,Z_ABOVE as H,wireExpandToggle as z,wireControlHover as P}from"./toolbar.js";export function createMetaPanelEl(i){const t=i.createElement("div");return Object.assign(t.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:H,background:x.menuBg,borderBottom:`1px solid ${x.menuBorder}`,boxShadow:L.menu,padding:`${C.md} ${C.lg}`,fontSize:g.body,display:"none"}),t}export function attachExpandableMetadata(i,t,a,n,p){const o=n??{};if(v(o).length===0)return null;const r=i.createElement("span");Object.assign(r.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0"}),r.textContent="\u25BE",t.appendChild(r),Object.assign(t.style,{cursor:"pointer",borderRadius:j.control}),P(t,"bare");const s=createMetaPanelEl(i);s.dataset.wmapCardMetaPanel="1";const d=$(o,p);return d&&s.appendChild(d),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-label",`Wafer info for ${a||"this card"}. Click to expand.`),z(t,e=>{r.textContent=e?"\u25B4":"\u25BE",t.setAttribute("aria-expanded",String(e)),s.style.display=e?"block":"none"}),s}export function collapsedLabel(i,t){if(t)return t.aggrMethod?`${t.lotSize} wafers \xB7 ${t.aggrMethod}`:`${t.lotSize} wafers`;if(i.lot&&i.waferId!==void 0&&i.waferId!==""){const a=String(i.lot),n=String(i.waferId);return n.includes(a)?n:`${a} \xB7 ${n}`}for(const a of["lot","waferId","product","testProgram"]){const n=i[a];if(n!=null&&n!=="")return String(n)}}export function createIdentityHeader(i,t,a={}){let n=i,p=t??{},o=a.lotStack,r=!1,s=!1;const d=a.ownerDocument??document,e=d.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",gap:C.xs,minWidth:"0"});const h=d.createElement("span");Object.assign(h.style,{fontWeight:"700",fontSize:g.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),e.appendChild(h);const w=d.createElement("span");Object.assign(w.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0",display:"none"}),e.appendChild(w);const A=4,c=d.createElement("span");Object.assign(c.style,{fontSize:g.body,color:x.label,whiteSpace:"nowrap",overflow:"hidden",flexShrink:"0",display:"none",marginLeft:C.sm}),e.appendChild(c);const f=createMetaPanelEl(d);f.dataset.wmapMetaPanel="1";function S(){return v(p).length>0||!!o}function I(){return o?[]:v(p).filter(([,l])=>!n.includes(l))}function W(){return e.clientWidth?h.scrollWidth>h.clientWidth||c.scrollWidth>c.clientWidth||e.scrollWidth>e.clientWidth:!0}function m(){h.textContent=n;const l=I();c.textContent=l.map(([b,y])=>`${M(b,a.attributes)}: ${y}`).join(" \xB7 "),c.style.display=l.length>0?"":"none",s=l.length>0&&l.length<=A&&!W(),c.style.display=s?"":"none";const u=S()&&!s;if(w.style.display=u?"":"none",e.style.cursor=u?"pointer":"",u||(r=!1),w.textContent=r?"\u25B4":"\u25BE",f.style.display=r?"block":"none",u?(e.setAttribute("aria-expanded",String(r)),e.setAttribute("aria-label",`Wafer info: ${n||"this wafer"}. ${r?"Click to collapse.":"Click to expand."}`)):(e.removeAttribute("aria-expanded"),e.removeAttribute("aria-label")),f.innerHTML="",r){if(o){const y=d.createElement("div");Object.assign(y.style,{fontWeight:"600",marginBottom:"3px"}),y.textContent=o.aggrMethod?`${o.lotSize} wafers stacked \xB7 ${o.aggrMethod}`:`${o.lotSize} wafers stacked`,f.appendChild(y)}const b=$(p,a.attributes);b&&f.appendChild(b)}}const k=z(e,l=>{!S()||s||(r=l,m())});m();const O=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>m());return O?.observe(e),{wrap:e,metaPanel:f,update(l,u,b){n=l,p=u??{},o=b,m()},isEmpty(){return!n&&!S()},collapse(){r&&(r=!1,m())},destroy(){O?.disconnect(),k.destroy(),e.remove(),f.remove()}}}
@@ -1,7 +1,7 @@
1
1
  import type { Die } from '../core/dies.js';
2
2
  import type { Wafer } from '../core/wafer.js';
3
3
  import type { LotStatsSummary, StatsSummary } from '../stats/types.js';
4
- import { type FacetItem } from '../stats/facets.js';
4
+ import { type FacetCuration, type FacetItem } from '../stats/facets.js';
5
5
  import { type TestDef } from '../renderer/buildWaferMap.js';
6
6
  import type { WaferMapDisplayItem } from './renderWaferGallery.js';
7
7
  import { type PlotStore } from './plotStore.js';
@@ -83,6 +83,8 @@ export interface InsightsOptions {
83
83
  defaultOpen?: boolean;
84
84
  }
85
85
  export interface InsightsTabDeps {
86
+ /** The host's own wafer attributes (`attributes` on the render options): what Group by offers and calls each, the plot fields, the Wafers table's columns and the strip. Over the defaults. */
87
+ attributes?: Record<string, FacetCuration>;
86
88
  /** Current gallery/single-wafer items — read fresh each render (a gallery's list can still be building). `null` entries (not-yet-built cards) are skipped. */
87
89
  getItems: () => Array<WaferMapDisplayItem | null>;
88
90
  /** Precomputed lot-level yield, when the host has one — reused directly instead of recomputing (see stats/yield.ts). Omit when there is no lot (e.g. a single wafer). */
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as Ue}from"../stats/presentation.js";import{buildFacetTable as qe,facetValueOf as Ke,FACET_NONE_VALUE as Qe}from"../stats/facets.js";import{mergeTestDefs as he}from"../stats/mergeTestDefs.js";import{isParametricTest as we}from"../renderer/buildWaferMap.js";import{dieFailsTest as Xe}from"../stats/testPassRate.js";import{fmt as Ce}from"../renderer/fmt.js";import{testLabel as Je}from"../renderer/testLabel.js";import{waferDisplayLabel as Ze,waferIdentityLabel as et}from"../core/waferLabel.js";import{waferPopulation as tt}from"./chartPopulation.js";import{openDrilldownMenu as se}from"./drilldown.js";import{plotStoreFor as nt}from"./plotStore.js";import{itemPassBins as ot,passBinsLabel as Se}from"../core/passBins.js";import{NO_DATA_FILL as xe}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as rt}from"../stats/population.js";import{LEADING as it,ALPHA as st,SPACE as x,EDGE_GUTTER as le,FONT as M,CLR as B,RADIUS as lt,SHADOW as dt,controlStyle as ct,wireControlHover as de,wireTooltip as pt}from"./toolbar.js";import{ICONS as ut}from"./icons.js";import{renderCapabilityPanel as ft}from"./charts/capability.js";import{renderBoxplotPanel as mt}from"./charts/boxplot.js";import{renderTrendPanel as bt}from"./charts/trend.js";import{renderHistogramPanel as gt}from"./charts/histogram.js";import{renderCorrelationPanel as yt}from"./charts/correlation.js";import{renderScatterPanel as ht}from"./charts/scatter.js";import{renderBarPanel as ke}from"./charts/barPanel.js";import{renderBinClusterPanel as wt}from"./charts/binCluster.js";import{renderTestPassRatePanel as Ct}from"./charts/testPassRate.js";import{QUANTITY as St}from"./charts/palette.js";import{cardFrameStyle as xt,makeChartGridWrap as ce,makeLabeledSelect as kt,makeLinkedGroupSelect as vt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as ve}from"../stats/yield.js";import{buildBinParetoData as Tt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as Dt,buildLotFunctionalSection as Bt,buildMetadataStripBox as $t}from"./summaryPanel.js";import{runChunked as Lt}from"./chunked.js";import{buildRegionYieldData as Te,buildRingRegions as De,buildQuadrantRegions as Be,diesInRegion as It}from"../stats/regions.js";import{renderDataSection as Et}from"./dataTab.js";import{sourceFromDies as Pt}from"./plotItems.js";import{renderRegionYieldDiagram as $e}from"./charts/regionYieldDiagram.js";const Ot=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],At={key:"data",label:"Data"},Rt={key:"plot",label:"Plot"};export function createInsightsTab($){const{getItems:Le,getLotStats:pe,getBinColors:ue,getRingCount:F,onSaveImage:k,onSaveText:A,openWafer:R,focusTest:Z,locateDie:_}=$,Ie=$.showMetadataStrip??!0,z=$.contentInset??le,m=$.ownerDocument??document,N=m.createElement("div");Object.assign(N.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Ee=le,Y=m.createElement("div");Object.assign(Y.style,{paddingLeft:Ee});const E=m.createElement("div");Object.assign(E.style,{display:"flex",gap:x.xs,alignItems:"center",background:B.menuBg,border:`1px solid ${B.menuBorder}`,borderRadius:lt.container,boxShadow:dt.panel,padding:`0 ${x.lg}`,marginBottom:x.lg,marginLeft:z,marginRight:z}),E.setAttribute("role","tablist"),E.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(E.querySelectorAll('[role="tab"]')),a=n.indexOf(m.activeElement);if(a===-1)return;e.preventDefault();const d=n[(a+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];d.focus(),d.click()});const U=m.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:x.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),N.appendChild(Y),N.appendChild(E),N.appendChild(U);const Pe=[...Ot,At,Rt],q=$.plotStore??nt($);let L=$.defaultView==="sweeps"?"plot":$.defaultView??"overview",W,fe="statistics",me="wide",P=null,O=null,K={includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,be=(e,n)=>{K=e;for(const a of ee.values())for(const d of a)d!==n&&d.setAxisPrefs(e)},te=e=>{O!==e&&(O=e,G())};let j=new Map;function ge(){for(const e of j.values())e.destroy();j=new Map}function ne(e,n,a){R?.(e,n,a)}function oe(e){return(n,a,d)=>{const r=e.find(p=>p.waferIndex===n);if(!r)return;d.preventDefault();const f=tt(r.dies,{waferLabel:r.identity,testDefs:r.testDefs,activeTest:a??P??void 0,waferIndex:n,wafer:r.wafer,passBins:r.passBins,ringCount:F()});se({x:d.clientX,y:d.clientY},d.target,f,{plots:q,onSaveImage:k,onSaveText:A,onLocateDie:_})}}function Q(e,n,a,d,r){ye({x:e.clientX,y:e.clientY},e.target,n,a,d,r)}function ye(e,n,a,d,r,f){const p=Pt(a.map(l=>({label:l.identity??l.label,dies:l.dies,waferIndex:l.waferIndex,wafer:l.wafer,passBins:l.passBins,ringCount:F()})),d,r,he(a).defs,f);p&&se(e,n,p,{plots:q,onSaveImage:k,onSaveText:A,onLocateDie:_})}function ae(e){return R?{open:(n,a)=>ne(n,`Wafer ${e.find(d=>d.waferIndex===n)?.label??n}`,a)}:Z&&e.length===1?{open:(n,a)=>Z(a),label:"show this test on the map"}:null}function Oe(){return Le().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Ze(e,n),identity:et(e),waferIndex:n,passBins:ot(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Ae(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${B.iconActive}`:"2px solid transparent",color:n?B.iconActive:B.label,fontWeight:n?"700":"500",fontSize:M.body,padding:`${x.sm} ${le} ${x.md}`,cursor:"pointer",marginBottom:"-1px"})}function Re(e,n){const a=m.createElement("button");a.type="button",a.textContent=n;const d=e===L;return Ae(a,d),a.dataset.on=d?"true":"false",de(a,"bare"),a.dataset.wmapInsightsTab=e,a.setAttribute("role","tab"),a.setAttribute("aria-selected",d?"true":"false"),a.tabIndex=d?0:-1,a.addEventListener("click",()=>{L!==e&&(L=e,G({keepSections:!0}))}),a}function We(e,n,a,d=!0){const r=ce(m),f=ue();let p="label";const l=a??"group",y=Se(e.map(u=>u.passBins)),c=pe?.(),b=new Map(c?.lotYieldSeries.map(u=>[u.waferIndex,u.yieldPercent])),s=u=>({...u,label:u.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:b.get(u.waferIndex),key:u.waferIndex}),g=e.map(s),h=n?.map(u=>({key:u.key,items:u.items.map(s)})),i=()=>h?ve(h,p):J(g,p),t={title:n?`Yield by ${l} (pass: ${y})`:`Yield by wafer (pass: ${y})`,data:i(),selfControl:{current:p,options:[["yield","Sort: yield"],["label",n?`Sort: ${l}`:"Sort: wafer ID"]],onChange:u=>(p=u,{data:i()})},barColor:()=>St,valueLabel:u=>`${u.percent.toFixed(1)}%`,reference:u=>{if(u.length<3)return null;const C=u.map(I=>I.percent).sort((I,V)=>I-V),D=C.length%2?C[(C.length-1)/2]:(C[C.length/2-1]+C[C.length/2])/2;return{value:D,label:`median ${D.toFixed(1)}%`}},drill:h?{onOpenGroup:u=>{const C=h.find(D=>D.key===u.label)?.items??[];return{data:J(C,p),title:`Yield by wafer \u2014 ${l}: ${u.label} (pass: ${y})`}},onBack:()=>({data:i(),title:`Yield by ${l} (pass: ${y})`}),groupLabelText:l}:void 0,onOpen:R?u=>{typeof u.key=="number"&&ne(u.key,`Wafer ${u.label}`)}:void 0,onWaferContextMenu:oe(e),ownerDocument:m};let o=null;if(d&&(o=ke(t,k),o.card.style.minHeight="360px",r.appendChild(o.card)),n){const u=wt({title:"Hard bin pareto",groups:n.map(C=>({key:C.key,items:C.items.map(D=>({dies:D.dies,hardBinCounts:D.statsSummary?.stats.hardBinCounts,softBinCounts:D.statsSummary?.stats.softBinCounts}))})),onSelectBin:(C,D)=>{const I=n.find(X=>X.key===C.groupKey);if(!I)return;const V=C.binType==="hbin"?"hard":"soft";Q(D,I.items,`in ${V} bin ${C.bin} of ${C.groupKey}`,X=>(C.binType==="hbin"?X.hbin:X.sbin)===C.bin)},onSaveImage:k,ownerDocument:m});return u.card.style.minHeight="360px",r.appendChild(u.card),{card:r,destroy:()=>{o?.destroy(),u.destroy()}}}let w="hbin";const S=u=>u===void 0?xe:(w==="hbin"?f.hard:f.soft).get(u)??xe,v=e.map(u=>({dies:u.dies,hardBinCounts:u.statsSummary?.stats.hardBinCounts,softBinCounts:u.statsSummary?.stats.softBinCounts})),H=()=>Tt(v,w),ie={title:"Hard bin pareto",data:H(),selfControl:{current:w,options:[["hbin","Hard bins"],["sbin","Soft bins"]],onChange:u=>(w=u,{data:H(),title:`${w==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:u=>S(u.binCode),onSelectBar:(u,C)=>{const D=w==="hbin"?"hard":"soft",I=u.binCode;Q(C,e,I===void 0?`with no ${D} bin recorded`:`in ${D} bin ${I}`,V=>(w==="hbin"?V.hbin:V.sbin)===I)},selectLabel:"chart or tabulate its dies",ownerDocument:m},T=ke(ie,k);return T.card.style.minHeight="360px",r.appendChild(T.card),{card:r,destroy:()=>{o?.destroy(),T.destroy()}}}function re(){const e=m.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...xt(),display:"flex",flexDirection:"column",gap:x.lg,minWidth:"0"}),e}function Me(e){if(Y.innerHTML="",Y.style.marginBottom="0",!Ie)return;const n=$t(e.map(a=>({metadata:a.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",Y.appendChild(n),Y.style.marginBottom=x.xs)}function Fe(e,n,a,d){if(!e.length)return{elements:[],destroy:()=>{}};const r=e.map(i=>i.wafer),f=e.map(i=>i.dies),p=F(),l=[],y=[],b=Ct({groups:(d??[{key:"",items:e}]).map(i=>({key:i.key,items:i.items.map(t=>({dies:t.dies,testSpecYield:t.statsSummary?.stats.testSpecYield,functionalYield:t.statsSummary?.stats.functionalYield}))})),testDefs:a,onSaveImage:k,onSelectTest:(i,t)=>{const o=a.find(w=>w.testNumber===i.testNumber);o&&Q(t,e,`failing ${i.label}`,w=>Xe(w,o,i.kind)===!0,we(o)?i.testNumber:void 0)},ownerDocument:m});b.card.style.minHeight="300px",l.push(b.card),y.push(b.destroy);const s=i=>(t,o)=>{const w=new Set;for(const S of e)for(const v of It(S.dies,S.wafer,p,t.key,i))w.add(v);Q(o,e,`in ${t.label}`,S=>w.has(S))},g=Te(f,r,p,i=>e[i].passBins,De);if(g.length){const i=$e({title:"Ring yield",mode:"ring",rows:g,onSelectRegion:s(De),onSaveImage:k,ownerDocument:m});l.push(i.card),y.push(i.destroy)}const h=Te(f,r,p,i=>e[i].passBins,Be);if(h.length){const i=$e({title:"Quadrant yield",mode:"quadrant",rows:h,onSelectRegion:s(Be),onSaveImage:k,ownerDocument:m});l.push(i.card),y.push(i.destroy)}return{elements:l,destroy:()=>{for(const i of y)i()}}}function Ne(e,n,a){if(!e.length)return{cards:[],destroy:()=>{}};const d=e.map(s=>s.dies),r=e.flatMap(s=>s.dies),f=e.map(s=>s.statsSummary),p=f.every(s=>s!==void 0)?f:void 0,l=[],y=[];let c=null;if(n.length){const s=re();let g=null;const h=Lt(Dt(r,n,void 0,p,A,d.map(i=>({dies:i})),void 0,"full"),{onDone:i=>{g=i,s.removeAttribute("aria-busy"),i?s.replaceChildren(i):s.remove()}});if(h.done)g&&(c=s);else{const i=m.createElement("div");i.textContent="Computing test statistics\u2026",Object.assign(i.style,{color:B.label,fontSize:M.body}),s.setAttribute("aria-busy","true"),s.appendChild(i),c=s,l.push(()=>h.cancel())}}let b=null;if(a.length){const s=Bt(r,a,p,A);if(s){const g=re();g.appendChild(s),b=g}}return c&&y.push(c),b&&y.push(b),{cards:y,destroy:()=>{for(const s of l)s()}}}function Ye(e){const n=Se(e.map(c=>c.passBins)),a=e.length===1,d=e[0],r=re();Object.assign(r.style,{flexDirection:"row",flexWrap:"wrap",gap:x.md});const f=c=>{const b=c.lastElementChild;return b&&Object.assign(b.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),c};function p(c,b,s){const g=m.createElement("div");Object.assign(g.style,{display:"flex",alignItems:"baseline",gap:x.sm,paddingRight:x.xxl,marginRight:x.md,borderRight:`1px solid ${B.menuBorder}`});const h=m.createElement("div");h.textContent=c,Object.assign(h.style,{fontSize:M.heading,fontWeight:"700",color:B.value,lineHeight:it.tight});const i=m.createElement("div");if(i.textContent=b,Object.assign(i.style,{fontSize:M.body,color:B.label}),g.append(h,i),s){const t=m.createElement("div");t.textContent=s,Object.assign(t.style,{fontSize:M.meta,color:B.label,opacity:st.muted}),g.appendChild(t)}return g}if(a){const c=J([{...d,key:d.waferIndex}])[0]?.percent;return c!==void 0&&r.appendChild(p(`${c.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),r.appendChild(p(String(d.dies.length),"Total dies")),f(r)}r.appendChild(p(String(e.length),"Wafers"));const l=J(e.map(c=>({...c,key:c.waferIndex}))).map(c=>c.percent).filter(c=>Number.isFinite(c));if(l.length){const c=l.reduce((g,h)=>g+h,0)/l.length,b=ve([{key:"all",items:e.map(g=>({...g,key:g.waferIndex}))}])[0]?.percent,s=b!==void 0&&b.toFixed(1)!==c.toFixed(1);r.appendChild(p(`${c.toFixed(1)}%`,`${Ue} \xB7 pass: ${n}`,s?`${b.toFixed(1)}% by dies`:void 0))}const y=e.map(c=>c.statsSummary);if(y.every(c=>c!==void 0)){const c=y.reduce((s,g)=>s+g.stats.analyzedDies,0),b=y.reduce((s,g)=>s+g.stats.excludedDies,0);r.appendChild(p(c.toLocaleString(),"Dies analysed",b?`${b.toLocaleString()} excluded`:void 0))}else r.appendChild(p(e.reduce((c,b)=>c+b.dies.length,0).toLocaleString(),"Total dies"));return f(r)}function je(e,n,a,d,r){const f=m.createElement("div");Object.assign(f.style,{display:"flex",flexDirection:"column",gap:x.lg});const p=e.length===1&&!d;e.length&&!d&&f.appendChild(Ye(e));const l=We(e,d,r,!p);f.appendChild(l.card);const y=Fe(e,n,a,d);for(const c of y.elements)l.card.appendChild(c);return f.appendChild(Ge()),{card:f,destroy:()=>{l.destroy(),y.destroy()}}}function Ge(){const e=m.createElement("div");Object.assign(e.style,{fontSize:M.body,color:B.label});const n=m.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:B.iconActive,textDecoration:"underline"}),de(n,"bare"),n.addEventListener("click",()=>{L="data",G({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function He(e,n,a,d){const r=m.createElement("div");r.style.width="100%";let f,p=!1;return import("./plotTab.js").then(({createPlotSection:l})=>{if(p)return;const y=l({doc:m,store:q,items:e,testDefs:n,ringCount:F(),groupBy:a,groupLabel:d,onSaveImage:k,onSaveText:A,openWafer:R?(c,b,s)=>R(c,b,s):void 0,focusTest:Z,locateDie:_,pickPlotsFile:$.onPickPlotsFile});r.appendChild(y.card),f=y}),{card:r,destroy:()=>{p=!0,f?.destroy()}}}function Ve(e,n,a,d,r){const f=pe?.(),p=()=>{j.get("data")?.destroy(),j.delete("data"),G({keepSections:!0})};return Et({doc:m,items:e,testDefs:n,allTestDefs:a,groups:d,groupLabelText:r,ringCount:F(),yieldByWaferIndex:new Map(f?.lotYieldSeries.map(l=>[l.waferIndex,l.yieldPercent])),onSaveText:A,onLocateDie:_,onOpenWafer:R?(l,y)=>R(l,y):void 0,buildStatistics:l=>Ne(l,n,a),view:fe,onViewChange:l=>{fe=l,p()},diesLayout:me,onDiesLayoutChange:l=>{me=l}})}function _e(e,n,a,d){const r=ce(m),f=ae(e),p=t=>o=>be(o,t()),l=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),y=e.map(l),c=a?.map(t=>({key:t.key,items:t.items.map(l)})),b=mt({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:p(()=>b),onTestChange:t=>h(t),selectedTestNumber:P??void 0,items:y,testDefs:n,groups:c,groupLabelText:d,onSaveImage:k,onGroupChange:t=>te(t),onOpen:f?.open,openActionLabel:f?.label,onWaferContextMenu:oe(e),ownerDocument:m}),s=gt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:p(()=>s),onTestChange:t=>h(t),selectedTestNumber:P??void 0,items:e,testDefs:n,groups:a,onGroupChange:t=>te(t),onSaveImage:k,onSelectBucket:(t,o)=>{const w=n.find(T=>T.testNumber===t.testNumber),S=new Set(t.items.map(T=>T.item)),v=new Set(t.items.flatMap(T=>T.dies)),H=Ce(t.low,w?.unit,"engineering"),ie=Ce(t.high,w?.unit,"engineering");Q(o,e.filter(T=>S.has(T)),`with ${w?Je(w,w.testNumber):`test ${t.testNumber}`} from ${H} to ${ie}${t.group?` in ${t.group}`:""}`,T=>v.has(T),t.testNumber)},ownerDocument:m}),g=bt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:p(()=>g),onTestChange:t=>h(t),selectedTestNumber:P??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:rt(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>ne(t,`Wafer ${e.find(w=>w.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,w)=>{const S=new Set(t.keys);ye(o,w,e.filter(v=>S.has(v.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:oe(e),ownerDocument:m}),h=t=>{P=t,b.setTest(t),s.setTest(t),g.setTest(t),i.setTest(t)};ee.set("distribution",[b,s,g]);const i=ft({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:P??void 0,onSelectTest:t=>h(t),ownerDocument:m});return r.append(i.card,b.card,s.card,g.card),{card:r,destroy:()=>{i.destroy(),b.destroy(),s.destroy(),g.destroy()}}}function ze(e,n,a){const d=ce(m),r=ht({title:"Test scatter",items:e,testDefs:n,groups:a,binColors:ue().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:p=>be(p,r),onOpen:ae(e)?.open,openActionLabel:ae(e)?.label,onSelect:(p,l,y,c)=>{const b=new Map;for(const h of p){if(h.waferIndex===void 0||!h.die)continue;const i=b.get(h.waferIndex);i?i.push(h.die):b.set(h.waferIndex,[h.die])}const s=[...b].flatMap(([h,i])=>{const t=e.find(o=>o.waferIndex===h);return t?[{label:t.identity??t.label,dies:i,waferIndex:h,wafer:t.wafer,passBins:t.passBins,ringCount:F()}]:[]});if(s.length===0)return;const g=s.length===1?`selected on ${s[0].label} in the scatter`:`selected in the scatter, across ${s.length} wafers`;se(l,y,{items:s,population:g,testDefs:n,activeTest:c},{plots:q,onSaveImage:k,onSaveText:A,onLocateDie:_})},ownerDocument:m});ee.set("correlation",[r]);const f=yt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:A,onSelectPair:(p,l)=>r.setXY(p,l),ownerDocument:m});return d.append(f.card,r.card),{card:d,destroy:()=>{f.destroy(),r.destroy()}}}function G(e){e?.keepSections||ge(),U.innerHTML="",E.innerHTML="";for(const o of Pe)E.appendChild(Re(o.key,o.label));const n=Oe();Me(n);const a=qe(n,{facetableOnly:!0}).filter(o=>o.splittable),d=m.createElement("div");Object.assign(d.style,{display:"flex",gap:x.md,alignItems:"center",marginLeft:x.xxl,paddingBottom:x.xs});let r;a.length>0?(d.appendChild(kt("Group by:",[{value:"",label:"None"},...a.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],W??"",o=>{W=o||void 0,O=null,G()},{hook:"group-by",ownerDocument:m})),r=a.find(o=>o.key===W)?.label):W=void 0;let f;if(W){const o=new Map,w=[];for(const S of n){const v=Ke(S.metadata,W)??Qe;o.has(v)||(o.set(v,[]),w.push(v)),o.get(v).push(S)}f=w.map(S=>({key:S,items:o.get(S)}))}O!==null&&!f?.some(o=>o.key===O)&&(O=null),f&&f.length>0&&d.appendChild(vt(f.map(o=>o.key),"Show:",O,o=>te(o),{ownerDocument:m}).el);let p=null;if($.onOpenGuide){const o=m.createElement("button");o.type="button",o.innerHTML=ut.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...ct("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),de(o,"bare"),pt(o,"User guide"),o.addEventListener("click",()=>$.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),p=o}E.appendChild(d),p&&E.appendChild(p);const l=O!==null?f?.find(o=>o.key===O):void 0,y=l?.items??n,c=l?void 0:f,b=he(y),s=b.defs,g=s.filter(we);P!==null&&!g.some(o=>o.testNumber===P)&&(P=null);const h=e?.keepSections?j.get(L):void 0,i=h??(L==="overview"?je(y,g,s,c,r):L==="distributions"?_e(y,g,c,r):L==="data"?Ve(y,g,s,c,r):L==="plot"?He(y,s,l?void 0:W,l?void 0:r):ze(y,g,c));h||j.set(L,i);const t=b.conflicts.filter(o=>o.excluded);if(t.length>0){const o=m.createElement("div");Object.assign(o.style,{color:B.label,fontSize:M.body,padding:`0 ${z} ${x.sm}`});const w=t.slice(0,6).map(H=>H.testNumber).join(", "),S=t.length>6?`, and ${t.length-6} more`:"",v=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${w}${S}) \u2014 the wafers in view describe ${v} differently, so their values cannot be pooled. `+(f&&f.length>0?`Pick one ${r??"group"} under "Show:" to analyse ${v}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(i.card)}return{el:N,render:G,destroy:()=>{ge(),q.flush(),N.remove()}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as qe}from"../stats/presentation.js";import{buildFacetTable as Ke,facetValueOf as Qe,FACET_NONE_VALUE as Xe,DEFAULT_FACET_CURATION as Je}from"../stats/facets.js";import{mergeTestDefs as Se}from"../stats/mergeTestDefs.js";import{isParametricTest as xe}from"../renderer/buildWaferMap.js";import{dieFailsTest as Ze}from"../stats/testPassRate.js";import{fmt as ke}from"../renderer/fmt.js";import{testLabel as et}from"../renderer/testLabel.js";import{waferDisplayLabel as tt,waferIdentityLabel as nt}from"../core/waferLabel.js";import{waferPopulation as ot}from"./chartPopulation.js";import{openDrilldownMenu as se}from"./drilldown.js";import{plotStoreFor as it}from"./plotStore.js";import{itemPassBins as rt,passBinsLabel as Te}from"../core/passBins.js";import{NO_DATA_FILL as ve}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as st}from"../stats/population.js";import{LEADING as lt,ALPHA as dt,SPACE as T,EDGE_GUTTER as le,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as de,wireTooltip as ft}from"./toolbar.js";import{ICONS as mt}from"./icons.js";import{renderCapabilityPanel as bt}from"./charts/capability.js";import{renderBoxplotPanel as ht}from"./charts/boxplot.js";import{renderTrendPanel as gt}from"./charts/trend.js";import{renderHistogramPanel as yt}from"./charts/histogram.js";import{renderCorrelationPanel as wt}from"./charts/correlation.js";import{renderScatterPanel as Ct}from"./charts/scatter.js";import{renderBarPanel as De}from"./charts/barPanel.js";import{renderBinClusterPanel as St}from"./charts/binCluster.js";import{renderTestPassRatePanel as xt}from"./charts/testPassRate.js";import{QUANTITY as kt}from"./charts/palette.js";import{cardFrameStyle as Tt,makeChartGridWrap as ce,makeLabeledSelect as vt,makeLinkedGroupSelect as Dt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as Be}from"../stats/yield.js";import{buildBinParetoData as Bt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as $t,buildLotFunctionalSection as Lt,buildMetadataStripBox as It}from"./summaryPanel.js";import{runChunked as Et}from"./chunked.js";import{buildRegionYieldData as ue,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as Pt,diesInRegion as At}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as pe}from"./charts/regionYieldDiagram.js";const Wt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Mt={key:"data",label:"Data"},Ft={key:"plot",label:"Plot"};export function createInsightsTab(v){const{getItems:Ie,getLotStats:fe,getBinColors:me,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,be={...Je,...v.attributes},Ee=v.showMetadataStrip??!0,z=v.contentInset??le,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Pe=le,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Pe});const E=f.createElement("div");Object.assign(E.style,{display:"flex",gap:T.xs,alignItems:"center",background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:ct.container,boxShadow:ut.panel,padding:`0 ${T.lg}`,marginBottom:T.lg,marginLeft:z,marginRight:z}),E.setAttribute("role","tablist"),E.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(E.querySelectorAll('[role="tab"]')),r=n.indexOf(f.activeElement);if(r===-1)return;e.preventDefault();const l=n[(r+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];l.focus(),l.click()});const U=f.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:T.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),Y.appendChild(j),Y.appendChild(E),Y.appendChild(U);const Ae=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,he="statistics",ge="wide",P=null,A=null,K={includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,ye=(e,n)=>{K=e;for(const r of ee.values())for(const l of r)l!==n&&l.setAxisPrefs(e)},te=e=>{A!==e&&(A=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function ne(e,n,r){R?.(e,n,r)}function oe(e){return(n,r,l)=>{const i=e.find(c=>c.waferIndex===n);if(!i)return;l.preventDefault();const u=ot(i.dies,{waferLabel:i.identity,testDefs:i.testDefs,activeTest:r??P??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});se({x:l.clientX,y:l.clientY},l.target,u,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}}function Q(e,n,r,l,i){Ce({x:e.clientX,y:e.clientY},e.target,n,r,l,i)}function Ce(e,n,r,l,i,u){const c=Rt(r.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:N()})),l,i,Se(r).defs,u);c&&se(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function ie(e){return R?{open:(n,r)=>ne(n,`Wafer ${e.find(l=>l.waferIndex===n)?.label??n}`,r)}:Z&&e.length===1?{open:(n,r)=>Z(r),label:"show this test on the map"}:null}function Oe(){return Ie().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:tt(e,n),identity:nt(e),waferIndex:n,passBins:rt(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Re(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${$.iconActive}`:"2px solid transparent",color:n?$.iconActive:$.label,fontWeight:n?"700":"500",fontSize:F.body,padding:`${T.sm} ${le} ${T.md}`,cursor:"pointer",marginBottom:"-1px"})}function We(e,n){const r=f.createElement("button");r.type="button",r.textContent=n;const l=e===L;return Re(r,l),r.dataset.on=l?"true":"false",de(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",l?"true":"false"),r.tabIndex=l?0:-1,r.addEventListener("click",()=>{L!==e&&(L=e,H({keepSections:!0}))}),r}function Me(e,n,r,l=!0){const i=ce(f),u=me();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=fe?.(),m=new Map(d?.lotYieldSeries.map(p=>[p.waferIndex,p.yieldPercent])),a=p=>({...p,label:p.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(p.waferIndex),key:p.waferIndex}),b=e.map(a),y=n?.map(p=>({key:p.key,items:p.items.map(a)})),w=()=>y?Be(y,c):J(b,c),t={title:n?`Yield by ${s} (pass: ${h})`:`Yield by wafer (pass: ${h})`,data:w(),selfControl:{current:c,options:[["yield","Sort: yield"],["label",n?`Sort: ${s}`:"Sort: wafer ID"]],onChange:p=>(c=p,{data:w()})},barColor:()=>kt,valueLabel:p=>`${p.percent.toFixed(1)}%`,reference:p=>{if(p.length<3)return null;const S=p.map(I=>I.percent).sort((I,_)=>I-_),B=S.length%2?S[(S.length-1)/2]:(S[S.length/2-1]+S[S.length/2])/2;return{value:B,label:`median ${B.toFixed(1)}%`}},drill:y?{onOpenGroup:p=>{const S=y.find(B=>B.key===p.label)?.items??[];return{data:J(S,c),title:`Yield by wafer \u2014 ${s}: ${p.label} (pass: ${h})`}},onBack:()=>({data:w(),title:`Yield by ${s} (pass: ${h})`}),groupLabelText:s}:void 0,onOpen:R?p=>{typeof p.key=="number"&&ne(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:oe(e),ownerDocument:f};let o=null;if(l&&(o=De(t,k),o.card.style.minHeight="360px",i.appendChild(o.card)),n){const p=St({title:"Hard bin pareto",groups:n.map(S=>({key:S.key,items:S.items.map(B=>({dies:B.dies,hardBinCounts:B.statsSummary?.stats.hardBinCounts,softBinCounts:B.statsSummary?.stats.softBinCounts}))})),onSelectBin:(S,B)=>{const I=n.find(X=>X.key===S.groupKey);if(!I)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,I.items,`in ${_} bin ${S.bin} of ${S.groupKey}`,X=>(S.binType==="hbin"?X.hbin:X.sbin)===S.bin)},onSaveImage:k,ownerDocument:f});return p.card.style.minHeight="360px",i.appendChild(p.card),{card:i,destroy:()=>{o?.destroy(),p.destroy()}}}let g="hbin";const C=p=>p===void 0?ve:(g==="hbin"?u.hard:u.soft).get(p)??ve,x=e.map(p=>({dies:p.dies,hardBinCounts:p.statsSummary?.stats.hardBinCounts,softBinCounts:p.statsSummary?.stats.softBinCounts})),W=()=>Bt(x,g),ae={title:"Hard bin pareto",data:W(),selfControl:{current:g,options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],onChange:p=>(g=p,{data:W(),title:`${g==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:p=>C(p.binCode),onSelectBar:(p,S)=>{const B=g==="hbin"?"hard":"soft",I=p.binCode;Q(S,e,I===void 0?`with no ${B} bin recorded`:`in ${B} bin ${I}`,_=>(g==="hbin"?_.hbin:_.sbin)===I)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(ae,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function re(){const e=f.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Tt(),display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"}),e}function Fe(e){if(j.innerHTML="",j.style.marginBottom="0",!Ee)return;const n=It(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",j.appendChild(n),j.style.marginBottom=T.xs)}function Ne(e,n,r,l){if(!e.length)return{elements:[],destroy:()=>{}};const i=e.map(t=>t.wafer),u=e.map(t=>t.dies),c=N(),s=[],h=[],m=xt({groups:(l??[{key:"",items:e}]).map(t=>({key:t.key,items:t.items.map(o=>({dies:o.dies,testSpecYield:o.statsSummary?.stats.testSpecYield,functionalYield:o.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:k,onSelectTest:(t,o)=>{const g=r.find(C=>C.testNumber===t.testNumber);g&&Q(o,e,`failing ${t.label}`,C=>Ze(C,g,t.kind)===!0,xe(g)?t.testNumber:void 0)},ownerDocument:f});m.card.style.minHeight="300px",s.push(m.card),h.push(m.destroy);const a=t=>(o,g)=>{const C=new Set;for(const x of e)for(const W of At(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=ue(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=pe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=ue(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=pe({title:"Quadrant yield",mode:"quadrant",rows:y,onSelectRegion:a(Le),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const w=i.find(t=>t.reticle!==void 0)?.reticle;if(w){const t=(g,C)=>Pt(g,C.reticle),o=ue(u,i,c,g=>e[g].passBins,t);if(o.length){const g=pe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:w.width,height:w.height},onSelectRegion:a(t),onSaveImage:k,ownerDocument:f});s.push(g.card),h.push(g.destroy)}}return{elements:s,destroy:()=>{for(const t of h)t()}}}function Ye(e,n,r){if(!e.length)return{cards:[],destroy:()=>{}};const l=e.map(a=>a.dies),i=e.flatMap(a=>a.dies),u=e.map(a=>a.statsSummary),c=u.every(a=>a!==void 0)?u:void 0,s=[],h=[];let d=null;if(n.length){const a=re();let b=null;const y=Et($t(i,n,void 0,c,O,l.map(w=>({dies:w})),void 0,"full"),{onDone:w=>{b=w,a.removeAttribute("aria-busy"),w?a.replaceChildren(w):a.remove()}});if(y.done)b&&(d=a);else{const w=f.createElement("div");w.textContent="Computing test statistics\u2026",Object.assign(w.style,{color:$.label,fontSize:F.body}),a.setAttribute("aria-busy","true"),a.appendChild(w),d=a,s.push(()=>y.cancel())}}let m=null;if(r.length){const a=Lt(i,r,c,O);if(a){const b=re();b.appendChild(a),m=b}}return d&&h.push(d),m&&h.push(m),{cards:h,destroy:()=>{for(const a of s)a()}}}function je(e){const n=Te(e.map(d=>d.passBins)),r=e.length===1,l=e[0],i=re();Object.assign(i.style,{flexDirection:"row",flexWrap:"wrap",gap:T.md});const u=d=>{const m=d.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function c(d,m,a){const b=f.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:T.sm,paddingRight:T.xxl,marginRight:T.md,borderRight:`1px solid ${$.menuBorder}`});const y=f.createElement("div");y.textContent=d,Object.assign(y.style,{fontSize:F.heading,fontWeight:"700",color:$.value,lineHeight:lt.tight});const w=f.createElement("div");if(w.textContent=m,Object.assign(w.style,{fontSize:F.body,color:$.label}),b.append(y,w),a){const t=f.createElement("div");t.textContent=a,Object.assign(t.style,{fontSize:F.meta,color:$.label,opacity:dt.muted}),b.appendChild(t)}return b}if(r){const d=J([{...l,key:l.waferIndex}])[0]?.percent;return d!==void 0&&i.appendChild(c(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),i.appendChild(c(String(l.dies.length),"Total dies")),u(i)}i.appendChild(c(String(e.length),"Wafers"));const s=J(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(s.length){const d=s.reduce((b,y)=>b+y,0)/s.length,m=Be([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,a=m!==void 0&&m.toFixed(1)!==d.toFixed(1);i.appendChild(c(`${d.toFixed(1)}%`,`${qe} \xB7 pass: ${n}`,a?`${m.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((a,b)=>a+b.stats.analyzedDies,0),m=h.reduce((a,b)=>a+b.stats.excludedDies,0);i.appendChild(c(d.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else i.appendChild(c(e.reduce((d,m)=>d+m.dies.length,0).toLocaleString(),"Total dies"));return u(i)}function Ge(e,n,r,l,i){const u=f.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:T.lg});const c=e.length===1&&!l;e.length&&!l&&u.appendChild(je(e));const s=Me(e,l,i,!c);u.appendChild(s.card);const h=Ne(e,n,r,l);for(const d of h.elements)s.card.appendChild(d);return u.appendChild(He()),{card:u,destroy:()=>{s.destroy(),h.destroy()}}}function He(){const e=f.createElement("div");Object.assign(e.style,{fontSize:F.body,color:$.label});const n=f.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:$.iconActive,textDecoration:"underline"}),de(n,"bare"),n.addEventListener("click",()=>{L="data",H({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function _e(e,n,r,l){const i=f.createElement("div");i.style.width="100%";let u,c=!1;return import("./plotTab.js").then(({createPlotSection:s})=>{if(c)return;const h=s({doc:f,store:q,items:e,testDefs:n,ringCount:N(),attributes:v.attributes,groupBy:r,groupLabel:l,onSaveImage:k,onSaveText:O,openWafer:R?(d,m,a)=>R(d,m,a):void 0,focusTest:Z,locateDie:V,pickPlotsFile:v.onPickPlotsFile});i.appendChild(h.card),u=h}),{card:i,destroy:()=>{c=!0,u?.destroy()}}}function Ve(e,n,r,l,i){const u=fe?.(),c=()=>{G.get("data")?.destroy(),G.delete("data"),H({keepSections:!0})};return Ot({doc:f,items:e,testDefs:n,allTestDefs:r,groups:l,groupLabelText:i,ringCount:N(),attributes:v.attributes,yieldByWaferIndex:new Map(u?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),onSaveText:O,onLocateDie:V,onOpenWafer:R?(s,h)=>R(s,h):void 0,buildStatistics:s=>Ye(s,n,r),view:he,onViewChange:s=>{he=s,c()},diesLayout:ge,onDiesLayoutChange:s=>{ge=s}})}function ze(e,n,r,l){const i=ce(f),u=ie(e),c=t=>o=>ye(o,t()),s=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),h=e.map(s),d=r?.map(t=>({key:t.key,items:t.items.map(s)})),m=ht({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:c(()=>m),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>te(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:oe(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>te(t),onSaveImage:k,onSelectBucket:(t,o)=>{const g=n.find(D=>D.testNumber===t.testNumber),C=new Set(t.items.map(D=>D.item)),x=new Set(t.items.flatMap(D=>D.dies)),W=ke(t.low,g?.unit,"engineering"),ae=ke(t.high,g?.unit,"engineering");Q(o,e.filter(D=>C.has(D)),`with ${g?et(g,g.testNumber):`test ${t.testNumber}`} from ${W} to ${ae}${t.group?` in ${t.group}`:""}`,D=>x.has(D),t.testNumber)},ownerDocument:f}),b=gt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:c(()=>b),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:st(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>ne(t,`Wafer ${e.find(g=>g.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,g)=>{const C=new Set(t.keys);Ce(o,g,e.filter(x=>C.has(x.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:oe(e),ownerDocument:f}),y=t=>{P=t,m.setTest(t),a.setTest(t),b.setTest(t),w.setTest(t)};ee.set("distribution",[m,a,b]);const w=bt({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:P??void 0,onSelectTest:t=>y(t),ownerDocument:f});return i.append(w.card,m.card,a.card,b.card),{card:i,destroy:()=>{w.destroy(),m.destroy(),a.destroy(),b.destroy()}}}function Ue(e,n,r){const l=ce(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:me().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>ye(c,i),onOpen:ie(e)?.open,openActionLabel:ie(e)?.label,onSelect:(c,s,h,d)=>{const m=new Map;for(const y of c){if(y.waferIndex===void 0||!y.die)continue;const w=m.get(y.waferIndex);w?w.push(y.die):m.set(y.waferIndex,[y.die])}const a=[...m].flatMap(([y,w])=>{const t=e.find(o=>o.waferIndex===y);return t?[{label:t.identity??t.label,dies:w,waferIndex:y,wafer:t.wafer,passBins:t.passBins,ringCount:N()}]:[]});if(a.length===0)return;const b=a.length===1?`selected on ${a[0].label} in the scatter`:`selected in the scatter, across ${a.length} wafers`;se(s,h,{items:a,population:b,testDefs:n,activeTest:d},{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})},ownerDocument:f});ee.set("correlation",[i]);const u=wt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:O,onSelectPair:(c,s)=>i.setXY(c,s),ownerDocument:f});return l.append(u.card,i.card),{card:l,destroy:()=>{u.destroy(),i.destroy()}}}function H(e){e?.keepSections||we(),U.innerHTML="",E.innerHTML="";for(const o of Ae)E.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:be}).filter(o=>o.splittable),l=f.createElement("div");Object.assign(l.style,{display:"flex",gap:T.md,alignItems:"center",marginLeft:T.xxl,paddingBottom:T.xs});let i;r.length>0?(l.appendChild(vt("Group by:",[{value:"",label:"None"},...r.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],M??"",o=>{M=o||void 0,A=null,H()},{hook:"group-by",ownerDocument:f})),i=r.find(o=>o.key===M)?.label):M=void 0;let u;if(M){const o=new Map,g=[];for(const C of n){const x=Qe(C.metadata,M,be)??Xe;o.has(x)||(o.set(x,[]),g.push(x)),o.get(x).push(C)}u=g.map(C=>({key:C,items:o.get(C)}))}A!==null&&!u?.some(o=>o.key===A)&&(A=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",A,o=>te(o),{ownerDocument:f}).el);let c=null;if(v.onOpenGuide){const o=f.createElement("button");o.type="button",o.innerHTML=mt.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...pt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),de(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}E.appendChild(l),c&&E.appendChild(c);const s=A!==null?u?.find(o=>o.key===A):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);P!==null&&!b.some(o=>o.testNumber===P)&&(P=null);const y=e?.keepSections?G.get(L):void 0,w=y??(L==="overview"?Ge(h,b,a,d,i):L==="distributions"?ze(h,b,d,i):L==="data"?Ve(h,b,a,d,i):L==="plot"?_e(h,a,s?void 0:M,s?void 0:i):Ue(h,b,d));y||G.set(L,w);const t=m.conflicts.filter(o=>o.excluded);if(t.length>0){const o=f.createElement("div");Object.assign(o.style,{color:$.label,fontSize:F.body,padding:`0 ${z} ${T.sm}`});const g=t.slice(0,6).map(W=>W.testNumber).join(", "),C=t.length>6?`, and ${t.length-6} more`:"",x=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${g}${C}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${i??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(w.card)}return{el:Y,render:H,destroy:()=>{we(),q.flush(),Y.remove()}}}