@wafertools/wafermap 0.37.0 → 0.37.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.
package/CHANGELOG.md CHANGED
@@ -24,6 +24,34 @@ under `### Breaking`.
24
24
 
25
25
  ## [Unreleased]
26
26
 
27
+ ## [0.37.1] — 2026-10-22
28
+
29
+ ### Added
30
+
31
+ - **PAT verdict as a plot mode.** The **Plot mode** menu of a map and of a gallery offers **PAT verdict** when a test has both
32
+ limits and a wafer has enough dies to set PAT limits from: each die is coloured within the PAT limits (blue), PAT outlier
33
+ (amber) or fails (red), with the legend, counts, tooltips, Expand and a gallery's shared colours as in the other modes. The dies
34
+ keep their bins and measurements, and the verdicts are judged over the dies the page filter keeps, as the PAT card's are.
35
+
36
+ ### Changed
37
+
38
+ - **Enter in a long list's filter box picks the only test left showing.** In the test pickers and the Plot mode menu's test list, typing
39
+ until one test remains and pressing Enter chooses it.
40
+ - **Map the verdicts on the PAT card shows the maps in that mode** instead of opening them in a window, so the map's own yield,
41
+ legend, selection and filter apply.
42
+
43
+ ### Fixed
44
+
45
+ - **A filtered wafer's gross yield and edge count leave out the dies the filter drops.** `computeYield` counts only the
46
+ edge-excluded dies that are kept, so a filtered-out edge die no longer enters the gross denominator.
47
+ - **Group comparison reads the dies a yield judges.** `compareTestsByGroup` leaves out partial, edge-excluded and
48
+ filtered-out dies, as the Insights plots beside it do, so its means and p-values describe the same population.
49
+ - **PAT: a die failing its bin is in "Fails (bin or limits)" even when none of its limited tests has a value.**
50
+ - **The gallery's filtered Summary follows `setItems()` and `setLotStatsSummary()`.** With a filter on, the lot analysis
51
+ is rerun over the new items or the host's new analysis, so the panel and findings describe what is shown.
52
+ - **A command menu taller than the window scrolls inside it.** The right-click menu lists every saved plot, and with many
53
+ of them its last rows, **New plot…**, **New sweep…** and the tables, stay reachable.
54
+
27
55
  ## [0.37.0] — 2026-10-20
28
56
 
29
57
  ### Added
