@wafertools/wafermap 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/README.md +21 -13
- package/dist/packages/canvas-adapter/cellShade.d.ts +21 -0
- package/dist/packages/canvas-adapter/cellShade.js +1 -0
- package/dist/packages/canvas-adapter/chartPopulation.d.ts +8 -3
- package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +45 -19
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/commonality.js +1 -1
- package/dist/packages/canvas-adapter/charts/correlation.d.ts +11 -0
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +23 -0
- package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -0
- package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
- package/dist/packages/canvas-adapter/charts/palette.d.ts +10 -3
- package/dist/packages/canvas-adapter/charts/palette.js +1 -1
- package/dist/packages/canvas-adapter/charts/plotChart.d.ts +3 -7
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +1 -0
- package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.d.ts +5 -0
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/filterJson.d.ts +25 -0
- package/dist/packages/canvas-adapter/filterJson.js +5 -0
- package/dist/packages/canvas-adapter/index.d.ts +1 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/pageFilter.js +2 -2
- package/dist/packages/canvas-adapter/pinnedTests.d.ts +10 -0
- package/dist/packages/canvas-adapter/pinnedTests.js +1 -0
- package/dist/packages/canvas-adapter/plotCard.d.ts +1 -1
- package/dist/packages/canvas-adapter/plotCard.js +1 -1
- package/dist/packages/canvas-adapter/plotEditor.js +10 -1
- package/dist/packages/canvas-adapter/plotJsonComplete.d.ts +46 -0
- package/dist/packages/canvas-adapter/plotJsonComplete.js +4 -0
- package/dist/packages/canvas-adapter/plotJsonHistory.d.ts +12 -0
- package/dist/packages/canvas-adapter/plotJsonHistory.js +1 -0
- package/dist/packages/canvas-adapter/plotJsonSuggest.d.ts +16 -0
- package/dist/packages/canvas-adapter/plotJsonSuggest.js +1 -0
- package/dist/packages/canvas-adapter/plotModal.js +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 +3 -3
- 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 +68 -33
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
- package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -0
- package/dist/packages/canvas-adapter/virtualTable.js +1 -1
- package/dist/packages/core/utils.d.ts +6 -0
- package/dist/packages/core/utils.js +1 -1
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/derivedTests/apply.d.ts +10 -0
- package/dist/packages/renderer/derivedTests/apply.js +1 -1
- package/dist/packages/renderer/derivedTests/check.d.ts +35 -0
- package/dist/packages/renderer/derivedTests/check.js +1 -0
- package/dist/packages/renderer/fmt.d.ts +5 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +2 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/chartCatalogue.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/coFailure.d.ts +11 -0
- package/dist/packages/stats/coFailure.js +1 -0
- package/dist/packages/stats/correlation.d.ts +7 -0
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/differenceMap.d.ts +2 -0
- package/dist/packages/stats/differenceMap.js +1 -1
- package/dist/packages/stats/plotData.d.ts +18 -2
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/plotSpec.d.ts +31 -2
- package/dist/packages/stats/plotSpec.js +4 -4
- package/dist/packages/stats/plotTable.d.ts +18 -0
- package/dist/packages/stats/plotTable.js +1 -0
- package/dist/packages/stats/reportHtml.js +33 -29
- package/dist/packages/stats/synthesis.d.ts +7 -1
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/testsByWafer.d.ts +11 -0
- package/dist/packages/stats/testsByWafer.js +1 -0
- package/package.json +8 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
import{rankCommonality as
|
|
1
|
+
import{rankCommonality as O,measureLabel as B}from"../../stats/commonality.js";import{formatP as b}from"../../stats/groupCompare.js";import{CLR as u,FONT as j,SPACE as p,controlStyle as T,wireControlHover as F,wireTooltip as C}from"../toolbar.js";import{shortfallShade as G}from"../cellShade.js";import{cardShell as R,firstRowsToggle as q,guideCite as I,renderEmptyState as D}from"./chartShell.js";import{GUIDE_SECTIONS as L}from"../../stats/guideSections.js";import{cardAbout as P}from"./cardAbout.js";const S=8;export function renderCommonalityPanel(l){const r=l.ownerDocument??document,{card:d,body:g,setAbout:v}=R("What divides yield",void 0,r);v(P("commonality")),d.dataset.wmapCommonality="1",d.style.gridColumn="1 / -1",d.style.flex="0 0 auto";const s=O(l.wafers,l.fields,l.curation);if(l.fields.length===0||s.rows.length===0)return D(g,l.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:d,destroy:()=>{}};const f=r.createElement("div"),w=[`Every wafer field, compared for yield and for the ${s.bins.length} most common fail bin${s.bins.length===1?"":"s"}, with each wafer as one value. Ranked by q (Welch's p adjusted for the ${s.rows.length} comparisons). A low q says the groups differ by more than wafer-to-wafer noise; it does not say why.`];s.confounded.length&&w.push(`These fields group the wafers identically, so the wafers cannot tell them apart: ${s.confounded.map(([n,e])=>`${n.label} and ${e.label}`).join("; ")}.`),s.untestable.length&&w.push(`Not compared, with no two groups of two or more wafers: ${s.untestable.map(n=>n.label).join(", ")}.`),f.textContent=w.join(" ")+" ",f.append(I(r,L.dividesYield),"."),Object.assign(f.style,{color:u.label,fontSize:j.body,marginBottom:p.sm}),g.appendChild(f);const c=r.createElement("table");Object.assign(c.style,{borderCollapse:"collapse",width:"100%",fontSize:j.body,fontVariantNumeric:"tabular-nums"});const $=r.createElement("tr"),i=(n,e,o="right")=>{const t=r.createElement("th");t.scope="col",t.textContent=n,e&&C(t,e),Object.assign(t.style,{textAlign:o,padding:`${p.xs} ${p.sm}`,borderBottom:`1px solid ${u.menuBorder}`,color:u.label,fontWeight:"600",whiteSpace:"nowrap"}),$.appendChild(t)};i("Field",void 0,"left"),i("Measure","Yield, or a fail bin\u2019s share of the judged dies","left"),i("Worst group","The group with the lowest yield, or the highest rate of the bin: its mean over its wafers","left"),i("Best group",void 0,"left"),i("Spread","Worst to best, in percentage points"),i("Welch p","Do the groups\u2019 wafer means differ? Welch\u2019s ANOVA, or Welch\u2019s t for two groups"),i("Rank p","The same question on ranks (Kruskal\u2013Wallis)"),i("q","Welch p adjusted for every comparison in the table (Benjamini\u2013Hochberg)"),i("");const k=r.createElement("thead");k.appendChild($),c.appendChild(k);const y=r.createElement("tbody");c.appendChild(y);const a=(n,e,o={})=>{const t=r.createElement("td");typeof e=="string"?t.textContent=e:t.appendChild(e),o.title&&C(t,o.title),o.shade&&(t.style.background=o.shade),Object.assign(t.style,{padding:`${p.xs} ${p.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${u.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400"}),n.appendChild(t)},x=n=>`${n.toFixed(1)}%`,E=(n,e)=>e.comparison.groups.find(o=>o.key===n)?.n??0,N=n=>{if(n.measure.kind!=="yield")return;const e=n.comparison.groups.filter(t=>Number.isFinite(t.mean)&&t.n>0),o=e.reduce((t,h)=>t+h.n,0);return o>0?G(n.worst.mean-e.reduce((t,h)=>t+h.mean*h.n,0)/o):void 0};function W(n){y.replaceChildren();for(const e of n?s.rows:s.rows.slice(0,S)){const o=r.createElement("tr");if(a(o,e.field.label,{align:"left"}),a(o,B(e.measure),{align:"left"}),a(o,`${e.worst.key}: ${x(e.worst.mean)} (${E(e.worst.key,e)} wafers)`,{align:"left",shade:N(e)}),a(o,`${e.best.key}: ${x(e.best.mean)} (${E(e.best.key,e)} wafers)`,{align:"left"}),a(o,`${e.spread.toFixed(1)} pts`),a(o,b(e.comparison.welch?.p??NaN),{title:e.comparison.issue}),a(o,`${b(e.comparison.kruskal?.p??NaN)}${e.comparison.kruskal?.approximate?"*":""}`,{title:e.comparison.kruskal?.approximate?"Approximate: fewer than five wafers in a group":void 0}),a(o,b(e.pAdjusted),{strong:e.pAdjusted<.05}),e.field.key===l.groupedBy)a(o,"Grouped by this",{align:"left"});else{const t=r.createElement("button");t.type="button",t.textContent="Group by",t.dataset.wmapCommonalityGroup=e.field.key,C(t,`Group Insights by ${e.field.label}, so every chart compares its groups`),Object.assign(t.style,T("outlined")),F(t),t.addEventListener("click",()=>l.onGroupBy(e.field.key)),a(o,t,{align:"left"})}y.appendChild(o)}}const m=r.createElement("div");Object.assign(m.style,{overflowX:"auto"}),m.appendChild(c);const A=q(r,{total:s.rows.length,first:S,noun:"rows",scroller:m,fill:W});return g.append(m,A),{card:d,destroy:()=>{}}}
|
|
@@ -23,6 +23,17 @@ export interface CorrelationPanelOptions {
|
|
|
23
23
|
*/
|
|
24
24
|
/** Clicking a non-diagonal cell calls this — the Analysis tab wires it to drive the scatter panel's X/Y in place. */
|
|
25
25
|
onSelectPair?: (xTestNumber: number, yTestNumber: number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* With Group by on (two groups or more), the groups' wafers: the matrix then offers **Within groups**, the correlation
|
|
28
|
+
* left once each group's mean is taken off every test. Not a restriction to one group (see above): the choice is how
|
|
29
|
+
* the same wafers are correlated.
|
|
30
|
+
*/
|
|
31
|
+
groups?: ReadonlyArray<{
|
|
32
|
+
key: string;
|
|
33
|
+
items: CorrelationItem[];
|
|
34
|
+
}>;
|
|
35
|
+
/** The field the groups are values of, for the choice's label. */
|
|
36
|
+
groupLabelText?: string;
|
|
26
37
|
/** Document to build this panel's DOM into. Default `document` — pass the
|
|
27
38
|
* host's own `ownerDocument` when the container might live in a
|
|
28
39
|
* different document (e.g. a gallery card detached into its own popup
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildCorrelationMatrix as It,filterCorrelationMatrix as Tt,correlationSampleNote as St}from"../../stats/correlation.js";import{maxOf as Dt}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Rt}from"../../stats/facets.js";import{wireControlHover as At,wireTooltip as ut,controlStyle as kt,SPACE as L,RADIUS as lt,fontPx as ft,FONT as j,CLR as b}from"../toolbar.js";import{exportCsv as _t}from"../tableExport.js";import{attachChartTip as Bt,cardShell as Nt,setChartGrow as Ot,isExpandedCard as Wt,bodyRoom as Ht,observeResize as Xt,makeTooltip as jt,positionChartTooltip as Vt,makeWaferSelect as zt,renderEmptyState as Ft,resolveChartCanvasColors as Pt,prepareCanvas as Yt,chartDpr as pt}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as bt,DERIVED_MARK as Gt,DERIVED_KEY as Ut}from"../../renderer/testLabel.js";import{cardAbout as Kt}from"./cardAbout.js";const it=5,at=100,gt=20;function q(g){const d=g.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=g.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function qt(g){const d=q(g);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(g,d,h){const O=q(g);if(!O)return g;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(g){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=g,{card:l,body:$,controlsRow:Q,setPngDecor:wt,setAbout:Ct}=Nt(d,J,g.ownerDocument);Ct(Kt("correlation")),wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Ot(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=gt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",ut(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:b.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:b.menuBg,color:b.value,border:`1px solid ${b.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||gt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(zt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Mt(){return V!==null?h[V]?[h[V]]:[]:h}if(g.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",ut(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...kt("outlined"),color:b.text}),At(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),u=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&u.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}_t([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${bt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${bt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],u,"test-correlation.csv",g.onSaveText)}),Q.appendChild(e)}const _=l.ownerDocument.createElement("div");Object.assign(_.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(_,$);const I=jt(l);Bt(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Et(e,o,m,u,s,a,y,x){_.innerHTML="";const T=St(y);if(T){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=y.sample?`${T} \u2014 r is an estimate, not the whole population.`:`${T}.`,Object.assign(f.style,{color:b.label,fontSize:j.body}),_.appendChild(f)}if(s.length>0){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(f.style,{color:b.warnText,background:b.warnBg,border:`1px solid ${b.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),_.appendChild(f)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:b.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Gt} ${Ut} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const S=l.ownerDocument.createElement("span");S.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${b.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${b.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(S,P,z),C.appendChild(i),_.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:b.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=u?`No significant correlations found \u2014 strongest pair: ${u.xLabel} \u2194 ${u.yLabel} (r = ${u.r.toFixed(2)})`:"No significant correlations found";else{const f=[];e>0&&f.push(`${e} strong (|r| \u2265 0.7)`),o>0&&f.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=f.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}_.appendChild(v)}function vt(e){if($.innerHTML="",e.tests.length<2)return Ft($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,u=r=>r.label.split(" (#")[0],s=Math.min(14,Dt(e.tests.map(r=>u(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,T=14,C=28,B=44;let i=-1,S=-1;const P=96;function z(r){const c=Math.max(0,r-a),p=Math.floor(c/m);if(!Wt(l))return Math.max(T,Math.min(B,p));const n=Math.floor((Ht(l,$,o)-x-4)/m);return Math.max(T,Math.min(P,p,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function f(){const r=Pt(l),c=q(r.bg)??[255,255,255],p=$.clientWidth,n=z(p),X=n*m,D=x+n*m+4,R=a+X,A=Yt(o,l,R,D);if(!A)return;const{ctx:t}=A;t.font=`${ft(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((k,w)=>{const M=u(k),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((k,w)=>{const M=u(k),N=x+w*n,et=N+n/2;t.font=`${ft(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===S?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,$t=nt===i&&w===S,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=qt(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),$t&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let k=0;k<=m;k++){const w=a+k*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+k*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),p=$.clientWidth,n=z(p),X=(r.clientX-c.left)*(o.width/pt(o)/c.width),D=(r.clientY-c.top)*(o.height/pt(o)/c.height),R=Math.floor((X-a)/n),A=Math.floor((D-x)/n);return R>=0&&R<m&&A>=0&&A<m?{xi:R,yi:A}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:p,yi:n}=c,X=p===n;o.style.cursor=X||!W?"default":"pointer";const D=e.cells.find(t=>t.xIndex===p&&t.yIndex===n),R=e.tests[p].label,A=e.tests[n].label;X?I.innerHTML=`<strong>${K(R)}</strong>`:D?.r!==null&&D?.r!==void 0?I.innerHTML=`<strong>${K(u(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(u(e.tests[p]))}</strong> (#${e.tests[p].testNumber})<br>r = ${D.r.toFixed(4)} \xB7 n = ${D.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${A} vs ${R}`)}<br><em>insufficient data</em>`,I.style.display="block",Vt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:p,yi:n}=c;p!==n&&(i=p,S=n,f(),W(e.tests[p].testNumber,e.tests[n].testNumber))}),f}let ct=null;function tt(){const e=Mt(),o=e.flatMap(i=>i.dies??[]),m=It(o,O),{matrix:u,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=Tt(m,{minTests:6,maxTests:F}),T=Rt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=u.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,S)=>i-S),B=C.length?C[Math.floor(C.length/2)]:null;ct=u,Et(s,a,y,x,T,B,m,u.tests.some(i=>i.derived)),Z=vt(u),Z()}const Lt=Xt(l,()=>Z());return tt(),{card:l,destroy:()=>Lt.disconnect()}}
|
|
1
|
+
import{buildCoFailureMatrix as De}from"../../stats/coFailure.js";import{buildCorrelationMatrix as Re,demeanWithinGroups as ke,filterCorrelationMatrix as Ae,correlationSampleNote as _e}from"../../stats/correlation.js";import{maxOf as We}from"../../core/utils.js";import{CORRELATION_POSITIVE as Q,CORRELATION_NEGATIVE as re}from"./palette.js";import{buildFacetTable as Be}from"../../stats/facets.js";import{wireControlHover as Oe,wireTooltip as me,controlStyle as Ne,SPACE as I,RADIUS as ie,fontPx as pe,FONT as z,CLR as x}from"../toolbar.js";import{exportCsv as He}from"../tableExport.js";import{attachChartTip as Xe,cardShell as je,makeSegmented as ge,setChartGrow as Fe,isExpandedCard as Ve,bodyRoom as ze,observeResize as Ye,makeTooltip as Ge,positionChartTooltip as Pe,makeWaferSelect as Ke,renderEmptyState as Ue,resolveChartCanvasColors as qe,prepareCanvas as Je,chartDpr as be}from"./chartShell.js";import{escHtml as Z}from"../../core/utils.js";import{unmarkedLabel as xe,derivedCsvCell as ye,DERIVED_CSV_HEADER as we,DERIVED_MARK as Qe,DERIVED_KEY as Ze}from"../../renderer/testLabel.js";import{cardAbout as et}from"./cardAbout.js";const ae=5,ce=100,Ce=20;function ee(d){const h=d.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(h)return[+h[1],+h[2],+h[3]];const g=d.trim().replace("#","");return g.length===6?[parseInt(g.slice(0,2),16),parseInt(g.slice(2,4),16),parseInt(g.slice(4,6),16)]:null}function tt(d){const h=ee(d);return h?(h[0]*299+h[1]*587+h[2]*114)/1e3>140?"#111":"#fff":"#000"}function $e(d,h,g){const v=ee(d);if(!v)return d;const te=Math.round(h[0]+(v[0]-h[0])*g),X=Math.round(h[1]+(v[1]-h[1])*g),l=Math.round(h[2]+(v[2]-h[2])*g);return`rgb(${te},${X},${l})`}export function renderCorrelationPanel(d){const{title:h="Test correlation matrix",items:g,testDefs:v,onSaveImage:te,onSelectPair:X}=d,{card:l,body:D,controlsRow:Y,setPngDecor:Me,setAbout:Le}=je(h,te,d.ownerDocument);Le(et("correlation")),Me(()=>{const e=ee(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:n=>$e(n<.5?re:Q,e,Math.abs(2*n-1))}}}),Fe(l,"square"),D.style.overflowX="auto",l.style.alignSelf="start";let K=Ce,j=null;const F=l.ownerDocument.createElement("label");F.textContent="Max tests:",me(F,`The most tests the matrix shows, from ${ae} to ${ce}`),Object.assign(F.style,{color:x.label,fontSize:z.body,display:"flex",alignItems:"center",gap:I.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(ae),E.max=String(ce),E.value=String(K),Object.assign(E.style,{width:"52px",fontSize:z.body,padding:`${I.xxs} ${I.xs}`,background:x.menuBg,color:x.value,border:`1px solid ${x.menuBorder}`,borderRadius:ie.control}),E.addEventListener("change",()=>{const e=Math.max(ae,Math.min(ce,parseInt(E.value,10)||Ce));E.value=String(e),e!==K&&(K=e,G())}),F.appendChild(E),Y.appendChild(F),g.length>1&&Y.appendChild(Ke(g,j,e=>{j=e,G()},{ownerDocument:l.ownerDocument}));let de=!1,y=!1;if(v.filter(e=>e.limitLow!==void 0||e.limitHigh!==void 0).length>=2){const e=ge([["values","Values","How the tests\u2019 values move together (Pearson r)"],["fails","Fails together","Which tests fail on the same dies: the share of the dies failing either of two tests that fail both"]],"values",n=>{y=n==="fails",G()},l.ownerDocument);e.dataset.wmapCorrelationKind="1",Y.appendChild(e)}if(d.groups&&d.groups.length>=2){const e=ge([["pooled","Pooled"],["within",`Within ${d.groupLabelText??"groups"}`,"The correlation left once each group\u2019s mean is taken off every test, so a difference between groups is not read as a relationship between tests"]],"pooled",n=>{de=n==="within",G()},l.ownerDocument);e.dataset.wmapCorrelationMode="1",Y.appendChild(e)}function ve(){return j!==null?g[j]?[g[j]]:[]:g}if(d.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",me(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...Ne("outlined"),color:x.text}),Oe(e),e.addEventListener("click",()=>{const n=fe;if(!n)return;const u=n.tests.some(o=>o.derived),a=[];for(let o=0;o<n.tests.length;o++)for(let c=o+1;c<n.tests.length;c++){const w=n.cells.find(b=>b.xIndex===c&&b.yIndex===o);w&&a.push({x:n.tests[c],y:n.tests[o],r:w.r,n:w.n})}He([{header:"Test X",get:o=>xe(o.x.label)},{header:"Test X number",get:o=>o.x.testNumber},{header:"Test Y",get:o=>xe(o.y.label)},{header:"Test Y number",get:o=>o.y.testNumber},{header:y?"Share failing both":"r",get:o=>o.r===null?"":o.r.toFixed(6)},{header:y?"Dies failing either":"n",get:o=>o.n},...u?[{header:`Test X ${we.toLowerCase()}`,get:o=>ye(o.x)},{header:`Test Y ${we.toLowerCase()}`,get:o=>ye(o.y)}]:[]],a,"test-correlation.csv",d.onSaveText)}),Y.appendChild(e)}const N=l.ownerDocument.createElement("div");Object.assign(N.style,{display:"flex",flexDirection:"column",gap:I.xs,marginBottom:I.sm}),l.insertBefore(N,D);const R=Ge(l);Xe(F,l,R,"Cap on how many tests the matrix includes (strongest correlations kept first)");let ne=()=>{};function Ee(e,n,u,a,o,c,w,b){N.innerHTML="";const k=_e(w);if(k){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=w.sample?`${k} \u2014 r is an estimate, not the whole population.`:`${k}.`,Object.assign(m.style,{color:x.label,fontSize:z.body}),N.appendChild(m)}if(o.length>0){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=`\u26A0 Mixed ${o.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). ${d.groups&&d.groups.length>=2?`Choose Within ${d.groupLabelText??"groups"} to take the groups\u2019 differences out, or use the Wafer picker`:"Use the Wafer picker to narrow to a like-for-like set, or Group by one of these fields where it is in the list"}.`,Object.assign(m.style,{color:x.warnText,background:x.warnBg,border:`1px solid ${x.warnBorder}`,borderRadius:ie.control,padding:`${I.xs} ${I.md}`,fontSize:z.body}),N.appendChild(m)}const A=l.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-flex",alignItems:"center",gap:I.sm,color:x.label,fontSize:z.body,flexWrap:"wrap"});const S=l.ownerDocument.createElement("span");S.dataset.wmapCaption="1",S.textContent=y?`Share of the dies failing either that fail both${c!==null?` \xB7 ${c.toLocaleString()} failing dies per pair (median)`:""} \xB7 click a cell to view that pair in scatter \xB7`:(c!==null?`Pearson r \xB7 n \u2248 ${c.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(b?` ${Qe} ${Ze} \xB7`:""),A.appendChild(S);const T=l.ownerDocument.createElement("span");Object.assign(T.style,{display:"inline-flex",alignItems:"center",gap:I.xs});const i=l.ownerDocument.createElement("span");i.textContent=y?"0":"\u22121";const _=l.ownerDocument.createElement("span");Object.assign(_.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:ie.control,border:`1px solid ${x.menuBorder}`,background:y?`linear-gradient(to right, ${x.menuBg}, ${Q})`:`linear-gradient(to right, ${re}, ${x.menuBg}, ${Q})`});const P=l.ownerDocument.createElement("span");P.textContent=y?"1":"+1",T.append(i,_,P),A.appendChild(T),N.appendChild(A);const $=l.ownerDocument.createElement("span");if($.dataset.wmapCaption="1",Object.assign($.style,{color:x.value,fontSize:z.body,fontWeight:"500"}),y)$.textContent=a&&a.r>0?`Most shared failures: ${a.xLabel} \u2194 ${a.yLabel} (${Math.round(100*a.r)}% of the dies failing either fail both)`:"No two tests fail on the same dies";else if(e===0&&n===0)$.textContent=a?`No significant correlations found \u2014 strongest pair: ${a.xLabel} \u2194 ${a.yLabel} (r = ${a.r.toFixed(2)})`:"No significant correlations found";else{const m=[];e>0&&m.push(`${e} strong (|r| \u2265 0.7)`),n>0&&m.push(`${n} moderate (0.4\u20130.7)`);const U=e+n;let r=m.join(", ")+` pair${U!==1?"s":""} found`;u>0&&(r+=` \xB7 ${u} weak pair${u!==1?"s":""} not shown`),$.textContent=r}N.appendChild($)}function Se(e){if(D.innerHTML="",e.tests.length<2)return Ue(D,"Need at least two parametric tests for a correlation matrix."),()=>{};const n=l.ownerDocument.createElement("canvas");n.style.display="block",n.style.cursor="default",D.appendChild(n);const u=e.tests.length,a=r=>r.label.split(" (#")[0],o=Math.min(14,We(e.tests.map(r=>a(r).length))),c=o*6.5+8,w=10,b=Math.round(w*6.5*Math.sin(Math.PI/4))+14,k=14,A=28,S=44;let T=-1,i=-1;const _=96;function P(r){const f=Math.max(0,r-c),p=Math.floor(f/u);if(!Ve(l))return Math.max(k,Math.min(S,p));const s=Math.floor((ze(l,D,n)-b-4)/u);return Math.max(k,Math.min(_,p,s))}const $=new Map;for(const r of e.cells){let f=$.get(r.yIndex);f||(f=[],$.set(r.yIndex,f)),f.push(r)}function m(){const r=qe(l),f=ee(r.bg)??[255,255,255],p=D.clientWidth,s=P(p),V=s*u,M=b+s*u+4,W=c+V,B=Je(n,l,W,M);if(!B)return;const{ctx:t}=B;t.font=`${pe(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((O,C)=>{const L=a(O),H=L.length>w?`${L.slice(0,w-1)}\u2026`:L,oe=c+C*s+s/2;t.save(),t.translate(oe,b-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=C===T?r.text:r.textMuted,t.fillText(H,0,0),t.restore()}),e.tests.forEach((O,C)=>{const L=a(O),H=b+C*s,oe=H+s/2;t.font=`${pe(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=C===i?r.text:r.textMuted,t.fillText(L.length>o?`${L.slice(0,o-1)}\u2026`:L,c-4,oe),($.get(C)??[]).forEach(he=>{const se=he.xIndex,q=c+se*s,Ie=se===T&&C===i,ue=se===C,J=he.r;if(J===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(q+1,H+1,s-2,s-2),t.globalAlpha=1;return}let le=r.bgHover;ue?t.fillStyle=r.bgHover:(le=$e(J>=0?Q:re,f,Math.abs(J)),t.fillStyle=le),t.fillRect(q+1,H+1,s-2,s-2),s>=A&&!ue&&(t.font=`${Math.min(10,s*.35)}px system-ui, sans-serif`,t.fillStyle=tt(le),t.textAlign="center",t.textBaseline="middle",t.fillText(J.toFixed(2),q+s/2,H+s/2)),Ie&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(q+1,H+1,s-2,s-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let O=0;O<=u;O++){const C=c+O*s;t.beginPath(),t.moveTo(C,b),t.lineTo(C,b+u*s),t.stroke();const L=b+O*s;t.beginPath(),t.moveTo(c,L),t.lineTo(c+u*s,L),t.stroke()}}function U(r){const f=n.getBoundingClientRect(),p=D.clientWidth,s=P(p),V=(r.clientX-f.left)*(n.width/be(n)/f.width),M=(r.clientY-f.top)*(n.height/be(n)/f.height),W=Math.floor((V-c)/s),B=Math.floor((M-b)/s);return W>=0&&W<u&&B>=0&&B<u?{xi:W,yi:B}:null}return n.addEventListener("mousemove",r=>{const f=U(r);if(!f){R.style.display="none",n.style.cursor="default";return}const{xi:p,yi:s}=f,V=p===s;n.style.cursor=V||!X?"default":"pointer";const M=e.cells.find(t=>t.xIndex===p&&t.yIndex===s),W=e.tests[p].label,B=e.tests[s].label;V?R.innerHTML=`<strong>${Z(W)}</strong>`:M?.r!==null&&M?.r!==void 0?R.innerHTML=`<strong>${Z(a(e.tests[s]))}</strong> (#${e.tests[s].testNumber}) vs <strong>${Z(a(e.tests[p]))}</strong> (#${e.tests[p].testNumber})<br>${y?`${(100*M.r).toFixed(0)}% of the dies failing either fail both \xB7 ${M.n.toLocaleString()} fail either`:`r = ${M.r.toFixed(4)} \xB7 n = ${M.n.toLocaleString()}`}${X?"<br><em>click to view in scatter</em>":""}`:R.innerHTML=`${Z(`${B} vs ${W}`)}<br><em>insufficient data</em>`,R.style.display="block",Pe(R,l,r.clientX,r.clientY)}),n.addEventListener("mouseleave",()=>{R.style.display="none"}),n.addEventListener("click",r=>{const f=U(r);if(!f||!X)return;const{xi:p,yi:s}=f;p!==s&&(T=p,i=s,m(),X(e.tests[p].testNumber,e.tests[s].testNumber))}),m}let fe=null;function G(){const e=ve(),n=!y&&de&&j===null&&!!d.groups,u=n?ke(d.groups.map(i=>i.items.flatMap(_=>_.dies??[])),v):e.flatMap(i=>i.dies??[]),a=y?De(u,v):Re(u,v),{matrix:o,strongPairs:c,moderatePairs:w,hiddenWeakPairs:b,strongestPair:k}=Ae(a,{minTests:6,maxTests:K}),A=n||y?[]:Be(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),S=o.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,_)=>i-_),T=S.length?S[Math.floor(S.length/2)]:null;fe=o,Ee(c,w,b,k,A,T,a,o.tests.some(i=>i.derived)),ne=Se(o),ne()}const Te=Ye(l,()=>ne());return G(),{card:l,destroy:()=>Te.disconnect()}}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Rgb = [number, number, number];
|
|
2
|
+
/** The colour at `t` in [0, 1] on the signed scale (blue below, warm above), where 0.5 is zero. */
|
|
3
|
+
export declare const divergingRgb: (t: number) => Rgb;
|
|
4
|
+
export declare const divergingColor: (t: number) => string;
|
|
5
|
+
/** The colour at `t` on the rating scale (vermillion for bad to blue for good). */
|
|
6
|
+
export declare const ratingRgb: (t: number) => Rgb;
|
|
7
|
+
/** The gradients only a plot offers, beside the map's own (`listValueColorSchemes`). */
|
|
8
|
+
export declare const PLOT_GRADIENTS: ReadonlyArray<{
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* The colour of a value at `t` in [0, 1] of a plot's key. `scheme` is a name from `PLOT_GRADIENTS` or a map gradient;
|
|
14
|
+
* unset, a value rescaled around zero (`diverging`) takes the signed scale, a rating (a yield, a pass rate) the rating
|
|
15
|
+
* scale, and any other the map's default. `reversed` flips the key.
|
|
16
|
+
*/
|
|
17
|
+
export declare function plotGradient(scheme: string | undefined, reversed: boolean | undefined, diverging: boolean | undefined, rating?: boolean): (t: number) => string;
|
|
18
|
+
/** Whether dark text reads better than white on `rgb` (WCAG relative luminance: the crossover of the two contrasts). */
|
|
19
|
+
export declare const darkTextOn: (rgb: Rgb) => boolean;
|
|
20
|
+
/** Whether dark text reads better on a CSS colour (`rgb(...)` or `#rgb`/`#rrggbb`); white when the colour cannot be read. */
|
|
21
|
+
export declare function darkTextOnColor(color: string): boolean;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=divergingScale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registerValueColorScheme as f,resolveValueColorFn as b}from"../../renderer/colorSchemes.js";import{SIGNED_HIGH as x,SIGNED_LOW as p}from"./palette.js";const c=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)],s=[247,247,247],l=(n,e,r)=>[n[0]+(e[0]-n[0])*r,n[1]+(e[1]-n[1])*r,n[2]+(e[2]-n[2])*r],g=c(p),u=c(x),I=[g,l(g,s,.5),s,l(u,s,.5),u],h=[[213,94,0],[230,159,0],[240,228,66],[86,180,233],[0,114,178]];function d(n,e){const r=Math.min(1,Math.max(0,Number.isFinite(e)?e:.5))*(n.length-1),t=Math.min(n.length-2,Math.floor(r)),i=r-t,o=n[t],a=n[t+1];return[o[0]+(a[0]-o[0])*i,o[1]+(a[1]-o[1])*i,o[2]+(a[2]-o[2])*i]}const m=([n,e,r])=>`rgb(${Math.round(n)}, ${Math.round(e)}, ${Math.round(r)})`;export const divergingRgb=n=>d(I,n),divergingColor=n=>m(divergingRgb(n)),ratingRgb=n=>d(h,n),PLOT_GRADIENTS=[{name:"diverging",label:"Blue to orange, around zero"},{name:"rating",label:"Rating: orange-red to blue (colour-blind safe)"}];f("diverging",{label:PLOT_GRADIENTS[0].label,forValue:divergingColor});export function plotGradient(n,e,r,t){const i=n??(r?"diverging":t?"rating":void 0),o=i==="diverging"?divergingColor:i==="rating"?a=>m(ratingRgb(a)):b(i);return e?a=>o(1-a):o}function N([n,e,r]){const t=i=>{const o=i/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4};return .2126*t(n)+.7152*t(e)+.0722*t(r)}export const darkTextOn=n=>N(n)>.179;export function darkTextOnColor(n){const e=/^rgba?\(\s*(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)/i.exec(n);if(e)return darkTextOn([Number(e[1]),Number(e[2]),Number(e[3])]);const r=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());if(!r)return!1;const t=r[1].length===3?[...r[1]].map(i=>i+i).join(""):r[1];return darkTextOn([parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)])}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compareTestsByGroup as
|
|
1
|
+
import{compareTestsByGroup as J,formatP as N,groupKeys as Q}from"../../stats/groupCompare.js";import{fmt as S}from"../../renderer/fmt.js";import{testLabel as G,unmarkedLabel as Y}from"../../renderer/testLabel.js";import{CLR as l,FONT as q,SPACE as C,controlStyle as R,wireControlHover as V,wireTooltip as k}from"../toolbar.js";import{exportCsv as Z}from"../tableExport.js";import{cardShell as ee,guideCite as te,makeListSelect as oe,renderEmptyState as K}from"./chartShell.js";import{GUIDE_SECTIONS as ne}from"../../stats/guideSections.js";import{cardAbout as se}from"./cardAbout.js";import{shadesAmong as re}from"../cellShade.js";const L="\0none",ae=6;export function renderGroupComparisonPanel(s){const r=s.ownerDocument??document,O=s.groupLabelText??"group",{card:b,body:$,controlsRow:B,setAbout:P}=ee(s.title??`Comparison by ${O.toLowerCase()}`,void 0,r);P(se("comparison")),b.dataset.wmapGroupComparison="1",b.style.gridColumn="1 / -1";const A=s.groups.flatMap(t=>t.items.map(e=>({dies:e.dies,group:t.key}))),p=Q(A),a=s.control!==null&&p.includes(s.control)?s.control:null,f=J(A,s.testDefs,a??void 0),E=p.length<=ae?p:[],U=oe([{value:L,label:"No control: compare all groups"},...p.map(t=>({value:t,label:`Control: ${t}`}))],a??L,t=>s.onControlChange(t===L?null:t),{ownerDocument:r,ariaLabel:"Control group",hook:"compare-control"});if(B.appendChild(U),s.onSaveText&&f.length){const t=r.createElement("button");t.type="button",t.textContent="Comparison CSV",k(t,"Save this table as a CSV file, one row per test"),Object.assign(t.style,{...R("outlined"),color:l.text}),V(t),t.addEventListener("click",()=>Z([{header:"Test",get:e=>Y(G(e.test,e.test.testNumber))},{header:"Test number",get:e=>e.test.testNumber},{header:"Unit",get:e=>e.test.unit??""},...p.flatMap(e=>[{header:`${e} wafers`,get:o=>o.comparison.groups.find(n=>n.key===e)?.n??0},{header:`${e} mean`,get:o=>c(o.comparison.groups.find(n=>n.key===e)?.mean)},...a&&e!==a?[{header:`${e} minus ${a}`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.delta)},{header:`${e} vs ${a} p (Holm)`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.pAdjusted)}]:[]]),{header:"Welch p",get:e=>c(e.comparison.welch?.p)},{header:"Kruskal-Wallis p",get:e=>c(e.comparison.kruskal?.p)},{header:"q (Benjamini-Hochberg)",get:e=>c(e.pAdjusted)},{header:"Largest shift (wafer SDs)",get:e=>c(e.effect)},{header:"Largest shift (share of limit window)",get:e=>c(e.windowShare)},{header:"Note",get:e=>e.comparison.issue??""}],f,"group-comparison.csv",s.onSaveText)),B.appendChild(t)}if(p.length<2)return K($,`Needs two or more ${O.toLowerCase()} groups to compare.`),{card:b,setTest:()=>{},destroy:()=>{}};if(f.length===0)return K($,"No measured test has values in these wafers."),{card:b,setTest:()=>{},destroy:()=>{}};const y=r.createElement("div"),z=p.map(t=>`${t} ${A.filter(e=>e.group===t).length}`).join(", ");y.textContent=`Each wafer is one value, the mean of its dies, so n is wafers (${z}). Welch: Welch's ANOVA (Welch's t for two groups). Rank: Kruskal\u2013Wallis${f.some(t=>t.comparison.kruskal?.approximate)?", approximate with fewer than five wafers in a group":""}. q: Benjamini\u2013Hochberg across the ${f.length} tests, which the table is ranked by.`+(a?` Each group's difference from ${a} has a Holm-adjusted p.`:"")+" ",y.append(te(r,ne.groups),"."),Object.assign(y.style,{color:l.label,fontSize:q.body,marginBottom:C.sm}),$.appendChild(y);const j=r.createElement("div");Object.assign(j.style,{overflow:"auto",maxHeight:"420px",border:`1px solid ${l.menuBorder}`});const x=r.createElement("table");Object.assign(x.style,{borderCollapse:"collapse",width:"100%",fontSize:q.body,fontVariantNumeric:"tabular-nums"});const W=r.createElement("thead"),D=r.createElement("tr"),h=(t,e,o="right")=>{const n=r.createElement("th");n.scope="col",n.textContent=t,e&&k(n,e),Object.assign(n.style,{position:"sticky",top:"0",background:l.menuBg,textAlign:o,padding:`${C.xs} ${C.sm}`,borderBottom:`1px solid ${l.menuBorder}`,color:l.label,fontWeight:"600",whiteSpace:"nowrap"}),D.appendChild(n)};h("Test",void 0,"left");for(const t of E)h(t===a?`${t} (control)`:t,a&&t!==a?`Mean of the wafer means, and the difference from ${a}`:"Mean of the wafer means");h("Welch p","Do the group means differ? Welch\u2019s ANOVA on wafer means, not assuming equal spreads"),h("Rank p","The same question on ranks (Kruskal\u2013Wallis): one odd wafer cannot drive it"),h("q","Welch p adjusted for the number of tests compared (Benjamini\u2013Hochberg); the table is ranked by it"),h("Largest shift","The largest difference between group means: in wafer-to-wafer standard deviations, and as a share of the limit window where the test has both limits"),W.appendChild(D),x.appendChild(W);const M=r.createElement("tbody"),H=new Map,g=(t,e,o={})=>{const n=r.createElement("td");typeof e=="string"?n.textContent=e:n.appendChild(e),o.title&&k(n,o.title),Object.assign(n.style,{padding:`${C.xs} ${C.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${l.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400",color:o.muted?l.label:l.text}),o.shade&&(n.style.background=o.shade),t.appendChild(n)};for(const t of f){const e=r.createElement("tr"),o=t.comparison,n=t.test.unit,d=r.createElement("button");d.type="button",d.textContent=G(t.test,t.test.testNumber),d.dataset.wmapCompareTest=String(t.test.testNumber),k(d,`Show ${d.textContent} in the panels below${o.issue?`. ${o.issue}`:""}`),Object.assign(d.style,{...R("bare"),padding:"0",textAlign:"left",color:l.text,textDecoration:"underline",textDecorationColor:l.menuBorder}),V(d,"bare"),d.addEventListener("click",()=>{s.onSelectTest(t.test.testNumber),v(t.test.testNumber)}),g(e,d,{align:"left"});const _=re(E.map(w=>{const m=o.groups.find(i=>i.key===w);return m&&m.n?m.mean:NaN}),w=>S(w,n));for(const[w,m]of E.entries()){const i=o.groups.find(T=>T.key===m),u=o.contrasts?.find(T=>T.key===m),F=i&&i.n?S(i.mean,n):"\u2014",X=u&&Number.isFinite(u.delta)?`${F} (${u.delta>=0?"+":""}${S(u.delta,n)}, p ${N(u.pAdjusted)})`:F;g(e,X,{shade:_[w],title:i?`${m}: ${i.n} wafer${i.n===1?"":"s"}${i.n>=2?`, wafer-to-wafer SD ${S(i.sd,n)}`:""}`:void 0,muted:!i||i.n<2,strong:!!u&&u.pAdjusted<.05})}g(e,N(o.welch?.p??NaN),{title:o.issue}),g(e,N(o.kruskal?.p??NaN)),g(e,N(t.pAdjusted),{strong:t.pAdjusted<.05});const I=Number.isFinite(t.effect)?`${Math.abs(t.effect).toFixed(1)} SD${t.windowShare!==void 0?` \xB7 ${Math.abs(t.windowShare*100).toFixed(0)}% of limits`:""}`:"\u2014";g(e,I),H.set(t.test.testNumber,e),M.appendChild(e)}x.appendChild(M),j.appendChild(x),$.appendChild(j);function v(t){for(const[e,o]of H)o.style.background=e===t?l.bgActive:"",e===t?o.setAttribute("aria-current","true"):o.removeAttribute("aria-current")}return v(s.selectedTestNumber),{card:b,setTest:v,destroy:()=>{}}}const c=s=>s===void 0||!Number.isFinite(s)?"":String(s);
|
|
@@ -22,7 +22,14 @@ export declare function yieldFill(yieldPercent: number): string;
|
|
|
22
22
|
* same information positionally.
|
|
23
23
|
*/
|
|
24
24
|
export declare function capabilityColor(ppk: number | null): string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The two ends of every signed scale (a correlation, a z-score, a difference): warm is positive or above average, blue is
|
|
27
|
+
* negative or below, so one colour never means "high" on one chart and "low" on the next. Okabe-Ito blue and vermillion,
|
|
28
|
+
* which stay far apart under every common colour-vision deficiency.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SIGNED_LOW = "#0072B2";
|
|
31
|
+
export declare const SIGNED_HIGH = "#D55E00";
|
|
32
|
+
/** Correlation sign hues (vermillion = positive, blue = negative); |r| sets intensity via background blend. */
|
|
33
|
+
export declare const CORRELATION_POSITIVE = "#D55E00";
|
|
34
|
+
export declare const CORRELATION_NEGATIVE = "#0072B2";
|
|
28
35
|
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{clamp01 as
|
|
1
|
+
import{clamp01 as f}from"../../core/utils.js";export const QUANTITY="#4e79a7";const p=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#8C6D31","#999999"],I=["#1f1ff9","#f91ff9","#05d105","#65188b","#f91f68","#607afb","#8b1818","#1f4951"],n=[...p,...I];export function categorical(t){return n[(t%n.length+n.length)%n.length]}export const CATEGORICAL_COUNT=n.length;function i(t,e,c){const s=[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)],l=[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)],o=s.map((r,E)=>Math.round(r+(l[E]-r)*c));return`rgb(${o[0]},${o[1]},${o[2]})`}export function yieldFill(t){const e=f((t-50)/50);return i("#e7eef6","#2f6395",e)}export function capabilityColor(t){return t===null?"#999999":t>=1.33?"#009E73":t>=1?"#E69F00":"#D55E00"}export const SIGNED_LOW="#0072B2",SIGNED_HIGH="#D55E00",CORRELATION_POSITIVE=SIGNED_HIGH,CORRELATION_NEGATIVE=SIGNED_LOW;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type PlotPoint, type ResolvedPlot } from '../../stats/plotData.js';
|
|
2
|
+
import { type SaveTextHandler } from '../toolbar.js';
|
|
2
3
|
import { type CardMenuRow, type SaveImageHandler, type WaferContextMenuHandler } from './chartShell.js';
|
|
3
4
|
import type { BinColors } from '../../renderer/binColors.js';
|
|
4
5
|
/**
|
|
@@ -18,19 +19,14 @@ export declare function categoryLayout(present: ReadonlyArray<readonly number[]>
|
|
|
18
19
|
export interface PlotChartOptions {
|
|
19
20
|
ownerDocument?: Document;
|
|
20
21
|
onSaveImage?: SaveImageHandler;
|
|
22
|
+
/** Where the card's Save data as CSV goes (the host's save dialog); absent = the browser's download. */
|
|
23
|
+
onSaveText?: SaveTextHandler;
|
|
21
24
|
/** The label of the wafer an item index names, for tooltips. */
|
|
22
25
|
waferLabel: (item: number) => string;
|
|
23
26
|
/** The maps' bin colours: a plot coloured by hard or soft bin draws each bin in its map colour. */
|
|
24
27
|
binColors?: BinColors;
|
|
25
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. */
|
|
26
29
|
onWaferMenu?: WaferContextMenuHandler;
|
|
27
|
-
/**
|
|
28
|
-
* A legend click picks a group for the host to narrow to (an Insights section's group), in place of filtering this
|
|
29
|
-
* plot alone: called with the group clicked, or null when it is `legendPicked` already (show every group again).
|
|
30
|
-
*/
|
|
31
|
-
onLegendPick?: (group: string | null) => void;
|
|
32
|
-
/** The group the host has narrowed to, shown selected in the legend. */
|
|
33
|
-
legendPicked?: string | null;
|
|
34
30
|
/** Click a point: open its wafer, on `testNumber` (the plot's own measurement) when it has one. Omit where there is no wafer to open. */
|
|
35
31
|
onOpenWafer?: (item: number, testNumber?: number) => void;
|
|
36
32
|
/** 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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{escHtml as U,maxOf as ke,minOf as Rt}from"../../core/utils.js";import{fiveNumberSummary as zt,normalQuantile as _t,sampleVariance as An}from"../../stats/math.js";import{CONTROL_RULE_TEXT as En}from"../../stats/control.js";import{PAT_VERDICT_LABEL as Gt}from"../../stats/pat.js";import{fmt as ee}from"../../renderer/fmt.js";import{fitTicks as ft}from"../../renderer/axisTicks.js";import{binOfLabel as Cn,plotFootnote as Xt,plotGuideSections as Ut,plotTestNumber as Ye,plotTitle as Bn,probabilityPosition as it}from"../../stats/plotData.js";import{SPACE as xe,RADIUS as Wn,fontPx as te,FONT as ut,CLR as Je,markNoPrint as Dt}from"../toolbar.js";import{cardShell as In,appendGuideCites as Nn,observeResize as Fn,makeTooltip as On,attachChartTip as Rn,chartFillHeight as zn,applyCanvasFlow as Re,prepareCanvas as ze,positionChartTooltip as ht,resolveChartCanvasColors as _e,makeAxisFormat as _n,horizontalTickSpacing as jt,VERTICAL_TICK_SPACING_PX as Gn,makeSeriesLegendItem as Xn,renderEmptyState as qt,isExpandedCard as Yt,fillTextOnHalo as St,limitLines as Un,limitExtent as Dn,stackLabelRows as Ht,placeClearOf as Vt,strokeLimitLine as Kt,drawOffAxisLimits as jn,limitLabelSide as qn,shouldIncludeLimitsByDefault as Yn,WAFER_MENU_HINT as Zt}from"./chartShell.js";import{guideCitesText as Hn}from"../../stats/guideSections.js";import{categorical as Vn}from"./palette.js";import{NO_DATA_FILL as Qt}from"../../renderer/colorMap.js";import{resolveValueColorFn as dt}from"../../renderer/colorSchemes.js";import{wirePointInteractions as $t}from"./pointInteractions.js";import{plotAbout as Kn}from"./cardAbout.js";const wt=64,mt=16,Pt=12,Ge=52,Zn=16,Qn=92,Jn=16,Lt=5e3,Jt=1500,at=100,eo=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],en=h=>`${+(h*100).toPrecision(4)}%`;export function categoryLayout(h){const I=.8/Math.max(1,...h.map(B=>B.length)),j=B=>(1-h[B].length*I)/2;return{width:I,left:(B,q)=>{const V=h[B].indexOf(q);return V<0?void 0:j(B)+V*I},groupAt:(B,q)=>{const V=Math.floor((q-j(B))/I);return V>=0&&V<h[B].length?h[B][V]:void 0}}}function to(h){if(h<=Jt)return Array.from({length:h},(B,q)=>q);const R=[];for(let B=0;B<at;B++)R.push(B);const I=Jt-2*at,j=h-2*at;for(let B=0;B<I;B++)R.push(at+Math.floor(B*j/I));for(let B=h-at;B<h;B++)R.push(B);return R}function At(h,R,I){return I?Math.round(h).toLocaleString("en-GB"):R?ee(h,R):`${h<=-.005?"\u2212":""}${Math.abs(h).toFixed(2)}`}const no=260;function oo(h){const R=[...h.querySelectorAll("[data-wmap-plot-panel]")],I=R[0]?.querySelector("canvas");if(!I)return null;const j=I.width/Math.max(1,I.getBoundingClientRect().width)||1,B=h.getBoundingClientRect(),q=h.ownerDocument.createElement("canvas");q.width=Math.ceil(B.width*j),q.height=Math.ceil(B.height*j);const V=q.getContext("2d");if(!V)return null;const Te=getComputedStyle(h);V.fillStyle=Te.backgroundColor&&Te.backgroundColor!=="rgba(0, 0, 0, 0)"?Te.backgroundColor:"#fff",V.fillRect(0,0,q.width,q.height);for(const ve of R){const Se=ve.querySelector("canvas"),ce=ve.dataset.wmapChartTitle??"",z=(Se??ve).getBoundingClientRect(),i=ve.getBoundingClientRect();V.fillStyle=getComputedStyle(ve).color||"#333",V.font=`600 ${Math.round(13*j)}px system-ui, sans-serif`,V.textBaseline="top",V.fillText(ce,(i.left-B.left+8)*j,(i.top-B.top+6)*j),Se&&V.drawImage(Se,(z.left-B.left)*j,(z.top-B.top)*j,z.width*j,z.height*j)}return q}const Be=(h,R)=>R.extent?[...h,...R.extent]:h;function ue(h,R,I={}){const j=R.scale==="log";let B=h.length?Rt(h):0,q=h.length?ke(h):1;j&&(B=Math.log10(Math.max(B,Number.MIN_VALUE)),q=Math.log10(Math.max(q,Number.MIN_VALUE)));const V=(q-B)*.05||(j?.5:1);B=I.floorAtZero&&!j&&B>=0?0:B-V,q+=V;const ve=Q=>Q===void 0||!Number.isFinite(Q)?void 0:j?Q>0?Math.log10(Q):void 0:Q,Se=ve(R.min),ce=ve(R.max);Se!==void 0&&(B=Se),ce!==void 0&&(q=ce),q>B||(q=B+1);const z=q-B,i=!!R.reverse,S=Q=>{const J=((j?Math.log10(Math.max(Q,Number.MIN_VALUE)):Q)-B)/z;return i?1-J:J};return{lo:j?10**B:B,hi:j?10**q:q,log:j,reverse:i,frac:S}}function Et(h,R,I,j){if(R/h<10)return ft(h,R,I,j);const B=Math.floor(Math.log10(h)),q=Math.ceil(Math.log10(R)),V=Se=>{const ce=[];for(let z=B;z<=q;z++)for(const i of Se){const S=i*10**z;S>=h&&S<=R&&ce.push(S)}return ce},Te=V([1]);return{ticks:Te.length>=4?Te:V([1,2,5]),step:0}}export function renderPlotChart(h){const R=h.ownerDocument??document,{card:I,heading:j,body:B,controlsRow:q,setPngDecor:V,setPngCanvas:Te,setAbout:ve,setMenuRows:Se}=In(h.panel?.title??"Plot",h.onSaveImage,R,{png:!h.panel});h.panel&&(I.dataset.wmapPlotPanel="1");let ce=[];I.dataset.wmapPlotCard="1";const z=On(I);let i,S,Q,J,He,et=[];const W=new Set,Xe=new Set;let de=null,me=-1,se=[],K,Ae,ne,ie=null,tt=0,$e,rt;const tn=()=>!!i?.facets;let he=[],Me=-1,pt=new Map,Ue=[],De=Ge,k=wt,M=Pt;const nn={[Gt.outlier]:"#e69f00",[Gt.fails]:"#c0392b"},oe=e=>{const l=i?.groups[e]??"";if(i?.colorBins&&h.binColors){const s=Cn(l);return s===void 0?Qt:(i.colorBins==="hard"?h.binColors.hard:h.binColors.soft).get(s)??Qt}return nn[l]??Vn(e)},je=e=>i?.groups[e]||"";function We(){const e=B.clientWidth,l=(h.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(De-Ge),s=zn(I,B,S,l);return{w:e,h:s,plotW:Math.max(10,e-k-mt),plotH:Math.max(10,s-M-De)}}const Ee=e=>{const l=(e?.references??[]).flatMap(s=>s.to===void 0?[{value:s.at,kind:"ref",end:"lo",label:s.label??""}]:[{value:s.at,kind:"ref",end:"lo",label:s.label??"",bandTo:s.to},{value:s.to,kind:"ref",end:"hi",label:s.label??""}]);return[...Un(e?.limits,i?.spec.limits??"both"),...l].filter(s=>e?.scale!=="log"||s.value>0)},Ie=(e,l,s)=>{const r=s?.clip,a=r?[...e.filter(d=>d>=r.lo&&d<=r.hi),r.lo,r.hi]:e,u=a.filter(Number.isFinite);if(!l.length||u.length===0)return a;const{lo:n,hi:t}=Dn(l);return(s?i?.spec.axes?.[s===i?.x?"x":"y"]?.includeLimits:void 0)??Yn(Rt(u),ke(u),n,t)?[...a,...l.map(d=>d.value)]:a};let gt;function Ve(e,l,s,r=!1){return!r&&!i?.x?.clip&&!i?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(k,M,l,s),e.clip(),gt=e,Ct)}function Ct(){gt?.restore(),gt=void 0}function Ne(e,l,s,r,a,u,n,t,o){const d=[];if(u.length===0)return()=>{};const $=u.filter(m=>m.value>=a.lo&&m.value<=a.hi),w=u.filter(m=>!$.includes(m)).map(m=>({value:m.value,label:m.label,side:m.value<a.lo?"lo":"hi"}));e.save(),e.font=`${te(-1)}px system-ui, sans-serif`;const b=m=>`${m.label} ${ee(m.value,n.unit)}`.trim(),c=te(-1)+2;for(const m of u){if(m.bandTo===void 0)continue;const P=a.frac(Math.min(m.value,m.bandTo)),v=a.frac(Math.max(m.value,m.bandTo)),g=Math.max(0,Math.min(P,v)),y=Math.min(1,Math.max(P,v));y<=g||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(k,M+(1-y)*r,s,(y-g)*r):e.fillRect(k+g*s,M,(y-g)*s,r),e.restore())}if(t==="y"){const m=$.map(g=>{const y=M+(1-a.frac(g.value))*r;return{l:g,y,start:y-6-c/2,end:y-6+c/2}}),P=Ht(m,1),v=m.length?ke(m.map(g=>e.measureText(b(g.l)).width))+8:0;m.forEach(({l:g,y},p)=>{e.globalAlpha=.7,Kt(e,g,l,k,y,k+s,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const f=k+3+P[p]*v,E=Vt(Ue,{x0:f,x1:f+e.measureText(b(g)).width,y0:y-4-c+2,y1:y-4+2},c);if(!o){e.fillText(b(g),f,E.y1-2);return}d.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",St(e,b(g),f,E.y1-2,o.halo),e.restore()})})}else{const m=$.map(v=>{const g=k+a.frac(v.value)*s,y=e.measureText(b(v)).width,p=qn(g,y,k,k+s,v.end==="lo");return{l:v,x:g,side:p,start:p<0?g-3-y:g+3,end:p<0?g-3:g+3+y}}),P=Ht(m,4);m.forEach(({l:v,x:g,side:y,start:p,end:f},E)=>{e.globalAlpha=.7,Kt(e,v,l,g,M,g,M+r),e.globalAlpha=1;const N=y<0?"right":"left";e.fillStyle=l,e.textAlign=N,e.textBaseline="top";const _=M+2+P[E]*c,L=Vt(Ue,{x0:p,x1:f,y0:_,y1:_+c},c);if(!o){e.fillText(b(v),g+y*3,L.y0);return}d.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=N,e.textBaseline="top",St(e,b(v),g+y*3,L.y0,o.halo),e.restore()})})}return e.restore(),jn(e,w,{left:k,right:k+s,top:M,bottom:M+r},t==="y"?"vertical":"horizontal",l,m=>ee(m,n.unit),void 0,Ue),()=>d.forEach(m=>m())}function yt(e,l,s,r){return _n(Math.max(Math.abs(l),Math.abs(s)),e.unit,r)}function ct(e,l){return l?`${e.label} (${l})`:e.label}const bt=18,xt=(e,l,s)=>{if(e.measureText(l).width<=s)return l;for(let r=l.length-1;r>0;r--){const a=`${l.slice(0,r)}\u2026`;if(e.measureText(a).width<=s)return a}return""};function qe(e,l,s,r,a,u,n,t,o,d,$){Ue=[],e.font=`${te(-1)}px system-ui, sans-serif`;const w=()=>Gn,b=$?{ticks:$.map(g=>g.at),step:0}:t.log?Et(t.lo,t.hi,u,w):ft(t.lo,t.hi,u,w),c=new Map($?.map(g=>[g.at,g.label])),m=yt(d,t.lo,t.hi,b.step||void 0),P=$?{tick:g=>c.get(g)??"",unitLabel:""}:m;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let v="";if("labels"in n){const g=n.labels.length;if(n.labels.forEach((y,p)=>{const f=k+(p+.5)/g*a,E=y.length>22?`${y.slice(0,21)}\u2026`:y;n.rotate?(e.save(),e.translate(f,M+u+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(E,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(E,f,M+u+4))}),n.nest){const y=n.nest[0]?.length??0,p=a/g;for(let f=y-2;f>=0;f--){const E=r-6-bt-f*bt,N=L=>n.nest[L].slice(0,f+1).join("");let _=0;for(let L=1;L<=g;L++){if(L<g&&N(L)===N(_))continue;const A=k+_*p,D=k+L*p;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(xt(e,n.nest[_][f],D-A-4),(A+D)/2,E),L<g&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=f===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(D,M),e.lineTo(D,E-2),e.stroke(),e.restore()),_=L}}e.fillStyle=l.textMuted}}else{const g=jt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),y=n.log?Et(n.lo,n.hi,a,g):ft(n.lo,n.hi,a,g),p=yt(o,n.lo,n.hi,y.step||void 0);v=p.unitLabel;for(const f of y.ticks){const E=k+n.frac(f)*a;e.beginPath(),e.moveTo(E,M),e.lineTo(E,M+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(f),E,M+u+4)}}for(const g of b.ticks){const y=M+(1-t.frac(g))*u;e.beginPath(),e.moveTo(k,y),e.lineTo(k+a,y),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(P.tick(g),k-4,y)}e.font=`${te(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(ct(o,v),k+a/2,r-6),e.save(),e.translate(14,M+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ct(d,P.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,M),e.lineTo(k,M+u),e.moveTo(k,M+u),e.lineTo(k+a,M+u),e.stroke()}function on(e,l,s,r,a,u,n,t,o,d,$,w={along:u,offset:0}){Ue=[],e.font=`${te(-1)}px system-ui, sans-serif`;const b=jt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),$.unit),c=o.log?Et(o.lo,o.hi,a,b):ft(o.lo,o.hi,a,b),m=yt($,o.lo,o.hi,c.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const f of c.ticks){const E=k+o.frac(f)*a;e.beginPath(),e.moveTo(E,M),e.lineTo(E,M+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(m.tick(f),E,M+u+4)}const P=n.labels.length,v=w.along/Math.max(1,P),g=M-w.offset;e.save(),e.beginPath(),e.rect(0,M-1,k+a+1,u+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const y=Math.max(0,Math.floor(w.offset/v)),p=Math.min(P,Math.ceil((w.offset+u)/v));for(let f=y;f<p;f++)e.fillText(xt(e,n.labels[f],t.inner),k-6,g+(f+.5)*v);if(n.nest){const f=n.nest[0]?.length??0;let E=k-6-t.inner-10;for(let N=f-2;N>=0;N--){const _=t.outer[N]??0,L=A=>n.nest[A].slice(0,N+1).join("");let C=0;for(let A=1;A<=P;A++){if(A<P&&L(A)===L(C))continue;const D=g+C*v,x=g+A*v;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(xt(e,n.nest[C][N],_),E,(D+x)/2),A<P&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=N===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(E-_,x),e.lineTo(k+a,x),e.stroke(),e.restore()),C=A}E-=_+10}e.fillStyle=l.textMuted}e.restore(),e.font=`${te(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(ct($,m.unitLabel),k+a/2,r-6),e.save(),e.translate(14,M+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ct(d,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,M),e.lineTo(k,M+u),e.moveTo(k,M+u),e.lineTo(k+a,M+u),e.stroke()}function ln(){if(!i||!S||i.marks?.type!=="scatter"||!i.x||!i.y)return;Re(S,J??0);const e=_e(I),{w:l,h:s,plotW:r,plotH:a}=We(),u=ze(S,I,l,s);if(!u)return;const{ctx:n}=u,t=i.marks.points,o=W.size===0?t:t.filter(L=>W.has(L.group)),d=i.colorScale,$=dt(),w=Ee(i.x),b=Ee(i.y),c=ue(Ie(Be(t.map(L=>L.x),i.x),w,i.x),i.x),m=ue(Ie(Be(t.map(L=>L.y),i.y),b,i.y),i.y);K={x:c,y:m,plotW:r,plotH:a},qe(n,e,l,s,r,a,c,m,i.x,i.y),Ne(n,e.limitLine,r,a,c,w,i.x,"x"),Ne(n,e.limitLine,r,a,m,b,i.y,"y"),Ve(n,r,a);const P=o.length>Lt?Math.ceil(o.length/Lt):1,v=[];for(let L=0;L<o.length;L+=P)v.push(o[L]);n.globalAlpha=Math.max(.15,Math.min(.7,200/v.length));let g;if(d)g=[v];else{const L=new Map;for(const C of v){const A=L.get(C.group);A?A.push(C):L.set(C.group,[C])}g=[...L.values()].sort((C,A)=>A.length-C.length)}se=[];const y=k,p=k+r,f=M,E=M+a;for(const L of g)for(const C of L){const A=k+c.frac(C.x)*r,D=M+(1-m.frac(C.y))*a;A<y||A>p||D<f||D>E||(se.push({p:C,cx:A,cy:D}),n.beginPath(),n.arc(A,D,2.5,0,Math.PI*2),n.fillStyle=d&&C.value!==void 0?$((C.value-d.lo)/(d.hi-d.lo||1)):oe(C.group),n.fill())}n.globalAlpha=1;const N=i.marks;if(N.type==="scatter"&&(N.identity||N.fits)){const L=(A,D)=>[k+c.frac(A)*r,M+(1-m.frac(D))*a],C=(A,D,x)=>{n.save(),n.beginPath(),n.rect(k,M,r,a),n.clip(),n.strokeStyle=D,n.lineWidth=2,n.setLineDash(x),n.beginPath();for(let ge=0;ge<=60;ge++){const Ce=ge/60,Oe=c.log?10**(Math.log10(c.lo)+(Math.log10(c.hi)-Math.log10(c.lo))*Ce):c.lo+(c.hi-c.lo)*Ce,[we,fe]=L(Oe,A(Oe));ge===0?n.moveTo(we,fe):n.lineTo(we,fe)}n.stroke(),n.restore()};N.identity&&C(A=>A,e.textMuted,[6,4]);for(const A of N.fits??[])W.size>0&&!W.has(A.group)&&!d||C(D=>A.intercept+A.slope*D,d?e.text:oe(A.group),[])}const _=de?se.find(L=>L.p===de):void 0;if(_&&(n.beginPath(),n.arc(_.cx,_.cy,5,0,Math.PI*2),n.lineWidth=2,n.strokeStyle=e.text,n.stroke()),Xe.size>0){n.lineWidth=1.5,n.strokeStyle=e.text;let L=0;for(const C of Xe)if(!(W.size>0&&!W.has(C.group))){if(++L>Lt)break;n.beginPath(),n.arc(k+c.frac(C.x)*r,M+(1-m.frac(C.y))*a,4,0,Math.PI*2),n.stroke()}}}function sn(){if(Ae=void 0,!i||i.marks?.type!=="histogram"||!i.x)return;const e=i.marks.values,l=e.flat();if(l.length===0)return;const s=ue(Ie(Be(l,i.x),Ee(i.x),i.x),i.x),r=Math.max(1,i.spec.bins??Jn),a=s.log?Math.log10(s.lo):s.lo,u=s.log?Math.log10(s.hi):s.hi,n=Array.from({length:r+1},(b,c)=>{const m=a+(u-a)*c/r;return s.log?10**m:m}),t=e.map(()=>new Array(r).fill(0));e.forEach((b,c)=>{for(const m of b){const P=s.log?m>0?Math.log10(m):NaN:m;if(!Number.isFinite(P)||P<a||P>u)continue;const v=Math.min(r-1,Math.floor((P-a)/(u-a)*r));t[c][v]++}});const o=i.spec.histNorm==="percent",d=o?t.map(b=>{const c=b.reduce((m,P)=>m+P,0);return b.map(m=>c?m/c*100:0)}):t;let $=0;const w=e.map(()=>{});if(i.spec.normalCurve&&!s.log){const b=(n[n.length-1]-n[0])/r;e.forEach((c,m)=>{const P=c.filter(Number.isFinite);if(P.length<2)return;const v=P.reduce((y,p)=>y+p,0)/P.length,g=Math.sqrt(An(P,v));g>0&&(w[m]={mean:v,sd:g},$=Math.max($,(o?100:t[m].reduce((y,p)=>y+p,0))*b/(g*Math.sqrt(2*Math.PI))))})}Ae={edges:n,counts:t,heights:d,normal:w,maxCount:Math.max(o?.001:1,$,...d.map(b=>ke(b)))}}function an(){if(!i||!S||!Ae||!i.x||!i.y)return;Re(S,J??0);const e=_e(I),{w:l,h:s,plotW:r,plotH:a}=We(),u=ze(S,I,l,s);if(!u)return;const{ctx:n}=u,{edges:t,counts:o,heights:d,normal:$,maxCount:w}=Ae,b=ue([t[0],t[t.length-1]],{...i.x,min:t[0],max:t[t.length-1]}),c=ue([0,w],{label:i.y.label,scale:"linear",min:0,max:w*1.05});K={x:b,y:c,plotW:r,plotH:a},qe(n,e,l,s,r,a,b,c,i.x,i.y),Ne(n,e.limitLine,r,a,b,Ee(i.x),i.x,"x"),Ve(n,r,a);const m=o.map((v,g)=>g).filter(v=>W.size===0||W.has(v)),P=m.length>1;for(const v of m)n.globalAlpha=P?.55:.85,n.fillStyle=oe(v),d[v].forEach((g,y)=>{if(g===0)return;const p=k+Math.min(b.frac(t[y]),b.frac(t[y+1]))*r,f=k+Math.max(b.frac(t[y]),b.frac(t[y+1]))*r,E=M+(1-c.frac(g))*a;n.fillRect(p,E,Math.max(1,f-p-1),M+a-E)});if(n.globalAlpha=1,i.spec.normalCurve&&!b.log){const v=(t[t.length-1]-t[0])/(t.length-1);for(const g of m){const y=$[g];if(!y)continue;const{mean:p,sd:f}=y,E=(i.spec.histNorm==="percent"?100:o[g].reduce((N,_)=>N+_,0))*v;n.save(),n.beginPath(),n.rect(k,M,r,a),n.clip(),n.strokeStyle=oe(g),n.lineWidth=2,n.beginPath();for(let N=0;N<=120;N++){const _=t[0]+(t[t.length-1]-t[0])*N/120,L=Math.exp(-.5*((_-p)/f)**2)/(f*Math.sqrt(2*Math.PI)),C=k+b.frac(_)*r,A=M+(1-c.frac(E*L))*a;N===0?n.moveTo(C,A):n.lineTo(C,A)}n.stroke(),n.restore()}}if(me>=0){const v=k+Math.min(b.frac(t[me]),b.frac(t[me+1]))*r,g=k+Math.max(b.frac(t[me]),b.frac(t[me+1]))*r;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(v,M,Math.max(1,g-v),a)}}function rn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||!e||e.type!=="box"&&e.type!=="bar")return;Re(S,J??0);const l=_e(I),s=i.spec.orientation==="horizontal",r=e.nest?e.nest.parts.map(T=>T[T.length-1]):e.categories,a=e.categories.length,u=i.groups.length,n=T=>W.size===0||W.has(T),t=e.type==="bar"&&!!e.stack,o=(T,O)=>e.type==="bar"?Number.isFinite(e.values[T][O]):e.cells[T][O].length>0,d=Array.from({length:a},(T,O)=>Array.from({length:u},(F,G)=>G).filter(F=>n(F)&&o(F,O))),$=categoryLayout(t?d.map(T=>T.length?[0]:[]):d),w=S.getContext("2d"),b=T=>w?w.measureText(T).width:T.length*6;w&&(w.font=`${te(-1)}px system-ui, sans-serif`);const c=(T,O)=>T.length>O?`${T.slice(0,O-1)}\u2026`:T;let m=!1,P={inner:0,outer:[]},v=0;if(s){P={inner:Math.min(200,ke(r.map(O=>b(c(O,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((O,F)=>Math.min(140,ke(e.nest.parts.map(G=>b(c(G[F],20)))))):[]},k=Math.max(wt,30+P.inner+6+P.outer.reduce((O,F)=>O+F+10,0)),e.cumulative&&(M=Pt+18),De=Ge;const T=Math.max(1,...d.map(O=>t?Math.min(1,O.length):O.length));v=Math.max(22,T*Zn/.8)}else{const T=ke(r.map(G=>b(c(G,22)))),O=Math.max(10,B.clientWidth-k-mt)/Math.max(1,a);m=T+8>O;const F=e.nest?e.nest.levels.length-1:0;De=(m?Ge+Math.min(110,T*.72):Ge)+F*bt}const g=e.type==="bar"&&!t&&!!i.spec.valueLabels,y=i.y.unit,p=T=>ee(T,y),f=g?ke(e.values.flat().filter(Number.isFinite).map(T=>b(p(T))).concat(0))+8:0,E=s?f:e.cumulative?40:0,{w:N,h:_,plotW:L,plotH:C}=We(),A=Math.max(10,L-E),D=ze(S,I,N,_);if(!D)return;const{ctx:x}=D,ge=T=>T.filter(Number.isFinite),Ce=Ee(i.y),Oe=t?e.categories.map((T,O)=>e.values.reduce((F,G,Y)=>F+(n(Y)&&Number.isFinite(G[O])?G[O]:0),0)):[],we=e.type==="bar"?[...t?Oe:ge(e.values.flat()),0]:ge(e.cells.flat(2));x.font=`${te(-1)}px system-ui, sans-serif`;const fe=s?f:te(-1)+6;if(g&&!s&&we.length){const T=ke(we);T>0&&we.push(T*(1+fe/Math.max(1,C-fe)))}const Pe=ue(Ie(Be(we,i.y),Ce,i.y),i.y,{floorAtZero:e.type==="bar"});K={x:Pe,y:Pe,plotW:A,plotH:C};const ot=s?C:A,Ke=s&&a*v>C+.5,lt=Ke?a*v:ot,st=Ke?Math.max(0,Math.min(tt,lt-ot)):0;tt=st,Mn(Ke,lt,st,A+E,C),s?on(x,l,N,_,A,C,{labels:r,rotate:!1,nest:e.nest?.parts},P,Pe,i.x,i.y,{along:lt,offset:st}):qe(x,l,N,_,A,C,{labels:r,rotate:m,nest:e.nest?.parts},Pe,i.x,i.y);const ye=lt/a,Le=$.width*ye;ne={slotW:ye,n:a,plotW:lt,layout:$,across:s,offset:st,view:ot};const le=T=>s?k+Pe.frac(T)*A:M+(1-Pe.frac(T))*C,be=T=>s?M+T-st:k+T,kt=Pe.log?s?k:M+C:le(0),Ze=(T,O,F,G)=>s?[Math.min(F,G),be(T),Math.max(1,Math.abs(G-F)),O-T]:[be(T),Math.min(F,G),O-T,Math.max(1,Math.abs(G-F))],Tt=(T,O,F,G)=>{x.beginPath(),s?(x.moveTo(O,be(T)),x.lineTo(G,be(F))):(x.moveTo(be(T),O),x.lineTo(be(F),G)),x.stroke()},Qe=T=>s?T>=kt:T<=kt,wn=T=>s?te(-1)<=Le+4:x.measureText(p(T)).width<=Le+6,Nt=g&&e.values.every(T=>T.every(O=>!Number.isFinite(O)||wn(O)));if(Nt){for(let T=0;T<u;T++)if(n(T))for(let O=0;O<a;O++){const F=$.left(O,T),G=e.values[T][O];if(F===void 0||!Number.isFinite(G))continue;const Y=be(O*ye+F*ye+Le/2),H=x.measureText(p(G)).width,X=le(G);s?Ue.push(Qe(X)?{x0:X,x1:X+H+6,y0:Y-fe/2,y1:Y+fe/2}:{x0:X-H-6,x1:X,y0:Y-8,y1:Y+8}):Ue.push(Qe(X)?{x0:Y-H/2,x1:Y+H/2,y0:X-fe,y1:X}:{x0:Y-H/2,x1:Y+H/2,y0:X,y1:X+fe})}}const Pn=Ne(x,l.limitLine,A,C,Pe,Ce,i.y,s?"x":"y",{halo:l.bg}),Ln=Ve(x,A,C,Ke);if(t){ne.stacks=[];for(let T=0;T<a;T++){const O=$.left(T,0),F=[];if(ne.stacks.push(F),O===void 0)continue;let G=0;for(let Y=0;Y<u;Y++){const H=e.values[Y][T];if(!n(Y)||!Number.isFinite(H)||H<=0)continue;const X=le(G),ae=le(G+H);x.fillStyle=oe(Y),x.globalAlpha=.9;const re=T*ye+O*ye;x.fillRect(...Ze(re+1,re+Le-1,X,ae)),x.globalAlpha=1,F.push({g:Y,p0:Math.min(X,ae),p1:Math.max(X,ae)}),G+=H}}}for(let T=0;T<u&&!t;T++){if(W.size>0&&!W.has(T))continue;const O=oe(T);for(let F=0;F<a;F++){const G=$.left(F,T);if(G===void 0)continue;const Y=F*ye+G*ye;if(e.type==="bar"){const H=e.values[T][F];if(!Number.isFinite(H))continue;const X=le(H);if(x.fillStyle=O,x.globalAlpha=.9,x.fillRect(...Ze(Y+1,Y+Le-1,kt,X)),x.globalAlpha=1,Nt){x.fillStyle=l.text,x.font=`${te(-1)}px system-ui, sans-serif`;const ae=be(Y+Le/2);s?(x.textBaseline="middle",x.textAlign=Qe(X)?"left":"right",x.fillText(p(H),X+(Qe(X)?3:-3),ae)):(x.textAlign="center",x.textBaseline=Qe(X)?"bottom":"top",x.fillText(p(H),ae,X+(Qe(X)?-2:2)))}}else{const H=e.cells[T][F];if(H.length===0)continue;const X=Y+Le/2,ae=Math.max(3,Math.min(Le*.7,46)),re=zt(Float64Array.from(H));if(x.strokeStyle=O,x.fillStyle=O,x.lineWidth=1.5,H.length===1){x.beginPath(),s?x.arc(le(re.median),be(X),3,0,Math.PI*2):x.arc(be(X),le(re.median),3,0,Math.PI*2),x.fill();continue}Tt(X,le(re.min),X,le(re.max));for(const Ot of[re.min,re.max])Tt(X-ae/4,le(Ot),X+ae/4,le(Ot));x.globalAlpha=.35,x.fillRect(...Ze(X-ae/2,X+ae/2,le(re.q1),le(re.q3))),x.globalAlpha=1,x.strokeRect(...Ze(X-ae/2,X+ae/2,le(re.q1),le(re.q3))),x.lineWidth=2.5,Tt(X-ae/2,le(re.median),X+ae/2,le(re.median))}}}Ln(),Pn();const Ft=ie?$.left(ie.c,t?0:ie.g):void 0;if(ie&&Ft!==void 0){Ke&&(x.save(),x.beginPath(),x.rect(k-1,M,A+2,C),x.clip()),x.lineWidth=1.5,x.strokeStyle=l.text;const T=ie.c*ye+Ft*ye,O=t?ne.stacks?.[ie.c]?.find(F=>F.g===ie.g):void 0;t&&O?x.strokeRect(...Ze(T,T+Le,O.p0,O.p1)):t||x.strokeRect(...Ze(T,T+Le,s?k:M,s?k+A:M+C)),Ke&&x.restore()}if(e.cumulative){const T=F=>s?k+F/100*A:M+(1-F/100)*C,O=(F,G)=>s?[T(G),be((F+.5)*ye)]:[be((F+.5)*ye),T(G)];if(x.save(),x.strokeStyle=l.text,x.fillStyle=l.text,x.lineWidth=1.5,x.beginPath(),e.cumulative.forEach((F,G)=>{const[Y,H]=O(G,F);G===0?x.moveTo(Y,H):x.lineTo(Y,H)}),x.stroke(),e.cumulative.forEach((F,G)=>{const[Y,H]=O(G,F);x.beginPath(),x.arc(Y,H,2.5,0,Math.PI*2),x.fill()}),x.strokeStyle=l.border,x.lineWidth=1,x.beginPath(),s?(x.moveTo(k,M),x.lineTo(k+A,M)):(x.moveTo(k+A,M),x.lineTo(k+A,M+C)),x.stroke(),x.fillStyle=l.textMuted,x.font=`${te(-1)}px system-ui, sans-serif`,s){x.textAlign="center",x.textBaseline="bottom";for(const F of[0,25,50,75,100])x.fillText(`${F}%`,T(F),M-3)}else{x.textAlign="left",x.textBaseline="middle";for(const F of[0,25,50,75,100])x.fillText(`${F}%`,k+A+4,T(F))}x.restore()}}function cn(e){const l=i?.setTests,s=l?l.labels.indexOf(e):-1;return s>=0?{test:l.tests[s]}:{}}function vt(e){if(!ne||!S)return null;const l=S.getBoundingClientRect(),s=ne.across?e.clientY-l.top-M:e.clientX-l.left-k;if(s<0||s>ne.view)return null;const r=s+ne.offset,a=Math.min(ne.n-1,Math.floor(r/ne.slotW)),u=ne.layout.groupAt(a,(r-a*ne.slotW)/ne.slotW);if(u===void 0)return null;if(!ne.stacks)return{g:u,c:a};const n=ne.across?e.clientX-l.left:e.clientY-l.top,t=ne.stacks[a]?.find(o=>n>=o.p0&&n<=o.p1);return t?{g:t.g,c:a}:null}function fn(e,l,s){let r=0,a=0,u=0;for(const o of l)o===100&&r++;if(e.failSide)for(const o of s){const d=e.failSide[o];d<0?a++:d>0&&u++}const n=o=>o.toLocaleString("en-GB"),t=a+u>0?` (${n(a)} below the low limit \xB7 ${n(u)} above the high limit)`:"";return`${n(r)} pass \xB7 ${n(l.length-r)} fail${t} \xB7 n = ${n(l.length)}`}function un(e){const l=i,s=l.marks,r=l.level==="die"?"dies":"wafers",a=s.cells[e.g][e.c],u=s.nest?s.nest.parts[e.c]:[s.categories[e.c]],n=l.groups.length>1&&!u.includes(je(e.g))?` \xB7 ${U(je(e.g))}`:"",t=`<strong>${U(s.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(a.length===0)return`${t}no ${r}`;const d=`${a.length.toLocaleString("en-GB")} ${r}`,$=(s.categoryItems&&h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")+(s.categoryItems&&h.onWaferMenu?Zt:"");if(s.type==="bar"){const b=s.values[e.g][e.c],c=s.cumulative?`<br>${U(`cumulative: ${s.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${U(`${l.y.label}: ${ee(b,o)}`)}<br>${U(s.passFail?fn(s.passFail,a,s.cellUnits[e.g][e.c]):d)}${c}${$}`}const w=zt(Float64Array.from(a));return`${t}${["max","q3","median","q1","min"].map(b=>U(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[b]}: ${ee(w[b],o)}`)).join("<br>")}<br>${U(d)}${$}`}function hn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||!e||e.type!=="line")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=Ee(i.x),d=Ee(i.y),$=ue(Ie(Be(e.xs,i.x),o,i.x),i.x),w=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],b=ue(Ie(Be([...e.values.flat(),...w].filter(Number.isFinite),i.y),d,i.y),i.y);if(K={x:$,y:b,plotW:a,plotH:u},qe(t,l,s,r,a,u,$,b,i.x,i.y),Ne(t,l.limitLine,a,u,$,o,i.x,"x"),Ne(t,l.limitLine,a,u,b,d,i.y,"y"),Ve(t,a,u),he=e.xs.map(c=>k+$.frac(c)*a),e.band){const c=m=>M+(1-b.frac(m))*u;e.band.lo.forEach((m,P)=>{if(W.size>0&&!W.has(P))return;const v=e.band.hi[P];t.save(),t.fillStyle=oe(P),t.globalAlpha=.16;let g=[];const y=()=>{if(g.length===1){const p=g[0],f=he[p];t.globalAlpha=.55,t.strokeStyle=oe(P),t.lineWidth=2,t.beginPath(),t.moveTo(f,c(m[p])),t.lineTo(f,c(v[p])),t.moveTo(f-4,c(m[p])),t.lineTo(f+4,c(m[p])),t.moveTo(f-4,c(v[p])),t.lineTo(f+4,c(v[p])),t.stroke(),t.globalAlpha=.16}else if(g.length){t.beginPath(),g.forEach((p,f)=>{f===0?t.moveTo(he[p],c(v[p])):t.lineTo(he[p],c(v[p]))});for(let p=g.length-1;p>=0;p--)t.lineTo(he[g[p]],c(m[g[p]]));t.closePath(),t.fill()}g=[]};m.forEach((p,f)=>{Number.isFinite(p)&&Number.isFinite(v[f])?g.push(f):y()}),y(),t.restore()})}e.values.forEach((c,m)=>{if(W.size>0&&!W.has(m))return;t.strokeStyle=oe(m),t.fillStyle=oe(m),t.lineWidth=2;let P=!1;t.beginPath(),c.forEach((v,g)=>{if(!Number.isFinite(v)){P=!1;return}const y=he[g],p=M+(1-b.frac(v))*u;P?t.lineTo(y,p):t.moveTo(y,p),P=!0}),t.stroke(),c.forEach((v,g)=>{Number.isFinite(v)&&(t.beginPath(),t.arc(he[g],M+(1-b.frac(v))*u,Me===g?4.5:3,0,Math.PI*2),t.fill())})}),Me>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(he[Me],M),t.lineTo(he[Me],M+u),t.stroke())}function Mt(e){const l=i?.marks;if(!l||l.type!=="line"||!S||!i?.x||he.length===0)return null;const s=e.clientX-S.getBoundingClientRect().left;let r=-1,a=24;if(he.forEach((t,o)=>{const d=Math.abs(t-s);d<a&&(a=d,r=o)}),Me=r,r<0)return null;const u=i.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[r],n:l.counts[o][r]})).filter(t=>Number.isFinite(t.v)&&(W.size===0||W.has(t.g)));return`<strong>${U(`${i.x.label}: ${ee(l.xs[r],i.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][r],d=l.band?.hi[t.g][r],$=o!==void 0&&d!==void 0&&Number.isFinite(o)&&Number.isFinite(d)?`, band ${ee(o,i.y.unit)} to ${ee(d,i.y.unit)}`:"";return U(`${i.groups.length>1?`${je(t.g)}: `:""}${ee(t.v,i.y.unit)}${$} (${t.n.toLocaleString("en-GB")} ${u})`)}).join("<br>")+(h.onWaferMenu&&Bt(r)!==void 0?Zt:"")}function Bt(e){const l=i?.marks;if(l?.type!=="line")return;const s=new Set(l.cellUnits.flatMap((r,a)=>W.size>0&&!W.has(a)?[]:(r[e]??[]).map(u=>l.unit(u).item)));return s.size===1?[...s][0]:void 0}function dn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="probability")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=i.spec.probabilityAxis==="linear",d=e.values.map((L,C)=>C).filter(L=>e.values[L].length>0&&(W.size===0||W.has(L))),$=Math.max(1,...d.map(L=>e.values[L].length)),w=Math.min(.01,it(0,$)),b=L=>o?L:_t(L),c=o?0:b(w),m=o?1:b(1-w),P=o?0:(m-c)*.03,v=ue([c-P,m+P],{label:i.y.label,scale:"linear",min:c-P,max:m+P}),g=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:eo.filter(L=>L>=w&&L<=1-w),y=[],p=L=>M+(1-v.frac(L))*u,f=g.indexOf(.5);y.push({at:b(.5),label:en(.5)});for(const L of[g.slice(f+1),g.slice(0,f).reverse()]){let C=p(b(.5));for(const A of L){const D=p(b(A));Math.abs(D-C)<16||(y.push({at:b(A),label:en(A)}),C=D)}}const E=Ee(i.x),N=ue(Ie(Be(d.flatMap(L=>[e.values[L][0],e.values[L][e.values[L].length-1]]),i.x),E,i.x),i.x);K={x:N,y:v,plotW:a,plotH:u},qe(t,l,s,r,a,u,N,v,i.x,i.y,y),Ne(t,l.limitLine,a,u,N,E,i.x,"x"),Ve(t,a,u),se=[],t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip();for(const L of d){const C=e.values[L],A=C.length,D=to(A);if(t.strokeStyle=oe(L),t.fillStyle=oe(L),t.lineWidth=1.5,t.beginPath(),D.forEach((x,ge)=>{const Ce=k+N.frac(C[x])*a,Oe=p(b(it(x,A)));ge===0?t.moveTo(Ce,Oe):t.lineTo(Ce,Oe);const we=L*2**26+x;let fe=pt.get(we);if(!fe){const{item:Pe,die:ot}=e.unit(e.units[L][x]);fe={x:C[x],y:it(x,A),group:L,item:Pe,die:ot},pt.set(we,fe)}se.push({p:fe,cx:Ce,cy:Oe})}),t.stroke(),A<=300)for(const x of D)t.beginPath(),t.arc(k+N.frac(C[x])*a,p(b(it(x,A))),2.5,0,Math.PI*2),t.fill()}t.restore();const _=de?se.find(L=>L.p===de):void 0;_&&(t.beginPath(),t.arc(_.cx,_.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function mn(e){const l=i,r=l.marks.values[e.group].length,a=Math.round(e.y*r+.5),u=h.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[u,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${U(t)}</strong><br>`:"")+U(`${l.x.label}: ${ee(e.x,l.x.unit)}`)+"<br>"+U(`rank ${a.toLocaleString("en-GB")} of ${r.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${U(je(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}let Fe,pe=null;function pn(){const e=i?.marks;if(!i||!S||e?.type!=="heatmap")return;Re(S,J??0);const l=_e(I),s=S.getContext("2d");let r=0,a=0;s&&(s.font=`${te(-1)}px system-ui, sans-serif`,r=ke(e.rows.map(p=>s.measureText(p.length>24?`${p.slice(0,23)}\u2026`:p).width)),a=ke(e.cols.map(p=>s.measureText(p.length>22?`${p.slice(0,21)}\u2026`:p).width)));const u=Math.min(180,Math.max(k,r+24)),n=Math.max(8,B.clientWidth-u-mt)/Math.max(1,e.cols.length),t=a+8>n;De=t?Ge+Math.min(110,a*.72):Ge;const{w:o,h:d}=We(),$=Math.max(10,o-u-mt),w=Math.max(10,d-M-De),b=ze(S,I,o,d);if(!b)return;const{ctx:c}=b,m=$/e.cols.length,P=w/e.rows.length;Fe={left:u,cw:m,ch:P,rows:e.rows.length,cols:e.cols.length};const v=i.colorScale,g=dt(),y=v&&v.hi-v.lo||1;c.font=`${te(-1)}px system-ui, sans-serif`;for(let p=0;p<e.rows.length;p++)for(let f=0;f<e.cols.length;f++){const E=e.values[p][f],N=u+f*m,_=M+p*P;c.fillStyle=Number.isFinite(E)&&v?g((E-v.lo)/y):l.track,c.fillRect(N+.5,_+.5,Math.max(1,m-1),Math.max(1,P-1)),Number.isFinite(E)&&m>=40&&P>=16&&(c.fillStyle="#fff",c.textAlign="center",c.textBaseline="middle",St(c,At(E,i.y?.unit,v?.integer),N+m/2,_+P/2,"rgba(0,0,0,0.55)"))}pe&&(c.lineWidth=2,c.strokeStyle=l.text,c.strokeRect(u+pe.c*m,M+pe.r*P,m,P)),c.fillStyle=l.textMuted,c.textAlign="right",c.textBaseline="middle",e.rows.forEach((p,f)=>c.fillText(p.length>24?`${p.slice(0,23)}\u2026`:p,u-6,M+(f+.5)*P)),e.cols.forEach((p,f)=>{const E=p.length>22?`${p.slice(0,21)}\u2026`:p,N=u+(f+.5)*m;t?(c.save(),c.translate(N,M+w+6),c.rotate(-Math.PI/4),c.textAlign="right",c.textBaseline="middle",c.fillText(E,0,0),c.restore()):(c.textAlign="center",c.textBaseline="top",c.fillText(E,N,M+w+4))}),c.font=`${te(0)}px system-ui, sans-serif`,c.fillStyle=l.text,c.textAlign="center",c.textBaseline="bottom",c.fillText(i.x?.label??"",u+$/2,d-6)}function Wt(e){if(!Fe||!S)return null;const l=S.getBoundingClientRect(),s=Math.floor((e.clientX-l.left-Fe.left)/Fe.cw),r=Math.floor((e.clientY-l.top-M)/Fe.ch);return r>=0&&r<Fe.rows&&s>=0&&s<Fe.cols?{r,c:s}:null}function gn(e){const l=i,s=l.marks,r=s.values[e.r][e.c],a=s.cellUnits[e.r][e.c].length,u=l.level==="die"?"dies":"wafers";return`<strong>${U(`${s.rows[e.r]} \xB7 ${s.cols[e.c]}`)}</strong><br>`+(Number.isFinite(r)?U(`${l.y?.label??"Count"}: ${At(r,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+U(`${a.toLocaleString("en-GB")} ${u}`)+(a&&h.onSelectPoints?"<br><em>click to chart or tabulate them</em>":"")}function yn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="control")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=e.limits,d=Ee(i.y),$=ue(Be(e.xs,i.x),i.x),w=ue(Ie(Be([...e.values,o.ucl,o.lcl],i.y),d,i.y),i.y);K={x:$,y:w,plotW:a,plotH:u},qe(t,l,s,r,a,u,$,w,i.x,i.y),Ne(t,l.limitLine,a,u,w,d,i.y,"y"),Ve(t,a,u);const b=y=>k+$.frac(e.xs[y])*a,c=y=>M+(1-w.frac(y))*u;t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip();const m=(y,p,f,E=1)=>{t.globalAlpha=f,t.setLineDash(p),t.lineWidth=E,t.strokeStyle=l.text,t.beginPath(),t.moveTo(k,c(y)),t.lineTo(k+a,c(y)),t.stroke()};for(const y of[-2,-1,1,2])m(o.centre+y*o.sigma,[2,4],.25);m(o.centre,[],.6,1.5),m(o.ucl,[6,4],.85),m(o.lcl,[6,4],.85),t.restore(),t.fillStyle=l.textMuted,t.font=`${te(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const P=y=>ee(y,i.y.unit);if(t.fillText(`UCL ${P(o.ucl)}`,k+a-4,c(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${P(o.lcl)}`,k+a-4,c(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${P(o.centre)}`,k+a-4,c(o.centre)-2),o.baseline<e.values.length){const y=(b(o.baseline-1)+b(o.baseline))/2;t.save(),t.strokeStyle=l.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(y,M),t.lineTo(y,M+u),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",k+4,M+2)}t.strokeStyle=oe(0),t.lineWidth=1.5,t.setLineDash([]),t.beginPath(),e.values.forEach((y,p)=>{p===0?t.moveTo(b(p),c(y)):t.lineTo(b(p),c(y))}),t.stroke();const v=new Map(e.violations.map(y=>[y.index,y.rules]));se=[],e.values.forEach((y,p)=>{const f=v.get(p);t.beginPath(),t.arc(b(p),c(y),f?4.5:3,0,Math.PI*2),t.fillStyle=f?l.alert:oe(0),t.fill(),f&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(f.join(","),b(p),c(y)-6)),se.push({p:{x:e.xs[p],y,group:0,item:e.items[p]},cx:b(p),cy:c(y)})});const g=de?se.find(y=>y.p===de):void 0;g&&(t.beginPath(),t.arc(g.cx,g.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function bn(e){const l=i,s=l.marks,r=s.items.indexOf(e.item),a=(e.y-s.limits.centre)/s.limits.sigma,u=s.violations.find(n=>n.index===r)?.rules;return`<strong>${U(h.waferLabel(e.item))}</strong><br>`+U(`${l.y.label}: ${ee(e.y,l.y.unit)} (${a>=0?"+":"\u2212"}${Math.abs(a).toFixed(1)}\u03C3)`)+(u?`<br>${U(`breaks rule ${u.map(n=>`${n} (${En[n]})`).join(", ")}`)}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}function xn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="goal")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(f=>Math.abs(f.x))),d=ue([-o,o],{...i.x,min:i.x.min??-o*1.05,max:i.x.max??o*1.05}),$=ue([0,...e.points.map(f=>f.y),1/6],{...i.y,min:i.y.min??0},{floorAtZero:!0});K={x:d,y:$,plotW:a,plotH:u},qe(t,l,s,r,a,u,d,$,i.x,i.y);const w=f=>k+d.frac(f)*a,b=f=>M+(1-$.frac(f))*u;t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip(),t.font=`${te(-1)}px system-ui, sans-serif`;const c=[[1,[6,4]],[1.33,[]]];for(const[f,E]of c){const N=1/(6*f);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(E),t.beginPath(),t.moveTo(w(-.5),b(0)),t.lineTo(w(0),b(N)),t.lineTo(w(.5),b(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${f}`,w(0)+4,b(N)-2)}t.restore(),se=[];const m=e.points.filter(f=>W.size===0||W.has(f.group));for(const f of m)t.beginPath(),t.arc(w(f.x),b(f.y),4,0,Math.PI*2),t.fillStyle=oe(f.group),t.fill(),se.push({p:{x:f.x,y:f.y,group:f.group,item:-1,value:f.testNumber},cx:w(f.x),cy:b(f.y)});const P=m.map(f=>({x0:w(f.x)-5,x1:w(f.x)+5,y0:b(f.y)-5,y1:b(f.y)+5})),v={x0:k,x1:k+a,y0:M,y1:M+u},g=f=>f.x0>=v.x0&&f.x1<=v.x1&&f.y0>=v.y0&&f.y1<=v.y1&&!P.some(E=>f.x0<E.x1&&f.x1>E.x0&&f.y0<E.y1&&f.y1>E.y0),y=te(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const f of[...m].filter(E=>E.ppk<1.33).sort((E,N)=>E.ppk-N.ppk)){const E=w(f.x),N=b(f.y),_=t.measureText(f.label).width,L=[[E+7,N,"left"],[E-7,N,"right"],[E,N-13,"center"],[E,N+13,"center"]];for(const[C,A,D]of L){const x=D==="left"?C:D==="right"?C-_:C-_/2,ge={x0:x,x1:x+_,y0:A-y/2,y1:A+y/2};if(g(ge)){P.push(ge),t.textAlign=D,t.fillText(f.label,C,A);break}}}const p=de?se.find(f=>f.p===de):void 0;p&&(t.beginPath(),t.arc(p.cx,p.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function vn(e){const l=i,r=l.marks.points.find(a=>a.testNumber===e.value&&a.group===e.group);return r?`<strong>${U(r.label)}</strong>${l.groups.length>1?` \xB7 ${U(je(r.group))}`:""}<br>`+U(`Ppk ${r.ppk.toFixed(2)} \xB7 ${r.n.toLocaleString("en-GB")} dies`)+"<br>"+U(`mean ${r.x>=0?"+":"\u2212"}${Math.abs(r.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(r.y*100).toFixed(1)}% of it (${r.basis==="spec"?"spec":"test"} limits)`):""}function Mn(e,l,s,r,a){!$e||!S||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${S.offsetTop+M}px`,height:`${a}px`,left:`${S.offsetLeft+k+r+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-s)>=1&&($e.scrollTop=s)))}function Z(){$e&&($e.style.display="none"),rt&&!tn()&&(rt.style.maxHeight=Yt(I)?"":`${Qn}px`),Q&&h.panel&&(Q.style.display=Yt(I)?"flex":"none"),k=wt,M=Pt;const e=i?.marks?.type;e==="scatter"?ln():e==="control"?yn():e==="heatmap"?pn():e==="goal"?xn():e==="probability"?dn():e==="histogram"?an():e==="box"||e==="bar"?rn():e==="line"&&hn(),Ct()}function kn(e){const l=i,s=h.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",a=[s,r].filter(Boolean).join(" \xB7 "),u=(n,t)=>`${n.label}: ${ee(t,n.unit)}`;return(a?`<strong>${U(a)}</strong><br>`:"")+U(u(l.x,e.x))+"<br>"+U(u(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${U(`${l.colorScale.label}: ${ee(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${U(je(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}function It(e){if(!Ae||!K||!i?.x)return null;const l=S.getBoundingClientRect(),r=(e.clientX-l.left-k)/K.plotW;if(r<0||r>1)return null;const a=K.x.reverse?1-r:r,{edges:u,counts:n}=Ae,t=u.length-1,o=Math.min(t-1,Math.max(0,Math.floor(a*t)));me=o;const d=i.x,$=n.map((w,b)=>({g:b,n:w[o]})).filter(w=>w.n>0&&(W.size===0||W.has(w.g)));return`<strong>${U(`${ee(u[o],d.unit)} to ${ee(u[o+1],d.unit)}`)}</strong><br>`+($.length?$.map(w=>{const b=i.spec.histNorm==="percent"?` (${Ae.heights[w.g][o].toFixed(1)}% of ${i.groups.length>1?"its colour":"them"})`:"";return U(`${i.groups.length>1?`${je(w.g)}: `:""}${w.n.toLocaleString("en-GB")} ${i.level==="die"?"dies":"wafers"}${b}`)}).join("<br>"):"none")}function Tn(e){const l=R.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:xe.md,marginTop:xe.md,marginBottom:xe.xl,fontSize:ut.body,color:Je.label});const s=R.createElement("canvas");s.width=200,s.height=10,Object.assign(s.style,{width:"200px",height:"10px",borderRadius:Wn.control,flex:"0 0 auto"});const r=s.getContext("2d"),a=dt();if(r)for(let d=0;d<200;d++)r.fillStyle=a(d/199),r.fillRect(d,0,1,10);const u=d=>i?.marks?.type==="heatmap"?At(d,e.unit,e.integer):ee(d,e.unit),n=R.createElement("span");n.textContent=u(e.lo);const t=R.createElement("span");t.textContent=u(e.hi);const o=R.createElement("span");return o.textContent=e.label,o.style.color=Je.text,l.append(o,n,s,t),l}const nt=(e,l,s)=>l.map(r=>{const{item:a,die:u}=e(r);return{x:0,y:0,group:s,item:a,die:u}});function Sn(){He?.destroy(),He=void 0,B.innerHTML="",S=void 0,Q=void 0,J=void 0,et=[],de=null,me=-1,se=[],K=void 0,ne=void 0,ie=null,$e=void 0,tt=0,rt=void 0,Fe=void 0,pe=null,he=[],Me=-1,De=Ge,pt=new Map,W.clear(),Xe.clear();for(const n of ce)n.destroy();ce=[],Te(()=>I.querySelector("canvas"));const e=i,l=!!e?.facets&&!h.panel;if(I.style.flex=l?"0 0 auto":"1 1 0px",I.style.gridColumn=l?"1 / -1":"",!e)return;if(j.textContent=h.panel?h.panel.title:Bn(e),I.dataset.wmapChartTitle=j.textContent,e.issues.length||!e.marks){for(const n of e.issues)qt(B,n);return}const s=R.createElement("div");Object.assign(s.style,{color:Je.label,fontSize:ut.body,marginBottom:xe.xs});const r=h.openActionLabel??"open this wafer",a=e.marks.type==="scatter"?(h.onOpenWafer?` \xB7 click a point to ${r}`:"")+(h.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(h.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${r}`:h.onSelectPoints?` \xB7 click to ${h.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&h.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="probability"?(h.onOpenWafer?` \xB7 click a point to ${r}`:"")+(h.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="line"&&h.onSelectPoints?` \xB7 click a point to ${h.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the plot to select ${h.selectRangeLabel??"a run of points"}`:"";s.textContent=h.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:Xt(e)+(e.facets?"":a),h.panel||Nn(s,Ut(e)),Dt(s),J=R.createElement("div"),J.style.display="flow-root",B.appendChild(J),J.appendChild(s);for(const n of e.fitNotes??[]){const t=R.createElement("div");t.dataset.wmapPlotFit="1",t.textContent=n,Object.assign(t.style,{color:Je.text,fontSize:ut.body,marginBottom:xe.xxs,fontVariantNumeric:"tabular-nums"}),J.appendChild(t)}for(const n of e.notes){const t=R.createElement("div");Dt(t),t.textContent=n,Object.assign(t.style,{color:Je.warnText,fontSize:ut.body,marginBottom:xe.xs}),J.appendChild(t)}if(e.plotted===0){qt(B,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&!e.colorRepeatsX&&(Q=R.createElement("div"),Q.dataset.wmapPlotLegend="1",Object.assign(Q.style,{display:h.panel?"none":"flex",flexWrap:"wrap",gap:xe.sm,marginTop:xe.md,marginBottom:xe.xl,overflowY:"auto"}),rt=Q,e.facets&&Object.assign(Q.style,{position:"sticky",top:"0",zIndex:"2",background:Je.menuBg,paddingBottom:xe.sm,marginBottom:xe.md}),e.groups.forEach((n,t)=>{const o=Xn(n||"(none)",oe(t),R),d=h.onLegendPick&&h.legendPicked===n;Rn(o.el,I,z,h.onLegendPick?d?`${n||"(none)"} \u2014 click to show every group again`:`${n||"(none)"} \u2014 click to show only this group in every chart here`:`${n||"(none)"} \u2014 click to filter`),d&&W.add(t),o.el.addEventListener("click",()=>{if(h.onLegendPick){h.onLegendPick(d?null:n);return}if(W.has(t)?W.delete(t):W.add(t),et.forEach(($,w)=>$.setState({selected:W.has(w),dimmed:W.size>0&&!W.has(w)})),ce.length)for(const $ of ce)$.setActiveGroups(W);else Z()}),et.push(o),Q.appendChild(o.el)}),et.forEach((n,t)=>n.setState({selected:W.has(t),dimmed:W.size>0&&!W.has(t)})),J.appendChild(Q)),e.colorScale&&!h.panel&&(Q=Tn(e.colorScale),J.appendChild(Q)),e.facets){const n=R.createElement("div");n.dataset.wmapPlotPanels="1",n.style.isolation="isolate",Object.assign(n.style,{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${no}px, 1fr))`,gap:xe.md}),B.appendChild(n);for(const t of e.facets){const o=renderPlotChart({...h,panel:{title:t.label}});n.appendChild(o.card),o.setPlot(t.plot),ce.push(o)}Te(()=>oo(n));return}S=R.createElement("canvas"),S.style.display="block",S.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",B.appendChild(S);const u=h.onWaferMenu?(n,t)=>{n.die||h.onWaferMenu(n.item,Ye(e.spec),t)}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!h.onSelectPoints;He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:kn,clickable:()=>!!h.onOpenWafer,onOpen:o=>h.onOpenWafer?.(o.item,Ye(e.spec)),onContextMenu:u,onHover:o=>{de=o,Z()},select:t?{pick:({x0:o,y0:d,x1:$,y1:w})=>K?(W.size===0?n.points:n.points.filter(c=>W.has(c.group))).filter(c=>{const m=k+K.x.frac(c.x)*K.plotW,P=M+(1-K.y.frac(c.y))*K.plotH;return m>=o&&m<=$&&P>=d&&P<=w}):[],onPicked:(o,d)=>{Xe.clear();for(const $ of o)Xe.add($);Z(),o.length>0&&h.onSelectPoints(o,d,S)},onClear:()=>{Xe.clear(),Z()},hasSelection:()=>Xe.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const n=e.marks.type==="control";He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:n?bn:vn,clickable:()=>n&&!!h.onOpenWafer,onOpen:t=>{n&&h.onOpenWafer?.(t.item,Ye(e.spec))},onContextMenu:n?u:void 0,onHover:t=>{de=t,Z()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:mn,clickable:()=>!!h.onOpenWafer,onOpen:o=>h.onOpenWafer?.(o.item,Ye(e.spec)),onHover:o=>{de=o,Z()},select:h.onSelectPoints?{pick:({x0:o,y0:d,x1:$,y1:w})=>{if(!K)return[];const b=[];return n.values.forEach((c,m)=>{W.size>0&&!W.has(m)||c.forEach((P,v)=>{const g=it(v,c.length),y=k+K.x.frac(P)*K.plotW,p=M+(1-K.y.frac(t?g:_t(g)))*K.plotH;if(y<o||y>$||p<d||p>w)return;const{item:f,die:E}=n.unit(n.units[m][v]);b.push({x:P,y:g,group:m,item:f,die:E})})}),b},onPicked:(o,d)=>{o.length>0&&h.onSelectPoints(o,d,S)},onClear:()=>{},hasSelection:()=>!1}:void 0})}else if(e.marks.type==="histogram"){sn(),S.addEventListener("mousemove",t=>{const o=It(t);if(!o){z.style.display="none",me>=0&&(me=-1,Z());return}z.innerHTML=o,z.style.display="block",ht(z,I,t.clientX,t.clientY),Z()}),S.addEventListener("mouseleave",()=>{z.style.display="none",me>=0&&(me=-1,Z())});const n=e.marks;h.onSelectPoints&&(S.style.cursor="pointer",S.addEventListener("click",t=>{if(!Ae||It(t)===null)return;const o=me,{edges:d}=Ae,$=K?.x.log,w=$?Math.log10(d[0]):d[0],b=$?Math.log10(d[d.length-1]):d[d.length-1],c=d.length-1,m=[];n.values.forEach((P,v)=>{if(W.size>0&&!W.has(v))return;const g=[];P.forEach((y,p)=>{const f=$?y>0?Math.log10(y):NaN:y;!Number.isFinite(f)||f<w||f>b||Math.min(c-1,Math.floor((f-w)/(b-w)*c))===o&&g.push(n.units[v][p])}),m.push(...nt(n.unit,g,v))}),m.length>0&&(z.style.display="none",h.onSelectPoints(m,{x:t.clientX,y:t.clientY},S,{range:{lo:d[o],hi:d[o+1]},...W.size===1?{group:e.groups[[...W][0]]}:{}}))}))}else if(e.marks.type==="heatmap"){const n=e.marks;S.addEventListener("mousemove",t=>{const o=Wt(t);if(S.style.cursor=o&&h.onSelectPoints&&n.cellUnits[o.r][o.c].length?"pointer":"default",!o){z.style.display="none",pe&&(pe=null,Z());return}z.innerHTML=gn(o),z.style.display="block",ht(z,I,t.clientX,t.clientY),(!pe||pe.r!==o.r||pe.c!==o.c)&&(pe=o,Z())}),S.addEventListener("mouseleave",()=>{z.style.display="none",pe&&(pe=null,Z())}),S.addEventListener("click",t=>{const o=Wt(t);if(!o||!h.onSelectPoints)return;const d=n.cellUnits[o.r][o.c];d.length&&(z.style.display="none",h.onSelectPoints(nt(n.unit,d,0),{x:t.clientX,y:t.clientY},S))})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const t=R.createElement("div");t.dataset.wmapRowScroll="1",t.tabIndex=0,t.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(t.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const o=R.createElement("div");o.style.width="1px",t.appendChild(o),t.addEventListener("scroll",()=>{Math.abs(t.scrollTop-tt)<1||(tt=t.scrollTop,z.style.display="none",Z())}),S.addEventListener("wheel",d=>{if(t.style.display==="none")return;const $=t.scrollTop;t.scrollTop+=d.deltaMode===1?d.deltaY*16:d.deltaY,t.scrollTop!==$&&d.preventDefault()},{passive:!1}),B.appendChild(t),$e=t}S.addEventListener("mousemove",t=>{const o=vt(t);if(S.style.cursor=o&&(n.categoryItems&&h.onOpenWafer||h.onSelectPoints&&n.cellUnits[o.g][o.c].length>0)?"pointer":"default",!o){z.style.display="none",ie&&(ie=null,Z());return}z.innerHTML=un(o),z.style.display="block",ht(z,I,t.clientX,t.clientY),(!ie||ie.g!==o.g||ie.c!==o.c)&&(ie=o,Z())}),S.addEventListener("mouseleave",()=>{z.style.display="none",ie&&(ie=null,Z())}),h.onWaferMenu&&n.categoryItems&&S.addEventListener("contextmenu",t=>{const o=vt(t),d=o?n.categoryItems[o.c]:void 0;d===void 0||d<0||(z.style.display="none",h.onWaferMenu(d,Ye(e.spec),t))}),S.addEventListener("click",t=>{const o=vt(t);if(!o)return;const d=n.categoryItems?.[o.c];if(d!==void 0&&d>=0&&h.onOpenWafer){h.onOpenWafer(d,Ye(e.spec));return}const $=n.cellUnits[o.g][o.c];$.length>0&&h.onSelectPoints&&(z.style.display="none",h.onSelectPoints(nt(n.unit,$,o.g),{x:t.clientX,y:t.clientY},S,{category:n.categories[o.c],...e.groups.length>1?{group:e.groups[o.g]}:{},...cn(n.categories[o.c])}))})}else if(e.marks.type==="line"){S.addEventListener("mousemove",t=>{const o=Mt(t);if(!o){z.style.display="none",Z();return}z.innerHTML=o,z.style.display="block",ht(z,I,t.clientX,t.clientY),Z()}),S.addEventListener("mouseleave",()=>{z.style.display="none",Me>=0&&(Me=-1,Z())});const n=e.marks;if(h.onWaferMenu&&S.addEventListener("contextmenu",t=>{const o=Mt(t)===null?void 0:Bt(Me);o!==void 0&&(z.style.display="none",h.onWaferMenu(o,Ye(e.spec),t))}),h.onSelectPoints){S.style.cursor="pointer";let t=!1;S.addEventListener("mousedown",o=>{if(o.button!==0)return;t=!1;const d=S.getBoundingClientRect(),$=o.clientX-d.left,w=b=>{R.removeEventListener("mouseup",w);const c=b.clientX-d.left;if(Math.abs(c-$)<4)return;t=!0;const[m,P]=$<c?[$,c]:[c,$],v=he.map((y,p)=>y>=m&&y<=P?p:-1).filter(y=>y>=0),g=n.cellUnits.flatMap((y,p)=>W.size>0&&!W.has(p)?[]:v.flatMap(f=>nt(n.unit,y[f]??[],p)));g.length>0&&(z.style.display="none",h.onSelectPoints(g,{x:b.clientX,y:b.clientY},S))};R.addEventListener("mouseup",w)}),S.addEventListener("click",o=>{if(t){t=!1;return}if(Mt(o)===null||Me<0)return;const d=n.cellUnits.flatMap(($,w)=>W.size>0&&!W.has(w)?[]:nt(n.unit,$[Me]??[],w));d.length>0&&(z.style.display="none",h.onSelectPoints(d,{x:o.clientX,y:o.clientY},S))})}}Z()}V(()=>{const e=i;if(!e||!e.marks)return;const l=dt();return{caption:[Xt(e),...e.fitNotes??[],...e.notes,...Hn(Ut(e))],legend:e.groups.length>1&&!e.colorRepeatsX?e.groups.map((s,r)=>({label:s||"(none)",color:oe(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:ee(e.colorScale.lo,e.colorScale.unit),hi:ee(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const $n=Fn(I,()=>Z());return{card:I,actions:q,setPlot(e){i=e,ve(Kn(e.spec)),Sn()},setMenuRows:Se,setActiveGroups(e){W.clear();for(const l of e)W.add(l);et.forEach((l,s)=>l.setState({selected:W.has(s),dimmed:W.size>0&&!W.has(s)})),Z()},destroy(){$n.disconnect(),He?.destroy();for(const e of ce)e.destroy()}}}
|
|
1
|
+
import{escHtml as D,maxOf as Te,minOf as jt}from"../../core/utils.js";import{fiveNumberSummary as Ut,normalQuantile as qt,sampleVariance as Rn}from"../../stats/math.js";import{CONTROL_RULE_TEXT as On}from"../../stats/control.js";import{PAT_VERDICT_LABEL as Yt}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 Gn}from"../../stats/plotTable.js";import{cardShell as Xn,appendGuideCites as Dn,observeResize as jn,makeTooltip as Un,attachChartTip as qn,chartFillHeight as Yn,applyCanvasFlow as Xe,prepareCanvas as De,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,q)=>{const V=m[R].indexOf(q);return V<0?void 0:U(R)+V*W},groupAt:(R,q)=>{const V=Math.floor((q-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,q)=>q);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(),q=m.ownerDocument.createElement("canvas");q.width=Math.ceil(R.width*U),q.height=Math.ceil(R.height*U);const V=q.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,q.width,q.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 q}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,q=m.length?Te(m):1;U&&(R=Math.log10(Math.max(R,Number.MIN_VALUE)),q=Math.log10(Math.max(q,Number.MIN_VALUE)));const V=(q-R)*.05||(U?.5:1);R=W.floorAtZero&&!U&&R>=0?0:R-V,q+=V;const Me=$e=>$e===void 0||!Number.isFinite($e)?void 0:U?$e>0?Math.log10($e):void 0:$e,Se=Me(z.min),ce=Me(z.max);Se!==void 0&&(R=Se),ce!==void 0&&(q=ce),q>R||(q=R+1);const _=q-R,s=!!z.reverse,Oe=$e=>{const C=((U?Math.log10(Math.max($e,Number.MIN_VALUE)):$e)-R)/_;return s?1-C:C};return{lo:U?10**R:R,hi:U?10**q:q,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)),q=Math.ceil(Math.log10(z)),V=Se=>{const ce=[];for(let _=R;_<=q;_++)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:q,setPngDecor:V,setPngCanvas:we,setAbout:Me,setMenuRows:Se}=Xn(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 $e=()=>{const e=s&&(s.marks||s.facets?.length)?Gn(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(()=>[...$e(),...Oe()]);let C,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,Pe,dt;const an=()=>!!s?.facets;let de=[],ke=-1,Mt=new Map,qe=[],Ye=Ue,w=Wt,v=Rt;const rn={[Yt.outlier]:"#e69f00",[Yt.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)))+(Ye-Ue),a=Yn(W,R,C,l);return{w:e,h:a,plotW:Math.max(10,e-w-xt),plotH:Math.max(10,a-v-Ye)}}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 f=a?.clip,r=f?[...e.filter(d=>d>=f.lo&&d<=f.hi),f.lo,f.hi]:e,h=r.filter(Number.isFinite);if(!l.length||h.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(h),Te(h),n,t)?[...r,...l.map(d=>d.value)]:r};let kt;function Je(e,l,a,f=!1){return!f&&!s?.x?.clip&&!s?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(w,v,l,a),e.clip(),kt=e,Nt)}function Nt(){kt?.restore(),kt=void 0}function ze(e,l,a,f,r,h,n,t,o){const d=[];if(h.length===0)return()=>{};const k=h.filter(p=>p.value>=r.lo&&p.value<=r.hi),x=h.filter(p=>!k.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(),c=Q(-1)+2;for(const p of h){if(p.bandTo===void 0)continue;const A=r.frac(Math.min(p.value,p.bandTo)),S=r.frac(Math.max(p.value,p.bandTo)),y=Math.max(0,Math.min(A,S)),P=Math.min(1,Math.max(A,S));P<=y||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(w,v+(1-P)*f,a,(P-y)*f):e.fillRect(w+y*a,v,(P-y)*a,f),e.restore())}if(t==="y"){const p=k.map(y=>{const P=v+(1-r.frac(y.value))*f;return{l:y,y:P,start:P-6-c/2,end:P-6+c/2}}),A=en(p,1),S=p.length?Te(p.map(y=>e.measureText(g(y.l)).width))+8:0;p.forEach(({l:y,y:P},u)=>{e.globalAlpha=.7,nn(e,y,l,w,P,w+a,P),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const i=w+3+A[u]*S,M=tn(qe,{x0:i,x1:i+e.measureText(g(y)).width,y0:P-4-c+2,y1:P-4+2},c);if(!o){e.fillText(g(y),i,M.y1-2);return}d.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",Ct(e,g(y),i,M.y1-2,o.halo),e.restore()})})}else{const p=k.map(S=>{const y=w+r.frac(S.value)*a,P=g(S),u=S.label.split(/\s+/)[0],i=J(S.value,n.unit),M=u&&u!==S.label?[P,`${u} ${i}`,u]:[P],B=k.filter(E=>E!==S).map(E=>w+r.frac(E.value)*a),{text:F,side:T}=to(y,M,E=>e.measureText(E).width,w,w+a,S.end==="lo",B),L=e.measureText(F).width;return{l:S,x:y,side:T,shown:F,start:T<0?y-3-L:y+3,end:T<0?y-3:y+3+L}}),A=en(p,4);p.forEach(({l:S,x:y,side:P,shown:u,start:i,end:M},B)=>{e.globalAlpha=.7,nn(e,S,l,y,v,y,v+f),e.globalAlpha=1;const F=P<0?"right":"left";e.fillStyle=l,e.textAlign=F,e.textBaseline="top";const T=v+2+A[B]*c,L=tn(qe,{x0:i,x1:M,y0:T,y1:T+c},c);if(!o){e.fillText(u,y+P*3,L.y0);return}d.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=F,e.textBaseline="top",Ct(e,u,y+P*3,L.y0,o.halo),e.restore()})})}return e.restore(),eo(e,x,{left:w,right:w+a,top:v,bottom:v+f},t==="y"?"vertical":"horizontal",l,p=>J(p,n.unit),void 0,qe),()=>d.forEach(p=>p())}function Tt(e,l,a,f){return Hn(Math.max(Math.abs(l),Math.abs(a)),e.unit,f,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 f=l.length-1;f>0;f--){const r=`${l.slice(0,f)}\u2026`;if(e.measureText(r).width<=a)return r}return""};function Ke(e,l,a,f,r,h,n,t,o,d,k){qe=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const x=()=>Kn,g=k?{ticks:k.map(y=>y.at),step:0}:t.log?It(t.lo,t.hi,h,x):pt(t.lo,t.hi,h,x),c=new Map(k?.map(y=>[y.at,y.label])),p=Tt(d,t.lo,t.hi,g.step||void 0),A=k?{tick:y=>c.get(y)??"",unitLabel:""}:p;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let S="";if("labels"in n){const y=n.labels.length;if(n.labels.forEach((P,u)=>{const i=w+(u+.5)/y*r,M=P.length>22?`${P.slice(0,21)}\u2026`:P;n.rotate?(e.save(),e.translate(i,v+h+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(M,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(M,i,v+h+4))}),n.nest){const P=n.nest[0]?.length??0,u=r/y;for(let i=P-2;i>=0;i--){const M=f-6-wt-i*wt,B=T=>n.nest[T].slice(0,i+1).join("");let F=0;for(let T=1;T<=y;T++){if(T<y&&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,M),T<y&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=i===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(j,v),e.lineTo(j,M-2),e.stroke(),e.restore()),F=T}}e.fillStyle=l.textMuted}}else{const y=Zt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),P=n.log?It(n.lo,n.hi,r,y):pt(n.lo,n.hi,r,y),u=Tt(o,n.lo,n.hi,P.step||void 0);S=u.unitLabel;for(const i of P.ticks){const M=w+n.frac(i)*r;e.beginPath(),e.moveTo(M,v),e.lineTo(M,v+h),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(u.tick(i),M,v+h+4)}}for(const y of g.ticks){const P=v+(1-t.frac(y))*h;e.beginPath(),e.moveTo(w,P),e.lineTo(w+r,P),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(A.tick(y),w-4,P)}e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(mt(o,S),w+r/2,f-6),e.save(),e.translate(14,v+h/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(d,A.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,v),e.lineTo(w,v+h),e.moveTo(w,v+h),e.lineTo(w+r,v+h),e.stroke()}function cn(e,l,a,f,r,h,n,t,o,d,k,x={along:h,offset:0}){qe=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const g=Zt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),k.unit),c=o.log?It(o.lo,o.hi,r,g):pt(o.lo,o.hi,r,g),p=Tt(k,o.lo,o.hi,c.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const i of c.ticks){const M=w+o.frac(i)*r;e.beginPath(),e.moveTo(M,v),e.lineTo(M,v+h),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(i),M,v+h+4)}const A=n.labels.length,S=x.along/Math.max(1,A),y=v-x.offset;e.save(),e.beginPath(),e.rect(0,v-1,w+r+1,h+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const P=Math.max(0,Math.floor(x.offset/S)),u=Math.min(A,Math.ceil((x.offset+h)/S));for(let i=P;i<u;i++)e.fillText(St(e,n.labels[i],t.inner),w-6,y+(i+.5)*S);if(n.nest){const i=n.nest[0]?.length??0;let M=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 L=0;for(let E=1;E<=A;E++){if(E<A&&T(E)===T(L))continue;const j=y+L*S,b=y+E*S;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(St(e,n.nest[L][B],F),M,(j+b)/2),E<A&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=B===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(M-F,b),e.lineTo(w+r,b),e.stroke(),e.restore()),L=E}M-=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(k,p.unitLabel),w+r/2,f-6),e.save(),e.translate(14,v+h/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(d,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,v),e.lineTo(w,v+h),e.moveTo(w,v+h),e.lineTo(w+r,v+h),e.stroke()}function fn(){if(!s||!C||s.marks?.type!=="scatter"||!s.x||!s.y)return;Xe(C,te??0);const e=je(W),{w:l,h:a,plotW:f,plotH:r}=Ne(),h=De(C,W,l,a);if(!h)return;const{ctx:n}=h,t=s.marks.points,o=O.size===0?t:t.filter(T=>O.has(T.group)),d=s.colorScale,k=bt(s.spec.colorGradient,s.spec.colorReverse,d?.diverging,d?.rating),x=Be(s.x),g=Be(s.y),c=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:c,y:p,plotW:f,plotH:r},Ke(n,e,l,a,f,r,c,p,s.x,s.y),ze(n,e.limitLine,f,r,c,x,s.x,"x"),ze(n,e.limitLine,f,r,p,g,s.y,"y"),Je(n,f,r);const A=o.length>vt?Math.ceil(o.length/vt):1,S=[];for(let T=0;T<o.length;T+=A)S.push(o[T]);n.globalAlpha=Math.max(.15,Math.min(.7,200/S.length));let y;if(d)y=[S];else{const T=new Map;for(const L of S){const E=T.get(L.group);E?E.push(L):T.set(L.group,[L])}y=[...T.values()].sort((L,E)=>E.length-L.length)}le=[];const P=w,u=w+f,i=v,M=v+r;for(const T of y)for(const L of T){const E=w+c.frac(L.x)*f,j=v+(1-p.frac(L.y))*r;E<P||E>u||j<i||j>M||(le.push({p:L,cx:E,cy:j}),n.beginPath(),n.arc(E,j,2.5,0,Math.PI*2),n.fillStyle=d&&L.value!==void 0?k((L.value-d.lo)/(d.hi-d.lo||1)):ee(L.group),n.fill())}n.globalAlpha=1;const B=s.marks;if(B.type==="scatter"&&(B.identity||B.fits)){const T=(E,j)=>[w+c.frac(E)*f,v+(1-p.frac(j))*r],L=(E,j,b)=>{n.save(),n.beginPath(),n.rect(w,v,f,r),n.clip(),n.strokeStyle=j,n.lineWidth=2,n.setLineDash(b),n.beginPath();for(let ie=0;ie<=60;ie++){const We=ie/60,Ge=c.log?10**(Math.log10(c.lo)+(Math.log10(c.hi)-Math.log10(c.lo))*We):c.lo+(c.hi-c.lo)*We,[Le,fe]=T(Ge,E(Ge));ie===0?n.moveTo(Le,fe):n.lineTo(Le,fe)}n.stroke(),n.restore()};B.identity&&L(E=>E,e.textMuted,[6,4]);for(const E of B.fits??[])O.size>0&&!O.has(E.group)&&!d||L(j=>E.intercept+E.slope*j,d?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 L of he)if(!(O.size>0&&!O.has(L.group))){if(++T>vt)break;n.beginPath(),n.arc(w+c.frac(L.x)*f,v+(1-p.frac(L.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),f=Math.max(1,s.spec.bins??co),r=a.log?Math.log10(a.lo):a.lo,h=a.log?Math.log10(a.hi):a.hi,n=Array.from({length:f+1},(g,c)=>{const p=r+(h-r)*c/f;return a.log?10**p:p}),t=e.map(()=>new Array(f).fill(0));e.forEach((g,c)=>{for(const p of g){const A=a.log?p>0?Math.log10(p):NaN:p;if(!Number.isFinite(A)||A<r||A>h)continue;const S=Math.min(f-1,Math.floor((A-r)/(h-r)*f));t[c][S]++}});const o=s.spec.histNorm==="percent",d=o?t.map(g=>{const c=g.reduce((p,A)=>p+A,0);return g.map(p=>c?p/c*100:0)}):t;let k=0;const x=e.map(()=>{});if(s.spec.normalCurve&&!a.log){const g=(n[n.length-1]-n[0])/f;e.forEach((c,p)=>{const A=c.filter(Number.isFinite);if(A.length<2)return;const S=A.reduce((P,u)=>P+u,0)/A.length,y=Math.sqrt(Rn(A,S));y>0&&(x[p]={mean:S,sd:y},k=Math.max(k,(o?100:t[p].reduce((P,u)=>P+u,0))*g/(y*Math.sqrt(2*Math.PI))))})}Ee={edges:n,counts:t,heights:d,normal:x,maxCount:Math.max(o?.001:1,k,...d.map(g=>Te(g)))}}function hn(){if(!s||!C||!Ee||!s.x||!s.y)return;Xe(C,te??0);const e=je(W),{w:l,h:a,plotW:f,plotH:r}=Ne(),h=De(C,W,l,a);if(!h)return;const{ctx:n}=h,{edges:t,counts:o,heights:d,normal:k,maxCount:x}=Ee,g=ue([t[0],t[t.length-1]],{...s.x,min:t[0],max:t[t.length-1]}),c=ue([0,x],{label:s.y.label,scale:"linear",min:0,max:x*1.05});Z={x:g,y:c,plotW:f,plotH:r},Ke(n,e,l,a,f,r,g,c,s.x,s.y),ze(n,e.limitLine,f,r,g,Be(s.x),s.x,"x"),Je(n,f,r);const p=o.map((u,i)=>i).filter(u=>O.size===0||O.has(u)),A=p.length>1,S=p.length>=3,y=u=>w+Math.min(g.frac(t[u]),g.frac(t[u+1]))*f,P=u=>w+Math.max(g.frac(t[u]),g.frac(t[u+1]))*f;for(const u of p){if(S){n.fillStyle=ee(u),n.strokeStyle=ee(u),n.lineWidth=1.75,n.lineJoin="round",n.globalAlpha=.1,d[u].forEach((M,B)=>{if(M===0)return;const F=v+(1-c.frac(M))*r;n.fillRect(y(B),F,Math.max(1,P(B)-y(B)),v+r-F)}),n.globalAlpha=1,n.beginPath();let i=!1;d[u].forEach((M,B)=>{const F=v+(1-c.frac(M))*r;i||(n.moveTo(y(B),v+r),i=!0),n.lineTo(y(B),F),n.lineTo(P(B),F),B===d[u].length-1&&n.lineTo(P(B),v+r)}),n.stroke();continue}n.globalAlpha=A?.55:.85,n.fillStyle=ee(u),d[u].forEach((i,M)=>{if(i===0)return;const B=v+(1-c.frac(i))*r;n.fillRect(y(M),B,Math.max(1,P(M)-y(M)-1),v+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 M=k[i];if(!M)continue;const{mean:B,sd:F}=M,T=(s.spec.histNorm==="percent"?100:o[i].reduce((L,E)=>L+E,0))*u;n.save(),n.beginPath(),n.rect(w,v,f,r),n.clip(),n.strokeStyle=ee(i),n.lineWidth=2,n.beginPath();for(let L=0;L<=120;L++){const E=t[0]+(t[t.length-1]-t[0])*L/120,j=Math.exp(-.5*((E-B)/F)**2)/(F*Math.sqrt(2*Math.PI)),b=w+g.frac(E)*f,ie=v+(1-c.frac(T*j))*r;L===0?n.moveTo(b,ie):n.lineTo(b,ie)}n.stroke(),n.restore()}}if(ye>=0){const u=w+Math.min(g.frac(t[ye]),g.frac(t[ye+1]))*f,i=w+Math.max(g.frac(t[ye]),g.frac(t[ye+1]))*f;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(u,v,Math.max(1,i-u),r)}}function dn(){const e=s?.marks;if(!s||!C||!s.x||!s.y||!e||e.type!=="box"&&e.type!=="bar")return;Xe(C,te??0);const l=je(W),a=s.spec.orientation==="horizontal",f=e.nest?e.nest.parts.map($=>$[$.length-1]):e.categories,r=e.categories.length,h=s.groups.length,n=$=>O.size===0||O.has($),t=e.type==="bar"&&!!e.stack,o=($,N)=>e.type==="bar"?Number.isFinite(e.values[$][N]):e.cells[$][N].length>0,d=Array.from({length:r},($,N)=>Array.from({length:h},(I,G)=>G).filter(I=>n(I)&&o(I,N))),k=categoryLayout(t?d.map($=>$.length?[0]:[]):d),x=C.getContext("2d"),g=$=>x?x.measureText($).width:$.length*6;x&&(x.font=`${Q(-1)}px system-ui, sans-serif`);const c=($,N)=>$.length>N?`${$.slice(0,N-1)}\u2026`:$;let p=!1,A={inner:0,outer:[]},S=0;if(a){A={inner:Math.min(200,Te(f.map(N=>g(c(N,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((N,I)=>Math.min(140,Te(e.nest.parts.map(G=>g(c(G[I],20)))))):[]},w=Math.max(Wt,30+A.inner+6+A.outer.reduce((N,I)=>N+I+10,0)),e.cumulative&&(v=Rt+18),Ye=Ue;const $=Math.max(1,...d.map(N=>t?Math.min(1,N.length):N.length));S=Math.max(22,$*ao/.8)}else{const $=Te(f.map(G=>g(c(G,22)))),N=Math.max(10,R.clientWidth-w-xt)/Math.max(1,r);p=$+8>N;const I=e.nest?e.nest.levels.length-1:0;Ye=(p?Ue+Math.min(110,$*.72):Ue)+I*wt}const y=e.type==="bar"&&!t&&!!s.spec.valueLabels,P=s.y.unit,u=$=>J($,P),i=y?Te(e.values.flat().filter(Number.isFinite).map($=>g(u($))).concat(0))+8:0,M=a?i:e.cumulative?40:0,{w:B,h:F,plotW:T,plotH:L}=Ne(),E=Math.max(10,T-M),j=De(C,W,B,F);if(!j)return;const{ctx:b}=j,ie=$=>$.filter(Number.isFinite),We=Be(s.y),Ge=t?e.categories.map(($,N)=>e.values.reduce((I,G,Y)=>I+(n(Y)&&Number.isFinite(G[N])?G[N]:0),0)):[],Le=e.type==="bar"?[...t?Ge:ie(e.values.flat()),0]:ie(e.cells.flat(2));b.font=`${Q(-1)}px system-ui, sans-serif`;const fe=a?i:Q(-1)+6;if(y&&!a&&Le.length){const $=Te(Le);$>0&&Le.push($*(1+fe/Math.max(1,L-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:L};const it=a?L:E,Qe=a&&r*S>L+.5,at=Qe?r*S:it,rt=Qe?Math.max(0,Math.min(lt,at-it)):0;lt=rt,$n(Qe,at,rt,E+M,L),a?cn(b,l,B,F,E,L,{labels:f,rotate:!1,nest:e.nest?.parts},A,Ae,s.x,s.y,{along:at,offset:rt}):Ke(b,l,B,F,E,L,{labels:f,rotate:p,nest:e.nest?.parts},Ae,s.x,s.y);const xe=at/r,Ce=k.width*xe;ne={slotW:xe,n:r,plotW:at,layout:k,across:a,offset:rt,view:it};const oe=$=>a?w+Ae.frac($)*E:v+(1-Ae.frac($))*L,ve=$=>a?v+$-rt:w+$,Lt=Ae.log?a?w:v+L:oe(0),et=($,N,I,G)=>a?[Math.min(I,G),ve($),Math.max(1,Math.abs(G-I)),N-$]:[ve($),Math.min(I,G),N-$,Math.max(1,Math.abs(G-I))],At=($,N,I,G)=>{b.beginPath(),a?(b.moveTo(N,ve($)),b.lineTo(G,ve(I))):(b.moveTo(ve($),N),b.lineTo(ve(I),G)),b.stroke()},tt=$=>a?$>=Lt:$<=Lt,En=$=>a?Q(-1)<=Ce+4:b.measureText(u($)).width<=Ce+6,Gt=y&&e.values.every($=>$.every(N=>!Number.isFinite(N)||En(N)));if(Gt){for(let $=0;$<h;$++)if(n($))for(let N=0;N<r;N++){const I=k.left(N,$),G=e.values[$][N];if(I===void 0||!Number.isFinite(G))continue;const Y=ve(N*xe+I*xe+Ce/2),H=b.measureText(u(G)).width,X=oe(G);a?qe.push(tt(X)?{x0:X,x1:X+H+6,y0:Y-fe/2,y1:Y+fe/2}:{x0:X-H-6,x1:X,y0:Y-8,y1:Y+8}):qe.push(tt(X)?{x0:Y-H/2,x1:Y+H/2,y0:X-fe,y1:X}:{x0:Y-H/2,x1:Y+H/2,y0:X,y1:X+fe})}}const Bn=ze(b,l.limitLine,E,L,Ae,We,s.y,a?"x":"y",{halo:l.bg}),Wn=Je(b,E,L,Qe);if(t){ne.stacks=[];for(let $=0;$<r;$++){const N=k.left($,0),I=[];if(ne.stacks.push(I),N===void 0)continue;let G=0;for(let Y=0;Y<h;Y++){const H=e.values[Y][$];if(!n(Y)||!Number.isFinite(H)||H<=0)continue;const X=oe(G),ae=oe(G+H);b.fillStyle=ee(Y),b.globalAlpha=.9;const re=$*xe+N*xe;b.fillRect(...et(re+1,re+Ce-1,X,ae)),b.globalAlpha=1,I.push({g:Y,p0:Math.min(X,ae),p1:Math.max(X,ae)}),G+=H}}}for(let $=0;$<h&&!t;$++){if(O.size>0&&!O.has($))continue;const N=ee($);for(let I=0;I<r;I++){const G=k.left(I,$);if(G===void 0)continue;const Y=I*xe+G*xe;if(e.type==="bar"){const H=e.values[$][I];if(!Number.isFinite(H))continue;const X=oe(H);if(b.fillStyle=N,b.globalAlpha=.9,b.fillRect(...et(Y+1,Y+Ce-1,Lt,X)),b.globalAlpha=1,Gt){b.fillStyle=l.text,b.font=`${Q(-1)}px system-ui, sans-serif`;const ae=ve(Y+Ce/2);a?(b.textBaseline="middle",b.textAlign=tt(X)?"left":"right",b.fillText(u(H),X+(tt(X)?3:-3),ae)):(b.textAlign="center",b.textBaseline=tt(X)?"bottom":"top",b.fillText(u(H),ae,X+(tt(X)?-2:2)))}}else{const H=e.cells[$][I];if(H.length===0)continue;const X=Y+Ce/2,ae=Math.max(3,Math.min(Ce*.7,46)),re=Ut(Float64Array.from(H));if(b.strokeStyle=N,b.fillStyle=N,b.lineWidth=1.5,H.length===1){b.beginPath(),a?b.arc(oe(re.median),ve(X),3,0,Math.PI*2):b.arc(ve(X),oe(re.median),3,0,Math.PI*2),b.fill();continue}At(X,oe(re.min),X,oe(re.max));for(const Dt of[re.min,re.max])At(X-ae/4,oe(Dt),X+ae/4,oe(Dt));b.globalAlpha=.35,b.fillRect(...et(X-ae/2,X+ae/2,oe(re.q1),oe(re.q3))),b.globalAlpha=1,b.strokeRect(...et(X-ae/2,X+ae/2,oe(re.q1),oe(re.q3))),b.lineWidth=2.5,At(X-ae/2,oe(re.median),X+ae/2,oe(re.median))}}}Wn(),Bn();const Xt=se?k.left(se.c,t?0:se.g):void 0;if(se&&Xt!==void 0){Qe&&(b.save(),b.beginPath(),b.rect(w-1,v,E+2,L),b.clip()),b.lineWidth=1.5,b.strokeStyle=l.text;const $=se.c*xe+Xt*xe,N=t?ne.stacks?.[se.c]?.find(I=>I.g===se.g):void 0;t&&N?b.strokeRect(...et($,$+Ce,N.p0,N.p1)):t||b.strokeRect(...et($,$+Ce,a?w:v,a?w+E:v+L)),Qe&&b.restore()}if(e.cumulative){const $=I=>a?w+I/100*E:v+(1-I/100)*L,N=(I,G)=>a?[$(G),ve((I+.5)*xe)]:[ve((I+.5)*xe),$(G)];if(b.save(),b.strokeStyle=l.text,b.fillStyle=l.text,b.lineWidth=1.5,b.beginPath(),e.cumulative.forEach((I,G)=>{const[Y,H]=N(G,I);G===0?b.moveTo(Y,H):b.lineTo(Y,H)}),b.stroke(),e.cumulative.forEach((I,G)=>{const[Y,H]=N(G,I);b.beginPath(),b.arc(Y,H,2.5,0,Math.PI*2),b.fill()}),b.strokeStyle=l.border,b.lineWidth=1,b.beginPath(),a?(b.moveTo(w,v),b.lineTo(w+E,v)):(b.moveTo(w+E,v),b.lineTo(w+E,v+L)),b.stroke(),b.fillStyle=l.textMuted,b.font=`${Q(-1)}px system-ui, sans-serif`,a){b.textAlign="center",b.textBaseline="bottom";for(const I of[0,25,50,75,100])b.fillText(`${I}%`,$(I),v-3)}else{b.textAlign="left",b.textBaseline="middle";for(const I of[0,25,50,75,100])b.fillText(`${I}%`,w+E+4,$(I))}b.restore()}}function mn(e){const l=s?.setTests,a=l?l.labels.indexOf(e):-1;return a>=0?{test:l.tests[a]}:{}}function $t(e){if(!ne||!C)return null;const l=C.getBoundingClientRect(),a=ne.across?e.clientY-l.top-v:e.clientX-l.left-w;if(a<0||a>ne.view)return null;const f=a+ne.offset,r=Math.min(ne.n-1,Math.floor(f/ne.slotW)),h=ne.layout.groupAt(r,(f-r*ne.slotW)/ne.slotW);if(h===void 0)return null;if(!ne.stacks)return{g:h,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 f=0,r=0,h=0;for(const o of l)o===100&&f++;if(e.failSide)for(const o of a){const d=e.failSide[o];d<0?r++:d>0&&h++}const n=o=>o.toLocaleString("en-GB"),t=r+h>0?` (${n(r)} below the low limit \xB7 ${n(h)} above the high limit)`:"";return`${n(f)} pass \xB7 ${n(l.length-f)} fail${t} \xB7 n = ${n(l.length)}`}function gn(e){const l=s,a=l.marks,f=l.level==="die"?"dies":"wafers",r=a.cells[e.g][e.c],h=a.nest?a.nest.parts[e.c]:[a.categories[e.c]],n=l.groups.length>1&&!h.includes(He(e.g))?` \xB7 ${D(He(e.g))}`:"",t=`<strong>${D(a.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(r.length===0)return`${t}no ${f}`;const d=`${r.length.toLocaleString("en-GB")} ${f}`,k=(a.categoryItems&&m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")+(a.categoryItems&&m.onWaferMenu?Et:"");if(a.type==="bar"){const g=a.values[e.g][e.c],c=a.cumulative?`<br>${D(`cumulative: ${a.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${D(`${l.y.label}: ${J(g,o)}`)}<br>${D(a.passFail?pn(a.passFail,r,a.cellUnits[e.g][e.c]):d)}${c}${k}`}const x=Ut(Float64Array.from(r));return`${t}${["max","q3","median","q1","min"].map(g=>D(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[g]}: ${J(x[g],o)}`)).join("<br>")}<br>${D(d)}${k}`}function yn(){const e=s?.marks;if(!s||!C||!s.x||!s.y||!e||e.type!=="line")return;Xe(C,te??0);const l=je(W),{w:a,h:f,plotW:r,plotH:h}=Ne(),n=De(C,W,a,f);if(!n)return;const{ctx:t}=n,o=Be(s.x),d=Be(s.y),k=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),d,s.y),s.y);if(Z={x:k,y:g,plotW:r,plotH:h},Ke(t,l,a,f,r,h,k,g,s.x,s.y),ze(t,l.limitLine,r,h,k,o,s.x,"x"),ze(t,l.limitLine,r,h,g,d,s.y,"y"),Je(t,r,h),de=e.xs.map(c=>w+k.frac(c)*r),e.band){const c=p=>v+(1-g.frac(p))*h;e.band.lo.forEach((p,A)=>{if(O.size>0&&!O.has(A))return;const S=e.band.hi[A];t.save(),t.fillStyle=ee(A),t.globalAlpha=.16;let y=[];const P=()=>{if(y.length===1){const u=y[0],i=de[u];t.globalAlpha=.55,t.strokeStyle=ee(A),t.lineWidth=2,t.beginPath(),t.moveTo(i,c(p[u])),t.lineTo(i,c(S[u])),t.moveTo(i-4,c(p[u])),t.lineTo(i+4,c(p[u])),t.moveTo(i-4,c(S[u])),t.lineTo(i+4,c(S[u])),t.stroke(),t.globalAlpha=.16}else if(y.length){t.beginPath(),y.forEach((u,i)=>{i===0?t.moveTo(de[u],c(S[u])):t.lineTo(de[u],c(S[u]))});for(let u=y.length-1;u>=0;u--)t.lineTo(de[y[u]],c(p[y[u]]));t.closePath(),t.fill()}y=[]};p.forEach((u,i)=>{Number.isFinite(u)&&Number.isFinite(S[i])?y.push(i):P()}),P(),t.restore()})}e.values.forEach((c,p)=>{if(O.size>0&&!O.has(p))return;t.strokeStyle=ee(p),t.fillStyle=ee(p),t.lineWidth=2;let A=!1;t.beginPath(),c.forEach((S,y)=>{if(!Number.isFinite(S)){A=!1;return}const P=de[y],u=v+(1-g.frac(S))*h;A?t.lineTo(P,u):t.moveTo(P,u),A=!0}),t.stroke(),c.forEach((S,y)=>{Number.isFinite(S)&&(t.beginPath(),t.arc(de[y],v+(1-g.frac(S))*h,ke===y?4.5:3,0,Math.PI*2),t.fill())})}),ke>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(de[ke],v),t.lineTo(de[ke],v+h),t.stroke())}function Pt(e){const l=s?.marks;if(!l||l.type!=="line"||!C||!s?.x||de.length===0)return null;const a=e.clientX-C.getBoundingClientRect().left;let f=-1,r=24;if(de.forEach((t,o)=>{const d=Math.abs(t-a);d<r&&(r=d,f=o)}),ke=f,f<0)return null;const h=s.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[f],n:l.counts[o][f]})).filter(t=>Number.isFinite(t.v)&&(O.size===0||O.has(t.g)));return`<strong>${D(`${s.x.label}: ${J(l.xs[f],s.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][f],d=l.band?.hi[t.g][f],k=o!==void 0&&d!==void 0&&Number.isFinite(o)&&Number.isFinite(d)?`, band ${J(o,s.y.unit)} to ${J(d,s.y.unit)}`:"";return D(`${s.groups.length>1?`${He(t.g)}: `:""}${J(t.v,s.y.unit)}${k} (${t.n.toLocaleString("en-GB")} ${h})`)}).join("<br>")+(m.onWaferMenu&&Ft(f)!==void 0?Et:"")}function Ft(e){const l=s?.marks;if(l?.type!=="line")return;const a=new Set(l.cellUnits.flatMap((f,r)=>O.size>0&&!O.has(r)?[]:(f[e]??[]).map(h=>l.unit(h).item)));return a.size===1?[...a][0]:void 0}function bn(){const e=s?.marks;if(!s||!C||!s.x||!s.y||e?.type!=="probability")return;Xe(C,te??0);const l=je(W),{w:a,h:f,plotW:r,plotH:h}=Ne(),n=De(C,W,a,f);if(!n)return;const{ctx:t}=n,o=s.spec.probabilityAxis==="linear",d=e.values.map((T,L)=>L).filter(T=>e.values[T].length>0&&(O.size===0||O.has(T))),k=Math.max(1,...d.map(T=>e.values[T].length)),x=Math.min(.01,ct(0,k)),g=T=>o?T:qt(T),c=o?0:g(x),p=o?1:g(1-x),A=o?0:(p-c)*.03,S=ue([c-A,p+A],{label:s.y.label,scale:"linear",min:c-A,max:p+A}),y=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:fo.filter(T=>T>=x&&T<=1-x),P=[],u=T=>v+(1-S.frac(T))*h,i=y.indexOf(.5);P.push({at:g(.5),label:sn(.5)});for(const T of[y.slice(i+1),y.slice(0,i).reverse()]){let L=u(g(.5));for(const E of T){const j=u(g(E));Math.abs(j-L)<16||(P.push({at:g(E),label:sn(E)}),L=j)}}const M=Be(s.x),B=ue(Fe(Re(d.flatMap(T=>[e.values[T][0],e.values[T][e.values[T].length-1]]),s.x),M,s.x),s.x);Z={x:B,y:S,plotW:r,plotH:h},Ke(t,l,a,f,r,h,B,S,s.x,s.y,P),ze(t,l.limitLine,r,h,B,M,s.x,"x"),Je(t,r,h),le=[],t.save(),t.beginPath(),t.rect(w,v,r,h),t.clip();for(const T of d){const L=e.values[T],E=L.length,j=uo(E);if(t.strokeStyle=ee(T),t.fillStyle=ee(T),t.lineWidth=1.5,t.beginPath(),j.forEach((b,ie)=>{const We=w+B.frac(L[b])*r,Ge=u(g(ct(b,E)));ie===0?t.moveTo(We,Ge):t.lineTo(We,Ge);const Le=T*2**26+b;let fe=Mt.get(Le);if(!fe){const{item:Ae,die:it}=e.unit(e.units[T][b]);fe={x:L[b],y:ct(b,E),group:T,item:Ae,die:it},Mt.set(Le,fe)}le.push({p:fe,cx:We,cy:Ge})}),t.stroke(),E<=300)for(const b of j)t.beginPath(),t.arc(w+B.frac(L[b])*r,u(g(ct(b,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 L of he)if(!(O.size>0&&!O.has(L.group))){if(++T>vt)break;t.beginPath(),t.arc(w+B.frac(L.x)*r,u(g(L.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,f=l.marks.values[e.group].length,r=Math.round(e.y*f+.5),h=m.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[h,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${D(t)}</strong><br>`:"")+D(`${l.x.label}: ${J(e.x,l.x.unit)}`)+"<br>"+D(`rank ${r.toLocaleString("en-GB")} of ${f.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${D(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")+(m.onWaferMenu&&!e.die?Et:"")}let _e,be=null;function vn(){const e=s?.marks;if(!s||!C||e?.type!=="heatmap")return;Xe(C,te??0);const l=je(W),a=C.getContext("2d");let f=0,r=0;a&&(a.font=`${Q(-1)}px system-ui, sans-serif`,f=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 h=Math.min(180,Math.max(w,f+24)),n=Math.max(8,R.clientWidth-h-xt)/Math.max(1,e.cols.length),t=r+8>n;Ye=t?Ue+Math.min(110,r*.72):Ue;const{w:o,h:d}=Ne(),k=Math.max(10,o-h-xt),x=Math.max(10,d-v-Ye),g=De(C,W,o,d);if(!g)return;const{ctx:c}=g,p=k/e.cols.length,A=x/e.rows.length;_e={left:h,cw:p,ch:A,rows:e.rows.length,cols:e.cols.length};const S=s.colorScale,y=bt(s.spec.colorGradient,s.spec.colorReverse,S?.diverging,S?.rating),P=S&&S.hi-S.lo||1;c.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 M=e.values[u][i],B=h+i*p,F=v+u*A,T=Number.isFinite(M)&&S?y((M-S.lo)/P):l.track;if(c.fillStyle=T,c.fillRect(B,F,p,A),Number.isFinite(M)&&p>=40&&A>=16){const L=so(T);c.fillStyle=L?"#1a1a1a":"#fff",c.textAlign="center",c.textBaseline="middle",Ct(c,Ot(M,s.y?.unit,S?.integer),B+p/2,F+A/2,L?"rgba(255,255,255,0.55)":"rgba(0,0,0,0.55)")}}c.lineWidth=1,c.setLineDash([]),c.strokeStyle=l.border,c.beginPath();for(let u=1;u<e.rows.length;u++){const i=Math.round(v+u*A)+.5;c.moveTo(h,i),c.lineTo(h+k,i)}for(let u=1;u<e.cols.length;u++){const i=Math.round(h+u*p)+.5;c.moveTo(i,v),c.lineTo(i,v+x)}c.stroke(),c.strokeStyle=l.textMuted,c.strokeRect(h+.5,v+.5,k-1,x-1),c.beginPath();for(let u=0;u<e.rows.length;u++){const i=Math.round(v+(u+.5)*A)+.5;c.moveTo(h-4,i),c.lineTo(h,i)}for(let u=0;u<e.cols.length;u++){const i=Math.round(h+(u+.5)*p)+.5;c.moveTo(i,v+x),c.lineTo(i,v+x+4)}c.stroke(),be&&(c.lineWidth=2,c.strokeStyle=l.text,c.strokeRect(h+be.c*p,v+be.r*A,p,A)),c.fillStyle=l.textMuted,c.textAlign="right",c.textBaseline="middle",e.rows.forEach((u,i)=>c.fillText(u.length>24?`${u.slice(0,23)}\u2026`:u,h-8,v+(i+.5)*A)),e.cols.forEach((u,i)=>{const M=u.length>22?`${u.slice(0,21)}\u2026`:u,B=h+(i+.5)*p;t?(c.save(),c.translate(B,v+x+8),c.rotate(-Math.PI/4),c.textAlign="right",c.textBaseline="middle",c.fillText(M,0,0),c.restore()):(c.textAlign="center",c.textBaseline="top",c.fillText(M,B,v+x+7))}),c.font=`${Q(0)}px system-ui, sans-serif`,c.fillStyle=l.text,c.textAlign="center",c.textBaseline="bottom",c.fillText(s.x?.label??"",h+k/2,d-6)}function zt(e){if(!_e||!C)return null;const l=C.getBoundingClientRect(),a=Math.floor((e.clientX-l.left-_e.left)/_e.cw),f=Math.floor((e.clientY-l.top-v)/_e.ch);return f>=0&&f<_e.rows&&a>=0&&a<_e.cols?{r:f,c:a}:null}function Mn(e){const l=s,a=l.marks,f=a.values[e.r][e.c],r=a.cellUnits[e.r][e.c].length,h=l.level==="die"?"dies":"wafers";return`<strong>${D(`${a.rows[e.r]} \xB7 ${a.cols[e.c]}`)}</strong><br>`+(Number.isFinite(f)?D(`${l.y?.label??"Count"}: ${Ot(f,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+D(`${r.toLocaleString("en-GB")} ${h}`)+(r&&m.onSelectPoints?"<br><em>click to chart or tabulate them</em>":"")}function kn(){const e=s?.marks;if(!s||!C||!s.x||!s.y||e?.type!=="control")return;Xe(C,te??0);const l=je(W),{w:a,h:f,plotW:r,plotH:h}=Ne(),n=De(C,W,a,f);if(!n)return;const{ctx:t}=n,o=e.limits,d=Be(s.y),k=ue(Re(e.xs,s.x),s.x),x=ue(Fe(Re([...e.values,o.ucl,o.lcl],s.y),d,s.y),s.y);Z={x:k,y:x,plotW:r,plotH:h},Ke(t,l,a,f,r,h,k,x,s.x,s.y),ze(t,l.limitLine,r,h,x,d,s.y,"y"),Je(t,r,h);const g=i=>w+k.frac(e.xs[i])*r,c=i=>v+(1-x.frac(i))*h;t.save(),t.beginPath(),t.rect(w,v,r,h),t.clip();const p=(i,M,B,F=1)=>{t.globalAlpha=B,t.setLineDash(M),t.lineWidth=F,t.strokeStyle=l.text,t.beginPath(),t.moveTo(w,c(i)),t.lineTo(w+r,c(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 A=i=>J(i,s.y.unit);if(t.fillText(`UCL ${A(o.ucl)}`,w+r-4,c(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${A(o.lcl)}`,w+r-4,c(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${A(o.centre)}`,w+r-4,c(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,v),t.lineTo(i,v+h),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",w+4,v+2)}t.strokeStyle=ee(0),t.lineWidth=1.5,t.setLineDash([]);const S=O.size>0,y=i=>e.group?.[i]??0;if(!S)t.beginPath(),e.values.forEach((i,M)=>{M===0?t.moveTo(g(M),c(i)):t.lineTo(g(M),c(i))}),t.stroke();else{for(const i of[!1,!0]){t.globalAlpha=i?1:.2,t.beginPath();for(let M=1;M<e.values.length;M++)(O.has(y(M-1))&&O.has(y(M)))===i&&(t.moveTo(g(M-1),c(e.values[M-1])),t.lineTo(g(M),c(e.values[M])));t.stroke()}t.globalAlpha=1}const P=new Map(e.violations.map(i=>[i.index,i.rules]));le=[],e.values.forEach((i,M)=>{const B=P.get(M),F=y(M),T=S&&O.has(F),L=S&&!T;t.globalAlpha=L?.2:1,t.beginPath(),t.arc(g(M),c(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(M),c(i)-(T?8:6))),t.globalAlpha=1,le.push({p:{x:e.xs[M],y:i,group:F,item:e.items[M]},cx:g(M),cy:c(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,f=a.items.indexOf(e.item),r=(e.y-a.limits.centre)/a.limits.sigma,h=a.violations.find(n=>n.index===f)?.rules;return`<strong>${D(m.waferLabel(e.item))}</strong><br>`+D(`${l.y.label}: ${J(e.y,l.y.unit)} (${r>=0?"+":"\u2212"}${Math.abs(r).toFixed(1)}\u03C3)`)+(h?`<br>${D(`breaks rule ${h.map(n=>`${n} (${On[n]})`).join(", ")}`)}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")}function wn(){const e=s?.marks;if(!s||!C||!s.x||!s.y||e?.type!=="goal")return;Xe(C,te??0);const l=je(W),{w:a,h:f,plotW:r,plotH:h}=Ne(),n=De(C,W,a,f);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(i=>Math.abs(i.x))),d=ue([-o,o],{...s.x,min:s.x.min??-o*1.05,max:s.x.max??o*1.05}),k=ue([0,...e.points.map(i=>i.y),1/6],{...s.y,min:s.y.min??0},{floorAtZero:!0});Z={x:d,y:k,plotW:r,plotH:h},Ke(t,l,a,f,r,h,d,k,s.x,s.y);const x=i=>w+d.frac(i)*r,g=i=>v+(1-k.frac(i))*h;t.save(),t.beginPath(),t.rect(w,v,r,h),t.clip(),t.font=`${Q(-1)}px system-ui, sans-serif`;const c=[[1,[6,4]],[1.33,[]]];for(const[i,M]of c){const B=1/(6*i);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(M),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 A=p.map(i=>({x0:x(i.x)-5,x1:x(i.x)+5,y0:g(i.y)-5,y1:g(i.y)+5})),S={x0:w,x1:w+r,y0:v,y1:v+h},y=i=>i.x0>=S.x0&&i.x1<=S.x1&&i.y0>=S.y0&&i.y1<=S.y1&&!A.some(M=>i.x0<M.x1&&i.x1>M.x0&&i.y0<M.y1&&i.y1>M.y0),P=Q(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const i of[...p].filter(M=>M.ppk<1.33).sort((M,B)=>M.ppk-B.ppk)){const M=x(i.x),B=g(i.y),F=t.measureText(i.label).width,T=[[M+7,B,"left"],[M-7,B,"right"],[M,B-13,"center"],[M,B+13,"center"]];for(const[L,E,j]of T){const b=j==="left"?L:j==="right"?L-F:L-F/2,ie={x0:b,x1:b+F,y0:E-P/2,y1:E+P/2};if(y(ie)){A.push(ie),t.textAlign=j,t.fillText(i.label,L,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,f=l.marks.points.find(r=>r.testNumber===e.value&&r.group===e.group);return f?`<strong>${D(f.label)}</strong>${l.groups.length>1?` \xB7 ${D(He(f.group))}`:""}<br>`+D(`Ppk ${f.ppk.toFixed(2)} \xB7 ${f.n.toLocaleString("en-GB")} dies`)+"<br>"+D(`mean ${f.x>=0?"+":"\u2212"}${Math.abs(f.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(f.y*100).toFixed(1)}% of it (${f.basis==="spec"?"spec":"test"} limits)`):""}function $n(e,l,a,f,r){!Pe||!C||(Pe.style.display=e?"block":"none",e&&(Object.assign(Pe.style,{top:`${C.offsetTop+v}px`,height:`${r}px`,left:`${C.offsetLeft+w+f+1}px`}),Pe.firstElementChild.style.height=`${l}px`,Math.abs(Pe.scrollTop-a)>=1&&(Pe.scrollTop=a)))}function K(){Pe&&(Pe.style.display="none"),dt&&!an()&&(dt.style.maxHeight=Qt(W)?"":`${ro}px`),pe&&m.panel&&(pe.style.display=Qt(W)?"flex":"none"),w=Wt,v=Rt;const e=s?.marks?.type;e==="scatter"?fn():e==="control"?kn():e==="heatmap"?vn():e==="goal"?wn():e==="probability"?bn():e==="histogram"?hn():e==="box"||e==="bar"?dn():e==="line"&&yn(),Nt()}function Pn(e){const l=s,a=m.waferLabel(e.item),f=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,f].filter(Boolean).join(" \xB7 "),h=(n,t)=>`${n.label}: ${J(t,n.unit)}`;return(r?`<strong>${D(r)}</strong><br>`:"")+D(h(l.x,e.x))+"<br>"+D(h(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${D(`${l.colorScale.label}: ${J(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${D(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")}function _t(e){if(!Ee||!Z||!s?.x)return null;const l=C.getBoundingClientRect(),f=(e.clientX-l.left-w)/Z.plotW;if(f<0||f>1)return null;const r=Z.x.reverse?1-f:f,{edges:h,counts:n}=Ee,t=h.length-1,o=Math.min(t-1,Math.max(0,Math.floor(r*t)));ye=o;const d=s.x,k=n.map((x,g)=>({g,n:x[o]})).filter(x=>x.n>0&&(O.size===0||O.has(x.g)));return`<strong>${D(`${J(h[o],d.unit)} to ${J(h[o+1],d.unit)}`)}</strong><br>`+(k.length?k.map(x=>{const g=s.spec.histNorm==="percent"?` (${Ee.heights[x.g][o].toFixed(1)}% of ${s.groups.length>1?"its colour":"them"})`:"";return D(`${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 f=a.getContext("2d"),r=bt(s?.spec.colorGradient,s?.spec.colorReverse,e.diverging,e.rating);if(f)for(let d=0;d<200;d++)f.fillStyle=r(d/199),f.fillRect(d,0,1,10);const h=d=>s?.marks?.type==="heatmap"?Ot(d,e.unit,e.integer):J(d,e.unit),n=z.createElement("span");n.textContent=h(e.lo);const t=z.createElement("span");t.textContent=h(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(f=>{const{item:r,die:h}=e(f);return{x:0,y:0,group:a,item:r,die:h}});function An(){Ze?.destroy(),Ze=void 0,R.innerHTML="",C=void 0,pe=void 0,te=void 0,ot=[],ge=null,ye=-1,le=[],Z=void 0,ne=void 0,se=null,Pe=void 0,lt=0,dt=void 0,_e=void 0,be=null,de=[],ke=-1,Ye=Ue,Mt=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 f=m.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(m.onOpenWafer?` \xB7 click a point to ${f}`:"")+(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 ${f}`:m.onSelectPoints?` \xB7 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 a bar to chart or tabulate its dies":e.marks.type==="probability"?(m.onOpenWafer?` \xB7 click a point to ${f}`:"")+(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||Dn(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);qn(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((d,k)=>d.setState({selected:O.has(k),dimmed:O.size>0&&!O.has(k)})),ce.length)for(const d of ce)d.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 d=o.querySelector("button");R.append(o,n),R.style.overflowY="auto",W.dataset.wmapPlotPanelsOwner="1",ht&&(W.dataset.wmapPanelsHover="1");const k=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(),d&&(d.value=Ie?String(Ie):"auto"))};z.addEventListener("keydown",k),ut=()=>z.removeEventListener("keydown",k);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}C=z.createElement("canvas"),C.style.display="block",C.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",R.appendChild(C);const h=m.onWaferMenu?(n,t)=>{n.die||m.onWaferMenu(n.item,Ve(e.spec),t)}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!m.onSelectPoints;Ze=Bt({card:W,canvas:C,tooltip:_,drawn:()=>le,describe:Pn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:h,onHover:o=>{ge=o,K()},select:t?{pick:({x0:o,y0:d,x1:k,y1:x})=>Z?(O.size===0?n.points:n.points.filter(c=>O.has(c.group))).filter(c=>{const p=w+Z.x.frac(c.x)*Z.plotW,A=v+(1-Z.y.frac(c.y))*Z.plotH;return p>=o&&p<=k&&A>=d&&A<=x}):[],onPicked:(o,d)=>{he.clear();for(const k of o)he.add(k);K(),o.length>0&&m.onSelectPoints(o,d,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:C,tooltip:_,drawn:()=>le,describe:n?Tn:Sn,clickable:()=>n&&!!m.onOpenWafer,onOpen:t=>{n&&m.onOpenWafer?.(t.item,Ve(e.spec))},onContextMenu:n?h: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:C,tooltip:_,drawn:()=>le,describe:xn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:h,onHover:o=>{ge=o,K()},select:m.onSelectPoints?{pick:({x0:o,y0:d,x1:k,y1:x})=>{if(!Z)return[];const g=[];return n.values.forEach((c,p)=>{O.size>0&&!O.has(p)||c.forEach((A,S)=>{const y=ct(S,c.length),P=w+Z.x.frac(A)*Z.plotW,u=v+(1-Z.y.frac(t?y:qt(y)))*Z.plotH;if(P<o||P>k||u<d||u>x)return;const{item:i,die:M}=n.unit(n.units[p][S]);g.push({x:A,y,group:p,item:i,die:M})})}),g},onPicked:(o,d)=>{he.clear();for(const k of o)he.add(k);K(),o.length>0&&m.onSelectPoints(o,d,C)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="histogram"){un(),C.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()}),C.addEventListener("mouseleave",()=>{_.style.display="none",ye>=0&&(ye=-1,K())});const n=e.marks;m.onSelectPoints&&(C.style.cursor="pointer",C.addEventListener("click",t=>{if(!Ee||_t(t)===null)return;const o=ye,{edges:d}=Ee,k=Z?.x.log,x=k?Math.log10(d[0]):d[0],g=k?Math.log10(d[d.length-1]):d[d.length-1],c=d.length-1,p=[];n.values.forEach((A,S)=>{if(O.size>0&&!O.has(S))return;const y=[];A.forEach((P,u)=>{const i=k?P>0?Math.log10(P):NaN:P;!Number.isFinite(i)||i<x||i>g||Math.min(c-1,Math.floor((i-x)/(g-x)*c))===o&&y.push(n.units[S][u])});for(const P of st(n.unit,y,S))p.push(P)}),p.length>0&&(_.style.display="none",m.onSelectPoints(p,{x:t.clientX,y:t.clientY},C,{range:{lo:d[o],hi:d[o+1]},...O.size===1?{group:e.groups[[...O][0]]}:{}}))}))}else if(e.marks.type==="heatmap"){const n=e.marks;C.addEventListener("mousemove",t=>{const o=zt(t);if(C.style.cursor=o&&m.onSelectPoints&&n.cellUnits[o.r][o.c].length?"pointer":"default",!o){_.style.display="none",be&&(be=null,K());return}_.innerHTML=Mn(o),_.style.display="block",yt(_,W,t.clientX,t.clientY),(!be||be.r!==o.r||be.c!==o.c)&&(be=o,K())}),C.addEventListener("mouseleave",()=>{_.style.display="none",be&&(be=null,K())}),C.addEventListener("click",t=>{const o=zt(t);if(!o||!m.onSelectPoints)return;const d=n.cellUnits[o.r][o.c];d.length&&(_.style.display="none",m.onSelectPoints(st(n.unit,d,0),{x:t.clientX,y:t.clientY},C))})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const t=z.createElement("div");t.dataset.wmapRowScroll="1",t.tabIndex=0,t.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(t.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const o=z.createElement("div");o.style.width="1px",t.appendChild(o),t.addEventListener("scroll",()=>{Math.abs(t.scrollTop-lt)<1||(lt=t.scrollTop,_.style.display="none",K())}),C.addEventListener("wheel",d=>{if(t.style.display==="none")return;const k=t.scrollTop;t.scrollTop+=d.deltaMode===1?d.deltaY*16:d.deltaY,t.scrollTop!==k&&d.preventDefault()},{passive:!1}),R.appendChild(t),Pe=t}C.addEventListener("mousemove",t=>{const o=$t(t);if(C.style.cursor=o&&(n.categoryItems&&m.onOpenWafer||m.onSelectPoints&&n.cellUnits[o.g][o.c].length>0)?"pointer":"default",!o){_.style.display="none",se&&(se=null,K());return}_.innerHTML=gn(o),_.style.display="block",yt(_,W,t.clientX,t.clientY),(!se||se.g!==o.g||se.c!==o.c)&&(se=o,K())}),C.addEventListener("mouseleave",()=>{_.style.display="none",se&&(se=null,K())}),m.onWaferMenu&&n.categoryItems&&C.addEventListener("contextmenu",t=>{const o=$t(t),d=o?n.categoryItems[o.c]:void 0;d===void 0||d<0||(_.style.display="none",m.onWaferMenu(d,Ve(e.spec),t))}),C.addEventListener("click",t=>{const o=$t(t);if(!o)return;const d=n.categoryItems?.[o.c];if(d!==void 0&&d>=0&&m.onOpenWafer){m.onOpenWafer(d,Ve(e.spec));return}const k=n.cellUnits[o.g][o.c];k.length>0&&m.onSelectPoints&&(_.style.display="none",m.onSelectPoints(st(n.unit,k,o.g),{x:t.clientX,y:t.clientY},C,{category:n.categories[o.c],...e.groups.length>1?{group:e.groups[o.g]}:{},...mn(n.categories[o.c])}))})}else if(e.marks.type==="line"){C.addEventListener("mousemove",t=>{const o=Pt(t);if(!o){_.style.display="none",K();return}_.innerHTML=o,_.style.display="block",yt(_,W,t.clientX,t.clientY),K()}),C.addEventListener("mouseleave",()=>{_.style.display="none",ke>=0&&(ke=-1,K())});const n=e.marks;if(m.onWaferMenu&&C.addEventListener("contextmenu",t=>{const o=Pt(t)===null?void 0:Ft(ke);o!==void 0&&(_.style.display="none",m.onWaferMenu(o,Ve(e.spec),t))}),m.onSelectPoints){C.style.cursor="pointer";let t=!1;C.addEventListener("mousedown",o=>{if(o.button!==0)return;t=!1;const d=C.getBoundingClientRect(),k=o.clientX-d.left,x=g=>{z.removeEventListener("mouseup",x);const c=g.clientX-d.left;if(Math.abs(c-k)<4)return;t=!0;const[p,A]=k<c?[k,c]:[c,k],S=de.map((P,u)=>P>=p&&P<=A?u:-1).filter(P=>P>=0),y=n.cellUnits.flatMap((P,u)=>O.size>0&&!O.has(u)?[]:S.flatMap(i=>st(n.unit,P[i]??[],u)));y.length>0&&(_.style.display="none",m.onSelectPoints(y,{x:g.clientX,y:g.clientY},C))};z.addEventListener("mouseup",x)}),C.addEventListener("click",o=>{if(t){t=!1;return}if(Pt(o)===null||ke<0)return;const d=n.cellUnits.flatMap((k,x)=>O.size>0&&!O.has(x)?[]:st(n.unit,k[ke]??[],x));d.length>0&&(_.style.display="none",m.onSelectPoints(d,{x:o.clientX,y:o.clientY},C))})}}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,f)=>({label:a||"(none)",color:ee(f)})):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:q,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()}}}
|