@wafertools/wafermap 0.35.0 → 0.36.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 (97) hide show
  1. package/AGENTS.md +18 -9
  2. package/CHANGELOG.md +246 -0
  3. package/README.md +7 -4
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  10. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  11. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  12. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  13. package/dist/packages/canvas-adapter/index.js +1 -1
  14. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  15. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  17. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  18. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +85 -38
  19. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  20. package/dist/packages/canvas-adapter/summaryPanel.d.ts +38 -12
  21. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  22. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  23. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  24. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  25. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  26. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  27. package/dist/packages/canvas-adapter/toolbar.d.ts +2 -0
  28. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  29. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  30. package/dist/packages/canvas-adapter/userGuideHtml.js +46 -23
  31. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  32. package/dist/packages/canvas-adapter/version.js +1 -1
  33. package/dist/packages/canvas-adapter/warnings.js +1 -1
  34. package/dist/packages/core/aggregates.d.ts +10 -0
  35. package/dist/packages/core/aggregates.js +1 -1
  36. package/dist/packages/core/classify.d.ts +5 -0
  37. package/dist/packages/core/classify.js +1 -1
  38. package/dist/packages/core/dieTable.d.ts +31 -0
  39. package/dist/packages/core/dieTable.js +1 -1
  40. package/dist/packages/core/passBins.d.ts +6 -0
  41. package/dist/packages/core/passBins.js +1 -1
  42. package/dist/packages/core/wafer.d.ts +10 -1
  43. package/dist/packages/core/wafer.js +1 -1
  44. package/dist/packages/renderer/buildView.d.ts +5 -0
  45. package/dist/packages/renderer/buildView.js +1 -1
  46. package/dist/packages/renderer/buildWaferMap.d.ts +50 -4
  47. package/dist/packages/renderer/buildWaferMap.js +1 -1
  48. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  49. package/dist/packages/renderer/fmt.d.ts +10 -0
  50. package/dist/packages/renderer/fmt.js +1 -1
  51. package/dist/packages/renderer/index.d.ts +1 -0
  52. package/dist/packages/renderer/index.js +1 -1
  53. package/dist/packages/renderer/spec.d.ts +4 -0
  54. package/dist/packages/renderer/spec.js +1 -1
  55. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  56. package/dist/packages/renderer/valueFilter.js +1 -0
  57. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  58. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  59. package/dist/packages/stats/analyzeWaferMap.d.ts +62 -4
  60. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  61. package/dist/packages/stats/capability.d.ts +5 -0
  62. package/dist/packages/stats/capability.js +1 -1
  63. package/dist/packages/stats/clusterDetection.js +1 -1
  64. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  65. package/dist/packages/stats/connectedComponents.js +1 -1
  66. package/dist/packages/stats/correlation.d.ts +36 -4
  67. package/dist/packages/stats/correlation.js +1 -1
  68. package/dist/packages/stats/filterFindings.d.ts +1 -1
  69. package/dist/packages/stats/filterFindings.js +1 -1
  70. package/dist/packages/stats/findingText.d.ts +8 -0
  71. package/dist/packages/stats/findingText.js +2 -2
  72. package/dist/packages/stats/index.d.ts +2 -1
  73. package/dist/packages/stats/index.js +1 -1
  74. package/dist/packages/stats/lotDrift.js +1 -1
  75. package/dist/packages/stats/lotPattern.js +1 -1
  76. package/dist/packages/stats/math.d.ts +25 -3
  77. package/dist/packages/stats/math.js +1 -1
  78. package/dist/packages/stats/mergeTestDefs.js +1 -1
  79. package/dist/packages/stats/patternClassification.d.ts +44 -18
  80. package/dist/packages/stats/patternClassification.js +1 -1
  81. package/dist/packages/stats/plotData.d.ts +11 -0
  82. package/dist/packages/stats/plotData.js +1 -1
  83. package/dist/packages/stats/regions.d.ts +6 -0
  84. package/dist/packages/stats/regions.js +1 -1
  85. package/dist/packages/stats/renderSummaryReport.js +33 -33
  86. package/dist/packages/stats/reportHtml.d.ts +12 -18
  87. package/dist/packages/stats/reportHtml.js +112 -48
  88. package/dist/packages/stats/synthesis.d.ts +48 -17
  89. package/dist/packages/stats/synthesis.js +1 -1
  90. package/dist/packages/stats/testPassRate.js +1 -1
  91. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  92. package/dist/packages/stats/testValueBudget.js +1 -0
  93. package/dist/packages/stats/types.d.ts +89 -22
  94. package/llms.txt +2 -2
  95. package/package.json +1 -1
  96. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  97. package/dist/packages/canvas-adapter/summaryRail.js +0 -1
