@wafertools/wafermap 0.34.0 → 0.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/AGENTS.md +7 -1
  2. package/CHANGELOG.md +189 -1
  3. package/README.md +6 -3
  4. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +1 -1
  5. package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +17 -2
  9. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  13. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +6 -1
  14. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  17. package/dist/packages/canvas-adapter/dataTab.d.ts +6 -0
  18. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  19. package/dist/packages/canvas-adapter/dieList.js +6 -6
  20. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  21. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  22. package/dist/packages/canvas-adapter/identityHeader.d.ts +4 -1
  23. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  24. package/dist/packages/canvas-adapter/insightsTab.d.ts +3 -1
  25. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  26. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  27. package/dist/packages/canvas-adapter/plotTab.d.ts +3 -0
  28. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  29. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +8 -0
  30. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  31. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +22 -1
  32. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  33. package/dist/packages/canvas-adapter/summaryPanel.d.ts +39 -11
  34. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  35. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  36. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  37. package/dist/packages/canvas-adapter/sweepEditor.js +1 -1
  38. package/dist/packages/canvas-adapter/toolbar.d.ts +8 -0
  39. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  40. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  41. package/dist/packages/canvas-adapter/userGuideHtml.js +57 -27
  42. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  43. package/dist/packages/canvas-adapter/version.js +1 -1
  44. package/dist/packages/canvas-adapter/warnings.js +1 -1
  45. package/dist/packages/core/classify.d.ts +5 -0
  46. package/dist/packages/core/classify.js +1 -1
  47. package/dist/packages/core/dieTable.d.ts +26 -0
  48. package/dist/packages/core/dieTable.js +1 -1
  49. package/dist/packages/core/index.d.ts +1 -1
  50. package/dist/packages/core/index.js +1 -1
  51. package/dist/packages/core/passBins.d.ts +6 -0
  52. package/dist/packages/core/passBins.js +1 -1
  53. package/dist/packages/core/reticle.d.ts +20 -0
  54. package/dist/packages/core/reticle.js +1 -1
  55. package/dist/packages/core/wafer.d.ts +15 -0
  56. package/dist/packages/core/wafer.js +1 -1
  57. package/dist/packages/renderer/buildView.js +1 -1
  58. package/dist/packages/renderer/buildWaferMap.d.ts +32 -1
  59. package/dist/packages/renderer/buildWaferMap.js +1 -1
  60. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  61. package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
  62. package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
  63. package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
  64. package/dist/packages/renderer/derivedTests/parser.js +2 -2
  65. package/dist/packages/renderer/spec.d.ts +4 -0
  66. package/dist/packages/renderer/spec.js +1 -1
  67. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  68. package/dist/packages/renderer/valueFilter.js +1 -0
  69. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  70. package/dist/packages/stats/analyzeWaferMap.d.ts +44 -3
  71. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  72. package/dist/packages/stats/capability.d.ts +5 -0
  73. package/dist/packages/stats/capability.js +1 -1
  74. package/dist/packages/stats/clusterDetection.js +1 -1
  75. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  76. package/dist/packages/stats/connectedComponents.js +1 -1
  77. package/dist/packages/stats/dieRegions.d.ts +42 -0
  78. package/dist/packages/stats/dieRegions.js +1 -0
  79. package/dist/packages/stats/facets.d.ts +8 -0
  80. package/dist/packages/stats/facets.js +1 -1
  81. package/dist/packages/stats/index.d.ts +2 -1
  82. package/dist/packages/stats/index.js +1 -1
  83. package/dist/packages/stats/lotPattern.js +1 -1
  84. package/dist/packages/stats/math.d.ts +25 -3
  85. package/dist/packages/stats/math.js +1 -1
  86. package/dist/packages/stats/metadataColumns.js +1 -1
  87. package/dist/packages/stats/patternClassification.d.ts +44 -18
  88. package/dist/packages/stats/patternClassification.js +1 -1
  89. package/dist/packages/stats/plotData.d.ts +12 -1
  90. package/dist/packages/stats/plotData.js +1 -1
  91. package/dist/packages/stats/plotSpec.d.ts +1 -1
  92. package/dist/packages/stats/plotSpec.js +1 -1
  93. package/dist/packages/stats/regions.d.ts +15 -0
  94. package/dist/packages/stats/regions.js +1 -1
  95. package/dist/packages/stats/renderSummaryReport.js +33 -33
  96. package/dist/packages/stats/reportHtml.d.ts +7 -6
  97. package/dist/packages/stats/reportHtml.js +39 -37
  98. package/dist/packages/stats/synthesis.d.ts +44 -17
  99. package/dist/packages/stats/synthesis.js +1 -1
  100. package/dist/packages/stats/types.d.ts +12 -0
  101. package/llms.txt +2 -2
  102. package/package.json +1 -1
  103. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  104. package/dist/packages/canvas-adapter/summaryRail.js +0 -1
