@wafertools/wafermap 0.37.1 → 0.39.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 (86) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +21 -13
  3. package/dist/packages/canvas-adapter/cellShade.d.ts +21 -0
  4. package/dist/packages/canvas-adapter/cellShade.js +1 -0
  5. package/dist/packages/canvas-adapter/chartPopulation.d.ts +8 -3
  6. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +45 -19
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/correlation.d.ts +11 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +23 -0
  13. package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/palette.d.ts +10 -3
  16. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  17. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +3 -7
  18. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  19. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  20. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +1 -0
  21. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
  22. package/dist/packages/canvas-adapter/drilldown.d.ts +5 -0
  23. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  24. package/dist/packages/canvas-adapter/filterJson.d.ts +25 -0
  25. package/dist/packages/canvas-adapter/filterJson.js +5 -0
  26. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  27. package/dist/packages/canvas-adapter/index.js +1 -1
  28. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  29. package/dist/packages/canvas-adapter/pageFilter.js +2 -2
  30. package/dist/packages/canvas-adapter/pinnedTests.d.ts +10 -0
  31. package/dist/packages/canvas-adapter/pinnedTests.js +1 -0
  32. package/dist/packages/canvas-adapter/plotCard.d.ts +1 -1
  33. package/dist/packages/canvas-adapter/plotCard.js +1 -1
  34. package/dist/packages/canvas-adapter/plotEditor.js +10 -1
  35. package/dist/packages/canvas-adapter/plotJsonComplete.d.ts +46 -0
  36. package/dist/packages/canvas-adapter/plotJsonComplete.js +4 -0
  37. package/dist/packages/canvas-adapter/plotJsonHistory.d.ts +12 -0
  38. package/dist/packages/canvas-adapter/plotJsonHistory.js +1 -0
  39. package/dist/packages/canvas-adapter/plotJsonSuggest.d.ts +16 -0
  40. package/dist/packages/canvas-adapter/plotJsonSuggest.js +1 -0
  41. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  42. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  43. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  44. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  45. package/dist/packages/canvas-adapter/summaryPanel.d.ts +3 -3
  46. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  47. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  48. package/dist/packages/canvas-adapter/userGuideHtml.js +68 -33
  49. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  50. package/dist/packages/canvas-adapter/version.js +1 -1
  51. package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
  52. package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -0
  53. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  54. package/dist/packages/core/utils.d.ts +6 -0
  55. package/dist/packages/core/utils.js +1 -1
  56. package/dist/packages/renderer/buildWaferMap.js +1 -1
  57. package/dist/packages/renderer/derivedTests/apply.d.ts +10 -0
  58. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  59. package/dist/packages/renderer/derivedTests/check.d.ts +35 -0
  60. package/dist/packages/renderer/derivedTests/check.js +1 -0
  61. package/dist/packages/renderer/fmt.d.ts +5 -0
  62. package/dist/packages/renderer/fmt.js +1 -1
  63. package/dist/packages/renderer/index.d.ts +2 -0
  64. package/dist/packages/renderer/index.js +1 -1
  65. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  66. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  67. package/dist/packages/stats/chartCatalogue.js +1 -1
  68. package/dist/packages/stats/clusterDetection.js +1 -1
  69. package/dist/packages/stats/coFailure.d.ts +11 -0
  70. package/dist/packages/stats/coFailure.js +1 -0
  71. package/dist/packages/stats/correlation.d.ts +7 -0
  72. package/dist/packages/stats/correlation.js +1 -1
  73. package/dist/packages/stats/differenceMap.d.ts +2 -0
  74. package/dist/packages/stats/differenceMap.js +1 -1
  75. package/dist/packages/stats/plotData.d.ts +18 -2
  76. package/dist/packages/stats/plotData.js +1 -1
  77. package/dist/packages/stats/plotSpec.d.ts +31 -2
  78. package/dist/packages/stats/plotSpec.js +4 -4
  79. package/dist/packages/stats/plotTable.d.ts +18 -0
  80. package/dist/packages/stats/plotTable.js +1 -0
  81. package/dist/packages/stats/reportHtml.js +33 -29
  82. package/dist/packages/stats/synthesis.d.ts +7 -1
  83. package/dist/packages/stats/synthesis.js +1 -1
  84. package/dist/packages/stats/testsByWafer.d.ts +11 -0
  85. package/dist/packages/stats/testsByWafer.js +1 -0
  86. package/package.json +8 -4
