@wafertools/wafermap 0.38.0 → 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 +55 -0
- package/README.md +2 -1
- package/dist/packages/canvas-adapter/cellShade.d.ts +21 -0
- package/dist/packages/canvas-adapter/cellShade.js +1 -0
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +19 -3
- 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 -0
- 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/filterJson.d.ts +25 -0
- package/dist/packages/canvas-adapter/filterJson.js +5 -0
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/pageFilter.js +2 -2
- 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/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +40 -18
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -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/fmt.js +1 -1
- package/dist/packages/stats/chartCatalogue.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 +11 -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/synthesis.d.ts +6 -0
- 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 +1 -1
|
@@ -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,6 +19,8 @@ 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. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{escHtml as D,maxOf as Te,minOf as Gt}from"../../core/utils.js";import{fiveNumberSummary as Dt,normalQuantile as jt,sampleVariance as Bn}from"../../stats/math.js";import{CONTROL_RULE_TEXT as Wn}from"../../stats/control.js";import{PAT_VERDICT_LABEL as Ut}from"../../stats/pat.js";import{fmt as J}from"../../renderer/fmt.js";import{fitTicks as dt}from"../../renderer/axisTicks.js";import{binOfLabel as In,plotFootnote as qt,plotGuideSections as Yt,plotTestNumber as He,plotTitle as On,probabilityPosition as at}from"../../stats/plotData.js";import{SPACE as me,RADIUS as Nn,fontPx as te,FONT as mt,CLR as et,markNoPrint as Ht}from"../toolbar.js";import{cardShell as Fn,appendGuideCites as Rn,observeResize as zn,makeTooltip as _n,attachChartTip as Xn,chartFillHeight as Gn,applyCanvasFlow as _e,prepareCanvas as Xe,positionChartTooltip as pt,resolveChartCanvasColors as Ge,makeAxisFormat as Dn,horizontalTickSpacing as Kt,VERTICAL_TICK_SPACING_PX as jn,makeSeriesLegendItem as Un,renderEmptyState as Vt,isExpandedCard as Zt,makeLabeledSelect as qn,fillTextOnHalo as Lt,limitLines as Yn,limitExtent as Hn,stackLabelRows as Qt,placeClearOf as Jt,strokeLimitLine as en,drawOffAxisLimits as Kn,limitLabelPlacement as Vn,shouldIncludeLimitsByDefault as Zn,WAFER_MENU_HINT as At}from"./chartShell.js";import{guideCitesText as Qn}from"../../stats/guideSections.js";import{categorical as Jn}from"./palette.js";import{NO_DATA_FILL as tn}from"../../renderer/colorMap.js";import{resolveValueColorFn as gt}from"../../renderer/colorSchemes.js";import{wirePointInteractions as Et}from"./pointInteractions.js";import{plotAbout as eo}from"./cardAbout.js";const Ct=64,yt=16,Bt=12,De=52,to=16,no=92,oo=16,bt=5e3,nn=1500,rt=100,lo=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],on=m=>`${+(m*100).toPrecision(4)}%`;export function categoryLayout(m){const B=.8/Math.max(1,...m.map(W=>W.length)),U=W=>(1-m[W].length*B)/2;return{width:B,left:(W,q)=>{const V=m[W].indexOf(q);return V<0?void 0:U(W)+V*B},groupAt:(W,q)=>{const V=Math.floor((q-U(W))/B);return V>=0&&V<m[W].length?m[W][V]:void 0}}}function so(m){if(m<=nn)return Array.from({length:m},(W,q)=>q);const R=[];for(let W=0;W<rt;W++)R.push(W);const B=nn-2*rt,U=m-2*rt;for(let W=0;W<B;W++)R.push(rt+Math.floor(W*U/B));for(let W=m-rt;W<m;W++)R.push(W);return R}function Wt(m,R,B){return B?Math.round(m).toLocaleString("en-GB"):R?J(m,R):`${m<=-.005?"\u2212":""}${Math.abs(m).toFixed(2)}`}const io=260;function ao(m){const R=[...m.querySelectorAll("[data-wmap-plot-panel]")],B=R[0]?.querySelector("canvas");if(!B)return null;const U=B.width/Math.max(1,B.getBoundingClientRect().width)||1,W=m.getBoundingClientRect(),q=m.ownerDocument.createElement("canvas");q.width=Math.ceil(W.width*U),q.height=Math.ceil(W.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 R){const Se=Me.querySelector("canvas"),ce=Me.dataset.wmapChartTitle??"",z=(Se??Me).getBoundingClientRect(),i=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,(i.left-W.left+8)*U,(i.top-W.top+6)*U),Se&&V.drawImage(Se,(z.left-W.left)*U,(z.top-W.top)*U,z.width*U,z.height*U)}return q}const We=(m,R)=>R.extent?[...m,...R.extent]:m;function ue(m,R,B={}){const U=R.scale==="log";let W=m.length?Gt(m):0,q=m.length?Te(m):1;U&&(W=Math.log10(Math.max(W,Number.MIN_VALUE)),q=Math.log10(Math.max(q,Number.MIN_VALUE)));const V=(q-W)*.05||(U?.5:1);W=B.floorAtZero&&!U&&W>=0?0:W-V,q+=V;const Me=Q=>Q===void 0||!Number.isFinite(Q)?void 0:U?Q>0?Math.log10(Q):void 0:Q,Se=Me(R.min),ce=Me(R.max);Se!==void 0&&(W=Se),ce!==void 0&&(q=ce),q>W||(q=W+1);const z=q-W,i=!!R.reverse,$=Q=>{const ee=((U?Math.log10(Math.max(Q,Number.MIN_VALUE)):Q)-W)/z;return i?1-ee:ee};return{lo:U?10**W:W,hi:U?10**q:q,log:U,reverse:i,frac:$}}function It(m,R,B,U){if(R/m<10)return dt(m,R,B,U);const W=Math.floor(Math.log10(m)),q=Math.ceil(Math.log10(R)),V=Se=>{const ce=[];for(let z=W;z<=q;z++)for(const i of Se){const $=i*10**z;$>=m&&$<=R&&ce.push($)}return ce},we=V([1]);return{ticks:we.length>=4?we:V([1,2,5]),step:0}}export function renderPlotChart(m){const R=m.ownerDocument??document,{card:B,heading:U,body:W,controlsRow:q,setPngDecor:V,setPngCanvas:we,setAbout:Me,setMenuRows:Se}=Fn(m.panel?.title??"Plot",m.onSaveImage,R,{png:!m.panel});m.panel&&(B.dataset.wmapPlotPanel="1");let ce=[];B.dataset.wmapPlotCard="1";const z=_n(B);let i,$,Q,ee,Ke,Ie,ct,ft=!1;B.addEventListener("pointerenter",()=>{ft=!0,B.dataset.wmapPlotPanelsOwner&&(B.dataset.wmapPanelsHover="1")}),B.addEventListener("pointerleave",()=>{ft=!1,delete B.dataset.wmapPanelsHover});let tt=[];const I=new Set,he=new Set;let pe=null,ge=-1,se=[],Z,Ee,ne,ie=null,nt=0,$e,ut;const ln=()=>!!i?.facets;let de=[],ke=-1,xt=new Map,je=[],Ue=De,k=Ct,T=Bt;const sn={[Ut.outlier]:"#e69f00",[Ut.fails]:"#c0392b"},oe=e=>{const l=i?.groups[e]??"";if(i?.colorBins&&m.binColors){const s=In(l);return s===void 0?tn:(i.colorBins==="hard"?m.binColors.hard:m.binColors.soft).get(s)??tn}return sn[l]??Jn(e)},qe=e=>i?.groups[e]||"";function Oe(){const e=W.clientWidth,l=(m.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(Ue-De),s=Gn(B,W,$,l);return{w:e,h:s,plotW:Math.max(10,e-k-yt),plotH:Math.max(10,s-T-Ue)}}const Ce=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[...Yn(e?.limits,i?.spec.limits??"both"),...l].filter(s=>e?.scale!=="log"||s.value>0)},Ne=(e,l,s)=>{const r=s?.clip,a=r?[...e.filter(h=>h>=r.lo&&h<=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}=Hn(l);return(s?i?.spec.axes?.[s===i?.x?"x":"y"]?.includeLimits:void 0)??Zn(Gt(u),Te(u),n,t)?[...a,...l.map(h=>h.value)]:a};let vt;function Ve(e,l,s,r=!1){return!r&&!i?.x?.clip&&!i?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(k,T,l,s),e.clip(),vt=e,Ot)}function Ot(){vt?.restore(),vt=void 0}function Fe(e,l,s,r,a,u,n,t,o){const h=[];if(u.length===0)return()=>{};const w=u.filter(p=>p.value>=a.lo&&p.value<=a.hi),v=u.filter(p=>!w.includes(p)).map(p=>({value:p.value,label:p.label,side:p.value<a.lo?"lo":"hi"}));e.save(),e.font=`${te(-1)}px system-ui, sans-serif`;const b=p=>`${p.label} ${J(p.value,n.unit)}`.trim(),f=te(-1)+2;for(const p of u){if(p.bandTo===void 0)continue;const L=a.frac(Math.min(p.value,p.bandTo)),M=a.frac(Math.max(p.value,p.bandTo)),g=Math.max(0,Math.min(L,M)),y=Math.min(1,Math.max(L,M));y<=g||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(k,T+(1-y)*r,s,(y-g)*r):e.fillRect(k+g*s,T,(y-g)*s,r),e.restore())}if(t==="y"){const p=w.map(g=>{const y=T+(1-a.frac(g.value))*r;return{l:g,y,start:y-6-f/2,end:y-6+f/2}}),L=Qt(p,1),M=p.length?Te(p.map(g=>e.measureText(b(g.l)).width))+8:0;p.forEach(({l:g,y},d)=>{e.globalAlpha=.7,en(e,g,l,k,y,k+s,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const c=k+3+L[d]*M,C=Jt(je,{x0:c,x1:c+e.measureText(b(g)).width,y0:y-4-f+2,y1:y-4+2},f);if(!o){e.fillText(b(g),c,C.y1-2);return}h.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",Lt(e,b(g),c,C.y1-2,o.halo),e.restore()})})}else{const p=w.map(M=>{const g=k+a.frac(M.value)*s,y=b(M),d=M.label.split(/\s+/)[0],c=J(M.value,n.unit),C=d&&d!==M.label?[y,`${d} ${c}`,d]:[y],O=w.filter(A=>A!==M).map(A=>k+a.frac(A.value)*s),{text:_,side:P}=Vn(g,C,A=>e.measureText(A).width,k,k+s,M.end==="lo",O),E=e.measureText(_).width;return{l:M,x:g,side:P,shown:_,start:P<0?g-3-E:g+3,end:P<0?g-3:g+3+E}}),L=Qt(p,4);p.forEach(({l:M,x:g,side:y,shown:d,start:c,end:C},O)=>{e.globalAlpha=.7,en(e,M,l,g,T,g,T+r),e.globalAlpha=1;const _=y<0?"right":"left";e.fillStyle=l,e.textAlign=_,e.textBaseline="top";const P=T+2+L[O]*f,E=Jt(je,{x0:c,x1:C,y0:P,y1:P+f},f);if(!o){e.fillText(d,g+y*3,E.y0);return}h.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=_,e.textBaseline="top",Lt(e,d,g+y*3,E.y0,o.halo),e.restore()})})}return e.restore(),Kn(e,v,{left:k,right:k+s,top:T,bottom:T+r},t==="y"?"vertical":"horizontal",l,p=>J(p,n.unit),void 0,je),()=>h.forEach(p=>p())}function Mt(e,l,s,r){return Dn(Math.max(Math.abs(l),Math.abs(s)),e.unit,r,e.label)}function ht(e,l){return l?`${e.label} (${l})`:e.label}const kt=18,Tt=(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 Ye(e,l,s,r,a,u,n,t,o,h,w){je=[],e.font=`${te(-1)}px system-ui, sans-serif`;const v=()=>jn,b=w?{ticks:w.map(g=>g.at),step:0}:t.log?It(t.lo,t.hi,u,v):dt(t.lo,t.hi,u,v),f=new Map(w?.map(g=>[g.at,g.label])),p=Mt(h,t.lo,t.hi,b.step||void 0),L=w?{tick:g=>f.get(g)??"",unitLabel:""}:p;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let M="";if("labels"in n){const g=n.labels.length;if(n.labels.forEach((y,d)=>{const c=k+(d+.5)/g*a,C=y.length>22?`${y.slice(0,21)}\u2026`:y;n.rotate?(e.save(),e.translate(c,T+u+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(C,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(C,c,T+u+4))}),n.nest){const y=n.nest[0]?.length??0,d=a/g;for(let c=y-2;c>=0;c--){const C=r-6-kt-c*kt,O=P=>n.nest[P].slice(0,c+1).join("");let _=0;for(let P=1;P<=g;P++){if(P<g&&O(P)===O(_))continue;const A=k+_*d,j=k+P*d;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Tt(e,n.nest[_][c],j-A-4),(A+j)/2,C),P<g&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=c===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(j,T),e.lineTo(j,C-2),e.stroke(),e.restore()),_=P}}e.fillStyle=l.textMuted}}else{const g=Kt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),y=n.log?It(n.lo,n.hi,a,g):dt(n.lo,n.hi,a,g),d=Mt(o,n.lo,n.hi,y.step||void 0);M=d.unitLabel;for(const c of y.ticks){const C=k+n.frac(c)*a;e.beginPath(),e.moveTo(C,T),e.lineTo(C,T+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(d.tick(c),C,T+u+4)}}for(const g of b.ticks){const y=T+(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(L.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(ht(o,M),k+a/2,r-6),e.save(),e.translate(14,T+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ht(h,L.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,T),e.lineTo(k,T+u),e.moveTo(k,T+u),e.lineTo(k+a,T+u),e.stroke()}function an(e,l,s,r,a,u,n,t,o,h,w,v={along:u,offset:0}){je=[],e.font=`${te(-1)}px system-ui, sans-serif`;const b=Kt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),w.unit),f=o.log?It(o.lo,o.hi,a,b):dt(o.lo,o.hi,a,b),p=Mt(w,o.lo,o.hi,f.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const c of f.ticks){const C=k+o.frac(c)*a;e.beginPath(),e.moveTo(C,T),e.lineTo(C,T+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(c),C,T+u+4)}const L=n.labels.length,M=v.along/Math.max(1,L),g=T-v.offset;e.save(),e.beginPath(),e.rect(0,T-1,k+a+1,u+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const y=Math.max(0,Math.floor(v.offset/M)),d=Math.min(L,Math.ceil((v.offset+u)/M));for(let c=y;c<d;c++)e.fillText(Tt(e,n.labels[c],t.inner),k-6,g+(c+.5)*M);if(n.nest){const c=n.nest[0]?.length??0;let C=k-6-t.inner-10;for(let O=c-2;O>=0;O--){const _=t.outer[O]??0,P=A=>n.nest[A].slice(0,O+1).join("");let E=0;for(let A=1;A<=L;A++){if(A<L&&P(A)===P(E))continue;const j=g+E*M,x=g+A*M;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(Tt(e,n.nest[E][O],_),C,(j+x)/2),A<L&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=O===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(C-_,x),e.lineTo(k+a,x),e.stroke(),e.restore()),E=A}C-=_+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(ht(w,p.unitLabel),k+a/2,r-6),e.save(),e.translate(14,T+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ht(h,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,T),e.lineTo(k,T+u),e.moveTo(k,T+u),e.lineTo(k+a,T+u),e.stroke()}function rn(){if(!i||!$||i.marks?.type!=="scatter"||!i.x||!i.y)return;_e($,ee??0);const e=Ge(B),{w:l,h:s,plotW:r,plotH:a}=Oe(),u=Xe($,B,l,s);if(!u)return;const{ctx:n}=u,t=i.marks.points,o=I.size===0?t:t.filter(P=>I.has(P.group)),h=i.colorScale,w=gt(),v=Ce(i.x),b=Ce(i.y),f=ue(Ne(We(t.map(P=>P.x),i.x),v,i.x),i.x),p=ue(Ne(We(t.map(P=>P.y),i.y),b,i.y),i.y);Z={x:f,y:p,plotW:r,plotH:a},Ye(n,e,l,s,r,a,f,p,i.x,i.y),Fe(n,e.limitLine,r,a,f,v,i.x,"x"),Fe(n,e.limitLine,r,a,p,b,i.y,"y"),Ve(n,r,a);const L=o.length>bt?Math.ceil(o.length/bt):1,M=[];for(let P=0;P<o.length;P+=L)M.push(o[P]);n.globalAlpha=Math.max(.15,Math.min(.7,200/M.length));let g;if(h)g=[M];else{const P=new Map;for(const E of M){const A=P.get(E.group);A?A.push(E):P.set(E.group,[E])}g=[...P.values()].sort((E,A)=>A.length-E.length)}se=[];const y=k,d=k+r,c=T,C=T+a;for(const P of g)for(const E of P){const A=k+f.frac(E.x)*r,j=T+(1-p.frac(E.y))*a;A<y||A>d||j<c||j>C||(se.push({p:E,cx:A,cy:j}),n.beginPath(),n.arc(A,j,2.5,0,Math.PI*2),n.fillStyle=h&&E.value!==void 0?w((E.value-h.lo)/(h.hi-h.lo||1)):oe(E.group),n.fill())}n.globalAlpha=1;const O=i.marks;if(O.type==="scatter"&&(O.identity||O.fits)){const P=(A,j)=>[k+f.frac(A)*r,T+(1-p.frac(j))*a],E=(A,j,x)=>{n.save(),n.beginPath(),n.rect(k,T,r,a),n.clip(),n.strokeStyle=j,n.lineWidth=2,n.setLineDash(x),n.beginPath();for(let be=0;be<=60;be++){const Be=be/60,ze=f.log?10**(Math.log10(f.lo)+(Math.log10(f.hi)-Math.log10(f.lo))*Be):f.lo+(f.hi-f.lo)*Be,[Pe,fe]=P(ze,A(ze));be===0?n.moveTo(Pe,fe):n.lineTo(Pe,fe)}n.stroke(),n.restore()};O.identity&&E(A=>A,e.textMuted,[6,4]);for(const A of O.fits??[])I.size>0&&!I.has(A.group)&&!h||E(j=>A.intercept+A.slope*j,h?e.text:oe(A.group),[])}const _=pe?se.find(P=>P.p===pe):void 0;if(_&&(n.beginPath(),n.arc(_.cx,_.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 P=0;for(const E of he)if(!(I.size>0&&!I.has(E.group))){if(++P>bt)break;n.beginPath(),n.arc(k+f.frac(E.x)*r,T+(1-p.frac(E.y))*a,4,0,Math.PI*2),n.stroke()}}}function cn(){if(Ee=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(Ne(We(l,i.x),Ce(i.x),i.x),i.x),r=Math.max(1,i.spec.bins??oo),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,f)=>{const p=a+(u-a)*f/r;return s.log?10**p:p}),t=e.map(()=>new Array(r).fill(0));e.forEach((b,f)=>{for(const p of b){const L=s.log?p>0?Math.log10(p):NaN:p;if(!Number.isFinite(L)||L<a||L>u)continue;const M=Math.min(r-1,Math.floor((L-a)/(u-a)*r));t[f][M]++}});const o=i.spec.histNorm==="percent",h=o?t.map(b=>{const f=b.reduce((p,L)=>p+L,0);return b.map(p=>f?p/f*100:0)}):t;let w=0;const v=e.map(()=>{});if(i.spec.normalCurve&&!s.log){const b=(n[n.length-1]-n[0])/r;e.forEach((f,p)=>{const L=f.filter(Number.isFinite);if(L.length<2)return;const M=L.reduce((y,d)=>y+d,0)/L.length,g=Math.sqrt(Bn(L,M));g>0&&(v[p]={mean:M,sd:g},w=Math.max(w,(o?100:t[p].reduce((y,d)=>y+d,0))*b/(g*Math.sqrt(2*Math.PI))))})}Ee={edges:n,counts:t,heights:h,normal:v,maxCount:Math.max(o?.001:1,w,...h.map(b=>Te(b)))}}function fn(){if(!i||!$||!Ee||!i.x||!i.y)return;_e($,ee??0);const e=Ge(B),{w:l,h:s,plotW:r,plotH:a}=Oe(),u=Xe($,B,l,s);if(!u)return;const{ctx:n}=u,{edges:t,counts:o,heights:h,normal:w,maxCount:v}=Ee,b=ue([t[0],t[t.length-1]],{...i.x,min:t[0],max:t[t.length-1]}),f=ue([0,v],{label:i.y.label,scale:"linear",min:0,max:v*1.05});Z={x:b,y:f,plotW:r,plotH:a},Ye(n,e,l,s,r,a,b,f,i.x,i.y),Fe(n,e.limitLine,r,a,b,Ce(i.x),i.x,"x"),Ve(n,r,a);const p=o.map((M,g)=>g).filter(M=>I.size===0||I.has(M)),L=p.length>1;for(const M of p)n.globalAlpha=L?.55:.85,n.fillStyle=oe(M),h[M].forEach((g,y)=>{if(g===0)return;const d=k+Math.min(b.frac(t[y]),b.frac(t[y+1]))*r,c=k+Math.max(b.frac(t[y]),b.frac(t[y+1]))*r,C=T+(1-f.frac(g))*a;n.fillRect(d,C,Math.max(1,c-d-1),T+a-C)});if(n.globalAlpha=1,i.spec.normalCurve&&!b.log){const M=(t[t.length-1]-t[0])/(t.length-1);for(const g of p){const y=w[g];if(!y)continue;const{mean:d,sd:c}=y,C=(i.spec.histNorm==="percent"?100:o[g].reduce((O,_)=>O+_,0))*M;n.save(),n.beginPath(),n.rect(k,T,r,a),n.clip(),n.strokeStyle=oe(g),n.lineWidth=2,n.beginPath();for(let O=0;O<=120;O++){const _=t[0]+(t[t.length-1]-t[0])*O/120,P=Math.exp(-.5*((_-d)/c)**2)/(c*Math.sqrt(2*Math.PI)),E=k+b.frac(_)*r,A=T+(1-f.frac(C*P))*a;O===0?n.moveTo(E,A):n.lineTo(E,A)}n.stroke(),n.restore()}}if(ge>=0){const M=k+Math.min(b.frac(t[ge]),b.frac(t[ge+1]))*r,g=k+Math.max(b.frac(t[ge]),b.frac(t[ge+1]))*r;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(M,T,Math.max(1,g-M),a)}}function un(){const e=i?.marks;if(!i||!$||!i.x||!i.y||!e||e.type!=="box"&&e.type!=="bar")return;_e($,ee??0);const l=Ge(B),s=i.spec.orientation==="horizontal",r=e.nest?e.nest.parts.map(S=>S[S.length-1]):e.categories,a=e.categories.length,u=i.groups.length,n=S=>I.size===0||I.has(S),t=e.type==="bar"&&!!e.stack,o=(S,F)=>e.type==="bar"?Number.isFinite(e.values[S][F]):e.cells[S][F].length>0,h=Array.from({length:a},(S,F)=>Array.from({length:u},(N,X)=>X).filter(N=>n(N)&&o(N,F))),w=categoryLayout(t?h.map(S=>S.length?[0]:[]):h),v=$.getContext("2d"),b=S=>v?v.measureText(S).width:S.length*6;v&&(v.font=`${te(-1)}px system-ui, sans-serif`);const f=(S,F)=>S.length>F?`${S.slice(0,F-1)}\u2026`:S;let p=!1,L={inner:0,outer:[]},M=0;if(s){L={inner:Math.min(200,Te(r.map(F=>b(f(F,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((F,N)=>Math.min(140,Te(e.nest.parts.map(X=>b(f(X[N],20)))))):[]},k=Math.max(Ct,30+L.inner+6+L.outer.reduce((F,N)=>F+N+10,0)),e.cumulative&&(T=Bt+18),Ue=De;const S=Math.max(1,...h.map(F=>t?Math.min(1,F.length):F.length));M=Math.max(22,S*to/.8)}else{const S=Te(r.map(X=>b(f(X,22)))),F=Math.max(10,W.clientWidth-k-yt)/Math.max(1,a);p=S+8>F;const N=e.nest?e.nest.levels.length-1:0;Ue=(p?De+Math.min(110,S*.72):De)+N*kt}const g=e.type==="bar"&&!t&&!!i.spec.valueLabels,y=i.y.unit,d=S=>J(S,y),c=g?Te(e.values.flat().filter(Number.isFinite).map(S=>b(d(S))).concat(0))+8:0,C=s?c:e.cumulative?40:0,{w:O,h:_,plotW:P,plotH:E}=Oe(),A=Math.max(10,P-C),j=Xe($,B,O,_);if(!j)return;const{ctx:x}=j,be=S=>S.filter(Number.isFinite),Be=Ce(i.y),ze=t?e.categories.map((S,F)=>e.values.reduce((N,X,Y)=>N+(n(Y)&&Number.isFinite(X[F])?X[F]:0),0)):[],Pe=e.type==="bar"?[...t?ze:be(e.values.flat()),0]:be(e.cells.flat(2));x.font=`${te(-1)}px system-ui, sans-serif`;const fe=s?c:te(-1)+6;if(g&&!s&&Pe.length){const S=Te(Pe);S>0&&Pe.push(S*(1+fe/Math.max(1,E-fe)))}const Le=ue(Ne(We(Pe,i.y),Be,i.y),i.y,{floorAtZero:e.type==="bar"});Z={x:Le,y:Le,plotW:A,plotH:E};const lt=s?E:A,Ze=s&&a*M>E+.5,st=Ze?a*M:lt,it=Ze?Math.max(0,Math.min(nt,st-lt)):0;nt=it,wn(Ze,st,it,A+C,E),s?an(x,l,O,_,A,E,{labels:r,rotate:!1,nest:e.nest?.parts},L,Le,i.x,i.y,{along:st,offset:it}):Ye(x,l,O,_,A,E,{labels:r,rotate:p,nest:e.nest?.parts},Le,i.x,i.y);const xe=st/a,Ae=w.width*xe;ne={slotW:xe,n:a,plotW:st,layout:w,across:s,offset:it,view:lt};const le=S=>s?k+Le.frac(S)*A:T+(1-Le.frac(S))*E,ve=S=>s?T+S-it:k+S,$t=Le.log?s?k:T+E:le(0),Qe=(S,F,N,X)=>s?[Math.min(N,X),ve(S),Math.max(1,Math.abs(X-N)),F-S]:[ve(S),Math.min(N,X),F-S,Math.max(1,Math.abs(X-N))],Pt=(S,F,N,X)=>{x.beginPath(),s?(x.moveTo(F,ve(S)),x.lineTo(X,ve(N))):(x.moveTo(ve(S),F),x.lineTo(ve(N),X)),x.stroke()},Je=S=>s?S>=$t:S<=$t,An=S=>s?te(-1)<=Ae+4:x.measureText(d(S)).width<=Ae+6,zt=g&&e.values.every(S=>S.every(F=>!Number.isFinite(F)||An(F)));if(zt){for(let S=0;S<u;S++)if(n(S))for(let F=0;F<a;F++){const N=w.left(F,S),X=e.values[S][F];if(N===void 0||!Number.isFinite(X))continue;const Y=ve(F*xe+N*xe+Ae/2),H=x.measureText(d(X)).width,G=le(X);s?je.push(Je(G)?{x0:G,x1:G+H+6,y0:Y-fe/2,y1:Y+fe/2}:{x0:G-H-6,x1:G,y0:Y-8,y1:Y+8}):je.push(Je(G)?{x0:Y-H/2,x1:Y+H/2,y0:G-fe,y1:G}:{x0:Y-H/2,x1:Y+H/2,y0:G,y1:G+fe})}}const En=Fe(x,l.limitLine,A,E,Le,Be,i.y,s?"x":"y",{halo:l.bg}),Cn=Ve(x,A,E,Ze);if(t){ne.stacks=[];for(let S=0;S<a;S++){const F=w.left(S,0),N=[];if(ne.stacks.push(N),F===void 0)continue;let X=0;for(let Y=0;Y<u;Y++){const H=e.values[Y][S];if(!n(Y)||!Number.isFinite(H)||H<=0)continue;const G=le(X),ae=le(X+H);x.fillStyle=oe(Y),x.globalAlpha=.9;const re=S*xe+F*xe;x.fillRect(...Qe(re+1,re+Ae-1,G,ae)),x.globalAlpha=1,N.push({g:Y,p0:Math.min(G,ae),p1:Math.max(G,ae)}),X+=H}}}for(let S=0;S<u&&!t;S++){if(I.size>0&&!I.has(S))continue;const F=oe(S);for(let N=0;N<a;N++){const X=w.left(N,S);if(X===void 0)continue;const Y=N*xe+X*xe;if(e.type==="bar"){const H=e.values[S][N];if(!Number.isFinite(H))continue;const G=le(H);if(x.fillStyle=F,x.globalAlpha=.9,x.fillRect(...Qe(Y+1,Y+Ae-1,$t,G)),x.globalAlpha=1,zt){x.fillStyle=l.text,x.font=`${te(-1)}px system-ui, sans-serif`;const ae=ve(Y+Ae/2);s?(x.textBaseline="middle",x.textAlign=Je(G)?"left":"right",x.fillText(d(H),G+(Je(G)?3:-3),ae)):(x.textAlign="center",x.textBaseline=Je(G)?"bottom":"top",x.fillText(d(H),ae,G+(Je(G)?-2:2)))}}else{const H=e.cells[S][N];if(H.length===0)continue;const G=Y+Ae/2,ae=Math.max(3,Math.min(Ae*.7,46)),re=Dt(Float64Array.from(H));if(x.strokeStyle=F,x.fillStyle=F,x.lineWidth=1.5,H.length===1){x.beginPath(),s?x.arc(le(re.median),ve(G),3,0,Math.PI*2):x.arc(ve(G),le(re.median),3,0,Math.PI*2),x.fill();continue}Pt(G,le(re.min),G,le(re.max));for(const Xt of[re.min,re.max])Pt(G-ae/4,le(Xt),G+ae/4,le(Xt));x.globalAlpha=.35,x.fillRect(...Qe(G-ae/2,G+ae/2,le(re.q1),le(re.q3))),x.globalAlpha=1,x.strokeRect(...Qe(G-ae/2,G+ae/2,le(re.q1),le(re.q3))),x.lineWidth=2.5,Pt(G-ae/2,le(re.median),G+ae/2,le(re.median))}}}Cn(),En();const _t=ie?w.left(ie.c,t?0:ie.g):void 0;if(ie&&_t!==void 0){Ze&&(x.save(),x.beginPath(),x.rect(k-1,T,A+2,E),x.clip()),x.lineWidth=1.5,x.strokeStyle=l.text;const S=ie.c*xe+_t*xe,F=t?ne.stacks?.[ie.c]?.find(N=>N.g===ie.g):void 0;t&&F?x.strokeRect(...Qe(S,S+Ae,F.p0,F.p1)):t||x.strokeRect(...Qe(S,S+Ae,s?k:T,s?k+A:T+E)),Ze&&x.restore()}if(e.cumulative){const S=N=>s?k+N/100*A:T+(1-N/100)*E,F=(N,X)=>s?[S(X),ve((N+.5)*xe)]:[ve((N+.5)*xe),S(X)];if(x.save(),x.strokeStyle=l.text,x.fillStyle=l.text,x.lineWidth=1.5,x.beginPath(),e.cumulative.forEach((N,X)=>{const[Y,H]=F(X,N);X===0?x.moveTo(Y,H):x.lineTo(Y,H)}),x.stroke(),e.cumulative.forEach((N,X)=>{const[Y,H]=F(X,N);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,T),x.lineTo(k+A,T)):(x.moveTo(k+A,T),x.lineTo(k+A,T+E)),x.stroke(),x.fillStyle=l.textMuted,x.font=`${te(-1)}px system-ui, sans-serif`,s){x.textAlign="center",x.textBaseline="bottom";for(const N of[0,25,50,75,100])x.fillText(`${N}%`,S(N),T-3)}else{x.textAlign="left",x.textBaseline="middle";for(const N of[0,25,50,75,100])x.fillText(`${N}%`,k+A+4,S(N))}x.restore()}}function hn(e){const l=i?.setTests,s=l?l.labels.indexOf(e):-1;return s>=0?{test:l.tests[s]}:{}}function wt(e){if(!ne||!$)return null;const l=$.getBoundingClientRect(),s=ne.across?e.clientY-l.top-T: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 dn(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 h=e.failSide[o];h<0?a++:h>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 mn(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(qe(e.g))?` \xB7 ${D(qe(e.g))}`:"",t=`<strong>${D(s.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(a.length===0)return`${t}no ${r}`;const h=`${a.length.toLocaleString("en-GB")} ${r}`,w=(s.categoryItems&&m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")+(s.categoryItems&&m.onWaferMenu?At:"");if(s.type==="bar"){const b=s.values[e.g][e.c],f=s.cumulative?`<br>${D(`cumulative: ${s.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${D(`${l.y.label}: ${J(b,o)}`)}<br>${D(s.passFail?dn(s.passFail,a,s.cellUnits[e.g][e.c]):h)}${f}${w}`}const v=Dt(Float64Array.from(a));return`${t}${["max","q3","median","q1","min"].map(b=>D(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[b]}: ${J(v[b],o)}`)).join("<br>")}<br>${D(h)}${w}`}function pn(){const e=i?.marks;if(!i||!$||!i.x||!i.y||!e||e.type!=="line")return;_e($,ee??0);const l=Ge(B),{w:s,h:r,plotW:a,plotH:u}=Oe(),n=Xe($,B,s,r);if(!n)return;const{ctx:t}=n,o=Ce(i.x),h=Ce(i.y),w=ue(Ne(We(e.xs,i.x),o,i.x),i.x),v=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],b=ue(Ne(We([...e.values.flat(),...v].filter(Number.isFinite),i.y),h,i.y),i.y);if(Z={x:w,y:b,plotW:a,plotH:u},Ye(t,l,s,r,a,u,w,b,i.x,i.y),Fe(t,l.limitLine,a,u,w,o,i.x,"x"),Fe(t,l.limitLine,a,u,b,h,i.y,"y"),Ve(t,a,u),de=e.xs.map(f=>k+w.frac(f)*a),e.band){const f=p=>T+(1-b.frac(p))*u;e.band.lo.forEach((p,L)=>{if(I.size>0&&!I.has(L))return;const M=e.band.hi[L];t.save(),t.fillStyle=oe(L),t.globalAlpha=.16;let g=[];const y=()=>{if(g.length===1){const d=g[0],c=de[d];t.globalAlpha=.55,t.strokeStyle=oe(L),t.lineWidth=2,t.beginPath(),t.moveTo(c,f(p[d])),t.lineTo(c,f(M[d])),t.moveTo(c-4,f(p[d])),t.lineTo(c+4,f(p[d])),t.moveTo(c-4,f(M[d])),t.lineTo(c+4,f(M[d])),t.stroke(),t.globalAlpha=.16}else if(g.length){t.beginPath(),g.forEach((d,c)=>{c===0?t.moveTo(de[d],f(M[d])):t.lineTo(de[d],f(M[d]))});for(let d=g.length-1;d>=0;d--)t.lineTo(de[g[d]],f(p[g[d]]));t.closePath(),t.fill()}g=[]};p.forEach((d,c)=>{Number.isFinite(d)&&Number.isFinite(M[c])?g.push(c):y()}),y(),t.restore()})}e.values.forEach((f,p)=>{if(I.size>0&&!I.has(p))return;t.strokeStyle=oe(p),t.fillStyle=oe(p),t.lineWidth=2;let L=!1;t.beginPath(),f.forEach((M,g)=>{if(!Number.isFinite(M)){L=!1;return}const y=de[g],d=T+(1-b.frac(M))*u;L?t.lineTo(y,d):t.moveTo(y,d),L=!0}),t.stroke(),f.forEach((M,g)=>{Number.isFinite(M)&&(t.beginPath(),t.arc(de[g],T+(1-b.frac(M))*u,ke===g?4.5:3,0,Math.PI*2),t.fill())})}),ke>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(de[ke],T),t.lineTo(de[ke],T+u),t.stroke())}function St(e){const l=i?.marks;if(!l||l.type!=="line"||!$||!i?.x||de.length===0)return null;const s=e.clientX-$.getBoundingClientRect().left;let r=-1,a=24;if(de.forEach((t,o)=>{const h=Math.abs(t-s);h<a&&(a=h,r=o)}),ke=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)&&(I.size===0||I.has(t.g)));return`<strong>${D(`${i.x.label}: ${J(l.xs[r],i.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][r],h=l.band?.hi[t.g][r],w=o!==void 0&&h!==void 0&&Number.isFinite(o)&&Number.isFinite(h)?`, band ${J(o,i.y.unit)} to ${J(h,i.y.unit)}`:"";return D(`${i.groups.length>1?`${qe(t.g)}: `:""}${J(t.v,i.y.unit)}${w} (${t.n.toLocaleString("en-GB")} ${u})`)}).join("<br>")+(m.onWaferMenu&&Nt(r)!==void 0?At:"")}function Nt(e){const l=i?.marks;if(l?.type!=="line")return;const s=new Set(l.cellUnits.flatMap((r,a)=>I.size>0&&!I.has(a)?[]:(r[e]??[]).map(u=>l.unit(u).item)));return s.size===1?[...s][0]:void 0}function gn(){const e=i?.marks;if(!i||!$||!i.x||!i.y||e?.type!=="probability")return;_e($,ee??0);const l=Ge(B),{w:s,h:r,plotW:a,plotH:u}=Oe(),n=Xe($,B,s,r);if(!n)return;const{ctx:t}=n,o=i.spec.probabilityAxis==="linear",h=e.values.map((P,E)=>E).filter(P=>e.values[P].length>0&&(I.size===0||I.has(P))),w=Math.max(1,...h.map(P=>e.values[P].length)),v=Math.min(.01,at(0,w)),b=P=>o?P:jt(P),f=o?0:b(v),p=o?1:b(1-v),L=o?0:(p-f)*.03,M=ue([f-L,p+L],{label:i.y.label,scale:"linear",min:f-L,max:p+L}),g=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:lo.filter(P=>P>=v&&P<=1-v),y=[],d=P=>T+(1-M.frac(P))*u,c=g.indexOf(.5);y.push({at:b(.5),label:on(.5)});for(const P of[g.slice(c+1),g.slice(0,c).reverse()]){let E=d(b(.5));for(const A of P){const j=d(b(A));Math.abs(j-E)<16||(y.push({at:b(A),label:on(A)}),E=j)}}const C=Ce(i.x),O=ue(Ne(We(h.flatMap(P=>[e.values[P][0],e.values[P][e.values[P].length-1]]),i.x),C,i.x),i.x);Z={x:O,y:M,plotW:a,plotH:u},Ye(t,l,s,r,a,u,O,M,i.x,i.y,y),Fe(t,l.limitLine,a,u,O,C,i.x,"x"),Ve(t,a,u),se=[],t.save(),t.beginPath(),t.rect(k,T,a,u),t.clip();for(const P of h){const E=e.values[P],A=E.length,j=so(A);if(t.strokeStyle=oe(P),t.fillStyle=oe(P),t.lineWidth=1.5,t.beginPath(),j.forEach((x,be)=>{const Be=k+O.frac(E[x])*a,ze=d(b(at(x,A)));be===0?t.moveTo(Be,ze):t.lineTo(Be,ze);const Pe=P*2**26+x;let fe=xt.get(Pe);if(!fe){const{item:Le,die:lt}=e.unit(e.units[P][x]);fe={x:E[x],y:at(x,A),group:P,item:Le,die:lt},xt.set(Pe,fe)}se.push({p:fe,cx:Be,cy:ze})}),t.stroke(),A<=300)for(const x of j)t.beginPath(),t.arc(k+O.frac(E[x])*a,d(b(at(x,A))),2.5,0,Math.PI*2),t.fill()}if(t.restore(),he.size>0){t.lineWidth=1.5,t.strokeStyle=l.text;let P=0;for(const E of he)if(!(I.size>0&&!I.has(E.group))){if(++P>bt)break;t.beginPath(),t.arc(k+O.frac(E.x)*a,d(b(E.y)),4,0,Math.PI*2),t.stroke()}}const _=pe?se.find(P=>P.p===pe):void 0;_&&(t.beginPath(),t.arc(_.cx,_.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function yn(e){const l=i,r=l.marks.values[e.group].length,a=Math.round(e.y*r+.5),u=m.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>${D(t)}</strong><br>`:"")+D(`${l.x.label}: ${J(e.x,l.x.unit)}`)+"<br>"+D(`rank ${a.toLocaleString("en-GB")} of ${r.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${D(qe(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")+(m.onWaferMenu&&!e.die?At:"")}let Re,ye=null;function bn(){const e=i?.marks;if(!i||!$||e?.type!=="heatmap")return;_e($,ee??0);const l=Ge(B),s=$.getContext("2d");let r=0,a=0;s&&(s.font=`${te(-1)}px system-ui, sans-serif`,r=Te(e.rows.map(d=>s.measureText(d.length>24?`${d.slice(0,23)}\u2026`:d).width)),a=Te(e.cols.map(d=>s.measureText(d.length>22?`${d.slice(0,21)}\u2026`:d).width)));const u=Math.min(180,Math.max(k,r+24)),n=Math.max(8,W.clientWidth-u-yt)/Math.max(1,e.cols.length),t=a+8>n;Ue=t?De+Math.min(110,a*.72):De;const{w:o,h}=Oe(),w=Math.max(10,o-u-yt),v=Math.max(10,h-T-Ue),b=Xe($,B,o,h);if(!b)return;const{ctx:f}=b,p=w/e.cols.length,L=v/e.rows.length;Re={left:u,cw:p,ch:L,rows:e.rows.length,cols:e.cols.length};const M=i.colorScale,g=gt(),y=M&&M.hi-M.lo||1;f.font=`${te(-1)}px system-ui, sans-serif`;for(let d=0;d<e.rows.length;d++)for(let c=0;c<e.cols.length;c++){const C=e.values[d][c],O=u+c*p,_=T+d*L;f.fillStyle=Number.isFinite(C)&&M?g((C-M.lo)/y):l.track,f.fillRect(O+.5,_+.5,Math.max(1,p-1),Math.max(1,L-1)),Number.isFinite(C)&&p>=40&&L>=16&&(f.fillStyle="#fff",f.textAlign="center",f.textBaseline="middle",Lt(f,Wt(C,i.y?.unit,M?.integer),O+p/2,_+L/2,"rgba(0,0,0,0.55)"))}ye&&(f.lineWidth=2,f.strokeStyle=l.text,f.strokeRect(u+ye.c*p,T+ye.r*L,p,L)),f.fillStyle=l.textMuted,f.textAlign="right",f.textBaseline="middle",e.rows.forEach((d,c)=>f.fillText(d.length>24?`${d.slice(0,23)}\u2026`:d,u-6,T+(c+.5)*L)),e.cols.forEach((d,c)=>{const C=d.length>22?`${d.slice(0,21)}\u2026`:d,O=u+(c+.5)*p;t?(f.save(),f.translate(O,T+v+6),f.rotate(-Math.PI/4),f.textAlign="right",f.textBaseline="middle",f.fillText(C,0,0),f.restore()):(f.textAlign="center",f.textBaseline="top",f.fillText(C,O,T+v+4))}),f.font=`${te(0)}px system-ui, sans-serif`,f.fillStyle=l.text,f.textAlign="center",f.textBaseline="bottom",f.fillText(i.x?.label??"",u+w/2,h-6)}function Ft(e){if(!Re||!$)return null;const l=$.getBoundingClientRect(),s=Math.floor((e.clientX-l.left-Re.left)/Re.cw),r=Math.floor((e.clientY-l.top-T)/Re.ch);return r>=0&&r<Re.rows&&s>=0&&s<Re.cols?{r,c:s}:null}function xn(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>${D(`${s.rows[e.r]} \xB7 ${s.cols[e.c]}`)}</strong><br>`+(Number.isFinite(r)?D(`${l.y?.label??"Count"}: ${Wt(r,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+D(`${a.toLocaleString("en-GB")} ${u}`)+(a&&m.onSelectPoints?"<br><em>click to chart or tabulate them</em>":"")}function vn(){const e=i?.marks;if(!i||!$||!i.x||!i.y||e?.type!=="control")return;_e($,ee??0);const l=Ge(B),{w:s,h:r,plotW:a,plotH:u}=Oe(),n=Xe($,B,s,r);if(!n)return;const{ctx:t}=n,o=e.limits,h=Ce(i.y),w=ue(We(e.xs,i.x),i.x),v=ue(Ne(We([...e.values,o.ucl,o.lcl],i.y),h,i.y),i.y);Z={x:w,y:v,plotW:a,plotH:u},Ye(t,l,s,r,a,u,w,v,i.x,i.y),Fe(t,l.limitLine,a,u,v,h,i.y,"y"),Ve(t,a,u);const b=y=>k+w.frac(e.xs[y])*a,f=y=>T+(1-v.frac(y))*u;t.save(),t.beginPath(),t.rect(k,T,a,u),t.clip();const p=(y,d,c,C=1)=>{t.globalAlpha=c,t.setLineDash(d),t.lineWidth=C,t.strokeStyle=l.text,t.beginPath(),t.moveTo(k,f(y)),t.lineTo(k+a,f(y)),t.stroke()};for(const y of[-2,-1,1,2])p(o.centre+y*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=`${te(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const L=y=>J(y,i.y.unit);if(t.fillText(`UCL ${L(o.ucl)}`,k+a-4,f(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${L(o.lcl)}`,k+a-4,f(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${L(o.centre)}`,k+a-4,f(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,T),t.lineTo(y,T+u),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",k+4,T+2)}t.strokeStyle=oe(0),t.lineWidth=1.5,t.setLineDash([]),t.beginPath(),e.values.forEach((y,d)=>{d===0?t.moveTo(b(d),f(y)):t.lineTo(b(d),f(y))}),t.stroke();const M=new Map(e.violations.map(y=>[y.index,y.rules]));se=[],e.values.forEach((y,d)=>{const c=M.get(d);t.beginPath(),t.arc(b(d),f(y),c?4.5:3,0,Math.PI*2),t.fillStyle=c?l.alert:oe(0),t.fill(),c&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(c.join(","),b(d),f(y)-6)),se.push({p:{x:e.xs[d],y,group:0,item:e.items[d]},cx:b(d),cy:f(y)})});const g=pe?se.find(y=>y.p===pe):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 Mn(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>${D(m.waferLabel(e.item))}</strong><br>`+D(`${l.y.label}: ${J(e.y,l.y.unit)} (${a>=0?"+":"\u2212"}${Math.abs(a).toFixed(1)}\u03C3)`)+(u?`<br>${D(`breaks rule ${u.map(n=>`${n} (${Wn[n]})`).join(", ")}`)}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")}function kn(){const e=i?.marks;if(!i||!$||!i.x||!i.y||e?.type!=="goal")return;_e($,ee??0);const l=Ge(B),{w:s,h:r,plotW:a,plotH:u}=Oe(),n=Xe($,B,s,r);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(c=>Math.abs(c.x))),h=ue([-o,o],{...i.x,min:i.x.min??-o*1.05,max:i.x.max??o*1.05}),w=ue([0,...e.points.map(c=>c.y),1/6],{...i.y,min:i.y.min??0},{floorAtZero:!0});Z={x:h,y:w,plotW:a,plotH:u},Ye(t,l,s,r,a,u,h,w,i.x,i.y);const v=c=>k+h.frac(c)*a,b=c=>T+(1-w.frac(c))*u;t.save(),t.beginPath(),t.rect(k,T,a,u),t.clip(),t.font=`${te(-1)}px system-ui, sans-serif`;const f=[[1,[6,4]],[1.33,[]]];for(const[c,C]of f){const O=1/(6*c);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(C),t.beginPath(),t.moveTo(v(-.5),b(0)),t.lineTo(v(0),b(O)),t.lineTo(v(.5),b(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${c}`,v(0)+4,b(O)-2)}t.restore(),se=[];const p=e.points.filter(c=>I.size===0||I.has(c.group));for(const c of p)t.beginPath(),t.arc(v(c.x),b(c.y),4,0,Math.PI*2),t.fillStyle=oe(c.group),t.fill(),se.push({p:{x:c.x,y:c.y,group:c.group,item:-1,value:c.testNumber},cx:v(c.x),cy:b(c.y)});const L=p.map(c=>({x0:v(c.x)-5,x1:v(c.x)+5,y0:b(c.y)-5,y1:b(c.y)+5})),M={x0:k,x1:k+a,y0:T,y1:T+u},g=c=>c.x0>=M.x0&&c.x1<=M.x1&&c.y0>=M.y0&&c.y1<=M.y1&&!L.some(C=>c.x0<C.x1&&c.x1>C.x0&&c.y0<C.y1&&c.y1>C.y0),y=te(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const c of[...p].filter(C=>C.ppk<1.33).sort((C,O)=>C.ppk-O.ppk)){const C=v(c.x),O=b(c.y),_=t.measureText(c.label).width,P=[[C+7,O,"left"],[C-7,O,"right"],[C,O-13,"center"],[C,O+13,"center"]];for(const[E,A,j]of P){const x=j==="left"?E:j==="right"?E-_:E-_/2,be={x0:x,x1:x+_,y0:A-y/2,y1:A+y/2};if(g(be)){L.push(be),t.textAlign=j,t.fillText(c.label,E,A);break}}}const d=pe?se.find(c=>c.p===pe):void 0;d&&(t.beginPath(),t.arc(d.cx,d.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Tn(e){const l=i,r=l.marks.points.find(a=>a.testNumber===e.value&&a.group===e.group);return r?`<strong>${D(r.label)}</strong>${l.groups.length>1?` \xB7 ${D(qe(r.group))}`:""}<br>`+D(`Ppk ${r.ppk.toFixed(2)} \xB7 ${r.n.toLocaleString("en-GB")} dies`)+"<br>"+D(`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 wn(e,l,s,r,a){!$e||!$||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${$.offsetTop+T}px`,height:`${a}px`,left:`${$.offsetLeft+k+r+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-s)>=1&&($e.scrollTop=s)))}function K(){$e&&($e.style.display="none"),ut&&!ln()&&(ut.style.maxHeight=Zt(B)?"":`${no}px`),Q&&m.panel&&(Q.style.display=Zt(B)?"flex":"none"),k=Ct,T=Bt;const e=i?.marks?.type;e==="scatter"?rn():e==="control"?vn():e==="heatmap"?bn():e==="goal"?kn():e==="probability"?gn():e==="histogram"?fn():e==="box"||e==="bar"?un():e==="line"&&pn(),Ot()}function Sn(e){const l=i,s=m.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}: ${J(t,n.unit)}`;return(a?`<strong>${D(a)}</strong><br>`:"")+D(u(l.x,e.x))+"<br>"+D(u(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(qe(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${D(m.openActionLabel??"open this wafer")}</em>`:"")}function Rt(e){if(!Ee||!Z||!i?.x)return null;const l=$.getBoundingClientRect(),r=(e.clientX-l.left-k)/Z.plotW;if(r<0||r>1)return null;const a=Z.x.reverse?1-r:r,{edges:u,counts:n}=Ee,t=u.length-1,o=Math.min(t-1,Math.max(0,Math.floor(a*t)));ge=o;const h=i.x,w=n.map((v,b)=>({g:b,n:v[o]})).filter(v=>v.n>0&&(I.size===0||I.has(v.g)));return`<strong>${D(`${J(u[o],h.unit)} to ${J(u[o+1],h.unit)}`)}</strong><br>`+(w.length?w.map(v=>{const b=i.spec.histNorm==="percent"?` (${Ee.heights[v.g][o].toFixed(1)}% of ${i.groups.length>1?"its colour":"them"})`:"";return D(`${i.groups.length>1?`${qe(v.g)}: `:""}${v.n.toLocaleString("en-GB")} ${i.level==="die"?"dies":"wafers"}${b}`)}).join("<br>"):"none")}function $n(e){const l=R.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:me.md,marginTop:me.md,marginBottom:me.xl,fontSize:mt.body,color:et.label});const s=R.createElement("canvas");s.width=200,s.height=10,Object.assign(s.style,{width:"200px",height:"10px",borderRadius:Nn.control,flex:"0 0 auto"});const r=s.getContext("2d"),a=gt();if(r)for(let h=0;h<200;h++)r.fillStyle=a(h/199),r.fillRect(h,0,1,10);const u=h=>i?.marks?.type==="heatmap"?Wt(h,e.unit,e.integer):J(h,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=et.text,l.append(o,n,s,t),l}const ot=(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 Pn(){Ke?.destroy(),Ke=void 0,W.innerHTML="",$=void 0,Q=void 0,ee=void 0,tt=[],pe=null,ge=-1,se=[],Z=void 0,ne=void 0,ie=null,$e=void 0,nt=0,ut=void 0,Re=void 0,ye=null,de=[],ke=-1,Ue=De,xt=new Map,I.clear(),he.clear();for(const n of ce)n.destroy();ce=[],ct?.(),ct=void 0,W.style.overflowY="",delete B.dataset.wmapPlotPanelsOwner,delete B.dataset.wmapPanelsHover,we(()=>B.querySelector("canvas"));const e=i,l=!!e?.facets&&!m.panel;if(B.style.flex=l?"0 0 auto":"1 1 0px",B.style.gridColumn=l?"1 / -1":"",!e)return;if(U.textContent=m.panel?m.panel.title:On(e),B.dataset.wmapChartTitle=U.textContent,e.issues.length||!e.marks){for(const n of e.issues)Vt(W,n);return}const s=R.createElement("div");Object.assign(s.style,{color:et.label,fontSize:mt.body,marginBottom:me.xs});const r=m.openActionLabel??"open this wafer",a=e.marks.type==="scatter"?(m.onOpenWafer?` \xB7 click a point to ${r}`:"")+(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 ${r}`: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 ${r}`:"")+(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"}`:"";s.textContent=m.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:qt(e)+(e.facets?"":a),m.panel||Rn(s,Yt(e)),Ht(s),ee=R.createElement("div"),ee.style.display="flow-root",W.appendChild(ee),ee.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:et.text,fontSize:mt.body,marginBottom:me.xxs,fontVariantNumeric:"tabular-nums"}),ee.appendChild(t)}for(const n of e.notes){const t=R.createElement("div");Ht(t),t.textContent=n,Object.assign(t.style,{color:et.warnText,fontSize:mt.body,marginBottom:me.xs}),ee.appendChild(t)}if(e.plotted===0){Vt(W,"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:m.panel?"none":"flex",flexWrap:"wrap",gap:me.sm,marginTop:me.md,marginBottom:me.xl,overflowY:"auto"}),ut=Q,e.facets&&Object.assign(Q.style,{position:"sticky",top:"0",zIndex:"2",background:et.menuBg,paddingBottom:me.sm,marginBottom:me.md}),e.groups.forEach((n,t)=>{const o=Un(n||"(none)",oe(t),R);Xn(o.el,B,z,`${n||"(none)"} \u2014 click to filter`),o.el.addEventListener("click",()=>{if(I.has(t)?I.delete(t):I.add(t),tt.forEach((h,w)=>h.setState({selected:I.has(w),dimmed:I.size>0&&!I.has(w)})),ce.length)for(const h of ce)h.setActiveGroups(I);else K()}),tt.push(o),Q.appendChild(o.el)}),tt.forEach((n,t)=>n.setState({selected:I.has(t),dimmed:I.size>0&&!I.has(t)})),ee.appendChild(Q)),e.colorScale&&!m.panel&&(Q=$n(e.colorScale),ee.appendChild(Q)),e.facets){const n=R.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(${io}px, 1fr))`};t();const o=qn("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(v=>({value:String(v),label:`${v} (${v})`}))],Ie?String(Ie):"auto",v=>{Ie=v==="auto"?void 0:Number(v),t()},{hook:"panel-columns",maxWidth:"90px",ownerDocument:R});Object.assign(o.style,{justifyContent:"flex-end",marginBottom:me.sm});const h=o.querySelector("button");W.append(o,n),W.style.overflowY="auto",B.dataset.wmapPlotPanelsOwner="1",ft&&(B.dataset.wmapPanelsHover="1");const w=v=>{if(!ft||v.ctrlKey||v.metaKey||v.altKey||v.shiftKey||v.defaultPrevented||!/^[0-5]$/.test(v.key))return;const b=v.target;typeof b?.closest=="function"&&b.closest('input, textarea, select, [contenteditable="true"], [role="menu"]')||(v.preventDefault(),Ie=v.key==="0"?void 0:Number(v.key),t(),h&&(h.value=Ie?String(Ie):"auto"))};R.addEventListener("keydown",w),ct=()=>R.removeEventListener("keydown",w);for(const v of e.facets){const b=renderPlotChart({...m,panel:{title:v.label}});n.appendChild(b.card),b.setPlot(v.plot),ce.push(b)}we(()=>ao(n));return}$=R.createElement("canvas"),$.style.display="block",$.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",W.appendChild($);const u=m.onWaferMenu?(n,t)=>{n.die||m.onWaferMenu(n.item,He(e.spec),t)}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!m.onSelectPoints;Ke=Et({card:B,canvas:$,tooltip:z,drawn:()=>se,describe:Sn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,He(e.spec)),onContextMenu:u,onHover:o=>{pe=o,K()},select:t?{pick:({x0:o,y0:h,x1:w,y1:v})=>Z?(I.size===0?n.points:n.points.filter(f=>I.has(f.group))).filter(f=>{const p=k+Z.x.frac(f.x)*Z.plotW,L=T+(1-Z.y.frac(f.y))*Z.plotH;return p>=o&&p<=w&&L>=h&&L<=v}):[],onPicked:(o,h)=>{he.clear();for(const w of o)he.add(w);K(),o.length>0&&m.onSelectPoints(o,h,$)},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";Ke=Et({card:B,canvas:$,tooltip:z,drawn:()=>se,describe:n?Mn:Tn,clickable:()=>n&&!!m.onOpenWafer,onOpen:t=>{n&&m.onOpenWafer?.(t.item,He(e.spec))},onContextMenu:n?u:void 0,onHover:t=>{pe=t,K()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";Ke=Et({card:B,canvas:$,tooltip:z,drawn:()=>se,describe:yn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,He(e.spec)),onContextMenu:u,onHover:o=>{pe=o,K()},select:m.onSelectPoints?{pick:({x0:o,y0:h,x1:w,y1:v})=>{if(!Z)return[];const b=[];return n.values.forEach((f,p)=>{I.size>0&&!I.has(p)||f.forEach((L,M)=>{const g=at(M,f.length),y=k+Z.x.frac(L)*Z.plotW,d=T+(1-Z.y.frac(t?g:jt(g)))*Z.plotH;if(y<o||y>w||d<h||d>v)return;const{item:c,die:C}=n.unit(n.units[p][M]);b.push({x:L,y:g,group:p,item:c,die:C})})}),b},onPicked:(o,h)=>{he.clear();for(const w of o)he.add(w);K(),o.length>0&&m.onSelectPoints(o,h,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="histogram"){cn(),$.addEventListener("mousemove",t=>{const o=Rt(t);if(!o){z.style.display="none",ge>=0&&(ge=-1,K());return}z.innerHTML=o,z.style.display="block",pt(z,B,t.clientX,t.clientY),K()}),$.addEventListener("mouseleave",()=>{z.style.display="none",ge>=0&&(ge=-1,K())});const n=e.marks;m.onSelectPoints&&($.style.cursor="pointer",$.addEventListener("click",t=>{if(!Ee||Rt(t)===null)return;const o=ge,{edges:h}=Ee,w=Z?.x.log,v=w?Math.log10(h[0]):h[0],b=w?Math.log10(h[h.length-1]):h[h.length-1],f=h.length-1,p=[];n.values.forEach((L,M)=>{if(I.size>0&&!I.has(M))return;const g=[];L.forEach((y,d)=>{const c=w?y>0?Math.log10(y):NaN:y;!Number.isFinite(c)||c<v||c>b||Math.min(f-1,Math.floor((c-v)/(b-v)*f))===o&&g.push(n.units[M][d])});for(const y of ot(n.unit,g,M))p.push(y)}),p.length>0&&(z.style.display="none",m.onSelectPoints(p,{x:t.clientX,y:t.clientY},$,{range:{lo:h[o],hi:h[o+1]},...I.size===1?{group:e.groups[[...I][0]]}:{}}))}))}else if(e.marks.type==="heatmap"){const n=e.marks;$.addEventListener("mousemove",t=>{const o=Ft(t);if($.style.cursor=o&&m.onSelectPoints&&n.cellUnits[o.r][o.c].length?"pointer":"default",!o){z.style.display="none",ye&&(ye=null,K());return}z.innerHTML=xn(o),z.style.display="block",pt(z,B,t.clientX,t.clientY),(!ye||ye.r!==o.r||ye.c!==o.c)&&(ye=o,K())}),$.addEventListener("mouseleave",()=>{z.style.display="none",ye&&(ye=null,K())}),$.addEventListener("click",t=>{const o=Ft(t);if(!o||!m.onSelectPoints)return;const h=n.cellUnits[o.r][o.c];h.length&&(z.style.display="none",m.onSelectPoints(ot(n.unit,h,0),{x:t.clientX,y:t.clientY},$))})}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-nt)<1||(nt=t.scrollTop,z.style.display="none",K())}),$.addEventListener("wheel",h=>{if(t.style.display==="none")return;const w=t.scrollTop;t.scrollTop+=h.deltaMode===1?h.deltaY*16:h.deltaY,t.scrollTop!==w&&h.preventDefault()},{passive:!1}),W.appendChild(t),$e=t}$.addEventListener("mousemove",t=>{const o=wt(t);if($.style.cursor=o&&(n.categoryItems&&m.onOpenWafer||m.onSelectPoints&&n.cellUnits[o.g][o.c].length>0)?"pointer":"default",!o){z.style.display="none",ie&&(ie=null,K());return}z.innerHTML=mn(o),z.style.display="block",pt(z,B,t.clientX,t.clientY),(!ie||ie.g!==o.g||ie.c!==o.c)&&(ie=o,K())}),$.addEventListener("mouseleave",()=>{z.style.display="none",ie&&(ie=null,K())}),m.onWaferMenu&&n.categoryItems&&$.addEventListener("contextmenu",t=>{const o=wt(t),h=o?n.categoryItems[o.c]:void 0;h===void 0||h<0||(z.style.display="none",m.onWaferMenu(h,He(e.spec),t))}),$.addEventListener("click",t=>{const o=wt(t);if(!o)return;const h=n.categoryItems?.[o.c];if(h!==void 0&&h>=0&&m.onOpenWafer){m.onOpenWafer(h,He(e.spec));return}const w=n.cellUnits[o.g][o.c];w.length>0&&m.onSelectPoints&&(z.style.display="none",m.onSelectPoints(ot(n.unit,w,o.g),{x:t.clientX,y:t.clientY},$,{category:n.categories[o.c],...e.groups.length>1?{group:e.groups[o.g]}:{},...hn(n.categories[o.c])}))})}else if(e.marks.type==="line"){$.addEventListener("mousemove",t=>{const o=St(t);if(!o){z.style.display="none",K();return}z.innerHTML=o,z.style.display="block",pt(z,B,t.clientX,t.clientY),K()}),$.addEventListener("mouseleave",()=>{z.style.display="none",ke>=0&&(ke=-1,K())});const n=e.marks;if(m.onWaferMenu&&$.addEventListener("contextmenu",t=>{const o=St(t)===null?void 0:Nt(ke);o!==void 0&&(z.style.display="none",m.onWaferMenu(o,He(e.spec),t))}),m.onSelectPoints){$.style.cursor="pointer";let t=!1;$.addEventListener("mousedown",o=>{if(o.button!==0)return;t=!1;const h=$.getBoundingClientRect(),w=o.clientX-h.left,v=b=>{R.removeEventListener("mouseup",v);const f=b.clientX-h.left;if(Math.abs(f-w)<4)return;t=!0;const[p,L]=w<f?[w,f]:[f,w],M=de.map((y,d)=>y>=p&&y<=L?d:-1).filter(y=>y>=0),g=n.cellUnits.flatMap((y,d)=>I.size>0&&!I.has(d)?[]:M.flatMap(c=>ot(n.unit,y[c]??[],d)));g.length>0&&(z.style.display="none",m.onSelectPoints(g,{x:b.clientX,y:b.clientY},$))};R.addEventListener("mouseup",v)}),$.addEventListener("click",o=>{if(t){t=!1;return}if(St(o)===null||ke<0)return;const h=n.cellUnits.flatMap((w,v)=>I.size>0&&!I.has(v)?[]:ot(n.unit,w[ke]??[],v));h.length>0&&(z.style.display="none",m.onSelectPoints(h,{x:o.clientX,y:o.clientY},$))})}}K()}V(()=>{const e=i;if(!e||!e.marks)return;const l=gt();return{caption:[qt(e),...e.fitNotes??[],...e.notes,...Qn(Yt(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:J(e.colorScale.lo,e.colorScale.unit),hi:J(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const Ln=zn(B,()=>K());return{card:B,actions:q,setPlot(e){i=e,Me(eo(e.spec)),Pn()},setMenuRows:Se,setActiveGroups(e){I.clear();for(const l of e)I.add(l);tt.forEach((l,s)=>l.setState({selected:I.has(s),dimmed:I.size>0&&!I.has(s)})),K()},destroy(){ct?.(),Ln.disconnect(),Ke?.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()}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isYieldEligibleDie as W}from"../core/dies.js";import{testValue as A}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as H}from"../stats/facets.js";import{tableToTsv as V}from"../core/tableCsv.js";import{commonMetadata as Y}from"../stats/facets.js";import{buildYieldData as G}from"../stats/yield.js";import{isParametricTest as k}from"../renderer/buildWaferMap.js";import{fmt as U}from"../renderer/fmt.js";import{testLabel as $}from"../renderer/testLabel.js";import{resolveDieColumns as K}from"./dieList.js";import{createVirtualTable as N}from"./virtualTable.js";import{exportCsv as O}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as R,SPACE as C,controlStyle as q,wireControlHover as j,wireTooltip as S}from"./toolbar.js";import{buildTestSection as X,buildFunctionalTestSection as J}from"./summaryPanel.js";import{patTests as Q,waferPatVerdicts as Z,PAT_VERDICT_LABEL as ee}from"../stats/pat.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,l,o=l+"s")=>`${e.toLocaleString()} ${e===1?l:o}`;export function renderDataSection(e){const{doc:l}=e,o=l.createElement("div");o.dataset.wmapDataTab="1",Object.assign(o.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=l.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),o.appendChild(c);const p=l.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),o.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),s=P(l,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(s.el);let r;switch(e.view){case"dies":r=oe(e);break;case"wafers":r=se(e);break;default:r=te(e)}let u=()=>{};if(e.view==="dies"){const f=P(l,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),r.actions?.setLayout?.(t),u()});S(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const d=l.createElement("span");Object.assign(d.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const i=l.createElement("span");i.textContent="Export format:",Object.assign(i.style,{color:y.label,fontSize:L.body}),d.append(i,f.el),c.appendChild(d)}if(r.actions){const f=r.actions,d=l.createElement("div");d.style.flex="1",c.appendChild(d);const i=M(l,"Export CSV");i.dataset.wmapDataExport="1",i.addEventListener("click",()=>{if(i.disabled)return;const m=i.textContent,h=f.exportCsv();h&&(i.disabled=!0,i.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{i.disabled=!1,i.removeAttribute("aria-busy"),i.textContent=m}))});const t=M(l,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(S(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=l.defaultView?.navigator?.clipboard;if(!h)return;const v=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",l.defaultView?.setTimeout(()=>{t.textContent=v},1500)}).catch(()=>{})})):(t.disabled=!0,S(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,i);const a=l.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),o.insertBefore(a,p)}return p.appendChild(r.el),{card:o,destroy:()=>r.destroy()}}function te(e){const{doc:l}=e,o=l.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const s of g){if(p){const u=l.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${s.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),o.appendChild(u)}const r=e.buildStatistics(s.items);c.push(r.destroy);for(const u of r.cards)o.appendChild(u)}return!o.querySelector("table")&&!o.textContent&&(o.textContent="No test statistics to show for these wafers.",Object.assign(o.style,{color:y.label,fontSize:L.body})),{el:o,destroy:()=>{for(const s of c)s()}}}function ne(e,l,o){if(Q(l).length===0)return;const c=new Map;for(const s of e){const r=s.allDies??(o?void 0:s.dies);if(!r)continue;const u=Z(r,l,s.passBins);r.forEach((f,d)=>c.set(f,u[d]))}if(c.size===0)return;const p=s=>{const r=l.find(u=>u.testNumber===s);return r?$(r,s):`Test ${s}`};let g=!1;for(const s of c.values())if(s.verdict==="outlier"){g=!0;break}return{verdict:s=>{const r=c.get(s)?.verdict;return r?ee[r]:void 0},tests:s=>{const r=c.get(s);return r?.verdict==="outlier"?r.tests.map(p).join("; "):""},anyOutlier:g}}function oe(e){const{doc:l,items:o}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,s=[];let r=!1;for(const n of o){n.wafer&&(r=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),s.push(b)}if(s.length===0)return B(l,"No dies to show.");const u=ne(o,e.allTestDefs,!!e.population),{columns:f,visibleColumns:d}=K(s,e.allTestDefs,{...e.dieListOptions,...u?{patColumns:u}:{},metadataFields:e.metadataFields,extraColumn:o.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:r?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:o.some(n=>n.wafer)?Y(o.map(n=>({metadata:n.wafer?.metadata}))):void 0,attributes:e.attributes,ownerDocument:l}),i=d.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&k(n.test),...n.test!==void 0&&k(n.test)?{sortKey:b=>A(b,n.test.testNumber)}:{}})),t=N({columns:i,rows:s,ariaLabel:`Dies (${s.length})`,ownerDocument:l,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});t.el.style.maxHeight="70vh",t.el.style.minHeight="240px";const a=e.population?`-${e.population.fileTag}`:"",m=f.filter(n=>n.test!==void 0),h=f.filter(n=>n.test===void 0),v=s.length*f.length,w=s.length*m.length,x=()=>f.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),_=()=>[...h.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>$(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*F(){for(const n of t.orderedRows())for(const b of m){const T=(b.csvGet??b.get)(n);T===""||T===void 0||T===null||(yield{die:n,test:b.test,value:T})}}let E=e.diesLayout==="long"&&m.length>0;const z=()=>E?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(s.length,"row")} \xD7 ${D(f.length,"column")}`+(s.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:t.el,destroy:()=>t.destroy(),actions:{note:()=>`${D(s.length,"die")} ${e.population?.phrase??`on ${D(o.length,"wafer")}`}. ${z()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{E=n==="long"&&m.length>0},exportCsv:()=>E?O(_(),F(),`die-list-long${a}.csv`,e.onSaveText,{rowCount:w}):O(x(),t.orderedRows(),`die-list${a}.csv`,e.onSaveText,{rowCount:s.length}),copyText:v<=COPY_CELL_LIMIT?()=>V(x(),t.orderedRows()):null}}}function se(e){const{doc:l,items:o}=e;if(o.length===0)return B(l,"No wafers to show.");const c=o.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=G([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),s=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(w=>w.testNumber===a.testNumber);if(m)return m.mean;let h=0,v=0;for(const w of t.item.dies){if(!W(w))continue;const x=A(w,a.testNumber);x!==void 0&&Number.isFinite(x)&&(h++,v+=x)}return h?v/h:void 0},r=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:H(t,e.attributes),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>W(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${$(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>s(a,t),show:a=>{const m=s(a,t);return m===void 0?"":U(m,t.unit)},numeric:!0}))],u=r.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=N({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:l,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const d=()=>r.map(t=>({header:t.header,get:t.cell})),i=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${i}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>O(d(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*r.length<=COPY_CELL_LIMIT?()=>V(d(),f.orderedRows()):null}}}function B(e,l){const o=e.createElement("div");return o.textContent=l,Object.assign(o.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:o,destroy:()=>{}}}function M(e,l){const o=e.createElement("button");return o.type="button",o.textContent=l,Object.assign(o.style,{fontSize:L.body,padding:"3px 10px",borderRadius:R.control,...q("outlined"),background:y.menuBg}),j(o),o}function P(e,l,o,c,p,g){const s=e.createElement("div");s.setAttribute("role","radiogroup"),s.setAttribute("aria-label",l),Object.assign(s.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:R.control,overflow:"hidden"});const r=[];let u=c;const f=()=>{for(const d of r){const i=d.dataset[p]===u;d.setAttribute("aria-checked",String(i)),d.tabIndex=i?0:-1,Object.assign(d.style,{background:i?y.bgActive:"transparent",color:i?y.iconActive:y.label,fontWeight:i?"600":"400"})}};for(const d of o){const i=e.createElement("button");d.hint&&S(i,d.hint),i.type="button",i.textContent=d.label,i.dataset[p]=d.key,i.setAttribute("role","radio"),Object.assign(i.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(i,"bare"),i.addEventListener("click",()=>{u!==d.key&&g(d.key)}),r.push(i),s.appendChild(i)}return f(),s.addEventListener("keydown",d=>{if(d.key!=="ArrowLeft"&&d.key!=="ArrowRight")return;const i=r.indexOf(e.activeElement);if(i<0)return;d.preventDefault();const t=r[(i+(d.key==="ArrowRight"?1:-1)+r.length)%r.length];t.click(),t.focus()}),{el:s,set:d=>{u=d,f()}}}export function renderDataTables(e){const{doc:l}=e,o=l.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],s=g.filter(k),r=e.views??(c.length>1?["statistics","wafers","dies"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=r.includes(e.view)?e.view:r[0],d="wide",i=null;const t=()=>{i?.destroy(),i=renderDataSection({doc:l,items:c,testDefs:s,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:r,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,attributes:e.attributes,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(x=>x.dies),h=[],v=X(m,s,void 0,void 0,e.onSaveText,u,a.map(x=>({dies:x.dies})),void 0,"full");v&&h.push(v);const w=J(m,g,void 0,e.onSaveText,u);return w&&h.push(w),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:d,onDiesLayoutChange:a=>{d=a}}),o.replaceChildren(i.card)};return t(),{el:o,destroy:()=>i?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
|
|
1
|
+
import{maxOf as J}from"../core/utils.js";import{isYieldEligibleDie as z}from"../core/dies.js";import{testValue as B}from"../core/dieTable.js";import{metadataDisplayValue as _}from"../core/metadata.js";import{attributeLabel as F}from"../stats/facets.js";import{tableToTsv as H}from"../core/tableCsv.js";import{commonMetadata as Z}from"../stats/facets.js";import{buildYieldData as ee}from"../stats/yield.js";import{isParametricTest as j}from"../renderer/buildWaferMap.js";import{fmt as I}from"../renderer/fmt.js";import{testLabel as M}from"../renderer/testLabel.js";import{resolveDieColumns as te}from"./dieList.js";import{createVirtualTable as P}from"./virtualTable.js";import{exportCsv as A}from"./tableExport.js";import{CLR as S,FONT as k,RADIUS as q,SPACE as T,controlStyle as ne,wireControlHover as G,wireTooltip as V}from"./toolbar.js";import{buildTestSection as oe,buildFunctionalTestSection as se}from"./summaryPanel.js";import{pooledTestStatsSteps as ie}from"../stats/capability.js";import{runChunked as ae}from"./chunked.js";import{capabilityShade as re,outOfLimitsShade as le,shadesAmong as K,shortfallShade as U}from"./cellShade.js";import{patTests as de,waferPatVerdicts as ce,PAT_VERDICT_LABEL as ue}from"../stats/pat.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const O=(t,d,s=d+"s")=>`${t.toLocaleString()} ${t===1?d:s}`;export function renderDataSection(t){const{doc:d}=t,s=d.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:T.md,minWidth:"0"});const a=d.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",gap:T.md,flexWrap:"wrap"}),s.appendChild(a);const h=d.createElement("div");Object.assign(h.style,{display:"flex",flexDirection:"column",gap:T.md,minWidth:"0"}),s.appendChild(h);const y=DATA_VIEWS.filter(f=>!t.views||t.views.includes(f.key)),o=X(d,"Table",y,t.view,"wmapDataView",f=>t.onViewChange(f));a.appendChild(o.el);let r;switch(t.view){case"dies":r=pe(t);break;case"wafers":r=ge(t);break;default:r=fe(t)}let p=()=>{};if(t.view==="dies"){const f=X(d,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],t.diesLayout,"wmapDataLayout",u=>{f.set(u),t.onDiesLayoutChange(u),r.actions?.setLayout?.(u),p()});V(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const c=d.createElement("span");Object.assign(c.style,{display:"inline-flex",alignItems:"center",gap:T.sm});const l=d.createElement("span");l.textContent="Export format:",Object.assign(l.style,{color:S.label,fontSize:k.body}),c.append(l,f.el),a.appendChild(c)}if(r.actions){const f=r.actions,c=d.createElement("div");c.style.flex="1",a.appendChild(c);const l=Y(d,"Export CSV");l.dataset.wmapDataExport="1",l.addEventListener("click",()=>{if(l.disabled)return;const w=l.textContent,b=f.exportCsv();b&&(l.disabled=!0,l.setAttribute("aria-busy","true"),b.catch(()=>{}).finally(()=>{l.disabled=!1,l.removeAttribute("aria-busy"),l.textContent=w}))});const u=Y(d,"Copy");u.dataset.wmapDataCopy="1",f.copyText?(V(u,"Copy the table as tab-separated text, to paste into a spreadsheet"),u.addEventListener("click",()=>{const w=f.copyText(),b=d.defaultView?.navigator?.clipboard;if(!b)return;const x=u.textContent;b.writeText(w).then(()=>{u.textContent="Copied",d.defaultView?.setTimeout(()=>{u.textContent=x},1500)}).catch(()=>{})})):(u.disabled=!0,V(u,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),a.append(u,l);const g=d.createElement("div");g.dataset.wmapDataNote="1",g.textContent=f.note(),p=()=>{g.textContent=f.note()},Object.assign(g.style,{color:S.label,fontSize:k.body}),s.insertBefore(g,h)}return h.appendChild(r.el),{card:s,destroy:()=>r.destroy()}}function fe(t){const{doc:d}=t,s=d.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"});const a=[],h=t.groups&&t.groups.length>0?t.groups:void 0,y=h??[{key:"",items:t.items}];if(h&&h.length>1){const o=me(t,h);o&&(s.appendChild(o.el),a.push(o.destroy))}for(const o of y){if(h){const p=d.createElement("div");p.textContent=`${t.groupLabelText??"Group"}: ${o.key}`,Object.assign(p.style,{fontWeight:"700",color:S.text,fontSize:k.body}),s.appendChild(p)}const r=t.buildStatistics(o.items);a.push(r.destroy);for(const p of r.cards)s.appendChild(p)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:S.label,fontSize:k.body})),{el:s,destroy:()=>{for(const o of a)o()}}}function me(t,d){const{doc:s}=t,a=t.testDefs.filter(b=>b.testNumber!==void 0&&j(b));if(a.length===0)return null;const h=t.groupLabelText??"Group",y=s.createElement("div");y.dataset.wmapGroupStats="1",Object.assign(y.style,{display:"flex",flexDirection:"column",gap:T.sm,minWidth:"0"});const o=s.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:T.md,flexWrap:"wrap"});const r=s.createElement("div");r.textContent=`Compared across ${h}`,Object.assign(r.style,{fontWeight:"700",color:S.text,fontSize:k.body}),o.appendChild(r);const p=s.createElement("div");p.textContent="Computing test statistics\u2026",Object.assign(p.style,{color:S.label,fontSize:k.body}),y.append(o,p);const f=new Map;let c=d.length,l,u=!1;const g=()=>{if(u)return;const b=[];for(const e of a)for(const n of d){const m=f.get(n.key),i=m?.stats.get(e.testNumber);if(!m||!i)continue;const C=m.specTally.get(e.testNumber);b.push({def:e,group:n.key,count:i.count,min:i.min,q1:i.q1,median:i.median,mean:i.mean,q3:i.q3,max:i.max,stddev:i.stddev,ppk:m.capability.find(W=>W.testNumber===e.testNumber)?.ppk??null,limitYield:C&&C.n>0?100*(1-C.fail/C.n):void 0})}if(b.length===0){y.remove();return}const x=new Map;for(const e of b){const n=x.get(e.def.testNumber);n?n.push(e):x.set(e.def.testNumber,[e])}for(const e of x.values()){const n=K(e.map(i=>i.mean),i=>I(i,e[0].def.unit)),m=J(e.map(i=>i.limitYield??-1/0));e.forEach((i,C)=>{i.meanShade=n[C],i.yieldShade=i.limitYield===void 0||!Number.isFinite(m)?void 0:U(i.limitYield-m)})}const v=e=>({get:n=>I(e(n),n.def.unit),numeric:!0,sortKey:e}),L=(e,n)=>({get:m=>{const i=e(m);return i===void 0||!Number.isFinite(i)?"":n(i)},numeric:!0,sortKey:m=>{const i=e(m);return i===void 0||!Number.isFinite(i)?void 0:i}}),D=[{header:"Test",get:e=>`${M(e.def,e.def.testNumber)}${e.def.unit?` (${e.def.unit})`:""}`},{header:h,get:e=>e.group},{header:"N",...L(e=>e.count,e=>String(e))},{header:"Min",...v(e=>e.min)},{header:"Q1",...v(e=>e.q1)},{header:"Median",...v(e=>e.median)},{header:"Mean",...v(e=>e.mean),shade:e=>e.meanShade},{header:"Q3",...v(e=>e.q3)},{header:"Max",...v(e=>e.max)},{header:"Std dev",...v(e=>e.stddev)},{header:"Ppk",...L(e=>e.ppk??void 0,e=>e.toFixed(2)),shade:e=>re(e.ppk)},{header:"Limit yield %",...L(e=>e.limitYield,e=>e.toFixed(1)),shade:e=>e.yieldShade}],E=P({columns:D,rows:b,ariaLabel:`Statistics by ${h} (${b.length})`,ownerDocument:s});E.el.style.maxHeight="50vh",E.el.style.minHeight="120px",l=E;const N=()=>[{header:"Test number",get:e=>e.def.testNumber??null},{header:"Test",get:e=>M(e.def,e.def.testNumber)},{header:"Unit",get:e=>e.def.unit??""},{header:h,get:e=>e.group},{header:"N",get:e=>e.count},{header:"Min",get:e=>e.min},{header:"Q1",get:e=>e.q1},{header:"Median",get:e=>e.median},{header:"Mean",get:e=>e.mean},{header:"Q3",get:e=>e.q3},{header:"Max",get:e=>e.max},{header:"Std dev",get:e=>e.stddev},{header:"Ppk",get:e=>e.ppk},{header:"Limit yield %",get:e=>e.limitYield??null}],$=Y(s,"Statistics CSV");$.dataset.wmapGroupStatsCsv="1",$.addEventListener("click",()=>{A(N(),E.orderedRows(),`statistics-by-${h.toLowerCase().replace(/[^a-z0-9]+/g,"-")}.csv`,t.onSaveText,{rowCount:b.length})}),o.appendChild($),p.replaceWith(E.el)},w=[];for(const b of d)w.push(ae(ie(b.items.map(x=>({dies:x.dies})),a),{onDone:x=>{f.set(b.key,x),--c===0&&g()}}));return{el:y,destroy:()=>{u=!0;for(const b of w)b.cancel();l?.destroy()}}}function he(t,d,s){if(de(d).length===0)return;const a=new Map;for(const o of t){const r=o.allDies??(s?void 0:o.dies);if(!r)continue;const p=ce(r,d,o.passBins);r.forEach((f,c)=>a.set(f,p[c]))}if(a.size===0)return;const h=o=>{const r=d.find(p=>p.testNumber===o);return r?M(r,o):`Test ${o}`};let y=!1;for(const o of a.values())if(o.verdict==="outlier"){y=!0;break}return{verdict:o=>{const r=a.get(o)?.verdict;return r?ue[r]:void 0},tests:o=>{const r=a.get(o);return r?.verdict==="outlier"?r.tests.map(h).join("; "):""},anyOutlier:y}}function pe(t){const{doc:d,items:s}=t,a=new WeakMap,h=new WeakMap,y=new WeakMap,o=[];let r=!1;for(const e of s){e.wafer&&(r=!0);for(const n of e.dies)a.set(n,e.label),y.set(n,e.waferIndex),e.wafer&&h.set(n,e.wafer),o.push(n)}if(o.length===0)return Q(d,"No dies to show.");const p=he(s,t.allTestDefs,!!t.population),{columns:f,visibleColumns:c}=te(o,t.allTestDefs,{...t.dieListOptions,...p?{patColumns:p}:{},metadataFields:t.metadataFields,extraColumn:s.length>1||t.population?{label:"Wafer",get:e=>a.get(e)}:void 0,getWafer:r?(e=>h.get(e)):void 0,ringCount:t.ringCount,waferMetadata:s.some(e=>e.wafer)?Z(s.map(e=>({metadata:e.wafer?.metadata}))):void 0,attributes:t.attributes,ownerDocument:d}),l=c.map(e=>({header:e.label,get:e.get,numeric:e.test!==void 0&&j(e.test),...e.test!==void 0&&j(e.test)?{sortKey:n=>B(n,e.test.testNumber),shade:n=>{const m=e.test,i=B(n,m.testNumber);return i!==void 0&&Number.isFinite(i)&&(m.limitLow!==void 0&&i<m.limitLow||m.limitHigh!==void 0&&i>m.limitHigh)?le():void 0}}:{}})),u=P({columns:l,rows:o,ariaLabel:`Dies (${o.length})`,ownerDocument:d,onRowClick:t.onLocateDie?e=>t.onLocateDie(e,y.get(e)):void 0});u.el.style.maxHeight="70vh",u.el.style.minHeight="240px";const g=t.population?`-${t.population.fileTag}`:"",w=f.filter(e=>e.test!==void 0),b=f.filter(e=>e.test===void 0),x=o.length*f.length,v=o.length*w.length,L=()=>f.map(e=>({header:e.csvLabel??e.label,get:e.csvGet??e.get})),D=()=>[...b.map(e=>({header:e.csvLabel??e.label,get:n=>(e.csvGet??e.get)(n.die)})),{header:"Test",get:e=>M(e.test,e.test.testNumber)},{header:"Test number",get:e=>e.test.testNumber},{header:"Unit",get:e=>e.test.unit??""},{header:"Value",get:e=>e.value}];function*E(){for(const e of u.orderedRows())for(const n of w){const m=(n.csvGet??n.get)(e);m===""||m===void 0||m===null||(yield{die:e,test:n.test,value:m})}}let N=t.diesLayout==="long"&&w.length>0;const $=()=>N?`Long format: up to ${O(v,"row")} (a die with no result for a test has no row)`+(v>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${O(o.length,"row")} \xD7 ${O(f.length,"column")}`+(o.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:u.el,destroy:()=>u.destroy(),actions:{note:()=>`${O(o.length,"die")} ${t.population?.phrase??`on ${O(s.length,"wafer")}`}. ${$()} Export follows the order shown.${t.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:e=>{N=e==="long"&&w.length>0},exportCsv:()=>N?A(D(),E(),`die-list-long${g}.csv`,t.onSaveText,{rowCount:v}):A(L(),u.orderedRows(),`die-list${g}.csv`,t.onSaveText,{rowCount:o.length}),copyText:x<=COPY_CELL_LIMIT?()=>H(L(),u.orderedRows()):null}}}function ge(t){const{doc:d,items:s}=t;if(s.length===0)return Q(d,"No wafers to show.");const a=s.map(e=>{const n=t.yieldByWaferIndex.get(e.waferIndex),m=ee([{label:e.label,dies:e.dies,passBins:e.passBins,yieldPercent:n,key:e.waferIndex}])[0]?.percent;return{item:e,yieldPercent:e.dies.length?m??null:null}}),h=[];for(const{item:e}of a)for(const n of Object.keys(e.wafer?.metadata??{}))!h.includes(n)&&_((e.wafer?.metadata)[n])!==void 0&&h.push(n);const y=t.testDefs.slice(0,WAFER_TEST_COLUMNS),o=(e,n)=>{const m=e.item.statsSummary?.stats.perTestStats?.find(W=>W.testNumber===n.testNumber);if(m)return m.mean;let i=0,C=0;for(const W of e.item.dies){if(!z(W))continue;const R=B(W,n.testNumber);R!==void 0&&Number.isFinite(R)&&(i++,C+=R)}return i?C/i:void 0},r=(e,n)=>_(e.item.wafer?.metadata?.[n])??"",p=e=>({header:F(e,t.attributes),cell:n=>r(n,e)}),f=e=>a.length>1&&a.every(n=>r(n,e)===r(a[0],e)),c=h.filter(f),l=h.filter(e=>!c.includes(e)),u=t.groupLabelText?l.find(e=>F(e,t.attributes)===t.groupLabelText):void 0,g=a.map(e=>e.yieldPercent).filter(e=>e!==null&&Number.isFinite(e)),w=g.length?g.reduce((e,n)=>e+n,0)/g.length:void 0,b=[{header:"Dies",cell:e=>e.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:e=>e.item.dies.filter(n=>z(n)).length,numeric:!0},{header:"Yield %",cell:e=>e.yieldPercent===null?"":e.yieldPercent,show:e=>e.yieldPercent===null?"":e.yieldPercent.toFixed(1),numeric:!0,shade:e=>e.yieldPercent===null||w===void 0?void 0:U(e.yieldPercent-w)},...y.map(e=>{const n=new Map,m=K(a.map(i=>o(i,e)??NaN),i=>I(i,e.unit));return a.forEach((i,C)=>n.set(i,m[C])),{header:`${M(e,e.testNumber)}${e.unit?` (${e.unit})`:""} mean`,cell:i=>o(i,e),show:i=>{const C=o(i,e);return C===void 0?"":I(C,e.unit)},numeric:!0,shade:i=>n.get(i)}})],x=[{header:"Wafer",cell:e=>e.item.label},...u?[p(u)]:[],...b,...l.filter(e=>e!==u).map(p)],v=[...x,...c.map(p)],L=x.map(e=>({header:e.header,get:n=>e.show?e.show(n):String(e.cell(n)??""),numeric:e.numeric,...e.shade?{shade:e.shade}:{},...e.numeric?{sortKey:n=>{const m=e.cell(n);return typeof m=="number"?m:void 0}}:{}})),D=P({columns:L,rows:a,ariaLabel:`Wafers (${a.length})`,ownerDocument:d,onRowClick:t.onOpenWafer?e=>t.onOpenWafer(e.item.waferIndex,e.item.label):void 0});D.el.style.maxHeight="70vh",D.el.style.minHeight="120px";const E=()=>v.map(e=>({header:e.header,get:e.cell})),N=t.testDefs.length>y.length?` Mean columns cover the first ${y.length} of ${t.testDefs.length} tests.`:"";let $=D.el;if(c.length){const e=d.createElement("div");e.dataset.wmapWafersSame="1",e.textContent=`Same on every wafer: ${c.map(n=>`${F(n,t.attributes)} ${r(a[0],n)}`).join(" \xB7 ")}`,Object.assign(e.style,{color:S.label,fontSize:k.body,lineHeight:"1.5",marginBottom:T.sm}),$=d.createElement("div"),$.append(e,D.el)}return{el:$,destroy:()=>D.destroy(),actions:{note:()=>`${O(a.length,"wafer")}.${N}${t.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>A(E(),D.orderedRows(),"wafers.csv",t.onSaveText,{rowCount:a.length}),copyText:a.length*v.length<=COPY_CELL_LIMIT?()=>H(E(),D.orderedRows()):null}}}function Q(t,d){const s=t.createElement("div");return s.textContent=d,Object.assign(s.style,{color:S.label,fontSize:k.body,padding:T.md}),{el:s,destroy:()=>{}}}function Y(t,d){const s=t.createElement("button");return s.type="button",s.textContent=d,Object.assign(s.style,{fontSize:k.body,padding:"3px 10px",borderRadius:q.control,...ne("outlined"),background:S.menuBg}),G(s),s}function X(t,d,s,a,h,y){const o=t.createElement("div");o.setAttribute("role","radiogroup"),o.setAttribute("aria-label",d),Object.assign(o.style,{display:"inline-flex",background:S.menuBg,border:`1px solid ${S.menuBorder}`,borderRadius:q.control,overflow:"hidden"});const r=[];let p=a;const f=()=>{for(const c of r){const l=c.dataset[h]===p;c.setAttribute("aria-checked",String(l)),c.tabIndex=l?0:-1,Object.assign(c.style,{background:l?S.bgActive:"transparent",color:l?S.iconActive:S.label,fontWeight:l?"600":"400"})}};for(const c of s){const l=t.createElement("button");c.hint&&V(l,c.hint),l.type="button",l.textContent=c.label,l.dataset[h]=c.key,l.setAttribute("role","radio"),Object.assign(l.style,{border:"none",cursor:"pointer",fontSize:k.body,padding:`${T.xs} ${T.md}`,whiteSpace:"nowrap"}),G(l,"bare"),l.addEventListener("click",()=>{p!==c.key&&y(c.key)}),r.push(l),o.appendChild(l)}return f(),o.addEventListener("keydown",c=>{if(c.key!=="ArrowLeft"&&c.key!=="ArrowRight")return;const l=r.indexOf(t.activeElement);if(l<0)return;c.preventDefault();const u=r[(l+(c.key==="ArrowRight"?1:-1)+r.length)%r.length];u.click(),u.focus()}),{el:o,set:c=>{p=c,f()}}}export function renderDataTables(t){const{doc:d}=t,s=d.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:T.md});const a=t.items.map((g,w)=>({...g,waferIndex:g.waferIndex??w})),h=a.flatMap(g=>g.dies),y=t.testDefs??[],o=y.filter(j),r=t.views??(a.length>1?["statistics","wafers","dies"]:["statistics","dies"]),p=t.population?{populationLabel:`${O(h.length,"die")} ${t.population}`}:a.length>1?{perWaferMetadata:a.map(g=>g.wafer?.metadata??{}),populationLabel:`${O(a.length,"wafer")} pooled`}:{waferMetadata:a[0]?.wafer?.metadata};let f=r.includes(t.view)?t.view:r[0],c="wide",l=null;const u=()=>{l?.destroy(),l=renderDataSection({doc:d,items:a,testDefs:o,allTestDefs:y,ringCount:t.ringCount,yieldByWaferIndex:new Map,onSaveText:t.onSaveText,views:r,view:f,dieListOptions:t.dieListOptions,metadataFields:t.metadataFields,attributes:t.attributes,onLocateDie:t.onLocateDie,population:t.population?{phrase:t.population,fileTag:"selection"}:void 0,buildStatistics:g=>{const w=g.flatMap(L=>L.dies),b=[],x=oe(w,o,void 0,void 0,t.onSaveText,p,g.map(L=>({dies:L.dies})),void 0,"full");x&&b.push(x);const v=se(w,y,void 0,t.onSaveText,p);return v&&b.push(v),{cards:b,destroy:()=>{}}},onViewChange:g=>{f=g,u()},diesLayout:c,onDiesLayoutChange:g=>{c=g}}),s.replaceChildren(l.card)};return u(),{el:s,destroy:()=>l?.destroy()}}export function renderSelectionTables(t){return renderDataTables({...t,views:t.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{differenceMap as
|
|
1
|
+
import"./charts/divergingScale.js";import{NEGLIGIBLE_SPREAD as L}from"../core/utils.js";import{differenceMap as W}from"../stats/differenceMap.js";import{isParametricTest as Y}from"../renderer/buildWaferMap.js";import{testLabel as G}from"../renderer/testLabel.js";import{fmt as R}from"../renderer/fmt.js";import{CLR as A,FONT as k,MAP_CHROME_INSET as q,SPACE as U}from"./toolbar.js";import{bodyRoom as X,cardShell as J,guideCite as K,isExpandedCard as Q,makeListSelect as O,observeResize as Z,renderEmptyState as ee}from"./charts/chartShell.js";import{GUIDE_SECTIONS as te}from"../stats/guideSections.js";import{renderWaferMapCard as oe}from"./renderWaferMap.js";import{cardAbout as se}from"./charts/cardAbout.js";const f="\0yield";export function renderDifferenceMapPanel(o){const m=o.ownerDocument??document,{card:c,body:w,controlsRow:_,setAbout:P}=J("Difference map",o.onSaveImage,m,{png:!1});P(se("difference-map")),c.dataset.wmapDifferenceMap="1";const g=o.groups.map(e=>e.key),p=o.testDefs.filter(Y);let l=g[0],d=g[1],t=o.selectedTestNumber!==void 0&&p.some(e=>e.testNumber===o.selectedTestNumber)?String(o.selectedTestNumber):p[0]?String(p[0].testNumber):f,M=!0,u;if(g.length<2)return ee(w,"Needs two groups to subtract."),{card:c,setTest:()=>{},destroy:()=>{}};const I=(o.groupLabelText??"Group").toLowerCase(),D=(e,s,a,S)=>O(g.map(i=>({value:i,label:i})),e,i=>{S(i),y()},{ownerDocument:m,ariaLabel:s,hook:a}),$=m.createElement("span");$.textContent="minus",Object.assign($.style,{color:A.label,fontSize:k.body});const T=()=>O([{value:f,label:"Yield"},...p.map(e=>({value:String(e.testNumber),label:G(e,e.testNumber)}))],t,e=>{t=e,M=!1,y()},{ownerDocument:m,ariaLabel:"Measure",hook:"difference-measure",searchPlaceholder:"Filter tests\u2026"});let N=T();_.append(D(l,`First ${I}`,"difference-a",e=>{l=e}),$,D(d,`Second ${I}`,"difference-b",e=>{d=e}),N);const h=m.createElement("div");Object.assign(h.style,{color:A.label,fontSize:k.body,marginBottom:U.sm});const r=m.createElement("div"),x=380,z=480;Object.assign(r.style,{position:"relative",height:`${x}px`}),w.append(h,r);const B=Z(c,()=>{const e=r.clientWidth,s=e?Math.min(z,Math.max(x,e)):x,a=`${Q(c)?Math.max(s,Math.floor(X(c,w,r))):s}px`;r.style.height!==a&&(r.style.height=a)});function y(){if(u?.destroy(),u=void 0,r.replaceChildren(),l===d){h.textContent="Choose two different groups.";return}const e=o.groups.find(b=>b.key===l),s=o.groups.find(b=>b.key===d),a=t===f?{yield:!0}:{test:Number(t)},S=t===f?void 0:p.find(b=>b.testNumber===Number(t)),i=t===f?"Yield":G(S,Number(t)),E=t===f?"%":S?.unit,n=W(e.items,s.items,a),v=Math.max(n.maxAbs,n.level*L),j=n.compared>0&&n.maxAbs<n.level*L;h.textContent=n.compared?`${i}: ${l} (${e.items.length} wafer${e.items.length===1?"":"s"}) minus ${d} (${s.items.length}), each the mean over its wafers at the position${t===f?" of the share passing":""}. ${n.compared.toLocaleString("en-GB")} positions compared; the colours run from \u2212${R(v,E)} to +${R(v,E)}, zero in the middle${j?" (no difference is over 1% of the level, so the groups do not differ in a way worth reading)":""}. Grey: a position one group has no value at.`:`${l} and ${d} have no position with a value of ${i} in common.`,n.compared&&h.append(" ",K(m,te.heatmap),".");const C=e.items[0]?.source;if(!C||!n.compared)return;const{metadata:re,...F}=C.wafer,H={...C,wafer:F,dies:n.dies,passBins:[...e.items[0].passBins],testDefs:[{testNumber:0,name:`${i}: ${l} \u2212 ${d}`,unit:E}]},V=[-(v||1),v||1];u=oe(r,H,{viewOptions:{plotMode:"value",activeTest:0,valueRange:V,valueColorScheme:"diverging"},showIdentity:!1,insights:{enabled:!1},onSaveImage:o.onSaveImage,chromeInset:q,onExpand:()=>c.querySelector("[data-wmap-card-expand]")?.click()}),u.setViewControlsVisible(!1),u.setSummaryVisible(!1)}return y(),{card:c,setTest:e=>{if(!M||!p.some(a=>a.testNumber===e)||String(e)===t)return;t=String(e);const s=T();N.replaceWith(s),N=s,y()},destroy:()=>{B.disconnect(),u?.destroy()}}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type PlotFilter } from '../stats/plotSpec.js';
|
|
2
|
+
import type { CompletionSource } from './plotJsonComplete.js';
|
|
3
|
+
export interface FilterJsonOptions {
|
|
4
|
+
doc: Document;
|
|
5
|
+
/** The filter now in force in the window's draft. */
|
|
6
|
+
filter: PlotFilter | undefined;
|
|
7
|
+
/** What the suggestions know of the lot: its fields, its tests, and the values a field takes. */
|
|
8
|
+
source: () => CompletionSource;
|
|
9
|
+
/** The text now reads as this filter (undefined: no conditions). Called as the text is typed. */
|
|
10
|
+
onChange: (filter: PlotFilter | undefined) => void;
|
|
11
|
+
/** The text cannot be a filter yet (said in words), or can again (undefined). */
|
|
12
|
+
onProblem: (problem: string | undefined) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface FilterJsonHandle {
|
|
15
|
+
el: HTMLElement;
|
|
16
|
+
/** Show `filter` in the text (an edit the history can undo). */
|
|
17
|
+
set(filter: PlotFilter | undefined): void;
|
|
18
|
+
/** Put the text back as the draft stands, dropping what could not be read. */
|
|
19
|
+
discard(filter: PlotFilter | undefined): void;
|
|
20
|
+
focus(): void;
|
|
21
|
+
}
|
|
22
|
+
/** The filter as text: always with its conditions list, so an empty filter shows where conditions go. */
|
|
23
|
+
export declare const filterText: (f: PlotFilter | undefined) => string;
|
|
24
|
+
export declare function buildFilterJsonPanel(o: FilterJsonOptions): FilterJsonHandle;
|
|
25
|
+
//# sourceMappingURL=filterJson.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{nearest as E,readFilter as F,syntaxErrorAt as O}from"../stats/plotSpec.js";import{FILTERS_FORMAT as T,readFiltersFile as j}from"../stats/filterFile.js";import{attachJsonSuggestions as A}from"./plotJsonSuggest.js";import{copyText as J,createTextHistory as N}from"./plotJsonHistory.js";import{CLR as c,FONT as S,SPACE as x,controlStyle as k,wireControlHover as L,wireTooltip as $}from"./toolbar.js";import{inputStyle as K}from"./charts/chartShell.js";const C=["conditions","off","field","values","min","max","not"];export const filterText=i=>JSON.stringify(i??{conditions:[]},null,2);function z(i){let o;try{o=JSON.parse(i)}catch(n){return{problem:`Not valid JSON: ${O(i,n instanceof Error?n.message:String(n))}`,notes:[]}}const a=typeof o=="object"&&o!==null&&!Array.isArray(o);if(Array.isArray(o)||a&&o.format===T){const n=j(i);return n.error?{problem:[n.error,...n.warnings].join(`
|
|
2
|
+
`),notes:[]}:n.filters.length>1?{choices:n.filters,notes:n.warnings,problem:"This is a filters file: choose the filter to use"}:{filter:{conditions:n.filters[0].conditions},notes:n.warnings}}if(!a)return{problem:'A filter is an object with a "conditions" list, like { "conditions": [ \u2026 ] }',notes:[]};const t=[];for(const n of Object.keys(o))if(!C.includes(n)){const f=E(n,C);t.push(`filter.${n}: not a setting of a filter, ignored.${f?` Did you mean "${f}"?`:""}`)}const d=F(o,"filter",t);return d?{filter:d,notes:t}:(Array.isArray(o.conditions)?o.conditions.length:0)>0?{problem:["No condition could be read:",...t].join(`
|
|
3
|
+
`),notes:[]}:{filter:null,notes:t}}export function buildFilterJsonPanel(i){const{doc:o}=i,a=o.createElement("div");a.dataset.wmapFilterJson="1",Object.assign(a.style,{display:"flex",flexDirection:"column",gap:x.sm,minWidth:"0"});const t=o.createElement("textarea");t.dataset.wmapFilterJsonText="1",t.value=filterText(i.filter),t.spellcheck=!1,t.rows=14,t.setAttribute("aria-label","Filter as JSON"),Object.assign(t.style,{...K(),fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:S.sub,width:"100%",boxSizing:"border-box",resize:"vertical",whiteSpace:"pre",overflow:"auto"});const d=A({doc:o,area:t,source:i.source,as:"filter"}),n=N(t),f=o.createElement("div");f.append(t,d.el);const r=o.createElement("div");r.dataset.wmapFilterJsonStatus="1",r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),Object.assign(r.style,{fontSize:S.sub,minHeight:"1.4em",whiteSpace:"pre-wrap",color:c.label});const u=o.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:x.xs,alignItems:"flex-start"});const b=(e,l)=>{const s=o.createElement("button");return s.type="button",s.textContent=e,$(s,l),Object.assign(s.style,k("outlined")),L(s),s},y=b("Suggest","Show what can be written at the cursor (also Ctrl/Cmd+Space)");y.dataset.wmapFilterJsonSuggest="1",y.addEventListener("click",()=>{d.show()||(r.style.color=c.label,r.textContent="Nothing to suggest at the cursor")});const w=b("Copy","Copy the text to the clipboard");w.addEventListener("click",()=>{const e=l=>{r.style.color=l?c.label:c.errText,r.textContent=l?"Copied":"The text could not be copied: select it and copy by hand"};J(o,t.value,e)});const h=o.createElement("div");Object.assign(h.style,{display:"flex",gap:x.sm}),h.append(y,w);const v=e=>{t.focus(),t.select(),o.execCommand?.("insertText",!1,e)||(t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))),t.setSelectionRange(0,0)},p=()=>{const e=z(t.value);if(u.replaceChildren(),e.problem){r.style.color=c.errText,r.textContent=e.problem,i.onProblem(e.problem),e.choices?.forEach((s,m)=>{const g=b(`${m+1}. ${s.name}`,"Use this filter from the file");g.dataset.wmapFilterJsonChoice=String(m),g.addEventListener("click",()=>v(filterText({conditions:s.conditions}))),u.appendChild(g)});return}i.onProblem(void 0),i.onChange(e.filter??void 0);const l=e.filter?.conditions.length??0;r.style.color=e.notes.length?c.errText:c.label,r.textContent=e.notes.length?`Left out or ignored:
|
|
4
|
+
${e.notes.join(`
|
|
5
|
+
`)}`:l===0?"No conditions: every wafer and die is shown":`${l} condition${l===1?"":"s"}`};return t.addEventListener("input",p),t.addEventListener("keydown",e=>{if(!(e.ctrlKey||e.metaKey)||e.altKey)return;const l=e.key.toLowerCase(),s=l==="z"&&!e.shiftKey,m=l==="z"&&e.shiftKey||l==="y";!s&&!m||(s?n.canUndo:n.canRedo)&&(e.preventDefault(),s?n.undo():n.redo())}),a.append(f,h,r,u),p(),{el:a,set:e=>{filterText(e)!==t.value?v(filterText(e)):p()},discard:e=>{t.value=filterText(e),p()},focus:()=>t.focus()}}
|