@@ -1 +1 @@
1
- import{SHADOW as G,LEADING as re,wireTooltip as U,wireControlHover as O,controlStyle as _,SPACE as v,RADIUS as $,fontPx as H,FONT as A,CLR as g,Z_BASE as le,menuLayerFor as se,wireListNavigation as ae,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as ce,markMenuTrigger as D,markNoPrint as W,openCommandMenu as de,saveImageBlob as ue,openReparentedModal as pe}from"../toolbar.js";import{ICONS as Y}from"../icons.js";import{openGuideAt as fe}from"../guideWindow.js";import{minOf as me,maxOf as he}from"../../core/utils.js";import{robustFence as K}from"../../stats/math.js";import{fmt as ge,fmtColorbarAxis as xe}from"../../renderer/fmt.js";import{markedTestLabel as be,DERIVED_LANE_PAD as ye}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=pe([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:we[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const d=Number(e.dataset.wmapChartFullH);if(!d)return;const c=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(c+d)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const we={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const d=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[i,n,r]=[0,2,4].map(c=>parseInt(d.slice(c,c+2),16)),d.length===8&&(l=parseInt(d.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Ce={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},Z={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(Z)){const n=o.getPropertyValue(`--wmap-${Z[i]}`).trim();t[i]=n||Ce[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${z(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function z(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function J(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(z(e,o)-l)-(t?J(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(z(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=J(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${H(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:ge(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,t){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:i,axisLabel:n,scaledUnit:r}=xe(e,null,o,"engineering",t);return{tick:i,tickWithUnit:r?l=>`${i(l)} ${r}`:i,unitLabel:n}}const ve=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+ve}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${H(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const j=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Se=/\s*[▾▼]\s*$/,q=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!j(l,t))continue;const s=(l.textContent??"").replace(Se,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!j(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!j(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!j(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}const r=q.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function ke(e){const o=describeCard(e),t=q.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function Q(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ee=new WeakSet;function Le(e){if(ee.has(e))return;ee.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>Q(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&Q(e)})}catch{}}function Ae(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(f,x="400")=>`${x} ${f*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,d=(f,x)=>l?(l.font=x,l.measureText(f).width):f.length*7*n,c=[];let u=0;if(o){u=s,c.push({kind:"text",text:o.title,x:s,y:u+14*n,font:a(16,"600"),alpha:1}),u+=24*n;const f=o.decor,x=[];f?.controls?.length&&x.push({text:f.controls.join(" \xB7 "),alpha:1});for(const m of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)x.push({text:m,alpha:.75});const b=a(12);for(const{text:m,alpha:C}of x){let y="";for(const S of m.split(" ")){const T=y?`${y} ${S}`:S;y&&d(T,b)>r-2*s?(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n,y=S):y=T}y&&(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n)}if(f?.legend?.length){u+=4*n;const m=a(12);let C=s;for(const y of f.legend){const S=14*n+d(y.label,m)+14*n;C>s&&C+S>r-s&&(C=s,u+=18*n),c.push({kind:"dot",x:C+5*n,y:u+7*n,r:5*n,color:y.color}),c.push({kind:"text",text:y.label,x:C+14*n,y:u+11*n,font:m,alpha:1}),C+=S}u+=20*n}if(f?.colorbar){u+=4*n;const m=a(12),C=f.colorbar;let y=s;c.push({kind:"text",text:C.label,x:y,y:u+10*n,font:m,alpha:1}),y+=d(C.label,m)+10*n,c.push({kind:"text",text:C.lo,x:y,y:u+10*n,font:m,alpha:.75}),y+=d(C.lo,m)+6*n,c.push({kind:"strip",x:y,y:u+1*n,w:200*n,h:10*n,color:C.color}),y+=206*n,c.push({kind:"text",text:C.hi,x:y,y:u+10*n,font:m,alpha:.75}),u+=20*n}u+=6*n}i.width=r,i.height=Math.ceil(e.height+u);const p=i.getContext("2d");if(p.fillStyle=o?Ae(o.card):"#ffffff",p.fillRect(0,0,i.width,i.height),o){const f=t.defaultView,x=f&&f.getComputedStyle(o.card).color||"#222222";p.textBaseline="alphabetic";for(const b of c)if(b.kind==="text")p.font=b.font,p.fillStyle=x,p.globalAlpha=b.alpha,p.fillText(b.text,b.x,b.y),p.globalAlpha=1;else if(b.kind==="dot")p.fillStyle=b.color,p.beginPath(),p.arc(b.x,b.y,b.r,0,Math.PI*2),p.fill();else for(let m=0;m<b.w;m++)p.fillStyle=b.color(m/Math.max(1,b.w-1)),p.fillRect(b.x+m,b.y,1,b.h)}return p.drawImage(e,0,u),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&ue(n,o,t)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${$.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ee="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:v.xs,padding:`${v.xs} ${v.md}`,borderRadius:$.pill,border:`1px solid ${g.menuBorder}`,background:"none",cursor:"pointer",fontSize:A.body,color:g.text,whiteSpace:"nowrap"}),O(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?g.iconActive:g.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ee:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.container,padding:v.xl,fontVariantNumeric:"tabular-nums"}}function ne(e){Object.assign(e.style,{..._("outlined"),color:g.label,padding:"0",width:"22px",height:"22px",lineHeight:re.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),O(e)}export function cardShell(e,o,t=document,i={}){const n=t.createElement("div");n.dataset.wmapChartCard="1",n.dataset.wmapChartTitle=e,Object.assign(n.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=n.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:v.sm,paddingBottom:"6px",marginBottom:v.md,borderBottom:`1px solid ${g.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:g.value,fontSize:A.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=Y.expand,a.dataset.wmapCardExpand="1",ne(a),attachChartTip(a,n,s,"Expand"),W(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const d=n.ownerDocument.createElement("button");d.type="button",d.setAttribute("aria-label","Chart actions"),d.innerHTML=Y.more,d.dataset.wmapCardMenu="1",ne(d),attachChartTip(d,n,s,"Chart actions"),D(d,!1),W(d),r.appendChild(d);const c=n.ownerDocument.createElement("div");c.dataset.wmapCardAbout="1",c.setAttribute("role","note"),Object.assign(c.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.md}),W(c);let u;const p=h=>{c.textContent=h?u?.text??"":"",c.style.display=h?"":"none"};let f,x;const b=()=>{const h=f?f():n.querySelector("canvas");h&&saveCanvasPng(h,l.textContent||e,o,{card:n,title:l.textContent||e,decor:ke(n)})},m=()=>{const h=[],M=(E,P,B)=>({label:E,active:!1,action:!0,enabled:!B,disabledHint:B,onClick:()=>{C?.(),P()}});i.png!==!1&&(f||n.querySelector("canvas"))&&h.push(M("Save as PNG",b));for(const E of x?.()??[])h.push(M(E.label,E.onClick,E.disabledHint));if(u){const E=c.style.display!=="none";h.push({label:`About this ${u.noun}`,active:E,onClick:()=>{C?.(),p(!E)}})}return h};let C;d.addEventListener("click",()=>{if(d.getAttribute("aria-expanded")==="true"){C?.();return}const h=m();h.length!==0&&(C=de(d.getBoundingClientRect(),d,h,`${l.textContent||e}: chart actions`,{trigger:d,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(c);const y=n.ownerDocument.createElement("div");y.dataset.wmapPrintOnly="1",Object.assign(y.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.sm}),n.appendChild(y),Le(n.ownerDocument);const S=n.ownerDocument.createElement("div");S.dataset.wmapControls="1",Object.assign(S.style,{display:"flex",gap:v.sm,marginBottom:v.md,flexWrap:"wrap",alignItems:"center"}),W(S),n.appendChild(S);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:S,body:T,setPngDecor:h=>{q.set(n,h)},setPngCanvas:h=>{f=h},setAbout:h=>{u=h,p(!!h&&c.style.display!=="none")},setMenuRows:h=>{x=h}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,oe(e,o)," in the user guide"),i}function oe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:g.iconActive,textDecoration:"underline",cursor:"pointer"}),O(t),t.addEventListener("click",()=>fe(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(oe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,padding:`${v.xs} ${v.sm}`,fontSize:A.body,fontFamily:A.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,o,t,i=document,n=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const l=e.length-1,s=`seg-${Math.random().toString(36).slice(2,9)}`,a=[];return e.forEach(([d,c,u],p)=>{const f=i.createElement("label");u&&U(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:A.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${g.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:p===0?$.control:"0",borderBottomLeftRadius:p===0?$.control:"0",borderTopRightRadius:p===l?$.control:"0",borderBottomRightRadius:p===l?$.control:"0"}),O(f,"bare");const x=i.createElement("input");x.type="radio",x.name=s,x.value=d,x.checked=d===o,Object.assign(x.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const b=()=>{f.style.background=x.checked?g.bgActive:g.menuBg,f.style.color=x.checked?g.iconActive:g.text,f.dataset.on=x.checked?"true":"false"};a.push(b),b(),x.addEventListener("change",()=>{if(x.checked){for(const m of a)m();t(d)}}),f.append(x,i.createTextNode(c)),r.appendChild(f)}),r}const $e=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{..._("outlined"),marginTop:v.sm}),O(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${$e}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{..._("outlined"),background:g.menuBg,color:g.label}),O(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:g.label,fontSize:A.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:d}=i;let c=o;const u=h=>e.find(M=>M.value===h)?.label??"",p=r.createElement("button");p.type="button",d&&(p.dataset.wmapSelect=d),l&&p.setAttribute("aria-label",l),Object.assign(p.style,{fontSize:A.body,padding:`${v.xxs} ${v.sm}`,background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:v.sm,justifyContent:"space-between"}),O(p),D(p,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const x=r.createElement("span");x.textContent="\u25BE",x.style.flex="0 0 auto",p.append(f,x);const b=()=>{f.textContent=e.length===0?s??"(none)":u(c)||s||"(none)"};if(b(),e.length===0)return p.disabled=!0,p.style.opacity="0.6",p.style.cursor="default",Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}});let m=null;const C=()=>{m&&(m.remove(),m=null,D(p,!1))},y=()=>{C(),p.focus()};function S(){const h=p.getBoundingClientRect(),M=r.defaultView??window,E=Math.max(h.width,220),P=Math.min(h.left,Math.max(4,(M.innerWidth??1/0)-E-4));m=r.createElement("div"),m.setAttribute("role","listbox"),m.setAttribute("aria-label",l??"Options"),Object.assign(m.style,{position:"fixed",top:`${h.bottom+4}px`,left:`${P}px`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,boxShadow:G.menu,zIndex:le,minWidth:`${E}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const B=[],N=()=>B.filter(w=>w.row.style.display!=="none").map(w=>w.row),F=[],ie=()=>{for(const w of F)w.el.style.display=B.slice(w.first,w.last+1).some(k=>k.row.style.display!=="none")?"":"none"};if(e.length>X){const w=ce(k=>{for(const L of B)L.row.style.display=L.label.includes(k)?"":"none";ie()},a,r);Object.assign(w.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),w.addEventListener("keydown",k=>{if(k.key==="Escape"){k.preventDefault(),y();return}k.key==="ArrowDown"&&(k.preventDefault(),N()[0]?.focus())}),m.appendChild(w)}let V;for(const w of e){if(w.group!==void 0&&w.group!==V){const R=r.createElement("div");R.textContent=w.group,R.setAttribute("role","presentation"),Object.assign(R.style,{padding:`${v.sm} ${v.xl} ${v.xxs}`,fontSize:A.sub,color:g.label,fontWeight:"600"}),m.appendChild(R),F.push({el:R,first:B.length,last:B.length})}V=w.group;const k=w.value===c,L=r.createElement("div");L.textContent=w.disabled?`${w.label} \u2014 ${w.disabled}`:w.label,L.setAttribute("role","option"),L.setAttribute("aria-selected",k?"true":"false"),w.disabled&&L.setAttribute("aria-disabled","true"),L.tabIndex=-1,Object.assign(L.style,{padding:`${v.sm} ${v.xl}`,fontSize:A.body,cursor:w.disabled?"default":"pointer",color:w.disabled?g.label:k?g.iconActive:g.text,fontWeight:k?"700":"400",opacity:w.disabled?"0.7":"",background:k?g.menuActive:"transparent",whiteSpace:"nowrap"}),L.addEventListener("mouseenter",()=>{!k&&!w.disabled&&(L.style.background=g.menuHover)}),L.addEventListener("mouseleave",()=>{k||(L.style.background="transparent")}),L.addEventListener("click",R=>{R.stopPropagation(),!w.disabled&&(c=w.value,b(),y(),t(w.value))}),m.appendChild(L),B.push({row:L,label:w.label.toLowerCase()}),F.length&&(F[F.length-1].last=B.length-1)}if(ae(m,N,y),se(p).appendChild(m),D(p,!0),e.length<=X){const w=e.findIndex(k=>k.value===c);N()[w>=0?w:0]?.focus()}}p.addEventListener("click",h=>{if(h.stopPropagation(),m){C();return}S()});const T=h=>{if(!p.isConnected){r.removeEventListener("click",T);return}m&&!m.contains(h.target)&&!p.contains(h.target)&&C()};return r.addEventListener("click",T),Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?ye:"")+be(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>t(Number(s)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,d,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,u=>{l=u,s()},i)),d&&e.appendChild(makeToggle("Axis includes limits",a,u=>{n=u,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,u=>{r=u,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const d=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&d===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=d,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const u=s(c);u!==r&&(r=u,i(u))},{...n,hook:"group-scope"}),d=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(c){return r===c||c!==null&&!e.includes(c)?!1:(r=c,d&&(d.value=l(c)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,d)=>({value:String(d),label:a.label??`#${d}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:v.xs,fontSize:A.body,color:g.label,cursor:"pointer",userSelect:"none"}),O(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&U(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=n,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:g.label,fontSize:A.body,display:"flex",alignItems:"center",gap:v.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(d),a}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:v.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:$.control,padding:`${v.sm} ${v.xl}`,fontSize:A.sub,fontFamily:A.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:G.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let d=t-n.left+r,c=i-n.top+r;d+s+l>n.width&&(d=t-n.left-r-s),c+a+l>n.height&&(c=i-n.top-r-a),d=Math.max(l,d),c=Math.max(l,c),e.style.left=`${d}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function I(e,o){const[t,i]=o==="test"?[e?.limitLow,e?.limitHigh]:o==="spec"?[e?.specLow,e?.specHigh]:o==="pat"?[e?.patLow,e?.patHigh]:o==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],n=[];return t!==void 0&&Number.isFinite(t)&&n.push({value:t,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),i!==void 0&&Number.isFinite(i)&&n.push({value:i,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),n}export function hasBothLimitKinds(e){return I(e,"test").length>0&&I(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=I(e,"test"),i=I(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...I(e,"pat"),...I(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:me(o),hi:he(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{K as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,d=0;if(r&&l?.length){const u=K(l);if(u){const p=Math.max(s,u.lo),f=Math.min(a,u.hi);f>p&&(d=l.filter(x=>Number.isFinite(x)&&(x<p||x>f)).length,s=p,a=f)}}if(n)for(const u of i)s=Math.min(s,u.value),a=Math.max(a,u.value);s===a&&(s-=1,a+=1);const c=[];for(const u of i)u.value<s?c.push({value:u.value,label:u.label,side:"lo"}):u.value>a&&c.push({value:u.value,label:u.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:d}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${H(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},d=H(-1)+2;for(const{value:c,label:u,side:p}of o){const f=a[p]++*d,x=i==="horizontal"?p==="lo"?"\u2190":"\u2192":p==="lo"?"\u2193":"\u2191",b=p==="lo"?`${x} ${u} ${r(c)}`:`${u} ${r(c)} ${x}`,m=e.measureText(b).width;if(i==="horizontal"){const C=p==="lo"?t.left+2:t.right-2-m,y={x0:C,x1:C+m,y0:t.top+2+f,y1:t.top+2+f+d},S=s?placeClearOf(s,y,d):y;e.textBaseline="top",e.textAlign=p==="lo"?"left":"right",fillTextOnHalo(e,b,p==="lo"?t.left+2:t.right-2,S.y0,l)}else{const C=p==="lo"?t.bottom-2-f-d:t.top+2+f,y={x0:t.left+4,x1:t.left+4+m,y0:C,y1:C+d},S=s?placeClearOf(s,y,p==="lo"?-d:d):y;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,b,t.left+4,S.y0,l)}}e.restore()}
1
+ import{SHADOW as G,LEADING as re,wireTooltip as U,wireControlHover as O,controlStyle as _,SPACE as v,RADIUS as $,fontPx as D,FONT as A,CLR as g,Z_BASE as le,menuLayerFor as se,wireListNavigation as ae,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as ce,markMenuTrigger as W,markNoPrint as j,openCommandMenu as de,saveImageBlob as ue,openReparentedModal as pe}from"../toolbar.js";import{ICONS as Y}from"../icons.js";import{openGuideAt as fe}from"../guideWindow.js";import{minOf as me,maxOf as he}from"../../core/utils.js";import{robustFence as K}from"../../stats/math.js";import{fmt as ge,fmtColorbarAxis as xe}from"../../renderer/fmt.js";import{markedTestLabel as be,DERIVED_LANE_PAD as ye}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=pe([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:we[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const d=Number(e.dataset.wmapChartFullH);if(!d)return;const c=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(c+d)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const we={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const d=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[i,n,r]=[0,2,4].map(c=>parseInt(d.slice(c,c+2),16)),d.length===8&&(l=parseInt(d.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Ce={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},Z={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(Z)){const n=o.getPropertyValue(`--wmap-${Z[i]}`).trim();t[i]=n||Ce[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${z(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function z(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function J(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(z(e,o)-l)-(t?J(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(z(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=J(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${D(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:ge(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,t){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:i,axisLabel:n,scaledUnit:r}=xe(e,null,o,"engineering",t);return{tick:i,tickWithUnit:r?l=>`${i(l)} ${r}`:i,unitLabel:n}}const ve=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+ve}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${D(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const P=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Se=/\s*[▾▼]\s*$/,q=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!P(l,t))continue;const s=(l.textContent??"").replace(Se,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!P(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!P(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!P(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}const r=q.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function ke(e){const o=describeCard(e),t=q.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function Q(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ee=new WeakSet;function Le(e){if(ee.has(e))return;ee.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>Q(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&Q(e)})}catch{}}function Ae(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(f,x="400")=>`${x} ${f*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,d=(f,x)=>l?(l.font=x,l.measureText(f).width):f.length*7*n,c=[];let u=0;if(o){u=s,c.push({kind:"text",text:o.title,x:s,y:u+14*n,font:a(16,"600"),alpha:1}),u+=24*n;const f=o.decor,x=[];f?.controls?.length&&x.push({text:f.controls.join(" \xB7 "),alpha:1});for(const m of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)x.push({text:m,alpha:.75});const b=a(12);for(const{text:m,alpha:C}of x){let y="";for(const S of m.split(" ")){const T=y?`${y} ${S}`:S;y&&d(T,b)>r-2*s?(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n,y=S):y=T}y&&(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n)}if(f?.legend?.length){u+=4*n;const m=a(12);let C=s;for(const y of f.legend){const S=14*n+d(y.label,m)+14*n;C>s&&C+S>r-s&&(C=s,u+=18*n),c.push({kind:"dot",x:C+5*n,y:u+7*n,r:5*n,color:y.color}),c.push({kind:"text",text:y.label,x:C+14*n,y:u+11*n,font:m,alpha:1}),C+=S}u+=20*n}if(f?.colorbar){u+=4*n;const m=a(12),C=f.colorbar;let y=s;c.push({kind:"text",text:C.label,x:y,y:u+10*n,font:m,alpha:1}),y+=d(C.label,m)+10*n,c.push({kind:"text",text:C.lo,x:y,y:u+10*n,font:m,alpha:.75}),y+=d(C.lo,m)+6*n,c.push({kind:"strip",x:y,y:u+1*n,w:200*n,h:10*n,color:C.color}),y+=206*n,c.push({kind:"text",text:C.hi,x:y,y:u+10*n,font:m,alpha:.75}),u+=20*n}u+=6*n}i.width=r,i.height=Math.ceil(e.height+u);const p=i.getContext("2d");if(p.fillStyle=o?Ae(o.card):"#ffffff",p.fillRect(0,0,i.width,i.height),o){const f=t.defaultView,x=f&&f.getComputedStyle(o.card).color||"#222222";p.textBaseline="alphabetic";for(const b of c)if(b.kind==="text")p.font=b.font,p.fillStyle=x,p.globalAlpha=b.alpha,p.fillText(b.text,b.x,b.y),p.globalAlpha=1;else if(b.kind==="dot")p.fillStyle=b.color,p.beginPath(),p.arc(b.x,b.y,b.r,0,Math.PI*2),p.fill();else for(let m=0;m<b.w;m++)p.fillStyle=b.color(m/Math.max(1,b.w-1)),p.fillRect(b.x+m,b.y,1,b.h)}return p.drawImage(e,0,u),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&ue(n,o,t)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${$.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ee="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:v.xs,padding:`${v.xs} ${v.md}`,borderRadius:$.pill,border:`1px solid ${g.menuBorder}`,background:"none",cursor:"pointer",fontSize:A.body,color:g.text,whiteSpace:"nowrap"}),O(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?g.iconActive:g.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ee:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.container,padding:v.xl,fontVariantNumeric:"tabular-nums"}}function ne(e){Object.assign(e.style,{..._("outlined"),color:g.label,padding:"0",width:"22px",height:"22px",lineHeight:re.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),O(e)}export function cardShell(e,o,t=document,i={}){const n=t.createElement("div");n.dataset.wmapChartCard="1",n.dataset.wmapChartTitle=e,Object.assign(n.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=n.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:v.sm,paddingBottom:"6px",marginBottom:v.md,borderBottom:`1px solid ${g.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:g.value,fontSize:A.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=Y.expand,a.dataset.wmapCardExpand="1",ne(a),attachChartTip(a,n,s,"Expand"),j(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const d=n.ownerDocument.createElement("button");d.type="button",d.setAttribute("aria-label","Chart actions"),d.innerHTML=Y.more,d.dataset.wmapCardMenu="1",ne(d),attachChartTip(d,n,s,"Chart actions"),W(d,!1),j(d),r.appendChild(d);const c=n.ownerDocument.createElement("div");c.dataset.wmapCardAbout="1",c.setAttribute("role","note"),Object.assign(c.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.md}),j(c);let u;const p=h=>{c.textContent=h?u?.text??"":"",c.style.display=h?"":"none"};let f,x;const b=()=>{const h=f?f():n.querySelector("canvas");h&&saveCanvasPng(h,l.textContent||e,o,{card:n,title:l.textContent||e,decor:ke(n)})},m=()=>{const h=[],M=(E,N,B)=>({label:E,active:!1,action:!0,enabled:!B,disabledHint:B,onClick:()=>{C?.(),N()}});i.png!==!1&&(f||n.querySelector("canvas"))&&h.push(M("Save as PNG",b));for(const E of x?.()??[])h.push(M(E.label,E.onClick,E.disabledHint));if(u){const E=c.style.display!=="none";h.push({label:`About this ${u.noun}`,active:E,onClick:()=>{C?.(),p(!E)}})}return h};let C;d.addEventListener("click",()=>{if(d.getAttribute("aria-expanded")==="true"){C?.();return}const h=m();h.length!==0&&(C=de(d.getBoundingClientRect(),d,h,`${l.textContent||e}: chart actions`,{trigger:d,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(c);const y=n.ownerDocument.createElement("div");y.dataset.wmapPrintOnly="1",Object.assign(y.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.sm}),n.appendChild(y),Le(n.ownerDocument);const S=n.ownerDocument.createElement("div");S.dataset.wmapControls="1",Object.assign(S.style,{display:"flex",gap:v.sm,marginBottom:v.md,flexWrap:"wrap",alignItems:"center"}),j(S),n.appendChild(S);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:S,body:T,setPngDecor:h=>{q.set(n,h)},setPngCanvas:h=>{f=h},setAbout:h=>{u=h,p(!!h&&c.style.display!=="none")},setMenuRows:h=>{x=h}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,oe(e,o)," in the user guide"),i}function oe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:g.iconActive,textDecoration:"underline",cursor:"pointer"}),O(t),t.addEventListener("click",()=>fe(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(oe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,padding:`${v.xs} ${v.sm}`,fontSize:A.body,fontFamily:A.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,o,t,i=document,n=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const l=e.length-1,s=`seg-${Math.random().toString(36).slice(2,9)}`,a=[];return e.forEach(([d,c,u],p)=>{const f=i.createElement("label");u&&U(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:A.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${g.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:p===0?$.control:"0",borderBottomLeftRadius:p===0?$.control:"0",borderTopRightRadius:p===l?$.control:"0",borderBottomRightRadius:p===l?$.control:"0"}),O(f,"bare");const x=i.createElement("input");x.type="radio",x.name=s,x.value=d,x.checked=d===o,Object.assign(x.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const b=()=>{f.style.background=x.checked?g.bgActive:g.menuBg,f.style.color=x.checked?g.iconActive:g.text,f.dataset.on=x.checked?"true":"false"};a.push(b),b(),x.addEventListener("change",()=>{if(x.checked){for(const m of a)m();t(d)}}),f.append(x,i.createTextNode(c)),r.appendChild(f)}),r}const $e=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{..._("outlined"),marginTop:v.sm}),O(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${$e}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{..._("outlined"),background:g.menuBg,color:g.label}),O(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:g.label,fontSize:A.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:d}=i;let c=o;const u=h=>e.find(M=>M.value===h)?.label??"",p=r.createElement("button");p.type="button",d&&(p.dataset.wmapSelect=d),l&&p.setAttribute("aria-label",l),Object.assign(p.style,{fontSize:A.body,padding:`${v.xxs} ${v.sm}`,background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:v.sm,justifyContent:"space-between"}),O(p),W(p,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const x=r.createElement("span");x.textContent="\u25BE",x.style.flex="0 0 auto",p.append(f,x);const b=()=>{f.textContent=e.length===0?s??"(none)":u(c)||s||"(none)"};if(b(),e.length===0)return p.disabled=!0,p.style.opacity="0.6",p.style.cursor="default",Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}});let m=null;const C=()=>{m&&(m.remove(),m=null,W(p,!1))},y=()=>{C(),p.focus()};function S(){const h=p.getBoundingClientRect(),M=r.defaultView??window,E=Math.max(h.width,220),N=Math.min(h.left,Math.max(4,(M.innerWidth??1/0)-E-4));m=r.createElement("div"),m.setAttribute("role","listbox"),m.setAttribute("aria-label",l??"Options"),Object.assign(m.style,{position:"fixed",top:`${h.bottom+4}px`,left:`${N}px`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,boxShadow:G.menu,zIndex:le,minWidth:`${E}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const B=[],H=()=>B.filter(w=>w.row.style.display!=="none").map(w=>w.row),F=[],ie=()=>{for(const w of F)w.el.style.display=B.slice(w.first,w.last+1).some(k=>k.row.style.display!=="none")?"":"none"};if(e.length>X){const w=ce(k=>{for(const L of B)L.row.style.display=L.label.includes(k)?"":"none";ie()},a,r,H);Object.assign(w.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),w.addEventListener("keydown",k=>{if(k.key==="Escape"){k.preventDefault(),y();return}k.key==="ArrowDown"&&(k.preventDefault(),H()[0]?.focus())}),m.appendChild(w)}let V;for(const w of e){if(w.group!==void 0&&w.group!==V){const R=r.createElement("div");R.textContent=w.group,R.setAttribute("role","presentation"),Object.assign(R.style,{padding:`${v.sm} ${v.xl} ${v.xxs}`,fontSize:A.sub,color:g.label,fontWeight:"600"}),m.appendChild(R),F.push({el:R,first:B.length,last:B.length})}V=w.group;const k=w.value===c,L=r.createElement("div");L.textContent=w.disabled?`${w.label} \u2014 ${w.disabled}`:w.label,L.setAttribute("role","option"),L.setAttribute("aria-selected",k?"true":"false"),w.disabled&&L.setAttribute("aria-disabled","true"),L.tabIndex=-1,Object.assign(L.style,{padding:`${v.sm} ${v.xl}`,fontSize:A.body,cursor:w.disabled?"default":"pointer",color:w.disabled?g.label:k?g.iconActive:g.text,fontWeight:k?"700":"400",opacity:w.disabled?"0.7":"",background:k?g.menuActive:"transparent",whiteSpace:"nowrap"}),L.addEventListener("mouseenter",()=>{!k&&!w.disabled&&(L.style.background=g.menuHover)}),L.addEventListener("mouseleave",()=>{k||(L.style.background="transparent")}),L.addEventListener("click",R=>{R.stopPropagation(),!w.disabled&&(c=w.value,b(),y(),t(w.value))}),m.appendChild(L),B.push({row:L,label:w.label.toLowerCase()}),F.length&&(F[F.length-1].last=B.length-1)}if(ae(m,H,y),se(p).appendChild(m),W(p,!0),e.length<=X){const w=e.findIndex(k=>k.value===c);H()[w>=0?w:0]?.focus()}}p.addEventListener("click",h=>{if(h.stopPropagation(),m){C();return}S()});const T=h=>{if(!p.isConnected){r.removeEventListener("click",T);return}m&&!m.contains(h.target)&&!p.contains(h.target)&&C()};return r.addEventListener("click",T),Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?ye:"")+be(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>t(Number(s)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,d,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,u=>{l=u,s()},i)),d&&e.appendChild(makeToggle("Axis includes limits",a,u=>{n=u,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,u=>{r=u,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const d=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&d===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=d,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const u=s(c);u!==r&&(r=u,i(u))},{...n,hook:"group-scope"}),d=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(c){return r===c||c!==null&&!e.includes(c)?!1:(r=c,d&&(d.value=l(c)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,d)=>({value:String(d),label:a.label??`#${d}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:v.xs,fontSize:A.body,color:g.label,cursor:"pointer",userSelect:"none"}),O(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&U(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=n,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:g.label,fontSize:A.body,display:"flex",alignItems:"center",gap:v.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(d),a}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:v.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:$.control,padding:`${v.sm} ${v.xl}`,fontSize:A.sub,fontFamily:A.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:G.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let d=t-n.left+r,c=i-n.top+r;d+s+l>n.width&&(d=t-n.left-r-s),c+a+l>n.height&&(c=i-n.top-r-a),d=Math.max(l,d),c=Math.max(l,c),e.style.left=`${d}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function I(e,o){const[t,i]=o==="test"?[e?.limitLow,e?.limitHigh]:o==="spec"?[e?.specLow,e?.specHigh]:o==="pat"?[e?.patLow,e?.patHigh]:o==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],n=[];return t!==void 0&&Number.isFinite(t)&&n.push({value:t,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),i!==void 0&&Number.isFinite(i)&&n.push({value:i,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),n}export function hasBothLimitKinds(e){return I(e,"test").length>0&&I(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=I(e,"test"),i=I(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...I(e,"pat"),...I(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:me(o),hi:he(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{K as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,d=0;if(r&&l?.length){const u=K(l);if(u){const p=Math.max(s,u.lo),f=Math.min(a,u.hi);f>p&&(d=l.filter(x=>Number.isFinite(x)&&(x<p||x>f)).length,s=p,a=f)}}if(n)for(const u of i)s=Math.min(s,u.value),a=Math.max(a,u.value);s===a&&(s-=1,a+=1);const c=[];for(const u of i)u.value<s?c.push({value:u.value,label:u.label,side:"lo"}):u.value>a&&c.push({value:u.value,label:u.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:d}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${D(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},d=D(-1)+2;for(const{value:c,label:u,side:p}of o){const f=a[p]++*d,x=i==="horizontal"?p==="lo"?"\u2190":"\u2192":p==="lo"?"\u2193":"\u2191",b=p==="lo"?`${x} ${u} ${r(c)}`:`${u} ${r(c)} ${x}`,m=e.measureText(b).width;if(i==="horizontal"){const C=p==="lo"?t.left+2:t.right-2-m,y={x0:C,x1:C+m,y0:t.top+2+f,y1:t.top+2+f+d},S=s?placeClearOf(s,y,d):y;e.textBaseline="top",e.textAlign=p==="lo"?"left":"right",fillTextOnHalo(e,b,p==="lo"?t.left+2:t.right-2,S.y0,l)}else{const C=p==="lo"?t.bottom-2-f-d:t.top+2+f,y={x0:t.left+4,x1:t.left+4+m,y0:C,y1:C+d},S=s?placeClearOf(s,y,p==="lo"?-d:d):y;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,b,t.left+4,S.y0,l)}}e.restore()}
@@ -12,6 +12,8 @@ export interface PatCardOptions {
12
12
  }>;
13
13
  testDefs: readonly TestDef[];
14
14
  ownerDocument?: Document;
15
+ /** Back to the maps, coloured by PAT verdict: the button is offered when the host can. */
16
+ showMap?: () => void;
15
17
  }
16
18
  /** The card, or undefined when no test has both limits or no wafer has enough passing dies for PAT limits. */
17
19
  export declare function renderPatCard(o: PatCardOptions): {
@@ -1 +1 @@
1
- import{summarisePat as O}from"../../stats/patSummary.js";import{PAT_K as j,PAT_MIN_DIES as B,PAT_SKEW_WARN as W}from"../../stats/pat.js";import{CLR as d,FONT as f,SPACE as i,controlStyle as L,wireControlHover as D,wireTooltip as T}from"../toolbar.js";import{cardShell as G,firstRowsToggle as _,guideCite as k}from"./chartShell.js";import{GUIDE_SECTIONS as F}from"../../stats/guideSections.js";import{cardAbout as M}from"./cardAbout.js";const $=8,S=(r,o)=>o>0?`${(r/o*100).toFixed(o>=1e3?2:1)}%`:"\u2013";export function renderPatCard(r){const o=O(r.items,r.testDefs);if(!o)return;const s=r.ownerDocument??document,{card:p,body:m,setAbout:x}=G("Part average testing (PAT)",void 0,s);x(M("pat")),p.dataset.wmapPatCard="1",p.style.gridColumn="1 / -1",p.style.flex="0 0 auto";const u=s.createElement("div");u.textContent=`Dynamic limits for each of the ${o.tests} test${o.tests===1?"":"s"} with both limits, set per wafer at the median \xB1 ${j} robust standard deviations (interquartile range \xF7 1.35) of the dies that pass, never wider than the specification limits (the test's own where a test has none), and only where a wafer has ${B} or more passing values. An outlier passes its bin and every test limit but lies outside the PAT limits of at least one test. Overall: ${o.total.outliers.toLocaleString("en-GB")} outlier${o.total.outliers===1?"":"s"} in ${o.total.judged.toLocaleString("en-GB")} dies (${S(o.total.outliers,o.total.judged)}). `,u.append(k(s,F.pat,"How to read this, and how it differs from AEC-Q001"),"."),Object.assign(u.style,{color:d.label,fontSize:f.body,marginBottom:i.sm}),m.appendChild(u);const b=t=>{const e=s.createElement("table");Object.assign(e.style,{borderCollapse:"collapse",width:"100%",fontSize:f.body,fontVariantNumeric:"tabular-nums"});const l=s.createElement("tr");t.forEach(([v,c],A)=>{const h=s.createElement("th");h.scope="col",h.textContent=v,c&&T(h,c),Object.assign(h.style,{textAlign:A===0?"left":"right",padding:`${i.xs} ${i.sm}`,borderBottom:`1px solid ${d.menuBorder}`,color:d.label,fontWeight:"600",whiteSpace:"nowrap"}),l.appendChild(h)});const a=s.createElement("thead");a.appendChild(l);const n=s.createElement("tbody");return e.append(a,n),{table:e,tbody:n}},w=(t,e,l=!1)=>{const a=s.createElement("tr");e.forEach((n,v)=>{const c=s.createElement("td");c.textContent=n,Object.assign(c.style,{padding:`${i.xs} ${i.sm}`,textAlign:v===0?"left":"right",borderBottom:`1px solid ${d.menuBorder}`,whiteSpace:"nowrap",fontWeight:l?"700":"400"}),a.appendChild(c)}),t.appendChild(a)},y=[...o.wafers].sort((t,e)=>e.outliers/e.judged-t.outliers/t.judged||e.outliers-t.outliers),{table:E,tbody:C}=b([["Wafer"],["Dies judged","Dies with a PAT verdict"],["Within","Pass and inside the PAT limits"],["Outliers","Pass every limit and bin, but outside the PAT limits of a test"],["Outlier rate"],["Fail anyway","Fail their bin or a test limit"]]),g=s.createElement("div");g.style.overflowX="auto",g.appendChild(E);const P=_(s,{total:y.length,first:$,noun:"wafers",scroller:g,fill:t=>{C.replaceChildren();for(const e of t?y:y.slice(0,$))w(C,[e.label,e.judged.toLocaleString("en-GB"),e.within.toLocaleString("en-GB"),e.outliers.toLocaleString("en-GB"),S(e.outliers,e.judged),e.fails.toLocaleString("en-GB")],e.outliers>0)}});if(m.append(g,P),r.items.some(t=>t.source)){const t=s.createElement("button");t.type="button",t.textContent="Map the verdicts",t.dataset.wmapPatMaps="1",T(t,"Open a map of each wafer with its dies coloured by PAT verdict: within the limits, outlier, fails anyway"),Object.assign(t.style,{...L("outlined"),marginTop:i.sm,marginLeft:i.sm}),D(t),t.addEventListener("click",()=>{import("../patMaps.js").then(e=>e.openPatMaps({anchor:t,items:r.items,testDefs:r.testDefs})).catch(e=>console.error("[wafermap] The PAT verdict maps could not be drawn:",e))}),m.appendChild(t)}if(o.byTest.length){const t=s.createElement("div");t.textContent="Where the outliers are outside",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const{table:e,tbody:l}=b([["Test"],["Outliers","Outlier dies outside the PAT limits of this test; a die outside on several tests counts for each"]]);for(const a of o.byTest.slice(0,5))w(l,[a.name,a.outliers.toLocaleString("en-GB")]);m.append(t,e)}if(o.skewed.length){const t=s.createElement("div");t.textContent="Lopsided distributions",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const e=s.createElement("div");e.textContent=`The middle half of these tests' values is lopsided (quartile skewness of ${W} or more either way), so limits placed symmetrically about the median sit too close on one side and too far on the other: they flag normal dies on the short side and miss outliers on the long one. Read their counts with care.`,Object.assign(e.style,{color:d.label,fontSize:f.body,marginBottom:i.xs});const{table:l,tbody:a}=b([["Test"],["Wafers lopsided","Wafers where the test is lopsided, of the wafers that have PAT limits for it"],["Most lopsided","Quartile skewness of the most lopsided wafer: positive means a long tail towards high values"]]);for(const n of o.skewed.slice(0,5))w(a,[n.name,`${n.wafers} of ${n.of}`,`${n.worst>0?"+":"\u2212"}${Math.abs(n.worst).toFixed(2)}`]);m.append(t,e,l)}return{card:p,destroy:()=>{}}}
1
+ import{summarisePat as O}from"../../stats/patSummary.js";import{PAT_K as j,PAT_MIN_DIES as B,PAT_SKEW_WARN as W}from"../../stats/pat.js";import{CLR as d,FONT as f,SPACE as i,controlStyle as L,wireControlHover as G,wireTooltip as $}from"../toolbar.js";import{cardShell as D,firstRowsToggle as M,guideCite as _}from"./chartShell.js";import{GUIDE_SECTIONS as k}from"../../stats/guideSections.js";import{cardAbout as F}from"./cardAbout.js";const v=8,T=(l,o)=>o>0?`${(l/o*100).toFixed(o>=1e3?2:1)}%`:"\u2013";export function renderPatCard(l){const o=O(l.items,l.testDefs);if(!o)return;const s=l.ownerDocument??document,{card:p,body:h,setAbout:x}=D("Part average testing (PAT)",void 0,s);x(F("pat")),p.dataset.wmapPatCard="1",p.style.gridColumn="1 / -1",p.style.flex="0 0 auto";const u=s.createElement("div");u.textContent=`Dynamic limits for each of the ${o.tests} test${o.tests===1?"":"s"} with both limits, set per wafer at the median \xB1 ${j} robust standard deviations (interquartile range \xF7 1.35) of the dies that pass, never wider than the specification limits (the test's own where a test has none), and only where a wafer has ${B} or more passing values. An outlier passes its bin and every test limit but lies outside the PAT limits of at least one test. Overall: ${o.total.outliers.toLocaleString("en-GB")} outlier${o.total.outliers===1?"":"s"} in ${o.total.judged.toLocaleString("en-GB")} dies (${T(o.total.outliers,o.total.judged)}). `,u.append(_(s,k.pat,"How to read this, and how it differs from AEC-Q001"),"."),Object.assign(u.style,{color:d.label,fontSize:f.body,marginBottom:i.sm}),h.appendChild(u);const w=t=>{const e=s.createElement("table");Object.assign(e.style,{borderCollapse:"collapse",width:"100%",fontSize:f.body,fontVariantNumeric:"tabular-nums"});const r=s.createElement("tr");t.forEach(([C,c],P)=>{const m=s.createElement("th");m.scope="col",m.textContent=C,c&&$(m,c),Object.assign(m.style,{textAlign:P===0?"left":"right",padding:`${i.xs} ${i.sm}`,borderBottom:`1px solid ${d.menuBorder}`,color:d.label,fontWeight:"600",whiteSpace:"nowrap"}),r.appendChild(m)});const a=s.createElement("thead");a.appendChild(r);const n=s.createElement("tbody");return e.append(a,n),{table:e,tbody:n}},b=(t,e,r=!1)=>{const a=s.createElement("tr");e.forEach((n,C)=>{const c=s.createElement("td");c.textContent=n,Object.assign(c.style,{padding:`${i.xs} ${i.sm}`,textAlign:C===0?"left":"right",borderBottom:`1px solid ${d.menuBorder}`,whiteSpace:"nowrap",fontWeight:r?"700":"400"}),a.appendChild(c)}),t.appendChild(a)},y=[...o.wafers].sort((t,e)=>e.outliers/e.judged-t.outliers/t.judged||e.outliers-t.outliers),{table:E,tbody:S}=w([["Wafer"],["Dies judged","Dies with a PAT verdict"],["Within","Pass and inside the PAT limits"],["Outliers","Pass every limit and bin, but outside the PAT limits of a test"],["Outlier rate"],["Fail anyway","Fail their bin or a test limit"]]),g=s.createElement("div");g.style.overflowX="auto",g.appendChild(E);const A=M(s,{total:y.length,first:v,noun:"wafers",scroller:g,fill:t=>{S.replaceChildren();for(const e of t?y:y.slice(0,v))b(S,[e.label,e.judged.toLocaleString("en-GB"),e.within.toLocaleString("en-GB"),e.outliers.toLocaleString("en-GB"),T(e.outliers,e.judged),e.fails.toLocaleString("en-GB")],e.outliers>0)}});if(h.append(g,A),l.showMap){const t=s.createElement("button");t.type="button",t.textContent="Map the verdicts",t.dataset.wmapPatMaps="1",$(t,"Show the maps with their dies coloured by PAT verdict: within the limits, outlier, fails anyway"),Object.assign(t.style,{...L("outlined"),marginTop:i.sm,marginLeft:i.sm}),G(t),t.addEventListener("click",()=>l.showMap()),h.appendChild(t)}if(o.byTest.length){const t=s.createElement("div");t.textContent="Where the outliers are outside",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const{table:e,tbody:r}=w([["Test"],["Outliers","Outlier dies outside the PAT limits of this test; a die outside on several tests counts for each"]]);for(const a of o.byTest.slice(0,5))b(r,[a.name,a.outliers.toLocaleString("en-GB")]);h.append(t,e)}if(o.skewed.length){const t=s.createElement("div");t.textContent="Lopsided distributions",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const e=s.createElement("div");e.textContent=`The middle half of these tests' values is lopsided (quartile skewness of ${W} or more either way), so limits placed symmetrically about the median sit too close on one side and too far on the other: they flag normal dies on the short side and miss outliers on the long one. Read their counts with care.`,Object.assign(e.style,{color:d.label,fontSize:f.body,marginBottom:i.xs});const{table:r,tbody:a}=w([["Test"],["Wafers lopsided","Wafers where the test is lopsided, of the wafers that have PAT limits for it"],["Most lopsided","Quartile skewness of the most lopsided wafer: positive means a long tail towards high values"]]);for(const n of o.skewed.slice(0,5))b(a,[n.name,`${n.wafers} of ${n.of}`,`${n.worst>0?"+":"\u2212"}${Math.abs(n.worst).toFixed(2)}`]);h.append(t,e,r)}return{card:p,destroy:()=>{}}}
@@ -183,6 +183,8 @@ export interface InsightsTabDeps {
183
183
  * or a test's value map with the dies it fails. Omitted ⇒ the Worth a look cards offer no Show on map.
184
184
  */
185
185
  showOnMap?: (target: SynthesisTarget) => void;
186
+ /** The PAT card's Map the verdicts: back to the maps, coloured by PAT verdict. */
187
+ showPatMap?: () => void;
186
188
  /** See `InsightsOptions.filter` and `onFilterChange`. */
187
189
  filter?: PlotFilter;
188
190
  onFilterChange?: (filter: PlotFilter | undefined) => void;
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as Lt}from"../stats/presentation.js";import{buildFacetTable as Et,facetValueOf as Be,FACET_NONE_VALUE as Tt,DEFAULT_FACET_CURATION as $t}from"../stats/facets.js";import{mergeTestDefs as ke}from"../stats/mergeTestDefs.js";import{isParametricTest as Le}from"../renderer/buildWaferMap.js";import{dieFailsTest as It,hasJudgeableTests as Dt,testsForPassKind as Ot,buildTestPassRateData as At}from"../stats/testPassRate.js";import{fmt as Ve}from"../renderer/fmt.js";import{testLabel as Ye}from"../renderer/testLabel.js";import{waferDisplayLabel as Wt,waferIdentityLabel as Pt}from"../core/waferLabel.js";import{waferPopulation as Rt}from"./chartPopulation.js";import{openDrilldownMenu as Ee}from"./drilldown.js";import{plotStoreFor as Ft}from"./plotStore.js";import{createPageFilter as Mt}from"./pageFilter.js";import{bandButton as Nt}from"./filterButton.js";import{itemPassBins as jt,passBinsLabel as Ge}from"../core/passBins.js";import{describeWaferPopulation as zt,populationStat as Ht}from"../stats/population.js";import{LEADING as Te,ALPHA as Vt,SPACE as O,EDGE_GUTTER as $e,FONT as N,CLR as W,RADIUS as Yt,SHADOW as Gt,controlStyle as _e,wireControlHover as fe,wireTooltip as Ie}from"./toolbar.js";import{ICONS as _t}from"./icons.js";import{renderCapabilityPanel as qt}from"./charts/capability.js";import{renderGroupComparisonPanel as Kt}from"./charts/groupComparison.js";import{renderCommonalityPanel as Ut}from"./charts/commonality.js";import{renderPatCard as Xt}from"./charts/patCard.js";import{renderDifferenceMapPanel as Jt}from"./differenceMapPanel.js";import{renderCorrelationPanel as Qt}from"./charts/correlation.js";import{cardFrameStyle as Zt,makeChartGridWrap as pe,makeLabeledSelect as en,makeLinkedGroupSelect as tn,makeLinkedTestSelect as nn,makeWaferSelect as qe,makeTestSelect as Ke,makeLimitsSelect as sn,makeLinkedAxisPrefs as an,makeToggle as on,limitLines as Ue,limitExtent as rn,shouldIncludeLimitsByDefault as ln,hasBothLimitKinds as Xe}from"./charts/chartShell.js";import{maxOf as dn,minOf as cn}from"../core/utils.js";import{buildYieldData as Je,buildYieldDataCombined as un}from"../stats/yield.js";import{buildLotTestSectionSteps as fn,buildLotFunctionalSection as pn,buildMetadataStripBox as mn}from"./summaryPanel.js";import{runChunked as hn}from"./chunked.js";import{buildRegionYieldData as De,buildRingRegions as Qe,buildQuadrantRegions as Ze,buildReticlePositionRegions as bn,diesInRegion as gn}from"../stats/regions.js";import{renderDataSection as yn}from"./dataTab.js";import{sourceFromDies as wn,toPlotItems as le}from"./plotItems.js";import{isYieldEligibleDie as xn}from"../core/dies.js";import{renderPlotCard as se}from"./plotCard.js";import{orderFieldValues as Cn,axisValues as Sn}from"../stats/plotData.js";import{buildSynthesis as vn,synthesisKey as Bn}from"../stats/synthesis.js";import{commonPassBins as kn}from"../core/passBins.js";import{renderRegionYieldDiagram as Oe}from"./charts/regionYieldDiagram.js";const Ln=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],En={key:"data",label:"Data"},Tn={key:"plot",label:"My plots"};export function createInsightsTab(B){const{getItems:et,getLotStats:Ae,getBinColors:U,getRingCount:V,onSaveImage:P,onSaveText:Y,openWafer:X,focusTest:me,locateDie:ae}=B,de={...$t,...B.attributes},tt=B.showMetadataStrip??!0,J=B.contentInset??$e,c=B.ownerDocument??document,G=c.createElement("div");Object.assign(G.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const nt=$e,Z=c.createElement("div");Object.assign(Z.style,{paddingLeft:nt});const _=c.createElement("div");Object.assign(_.style,{display:"flex",gap:O.xs,alignItems:"center",background:W.menuBg,border:`1px solid ${W.menuBorder}`,borderRadius:Yt.container,boxShadow:Gt.panel,padding:`0 ${O.lg}`,marginBottom:O.lg,marginLeft:J,marginRight:J}),_.setAttribute("role","tablist"),_.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from(_.querySelectorAll('[role="tab"]')),n=t.indexOf(c.activeElement);if(n===-1)return;e.preventDefault();const d=t[(n+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];d.focus(),d.click()});const Q=c.createElement("div");Object.assign(Q.style,{display:"flex",flexDirection:"column",gap:O.lg,marginTop:"0",paddingLeft:J,paddingRight:J});const ce=B.pageFilter??Mt({doc:c,initial:B.filter,onChange:B.onFilterChange,attributes:B.attributes,getRingCount:B.getRingCount}),We=ce.createBand(()=>xe(),{marginLeft:J,marginRight:J,marginBottom:O.lg}),st=We.el;G.appendChild(Z),G.appendChild(_),G.appendChild(st),G.appendChild(Q);const at=[...Ln,En,Tn],ee=B.plotStore??Ft(B),te=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:n})=>n({doc:c,anchor:G,store:ee,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:P,binColors:U()}}))};let z=B.defaultView==="sweeps"?"plot":B.defaultView??"overview",F,he=!1;ce.subscribe(()=>q());let Pe="statistics",Re="wide",H=null,Fe=null,be=[],R=null,ge=B.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ye=new Map,we=(e,t,n=!1)=>{ge=e;for(const d of ye.values())for(const u of d)u!==t&&u.setAxisPrefs(e);n||B.onAxisPrefsChange?.(e)},ie=e=>{R!==e&&(R=e,q())};let ne=new Map;function Me(){for(const e of ne.values())e.destroy();ne=new Map}function Ne(e,t,n){X?.(e,t,n)}function ue(e){return(t,n,d)=>{const u=e.find(f=>f.waferIndex===t);if(!u)return;d.preventDefault();const h=Rt(u.dies,{waferLabel:u.identity,testDefs:u.testDefs,activeTest:n??H??void 0,waferIndex:t,wafer:u.wafer,passBins:u.passBins,ringCount:V()});Ee({x:d.clientX,y:d.clientY},d.target,h,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}}function it(e,t,n,d,u){oe({x:e.clientX,y:e.clientY},e.target,t,n,d,u)}function oe(e,t,n,d,u,h){const f=wn(n.map(r=>({label:r.identity??r.label,dies:r.dies,waferIndex:r.waferIndex,wafer:r.wafer,passBins:r.passBins,ringCount:V()})),d,u,ke(n).defs,h);f&&Ee(e,t,f,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}function je(e){return X?{open:(t,n)=>Ne(t,`Wafer ${e.find(d=>d.waferIndex===t)?.label??t}`,n)}:me&&e.length===1?{open:(t,n)=>me(n),label:"show this test on the map"}:null}function xe(){return et().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Wt(e,t),identity:Pt(e),waferIndex:t,passBins:jt(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function ot(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${W.iconActive}`:"2px solid transparent",color:t?W.iconActive:W.label,fontWeight:t?"700":"500",fontSize:N.body,padding:`${O.sm} ${$e} ${O.md}`,cursor:"pointer",marginBottom:"-1px"})}function rt(e,t){const n=c.createElement("button");n.type="button",n.textContent=t;const d=e===z;return ot(n,d),n.dataset.on=d?"true":"false",fe(n,"bare"),n.dataset.wmapInsightsTab=e,n.setAttribute("role","tab"),n.setAttribute("aria-selected",d?"true":"false"),n.tabIndex=d?0:-1,n.addEventListener("click",()=>{z!==e&&(z=e,q({keepSections:!0}))}),n}function lt(e,t,n,d=!0){const u=pe(c),h=U(),f=n??"group",r=Ge(e.map(m=>m.passBins)),g=le(e.map(m=>({label:m.identity??m.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:m.dies,waferIndex:m.waferIndex,wafer:m.wafer,passBins:m.passBins,ringCount:V()}))),p=ke(e).defs,o=t?F:void 0,l={testDefs:p,groupBy:o,curation:B.attributes},b=(m,x)=>({id:"card-yield",title:t?`Yield by ${f} (pass: ${r})`:`Yield by wafer (pass: ${r})`,chart:"bar",fields:{x:{slot:"groupBy"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...m?{sort:"value"}:{},...x>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),k=t?t.length:e.length;let C=null;d&&(C=se({doc:c,editAsPlot:te,items:g,ctx:l,spec:{choices:[{current:"natural",options:m=>[["value","Sort: yield"],["natural",t&&!m?`Sort: ${f}`:"Sort: wafer"]]}],build:([m])=>b(m==="value",k)},drill:t&&o?m=>{const x=Be(g[m[0]?.item]?.metadata,o,B.attributes);if(x===void 0)return null;const E=t.find(i=>i.key===x)?.items.length??0;return i=>({...i,title:`Yield by wafer \u2014 ${f}: ${x} (pass: ${r})`,fields:{...i.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:o},values:[x]}]},axes:E>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:"see its wafers",chart:{onSaveImage:P,onOpenWafer:X?m=>Ne(g[m].waferIndex??m,`Wafer ${g[m].label}`):void 0,onWaferMenu:ue(e)}}),C.card.style.minHeight="360px",u.appendChild(C.card));const L={current:"hbin",options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]]},w={current:"share",options:[["count","Counts"],["share",`Share of ${f}`,`Each ${f}\u2019s dies in a bin as a share of all its dies, so ${f} values of different sizes compare`]]},S=(m,x)=>({id:"card-bin-pareto",title:`${m==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:m==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:m==="sbin"?"sbin":"hbin"}},...t?x==="share"?{barNorm:"percent"}:{}:{cumulative:!0}}),a=se({doc:c,editAsPlot:te,items:g,ctx:l,spec:t?{choices:[L,w],build:([m,x])=>S(m,x)}:{choices:[L],build:([m])=>S(m,void 0)},chart:{onSaveImage:P,binColors:h,onSelectPoints:(m,x,E,i)=>{const v=a.current().fields.x,s=v&&!Array.isArray(v)&&"builtin"in v&&v.builtin==="sbin"?"sbin":"hbin",y=new Set(m.map(T=>s==="hbin"?T.die?.hbin:T.die?.sbin));if(y.size!==1)return;const $=[...y][0],A=t?i?.group:void 0,I=A!==void 0?t?.find(T=>T.key===A)?.items??[]:e;oe(x,E,I,`in ${s==="hbin"?"hard":"soft"} bin ${$}${A!==void 0?` of ${A}`:""}`,T=>xn(T)&&(s==="hbin"?T.hbin:T.sbin)===$)}}});return a.card.style.minHeight="360px",u.appendChild(a.card),{card:u,destroy:()=>{C?.destroy(),a.destroy()}}}function Ce(){const e=c.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Zt(),display:"flex",flexDirection:"column",gap:O.lg,minWidth:"0"}),e}function dt(e){if(Z.innerHTML="",Z.style.marginBottom="0",!tt)return;const t=mn(e.map(n=>({metadata:n.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",Z.appendChild(t),Z.style.marginBottom=O.xs)}function ct(e,t,n,d){if(!e.length)return{elements:[],destroy:()=>{}};const u=e.map(w=>w.wafer),h=e.map(w=>w.dies),f=V(),r=[],g=[],p=d??[{key:"",items:e}],o=e.flatMap(w=>w.dies),l=["spec","testFlag","functional"].filter(w=>Dt(n,w,o));if(l.length){const w={spec:{label:"Test limits",hint:"Judged from each die\u2019s measured value against the test\u2019s limits",title:"Parametric pass rate \xB7 test limits"},testFlag:{label:"Tester flag",hint:"The pass or fail the tester recorded for each die",title:"Parametric pass rate \xB7 tester flag"},functional:{label:"Functional",hint:"Tests that only pass or fail and have no measured value",title:"Functional test pass rate"}},S=!!d,a=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:f}))),m=i=>({id:`card-pass-rate-${i}`,title:w[i].title,chart:"bar",orientation:"horizontal",sort:"ascending",fields:{x:{builtin:"test"},y:{tests:Ot(n,i).map(v=>v.testNumber),passRate:!0,...i==="testFlag"?{judge:"flag"}:{}},color:S?{follow:"groupBy"}:{none:!0}},...S?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}}),x=i=>i.id.slice(15),E=se({doc:c,editAsPlot:te,items:a,ctx:{testDefs:n,groupBy:S?F:void 0,curation:B.attributes},spec:l.length>1?{choices:[{current:l[0],options:l.map(i=>[i,w[i].label,w[i].hint])}],build:([i])=>m(i)}:m(l[0]),notes:i=>{const v=x(i);if(v==="functional")return[];const s=At(p.map(y=>({key:y.key,items:y.items.map($=>({dies:$.dies}))})),n,v).disagreementDies;return s?[`${s.toLocaleString("en-GB")} die${s===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:P,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(i,v,s,y)=>{const $=n.find(T=>T.testNumber===y?.test);if(!$)return;const A=x(E.current()),I=y?.group!==void 0?p.find(T=>T.key===y.group)?.items??e:e;oe(v,s,I,`failing ${Ye($,$.testNumber)}${y?.group!==void 0?` in ${y.group}`:""}`,T=>It(T,$,A)===!0,Le($)?$.testNumber:void 0)}}});E.card.style.minHeight="300px",r.push(E.card),g.push(E.destroy)}const b=w=>(S,a)=>{const m=new Set;for(const x of e)for(const E of gn(x.dies,x.wafer,f,S.key,w))m.add(E);it(a,e,`in ${S.label}`,x=>m.has(x))},k=De(h,u,f,w=>e[w].passBins,Qe);if(k.length){const w=Oe({title:"Ring yield",mode:"ring",rows:k,onSelectRegion:b(Qe),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const C=De(h,u,f,w=>e[w].passBins,Ze);if(C.length){const w=Oe({title:"Quadrant yield",mode:"quadrant",rows:C,onSelectRegion:b(Ze),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const L=u.find(w=>w.reticle!==void 0)?.reticle;if(L){const w=(a,m)=>bn(a,m.reticle),S=De(h,u,f,a=>e[a].passBins,w);if(S.length){const a=Oe({title:"Reticle cell yield",mode:"reticleCell",rows:S,grid:{width:Math.max(1,Math.floor(L.width)),height:Math.max(1,Math.floor(L.height))},onSelectRegion:b(w),onSaveImage:P,ownerDocument:c});r.push(a.card),g.push(a.destroy)}}return{elements:r,destroy:()=>{for(const w of g)w()}}}function ut(e,t,n){if(!e.length)return{cards:[],destroy:()=>{}};const d=e.map(l=>l.dies),u=e.flatMap(l=>l.dies),h=e.map(l=>l.statsSummary),f=h.every(l=>l!==void 0)?h:void 0,r=[],g=[];let p=null;if(t.length){const l=Ce();let b=null;const k=hn(fn(u,t,void 0,f,Y,d.map(C=>({dies:C})),void 0,"full"),{onDone:C=>{b=C,l.removeAttribute("aria-busy"),C?l.replaceChildren(C):l.remove()}});if(k.done)b&&(p=l);else{const C=c.createElement("div");C.textContent="Computing test statistics\u2026",Object.assign(C.style,{color:W.label,fontSize:N.body}),l.setAttribute("aria-busy","true"),l.appendChild(C),p=l,r.push(()=>k.cancel())}}let o=null;if(n.length){const l=pn(u,n,f,Y);if(l){const b=Ce();b.appendChild(l),o=b}}return p&&g.push(p),o&&g.push(o),{cards:g,destroy:()=>{for(const l of r)l()}}}function ft(e){const t=Ge(e.map(p=>p.passBins)),n=e.length===1,d=e[0],u=Ce();Object.assign(u.style,{flexDirection:"row",flexWrap:"wrap",gap:O.md});const h=p=>{const o=p.lastElementChild;return o&&Object.assign(o.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),p};function f(p,o,l){const b=c.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:O.sm,paddingRight:O.xxl,marginRight:O.md,borderRight:`1px solid ${W.menuBorder}`});const k=c.createElement("div");k.textContent=p,Object.assign(k.style,{fontSize:N.heading,fontWeight:"700",color:W.value,lineHeight:Te.tight});const C=c.createElement("div");if(C.textContent=o,Object.assign(C.style,{fontSize:N.body,color:W.label}),b.append(k,C),l){const L=c.createElement("div");L.textContent=l,Object.assign(L.style,{fontSize:N.meta,color:W.label,opacity:Vt.muted}),b.appendChild(L)}return b}if(n){const p=Je([{...d,key:d.waferIndex}])[0]?.percent;return p!==void 0&&u.appendChild(f(`${p.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),u.appendChild(f(String(d.dies.length),"Total dies")),h(u)}u.appendChild(f(String(e.length),"Wafers"));const r=Je(e.map(p=>({...p,key:p.waferIndex}))).map(p=>p.percent).filter(p=>Number.isFinite(p));if(r.length){const p=r.reduce((b,k)=>b+k,0)/r.length,o=un([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,l=o!==void 0&&o.toFixed(1)!==p.toFixed(1);u.appendChild(f(`${p.toFixed(1)}%`,`${Lt} \xB7 pass: ${t}`,l?`${o.toFixed(1)}% by dies`:void 0))}const g=e.map(p=>p.statsSummary);if(g.every(p=>p!==void 0)){const p=g.reduce((l,b)=>l+b.stats.analyzedDies,0),o=g.reduce((l,b)=>l+b.stats.excludedDies,0);u.appendChild(f(p.toLocaleString(),"Dies analysed",o?`${o.toLocaleString()} excluded`:void 0))}else u.appendChild(f(e.reduce((p,o)=>p+o.dies.length,0).toLocaleString(),"Total dies"));return h(u)}function pt(e,t,n,d,u){const h=c.createElement("div");Object.assign(h.style,{display:"flex",flexDirection:"column",gap:O.lg});const f=e.length===1&&!d;e.length&&!d&&h.appendChild(ft(e));const r=lt(e,d,u,!f);h.appendChild(r.card);const g=ct(e,t,n,d);for(const l of g.elements)r.card.appendChild(l);const p=mt(e,n);if(p&&h.appendChild(p.el),e.length>=4&&be.length){const l=Ut({wafers:e,fields:be,curation:de,groupedBy:F,onGroupBy:b=>{F=b,R=null,q()},ownerDocument:c});h.appendChild(l.card)}const o=Xt({items:e.map(l=>({...l,ringCount:V()})),testDefs:n,ownerDocument:c});return o&&h.appendChild(o.card),h.appendChild(ht()),{card:h,destroy:()=>{r.destroy(),g.destroy(),p?.destroy()}}}function mt(e,t){const n=Ae?.()??(e.length===1?e[0].statsSummary:void 0);if(!n)return null;const d=c.createElement("section");d.dataset.wmapWorthALook="1",Object.assign(d.style,{display:"flex",flexDirection:"column",gap:O.md});const u=c.createElement("h3");u.textContent="Worth a look",Object.assign(u.style,{margin:"0",fontSize:N.heading,fontWeight:"600",color:W.value}),d.appendChild(u);const h=(o,l)=>{const b=c.createElement("p");b.textContent=o,l&&(b.dataset[l]="1"),Object.assign(b.style,{margin:"0",fontSize:N.body,color:W.label,lineHeight:Te.base}),d.appendChild(b)};if(he||R!==null)return h("Worth a look describes the whole lot, as What stands out beside the map does. Switch the filter off, or Show all groups, to see it here.","wmapWorthNarrowed"),{el:d,destroy:()=>{}};const f=vn(n,{passBins:kn(e.map(o=>o.passBins)),attributes:B.attributes});if(f.items.length===0)return h(f.nothing??"Nothing stands out.","wmapWorthNothing"),{el:d,destroy:()=>{}};const r=pe(c);d.appendChild(r);const g=le(e.map(o=>({label:o.identity??o.label,dies:o.dies,waferIndex:o.waferIndex,wafer:o.wafer,passBins:o.passBins,ringCount:V()}))),p=[];if(f.items.forEach((o,l)=>{const b=c.createElement("div");b.dataset.wmapWorthWhy="1",b.textContent=`Shown because: ${o.reason}`,o.text!==o.reason&&Ie(b,o.text),Object.assign(b.style,{flexBasis:"100%",fontSize:N.body,color:W.text,lineHeight:Te.base});const k=[b];if(B.showOnMap){const L=c.createElement("button");L.type="button",L.textContent="Show on map",L.dataset.wmapWorthShowOnMap="1",Object.assign(L.style,{..._e("outlined"),fontSize:N.body,padding:`0 ${O.md}`}),fe(L),Ie(L,"Leave Insights and show this on the map, as its row in What stands out does"),L.addEventListener("click",()=>B.showOnMap(o.target)),k.push(L)}const C=se({doc:c,items:g,ctx:{testDefs:t,curation:de},spec:{id:`worth-${l}`,...o.chart},extras:k,editAsPlot:te,chart:{onSaveImage:P}});C.card.dataset.wmapWorthKey=Bn(o),r.appendChild(C.card),p.push(C.destroy)}),f.also){const o=f.also.items.map(l=>l.brief).join("; ");h(`Also: ${o}${f.also.more?`; and ${f.also.more} more`:""}. Their rows in What stands out show them on the map.`,"wmapWorthAlso")}return{el:d,destroy:()=>p.forEach(o=>o())}}function ht(){const e=c.createElement("div");Object.assign(e.style,{fontSize:N.body,color:W.label});const t=c.createElement("button");return t.type="button",t.textContent="Data tab",t.dataset.wmapOpenDataTab="1",Object.assign(t.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:W.iconActive,textDecoration:"underline"}),fe(t,"bare"),t.addEventListener("click",()=>{z="data",q({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",t,"."),e}function bt(e,t,n,d){const u=c.createElement("div");u.style.width="100%";let h,f=!1;return import("./plotTab.js").then(({createPlotSection:r})=>{if(f)return;const g=r({doc:c,store:ee,items:e,testDefs:t,ringCount:V(),attributes:B.attributes,groupBy:n,groupLabel:d,onSaveImage:P,onSaveText:Y,getBinColors:U,waferMenu:ue(e),openWafer:X?(p,o,l)=>X(p,o,l):void 0,focusTest:me,locateDie:ae,pickPlotsFile:B.onPickPlotsFile});u.appendChild(g.card),h=g}),{card:u,destroy:()=>{f=!0,h?.destroy()}}}function gt(e,t,n,d,u){const h=he?void 0:Ae?.(),f=()=>{ne.get("data")?.destroy(),ne.delete("data"),q({keepSections:!0})};return yn({doc:c,items:e,testDefs:t,allTestDefs:n,groups:d,groupLabelText:u,ringCount:V(),attributes:B.attributes,yieldByWaferIndex:new Map(h?.lotYieldSeries.map(r=>[r.waferIndex,r.yieldPercent])),onSaveText:Y,onLocateDie:ae,onOpenWafer:X?(r,g)=>X(r,g):void 0,buildStatistics:r=>ut(r,t,n),view:Pe,onViewChange:r=>{Pe=r,f()},diesLayout:Re,onDiesLayoutChange:r=>{Re=r}})}function ze(e,t){const n=c.createElement("h3");return n.textContent=e,n.dataset.wmapRowHeading=t,Object.assign(n.style,{gridColumn:"1 / -1",margin:`${O.md} 0 0`,color:W.value,fontSize:N.heading,fontWeight:"600"}),n}function yt(e,t,n,d){const u=pe(c),h=je(e),f=le(e.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:V()}))),r=t.filter(s=>s.testNumber!==void 0),g=!!n&&!!F,p=g&&R!==null,o={testDefs:t,groupBy:g?F:void 0,curation:B.attributes},l=(s,y,$)=>({limits:y.limits??"both",axes:{[s]:{...y.includeLimits!==void 0?{includeLimits:y.includeLimits}:{},...y.clipOutliers?{clip:!0}:{},...$?{scale:"log"}:{}}}});function b(s){let y=ge,$=!1,A;const I=nn(r,H??r[0]?.testNumber??null,j=>{A?.refresh(),m(j)},{ownerDocument:c}),T=c.createElement("span");Object.assign(T.style,{display:"inline-flex",flexWrap:"wrap",gap:O.sm,alignItems:"center"});const D={setAxisPrefs:j=>{K.set(j)&&(y=j,A?.refresh())}},K=an(T,y,j=>{y=j,A?.refresh(),we(j,D)},c),re=[I.el,T];s.logToggle&&re.push(on("Log scale",$,j=>{$=j,A?.refresh()},c,"Draw the value axis on a logarithmic scale")),re.push(...s.extras??[]),A=se({doc:c,editAsPlot:te,items:f,ctx:o,...s.card,spec:{choices:[],build:()=>s.build(y,$)},slots:()=>({test:I.get()??void 0}),extras:re,onResolved:j=>{const Se=t.find(kt=>kt.testNumber===I.get()),He=Ue(Se,y.limits),ve=Sn(j,s.valueRole),{lo:St,hi:vt}=rn(He),Bt=ve.length>0&&He.length>0&&ln(cn(ve),dn(ve),St,vt);K.sync(y.includeLimits??Bt,Ue(Se).length>0,Xe(Se))},chart:s.chart});const M=A;return{card:M.card,setTest:j=>{I.set(j)&&M.refresh()},refresh:()=>M.refresh(),setAxisPrefs:D.setAxisPrefs,destroy:()=>M.destroy()}}const k=h?(s,y)=>h.open(f[s]?.waferIndex??s,y??H??r[0]?.testNumber??0):void 0,C=b({valueRole:"y",logToggle:!0,build:(s,y)=>({id:"card-box",title:"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:g&&!p?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:{none:!0}},...p?{where:{conditions:[{field:{meta:F},values:[R]}]}}:{},...l("y",s,y)}),card:{...g&&!p?{drill:s=>{const y=Be(f[s[0]?.item]?.metadata,F,B.attributes);return y!==void 0&&ie(y),null},drillLabel:"see its wafers"}:{},...R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{}},chart:{onSaveImage:P,onOpenWafer:k,openActionLabel:h?.label,onWaferMenu:ue(e)}});let L=null;const w=g?[]:[qe(f.map(s=>({label:s.label})),null,s=>{L=s,S.refresh()},{ownerDocument:c})],S=b({valueRole:"x",extras:w,card:R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{},build:s=>({id:"card-histogram",title:"Value histogram",chart:"histogram",fields:{y:{slot:"test"},color:g?{follow:"groupBy"}:{none:!0}},...L!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[L].label]}]}}:{},...l("x",s,!1)}),chart:{onSaveImage:P,...g?{onLegendPick:s=>ie(s),legendPicked:R}:{},onSelectPoints:(s,y,$,A)=>{const I=t.find(M=>M.testNumber===(H??r[0]?.testNumber)),T=new Set(s.map(M=>M.die).filter(M=>!!M)),D=new Set(s.map(M=>f[M.item]?.waferIndex)),K=A?.range,re=I&&K?`with ${Ye(I,I.testNumber)} from ${Ve(K.lo,I.unit,"engineering")} to ${Ve(K.hi,I.unit,"engineering")}${A?.group?` in ${A.group}`:""}`:"selected in the histogram";oe(y,$,e.filter(M=>D.has(M.waferIndex)),re,M=>T.has(M),I?.testNumber)}}}),a=b({valueRole:"y",build:s=>({id:"card-trend",title:"Wafer-to-wafer trend",chart:"line",aggregate:"mean",spread:"sd",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:{none:!0}},...l("y",s,!1),axes:{...l("y",s,!1).axes,y:{...l("y",s,!1).axes.y,references:[{stat:"mean",label:Ht(zt(e.map(y=>y.wafer.metadata)),"mean")}]}}}),card:{ctx:{...o,groupBy:void 0},...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:P,onWaferMenu:ue(e),selectActionLabel:k?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(s,y,$)=>{const A=new Set(s.map(D=>D.item));if(A.size===1&&k){k([...A][0]);return}const I=new Set(s.map(D=>D.die).filter(D=>!!D)),T=new Set(s.map(D=>f[D.item]?.waferIndex));oe(y,$,e.filter(D=>T.has(D.waferIndex)),"selected in the trend",D=>I.has(D),H??void 0)}}}),m=s=>{H=s,C.setTest(s),S.setTest(s),a.setTest(s),v.setTest(s),E?.setTest(s),i?.setTest(s)},x=()=>Kt({groups:n,testDefs:t,groupLabelText:d,control:Fe,onControlChange:s=>{Fe=s;const y=x();E.card.replaceWith(y.card),E=y},selectedTestNumber:H??void 0,onSelectTest:s=>m(s),onSaveText:Y,ownerDocument:c});let E=n&&n.length>=2?x():void 0;const i=n&&n.length>=2?Jt({groups:n,testDefs:t,groupLabelText:d,selectedTestNumber:H??void 0,onSaveImage:P,ownerDocument:c}):void 0;ye.set("distribution",[C,S,a]);const v=qt({title:"Process capability",items:e,testDefs:t,onSaveImage:P,selectedTestNumber:H??void 0,onSelectTest:s=>m(s),ownerDocument:c});return(E||i)&&(u.append(ze(`Comparing ${d??"groups"}`,"comparing")),E&&u.append(E.card),i&&u.append(i.card),u.append(ze("Test by test","tests"))),u.append(v.card,C.card,S.card,a.card),{card:u,destroy:()=>{v.destroy(),C.destroy(),S.destroy(),a.destroy(),E?.destroy(),i?.destroy()}}}function wt(e,t,n){const d=pe(c),u=je(e),h=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:V()}))),f=t.filter(i=>i.testNumber!==void 0&&Le(i));let r=f[0]?.testNumber,g=f[1]?.testNumber??r,p=null,o=ge;const l=!!n&&!!F,b=(i,v)=>{const s=c.createElement("label");Object.assign(s.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:N.body,color:W.label});const y=c.createElement("span");return y.textContent=i,s.append(y,v),s},k=Ke(f,r??null,i=>{r=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),C=Ke(f,g??null,i=>{g=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),L=c.createElement("span"),w={setXY:(i,v)=>{r=i,g=v,k.value=String(i),C.value=String(v),S(),x.refresh()},setAxisPrefs:i=>{o=i,S(),x.refresh()},destroy:()=>x.destroy()};function S(){const i=[r,g].map(v=>t.find(s=>s.testNumber===v));L.replaceChildren(...i.some(Xe)?[sn(o.limits??"both",v=>{o={...o,limits:v},x.refresh(),we(o,w)},c)]:[])}const a=i=>{const v=t.find(s=>s.testNumber===i);return v?.name?{test:i??0,name:v.name}:{test:i??0}},m=[b("X:",k),b("Y:",C),L];!l&&e.length>1&&m.push(qe(h.map(i=>({label:i.label})),null,i=>{p=i,x.refresh()},{ownerDocument:c}));const x=se({doc:c,editAsPlot:te,items:h,ctx:{testDefs:t,groupBy:l?F:void 0,curation:B.attributes},extras:m,spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:o.limits??"both",fields:{x:a(r),y:a(g),color:l?{follow:"groupBy"}:{builtin:"hbin"}},...p!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[h[p].label]}]}}:{}})},...r===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:P,binColors:U(),onOpenWafer:u?(i,v)=>u.open(h[i]?.waferIndex??i,v??r??0):void 0,openActionLabel:u?.label,onSelectPoints:(i,v,s)=>{const y=new Map;for(const I of i){const T=h[I.item]?.waferIndex;if(T===void 0||!I.die)continue;const D=y.get(T);D?D.push(I.die):y.set(T,[I.die])}const $=[...y].flatMap(([I,T])=>{const D=e.find(K=>K.waferIndex===I);return D?[{label:D.identity??D.label,dies:T,waferIndex:I,wafer:D.wafer,passBins:D.passBins,ringCount:V()}]:[]});if($.length===0)return;const A=$.length===1?`selected on ${$[0].label} in the scatter`:`selected in the scatter, across ${$.length} wafers`;Ee(v,s,{items:$,population:A,testDefs:t,activeTest:r},{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:ae})}}});S(),ye.set("correlation",[w]);const E=Qt({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:P,onSaveText:Y,onSelectPair:(i,v)=>w.setXY(i,v),ownerDocument:c});return d.append(E.card,x.card),{card:d,destroy:()=>{E.destroy(),w.destroy()}}}const xt=(e,t,n,d)=>Nt(c,e,t,n,d),Ct=()=>ce.openEditor(G,xe());function q(e){e?.keepSections||Me(),Q.innerHTML="",_.innerHTML="";for(const a of at)_.appendChild(rt(a.key,a.label));const t=xe(),n=ce.keep(t),d=n.items;he=n.narrowing,We.refresh(n.result,t),dt(d);const u=Et(d,{facetableOnly:!0,curation:de}).filter(a=>a.splittable);be=u.map(a=>({key:a.key,label:a.label}));const h=c.createElement("div");Object.assign(h.style,{display:"flex",gap:O.md,alignItems:"center",marginLeft:O.xxl,paddingBottom:O.xs}),B.showFilterButton!==!1&&h.appendChild(xt("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>Ct()));let f;u.length>0?(h.appendChild(en("Group by:",[{value:"",label:"None"},...u.map(a=>({value:a.key,label:`${a.label} (${a.values.length})`}))],F??"",a=>{F=a||void 0,R=null,q()},{hook:"group-by",ownerDocument:c})),f=u.find(a=>a.key===F)?.label):F=void 0;let r;if(F){const a=new Map,m=[];for(const x of d){const E=Be(x.metadata,F,de)??Tt;a.has(E)||(a.set(E,[]),m.push(E)),a.get(E).push(x)}r=Cn(m).map(x=>({key:x,items:a.get(x)}))}R!==null&&!r?.some(a=>a.key===R)&&(R=null),r&&r.length>0&&h.appendChild(tn(r.map(a=>a.key),"Show:",R,a=>ie(a),{ownerDocument:c}).el);let g=null;if(B.onOpenGuide){const a=c.createElement("button");a.type="button",a.innerHTML=_t.help,a.setAttribute("aria-label","User guide"),Object.assign(a.style,{..._e("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),fe(a,"bare"),Ie(a,"User guide"),a.addEventListener("click",()=>B.onOpenGuide()),Object.assign(a.style,{marginLeft:"auto"}),g=a}_.appendChild(h),g&&_.appendChild(g);const p=R!==null?r?.find(a=>a.key===R):void 0,o=p?.items??d,l=p?void 0:r,b=ke(o),k=b.defs,C=k.filter(Le);if(H!==null&&!C.some(a=>a.testNumber===H)&&(H=null),d.length===0){const a=c.createElement("div");a.dataset.wmapInsightsFilterEmpty="1",a.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(a.style,{color:W.label,fontSize:N.body,padding:O.xl}),Q.appendChild(a);return}const L=e?.keepSections?ne.get(z):void 0,w=L??(z==="overview"?pt(o,C,k,l,f):z==="distributions"?yt(o,C,l,f):z==="data"?gt(o,C,k,l,f):z==="plot"?bt(o,k,p?void 0:F,p?void 0:f):wt(o,C,l));L||ne.set(z,w);const S=b.conflicts.filter(a=>a.excluded);if(S.length>0){const a=c.createElement("div");Object.assign(a.style,{color:W.label,fontSize:N.body,padding:`0 ${J} ${O.sm}`});const m=S.slice(0,6).map(i=>i.testNumber).join(", "),x=S.length>6?`, and ${S.length-6} more`:"",E=S.length===1?"it":"them";a.textContent=`${S.length} test ${S.length===1?"number is":"numbers are"} hidden (${m}${x}) \u2014 the wafers in view describe ${E} differently, so their values cannot be pooled. `+(r&&r.length>0?`Pick one ${f??"group"} under "Show:" to analyse ${E}.`:"Load one test program at a time to analyse them."),a.dataset.wmapWithheldTests=String(S.length),Q.appendChild(a)}Q.appendChild(w.card)}return{el:G,render:q,destroy:()=>{Me(),ee.flush(),G.remove()},setAxisPrefs:e=>we(e,null,!0),showWorthCard:e=>{z!=="overview"&&(z="overview",q({keepSections:!0}));const t=[...Q.querySelectorAll("[data-wmap-worth-key]")].find(u=>u.dataset.wmapWorthKey===e);if(!t)return!1;const n=c.defaultView,d=()=>t.scrollIntoView({block:"center"});return n?.requestAnimationFrame?n.requestAnimationFrame(()=>n.requestAnimationFrame(d)):d(),t.style.outline=`2px solid ${W.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as Lt}from"../stats/presentation.js";import{buildFacetTable as Et,facetValueOf as Be,FACET_NONE_VALUE as Tt,DEFAULT_FACET_CURATION as $t}from"../stats/facets.js";import{mergeTestDefs as ke}from"../stats/mergeTestDefs.js";import{isParametricTest as Le}from"../renderer/buildWaferMap.js";import{dieFailsTest as It,hasJudgeableTests as Dt,testsForPassKind as Ot,buildTestPassRateData as At}from"../stats/testPassRate.js";import{fmt as Ve}from"../renderer/fmt.js";import{testLabel as Ye}from"../renderer/testLabel.js";import{waferDisplayLabel as Wt,waferIdentityLabel as Pt}from"../core/waferLabel.js";import{waferPopulation as Rt}from"./chartPopulation.js";import{openDrilldownMenu as Ee}from"./drilldown.js";import{plotStoreFor as Ft}from"./plotStore.js";import{createPageFilter as Mt}from"./pageFilter.js";import{bandButton as Nt}from"./filterButton.js";import{itemPassBins as jt,passBinsLabel as Ge}from"../core/passBins.js";import{describeWaferPopulation as zt,populationStat as Ht}from"../stats/population.js";import{LEADING as Te,ALPHA as Vt,SPACE as O,EDGE_GUTTER as $e,FONT as N,CLR as W,RADIUS as Yt,SHADOW as Gt,controlStyle as _e,wireControlHover as fe,wireTooltip as Ie}from"./toolbar.js";import{ICONS as _t}from"./icons.js";import{renderCapabilityPanel as qt}from"./charts/capability.js";import{renderGroupComparisonPanel as Kt}from"./charts/groupComparison.js";import{renderCommonalityPanel as Ut}from"./charts/commonality.js";import{renderPatCard as Xt}from"./charts/patCard.js";import{renderDifferenceMapPanel as Jt}from"./differenceMapPanel.js";import{renderCorrelationPanel as Qt}from"./charts/correlation.js";import{cardFrameStyle as Zt,makeChartGridWrap as pe,makeLabeledSelect as en,makeLinkedGroupSelect as tn,makeLinkedTestSelect as nn,makeWaferSelect as qe,makeTestSelect as Ke,makeLimitsSelect as an,makeLinkedAxisPrefs as sn,makeToggle as on,limitLines as Ue,limitExtent as rn,shouldIncludeLimitsByDefault as ln,hasBothLimitKinds as Xe}from"./charts/chartShell.js";import{maxOf as dn,minOf as cn}from"../core/utils.js";import{buildYieldData as Je,buildYieldDataCombined as un}from"../stats/yield.js";import{buildLotTestSectionSteps as fn,buildLotFunctionalSection as pn,buildMetadataStripBox as mn}from"./summaryPanel.js";import{runChunked as hn}from"./chunked.js";import{buildRegionYieldData as De,buildRingRegions as Qe,buildQuadrantRegions as Ze,buildReticlePositionRegions as bn,diesInRegion as gn}from"../stats/regions.js";import{renderDataSection as yn}from"./dataTab.js";import{sourceFromDies as wn,toPlotItems as le}from"./plotItems.js";import{isYieldEligibleDie as xn}from"../core/dies.js";import{renderPlotCard as ae}from"./plotCard.js";import{orderFieldValues as Cn,axisValues as Sn}from"../stats/plotData.js";import{buildSynthesis as vn,synthesisKey as Bn}from"../stats/synthesis.js";import{commonPassBins as kn}from"../core/passBins.js";import{renderRegionYieldDiagram as Oe}from"./charts/regionYieldDiagram.js";const Ln=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],En={key:"data",label:"Data"},Tn={key:"plot",label:"My plots"};export function createInsightsTab(B){const{getItems:et,getLotStats:Ae,getBinColors:U,getRingCount:V,onSaveImage:P,onSaveText:Y,openWafer:X,focusTest:me,locateDie:se}=B,de={...$t,...B.attributes},tt=B.showMetadataStrip??!0,J=B.contentInset??$e,c=B.ownerDocument??document,G=c.createElement("div");Object.assign(G.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const nt=$e,Z=c.createElement("div");Object.assign(Z.style,{paddingLeft:nt});const _=c.createElement("div");Object.assign(_.style,{display:"flex",gap:O.xs,alignItems:"center",background:W.menuBg,border:`1px solid ${W.menuBorder}`,borderRadius:Yt.container,boxShadow:Gt.panel,padding:`0 ${O.lg}`,marginBottom:O.lg,marginLeft:J,marginRight:J}),_.setAttribute("role","tablist"),_.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from(_.querySelectorAll('[role="tab"]')),n=t.indexOf(c.activeElement);if(n===-1)return;e.preventDefault();const d=t[(n+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];d.focus(),d.click()});const Q=c.createElement("div");Object.assign(Q.style,{display:"flex",flexDirection:"column",gap:O.lg,marginTop:"0",paddingLeft:J,paddingRight:J});const ce=B.pageFilter??Mt({doc:c,initial:B.filter,onChange:B.onFilterChange,attributes:B.attributes,getRingCount:B.getRingCount}),We=ce.createBand(()=>xe(),{marginLeft:J,marginRight:J,marginBottom:O.lg}),at=We.el;G.appendChild(Z),G.appendChild(_),G.appendChild(at),G.appendChild(Q);const st=[...Ln,En,Tn],ee=B.plotStore??Ft(B),te=(e,t)=>{import("./plotModal.js").then(({openPlotEditor:n})=>n({doc:c,anchor:G,store:ee,plot:e,draft:!0,items:[...t.items],ctx:t.ctx,title:e.title?`New plot from \u201C${e.title}\u201D`:"New plot",chart:{onSaveImage:P,binColors:U()}}))};let z=B.defaultView==="sweeps"?"plot":B.defaultView??"overview",F,he=!1;ce.subscribe(()=>q());let Pe="statistics",Re="wide",H=null,Fe=null,be=[],R=null,ge=B.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ye=new Map,we=(e,t,n=!1)=>{ge=e;for(const d of ye.values())for(const u of d)u!==t&&u.setAxisPrefs(e);n||B.onAxisPrefsChange?.(e)},ie=e=>{R!==e&&(R=e,q())};let ne=new Map;function Me(){for(const e of ne.values())e.destroy();ne=new Map}function Ne(e,t,n){X?.(e,t,n)}function ue(e){return(t,n,d)=>{const u=e.find(f=>f.waferIndex===t);if(!u)return;d.preventDefault();const h=Rt(u.dies,{waferLabel:u.identity,testDefs:u.testDefs,activeTest:n??H??void 0,waferIndex:t,wafer:u.wafer,passBins:u.passBins,ringCount:V()});Ee({x:d.clientX,y:d.clientY},d.target,h,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:se})}}function it(e,t,n,d,u){oe({x:e.clientX,y:e.clientY},e.target,t,n,d,u)}function oe(e,t,n,d,u,h){const f=wn(n.map(r=>({label:r.identity??r.label,dies:r.dies,waferIndex:r.waferIndex,wafer:r.wafer,passBins:r.passBins,ringCount:V()})),d,u,ke(n).defs,h);f&&Ee(e,t,f,{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:se})}function je(e){return X?{open:(t,n)=>Ne(t,`Wafer ${e.find(d=>d.waferIndex===t)?.label??t}`,n)}:me&&e.length===1?{open:(t,n)=>me(n),label:"show this test on the map"}:null}function xe(){return et().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Wt(e,t),identity:Pt(e),waferIndex:t,passBins:jt(e),statsSummary:e.statsSummary,testDefs:e.testDefs,source:e}).filter(e=>e!=null)}function ot(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${W.iconActive}`:"2px solid transparent",color:t?W.iconActive:W.label,fontWeight:t?"700":"500",fontSize:N.body,padding:`${O.sm} ${$e} ${O.md}`,cursor:"pointer",marginBottom:"-1px"})}function rt(e,t){const n=c.createElement("button");n.type="button",n.textContent=t;const d=e===z;return ot(n,d),n.dataset.on=d?"true":"false",fe(n,"bare"),n.dataset.wmapInsightsTab=e,n.setAttribute("role","tab"),n.setAttribute("aria-selected",d?"true":"false"),n.tabIndex=d?0:-1,n.addEventListener("click",()=>{z!==e&&(z=e,q({keepSections:!0}))}),n}function lt(e,t,n,d=!0){const u=pe(c),h=U(),f=n??"group",r=Ge(e.map(m=>m.passBins)),g=le(e.map(m=>({label:m.identity??m.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),dies:m.dies,waferIndex:m.waferIndex,wafer:m.wafer,passBins:m.passBins,ringCount:V()}))),p=ke(e).defs,o=t?F:void 0,l={testDefs:p,groupBy:o,curation:B.attributes},b=(m,x)=>({id:"card-yield",title:t?`Yield by ${f} (pass: ${r})`:`Yield by wafer (pass: ${r})`,chart:"bar",fields:{x:{slot:"groupBy"},y:{builtin:"yield"},color:{none:!0}},valueLabels:!0,...m?{sort:"value"}:{},...x>=3?{axes:{y:{references:[{stat:"median"}]}}}:{}}),k=t?t.length:e.length;let C=null;d&&(C=ae({doc:c,editAsPlot:te,items:g,ctx:l,spec:{choices:[{current:"natural",options:m=>[["value","Sort: yield"],["natural",t&&!m?`Sort: ${f}`:"Sort: wafer"]]}],build:([m])=>b(m==="value",k)},drill:t&&o?m=>{const x=Be(g[m[0]?.item]?.metadata,o,B.attributes);if(x===void 0)return null;const E=t.find(i=>i.key===x)?.items.length??0;return i=>({...i,title:`Yield by wafer \u2014 ${f}: ${x} (pass: ${r})`,fields:{...i.fields,x:{builtin:"wafer"}},where:{conditions:[{field:{meta:o},values:[x]}]},axes:E>=3?{y:{references:[{stat:"median"}]}}:void 0})}:void 0,drillLabel:"see its wafers",chart:{onSaveImage:P,onOpenWafer:X?m=>Ne(g[m].waferIndex??m,`Wafer ${g[m].label}`):void 0,onWaferMenu:ue(e)}}),C.card.style.minHeight="360px",u.appendChild(C.card));const L={current:"hbin",options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]]},w={current:"share",options:[["count","Counts"],["share",`Share of ${f}`,`Each ${f}\u2019s dies in a bin as a share of all its dies, so ${f} values of different sizes compare`]]},S=(m,x)=>({id:"card-bin-pareto",title:`${m==="sbin"?"Soft":"Hard"} bin pareto`,chart:"bar",sort:"value",fields:{x:{builtin:m==="sbin"?"sbin":"hbin"},color:t?{follow:"groupBy"}:{builtin:m==="sbin"?"sbin":"hbin"}},...t?x==="share"?{barNorm:"percent"}:{}:{cumulative:!0}}),s=ae({doc:c,editAsPlot:te,items:g,ctx:l,spec:t?{choices:[L,w],build:([m,x])=>S(m,x)}:{choices:[L],build:([m])=>S(m,void 0)},chart:{onSaveImage:P,binColors:h,onSelectPoints:(m,x,E,i)=>{const v=s.current().fields.x,a=v&&!Array.isArray(v)&&"builtin"in v&&v.builtin==="sbin"?"sbin":"hbin",y=new Set(m.map(T=>a==="hbin"?T.die?.hbin:T.die?.sbin));if(y.size!==1)return;const $=[...y][0],A=t?i?.group:void 0,I=A!==void 0?t?.find(T=>T.key===A)?.items??[]:e;oe(x,E,I,`in ${a==="hbin"?"hard":"soft"} bin ${$}${A!==void 0?` of ${A}`:""}`,T=>xn(T)&&(a==="hbin"?T.hbin:T.sbin)===$)}}});return s.card.style.minHeight="360px",u.appendChild(s.card),{card:u,destroy:()=>{C?.destroy(),s.destroy()}}}function Ce(){const e=c.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Zt(),display:"flex",flexDirection:"column",gap:O.lg,minWidth:"0"}),e}function dt(e){if(Z.innerHTML="",Z.style.marginBottom="0",!tt)return;const t=mn(e.map(n=>({metadata:n.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",Z.appendChild(t),Z.style.marginBottom=O.xs)}function ct(e,t,n,d){if(!e.length)return{elements:[],destroy:()=>{}};const u=e.map(w=>w.wafer),h=e.map(w=>w.dies),f=V(),r=[],g=[],p=d??[{key:"",items:e}],o=e.flatMap(w=>w.dies),l=["spec","testFlag","functional"].filter(w=>Dt(n,w,o));if(l.length){const w={spec:{label:"Test limits",hint:"Judged from each die\u2019s measured value against the test\u2019s limits",title:"Parametric pass rate \xB7 test limits"},testFlag:{label:"Tester flag",hint:"The pass or fail the tester recorded for each die",title:"Parametric pass rate \xB7 tester flag"},functional:{label:"Functional",hint:"Tests that only pass or fail and have no measured value",title:"Functional test pass rate"}},S=!!d,s=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:f}))),m=i=>({id:`card-pass-rate-${i}`,title:w[i].title,chart:"bar",orientation:"horizontal",sort:"ascending",fields:{x:{builtin:"test"},y:{tests:Ot(n,i).map(v=>v.testNumber),passRate:!0,...i==="testFlag"?{judge:"flag"}:{}},color:S?{follow:"groupBy"}:{none:!0}},...S?{}:{valueLabels:!0},axes:{y:{min:0,max:100}}}),x=i=>i.id.slice(15),E=ae({doc:c,editAsPlot:te,items:s,ctx:{testDefs:n,groupBy:S?F:void 0,curation:B.attributes},spec:l.length>1?{choices:[{current:l[0],options:l.map(i=>[i,w[i].label,w[i].hint])}],build:([i])=>m(i)}:m(l[0]),notes:i=>{const v=x(i);if(v==="functional")return[];const a=At(p.map(y=>({key:y.key,items:y.items.map($=>({dies:$.dies}))})),n,v).disagreementDies;return a?[`${a.toLocaleString("en-GB")} die${a===1?"":"s"} judged differently by test limits and the tester flag`]:[]},chart:{onSaveImage:P,selectActionLabel:"chart or tabulate the dies that fail its test",onSelectPoints:(i,v,a,y)=>{const $=n.find(T=>T.testNumber===y?.test);if(!$)return;const A=x(E.current()),I=y?.group!==void 0?p.find(T=>T.key===y.group)?.items??e:e;oe(v,a,I,`failing ${Ye($,$.testNumber)}${y?.group!==void 0?` in ${y.group}`:""}`,T=>It(T,$,A)===!0,Le($)?$.testNumber:void 0)}}});E.card.style.minHeight="300px",r.push(E.card),g.push(E.destroy)}const b=w=>(S,s)=>{const m=new Set;for(const x of e)for(const E of gn(x.dies,x.wafer,f,S.key,w))m.add(E);it(s,e,`in ${S.label}`,x=>m.has(x))},k=De(h,u,f,w=>e[w].passBins,Qe);if(k.length){const w=Oe({title:"Ring yield",mode:"ring",rows:k,onSelectRegion:b(Qe),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const C=De(h,u,f,w=>e[w].passBins,Ze);if(C.length){const w=Oe({title:"Quadrant yield",mode:"quadrant",rows:C,onSelectRegion:b(Ze),onSaveImage:P,ownerDocument:c});r.push(w.card),g.push(w.destroy)}const L=u.find(w=>w.reticle!==void 0)?.reticle;if(L){const w=(s,m)=>bn(s,m.reticle),S=De(h,u,f,s=>e[s].passBins,w);if(S.length){const s=Oe({title:"Reticle cell yield",mode:"reticleCell",rows:S,grid:{width:Math.max(1,Math.floor(L.width)),height:Math.max(1,Math.floor(L.height))},onSelectRegion:b(w),onSaveImage:P,ownerDocument:c});r.push(s.card),g.push(s.destroy)}}return{elements:r,destroy:()=>{for(const w of g)w()}}}function ut(e,t,n){if(!e.length)return{cards:[],destroy:()=>{}};const d=e.map(l=>l.dies),u=e.flatMap(l=>l.dies),h=e.map(l=>l.statsSummary),f=h.every(l=>l!==void 0)?h:void 0,r=[],g=[];let p=null;if(t.length){const l=Ce();let b=null;const k=hn(fn(u,t,void 0,f,Y,d.map(C=>({dies:C})),void 0,"full"),{onDone:C=>{b=C,l.removeAttribute("aria-busy"),C?l.replaceChildren(C):l.remove()}});if(k.done)b&&(p=l);else{const C=c.createElement("div");C.textContent="Computing test statistics\u2026",Object.assign(C.style,{color:W.label,fontSize:N.body}),l.setAttribute("aria-busy","true"),l.appendChild(C),p=l,r.push(()=>k.cancel())}}let o=null;if(n.length){const l=pn(u,n,f,Y);if(l){const b=Ce();b.appendChild(l),o=b}}return p&&g.push(p),o&&g.push(o),{cards:g,destroy:()=>{for(const l of r)l()}}}function ft(e){const t=Ge(e.map(p=>p.passBins)),n=e.length===1,d=e[0],u=Ce();Object.assign(u.style,{flexDirection:"row",flexWrap:"wrap",gap:O.md});const h=p=>{const o=p.lastElementChild;return o&&Object.assign(o.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),p};function f(p,o,l){const b=c.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:O.sm,paddingRight:O.xxl,marginRight:O.md,borderRight:`1px solid ${W.menuBorder}`});const k=c.createElement("div");k.textContent=p,Object.assign(k.style,{fontSize:N.heading,fontWeight:"700",color:W.value,lineHeight:Te.tight});const C=c.createElement("div");if(C.textContent=o,Object.assign(C.style,{fontSize:N.body,color:W.label}),b.append(k,C),l){const L=c.createElement("div");L.textContent=l,Object.assign(L.style,{fontSize:N.meta,color:W.label,opacity:Vt.muted}),b.appendChild(L)}return b}if(n){const p=Je([{...d,key:d.waferIndex}])[0]?.percent;return p!==void 0&&u.appendChild(f(`${p.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),u.appendChild(f(String(d.dies.length),"Total dies")),h(u)}u.appendChild(f(String(e.length),"Wafers"));const r=Je(e.map(p=>({...p,key:p.waferIndex}))).map(p=>p.percent).filter(p=>Number.isFinite(p));if(r.length){const p=r.reduce((b,k)=>b+k,0)/r.length,o=un([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,l=o!==void 0&&o.toFixed(1)!==p.toFixed(1);u.appendChild(f(`${p.toFixed(1)}%`,`${Lt} \xB7 pass: ${t}`,l?`${o.toFixed(1)}% by dies`:void 0))}const g=e.map(p=>p.statsSummary);if(g.every(p=>p!==void 0)){const p=g.reduce((l,b)=>l+b.stats.analyzedDies,0),o=g.reduce((l,b)=>l+b.stats.excludedDies,0);u.appendChild(f(p.toLocaleString(),"Dies analysed",o?`${o.toLocaleString()} excluded`:void 0))}else u.appendChild(f(e.reduce((p,o)=>p+o.dies.length,0).toLocaleString(),"Total dies"));return h(u)}function pt(e,t,n,d,u){const h=c.createElement("div");Object.assign(h.style,{display:"flex",flexDirection:"column",gap:O.lg});const f=e.length===1&&!d;e.length&&!d&&h.appendChild(ft(e));const r=lt(e,d,u,!f);h.appendChild(r.card);const g=ct(e,t,n,d);for(const l of g.elements)r.card.appendChild(l);const p=mt(e,n);if(p&&h.appendChild(p.el),e.length>=4&&be.length){const l=Ut({wafers:e,fields:be,curation:de,groupedBy:F,onGroupBy:b=>{F=b,R=null,q()},ownerDocument:c});h.appendChild(l.card)}const o=Xt({items:e.map(l=>({...l,ringCount:V()})),testDefs:n,ownerDocument:c,showMap:B.showPatMap});return o&&h.appendChild(o.card),h.appendChild(ht()),{card:h,destroy:()=>{r.destroy(),g.destroy(),p?.destroy()}}}function mt(e,t){const n=Ae?.()??(e.length===1?e[0].statsSummary:void 0);if(!n)return null;const d=c.createElement("section");d.dataset.wmapWorthALook="1",Object.assign(d.style,{display:"flex",flexDirection:"column",gap:O.md});const u=c.createElement("h3");u.textContent="Worth a look",Object.assign(u.style,{margin:"0",fontSize:N.heading,fontWeight:"600",color:W.value}),d.appendChild(u);const h=(o,l)=>{const b=c.createElement("p");b.textContent=o,l&&(b.dataset[l]="1"),Object.assign(b.style,{margin:"0",fontSize:N.body,color:W.label,lineHeight:Te.base}),d.appendChild(b)};if(he||R!==null)return h("Worth a look describes the whole lot, as What stands out beside the map does. Switch the filter off, or Show all groups, to see it here.","wmapWorthNarrowed"),{el:d,destroy:()=>{}};const f=vn(n,{passBins:kn(e.map(o=>o.passBins)),attributes:B.attributes});if(f.items.length===0)return h(f.nothing??"Nothing stands out.","wmapWorthNothing"),{el:d,destroy:()=>{}};const r=pe(c);d.appendChild(r);const g=le(e.map(o=>({label:o.identity??o.label,dies:o.dies,waferIndex:o.waferIndex,wafer:o.wafer,passBins:o.passBins,ringCount:V()}))),p=[];if(f.items.forEach((o,l)=>{const b=c.createElement("div");b.dataset.wmapWorthWhy="1",b.textContent=`Shown because: ${o.reason}`,o.text!==o.reason&&Ie(b,o.text),Object.assign(b.style,{flexBasis:"100%",fontSize:N.body,color:W.text,lineHeight:Te.base});const k=[b];if(B.showOnMap){const L=c.createElement("button");L.type="button",L.textContent="Show on map",L.dataset.wmapWorthShowOnMap="1",Object.assign(L.style,{..._e("outlined"),fontSize:N.body,padding:`0 ${O.md}`}),fe(L),Ie(L,"Leave Insights and show this on the map, as its row in What stands out does"),L.addEventListener("click",()=>B.showOnMap(o.target)),k.push(L)}const C=ae({doc:c,items:g,ctx:{testDefs:t,curation:de},spec:{id:`worth-${l}`,...o.chart},extras:k,editAsPlot:te,chart:{onSaveImage:P}});C.card.dataset.wmapWorthKey=Bn(o),r.appendChild(C.card),p.push(C.destroy)}),f.also){const o=f.also.items.map(l=>l.brief).join("; ");h(`Also: ${o}${f.also.more?`; and ${f.also.more} more`:""}. Their rows in What stands out show them on the map.`,"wmapWorthAlso")}return{el:d,destroy:()=>p.forEach(o=>o())}}function ht(){const e=c.createElement("div");Object.assign(e.style,{fontSize:N.body,color:W.label});const t=c.createElement("button");return t.type="button",t.textContent="Data tab",t.dataset.wmapOpenDataTab="1",Object.assign(t.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:W.iconActive,textDecoration:"underline"}),fe(t,"bare"),t.addEventListener("click",()=>{z="data",q({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",t,"."),e}function bt(e,t,n,d){const u=c.createElement("div");u.style.width="100%";let h,f=!1;return import("./plotTab.js").then(({createPlotSection:r})=>{if(f)return;const g=r({doc:c,store:ee,items:e,testDefs:t,ringCount:V(),attributes:B.attributes,groupBy:n,groupLabel:d,onSaveImage:P,onSaveText:Y,getBinColors:U,waferMenu:ue(e),openWafer:X?(p,o,l)=>X(p,o,l):void 0,focusTest:me,locateDie:se,pickPlotsFile:B.onPickPlotsFile});u.appendChild(g.card),h=g}),{card:u,destroy:()=>{f=!0,h?.destroy()}}}function gt(e,t,n,d,u){const h=he?void 0:Ae?.(),f=()=>{ne.get("data")?.destroy(),ne.delete("data"),q({keepSections:!0})};return yn({doc:c,items:e,testDefs:t,allTestDefs:n,groups:d,groupLabelText:u,ringCount:V(),attributes:B.attributes,yieldByWaferIndex:new Map(h?.lotYieldSeries.map(r=>[r.waferIndex,r.yieldPercent])),onSaveText:Y,onLocateDie:se,onOpenWafer:X?(r,g)=>X(r,g):void 0,buildStatistics:r=>ut(r,t,n),view:Pe,onViewChange:r=>{Pe=r,f()},diesLayout:Re,onDiesLayoutChange:r=>{Re=r}})}function ze(e,t){const n=c.createElement("h3");return n.textContent=e,n.dataset.wmapRowHeading=t,Object.assign(n.style,{gridColumn:"1 / -1",margin:`${O.md} 0 0`,color:W.value,fontSize:N.heading,fontWeight:"600"}),n}function yt(e,t,n,d){const u=pe(c),h=je(e),f=le(e.map(a=>({label:a.identity??a.label,dies:a.dies,waferIndex:a.waferIndex,wafer:a.wafer,passBins:a.passBins,ringCount:V()}))),r=t.filter(a=>a.testNumber!==void 0),g=!!n&&!!F,p=g&&R!==null,o={testDefs:t,groupBy:g?F:void 0,curation:B.attributes},l=(a,y,$)=>({limits:y.limits??"both",axes:{[a]:{...y.includeLimits!==void 0?{includeLimits:y.includeLimits}:{},...y.clipOutliers?{clip:!0}:{},...$?{scale:"log"}:{}}}});function b(a){let y=ge,$=!1,A;const I=nn(r,H??r[0]?.testNumber??null,j=>{A?.refresh(),m(j)},{ownerDocument:c}),T=c.createElement("span");Object.assign(T.style,{display:"inline-flex",flexWrap:"wrap",gap:O.sm,alignItems:"center"});const D={setAxisPrefs:j=>{K.set(j)&&(y=j,A?.refresh())}},K=sn(T,y,j=>{y=j,A?.refresh(),we(j,D)},c),re=[I.el,T];a.logToggle&&re.push(on("Log scale",$,j=>{$=j,A?.refresh()},c,"Draw the value axis on a logarithmic scale")),re.push(...a.extras??[]),A=ae({doc:c,editAsPlot:te,items:f,ctx:o,...a.card,spec:{choices:[],build:()=>a.build(y,$)},slots:()=>({test:I.get()??void 0}),extras:re,onResolved:j=>{const Se=t.find(kt=>kt.testNumber===I.get()),He=Ue(Se,y.limits),ve=Sn(j,a.valueRole),{lo:St,hi:vt}=rn(He),Bt=ve.length>0&&He.length>0&&ln(cn(ve),dn(ve),St,vt);K.sync(y.includeLimits??Bt,Ue(Se).length>0,Xe(Se))},chart:a.chart});const M=A;return{card:M.card,setTest:j=>{I.set(j)&&M.refresh()},refresh:()=>M.refresh(),setAxisPrefs:D.setAxisPrefs,destroy:()=>M.destroy()}}const k=h?(a,y)=>h.open(f[a]?.waferIndex??a,y??H??r[0]?.testNumber??0):void 0,C=b({valueRole:"y",logToggle:!0,build:(a,y)=>({id:"card-box",title:"Test value distribution",chart:"box",orientation:"horizontal",fields:{x:g&&!p?{slot:"groupBy"}:{builtin:"wafer"},y:{slot:"test"},color:{none:!0}},...p?{where:{conditions:[{field:{meta:F},values:[R]}]}}:{},...l("y",a,y)}),card:{...g&&!p?{drill:a=>{const y=Be(f[a[0]?.item]?.metadata,F,B.attributes);return y!==void 0&&ie(y),null},drillLabel:"see its wafers"}:{},...R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{}},chart:{onSaveImage:P,onOpenWafer:k,openActionLabel:h?.label,onWaferMenu:ue(e)}});let L=null;const w=g?[]:[qe(f.map(a=>({label:a.label})),null,a=>{L=a,S.refresh()},{ownerDocument:c})],S=b({valueRole:"x",extras:w,card:R!==null?{externalBack:{shown:()=>R!==null,onBack:()=>ie(null)}}:{},build:a=>({id:"card-histogram",title:"Value histogram",chart:"histogram",fields:{y:{slot:"test"},color:g?{follow:"groupBy"}:{none:!0}},...L!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[f[L].label]}]}}:{},...l("x",a,!1)}),chart:{onSaveImage:P,...g?{onLegendPick:a=>ie(a),legendPicked:R}:{},onSelectPoints:(a,y,$,A)=>{const I=t.find(M=>M.testNumber===(H??r[0]?.testNumber)),T=new Set(a.map(M=>M.die).filter(M=>!!M)),D=new Set(a.map(M=>f[M.item]?.waferIndex)),K=A?.range,re=I&&K?`with ${Ye(I,I.testNumber)} from ${Ve(K.lo,I.unit,"engineering")} to ${Ve(K.hi,I.unit,"engineering")}${A?.group?` in ${A.group}`:""}`:"selected in the histogram";oe(y,$,e.filter(M=>D.has(M.waferIndex)),re,M=>T.has(M),I?.testNumber)}}}),s=b({valueRole:"y",build:a=>({id:"card-trend",title:"Wafer-to-wafer trend",chart:"line",aggregate:"mean",spread:"sd",fields:{x:{builtin:"waferOrder"},y:{slot:"test"},color:{none:!0}},...l("y",a,!1),axes:{...l("y",a,!1).axes,y:{...l("y",a,!1).axes.y,references:[{stat:"mean",label:Ht(zt(e.map(y=>y.wafer.metadata)),"mean")}]}}}),card:{ctx:{...o,groupBy:void 0},...e.length<2?{unavailable:"A trend needs at least two wafers"}:{}},chart:{onSaveImage:P,onWaferMenu:ue(e),selectActionLabel:k?"open that wafer":"chart or tabulate its dies",selectRangeLabel:"wafers",onSelectPoints:(a,y,$)=>{const A=new Set(a.map(D=>D.item));if(A.size===1&&k){k([...A][0]);return}const I=new Set(a.map(D=>D.die).filter(D=>!!D)),T=new Set(a.map(D=>f[D.item]?.waferIndex));oe(y,$,e.filter(D=>T.has(D.waferIndex)),"selected in the trend",D=>I.has(D),H??void 0)}}}),m=a=>{H=a,C.setTest(a),S.setTest(a),s.setTest(a),v.setTest(a),E?.setTest(a),i?.setTest(a)},x=()=>Kt({groups:n,testDefs:t,groupLabelText:d,control:Fe,onControlChange:a=>{Fe=a;const y=x();E.card.replaceWith(y.card),E=y},selectedTestNumber:H??void 0,onSelectTest:a=>m(a),onSaveText:Y,ownerDocument:c});let E=n&&n.length>=2?x():void 0;const i=n&&n.length>=2?Jt({groups:n,testDefs:t,groupLabelText:d,selectedTestNumber:H??void 0,onSaveImage:P,ownerDocument:c}):void 0;ye.set("distribution",[C,S,s]);const v=qt({title:"Process capability",items:e,testDefs:t,onSaveImage:P,selectedTestNumber:H??void 0,onSelectTest:a=>m(a),ownerDocument:c});return(E||i)&&(u.append(ze(`Comparing ${d??"groups"}`,"comparing")),E&&u.append(E.card),i&&u.append(i.card),u.append(ze("Test by test","tests"))),u.append(v.card,C.card,S.card,s.card),{card:u,destroy:()=>{v.destroy(),C.destroy(),S.destroy(),s.destroy(),E?.destroy(),i?.destroy()}}}function wt(e,t,n){const d=pe(c),u=je(e),h=le(e.map(i=>({label:i.identity??i.label,dies:i.dies,waferIndex:i.waferIndex,wafer:i.wafer,passBins:i.passBins,ringCount:V()}))),f=t.filter(i=>i.testNumber!==void 0&&Le(i));let r=f[0]?.testNumber,g=f[1]?.testNumber??r,p=null,o=ge;const l=!!n&&!!F,b=(i,v)=>{const a=c.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:O.xs,fontSize:N.body,color:W.label});const y=c.createElement("span");return y.textContent=i,a.append(y,v),a},k=Ke(f,r??null,i=>{r=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),C=Ke(f,g??null,i=>{g=i,S(),x.refresh()},{maxWidth:"180px",emptyText:"No tests",ownerDocument:c}),L=c.createElement("span"),w={setXY:(i,v)=>{r=i,g=v,k.value=String(i),C.value=String(v),S(),x.refresh()},setAxisPrefs:i=>{o=i,S(),x.refresh()},destroy:()=>x.destroy()};function S(){const i=[r,g].map(v=>t.find(a=>a.testNumber===v));L.replaceChildren(...i.some(Xe)?[an(o.limits??"both",v=>{o={...o,limits:v},x.refresh(),we(o,w)},c)]:[])}const s=i=>{const v=t.find(a=>a.testNumber===i);return v?.name?{test:i??0,name:v.name}:{test:i??0}},m=[b("X:",k),b("Y:",C),L];!l&&e.length>1&&m.push(qe(h.map(i=>({label:i.label})),null,i=>{p=i,x.refresh()},{ownerDocument:c}));const x=ae({doc:c,editAsPlot:te,items:h,ctx:{testDefs:t,groupBy:l?F:void 0,curation:B.attributes},extras:m,spec:{choices:[],build:()=>({id:"card-scatter",title:"Test scatter",chart:"scatter",limits:o.limits??"both",fields:{x:s(r),y:s(g),color:l?{follow:"groupBy"}:{builtin:"hbin"}},...p!==null?{where:{conditions:[{field:{builtin:"wafer"},values:[h[p].label]}]}}:{}})},...r===void 0?{unavailable:"No parametric test has values to plot"}:{},chart:{onSaveImage:P,binColors:U(),onOpenWafer:u?(i,v)=>u.open(h[i]?.waferIndex??i,v??r??0):void 0,openActionLabel:u?.label,onSelectPoints:(i,v,a)=>{const y=new Map;for(const I of i){const T=h[I.item]?.waferIndex;if(T===void 0||!I.die)continue;const D=y.get(T);D?D.push(I.die):y.set(T,[I.die])}const $=[...y].flatMap(([I,T])=>{const D=e.find(K=>K.waferIndex===I);return D?[{label:D.identity??D.label,dies:T,waferIndex:I,wafer:D.wafer,passBins:D.passBins,ringCount:V()}]:[]});if($.length===0)return;const A=$.length===1?`selected on ${$[0].label} in the scatter`:`selected in the scatter, across ${$.length} wafers`;Ee(v,a,{items:$,population:A,testDefs:t,activeTest:r},{plots:ee,getBinColors:U,onSaveImage:P,onSaveText:Y,onLocateDie:se})}}});S(),ye.set("correlation",[w]);const E=Qt({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:P,onSaveText:Y,onSelectPair:(i,v)=>w.setXY(i,v),ownerDocument:c});return d.append(E.card,x.card),{card:d,destroy:()=>{E.destroy(),w.destroy()}}}const xt=(e,t,n,d)=>Nt(c,e,t,n,d),Ct=()=>ce.openEditor(G,xe());function q(e){e?.keepSections||Me(),Q.innerHTML="",_.innerHTML="";for(const s of st)_.appendChild(rt(s.key,s.label));const t=xe(),n=ce.keep(t),d=n.items;he=n.narrowing,We.refresh(n.result,t),dt(d);const u=Et(d,{facetableOnly:!0,curation:de}).filter(s=>s.splittable);be=u.map(s=>({key:s.key,label:s.label}));const h=c.createElement("div");Object.assign(h.style,{display:"flex",gap:O.md,alignItems:"center",marginLeft:O.xxl,paddingBottom:O.xs}),B.showFilterButton!==!1&&h.appendChild(xt("Filter\u2026","wmapInsightsFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>Ct()));let f;u.length>0?(h.appendChild(en("Group by:",[{value:"",label:"None"},...u.map(s=>({value:s.key,label:`${s.label} (${s.values.length})`}))],F??"",s=>{F=s||void 0,R=null,q()},{hook:"group-by",ownerDocument:c})),f=u.find(s=>s.key===F)?.label):F=void 0;let r;if(F){const s=new Map,m=[];for(const x of d){const E=Be(x.metadata,F,de)??Tt;s.has(E)||(s.set(E,[]),m.push(E)),s.get(E).push(x)}r=Cn(m).map(x=>({key:x,items:s.get(x)}))}R!==null&&!r?.some(s=>s.key===R)&&(R=null),r&&r.length>0&&h.appendChild(tn(r.map(s=>s.key),"Show:",R,s=>ie(s),{ownerDocument:c}).el);let g=null;if(B.onOpenGuide){const s=c.createElement("button");s.type="button",s.innerHTML=_t.help,s.setAttribute("aria-label","User guide"),Object.assign(s.style,{..._e("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),fe(s,"bare"),Ie(s,"User guide"),s.addEventListener("click",()=>B.onOpenGuide()),Object.assign(s.style,{marginLeft:"auto"}),g=s}_.appendChild(h),g&&_.appendChild(g);const p=R!==null?r?.find(s=>s.key===R):void 0,o=p?.items??d,l=p?void 0:r,b=ke(o),k=b.defs,C=k.filter(Le);if(H!==null&&!C.some(s=>s.testNumber===H)&&(H=null),d.length===0){const s=c.createElement("div");s.dataset.wmapInsightsFilterEmpty="1",s.textContent="The filter keeps no wafer and no die. Edit the filter or switch it off to see the data.",Object.assign(s.style,{color:W.label,fontSize:N.body,padding:O.xl}),Q.appendChild(s);return}const L=e?.keepSections?ne.get(z):void 0,w=L??(z==="overview"?pt(o,C,k,l,f):z==="distributions"?yt(o,C,l,f):z==="data"?gt(o,C,k,l,f):z==="plot"?bt(o,k,p?void 0:F,p?void 0:f):wt(o,C,l));L||ne.set(z,w);const S=b.conflicts.filter(s=>s.excluded);if(S.length>0){const s=c.createElement("div");Object.assign(s.style,{color:W.label,fontSize:N.body,padding:`0 ${J} ${O.sm}`});const m=S.slice(0,6).map(i=>i.testNumber).join(", "),x=S.length>6?`, and ${S.length-6} more`:"",E=S.length===1?"it":"them";s.textContent=`${S.length} test ${S.length===1?"number is":"numbers are"} hidden (${m}${x}) \u2014 the wafers in view describe ${E} differently, so their values cannot be pooled. `+(r&&r.length>0?`Pick one ${f??"group"} under "Show:" to analyse ${E}.`:"Load one test program at a time to analyse them."),s.dataset.wmapWithheldTests=String(S.length),Q.appendChild(s)}Q.appendChild(w.card)}return{el:G,render:q,destroy:()=>{Me(),ee.flush(),G.remove()},setAxisPrefs:e=>we(e,null,!0),showWorthCard:e=>{z!=="overview"&&(z="overview",q({keepSections:!0}));const t=[...Q.querySelectorAll("[data-wmap-worth-key]")].find(u=>u.dataset.wmapWorthKey===e);if(!t)return!1;const n=c.defaultView,d=()=>t.scrollIntoView({block:"center"});return n?.requestAnimationFrame?n.requestAnimationFrame(()=>n.requestAnimationFrame(d)):d(),t.style.outline=`2px solid ${W.iconActive}`,t.style.outlineOffset="2px",setTimeout(()=>{t.style.outline="",t.style.outlineOffset=""},1600),!0}}}
@@ -0,0 +1,27 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { MetadataFieldDef, TestDef } from '../renderer/buildWaferMap.js';
3
+ /** The die metadata key the verdict is carried under. Not a host key: nothing a host sets can collide with it. */
4
+ export declare const PAT_MODE_KEY = "wmapPat";
5
+ /** The field the legend and tooltip name the verdict by; the colours say what a verdict is (blue within, amber outlier, red fails). */
6
+ export declare const PAT_MODE_FIELD: MetadataFieldDef;
7
+ /** The lot-wide order of the verdicts: fixed, so no card has to be read to know it. */
8
+ export declare const PAT_MODE_ORDER: readonly string[];
9
+ /** Whether these view options are the PAT verdict mode. */
10
+ export declare function isPatMode(o: {
11
+ plotMode?: string;
12
+ activeMetadataKey?: string;
13
+ }): boolean;
14
+ /** Cheap test for the mode menu: a test with both limits and a wafer with enough dies to set PAT limits from. */
15
+ export declare function patModeOffered(items: ReadonlyArray<{
16
+ dies: readonly Die[];
17
+ testDefs?: readonly TestDef[];
18
+ } | null | undefined>): boolean;
19
+ /**
20
+ * A wafer's dies with each die's verdict under {@link PAT_MODE_KEY}. The verdicts are judged over the dies the page
21
+ * filter keeps (the Insights PAT card's rule), and a die the filter dropped keeps no verdict and is left as it is, to be
22
+ * drawn dimmed. A die no test judged carries no value and draws as no data. Memoised on the die list.
23
+ */
24
+ export declare function withPatVerdicts(dies: readonly Die[], testDefs: readonly TestDef[] | undefined, passBins: readonly number[]): Die[];
25
+ /** `fields` with the verdict field added (once). */
26
+ export declare function withPatField(fields: readonly MetadataFieldDef[] | undefined): MetadataFieldDef[];
27
+ //# sourceMappingURL=patMode.d.ts.map
@@ -0,0 +1 @@
1
+ import{copyDie as D}from"../core/dieTable.js";import{PAT_MIN_DIES as P,PAT_VERDICT_LABEL as a,PAT_VERDICT_ORDER as _,patTests as E,waferPatVerdicts as d}from"../stats/pat.js";export const PAT_MODE_KEY="wmapPat",PAT_MODE_FIELD={key:PAT_MODE_KEY,label:"PAT verdict",values:[{value:a.within,color:"#0072b2"},{value:a.outlier,color:"#e69f00"},{value:a.fails,color:"#c0392b"}]},PAT_MODE_ORDER=_;export function isPatMode(t){return t.plotMode==="metadata"&&t.activeMetadataKey===PAT_MODE_KEY}export function patModeOffered(t){return t.some(o=>!!o&&o.dies.length>=P&&E(o.testDefs??[]).length>0)}const u=new WeakMap;export function withPatVerdicts(t,o,c){const n=o??[],s=c.join(","),r=u.get(t);if(r&&r.testDefs===n&&r.passKey===s)return r.out;const l=t.some(e=>e.filteredOut)?t.filter(e=>!e.filteredOut):t,p=d(l,n,c);let m=0;const i=t.map(e=>{if(e.filteredOut)return e;const f=p[m++]?.verdict;return f?D(e,{metadata:{...e.metadata,[PAT_MODE_KEY]:a[f]}}):e});return u.set(t,{testDefs:n,passKey:s,out:i}),i}export function withPatField(t){return t?.some(o=>o.key===PAT_MODE_KEY)?[...t]:[...t??[],PAT_MODE_FIELD]}