@wafertools/wafermap 0.40.0 → 0.40.1

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 (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/packages/canvas-adapter/charts/commonality.js +3 -3
  3. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +5 -2
  4. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  6. package/dist/packages/canvas-adapter/dataTab.d.ts +12 -6
  7. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  8. package/dist/packages/canvas-adapter/drilldown.d.ts +1 -1
  9. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  10. package/dist/packages/canvas-adapter/filterButton.d.ts +2 -0
  11. package/dist/packages/canvas-adapter/filterButton.js +1 -1
  12. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  13. package/dist/packages/canvas-adapter/insightsTab.d.ts +9 -4
  14. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  15. package/dist/packages/canvas-adapter/openWaferMode.d.ts +7 -0
  16. package/dist/packages/canvas-adapter/openWaferMode.js +1 -0
  17. package/dist/packages/canvas-adapter/plotTab.d.ts +1 -1
  18. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  19. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  20. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  21. package/dist/packages/canvas-adapter/summaryPanel.d.ts +2 -2
  22. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  23. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  24. package/dist/packages/canvas-adapter/userGuideHtml.js +20 -13
  25. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  26. package/dist/packages/canvas-adapter/version.js +1 -1
  27. package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -1
  28. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  29. package/dist/packages/renderer/buildView.js +1 -1
  30. package/dist/packages/renderer/fmt.d.ts +2 -0
  31. package/dist/packages/renderer/fmt.js +1 -1
  32. package/dist/packages/stats/commonality.d.ts +1 -1
  33. package/dist/packages/stats/commonality.js +1 -1
  34. package/dist/packages/stats/examplePicks.js +1 -1
  35. package/dist/packages/stats/groupEffects.d.ts +8 -0
  36. package/dist/packages/stats/groupEffects.js +1 -1
  37. package/dist/packages/stats/plotData.d.ts +7 -2
  38. package/dist/packages/stats/plotData.js +1 -1
  39. package/dist/packages/stats/synthesis.d.ts +8 -1
  40. package/dist/packages/stats/synthesis.js +1 -1
  41. package/package.json +1 -1
@@ -1 +1 @@
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
+ import{maxOf as J}from"../core/utils.js";import{isYieldEligibleDie as Y}from"../core/dies.js";import{testValue as B}from"../core/dieTable.js";import{metadataDisplayValue as z}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 N=(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 p=d.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:T.md,minWidth:"0"}),s.appendChild(p);const y=DATA_VIEWS.filter(m=>!t.views||t.views.includes(m.key)),o=X(d,"Table",y,t.view,"wmapDataView",m=>t.onViewChange(m));a.appendChild(o.el);let r;switch(t.view){case"dies":r=he(t);break;case"wafers":r=ge(t);break;default:r=fe(t)}let h=()=>{};if(t.view==="dies"){const m=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",f=>{m.set(f),t.onDiesLayoutChange(f),r.actions?.setLayout?.(f),h()});V(m.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,m.el),a.appendChild(c)}if(r.actions){const m=r.actions,c=d.createElement("div");c.style.flex="1",a.appendChild(c);const l=_(d,"Export CSV");l.dataset.wmapDataExport="1",l.addEventListener("click",()=>{if(l.disabled)return;const w=l.textContent,b=m.exportCsv();b&&(l.disabled=!0,l.setAttribute("aria-busy","true"),b.catch(()=>{}).finally(()=>{l.disabled=!1,l.removeAttribute("aria-busy"),l.textContent=w}))});const f=_(d,"Copy");f.dataset.wmapDataCopy="1",m.copyText?(V(f,"Copy the table as tab-separated text, to paste into a spreadsheet"),f.addEventListener("click",()=>{const w=m.copyText(),b=d.defaultView?.navigator?.clipboard;if(!b)return;const x=f.textContent;b.writeText(w).then(()=>{f.textContent="Copied",d.defaultView?.setTimeout(()=>{f.textContent=x},1500)}).catch(()=>{})})):(f.disabled=!0,V(f,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),a.append(f,l);const g=d.createElement("div");g.dataset.wmapDataNote="1",g.textContent=m.note(),h=()=>{g.textContent=m.note()},Object.assign(g.style,{color:S.label,fontSize:k.body}),s.insertBefore(g,p)}return p.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=[],p=t.groups&&t.groups.length>0?t.groups:void 0,y=p??[{key:"",items:t.items}];if(p&&p.length>1){const o=me(t,p);o&&(s.appendChild(o.el),a.push(o.destroy))}for(const o of y){if(p){const h=d.createElement("div");h.textContent=`${t.groupLabelText??"Group"}: ${o.key}`,Object.assign(h.style,{fontWeight:"700",color:S.text,fontSize:k.body}),s.appendChild(h)}const r=t.buildStatistics(o.items);a.push(r.destroy);for(const h of r.cards)s.appendChild(h)}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 p=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 ${p}`,Object.assign(r.style,{fontWeight:"700",color:S.text,fontSize:k.body}),o.appendChild(r);const h=s.createElement("div");h.textContent="Computing test statistics\u2026",Object.assign(h.style,{color:S.label,fontSize:k.body}),y.append(o,h);const m=new Map;let c=d.length,l,f=!1;const g=()=>{if(f)return;const b=[];for(const e of a)for(const n of d){const u=m.get(n.key),i=u?.stats.get(e.testNumber);if(!u||!i)continue;const C=u.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:u.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)),u=J(e.map(i=>i.limitYield??-1/0));e.forEach((i,C)=>{i.meanShade=n[C],i.yieldShade=i.limitYield===void 0||!Number.isFinite(u)?void 0:U(i.limitYield-u)})}const v=e=>({get:n=>I(e(n),n.def.unit),numeric:!0,sortKey:e}),L=(e,n)=>({get:u=>{const i=e(u);return i===void 0||!Number.isFinite(i)?"":n(i)},numeric:!0,sortKey:u=>{const i=e(u);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:p,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 ${p} (${b.length})`,ownerDocument:s});E.el.style.maxHeight="50vh",E.el.style.minHeight="120px",l=E;const O=()=>[{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:p,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}],$=_(s,"Statistics CSV");$.dataset.wmapGroupStatsCsv="1",$.addEventListener("click",()=>{A(O(),E.orderedRows(),`statistics-by-${p.toLowerCase().replace(/[^a-z0-9]+/g,"-")}.csv`,t.onSaveText,{rowCount:b.length})}),o.appendChild($),h.replaceWith(E.el)},w=[];for(const b of d)w.push(ae(ie(b.items.map(x=>({dies:x.dies})),a),{onDone:x=>{m.set(b.key,x),--c===0&&g()}}));return{el:y,destroy:()=>{f=!0;for(const b of w)b.cancel();l?.destroy()}}}function pe(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 h=ce(r,d,o.passBins);r.forEach((m,c)=>a.set(m,h[c]))}if(a.size===0)return;const p=o=>{const r=d.find(h=>h.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(p).join("; "):""},anyOutlier:y}}function he(t){const{doc:d,items:s}=t,a=new WeakMap,p=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&&p.set(n,e.wafer),o.push(n)}if(o.length===0)return Q(d,"No dies to show.");const h=pe(s,t.allTestDefs,!!t.population),{columns:m,visibleColumns:c}=te(o,t.allTestDefs,{...t.dieListOptions,...h?{patColumns:h}:{},metadataFields:t.metadataFields,extraColumn:s.length>1||t.population?{label:"Wafer",get:e=>a.get(e)}:void 0,getWafer:r?(e=>p.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 u=e.test,i=B(n,u.testNumber);return i!==void 0&&Number.isFinite(i)&&(u.limitLow!==void 0&&i<u.limitLow||u.limitHigh!==void 0&&i>u.limitHigh)?le():void 0}}:{}})),f=P({columns:l,rows:o,ariaLabel:`Dies (${o.length})`,ownerDocument:d,onRowClick:t.onLocateDie?(e,n,u)=>t.onLocateDie(e,y.get(e),c[u]?.test?.testNumber):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="240px";const g=t.population?`-${t.population.fileTag}`:"",w=m.filter(e=>e.test!==void 0),b=m.filter(e=>e.test===void 0),x=o.length*m.length,v=o.length*w.length,L=()=>m.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 f.orderedRows())for(const n of w){const u=(n.csvGet??n.get)(e);u===""||u===void 0||u===null||(yield{die:e,test:n.test,value:u})}}let O=t.diesLayout==="long"&&w.length>0;const $=()=>O?`Long format: up to ${N(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: ${N(o.length,"row")} \xD7 ${N(m.length,"column")}`+(o.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${N(o.length,"die")} ${t.population?.phrase??`on ${N(s.length,"wafer")}`}. ${$()} Export follows the order shown.${t.onLocateDie?" Click a row to see that die ringed on the map of its wafer, on the test whose column you click.":""}`,setLayout:e=>{O=e==="long"&&w.length>0},exportCsv:()=>O?A(D(),E(),`die-list-long${g}.csv`,t.onSaveText,{rowCount:v}):A(L(),f.orderedRows(),`die-list${g}.csv`,t.onSaveText,{rowCount:o.length}),copyText:x<=COPY_CELL_LIMIT?()=>H(L(),f.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),u=ee([{label:e.label,dies:e.dies,passBins:e.passBins,yieldPercent:n,key:e.waferIndex}])[0]?.percent;return{item:e,yieldPercent:e.dies.length?u??null:null}}),p=[];for(const{item:e}of a)for(const n of Object.keys(e.wafer?.metadata??{}))!p.includes(n)&&z((e.wafer?.metadata)[n])!==void 0&&p.push(n);const y=t.testDefs.slice(0,WAFER_TEST_COLUMNS),o=(e,n)=>{const u=e.item.statsSummary?.stats.perTestStats?.find(W=>W.testNumber===n.testNumber);if(u)return u.mean;let i=0,C=0;for(const W of e.item.dies){if(!Y(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)=>z(e.item.wafer?.metadata?.[n])??"",h=e=>({header:F(e,t.attributes),cell:n=>r(n,e)}),m=e=>a.length>1&&a.every(n=>r(n,e)===r(a[0],e)),c=p.filter(m),l=p.filter(e=>!c.includes(e)),f=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=>Y(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),opens:"bins"},...y.map(e=>{const n=new Map,u=K(a.map(i=>o(i,e)??NaN),i=>I(i,e.unit));return a.forEach((i,C)=>n.set(i,u[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),opens:{testNumber:e.testNumber}}})],x=[{header:"Wafer",cell:e=>e.item.label},...f?[h(f)]:[],...b,...l.filter(e=>e!==f).map(h)],v=[...x,...c.map(h)],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 u=e.cell(n);return typeof u=="number"?u:void 0}}:{}})),D=P({columns:L,rows:a,ariaLabel:`Wafers (${a.length})`,ownerDocument:d,onRowClick:t.onOpenWafer?(e,n,u)=>{const i=x[u]?.opens;t.onOpenWafer(e.item.waferIndex,e.item.label,typeof i=="object"?i.testNumber:void 0,i==="bins"?"bins":void 0)}:void 0});D.el.style.maxHeight="70vh",D.el.style.minHeight="120px";const E=()=>v.map(e=>({header:e.header,get:e.cell})),O=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:()=>`${N(a.length,"wafer")}.${O}${t.onOpenWafer?" Click a row to open that wafer, on the test whose mean you click, or on its bins for its yield.":""} 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 _(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,p,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 h=a;const m=()=>{for(const c of r){const l=c.dataset[p]===h;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[p]=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",()=>{h!==c.key&&y(c.key)}),r.push(l),o.appendChild(l)}return m(),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 f=r[(l+(c.key==="ArrowRight"?1:-1)+r.length)%r.length];f.click(),f.focus()}),{el:o,set:c=>{h=c,m()}}}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})),p=a.flatMap(g=>g.dies),y=t.testDefs??[],o=y.filter(j),r=t.views??(a.length>1?["statistics","wafers","dies"]:["statistics","dies"]),h=t.population?{populationLabel:`${N(p.length,"die")} ${t.population}`}:a.length>1?{perWaferMetadata:a.map(g=>g.wafer?.metadata??{}),populationLabel:`${N(a.length,"wafer")} pooled`}:{waferMetadata:a[0]?.wafer?.metadata};let m=r.includes(t.view)?t.view:r[0],c="wide",l=null;const f=()=>{l?.destroy(),l=renderDataSection({doc:d,items:a,testDefs:o,allTestDefs:y,ringCount:t.ringCount,yieldByWaferIndex:new Map,onSaveText:t.onSaveText,views:r,view:m,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,h,g.map(L=>({dies:L.dies})),void 0,"full");x&&b.push(x);const v=se(w,y,void 0,t.onSaveText,h);return v&&b.push(v),{cards:b,destroy:()=>{}}},onViewChange:g=>{m=g,f()},diesLayout:c,onDiesLayoutChange:g=>{c=g}}),s.replaceChildren(l.card)};return f(),{el:s,destroy:()=>l?.destroy()}}export function renderSelectionTables(t){return renderDataTables({...t,views:t.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
@@ -17,7 +17,7 @@ export interface DrilldownContext {
17
17
  /** The host's CSV save hook, for the tables' Export CSV. */
18
18
  onSaveText?: SaveTextHandler;
19
19
  /** A die row clicked in a table: show that die on the map it belongs to. The table steps aside first. */
20
- onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
20
+ onLocateDie?: (die: Die, waferIndex: number | undefined, testNumber?: number) => void;
21
21
  /**
22
22
  * A narrower population for the same dies, offered as the menu's first row: the menu reopens on it, and its own
23
23
  * `narrower` is the population it left, so the row swaps back. Set by a gallery when dies are selected on several
@@ -1 +1 @@
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}
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,w=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=w(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=w(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,v,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 ${v}`,`Population: ${v}`,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)),v=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:v,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:v,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=w(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,v)=>{const g=oe(l,o,e.testDefs);g&&openDrilldownMenu(b,v,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=w(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=w(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,v)=>{h?.(),t.onLocateDie(l,b,v)}: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(w(n).length,w(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=w(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}
@@ -1,3 +1,5 @@
1
1
  /** The small outlined button the band, the editor and each view's Filter button share. */
2
2
  export declare function bandButton(doc: Document, text: string, hook: string, hint: string, onClick: () => void): HTMLButtonElement;
3
+ /** What a view says where its maps or charts would be when the filter keeps nothing. */
4
+ export declare function filterKeepsNothing(doc: Document, hook: string): HTMLDivElement;
3
5
  //# sourceMappingURL=filterButton.d.ts.map
@@ -1 +1 @@
1
- import{FONT as d,SPACE as l,controlStyle as a,wireControlHover as c,wireTooltip as b}from"./toolbar.js";export function bandButton(e,n,o,r,i){const t=e.createElement("button");return t.type="button",t.textContent=n,t.dataset[o]="1",Object.assign(t.style,{...a("outlined"),fontSize:d.body,padding:`0 ${l.md}`}),c(t),b(t,r),t.addEventListener("click",i),t}
1
+ import{CLR as l,FONT as i,SPACE as r,controlStyle as s,wireControlHover as c,wireTooltip as f}from"./toolbar.js";export function bandButton(n,o,e,d,a){const t=n.createElement("button");return t.type="button",t.textContent=o,t.dataset[e]="1",Object.assign(t.style,{...s("outlined"),fontSize:i.body,padding:`0 ${r.md}`}),c(t),f(t,d),t.addEventListener("click",a),t}export function filterKeepsNothing(n,o){const e=n.createElement("div");return e.dataset[o]="1",e.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(e.style,{color:l.label,fontSize:i.body,padding:r.xl}),e}
@@ -1 +1 @@
1
- import{metadataEntries as v,buildCompactMetadataRows as $}from"./summaryPanel.js";import{attributeLabel as M}from"../stats/facets.js";import{SHADOW as L,LEADING as E,SPACE as C,FONT as g,CLR as x,RADIUS as j,Z_ABOVE as H,wireExpandToggle as z,wireControlHover as P}from"./toolbar.js";export function createMetaPanelEl(i){const t=i.createElement("div");return Object.assign(t.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:H,background:x.menuBg,borderBottom:`1px solid ${x.menuBorder}`,boxShadow:L.menu,padding:`${C.md} ${C.lg}`,fontSize:g.body,display:"none"}),t}export function attachExpandableMetadata(i,t,a,n,p){const o=n??{};if(v(o).length===0)return null;const r=i.createElement("span");Object.assign(r.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0"}),r.textContent="\u25BE",t.appendChild(r),Object.assign(t.style,{cursor:"pointer",borderRadius:j.control}),P(t,"bare");const s=createMetaPanelEl(i);s.dataset.wmapCardMetaPanel="1";const d=$(o,p);return d&&s.appendChild(d),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-label",`Wafer info for ${a||"this card"}. Click to expand.`),z(t,e=>{r.textContent=e?"\u25B4":"\u25BE",t.setAttribute("aria-expanded",String(e)),s.style.display=e?"block":"none"}),s}export function collapsedLabel(i,t){if(t)return t.aggrMethod?`${t.lotSize} wafers \xB7 ${t.aggrMethod}`:`${t.lotSize} wafers`;if(i.lot&&i.waferId!==void 0&&i.waferId!==""){const a=String(i.lot),n=String(i.waferId);return n.includes(a)?n:`${a} \xB7 ${n}`}for(const a of["lot","waferId","product","testProgram"]){const n=i[a];if(n!=null&&n!=="")return String(n)}}export function createIdentityHeader(i,t,a={}){let n=i,p=t??{},o=a.lotStack,r=!1,s=!1;const d=a.ownerDocument??document,e=d.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",gap:C.xs,minWidth:"0"});const h=d.createElement("span");Object.assign(h.style,{fontWeight:"700",fontSize:g.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),e.appendChild(h);const w=d.createElement("span");Object.assign(w.style,{fontSize:g.body,lineHeight:E.none,color:x.label,flexShrink:"0",display:"none"}),e.appendChild(w);const A=4,c=d.createElement("span");Object.assign(c.style,{fontSize:g.body,color:x.label,whiteSpace:"nowrap",overflow:"hidden",flexShrink:"0",display:"none",marginLeft:C.sm}),e.appendChild(c);const f=createMetaPanelEl(d);f.dataset.wmapMetaPanel="1";function S(){return v(p).length>0||!!o}function I(){return o?[]:v(p).filter(([,l])=>!n.includes(l))}function W(){return e.clientWidth?h.scrollWidth>h.clientWidth||c.scrollWidth>c.clientWidth||e.scrollWidth>e.clientWidth:!0}function m(){h.textContent=n;const l=I();c.textContent=l.map(([b,y])=>`${M(b,a.attributes)}: ${y}`).join(" \xB7 "),c.style.display=l.length>0?"":"none",s=l.length>0&&l.length<=A&&!W(),c.style.display=s?"":"none";const u=S()&&!s;if(w.style.display=u?"":"none",e.style.cursor=u?"pointer":"",u||(r=!1),w.textContent=r?"\u25B4":"\u25BE",f.style.display=r?"block":"none",u?(e.setAttribute("aria-expanded",String(r)),e.setAttribute("aria-label",`Wafer info: ${n||"this wafer"}. ${r?"Click to collapse.":"Click to expand."}`)):(e.removeAttribute("aria-expanded"),e.removeAttribute("aria-label")),f.innerHTML="",r){if(o){const y=d.createElement("div");Object.assign(y.style,{fontWeight:"600",marginBottom:"3px"}),y.textContent=o.aggrMethod?`${o.lotSize} wafers stacked \xB7 ${o.aggrMethod}`:`${o.lotSize} wafers stacked`,f.appendChild(y)}const b=$(p,a.attributes);b&&f.appendChild(b)}}const k=z(e,l=>{!S()||s||(r=l,m())});m();const O=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>m());return O?.observe(e),{wrap:e,metaPanel:f,update(l,u,b){n=l,p=u??{},o=b,m()},isEmpty(){return!n&&!S()},collapse(){r&&(r=!1,m())},destroy(){O?.disconnect(),k.destroy(),e.remove(),f.remove()}}}
1
+ import{metadataEntries as v,buildCompactMetadataRows as E}from"./summaryPanel.js";import{attributeLabel as M}from"../stats/facets.js";import{SHADOW as k,LEADING as A,SPACE as C,FONT as y,CLR as x,RADIUS as j,Z_ABOVE as H,wireExpandToggle as I,wireControlHover as P}from"./toolbar.js";import{fmtAggregationMethod as R,fmtStackedLabel as B}from"../renderer/fmt.js";export function createMetaPanelEl(i){const t=i.createElement("div");return Object.assign(t.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:H,background:x.menuBg,borderBottom:`1px solid ${x.menuBorder}`,boxShadow:k.menu,padding:`${C.md} ${C.lg}`,fontSize:y.body,display:"none"}),t}export function attachExpandableMetadata(i,t,a,n,p){const l=n??{};if(v(l).length===0)return null;const r=i.createElement("span");Object.assign(r.style,{fontSize:y.body,lineHeight:A.none,color:x.label,flexShrink:"0"}),r.textContent="\u25BE",t.appendChild(r),Object.assign(t.style,{cursor:"pointer",borderRadius:j.control}),P(t,"bare");const s=createMetaPanelEl(i);s.dataset.wmapCardMetaPanel="1";const d=E(l,p);return d&&s.appendChild(d),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-label",`Wafer info for ${a||"this card"}. Click to expand.`),I(t,e=>{r.textContent=e?"\u25B4":"\u25BE",t.setAttribute("aria-expanded",String(e)),s.style.display=e?"block":"none"}),s}export function collapsedLabel(i,t){if(t)return t.aggrMethod?`${t.lotSize} wafers \xB7 ${R(t.aggrMethod)}`:`${t.lotSize} wafers`;if(i.lot&&i.waferId!==void 0&&i.waferId!==""){const a=String(i.lot),n=String(i.waferId);return n.includes(a)?n:`${a} \xB7 ${n}`}for(const a of["lot","waferId","product","testProgram"]){const n=i[a];if(n!=null&&n!=="")return String(n)}}export function createIdentityHeader(i,t,a={}){let n=i,p=t??{},l=a.lotStack,r=!1,s=!1;const d=a.ownerDocument??document,e=d.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",gap:C.xs,minWidth:"0"});const h=d.createElement("span");Object.assign(h.style,{fontWeight:"700",fontSize:y.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),e.appendChild(h);const w=d.createElement("span");Object.assign(w.style,{fontSize:y.body,lineHeight:A.none,color:x.label,flexShrink:"0",display:"none"}),e.appendChild(w);const W=4,c=d.createElement("span");Object.assign(c.style,{fontSize:y.body,color:x.label,whiteSpace:"nowrap",overflow:"hidden",flexShrink:"0",display:"none",marginLeft:C.sm}),e.appendChild(c);const f=createMetaPanelEl(d);f.dataset.wmapMetaPanel="1";function S(){return v(p).length>0||!!l}function $(){return l?[]:v(p).filter(([,o])=>!n.includes(o))}function z(){return e.clientWidth?h.scrollWidth>h.clientWidth||c.scrollWidth>c.clientWidth||e.scrollWidth>e.clientWidth:!0}function m(){h.textContent=n;const o=$();c.textContent=o.map(([b,g])=>`${M(b,a.attributes)}: ${g}`).join(" \xB7 "),c.style.display=o.length>0?"":"none",s=o.length>0&&o.length<=W&&!z(),c.style.display=s?"":"none";const u=S()&&!s;if(w.style.display=u?"":"none",e.style.cursor=u?"pointer":"",u||(r=!1),w.textContent=r?"\u25B4":"\u25BE",f.style.display=r?"block":"none",u?(e.setAttribute("aria-expanded",String(r)),e.setAttribute("aria-label",`Wafer info: ${n||"this wafer"}. ${r?"Click to collapse.":"Click to expand."}`)):(e.removeAttribute("aria-expanded"),e.removeAttribute("aria-label")),f.innerHTML="",r){if(l){const g=d.createElement("div");Object.assign(g.style,{fontWeight:"600",marginBottom:"3px"}),g.textContent=B(l.lotSize,l.aggrMethod),f.appendChild(g)}const b=E(p,a.attributes);b&&f.appendChild(b)}}const L=I(e,o=>{!S()||s||(r=o,m())});m();const O=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>m());return O?.observe(e),{wrap:e,metaPanel:f,update(o,u,b){n=o,p=u??{},l=b,m()},isEmpty(){return!n&&!S()},collapse(){r&&(r=!1,m())},destroy(){O?.disconnect(),L.destroy(),e.remove(),f.remove()}}}
@@ -122,6 +122,11 @@ export interface InsightsTabDeps {
122
122
  getItems: () => Array<WaferMapDisplayItem | null>;
123
123
  /** Precomputed lot-level yield, when the host has one — reused directly instead of recomputing (see stats/yield.ts). Omit when there is no lot (e.g. a single wafer). */
124
124
  getLotStats?: () => LotStatsSummary | undefined;
125
+ /**
126
+ * The analysis What stands out beside the map is built from now: the lot's or the wafer's, and while the filter narrows,
127
+ * the one over what it keeps (undefined while that is being worked out). Worth a look draws the same list from it.
128
+ */
129
+ getSynthesisSummary?: () => StatsSummary | LotStatsSummary | undefined;
125
130
  /**
126
131
  * The host map's resolved bin colours (`View.binColors`, or the gallery's
127
132
  * gallery-wide assignment) — read fresh each render so a live palette change is
@@ -141,7 +146,7 @@ export interface InsightsTabDeps {
141
146
  * plot mode — so opening from a specific test's boxplot row lands on that
142
147
  * same test instead of hard-bin mode.
143
148
  */
144
- openWafer?: (waferIndex: number, label: string, testNumber?: number) => void;
149
+ openWafer?: (waferIndex: number, label: string, testNumber?: number, view?: 'bins') => void;
145
150
  /**
146
151
  * Shows `testNumber` on the host's own map, in test-value mode, and leaves
147
152
  * Insights — the single-wafer counterpart to `openWafer`.
@@ -160,10 +165,10 @@ export interface InsightsTabDeps {
160
165
  */
161
166
  focusTest?: (testNumber: number) => void;
162
167
  /**
163
- * A die row clicked in a table (the Data tab, or a table opened from a chart): leave Insights and show
164
- * that die on its map. Omit where there is no map to go back to; the rows are then not clickable.
168
+ * A die row clicked in a table (the Data tab, or a table opened from a chart): show that die on its wafer's map, on
169
+ * the test whose column was clicked. Omit where there is no map to go to; the rows are then not clickable.
165
170
  */
166
- locateDie?: (die: Die, waferIndex: number | undefined) => void;
171
+ locateDie?: (die: Die, waferIndex: number | undefined, testNumber?: number) => void;
167
172
  /** Default sub-tab shown on first render. Default 'overview'. */
168
173
  defaultView?: InsightsView;
169
174
  /** Sweep definitions to render in the Distributions view — see `InsightsOptions.sweeps`. */
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as en}from"../stats/presentation.js";import{buildFacetTable as tn,facetValueOf as Ye,FACET_NONE_VALUE as nn,DEFAULT_FACET_CURATION as sn}from"../stats/facets.js";import{mergeTestDefs as _e}from"../stats/mergeTestDefs.js";import{isParametricTest as Be}from"../renderer/buildWaferMap.js";import{dieFailsTest as rn,hasJudgeableTests as an,testsForPassKind as on,buildTestPassRateData as lt}from"../stats/testPassRate.js";import{fmt as dt}from"../renderer/fmt.js";import{testLabel as ct}from"../renderer/testLabel.js";import{waferDisplayLabel as ln,waferIdentityLabel as dn}from"../core/waferLabel.js";import{waferPopulation as cn}from"./chartPopulation.js";import{openDrilldownMenu as Ve}from"./drilldown.js";import{plotStoreFor as un}from"./plotStore.js";import{createPageFilter as fn}from"./pageFilter.js";import{bandButton as pn}from"./filterButton.js";import{itemPassBins as hn,passBinsLabel as ut}from"../core/passBins.js";import{describeWaferPopulation as mn,populationStat as gn}from"../stats/population.js";import{LEADING as Ge,ALPHA as bn,SPACE as A,EDGE_GUTTER as qe,FONT as G,CLR as M,RADIUS as yn,SHADOW as wn,controlStyle as ft,wireControlHover as $e,wireTooltip as ke}from"./toolbar.js";import{ICONS as xn}from"./icons.js";import{renderCapabilityPanel as Sn}from"./charts/capability.js";import{renderGroupComparisonPanel as vn}from"./charts/groupComparison.js";import{renderCommonalityPanel as Cn}from"./charts/commonality.js";import{renderPatCard as Bn}from"./charts/patCard.js";import{renderDifferenceMapPanel as $n}from"./differenceMapPanel.js";import{renderCorrelationPanel as kn}from"./charts/correlation.js";import{cardFrameStyle as En,pairCards as In,makeChartGridWrap as Ee,makeLabeledSelect as pt,makeLinkedGroupSelect as Tn,makeLinkedTestSelect as ht,makeWaferSelect as mt,makeTestSelect as gt,isExpandedCard as On,makeLinkedAxisPrefs as bt,makeToggle as Ke,limitLines as Ie,limitExtent as yt,shouldIncludeLimitsByDefault as wt,hasBothLimitKinds as xt}from"./charts/chartShell.js";import{maxOf as St,minOf as vt}from"../core/utils.js";import{buildYieldData as Ct,buildYieldDataCombined as An}from"../stats/yield.js";import{buildLotTestSectionSteps as Pn,buildLotFunctionalSection as Ln,buildMetadataStripBox as Wn}from"./summaryPanel.js";import{runChunked as Dn}from"./chunked.js";import{buildRegionYieldData as Xe,buildRingRegions as Bt,buildQuadrantRegions as $t,buildReticlePositionRegions as Rn,diesInRegion as Nn}from"../stats/regions.js";import{renderDataSection as Mn}from"./dataTab.js";import{sourceFromDies as jn,toPlotItems as oe}from"./plotItems.js";import{rankTestsByWaferSpread as Fn}from"../stats/testsByWafer.js";import{isYieldEligibleDie as zn}from"../core/dies.js";import{renderPlotCard as Hn}from"./plotCard.js";import{orderFieldValues as Yn,axisValues as kt}from"../stats/plotData.js";import{buildSynthesis as _n,groupColouredChart as Vn,synthesisKey as Gn,SYNTHESIS_POSSIBLE_HEADING as qn}from"../stats/synthesis.js";import{commonPassBins as Kn}from"../core/passBins.js";import{renderRegionYieldDiagram as Ue}from"./charts/regionYieldDiagram.js";const Xn=12,Un=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Qn={key:"data",label:"Data"},Jn={key:"plot",label:"My plots"},Zn={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(I){const{getItems:Et,getLotStats:Qe,getBinColors:ie,getRingCount:Q,onSaveImage:R,onSaveText:J,openWafer:se,focusTest:Te,locateDie:me}=I,xe={...sn,...I.attributes},It=I.showMetadataStrip??!0,le=I.contentInset??qe,r=I.ownerDocument??document,Y=r.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Tt=qe,ue=r.createElement("div");Object.assign(ue.style,{paddingLeft:Tt});const te=r.createElement("div");Object.assign(te.style,{display:"flex",gap:A.xs,alignItems:"center",background:M.menuBg,border:`1px solid ${M.menuBorder}`,borderRadius:yn.container,boxShadow:wn.panel,padding:`0 ${A.lg}`,margin:"0"}),te.setAttribute("role","tablist");const Oe=r.createElement("div");Object.assign(Oe.style,{position:"sticky",top:"var(--wmap-sticky-top, 0px)",zIndex:"1",background:M.menuBg,paddingLeft:le,paddingRight:le,paddingBottom:A.lg}),Oe.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(r.activeElement);if(s===-1)return;e.preventDefault();const i=t[(s+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];i.focus(),i.click()});const re=r.createElement("div");Object.assign(re.style,{display:"flex",flexDirection:"column",gap:A.lg,marginTop:"0",isolation:"isolate",paddingLeft:le,paddingRight:le});const Se=I.pageFilter??fn({doc:r,initial:I.filter,onChange:I.onFilterChange,attributes:I.attributes,getRingCount:I.getRingCount}),Je=Se.createBand(()=>Fe(),{marginLeft:le,marginRight:le,marginBottom:A.lg}),Ot=Je.el;let de,Ae=null;const At=()=>{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},ve=()=>{if(de===void 0){Y.style.removeProperty("--wmap-insights-cols"),Y.style.removeProperty("--wmap-insights-min");return}const e=At(),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")},Ze=e=>{de=e,ve(),Ae&&(Ae.value=e===void 0?"auto":String(e))},et=r.defaultView?.MutationObserver;let Pe=0;const tt=et?new et(()=>{if(Pe||de===void 0)return;const e=r.defaultView;if(!e){ve();return}Pe=e.requestAnimationFrame(()=>{Pe=0,ve()})}):void 0;tt?.observe(re,{childList:!0,subtree:!0});const nt=e=>{if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.defaultPrevented||!/^[0-5]$/.test(e.key)||!Y.isConnected||Y.style.display==="none"||r.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(),Ze(e.key==="0"?void 0:Number(e.key)))};r.addEventListener("keydown",nt),Y.appendChild(ue),Y.appendChild(Oe),Y.appendChild(Ot),Y.appendChild(re);const Pt=[...Un,Qn,Jn],fe=I.plotStore??un(I),Z=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:s})=>s({doc:r,anchor:Y,store:fe,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:R,binColors:ie()}}))};let X=I.defaultView==="sweeps"?"plot":I.defaultView??"overview",W,Le=!1;Se.subscribe(()=>ne());let st="statistics",rt="wide",q=null,at=null,We=[],_=null,De=I.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=e=>Hn({...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"}:{}}}}),Re=new Map,Ne=(e,t,s=!1)=>{De=e;for(const i of Re.values())for(const f of i)f!==t&&f.setAxisPrefs(e);s||I.onAxisPrefsChange?.(e)},Me=e=>{_!==e&&(_=e,ne())};let pe=new Map;function ot(){for(const e of pe.values())e.destroy();pe=new Map}function je(e,t,s){se?.(e,t,s)}function ge(e){return(t,s,i)=>{const f=e.find(d=>d.waferIndex===t);if(!f)return;i.preventDefault();const S=cn(f.dies,{waferLabel:f.identity,testDefs:f.testDefs,activeTest:s??q??void 0,waferIndex:t,wafer:f.wafer,passBins:f.passBins,ringCount:Q()});Ve({x:i.clientX,y:i.clientY},i.target,S,{plots:fe,getBinColors:ie,onSaveImage:R,onSaveText:J,onLocateDie:me})}}function Lt(e,t,s,i,f){ce({x:e.clientX,y:e.clientY},e.target,t,s,i,f)}function be(e,t,s){return(i,f,S,d)=>{const c=new Set(i.map(o=>o.die).filter(o=>!!o)),m=new Set(i.map(o=>e[o.item]?.waferIndex));ce(f,S,t.filter(o=>m.has(o.waferIndex)),s(d),c.size?o=>c.has(o):()=>!0)}}function ce(e,t,s,i,f,S){const d=jn(s.map(c=>({label:c.identity??c.label,dies:c.dies,waferIndex:c.waferIndex,wafer:c.wafer,passBins:c.passBins,ringCount:Q()})),i,f,_e(s).defs,S);d&&Ve(e,t,d,{plots:fe,getBinColors:ie,onSaveImage:R,onSaveText:J,onLocateDie:me})}function it(e){return se?{open:(t,s)=>je(t,`Wafer ${e.find(i=>i.waferIndex===t)?.label??t}`,s)}:Te&&e.length===1?{open:(t,s)=>Te(s),label:"show this test on the map"}:null}function Fe(){return Et().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:ln(e,t),identity:dn(e),waferIndex:t,passBins:hn(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function Wt(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:`${A.sm} ${qe} ${A.md}`,cursor:"pointer"})}function Dt(e,t){const s=r.createElement("button");s.type="button",s.textContent=t;const i=e===X;Wt(s,i),s.dataset.on=i?"true":"false",$e(s,"bare"),s.dataset.wmapInsightsTab=e;const f=Zn[e];return f&&ke(s,f),s.setAttribute("role","tab"),s.setAttribute("aria-selected",i?"true":"false"),s.tabIndex=i?0:-1,s.addEventListener("click",()=>{X!==e&&(X=e,ne({keepSections:!0}))}),s}function Rt(e,t,s,i=!0){const f=Ee(r),S=ie(),d=s??"group",c=ut(e.map(a=>a.passBins)),m=oe(e.map(a=>({label:a.identity??a.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:a.dies,waferIndex:a.waferIndex,wafer:a.wafer,passBins:a.passBins,ringCount:Q()}))),o=_e(e).defs,u=t?W:void 0,p={testDefs:o,groupBy:u,curation:I.attributes},b=(a,y,v=!1)=>({id:"card-yield",title:t?`Yield by ${d} (pass: ${c})`:`Yield by wafer (pass: ${c})`,chart:"bar",fields:{x:v?[{slot:"groupBy"},{builtin:"wafer"}]:{slot:"groupBy"},y:{builtin:"yield"},color:t?{follow:"groupBy"}:{none:!0}},...v?{}:{valueLabels:!0},...a&&!v?{sort:"value"}:{},...y>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),P=t?t.length:e.length;let k=null,C=!1;i&&(k=ee({doc:r,editAsPlot:Z,items:m,ctx:p,spec:{choices:[{current:"natural",options:a=>[["value","Sort: yield"],["natural",t&&!a?`Sort: ${d}`:"Sort: wafer"],...t&&!a?[["nested",`${d}, then wafer`,`Each ${d} with its wafers inside it`]]:[]]}],build:([a])=>(C=a==="nested",b(a==="value",P,C))},drill:t&&u?a=>{if(C)return null;const y=Ye(m[a[0]?.item]?.metadata,u,I.attributes);if(y===void 0)return null;const v=t.find(D=>D.key===y)?.items.length??0;return D=>({...D,title:`Yield by wafer \u2014 ${d}: ${y} (pass: ${c})`,fields:{...D.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:u},values:[y]}]},axes:v>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:()=>C?void 0:"see its wafers",chart:{onSaveImage:R,onOpenWafer:se?a=>je(m[a].waferIndex??a,`Wafer ${m[a].label}`):void 0,onWaferMenu:ge(e)}}),k.card.style.minHeight="360px",f.appendChild(k.card));const F={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"]]},V={current:"share",options:[["count","Counts"],["share",`Share of ${d}`,`Each ${d}\u2019s dies in a bin as a share of all its dies, so ${d} values of different sizes compare`],["mix","Bin mix",`Each ${d} as one bar split into its bins, as shares of its own dies`]]},N=15,l=(a,y)=>t&&y==="mix"?{id:"card-bin-pareto",title:`${a==="sbin"?"Soft":"Hard"} bin mix by ${d}`,chart:"bar",stack:"percent",fields:{x:{slot:"groupBy"},color:{builtin:a==="sbin"?"sbin":"hbin"}}}:{id:"card-bin-pareto",title:`${a==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:a==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:a==="sbin"?"sbin":"hbin"}},...a==="sbin"?{top:N}:{},...t?y==="share"?{barNorm:"percent"}:{}:{cumulative:!0}},w=ee({doc:r,editAsPlot:Z,items:m,ctx:p,spec:t?{choices:[F,V],build:([a,y])=>l(a,y)}:{choices:[F],build:([a])=>l(a,void 0)},chart:{onSaveImage:R,binColors:S,onSelectPoints:(a,y,v,D)=>{const g=w.current().fields,E=g.x,O=g.color,j=$=>!!$&&!Array.isArray($)&&typeof $=="object"&&"builtin"in $&&$.builtin==="sbin",L=j(E)||j(O)?"sbin":"hbin",n=new Set(a.map($=>L==="hbin"?$.die?.hbin:$.die?.sbin));if(n.size!==1)return;const h=[...n][0];if(E&&!Array.isArray(E)&&"slot"in E){const $=new Set(a.map(T=>T.die).filter(T=>!!T)),K=new Set(a.map(T=>m[T.item]?.waferIndex));ce(y,v,e.filter(T=>K.has(T.waferIndex)),`in ${L==="hbin"?"hard":"soft"} bin ${h}`,T=>$.has(T));return}const x=t?D?.group:void 0,B=x!==void 0?t?.find($=>$.key===x)?.items??[]:e;ce(y,v,B,`in ${L==="hbin"?"hard":"soft"} bin ${h}${x!==void 0?` of ${x}`:""}`,$=>zn($)&&(L==="hbin"?$.hbin:$.sbin)===h)}}});return w.card.style.minHeight="360px",f.appendChild(w.card),{card:f,destroy:()=>{k?.destroy(),w.destroy()}}}function ze(){const e=r.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...En(),display:"flex",flexDirection:"column",gap:A.lg,minWidth:"0"}),e}function Nt(e){if(ue.innerHTML="",ue.style.marginBottom="0",!It)return;const t=Wn(e.map(s=>({metadata:s.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",ue.appendChild(t),ue.style.marginBottom=A.xs)}function Mt(e,t,s,i,f){if(!e.length)return{elements:[],destroy:()=>{}};const S=e.map(w=>w.wafer),d=e.map(w=>w.dies),c=Q(),m=[],o=[],u=i??[{key:"",items:e}],p=e.flatMap(w=>w.dies),b=["spec","testFlag","functional"].filter(w=>an(s,w,p));if(b.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"}},a=!!i,y=oe(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:c}))),v=25,D=n=>on(s,n).map(h=>h.testNumber),g=n=>lt(u.map(h=>({key:h.key,items:h.items.map(x=>({dies:x.dies}))})),s,n).rows.map(h=>h.testNumber),E=n=>n==="testFlag"?{judge:"flag"}:{},O=(n,h="bars",x="worst")=>a&&h==="grid"?{id:`card-pass-rate-${n}`,title:w[n].title,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},y:{tests:g(n).slice(0,v),passRate:!0,...E(n)}}}:{id:`card-pass-rate-${n}`,title:w[n].title,chart:"bar",orientation:"horizontal",sort:"ascending",...D(n).length>v&&x==="worst"?{top:v}:{},fields:{x:{builtin:"test"},y:{tests:D(n),passRate:!0,...E(n)},color:a?{follow:"groupBy"}:{none:!0}},...a?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}},j=n=>n.id.slice(15),L=ee({doc:r,editAsPlot:Z,items:y,ctx:{testDefs:s,groupBy:a?W:void 0,curation:I.attributes},spec:(()=>{const n=b.some(x=>D(x).length>v),h=[];return b.length>1&&h.push({current:b[0],options:b.map(x=>[x,w[x].label,w[x].hint])}),a&&h.push({current:"bars",options:[["bars","Bars"],["grid","Grid",`The worst ${v} tests as a grid of test by group`]]}),n&&h.push({current:"worst",options:[["worst",`Worst ${v}`],["all","All tests"]]}),h.length?{choices:h,build:x=>{let B=0;const $=b.length>1?x[B++]:b[0],K=a?x[B++]:"bars",T=n?x[B++]:"worst";return O($,K,T)}}:O(b[0])})(),notes:n=>{const h=j(n);if(h==="functional")return[];const x=lt(u.map(B=>({key:B.key,items:B.items.map($=>({dies:$.dies}))})),s,h).disagreementDies;return x?[`${x.toLocaleString("en-GB")} die${x===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:R,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(n,h,x,B)=>{const $=s.find(U=>U.testNumber===B?.test);if(!$)return;const K=j(L.current()),T=B?.group!==void 0?u.find(U=>U.key===B.group)?.items??e:e;ce(h,x,T,`failing ${ct($,$.testNumber)}${B?.group!==void 0?` in ${B.group}`:""}`,U=>rn(U,$,K)===!0,Be($)?$.testNumber:void 0)}}});L.card.style.minHeight="300px",m.push(L.card),o.push(L.destroy)}const P=w=>(a,y)=>{const v=new Set;for(const D of e)for(const g of Nn(D.dies,D.wafer,c,a.key,w))v.add(g);Lt(y,e,`in ${a.label}`,D=>v.has(D))},k=Xe(d,S,c,w=>e[w].passBins,Bt),C=k.length?Ue({title:"Ring yield",mode:"ring",rows:k,onSelectRegion:P(Bt),onSaveImage:R,ownerDocument:r}):void 0;C&&o.push(C.destroy);const F=(w,a,y,v)=>{const D=!!i,g=oe(e.map(O=>({label:O.identity??O.label,dies:O.dies,waferIndex:O.waferIndex,wafer:O.wafer,passBins:O.passBins,ringCount:c}))),E=ee({doc:r,editAsPlot:Z,items:g,ctx:{testDefs:s,groupBy:D?W:void 0,curation:I.attributes},spec:{id:w,title:`${y} yield by ${D?f??"group":"wafer"}`,chart:"heatmap",fields:{x:{slot:"groupBy"},rows:{builtin:a},y:{builtin:"yield"}}},chart:{onSaveImage:R,onSelectPoints:be(g,e,O=>`in ${O?.cell?.row??y}, ${O?.cell?.column??""}`)}});E.card.style.minHeight="300px",m.push(v?In([{label:"Heatmap",card:E.card},{label:"Diagram",card:v.card}],r):E.card),o.push(E.destroy)};k.length&&e.length>=2?F("card-ring-wafer","ring","Ring",C):C&&m.push(C.card);const V=Xe(d,S,c,w=>e[w].passBins,$t);if(V.length){const w=Ue({title:"Quadrant yield",mode:"quadrant",rows:V,onSelectRegion:P($t),onSaveImage:R,ownerDocument:r});o.push(w.destroy),e.length>=2?F("card-quadrant-wafer","quadrant","Quadrant",w):m.push(w.card)}const N=S.find(w=>w.reticle!==void 0)?.reticle;if(N){const w=(y,v)=>Rn(y,v.reticle),a=Xe(d,S,c,y=>e[y].passBins,w);if(a.length){const y=Ue({title:"Reticle cell yield",mode:"reticleCell",rows:a,grid:{width:Math.max(1,Math.floor(N.width)),height:Math.max(1,Math.floor(N.height))},onSelectRegion:P(w),onSaveImage:R,ownerDocument:r});m.push(y.card),o.push(y.destroy)}}const l=new Set;for(const w of e)for(const a of w.dies)a.siteNum!==void 0&&l.add(a.siteNum);if(l.size>=2){const w=oe(e.map(y=>({label:y.identity??y.label,dies:y.dies,waferIndex:y.waferIndex,wafer:y.wafer,passBins:y.passBins,ringCount:c}))),a=ee({doc:r,editAsPlot:Z,items:w,ctx:{testDefs:s,curation:I.attributes},spec:{id:"card-site",title:"Yield by site",chart:"bar",fields:{x:{builtin:"site"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...l.size>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}},chart:{onSaveImage:R,onSelectPoints:be(w,e,y=>`at site ${y?.category??""}`)}});m.push(a.card),o.push(a.destroy)}if(e.some(w=>w.dies.some(a=>a.retestCount!==void 0))){const w=oe(e.map(v=>({label:v.identity??v.label,dies:v.dies,waferIndex:v.waferIndex,wafer:v.wafer,passBins:v.passBins,ringCount:c}))),a=!!i,y=ee({doc:r,editAsPlot:Z,items:w,ctx:{testDefs:s,groupBy:a?W:void 0,curation:I.attributes},spec:{id:"card-reprobed",title:`Re-probed dies by ring and ${a?f??"group":"wafer"}`,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},rows:{builtin:"ring"},y:{builtin:"reprobed"}}},chart:{onSaveImage:R,onSelectPoints:be(w,e,v=>`re-probed dies in ${v?.cell?.row??"a ring"}, ${v?.cell?.column??""}`)}});y.card.style.minHeight="300px",m.push(y.card),o.push(y.destroy)}return{elements:m,destroy:()=>{for(const w of o)w()}}}function jt(e,t,s){if(!e.length)return{cards:[],destroy:()=>{}};const i=e.map(p=>p.dies),f=e.flatMap(p=>p.dies),S=e.map(p=>p.statsSummary),d=S.every(p=>p!==void 0)?S:void 0,c=[],m=[];let o=null;if(t.length){const p=ze();let b=null;const P=Dn(Pn(f,t,void 0,d,J,i.map(k=>({dies:k})),void 0,"full"),{onDone:k=>{b=k,p.removeAttribute("aria-busy"),k?p.replaceChildren(k):p.remove()}});if(P.done)b&&(o=p);else{const k=r.createElement("div");k.textContent="Computing test statistics\u2026",Object.assign(k.style,{color:M.label,fontSize:G.body}),p.setAttribute("aria-busy","true"),p.appendChild(k),o=p,c.push(()=>P.cancel())}}let u=null;if(s.length){const p=Ln(f,s,d,J);if(p){const b=ze();b.appendChild(p),u=b}}return o&&m.push(o),u&&m.push(u),{cards:m,destroy:()=>{for(const p of c)p()}}}function Ft(e){const t=ut(e.map(o=>o.passBins)),s=e.length===1,i=e[0],f=ze();Object.assign(f.style,{flexDirection:"row",flexWrap:"wrap",gap:A.md});const S=o=>{const u=o.lastElementChild;return u&&Object.assign(u.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),o};function d(o,u,p){const b=r.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:A.sm,paddingRight:A.xxl,marginRight:A.md,borderRight:`1px solid ${M.menuBorder}`});const P=r.createElement("div");P.textContent=o,Object.assign(P.style,{fontSize:G.heading,fontWeight:"700",color:M.value,lineHeight:Ge.tight});const k=r.createElement("div");if(k.textContent=u,Object.assign(k.style,{fontSize:G.body,color:M.label}),b.append(P,k),p){const C=r.createElement("div");C.textContent=p,Object.assign(C.style,{fontSize:G.meta,color:M.label,opacity:bn.muted}),b.appendChild(C)}return b}if(s){const o=Ct([{...i,key:i.waferIndex}])[0]?.percent;return o!==void 0&&f.appendChild(d(`${o.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),f.appendChild(d(String(i.dies.length),"Total dies")),S(f)}f.appendChild(d(String(e.length),"Wafers"));const c=Ct(e.map(o=>({...o,key:o.waferIndex}))).map(o=>o.percent).filter(o=>Number.isFinite(o));if(c.length){const o=c.reduce((b,P)=>b+P,0)/c.length,u=An([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,p=u!==void 0&&u.toFixed(1)!==o.toFixed(1);f.appendChild(d(`${o.toFixed(1)}%`,`${en} \xB7 pass: ${t}`,p?`${u.toFixed(1)}% by dies`:void 0))}const m=e.map(o=>o.statsSummary);if(m.every(o=>o!==void 0)){const o=m.reduce((p,b)=>p+b.stats.analyzedDies,0),u=m.reduce((p,b)=>p+b.stats.excludedDies,0);f.appendChild(d(o.toLocaleString(),"Dies analysed",u?`${u.toLocaleString()} excluded`:void 0))}else f.appendChild(d(e.reduce((o,u)=>o+u.dies.length,0).toLocaleString(),"Total dies"));return S(f)}function zt(e,t,s,i,f){const S=r.createElement("div");Object.assign(S.style,{display:"flex",flexDirection:"column",gap:A.lg});const d=e.length===1&&!i;e.length&&!i&&S.appendChild(Ft(e));const c=Rt(e,i,f,!d),m=Mt(e,t,s,i,f);for(const p of m.elements)c.card.appendChild(p);const o=Ht(e,s);if(o&&S.appendChild(o.el),e.length>=4&&We.length){const p=Cn({wafers:e,fields:We,curation:xe,groupedBy:W,onGroupBy:b=>{W=b,_=null,ne()},ownerDocument:r});S.appendChild(p.card)}S.appendChild(c.card);const u=Bn({items:e.map(p=>({...p,ringCount:Q()})),testDefs:s,ownerDocument:r,showMap:I.showPatMap});return u&&S.appendChild(u.card),S.appendChild(Yt()),{card:S,destroy:()=>{c.destroy(),m.destroy(),o?.destroy()}}}function Ht(e,t){const s=Qe?.()??(e.length===1?e[0].statsSummary:void 0);if(!s)return null;const i=r.createElement("section");i.dataset.wmapWorthALook="1",Object.assign(i.style,{display:"flex",flexDirection:"column",gap:A.md});const f=r.createElement("h3");f.textContent="Worth a look",Object.assign(f.style,{margin:"0",fontSize:G.heading,fontWeight:"600",color:M.value}),i.appendChild(f);const S=(u,p)=>{const b=r.createElement("p");b.textContent=u,p&&(b.dataset[p]="1"),Object.assign(b.style,{margin:"0",fontSize:G.body,color:M.label,lineHeight:Ge.base}),i.appendChild(b)};if(Le||_!==null)return S("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:i,destroy:()=>{}};const d=_n(s,{passBins:Kn(e.map(u=>u.passBins)),attributes:I.attributes});if(d.items.length===0)return S(d.nothing??"Nothing stands out.","wmapWorthNothing"),{el:i,destroy:()=>{}};const c=Ee(r);i.appendChild(c);const m=oe(e.map(u=>({label:u.identity??u.label,dies:u.dies,waferIndex:u.waferIndex,wafer:u.wafer,passBins:u.passBins,ringCount:Q()}))),o=[];if(d.items.forEach((u,p)=>{if(u.target.kind==="group"&&W!==void 0&&u.target.fields.includes(W))return;const b=r.createElement("div");b.dataset.wmapWorthWhy="1",b.textContent=`Shown because: ${u.reason}`,u.text!==u.reason&&ke(b,u.text),Object.assign(b.style,{flexBasis:"100%",fontSize:G.body,color:M.text,lineHeight:Ge.base});const P=[b];if(I.showOnMap&&u.target.kind!=="group"){const C=r.createElement("button");C.type="button",C.textContent="Show on map",C.dataset.wmapWorthShowOnMap="1",Object.assign(C.style,{...ft("outlined"),fontSize:G.body,padding:`0 ${A.md}`}),$e(C),ke(C,"Leave Insights and show this on the map, as its row in What stands out does"),C.addEventListener("click",()=>I.showOnMap(u.target)),P.push(C)}const k=ee({doc:r,items:m,ctx:{testDefs:t,curation:xe,groupBy:W},spec:{id:`worth-${p}`,...Vn(u.chart,!!W)},extras:P,editAsPlot:Z,chart:{onSaveImage:R,onSelectPoints:be(m,e,C=>C?.cell?`in ${C.cell.row}, ${C.cell.column}`:C?.category!==void 0?`in ${C.category}${C.group!==void 0?`, ${C.group}`:""}`:"in this part of the chart"),onWaferMenu:ge(e),onOpenWafer:se?C=>je(m[C].waferIndex??C,`Wafer ${m[C].label}`):void 0}});k.card.dataset.wmapWorthKey=Gn(u),c.appendChild(k.card),o.push(k.destroy)}),d.also){const u=d.also.items.map(p=>p.brief).join("; ");S(`Also: ${u}${d.also.more?`; and ${d.also.more} more`:""}. Their rows in What stands out show them on the map.`,"wmapWorthAlso")}return d.possible?.length&&S(`${qn}: ${d.possible.map(u=>u.reason).join("; ")}.`,"wmapWorthPossible"),{el:i,destroy:()=>o.forEach(u=>u())}}function Yt(){const e=r.createElement("div");Object.assign(e.style,{fontSize:G.body,color:M.label});const t=r.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"}),$e(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 _t(e,t,s,i){const f=r.createElement("div");f.style.width="100%";let S,d=!1;return import("./plotTab.js").then(({createPlotSection:c})=>{if(d)return;const m=c({doc:r,store:fe,items:e,testDefs:t,ringCount:Q(),attributes:I.attributes,groupBy:s,groupLabel:i,onSaveImage:R,onSaveText:J,getBinColors:ie,waferMenu:ge(e),openWafer:se?(o,u,p)=>se(o,u,p):void 0,focusTest:Te,locateDie:me,pickPlotsFile:I.onPickPlotsFile});f.appendChild(m.card),S=m}),{card:f,destroy:()=>{d=!0,S?.destroy()}}}function Vt(e,t,s,i,f){const S=Le?void 0:Qe?.(),d=()=>{pe.get("data")?.destroy(),pe.delete("data"),ne({keepSections:!0})};return Mn({doc:r,items:e,testDefs:t,allTestDefs:s,groups:i,groupLabelText:f,ringCount:Q(),attributes:I.attributes,yieldByWaferIndex:new Map(S?.lotYieldSeries.map(c=>[c.waferIndex,c.yieldPercent])),onSaveText:J,onLocateDie:me,onOpenWafer:se?(c,m)=>se(c,m):void 0,buildStatistics:c=>jt(c,t,s),view:st,onViewChange:c=>{st=c,d()},diesLayout:rt,onDiesLayoutChange:c=>{rt=c}})}function Ce(e,t){const s=r.createElement("h3");return s.textContent=e,s.dataset.wmapRowHeading=t,Object.assign(s.style,{gridColumn:"1 / -1",margin:`${A.md} 0 0`,color:M.value,fontSize:G.heading,fontWeight:"600"}),s}function Gt(e,t,s,i){const f=Ee(r),S=it(e),d=oe(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:Q()}))),c=t.filter(n=>n.testNumber!==void 0),m=!!s&&!!W,o=m&&_!==null,u={testDefs:t,groupBy:m?W:void 0,curation:I.attributes},p=c.length>1;let b;const P=[];function k(n){let h=De,x=!1,B;const $=ht(c,q??c[0]?.testNumber??null,H=>{B?.refresh(),v(H)},{ownerDocument:r}),K=r.createElement("span");Object.assign(K.style,{display:"inline-flex",flexWrap:"wrap",gap:A.sm,alignItems:"center"});const T={setAxisPrefs:H=>{U.set(H)&&(h=H,B?.refresh())}},U=bt(K,h,H=>{h=H,B?.refresh(),Ne(H,T)},r),ye=[$.el,K];n.logToggle&&ye.push(Ke("Log scale",x,H=>{x=H,B?.refresh()},r,"Draw the value axis on a logarithmic scale")),ye.push(...n.extras??[]),B=ee({doc:r,editAsPlot:Z,items:d,ctx:u,...n.card,spec:{choices:n.choices??[],build:H=>n.build(h,x,H)},slots:()=>({test:$.get()??void 0}),extras:ye,onResolved:H=>{const he=t.find(Zt=>Zt.testNumber===$.get()),we=Ie(he,h.limits),He=kt(H,n.valueRole),{lo:Ut,hi:Qt}=yt(we),Jt=He.length>0&&we.length>0&&wt(vt(He),St(He),Ut,Qt);U.sync(h.includeLimits??Jt,Ie(he).length>0,xt(he))},chart:n.chart});const z=B;if(p){const H=()=>{$.el.style.display=On(z.card)?"":"none"};H();const he=r.defaultView?.MutationObserver;if(he){const we=new he(H);we.observe(z.card,{attributes:!0,attributeFilter:["data-wmap-expanded"]}),P.push(we)}}return{card:z.card,setTest:H=>{$.set(H)&&z.refresh()},refresh:()=>z.refresh(),setAxisPrefs:T.setAxisPrefs,destroy:()=>z.destroy()}}const C=S?(n,h)=>S.open(d[n]?.waferIndex??n,h??q??c[0]?.testNumber??0):void 0;let F=!1,V=!1;const N=k({valueRole:"y",logToggle:!0,choices:[{current:m&&!o?"groups":"wafers",options:[...m&&!o?[["groups",`By ${i??"group"}`],["nested",`${i??"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,[x])=>(F=m&&!o&&x==="nested",V=x==="radius",{id:"card-box",title:V?"Test value by radius":"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:V?{builtin:"ring"}:F?[{slot:"groupBy"},{builtin:"wafer"}]:m&&!o?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:F?{follow:"groupBy"}:{none:!0}},...o?{where:{conditions:[{field:{meta:W},values:[_]}]}}:{},...ae("y",n,h)}),card:{...m&&!o?{drill:n=>{if(F||V)return null;const h=Ye(d[n[0]?.item]?.metadata,W,I.attributes);return h===void 0?null:x=>({...x,fields:{...x.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:W},values:[h]}]}})},drillLabel:()=>F||V?void 0:"see its wafers"}:{},..._!==null?{externalBack:{shown:()=>_!==null,onBack:()=>Me(null)}}:{}},chart:{onSaveImage:R,onOpenWafer:C,openActionLabel:S?.label,onWaferMenu:ge(e)}});let l=null;const w=m?[]:[mt(d.map(n=>({label:n.label})),null,n=>{l=n,a.refresh()},{ownerDocument:r})],a=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"]]},...m?[{current:"percent",options:[["percent",`Share of ${i??"group"}`,"Each group\u2019s bars as a share of its own dies, so groups of different sizes compare"],["count","Counts"]]}]:[]],card:_!==null?{externalBack:{shown:()=>_!==null,onBack:()=>Me(null)}}:{},build:(n,h,[x,B])=>({id:"card-histogram",title:x==="cumulative"?"Cumulative distribution":"Value histogram",chart:x==="cumulative"?"probability":"histogram",fields:{y:{slot:"test"},color:m?{follow:"groupBy"}:{none:!0}},...m&&B!=="count"&&x!=="cumulative"?{histNorm:"percent"}:{},...l!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[d[l].label]}]}}:{},...ae("x",n,h)}),chart:{onSaveImage:R,onSelectPoints:(n,h,x,B)=>{const $=t.find(z=>z.testNumber===(q??c[0]?.testNumber)),K=new Set(n.map(z=>z.die).filter(z=>!!z)),T=new Set(n.map(z=>d[z.item]?.waferIndex)),U=B?.range,ye=$&&U?`with ${ct($,$.testNumber)} from ${dt(U.lo,$.unit,"engineering")} to ${dt(U.hi,$.unit,"engineering")}${B?.group?` in ${B.group}`:""}`:"selected in the histogram";ce(h,x,e.filter(z=>T.has(z.waferIndex)),ye,z=>K.has(z),$?.testNumber)}}}),y=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,[x])=>x==="control"?{id:"card-trend",title:"Wafer-to-wafer control chart",chart:"control",aggregate:"mean",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:m?{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:gn(mn(e.map(B=>B.wafer.metadata)),"mean")}]}}},card:{ctx:u,...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:R,onWaferMenu:ge(e),selectActionLabel:C?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(n,h,x)=>{const B=new Set(n.map(T=>T.item));if(B.size===1&&C){C([...B][0]);return}const $=new Set(n.map(T=>T.die).filter(T=>!!T)),K=new Set(n.map(T=>d[T.item]?.waferIndex));ce(h,x,e.filter(T=>K.has(T.waferIndex)),"selected in the trend",T=>$.has(T),q??void 0)}}}),v=n=>{q=n,b?.set(n),N.setTest(n),a.setTest(n),y.setTest(n),O.setTest(n),g?.setTest(n),E?.setTest(n)},D=()=>vn({groups:s,testDefs:t,groupLabelText:i,control:at,onControlChange:n=>{at=n;const h=D();g.card.replaceWith(h.card),g=h},selectedTestNumber:q??void 0,onSelectTest:n=>v(n),onSaveText:J,ownerDocument:r});let g=s&&s.length>=2?D():void 0;const E=s&&s.length>=2?$n({groups:s,testDefs:t,groupLabelText:i,selectedTestNumber:q??void 0,onSaveImage:R,ownerDocument:r}):void 0;Re.set("distribution",[N,a,y]);const O=Sn({title:"Process capability",items:e,testDefs:t,onSaveImage:R,selectedTestNumber:q??void 0,onSelectTest:n=>v(n),ownerDocument:r}),j=e.length>=2?Fn(e.map(n=>({dies:n.dies})),t.filter(n=>n.testNumber!==void 0&&Be(n)).map(n=>n.testNumber),Xn):[],L=j.length>=2?ee({doc:r,editAsPlot:Z,items:d,ctx:u,spec:{id:"card-tests-wafer",title:`Tests by ${s?i??"group":"wafer"} (z-scores)`,chart:"heatmap",level:"wafer",aggregate:"mean",normalize:"zscore",fields:{x:{slot:"groupBy"},y:{tests:j}}},chart:{onSaveImage:R,onSelectPoints:be(d,e,n=>`on ${n?.cell?.column??"the wafer"}, for ${n?.cell?.row??"a test"}`)}}):void 0;if(L&&(L.card.style.minHeight="300px"),L&&(f.append(Ce(`Tests across ${s?i??"groups":"wafers"}`,"tests-grid")),f.append(L.card)),(g||E)&&(f.append(Ce(`Comparing ${i??"groups"}`,"comparing")),g&&f.append(g.card),E&&f.append(E.card)),p){b=ht(c,q??c[0]?.testNumber??null,$=>v($),{ownerDocument:r});const n=r.createElement("div");n.dataset.wmapSectionTest="1",Object.assign(n.style,{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:A.lg,flexWrap:"wrap",marginTop:A.md});const h=Ce("Test by test","tests");h.style.margin="0";const x=r.createElement("label");Object.assign(x.style,{display:"inline-flex",alignItems:"center",gap:A.xs,fontSize:G.body,color:M.label});const B=r.createElement("span");B.textContent="Test",x.append(B,b.el),n.append(h,x),f.append(n)}else(g||E)&&f.append(Ce("Test by test","tests"));return f.append(O.card,N.card,a.card,y.card),{card:f,destroy:()=>{for(const n of P)n.disconnect();O.destroy(),N.destroy(),a.destroy(),y.destroy(),g?.destroy(),E?.destroy(),L?.destroy()}}}function qt(e,t,s,i){const f=Ee(r),S=it(e),d=oe(e.map(g=>({label:g.identity??g.label,dies:g.dies,waferIndex:g.waferIndex,wafer:g.wafer,passBins:g.passBins,ringCount:Q()}))),c=t.filter(g=>g.testNumber!==void 0&&Be(g));let m=c[0]?.testNumber,o=c[1]?.testNumber??m,u=null,p=De;const b=!!s&&!!W,P=(g,E)=>{const O=r.createElement("label");Object.assign(O.style,{display:"inline-flex",alignItems:"center",gap:A.xs,fontSize:G.body,color:M.label});const j=r.createElement("span");return j.textContent=g,O.append(j,E),O},k=gt(c,m??null,g=>{m=g,v.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:r}),C=gt(c,o??null,g=>{o=g,v.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:r}),F=r.createElement("span");Object.assign(F.style,{display:"inline-flex",flexWrap:"wrap",gap:A.sm,alignItems:"center"});let V=!1,N=!1;const l={setXY:(g,E)=>{m=g,o=E,k.value=String(g),C.value=String(E),v.refresh()},setAxisPrefs:g=>{w.set(g)&&(p=g,v.refresh())},destroy:()=>v.destroy()},w=bt(F,p,g=>{p=g,v.refresh(),Ne(g,l)},r),a=g=>{const E=t.find(O=>O.testNumber===g);return E?.name?{test:g??0,name:E.name}:{test:g??0}},y=[P("X:",k),P("Y:",C),F,Ke("Log X",V,g=>{V=g,v.refresh()},r,"Draw the X axis on a logarithmic scale"),Ke("Log Y",N,g=>{N=g,v.refresh()},r,"Draw the Y axis on a logarithmic scale")];!b&&e.length>1&&y.push(mt(d.map(g=>({label:g.label})),null,g=>{u=g,v.refresh()},{ownerDocument:r}));const v=ee({doc:r,editAsPlot:Z,items:d,ctx:{testDefs:t,groupBy:b?W:void 0,curation:I.attributes},extras:y,onResolved:g=>{const E=[m,o].map(j=>t.find(L=>L.testNumber===j)),O=["x","y"].some((j,L)=>{const n=Ie(E[L],p.limits),h=kt(g,j),{lo:x,hi:B}=yt(n);return h.length>0&&n.length>0&&wt(vt(h),St(h),x,B)});w.sync(p.includeLimits??O,E.some(j=>Ie(j).length>0),E.some(xt))},spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:p.limits??"both",axes:{...ae("x",p,V).axes,...ae("y",p,N).axes},fields:{x:a(m),y:a(o),color:b?{follow:"groupBy"}:{builtin:"hbin"}},...b?{fit:"linear"}:{},...u!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[d[u].label]}]}}:{}})},...m===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:R,binColors:ie(),onOpenWafer:S?(g,E)=>S.open(d[g]?.waferIndex??g,E??m??0):void 0,openActionLabel:S?.label,onSelectPoints:(g,E,O)=>{const j=new Map;for(const h of g){const x=d[h.item]?.waferIndex;if(x===void 0||!h.die)continue;const B=j.get(x);B?B.push(h.die):j.set(x,[h.die])}const L=[...j].flatMap(([h,x])=>{const B=e.find($=>$.waferIndex===h);return B?[{label:B.identity??B.label,dies:x,waferIndex:h,wafer:B.wafer,passBins:B.passBins,ringCount:Q()}]:[]});if(L.length===0)return;const n=L.length===1?`selected on ${L[0].label} in the scatter`:`selected in the scatter, across ${L.length} wafers`;Ve(E,O,{items:L,population:n,testDefs:t,activeTest:m},{plots:fe,getBinColors:ie,onSaveImage:R,onSaveText:J,onLocateDie:me})}}});Re.set("correlation",[l]);const D=kn({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:R,onSaveText:J,...b&&s&&s.length>=2?{groups:s,groupLabelText:i}:{},onSelectPair:(g,E)=>l.setXY(g,E),ownerDocument:r});return f.append(D.card,v.card),{card:f,destroy:()=>{D.destroy(),l.destroy()}}}const Kt=(e,t,s,i)=>pn(r,e,t,s,i),Xt=()=>Se.openEditor(Y,Fe());function ne(e){e?.keepSections||ot(),re.innerHTML="",te.innerHTML="";for(const l of Pt)te.appendChild(Dt(l.key,l.label));const t=Fe(),s=Se.keep(t),i=s.items;Le=s.narrowing,Je.refresh(s.result,t),Nt(i);const f=tn(i,{facetableOnly:!0,curation:xe}).filter(l=>l.splittable);We=f.map(l=>({key:l.key,label:l.label}));const S=r.createElement("div");Object.assign(S.style,{display:"flex",gap:A.md,alignItems:"center",marginLeft:A.xxl,paddingBottom:A.xs}),I.showFilterButton!==!1&&S.appendChild(Kt("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>Xt()));let d;f.length>0?(S.appendChild(pt("Group by:",[{value:"",label:"None"},...f.map(l=>({value:l.key,label:`${l.label} (${l.values.length})`}))],W??"",l=>{W=l||void 0,_=null,ne()},{hook:"group-by",ownerDocument:r,hint:"Split every chart by a wafer attribute, such as lot or tester"})),d=f.find(l=>l.key===W)?.label):W=void 0;let c;if(W){const l=new Map,w=[];for(const a of i){const y=Ye(a.metadata,W,xe)??nn;l.has(y)||(l.set(y,[]),w.push(y)),l.get(y).push(a)}c=Yn(w).map(a=>({key:a,items:l.get(a)}))}_!==null&&!c?.some(l=>l.key===_)&&(_=null),c&&c.length>0&&S.appendChild(Tn(c.map(l=>l.key),"Show:",_,l=>Me(l),{ownerDocument:r,hint:"Show every group, or analyse just one"}).el);const m=pt("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(l=>({value:String(l),label:`${l} (${l})`}))],de===void 0?"auto":String(de),l=>Ze(l==="auto"?void 0:Number(l)),{hook:"insights-columns",maxWidth:"90px",ownerDocument:r,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"});Ae=m.querySelector("button"),S.appendChild(m);let o=null;if(I.onOpenGuide){const l=r.createElement("button");l.type="button",l.innerHTML=xn.help,l.setAttribute("aria-label","User guide"),Object.assign(l.style,{...ft("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),$e(l,"bare"),ke(l,"User guide"),l.addEventListener("click",()=>I.onOpenGuide()),Object.assign(l.style,{marginLeft:"auto"}),o=l}te.appendChild(S),o&&te.appendChild(o);const u=_!==null?c?.find(l=>l.key===_):void 0,p=u?.items??i,b=u?void 0:c,P=_e(p),k=P.defs,C=k.filter(Be);if(q!==null&&!C.some(l=>l.testNumber===q)&&(q=null),i.length===0){const l=r.createElement("div");l.dataset.wmapInsightsFilterEmpty="1",l.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(l.style,{color:M.label,fontSize:G.body,padding:A.xl}),re.appendChild(l);return}const F=e?.keepSections?pe.get(X):void 0,V=F??(X==="overview"?zt(p,C,k,b,d):X==="distributions"?Gt(p,C,b,d):X==="data"?Vt(p,C,k,b,d):X==="plot"?_t(p,k,u?void 0:W,u?void 0:d):qt(p,C,b,d));F||pe.set(X,V);const N=P.conflicts.filter(l=>l.excluded);if(N.length>0){const l=r.createElement("div");Object.assign(l.style,{color:M.label,fontSize:G.body,padding:`0 ${le} ${A.sm}`});const w=N.slice(0,6).map(v=>v.testNumber).join(", "),a=N.length>6?`, and ${N.length-6} more`:"",y=N.length===1?"it":"them";l.textContent=`${N.length} test ${N.length===1?"number is":"numbers are"} hidden (${w}${a}) \u2014 the wafers in view describe ${y} differently, so their values cannot be pooled. `+(c&&c.length>0?`Pick one ${d??"group"} under "Show:" to analyse ${y}.`:"Load one test program at a time to analyse them."),l.dataset.wmapWithheldTests=String(N.length),re.appendChild(l)}re.appendChild(V.card),ve()}return{el:Y,render:ne,destroy:()=>{r.removeEventListener("keydown",nt),tt?.disconnect(),ot(),fe.flush(),Y.remove()},setAxisPrefs:e=>Ne(e,null,!0),showWorthCard:e=>{X!=="overview"&&(X="overview",ne({keepSections:!0}));const t=[...re.querySelectorAll("[data-wmap-worth-key]")].find(f=>f.dataset.wmapWorthKey===e);if(!t)return!1;const s=r.defaultView,i=()=>t.scrollIntoView({block:"center"});return s?.requestAnimationFrame?s.requestAnimationFrame(()=>s.requestAnimationFrame(i)):i(),t.style.outline=`2px solid ${M.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as on}from"../stats/presentation.js";import{buildFacetTable as ln,facetValueOf as Ke,FACET_NONE_VALUE as dn,DEFAULT_FACET_CURATION as cn}from"../stats/facets.js";import{mergeTestDefs as Xe}from"../stats/mergeTestDefs.js";import{isParametricTest as Ie}from"../renderer/buildWaferMap.js";import{dieFailsTest as un,hasJudgeableTests as fn,testsForPassKind as pn,buildTestPassRateData as pt}from"../stats/testPassRate.js";import{fmt as Ee}from"../renderer/fmt.js";import{testLabel as ge}from"../renderer/testLabel.js";import{waferDisplayLabel as hn,waferIdentityLabel as mn}from"../core/waferLabel.js";import{waferPopulation as gn}from"./chartPopulation.js";import{openDrilldownMenu as Ue}from"./drilldown.js";import{plotStoreFor as bn}from"./plotStore.js";import{createPageFilter as yn}from"./pageFilter.js";import{bandButton as wn,filterKeepsNothing as xn}from"./filterButton.js";import{itemPassBins as Sn,passBinsLabel as ht}from"../core/passBins.js";import{describeWaferPopulation as vn,populationStat as Cn}from"../stats/population.js";import{LEADING as Qe,ALPHA as Bn,SPACE as W,EDGE_GUTTER as Je,FONT as V,CLR as z,RADIUS as $n,SHADOW as kn,controlStyle as mt,wireControlHover as Te,wireTooltip as Oe}from"./toolbar.js";import{ICONS as In}from"./icons.js";import{renderCapabilityPanel as En}from"./charts/capability.js";import{renderGroupComparisonPanel as Tn}from"./charts/groupComparison.js";import{renderCommonalityPanel as On}from"./charts/commonality.js";import{renderPatCard as Ln}from"./charts/patCard.js";import{renderDifferenceMapPanel as An}from"./differenceMapPanel.js";import{renderCorrelationPanel as Pn}from"./charts/correlation.js";import{cardFrameStyle as Wn,pairCards as Dn,makeChartGridWrap as Le,makeLabeledSelect as gt,makeLinkedGroupSelect as Nn,makeLinkedTestSelect as bt,makeWaferSelect as yt,makeTestSelect as wt,isExpandedCard as Rn,makeLinkedAxisPrefs as xt,makeToggle as Ze,limitLines as Ae,limitExtent as St,shouldIncludeLimitsByDefault as vt,hasBothLimitKinds as Ct}from"./charts/chartShell.js";import{maxOf as Bt,minOf as $t}from"../core/utils.js";import{buildYieldData as kt,buildYieldDataCombined as Mn}from"../stats/yield.js";import{buildLotTestSectionSteps as Fn,buildLotFunctionalSection as jn,buildMetadataStripBox as zn}from"./summaryPanel.js";import{runChunked as Hn}from"./chunked.js";import{buildRegionYieldData as et,buildRingRegions as It,buildQuadrantRegions as Et,buildReticlePositionRegions as Yn,diesInRegion as Gn}from"../stats/regions.js";import{renderDataSection as _n}from"./dataTab.js";import{sourceFromDies as Vn,toPlotItems as ie}from"./plotItems.js";import{rankTestsByWaferSpread as qn}from"../stats/testsByWafer.js";import{isYieldEligibleDie as Kn}from"../core/dies.js";import{renderPlotCard as Xn}from"./plotCard.js";import{plotTestNumber as Tt,orderFieldValues as Un,axisValues as Ot}from"../stats/plotData.js";import{buildSynthesis as Qn,groupColouredChart as Jn,synthesisKey as Lt,SYNTHESIS_POSSIBLE_HEADING as Zn,groupedByField as er,isGroupYieldItem as At}from"../stats/synthesis.js";import{commonPassBins as tr}from"../core/passBins.js";import{renderRegionYieldDiagram as tt}from"./charts/regionYieldDiagram.js";const nr=12,rr=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],sr={key:"data",label:"Data"},ar={key:"plot",label:"My plots"},ir={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"};function Pt(k,be){if(be!==void 0)return k.find(oe=>oe.testNumber!==void 0&&(oe.name===be||ge(oe,oe.testNumber)===be))?.testNumber}export function createInsightsTab(k){const{getItems:be,getLotStats:oe,getBinColors:le,getRingCount:Q,onSaveImage:M,onSaveText:J,openWafer:se,focusTest:Pe,locateDie:ye}=k,Ce={...cn,...k.attributes},Wt=k.showMetadataStrip??!0,de=k.contentInset??Je,a=k.ownerDocument??document,G=a.createElement("div");Object.assign(G.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Dt=Je,fe=a.createElement("div");Object.assign(fe.style,{paddingLeft:Dt});const te=a.createElement("div");Object.assign(te.style,{display:"flex",gap:W.xs,alignItems:"center",background:z.menuBg,border:`1px solid ${z.menuBorder}`,borderRadius:$n.container,boxShadow:kn.panel,padding:`0 ${W.lg}`,margin:"0"}),te.setAttribute("role","tablist");const We=a.createElement("div");Object.assign(We.style,{position:"sticky",top:"var(--wmap-sticky-top, 0px)",zIndex:"1",background:z.menuBg,paddingLeft:de,paddingRight:de,paddingBottom:W.lg}),We.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 ne=a.createElement("div");Object.assign(ne.style,{display:"flex",flexDirection:"column",gap:W.lg,marginTop:"0",isolation:"isolate",paddingLeft:de,paddingRight:de});const Be=k.pageFilter??yn({doc:a,initial:k.filter,onChange:k.onFilterChange,attributes:k.attributes,getRingCount:k.getRingCount}),nt=Be.createBand(()=>_e(),{marginLeft:de,marginRight:de,marginBottom:W.lg}),Nt=nt.el;let ce,De=null;const Rt=()=>{let e=0;for(const t of Array.from(G.querySelectorAll("[data-wmap-chart-grid]")))t.offsetParent!==null&&(e=Math.max(e,Array.from(t.children).filter(s=>s.offsetParent!==null).length));return e},$e=()=>{if(ce===void 0){G.style.removeProperty("--wmap-insights-cols"),G.style.removeProperty("--wmap-insights-min");return}const e=Rt(),t=e>0?Math.min(ce,e):ce;G.style.getPropertyValue("--wmap-insights-cols")!==String(t)&&G.style.setProperty("--wmap-insights-cols",String(t)),G.style.setProperty("--wmap-insights-min","0px")},rt=e=>{ce=e,$e(),De&&(De.value=e===void 0?"auto":String(e))},st=a.defaultView?.MutationObserver;let Ne=0;const at=st?new st(()=>{if(Ne||ce===void 0)return;const e=a.defaultView;if(!e){$e();return}Ne=e.requestAnimationFrame(()=>{Ne=0,$e()})}):void 0;at?.observe(ne,{childList:!0,subtree:!0});const it=e=>{if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.defaultPrevented||!/^[0-5]$/.test(e.key)||!G.isConnected||G.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(),rt(e.key==="0"?void 0:Number(e.key)))};a.addEventListener("keydown",it),G.appendChild(fe),G.appendChild(We),G.appendChild(Nt),G.appendChild(ne);const Mt=[...rr,sr,ar],pe=k.plotStore??bn(k),Z=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:s})=>s({doc:a,anchor:G,store:pe,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:M,binColors:le()}}))};let X=k.defaultView==="sweeps"?"plot":k.defaultView??"overview",R,Re=!1;Be.subscribe(()=>re());let ot="statistics",lt="wide",q=null,dt=null,Me=[],ct=new Set,_=null,Fe=k.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=e=>Xn({...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"}:{}}}}),je=new Map,ze=(e,t,s=!1)=>{Fe=e;for(const o of je.values())for(const c of o)c!==t&&c.setAxisPrefs(e);s||k.onAxisPrefsChange?.(e)},He=e=>{_!==e&&(_=e,re())};let he=new Map;function ut(){for(const e of he.values())e.destroy();he=new Map}function Ye(e,t,s,o){se?.(e,t,s,o)}function we(e){return(t,s,o)=>{const c=e.find(f=>f.waferIndex===t);if(!c)return;o.preventDefault();const x=gn(c.dies,{waferLabel:c.identity,testDefs:c.testDefs,activeTest:s??q??void 0,waferIndex:t,wafer:c.wafer,passBins:c.passBins,ringCount:Q()});Ue({x:o.clientX,y:o.clientY},o.target,x,{plots:pe,getBinColors:le,onSaveImage:M,onSaveText:J,onLocateDie:ye})}}function Ft(e,t,s,o,c){ue({x:e.clientX,y:e.clientY},e.target,t,s,o,c)}function xe(e,t,s,o){return(c,x,f,u)=>{const h=new Set(c.map(r=>r.die).filter(r=>!!r)),d=new Set(c.map(r=>e[r.item]?.waferIndex)),S=t.filter(r=>d.has(r.waferIndex));ue(x,f,S,s(u,S.length===1),h.size?r=>h.has(r):()=>!0,o?.(u))}}function Ge(e,t,s){return e?.cell?`in ${e.cell.row}${t?"":`, ${e.cell.column}`}`:e?.category!==void 0?`in ${e.category}${e.group!==void 0&&e.group!==e.category?`, ${e.group}`:""}`:s}function ue(e,t,s,o,c,x){const f=Vn(s.map(u=>({label:u.identity??u.label,dies:u.dies,waferIndex:u.waferIndex,wafer:u.wafer,passBins:u.passBins,ringCount:Q()})),o,c,Xe(s).defs,x);f&&Ue(e,t,f,{plots:pe,getBinColors:le,onSaveImage:M,onSaveText:J,onLocateDie:ye})}function ft(e){return se?{open:(t,s)=>Ye(t,`Wafer ${e.find(o=>o.waferIndex===t)?.label??t}`,s)}:Pe&&e.length===1?{open:(t,s)=>Pe(s),label:"show this test on the map"}:null}function _e(){return be().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:hn(e,t),identity:mn(e),waferIndex:t,passBins:Sn(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function jt(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${z.iconActive}`:"2px solid transparent",color:t?z.iconActive:z.label,fontWeight:t?"700":"500",fontSize:V.body,padding:`${W.sm} ${Je} ${W.md}`,cursor:"pointer"})}function zt(e,t){const s=a.createElement("button");s.type="button",s.textContent=t;const o=e===X;jt(s,o),s.dataset.on=o?"true":"false",Te(s,"bare"),s.dataset.wmapInsightsTab=e;const c=ir[e];return c&&Oe(s,c),s.setAttribute("role","tab"),s.setAttribute("aria-selected",o?"true":"false"),s.tabIndex=o?0:-1,s.addEventListener("click",()=>{X!==e&&(X=e,re({keepSections:!0}))}),s}function Ht(e,t,s,o=!0){const c=Le(a),x=le(),f=s??"group",u=ht(e.map(i=>i.passBins)),h=ie(e.map(i=>({label:i.identity??i.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:Q()}))),d=Xe(e).defs,S=t?R:void 0,r={testDefs:d,groupBy:S,curation:k.attributes},w=(i,g,v=!1)=>({id:"card-yield",title:t?`Yield by ${f} (pass: ${u})`:`Yield by wafer (pass: ${u})`,chart:"bar",fields:{x:v?[{slot:"groupBy"},{builtin:"wafer"}]:{slot:"groupBy"},y:{builtin:"yield"},color:t?{follow:"groupBy"}:{none:!0}},...v?{}:{valueLabels:!0},...i&&!v?{sort:"value"}:{},...g>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),O=t?t.length:e.length;let E=null,L=!1;o&&(E=ee({doc:a,editAsPlot:Z,items:h,ctx:r,spec:{choices:[{current:"natural",options:i=>[["value","Sort: yield"],["natural",t&&!i?`Sort: ${f}`:"Sort: wafer"],...t&&!i?[["nested",`${f}, then wafer`,`Each ${f} with its wafers inside it`]]:[]]}],build:([i])=>(L=i==="nested",w(i==="value",O,L))},drill:t&&S?i=>{if(L)return null;const g=Ke(h[i[0]?.item]?.metadata,S,k.attributes);if(g===void 0)return null;const v=t.find(D=>D.key===g)?.items.length??0;return D=>({...D,title:`Yield by wafer \u2014 ${f}: ${g} (pass: ${u})`,fields:{...D.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:S},values:[g]}]},axes:v>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:()=>L?void 0:"see its wafers",chart:{onSaveImage:M,onOpenWafer:se?(i,g,v)=>Ye(h[i].waferIndex??i,`Wafer ${h[i].label}`,g,v):void 0,onWaferMenu:we(e)}}),E.card.style.minHeight="360px",c.appendChild(E.card));const $={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"]]},j={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`]]},I=15,l=(i,g)=>t&&g==="mix"?{id:"card-bin-pareto",title:`${i==="sbin"?"Soft":"Hard"} bin mix by ${f}`,chart:"bar",stack:"percent",fields:{x:{slot:"groupBy"},color:{builtin:i==="sbin"?"sbin":"hbin"}}}:{id:"card-bin-pareto",title:`${i==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:i==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:i==="sbin"?"sbin":"hbin"}},...i==="sbin"?{top:I}:{},...t?g==="share"?{barNorm:"percent"}:{}:{cumulative:!0}},b=ee({doc:a,editAsPlot:Z,items:h,ctx:r,spec:t?{choices:[$,j],build:([i,g])=>l(i,g)}:{choices:[$],build:([i])=>l(i,void 0)},chart:{onSaveImage:M,binColors:x,onSelectPoints:(i,g,v,D)=>{const m=b.current().fields,T=m.x,P=m.color,F=B=>!!B&&!Array.isArray(B)&&typeof B=="object"&&"builtin"in B&&B.builtin==="sbin",N=F(T)||F(P)?"sbin":"hbin",n=new Set(i.map(B=>N==="hbin"?B.die?.hbin:B.die?.sbin));if(n.size!==1)return;const p=[...n][0];if(T&&!Array.isArray(T)&&"slot"in T){const B=new Set(i.map(A=>A.die).filter(A=>!!A)),K=new Set(i.map(A=>h[A.item]?.waferIndex));ue(g,v,e.filter(A=>K.has(A.waferIndex)),`in ${N==="hbin"?"hard":"soft"} bin ${p}`,A=>B.has(A));return}const y=t?D?.group:void 0,C=y!==void 0?t?.find(B=>B.key===y)?.items??[]:e;ue(g,v,C,`in ${N==="hbin"?"hard":"soft"} bin ${p}${y!==void 0?` of ${y}`:""}`,B=>Kn(B)&&(N==="hbin"?B.hbin:B.sbin)===p)}}});return b.card.style.minHeight="360px",c.appendChild(b.card),{card:c,destroy:()=>{E?.destroy(),b.destroy()}}}function Ve(){const e=a.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Wn(),display:"flex",flexDirection:"column",gap:W.lg,minWidth:"0"}),e}function Yt(e){if(fe.innerHTML="",fe.style.marginBottom="0",!Wt)return;const t=zn(e.map(s=>({metadata:s.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",fe.appendChild(t),fe.style.marginBottom=W.xs)}function Gt(e,t,s,o,c){if(!e.length)return{elements:[],destroy:()=>{}};const x=e.map(b=>b.wafer),f=e.map(b=>b.dies),u=Q(),h=[],d=[],S=o??[{key:"",items:e}],r=e.flatMap(b=>b.dies),w=["spec","testFlag","functional"].filter(b=>fn(s,b,r));if(w.length){const b={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"}},i=!!o,g=ie(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:u}))),v=25,D=n=>pn(s,n).map(p=>p.testNumber),m=n=>pt(S.map(p=>({key:p.key,items:p.items.map(y=>({dies:y.dies}))})),s,n).rows.map(p=>p.testNumber),T=n=>n==="testFlag"?{judge:"flag"}:{},P=(n,p="bars",y="worst")=>i&&p==="grid"?{id:`card-pass-rate-${n}`,title:b[n].title,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},y:{tests:m(n).slice(0,v),passRate:!0,...T(n)}}}:{id:`card-pass-rate-${n}`,title:b[n].title,chart:"bar",orientation:"horizontal",sort:"ascending",...D(n).length>v&&y==="worst"?{top:v}:{},fields:{x:{builtin:"test"},y:{tests:D(n),passRate:!0,...T(n)},color:i?{follow:"groupBy"}:{none:!0}},...i?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}},F=n=>n.id.slice(15),N=ee({doc:a,editAsPlot:Z,items:g,ctx:{testDefs:s,groupBy:i?R:void 0,curation:k.attributes},spec:(()=>{const n=w.some(y=>D(y).length>v),p=[];return w.length>1&&p.push({current:w[0],options:w.map(y=>[y,b[y].label,b[y].hint])}),i&&p.push({current:"bars",options:[["bars","Bars"],["grid","Grid",`The worst ${v} tests as a grid of test by group`]]}),n&&p.push({current:"worst",options:[["worst",`Worst ${v}`],["all","All tests"]]}),p.length?{choices:p,build:y=>{let C=0;const B=w.length>1?y[C++]:w[0],K=i?y[C++]:"bars",A=n?y[C++]:"worst";return P(B,K,A)}}:P(w[0])})(),notes:n=>{const p=F(n);if(p==="functional")return[];const y=pt(S.map(C=>({key:C.key,items:C.items.map(B=>({dies:B.dies}))})),s,p).disagreementDies;return y?[`${y.toLocaleString("en-GB")} die${y===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:M,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(n,p,y,C)=>{const B=s.find(U=>U.testNumber===C?.test);if(!B)return;const K=F(N.current()),A=C?.group!==void 0?S.find(U=>U.key===C.group)?.items??e:e;ue(p,y,A,`failing ${ge(B,B.testNumber)}${C?.group!==void 0?` in ${C.group}`:""}`,U=>un(U,B,K)===!0,Ie(B)?B.testNumber:void 0)}}});N.card.style.minHeight="300px",h.push(N.card),d.push(N.destroy)}const O=b=>(i,g)=>{const v=new Set;for(const D of e)for(const m of Gn(D.dies,D.wafer,u,i.key,b))v.add(m);Ft(g,e,`in ${i.label}`,D=>v.has(D))},E=et(f,x,u,b=>e[b].passBins,It),L=E.length?tt({title:"Ring yield",mode:"ring",rows:E,onSelectRegion:O(It),onSaveImage:M,ownerDocument:a}):void 0;L&&d.push(L.destroy);const $=(b,i,g,v)=>{const D=!!o,m=ie(e.map(P=>({label:P.identity??P.label,dies:P.dies,waferIndex:P.waferIndex,wafer:P.wafer,passBins:P.passBins,ringCount:u}))),T=ee({doc:a,editAsPlot:Z,items:m,ctx:{testDefs:s,groupBy:D?R:void 0,curation:k.attributes},spec:{id:b,title:`${g} yield by ${D?c??"group":"wafer"}`,chart:"heatmap",fields:{x:{slot:"groupBy"},rows:{builtin:i},y:{builtin:"yield"}}},chart:{onSaveImage:M,onSelectPoints:xe(m,e,(P,F)=>Ge(P,F,`in a ${g.toLowerCase()}`))}});T.card.style.minHeight="300px",h.push(v?Dn([{label:"Heatmap",card:T.card},{label:"Diagram",card:v.card}],a):T.card),d.push(T.destroy)};E.length&&e.length>=2?$("card-ring-wafer","ring","Ring",L):L&&h.push(L.card);const j=et(f,x,u,b=>e[b].passBins,Et);if(j.length){const b=tt({title:"Quadrant yield",mode:"quadrant",rows:j,onSelectRegion:O(Et),onSaveImage:M,ownerDocument:a});d.push(b.destroy),e.length>=2?$("card-quadrant-wafer","quadrant","Quadrant",b):h.push(b.card)}const I=x.find(b=>b.reticle!==void 0)?.reticle;if(I){const b=(g,v)=>Yn(g,v.reticle),i=et(f,x,u,g=>e[g].passBins,b);if(i.length){const g=tt({title:"Reticle cell yield",mode:"reticleCell",rows:i,grid:{width:Math.max(1,Math.floor(I.width)),height:Math.max(1,Math.floor(I.height))},onSelectRegion:O(b),onSaveImage:M,ownerDocument:a});h.push(g.card),d.push(g.destroy)}}const l=new Set;for(const b of e)for(const i of b.dies)i.siteNum!==void 0&&l.add(i.siteNum);if(l.size>=2){const b=ie(e.map(g=>({label:g.identity??g.label,dies:g.dies,waferIndex:g.waferIndex,wafer:g.wafer,passBins:g.passBins,ringCount:u}))),i=ee({doc:a,editAsPlot:Z,items:b,ctx:{testDefs:s,curation:k.attributes},spec:{id:"card-site",title:"Yield by site",chart:"bar",fields:{x:{builtin:"site"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...l.size>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}},chart:{onSaveImage:M,onSelectPoints:xe(b,e,g=>`at site ${g?.category??""}`)}});h.push(i.card),d.push(i.destroy)}if(e.some(b=>b.dies.some(i=>i.retestCount!==void 0))){const b=ie(e.map(v=>({label:v.identity??v.label,dies:v.dies,waferIndex:v.waferIndex,wafer:v.wafer,passBins:v.passBins,ringCount:u}))),i=!!o,g=ee({doc:a,editAsPlot:Z,items:b,ctx:{testDefs:s,groupBy:i?R:void 0,curation:k.attributes},spec:{id:"card-reprobed",title:`Re-probed dies by ring and ${i?c??"group":"wafer"}`,chart:"heatmap",aggregate:"mean",fields:{x:{slot:"groupBy"},rows:{builtin:"ring"},y:{builtin:"reprobed"}}},chart:{onSaveImage:M,onSelectPoints:xe(b,e,(v,D)=>`re-probed ${Ge(v,D,"in a ring")}`)}});g.card.style.minHeight="300px",h.push(g.card),d.push(g.destroy)}return{elements:h,destroy:()=>{for(const b of d)b()}}}function _t(e,t,s){if(!e.length)return{cards:[],destroy:()=>{}};const o=e.map(r=>r.dies),c=e.flatMap(r=>r.dies),x=e.map(r=>r.statsSummary),f=x.every(r=>r!==void 0)?x:void 0,u=[],h=[];let d=null;if(t.length){const r=Ve();let w=null;const O=Hn(Fn(c,t,void 0,f,J,o.map(E=>({dies:E})),void 0,"full"),{onDone:E=>{w=E,r.removeAttribute("aria-busy"),E?r.replaceChildren(E):r.remove()}});if(O.done)w&&(d=r);else{const E=a.createElement("div");E.textContent="Computing test statistics\u2026",Object.assign(E.style,{color:z.label,fontSize:V.body}),r.setAttribute("aria-busy","true"),r.appendChild(E),d=r,u.push(()=>O.cancel())}}let S=null;if(s.length){const r=jn(c,s,f,J);if(r){const w=Ve();w.appendChild(r),S=w}}return d&&h.push(d),S&&h.push(S),{cards:h,destroy:()=>{for(const r of u)r()}}}function Vt(e){const t=ht(e.map(d=>d.passBins)),s=e.length===1,o=e[0],c=Ve();Object.assign(c.style,{flexDirection:"row",flexWrap:"wrap",gap:W.md});const x=d=>{const S=d.lastElementChild;return S&&Object.assign(S.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function f(d,S,r){const w=a.createElement("div");Object.assign(w.style,{display:"flex",alignItems:"baseline",gap:W.sm,paddingRight:W.xxl,marginRight:W.md,borderRight:`1px solid ${z.menuBorder}`});const O=a.createElement("div");O.textContent=d,Object.assign(O.style,{fontSize:V.heading,fontWeight:"700",color:z.value,lineHeight:Qe.tight});const E=a.createElement("div");if(E.textContent=S,Object.assign(E.style,{fontSize:V.body,color:z.label}),w.append(O,E),r){const L=a.createElement("div");L.textContent=r,Object.assign(L.style,{fontSize:V.meta,color:z.label,opacity:Bn.muted}),w.appendChild(L)}return w}if(s){const d=kt([{...o,key:o.waferIndex}])[0]?.percent;return d!==void 0&&c.appendChild(f(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),c.appendChild(f(String(o.dies.length),"Total dies")),x(c)}c.appendChild(f(String(e.length),"Wafers"));const u=kt(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(u.length){const d=u.reduce((w,O)=>w+O,0)/u.length,S=Mn([{key:"all",items:e.map(w=>({...w,key:w.waferIndex}))}])[0]?.percent,r=S!==void 0&&S.toFixed(1)!==d.toFixed(1);c.appendChild(f(`${d.toFixed(1)}%`,`${on} \xB7 pass: ${t}`,r?`${S.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((r,w)=>r+w.stats.analyzedDies,0),S=h.reduce((r,w)=>r+w.stats.excludedDies,0);c.appendChild(f(d.toLocaleString(),"Dies analysed",S?`${S.toLocaleString()} excluded`:void 0))}else c.appendChild(f(e.reduce((d,S)=>d+S.dies.length,0).toLocaleString(),"Total dies"));return x(c)}function qt(e,t,s,o,c){const x=a.createElement("div");Object.assign(x.style,{display:"flex",flexDirection:"column",gap:W.lg});const f=e.length===1&&!o;e.length&&!o&&x.appendChild(Vt(e));const u=Ht(e,o,c,!f),h=Gt(e,t,s,o,c);for(const r of h.elements)u.card.appendChild(r);const d=Kt(e,s);if(d&&x.appendChild(d.el),e.length>=4&&Me.length){const r=On({wafers:e,fields:Me,curation:Ce,groupedBy:R,onGroupBy:w=>{R=w,_=null,re()},ownerDocument:a});x.appendChild(r.card)}x.appendChild(u.card);const S=Ln({items:e.map(r=>({...r,ringCount:Q()})),testDefs:s,ownerDocument:a,showMap:k.showPatMap});return S&&x.appendChild(S.card),x.appendChild(Xt()),{card:x,destroy:()=>{u.destroy(),h.destroy(),d?.destroy()}}}function Kt(e,t){const s=k.getSynthesisSummary?.()??(Re?void 0:oe?.()??(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:W.md});const c=a.createElement("h3");c.textContent="Worth a look",Object.assign(c.style,{margin:"0",fontSize:V.heading,fontWeight:"600",color:z.value}),o.appendChild(c);const x=(r,w)=>{const O=a.createElement("p");O.textContent=r,w&&(O.dataset[w]="1"),Object.assign(O.style,{margin:"0",fontSize:V.body,color:z.label,lineHeight:Qe.base}),o.appendChild(O)};if(_!==null)return x("Worth a look describes every group, as What stands out beside the map does. Show all groups to see it here.","wmapWorthNarrowed"),{el:o,destroy:()=>{}};const f=Qn(s,{passBins:tr(e.map(r=>r.passBins)),attributes:k.attributes});if(f.items.length===0)return x(f.nothing??"Nothing stands out.","wmapWorthNothing"),{el:o,destroy:()=>{}};const u=Le(a);o.appendChild(u);const h=ie(e.map(r=>({label:r.identity??r.label,dies:r.dies,waferIndex:r.waferIndex,wafer:r.wafer,passBins:r.passBins,ringCount:Q()}))),d=[],S=f.items.filter(r=>!At(r));return ct=new Set(f.items.filter(At).map(Lt)),S.length===0&&x("The groups of wafers that differ in yield are in What divides yield, below.","wmapWorthGroupsBelow"),S.forEach((r,w)=>{if(r.target.kind==="group"&&R!==void 0&&r.target.fields.includes(R))return;const O=a.createElement("div");O.dataset.wmapWorthWhy="1",O.textContent=`Shown because: ${r.reason}`,r.text!==r.reason&&Oe(O,r.text),Object.assign(O.style,{flexBasis:"100%",fontSize:V.body,color:z.text,lineHeight:Qe.base});const E=[O];if(k.showOnMap&&r.target.kind!=="group"){const $=a.createElement("button");$.type="button";const I=r.target.kind==="test"&&er(r)!==void 0&&r.target.kind==="test"?t.find(l=>l.testNumber===r.target.testNumber):void 0;$.textContent=I?`Show ${ge(I,I.testNumber)} on map`:"Show on map",$.dataset.wmapWorthShowOnMap="1",Object.assign($.style,{...mt("outlined"),fontSize:V.body,padding:`0 ${W.md}`}),Te($),Oe($,I?`Leave Insights and show ${ge(I,I.testNumber)} on the map. The map shows the test, not the groups`:"Leave Insights and show this on the map, as its row in What stands out does"),$.addEventListener("click",()=>k.showOnMap(r.target)),E.push($)}const L=ee({doc:a,items:h,ctx:{testDefs:t,curation:Ce,groupBy:R},spec:{id:`worth-${w}`,...Jn(r.chart,!!R)},extras:E,editAsPlot:Z,chart:{onSaveImage:M,onSelectPoints:xe(h,e,($,j)=>{const I=$?.range?t.find(l=>l.testNumber===Tt(r.chart)):void 0;return I&&$?.range?`with ${ge(I,I.testNumber)} from ${Ee($.range.lo,I.unit,"engineering")} to ${Ee($.range.hi,I.unit,"engineering")}${$.group?` in ${$.group}`:""}`:Ge($,j,"in this part of the chart")},$=>Pt(t,$?.cell?.row??$?.category)??Tt(r.chart)),onWaferMenu:we(e),onOpenWafer:se?($,j,I)=>Ye(h[$].waferIndex??$,`Wafer ${h[$].label}`,j,I):void 0}});L.card.dataset.wmapWorthKey=Lt(r),u.appendChild(L.card),d.push(L.destroy)}),f.possible?.length&&x(`${Zn}: ${f.possible.map(r=>r.reason).join("; ")}.`,"wmapWorthPossible"),{el:o,destroy:()=>d.forEach(r=>r())}}function Xt(){const e=a.createElement("div");Object.assign(e.style,{fontSize:V.body,color:z.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:z.iconActive,textDecoration:"underline"}),Te(t,"bare"),t.addEventListener("click",()=>{X="data",re({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",t,"."),e}function Ut(e,t,s,o){const c=a.createElement("div");c.style.width="100%";let x,f=!1;return import("./plotTab.js").then(({createPlotSection:u})=>{if(f)return;const h=u({doc:a,store:pe,items:e,testDefs:t,ringCount:Q(),attributes:k.attributes,groupBy:s,groupLabel:o,onSaveImage:M,onSaveText:J,getBinColors:le,waferMenu:we(e),openWafer:se?(d,S,r,w)=>se(d,S,r,w):void 0,focusTest:Pe,locateDie:ye,pickPlotsFile:k.onPickPlotsFile});c.appendChild(h.card),x=h}),{card:c,destroy:()=>{f=!0,x?.destroy()}}}function Qt(e,t,s,o,c){const x=Re?void 0:oe?.(),f=()=>{he.get("data")?.destroy(),he.delete("data"),re({keepSections:!0})};return _n({doc:a,items:e,testDefs:t,allTestDefs:s,groups:o,groupLabelText:c,ringCount:Q(),attributes:k.attributes,yieldByWaferIndex:new Map(x?.lotYieldSeries.map(u=>[u.waferIndex,u.yieldPercent])),onSaveText:J,onLocateDie:ye,onOpenWafer:se?(u,h,d,S)=>se(u,h,d,S):void 0,buildStatistics:u=>_t(u,t,s),view:ot,onViewChange:u=>{ot=u,f()},diesLayout:lt,onDiesLayoutChange:u=>{lt=u}})}function ke(e,t){const s=a.createElement("h3");return s.textContent=e,s.dataset.wmapRowHeading=t,Object.assign(s.style,{gridColumn:"1 / -1",margin:`${W.md} 0 0`,color:z.value,fontSize:V.heading,fontWeight:"600"}),s}function Jt(e,t,s,o){const c=Le(a),x=ft(e),f=ie(e.map(n=>({label:n.identity??n.label,dies:n.dies,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:Q()}))),u=t.filter(n=>n.testNumber!==void 0),h=!!s&&!!R,d=h&&_!==null,S={testDefs:t,groupBy:h?R:void 0,curation:k.attributes},r=u.length>1;let w;const O=[];function E(n){let p=Fe,y=!1,C;const B=bt(u,q??u[0]?.testNumber??null,Y=>{C?.refresh(),v(Y)},{ownerDocument:a}),K=a.createElement("span");Object.assign(K.style,{display:"inline-flex",flexWrap:"wrap",gap:W.sm,alignItems:"center"});const A={setAxisPrefs:Y=>{U.set(Y)&&(p=Y,C?.refresh())}},U=xt(K,p,Y=>{p=Y,C?.refresh(),ze(Y,A)},a),Se=[B.el,K];n.logToggle&&Se.push(Ze("Log scale",y,Y=>{y=Y,C?.refresh()},a,"Draw the value axis on a logarithmic scale")),Se.push(...n.extras??[]),C=ee({doc:a,editAsPlot:Z,items:f,ctx:S,...n.card,spec:{choices:n.choices??[],build:Y=>n.build(p,y,Y)},slots:()=>({test:B.get()??void 0}),extras:Se,onResolved:Y=>{const me=t.find(an=>an.testNumber===B.get()),ve=Ae(me,p.limits),qe=Ot(Y,n.valueRole),{lo:nn,hi:rn}=St(ve),sn=qe.length>0&&ve.length>0&&vt($t(qe),Bt(qe),nn,rn);U.sync(p.includeLimits??sn,Ae(me).length>0,Ct(me))},chart:n.chart});const H=C;if(r){const Y=()=>{B.el.style.display=Rn(H.card)?"":"none"};Y();const me=a.defaultView?.MutationObserver;if(me){const ve=new me(Y);ve.observe(H.card,{attributes:!0,attributeFilter:["data-wmap-expanded"]}),O.push(ve)}}return{card:H.card,setTest:Y=>{B.set(Y)&&H.refresh()},refresh:()=>H.refresh(),setAxisPrefs:A.setAxisPrefs,destroy:()=>H.destroy()}}const L=x?(n,p)=>x.open(f[n]?.waferIndex??n,p??q??u[0]?.testNumber??0):void 0;let $=!1,j=!1;const I=E({valueRole:"y",logToggle:!0,choices:[{current:h&&!d?"groups":"wafers",options:[...h&&!d?[["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,p,[y])=>($=h&&!d&&y==="nested",j=y==="radius",{id:"card-box",title:j?"Test value by radius":"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:j?{builtin:"ring"}:$?[{slot:"groupBy"},{builtin:"wafer"}]:h&&!d?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:$?{follow:"groupBy"}:{none:!0}},...d?{where:{conditions:[{field:{meta:R},values:[_]}]}}:{},...ae("y",n,p)}),card:{...h&&!d?{drill:n=>{if($||j)return null;const p=Ke(f[n[0]?.item]?.metadata,R,k.attributes);return p===void 0?null:y=>({...y,fields:{...y.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:R},values:[p]}]}})},drillLabel:()=>$||j?void 0:"see its wafers"}:{},..._!==null?{externalBack:{shown:()=>_!==null,onBack:()=>He(null)}}:{}},chart:{onSaveImage:M,onOpenWafer:L,openActionLabel:x?.label,onWaferMenu:we(e)}});let l=null;const b=h?[]:[yt(f.map(n=>({label:n.label})),null,n=>{l=n,i.refresh()},{ownerDocument:a})],i=E({valueRole:"x",logToggle:!0,extras:b,choices:[{current:"bars",options:[["bars","Histogram"],["cumulative","Cumulative","The share of dies at or below each value, as one curve per colour"]]},...h?[{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:_!==null?{externalBack:{shown:()=>_!==null,onBack:()=>He(null)}}:{},build:(n,p,[y,C])=>({id:"card-histogram",title:y==="cumulative"?"Cumulative distribution":"Value histogram",chart:y==="cumulative"?"probability":"histogram",fields:{y:{slot:"test"},color:h?{follow:"groupBy"}:{none:!0}},...h&&C!=="count"&&y!=="cumulative"?{histNorm:"percent"}:{},...l!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[l].label]}]}}:{},...ae("x",n,p)}),chart:{onSaveImage:M,onSelectPoints:(n,p,y,C)=>{const B=t.find(H=>H.testNumber===(q??u[0]?.testNumber)),K=new Set(n.map(H=>H.die).filter(H=>!!H)),A=new Set(n.map(H=>f[H.item]?.waferIndex)),U=C?.range,Se=B&&U?`with ${ge(B,B.testNumber)} from ${Ee(U.lo,B.unit,"engineering")} to ${Ee(U.hi,B.unit,"engineering")}${C?.group?` in ${C.group}`:""}`:"selected in the histogram";ue(p,y,e.filter(H=>A.has(H.waferIndex)),Se,H=>K.has(H),B?.testNumber)}}}),g=E({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,p,[y])=>y==="control"?{id:"card-trend",title:"Wafer-to-wafer control chart",chart:"control",aggregate:"mean",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:h?{follow:"groupBy"}:{none:!0}},...ae("y",n,p)}:{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,p),axes:{...ae("y",n,p).axes,y:{...ae("y",n,p).axes.y,references:[{stat:"mean",label:Cn(vn(e.map(C=>C.wafer.metadata)),"mean")}]}}},card:{ctx:S,...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:M,onWaferMenu:we(e),selectActionLabel:L?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(n,p,y)=>{const C=new Set(n.map(A=>A.item));if(C.size===1&&L){L([...C][0]);return}const B=new Set(n.map(A=>A.die).filter(A=>!!A)),K=new Set(n.map(A=>f[A.item]?.waferIndex));ue(p,y,e.filter(A=>K.has(A.waferIndex)),"selected in the trend",A=>B.has(A),q??void 0)}}}),v=n=>{q=n,w?.set(n),I.setTest(n),i.setTest(n),g.setTest(n),P.setTest(n),m?.setTest(n),T?.setTest(n)},D=()=>Tn({groups:s,testDefs:t,groupLabelText:o,control:dt,onControlChange:n=>{dt=n;const p=D();m.card.replaceWith(p.card),m=p},selectedTestNumber:q??void 0,onSelectTest:n=>v(n),onSaveText:J,ownerDocument:a});let m=s&&s.length>=2?D():void 0;const T=s&&s.length>=2?An({groups:s,testDefs:t,groupLabelText:o,selectedTestNumber:q??void 0,onSaveImage:M,ownerDocument:a}):void 0;je.set("distribution",[I,i,g]);const P=En({title:"Process capability",items:e,testDefs:t,onSaveImage:M,selectedTestNumber:q??void 0,onSelectTest:n=>v(n),ownerDocument:a}),F=e.length>=2?qn(e.map(n=>({dies:n.dies})),t.filter(n=>n.testNumber!==void 0&&Ie(n)).map(n=>n.testNumber),nr):[],N=F.length>=2?ee({doc:a,editAsPlot:Z,items:f,ctx:S,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:M,onSelectPoints:xe(f,e,(n,p)=>`${p?"":`in ${n?.cell?.column??"the group"}, `}for ${n?.cell?.row??"a test"}`,n=>Pt(t,n?.cell?.row))}}):void 0;if(N&&(N.card.style.minHeight="300px"),N&&(c.append(ke(`Tests across ${s?o??"groups":"wafers"}`,"tests-grid")),c.append(N.card)),(m||T)&&(c.append(ke(`Comparing ${o??"groups"}`,"comparing")),m&&c.append(m.card),T&&c.append(T.card)),r){w=bt(u,q??u[0]?.testNumber??null,B=>v(B),{ownerDocument:a});const n=a.createElement("div");n.dataset.wmapSectionTest="1",Object.assign(n.style,{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:W.lg,flexWrap:"wrap",marginTop:W.md});const p=ke("Test by test","tests");p.style.margin="0";const y=a.createElement("label");Object.assign(y.style,{display:"inline-flex",alignItems:"center",gap:W.xs,fontSize:V.body,color:z.label});const C=a.createElement("span");C.textContent="Test",y.append(C,w.el),n.append(p,y),c.append(n)}else(m||T)&&c.append(ke("Test by test","tests"));return c.append(P.card,I.card,i.card,g.card),{card:c,destroy:()=>{for(const n of O)n.disconnect();P.destroy(),I.destroy(),i.destroy(),g.destroy(),m?.destroy(),T?.destroy(),N?.destroy()}}}function Zt(e,t,s,o){const c=Le(a),x=ft(e),f=ie(e.map(m=>({label:m.identity??m.label,dies:m.dies,waferIndex:m.waferIndex,wafer:m.wafer,passBins:m.passBins,ringCount:Q()}))),u=t.filter(m=>m.testNumber!==void 0&&Ie(m));let h=u[0]?.testNumber,d=u[1]?.testNumber??h,S=null,r=Fe;const w=!!s&&!!R,O=(m,T)=>{const P=a.createElement("label");Object.assign(P.style,{display:"inline-flex",alignItems:"center",gap:W.xs,fontSize:V.body,color:z.label});const F=a.createElement("span");return F.textContent=m,P.append(F,T),P},E=wt(u,h??null,m=>{h=m,v.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:a}),L=wt(u,d??null,m=>{d=m,v.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:a}),$=a.createElement("span");Object.assign($.style,{display:"inline-flex",flexWrap:"wrap",gap:W.sm,alignItems:"center"});let j=!1,I=!1;const l={setXY:(m,T)=>{h=m,d=T,E.value=String(m),L.value=String(T),v.refresh()},setAxisPrefs:m=>{b.set(m)&&(r=m,v.refresh())},destroy:()=>v.destroy()},b=xt($,r,m=>{r=m,v.refresh(),ze(m,l)},a),i=m=>{const T=t.find(P=>P.testNumber===m);return T?.name?{test:m??0,name:T.name}:{test:m??0}},g=[O("X:",E),O("Y:",L),$,Ze("Log X",j,m=>{j=m,v.refresh()},a,"Draw the X axis on a logarithmic scale"),Ze("Log Y",I,m=>{I=m,v.refresh()},a,"Draw the Y axis on a logarithmic scale")];!w&&e.length>1&&g.push(yt(f.map(m=>({label:m.label})),null,m=>{S=m,v.refresh()},{ownerDocument:a}));const v=ee({doc:a,editAsPlot:Z,items:f,ctx:{testDefs:t,groupBy:w?R:void 0,curation:k.attributes},extras:g,onResolved:m=>{const T=[h,d].map(F=>t.find(N=>N.testNumber===F)),P=["x","y"].some((F,N)=>{const n=Ae(T[N],r.limits),p=Ot(m,F),{lo:y,hi:C}=St(n);return p.length>0&&n.length>0&&vt($t(p),Bt(p),y,C)});b.sync(r.includeLimits??P,T.some(F=>Ae(F).length>0),T.some(Ct))},spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:r.limits??"both",axes:{...ae("x",r,j).axes,...ae("y",r,I).axes},fields:{x:i(h),y:i(d),color:w?{follow:"groupBy"}:{builtin:"hbin"}},...w?{fit:"linear"}:{},...S!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[S].label]}]}}:{}})},...h===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:M,binColors:le(),onOpenWafer:x?(m,T)=>x.open(f[m]?.waferIndex??m,T??h??0):void 0,openActionLabel:x?.label,onSelectPoints:(m,T,P)=>{const F=new Map;for(const p of m){const y=f[p.item]?.waferIndex;if(y===void 0||!p.die)continue;const C=F.get(y);C?C.push(p.die):F.set(y,[p.die])}const N=[...F].flatMap(([p,y])=>{const C=e.find(B=>B.waferIndex===p);return C?[{label:C.identity??C.label,dies:y,waferIndex:p,wafer:C.wafer,passBins:C.passBins,ringCount:Q()}]:[]});if(N.length===0)return;const n=N.length===1?`selected on ${N[0].label} in the scatter`:`selected in the scatter, across ${N.length} wafers`;Ue(T,P,{items:N,population:n,testDefs:t,activeTest:h},{plots:pe,getBinColors:le,onSaveImage:M,onSaveText:J,onLocateDie:ye})}}});je.set("correlation",[l]);const D=Pn({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:M,onSaveText:J,...w&&s&&s.length>=2?{groups:s,groupLabelText:o}:{},onSelectPair:(m,T)=>l.setXY(m,T),ownerDocument:a});return c.append(D.card,v.card),{card:c,destroy:()=>{D.destroy(),l.destroy()}}}const en=(e,t,s,o)=>wn(a,e,t,s,o),tn=()=>Be.openEditor(G,_e());function re(e){e?.keepSections||ut(),ne.innerHTML="",te.innerHTML="";for(const l of Mt)te.appendChild(zt(l.key,l.label));const t=_e(),s=Be.keep(t),o=s.items;Re=s.narrowing,nt.refresh(s.result,t),Yt(o);const c=ln(o,{facetableOnly:!0,curation:Ce}).filter(l=>l.splittable);Me=c.map(l=>({key:l.key,label:l.label}));const x=a.createElement("div");Object.assign(x.style,{display:"flex",gap:W.md,alignItems:"center",marginLeft:W.xxl,paddingBottom:W.xs}),k.showFilterButton!==!1&&x.appendChild(en("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>tn()));let f;c.length>0?(x.appendChild(gt("Group by:",[{value:"",label:"None"},...c.map(l=>({value:l.key,label:`${l.label} (${l.values.length})`}))],R??"",l=>{R=l||void 0,_=null,re()},{hook:"group-by",ownerDocument:a,hint:"Split every chart by a wafer attribute, such as lot or tester"})),f=c.find(l=>l.key===R)?.label):R=void 0;let u;if(R){const l=new Map,b=[];for(const i of o){const g=Ke(i.metadata,R,Ce)??dn;l.has(g)||(l.set(g,[]),b.push(g)),l.get(g).push(i)}u=Un(b).map(i=>({key:i,items:l.get(i)}))}_!==null&&!u?.some(l=>l.key===_)&&(_=null),u&&u.length>0&&x.appendChild(Nn(u.map(l=>l.key),"Show:",_,l=>He(l),{ownerDocument:a,hint:"Show every group, or analyse just one"}).el);const h=gt("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(l=>({value:String(l),label:`${l} (${l})`}))],ce===void 0?"auto":String(ce),l=>rt(l==="auto"?void 0:Number(l)),{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"});De=h.querySelector("button"),x.appendChild(h);let d=null;if(k.onOpenGuide){const l=a.createElement("button");l.type="button",l.innerHTML=In.help,l.setAttribute("aria-label","User guide"),Object.assign(l.style,{...mt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),Te(l,"bare"),Oe(l,"User guide"),l.addEventListener("click",()=>k.onOpenGuide()),Object.assign(l.style,{marginLeft:"auto"}),d=l}te.appendChild(x),d&&te.appendChild(d);const S=_!==null?u?.find(l=>l.key===_):void 0,r=S?.items??o,w=S?void 0:u,O=Xe(r),E=O.defs,L=E.filter(Ie);if(q!==null&&!L.some(l=>l.testNumber===q)&&(q=null),o.length===0){ne.appendChild(xn(a,"wmapInsightsFilterEmpty"));return}const $=e?.keepSections?he.get(X):void 0,j=$??(X==="overview"?qt(r,L,E,w,f):X==="distributions"?Jt(r,L,w,f):X==="data"?Qt(r,L,E,w,f):X==="plot"?Ut(r,E,S?void 0:R,S?void 0:f):Zt(r,L,w,f));$||he.set(X,j);const I=O.conflicts.filter(l=>l.excluded);if(I.length>0){const l=a.createElement("div");Object.assign(l.style,{color:z.label,fontSize:V.body,padding:`0 ${de} ${W.sm}`});const b=I.slice(0,6).map(v=>v.testNumber).join(", "),i=I.length>6?`, and ${I.length-6} more`:"",g=I.length===1?"it":"them";l.textContent=`${I.length} test ${I.length===1?"number is":"numbers are"} hidden (${b}${i}) \u2014 the wafers in view describe ${g} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${f??"group"} under "Show:" to analyse ${g}.`:"Load one test program at a time to analyse them."),l.dataset.wmapWithheldTests=String(I.length),ne.appendChild(l)}ne.appendChild(j.card),$e()}return{el:G,render:re,destroy:()=>{a.removeEventListener("keydown",it),at?.disconnect(),ut(),pe.flush(),G.remove()},setAxisPrefs:e=>ze(e,null,!0),showWorthCard:e=>{X!=="overview"&&(X="overview",re({keepSections:!0}));const t=[...ne.querySelectorAll("[data-wmap-worth-key]")].find(c=>c.dataset.wmapWorthKey===e)??(ct.has(e)?ne.querySelector("[data-wmap-commonality]")??void 0:void 0);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 ${z.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
@@ -0,0 +1,7 @@
1
+ import type { PlotMode } from '../renderer/buildView.js';
2
+ /**
3
+ * The mode to open the wafer in, or `undefined` to leave the gallery's mode as it is.
4
+ * `sharedMode` and `sharedTest` are the gallery's own; `testNumber` is the one the chart names, `view` 'bins' a request for the bins.
5
+ */
6
+ export declare function waferOpenMode(sharedMode: PlotMode | undefined, sharedTest: number | undefined, testNumber: number | undefined, view?: 'bins'): PlotMode | undefined;
7
+ //# sourceMappingURL=openWaferMode.d.ts.map
@@ -0,0 +1 @@
1
+ const u={stackedValues:"value",stackedBins:"hardBin",stackedSoftBins:"softBin"};export function waferOpenMode(n,i,d,t){if(d!==void 0)return;if(t==="bins")return"hardBin";const e=n?u[n]:void 0;return e==="value"&&i===void 0?"hardBin":e}
@@ -25,7 +25,7 @@ export interface PlotSectionDeps {
25
25
  /** Right-click a wafer's own mark: that wafer's menu, by its index in the host's list. */
26
26
  waferMenu?: WaferContextMenuHandler;
27
27
  /** Click a point: open its wafer, on a test's values when the plot is about one. */
28
- openWafer?: (waferIndex: number, label: string, testNumber?: number) => void;
28
+ openWafer?: (waferIndex: number, label: string, testNumber?: number, view?: 'bins') => void;
29
29
  /** A single-wafer host's version of the same: show the test on the map that is already there. */
30
30
  focusTest?: (testNumber: number) => void;
31
31
  locateDie?: (die: Die, waferIndex: number | undefined) => void;
@@ -1 +1 @@
1
- import{defaultPlot as Pe,describeTitleDrift as Ee,examplePlots as Se,fieldCatalogue as De,resolvePlot as Ce,titleDrift as Ae}from"../stats/plotData.js";import{addPlots as ke,newPlotId as V,readPlotsFile as Te,writePlotsFile as Ie}from"../stats/plotSpec.js";import{buildFilterStrip as $e}from"./filterEditor.js";import{isYieldEligibleDie as je}from"../core/dies.js";import{testValue as Be}from"../core/dieTable.js";import{sweepAppliesTo as Oe}from"../stats/sweep.js";import{plotToSweep as Y}from"../stats/plotSpec.js";import{renderPlotChart as ee}from"./charts/plotChart.js";import{renderSweepPanel as te}from"./charts/sweep.js";import{makeChartGridWrap as oe,makeSegmented as Le}from"./charts/chartShell.js";import{confirmDialog as Me}from"./confirmDialog.js";import{openDrilldownMenu as ne}from"./drilldown.js";import{openPlotEditor as Ne}from"./plotModal.js";import{sourceFromDies as Fe,sourceFromPoints as We,toPlotItems as Re}from"./plotItems.js";import{CLR as h,FONT as D,RADIUS as W,SPACE as u,controlStyle as Ue,markNoPrint as I,saveTextFile as ze,wireControlHover as Ve,wireTooltip as Ye}from"./toolbar.js";const se=1e4;export function createPlotSection(l){const{doc:r,store:a}=l,p=Re(l.items.map(e=>({label:e.identity??e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:l.ringCount}))),$={testDefs:l.testDefs,groupBy:l.groupBy,curation:l.attributes},q=e=>Ce(e,p,$),j=De(p,$),g=r.createElement("div");g.dataset.wmapPlotTab="1",Object.assign(g.style,{display:"flex",flexDirection:"column",gap:u.lg,width:"100%"});const B=r.createElement("div");Object.assign(B.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const w=(e,t,n,o)=>{const s=r.createElement("button");return s.type="button",s.textContent=e,s.dataset[t]="1",Object.assign(s.style,{...Ue("outlined"),fontSize:D.body}),Ve(s),Ye(s,n),s.addEventListener("click",o),s},O=w("Delete all plots\u2026","wmapPlotDeleteAll","Remove every plot and sweep. You are asked first, and Undo brings them back for ten seconds",()=>{ye()});let E="plots";const C=Le([["plots","My plots","Your own plots, kept for the next lot"],["examples","Examples","One example of each chart type this lot can show, drawn from its own tests. They are not your plots until you add them"]],E,e=>ie(e),r);C.dataset.wmapPlotViews="1",C.setAttribute("aria-label","Plots shown");for(const e of Array.from(C.querySelectorAll("label")))e.querySelector("input")?.value==="examples"&&(e.dataset.wmapPlotExamples="1");B.append(C,w("+ New plot","wmapPlotNew","Start a chart of your own: choose its type (a sweep reads runs of tests as response curves), what goes on each axis and how it is coloured",()=>ae()),w("Import plots\u2026","wmapPlotImport","Add the plots from a file written by Export plots\u2026",()=>{be()}),w("Export plots\u2026","wmapPlotExport","Save all your plots to a file, to share or to keep a copy",()=>ge()),O),I(B),g.appendChild(B);const y=r.createElement("div");y.setAttribute("role","status"),Object.assign(y.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",padding:`${u.sm} ${u.md}`,background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:W.container,color:h.text,fontSize:D.body}),I(y),g.appendChild(y);let b;function S(e,t,n=[]){b!==void 0&&clearTimeout(b),y.replaceChildren();const o=r.createElement("span");if(o.textContent=e,y.appendChild(o),t){const s=w(t.label,"wmapPlotNoticeAction",t.label==="Undo"?"Put back what was just removed":t.label,()=>{t.run(),G()});y.appendChild(s)}for(const s of n){const i=r.createElement("div");i.textContent=s,Object.assign(i.style,{flexBasis:"100%",color:h.label}),y.appendChild(i)}y.style.display="flex",b=setTimeout(G,t?se:se*2)}function G(){b!==void 0&&(clearTimeout(b),b=void 0),y.style.display="none",y.replaceChildren()}const x=r.createElement("div");x.dataset.wmapPlotGallery="1",Object.assign(x.style,{display:"none",flexDirection:"column",gap:u.md,padding:u.md,border:`1px solid ${h.menuBorder}`,borderRadius:W.container}),I(x),g.appendChild(x);let L=[];const _=()=>{for(const e of L)e.destroy();L=[],x.replaceChildren(),x.style.display="none"},A=r.createElement("div");A.textContent="No plots yet. A plot is any measured value against another, or a distribution, that you choose: New plot starts one, and it is kept for the next lot. Examples shows one of each chart type from this lot, to look at and to add the ones you want.",Object.assign(A.style,{color:h.label,fontSize:D.body,padding:`${u.lg} 0`});const k=oe(r);g.append(A,k);const v=new Map,R=()=>({onSaveImage:l.onSaveImage,onSaveText:l.onSaveText,binColors:l.getBinColors?.(),onWaferMenu:l.waferMenu?(e,t,n)=>l.waferMenu(p[e].waferIndex??e,t,n):void 0,onOpenWafer:l.openWafer?(e,t)=>l.openWafer(p[e].waferIndex??e,p[e].label,t):l.focusTest&&p.length===1?(e,t)=>{t!==void 0&&l.focusTest(t)}:void 0,openActionLabel:!l.openWafer&&l.focusTest&&p.length===1?"show this test on the map":void 0,onSelectPoints:(e,t,n)=>le(e,t,n)}),H=()=>({plots:a,getBinColors:l.getBinColors,onSaveImage:l.onSaveImage,onSaveText:l.onSaveText,onLocateDie:l.locateDie});function le(e,t,n){const o=We(e,p,l.testDefs);o&&ne(t,n,o,H())}function J(e,t=!1){Ne({doc:r,anchor:g,store:a,plot:e,draft:t,items:p,ctx:$,groupLabel:l.groupLabel,chart:R(),onSelectLevel:U})}function U(e,t){const n=s=>e.testNumbers.some(i=>{const d=Be(s,i);return d!==void 0&&Number.isFinite(d)}),o=Fe(p,`measured at ${e.label}`,s=>je(s)&&n(s),l.testDefs,e.testNumbers[0]);o&&ne({x:t.clientX,y:t.clientY},t.target,o,H())}function ae(){N("plots");const e=Pe(j,V());a.upsert(e),J(e)}const M=e=>JSON.stringify([e.chart,e.fields,e.aggregate??null,e.sweep??null,e.fit??null,e.normalCurve??null,e.spread??null,e.normalize??null,e.sort??null,e.cumulative??null,e.stack??null]);function N(e){const t=C.querySelector(`input[value="${e}"]`);!t||t.checked||(t.checked=!0,t.dispatchEvent(new(r.defaultView??window).Event("change")))}function re(){k.style.display=E==="plots"?"grid":"none",A.style.display=E==="plots"&&a.get().length===0?"":"none",x.style.display=E==="examples"?"flex":"none"}function ie(e){if(e!==E){if(E=e,e==="examples"){if(!ce()){N("plots");return}}else _();re()}}function ce(){const e=Se(j,p.length,V,{items:p,ctx:$});if(e.length===0)return S(j.some(c=>c.group==="Tests")?"There are no examples this lot can draw.":"There are no measured values in this lot to draw examples from."),!1;const t=r.createElement("div");Object.assign(t.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const n=r.createElement("div");Object.assign(n.style,{color:h.text,fontSize:D.body,flex:"1 1 auto"});const o=[],s=w("Add all","wmapPlotExamplesAddAll","Add every example you do not have yet to My plots",()=>{const c=o.map(f=>f.add()).filter(f=>f!==void 0);c.length!==0&&(N("plots"),S(`Added ${c.length} plot${c.length===1?"":"s"} to My plots.`,{label:"Undo",run:()=>{const f=new Set(c);a.replaceAll(a.get().filter(P=>!f.has(P.id)))}}))});t.append(n,s);const i=oe(r);x.append(t,i);const d=[],F=()=>{const c=o.filter(f=>a.get().some(P=>M(P)===M(f.example))).length;n.textContent=`${e.length} examples from this lot, drawn for you. They are not your plots until you add them${c?` (${c} added)`:""}; edit them under My plots.`,s.disabled=c===e.length,s.style.opacity=c===e.length?"0.6":"1"};for(const c of e){let f;if(c.chart==="sweep")f=te({spec:Y(c),dies:p.flatMap(z=>z.dies),testDefs:l.testDefs,onSaveImage:l.onSaveImage,ownerDocument:r,onSelectPoint:U});else{const m=ee({ownerDocument:r,waferLabel:z=>p[z]?.label??"",...R()});m.setPlot(q(c)),f=m}f.card.dataset.wmapPlotExample=c.chart;const P=r.createElement("span");P.textContent="Example",P.dataset.wmapPlotExampleBadge="1",Object.assign(P.style,{fontSize:D.sub,color:h.label,border:`1px dashed ${h.menuBorder}`,borderRadius:W.control,padding:`0 ${u.sm}`});const T=w("Add to my plots","wmapPlotExampleAdd","Add this example to My plots, where you can edit it",()=>{}),Q=()=>a.get().some(m=>M(m)===M(c)),ve=()=>{const m=Q();T.textContent=m?"In your plots":"Add to my plots",T.disabled=m,T.style.opacity=m?"0.6":"1"},Z=()=>{if(Q())return;const m=V();return a.upsert({...c,id:m}),m};T.addEventListener("click",()=>{Z()}),o.push({example:c,add:Z}),d.push(ve),f.actions.append(P,T),i.appendChild(f.card),L.push(f)}const xe=a.subscribe(()=>{for(const c of d)c();F()});L.push({card:t,destroy:xe});for(const c of d)c();return F(),!0}function K(e,t){const n=(o,s,i,d)=>e.appendChild(w(o,s,i,d));n("Edit","wmapPlotEdit","Change this plot\u2019s type, fields, titles, limits and axes",()=>{const o=a.get().find(s=>s.id===t.id);o&&J(o)}),n("Duplicate","wmapPlotDuplicate","Make a copy of this plot to vary",()=>{a.duplicate(t.id)}),n("Delete","wmapPlotDelete","Remove this plot. Undo brings it back for ten seconds",()=>{const o=a.remove(t.id);o&&S(`Deleted \u201C${o.plot.title??"plot"}\u201D.`,{label:"Undo",run:()=>a.insertAt(o.index,o.plot)})})}function de(e){return e.chart==="sweep"?fe(e):pe(e)}function pe(e){const t=ee({ownerDocument:r,waferLabel:i=>p[i]?.label??"",...R()});t.card.dataset.wmapPlotId=e.id,I(t.actions),K(t.actions,e);const n=r.createElement("div");n.dataset.wmapPlotTitleDrift="1",Object.assign(n.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",flexBasis:"100%",padding:`${u.xs} ${u.md}`,background:h.warnBg,border:`1px solid ${h.warnBorder}`,borderRadius:W.control,color:h.warnText,fontSize:D.body});const o=r.createElement("div");o.style.flexBasis="100%",t.actions.append(o,n);const s={sweep:!1,card:t.card,actions:t.actions,json:"",driftNote:n,destroy:()=>t.destroy(),update:i=>{const d=q(i);t.setPlot(d),ue(o,i),t.card.style.opacity=d.issues.length?"0.7":"1",me(n,i)}};return v.set(e.id,s),s}function fe(e){const t=Y(e),n=p.flatMap(i=>i.dies),o=te({spec:t,dies:n,testDefs:l.testDefs,onSaveImage:l.onSaveImage,ownerDocument:r,onSelectPoint:U});o.card.dataset.wmapPlotId=e.id,o.card.dataset.wmapSweepPlot="1",I(o.actions),K(o.actions,e);const s={sweep:!0,card:o.card,actions:o.actions,json:"",destroy:()=>o.destroy(),update:i=>{const d=Y(i);o.setSpec(d),o.card.style.opacity=Oe(d,l.testDefs)?"1":"0.7"}};return v.set(e.id,s),s}function ue(e,t){const n=t.where;e.replaceChildren(),n&&e.appendChild($e({doc:r,filter:n,testDefs:l.testDefs,attributes:l.attributes,label:"Filter",onToggle:o=>{const s=a.get().find(F=>F.id===t.id),i=s?.where;if(!s||!i)return;const d={...i};o?delete d.off:d.off=!0,a.upsert({...s,where:d})}}))}function me(e,t){const n=Ee(Ae(t,j));if(e.replaceChildren(),e.style.display=n?"flex":"none",!n)return;const o=r.createElement("span");o.textContent=n,e.append(o,w("Use the automatic title","wmapPlotAutoTitle","Replace the title you typed with the one written from the plot\u2019s settings",()=>{const s=a.get().find(d=>d.id===t.id);if(!s)return;const i={...s};delete i.title,a.upsert(i)}))}function X(){const e=a.get();for(const[t,n]of v)e.some(o=>o.id===t)||(n.destroy(),n.card.remove(),v.delete(t));e.forEach((t,n)=>{let o=v.get(t.id);o&&o.sweep!==(t.chart==="sweep")&&(o.destroy(),o.card.remove(),v.delete(t.id),o=void 0),o??=de(t);const s=JSON.stringify(t);o.json!==s&&(o.json=s,o.update(t)),k.children[n]!==o.card&&k.insertBefore(o.card,k.children[n]??null)}),A.style.display=E==="plots"&&e.length===0?"":"none",O.disabled=e.length===0,O.style.opacity=e.length===0?"0.5":"1",O.style.cursor=e.length===0?"default":"pointer"}const he=a.subscribe(X);X();async function ye(){const e=a.get().slice();if(e.length===0)return;const t=e.length;if(!await Me({doc:r,anchor:g,title:"Delete all plots",message:t===1?"Delete your 1 saved plot? It is kept on this computer for the next lot, so it will not be there for the next file either. Export plots\u2026 first to keep a copy.":`Delete all ${t} saved plots, sweeps included? They are kept on this computer for the next lot, so they will not be there for the next file either. Export plots\u2026 first to keep a copy.`,confirmLabel:t===1?"Delete 1 plot":`Delete ${t} plots`}))return;const o=a.get().slice();o.length!==0&&(a.replaceAll([]),S(`Deleted ${o.length===1?"1 plot":`all ${o.length} plots`}.`,{label:"Undo",run:()=>a.replaceAll(o)}))}function ge(){const e=a.get();if(e.length===0){S("There are no plots to export yet.");return}ze(Ie(e),"wafermap-plots.json","application/json",l.onSaveText)}async function we(){return l.pickPlotsFile?l.pickPlotsFile():new Promise(e=>{const t=r.createElement("input");t.type="file",t.accept=".json,application/json",t.addEventListener("change",()=>{const n=t.files?.[0];if(!n){e(null);return}n.text().then(e,()=>e(null))}),t.addEventListener("cancel",()=>e(null)),t.click()})}async function be(){const e=await we();if(e===null)return;const t=Te(e);if(t.error){S(`Could not import: ${t.error}`);return}const{plots:n,copies:o}=ke(a.get(),t.plots);a.replaceAll(n),N("plots");const s=[...t.warnings,...o.length?[`Kept as copies, since a plot with the same id already existed: ${o.join(", ")}`]:[]];S(`Imported ${t.plots.length} plot${t.plots.length===1?"":"s"}.`,void 0,s)}return{card:g,destroy:()=>{he(),b!==void 0&&clearTimeout(b),_();for(const e of v.values())e.destroy();v.clear(),a.flush()}}}
1
+ import{defaultPlot as Pe,describeTitleDrift as Ee,examplePlots as Se,fieldCatalogue as De,resolvePlot as Ce,titleDrift as Ae}from"../stats/plotData.js";import{addPlots as ke,newPlotId as V,readPlotsFile as Te,writePlotsFile as Ie}from"../stats/plotSpec.js";import{buildFilterStrip as $e}from"./filterEditor.js";import{isYieldEligibleDie as je}from"../core/dies.js";import{testValue as Be}from"../core/dieTable.js";import{sweepAppliesTo as Oe}from"../stats/sweep.js";import{plotToSweep as Y}from"../stats/plotSpec.js";import{renderPlotChart as ee}from"./charts/plotChart.js";import{renderSweepPanel as te}from"./charts/sweep.js";import{makeChartGridWrap as oe,makeSegmented as Le}from"./charts/chartShell.js";import{confirmDialog as Me}from"./confirmDialog.js";import{openDrilldownMenu as ne}from"./drilldown.js";import{openPlotEditor as Ne}from"./plotModal.js";import{sourceFromDies as Fe,sourceFromPoints as We,toPlotItems as Re}from"./plotItems.js";import{CLR as h,FONT as D,RADIUS as W,SPACE as u,controlStyle as Ue,markNoPrint as I,saveTextFile as ze,wireControlHover as Ve,wireTooltip as Ye}from"./toolbar.js";const se=1e4;export function createPlotSection(l){const{doc:r,store:a}=l,p=Re(l.items.map(e=>({label:e.identity??e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:l.ringCount}))),$={testDefs:l.testDefs,groupBy:l.groupBy,curation:l.attributes},q=e=>Ce(e,p,$),j=De(p,$),g=r.createElement("div");g.dataset.wmapPlotTab="1",Object.assign(g.style,{display:"flex",flexDirection:"column",gap:u.lg,width:"100%"});const B=r.createElement("div");Object.assign(B.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const w=(e,t,n,o)=>{const s=r.createElement("button");return s.type="button",s.textContent=e,s.dataset[t]="1",Object.assign(s.style,{...Ue("outlined"),fontSize:D.body}),Ve(s),Ye(s,n),s.addEventListener("click",o),s},O=w("Delete all plots\u2026","wmapPlotDeleteAll","Remove every plot and sweep. You are asked first, and Undo brings them back for ten seconds",()=>{ye()});let E="plots";const C=Le([["plots","My plots","Your own plots, kept for the next lot"],["examples","Examples","One example of each chart type this lot can show, drawn from its own tests. They are not your plots until you add them"]],E,e=>ie(e),r);C.dataset.wmapPlotViews="1",C.setAttribute("aria-label","Plots shown");for(const e of Array.from(C.querySelectorAll("label")))e.querySelector("input")?.value==="examples"&&(e.dataset.wmapPlotExamples="1");B.append(C,w("+ New plot","wmapPlotNew","Start a chart of your own: choose its type (a sweep reads runs of tests as response curves), what goes on each axis and how it is coloured",()=>ae()),w("Import plots\u2026","wmapPlotImport","Add the plots from a file written by Export plots\u2026",()=>{be()}),w("Export plots\u2026","wmapPlotExport","Save all your plots to a file, to share or to keep a copy",()=>ge()),O),I(B),g.appendChild(B);const y=r.createElement("div");y.setAttribute("role","status"),Object.assign(y.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",padding:`${u.sm} ${u.md}`,background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:W.container,color:h.text,fontSize:D.body}),I(y),g.appendChild(y);let b;function S(e,t,n=[]){b!==void 0&&clearTimeout(b),y.replaceChildren();const o=r.createElement("span");if(o.textContent=e,y.appendChild(o),t){const s=w(t.label,"wmapPlotNoticeAction",t.label==="Undo"?"Put back what was just removed":t.label,()=>{t.run(),G()});y.appendChild(s)}for(const s of n){const i=r.createElement("div");i.textContent=s,Object.assign(i.style,{flexBasis:"100%",color:h.label}),y.appendChild(i)}y.style.display="flex",b=setTimeout(G,t?se:se*2)}function G(){b!==void 0&&(clearTimeout(b),b=void 0),y.style.display="none",y.replaceChildren()}const x=r.createElement("div");x.dataset.wmapPlotGallery="1",Object.assign(x.style,{display:"none",flexDirection:"column",gap:u.md,padding:u.md,border:`1px solid ${h.menuBorder}`,borderRadius:W.container}),I(x),g.appendChild(x);let L=[];const _=()=>{for(const e of L)e.destroy();L=[],x.replaceChildren(),x.style.display="none"},A=r.createElement("div");A.textContent="No plots yet. A plot is any measured value against another, or a distribution, that you choose: New plot starts one, and it is kept for the next lot. Examples shows one of each chart type from this lot, to look at and to add the ones you want.",Object.assign(A.style,{color:h.label,fontSize:D.body,padding:`${u.lg} 0`});const k=oe(r);g.append(A,k);const v=new Map,R=()=>({onSaveImage:l.onSaveImage,onSaveText:l.onSaveText,binColors:l.getBinColors?.(),onWaferMenu:l.waferMenu?(e,t,n)=>l.waferMenu(p[e].waferIndex??e,t,n):void 0,onOpenWafer:l.openWafer?(e,t,n)=>l.openWafer(p[e].waferIndex??e,p[e].label,t,n):l.focusTest&&p.length===1?(e,t)=>{t!==void 0&&l.focusTest(t)}:void 0,openActionLabel:!l.openWafer&&l.focusTest&&p.length===1?"show this test on the map":void 0,onSelectPoints:(e,t,n)=>le(e,t,n)}),H=()=>({plots:a,getBinColors:l.getBinColors,onSaveImage:l.onSaveImage,onSaveText:l.onSaveText,onLocateDie:l.locateDie});function le(e,t,n){const o=We(e,p,l.testDefs);o&&ne(t,n,o,H())}function J(e,t=!1){Ne({doc:r,anchor:g,store:a,plot:e,draft:t,items:p,ctx:$,groupLabel:l.groupLabel,chart:R(),onSelectLevel:U})}function U(e,t){const n=s=>e.testNumbers.some(i=>{const d=Be(s,i);return d!==void 0&&Number.isFinite(d)}),o=Fe(p,`measured at ${e.label}`,s=>je(s)&&n(s),l.testDefs,e.testNumbers[0]);o&&ne({x:t.clientX,y:t.clientY},t.target,o,H())}function ae(){N("plots");const e=Pe(j,V());a.upsert(e),J(e)}const M=e=>JSON.stringify([e.chart,e.fields,e.aggregate??null,e.sweep??null,e.fit??null,e.normalCurve??null,e.spread??null,e.normalize??null,e.sort??null,e.cumulative??null,e.stack??null]);function N(e){const t=C.querySelector(`input[value="${e}"]`);!t||t.checked||(t.checked=!0,t.dispatchEvent(new(r.defaultView??window).Event("change")))}function re(){k.style.display=E==="plots"?"grid":"none",A.style.display=E==="plots"&&a.get().length===0?"":"none",x.style.display=E==="examples"?"flex":"none"}function ie(e){if(e!==E){if(E=e,e==="examples"){if(!ce()){N("plots");return}}else _();re()}}function ce(){const e=Se(j,p.length,V,{items:p,ctx:$});if(e.length===0)return S(j.some(c=>c.group==="Tests")?"There are no examples this lot can draw.":"There are no measured values in this lot to draw examples from."),!1;const t=r.createElement("div");Object.assign(t.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const n=r.createElement("div");Object.assign(n.style,{color:h.text,fontSize:D.body,flex:"1 1 auto"});const o=[],s=w("Add all","wmapPlotExamplesAddAll","Add every example you do not have yet to My plots",()=>{const c=o.map(f=>f.add()).filter(f=>f!==void 0);c.length!==0&&(N("plots"),S(`Added ${c.length} plot${c.length===1?"":"s"} to My plots.`,{label:"Undo",run:()=>{const f=new Set(c);a.replaceAll(a.get().filter(P=>!f.has(P.id)))}}))});t.append(n,s);const i=oe(r);x.append(t,i);const d=[],F=()=>{const c=o.filter(f=>a.get().some(P=>M(P)===M(f.example))).length;n.textContent=`${e.length} examples from this lot, drawn for you. They are not your plots until you add them${c?` (${c} added)`:""}; edit them under My plots.`,s.disabled=c===e.length,s.style.opacity=c===e.length?"0.6":"1"};for(const c of e){let f;if(c.chart==="sweep")f=te({spec:Y(c),dies:p.flatMap(z=>z.dies),testDefs:l.testDefs,onSaveImage:l.onSaveImage,ownerDocument:r,onSelectPoint:U});else{const m=ee({ownerDocument:r,waferLabel:z=>p[z]?.label??"",...R()});m.setPlot(q(c)),f=m}f.card.dataset.wmapPlotExample=c.chart;const P=r.createElement("span");P.textContent="Example",P.dataset.wmapPlotExampleBadge="1",Object.assign(P.style,{fontSize:D.sub,color:h.label,border:`1px dashed ${h.menuBorder}`,borderRadius:W.control,padding:`0 ${u.sm}`});const T=w("Add to my plots","wmapPlotExampleAdd","Add this example to My plots, where you can edit it",()=>{}),Q=()=>a.get().some(m=>M(m)===M(c)),ve=()=>{const m=Q();T.textContent=m?"In your plots":"Add to my plots",T.disabled=m,T.style.opacity=m?"0.6":"1"},Z=()=>{if(Q())return;const m=V();return a.upsert({...c,id:m}),m};T.addEventListener("click",()=>{Z()}),o.push({example:c,add:Z}),d.push(ve),f.actions.append(P,T),i.appendChild(f.card),L.push(f)}const xe=a.subscribe(()=>{for(const c of d)c();F()});L.push({card:t,destroy:xe});for(const c of d)c();return F(),!0}function K(e,t){const n=(o,s,i,d)=>e.appendChild(w(o,s,i,d));n("Edit","wmapPlotEdit","Change this plot\u2019s type, fields, titles, limits and axes",()=>{const o=a.get().find(s=>s.id===t.id);o&&J(o)}),n("Duplicate","wmapPlotDuplicate","Make a copy of this plot to vary",()=>{a.duplicate(t.id)}),n("Delete","wmapPlotDelete","Remove this plot. Undo brings it back for ten seconds",()=>{const o=a.remove(t.id);o&&S(`Deleted \u201C${o.plot.title??"plot"}\u201D.`,{label:"Undo",run:()=>a.insertAt(o.index,o.plot)})})}function de(e){return e.chart==="sweep"?fe(e):pe(e)}function pe(e){const t=ee({ownerDocument:r,waferLabel:i=>p[i]?.label??"",...R()});t.card.dataset.wmapPlotId=e.id,I(t.actions),K(t.actions,e);const n=r.createElement("div");n.dataset.wmapPlotTitleDrift="1",Object.assign(n.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",flexBasis:"100%",padding:`${u.xs} ${u.md}`,background:h.warnBg,border:`1px solid ${h.warnBorder}`,borderRadius:W.control,color:h.warnText,fontSize:D.body});const o=r.createElement("div");o.style.flexBasis="100%",t.actions.append(o,n);const s={sweep:!1,card:t.card,actions:t.actions,json:"",driftNote:n,destroy:()=>t.destroy(),update:i=>{const d=q(i);t.setPlot(d),ue(o,i),t.card.style.opacity=d.issues.length?"0.7":"1",me(n,i)}};return v.set(e.id,s),s}function fe(e){const t=Y(e),n=p.flatMap(i=>i.dies),o=te({spec:t,dies:n,testDefs:l.testDefs,onSaveImage:l.onSaveImage,ownerDocument:r,onSelectPoint:U});o.card.dataset.wmapPlotId=e.id,o.card.dataset.wmapSweepPlot="1",I(o.actions),K(o.actions,e);const s={sweep:!0,card:o.card,actions:o.actions,json:"",destroy:()=>o.destroy(),update:i=>{const d=Y(i);o.setSpec(d),o.card.style.opacity=Oe(d,l.testDefs)?"1":"0.7"}};return v.set(e.id,s),s}function ue(e,t){const n=t.where;e.replaceChildren(),n&&e.appendChild($e({doc:r,filter:n,testDefs:l.testDefs,attributes:l.attributes,label:"Filter",onToggle:o=>{const s=a.get().find(F=>F.id===t.id),i=s?.where;if(!s||!i)return;const d={...i};o?delete d.off:d.off=!0,a.upsert({...s,where:d})}}))}function me(e,t){const n=Ee(Ae(t,j));if(e.replaceChildren(),e.style.display=n?"flex":"none",!n)return;const o=r.createElement("span");o.textContent=n,e.append(o,w("Use the automatic title","wmapPlotAutoTitle","Replace the title you typed with the one written from the plot\u2019s settings",()=>{const s=a.get().find(d=>d.id===t.id);if(!s)return;const i={...s};delete i.title,a.upsert(i)}))}function X(){const e=a.get();for(const[t,n]of v)e.some(o=>o.id===t)||(n.destroy(),n.card.remove(),v.delete(t));e.forEach((t,n)=>{let o=v.get(t.id);o&&o.sweep!==(t.chart==="sweep")&&(o.destroy(),o.card.remove(),v.delete(t.id),o=void 0),o??=de(t);const s=JSON.stringify(t);o.json!==s&&(o.json=s,o.update(t)),k.children[n]!==o.card&&k.insertBefore(o.card,k.children[n]??null)}),A.style.display=E==="plots"&&e.length===0?"":"none",O.disabled=e.length===0,O.style.opacity=e.length===0?"0.5":"1",O.style.cursor=e.length===0?"default":"pointer"}const he=a.subscribe(X);X();async function ye(){const e=a.get().slice();if(e.length===0)return;const t=e.length;if(!await Me({doc:r,anchor:g,title:"Delete all plots",message:t===1?"Delete your 1 saved plot? It is kept on this computer for the next lot, so it will not be there for the next file either. Export plots\u2026 first to keep a copy.":`Delete all ${t} saved plots, sweeps included? They are kept on this computer for the next lot, so they will not be there for the next file either. Export plots\u2026 first to keep a copy.`,confirmLabel:t===1?"Delete 1 plot":`Delete ${t} plots`}))return;const o=a.get().slice();o.length!==0&&(a.replaceAll([]),S(`Deleted ${o.length===1?"1 plot":`all ${o.length} plots`}.`,{label:"Undo",run:()=>a.replaceAll(o)}))}function ge(){const e=a.get();if(e.length===0){S("There are no plots to export yet.");return}ze(Ie(e),"wafermap-plots.json","application/json",l.onSaveText)}async function we(){return l.pickPlotsFile?l.pickPlotsFile():new Promise(e=>{const t=r.createElement("input");t.type="file",t.accept=".json,application/json",t.addEventListener("change",()=>{const n=t.files?.[0];if(!n){e(null);return}n.text().then(e,()=>e(null))}),t.addEventListener("cancel",()=>e(null)),t.click()})}async function be(){const e=await we();if(e===null)return;const t=Te(e);if(t.error){S(`Could not import: ${t.error}`);return}const{plots:n,copies:o}=ke(a.get(),t.plots);a.replaceAll(n),N("plots");const s=[...t.warnings,...o.length?[`Kept as copies, since a plot with the same id already existed: ${o.join(", ")}`]:[]];S(`Imported ${t.plots.length} plot${t.plots.length===1?"":"s"}.`,void 0,s)}return{card:g,destroy:()=>{he(),b!==void 0&&clearTimeout(b),_();for(const e of v.values())e.destroy();v.clear(),a.flush()}}}