@wafertools/wafermap 0.40.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/packages/canvas-adapter/charts/commonality.js +3 -3
- package/dist/packages/canvas-adapter/charts/plotChart.d.ts +5 -2
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.d.ts +12 -6
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.d.ts +1 -1
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/filterButton.d.ts +2 -0
- package/dist/packages/canvas-adapter/filterButton.js +1 -1
- package/dist/packages/canvas-adapter/identityHeader.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +9 -4
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/openWaferMode.d.ts +7 -0
- package/dist/packages/canvas-adapter/openWaferMode.js +1 -0
- package/dist/packages/canvas-adapter/plotTab.d.ts +1 -1
- package/dist/packages/canvas-adapter/plotTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +2 -2
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +20 -13
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -1
- package/dist/packages/canvas-adapter/virtualTable.js +1 -1
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +2 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/stats/commonality.d.ts +1 -1
- package/dist/packages/stats/commonality.js +1 -1
- package/dist/packages/stats/examplePicks.js +1 -1
- package/dist/packages/stats/groupEffects.d.ts +8 -0
- package/dist/packages/stats/groupEffects.js +1 -1
- package/dist/packages/stats/plotData.d.ts +7 -2
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/synthesis.d.ts +8 -1
- package/dist/packages/stats/synthesis.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -24,6 +24,20 @@ under `### Breaking`.
|
|
|
24
24
|
|
|
25
25
|
## [Unreleased]
|
|
26
26
|
|
|
27
|
+
## [0.40.1] — 2026-11-06
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **A wafer opened from an Insights chart starts in the mode that describes it.** A bar on a chart about a test opens that wafer on the test, a yield bar opens its bins, and a gallery showing a lot-stacked mode opens the wafer in the same kind of measure on its own, never in a stack of one wafer. The menus opened from heatmap cells and Worth a look charts name their dies once ("884 dies in FF, across 4 wafers"), a histogram bar names its test and range ("162 dies with Ioff from 11.2 pA to 23.5 pA"), a cell of Tests by wafer opens the menu on its test, and a sweep level is named by its value ("measured at VDD 0.65 V"). On a Worth a look card about groups of wafers that leads with a test, the map button names that test ("Show fmax_MHz on map").
|
|
32
|
+
- **What stands out, What divides yield and the example plots compare the same fields.** A field is compared when at least two of its groups have two wafers or more and it has no more groups than half the wafers (two, below six wafers). What divides yield no longer ranks a field with more groups than that, which can move the q of the other rows, and lists it under "Not compared" with the rule; the example plots now accept a field with a group of one wafer beside two larger ones. Each set of groups is therefore read after allowing for the same other field everywhere.
|
|
33
|
+
- **Worth a look draws each item once.** An item about the yield of groups of wafers (a probe card, a recipe) is a row of What divides yield, just below, so it has no card of its own; an item about a ring's pass rate in each group keeps its card. The Summary panel's Chart link for such an item opens Insights at What divides yield. The smaller items are listed under What stands out beside the map only, not on a line under Worth a look. A Chart link appears only on an item that has a card, and it opens that item's card: a test's own item and an item about groups of wafers that leads with the same test each have their own.
|
|
34
|
+
- **Worth a look follows the filter.** While the filter narrows the lot, Worth a look draws the items What stands out lists for what it keeps, so each of the Summary panel's Chart links opens its card. Only Show, narrowing to one group, leaves it out, and says so.
|
|
35
|
+
- **A wafer opens on what was clicked, from every chart and table.** A plot of yield or bins that names no test opens the wafer on its bins wherever it is drawn (a Worth a look card, My plots), as the Overview's yield bar does, and so does a row of the Summary panel's Wafer Yield list, in a window of its own over the maps (in a stacked mode too).
|
|
36
|
+
- **A row of the Wafers table opens its wafer on the column you clicked.** A test's mean column opens it on that test, its yield on its bins, and any other column as a wafer opened from Insights opens.
|
|
37
|
+
- **A row of the Dies table opens its die's wafer on the test you clicked.** In Insights, a click opens the wafer in a window of its own with the die ringed, on the test whose column was clicked; a click in another column opens it as any wafer opened from Insights does. In the Maps view's tables, the die is ringed on its card, which shows that test. A single map shows the test and rings the die.
|
|
38
|
+
- **A lot stack names only what its wafers share.** The header and the Summary panel of a stacked mode list the fields every stacked wafer has with one value, and the header strip lists the stacked wafers' fields, never the first wafer's split or temperature as the stack's. The stacking method is named in words ("25 wafers stacked · occurrence count", "std dev").
|
|
39
|
+
- **A filter that keeps nothing says so on the Maps view too**, in the words Insights uses, and the Summary panel says once that there are no findings.
|
|
40
|
+
|
|
27
41
|
## [0.40.0] — 2026-11-06
|
|
28
42
|
|
|
29
43
|
### Added
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{rankCommonality as se,measureLabel as V,groupCommonalityRows as ae,commonalityConfidence as X,CONFIDENCE_LABEL as ie}from"../../stats/commonality.js";import{formatP as I}from"../../stats/groupCompare.js";import{CLR as m,FONT as N,RADIUS as
|
|
2
|
-
`)),b},u=t.find(i=>i.key===e.worst.key),w=t.find(i=>i.key===e.best.key);u&&o.appendChild(r(u,"worst")),w&&o.appendChild(r(w,"best"));const
|
|
1
|
+
import{rankCommonality as se,measureLabel as V,groupCommonalityRows as ae,commonalityConfidence as X,CONFIDENCE_LABEL as ie}from"../../stats/commonality.js";import{formatP as I}from"../../stats/groupCompare.js";import{maxGroups as re}from"../../stats/groupEffects.js";import{CLR as m,FONT as N,RADIUS as le,SPACE as c,controlStyle as Y,wireControlHover as z,wireTooltip as g}from"../toolbar.js";import{shortfallShade as de}from"../cellShade.js";import{cardShell as ce,firstRowsToggle as pe,guideCite as me,renderEmptyState as fe}from"./chartShell.js";import{GUIDE_SECTIONS as he}from"../../stats/guideSections.js";import{cardAbout as ue}from"./cardAbout.js";const J=8,we=5,be=110;export function renderCommonalityPanel(f){const s=f.ownerDocument??document,{card:$,body:E,setAbout:K}=ce("What divides yield",void 0,s);K(ue("commonality")),$.dataset.wmapCommonality="1",$.style.gridColumn="1 / -1",$.style.flex="0 0 auto";const p=se(f.wafers,f.fields,f.curation);if(f.fields.length===0||p.rows.length===0)return fe(E,f.fields.length===0?"No wafer field divides these wafers, so there is nothing to compare.":"No wafer field has two groups of two or more wafers, so there is nothing to compare."),{card:$,destroy:()=>{}};const B=ae(p.rows,p.tied),v=e=>`${e.slice(0,-1).map(t=>t.label).join(", ")}${e.length>1?" and ":""}${e[e.length-1].label}`,T=s.createElement("div"),R=[`Each wafer field, compared for yield and for the ${p.bins.length} most common fail bin${p.bins.length===1?"":"s"}, with each wafer as one value. The clearest fields come first. A clear difference is more than wafer-to-wafer noise; it does not say why.`];p.overlapping.length&&R.push(`These fields nearly match, so the wafers cannot fully tell them apart: ${p.overlapping.map(e=>`${v(e.fields)} and ${v(e.with)} put ${e.agree} of ${e.of} wafers in the same groups`).join("; ")}.`),p.untestable.length&&R.push(`Not compared: ${p.untestable.map(e=>e.label).join(", ")}. A field is compared when two of its groups have two wafers or more and it has no more than ${re(f.wafers.length)} groups.`),T.textContent=R.join(" "),Object.assign(T.style,{color:m.label,fontSize:N.body,marginBottom:c.xs}),E.appendChild(T);const W=s.createElement("details"),j=s.createElement("summary");j.textContent="How to read this",Object.assign(j.style,{cursor:"pointer"}),z(j,"bare");const G=s.createElement("div");G.textContent=`Clear means q is under 0.05 and possible under 0.2, where q is Welch\u2019s p adjusted for the ${p.rows.length} comparisons in the table (Benjamini\u2013Hochberg). Hover a word for the p-values. Each field is read after allowing for the strongest other field that explains the same measure and does not contain it, and its row says so. The bars show the worst (in bold) and the best group\u2019s mean, filled from zero on a scale of 0 to 100%; hover a bar for its group\u2019s median, spread and wafers. `,G.append(me(s,he.dividesYield),"."),W.append(j,G),Object.assign(W.style,{color:m.label,fontSize:N.body,marginBottom:c.sm}),E.appendChild(W);const O=s.createElement("table");Object.assign(O.style,{borderCollapse:"collapse",width:"100%",fontSize:N.body,fontVariantNumeric:"tabular-nums"});const D=s.createElement("tr"),S=(e,t)=>{const n=s.createElement("th");n.scope="col",n.textContent=e,t&&g(n,t),Object.assign(n.style,{textAlign:"left",padding:`${c.xs} ${c.sm}`,borderBottom:`1px solid ${m.menuBorder}`,color:m.label,fontWeight:"600",whiteSpace:"nowrap"}),D.appendChild(n)};S("Field"),S("Effect","The worst and the best group\u2019s mean over their wafers, and how far apart they are"),S("Confidence","Whether the groups differ by more than wafer-to-wafer noise: clear (q under 0.05), possible (under 0.2), or not clear"),S("");const H=s.createElement("thead");H.appendChild(D),O.appendChild(H);const L=s.createElement("tbody");O.appendChild(L);const y=(e,t,n={})=>{const o=s.createElement("td");return typeof t=="string"?o.textContent=t:o.appendChild(t),n.title&&g(o,n.title),n.shade&&(o.style.background=n.shade),Object.assign(o.style,{padding:`${c.xs} ${c.sm}`,textAlign:"left",borderBottom:`1px solid ${m.menuBorder}`,verticalAlign:"top",fontWeight:n.strong?"700":"400"}),e.appendChild(o),o},A=e=>`${e.toFixed(1)}%`,M=e=>`${e.toFixed(1)} pts`,_=(e,t)=>t.comparison.groups.find(n=>n.key===e)?.n??0,Q=e=>e.comparison.groups.filter(t=>!e.comparison.tooSmall.includes(t.key)&&Number.isFinite(t.mean)),Z=e=>{if(e.measure.kind!=="yield")return;const t=e.comparison.groups.filter(o=>Number.isFinite(o.mean)&&o.n>0),n=t.reduce((o,r)=>o+r.n,0);return n>0?de(e.worst.mean-t.reduce((o,r)=>o+r.mean*r.n,0)/n):void 0},ee=e=>{const t=e.measure.kind==="yield"?`${e.worst.key} is ${M(e.spread)} below ${e.best.key}`:`${V(e.measure)} is ${M(e.spread)} higher in ${e.worst.key} than in ${e.best.key}`,[n,o]=[_(e.worst.key,e),_(e.best.key,e)];return Math.min(n,o)<we?`${t} (${n} vs ${o} wafers)`:t},te=e=>{const t=Q(e),n=100,o=s.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",gap:"2px",flex:"0 0 auto"});const r=(i,l)=>{const b=s.createElement("div");b.dataset.wmapBar=l,Object.assign(b.style,{display:"flex",alignItems:"center",gap:c.sm});const a=s.createElement("span");a.textContent=i.key,Object.assign(a.style,{width:"72px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:m.label,fontWeight:l==="worst"?"700":"400"});const d=s.createElement("div");Object.assign(d.style,{width:`${be}px`,height:"10px",border:`1px solid ${m.label}`,boxSizing:"border-box",flex:"0 0 auto"});const C=s.createElement("div");Object.assign(C.style,{width:`${Math.max(0,Math.min(100,i.mean/n*100)).toFixed(1)}%`,height:"100%",background:m.label}),d.appendChild(C);const k=s.createElement("span");return k.textContent=A(i.mean),Object.assign(k.style,{width:"52px",textAlign:"right"}),b.append(a,d,k),g(b,[`${i.key}${l==="worst"?" (worst group)":" (best group)"}`,`mean ${A(i.mean)} \xB7 median ${A(i.median)}`,Number.isFinite(i.sd)?`standard deviation ${i.sd.toFixed(1)} pts between wafers`:"",`${i.n} wafer${i.n===1?"":"s"}`].filter(Boolean).join(`
|
|
2
|
+
`)),b},u=t.find(i=>i.key===e.worst.key),w=t.find(i=>i.key===e.best.key);u&&o.appendChild(r(u,"worst")),w&&o.appendChild(r(w,"best"));const h=t.filter(i=>i!==u&&i!==w);if(h.length){const i=s.createElement("div");i.textContent=`+ ${h.length} other group${h.length===1?"":"s"}`,Object.assign(i.style,{color:m.label}),g(i,h.map(l=>`${l.key}: ${A(l.mean)} (${l.n} wafer${l.n===1?"":"s"})`).join(`
|
|
3
3
|
`)),o.appendChild(i)}return o},ne=e=>{const t=e.adjusted??e.comparison,n=t.kruskal;return[`q ${I(e.pAdjusted)} \xB7 Welch p ${I(t.welch?.p??NaN)} \xB7 rank p ${I(n?.p??NaN)}${n?.approximate?"* (approximate: fewer than five wafers in a group)":""}`,t.issue].filter(Boolean).join(`
|
|
4
|
-
`)},x=new Set;let q=!1;const P=(e,t,n)=>{const o=s.createElement("tr");o.dataset.wmapCommonalityRow=n?"field":"measure";const r=s.createElement("div");if(n){const a=s.createElement("div");a.textContent=v(t.fields),a.style.fontWeight="600",t.fields.length>1&&g(a,"These fields group the wafers identically, so the wafers cannot tell them apart: one row stands for all of them."),r.appendChild(a)}const u=s.createElement("div");if(u.textContent=V(e.measure)+(e.allowedFor?`, allowing for ${e.allowedFor.map(a=>a.label).join(", ")}`:""),Object.assign(u.style,{color:m.label,paddingLeft:n?"0":c.md}),e.allowedFor&&g(u,`Read after allowing for ${e.allowedFor.map(a=>a.label).join(", ")}: each wafer's value less its ${e.allowedFor.length===1?"group\u2019s":"groups\u2019"} mean on ${e.allowedFor.length===1?"that field":"those fields"}, so a difference the other field explains does not hide this one. The bars and the points are the measure's own means.`),r.appendChild(u),n&&t.others.length){const a=t.others.filter(k=>X(k.pAdjusted)!=="none").length,d=s.createElement("button");d.type="button",d.dataset.wmapCommonalityMore=t.field.key;const C=x.has(t.field.key);d.setAttribute("aria-expanded",String(C)),d.textContent=C?"Hide other measures":a?`+${a} other measure${a===1?"":"s"} ${a===1?"differs":"differ"}`:`${t.others.length} other measure${t.others.length===1?"":"s"}`,Object.assign(d.style,{...Y("outlined"),marginTop:c.xs,fontSize:N.body}),z(d),d.addEventListener("click",()=>{x.has(t.field.key)?x.delete(t.field.key):x.add(t.field.key),U(q)}),r.appendChild(d)}y(o,r);const w=s.createElement("div");Object.assign(w.style,{display:"flex",alignItems:"flex-start",gap:c.md});const
|
|
4
|
+
`)},x=new Set;let q=!1;const P=(e,t,n)=>{const o=s.createElement("tr");o.dataset.wmapCommonalityRow=n?"field":"measure";const r=s.createElement("div");if(n){const a=s.createElement("div");a.textContent=v(t.fields),a.style.fontWeight="600",t.fields.length>1&&g(a,"These fields group the wafers identically, so the wafers cannot tell them apart: one row stands for all of them."),r.appendChild(a)}const u=s.createElement("div");if(u.textContent=V(e.measure)+(e.allowedFor?`, allowing for ${e.allowedFor.map(a=>a.label).join(", ")}`:""),Object.assign(u.style,{color:m.label,paddingLeft:n?"0":c.md}),e.allowedFor&&g(u,`Read after allowing for ${e.allowedFor.map(a=>a.label).join(", ")}: each wafer's value less its ${e.allowedFor.length===1?"group\u2019s":"groups\u2019"} mean on ${e.allowedFor.length===1?"that field":"those fields"}, so a difference the other field explains does not hide this one. The bars and the points are the measure's own means.`),r.appendChild(u),n&&t.others.length){const a=t.others.filter(k=>X(k.pAdjusted)!=="none").length,d=s.createElement("button");d.type="button",d.dataset.wmapCommonalityMore=t.field.key;const C=x.has(t.field.key);d.setAttribute("aria-expanded",String(C)),d.textContent=C?"Hide other measures":a?`+${a} other measure${a===1?"":"s"} ${a===1?"differs":"differ"}`:`${t.others.length} other measure${t.others.length===1?"":"s"}`,Object.assign(d.style,{...Y("outlined"),marginTop:c.xs,fontSize:N.body}),z(d),d.addEventListener("click",()=>{x.has(t.field.key)?x.delete(t.field.key):x.add(t.field.key),U(q)}),r.appendChild(d)}y(o,r);const w=s.createElement("div");Object.assign(w.style,{display:"flex",alignItems:"flex-start",gap:c.md});const h=s.createElement("span");h.textContent=ee(e);const i=Z(e);i&&Object.assign(h.style,{background:i,padding:`0 ${c.xs}`,borderRadius:le.control}),h.dataset.wmapSentence="1",w.append(te(e),h),y(o,w);const l=X(e.pAdjusted),b=y(o,ie[l],{strong:l==="clear",title:ne(e)});if(b.dataset.wmapConfidence=l,n)if(t.fields.some(a=>a.key===f.groupedBy))y(o,"Grouped by this");else{const a=s.createElement("button");a.type="button",a.textContent="Group by",a.dataset.wmapCommonalityGroup=t.field.key,g(a,`Group Insights by ${t.field.label}, so every chart compares its groups${t.fields.length>1?`; ${v(t.fields.slice(1))} give the same groups`:""}`),Object.assign(a.style,Y("outlined")),z(a),a.addEventListener("click",()=>f.onGroupBy(t.field.key)),y(o,a)}else y(o,"");L.appendChild(o)};function U(e){q=e,L.replaceChildren();for(const t of e?B:B.slice(0,J))if(P(t.primary,t,!0),x.has(t.field.key))for(const n of t.others)P(n,t,!1)}const F=s.createElement("div");Object.assign(F.style,{overflowX:"auto"}),F.appendChild(O);const oe=pe(s,{total:B.length,first:J,noun:"rows",scroller:F,fill:U});return E.append(F,oe),{card:$,destroy:()=>{}}}
|
|
@@ -27,8 +27,11 @@ export interface PlotChartOptions {
|
|
|
27
27
|
binColors?: BinColors;
|
|
28
28
|
/** Right-click a mark that is one wafer (a wafer's bar or box, a point per wafer): that wafer's menu, as on the maps. */
|
|
29
29
|
onWaferMenu?: WaferContextMenuHandler;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Click a point: open its wafer, on `testNumber` (the plot's own measurement) when it has one, or on its bins (`view`)
|
|
32
|
+
* for a plot of yield or bins (stats/plotData.ts says which). Omit where there is no wafer to open.
|
|
33
|
+
*/
|
|
34
|
+
onOpenWafer?: (item: number, testNumber?: number, view?: 'bins') => void;
|
|
32
35
|
/** What a click on a bar or box that is not one wafer (or on a line's point) does, in the reader's words. Default `chart
|
|
33
36
|
* or tabulate what it counts`. Read at each draw. */
|
|
34
37
|
selectActionLabel?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{escHtml as X,maxOf as Te,minOf as jt}from"../../core/utils.js";import{fiveNumberSummary as Ut,normalQuantile as Yt,sampleVariance as Rn}from"../../stats/math.js";import{CONTROL_RULE_TEXT as On}from"../../stats/control.js";import{PAT_VERDICT_LABEL as qt}from"../../stats/pat.js";import{fmt as J}from"../../renderer/fmt.js";import{fitTicks as pt}from"../../renderer/axisTicks.js";import{binOfLabel as In,plotFootnote as Ht,plotGuideSections as Kt,plotTestNumber as Ve,plotTitle as Nn,probabilityPosition as ct}from"../../stats/plotData.js";import{SPACE as me,RADIUS as Fn,fontPx as Q,FONT as gt,CLR as nt,markNoPrint as Vt}from"../toolbar.js";import{exportCsv as zn}from"../tableExport.js";import{tableToTsv as _n}from"../../core/tableCsv.js";import{plotTable as Dn}from"../../stats/plotTable.js";import{cardShell as Gn,appendGuideCites as Xn,observeResize as jn,makeTooltip as Un,attachChartTip as Yn,chartFillHeight as qn,applyCanvasFlow as Ge,prepareCanvas as Xe,positionChartTooltip as yt,resolveChartCanvasColors as je,makeAxisFormat as Hn,horizontalTickSpacing as Zt,VERTICAL_TICK_SPACING_PX as Kn,makeSeriesLegendItem as Vn,renderEmptyState as Jt,isExpandedCard as Qt,makeLabeledSelect as Zn,fillTextOnHalo as Ct,limitLines as Jn,limitExtent as Qn,stackLabelRows as en,placeClearOf as tn,strokeLimitLine as nn,drawOffAxisLimits as eo,limitLabelPlacement as to,shouldIncludeLimitsByDefault as no,WAFER_MENU_HINT as Et}from"./chartShell.js";import{guideCitesText as oo}from"../../stats/guideSections.js";import{categorical as lo}from"./palette.js";import{NO_DATA_FILL as on}from"../../renderer/colorMap.js";import{darkTextOnColor as so,plotGradient as bt}from"./divergingScale.js";import{wirePointInteractions as Bt}from"./pointInteractions.js";import{plotAbout as io}from"./cardAbout.js";const Wt=64,xt=16,Rt=12,Ue=52,ao=16,ro=92,co=16,vt=5e3,ln=1500,ft=100,fo=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],sn=m=>`${+(m*100).toPrecision(4)}%`;export function categoryLayout(m){const W=.8/Math.max(1,...m.map(R=>R.length)),U=R=>(1-m[R].length*W)/2;return{width:W,left:(R,Y)=>{const V=m[R].indexOf(Y);return V<0?void 0:U(R)+V*W},groupAt:(R,Y)=>{const V=Math.floor((Y-U(R))/W);return V>=0&&V<m[R].length?m[R][V]:void 0}}}function uo(m){if(m<=ln)return Array.from({length:m},(R,Y)=>Y);const z=[];for(let R=0;R<ft;R++)z.push(R);const W=ln-2*ft,U=m-2*ft;for(let R=0;R<W;R++)z.push(ft+Math.floor(R*U/W));for(let R=m-ft;R<m;R++)z.push(R);return z}function Ot(m,z,W){return W?Math.round(m).toLocaleString("en-GB"):z?J(m,z):`${m<=-.005?"\u2212":""}${Math.abs(m).toFixed(2)}`}const ho=260;function mo(m){const z=[...m.querySelectorAll("[data-wmap-plot-panel]")],W=z[0]?.querySelector("canvas");if(!W)return null;const U=W.width/Math.max(1,W.getBoundingClientRect().width)||1,R=m.getBoundingClientRect(),Y=m.ownerDocument.createElement("canvas");Y.width=Math.ceil(R.width*U),Y.height=Math.ceil(R.height*U);const V=Y.getContext("2d");if(!V)return null;const we=getComputedStyle(m);V.fillStyle=we.backgroundColor&&we.backgroundColor!=="rgba(0, 0, 0, 0)"?we.backgroundColor:"#fff",V.fillRect(0,0,Y.width,Y.height);for(const Me of z){const Se=Me.querySelector("canvas"),ce=Me.dataset.wmapChartTitle??"",_=(Se??Me).getBoundingClientRect(),s=Me.getBoundingClientRect();V.fillStyle=getComputedStyle(Me).color||"#333",V.font=`600 ${Math.round(13*U)}px system-ui, sans-serif`,V.textBaseline="top",V.fillText(ce,(s.left-R.left+8)*U,(s.top-R.top+6)*U),Se&&V.drawImage(Se,(_.left-R.left)*U,(_.top-R.top)*U,_.width*U,_.height*U)}return Y}const Re=(m,z)=>z.extent?[...m,...z.extent]:m;function ue(m,z,W={}){const U=z.scale==="log";let R=m.length?jt(m):0,Y=m.length?Te(m):1;U&&(R=Math.log10(Math.max(R,Number.MIN_VALUE)),Y=Math.log10(Math.max(Y,Number.MIN_VALUE)));const V=(Y-R)*.05||(U?.5:1);R=W.floorAtZero&&!U&&R>=0?0:R-V,Y+=V;const Me=Pe=>Pe===void 0||!Number.isFinite(Pe)?void 0:U?Pe>0?Math.log10(Pe):void 0:Pe,Se=Me(z.min),ce=Me(z.max);Se!==void 0&&(R=Se),ce!==void 0&&(Y=ce),Y>R||(Y=R+1);const _=Y-R,s=!!z.reverse,Oe=Pe=>{const $=((U?Math.log10(Math.max(Pe,Number.MIN_VALUE)):Pe)-R)/_;return s?1-$:$};return{lo:U?10**R:R,hi:U?10**Y:Y,log:U,reverse:s,frac:Oe}}function It(m,z,W,U){if(z/m<10)return pt(m,z,W,U);const R=Math.floor(Math.log10(m)),Y=Math.ceil(Math.log10(z)),V=Se=>{const ce=[];for(let _=R;_<=Y;_++)for(const s of Se){const Oe=s*10**_;Oe>=m&&Oe<=z&&ce.push(Oe)}return ce},we=V([1]);return{ticks:we.length>=4?we:V([1,2,5]),step:0}}export function renderPlotChart(m){const z=m.ownerDocument??document,{card:W,heading:U,body:R,controlsRow:Y,setPngDecor:V,setPngCanvas:we,setAbout:Me,setMenuRows:Se}=Gn(m.panel?.title??"Plot",m.onSaveImage,z,{png:!m.panel});m.panel&&(W.dataset.wmapPlotPanel="1");let ce=[];W.dataset.wmapPlotCard="1";const _=Un(W);let s,Oe=()=>[];const Pe=()=>{const e=s&&(s.marks||s.facets?.length)?Dn(s,m.waferLabel):void 0;return e?[{label:"Save data as CSV",onClick:()=>{zn(e.columns,e.rows,`${e.name}.csv`,m.onSaveText)}},{label:"Copy data",onClick:()=>{z.defaultView?.navigator.clipboard?.writeText(_n(e.columns,e.rows))}}]:[]};Se(()=>[...Pe(),...Oe()]);let $,pe,te,Ze,Ie,ut,ht=!1;W.addEventListener("pointerenter",()=>{ht=!0,W.dataset.wmapPlotPanelsOwner&&(W.dataset.wmapPanelsHover="1")}),W.addEventListener("pointerleave",()=>{ht=!1,delete W.dataset.wmapPanelsHover});let ot=[];const O=new Set,he=new Set;let ge=null,ye=-1,le=[],Z,Ee,ne,se=null,lt=0,$e,dt;const an=()=>!!s?.facets;let de=[],be=-1,kt=new Map,Ye=[],qe=Ue,w=Wt,M=Rt;const rn={[qt.outlier]:"#e69f00",[qt.fails]:"#c0392b"},ee=e=>{const l=s?.groups[e]??"";if(s?.colorBins&&m.binColors){const a=In(l);return a===void 0?on:(s.colorBins==="hard"?m.binColors.hard:m.binColors.soft).get(a)??on}return rn[l]??lo(e)},He=e=>s?.groups[e]||"";function Ne(){const e=R.clientWidth,l=(m.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(qe-Ue),a=qn(W,R,$,l);return{w:e,h:a,plotW:Math.max(10,e-w-xt),plotH:Math.max(10,a-M-qe)}}const Be=e=>{const l=(e?.references??[]).flatMap(a=>a.to===void 0?[{value:a.at,kind:"ref",end:"lo",label:a.label??""}]:[{value:a.at,kind:"ref",end:"lo",label:a.label??"",bandTo:a.to},{value:a.to,kind:"ref",end:"hi",label:a.label??""}]);return[...Jn(e?.limits,s?.spec.limits??"both"),...l].filter(a=>e?.scale!=="log"||a.value>0)},Fe=(e,l,a)=>{const h=a?.clip,r=h?[...e.filter(c=>c>=h.lo&&c<=h.hi),h.lo,h.hi]:e,d=r.filter(Number.isFinite);if(!l.length||d.length===0)return r;const{lo:n,hi:t}=Qn(l);return(a?s?.spec.axes?.[a===s?.x?"x":"y"]?.includeLimits:void 0)??no(jt(d),Te(d),n,t)?[...r,...l.map(c=>c.value)]:r};let Mt;function Je(e,l,a,h=!1){return!h&&!s?.x?.clip&&!s?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(w,M,l,a),e.clip(),Mt=e,Nt)}function Nt(){Mt?.restore(),Mt=void 0}function ze(e,l,a,h,r,d,n,t,o){const c=[];if(d.length===0)return()=>{};const y=d.filter(p=>p.value>=r.lo&&p.value<=r.hi),x=d.filter(p=>!y.includes(p)).map(p=>({value:p.value,label:p.label,side:p.value<r.lo?"lo":"hi"}));e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`;const g=p=>`${p.label} ${J(p.value,n.unit)}`.trim(),f=Q(-1)+2;for(const p of d){if(p.bandTo===void 0)continue;const L=r.frac(Math.min(p.value,p.bandTo)),P=r.frac(Math.max(p.value,p.bandTo)),b=Math.max(0,Math.min(L,P)),C=Math.min(1,Math.max(L,P));C<=b||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(w,M+(1-C)*h,a,(C-b)*h):e.fillRect(w+b*a,M,(C-b)*a,h),e.restore())}if(t==="y"){const p=y.map(b=>{const C=M+(1-r.frac(b.value))*h;return{l:b,y:C,start:C-6-f/2,end:C-6+f/2}}),L=en(p,1),P=p.length?Te(p.map(b=>e.measureText(g(b.l)).width))+8:0;p.forEach(({l:b,y:C},u)=>{e.globalAlpha=.7,nn(e,b,l,w,C,w+a,C),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const i=w+3+L[u]*P,v=tn(Ye,{x0:i,x1:i+e.measureText(g(b)).width,y0:C-4-f+2,y1:C-4+2},f);if(!o){e.fillText(g(b),i,v.y1-2);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",Ct(e,g(b),i,v.y1-2,o.halo),e.restore()})})}else{const p=y.map(P=>{const b=w+r.frac(P.value)*a,C=g(P),u=P.label.split(/\s+/)[0],i=J(P.value,n.unit),v=u&&u!==P.label?[C,`${u} ${i}`,u]:[C],B=y.filter(E=>E!==P).map(E=>w+r.frac(E.value)*a),{text:F,side:T}=to(b,v,E=>e.measureText(E).width,w,w+a,P.end==="lo",B),A=e.measureText(F).width;return{l:P,x:b,side:T,shown:F,start:T<0?b-3-A:b+3,end:T<0?b-3:b+3+A}}),L=en(p,4);p.forEach(({l:P,x:b,side:C,shown:u,start:i,end:v},B)=>{e.globalAlpha=.7,nn(e,P,l,b,M,b,M+h),e.globalAlpha=1;const F=C<0?"right":"left";e.fillStyle=l,e.textAlign=F,e.textBaseline="top";const T=M+2+L[B]*f,A=tn(Ye,{x0:i,x1:v,y0:T,y1:T+f},f);if(!o){e.fillText(u,b+C*3,A.y0);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=F,e.textBaseline="top",Ct(e,u,b+C*3,A.y0,o.halo),e.restore()})})}return e.restore(),eo(e,x,{left:w,right:w+a,top:M,bottom:M+h},t==="y"?"vertical":"horizontal",l,p=>J(p,n.unit),void 0,Ye),()=>c.forEach(p=>p())}function Tt(e,l,a,h){return Hn(Math.max(Math.abs(l),Math.abs(a)),e.unit,h,e.label)}function mt(e,l){return l?`${e.label} (${l})`:e.label}const wt=18,St=(e,l,a)=>{if(e.measureText(l).width<=a)return l;for(let h=l.length-1;h>0;h--){const r=`${l.slice(0,h)}\u2026`;if(e.measureText(r).width<=a)return r}return""};function Ke(e,l,a,h,r,d,n,t,o,c,y){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const x=()=>Kn,g=y?{ticks:y.map(b=>b.at),step:0}:t.log?It(t.lo,t.hi,d,x):pt(t.lo,t.hi,d,x),f=new Map(y?.map(b=>[b.at,b.label])),p=Tt(c,t.lo,t.hi,g.step||void 0),L=y?{tick:b=>f.get(b)??"",unitLabel:""}:p;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let P="";if("labels"in n){const b=n.labels.length;if(n.labels.forEach((C,u)=>{const i=w+(u+.5)/b*r,v=C.length>22?`${C.slice(0,21)}\u2026`:C;n.rotate?(e.save(),e.translate(i,M+d+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,i,M+d+4))}),n.nest){const C=n.nest[0]?.length??0,u=r/b;for(let i=C-2;i>=0;i--){const v=h-6-wt-i*wt,B=T=>n.nest[T].slice(0,i+1).join("");let F=0;for(let T=1;T<=b;T++){if(T<b&&B(T)===B(F))continue;const E=w+F*u,j=w+T*u;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(St(e,n.nest[F][i],j-E-4),(E+j)/2,v),T<b&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=i===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(j,M),e.lineTo(j,v-2),e.stroke(),e.restore()),F=T}}e.fillStyle=l.textMuted}}else{const b=Zt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),C=n.log?It(n.lo,n.hi,r,b):pt(n.lo,n.hi,r,b),u=Tt(o,n.lo,n.hi,C.step||void 0);P=u.unitLabel;for(const i of C.ticks){const v=w+n.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(u.tick(i),v,M+d+4)}}for(const b of g.ticks){const C=M+(1-t.frac(b))*d;e.beginPath(),e.moveTo(w,C),e.lineTo(w+r,C),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(L.tick(b),w-4,C)}e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(mt(o,P),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(c,L.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function cn(e,l,a,h,r,d,n,t,o,c,y,x={along:d,offset:0}){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const g=Zt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),y.unit),f=o.log?It(o.lo,o.hi,r,g):pt(o.lo,o.hi,r,g),p=Tt(y,o.lo,o.hi,f.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const i of f.ticks){const v=w+o.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(i),v,M+d+4)}const L=n.labels.length,P=x.along/Math.max(1,L),b=M-x.offset;e.save(),e.beginPath(),e.rect(0,M-1,w+r+1,d+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const C=Math.max(0,Math.floor(x.offset/P)),u=Math.min(L,Math.ceil((x.offset+d)/P));for(let i=C;i<u;i++)e.fillText(St(e,n.labels[i],t.inner),w-6,b+(i+.5)*P);if(n.nest){const i=n.nest[0]?.length??0;let v=w-6-t.inner-10;for(let B=i-2;B>=0;B--){const F=t.outer[B]??0,T=E=>n.nest[E].slice(0,B+1).join("");let A=0;for(let E=1;E<=L;E++){if(E<L&&T(E)===T(A))continue;const j=b+A*P,k=b+E*P;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(St(e,n.nest[A][B],F),v,(j+k)/2),E<L&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=B===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(v-F,k),e.lineTo(w+r,k),e.stroke(),e.restore()),A=E}v-=F+10}e.fillStyle=l.textMuted}e.restore(),e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(mt(y,p.unitLabel),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(c,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function fn(){if(!s||!$||s.marks?.type!=="scatter"||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,t=s.marks.points,o=O.size===0?t:t.filter(T=>O.has(T.group)),c=s.colorScale,y=bt(s.spec.colorGradient,s.spec.colorReverse,c?.diverging,c?.rating),x=Be(s.x),g=Be(s.y),f=ue(Fe(Re(t.map(T=>T.x),s.x),x,s.x),s.x),p=ue(Fe(Re(t.map(T=>T.y),s.y),g,s.y),s.y);Z={x:f,y:p,plotW:h,plotH:r},Ke(n,e,l,a,h,r,f,p,s.x,s.y),ze(n,e.limitLine,h,r,f,x,s.x,"x"),ze(n,e.limitLine,h,r,p,g,s.y,"y"),Je(n,h,r);const L=o.length>vt?Math.ceil(o.length/vt):1,P=[];for(let T=0;T<o.length;T+=L)P.push(o[T]);n.globalAlpha=Math.max(.15,Math.min(.7,200/P.length));let b;if(c)b=[P];else{const T=new Map;for(const A of P){const E=T.get(A.group);E?E.push(A):T.set(A.group,[A])}b=[...T.values()].sort((A,E)=>E.length-A.length)}le=[];const C=w,u=w+h,i=M,v=M+r;for(const T of b)for(const A of T){const E=w+f.frac(A.x)*h,j=M+(1-p.frac(A.y))*r;E<C||E>u||j<i||j>v||(le.push({p:A,cx:E,cy:j}),n.beginPath(),n.arc(E,j,2.5,0,Math.PI*2),n.fillStyle=c&&A.value!==void 0?y((A.value-c.lo)/(c.hi-c.lo||1)):ee(A.group),n.fill())}n.globalAlpha=1;const B=s.marks;if(B.type==="scatter"&&(B.identity||B.fits)){const T=(E,j)=>[w+f.frac(E)*h,M+(1-p.frac(j))*r],A=(E,j,k)=>{n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=j,n.lineWidth=2,n.setLineDash(k),n.beginPath();for(let ie=0;ie<=60;ie++){const We=ie/60,De=f.log?10**(Math.log10(f.lo)+(Math.log10(f.hi)-Math.log10(f.lo))*We):f.lo+(f.hi-f.lo)*We,[Le,fe]=T(De,E(De));ie===0?n.moveTo(Le,fe):n.lineTo(Le,fe)}n.stroke(),n.restore()};B.identity&&A(E=>E,e.textMuted,[6,4]);for(const E of B.fits??[])O.size>0&&!O.has(E.group)&&!c||A(j=>E.intercept+E.slope*j,c?e.text:ee(E.group),[])}const F=ge?le.find(T=>T.p===ge):void 0;if(F&&(n.beginPath(),n.arc(F.cx,F.cy,5,0,Math.PI*2),n.lineWidth=2,n.strokeStyle=e.text,n.stroke()),he.size>0){n.lineWidth=1.5,n.strokeStyle=e.text;let T=0;for(const A of he)if(!(O.size>0&&!O.has(A.group))){if(++T>vt)break;n.beginPath(),n.arc(w+f.frac(A.x)*h,M+(1-p.frac(A.y))*r,4,0,Math.PI*2),n.stroke()}}}function un(){if(Ee=void 0,!s||s.marks?.type!=="histogram"||!s.x)return;const e=s.marks.values,l=e.flat();if(l.length===0)return;const a=ue(Fe(Re(l,s.x),Be(s.x),s.x),s.x),h=Math.max(1,s.spec.bins??co),r=a.log?Math.log10(a.lo):a.lo,d=a.log?Math.log10(a.hi):a.hi,n=Array.from({length:h+1},(g,f)=>{const p=r+(d-r)*f/h;return a.log?10**p:p}),t=e.map(()=>new Array(h).fill(0));e.forEach((g,f)=>{for(const p of g){const L=a.log?p>0?Math.log10(p):NaN:p;if(!Number.isFinite(L)||L<r||L>d)continue;const P=Math.min(h-1,Math.floor((L-r)/(d-r)*h));t[f][P]++}});const o=s.spec.histNorm==="percent",c=o?t.map(g=>{const f=g.reduce((p,L)=>p+L,0);return g.map(p=>f?p/f*100:0)}):t;let y=0;const x=e.map(()=>{});if(s.spec.normalCurve&&!a.log){const g=(n[n.length-1]-n[0])/h;e.forEach((f,p)=>{const L=f.filter(Number.isFinite);if(L.length<2)return;const P=L.reduce((C,u)=>C+u,0)/L.length,b=Math.sqrt(Rn(L,P));b>0&&(x[p]={mean:P,sd:b},y=Math.max(y,(o?100:t[p].reduce((C,u)=>C+u,0))*g/(b*Math.sqrt(2*Math.PI))))})}Ee={edges:n,counts:t,heights:c,normal:x,maxCount:Math.max(o?.001:1,y,...c.map(g=>Te(g)))}}function hn(){if(!s||!$||!Ee||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,{edges:t,counts:o,heights:c,normal:y,maxCount:x}=Ee,g=ue([t[0],t[t.length-1]],{...s.x,min:t[0],max:t[t.length-1]}),f=ue([0,x],{label:s.y.label,scale:"linear",min:0,max:x*1.05});Z={x:g,y:f,plotW:h,plotH:r},Ke(n,e,l,a,h,r,g,f,s.x,s.y),ze(n,e.limitLine,h,r,g,Be(s.x),s.x,"x"),Je(n,h,r);const p=o.map((u,i)=>i).filter(u=>O.size===0||O.has(u)),L=p.length>1,P=p.length>=3,b=u=>w+Math.min(g.frac(t[u]),g.frac(t[u+1]))*h,C=u=>w+Math.max(g.frac(t[u]),g.frac(t[u+1]))*h;for(const u of p){if(P){n.fillStyle=ee(u),n.strokeStyle=ee(u),n.lineWidth=1.75,n.lineJoin="round",n.globalAlpha=.1,c[u].forEach((v,B)=>{if(v===0)return;const F=M+(1-f.frac(v))*r;n.fillRect(b(B),F,Math.max(1,C(B)-b(B)),M+r-F)}),n.globalAlpha=1,n.beginPath();let i=!1;c[u].forEach((v,B)=>{const F=M+(1-f.frac(v))*r;i||(n.moveTo(b(B),M+r),i=!0),n.lineTo(b(B),F),n.lineTo(C(B),F),B===c[u].length-1&&n.lineTo(C(B),M+r)}),n.stroke();continue}n.globalAlpha=L?.55:.85,n.fillStyle=ee(u),c[u].forEach((i,v)=>{if(i===0)return;const B=M+(1-f.frac(i))*r;n.fillRect(b(v),B,Math.max(1,C(v)-b(v)-1),M+r-B)})}if(n.globalAlpha=1,s.spec.normalCurve&&!g.log){const u=(t[t.length-1]-t[0])/(t.length-1);for(const i of p){const v=y[i];if(!v)continue;const{mean:B,sd:F}=v,T=(s.spec.histNorm==="percent"?100:o[i].reduce((A,E)=>A+E,0))*u;n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=ee(i),n.lineWidth=2,n.beginPath();for(let A=0;A<=120;A++){const E=t[0]+(t[t.length-1]-t[0])*A/120,j=Math.exp(-.5*((E-B)/F)**2)/(F*Math.sqrt(2*Math.PI)),k=w+g.frac(E)*h,ie=M+(1-f.frac(T*j))*r;A===0?n.moveTo(k,ie):n.lineTo(k,ie)}n.stroke(),n.restore()}}if(ye>=0){const u=w+Math.min(g.frac(t[ye]),g.frac(t[ye+1]))*h,i=w+Math.max(g.frac(t[ye]),g.frac(t[ye+1]))*h;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(u,M,Math.max(1,i-u),r)}}function dn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="box"&&e.type!=="bar")return;Ge($,te??0);const l=je(W),a=s.spec.orientation==="horizontal",h=e.nest?e.nest.parts.map(S=>S[S.length-1]):e.categories,r=e.categories.length,d=s.groups.length,n=S=>O.size===0||O.has(S),t=e.type==="bar"&&!!e.stack,o=(S,N)=>e.type==="bar"?Number.isFinite(e.values[S][N]):e.cells[S][N].length>0,c=Array.from({length:r},(S,N)=>Array.from({length:d},(I,D)=>D).filter(I=>n(I)&&o(I,N))),y=categoryLayout(t?c.map(S=>S.length?[0]:[]):c),x=$.getContext("2d"),g=S=>x?x.measureText(S).width:S.length*6;x&&(x.font=`${Q(-1)}px system-ui, sans-serif`);const f=(S,N)=>S.length>N?`${S.slice(0,N-1)}\u2026`:S;let p=!1,L={inner:0,outer:[]},P=0;if(a){L={inner:Math.min(200,Te(h.map(N=>g(f(N,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((N,I)=>Math.min(140,Te(e.nest.parts.map(D=>g(f(D[I],20)))))):[]},w=Math.max(Wt,30+L.inner+6+L.outer.reduce((N,I)=>N+I+10,0)),e.cumulative&&(M=Rt+18),qe=Ue;const S=Math.max(1,...c.map(N=>t?Math.min(1,N.length):N.length));P=Math.max(22,S*ao/.8)}else{const S=Te(h.map(D=>g(f(D,22)))),N=Math.max(10,R.clientWidth-w-xt)/Math.max(1,r);p=S+8>N;const I=e.nest?e.nest.levels.length-1:0;qe=(p?Ue+Math.min(110,S*.72):Ue)+I*wt}const b=e.type==="bar"&&!t&&!!s.spec.valueLabels,C=s.y.unit,u=S=>J(S,C),i=b?Te(e.values.flat().filter(Number.isFinite).map(S=>g(u(S))).concat(0))+8:0,v=a?i:e.cumulative?40:0,{w:B,h:F,plotW:T,plotH:A}=Ne(),E=Math.max(10,T-v),j=Xe($,W,B,F);if(!j)return;const{ctx:k}=j,ie=S=>S.filter(Number.isFinite),We=Be(s.y),De=t?e.categories.map((S,N)=>e.values.reduce((I,D,q)=>I+(n(q)&&Number.isFinite(D[N])?D[N]:0),0)):[],Le=e.type==="bar"?[...t?De:ie(e.values.flat()),0]:ie(e.cells.flat(2));k.font=`${Q(-1)}px system-ui, sans-serif`;const fe=a?i:Q(-1)+6;if(b&&!a&&Le.length){const S=Te(Le);S>0&&Le.push(S*(1+fe/Math.max(1,A-fe)))}const Ae=ue(Fe(Re(Le,s.y),We,s.y),s.y,{floorAtZero:e.type==="bar"});Z={x:Ae,y:Ae,plotW:E,plotH:A};const it=a?A:E,Qe=a&&r*P>A+.5,at=Qe?r*P:it,rt=Qe?Math.max(0,Math.min(lt,at-it)):0;lt=rt,Pn(Qe,at,rt,E+v,A),a?cn(k,l,B,F,E,A,{labels:h,rotate:!1,nest:e.nest?.parts},L,Ae,s.x,s.y,{along:at,offset:rt}):Ke(k,l,B,F,E,A,{labels:h,rotate:p,nest:e.nest?.parts},Ae,s.x,s.y);const ve=at/r,Ce=y.width*ve;ne={slotW:ve,n:r,plotW:at,layout:y,across:a,offset:rt,view:it};const oe=S=>a?w+Ae.frac(S)*E:M+(1-Ae.frac(S))*A,ke=S=>a?M+S-rt:w+S,Lt=Ae.log?a?w:M+A:oe(0),et=(S,N,I,D)=>a?[Math.min(I,D),ke(S),Math.max(1,Math.abs(D-I)),N-S]:[ke(S),Math.min(I,D),N-S,Math.max(1,Math.abs(D-I))],At=(S,N,I,D)=>{k.beginPath(),a?(k.moveTo(N,ke(S)),k.lineTo(D,ke(I))):(k.moveTo(ke(S),N),k.lineTo(ke(I),D)),k.stroke()},tt=S=>a?S>=Lt:S<=Lt,En=S=>a?Q(-1)<=Ce+4:k.measureText(u(S)).width<=Ce+6,Dt=b&&e.values.every(S=>S.every(N=>!Number.isFinite(N)||En(N)));if(Dt){for(let S=0;S<d;S++)if(n(S))for(let N=0;N<r;N++){const I=y.left(N,S),D=e.values[S][N];if(I===void 0||!Number.isFinite(D))continue;const q=ke(N*ve+I*ve+Ce/2),H=k.measureText(u(D)).width,G=oe(D);a?Ye.push(tt(G)?{x0:G,x1:G+H+6,y0:q-fe/2,y1:q+fe/2}:{x0:G-H-6,x1:G,y0:q-8,y1:q+8}):Ye.push(tt(G)?{x0:q-H/2,x1:q+H/2,y0:G-fe,y1:G}:{x0:q-H/2,x1:q+H/2,y0:G,y1:G+fe})}}const Bn=ze(k,l.limitLine,E,A,Ae,We,s.y,a?"x":"y",{halo:l.bg}),Wn=Je(k,E,A,Qe);if(t){ne.stacks=[];for(let S=0;S<r;S++){const N=y.left(S,0),I=[];if(ne.stacks.push(I),N===void 0)continue;let D=0;for(let q=0;q<d;q++){const H=e.values[q][S];if(!n(q)||!Number.isFinite(H)||H<=0)continue;const G=oe(D),ae=oe(D+H);k.fillStyle=ee(q),k.globalAlpha=.9;const re=S*ve+N*ve;k.fillRect(...et(re+1,re+Ce-1,G,ae)),k.globalAlpha=1,I.push({g:q,p0:Math.min(G,ae),p1:Math.max(G,ae)}),D+=H}}}for(let S=0;S<d&&!t;S++){if(O.size>0&&!O.has(S))continue;const N=ee(S);for(let I=0;I<r;I++){const D=y.left(I,S);if(D===void 0)continue;const q=I*ve+D*ve;if(e.type==="bar"){const H=e.values[S][I];if(!Number.isFinite(H))continue;const G=oe(H);if(k.fillStyle=N,k.globalAlpha=.9,k.fillRect(...et(q+1,q+Ce-1,Lt,G)),k.globalAlpha=1,Dt){k.fillStyle=l.text,k.font=`${Q(-1)}px system-ui, sans-serif`;const ae=ke(q+Ce/2);a?(k.textBaseline="middle",k.textAlign=tt(G)?"left":"right",k.fillText(u(H),G+(tt(G)?3:-3),ae)):(k.textAlign="center",k.textBaseline=tt(G)?"bottom":"top",k.fillText(u(H),ae,G+(tt(G)?-2:2)))}}else{const H=e.cells[S][I];if(H.length===0)continue;const G=q+Ce/2,ae=Math.max(3,Math.min(Ce*.7,46)),re=Ut(Float64Array.from(H));if(k.strokeStyle=N,k.fillStyle=N,k.lineWidth=1.5,H.length===1){k.beginPath(),a?k.arc(oe(re.median),ke(G),3,0,Math.PI*2):k.arc(ke(G),oe(re.median),3,0,Math.PI*2),k.fill();continue}At(G,oe(re.min),G,oe(re.max));for(const Xt of[re.min,re.max])At(G-ae/4,oe(Xt),G+ae/4,oe(Xt));k.globalAlpha=.35,k.fillRect(...et(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.globalAlpha=1,k.strokeRect(...et(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.lineWidth=2.5,At(G-ae/2,oe(re.median),G+ae/2,oe(re.median))}}}Wn(),Bn();const Gt=se?y.left(se.c,t?0:se.g):void 0;if(se&&Gt!==void 0){Qe&&(k.save(),k.beginPath(),k.rect(w-1,M,E+2,A),k.clip()),k.lineWidth=1.5,k.strokeStyle=l.text;const S=se.c*ve+Gt*ve,N=t?ne.stacks?.[se.c]?.find(I=>I.g===se.g):void 0;t&&N?k.strokeRect(...et(S,S+Ce,N.p0,N.p1)):t||k.strokeRect(...et(S,S+Ce,a?w:M,a?w+E:M+A)),Qe&&k.restore()}if(e.cumulative){const S=I=>a?w+I/100*E:M+(1-I/100)*A,N=(I,D)=>a?[S(D),ke((I+.5)*ve)]:[ke((I+.5)*ve),S(D)];if(k.save(),k.strokeStyle=l.text,k.fillStyle=l.text,k.lineWidth=1.5,k.beginPath(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);D===0?k.moveTo(q,H):k.lineTo(q,H)}),k.stroke(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);k.beginPath(),k.arc(q,H,2.5,0,Math.PI*2),k.fill()}),k.strokeStyle=l.border,k.lineWidth=1,k.beginPath(),a?(k.moveTo(w,M),k.lineTo(w+E,M)):(k.moveTo(w+E,M),k.lineTo(w+E,M+A)),k.stroke(),k.fillStyle=l.textMuted,k.font=`${Q(-1)}px system-ui, sans-serif`,a){k.textAlign="center",k.textBaseline="bottom";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,S(I),M-3)}else{k.textAlign="left",k.textBaseline="middle";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,w+E+4,S(I))}k.restore()}}function mn(e){const l=s?.setTests,a=l?l.labels.indexOf(e):-1;return a>=0?{test:l.tests[a]}:{}}function Pt(e){if(!ne||!$)return null;const l=$.getBoundingClientRect(),a=ne.across?e.clientY-l.top-M:e.clientX-l.left-w;if(a<0||a>ne.view)return null;const h=a+ne.offset,r=Math.min(ne.n-1,Math.floor(h/ne.slotW)),d=ne.layout.groupAt(r,(h-r*ne.slotW)/ne.slotW);if(d===void 0)return null;if(!ne.stacks)return{g:d,c:r};const n=ne.across?e.clientX-l.left:e.clientY-l.top,t=ne.stacks[r]?.find(o=>n>=o.p0&&n<=o.p1);return t?{g:t.g,c:r}:null}function pn(e,l,a){let h=0,r=0,d=0;for(const o of l)o===100&&h++;if(e.failSide)for(const o of a){const c=e.failSide[o];c<0?r++:c>0&&d++}const n=o=>o.toLocaleString("en-GB"),t=r+d>0?` (${n(r)} below the low limit \xB7 ${n(d)} above the high limit)`:"";return`${n(h)} pass \xB7 ${n(l.length-h)} fail${t} \xB7 n = ${n(l.length)}`}function gn(e){const l=s,a=l.marks,h=l.level==="die"?"dies":"wafers",r=a.cells[e.g][e.c],d=a.nest?a.nest.parts[e.c]:[a.categories[e.c]],n=l.groups.length>1&&!d.includes(He(e.g))?` \xB7 ${X(He(e.g))}`:"",t=`<strong>${X(a.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(r.length===0)return`${t}no ${h}`;const c=`${r.length.toLocaleString("en-GB")} ${h}`,y=(a.categoryItems&&m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(a.categoryItems&&m.onWaferMenu?Et:"");if(a.type==="bar"){const g=a.values[e.g][e.c],f=a.cumulative?`<br>${X(`cumulative: ${a.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${X(`${l.y.label}: ${J(g,o)}`)}<br>${X(a.passFail?pn(a.passFail,r,a.cellUnits[e.g][e.c]):c)}${f}${y}`}const x=Ut(Float64Array.from(r));return`${t}${["max","q3","median","q1","min"].map(g=>X(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[g]}: ${J(x[g],o)}`)).join("<br>")}<br>${X(c)}${y}`}function yn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="line")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Be(s.x),c=Be(s.y),y=ue(Fe(Re(e.xs,s.x),o,s.x),s.x),x=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],g=ue(Fe(Re([...e.values.flat(),...x].filter(Number.isFinite),s.y),c,s.y),s.y);if(Z={x:y,y:g,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,g,s.x,s.y),ze(t,l.limitLine,r,d,y,o,s.x,"x"),ze(t,l.limitLine,r,d,g,c,s.y,"y"),Je(t,r,d),de=e.xs.map(f=>w+y.frac(f)*r),e.band){const f=p=>M+(1-g.frac(p))*d;e.band.lo.forEach((p,L)=>{if(O.size>0&&!O.has(L))return;const P=e.band.hi[L];t.save(),t.fillStyle=ee(L),t.globalAlpha=.16;let b=[];const C=()=>{if(b.length===1){const u=b[0],i=de[u];t.globalAlpha=.55,t.strokeStyle=ee(L),t.lineWidth=2,t.beginPath(),t.moveTo(i,f(p[u])),t.lineTo(i,f(P[u])),t.moveTo(i-4,f(p[u])),t.lineTo(i+4,f(p[u])),t.moveTo(i-4,f(P[u])),t.lineTo(i+4,f(P[u])),t.stroke(),t.globalAlpha=.16}else if(b.length){t.beginPath(),b.forEach((u,i)=>{i===0?t.moveTo(de[u],f(P[u])):t.lineTo(de[u],f(P[u]))});for(let u=b.length-1;u>=0;u--)t.lineTo(de[b[u]],f(p[b[u]]));t.closePath(),t.fill()}b=[]};p.forEach((u,i)=>{Number.isFinite(u)&&Number.isFinite(P[i])?b.push(i):C()}),C(),t.restore()})}e.values.forEach((f,p)=>{if(O.size>0&&!O.has(p))return;t.strokeStyle=ee(p),t.fillStyle=ee(p),t.lineWidth=2;let L=!1;t.beginPath(),f.forEach((P,b)=>{if(!Number.isFinite(P)){L=!1;return}const C=de[b],u=M+(1-g.frac(P))*d;L?t.lineTo(C,u):t.moveTo(C,u),L=!0}),t.stroke(),f.forEach((P,b)=>{Number.isFinite(P)&&(t.beginPath(),t.arc(de[b],M+(1-g.frac(P))*d,be===b?4.5:3,0,Math.PI*2),t.fill())})}),be>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(de[be],M),t.lineTo(de[be],M+d),t.stroke())}function $t(e){const l=s?.marks;if(!l||l.type!=="line"||!$||!s?.x||de.length===0)return null;const a=e.clientX-$.getBoundingClientRect().left;let h=-1,r=24;if(de.forEach((t,o)=>{const c=Math.abs(t-a);c<r&&(r=c,h=o)}),be=h,h<0)return null;const d=s.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[h],n:l.counts[o][h]})).filter(t=>Number.isFinite(t.v)&&(O.size===0||O.has(t.g)));return`<strong>${X(`${s.x.label}: ${J(l.xs[h],s.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][h],c=l.band?.hi[t.g][h],y=o!==void 0&&c!==void 0&&Number.isFinite(o)&&Number.isFinite(c)?`, band ${J(o,s.y.unit)} to ${J(c,s.y.unit)}`:"";return X(`${s.groups.length>1?`${He(t.g)}: `:""}${J(t.v,s.y.unit)}${y} (${t.n.toLocaleString("en-GB")} ${d})`)}).join("<br>")+(m.onWaferMenu&&Ft(h)!==void 0?Et:"")}function Ft(e){const l=s?.marks;if(l?.type!=="line")return;const a=new Set(l.cellUnits.flatMap((h,r)=>O.size>0&&!O.has(r)?[]:(h[e]??[]).map(d=>l.unit(d).item)));return a.size===1?[...a][0]:void 0}function bn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="probability")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=s.spec.probabilityAxis==="linear",c=e.values.map((T,A)=>A).filter(T=>e.values[T].length>0&&(O.size===0||O.has(T))),y=Math.max(1,...c.map(T=>e.values[T].length)),x=Math.min(.01,ct(0,y)),g=T=>o?T:Yt(T),f=o?0:g(x),p=o?1:g(1-x),L=o?0:(p-f)*.03,P=ue([f-L,p+L],{label:s.y.label,scale:"linear",min:f-L,max:p+L}),b=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:fo.filter(T=>T>=x&&T<=1-x),C=[],u=T=>M+(1-P.frac(T))*d,i=b.indexOf(.5);C.push({at:g(.5),label:sn(.5)});for(const T of[b.slice(i+1),b.slice(0,i).reverse()]){let A=u(g(.5));for(const E of T){const j=u(g(E));Math.abs(j-A)<16||(C.push({at:g(E),label:sn(E)}),A=j)}}const v=Be(s.x),B=ue(Fe(Re(c.flatMap(T=>[e.values[T][0],e.values[T][e.values[T].length-1]]),s.x),v,s.x),s.x);Z={x:B,y:P,plotW:r,plotH:d},Ke(t,l,a,h,r,d,B,P,s.x,s.y,C),ze(t,l.limitLine,r,d,B,v,s.x,"x"),Je(t,r,d),le=[],t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();for(const T of c){const A=e.values[T],E=A.length,j=uo(E);if(t.strokeStyle=ee(T),t.fillStyle=ee(T),t.lineWidth=1.5,t.beginPath(),j.forEach((k,ie)=>{const We=w+B.frac(A[k])*r,De=u(g(ct(k,E)));ie===0?t.moveTo(We,De):t.lineTo(We,De);const Le=T*2**26+k;let fe=kt.get(Le);if(!fe){const{item:Ae,die:it}=e.unit(e.units[T][k]);fe={x:A[k],y:ct(k,E),group:T,item:Ae,die:it},kt.set(Le,fe)}le.push({p:fe,cx:We,cy:De})}),t.stroke(),E<=300)for(const k of j)t.beginPath(),t.arc(w+B.frac(A[k])*r,u(g(ct(k,E))),2.5,0,Math.PI*2),t.fill()}if(t.restore(),he.size>0){t.lineWidth=1.5,t.strokeStyle=l.text;let T=0;for(const A of he)if(!(O.size>0&&!O.has(A.group))){if(++T>vt)break;t.beginPath(),t.arc(w+B.frac(A.x)*r,u(g(A.y)),4,0,Math.PI*2),t.stroke()}}const F=ge?le.find(T=>T.p===ge):void 0;F&&(t.beginPath(),t.arc(F.cx,F.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function xn(e){const l=s,h=l.marks.values[e.group].length,r=Math.round(e.y*h+.5),d=m.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[d,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${X(t)}</strong><br>`:"")+X(`${l.x.label}: ${J(e.x,l.x.unit)}`)+"<br>"+X(`rank ${r.toLocaleString("en-GB")} of ${h.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(m.onWaferMenu&&!e.die?Et:"")}let _e,xe=null;function vn(){const e=s?.marks;if(!s||!$||e?.type!=="heatmap")return;Ge($,te??0);const l=je(W),a=$.getContext("2d");let h=0,r=0;a&&(a.font=`${Q(-1)}px system-ui, sans-serif`,h=Te(e.rows.map(u=>a.measureText(u.length>24?`${u.slice(0,23)}\u2026`:u).width)),r=Te(e.cols.map(u=>a.measureText(u.length>22?`${u.slice(0,21)}\u2026`:u).width)));const d=Math.min(180,Math.max(w,h+24)),n=Math.max(8,R.clientWidth-d-xt)/Math.max(1,e.cols.length),t=r+8>n;qe=t?Ue+Math.min(110,r*.72):Ue;const{w:o,h:c}=Ne(),y=Math.max(10,o-d-xt),x=Math.max(10,c-M-qe),g=Xe($,W,o,c);if(!g)return;const{ctx:f}=g,p=y/e.cols.length,L=x/e.rows.length;_e={left:d,cw:p,ch:L,rows:e.rows.length,cols:e.cols.length};const P=s.colorScale,b=bt(s.spec.colorGradient,s.spec.colorReverse,P?.diverging,P?.rating),C=P&&P.hi-P.lo||1;f.font=`${Q(-1)}px system-ui, sans-serif`;for(let u=0;u<e.rows.length;u++)for(let i=0;i<e.cols.length;i++){const v=e.values[u][i],B=d+i*p,F=M+u*L,T=Number.isFinite(v)&&P?b((v-P.lo)/C):l.track;if(f.fillStyle=T,f.fillRect(B,F,p,L),Number.isFinite(v)&&p>=40&&L>=16){const A=so(T);f.fillStyle=A?"#1a1a1a":"#fff",f.textAlign="center",f.textBaseline="middle",Ct(f,Ot(v,s.y?.unit,P?.integer),B+p/2,F+L/2,A?"rgba(255,255,255,0.55)":"rgba(0,0,0,0.55)")}}f.lineWidth=1,f.setLineDash([]),f.strokeStyle=l.border,f.beginPath();for(let u=1;u<e.rows.length;u++){const i=Math.round(M+u*L)+.5;f.moveTo(d,i),f.lineTo(d+y,i)}for(let u=1;u<e.cols.length;u++){const i=Math.round(d+u*p)+.5;f.moveTo(i,M),f.lineTo(i,M+x)}f.stroke(),f.strokeStyle=l.textMuted,f.strokeRect(d+.5,M+.5,y-1,x-1),f.beginPath();for(let u=0;u<e.rows.length;u++){const i=Math.round(M+(u+.5)*L)+.5;f.moveTo(d-4,i),f.lineTo(d,i)}for(let u=0;u<e.cols.length;u++){const i=Math.round(d+(u+.5)*p)+.5;f.moveTo(i,M+x),f.lineTo(i,M+x+4)}f.stroke(),xe&&(f.lineWidth=2,f.strokeStyle=l.text,f.strokeRect(d+xe.c*p,M+xe.r*L,p,L)),f.fillStyle=l.textMuted,f.textAlign="right",f.textBaseline="middle",e.rows.forEach((u,i)=>f.fillText(u.length>24?`${u.slice(0,23)}\u2026`:u,d-8,M+(i+.5)*L)),e.cols.forEach((u,i)=>{const v=u.length>22?`${u.slice(0,21)}\u2026`:u,B=d+(i+.5)*p;t?(f.save(),f.translate(B,M+x+8),f.rotate(-Math.PI/4),f.textAlign="right",f.textBaseline="middle",f.fillText(v,0,0),f.restore()):(f.textAlign="center",f.textBaseline="top",f.fillText(v,B,M+x+7))}),f.font=`${Q(0)}px system-ui, sans-serif`,f.fillStyle=l.text,f.textAlign="center",f.textBaseline="bottom",f.fillText(s.x?.label??"",d+y/2,c-6)}function zt(e){if(!_e||!$)return null;const l=$.getBoundingClientRect(),a=Math.floor((e.clientX-l.left-_e.left)/_e.cw),h=Math.floor((e.clientY-l.top-M)/_e.ch);return h>=0&&h<_e.rows&&a>=0&&a<_e.cols?{r:h,c:a}:null}function kn(e){const l=s,a=l.marks,h=a.values[e.r][e.c],r=a.cellUnits[e.r][e.c].length,d=l.level==="die"?"dies":"wafers";return`<strong>${X(`${a.rows[e.r]} \xB7 ${a.cols[e.c]}`)}</strong><br>`+(Number.isFinite(h)?X(`${l.y?.label??"Count"}: ${Ot(h,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+X(`${r.toLocaleString("en-GB")} ${d}`)+(r&&m.onSelectPoints?"<br><em>click or right-click to chart or tabulate them</em>":"")}function Mn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="control")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=e.limits,c=Be(s.y),y=ue(Re(e.xs,s.x),s.x),x=ue(Fe(Re([...e.values,o.ucl,o.lcl],s.y),c,s.y),s.y);Z={x:y,y:x,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,x,s.x,s.y),ze(t,l.limitLine,r,d,x,c,s.y,"y"),Je(t,r,d);const g=i=>w+y.frac(e.xs[i])*r,f=i=>M+(1-x.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();const p=(i,v,B,F=1)=>{t.globalAlpha=B,t.setLineDash(v),t.lineWidth=F,t.strokeStyle=l.text,t.beginPath(),t.moveTo(w,f(i)),t.lineTo(w+r,f(i)),t.stroke()};for(const i of[-2,-1,1,2])p(o.centre+i*o.sigma,[2,4],.25);p(o.centre,[],.6,1.5),p(o.ucl,[6,4],.85),p(o.lcl,[6,4],.85),t.restore(),t.fillStyle=l.textMuted,t.font=`${Q(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const L=i=>J(i,s.y.unit);if(t.fillText(`UCL ${L(o.ucl)}`,w+r-4,f(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${L(o.lcl)}`,w+r-4,f(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${L(o.centre)}`,w+r-4,f(o.centre)-2),o.baseline<e.values.length){const i=(g(o.baseline-1)+g(o.baseline))/2;t.save(),t.strokeStyle=l.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(i,M),t.lineTo(i,M+d),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",w+4,M+2)}t.strokeStyle=ee(0),t.lineWidth=1.5,t.setLineDash([]);const P=O.size>0,b=i=>e.group?.[i]??0;if(!P)t.beginPath(),e.values.forEach((i,v)=>{v===0?t.moveTo(g(v),f(i)):t.lineTo(g(v),f(i))}),t.stroke();else{for(const i of[!1,!0]){t.globalAlpha=i?1:.2,t.beginPath();for(let v=1;v<e.values.length;v++)(O.has(b(v-1))&&O.has(b(v)))===i&&(t.moveTo(g(v-1),f(e.values[v-1])),t.lineTo(g(v),f(e.values[v])));t.stroke()}t.globalAlpha=1}const C=new Map(e.violations.map(i=>[i.index,i.rules]));le=[],e.values.forEach((i,v)=>{const B=C.get(v),F=b(v),T=P&&O.has(F),A=P&&!T;t.globalAlpha=A?.2:1,t.beginPath(),t.arc(g(v),f(i),(B?4.5:3)+(T?1.5:0),0,Math.PI*2),t.fillStyle=B?l.alert:ee(F),t.fill(),T&&(t.lineWidth=1.5,t.strokeStyle=l.text,t.stroke()),B&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(B.join(","),g(v),f(i)-(T?8:6))),t.globalAlpha=1,le.push({p:{x:e.xs[v],y:i,group:F,item:e.items[v]},cx:g(v),cy:f(i)})});const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Tn(e){const l=s,a=l.marks,h=a.items.indexOf(e.item),r=(e.y-a.limits.centre)/a.limits.sigma,d=a.violations.find(n=>n.index===h)?.rules;return`<strong>${X(m.waferLabel(e.item))}</strong><br>`+X(`${l.y.label}: ${J(e.y,l.y.unit)} (${r>=0?"+":"\u2212"}${Math.abs(r).toFixed(1)}\u03C3)`)+(d?`<br>${X(`breaks rule ${d.map(n=>`${n} (${On[n]})`).join(", ")}`)}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function wn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="goal")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(i=>Math.abs(i.x))),c=ue([-o,o],{...s.x,min:s.x.min??-o*1.05,max:s.x.max??o*1.05}),y=ue([0,...e.points.map(i=>i.y),1/6],{...s.y,min:s.y.min??0},{floorAtZero:!0});Z={x:c,y,plotW:r,plotH:d},Ke(t,l,a,h,r,d,c,y,s.x,s.y);const x=i=>w+c.frac(i)*r,g=i=>M+(1-y.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip(),t.font=`${Q(-1)}px system-ui, sans-serif`;const f=[[1,[6,4]],[1.33,[]]];for(const[i,v]of f){const B=1/(6*i);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(v),t.beginPath(),t.moveTo(x(-.5),g(0)),t.lineTo(x(0),g(B)),t.lineTo(x(.5),g(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${i}`,x(0)+4,g(B)-2)}t.restore(),le=[];const p=e.points.filter(i=>O.size===0||O.has(i.group));for(const i of p)t.beginPath(),t.arc(x(i.x),g(i.y),4,0,Math.PI*2),t.fillStyle=ee(i.group),t.fill(),le.push({p:{x:i.x,y:i.y,group:i.group,item:-1,value:i.testNumber},cx:x(i.x),cy:g(i.y)});const L=p.map(i=>({x0:x(i.x)-5,x1:x(i.x)+5,y0:g(i.y)-5,y1:g(i.y)+5})),P={x0:w,x1:w+r,y0:M,y1:M+d},b=i=>i.x0>=P.x0&&i.x1<=P.x1&&i.y0>=P.y0&&i.y1<=P.y1&&!L.some(v=>i.x0<v.x1&&i.x1>v.x0&&i.y0<v.y1&&i.y1>v.y0),C=Q(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const i of[...p].filter(v=>v.ppk<1.33).sort((v,B)=>v.ppk-B.ppk)){const v=x(i.x),B=g(i.y),F=t.measureText(i.label).width,T=[[v+7,B,"left"],[v-7,B,"right"],[v,B-13,"center"],[v,B+13,"center"]];for(const[A,E,j]of T){const k=j==="left"?A:j==="right"?A-F:A-F/2,ie={x0:k,x1:k+F,y0:E-C/2,y1:E+C/2};if(b(ie)){L.push(ie),t.textAlign=j,t.fillText(i.label,A,E);break}}}const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Sn(e){const l=s,h=l.marks.points.find(r=>r.testNumber===e.value&&r.group===e.group);return h?`<strong>${X(h.label)}</strong>${l.groups.length>1?` \xB7 ${X(He(h.group))}`:""}<br>`+X(`Ppk ${h.ppk.toFixed(2)} \xB7 ${h.n.toLocaleString("en-GB")} dies`)+"<br>"+X(`mean ${h.x>=0?"+":"\u2212"}${Math.abs(h.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(h.y*100).toFixed(1)}% of it (${h.basis==="spec"?"spec":"test"} limits)`):""}function Pn(e,l,a,h,r){!$e||!$||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${$.offsetTop+M}px`,height:`${r}px`,left:`${$.offsetLeft+w+h+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-a)>=1&&($e.scrollTop=a)))}function K(){$e&&($e.style.display="none"),dt&&!an()&&(dt.style.maxHeight=Qt(W)?"":`${ro}px`),pe&&m.panel&&(pe.style.display=Qt(W)?"flex":"none"),w=Wt,M=Rt;const e=s?.marks?.type;e==="scatter"?fn():e==="control"?Mn():e==="heatmap"?vn():e==="goal"?wn():e==="probability"?bn():e==="histogram"?hn():e==="box"||e==="bar"?dn():e==="line"&&yn(),Nt()}function $n(e){const l=s,a=m.waferLabel(e.item),h=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,h].filter(Boolean).join(" \xB7 "),d=(n,t)=>`${n.label}: ${J(t,n.unit)}`;return(r?`<strong>${X(r)}</strong><br>`:"")+X(d(l.x,e.x))+"<br>"+X(d(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${X(`${l.colorScale.label}: ${J(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function _t(e){if(!Ee||!Z||!s?.x)return null;const l=$.getBoundingClientRect(),h=(e.clientX-l.left-w)/Z.plotW;if(h<0||h>1)return null;const r=Z.x.reverse?1-h:h,{edges:d,counts:n}=Ee,t=d.length-1,o=Math.min(t-1,Math.max(0,Math.floor(r*t)));ye=o;const c=s.x,y=n.map((x,g)=>({g,n:x[o]})).filter(x=>x.n>0&&(O.size===0||O.has(x.g)));return`<strong>${X(`${J(d[o],c.unit)} to ${J(d[o+1],c.unit)}`)}</strong><br>`+(y.length?y.map(x=>{const g=s.spec.histNorm==="percent"?` (${Ee.heights[x.g][o].toFixed(1)}% of ${s.groups.length>1?"its colour":"them"})`:"";return X(`${s.groups.length>1?`${He(x.g)}: `:""}${x.n.toLocaleString("en-GB")} ${s.level==="die"?"dies":"wafers"}${g}`)}).join("<br>"):"none")}function Ln(e){const l=z.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:me.md,marginTop:me.md,marginBottom:me.xl,fontSize:gt.body,color:nt.label});const a=z.createElement("canvas");a.width=200,a.height=10,Object.assign(a.style,{width:"200px",height:"10px",borderRadius:Fn.control,flex:"0 0 auto"});const h=a.getContext("2d"),r=bt(s?.spec.colorGradient,s?.spec.colorReverse,e.diverging,e.rating);if(h)for(let c=0;c<200;c++)h.fillStyle=r(c/199),h.fillRect(c,0,1,10);const d=c=>s?.marks?.type==="heatmap"?Ot(c,e.unit,e.integer):J(c,e.unit),n=z.createElement("span");n.textContent=d(e.lo);const t=z.createElement("span");t.textContent=d(e.hi);const o=z.createElement("span");return o.textContent=e.label,o.style.color=nt.text,l.append(o,n,a,t),l}const st=(e,l,a)=>l.map(h=>{const{item:r,die:d}=e(h);return{x:0,y:0,group:a,item:r,die:d}});function An(){Ze?.destroy(),Ze=void 0,R.innerHTML="",$=void 0,pe=void 0,te=void 0,ot=[],ge=null,ye=-1,le=[],Z=void 0,ne=void 0,se=null,$e=void 0,lt=0,dt=void 0,_e=void 0,xe=null,de=[],be=-1,qe=Ue,kt=new Map,O.clear(),he.clear();for(const n of ce)n.destroy();ce=[],ut?.(),ut=void 0,R.style.overflowY="hidden",delete W.dataset.wmapPlotPanelsOwner,delete W.dataset.wmapPanelsHover,we(()=>W.querySelector("canvas"));const e=s,l=!!e?.facets&&!m.panel;if(W.style.flex=l?"0 0 auto":"1 1 0px",W.style.gridColumn=l?"1 / -1":"",!e)return;if(U.textContent=m.panel?m.panel.title:Nn(e),W.dataset.wmapChartTitle=U.textContent,e.issues.length||!e.marks){for(const n of e.issues)Jt(R,n);return}const a=z.createElement("div");Object.assign(a.style,{color:nt.label,fontSize:gt.body,marginBottom:me.xs});const h=m.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(m.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${h}`:m.onSelectPoints?` \xB7 click or right-click to ${m.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&m.onSelectPoints?" \xB7 click or right-click a bar to chart or tabulate its dies":e.marks.type==="heatmap"&&m.onSelectPoints?` \xB7 click or right-click a cell to chart or tabulate its ${e.level==="die"?"dies":"wafers"}`:e.marks.type==="probability"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="line"&&m.onSelectPoints?` \xB7 click a point to ${m.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the plot to select ${m.selectRangeLabel??"a run of points"}`:"";a.textContent=m.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:Ht(e)+(e.facets?"":r),m.panel||Xn(a,Kt(e)),Vt(a),te=z.createElement("div"),te.style.display="flow-root",R.appendChild(te),te.appendChild(a);for(const n of e.fitNotes??[]){const t=z.createElement("div");t.dataset.wmapPlotFit="1",t.textContent=n,Object.assign(t.style,{color:nt.text,fontSize:gt.body,marginBottom:me.xxs,fontVariantNumeric:"tabular-nums"}),te.appendChild(t)}for(const n of e.notes){const t=z.createElement("div");Vt(t),t.textContent=n,Object.assign(t.style,{color:nt.warnText,fontSize:gt.body,marginBottom:me.xs}),te.appendChild(t)}if(e.plotted===0){Jt(R,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&!e.colorRepeatsX&&(pe=z.createElement("div"),pe.dataset.wmapPlotLegend="1",Object.assign(pe.style,{display:m.panel?"none":"flex",flexWrap:"wrap",gap:me.sm,marginTop:me.md,marginBottom:me.xl,overflowY:"auto"}),dt=pe,e.facets&&Object.assign(pe.style,{position:"sticky",top:"0",zIndex:"2",background:nt.menuBg,paddingBottom:me.sm,marginBottom:me.md}),e.groups.forEach((n,t)=>{const o=Vn(n||"(none)",ee(t),z);Yn(o.el,W,_,`${n||"(none)"} \u2014 click to filter`),o.el.addEventListener("click",()=>{if(O.has(t)?O.delete(t):O.add(t),ot.forEach((c,y)=>c.setState({selected:O.has(y),dimmed:O.size>0&&!O.has(y)})),ce.length)for(const c of ce)c.setActiveGroups(O);else K()}),ot.push(o),pe.appendChild(o.el)}),ot.forEach((n,t)=>n.setState({selected:O.has(t),dimmed:O.size>0&&!O.has(t)})),te.appendChild(pe)),e.colorScale&&!m.panel&&(pe=Ln(e.colorScale),te.appendChild(pe)),e.facets){const n=z.createElement("div");n.dataset.wmapPlotPanels="1",n.style.isolation="isolate",Object.assign(n.style,{display:"grid",gap:me.md});const t=()=>{n.style.gridTemplateColumns=Ie?`repeat(${Ie}, minmax(0, 1fr))`:`repeat(auto-fill, minmax(${ho}px, 1fr))`};t();const o=Zn("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(x=>({value:String(x),label:`${x} (${x})`}))],Ie?String(Ie):"auto",x=>{Ie=x==="auto"?void 0:Number(x),t()},{hook:"panel-columns",maxWidth:"90px",ownerDocument:z});Object.assign(o.style,{justifyContent:"flex-end",marginBottom:me.sm});const c=o.querySelector("button");R.append(o,n),R.style.overflowY="auto",W.dataset.wmapPlotPanelsOwner="1",ht&&(W.dataset.wmapPanelsHover="1");const y=x=>{if(!ht||x.ctrlKey||x.metaKey||x.altKey||x.shiftKey||x.defaultPrevented||!/^[0-5]$/.test(x.key))return;const g=x.target;typeof g?.closest=="function"&&g.closest('input, textarea, select, [contenteditable="true"], [role="menu"]')||(x.preventDefault(),Ie=x.key==="0"?void 0:Number(x.key),t(),c&&(c.value=Ie?String(Ie):"auto"))};z.addEventListener("keydown",y),ut=()=>z.removeEventListener("keydown",y);for(const x of e.facets){const g=renderPlotChart({...m,panel:{title:x.label}});n.appendChild(g.card),g.setPlot(x.plot),ce.push(g)}we(()=>mo(n));return}$=z.createElement("canvas"),$.style.display="block",$.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",R.appendChild($);const d=m.onWaferMenu||m.onSelectPoints?(n,t)=>{!n.die&&m.onWaferMenu?m.onWaferMenu(n.item,Ve(e.spec),t):n.die&&m.onSelectPoints&&(t.preventDefault(),m.onSelectPoints([n],{x:t.clientX,y:t.clientY},$))}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!m.onSelectPoints;Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:$n,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:t?{pick:({x0:o,y0:c,x1:y,y1:x})=>Z?(O.size===0?n.points:n.points.filter(f=>O.has(f.group))).filter(f=>{const p=w+Z.x.frac(f.x)*Z.plotW,L=M+(1-Z.y.frac(f.y))*Z.plotH;return p>=o&&p<=y&&L>=c&&L<=x}):[],onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const n=e.marks.type==="control";Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:n?Tn:Sn,clickable:()=>n&&!!m.onOpenWafer,onOpen:t=>{n&&m.onOpenWafer?.(t.item,Ve(e.spec))},onContextMenu:n?d:void 0,onHover:t=>{ge=t,K()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:xn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:m.onSelectPoints?{pick:({x0:o,y0:c,x1:y,y1:x})=>{if(!Z)return[];const g=[];return n.values.forEach((f,p)=>{O.size>0&&!O.has(p)||f.forEach((L,P)=>{const b=ct(P,f.length),C=w+Z.x.frac(L)*Z.plotW,u=M+(1-Z.y.frac(t?b:Yt(b)))*Z.plotH;if(C<o||C>y||u<c||u>x)return;const{item:i,die:v}=n.unit(n.units[p][P]);g.push({x:L,y:b,group:p,item:i,die:v})})}),g},onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="histogram"){un(),$.addEventListener("mousemove",t=>{const o=_t(t);if(!o){_.style.display="none",ye>=0&&(ye=-1,K());return}_.innerHTML=o,_.style.display="block",yt(_,W,t.clientX,t.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",ye>=0&&(ye=-1,K())});const n=e.marks;if(m.onSelectPoints){$.style.cursor="pointer";const t=o=>{if(!Ee||_t(o)===null)return!1;const c=ye,{edges:y}=Ee,x=Z?.x.log,g=x?Math.log10(y[0]):y[0],f=x?Math.log10(y[y.length-1]):y[y.length-1],p=y.length-1,L=[];return n.values.forEach((P,b)=>{if(O.size>0&&!O.has(b))return;const C=[];P.forEach((u,i)=>{const v=x?u>0?Math.log10(u):NaN:u;!Number.isFinite(v)||v<g||v>f||Math.min(p-1,Math.floor((v-g)/(f-g)*p))===c&&C.push(n.units[b][i])});for(const u of st(n.unit,C,b))L.push(u)}),L.length===0?!1:(_.style.display="none",m.onSelectPoints(L,{x:o.clientX,y:o.clientY},$,{range:{lo:y[c],hi:y[c+1]},...O.size===1?{group:e.groups[[...O][0]]}:{}}),!0)};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}}else if(e.marks.type==="heatmap"){const n=e.marks;$.addEventListener("mousemove",o=>{const c=zt(o);if($.style.cursor=c&&m.onSelectPoints&&n.cellUnits[c.r][c.c].length?"pointer":"default",!c){_.style.display="none",xe&&(xe=null,K());return}_.innerHTML=kn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!xe||xe.r!==c.r||xe.c!==c.c)&&(xe=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",xe&&(xe=null,K())});const t=o=>{const c=zt(o);if(!c||!m.onSelectPoints)return!1;const y=n.cellUnits[c.r][c.c];return y.length?(_.style.display="none",m.onSelectPoints(st(n.unit,y,0),{x:o.clientX,y:o.clientY},$,{cell:{row:n.rows[c.r],column:n.cols[c.c]}}),!0):!1};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const o=z.createElement("div");o.dataset.wmapRowScroll="1",o.tabIndex=0,o.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(o.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const c=z.createElement("div");c.style.width="1px",o.appendChild(c),o.addEventListener("scroll",()=>{Math.abs(o.scrollTop-lt)<1||(lt=o.scrollTop,_.style.display="none",K())}),$.addEventListener("wheel",y=>{if(o.style.display==="none")return;const x=o.scrollTop;o.scrollTop+=y.deltaMode===1?y.deltaY*16:y.deltaY,o.scrollTop!==x&&y.preventDefault()},{passive:!1}),R.appendChild(o),$e=o}$.addEventListener("mousemove",o=>{const c=Pt(o);if($.style.cursor=c&&(n.categoryItems&&m.onOpenWafer||m.onSelectPoints&&n.cellUnits[c.g][c.c].length>0)?"pointer":"default",!c){_.style.display="none",se&&(se=null,K());return}_.innerHTML=gn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!se||se.g!==c.g||se.c!==c.c)&&(se=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",se&&(se=null,K())});const t=(o,c)=>{const y=n.cellUnits[c.g][c.c];return y.length===0||!m.onSelectPoints?!1:(_.style.display="none",m.onSelectPoints(st(n.unit,y,c.g),{x:o.clientX,y:o.clientY},$,{category:n.categories[c.c],...e.groups.length>1?{group:e.groups[c.g]}:{},...mn(n.categories[c.c])}),!0)};$.addEventListener("contextmenu",o=>{const c=Pt(o);if(!c)return;const y=n.categoryItems?.[c.c];y!==void 0&&y>=0&&m.onWaferMenu?(_.style.display="none",m.onWaferMenu(y,Ve(e.spec),o)):t(o,c)&&o.preventDefault()}),$.addEventListener("click",o=>{const c=Pt(o);if(!c)return;const y=n.categoryItems?.[c.c];if(y!==void 0&&y>=0&&m.onOpenWafer){m.onOpenWafer(y,Ve(e.spec));return}t(o,c)})}else if(e.marks.type==="line"){$.addEventListener("mousemove",o=>{const c=$t(o);if(!c){_.style.display="none",K();return}_.innerHTML=c,_.style.display="block",yt(_,W,o.clientX,o.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",be>=0&&(be=-1,K())});const n=e.marks,t=()=>n.cellUnits.flatMap((o,c)=>O.size>0&&!O.has(c)?[]:st(n.unit,o[be]??[],c));if((m.onWaferMenu||m.onSelectPoints)&&$.addEventListener("contextmenu",o=>{if($t(o)===null||be<0)return;const c=Ft(be);if(c!==void 0&&m.onWaferMenu)_.style.display="none",m.onWaferMenu(c,Ve(e.spec),o);else if(m.onSelectPoints){const y=t();y.length>0&&(o.preventDefault(),_.style.display="none",m.onSelectPoints(y,{x:o.clientX,y:o.clientY},$))}}),m.onSelectPoints){$.style.cursor="pointer";let o=!1;$.addEventListener("mousedown",c=>{if(c.button!==0)return;o=!1;const y=$.getBoundingClientRect(),x=c.clientX-y.left,g=f=>{z.removeEventListener("mouseup",g);const p=f.clientX-y.left;if(Math.abs(p-x)<4)return;o=!0;const[L,P]=x<p?[x,p]:[p,x],b=de.map((u,i)=>u>=L&&u<=P?i:-1).filter(u=>u>=0),C=n.cellUnits.flatMap((u,i)=>O.size>0&&!O.has(i)?[]:b.flatMap(v=>st(n.unit,u[v]??[],i)));C.length>0&&(_.style.display="none",m.onSelectPoints(C,{x:f.clientX,y:f.clientY},$))};z.addEventListener("mouseup",g)}),$.addEventListener("click",c=>{if(o){o=!1;return}if($t(c)===null||be<0)return;const y=t();y.length>0&&(_.style.display="none",m.onSelectPoints(y,{x:c.clientX,y:c.clientY},$))})}}K()}V(()=>{const e=s;if(!e||!e.marks)return;const l=bt(e.spec.colorGradient,e.spec.colorReverse,e.colorScale?.diverging,e.colorScale?.rating);return{caption:[Ht(e),...e.fitNotes??[],...e.notes,...oo(Kt(e))],legend:e.groups.length>1&&!e.colorRepeatsX?e.groups.map((a,h)=>({label:a||"(none)",color:ee(h)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:J(e.colorScale.lo,e.colorScale.unit),hi:J(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const Cn=jn(W,()=>K());return{card:W,actions:Y,setPlot(e){s=e,Me(io(e.spec)),An()},setMenuRows(e){Oe=e},setActiveGroups(e){O.clear();for(const l of e)O.add(l);ot.forEach((l,a)=>l.setState({selected:O.has(a),dimmed:O.size>0&&!O.has(a)})),K()},destroy(){ut?.(),Cn.disconnect(),Ze?.destroy();for(const e of ce)e.destroy()}}}
|
|
1
|
+
import{escHtml as X,maxOf as Te,minOf as Ut}from"../../core/utils.js";import{fiveNumberSummary as Yt,normalQuantile as qt,sampleVariance as Rn}from"../../stats/math.js";import{CONTROL_RULE_TEXT as In}from"../../stats/control.js";import{PAT_VERDICT_LABEL as Ht}from"../../stats/pat.js";import{fmt as J}from"../../renderer/fmt.js";import{fitTicks as mt}from"../../renderer/axisTicks.js";import{binOfLabel as Nn,plotFootnote as Kt,plotGuideSections as Vt,plotOpensBins as Fn,plotTestNumber as pt,plotTitle as zn,probabilityPosition as rt}from"../../stats/plotData.js";import{SPACE as me,RADIUS as _n,fontPx as Q,FONT as gt,CLR as tt,markNoPrint as Zt}from"../toolbar.js";import{exportCsv as Dn}from"../tableExport.js";import{tableToTsv as Gn}from"../../core/tableCsv.js";import{plotTable as Xn}from"../../stats/plotTable.js";import{cardShell as jn,appendGuideCites as Un,observeResize as Yn,makeTooltip as qn,attachChartTip as Hn,chartFillHeight as Kn,applyCanvasFlow as Ge,prepareCanvas as Xe,positionChartTooltip as yt,resolveChartCanvasColors as je,makeAxisFormat as Vn,horizontalTickSpacing as Jt,VERTICAL_TICK_SPACING_PX as Zn,makeSeriesLegendItem as Jn,renderEmptyState as Qt,isExpandedCard as en,makeLabeledSelect as Qn,fillTextOnHalo as Et,limitLines as eo,limitExtent as to,stackLabelRows as tn,placeClearOf as nn,strokeLimitLine as on,drawOffAxisLimits as no,limitLabelPlacement as oo,shouldIncludeLimitsByDefault as lo,WAFER_MENU_HINT as Bt}from"./chartShell.js";import{guideCitesText as so}from"../../stats/guideSections.js";import{categorical as io}from"./palette.js";import{NO_DATA_FILL as ln}from"../../renderer/colorMap.js";import{darkTextOnColor as ao,plotGradient as bt}from"./divergingScale.js";import{wirePointInteractions as Wt}from"./pointInteractions.js";import{plotAbout as ro}from"./cardAbout.js";const Ot=64,xt=16,Rt=12,Ue=52,co=16,fo=92,uo=16,vt=5e3,sn=1500,ct=100,ho=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],an=m=>`${+(m*100).toPrecision(4)}%`;export function categoryLayout(m){const W=.8/Math.max(1,...m.map(O=>O.length)),U=O=>(1-m[O].length*W)/2;return{width:W,left:(O,Y)=>{const V=m[O].indexOf(Y);return V<0?void 0:U(O)+V*W},groupAt:(O,Y)=>{const V=Math.floor((Y-U(O))/W);return V>=0&&V<m[O].length?m[O][V]:void 0}}}function mo(m){if(m<=sn)return Array.from({length:m},(O,Y)=>Y);const z=[];for(let O=0;O<ct;O++)z.push(O);const W=sn-2*ct,U=m-2*ct;for(let O=0;O<W;O++)z.push(ct+Math.floor(O*U/W));for(let O=m-ct;O<m;O++)z.push(O);return z}const kt=m=>[pt(m),Fn(m)?"bins":void 0];function It(m,z,W){return W?Math.round(m).toLocaleString("en-GB"):z?J(m,z):`${m<=-.005?"\u2212":""}${Math.abs(m).toFixed(2)}`}const po=260;function go(m){const z=[...m.querySelectorAll("[data-wmap-plot-panel]")],W=z[0]?.querySelector("canvas");if(!W)return null;const U=W.width/Math.max(1,W.getBoundingClientRect().width)||1,O=m.getBoundingClientRect(),Y=m.ownerDocument.createElement("canvas");Y.width=Math.ceil(O.width*U),Y.height=Math.ceil(O.height*U);const V=Y.getContext("2d");if(!V)return null;const we=getComputedStyle(m);V.fillStyle=we.backgroundColor&&we.backgroundColor!=="rgba(0, 0, 0, 0)"?we.backgroundColor:"#fff",V.fillRect(0,0,Y.width,Y.height);for(const Me of z){const Se=Me.querySelector("canvas"),ce=Me.dataset.wmapChartTitle??"",_=(Se??Me).getBoundingClientRect(),s=Me.getBoundingClientRect();V.fillStyle=getComputedStyle(Me).color||"#333",V.font=`600 ${Math.round(13*U)}px system-ui, sans-serif`,V.textBaseline="top",V.fillText(ce,(s.left-O.left+8)*U,(s.top-O.top+6)*U),Se&&V.drawImage(Se,(_.left-O.left)*U,(_.top-O.top)*U,_.width*U,_.height*U)}return Y}const Oe=(m,z)=>z.extent?[...m,...z.extent]:m;function ue(m,z,W={}){const U=z.scale==="log";let O=m.length?Ut(m):0,Y=m.length?Te(m):1;U&&(O=Math.log10(Math.max(O,Number.MIN_VALUE)),Y=Math.log10(Math.max(Y,Number.MIN_VALUE)));const V=(Y-O)*.05||(U?.5:1);O=W.floorAtZero&&!U&&O>=0?0:O-V,Y+=V;const Me=Pe=>Pe===void 0||!Number.isFinite(Pe)?void 0:U?Pe>0?Math.log10(Pe):void 0:Pe,Se=Me(z.min),ce=Me(z.max);Se!==void 0&&(O=Se),ce!==void 0&&(Y=ce),Y>O||(Y=O+1);const _=Y-O,s=!!z.reverse,Re=Pe=>{const $=((U?Math.log10(Math.max(Pe,Number.MIN_VALUE)):Pe)-O)/_;return s?1-$:$};return{lo:U?10**O:O,hi:U?10**Y:Y,log:U,reverse:s,frac:Re}}function Nt(m,z,W,U){if(z/m<10)return mt(m,z,W,U);const O=Math.floor(Math.log10(m)),Y=Math.ceil(Math.log10(z)),V=Se=>{const ce=[];for(let _=O;_<=Y;_++)for(const s of Se){const Re=s*10**_;Re>=m&&Re<=z&&ce.push(Re)}return ce},we=V([1]);return{ticks:we.length>=4?we:V([1,2,5]),step:0}}export function renderPlotChart(m){const z=m.ownerDocument??document,{card:W,heading:U,body:O,controlsRow:Y,setPngDecor:V,setPngCanvas:we,setAbout:Me,setMenuRows:Se}=jn(m.panel?.title??"Plot",m.onSaveImage,z,{png:!m.panel});m.panel&&(W.dataset.wmapPlotPanel="1");let ce=[];W.dataset.wmapPlotCard="1";const _=qn(W);let s,Re=()=>[];const Pe=()=>{const e=s&&(s.marks||s.facets?.length)?Xn(s,m.waferLabel):void 0;return e?[{label:"Save data as CSV",onClick:()=>{Dn(e.columns,e.rows,`${e.name}.csv`,m.onSaveText)}},{label:"Copy data",onClick:()=>{z.defaultView?.navigator.clipboard?.writeText(Gn(e.columns,e.rows))}}]:[]};Se(()=>[...Pe(),...Re()]);let $,pe,te,Ve,Ie,ft,ut=!1;W.addEventListener("pointerenter",()=>{ut=!0,W.dataset.wmapPlotPanelsOwner&&(W.dataset.wmapPanelsHover="1")}),W.addEventListener("pointerleave",()=>{ut=!1,delete W.dataset.wmapPanelsHover});let nt=[];const R=new Set,he=new Set;let ge=null,ye=-1,le=[],Z,Ee,ne,se=null,ot=0,$e,ht;const rn=()=>!!s?.facets;let de=[],be=-1,Mt=new Map,Ye=[],qe=Ue,w=Ot,M=Rt;const cn={[Ht.outlier]:"#e69f00",[Ht.fails]:"#c0392b"},ee=e=>{const l=s?.groups[e]??"";if(s?.colorBins&&m.binColors){const a=Nn(l);return a===void 0?ln:(s.colorBins==="hard"?m.binColors.hard:m.binColors.soft).get(a)??ln}return cn[l]??io(e)},He=e=>s?.groups[e]||"";function Ne(){const e=O.clientWidth,l=(m.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(qe-Ue),a=Kn(W,O,$,l);return{w:e,h:a,plotW:Math.max(10,e-w-xt),plotH:Math.max(10,a-M-qe)}}const Be=e=>{const l=(e?.references??[]).flatMap(a=>a.to===void 0?[{value:a.at,kind:"ref",end:"lo",label:a.label??""}]:[{value:a.at,kind:"ref",end:"lo",label:a.label??"",bandTo:a.to},{value:a.to,kind:"ref",end:"hi",label:a.label??""}]);return[...eo(e?.limits,s?.spec.limits??"both"),...l].filter(a=>e?.scale!=="log"||a.value>0)},Fe=(e,l,a)=>{const h=a?.clip,r=h?[...e.filter(c=>c>=h.lo&&c<=h.hi),h.lo,h.hi]:e,d=r.filter(Number.isFinite);if(!l.length||d.length===0)return r;const{lo:n,hi:t}=to(l);return(a?s?.spec.axes?.[a===s?.x?"x":"y"]?.includeLimits:void 0)??lo(Ut(d),Te(d),n,t)?[...r,...l.map(c=>c.value)]:r};let Tt;function Ze(e,l,a,h=!1){return!h&&!s?.x?.clip&&!s?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(w,M,l,a),e.clip(),Tt=e,Ft)}function Ft(){Tt?.restore(),Tt=void 0}function ze(e,l,a,h,r,d,n,t,o){const c=[];if(d.length===0)return()=>{};const y=d.filter(p=>p.value>=r.lo&&p.value<=r.hi),x=d.filter(p=>!y.includes(p)).map(p=>({value:p.value,label:p.label,side:p.value<r.lo?"lo":"hi"}));e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`;const g=p=>`${p.label} ${J(p.value,n.unit)}`.trim(),f=Q(-1)+2;for(const p of d){if(p.bandTo===void 0)continue;const L=r.frac(Math.min(p.value,p.bandTo)),P=r.frac(Math.max(p.value,p.bandTo)),b=Math.max(0,Math.min(L,P)),C=Math.min(1,Math.max(L,P));C<=b||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(w,M+(1-C)*h,a,(C-b)*h):e.fillRect(w+b*a,M,(C-b)*a,h),e.restore())}if(t==="y"){const p=y.map(b=>{const C=M+(1-r.frac(b.value))*h;return{l:b,y:C,start:C-6-f/2,end:C-6+f/2}}),L=tn(p,1),P=p.length?Te(p.map(b=>e.measureText(g(b.l)).width))+8:0;p.forEach(({l:b,y:C},u)=>{e.globalAlpha=.7,on(e,b,l,w,C,w+a,C),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const i=w+3+L[u]*P,v=nn(Ye,{x0:i,x1:i+e.measureText(g(b)).width,y0:C-4-f+2,y1:C-4+2},f);if(!o){e.fillText(g(b),i,v.y1-2);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",Et(e,g(b),i,v.y1-2,o.halo),e.restore()})})}else{const p=y.map(P=>{const b=w+r.frac(P.value)*a,C=g(P),u=P.label.split(/\s+/)[0],i=J(P.value,n.unit),v=u&&u!==P.label?[C,`${u} ${i}`,u]:[C],B=y.filter(E=>E!==P).map(E=>w+r.frac(E.value)*a),{text:F,side:T}=oo(b,v,E=>e.measureText(E).width,w,w+a,P.end==="lo",B),A=e.measureText(F).width;return{l:P,x:b,side:T,shown:F,start:T<0?b-3-A:b+3,end:T<0?b-3:b+3+A}}),L=tn(p,4);p.forEach(({l:P,x:b,side:C,shown:u,start:i,end:v},B)=>{e.globalAlpha=.7,on(e,P,l,b,M,b,M+h),e.globalAlpha=1;const F=C<0?"right":"left";e.fillStyle=l,e.textAlign=F,e.textBaseline="top";const T=M+2+L[B]*f,A=nn(Ye,{x0:i,x1:v,y0:T,y1:T+f},f);if(!o){e.fillText(u,b+C*3,A.y0);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=F,e.textBaseline="top",Et(e,u,b+C*3,A.y0,o.halo),e.restore()})})}return e.restore(),no(e,x,{left:w,right:w+a,top:M,bottom:M+h},t==="y"?"vertical":"horizontal",l,p=>J(p,n.unit),void 0,Ye),()=>c.forEach(p=>p())}function wt(e,l,a,h){return Vn(Math.max(Math.abs(l),Math.abs(a)),e.unit,h,e.label)}function dt(e,l){return l?`${e.label} (${l})`:e.label}const St=18,Pt=(e,l,a)=>{if(e.measureText(l).width<=a)return l;for(let h=l.length-1;h>0;h--){const r=`${l.slice(0,h)}\u2026`;if(e.measureText(r).width<=a)return r}return""};function Ke(e,l,a,h,r,d,n,t,o,c,y){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const x=()=>Zn,g=y?{ticks:y.map(b=>b.at),step:0}:t.log?Nt(t.lo,t.hi,d,x):mt(t.lo,t.hi,d,x),f=new Map(y?.map(b=>[b.at,b.label])),p=wt(c,t.lo,t.hi,g.step||void 0),L=y?{tick:b=>f.get(b)??"",unitLabel:""}:p;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let P="";if("labels"in n){const b=n.labels.length;if(n.labels.forEach((C,u)=>{const i=w+(u+.5)/b*r,v=C.length>22?`${C.slice(0,21)}\u2026`:C;n.rotate?(e.save(),e.translate(i,M+d+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,i,M+d+4))}),n.nest){const C=n.nest[0]?.length??0,u=r/b;for(let i=C-2;i>=0;i--){const v=h-6-St-i*St,B=T=>n.nest[T].slice(0,i+1).join("");let F=0;for(let T=1;T<=b;T++){if(T<b&&B(T)===B(F))continue;const E=w+F*u,j=w+T*u;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Pt(e,n.nest[F][i],j-E-4),(E+j)/2,v),T<b&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=i===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(j,M),e.lineTo(j,v-2),e.stroke(),e.restore()),F=T}}e.fillStyle=l.textMuted}}else{const b=Jt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),C=n.log?Nt(n.lo,n.hi,r,b):mt(n.lo,n.hi,r,b),u=wt(o,n.lo,n.hi,C.step||void 0);P=u.unitLabel;for(const i of C.ticks){const v=w+n.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(u.tick(i),v,M+d+4)}}for(const b of g.ticks){const C=M+(1-t.frac(b))*d;e.beginPath(),e.moveTo(w,C),e.lineTo(w+r,C),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(L.tick(b),w-4,C)}e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(dt(o,P),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(dt(c,L.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function fn(e,l,a,h,r,d,n,t,o,c,y,x={along:d,offset:0}){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const g=Jt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),y.unit),f=o.log?Nt(o.lo,o.hi,r,g):mt(o.lo,o.hi,r,g),p=wt(y,o.lo,o.hi,f.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const i of f.ticks){const v=w+o.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(i),v,M+d+4)}const L=n.labels.length,P=x.along/Math.max(1,L),b=M-x.offset;e.save(),e.beginPath(),e.rect(0,M-1,w+r+1,d+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const C=Math.max(0,Math.floor(x.offset/P)),u=Math.min(L,Math.ceil((x.offset+d)/P));for(let i=C;i<u;i++)e.fillText(Pt(e,n.labels[i],t.inner),w-6,b+(i+.5)*P);if(n.nest){const i=n.nest[0]?.length??0;let v=w-6-t.inner-10;for(let B=i-2;B>=0;B--){const F=t.outer[B]??0,T=E=>n.nest[E].slice(0,B+1).join("");let A=0;for(let E=1;E<=L;E++){if(E<L&&T(E)===T(A))continue;const j=b+A*P,k=b+E*P;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(Pt(e,n.nest[A][B],F),v,(j+k)/2),E<L&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=B===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(v-F,k),e.lineTo(w+r,k),e.stroke(),e.restore()),A=E}v-=F+10}e.fillStyle=l.textMuted}e.restore(),e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(dt(y,p.unitLabel),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(dt(c,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function un(){if(!s||!$||s.marks?.type!=="scatter"||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,t=s.marks.points,o=R.size===0?t:t.filter(T=>R.has(T.group)),c=s.colorScale,y=bt(s.spec.colorGradient,s.spec.colorReverse,c?.diverging,c?.rating),x=Be(s.x),g=Be(s.y),f=ue(Fe(Oe(t.map(T=>T.x),s.x),x,s.x),s.x),p=ue(Fe(Oe(t.map(T=>T.y),s.y),g,s.y),s.y);Z={x:f,y:p,plotW:h,plotH:r},Ke(n,e,l,a,h,r,f,p,s.x,s.y),ze(n,e.limitLine,h,r,f,x,s.x,"x"),ze(n,e.limitLine,h,r,p,g,s.y,"y"),Ze(n,h,r);const L=o.length>vt?Math.ceil(o.length/vt):1,P=[];for(let T=0;T<o.length;T+=L)P.push(o[T]);n.globalAlpha=Math.max(.15,Math.min(.7,200/P.length));let b;if(c)b=[P];else{const T=new Map;for(const A of P){const E=T.get(A.group);E?E.push(A):T.set(A.group,[A])}b=[...T.values()].sort((A,E)=>E.length-A.length)}le=[];const C=w,u=w+h,i=M,v=M+r;for(const T of b)for(const A of T){const E=w+f.frac(A.x)*h,j=M+(1-p.frac(A.y))*r;E<C||E>u||j<i||j>v||(le.push({p:A,cx:E,cy:j}),n.beginPath(),n.arc(E,j,2.5,0,Math.PI*2),n.fillStyle=c&&A.value!==void 0?y((A.value-c.lo)/(c.hi-c.lo||1)):ee(A.group),n.fill())}n.globalAlpha=1;const B=s.marks;if(B.type==="scatter"&&(B.identity||B.fits)){const T=(E,j)=>[w+f.frac(E)*h,M+(1-p.frac(j))*r],A=(E,j,k)=>{n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=j,n.lineWidth=2,n.setLineDash(k),n.beginPath();for(let ie=0;ie<=60;ie++){const We=ie/60,De=f.log?10**(Math.log10(f.lo)+(Math.log10(f.hi)-Math.log10(f.lo))*We):f.lo+(f.hi-f.lo)*We,[Le,fe]=T(De,E(De));ie===0?n.moveTo(Le,fe):n.lineTo(Le,fe)}n.stroke(),n.restore()};B.identity&&A(E=>E,e.textMuted,[6,4]);for(const E of B.fits??[])R.size>0&&!R.has(E.group)&&!c||A(j=>E.intercept+E.slope*j,c?e.text:ee(E.group),[])}const F=ge?le.find(T=>T.p===ge):void 0;if(F&&(n.beginPath(),n.arc(F.cx,F.cy,5,0,Math.PI*2),n.lineWidth=2,n.strokeStyle=e.text,n.stroke()),he.size>0){n.lineWidth=1.5,n.strokeStyle=e.text;let T=0;for(const A of he)if(!(R.size>0&&!R.has(A.group))){if(++T>vt)break;n.beginPath(),n.arc(w+f.frac(A.x)*h,M+(1-p.frac(A.y))*r,4,0,Math.PI*2),n.stroke()}}}function hn(){if(Ee=void 0,!s||s.marks?.type!=="histogram"||!s.x)return;const e=s.marks.values,l=e.flat();if(l.length===0)return;const a=ue(Fe(Oe(l,s.x),Be(s.x),s.x),s.x),h=Math.max(1,s.spec.bins??uo),r=a.log?Math.log10(a.lo):a.lo,d=a.log?Math.log10(a.hi):a.hi,n=Array.from({length:h+1},(g,f)=>{const p=r+(d-r)*f/h;return a.log?10**p:p}),t=e.map(()=>new Array(h).fill(0));e.forEach((g,f)=>{for(const p of g){const L=a.log?p>0?Math.log10(p):NaN:p;if(!Number.isFinite(L)||L<r||L>d)continue;const P=Math.min(h-1,Math.floor((L-r)/(d-r)*h));t[f][P]++}});const o=s.spec.histNorm==="percent",c=o?t.map(g=>{const f=g.reduce((p,L)=>p+L,0);return g.map(p=>f?p/f*100:0)}):t;let y=0;const x=e.map(()=>{});if(s.spec.normalCurve&&!a.log){const g=(n[n.length-1]-n[0])/h;e.forEach((f,p)=>{const L=f.filter(Number.isFinite);if(L.length<2)return;const P=L.reduce((C,u)=>C+u,0)/L.length,b=Math.sqrt(Rn(L,P));b>0&&(x[p]={mean:P,sd:b},y=Math.max(y,(o?100:t[p].reduce((C,u)=>C+u,0))*g/(b*Math.sqrt(2*Math.PI))))})}Ee={edges:n,counts:t,heights:c,normal:x,maxCount:Math.max(o?.001:1,y,...c.map(g=>Te(g)))}}function dn(){if(!s||!$||!Ee||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,{edges:t,counts:o,heights:c,normal:y,maxCount:x}=Ee,g=ue([t[0],t[t.length-1]],{...s.x,min:t[0],max:t[t.length-1]}),f=ue([0,x],{label:s.y.label,scale:"linear",min:0,max:x*1.05});Z={x:g,y:f,plotW:h,plotH:r},Ke(n,e,l,a,h,r,g,f,s.x,s.y),ze(n,e.limitLine,h,r,g,Be(s.x),s.x,"x"),Ze(n,h,r);const p=o.map((u,i)=>i).filter(u=>R.size===0||R.has(u)),L=p.length>1,P=p.length>=3,b=u=>w+Math.min(g.frac(t[u]),g.frac(t[u+1]))*h,C=u=>w+Math.max(g.frac(t[u]),g.frac(t[u+1]))*h;for(const u of p){if(P){n.fillStyle=ee(u),n.strokeStyle=ee(u),n.lineWidth=1.75,n.lineJoin="round",n.globalAlpha=.1,c[u].forEach((v,B)=>{if(v===0)return;const F=M+(1-f.frac(v))*r;n.fillRect(b(B),F,Math.max(1,C(B)-b(B)),M+r-F)}),n.globalAlpha=1,n.beginPath();let i=!1;c[u].forEach((v,B)=>{const F=M+(1-f.frac(v))*r;i||(n.moveTo(b(B),M+r),i=!0),n.lineTo(b(B),F),n.lineTo(C(B),F),B===c[u].length-1&&n.lineTo(C(B),M+r)}),n.stroke();continue}n.globalAlpha=L?.55:.85,n.fillStyle=ee(u),c[u].forEach((i,v)=>{if(i===0)return;const B=M+(1-f.frac(i))*r;n.fillRect(b(v),B,Math.max(1,C(v)-b(v)-1),M+r-B)})}if(n.globalAlpha=1,s.spec.normalCurve&&!g.log){const u=(t[t.length-1]-t[0])/(t.length-1);for(const i of p){const v=y[i];if(!v)continue;const{mean:B,sd:F}=v,T=(s.spec.histNorm==="percent"?100:o[i].reduce((A,E)=>A+E,0))*u;n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=ee(i),n.lineWidth=2,n.beginPath();for(let A=0;A<=120;A++){const E=t[0]+(t[t.length-1]-t[0])*A/120,j=Math.exp(-.5*((E-B)/F)**2)/(F*Math.sqrt(2*Math.PI)),k=w+g.frac(E)*h,ie=M+(1-f.frac(T*j))*r;A===0?n.moveTo(k,ie):n.lineTo(k,ie)}n.stroke(),n.restore()}}if(ye>=0){const u=w+Math.min(g.frac(t[ye]),g.frac(t[ye+1]))*h,i=w+Math.max(g.frac(t[ye]),g.frac(t[ye+1]))*h;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(u,M,Math.max(1,i-u),r)}}function mn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="box"&&e.type!=="bar")return;Ge($,te??0);const l=je(W),a=s.spec.orientation==="horizontal",h=e.nest?e.nest.parts.map(S=>S[S.length-1]):e.categories,r=e.categories.length,d=s.groups.length,n=S=>R.size===0||R.has(S),t=e.type==="bar"&&!!e.stack,o=(S,N)=>e.type==="bar"?Number.isFinite(e.values[S][N]):e.cells[S][N].length>0,c=Array.from({length:r},(S,N)=>Array.from({length:d},(I,D)=>D).filter(I=>n(I)&&o(I,N))),y=categoryLayout(t?c.map(S=>S.length?[0]:[]):c),x=$.getContext("2d"),g=S=>x?x.measureText(S).width:S.length*6;x&&(x.font=`${Q(-1)}px system-ui, sans-serif`);const f=(S,N)=>S.length>N?`${S.slice(0,N-1)}\u2026`:S;let p=!1,L={inner:0,outer:[]},P=0;if(a){L={inner:Math.min(200,Te(h.map(N=>g(f(N,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((N,I)=>Math.min(140,Te(e.nest.parts.map(D=>g(f(D[I],20)))))):[]},w=Math.max(Ot,30+L.inner+6+L.outer.reduce((N,I)=>N+I+10,0)),e.cumulative&&(M=Rt+18),qe=Ue;const S=Math.max(1,...c.map(N=>t?Math.min(1,N.length):N.length));P=Math.max(22,S*co/.8)}else{const S=Te(h.map(D=>g(f(D,22)))),N=Math.max(10,O.clientWidth-w-xt)/Math.max(1,r);p=S+8>N;const I=e.nest?e.nest.levels.length-1:0;qe=(p?Ue+Math.min(110,S*.72):Ue)+I*St}const b=e.type==="bar"&&!t&&!!s.spec.valueLabels,C=s.y.unit,u=S=>J(S,C),i=b?Te(e.values.flat().filter(Number.isFinite).map(S=>g(u(S))).concat(0))+8:0,v=a?i:e.cumulative?40:0,{w:B,h:F,plotW:T,plotH:A}=Ne(),E=Math.max(10,T-v),j=Xe($,W,B,F);if(!j)return;const{ctx:k}=j,ie=S=>S.filter(Number.isFinite),We=Be(s.y),De=t?e.categories.map((S,N)=>e.values.reduce((I,D,q)=>I+(n(q)&&Number.isFinite(D[N])?D[N]:0),0)):[],Le=e.type==="bar"?[...t?De:ie(e.values.flat()),0]:ie(e.cells.flat(2));k.font=`${Q(-1)}px system-ui, sans-serif`;const fe=a?i:Q(-1)+6;if(b&&!a&&Le.length){const S=Te(Le);S>0&&Le.push(S*(1+fe/Math.max(1,A-fe)))}const Ae=ue(Fe(Oe(Le,s.y),We,s.y),s.y,{floorAtZero:e.type==="bar"});Z={x:Ae,y:Ae,plotW:E,plotH:A};const st=a?A:E,Je=a&&r*P>A+.5,it=Je?r*P:st,at=Je?Math.max(0,Math.min(ot,it-st)):0;ot=at,$n(Je,it,at,E+v,A),a?fn(k,l,B,F,E,A,{labels:h,rotate:!1,nest:e.nest?.parts},L,Ae,s.x,s.y,{along:it,offset:at}):Ke(k,l,B,F,E,A,{labels:h,rotate:p,nest:e.nest?.parts},Ae,s.x,s.y);const ve=it/r,Ce=y.width*ve;ne={slotW:ve,n:r,plotW:it,layout:y,across:a,offset:at,view:st};const oe=S=>a?w+Ae.frac(S)*E:M+(1-Ae.frac(S))*A,ke=S=>a?M+S-at:w+S,At=Ae.log?a?w:M+A:oe(0),Qe=(S,N,I,D)=>a?[Math.min(I,D),ke(S),Math.max(1,Math.abs(D-I)),N-S]:[ke(S),Math.min(I,D),N-S,Math.max(1,Math.abs(D-I))],Ct=(S,N,I,D)=>{k.beginPath(),a?(k.moveTo(N,ke(S)),k.lineTo(D,ke(I))):(k.moveTo(ke(S),N),k.lineTo(ke(I),D)),k.stroke()},et=S=>a?S>=At:S<=At,Bn=S=>a?Q(-1)<=Ce+4:k.measureText(u(S)).width<=Ce+6,Gt=b&&e.values.every(S=>S.every(N=>!Number.isFinite(N)||Bn(N)));if(Gt){for(let S=0;S<d;S++)if(n(S))for(let N=0;N<r;N++){const I=y.left(N,S),D=e.values[S][N];if(I===void 0||!Number.isFinite(D))continue;const q=ke(N*ve+I*ve+Ce/2),H=k.measureText(u(D)).width,G=oe(D);a?Ye.push(et(G)?{x0:G,x1:G+H+6,y0:q-fe/2,y1:q+fe/2}:{x0:G-H-6,x1:G,y0:q-8,y1:q+8}):Ye.push(et(G)?{x0:q-H/2,x1:q+H/2,y0:G-fe,y1:G}:{x0:q-H/2,x1:q+H/2,y0:G,y1:G+fe})}}const Wn=ze(k,l.limitLine,E,A,Ae,We,s.y,a?"x":"y",{halo:l.bg}),On=Ze(k,E,A,Je);if(t){ne.stacks=[];for(let S=0;S<r;S++){const N=y.left(S,0),I=[];if(ne.stacks.push(I),N===void 0)continue;let D=0;for(let q=0;q<d;q++){const H=e.values[q][S];if(!n(q)||!Number.isFinite(H)||H<=0)continue;const G=oe(D),ae=oe(D+H);k.fillStyle=ee(q),k.globalAlpha=.9;const re=S*ve+N*ve;k.fillRect(...Qe(re+1,re+Ce-1,G,ae)),k.globalAlpha=1,I.push({g:q,p0:Math.min(G,ae),p1:Math.max(G,ae)}),D+=H}}}for(let S=0;S<d&&!t;S++){if(R.size>0&&!R.has(S))continue;const N=ee(S);for(let I=0;I<r;I++){const D=y.left(I,S);if(D===void 0)continue;const q=I*ve+D*ve;if(e.type==="bar"){const H=e.values[S][I];if(!Number.isFinite(H))continue;const G=oe(H);if(k.fillStyle=N,k.globalAlpha=.9,k.fillRect(...Qe(q+1,q+Ce-1,At,G)),k.globalAlpha=1,Gt){k.fillStyle=l.text,k.font=`${Q(-1)}px system-ui, sans-serif`;const ae=ke(q+Ce/2);a?(k.textBaseline="middle",k.textAlign=et(G)?"left":"right",k.fillText(u(H),G+(et(G)?3:-3),ae)):(k.textAlign="center",k.textBaseline=et(G)?"bottom":"top",k.fillText(u(H),ae,G+(et(G)?-2:2)))}}else{const H=e.cells[S][I];if(H.length===0)continue;const G=q+Ce/2,ae=Math.max(3,Math.min(Ce*.7,46)),re=Yt(Float64Array.from(H));if(k.strokeStyle=N,k.fillStyle=N,k.lineWidth=1.5,H.length===1){k.beginPath(),a?k.arc(oe(re.median),ke(G),3,0,Math.PI*2):k.arc(ke(G),oe(re.median),3,0,Math.PI*2),k.fill();continue}Ct(G,oe(re.min),G,oe(re.max));for(const jt of[re.min,re.max])Ct(G-ae/4,oe(jt),G+ae/4,oe(jt));k.globalAlpha=.35,k.fillRect(...Qe(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.globalAlpha=1,k.strokeRect(...Qe(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.lineWidth=2.5,Ct(G-ae/2,oe(re.median),G+ae/2,oe(re.median))}}}On(),Wn();const Xt=se?y.left(se.c,t?0:se.g):void 0;if(se&&Xt!==void 0){Je&&(k.save(),k.beginPath(),k.rect(w-1,M,E+2,A),k.clip()),k.lineWidth=1.5,k.strokeStyle=l.text;const S=se.c*ve+Xt*ve,N=t?ne.stacks?.[se.c]?.find(I=>I.g===se.g):void 0;t&&N?k.strokeRect(...Qe(S,S+Ce,N.p0,N.p1)):t||k.strokeRect(...Qe(S,S+Ce,a?w:M,a?w+E:M+A)),Je&&k.restore()}if(e.cumulative){const S=I=>a?w+I/100*E:M+(1-I/100)*A,N=(I,D)=>a?[S(D),ke((I+.5)*ve)]:[ke((I+.5)*ve),S(D)];if(k.save(),k.strokeStyle=l.text,k.fillStyle=l.text,k.lineWidth=1.5,k.beginPath(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);D===0?k.moveTo(q,H):k.lineTo(q,H)}),k.stroke(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);k.beginPath(),k.arc(q,H,2.5,0,Math.PI*2),k.fill()}),k.strokeStyle=l.border,k.lineWidth=1,k.beginPath(),a?(k.moveTo(w,M),k.lineTo(w+E,M)):(k.moveTo(w+E,M),k.lineTo(w+E,M+A)),k.stroke(),k.fillStyle=l.textMuted,k.font=`${Q(-1)}px system-ui, sans-serif`,a){k.textAlign="center",k.textBaseline="bottom";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,S(I),M-3)}else{k.textAlign="left",k.textBaseline="middle";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,w+E+4,S(I))}k.restore()}}function pn(e){const l=s?.setTests,a=l?l.labels.indexOf(e):-1;return a>=0?{test:l.tests[a]}:{}}function $t(e){if(!ne||!$)return null;const l=$.getBoundingClientRect(),a=ne.across?e.clientY-l.top-M:e.clientX-l.left-w;if(a<0||a>ne.view)return null;const h=a+ne.offset,r=Math.min(ne.n-1,Math.floor(h/ne.slotW)),d=ne.layout.groupAt(r,(h-r*ne.slotW)/ne.slotW);if(d===void 0)return null;if(!ne.stacks)return{g:d,c:r};const n=ne.across?e.clientX-l.left:e.clientY-l.top,t=ne.stacks[r]?.find(o=>n>=o.p0&&n<=o.p1);return t?{g:t.g,c:r}:null}function gn(e,l,a){let h=0,r=0,d=0;for(const o of l)o===100&&h++;if(e.failSide)for(const o of a){const c=e.failSide[o];c<0?r++:c>0&&d++}const n=o=>o.toLocaleString("en-GB"),t=r+d>0?` (${n(r)} below the low limit \xB7 ${n(d)} above the high limit)`:"";return`${n(h)} pass \xB7 ${n(l.length-h)} fail${t} \xB7 n = ${n(l.length)}`}function yn(e){const l=s,a=l.marks,h=l.level==="die"?"dies":"wafers",r=a.cells[e.g][e.c],d=a.nest?a.nest.parts[e.c]:[a.categories[e.c]],n=l.groups.length>1&&!d.includes(He(e.g))?` \xB7 ${X(He(e.g))}`:"",t=`<strong>${X(a.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(r.length===0)return`${t}no ${h}`;const c=`${r.length.toLocaleString("en-GB")} ${h}`,y=(a.categoryItems&&m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(a.categoryItems&&m.onWaferMenu?Bt:"");if(a.type==="bar"){const g=a.values[e.g][e.c],f=a.cumulative?`<br>${X(`cumulative: ${a.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${X(`${l.y.label}: ${J(g,o)}`)}<br>${X(a.passFail?gn(a.passFail,r,a.cellUnits[e.g][e.c]):c)}${f}${y}`}const x=Yt(Float64Array.from(r));return`${t}${["max","q3","median","q1","min"].map(g=>X(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[g]}: ${J(x[g],o)}`)).join("<br>")}<br>${X(c)}${y}`}function bn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="line")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Be(s.x),c=Be(s.y),y=ue(Fe(Oe(e.xs,s.x),o,s.x),s.x),x=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],g=ue(Fe(Oe([...e.values.flat(),...x].filter(Number.isFinite),s.y),c,s.y),s.y);if(Z={x:y,y:g,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,g,s.x,s.y),ze(t,l.limitLine,r,d,y,o,s.x,"x"),ze(t,l.limitLine,r,d,g,c,s.y,"y"),Ze(t,r,d),de=e.xs.map(f=>w+y.frac(f)*r),e.band){const f=p=>M+(1-g.frac(p))*d;e.band.lo.forEach((p,L)=>{if(R.size>0&&!R.has(L))return;const P=e.band.hi[L];t.save(),t.fillStyle=ee(L),t.globalAlpha=.16;let b=[];const C=()=>{if(b.length===1){const u=b[0],i=de[u];t.globalAlpha=.55,t.strokeStyle=ee(L),t.lineWidth=2,t.beginPath(),t.moveTo(i,f(p[u])),t.lineTo(i,f(P[u])),t.moveTo(i-4,f(p[u])),t.lineTo(i+4,f(p[u])),t.moveTo(i-4,f(P[u])),t.lineTo(i+4,f(P[u])),t.stroke(),t.globalAlpha=.16}else if(b.length){t.beginPath(),b.forEach((u,i)=>{i===0?t.moveTo(de[u],f(P[u])):t.lineTo(de[u],f(P[u]))});for(let u=b.length-1;u>=0;u--)t.lineTo(de[b[u]],f(p[b[u]]));t.closePath(),t.fill()}b=[]};p.forEach((u,i)=>{Number.isFinite(u)&&Number.isFinite(P[i])?b.push(i):C()}),C(),t.restore()})}e.values.forEach((f,p)=>{if(R.size>0&&!R.has(p))return;t.strokeStyle=ee(p),t.fillStyle=ee(p),t.lineWidth=2;let L=!1;t.beginPath(),f.forEach((P,b)=>{if(!Number.isFinite(P)){L=!1;return}const C=de[b],u=M+(1-g.frac(P))*d;L?t.lineTo(C,u):t.moveTo(C,u),L=!0}),t.stroke(),f.forEach((P,b)=>{Number.isFinite(P)&&(t.beginPath(),t.arc(de[b],M+(1-g.frac(P))*d,be===b?4.5:3,0,Math.PI*2),t.fill())})}),be>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(de[be],M),t.lineTo(de[be],M+d),t.stroke())}function Lt(e){const l=s?.marks;if(!l||l.type!=="line"||!$||!s?.x||de.length===0)return null;const a=e.clientX-$.getBoundingClientRect().left;let h=-1,r=24;if(de.forEach((t,o)=>{const c=Math.abs(t-a);c<r&&(r=c,h=o)}),be=h,h<0)return null;const d=s.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[h],n:l.counts[o][h]})).filter(t=>Number.isFinite(t.v)&&(R.size===0||R.has(t.g)));return`<strong>${X(`${s.x.label}: ${J(l.xs[h],s.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][h],c=l.band?.hi[t.g][h],y=o!==void 0&&c!==void 0&&Number.isFinite(o)&&Number.isFinite(c)?`, band ${J(o,s.y.unit)} to ${J(c,s.y.unit)}`:"";return X(`${s.groups.length>1?`${He(t.g)}: `:""}${J(t.v,s.y.unit)}${y} (${t.n.toLocaleString("en-GB")} ${d})`)}).join("<br>")+(m.onWaferMenu&&zt(h)!==void 0?Bt:"")}function zt(e){const l=s?.marks;if(l?.type!=="line")return;const a=new Set(l.cellUnits.flatMap((h,r)=>R.size>0&&!R.has(r)?[]:(h[e]??[]).map(d=>l.unit(d).item)));return a.size===1?[...a][0]:void 0}function xn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="probability")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=s.spec.probabilityAxis==="linear",c=e.values.map((T,A)=>A).filter(T=>e.values[T].length>0&&(R.size===0||R.has(T))),y=Math.max(1,...c.map(T=>e.values[T].length)),x=Math.min(.01,rt(0,y)),g=T=>o?T:qt(T),f=o?0:g(x),p=o?1:g(1-x),L=o?0:(p-f)*.03,P=ue([f-L,p+L],{label:s.y.label,scale:"linear",min:f-L,max:p+L}),b=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:ho.filter(T=>T>=x&&T<=1-x),C=[],u=T=>M+(1-P.frac(T))*d,i=b.indexOf(.5);C.push({at:g(.5),label:an(.5)});for(const T of[b.slice(i+1),b.slice(0,i).reverse()]){let A=u(g(.5));for(const E of T){const j=u(g(E));Math.abs(j-A)<16||(C.push({at:g(E),label:an(E)}),A=j)}}const v=Be(s.x),B=ue(Fe(Oe(c.flatMap(T=>[e.values[T][0],e.values[T][e.values[T].length-1]]),s.x),v,s.x),s.x);Z={x:B,y:P,plotW:r,plotH:d},Ke(t,l,a,h,r,d,B,P,s.x,s.y,C),ze(t,l.limitLine,r,d,B,v,s.x,"x"),Ze(t,r,d),le=[],t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();for(const T of c){const A=e.values[T],E=A.length,j=mo(E);if(t.strokeStyle=ee(T),t.fillStyle=ee(T),t.lineWidth=1.5,t.beginPath(),j.forEach((k,ie)=>{const We=w+B.frac(A[k])*r,De=u(g(rt(k,E)));ie===0?t.moveTo(We,De):t.lineTo(We,De);const Le=T*2**26+k;let fe=Mt.get(Le);if(!fe){const{item:Ae,die:st}=e.unit(e.units[T][k]);fe={x:A[k],y:rt(k,E),group:T,item:Ae,die:st},Mt.set(Le,fe)}le.push({p:fe,cx:We,cy:De})}),t.stroke(),E<=300)for(const k of j)t.beginPath(),t.arc(w+B.frac(A[k])*r,u(g(rt(k,E))),2.5,0,Math.PI*2),t.fill()}if(t.restore(),he.size>0){t.lineWidth=1.5,t.strokeStyle=l.text;let T=0;for(const A of he)if(!(R.size>0&&!R.has(A.group))){if(++T>vt)break;t.beginPath(),t.arc(w+B.frac(A.x)*r,u(g(A.y)),4,0,Math.PI*2),t.stroke()}}const F=ge?le.find(T=>T.p===ge):void 0;F&&(t.beginPath(),t.arc(F.cx,F.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function vn(e){const l=s,h=l.marks.values[e.group].length,r=Math.round(e.y*h+.5),d=m.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[d,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${X(t)}</strong><br>`:"")+X(`${l.x.label}: ${J(e.x,l.x.unit)}`)+"<br>"+X(`rank ${r.toLocaleString("en-GB")} of ${h.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(m.onWaferMenu&&!e.die?Bt:"")}let _e,xe=null;function kn(){const e=s?.marks;if(!s||!$||e?.type!=="heatmap")return;Ge($,te??0);const l=je(W),a=$.getContext("2d");let h=0,r=0;a&&(a.font=`${Q(-1)}px system-ui, sans-serif`,h=Te(e.rows.map(u=>a.measureText(u.length>24?`${u.slice(0,23)}\u2026`:u).width)),r=Te(e.cols.map(u=>a.measureText(u.length>22?`${u.slice(0,21)}\u2026`:u).width)));const d=Math.min(180,Math.max(w,h+24)),n=Math.max(8,O.clientWidth-d-xt)/Math.max(1,e.cols.length),t=r+8>n;qe=t?Ue+Math.min(110,r*.72):Ue;const{w:o,h:c}=Ne(),y=Math.max(10,o-d-xt),x=Math.max(10,c-M-qe),g=Xe($,W,o,c);if(!g)return;const{ctx:f}=g,p=y/e.cols.length,L=x/e.rows.length;_e={left:d,cw:p,ch:L,rows:e.rows.length,cols:e.cols.length};const P=s.colorScale,b=bt(s.spec.colorGradient,s.spec.colorReverse,P?.diverging,P?.rating),C=P&&P.hi-P.lo||1;f.font=`${Q(-1)}px system-ui, sans-serif`;for(let u=0;u<e.rows.length;u++)for(let i=0;i<e.cols.length;i++){const v=e.values[u][i],B=d+i*p,F=M+u*L,T=Number.isFinite(v)&&P?b((v-P.lo)/C):l.track;if(f.fillStyle=T,f.fillRect(B,F,p,L),Number.isFinite(v)&&p>=40&&L>=16){const A=ao(T);f.fillStyle=A?"#1a1a1a":"#fff",f.textAlign="center",f.textBaseline="middle",Et(f,It(v,s.y?.unit,P?.integer),B+p/2,F+L/2,A?"rgba(255,255,255,0.55)":"rgba(0,0,0,0.55)")}}f.lineWidth=1,f.setLineDash([]),f.strokeStyle=l.border,f.beginPath();for(let u=1;u<e.rows.length;u++){const i=Math.round(M+u*L)+.5;f.moveTo(d,i),f.lineTo(d+y,i)}for(let u=1;u<e.cols.length;u++){const i=Math.round(d+u*p)+.5;f.moveTo(i,M),f.lineTo(i,M+x)}f.stroke(),f.strokeStyle=l.textMuted,f.strokeRect(d+.5,M+.5,y-1,x-1),f.beginPath();for(let u=0;u<e.rows.length;u++){const i=Math.round(M+(u+.5)*L)+.5;f.moveTo(d-4,i),f.lineTo(d,i)}for(let u=0;u<e.cols.length;u++){const i=Math.round(d+(u+.5)*p)+.5;f.moveTo(i,M+x),f.lineTo(i,M+x+4)}f.stroke(),xe&&(f.lineWidth=2,f.strokeStyle=l.text,f.strokeRect(d+xe.c*p,M+xe.r*L,p,L)),f.fillStyle=l.textMuted,f.textAlign="right",f.textBaseline="middle",e.rows.forEach((u,i)=>f.fillText(u.length>24?`${u.slice(0,23)}\u2026`:u,d-8,M+(i+.5)*L)),e.cols.forEach((u,i)=>{const v=u.length>22?`${u.slice(0,21)}\u2026`:u,B=d+(i+.5)*p;t?(f.save(),f.translate(B,M+x+8),f.rotate(-Math.PI/4),f.textAlign="right",f.textBaseline="middle",f.fillText(v,0,0),f.restore()):(f.textAlign="center",f.textBaseline="top",f.fillText(v,B,M+x+7))}),f.font=`${Q(0)}px system-ui, sans-serif`,f.fillStyle=l.text,f.textAlign="center",f.textBaseline="bottom",f.fillText(s.x?.label??"",d+y/2,c-6)}function _t(e){if(!_e||!$)return null;const l=$.getBoundingClientRect(),a=Math.floor((e.clientX-l.left-_e.left)/_e.cw),h=Math.floor((e.clientY-l.top-M)/_e.ch);return h>=0&&h<_e.rows&&a>=0&&a<_e.cols?{r:h,c:a}:null}function Mn(e){const l=s,a=l.marks,h=a.values[e.r][e.c],r=a.cellUnits[e.r][e.c].length,d=l.level==="die"?"dies":"wafers";return`<strong>${X(`${a.rows[e.r]} \xB7 ${a.cols[e.c]}`)}</strong><br>`+(Number.isFinite(h)?X(`${l.y?.label??"Count"}: ${It(h,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+X(`${r.toLocaleString("en-GB")} ${d}`)+(r&&m.onSelectPoints?"<br><em>click or right-click to chart or tabulate them</em>":"")}function Tn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="control")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=e.limits,c=Be(s.y),y=ue(Oe(e.xs,s.x),s.x),x=ue(Fe(Oe([...e.values,o.ucl,o.lcl],s.y),c,s.y),s.y);Z={x:y,y:x,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,x,s.x,s.y),ze(t,l.limitLine,r,d,x,c,s.y,"y"),Ze(t,r,d);const g=i=>w+y.frac(e.xs[i])*r,f=i=>M+(1-x.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();const p=(i,v,B,F=1)=>{t.globalAlpha=B,t.setLineDash(v),t.lineWidth=F,t.strokeStyle=l.text,t.beginPath(),t.moveTo(w,f(i)),t.lineTo(w+r,f(i)),t.stroke()};for(const i of[-2,-1,1,2])p(o.centre+i*o.sigma,[2,4],.25);p(o.centre,[],.6,1.5),p(o.ucl,[6,4],.85),p(o.lcl,[6,4],.85),t.restore(),t.fillStyle=l.textMuted,t.font=`${Q(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const L=i=>J(i,s.y.unit);if(t.fillText(`UCL ${L(o.ucl)}`,w+r-4,f(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${L(o.lcl)}`,w+r-4,f(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${L(o.centre)}`,w+r-4,f(o.centre)-2),o.baseline<e.values.length){const i=(g(o.baseline-1)+g(o.baseline))/2;t.save(),t.strokeStyle=l.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(i,M),t.lineTo(i,M+d),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",w+4,M+2)}t.strokeStyle=ee(0),t.lineWidth=1.5,t.setLineDash([]);const P=R.size>0,b=i=>e.group?.[i]??0;if(!P)t.beginPath(),e.values.forEach((i,v)=>{v===0?t.moveTo(g(v),f(i)):t.lineTo(g(v),f(i))}),t.stroke();else{for(const i of[!1,!0]){t.globalAlpha=i?1:.2,t.beginPath();for(let v=1;v<e.values.length;v++)(R.has(b(v-1))&&R.has(b(v)))===i&&(t.moveTo(g(v-1),f(e.values[v-1])),t.lineTo(g(v),f(e.values[v])));t.stroke()}t.globalAlpha=1}const C=new Map(e.violations.map(i=>[i.index,i.rules]));le=[],e.values.forEach((i,v)=>{const B=C.get(v),F=b(v),T=P&&R.has(F),A=P&&!T;t.globalAlpha=A?.2:1,t.beginPath(),t.arc(g(v),f(i),(B?4.5:3)+(T?1.5:0),0,Math.PI*2),t.fillStyle=B?l.alert:ee(F),t.fill(),T&&(t.lineWidth=1.5,t.strokeStyle=l.text,t.stroke()),B&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(B.join(","),g(v),f(i)-(T?8:6))),t.globalAlpha=1,le.push({p:{x:e.xs[v],y:i,group:F,item:e.items[v]},cx:g(v),cy:f(i)})});const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function wn(e){const l=s,a=l.marks,h=a.items.indexOf(e.item),r=(e.y-a.limits.centre)/a.limits.sigma,d=a.violations.find(n=>n.index===h)?.rules;return`<strong>${X(m.waferLabel(e.item))}</strong><br>`+X(`${l.y.label}: ${J(e.y,l.y.unit)} (${r>=0?"+":"\u2212"}${Math.abs(r).toFixed(1)}\u03C3)`)+(d?`<br>${X(`breaks rule ${d.map(n=>`${n} (${In[n]})`).join(", ")}`)}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function Sn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="goal")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(i=>Math.abs(i.x))),c=ue([-o,o],{...s.x,min:s.x.min??-o*1.05,max:s.x.max??o*1.05}),y=ue([0,...e.points.map(i=>i.y),1/6],{...s.y,min:s.y.min??0},{floorAtZero:!0});Z={x:c,y,plotW:r,plotH:d},Ke(t,l,a,h,r,d,c,y,s.x,s.y);const x=i=>w+c.frac(i)*r,g=i=>M+(1-y.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip(),t.font=`${Q(-1)}px system-ui, sans-serif`;const f=[[1,[6,4]],[1.33,[]]];for(const[i,v]of f){const B=1/(6*i);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(v),t.beginPath(),t.moveTo(x(-.5),g(0)),t.lineTo(x(0),g(B)),t.lineTo(x(.5),g(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${i}`,x(0)+4,g(B)-2)}t.restore(),le=[];const p=e.points.filter(i=>R.size===0||R.has(i.group));for(const i of p)t.beginPath(),t.arc(x(i.x),g(i.y),4,0,Math.PI*2),t.fillStyle=ee(i.group),t.fill(),le.push({p:{x:i.x,y:i.y,group:i.group,item:-1,value:i.testNumber},cx:x(i.x),cy:g(i.y)});const L=p.map(i=>({x0:x(i.x)-5,x1:x(i.x)+5,y0:g(i.y)-5,y1:g(i.y)+5})),P={x0:w,x1:w+r,y0:M,y1:M+d},b=i=>i.x0>=P.x0&&i.x1<=P.x1&&i.y0>=P.y0&&i.y1<=P.y1&&!L.some(v=>i.x0<v.x1&&i.x1>v.x0&&i.y0<v.y1&&i.y1>v.y0),C=Q(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const i of[...p].filter(v=>v.ppk<1.33).sort((v,B)=>v.ppk-B.ppk)){const v=x(i.x),B=g(i.y),F=t.measureText(i.label).width,T=[[v+7,B,"left"],[v-7,B,"right"],[v,B-13,"center"],[v,B+13,"center"]];for(const[A,E,j]of T){const k=j==="left"?A:j==="right"?A-F:A-F/2,ie={x0:k,x1:k+F,y0:E-C/2,y1:E+C/2};if(b(ie)){L.push(ie),t.textAlign=j,t.fillText(i.label,A,E);break}}}const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Pn(e){const l=s,h=l.marks.points.find(r=>r.testNumber===e.value&&r.group===e.group);return h?`<strong>${X(h.label)}</strong>${l.groups.length>1?` \xB7 ${X(He(h.group))}`:""}<br>`+X(`Ppk ${h.ppk.toFixed(2)} \xB7 ${h.n.toLocaleString("en-GB")} dies`)+"<br>"+X(`mean ${h.x>=0?"+":"\u2212"}${Math.abs(h.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(h.y*100).toFixed(1)}% of it (${h.basis==="spec"?"spec":"test"} limits)`):""}function $n(e,l,a,h,r){!$e||!$||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${$.offsetTop+M}px`,height:`${r}px`,left:`${$.offsetLeft+w+h+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-a)>=1&&($e.scrollTop=a)))}function K(){$e&&($e.style.display="none"),ht&&!rn()&&(ht.style.maxHeight=en(W)?"":`${fo}px`),pe&&m.panel&&(pe.style.display=en(W)?"flex":"none"),w=Ot,M=Rt;const e=s?.marks?.type;e==="scatter"?un():e==="control"?Tn():e==="heatmap"?kn():e==="goal"?Sn():e==="probability"?xn():e==="histogram"?dn():e==="box"||e==="bar"?mn():e==="line"&&bn(),Ft()}function Ln(e){const l=s,a=m.waferLabel(e.item),h=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,h].filter(Boolean).join(" \xB7 "),d=(n,t)=>`${n.label}: ${J(t,n.unit)}`;return(r?`<strong>${X(r)}</strong><br>`:"")+X(d(l.x,e.x))+"<br>"+X(d(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${X(`${l.colorScale.label}: ${J(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function Dt(e){if(!Ee||!Z||!s?.x)return null;const l=$.getBoundingClientRect(),h=(e.clientX-l.left-w)/Z.plotW;if(h<0||h>1)return null;const r=Z.x.reverse?1-h:h,{edges:d,counts:n}=Ee,t=d.length-1,o=Math.min(t-1,Math.max(0,Math.floor(r*t)));ye=o;const c=s.x,y=n.map((x,g)=>({g,n:x[o]})).filter(x=>x.n>0&&(R.size===0||R.has(x.g)));return`<strong>${X(`${J(d[o],c.unit)} to ${J(d[o+1],c.unit)}`)}</strong><br>`+(y.length?y.map(x=>{const g=s.spec.histNorm==="percent"?` (${Ee.heights[x.g][o].toFixed(1)}% of ${s.groups.length>1?"its colour":"them"})`:"";return X(`${s.groups.length>1?`${He(x.g)}: `:""}${x.n.toLocaleString("en-GB")} ${s.level==="die"?"dies":"wafers"}${g}`)}).join("<br>"):"none")}function An(e){const l=z.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:me.md,marginTop:me.md,marginBottom:me.xl,fontSize:gt.body,color:tt.label});const a=z.createElement("canvas");a.width=200,a.height=10,Object.assign(a.style,{width:"200px",height:"10px",borderRadius:_n.control,flex:"0 0 auto"});const h=a.getContext("2d"),r=bt(s?.spec.colorGradient,s?.spec.colorReverse,e.diverging,e.rating);if(h)for(let c=0;c<200;c++)h.fillStyle=r(c/199),h.fillRect(c,0,1,10);const d=c=>s?.marks?.type==="heatmap"?It(c,e.unit,e.integer):J(c,e.unit),n=z.createElement("span");n.textContent=d(e.lo);const t=z.createElement("span");t.textContent=d(e.hi);const o=z.createElement("span");return o.textContent=e.label,o.style.color=tt.text,l.append(o,n,a,t),l}const lt=(e,l,a)=>l.map(h=>{const{item:r,die:d}=e(h);return{x:0,y:0,group:a,item:r,die:d}});function Cn(){Ve?.destroy(),Ve=void 0,O.innerHTML="",$=void 0,pe=void 0,te=void 0,nt=[],ge=null,ye=-1,le=[],Z=void 0,ne=void 0,se=null,$e=void 0,ot=0,ht=void 0,_e=void 0,xe=null,de=[],be=-1,qe=Ue,Mt=new Map,R.clear(),he.clear();for(const n of ce)n.destroy();ce=[],ft?.(),ft=void 0,O.style.overflowY="hidden",delete W.dataset.wmapPlotPanelsOwner,delete W.dataset.wmapPanelsHover,we(()=>W.querySelector("canvas"));const e=s,l=!!e?.facets&&!m.panel;if(W.style.flex=l?"0 0 auto":"1 1 0px",W.style.gridColumn=l?"1 / -1":"",!e)return;if(U.textContent=m.panel?m.panel.title:zn(e),W.dataset.wmapChartTitle=U.textContent,e.issues.length||!e.marks){for(const n of e.issues)Qt(O,n);return}const a=z.createElement("div");Object.assign(a.style,{color:tt.label,fontSize:gt.body,marginBottom:me.xs});const h=m.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(m.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${h}`:m.onSelectPoints?` \xB7 click or right-click to ${m.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&m.onSelectPoints?" \xB7 click or right-click a bar to chart or tabulate its dies":e.marks.type==="heatmap"&&m.onSelectPoints?` \xB7 click or right-click a cell to chart or tabulate its ${e.level==="die"?"dies":"wafers"}`:e.marks.type==="probability"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="line"&&m.onSelectPoints?` \xB7 click a point to ${m.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the plot to select ${m.selectRangeLabel??"a run of points"}`:"";a.textContent=m.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:Kt(e)+(e.facets?"":r),m.panel||Un(a,Vt(e)),Zt(a),te=z.createElement("div"),te.style.display="flow-root",O.appendChild(te),te.appendChild(a);for(const n of e.fitNotes??[]){const t=z.createElement("div");t.dataset.wmapPlotFit="1",t.textContent=n,Object.assign(t.style,{color:tt.text,fontSize:gt.body,marginBottom:me.xxs,fontVariantNumeric:"tabular-nums"}),te.appendChild(t)}for(const n of e.notes){const t=z.createElement("div");Zt(t),t.textContent=n,Object.assign(t.style,{color:tt.warnText,fontSize:gt.body,marginBottom:me.xs}),te.appendChild(t)}if(e.plotted===0){Qt(O,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&!e.colorRepeatsX&&(pe=z.createElement("div"),pe.dataset.wmapPlotLegend="1",Object.assign(pe.style,{display:m.panel?"none":"flex",flexWrap:"wrap",gap:me.sm,marginTop:me.md,marginBottom:me.xl,overflowY:"auto"}),ht=pe,e.facets&&Object.assign(pe.style,{position:"sticky",top:"0",zIndex:"2",background:tt.menuBg,paddingBottom:me.sm,marginBottom:me.md}),e.groups.forEach((n,t)=>{const o=Jn(n||"(none)",ee(t),z);Hn(o.el,W,_,`${n||"(none)"} \u2014 click to filter`),o.el.addEventListener("click",()=>{if(R.has(t)?R.delete(t):R.add(t),nt.forEach((c,y)=>c.setState({selected:R.has(y),dimmed:R.size>0&&!R.has(y)})),ce.length)for(const c of ce)c.setActiveGroups(R);else K()}),nt.push(o),pe.appendChild(o.el)}),nt.forEach((n,t)=>n.setState({selected:R.has(t),dimmed:R.size>0&&!R.has(t)})),te.appendChild(pe)),e.colorScale&&!m.panel&&(pe=An(e.colorScale),te.appendChild(pe)),e.facets){const n=z.createElement("div");n.dataset.wmapPlotPanels="1",n.style.isolation="isolate",Object.assign(n.style,{display:"grid",gap:me.md});const t=()=>{n.style.gridTemplateColumns=Ie?`repeat(${Ie}, minmax(0, 1fr))`:`repeat(auto-fill, minmax(${po}px, 1fr))`};t();const o=Qn("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(x=>({value:String(x),label:`${x} (${x})`}))],Ie?String(Ie):"auto",x=>{Ie=x==="auto"?void 0:Number(x),t()},{hook:"panel-columns",maxWidth:"90px",ownerDocument:z});Object.assign(o.style,{justifyContent:"flex-end",marginBottom:me.sm});const c=o.querySelector("button");O.append(o,n),O.style.overflowY="auto",W.dataset.wmapPlotPanelsOwner="1",ut&&(W.dataset.wmapPanelsHover="1");const y=x=>{if(!ut||x.ctrlKey||x.metaKey||x.altKey||x.shiftKey||x.defaultPrevented||!/^[0-5]$/.test(x.key))return;const g=x.target;typeof g?.closest=="function"&&g.closest('input, textarea, select, [contenteditable="true"], [role="menu"]')||(x.preventDefault(),Ie=x.key==="0"?void 0:Number(x.key),t(),c&&(c.value=Ie?String(Ie):"auto"))};z.addEventListener("keydown",y),ft=()=>z.removeEventListener("keydown",y);for(const x of e.facets){const g=renderPlotChart({...m,panel:{title:x.label}});n.appendChild(g.card),g.setPlot(x.plot),ce.push(g)}we(()=>go(n));return}$=z.createElement("canvas"),$.style.display="block",$.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",O.appendChild($);const d=m.onWaferMenu||m.onSelectPoints?(n,t)=>{!n.die&&m.onWaferMenu?m.onWaferMenu(n.item,pt(e.spec),t):n.die&&m.onSelectPoints&&(t.preventDefault(),m.onSelectPoints([n],{x:t.clientX,y:t.clientY},$))}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!m.onSelectPoints;Ve=Wt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:Ln,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,...kt(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:t?{pick:({x0:o,y0:c,x1:y,y1:x})=>Z?(R.size===0?n.points:n.points.filter(f=>R.has(f.group))).filter(f=>{const p=w+Z.x.frac(f.x)*Z.plotW,L=M+(1-Z.y.frac(f.y))*Z.plotH;return p>=o&&p<=y&&L>=c&&L<=x}):[],onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const n=e.marks.type==="control";Ve=Wt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:n?wn:Pn,clickable:()=>n&&!!m.onOpenWafer,onOpen:t=>{n&&m.onOpenWafer?.(t.item,...kt(e.spec))},onContextMenu:n?d:void 0,onHover:t=>{ge=t,K()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";Ve=Wt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:vn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,...kt(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:m.onSelectPoints?{pick:({x0:o,y0:c,x1:y,y1:x})=>{if(!Z)return[];const g=[];return n.values.forEach((f,p)=>{R.size>0&&!R.has(p)||f.forEach((L,P)=>{const b=rt(P,f.length),C=w+Z.x.frac(L)*Z.plotW,u=M+(1-Z.y.frac(t?b:qt(b)))*Z.plotH;if(C<o||C>y||u<c||u>x)return;const{item:i,die:v}=n.unit(n.units[p][P]);g.push({x:L,y:b,group:p,item:i,die:v})})}),g},onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="histogram"){hn(),$.addEventListener("mousemove",t=>{const o=Dt(t);if(!o){_.style.display="none",ye>=0&&(ye=-1,K());return}_.innerHTML=o,_.style.display="block",yt(_,W,t.clientX,t.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",ye>=0&&(ye=-1,K())});const n=e.marks;if(m.onSelectPoints){$.style.cursor="pointer";const t=o=>{if(!Ee||Dt(o)===null)return!1;const c=ye,{edges:y}=Ee,x=Z?.x.log,g=x?Math.log10(y[0]):y[0],f=x?Math.log10(y[y.length-1]):y[y.length-1],p=y.length-1,L=[];return n.values.forEach((P,b)=>{if(R.size>0&&!R.has(b))return;const C=[];P.forEach((u,i)=>{const v=x?u>0?Math.log10(u):NaN:u;!Number.isFinite(v)||v<g||v>f||Math.min(p-1,Math.floor((v-g)/(f-g)*p))===c&&C.push(n.units[b][i])});for(const u of lt(n.unit,C,b))L.push(u)}),L.length===0?!1:(_.style.display="none",m.onSelectPoints(L,{x:o.clientX,y:o.clientY},$,{range:{lo:y[c],hi:y[c+1]},...R.size===1?{group:e.groups[[...R][0]]}:{}}),!0)};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}}else if(e.marks.type==="heatmap"){const n=e.marks;$.addEventListener("mousemove",o=>{const c=_t(o);if($.style.cursor=c&&m.onSelectPoints&&n.cellUnits[c.r][c.c].length?"pointer":"default",!c){_.style.display="none",xe&&(xe=null,K());return}_.innerHTML=Mn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!xe||xe.r!==c.r||xe.c!==c.c)&&(xe=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",xe&&(xe=null,K())});const t=o=>{const c=_t(o);if(!c||!m.onSelectPoints)return!1;const y=n.cellUnits[c.r][c.c];return y.length?(_.style.display="none",m.onSelectPoints(lt(n.unit,y,0),{x:o.clientX,y:o.clientY},$,{cell:{row:n.rows[c.r],column:n.cols[c.c]}}),!0):!1};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const o=z.createElement("div");o.dataset.wmapRowScroll="1",o.tabIndex=0,o.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(o.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const c=z.createElement("div");c.style.width="1px",o.appendChild(c),o.addEventListener("scroll",()=>{Math.abs(o.scrollTop-ot)<1||(ot=o.scrollTop,_.style.display="none",K())}),$.addEventListener("wheel",y=>{if(o.style.display==="none")return;const x=o.scrollTop;o.scrollTop+=y.deltaMode===1?y.deltaY*16:y.deltaY,o.scrollTop!==x&&y.preventDefault()},{passive:!1}),O.appendChild(o),$e=o}$.addEventListener("mousemove",o=>{const c=$t(o);if($.style.cursor=c&&(n.categoryItems&&m.onOpenWafer||m.onSelectPoints&&n.cellUnits[c.g][c.c].length>0)?"pointer":"default",!c){_.style.display="none",se&&(se=null,K());return}_.innerHTML=yn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!se||se.g!==c.g||se.c!==c.c)&&(se=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",se&&(se=null,K())});const t=(o,c)=>{const y=n.cellUnits[c.g][c.c];return y.length===0||!m.onSelectPoints?!1:(_.style.display="none",m.onSelectPoints(lt(n.unit,y,c.g),{x:o.clientX,y:o.clientY},$,{category:n.categories[c.c],...e.groups.length>1?{group:e.groups[c.g]}:{},...pn(n.categories[c.c])}),!0)};$.addEventListener("contextmenu",o=>{const c=$t(o);if(!c)return;const y=n.categoryItems?.[c.c];y!==void 0&&y>=0&&m.onWaferMenu?(_.style.display="none",m.onWaferMenu(y,pt(e.spec),o)):t(o,c)&&o.preventDefault()}),$.addEventListener("click",o=>{const c=$t(o);if(!c)return;const y=n.categoryItems?.[c.c];if(y!==void 0&&y>=0&&m.onOpenWafer){m.onOpenWafer(y,...kt(e.spec));return}t(o,c)})}else if(e.marks.type==="line"){$.addEventListener("mousemove",o=>{const c=Lt(o);if(!c){_.style.display="none",K();return}_.innerHTML=c,_.style.display="block",yt(_,W,o.clientX,o.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",be>=0&&(be=-1,K())});const n=e.marks,t=()=>n.cellUnits.flatMap((o,c)=>R.size>0&&!R.has(c)?[]:lt(n.unit,o[be]??[],c));if((m.onWaferMenu||m.onSelectPoints)&&$.addEventListener("contextmenu",o=>{if(Lt(o)===null||be<0)return;const c=zt(be);if(c!==void 0&&m.onWaferMenu)_.style.display="none",m.onWaferMenu(c,pt(e.spec),o);else if(m.onSelectPoints){const y=t();y.length>0&&(o.preventDefault(),_.style.display="none",m.onSelectPoints(y,{x:o.clientX,y:o.clientY},$))}}),m.onSelectPoints){$.style.cursor="pointer";let o=!1;$.addEventListener("mousedown",c=>{if(c.button!==0)return;o=!1;const y=$.getBoundingClientRect(),x=c.clientX-y.left,g=f=>{z.removeEventListener("mouseup",g);const p=f.clientX-y.left;if(Math.abs(p-x)<4)return;o=!0;const[L,P]=x<p?[x,p]:[p,x],b=de.map((u,i)=>u>=L&&u<=P?i:-1).filter(u=>u>=0),C=n.cellUnits.flatMap((u,i)=>R.size>0&&!R.has(i)?[]:b.flatMap(v=>lt(n.unit,u[v]??[],i)));C.length>0&&(_.style.display="none",m.onSelectPoints(C,{x:f.clientX,y:f.clientY},$))};z.addEventListener("mouseup",g)}),$.addEventListener("click",c=>{if(o){o=!1;return}if(Lt(c)===null||be<0)return;const y=t();y.length>0&&(_.style.display="none",m.onSelectPoints(y,{x:c.clientX,y:c.clientY},$))})}}K()}V(()=>{const e=s;if(!e||!e.marks)return;const l=bt(e.spec.colorGradient,e.spec.colorReverse,e.colorScale?.diverging,e.colorScale?.rating);return{caption:[Kt(e),...e.fitNotes??[],...e.notes,...so(Vt(e))],legend:e.groups.length>1&&!e.colorRepeatsX?e.groups.map((a,h)=>({label:a||"(none)",color:ee(h)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:J(e.colorScale.lo,e.colorScale.unit),hi:J(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const En=Yn(W,()=>K());return{card:W,actions:Y,setPlot(e){s=e,Me(ro(e.spec)),Cn()},setMenuRows(e){Re=e},setActiveGroups(e){R.clear();for(const l of e)R.add(l);nt.forEach((l,a)=>l.setState({selected:R.has(a),dimmed:R.size>0&&!R.has(a)})),K()},destroy(){ft?.(),En.disconnect(),Ve?.destroy();for(const e of ce)e.destroy()}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildSweepData as
|
|
1
|
+
import{buildSweepData as he,sweepAppliesTo as me}from"../../stats/sweep.js";import{fmt as D}from"../../renderer/fmt.js";import{SPACE as oe,fontPx as xe,FONT as ie,CLR as Y,ALPHA as ge}from"../toolbar.js";import{categorical as be}from"./palette.js";import{cardShell as ye,observeResize as $e,makeTooltip as ve,positionChartTooltip as Te,renderEmptyState as re,chartFillHeight as Se,populationPhrase as Le,PADDING as J,prepareCanvas as Me,makeAxisFormat as we,VERTICAL_TICK_SPACING_PX as Pe}from"./chartShell.js";import{fitTicks as ke}from"../../renderer/axisTicks.js";import{escHtml as x}from"../../core/utils.js";import{unmarkedLabel as Ae,derivedTestNote as Ee,DERIVED_MARK as Q,DERIVED_KEY as Ce}from"../../renderer/testLabel.js";import{plotAbout as Ie}from"./cardAbout.js";function N(p,g){return g?D(p,g).replace(/(\.\d*?)0+(?=\D|$)/,"$1").replace(/\.(?=\D|$)/,""):Number.isInteger(p)?String(p):String(Number(p.toPrecision(3)))}function le(p){const g=Ae(p.label),C=g.length>9?`${g.slice(0,8)}\u2026`:g;return p.derived?`${Q} ${C}`:C}const ae=260,De=62,Ne=56,He=3;function Be(p,g){const C=p.series[0]?.points[0]?.testNumber;return C===void 0?void 0:g?.find(j=>j.testNumber===C)?.unit}export function renderSweepPanel(p){const{testDefs:g,onSaveImage:C,population:j}=p;let v=p.spec,z=p.dies;const{card:$,body:M,heading:ce,controlsRow:fe,setAbout:pe}=ye(v.title,C,p.ownerDocument);pe(Ie({id:v.id,chart:"sweep"})),$.style.alignSelf="start";const V=$.ownerDocument,H=V.createElement("div");H.dataset.wmapCaption="1",Object.assign(H.style,{color:Y.label,fontSize:ie.body,marginBottom:oe.sm}),$.insertBefore(H,M);const U=V.createElement("div");Object.assign(U.style,{color:Y.label,fontSize:ie.body,marginTop:oe.sm}),$.appendChild(U);const w=ve($);let W=null,L=null,T;const X=n=>v.series[n]?.color??be(n);function K(){if(M.innerHTML="",U.innerHTML="",W?.disconnect(),W=null,v.series.length===0){H.textContent="",re(M,"This sweep defines no series.");return}if(L=he(z,g,v),T=Be(L,g),L.series.filter(o=>o.points.some(a=>a.count>0)).length===0){H.textContent="",re(M,me(v,g)?"No values recorded for the tests in this sweep.":"None of this sweep\u2019s tests are in this data \u2014 it may belong to another test program."),Z();return}H.textContent=`Line = median across ${Le(L.dieCount,z.length,j)}, band = p10\u2013p90`+(v.series.length>2?" \xB7 crossing and separation measured between the first two series":"")+(p.onSelectPoint?" \xB7 click a level to chart or tabulate the dies measured there":"");const c=V.createElement("canvas");c.style.display="block",M.appendChild(c);let i=null;const P=()=>{const o=L;if(o===null)return;const a=Math.max(1,M.clientWidth),d=Math.max(ae,Se($,M,c,ae)),b=Me(c,$,a,d);if(!b)return;const{ctx:e,theme:f}=b,y=t=>o.xScale==="log"?Math.log10(t):t;let l=1/0,s=-1/0,h=1/0,m=-1/0;for(const t of o.series)for(const r of t.points)r.count!==0&&(l=Math.min(l,r.p10),s=Math.max(s,r.p90),h=Math.min(h,y(r.x)),m=Math.max(m,y(r.x)));for(const t of o.separations)l=Math.min(l,t.y),s=Math.max(s,t.y);if(!Number.isFinite(l)||!Number.isFinite(s))return;l===s&&(l-=1,s+=1);const ee=(s-l)*.08;if(l-=ee,s+=ee,h===m&&(h-=.5,m+=.5),o.xScale==="log"){const t=(m-h)*.03;h-=t,m+=t}e.font=`${xe(-1)}px system-ui, sans-serif`;const S=J+De,B=a-J-8,_=J,k=d-Ne,A=t=>k-(t-l)/(s-l)*(k-_),R=t=>S+(y(t)-h)/(m-h)*(B-S);i={left:S,right:B,xLo:h,xHi:m,yOf:A,ax:y},e.strokeStyle=f.border,e.lineWidth=1,e.beginPath(),e.moveTo(S,_),e.lineTo(S,k),e.lineTo(B,k),e.stroke(),e.fillStyle=f.text,e.textAlign="right",e.textBaseline="middle";const te=ke(l,s,k-_,()=>Pe),de=we(Math.max(Math.abs(l),Math.abs(s)),T,te.step||void 0);for(const t of te.ticks)e.fillText(de.tickWithUnit(t),S-6,A(t));for(const t of o.separations){const r=A(t.y);e.save(),e.strokeStyle=f.limitLine,e.globalAlpha=.55,e.setLineDash([4,3]),e.beginPath(),e.moveTo(S,r),e.lineTo(B,r),e.stroke(),e.restore()}if(o.series.forEach((t,r)=>{const E=t.points.filter(u=>u.count>0);if(!(E.length<2)){e.save(),e.fillStyle=X(r),e.globalAlpha=.14,e.beginPath(),E.forEach((u,I)=>{const O=R(u.x),se=A(u.p90);I===0?e.moveTo(O,se):e.lineTo(O,se)});for(let u=E.length-1;u>=0;u--){const I=E[u];e.lineTo(R(I.x),A(I.p10))}e.closePath(),e.fill(),e.restore()}}),o.series.forEach((t,r)=>{e.strokeStyle=X(r),e.lineWidth=1.75,e.beginPath();let E=!1;for(const u of t.points){if(u.count===0){E=!1;continue}const I=R(u.x),O=A(u.median);E?e.lineTo(I,O):e.moveTo(I,O),E=!0}e.stroke(),e.fillStyle=X(r);for(const u of t.points)u.count!==0&&(e.beginPath(),e.arc(R(u.x),A(u.median),He,0,Math.PI*2),e.fill())}),o.crossing){const t=R(o.crossing.x),r=A(o.crossing.y);e.save(),e.strokeStyle=f.text,e.globalAlpha=.45,e.setLineDash([3,3]),e.beginPath(),e.moveTo(t,r),e.lineTo(t,k),e.stroke(),e.restore(),e.save(),e.strokeStyle=f.text,e.lineWidth=2,e.beginPath(),e.arc(t,r,5.5,0,Math.PI*2),e.stroke(),e.restore()}e.fillStyle=f.text,e.textBaseline="top",e.textAlign="center";const G=o.xIsPhysical?[...new Set(o.series.flatMap(t=>t.points.map(r=>r.x)))].sort((t,r)=>t-r).map(t=>({x:t,label:N(t,o.xUnit)})):(o.series[0]?.points??[]).map(t=>({x:t.x,label:le(t)})),ue=Math.max(1,Math.ceil(G.length*46/Math.max(1,B-S)));G.forEach((t,r)=>{r%ue!==0&&r!==G.length-1||e.fillText(t.label,R(t.x),k+6)}),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.textAlign="center",e.textBaseline="bottom",e.fillText(o.xLabel,(S+B)/2,d-4),e.restore(),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.translate(12,(_+k)/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(o.yLabel+(T?` (${T})`:""),0,0),e.restore(),e.textAlign="left",e.textBaseline="middle";let F=S+4;const ne=_+8;o.series.forEach((t,r)=>{e.fillStyle=X(r),e.fillRect(F,ne-4,10,3),F+=14,e.fillStyle=f.text,e.fillText(t.label,F,ne),F+=e.measureText(t.label).width+16})};P(),W=$e(M,P);const q=o=>{const a=L;if(a===null||i===null)return null;const d=o.clientX-c.getBoundingClientRect().left,b=i.xLo+(d-i.left)/Math.max(1,i.right-i.left)*(i.xHi-i.xLo);let e=null;for(const f of a.series)for(const y of f.points){if(y.count===0)continue;const l=Math.abs(i.ax(y.x)-b);(e===null||l<e.dist)&&(e={x:y.x,dist:l})}return e===null?null:e.x};if(c.addEventListener("mousemove",o=>{const a=L,d=q(o);if(a===null||d===null){w.style.display="none";return}const b={x:d},e=a.series.map(s=>s.points.find(h=>h.x===b.x&&h.count>0)),f=a.series.map((s,h)=>{const m=e[h];return m===void 0?"":`<span style="color:${X(h)}">\u25A0</span> ${m.derived?`${Q} `:""}${x(s.label)}: <strong>${x(D(m.median,T))}</strong><br><span style="opacity:${ge.muted}">p10 ${x(D(m.p10,T))} \u2013 p90 ${x(D(m.p90,T))} \xB7 n=${m.count.toLocaleString()}</span>`}).filter(Boolean);if(f.length===0){w.style.display="none";return}const y=a.series.flatMap(s=>s.points).find(s=>s.x===b.x&&s.count>0),l=[...new Set(e.map(s=>Ee(s)).filter(s=>s!==void 0))];w.innerHTML=`<strong>${x(y?.label??"")}</strong><br>`+f.join("<br>")+l.map(s=>`<br><em>${x(s)}</em>`).join(""),w.style.display="block",Te(w,$,o.clientX,o.clientY)}),c.addEventListener("mouseleave",()=>{w.style.display="none"}),p.onSelectPoint){c.style.cursor="pointer";const o=a=>{const d=L,b=q(a);if(d===null||b===null)return!1;const e=d.series.flatMap(l=>l.points.filter(s=>s.x===b&&s.count>0));if(e.length===0)return!1;w.style.display="none";const f=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(d.xLabel),y=d.xIsPhysical?d.xUnit||!f?`${d.xLabel} ${N(b,d.xUnit)}`:`${f[1]} ${N(b)} ${f[2]}`:le(e[0]);return p.onSelectPoint({testNumbers:e.map(l=>l.testNumber),label:y},a),!0};c.addEventListener("click",a=>{o(a)}),c.addEventListener("contextmenu",a=>{o(a)&&a.preventDefault()})}Z()}function Z(){const n=L;if(n===null)return;const c=[];n.notMeasured!==void 0?c.push(`<strong>Crossing and widths:</strong> not measured \u2014 ${x(n.notMeasured)}`):n.crossing?c.push(`<strong>Crossing:</strong> ${x(`${n.xLabel} = ${N(n.crossing.x,n.xUnit)}`)} \xB7 ${x(`${n.yLabel} ${D(n.crossing.y,T)}`)}`+(n.crossing.multiple?" <em>(first of several \u2014 the curves cross more than once)</em>":"")):(v.crossing??!0)&&v.series.length>=2&&c.push("<strong>Crossing:</strong> the first two series do not cross over the swept range");for(const i of n.separations)if(i.distance!==null){const P=i.ratio!==void 0&&i.from!==void 0&&i.to!==void 0?`\xD7${Number(i.ratio.toPrecision(3))} on the ${n.xLabel} axis (${N(i.from,n.xUnit)} \u2192 ${N(i.to,n.xUnit)})`:`${N(i.distance,n.xUnit)} on the ${n.xLabel} axis`;c.push(`<strong>Width at ${x(D(i.y,T))}:</strong> ${x(P)}`)}else{const P=i.reason==="second-series-never-reaches"?n.series[1]?.label:n.series[0]?.label;c.push(`<strong>Width at ${x(D(i.y,T))}:</strong> not measurable \u2014 ${x(P??"a series")} never reaches this level`)}n.series.some(i=>i.points.some(P=>P.derived))&&c.push(`${Q} ${x(Ce)} \u2014 hover a point for the expression`);for(const i of n.warnings)c.push(`<span style="color:${Y.errText}">${x(i)}</span>`);U.innerHTML=c.join("<br>")}return K(),{card:$,destroy:()=>{W?.disconnect(),w.remove(),$.remove()},setDies:n=>{z=n,K()},setSpec:n=>{v=n,ce.textContent=n.title,$.dataset.wmapChartTitle=n.title,K()},actions:fe}}
|
|
@@ -61,10 +61,16 @@ export interface DataSectionDeps {
|
|
|
61
61
|
metadataFields?: MetadataFieldDef[];
|
|
62
62
|
/** The host's own wafer attributes (`attributes` on the render options): the Wafers table names its columns by them. */
|
|
63
63
|
attributes?: Record<string, FacetCuration>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A die row was clicked: show that die on its wafer's map, on the test whose column was clicked (none for another
|
|
66
|
+
* column). When set, Dies rows are clickable and say so.
|
|
67
|
+
*/
|
|
68
|
+
onLocateDie?: (die: Die, waferIndex: number | undefined, testNumber?: number) => void;
|
|
69
|
+
/**
|
|
70
|
+
* A wafer row was clicked: open that wafer, on the test whose mean column was clicked, or on its bins for its yield.
|
|
71
|
+
* When set, Wafers rows are clickable and say so.
|
|
72
|
+
*/
|
|
73
|
+
onOpenWafer?: (waferIndex: number, label: string, testNumber?: number, view?: 'bins') => void;
|
|
68
74
|
/** Set when the tables describe part of a population (a drilldown selection): what to say after the
|
|
69
75
|
* counts ("selected on W03"), and a wafer column and file-name tag so a file says so too. */
|
|
70
76
|
population?: {
|
|
@@ -106,8 +112,8 @@ export interface DataTablesInput {
|
|
|
106
112
|
metadataFields?: MetadataFieldDef[];
|
|
107
113
|
/** The host's own wafer attributes, for the Wafers table's column names. */
|
|
108
114
|
attributes?: Record<string, FacetCuration>;
|
|
109
|
-
/** A die row clicked: show that die on its map. The caller closes the table around it. */
|
|
110
|
-
onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
|
|
115
|
+
/** A die row clicked: show that die on its map, on the test whose column was clicked. The caller closes the table around it. */
|
|
116
|
+
onLocateDie?: (die: Die, waferIndex: number | undefined, testNumber?: number) => void;
|
|
111
117
|
dieListOptions?: DieListDisplayOptions;
|
|
112
118
|
onSaveText?: SaveTextHandler;
|
|
113
119
|
}
|