@@ -1 +1 @@
1
- import{buildTestHistogramData as Zt,collectTestValues as Ct,buildTestHistogramSeries as te,testValueExtent as Bt,diesInBucket as At}from"../../stats/histogram.js";import{SPACE as lt,fontPx as N,FONT as $t,CLR as Et}from"../toolbar.js";import{fmt as xt}from"../../renderer/fmt.js";import{niceStep as ee,fitTicks as Wt}from"../../renderer/axisTicks.js";import{QUANTITY as ne,categorical as ie}from"./palette.js";import{cardShell as oe,observeResize as Dt,makeTooltip as se,attachChartTip as le,positionChartTooltip as It,makeLinkedTestSelect as ae,makeWaferSelect as re,makeLinkedAxisPrefs as ce,renderEmptyState as kt,chartFillHeight as Pt,applyCanvasFlow as Rt,makeAxisFormat as Tt,horizontalTickSpacing as Kt,PADDING as mt,robustFence as Nt,shouldIncludeLimitsByDefault as Ot,drawOffAxisLimits as ue,resolveAxisRange as de,limitLines as Ft,limitExtent as me,hasBothLimitKinds as he,stackLabelRows as fe,strokeLimitLine as ge,chartSwatchCss as pe,makeSeriesLegendItem as xe,prepareCanvas as zt}from"./chartShell.js";import{escHtml as wt,maxOf as be}from"../../core/utils.js";const Mt=230,Gt=36,ye=18;function Vt(n){const $=new Set(n.map(E=>E.kind)).size;return ye+Math.max(0,$-1)*(N(-1)+2)}function jt(n,$,E,V,et,S,l){n.font=`${N(-1)}px system-ui, sans-serif`;const x=$.filter(i=>!E.has(i.value)).map(i=>{const k=V(i.value),W=n.measureText(i.label).width;return{l:i,x:k,start:k-W/2,end:k+W/2}}),U=fe(x),nt=N(-1)+2;x.forEach(({l:i,x:k},W)=>{ge(n,i,l,k,et,k,S),n.fillStyle=l,n.textAlign="center",n.textBaseline="bottom",n.fillText(i.label,k,et-2-U[W]*nt)})}function Xt(n,$,E,V,et,S,l,x=4){const U=Math.max(1,ee(S/x)),nt=V-E;n.save(),n.font=`${N(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(let i=0;i<=S+1e-9;i+=U){const k=V-i/(S||1)*nt;n.strokeStyle=l.grid,n.lineWidth=1,n.beginPath(),n.moveTo($,k),n.lineTo($+et,k),n.stroke(),n.fillStyle=l.text,n.fillText(String(Math.round(i)),$-4,k)}n.strokeStyle=l.axis,n.lineWidth=1,n.beginPath(),n.moveTo($,E),n.lineTo($,V),n.stroke(),n.restore()}export function renderHistogramPanel(n){const{title:$="Test value distribution",items:E,testDefs:V,onSaveImage:et,groups:S}=n,{card:l,body:x,controlsRow:U}=oe($,et,n.ownerDocument),nt=V.filter(c=>c.testNumber!==void 0);let i=n.selectedTestNumber??nt[0]?.testNumber??null,k=null,W=0,ht;const vt=ae(nt,i,c=>{i=c,q(),n.onTestChange?.(c)},{maxWidth:"200px",ownerDocument:l.ownerDocument}),_t=vt.el;U.appendChild(_t);const ft=E.length>1?re(E,k,c=>{k=c,q()},{ownerDocument:l.ownerDocument}):null;ft&&U.appendChild(ft);function Yt(c){return b===c||c!==null&&!(S??[]).some(L=>L.key===c)?!1:(b=c,q(),!0)}const bt=l.ownerDocument.createElement("span");Object.assign(bt.style,{display:"inline-flex",gap:lt.lg,alignItems:"center"}),U.appendChild(bt);const at=ce(bt,n.axisPrefs,c=>{n.onAxisPrefsChange?.(c),q()},l.ownerDocument),C=se(l);let rt=null,b=null;function it(c){const L=V.find(I=>I.testNumber===c),j=Ft(L,at.get().limits),{lo:T,hi:w}=me(j);return{unit:L?.unit,lines:j,limitLow:T,limitHigh:w,hasLimits:Ft(L).length>0,hasBothKinds:he(L)}}function q(){const{includeLimits:c,clipOutliers:L}=at.get();if(rt?.disconnect(),rt=null,x.innerHTML="",i===null){kt(x,"No parametric test data available for a histogram.");return}const j=!!S&&S.length>0;let T=!1,w;if(j){const{limitLow:u,limitHigh:m}=it(i),g=S.flatMap(r=>r.items),{min:e,max:p}=Bt(g,i);if(T=c??Ot(e,p,u,m),L){const r=Ct(g,i),h=Nt(r);h&&(w={lo:Math.max(e,h.lo),hi:Math.min(p,h.hi)},W=r.reduce((Z,K)=>Z+(K<w.lo||K>w.hi?1:0),0))}w||(W=0),ht=w}const I=j?te(S,i,16,T?it(i).limitLow:void 0,T?it(i).limitHigh:void 0,w):null;if(ft&&(ft.style.display=I?"none":""),I){const{hasLimits:u,hasBothKinds:m}=it(i);if(at.sync(T,u,m),I.series.length===0){kt(x,"No parametric test data available for a histogram.");return}Qt(I);return}const O=k!==null?[E[k]]:E,{unit:D,lines:X,limitLow:M,limitHigh:_,hasLimits:ct,hasBothKinds:gt}=it(i),ut=Ct(O,i),{min:dt,max:pt}=Bt(O,i),P=c??Ot(dt,pt,M,_);at.sync(P,ct,gt);const ot=L?Nt(ut):null,R=ot?{lo:Math.max(dt,ot.lo),hi:Math.min(pt,ot.hi)}:void 0;W=R?ut.filter(u=>u<R.lo||u>R.hi).length:0,ht=R;const y=Zt(O,i,16,P?M:void 0,P?_:void 0,R);if(y.length===0){kt(x,"No parametric test data available for a histogram.");return}const o=Math.max(be(y.map(u=>u.count)),1),d=l.ownerDocument.createElement("div");d.dataset.wmapCaption="1",Object.assign(d.style,{fontSize:$t.body,color:Et.label,marginBottom:lt.xxs}),d.textContent=`max ${o} dies/bucket`+(W?` \xB7 ${W} value${W===1?"":"s"} outside clipped range`:"")+(n.onSelectBucket?" \xB7 click a bar to chart or tabulate its dies":""),x.appendChild(d);const s=l.ownerDocument.createElement("canvas");s.style.display="block",s.style.cursor="default",x.appendChild(s);let t=-1;const a=y[0].rangeLow,f=y[y.length-1].rangeHigh,H=f-a||1,F=Math.max(Math.abs(a),Math.abs(f));function J(u){const m=mt+36,g=s.clientWidth-m-mt,e=Vt(X),p=u-Gt-e;return{plotX:m,plotMaxWidth:Math.max(10,g),plotMaxHeight:p,plotTop:e}}function v(u){const{plotX:m,plotMaxWidth:g}=J(Mt);if(u<m||u>m+g)return-1;const e=Math.floor((u-m)/g*y.length);return e>=0&&e<y.length?e:-1}function A(){Rt(s,d);const u=x.clientWidth,m=Pt(l,x,s,Mt),g=zt(s,l,u,m);if(!g)return;const{ctx:e,theme:p}=g,{plotX:r,plotMaxWidth:h,plotMaxHeight:Z,plotTop:K}=J(m),B=K+Z,tt=h/y.length;Xt(e,r,K,B,h,o,{text:p.textMuted,axis:p.border,grid:p.grid}),y.forEach((G,Q)=>{const St=G.count/o*Z,Lt=r+Q*tt,Ht=B-St;e.fillStyle=Q===t?p.text:ne,e.globalAlpha=Q===t?1:.7,e.fillRect(Lt+1,Ht,Math.max(1,tt-2),St),e.globalAlpha=1,Q===t&&(e.fillStyle=p.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(`${G.count}`,Lt+tt/2,Ht-2))});const st=G=>r+(G-a)/H*h;e.font=`${N(-1)}px system-ui, sans-serif`;const{offAxis:z}=de({dataMin:a,dataMax:f,limits:X,includeLimits:!1});ue(e,z,{left:r,right:r+h,top:K,bottom:B},"horizontal",p.limitLine,Tt(F,D).tick),jt(e,X,new Set(z.map(G=>G.value)),st,K,B,p.limitLine),e.font=`${N(-1)}px system-ui, sans-serif`,e.strokeStyle=p.border,e.lineWidth=1,e.beginPath(),e.moveTo(r,B),e.lineTo(r+h,B),e.stroke(),e.fillStyle=p.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:Y,step:Jt}=Wt(a,f,h,Kt(e,F,D)),yt=Tt(F,D,Jt||void 0);for(const G of Y){const Q=r+(G-a)/H*h;e.beginPath(),e.moveTo(Q,B),e.lineTo(Q,B+4),e.stroke(),e.fillText(yt.tick(G),Q,B+6)}yt.unitLabel&&(e.save(),e.font=`${N(-1)}px system-ui, sans-serif`,e.fillStyle=p.textMuted,e.textAlign="right",e.textBaseline="top",e.fillText(`(${yt.unitLabel})`,r+h,B+20),e.restore())}s.addEventListener("mousemove",u=>{const m=s.getBoundingClientRect(),g=v(u.clientX-m.left);if(g!==t&&(t=g,A()),g>=0){const e=y[g];C.innerHTML=`<strong>${wt(`${xt(e.rangeLow,D,"engineering")} \u2013 ${xt(e.rangeHigh,D,"engineering")}`)}</strong><br>${e.count} dies`+(n.onSelectBucket&&e.count>0?"<br><em>click to chart or tabulate these dies</em>":""),C.style.display="block",It(C,l,u.clientX,u.clientY)}else C.style.display="none"}),s.addEventListener("mouseleave",()=>{t!==-1&&(t=-1,A()),C.style.display="none"}),n.onSelectBucket&&(s.style.cursor="pointer",s.addEventListener("click",u=>{const m=v(u.clientX-s.getBoundingClientRect().left);if(m<0||i===null||y[m].count===0)return;const g=At(O,i,y,m,ht);g.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:y[m].rangeLow,high:y[m].rangeHigh,items:g},u))})),rt=Dt(l,()=>A()),A()}function Qt(c){const{unit:L,lines:j}=it(i),T=c.ranges,w=c.series,I=ie;b&&!w.some(o=>o.groupKey===b)&&(b=null);const O=Math.max(1,...w.flatMap(o=>o.counts)),D=l.ownerDocument.createElement("div");D.dataset.wmapCaption="1",Object.assign(D.style,{fontSize:$t.body,color:Et.label,marginBottom:lt.xxs}),D.textContent=`${w.length} groups \xB7 max ${O} dies/bucket`+(n.onSelectBucket?" \xB7 click a column to chart or tabulate its dies":""),x.appendChild(D);const X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:lt.sm,marginTop:lt.md,marginBottom:lt.xl}),w.forEach((o,d)=>{const s=xe(o.groupKey,I(d),l.ownerDocument),t=s.el;le(t,l,C,`${o.groupKey} \u2014 click to emphasize (dim the rest)`),s.setState({selected:b===o.groupKey,dimmed:b!==null&&b!==o.groupKey}),t.addEventListener("click",()=>{const a=b===o.groupKey?null:o.groupKey;Yt(a),n.onGroupChange?.(a)}),X.appendChild(t)}),x.appendChild(X);const M=l.ownerDocument.createElement("canvas");M.style.display="block",M.style.cursor="default",x.appendChild(M);const _=T[0].rangeLow,ct=T[T.length-1].rangeHigh,gt=ct-_||1,ut=Math.max(Math.abs(_),Math.abs(ct)),dt=o=>{const d=(o.ownerDocument.defaultView??window).getComputedStyle(o);return o.offsetHeight+(parseFloat(d.marginTop)||0)+(parseFloat(d.marginBottom)||0)},pt=()=>dt(D)+dt(X);let P=-1,ot={plotX:mt+36,plotMaxWidth:10,barWidth:10};function R(){Rt(M,pt());const o=x.clientWidth,d=Pt(l,x,M,Mt),s=zt(M,l,o,d);if(!s)return;const{ctx:t,theme:a}=s,f=mt+36,H=Math.max(10,o-f-mt),F=Vt(j),J=d-Gt-F,v=F+J,A=H/T.length;ot={plotX:f,plotMaxWidth:H,barWidth:A},Xt(t,f,F,v,H,O,{text:a.textMuted,axis:a.border,grid:a.grid}),P>=0&&(t.fillStyle=a.bgHover,t.globalAlpha=.5,t.fillRect(f+P*A,F,A,J),t.globalAlpha=1);const u=w.map((r,h)=>({s:r,i:h})).sort((r,h)=>(r.s.groupKey===b?1:0)-(h.s.groupKey===b?1:0));for(const{s:r,i:h}of u){const Z=b===r.groupKey,K=b!==null&&!Z,B=I(h);t.strokeStyle=B,t.fillStyle=B,t.lineWidth=Z?2:1,t.globalAlpha=K?.12:b?.32:.22,t.beginPath(),t.moveTo(f,v),r.counts.forEach((tt,st)=>{const z=f+st*A,Y=v-tt/O*J;t.lineTo(z,Y),t.lineTo(z+A,Y)}),t.lineTo(f+H,v),t.closePath(),t.fill(),t.globalAlpha=K?.3:1,t.beginPath(),r.counts.forEach((tt,st)=>{const z=f+st*A,Y=v-tt/O*J;st===0?t.moveTo(z,Y):t.lineTo(z,Y),t.lineTo(z+A,Y)}),t.stroke()}t.globalAlpha=1;const m=r=>f+(r-_)/gt*H;t.font=`${N(-1)}px system-ui, sans-serif`,jt(t,j,new Set,m,F,v,a.limitLine),t.font=`${N(-1)}px system-ui, sans-serif`,t.strokeStyle=a.border,t.lineWidth=1,t.beginPath(),t.moveTo(f,v),t.lineTo(f+H,v),t.stroke(),t.fillStyle=a.textMuted,t.textAlign="center",t.textBaseline="top";const{ticks:g,step:e}=Wt(_,ct,H,Kt(t,ut,L)),p=Tt(ut,L,e||void 0);for(const r of g){const h=f+(r-_)/gt*H;t.beginPath(),t.moveTo(h,v),t.lineTo(h,v+4),t.stroke(),t.fillText(p.tick(r),h,v+6)}p.unitLabel&&(t.save(),t.font=`${N(-1)}px system-ui, sans-serif`,t.fillStyle=a.textMuted,t.textAlign="right",t.textBaseline="top",t.fillText(`(${p.unitLabel})`,f+H,v+20),t.restore())}function y(o){const{plotX:d,plotMaxWidth:s,barWidth:t}=ot;if(o<d||o>d+s)return-1;const a=Math.floor((o-d)/t);return a>=0&&a<T.length?a:-1}M.addEventListener("mousemove",o=>{const d=M.getBoundingClientRect(),s=y(o.clientX-d.left);if(s!==P&&(P=s,R()),s>=0){const t=T[s],a=w.map((f,H)=>`<span style="${pe(I(H))};margin-right:4px"></span>${wt(`${f.groupKey}: ${f.counts[s]}`)}`).join("<br>");C.innerHTML=`<strong>${wt(`${xt(t.rangeLow,L,"engineering")} \u2013 ${xt(t.rangeHigh,L,"engineering")}`)}</strong><br>${a}`,C.style.display="block",It(C,l,o.clientX,o.clientY)}else C.style.display="none"}),M.addEventListener("mouseleave",()=>{P!==-1&&(P=-1,R()),C.style.display="none"}),n.onSelectBucket&&S&&(M.style.cursor="pointer",M.addEventListener("click",o=>{const d=y(o.clientX-M.getBoundingClientRect().left);if(d<0||i===null)return;const s=b?S.filter(a=>a.key===b):S,t=At(s.flatMap(a=>a.items),i,T,d,ht);t.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:T[d].rangeLow,high:T[d].rangeHigh,items:t,...b?{group:b}:{}},o))})),rt=Dt(l,()=>R()),R()}q();function Ut(c){vt.set(c)&&(i=c,q())}function qt(c){at.set(c)&&q()}return{card:l,setTest:Ut,setAxisPrefs:qt,destroy:()=>rt?.disconnect()}}
1
+ import{buildTestHistogramData as ee,collectTestValues as Bt,buildTestHistogramSeries as ne,testValueExtent as At,diesInBucket as $t}from"../../stats/histogram.js";import{excludedNote as Et}from"../../renderer/valueFilter.js";import{SPACE as at,fontPx as K,FONT as Wt,CLR as Dt}from"../toolbar.js";import{fmt as bt}from"../../renderer/fmt.js";import{niceStep as ie,fitTicks as It}from"../../renderer/axisTicks.js";import{QUANTITY as oe,categorical as se}from"./palette.js";import{cardShell as le,observeResize as Pt,makeTooltip as ae,attachChartTip as re,positionChartTooltip as Rt,makeLinkedTestSelect as ce,makeWaferSelect as ue,makeLinkedAxisPrefs as de,renderEmptyState as Tt,chartFillHeight as Kt,applyCanvasFlow as Nt,makeAxisFormat as Mt,horizontalTickSpacing as Ot,PADDING as ht,robustFence as Ft,shouldIncludeLimitsByDefault as zt,drawOffAxisLimits as me,resolveAxisRange as he,limitLines as Gt,limitExtent as fe,hasBothLimitKinds as ge,stackLabelRows as pe,strokeLimitLine as xe,chartSwatchCss as be,makeSeriesLegendItem as ye,prepareCanvas as Vt}from"./chartShell.js";import{escHtml as wt,maxOf as ke}from"../../core/utils.js";const vt=230,jt=36,Te=18;function Xt(n){const E=new Set(n.map(A=>A.kind)).size;return Te+Math.max(0,E-1)*(K(-1)+2)}function _t(n,E,A,V,et,k,a){n.font=`${K(-1)}px system-ui, sans-serif`;const x=E.filter(i=>!A.has(i.value)).map(i=>{const S=V(i.value),N=n.measureText(i.label).width;return{l:i,x:S,start:S-N/2,end:S+N/2}}),U=pe(x),nt=K(-1)+2;x.forEach(({l:i,x:S},N)=>{xe(n,i,a,S,et,S,k),n.fillStyle=a,n.textAlign="center",n.textBaseline="bottom",n.fillText(i.label,S,et-2-U[N]*nt)})}function Yt(n,E,A,V,et,k,a,x=4){const U=Math.max(1,ie(k/x)),nt=V-A;n.save(),n.font=`${K(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(let i=0;i<=k+1e-9;i+=U){const S=V-i/(k||1)*nt;n.strokeStyle=a.grid,n.lineWidth=1,n.beginPath(),n.moveTo(E,S),n.lineTo(E+et,S),n.stroke(),n.fillStyle=a.text,n.fillText(String(Math.round(i)),E-4,S)}n.strokeStyle=a.axis,n.lineWidth=1,n.beginPath(),n.moveTo(E,A),n.lineTo(E,V),n.stroke(),n.restore()}export function renderHistogramPanel(n){const{title:E="Test value distribution",items:A,testDefs:V,onSaveImage:et,groups:k}=n,{card:a,body:x,controlsRow:U}=le(E,et,n.ownerDocument),nt=V.filter(s=>s.testNumber!==void 0);let i=n.selectedTestNumber??nt[0]?.testNumber??null;const S=()=>(k?k.flatMap(s=>s.items):A).flatMap(s=>s.dies??[]);let N=null,it=0,ft;const St=ce(nt,i,s=>{i=s,q(),n.onTestChange?.(s)},{maxWidth:"200px",ownerDocument:a.ownerDocument}),Qt=St.el;U.appendChild(Qt);const gt=A.length>1?ue(A,N,s=>{N=s,q()},{ownerDocument:a.ownerDocument}):null;gt&&U.appendChild(gt);function Ut(s){return b===s||s!==null&&!(k??[]).some(L=>L.key===s)?!1:(b=s,q(),!0)}const yt=a.ownerDocument.createElement("span");Object.assign(yt.style,{display:"inline-flex",gap:at.lg,alignItems:"center"}),U.appendChild(yt);const rt=de(yt,n.axisPrefs,s=>{n.onAxisPrefsChange?.(s),q()},a.ownerDocument),C=ae(a);let ct=null,b=null;function ot(s){const L=V.find(D=>D.testNumber===s),j=Gt(L,rt.get().limits),{lo:T,hi:M}=fe(j);return{unit:L?.unit,lines:j,limitLow:T,limitHigh:M,hasLimits:Gt(L).length>0,hasBothKinds:ge(L)}}function q(){const{includeLimits:s,clipOutliers:L}=rt.get();if(ct?.disconnect(),ct=null,x.innerHTML="",i===null){Tt(x,"No parametric test data available for a histogram.");return}const j=!!k&&k.length>0;let T=!1,M;if(j){const{limitLow:u,limitHigh:m}=ot(i),g=k.flatMap(c=>c.items),{min:e,max:p}=At(g,i);if(T=s??zt(e,p,u,m),L){const c=Bt(g,i),h=Ft(c);h&&(M={lo:Math.max(e,h.lo),hi:Math.min(p,h.hi)},it=c.reduce((Z,R)=>Z+(R<M.lo||R>M.hi?1:0),0))}M||(it=0),ft=M}const D=j?ne(k,i,16,T?ot(i).limitLow:void 0,T?ot(i).limitHigh:void 0,M):null;if(gt&&(gt.style.display=D?"none":""),D){const{hasLimits:u,hasBothKinds:m}=ot(i);if(rt.sync(T,u,m),D.series.length===0){Tt(x,"No parametric test data available for a histogram.");return}qt(D);return}const O=N!==null?[A[N]]:A,{unit:W,lines:X,limitLow:w,limitHigh:_,hasLimits:ut,hasBothKinds:pt}=ot(i),dt=Bt(O,i),{min:mt,max:xt}=At(O,i),I=s??zt(mt,xt,w,_);rt.sync(I,ut,pt);const st=L?Ft(dt):null,P=st?{lo:Math.max(mt,st.lo),hi:Math.min(xt,st.hi)}:void 0;it=P?dt.filter(u=>u<P.lo||u>P.hi).length:0,ft=P;const y=ee(O,i,16,I?w:void 0,I?_:void 0,P);if(y.length===0){Tt(x,"No parametric test data available for a histogram.");return}const o=Math.max(ke(y.map(u=>u.count)),1),d=a.ownerDocument.createElement("div");d.dataset.wmapCaption="1",Object.assign(d.style,{fontSize:Wt.body,color:Dt.label,marginBottom:at.xxs}),d.textContent=`max ${o} dies/bucket`+Et(S(),i)+(it?` \xB7 ${it} value${it===1?"":"s"} outside clipped range`:"")+(n.onSelectBucket?" \xB7 click a bar to chart or tabulate its dies":""),x.appendChild(d);const l=a.ownerDocument.createElement("canvas");l.style.display="block",l.style.cursor="default",x.appendChild(l);let t=-1;const r=y[0].rangeLow,f=y[y.length-1].rangeHigh,H=f-r||1,F=Math.max(Math.abs(r),Math.abs(f));function J(u){const m=ht+36,g=l.clientWidth-m-ht,e=Xt(X),p=u-jt-e;return{plotX:m,plotMaxWidth:Math.max(10,g),plotMaxHeight:p,plotTop:e}}function v(u){const{plotX:m,plotMaxWidth:g}=J(vt);if(u<m||u>m+g)return-1;const e=Math.floor((u-m)/g*y.length);return e>=0&&e<y.length?e:-1}function $(){Nt(l,d);const u=x.clientWidth,m=Kt(a,x,l,vt),g=Vt(l,a,u,m);if(!g)return;const{ctx:e,theme:p}=g,{plotX:c,plotMaxWidth:h,plotMaxHeight:Z,plotTop:R}=J(m),B=R+Z,tt=h/y.length;Yt(e,c,R,B,h,o,{text:p.textMuted,axis:p.border,grid:p.grid}),y.forEach((G,Q)=>{const Lt=G.count/o*Z,Ht=c+Q*tt,Ct=B-Lt;e.fillStyle=Q===t?p.text:oe,e.globalAlpha=Q===t?1:.7,e.fillRect(Ht+1,Ct,Math.max(1,tt-2),Lt),e.globalAlpha=1,Q===t&&(e.fillStyle=p.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(`${G.count}`,Ht+tt/2,Ct-2))});const lt=G=>c+(G-r)/H*h;e.font=`${K(-1)}px system-ui, sans-serif`;const{offAxis:z}=he({dataMin:r,dataMax:f,limits:X,includeLimits:!1});me(e,z,{left:c,right:c+h,top:R,bottom:B},"horizontal",p.limitLine,Mt(F,W).tick),_t(e,X,new Set(z.map(G=>G.value)),lt,R,B,p.limitLine),e.font=`${K(-1)}px system-ui, sans-serif`,e.strokeStyle=p.border,e.lineWidth=1,e.beginPath(),e.moveTo(c,B),e.lineTo(c+h,B),e.stroke(),e.fillStyle=p.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:Y,step:te}=It(r,f,h,Ot(e,F,W)),kt=Mt(F,W,te||void 0);for(const G of Y){const Q=c+(G-r)/H*h;e.beginPath(),e.moveTo(Q,B),e.lineTo(Q,B+4),e.stroke(),e.fillText(kt.tick(G),Q,B+6)}kt.unitLabel&&(e.save(),e.font=`${K(-1)}px system-ui, sans-serif`,e.fillStyle=p.textMuted,e.textAlign="right",e.textBaseline="top",e.fillText(`(${kt.unitLabel})`,c+h,B+20),e.restore())}l.addEventListener("mousemove",u=>{const m=l.getBoundingClientRect(),g=v(u.clientX-m.left);if(g!==t&&(t=g,$()),g>=0){const e=y[g];C.innerHTML=`<strong>${wt(`${bt(e.rangeLow,W,"engineering")} \u2013 ${bt(e.rangeHigh,W,"engineering")}`)}</strong><br>${e.count} dies`+(n.onSelectBucket&&e.count>0?"<br><em>click to chart or tabulate these dies</em>":""),C.style.display="block",Rt(C,a,u.clientX,u.clientY)}else C.style.display="none"}),l.addEventListener("mouseleave",()=>{t!==-1&&(t=-1,$()),C.style.display="none"}),n.onSelectBucket&&(l.style.cursor="pointer",l.addEventListener("click",u=>{const m=v(u.clientX-l.getBoundingClientRect().left);if(m<0||i===null||y[m].count===0)return;const g=$t(O,i,y,m,ft);g.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:y[m].rangeLow,high:y[m].rangeHigh,items:g},u))})),ct=Pt(a,()=>$()),$()}function qt(s){const{unit:L,lines:j}=ot(i),T=s.ranges,M=s.series,D=se;b&&!M.some(o=>o.groupKey===b)&&(b=null);const O=Math.max(1,...M.flatMap(o=>o.counts)),W=a.ownerDocument.createElement("div");W.dataset.wmapCaption="1",Object.assign(W.style,{fontSize:Wt.body,color:Dt.label,marginBottom:at.xxs}),W.textContent=`${M.length} groups \xB7 max ${O} dies/bucket`+Et(S(),i)+(n.onSelectBucket?" \xB7 click a column to chart or tabulate its dies":""),x.appendChild(W);const X=a.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:at.sm,marginTop:at.md,marginBottom:at.xl}),M.forEach((o,d)=>{const l=ye(o.groupKey,D(d),a.ownerDocument),t=l.el;re(t,a,C,`${o.groupKey} \u2014 click to emphasize (dim the rest)`),l.setState({selected:b===o.groupKey,dimmed:b!==null&&b!==o.groupKey}),t.addEventListener("click",()=>{const r=b===o.groupKey?null:o.groupKey;Ut(r),n.onGroupChange?.(r)}),X.appendChild(t)}),x.appendChild(X);const w=a.ownerDocument.createElement("canvas");w.style.display="block",w.style.cursor="default",x.appendChild(w);const _=T[0].rangeLow,ut=T[T.length-1].rangeHigh,pt=ut-_||1,dt=Math.max(Math.abs(_),Math.abs(ut)),mt=o=>{const d=(o.ownerDocument.defaultView??window).getComputedStyle(o);return o.offsetHeight+(parseFloat(d.marginTop)||0)+(parseFloat(d.marginBottom)||0)},xt=()=>mt(W)+mt(X);let I=-1,st={plotX:ht+36,plotMaxWidth:10,barWidth:10};function P(){Nt(w,xt());const o=x.clientWidth,d=Kt(a,x,w,vt),l=Vt(w,a,o,d);if(!l)return;const{ctx:t,theme:r}=l,f=ht+36,H=Math.max(10,o-f-ht),F=Xt(j),J=d-jt-F,v=F+J,$=H/T.length;st={plotX:f,plotMaxWidth:H,barWidth:$},Yt(t,f,F,v,H,O,{text:r.textMuted,axis:r.border,grid:r.grid}),I>=0&&(t.fillStyle=r.bgHover,t.globalAlpha=.5,t.fillRect(f+I*$,F,$,J),t.globalAlpha=1);const u=M.map((c,h)=>({s:c,i:h})).sort((c,h)=>(c.s.groupKey===b?1:0)-(h.s.groupKey===b?1:0));for(const{s:c,i:h}of u){const Z=b===c.groupKey,R=b!==null&&!Z,B=D(h);t.strokeStyle=B,t.fillStyle=B,t.lineWidth=Z?2:1,t.globalAlpha=R?.12:b?.32:.22,t.beginPath(),t.moveTo(f,v),c.counts.forEach((tt,lt)=>{const z=f+lt*$,Y=v-tt/O*J;t.lineTo(z,Y),t.lineTo(z+$,Y)}),t.lineTo(f+H,v),t.closePath(),t.fill(),t.globalAlpha=R?.3:1,t.beginPath(),c.counts.forEach((tt,lt)=>{const z=f+lt*$,Y=v-tt/O*J;lt===0?t.moveTo(z,Y):t.lineTo(z,Y),t.lineTo(z+$,Y)}),t.stroke()}t.globalAlpha=1;const m=c=>f+(c-_)/pt*H;t.font=`${K(-1)}px system-ui, sans-serif`,_t(t,j,new Set,m,F,v,r.limitLine),t.font=`${K(-1)}px system-ui, sans-serif`,t.strokeStyle=r.border,t.lineWidth=1,t.beginPath(),t.moveTo(f,v),t.lineTo(f+H,v),t.stroke(),t.fillStyle=r.textMuted,t.textAlign="center",t.textBaseline="top";const{ticks:g,step:e}=It(_,ut,H,Ot(t,dt,L)),p=Mt(dt,L,e||void 0);for(const c of g){const h=f+(c-_)/pt*H;t.beginPath(),t.moveTo(h,v),t.lineTo(h,v+4),t.stroke(),t.fillText(p.tick(c),h,v+6)}p.unitLabel&&(t.save(),t.font=`${K(-1)}px system-ui, sans-serif`,t.fillStyle=r.textMuted,t.textAlign="right",t.textBaseline="top",t.fillText(`(${p.unitLabel})`,f+H,v+20),t.restore())}function y(o){const{plotX:d,plotMaxWidth:l,barWidth:t}=st;if(o<d||o>d+l)return-1;const r=Math.floor((o-d)/t);return r>=0&&r<T.length?r:-1}w.addEventListener("mousemove",o=>{const d=w.getBoundingClientRect(),l=y(o.clientX-d.left);if(l!==I&&(I=l,P()),l>=0){const t=T[l],r=M.map((f,H)=>`<span style="${be(D(H))};margin-right:4px"></span>${wt(`${f.groupKey}: ${f.counts[l]}`)}`).join("<br>");C.innerHTML=`<strong>${wt(`${bt(t.rangeLow,L,"engineering")} \u2013 ${bt(t.rangeHigh,L,"engineering")}`)}</strong><br>${r}`,C.style.display="block",Rt(C,a,o.clientX,o.clientY)}else C.style.display="none"}),w.addEventListener("mouseleave",()=>{I!==-1&&(I=-1,P()),C.style.display="none"}),n.onSelectBucket&&k&&(w.style.cursor="pointer",w.addEventListener("click",o=>{const d=y(o.clientX-w.getBoundingClientRect().left);if(d<0||i===null)return;const l=b?k.filter(r=>r.key===b):k,t=$t(l.flatMap(r=>r.items),i,T,d,ft);t.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:T[d].rangeLow,high:T[d].rangeHigh,items:t,...b?{group:b}:{}},o))})),ct=Pt(a,()=>P()),P()}q();function Jt(s){St.set(s)&&(i=s,q())}function Zt(s){rt.set(s)&&q()}return{card:a,setTest:Jt,setAxisPrefs:Zt,destroy:()=>ct?.disconnect()}}
@@ -1 +1 @@
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
+ 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:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],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","wafers","dies"]:["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","wafers","dies"]:["statistics","dies"]})}
@@ -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 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
+ 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:"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")}]:[],{section:"Tables",label:"Dies",unavailable:o,open:l("dies","Dies")}]}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}
@@ -2,6 +2,7 @@ export { WMAP_VERSION, WMAP_BUILD_TIME } from './version.js';
2
2
  export type { ToCanvasOptions, ViewportTransform } from './toCanvas.js';
