@wafertools/wafermap 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/AGENTS.md +6 -6
  2. package/CHANGELOG.md +271 -0
  3. package/README.md +5 -5
  4. package/dist/packages/canvas-adapter/chartPopulation.d.ts +15 -10
  5. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +8 -1
  7. package/dist/packages/canvas-adapter/charts/barPanel.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +7 -1
  9. package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +72 -5
  13. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  14. package/dist/packages/canvas-adapter/charts/correlation.js +1 -2
  15. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +2 -0
  16. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +1 -1
  17. package/dist/packages/canvas-adapter/charts/histogram.d.ts +16 -0
  18. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  19. package/dist/packages/canvas-adapter/charts/palette.d.ts +2 -0
  20. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  21. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +27 -0
  22. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -0
  23. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +45 -0
  24. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -0
  25. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +8 -1
  26. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  27. package/dist/packages/canvas-adapter/charts/scatter.d.ts +19 -0
  28. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  29. package/dist/packages/canvas-adapter/charts/sweep.d.ts +12 -0
  30. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  31. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +7 -0
  32. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  33. package/dist/packages/canvas-adapter/charts/trend.d.ts +11 -0
  34. package/dist/packages/canvas-adapter/charts/trend.js +1 -1
  35. package/dist/packages/canvas-adapter/confirmDialog.d.ts +13 -0
  36. package/dist/packages/canvas-adapter/confirmDialog.js +1 -0
  37. package/dist/packages/canvas-adapter/dataTab.d.ts +137 -0
  38. package/dist/packages/canvas-adapter/dataTab.js +1 -0
  39. package/dist/packages/canvas-adapter/dieList.d.ts +39 -4
  40. package/dist/packages/canvas-adapter/dieList.js +6 -7
  41. package/dist/packages/canvas-adapter/drilldown.d.ts +23 -3
  42. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  43. package/dist/packages/canvas-adapter/guideWindow.d.ts +96 -0
  44. package/dist/packages/canvas-adapter/guideWindow.js +1 -0
  45. package/dist/packages/canvas-adapter/identityHeader.d.ts +19 -0
  46. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  47. package/dist/packages/canvas-adapter/index.d.ts +3 -3
  48. package/dist/packages/canvas-adapter/index.js +1 -1
  49. package/dist/packages/canvas-adapter/insightsTab.d.ts +75 -54
  50. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  51. package/dist/packages/canvas-adapter/maplessSummary.d.ts +2 -2
  52. package/dist/packages/canvas-adapter/plotEditor.d.ts +29 -0
  53. package/dist/packages/canvas-adapter/plotEditor.js +1 -0
  54. package/dist/packages/canvas-adapter/plotItems.d.ts +32 -0
  55. package/dist/packages/canvas-adapter/plotItems.js +1 -0
  56. package/dist/packages/canvas-adapter/plotModal.d.ts +30 -0
  57. package/dist/packages/canvas-adapter/plotModal.js +1 -0
  58. package/dist/packages/canvas-adapter/plotStore.d.ts +52 -0
  59. package/dist/packages/canvas-adapter/plotStore.js +1 -0
  60. package/dist/packages/canvas-adapter/plotTab.d.ts +33 -0
  61. package/dist/packages/canvas-adapter/plotTab.js +1 -0
  62. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +11 -2
  63. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  64. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +29 -2
  65. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  66. package/dist/packages/canvas-adapter/summaryPanel.d.ts +34 -10
  67. package/dist/packages/canvas-adapter/summaryPanel.js +2 -4
  68. package/dist/packages/canvas-adapter/summaryRail.d.ts +7 -0
  69. package/dist/packages/canvas-adapter/summaryRail.js +1 -0
  70. package/dist/packages/canvas-adapter/sweepEditor.d.ts +17 -0
  71. package/dist/packages/canvas-adapter/sweepEditor.js +1 -0
  72. package/dist/packages/canvas-adapter/tableExport.d.ts +22 -0
  73. package/dist/packages/canvas-adapter/tableExport.js +3 -0
  74. package/dist/packages/canvas-adapter/toolbar.d.ts +25 -97
  75. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  76. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  77. package/dist/packages/canvas-adapter/userGuideHtml.js +354 -45
  78. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  79. package/dist/packages/canvas-adapter/version.js +1 -1
  80. package/dist/packages/canvas-adapter/viewSwitch.d.ts +13 -0
  81. package/dist/packages/canvas-adapter/viewSwitch.js +1 -0
  82. package/dist/packages/canvas-adapter/virtualTable.d.ts +44 -0
  83. package/dist/packages/canvas-adapter/virtualTable.js +1 -0
  84. package/dist/packages/core/classify.d.ts +3 -2
  85. package/dist/packages/core/classify.js +1 -1
  86. package/dist/packages/core/index.d.ts +1 -1
  87. package/dist/packages/core/index.js +1 -1
  88. package/dist/packages/core/passBins.d.ts +17 -4
  89. package/dist/packages/core/passBins.js +1 -1
  90. package/dist/packages/core/reticle.d.ts +20 -0
  91. package/dist/packages/core/reticle.js +1 -1
  92. package/dist/packages/core/ringCount.d.ts +22 -0
  93. package/dist/packages/core/ringCount.js +1 -0
  94. package/dist/packages/core/tableCsv.d.ts +43 -0
  95. package/dist/packages/core/tableCsv.js +3 -0
  96. package/dist/packages/core/wafer.d.ts +15 -0
  97. package/dist/packages/core/wafer.js +1 -1
  98. package/dist/packages/renderer/binColors.d.ts +6 -6
  99. package/dist/packages/renderer/binColors.js +1 -1
  100. package/dist/packages/renderer/buildView.d.ts +1 -1
  101. package/dist/packages/renderer/buildView.js +1 -1
  102. package/dist/packages/renderer/buildWaferMap.js +1 -1
  103. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  104. package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
  105. package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
  106. package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
  107. package/dist/packages/renderer/derivedTests/parser.js +2 -2
  108. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  109. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  110. package/dist/packages/stats/binPareto.d.ts +1 -1
  111. package/dist/packages/stats/binPareto.js +1 -1
  112. package/dist/packages/stats/dieRegions.d.ts +42 -0
  113. package/dist/packages/stats/dieRegions.js +1 -0
  114. package/dist/packages/stats/facets.d.ts +8 -0
  115. package/dist/packages/stats/facets.js +1 -1
  116. package/dist/packages/stats/histogram.d.ts +27 -0
  117. package/dist/packages/stats/histogram.js +1 -1
  118. package/dist/packages/stats/index.d.ts +4 -1
  119. package/dist/packages/stats/index.js +1 -1
  120. package/dist/packages/stats/lotDrift.js +1 -1
  121. package/dist/packages/stats/lotPattern.js +1 -1
  122. package/dist/packages/stats/math.d.ts +9 -6
  123. package/dist/packages/stats/math.js +1 -1
  124. package/dist/packages/stats/metadataColumns.js +1 -1
  125. package/dist/packages/stats/patternClassification.d.ts +1 -1
  126. package/dist/packages/stats/patternClassification.js +1 -1
  127. package/dist/packages/stats/plotData.d.ts +258 -0
  128. package/dist/packages/stats/plotData.js +1 -0
  129. package/dist/packages/stats/plotId.d.ts +3 -0
  130. package/dist/packages/stats/plotId.js +1 -0
  131. package/dist/packages/stats/plotSpec.d.ts +119 -0
  132. package/dist/packages/stats/plotSpec.js +4 -0
  133. package/dist/packages/stats/presentation.d.ts +2 -0
  134. package/dist/packages/stats/presentation.js +1 -1
  135. package/dist/packages/stats/regions.d.ts +15 -0
  136. package/dist/packages/stats/regions.js +1 -1
  137. package/dist/packages/stats/renderSummaryReport.d.ts +8 -3
  138. package/dist/packages/stats/renderSummaryReport.js +15 -15
  139. package/dist/packages/stats/reportHtml.d.ts +1 -1
  140. package/dist/packages/stats/reportHtml.js +36 -29
  141. package/dist/packages/stats/scatter.d.ts +6 -0
  142. package/dist/packages/stats/scatter.js +1 -1
  143. package/dist/packages/stats/sweep.d.ts +37 -1
  144. package/dist/packages/stats/sweep.js +1 -1
  145. package/dist/packages/stats/sweepText.d.ts +14 -0
  146. package/dist/packages/stats/sweepText.js +1 -0
  147. package/dist/packages/stats/sweepXFromName.d.ts +14 -0
  148. package/dist/packages/stats/sweepXFromName.js +1 -1
  149. package/dist/packages/stats/synthesis.d.ts +14 -4
  150. package/dist/packages/stats/synthesis.js +1 -1
  151. package/dist/packages/stats/testPassRate.d.ts +6 -0
  152. package/dist/packages/stats/testPassRate.js +1 -1
  153. package/dist/packages/stats/trend.js +1 -1
  154. package/dist/packages/stats/types.d.ts +1 -1
  155. package/dist/packages/stats/yield.d.ts +15 -6
  156. package/dist/packages/stats/yield.js +1 -1
  157. package/llms.txt +15 -3
  158. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ import{escHtml as I,maxOf as fe,minOf as Oe}from"../../core/utils.js";import{fiveNumberSummary as We}from"../../stats/math.js";import{fmt as R}from"../../renderer/fmt.js";import{fitTicks as we}from"../../renderer/axisTicks.js";import{plotFootnote as Fe,plotTestNumber as ze,plotTitle as nt}from"../../stats/plotData.js";import{SPACE as te,RADIUS as ot,fontPx as me,FONT as Le,CLR as xe,markNoPrint as Re}from"../toolbar.js";import{cardShell as it,observeResize as lt,makeTooltip as st,attachChartTip as at,chartFillHeight as rt,applyCanvasFlow as ke,prepareCanvas as Me,positionChartTooltip as $e,resolveChartCanvasColors as ve,makeAxisFormat as ct,horizontalTickSpacing as ft,VERTICAL_TICK_SPACING_PX as mt,makeSeriesLegendItem as ht,renderEmptyState as qe,limitLines as ut,limitExtent as dt,stackLabelRows as He,placeClearOf as Xe,strokeLimitLine as _e,drawOffAxisLimits as gt,limitLabelSide as pt,shouldIncludeLimitsByDefault as yt}from"./chartShell.js";import{categorical as bt}from"./palette.js";import{resolveValueColorFn as Pe}from"../../renderer/colorSchemes.js";import{wirePointInteractions as xt}from"./pointInteractions.js";const M=64,je=16,k=12,he=52,kt=16,Ce=5e3;function ne(b,P,$={}){const q=P.scale==="log";let w=b.length?Oe(b):0,F=b.length?fe(b):1;q&&(w=Math.log10(Math.max(w,Number.MIN_VALUE)),F=Math.log10(Math.max(F,Number.MIN_VALUE)));const oe=(F-w)*.05||(q?.5:1);w=$.floorAtZero&&!q&&w>=0?0:w-oe,F+=oe;const a=x=>x===void 0||!Number.isFinite(x)?void 0:q?x>0?Math.log10(x):void 0:x,g=a(P.min),H=a(P.max);g!==void 0&&(w=g),H!==void 0&&(F=H),F>w||(F=w+1);const A=F-w,Z=!!P.reverse,K=x=>{const G=((q?Math.log10(Math.max(x,Number.MIN_VALUE)):x)-w)/A;return Z?1-G:G};return{lo:q?10**w:w,hi:q?10**F:F,log:q,reverse:Z,frac:K}}function Ue(b,P,$,q){if(P/b<10)return we(b,P,$,q);const w=Math.floor(Math.log10(b)),F=Math.ceil(Math.log10(P)),oe=g=>{const H=[];for(let A=w;A<=F;A++)for(const Z of g){const K=Z*10**A;K>=b&&K<=P&&H.push(K)}return H},L=oe([1]);return{ticks:L.length>=4?L:oe([1,2,5]),step:0}}export function renderPlotChart(b){const P=b.ownerDocument??document,{card:$,heading:q,body:w,controlsRow:F,setPngDecor:oe}=it("Plot",b.onSaveImage,P);$.dataset.wmapPlotCard="1";const L=st($);let a,g,H,A,Z,K=[];const x=new Set,G=new Set;let ue=null,X=-1,ce=[],z,J,D,_=null,Q=[],V=-1,Se=[],de=he;const ie=e=>bt(e),ge=e=>a?.groups[e]||"";function pe(){const e=w.clientWidth,l=Math.max(220,Math.min(420,e*.62))+(de-he),c=rt($,w,g,l);return{w:e,h:c,plotW:Math.max(10,e-M-je),plotH:Math.max(10,c-k-de)}}const le=e=>ut(e?.limits,a?.spec.limits??"both").filter(l=>e?.scale!=="log"||l.value>0),ae=(e,l)=>{const c=e.filter(Number.isFinite);if(!l.length||c.length===0)return e;const{lo:r,hi:i}=dt(l);return yt(Oe(c),fe(c),r,i)?[...e,...l.map(o=>o.value)]:e};function re(e,l,c,r,i,o,t,n){if(o.length===0)return;const f=o.filter(u=>u.value>=i.lo&&u.value<=i.hi),p=o.filter(u=>!f.includes(u)).map(u=>({value:u.value,label:u.label,side:u.value<i.lo?"lo":"hi"}));e.save(),e.font=`${me(-1)}px system-ui, sans-serif`;const h=u=>`${u.label} ${R(u.value,t.unit)}`,s=me(-1)+2;if(n==="y"){const u=f.map(m=>{const y=k+(1-i.frac(m.value))*r;return{l:m,y,start:y-6-s/2,end:y-6+s/2}}),T=He(u,1),d=u.length?fe(u.map(m=>e.measureText(h(m.l)).width))+8:0;u.forEach(({l:m,y},S)=>{e.globalAlpha=.7,_e(e,m,l,M,y,M+c,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const v=M+3+T[S]*d,U=Xe(Se,{x0:v,x1:v+e.measureText(h(m)).width,y0:y-4-s+2,y1:y-4+2},s);e.fillText(h(m),v,U.y1-2)})}else{const u=f.map(d=>{const m=M+i.frac(d.value)*c,y=e.measureText(h(d)).width,S=pt(m,y,M,M+c,d.end==="lo");return{l:d,x:m,side:S,start:S<0?m-3-y:m+3,end:S<0?m-3:m+3+y}}),T=He(u,4);u.forEach(({l:d,x:m,side:y,start:S,end:v},U)=>{e.globalAlpha=.7,_e(e,d,l,m,k,m,k+r),e.globalAlpha=1,e.fillStyle=l,e.textAlign=y<0?"right":"left",e.textBaseline="top";const C=k+2+T[U]*s,E=Xe(Se,{x0:S,x1:v,y0:C,y1:C+s},s);e.fillText(h(d),m+y*3,E.y0)})}e.restore(),gt(e,p,{left:M,right:M+c,top:k,bottom:k+r},n==="y"?"vertical":"horizontal",l,u=>R(u,t.unit))}function Ee(e,l,c,r){return ct(Math.max(Math.abs(l),Math.abs(c)),e.unit,r)}function Ae(e,l){return l?`${e.label} (${l})`:e.label}function ye(e,l,c,r,i,o,t,n,f,p){Se=[],e.font=`${me(-1)}px system-ui, sans-serif`;const h=()=>mt,s=n.log?Ue(n.lo,n.hi,o,h):we(n.lo,n.hi,o,h),u=Ee(p,n.lo,n.hi,s.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let T="";if("labels"in t){const d=t.labels.length;t.labels.forEach((m,y)=>{const S=M+(y+.5)/d*i,v=m.length>22?`${m.slice(0,21)}\u2026`:m;t.rotate?(e.save(),e.translate(S,k+o+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(v,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(v,S,k+o+4))})}else{const d=ft(e,Math.max(Math.abs(t.lo),Math.abs(t.hi)),f.unit),m=t.log?Ue(t.lo,t.hi,i,d):we(t.lo,t.hi,i,d),y=Ee(f,t.lo,t.hi,m.step||void 0);T=y.unitLabel;for(const S of m.ticks){const v=M+t.frac(S)*i;e.beginPath(),e.moveTo(v,k),e.lineTo(v,k+o),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y.tick(S),v,k+o+4)}}for(const d of s.ticks){const m=k+(1-n.frac(d))*o;e.beginPath(),e.moveTo(M,m),e.lineTo(M+i,m),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(u.tick(d),M-4,m)}e.font=`${me(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Ae(f,T),M+i/2,r-6),e.save(),e.translate(14,k+o/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Ae(p,u.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(M,k),e.lineTo(M,k+o),e.moveTo(M,k+o),e.lineTo(M+i,k+o),e.stroke()}function Ye(){if(!a||!g||a.marks?.type!=="scatter"||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,n=a.marks.points,f=x.size===0?n:n.filter(E=>x.has(E.group)),p=a.colorScale,h=Pe(),s=le(a.x),u=le(a.y),T=ne(ae(n.map(E=>E.x),s),a.x),d=ne(ae(n.map(E=>E.y),u),a.y);z={x:T,y:d,plotW:r,plotH:i},ye(t,e,l,c,r,i,T,d,a.x,a.y),re(t,e.limitLine,r,i,T,s,a.x,"x"),re(t,e.limitLine,r,i,d,u,a.y,"y");const m=f.length>Ce?Math.ceil(f.length/Ce):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(f.length/m))),ce=[];const y=M,S=M+r,v=k,U=k+i;for(let E=0;E<f.length;E+=m){const N=f[E],se=M+T.frac(N.x)*r,Y=k+(1-d.frac(N.y))*i;se<y||se>S||Y<v||Y>U||(ce.push({p:N,cx:se,cy:Y}),t.beginPath(),t.arc(se,Y,2.5,0,Math.PI*2),t.fillStyle=p&&N.value!==void 0?h((N.value-p.lo)/(p.hi-p.lo||1)):ie(N.group),t.fill())}t.globalAlpha=1;const C=ue?ce.find(E=>E.p===ue):void 0;if(C&&(t.beginPath(),t.arc(C.cx,C.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),G.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let E=0;for(const N of G)if(!(x.size>0&&!x.has(N.group))){if(++E>Ce)break;t.beginPath(),t.arc(M+T.frac(N.x)*r,k+(1-d.frac(N.y))*i,4,0,Math.PI*2),t.stroke()}}}function Ge(){if(J=void 0,!a||a.marks?.type!=="histogram"||!a.x)return;const e=a.marks.values,l=e.flat();if(l.length===0)return;const c=ne(ae(l,le(a.x)),a.x),r=Math.max(1,a.spec.bins??kt),i=c.log?Math.log10(c.lo):c.lo,o=c.log?Math.log10(c.hi):c.hi,t=Array.from({length:r+1},(f,p)=>{const h=i+(o-i)*p/r;return c.log?10**h:h}),n=e.map(()=>new Array(r).fill(0));e.forEach((f,p)=>{for(const h of f){const s=c.log?h>0?Math.log10(h):NaN:h;if(!Number.isFinite(s)||s<i||s>o)continue;const u=Math.min(r-1,Math.floor((s-i)/(o-i)*r));n[p][u]++}}),J={edges:t,counts:n,maxCount:Math.max(1,...n.map(f=>fe(f)))}}function De(){if(!a||!g||!J||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,{edges:n,counts:f,maxCount:p}=J,h=ne([n[0],n[n.length-1]],{...a.x,min:n[0],max:n[n.length-1]}),s=ne([0,p],{label:a.y.label,scale:"linear",min:0,max:p*1.05});z={x:h,y:s,plotW:r,plotH:i},ye(t,e,l,c,r,i,h,s,a.x,a.y),re(t,e.limitLine,r,i,h,le(a.x),a.x,"x");const u=f.map((d,m)=>m).filter(d=>x.size===0||x.has(d)),T=u.length>1;for(const d of u)t.globalAlpha=T?.55:.85,t.fillStyle=ie(d),f[d].forEach((m,y)=>{if(m===0)return;const S=M+Math.min(h.frac(n[y]),h.frac(n[y+1]))*r,v=M+Math.max(h.frac(n[y]),h.frac(n[y+1]))*r,U=k+(1-s.frac(m))*i;t.fillRect(S,U,Math.max(1,v-S-1),k+i-U)});if(t.globalAlpha=1,X>=0){const d=M+Math.min(h.frac(n[X]),h.frac(n[X+1]))*r,m=M+Math.max(h.frac(n[X]),h.frac(n[X+1]))*r;t.lineWidth=1.5,t.strokeStyle=e.text,t.strokeRect(d,k,Math.max(1,m-d),i)}}function Ve(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="box"&&e.type!=="bar")return;ke(g,A??0);const l=ve($),c=g.getContext("2d");let r=0;c&&(c.font=`${me(-1)}px system-ui, sans-serif`,r=fe(e.categories.map(C=>c.measureText(C.length>22?`${C.slice(0,21)}\u2026`:C).width)));const i=Math.max(10,w.clientWidth-M-je)/Math.max(1,e.categories.length),o=r+8>i;de=o?he+Math.min(110,r*.72):he;const{w:t,h:n,plotW:f,plotH:p}=pe(),h=Me(g,$,t,n);if(!h)return;const{ctx:s}=h,u=C=>C.filter(Number.isFinite),T=le(a.y),d=ne(ae(e.type==="bar"?[...u(e.values.flat()),0]:u(e.cells.flat(2)),T),a.y,{floorAtZero:e.type==="bar"});z={x:d,y:d,plotW:f,plotH:p},ye(s,l,t,n,f,p,{labels:e.categories,rotate:o},d,a.x,a.y),re(s,l.limitLine,f,p,d,T,a.y,"y");const m=e.categories.length,y=a.groups.length,S=f/m,v=S*.8/y;D={slotW:S,gw:v,n:m,groups:y,plotW:f};const U=d.log?k+p:k+(1-d.frac(0))*p;for(let C=0;C<y;C++){if(x.size>0&&!x.has(C))continue;const E=ie(C);for(let N=0;N<m;N++){const se=M+N*S+S*.1+C*v;if(e.type==="bar"){const Y=e.values[C][N];if(!Number.isFinite(Y))continue;const j=k+(1-d.frac(Y))*p;s.fillStyle=E,s.globalAlpha=.9,s.fillRect(se+1,Math.min(j,U),Math.max(1,v-2),Math.max(1,Math.abs(U-j))),s.globalAlpha=1}else{const Y=e.cells[C][N];if(Y.length===0)continue;const j=se+v/2,ee=Math.max(3,Math.min(v*.7,46)),O=We(Float64Array.from(Y)),W=be=>k+(1-d.frac(be))*p;if(s.strokeStyle=E,s.fillStyle=E,s.lineWidth=1.5,Y.length===1){s.beginPath(),s.arc(j,W(O.median),3,0,Math.PI*2),s.fill();continue}s.beginPath(),s.moveTo(j,W(O.min)),s.lineTo(j,W(O.max)),s.stroke();for(const be of[O.min,O.max])s.beginPath(),s.moveTo(j-ee/4,W(be)),s.lineTo(j+ee/4,W(be)),s.stroke();s.globalAlpha=.35,s.fillRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.globalAlpha=1,s.strokeRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.lineWidth=2.5,s.beginPath(),s.moveTo(j-ee/2,W(O.median)),s.lineTo(j+ee/2,W(O.median)),s.stroke()}}}if(_){const C=M+_.c*S+S*.1+_.g*v;s.lineWidth=1.5,s.strokeStyle=l.text,s.strokeRect(C,k,v,p)}}function Ie(e){if(!D||!g)return null;const l=g.getBoundingClientRect(),c=e.clientX-l.left-M;if(c<0||c>D.plotW)return null;const r=Math.min(D.n-1,Math.floor(c/D.slotW)),i=Math.floor((c-r*D.slotW-D.slotW*.1)/D.gw);return i<0||i>=D.groups?null:{g:i,c:r}}function Ze(e){const l=a,c=l.marks,r=l.level==="die"?"dies":"wafers",i=c.cells[e.g][e.c],o=`<strong>${I(c.categories[e.c])}${l.groups.length>1?` \xB7 ${I(ge(e.g))}`:""}</strong><br>`,t=l.y?.unit;if(i.length===0)return`${o}no ${r}`;const n=`${i.length.toLocaleString("en-GB")} ${r}`,f=c.categoryItems&&b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"";if(c.type==="bar"){const h=c.values[e.g][e.c];return`${o}${I(`${l.y.label}: ${R(h,t)}`)}<br>${I(n)}${f}`}const p=We(Float64Array.from(i));return`${o}${["max","q3","median","q1","min"].map(h=>I(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[h]}: ${R(p[h],t)}`)).join("<br>")}<br>${I(n)}${f}`}function Ke(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="line")return;ke(g,A??0);const l=ve($),{w:c,h:r,plotW:i,plotH:o}=pe(),t=Me(g,$,c,r);if(!t)return;const{ctx:n}=t,f=le(a.x),p=le(a.y),h=ne(ae(e.xs,f),a.x),s=ne(ae(e.values.flat().filter(Number.isFinite),p),a.y);z={x:h,y:s,plotW:i,plotH:o},ye(n,l,c,r,i,o,h,s,a.x,a.y),re(n,l.limitLine,i,o,h,f,a.x,"x"),re(n,l.limitLine,i,o,s,p,a.y,"y"),Q=e.xs.map(u=>M+h.frac(u)*i),e.values.forEach((u,T)=>{if(x.size>0&&!x.has(T))return;n.strokeStyle=ie(T),n.fillStyle=ie(T),n.lineWidth=2;let d=!1;n.beginPath(),u.forEach((m,y)=>{if(!Number.isFinite(m)){d=!1;return}const S=Q[y],v=k+(1-s.frac(m))*o;d?n.lineTo(S,v):n.moveTo(S,v),d=!0}),n.stroke(),u.forEach((m,y)=>{Number.isFinite(m)&&(n.beginPath(),n.arc(Q[y],k+(1-s.frac(m))*o,V===y?4.5:3,0,Math.PI*2),n.fill())})}),V>=0&&(n.lineWidth=1,n.strokeStyle=l.textMuted,n.beginPath(),n.moveTo(Q[V],k),n.lineTo(Q[V],k+o),n.stroke())}function Ne(e){const l=a?.marks;if(!l||l.type!=="line"||!g||!a?.x||Q.length===0)return null;const c=e.clientX-g.getBoundingClientRect().left;let r=-1,i=24;if(Q.forEach((n,f)=>{const p=Math.abs(n-c);p<i&&(i=p,r=f)}),V=r,r<0)return null;const o=a.level==="die"?"dies":"wafers",t=l.values.map((n,f)=>({g:f,v:n[r],n:l.counts[f][r]})).filter(n=>Number.isFinite(n.v)&&(x.size===0||x.has(n.g)));return`<strong>${I(`${a.x.label}: ${R(l.xs[r],a.x.unit)}`)}</strong><br>`+t.map(n=>I(`${a.groups.length>1?`${ge(n.g)}: `:""}${R(n.v,a.y.unit)} (${n.n.toLocaleString("en-GB")} ${o})`)).join("<br>")}function B(){const e=a?.marks?.type;e==="scatter"?Ye():e==="histogram"?De():e==="box"||e==="bar"?Ve():e==="line"&&Ke()}function Je(e){const l=a,c=b.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",i=[c,r].filter(Boolean).join(" \xB7 "),o=(t,n)=>`${t.label}: ${R(n,t.unit)}`;return(i?`<strong>${I(i)}</strong><br>`:"")+I(o(l.x,e.x))+"<br>"+I(o(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${I(`${l.colorScale.label}: ${R(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${I(ge(e.group))}`:"")+(b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"")}function Be(e){if(!J||!z||!a?.x)return null;const l=g.getBoundingClientRect(),r=(e.clientX-l.left-M)/z.plotW;if(r<0||r>1)return null;const i=z.x.reverse?1-r:r,{edges:o,counts:t}=J,n=o.length-1,f=Math.min(n-1,Math.max(0,Math.floor(i*n)));X=f;const p=a.x,h=t.map((s,u)=>({g:u,n:s[f]})).filter(s=>s.n>0&&(x.size===0||x.has(s.g)));return`<strong>${I(`${R(o[f],p.unit)} to ${R(o[f+1],p.unit)}`)}</strong><br>`+(h.length?h.map(s=>I(`${a.groups.length>1?`${ge(s.g)}: `:""}${s.n.toLocaleString("en-GB")} ${a.level==="die"?"dies":"wafers"}`)).join("<br>"):"none")}function Qe(e){const l=P.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:te.md,marginTop:te.md,marginBottom:te.xl,fontSize:Le.body,color:xe.label});const c=P.createElement("canvas");c.width=200,c.height=10,Object.assign(c.style,{width:"200px",height:"10px",borderRadius:ot.control,flex:"0 0 auto"});const r=c.getContext("2d"),i=Pe();if(r)for(let f=0;f<200;f++)r.fillStyle=i(f/199),r.fillRect(f,0,1,10);const o=P.createElement("span");o.textContent=R(e.lo,e.unit);const t=P.createElement("span");t.textContent=R(e.hi,e.unit);const n=P.createElement("span");return n.textContent=e.label,n.style.color=xe.text,l.append(n,o,c,t),l}const Te=(e,l,c)=>l.map(r=>{const{item:i,die:o}=e(r);return{x:0,y:0,group:c,item:i,die:o}});function et(){Z?.destroy(),Z=void 0,w.innerHTML="",g=void 0,H=void 0,A=void 0,K=[],ue=null,X=-1,ce=[],z=void 0,D=void 0,_=null,Q=[],V=-1,de=he,x.clear(),G.clear();const e=a;if(!e)return;if(q.textContent=nt(e),$.dataset.wmapChartTitle=q.textContent,e.issues.length||!e.marks){for(const i of e.issues)qe(w,i);return}const l=P.createElement("div");Object.assign(l.style,{color:xe.label,fontSize:Le.body,marginBottom:te.xs});const c=b.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(b.onOpenWafer?` \xB7 click a point to ${c}`:"")+(b.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(b.onOpenWafer&&e.marks.categoryItems?` \xB7 click to ${c}`:b.onSelectPoints?" \xB7 click to chart or tabulate what it counts":"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&b.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="line"&&b.onSelectPoints?" \xB7 click a point to chart or tabulate what it averages":"";l.textContent=Fe(e)+r,Re(l),A=P.createElement("div"),A.style.display="flow-root",w.appendChild(A),A.appendChild(l);for(const i of e.notes){const o=P.createElement("div");Re(o),o.textContent=i,Object.assign(o.style,{color:xe.warnText,fontSize:Le.body,marginBottom:te.xs}),A.appendChild(o)}if(e.plotted===0){qe(w,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&(H=P.createElement("div"),Object.assign(H.style,{display:"flex",flexWrap:"wrap",gap:te.sm,marginTop:te.md,marginBottom:te.xl}),e.groups.forEach((i,o)=>{const t=ht(i||"(none)",ie(o),P);at(t.el,$,L,`${i||"(none)"} \u2014 click to filter`),t.el.addEventListener("click",()=>{x.has(o)?x.delete(o):x.add(o),K.forEach((n,f)=>n.setState({selected:x.has(f),dimmed:x.size>0&&!x.has(f)})),B()}),K.push(t),H.appendChild(t.el)}),A.appendChild(H)),e.colorScale&&(H=Qe(e.colorScale),A.appendChild(H)),g=P.createElement("canvas"),g.style.display="block",g.style.cursor=e.marks.type==="scatter"?"crosshair":"default",w.appendChild(g),e.marks.type==="scatter"){const i=e.marks,o=!!b.onSelectPoints;Z=xt({card:$,canvas:g,tooltip:L,drawn:()=>ce,describe:Je,clickable:()=>!!b.onOpenWafer,onOpen:t=>b.onOpenWafer?.(t.item,ze(e.spec)),onHover:t=>{ue=t,B()},select:o?{pick:({x0:t,y0:n,x1:f,y1:p})=>z?(x.size===0?i.points:i.points.filter(s=>x.has(s.group))).filter(s=>{const u=M+z.x.frac(s.x)*z.plotW,T=k+(1-z.y.frac(s.y))*z.plotH;return u>=t&&u<=f&&T>=n&&T<=p}):[],onPicked:(t,n)=>{G.clear();for(const f of t)G.add(f);B(),t.length>0&&b.onSelectPoints(t,n,g)},onClear:()=>{G.clear(),B()},hasSelection:()=>G.size>0}:void 0})}else if(e.marks.type==="histogram"){Ge(),g.addEventListener("mousemove",o=>{const t=Be(o);if(!t){L.style.display="none",X>=0&&(X=-1,B());return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",X>=0&&(X=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(!J||Be(o)===null)return;const t=X,{edges:n}=J,f=z?.x.log,p=f?Math.log10(n[0]):n[0],h=f?Math.log10(n[n.length-1]):n[n.length-1],s=n.length-1,u=[];i.values.forEach((T,d)=>{if(x.size>0&&!x.has(d))return;const m=[];T.forEach((y,S)=>{const v=f?y>0?Math.log10(y):NaN:y;!Number.isFinite(v)||v<p||v>h||Math.min(s-1,Math.floor((v-p)/(h-p)*s))===t&&m.push(i.units[d][S])}),u.push(...Te(i.unit,m,d))}),u.length>0&&(L.style.display="none",b.onSelectPoints(u,{x:o.clientX,y:o.clientY},g))}))}else if(e.marks.type==="box"||e.marks.type==="bar"){const i=e.marks;g.addEventListener("mousemove",o=>{const t=Ie(o);if(g.style.cursor=t&&(i.categoryItems&&b.onOpenWafer||b.onSelectPoints&&i.cellUnits[t.g][t.c].length>0)?"pointer":"default",!t){L.style.display="none",_&&(_=null,B());return}L.innerHTML=Ze(t),L.style.display="block",$e(L,$,o.clientX,o.clientY),(!_||_.g!==t.g||_.c!==t.c)&&(_=t,B())}),g.addEventListener("mouseleave",()=>{L.style.display="none",_&&(_=null,B())}),g.addEventListener("click",o=>{const t=Ie(o);if(!t)return;const n=i.categoryItems?.[t.c];if(n!==void 0&&n>=0&&b.onOpenWafer){b.onOpenWafer(n,ze(e.spec));return}const f=i.cellUnits[t.g][t.c];f.length>0&&b.onSelectPoints&&(L.style.display="none",b.onSelectPoints(Te(i.unit,f,t.g),{x:o.clientX,y:o.clientY},g))})}else if(e.marks.type==="line"){g.addEventListener("mousemove",o=>{const t=Ne(o);if(!t){L.style.display="none",B();return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",V>=0&&(V=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(Ne(o)===null||V<0)return;const t=i.cellUnits.flatMap((n,f)=>x.size>0&&!x.has(f)?[]:Te(i.unit,n[V]??[],f));t.length>0&&(L.style.display="none",b.onSelectPoints(t,{x:o.clientX,y:o.clientY},g))}))}B()}oe(()=>{const e=a;if(!e||!e.marks)return;const l=Pe();return{caption:[Fe(e),...e.notes],legend:e.groups.length>1?e.groups.map((c,r)=>({label:c||"(none)",color:ie(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:R(e.colorScale.lo,e.colorScale.unit),hi:R(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const tt=lt($,()=>B());return{card:$,actions:F,setPlot(e){a=e,et()},destroy(){tt.disconnect(),Z?.destroy()}}}
@@ -0,0 +1,45 @@
1
+ /** A point as drawn, with its pixel position inside the canvas. */
2
+ export interface DrawnPoint<P> {
3
+ p: P;
4
+ cx: number;
5
+ cy: number;
6
+ }
7
+ export interface PointInteractionOptions<P> {
8
+ card: HTMLElement;
9
+ canvas: HTMLCanvasElement;
10
+ tooltip: HTMLElement;
11
+ /** The points as last drawn. Only these can be hit: a chart that samples a large population hides the rest. */
12
+ drawn: () => ReadonlyArray<DrawnPoint<P>>;
13
+ /** Finds the point a pointer is on by its own rule, in place of the nearest drawn point within a few pixels: a chart
14
+ * whose points are columns (one per wafer) is hit anywhere along the column, not only on the dot. */
15
+ locate?: (e: MouseEvent) => P | null;
16
+ /** Tooltip HTML for a point (already escaped). */
17
+ describe: (p: P) => string;
18
+ /** Whether a click on this point does anything. */
19
+ clickable: (p: P) => boolean;
20
+ onOpen?: (p: P) => void;
21
+ /** The point under the pointer changed (null when it left all points): redraw. */
22
+ onHover: (p: P | null) => void;
23
+ /** Present to enable drag-to-select. */
24
+ select?: {
25
+ /** The points inside a rectangle given in canvas pixels. */
26
+ pick: (rect: {
27
+ x0: number;
28
+ y0: number;
29
+ x1: number;
30
+ y1: number;
31
+ }) => P[];
32
+ /** A drag finished: the chart records the selection, redraws and tells its host. `at` is the pointer in the viewport. */
33
+ onPicked: (picked: P[], at: {
34
+ x: number;
35
+ y: number;
36
+ }) => void;
37
+ /** A click on empty space while a selection stands. */
38
+ onClear: () => void;
39
+ hasSelection: () => boolean;
40
+ };
41
+ }
42
+ export declare function wirePointInteractions<P>(o: PointInteractionOptions<P>): {
43
+ destroy: () => void;
44
+ };
45
+ //# sourceMappingURL=pointInteractions.d.ts.map
@@ -0,0 +1 @@
1
+ import{CLR as E}from"../toolbar.js";import{positionChartTooltip as L}from"./chartShell.js";const M=7,k=4;export function wirePointInteractions(n){const{card:u,canvas:r,tooltip:a}=n;let d=null;const x=t=>{if(n.locate)return n.locate(t);const e=r.getBoundingClientRect(),s=t.clientX-e.left,l=t.clientY-e.top;let p=null,i=M*M;for(const o of n.drawn()){const c=o.cx-s,h=o.cy-l,y=c*c+h*h;y<=i&&(i=y,p=o.p)}return p};r.addEventListener("mousemove",t=>{const e=x(t);if(r.style.cursor=e&&n.clickable(e)?"pointer":"crosshair",!e){a.style.display="none",d&&(d=null,n.onHover(null));return}a.innerHTML=n.describe(e),a.style.display="block",L(a,u,t.clientX,t.clientY),d!==e&&(d=e,n.onHover(e))}),r.addEventListener("mouseleave",()=>{a.style.display="none",d&&(d=null,n.onHover(null))});let b=!1;const m=u.ownerDocument.createElement("div");Object.assign(m.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"40",boxSizing:"border-box",border:`1px dashed ${E.iconActive}`,background:"rgba(120,150,200,0.15)"}),u.appendChild(m);const f=n.select;return f&&r.addEventListener("mousedown",t=>{if(t.button!==0)return;b=!1;const e=r.getBoundingClientRect(),s=t.clientX-e.left,l=t.clientY-e.top;let p=!1,i=s,o=l;const c=u.ownerDocument,h=v=>{if(i=Math.min(Math.max(v.clientX-e.left,0),e.width),o=Math.min(Math.max(v.clientY-e.top,0),e.height),!p&&Math.hypot(i-s,o-l)<k)return;p=!0,a.style.display="none";const g=u.getBoundingClientRect();Object.assign(m.style,{display:"block",left:`${e.left-g.left+Math.min(s,i)}px`,top:`${e.top-g.top+Math.min(l,o)}px`,width:`${Math.abs(i-s)}px`,height:`${Math.abs(o-l)}px`})},y=v=>{c.removeEventListener("mousemove",h),c.removeEventListener("mouseup",y),m.style.display="none",p&&(b=!0,f.onPicked(f.pick({x0:Math.min(s,i),y0:Math.min(l,o),x1:Math.max(s,i),y1:Math.max(l,o)}),{x:v.clientX,y:v.clientY}))};c.addEventListener("mousemove",h),c.addEventListener("mouseup",y)}),r.addEventListener("click",t=>{if(b){b=!1;return}const e=x(t);if(!e){f?.hasSelection()&&f.onClear();return}n.clickable(e)&&n.onOpen?.(e)}),{destroy:()=>m.remove()}}
@@ -1,11 +1,18 @@
1
1
  import type { RegionYieldDatum } from '../../stats/regions.js';
2
2
  import { type SaveImageHandler } from './chartShell.js';
3
- export type RegionYieldMode = 'ring' | 'quadrant';
3
+ export type RegionYieldMode = 'ring' | 'quadrant' | 'reticleCell';
4
4
  export interface RegionYieldDiagramOptions {
5
5
  title?: string;
6
6
  mode: RegionYieldMode;
7
7
  /** Ring mode: ordered ring 1 (core) → ring N (edge), matching `buildRegionYieldData`'s output for `buildRingRegions`. Quadrant mode: any order — each row's quadrant is read from its `key` (`quadrant:NE` etc.), not position. */
8
8
  rows: RegionYieldDatum[];
9
+ /** Reticle-cell mode: the field's size in dies, so cells with no data still take their place. Without it the grid is as large as the cells given. */
10
+ grid?: {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ /** Click a region: called with it and the click, so the host can pick out the dies it counts and open a menu there. */
15
+ onSelectRegion?: (row: RegionYieldDatum, e: MouseEvent) => void;
9
16
  onSaveImage?: SaveImageHandler;
10
17
  /** Document to build this panel's DOM into. Default `document` — pass the
11
18
  * host's own `ownerDocument` when the container might live in a
@@ -1 +1 @@
1
- import{parseRegionKey as A}from"../../stats/regions.js";import{yieldFill as D}from"./palette.js";import{fontPx as C}from"../toolbar.js";import{cardShell as N,resolveChartCanvasColors as F,observeResize as $,growCardToFitContent as j,setChartGrow as q,isExpandedCard as z,bodyRoom as G,renderEmptyState as O,prepareCanvas as _}from"./chartShell.js";const v=320,L=220,Q={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function Y(e,a,o,r,l,n){e.beginPath(),e.moveTo(a+n,o),e.arcTo(a+r,o,a+r,o+l,n),e.arcTo(a+r,o+l,a,o+l,n),e.arcTo(a,o+l,a,o,n),e.arcTo(a,o,a+r,o,n),e.closePath()}function w(e,a,o,r,l,n){e.font=`${C(-1)}px system-ui, sans-serif`;const c=e.measureText(r).width;e.font="700 11px system-ui, sans-serif";const y=e.measureText(l).width,m=Math.max(c,y)+12,g=30;e.fillStyle=n.bg,Y(e,a-m/2,o-g/2,m,g,4),e.fill(),e.strokeStyle=n.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=n.textMuted,e.font=`${C(-1)}px system-ui, sans-serif`,e.fillText(r,a,o-7),e.fillStyle=n.text,e.font="700 11px system-ui, sans-serif",e.fillText(l,a,o+7)}export function renderRegionYieldDiagram(e){const{mode:a,rows:o,onSaveImage:r}=e,l=e.title??(a==="ring"?"Ring yield":"Quadrant yield"),{card:n,body:c}=N(l,r,e.ownerDocument);q(n,"square");const y=o.length>0;if(!y)return O(c,"No bin data available for regional yield."),{card:n,hasData:y,destroy:()=>{}};Object.assign(c.style,{display:"flex",justifyContent:"center",alignItems:"center"});const m=n.ownerDocument.createElement("canvas");Object.assign(m.style,{display:"block",flex:"none"}),c.appendChild(m);function g(){const S=Math.max(L,Math.min(c.clientWidth||v,v));j(n,c,S);const b=z(n)?Math.max(S,Math.floor(Math.min(c.clientWidth,G(n,c,m)))):S,k=_(m,n,b,b);if(!k)return;const{ctx:t}=k,u=F(n),T=D,d=b/2,h=b/2,f=b/2-34;if(a==="ring"){const i=o.length;for(let s=0;s<i;s++){const M=s/i*f,P=(s+1)/i*f;t.beginPath(),t.arc(d,h,P,0,2*Math.PI),t.arc(d,h,M,0,2*Math.PI,!0),t.closePath(),t.fillStyle=T(o[s].yieldPercent),t.fill(),t.strokeStyle=u.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(d,h,f,0,2*Math.PI),t.strokeStyle=u.text,t.lineWidth=1.5,t.stroke();for(let s=0;s<i;s++){const M=(s+.5)/i*f,P=-Math.PI/2+s/i*2*Math.PI,I=d+Math.cos(P)*M,p=h+Math.sin(P)*M;w(t,I,p,o[s].label,`${o[s].yieldPercent.toFixed(1)}%`,u)}}else{for(const i of o){const s=A(i.key).quadrant,M=s?Q[s]:void 0;if(!M)continue;const[P,I]=M;t.beginPath(),t.moveTo(d,h),t.arc(d,h,f,P,I),t.closePath(),t.fillStyle=T(i.yieldPercent),t.fill(),t.strokeStyle=u.border,t.lineWidth=1,t.stroke();const p=(P+I)/2,W=d+Math.cos(p)*f*.6,E=h+Math.sin(p)*f*.6;w(t,W,E,i.label,`${i.yieldPercent.toFixed(1)}%`,u)}t.beginPath(),t.arc(d,h,f,0,2*Math.PI),t.strokeStyle=u.text,t.lineWidth=1.5,t.stroke()}}const R=$(n,()=>g());return g(),{card:n,hasData:y,destroy:()=>R.disconnect()}}
1
+ import{parseRegionKey as D,parseReticleCellKey as G}from"../../stats/regions.js";import{yieldFill as H}from"./palette.js";import{fontPx as L}from"../toolbar.js";import{escHtml as _}from"../../core/utils.js";import{makeTooltip as K,positionChartTooltip as Q,cardShell as Z,resolveChartCanvasColors as U,observeResize as z,growCardToFitContent as J,setChartGrow as V,isExpandedCard as x,bodyRoom as ee,renderEmptyState as te,prepareCanvas as ne}from"./chartShell.js";const N=320,oe=220,q={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function Y(e,r,o,m,M,l){e.beginPath(),e.moveTo(r+l,o),e.arcTo(r+m,o,r+m,o+M,l),e.arcTo(r+m,o+M,r,o+M,l),e.arcTo(r,o+M,r,o,l),e.arcTo(r,o,r+m,o,l),e.closePath()}function W(e,r,o,m,M,l){e.font=`${L(-1)}px system-ui, sans-serif`;const b=e.measureText(m).width;e.font="700 11px system-ui, sans-serif";const C=e.measureText(M).width,y=Math.max(b,C)+12,w=30;e.fillStyle=l.bg,Y(e,r-y/2,o-w/2,y,w,4),e.fill(),e.strokeStyle=l.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=l.textMuted,e.font=`${L(-1)}px system-ui, sans-serif`,e.fillText(m,r,o-7),e.fillStyle=l.text,e.font="700 11px system-ui, sans-serif",e.fillText(M,r,o+7)}function le(e,r,o,m,M){e.font="700 11px system-ui, sans-serif";const l=e.measureText(m).width+8;e.fillStyle=M.bg,Y(e,r-l/2,o-8,l,16,3),e.fill(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=M.text,e.fillText(m,r,o+.5)}export function renderRegionYieldDiagram(e){const{mode:r,rows:o,onSaveImage:m}=e,M=e.title??(r==="ring"?"Ring yield":r==="quadrant"?"Quadrant yield":"Reticle cell yield"),{card:l,body:b}=Z(M,m,e.ownerDocument);V(l,"square");const C=o.length>0;if(!C)return te(b,"No bin data available for regional yield."),{card:l,hasData:C,destroy:()=>{}};Object.assign(b.style,{display:"flex",justifyContent:"center",alignItems:"center"});const y=l.ownerDocument.createElement("canvas");Object.assign(y.style,{display:"block",flex:"none"}),b.appendChild(y);let w={cx:0,cy:0,R:0};const E=new Map;let S=0,P=0;if(r==="reticleCell"){for(const n of o){const i=G(n.key);i&&(E.set(`${i.column},${i.row}`,n),S=Math.max(S,i.column+1),P=Math.max(P,i.row+1))}S=Math.max(S,e.grid?.width??0),P=Math.max(P,e.grid?.height??0)}let k={x0:0,y0:0,side:0};const T=K(l);function B(n,i,c,t){const s=Math.max(4,Math.floor(Math.min((i-40)/S,(i-40)/P))),f=Math.round((i-s*S)/2),a=Math.round((i-s*P)/2);k={x0:f,y0:a,side:s};for(let I=0;I<P;I++)for(let u=0;u<S;u++){const h=f+u*s,d=a+(P-1-I)*s,g=E.get(`${u},${I}`);n.fillStyle=g?t(g.yieldPercent):c.bg,n.fillRect(h,d,s,s),n.strokeStyle=c.border,n.lineWidth=1,n.strokeRect(h+.5,d+.5,s-1,s-1),!(!g||s<30)&&(s>=54?W(n,h+s/2,d+s/2,`(${u}, ${I})`,`${g.yieldPercent.toFixed(1)}%`,c):le(n,h+s/2,d+s/2,`${g.yieldPercent.toFixed(0)}%`,c))}n.strokeStyle=c.text,n.lineWidth=1.5,n.strokeRect(f+.5,a+.5,s*S-1,s*P-1)}function F(){const n=Math.max(oe,Math.min(b.clientWidth||N,N));J(l,b,n);const i=x(l)?Math.max(n,Math.floor(Math.min(b.clientWidth,ee(l,b,y)))):n,c=ne(y,l,i,i);if(!c)return;const{ctx:t}=c,p=U(l),s=H;if(r==="reticleCell"){B(t,i,p,s);return}const f=i/2,a=i/2,u=i/2-34;if(w={cx:f,cy:a,R:u},r==="ring"){const h=o.length;for(let d=0;d<h;d++){const g=d/h*u,R=(d+1)/h*u;t.beginPath(),t.arc(f,a,R,0,2*Math.PI),t.arc(f,a,g,0,2*Math.PI,!0),t.closePath(),t.fillStyle=s(o[d].yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke();for(let d=0;d<h;d++){const g=(d+.5)/h*u,R=-Math.PI/2+d/h*2*Math.PI,$=f+Math.cos(R)*g,v=a+Math.sin(R)*g;W(t,$,v,o[d].label,`${o[d].yieldPercent.toFixed(1)}%`,p)}}else{for(const h of o){const d=D(h.key).quadrant,g=d?q[d]:void 0;if(!g)continue;const[R,$]=g;t.beginPath(),t.moveTo(f,a),t.arc(f,a,u,R,$),t.closePath(),t.fillStyle=s(h.yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke();const v=(R+$)/2,X=f+Math.cos(v)*u*.6,j=a+Math.sin(v)*u*.6;W(t,X,j,h.label,`${h.yieldPercent.toFixed(1)}%`,p)}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke()}}function A(n,i){if(r==="reticleCell"){const f=Math.floor((n-k.x0)/k.side),a=Math.floor((i-k.y0)/k.side);return k.side<=0||f<0||f>=S||a<0||a>=P?null:E.get(`${f},${P-1-a}`)??null}const c=n-w.cx,t=i-w.cy,p=Math.hypot(c,t);if(!(p<=w.R))return null;if(r==="ring")return o[Math.min(o.length-1,Math.floor(p/w.R*o.length))]??null;const s=(Math.atan2(t,c)+2*Math.PI)%(2*Math.PI);return o.find(f=>{const a=q[D(f.key).quadrant??""];return!!a&&s>=a[0]&&s<a[1]})??null}y.addEventListener("mousemove",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);if(!c){T.style.display="none";return}T.innerHTML=`<strong>${_(c.label)}</strong><br>${c.yieldPercent.toFixed(1)}% yield (${c.passDies} of ${c.n} dies)`+(e.onSelectRegion?"<br><em>click to chart or tabulate these dies</em>":""),T.style.display="block",Q(T,l,n.clientX,n.clientY)}),y.addEventListener("mouseleave",()=>{T.style.display="none"}),e.onSelectRegion&&(y.style.cursor="pointer",y.addEventListener("click",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);c&&e.onSelectRegion(c,n)}));const O=z(l,()=>F());return F(),{card:l,hasData:C,destroy:()=>O.disconnect()}}
@@ -42,6 +42,25 @@ export interface ScatterPanelOptions {
42
42
  axisPrefs?: AxisPrefs;
43
43
  /** Called when the user changes the "Limits:" choice here. */
44
44
  onAxisPrefsChange?: (prefs: AxisPrefs) => void;
45
+ /**
46
+ * Click a point to open its die's wafer, on the X test — the same
47
+ * `(waferIndex, testNumber)` the boxplot and trend use. Needs each item's
48
+ * `waferIndex`; a point without one is not clickable. Omit for no click action.
49
+ */
50
+ onOpen?: (waferIndex: number, testNumber: number) => void;
51
+ /** What a click does, in the reader's words, when it is not "open this wafer" (a single-wafer host
52
+ * shows the X test on its map instead). Default `open this wafer`. */
53
+ openActionLabel?: string;
54
+ /**
55
+ * Drag a rectangle over the plot to select the dies inside it (only points the
56
+ * legend filter leaves visible). Called on release with those points, the
57
+ * pointer position and the canvas, so the host can open a menu there. The
58
+ * selection stays ringed until X/Y change or a click on empty space.
59
+ */
60
+ onSelect?: (points: ScatterPoint[], at: {
61
+ x: number;
62
+ y: number;
63
+ }, anchor: HTMLElement, xTestNumber: number) => void;
45
64
  /** Document to build this panel's DOM into. Default `document` — pass the
46
65
  * host's own `ownerDocument` when the container might live in a
47
66
  * different document (e.g. a gallery card detached into its own popup
@@ -1 +1 @@
1
- import{NO_DATA_FILL as Ce}from"../../renderer/colorMap.js";import{maxOf as J,minOf as Le}from"../../core/utils.js";import{categorical as Xe}from"./palette.js";import{buildScatterData as Ye,buildScatterDataGrouped as Ke}from"../../stats/scatter.js";import{pearsonOfPairs as Ve}from"../../stats/correlation.js";import{buildFacetTable as qe}from"../../stats/facets.js";import{SPACE as k,RADIUS as Je,fontPx as L,FONT as re,CLR as X}from"../toolbar.js";import{fitTicks as Ae}from"../../renderer/axisTicks.js";import{cardShell as Qe,observeResize as Ze,makeTooltip as et,attachChartTip as tt,makeTestSelect as nt,makeWaferSelect as it,chartFillHeight as ot,applyCanvasFlow as st,drawAxisUnit as lt,resolveChartCanvasColors as at,makeAxisFormat as Q,horizontalTickSpacing as rt,VERTICAL_TICK_SPACING_PX as ct,makeSeriesLegendItem as ft,prepareCanvas as dt,drawOffAxisLimits as Oe,limitLines as mt,hasBothLimitKinds as ut,makeLimitsSelect as pt,stackLabelRows as Pe,strokeLimitLine as De,fillTextOnHalo as Be}from"./chartShell.js";const c=52,xt=16,l=16,ht=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(h){return h===void 0?NO_BIN_CATEGORY:String(h)}export function binCategories(h){const Y=new Set;let S=!1;for(const O of h)O.hbin===void 0?S=!0:Y.add(O.hbin);const A=Array.from(Y).sort((O,Z)=>O-Z).map(String);return S&&A.push(NO_BIN_CATEGORY),A}export function renderScatterPanel(h){const{title:Y="Test scatter",items:S,testDefs:A,binColors:O,onSaveImage:Z,groups:K}=h,{card:s,body:P,controlsRow:ee}=Qe(Y,Z,h.ownerDocument),V=A.filter(e=>e.testNumber!==void 0),v=!!(K&&K.length>0),ce=(K??[]).map(e=>e.key),Ee=new Map(ce.map((e,n)=>[e,n]));let p=h.xTestNumber??V[0]?.testNumber??null,b=h.yTestNumber??V[1]?.testNumber??p,R=null;const fe=()=>R!==null?S[R]?[S[R]]:[]:S;function de(e,n,o){const r=s.ownerDocument.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:k.xs,fontSize:re.body,color:X.label});const T=s.ownerDocument.createElement("span");T.textContent=e;const d=nt(V,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:s.ownerDocument});return r.append(T,d),{wrap:r,select:d}}const{wrap:$e,select:Re}=de("X:",p,e=>{p=e,F()}),{wrap:Ie,select:We}=de("Y:",b,e=>{b=e,F()});ee.append($e,Ie);let M=h.axisPrefs??{clipOutliers:!1};const me=s.ownerDocument.createElement("span");ee.appendChild(me);function ue(){const e=[p,b].map(n=>A.find(o=>o.testNumber===n));me.replaceChildren(...e.some(ut)?[pt(M.limits??"both",n=>{M={...M,limits:n},h.onAxisPrefsChange?.(M),E()},s.ownerDocument)]:[])}!v&&S.length>1&&ee.appendChild(it(S,R,e=>{R=e,F()},{ownerDocument:s.ownerDocument}));const I=s.ownerDocument.createElement("div");Object.assign(I.style,{color:X.warnText,background:X.warnBg,border:`1px solid ${X.warnBorder}`,borderRadius:Je.control,padding:`${k.xs} ${k.md}`,fontSize:re.body,marginBottom:k.xs,display:"none"}),s.insertBefore(I,P);function pe(){const e=v?[]:qe(fe(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(I.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,I.style.display=""):I.style.display="none"}pe();const te=s.ownerDocument.createElement("div");Object.assign(te.style,{color:X.label,fontSize:re.body,marginBottom:k.xs}),s.insertBefore(te,P);function ne(){const e=v?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter",n=g.size===0?x:x.filter(T=>g.has(q(T))),{r:o,n:r}=Ve(n);te.textContent=o===null?`${e} \xB7 n = ${r.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${r.toLocaleString()}`}const q=e=>v?e.group??"\u2014":binCategoryOf(e.hbin),xe=e=>v?Xe(Ee.get(e)??0):e===NO_BIN_CATEGORY?Ce:O?.get(Number(e))??Ce,he=e=>v?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,g=new Set,W=s.ownerDocument.createElement("div");Object.assign(W.style,{display:"flex",flexWrap:"wrap",gap:k.sm,marginTop:k.md,marginBottom:k.xl}),P.appendChild(W);const D=s.ownerDocument.createElement("canvas");D.style.display="block",D.style.cursor="crosshair",P.appendChild(D);const Ne=et(s);let x=[],y=0,C=1,w=0,B=1;function N(e){const n=A.find(o=>o.testNumber===e);return{unit:n?.unit,lines:mt(n,M.limits)}}function Fe(){const e=P.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=ot(s,P,D,n);return{w:e,h:o,plotW:Math.max(10,e-c-xt),plotH:Math.max(10,o-l-ht)}}const ie=new Map;function be(){for(const[e,n]of ie){const o=g.has(e);n.setState({selected:o,dimmed:g.size>0&&!o})}}function ge(e){W.innerHTML="",ie.clear(),g.clear();for(const n of e){const o=ft(he(n),xe(n),s.ownerDocument),r=o.el;r.dataset.cat=n,ie.set(n,o),tt(r,s,Ne,`${he(n)} \u2014 click to filter`),r.addEventListener("click",()=>{g.has(n)?g.delete(n):g.add(n),be(),ne(),E()}),W.appendChild(r)}be()}function E(){st(D,W);const e=at(s),n=C-y,o=B-w,{w:r,h:T,plotW:d,plotH:f}=Fe(),H=dt(D,s,r,T);if(!H)return;const{ctx:t}=H;if(x.length===0){t.font=`${L()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",r/2,T/2);return}t.font=`${L(-1)}px system-ui, sans-serif`;const _=p!==null?N(p).unit:void 0,ye=Ae(y,C,d,rt(t,Math.max(Math.abs(y),Math.abs(C)),_)),Te=Ae(w,B,f,()=>ct),oe=Q(Math.max(Math.abs(y),Math.abs(C)),p!==null?N(p).unit:void 0,ye.step||void 0),se=Q(Math.max(Math.abs(w),Math.abs(B)),b!==null?N(b).unit:void 0,Te.step||void 0);t.font=`${L(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of ye.ticks){const u=c+(m-y)/n*d;t.beginPath(),t.moveTo(u,l),t.lineTo(u,l+f),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(oe.tick(m),u,l+f+4)}for(const m of Te.ticks){const u=l+(1-(m-w)/o)*f;t.beginPath(),t.moveTo(c,u),t.lineTo(c+d,u),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(se.tick(m),c-4,u)}oe.unitLabel&&lt(t,oe.unitLabel,c+d/2,l+f+24,e.textMuted),se.unitLabel&&(t.save(),t.font=`${L(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,l+f/2),t.rotate(-Math.PI/2),t.fillText(`(${se.unitLabel})`,0,0),t.restore());const z=g.size===0?x:x.filter(m=>g.has(q(m))),we=z.length>5e3?Math.ceil(z.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(z.length/we)));for(let m=0;m<z.length;m+=we){const u=z[m],G=c+(u.x-y)/n*d,j=l+(1-(u.y-w)/o)*f;t.beginPath(),t.arc(G,j,2.5,0,Math.PI*2),t.fillStyle=xe(q(u)),t.fill()}if(t.globalAlpha=1,p!==null&&b!==null){const m=N(p),u=N(b);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${L(-1)}px system-ui, sans-serif`,t.textBaseline="top";const G=L(-1)+2,j=m.lines.filter(i=>i.value>=y&&i.value<=C).map(i=>{const a=c+(i.value-y)/n*d;return{l:i,cx:a,start:a+2,end:a+2+t.measureText(i.label).width}}),Se=Pe(j);j.forEach(({l:i,cx:a},U)=>{De(t,i,e.limitLine,a,l,a,l+f),t.textAlign="left",Be(t,i.label,a+2,l+2+Se[U]*G,e.bg)});const le=u.lines.filter(i=>i.value>=w&&i.value<=B).map(i=>{const a=l+(1-(i.value-w)/o)*f;return{l:i,cy:a,start:a+2,end:a+2+L(-1)}}),Ge=Pe(le,1),je=J(le.map(i=>t.measureText(i.l.label).width))+8;le.forEach(({l:i,cy:a},U)=>{De(t,i,e.limitLine,c,a,c+d,a),t.textAlign="left",Be(t,i.label,c+3+Ge[U]*je,a+2,e.bg)});const ve=(i,a,U)=>i.filter($=>$.value<a||$.value>U).map($=>({value:$.value,label:$.label,side:$.value<a?"lo":"hi"})),Me={left:c,right:c+d,top:l,bottom:l+f},ae=ve(m.lines,y,C),ke=l+(j.length?(J(Se)+1)*G:0),Ue=Math.max(ae.filter(i=>i.side==="lo").length,ae.filter(i=>i.side==="hi").length);Oe(t,ae,{...Me,top:ke},"horizontal",e.limitLine,i=>Q(Math.abs(i),m.unit).tick(i),e.bg),Oe(t,ve(u.lines,w,B),{...Me,top:ke+Ue*G},"vertical",e.limitLine,i=>Q(Math.abs(i),u.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(c,l),t.lineTo(c,l+f),t.moveTo(c,l+f),t.lineTo(c+d,l+f),t.stroke()}function F(){if(pe(),ue(),V.length<2||p===null||b===null){x=[],ge([]),ne(),E();return}x=v?Ke(K,p,b):Ye(fe(),p,b);let e;if(v){const n=new Set(x.map(q));e=ce.filter(o=>n.has(o))}else e=binCategories(x);if(ge(e),ne(),x.length>0){const n=x.map(_=>_.x),o=x.map(_=>_.y),r=Le(n),T=J(n),d=Le(o),f=J(o),H=(T-r)*.05||1,t=(f-d)*.05||1;y=r-H,C=T+H,w=d-t,B=f+t}E()}const He=Ze(s,()=>E());F();function _e(e,n){p=e,b=n,Re.value=String(e),We.value=String(n),F()}function ze(e){if((e.limits??"both")===(M.limits??"both")){M=e;return}M=e,ue(),E()}return{card:s,setXY:_e,setAxisPrefs:ze,destroy:()=>He.disconnect()}}
1
+ import{NO_DATA_FILL as Fe}from"../../renderer/colorMap.js";import{escHtml as Z,maxOf as se,minOf as _e}from"../../core/utils.js";import{fmt as je}from"../../renderer/fmt.js";import{categorical as dt}from"./palette.js";import{buildScatterData as ft,buildScatterDataGrouped as mt}from"../../stats/scatter.js";import{pearsonOfPairs as ut}from"../../stats/correlation.js";import{buildFacetTable as pt}from"../../stats/facets.js";import{SPACE as B,RADIUS as xt,fontPx as N,FONT as ge,CLR as ee}from"../toolbar.js";import{fitTicks as Ge}from"../../renderer/axisTicks.js";import{wirePointInteractions as ht}from"./pointInteractions.js";import{placeClearOf as Xe,cardShell as bt,observeResize as yt,makeTooltip as gt,attachChartTip as wt,makeTestSelect as St,makeWaferSelect as Tt,chartFillHeight as kt,applyCanvasFlow as Mt,drawAxisUnit as vt,resolveChartCanvasColors as Ct,makeAxisFormat as le,horizontalTickSpacing as Lt,VERTICAL_TICK_SPACING_PX as Ot,makeSeriesLegendItem as At,prepareCanvas as Pt,drawOffAxisLimits as Ye,limitLines as $t,hasBothLimitKinds as It,makeLimitsSelect as Dt,stackLabelRows as Ue,strokeLimitLine as Ke,fillTextOnHalo as Ve}from"./chartShell.js";const p=52,Bt=16,c=16,Et=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(x){return x===void 0?NO_BIN_CATEGORY:String(x)}export function binCategories(x){const te=new Set;let v=!1;for(const R of x)R.hbin===void 0?v=!0:te.add(R.hbin);const O=Array.from(te).sort((R,ae)=>R-ae).map(String);return v&&O.push(NO_BIN_CATEGORY),O}export function renderScatterPanel(x){const{title:te="Test scatter",items:v,testDefs:O,binColors:R,onSaveImage:ae,groups:_}=x,{card:l,body:H,controlsRow:re}=bt(te,ae,x.ownerDocument),ne=O.filter(e=>e.testNumber!==void 0),A=!!(_&&_.length>0),we=(_??[]).map(e=>e.key),qe=new Map(we.map((e,n)=>[e,n]));let f=x.xTestNumber??ne[0]?.testNumber??null,w=x.yTestNumber??ne[1]?.testNumber??f,j=null;const Se=()=>j!==null?v[j]?[v[j]]:[]:v;function Te(e,n,o){const a=l.ownerDocument.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:B.xs,fontSize:ge.body,color:ee.label});const y=l.ownerDocument.createElement("span");y.textContent=e;const r=St(ne,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:l.ownerDocument});return a.append(y,r),{wrap:a,select:r}}const{wrap:Je,select:Qe}=Te("X:",f,e=>{f=e,K()}),{wrap:Ze,select:et}=Te("Y:",w,e=>{w=e,K()});re.append(Je,Ze);let P=x.axisPrefs??{clipOutliers:!1};const ke=l.ownerDocument.createElement("span");re.appendChild(ke);function Me(){const e=[f,w].map(n=>O.find(o=>o.testNumber===n));ke.replaceChildren(...e.some(It)?[Dt(P.limits??"both",n=>{P={...P,limits:n},x.onAxisPrefsChange?.(P),L()},l.ownerDocument)]:[])}!A&&v.length>1&&re.appendChild(Tt(v,j,e=>{j=e,K()},{ownerDocument:l.ownerDocument}));const F=l.ownerDocument.createElement("div");F.dataset.wmapCaption="1",Object.assign(F.style,{color:ee.warnText,background:ee.warnBg,border:`1px solid ${ee.warnBorder}`,borderRadius:xt.control,padding:`${B.xs} ${B.md}`,fontSize:ge.body,marginBottom:B.xs,display:"none"}),l.insertBefore(F,H);function ve(){const e=A?[]:pt(Se(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(F.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,F.style.display=""):F.style.display="none"}ve();const oe=l.ownerDocument.createElement("div");oe.dataset.wmapCaption="1",Object.assign(oe.style,{color:ee.label,fontSize:ge.body,marginBottom:B.xs}),l.insertBefore(oe,H);function G(){const e=(A?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter")+(fe?` \xB7 click a point to ${Oe}`:"")+(de?C.size>0?` \xB7 ${C.size.toLocaleString()} selected (click empty space to clear)`:" \xB7 drag to select dies":""),n=h.size===0?b:b.filter(y=>h.has(E(y))),{r:o,n:a}=ut(n);oe.textContent=o===null?`${e} \xB7 n = ${a.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${a.toLocaleString()}`}const E=e=>A?e.group??"\u2014":binCategoryOf(e.hbin),Ce=e=>A?dt(qe.get(e)??0):e===NO_BIN_CATEGORY?Fe:R?.get(Number(e))??Fe,ce=e=>A?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,h=new Set,X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:B.sm,marginTop:B.md,marginBottom:B.xl}),H.appendChild(X);const $=l.ownerDocument.createElement("canvas");$.style.display="block",$.style.cursor="crosshair",H.appendChild($);const Le=gt(l);let b=[],g=0,I=1,S=0,W=1,Y=[],ie=null;const C=new Set,de=x.onSelect,fe=x.onOpen,Oe=x.openActionLabel??"open this wafer",Ae=new Map;for(const e of[...v,...(_??[]).flatMap(n=>n.items)])e.waferIndex!==void 0&&e.label&&Ae.set(e.waferIndex,e.label);function U(e){const n=O.find(o=>o.testNumber===e);return{unit:n?.unit,lines:$t(n,P.limits)}}function Pe(){const e=H.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=kt(l,H,$,n);return{w:e,h:o,plotW:Math.max(10,e-p-Bt),plotH:Math.max(10,o-c-Et)}}const me=new Map;function $e(){for(const[e,n]of me){const o=h.has(e);n.setState({selected:o,dimmed:h.size>0&&!o})}}function Ie(e){X.innerHTML="",me.clear(),h.clear();for(const n of e){const o=At(ce(n),Ce(n),l.ownerDocument),a=o.el;a.dataset.cat=n,me.set(n,o),wt(a,l,Le,`${ce(n)} \u2014 click to filter`),a.addEventListener("click",()=>{h.has(n)?h.delete(n):h.add(n),$e(),G(),L()}),X.appendChild(a)}$e()}function L(){Mt($,X);const e=Ct(l),n=I-g,o=W-S,{w:a,h:y,plotW:r,plotH:s}=Pe(),z=Pt($,l,a,y);if(!z)return;const{ctx:t}=z;if(b.length===0){Y=[],t.font=`${N()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",a/2,y/2);return}t.font=`${N(-1)}px system-ui, sans-serif`;const M=f!==null?U(f).unit:void 0,V=Ge(g,I,r,Lt(t,Math.max(Math.abs(g),Math.abs(I)),M)),q=Ge(S,W,s,()=>Ot),ue=le(Math.max(Math.abs(g),Math.abs(I)),f!==null?U(f).unit:void 0,V.step||void 0),pe=le(Math.max(Math.abs(S),Math.abs(W)),w!==null?U(w).unit:void 0,q.step||void 0);t.font=`${N(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of V.ticks){const d=p+(m-g)/n*r;t.beginPath(),t.moveTo(d,c),t.lineTo(d,c+s),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(ue.tick(m),d,c+s+4)}for(const m of q.ticks){const d=c+(1-(m-S)/o)*s;t.beginPath(),t.moveTo(p,d),t.lineTo(p+r,d),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(pe.tick(m),p-4,d)}ue.unitLabel&&vt(t,ue.unitLabel,p+r/2,c+s+24,e.textMuted),pe.unitLabel&&(t.save(),t.font=`${N(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,c+s/2),t.rotate(-Math.PI/2),t.fillText(`(${pe.unitLabel})`,0,0),t.restore());const J=h.size===0?b:b.filter(m=>h.has(E(m))),Be=J.length>5e3?Math.ceil(J.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(J.length/Be))),Y=[];for(let m=0;m<J.length;m+=Be){const d=J[m],T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;Y.push({p:d,cx:T,cy:D}),t.beginPath(),t.arc(T,D,2.5,0,Math.PI*2),t.fillStyle=Ce(E(d)),t.fill()}t.globalAlpha=1;const xe=ie?Y.find(m=>m.p===ie):void 0;if(xe&&(t.beginPath(),t.arc(xe.cx,xe.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),C.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let m=0;for(const d of C){if(h.size>0&&!h.has(E(d)))continue;if(++m>5e3)break;const T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;t.beginPath(),t.arc(T,D,4,0,Math.PI*2),t.stroke()}}if(f!==null&&w!==null){const m=U(f),d=U(w);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${N(-1)}px system-ui, sans-serif`,t.textBaseline="top";const T=N(-1)+2,D=m.lines.filter(i=>i.value>=g&&i.value<=I).map(i=>{const u=p+(i.value-g)/n*r;return{l:i,cx:u,start:u+2,end:u+2+t.measureText(i.label).width}}),Ee=Ue(D),We=[];D.forEach(({l:i,cx:u,start:Q,end:k},ye)=>{Ke(t,i,e.limitLine,u,c,u,c+s),t.textAlign="left";const He=c+2+Ee[ye]*T,ct=Xe(We,{x0:Q,x1:k,y0:He,y1:He+T},T);Ve(t,i.label,u+2,ct.y0,e.bg)});const he=d.lines.filter(i=>i.value>=S&&i.value<=W).map(i=>{const u=c+(1-(i.value-S)/o)*s;return{l:i,cy:u,start:u+2,end:u+2+N(-1)}}),lt=Ue(he,1),at=se(he.map(i=>t.measureText(i.l.label).width))+8;he.forEach(({l:i,cy:u},Q)=>{Ke(t,i,e.limitLine,p,u,p+r,u),t.textAlign="left";const k=p+3+lt[Q]*at,ye=Xe(We,{x0:k,x1:k+t.measureText(i.label).width,y0:u+2,y1:u+2+T},T);Ve(t,i.label,k,ye.y0,e.bg)});const ze=(i,u,Q)=>i.filter(k=>k.value<u||k.value>Q).map(k=>({value:k.value,label:k.label,side:k.value<u?"lo":"hi"})),Ne={left:p,right:p+r,top:c,bottom:c+s},be=ze(m.lines,g,I),Re=c+(D.length?(se(Ee)+1)*T:0),rt=Math.max(be.filter(i=>i.side==="lo").length,be.filter(i=>i.side==="hi").length);Ye(t,be,{...Ne,top:Re},"horizontal",e.limitLine,i=>le(Math.abs(i),m.unit).tick(i),e.bg),Ye(t,ze(d.lines,S,W),{...Ne,top:Re+rt*T},"vertical",e.limitLine,i=>le(Math.abs(i),d.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(p,c),t.lineTo(p,c+s),t.moveTo(p,c+s),t.lineTo(p+r,c+s),t.stroke()}function K(){if(ie=null,C.clear(),ve(),Me(),ne.length<2||f===null||w===null){b=[],Ie([]),G(),L();return}b=A?mt(_,f,w):ft(Se(),f,w);let e;if(A){const n=new Set(b.map(E));e=we.filter(o=>n.has(o))}else e=binCategories(b);if(Ie(e),G(),b.length>0){const n=b.map(M=>M.x),o=b.map(M=>M.y),a=_e(n),y=se(n),r=_e(o),s=se(o),z=(y-a)*.05||1,t=(s-r)*.05||1;g=a-z,I=y+z,S=r-t,W=s+t}L()}const De=e=>!!fe&&e.waferIndex!==void 0;function tt(e){const n=O.find(s=>s.testNumber===f),o=O.find(s=>s.testNumber===w),a=e.waferIndex!==void 0?Ae.get(e.waferIndex):void 0,y=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,y].filter(Boolean).join(" \xB7 ");return(r?`<strong>${Z(r)}</strong><br>`:"")+Z(`${n?.name??"X"}: ${je(e.x,n?.unit)}`)+"<br>"+Z(`${o?.name??"Y"}: ${je(e.y,o?.unit)}`)+"<br>"+Z(ce(E(e)))+(De(e)?`<br><em>click to ${Z(Oe)}</em>`:"")}const nt=ht({card:l,canvas:$,tooltip:Le,drawn:()=>Y,describe:tt,clickable:De,onOpen:e=>{f!==null&&fe(e.waferIndex,f)},onHover:e=>{ie=e,L()},select:de?{pick:({x0:e,y0:n,x1:o,y1:a})=>{const{plotW:y,plotH:r}=Pe(),s=I-g,z=W-S;return(h.size===0?b:b.filter(M=>h.has(E(M)))).filter(M=>{const V=p+(M.x-g)/s*y,q=c+(1-(M.y-S)/z)*r;return V>=e&&V<=o&&q>=n&&q<=a})},onPicked:(e,n)=>{C.clear();for(const o of e)C.add(o);G(),L(),e.length>0&&f!==null&&de(e,n,$,f)},onClear:()=>{C.clear(),G(),L()},hasSelection:()=>C.size>0}:void 0}),ot=yt(l,()=>L());K();function it(e,n){f=e,w=n,Qe.value=String(e),et.value=String(n),K()}function st(e){if((e.limits??"both")===(P.limits??"both")){P=e;return}P=e,Me(),L()}return{card:l,setXY:it,setAxisPrefs:st,destroy:()=>{ot.disconnect(),nt.destroy()}}}
@@ -19,6 +19,14 @@ export interface SweepPanelOptions {
19
19
  population?: string;
20
20
  testDefs: TestDef[] | undefined;
21
21
  onSaveImage?: SaveImageHandler;
22
+ /**
23
+ * Click a level of the curve: the tests measured there (one per series that has a value at it) and its label, with the
24
+ * click, so the host can pick out the dies that were measured and open a menu on them.
25
+ */
26
+ onSelectPoint?: (sel: {
27
+ testNumbers: number[];
28
+ label: string;
29
+ }, e: MouseEvent) => void;
22
30
  ownerDocument?: Document;
23
31
  }
24
32
  export interface SweepPanelHandle {
@@ -26,6 +34,10 @@ export interface SweepPanelHandle {
26
34
  destroy: () => void;
27
35
  /** Re-aggregate over a new population, keeping the same curve definition. */
28
36
  setDies: (dies: Die[]) => void;
37
+ /** Draw a changed definition (the editor), keeping the population. */
38
+ setSpec: (spec: SweepSpec) => void;
39
+ /** The row under the title, for the host's own buttons (Edit, Duplicate, Delete). */
40
+ actions: HTMLElement;
29
41
  }
30
42
  export declare function renderSweepPanel(options: SweepPanelOptions): SweepPanelHandle;
31
43
  //# sourceMappingURL=sweep.d.ts.map
@@ -1 +1 @@
1
- import{buildSweepData as ce,sweepAppliesTo as fe}from"../../stats/sweep.js";import{fmt as C}from"../../renderer/fmt.js";import{SPACE as ne,fontPx as pe,FONT as oe,CLR as G,ALPHA as de}from"../toolbar.js";import{categorical as he}from"./palette.js";import{cardShell as me,observeResize as ue,makeTooltip as xe,positionChartTooltip as ge,renderEmptyState as se,chartFillHeight as be,populationPhrase as ye,PADDING as Y,prepareCanvas as $e,makeAxisFormat as Te,VERTICAL_TICK_SPACING_PX as ve}from"./chartShell.js";import{fitTicks as Se}from"../../renderer/axisTicks.js";import{escHtml as m}from"../../core/utils.js";import{unmarkedLabel as Me,derivedTestNote as Le,DERIVED_MARK as J,DERIVED_KEY as we}from"../../renderer/testLabel.js";function _(u,a){return a?C(u,a).replace(/(\.\d*?)0+(?=\D|$)/,"$1").replace(/\.(?=\D|$)/,""):Number.isInteger(u)?String(u):String(Number(u.toPrecision(3)))}function Pe(u){const a=Me(u.label),S=a.length>9?`${a.slice(0,8)}\u2026`:a;return u.derived?`${J} ${S}`:S}const ie=260,ke=62,Ae=56,Ee=3;function Ie(u,a){const S=u.series[0]?.points[0]?.testNumber;return S===void 0?void 0:a?.find(j=>j.testNumber===S)?.unit}export function renderSweepPanel(u){const{spec:a,testDefs:S,onSaveImage:j,population:re}=u;let z=u.dies;const{card:y,body:M}=me(a.title,j,u.ownerDocument);y.style.alignSelf="start";const V=y.ownerDocument,N=V.createElement("div");Object.assign(N.style,{color:G.label,fontSize:oe.body,marginBottom:ne.sm}),y.insertBefore(N,M);const W=V.createElement("div");Object.assign(W.style,{color:G.label,fontSize:oe.body,marginTop:ne.sm}),y.appendChild(W);const L=xe(y);let X=null,E=null,$;const H=n=>a.series[n]?.color??he(n);function Q(){if(M.innerHTML="",W.innerHTML="",X?.disconnect(),X=null,a.series.length===0){N.textContent="",se(M,"This sweep defines no series.");return}if(E=ce(z,S,a),$=Ie(E,S),E.series.filter(i=>i.points.some(T=>T.count>0)).length===0){N.textContent="",se(M,fe(a,S)?"No values recorded for the tests in this sweep.":"None of this sweep\u2019s tests are in this data \u2014 it may belong to another test program."),Z();return}N.textContent=`Line = median across ${ye(E.dieCount,z.length,re)}, band = p10\u2013p90`+(a.series.length>2?" \xB7 crossing and separation measured between the first two series":"");const c=V.createElement("canvas");c.style.display="block",M.appendChild(c);let o=null;const w=()=>{const i=E;if(i===null)return;const T=Math.max(1,M.clientWidth),B=Math.max(ie,be(y,M,c,ie)),F=$e(c,y,T,B);if(!F)return;const{ctx:e,theme:x}=F,g=t=>i.xScale==="log"?Math.log10(t):t;let f=1/0,h=-1/0,b=1/0,v=-1/0;for(const t of i.series)for(const s of t.points)s.count!==0&&(f=Math.min(f,s.p10),h=Math.max(h,s.p90),b=Math.min(b,g(s.x)),v=Math.max(v,g(s.x)));for(const t of i.separations)f=Math.min(f,t.y),h=Math.max(h,t.y);if(!Number.isFinite(f)||!Number.isFinite(h))return;f===h&&(f-=1,h+=1);const l=(h-f)*.08;if(f-=l,h+=l,b===v&&(b-=.5,v+=.5),i.xScale==="log"){const t=(v-b)*.03;b-=t,v+=t}e.font=`${pe(-1)}px system-ui, sans-serif`;const r=Y+ke,p=T-Y-8,R=Y,P=B-Ae,k=t=>P-(t-f)/(h-f)*(P-R),D=t=>r+(g(t)-b)/(v-b)*(p-r);o={left:r,right:p,xLo:b,xHi:v,yOf:k,ax:g},e.strokeStyle=x.border,e.lineWidth=1,e.beginPath(),e.moveTo(r,R),e.lineTo(r,P),e.lineTo(p,P),e.stroke(),e.fillStyle=x.text,e.textAlign="right",e.textBaseline="middle";const q=Se(f,h,P-R,()=>ve),le=Te(Math.max(Math.abs(f),Math.abs(h)),$,q.step||void 0);for(const t of q.ticks)e.fillText(le.tickWithUnit(t),r-6,k(t));for(const t of i.separations){const s=k(t.y);e.save(),e.strokeStyle=x.limitLine,e.globalAlpha=.55,e.setLineDash([4,3]),e.beginPath(),e.moveTo(r,s),e.lineTo(p,s),e.stroke(),e.restore()}if(i.series.forEach((t,s)=>{const A=t.points.filter(d=>d.count>0);if(!(A.length<2)){e.save(),e.fillStyle=H(s),e.globalAlpha=.14,e.beginPath(),A.forEach((d,I)=>{const O=D(d.x),te=k(d.p90);I===0?e.moveTo(O,te):e.lineTo(O,te)});for(let d=A.length-1;d>=0;d--){const I=A[d];e.lineTo(D(I.x),k(I.p10))}e.closePath(),e.fill(),e.restore()}}),i.series.forEach((t,s)=>{e.strokeStyle=H(s),e.lineWidth=1.75,e.beginPath();let A=!1;for(const d of t.points){if(d.count===0){A=!1;continue}const I=D(d.x),O=k(d.median);A?e.lineTo(I,O):e.moveTo(I,O),A=!0}e.stroke(),e.fillStyle=H(s);for(const d of t.points)d.count!==0&&(e.beginPath(),e.arc(D(d.x),k(d.median),Ee,0,Math.PI*2),e.fill())}),i.crossing){const t=D(i.crossing.x),s=k(i.crossing.y);e.save(),e.strokeStyle=x.text,e.globalAlpha=.45,e.setLineDash([3,3]),e.beginPath(),e.moveTo(t,s),e.lineTo(t,P),e.stroke(),e.restore(),e.save(),e.strokeStyle=x.text,e.lineWidth=2,e.beginPath(),e.arc(t,s,5.5,0,Math.PI*2),e.stroke(),e.restore()}e.fillStyle=x.text,e.textBaseline="top",e.textAlign="center";const K=i.xIsPhysical?[...new Set(i.series.flatMap(t=>t.points.map(s=>s.x)))].sort((t,s)=>t-s).map(t=>({x:t,label:_(t,i.xUnit)})):(i.series[0]?.points??[]).map(t=>({x:t.x,label:Pe(t)})),ae=Math.max(1,Math.ceil(K.length*46/Math.max(1,p-r)));K.forEach((t,s)=>{s%ae!==0&&s!==K.length-1||e.fillText(t.label,D(t.x),P+6)}),e.save(),e.fillStyle=x.text,e.globalAlpha=.75,e.textAlign="center",e.textBaseline="bottom",e.fillText(i.xLabel,(r+p)/2,B-4),e.restore(),e.save(),e.fillStyle=x.text,e.globalAlpha=.75,e.translate(12,(R+P)/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(i.yLabel+($?` (${$})`:""),0,0),e.restore(),e.textAlign="left",e.textBaseline="middle";let U=r+4;const ee=R+8;i.series.forEach((t,s)=>{e.fillStyle=H(s),e.fillRect(U,ee-4,10,3),U+=14,e.fillStyle=x.text,e.fillText(t.label,U,ee),U+=e.measureText(t.label).width+16})};w(),X=ue(M,w),c.addEventListener("mousemove",i=>{const T=E;if(T===null||o===null){L.style.display="none";return}const B=c.getBoundingClientRect(),F=i.clientX-B.left,e=o.xLo+(F-o.left)/Math.max(1,o.right-o.left)*(o.xHi-o.xLo),x=o.ax;let g=null;for(const l of T.series)for(const r of l.points){if(r.count===0)continue;const p=Math.abs(x(r.x)-e);(g===null||p<g.dist)&&(g={x:r.x,dist:p})}if(g===null){L.style.display="none";return}const f=T.series.map(l=>l.points.find(r=>r.x===g.x&&r.count>0)),h=T.series.map((l,r)=>{const p=f[r];return p===void 0?"":`<span style="color:${H(r)}">\u25A0</span> ${p.derived?`${J} `:""}${m(l.label)}: <strong>${m(C(p.median,$))}</strong><br><span style="opacity:${de.muted}">p10 ${m(C(p.p10,$))} \u2013 p90 ${m(C(p.p90,$))} \xB7 n=${p.count.toLocaleString()}</span>`}).filter(Boolean);if(h.length===0){L.style.display="none";return}const b=T.series.flatMap(l=>l.points).find(l=>l.x===g.x&&l.count>0),v=[...new Set(f.map(l=>Le(l)).filter(l=>l!==void 0))];L.innerHTML=`<strong>${m(b?.label??"")}</strong><br>`+h.join("<br>")+v.map(l=>`<br><em>${m(l)}</em>`).join(""),L.style.display="block",ge(L,y,i.clientX,i.clientY)}),c.addEventListener("mouseleave",()=>{L.style.display="none"}),Z()}function Z(){const n=E;if(n===null)return;const c=[];n.notMeasured!==void 0?c.push(`<strong>Crossing and widths:</strong> not measured \u2014 ${m(n.notMeasured)}`):n.crossing?c.push(`<strong>Crossing:</strong> ${m(`${n.xLabel} = ${_(n.crossing.x,n.xUnit)}`)} \xB7 ${m(`${n.yLabel} ${C(n.crossing.y,$)}`)}`+(n.crossing.multiple?" <em>(first of several \u2014 the curves cross more than once)</em>":"")):(a.crossing??!0)&&a.series.length>=2&&c.push("<strong>Crossing:</strong> the first two series do not cross over the swept range");for(const o of n.separations)if(o.distance!==null){const w=o.ratio!==void 0&&o.from!==void 0&&o.to!==void 0?`\xD7${Number(o.ratio.toPrecision(3))} on the ${n.xLabel} axis (${_(o.from,n.xUnit)} \u2192 ${_(o.to,n.xUnit)})`:`${_(o.distance,n.xUnit)} on the ${n.xLabel} axis`;c.push(`<strong>Width at ${m(C(o.y,$))}:</strong> ${m(w)}`)}else{const w=o.reason==="second-series-never-reaches"?n.series[1]?.label:n.series[0]?.label;c.push(`<strong>Width at ${m(C(o.y,$))}:</strong> not measurable \u2014 ${m(w??"a series")} never reaches this level`)}n.series.some(o=>o.points.some(w=>w.derived))&&c.push(`${J} ${m(we)} \u2014 hover a point for the expression`);for(const o of n.warnings)c.push(`<span style="color:${G.errText}">${m(o)}</span>`);W.innerHTML=c.join("<br>")}return Q(),{card:y,destroy:()=>{X?.disconnect(),L.remove(),y.remove()},setDies:n=>{z=n,Q()}}}
1
+ import{buildSweepData as de,sweepAppliesTo as ue}from"../../stats/sweep.js";import{fmt as N}from"../../renderer/fmt.js";import{SPACE as oe,fontPx as he,FONT as ie,CLR as Y,ALPHA as me}from"../toolbar.js";import{categorical as xe}from"./palette.js";import{cardShell as ge,observeResize as be,makeTooltip as ye,positionChartTooltip as $e,renderEmptyState as re,chartFillHeight as Te,populationPhrase as ve,PADDING as J,prepareCanvas as Se,makeAxisFormat as Me,VERTICAL_TICK_SPACING_PX as Le}from"./chartShell.js";import{fitTicks as we}from"../../renderer/axisTicks.js";import{escHtml as m}from"../../core/utils.js";import{unmarkedLabel as Pe,derivedTestNote as ke,DERIVED_MARK as Q,DERIVED_KEY as Ae}from"../../renderer/testLabel.js";function O(c,x){return x?N(c,x).replace(/(\.\d*?)0+(?=\D|$)/,"$1").replace(/\.(?=\D|$)/,""):Number.isInteger(c)?String(c):String(Number(c.toPrecision(3)))}function Ce(c){const x=Pe(c.label),E=x.length>9?`${x.slice(0,8)}\u2026`:x;return c.derived?`${Q} ${E}`:E}const le=260,Ee=62,Ie=56,Ne=3;function De(c,x){const E=c.series[0]?.points[0]?.testNumber;return E===void 0?void 0:x?.find(j=>j.testNumber===E)?.unit}export function renderSweepPanel(c){const{testDefs:x,onSaveImage:E,population:j}=c;let S=c.spec,z=c.dies;const{card:g,body:L,heading:ae,controlsRow:ce}=ge(S.title,E,c.ownerDocument);g.style.alignSelf="start";const V=g.ownerDocument,D=V.createElement("div");D.dataset.wmapCaption="1",Object.assign(D.style,{color:Y.label,fontSize:ie.body,marginBottom:oe.sm}),g.insertBefore(D,L);const W=V.createElement("div");Object.assign(W.style,{color:Y.label,fontSize:ie.body,marginTop:oe.sm}),g.appendChild(W);const w=ye(g);let F=null,M=null,$;const R=n=>S.series[n]?.color??xe(n);function K(){if(L.innerHTML="",W.innerHTML="",F?.disconnect(),F=null,S.series.length===0){D.textContent="",re(L,"This sweep defines no series.");return}if(M=de(z,x,S),$=De(M,x),M.series.filter(s=>s.points.some(d=>d.count>0)).length===0){D.textContent="",re(L,ue(S,x)?"No values recorded for the tests in this sweep.":"None of this sweep\u2019s tests are in this data \u2014 it may belong to another test program."),Z();return}D.textContent=`Line = median across ${ve(M.dieCount,z.length,j)}, band = p10\u2013p90`+(S.series.length>2?" \xB7 crossing and separation measured between the first two series":"")+(c.onSelectPoint?" \xB7 click a level to chart or tabulate the dies measured there":"");const l=V.createElement("canvas");l.style.display="block",L.appendChild(l);let i=null;const P=()=>{const s=M;if(s===null)return;const d=Math.max(1,L.clientWidth),b=Math.max(le,Te(g,L,l,le)),y=Se(l,g,d,b);if(!y)return;const{ctx:e,theme:f}=y,T=t=>s.xScale==="log"?Math.log10(t):t;let a=1/0,o=-1/0,u=1/0,h=-1/0;for(const t of s.series)for(const r of t.points)r.count!==0&&(a=Math.min(a,r.p10),o=Math.max(o,r.p90),u=Math.min(u,T(r.x)),h=Math.max(h,T(r.x)));for(const t of s.separations)a=Math.min(a,t.y),o=Math.max(o,t.y);if(!Number.isFinite(a)||!Number.isFinite(o))return;a===o&&(a-=1,o+=1);const ee=(o-a)*.08;if(a-=ee,o+=ee,u===h&&(u-=.5,h+=.5),s.xScale==="log"){const t=(h-u)*.03;u-=t,h+=t}e.font=`${he(-1)}px system-ui, sans-serif`;const v=J+Ee,H=d-J-8,X=J,k=b-Ie,A=t=>k-(t-a)/(o-a)*(k-X),B=t=>v+(T(t)-u)/(h-u)*(H-v);i={left:v,right:H,xLo:u,xHi:h,yOf:A,ax:T},e.strokeStyle=f.border,e.lineWidth=1,e.beginPath(),e.moveTo(v,X),e.lineTo(v,k),e.lineTo(H,k),e.stroke(),e.fillStyle=f.text,e.textAlign="right",e.textBaseline="middle";const te=we(a,o,k-X,()=>Le),fe=Me(Math.max(Math.abs(a),Math.abs(o)),$,te.step||void 0);for(const t of te.ticks)e.fillText(fe.tickWithUnit(t),v-6,A(t));for(const t of s.separations){const r=A(t.y);e.save(),e.strokeStyle=f.limitLine,e.globalAlpha=.55,e.setLineDash([4,3]),e.beginPath(),e.moveTo(v,r),e.lineTo(H,r),e.stroke(),e.restore()}if(s.series.forEach((t,r)=>{const C=t.points.filter(p=>p.count>0);if(!(C.length<2)){e.save(),e.fillStyle=R(r),e.globalAlpha=.14,e.beginPath(),C.forEach((p,I)=>{const _=B(p.x),se=A(p.p90);I===0?e.moveTo(_,se):e.lineTo(_,se)});for(let p=C.length-1;p>=0;p--){const I=C[p];e.lineTo(B(I.x),A(I.p10))}e.closePath(),e.fill(),e.restore()}}),s.series.forEach((t,r)=>{e.strokeStyle=R(r),e.lineWidth=1.75,e.beginPath();let C=!1;for(const p of t.points){if(p.count===0){C=!1;continue}const I=B(p.x),_=A(p.median);C?e.lineTo(I,_):e.moveTo(I,_),C=!0}e.stroke(),e.fillStyle=R(r);for(const p of t.points)p.count!==0&&(e.beginPath(),e.arc(B(p.x),A(p.median),Ne,0,Math.PI*2),e.fill())}),s.crossing){const t=B(s.crossing.x),r=A(s.crossing.y);e.save(),e.strokeStyle=f.text,e.globalAlpha=.45,e.setLineDash([3,3]),e.beginPath(),e.moveTo(t,r),e.lineTo(t,k),e.stroke(),e.restore(),e.save(),e.strokeStyle=f.text,e.lineWidth=2,e.beginPath(),e.arc(t,r,5.5,0,Math.PI*2),e.stroke(),e.restore()}e.fillStyle=f.text,e.textBaseline="top",e.textAlign="center";const G=s.xIsPhysical?[...new Set(s.series.flatMap(t=>t.points.map(r=>r.x)))].sort((t,r)=>t-r).map(t=>({x:t,label:O(t,s.xUnit)})):(s.series[0]?.points??[]).map(t=>({x:t.x,label:Ce(t)})),pe=Math.max(1,Math.ceil(G.length*46/Math.max(1,H-v)));G.forEach((t,r)=>{r%pe!==0&&r!==G.length-1||e.fillText(t.label,B(t.x),k+6)}),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.textAlign="center",e.textBaseline="bottom",e.fillText(s.xLabel,(v+H)/2,b-4),e.restore(),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.translate(12,(X+k)/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(s.yLabel+($?` (${$})`:""),0,0),e.restore(),e.textAlign="left",e.textBaseline="middle";let U=v+4;const ne=X+8;s.series.forEach((t,r)=>{e.fillStyle=R(r),e.fillRect(U,ne-4,10,3),U+=14,e.fillStyle=f.text,e.fillText(t.label,U,ne),U+=e.measureText(t.label).width+16})};P(),F=be(L,P);const q=s=>{const d=M;if(d===null||i===null)return null;const b=s.clientX-l.getBoundingClientRect().left,y=i.xLo+(b-i.left)/Math.max(1,i.right-i.left)*(i.xHi-i.xLo);let e=null;for(const f of d.series)for(const T of f.points){if(T.count===0)continue;const a=Math.abs(i.ax(T.x)-y);(e===null||a<e.dist)&&(e={x:T.x,dist:a})}return e===null?null:e.x};l.addEventListener("mousemove",s=>{const d=M,b=q(s);if(d===null||b===null){w.style.display="none";return}const y={x:b},e=d.series.map(o=>o.points.find(u=>u.x===y.x&&u.count>0)),f=d.series.map((o,u)=>{const h=e[u];return h===void 0?"":`<span style="color:${R(u)}">\u25A0</span> ${h.derived?`${Q} `:""}${m(o.label)}: <strong>${m(N(h.median,$))}</strong><br><span style="opacity:${me.muted}">p10 ${m(N(h.p10,$))} \u2013 p90 ${m(N(h.p90,$))} \xB7 n=${h.count.toLocaleString()}</span>`}).filter(Boolean);if(f.length===0){w.style.display="none";return}const T=d.series.flatMap(o=>o.points).find(o=>o.x===y.x&&o.count>0),a=[...new Set(e.map(o=>ke(o)).filter(o=>o!==void 0))];w.innerHTML=`<strong>${m(T?.label??"")}</strong><br>`+f.join("<br>")+a.map(o=>`<br><em>${m(o)}</em>`).join(""),w.style.display="block",$e(w,g,s.clientX,s.clientY)}),l.addEventListener("mouseleave",()=>{w.style.display="none"}),c.onSelectPoint&&(l.style.cursor="pointer",l.addEventListener("click",s=>{const d=M,b=q(s);if(d===null||b===null)return;const y=d.series.flatMap(e=>e.points.filter(f=>f.x===b&&f.count>0));y.length!==0&&(w.style.display="none",c.onSelectPoint({testNumbers:y.map(e=>e.testNumber),label:y[0].label},s))})),Z()}function Z(){const n=M;if(n===null)return;const l=[];n.notMeasured!==void 0?l.push(`<strong>Crossing and widths:</strong> not measured \u2014 ${m(n.notMeasured)}`):n.crossing?l.push(`<strong>Crossing:</strong> ${m(`${n.xLabel} = ${O(n.crossing.x,n.xUnit)}`)} \xB7 ${m(`${n.yLabel} ${N(n.crossing.y,$)}`)}`+(n.crossing.multiple?" <em>(first of several \u2014 the curves cross more than once)</em>":"")):(S.crossing??!0)&&S.series.length>=2&&l.push("<strong>Crossing:</strong> the first two series do not cross over the swept range");for(const i of n.separations)if(i.distance!==null){const P=i.ratio!==void 0&&i.from!==void 0&&i.to!==void 0?`\xD7${Number(i.ratio.toPrecision(3))} on the ${n.xLabel} axis (${O(i.from,n.xUnit)} \u2192 ${O(i.to,n.xUnit)})`:`${O(i.distance,n.xUnit)} on the ${n.xLabel} axis`;l.push(`<strong>Width at ${m(N(i.y,$))}:</strong> ${m(P)}`)}else{const P=i.reason==="second-series-never-reaches"?n.series[1]?.label:n.series[0]?.label;l.push(`<strong>Width at ${m(N(i.y,$))}:</strong> not measurable \u2014 ${m(P??"a series")} never reaches this level`)}n.series.some(i=>i.points.some(P=>P.derived))&&l.push(`${Q} ${m(Ae)} \u2014 hover a point for the expression`);for(const i of n.warnings)l.push(`<span style="color:${Y.errText}">${m(i)}</span>`);W.innerHTML=l.join("<br>")}return K(),{card:g,destroy:()=>{F?.disconnect(),w.remove(),g.remove()},setDies:n=>{z=n,K()},setSpec:n=>{S=n,ae.textContent=n.title,g.dataset.wmapChartTitle=n.title,K()},actions:ce}}
@@ -1,3 +1,4 @@
1
+ import { type TestPassKind } from '../../stats/testPassRate.js';
1
2
  import type { TestPassRateItem } from '../../stats/testPassRate.js';
2
3
  import type { TestDef } from '../../renderer/buildWaferMap.js';
3
4
  import { type SaveImageHandler } from './chartShell.js';
@@ -10,6 +11,12 @@ export interface TestPassRatePanelOptions {
10
11
  }[];
11
12
  testDefs: TestDef[] | undefined;
12
13
  onSaveImage?: SaveImageHandler;
14
+ /** Click a test's row: the host picks out the dies that fail it (judged the way the card is showing). */
15
+ onSelectTest?: (row: {
16
+ testNumber: number;
17
+ label: string;
18
+ kind: TestPassKind;
19
+ }, e: MouseEvent) => void;
13
20
  ownerDocument?: Document;
14
21
  }
15
22
  export interface TestPassRatePanelHandle {
@@ -1 +1 @@
1
- import{buildTestPassRateData as F,hasJudgeableTests as B}from"../../stats/testPassRate.js";import{categorical as I,QUANTITY as N}from"./palette.js";import{SPACE as H,FONT as _,CLR as S}from"../toolbar.js";import{cardShell as A,makeTooltip as O,makeSegmented as j,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as M}from"./groupedBarPlot.js";import{escHtml as g}from"../../core/utils.js";const k=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(f){const{groups:u,testDefs:b,onSaveImage:$}=f,p=f.ownerDocument??document,P=u.flatMap(t=>t.items.flatMap(a=>a.dies??[])),d=["spec","testFlag","functional"].filter(t=>B(b,t,P));let s=d[0]??"spec";const h=t=>U[t],{card:o,heading:v,body:i,controlsRow:x}=A(h(s),$,p);o.style.alignSelf="start",d.length>1&&x.appendChild(j(d.map(t=>[t,K[t]]),s,t=>{s=t,v.textContent=h(s),T()},p));const n=p.createElement("div");Object.assign(n.style,{color:S.label,fontSize:_.body,marginBottom:H.sm}),o.insertBefore(n,i);const D=O(o);let m=null;function T(){if(m?.destroy(),m=null,i.innerHTML="",d.length===0){n.textContent="",y(i,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const t=F(u,b,s);if(t.rows.length===0){n.textContent="",y(i,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const a=t.groups.length>1,R=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(n.textContent=R+(a?" \xB7 one bar per group":"")+" \xB7 worst first",t.disagreementDies){const e=p.createElement("span");e.textContent=` \xB7 ${t.disagreementDies.toLocaleString()} die${t.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(e.style,{color:S.warnText}),n.appendChild(e)}const L=t.rows,C=e=>a?I(e):N;m=M(o,i,D,{rows:L.map(e=>({label:e.label,bars:e.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:e.overall.passRatePercent===null?"\u2014":`${e.overall.passRatePercent.toFixed(1)}%`})),groups:t.groups,labelWidth:k,maxVisibleRows:G,showLegend:a,maxLabelChars:14,emptyBarText:"no data",colorOf:C,tooltipHtml:(e,l)=>{const r=L[e],c=r.byGroup[l],w=a?` \xB7 ${g(String(t.groups[l]))}`:"";if(c.passRatePercent===null)return`<strong>${g(r.label)}</strong>${w}<br>no dies with a verdict`;const E=s==="spec"&&!a&&(r.failLowDies||r.failHighDies)?`<br>${r.failLowDies??0} below the low limit \xB7 ${r.failHighDies??0} above the high limit`:"";return`<strong>${g(r.label)}</strong>${w}<br>${c.passRatePercent.toFixed(1)}% pass<br>${c.passDies.toLocaleString()} pass \xB7 ${c.failDies.toLocaleString()} fail \xB7 n = ${c.totalDies.toLocaleString()}`+E}})}return T(),{card:o,destroy:()=>{m?.destroy(),D.remove(),o.remove()}}}
1
+ import{buildTestPassRateData as F,hasJudgeableTests as E}from"../../stats/testPassRate.js";import{categorical as I,QUANTITY as B}from"./palette.js";import{SPACE as _,FONT as H,CLR as L}from"../toolbar.js";import{cardShell as A,makeTooltip as O,makeSegmented as j,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as k}from"./groupedBarPlot.js";import{escHtml as f}from"../../core/utils.js";const M=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},J={spec:"Judged from each die's measured value against the test's limits",testFlag:"The pass or fail the tester recorded for each die",functional:"Tests that only pass or fail and have no measured value"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(i){const{groups:h,testDefs:b,onSaveImage:v}=i,p=i.ownerDocument??document,$=h.flatMap(e=>e.items.flatMap(o=>o.dies??[])),m=["spec","testFlag","functional"].filter(e=>E(b,e,$));let s=m[0]??"spec";const T=e=>U[e],{card:n,heading:C,body:c,controlsRow:P}=A(T(s),v,p);n.style.alignSelf="start",m.length>1&&P.appendChild(j(m.map(e=>[e,K[e],J[e]]),s,e=>{s=e,C.textContent=T(s),S()},p));const r=p.createElement("div");r.dataset.wmapCaption="1",Object.assign(r.style,{color:L.label,fontSize:H.body,marginBottom:_.sm}),n.insertBefore(r,c);const D=O(n);let g=null;function S(){if(g?.destroy(),g=null,c.innerHTML="",m.length===0){r.textContent="",y(c,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const e=F(h,b,s);if(e.rows.length===0){r.textContent="",y(c,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const o=e.groups.length>1,R=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(r.textContent=R+(o?" \xB7 one bar per group":"")+" \xB7 worst first"+(i.onSelectTest?" \xB7 click a test to chart or tabulate the dies that fail it":""),e.disagreementDies){const t=p.createElement("span");t.textContent=` \xB7 ${e.disagreementDies.toLocaleString()} die${e.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(t.style,{color:L.warnText}),r.appendChild(t)}const u=e.rows,x=t=>o?I(t):B;g=k(n,c,D,{rows:u.map(t=>({label:t.label,bars:t.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:t.overall.passRatePercent===null?"\u2014":`${t.overall.passRatePercent.toFixed(1)}%`})),groups:e.groups,labelWidth:M,maxVisibleRows:G,showLegend:o,maxLabelChars:14,emptyBarText:"no data",colorOf:x,onRowClick:i.onSelectTest?(t,l,a)=>i.onSelectTest({testNumber:u[t].testNumber,label:u[t].label,kind:s},a):void 0,tooltipHtml:(t,l)=>{const a=u[t],d=a.byGroup[l],w=o?` \xB7 ${f(String(e.groups[l]))}`:"";if(d.passRatePercent===null)return`<strong>${f(a.label)}</strong>${w}<br>no dies with a verdict`;const N=s==="spec"&&!o&&(a.failLowDies||a.failHighDies)?`<br>${a.failLowDies??0} below the low limit \xB7 ${a.failHighDies??0} above the high limit`:"";return`<strong>${f(a.label)}</strong>${w}<br>${d.passRatePercent.toFixed(1)}% pass<br>${d.passDies.toLocaleString()} pass \xB7 ${d.failDies.toLocaleString()} fail \xB7 n = ${d.totalDies.toLocaleString()}`+N}})}return S(),{card:n,destroy:()=>{g?.destroy(),D.remove(),n.remove()}}}
@@ -11,6 +11,17 @@ export interface TrendPanelOptions {
11
11
  onOpen?: (key: number, testNumber: number) => void;
12
12
  /** Right-click on a wafer's point — see `WaferContextMenuHandler`. */
13
13
  onWaferContextMenu?: WaferContextMenuHandler;
14
+ /**
15
+ * Drag across the trend to pick a run of wafers: their `key`s (the wafer indexes), the test shown, where the pointer
16
+ * was released and the canvas to anchor a menu on. The wafers' own dies are the population.
17
+ */
18
+ onSelectWafers?: (sel: {
19
+ keys: number[];
20
+ testNumber: number;
21
+ }, at: {
22
+ x: number;
23
+ y: number;
24
+ }, anchor: HTMLElement) => void;
14
25
  /**
15
26
  * What the dashed reference line is, as a noun phrase — "lot mean" when the
16
27
  * items are one lot, else "mean of all wafers" (see stats/population.ts).
@@ -1 +1 @@
1
- import{buildTestTrendData as ke,trendCentre as we}from"../../stats/trend.js";import{isParametricTest as Ce}from"../../renderer/buildWaferMap.js";import{fmt as W}from"../../renderer/fmt.js";import{SPACE as re,fontPx as ce,FONT as Ae,CLR as Me}from"../toolbar.js";import{QUANTITY as G}from"./palette.js";import{cardShell as Pe,observeResize as Se,makeTooltip as Ne,positionChartTooltip as Ee,makeLinkedTestSelect as Ie,makeLinkedAxisPrefs as De,renderEmptyState as U,chartFillHeight as Oe,PADDING as j,resolveAxisRange as We,shouldIncludeLimitsByDefault as He,drawOffAxisLimits as $e,limitLines as me,limitExtent as de,hasBothLimitKinds as Re,stackLabelRows as Be,strokeLimitLine as Fe,makeAxisFormat as _e,VERTICAL_TICK_SPACING_PX as Xe,WAFER_MENU_HINT as ze,prepareCanvas as Ge}from"./chartShell.js";import{fitTicks as Ue}from"../../renderer/axisTicks.js";import{escHtml as K}from"../../core/utils.js";import{maxOf as je}from"../../core/utils.js";const fe=220,Ke=56,Ye=34,Qe=3.5;export function renderTrendPanel(d){const{items:Y,testDefs:ue,onSaveImage:he,onOpen:C,centreLabel:Q="mean of all wafers"}=d,pe=d.title??"Wafer-to-wafer trend",{card:a,body:u,controlsRow:V}=Pe(pe,he,d.ownerDocument);a.style.alignSelf="start";const N=ue.filter(s=>s.testNumber!==void 0&&Ce(s));let h=d.selectedTestNumber??N[0]?.testNumber??null,H=0;const q=Ie(N,h,s=>{h=s,A(),d.onTestChange?.(s)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:a.ownerDocument});V.appendChild(q.el);const $=a.ownerDocument.createElement("span");Object.assign($.style,{display:"inline-flex",gap:re.lg,alignItems:"center"}),V.appendChild($);const R=De($,d.axisPrefs,s=>{d.onAxisPrefsChange?.(s),A()},a.ownerDocument),w=a.ownerDocument.createElement("div");Object.assign(w.style,{color:Me.label,fontSize:Ae.body,marginBottom:re.sm}),a.insertBefore(w,u);const b=Ne(a);let E=null,i=[];function xe(s){return N.find(B=>B.testNumber===s)}function A(){const{includeLimits:s,clipOutliers:B,limits:be}=R.get();if(u.innerHTML="",E?.disconnect(),E=null,N.length===0||h===null){w.textContent="",U(u,"No parametric test data available for a trend.");return}if(Y.length<2){w.textContent="",U(u,"A wafer-to-wafer trend needs at least two wafers.");return}if(i=ke(Y,h),!i.some(o=>o.count>0)){w.textContent="",U(u,"No values recorded for this test.");return}const p=xe(h),I=me(p,be),g=we(i),J=()=>{w.textContent=`Point = wafer mean, whisker = \xB11\u03C3, dashed = ${Q} \xB7 wafers in slot order`+(C?" \xB7 click a point to open that wafer":"")+(H?` \xB7 axis clipped, ${H} outside`:"")};J();const m=a.ownerDocument.createElement("canvas");m.style.display="block",u.appendChild(m);let M=null;const Z=()=>{const o=Math.max(1,u.clientWidth),r=Math.max(fe,Oe(a,u,m,fe)),n=Ge(m,a,o,r);if(!n)return;const{ctx:e,theme:y}=n;let P=1/0,S=-1/0;const ee=[];for(const t of i)!t.count||!Number.isFinite(t.mean)||(P=Math.min(P,t.mean-t.stddev),S=Math.max(S,t.mean+t.stddev),ee.push(t.mean-t.stddev,t.mean+t.stddev));if(!Number.isFinite(P)||!Number.isFinite(S))return;const te=s??He(P,S,de(I).lo,de(I).hi);R.sync(te,me(p).length>0,Re(p));const D=We({dataMin:P,dataMax:S,limits:I,includeLimits:te,clipOutliers:B,values:ee});H=D.clippedCount,J();let x=D.lo,v=D.hi;const ne=(v-x)*.08;x-=ne,v+=ne;const c=j+Ke;e.font=`${ce(-1)}px system-ui, sans-serif`;const ie=t=>t.length>8?`${t.slice(0,7)}\u2026`:t,ge=i.length?Math.ceil(Math.max(e.measureText(ie(i[0].label)).width,e.measureText(ie(i[i.length-1].label)).width)/2):0,T=o-j-ge,O=j,L=r-Ye,k=t=>L-(t-x)/(v-x)*(L-O),se=i.length>1?(T-c)/(i.length-1):0;M={left:c,step:se};const _=t=>i.length>1?c+t*se:(c+T)/2;e.strokeStyle=y.border,e.lineWidth=1,e.beginPath(),e.moveTo(c,O),e.lineTo(c,L),e.lineTo(T,L),e.stroke(),e.fillStyle=y.text,e.textAlign="right",e.textBaseline="middle";const oe=Ue(x,v,L-O,()=>Xe),ye=_e(Math.max(Math.abs(x),Math.abs(v)),p?.unit,oe.step||void 0);for(const t of oe.ticks)e.fillText(ye.tickWithUnit(t),c-6,k(t));$e(e,D.offAxis,{left:c,right:T,top:O,bottom:L},"vertical",y.limitLine,t=>W(t,p?.unit));const le=ce(-1),X=I.filter(t=>t.value>=x&&t.value<=v).map(t=>{const l=k(t.value);return{l:t,y:l,start:l-6-le/2,end:l-6+le/2}}),ve=Be(X,1),Te=je(X.map(t=>e.measureText(t.l.label).width))+8;if(X.forEach(({l:t,y:l},f)=>{e.save(),e.globalAlpha=.7,Fe(e,t,y.limitLine,c,l,T,l),e.restore(),e.save(),e.fillStyle=y.limitLine,e.textAlign="left",e.fillText(t.label,c+3+ve[f]*Te,l-6),e.restore()}),g!==null&&g>=x&&g<=v){const t=k(g);e.save(),e.strokeStyle=y.text,e.globalAlpha=.5,e.setLineDash([3,3]),e.beginPath(),e.moveTo(c,t),e.lineTo(T,t),e.stroke(),e.restore()}e.strokeStyle=G,e.lineWidth=1.5,e.beginPath();let z=!1;i.forEach((t,l)=>{if(!t.count||!Number.isFinite(t.mean)){z=!1;return}const f=_(l),ae=k(t.mean);z?e.lineTo(f,ae):e.moveTo(f,ae),z=!0}),e.stroke(),i.forEach((t,l)=>{if(!t.count||!Number.isFinite(t.mean))return;const f=_(l);t.stddev>0&&(e.save(),e.strokeStyle=G,e.globalAlpha=.55,e.lineWidth=1,e.beginPath(),e.moveTo(f,k(t.mean-t.stddev)),e.lineTo(f,k(t.mean+t.stddev)),e.stroke(),e.restore()),e.fillStyle=G,e.beginPath(),e.arc(f,k(t.mean),Qe,0,Math.PI*2),e.fill()}),e.fillStyle=y.text,e.textBaseline="top",e.textAlign="center";const Le=Math.max(1,Math.ceil(i.length*42/Math.max(1,T-c)));i.forEach((t,l)=>{if(l%Le!==0&&l!==i.length-1)return;const f=t.label.length>8?`${t.label.slice(0,7)}\u2026`:t.label;e.fillText(f,_(l),L+6)})},F=o=>{if(!M||M.step<=0)return-1;const r=m.getBoundingClientRect(),n=Math.round((o.clientX-r.left-M.left)/M.step);return n>=0&&n<i.length&&i[n].count>0?n:-1};m.addEventListener("mousemove",o=>{const r=F(o);if(r<0){b.style.display="none",m.style.cursor="default";return}const n=i[r];m.style.cursor=C&&n.key!==void 0?"pointer":"default",b.innerHTML=`<strong>${K(n.label)}</strong><br>`+K(`mean ${W(n.mean,p?.unit)} \xB7 \u03C3 ${W(n.stddev,p?.unit)}`)+`<br>n = ${n.count.toLocaleString()}`+(g!==null?"<br>"+K(`\u0394 vs ${Q} ${n.mean-g>=0?"+":""}${W(n.mean-g,p?.unit)}`):"")+(C&&n.key!==void 0?"<br><em>click to open this wafer</em>":"")+(d.onWaferContextMenu&&n.key!==void 0?ze:""),b.style.display="block",Ee(b,a,o.clientX,o.clientY)}),m.addEventListener("mouseleave",()=>{b.style.display="none"}),m.addEventListener("click",o=>{const r=F(o);if(r<0||!C)return;const n=i[r];n.key!==void 0&&h!==null&&C(n.key,h)}),m.addEventListener("contextmenu",o=>{const r=F(o),n=r<0?void 0:i[r].key;n===void 0||!d.onWaferContextMenu||(b.style.display="none",d.onWaferContextMenu(n,h??void 0,o))}),Z(),E=Se(u,Z)}return A(),{card:a,destroy:()=>{E?.disconnect(),b.remove(),a.remove()},setTest:s=>{q.set(s)&&(h=s,A())},setAxisPrefs:s=>{R.set(s)&&A()}}}
1
+ import{buildTestTrendData as Se,trendCentre as Ce}from"../../stats/trend.js";import{isParametricTest as Ae}from"../../renderer/buildWaferMap.js";import{fmt as H}from"../../renderer/fmt.js";import{SPACE as ce,fontPx as me,FONT as Pe,CLR as Me}from"../toolbar.js";import{QUANTITY as X}from"./palette.js";import{wirePointInteractions as Ne}from"./pointInteractions.js";import{cardShell as Ie,observeResize as We,makeTooltip as Ee,makeLinkedTestSelect as De,makeLinkedAxisPrefs as Oe,renderEmptyState as j,chartFillHeight as He,PADDING as K,resolveAxisRange as $e,shouldIncludeLimitsByDefault as Re,drawOffAxisLimits as _e,limitLines as fe,limitExtent as de,hasBothLimitKinds as Be,stackLabelRows as Fe,strokeLimitLine as ze,makeAxisFormat as Ge,VERTICAL_TICK_SPACING_PX as Ue,WAFER_MENU_HINT as Xe,prepareCanvas as je}from"./chartShell.js";import{fitTicks as Ke}from"../../renderer/axisTicks.js";import{escHtml as Q}from"../../core/utils.js";import{maxOf as Qe}from"../../core/utils.js";const ue=220,Ve=56,Ye=34,he=3.5;export function renderTrendPanel(a){const{items:V,testDefs:pe,onSaveImage:xe,onOpen:M,centreLabel:Y="mean of all wafers"}=a,be=a.title??"Wafer-to-wafer trend",{card:c,body:h,controlsRow:q}=Ie(be,xe,a.ownerDocument);c.style.alignSelf="start";const N=pe.filter(l=>l.testNumber!==void 0&&Ae(l));let f=a.selectedTestNumber??N[0]?.testNumber??null,$=0;const J=De(N,f,l=>{f=l,S(),a.onTestChange?.(l)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:c.ownerDocument});q.appendChild(J.el);const R=c.ownerDocument.createElement("span");Object.assign(R.style,{display:"inline-flex",gap:ce.lg,alignItems:"center"}),q.appendChild(R);const _=Oe(R,a.axisPrefs,l=>{a.onAxisPrefsChange?.(l),S()},c.ownerDocument),y=c.ownerDocument.createElement("div");y.dataset.wmapCaption="1",Object.assign(y.style,{color:Me.label,fontSize:Pe.body,marginBottom:ce.sm}),c.insertBefore(y,h);const B=Ee(c);let I=null,s=[];function ge(l){return N.find(F=>F.testNumber===l)}function S(){const{includeLimits:l,clipOutliers:F,limits:ye}=_.get();if(h.innerHTML="",I?.disconnect(),I=null,N.length===0||f===null){y.textContent="",j(h,"No parametric test data available for a trend.");return}if(V.length<2){y.textContent="",j(h,"A wafer-to-wafer trend needs at least two wafers.");return}if(s=Se(V,f),!s.some(i=>i.count>0)){y.textContent="",j(h,"No values recorded for this test.");return}const p=ge(f),W=fe(p,ye),v=Ce(s),Z=()=>{y.textContent=`Point = wafer mean, whisker = \xB11\u03C3, dashed = ${Y} \xB7 wafers in slot order`+(M?" \xB7 click a point to open that wafer":"")+(a.onSelectWafers?" \xB7 drag across the plot to select wafers":"")+($?` \xB7 axis clipped, ${$} outside`:"")};Z();const x=c.ownerDocument.createElement("canvas");x.style.display="block",h.appendChild(x);let T=null;const C=new Set,E=()=>{const i=Math.max(1,h.clientWidth),n=Math.max(ue,He(c,h,x,ue)),o=je(x,c,i,n);if(!o)return;const{ctx:e,theme:u}=o;let A=1/0,P=-1/0;const te=[];for(const t of s)!t.count||!Number.isFinite(t.mean)||(A=Math.min(A,t.mean-t.stddev),P=Math.max(P,t.mean+t.stddev),te.push(t.mean-t.stddev,t.mean+t.stddev));if(!Number.isFinite(A)||!Number.isFinite(P))return;const ne=l??Re(A,P,de(W).lo,de(W).hi);_.sync(ne,fe(p).length>0,Be(p));const D=$e({dataMin:A,dataMax:P,limits:W,includeLimits:ne,clipOutliers:F,values:te});$=D.clippedCount,Z();let b=D.lo,k=D.hi;const se=(k-b)*.08;b-=se,k+=se;const m=K+Ve;e.font=`${me(-1)}px system-ui, sans-serif`;const ie=t=>t.length>8?`${t.slice(0,7)}\u2026`:t,ve=s.length?Math.ceil(Math.max(e.measureText(ie(s[0].label)).width,e.measureText(ie(s[s.length-1].label)).width)/2):0,w=i-K-ve,O=K,L=n-Ye,g=t=>L-(t-b)/(k-b)*(L-O),oe=s.length>1?(w-m)/(s.length-1):0;T={left:m,step:oe};const z=t=>s.length>1?m+t*oe:(m+w)/2;e.strokeStyle=u.border,e.lineWidth=1,e.beginPath(),e.moveTo(m,O),e.lineTo(m,L),e.lineTo(w,L),e.stroke(),e.fillStyle=u.text,e.textAlign="right",e.textBaseline="middle";const le=Ke(b,k,L-O,()=>Ue),Te=Ge(Math.max(Math.abs(b),Math.abs(k)),p?.unit,le.step||void 0);for(const t of le.ticks)e.fillText(Te.tickWithUnit(t),m-6,g(t));_e(e,D.offAxis,{left:m,right:w,top:O,bottom:L},"vertical",u.limitLine,t=>H(t,p?.unit));const re=me(-1),G=W.filter(t=>t.value>=b&&t.value<=k).map(t=>{const r=g(t.value);return{l:t,y:r,start:r-6-re/2,end:r-6+re/2}}),ke=Fe(G,1),we=Qe(G.map(t=>e.measureText(t.l.label).width))+8;if(G.forEach(({l:t,y:r},d)=>{e.save(),e.globalAlpha=.7,ze(e,t,u.limitLine,m,r,w,r),e.restore(),e.save(),e.fillStyle=u.limitLine,e.textAlign="left",e.fillText(t.label,m+3+ke[d]*we,r-6),e.restore()}),v!==null&&v>=b&&v<=k){const t=g(v);e.save(),e.strokeStyle=u.text,e.globalAlpha=.5,e.setLineDash([3,3]),e.beginPath(),e.moveTo(m,t),e.lineTo(w,t),e.stroke(),e.restore()}e.strokeStyle=X,e.lineWidth=1.5,e.beginPath();let U=!1;s.forEach((t,r)=>{if(!t.count||!Number.isFinite(t.mean)){U=!1;return}const d=z(r),ae=g(t.mean);U?e.lineTo(d,ae):e.moveTo(d,ae),U=!0}),e.stroke(),s.forEach((t,r)=>{if(!t.count||!Number.isFinite(t.mean))return;const d=z(r);t.stddev>0&&(e.save(),e.strokeStyle=X,e.globalAlpha=.55,e.lineWidth=1,e.beginPath(),e.moveTo(d,g(t.mean-t.stddev)),e.lineTo(d,g(t.mean+t.stddev)),e.stroke(),e.restore()),e.fillStyle=X,e.beginPath(),e.arc(d,g(t.mean),he,0,Math.PI*2),e.fill(),C.has(r)&&(e.beginPath(),e.arc(d,g(t.mean),he+3,0,Math.PI*2),e.strokeStyle=u.text,e.lineWidth=1.5,e.stroke())}),e.fillStyle=u.text,e.textBaseline="top",e.textAlign="center";const Le=Math.max(1,Math.ceil(s.length*42/Math.max(1,w-m)));s.forEach((t,r)=>{if(r%Le!==0&&r!==s.length-1)return;const d=t.label.length>8?`${t.label.slice(0,7)}\u2026`:t.label;e.fillText(d,z(r),L+6)})},ee=i=>{if(!T||T.step<=0)return-1;const n=x.getBoundingClientRect(),o=Math.round((i.clientX-n.left-T.left)/T.step);return o>=0&&o<s.length&&s[o].count>0?o:-1};Ne({card:c,canvas:x,tooltip:B,drawn:()=>[],locate:i=>{const n=ee(i);return n<0?null:n},describe:i=>{const n=s[i];return`<strong>${Q(n.label)}</strong><br>`+Q(`mean ${H(n.mean,p?.unit)} \xB7 \u03C3 ${H(n.stddev,p?.unit)}`)+`<br>n = ${n.count.toLocaleString()}`+(v!==null?"<br>"+Q(`\u0394 vs ${Y} ${n.mean-v>=0?"+":""}${H(n.mean-v,p?.unit)}`):"")+(M&&n.key!==void 0?"<br><em>click to open this wafer</em>":"")+(a.onSelectWafers?"<br><em>drag across the plot to select wafers</em>":"")+(a.onWaferContextMenu&&n.key!==void 0?Xe:"")},clickable:i=>!!M&&s[i].key!==void 0,onOpen:i=>{const n=s[i];n.key!==void 0&&f!==null&&M(n.key,f)},onHover:()=>{},select:a.onSelectWafers?{pick:({x0:i,x1:n})=>{if(!T)return[];const o=T;return s.map((e,u)=>u).filter(e=>s[e].count>0&&o.left+e*o.step>=i&&o.left+e*o.step<=n)},onPicked:(i,n)=>{C.clear();for(const e of i)C.add(e);E();const o=i.map(e=>s[e].key).filter(e=>e!==void 0);o.length>0&&f!==null&&a.onSelectWafers({keys:o,testNumber:f},n,x)},onClear:()=>{C.clear(),E()},hasSelection:()=>C.size>0}:void 0}),x.addEventListener("contextmenu",i=>{const n=ee(i),o=n<0?void 0:s[n].key;o===void 0||!a.onWaferContextMenu||(B.style.display="none",a.onWaferContextMenu(o,f??void 0,i))}),E(),I=We(h,E)}return S(),{card:c,destroy:()=>{I?.disconnect(),B.remove(),c.remove()},setTest:l=>{J.set(l)&&(f=l,S())},setAxisPrefs:l=>{_.set(l)&&S()}}}
@@ -0,0 +1,13 @@
1
+ export interface ConfirmOptions {
2
+ doc: Document;
3
+ /** An element from the live DOM the dialog belongs to, so it lands inside a host's own `<dialog>` (see `OverlayOptions.anchor`). */
4
+ anchor: Element;
5
+ title: string;
6
+ /** What will happen, in a sentence or two. Plain text. */
7
+ message: string;
8
+ /** The destructive button's label, naming the action ("Delete 4 plots"), not "OK". */
9
+ confirmLabel: string;
10
+ cancelLabel?: string;
11
+ }
12
+ export declare function confirmDialog(o: ConfirmOptions): Promise<boolean>;
13
+ //# sourceMappingURL=confirmDialog.d.ts.map
@@ -0,0 +1 @@
1
+ import{openModal as u,controlStyle as y,wireControlHover as C,CLR as w,FONT as m,SPACE as i}from"./toolbar.js";export function confirmDialog(t){const{doc:o}=t;return new Promise(p=>{let s=!1,l;const n=u({title:t.title,anchor:t.anchor,ownerDocument:o,boxSize:{width:"min(90vw, 460px)",height:"auto"},maximizable:!1,initialFocus:()=>l,onClose:()=>p(s)});n.box.dataset.wmapConfirm="1",n.box.style.minHeight="0";const c=o.createElement("div");Object.assign(c.style,{display:"flex",flexDirection:"column",gap:i.lg,padding:i.xl,color:w.text,fontSize:m.body});const a=o.createElement("p");a.textContent=t.message,a.id=`wmap-confirm-${Math.random().toString(36).slice(2,8)}`,a.style.margin="0",n.box.setAttribute("aria-describedby",a.id);const r=o.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",gap:i.md,flexWrap:"wrap"});const d=(f,g,x)=>{const e=o.createElement("button");return e.type="button",e.textContent=f,e.dataset[g]="1",Object.assign(e.style,{...y("outlined"),fontSize:m.body,padding:`${i.sm} ${i.lg}`}),C(e),e.addEventListener("click",x),e};l=d(t.cancelLabel??"Cancel","wmapConfirmCancel",()=>n.close());const b=d(t.confirmLabel,"wmapConfirmOk",()=>{s=!0,n.close()});r.append(l,b),c.append(a,r),n.contentWrap.appendChild(c)})}