@@ -1 +1 @@
1
- import{isYieldEligibleDie as W}from"../core/dies.js";import{testValue as A}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as H}from"../stats/facets.js";import{tableToTsv as V}from"../core/tableCsv.js";import{commonMetadata as Y}from"../stats/facets.js";import{buildYieldData as G}from"../stats/yield.js";import{isParametricTest as k}from"../renderer/buildWaferMap.js";import{fmt as U}from"../renderer/fmt.js";import{testLabel as $}from"../renderer/testLabel.js";import{resolveDieColumns as K}from"./dieList.js";import{createVirtualTable as N}from"./virtualTable.js";import{exportCsv as O}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as R,SPACE as C,controlStyle as q,wireControlHover as j,wireTooltip as S}from"./toolbar.js";import{buildTestSection as X,buildFunctionalTestSection as J}from"./summaryPanel.js";import{patTests as Q,waferPatVerdicts as Z,PAT_VERDICT_LABEL as ee}from"../stats/pat.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,l,o=l+"s")=>`${e.toLocaleString()} ${e===1?l:o}`;export function renderDataSection(e){const{doc:l}=e,o=l.createElement("div");o.dataset.wmapDataTab="1",Object.assign(o.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=l.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),o.appendChild(c);const p=l.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),o.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),s=P(l,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(s.el);let r;switch(e.view){case"dies":r=oe(e);break;case"wafers":r=se(e);break;default:r=te(e)}let u=()=>{};if(e.view==="dies"){const f=P(l,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),r.actions?.setLayout?.(t),u()});S(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const d=l.createElement("span");Object.assign(d.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const i=l.createElement("span");i.textContent="Export format:",Object.assign(i.style,{color:y.label,fontSize:L.body}),d.append(i,f.el),c.appendChild(d)}if(r.actions){const f=r.actions,d=l.createElement("div");d.style.flex="1",c.appendChild(d);const i=M(l,"Export CSV");i.dataset.wmapDataExport="1",i.addEventListener("click",()=>{if(i.disabled)return;const m=i.textContent,h=f.exportCsv();h&&(i.disabled=!0,i.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{i.disabled=!1,i.removeAttribute("aria-busy"),i.textContent=m}))});const t=M(l,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(S(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=l.defaultView?.navigator?.clipboard;if(!h)return;const v=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",l.defaultView?.setTimeout(()=>{t.textContent=v},1500)}).catch(()=>{})})):(t.disabled=!0,S(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,i);const a=l.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),o.insertBefore(a,p)}return p.appendChild(r.el),{card:o,destroy:()=>r.destroy()}}function te(e){const{doc:l}=e,o=l.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const s of g){if(p){const u=l.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${s.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),o.appendChild(u)}const r=e.buildStatistics(s.items);c.push(r.destroy);for(const u of r.cards)o.appendChild(u)}return!o.querySelector("table")&&!o.textContent&&(o.textContent="No test statistics to show for these wafers.",Object.assign(o.style,{color:y.label,fontSize:L.body})),{el:o,destroy:()=>{for(const s of c)s()}}}function ne(e,l,o){if(Q(l).length===0)return;const c=new Map;for(const s of e){const r=s.allDies??(o?void 0:s.dies);if(!r)continue;const u=Z(r,l,s.passBins);r.forEach((f,d)=>c.set(f,u[d]))}if(c.size===0)return;const p=s=>{const r=l.find(u=>u.testNumber===s);return r?$(r,s):`Test ${s}`};let g=!1;for(const s of c.values())if(s.verdict==="outlier"){g=!0;break}return{verdict:s=>{const r=c.get(s)?.verdict;return r?ee[r]:void 0},tests:s=>{const r=c.get(s);return r?.verdict==="outlier"?r.tests.map(p).join("; "):""},anyOutlier:g}}function oe(e){const{doc:l,items:o}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,s=[];let r=!1;for(const n of o){n.wafer&&(r=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),s.push(b)}if(s.length===0)return B(l,"No dies to show.");const u=ne(o,e.allTestDefs,!!e.population),{columns:f,visibleColumns:d}=K(s,e.allTestDefs,{...e.dieListOptions,...u?{patColumns:u}:{},metadataFields:e.metadataFields,extraColumn:o.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:r?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:o.some(n=>n.wafer)?Y(o.map(n=>({metadata:n.wafer?.metadata}))):void 0,attributes:e.attributes,ownerDocument:l}),i=d.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&k(n.test),...n.test!==void 0&&k(n.test)?{sortKey:b=>A(b,n.test.testNumber)}:{}})),t=N({columns:i,rows:s,ariaLabel:`Dies (${s.length})`,ownerDocument:l,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});t.el.style.maxHeight="70vh",t.el.style.minHeight="240px";const a=e.population?`-${e.population.fileTag}`:"",m=f.filter(n=>n.test!==void 0),h=f.filter(n=>n.test===void 0),v=s.length*f.length,w=s.length*m.length,x=()=>f.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),_=()=>[...h.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>$(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*F(){for(const n of t.orderedRows())for(const b of m){const T=(b.csvGet??b.get)(n);T===""||T===void 0||T===null||(yield{die:n,test:b.test,value:T})}}let E=e.diesLayout==="long"&&m.length>0;const z=()=>E?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(s.length,"row")} \xD7 ${D(f.length,"column")}`+(s.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:t.el,destroy:()=>t.destroy(),actions:{note:()=>`${D(s.length,"die")} ${e.population?.phrase??`on ${D(o.length,"wafer")}`}. ${z()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{E=n==="long"&&m.length>0},exportCsv:()=>E?O(_(),F(),`die-list-long${a}.csv`,e.onSaveText,{rowCount:w}):O(x(),t.orderedRows(),`die-list${a}.csv`,e.onSaveText,{rowCount:s.length}),copyText:v<=COPY_CELL_LIMIT?()=>V(x(),t.orderedRows()):null}}}function se(e){const{doc:l,items:o}=e;if(o.length===0)return B(l,"No wafers to show.");const c=o.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=G([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),s=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(w=>w.testNumber===a.testNumber);if(m)return m.mean;let h=0,v=0;for(const w of t.item.dies){if(!W(w))continue;const x=A(w,a.testNumber);x!==void 0&&Number.isFinite(x)&&(h++,v+=x)}return h?v/h:void 0},r=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:H(t,e.attributes),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>W(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${$(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>s(a,t),show:a=>{const m=s(a,t);return m===void 0?"":U(m,t.unit)},numeric:!0}))],u=r.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=N({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:l,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const d=()=>r.map(t=>({header:t.header,get:t.cell})),i=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${i}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>O(d(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*r.length<=COPY_CELL_LIMIT?()=>V(d(),f.orderedRows()):null}}}function B(e,l){const o=e.createElement("div");return o.textContent=l,Object.assign(o.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:o,destroy:()=>{}}}function M(e,l){const o=e.createElement("button");return o.type="button",o.textContent=l,Object.assign(o.style,{fontSize:L.body,padding:"3px 10px",borderRadius:R.control,...q("outlined"),background:y.menuBg}),j(o),o}function P(e,l,o,c,p,g){const s=e.createElement("div");s.setAttribute("role","radiogroup"),s.setAttribute("aria-label",l),Object.assign(s.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:R.control,overflow:"hidden"});const r=[];let u=c;const f=()=>{for(const d of r){const i=d.dataset[p]===u;d.setAttribute("aria-checked",String(i)),d.tabIndex=i?0:-1,Object.assign(d.style,{background:i?y.bgActive:"transparent",color:i?y.iconActive:y.label,fontWeight:i?"600":"400"})}};for(const d of o){const i=e.createElement("button");d.hint&&S(i,d.hint),i.type="button",i.textContent=d.label,i.dataset[p]=d.key,i.setAttribute("role","radio"),Object.assign(i.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(i,"bare"),i.addEventListener("click",()=>{u!==d.key&&g(d.key)}),r.push(i),s.appendChild(i)}return f(),s.addEventListener("keydown",d=>{if(d.key!=="ArrowLeft"&&d.key!=="ArrowRight")return;const i=r.indexOf(e.activeElement);if(i<0)return;d.preventDefault();const t=r[(i+(d.key==="ArrowRight"?1:-1)+r.length)%r.length];t.click(),t.focus()}),{el:s,set:d=>{u=d,f()}}}export function renderDataTables(e){const{doc:l}=e,o=l.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],s=g.filter(k),r=e.views??(c.length>1?["statistics","wafers","dies"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=r.includes(e.view)?e.view:r[0],d="wide",i=null;const t=()=>{i?.destroy(),i=renderDataSection({doc:l,items:c,testDefs:s,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:r,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,attributes:e.attributes,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(x=>x.dies),h=[],v=X(m,s,void 0,void 0,e.onSaveText,u,a.map(x=>({dies:x.dies})),void 0,"full");v&&h.push(v);const w=J(m,g,void 0,e.onSaveText,u);return w&&h.push(w),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:d,onDiesLayoutChange:a=>{d=a}}),o.replaceChildren(i.card)};return t(),{el:o,destroy:()=>i?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
1
+ import{maxOf as J}from"../core/utils.js";import{isYieldEligibleDie as z}from"../core/dies.js";import{testValue as B}from"../core/dieTable.js";import{metadataDisplayValue as _}from"../core/metadata.js";import{attributeLabel as F}from"../stats/facets.js";import{tableToTsv as H}from"../core/tableCsv.js";import{commonMetadata as Z}from"../stats/facets.js";import{buildYieldData as ee}from"../stats/yield.js";import{isParametricTest as j}from"../renderer/buildWaferMap.js";import{fmt as I}from"../renderer/fmt.js";import{testLabel as M}from"../renderer/testLabel.js";import{resolveDieColumns as te}from"./dieList.js";import{createVirtualTable as P}from"./virtualTable.js";import{exportCsv as A}from"./tableExport.js";import{CLR as S,FONT as k,RADIUS as q,SPACE as T,controlStyle as ne,wireControlHover as G,wireTooltip as V}from"./toolbar.js";import{buildTestSection as oe,buildFunctionalTestSection as se}from"./summaryPanel.js";import{pooledTestStatsSteps as ie}from"../stats/capability.js";import{runChunked as ae}from"./chunked.js";import{capabilityShade as re,outOfLimitsShade as le,shadesAmong as K,shortfallShade as U}from"./cellShade.js";import{patTests as de,waferPatVerdicts as ce,PAT_VERDICT_LABEL as ue}from"../stats/pat.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const O=(t,d,s=d+"s")=>`${t.toLocaleString()} ${t===1?d:s}`;export function renderDataSection(t){const{doc:d}=t,s=d.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:T.md,minWidth:"0"});const a=d.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",gap:T.md,flexWrap:"wrap"}),s.appendChild(a);const h=d.createElement("div");Object.assign(h.style,{display:"flex",flexDirection:"column",gap:T.md,minWidth:"0"}),s.appendChild(h);const y=DATA_VIEWS.filter(f=>!t.views||t.views.includes(f.key)),o=X(d,"Table",y,t.view,"wmapDataView",f=>t.onViewChange(f));a.appendChild(o.el);let r;switch(t.view){case"dies":r=pe(t);break;case"wafers":r=ge(t);break;default:r=fe(t)}let p=()=>{};if(t.view==="dies"){const f=X(d,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],t.diesLayout,"wmapDataLayout",u=>{f.set(u),t.onDiesLayoutChange(u),r.actions?.setLayout?.(u),p()});V(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const c=d.createElement("span");Object.assign(c.style,{display:"inline-flex",alignItems:"center",gap:T.sm});const l=d.createElement("span");l.textContent="Export format:",Object.assign(l.style,{color:S.label,fontSize:k.body}),c.append(l,f.el),a.appendChild(c)}if(r.actions){const f=r.actions,c=d.createElement("div");c.style.flex="1",a.appendChild(c);const l=Y(d,"Export CSV");l.dataset.wmapDataExport="1",l.addEventListener("click",()=>{if(l.disabled)return;const w=l.textContent,b=f.exportCsv();b&&(l.disabled=!0,l.setAttribute("aria-busy","true"),b.catch(()=>{}).finally(()=>{l.disabled=!1,l.removeAttribute("aria-busy"),l.textContent=w}))});const u=Y(d,"Copy");u.dataset.wmapDataCopy="1",f.copyText?(V(u,"Copy the table as tab-separated text, to paste into a spreadsheet"),u.addEventListener("click",()=>{const w=f.copyText(),b=d.defaultView?.navigator?.clipboard;if(!b)return;const x=u.textContent;b.writeText(w).then(()=>{u.textContent="Copied",d.defaultView?.setTimeout(()=>{u.textContent=x},1500)}).catch(()=>{})})):(u.disabled=!0,V(u,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),a.append(u,l);const g=d.createElement("div");g.dataset.wmapDataNote="1",g.textContent=f.note(),p=()=>{g.textContent=f.note()},Object.assign(g.style,{color:S.label,fontSize:k.body}),s.insertBefore(g,h)}return h.appendChild(r.el),{card:s,destroy:()=>r.destroy()}}function fe(t){const{doc:d}=t,s=d.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"});const a=[],h=t.groups&&t.groups.length>0?t.groups:void 0,y=h??[{key:"",items:t.items}];if(h&&h.length>1){const o=me(t,h);o&&(s.appendChild(o.el),a.push(o.destroy))}for(const o of y){if(h){const p=d.createElement("div");p.textContent=`${t.groupLabelText??"Group"}: ${o.key}`,Object.assign(p.style,{fontWeight:"700",color:S.text,fontSize:k.body}),s.appendChild(p)}const r=t.buildStatistics(o.items);a.push(r.destroy);for(const p of r.cards)s.appendChild(p)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:S.label,fontSize:k.body})),{el:s,destroy:()=>{for(const o of a)o()}}}function me(t,d){const{doc:s}=t,a=t.testDefs.filter(b=>b.testNumber!==void 0&&j(b));if(a.length===0)return null;const h=t.groupLabelText??"Group",y=s.createElement("div");y.dataset.wmapGroupStats="1",Object.assign(y.style,{display:"flex",flexDirection:"column",gap:T.sm,minWidth:"0"});const o=s.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:T.md,flexWrap:"wrap"});const r=s.createElement("div");r.textContent=`Compared across ${h}`,Object.assign(r.style,{fontWeight:"700",color:S.text,fontSize:k.body}),o.appendChild(r);const p=s.createElement("div");p.textContent="Computing test statistics\u2026",Object.assign(p.style,{color:S.label,fontSize:k.body}),y.append(o,p);const f=new Map;let c=d.length,l,u=!1;const g=()=>{if(u)return;const b=[];for(const e of a)for(const n of d){const m=f.get(n.key),i=m?.stats.get(e.testNumber);if(!m||!i)continue;const C=m.specTally.get(e.testNumber);b.push({def:e,group:n.key,count:i.count,min:i.min,q1:i.q1,median:i.median,mean:i.mean,q3:i.q3,max:i.max,stddev:i.stddev,ppk:m.capability.find(W=>W.testNumber===e.testNumber)?.ppk??null,limitYield:C&&C.n>0?100*(1-C.fail/C.n):void 0})}if(b.length===0){y.remove();return}const x=new Map;for(const e of b){const n=x.get(e.def.testNumber);n?n.push(e):x.set(e.def.testNumber,[e])}for(const e of x.values()){const n=K(e.map(i=>i.mean),i=>I(i,e[0].def.unit)),m=J(e.map(i=>i.limitYield??-1/0));e.forEach((i,C)=>{i.meanShade=n[C],i.yieldShade=i.limitYield===void 0||!Number.isFinite(m)?void 0:U(i.limitYield-m)})}const v=e=>({get:n=>I(e(n),n.def.unit),numeric:!0,sortKey:e}),L=(e,n)=>({get:m=>{const i=e(m);return i===void 0||!Number.isFinite(i)?"":n(i)},numeric:!0,sortKey:m=>{const i=e(m);return i===void 0||!Number.isFinite(i)?void 0:i}}),D=[{header:"Test",get:e=>`${M(e.def,e.def.testNumber)}${e.def.unit?` (${e.def.unit})`:""}`},{header:h,get:e=>e.group},{header:"N",...L(e=>e.count,e=>String(e))},{header:"Min",...v(e=>e.min)},{header:"Q1",...v(e=>e.q1)},{header:"Median",...v(e=>e.median)},{header:"Mean",...v(e=>e.mean),shade:e=>e.meanShade},{header:"Q3",...v(e=>e.q3)},{header:"Max",...v(e=>e.max)},{header:"Std dev",...v(e=>e.stddev)},{header:"Ppk",...L(e=>e.ppk??void 0,e=>e.toFixed(2)),shade:e=>re(e.ppk)},{header:"Limit yield %",...L(e=>e.limitYield,e=>e.toFixed(1)),shade:e=>e.yieldShade}],E=P({columns:D,rows:b,ariaLabel:`Statistics by ${h} (${b.length})`,ownerDocument:s});E.el.style.maxHeight="50vh",E.el.style.minHeight="120px",l=E;const N=()=>[{header:"Test number",get:e=>e.def.testNumber??null},{header:"Test",get:e=>M(e.def,e.def.testNumber)},{header:"Unit",get:e=>e.def.unit??""},{header:h,get:e=>e.group},{header:"N",get:e=>e.count},{header:"Min",get:e=>e.min},{header:"Q1",get:e=>e.q1},{header:"Median",get:e=>e.median},{header:"Mean",get:e=>e.mean},{header:"Q3",get:e=>e.q3},{header:"Max",get:e=>e.max},{header:"Std dev",get:e=>e.stddev},{header:"Ppk",get:e=>e.ppk},{header:"Limit yield %",get:e=>e.limitYield??null}],$=Y(s,"Statistics CSV");$.dataset.wmapGroupStatsCsv="1",$.addEventListener("click",()=>{A(N(),E.orderedRows(),`statistics-by-${h.toLowerCase().replace(/[^a-z0-9]+/g,"-")}.csv`,t.onSaveText,{rowCount:b.length})}),o.appendChild($),p.replaceWith(E.el)},w=[];for(const b of d)w.push(ae(ie(b.items.map(x=>({dies:x.dies})),a),{onDone:x=>{f.set(b.key,x),--c===0&&g()}}));return{el:y,destroy:()=>{u=!0;for(const b of w)b.cancel();l?.destroy()}}}function he(t,d,s){if(de(d).length===0)return;const a=new Map;for(const o of t){const r=o.allDies??(s?void 0:o.dies);if(!r)continue;const p=ce(r,d,o.passBins);r.forEach((f,c)=>a.set(f,p[c]))}if(a.size===0)return;const h=o=>{const r=d.find(p=>p.testNumber===o);return r?M(r,o):`Test ${o}`};let y=!1;for(const o of a.values())if(o.verdict==="outlier"){y=!0;break}return{verdict:o=>{const r=a.get(o)?.verdict;return r?ue[r]:void 0},tests:o=>{const r=a.get(o);return r?.verdict==="outlier"?r.tests.map(h).join("; "):""},anyOutlier:y}}function pe(t){const{doc:d,items:s}=t,a=new WeakMap,h=new WeakMap,y=new WeakMap,o=[];let r=!1;for(const e of s){e.wafer&&(r=!0);for(const n of e.dies)a.set(n,e.label),y.set(n,e.waferIndex),e.wafer&&h.set(n,e.wafer),o.push(n)}if(o.length===0)return Q(d,"No dies to show.");const p=he(s,t.allTestDefs,!!t.population),{columns:f,visibleColumns:c}=te(o,t.allTestDefs,{...t.dieListOptions,...p?{patColumns:p}:{},metadataFields:t.metadataFields,extraColumn:s.length>1||t.population?{label:"Wafer",get:e=>a.get(e)}:void 0,getWafer:r?(e=>h.get(e)):void 0,ringCount:t.ringCount,waferMetadata:s.some(e=>e.wafer)?Z(s.map(e=>({metadata:e.wafer?.metadata}))):void 0,attributes:t.attributes,ownerDocument:d}),l=c.map(e=>({header:e.label,get:e.get,numeric:e.test!==void 0&&j(e.test),...e.test!==void 0&&j(e.test)?{sortKey:n=>B(n,e.test.testNumber),shade:n=>{const m=e.test,i=B(n,m.testNumber);return i!==void 0&&Number.isFinite(i)&&(m.limitLow!==void 0&&i<m.limitLow||m.limitHigh!==void 0&&i>m.limitHigh)?le():void 0}}:{}})),u=P({columns:l,rows:o,ariaLabel:`Dies (${o.length})`,ownerDocument:d,onRowClick:t.onLocateDie?e=>t.onLocateDie(e,y.get(e)):void 0});u.el.style.maxHeight="70vh",u.el.style.minHeight="240px";const g=t.population?`-${t.population.fileTag}`:"",w=f.filter(e=>e.test!==void 0),b=f.filter(e=>e.test===void 0),x=o.length*f.length,v=o.length*w.length,L=()=>f.map(e=>({header:e.csvLabel??e.label,get:e.csvGet??e.get})),D=()=>[...b.map(e=>({header:e.csvLabel??e.label,get:n=>(e.csvGet??e.get)(n.die)})),{header:"Test",get:e=>M(e.test,e.test.testNumber)},{header:"Test number",get:e=>e.test.testNumber},{header:"Unit",get:e=>e.test.unit??""},{header:"Value",get:e=>e.value}];function*E(){for(const e of u.orderedRows())for(const n of w){const m=(n.csvGet??n.get)(e);m===""||m===void 0||m===null||(yield{die:e,test:n.test,value:m})}}let N=t.diesLayout==="long"&&w.length>0;const $=()=>N?`Long format: up to ${O(v,"row")} (a die with no result for a test has no row)`+(v>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${O(o.length,"row")} \xD7 ${O(f.length,"column")}`+(o.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:u.el,destroy:()=>u.destroy(),actions:{note:()=>`${O(o.length,"die")} ${t.population?.phrase??`on ${O(s.length,"wafer")}`}. ${$()} Export follows the order shown.${t.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:e=>{N=e==="long"&&w.length>0},exportCsv:()=>N?A(D(),E(),`die-list-long${g}.csv`,t.onSaveText,{rowCount:v}):A(L(),u.orderedRows(),`die-list${g}.csv`,t.onSaveText,{rowCount:o.length}),copyText:x<=COPY_CELL_LIMIT?()=>H(L(),u.orderedRows()):null}}}function ge(t){const{doc:d,items:s}=t;if(s.length===0)return Q(d,"No wafers to show.");const a=s.map(e=>{const n=t.yieldByWaferIndex.get(e.waferIndex),m=ee([{label:e.label,dies:e.dies,passBins:e.passBins,yieldPercent:n,key:e.waferIndex}])[0]?.percent;return{item:e,yieldPercent:e.dies.length?m??null:null}}),h=[];for(const{item:e}of a)for(const n of Object.keys(e.wafer?.metadata??{}))!h.includes(n)&&_((e.wafer?.metadata)[n])!==void 0&&h.push(n);const y=t.testDefs.slice(0,WAFER_TEST_COLUMNS),o=(e,n)=>{const m=e.item.statsSummary?.stats.perTestStats?.find(W=>W.testNumber===n.testNumber);if(m)return m.mean;let i=0,C=0;for(const W of e.item.dies){if(!z(W))continue;const R=B(W,n.testNumber);R!==void 0&&Number.isFinite(R)&&(i++,C+=R)}return i?C/i:void 0},r=(e,n)=>_(e.item.wafer?.metadata?.[n])??"",p=e=>({header:F(e,t.attributes),cell:n=>r(n,e)}),f=e=>a.length>1&&a.every(n=>r(n,e)===r(a[0],e)),c=h.filter(f),l=h.filter(e=>!c.includes(e)),u=t.groupLabelText?l.find(e=>F(e,t.attributes)===t.groupLabelText):void 0,g=a.map(e=>e.yieldPercent).filter(e=>e!==null&&Number.isFinite(e)),w=g.length?g.reduce((e,n)=>e+n,0)/g.length:void 0,b=[{header:"Dies",cell:e=>e.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:e=>e.item.dies.filter(n=>z(n)).length,numeric:!0},{header:"Yield %",cell:e=>e.yieldPercent===null?"":e.yieldPercent,show:e=>e.yieldPercent===null?"":e.yieldPercent.toFixed(1),numeric:!0,shade:e=>e.yieldPercent===null||w===void 0?void 0:U(e.yieldPercent-w)},...y.map(e=>{const n=new Map,m=K(a.map(i=>o(i,e)??NaN),i=>I(i,e.unit));return a.forEach((i,C)=>n.set(i,m[C])),{header:`${M(e,e.testNumber)}${e.unit?` (${e.unit})`:""} mean`,cell:i=>o(i,e),show:i=>{const C=o(i,e);return C===void 0?"":I(C,e.unit)},numeric:!0,shade:i=>n.get(i)}})],x=[{header:"Wafer",cell:e=>e.item.label},...u?[p(u)]:[],...b,...l.filter(e=>e!==u).map(p)],v=[...x,...c.map(p)],L=x.map(e=>({header:e.header,get:n=>e.show?e.show(n):String(e.cell(n)??""),numeric:e.numeric,...e.shade?{shade:e.shade}:{},...e.numeric?{sortKey:n=>{const m=e.cell(n);return typeof m=="number"?m:void 0}}:{}})),D=P({columns:L,rows:a,ariaLabel:`Wafers (${a.length})`,ownerDocument:d,onRowClick:t.onOpenWafer?e=>t.onOpenWafer(e.item.waferIndex,e.item.label):void 0});D.el.style.maxHeight="70vh",D.el.style.minHeight="120px";const E=()=>v.map(e=>({header:e.header,get:e.cell})),N=t.testDefs.length>y.length?` Mean columns cover the first ${y.length} of ${t.testDefs.length} tests.`:"";let $=D.el;if(c.length){const e=d.createElement("div");e.dataset.wmapWafersSame="1",e.textContent=`Same on every wafer: ${c.map(n=>`${F(n,t.attributes)} ${r(a[0],n)}`).join(" \xB7 ")}`,Object.assign(e.style,{color:S.label,fontSize:k.body,lineHeight:"1.5",marginBottom:T.sm}),$=d.createElement("div"),$.append(e,D.el)}return{el:$,destroy:()=>D.destroy(),actions:{note:()=>`${O(a.length,"wafer")}.${N}${t.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>A(E(),D.orderedRows(),"wafers.csv",t.onSaveText,{rowCount:a.length}),copyText:a.length*v.length<=COPY_CELL_LIMIT?()=>H(E(),D.orderedRows()):null}}}function Q(t,d){const s=t.createElement("div");return s.textContent=d,Object.assign(s.style,{color:S.label,fontSize:k.body,padding:T.md}),{el:s,destroy:()=>{}}}function Y(t,d){const s=t.createElement("button");return s.type="button",s.textContent=d,Object.assign(s.style,{fontSize:k.body,padding:"3px 10px",borderRadius:q.control,...ne("outlined"),background:S.menuBg}),G(s),s}function X(t,d,s,a,h,y){const o=t.createElement("div");o.setAttribute("role","radiogroup"),o.setAttribute("aria-label",d),Object.assign(o.style,{display:"inline-flex",background:S.menuBg,border:`1px solid ${S.menuBorder}`,borderRadius:q.control,overflow:"hidden"});const r=[];let p=a;const f=()=>{for(const c of r){const l=c.dataset[h]===p;c.setAttribute("aria-checked",String(l)),c.tabIndex=l?0:-1,Object.assign(c.style,{background:l?S.bgActive:"transparent",color:l?S.iconActive:S.label,fontWeight:l?"600":"400"})}};for(const c of s){const l=t.createElement("button");c.hint&&V(l,c.hint),l.type="button",l.textContent=c.label,l.dataset[h]=c.key,l.setAttribute("role","radio"),Object.assign(l.style,{border:"none",cursor:"pointer",fontSize:k.body,padding:`${T.xs} ${T.md}`,whiteSpace:"nowrap"}),G(l,"bare"),l.addEventListener("click",()=>{p!==c.key&&y(c.key)}),r.push(l),o.appendChild(l)}return f(),o.addEventListener("keydown",c=>{if(c.key!=="ArrowLeft"&&c.key!=="ArrowRight")return;const l=r.indexOf(t.activeElement);if(l<0)return;c.preventDefault();const u=r[(l+(c.key==="ArrowRight"?1:-1)+r.length)%r.length];u.click(),u.focus()}),{el:o,set:c=>{p=c,f()}}}export function renderDataTables(t){const{doc:d}=t,s=d.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:T.md});const a=t.items.map((g,w)=>({...g,waferIndex:g.waferIndex??w})),h=a.flatMap(g=>g.dies),y=t.testDefs??[],o=y.filter(j),r=t.views??(a.length>1?["statistics","wafers","dies"]:["statistics","dies"]),p=t.population?{populationLabel:`${O(h.length,"die")} ${t.population}`}:a.length>1?{perWaferMetadata:a.map(g=>g.wafer?.metadata??{}),populationLabel:`${O(a.length,"wafer")} pooled`}:{waferMetadata:a[0]?.wafer?.metadata};let f=r.includes(t.view)?t.view:r[0],c="wide",l=null;const u=()=>{l?.destroy(),l=renderDataSection({doc:d,items:a,testDefs:o,allTestDefs:y,ringCount:t.ringCount,yieldByWaferIndex:new Map,onSaveText:t.onSaveText,views:r,view:f,dieListOptions:t.dieListOptions,metadataFields:t.metadataFields,attributes:t.attributes,onLocateDie:t.onLocateDie,population:t.population?{phrase:t.population,fileTag:"selection"}:void 0,buildStatistics:g=>{const w=g.flatMap(L=>L.dies),b=[],x=oe(w,o,void 0,void 0,t.onSaveText,p,g.map(L=>({dies:L.dies})),void 0,"full");x&&b.push(x);const v=se(w,y,void 0,t.onSaveText,p);return v&&b.push(v),{cards:b,destroy:()=>{}}},onViewChange:g=>{f=g,u()},diesLayout:c,onDiesLayoutChange:g=>{c=g}}),s.replaceChildren(l.card)};return u(),{el:s,destroy:()=>l?.destroy()}}export function renderSelectionTables(t){return renderDataTables({...t,views:t.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
@@ -1,3 +1,4 @@
1
+ import './charts/divergingScale.js';
1
2
  import { type TestDef } from '../renderer/buildWaferMap.js';
2
3
  import type { Die } from '../core/dies.js';
3
4
  import { type SaveImageHandler } from './charts/chartShell.js';
@@ -1 +1 @@
1
- import{differenceMap as z}from"../stats/differenceMap.js";import{isParametricTest as F}from"../renderer/buildWaferMap.js";import{testLabel as E}from"../renderer/testLabel.js";import{fmt as A}from"../renderer/fmt.js";import{CLR as I,FONT as M,SPACE as R}from"./toolbar.js";import{cardShell as Y,guideCite as W,makeListSelect as k,renderEmptyState as _}from"./charts/chartShell.js";import{GUIDE_SECTIONS as U}from"../stats/guideSections.js";import{renderWaferMap as q}from"./renderWaferMap.js";import{cardAbout as H}from"./charts/cardAbout.js";const c="\0yield";export function renderDifferenceMapPanel(s){const n=s.ownerDocument??document,{card:y,body:x,controlsRow:O,setAbout:B}=Y("Difference map",s.onSaveImage,n,{png:!1});B(H("difference-map")),y.dataset.wmapDifferenceMap="1";const p=s.groups.map(e=>e.key),l=s.testDefs.filter(F);let a=p[0],i=p[1],t=s.selectedTestNumber!==void 0&&l.some(e=>e.testNumber===s.selectedTestNumber)?String(s.selectedTestNumber):l[0]?String(l[0].testNumber):c,C=!0,b;if(p.length<2)return _(x,"Needs two groups to subtract."),{card:y,setTest:()=>{},destroy:()=>{}};const D=(s.groupLabelText??"Group").toLowerCase(),T=(e,m,u,S)=>k(p.map(o=>({value:o,label:o})),e,o=>{S(o),h()},{ownerDocument:n,ariaLabel:m,hook:u}),w=n.createElement("span");w.textContent="minus",Object.assign(w.style,{color:I.label,fontSize:M.body});const L=()=>k([{value:c,label:"Yield"},...l.map(e=>({value:String(e.testNumber),label:E(e,e.testNumber)}))],t,e=>{t=e,C=!1,h()},{ownerDocument:n,ariaLabel:"Measure",hook:"difference-measure",searchPlaceholder:"Filter tests\u2026"});let $=L();O.append(T(a,`First ${D}`,"difference-a",e=>{a=e}),w,T(i,`Second ${D}`,"difference-b",e=>{i=e}),$);const d=n.createElement("div");Object.assign(d.style,{color:I.label,fontSize:M.body,marginBottom:R.sm});const g=n.createElement("div");Object.assign(g.style,{position:"relative",height:"380px"}),x.append(d,g);function h(){if(b?.destroy(),b=void 0,g.replaceChildren(),a===i){d.textContent="Choose two different groups.";return}const e=s.groups.find(f=>f.key===a),m=s.groups.find(f=>f.key===i),u=t===c?{yield:!0}:{test:Number(t)},S=t===c?void 0:l.find(f=>f.testNumber===Number(t)),o=t===c?"Yield":E(S,Number(t)),v=t===c?"%":S?.unit,r=z(e.items,m.items,u);d.textContent=r.compared?`${o}: ${a} (${e.items.length} wafer${e.items.length===1?"":"s"}) minus ${i} (${m.items.length}), each the mean over its wafers at the position${t===c?" of the share passing":""}. ${r.compared.toLocaleString("en-GB")} positions compared; the colours run from \u2212${A(r.maxAbs,v)} to +${A(r.maxAbs,v)}, zero in the middle. Grey: a position one group has no value at.`:`${a} and ${i} have no position with a value of ${o} in common.`,r.compared&&d.append(W(n,U.heatmap),".");const N=e.items[0]?.source;if(!N||!r.compared)return;const{metadata:J,...G}=N.wafer,P={...N,wafer:G,dies:r.dies,passBins:[...e.items[0].passBins],testDefs:[{testNumber:0,name:`${o}: ${a} \u2212 ${i}`,unit:v}]},j=[-(r.maxAbs||1),r.maxAbs||1];b=q(g,P,{viewOptions:{plotMode:"value",activeTest:0,valueRange:j},showIdentity:!1,insights:{enabled:!1},onSaveImage:s.onSaveImage})}return h(),{card:y,setTest:e=>{if(!C||!l.some(u=>u.testNumber===e)||String(e)===t)return;t=String(e);const m=L();$.replaceWith(m),$=m,h()},destroy:()=>{b?.destroy()}}}
1
+ import"./charts/divergingScale.js";import{NEGLIGIBLE_SPREAD as L}from"../core/utils.js";import{differenceMap as W}from"../stats/differenceMap.js";import{isParametricTest as Y}from"../renderer/buildWaferMap.js";import{testLabel as G}from"../renderer/testLabel.js";import{fmt as R}from"../renderer/fmt.js";import{CLR as A,FONT as k,MAP_CHROME_INSET as q,SPACE as U}from"./toolbar.js";import{bodyRoom as X,cardShell as J,guideCite as K,isExpandedCard as Q,makeListSelect as O,observeResize as Z,renderEmptyState as ee}from"./charts/chartShell.js";import{GUIDE_SECTIONS as te}from"../stats/guideSections.js";import{renderWaferMapCard as oe}from"./renderWaferMap.js";import{cardAbout as se}from"./charts/cardAbout.js";const f="\0yield";export function renderDifferenceMapPanel(o){const m=o.ownerDocument??document,{card:c,body:w,controlsRow:_,setAbout:P}=J("Difference map",o.onSaveImage,m,{png:!1});P(se("difference-map")),c.dataset.wmapDifferenceMap="1";const g=o.groups.map(e=>e.key),p=o.testDefs.filter(Y);let l=g[0],d=g[1],t=o.selectedTestNumber!==void 0&&p.some(e=>e.testNumber===o.selectedTestNumber)?String(o.selectedTestNumber):p[0]?String(p[0].testNumber):f,M=!0,u;if(g.length<2)return ee(w,"Needs two groups to subtract."),{card:c,setTest:()=>{},destroy:()=>{}};const I=(o.groupLabelText??"Group").toLowerCase(),D=(e,s,a,S)=>O(g.map(i=>({value:i,label:i})),e,i=>{S(i),y()},{ownerDocument:m,ariaLabel:s,hook:a}),$=m.createElement("span");$.textContent="minus",Object.assign($.style,{color:A.label,fontSize:k.body});const T=()=>O([{value:f,label:"Yield"},...p.map(e=>({value:String(e.testNumber),label:G(e,e.testNumber)}))],t,e=>{t=e,M=!1,y()},{ownerDocument:m,ariaLabel:"Measure",hook:"difference-measure",searchPlaceholder:"Filter tests\u2026"});let N=T();_.append(D(l,`First ${I}`,"difference-a",e=>{l=e}),$,D(d,`Second ${I}`,"difference-b",e=>{d=e}),N);const h=m.createElement("div");Object.assign(h.style,{color:A.label,fontSize:k.body,marginBottom:U.sm});const r=m.createElement("div"),x=380,z=480;Object.assign(r.style,{position:"relative",height:`${x}px`}),w.append(h,r);const B=Z(c,()=>{const e=r.clientWidth,s=e?Math.min(z,Math.max(x,e)):x,a=`${Q(c)?Math.max(s,Math.floor(X(c,w,r))):s}px`;r.style.height!==a&&(r.style.height=a)});function y(){if(u?.destroy(),u=void 0,r.replaceChildren(),l===d){h.textContent="Choose two different groups.";return}const e=o.groups.find(b=>b.key===l),s=o.groups.find(b=>b.key===d),a=t===f?{yield:!0}:{test:Number(t)},S=t===f?void 0:p.find(b=>b.testNumber===Number(t)),i=t===f?"Yield":G(S,Number(t)),E=t===f?"%":S?.unit,n=W(e.items,s.items,a),v=Math.max(n.maxAbs,n.level*L),j=n.compared>0&&n.maxAbs<n.level*L;h.textContent=n.compared?`${i}: ${l} (${e.items.length} wafer${e.items.length===1?"":"s"}) minus ${d} (${s.items.length}), each the mean over its wafers at the position${t===f?" of the share passing":""}. ${n.compared.toLocaleString("en-GB")} positions compared; the colours run from \u2212${R(v,E)} to +${R(v,E)}, zero in the middle${j?" (no difference is over 1% of the level, so the groups do not differ in a way worth reading)":""}. Grey: a position one group has no value at.`:`${l} and ${d} have no position with a value of ${i} in common.`,n.compared&&h.append(" ",K(m,te.heatmap),".");const C=e.items[0]?.source;if(!C||!n.compared)return;const{metadata:re,...F}=C.wafer,H={...C,wafer:F,dies:n.dies,passBins:[...e.items[0].passBins],testDefs:[{testNumber:0,name:`${i}: ${l} \u2212 ${d}`,unit:E}]},V=[-(v||1),v||1];u=oe(r,H,{viewOptions:{plotMode:"value",activeTest:0,valueRange:V,valueColorScheme:"diverging"},showIdentity:!1,insights:{enabled:!1},onSaveImage:o.onSaveImage,chromeInset:q,onExpand:()=>c.querySelector("[data-wmap-card-expand]")?.click()}),u.setViewControlsVisible(!1),u.setSummaryVisible(!1)}return y(),{card:c,setTest:e=>{if(!M||!p.some(a=>a.testNumber===e)||String(e)===t)return;t=String(e);const s=T();N.replaceWith(s),N=s,y()},destroy:()=>{B.disconnect(),u?.destroy()}}}
@@ -23,6 +23,11 @@ export interface DrilldownContext {
23
23
  * `narrower` is the population it left, so the row swaps back. Set by a gallery when dies are selected on several
24
24
  * wafers and the right-click is on one of them.
25
25
  */
26
+ /**
27
+ * Swap the map's selection for the dies it does not hold, offered as a "Selection" row. Set by a single map when it has a
28
+ * selection; absent in a gallery, whose selection spans several wafers.
29
+ */
30
+ onInvertSelection?: () => void;
26
31
  narrower?: {
27
32
  label: string; /** The swap-back row's wording before the population; default "All selected". */
28
33
  backLabel?: string;
@@ -1 +1 @@
1
- import{isYieldEligibleDie as T}from"../core/dies.js";import{testValue as R}from"../core/dieTable.js";import{isParametricTest as C}from"../renderer/buildWaferMap.js";import{buildSweepData as k}from"../stats/sweep.js";import{plotToSweep as E}from"../stats/plotSpec.js";import{renderPlotCard as F}from"./plotCard.js";import{renderCapabilityPanel as L}from"./charts/capability.js";import{makeTestSelect as O,openChartExpandModal as V,populationPhrase as v}from"./charts/chartShell.js";import{openCommandMenu as W,CLR as A,FONT as B,SPACE as q,openReparentedModal as z}from"./toolbar.js";import{requireRingCount as _}from"../core/ringCount.js";import{defaultPlot as j,defaultSweep as H,fieldCatalogue as K,plotTitle as U,resolvePlot as Y}from"../stats/plotData.js";import{newPlotId as M}from"../stats/plotSpec.js";import{sourceFromPoints as G,toPlotItems as S}from"./plotItems.js";const N=30,b=e=>e.items.flatMap(t=>t.dies);function J(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>T(n))}))}function y(e,t,n){return(e.testDefs??[]).filter(C).map(s=>s.testNumber).filter(s=>{let l=0;for(const o of t){const r=R(o,s);if(r!==void 0&&Number.isFinite(r)&&++l>=n)return!0}return!1})}function $(e,t,n,s,l){const o=e.ownerDocument.createElement("div");o.textContent=n,o.dataset.wmapPopulation="1",Object.assign(o.style,{color:A.label,fontSize:B.body,marginBottom:q.sm});const r=e.querySelector("[data-wmap-card-menu]")?.parentElement;r?.parentElement===e?r.after(o):e.prepend(o);const p=V(e,t,{anchor:s,onClosed:l});return()=>p?.close()}function Q(e,t){const n=b(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(l=>T(l))?k(n,t.testDefs,e).series.some(l=>l.points.some(o=>o.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function X(e,t,n){const s=J(e),l=b(e).length,o=s.flatMap(a=>a.dies),r=v(o.length,l,e.population),p=(e.testDefs??[]).filter(C),c=n.ownerDocument,u=(a,i)=>e.notMeasuredReason?e.notMeasuredReason:o.length===0?"These dies are all partial or edge-excluded, which charts leave out":y(e,o,a).length>0?null:i,d={section:"Distributions",label:"Value histogram",unavailable:u(1,"These dies have no parametric test values"),open:()=>{let a=e.activeTest??p[0]?.testNumber;const i=p.filter(D=>D.testNumber!==void 0),f=O(i,a??null,D=>{a=D,w.refresh()},{ownerDocument:c}),h=S(s),g=I(e,t,n);let P;const w=F({doc:c,items:h,ctx:{testDefs:p,curation:t.attributes},extras:[f],spec:{choices:[],build:()=>({id:"drill-histogram",title:"Value histogram",chart:"histogram",fields:{y:{slot:"test"},color:{none:!0}}})},slots:()=>({test:a}),chart:{onSaveImage:t.onSaveImage,binColors:t.getBinColors?.()},editAsPlot:g?D=>{P?.(),g(D,!0)()}:void 0});P=$(w.card,`Value histogram \u2014 ${r}`,`Population: ${r}`,n,()=>w.destroy())}},m={section:"Distributions",label:"Process capability",unavailable:u(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const a=L({title:"Process capability",items:s,testDefs:p,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:c}),i=o.length<N?` \xB7 fewer than ${N} dies, so each Ppk is a rough estimate`:"";$(a.card,`Process capability \u2014 ${r}`,`Population: ${r}${i}`,n,()=>a.destroy())}};return[d,m]}function I(e,t,n){const s=t.plots;if(!s)return null;const l=n.ownerDocument,o=S(e.items),r={testDefs:e.testDefs,curation:t.attributes},p=b(e),c=v(p.length,p.length,e.population),u=v(p.filter(d=>T(d)).length,p.length,e.population);return(d,m)=>()=>{const a=d.chart==="sweep",i=a?u:c;import("./plotModal.js").then(({openPlotEditor:f})=>f({doc:l,anchor:n,store:s,plot:d,draft:m,items:o,ctx:r,population:i,rawPopulation:e.population,title:`${m?a?"New sweep":"New plot":a?"Sweep":"Plot"} \u2014 ${i}`,chart:{onSaveImage:t.onSaveImage,binColors:t.getBinColors?.(),onSelectPoints:(h,g,P)=>{const w=G(h,o,e.testDefs);w&&openDrilldownMenu(g,P,w,t)}}}))}}function Z(e,t,n){const s=t.plots,l=I(e,t,n);if(!s||!l)return[];const o=S(e.items),r={testDefs:e.testDefs,curation:t.attributes},p=b(e),c=e.notMeasuredReason??(p.length===0?"Nothing is selected":null),u=s.get().map(i=>{const f=E(i);if(f)return{section:"Plots",label:f.title,unavailable:Q(f,e),open:l(i,!1)};const h=Y(i,o,r);return{section:"Plots",label:U(h)||"Plot",unavailable:c??h.issues[0]??(h.plotted===0?"No die here has the values this plot needs":null),open:l(i,!1)}}),d=K(o,r),m=d.some(i=>i.group==="Tests");u.push({section:"Plots",label:"New plot\u2026",unavailable:c??(m?null:"These dies have no parametric test values"),open:l(j(d,M()),!0)});const a=(e.testDefs??[]).filter(i=>C(i));return u.push({section:"Plots",label:"New sweep\u2026",unavailable:c??(a.length>0?null:"These dies have no parametric test values"),open:l(H(e.testDefs??[],M()),!0)}),u}function x(e,t,n){const s=b(e),l=e.notMeasuredReason??(s.length===0?"Nothing is selected":null),o=s.length,r=v(o,o,e.population),p=(c,u)=>()=>{import("./dataTab.js").then(({renderSelectionTables:d})=>{const m=n.ownerDocument;let a;const i=d({doc:m,ringCount:_(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:c,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(h,g)=>{a?.(),t.onLocateDie(h,g)}:void 0}),f=z([i.el],{title:`${u} \u2014 ${r}`,anchor:n,ownerDocument:m,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:i.destroy});f?a=()=>f.close():i.destroy()})};return[{section:"Tables",label:"Test statistics",unavailable:l??(y(e,s,1).length>0?null:"These dies have no parametric test values"),open:p("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:l,open:p("wafers","Wafers")}]:[],{section:"Tables",label:"Dies",unavailable:l,open:p("dies","Dies")}]}function ee(e,t,n){return[...X(e,t,n),...Z(e,t,n),...x(e,t,n)]}export function openDrilldownMenu(e,t,n,s){const l=ee(n,s,t),o=[];if(s.narrower){const{label:u,source:d,ctx:m}=s.narrower,a={label:`${s.narrower.backLabel??"All selected"} \u2014 ${v(b(n).length,b(n).length,n.population)}`,source:n,ctx:s};o.push({section:"Dies"}),o.push({label:u,active:!1,action:!0,enabled:!0,onClick:()=>{c(),openDrilldownMenu(e,t,d,{...m??s,narrower:a})}})}let r;for(const u of l)u.section!==r&&(o.push({section:u.section}),r=u.section),o.push({label:u.label,active:!1,action:!0,enabled:u.unavailable===null,disabledHint:u.unavailable??void 0,onClick:()=>{c(),u.open()}});const p=b(n).length,c=W(new DOMRect(e.x,e.y-4,0,0),t,o,`Open a chart or table of ${v(p,p,n.population)}`,{hook:"wmapDrilldownMenu"});return c}
1
+ import{isYieldEligibleDie as $}from"../core/dies.js";import{testValue as A}from"../core/dieTable.js";import{isParametricTest as N}from"../renderer/buildWaferMap.js";import{buildSweepData as W}from"../stats/sweep.js";import{plotToSweep as _}from"../stats/plotSpec.js";import{renderPlotCard as q}from"./plotCard.js";import{renderCapabilityPanel as z}from"./charts/capability.js";import{makeTestSelect as j,openChartExpandModal as H,populationPhrase as P}from"./charts/chartShell.js";import{openCommandMenu as K,CLR as U,FONT as Y,SPACE as G,openReparentedModal as J}from"./toolbar.js";import{requireRingCount as Q}from"../core/ringCount.js";import{defaultPlot as X,defaultSweep as Z,fieldCatalogue as ee,plotTitle as te,resolvePlot as ne}from"../stats/plotData.js";import{newPlotId as k}from"../stats/plotSpec.js";import{sourceFromPoints as oe,toPlotItems as y}from"./plotItems.js";const E=30,x=10,v=e=>e.items.flatMap(t=>t.dies);function se(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>$(n))}))}function V(e,t,n){return(e.testDefs??[]).filter(N).map(s=>s.testNumber).filter(s=>{let a=0;for(const o of t){const c=A(o,s);if(c!==void 0&&Number.isFinite(c)&&++a>=n)return!0}return!1})}function L(e,t,n,s,a){const o=e.ownerDocument.createElement("div");o.textContent=n,o.dataset.wmapPopulation="1",Object.assign(o.style,{color:U.label,fontSize:Y.body,marginBottom:G.sm});const c=e.querySelector("[data-wmap-card-menu]")?.parentElement;c?.parentElement===e?c.after(o):e.prepend(o);const p=H(e,t,{anchor:s,onClosed:a});return()=>p?.close()}function le(e,t){const n=v(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(a=>$(a))?W(n,t.testDefs,e).series.some(a=>a.points.some(o=>o.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function ie(e,t,n){const s=se(e),a=v(e).length,o=s.flatMap(i=>i.dies),c=P(o.length,a,e.population),p=(e.testDefs??[]).filter(N),d=n.ownerDocument,r=(i,l)=>e.notMeasuredReason?e.notMeasuredReason:o.length===0?"These dies are all partial or edge-excluded, which charts leave out":V(e,o,i).length>0?null:l,f=(i,l,b,w,g,T)=>{let D=e.activeTest??p[0]?.testNumber;const C=p.filter(S=>S.testNumber!==void 0),B=j(C,D??null,S=>{D=S,M.refresh()},{ownerDocument:d}),I=g?null:O(e,t,n);let R;const F=i==="box"?{x:{builtin:"wafer"},y:{slot:"test"},color:{none:!0}}:{y:{slot:"test"},color:g?{builtin:"wafer"}:{none:!0}},M=q({doc:d,items:y(b),ctx:{testDefs:p,curation:t.attributes,...T?{populationLabel:T}:{}},extras:[B],spec:{choices:[],build:()=>({id:`drill-${i}${g?"-compare":""}`,title:l,chart:i,fields:F,...g&&i==="box"?{axes:{x:{label:"Dies"}}}:{}})},slots:()=>({test:D}),chart:{onSaveImage:t.onSaveImage,binColors:t.getBinColors?.()},editAsPlot:I?S=>{R?.(),I(S,!0)()}:void 0});R=L(M.card,`${l} \u2014 ${w}`,`Population: ${w}`,n,()=>M.destroy())},m={section:"Distributions",label:"Value histogram",unavailable:r(1,"These dies have no parametric test values"),open:()=>f("histogram","Value histogram",s,c,!1)},h={section:"Distributions",label:"Process capability",unavailable:r(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const i=z({title:"Process capability",items:s,testDefs:p,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:d}),l=o.length<E?` \xB7 fewer than ${E} dies, so each Ppk is a rough estimate`:"";L(i.card,`Process capability \u2014 ${c}`,`Population: ${c}${l}`,n,()=>i.destroy())}};return[m,h,...u()];function u(){const i=e.rest;if(!i||e.items.length!==1)return[];const[l]=s,b=i.dies.filter(C=>$(C)),w=r(1,"These dies have no parametric test values")??(l.dies.length===0?"None of the selected dies counts in a chart (partial or edge-excluded dies are left out)":b.length===0?"Every other die on the wafer is partial or edge-excluded":null),g=[{...l,label:`Selected on ${l.label} (${l.dies.length})`},{...i,dies:b,label:`Rest of ${l.label} (${b.length})`}],T=`${l.dies.length.toLocaleString()} selected dies against the other ${b.length.toLocaleString()} on ${l.label}`,D=Math.min(l.dies.length,b.length)<x?` \xB7 fewer than ${x} dies on one side, so read the spread rather than small differences`:"";return[{section:"Selection vs the rest of the wafer",label:"Value histogram",unavailable:w,open:()=>f("histogram","Value histogram, selection vs rest",g,T+D,!0,`selection vs the rest of ${l.label}`)},{section:"Selection vs the rest of the wafer",label:"Box plot",unavailable:w,open:()=>f("box","Box plot, selection vs rest",g,T+D,!0,`selection vs the rest of ${l.label}`)}]}}function O(e,t,n){const s=t.plots;if(!s)return null;const a=n.ownerDocument,o=y(e.items),c={testDefs:e.testDefs,curation:t.attributes},p=v(e),d=P(p.length,p.length,e.population),r=P(p.filter(f=>$(f)).length,p.length,e.population);return(f,m)=>()=>{const h=f.chart==="sweep",u=h?r:d;import("./plotModal.js").then(({openPlotEditor:i})=>i({doc:a,anchor:n,store:s,plot:f,draft:m,items:o,ctx:c,population:u,rawPopulation:e.population,title:`${m?h?"New sweep":"New plot":h?"Sweep":"Plot"} \u2014 ${u}`,chart:{onSaveImage:t.onSaveImage,binColors:t.getBinColors?.(),onSelectPoints:(l,b,w)=>{const g=oe(l,o,e.testDefs);g&&openDrilldownMenu(b,w,g,t)}}}))}}function ae(e,t,n){const s=t.plots,a=O(e,t,n);if(!s||!a)return[];const o=y(e.items),c={testDefs:e.testDefs,curation:t.attributes},p=v(e),d=e.notMeasuredReason??(p.length===0?"Nothing is selected":null),r=s.get().map(u=>{const i=_(u);if(i)return{section:"Plots",label:i.title,unavailable:le(i,e),open:a(u,!1)};const l=ne(u,o,c);return{section:"Plots",label:te(l)||"Plot",unavailable:d??l.issues[0]??(l.plotted===0?"No die here has the values this plot needs":null),open:a(u,!1)}}),f=ee(o,c),m=f.some(u=>u.group==="Tests");r.push({section:"Plots",label:"New plot\u2026",unavailable:d??(m?null:"These dies have no parametric test values"),open:a(X(f,k()),!0)});const h=(e.testDefs??[]).filter(u=>N(u));return r.push({section:"Plots",label:"New sweep\u2026",unavailable:d??(h.length>0?null:"These dies have no parametric test values"),open:a(Z(e.testDefs??[],k()),!0)}),r}function re(e,t,n){const s=v(e),a=e.notMeasuredReason??(s.length===0?"Nothing is selected":null),o=s.length,c=P(o,o,e.population),p=(d,r)=>()=>{import("./dataTab.js").then(({renderSelectionTables:f})=>{const m=n.ownerDocument;let h;const u=f({doc:m,ringCount:Q(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:d,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(l,b)=>{h?.(),t.onLocateDie(l,b)}:void 0}),i=J([u.el],{title:`${r} \u2014 ${c}`,anchor:n,ownerDocument:m,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:u.destroy});i?h=()=>i.close():u.destroy()})};return[{section:"Tables",label:"Test statistics",unavailable:a??(V(e,s,1).length>0?null:"These dies have no parametric test values"),open:p("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:a,open:p("wafers","Wafers")}]:[],{section:"Tables",label:"Dies",unavailable:a,open:p("dies","Dies")}]}function pe(e,t,n){return[...ie(e,t,n),...ae(e,t,n),...re(e,t,n)]}export function openDrilldownMenu(e,t,n,s){const a=pe(n,s,t),o=[];if(s.onInvertSelection){const r=s.onInvertSelection;o.push({section:"Selection"}),o.push({label:"Invert selection",active:!1,action:!0,enabled:!0,onClick:()=>{d(),r()}})}if(s.narrower){const{label:r,source:f,ctx:m}=s.narrower,h={label:`${s.narrower.backLabel??"All selected"} \u2014 ${P(v(n).length,v(n).length,n.population)}`,source:n,ctx:s};o.push({section:"Dies"}),o.push({label:r,active:!1,action:!0,enabled:!0,onClick:()=>{d(),openDrilldownMenu(e,t,f,{...m??s,narrower:h})}})}let c;for(const r of a)r.section!==c&&(o.push({section:r.section}),c=r.section),o.push({label:r.label,active:!1,action:!0,enabled:r.unavailable===null,disabledHint:r.unavailable??void 0,onClick:()=>{d(),r.open()}});const p=v(n).length,d=K(new DOMRect(e.x,e.y-4,0,0),t,o,`Open a chart or table of ${P(p,p,n.population)}`,{hook:"wmapDrilldownMenu"});return d}
@@ -0,0 +1,25 @@
1
+ import { type PlotFilter } from '../stats/plotSpec.js';
2
+ import type { CompletionSource } from './plotJsonComplete.js';
3
+ export interface FilterJsonOptions {
4
+ doc: Document;
5
+ /** The filter now in force in the window's draft. */
6
+ filter: PlotFilter | undefined;
7
+ /** What the suggestions know of the lot: its fields, its tests, and the values a field takes. */
8
+ source: () => CompletionSource;
9
+ /** The text now reads as this filter (undefined: no conditions). Called as the text is typed. */
10
+ onChange: (filter: PlotFilter | undefined) => void;
11
+ /** The text cannot be a filter yet (said in words), or can again (undefined). */
12
+ onProblem: (problem: string | undefined) => void;
13
+ }
14
+ export interface FilterJsonHandle {
15
+ el: HTMLElement;
16
+ /** Show `filter` in the text (an edit the history can undo). */
17
+ set(filter: PlotFilter | undefined): void;
18
+ /** Put the text back as the draft stands, dropping what could not be read. */
19
+ discard(filter: PlotFilter | undefined): void;
20
+ focus(): void;
21
+ }
22
+ /** The filter as text: always with its conditions list, so an empty filter shows where conditions go. */
23
+ export declare const filterText: (f: PlotFilter | undefined) => string;
24
+ export declare function buildFilterJsonPanel(o: FilterJsonOptions): FilterJsonHandle;
25
+ //# sourceMappingURL=filterJson.d.ts.map
@@ -0,0 +1,5 @@
1
+ import{nearest as E,readFilter as F,syntaxErrorAt as O}from"../stats/plotSpec.js";import{FILTERS_FORMAT as T,readFiltersFile as j}from"../stats/filterFile.js";import{attachJsonSuggestions as A}from"./plotJsonSuggest.js";import{copyText as J,createTextHistory as N}from"./plotJsonHistory.js";import{CLR as c,FONT as S,SPACE as x,controlStyle as k,wireControlHover as L,wireTooltip as $}from"./toolbar.js";import{inputStyle as K}from"./charts/chartShell.js";const C=["conditions","off","field","values","min","max","not"];export const filterText=i=>JSON.stringify(i??{conditions:[]},null,2);function z(i){let o;try{o=JSON.parse(i)}catch(n){return{problem:`Not valid JSON: ${O(i,n instanceof Error?n.message:String(n))}`,notes:[]}}const a=typeof o=="object"&&o!==null&&!Array.isArray(o);if(Array.isArray(o)||a&&o.format===T){const n=j(i);return n.error?{problem:[n.error,...n.warnings].join(`
2
+ `),notes:[]}:n.filters.length>1?{choices:n.filters,notes:n.warnings,problem:"This is a filters file: choose the filter to use"}:{filter:{conditions:n.filters[0].conditions},notes:n.warnings}}if(!a)return{problem:'A filter is an object with a "conditions" list, like { "conditions": [ \u2026 ] }',notes:[]};const t=[];for(const n of Object.keys(o))if(!C.includes(n)){const f=E(n,C);t.push(`filter.${n}: not a setting of a filter, ignored.${f?` Did you mean "${f}"?`:""}`)}const d=F(o,"filter",t);return d?{filter:d,notes:t}:(Array.isArray(o.conditions)?o.conditions.length:0)>0?{problem:["No condition could be read:",...t].join(`
3
+ `),notes:[]}:{filter:null,notes:t}}export function buildFilterJsonPanel(i){const{doc:o}=i,a=o.createElement("div");a.dataset.wmapFilterJson="1",Object.assign(a.style,{display:"flex",flexDirection:"column",gap:x.sm,minWidth:"0"});const t=o.createElement("textarea");t.dataset.wmapFilterJsonText="1",t.value=filterText(i.filter),t.spellcheck=!1,t.rows=14,t.setAttribute("aria-label","Filter as JSON"),Object.assign(t.style,{...K(),fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:S.sub,width:"100%",boxSizing:"border-box",resize:"vertical",whiteSpace:"pre",overflow:"auto"});const d=A({doc:o,area:t,source:i.source,as:"filter"}),n=N(t),f=o.createElement("div");f.append(t,d.el);const r=o.createElement("div");r.dataset.wmapFilterJsonStatus="1",r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),Object.assign(r.style,{fontSize:S.sub,minHeight:"1.4em",whiteSpace:"pre-wrap",color:c.label});const u=o.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:x.xs,alignItems:"flex-start"});const b=(e,l)=>{const s=o.createElement("button");return s.type="button",s.textContent=e,$(s,l),Object.assign(s.style,k("outlined")),L(s),s},y=b("Suggest","Show what can be written at the cursor (also Ctrl/Cmd+Space)");y.dataset.wmapFilterJsonSuggest="1",y.addEventListener("click",()=>{d.show()||(r.style.color=c.label,r.textContent="Nothing to suggest at the cursor")});const w=b("Copy","Copy the text to the clipboard");w.addEventListener("click",()=>{const e=l=>{r.style.color=l?c.label:c.errText,r.textContent=l?"Copied":"The text could not be copied: select it and copy by hand"};J(o,t.value,e)});const h=o.createElement("div");Object.assign(h.style,{display:"flex",gap:x.sm}),h.append(y,w);const v=e=>{t.focus(),t.select(),o.execCommand?.("insertText",!1,e)||(t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))),t.setSelectionRange(0,0)},p=()=>{const e=z(t.value);if(u.replaceChildren(),e.problem){r.style.color=c.errText,r.textContent=e.problem,i.onProblem(e.problem),e.choices?.forEach((s,m)=>{const g=b(`${m+1}. ${s.name}`,"Use this filter from the file");g.dataset.wmapFilterJsonChoice=String(m),g.addEventListener("click",()=>v(filterText({conditions:s.conditions}))),u.appendChild(g)});return}i.onProblem(void 0),i.onChange(e.filter??void 0);const l=e.filter?.conditions.length??0;r.style.color=e.notes.length?c.errText:c.label,r.textContent=e.notes.length?`Left out or ignored:
4
+ ${e.notes.join(`
5
+ `)}`:l===0?"No conditions: every wafer and die is shown":`${l} condition${l===1?"":"s"}`};return t.addEventListener("input",p),t.addEventListener("keydown",e=>{if(!(e.ctrlKey||e.metaKey)||e.altKey)return;const l=e.key.toLowerCase(),s=l==="z"&&!e.shiftKey,m=l==="z"&&e.shiftKey||l==="y";!s&&!m||(s?n.canUndo:n.canRedo)&&(e.preventDefault(),s?n.undo():n.redo())}),a.append(f,h,r,u),p(),{el:a,set:e=>{filterText(e)!==t.value?v(filterText(e)):p()},discard:e=>{t.value=filterText(e),p()},focus:()=>t.focus()}}
@@ -6,6 +6,7 @@ export { WAFER_PREFERENCE_KEYS } from './renderWaferMap.js';
6
6
  export { renderWaferGallery } from './renderWaferGallery.js';
7
7
  export type { WaferMapDisplayItem, WaferMapDisplayItemFactory, GalleryOptions, GalleryController } from './renderWaferGallery.js';
8
8
  export type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
9
+ export { getPinnedTests, setPinnedTests, onPinnedTestsChange } from './pinnedTests.js';
9
10
  export type { DieListDisplayOptions } from './dieList.js';
10
11
  export { collectWarnings, severityOf } from './warnings.js';
11
12
  export type { WarningsOptions } from './warnings.js';
@@ -1 +1 @@
1
- export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{WAFER_PREFERENCE_KEYS}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
1
+ export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{WAFER_PREFERENCE_KEYS}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{getPinnedTests,setPinnedTests,onPinnedTestsChange}from"./pinnedTests.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
@@ -1 +1 @@
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 an,makeLinkedAxisPrefs as sn,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 ae}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:se}=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}),at=We.el;G.appendChild(Z),G.appendChild(_),G.appendChild(at),G.appendChild(Q);const st=[...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:se})}}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:se})}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=ae({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}}),s=ae({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=s.current().fields.x,a=v&&!Array.isArray(v)&&"builtin"in v&&v.builtin==="sbin"?"sbin":"hbin",y=new Set(m.map(T=>a==="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 ${a==="hbin"?"hard":"soft"} bin ${$}${A!==void 0?` of ${A}`:""}`,T=>xn(T)&&(a==="hbin"?T.hbin:T.sbin)===$)}}});return s.card.style.minHeight="360px",u.appendChild(s.card),{card:u,destroy:()=>{C?.destroy(),s.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,s=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=ae({doc:c,editAsPlot:te,items:s,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 a=At(p.map(y=>({key:y.key,items:y.items.map($=>({dies:$.dies}))})),n,v).disagreementDies;return a?[`${a.toLocaleString("en-GB")} die${a===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,a,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,a,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,s)=>{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(s,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=(s,m)=>bn(s,m.reticle),S=De(h,u,f,s=>e[s].passBins,w);if(S.length){const s=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(s.card),g.push(s.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,showMap:B.showPatMap});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=ae({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:se,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:se,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(a=>({label:a.identity??a.label,dies:a.dies,waferIndex:a.waferIndex,wafer:a.wafer,passBins:a.passBins,ringCount:V()}))),r=t.filter(a=>a.testNumber!==void 0),g=!!n&&!!F,p=g&&R!==null,o={testDefs:t,groupBy:g?F:void 0,curation:B.attributes},l=(a,y,$)=>({limits:y.limits??"both",axes:{[a]:{...y.includeLimits!==void 0?{includeLimits:y.includeLimits}:{},...y.clipOutliers?{clip:!0}:{},...$?{scale:"log"}:{}}}});function b(a){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=sn(T,y,j=>{y=j,A?.refresh(),we(j,D)},c),re=[I.el,T];a.logToggle&&re.push(on("Log scale",$,j=>{$=j,A?.refresh()},c,"Draw the value axis on a logarithmic scale")),re.push(...a.extras??[]),A=ae({doc:c,editAsPlot:te,items:f,ctx:o,...a.card,spec:{choices:[],build:()=>a.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,a.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:a.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?(a,y)=>h.open(f[a]?.waferIndex??a,y??H??r[0]?.testNumber??0):void 0,C=b({valueRole:"y",logToggle:!0,build:(a,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",a,y)}),card:{...g&&!p?{drill:a=>{const y=Be(f[a[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(a=>({label:a.label})),null,a=>{L=a,S.refresh()},{ownerDocument:c})],S=b({valueRole:"x",extras:w,card:R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{},build:a=>({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",a,!1)}),chart:{onSaveImage:P,...g?{onLegendPick:a=>ie(a),legendPicked:R}:{},onSelectPoints:(a,y,$,A)=>{const I=t.find(M=>M.testNumber===(H??r[0]?.testNumber)),T=new Set(a.map(M=>M.die).filter(M=>!!M)),D=new Set(a.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)}}}),s=b({valueRole:"y",build:a=>({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",a,!1),axes:{...l("y",a,!1).axes,y:{...l("y",a,!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:(a,y,$)=>{const A=new Set(a.map(D=>D.item));if(A.size===1&&k){k([...A][0]);return}const I=new Set(a.map(D=>D.die).filter(D=>!!D)),T=new Set(a.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=a=>{H=a,C.setTest(a),S.setTest(a),s.setTest(a),v.setTest(a),E?.setTest(a),i?.setTest(a)},x=()=>Kt({groups:n,testDefs:t,groupLabelText:d,control:Fe,onControlChange:a=>{Fe=a;const y=x();E.card.replaceWith(y.card),E=y},selectedTestNumber:H??void 0,onSelectTest:a=>m(a),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,s]);const v=qt({title:"Process capability",items:e,testDefs:t,onSaveImage:P,selectedTestNumber:H??void 0,onSelectTest:a=>m(a),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,s.card),{card:u,destroy:()=>{v.destroy(),C.destroy(),S.destroy(),s.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 a=c.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:N.body,color:W.label});const y=c.createElement("span");return y.textContent=i,a.append(y,v),a},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(a=>a.testNumber===v));L.replaceChildren(...i.some(Xe)?[an(o.limits??"both",v=>{o={...o,limits:v},x.refresh(),we(o,w)},c)]:[])}const s=i=>{const v=t.find(a=>a.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=ae({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:s(r),y:s(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,a)=>{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,a,{items:$,population:A,testDefs:t,activeTest:r},{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:se})}}});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 s of st)_.appendChild(rt(s.key,s.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(s=>s.splittable);be=u.map(s=>({key:s.key,label:s.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(s=>({value:s.key,label:`${s.label} (${s.values.length})`}))],F??"",s=>{F=s||void 0,R=null,q()},{hook:"group-by",ownerDocument:c})),f=u.find(s=>s.key===F)?.label):F=void 0;let r;if(F){const s=new Map,m=[];for(const x of d){const E=Be(x.metadata,F,de)??Tt;s.has(E)||(s.set(E,[]),m.push(E)),s.get(E).push(x)}r=Cn(m).map(x=>({key:x,items:s.get(x)}))}R!==null&&!r?.some(s=>s.key===R)&&(R=null),r&&r.length>0&&h.appendChild(tn(r.map(s=>s.key),"Show:",R,s=>ie(s),{ownerDocument:c}).el);let g=null;if(B.onOpenGuide){const s=c.createElement("button");s.type="button",s.innerHTML=_t.help,s.setAttribute("aria-label","User guide"),Object.assign(s.style,{..._e("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),fe(s,"bare"),Ie(s,"User guide"),s.addEventListener("click",()=>B.onOpenGuide()),Object.assign(s.style,{marginLeft:"auto"}),g=s}_.appendChild(h),g&&_.appendChild(g);const p=R!==null?r?.find(s=>s.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(s=>s.testNumber===H)&&(H=null),d.length===0){const s=c.createElement("div");s.dataset.wmapInsightsFilterEmpty="1",s.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(s.style,{color:W.label,fontSize:N.body,padding:O.xl}),Q.appendChild(s);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(s=>s.excluded);if(S.length>0){const s=c.createElement("div");Object.assign(s.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";s.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."),s.dataset.wmapWithheldTests=String(S.length),Q.appendChild(s)}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}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as Zt}from"../stats/presentation.js";import{buildFacetTable as en,facetValueOf as ze,FACET_NONE_VALUE as tn,DEFAULT_FACET_CURATION as nn}from"../stats/facets.js";import{mergeTestDefs as He}from"../stats/mergeTestDefs.js";import{isParametricTest as Ce}from"../renderer/buildWaferMap.js";import{dieFailsTest as sn,hasJudgeableTests as an,testsForPassKind as rn,buildTestPassRateData as ot}from"../stats/testPassRate.js";import{fmt as lt}from"../renderer/fmt.js";import{testLabel as dt}from"../renderer/testLabel.js";import{waferDisplayLabel as on,waferIdentityLabel as ln}from"../core/waferLabel.js";import{waferPopulation as dn}from"./chartPopulation.js";import{openDrilldownMenu as Ye}from"./drilldown.js";import{plotStoreFor as cn}from"./plotStore.js";import{createPageFilter as un}from"./pageFilter.js";import{bandButton as fn}from"./filterButton.js";import{itemPassBins as pn,passBinsLabel as ct}from"../core/passBins.js";import{describeWaferPopulation as hn,populationStat as mn}from"../stats/population.js";import{LEADING as Ve,ALPHA as bn,SPACE as O,EDGE_GUTTER as _e,FONT as G,CLR as M,RADIUS as gn,SHADOW as yn,controlStyle as ut,wireControlHover as Be,wireTooltip as ke}from"./toolbar.js";import{ICONS as wn}from"./icons.js";import{renderCapabilityPanel as xn}from"./charts/capability.js";import{renderGroupComparisonPanel as vn}from"./charts/groupComparison.js";import{renderCommonalityPanel as Sn}from"./charts/commonality.js";import{renderPatCard as Cn}from"./charts/patCard.js";import{renderDifferenceMapPanel as Bn}from"./differenceMapPanel.js";import{renderCorrelationPanel as kn}from"./charts/correlation.js";import{cardFrameStyle as $n,pairCards as En,makeChartGridWrap as $e,makeLabeledSelect as ft,makeLinkedGroupSelect as Tn,makeLinkedTestSelect as pt,makeWaferSelect as ht,makeTestSelect as mt,isExpandedCard as In,makeLinkedAxisPrefs as bt,makeToggle as Ge,limitLines as Ee,limitExtent as gt,shouldIncludeLimitsByDefault as yt,hasBothLimitKinds as wt}from"./charts/chartShell.js";import{maxOf as xt,minOf as vt}from"../core/utils.js";import{buildYieldData as St,buildYieldDataCombined as On}from"../stats/yield.js";import{buildLotTestSectionSteps as An,buildLotFunctionalSection as Ln,buildMetadataStripBox as Dn}from"./summaryPanel.js";import{runChunked as Pn}from"./chunked.js";import{buildRegionYieldData as qe,buildRingRegions as Ct,buildQuadrantRegions as Bt,buildReticlePositionRegions as Wn,diesInRegion as Rn}from"../stats/regions.js";import{renderDataSection as Nn}from"./dataTab.js";import{sourceFromDies as Mn,toPlotItems as re}from"./plotItems.js";import{rankTestsByWaferSpread as Fn}from"../stats/testsByWafer.js";import{isYieldEligibleDie as jn}from"../core/dies.js";import{renderPlotCard as zn}from"./plotCard.js";import{orderFieldValues as Hn,axisValues as kt}from"../stats/plotData.js";import{buildSynthesis as Yn,groupColouredChart as Vn,synthesisKey as _n}from"../stats/synthesis.js";import{commonPassBins as Gn}from"../core/passBins.js";import{renderRegionYieldDiagram as Ke}from"./charts/regionYieldDiagram.js";const qn=12,Kn=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Xn={key:"data",label:"Data"},Un={key:"plot",label:"My plots"},Qn={overview:"Yield, bins and what stands out",distributions:"How each test\u2019s values spread",correlation:"How tests move together",data:"The same scope as tables, with CSV exports",plot:"Plots you have built and saved"};export function createInsightsTab(T){const{getItems:$t,getLotStats:Xe,getBinColors:ie,getRingCount:Q,onSaveImage:W,onSaveText:J,openWafer:oe,focusTest:Te,locateDie:me}=T,ye={...nn,...T.attributes},Et=T.showMetadataStrip??!0,le=T.contentInset??_e,a=T.ownerDocument??document,Y=a.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Tt=_e,ce=a.createElement("div");Object.assign(ce.style,{paddingLeft:Tt});const te=a.createElement("div");Object.assign(te.style,{display:"flex",gap:O.xs,alignItems:"center",background:M.menuBg,border:`1px solid ${M.menuBorder}`,borderRadius:gn.container,boxShadow:yn.panel,padding:`0 ${O.lg}`,margin:"0"}),te.setAttribute("role","tablist");const Ie=a.createElement("div");Object.assign(Ie.style,{position:"sticky",top:"var(--wmap-sticky-top, 0px)",zIndex:"1",background:M.menuBg,paddingLeft:le,paddingRight:le,paddingBottom:O.lg}),Ie.appendChild(te),te.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from(te.querySelectorAll('[role="tab"]')),s=t.indexOf(a.activeElement);if(s===-1)return;e.preventDefault();const o=t[(s+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];o.focus(),o.click()});const se=a.createElement("div");Object.assign(se.style,{display:"flex",flexDirection:"column",gap:O.lg,marginTop:"0",isolation:"isolate",paddingLeft:le,paddingRight:le});const we=T.pageFilter??un({doc:a,initial:T.filter,onChange:T.onFilterChange,attributes:T.attributes,getRingCount:T.getRingCount}),Ue=we.createBand(()=>Me(),{marginLeft:le,marginRight:le,marginBottom:O.lg}),It=Ue.el;let de,Oe=null;const Ot=()=>{let e=0;for(const t of Array.from(Y.querySelectorAll("[data-wmap-chart-grid]")))t.offsetParent!==null&&(e=Math.max(e,Array.from(t.children).filter(s=>s.offsetParent!==null).length));return e},xe=()=>{if(de===void 0){Y.style.removeProperty("--wmap-insights-cols"),Y.style.removeProperty("--wmap-insights-min");return}const e=Ot(),t=e>0?Math.min(de,e):de;Y.style.getPropertyValue("--wmap-insights-cols")!==String(t)&&Y.style.setProperty("--wmap-insights-cols",String(t)),Y.style.setProperty("--wmap-insights-min","0px")},Qe=e=>{de=e,xe(),Oe&&(Oe.value=e===void 0?"auto":String(e))},Je=a.defaultView?.MutationObserver;let Ae=0;const Ze=Je?new Je(()=>{if(Ae||de===void 0)return;const e=a.defaultView;if(!e){xe();return}Ae=e.requestAnimationFrame(()=>{Ae=0,xe()})}):void 0;Ze?.observe(se,{childList:!0,subtree:!0});const et=e=>{if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.defaultPrevented||!/^[0-5]$/.test(e.key)||!Y.isConnected||Y.style.display==="none"||a.querySelector('[data-wmap-panels-hover], [role="dialog"]'))return;const t=e.target;typeof t?.closest=="function"&&t.closest('input, textarea, select, [contenteditable="true"], [role="menu"], [role="dialog"]')||(e.preventDefault(),Qe(e.key==="0"?void 0:Number(e.key)))};a.addEventListener("keydown",et),Y.appendChild(ce),Y.appendChild(Ie),Y.appendChild(It),Y.appendChild(se);const At=[...Kn,Xn,Un],ue=T.plotStore??cn(T),Z=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:s})=>s({doc:a,anchor:Y,store:ue,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:W,binColors:ie()}}))};let X=T.defaultView==="sweeps"?"plot":T.defaultView??"overview",N,Le=!1;we.subscribe(()=>ne());let tt="statistics",nt="wide",q=null,st=null,De=[],V=null,Pe=T.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=e=>zn({...e,chart:{onSaveText:J,...e.chart}}),ae=(e,t,s)=>({limits:t.limits??"both",axes:{[e]:{...t.includeLimits!==void 0?{includeLimits:t.includeLimits}:{},...t.clipOutliers?{clip:!0}:{},...s?{scale:"log"}:{}}}}),We=new Map,Re=(e,t,s=!1)=>{Pe=e;for(const o of We.values())for(const l of o)l!==t&&l.setAxisPrefs(e);s||T.onAxisPrefsChange?.(e)},Ne=e=>{V!==e&&(V=e,ne())};let fe=new Map;function at(){for(const e of fe.values())e.destroy();fe=new Map}function rt(e,t,s){oe?.(e,t,s)}function ve(e){return(t,s,o)=>{const l=e.find(f=>f.waferIndex===t);if(!l)return;o.preventDefault();const v=dn(l.dies,{waferLabel:l.identity,testDefs:l.testDefs,activeTest:s??q??void 0,waferIndex:t,wafer:l.wafer,passBins:l.passBins,ringCount:Q()});Ye({x:o.clientX,y:o.clientY},o.target,v,{plots:ue,getBinColors:ie,onSaveImage:W,onSaveText:J,onLocateDie:me})}}function Lt(e,t,s,o,l){pe({x:e.clientX,y:e.clientY},e.target,t,s,o,l)}function pe(e,t,s,o,l,v){const f=Mn(s.map(d=>({label:d.identity??d.label,dies:d.dies,waferIndex:d.waferIndex,wafer:d.wafer,passBins:d.passBins,ringCount:Q()})),o,l,He(s).defs,v);f&&Ye(e,t,f,{plots:ue,getBinColors:ie,onSaveImage:W,onSaveText:J,onLocateDie:me})}function it(e){return oe?{open:(t,s)=>rt(t,`Wafer ${e.find(o=>o.waferIndex===t)?.label??t}`,s)}:Te&&e.length===1?{open:(t,s)=>Te(s),label:"show this test on the map"}:null}function Me(){return $t().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:on(e,t),identity:ln(e),waferIndex:t,passBins:pn(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function Dt(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${M.iconActive}`:"2px solid transparent",color:t?M.iconActive:M.label,fontWeight:t?"700":"500",fontSize:G.body,padding:`${O.sm} ${_e} ${O.md}`,cursor:"pointer"})}function Pt(e,t){const s=a.createElement("button");s.type="button",s.textContent=t;const o=e===X;Dt(s,o),s.dataset.on=o?"true":"false",Be(s,"bare"),s.dataset.wmapInsightsTab=e;const l=Qn[e];return l&&ke(s,l),s.setAttribute("role","tab"),s.setAttribute("aria-selected",o?"true":"false"),s.tabIndex=o?0:-1,s.addEventListener("click",()=>{X!==e&&(X=e,ne({keepSections:!0}))}),s}function Wt(e,t,s,o=!0){const l=$e(a),v=ie(),f=s??"group",d=ct(e.map(r=>r.passBins)),b=re(e.map(r=>({label:r.identity??r.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:r.dies,waferIndex:r.waferIndex,wafer:r.wafer,passBins:r.passBins,ringCount:Q()}))),c=He(e).defs,p=t?N:void 0,u={testDefs:c,groupBy:p,curation:T.attributes},g=(r,x,S=!1)=>({id:"card-yield",title:t?`Yield by ${f} (pass: ${d})`:`Yield by wafer (pass: ${d})`,chart:"bar",fields:{x:S?[{slot:"groupBy"},{builtin:"wafer"}]:{slot:"groupBy"},y:{builtin:"yield"},color:t?{follow:"groupBy"}:{none:!0}},...S?{}:{valueLabels:!0},...r&&!S?{sort:"value"}:{},...x>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),A=t?t.length:e.length;let k=null,$=!1;o&&(k=ee({doc:a,editAsPlot:Z,items:b,ctx:u,spec:{choices:[{current:"natural",options:r=>[["value","Sort: yield"],["natural",t&&!r?`Sort: ${f}`:"Sort: wafer"],...t&&!r?[["nested",`${f}, then wafer`,`Each ${f} with its wafers inside it`]]:[]]}],build:([r])=>($=r==="nested",g(r==="value",A,$))},drill:t&&p?r=>{if($)return null;const x=ze(b[r[0]?.item]?.metadata,p,T.attributes);if(x===void 0)return null;const S=t.find(P=>P.key===x)?.items.length??0;return P=>({...P,title:`Yield by wafer \u2014 ${f}: ${x} (pass: ${d})`,fields:{...P.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:p},values:[x]}]},axes:S>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:()=>$?void 0:"see its wafers",chart:{onSaveImage:W,onOpenWafer:oe?r=>rt(b[r].waferIndex??r,`Wafer ${b[r].label}`):void 0,onWaferMenu:ve(e)}}),k.card.style.minHeight="360px",l.appendChild(k.card));const j={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"]]},_={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`],["mix","Bin mix",`Each ${f} as one bar split into its bins, as shares of its own dies`]]},R=15,i=(r,x)=>t&&x==="mix"?{id:"card-bin-pareto",title:`${r==="sbin"?"Soft":"Hard"} bin mix by ${f}`,chart:"bar",stack:"percent",fields:{x:{slot:"groupBy"},color:{builtin:r==="sbin"?"sbin":"hbin"}}}:{id:"card-bin-pareto",title:`${r==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:r==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:r==="sbin"?"sbin":"hbin"}},...r==="sbin"?{top:R}:{},...t?x==="share"?{barNorm:"percent"}:{}:{cumulative:!0}},w=ee({doc:a,editAsPlot:Z,items:b,ctx:u,spec:t?{choices:[j,_],build:([r,x])=>i(r,x)}:{choices:[j],build:([r])=>i(r,void 0)},chart:{onSaveImage:W,binColors:v,onSelectPoints:(r,x,S,P)=>{const m=w.current().fields,E=m.x,L=m.color,F=B=>!!B&&!Array.isArray(B)&&typeof B=="object"&&"builtin"in B&&B.builtin==="sbin",D=F(E)||F(L)?"sbin":"hbin",n=new Set(r.map(B=>D==="hbin"?B.die?.hbin:B.die?.sbin));if(n.size!==1)return;const h=[...n][0];if(E&&!Array.isArray(E)&&"slot"in E){const B=new Set(r.map(I=>I.die).filter(I=>!!I)),K=new Set(r.map(I=>b[I.item]?.waferIndex));pe(x,S,e.filter(I=>K.has(I.waferIndex)),`in ${D==="hbin"?"hard":"soft"} bin ${h}`,I=>B.has(I));return}const y=t?P?.group:void 0,C=y!==void 0?t?.find(B=>B.key===y)?.items??[]:e;pe(x,S,C,`in ${D==="hbin"?"hard":"soft"} bin ${h}${y!==void 0?` of ${y}`:""}`,B=>jn(B)&&(D==="hbin"?B.hbin:B.sbin)===h)}}});return w.card.style.minHeight="360px",l.appendChild(w.card),{card:l,destroy:()=>{k?.destroy(),w.destroy()}}}function Fe(){const e=a.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...$n(),display:"flex",flexDirection:"column",gap:O.lg,minWidth:"0"}),e}function Rt(e){if(ce.innerHTML="",ce.style.marginBottom="0",!Et)return;const t=Dn(e.map(s=>({metadata:s.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",ce.appendChild(t),ce.style.marginBottom=O.xs)}function Nt(e,t,s,o,l){if(!e.length)return{elements:[],destroy:()=>{}};const v=e.map(w=>w.wafer),f=e.map(w=>w.dies),d=Q(),b=[],c=[],p=o??[{key:"",items:e}],u=e.flatMap(w=>w.dies),g=["spec","testFlag","functional"].filter(w=>an(s,w,u));if(g.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"}},r=!!o,x=re(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:d}))),S=25,P=n=>rn(s,n).map(h=>h.testNumber),m=n=>ot(p.map(h=>({key:h.key,items:h.items.map(y=>({dies:y.dies}))})),s,n).rows.map(h=>h.testNumber),E=n=>n==="testFlag"?{judge:"flag"}:{},L=(n,h="bars",y="worst")=>r&&h==="grid"?{id:`card-pass-rate-${n}`,title:w[n].title,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},y:{tests:m(n).slice(0,S),passRate:!0,...E(n)}}}:{id:`card-pass-rate-${n}`,title:w[n].title,chart:"bar",orientation:"horizontal",sort:"ascending",...P(n).length>S&&y==="worst"?{top:S}:{},fields:{x:{builtin:"test"},y:{tests:P(n),passRate:!0,...E(n)},color:r?{follow:"groupBy"}:{none:!0}},...r?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}},F=n=>n.id.slice(15),D=ee({doc:a,editAsPlot:Z,items:x,ctx:{testDefs:s,groupBy:r?N:void 0,curation:T.attributes},spec:(()=>{const n=g.some(y=>P(y).length>S),h=[];return g.length>1&&h.push({current:g[0],options:g.map(y=>[y,w[y].label,w[y].hint])}),r&&h.push({current:"bars",options:[["bars","Bars"],["grid","Grid",`The worst ${S} tests as a grid of test by group`]]}),n&&h.push({current:"worst",options:[["worst",`Worst ${S}`],["all","All tests"]]}),h.length?{choices:h,build:y=>{let C=0;const B=g.length>1?y[C++]:g[0],K=r?y[C++]:"bars",I=n?y[C++]:"worst";return L(B,K,I)}}:L(g[0])})(),notes:n=>{const h=F(n);if(h==="functional")return[];const y=ot(p.map(C=>({key:C.key,items:C.items.map(B=>({dies:B.dies}))})),s,h).disagreementDies;return y?[`${y.toLocaleString("en-GB")} die${y===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:W,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(n,h,y,C)=>{const B=s.find(U=>U.testNumber===C?.test);if(!B)return;const K=F(D.current()),I=C?.group!==void 0?p.find(U=>U.key===C.group)?.items??e:e;pe(h,y,I,`failing ${dt(B,B.testNumber)}${C?.group!==void 0?` in ${C.group}`:""}`,U=>sn(U,B,K)===!0,Ce(B)?B.testNumber:void 0)}}});D.card.style.minHeight="300px",b.push(D.card),c.push(D.destroy)}const A=w=>(r,x)=>{const S=new Set;for(const P of e)for(const m of Rn(P.dies,P.wafer,d,r.key,w))S.add(m);Lt(x,e,`in ${r.label}`,P=>S.has(P))},k=qe(f,v,d,w=>e[w].passBins,Ct),$=k.length?Ke({title:"Ring yield",mode:"ring",rows:k,onSelectRegion:A(Ct),onSaveImage:W,ownerDocument:a}):void 0;$&&c.push($.destroy);const j=(w,r,x,S)=>{const P=!!o,m=re(e.map(L=>({label:L.identity??L.label,dies:L.dies,waferIndex:L.waferIndex,wafer:L.wafer,passBins:L.passBins,ringCount:d}))),E=ee({doc:a,editAsPlot:Z,items:m,ctx:{testDefs:s,groupBy:P?N:void 0,curation:T.attributes},spec:{id:w,title:`${x} yield by ${P?l??"group":"wafer"}`,chart:"heatmap",fields:{x:{slot:"groupBy"},rows:{builtin:r},y:{builtin:"yield"}}},chart:{onSaveImage:W}});E.card.style.minHeight="300px",b.push(S?En([{label:"Heatmap",card:E.card},{label:"Diagram",card:S.card}],a):E.card),c.push(E.destroy)};k.length&&e.length>=2?j("card-ring-wafer","ring","Ring",$):$&&b.push($.card);const _=qe(f,v,d,w=>e[w].passBins,Bt);if(_.length){const w=Ke({title:"Quadrant yield",mode:"quadrant",rows:_,onSelectRegion:A(Bt),onSaveImage:W,ownerDocument:a});c.push(w.destroy),e.length>=2?j("card-quadrant-wafer","quadrant","Quadrant",w):b.push(w.card)}const R=v.find(w=>w.reticle!==void 0)?.reticle;if(R){const w=(x,S)=>Wn(x,S.reticle),r=qe(f,v,d,x=>e[x].passBins,w);if(r.length){const x=Ke({title:"Reticle cell yield",mode:"reticleCell",rows:r,grid:{width:Math.max(1,Math.floor(R.width)),height:Math.max(1,Math.floor(R.height))},onSelectRegion:A(w),onSaveImage:W,ownerDocument:a});b.push(x.card),c.push(x.destroy)}}const i=new Set;for(const w of e)for(const r of w.dies)r.siteNum!==void 0&&i.add(r.siteNum);if(i.size>=2){const w=re(e.map(x=>({label:x.identity??x.label,dies:x.dies,waferIndex:x.waferIndex,wafer:x.wafer,passBins:x.passBins,ringCount:d}))),r=ee({doc:a,editAsPlot:Z,items:w,ctx:{testDefs:s,curation:T.attributes},spec:{id:"card-site",title:"Yield by site",chart:"bar",fields:{x:{builtin:"site"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...i.size>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}},chart:{onSaveImage:W}});b.push(r.card),c.push(r.destroy)}if(e.some(w=>w.dies.some(r=>r.retestCount!==void 0))){const w=re(e.map(S=>({label:S.identity??S.label,dies:S.dies,waferIndex:S.waferIndex,wafer:S.wafer,passBins:S.passBins,ringCount:d}))),r=!!o,x=ee({doc:a,editAsPlot:Z,items:w,ctx:{testDefs:s,groupBy:r?N:void 0,curation:T.attributes},spec:{id:"card-reprobed",title:`Re-probed dies by ring and ${r?l??"group":"wafer"}`,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},rows:{builtin:"ring"},y:{builtin:"reprobed"}}},chart:{onSaveImage:W}});x.card.style.minHeight="300px",b.push(x.card),c.push(x.destroy)}return{elements:b,destroy:()=>{for(const w of c)w()}}}function Mt(e,t,s){if(!e.length)return{cards:[],destroy:()=>{}};const o=e.map(u=>u.dies),l=e.flatMap(u=>u.dies),v=e.map(u=>u.statsSummary),f=v.every(u=>u!==void 0)?v:void 0,d=[],b=[];let c=null;if(t.length){const u=Fe();let g=null;const A=Pn(An(l,t,void 0,f,J,o.map(k=>({dies:k})),void 0,"full"),{onDone:k=>{g=k,u.removeAttribute("aria-busy"),k?u.replaceChildren(k):u.remove()}});if(A.done)g&&(c=u);else{const k=a.createElement("div");k.textContent="Computing test statistics\u2026",Object.assign(k.style,{color:M.label,fontSize:G.body}),u.setAttribute("aria-busy","true"),u.appendChild(k),c=u,d.push(()=>A.cancel())}}let p=null;if(s.length){const u=Ln(l,s,f,J);if(u){const g=Fe();g.appendChild(u),p=g}}return c&&b.push(c),p&&b.push(p),{cards:b,destroy:()=>{for(const u of d)u()}}}function Ft(e){const t=ct(e.map(c=>c.passBins)),s=e.length===1,o=e[0],l=Fe();Object.assign(l.style,{flexDirection:"row",flexWrap:"wrap",gap:O.md});const v=c=>{const p=c.lastElementChild;return p&&Object.assign(p.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),c};function f(c,p,u){const g=a.createElement("div");Object.assign(g.style,{display:"flex",alignItems:"baseline",gap:O.sm,paddingRight:O.xxl,marginRight:O.md,borderRight:`1px solid ${M.menuBorder}`});const A=a.createElement("div");A.textContent=c,Object.assign(A.style,{fontSize:G.heading,fontWeight:"700",color:M.value,lineHeight:Ve.tight});const k=a.createElement("div");if(k.textContent=p,Object.assign(k.style,{fontSize:G.body,color:M.label}),g.append(A,k),u){const $=a.createElement("div");$.textContent=u,Object.assign($.style,{fontSize:G.meta,color:M.label,opacity:bn.muted}),g.appendChild($)}return g}if(s){const c=St([{...o,key:o.waferIndex}])[0]?.percent;return c!==void 0&&l.appendChild(f(`${c.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),l.appendChild(f(String(o.dies.length),"Total dies")),v(l)}l.appendChild(f(String(e.length),"Wafers"));const d=St(e.map(c=>({...c,key:c.waferIndex}))).map(c=>c.percent).filter(c=>Number.isFinite(c));if(d.length){const c=d.reduce((g,A)=>g+A,0)/d.length,p=On([{key:"all",items:e.map(g=>({...g,key:g.waferIndex}))}])[0]?.percent,u=p!==void 0&&p.toFixed(1)!==c.toFixed(1);l.appendChild(f(`${c.toFixed(1)}%`,`${Zt} \xB7 pass: ${t}`,u?`${p.toFixed(1)}% by dies`:void 0))}const b=e.map(c=>c.statsSummary);if(b.every(c=>c!==void 0)){const c=b.reduce((u,g)=>u+g.stats.analyzedDies,0),p=b.reduce((u,g)=>u+g.stats.excludedDies,0);l.appendChild(f(c.toLocaleString(),"Dies analysed",p?`${p.toLocaleString()} excluded`:void 0))}else l.appendChild(f(e.reduce((c,p)=>c+p.dies.length,0).toLocaleString(),"Total dies"));return v(l)}function jt(e,t,s,o,l){const v=a.createElement("div");Object.assign(v.style,{display:"flex",flexDirection:"column",gap:O.lg});const f=e.length===1&&!o;e.length&&!o&&v.appendChild(Ft(e));const d=Wt(e,o,l,!f),b=Nt(e,t,s,o,l);for(const u of b.elements)d.card.appendChild(u);const c=zt(e,s);if(c&&v.appendChild(c.el),e.length>=4&&De.length){const u=Sn({wafers:e,fields:De,curation:ye,groupedBy:N,onGroupBy:g=>{N=g,V=null,ne()},ownerDocument:a});v.appendChild(u.card)}v.appendChild(d.card);const p=Cn({items:e.map(u=>({...u,ringCount:Q()})),testDefs:s,ownerDocument:a,showMap:T.showPatMap});return p&&v.appendChild(p.card),v.appendChild(Ht()),{card:v,destroy:()=>{d.destroy(),b.destroy(),c?.destroy()}}}function zt(e,t){const s=Xe?.()??(e.length===1?e[0].statsSummary:void 0);if(!s)return null;const o=a.createElement("section");o.dataset.wmapWorthALook="1",Object.assign(o.style,{display:"flex",flexDirection:"column",gap:O.md});const l=a.createElement("h3");l.textContent="Worth a look",Object.assign(l.style,{margin:"0",fontSize:G.heading,fontWeight:"600",color:M.value}),o.appendChild(l);const v=(p,u)=>{const g=a.createElement("p");g.textContent=p,u&&(g.dataset[u]="1"),Object.assign(g.style,{margin:"0",fontSize:G.body,color:M.label,lineHeight:Ve.base}),o.appendChild(g)};if(Le||V!==null)return v("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:o,destroy:()=>{}};const f=Yn(s,{passBins:Gn(e.map(p=>p.passBins)),attributes:T.attributes});if(f.items.length===0)return v(f.nothing??"Nothing stands out.","wmapWorthNothing"),{el:o,destroy:()=>{}};const d=$e(a);o.appendChild(d);const b=re(e.map(p=>({label:p.identity??p.label,dies:p.dies,waferIndex:p.waferIndex,wafer:p.wafer,passBins:p.passBins,ringCount:Q()}))),c=[];if(f.items.forEach((p,u)=>{const g=a.createElement("div");g.dataset.wmapWorthWhy="1",g.textContent=`Shown because: ${p.reason}`,p.text!==p.reason&&ke(g,p.text),Object.assign(g.style,{flexBasis:"100%",fontSize:G.body,color:M.text,lineHeight:Ve.base});const A=[g];if(T.showOnMap){const $=a.createElement("button");$.type="button",$.textContent="Show on map",$.dataset.wmapWorthShowOnMap="1",Object.assign($.style,{...ut("outlined"),fontSize:G.body,padding:`0 ${O.md}`}),Be($),ke($,"Leave Insights and show this on the map, as its row in What stands out does"),$.addEventListener("click",()=>T.showOnMap(p.target)),A.push($)}const k=ee({doc:a,items:b,ctx:{testDefs:t,curation:ye,groupBy:N},spec:{id:`worth-${u}`,...Vn(p.chart,!!N)},extras:A,editAsPlot:Z,chart:{onSaveImage:W}});k.card.dataset.wmapWorthKey=_n(p),d.appendChild(k.card),c.push(k.destroy)}),f.also){const p=f.also.items.map(u=>u.brief).join("; ");v(`Also: ${p}${f.also.more?`; and ${f.also.more} more`:""}. Their rows in What stands out show them on the map.`,"wmapWorthAlso")}return{el:o,destroy:()=>c.forEach(p=>p())}}function Ht(){const e=a.createElement("div");Object.assign(e.style,{fontSize:G.body,color:M.label});const t=a.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:M.iconActive,textDecoration:"underline"}),Be(t,"bare"),t.addEventListener("click",()=>{X="data",ne({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",t,"."),e}function Yt(e,t,s,o){const l=a.createElement("div");l.style.width="100%";let v,f=!1;return import("./plotTab.js").then(({createPlotSection:d})=>{if(f)return;const b=d({doc:a,store:ue,items:e,testDefs:t,ringCount:Q(),attributes:T.attributes,groupBy:s,groupLabel:o,onSaveImage:W,onSaveText:J,getBinColors:ie,waferMenu:ve(e),openWafer:oe?(c,p,u)=>oe(c,p,u):void 0,focusTest:Te,locateDie:me,pickPlotsFile:T.onPickPlotsFile});l.appendChild(b.card),v=b}),{card:l,destroy:()=>{f=!0,v?.destroy()}}}function Vt(e,t,s,o,l){const v=Le?void 0:Xe?.(),f=()=>{fe.get("data")?.destroy(),fe.delete("data"),ne({keepSections:!0})};return Nn({doc:a,items:e,testDefs:t,allTestDefs:s,groups:o,groupLabelText:l,ringCount:Q(),attributes:T.attributes,yieldByWaferIndex:new Map(v?.lotYieldSeries.map(d=>[d.waferIndex,d.yieldPercent])),onSaveText:J,onLocateDie:me,onOpenWafer:oe?(d,b)=>oe(d,b):void 0,buildStatistics:d=>Mt(d,t,s),view:tt,onViewChange:d=>{tt=d,f()},diesLayout:nt,onDiesLayoutChange:d=>{nt=d}})}function Se(e,t){const s=a.createElement("h3");return s.textContent=e,s.dataset.wmapRowHeading=t,Object.assign(s.style,{gridColumn:"1 / -1",margin:`${O.md} 0 0`,color:M.value,fontSize:G.heading,fontWeight:"600"}),s}function _t(e,t,s,o){const l=$e(a),v=it(e),f=re(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:Q()}))),d=t.filter(n=>n.testNumber!==void 0),b=!!s&&!!N,c=b&&V!==null,p={testDefs:t,groupBy:b?N:void 0,curation:T.attributes},u=d.length>1;let g;const A=[];function k(n){let h=Pe,y=!1,C;const B=pt(d,q??d[0]?.testNumber??null,H=>{C?.refresh(),S(H)},{ownerDocument:a}),K=a.createElement("span");Object.assign(K.style,{display:"inline-flex",flexWrap:"wrap",gap:O.sm,alignItems:"center"});const I={setAxisPrefs:H=>{U.set(H)&&(h=H,C?.refresh())}},U=bt(K,h,H=>{h=H,C?.refresh(),Re(H,I)},a),be=[B.el,K];n.logToggle&&be.push(Ge("Log scale",y,H=>{y=H,C?.refresh()},a,"Draw the value axis on a logarithmic scale")),be.push(...n.extras??[]),C=ee({doc:a,editAsPlot:Z,items:f,ctx:p,...n.card,spec:{choices:n.choices??[],build:H=>n.build(h,y,H)},slots:()=>({test:B.get()??void 0}),extras:be,onResolved:H=>{const he=t.find(Jt=>Jt.testNumber===B.get()),ge=Ee(he,h.limits),je=kt(H,n.valueRole),{lo:Xt,hi:Ut}=gt(ge),Qt=je.length>0&&ge.length>0&&yt(vt(je),xt(je),Xt,Ut);U.sync(h.includeLimits??Qt,Ee(he).length>0,wt(he))},chart:n.chart});const z=C;if(u){const H=()=>{B.el.style.display=In(z.card)?"":"none"};H();const he=a.defaultView?.MutationObserver;if(he){const ge=new he(H);ge.observe(z.card,{attributes:!0,attributeFilter:["data-wmap-expanded"]}),A.push(ge)}}return{card:z.card,setTest:H=>{B.set(H)&&z.refresh()},refresh:()=>z.refresh(),setAxisPrefs:I.setAxisPrefs,destroy:()=>z.destroy()}}const $=v?(n,h)=>v.open(f[n]?.waferIndex??n,h??q??d[0]?.testNumber??0):void 0;let j=!1,_=!1;const R=k({valueRole:"y",logToggle:!0,choices:[{current:b&&!c?"groups":"wafers",options:[...b&&!c?[["groups",`By ${o??"group"}`],["nested",`${o??"Group"}, then wafer`,"Each group with its wafers inside it"]]:[["wafers","By wafer"]],["radius","By radius","A box for each ring, from the centre to the edge: whether the test changes across the wafer"]]}],build:(n,h,[y])=>(j=b&&!c&&y==="nested",_=y==="radius",{id:"card-box",title:_?"Test value by radius":"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:_?{builtin:"ring"}:j?[{slot:"groupBy"},{builtin:"wafer"}]:b&&!c?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:j?{follow:"groupBy"}:{none:!0}},...c?{where:{conditions:[{field:{meta:N},values:[V]}]}}:{},...ae("y",n,h)}),card:{...b&&!c?{drill:n=>{if(j||_)return null;const h=ze(f[n[0]?.item]?.metadata,N,T.attributes);return h===void 0?null:y=>({...y,fields:{...y.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:N},values:[h]}]}})},drillLabel:()=>j||_?void 0:"see its wafers"}:{},...V!==null?{externalBack:{shown:()=>V!==null,onBack:()=>Ne(null)}}:{}},chart:{onSaveImage:W,onOpenWafer:$,openActionLabel:v?.label,onWaferMenu:ve(e)}});let i=null;const w=b?[]:[ht(f.map(n=>({label:n.label})),null,n=>{i=n,r.refresh()},{ownerDocument:a})],r=k({valueRole:"x",logToggle:!0,extras:w,choices:[{current:"bars",options:[["bars","Histogram"],["cumulative","Cumulative","The share of dies at or below each value, as one curve per colour"]]},...b?[{current:"percent",options:[["percent",`Share of ${o??"group"}`,"Each group\u2019s bars as a share of its own dies, so groups of different sizes compare"],["count","Counts"]]}]:[]],card:V!==null?{externalBack:{shown:()=>V!==null,onBack:()=>Ne(null)}}:{},build:(n,h,[y,C])=>({id:"card-histogram",title:y==="cumulative"?"Cumulative distribution":"Value histogram",chart:y==="cumulative"?"probability":"histogram",fields:{y:{slot:"test"},color:b?{follow:"groupBy"}:{none:!0}},...b&&C!=="count"&&y!=="cumulative"?{histNorm:"percent"}:{},...i!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[i].label]}]}}:{},...ae("x",n,h)}),chart:{onSaveImage:W,onSelectPoints:(n,h,y,C)=>{const B=t.find(z=>z.testNumber===(q??d[0]?.testNumber)),K=new Set(n.map(z=>z.die).filter(z=>!!z)),I=new Set(n.map(z=>f[z.item]?.waferIndex)),U=C?.range,be=B&&U?`with ${dt(B,B.testNumber)} from ${lt(U.lo,B.unit,"engineering")} to ${lt(U.hi,B.unit,"engineering")}${C?.group?` in ${C.group}`:""}`:"selected in the histogram";pe(h,y,e.filter(z=>I.has(z.waferIndex)),be,z=>K.has(z),B?.testNumber)}}}),x=k({valueRole:"y",logToggle:!0,choices:e.length>=3?[{current:"trend",options:[["trend","Trend","Each wafer\u2019s mean with a band of one standard deviation"],["control","Control chart","One value per wafer against control limits, with the points that break a Western Electric rule marked"]]}]:[],build:(n,h,[y])=>y==="control"?{id:"card-trend",title:"Wafer-to-wafer control chart",chart:"control",aggregate:"mean",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:b?{follow:"groupBy"}:{none:!0}},...ae("y",n,h)}:{id:"card-trend",title:"Wafer-to-wafer trend",chart:"line",aggregate:"mean",spread:"sd",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:{none:!0}},...ae("y",n,h),axes:{...ae("y",n,h).axes,y:{...ae("y",n,h).axes.y,references:[{stat:"mean",label:mn(hn(e.map(C=>C.wafer.metadata)),"mean")}]}}},card:{ctx:p,...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:W,onWaferMenu:ve(e),selectActionLabel:$?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(n,h,y)=>{const C=new Set(n.map(I=>I.item));if(C.size===1&&$){$([...C][0]);return}const B=new Set(n.map(I=>I.die).filter(I=>!!I)),K=new Set(n.map(I=>f[I.item]?.waferIndex));pe(h,y,e.filter(I=>K.has(I.waferIndex)),"selected in the trend",I=>B.has(I),q??void 0)}}}),S=n=>{q=n,g?.set(n),R.setTest(n),r.setTest(n),x.setTest(n),L.setTest(n),m?.setTest(n),E?.setTest(n)},P=()=>vn({groups:s,testDefs:t,groupLabelText:o,control:st,onControlChange:n=>{st=n;const h=P();m.card.replaceWith(h.card),m=h},selectedTestNumber:q??void 0,onSelectTest:n=>S(n),onSaveText:J,ownerDocument:a});let m=s&&s.length>=2?P():void 0;const E=s&&s.length>=2?Bn({groups:s,testDefs:t,groupLabelText:o,selectedTestNumber:q??void 0,onSaveImage:W,ownerDocument:a}):void 0;We.set("distribution",[R,r,x]);const L=xn({title:"Process capability",items:e,testDefs:t,onSaveImage:W,selectedTestNumber:q??void 0,onSelectTest:n=>S(n),ownerDocument:a}),F=e.length>=2?Fn(e.map(n=>({dies:n.dies})),t.filter(n=>n.testNumber!==void 0&&Ce(n)).map(n=>n.testNumber),qn):[],D=F.length>=2?ee({doc:a,editAsPlot:Z,items:f,ctx:p,spec:{id:"card-tests-wafer",title:`Tests by ${s?o??"group":"wafer"} (z-scores)`,chart:"heatmap",level:"wafer",aggregate:"mean",normalize:"zscore",fields:{x:{slot:"groupBy"},y:{tests:F}}},chart:{onSaveImage:W}}):void 0;if(D&&(D.card.style.minHeight="300px"),D&&(l.append(Se(`Tests across ${s?o??"groups":"wafers"}`,"tests-grid")),l.append(D.card)),(m||E)&&(l.append(Se(`Comparing ${o??"groups"}`,"comparing")),m&&l.append(m.card),E&&l.append(E.card)),u){g=pt(d,q??d[0]?.testNumber??null,B=>S(B),{ownerDocument:a});const n=a.createElement("div");n.dataset.wmapSectionTest="1",Object.assign(n.style,{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:O.lg,flexWrap:"wrap",marginTop:O.md});const h=Se("Test by test","tests");h.style.margin="0";const y=a.createElement("label");Object.assign(y.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:G.body,color:M.label});const C=a.createElement("span");C.textContent="Test",y.append(C,g.el),n.append(h,y),l.append(n)}else(m||E)&&l.append(Se("Test by test","tests"));return l.append(L.card,R.card,r.card,x.card),{card:l,destroy:()=>{for(const n of A)n.disconnect();L.destroy(),R.destroy(),r.destroy(),x.destroy(),m?.destroy(),E?.destroy(),D?.destroy()}}}function Gt(e,t,s,o){const l=$e(a),v=it(e),f=re(e.map(m=>({label:m.identity??m.label,dies:m.dies,waferIndex:m.waferIndex,wafer:m.wafer,passBins:m.passBins,ringCount:Q()}))),d=t.filter(m=>m.testNumber!==void 0&&Ce(m));let b=d[0]?.testNumber,c=d[1]?.testNumber??b,p=null,u=Pe;const g=!!s&&!!N,A=(m,E)=>{const L=a.createElement("label");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:G.body,color:M.label});const F=a.createElement("span");return F.textContent=m,L.append(F,E),L},k=mt(d,b??null,m=>{b=m,S.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:a}),$=mt(d,c??null,m=>{c=m,S.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:a}),j=a.createElement("span");Object.assign(j.style,{display:"inline-flex",flexWrap:"wrap",gap:O.sm,alignItems:"center"});let _=!1,R=!1;const i={setXY:(m,E)=>{b=m,c=E,k.value=String(m),$.value=String(E),S.refresh()},setAxisPrefs:m=>{w.set(m)&&(u=m,S.refresh())},destroy:()=>S.destroy()},w=bt(j,u,m=>{u=m,S.refresh(),Re(m,i)},a),r=m=>{const E=t.find(L=>L.testNumber===m);return E?.name?{test:m??0,name:E.name}:{test:m??0}},x=[A("X:",k),A("Y:",$),j,Ge("Log X",_,m=>{_=m,S.refresh()},a,"Draw the X axis on a logarithmic scale"),Ge("Log Y",R,m=>{R=m,S.refresh()},a,"Draw the Y axis on a logarithmic scale")];!g&&e.length>1&&x.push(ht(f.map(m=>({label:m.label})),null,m=>{p=m,S.refresh()},{ownerDocument:a}));const S=ee({doc:a,editAsPlot:Z,items:f,ctx:{testDefs:t,groupBy:g?N:void 0,curation:T.attributes},extras:x,onResolved:m=>{const E=[b,c].map(F=>t.find(D=>D.testNumber===F)),L=["x","y"].some((F,D)=>{const n=Ee(E[D],u.limits),h=kt(m,F),{lo:y,hi:C}=gt(n);return h.length>0&&n.length>0&&yt(vt(h),xt(h),y,C)});w.sync(u.includeLimits??L,E.some(F=>Ee(F).length>0),E.some(wt))},spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:u.limits??"both",axes:{...ae("x",u,_).axes,...ae("y",u,R).axes},fields:{x:r(b),y:r(c),color:g?{follow:"groupBy"}:{builtin:"hbin"}},...g?{fit:"linear"}:{},...p!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[p].label]}]}}:{}})},...b===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:W,binColors:ie(),onOpenWafer:v?(m,E)=>v.open(f[m]?.waferIndex??m,E??b??0):void 0,openActionLabel:v?.label,onSelectPoints:(m,E,L)=>{const F=new Map;for(const h of m){const y=f[h.item]?.waferIndex;if(y===void 0||!h.die)continue;const C=F.get(y);C?C.push(h.die):F.set(y,[h.die])}const D=[...F].flatMap(([h,y])=>{const C=e.find(B=>B.waferIndex===h);return C?[{label:C.identity??C.label,dies:y,waferIndex:h,wafer:C.wafer,passBins:C.passBins,ringCount:Q()}]:[]});if(D.length===0)return;const n=D.length===1?`selected on ${D[0].label} in the scatter`:`selected in the scatter, across ${D.length} wafers`;Ye(E,L,{items:D,population:n,testDefs:t,activeTest:b},{plots:ue,getBinColors:ie,onSaveImage:W,onSaveText:J,onLocateDie:me})}}});We.set("correlation",[i]);const P=kn({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:W,onSaveText:J,...g&&s&&s.length>=2?{groups:s,groupLabelText:o}:{},onSelectPair:(m,E)=>i.setXY(m,E),ownerDocument:a});return l.append(P.card,S.card),{card:l,destroy:()=>{P.destroy(),i.destroy()}}}const qt=(e,t,s,o)=>fn(a,e,t,s,o),Kt=()=>we.openEditor(Y,Me());function ne(e){e?.keepSections||at(),se.innerHTML="",te.innerHTML="";for(const i of At)te.appendChild(Pt(i.key,i.label));const t=Me(),s=we.keep(t),o=s.items;Le=s.narrowing,Ue.refresh(s.result,t),Rt(o);const l=en(o,{facetableOnly:!0,curation:ye}).filter(i=>i.splittable);De=l.map(i=>({key:i.key,label:i.label}));const v=a.createElement("div");Object.assign(v.style,{display:"flex",gap:O.md,alignItems:"center",marginLeft:O.xxl,paddingBottom:O.xs}),T.showFilterButton!==!1&&v.appendChild(qt("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>Kt()));let f;l.length>0?(v.appendChild(ft("Group by:",[{value:"",label:"None"},...l.map(i=>({value:i.key,label:`${i.label} (${i.values.length})`}))],N??"",i=>{N=i||void 0,V=null,ne()},{hook:"group-by",ownerDocument:a,hint:"Split every chart by a wafer attribute, such as lot or tester"})),f=l.find(i=>i.key===N)?.label):N=void 0;let d;if(N){const i=new Map,w=[];for(const r of o){const x=ze(r.metadata,N,ye)??tn;i.has(x)||(i.set(x,[]),w.push(x)),i.get(x).push(r)}d=Hn(w).map(r=>({key:r,items:i.get(r)}))}V!==null&&!d?.some(i=>i.key===V)&&(V=null),d&&d.length>0&&v.appendChild(Tn(d.map(i=>i.key),"Show:",V,i=>Ne(i),{ownerDocument:a,hint:"Show every group, or analyse just one"}).el);const b=ft("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(i=>({value:String(i),label:`${i} (${i})`}))],de===void 0?"auto":String(de),i=>Qe(i==="auto"?void 0:Number(i)),{hook:"insights-columns",maxWidth:"90px",ownerDocument:a,hint:"The most cards that sit side by side (a tab with fewer cards uses fewer); the keys 1 to 5 set it and 0 returns to Auto"});Oe=b.querySelector("button"),v.appendChild(b);let c=null;if(T.onOpenGuide){const i=a.createElement("button");i.type="button",i.innerHTML=wn.help,i.setAttribute("aria-label","User guide"),Object.assign(i.style,{...ut("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),Be(i,"bare"),ke(i,"User guide"),i.addEventListener("click",()=>T.onOpenGuide()),Object.assign(i.style,{marginLeft:"auto"}),c=i}te.appendChild(v),c&&te.appendChild(c);const p=V!==null?d?.find(i=>i.key===V):void 0,u=p?.items??o,g=p?void 0:d,A=He(u),k=A.defs,$=k.filter(Ce);if(q!==null&&!$.some(i=>i.testNumber===q)&&(q=null),o.length===0){const i=a.createElement("div");i.dataset.wmapInsightsFilterEmpty="1",i.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(i.style,{color:M.label,fontSize:G.body,padding:O.xl}),se.appendChild(i);return}const j=e?.keepSections?fe.get(X):void 0,_=j??(X==="overview"?jt(u,$,k,g,f):X==="distributions"?_t(u,$,g,f):X==="data"?Vt(u,$,k,g,f):X==="plot"?Yt(u,k,p?void 0:N,p?void 0:f):Gt(u,$,g,f));j||fe.set(X,_);const R=A.conflicts.filter(i=>i.excluded);if(R.length>0){const i=a.createElement("div");Object.assign(i.style,{color:M.label,fontSize:G.body,padding:`0 ${le} ${O.sm}`});const w=R.slice(0,6).map(S=>S.testNumber).join(", "),r=R.length>6?`, and ${R.length-6} more`:"",x=R.length===1?"it":"them";i.textContent=`${R.length} test ${R.length===1?"number is":"numbers are"} hidden (${w}${r}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(d&&d.length>0?`Pick one ${f??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),i.dataset.wmapWithheldTests=String(R.length),se.appendChild(i)}se.appendChild(_.card),xe()}return{el:Y,render:ne,destroy:()=>{a.removeEventListener("keydown",et),Ze?.disconnect(),at(),ue.flush(),Y.remove()},setAxisPrefs:e=>Re(e,null,!0),showWorthCard:e=>{X!=="overview"&&(X="overview",ne({keepSections:!0}));const t=[...se.querySelectorAll("[data-wmap-worth-key]")].find(l=>l.dataset.wmapWorthKey===e);if(!t)return!1;const s=a.defaultView,o=()=>t.scrollIntoView({block:"center"});return s?.requestAnimationFrame?s.requestAnimationFrame(()=>s.requestAnimationFrame(o)):o(),t.style.outline=`2px solid ${M.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
@@ -1,2 +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()})}
1
+ import{mergeTestDefs as T}from"../stats/mergeTestDefs.js";import{DEFAULT_FACET_CURATION as P}from"../stats/facets.js";import{conditionText as W}from"../stats/plotData.js";import{readFilter as R}from"../stats/plotSpec.js";import{addSavedFilters as M,readSavedFilters as G,readFiltersFile as z,writeFiltersFile as K}from"../stats/filterFile.js";import{newFilterId as U}from"../stats/plotId.js";import{applyConditions as N,fieldCatalogue as A,fieldExtent as V,fieldValues as B}from"../stats/plotData.js";import{toPlotItems as _}from"./plotItems.js";import{buildFilterEditor as q,buildFilterStrip as H}from"./filterEditor.js";import{CLR as x,FONT as k,RADIUS as Y,SPACE as g,openModal as Q,saveTextFile as X,wireTooltip as Z}from"./toolbar.js";import{inputStyle as ee,makeSegmented as te}from"./charts/chartShell.js";import{buildFilterJsonPanel as ne}from"./filterJson.js";import{bandButton as O}from"./filterButton.js";export function readFilterOption(i){if(i==null)return;const t=[],c=typeof i=="object"&&!Array.isArray(i)?R(JSON.parse(JSON.stringify(i)),"insights.filter",t):void 0;return c||t.push("insights.filter: needs at least one condition, so no filter is applied"),t.length&&console.warn(`[wafermap] ${t.join("; ")}`),c}const L=i=>JSON.parse(JSON.stringify(i));export function createPageFilter(i){const{doc:t}=i,h={...P,...i.attributes};let c=readFilterOption(i.initial);const y=new Set;let b=(()=>{if(!i.savedFilters)return[];const a=G(i.savedFilters,"insights.savedFilters");return a.warnings.length&&console.warn(`[wafermap] ${a.warnings.join("; ")}`),a.filters})();const E=a=>({items:_(a.map(o=>({label:o.identity??o.label,dies:o.dies,waferIndex:o.waferIndex,wafer:o.wafer,passBins:o.passBins,ringCount:i.getRingCount()}))),ctx:{testDefs:T([...a]).defs,curation:h}}),v=a=>{if(!c||c.off)return;const o=E(a);return N(c.conditions,o.items,o.ctx)},F={get:()=>c,set(a){c=a,i.onChange?.(a?L(a):void 0);for(const o of[...y])o()},subscribe(a){return y.add(a),()=>{y.delete(a)}},saved:()=>b,setSaved(a){b=a.map(o=>JSON.parse(JSON.stringify(o))),i.onSavedFiltersChange?.(b.map(o=>JSON.parse(JSON.stringify(o))))},keep(a){const o=v(a);if(!o||o.issue)return{items:a,result:o,narrowing:!1};const s=o.index.map((d,m)=>{const r=a[d],e=o.items[m].dies;return e.length===r.dies.length?r:{...r,dies:e,statsSummary:void 0}});return{items:s,result:o,narrowing:s.length!==a.length||s.some((d,m)=>d!==a[o.index[m]])}},mark(a){const o=new Set,s=v(a);if(!s||s.issue)return{items:a,hidden:o,result:s,narrowing:!1};const d=new Map(s.index.map((e,f)=>[e,s.items[f].dies]));let m=!1;return{items:a.map((e,f)=>{const l=d.get(f);if(l===void 0&&(o.add(f),m=!0),l&&l.length===e.dies.length)return e;m=!0;const w=l?new Set(l):void 0,p=e.dies.map(u=>w?.has(u)?u:{...u,filteredOut:!0});return{...e,dies:p,statsSummary:void 0}}),hidden:o,result:s,narrowing:m}},createBand(a,o){const s=t.createElement("div");s.dataset.wmapInsightsFilter="1",Object.assign(s.style,{display:"none",...o});const d=(r,e,f,l)=>O(t,r,e,f,l);return{el:s,refresh:(r,e)=>{if(s.replaceChildren(),s.style.display=c?"":"none",!c)return;const f=[d("Edit\u2026","wmapInsightsFilterEdit","Change the conditions",()=>F.openEditor(s,e)),d("Remove","wmapInsightsFilterRemove","Delete the filter: every wafer and die is shown again",()=>F.set(void 0))];if(r?.issue){const p=t.createElement("div");p.dataset.wmapInsightsFilterIssue="1",p.setAttribute("role","status"),Object.assign(p.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:g.md,padding:`${g.xs} ${g.md}`,background:x.warnBg,border:`1px solid ${x.warnBorder}`,borderRadius:Y.control,color:x.warnText,fontSize:k.body});const u=t.createElement("span");u.textContent=`The filter cannot be applied to these wafers (${r.issue}), so nothing is filtered.`;const C=t.createElement("span");Object.assign(C.style,{display:"inline-flex",gap:g.sm,marginLeft:"auto"}),C.append(...f),p.append(u,C),s.appendChild(p);return}const l=p=>p.toLocaleString("en-GB"),w=r?`${l(r.wafers.kept)} of ${l(r.wafers.total)} wafer${r.wafers.total===1?"":"s"} \xB7 ${l(r.dies.kept)} of ${l(r.dies.total)} dies`:void 0;s.appendChild(H({doc:t,filter:c,testDefs:T([...e]).defs,attributes:h,label:"Filter",kept:w,actions:f,onToggle:p=>{if(!c)return;const u={...c};p?delete u.off:u.off=!0,F.set(u)}}))}}},openEditor(a,o){const s=E(o);let d=c?L(c):void 0,m;const r=Q({title:"Filter",anchor:a,ownerDocument:t,boxSize:{width:"min(92vw, 640px)",height:"min(85vh, 640px)"},maximizable:!1,initialFocus:()=>d?m:p.el.querySelector("[data-wmap-filter-add]")??m,onClose:()=>{}});r.box.dataset.wmapInsightsFilterModal="1";const e=t.createElement("div");Object.assign(e.style,{display:"flex",flexDirection:"column",gap:g.lg,padding:g.xl,color:x.text,fontSize:k.body,overflowY:"auto",flex:"1 1 auto",minHeight:"0"});const f=t.createElement("p");f.style.margin="0",f.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 l=t.createElement("div");l.dataset.wmapInsightsFilterPreview="1",l.setAttribute("aria-live","polite"),Object.assign(l.style,{fontWeight:"600",color:x.value});const w=()=>{if(!d||d.off){l.textContent=d?"Off: every wafer and die is shown.":"No conditions: every wafer and die is shown.";return}const n=N(d.conditions,s.items,s.ctx);l.textContent=n.issue?`Cannot be applied: ${n.issue}`:`Keeps ${n.wafers.kept.toLocaleString("en-GB")} of ${n.wafers.total.toLocaleString("en-GB")} wafers \xB7 ${n.dies.kept.toLocaleString("en-GB")} of ${n.dies.total.toLocaleString("en-GB")} dies`},p=q({doc:t,catalogue:A(s.items,s.ctx),filter:d,testDefs:s.ctx.testDefs,attributes:h,switchLabel:"Filter",valuesOf:n=>B(n,s.items,s.ctx),extentOf:n=>V(n,s.items,s.ctx),onChange:n=>{d=n,w()}});w();const u=t.createElement("div");Object.assign(u.style,{display:"flex",justifyContent:"flex-end",gap:g.md,flexWrap:"wrap",flexShrink:"0",padding:`${g.md} ${g.xl}`,borderTop:`1px solid ${x.menuBorder}`});const C=O(t,"Cancel","wmapInsightsFilterCancel","Close without changing the filter",()=>r.close());m=O(t,"Apply","wmapInsightsFilterApply","Filter the maps, the gallery and Insights by these conditions",()=>{r.close(),F.set(d)});for(const n of[C,m])n.style.padding=`${g.sm} ${g.lg}`;u.append(C,m);let $="conditions",S;const I=A(s.items,s.ctx),j=ne({doc:t,filter:d,source:()=>({tests:s.ctx.testDefs?.flatMap(n=>n.testNumber!==void 0?[{number:n.testNumber,name:n.name}]:[]),metaKeys:I.flatMap(n=>"meta"in n.field?[{key:n.field.meta,label:n.name}]:[]),conditionValues:n=>B(n,s.items,s.ctx)}),onChange:n=>{d=n,w()},onProblem:n=>{S=n,m&&(m.disabled=!!n,m.style.opacity=n?"0.5":"")}});j.el.style.display="none";const J=n=>{n!==$&&(n==="conditions"?(S&&j.discard(d),p.set(d)):j.set(d),$=n,p.el.style.display=n==="conditions"?"":"none",j.el.style.display=n==="json"?"":"none",n==="json"&&j.focus())},D=te([["conditions","Conditions","Add and change the conditions one at a time"],["json","JSON","The filter as text: paste one in, edit it, with suggestions from this lot"]],"conditions",n=>J(n==="json"?"json":"conditions"),t);D.dataset.wmapFilterMode="1",e.append(f,D,p.el,j.el,l,ie({doc:t,popItems:s,getDraft:()=>d,load:n=>{d={conditions:JSON.parse(JSON.stringify(n.conditions))},p.set(d),$==="json"&&j.set(d),w()},saved:()=>F.saved(),setSaved:n=>F.setSaved(n),onSaveText:i.onSaveText,pickFile:i.pickFiltersFile,attributes:h})),r.contentWrap.style.flexDirection="column",r.contentWrap.append(e,u)}};return F}function ie(i){const{doc:t}=i,h=t.createElement("div");h.dataset.wmapSavedFilters="1",Object.assign(h.style,{display:"flex",flexDirection:"column",gap:g.md,borderTop:`1px solid ${x.menuBorder}`,paddingTop:g.lg});const c=t.createElement("div");c.textContent="Saved filters",Object.assign(c.style,{fontWeight:"600",color:x.value});const y=t.createElement("div");y.dataset.wmapSavedFiltersStatus="1",y.setAttribute("role","status"),Object.assign(y.style,{color:x.label,whiteSpace:"pre-line"});const b=(r,e=[])=>{y.textContent=[r,...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,{...ee(),flex:"1 1 12em"});const F=O(t,"Save","wmapSavedFilterSave","Keep the conditions above under this name",()=>{const r=i.getDraft(),e=v.value.trim();if(!r||r.conditions.length===0){b("Add a condition first: there is nothing to save.");return}if(!e){b("Give the filter a name."),v.focus();return}const f=JSON.parse(JSON.stringify(r.conditions)),l=i.saved(),w=l.findIndex(p=>p.name===e);i.setSaved(w<0?[...l,{id:U(),name:e,conditions:f}]:l.map((p,u)=>u===w?{...p,conditions:f}:p)),v.value="",b(w<0?`Saved \u201C${e}\u201D.`:`Updated \u201C${e}\u201D.`),o()});E.append(v,F);const a=t.createElement("div");a.dataset.wmapSavedFilterList="1",Object.assign(a.style,{display:"flex",flexDirection:"column",gap:g.xs});function o(){a.replaceChildren();const r=i.saved();if(r.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=x.label,a.appendChild(e);return}for(const e of r){const f=t.createElement("div");f.dataset.wmapSavedFilter=e.id,Object.assign(f.style,{display:"flex",gap:g.sm,alignItems:"center",flexWrap:"wrap"});const l=t.createElement("span");Object.assign(l.style,{flex:"1 1 14em",minWidth:"0"});const w=t.createElement("strong");w.textContent=e.name;const p=t.createElement("span");p.style.color=x.label,p.textContent=` \u2014 ${e.conditions.map(S=>W(S,i.popItems.ctx.testDefs,i.attributes)).join(" \xB7 ")}`,l.append(w,p);const u=N(e.conditions,i.popItems.items,i.popItems.ctx).issue;if(u){const S=t.createElement("div");S.dataset.wmapSavedFilterIssue="1",S.textContent=`Cannot be applied to these wafers: ${u}`,Object.assign(S.style,{color:x.warnText,fontSize:k.body}),l.appendChild(S)}const C=O(t,"Load","wmapSavedFilterLoad","Put these conditions in the editor, replacing the ones there",()=>{i.load(e),b(`Loaded \u201C${e.name}\u201D. Press Apply to filter by it.`)}),$=O(t,"Delete","wmapSavedFilterDelete","Remove this saved filter",()=>{const S=i.saved();i.setSaved(S.filter(I=>I.id!==e.id)),b(`Deleted \u201C${e.name}\u201D.`),o()});f.append(l,C,$),a.appendChild(f)}}const s=t.createElement("div");Object.assign(s.style,{display:"flex",gap:g.sm,flexWrap:"wrap"});const d=O(t,"Export\u2026","wmapSavedFilterExport","Save all your saved filters to a file, to share or to keep a copy",()=>{if(i.saved().length===0){b("There are no saved filters to export yet.");return}X(K(i.saved()),"wafermap-filters.json","application/json",i.onSaveText)}),m=O(t,"Import\u2026","wmapSavedFilterImport","Add the filters from a file written by Export\u2026",()=>{(async()=>{const r=await se(t,i.pickFile);if(r===null)return;const e=z(r);if(e.error){b(`Could not import: ${e.error}`);return}const{filters:f,copies:l}=M(i.saved(),e.filters);i.setSaved(f),o(),b(`Imported ${e.filters.length} filter${e.filters.length===1?"":"s"}.`,[...e.warnings,...l.length?[`Kept as copies, since a filter with the same id already existed: ${l.join(", ")}`]:[]])})()});for(const r of[F,d,m])r.style.padding=`${g.sm} ${g.lg}`;return s.append(m,d),Z(v,"The name the filter is listed under; saving under a name already used updates that filter"),o(),h.append(c,E,a,s,y),h}async function se(i,t){return t?t():new Promise(h=>{const c=i.createElement("input");c.type="file",c.accept=".json,application/json",c.addEventListener("change",()=>{const y=c.files?.[0];if(!y){h(null);return}y.text().then(h,()=>h(null))}),c.addEventListener("cancel",()=>h(null)),c.click()})}
@@ -0,0 +1,10 @@
1
+ /** The pinned test numbers, in the order they were pinned. */
2
+ export declare function getPinnedTests(): number[];
3
+ /** Adopt a saved set of pinned tests. Does not call {@link onPinnedTestsChange}: that reports the reader's own changes only. */
4
+ export declare function setPinnedTests(testNumbers: Iterable<number>): void;
5
+ /** Called with the whole set after the reader pins or unpins a test. Returns a function that stops the calls. */
6
+ export declare function onPinnedTestsChange(listener: (testNumbers: number[]) => void): () => void;
7
+ export declare function isTestPinned(testNumber: number): boolean;
8
+ /** The reader's pin or unpin of one test. */
9
+ export declare function toggleTestPinned(testNumber: number): void;
10
+ //# sourceMappingURL=pinnedTests.d.ts.map
@@ -0,0 +1 @@
1
+ const e=new Set,o=new Set;export function getPinnedTests(){return[...e]}export function setPinnedTests(n){e.clear();for(const t of n)Number.isFinite(t)&&e.add(t)}export function onPinnedTestsChange(n){return o.add(n),()=>{o.delete(n)}}export function isTestPinned(n){return e.has(n)}export function toggleTestPinned(n){e.delete(n)||e.add(n);const t=getPinnedTests();for(const i of o)i(t)}
@@ -30,7 +30,7 @@ export interface PlotCardOptions {
30
30
  */
31
31
  drill?: (points: readonly PlotPoint[]) => CardTransform | null;
32
32
  /** What a click on a bar that drills does, in the reader's words ("see its wafers"). */
33
- drillLabel?: string;
33
+ drillLabel?: string | (() => string | undefined);
34
34
  /** Lines the card adds under its statement, for what the plot itself cannot know (two judgements disagreeing). */
35
35
  notes?: (spec: CardSpec) => string[];
36
36
  /** Controls the host owns (a test picker shared across a section, its axis settings), put before the card's own. */
@@ -1 +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
+ import{resolvePlot as k}from"../stats/plotData.js";import{fillCard as y,freezeCard as w}from"../stats/cardSpec.js";import{newPlotId as B}from"../stats/plotSpec.js";import{renderPlotChart as L}from"./charts/plotChart.js";import{makeBackButton as v,makeSegmented as D}from"./charts/chartShell.js";import{markNoPrint as g}from"./toolbar.js";export function renderPlotCard(e){let l;const p=v(()=>{l?(l=void 0,a()):e.externalBack?.onBack()},e.doc);g(p);const h={ownerDocument:e.doc,waferLabel:t=>e.items[t]?.label??"",...e.chart,onSelectPoints:e.drill||e.chart.onSelectPoints?(t,s,i,n)=>{const r=l?null:e.drill?.(t);if(r){l=r,a();return}e.chart.onSelectPoints?.(t,s,i,n)}:void 0},c=L(h),d="build"in e.spec?e.spec:void 0,u=d?.choices.map(t=>t.current)??[],b=()=>d?d.build(u):e.spec,o=()=>l?l(b()):b(),x=()=>({testDefs:e.ctx.testDefs,groupBy:e.ctx.groupBy,...e.slots?.()});if(e.editAsPlot){const t=e.editAsPlot;c.setMenuRows(()=>{const s=w(o(),{...x(),waferCount:e.items.length},B());return[{label:"Edit as plot",disabledHint:"issue"in s?s.issue:void 0,onClick:()=>{"spec"in s&&t(s.spec,{items:e.items,ctx:e.ctx})}}]})}c.actions.appendChild(p);for(const t of e.extras??[])c.actions.appendChild(t);let m=[],P;const C=()=>{const t=!!l;if(P===t)return;P=t;const s=(d?.choices??[]).map((i,n)=>{const r=D(typeof i.options=="function"?i.options(t):i.options,u[n],f=>{u[n]=f,a()},e.doc);return g(r),r});if(m.length)m.forEach((i,n)=>i.replaceWith(s[n]));else for(const i of s)c.actions.appendChild(i);m=s};function a(){C(),p.style.display=l||e.externalBack?.shown()?"":"none";const t=y(o(),x()),s=typeof e.drillLabel=="function"?e.drillLabel():e.drillLabel;h.selectActionLabel=e.drill&&!l&&s?s:e.chart.selectActionLabel;const i="spec"in t?t.spec:{...o(),fields:{}},n=k(i,e.items,e.ctx),r=e.notes?.(o())??[],f=e.unavailable?{...n,marks:void 0,issues:[e.unavailable]}:"issue"in t?{...n,issues:[t.issue]}:r.length?{...n,notes:[...n.notes,...r]}:n;c.setPlot(f),e.onResolved?.(f)}return a(),{card:c.card,current:o,refresh:a,destroy:()=>c.destroy()}}