@wafertools/wafermap 0.35.1 → 0.37.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 (188) hide show
  1. package/AGENTS.md +13 -10
  2. package/CHANGELOG.md +474 -0
  3. package/README.md +7 -7
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  8. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  9. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  10. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  12. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  13. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  14. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  15. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  16. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  17. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  18. package/dist/packages/canvas-adapter/charts/patCard.d.ts +21 -0
  19. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  20. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  21. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  23. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  24. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  25. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  26. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  27. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  28. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  29. package/dist/packages/canvas-adapter/dieList.js +2 -2
  30. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  31. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  32. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  34. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  35. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  36. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  37. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  38. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  39. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  40. package/dist/packages/canvas-adapter/icons.js +1 -1
  41. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  42. package/dist/packages/canvas-adapter/index.js +1 -1
  43. package/dist/packages/canvas-adapter/insightsTab.d.ts +57 -2
  44. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  45. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  46. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  47. package/dist/packages/canvas-adapter/patMaps.d.ts +26 -0
  48. package/dist/packages/canvas-adapter/patMaps.js +1 -0
  49. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  50. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  51. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  52. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  53. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  54. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  55. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  56. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  57. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  58. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  59. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
  60. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  61. package/dist/packages/canvas-adapter/summaryPanel.d.ts +22 -9
  62. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  63. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  64. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  65. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  66. package/dist/packages/canvas-adapter/toolbar.d.ts +12 -6
  67. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  68. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  69. package/dist/packages/canvas-adapter/userGuideHtml.js +607 -117
  70. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  71. package/dist/packages/canvas-adapter/version.js +1 -1
  72. package/dist/packages/canvas-adapter/warnings.js +1 -1
  73. package/dist/packages/core/aggregates.d.ts +10 -0
  74. package/dist/packages/core/aggregates.js +1 -1
  75. package/dist/packages/core/classify.d.ts +11 -0
  76. package/dist/packages/core/classify.js +1 -1
  77. package/dist/packages/core/dieTable.d.ts +5 -0
  78. package/dist/packages/core/dieTable.js +1 -1
  79. package/dist/packages/core/dies.d.ts +2 -0
  80. package/dist/packages/core/dies.js +1 -1
  81. package/dist/packages/core/wafer.d.ts +10 -1
  82. package/dist/packages/core/wafer.js +1 -1
  83. package/dist/packages/renderer/buildView.d.ts +5 -0
  84. package/dist/packages/renderer/buildView.js +1 -1
  85. package/dist/packages/renderer/buildWaferMap.d.ts +21 -4
  86. package/dist/packages/renderer/buildWaferMap.js +1 -1
  87. package/dist/packages/renderer/deprecate.d.ts +2 -8
  88. package/dist/packages/renderer/deprecate.js +1 -1
  89. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  90. package/dist/packages/renderer/fmt.d.ts +10 -0
  91. package/dist/packages/renderer/fmt.js +1 -1
  92. package/dist/packages/renderer/index.d.ts +1 -0
  93. package/dist/packages/renderer/index.js +1 -1
  94. package/dist/packages/renderer/testLabel.d.ts +0 -11
  95. package/dist/packages/renderer/testLabel.js +1 -1
  96. package/dist/packages/renderer/valueFilter.d.ts +1 -1
  97. package/dist/packages/renderer/valueFilter.js +1 -1
  98. package/dist/packages/stats/analyzeWaferLot.d.ts +22 -0
  99. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  100. package/dist/packages/stats/analyzeWaferMap.d.ts +26 -1
  101. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  102. package/dist/packages/stats/binPareto.d.ts +2 -54
  103. package/dist/packages/stats/binPareto.js +1 -1
  104. package/dist/packages/stats/binRows.js +1 -1
  105. package/dist/packages/stats/capability.d.ts +10 -0
  106. package/dist/packages/stats/capability.js +1 -1
  107. package/dist/packages/stats/cardSpec.d.ts +53 -0
  108. package/dist/packages/stats/cardSpec.js +1 -0
  109. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  110. package/dist/packages/stats/chartCatalogue.js +1 -0
  111. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  112. package/dist/packages/stats/clusterDetection.js +1 -1
  113. package/dist/packages/stats/commonality.d.ts +62 -0
  114. package/dist/packages/stats/commonality.js +1 -0
  115. package/dist/packages/stats/connectedComponents.js +1 -1
  116. package/dist/packages/stats/control.d.ts +21 -0
  117. package/dist/packages/stats/control.js +1 -0
  118. package/dist/packages/stats/correlation.d.ts +42 -4
  119. package/dist/packages/stats/correlation.js +1 -1
  120. package/dist/packages/stats/dieRegions.d.ts +4 -1
  121. package/dist/packages/stats/dieRegions.js +1 -1
  122. package/dist/packages/stats/differenceMap.d.ts +22 -0
  123. package/dist/packages/stats/differenceMap.js +1 -0
  124. package/dist/packages/stats/examplePicks.d.ts +22 -0
  125. package/dist/packages/stats/examplePicks.js +1 -0
  126. package/dist/packages/stats/filterFile.d.ts +41 -0
  127. package/dist/packages/stats/filterFile.js +2 -0
  128. package/dist/packages/stats/filterFindings.d.ts +21 -6
  129. package/dist/packages/stats/filterFindings.js +1 -1
  130. package/dist/packages/stats/findingText.d.ts +8 -0
  131. package/dist/packages/stats/findingText.js +2 -2
  132. package/dist/packages/stats/groupCompare.d.ts +87 -0
  133. package/dist/packages/stats/groupCompare.js +1 -0
  134. package/dist/packages/stats/guideSections.d.ts +55 -0
  135. package/dist/packages/stats/guideSections.js +1 -0
  136. package/dist/packages/stats/index.d.ts +5 -2
  137. package/dist/packages/stats/index.js +1 -1
  138. package/dist/packages/stats/lotDrift.js +1 -1
  139. package/dist/packages/stats/math.d.ts +29 -4
  140. package/dist/packages/stats/math.js +1 -1
  141. package/dist/packages/stats/mergeTestDefs.js +1 -1
  142. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  143. package/dist/packages/stats/metadataColumns.js +1 -1
  144. package/dist/packages/stats/pat.d.ts +58 -0
  145. package/dist/packages/stats/pat.js +1 -0
  146. package/dist/packages/stats/patSummary.d.ts +45 -0
  147. package/dist/packages/stats/patSummary.js +1 -0
  148. package/dist/packages/stats/patternClassification.d.ts +3 -3
  149. package/dist/packages/stats/patternClassification.js +1 -1
  150. package/dist/packages/stats/plotData.d.ts +294 -17
  151. package/dist/packages/stats/plotData.js +1 -1
  152. package/dist/packages/stats/plotId.d.ts +2 -0
  153. package/dist/packages/stats/plotId.js +1 -1
  154. package/dist/packages/stats/plotReferences.d.ts +17 -0
  155. package/dist/packages/stats/plotReferences.js +1 -0
  156. package/dist/packages/stats/plotSpec.d.ts +239 -3
  157. package/dist/packages/stats/plotSpec.js +4 -4
  158. package/dist/packages/stats/regions.js +1 -1
  159. package/dist/packages/stats/renderSummaryReport.js +33 -33
  160. package/dist/packages/stats/reportHtml.d.ts +5 -12
  161. package/dist/packages/stats/reportHtml.js +98 -40
  162. package/dist/packages/stats/synthesis.d.ts +48 -16
  163. package/dist/packages/stats/synthesis.js +1 -1
  164. package/dist/packages/stats/testPassRate.d.ts +7 -0
  165. package/dist/packages/stats/testPassRate.js +1 -1
  166. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  167. package/dist/packages/stats/testValueBudget.js +1 -0
  168. package/dist/packages/stats/types.d.ts +90 -30
  169. package/dist/packages/stats/yield.d.ts +3 -11
  170. package/dist/packages/stats/yield.js +1 -1
  171. package/llms.txt +1 -1
  172. package/package.json +2 -1
  173. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  174. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  175. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  176. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  177. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  178. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  179. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  180. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  181. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  182. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  183. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  184. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  185. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  186. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  187. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  188. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as qe}from"../stats/presentation.js";import{buildFacetTable as Ke,facetValueOf as Qe,FACET_NONE_VALUE as Xe,DEFAULT_FACET_CURATION as Je}from"../stats/facets.js";import{mergeTestDefs as Se}from"../stats/mergeTestDefs.js";import{isParametricTest as xe}from"../renderer/buildWaferMap.js";import{dieFailsTest as Ze}from"../stats/testPassRate.js";import{fmt as ke}from"../renderer/fmt.js";import{testLabel as et}from"../renderer/testLabel.js";import{waferDisplayLabel as tt,waferIdentityLabel as nt}from"../core/waferLabel.js";import{waferPopulation as ot}from"./chartPopulation.js";import{openDrilldownMenu as se}from"./drilldown.js";import{plotStoreFor as it}from"./plotStore.js";import{itemPassBins as rt,passBinsLabel as Te}from"../core/passBins.js";import{NO_DATA_FILL as ve}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as st}from"../stats/population.js";import{LEADING as lt,ALPHA as dt,SPACE as T,EDGE_GUTTER as le,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as de,wireTooltip as ft}from"./toolbar.js";import{ICONS as mt}from"./icons.js";import{renderCapabilityPanel as bt}from"./charts/capability.js";import{renderBoxplotPanel as ht}from"./charts/boxplot.js";import{renderTrendPanel as gt}from"./charts/trend.js";import{renderHistogramPanel as yt}from"./charts/histogram.js";import{renderCorrelationPanel as wt}from"./charts/correlation.js";import{renderScatterPanel as Ct}from"./charts/scatter.js";import{renderBarPanel as De}from"./charts/barPanel.js";import{renderBinClusterPanel as St}from"./charts/binCluster.js";import{renderTestPassRatePanel as xt}from"./charts/testPassRate.js";import{QUANTITY as kt}from"./charts/palette.js";import{cardFrameStyle as Tt,makeChartGridWrap as ce,makeLabeledSelect as vt,makeLinkedGroupSelect as Dt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as Be}from"../stats/yield.js";import{buildBinParetoData as Bt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as $t,buildLotFunctionalSection as Lt,buildMetadataStripBox as It}from"./summaryPanel.js";import{runChunked as Et}from"./chunked.js";import{buildRegionYieldData as ue,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as Pt,diesInRegion as At}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as pe}from"./charts/regionYieldDiagram.js";const Wt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Mt={key:"data",label:"Data"},Ft={key:"plot",label:"Plot"};export function createInsightsTab(v){const{getItems:Ie,getLotStats:fe,getBinColors:me,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,be={...Je,...v.attributes},Ee=v.showMetadataStrip??!0,z=v.contentInset??le,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Pe=le,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Pe});const E=f.createElement("div");Object.assign(E.style,{display:"flex",gap:T.xs,alignItems:"center",background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:ct.container,boxShadow:ut.panel,padding:`0 ${T.lg}`,marginBottom:T.lg,marginLeft:z,marginRight:z}),E.setAttribute("role","tablist"),E.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(E.querySelectorAll('[role="tab"]')),r=n.indexOf(f.activeElement);if(r===-1)return;e.preventDefault();const l=n[(r+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];l.focus(),l.click()});const U=f.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:T.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),Y.appendChild(j),Y.appendChild(E),Y.appendChild(U);const Ae=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,he="statistics",ge="wide",P=null,A=null,K={includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,ye=(e,n)=>{K=e;for(const r of ee.values())for(const l of r)l!==n&&l.setAxisPrefs(e)},te=e=>{A!==e&&(A=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function ne(e,n,r){R?.(e,n,r)}function oe(e){return(n,r,l)=>{const i=e.find(c=>c.waferIndex===n);if(!i)return;l.preventDefault();const u=ot(i.dies,{waferLabel:i.identity,testDefs:i.testDefs,activeTest:r??P??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});se({x:l.clientX,y:l.clientY},l.target,u,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}}function Q(e,n,r,l,i){Ce({x:e.clientX,y:e.clientY},e.target,n,r,l,i)}function Ce(e,n,r,l,i,u){const c=Rt(r.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:N()})),l,i,Se(r).defs,u);c&&se(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function ie(e){return R?{open:(n,r)=>ne(n,`Wafer ${e.find(l=>l.waferIndex===n)?.label??n}`,r)}:Z&&e.length===1?{open:(n,r)=>Z(r),label:"show this test on the map"}:null}function Oe(){return Ie().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:tt(e,n),identity:nt(e),waferIndex:n,passBins:rt(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Re(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${$.iconActive}`:"2px solid transparent",color:n?$.iconActive:$.label,fontWeight:n?"700":"500",fontSize:F.body,padding:`${T.sm} ${le} ${T.md}`,cursor:"pointer",marginBottom:"-1px"})}function We(e,n){const r=f.createElement("button");r.type="button",r.textContent=n;const l=e===L;return Re(r,l),r.dataset.on=l?"true":"false",de(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",l?"true":"false"),r.tabIndex=l?0:-1,r.addEventListener("click",()=>{L!==e&&(L=e,H({keepSections:!0}))}),r}function Me(e,n,r,l=!0){const i=ce(f),u=me();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=fe?.(),m=new Map(d?.lotYieldSeries.map(p=>[p.waferIndex,p.yieldPercent])),a=p=>({...p,label:p.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(p.waferIndex),key:p.waferIndex}),b=e.map(a),y=n?.map(p=>({key:p.key,items:p.items.map(a)})),w=()=>y?Be(y,c):J(b,c),t={title:n?`Yield by ${s} (pass: ${h})`:`Yield by wafer (pass: ${h})`,data:w(),selfControl:{current:c,options:[["yield","Sort: yield"],["label",n?`Sort: ${s}`:"Sort: wafer ID"]],onChange:p=>(c=p,{data:w()})},barColor:()=>kt,valueLabel:p=>`${p.percent.toFixed(1)}%`,reference:p=>{if(p.length<3)return null;const S=p.map(I=>I.percent).sort((I,_)=>I-_),B=S.length%2?S[(S.length-1)/2]:(S[S.length/2-1]+S[S.length/2])/2;return{value:B,label:`median ${B.toFixed(1)}%`}},drill:y?{onOpenGroup:p=>{const S=y.find(B=>B.key===p.label)?.items??[];return{data:J(S,c),title:`Yield by wafer \u2014 ${s}: ${p.label} (pass: ${h})`}},onBack:()=>({data:w(),title:`Yield by ${s} (pass: ${h})`}),groupLabelText:s}:void 0,onOpen:R?p=>{typeof p.key=="number"&&ne(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:oe(e),ownerDocument:f};let o=null;if(l&&(o=De(t,k),o.card.style.minHeight="360px",i.appendChild(o.card)),n){const p=St({title:"Hard bin pareto",groups:n.map(S=>({key:S.key,items:S.items.map(B=>({dies:B.dies,hardBinCounts:B.statsSummary?.stats.hardBinCounts,softBinCounts:B.statsSummary?.stats.softBinCounts}))})),onSelectBin:(S,B)=>{const I=n.find(X=>X.key===S.groupKey);if(!I)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,I.items,`in ${_} bin ${S.bin} of ${S.groupKey}`,X=>(S.binType==="hbin"?X.hbin:X.sbin)===S.bin)},onSaveImage:k,ownerDocument:f});return p.card.style.minHeight="360px",i.appendChild(p.card),{card:i,destroy:()=>{o?.destroy(),p.destroy()}}}let g="hbin";const C=p=>p===void 0?ve:(g==="hbin"?u.hard:u.soft).get(p)??ve,x=e.map(p=>({dies:p.dies,hardBinCounts:p.statsSummary?.stats.hardBinCounts,softBinCounts:p.statsSummary?.stats.softBinCounts})),W=()=>Bt(x,g),ae={title:"Hard bin pareto",data:W(),selfControl:{current:g,options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],onChange:p=>(g=p,{data:W(),title:`${g==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:p=>C(p.binCode),onSelectBar:(p,S)=>{const B=g==="hbin"?"hard":"soft",I=p.binCode;Q(S,e,I===void 0?`with no ${B} bin recorded`:`in ${B} bin ${I}`,_=>(g==="hbin"?_.hbin:_.sbin)===I)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(ae,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function re(){const e=f.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Tt(),display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"}),e}function Fe(e){if(j.innerHTML="",j.style.marginBottom="0",!Ee)return;const n=It(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",j.appendChild(n),j.style.marginBottom=T.xs)}function Ne(e,n,r,l){if(!e.length)return{elements:[],destroy:()=>{}};const i=e.map(t=>t.wafer),u=e.map(t=>t.dies),c=N(),s=[],h=[],m=xt({groups:(l??[{key:"",items:e}]).map(t=>({key:t.key,items:t.items.map(o=>({dies:o.dies,testSpecYield:o.statsSummary?.stats.testSpecYield,functionalYield:o.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:k,onSelectTest:(t,o)=>{const g=r.find(C=>C.testNumber===t.testNumber);g&&Q(o,e,`failing ${t.label}`,C=>Ze(C,g,t.kind)===!0,xe(g)?t.testNumber:void 0)},ownerDocument:f});m.card.style.minHeight="300px",s.push(m.card),h.push(m.destroy);const a=t=>(o,g)=>{const C=new Set;for(const x of e)for(const W of At(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=ue(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=pe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=ue(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=pe({title:"Quadrant yield",mode:"quadrant",rows:y,onSelectRegion:a(Le),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const w=i.find(t=>t.reticle!==void 0)?.reticle;if(w){const t=(g,C)=>Pt(g,C.reticle),o=ue(u,i,c,g=>e[g].passBins,t);if(o.length){const g=pe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:w.width,height:w.height},onSelectRegion:a(t),onSaveImage:k,ownerDocument:f});s.push(g.card),h.push(g.destroy)}}return{elements:s,destroy:()=>{for(const t of h)t()}}}function Ye(e,n,r){if(!e.length)return{cards:[],destroy:()=>{}};const l=e.map(a=>a.dies),i=e.flatMap(a=>a.dies),u=e.map(a=>a.statsSummary),c=u.every(a=>a!==void 0)?u:void 0,s=[],h=[];let d=null;if(n.length){const a=re();let b=null;const y=Et($t(i,n,void 0,c,O,l.map(w=>({dies:w})),void 0,"full"),{onDone:w=>{b=w,a.removeAttribute("aria-busy"),w?a.replaceChildren(w):a.remove()}});if(y.done)b&&(d=a);else{const w=f.createElement("div");w.textContent="Computing test statistics\u2026",Object.assign(w.style,{color:$.label,fontSize:F.body}),a.setAttribute("aria-busy","true"),a.appendChild(w),d=a,s.push(()=>y.cancel())}}let m=null;if(r.length){const a=Lt(i,r,c,O);if(a){const b=re();b.appendChild(a),m=b}}return d&&h.push(d),m&&h.push(m),{cards:h,destroy:()=>{for(const a of s)a()}}}function je(e){const n=Te(e.map(d=>d.passBins)),r=e.length===1,l=e[0],i=re();Object.assign(i.style,{flexDirection:"row",flexWrap:"wrap",gap:T.md});const u=d=>{const m=d.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function c(d,m,a){const b=f.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:T.sm,paddingRight:T.xxl,marginRight:T.md,borderRight:`1px solid ${$.menuBorder}`});const y=f.createElement("div");y.textContent=d,Object.assign(y.style,{fontSize:F.heading,fontWeight:"700",color:$.value,lineHeight:lt.tight});const w=f.createElement("div");if(w.textContent=m,Object.assign(w.style,{fontSize:F.body,color:$.label}),b.append(y,w),a){const t=f.createElement("div");t.textContent=a,Object.assign(t.style,{fontSize:F.meta,color:$.label,opacity:dt.muted}),b.appendChild(t)}return b}if(r){const d=J([{...l,key:l.waferIndex}])[0]?.percent;return d!==void 0&&i.appendChild(c(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),i.appendChild(c(String(l.dies.length),"Total dies")),u(i)}i.appendChild(c(String(e.length),"Wafers"));const s=J(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(s.length){const d=s.reduce((b,y)=>b+y,0)/s.length,m=Be([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,a=m!==void 0&&m.toFixed(1)!==d.toFixed(1);i.appendChild(c(`${d.toFixed(1)}%`,`${qe} \xB7 pass: ${n}`,a?`${m.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((a,b)=>a+b.stats.analyzedDies,0),m=h.reduce((a,b)=>a+b.stats.excludedDies,0);i.appendChild(c(d.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else i.appendChild(c(e.reduce((d,m)=>d+m.dies.length,0).toLocaleString(),"Total dies"));return u(i)}function Ge(e,n,r,l,i){const u=f.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:T.lg});const c=e.length===1&&!l;e.length&&!l&&u.appendChild(je(e));const s=Me(e,l,i,!c);u.appendChild(s.card);const h=Ne(e,n,r,l);for(const d of h.elements)s.card.appendChild(d);return u.appendChild(He()),{card:u,destroy:()=>{s.destroy(),h.destroy()}}}function He(){const e=f.createElement("div");Object.assign(e.style,{fontSize:F.body,color:$.label});const n=f.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:$.iconActive,textDecoration:"underline"}),de(n,"bare"),n.addEventListener("click",()=>{L="data",H({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function _e(e,n,r,l){const i=f.createElement("div");i.style.width="100%";let u,c=!1;return import("./plotTab.js").then(({createPlotSection:s})=>{if(c)return;const h=s({doc:f,store:q,items:e,testDefs:n,ringCount:N(),attributes:v.attributes,groupBy:r,groupLabel:l,onSaveImage:k,onSaveText:O,openWafer:R?(d,m,a)=>R(d,m,a):void 0,focusTest:Z,locateDie:V,pickPlotsFile:v.onPickPlotsFile});i.appendChild(h.card),u=h}),{card:i,destroy:()=>{c=!0,u?.destroy()}}}function Ve(e,n,r,l,i){const u=fe?.(),c=()=>{G.get("data")?.destroy(),G.delete("data"),H({keepSections:!0})};return Ot({doc:f,items:e,testDefs:n,allTestDefs:r,groups:l,groupLabelText:i,ringCount:N(),attributes:v.attributes,yieldByWaferIndex:new Map(u?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),onSaveText:O,onLocateDie:V,onOpenWafer:R?(s,h)=>R(s,h):void 0,buildStatistics:s=>Ye(s,n,r),view:he,onViewChange:s=>{he=s,c()},diesLayout:ge,onDiesLayoutChange:s=>{ge=s}})}function ze(e,n,r,l){const i=ce(f),u=ie(e),c=t=>o=>ye(o,t()),s=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),h=e.map(s),d=r?.map(t=>({key:t.key,items:t.items.map(s)})),m=ht({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:c(()=>m),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>te(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:oe(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>te(t),onSaveImage:k,onSelectBucket:(t,o)=>{const g=n.find(D=>D.testNumber===t.testNumber),C=new Set(t.items.map(D=>D.item)),x=new Set(t.items.flatMap(D=>D.dies)),W=ke(t.low,g?.unit,"engineering"),ae=ke(t.high,g?.unit,"engineering");Q(o,e.filter(D=>C.has(D)),`with ${g?et(g,g.testNumber):`test ${t.testNumber}`} from ${W} to ${ae}${t.group?` in ${t.group}`:""}`,D=>x.has(D),t.testNumber)},ownerDocument:f}),b=gt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:c(()=>b),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:st(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>ne(t,`Wafer ${e.find(g=>g.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,g)=>{const C=new Set(t.keys);Ce(o,g,e.filter(x=>C.has(x.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:oe(e),ownerDocument:f}),y=t=>{P=t,m.setTest(t),a.setTest(t),b.setTest(t),w.setTest(t)};ee.set("distribution",[m,a,b]);const w=bt({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:P??void 0,onSelectTest:t=>y(t),ownerDocument:f});return i.append(w.card,m.card,a.card,b.card),{card:i,destroy:()=>{w.destroy(),m.destroy(),a.destroy(),b.destroy()}}}function Ue(e,n,r){const l=ce(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:me().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>ye(c,i),onOpen:ie(e)?.open,openActionLabel:ie(e)?.label,onSelect:(c,s,h,d)=>{const m=new Map;for(const y of c){if(y.waferIndex===void 0||!y.die)continue;const w=m.get(y.waferIndex);w?w.push(y.die):m.set(y.waferIndex,[y.die])}const a=[...m].flatMap(([y,w])=>{const t=e.find(o=>o.waferIndex===y);return t?[{label:t.identity??t.label,dies:w,waferIndex:y,wafer:t.wafer,passBins:t.passBins,ringCount:N()}]:[]});if(a.length===0)return;const b=a.length===1?`selected on ${a[0].label} in the scatter`:`selected in the scatter, across ${a.length} wafers`;se(s,h,{items:a,population:b,testDefs:n,activeTest:d},{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})},ownerDocument:f});ee.set("correlation",[i]);const u=wt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:O,onSelectPair:(c,s)=>i.setXY(c,s),ownerDocument:f});return l.append(u.card,i.card),{card:l,destroy:()=>{u.destroy(),i.destroy()}}}function H(e){e?.keepSections||we(),U.innerHTML="",E.innerHTML="";for(const o of Ae)E.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:be}).filter(o=>o.splittable),l=f.createElement("div");Object.assign(l.style,{display:"flex",gap:T.md,alignItems:"center",marginLeft:T.xxl,paddingBottom:T.xs});let i;r.length>0?(l.appendChild(vt("Group by:",[{value:"",label:"None"},...r.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],M??"",o=>{M=o||void 0,A=null,H()},{hook:"group-by",ownerDocument:f})),i=r.find(o=>o.key===M)?.label):M=void 0;let u;if(M){const o=new Map,g=[];for(const C of n){const x=Qe(C.metadata,M,be)??Xe;o.has(x)||(o.set(x,[]),g.push(x)),o.get(x).push(C)}u=g.map(C=>({key:C,items:o.get(C)}))}A!==null&&!u?.some(o=>o.key===A)&&(A=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",A,o=>te(o),{ownerDocument:f}).el);let c=null;if(v.onOpenGuide){const o=f.createElement("button");o.type="button",o.innerHTML=mt.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...pt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),de(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}E.appendChild(l),c&&E.appendChild(c);const s=A!==null?u?.find(o=>o.key===A):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);P!==null&&!b.some(o=>o.testNumber===P)&&(P=null);const y=e?.keepSections?G.get(L):void 0,w=y??(L==="overview"?Ge(h,b,a,d,i):L==="distributions"?ze(h,b,d,i):L==="data"?Ve(h,b,a,d,i):L==="plot"?_e(h,a,s?void 0:M,s?void 0:i):Ue(h,b,d));y||G.set(L,w);const t=m.conflicts.filter(o=>o.excluded);if(t.length>0){const o=f.createElement("div");Object.assign(o.style,{color:$.label,fontSize:F.body,padding:`0 ${z} ${T.sm}`});const g=t.slice(0,6).map(W=>W.testNumber).join(", "),C=t.length>6?`, and ${t.length-6} more`:"",x=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${g}${C}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${i??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(w.card)}return{el:Y,render:H,destroy:()=>{we(),q.flush(),Y.remove()}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as Lt}from"../stats/presentation.js";import{buildFacetTable as Et,facetValueOf as Be,FACET_NONE_VALUE as Tt,DEFAULT_FACET_CURATION as $t}from"../stats/facets.js";import{mergeTestDefs as ke}from"../stats/mergeTestDefs.js";import{isParametricTest as Le}from"../renderer/buildWaferMap.js";import{dieFailsTest as It,hasJudgeableTests as Dt,testsForPassKind as Ot,buildTestPassRateData as At}from"../stats/testPassRate.js";import{fmt as Ve}from"../renderer/fmt.js";import{testLabel as Ye}from"../renderer/testLabel.js";import{waferDisplayLabel as Wt,waferIdentityLabel as Pt}from"../core/waferLabel.js";import{waferPopulation as Rt}from"./chartPopulation.js";import{openDrilldownMenu as Ee}from"./drilldown.js";import{plotStoreFor as Ft}from"./plotStore.js";import{createPageFilter as Mt}from"./pageFilter.js";import{bandButton as Nt}from"./filterButton.js";import{itemPassBins as jt,passBinsLabel as Ge}from"../core/passBins.js";import{describeWaferPopulation as zt,populationStat as Ht}from"../stats/population.js";import{LEADING as Te,ALPHA as Vt,SPACE as O,EDGE_GUTTER as $e,FONT as N,CLR as W,RADIUS as Yt,SHADOW as Gt,controlStyle as _e,wireControlHover as fe,wireTooltip as Ie}from"./toolbar.js";import{ICONS as _t}from"./icons.js";import{renderCapabilityPanel as qt}from"./charts/capability.js";import{renderGroupComparisonPanel as Kt}from"./charts/groupComparison.js";import{renderCommonalityPanel as Ut}from"./charts/commonality.js";import{renderPatCard as Xt}from"./charts/patCard.js";import{renderDifferenceMapPanel as Jt}from"./differenceMapPanel.js";import{renderCorrelationPanel as Qt}from"./charts/correlation.js";import{cardFrameStyle as Zt,makeChartGridWrap as pe,makeLabeledSelect as en,makeLinkedGroupSelect as tn,makeLinkedTestSelect as nn,makeWaferSelect as qe,makeTestSelect as Ke,makeLimitsSelect as sn,makeLinkedAxisPrefs as an,makeToggle as on,limitLines as Ue,limitExtent as rn,shouldIncludeLimitsByDefault as ln,hasBothLimitKinds as Xe}from"./charts/chartShell.js";import{maxOf as dn,minOf as cn}from"../core/utils.js";import{buildYieldData as Je,buildYieldDataCombined as un}from"../stats/yield.js";import{buildLotTestSectionSteps as fn,buildLotFunctionalSection as pn,buildMetadataStripBox as mn}from"./summaryPanel.js";import{runChunked as hn}from"./chunked.js";import{buildRegionYieldData as De,buildRingRegions as Qe,buildQuadrantRegions as Ze,buildReticlePositionRegions as bn,diesInRegion as gn}from"../stats/regions.js";import{renderDataSection as yn}from"./dataTab.js";import{sourceFromDies as wn,toPlotItems as le}from"./plotItems.js";import{isYieldEligibleDie as xn}from"../core/dies.js";import{renderPlotCard as se}from"./plotCard.js";import{orderFieldValues as Cn,axisValues as Sn}from"../stats/plotData.js";import{buildSynthesis as vn,synthesisKey as Bn}from"../stats/synthesis.js";import{commonPassBins as kn}from"../core/passBins.js";import{renderRegionYieldDiagram as Oe}from"./charts/regionYieldDiagram.js";const Ln=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],En={key:"data",label:"Data"},Tn={key:"plot",label:"My plots"};export function createInsightsTab(B){const{getItems:et,getLotStats:Ae,getBinColors:U,getRingCount:V,onSaveImage:P,onSaveText:Y,openWafer:X,focusTest:me,locateDie:ae}=B,de={...$t,...B.attributes},tt=B.showMetadataStrip??!0,J=B.contentInset??$e,c=B.ownerDocument??document,G=c.createElement("div");Object.assign(G.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const nt=$e,Z=c.createElement("div");Object.assign(Z.style,{paddingLeft:nt});const _=c.createElement("div");Object.assign(_.style,{display:"flex",gap:O.xs,alignItems:"center",background:W.menuBg,border:`1px solid ${W.menuBorder}`,borderRadius:Yt.container,boxShadow:Gt.panel,padding:`0 ${O.lg}`,marginBottom:O.lg,marginLeft:J,marginRight:J}),_.setAttribute("role","tablist"),_.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from(_.querySelectorAll('[role="tab"]')),n=t.indexOf(c.activeElement);if(n===-1)return;e.preventDefault();const d=t[(n+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];d.focus(),d.click()});const Q=c.createElement("div");Object.assign(Q.style,{display:"flex",flexDirection:"column",gap:O.lg,marginTop:"0",paddingLeft:J,paddingRight:J});const ce=B.pageFilter??Mt({doc:c,initial:B.filter,onChange:B.onFilterChange,attributes:B.attributes,getRingCount:B.getRingCount}),We=ce.createBand(()=>xe(),{marginLeft:J,marginRight:J,marginBottom:O.lg}),st=We.el;G.appendChild(Z),G.appendChild(_),G.appendChild(st),G.appendChild(Q);const at=[...Ln,En,Tn],ee=B.plotStore??Ft(B),te=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:n})=>n({doc:c,anchor:G,store:ee,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:P,binColors:U()}}))};let z=B.defaultView==="sweeps"?"plot":B.defaultView??"overview",F,he=!1;ce.subscribe(()=>q());let Pe="statistics",Re="wide",H=null,Fe=null,be=[],R=null,ge=B.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ye=new Map,we=(e,t,n=!1)=>{ge=e;for(const d of ye.values())for(const u of d)u!==t&&u.setAxisPrefs(e);n||B.onAxisPrefsChange?.(e)},ie=e=>{R!==e&&(R=e,q())};let ne=new Map;function Me(){for(const e of ne.values())e.destroy();ne=new Map}function Ne(e,t,n){X?.(e,t,n)}function ue(e){return(t,n,d)=>{const u=e.find(f=>f.waferIndex===t);if(!u)return;d.preventDefault();const h=Rt(u.dies,{waferLabel:u.identity,testDefs:u.testDefs,activeTest:n??H??void 0,waferIndex:t,wafer:u.wafer,passBins:u.passBins,ringCount:V()});Ee({x:d.clientX,y:d.clientY},d.target,h,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}}function it(e,t,n,d,u){oe({x:e.clientX,y:e.clientY},e.target,t,n,d,u)}function oe(e,t,n,d,u,h){const f=wn(n.map(r=>({label:r.identity??r.label,dies:r.dies,waferIndex:r.waferIndex,wafer:r.wafer,passBins:r.passBins,ringCount:V()})),d,u,ke(n).defs,h);f&&Ee(e,t,f,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}function je(e){return X?{open:(t,n)=>Ne(t,`Wafer ${e.find(d=>d.waferIndex===t)?.label??t}`,n)}:me&&e.length===1?{open:(t,n)=>me(n),label:"show this test on the map"}:null}function xe(){return et().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Wt(e,t),identity:Pt(e),waferIndex:t,passBins:jt(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function ot(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${W.iconActive}`:"2px solid transparent",color:t?W.iconActive:W.label,fontWeight:t?"700":"500",fontSize:N.body,padding:`${O.sm} ${$e} ${O.md}`,cursor:"pointer",marginBottom:"-1px"})}function rt(e,t){const n=c.createElement("button");n.type="button",n.textContent=t;const d=e===z;return ot(n,d),n.dataset.on=d?"true":"false",fe(n,"bare"),n.dataset.wmapInsightsTab=e,n.setAttribute("role","tab"),n.setAttribute("aria-selected",d?"true":"false"),n.tabIndex=d?0:-1,n.addEventListener("click",()=>{z!==e&&(z=e,q({keepSections:!0}))}),n}function lt(e,t,n,d=!0){const u=pe(c),h=U(),f=n??"group",r=Ge(e.map(m=>m.passBins)),g=le(e.map(m=>({label:m.identity??m.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:m.dies,waferIndex:m.waferIndex,wafer:m.wafer,passBins:m.passBins,ringCount:V()}))),p=ke(e).defs,o=t?F:void 0,l={testDefs:p,groupBy:o,curation:B.attributes},b=(m,x)=>({id:"card-yield",title:t?`Yield by ${f} (pass: ${r})`:`Yield by wafer (pass: ${r})`,chart:"bar",fields:{x:{slot:"groupBy"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...m?{sort:"value"}:{},...x>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),k=t?t.length:e.length;let C=null;d&&(C=se({doc:c,editAsPlot:te,items:g,ctx:l,spec:{choices:[{current:"natural",options:m=>[["value","Sort: yield"],["natural",t&&!m?`Sort: ${f}`:"Sort: wafer"]]}],build:([m])=>b(m==="value",k)},drill:t&&o?m=>{const x=Be(g[m[0]?.item]?.metadata,o,B.attributes);if(x===void 0)return null;const E=t.find(i=>i.key===x)?.items.length??0;return i=>({...i,title:`Yield by wafer \u2014 ${f}: ${x} (pass: ${r})`,fields:{...i.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:o},values:[x]}]},axes:E>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:"see its wafers",chart:{onSaveImage:P,onOpenWafer:X?m=>Ne(g[m].waferIndex??m,`Wafer ${g[m].label}`):void 0,onWaferMenu:ue(e)}}),C.card.style.minHeight="360px",u.appendChild(C.card));const L={current:"hbin",options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]]},w={current:"share",options:[["count","Counts"],["share",`Share of ${f}`,`Each ${f}\u2019s dies in a bin as a share of all its dies, so ${f} values of different sizes compare`]]},S=(m,x)=>({id:"card-bin-pareto",title:`${m==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:m==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:m==="sbin"?"sbin":"hbin"}},...t?x==="share"?{barNorm:"percent"}:{}:{cumulative:!0}}),a=se({doc:c,editAsPlot:te,items:g,ctx:l,spec:t?{choices:[L,w],build:([m,x])=>S(m,x)}:{choices:[L],build:([m])=>S(m,void 0)},chart:{onSaveImage:P,binColors:h,onSelectPoints:(m,x,E,i)=>{const v=a.current().fields.x,s=v&&!Array.isArray(v)&&"builtin"in v&&v.builtin==="sbin"?"sbin":"hbin",y=new Set(m.map(T=>s==="hbin"?T.die?.hbin:T.die?.sbin));if(y.size!==1)return;const $=[...y][0],A=t?i?.group:void 0,I=A!==void 0?t?.find(T=>T.key===A)?.items??[]:e;oe(x,E,I,`in ${s==="hbin"?"hard":"soft"} bin ${$}${A!==void 0?` of ${A}`:""}`,T=>xn(T)&&(s==="hbin"?T.hbin:T.sbin)===$)}}});return a.card.style.minHeight="360px",u.appendChild(a.card),{card:u,destroy:()=>{C?.destroy(),a.destroy()}}}function Ce(){const e=c.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Zt(),display:"flex",flexDirection:"column",gap:O.lg,minWidth:"0"}),e}function dt(e){if(Z.innerHTML="",Z.style.marginBottom="0",!tt)return;const t=mn(e.map(n=>({metadata:n.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",Z.appendChild(t),Z.style.marginBottom=O.xs)}function ct(e,t,n,d){if(!e.length)return{elements:[],destroy:()=>{}};const u=e.map(w=>w.wafer),h=e.map(w=>w.dies),f=V(),r=[],g=[],p=d??[{key:"",items:e}],o=e.flatMap(w=>w.dies),l=["spec","testFlag","functional"].filter(w=>Dt(n,w,o));if(l.length){const w={spec:{label:"Test limits",hint:"Judged from each die\u2019s measured value against the test\u2019s limits",title:"Parametric pass rate \xB7 test limits"},testFlag:{label:"Tester flag",hint:"The pass or fail the tester recorded for each die",title:"Parametric pass rate \xB7 tester flag"},functional:{label:"Functional",hint:"Tests that only pass or fail and have no measured value",title:"Functional test pass rate"}},S=!!d,a=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:f}))),m=i=>({id:`card-pass-rate-${i}`,title:w[i].title,chart:"bar",orientation:"horizontal",sort:"ascending",fields:{x:{builtin:"test"},y:{tests:Ot(n,i).map(v=>v.testNumber),passRate:!0,...i==="testFlag"?{judge:"flag"}:{}},color:S?{follow:"groupBy"}:{none:!0}},...S?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}}),x=i=>i.id.slice(15),E=se({doc:c,editAsPlot:te,items:a,ctx:{testDefs:n,groupBy:S?F:void 0,curation:B.attributes},spec:l.length>1?{choices:[{current:l[0],options:l.map(i=>[i,w[i].label,w[i].hint])}],build:([i])=>m(i)}:m(l[0]),notes:i=>{const v=x(i);if(v==="functional")return[];const s=At(p.map(y=>({key:y.key,items:y.items.map($=>({dies:$.dies}))})),n,v).disagreementDies;return s?[`${s.toLocaleString("en-GB")} die${s===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:P,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(i,v,s,y)=>{const $=n.find(T=>T.testNumber===y?.test);if(!$)return;const A=x(E.current()),I=y?.group!==void 0?p.find(T=>T.key===y.group)?.items??e:e;oe(v,s,I,`failing ${Ye($,$.testNumber)}${y?.group!==void 0?` in ${y.group}`:""}`,T=>It(T,$,A)===!0,Le($)?$.testNumber:void 0)}}});E.card.style.minHeight="300px",r.push(E.card),g.push(E.destroy)}const b=w=>(S,a)=>{const m=new Set;for(const x of e)for(const E of gn(x.dies,x.wafer,f,S.key,w))m.add(E);it(a,e,`in ${S.label}`,x=>m.has(x))},k=De(h,u,f,w=>e[w].passBins,Qe);if(k.length){const w=Oe({title:"Ring yield",mode:"ring",rows:k,onSelectRegion:b(Qe),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const C=De(h,u,f,w=>e[w].passBins,Ze);if(C.length){const w=Oe({title:"Quadrant yield",mode:"quadrant",rows:C,onSelectRegion:b(Ze),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const L=u.find(w=>w.reticle!==void 0)?.reticle;if(L){const w=(a,m)=>bn(a,m.reticle),S=De(h,u,f,a=>e[a].passBins,w);if(S.length){const a=Oe({title:"Reticle cell yield",mode:"reticleCell",rows:S,grid:{width:Math.max(1,Math.floor(L.width)),height:Math.max(1,Math.floor(L.height))},onSelectRegion:b(w),onSaveImage:P,ownerDocument:c});r.push(a.card),g.push(a.destroy)}}return{elements:r,destroy:()=>{for(const w of g)w()}}}function ut(e,t,n){if(!e.length)return{cards:[],destroy:()=>{}};const d=e.map(l=>l.dies),u=e.flatMap(l=>l.dies),h=e.map(l=>l.statsSummary),f=h.every(l=>l!==void 0)?h:void 0,r=[],g=[];let p=null;if(t.length){const l=Ce();let b=null;const k=hn(fn(u,t,void 0,f,Y,d.map(C=>({dies:C})),void 0,"full"),{onDone:C=>{b=C,l.removeAttribute("aria-busy"),C?l.replaceChildren(C):l.remove()}});if(k.done)b&&(p=l);else{const C=c.createElement("div");C.textContent="Computing test statistics\u2026",Object.assign(C.style,{color:W.label,fontSize:N.body}),l.setAttribute("aria-busy","true"),l.appendChild(C),p=l,r.push(()=>k.cancel())}}let o=null;if(n.length){const l=pn(u,n,f,Y);if(l){const b=Ce();b.appendChild(l),o=b}}return p&&g.push(p),o&&g.push(o),{cards:g,destroy:()=>{for(const l of r)l()}}}function ft(e){const t=Ge(e.map(p=>p.passBins)),n=e.length===1,d=e[0],u=Ce();Object.assign(u.style,{flexDirection:"row",flexWrap:"wrap",gap:O.md});const h=p=>{const o=p.lastElementChild;return o&&Object.assign(o.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),p};function f(p,o,l){const b=c.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:O.sm,paddingRight:O.xxl,marginRight:O.md,borderRight:`1px solid ${W.menuBorder}`});const k=c.createElement("div");k.textContent=p,Object.assign(k.style,{fontSize:N.heading,fontWeight:"700",color:W.value,lineHeight:Te.tight});const C=c.createElement("div");if(C.textContent=o,Object.assign(C.style,{fontSize:N.body,color:W.label}),b.append(k,C),l){const L=c.createElement("div");L.textContent=l,Object.assign(L.style,{fontSize:N.meta,color:W.label,opacity:Vt.muted}),b.appendChild(L)}return b}if(n){const p=Je([{...d,key:d.waferIndex}])[0]?.percent;return p!==void 0&&u.appendChild(f(`${p.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),u.appendChild(f(String(d.dies.length),"Total dies")),h(u)}u.appendChild(f(String(e.length),"Wafers"));const r=Je(e.map(p=>({...p,key:p.waferIndex}))).map(p=>p.percent).filter(p=>Number.isFinite(p));if(r.length){const p=r.reduce((b,k)=>b+k,0)/r.length,o=un([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,l=o!==void 0&&o.toFixed(1)!==p.toFixed(1);u.appendChild(f(`${p.toFixed(1)}%`,`${Lt} \xB7 pass: ${t}`,l?`${o.toFixed(1)}% by dies`:void 0))}const g=e.map(p=>p.statsSummary);if(g.every(p=>p!==void 0)){const p=g.reduce((l,b)=>l+b.stats.analyzedDies,0),o=g.reduce((l,b)=>l+b.stats.excludedDies,0);u.appendChild(f(p.toLocaleString(),"Dies analysed",o?`${o.toLocaleString()} excluded`:void 0))}else u.appendChild(f(e.reduce((p,o)=>p+o.dies.length,0).toLocaleString(),"Total dies"));return h(u)}function pt(e,t,n,d,u){const h=c.createElement("div");Object.assign(h.style,{display:"flex",flexDirection:"column",gap:O.lg});const f=e.length===1&&!d;e.length&&!d&&h.appendChild(ft(e));const r=lt(e,d,u,!f);h.appendChild(r.card);const g=ct(e,t,n,d);for(const l of g.elements)r.card.appendChild(l);const p=mt(e,n);if(p&&h.appendChild(p.el),e.length>=4&&be.length){const l=Ut({wafers:e,fields:be,curation:de,groupedBy:F,onGroupBy:b=>{F=b,R=null,q()},ownerDocument:c});h.appendChild(l.card)}const o=Xt({items:e.map(l=>({...l,ringCount:V()})),testDefs:n,ownerDocument:c});return o&&h.appendChild(o.card),h.appendChild(ht()),{card:h,destroy:()=>{r.destroy(),g.destroy(),p?.destroy()}}}function mt(e,t){const n=Ae?.()??(e.length===1?e[0].statsSummary:void 0);if(!n)return null;const d=c.createElement("section");d.dataset.wmapWorthALook="1",Object.assign(d.style,{display:"flex",flexDirection:"column",gap:O.md});const u=c.createElement("h3");u.textContent="Worth a look",Object.assign(u.style,{margin:"0",fontSize:N.heading,fontWeight:"600",color:W.value}),d.appendChild(u);const h=(o,l)=>{const b=c.createElement("p");b.textContent=o,l&&(b.dataset[l]="1"),Object.assign(b.style,{margin:"0",fontSize:N.body,color:W.label,lineHeight:Te.base}),d.appendChild(b)};if(he||R!==null)return h("Worth a look describes the whole lot, as What stands out beside the map does. Switch the filter off, or Show all groups, to see it here.","wmapWorthNarrowed"),{el:d,destroy:()=>{}};const f=vn(n,{passBins:kn(e.map(o=>o.passBins)),attributes:B.attributes});if(f.items.length===0)return h(f.nothing??"Nothing stands out.","wmapWorthNothing"),{el:d,destroy:()=>{}};const r=pe(c);d.appendChild(r);const g=le(e.map(o=>({label:o.identity??o.label,dies:o.dies,waferIndex:o.waferIndex,wafer:o.wafer,passBins:o.passBins,ringCount:V()}))),p=[];if(f.items.forEach((o,l)=>{const b=c.createElement("div");b.dataset.wmapWorthWhy="1",b.textContent=`Shown because: ${o.reason}`,o.text!==o.reason&&Ie(b,o.text),Object.assign(b.style,{flexBasis:"100%",fontSize:N.body,color:W.text,lineHeight:Te.base});const k=[b];if(B.showOnMap){const L=c.createElement("button");L.type="button",L.textContent="Show on map",L.dataset.wmapWorthShowOnMap="1",Object.assign(L.style,{..._e("outlined"),fontSize:N.body,padding:`0 ${O.md}`}),fe(L),Ie(L,"Leave Insights and show this on the map, as its row in What stands out does"),L.addEventListener("click",()=>B.showOnMap(o.target)),k.push(L)}const C=se({doc:c,items:g,ctx:{testDefs:t,curation:de},spec:{id:`worth-${l}`,...o.chart},extras:k,editAsPlot:te,chart:{onSaveImage:P}});C.card.dataset.wmapWorthKey=Bn(o),r.appendChild(C.card),p.push(C.destroy)}),f.also){const o=f.also.items.map(l=>l.brief).join("; ");h(`Also: ${o}${f.also.more?`; and ${f.also.more} more`:""}. Their rows in What stands out show them on the map.`,"wmapWorthAlso")}return{el:d,destroy:()=>p.forEach(o=>o())}}function ht(){const e=c.createElement("div");Object.assign(e.style,{fontSize:N.body,color:W.label});const t=c.createElement("button");return t.type="button",t.textContent="Data tab",t.dataset.wmapOpenDataTab="1",Object.assign(t.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:W.iconActive,textDecoration:"underline"}),fe(t,"bare"),t.addEventListener("click",()=>{z="data",q({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",t,"."),e}function bt(e,t,n,d){const u=c.createElement("div");u.style.width="100%";let h,f=!1;return import("./plotTab.js").then(({createPlotSection:r})=>{if(f)return;const g=r({doc:c,store:ee,items:e,testDefs:t,ringCount:V(),attributes:B.attributes,groupBy:n,groupLabel:d,onSaveImage:P,onSaveText:Y,getBinColors:U,waferMenu:ue(e),openWafer:X?(p,o,l)=>X(p,o,l):void 0,focusTest:me,locateDie:ae,pickPlotsFile:B.onPickPlotsFile});u.appendChild(g.card),h=g}),{card:u,destroy:()=>{f=!0,h?.destroy()}}}function gt(e,t,n,d,u){const h=he?void 0:Ae?.(),f=()=>{ne.get("data")?.destroy(),ne.delete("data"),q({keepSections:!0})};return yn({doc:c,items:e,testDefs:t,allTestDefs:n,groups:d,groupLabelText:u,ringCount:V(),attributes:B.attributes,yieldByWaferIndex:new Map(h?.lotYieldSeries.map(r=>[r.waferIndex,r.yieldPercent])),onSaveText:Y,onLocateDie:ae,onOpenWafer:X?(r,g)=>X(r,g):void 0,buildStatistics:r=>ut(r,t,n),view:Pe,onViewChange:r=>{Pe=r,f()},diesLayout:Re,onDiesLayoutChange:r=>{Re=r}})}function ze(e,t){const n=c.createElement("h3");return n.textContent=e,n.dataset.wmapRowHeading=t,Object.assign(n.style,{gridColumn:"1 / -1",margin:`${O.md} 0 0`,color:W.value,fontSize:N.heading,fontWeight:"600"}),n}function yt(e,t,n,d){const u=pe(c),h=je(e),f=le(e.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:V()}))),r=t.filter(s=>s.testNumber!==void 0),g=!!n&&!!F,p=g&&R!==null,o={testDefs:t,groupBy:g?F:void 0,curation:B.attributes},l=(s,y,$)=>({limits:y.limits??"both",axes:{[s]:{...y.includeLimits!==void 0?{includeLimits:y.includeLimits}:{},...y.clipOutliers?{clip:!0}:{},...$?{scale:"log"}:{}}}});function b(s){let y=ge,$=!1,A;const I=nn(r,H??r[0]?.testNumber??null,j=>{A?.refresh(),m(j)},{ownerDocument:c}),T=c.createElement("span");Object.assign(T.style,{display:"inline-flex",flexWrap:"wrap",gap:O.sm,alignItems:"center"});const D={setAxisPrefs:j=>{K.set(j)&&(y=j,A?.refresh())}},K=an(T,y,j=>{y=j,A?.refresh(),we(j,D)},c),re=[I.el,T];s.logToggle&&re.push(on("Log scale",$,j=>{$=j,A?.refresh()},c,"Draw the value axis on a logarithmic scale")),re.push(...s.extras??[]),A=se({doc:c,editAsPlot:te,items:f,ctx:o,...s.card,spec:{choices:[],build:()=>s.build(y,$)},slots:()=>({test:I.get()??void 0}),extras:re,onResolved:j=>{const Se=t.find(kt=>kt.testNumber===I.get()),He=Ue(Se,y.limits),ve=Sn(j,s.valueRole),{lo:St,hi:vt}=rn(He),Bt=ve.length>0&&He.length>0&&ln(cn(ve),dn(ve),St,vt);K.sync(y.includeLimits??Bt,Ue(Se).length>0,Xe(Se))},chart:s.chart});const M=A;return{card:M.card,setTest:j=>{I.set(j)&&M.refresh()},refresh:()=>M.refresh(),setAxisPrefs:D.setAxisPrefs,destroy:()=>M.destroy()}}const k=h?(s,y)=>h.open(f[s]?.waferIndex??s,y??H??r[0]?.testNumber??0):void 0,C=b({valueRole:"y",logToggle:!0,build:(s,y)=>({id:"card-box",title:"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:g&&!p?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:{none:!0}},...p?{where:{conditions:[{field:{meta:F},values:[R]}]}}:{},...l("y",s,y)}),card:{...g&&!p?{drill:s=>{const y=Be(f[s[0]?.item]?.metadata,F,B.attributes);return y!==void 0&&ie(y),null},drillLabel:"see its wafers"}:{},...R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{}},chart:{onSaveImage:P,onOpenWafer:k,openActionLabel:h?.label,onWaferMenu:ue(e)}});let L=null;const w=g?[]:[qe(f.map(s=>({label:s.label})),null,s=>{L=s,S.refresh()},{ownerDocument:c})],S=b({valueRole:"x",extras:w,card:R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{},build:s=>({id:"card-histogram",title:"Value histogram",chart:"histogram",fields:{y:{slot:"test"},color:g?{follow:"groupBy"}:{none:!0}},...L!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[L].label]}]}}:{},...l("x",s,!1)}),chart:{onSaveImage:P,...g?{onLegendPick:s=>ie(s),legendPicked:R}:{},onSelectPoints:(s,y,$,A)=>{const I=t.find(M=>M.testNumber===(H??r[0]?.testNumber)),T=new Set(s.map(M=>M.die).filter(M=>!!M)),D=new Set(s.map(M=>f[M.item]?.waferIndex)),K=A?.range,re=I&&K?`with ${Ye(I,I.testNumber)} from ${Ve(K.lo,I.unit,"engineering")} to ${Ve(K.hi,I.unit,"engineering")}${A?.group?` in ${A.group}`:""}`:"selected in the histogram";oe(y,$,e.filter(M=>D.has(M.waferIndex)),re,M=>T.has(M),I?.testNumber)}}}),a=b({valueRole:"y",build:s=>({id:"card-trend",title:"Wafer-to-wafer trend",chart:"line",aggregate:"mean",spread:"sd",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:{none:!0}},...l("y",s,!1),axes:{...l("y",s,!1).axes,y:{...l("y",s,!1).axes.y,references:[{stat:"mean",label:Ht(zt(e.map(y=>y.wafer.metadata)),"mean")}]}}}),card:{ctx:{...o,groupBy:void 0},...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:P,onWaferMenu:ue(e),selectActionLabel:k?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(s,y,$)=>{const A=new Set(s.map(D=>D.item));if(A.size===1&&k){k([...A][0]);return}const I=new Set(s.map(D=>D.die).filter(D=>!!D)),T=new Set(s.map(D=>f[D.item]?.waferIndex));oe(y,$,e.filter(D=>T.has(D.waferIndex)),"selected in the trend",D=>I.has(D),H??void 0)}}}),m=s=>{H=s,C.setTest(s),S.setTest(s),a.setTest(s),v.setTest(s),E?.setTest(s),i?.setTest(s)},x=()=>Kt({groups:n,testDefs:t,groupLabelText:d,control:Fe,onControlChange:s=>{Fe=s;const y=x();E.card.replaceWith(y.card),E=y},selectedTestNumber:H??void 0,onSelectTest:s=>m(s),onSaveText:Y,ownerDocument:c});let E=n&&n.length>=2?x():void 0;const i=n&&n.length>=2?Jt({groups:n,testDefs:t,groupLabelText:d,selectedTestNumber:H??void 0,onSaveImage:P,ownerDocument:c}):void 0;ye.set("distribution",[C,S,a]);const v=qt({title:"Process capability",items:e,testDefs:t,onSaveImage:P,selectedTestNumber:H??void 0,onSelectTest:s=>m(s),ownerDocument:c});return(E||i)&&(u.append(ze(`Comparing ${d??"groups"}`,"comparing")),E&&u.append(E.card),i&&u.append(i.card),u.append(ze("Test by test","tests"))),u.append(v.card,C.card,S.card,a.card),{card:u,destroy:()=>{v.destroy(),C.destroy(),S.destroy(),a.destroy(),E?.destroy(),i?.destroy()}}}function wt(e,t,n){const d=pe(c),u=je(e),h=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:V()}))),f=t.filter(i=>i.testNumber!==void 0&&Le(i));let r=f[0]?.testNumber,g=f[1]?.testNumber??r,p=null,o=ge;const l=!!n&&!!F,b=(i,v)=>{const s=c.createElement("label");Object.assign(s.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:N.body,color:W.label});const y=c.createElement("span");return y.textContent=i,s.append(y,v),s},k=Ke(f,r??null,i=>{r=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),C=Ke(f,g??null,i=>{g=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),L=c.createElement("span"),w={setXY:(i,v)=>{r=i,g=v,k.value=String(i),C.value=String(v),S(),x.refresh()},setAxisPrefs:i=>{o=i,S(),x.refresh()},destroy:()=>x.destroy()};function S(){const i=[r,g].map(v=>t.find(s=>s.testNumber===v));L.replaceChildren(...i.some(Xe)?[sn(o.limits??"both",v=>{o={...o,limits:v},x.refresh(),we(o,w)},c)]:[])}const a=i=>{const v=t.find(s=>s.testNumber===i);return v?.name?{test:i??0,name:v.name}:{test:i??0}},m=[b("X:",k),b("Y:",C),L];!l&&e.length>1&&m.push(qe(h.map(i=>({label:i.label})),null,i=>{p=i,x.refresh()},{ownerDocument:c}));const x=se({doc:c,editAsPlot:te,items:h,ctx:{testDefs:t,groupBy:l?F:void 0,curation:B.attributes},extras:m,spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:o.limits??"both",fields:{x:a(r),y:a(g),color:l?{follow:"groupBy"}:{builtin:"hbin"}},...p!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[h[p].label]}]}}:{}})},...r===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:P,binColors:U(),onOpenWafer:u?(i,v)=>u.open(h[i]?.waferIndex??i,v??r??0):void 0,openActionLabel:u?.label,onSelectPoints:(i,v,s)=>{const y=new Map;for(const I of i){const T=h[I.item]?.waferIndex;if(T===void 0||!I.die)continue;const D=y.get(T);D?D.push(I.die):y.set(T,[I.die])}const $=[...y].flatMap(([I,T])=>{const D=e.find(K=>K.waferIndex===I);return D?[{label:D.identity??D.label,dies:T,waferIndex:I,wafer:D.wafer,passBins:D.passBins,ringCount:V()}]:[]});if($.length===0)return;const A=$.length===1?`selected on ${$[0].label} in the scatter`:`selected in the scatter, across ${$.length} wafers`;Ee(v,s,{items:$,population:A,testDefs:t,activeTest:r},{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}}});S(),ye.set("correlation",[w]);const E=Qt({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:P,onSaveText:Y,onSelectPair:(i,v)=>w.setXY(i,v),ownerDocument:c});return d.append(E.card,x.card),{card:d,destroy:()=>{E.destroy(),w.destroy()}}}const xt=(e,t,n,d)=>Nt(c,e,t,n,d),Ct=()=>ce.openEditor(G,xe());function q(e){e?.keepSections||Me(),Q.innerHTML="",_.innerHTML="";for(const a of at)_.appendChild(rt(a.key,a.label));const t=xe(),n=ce.keep(t),d=n.items;he=n.narrowing,We.refresh(n.result,t),dt(d);const u=Et(d,{facetableOnly:!0,curation:de}).filter(a=>a.splittable);be=u.map(a=>({key:a.key,label:a.label}));const h=c.createElement("div");Object.assign(h.style,{display:"flex",gap:O.md,alignItems:"center",marginLeft:O.xxl,paddingBottom:O.xs}),B.showFilterButton!==!1&&h.appendChild(xt("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>Ct()));let f;u.length>0?(h.appendChild(en("Group by:",[{value:"",label:"None"},...u.map(a=>({value:a.key,label:`${a.label} (${a.values.length})`}))],F??"",a=>{F=a||void 0,R=null,q()},{hook:"group-by",ownerDocument:c})),f=u.find(a=>a.key===F)?.label):F=void 0;let r;if(F){const a=new Map,m=[];for(const x of d){const E=Be(x.metadata,F,de)??Tt;a.has(E)||(a.set(E,[]),m.push(E)),a.get(E).push(x)}r=Cn(m).map(x=>({key:x,items:a.get(x)}))}R!==null&&!r?.some(a=>a.key===R)&&(R=null),r&&r.length>0&&h.appendChild(tn(r.map(a=>a.key),"Show:",R,a=>ie(a),{ownerDocument:c}).el);let g=null;if(B.onOpenGuide){const a=c.createElement("button");a.type="button",a.innerHTML=_t.help,a.setAttribute("aria-label","User guide"),Object.assign(a.style,{..._e("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),fe(a,"bare"),Ie(a,"User guide"),a.addEventListener("click",()=>B.onOpenGuide()),Object.assign(a.style,{marginLeft:"auto"}),g=a}_.appendChild(h),g&&_.appendChild(g);const p=R!==null?r?.find(a=>a.key===R):void 0,o=p?.items??d,l=p?void 0:r,b=ke(o),k=b.defs,C=k.filter(Le);if(H!==null&&!C.some(a=>a.testNumber===H)&&(H=null),d.length===0){const a=c.createElement("div");a.dataset.wmapInsightsFilterEmpty="1",a.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(a.style,{color:W.label,fontSize:N.body,padding:O.xl}),Q.appendChild(a);return}const L=e?.keepSections?ne.get(z):void 0,w=L??(z==="overview"?pt(o,C,k,l,f):z==="distributions"?yt(o,C,l,f):z==="data"?gt(o,C,k,l,f):z==="plot"?bt(o,k,p?void 0:F,p?void 0:f):wt(o,C,l));L||ne.set(z,w);const S=b.conflicts.filter(a=>a.excluded);if(S.length>0){const a=c.createElement("div");Object.assign(a.style,{color:W.label,fontSize:N.body,padding:`0 ${J} ${O.sm}`});const m=S.slice(0,6).map(i=>i.testNumber).join(", "),x=S.length>6?`, and ${S.length-6} more`:"",E=S.length===1?"it":"them";a.textContent=`${S.length} test ${S.length===1?"number is":"numbers are"} hidden (${m}${x}) \u2014 the wafers in view describe ${E} differently, so their values cannot be pooled. `+(r&&r.length>0?`Pick one ${f??"group"} under "Show:" to analyse ${E}.`:"Load one test program at a time to analyse them."),a.dataset.wmapWithheldTests=String(S.length),Q.appendChild(a)}Q.appendChild(w.card)}return{el:G,render:q,destroy:()=>{Me(),ee.flush(),G.remove()},setAxisPrefs:e=>we(e,null,!0),showWorthCard:e=>{z!=="overview"&&(z="overview",q({keepSections:!0}));const t=[...Q.querySelectorAll("[data-wmap-worth-key]")].find(u=>u.dataset.wmapWorthKey===e);if(!t)return!1;const n=c.defaultView,d=()=>t.scrollIntoView({block:"center"});return n?.requestAnimationFrame?n.requestAnimationFrame(()=>n.requestAnimationFrame(d)):d(),t.style.outline=`2px solid ${W.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
@@ -0,0 +1,84 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { Wafer } from '../core/wafer.js';
3
+ import type { TestDef } from '../renderer/buildWaferMap.js';
4
+ import type { StatsSummary } from '../stats/types.js';
5
+ import { type FacetCuration } from '../stats/facets.js';
6
+ import { type PlotFilter } from '../stats/plotSpec.js';
7
+ import { type SavedFilter } from '../stats/filterFile.js';
8
+ import { type ConditionsApplied } from '../stats/plotData.js';
9
+ import { type SaveTextHandler } from './toolbar.js';
10
+ /** What the filter reads of a wafer. Insights' items and the gallery's cards both have this shape. */
11
+ export interface FilterSource {
12
+ dies: Die[];
13
+ wafer: Wafer;
14
+ /** Shown in a plot's title; the wafer's identity when it has one. */
15
+ label: string;
16
+ identity?: string;
17
+ waferIndex: number;
18
+ passBins: readonly number[];
19
+ testDefs?: TestDef[];
20
+ statsSummary?: StatsSummary;
21
+ }
22
+ export interface PageFilterOptions {
23
+ /** The filter to start with, as the host stored it (read like a plots file, so a stale one is tolerated). */
24
+ initial?: unknown;
25
+ /** Called with the filter after the reader applies, switches or removes it. */
26
+ onChange?: (filter: PlotFilter | undefined) => void;
27
+ attributes?: Record<string, FacetCuration>;
28
+ getRingCount: () => number;
29
+ doc: Document;
30
+ /** The host's saved filters to start with, read as a filters file's are: one it cannot read is left out and logged. */
31
+ savedFilters?: readonly unknown[];
32
+ /** Called with the whole list after the reader saves, deletes or imports a filter. */
33
+ onSavedFiltersChange?: (filters: SavedFilter[]) => void;
34
+ /** Choose a filters file to import, resolving to its text, or `null` when cancelled. Without it the browser's own file input is used. */
35
+ pickFiltersFile?: () => Promise<string | null>;
36
+ onSaveText?: SaveTextHandler;
37
+ }
38
+ export interface PageFilterBand {
39
+ el: HTMLElement;
40
+ /** Show the filter and what it kept; hides the band when there is no filter. */
41
+ refresh(result: ConditionsApplied | undefined, sources: readonly FilterSource[]): void;
42
+ }
43
+ export interface PageFilterController {
44
+ get(): PlotFilter | undefined;
45
+ /** Set (or with `undefined` remove) the filter: the host is told and every subscribed view re-renders. */
46
+ set(filter: PlotFilter | undefined): void;
47
+ /** Called after every change; returns the unsubscribe. */
48
+ subscribe(fn: () => void): () => void;
49
+ /** The wafers and dies the filter keeps; the rest are gone. `result` is undefined with no filter in force. */
50
+ keep<T extends FilterSource>(sources: readonly T[]): {
51
+ items: T[];
52
+ result?: ConditionsApplied;
53
+ narrowing: boolean;
54
+ };
55
+ /**
56
+ * Every wafer, in place: dies the filter drops are copies flagged `filteredOut`, a narrowed wafer loses its summary
57
+ * (it describes every die), and `hidden` holds the positions of wafers dropped whole.
58
+ */
59
+ mark<T extends FilterSource>(sources: readonly T[]): {
60
+ items: T[];
61
+ hidden: Set<number>;
62
+ result?: ConditionsApplied;
63
+ narrowing: boolean;
64
+ };
65
+ createBand(sources: () => readonly FilterSource[], inset?: {
66
+ marginLeft: string;
67
+ marginRight: string;
68
+ marginBottom: string;
69
+ }): PageFilterBand;
70
+ /** The saved filters, in the order they were kept. */
71
+ saved(): readonly SavedFilter[];
72
+ /** Replace the list (the host is told). */
73
+ setSaved(filters: readonly SavedFilter[]): void;
74
+ /** The editor window, over the population given. */
75
+ openEditor(anchor: HTMLElement, sources: readonly FilterSource[]): void;
76
+ }
77
+ /**
78
+ * A filter as the host gave it, read by the plots file's own reader: a host restores it from storage, where it may be
79
+ * malformed or written by another version. A condition that cannot be read is left out and the problem logged; the band
80
+ * then states the filter that is applied, so nothing is filtered unseen.
81
+ */
82
+ export declare function readFilterOption(raw: unknown): PlotFilter | undefined;
83
+ export declare function createPageFilter(o: PageFilterOptions): PageFilterController;
84
+ //# sourceMappingURL=pageFilter.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{mergeTestDefs as I}from"../stats/mergeTestDefs.js";import{DEFAULT_FACET_CURATION as T}from"../stats/facets.js";import{conditionText as k}from"../stats/plotData.js";import{readFilter as A}from"../stats/plotSpec.js";import{addSavedFilters as B,readSavedFilters as L,readFiltersFile as J,writeFiltersFile as W}from"../stats/filterFile.js";import{newFilterId as R}from"../stats/plotId.js";import{applyConditions as $,fieldCatalogue as P,fieldExtent as G,fieldValues as z}from"../stats/plotData.js";import{toPlotItems as U}from"./plotItems.js";import{buildFilterEditor as K,buildFilterStrip as M}from"./filterEditor.js";import{CLR as b,FONT as j,RADIUS as _,SPACE as g,openModal as q,saveTextFile as H,wireTooltip as V}from"./toolbar.js";import{inputStyle as Y}from"./charts/chartShell.js";import{bandButton as O}from"./filterButton.js";export function readFilterOption(n){if(n==null)return;const t=[],l=typeof n=="object"&&!Array.isArray(n)?A(JSON.parse(JSON.stringify(n)),"insights.filter",t):void 0;return l||t.push("insights.filter: needs at least one condition, so no filter is applied"),t.length&&console.warn(`[wafermap] ${t.join("; ")}`),l}const D=n=>JSON.parse(JSON.stringify(n));export function createPageFilter(n){const{doc:t}=n,h={...T,...n.attributes};let l=readFilterOption(n.initial);const y=new Set;let x=(()=>{if(!n.savedFilters)return[];const i=L(n.savedFilters,"insights.savedFilters");return i.warnings.length&&console.warn(`[wafermap] ${i.warnings.join("; ")}`),i.filters})();const E=i=>({items:U(i.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:n.getRingCount()}))),ctx:{testDefs:I([...i]).defs,curation:h}}),v=i=>{if(!l||l.off)return;const s=E(i);return $(l.conditions,s.items,s.ctx)},S={get:()=>l,set(i){l=i,n.onChange?.(i?D(i):void 0);for(const s of[...y])s()},subscribe(i){return y.add(i),()=>{y.delete(i)}},saved:()=>x,setSaved(i){x=i.map(s=>JSON.parse(JSON.stringify(s))),n.onSavedFiltersChange?.(x.map(s=>JSON.parse(JSON.stringify(s))))},keep(i){const s=v(i);if(!s||s.issue)return{items:i,result:s,narrowing:!1};const r=s.index.map((p,u)=>{const a=i[p],e=s.items[u].dies;return e.length===a.dies.length?a:{...a,dies:e,statsSummary:void 0}});return{items:r,result:s,narrowing:r.length!==i.length||r.some((p,u)=>p!==i[s.index[u]])}},mark(i){const s=new Set,r=v(i);if(!r||r.issue)return{items:i,hidden:s,result:r,narrowing:!1};const p=new Map(r.index.map((e,c)=>[e,r.items[c].dies]));let u=!1;return{items:i.map((e,c)=>{const o=p.get(c);if(o===void 0&&(s.add(c),u=!0),o&&o.length===e.dies.length)return e;u=!0;const w=o?new Set(o):void 0,d=e.dies.map(m=>w?.has(m)?m:{...m,filteredOut:!0});return{...e,dies:d,statsSummary:void 0}}),hidden:s,result:r,narrowing:u}},createBand(i,s){const r=t.createElement("div");r.dataset.wmapInsightsFilter="1",Object.assign(r.style,{display:"none",...s});const p=(a,e,c,o)=>O(t,a,e,c,o);return{el:r,refresh:(a,e)=>{if(r.replaceChildren(),r.style.display=l?"":"none",!l)return;const c=[p("Edit\u2026","wmapInsightsFilterEdit","Change the conditions",()=>S.openEditor(r,e)),p("Remove","wmapInsightsFilterRemove","Delete the filter: every wafer and die is shown again",()=>S.set(void 0))];if(a?.issue){const d=t.createElement("div");d.dataset.wmapInsightsFilterIssue="1",d.setAttribute("role","status"),Object.assign(d.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:g.md,padding:`${g.xs} ${g.md}`,background:b.warnBg,border:`1px solid ${b.warnBorder}`,borderRadius:_.control,color:b.warnText,fontSize:j.body});const m=t.createElement("span");m.textContent=`The filter cannot be applied to these wafers (${a.issue}), so nothing is filtered.`;const F=t.createElement("span");Object.assign(F.style,{display:"inline-flex",gap:g.sm,marginLeft:"auto"}),F.append(...c),d.append(m,F),r.appendChild(d);return}const o=d=>d.toLocaleString("en-GB"),w=a?`${o(a.wafers.kept)} of ${o(a.wafers.total)} wafer${a.wafers.total===1?"":"s"} \xB7 ${o(a.dies.kept)} of ${o(a.dies.total)} dies`:void 0;r.appendChild(M({doc:t,filter:l,testDefs:I([...e]).defs,attributes:h,label:"Filter",kept:w,actions:c,onToggle:d=>{if(!l)return;const m={...l};d?delete m.off:m.off=!0,S.set(m)}}))}}},openEditor(i,s){const r=E(s);let p=l?D(l):void 0,u;const a=q({title:"Filter",anchor:i,ownerDocument:t,boxSize:{width:"min(92vw, 640px)",height:"min(85vh, 640px)"},maximizable:!1,initialFocus:()=>p?u:d.el.querySelector("[data-wmap-filter-add]")??u,onClose:()=>{}});a.box.dataset.wmapInsightsFilterModal="1";const e=t.createElement("div");Object.assign(e.style,{display:"flex",flexDirection:"column",gap:g.lg,padding:g.xl,color:b.text,fontSize:j.body,overflowY:"auto",flex:"1 1 auto",minHeight:"0"});const c=t.createElement("p");c.style.margin="0",c.textContent="The maps, the gallery and every Insights tab show only the wafers and dies that meet every condition. A condition on a wafer field (split, yield) keeps whole wafers; one on a die field (bin, ring, a test) keeps those dies inside them, and a map draws the others dimmed. The filter is shown above each view for as long as it exists, and can be switched off there without losing it.";const o=t.createElement("div");o.dataset.wmapInsightsFilterPreview="1",o.setAttribute("aria-live","polite"),Object.assign(o.style,{fontWeight:"600",color:b.value});const w=()=>{if(!p||p.off){o.textContent=p?"Off: every wafer and die is shown.":"No conditions: every wafer and die is shown.";return}const f=$(p.conditions,r.items,r.ctx);o.textContent=f.issue?`Cannot be applied: ${f.issue}`:`Keeps ${f.wafers.kept.toLocaleString("en-GB")} of ${f.wafers.total.toLocaleString("en-GB")} wafers \xB7 ${f.dies.kept.toLocaleString("en-GB")} of ${f.dies.total.toLocaleString("en-GB")} dies`},d=K({doc:t,catalogue:P(r.items,r.ctx),filter:p,testDefs:r.ctx.testDefs,attributes:h,switchLabel:"Filter",valuesOf:f=>z(f,r.items,r.ctx),extentOf:f=>G(f,r.items,r.ctx),onChange:f=>{p=f,w()}});w();const m=t.createElement("div");Object.assign(m.style,{display:"flex",justifyContent:"flex-end",gap:g.md,flexWrap:"wrap",flexShrink:"0",padding:`${g.md} ${g.xl}`,borderTop:`1px solid ${b.menuBorder}`});const F=O(t,"Cancel","wmapInsightsFilterCancel","Close without changing the filter",()=>a.close());u=O(t,"Apply","wmapInsightsFilterApply","Filter the maps, the gallery and Insights by these conditions",()=>{a.close(),S.set(p)});for(const f of[F,u])f.style.padding=`${g.sm} ${g.lg}`;m.append(F,u),e.append(c,d.el,o,Q({doc:t,popItems:r,getDraft:()=>p,load:f=>{p={conditions:JSON.parse(JSON.stringify(f.conditions))},d.set(p),w()},saved:()=>S.saved(),setSaved:f=>S.setSaved(f),onSaveText:n.onSaveText,pickFile:n.pickFiltersFile,attributes:h})),a.contentWrap.style.flexDirection="column",a.contentWrap.append(e,m)}};return S}function Q(n){const{doc:t}=n,h=t.createElement("div");h.dataset.wmapSavedFilters="1",Object.assign(h.style,{display:"flex",flexDirection:"column",gap:g.md,borderTop:`1px solid ${b.menuBorder}`,paddingTop:g.lg});const l=t.createElement("div");l.textContent="Saved filters",Object.assign(l.style,{fontWeight:"600",color:b.value});const y=t.createElement("div");y.dataset.wmapSavedFiltersStatus="1",y.setAttribute("role","status"),Object.assign(y.style,{color:b.label,whiteSpace:"pre-line"});const x=(a,e=[])=>{y.textContent=[a,...e].filter(Boolean).join(`
2
+ `)},E=t.createElement("div");Object.assign(E.style,{display:"flex",gap:g.sm,flexWrap:"wrap",alignItems:"center"});const v=t.createElement("input");v.type="text",v.placeholder="Name for the conditions above",v.setAttribute("aria-label","Name for the saved filter"),v.dataset.wmapSavedFilterName="1",Object.assign(v.style,{...Y(),flex:"1 1 12em"});const S=O(t,"Save","wmapSavedFilterSave","Keep the conditions above under this name",()=>{const a=n.getDraft(),e=v.value.trim();if(!a||a.conditions.length===0){x("Add a condition first: there is nothing to save.");return}if(!e){x("Give the filter a name."),v.focus();return}const c=JSON.parse(JSON.stringify(a.conditions)),o=n.saved(),w=o.findIndex(d=>d.name===e);n.setSaved(w<0?[...o,{id:R(),name:e,conditions:c}]:o.map((d,m)=>m===w?{...d,conditions:c}:d)),v.value="",x(w<0?`Saved \u201C${e}\u201D.`:`Updated \u201C${e}\u201D.`),s()});E.append(v,S);const i=t.createElement("div");i.dataset.wmapSavedFilterList="1",Object.assign(i.style,{display:"flex",flexDirection:"column",gap:g.xs});function s(){i.replaceChildren();const a=n.saved();if(a.length===0){const e=t.createElement("div");e.textContent="None yet. Set conditions above and save them under a name to use them again.",e.style.color=b.label,i.appendChild(e);return}for(const e of a){const c=t.createElement("div");c.dataset.wmapSavedFilter=e.id,Object.assign(c.style,{display:"flex",gap:g.sm,alignItems:"center",flexWrap:"wrap"});const o=t.createElement("span");Object.assign(o.style,{flex:"1 1 14em",minWidth:"0"});const w=t.createElement("strong");w.textContent=e.name;const d=t.createElement("span");d.style.color=b.label,d.textContent=` \u2014 ${e.conditions.map(C=>k(C,n.popItems.ctx.testDefs,n.attributes)).join(" \xB7 ")}`,o.append(w,d);const m=$(e.conditions,n.popItems.items,n.popItems.ctx).issue;if(m){const C=t.createElement("div");C.dataset.wmapSavedFilterIssue="1",C.textContent=`Cannot be applied to these wafers: ${m}`,Object.assign(C.style,{color:b.warnText,fontSize:j.body}),o.appendChild(C)}const F=O(t,"Load","wmapSavedFilterLoad","Put these conditions in the editor, replacing the ones there",()=>{n.load(e),x(`Loaded \u201C${e.name}\u201D. Press Apply to filter by it.`)}),f=O(t,"Delete","wmapSavedFilterDelete","Remove this saved filter",()=>{const C=n.saved();n.setSaved(C.filter(N=>N.id!==e.id)),x(`Deleted \u201C${e.name}\u201D.`),s()});c.append(o,F,f),i.appendChild(c)}}const r=t.createElement("div");Object.assign(r.style,{display:"flex",gap:g.sm,flexWrap:"wrap"});const p=O(t,"Export\u2026","wmapSavedFilterExport","Save all your saved filters to a file, to share or to keep a copy",()=>{if(n.saved().length===0){x("There are no saved filters to export yet.");return}H(W(n.saved()),"wafermap-filters.json","application/json",n.onSaveText)}),u=O(t,"Import\u2026","wmapSavedFilterImport","Add the filters from a file written by Export\u2026",()=>{(async()=>{const a=await X(t,n.pickFile);if(a===null)return;const e=J(a);if(e.error){x(`Could not import: ${e.error}`);return}const{filters:c,copies:o}=B(n.saved(),e.filters);n.setSaved(c),s(),x(`Imported ${e.filters.length} filter${e.filters.length===1?"":"s"}.`,[...e.warnings,...o.length?[`Kept as copies, since a filter with the same id already existed: ${o.join(", ")}`]:[]])})()});for(const a of[S,p,u])a.style.padding=`${g.sm} ${g.lg}`;return r.append(u,p),V(v,"The name the filter is listed under; saving under a name already used updates that filter"),s(),h.append(l,E,i,r,y),h}async function X(n,t){return t?t():new Promise(h=>{const l=n.createElement("input");l.type="file",l.accept=".json,application/json",l.addEventListener("change",()=>{const y=l.files?.[0];if(!y){h(null);return}y.text().then(h,()=>h(null))}),l.addEventListener("cancel",()=>h(null)),l.click()})}
@@ -0,0 +1,26 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { TestDef } from '../renderer/buildWaferMap.js';
3
+ import type { RenderableWaferMap } from './renderWaferMap.js';
4
+ import { type WaferMapDisplayItem } from './renderWaferGallery.js';
5
+ export interface PatMapItem {
6
+ label: string;
7
+ dies: readonly Die[];
8
+ allDies?: readonly Die[];
9
+ passBins: readonly number[];
10
+ ringCount: number;
11
+ source?: RenderableWaferMap;
12
+ }
13
+ /**
14
+ * One map per wafer that has its own result to draw on (geometry and orientation come from it), each die carrying its
15
+ * verdict as a value of the field "PAT verdict" and the map coloured by it, so the legend, toolbar and tooltips name the
16
+ * verdict and not a bin. A die with no verdict (no test judged it) carries no value and draws as no data. The maps state no
17
+ * yield: a verdict is not a bin.
18
+ */
19
+ export declare function patVerdictMaps(items: readonly PatMapItem[], testDefs: readonly TestDef[]): WaferMapDisplayItem[];
20
+ /** Opens the maps in a window over `anchor`: a gallery of them coloured by verdict, destroyed with the window. */
21
+ export declare function openPatMaps(o: {
22
+ anchor: HTMLElement;
23
+ items: readonly PatMapItem[];
24
+ testDefs: readonly TestDef[];
25
+ }): void;
26
+ //# sourceMappingURL=patMaps.d.ts.map
@@ -0,0 +1 @@
1
+ import{copyDie as u}from"../core/dieTable.js";import{PAT_VERDICT_LABEL as i,waferPatVerdicts as p}from"../stats/pat.js";import{openModal as h}from"./toolbar.js";import{renderWaferGallery as m}from"./renderWaferGallery.js";const a="pat",v={key:a,label:"PAT verdict",values:[{value:i.within,color:"#0072b2"},{value:i.outlier,color:"#e69f00"},{value:i.fails,color:"#c0392b"}]};export function patVerdictMaps(t,s){const n=[];for(const e of t){if(!e.source)continue;const o=e.allDies??e.dies,r=p(o,s,e.passBins),l=o.map((d,f)=>{const c=r[f].verdict;return u(d,{hbin:void 0,sbin:void 0,testValues:void 0,testPass:void 0,metadata:c?{[a]:i[c]}:void 0})});n.push({...e.source,label:e.label,dies:l,ringCount:e.ringCount,passBins:[],hbinDefs:[],sbinDefs:[],testDefs:[],metadataFields:[v]})}return n}export function openPatMaps(t){const s=patVerdictMaps(t.items,t.testDefs);if(s.length===0)return;const n=t.anchor.ownerDocument,e=n.createElement("div");Object.assign(e.style,{height:"100%",minHeight:"0",overflow:"auto"});let o;h({title:"PAT verdicts by wafer",anchor:t.anchor,ownerDocument:n,onClose:()=>o?.destroy(),boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"}}).contentWrap.appendChild(e),o=m(e,s,{viewOptions:{plotMode:"metadata",activeMetadataKey:a},insights:{enabled:!1}})}
@@ -0,0 +1,67 @@
1
+ import { type PlotContext, type PlotItem, type PlotPoint, type ResolvedPlot } from '../stats/plotData.js';
2
+ import { type CardSlotValues, type CardSpec } from '../stats/cardSpec.js';
3
+ import { type PlotSpec } from '../stats/plotSpec.js';
4
+ import { type PlotChartOptions } from './charts/plotChart.js';
5
+ type ChoiceOptions = Array<[value: string, label: string, hint?: string]>;
6
+ /**
7
+ * One of a card's own choices (Hard or Soft bins, the sort): its options and the one shown first. Options given as a
8
+ * function are named for whether the card is drilled into a group (the sort then orders wafers, not groups).
9
+ */
10
+ export interface CardChoice {
11
+ current: string;
12
+ options: ChoiceOptions | ((drilled: boolean) => ChoiceOptions);
13
+ }
14
+ /** A change the card makes to whichever variant is shown: a drill into one group. */
15
+ export type CardTransform = (spec: CardSpec) => CardSpec;
16
+ export interface PlotCardOptions {
17
+ doc: Document;
18
+ items: readonly PlotItem[];
19
+ ctx: PlotContext;
20
+ /** The card, or its variants: one segmented control per choice, and the spec for the values chosen, in order. */
21
+ spec: CardSpec | {
22
+ choices: CardChoice[];
23
+ build: (values: readonly string[]) => CardSpec;
24
+ };
25
+ /** The slots' values now (the section's test, the Group by). */
26
+ slots?: () => CardSlotValues;
27
+ /**
28
+ * Clicking a mark that is not one wafer (a group's bar) drills into it: the change to draw, or `null` to fall through to
29
+ * `chart.onSelectPoints`. A Back button undoes it.
30
+ */
31
+ drill?: (points: readonly PlotPoint[]) => CardTransform | null;
32
+ /** What a click on a bar that drills does, in the reader's words ("see its wafers"). */
33
+ drillLabel?: string;
34
+ /** Lines the card adds under its statement, for what the plot itself cannot know (two judgements disagreeing). */
35
+ notes?: (spec: CardSpec) => string[];
36
+ /** Controls the host owns (a test picker shared across a section, its axis settings), put before the card's own. */
37
+ extras?: HTMLElement[];
38
+ /** A Back button the host drives: shown while `shown()` (a scope narrowed elsewhere), calling `onBack`. */
39
+ externalBack?: {
40
+ shown: () => boolean;
41
+ onBack: () => void;
42
+ };
43
+ /** Why the card draws nothing on this population (a trend through one wafer), in place of the plot. */
44
+ unavailable?: string;
45
+ /** Told each resolved plot, after it is drawn (a host control that reflects what was drawn). */
46
+ onResolved?: (r: ResolvedPlot) => void;
47
+ chart: Omit<PlotChartOptions, 'ownerDocument' | 'waferLabel'>;
48
+ /**
49
+ * Edit as plot, in the card's ⋯ menu: called with the reader's own plot of what the card shows now (`freezeCard`) and
50
+ * the population the card draws, to open in the plot editor. Absent = no such row (a host that keeps no plots).
51
+ */
52
+ editAsPlot?: (plot: PlotSpec, over: {
53
+ items: readonly PlotItem[];
54
+ ctx: PlotContext;
55
+ }) => void;
56
+ }
57
+ export interface PlotCardHandle {
58
+ card: HTMLElement;
59
+ /** The spec drawn now, slots unfilled. */
60
+ current(): CardSpec;
61
+ /** Draw again, with the slots as they are now. */
62
+ refresh(): void;
63
+ destroy(): void;
64
+ }
65
+ export declare function renderPlotCard(o: PlotCardOptions): PlotCardHandle;
66
+ export {};
67
+ //# sourceMappingURL=plotCard.d.ts.map
@@ -0,0 +1 @@
1
+ import{resolvePlot as k}from"../stats/plotData.js";import{fillCard as w,freezeCard as y}from"../stats/cardSpec.js";import{newPlotId as B}from"../stats/plotSpec.js";import{renderPlotChart as v}from"./charts/plotChart.js";import{makeBackButton as D,makeSegmented as A}from"./charts/chartShell.js";import{markNoPrint as P}from"./toolbar.js";export function renderPlotCard(e){let i;const f=D(()=>{i?(i=void 0,a()):e.externalBack?.onBack()},e.doc);P(f);const m={ownerDocument:e.doc,waferLabel:t=>e.items[t]?.label??"",...e.chart,onSelectPoints:e.drill||e.chart.onSelectPoints?(t,n,s,c)=>{const r=i?null:e.drill?.(t);if(r){i=r,a();return}e.chart.onSelectPoints?.(t,n,s,c)}:void 0},l=v(m),d="build"in e.spec?e.spec:void 0,p=d?.choices.map(t=>t.current)??[],h=()=>d?d.build(p):e.spec,o=()=>i?i(h()):h(),b=()=>({testDefs:e.ctx.testDefs,groupBy:e.ctx.groupBy,...e.slots?.()});if(e.editAsPlot){const t=e.editAsPlot;l.setMenuRows(()=>{const n=y(o(),{...b(),waferCount:e.items.length},B());return[{label:"Edit as plot",disabledHint:"issue"in n?n.issue:void 0,onClick:()=>{"spec"in n&&t(n.spec,{items:e.items,ctx:e.ctx})}}]})}l.actions.appendChild(f);for(const t of e.extras??[])l.actions.appendChild(t);let u=[],x;const g=()=>{const t=!!i;if(x===t)return;x=t;const n=(d?.choices??[]).map((s,c)=>{const r=A(typeof s.options=="function"?s.options(t):s.options,p[c],C=>{p[c]=C,a()},e.doc);return P(r),r});if(u.length)u.forEach((s,c)=>s.replaceWith(n[c]));else for(const s of n)l.actions.appendChild(s);u=n};function a(){g(),f.style.display=i||e.externalBack?.shown()?"":"none",m.selectActionLabel=e.drill&&!i?e.drillLabel:e.chart.selectActionLabel;const t=w(o(),b()),n="spec"in t?t.spec:{...o(),fields:{}},s=k(n,e.items,e.ctx),c=e.notes?.(o())??[],r=e.unavailable?{...s,marks:void 0,issues:[e.unavailable]}:"issue"in t?{...s,issues:[t.issue]}:c.length?{...s,notes:[...s.notes,...c]}:s;l.setPlot(r),e.onResolved?.(r)}return a(),{card:l.card,current:o,refresh:a,destroy:()=>l.destroy()}}
@@ -1,5 +1,9 @@
1
1
  import { type FieldOption } from '../stats/plotData.js';
2
- import { type PlotSpec } from '../stats/plotSpec.js';
2
+ import { type PlotField, type PlotSpec } from '../stats/plotSpec.js';
3
+ import type { TestDef } from '../renderer/buildWaferMap.js';
4
+ import type { FacetCuration } from '../stats/facets.js';
5
+ import { inputStyle } from './charts/chartShell.js';
6
+ export { inputStyle };
3
7
  export interface PlotEditorOptions {
4
8
  doc: Document;
5
9
  plot: PlotSpec;
@@ -14,6 +18,14 @@ export interface PlotEditorOptions {
14
18
  };
15
19
  /** Called with the new spec after every change. */
16
20
  onChange: (next: PlotSpec) => void;
21
+ /** The values a category field takes on the population, in order: what a filter condition offers. */
22
+ valuesOf?: (field: PlotField) => string[];
23
+ /** The range a number field spans on the population: where a new range condition starts. */
24
+ extentOf?: (field: PlotField) => [number, number] | undefined;
25
+ /** The population's test definitions, so a condition on a test is stated with its name and unit. */
26
+ testDefs?: readonly TestDef[];
27
+ /** The host's names for wafer attributes, so a condition names a field as the field list does. */
28
+ attributes?: Record<string, FacetCuration>;
17
29
  }
18
30
  export interface PlotEditorHandle {
19
31
  el: HTMLElement;
@@ -22,7 +34,6 @@ export interface PlotEditorHandle {
22
34
  /** The automatic text changed (the data did): refresh the placeholders. */
23
35
  refreshAuto(): void;
24
36
  }
25
- export declare function inputStyle(): Partial<CSSStyleDeclaration>;
26
37
  /** A labelled control with an optional hint beneath it: the one layout every editor field uses. */
27
38
  export declare function fieldRow(doc: Document, label: string, control: HTMLElement, hint?: string): HTMLElement;
28
39
  export declare function createPlotEditor(o: PlotEditorOptions): PlotEditorHandle;
@@ -1 +1 @@
1
- import{combinationIssue as le,describeTitleDrift as oe,fieldKey as k,fieldsForRole as q,titleDrift as ae}from"../stats/plotData.js";import{sameField as $}from"../stats/plotSpec.js";import{CLR as m,FONT as S,RADIUS as V,SPACE as b,controlStyle as K,wireControlHover as _,wireTooltip as se}from"./toolbar.js";import{makeListSelect as X,makeSegmented as N,makeToggle as re}from"./charts/chartShell.js";const Y="\0follow",z="\0none",ce=[["scatter","Scatter","One point per die or wafer, one value against another"],["histogram","Histogram","How often each value occurs"],["box","Box","Quartiles, with whiskers to the minimum and maximum, for each category"],["bar","Bar","One combined value for each category, or a count"],["line","Line","One combined value at each X, joined"]],A="\0auto",G="\0count",Q={mean:"Mean",median:"Median",min:"Minimum",max:"Maximum",sum:"Sum",count:"Count",yield:"Pooled yield (passing over judged dies)"};export function inputStyle(){return{background:m.menuBg,color:m.text,border:`1px solid ${m.menuBorder}`,borderRadius:V.control,padding:`${b.xs} ${b.sm}`,fontSize:S.body,fontFamily:S.family,boxSizing:"border-box",minWidth:"0"}}export function fieldRow(d,r,B,a){const p=d.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:b.xxs,minWidth:"0"});const x=d.createElement("div");if(x.textContent=r,Object.assign(x.style,{fontSize:S.sub,color:m.label,fontWeight:"600"}),p.append(x,B),a){const T=d.createElement("div");T.textContent=a,Object.assign(T.style,{fontSize:S.sub,color:m.label}),p.appendChild(T)}return p}export function createPlotEditor(d){const{doc:r}=d,B=t=>t.fields?t:{...t,fields:{}};let a=B(d.plot),p="setup";const x=r.createElement("div");x.dataset.wmapPlotEditor="1",Object.assign(x.style,{display:"flex",flexDirection:"column",gap:b.lg,minWidth:"0"});const T=t=>{a=t,d.onChange(t)},y=t=>{const e=JSON.parse(JSON.stringify(a));t(e),T(e)},c=(t,e,i)=>fieldRow(r,t,e,i),D=t=>{const e=t&&d.catalogue.find(i=>$(i.field,t));return e?{label:e.name,level:e.level,kind:e.kind,yield:"builtin"in e.field&&e.field.builtin==="yield"}:void 0};function Z(t,e){const i=a.fields??{},n=i.color&&!("follow"in i.color)&&!("none"in i.color)?i.color:void 0,o={x:D(i.x),y:D(i.y),color:D(n)};o[t]=D(e.field);const l=a.chart==="scatter"&&o.color?.kind==="numeric"&&!!n&&!("meta"in n);return le(a.chart,o,{aggregate:a.aggregate,level:a.level,continuousColor:l})?.short}const I=t=>{const e=a.fields?.[t],i=e&&!("follow"in e)&&!("none"in e)?e:void 0;return q(d.catalogue,a.chart,t).map(n=>{const o=i&&$(n.field,i)?void 0:Z(t,n);return{value:k(n.field),label:n.label,group:n.group,...o?{disabled:o}:{}}})},H=t=>d.catalogue.find(e=>k(e.field)===t)?.field;function w(t,e,i={}){const n=a.fields[t],o=I(t);if(i.optional&&o.unshift({value:G,label:i.optional,group:"Count"}),n&&!o.some(u=>u.value===k(n))){const u=d.catalogue.some(C=>$(C.field,n)),h="test"in n?n.name??`Test ${n.test}`:"meta"in n?n.meta:n.builtin;o.unshift({value:k(n),label:`${h} (${u?"not usable here":"not in this lot"})`,group:"Saved"})}const l=n?k(n):i.optional?G:"",s=X(o,l,u=>{if(u===G){y(C=>{delete C.fields[t]});return}const h=H(u)??a.fields[t];h&&y(C=>{C.fields[t]=h})},{maxWidth:"100%",ownerDocument:r,ariaLabel:e,emptyText:"Choose a field\u2026",searchPlaceholder:"Filter fields\u2026",hook:`plot-${t}`});return s.style.width="100%",s}const P={},F={};function ee(t){y(e=>{e.chart=t;for(const i of["x","y"]){const n=q(d.catalogue,t,i),o=h=>!!h&&n.some(C=>$(C.field,h)),l=e.fields[i];if(l&&!o(l)&&($(l,F[i])||(P[i]=l),delete e.fields[i]),e.fields[i]||i==="y"&&t==="bar")continue;const s=P[i];if(o(s)){e.fields[i]=s,delete P[i],delete F[i];continue}const u=i==="x"&&(t==="box"||t==="bar")?{builtin:"wafer"}:i==="x"&&t==="line"?n.find(h=>h.group==="Wafer")?.field??n[0]?.field:n[0]?.field;u&&!(i==="x"&&t==="histogram")&&(e.fields[i]=u,F[i]=u)}}),O()}function te(){const t=!!a.fields.y&&"builtin"in a.fields.y&&a.fields.y.builtin==="yield",e=[{value:A,label:"Automatic"},...["mean","median","min","max","sum","count"].map(n=>({value:n,label:Q[n]}))];t&&e.push({value:"yield",label:Q.yield});const i=X(e,a.aggregate??A,n=>y(o=>{n===A?delete o.aggregate:o.aggregate=n}),{maxWidth:"100%",ownerDocument:r,ariaLabel:"Combine values by",hook:"plot-aggregate"});return i.style.width="100%",i}function ie(){const t=a.fields.color,e=d.followLabel(),i=[{value:Y,label:e?`Follow Group by (${e})`:"Follow Group by (single colour)",group:"Colour"},{value:z,label:"None",group:"Colour"},...I("color")],n=t===void 0||"follow"in t?Y:"none"in t?z:k(t),o=X(i,n,l=>{y(s=>{if(l===Y)delete s.fields.color;else if(l===z)s.fields.color={none:!0};else{const u=H(l);u&&(s.fields.color=u)}})},{maxWidth:"100%",ownerDocument:r,ariaLabel:"Colour",searchPlaceholder:"Filter fields\u2026",hook:"plot-color"});return o.style.width="100%",o}function J(t,e,i,n){const o=r.createElement("input");return o.type="text",o.value=t,o.placeholder=e,o.setAttribute("aria-label",i),Object.assign(o.style,inputStyle(),{width:"100%"}),o.addEventListener("input",()=>n(o.value)),o.addEventListener("keydown",l=>{l.key==="Escape"&&(l.stopPropagation(),o.blur())}),o}function W(t,e,i){const n=r.createElement("input");n.type="text",n.inputMode="decimal",n.value=t===void 0?"":String(t),n.placeholder="auto",n.setAttribute("aria-label",e),Object.assign(n.style,inputStyle(),{width:"100%",fontVariantNumeric:"tabular-nums"});const o=()=>{const l=n.value.trim();if(l===""){i(void 0);return}const s=Number(l);Number.isFinite(s)?i(s):n.value=t===void 0?"":String(t)};return n.addEventListener("change",o),n.addEventListener("keydown",l=>{l.key==="Enter"&&o(),l.key==="Escape"&&(l.stopPropagation(),n.value=t===void 0?"":String(t),n.blur())}),n}function U(t,e,i,n){const o=a.axes?.[t]??{},l=g=>y(f=>{f.axes=f.axes??{};const E=f.axes[t]=f.axes[t]??{};g(E);for(const j of Object.keys(E))(E[j]===void 0||E[j]===""||j==="reverse"&&E[j]===!1)&&delete E[j];Object.keys(E).length===0&&delete f.axes[t],Object.keys(f.axes).length===0&&delete f.axes}),s=r.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:b.md,padding:b.lg,border:`1px solid ${m.menuBorder}`,borderRadius:V.control});const u=r.createElement("div");u.textContent=e,Object.assign(u.style,{fontSize:S.body,fontWeight:"600",color:m.value}),s.appendChild(u);const h=J(o.label??"",i??"",`${e} title`,g=>l(f=>{f.label=g.trim()===""?void 0:g}));if(h.dataset.wmapPlotAxisTitle=t,s.appendChild(c("Title",h)),n.limits===!1)return s;const C=r.createElement("div");return Object.assign(C.style,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:b.md}),C.append(c("Minimum",W(o.min,`${e} minimum`,g=>l(f=>{f.min=g}))),c("Maximum",W(o.max,`${e} maximum`,g=>l(f=>{f.max=g})))),s.appendChild(C),n.scale&&s.appendChild(c("Scale",N([["linear","Linear"],["log","Log"]],o.scale??"linear",g=>l(f=>{f.scale=g==="log"?"log":void 0}),r))),s.appendChild(re("Reverse direction",!!o.reverse,g=>l(f=>{f.reverse=g}),r)),s}const ne=t=>x.querySelector(`[role="tab"][data-tab="${t}"]`);let L,v;const R=new Map;function M(){if(!v)return;const t=oe(ae(a,d.catalogue));if(v.replaceChildren(),v.style.display=t?"flex":"none",!t)return;const e=r.createElement("span");e.textContent=t;const i=r.createElement("button");i.type="button",i.textContent="Use the automatic title",i.dataset.wmapPlotAutoTitle="1",Object.assign(i.style,K("outlined")),_(i),i.addEventListener("click",()=>{y(n=>{delete n.title}),O()}),v.append(e,i)}function O(){x.replaceChildren(),R.clear();const t=r.createElement("div");t.setAttribute("role","tablist"),Object.assign(t.style,{display:"flex",gap:b.sm,borderBottom:`1px solid ${m.menuBorder}`});for(const[i,n,o]of[["setup","Setup","Which fields to plot and how they are combined"],["customise","Customise","Titles, axis limits, scale and direction"]]){const l=r.createElement("button");l.type="button",l.textContent=n,se(l,o),l.setAttribute("role","tab"),l.dataset.tab=i,l.setAttribute("aria-selected",String(p===i)),Object.assign(l.style,{...K("bare"),padding:`${b.sm} ${b.lg}`,fontSize:S.body,borderBottom:`2px solid ${p===i?m.iconActive:"transparent"}`,borderRadius:"0",color:p===i?m.iconActive:m.text,fontWeight:p===i?"600":"400"}),_(l,"bare"),l.tabIndex=p===i?0:-1,l.addEventListener("click",()=>{p=i,O()}),l.addEventListener("keydown",s=>{s.key!=="ArrowLeft"&&s.key!=="ArrowRight"||(s.preventDefault(),p=i==="setup"?"customise":"setup",O(),ne(p)?.focus())}),t.appendChild(l)}x.appendChild(t);const e=r.createElement("div");if(e.setAttribute("role","tabpanel"),Object.assign(e.style,{display:"flex",flexDirection:"column",gap:b.lg}),p==="setup"){e.appendChild(c("Chart type",N(ce,a.chart,n=>ee(n),r,!0)));const i=a.level==="wafer"?"wafers":"dies";switch(a.chart){case"scatter":e.appendChild(c("X axis",w("x","X axis"))),e.appendChild(c("Y axis",w("y","Y axis")));break;case"histogram":e.appendChild(c("Values",w("y","Values")));break;case"box":e.appendChild(c("Categories (X axis)",w("x","Categories"),"Compare by this field: one box per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell).")),e.appendChild(c("Values (Y axis)",w("y","Values")));break;case"bar":e.appendChild(c("Categories (X axis)",w("x","Categories"),"Compare by this field: one bar per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell).")),e.appendChild(c("Values (Y axis)",w("y","Values",{optional:`Count of ${i}`})));break;case"line":e.appendChild(c("X axis",w("x","X axis"),"A line joins the value at each X.")),e.appendChild(c("Y axis",w("y","Y axis")));break}e.appendChild(c("Colour",ie(),"Compare by this field: each value gets its own colour. Follow Group by takes it from the Group by control.")),(a.chart==="bar"||a.chart==="line"||a.level==="wafer")&&e.appendChild(c("Combine values by",te())),e.appendChild(c("One mark per",N([[A,"Automatic"],["die","Die"],["wafer","Wafer"]],a.level??A,n=>{y(o=>{n===A?delete o.level:o.level=n}),O()},r,!0),a.level==="wafer"?"Die-level values are combined per wafer.":"Automatic uses the finest level the chosen fields allow."))}else{L=J(a.title??"",d.autoText().title,"Plot title",l=>{y(s=>{l.trim()===""?delete s.title:Object.assign(s,{title:l})}),M()}),L.dataset.wmapPlotTitle="1",v=r.createElement("div"),v.dataset.wmapPlotTitleDrift="1",Object.assign(v.style,{display:"none",flexDirection:"column",gap:b.sm,alignItems:"flex-start",padding:`${b.sm} ${b.md}`,background:m.warnBg,border:`1px solid ${m.warnBorder}`,borderRadius:V.control,color:m.warnText,fontSize:S.body}),e.appendChild(c("Title",L)),e.appendChild(v),M();const i=d.autoText(),n=a.chart==="box"||a.chart==="bar";e.appendChild(U("x",a.chart==="histogram"?"Values axis":n?"Categories axis":"X axis",i.x,{scale:!n,limits:!n})),e.appendChild(U("y",a.chart==="histogram"?"Count axis":n||a.chart==="line"?"Values axis":"Y axis",i.y,{scale:a.chart!=="histogram"})),a.chart==="histogram"&&e.appendChild(c("Bins",W(a.bins,"Number of bins",l=>y(s=>{l===void 0||!Number.isInteger(l)||l<1?delete s.bins:s.bins=Math.min(l,200)})),"Automatic is 16 equal bins."));const o=a.fields??{};(o.x&&"test"in o.x||o.y&&"test"in o.y)&&e.appendChild(c("Limits",N([["both","Test + spec"],["test","Test"],["spec","Spec"],["none","None"]],a.limits??"both",l=>y(s=>{l==="both"?delete s.limits:s.limits=l}),r),"Drawn as dashed lines on the axis of a test that has them: short dashes for test limits, long for spec limits."));for(const l of e.querySelectorAll("[data-wmap-plot-axis-title]"))R.set(l.dataset.wmapPlotAxisTitle,l)}x.appendChild(e)}return O(),{el:x,setPlot(t){const e=B(t);JSON.stringify(e)!==JSON.stringify(a)&&(a=e,O())},refreshAuto(){const t=d.autoText();L&&(L.placeholder=t.title),M();for(const[e,i]of R)i.placeholder=(e==="x"?t.x:t.y)??""}}}
1
+ import{combinationIssue as $e,describeTitleDrift as je,fieldKey as N,fieldsForRole as ge,titleDrift as Pe,withTestSetNames as ye}from"../stats/plotData.js";import{isBinned as $,isField as U,isPassRateSet as We,isTestSet as P,sameField as j,xFieldsOf as Re,PLOT_BINS_DEFAULT as re,PLOT_BINS_MAX as Be,PLOT_BINS_MIN as De,PLOT_X_LEVELS as ce}from"../stats/plotSpec.js";import{formatTestList as Fe,parseTestList as Ie}from"../stats/sweepText.js";import{formatReferences as ze,parseReferences as Me}from"../stats/plotReferences.js";import{CLR as S,FONT as D,RADIUS as we,SPACE as C,controlStyle as K,wireControlHover as Q,wireTooltip as de}from"./toolbar.js";import{inputStyle as Z,makeListSelect as _,makeSegmented as T,makeToggle as Y}from"./charts/chartShell.js";export{Z as inputStyle};import{buildFilterEditor as Ve}from"./filterEditor.js";const ue="\0follow",z="\0none",Xe=[["scatter","Scatter","One point per die or wafer, one value against another"],["histogram","Histogram","How often each value occurs"],["box","Box","Quartiles, with whiskers to the minimum and maximum, for each category"],["bar","Bar","One combined value for each category, or a count"],["line","Line","One combined value at each X, joined"],["probability","Probability","The share of values at or below each value, one curve per colour: on the normal-probability axis a normal distribution is a straight line, and its tails are spread out to read"],["control","Control","One value per wafer in order, against limits from its own wafer-to-wafer variation, with the points that break a Western Electric rule marked"],["heatmap","Heatmap","One cell per row and column, coloured by the value combined there: tests by wafer, bins by wafer, rings by split"],["goal","Goal","Every test with both limits as a point: how far its mean is off centre, and how wide it is, against lines of equal Ppk"]],y="\0auto",fe="\0count",he="\0set",qe=8,_e=[[y,"None","The values as measured, in their own unit"],["limits","To limits","0 at the low limit and 1 at the high one, each test by its own limits (spec limits where it has both)"],["zscore","z-score","Standard deviations from the mean of the values in view, each test on its own"],["robust","Robust z","Like a z-score, from the median and the median absolute deviation, so a few outliers do not set the scale"]],xe={mean:"Mean",median:"Median",min:"Minimum",max:"Maximum",sum:"Sum",count:"Count",yield:"Pooled yield (passing over judged dies)"};export function fieldRow(x,f,G,l){const A=x.createElement("div");Object.assign(A.style,{display:"flex",flexDirection:"column",gap:C.xxs,minWidth:"0"});const k=x.createElement("div");if(k.textContent=f,Object.assign(k.style,{fontSize:D.sub,color:S.label,fontWeight:"600"}),A.append(k,G),l){const M=x.createElement("div");M.textContent=l,Object.assign(M.style,{fontSize:D.sub,color:S.label}),A.appendChild(M)}return A}export function createPlotEditor(x){const{doc:f}=x,G=e=>e.fields?e:{...e,fields:{}};let l=G(x.plot),A="setup";const k=f.createElement("div");k.dataset.wmapPlotEditor="1",Object.assign(k.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const M=e=>{l=e,x.onChange(e)},b=e=>{const t=JSON.parse(JSON.stringify(l));e(t),M(t)},h=(e,t,i)=>fieldRow(f,e,t,i),H=e=>{if(P(e))return{label:"Tests",level:"die",kind:"numeric",yield:!1};const t=e&&x.catalogue.find(i=>j(i.field,$(e)?e.binned:e));return t?{label:t.name,level:t.level,kind:e&&$(e)?"categorical":t.kind,yield:!(e&&$(e))&&"builtin"in t.field&&t.field.builtin==="yield"}:void 0},E=(e=l)=>[...Re(e.fields?.x)],I=(e,t)=>{t.length===0?delete e.fields.x:e.fields.x=t.length===1?t[0]:t},ve=e=>{const t=e.map(H).filter(i=>!!i);return t.find(i=>i.level==="die")??t[0]};function pe(e,t,i=0){const s=l.fields??{},a=s.color&&!("follow"in s.color)&&!("none"in s.color)?s.color:void 0,o=E();e==="x"&&(o[i]=t.field);const c={x:ve(o),y:H(s.y),color:H(a)};e!=="x"&&(c[e]=H(t.field));const n=l.chart==="scatter"&&c.color?.kind==="numeric"&&!!a&&!("meta"in a);return $e(l.chart,c,{aggregate:l.aggregate,level:l.level,continuousColor:n})?.short}const ee=()=>x.catalogue.flatMap(e=>e.group==="Tests"&&"test"in e.field?[{testNumber:e.field.test,name:e.field.name??""}]:[]),F=()=>P(l.fields?.y)?l.fields.y:void 0,V=e=>!!e&&"builtin"in e&&e.builtin==="test",te=(e,t=0)=>{const i=e==="x"?E()[t]:l.fields?.[e],s=i&&!("follow"in i)&&!("none"in i)?i:void 0,a=e==="x"?E().filter((c,n)=>n!==t):[],o=ge(x.catalogue,l.chart,e).filter(c=>(F()||!V(c.field))&&!a.some(n=>j(n,c.field))).map(c=>{const n=s&&j(c.field,s)?void 0:pe(e,c,t);return{value:N(c.field),label:c.label,group:c.group,...n?{disabled:n}:{}}});return e==="y"?o:[...o,...ie(e,t)]},ie=(e,t=0)=>{if(e==="x"&&!(l.chart==="box"||l.chart==="bar"||l.chart==="heatmap"))return[];if(e==="color"&&l.chart==="scatter")return[];const i=[...e==="x"?E().filter((s,a)=>a!==t):E(),...l.fields?.color&&U(l.fields.color)?[l.fields.color]:[]];return x.catalogue.filter(s=>s.kind==="numeric"&&!s.categorical&&s.group!=="Pass rates"&&!P(s.field)&&!i.some(a=>j(a,s.field))).map(s=>{const a={binned:s.field},o=e==="facet"&&s.level==="die"&&l.level==="wafer"?`${s.name} is per die: this plot has one mark per wafer`:e==="x"||e==="color"?pe(e,{...s,field:a,kind:"categorical",categorical:!0},t):void 0;return{value:N(a),label:`${s.label} in ranges`,group:s.group,...o?{disabled:o}:{}}})},X=e=>{const t=x.catalogue.find(s=>N(s.field)===e)?.field;if(t||!e.startsWith("binned:"))return t;const i=x.catalogue.find(s=>N({binned:s.field})===e)?.field;return i?{binned:i}:void 0};function J(e,t,i,s){if(!t||!$(t))return e;const a=f.createElement("div");Object.assign(a.style,{display:"flex",flexDirection:"column",gap:C.xs,minWidth:"0"});const o=f.createElement("div");Object.assign(o.style,{display:"flex",gap:C.sm,alignItems:"center",minWidth:"0"});const c=R(t.bins??re,"Number of ranges",u=>{const d=u===void 0?re:Math.round(u);b(p=>s(p,g=>{d===re?delete g.bins:g.bins=Math.min(Be,Math.max(De,d))})),O()});c.dataset.wmapPlotBins=i,c.style.width="64px";const n=f.createElement("span");n.textContent="ranges",Object.assign(n.style,{fontSize:D.sub,color:S.label});const r=T([["count","Equal counts","Each range holds about the same number of values (quartiles, deciles)"],["width","Equal widths","Each range spans the same width of values"]],t.by??"count",u=>b(d=>s(d,p=>{u==="count"?delete p.by:p.by="width"})),f);return o.append(c,n,r),a.append(e,o),a}function L(e,t,i={}){const s=i.at??0,a=e==="x"?E()[s]:l.fields.y,o=te(e,s);if(i.optional&&o.unshift({value:fe,label:i.optional,group:"Count"}),e==="y"&&l.chart!=="scatter"&&ee().length>=2&&o.unshift({value:he,label:"Several tests\u2026",group:"Several tests"}),a&&!P(a)&&!o.some(u=>u.value===N(a))){const u=x.catalogue.some(p=>j(p.field,a)),d="test"in a?a.name??`Test ${a.test}`:"meta"in a?a.meta:"builtin"in a?a.builtin:"";o.unshift({value:N(a),label:`${d} (${u?"not usable here":"not in this lot"})`,group:"Saved"})}const n=a?P(a)?he:N(a):i.optional?fe:"",r=_(o,n,u=>{if(u===fe){b(g=>{delete g.fields[e]});return}if(u===he){F()||(Ce(),O());return}const d=X(u)??a;if(!d)return;const p=e==="y"&&!!F();b(g=>{if(e==="x"){const v=E(g);v[s]=d,I(g,v)}else g.fields.y=d;if(!p)return;const w=E(g),m=w.filter(v=>!V(v));m.length!==w.length&&I(g,m.length||!(g.chart==="box"||g.chart==="bar")?m:[{builtin:"wafer"}]),V(g.fields.color)&&delete g.fields.color}),(p||$(d)||a&&$(a))&&O()},{maxWidth:"100%",ownerDocument:f,ariaLabel:t,emptyText:"Choose a field\u2026",searchPlaceholder:"Filter fields\u2026",hook:e==="x"&&s>0?`plot-x-${s+1}`:`plot-${e}`});return r.style.width="100%",r}function Ce(){const e=ee(),t=ye({tests:e.slice(0,qe).map(i=>i.testNumber)},e);b(i=>{i.fields.y=t;const s=E(i);(i.chart==="box"||i.chart==="bar")&&(s.length===0||s.length===1&&j(s[0],{builtin:"wafer"}))&&(i.fields.x={builtin:"test"})})}function Ee(e){const t=f.createElement("div");Object.assign(t.style,{display:"flex",flexDirection:"column",gap:C.xxs});const i=f.createElement("input");i.type="text",i.value=Fe(e.tests),i.placeholder="1010, 1011, 1020..1030",i.setAttribute("aria-label","Tests"),i.dataset.wmapPlotTests="1",Object.assign(i.style,Z(),{width:"100%",fontVariantNumeric:"tabular-nums"});const s=f.createElement("div");return s.setAttribute("role","alert"),Object.assign(s.style,{fontSize:D.sub,color:S.errText}),i.addEventListener("input",()=>{const a=Ie(i.value),o=a.ok?a.value.length===0?"Name at least one test":void 0:a.error;if(s.textContent=o??"",i.setAttribute("aria-invalid",String(!!o)),i.style.borderColor=o?S.errText:S.menuBorder,o||!a.ok)return;const c=a.value;b(n=>{n.fields.y=ye({tests:c},ee())})}),i.addEventListener("keydown",a=>{a.key==="Escape"&&(a.stopPropagation(),i.blur())}),t.append(i,s),t}function me(){const e=E(),t=f.createElement("div");t.dataset.wmapPlotLevels="1",Object.assign(t.style,{display:"flex",flexDirection:"column",gap:C.xs,minWidth:"0"});const i=d=>{const p=e[d];return(p&&x.catalogue.find(g=>j(g.field,p))?.name)??`level ${d+1}`},s=(d,p,g,w,m)=>{const v=f.createElement("button");return v.type="button",v.textContent=d,v.setAttribute("aria-label",p),v.dataset.wmapPlotLevel=g,v.disabled=w,de(v,p),Object.assign(v.style,K("outlined"),{minWidth:"28px",opacity:w?"0.4":"1"}),Q(v),v.addEventListener("click",m),v},a=(...d)=>{O();for(const p of d){const g=k.querySelector(`[data-wmap-plot-level="${p}"]`);if(g&&!g.disabled){g.focus();return}}},o=(d,p)=>{b(w=>{const m=E(w);[m[d],m[d+p]]=[m[d+p],m[d]],I(w,m)});const g=d+p;a(`${p<0?"out":"in"}:${g}`,`${p<0?"in":"out"}:${g}`)},c=Math.max(1,e.length);for(let d=0;d<c;d++){const p=f.createElement("div");Object.assign(p.style,{display:"flex",gap:C.xs,alignItems:"center",minWidth:"0"});const g=J(L("x",c>1?`Categories, level ${d+1} of ${c}`:"Categories",{at:d}),e[d],`x-${d+1}`,(w,m)=>{const v=E(w),W=v[d];W&&$(W)&&(m(W),I(w,v))});Object.assign(g.style,{flex:"1",minWidth:"0"}),p.appendChild(g),e.length>1&&p.append(s("\u2191",`Move ${i(d)} out a level`,`out:${d}`,d===0,()=>o(d,-1)),s("\u2193",`Move ${i(d)} in a level`,`in:${d}`,d===e.length-1,()=>o(d,1)),s("\xD7",`Remove ${i(d)} from the categories`,`remove:${d}`,!1,()=>{b(w=>{const m=E(w);m.splice(d,1),I(w,m)}),a(`remove:${Math.min(d,e.length-2)}`),e.length-1<2&&k.querySelector('[data-wmap-select="plot-x"]')?.focus()})),t.appendChild(p)}const n=e.length<ce&&e.length>0?te("x",e.length).find(d=>!d.disabled):void 0,r=f.createElement("button");r.type="button",r.textContent="+ Add a level",r.dataset.wmapPlotLevelAdd="1",r.disabled=!n;const u=e.length>=ce?`At most ${ce} levels`:n?"Divide each category by another field, nested inside it":"No other field can divide these categories";return de(r,u),Object.assign(r.style,K("outlined"),{alignSelf:"flex-start",opacity:r.disabled?"0.4":"1"}),Q(r),r.addEventListener("click",()=>{const d=n&&X(n.value);d&&(b(p=>{I(p,[...E(p),d])}),O(),k.querySelector(`[data-wmap-select="plot-x-${e.length+1}"]`)?.focus())}),t.appendChild(r),t}const ae={},se={};function Oe(e){b(t=>{t.chart=e;for(const i of["x","y"]){const s=ge(x.catalogue,e,i),a=u=>!!u&&(P(u)?i==="y"&&e!=="scatter":$(u)?i==="x"&&(e==="box"||e==="bar"||e==="heatmap"):s.some(d=>j(d.field,u))),o=u=>Array.isArray(u)?(e==="box"||e==="bar")&&u.every(a):a(u),c=t.fields[i];if(c&&!o(c)&&((Array.isArray(c)||!j(c,se[i]))&&(ae[i]=c),delete t.fields[i]),t.fields[i]||i==="y"&&(e==="bar"||e==="goal"||e==="heatmap"))continue;const n=ae[i];if(o(n)){i==="x"?t.fields.x=n:t.fields.y=n,delete ae[i],delete se[i];continue}const r=i==="x"&&(e==="box"||e==="bar"||e==="heatmap")?{builtin:"wafer"}:i==="x"&&(e==="line"||e==="control")?s.find(u=>u.group==="Wafer")?.field??s[0]?.field:s[0]?.field;r&&!(i==="x"&&(e==="histogram"||e==="probability"||e==="goal"))&&(t.fields[i]=r,se[i]=r)}}),O()}function Se(){const e=!!l.fields.y&&"builtin"in l.fields.y&&l.fields.y.builtin==="yield",t=[{value:y,label:"Automatic"},...["mean","median","min","max","sum","count"].map(s=>({value:s,label:xe[s]}))];e&&t.push({value:"yield",label:xe.yield});const i=_(t,l.aggregate??y,s=>b(a=>{s===y?delete a.aggregate:a.aggregate=s}),{maxWidth:"100%",ownerDocument:f,ariaLabel:"Combine values by",hook:"plot-aggregate"});return i.style.width="100%",i}function Te(){const e=l.fields.color,t=x.followLabel(),i=[{value:ue,label:t?`Follow Group by (${t})`:"Follow Group by (single colour)",group:"Colour"},{value:z,label:"None",group:"Colour"},...te("color")],s=e===void 0||"follow"in e?ue:"none"in e?z:N(e),a=_(i,s,o=>{b(c=>{if(o===ue)delete c.fields.color;else if(o===z)c.fields.color={none:!0};else{const n=X(o);n&&(c.fields.color=n)}}),(o.startsWith("binned:")||s.startsWith("binned:"))&&O()},{maxWidth:"100%",ownerDocument:f,ariaLabel:"Colour",searchPlaceholder:"Filter fields\u2026",hook:"plot-color"});return a.style.width="100%",J(a,e&&U(e)?e:void 0,"color",(o,c)=>{const n=o.fields.color;n&&U(n)&&$(n)&&c(n)})}function Ae(){const e=l.fields.rows,t=x.catalogue.filter(a=>a.categorical&&!E().some(o=>j(o,a.field))&&(!V(a.field)||F())).map(a=>({value:N(a.field),label:a.label,group:a.group}));t.push(...ie("rows"));const i=e?N(e):F()?N({builtin:"test"}):"",s=_(t,i,a=>{const o=X(a);o&&(b(c=>{c.fields.rows=o}),(a.startsWith("binned:")||i.startsWith("binned:"))&&O())},{maxWidth:"100%",ownerDocument:f,ariaLabel:"Rows",emptyText:"Choose a field\u2026",searchPlaceholder:"Filter fields\u2026",hook:"plot-rows"});return s.style.width="100%",J(s,e,"rows",(a,o)=>{const c=a.fields.rows;c&&$(c)&&o(c)})}function ke(){const e=l.fields.facet,t=[...E(),...l.fields.color&&U(l.fields.color)?[l.fields.color]:[]],i=[{value:z,label:"None: one plot",group:"Panels"}];for(const o of x.catalogue){if(!o.categorical||t.some(n=>j(n,o.field))||V(o.field)&&!F())continue;const c=o.level==="die"&&l.level==="wafer"?`${o.name} is per die: this plot has one mark per wafer`:void 0;i.push({value:N(o.field),label:o.label,group:o.group,...c?{disabled:c}:{}})}i.push(...ie("facet"));const s=e?N(e):z,a=_(i,s,o=>{b(c=>{if(o===z)delete c.fields.facet;else{const n=X(o);n&&(c.fields.facet=n)}}),(o.startsWith("binned:")||s.startsWith("binned:"))&&O()},{maxWidth:"100%",ownerDocument:f,ariaLabel:"Panels",searchPlaceholder:"Filter fields\u2026",hook:"plot-facet"});return a.style.width="100%",J(a,e,"facet",(o,c)=>{const n=o.fields.facet;n&&$(n)&&c(n)})}function Le(){const e=Ve({doc:f,catalogue:x.catalogue,filter:l.where,testDefs:x.testDefs,attributes:x.attributes,switchLabel:"Filter this plot",valuesOf:t=>x.valuesOf?.(t)??[],extentOf:t=>x.extentOf?.(t),onChange:t=>b(i=>{t?i.where=t:delete i.where})});return e.el.dataset.wmapPlotWhere="1",e.el}function ne(e,t,i,s){const a=f.createElement("input");return a.type="text",a.value=e,a.placeholder=t,a.setAttribute("aria-label",i),Object.assign(a.style,Z(),{width:"100%"}),a.addEventListener("input",()=>s(a.value)),a.addEventListener("keydown",o=>{o.key==="Escape"&&(o.stopPropagation(),a.blur())}),a}function R(e,t,i){const s=f.createElement("input");s.type="text",s.inputMode="decimal",s.value=e===void 0?"":String(e),s.placeholder="auto",s.setAttribute("aria-label",t),Object.assign(s.style,Z(),{width:"100%",fontVariantNumeric:"tabular-nums"});const a=()=>{const o=s.value.trim();if(o===""){i(void 0);return}const c=Number(o);Number.isFinite(c)?i(c):s.value=e===void 0?"":String(e)};return s.addEventListener("change",a),s.addEventListener("keydown",o=>{o.key==="Enter"&&a(),o.key==="Escape"&&(o.stopPropagation(),s.value=e===void 0?"":String(e),s.blur())}),s}function be(e,t,i,s){const a=l.axes?.[e]??{},o=w=>b(m=>{m.axes=m.axes??{};const v=m.axes[e]=m.axes[e]??{};w(v);for(const W of Object.keys(v))(v[W]===void 0||v[W]===""||W==="reverse"&&v[W]===!1)&&delete v[W];Object.keys(v).length===0&&delete m.axes[e],Object.keys(m.axes).length===0&&delete m.axes}),c=f.createElement("div");Object.assign(c.style,{display:"flex",flexDirection:"column",gap:C.md,padding:C.lg,border:`1px solid ${S.menuBorder}`,borderRadius:we.control});const n=f.createElement("div");n.textContent=t,Object.assign(n.style,{fontSize:D.body,fontWeight:"600",color:S.value}),c.appendChild(n);const r=ne(a.label??"",i??"",`${t} title`,w=>o(m=>{m.label=w.trim()===""?void 0:w}));if(r.dataset.wmapPlotAxisTitle=e,c.appendChild(h("Title",r)),s.limits===!1)return c;const u=f.createElement("div");if(Object.assign(u.style,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:C.md}),u.append(h("Minimum",R(a.min,`${t} minimum`,w=>o(m=>{m.min=w}))),h("Maximum",R(a.max,`${t} maximum`,w=>o(m=>{m.max=w})))),c.appendChild(u),s.scale&&c.appendChild(h("Scale",T([["linear","Linear"],["log","Log"]],a.scale??"linear",w=>o(m=>{m.scale=w==="log"?"log":void 0}),f))),c.appendChild(Y("Reverse direction",!!a.reverse,w=>o(m=>{m.reverse=w}),f)),s.references===!1)return c;const d=ne(ze(a.references),"0.45 Target, 0.3..0.5 Window, median",`${t} reference lines`,w=>{const m=Me(w);if(!m.ok){p.textContent=m.error,d.setAttribute("aria-invalid","true");return}p.textContent="",d.removeAttribute("aria-invalid"),o(v=>{v.references=m.value.length?m.value:void 0})});d.dataset.wmapPlotRefs=e;const p=f.createElement("div");p.setAttribute("role","alert"),Object.assign(p.style,{fontSize:D.sub,color:S.errText});const g=h("Reference lines",d,"A value for a line, or lo..hi for a shaded band, each with an optional name, in the axis\u2019s own unit.");return g.appendChild(p),c.appendChild(g),c}const Ne=e=>k.querySelector(`[role="tab"][data-tab="${e}"]`);let q,B;const le=new Map;function oe(){if(!B)return;const e=je(Pe(l,x.catalogue));if(B.replaceChildren(),B.style.display=e?"flex":"none",!e)return;const t=f.createElement("span");t.textContent=e;const i=f.createElement("button");i.type="button",i.textContent="Use the automatic title",i.dataset.wmapPlotAutoTitle="1",Object.assign(i.style,K("outlined")),Q(i),i.addEventListener("click",()=>{b(s=>{delete s.title}),O()}),B.append(t,i)}function O(){k.replaceChildren(),le.clear();const e=f.createElement("div");e.setAttribute("role","tablist"),Object.assign(e.style,{display:"flex",gap:C.sm,borderBottom:`1px solid ${S.menuBorder}`});for(const[i,s,a]of[["setup","Setup","Which fields to plot and how they are combined"],["customise","Customise","Titles, axis limits, scale and direction"]]){const o=f.createElement("button");o.type="button",o.textContent=s,de(o,a),o.setAttribute("role","tab"),o.dataset.tab=i,o.setAttribute("aria-selected",String(A===i)),Object.assign(o.style,{...K("bare"),padding:`${C.sm} ${C.lg}`,fontSize:D.body,borderBottom:`2px solid ${A===i?S.iconActive:"transparent"}`,borderRadius:"0",color:A===i?S.iconActive:S.text,fontWeight:A===i?"600":"400"}),Q(o,"bare"),o.tabIndex=A===i?0:-1,o.addEventListener("click",()=>{A=i,O()}),o.addEventListener("keydown",c=>{c.key!=="ArrowLeft"&&c.key!=="ArrowRight"||(c.preventDefault(),A=i==="setup"?"customise":"setup",O(),Ne(A)?.focus())}),e.appendChild(o)}k.appendChild(e);const t=f.createElement("div");if(t.setAttribute("role","tabpanel"),Object.assign(t.style,{display:"flex",flexDirection:"column",gap:C.lg}),A==="setup"){t.appendChild(h("Chart type",T(Xe,l.chart,n=>Oe(n),f,!0)));const i=l.level==="wafer"?"wafers":"dies";switch(l.chart){case"scatter":t.appendChild(h("X axis",L("x","X axis"))),t.appendChild(h("Y axis",L("y","Y axis")));break;case"histogram":t.appendChild(h("Values",L("y","Values")));break;case"control":t.appendChild(h("Along (X axis)",L("x","Along"),"A wafer field with a number per wafer: wafer order, slot, a date.")),t.appendChild(h("Values (Y axis)",L("y","Values"),"One value per wafer: a test\u2019s wafer mean (or as Combine values by says), a yield or a pass rate.")),t.appendChild(h("Limits from the first",R(l.baseline,"Wafers the limits are set from",n=>b(r=>{n===void 0||!Number.isInteger(n)||n<3?delete r.baseline:r.baseline=n})),"Wafers, at least 3. Empty sets the limits from every wafer."));break;case"heatmap":t.appendChild(h("Columns (X axis)",L("x","Columns"),"One column per value: wafer, split, site\u2026")),t.appendChild(h("Rows",Ae(),"One row per value. With several tests as the values, Test gives a row per test.")),t.appendChild(h("Values (colour)",L("y","Values",{optional:`Count of ${i}`}),"What each cell\u2019s colour shows, combined over its dies or wafers."));break;case"goal":t.appendChild(h("Tests",L("y","Tests",{optional:"Every test with both limits"}),"Each test with both a low and a high limit is a point. Colour by a split to see it move."));break;case"probability":t.appendChild(h("Values (X axis)",L("y","Values"),"One curve per colour, each value at its share of its group: a shift is a curve moved sideways, a wider spread a flatter one, a second population a bend."));break;case"box":t.appendChild(h("Categories (X axis)",me(),"Compare by this field: one box per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell). Add a level to nest another inside it: the first level is the outer groups.")),t.appendChild(h("Values (Y axis)",L("y","Values")));break;case"bar":t.appendChild(h("Categories (X axis)",me(),"Compare by this field: one bar per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell). Add a level to nest another inside it: the first level is the outer groups.")),t.appendChild(h("Values (Y axis)",L("y","Values",{optional:`Count of ${i}`})));break;case"line":t.appendChild(h("X axis",L("x","X axis"),"A line joins the value at each X.")),t.appendChild(h("Y axis",L("y","Y axis")));break}const s=F();s&&l.chart!=="scatter"&&(t.appendChild(h("Tests",Ee(s),"Test numbers, or a range such as 1010..1030 for the tests declared between them. Put Test on the X axis or the colour to tell them apart.")),(l.chart==="bar"||l.chart==="line")&&t.appendChild(h("Read as",T([[y,"Values","Each test\u2019s measured values"],["passRate","Pass rates","Each test\u2019s share of judged dies that pass it"]],s.passRate?"passRate":y,n=>{b(r=>{const u=r.fields.y;if(!P(u))return;const d={...u};n===y?(delete d.passRate,delete d.judge):(d.passRate=!0,delete r.normalize),r.fields.y=d}),O()},f))));const a=l.fields.y;a&&(We(a)||!P(a)&&"passRate"in a)&&t.appendChild(h("Judged by",T([[y,"Test limits","A parametric test\u2019s measured value against its test limits"],["flag","Tester flag","The pass or fail the tester recorded for each die"]],a.judge??y,n=>b(r=>{const u={...r.fields.y};n===y?delete u.judge:u.judge="flag",r.fields.y=u}),f),"A functional test is judged by its recorded verdict either way.")),t.appendChild(h("Colour",Te(),"Compare by this field: each value gets its own colour. Follow Group by takes it from the Group by control.")),t.appendChild(h("Filter",Le(),"Keep only the dies that meet every condition: bin 1, the edge ring, a range of a test. A condition on a wafer field (split, yield) keeps whole wafers.")),l.chart==="line"&&t.appendChild(h("Band",T([[y,"None"],["sd","\xB11 SD","Mean \xB1 one standard deviation of the values at each X"],["ci95","95% CI","The mean\u2019s 95% confidence interval (Student\u2019s t)"],["iqr","Quartiles"],["minmax","Range"]],l.spread??y,n=>b(r=>{n===y?delete r.spread:r.spread=n}),f),"Round a line of means or medians.")),t.appendChild(h("Panels",ke(),"One panel per value of this field, on shared axes and colours: split or lot takes whole wafers, ring or site the dies in it.")),l.chart==="scatter"&&(t.appendChild(h("Fit line",T([[y,"None"],["linear","Least squares","Y on X: the usual regression line"],["orthogonal","Orthogonal","Closest to the points at right angles: for two measurements of one quantity (two testers, two insertions)"]],l.fit??y,n=>b(r=>{n===y?delete r.fit:r.fit=n}),f),"One line per colour, with its equation, R\xB2 and n above the chart.")),t.appendChild(Y("y = x line",!!l.identity,n=>b(r=>{n?r.identity=!0:delete r.identity}),f))),l.chart==="histogram"&&(t.appendChild(h("Bars as",T([[y,"Counts"],["percent","Shares","Each colour\u2019s bars as a share of its own values, so groups of different size compare"]],l.histNorm==="percent"?"percent":y,n=>b(r=>{n===y?delete r.histNorm:r.histNorm="percent"}),f))),t.appendChild(Y("Normal curve",!!l.normalCurve,n=>b(r=>{n?r.normalCurve=!0:delete r.normalCurve}),f)));const o=l.fields.y;if((l.chart==="histogram"||l.chart==="probability")&&o&&"test"in o&&!l.normalize){const n=f.createElement("div");Object.assign(n.style,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:C.md});const r=u=>d=>b(p=>{const g={...p.whatIf??{}};d===void 0?delete g[u]:g[u]=d,g.lo===void 0&&g.hi===void 0?delete p.whatIf:p.whatIf=g});n.append(h("Low",R(l.whatIf?.lo,"What-if low limit",r("lo"))),h("High",R(l.whatIf?.hi,"What-if high limit",r("hi")))),t.appendChild(h("What-if limits",n,"In the test\u2019s own unit (V, A\u2026). The line under the plot gives the test\u2019s pass rate now and with these, and the dies that change."))}if(l.chart==="box"||l.chart==="bar"){t.appendChild(h("Orientation",T([[y,"Vertical","Categories along the bottom"],["horizontal","Horizontal","Categories down the left: for many categories or long names"]],l.orientation==="horizontal"?"horizontal":y,r=>b(u=>{r===y?delete u.orientation:u.orientation="horizontal"}),f)));const n=E().length<=1;n&&(t.appendChild(h("Order",T([[y,"Field order","The field\u2019s own order: wafers as loaded, numbers by value, names naturally"],["value","Largest first",l.chart==="box"?"By median, largest first":"By value, largest first (a pareto)"],["ascending","Smallest first",l.chart==="box"?"By median, smallest first":"By value, smallest first (the worst pass rate at the top)"]],l.sort??y,r=>{b(u=>{r===y?(delete u.sort,delete u.cumulative):(u.sort=r,r==="ascending"&&delete u.cumulative)}),O()},f))),t.appendChild(h("Show the first",R(l.top,"Categories shown",r=>b(u=>{r===void 0||!Number.isInteger(r)||r<1?delete u.top:u.top=r})),"Leave empty for every category; the rest are counted in a note."))),l.chart==="bar"&&(t.appendChild(h("Colours",T([[y,"Side by side"],["share","Share of colour","Side by side, each colour as its share of its own total, so groups of different sizes compare"],["stack","Stacked","One bar per category, its colours one on another"],["percent","100%","Each colour as its share of the category"]],l.stack??(l.barNorm==="percent"?"share":y),r=>b(u=>{delete u.stack,delete u.barNorm,r==="share"?u.barNorm="percent":r!==y&&(u.stack=r)}),f),"Shares and stacking add values, so they need a count or a sum.")),n&&l.sort==="value"&&t.appendChild(Y("Cumulative line (pareto)",!!l.cumulative,r=>b(u=>{r?u.cumulative=!0:delete u.cumulative}),f)),t.appendChild(Y("Values on the bars",!!l.valueLabels,r=>b(u=>{r?u.valueLabels=!0:delete u.valueLabels}),f,"Each bar\u2019s value at its end. Shown only when every value fits its bar, so none is left unlabelled.")))}const c=l.fields.y;l.chart!=="scatter"&&c&&(P(c)||"test"in c)&&t.appendChild(h("Rescale values",T(_e,l.normalize??y,n=>{b(r=>{n===y?delete r.normalize:r.normalize=n})},f),s?"Tests in different units share one axis only once they are rescaled.":void 0)),(l.chart==="bar"||l.chart==="line"||l.chart==="control"||l.chart==="heatmap"||l.level==="wafer")&&t.appendChild(h("Combine values by",Se())),t.appendChild(h("One mark per",T([[y,"Automatic"],["die","Die"],["wafer","Wafer"]],l.level??y,n=>{b(r=>{n===y?delete r.level:r.level=n}),O()},f,!0),l.level==="wafer"?"Die-level values are combined per wafer.":"Automatic uses the finest level the chosen fields allow."))}else{q=ne(l.title??"",x.autoText().title,"Plot title",n=>{b(r=>{n.trim()===""?delete r.title:Object.assign(r,{title:n})}),oe()}),q.dataset.wmapPlotTitle="1",B=f.createElement("div"),B.dataset.wmapPlotTitleDrift="1",Object.assign(B.style,{display:"none",flexDirection:"column",gap:C.sm,alignItems:"flex-start",padding:`${C.sm} ${C.md}`,background:S.warnBg,border:`1px solid ${S.warnBorder}`,borderRadius:we.control,color:S.warnText,fontSize:D.body}),t.appendChild(h("Title",q)),t.appendChild(B),oe();const i=x.autoText(),s=l.chart==="box"||l.chart==="bar",a=l.chart==="probability",o=n=>{switch(l.chart){case"scatter":case"line":return!0;case"histogram":case"probability":return n==="x";case"box":case"bar":case"control":return n==="y";default:return!1}};t.appendChild(be("x",l.chart==="histogram"||a?"Values axis":s?"Categories axis":"X axis",i.x,{scale:!s,limits:!s,references:o("x")})),t.appendChild(be("y",l.chart==="histogram"?"Count axis":a?"Cumulative share axis":s||l.chart==="line"?"Values axis":"Y axis",i.y,{scale:l.chart!=="histogram"&&!a,limits:!a,references:o("y")})),a&&t.appendChild(h("Share axis",T([["normal","Normal probability","Shares spaced by the normal quantile: a normal distribution is a straight line"],["linear","Linear","Shares spaced evenly, 0 to 100%"]],l.probabilityAxis??"normal",n=>b(r=>{n==="normal"?delete r.probabilityAxis:r.probabilityAxis="linear"}),f),"Normal probability spreads out the tails, where outliers and a second population show.")),l.chart==="histogram"&&t.appendChild(h("Bins",R(l.bins,"Number of bins",n=>b(r=>{n===void 0||!Number.isInteger(n)||n<1?delete r.bins:r.bins=Math.min(n,200)})),"Automatic is 16 equal bins."));const c=l.fields??{};(c.x&&"test"in c.x||c.y&&("test"in c.y||P(c.y)))&&t.appendChild(h("Limits",T([["both","Test + spec"],["test","Test"],["spec","Spec"],["none","None"]],l.limits??"both",n=>b(r=>{n==="both"?delete r.limits:r.limits=n}),f),"Drawn as dashed lines on the axis of a test that has them: short dashes for test limits, long for spec limits."));for(const n of t.querySelectorAll("[data-wmap-plot-axis-title]"))le.set(n.dataset.wmapPlotAxisTitle,n)}k.appendChild(t)}return O(),{el:k,setPlot(e){const t=G(e);JSON.stringify(t)!==JSON.stringify(l)&&(l=t,O())},refreshAuto(){const e=x.autoText();q&&(q.placeholder=e.title),oe();for(const[t,i]of le)i.placeholder=(t==="x"?e.x:e.y)??""}}}
@@ -1 +1 @@
1
- import{fieldCatalogue as z,resolvePlot as I,plotTitle as $}from"../stats/plotData.js";import{plotToSweep as J}from"../stats/plotSpec.js";import{renderPlotChart as F}from"./charts/plotChart.js";import{renderSweepPanel as H}from"./charts/sweep.js";import{createPlotEditor as M}from"./plotEditor.js";import{createSweepEditor as Y}from"./sweepEditor.js";import{CLR as b,FONT as T,SPACE as i,controlStyle as B,openReparentedModal as q,wireControlHover as L}from"./toolbar.js";export function openPlotEditor(e){const{doc:n,store:c}=e;let o=e.plot,a=!e.draft;const W=z(e.items,e.ctx),h=t=>I(t,e.items,e.ctx),p=n.createElement("div");p.dataset.wmapPlotWindow="1",Object.assign(p.style,{display:"flex",flexWrap:"wrap",gap:i.xxl,alignItems:"flex-start",width:"100%",boxSizing:"border-box",padding:i.xl});const f=n.createElement("div");if(Object.assign(f.style,{flex:"3 1 420px",minWidth:"0",display:"flex",flexDirection:"column",gap:i.md}),e.population){const t=n.createElement("div");t.textContent=`Population: ${e.population}`,t.dataset.wmapPopulation="1",Object.assign(t.style,{color:b.label,fontSize:T.body}),f.appendChild(t)}const w=o.chart==="sweep";let r;if(w){const t=H({spec:J(o),dies:e.items.flatMap(l=>l.dies),testDefs:e.ctx.testDefs?[...e.ctx.testDefs]:void 0,population:e.rawPopulation??e.population,onSaveImage:e.chart.onSaveImage,onSelectPoint:e.onSelectLevel,ownerDocument:n});r={card:t.card,setPlot:l=>t.setSpec(J(l)),destroy:()=>t.destroy()}}else{const t=F({...e.chart,ownerDocument:n,waferLabel:l=>e.items[l]?.label??""});r={card:t.card,setPlot:l=>t.setPlot(h(l)),destroy:()=>t.destroy()}}r.card.style.alignSelf="stretch",f.appendChild(r.card);const m=n.createElement("div");Object.assign(m.style,{flex:"1 1 300px",minWidth:"260px",maxWidth:"420px",display:"flex",flexDirection:"column",gap:i.lg,maxHeight:"calc(min(92vh, 800px) - 110px)",overflowY:"auto",paddingRight:i.sm});const C=t=>{o=t,a&&c.upsert(t),y()},u=w?{...Y({doc:n,plot:o,testDefs:e.ctx.testDefs,onChange:C}),refreshAuto:()=>{}}:M({doc:n,plot:o,catalogue:W,followLabel:()=>e.groupLabel??(e.items.length>1?"a colour per wafer":void 0),autoText:()=>{const t=h(o);return{title:t.autoTitle,x:t.x?.label,y:t.y?.label}},onChange:C});m.appendChild(u.el);const g=n.createElement("div");Object.assign(g.style,{display:"flex",flexDirection:"column",gap:i.sm,color:b.label,fontSize:T.body,position:"sticky",bottom:"0",background:b.menuBg,borderTop:`1px solid ${b.menuBorder}`,paddingTop:i.sm,paddingBottom:i.md});const P=n.createElement("div");g.appendChild(P);const s=n.createElement("button");s.type="button",s.textContent="Add to my plots",s.dataset.wmapPlotAdd="1",Object.assign(s.style,{...B("outlined"),alignSelf:"flex-start"}),L(s),s.addEventListener("click",()=>{a=!0,c.upsert(o),N()});const E=JSON.parse(JSON.stringify(e.plot)),O=(t,l,R)=>{const d=n.createElement("button");return d.type="button",d.textContent=t,d.dataset[l]="1",Object.assign(d.style,B("outlined")),L(d),d.addEventListener("click",R),d},x=O("Reset","wmapPlotReset",()=>D()),k=O("Cancel","wmapPlotCancel",()=>{D(),v?.close()}),S=n.createElement("div");Object.assign(S.style,{display:"flex",gap:i.md,flexWrap:"wrap"}),S.append(x,k,s),g.appendChild(S),m.appendChild(g);const A=()=>JSON.stringify(o)!==JSON.stringify(E);function D(){o=JSON.parse(JSON.stringify(E)),a&&c.upsert(o),u.setPlot(o),y()}function N(){P.textContent=a?`Changes are saved to \u201C${w?o.title??"Sweep":$(h(o))}\u201D.`:"This is a draft: it is not kept until you add it to your plots.",s.style.display=a?"none":"",x.disabled=!A(),x.style.opacity=x.disabled?"0.5":"1"}function y(){r.setPlot(o),u.refreshAuto(),N()}y(),p.append(f,m);const j=c.subscribe(()=>{if(!a)return;const t=c.get().find(l=>l.id===o.id);if(!t){v?.close();return}JSON.stringify(t)!==JSON.stringify(o)&&(o=t,u.setPlot(t),y())}),v=q([p],{title:e.title??(a?"Edit plot":"New plot"),anchor:e.anchor,ownerDocument:n,boxSize:{width:"min(96vw, 1180px)",height:"min(92vh, 800px)"},onClosed:()=>{j(),r.destroy(),e.onClosed?.()}});v||(j(),r.destroy())}
1
+ import{fieldCatalogue as z,fieldValues as H,fieldExtent as I,resolvePlot as $,plotTitle as F}from"../stats/plotData.js";import{plotToSweep as J}from"../stats/plotSpec.js";import{renderPlotChart as M}from"./charts/plotChart.js";import{renderSweepPanel as Y}from"./charts/sweep.js";import{createPlotEditor as V}from"./plotEditor.js";import{createSweepEditor as q}from"./sweepEditor.js";import{CLR as b,FONT as T,SPACE as i,controlStyle as B,openReparentedModal as G,wireControlHover as L}from"./toolbar.js";export function openPlotEditor(e){const{doc:o,store:c}=e;let n=e.plot,a=!e.draft;const W=z(e.items,e.ctx),h=t=>$(t,e.items,e.ctx),p=o.createElement("div");p.dataset.wmapPlotWindow="1",Object.assign(p.style,{display:"flex",flexWrap:"wrap",gap:i.xxl,alignItems:"flex-start",width:"100%",boxSizing:"border-box",padding:i.xl});const f=o.createElement("div");if(Object.assign(f.style,{flex:"3 1 420px",minWidth:"0",display:"flex",flexDirection:"column",gap:i.md,maxHeight:"calc(min(92vh, 800px) - 110px)",overflowY:"auto"}),e.population){const t=o.createElement("div");t.textContent=`Population: ${e.population}`,t.dataset.wmapPopulation="1",Object.assign(t.style,{color:b.label,fontSize:T.body}),f.appendChild(t)}const w=n.chart==="sweep";let r;if(w){const t=Y({spec:J(n),dies:e.items.flatMap(l=>l.dies),testDefs:e.ctx.testDefs?[...e.ctx.testDefs]:void 0,population:e.rawPopulation??e.population,onSaveImage:e.chart.onSaveImage,onSelectPoint:e.onSelectLevel,ownerDocument:o});r={card:t.card,setPlot:l=>t.setSpec(J(l)),destroy:()=>t.destroy()}}else{const t=M({...e.chart,ownerDocument:o,waferLabel:l=>e.items[l]?.label??""});r={card:t.card,setPlot:l=>t.setPlot(h(l)),destroy:()=>t.destroy()}}r.card.style.alignSelf="stretch",f.appendChild(r.card);const m=o.createElement("div");Object.assign(m.style,{flex:"1 1 300px",minWidth:"260px",maxWidth:"420px",display:"flex",flexDirection:"column",gap:i.lg,maxHeight:"calc(min(92vh, 800px) - 110px)",overflowY:"auto",paddingRight:i.sm});const C=t=>{n=t,a&&c.upsert(t),y()},u=w?{...q({doc:o,plot:n,testDefs:e.ctx.testDefs,onChange:C}),refreshAuto:()=>{}}:V({doc:o,plot:n,catalogue:W,followLabel:()=>e.groupLabel??(e.items.length>1?"a colour per wafer":void 0),autoText:()=>{const t=h(n);return{title:t.autoTitle,x:t.x?.label,y:t.y?.label}},onChange:C,valuesOf:t=>H(t,e.items,e.ctx),extentOf:t=>I(t,e.items,e.ctx),testDefs:e.ctx.testDefs,attributes:e.ctx.curation});m.appendChild(u.el);const x=o.createElement("div");Object.assign(x.style,{display:"flex",flexDirection:"column",gap:i.sm,color:b.label,fontSize:T.body,position:"sticky",bottom:"0",background:b.menuBg,borderTop:`1px solid ${b.menuBorder}`,paddingTop:i.sm,paddingBottom:i.md});const P=o.createElement("div");x.appendChild(P);const s=o.createElement("button");s.type="button",s.textContent="Add to my plots",s.dataset.wmapPlotAdd="1",Object.assign(s.style,{...B("outlined"),alignSelf:"flex-start"}),L(s),s.addEventListener("click",()=>{a=!0,c.upsert(n),N()});const O=JSON.parse(JSON.stringify(e.plot)),E=(t,l,R)=>{const d=o.createElement("button");return d.type="button",d.textContent=t,d.dataset[l]="1",Object.assign(d.style,B("outlined")),L(d),d.addEventListener("click",R),d},g=E("Reset","wmapPlotReset",()=>D()),k=E("Cancel","wmapPlotCancel",()=>{D(),v?.close()}),S=o.createElement("div");Object.assign(S.style,{display:"flex",gap:i.md,flexWrap:"wrap"}),S.append(g,k,s),x.appendChild(S),m.appendChild(x);const A=()=>JSON.stringify(n)!==JSON.stringify(O);function D(){n=JSON.parse(JSON.stringify(O)),a&&c.upsert(n),u.setPlot(n),y()}function N(){P.textContent=a?`Changes are saved to \u201C${w?n.title??"Sweep":F(h(n))}\u201D.`:"This is a draft: it is not kept until you add it to your plots.",s.style.display=a?"none":"",g.disabled=!A(),g.style.opacity=g.disabled?"0.5":"1"}function y(){r.setPlot(n),u.refreshAuto(),N()}y(),p.append(f,m);const j=c.subscribe(()=>{if(!a)return;const t=c.get().find(l=>l.id===n.id);if(!t){v?.close();return}JSON.stringify(t)!==JSON.stringify(n)&&(n=t,u.setPlot(t),y())}),v=G([p],{title:e.title??(a?"Edit plot":"New plot"),anchor:e.anchor,ownerDocument:o,boxSize:{width:"min(96vw, 1180px)",height:"min(92vh, 800px)"},onClosed:()=>{j(),r.destroy(),e.onClosed?.()}});v||(j(),r.destroy())}
@@ -1 +1 @@
1
- import{sweepToPlot as O}from"../stats/plotSpec.js";import{newPlotId as g}from"../stats/plotId.js";import{noticeOnce as x}from"../renderer/deprecate.js";export function copyTitle(i,m){const l=i.replace(/(?:\s*\(copy(?: \d+)?\))+$/,"")||i,r=new Set(m);let d=`${l} (copy)`;for(let f=2;r.has(d);f++)d=`${l} (copy ${f})`;return d}export function plotStoreFor(i){return createPlotStore(i?.plots,i?.onPlotsChange,void 0,{sweeps:i?.sweeps,onRemove:i?.onRemoveSweeps})}export function createPlotStore(i,m,l=400,r){const d=new Set((i??[]).map(e=>e.id)),f=(r?.sweeps??[]).filter(e=>!d.has(e.id));(r?.sweeps?.length??0)>0&&x("insights.sweeps","`insights.sweeps` is deprecated: sweeps are plots now. Pass them in `insights.plots` as sweep plots (readPlotsFile reads a sweeps file), which the Plot tab can also save and share.");const h=new Set((r?.sweeps??[]).map(e=>e.id));let t=[...i??[],...f.map(O)].map(e=>JSON.parse(JSON.stringify(e)));const u=new Set;let p,w=!1;const S=()=>{p!==void 0&&(clearTimeout(p),p=void 0),w&&(w=!1,m?.(t.map(e=>JSON.parse(JSON.stringify(e)))))},a=()=>{for(const e of[...u])e();w=!0,p!==void 0&&clearTimeout(p),p=setTimeout(S,l)};return{get:()=>t,upsert(e){const s=t.findIndex(n=>n.id===e.id);t=s<0?[...t,e]:t.map((n,o)=>o===s?e:n),a()},insertAt(e,s){const n=Math.max(0,Math.min(e,t.length));t=[...t.slice(0,n),s,...t.slice(n)],a()},remove(e){const s=t.findIndex(o=>o.id===e);if(s<0)return;const n=t[s];return t=t.filter((o,c)=>c!==s),a(),h.has(e)&&r?.onRemove?.([e]),{plot:n,index:s}},duplicate(e){const s=t.findIndex(c=>c.id===e);if(s<0)return;const n=t[s],o=JSON.parse(JSON.stringify(n));return o.id=g(),n.title&&Object.assign(o,{title:copyTitle(n.title,t.map(c=>c.title))}),t=[...t.slice(0,s+1),o,...t.slice(s+1)],a(),o},replaceAll(e){const s=[...h].filter(n=>t.some(o=>o.id===n)&&!e.some(o=>o.id===n));t=e.map(n=>JSON.parse(JSON.stringify(n))),a(),s.length>0&&r?.onRemove?.(s)},subscribe(e){return u.add(e),()=>{u.delete(e)}},flush:S}}
1
+ import{sweepToPlot as O}from"../stats/plotSpec.js";import{newPlotId as g}from"../stats/plotId.js";import{noticeOnce as x}from"../renderer/deprecate.js";export function copyTitle(i,m){const l=i.replace(/(?:\s*\(copy(?: \d+)?\))+$/,"")||i,r=new Set(m);let d=`${l} (copy)`;for(let f=2;r.has(d);f++)d=`${l} (copy ${f})`;return d}export function plotStoreFor(i){return createPlotStore(i?.plots,i?.onPlotsChange,void 0,{sweeps:i?.sweeps,onRemove:i?.onRemoveSweeps})}export function createPlotStore(i,m,l=400,r){const d=new Set((i??[]).map(e=>e.id)),f=(r?.sweeps??[]).filter(e=>!d.has(e.id));(r?.sweeps?.length??0)>0&&x("insights.sweeps","`insights.sweeps` is deprecated: sweeps are plots now. Pass them in `insights.plots` as sweep plots (readPlotsFile reads a sweeps file), which the My plots tab can also save and share.");const h=new Set((r?.sweeps??[]).map(e=>e.id));let t=[...i??[],...f.map(O)].map(e=>JSON.parse(JSON.stringify(e)));const u=new Set;let p,w=!1;const S=()=>{p!==void 0&&(clearTimeout(p),p=void 0),w&&(w=!1,m?.(t.map(e=>JSON.parse(JSON.stringify(e)))))},a=()=>{for(const e of[...u])e();w=!0,p!==void 0&&clearTimeout(p),p=setTimeout(S,l)};return{get:()=>t,upsert(e){const s=t.findIndex(n=>n.id===e.id);t=s<0?[...t,e]:t.map((n,o)=>o===s?e:n),a()},insertAt(e,s){const n=Math.max(0,Math.min(e,t.length));t=[...t.slice(0,n),s,...t.slice(n)],a()},remove(e){const s=t.findIndex(o=>o.id===e);if(s<0)return;const n=t[s];return t=t.filter((o,c)=>c!==s),a(),h.has(e)&&r?.onRemove?.([e]),{plot:n,index:s}},duplicate(e){const s=t.findIndex(c=>c.id===e);if(s<0)return;const n=t[s],o=JSON.parse(JSON.stringify(n));return o.id=g(),n.title&&Object.assign(o,{title:copyTitle(n.title,t.map(c=>c.title))}),t=[...t.slice(0,s+1),o,...t.slice(s+1)],a(),o},replaceAll(e){const s=[...h].filter(n=>t.some(o=>o.id===n)&&!e.some(o=>o.id===n));t=e.map(n=>JSON.parse(JSON.stringify(n))),a(),s.length>0&&r?.onRemove?.(s)},subscribe(e){return u.add(e),()=>{u.delete(e)}},flush:S}}
@@ -1,5 +1,7 @@
1
1
  import type { Die } from '../core/dies.js';
2
2
  import type { TestDef } from '../renderer/buildWaferMap.js';
3
+ import type { BinColors } from '../renderer/binColors.js';
4
+ import type { WaferContextMenuHandler } from './charts/chartShell.js';
3
5
  import type { FacetCuration } from '../stats/facets.js';
4
6
  import type { PlotStore } from './plotStore.js';
5
7
  import type { InsightsItem } from './insightsTab.js';
@@ -18,6 +20,10 @@ export interface PlotSectionDeps {
18
20
  groupLabel?: string;
19
21
  onSaveImage?: SaveImageHandler;
20
22
  onSaveText?: SaveTextHandler;
23
+ /** The maps' bin colours: a plot coloured by bin draws each bin in its map colour. */
24
+ getBinColors?: () => BinColors;
25
+ /** Right-click a wafer's own mark: that wafer's menu, by its index in the host's list. */
26
+ waferMenu?: WaferContextMenuHandler;
21
27
  /** Click a point: open its wafer, on a test's values when the plot is about one. */
22
28
  openWafer?: (waferIndex: number, label: string, testNumber?: number) => void;
23
29
  /** A single-wafer host's version of the same: show the test on the map that is already there. */