@@ -1 +1 @@
1
- import{SHADOW as V,LEADING as G,wireControlHover as B,controlStyle as j,SPACE as w,RADIUS as T,fontPx as F,FONT as L,CLR as f,Z_BASE as oe,menuLayerFor as ie,wireListNavigation as re,MENU_SEARCH_THRESHOLD as U,makeMenuSearchBox as le,markMenuTrigger as N,markNoPrint as P,saveImageBlob as se,openReparentedModal as ae}from"../toolbar.js";import{ICONS as X}from"../icons.js";import{minOf as ce,maxOf as de}from"../../core/utils.js";import{robustFence as K}from"../../stats/math.js";import{fmt as ue,fmtColorbarAxis as pe}from"../../renderer/fmt.js";import{markedTestLabel as fe,DERIVED_LANE_PAD as me}from"../../renderer/testLabel.js";export function openChartExpandModal(e,i,n={}){for(const s of e.querySelectorAll('div[style*="position: absolute"]'))s.style.display==="block"&&s.style.pointerEvents==="none"&&(s.style.display="none");const t=e.querySelector("[data-wmap-chart-expand]"),o=e.getAttribute("style")??"",r=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const l=ae([e],{title:i,anchor:n.anchor,ownerDocument:e.ownerDocument,boxSize:he[r],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",o),t&&(t.style.display="flex"),n.onClosed?.()}});if(!l)return delete e.dataset.wmapExpanded,e.setAttribute("style",o),null;if(t&&(t.style.display="none"),r==="rows"){const s=()=>{const a=Number(e.dataset.wmapChartFullH);if(!a)return;const p=l.box.offsetHeight-l.contentWrap.clientHeight;l.setNaturalHeight(`min(90vh, ${Math.ceil(p+a)}px)`)};s(),(e.ownerDocument.defaultView??window).requestAnimationFrame(s)}return l}const he={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,i){const n=e.trim();let t,o,r,l=1;const s=n.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=n.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const p=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[t,o,r]=[0,2,4].map(c=>parseInt(p.slice(c,c+2),16)),p.length===8&&(l=parseInt(p.slice(6,8),16)/255)}else if(a)[t,o,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(${t}, ${o}, ${r}, ${+(l*i).toFixed(3)})`}const ge={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309"},Y={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text"};export function resolveChartCanvasColors(e){const i=getComputedStyle(e),n={};for(const t of Object.keys(Y)){const o=i.getPropertyValue(`--wmap-${Y[t]}`).trim();n[t]=o||ge[t]}return n.grid=withAlpha(n.border,GRID_ALPHA),n}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,i){const n=e.ownerDocument.defaultView??window;let t=0;const o=new n.ResizeObserver(()=>{t||(t=n.requestAnimationFrame(()=>{t=0,i()}))});return o.observe(e),{disconnect:()=>{t&&n.cancelAnimationFrame(t),t=0,o.disconnect()}}}export function growCardToFitContent(e,i,n){const t=`${W(e,i)+n}px`;e.style.minHeight!==t&&(e.style.minHeight=t)}function W(e,i){const n=e.ownerDocument.defaultView??window,t=n.getComputedStyle(e);let o=0;for(const r of Array.from(e.children)){if(r===i)continue;const l=r,s=n.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(o+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return t.boxSizing==="border-box"&&(o+=(parseFloat(t.paddingTop)||0)+(parseFloat(t.paddingBottom)||0)+(parseFloat(t.borderTopWidth)||0)+(parseFloat(t.borderBottomWidth)||0)),o}function Z(e,i){const n=e.ownerDocument.defaultView??window;let t=0;for(const o of Array.from(e.children)){if(o===i)continue;const r=o,l=n.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(t+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return t}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,i,n){const t=e.toLocaleString(),o=e===1?"die":"dies";return n?e===i?`${t} ${o} ${n}`:`${t} of ${i.toLocaleString()} dies ${n} (partial and edge-excluded dies left out)`:`${t} ${o}`}export function setChartGrow(e,i){e.dataset.wmapChartGrow=i}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,i,n){const o=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(o.paddingTop)||0)-(parseFloat(o.paddingBottom)||0),l=o.boxSizing==="border-box"?(parseFloat(o.paddingTop)||0)+(parseFloat(o.paddingBottom)||0)+(parseFloat(o.borderTopWidth)||0)+(parseFloat(o.borderBottomWidth)||0):0;return r-(W(e,i)-l)-(n?Z(i,n):0)}export function fitRowsHeight(e,i,n,t,o=0){if(growCardToFitContent(e,i,o+n),e.dataset.wmapChartFullH=String(Math.ceil(W(e,i)+o+t)),!isExpandedCard(e))return n;const r=bodyRoom(e,i)-o;return Math.max(n,Math.min(t,Math.floor(r)))}export function chartFillHeight(e,i,n,t){const o=Z(i,n);return growCardToFitContent(e,i,o+t),Math.max(t,i.clientHeight-o)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,i,n,t){const o=chartDpr(e);e.width=Math.max(1,Math.floor(n*o)),e.height=Math.max(1,Math.floor(t*o)),e.style.width=`${n}px`,e.style.height=`${t}px`;const r=e.getContext("2d");return r?(r.setTransform(o,0,0,o,0,0),r.clearRect(0,0,n,t),r.font=`${F(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(i)}):null}export function applyCanvasFlow(e,i=0){let n;if(typeof i=="number")n=i;else{const t=(i.ownerDocument.defaultView??window).getComputedStyle(i);n=i.offsetTop+i.offsetHeight+(parseFloat(t.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${n}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:ue(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,i,n){if(!i&&n===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:t,axisLabel:o,scaledUnit:r}=pe(e,null,i,"engineering",n);return{tick:t,tickWithUnit:r?l=>`${t(l)} ${r}`:t,unitLabel:o}}const xe=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,i,n){return(t,o)=>{const r=makeAxisFormat(i,n,t).tick;return o.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+xe}}export function drawAxisUnit(e,i,n,t,o){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${F(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=o,e.fillText(`(${i})`,n,t),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(i=>i.replace(/[\s·]+$/,"").trim()).filter(i=>i&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(i)&&!/\(.*(click|drag).*\)/i.test(i)).join(" \xB7 ")}const M=(e,i)=>{for(let n=e;n&&n!==i.parentElement;n=n.parentElement)if(n.style.display==="none")return!1;return!0},be=/\s*[▾▼]\s*$/,_=new WeakMap;export function describeCard(e){const i=[],n=e.querySelector("[data-wmap-controls]");if(n){for(const l of n.querySelectorAll("button[aria-haspopup]")){if(!M(l,n))continue;const s=(l.textContent??"").replace(be,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";i.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of n.querySelectorAll('[role="radiogroup"]')){if(!M(l,n))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&i.push(a)}for(const l of n.querySelectorAll('input[type="checkbox"]:checked')){if(!M(l,n))continue;const s=l.closest("label")?.textContent?.trim();s&&i.push(s)}}const t=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!M(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&t.push(s)}const o=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&o.push({label:p,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&o.push({label:p,color:a})}const r=_.get(e)?.();return r&&(r.controls&&i.push(...r.controls),r.caption!==void 0&&(t.length=0,t.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(o.length=0,o.push(...r.legend))),{controls:i,captions:t,legend:o}}function ye(e){const i=describeCard(e),n=_.get(e)?.();return{controls:i.controls,caption:i.captions,legend:i.legend.length?i.legend:void 0,colorbar:n?.colorbar}}function J(e){for(const i of e.querySelectorAll("[data-wmap-chart-card]")){const n=i.querySelector(":scope > [data-wmap-print-only]");if(!n)continue;const t=describeCard(i);n.replaceChildren();const o=[t.controls.length?t.controls.join(" \xB7 "):"",...t.captions].filter(Boolean);for(const r of o){const l=e.createElement("div");l.textContent=r,n.appendChild(l)}for(const r of i.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const Q=new WeakSet;function we(e){if(Q.has(e))return;Q.add(e);const i=e.createElement("style");i.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(i);const n=e.defaultView;n?.addEventListener("beforeprint",()=>J(e));try{n?.matchMedia?.("print").addEventListener?.("change",t=>{t.matches&&J(e)})}catch{}}function Ce(e){const i=e.ownerDocument.defaultView;for(let n=e;n&&i;n=n.parentElement){const t=i.getComputedStyle(n).backgroundColor;if(t&&t!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(t))return t}return"#ffffff"}export function composeChartPng(e,i){const n=e.ownerDocument,t=n.createElement("canvas"),o=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=n.createElement("canvas").getContext("2d"),s=12*o,a=(g,y="400")=>`${y} ${g*o}px system-ui, -apple-system, "Segoe UI", sans-serif`,p=(g,y)=>l?(l.font=y,l.measureText(g).width):g.length*7*o,c=[];let d=0;if(i){d=s,c.push({kind:"text",text:i.title,x:s,y:d+14*o,font:a(16,"600"),alpha:1}),d+=24*o;const g=i.decor,y=[];g?.controls?.length&&y.push({text:g.controls.join(" \xB7 "),alpha:1});for(const m of g?.caption===void 0?[]:typeof g.caption=="string"?[g.caption]:g.caption)y.push({text:m,alpha:.75});const x=a(12);for(const{text:m,alpha:C}of y){let b="";for(const E of m.split(" ")){const O=b?`${b} ${E}`:E;b&&p(O,x)>r-2*s?(c.push({kind:"text",text:b,x:s,y:d+11*o,font:x,alpha:C}),d+=17*o,b=E):b=O}b&&(c.push({kind:"text",text:b,x:s,y:d+11*o,font:x,alpha:C}),d+=17*o)}if(g?.legend?.length){d+=4*o;const m=a(12);let C=s;for(const b of g.legend){const E=14*o+p(b.label,m)+14*o;C>s&&C+E>r-s&&(C=s,d+=18*o),c.push({kind:"dot",x:C+5*o,y:d+7*o,r:5*o,color:b.color}),c.push({kind:"text",text:b.label,x:C+14*o,y:d+11*o,font:m,alpha:1}),C+=E}d+=20*o}if(g?.colorbar){d+=4*o;const m=a(12),C=g.colorbar;let b=s;c.push({kind:"text",text:C.label,x:b,y:d+10*o,font:m,alpha:1}),b+=p(C.label,m)+10*o,c.push({kind:"text",text:C.lo,x:b,y:d+10*o,font:m,alpha:.75}),b+=p(C.lo,m)+6*o,c.push({kind:"strip",x:b,y:d+1*o,w:200*o,h:10*o,color:C.color}),b+=206*o,c.push({kind:"text",text:C.hi,x:b,y:d+10*o,font:m,alpha:.75}),d+=20*o}d+=6*o}t.width=r,t.height=Math.ceil(e.height+d);const u=t.getContext("2d");if(u.fillStyle=i?Ce(i.card):"#ffffff",u.fillRect(0,0,t.width,t.height),i){const g=n.defaultView,y=g&&g.getComputedStyle(i.card).color||"#222222";u.textBaseline="alphabetic";for(const x of c)if(x.kind==="text")u.font=x.font,u.fillStyle=y,u.globalAlpha=x.alpha,u.fillText(x.text,x.x,x.y),u.globalAlpha=1;else if(x.kind==="dot")u.fillStyle=x.color,u.beginPath(),u.arc(x.x,x.y,x.r,0,Math.PI*2),u.fill();else for(let m=0;m<x.w;m++)u.fillStyle=x.color(m/Math.max(1,x.w-1)),u.fillRect(x.x+m,x.y,1,x.h)}return u.drawImage(e,0,d),t}export function saveCanvasPng(e,i,n,t){composeChartPng(e,t).toBlob(o=>{o&&se(o,i,n)},"image/png")}const ee="10px";export function chartSwatchCss(e,i="solid"){return["display:inline-block",`width:${ee}`,`height:${ee}`,`border-radius:${T.pill}`,`background:${i==="outline"?"transparent":e}`,`border:1px ${i==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Se="0.35";export function makeSeriesLegendItem(e,i,n=document){const t=n.createElement("button");t.type="button",Object.assign(t.style,{display:"inline-flex",alignItems:"center",gap:w.xs,padding:`${w.xs} ${w.md}`,borderRadius:T.pill,border:`1px solid ${f.menuBorder}`,background:"none",cursor:"pointer",fontSize:L.body,color:f.text,whiteSpace:"nowrap"}),B(t,"bare");const o=n.createElement("span");return o.style.cssText=chartSwatchCss(i),t.append(o,n.createTextNode(e)),{el:t,setState({selected:r,dimmed:l}){t.style.borderColor=r?f.iconActive:f.menuBorder,t.style.fontWeight=r?"600":"400",t.style.opacity=l?Se:"1",t.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:f.menuBg,border:`1px solid ${f.menuBorder}`,borderRadius:T.container,padding:w.xl,fontVariantNumeric:"tabular-nums"}}export function cardShell(e,i,n=document){const t=n.createElement("div");t.dataset.wmapChartCard="1",t.dataset.wmapChartTitle=e,Object.assign(t.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const o=t.ownerDocument.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.sm,paddingBottom:"6px",marginBottom:w.md,borderBottom:`1px solid ${f.menuBorder}`});const r=t.ownerDocument.createElement("div");r.textContent=e,Object.assign(r.style,{color:f.value,fontSize:L.heading,fontWeight:"600",flex:"1"}),o.appendChild(r);const l=makeTooltip(t),s=t.ownerDocument.createElement("button");s.type="button",s.setAttribute("aria-label","Save as PNG"),s.innerHTML=X.download,Object.assign(s.style,{...j("outlined"),color:f.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(s),attachChartTip(s,t,l,"Save as PNG"),s.addEventListener("click",()=>{const u=t.querySelector("canvas");u&&saveCanvasPng(u,r.textContent||e,i,{card:t,title:r.textContent||e,decor:ye(t)})}),P(s),o.appendChild(s);const a=t.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=X.expand,Object.assign(a.style,{...j("outlined"),color:f.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(a),attachChartTip(a,t,l,"Expand"),a.dataset.wmapChartExpand="1",a.addEventListener("click",()=>openChartExpandModal(t,r.textContent??e)),P(a),o.appendChild(a),t.appendChild(o);const p=t.ownerDocument.createElement("div");p.dataset.wmapPrintOnly="1",Object.assign(p.style,{display:"none",color:f.label,fontSize:L.body,marginBottom:w.sm}),t.appendChild(p),we(t.ownerDocument);const c=t.ownerDocument.createElement("div");c.dataset.wmapControls="1",Object.assign(c.style,{display:"flex",gap:w.sm,marginBottom:w.md,flexWrap:"wrap",alignItems:"center"}),P(c),t.appendChild(c);const d=t.ownerDocument.createElement("div");return Object.assign(d.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),t.appendChild(d),{card:t,heading:r,controlsRow:c,body:d,setPngDecor:u=>{_.set(t,u)}}}export function makeSegmented(e,i,n,t=document,o=!1){const r=t.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",border:`1px solid ${f.menuBorder}`,borderRadius:T.control,overflow:"hidden"});const l=`seg-${Math.random().toString(36).slice(2,9)}`,s=[];return e.forEach(([a,p],c)=>{const d=t.createElement("label");Object.assign(d.style,{display:"inline-flex",alignItems:"center",fontSize:L.body,padding:o?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",borderLeft:c>0?`1px solid ${f.menuBorder}`:"none"}),B(d,"bare");const u=t.createElement("input");u.type="radio",u.name=l,u.value=a,u.checked=a===i,Object.assign(u.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const g=()=>{d.style.background=u.checked?f.bgActive:f.menuBg,d.style.color=u.checked?f.iconActive:f.text,d.dataset.on=u.checked?"true":"false"};s.push(g),g(),u.addEventListener("change",()=>{if(u.checked){for(const y of s)y();n(a)}}),d.append(u,t.createTextNode(p)),r.appendChild(d)}),r}export function makeBackButton(e,i=document){const n=i.createElement("button");return n.type="button",n.textContent="\u2190 Back",Object.assign(n.style,{...j("outlined"),background:f.menuBg,color:f.label}),B(n),n.addEventListener("click",e),n}export function renderEmptyState(e,i,n){const t=e.ownerDocument.createElement("div");t.textContent=i,Object.assign(t.style,{color:f.label,fontSize:L.body,padding:"8px 0"}),n&&Object.assign(t.style,n),e.appendChild(t)}export function makeListSelect(e,i,n,t={}){const{maxWidth:o="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:p}=t;let c=i;const d=k=>e.find(H=>H.value===k)?.label??"",u=r.createElement("button");u.type="button",p&&(u.dataset.wmapSelect=p),l&&u.setAttribute("aria-label",l),Object.assign(u.style,{fontSize:L.body,padding:`${w.xxs} ${w.sm}`,background:f.menuBg,color:f.text,border:`1px solid ${f.menuBorder}`,borderRadius:T.control,maxWidth:o,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:w.sm,justifyContent:"space-between"}),B(u),N(u,!1);const g=r.createElement("span");Object.assign(g.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const y=r.createElement("span");y.textContent="\u25BE",y.style.flex="0 0 auto",u.append(g,y);const x=()=>{g.textContent=e.length===0?s??"(none)":d(c)||s||"(none)"};if(x(),e.length===0)return u.disabled=!0,u.style.opacity="0.6",u.style.cursor="default",Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,x()}});let m=null;const C=()=>{m&&(m.remove(),m=null,N(u,!1))},b=()=>{C(),u.focus()};function E(){const k=u.getBoundingClientRect(),H=r.defaultView??window,z=Math.max(k.width,220),te=Math.min(k.left,Math.max(4,(H.innerWidth??1/0)-z-4));m=r.createElement("div"),m.setAttribute("role","listbox"),m.setAttribute("aria-label",l??"Options"),Object.assign(m.style,{position:"fixed",top:`${k.bottom+4}px`,left:`${te}px`,background:f.menuBg,border:`1px solid ${f.menuBorder}`,borderRadius:T.control,boxShadow:V.menu,zIndex:oe,minWidth:`${z}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const A=[],D=()=>A.filter(h=>h.row.style.display!=="none").map(h=>h.row),I=[],ne=()=>{for(const h of I)h.el.style.display=A.slice(h.first,h.last+1).some(S=>S.row.style.display!=="none")?"":"none"};if(e.length>U){const h=le(S=>{for(const v of A)v.row.style.display=v.label.includes(S)?"":"none";ne()},a,r);Object.assign(h.style,{position:"sticky",top:"0",zIndex:"1",background:f.menuBg}),h.addEventListener("keydown",S=>{if(S.key==="Escape"){b();return}S.key==="ArrowDown"&&(S.preventDefault(),D()[0]?.focus())}),m.appendChild(h)}let q;for(const h of e){if(h.group!==void 0&&h.group!==q){const $=r.createElement("div");$.textContent=h.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${w.sm} ${w.xl} ${w.xxs}`,fontSize:L.sub,color:f.label,fontWeight:"600"}),m.appendChild($),I.push({el:$,first:A.length,last:A.length})}q=h.group;const S=h.value===c,v=r.createElement("div");v.textContent=h.disabled?`${h.label} \u2014 ${h.disabled}`:h.label,v.setAttribute("role","option"),v.setAttribute("aria-selected",S?"true":"false"),h.disabled&&v.setAttribute("aria-disabled","true"),v.tabIndex=-1,Object.assign(v.style,{padding:`${w.sm} ${w.xl}`,fontSize:L.body,cursor:h.disabled?"default":"pointer",color:h.disabled?f.label:S?f.iconActive:f.text,fontWeight:S?"700":"400",opacity:h.disabled?"0.7":"",background:S?f.menuActive:"transparent",whiteSpace:"nowrap"}),v.addEventListener("mouseenter",()=>{!S&&!h.disabled&&(v.style.background=f.menuHover)}),v.addEventListener("mouseleave",()=>{S||(v.style.background="transparent")}),v.addEventListener("click",$=>{$.stopPropagation(),!h.disabled&&(c=h.value,x(),b(),n(h.value))}),m.appendChild(v),A.push({row:v,label:h.label.toLowerCase()}),I.length&&(I[I.length-1].last=A.length-1)}if(re(m,D,b),ie(u).appendChild(m),N(u,!0),e.length<=U){const h=e.findIndex(S=>S.value===c);D()[h>=0?h:0]?.focus()}}u.addEventListener("click",k=>{if(k.stopPropagation(),m){C();return}E()});const O=k=>{if(!u.isConnected){r.removeEventListener("click",O);return}m&&!m.contains(k.target)&&!u.contains(k.target)&&C()};return r.addEventListener("click",O),Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,x()}})}export function testOptionLabels(e){const i=e.some(n=>n.derived);return e.map(n=>(i&&!n.derived?me:"")+fe(n,n.testNumber))}export function makeTestSelect(e,i,n,t={}){const{maxWidth:o="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=t;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),i!==null?String(i):"",s=>n(Number(s)),{maxWidth:o,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,i,n,t=document){let o=i?.includeLimits,r=i?.clipOutliers??!1,l=i?.limits??"both";const s=()=>n({includeLimits:o,clipOutliers:r,limits:l});return{get:()=>({includeLimits:o,clipOutliers:r,limits:l}),sync(a,p,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,d=>{l=d,s()},t)),p&&e.appendChild(makeToggle("Axis includes limits",a,d=>{o=d,s()},t)),e.appendChild(makeToggle("Clip outliers",r,d=>{r=d,s()},t))},set(a){const p=a.limits??"both";return a.includeLimits===o&&a.clipOutliers===r&&p===l?!1:(o=a.includeLimits,r=a.clipOutliers,l=p,!0)}}}export function makeLinkedTestSelect(e,i,n,t={}){let o=i;const r=makeTestSelect(e,o,l=>{l!==o&&(o=l,n(l))},t);return{el:r,get:()=>o,set(l){return o===l||!e.some(s=>s.testNumber===l)?!1:(o=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,i,n,t,o={}){let r=n;const l=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(i,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const d=s(c);d!==r&&(r=d,t(d))},{...o,hook:"group-scope"}),p=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,p&&(p.value=l(c)),!0)}}}export function makeWaferSelect(e,i,n,t={}){const{maxWidth:o="160px",allLabel:r="All wafers",ownerDocument:l=document}=t,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,p)=>({value:String(p),label:a.label??`#${p}`}))],i===null?s:String(i),a=>n(a===s?null:Number(a)),{maxWidth:o,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,i,n,t=document){const o=t.createElement("label");Object.assign(o.style,{display:"inline-flex",alignItems:"center",gap:w.xs,fontSize:L.body,color:f.label,cursor:"pointer",userSelect:"none"}),B(o,"bare");const r=t.createElement("input");return r.type="checkbox",r.checked=i,r.style.cssText="margin:0;cursor:pointer;",r.addEventListener("change",()=>n(r.checked)),o.append(r,t.createTextNode(e)),o}export function makeLabeledSelect(e,i,n,t,o={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=o,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:f.label,fontSize:L.body,display:"flex",alignItems:"center",gap:w.xs});const p=makeListSelect(i,n,t,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(p),a}export function makeChartGridWrap(e=document){const i=e.createElement("div");return i.dataset.wmapChartGrid="1",Object.assign(i.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:w.lg,flex:"0 0 auto"}),i}export function makeTooltip(e){const i=e.ownerDocument.createElement("div");return Object.assign(i.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:T.control,padding:`${w.sm} ${w.xl}`,fontSize:L.sub,fontFamily:L.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:V.menu}),e.appendChild(i),i}export function attachChartTip(e,i,n,t){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=t),e.addEventListener("mouseenter",o=>{n.textContent=t,n.style.display="block",positionChartTooltip(n,i,o.clientX,o.clientY)}),e.addEventListener("mousemove",o=>{n.style.display==="block"&&positionChartTooltip(n,i,o.clientX,o.clientY)}),e.addEventListener("mouseleave",()=>{n.style.display="none"}),e.addEventListener("click",()=>{n.style.display="none"}),e.addEventListener("focus",()=>{n.textContent=t,n.style.display="block";const o=e.getBoundingClientRect();positionChartTooltip(n,i,o.left+o.width/2,o.bottom)}),e.addEventListener("blur",()=>{n.style.display="none"})}export function positionChartTooltip(e,i,n,t){const o=i.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let p=n-o.left+r,c=t-o.top+r;p+s+l>o.width&&(p=n-o.left-r-s),c+a+l>o.height&&(c=t-o.top-r-a),p=Math.max(l,p),c=Math.max(l,c),e.style.left=`${p}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"}},LIMIT_DASH={test:[3,3],spec:[10,4]},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 R(e,i){const[n,t]=i==="test"?[e?.limitLow,e?.limitHigh]:[e?.specLow,e?.specHigh],o=[];return n!==void 0&&Number.isFinite(n)&&o.push({value:n,kind:i,end:"lo",label:LIMIT_LABEL[i].lo}),t!==void 0&&Number.isFinite(t)&&o.push({value:t,kind:i,end:"hi",label:LIMIT_LABEL[i].hi}),o}export function hasBothLimitKinds(e){return R(e,"test").length>0&&R(e,"spec").length>0}export function limitLines(e,i="both"){if(i==="none")return[];const n=R(e,"test"),t=R(e,"spec"),o=i==="test"?n:i==="spec"?t:[...n,...t];return o.length?o:[...n,...t]}export function limitExtent(e){if(!e.length)return{};const i=e.map(n=>n.value);return{lo:ce(i),hi:de(i)}}export function stackLabelRows(e,i=4){const n=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),t=[],o=new Array(e.length).fill(0);for(const r of n){let l=t.findIndex(s=>r.start>=s+i);l===-1?(l=t.length,t.push(r.end)):t[l]=r.end,o[r.i]=l}return o}export function fillTextOnHalo(e,i,n,t,o){if(o){const r=e.measureText(i),l=2,s=e.fillStyle;e.fillStyle=o,e.fillRect(n-r.actualBoundingBoxLeft-l,t-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(i,n,t)}export function strokeLimitLine(e,i,n,t,o,r,l){e.save(),e.strokeStyle=n,e.lineWidth=1,e.setLineDash(LIMIT_DASH[i.kind]),e.beginPath(),e.moveTo(t,o),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,i,n=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,t=>i(t),{maxWidth:"170px",hook:"limits-shown",ownerDocument:n})}export{K as robustFence};export function shouldIncludeLimitsByDefault(e,i,n,t,o=1/3){if(n===void 0&&t===void 0||!Number.isFinite(e)||!Number.isFinite(i))return!1;const r=Math.min(e,n??e),s=Math.max(i,t??i)-r;if(s<=0)return!0;const a=i-e;return a===0?!0:a/s>=o}export function resolveAxisRange(e){const{dataMin:i,dataMax:n,limits:t=[],includeLimits:o,clipOutliers:r,values:l}=e;let s=i,a=n,p=0;if(r&&l?.length){const d=K(l);if(d){const u=Math.max(s,d.lo),g=Math.min(a,d.hi);g>u&&(p=l.filter(y=>Number.isFinite(y)&&(y<u||y>g)).length,s=u,a=g)}}if(o)for(const d of t)s=Math.min(s,d.value),a=Math.max(a,d.value);s===a&&(s-=1,a+=1);const c=[];for(const d of t)d.value<s?c.push({value:d.value,label:d.label,side:"lo"}):d.value>a&&c.push({value:d.value,label:d.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:p}}export function limitLabelSide(e,i,n,t,o,r=3){const l=o?-1:1;return(l<0?e-r-i>=n:e+r+i<=t)?l:-l}export function drawOffAxisLimits(e,i,n,t,o,r,l){if(!i.length)return;e.save(),e.fillStyle=o,e.font=`${F(-1)}px system-ui, sans-serif`;const s={lo:0,hi:0},a=F(-1)+2;for(const{value:p,label:c,side:d}of i){const u=s[d]++*a,g=t==="horizontal"?d==="lo"?"\u2190":"\u2192":d==="lo"?"\u2193":"\u2191",y=d==="lo"?`${g} ${c} ${r(p)}`:`${c} ${r(p)} ${g}`;t==="horizontal"?(e.textBaseline="top",e.textAlign=d==="lo"?"left":"right",fillTextOnHalo(e,y,d==="lo"?n.left+2:n.right-2,n.top+2+u,l)):(e.textBaseline=d==="lo"?"bottom":"top",e.textAlign="left",fillTextOnHalo(e,y,n.left+4,d==="lo"?n.bottom-2-u:n.top+2+u,l))}e.restore()}
1
+ import{SHADOW as V,LEADING as G,wireTooltip as U,wireControlHover as B,controlStyle as j,SPACE as w,RADIUS as T,fontPx as F,FONT as L,CLR as m,Z_BASE as ie,menuLayerFor as re,wireListNavigation as le,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as se,markMenuTrigger as N,markNoPrint as P,saveImageBlob as ae,openReparentedModal as ce}from"../toolbar.js";import{ICONS as K}from"../icons.js";import{minOf as de,maxOf as ue}from"../../core/utils.js";import{robustFence as Y}from"../../stats/math.js";import{fmt as pe,fmtColorbarAxis as fe}from"../../renderer/fmt.js";import{markedTestLabel as me,DERIVED_LANE_PAD as he}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,n={}){for(const s of e.querySelectorAll('div[style*="position: absolute"]'))s.style.display==="block"&&s.style.pointerEvents==="none"&&(s.style.display="none");const t=e.querySelector("[data-wmap-chart-expand]"),i=e.getAttribute("style")??"",r=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const l=ce([e],{title:o,anchor:n.anchor,ownerDocument:e.ownerDocument,boxSize:xe[r],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),t&&(t.style.display="flex"),n.onClosed?.()}});if(!l)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),null;if(t&&(t.style.display="none"),r==="rows"){const s=()=>{const a=Number(e.dataset.wmapChartFullH);if(!a)return;const p=l.box.offsetHeight-l.contentWrap.clientHeight;l.setNaturalHeight(`min(90vh, ${Math.ceil(p+a)}px)`)};s(),(e.ownerDocument.defaultView??window).requestAnimationFrame(s)}return l}const xe={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 n=e.trim();let t,i,r,l=1;const s=n.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=n.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const p=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[t,i,r]=[0,2,4].map(c=>parseInt(p.slice(c,c+2),16)),p.length===8&&(l=parseInt(p.slice(6,8),16)/255)}else if(a)[t,i,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(${t}, ${i}, ${r}, ${+(l*o).toFixed(3)})`}const ge={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309"},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"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),n={};for(const t of Object.keys(Z)){const i=o.getPropertyValue(`--wmap-${Z[t]}`).trim();n[t]=i||ge[t]}return n.grid=withAlpha(n.border,GRID_ALPHA),n}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const n=e.ownerDocument.defaultView??window;let t=0;const i=new n.ResizeObserver(()=>{t||(t=n.requestAnimationFrame(()=>{t=0,o()}))});return i.observe(e),{disconnect:()=>{t&&n.cancelAnimationFrame(t),t=0,i.disconnect()}}}export function growCardToFitContent(e,o,n){const t=`${W(e,o)+n}px`;e.style.minHeight!==t&&(e.style.minHeight=t)}function W(e,o){const n=e.ownerDocument.defaultView??window,t=n.getComputedStyle(e);let i=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=n.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(i+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return t.boxSizing==="border-box"&&(i+=(parseFloat(t.paddingTop)||0)+(parseFloat(t.paddingBottom)||0)+(parseFloat(t.borderTopWidth)||0)+(parseFloat(t.borderBottomWidth)||0)),i}function J(e,o){const n=e.ownerDocument.defaultView??window;let t=0;for(const i of Array.from(e.children)){if(i===o)continue;const r=i,l=n.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(t+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return t}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,n){const t=e.toLocaleString(),i=e===1?"die":"dies";return n?e===o?`${t} ${i} ${n}`:`${t} of ${o.toLocaleString()} dies ${n} (partial and edge-excluded dies left out)`:`${t} ${i}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,n){const i=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(i.paddingTop)||0)-(parseFloat(i.paddingBottom)||0),l=i.boxSizing==="border-box"?(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0):0;return r-(W(e,o)-l)-(n?J(o,n):0)}export function fitRowsHeight(e,o,n,t,i=0){if(growCardToFitContent(e,o,i+n),e.dataset.wmapChartFullH=String(Math.ceil(W(e,o)+i+t)),!isExpandedCard(e))return n;const r=bodyRoom(e,o)-i;return Math.max(n,Math.min(t,Math.floor(r)))}export function chartFillHeight(e,o,n,t){const i=J(o,n);return growCardToFitContent(e,o,i+t),Math.max(t,o.clientHeight-i)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,n,t){const i=chartDpr(e);e.width=Math.max(1,Math.floor(n*i)),e.height=Math.max(1,Math.floor(t*i)),e.style.width=`${n}px`,e.style.height=`${t}px`;const r=e.getContext("2d");return r?(r.setTransform(i,0,0,i,0,0),r.clearRect(0,0,n,t),r.font=`${F(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let n;if(typeof o=="number")n=o;else{const t=(o.ownerDocument.defaultView??window).getComputedStyle(o);n=o.offsetTop+o.offsetHeight+(parseFloat(t.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${n}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:pe(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,n){if(!o&&n===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:t,axisLabel:i,scaledUnit:r}=fe(e,null,o,"engineering",n);return{tick:t,tickWithUnit:r?l=>`${t(l)} ${r}`:t,unitLabel:i}}const be=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,n){return(t,i)=>{const r=makeAxisFormat(o,n,t).tick;return i.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+be}}export function drawAxisUnit(e,o,n,t,i){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${F(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=i,e.fillText(`(${o})`,n,t),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 M=(e,o)=>{for(let n=e;n&&n!==o.parentElement;n=n.parentElement)if(n.style.display==="none")return!1;return!0},ye=/\s*[▾▼]\s*$/,_=new WeakMap;export function describeCard(e){const o=[],n=e.querySelector("[data-wmap-controls]");if(n){for(const l of n.querySelectorAll("button[aria-haspopup]")){if(!M(l,n))continue;const s=(l.textContent??"").replace(ye,"").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 n.querySelectorAll('[role="radiogroup"]')){if(!M(l,n))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of n.querySelectorAll('input[type="checkbox"]:checked')){if(!M(l,n))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const t=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!M(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&t.push(s)}const i=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&i.push({label:p,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&i.push({label:p,color:a})}const r=_.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(t.length=0,t.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(i.length=0,i.push(...r.legend))),{controls:o,captions:t,legend:i}}function we(e){const o=describeCard(e),n=_.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:n?.colorbar}}function Q(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const n=o.querySelector(":scope > [data-wmap-print-only]");if(!n)continue;const t=describeCard(o);n.replaceChildren();const i=[t.controls.length?t.controls.join(" \xB7 "):"",...t.captions].filter(Boolean);for(const r of i){const l=e.createElement("div");l.textContent=r,n.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ee=new WeakSet;function Ce(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 n=e.defaultView;n?.addEventListener("beforeprint",()=>Q(e));try{n?.matchMedia?.("print").addEventListener?.("change",t=>{t.matches&&Q(e)})}catch{}}function Se(e){const o=e.ownerDocument.defaultView;for(let n=e;n&&o;n=n.parentElement){const t=o.getComputedStyle(n).backgroundColor;if(t&&t!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(t))return t}return"#ffffff"}export function composeChartPng(e,o){const n=e.ownerDocument,t=n.createElement("canvas"),i=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=n.createElement("canvas").getContext("2d"),s=12*i,a=(f,y="400")=>`${y} ${f*i}px system-ui, -apple-system, "Segoe UI", sans-serif`,p=(f,y)=>l?(l.font=y,l.measureText(f).width):f.length*7*i,c=[];let d=0;if(o){d=s,c.push({kind:"text",text:o.title,x:s,y:d+14*i,font:a(16,"600"),alpha:1}),d+=24*i;const f=o.decor,y=[];f?.controls?.length&&y.push({text:f.controls.join(" \xB7 "),alpha:1});for(const h of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)y.push({text:h,alpha:.75});const g=a(12);for(const{text:h,alpha:C}of y){let b="";for(const E of h.split(" ")){const O=b?`${b} ${E}`:E;b&&p(O,g)>r-2*s?(c.push({kind:"text",text:b,x:s,y:d+11*i,font:g,alpha:C}),d+=17*i,b=E):b=O}b&&(c.push({kind:"text",text:b,x:s,y:d+11*i,font:g,alpha:C}),d+=17*i)}if(f?.legend?.length){d+=4*i;const h=a(12);let C=s;for(const b of f.legend){const E=14*i+p(b.label,h)+14*i;C>s&&C+E>r-s&&(C=s,d+=18*i),c.push({kind:"dot",x:C+5*i,y:d+7*i,r:5*i,color:b.color}),c.push({kind:"text",text:b.label,x:C+14*i,y:d+11*i,font:h,alpha:1}),C+=E}d+=20*i}if(f?.colorbar){d+=4*i;const h=a(12),C=f.colorbar;let b=s;c.push({kind:"text",text:C.label,x:b,y:d+10*i,font:h,alpha:1}),b+=p(C.label,h)+10*i,c.push({kind:"text",text:C.lo,x:b,y:d+10*i,font:h,alpha:.75}),b+=p(C.lo,h)+6*i,c.push({kind:"strip",x:b,y:d+1*i,w:200*i,h:10*i,color:C.color}),b+=206*i,c.push({kind:"text",text:C.hi,x:b,y:d+10*i,font:h,alpha:.75}),d+=20*i}d+=6*i}t.width=r,t.height=Math.ceil(e.height+d);const u=t.getContext("2d");if(u.fillStyle=o?Se(o.card):"#ffffff",u.fillRect(0,0,t.width,t.height),o){const f=n.defaultView,y=f&&f.getComputedStyle(o.card).color||"#222222";u.textBaseline="alphabetic";for(const g of c)if(g.kind==="text")u.font=g.font,u.fillStyle=y,u.globalAlpha=g.alpha,u.fillText(g.text,g.x,g.y),u.globalAlpha=1;else if(g.kind==="dot")u.fillStyle=g.color,u.beginPath(),u.arc(g.x,g.y,g.r,0,Math.PI*2),u.fill();else for(let h=0;h<g.w;h++)u.fillStyle=g.color(h/Math.max(1,g.w-1)),u.fillRect(g.x+h,g.y,1,g.h)}return u.drawImage(e,0,d),t}export function saveCanvasPng(e,o,n,t){composeChartPng(e,t).toBlob(i=>{i&&ae(i,o,n)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${T.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const ve="0.35";export function makeSeriesLegendItem(e,o,n=document){const t=n.createElement("button");t.type="button",Object.assign(t.style,{display:"inline-flex",alignItems:"center",gap:w.xs,padding:`${w.xs} ${w.md}`,borderRadius:T.pill,border:`1px solid ${m.menuBorder}`,background:"none",cursor:"pointer",fontSize:L.body,color:m.text,whiteSpace:"nowrap"}),B(t,"bare");const i=n.createElement("span");return i.style.cssText=chartSwatchCss(o),t.append(i,n.createTextNode(e)),{el:t,setState({selected:r,dimmed:l}){t.style.borderColor=r?m.iconActive:m.menuBorder,t.style.fontWeight=r?"600":"400",t.style.opacity=l?ve:"1",t.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:m.menuBg,border:`1px solid ${m.menuBorder}`,borderRadius:T.container,padding:w.xl,fontVariantNumeric:"tabular-nums"}}export function cardShell(e,o,n=document){const t=n.createElement("div");t.dataset.wmapChartCard="1",t.dataset.wmapChartTitle=e,Object.assign(t.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const i=t.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",gap:w.sm,paddingBottom:"6px",marginBottom:w.md,borderBottom:`1px solid ${m.menuBorder}`});const r=t.ownerDocument.createElement("div");r.textContent=e,Object.assign(r.style,{color:m.value,fontSize:L.heading,fontWeight:"600",flex:"1"}),i.appendChild(r);const l=makeTooltip(t),s=t.ownerDocument.createElement("button");s.type="button",s.setAttribute("aria-label","Save as PNG"),s.innerHTML=K.download,Object.assign(s.style,{...j("outlined"),color:m.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(s),attachChartTip(s,t,l,"Save as PNG"),s.addEventListener("click",()=>{const u=t.querySelector("canvas");u&&saveCanvasPng(u,r.textContent||e,o,{card:t,title:r.textContent||e,decor:we(t)})}),P(s),i.appendChild(s);const a=t.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=K.expand,Object.assign(a.style,{...j("outlined"),color:m.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(a),attachChartTip(a,t,l,"Expand"),a.dataset.wmapChartExpand="1",a.addEventListener("click",()=>openChartExpandModal(t,r.textContent??e)),P(a),i.appendChild(a),t.appendChild(i);const p=t.ownerDocument.createElement("div");p.dataset.wmapPrintOnly="1",Object.assign(p.style,{display:"none",color:m.label,fontSize:L.body,marginBottom:w.sm}),t.appendChild(p),Ce(t.ownerDocument);const c=t.ownerDocument.createElement("div");c.dataset.wmapControls="1",Object.assign(c.style,{display:"flex",gap:w.sm,marginBottom:w.md,flexWrap:"wrap",alignItems:"center"}),P(c),t.appendChild(c);const d=t.ownerDocument.createElement("div");return Object.assign(d.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),t.appendChild(d),{card:t,heading:r,controlsRow:c,body:d,setPngDecor:u=>{_.set(t,u)}}}export function makeSegmented(e,o,n,t=document,i=!1){const r=t.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",border:`1px solid ${m.menuBorder}`,borderRadius:T.control,overflow:"hidden"});const l=`seg-${Math.random().toString(36).slice(2,9)}`,s=[];return e.forEach(([a,p,c],d)=>{const u=t.createElement("label");c&&U(u,c),Object.assign(u.style,{display:"inline-flex",alignItems:"center",fontSize:L.body,padding:i?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",borderLeft:d>0?`1px solid ${m.menuBorder}`:"none"}),B(u,"bare");const f=t.createElement("input");f.type="radio",f.name=l,f.value=a,f.checked=a===o,Object.assign(f.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const y=()=>{u.style.background=f.checked?m.bgActive:m.menuBg,u.style.color=f.checked?m.iconActive:m.text,u.dataset.on=f.checked?"true":"false"};s.push(y),y(),f.addEventListener("change",()=>{if(f.checked){for(const g of s)g();n(a)}}),u.append(f,t.createTextNode(p)),r.appendChild(u)}),r}export function makeBackButton(e,o=document){const n=o.createElement("button");return n.type="button",n.textContent="\u2190 Back",Object.assign(n.style,{...j("outlined"),background:m.menuBg,color:m.label}),B(n),n.addEventListener("click",e),n}export function renderEmptyState(e,o,n){const t=e.ownerDocument.createElement("div");t.textContent=o,Object.assign(t.style,{color:m.label,fontSize:L.body,padding:"8px 0"}),n&&Object.assign(t.style,n),e.appendChild(t)}export function makeListSelect(e,o,n,t={}){const{maxWidth:i="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:p}=t;let c=o;const d=k=>e.find(D=>D.value===k)?.label??"",u=r.createElement("button");u.type="button",p&&(u.dataset.wmapSelect=p),l&&u.setAttribute("aria-label",l),Object.assign(u.style,{fontSize:L.body,padding:`${w.xxs} ${w.sm}`,background:m.menuBg,color:m.text,border:`1px solid ${m.menuBorder}`,borderRadius:T.control,maxWidth:i,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:w.sm,justifyContent:"space-between"}),B(u),N(u,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const y=r.createElement("span");y.textContent="\u25BE",y.style.flex="0 0 auto",u.append(f,y);const g=()=>{f.textContent=e.length===0?s??"(none)":d(c)||s||"(none)"};if(g(),e.length===0)return u.disabled=!0,u.style.opacity="0.6",u.style.cursor="default",Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,g()}});let h=null;const C=()=>{h&&(h.remove(),h=null,N(u,!1))},b=()=>{C(),u.focus()};function E(){const k=u.getBoundingClientRect(),D=r.defaultView??window,z=Math.max(k.width,220),ne=Math.min(k.left,Math.max(4,(D.innerWidth??1/0)-z-4));h=r.createElement("div"),h.setAttribute("role","listbox"),h.setAttribute("aria-label",l??"Options"),Object.assign(h.style,{position:"fixed",top:`${k.bottom+4}px`,left:`${ne}px`,background:m.menuBg,border:`1px solid ${m.menuBorder}`,borderRadius:T.control,boxShadow:V.menu,zIndex:ie,minWidth:`${z}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const A=[],H=()=>A.filter(x=>x.row.style.display!=="none").map(x=>x.row),I=[],oe=()=>{for(const x of I)x.el.style.display=A.slice(x.first,x.last+1).some(S=>S.row.style.display!=="none")?"":"none"};if(e.length>X){const x=se(S=>{for(const v of A)v.row.style.display=v.label.includes(S)?"":"none";oe()},a,r);Object.assign(x.style,{position:"sticky",top:"0",zIndex:"1",background:m.menuBg}),x.addEventListener("keydown",S=>{if(S.key==="Escape"){S.preventDefault(),b();return}S.key==="ArrowDown"&&(S.preventDefault(),H()[0]?.focus())}),h.appendChild(x)}let q;for(const x of e){if(x.group!==void 0&&x.group!==q){const $=r.createElement("div");$.textContent=x.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${w.sm} ${w.xl} ${w.xxs}`,fontSize:L.sub,color:m.label,fontWeight:"600"}),h.appendChild($),I.push({el:$,first:A.length,last:A.length})}q=x.group;const S=x.value===c,v=r.createElement("div");v.textContent=x.disabled?`${x.label} \u2014 ${x.disabled}`:x.label,v.setAttribute("role","option"),v.setAttribute("aria-selected",S?"true":"false"),x.disabled&&v.setAttribute("aria-disabled","true"),v.tabIndex=-1,Object.assign(v.style,{padding:`${w.sm} ${w.xl}`,fontSize:L.body,cursor:x.disabled?"default":"pointer",color:x.disabled?m.label:S?m.iconActive:m.text,fontWeight:S?"700":"400",opacity:x.disabled?"0.7":"",background:S?m.menuActive:"transparent",whiteSpace:"nowrap"}),v.addEventListener("mouseenter",()=>{!S&&!x.disabled&&(v.style.background=m.menuHover)}),v.addEventListener("mouseleave",()=>{S||(v.style.background="transparent")}),v.addEventListener("click",$=>{$.stopPropagation(),!x.disabled&&(c=x.value,g(),b(),n(x.value))}),h.appendChild(v),A.push({row:v,label:x.label.toLowerCase()}),I.length&&(I[I.length-1].last=A.length-1)}if(le(h,H,b),re(u).appendChild(h),N(u,!0),e.length<=X){const x=e.findIndex(S=>S.value===c);H()[x>=0?x:0]?.focus()}}u.addEventListener("click",k=>{if(k.stopPropagation(),h){C();return}E()});const O=k=>{if(!u.isConnected){r.removeEventListener("click",O);return}h&&!h.contains(k.target)&&!u.contains(k.target)&&C()};return r.addEventListener("click",O),Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,g()}})}export function testOptionLabels(e){const o=e.some(n=>n.derived);return e.map(n=>(o&&!n.derived?he:"")+me(n,n.testNumber))}export function makeTestSelect(e,o,n,t={}){const{maxWidth:i="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=t;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>n(Number(s)),{maxWidth:i,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,n,t=document){let i=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>n({includeLimits:i,clipOutliers:r,limits:l});return{get:()=>({includeLimits:i,clipOutliers:r,limits:l}),sync(a,p,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,d=>{l=d,s()},t)),p&&e.appendChild(makeToggle("Axis includes limits",a,d=>{i=d,s()},t,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,d=>{r=d,s()},t,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const p=a.limits??"both";return a.includeLimits===i&&a.clipOutliers===r&&p===l?!1:(i=a.includeLimits,r=a.clipOutliers,l=p,!0)}}}export function makeLinkedTestSelect(e,o,n,t={}){let i=o;const r=makeTestSelect(e,i,l=>{l!==i&&(i=l,n(l))},t);return{el:r,get:()=>i,set(l){return i===l||!e.some(s=>s.testNumber===l)?!1:(i=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,n,t,i={}){let r=n;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 d=s(c);d!==r&&(r=d,t(d))},{...i,hook:"group-scope"}),p=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,p&&(p.value=l(c)),!0)}}}export function makeWaferSelect(e,o,n,t={}){const{maxWidth:i="160px",allLabel:r="All wafers",ownerDocument:l=document}=t,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,p)=>({value:String(p),label:a.label??`#${p}`}))],o===null?s:String(o),a=>n(a===s?null:Number(a)),{maxWidth:i,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,n,t=document,i){const r=t.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:w.xs,fontSize:L.body,color:m.label,cursor:"pointer",userSelect:"none"}),B(r,"bare");const l=t.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>n(l.checked)),r.append(l,t.createTextNode(e)),i&&U(r,i),r}export function makeLabeledSelect(e,o,n,t,i={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=i,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:m.label,fontSize:L.body,display:"flex",alignItems:"center",gap:w.xs});const p=makeListSelect(o,n,t,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(p),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:w.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:T.control,padding:`${w.sm} ${w.xl}`,fontSize:L.sub,fontFamily:L.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:V.menu}),e.appendChild(o),o}export function attachChartTip(e,o,n,t){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=t),e.addEventListener("mouseenter",i=>{n.textContent=t,n.style.display="block",positionChartTooltip(n,o,i.clientX,i.clientY)}),e.addEventListener("mousemove",i=>{n.style.display==="block"&&positionChartTooltip(n,o,i.clientX,i.clientY)}),e.addEventListener("mouseleave",()=>{n.style.display="none"}),e.addEventListener("click",()=>{n.style.display="none"}),e.addEventListener("focus",()=>{n.textContent=t,n.style.display="block";const i=e.getBoundingClientRect();positionChartTooltip(n,o,i.left+i.width/2,i.bottom)}),e.addEventListener("blur",()=>{n.style.display="none"})}export function positionChartTooltip(e,o,n,t){const i=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let p=n-i.left+r,c=t-i.top+r;p+s+l>i.width&&(p=n-i.left-r-s),c+a+l>i.height&&(c=t-i.top-r-a),p=Math.max(l,p),c=Math.max(l,c),e.style.left=`${p}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"}},LIMIT_DASH={test:[3,3],spec:[10,4]},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 R(e,o){const[n,t]=o==="test"?[e?.limitLow,e?.limitHigh]:[e?.specLow,e?.specHigh],i=[];return n!==void 0&&Number.isFinite(n)&&i.push({value:n,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),t!==void 0&&Number.isFinite(t)&&i.push({value:t,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),i}export function hasBothLimitKinds(e){return R(e,"test").length>0&&R(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const n=R(e,"test"),t=R(e,"spec"),i=o==="test"?n:o==="spec"?t:[...n,...t];return i.length?i:[...n,...t]}export function limitExtent(e){if(!e.length)return{};const o=e.map(n=>n.value);return{lo:de(o),hi:ue(o)}}export function placeClearOf(e,o,n,t=6){const i=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<t&&i(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+n,y1:r.y1+n};return e.push(r),r}export function stackLabelRows(e,o=4){const n=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),t=[],i=new Array(e.length).fill(0);for(const r of n){let l=t.findIndex(s=>r.start>=s+o);l===-1?(l=t.length,t.push(r.end)):t[l]=r.end,i[r.i]=l}return i}export function fillTextOnHalo(e,o,n,t,i){if(i){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=i,e.fillRect(n-r.actualBoundingBoxLeft-l,t-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,n,t)}export function strokeLimitLine(e,o,n,t,i,r,l){e.save(),e.strokeStyle=n,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(t,i),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,n=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,t=>o(t),{maxWidth:"170px",hook:"limits-shown",ownerDocument:n})}export{Y as robustFence};export function shouldIncludeLimitsByDefault(e,o,n,t,i=1/3){if(n===void 0&&t===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,n??e),s=Math.max(o,t??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=i}export function resolveAxisRange(e){const{dataMin:o,dataMax:n,limits:t=[],includeLimits:i,clipOutliers:r,values:l}=e;let s=o,a=n,p=0;if(r&&l?.length){const d=Y(l);if(d){const u=Math.max(s,d.lo),f=Math.min(a,d.hi);f>u&&(p=l.filter(y=>Number.isFinite(y)&&(y<u||y>f)).length,s=u,a=f)}}if(i)for(const d of t)s=Math.min(s,d.value),a=Math.max(a,d.value);s===a&&(s-=1,a+=1);const c=[];for(const d of t)d.value<s?c.push({value:d.value,label:d.label,side:"lo"}):d.value>a&&c.push({value:d.value,label:d.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:p}}export function limitLabelSide(e,o,n,t,i,r=3){const l=i?-1:1;return(l<0?e-r-o>=n:e+r+o<=t)?l:-l}export function drawOffAxisLimits(e,o,n,t,i,r,l){if(!o.length)return;e.save(),e.fillStyle=i,e.font=`${F(-1)}px system-ui, sans-serif`;const s={lo:0,hi:0},a=F(-1)+2;for(const{value:p,label:c,side:d}of o){const u=s[d]++*a,f=t==="horizontal"?d==="lo"?"\u2190":"\u2192":d==="lo"?"\u2193":"\u2191",y=d==="lo"?`${f} ${c} ${r(p)}`:`${c} ${r(p)} ${f}`;t==="horizontal"?(e.textBaseline="top",e.textAlign=d==="lo"?"left":"right",fillTextOnHalo(e,y,d==="lo"?n.left+2:n.right-2,n.top+2+u,l)):(e.textBaseline=d==="lo"?"bottom":"top",e.textAlign="left",fillTextOnHalo(e,y,n.left+4,d==="lo"?n.bottom-2-u:n.top+2+u,l))}e.restore()}
@@ -1 +1 @@
1
- import{buildCorrelationMatrix as vt,filterCorrelationMatrix as It,correlationSampleNote as $t}from"../../stats/correlation.js";import{maxOf as Tt}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as lt}from"./palette.js";import{buildFacetTable as St}from"../../stats/facets.js";import{wireControlHover as Dt,controlStyle as Rt,SPACE as v,RADIUS as rt,fontPx as dt,FONT as X,CLR as g}from"../toolbar.js";import{exportCsv as At}from"../tableExport.js";import{attachChartTip as kt,cardShell as _t,setChartGrow as Bt,isExpandedCard as Nt,bodyRoom as Ot,observeResize as Wt,makeTooltip as Ht,positionChartTooltip as Xt,makeWaferSelect as jt,renderEmptyState as zt,resolveChartCanvasColors as Ft,prepareCanvas as Vt,chartDpr as ut}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as mt,derivedCsvCell as pt,DERIVED_CSV_HEADER as ft,DERIVED_MARK as Pt,DERIVED_KEY as Yt}from"../../renderer/testLabel.js";const ht=5,xt=100,gt=20;function q(b){const d=b.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=b.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function Gt(b){const d=q(b);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function bt(b,d,h){const O=q(b);if(!O)return b;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),r=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${r})`}export function renderCorrelationPanel(b){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=b,{card:r,body:I,controlsRow:Q,setPngDecor:yt}=_t(d,J,b.ownerDocument);yt(()=>{const e=q(r.ownerDocument.defaultView?.getComputedStyle(r).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>bt(o<.5?lt:st,e,Math.abs(2*o-1))}}}),Bt(r,"square"),I.style.overflowX="auto",r.style.alignSelf="start";let V=gt,j=null;const z=r.ownerDocument.createElement("label");z.textContent="Max tests:",Object.assign(z.style,{color:g.label,fontSize:X.body,display:"flex",alignItems:"center",gap:v.xs});const E=r.ownerDocument.createElement("input");E.type="number",E.min=String(ht),E.max=String(xt),E.value=String(V),Object.assign(E.style,{width:"52px",fontSize:X.body,padding:`${v.xxs} ${v.xs}`,background:g.menuBg,color:g.value,border:`1px solid ${g.menuBorder}`,borderRadius:rt.control}),E.addEventListener("change",()=>{const e=Math.max(ht,Math.min(xt,parseInt(E.value,10)||gt));E.value=String(e),e!==V&&(V=e,tt())}),z.appendChild(E),Q.appendChild(z),h.length>1&&Q.appendChild(jt(h,j,e=>{j=e,tt()},{ownerDocument:r.ownerDocument}));function Ct(){return j!==null?h[j]?[h[j]]:[]:h}if(b.onSaveText){const e=r.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",Object.assign(e.style,{...Rt("outlined"),color:g.text}),Dt(e),e.addEventListener("click",()=>{const o=it;if(!o)return;const u=o.tests.some(s=>s.derived),m=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&m.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}At([{header:"Test X",get:s=>mt(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>mt(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...u?[{header:`Test X ${ft.toLowerCase()}`,get:s=>pt(s.x)},{header:`Test Y ${ft.toLowerCase()}`,get:s=>pt(s.y)}]:[]],m,"test-correlation.csv",b.onSaveText)}),Q.appendChild(e)}const k=r.ownerDocument.createElement("div");Object.assign(k.style,{display:"flex",flexDirection:"column",gap:v.xs,marginBottom:v.sm}),r.insertBefore(k,I);const $=Ht(r);kt(z,r,$,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function wt(e,o,u,m,s,a,y,x){k.innerHTML="";const _=$t(y);if(_){const p=r.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=`${_} \u2014 r is an estimate, not the whole population.`,Object.assign(p.style,{color:g.label,fontSize:X.body}),k.appendChild(p)}if(s.length>0){const p=r.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(p.style,{color:g.warnText,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:rt.control,padding:`${v.xs} ${v.md}`,fontSize:X.body}),k.appendChild(p)}const w=r.ownerDocument.createElement("span");Object.assign(w.style,{display:"inline-flex",alignItems:"center",gap:v.sm,color:g.label,fontSize:X.body,flexWrap:"wrap"});const B=r.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Pt} ${Yt} \xB7`:""),w.appendChild(B);const i=r.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:v.xs});const T=r.ownerDocument.createElement("span");T.textContent="\u22121";const P=r.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:rt.control,border:`1px solid ${g.menuBorder}`,background:`linear-gradient(to right, ${lt}, ${g.menuBg}, ${st})`});const F=r.ownerDocument.createElement("span");F.textContent="+1",i.append(T,P,F),w.appendChild(i),k.appendChild(w);const L=r.ownerDocument.createElement("span");if(L.dataset.wmapCaption="1",Object.assign(L.style,{color:g.value,fontSize:X.body,fontWeight:"500"}),e===0&&o===0)L.textContent=m?`No significant correlations found \u2014 strongest pair: ${m.xLabel} \u2194 ${m.yLabel} (r = ${m.r.toFixed(2)})`:"No significant correlations found";else{const p=[];e>0&&p.push(`${e} strong (|r| \u2265 0.7)`),o>0&&p.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let l=p.join(", ")+` pair${Y!==1?"s":""} found`;u>0&&(l+=` \xB7 ${u} weak pair${u!==1?"s":""} not shown`),L.textContent=l}k.appendChild(L)}function Mt(e){if(I.innerHTML="",e.tests.length<2)return zt(I,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=r.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",I.appendChild(o);const u=e.tests.length,m=l=>l.label.split(" (#")[0],s=Math.min(14,Tt(e.tests.map(l=>m(l).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,_=14,w=28,B=44;let i=-1,T=-1;const P=96;function F(l){const c=Math.max(0,l-a),f=Math.floor(c/u);if(!Nt(r))return Math.max(_,Math.min(B,f));const n=Math.floor((Ot(r,I,o)-x-4)/u);return Math.max(_,Math.min(P,f,n))}const L=new Map;for(const l of e.cells){let c=L.get(l.yIndex);c||(c=[],L.set(l.yIndex,c)),c.push(l)}function p(){const l=Ft(r),c=q(l.bg)??[255,255,255],f=I.clientWidth,n=F(f),H=n*u,S=x+n*u+4,D=a+H,R=Vt(o,r,D,S);if(!R)return;const{ctx:t}=R;t.font=`${dt(-1)}px system-ui, sans-serif`,t.fillStyle=l.text,e.tests.forEach((A,C)=>{const M=m(A),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+C*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=C===i?l.text:l.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((A,C)=>{const M=m(A),N=x+C*n,et=N+n/2;t.font=`${dt(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=C===T?l.text:l.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(L.get(C)??[]).forEach(at=>{const nt=at.xIndex,G=a+nt*n,Lt=nt===i&&C===T,ct=nt===C,U=at.r;if(U===null){t.fillStyle=l.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=l.bgHover;ct?t.fillStyle=l.bgHover:(ot=bt(U>=0?st:lt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=w&&!ct&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=Gt(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),Lt&&(t.strokeStyle=l.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=l.bg,t.lineWidth=1;for(let A=0;A<=u;A++){const C=a+A*n;t.beginPath(),t.moveTo(C,x),t.lineTo(C,x+u*n),t.stroke();const M=x+A*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+u*n,M),t.stroke()}}function Y(l){const c=o.getBoundingClientRect(),f=I.clientWidth,n=F(f),H=(l.clientX-c.left)*(o.width/ut(o)/c.width),S=(l.clientY-c.top)*(o.height/ut(o)/c.height),D=Math.floor((H-a)/n),R=Math.floor((S-x)/n);return D>=0&&D<u&&R>=0&&R<u?{xi:D,yi:R}:null}return o.addEventListener("mousemove",l=>{const c=Y(l);if(!c){$.style.display="none",o.style.cursor="default";return}const{xi:f,yi:n}=c,H=f===n;o.style.cursor=H||!W?"default":"pointer";const S=e.cells.find(t=>t.xIndex===f&&t.yIndex===n),D=e.tests[f].label,R=e.tests[n].label;H?$.innerHTML=`<strong>${K(D)}</strong>`:S?.r!==null&&S?.r!==void 0?$.innerHTML=`<strong>${K(m(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(m(e.tests[f]))}</strong> (#${e.tests[f].testNumber})<br>r = ${S.r.toFixed(4)} \xB7 n = ${S.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:$.innerHTML=`${K(`${R} vs ${D}`)}<br><em>insufficient data</em>`,$.style.display="block",Xt($,r,l.clientX,l.clientY)}),o.addEventListener("mouseleave",()=>{$.style.display="none"}),o.addEventListener("click",l=>{const c=Y(l);if(!c||!W)return;const{xi:f,yi:n}=c;f!==n&&(i=f,T=n,p(),W(e.tests[f].testNumber,e.tests[n].testNumber))}),p}let it=null;function tt(){const e=Ct(),o=e.flatMap(i=>i.dies??[]),u=vt(o,O),{matrix:m,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=It(u,{minTests:6,maxTests:V}),_=St(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),w=m.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,T)=>i-T),B=w.length?w[Math.floor(w.length/2)]:null;it=m,wt(s,a,y,x,_,B,u.sample,m.tests.some(i=>i.derived)),Z=Mt(m),Z()}const Et=Wt(r,()=>Z());return tt(),{card:r,destroy:()=>Et.disconnect()}}
1
+ import{buildCorrelationMatrix as $t,filterCorrelationMatrix as It,correlationSampleNote as Tt}from"../../stats/correlation.js";import{maxOf as St}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Dt}from"../../stats/facets.js";import{wireControlHover as Rt,wireTooltip as pt,controlStyle as At,SPACE as L,RADIUS as lt,fontPx as ft,FONT as j,CLR as g}from"../toolbar.js";import{exportCsv as kt}from"../tableExport.js";import{attachChartTip as _t,cardShell as Bt,setChartGrow as Nt,isExpandedCard as Ot,bodyRoom as Wt,observeResize as Ht,makeTooltip as Xt,positionChartTooltip as jt,makeWaferSelect as Vt,renderEmptyState as zt,resolveChartCanvasColors as Ft,prepareCanvas as Pt,chartDpr as ut}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as gt,DERIVED_MARK as Yt,DERIVED_KEY as Gt}from"../../renderer/testLabel.js";const it=5,at=100,bt=20;function q(b){const d=b.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=b.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function Ut(b){const d=q(b);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(b,d,h){const O=q(b);if(!O)return b;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(b){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=b,{card:l,body:$,controlsRow:Q,setPngDecor:wt}=Bt(d,J,b.ownerDocument);wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Nt(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=bt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",pt(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:g.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:g.menuBg,color:g.value,border:`1px solid ${g.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||bt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(Vt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Ct(){return V!==null?h[V]?[h[V]]:[]:h}if(b.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",pt(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...At("outlined"),color:g.text}),Rt(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),p=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&p.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}kt([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${gt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${gt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],p,"test-correlation.csv",b.onSaveText)}),Q.appendChild(e)}const k=l.ownerDocument.createElement("div");Object.assign(k.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(k,$);const I=Xt(l);_t(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Mt(e,o,m,p,s,a,y,x){k.innerHTML="";const _=Tt(y);if(_){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`${_} \u2014 r is an estimate, not the whole population.`,Object.assign(f.style,{color:g.label,fontSize:j.body}),k.appendChild(f)}if(s.length>0){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(f.style,{color:g.warnText,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),k.appendChild(f)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:g.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Yt} ${Gt} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const T=l.ownerDocument.createElement("span");T.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${g.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${g.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(T,P,z),C.appendChild(i),k.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:g.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=p?`No significant correlations found \u2014 strongest pair: ${p.xLabel} \u2194 ${p.yLabel} (r = ${p.r.toFixed(2)})`:"No significant correlations found";else{const f=[];e>0&&f.push(`${e} strong (|r| \u2265 0.7)`),o>0&&f.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=f.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}k.appendChild(v)}function Et(e){if($.innerHTML="",e.tests.length<2)return zt($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,p=r=>r.label.split(" (#")[0],s=Math.min(14,St(e.tests.map(r=>p(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,_=14,C=28,B=44;let i=-1,T=-1;const P=96;function z(r){const c=Math.max(0,r-a),u=Math.floor(c/m);if(!Ot(l))return Math.max(_,Math.min(B,u));const n=Math.floor((Wt(l,$,o)-x-4)/m);return Math.max(_,Math.min(P,u,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function f(){const r=Ft(l),c=q(r.bg)??[255,255,255],u=$.clientWidth,n=z(u),X=n*m,S=x+n*m+4,D=a+X,R=Pt(o,l,D,S);if(!R)return;const{ctx:t}=R;t.font=`${ft(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((A,w)=>{const M=p(A),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((A,w)=>{const M=p(A),N=x+w*n,et=N+n/2;t.font=`${ft(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===T?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,Lt=nt===i&&w===T,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=Ut(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),Lt&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let A=0;A<=m;A++){const w=a+A*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+A*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),u=$.clientWidth,n=z(u),X=(r.clientX-c.left)*(o.width/ut(o)/c.width),S=(r.clientY-c.top)*(o.height/ut(o)/c.height),D=Math.floor((X-a)/n),R=Math.floor((S-x)/n);return D>=0&&D<m&&R>=0&&R<m?{xi:D,yi:R}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:u,yi:n}=c,X=u===n;o.style.cursor=X||!W?"default":"pointer";const S=e.cells.find(t=>t.xIndex===u&&t.yIndex===n),D=e.tests[u].label,R=e.tests[n].label;X?I.innerHTML=`<strong>${K(D)}</strong>`:S?.r!==null&&S?.r!==void 0?I.innerHTML=`<strong>${K(p(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(p(e.tests[u]))}</strong> (#${e.tests[u].testNumber})<br>r = ${S.r.toFixed(4)} \xB7 n = ${S.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${R} vs ${D}`)}<br><em>insufficient data</em>`,I.style.display="block",jt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:u,yi:n}=c;u!==n&&(i=u,T=n,f(),W(e.tests[u].testNumber,e.tests[n].testNumber))}),f}let ct=null;function tt(){const e=Ct(),o=e.flatMap(i=>i.dies??[]),m=$t(o,O),{matrix:p,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=It(m,{minTests:6,maxTests:F}),_=Dt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=p.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,T)=>i-T),B=C.length?C[Math.floor(C.length/2)]:null;ct=p,Mt(s,a,y,x,_,B,m.sample,p.tests.some(i=>i.derived)),Z=Et(p),Z()}const vt=Ht(l,()=>Z());return tt(),{card:l,destroy:()=>vt.disconnect()}}
@@ -1 +1 @@
1
- import{buildTestHistogramData as Zt,collectTestValues as Ct,buildTestHistogramSeries as te,testValueExtent as Bt,diesInBucket as At}from"../../stats/histogram.js";import{SPACE as lt,fontPx as N,FONT as $t,CLR as Et}from"../toolbar.js";import{fmt as xt}from"../../renderer/fmt.js";import{niceStep as ee,fitTicks as Wt}from"../../renderer/axisTicks.js";import{QUANTITY as ne,categorical as ie}from"./palette.js";import{cardShell as oe,observeResize as Dt,makeTooltip as se,attachChartTip as le,positionChartTooltip as It,makeLinkedTestSelect as ae,makeWaferSelect as re,makeLinkedAxisPrefs as ce,renderEmptyState as kt,chartFillHeight as Pt,applyCanvasFlow as Rt,makeAxisFormat as Tt,horizontalTickSpacing as Kt,PADDING as mt,robustFence as Nt,shouldIncludeLimitsByDefault as Ot,drawOffAxisLimits as ue,resolveAxisRange as de,limitLines as Ft,limitExtent as me,hasBothLimitKinds as he,stackLabelRows as fe,strokeLimitLine as ge,chartSwatchCss as pe,makeSeriesLegendItem as xe,prepareCanvas as zt}from"./chartShell.js";import{escHtml as wt,maxOf as be}from"../../core/utils.js";const Mt=230,Gt=36,ye=18;function Vt(n){const $=new Set(n.map(E=>E.kind)).size;return ye+Math.max(0,$-1)*(N(-1)+2)}function jt(n,$,E,V,et,S,l){n.font=`${N(-1)}px system-ui, sans-serif`;const x=$.filter(i=>!E.has(i.value)).map(i=>{const k=V(i.value),W=n.measureText(i.label).width;return{l:i,x:k,start:k-W/2,end:k+W/2}}),U=fe(x),nt=N(-1)+2;x.forEach(({l:i,x:k},W)=>{ge(n,i,l,k,et,k,S),n.fillStyle=l,n.textAlign="center",n.textBaseline="bottom",n.fillText(i.label,k,et-2-U[W]*nt)})}function Xt(n,$,E,V,et,S,l,x=4){const U=Math.max(1,ee(S/x)),nt=V-E;n.save(),n.font=`${N(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(let i=0;i<=S+1e-9;i+=U){const k=V-i/(S||1)*nt;n.strokeStyle=l.grid,n.lineWidth=1,n.beginPath(),n.moveTo($,k),n.lineTo($+et,k),n.stroke(),n.fillStyle=l.text,n.fillText(String(Math.round(i)),$-4,k)}n.strokeStyle=l.axis,n.lineWidth=1,n.beginPath(),n.moveTo($,E),n.lineTo($,V),n.stroke(),n.restore()}export function renderHistogramPanel(n){const{title:$="Test value distribution",items:E,testDefs:V,onSaveImage:et,groups:S}=n,{card:l,body:x,controlsRow:U}=oe($,et,n.ownerDocument),nt=V.filter(c=>c.testNumber!==void 0);let i=n.selectedTestNumber??nt[0]?.testNumber??null,k=null,W=0,ht;const vt=ae(nt,i,c=>{i=c,q(),n.onTestChange?.(c)},{maxWidth:"200px",ownerDocument:l.ownerDocument}),_t=vt.el;U.appendChild(_t);const ft=E.length>1?re(E,k,c=>{k=c,q()},{ownerDocument:l.ownerDocument}):null;ft&&U.appendChild(ft);function Yt(c){return b===c||c!==null&&!(S??[]).some(L=>L.key===c)?!1:(b=c,q(),!0)}const bt=l.ownerDocument.createElement("span");Object.assign(bt.style,{display:"inline-flex",gap:lt.lg,alignItems:"center"}),U.appendChild(bt);const at=ce(bt,n.axisPrefs,c=>{n.onAxisPrefsChange?.(c),q()},l.ownerDocument),C=se(l);let rt=null,b=null;function it(c){const L=V.find(I=>I.testNumber===c),j=Ft(L,at.get().limits),{lo:T,hi:w}=me(j);return{unit:L?.unit,lines:j,limitLow:T,limitHigh:w,hasLimits:Ft(L).length>0,hasBothKinds:he(L)}}function q(){const{includeLimits:c,clipOutliers:L}=at.get();if(rt?.disconnect(),rt=null,x.innerHTML="",i===null){kt(x,"No parametric test data available for a histogram.");return}const j=!!S&&S.length>0;let T=!1,w;if(j){const{limitLow:u,limitHigh:m}=it(i),g=S.flatMap(r=>r.items),{min:e,max:p}=Bt(g,i);if(T=c??Ot(e,p,u,m),L){const r=Ct(g,i),h=Nt(r);h&&(w={lo:Math.max(e,h.lo),hi:Math.min(p,h.hi)},W=r.reduce((Z,K)=>Z+(K<w.lo||K>w.hi?1:0),0))}w||(W=0),ht=w}const I=j?te(S,i,16,T?it(i).limitLow:void 0,T?it(i).limitHigh:void 0,w):null;if(ft&&(ft.style.display=I?"none":""),I){const{hasLimits:u,hasBothKinds:m}=it(i);if(at.sync(T,u,m),I.series.length===0){kt(x,"No parametric test data available for a histogram.");return}Qt(I);return}const O=k!==null?[E[k]]:E,{unit:D,lines:X,limitLow:M,limitHigh:_,hasLimits:ct,hasBothKinds:gt}=it(i),ut=Ct(O,i),{min:dt,max:pt}=Bt(O,i),P=c??Ot(dt,pt,M,_);at.sync(P,ct,gt);const ot=L?Nt(ut):null,R=ot?{lo:Math.max(dt,ot.lo),hi:Math.min(pt,ot.hi)}:void 0;W=R?ut.filter(u=>u<R.lo||u>R.hi).length:0,ht=R;const y=Zt(O,i,16,P?M:void 0,P?_:void 0,R);if(y.length===0){kt(x,"No parametric test data available for a histogram.");return}const o=Math.max(be(y.map(u=>u.count)),1),d=l.ownerDocument.createElement("div");d.dataset.wmapCaption="1",Object.assign(d.style,{fontSize:$t.body,color:Et.label,marginBottom:lt.xxs}),d.textContent=`max ${o} dies/bucket`+(W?` \xB7 ${W} value${W===1?"":"s"} outside clipped range`:"")+(n.onSelectBucket?" \xB7 click a bar to chart or tabulate its dies":""),x.appendChild(d);const s=l.ownerDocument.createElement("canvas");s.style.display="block",s.style.cursor="default",x.appendChild(s);let t=-1;const a=y[0].rangeLow,f=y[y.length-1].rangeHigh,H=f-a||1,F=Math.max(Math.abs(a),Math.abs(f));function J(u){const m=mt+36,g=s.clientWidth-m-mt,e=Vt(X),p=u-Gt-e;return{plotX:m,plotMaxWidth:Math.max(10,g),plotMaxHeight:p,plotTop:e}}function v(u){const{plotX:m,plotMaxWidth:g}=J(Mt);if(u<m||u>m+g)return-1;const e=Math.floor((u-m)/g*y.length);return e>=0&&e<y.length?e:-1}function A(){Rt(s,d);const u=x.clientWidth,m=Pt(l,x,s,Mt),g=zt(s,l,u,m);if(!g)return;const{ctx:e,theme:p}=g,{plotX:r,plotMaxWidth:h,plotMaxHeight:Z,plotTop:K}=J(m),B=K+Z,tt=h/y.length;Xt(e,r,K,B,h,o,{text:p.textMuted,axis:p.border,grid:p.grid}),y.forEach((G,Q)=>{const St=G.count/o*Z,Lt=r+Q*tt,Ht=B-St;e.fillStyle=Q===t?p.text:ne,e.globalAlpha=Q===t?1:.7,e.fillRect(Lt+1,Ht,Math.max(1,tt-2),St),e.globalAlpha=1,Q===t&&(e.fillStyle=p.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(`${G.count}`,Lt+tt/2,Ht-2))});const st=G=>r+(G-a)/H*h;e.font=`${N(-1)}px system-ui, sans-serif`;const{offAxis:z}=de({dataMin:a,dataMax:f,limits:X,includeLimits:!1});ue(e,z,{left:r,right:r+h,top:K,bottom:B},"horizontal",p.limitLine,Tt(F,D).tick),jt(e,X,new Set(z.map(G=>G.value)),st,K,B,p.limitLine),e.font=`${N(-1)}px system-ui, sans-serif`,e.strokeStyle=p.border,e.lineWidth=1,e.beginPath(),e.moveTo(r,B),e.lineTo(r+h,B),e.stroke(),e.fillStyle=p.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:Y,step:Jt}=Wt(a,f,h,Kt(e,F,D)),yt=Tt(F,D,Jt||void 0);for(const G of Y){const Q=r+(G-a)/H*h;e.beginPath(),e.moveTo(Q,B),e.lineTo(Q,B+4),e.stroke(),e.fillText(yt.tick(G),Q,B+6)}yt.unitLabel&&(e.save(),e.font=`${N(-1)}px system-ui, sans-serif`,e.fillStyle=p.textMuted,e.textAlign="right",e.textBaseline="top",e.fillText(`(${yt.unitLabel})`,r+h,B+20),e.restore())}s.addEventListener("mousemove",u=>{const m=s.getBoundingClientRect(),g=v(u.clientX-m.left);if(g!==t&&(t=g,A()),g>=0){const e=y[g];C.innerHTML=`<strong>${wt(`${xt(e.rangeLow,D,"engineering")} \u2013 ${xt(e.rangeHigh,D,"engineering")}`)}</strong><br>${e.count} dies`+(n.onSelectBucket&&e.count>0?"<br><em>click to chart or tabulate these dies</em>":""),C.style.display="block",It(C,l,u.clientX,u.clientY)}else C.style.display="none"}),s.addEventListener("mouseleave",()=>{t!==-1&&(t=-1,A()),C.style.display="none"}),n.onSelectBucket&&(s.style.cursor="pointer",s.addEventListener("click",u=>{const m=v(u.clientX-s.getBoundingClientRect().left);if(m<0||i===null||y[m].count===0)return;const g=At(O,i,y,m,ht);g.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:y[m].rangeLow,high:y[m].rangeHigh,items:g},u))})),rt=Dt(l,()=>A()),A()}function Qt(c){const{unit:L,lines:j}=it(i),T=c.ranges,w=c.series,I=ie;b&&!w.some(o=>o.groupKey===b)&&(b=null);const O=Math.max(1,...w.flatMap(o=>o.counts)),D=l.ownerDocument.createElement("div");D.dataset.wmapCaption="1",Object.assign(D.style,{fontSize:$t.body,color:Et.label,marginBottom:lt.xxs}),D.textContent=`${w.length} groups \xB7 max ${O} dies/bucket`+(n.onSelectBucket?" \xB7 click a column to chart or tabulate its dies":""),x.appendChild(D);const X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:lt.sm,marginTop:lt.md,marginBottom:lt.xl}),w.forEach((o,d)=>{const s=xe(o.groupKey,I(d),l.ownerDocument),t=s.el;le(t,l,C,`${o.groupKey} \u2014 click to emphasize (dim the rest)`),s.setState({selected:b===o.groupKey,dimmed:b!==null&&b!==o.groupKey}),t.addEventListener("click",()=>{const a=b===o.groupKey?null:o.groupKey;Yt(a),n.onGroupChange?.(a)}),X.appendChild(t)}),x.appendChild(X);const M=l.ownerDocument.createElement("canvas");M.style.display="block",M.style.cursor="default",x.appendChild(M);const _=T[0].rangeLow,ct=T[T.length-1].rangeHigh,gt=ct-_||1,ut=Math.max(Math.abs(_),Math.abs(ct)),dt=o=>{const d=(o.ownerDocument.defaultView??window).getComputedStyle(o);return o.offsetHeight+(parseFloat(d.marginTop)||0)+(parseFloat(d.marginBottom)||0)},pt=()=>dt(D)+dt(X);let P=-1,ot={plotX:mt+36,plotMaxWidth:10,barWidth:10};function R(){Rt(M,pt());const o=x.clientWidth,d=Pt(l,x,M,Mt),s=zt(M,l,o,d);if(!s)return;const{ctx:t,theme:a}=s,f=mt+36,H=Math.max(10,o-f-mt),F=Vt(j),J=d-Gt-F,v=F+J,A=H/T.length;ot={plotX:f,plotMaxWidth:H,barWidth:A},Xt(t,f,F,v,H,O,{text:a.textMuted,axis:a.border,grid:a.grid}),P>=0&&(t.fillStyle=a.bgHover,t.globalAlpha=.5,t.fillRect(f+P*A,F,A,J),t.globalAlpha=1);const u=w.map((r,h)=>({s:r,i:h})).sort((r,h)=>(r.s.groupKey===b?1:0)-(h.s.groupKey===b?1:0));for(const{s:r,i:h}of u){const Z=b===r.groupKey,K=b!==null&&!Z,B=I(h);t.strokeStyle=B,t.fillStyle=B,t.lineWidth=Z?2:1,t.globalAlpha=K?.12:b?.32:.22,t.beginPath(),t.moveTo(f,v),r.counts.forEach((tt,st)=>{const z=f+st*A,Y=v-tt/O*J;t.lineTo(z,Y),t.lineTo(z+A,Y)}),t.lineTo(f+H,v),t.closePath(),t.fill(),t.globalAlpha=K?.3:1,t.beginPath(),r.counts.forEach((tt,st)=>{const z=f+st*A,Y=v-tt/O*J;st===0?t.moveTo(z,Y):t.lineTo(z,Y),t.lineTo(z+A,Y)}),t.stroke()}t.globalAlpha=1;const m=r=>f+(r-_)/gt*H;t.font=`${N(-1)}px system-ui, sans-serif`,jt(t,j,new Set,m,F,v,a.limitLine),t.font=`${N(-1)}px system-ui, sans-serif`,t.strokeStyle=a.border,t.lineWidth=1,t.beginPath(),t.moveTo(f,v),t.lineTo(f+H,v),t.stroke(),t.fillStyle=a.textMuted,t.textAlign="center",t.textBaseline="top";const{ticks:g,step:e}=Wt(_,ct,H,Kt(t,ut,L)),p=Tt(ut,L,e||void 0);for(const r of g){const h=f+(r-_)/gt*H;t.beginPath(),t.moveTo(h,v),t.lineTo(h,v+4),t.stroke(),t.fillText(p.tick(r),h,v+6)}p.unitLabel&&(t.save(),t.font=`${N(-1)}px system-ui, sans-serif`,t.fillStyle=a.textMuted,t.textAlign="right",t.textBaseline="top",t.fillText(`(${p.unitLabel})`,f+H,v+20),t.restore())}function y(o){const{plotX:d,plotMaxWidth:s,barWidth:t}=ot;if(o<d||o>d+s)return-1;const a=Math.floor((o-d)/t);return a>=0&&a<T.length?a:-1}M.addEventListener("mousemove",o=>{const d=M.getBoundingClientRect(),s=y(o.clientX-d.left);if(s!==P&&(P=s,R()),s>=0){const t=T[s],a=w.map((f,H)=>`<span style="${pe(I(H))};margin-right:4px"></span>${wt(`${f.groupKey}: ${f.counts[s]}`)}`).join("<br>");C.innerHTML=`<strong>${wt(`${xt(t.rangeLow,L,"engineering")} \u2013 ${xt(t.rangeHigh,L,"engineering")}`)}</strong><br>${a}`,C.style.display="block",It(C,l,o.clientX,o.clientY)}else C.style.display="none"}),M.addEventListener("mouseleave",()=>{P!==-1&&(P=-1,R()),C.style.display="none"}),n.onSelectBucket&&S&&(M.style.cursor="pointer",M.addEventListener("click",o=>{const d=y(o.clientX-M.getBoundingClientRect().left);if(d<0||i===null)return;const s=b?S.filter(a=>a.key===b):S,t=At(s.flatMap(a=>a.items),i,T,d,ht);t.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:T[d].rangeLow,high:T[d].rangeHigh,items:t,...b?{group:b}:{}},o))})),rt=Dt(l,()=>R()),R()}q();function Ut(c){vt.set(c)&&(i=c,q())}function qt(c){at.set(c)&&q()}return{card:l,setTest:Ut,setAxisPrefs:qt,destroy:()=>rt?.disconnect()}}
1
+ import{buildTestHistogramData as ee,collectTestValues as Bt,buildTestHistogramSeries as ne,testValueExtent as At,diesInBucket as $t}from"../../stats/histogram.js";import{excludedNote as Et}from"../../renderer/valueFilter.js";import{SPACE as at,fontPx as K,FONT as Wt,CLR as Dt}from"../toolbar.js";import{fmt as bt}from"../../renderer/fmt.js";import{niceStep as ie,fitTicks as It}from"../../renderer/axisTicks.js";import{QUANTITY as oe,categorical as se}from"./palette.js";import{cardShell as le,observeResize as Pt,makeTooltip as ae,attachChartTip as re,positionChartTooltip as Rt,makeLinkedTestSelect as ce,makeWaferSelect as ue,makeLinkedAxisPrefs as de,renderEmptyState as Tt,chartFillHeight as Kt,applyCanvasFlow as Nt,makeAxisFormat as Mt,horizontalTickSpacing as Ot,PADDING as ht,robustFence as Ft,shouldIncludeLimitsByDefault as zt,drawOffAxisLimits as me,resolveAxisRange as he,limitLines as Gt,limitExtent as fe,hasBothLimitKinds as ge,stackLabelRows as pe,strokeLimitLine as xe,chartSwatchCss as be,makeSeriesLegendItem as ye,prepareCanvas as Vt}from"./chartShell.js";import{escHtml as wt,maxOf as ke}from"../../core/utils.js";const vt=230,jt=36,Te=18;function Xt(n){const E=new Set(n.map(A=>A.kind)).size;return Te+Math.max(0,E-1)*(K(-1)+2)}function _t(n,E,A,V,et,k,a){n.font=`${K(-1)}px system-ui, sans-serif`;const x=E.filter(i=>!A.has(i.value)).map(i=>{const S=V(i.value),N=n.measureText(i.label).width;return{l:i,x:S,start:S-N/2,end:S+N/2}}),U=pe(x),nt=K(-1)+2;x.forEach(({l:i,x:S},N)=>{xe(n,i,a,S,et,S,k),n.fillStyle=a,n.textAlign="center",n.textBaseline="bottom",n.fillText(i.label,S,et-2-U[N]*nt)})}function Yt(n,E,A,V,et,k,a,x=4){const U=Math.max(1,ie(k/x)),nt=V-A;n.save(),n.font=`${K(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(let i=0;i<=k+1e-9;i+=U){const S=V-i/(k||1)*nt;n.strokeStyle=a.grid,n.lineWidth=1,n.beginPath(),n.moveTo(E,S),n.lineTo(E+et,S),n.stroke(),n.fillStyle=a.text,n.fillText(String(Math.round(i)),E-4,S)}n.strokeStyle=a.axis,n.lineWidth=1,n.beginPath(),n.moveTo(E,A),n.lineTo(E,V),n.stroke(),n.restore()}export function renderHistogramPanel(n){const{title:E="Test value distribution",items:A,testDefs:V,onSaveImage:et,groups:k}=n,{card:a,body:x,controlsRow:U}=le(E,et,n.ownerDocument),nt=V.filter(s=>s.testNumber!==void 0);let i=n.selectedTestNumber??nt[0]?.testNumber??null;const S=()=>(k?k.flatMap(s=>s.items):A).flatMap(s=>s.dies??[]);let N=null,it=0,ft;const St=ce(nt,i,s=>{i=s,q(),n.onTestChange?.(s)},{maxWidth:"200px",ownerDocument:a.ownerDocument}),Qt=St.el;U.appendChild(Qt);const gt=A.length>1?ue(A,N,s=>{N=s,q()},{ownerDocument:a.ownerDocument}):null;gt&&U.appendChild(gt);function Ut(s){return b===s||s!==null&&!(k??[]).some(L=>L.key===s)?!1:(b=s,q(),!0)}const yt=a.ownerDocument.createElement("span");Object.assign(yt.style,{display:"inline-flex",gap:at.lg,alignItems:"center"}),U.appendChild(yt);const rt=de(yt,n.axisPrefs,s=>{n.onAxisPrefsChange?.(s),q()},a.ownerDocument),C=ae(a);let ct=null,b=null;function ot(s){const L=V.find(D=>D.testNumber===s),j=Gt(L,rt.get().limits),{lo:T,hi:M}=fe(j);return{unit:L?.unit,lines:j,limitLow:T,limitHigh:M,hasLimits:Gt(L).length>0,hasBothKinds:ge(L)}}function q(){const{includeLimits:s,clipOutliers:L}=rt.get();if(ct?.disconnect(),ct=null,x.innerHTML="",i===null){Tt(x,"No parametric test data available for a histogram.");return}const j=!!k&&k.length>0;let T=!1,M;if(j){const{limitLow:u,limitHigh:m}=ot(i),g=k.flatMap(c=>c.items),{min:e,max:p}=At(g,i);if(T=s??zt(e,p,u,m),L){const c=Bt(g,i),h=Ft(c);h&&(M={lo:Math.max(e,h.lo),hi:Math.min(p,h.hi)},it=c.reduce((Z,R)=>Z+(R<M.lo||R>M.hi?1:0),0))}M||(it=0),ft=M}const D=j?ne(k,i,16,T?ot(i).limitLow:void 0,T?ot(i).limitHigh:void 0,M):null;if(gt&&(gt.style.display=D?"none":""),D){const{hasLimits:u,hasBothKinds:m}=ot(i);if(rt.sync(T,u,m),D.series.length===0){Tt(x,"No parametric test data available for a histogram.");return}qt(D);return}const O=N!==null?[A[N]]:A,{unit:W,lines:X,limitLow:w,limitHigh:_,hasLimits:ut,hasBothKinds:pt}=ot(i),dt=Bt(O,i),{min:mt,max:xt}=At(O,i),I=s??zt(mt,xt,w,_);rt.sync(I,ut,pt);const st=L?Ft(dt):null,P=st?{lo:Math.max(mt,st.lo),hi:Math.min(xt,st.hi)}:void 0;it=P?dt.filter(u=>u<P.lo||u>P.hi).length:0,ft=P;const y=ee(O,i,16,I?w:void 0,I?_:void 0,P);if(y.length===0){Tt(x,"No parametric test data available for a histogram.");return}const o=Math.max(ke(y.map(u=>u.count)),1),d=a.ownerDocument.createElement("div");d.dataset.wmapCaption="1",Object.assign(d.style,{fontSize:Wt.body,color:Dt.label,marginBottom:at.xxs}),d.textContent=`max ${o} dies/bucket`+Et(S(),i)+(it?` \xB7 ${it} value${it===1?"":"s"} outside clipped range`:"")+(n.onSelectBucket?" \xB7 click a bar to chart or tabulate its dies":""),x.appendChild(d);const l=a.ownerDocument.createElement("canvas");l.style.display="block",l.style.cursor="default",x.appendChild(l);let t=-1;const r=y[0].rangeLow,f=y[y.length-1].rangeHigh,H=f-r||1,F=Math.max(Math.abs(r),Math.abs(f));function J(u){const m=ht+36,g=l.clientWidth-m-ht,e=Xt(X),p=u-jt-e;return{plotX:m,plotMaxWidth:Math.max(10,g),plotMaxHeight:p,plotTop:e}}function v(u){const{plotX:m,plotMaxWidth:g}=J(vt);if(u<m||u>m+g)return-1;const e=Math.floor((u-m)/g*y.length);return e>=0&&e<y.length?e:-1}function $(){Nt(l,d);const u=x.clientWidth,m=Kt(a,x,l,vt),g=Vt(l,a,u,m);if(!g)return;const{ctx:e,theme:p}=g,{plotX:c,plotMaxWidth:h,plotMaxHeight:Z,plotTop:R}=J(m),B=R+Z,tt=h/y.length;Yt(e,c,R,B,h,o,{text:p.textMuted,axis:p.border,grid:p.grid}),y.forEach((G,Q)=>{const Lt=G.count/o*Z,Ht=c+Q*tt,Ct=B-Lt;e.fillStyle=Q===t?p.text:oe,e.globalAlpha=Q===t?1:.7,e.fillRect(Ht+1,Ct,Math.max(1,tt-2),Lt),e.globalAlpha=1,Q===t&&(e.fillStyle=p.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(`${G.count}`,Ht+tt/2,Ct-2))});const lt=G=>c+(G-r)/H*h;e.font=`${K(-1)}px system-ui, sans-serif`;const{offAxis:z}=he({dataMin:r,dataMax:f,limits:X,includeLimits:!1});me(e,z,{left:c,right:c+h,top:R,bottom:B},"horizontal",p.limitLine,Mt(F,W).tick),_t(e,X,new Set(z.map(G=>G.value)),lt,R,B,p.limitLine),e.font=`${K(-1)}px system-ui, sans-serif`,e.strokeStyle=p.border,e.lineWidth=1,e.beginPath(),e.moveTo(c,B),e.lineTo(c+h,B),e.stroke(),e.fillStyle=p.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:Y,step:te}=It(r,f,h,Ot(e,F,W)),kt=Mt(F,W,te||void 0);for(const G of Y){const Q=c+(G-r)/H*h;e.beginPath(),e.moveTo(Q,B),e.lineTo(Q,B+4),e.stroke(),e.fillText(kt.tick(G),Q,B+6)}kt.unitLabel&&(e.save(),e.font=`${K(-1)}px system-ui, sans-serif`,e.fillStyle=p.textMuted,e.textAlign="right",e.textBaseline="top",e.fillText(`(${kt.unitLabel})`,c+h,B+20),e.restore())}l.addEventListener("mousemove",u=>{const m=l.getBoundingClientRect(),g=v(u.clientX-m.left);if(g!==t&&(t=g,$()),g>=0){const e=y[g];C.innerHTML=`<strong>${wt(`${bt(e.rangeLow,W,"engineering")} \u2013 ${bt(e.rangeHigh,W,"engineering")}`)}</strong><br>${e.count} dies`+(n.onSelectBucket&&e.count>0?"<br><em>click to chart or tabulate these dies</em>":""),C.style.display="block",Rt(C,a,u.clientX,u.clientY)}else C.style.display="none"}),l.addEventListener("mouseleave",()=>{t!==-1&&(t=-1,$()),C.style.display="none"}),n.onSelectBucket&&(l.style.cursor="pointer",l.addEventListener("click",u=>{const m=v(u.clientX-l.getBoundingClientRect().left);if(m<0||i===null||y[m].count===0)return;const g=$t(O,i,y,m,ft);g.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:y[m].rangeLow,high:y[m].rangeHigh,items:g},u))})),ct=Pt(a,()=>$()),$()}function qt(s){const{unit:L,lines:j}=ot(i),T=s.ranges,M=s.series,D=se;b&&!M.some(o=>o.groupKey===b)&&(b=null);const O=Math.max(1,...M.flatMap(o=>o.counts)),W=a.ownerDocument.createElement("div");W.dataset.wmapCaption="1",Object.assign(W.style,{fontSize:Wt.body,color:Dt.label,marginBottom:at.xxs}),W.textContent=`${M.length} groups \xB7 max ${O} dies/bucket`+Et(S(),i)+(n.onSelectBucket?" \xB7 click a column to chart or tabulate its dies":""),x.appendChild(W);const X=a.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:at.sm,marginTop:at.md,marginBottom:at.xl}),M.forEach((o,d)=>{const l=ye(o.groupKey,D(d),a.ownerDocument),t=l.el;re(t,a,C,`${o.groupKey} \u2014 click to emphasize (dim the rest)`),l.setState({selected:b===o.groupKey,dimmed:b!==null&&b!==o.groupKey}),t.addEventListener("click",()=>{const r=b===o.groupKey?null:o.groupKey;Ut(r),n.onGroupChange?.(r)}),X.appendChild(t)}),x.appendChild(X);const w=a.ownerDocument.createElement("canvas");w.style.display="block",w.style.cursor="default",x.appendChild(w);const _=T[0].rangeLow,ut=T[T.length-1].rangeHigh,pt=ut-_||1,dt=Math.max(Math.abs(_),Math.abs(ut)),mt=o=>{const d=(o.ownerDocument.defaultView??window).getComputedStyle(o);return o.offsetHeight+(parseFloat(d.marginTop)||0)+(parseFloat(d.marginBottom)||0)},xt=()=>mt(W)+mt(X);let I=-1,st={plotX:ht+36,plotMaxWidth:10,barWidth:10};function P(){Nt(w,xt());const o=x.clientWidth,d=Kt(a,x,w,vt),l=Vt(w,a,o,d);if(!l)return;const{ctx:t,theme:r}=l,f=ht+36,H=Math.max(10,o-f-ht),F=Xt(j),J=d-jt-F,v=F+J,$=H/T.length;st={plotX:f,plotMaxWidth:H,barWidth:$},Yt(t,f,F,v,H,O,{text:r.textMuted,axis:r.border,grid:r.grid}),I>=0&&(t.fillStyle=r.bgHover,t.globalAlpha=.5,t.fillRect(f+I*$,F,$,J),t.globalAlpha=1);const u=M.map((c,h)=>({s:c,i:h})).sort((c,h)=>(c.s.groupKey===b?1:0)-(h.s.groupKey===b?1:0));for(const{s:c,i:h}of u){const Z=b===c.groupKey,R=b!==null&&!Z,B=D(h);t.strokeStyle=B,t.fillStyle=B,t.lineWidth=Z?2:1,t.globalAlpha=R?.12:b?.32:.22,t.beginPath(),t.moveTo(f,v),c.counts.forEach((tt,lt)=>{const z=f+lt*$,Y=v-tt/O*J;t.lineTo(z,Y),t.lineTo(z+$,Y)}),t.lineTo(f+H,v),t.closePath(),t.fill(),t.globalAlpha=R?.3:1,t.beginPath(),c.counts.forEach((tt,lt)=>{const z=f+lt*$,Y=v-tt/O*J;lt===0?t.moveTo(z,Y):t.lineTo(z,Y),t.lineTo(z+$,Y)}),t.stroke()}t.globalAlpha=1;const m=c=>f+(c-_)/pt*H;t.font=`${K(-1)}px system-ui, sans-serif`,_t(t,j,new Set,m,F,v,r.limitLine),t.font=`${K(-1)}px system-ui, sans-serif`,t.strokeStyle=r.border,t.lineWidth=1,t.beginPath(),t.moveTo(f,v),t.lineTo(f+H,v),t.stroke(),t.fillStyle=r.textMuted,t.textAlign="center",t.textBaseline="top";const{ticks:g,step:e}=It(_,ut,H,Ot(t,dt,L)),p=Mt(dt,L,e||void 0);for(const c of g){const h=f+(c-_)/pt*H;t.beginPath(),t.moveTo(h,v),t.lineTo(h,v+4),t.stroke(),t.fillText(p.tick(c),h,v+6)}p.unitLabel&&(t.save(),t.font=`${K(-1)}px system-ui, sans-serif`,t.fillStyle=r.textMuted,t.textAlign="right",t.textBaseline="top",t.fillText(`(${p.unitLabel})`,f+H,v+20),t.restore())}function y(o){const{plotX:d,plotMaxWidth:l,barWidth:t}=st;if(o<d||o>d+l)return-1;const r=Math.floor((o-d)/t);return r>=0&&r<T.length?r:-1}w.addEventListener("mousemove",o=>{const d=w.getBoundingClientRect(),l=y(o.clientX-d.left);if(l!==I&&(I=l,P()),l>=0){const t=T[l],r=M.map((f,H)=>`<span style="${be(D(H))};margin-right:4px"></span>${wt(`${f.groupKey}: ${f.counts[l]}`)}`).join("<br>");C.innerHTML=`<strong>${wt(`${bt(t.rangeLow,L,"engineering")} \u2013 ${bt(t.rangeHigh,L,"engineering")}`)}</strong><br>${r}`,C.style.display="block",Rt(C,a,o.clientX,o.clientY)}else C.style.display="none"}),w.addEventListener("mouseleave",()=>{I!==-1&&(I=-1,P()),C.style.display="none"}),n.onSelectBucket&&k&&(w.style.cursor="pointer",w.addEventListener("click",o=>{const d=y(o.clientX-w.getBoundingClientRect().left);if(d<0||i===null)return;const l=b?k.filter(r=>r.key===b):k,t=$t(l.flatMap(r=>r.items),i,T,d,ft);t.length!==0&&(C.style.display="none",n.onSelectBucket({testNumber:i,low:T[d].rangeLow,high:T[d].rangeHigh,items:t,...b?{group:b}:{}},o))})),ct=Pt(a,()=>P()),P()}q();function Jt(s){St.set(s)&&(i=s,q())}function Zt(s){rt.set(s)&&q()}return{card:a,setTest:Jt,setAxisPrefs:Zt,destroy:()=>ct?.disconnect()}}
@@ -1 +1 @@
1
- import{escHtml as I,maxOf as fe,minOf as We}from"../../core/utils.js";import{fiveNumberSummary as Be}from"../../stats/math.js";import{fmt as R}from"../../renderer/fmt.js";import{fitTicks as Te}from"../../renderer/axisTicks.js";import{plotFootnote as Fe,plotTestNumber as Oe,plotTitle as et}from"../../stats/plotData.js";import{SPACE as ee,RADIUS as tt,fontPx as me,FONT as we,CLR as xe,markNoPrint as ze}from"../toolbar.js";import{cardShell as nt,observeResize as ot,makeTooltip as it,attachChartTip as lt,chartFillHeight as st,applyCanvasFlow as ke,prepareCanvas as Me,positionChartTooltip as Le,resolveChartCanvasColors as ve,makeAxisFormat as at,horizontalTickSpacing as rt,VERTICAL_TICK_SPACING_PX as ct,makeSeriesLegendItem as ft,renderEmptyState as Re,limitLines as mt,limitExtent as ht,stackLabelRows as qe,strokeLimitLine as He,drawOffAxisLimits as ut,limitLabelSide as dt,shouldIncludeLimitsByDefault as gt}from"./chartShell.js";import{categorical as pt}from"./palette.js";import{resolveValueColorFn as $e}from"../../renderer/colorSchemes.js";import{wirePointInteractions as yt}from"./pointInteractions.js";const M=64,Xe=16,k=12,he=52,bt=16,Pe=5e3;function te(b,P,$={}){const q=P.scale==="log";let w=b.length?We(b):0,O=b.length?fe(b):1;q&&(w=Math.log10(Math.max(w,Number.MIN_VALUE)),O=Math.log10(Math.max(O,Number.MIN_VALUE)));const ne=(O-w)*.05||(q?.5:1);w=$.floorAtZero&&!q&&w>=0?0:w-ne,O+=ne;const s=x=>x===void 0||!Number.isFinite(x)?void 0:q?x>0?Math.log10(x):void 0:x,g=s(P.min),H=s(P.max);g!==void 0&&(w=g),H!==void 0&&(O=H),O>w||(O=w+1);const C=O-w,V=!!P.reverse,Z=x=>{const Y=((q?Math.log10(Math.max(x,Number.MIN_VALUE)):x)-w)/C;return V?1-Y:Y};return{lo:q?10**w:w,hi:q?10**O:O,log:q,reverse:V,frac:Z}}function _e(b,P,$,q){if(P/b<10)return Te(b,P,$,q);const w=Math.floor(Math.log10(b)),O=Math.ceil(Math.log10(P)),ne=g=>{const H=[];for(let C=w;C<=O;C++)for(const V of g){const Z=V*10**C;Z>=b&&Z<=P&&H.push(Z)}return H},L=ne([1]);return{ticks:L.length>=4?L:ne([1,2,5]),step:0}}export function renderPlotChart(b){const P=b.ownerDocument??document,{card:$,heading:q,body:w,controlsRow:O,setPngDecor:ne}=nt("Plot",b.onSaveImage,P);$.dataset.wmapPlotCard="1";const L=it($);let s,g,H,C,V,Z=[];const x=new Set,Y=new Set;let ue=null,X=-1,ce=[],z,K,G,_=null,J=[],D=-1,de=he;const oe=e=>pt(e),ge=e=>s?.groups[e]||"";function pe(){const e=w.clientWidth,l=Math.max(220,Math.min(420,e*.62))+(de-he),c=st($,w,g,l);return{w:e,h:c,plotW:Math.max(10,e-M-Xe),plotH:Math.max(10,c-k-de)}}const ie=e=>mt(e?.limits,s?.spec.limits??"both").filter(l=>e?.scale!=="log"||l.value>0),ae=(e,l)=>{const c=e.filter(Number.isFinite);if(!l.length||c.length===0)return e;const{lo:r,hi:i}=ht(l);return gt(We(c),fe(c),r,i)?[...e,...l.map(o=>o.value)]:e};function re(e,l,c,r,i,o,t,n){if(o.length===0)return;const f=o.filter(h=>h.value>=i.lo&&h.value<=i.hi),p=o.filter(h=>!f.includes(h)).map(h=>({value:h.value,label:h.label,side:h.value<i.lo?"lo":"hi"}));e.save(),e.font=`${me(-1)}px system-ui, sans-serif`;const d=h=>`${h.label} ${R(h.value,t.unit)}`,a=me(-1)+2;if(n==="y"){const h=f.map(m=>{const y=k+(1-i.frac(m.value))*r;return{l:m,y,start:y-6-a/2,end:y-6+a/2}}),S=qe(h,1),u=h.length?fe(h.map(m=>e.measureText(d(m.l)).width))+8:0;h.forEach(({l:m,y},v)=>{e.globalAlpha=.7,He(e,m,l,M,y,M+c,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",e.fillText(d(m),M+3+S[v]*u,y-4)})}else{const h=f.map(u=>{const m=M+i.frac(u.value)*c,y=e.measureText(d(u)).width,v=dt(m,y,M,M+c,u.end==="lo");return{l:u,x:m,side:v,start:v<0?m-3-y:m+3,end:v<0?m-3:m+3+y}}),S=qe(h,4);h.forEach(({l:u,x:m,side:y},v)=>{e.globalAlpha=.7,He(e,u,l,m,k,m,k+r),e.globalAlpha=1,e.fillStyle=l,e.textAlign=y<0?"right":"left",e.textBaseline="top",e.fillText(d(u),m+y*3,k+2+S[v]*a)})}e.restore(),ut(e,p,{left:M,right:M+c,top:k,bottom:k+r},n==="y"?"vertical":"horizontal",l,h=>R(h,t.unit))}function Ee(e,l,c,r){return at(Math.max(Math.abs(l),Math.abs(c)),e.unit,r)}function Ce(e,l){return l?`${e.label} (${l})`:e.label}function ye(e,l,c,r,i,o,t,n,f,p){e.font=`${me(-1)}px system-ui, sans-serif`;const d=()=>ct,a=n.log?_e(n.lo,n.hi,o,d):Te(n.lo,n.hi,o,d),h=Ee(p,n.lo,n.hi,a.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let S="";if("labels"in t){const u=t.labels.length;t.labels.forEach((m,y)=>{const v=M+(y+.5)/u*i,T=m.length>22?`${m.slice(0,21)}\u2026`:m;t.rotate?(e.save(),e.translate(v,k+o+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(T,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(T,v,k+o+4))})}else{const u=rt(e,Math.max(Math.abs(t.lo),Math.abs(t.hi)),f.unit),m=t.log?_e(t.lo,t.hi,i,u):Te(t.lo,t.hi,i,u),y=Ee(f,t.lo,t.hi,m.step||void 0);S=y.unitLabel;for(const v of m.ticks){const T=M+t.frac(v)*i;e.beginPath(),e.moveTo(T,k),e.lineTo(T,k+o),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y.tick(v),T,k+o+4)}}for(const u of a.ticks){const m=k+(1-n.frac(u))*o;e.beginPath(),e.moveTo(M,m),e.lineTo(M+i,m),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(h.tick(u),M-4,m)}e.font=`${me(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Ce(f,S),M+i/2,r-6),e.save(),e.translate(14,k+o/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Ce(p,h.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(M,k),e.lineTo(M,k+o),e.moveTo(M,k+o),e.lineTo(M+i,k+o),e.stroke()}function je(){if(!s||!g||s.marks?.type!=="scatter"||!s.x||!s.y)return;ke(g,C??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,n=s.marks.points,f=x.size===0?n:n.filter(A=>x.has(A.group)),p=s.colorScale,d=$e(),a=ie(s.x),h=ie(s.y),S=te(ae(n.map(A=>A.x),a),s.x),u=te(ae(n.map(A=>A.y),h),s.y);z={x:S,y:u,plotW:r,plotH:i},ye(t,e,l,c,r,i,S,u,s.x,s.y),re(t,e.limitLine,r,i,S,a,s.x,"x"),re(t,e.limitLine,r,i,u,h,s.y,"y");const m=f.length>Pe?Math.ceil(f.length/Pe):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(f.length/m))),ce=[];const y=M,v=M+r,T=k,le=k+i;for(let A=0;A<f.length;A+=m){const N=f[A],se=M+S.frac(N.x)*r,U=k+(1-u.frac(N.y))*i;se<y||se>v||U<T||U>le||(ce.push({p:N,cx:se,cy:U}),t.beginPath(),t.arc(se,U,2.5,0,Math.PI*2),t.fillStyle=p&&N.value!==void 0?d((N.value-p.lo)/(p.hi-p.lo||1)):oe(N.group),t.fill())}t.globalAlpha=1;const E=ue?ce.find(A=>A.p===ue):void 0;if(E&&(t.beginPath(),t.arc(E.cx,E.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),Y.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let A=0;for(const N of Y)if(!(x.size>0&&!x.has(N.group))){if(++A>Pe)break;t.beginPath(),t.arc(M+S.frac(N.x)*r,k+(1-u.frac(N.y))*i,4,0,Math.PI*2),t.stroke()}}}function Ue(){if(K=void 0,!s||s.marks?.type!=="histogram"||!s.x)return;const e=s.marks.values,l=e.flat();if(l.length===0)return;const c=te(ae(l,ie(s.x)),s.x),r=Math.max(1,s.spec.bins??bt),i=c.log?Math.log10(c.lo):c.lo,o=c.log?Math.log10(c.hi):c.hi,t=Array.from({length:r+1},(f,p)=>{const d=i+(o-i)*p/r;return c.log?10**d:d}),n=e.map(()=>new Array(r).fill(0));e.forEach((f,p)=>{for(const d of f){const a=c.log?d>0?Math.log10(d):NaN:d;if(!Number.isFinite(a)||a<i||a>o)continue;const h=Math.min(r-1,Math.floor((a-i)/(o-i)*r));n[p][h]++}}),K={edges:t,counts:n,maxCount:Math.max(1,...n.map(f=>fe(f)))}}function Ye(){if(!s||!g||!K||!s.x||!s.y)return;ke(g,C??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,{edges:n,counts:f,maxCount:p}=K,d=te([n[0],n[n.length-1]],{...s.x,min:n[0],max:n[n.length-1]}),a=te([0,p],{label:s.y.label,scale:"linear",min:0,max:p*1.05});z={x:d,y:a,plotW:r,plotH:i},ye(t,e,l,c,r,i,d,a,s.x,s.y),re(t,e.limitLine,r,i,d,ie(s.x),s.x,"x");const h=f.map((u,m)=>m).filter(u=>x.size===0||x.has(u)),S=h.length>1;for(const u of h)t.globalAlpha=S?.55:.85,t.fillStyle=oe(u),f[u].forEach((m,y)=>{if(m===0)return;const v=M+Math.min(d.frac(n[y]),d.frac(n[y+1]))*r,T=M+Math.max(d.frac(n[y]),d.frac(n[y+1]))*r,le=k+(1-a.frac(m))*i;t.fillRect(v,le,Math.max(1,T-v-1),k+i-le)});if(t.globalAlpha=1,X>=0){const u=M+Math.min(d.frac(n[X]),d.frac(n[X+1]))*r,m=M+Math.max(d.frac(n[X]),d.frac(n[X+1]))*r;t.lineWidth=1.5,t.strokeStyle=e.text,t.strokeRect(u,k,Math.max(1,m-u),i)}}function Ge(){const e=s?.marks;if(!s||!g||!s.x||!s.y||!e||e.type!=="box"&&e.type!=="bar")return;ke(g,C??0);const l=ve($),c=g.getContext("2d");let r=0;c&&(c.font=`${me(-1)}px system-ui, sans-serif`,r=fe(e.categories.map(E=>c.measureText(E.length>22?`${E.slice(0,21)}\u2026`:E).width)));const i=Math.max(10,w.clientWidth-M-Xe)/Math.max(1,e.categories.length),o=r+8>i;de=o?he+Math.min(110,r*.72):he;const{w:t,h:n,plotW:f,plotH:p}=pe(),d=Me(g,$,t,n);if(!d)return;const{ctx:a}=d,h=E=>E.filter(Number.isFinite),S=ie(s.y),u=te(ae(e.type==="bar"?[...h(e.values.flat()),0]:h(e.cells.flat(2)),S),s.y,{floorAtZero:e.type==="bar"});z={x:u,y:u,plotW:f,plotH:p},ye(a,l,t,n,f,p,{labels:e.categories,rotate:o},u,s.x,s.y),re(a,l.limitLine,f,p,u,S,s.y,"y");const m=e.categories.length,y=s.groups.length,v=f/m,T=v*.8/y;G={slotW:v,gw:T,n:m,groups:y,plotW:f};const le=u.log?k+p:k+(1-u.frac(0))*p;for(let E=0;E<y;E++){if(x.size>0&&!x.has(E))continue;const A=oe(E);for(let N=0;N<m;N++){const se=M+N*v+v*.1+E*T;if(e.type==="bar"){const U=e.values[E][N];if(!Number.isFinite(U))continue;const j=k+(1-u.frac(U))*p;a.fillStyle=A,a.globalAlpha=.9,a.fillRect(se+1,Math.min(j,le),Math.max(1,T-2),Math.max(1,Math.abs(le-j))),a.globalAlpha=1}else{const U=e.cells[E][N];if(U.length===0)continue;const j=se+T/2,Q=Math.max(3,Math.min(T*.7,46)),B=Be(Float64Array.from(U)),F=be=>k+(1-u.frac(be))*p;if(a.strokeStyle=A,a.fillStyle=A,a.lineWidth=1.5,U.length===1){a.beginPath(),a.arc(j,F(B.median),3,0,Math.PI*2),a.fill();continue}a.beginPath(),a.moveTo(j,F(B.min)),a.lineTo(j,F(B.max)),a.stroke();for(const be of[B.min,B.max])a.beginPath(),a.moveTo(j-Q/4,F(be)),a.lineTo(j+Q/4,F(be)),a.stroke();a.globalAlpha=.35,a.fillRect(j-Q/2,Math.min(F(B.q1),F(B.q3)),Q,Math.max(1,Math.abs(F(B.q1)-F(B.q3)))),a.globalAlpha=1,a.strokeRect(j-Q/2,Math.min(F(B.q1),F(B.q3)),Q,Math.max(1,Math.abs(F(B.q1)-F(B.q3)))),a.lineWidth=2.5,a.beginPath(),a.moveTo(j-Q/2,F(B.median)),a.lineTo(j+Q/2,F(B.median)),a.stroke()}}}if(_){const E=M+_.c*v+v*.1+_.g*T;a.lineWidth=1.5,a.strokeStyle=l.text,a.strokeRect(E,k,T,p)}}function Ae(e){if(!G||!g)return null;const l=g.getBoundingClientRect(),c=e.clientX-l.left-M;if(c<0||c>G.plotW)return null;const r=Math.min(G.n-1,Math.floor(c/G.slotW)),i=Math.floor((c-r*G.slotW-G.slotW*.1)/G.gw);return i<0||i>=G.groups?null:{g:i,c:r}}function De(e){const l=s,c=l.marks,r=l.level==="die"?"dies":"wafers",i=c.cells[e.g][e.c],o=`<strong>${I(c.categories[e.c])}${l.groups.length>1?` \xB7 ${I(ge(e.g))}`:""}</strong><br>`,t=l.y?.unit;if(i.length===0)return`${o}no ${r}`;const n=`${i.length.toLocaleString("en-GB")} ${r}`,f=c.categoryItems&&b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"";if(c.type==="bar"){const d=c.values[e.g][e.c];return`${o}${I(`${l.y.label}: ${R(d,t)}`)}<br>${I(n)}${f}`}const p=Be(Float64Array.from(i));return`${o}${["max","q3","median","q1","min"].map(d=>I(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[d]}: ${R(p[d],t)}`)).join("<br>")}<br>${I(n)}${f}`}function Ve(){const e=s?.marks;if(!s||!g||!s.x||!s.y||!e||e.type!=="line")return;ke(g,C??0);const l=ve($),{w:c,h:r,plotW:i,plotH:o}=pe(),t=Me(g,$,c,r);if(!t)return;const{ctx:n}=t,f=ie(s.x),p=ie(s.y),d=te(ae(e.xs,f),s.x),a=te(ae(e.values.flat().filter(Number.isFinite),p),s.y);z={x:d,y:a,plotW:i,plotH:o},ye(n,l,c,r,i,o,d,a,s.x,s.y),re(n,l.limitLine,i,o,d,f,s.x,"x"),re(n,l.limitLine,i,o,a,p,s.y,"y"),J=e.xs.map(h=>M+d.frac(h)*i),e.values.forEach((h,S)=>{if(x.size>0&&!x.has(S))return;n.strokeStyle=oe(S),n.fillStyle=oe(S),n.lineWidth=2;let u=!1;n.beginPath(),h.forEach((m,y)=>{if(!Number.isFinite(m)){u=!1;return}const v=J[y],T=k+(1-a.frac(m))*o;u?n.lineTo(v,T):n.moveTo(v,T),u=!0}),n.stroke(),h.forEach((m,y)=>{Number.isFinite(m)&&(n.beginPath(),n.arc(J[y],k+(1-a.frac(m))*o,D===y?4.5:3,0,Math.PI*2),n.fill())})}),D>=0&&(n.lineWidth=1,n.strokeStyle=l.textMuted,n.beginPath(),n.moveTo(J[D],k),n.lineTo(J[D],k+o),n.stroke())}function Ie(e){const l=s?.marks;if(!l||l.type!=="line"||!g||!s?.x||J.length===0)return null;const c=e.clientX-g.getBoundingClientRect().left;let r=-1,i=24;if(J.forEach((n,f)=>{const p=Math.abs(n-c);p<i&&(i=p,r=f)}),D=r,r<0)return null;const o=s.level==="die"?"dies":"wafers",t=l.values.map((n,f)=>({g:f,v:n[r],n:l.counts[f][r]})).filter(n=>Number.isFinite(n.v)&&(x.size===0||x.has(n.g)));return`<strong>${I(`${s.x.label}: ${R(l.xs[r],s.x.unit)}`)}</strong><br>`+t.map(n=>I(`${s.groups.length>1?`${ge(n.g)}: `:""}${R(n.v,s.y.unit)} (${n.n.toLocaleString("en-GB")} ${o})`)).join("<br>")}function W(){const e=s?.marks?.type;e==="scatter"?je():e==="histogram"?Ye():e==="box"||e==="bar"?Ge():e==="line"&&Ve()}function Ze(e){const l=s,c=b.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",i=[c,r].filter(Boolean).join(" \xB7 "),o=(t,n)=>`${t.label}: ${R(n,t.unit)}`;return(i?`<strong>${I(i)}</strong><br>`:"")+I(o(l.x,e.x))+"<br>"+I(o(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${I(`${l.colorScale.label}: ${R(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${I(ge(e.group))}`:"")+(b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"")}function Ne(e){if(!K||!z||!s?.x)return null;const l=g.getBoundingClientRect(),r=(e.clientX-l.left-M)/z.plotW;if(r<0||r>1)return null;const i=z.x.reverse?1-r:r,{edges:o,counts:t}=K,n=o.length-1,f=Math.min(n-1,Math.max(0,Math.floor(i*n)));X=f;const p=s.x,d=t.map((a,h)=>({g:h,n:a[f]})).filter(a=>a.n>0&&(x.size===0||x.has(a.g)));return`<strong>${I(`${R(o[f],p.unit)} to ${R(o[f+1],p.unit)}`)}</strong><br>`+(d.length?d.map(a=>I(`${s.groups.length>1?`${ge(a.g)}: `:""}${a.n.toLocaleString("en-GB")} ${s.level==="die"?"dies":"wafers"}`)).join("<br>"):"none")}function Ke(e){const l=P.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:ee.md,marginTop:ee.md,marginBottom:ee.xl,fontSize:we.body,color:xe.label});const c=P.createElement("canvas");c.width=200,c.height=10,Object.assign(c.style,{width:"200px",height:"10px",borderRadius:tt.control,flex:"0 0 auto"});const r=c.getContext("2d"),i=$e();if(r)for(let f=0;f<200;f++)r.fillStyle=i(f/199),r.fillRect(f,0,1,10);const o=P.createElement("span");o.textContent=R(e.lo,e.unit);const t=P.createElement("span");t.textContent=R(e.hi,e.unit);const n=P.createElement("span");return n.textContent=e.label,n.style.color=xe.text,l.append(n,o,c,t),l}const Se=(e,l,c)=>l.map(r=>{const{item:i,die:o}=e(r);return{x:0,y:0,group:c,item:i,die:o}});function Je(){V?.destroy(),V=void 0,w.innerHTML="",g=void 0,H=void 0,C=void 0,Z=[],ue=null,X=-1,ce=[],z=void 0,G=void 0,_=null,J=[],D=-1,de=he,x.clear(),Y.clear();const e=s;if(!e)return;if(q.textContent=et(e),$.dataset.wmapChartTitle=q.textContent,e.issues.length||!e.marks){for(const i of e.issues)Re(w,i);return}const l=P.createElement("div");Object.assign(l.style,{color:xe.label,fontSize:we.body,marginBottom:ee.xs});const c=b.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(b.onOpenWafer?` \xB7 click a point to ${c}`:"")+(b.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(b.onOpenWafer&&e.marks.categoryItems?` \xB7 click to ${c}`:b.onSelectPoints?" \xB7 click to chart or tabulate what it counts":"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&b.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="line"&&b.onSelectPoints?" \xB7 click a point to chart or tabulate what it averages":"";l.textContent=Fe(e)+r,ze(l),C=P.createElement("div"),C.style.display="flow-root",w.appendChild(C),C.appendChild(l);for(const i of e.notes){const o=P.createElement("div");ze(o),o.textContent=i,Object.assign(o.style,{color:xe.warnText,fontSize:we.body,marginBottom:ee.xs}),C.appendChild(o)}if(e.plotted===0){Re(w,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&(H=P.createElement("div"),Object.assign(H.style,{display:"flex",flexWrap:"wrap",gap:ee.sm,marginTop:ee.md,marginBottom:ee.xl}),e.groups.forEach((i,o)=>{const t=ft(i||"(none)",oe(o),P);lt(t.el,$,L,`${i||"(none)"} \u2014 click to filter`),t.el.addEventListener("click",()=>{x.has(o)?x.delete(o):x.add(o),Z.forEach((n,f)=>n.setState({selected:x.has(f),dimmed:x.size>0&&!x.has(f)})),W()}),Z.push(t),H.appendChild(t.el)}),C.appendChild(H)),e.colorScale&&(H=Ke(e.colorScale),C.appendChild(H)),g=P.createElement("canvas"),g.style.display="block",g.style.cursor=e.marks.type==="scatter"?"crosshair":"default",w.appendChild(g),e.marks.type==="scatter"){const i=e.marks,o=!!b.onSelectPoints;V=yt({card:$,canvas:g,tooltip:L,drawn:()=>ce,describe:Ze,clickable:()=>!!b.onOpenWafer,onOpen:t=>b.onOpenWafer?.(t.item,Oe(e.spec)),onHover:t=>{ue=t,W()},select:o?{pick:({x0:t,y0:n,x1:f,y1:p})=>z?(x.size===0?i.points:i.points.filter(a=>x.has(a.group))).filter(a=>{const h=M+z.x.frac(a.x)*z.plotW,S=k+(1-z.y.frac(a.y))*z.plotH;return h>=t&&h<=f&&S>=n&&S<=p}):[],onPicked:(t,n)=>{Y.clear();for(const f of t)Y.add(f);W(),t.length>0&&b.onSelectPoints(t,n,g)},onClear:()=>{Y.clear(),W()},hasSelection:()=>Y.size>0}:void 0})}else if(e.marks.type==="histogram"){Ue(),g.addEventListener("mousemove",o=>{const t=Ne(o);if(!t){L.style.display="none",X>=0&&(X=-1,W());return}L.innerHTML=t,L.style.display="block",Le(L,$,o.clientX,o.clientY),W()}),g.addEventListener("mouseleave",()=>{L.style.display="none",X>=0&&(X=-1,W())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(!K||Ne(o)===null)return;const t=X,{edges:n}=K,f=z?.x.log,p=f?Math.log10(n[0]):n[0],d=f?Math.log10(n[n.length-1]):n[n.length-1],a=n.length-1,h=[];i.values.forEach((S,u)=>{if(x.size>0&&!x.has(u))return;const m=[];S.forEach((y,v)=>{const T=f?y>0?Math.log10(y):NaN:y;!Number.isFinite(T)||T<p||T>d||Math.min(a-1,Math.floor((T-p)/(d-p)*a))===t&&m.push(i.units[u][v])}),h.push(...Se(i.unit,m,u))}),h.length>0&&(L.style.display="none",b.onSelectPoints(h,{x:o.clientX,y:o.clientY},g))}))}else if(e.marks.type==="box"||e.marks.type==="bar"){const i=e.marks;g.addEventListener("mousemove",o=>{const t=Ae(o);if(g.style.cursor=t&&(i.categoryItems&&b.onOpenWafer||b.onSelectPoints&&i.cellUnits[t.g][t.c].length>0)?"pointer":"default",!t){L.style.display="none",_&&(_=null,W());return}L.innerHTML=De(t),L.style.display="block",Le(L,$,o.clientX,o.clientY),(!_||_.g!==t.g||_.c!==t.c)&&(_=t,W())}),g.addEventListener("mouseleave",()=>{L.style.display="none",_&&(_=null,W())}),g.addEventListener("click",o=>{const t=Ae(o);if(!t)return;const n=i.categoryItems?.[t.c];if(n!==void 0&&n>=0&&b.onOpenWafer){b.onOpenWafer(n,Oe(e.spec));return}const f=i.cellUnits[t.g][t.c];f.length>0&&b.onSelectPoints&&(L.style.display="none",b.onSelectPoints(Se(i.unit,f,t.g),{x:o.clientX,y:o.clientY},g))})}else if(e.marks.type==="line"){g.addEventListener("mousemove",o=>{const t=Ie(o);if(!t){L.style.display="none",W();return}L.innerHTML=t,L.style.display="block",Le(L,$,o.clientX,o.clientY),W()}),g.addEventListener("mouseleave",()=>{L.style.display="none",D>=0&&(D=-1,W())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(Ie(o)===null||D<0)return;const t=i.cellUnits.flatMap((n,f)=>x.size>0&&!x.has(f)?[]:Se(i.unit,n[D]??[],f));t.length>0&&(L.style.display="none",b.onSelectPoints(t,{x:o.clientX,y:o.clientY},g))}))}W()}ne(()=>{const e=s;if(!e||!e.marks)return;const l=$e();return{caption:[Fe(e),...e.notes],legend:e.groups.length>1?e.groups.map((c,r)=>({label:c||"(none)",color:oe(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:R(e.colorScale.lo,e.colorScale.unit),hi:R(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const Qe=ot($,()=>W());return{card:$,actions:O,setPlot(e){s=e,Je()},destroy(){Qe.disconnect(),V?.destroy()}}}
1
+ import{escHtml as I,maxOf as fe,minOf as Oe}from"../../core/utils.js";import{fiveNumberSummary as We}from"../../stats/math.js";import{fmt as R}from"../../renderer/fmt.js";import{fitTicks as we}from"../../renderer/axisTicks.js";import{plotFootnote as Fe,plotTestNumber as ze,plotTitle as nt}from"../../stats/plotData.js";import{SPACE as te,RADIUS as ot,fontPx as me,FONT as Le,CLR as xe,markNoPrint as Re}from"../toolbar.js";import{cardShell as it,observeResize as lt,makeTooltip as st,attachChartTip as at,chartFillHeight as rt,applyCanvasFlow as ke,prepareCanvas as Me,positionChartTooltip as $e,resolveChartCanvasColors as ve,makeAxisFormat as ct,horizontalTickSpacing as ft,VERTICAL_TICK_SPACING_PX as mt,makeSeriesLegendItem as ht,renderEmptyState as qe,limitLines as ut,limitExtent as dt,stackLabelRows as He,placeClearOf as Xe,strokeLimitLine as _e,drawOffAxisLimits as gt,limitLabelSide as pt,shouldIncludeLimitsByDefault as yt}from"./chartShell.js";import{categorical as bt}from"./palette.js";import{resolveValueColorFn as Pe}from"../../renderer/colorSchemes.js";import{wirePointInteractions as xt}from"./pointInteractions.js";const M=64,je=16,k=12,he=52,kt=16,Ce=5e3;function ne(b,P,$={}){const q=P.scale==="log";let w=b.length?Oe(b):0,F=b.length?fe(b):1;q&&(w=Math.log10(Math.max(w,Number.MIN_VALUE)),F=Math.log10(Math.max(F,Number.MIN_VALUE)));const oe=(F-w)*.05||(q?.5:1);w=$.floorAtZero&&!q&&w>=0?0:w-oe,F+=oe;const a=x=>x===void 0||!Number.isFinite(x)?void 0:q?x>0?Math.log10(x):void 0:x,g=a(P.min),H=a(P.max);g!==void 0&&(w=g),H!==void 0&&(F=H),F>w||(F=w+1);const A=F-w,Z=!!P.reverse,K=x=>{const G=((q?Math.log10(Math.max(x,Number.MIN_VALUE)):x)-w)/A;return Z?1-G:G};return{lo:q?10**w:w,hi:q?10**F:F,log:q,reverse:Z,frac:K}}function Ue(b,P,$,q){if(P/b<10)return we(b,P,$,q);const w=Math.floor(Math.log10(b)),F=Math.ceil(Math.log10(P)),oe=g=>{const H=[];for(let A=w;A<=F;A++)for(const Z of g){const K=Z*10**A;K>=b&&K<=P&&H.push(K)}return H},L=oe([1]);return{ticks:L.length>=4?L:oe([1,2,5]),step:0}}export function renderPlotChart(b){const P=b.ownerDocument??document,{card:$,heading:q,body:w,controlsRow:F,setPngDecor:oe}=it("Plot",b.onSaveImage,P);$.dataset.wmapPlotCard="1";const L=st($);let a,g,H,A,Z,K=[];const x=new Set,G=new Set;let ue=null,X=-1,ce=[],z,J,D,_=null,Q=[],V=-1,Se=[],de=he;const ie=e=>bt(e),ge=e=>a?.groups[e]||"";function pe(){const e=w.clientWidth,l=Math.max(220,Math.min(420,e*.62))+(de-he),c=rt($,w,g,l);return{w:e,h:c,plotW:Math.max(10,e-M-je),plotH:Math.max(10,c-k-de)}}const le=e=>ut(e?.limits,a?.spec.limits??"both").filter(l=>e?.scale!=="log"||l.value>0),ae=(e,l)=>{const c=e.filter(Number.isFinite);if(!l.length||c.length===0)return e;const{lo:r,hi:i}=dt(l);return yt(Oe(c),fe(c),r,i)?[...e,...l.map(o=>o.value)]:e};function re(e,l,c,r,i,o,t,n){if(o.length===0)return;const f=o.filter(u=>u.value>=i.lo&&u.value<=i.hi),p=o.filter(u=>!f.includes(u)).map(u=>({value:u.value,label:u.label,side:u.value<i.lo?"lo":"hi"}));e.save(),e.font=`${me(-1)}px system-ui, sans-serif`;const h=u=>`${u.label} ${R(u.value,t.unit)}`,s=me(-1)+2;if(n==="y"){const u=f.map(m=>{const y=k+(1-i.frac(m.value))*r;return{l:m,y,start:y-6-s/2,end:y-6+s/2}}),T=He(u,1),d=u.length?fe(u.map(m=>e.measureText(h(m.l)).width))+8:0;u.forEach(({l:m,y},S)=>{e.globalAlpha=.7,_e(e,m,l,M,y,M+c,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const v=M+3+T[S]*d,U=Xe(Se,{x0:v,x1:v+e.measureText(h(m)).width,y0:y-4-s+2,y1:y-4+2},s);e.fillText(h(m),v,U.y1-2)})}else{const u=f.map(d=>{const m=M+i.frac(d.value)*c,y=e.measureText(h(d)).width,S=pt(m,y,M,M+c,d.end==="lo");return{l:d,x:m,side:S,start:S<0?m-3-y:m+3,end:S<0?m-3:m+3+y}}),T=He(u,4);u.forEach(({l:d,x:m,side:y,start:S,end:v},U)=>{e.globalAlpha=.7,_e(e,d,l,m,k,m,k+r),e.globalAlpha=1,e.fillStyle=l,e.textAlign=y<0?"right":"left",e.textBaseline="top";const C=k+2+T[U]*s,E=Xe(Se,{x0:S,x1:v,y0:C,y1:C+s},s);e.fillText(h(d),m+y*3,E.y0)})}e.restore(),gt(e,p,{left:M,right:M+c,top:k,bottom:k+r},n==="y"?"vertical":"horizontal",l,u=>R(u,t.unit))}function Ee(e,l,c,r){return ct(Math.max(Math.abs(l),Math.abs(c)),e.unit,r)}function Ae(e,l){return l?`${e.label} (${l})`:e.label}function ye(e,l,c,r,i,o,t,n,f,p){Se=[],e.font=`${me(-1)}px system-ui, sans-serif`;const h=()=>mt,s=n.log?Ue(n.lo,n.hi,o,h):we(n.lo,n.hi,o,h),u=Ee(p,n.lo,n.hi,s.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let T="";if("labels"in t){const d=t.labels.length;t.labels.forEach((m,y)=>{const S=M+(y+.5)/d*i,v=m.length>22?`${m.slice(0,21)}\u2026`:m;t.rotate?(e.save(),e.translate(S,k+o+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(v,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(v,S,k+o+4))})}else{const d=ft(e,Math.max(Math.abs(t.lo),Math.abs(t.hi)),f.unit),m=t.log?Ue(t.lo,t.hi,i,d):we(t.lo,t.hi,i,d),y=Ee(f,t.lo,t.hi,m.step||void 0);T=y.unitLabel;for(const S of m.ticks){const v=M+t.frac(S)*i;e.beginPath(),e.moveTo(v,k),e.lineTo(v,k+o),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y.tick(S),v,k+o+4)}}for(const d of s.ticks){const m=k+(1-n.frac(d))*o;e.beginPath(),e.moveTo(M,m),e.lineTo(M+i,m),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(u.tick(d),M-4,m)}e.font=`${me(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Ae(f,T),M+i/2,r-6),e.save(),e.translate(14,k+o/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Ae(p,u.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(M,k),e.lineTo(M,k+o),e.moveTo(M,k+o),e.lineTo(M+i,k+o),e.stroke()}function Ye(){if(!a||!g||a.marks?.type!=="scatter"||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,n=a.marks.points,f=x.size===0?n:n.filter(E=>x.has(E.group)),p=a.colorScale,h=Pe(),s=le(a.x),u=le(a.y),T=ne(ae(n.map(E=>E.x),s),a.x),d=ne(ae(n.map(E=>E.y),u),a.y);z={x:T,y:d,plotW:r,plotH:i},ye(t,e,l,c,r,i,T,d,a.x,a.y),re(t,e.limitLine,r,i,T,s,a.x,"x"),re(t,e.limitLine,r,i,d,u,a.y,"y");const m=f.length>Ce?Math.ceil(f.length/Ce):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(f.length/m))),ce=[];const y=M,S=M+r,v=k,U=k+i;for(let E=0;E<f.length;E+=m){const N=f[E],se=M+T.frac(N.x)*r,Y=k+(1-d.frac(N.y))*i;se<y||se>S||Y<v||Y>U||(ce.push({p:N,cx:se,cy:Y}),t.beginPath(),t.arc(se,Y,2.5,0,Math.PI*2),t.fillStyle=p&&N.value!==void 0?h((N.value-p.lo)/(p.hi-p.lo||1)):ie(N.group),t.fill())}t.globalAlpha=1;const C=ue?ce.find(E=>E.p===ue):void 0;if(C&&(t.beginPath(),t.arc(C.cx,C.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),G.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let E=0;for(const N of G)if(!(x.size>0&&!x.has(N.group))){if(++E>Ce)break;t.beginPath(),t.arc(M+T.frac(N.x)*r,k+(1-d.frac(N.y))*i,4,0,Math.PI*2),t.stroke()}}}function Ge(){if(J=void 0,!a||a.marks?.type!=="histogram"||!a.x)return;const e=a.marks.values,l=e.flat();if(l.length===0)return;const c=ne(ae(l,le(a.x)),a.x),r=Math.max(1,a.spec.bins??kt),i=c.log?Math.log10(c.lo):c.lo,o=c.log?Math.log10(c.hi):c.hi,t=Array.from({length:r+1},(f,p)=>{const h=i+(o-i)*p/r;return c.log?10**h:h}),n=e.map(()=>new Array(r).fill(0));e.forEach((f,p)=>{for(const h of f){const s=c.log?h>0?Math.log10(h):NaN:h;if(!Number.isFinite(s)||s<i||s>o)continue;const u=Math.min(r-1,Math.floor((s-i)/(o-i)*r));n[p][u]++}}),J={edges:t,counts:n,maxCount:Math.max(1,...n.map(f=>fe(f)))}}function De(){if(!a||!g||!J||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,{edges:n,counts:f,maxCount:p}=J,h=ne([n[0],n[n.length-1]],{...a.x,min:n[0],max:n[n.length-1]}),s=ne([0,p],{label:a.y.label,scale:"linear",min:0,max:p*1.05});z={x:h,y:s,plotW:r,plotH:i},ye(t,e,l,c,r,i,h,s,a.x,a.y),re(t,e.limitLine,r,i,h,le(a.x),a.x,"x");const u=f.map((d,m)=>m).filter(d=>x.size===0||x.has(d)),T=u.length>1;for(const d of u)t.globalAlpha=T?.55:.85,t.fillStyle=ie(d),f[d].forEach((m,y)=>{if(m===0)return;const S=M+Math.min(h.frac(n[y]),h.frac(n[y+1]))*r,v=M+Math.max(h.frac(n[y]),h.frac(n[y+1]))*r,U=k+(1-s.frac(m))*i;t.fillRect(S,U,Math.max(1,v-S-1),k+i-U)});if(t.globalAlpha=1,X>=0){const d=M+Math.min(h.frac(n[X]),h.frac(n[X+1]))*r,m=M+Math.max(h.frac(n[X]),h.frac(n[X+1]))*r;t.lineWidth=1.5,t.strokeStyle=e.text,t.strokeRect(d,k,Math.max(1,m-d),i)}}function Ve(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="box"&&e.type!=="bar")return;ke(g,A??0);const l=ve($),c=g.getContext("2d");let r=0;c&&(c.font=`${me(-1)}px system-ui, sans-serif`,r=fe(e.categories.map(C=>c.measureText(C.length>22?`${C.slice(0,21)}\u2026`:C).width)));const i=Math.max(10,w.clientWidth-M-je)/Math.max(1,e.categories.length),o=r+8>i;de=o?he+Math.min(110,r*.72):he;const{w:t,h:n,plotW:f,plotH:p}=pe(),h=Me(g,$,t,n);if(!h)return;const{ctx:s}=h,u=C=>C.filter(Number.isFinite),T=le(a.y),d=ne(ae(e.type==="bar"?[...u(e.values.flat()),0]:u(e.cells.flat(2)),T),a.y,{floorAtZero:e.type==="bar"});z={x:d,y:d,plotW:f,plotH:p},ye(s,l,t,n,f,p,{labels:e.categories,rotate:o},d,a.x,a.y),re(s,l.limitLine,f,p,d,T,a.y,"y");const m=e.categories.length,y=a.groups.length,S=f/m,v=S*.8/y;D={slotW:S,gw:v,n:m,groups:y,plotW:f};const U=d.log?k+p:k+(1-d.frac(0))*p;for(let C=0;C<y;C++){if(x.size>0&&!x.has(C))continue;const E=ie(C);for(let N=0;N<m;N++){const se=M+N*S+S*.1+C*v;if(e.type==="bar"){const Y=e.values[C][N];if(!Number.isFinite(Y))continue;const j=k+(1-d.frac(Y))*p;s.fillStyle=E,s.globalAlpha=.9,s.fillRect(se+1,Math.min(j,U),Math.max(1,v-2),Math.max(1,Math.abs(U-j))),s.globalAlpha=1}else{const Y=e.cells[C][N];if(Y.length===0)continue;const j=se+v/2,ee=Math.max(3,Math.min(v*.7,46)),O=We(Float64Array.from(Y)),W=be=>k+(1-d.frac(be))*p;if(s.strokeStyle=E,s.fillStyle=E,s.lineWidth=1.5,Y.length===1){s.beginPath(),s.arc(j,W(O.median),3,0,Math.PI*2),s.fill();continue}s.beginPath(),s.moveTo(j,W(O.min)),s.lineTo(j,W(O.max)),s.stroke();for(const be of[O.min,O.max])s.beginPath(),s.moveTo(j-ee/4,W(be)),s.lineTo(j+ee/4,W(be)),s.stroke();s.globalAlpha=.35,s.fillRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.globalAlpha=1,s.strokeRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.lineWidth=2.5,s.beginPath(),s.moveTo(j-ee/2,W(O.median)),s.lineTo(j+ee/2,W(O.median)),s.stroke()}}}if(_){const C=M+_.c*S+S*.1+_.g*v;s.lineWidth=1.5,s.strokeStyle=l.text,s.strokeRect(C,k,v,p)}}function Ie(e){if(!D||!g)return null;const l=g.getBoundingClientRect(),c=e.clientX-l.left-M;if(c<0||c>D.plotW)return null;const r=Math.min(D.n-1,Math.floor(c/D.slotW)),i=Math.floor((c-r*D.slotW-D.slotW*.1)/D.gw);return i<0||i>=D.groups?null:{g:i,c:r}}function Ze(e){const l=a,c=l.marks,r=l.level==="die"?"dies":"wafers",i=c.cells[e.g][e.c],o=`<strong>${I(c.categories[e.c])}${l.groups.length>1?` \xB7 ${I(ge(e.g))}`:""}</strong><br>`,t=l.y?.unit;if(i.length===0)return`${o}no ${r}`;const n=`${i.length.toLocaleString("en-GB")} ${r}`,f=c.categoryItems&&b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"";if(c.type==="bar"){const h=c.values[e.g][e.c];return`${o}${I(`${l.y.label}: ${R(h,t)}`)}<br>${I(n)}${f}`}const p=We(Float64Array.from(i));return`${o}${["max","q3","median","q1","min"].map(h=>I(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[h]}: ${R(p[h],t)}`)).join("<br>")}<br>${I(n)}${f}`}function Ke(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="line")return;ke(g,A??0);const l=ve($),{w:c,h:r,plotW:i,plotH:o}=pe(),t=Me(g,$,c,r);if(!t)return;const{ctx:n}=t,f=le(a.x),p=le(a.y),h=ne(ae(e.xs,f),a.x),s=ne(ae(e.values.flat().filter(Number.isFinite),p),a.y);z={x:h,y:s,plotW:i,plotH:o},ye(n,l,c,r,i,o,h,s,a.x,a.y),re(n,l.limitLine,i,o,h,f,a.x,"x"),re(n,l.limitLine,i,o,s,p,a.y,"y"),Q=e.xs.map(u=>M+h.frac(u)*i),e.values.forEach((u,T)=>{if(x.size>0&&!x.has(T))return;n.strokeStyle=ie(T),n.fillStyle=ie(T),n.lineWidth=2;let d=!1;n.beginPath(),u.forEach((m,y)=>{if(!Number.isFinite(m)){d=!1;return}const S=Q[y],v=k+(1-s.frac(m))*o;d?n.lineTo(S,v):n.moveTo(S,v),d=!0}),n.stroke(),u.forEach((m,y)=>{Number.isFinite(m)&&(n.beginPath(),n.arc(Q[y],k+(1-s.frac(m))*o,V===y?4.5:3,0,Math.PI*2),n.fill())})}),V>=0&&(n.lineWidth=1,n.strokeStyle=l.textMuted,n.beginPath(),n.moveTo(Q[V],k),n.lineTo(Q[V],k+o),n.stroke())}function Ne(e){const l=a?.marks;if(!l||l.type!=="line"||!g||!a?.x||Q.length===0)return null;const c=e.clientX-g.getBoundingClientRect().left;let r=-1,i=24;if(Q.forEach((n,f)=>{const p=Math.abs(n-c);p<i&&(i=p,r=f)}),V=r,r<0)return null;const o=a.level==="die"?"dies":"wafers",t=l.values.map((n,f)=>({g:f,v:n[r],n:l.counts[f][r]})).filter(n=>Number.isFinite(n.v)&&(x.size===0||x.has(n.g)));return`<strong>${I(`${a.x.label}: ${R(l.xs[r],a.x.unit)}`)}</strong><br>`+t.map(n=>I(`${a.groups.length>1?`${ge(n.g)}: `:""}${R(n.v,a.y.unit)} (${n.n.toLocaleString("en-GB")} ${o})`)).join("<br>")}function B(){const e=a?.marks?.type;e==="scatter"?Ye():e==="histogram"?De():e==="box"||e==="bar"?Ve():e==="line"&&Ke()}function Je(e){const l=a,c=b.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",i=[c,r].filter(Boolean).join(" \xB7 "),o=(t,n)=>`${t.label}: ${R(n,t.unit)}`;return(i?`<strong>${I(i)}</strong><br>`:"")+I(o(l.x,e.x))+"<br>"+I(o(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${I(`${l.colorScale.label}: ${R(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${I(ge(e.group))}`:"")+(b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"")}function Be(e){if(!J||!z||!a?.x)return null;const l=g.getBoundingClientRect(),r=(e.clientX-l.left-M)/z.plotW;if(r<0||r>1)return null;const i=z.x.reverse?1-r:r,{edges:o,counts:t}=J,n=o.length-1,f=Math.min(n-1,Math.max(0,Math.floor(i*n)));X=f;const p=a.x,h=t.map((s,u)=>({g:u,n:s[f]})).filter(s=>s.n>0&&(x.size===0||x.has(s.g)));return`<strong>${I(`${R(o[f],p.unit)} to ${R(o[f+1],p.unit)}`)}</strong><br>`+(h.length?h.map(s=>I(`${a.groups.length>1?`${ge(s.g)}: `:""}${s.n.toLocaleString("en-GB")} ${a.level==="die"?"dies":"wafers"}`)).join("<br>"):"none")}function Qe(e){const l=P.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:te.md,marginTop:te.md,marginBottom:te.xl,fontSize:Le.body,color:xe.label});const c=P.createElement("canvas");c.width=200,c.height=10,Object.assign(c.style,{width:"200px",height:"10px",borderRadius:ot.control,flex:"0 0 auto"});const r=c.getContext("2d"),i=Pe();if(r)for(let f=0;f<200;f++)r.fillStyle=i(f/199),r.fillRect(f,0,1,10);const o=P.createElement("span");o.textContent=R(e.lo,e.unit);const t=P.createElement("span");t.textContent=R(e.hi,e.unit);const n=P.createElement("span");return n.textContent=e.label,n.style.color=xe.text,l.append(n,o,c,t),l}const Te=(e,l,c)=>l.map(r=>{const{item:i,die:o}=e(r);return{x:0,y:0,group:c,item:i,die:o}});function et(){Z?.destroy(),Z=void 0,w.innerHTML="",g=void 0,H=void 0,A=void 0,K=[],ue=null,X=-1,ce=[],z=void 0,D=void 0,_=null,Q=[],V=-1,de=he,x.clear(),G.clear();const e=a;if(!e)return;if(q.textContent=nt(e),$.dataset.wmapChartTitle=q.textContent,e.issues.length||!e.marks){for(const i of e.issues)qe(w,i);return}const l=P.createElement("div");Object.assign(l.style,{color:xe.label,fontSize:Le.body,marginBottom:te.xs});const c=b.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(b.onOpenWafer?` \xB7 click a point to ${c}`:"")+(b.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(b.onOpenWafer&&e.marks.categoryItems?` \xB7 click to ${c}`:b.onSelectPoints?" \xB7 click to chart or tabulate what it counts":"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&b.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="line"&&b.onSelectPoints?" \xB7 click a point to chart or tabulate what it averages":"";l.textContent=Fe(e)+r,Re(l),A=P.createElement("div"),A.style.display="flow-root",w.appendChild(A),A.appendChild(l);for(const i of e.notes){const o=P.createElement("div");Re(o),o.textContent=i,Object.assign(o.style,{color:xe.warnText,fontSize:Le.body,marginBottom:te.xs}),A.appendChild(o)}if(e.plotted===0){qe(w,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&(H=P.createElement("div"),Object.assign(H.style,{display:"flex",flexWrap:"wrap",gap:te.sm,marginTop:te.md,marginBottom:te.xl}),e.groups.forEach((i,o)=>{const t=ht(i||"(none)",ie(o),P);at(t.el,$,L,`${i||"(none)"} \u2014 click to filter`),t.el.addEventListener("click",()=>{x.has(o)?x.delete(o):x.add(o),K.forEach((n,f)=>n.setState({selected:x.has(f),dimmed:x.size>0&&!x.has(f)})),B()}),K.push(t),H.appendChild(t.el)}),A.appendChild(H)),e.colorScale&&(H=Qe(e.colorScale),A.appendChild(H)),g=P.createElement("canvas"),g.style.display="block",g.style.cursor=e.marks.type==="scatter"?"crosshair":"default",w.appendChild(g),e.marks.type==="scatter"){const i=e.marks,o=!!b.onSelectPoints;Z=xt({card:$,canvas:g,tooltip:L,drawn:()=>ce,describe:Je,clickable:()=>!!b.onOpenWafer,onOpen:t=>b.onOpenWafer?.(t.item,ze(e.spec)),onHover:t=>{ue=t,B()},select:o?{pick:({x0:t,y0:n,x1:f,y1:p})=>z?(x.size===0?i.points:i.points.filter(s=>x.has(s.group))).filter(s=>{const u=M+z.x.frac(s.x)*z.plotW,T=k+(1-z.y.frac(s.y))*z.plotH;return u>=t&&u<=f&&T>=n&&T<=p}):[],onPicked:(t,n)=>{G.clear();for(const f of t)G.add(f);B(),t.length>0&&b.onSelectPoints(t,n,g)},onClear:()=>{G.clear(),B()},hasSelection:()=>G.size>0}:void 0})}else if(e.marks.type==="histogram"){Ge(),g.addEventListener("mousemove",o=>{const t=Be(o);if(!t){L.style.display="none",X>=0&&(X=-1,B());return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",X>=0&&(X=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(!J||Be(o)===null)return;const t=X,{edges:n}=J,f=z?.x.log,p=f?Math.log10(n[0]):n[0],h=f?Math.log10(n[n.length-1]):n[n.length-1],s=n.length-1,u=[];i.values.forEach((T,d)=>{if(x.size>0&&!x.has(d))return;const m=[];T.forEach((y,S)=>{const v=f?y>0?Math.log10(y):NaN:y;!Number.isFinite(v)||v<p||v>h||Math.min(s-1,Math.floor((v-p)/(h-p)*s))===t&&m.push(i.units[d][S])}),u.push(...Te(i.unit,m,d))}),u.length>0&&(L.style.display="none",b.onSelectPoints(u,{x:o.clientX,y:o.clientY},g))}))}else if(e.marks.type==="box"||e.marks.type==="bar"){const i=e.marks;g.addEventListener("mousemove",o=>{const t=Ie(o);if(g.style.cursor=t&&(i.categoryItems&&b.onOpenWafer||b.onSelectPoints&&i.cellUnits[t.g][t.c].length>0)?"pointer":"default",!t){L.style.display="none",_&&(_=null,B());return}L.innerHTML=Ze(t),L.style.display="block",$e(L,$,o.clientX,o.clientY),(!_||_.g!==t.g||_.c!==t.c)&&(_=t,B())}),g.addEventListener("mouseleave",()=>{L.style.display="none",_&&(_=null,B())}),g.addEventListener("click",o=>{const t=Ie(o);if(!t)return;const n=i.categoryItems?.[t.c];if(n!==void 0&&n>=0&&b.onOpenWafer){b.onOpenWafer(n,ze(e.spec));return}const f=i.cellUnits[t.g][t.c];f.length>0&&b.onSelectPoints&&(L.style.display="none",b.onSelectPoints(Te(i.unit,f,t.g),{x:o.clientX,y:o.clientY},g))})}else if(e.marks.type==="line"){g.addEventListener("mousemove",o=>{const t=Ne(o);if(!t){L.style.display="none",B();return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",V>=0&&(V=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(Ne(o)===null||V<0)return;const t=i.cellUnits.flatMap((n,f)=>x.size>0&&!x.has(f)?[]:Te(i.unit,n[V]??[],f));t.length>0&&(L.style.display="none",b.onSelectPoints(t,{x:o.clientX,y:o.clientY},g))}))}B()}oe(()=>{const e=a;if(!e||!e.marks)return;const l=Pe();return{caption:[Fe(e),...e.notes],legend:e.groups.length>1?e.groups.map((c,r)=>({label:c||"(none)",color:ie(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:R(e.colorScale.lo,e.colorScale.unit),hi:R(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const tt=lt($,()=>B());return{card:$,actions:F,setPlot(e){a=e,et()},destroy(){tt.disconnect(),Z?.destroy()}}}
@@ -1,11 +1,16 @@
1
1
  import type { RegionYieldDatum } from '../../stats/regions.js';
2
2
  import { type SaveImageHandler } from './chartShell.js';
3
- export type RegionYieldMode = 'ring' | 'quadrant';
3
+ export type RegionYieldMode = 'ring' | 'quadrant' | 'reticleCell';
4
4
  export interface RegionYieldDiagramOptions {
5
5
  title?: string;
6
6
  mode: RegionYieldMode;
7
7
  /** Ring mode: ordered ring 1 (core) → ring N (edge), matching `buildRegionYieldData`'s output for `buildRingRegions`. Quadrant mode: any order — each row's quadrant is read from its `key` (`quadrant:NE` etc.), not position. */
8
8
  rows: RegionYieldDatum[];
9
+ /** Reticle-cell mode: the field's size in dies, so cells with no data still take their place. Without it the grid is as large as the cells given. */
10
+ grid?: {
11
+ width: number;
12
+ height: number;
13
+ };
9
14
  /** Click a region: called with it and the click, so the host can pick out the dies it counts and open a menu there. */
10
15
  onSelectRegion?: (row: RegionYieldDatum, e: MouseEvent) => void;
11
16
  onSaveImage?: SaveImageHandler;
@@ -1 +1 @@
1
- import{parseRegionKey as T}from"../../stats/regions.js";import{yieldFill as q}from"./palette.js";import{fontPx as v}from"../toolbar.js";import{cardShell as $,resolveChartCanvasColors as j,observeResize as z,growCardToFitContent as G,setChartGrow as L,isExpandedCard as O,bodyRoom as Y,renderEmptyState as _,prepareCanvas as B}from"./chartShell.js";const w=320,Q=220,E={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function X(e,a,n,h,f,o){e.beginPath(),e.moveTo(a+o,n),e.arcTo(a+h,n,a+h,n+f,o),e.arcTo(a+h,n+f,a,n+f,o),e.arcTo(a,n+f,a,n,o),e.arcTo(a,n,a+h,n,o),e.closePath()}function W(e,a,n,h,f,o){e.font=`${v(-1)}px system-ui, sans-serif`;const u=e.measureText(h).width;e.font="700 11px system-ui, sans-serif";const p=e.measureText(f).width,c=Math.max(u,p)+12,y=30;e.fillStyle=o.bg,X(e,a-c/2,n-y/2,c,y,4),e.fill(),e.strokeStyle=o.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=o.textMuted,e.font=`${v(-1)}px system-ui, sans-serif`,e.fillText(h,a,n-7),e.fillStyle=o.text,e.font="700 11px system-ui, sans-serif",e.fillText(f,a,n+7)}export function renderRegionYieldDiagram(e){const{mode:a,rows:n,onSaveImage:h}=e,f=e.title??(a==="ring"?"Ring yield":"Quadrant yield"),{card:o,body:u}=$(f,h,e.ownerDocument);L(o,"square");const p=n.length>0;if(!p)return _(u,"No bin data available for regional yield."),{card:o,hasData:p,destroy:()=>{}};Object.assign(u.style,{display:"flex",justifyContent:"center",alignItems:"center"});const c=o.ownerDocument.createElement("canvas");Object.assign(c.style,{display:"block",flex:"none"}),u.appendChild(c);let y={cx:0,cy:0,R:0};function C(){const g=Math.max(Q,Math.min(u.clientWidth||w,w));G(o,u,g);const d=O(o)?Math.max(g,Math.floor(Math.min(u.clientWidth,Y(o,u,c)))):g,P=B(c,o,d,d);if(!P)return;const{ctx:t}=P,m=j(o),S=q,s=d/2,i=d/2,M=d/2-34;if(y={cx:s,cy:i,R:M},a==="ring"){const l=n.length;for(let r=0;r<l;r++){const b=r/l*M,I=(r+1)/l*M;t.beginPath(),t.arc(s,i,I,0,2*Math.PI),t.arc(s,i,b,0,2*Math.PI,!0),t.closePath(),t.fillStyle=S(n[r].yieldPercent),t.fill(),t.strokeStyle=m.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(s,i,M,0,2*Math.PI),t.strokeStyle=m.text,t.lineWidth=1.5,t.stroke();for(let r=0;r<l;r++){const b=(r+.5)/l*M,I=-Math.PI/2+r/l*2*Math.PI,R=s+Math.cos(I)*b,k=i+Math.sin(I)*b;W(t,R,k,n[r].label,`${n[r].yieldPercent.toFixed(1)}%`,m)}}else{for(const l of n){const r=T(l.key).quadrant,b=r?E[r]:void 0;if(!b)continue;const[I,R]=b;t.beginPath(),t.moveTo(s,i),t.arc(s,i,M,I,R),t.closePath(),t.fillStyle=S(l.yieldPercent),t.fill(),t.strokeStyle=m.border,t.lineWidth=1,t.stroke();const k=(I+R)/2,N=s+Math.cos(k)*M*.6,F=i+Math.sin(k)*M*.6;W(t,N,F,l.label,`${l.yieldPercent.toFixed(1)}%`,m)}t.beginPath(),t.arc(s,i,M,0,2*Math.PI),t.strokeStyle=m.text,t.lineWidth=1.5,t.stroke()}}function A(g,d){const P=g-y.cx,t=d-y.cy,m=Math.hypot(P,t);if(!(m<=y.R))return null;if(a==="ring")return n[Math.min(n.length-1,Math.floor(m/y.R*n.length))]??null;const S=(Math.atan2(t,P)+2*Math.PI)%(2*Math.PI);return n.find(s=>{const i=E[T(s.key).quadrant??""];return!!i&&S>=i[0]&&S<i[1]})??null}e.onSelectRegion&&(c.style.cursor="pointer",c.addEventListener("click",g=>{const d=c.getBoundingClientRect(),P=A(g.clientX-d.left,g.clientY-d.top);P&&e.onSelectRegion(P,g)}));const D=z(o,()=>C());return C(),{card:o,hasData:p,destroy:()=>D.disconnect()}}
1
+ import{parseRegionKey as D,parseReticleCellKey as G}from"../../stats/regions.js";import{yieldFill as H}from"./palette.js";import{fontPx as L}from"../toolbar.js";import{escHtml as _}from"../../core/utils.js";import{makeTooltip as K,positionChartTooltip as Q,cardShell as Z,resolveChartCanvasColors as U,observeResize as z,growCardToFitContent as J,setChartGrow as V,isExpandedCard as x,bodyRoom as ee,renderEmptyState as te,prepareCanvas as ne}from"./chartShell.js";const N=320,oe=220,q={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function Y(e,r,o,m,M,l){e.beginPath(),e.moveTo(r+l,o),e.arcTo(r+m,o,r+m,o+M,l),e.arcTo(r+m,o+M,r,o+M,l),e.arcTo(r,o+M,r,o,l),e.arcTo(r,o,r+m,o,l),e.closePath()}function W(e,r,o,m,M,l){e.font=`${L(-1)}px system-ui, sans-serif`;const b=e.measureText(m).width;e.font="700 11px system-ui, sans-serif";const C=e.measureText(M).width,y=Math.max(b,C)+12,w=30;e.fillStyle=l.bg,Y(e,r-y/2,o-w/2,y,w,4),e.fill(),e.strokeStyle=l.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=l.textMuted,e.font=`${L(-1)}px system-ui, sans-serif`,e.fillText(m,r,o-7),e.fillStyle=l.text,e.font="700 11px system-ui, sans-serif",e.fillText(M,r,o+7)}function le(e,r,o,m,M){e.font="700 11px system-ui, sans-serif";const l=e.measureText(m).width+8;e.fillStyle=M.bg,Y(e,r-l/2,o-8,l,16,3),e.fill(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=M.text,e.fillText(m,r,o+.5)}export function renderRegionYieldDiagram(e){const{mode:r,rows:o,onSaveImage:m}=e,M=e.title??(r==="ring"?"Ring yield":r==="quadrant"?"Quadrant yield":"Reticle cell yield"),{card:l,body:b}=Z(M,m,e.ownerDocument);V(l,"square");const C=o.length>0;if(!C)return te(b,"No bin data available for regional yield."),{card:l,hasData:C,destroy:()=>{}};Object.assign(b.style,{display:"flex",justifyContent:"center",alignItems:"center"});const y=l.ownerDocument.createElement("canvas");Object.assign(y.style,{display:"block",flex:"none"}),b.appendChild(y);let w={cx:0,cy:0,R:0};const E=new Map;let S=0,P=0;if(r==="reticleCell"){for(const n of o){const i=G(n.key);i&&(E.set(`${i.column},${i.row}`,n),S=Math.max(S,i.column+1),P=Math.max(P,i.row+1))}S=Math.max(S,e.grid?.width??0),P=Math.max(P,e.grid?.height??0)}let k={x0:0,y0:0,side:0};const T=K(l);function B(n,i,c,t){const s=Math.max(4,Math.floor(Math.min((i-40)/S,(i-40)/P))),f=Math.round((i-s*S)/2),a=Math.round((i-s*P)/2);k={x0:f,y0:a,side:s};for(let I=0;I<P;I++)for(let u=0;u<S;u++){const h=f+u*s,d=a+(P-1-I)*s,g=E.get(`${u},${I}`);n.fillStyle=g?t(g.yieldPercent):c.bg,n.fillRect(h,d,s,s),n.strokeStyle=c.border,n.lineWidth=1,n.strokeRect(h+.5,d+.5,s-1,s-1),!(!g||s<30)&&(s>=54?W(n,h+s/2,d+s/2,`(${u}, ${I})`,`${g.yieldPercent.toFixed(1)}%`,c):le(n,h+s/2,d+s/2,`${g.yieldPercent.toFixed(0)}%`,c))}n.strokeStyle=c.text,n.lineWidth=1.5,n.strokeRect(f+.5,a+.5,s*S-1,s*P-1)}function F(){const n=Math.max(oe,Math.min(b.clientWidth||N,N));J(l,b,n);const i=x(l)?Math.max(n,Math.floor(Math.min(b.clientWidth,ee(l,b,y)))):n,c=ne(y,l,i,i);if(!c)return;const{ctx:t}=c,p=U(l),s=H;if(r==="reticleCell"){B(t,i,p,s);return}const f=i/2,a=i/2,u=i/2-34;if(w={cx:f,cy:a,R:u},r==="ring"){const h=o.length;for(let d=0;d<h;d++){const g=d/h*u,R=(d+1)/h*u;t.beginPath(),t.arc(f,a,R,0,2*Math.PI),t.arc(f,a,g,0,2*Math.PI,!0),t.closePath(),t.fillStyle=s(o[d].yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke();for(let d=0;d<h;d++){const g=(d+.5)/h*u,R=-Math.PI/2+d/h*2*Math.PI,$=f+Math.cos(R)*g,v=a+Math.sin(R)*g;W(t,$,v,o[d].label,`${o[d].yieldPercent.toFixed(1)}%`,p)}}else{for(const h of o){const d=D(h.key).quadrant,g=d?q[d]:void 0;if(!g)continue;const[R,$]=g;t.beginPath(),t.moveTo(f,a),t.arc(f,a,u,R,$),t.closePath(),t.fillStyle=s(h.yieldPercent),t.fill(),t.strokeStyle=p.border,t.lineWidth=1,t.stroke();const v=(R+$)/2,X=f+Math.cos(v)*u*.6,j=a+Math.sin(v)*u*.6;W(t,X,j,h.label,`${h.yieldPercent.toFixed(1)}%`,p)}t.beginPath(),t.arc(f,a,u,0,2*Math.PI),t.strokeStyle=p.text,t.lineWidth=1.5,t.stroke()}}function A(n,i){if(r==="reticleCell"){const f=Math.floor((n-k.x0)/k.side),a=Math.floor((i-k.y0)/k.side);return k.side<=0||f<0||f>=S||a<0||a>=P?null:E.get(`${f},${P-1-a}`)??null}const c=n-w.cx,t=i-w.cy,p=Math.hypot(c,t);if(!(p<=w.R))return null;if(r==="ring")return o[Math.min(o.length-1,Math.floor(p/w.R*o.length))]??null;const s=(Math.atan2(t,c)+2*Math.PI)%(2*Math.PI);return o.find(f=>{const a=q[D(f.key).quadrant??""];return!!a&&s>=a[0]&&s<a[1]})??null}y.addEventListener("mousemove",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);if(!c){T.style.display="none";return}T.innerHTML=`<strong>${_(c.label)}</strong><br>${c.yieldPercent.toFixed(1)}% yield (${c.passDies} of ${c.n} dies)`+(e.onSelectRegion?"<br><em>click to chart or tabulate these dies</em>":""),T.style.display="block",Q(T,l,n.clientX,n.clientY)}),y.addEventListener("mouseleave",()=>{T.style.display="none"}),e.onSelectRegion&&(y.style.cursor="pointer",y.addEventListener("click",n=>{const i=y.getBoundingClientRect(),c=A(n.clientX-i.left,n.clientY-i.top);c&&e.onSelectRegion(c,n)}));const O=z(l,()=>F());return F(),{card:l,hasData:C,destroy:()=>O.disconnect()}}
@@ -1 +1 @@
1
- import{NO_DATA_FILL as Ne}from"../../renderer/colorMap.js";import{escHtml as Z,maxOf as se,minOf as Re}from"../../core/utils.js";import{fmt as He}from"../../renderer/fmt.js";import{categorical as st}from"./palette.js";import{buildScatterData as lt,buildScatterDataGrouped as at}from"../../stats/scatter.js";import{pearsonOfPairs as rt}from"../../stats/correlation.js";import{buildFacetTable as ct}from"../../stats/facets.js";import{SPACE as D,RADIUS as dt,fontPx as z,FONT as ge,CLR as ee}from"../toolbar.js";import{fitTicks as Fe}from"../../renderer/axisTicks.js";import{wirePointInteractions as ft}from"./pointInteractions.js";import{cardShell as mt,observeResize as ut,makeTooltip as pt,attachChartTip as xt,makeTestSelect as ht,makeWaferSelect as bt,chartFillHeight as gt,applyCanvasFlow as yt,drawAxisUnit as wt,resolveChartCanvasColors as St,makeAxisFormat as le,horizontalTickSpacing as Tt,VERTICAL_TICK_SPACING_PX as kt,makeSeriesLegendItem as Mt,prepareCanvas as vt,drawOffAxisLimits as _e,limitLines as Lt,hasBothLimitKinds as Ct,makeLimitsSelect as Ot,stackLabelRows as je,strokeLimitLine as Ge,fillTextOnHalo as Xe}from"./chartShell.js";const u=52,At=16,c=16,Pt=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(x){return x===void 0?NO_BIN_CATEGORY:String(x)}export function binCategories(x){const te=new Set;let k=!1;for(const N of x)N.hbin===void 0?k=!0:te.add(N.hbin);const L=Array.from(te).sort((N,ae)=>N-ae).map(String);return k&&L.push(NO_BIN_CATEGORY),L}export function renderScatterPanel(x){const{title:te="Test scatter",items:k,testDefs:L,binColors:N,onSaveImage:ae,groups:_}=x,{card:l,body:R,controlsRow:re}=mt(te,ae,x.ownerDocument),ne=L.filter(e=>e.testNumber!==void 0),C=!!(_&&_.length>0),ye=(_??[]).map(e=>e.key),Ye=new Map(ye.map((e,n)=>[e,n]));let f=x.xTestNumber??ne[0]?.testNumber??null,w=x.yTestNumber??ne[1]?.testNumber??f,j=null;const we=()=>j!==null?k[j]?[k[j]]:[]:k;function Se(e,n,o){const a=l.ownerDocument.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:D.xs,fontSize:ge.body,color:ee.label});const g=l.ownerDocument.createElement("span");g.textContent=e;const r=ht(ne,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:l.ownerDocument});return a.append(g,r),{wrap:a,select:r}}const{wrap:Ue,select:Ke}=Se("X:",f,e=>{f=e,K()}),{wrap:Ve,select:qe}=Se("Y:",w,e=>{w=e,K()});re.append(Ue,Ve);let O=x.axisPrefs??{clipOutliers:!1};const Te=l.ownerDocument.createElement("span");re.appendChild(Te);function ke(){const e=[f,w].map(n=>L.find(o=>o.testNumber===n));Te.replaceChildren(...e.some(Ct)?[Ot(O.limits??"both",n=>{O={...O,limits:n},x.onAxisPrefsChange?.(O),v()},l.ownerDocument)]:[])}!C&&k.length>1&&re.appendChild(bt(k,j,e=>{j=e,K()},{ownerDocument:l.ownerDocument}));const H=l.ownerDocument.createElement("div");H.dataset.wmapCaption="1",Object.assign(H.style,{color:ee.warnText,background:ee.warnBg,border:`1px solid ${ee.warnBorder}`,borderRadius:dt.control,padding:`${D.xs} ${D.md}`,fontSize:ge.body,marginBottom:D.xs,display:"none"}),l.insertBefore(H,R);function Me(){const e=C?[]:ct(we(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(H.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,H.style.display=""):H.style.display="none"}Me();const oe=l.ownerDocument.createElement("div");oe.dataset.wmapCaption="1",Object.assign(oe.style,{color:ee.label,fontSize:ge.body,marginBottom:D.xs}),l.insertBefore(oe,R);function G(){const e=(C?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter")+(fe?` \xB7 click a point to ${Ce}`:"")+(de?M.size>0?` \xB7 ${M.size.toLocaleString()} selected (click empty space to clear)`:" \xB7 drag to select dies":""),n=h.size===0?b:b.filter(g=>h.has(B(g))),{r:o,n:a}=rt(n);oe.textContent=o===null?`${e} \xB7 n = ${a.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${a.toLocaleString()}`}const B=e=>C?e.group??"\u2014":binCategoryOf(e.hbin),ve=e=>C?st(Ye.get(e)??0):e===NO_BIN_CATEGORY?Ne:N?.get(Number(e))??Ne,ce=e=>C?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,h=new Set,X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:D.sm,marginTop:D.md,marginBottom:D.xl}),R.appendChild(X);const A=l.ownerDocument.createElement("canvas");A.style.display="block",A.style.cursor="crosshair",R.appendChild(A);const Le=pt(l);let b=[],y=0,P=1,S=0,E=1,Y=[],ie=null;const M=new Set,de=x.onSelect,fe=x.onOpen,Ce=x.openActionLabel??"open this wafer",Oe=new Map;for(const e of[...k,...(_??[]).flatMap(n=>n.items)])e.waferIndex!==void 0&&e.label&&Oe.set(e.waferIndex,e.label);function U(e){const n=L.find(o=>o.testNumber===e);return{unit:n?.unit,lines:Lt(n,O.limits)}}function Ae(){const e=R.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=gt(l,R,A,n);return{w:e,h:o,plotW:Math.max(10,e-u-At),plotH:Math.max(10,o-c-Pt)}}const me=new Map;function Pe(){for(const[e,n]of me){const o=h.has(e);n.setState({selected:o,dimmed:h.size>0&&!o})}}function $e(e){X.innerHTML="",me.clear(),h.clear();for(const n of e){const o=Mt(ce(n),ve(n),l.ownerDocument),a=o.el;a.dataset.cat=n,me.set(n,o),xt(a,l,Le,`${ce(n)} \u2014 click to filter`),a.addEventListener("click",()=>{h.has(n)?h.delete(n):h.add(n),Pe(),G(),v()}),X.appendChild(a)}Pe()}function v(){yt(A,X);const e=St(l),n=P-y,o=E-S,{w:a,h:g,plotW:r,plotH:s}=Ae(),W=vt(A,l,a,g);if(!W)return;const{ctx:t}=W;if(b.length===0){Y=[],t.font=`${z()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",a/2,g/2);return}t.font=`${z(-1)}px system-ui, sans-serif`;const T=f!==null?U(f).unit:void 0,V=Fe(y,P,r,Tt(t,Math.max(Math.abs(y),Math.abs(P)),T)),q=Fe(S,E,s,()=>kt),ue=le(Math.max(Math.abs(y),Math.abs(P)),f!==null?U(f).unit:void 0,V.step||void 0),pe=le(Math.max(Math.abs(S),Math.abs(E)),w!==null?U(w).unit:void 0,q.step||void 0);t.font=`${z(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of V.ticks){const d=u+(m-y)/n*r;t.beginPath(),t.moveTo(d,c),t.lineTo(d,c+s),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(ue.tick(m),d,c+s+4)}for(const m of q.ticks){const d=c+(1-(m-S)/o)*s;t.beginPath(),t.moveTo(u,d),t.lineTo(u+r,d),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(pe.tick(m),u-4,d)}ue.unitLabel&&wt(t,ue.unitLabel,u+r/2,c+s+24,e.textMuted),pe.unitLabel&&(t.save(),t.font=`${z(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,c+s/2),t.rotate(-Math.PI/2),t.fillText(`(${pe.unitLabel})`,0,0),t.restore());const J=h.size===0?b:b.filter(m=>h.has(B(m))),De=J.length>5e3?Math.ceil(J.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(J.length/De))),Y=[];for(let m=0;m<J.length;m+=De){const d=J[m],$=u+(d.x-y)/n*r,I=c+(1-(d.y-S)/o)*s;Y.push({p:d,cx:$,cy:I}),t.beginPath(),t.arc($,I,2.5,0,Math.PI*2),t.fillStyle=ve(B(d)),t.fill()}t.globalAlpha=1;const xe=ie?Y.find(m=>m.p===ie):void 0;if(xe&&(t.beginPath(),t.arc(xe.cx,xe.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),M.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let m=0;for(const d of M){if(h.size>0&&!h.has(B(d)))continue;if(++m>5e3)break;const $=u+(d.x-y)/n*r,I=c+(1-(d.y-S)/o)*s;t.beginPath(),t.arc($,I,4,0,Math.PI*2),t.stroke()}}if(f!==null&&w!==null){const m=U(f),d=U(w);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${z(-1)}px system-ui, sans-serif`,t.textBaseline="top";const $=z(-1)+2,I=m.lines.filter(i=>i.value>=y&&i.value<=P).map(i=>{const p=u+(i.value-y)/n*r;return{l:i,cx:p,start:p+2,end:p+2+t.measureText(i.label).width}}),Be=je(I);I.forEach(({l:i,cx:p},Q)=>{Ge(t,i,e.limitLine,p,c,p,c+s),t.textAlign="left",Xe(t,i.label,p+2,c+2+Be[Q]*$,e.bg)});const he=d.lines.filter(i=>i.value>=S&&i.value<=E).map(i=>{const p=c+(1-(i.value-S)/o)*s;return{l:i,cy:p,start:p+2,end:p+2+z(-1)}}),nt=je(he,1),ot=se(he.map(i=>t.measureText(i.l.label).width))+8;he.forEach(({l:i,cy:p},Q)=>{Ge(t,i,e.limitLine,u,p,u+r,p),t.textAlign="left",Xe(t,i.label,u+3+nt[Q]*ot,p+2,e.bg)});const Ee=(i,p,Q)=>i.filter(F=>F.value<p||F.value>Q).map(F=>({value:F.value,label:F.label,side:F.value<p?"lo":"hi"})),We={left:u,right:u+r,top:c,bottom:c+s},be=Ee(m.lines,y,P),ze=c+(I.length?(se(Be)+1)*$:0),it=Math.max(be.filter(i=>i.side==="lo").length,be.filter(i=>i.side==="hi").length);_e(t,be,{...We,top:ze},"horizontal",e.limitLine,i=>le(Math.abs(i),m.unit).tick(i),e.bg),_e(t,Ee(d.lines,S,E),{...We,top:ze+it*$},"vertical",e.limitLine,i=>le(Math.abs(i),d.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(u,c),t.lineTo(u,c+s),t.moveTo(u,c+s),t.lineTo(u+r,c+s),t.stroke()}function K(){if(ie=null,M.clear(),Me(),ke(),ne.length<2||f===null||w===null){b=[],$e([]),G(),v();return}b=C?at(_,f,w):lt(we(),f,w);let e;if(C){const n=new Set(b.map(B));e=ye.filter(o=>n.has(o))}else e=binCategories(b);if($e(e),G(),b.length>0){const n=b.map(T=>T.x),o=b.map(T=>T.y),a=Re(n),g=se(n),r=Re(o),s=se(o),W=(g-a)*.05||1,t=(s-r)*.05||1;y=a-W,P=g+W,S=r-t,E=s+t}v()}const Ie=e=>!!fe&&e.waferIndex!==void 0;function Je(e){const n=L.find(s=>s.testNumber===f),o=L.find(s=>s.testNumber===w),a=e.waferIndex!==void 0?Oe.get(e.waferIndex):void 0,g=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,g].filter(Boolean).join(" \xB7 ");return(r?`<strong>${Z(r)}</strong><br>`:"")+Z(`${n?.name??"X"}: ${He(e.x,n?.unit)}`)+"<br>"+Z(`${o?.name??"Y"}: ${He(e.y,o?.unit)}`)+"<br>"+Z(ce(B(e)))+(Ie(e)?`<br><em>click to ${Z(Ce)}</em>`:"")}const Qe=ft({card:l,canvas:A,tooltip:Le,drawn:()=>Y,describe:Je,clickable:Ie,onOpen:e=>{f!==null&&fe(e.waferIndex,f)},onHover:e=>{ie=e,v()},select:de?{pick:({x0:e,y0:n,x1:o,y1:a})=>{const{plotW:g,plotH:r}=Ae(),s=P-y,W=E-S;return(h.size===0?b:b.filter(T=>h.has(B(T)))).filter(T=>{const V=u+(T.x-y)/s*g,q=c+(1-(T.y-S)/W)*r;return V>=e&&V<=o&&q>=n&&q<=a})},onPicked:(e,n)=>{M.clear();for(const o of e)M.add(o);G(),v(),e.length>0&&f!==null&&de(e,n,A,f)},onClear:()=>{M.clear(),G(),v()},hasSelection:()=>M.size>0}:void 0}),Ze=ut(l,()=>v());K();function et(e,n){f=e,w=n,Ke.value=String(e),qe.value=String(n),K()}function tt(e){if((e.limits??"both")===(O.limits??"both")){O=e;return}O=e,ke(),v()}return{card:l,setXY:et,setAxisPrefs:tt,destroy:()=>{Ze.disconnect(),Qe.destroy()}}}
1
+ import{NO_DATA_FILL as Fe}from"../../renderer/colorMap.js";import{escHtml as Z,maxOf as se,minOf as _e}from"../../core/utils.js";import{fmt as je}from"../../renderer/fmt.js";import{categorical as dt}from"./palette.js";import{buildScatterData as ft,buildScatterDataGrouped as mt}from"../../stats/scatter.js";import{pearsonOfPairs as ut}from"../../stats/correlation.js";import{buildFacetTable as pt}from"../../stats/facets.js";import{SPACE as B,RADIUS as xt,fontPx as N,FONT as ge,CLR as ee}from"../toolbar.js";import{fitTicks as Ge}from"../../renderer/axisTicks.js";import{wirePointInteractions as ht}from"./pointInteractions.js";import{placeClearOf as Xe,cardShell as bt,observeResize as yt,makeTooltip as gt,attachChartTip as wt,makeTestSelect as St,makeWaferSelect as Tt,chartFillHeight as kt,applyCanvasFlow as Mt,drawAxisUnit as vt,resolveChartCanvasColors as Ct,makeAxisFormat as le,horizontalTickSpacing as Lt,VERTICAL_TICK_SPACING_PX as Ot,makeSeriesLegendItem as At,prepareCanvas as Pt,drawOffAxisLimits as Ye,limitLines as $t,hasBothLimitKinds as It,makeLimitsSelect as Dt,stackLabelRows as Ue,strokeLimitLine as Ke,fillTextOnHalo as Ve}from"./chartShell.js";const p=52,Bt=16,c=16,Et=44;export const NO_BIN_CATEGORY="none";export function binCategoryOf(x){return x===void 0?NO_BIN_CATEGORY:String(x)}export function binCategories(x){const te=new Set;let v=!1;for(const R of x)R.hbin===void 0?v=!0:te.add(R.hbin);const O=Array.from(te).sort((R,ae)=>R-ae).map(String);return v&&O.push(NO_BIN_CATEGORY),O}export function renderScatterPanel(x){const{title:te="Test scatter",items:v,testDefs:O,binColors:R,onSaveImage:ae,groups:_}=x,{card:l,body:H,controlsRow:re}=bt(te,ae,x.ownerDocument),ne=O.filter(e=>e.testNumber!==void 0),A=!!(_&&_.length>0),we=(_??[]).map(e=>e.key),qe=new Map(we.map((e,n)=>[e,n]));let f=x.xTestNumber??ne[0]?.testNumber??null,w=x.yTestNumber??ne[1]?.testNumber??f,j=null;const Se=()=>j!==null?v[j]?[v[j]]:[]:v;function Te(e,n,o){const a=l.ownerDocument.createElement("label");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:B.xs,fontSize:ge.body,color:ee.label});const y=l.ownerDocument.createElement("span");y.textContent=e;const r=St(ne,n,o,{maxWidth:"180px",emptyText:"No tests",ownerDocument:l.ownerDocument});return a.append(y,r),{wrap:a,select:r}}const{wrap:Je,select:Qe}=Te("X:",f,e=>{f=e,K()}),{wrap:Ze,select:et}=Te("Y:",w,e=>{w=e,K()});re.append(Je,Ze);let P=x.axisPrefs??{clipOutliers:!1};const ke=l.ownerDocument.createElement("span");re.appendChild(ke);function Me(){const e=[f,w].map(n=>O.find(o=>o.testNumber===n));ke.replaceChildren(...e.some(It)?[Dt(P.limits??"both",n=>{P={...P,limits:n},x.onAxisPrefsChange?.(P),L()},l.ownerDocument)]:[])}!A&&v.length>1&&re.appendChild(Tt(v,j,e=>{j=e,K()},{ownerDocument:l.ownerDocument}));const F=l.ownerDocument.createElement("div");F.dataset.wmapCaption="1",Object.assign(F.style,{color:ee.warnText,background:ee.warnBg,border:`1px solid ${ee.warnBorder}`,borderRadius:xt.control,padding:`${B.xs} ${B.md}`,fontSize:ge.body,marginBottom:B.xs,display:"none"}),l.insertBefore(F,H);function ve(){const e=A?[]:pt(Se(),{facetableOnly:!0}).filter(n=>n.splittable).map(n=>n.label);e.length>0?(F.textContent=`\u26A0 Mixed ${e.join(", ")} across these points \u2014 trends here may be confounded (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,F.style.display=""):F.style.display="none"}ve();const oe=l.ownerDocument.createElement("div");oe.dataset.wmapCaption="1",Object.assign(oe.style,{color:ee.label,fontSize:ge.body,marginBottom:B.xs}),l.insertBefore(oe,H);function G(){const e=(A?"One point per die \xB7 coloured by group \xB7 click legend to filter":"One point per die across all wafers \xB7 coloured by hard bin \xB7 click legend to filter")+(fe?` \xB7 click a point to ${Oe}`:"")+(de?C.size>0?` \xB7 ${C.size.toLocaleString()} selected (click empty space to clear)`:" \xB7 drag to select dies":""),n=h.size===0?b:b.filter(y=>h.has(E(y))),{r:o,n:a}=ut(n);oe.textContent=o===null?`${e} \xB7 n = ${a.toLocaleString()}`:`${e} \xB7 r = ${o.toFixed(3)} \xB7 n = ${a.toLocaleString()}`}const E=e=>A?e.group??"\u2014":binCategoryOf(e.hbin),Ce=e=>A?dt(qe.get(e)??0):e===NO_BIN_CATEGORY?Fe:R?.get(Number(e))??Fe,ce=e=>A?e:e===NO_BIN_CATEGORY?"No bin data":`Bin ${e}`,h=new Set,X=l.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexWrap:"wrap",gap:B.sm,marginTop:B.md,marginBottom:B.xl}),H.appendChild(X);const $=l.ownerDocument.createElement("canvas");$.style.display="block",$.style.cursor="crosshair",H.appendChild($);const Le=gt(l);let b=[],g=0,I=1,S=0,W=1,Y=[],ie=null;const C=new Set,de=x.onSelect,fe=x.onOpen,Oe=x.openActionLabel??"open this wafer",Ae=new Map;for(const e of[...v,...(_??[]).flatMap(n=>n.items)])e.waferIndex!==void 0&&e.label&&Ae.set(e.waferIndex,e.label);function U(e){const n=O.find(o=>o.testNumber===e);return{unit:n?.unit,lines:$t(n,P.limits)}}function Pe(){const e=H.clientWidth,n=Math.max(200,Math.min(400,e*.65)),o=kt(l,H,$,n);return{w:e,h:o,plotW:Math.max(10,e-p-Bt),plotH:Math.max(10,o-c-Et)}}const me=new Map;function $e(){for(const[e,n]of me){const o=h.has(e);n.setState({selected:o,dimmed:h.size>0&&!o})}}function Ie(e){X.innerHTML="",me.clear(),h.clear();for(const n of e){const o=At(ce(n),Ce(n),l.ownerDocument),a=o.el;a.dataset.cat=n,me.set(n,o),wt(a,l,Le,`${ce(n)} \u2014 click to filter`),a.addEventListener("click",()=>{h.has(n)?h.delete(n):h.add(n),$e(),G(),L()}),X.appendChild(a)}$e()}function L(){Mt($,X);const e=Ct(l),n=I-g,o=W-S,{w:a,h:y,plotW:r,plotH:s}=Pe(),z=Pt($,l,a,y);if(!z)return;const{ctx:t}=z;if(b.length===0){Y=[],t.font=`${N()}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.fillText("No data \u2014 select two parametric tests with values.",a/2,y/2);return}t.font=`${N(-1)}px system-ui, sans-serif`;const M=f!==null?U(f).unit:void 0,V=Ge(g,I,r,Lt(t,Math.max(Math.abs(g),Math.abs(I)),M)),q=Ge(S,W,s,()=>Ot),ue=le(Math.max(Math.abs(g),Math.abs(I)),f!==null?U(f).unit:void 0,V.step||void 0),pe=le(Math.max(Math.abs(S),Math.abs(W)),w!==null?U(w).unit:void 0,q.step||void 0);t.font=`${N(-1)}px system-ui, sans-serif`,t.strokeStyle=e.grid,t.lineWidth=.5,t.fillStyle=e.textMuted;for(const m of V.ticks){const d=p+(m-g)/n*r;t.beginPath(),t.moveTo(d,c),t.lineTo(d,c+s),t.stroke(),t.textAlign="center",t.textBaseline="top",t.fillText(ue.tick(m),d,c+s+4)}for(const m of q.ticks){const d=c+(1-(m-S)/o)*s;t.beginPath(),t.moveTo(p,d),t.lineTo(p+r,d),t.stroke(),t.textAlign="right",t.textBaseline="middle",t.fillText(pe.tick(m),p-4,d)}ue.unitLabel&&vt(t,ue.unitLabel,p+r/2,c+s+24,e.textMuted),pe.unitLabel&&(t.save(),t.font=`${N(-1)}px system-ui, sans-serif`,t.fillStyle=e.textMuted,t.textAlign="center",t.textBaseline="middle",t.translate(6,c+s/2),t.rotate(-Math.PI/2),t.fillText(`(${pe.unitLabel})`,0,0),t.restore());const J=h.size===0?b:b.filter(m=>h.has(E(m))),Be=J.length>5e3?Math.ceil(J.length/5e3):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(J.length/Be))),Y=[];for(let m=0;m<J.length;m+=Be){const d=J[m],T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;Y.push({p:d,cx:T,cy:D}),t.beginPath(),t.arc(T,D,2.5,0,Math.PI*2),t.fillStyle=Ce(E(d)),t.fill()}t.globalAlpha=1;const xe=ie?Y.find(m=>m.p===ie):void 0;if(xe&&(t.beginPath(),t.arc(xe.cx,xe.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),C.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let m=0;for(const d of C){if(h.size>0&&!h.has(E(d)))continue;if(++m>5e3)break;const T=p+(d.x-g)/n*r,D=c+(1-(d.y-S)/o)*s;t.beginPath(),t.arc(T,D,4,0,Math.PI*2),t.stroke()}}if(f!==null&&w!==null){const m=U(f),d=U(w);t.strokeStyle=e.limitLine,t.fillStyle=e.limitLine,t.lineWidth=1,t.font=`${N(-1)}px system-ui, sans-serif`,t.textBaseline="top";const T=N(-1)+2,D=m.lines.filter(i=>i.value>=g&&i.value<=I).map(i=>{const u=p+(i.value-g)/n*r;return{l:i,cx:u,start:u+2,end:u+2+t.measureText(i.label).width}}),Ee=Ue(D),We=[];D.forEach(({l:i,cx:u,start:Q,end:k},ye)=>{Ke(t,i,e.limitLine,u,c,u,c+s),t.textAlign="left";const He=c+2+Ee[ye]*T,ct=Xe(We,{x0:Q,x1:k,y0:He,y1:He+T},T);Ve(t,i.label,u+2,ct.y0,e.bg)});const he=d.lines.filter(i=>i.value>=S&&i.value<=W).map(i=>{const u=c+(1-(i.value-S)/o)*s;return{l:i,cy:u,start:u+2,end:u+2+N(-1)}}),lt=Ue(he,1),at=se(he.map(i=>t.measureText(i.l.label).width))+8;he.forEach(({l:i,cy:u},Q)=>{Ke(t,i,e.limitLine,p,u,p+r,u),t.textAlign="left";const k=p+3+lt[Q]*at,ye=Xe(We,{x0:k,x1:k+t.measureText(i.label).width,y0:u+2,y1:u+2+T},T);Ve(t,i.label,k,ye.y0,e.bg)});const ze=(i,u,Q)=>i.filter(k=>k.value<u||k.value>Q).map(k=>({value:k.value,label:k.label,side:k.value<u?"lo":"hi"})),Ne={left:p,right:p+r,top:c,bottom:c+s},be=ze(m.lines,g,I),Re=c+(D.length?(se(Ee)+1)*T:0),rt=Math.max(be.filter(i=>i.side==="lo").length,be.filter(i=>i.side==="hi").length);Ye(t,be,{...Ne,top:Re},"horizontal",e.limitLine,i=>le(Math.abs(i),m.unit).tick(i),e.bg),Ye(t,ze(d.lines,S,W),{...Ne,top:Re+rt*T},"vertical",e.limitLine,i=>le(Math.abs(i),d.unit).tick(i),e.bg),t.setLineDash([])}t.strokeStyle=e.border,t.lineWidth=1,t.beginPath(),t.moveTo(p,c),t.lineTo(p,c+s),t.moveTo(p,c+s),t.lineTo(p+r,c+s),t.stroke()}function K(){if(ie=null,C.clear(),ve(),Me(),ne.length<2||f===null||w===null){b=[],Ie([]),G(),L();return}b=A?mt(_,f,w):ft(Se(),f,w);let e;if(A){const n=new Set(b.map(E));e=we.filter(o=>n.has(o))}else e=binCategories(b);if(Ie(e),G(),b.length>0){const n=b.map(M=>M.x),o=b.map(M=>M.y),a=_e(n),y=se(n),r=_e(o),s=se(o),z=(y-a)*.05||1,t=(s-r)*.05||1;g=a-z,I=y+z,S=r-t,W=s+t}L()}const De=e=>!!fe&&e.waferIndex!==void 0;function tt(e){const n=O.find(s=>s.testNumber===f),o=O.find(s=>s.testNumber===w),a=e.waferIndex!==void 0?Ae.get(e.waferIndex):void 0,y=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,y].filter(Boolean).join(" \xB7 ");return(r?`<strong>${Z(r)}</strong><br>`:"")+Z(`${n?.name??"X"}: ${je(e.x,n?.unit)}`)+"<br>"+Z(`${o?.name??"Y"}: ${je(e.y,o?.unit)}`)+"<br>"+Z(ce(E(e)))+(De(e)?`<br><em>click to ${Z(Oe)}</em>`:"")}const nt=ht({card:l,canvas:$,tooltip:Le,drawn:()=>Y,describe:tt,clickable:De,onOpen:e=>{f!==null&&fe(e.waferIndex,f)},onHover:e=>{ie=e,L()},select:de?{pick:({x0:e,y0:n,x1:o,y1:a})=>{const{plotW:y,plotH:r}=Pe(),s=I-g,z=W-S;return(h.size===0?b:b.filter(M=>h.has(E(M)))).filter(M=>{const V=p+(M.x-g)/s*y,q=c+(1-(M.y-S)/z)*r;return V>=e&&V<=o&&q>=n&&q<=a})},onPicked:(e,n)=>{C.clear();for(const o of e)C.add(o);G(),L(),e.length>0&&f!==null&&de(e,n,$,f)},onClear:()=>{C.clear(),G(),L()},hasSelection:()=>C.size>0}:void 0}),ot=yt(l,()=>L());K();function it(e,n){f=e,w=n,Qe.value=String(e),et.value=String(n),K()}function st(e){if((e.limits??"both")===(P.limits??"both")){P=e;return}P=e,Me(),L()}return{card:l,setXY:it,setAxisPrefs:st,destroy:()=>{ot.disconnect(),nt.destroy()}}}
@@ -1 +1 @@
1
- import{buildTestPassRateData as F,hasJudgeableTests as N}from"../../stats/testPassRate.js";import{categorical as B,QUANTITY as I}from"./palette.js";import{SPACE as _,FONT as H,CLR as L}from"../toolbar.js";import{cardShell as k,makeTooltip as A,makeSegmented as O,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as j}from"./groupedBarPlot.js";import{escHtml as f}from"../../core/utils.js";const M=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(i){const{groups:b,testDefs:h,onSaveImage:$}=i,p=i.ownerDocument??document,C=b.flatMap(t=>t.items.flatMap(o=>o.dies??[])),m=["spec","testFlag","functional"].filter(t=>N(h,t,C));let s=m[0]??"spec";const T=t=>U[t],{card:n,heading:P,body:c,controlsRow:R}=k(T(s),$,p);n.style.alignSelf="start",m.length>1&&R.appendChild(O(m.map(t=>[t,K[t]]),s,t=>{s=t,P.textContent=T(s),S()},p));const r=p.createElement("div");r.dataset.wmapCaption="1",Object.assign(r.style,{color:L.label,fontSize:H.body,marginBottom:_.sm}),n.insertBefore(r,c);const D=A(n);let g=null;function S(){if(g?.destroy(),g=null,c.innerHTML="",m.length===0){r.textContent="",y(c,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const t=F(b,h,s);if(t.rows.length===0){r.textContent="",y(c,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const o=t.groups.length>1,v=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(r.textContent=v+(o?" \xB7 one bar per group":"")+" \xB7 worst first"+(i.onSelectTest?" \xB7 click a test to chart or tabulate the dies that fail it":""),t.disagreementDies){const e=p.createElement("span");e.textContent=` \xB7 ${t.disagreementDies.toLocaleString()} die${t.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(e.style,{color:L.warnText}),r.appendChild(e)}const u=t.rows,x=e=>o?B(e):I;g=j(n,c,D,{rows:u.map(e=>({label:e.label,bars:e.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:e.overall.passRatePercent===null?"\u2014":`${e.overall.passRatePercent.toFixed(1)}%`})),groups:t.groups,labelWidth:M,maxVisibleRows:G,showLegend:o,maxLabelChars:14,emptyBarText:"no data",colorOf:x,onRowClick:i.onSelectTest?(e,l,a)=>i.onSelectTest({testNumber:u[e].testNumber,label:u[e].label,kind:s},a):void 0,tooltipHtml:(e,l)=>{const a=u[e],d=a.byGroup[l],w=o?` \xB7 ${f(String(t.groups[l]))}`:"";if(d.passRatePercent===null)return`<strong>${f(a.label)}</strong>${w}<br>no dies with a verdict`;const E=s==="spec"&&!o&&(a.failLowDies||a.failHighDies)?`<br>${a.failLowDies??0} below the low limit \xB7 ${a.failHighDies??0} above the high limit`:"";return`<strong>${f(a.label)}</strong>${w}<br>${d.passRatePercent.toFixed(1)}% pass<br>${d.passDies.toLocaleString()} pass \xB7 ${d.failDies.toLocaleString()} fail \xB7 n = ${d.totalDies.toLocaleString()}`+E}})}return S(),{card:n,destroy:()=>{g?.destroy(),D.remove(),n.remove()}}}
1
+ import{buildTestPassRateData as F,hasJudgeableTests as E}from"../../stats/testPassRate.js";import{categorical as I,QUANTITY as B}from"./palette.js";import{SPACE as _,FONT as H,CLR as L}from"../toolbar.js";import{cardShell as A,makeTooltip as O,makeSegmented as j,renderEmptyState as y}from"./chartShell.js";import{renderGroupedBarPlot as k}from"./groupedBarPlot.js";import{escHtml as f}from"../../core/utils.js";const M=100,G=8,K={spec:"Test limits",testFlag:"Tester flag",functional:"Functional"},J={spec:"Judged from each die's measured value against the test's limits",testFlag:"The pass or fail the tester recorded for each die",functional:"Tests that only pass or fail and have no measured value"},U={spec:"Parametric pass rate \xB7 test limits",testFlag:"Parametric pass rate \xB7 tester flag",functional:"Functional test pass rate"};export function renderTestPassRatePanel(i){const{groups:h,testDefs:b,onSaveImage:v}=i,p=i.ownerDocument??document,$=h.flatMap(e=>e.items.flatMap(o=>o.dies??[])),m=["spec","testFlag","functional"].filter(e=>E(b,e,$));let s=m[0]??"spec";const T=e=>U[e],{card:n,heading:C,body:c,controlsRow:P}=A(T(s),v,p);n.style.alignSelf="start",m.length>1&&P.appendChild(j(m.map(e=>[e,K[e],J[e]]),s,e=>{s=e,C.textContent=T(s),S()},p));const r=p.createElement("div");r.dataset.wmapCaption="1",Object.assign(r.style,{color:L.label,fontSize:H.body,marginBottom:_.sm}),n.insertBefore(r,c);const D=O(n);let g=null;function S(){if(g?.destroy(),g=null,c.innerHTML="",m.length===0){r.textContent="",y(c,"No tests with a pass/fail verdict \u2014 parametric tests need test limits, functional tests need recorded results.");return}const e=F(h,b,s);if(e.rows.length===0){r.textContent="",y(c,s==="spec"?"No parametric test has test limits to judge against.":s==="testFlag"?"No parametric test has a recorded tester verdict.":"No functional test has recorded results.");return}const o=e.groups.length>1,R=s==="spec"?"Dies within test limits, per test":s==="testFlag"?"Dies the tester marked pass, per test":"Dies passing the recorded verdict, per test";if(r.textContent=R+(o?" \xB7 one bar per group":"")+" \xB7 worst first"+(i.onSelectTest?" \xB7 click a test to chart or tabulate the dies that fail it":""),e.disagreementDies){const t=p.createElement("span");t.textContent=` \xB7 ${e.disagreementDies.toLocaleString()} die${e.disagreementDies===1?"":"s"} judged differently by limits and tester flag`,Object.assign(t.style,{color:L.warnText}),r.appendChild(t)}const u=e.rows,x=t=>o?I(t):B;g=k(n,c,D,{rows:u.map(t=>({label:t.label,bars:t.byGroup.map(l=>({fraction:l.passRatePercent===null?null:l.passRatePercent/100})),trailing:t.overall.passRatePercent===null?"\u2014":`${t.overall.passRatePercent.toFixed(1)}%`})),groups:e.groups,labelWidth:M,maxVisibleRows:G,showLegend:o,maxLabelChars:14,emptyBarText:"no data",colorOf:x,onRowClick:i.onSelectTest?(t,l,a)=>i.onSelectTest({testNumber:u[t].testNumber,label:u[t].label,kind:s},a):void 0,tooltipHtml:(t,l)=>{const a=u[t],d=a.byGroup[l],w=o?` \xB7 ${f(String(e.groups[l]))}`:"";if(d.passRatePercent===null)return`<strong>${f(a.label)}</strong>${w}<br>no dies with a verdict`;const N=s==="spec"&&!o&&(a.failLowDies||a.failHighDies)?`<br>${a.failLowDies??0} below the low limit \xB7 ${a.failHighDies??0} above the high limit`:"";return`<strong>${f(a.label)}</strong>${w}<br>${d.passRatePercent.toFixed(1)}% pass<br>${d.passDies.toLocaleString()} pass \xB7 ${d.failDies.toLocaleString()} fail \xB7 n = ${d.totalDies.toLocaleString()}`+N}})}return S(),{card:n,destroy:()=>{g?.destroy(),D.remove(),n.remove()}}}
@@ -1,4 +1,5 @@
1
1
  import type { Die } from '../core/dies.js';
2
+ import { type FacetCuration } from '../stats/facets.js';
2
3
  import { type MetadataFieldDef, type TestDef } from '../renderer/buildWaferMap.js';
3
4
  import { type DieListDisplayOptions } from './dieList.js';
4
5
  import { type SaveTextHandler } from './toolbar.js';
@@ -19,6 +20,7 @@ export interface DataItem {
19
20
  export declare const DATA_VIEWS: ReadonlyArray<{
20
21
  key: DataView;
21
22
  label: string;
23
+ hint: string;
22
24
  }>;
23
25
  /** Rows Excel can open. A file with more is still valid; the reader is told. */
24
26
  export declare const EXCEL_ROW_LIMIT = 1048576;
@@ -55,6 +57,8 @@ export interface DataSectionDeps {
55
57
  dieListOptions?: DieListDisplayOptions;
56
58
  /** Label/order hints for die metadata columns, e.g. `WaferMapResult.metadataFields`. */
57
59
  metadataFields?: MetadataFieldDef[];
60
+ /** The host's own wafer attributes (`attributes` on the render options): the Wafers table names its columns by them. */
61
+ attributes?: Record<string, FacetCuration>;
58
62
  /** A die row was clicked: show that die on its map. When set, Dies rows are clickable and say so. */
59
63
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
60
64
  /** A wafer row was clicked: open that wafer. When set, Wafers rows are clickable and say so. */
@@ -97,6 +101,8 @@ export interface DataTablesInput {
97
101
  /** The wafers' ring count (`WaferMapResult.ringCount`): ring and quadrant columns use it. Required, never defaulted. */
98
102
  ringCount: number;
99
103
  metadataFields?: MetadataFieldDef[];
104
+ /** The host's own wafer attributes, for the Wafers table's column names. */
105
+ attributes?: Record<string, FacetCuration>;
100
106
  /** A die row clicked: show that die on its map. The caller closes the table around it. */
101
107
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
102
108
  dieListOptions?: DieListDisplayOptions;