3
3
  export { renderWaferMap } from './renderWaferMap.js';
4
4
  export type { RenderOptions, WaferMapController, WaferViewOptions, WaferPreferences, WaferDisplayState } from './renderWaferMap.js';
5
+ export { WAFER_PREFERENCE_KEYS } from './renderWaferMap.js';
5
6
  export { renderWaferGallery } from './renderWaferGallery.js';
6
7
  export type { WaferMapDisplayItem, WaferMapDisplayItemFactory, GalleryOptions, GalleryController } from './renderWaferGallery.js';
7
8
  export type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
@@ -1 +1 @@
1
- export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
1
+ export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{WAFER_PREFERENCE_KEYS}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
@@ -9,6 +9,7 @@ import type { PlotSpec } from '../stats/plotSpec.js';
9
9
  import type { BinColors } from '../renderer/binColors.js';
10
10
  import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
11
11
  import type { SweepSpec } from '../stats/sweep.js';
12
+ import { type AxisPrefs } from './charts/chartShell.js';
12
13
  export type InsightsView = 'overview' | 'distributions' | 'correlation' | 'sweeps' | 'data' | 'plot';
13
14
  /** Public option shape for `RenderOptions.insights`/`GalleryOptions.insights`. */
14
15
  export interface InsightsOptions {
@@ -83,6 +84,10 @@ export interface InsightsOptions {
83
84
  defaultOpen?: boolean;
84
85
  }
85
86
  export interface InsightsTabDeps {
87
+ /** The charts' axis settings to start from: the host's `chart*` preferences (see `axisPrefsFromOptions`). */
88
+ initialAxisPrefs?: AxisPrefs;
89
+ /** Called when the reader changes an axis setting, so the renderer can report it as a preference. */
90
+ onAxisPrefsChange?: (prefs: AxisPrefs) => void;
86
91
  /** 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
92
  attributes?: Record<string, FacetCuration>;
88
93
  /** 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. */
@@ -185,6 +190,8 @@ export interface InsightsTabHandle {
185
190
  render: () => void;
186
191
  /** Tears down every live panel's observers and removes `el`. */
187
192
  destroy: () => void;
193
+ /** Adopt axis settings set from outside (the host's `setOptions`), in every chart. */
194
+ setAxisPrefs: (prefs: AxisPrefs) => void;
188
195
  }
189
196
  type Item = FacetItem & {
190
197
  dies: Die[];
@@ -1 +1 @@
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()}}}
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 le}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 de,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as ce,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 ue,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 Pt}from"./summaryPanel.js";import{runChunked as At}from"./chunked.js";import{buildRegionYieldData as pe,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as It,diesInRegion as Et}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as fe}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:Pe,getLotStats:me,getBinColors:be,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,he={...Je,...v.attributes},Ae=v.showMetadataStrip??!0,z=v.contentInset??de,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Ie=de,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Ie});const A=f.createElement("div");Object.assign(A.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}),A.setAttribute("role","tablist"),A.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(A.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(A),Y.appendChild(U);const Ee=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,ge="statistics",ye="wide",I=null,E=null,K=v.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,te=(e,n,r=!1)=>{K=e;for(const l of ee.values())for(const i of l)i!==n&&i.setAxisPrefs(e);r||v.onAxisPrefsChange?.(e)},ne=e=>{E!==e&&(E=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function oe(e,n,r){R?.(e,n,r)}function ie(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??I??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});le({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&&le(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function re(e){return R?{open:(n,r)=>oe(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 Pe().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} ${de} ${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",ce(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=ue(f),u=be();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=me?.(),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(P=>P.percent).sort((P,_)=>P-_),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"&&oe(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:ie(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 P=n.find(X=>X.key===S.groupKey);if(!P)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,P.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),se={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",P=p.binCode;Q(S,e,P===void 0?`with no ${B} bin recorded`:`in ${B} bin ${P}`,_=>(g==="hbin"?_.hbin:_.sbin)===P)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(se,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function ae(){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",!Ae)return;const n=Pt(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 Et(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=pe(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=fe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=pe(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=fe({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)=>It(g,C.reticle),o=pe(u,i,c,g=>e[g].passBins,t);if(o.length){const g=fe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:Math.max(1,Math.floor(w.width)),height:Math.max(1,Math.floor(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=ae();let b=null;const y=At($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=ae();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=ae();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"}),ce(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=me?.(),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:ge,onViewChange:s=>{ge=s,c()},diesLayout:ye,onDiesLayoutChange:s=>{ye=s}})}function ze(e,n,r,l){const i=ue(f),u=re(e),c=t=>o=>te(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:I??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>ne(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:ie(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:I??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>ne(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"),se=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 ${se}${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:I??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)=>oe(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:ie(e),ownerDocument:f}),y=t=>{I=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:I??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=ue(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:be().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>te(c,i),onOpen:re(e)?.open,openActionLabel:re(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`;le(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="",A.innerHTML="";for(const o of Ee)A.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:he}).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,E=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,he)??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)}))}E!==null&&!u?.some(o=>o.key===E)&&(E=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",E,o=>ne(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"}),ce(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}A.appendChild(l),c&&A.appendChild(c);const s=E!==null?u?.find(o=>o.key===E):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);I!==null&&!b.some(o=>o.testNumber===I)&&(I=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()},setAxisPrefs:e=>te(e,null,!0)}}
@@ -4,7 +4,7 @@ import { type UserGuideExtension } from './guideWindow.js';
4
4
  import { type Die } from '../core/dies.js';
5
5
  import type { WaferViewOptions } from './renderWaferMap.js';
6
6
  import type { RenderableWaferMap } from './renderWaferMap.js';
7
- import type { LotStatsSummary } from '../stats/types.js';
7
+ import type { LotStatsSummary, StatsSummary } from '../stats/types.js';
8
8
  import { type WarningsOptions } from './warnings.js';
9
9
  import type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
10
10
  import { type WaferAttributeDef } from '../stats/facets.js';
@@ -137,6 +137,16 @@ export interface GalleryOptions {
137
137
  onSaveText?: SaveTextHandler;
138
138
  /** Precomputed lot-level stats summary. Enables the summary panel toggle button in the control bar. */
139
139
  lotStatsSummary?: LotStatsSummary;
140
+ /**
141
+ * Called after the gallery re-analyses the lot itself: when the reader asks, from the lot Findings section, for the
142
+ * test-value analysis the summaries record as not run (`stats.testValueAnalysis`). `summaries` holds each item's
143
+ * new summary in item order, `lotStatsSummary` the lot's; the gallery already shows them. Keep them so the host's
144
+ * own copies (reports, logs) match.
145
+ */
146
+ onStatsSummaryChange?: (change: {
147
+ summaries: StatsSummary[];
148
+ lotStatsSummary: LotStatsSummary;
149
+ }) => void;
140
150
  /**
141
151
  * Options for the always-available Summary panel alongside the gallery
142
152
  * grid — a "Lot" tab with full lot-level stats (metadata, yield, bin
@@ -151,9 +161,12 @@ export interface GalleryOptions {
151
161
  /**
152
162
  * A row at the top of the Findings section stating that a category of finding
153
163
  * is not present, and optionally offering to compute it — see
154
- * {@link FindingsNotice}. wmap never raises this itself: only the host knows
155
- * what analysis it chose to skip and what running it would cost. Replaceable
156
- * afterwards via the controller's `setFindingsNotice`.
164
+ * {@link FindingsNotice}. Replaces the built-in offer of the skipped
165
+ * test-value analysis while set.
166
+ *
167
+ * @deprecated The renderers offer the skipped test-value analysis themselves
168
+ * (from `stats.testValueAnalysis`) and report the re-run through
169
+ * `onStatsSummaryChange`. See API_REMOVALS.md.
157
170
  */
158
171
  findingsNotice?: FindingsNotice;
159
172
  /**
@@ -228,7 +241,9 @@ export interface GalleryController {
228
241
  setLotStatsSummary(summary: LotStatsSummary | undefined): void;
229
242
  /**
230
243
  * Replace the lot Findings-section notice (see `FindingsNotice`). Pass
231
- * `undefined` to clear it once the offered analysis has been run.
244
+ * `undefined` to clear it, which brings back the built-in offer.
245
+ *
246
+ * @deprecated With `findingsNotice`. See API_REMOVALS.md.
232
247
  */
233
248
  setFindingsNotice(notice: FindingsNotice | undefined): void;
234
249
  /**