@wafertools/wafermap 0.36.0 → 0.37.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/AGENTS.md +2 -2
- package/CHANGELOG.md +357 -0
- package/README.md +7 -7
- package/dist/packages/canvas-adapter/charts/capability.js +1 -1
- package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
- package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
- package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
- package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
- package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
- package/dist/packages/canvas-adapter/charts/index.js +1 -1
- package/dist/packages/canvas-adapter/charts/patCard.d.ts +21 -0
- package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
- package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
- package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
- package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
- package/dist/packages/canvas-adapter/dieList.js +2 -2
- package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
- package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
- package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
- package/dist/packages/canvas-adapter/filterButton.js +1 -0
- package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
- package/dist/packages/canvas-adapter/filterEditor.js +1 -0
- package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
- package/dist/packages/canvas-adapter/guideWindow.js +1 -1
- package/dist/packages/canvas-adapter/icons.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +50 -2
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
- package/dist/packages/canvas-adapter/pageFilter.js +2 -0
- package/dist/packages/canvas-adapter/patMaps.d.ts +26 -0
- package/dist/packages/canvas-adapter/patMaps.js +1 -0
- package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
- package/dist/packages/canvas-adapter/plotCard.js +1 -0
- package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
- package/dist/packages/canvas-adapter/plotEditor.js +1 -1
- package/dist/packages/canvas-adapter/plotModal.js +1 -1
- package/dist/packages/canvas-adapter/plotStore.js +1 -1
- package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
- package/dist/packages/canvas-adapter/plotTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +15 -5
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/toolbar.d.ts +12 -0
- package/dist/packages/canvas-adapter/toolbar.js +2 -2
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +598 -115
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/core/classify.d.ts +11 -0
- package/dist/packages/core/classify.js +1 -1
- package/dist/packages/core/dies.d.ts +2 -0
- package/dist/packages/core/dies.js +1 -1
- package/dist/packages/core/wafer.d.ts +2 -2
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +2 -0
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/deprecate.d.ts +2 -8
- package/dist/packages/renderer/deprecate.js +1 -1
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/testLabel.d.ts +0 -11
- package/dist/packages/renderer/testLabel.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.d.ts +6 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +8 -0
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/binPareto.d.ts +2 -54
- package/dist/packages/stats/binPareto.js +1 -1
- package/dist/packages/stats/binRows.js +1 -1
- package/dist/packages/stats/capability.d.ts +10 -0
- package/dist/packages/stats/capability.js +1 -1
- package/dist/packages/stats/cardSpec.d.ts +53 -0
- package/dist/packages/stats/cardSpec.js +1 -0
- package/dist/packages/stats/chartCatalogue.d.ts +37 -0
- package/dist/packages/stats/chartCatalogue.js +1 -0
- package/dist/packages/stats/clusterDetection.d.ts +9 -0
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/commonality.d.ts +62 -0
- package/dist/packages/stats/commonality.js +1 -0
- package/dist/packages/stats/control.d.ts +21 -0
- package/dist/packages/stats/control.js +1 -0
- package/dist/packages/stats/correlation.d.ts +9 -3
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/dieRegions.d.ts +4 -1
- package/dist/packages/stats/dieRegions.js +1 -1
- package/dist/packages/stats/differenceMap.d.ts +22 -0
- package/dist/packages/stats/differenceMap.js +1 -0
- package/dist/packages/stats/examplePicks.d.ts +22 -0
- package/dist/packages/stats/examplePicks.js +1 -0
- package/dist/packages/stats/filterFile.d.ts +41 -0
- package/dist/packages/stats/filterFile.js +2 -0
- package/dist/packages/stats/filterFindings.d.ts +20 -5
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/groupCompare.d.ts +87 -0
- package/dist/packages/stats/groupCompare.js +1 -0
- package/dist/packages/stats/guideSections.d.ts +55 -0
- package/dist/packages/stats/guideSections.js +1 -0
- package/dist/packages/stats/index.d.ts +3 -1
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/math.d.ts +29 -4
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/metadataColumns.d.ts +3 -0
- package/dist/packages/stats/metadataColumns.js +1 -1
- package/dist/packages/stats/pat.d.ts +58 -0
- package/dist/packages/stats/pat.js +1 -0
- package/dist/packages/stats/patSummary.d.ts +45 -0
- package/dist/packages/stats/patSummary.js +1 -0
- package/dist/packages/stats/patternClassification.d.ts +3 -3
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/plotData.d.ts +294 -17
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/plotId.d.ts +2 -0
- package/dist/packages/stats/plotId.js +1 -1
- package/dist/packages/stats/plotReferences.d.ts +17 -0
- package/dist/packages/stats/plotReferences.js +1 -0
- package/dist/packages/stats/plotSpec.d.ts +239 -3
- package/dist/packages/stats/plotSpec.js +4 -4
- package/dist/packages/stats/regions.js +1 -1
- package/dist/packages/stats/renderSummaryReport.js +31 -31
- package/dist/packages/stats/reportHtml.js +9 -13
- package/dist/packages/stats/synthesis.d.ts +44 -16
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/testPassRate.d.ts +7 -0
- package/dist/packages/stats/testPassRate.js +1 -1
- package/dist/packages/stats/types.d.ts +13 -8
- package/dist/packages/stats/yield.d.ts +3 -11
- package/dist/packages/stats/yield.js +1 -1
- package/llms.txt +1 -1
- package/package.json +2 -1
- package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
- package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
- package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
- package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
- package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
- package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
- package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
- package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
- package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
- package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
- package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
- package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
- package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
- package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
- package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
- package/dist/packages/canvas-adapter/charts/trend.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{escHtml as I,maxOf as fe,minOf as Oe}from"../../core/utils.js";import{fiveNumberSummary as We}from"../../stats/math.js";import{fmt as R}from"../../renderer/fmt.js";import{fitTicks as we}from"../../renderer/axisTicks.js";import{plotFootnote as Fe,plotTestNumber as ze,plotTitle as nt}from"../../stats/plotData.js";import{SPACE as te,RADIUS as ot,fontPx as me,FONT as Le,CLR as xe,markNoPrint as Re}from"../toolbar.js";import{cardShell as it,observeResize as lt,makeTooltip as st,attachChartTip as at,chartFillHeight as rt,applyCanvasFlow as ke,prepareCanvas as Me,positionChartTooltip as $e,resolveChartCanvasColors as ve,makeAxisFormat as ct,horizontalTickSpacing as ft,VERTICAL_TICK_SPACING_PX as mt,makeSeriesLegendItem as ht,renderEmptyState as qe,limitLines as ut,limitExtent as dt,stackLabelRows as He,placeClearOf as Xe,strokeLimitLine as _e,drawOffAxisLimits as gt,limitLabelSide as pt,shouldIncludeLimitsByDefault as yt}from"./chartShell.js";import{categorical as bt}from"./palette.js";import{resolveValueColorFn as Pe}from"../../renderer/colorSchemes.js";import{wirePointInteractions as xt}from"./pointInteractions.js";const M=64,je=16,k=12,he=52,kt=16,Ce=5e3;function ne(b,P,$={}){const q=P.scale==="log";let w=b.length?Oe(b):0,F=b.length?fe(b):1;q&&(w=Math.log10(Math.max(w,Number.MIN_VALUE)),F=Math.log10(Math.max(F,Number.MIN_VALUE)));const oe=(F-w)*.05||(q?.5:1);w=$.floorAtZero&&!q&&w>=0?0:w-oe,F+=oe;const a=x=>x===void 0||!Number.isFinite(x)?void 0:q?x>0?Math.log10(x):void 0:x,g=a(P.min),H=a(P.max);g!==void 0&&(w=g),H!==void 0&&(F=H),F>w||(F=w+1);const A=F-w,Z=!!P.reverse,K=x=>{const G=((q?Math.log10(Math.max(x,Number.MIN_VALUE)):x)-w)/A;return Z?1-G:G};return{lo:q?10**w:w,hi:q?10**F:F,log:q,reverse:Z,frac:K}}function Ue(b,P,$,q){if(P/b<10)return we(b,P,$,q);const w=Math.floor(Math.log10(b)),F=Math.ceil(Math.log10(P)),oe=g=>{const H=[];for(let A=w;A<=F;A++)for(const Z of g){const K=Z*10**A;K>=b&&K<=P&&H.push(K)}return H},L=oe([1]);return{ticks:L.length>=4?L:oe([1,2,5]),step:0}}export function renderPlotChart(b){const P=b.ownerDocument??document,{card:$,heading:q,body:w,controlsRow:F,setPngDecor:oe}=it("Plot",b.onSaveImage,P);$.dataset.wmapPlotCard="1";const L=st($);let a,g,H,A,Z,K=[];const x=new Set,G=new Set;let ue=null,X=-1,ce=[],z,J,D,_=null,Q=[],V=-1,Se=[],de=he;const ie=e=>bt(e),ge=e=>a?.groups[e]||"";function pe(){const e=w.clientWidth,l=Math.max(220,Math.min(420,e*.62))+(de-he),c=rt($,w,g,l);return{w:e,h:c,plotW:Math.max(10,e-M-je),plotH:Math.max(10,c-k-de)}}const le=e=>ut(e?.limits,a?.spec.limits??"both").filter(l=>e?.scale!=="log"||l.value>0),ae=(e,l)=>{const c=e.filter(Number.isFinite);if(!l.length||c.length===0)return e;const{lo:r,hi:i}=dt(l);return yt(Oe(c),fe(c),r,i)?[...e,...l.map(o=>o.value)]:e};function re(e,l,c,r,i,o,t,n){if(o.length===0)return;const f=o.filter(u=>u.value>=i.lo&&u.value<=i.hi),p=o.filter(u=>!f.includes(u)).map(u=>({value:u.value,label:u.label,side:u.value<i.lo?"lo":"hi"}));e.save(),e.font=`${me(-1)}px system-ui, sans-serif`;const h=u=>`${u.label} ${R(u.value,t.unit)}`,s=me(-1)+2;if(n==="y"){const u=f.map(m=>{const y=k+(1-i.frac(m.value))*r;return{l:m,y,start:y-6-s/2,end:y-6+s/2}}),T=He(u,1),d=u.length?fe(u.map(m=>e.measureText(h(m.l)).width))+8:0;u.forEach(({l:m,y},S)=>{e.globalAlpha=.7,_e(e,m,l,M,y,M+c,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const v=M+3+T[S]*d,U=Xe(Se,{x0:v,x1:v+e.measureText(h(m)).width,y0:y-4-s+2,y1:y-4+2},s);e.fillText(h(m),v,U.y1-2)})}else{const u=f.map(d=>{const m=M+i.frac(d.value)*c,y=e.measureText(h(d)).width,S=pt(m,y,M,M+c,d.end==="lo");return{l:d,x:m,side:S,start:S<0?m-3-y:m+3,end:S<0?m-3:m+3+y}}),T=He(u,4);u.forEach(({l:d,x:m,side:y,start:S,end:v},U)=>{e.globalAlpha=.7,_e(e,d,l,m,k,m,k+r),e.globalAlpha=1,e.fillStyle=l,e.textAlign=y<0?"right":"left",e.textBaseline="top";const C=k+2+T[U]*s,E=Xe(Se,{x0:S,x1:v,y0:C,y1:C+s},s);e.fillText(h(d),m+y*3,E.y0)})}e.restore(),gt(e,p,{left:M,right:M+c,top:k,bottom:k+r},n==="y"?"vertical":"horizontal",l,u=>R(u,t.unit))}function Ee(e,l,c,r){return ct(Math.max(Math.abs(l),Math.abs(c)),e.unit,r)}function Ae(e,l){return l?`${e.label} (${l})`:e.label}function ye(e,l,c,r,i,o,t,n,f,p){Se=[],e.font=`${me(-1)}px system-ui, sans-serif`;const h=()=>mt,s=n.log?Ue(n.lo,n.hi,o,h):we(n.lo,n.hi,o,h),u=Ee(p,n.lo,n.hi,s.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let T="";if("labels"in t){const d=t.labels.length;t.labels.forEach((m,y)=>{const S=M+(y+.5)/d*i,v=m.length>22?`${m.slice(0,21)}\u2026`:m;t.rotate?(e.save(),e.translate(S,k+o+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(v,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(v,S,k+o+4))})}else{const d=ft(e,Math.max(Math.abs(t.lo),Math.abs(t.hi)),f.unit),m=t.log?Ue(t.lo,t.hi,i,d):we(t.lo,t.hi,i,d),y=Ee(f,t.lo,t.hi,m.step||void 0);T=y.unitLabel;for(const S of m.ticks){const v=M+t.frac(S)*i;e.beginPath(),e.moveTo(v,k),e.lineTo(v,k+o),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y.tick(S),v,k+o+4)}}for(const d of s.ticks){const m=k+(1-n.frac(d))*o;e.beginPath(),e.moveTo(M,m),e.lineTo(M+i,m),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(u.tick(d),M-4,m)}e.font=`${me(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Ae(f,T),M+i/2,r-6),e.save(),e.translate(14,k+o/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Ae(p,u.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(M,k),e.lineTo(M,k+o),e.moveTo(M,k+o),e.lineTo(M+i,k+o),e.stroke()}function Ye(){if(!a||!g||a.marks?.type!=="scatter"||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,n=a.marks.points,f=x.size===0?n:n.filter(E=>x.has(E.group)),p=a.colorScale,h=Pe(),s=le(a.x),u=le(a.y),T=ne(ae(n.map(E=>E.x),s),a.x),d=ne(ae(n.map(E=>E.y),u),a.y);z={x:T,y:d,plotW:r,plotH:i},ye(t,e,l,c,r,i,T,d,a.x,a.y),re(t,e.limitLine,r,i,T,s,a.x,"x"),re(t,e.limitLine,r,i,d,u,a.y,"y");const m=f.length>Ce?Math.ceil(f.length/Ce):1;t.globalAlpha=Math.max(.15,Math.min(.7,200/(f.length/m))),ce=[];const y=M,S=M+r,v=k,U=k+i;for(let E=0;E<f.length;E+=m){const N=f[E],se=M+T.frac(N.x)*r,Y=k+(1-d.frac(N.y))*i;se<y||se>S||Y<v||Y>U||(ce.push({p:N,cx:se,cy:Y}),t.beginPath(),t.arc(se,Y,2.5,0,Math.PI*2),t.fillStyle=p&&N.value!==void 0?h((N.value-p.lo)/(p.hi-p.lo||1)):ie(N.group),t.fill())}t.globalAlpha=1;const C=ue?ce.find(E=>E.p===ue):void 0;if(C&&(t.beginPath(),t.arc(C.cx,C.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=e.text,t.stroke()),G.size>0){t.lineWidth=1.5,t.strokeStyle=e.text;let E=0;for(const N of G)if(!(x.size>0&&!x.has(N.group))){if(++E>Ce)break;t.beginPath(),t.arc(M+T.frac(N.x)*r,k+(1-d.frac(N.y))*i,4,0,Math.PI*2),t.stroke()}}}function Ge(){if(J=void 0,!a||a.marks?.type!=="histogram"||!a.x)return;const e=a.marks.values,l=e.flat();if(l.length===0)return;const c=ne(ae(l,le(a.x)),a.x),r=Math.max(1,a.spec.bins??kt),i=c.log?Math.log10(c.lo):c.lo,o=c.log?Math.log10(c.hi):c.hi,t=Array.from({length:r+1},(f,p)=>{const h=i+(o-i)*p/r;return c.log?10**h:h}),n=e.map(()=>new Array(r).fill(0));e.forEach((f,p)=>{for(const h of f){const s=c.log?h>0?Math.log10(h):NaN:h;if(!Number.isFinite(s)||s<i||s>o)continue;const u=Math.min(r-1,Math.floor((s-i)/(o-i)*r));n[p][u]++}}),J={edges:t,counts:n,maxCount:Math.max(1,...n.map(f=>fe(f)))}}function De(){if(!a||!g||!J||!a.x||!a.y)return;ke(g,A??0);const e=ve($),{w:l,h:c,plotW:r,plotH:i}=pe(),o=Me(g,$,l,c);if(!o)return;const{ctx:t}=o,{edges:n,counts:f,maxCount:p}=J,h=ne([n[0],n[n.length-1]],{...a.x,min:n[0],max:n[n.length-1]}),s=ne([0,p],{label:a.y.label,scale:"linear",min:0,max:p*1.05});z={x:h,y:s,plotW:r,plotH:i},ye(t,e,l,c,r,i,h,s,a.x,a.y),re(t,e.limitLine,r,i,h,le(a.x),a.x,"x");const u=f.map((d,m)=>m).filter(d=>x.size===0||x.has(d)),T=u.length>1;for(const d of u)t.globalAlpha=T?.55:.85,t.fillStyle=ie(d),f[d].forEach((m,y)=>{if(m===0)return;const S=M+Math.min(h.frac(n[y]),h.frac(n[y+1]))*r,v=M+Math.max(h.frac(n[y]),h.frac(n[y+1]))*r,U=k+(1-s.frac(m))*i;t.fillRect(S,U,Math.max(1,v-S-1),k+i-U)});if(t.globalAlpha=1,X>=0){const d=M+Math.min(h.frac(n[X]),h.frac(n[X+1]))*r,m=M+Math.max(h.frac(n[X]),h.frac(n[X+1]))*r;t.lineWidth=1.5,t.strokeStyle=e.text,t.strokeRect(d,k,Math.max(1,m-d),i)}}function Ve(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="box"&&e.type!=="bar")return;ke(g,A??0);const l=ve($),c=g.getContext("2d");let r=0;c&&(c.font=`${me(-1)}px system-ui, sans-serif`,r=fe(e.categories.map(C=>c.measureText(C.length>22?`${C.slice(0,21)}\u2026`:C).width)));const i=Math.max(10,w.clientWidth-M-je)/Math.max(1,e.categories.length),o=r+8>i;de=o?he+Math.min(110,r*.72):he;const{w:t,h:n,plotW:f,plotH:p}=pe(),h=Me(g,$,t,n);if(!h)return;const{ctx:s}=h,u=C=>C.filter(Number.isFinite),T=le(a.y),d=ne(ae(e.type==="bar"?[...u(e.values.flat()),0]:u(e.cells.flat(2)),T),a.y,{floorAtZero:e.type==="bar"});z={x:d,y:d,plotW:f,plotH:p},ye(s,l,t,n,f,p,{labels:e.categories,rotate:o},d,a.x,a.y),re(s,l.limitLine,f,p,d,T,a.y,"y");const m=e.categories.length,y=a.groups.length,S=f/m,v=S*.8/y;D={slotW:S,gw:v,n:m,groups:y,plotW:f};const U=d.log?k+p:k+(1-d.frac(0))*p;for(let C=0;C<y;C++){if(x.size>0&&!x.has(C))continue;const E=ie(C);for(let N=0;N<m;N++){const se=M+N*S+S*.1+C*v;if(e.type==="bar"){const Y=e.values[C][N];if(!Number.isFinite(Y))continue;const j=k+(1-d.frac(Y))*p;s.fillStyle=E,s.globalAlpha=.9,s.fillRect(se+1,Math.min(j,U),Math.max(1,v-2),Math.max(1,Math.abs(U-j))),s.globalAlpha=1}else{const Y=e.cells[C][N];if(Y.length===0)continue;const j=se+v/2,ee=Math.max(3,Math.min(v*.7,46)),O=We(Float64Array.from(Y)),W=be=>k+(1-d.frac(be))*p;if(s.strokeStyle=E,s.fillStyle=E,s.lineWidth=1.5,Y.length===1){s.beginPath(),s.arc(j,W(O.median),3,0,Math.PI*2),s.fill();continue}s.beginPath(),s.moveTo(j,W(O.min)),s.lineTo(j,W(O.max)),s.stroke();for(const be of[O.min,O.max])s.beginPath(),s.moveTo(j-ee/4,W(be)),s.lineTo(j+ee/4,W(be)),s.stroke();s.globalAlpha=.35,s.fillRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.globalAlpha=1,s.strokeRect(j-ee/2,Math.min(W(O.q1),W(O.q3)),ee,Math.max(1,Math.abs(W(O.q1)-W(O.q3)))),s.lineWidth=2.5,s.beginPath(),s.moveTo(j-ee/2,W(O.median)),s.lineTo(j+ee/2,W(O.median)),s.stroke()}}}if(_){const C=M+_.c*S+S*.1+_.g*v;s.lineWidth=1.5,s.strokeStyle=l.text,s.strokeRect(C,k,v,p)}}function Ie(e){if(!D||!g)return null;const l=g.getBoundingClientRect(),c=e.clientX-l.left-M;if(c<0||c>D.plotW)return null;const r=Math.min(D.n-1,Math.floor(c/D.slotW)),i=Math.floor((c-r*D.slotW-D.slotW*.1)/D.gw);return i<0||i>=D.groups?null:{g:i,c:r}}function Ze(e){const l=a,c=l.marks,r=l.level==="die"?"dies":"wafers",i=c.cells[e.g][e.c],o=`<strong>${I(c.categories[e.c])}${l.groups.length>1?` \xB7 ${I(ge(e.g))}`:""}</strong><br>`,t=l.y?.unit;if(i.length===0)return`${o}no ${r}`;const n=`${i.length.toLocaleString("en-GB")} ${r}`,f=c.categoryItems&&b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"";if(c.type==="bar"){const h=c.values[e.g][e.c];return`${o}${I(`${l.y.label}: ${R(h,t)}`)}<br>${I(n)}${f}`}const p=We(Float64Array.from(i));return`${o}${["max","q3","median","q1","min"].map(h=>I(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[h]}: ${R(p[h],t)}`)).join("<br>")}<br>${I(n)}${f}`}function Ke(){const e=a?.marks;if(!a||!g||!a.x||!a.y||!e||e.type!=="line")return;ke(g,A??0);const l=ve($),{w:c,h:r,plotW:i,plotH:o}=pe(),t=Me(g,$,c,r);if(!t)return;const{ctx:n}=t,f=le(a.x),p=le(a.y),h=ne(ae(e.xs,f),a.x),s=ne(ae(e.values.flat().filter(Number.isFinite),p),a.y);z={x:h,y:s,plotW:i,plotH:o},ye(n,l,c,r,i,o,h,s,a.x,a.y),re(n,l.limitLine,i,o,h,f,a.x,"x"),re(n,l.limitLine,i,o,s,p,a.y,"y"),Q=e.xs.map(u=>M+h.frac(u)*i),e.values.forEach((u,T)=>{if(x.size>0&&!x.has(T))return;n.strokeStyle=ie(T),n.fillStyle=ie(T),n.lineWidth=2;let d=!1;n.beginPath(),u.forEach((m,y)=>{if(!Number.isFinite(m)){d=!1;return}const S=Q[y],v=k+(1-s.frac(m))*o;d?n.lineTo(S,v):n.moveTo(S,v),d=!0}),n.stroke(),u.forEach((m,y)=>{Number.isFinite(m)&&(n.beginPath(),n.arc(Q[y],k+(1-s.frac(m))*o,V===y?4.5:3,0,Math.PI*2),n.fill())})}),V>=0&&(n.lineWidth=1,n.strokeStyle=l.textMuted,n.beginPath(),n.moveTo(Q[V],k),n.lineTo(Q[V],k+o),n.stroke())}function Ne(e){const l=a?.marks;if(!l||l.type!=="line"||!g||!a?.x||Q.length===0)return null;const c=e.clientX-g.getBoundingClientRect().left;let r=-1,i=24;if(Q.forEach((n,f)=>{const p=Math.abs(n-c);p<i&&(i=p,r=f)}),V=r,r<0)return null;const o=a.level==="die"?"dies":"wafers",t=l.values.map((n,f)=>({g:f,v:n[r],n:l.counts[f][r]})).filter(n=>Number.isFinite(n.v)&&(x.size===0||x.has(n.g)));return`<strong>${I(`${a.x.label}: ${R(l.xs[r],a.x.unit)}`)}</strong><br>`+t.map(n=>I(`${a.groups.length>1?`${ge(n.g)}: `:""}${R(n.v,a.y.unit)} (${n.n.toLocaleString("en-GB")} ${o})`)).join("<br>")}function B(){const e=a?.marks?.type;e==="scatter"?Ye():e==="histogram"?De():e==="box"||e==="bar"?Ve():e==="line"&&Ke()}function Je(e){const l=a,c=b.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",i=[c,r].filter(Boolean).join(" \xB7 "),o=(t,n)=>`${t.label}: ${R(n,t.unit)}`;return(i?`<strong>${I(i)}</strong><br>`:"")+I(o(l.x,e.x))+"<br>"+I(o(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${I(`${l.colorScale.label}: ${R(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${I(ge(e.group))}`:"")+(b.onOpenWafer?`<br><em>click to ${I(b.openActionLabel??"open this wafer")}</em>`:"")}function Be(e){if(!J||!z||!a?.x)return null;const l=g.getBoundingClientRect(),r=(e.clientX-l.left-M)/z.plotW;if(r<0||r>1)return null;const i=z.x.reverse?1-r:r,{edges:o,counts:t}=J,n=o.length-1,f=Math.min(n-1,Math.max(0,Math.floor(i*n)));X=f;const p=a.x,h=t.map((s,u)=>({g:u,n:s[f]})).filter(s=>s.n>0&&(x.size===0||x.has(s.g)));return`<strong>${I(`${R(o[f],p.unit)} to ${R(o[f+1],p.unit)}`)}</strong><br>`+(h.length?h.map(s=>I(`${a.groups.length>1?`${ge(s.g)}: `:""}${s.n.toLocaleString("en-GB")} ${a.level==="die"?"dies":"wafers"}`)).join("<br>"):"none")}function Qe(e){const l=P.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:te.md,marginTop:te.md,marginBottom:te.xl,fontSize:Le.body,color:xe.label});const c=P.createElement("canvas");c.width=200,c.height=10,Object.assign(c.style,{width:"200px",height:"10px",borderRadius:ot.control,flex:"0 0 auto"});const r=c.getContext("2d"),i=Pe();if(r)for(let f=0;f<200;f++)r.fillStyle=i(f/199),r.fillRect(f,0,1,10);const o=P.createElement("span");o.textContent=R(e.lo,e.unit);const t=P.createElement("span");t.textContent=R(e.hi,e.unit);const n=P.createElement("span");return n.textContent=e.label,n.style.color=xe.text,l.append(n,o,c,t),l}const Te=(e,l,c)=>l.map(r=>{const{item:i,die:o}=e(r);return{x:0,y:0,group:c,item:i,die:o}});function et(){Z?.destroy(),Z=void 0,w.innerHTML="",g=void 0,H=void 0,A=void 0,K=[],ue=null,X=-1,ce=[],z=void 0,D=void 0,_=null,Q=[],V=-1,de=he,x.clear(),G.clear();const e=a;if(!e)return;if(q.textContent=nt(e),$.dataset.wmapChartTitle=q.textContent,e.issues.length||!e.marks){for(const i of e.issues)qe(w,i);return}const l=P.createElement("div");Object.assign(l.style,{color:xe.label,fontSize:Le.body,marginBottom:te.xs});const c=b.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(b.onOpenWafer?` \xB7 click a point to ${c}`:"")+(b.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(b.onOpenWafer&&e.marks.categoryItems?` \xB7 click to ${c}`:b.onSelectPoints?" \xB7 click to chart or tabulate what it counts":"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&b.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="line"&&b.onSelectPoints?" \xB7 click a point to chart or tabulate what it averages":"";l.textContent=Fe(e)+r,Re(l),A=P.createElement("div"),A.style.display="flow-root",w.appendChild(A),A.appendChild(l);for(const i of e.notes){const o=P.createElement("div");Re(o),o.textContent=i,Object.assign(o.style,{color:xe.warnText,fontSize:Le.body,marginBottom:te.xs}),A.appendChild(o)}if(e.plotted===0){qe(w,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&(H=P.createElement("div"),Object.assign(H.style,{display:"flex",flexWrap:"wrap",gap:te.sm,marginTop:te.md,marginBottom:te.xl}),e.groups.forEach((i,o)=>{const t=ht(i||"(none)",ie(o),P);at(t.el,$,L,`${i||"(none)"} \u2014 click to filter`),t.el.addEventListener("click",()=>{x.has(o)?x.delete(o):x.add(o),K.forEach((n,f)=>n.setState({selected:x.has(f),dimmed:x.size>0&&!x.has(f)})),B()}),K.push(t),H.appendChild(t.el)}),A.appendChild(H)),e.colorScale&&(H=Qe(e.colorScale),A.appendChild(H)),g=P.createElement("canvas"),g.style.display="block",g.style.cursor=e.marks.type==="scatter"?"crosshair":"default",w.appendChild(g),e.marks.type==="scatter"){const i=e.marks,o=!!b.onSelectPoints;Z=xt({card:$,canvas:g,tooltip:L,drawn:()=>ce,describe:Je,clickable:()=>!!b.onOpenWafer,onOpen:t=>b.onOpenWafer?.(t.item,ze(e.spec)),onHover:t=>{ue=t,B()},select:o?{pick:({x0:t,y0:n,x1:f,y1:p})=>z?(x.size===0?i.points:i.points.filter(s=>x.has(s.group))).filter(s=>{const u=M+z.x.frac(s.x)*z.plotW,T=k+(1-z.y.frac(s.y))*z.plotH;return u>=t&&u<=f&&T>=n&&T<=p}):[],onPicked:(t,n)=>{G.clear();for(const f of t)G.add(f);B(),t.length>0&&b.onSelectPoints(t,n,g)},onClear:()=>{G.clear(),B()},hasSelection:()=>G.size>0}:void 0})}else if(e.marks.type==="histogram"){Ge(),g.addEventListener("mousemove",o=>{const t=Be(o);if(!t){L.style.display="none",X>=0&&(X=-1,B());return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",X>=0&&(X=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(!J||Be(o)===null)return;const t=X,{edges:n}=J,f=z?.x.log,p=f?Math.log10(n[0]):n[0],h=f?Math.log10(n[n.length-1]):n[n.length-1],s=n.length-1,u=[];i.values.forEach((T,d)=>{if(x.size>0&&!x.has(d))return;const m=[];T.forEach((y,S)=>{const v=f?y>0?Math.log10(y):NaN:y;!Number.isFinite(v)||v<p||v>h||Math.min(s-1,Math.floor((v-p)/(h-p)*s))===t&&m.push(i.units[d][S])}),u.push(...Te(i.unit,m,d))}),u.length>0&&(L.style.display="none",b.onSelectPoints(u,{x:o.clientX,y:o.clientY},g))}))}else if(e.marks.type==="box"||e.marks.type==="bar"){const i=e.marks;g.addEventListener("mousemove",o=>{const t=Ie(o);if(g.style.cursor=t&&(i.categoryItems&&b.onOpenWafer||b.onSelectPoints&&i.cellUnits[t.g][t.c].length>0)?"pointer":"default",!t){L.style.display="none",_&&(_=null,B());return}L.innerHTML=Ze(t),L.style.display="block",$e(L,$,o.clientX,o.clientY),(!_||_.g!==t.g||_.c!==t.c)&&(_=t,B())}),g.addEventListener("mouseleave",()=>{L.style.display="none",_&&(_=null,B())}),g.addEventListener("click",o=>{const t=Ie(o);if(!t)return;const n=i.categoryItems?.[t.c];if(n!==void 0&&n>=0&&b.onOpenWafer){b.onOpenWafer(n,ze(e.spec));return}const f=i.cellUnits[t.g][t.c];f.length>0&&b.onSelectPoints&&(L.style.display="none",b.onSelectPoints(Te(i.unit,f,t.g),{x:o.clientX,y:o.clientY},g))})}else if(e.marks.type==="line"){g.addEventListener("mousemove",o=>{const t=Ne(o);if(!t){L.style.display="none",B();return}L.innerHTML=t,L.style.display="block",$e(L,$,o.clientX,o.clientY),B()}),g.addEventListener("mouseleave",()=>{L.style.display="none",V>=0&&(V=-1,B())});const i=e.marks;b.onSelectPoints&&(g.style.cursor="pointer",g.addEventListener("click",o=>{if(Ne(o)===null||V<0)return;const t=i.cellUnits.flatMap((n,f)=>x.size>0&&!x.has(f)?[]:Te(i.unit,n[V]??[],f));t.length>0&&(L.style.display="none",b.onSelectPoints(t,{x:o.clientX,y:o.clientY},g))}))}B()}oe(()=>{const e=a;if(!e||!e.marks)return;const l=Pe();return{caption:[Fe(e),...e.notes],legend:e.groups.length>1?e.groups.map((c,r)=>({label:c||"(none)",color:ie(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:R(e.colorScale.lo,e.colorScale.unit),hi:R(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const tt=lt($,()=>B());return{card:$,actions:F,setPlot(e){a=e,et()},destroy(){tt.disconnect(),Z?.destroy()}}}
|
|
1
|
+
import{escHtml as U,maxOf as ke,minOf as Rt}from"../../core/utils.js";import{fiveNumberSummary as zt,normalQuantile as _t,sampleVariance as An}from"../../stats/math.js";import{CONTROL_RULE_TEXT as En}from"../../stats/control.js";import{PAT_VERDICT_LABEL as Gt}from"../../stats/pat.js";import{fmt as ee}from"../../renderer/fmt.js";import{fitTicks as ft}from"../../renderer/axisTicks.js";import{binOfLabel as Cn,plotFootnote as Xt,plotGuideSections as Ut,plotTestNumber as Ye,plotTitle as Bn,probabilityPosition as it}from"../../stats/plotData.js";import{SPACE as xe,RADIUS as Wn,fontPx as te,FONT as ut,CLR as Je,markNoPrint as Dt}from"../toolbar.js";import{cardShell as In,appendGuideCites as Nn,observeResize as Fn,makeTooltip as On,attachChartTip as Rn,chartFillHeight as zn,applyCanvasFlow as Re,prepareCanvas as ze,positionChartTooltip as ht,resolveChartCanvasColors as _e,makeAxisFormat as _n,horizontalTickSpacing as jt,VERTICAL_TICK_SPACING_PX as Gn,makeSeriesLegendItem as Xn,renderEmptyState as qt,isExpandedCard as Yt,fillTextOnHalo as St,limitLines as Un,limitExtent as Dn,stackLabelRows as Ht,placeClearOf as Vt,strokeLimitLine as Kt,drawOffAxisLimits as jn,limitLabelSide as qn,shouldIncludeLimitsByDefault as Yn,WAFER_MENU_HINT as Zt}from"./chartShell.js";import{guideCitesText as Hn}from"../../stats/guideSections.js";import{categorical as Vn}from"./palette.js";import{NO_DATA_FILL as Qt}from"../../renderer/colorMap.js";import{resolveValueColorFn as dt}from"../../renderer/colorSchemes.js";import{wirePointInteractions as $t}from"./pointInteractions.js";import{plotAbout as Kn}from"./cardAbout.js";const wt=64,mt=16,Pt=12,Ge=52,Zn=16,Qn=92,Jn=16,Lt=5e3,Jt=1500,at=100,eo=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],en=h=>`${+(h*100).toPrecision(4)}%`;export function categoryLayout(h){const I=.8/Math.max(1,...h.map(B=>B.length)),j=B=>(1-h[B].length*I)/2;return{width:I,left:(B,q)=>{const V=h[B].indexOf(q);return V<0?void 0:j(B)+V*I},groupAt:(B,q)=>{const V=Math.floor((q-j(B))/I);return V>=0&&V<h[B].length?h[B][V]:void 0}}}function to(h){if(h<=Jt)return Array.from({length:h},(B,q)=>q);const R=[];for(let B=0;B<at;B++)R.push(B);const I=Jt-2*at,j=h-2*at;for(let B=0;B<I;B++)R.push(at+Math.floor(B*j/I));for(let B=h-at;B<h;B++)R.push(B);return R}function At(h,R,I){return I?Math.round(h).toLocaleString("en-GB"):R?ee(h,R):`${h<=-.005?"\u2212":""}${Math.abs(h).toFixed(2)}`}const no=260;function oo(h){const R=[...h.querySelectorAll("[data-wmap-plot-panel]")],I=R[0]?.querySelector("canvas");if(!I)return null;const j=I.width/Math.max(1,I.getBoundingClientRect().width)||1,B=h.getBoundingClientRect(),q=h.ownerDocument.createElement("canvas");q.width=Math.ceil(B.width*j),q.height=Math.ceil(B.height*j);const V=q.getContext("2d");if(!V)return null;const Te=getComputedStyle(h);V.fillStyle=Te.backgroundColor&&Te.backgroundColor!=="rgba(0, 0, 0, 0)"?Te.backgroundColor:"#fff",V.fillRect(0,0,q.width,q.height);for(const ve of R){const Se=ve.querySelector("canvas"),ce=ve.dataset.wmapChartTitle??"",z=(Se??ve).getBoundingClientRect(),i=ve.getBoundingClientRect();V.fillStyle=getComputedStyle(ve).color||"#333",V.font=`600 ${Math.round(13*j)}px system-ui, sans-serif`,V.textBaseline="top",V.fillText(ce,(i.left-B.left+8)*j,(i.top-B.top+6)*j),Se&&V.drawImage(Se,(z.left-B.left)*j,(z.top-B.top)*j,z.width*j,z.height*j)}return q}const Be=(h,R)=>R.extent?[...h,...R.extent]:h;function ue(h,R,I={}){const j=R.scale==="log";let B=h.length?Rt(h):0,q=h.length?ke(h):1;j&&(B=Math.log10(Math.max(B,Number.MIN_VALUE)),q=Math.log10(Math.max(q,Number.MIN_VALUE)));const V=(q-B)*.05||(j?.5:1);B=I.floorAtZero&&!j&&B>=0?0:B-V,q+=V;const ve=Q=>Q===void 0||!Number.isFinite(Q)?void 0:j?Q>0?Math.log10(Q):void 0:Q,Se=ve(R.min),ce=ve(R.max);Se!==void 0&&(B=Se),ce!==void 0&&(q=ce),q>B||(q=B+1);const z=q-B,i=!!R.reverse,S=Q=>{const J=((j?Math.log10(Math.max(Q,Number.MIN_VALUE)):Q)-B)/z;return i?1-J:J};return{lo:j?10**B:B,hi:j?10**q:q,log:j,reverse:i,frac:S}}function Et(h,R,I,j){if(R/h<10)return ft(h,R,I,j);const B=Math.floor(Math.log10(h)),q=Math.ceil(Math.log10(R)),V=Se=>{const ce=[];for(let z=B;z<=q;z++)for(const i of Se){const S=i*10**z;S>=h&&S<=R&&ce.push(S)}return ce},Te=V([1]);return{ticks:Te.length>=4?Te:V([1,2,5]),step:0}}export function renderPlotChart(h){const R=h.ownerDocument??document,{card:I,heading:j,body:B,controlsRow:q,setPngDecor:V,setPngCanvas:Te,setAbout:ve,setMenuRows:Se}=In(h.panel?.title??"Plot",h.onSaveImage,R,{png:!h.panel});h.panel&&(I.dataset.wmapPlotPanel="1");let ce=[];I.dataset.wmapPlotCard="1";const z=On(I);let i,S,Q,J,He,et=[];const W=new Set,Xe=new Set;let de=null,me=-1,se=[],K,Ae,ne,ie=null,tt=0,$e,rt;const tn=()=>!!i?.facets;let he=[],Me=-1,pt=new Map,Ue=[],De=Ge,k=wt,M=Pt;const nn={[Gt.outlier]:"#e69f00",[Gt.fails]:"#c0392b"},oe=e=>{const l=i?.groups[e]??"";if(i?.colorBins&&h.binColors){const s=Cn(l);return s===void 0?Qt:(i.colorBins==="hard"?h.binColors.hard:h.binColors.soft).get(s)??Qt}return nn[l]??Vn(e)},je=e=>i?.groups[e]||"";function We(){const e=B.clientWidth,l=(h.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(De-Ge),s=zn(I,B,S,l);return{w:e,h:s,plotW:Math.max(10,e-k-mt),plotH:Math.max(10,s-M-De)}}const Ee=e=>{const l=(e?.references??[]).flatMap(s=>s.to===void 0?[{value:s.at,kind:"ref",end:"lo",label:s.label??""}]:[{value:s.at,kind:"ref",end:"lo",label:s.label??"",bandTo:s.to},{value:s.to,kind:"ref",end:"hi",label:s.label??""}]);return[...Un(e?.limits,i?.spec.limits??"both"),...l].filter(s=>e?.scale!=="log"||s.value>0)},Ie=(e,l,s)=>{const r=s?.clip,a=r?[...e.filter(d=>d>=r.lo&&d<=r.hi),r.lo,r.hi]:e,u=a.filter(Number.isFinite);if(!l.length||u.length===0)return a;const{lo:n,hi:t}=Dn(l);return(s?i?.spec.axes?.[s===i?.x?"x":"y"]?.includeLimits:void 0)??Yn(Rt(u),ke(u),n,t)?[...a,...l.map(d=>d.value)]:a};let gt;function Ve(e,l,s,r=!1){return!r&&!i?.x?.clip&&!i?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(k,M,l,s),e.clip(),gt=e,Ct)}function Ct(){gt?.restore(),gt=void 0}function Ne(e,l,s,r,a,u,n,t,o){const d=[];if(u.length===0)return()=>{};const $=u.filter(m=>m.value>=a.lo&&m.value<=a.hi),w=u.filter(m=>!$.includes(m)).map(m=>({value:m.value,label:m.label,side:m.value<a.lo?"lo":"hi"}));e.save(),e.font=`${te(-1)}px system-ui, sans-serif`;const b=m=>`${m.label} ${ee(m.value,n.unit)}`.trim(),c=te(-1)+2;for(const m of u){if(m.bandTo===void 0)continue;const P=a.frac(Math.min(m.value,m.bandTo)),v=a.frac(Math.max(m.value,m.bandTo)),g=Math.max(0,Math.min(P,v)),y=Math.min(1,Math.max(P,v));y<=g||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(k,M+(1-y)*r,s,(y-g)*r):e.fillRect(k+g*s,M,(y-g)*s,r),e.restore())}if(t==="y"){const m=$.map(g=>{const y=M+(1-a.frac(g.value))*r;return{l:g,y,start:y-6-c/2,end:y-6+c/2}}),P=Ht(m,1),v=m.length?ke(m.map(g=>e.measureText(b(g.l)).width))+8:0;m.forEach(({l:g,y},p)=>{e.globalAlpha=.7,Kt(e,g,l,k,y,k+s,y),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const f=k+3+P[p]*v,E=Vt(Ue,{x0:f,x1:f+e.measureText(b(g)).width,y0:y-4-c+2,y1:y-4+2},c);if(!o){e.fillText(b(g),f,E.y1-2);return}d.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",St(e,b(g),f,E.y1-2,o.halo),e.restore()})})}else{const m=$.map(v=>{const g=k+a.frac(v.value)*s,y=e.measureText(b(v)).width,p=qn(g,y,k,k+s,v.end==="lo");return{l:v,x:g,side:p,start:p<0?g-3-y:g+3,end:p<0?g-3:g+3+y}}),P=Ht(m,4);m.forEach(({l:v,x:g,side:y,start:p,end:f},E)=>{e.globalAlpha=.7,Kt(e,v,l,g,M,g,M+r),e.globalAlpha=1;const N=y<0?"right":"left";e.fillStyle=l,e.textAlign=N,e.textBaseline="top";const _=M+2+P[E]*c,L=Vt(Ue,{x0:p,x1:f,y0:_,y1:_+c},c);if(!o){e.fillText(b(v),g+y*3,L.y0);return}d.push(()=>{e.save(),e.font=`${te(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=N,e.textBaseline="top",St(e,b(v),g+y*3,L.y0,o.halo),e.restore()})})}return e.restore(),jn(e,w,{left:k,right:k+s,top:M,bottom:M+r},t==="y"?"vertical":"horizontal",l,m=>ee(m,n.unit),void 0,Ue),()=>d.forEach(m=>m())}function yt(e,l,s,r){return _n(Math.max(Math.abs(l),Math.abs(s)),e.unit,r)}function ct(e,l){return l?`${e.label} (${l})`:e.label}const bt=18,xt=(e,l,s)=>{if(e.measureText(l).width<=s)return l;for(let r=l.length-1;r>0;r--){const a=`${l.slice(0,r)}\u2026`;if(e.measureText(a).width<=s)return a}return""};function qe(e,l,s,r,a,u,n,t,o,d,$){Ue=[],e.font=`${te(-1)}px system-ui, sans-serif`;const w=()=>Gn,b=$?{ticks:$.map(g=>g.at),step:0}:t.log?Et(t.lo,t.hi,u,w):ft(t.lo,t.hi,u,w),c=new Map($?.map(g=>[g.at,g.label])),m=yt(d,t.lo,t.hi,b.step||void 0),P=$?{tick:g=>c.get(g)??"",unitLabel:""}:m;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let v="";if("labels"in n){const g=n.labels.length;if(n.labels.forEach((y,p)=>{const f=k+(p+.5)/g*a,E=y.length>22?`${y.slice(0,21)}\u2026`:y;n.rotate?(e.save(),e.translate(f,M+u+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(E,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(E,f,M+u+4))}),n.nest){const y=n.nest[0]?.length??0,p=a/g;for(let f=y-2;f>=0;f--){const E=r-6-bt-f*bt,N=L=>n.nest[L].slice(0,f+1).join("");let _=0;for(let L=1;L<=g;L++){if(L<g&&N(L)===N(_))continue;const A=k+_*p,D=k+L*p;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(xt(e,n.nest[_][f],D-A-4),(A+D)/2,E),L<g&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=f===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(D,M),e.lineTo(D,E-2),e.stroke(),e.restore()),_=L}}e.fillStyle=l.textMuted}}else{const g=jt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),y=n.log?Et(n.lo,n.hi,a,g):ft(n.lo,n.hi,a,g),p=yt(o,n.lo,n.hi,y.step||void 0);v=p.unitLabel;for(const f of y.ticks){const E=k+n.frac(f)*a;e.beginPath(),e.moveTo(E,M),e.lineTo(E,M+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(f),E,M+u+4)}}for(const g of b.ticks){const y=M+(1-t.frac(g))*u;e.beginPath(),e.moveTo(k,y),e.lineTo(k+a,y),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(P.tick(g),k-4,y)}e.font=`${te(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(ct(o,v),k+a/2,r-6),e.save(),e.translate(14,M+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ct(d,P.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,M),e.lineTo(k,M+u),e.moveTo(k,M+u),e.lineTo(k+a,M+u),e.stroke()}function on(e,l,s,r,a,u,n,t,o,d,$,w={along:u,offset:0}){Ue=[],e.font=`${te(-1)}px system-ui, sans-serif`;const b=jt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),$.unit),c=o.log?Et(o.lo,o.hi,a,b):ft(o.lo,o.hi,a,b),m=yt($,o.lo,o.hi,c.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const f of c.ticks){const E=k+o.frac(f)*a;e.beginPath(),e.moveTo(E,M),e.lineTo(E,M+u),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(m.tick(f),E,M+u+4)}const P=n.labels.length,v=w.along/Math.max(1,P),g=M-w.offset;e.save(),e.beginPath(),e.rect(0,M-1,k+a+1,u+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const y=Math.max(0,Math.floor(w.offset/v)),p=Math.min(P,Math.ceil((w.offset+u)/v));for(let f=y;f<p;f++)e.fillText(xt(e,n.labels[f],t.inner),k-6,g+(f+.5)*v);if(n.nest){const f=n.nest[0]?.length??0;let E=k-6-t.inner-10;for(let N=f-2;N>=0;N--){const _=t.outer[N]??0,L=A=>n.nest[A].slice(0,N+1).join("");let C=0;for(let A=1;A<=P;A++){if(A<P&&L(A)===L(C))continue;const D=g+C*v,x=g+A*v;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(xt(e,n.nest[C][N],_),E,(D+x)/2),A<P&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=N===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(E-_,x),e.lineTo(k+a,x),e.stroke(),e.restore()),C=A}E-=_+10}e.fillStyle=l.textMuted}e.restore(),e.font=`${te(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(ct($,m.unitLabel),k+a/2,r-6),e.save(),e.translate(14,M+u/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(ct(d,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(k,M),e.lineTo(k,M+u),e.moveTo(k,M+u),e.lineTo(k+a,M+u),e.stroke()}function ln(){if(!i||!S||i.marks?.type!=="scatter"||!i.x||!i.y)return;Re(S,J??0);const e=_e(I),{w:l,h:s,plotW:r,plotH:a}=We(),u=ze(S,I,l,s);if(!u)return;const{ctx:n}=u,t=i.marks.points,o=W.size===0?t:t.filter(L=>W.has(L.group)),d=i.colorScale,$=dt(),w=Ee(i.x),b=Ee(i.y),c=ue(Ie(Be(t.map(L=>L.x),i.x),w,i.x),i.x),m=ue(Ie(Be(t.map(L=>L.y),i.y),b,i.y),i.y);K={x:c,y:m,plotW:r,plotH:a},qe(n,e,l,s,r,a,c,m,i.x,i.y),Ne(n,e.limitLine,r,a,c,w,i.x,"x"),Ne(n,e.limitLine,r,a,m,b,i.y,"y"),Ve(n,r,a);const P=o.length>Lt?Math.ceil(o.length/Lt):1,v=[];for(let L=0;L<o.length;L+=P)v.push(o[L]);n.globalAlpha=Math.max(.15,Math.min(.7,200/v.length));let g;if(d)g=[v];else{const L=new Map;for(const C of v){const A=L.get(C.group);A?A.push(C):L.set(C.group,[C])}g=[...L.values()].sort((C,A)=>A.length-C.length)}se=[];const y=k,p=k+r,f=M,E=M+a;for(const L of g)for(const C of L){const A=k+c.frac(C.x)*r,D=M+(1-m.frac(C.y))*a;A<y||A>p||D<f||D>E||(se.push({p:C,cx:A,cy:D}),n.beginPath(),n.arc(A,D,2.5,0,Math.PI*2),n.fillStyle=d&&C.value!==void 0?$((C.value-d.lo)/(d.hi-d.lo||1)):oe(C.group),n.fill())}n.globalAlpha=1;const N=i.marks;if(N.type==="scatter"&&(N.identity||N.fits)){const L=(A,D)=>[k+c.frac(A)*r,M+(1-m.frac(D))*a],C=(A,D,x)=>{n.save(),n.beginPath(),n.rect(k,M,r,a),n.clip(),n.strokeStyle=D,n.lineWidth=2,n.setLineDash(x),n.beginPath();for(let ge=0;ge<=60;ge++){const Ce=ge/60,Oe=c.log?10**(Math.log10(c.lo)+(Math.log10(c.hi)-Math.log10(c.lo))*Ce):c.lo+(c.hi-c.lo)*Ce,[we,fe]=L(Oe,A(Oe));ge===0?n.moveTo(we,fe):n.lineTo(we,fe)}n.stroke(),n.restore()};N.identity&&C(A=>A,e.textMuted,[6,4]);for(const A of N.fits??[])W.size>0&&!W.has(A.group)&&!d||C(D=>A.intercept+A.slope*D,d?e.text:oe(A.group),[])}const _=de?se.find(L=>L.p===de):void 0;if(_&&(n.beginPath(),n.arc(_.cx,_.cy,5,0,Math.PI*2),n.lineWidth=2,n.strokeStyle=e.text,n.stroke()),Xe.size>0){n.lineWidth=1.5,n.strokeStyle=e.text;let L=0;for(const C of Xe)if(!(W.size>0&&!W.has(C.group))){if(++L>Lt)break;n.beginPath(),n.arc(k+c.frac(C.x)*r,M+(1-m.frac(C.y))*a,4,0,Math.PI*2),n.stroke()}}}function sn(){if(Ae=void 0,!i||i.marks?.type!=="histogram"||!i.x)return;const e=i.marks.values,l=e.flat();if(l.length===0)return;const s=ue(Ie(Be(l,i.x),Ee(i.x),i.x),i.x),r=Math.max(1,i.spec.bins??Jn),a=s.log?Math.log10(s.lo):s.lo,u=s.log?Math.log10(s.hi):s.hi,n=Array.from({length:r+1},(b,c)=>{const m=a+(u-a)*c/r;return s.log?10**m:m}),t=e.map(()=>new Array(r).fill(0));e.forEach((b,c)=>{for(const m of b){const P=s.log?m>0?Math.log10(m):NaN:m;if(!Number.isFinite(P)||P<a||P>u)continue;const v=Math.min(r-1,Math.floor((P-a)/(u-a)*r));t[c][v]++}});const o=i.spec.histNorm==="percent",d=o?t.map(b=>{const c=b.reduce((m,P)=>m+P,0);return b.map(m=>c?m/c*100:0)}):t;let $=0;const w=e.map(()=>{});if(i.spec.normalCurve&&!s.log){const b=(n[n.length-1]-n[0])/r;e.forEach((c,m)=>{const P=c.filter(Number.isFinite);if(P.length<2)return;const v=P.reduce((y,p)=>y+p,0)/P.length,g=Math.sqrt(An(P,v));g>0&&(w[m]={mean:v,sd:g},$=Math.max($,(o?100:t[m].reduce((y,p)=>y+p,0))*b/(g*Math.sqrt(2*Math.PI))))})}Ae={edges:n,counts:t,heights:d,normal:w,maxCount:Math.max(o?.001:1,$,...d.map(b=>ke(b)))}}function an(){if(!i||!S||!Ae||!i.x||!i.y)return;Re(S,J??0);const e=_e(I),{w:l,h:s,plotW:r,plotH:a}=We(),u=ze(S,I,l,s);if(!u)return;const{ctx:n}=u,{edges:t,counts:o,heights:d,normal:$,maxCount:w}=Ae,b=ue([t[0],t[t.length-1]],{...i.x,min:t[0],max:t[t.length-1]}),c=ue([0,w],{label:i.y.label,scale:"linear",min:0,max:w*1.05});K={x:b,y:c,plotW:r,plotH:a},qe(n,e,l,s,r,a,b,c,i.x,i.y),Ne(n,e.limitLine,r,a,b,Ee(i.x),i.x,"x"),Ve(n,r,a);const m=o.map((v,g)=>g).filter(v=>W.size===0||W.has(v)),P=m.length>1;for(const v of m)n.globalAlpha=P?.55:.85,n.fillStyle=oe(v),d[v].forEach((g,y)=>{if(g===0)return;const p=k+Math.min(b.frac(t[y]),b.frac(t[y+1]))*r,f=k+Math.max(b.frac(t[y]),b.frac(t[y+1]))*r,E=M+(1-c.frac(g))*a;n.fillRect(p,E,Math.max(1,f-p-1),M+a-E)});if(n.globalAlpha=1,i.spec.normalCurve&&!b.log){const v=(t[t.length-1]-t[0])/(t.length-1);for(const g of m){const y=$[g];if(!y)continue;const{mean:p,sd:f}=y,E=(i.spec.histNorm==="percent"?100:o[g].reduce((N,_)=>N+_,0))*v;n.save(),n.beginPath(),n.rect(k,M,r,a),n.clip(),n.strokeStyle=oe(g),n.lineWidth=2,n.beginPath();for(let N=0;N<=120;N++){const _=t[0]+(t[t.length-1]-t[0])*N/120,L=Math.exp(-.5*((_-p)/f)**2)/(f*Math.sqrt(2*Math.PI)),C=k+b.frac(_)*r,A=M+(1-c.frac(E*L))*a;N===0?n.moveTo(C,A):n.lineTo(C,A)}n.stroke(),n.restore()}}if(me>=0){const v=k+Math.min(b.frac(t[me]),b.frac(t[me+1]))*r,g=k+Math.max(b.frac(t[me]),b.frac(t[me+1]))*r;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(v,M,Math.max(1,g-v),a)}}function rn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||!e||e.type!=="box"&&e.type!=="bar")return;Re(S,J??0);const l=_e(I),s=i.spec.orientation==="horizontal",r=e.nest?e.nest.parts.map(T=>T[T.length-1]):e.categories,a=e.categories.length,u=i.groups.length,n=T=>W.size===0||W.has(T),t=e.type==="bar"&&!!e.stack,o=(T,O)=>e.type==="bar"?Number.isFinite(e.values[T][O]):e.cells[T][O].length>0,d=Array.from({length:a},(T,O)=>Array.from({length:u},(F,G)=>G).filter(F=>n(F)&&o(F,O))),$=categoryLayout(t?d.map(T=>T.length?[0]:[]):d),w=S.getContext("2d"),b=T=>w?w.measureText(T).width:T.length*6;w&&(w.font=`${te(-1)}px system-ui, sans-serif`);const c=(T,O)=>T.length>O?`${T.slice(0,O-1)}\u2026`:T;let m=!1,P={inner:0,outer:[]},v=0;if(s){P={inner:Math.min(200,ke(r.map(O=>b(c(O,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((O,F)=>Math.min(140,ke(e.nest.parts.map(G=>b(c(G[F],20)))))):[]},k=Math.max(wt,30+P.inner+6+P.outer.reduce((O,F)=>O+F+10,0)),e.cumulative&&(M=Pt+18),De=Ge;const T=Math.max(1,...d.map(O=>t?Math.min(1,O.length):O.length));v=Math.max(22,T*Zn/.8)}else{const T=ke(r.map(G=>b(c(G,22)))),O=Math.max(10,B.clientWidth-k-mt)/Math.max(1,a);m=T+8>O;const F=e.nest?e.nest.levels.length-1:0;De=(m?Ge+Math.min(110,T*.72):Ge)+F*bt}const g=e.type==="bar"&&!t&&!!i.spec.valueLabels,y=i.y.unit,p=T=>ee(T,y),f=g?ke(e.values.flat().filter(Number.isFinite).map(T=>b(p(T))).concat(0))+8:0,E=s?f:e.cumulative?40:0,{w:N,h:_,plotW:L,plotH:C}=We(),A=Math.max(10,L-E),D=ze(S,I,N,_);if(!D)return;const{ctx:x}=D,ge=T=>T.filter(Number.isFinite),Ce=Ee(i.y),Oe=t?e.categories.map((T,O)=>e.values.reduce((F,G,Y)=>F+(n(Y)&&Number.isFinite(G[O])?G[O]:0),0)):[],we=e.type==="bar"?[...t?Oe:ge(e.values.flat()),0]:ge(e.cells.flat(2));x.font=`${te(-1)}px system-ui, sans-serif`;const fe=s?f:te(-1)+6;if(g&&!s&&we.length){const T=ke(we);T>0&&we.push(T*(1+fe/Math.max(1,C-fe)))}const Pe=ue(Ie(Be(we,i.y),Ce,i.y),i.y,{floorAtZero:e.type==="bar"});K={x:Pe,y:Pe,plotW:A,plotH:C};const ot=s?C:A,Ke=s&&a*v>C+.5,lt=Ke?a*v:ot,st=Ke?Math.max(0,Math.min(tt,lt-ot)):0;tt=st,Mn(Ke,lt,st,A+E,C),s?on(x,l,N,_,A,C,{labels:r,rotate:!1,nest:e.nest?.parts},P,Pe,i.x,i.y,{along:lt,offset:st}):qe(x,l,N,_,A,C,{labels:r,rotate:m,nest:e.nest?.parts},Pe,i.x,i.y);const ye=lt/a,Le=$.width*ye;ne={slotW:ye,n:a,plotW:lt,layout:$,across:s,offset:st,view:ot};const le=T=>s?k+Pe.frac(T)*A:M+(1-Pe.frac(T))*C,be=T=>s?M+T-st:k+T,kt=Pe.log?s?k:M+C:le(0),Ze=(T,O,F,G)=>s?[Math.min(F,G),be(T),Math.max(1,Math.abs(G-F)),O-T]:[be(T),Math.min(F,G),O-T,Math.max(1,Math.abs(G-F))],Tt=(T,O,F,G)=>{x.beginPath(),s?(x.moveTo(O,be(T)),x.lineTo(G,be(F))):(x.moveTo(be(T),O),x.lineTo(be(F),G)),x.stroke()},Qe=T=>s?T>=kt:T<=kt,wn=T=>s?te(-1)<=Le+4:x.measureText(p(T)).width<=Le+6,Nt=g&&e.values.every(T=>T.every(O=>!Number.isFinite(O)||wn(O)));if(Nt){for(let T=0;T<u;T++)if(n(T))for(let O=0;O<a;O++){const F=$.left(O,T),G=e.values[T][O];if(F===void 0||!Number.isFinite(G))continue;const Y=be(O*ye+F*ye+Le/2),H=x.measureText(p(G)).width,X=le(G);s?Ue.push(Qe(X)?{x0:X,x1:X+H+6,y0:Y-fe/2,y1:Y+fe/2}:{x0:X-H-6,x1:X,y0:Y-8,y1:Y+8}):Ue.push(Qe(X)?{x0:Y-H/2,x1:Y+H/2,y0:X-fe,y1:X}:{x0:Y-H/2,x1:Y+H/2,y0:X,y1:X+fe})}}const Pn=Ne(x,l.limitLine,A,C,Pe,Ce,i.y,s?"x":"y",{halo:l.bg}),Ln=Ve(x,A,C,Ke);if(t){ne.stacks=[];for(let T=0;T<a;T++){const O=$.left(T,0),F=[];if(ne.stacks.push(F),O===void 0)continue;let G=0;for(let Y=0;Y<u;Y++){const H=e.values[Y][T];if(!n(Y)||!Number.isFinite(H)||H<=0)continue;const X=le(G),ae=le(G+H);x.fillStyle=oe(Y),x.globalAlpha=.9;const re=T*ye+O*ye;x.fillRect(...Ze(re+1,re+Le-1,X,ae)),x.globalAlpha=1,F.push({g:Y,p0:Math.min(X,ae),p1:Math.max(X,ae)}),G+=H}}}for(let T=0;T<u&&!t;T++){if(W.size>0&&!W.has(T))continue;const O=oe(T);for(let F=0;F<a;F++){const G=$.left(F,T);if(G===void 0)continue;const Y=F*ye+G*ye;if(e.type==="bar"){const H=e.values[T][F];if(!Number.isFinite(H))continue;const X=le(H);if(x.fillStyle=O,x.globalAlpha=.9,x.fillRect(...Ze(Y+1,Y+Le-1,kt,X)),x.globalAlpha=1,Nt){x.fillStyle=l.text,x.font=`${te(-1)}px system-ui, sans-serif`;const ae=be(Y+Le/2);s?(x.textBaseline="middle",x.textAlign=Qe(X)?"left":"right",x.fillText(p(H),X+(Qe(X)?3:-3),ae)):(x.textAlign="center",x.textBaseline=Qe(X)?"bottom":"top",x.fillText(p(H),ae,X+(Qe(X)?-2:2)))}}else{const H=e.cells[T][F];if(H.length===0)continue;const X=Y+Le/2,ae=Math.max(3,Math.min(Le*.7,46)),re=zt(Float64Array.from(H));if(x.strokeStyle=O,x.fillStyle=O,x.lineWidth=1.5,H.length===1){x.beginPath(),s?x.arc(le(re.median),be(X),3,0,Math.PI*2):x.arc(be(X),le(re.median),3,0,Math.PI*2),x.fill();continue}Tt(X,le(re.min),X,le(re.max));for(const Ot of[re.min,re.max])Tt(X-ae/4,le(Ot),X+ae/4,le(Ot));x.globalAlpha=.35,x.fillRect(...Ze(X-ae/2,X+ae/2,le(re.q1),le(re.q3))),x.globalAlpha=1,x.strokeRect(...Ze(X-ae/2,X+ae/2,le(re.q1),le(re.q3))),x.lineWidth=2.5,Tt(X-ae/2,le(re.median),X+ae/2,le(re.median))}}}Ln(),Pn();const Ft=ie?$.left(ie.c,t?0:ie.g):void 0;if(ie&&Ft!==void 0){Ke&&(x.save(),x.beginPath(),x.rect(k-1,M,A+2,C),x.clip()),x.lineWidth=1.5,x.strokeStyle=l.text;const T=ie.c*ye+Ft*ye,O=t?ne.stacks?.[ie.c]?.find(F=>F.g===ie.g):void 0;t&&O?x.strokeRect(...Ze(T,T+Le,O.p0,O.p1)):t||x.strokeRect(...Ze(T,T+Le,s?k:M,s?k+A:M+C)),Ke&&x.restore()}if(e.cumulative){const T=F=>s?k+F/100*A:M+(1-F/100)*C,O=(F,G)=>s?[T(G),be((F+.5)*ye)]:[be((F+.5)*ye),T(G)];if(x.save(),x.strokeStyle=l.text,x.fillStyle=l.text,x.lineWidth=1.5,x.beginPath(),e.cumulative.forEach((F,G)=>{const[Y,H]=O(G,F);G===0?x.moveTo(Y,H):x.lineTo(Y,H)}),x.stroke(),e.cumulative.forEach((F,G)=>{const[Y,H]=O(G,F);x.beginPath(),x.arc(Y,H,2.5,0,Math.PI*2),x.fill()}),x.strokeStyle=l.border,x.lineWidth=1,x.beginPath(),s?(x.moveTo(k,M),x.lineTo(k+A,M)):(x.moveTo(k+A,M),x.lineTo(k+A,M+C)),x.stroke(),x.fillStyle=l.textMuted,x.font=`${te(-1)}px system-ui, sans-serif`,s){x.textAlign="center",x.textBaseline="bottom";for(const F of[0,25,50,75,100])x.fillText(`${F}%`,T(F),M-3)}else{x.textAlign="left",x.textBaseline="middle";for(const F of[0,25,50,75,100])x.fillText(`${F}%`,k+A+4,T(F))}x.restore()}}function cn(e){const l=i?.setTests,s=l?l.labels.indexOf(e):-1;return s>=0?{test:l.tests[s]}:{}}function vt(e){if(!ne||!S)return null;const l=S.getBoundingClientRect(),s=ne.across?e.clientY-l.top-M:e.clientX-l.left-k;if(s<0||s>ne.view)return null;const r=s+ne.offset,a=Math.min(ne.n-1,Math.floor(r/ne.slotW)),u=ne.layout.groupAt(a,(r-a*ne.slotW)/ne.slotW);if(u===void 0)return null;if(!ne.stacks)return{g:u,c:a};const n=ne.across?e.clientX-l.left:e.clientY-l.top,t=ne.stacks[a]?.find(o=>n>=o.p0&&n<=o.p1);return t?{g:t.g,c:a}:null}function fn(e,l,s){let r=0,a=0,u=0;for(const o of l)o===100&&r++;if(e.failSide)for(const o of s){const d=e.failSide[o];d<0?a++:d>0&&u++}const n=o=>o.toLocaleString("en-GB"),t=a+u>0?` (${n(a)} below the low limit \xB7 ${n(u)} above the high limit)`:"";return`${n(r)} pass \xB7 ${n(l.length-r)} fail${t} \xB7 n = ${n(l.length)}`}function un(e){const l=i,s=l.marks,r=l.level==="die"?"dies":"wafers",a=s.cells[e.g][e.c],u=s.nest?s.nest.parts[e.c]:[s.categories[e.c]],n=l.groups.length>1&&!u.includes(je(e.g))?` \xB7 ${U(je(e.g))}`:"",t=`<strong>${U(s.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(a.length===0)return`${t}no ${r}`;const d=`${a.length.toLocaleString("en-GB")} ${r}`,$=(s.categoryItems&&h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")+(s.categoryItems&&h.onWaferMenu?Zt:"");if(s.type==="bar"){const b=s.values[e.g][e.c],c=s.cumulative?`<br>${U(`cumulative: ${s.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${U(`${l.y.label}: ${ee(b,o)}`)}<br>${U(s.passFail?fn(s.passFail,a,s.cellUnits[e.g][e.c]):d)}${c}${$}`}const w=zt(Float64Array.from(a));return`${t}${["max","q3","median","q1","min"].map(b=>U(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[b]}: ${ee(w[b],o)}`)).join("<br>")}<br>${U(d)}${$}`}function hn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||!e||e.type!=="line")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=Ee(i.x),d=Ee(i.y),$=ue(Ie(Be(e.xs,i.x),o,i.x),i.x),w=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],b=ue(Ie(Be([...e.values.flat(),...w].filter(Number.isFinite),i.y),d,i.y),i.y);if(K={x:$,y:b,plotW:a,plotH:u},qe(t,l,s,r,a,u,$,b,i.x,i.y),Ne(t,l.limitLine,a,u,$,o,i.x,"x"),Ne(t,l.limitLine,a,u,b,d,i.y,"y"),Ve(t,a,u),he=e.xs.map(c=>k+$.frac(c)*a),e.band){const c=m=>M+(1-b.frac(m))*u;e.band.lo.forEach((m,P)=>{if(W.size>0&&!W.has(P))return;const v=e.band.hi[P];t.save(),t.fillStyle=oe(P),t.globalAlpha=.16;let g=[];const y=()=>{if(g.length===1){const p=g[0],f=he[p];t.globalAlpha=.55,t.strokeStyle=oe(P),t.lineWidth=2,t.beginPath(),t.moveTo(f,c(m[p])),t.lineTo(f,c(v[p])),t.moveTo(f-4,c(m[p])),t.lineTo(f+4,c(m[p])),t.moveTo(f-4,c(v[p])),t.lineTo(f+4,c(v[p])),t.stroke(),t.globalAlpha=.16}else if(g.length){t.beginPath(),g.forEach((p,f)=>{f===0?t.moveTo(he[p],c(v[p])):t.lineTo(he[p],c(v[p]))});for(let p=g.length-1;p>=0;p--)t.lineTo(he[g[p]],c(m[g[p]]));t.closePath(),t.fill()}g=[]};m.forEach((p,f)=>{Number.isFinite(p)&&Number.isFinite(v[f])?g.push(f):y()}),y(),t.restore()})}e.values.forEach((c,m)=>{if(W.size>0&&!W.has(m))return;t.strokeStyle=oe(m),t.fillStyle=oe(m),t.lineWidth=2;let P=!1;t.beginPath(),c.forEach((v,g)=>{if(!Number.isFinite(v)){P=!1;return}const y=he[g],p=M+(1-b.frac(v))*u;P?t.lineTo(y,p):t.moveTo(y,p),P=!0}),t.stroke(),c.forEach((v,g)=>{Number.isFinite(v)&&(t.beginPath(),t.arc(he[g],M+(1-b.frac(v))*u,Me===g?4.5:3,0,Math.PI*2),t.fill())})}),Me>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(he[Me],M),t.lineTo(he[Me],M+u),t.stroke())}function Mt(e){const l=i?.marks;if(!l||l.type!=="line"||!S||!i?.x||he.length===0)return null;const s=e.clientX-S.getBoundingClientRect().left;let r=-1,a=24;if(he.forEach((t,o)=>{const d=Math.abs(t-s);d<a&&(a=d,r=o)}),Me=r,r<0)return null;const u=i.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[r],n:l.counts[o][r]})).filter(t=>Number.isFinite(t.v)&&(W.size===0||W.has(t.g)));return`<strong>${U(`${i.x.label}: ${ee(l.xs[r],i.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][r],d=l.band?.hi[t.g][r],$=o!==void 0&&d!==void 0&&Number.isFinite(o)&&Number.isFinite(d)?`, band ${ee(o,i.y.unit)} to ${ee(d,i.y.unit)}`:"";return U(`${i.groups.length>1?`${je(t.g)}: `:""}${ee(t.v,i.y.unit)}${$} (${t.n.toLocaleString("en-GB")} ${u})`)}).join("<br>")+(h.onWaferMenu&&Bt(r)!==void 0?Zt:"")}function Bt(e){const l=i?.marks;if(l?.type!=="line")return;const s=new Set(l.cellUnits.flatMap((r,a)=>W.size>0&&!W.has(a)?[]:(r[e]??[]).map(u=>l.unit(u).item)));return s.size===1?[...s][0]:void 0}function dn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="probability")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=i.spec.probabilityAxis==="linear",d=e.values.map((L,C)=>C).filter(L=>e.values[L].length>0&&(W.size===0||W.has(L))),$=Math.max(1,...d.map(L=>e.values[L].length)),w=Math.min(.01,it(0,$)),b=L=>o?L:_t(L),c=o?0:b(w),m=o?1:b(1-w),P=o?0:(m-c)*.03,v=ue([c-P,m+P],{label:i.y.label,scale:"linear",min:c-P,max:m+P}),g=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:eo.filter(L=>L>=w&&L<=1-w),y=[],p=L=>M+(1-v.frac(L))*u,f=g.indexOf(.5);y.push({at:b(.5),label:en(.5)});for(const L of[g.slice(f+1),g.slice(0,f).reverse()]){let C=p(b(.5));for(const A of L){const D=p(b(A));Math.abs(D-C)<16||(y.push({at:b(A),label:en(A)}),C=D)}}const E=Ee(i.x),N=ue(Ie(Be(d.flatMap(L=>[e.values[L][0],e.values[L][e.values[L].length-1]]),i.x),E,i.x),i.x);K={x:N,y:v,plotW:a,plotH:u},qe(t,l,s,r,a,u,N,v,i.x,i.y,y),Ne(t,l.limitLine,a,u,N,E,i.x,"x"),Ve(t,a,u),se=[],t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip();for(const L of d){const C=e.values[L],A=C.length,D=to(A);if(t.strokeStyle=oe(L),t.fillStyle=oe(L),t.lineWidth=1.5,t.beginPath(),D.forEach((x,ge)=>{const Ce=k+N.frac(C[x])*a,Oe=p(b(it(x,A)));ge===0?t.moveTo(Ce,Oe):t.lineTo(Ce,Oe);const we=L*2**26+x;let fe=pt.get(we);if(!fe){const{item:Pe,die:ot}=e.unit(e.units[L][x]);fe={x:C[x],y:it(x,A),group:L,item:Pe,die:ot},pt.set(we,fe)}se.push({p:fe,cx:Ce,cy:Oe})}),t.stroke(),A<=300)for(const x of D)t.beginPath(),t.arc(k+N.frac(C[x])*a,p(b(it(x,A))),2.5,0,Math.PI*2),t.fill()}t.restore();const _=de?se.find(L=>L.p===de):void 0;_&&(t.beginPath(),t.arc(_.cx,_.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function mn(e){const l=i,r=l.marks.values[e.group].length,a=Math.round(e.y*r+.5),u=h.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[u,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${U(t)}</strong><br>`:"")+U(`${l.x.label}: ${ee(e.x,l.x.unit)}`)+"<br>"+U(`rank ${a.toLocaleString("en-GB")} of ${r.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${U(je(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}let Fe,pe=null;function pn(){const e=i?.marks;if(!i||!S||e?.type!=="heatmap")return;Re(S,J??0);const l=_e(I),s=S.getContext("2d");let r=0,a=0;s&&(s.font=`${te(-1)}px system-ui, sans-serif`,r=ke(e.rows.map(p=>s.measureText(p.length>24?`${p.slice(0,23)}\u2026`:p).width)),a=ke(e.cols.map(p=>s.measureText(p.length>22?`${p.slice(0,21)}\u2026`:p).width)));const u=Math.min(180,Math.max(k,r+24)),n=Math.max(8,B.clientWidth-u-mt)/Math.max(1,e.cols.length),t=a+8>n;De=t?Ge+Math.min(110,a*.72):Ge;const{w:o,h:d}=We(),$=Math.max(10,o-u-mt),w=Math.max(10,d-M-De),b=ze(S,I,o,d);if(!b)return;const{ctx:c}=b,m=$/e.cols.length,P=w/e.rows.length;Fe={left:u,cw:m,ch:P,rows:e.rows.length,cols:e.cols.length};const v=i.colorScale,g=dt(),y=v&&v.hi-v.lo||1;c.font=`${te(-1)}px system-ui, sans-serif`;for(let p=0;p<e.rows.length;p++)for(let f=0;f<e.cols.length;f++){const E=e.values[p][f],N=u+f*m,_=M+p*P;c.fillStyle=Number.isFinite(E)&&v?g((E-v.lo)/y):l.track,c.fillRect(N+.5,_+.5,Math.max(1,m-1),Math.max(1,P-1)),Number.isFinite(E)&&m>=40&&P>=16&&(c.fillStyle="#fff",c.textAlign="center",c.textBaseline="middle",St(c,At(E,i.y?.unit,v?.integer),N+m/2,_+P/2,"rgba(0,0,0,0.55)"))}pe&&(c.lineWidth=2,c.strokeStyle=l.text,c.strokeRect(u+pe.c*m,M+pe.r*P,m,P)),c.fillStyle=l.textMuted,c.textAlign="right",c.textBaseline="middle",e.rows.forEach((p,f)=>c.fillText(p.length>24?`${p.slice(0,23)}\u2026`:p,u-6,M+(f+.5)*P)),e.cols.forEach((p,f)=>{const E=p.length>22?`${p.slice(0,21)}\u2026`:p,N=u+(f+.5)*m;t?(c.save(),c.translate(N,M+w+6),c.rotate(-Math.PI/4),c.textAlign="right",c.textBaseline="middle",c.fillText(E,0,0),c.restore()):(c.textAlign="center",c.textBaseline="top",c.fillText(E,N,M+w+4))}),c.font=`${te(0)}px system-ui, sans-serif`,c.fillStyle=l.text,c.textAlign="center",c.textBaseline="bottom",c.fillText(i.x?.label??"",u+$/2,d-6)}function Wt(e){if(!Fe||!S)return null;const l=S.getBoundingClientRect(),s=Math.floor((e.clientX-l.left-Fe.left)/Fe.cw),r=Math.floor((e.clientY-l.top-M)/Fe.ch);return r>=0&&r<Fe.rows&&s>=0&&s<Fe.cols?{r,c:s}:null}function gn(e){const l=i,s=l.marks,r=s.values[e.r][e.c],a=s.cellUnits[e.r][e.c].length,u=l.level==="die"?"dies":"wafers";return`<strong>${U(`${s.rows[e.r]} \xB7 ${s.cols[e.c]}`)}</strong><br>`+(Number.isFinite(r)?U(`${l.y?.label??"Count"}: ${At(r,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+U(`${a.toLocaleString("en-GB")} ${u}`)+(a&&h.onSelectPoints?"<br><em>click to chart or tabulate them</em>":"")}function yn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="control")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=e.limits,d=Ee(i.y),$=ue(Be(e.xs,i.x),i.x),w=ue(Ie(Be([...e.values,o.ucl,o.lcl],i.y),d,i.y),i.y);K={x:$,y:w,plotW:a,plotH:u},qe(t,l,s,r,a,u,$,w,i.x,i.y),Ne(t,l.limitLine,a,u,w,d,i.y,"y"),Ve(t,a,u);const b=y=>k+$.frac(e.xs[y])*a,c=y=>M+(1-w.frac(y))*u;t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip();const m=(y,p,f,E=1)=>{t.globalAlpha=f,t.setLineDash(p),t.lineWidth=E,t.strokeStyle=l.text,t.beginPath(),t.moveTo(k,c(y)),t.lineTo(k+a,c(y)),t.stroke()};for(const y of[-2,-1,1,2])m(o.centre+y*o.sigma,[2,4],.25);m(o.centre,[],.6,1.5),m(o.ucl,[6,4],.85),m(o.lcl,[6,4],.85),t.restore(),t.fillStyle=l.textMuted,t.font=`${te(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const P=y=>ee(y,i.y.unit);if(t.fillText(`UCL ${P(o.ucl)}`,k+a-4,c(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${P(o.lcl)}`,k+a-4,c(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${P(o.centre)}`,k+a-4,c(o.centre)-2),o.baseline<e.values.length){const y=(b(o.baseline-1)+b(o.baseline))/2;t.save(),t.strokeStyle=l.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(y,M),t.lineTo(y,M+u),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",k+4,M+2)}t.strokeStyle=oe(0),t.lineWidth=1.5,t.setLineDash([]),t.beginPath(),e.values.forEach((y,p)=>{p===0?t.moveTo(b(p),c(y)):t.lineTo(b(p),c(y))}),t.stroke();const v=new Map(e.violations.map(y=>[y.index,y.rules]));se=[],e.values.forEach((y,p)=>{const f=v.get(p);t.beginPath(),t.arc(b(p),c(y),f?4.5:3,0,Math.PI*2),t.fillStyle=f?l.alert:oe(0),t.fill(),f&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(f.join(","),b(p),c(y)-6)),se.push({p:{x:e.xs[p],y,group:0,item:e.items[p]},cx:b(p),cy:c(y)})});const g=de?se.find(y=>y.p===de):void 0;g&&(t.beginPath(),t.arc(g.cx,g.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function bn(e){const l=i,s=l.marks,r=s.items.indexOf(e.item),a=(e.y-s.limits.centre)/s.limits.sigma,u=s.violations.find(n=>n.index===r)?.rules;return`<strong>${U(h.waferLabel(e.item))}</strong><br>`+U(`${l.y.label}: ${ee(e.y,l.y.unit)} (${a>=0?"+":"\u2212"}${Math.abs(a).toFixed(1)}\u03C3)`)+(u?`<br>${U(`breaks rule ${u.map(n=>`${n} (${En[n]})`).join(", ")}`)}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}function xn(){const e=i?.marks;if(!i||!S||!i.x||!i.y||e?.type!=="goal")return;Re(S,J??0);const l=_e(I),{w:s,h:r,plotW:a,plotH:u}=We(),n=ze(S,I,s,r);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(f=>Math.abs(f.x))),d=ue([-o,o],{...i.x,min:i.x.min??-o*1.05,max:i.x.max??o*1.05}),$=ue([0,...e.points.map(f=>f.y),1/6],{...i.y,min:i.y.min??0},{floorAtZero:!0});K={x:d,y:$,plotW:a,plotH:u},qe(t,l,s,r,a,u,d,$,i.x,i.y);const w=f=>k+d.frac(f)*a,b=f=>M+(1-$.frac(f))*u;t.save(),t.beginPath(),t.rect(k,M,a,u),t.clip(),t.font=`${te(-1)}px system-ui, sans-serif`;const c=[[1,[6,4]],[1.33,[]]];for(const[f,E]of c){const N=1/(6*f);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(E),t.beginPath(),t.moveTo(w(-.5),b(0)),t.lineTo(w(0),b(N)),t.lineTo(w(.5),b(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${f}`,w(0)+4,b(N)-2)}t.restore(),se=[];const m=e.points.filter(f=>W.size===0||W.has(f.group));for(const f of m)t.beginPath(),t.arc(w(f.x),b(f.y),4,0,Math.PI*2),t.fillStyle=oe(f.group),t.fill(),se.push({p:{x:f.x,y:f.y,group:f.group,item:-1,value:f.testNumber},cx:w(f.x),cy:b(f.y)});const P=m.map(f=>({x0:w(f.x)-5,x1:w(f.x)+5,y0:b(f.y)-5,y1:b(f.y)+5})),v={x0:k,x1:k+a,y0:M,y1:M+u},g=f=>f.x0>=v.x0&&f.x1<=v.x1&&f.y0>=v.y0&&f.y1<=v.y1&&!P.some(E=>f.x0<E.x1&&f.x1>E.x0&&f.y0<E.y1&&f.y1>E.y0),y=te(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const f of[...m].filter(E=>E.ppk<1.33).sort((E,N)=>E.ppk-N.ppk)){const E=w(f.x),N=b(f.y),_=t.measureText(f.label).width,L=[[E+7,N,"left"],[E-7,N,"right"],[E,N-13,"center"],[E,N+13,"center"]];for(const[C,A,D]of L){const x=D==="left"?C:D==="right"?C-_:C-_/2,ge={x0:x,x1:x+_,y0:A-y/2,y1:A+y/2};if(g(ge)){P.push(ge),t.textAlign=D,t.fillText(f.label,C,A);break}}}const p=de?se.find(f=>f.p===de):void 0;p&&(t.beginPath(),t.arc(p.cx,p.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function vn(e){const l=i,r=l.marks.points.find(a=>a.testNumber===e.value&&a.group===e.group);return r?`<strong>${U(r.label)}</strong>${l.groups.length>1?` \xB7 ${U(je(r.group))}`:""}<br>`+U(`Ppk ${r.ppk.toFixed(2)} \xB7 ${r.n.toLocaleString("en-GB")} dies`)+"<br>"+U(`mean ${r.x>=0?"+":"\u2212"}${Math.abs(r.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(r.y*100).toFixed(1)}% of it (${r.basis==="spec"?"spec":"test"} limits)`):""}function Mn(e,l,s,r,a){!$e||!S||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${S.offsetTop+M}px`,height:`${a}px`,left:`${S.offsetLeft+k+r+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-s)>=1&&($e.scrollTop=s)))}function Z(){$e&&($e.style.display="none"),rt&&!tn()&&(rt.style.maxHeight=Yt(I)?"":`${Qn}px`),Q&&h.panel&&(Q.style.display=Yt(I)?"flex":"none"),k=wt,M=Pt;const e=i?.marks?.type;e==="scatter"?ln():e==="control"?yn():e==="heatmap"?pn():e==="goal"?xn():e==="probability"?dn():e==="histogram"?an():e==="box"||e==="bar"?rn():e==="line"&&hn(),Ct()}function kn(e){const l=i,s=h.waferLabel(e.item),r=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",a=[s,r].filter(Boolean).join(" \xB7 "),u=(n,t)=>`${n.label}: ${ee(t,n.unit)}`;return(a?`<strong>${U(a)}</strong><br>`:"")+U(u(l.x,e.x))+"<br>"+U(u(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${U(`${l.colorScale.label}: ${ee(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${U(je(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${U(h.openActionLabel??"open this wafer")}</em>`:"")}function It(e){if(!Ae||!K||!i?.x)return null;const l=S.getBoundingClientRect(),r=(e.clientX-l.left-k)/K.plotW;if(r<0||r>1)return null;const a=K.x.reverse?1-r:r,{edges:u,counts:n}=Ae,t=u.length-1,o=Math.min(t-1,Math.max(0,Math.floor(a*t)));me=o;const d=i.x,$=n.map((w,b)=>({g:b,n:w[o]})).filter(w=>w.n>0&&(W.size===0||W.has(w.g)));return`<strong>${U(`${ee(u[o],d.unit)} to ${ee(u[o+1],d.unit)}`)}</strong><br>`+($.length?$.map(w=>{const b=i.spec.histNorm==="percent"?` (${Ae.heights[w.g][o].toFixed(1)}% of ${i.groups.length>1?"its colour":"them"})`:"";return U(`${i.groups.length>1?`${je(w.g)}: `:""}${w.n.toLocaleString("en-GB")} ${i.level==="die"?"dies":"wafers"}${b}`)}).join("<br>"):"none")}function Tn(e){const l=R.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:xe.md,marginTop:xe.md,marginBottom:xe.xl,fontSize:ut.body,color:Je.label});const s=R.createElement("canvas");s.width=200,s.height=10,Object.assign(s.style,{width:"200px",height:"10px",borderRadius:Wn.control,flex:"0 0 auto"});const r=s.getContext("2d"),a=dt();if(r)for(let d=0;d<200;d++)r.fillStyle=a(d/199),r.fillRect(d,0,1,10);const u=d=>i?.marks?.type==="heatmap"?At(d,e.unit,e.integer):ee(d,e.unit),n=R.createElement("span");n.textContent=u(e.lo);const t=R.createElement("span");t.textContent=u(e.hi);const o=R.createElement("span");return o.textContent=e.label,o.style.color=Je.text,l.append(o,n,s,t),l}const nt=(e,l,s)=>l.map(r=>{const{item:a,die:u}=e(r);return{x:0,y:0,group:s,item:a,die:u}});function Sn(){He?.destroy(),He=void 0,B.innerHTML="",S=void 0,Q=void 0,J=void 0,et=[],de=null,me=-1,se=[],K=void 0,ne=void 0,ie=null,$e=void 0,tt=0,rt=void 0,Fe=void 0,pe=null,he=[],Me=-1,De=Ge,pt=new Map,W.clear(),Xe.clear();for(const n of ce)n.destroy();ce=[],Te(()=>I.querySelector("canvas"));const e=i,l=!!e?.facets&&!h.panel;if(I.style.flex=l?"0 0 auto":"1 1 0px",I.style.gridColumn=l?"1 / -1":"",!e)return;if(j.textContent=h.panel?h.panel.title:Bn(e),I.dataset.wmapChartTitle=j.textContent,e.issues.length||!e.marks){for(const n of e.issues)qt(B,n);return}const s=R.createElement("div");Object.assign(s.style,{color:Je.label,fontSize:ut.body,marginBottom:xe.xs});const r=h.openActionLabel??"open this wafer",a=e.marks.type==="scatter"?(h.onOpenWafer?` \xB7 click a point to ${r}`:"")+(h.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(h.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${r}`:h.onSelectPoints?` \xB7 click to ${h.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&h.onSelectPoints?" \xB7 click a bar to chart or tabulate its dies":e.marks.type==="probability"?(h.onOpenWafer?` \xB7 click a point to ${r}`:"")+(h.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="line"&&h.onSelectPoints?` \xB7 click a point to ${h.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the plot to select ${h.selectRangeLabel??"a run of points"}`:"";s.textContent=h.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:Xt(e)+(e.facets?"":a),h.panel||Nn(s,Ut(e)),Dt(s),J=R.createElement("div"),J.style.display="flow-root",B.appendChild(J),J.appendChild(s);for(const n of e.fitNotes??[]){const t=R.createElement("div");t.dataset.wmapPlotFit="1",t.textContent=n,Object.assign(t.style,{color:Je.text,fontSize:ut.body,marginBottom:xe.xxs,fontVariantNumeric:"tabular-nums"}),J.appendChild(t)}for(const n of e.notes){const t=R.createElement("div");Dt(t),t.textContent=n,Object.assign(t.style,{color:Je.warnText,fontSize:ut.body,marginBottom:xe.xs}),J.appendChild(t)}if(e.plotted===0){qt(B,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&!e.colorRepeatsX&&(Q=R.createElement("div"),Q.dataset.wmapPlotLegend="1",Object.assign(Q.style,{display:h.panel?"none":"flex",flexWrap:"wrap",gap:xe.sm,marginTop:xe.md,marginBottom:xe.xl,overflowY:"auto"}),rt=Q,e.facets&&Object.assign(Q.style,{position:"sticky",top:"0",zIndex:"2",background:Je.menuBg,paddingBottom:xe.sm,marginBottom:xe.md}),e.groups.forEach((n,t)=>{const o=Xn(n||"(none)",oe(t),R),d=h.onLegendPick&&h.legendPicked===n;Rn(o.el,I,z,h.onLegendPick?d?`${n||"(none)"} \u2014 click to show every group again`:`${n||"(none)"} \u2014 click to show only this group in every chart here`:`${n||"(none)"} \u2014 click to filter`),d&&W.add(t),o.el.addEventListener("click",()=>{if(h.onLegendPick){h.onLegendPick(d?null:n);return}if(W.has(t)?W.delete(t):W.add(t),et.forEach(($,w)=>$.setState({selected:W.has(w),dimmed:W.size>0&&!W.has(w)})),ce.length)for(const $ of ce)$.setActiveGroups(W);else Z()}),et.push(o),Q.appendChild(o.el)}),et.forEach((n,t)=>n.setState({selected:W.has(t),dimmed:W.size>0&&!W.has(t)})),J.appendChild(Q)),e.colorScale&&!h.panel&&(Q=Tn(e.colorScale),J.appendChild(Q)),e.facets){const n=R.createElement("div");n.dataset.wmapPlotPanels="1",n.style.isolation="isolate",Object.assign(n.style,{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${no}px, 1fr))`,gap:xe.md}),B.appendChild(n);for(const t of e.facets){const o=renderPlotChart({...h,panel:{title:t.label}});n.appendChild(o.card),o.setPlot(t.plot),ce.push(o)}Te(()=>oo(n));return}S=R.createElement("canvas"),S.style.display="block",S.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",B.appendChild(S);const u=h.onWaferMenu?(n,t)=>{n.die||h.onWaferMenu(n.item,Ye(e.spec),t)}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!h.onSelectPoints;He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:kn,clickable:()=>!!h.onOpenWafer,onOpen:o=>h.onOpenWafer?.(o.item,Ye(e.spec)),onContextMenu:u,onHover:o=>{de=o,Z()},select:t?{pick:({x0:o,y0:d,x1:$,y1:w})=>K?(W.size===0?n.points:n.points.filter(c=>W.has(c.group))).filter(c=>{const m=k+K.x.frac(c.x)*K.plotW,P=M+(1-K.y.frac(c.y))*K.plotH;return m>=o&&m<=$&&P>=d&&P<=w}):[],onPicked:(o,d)=>{Xe.clear();for(const $ of o)Xe.add($);Z(),o.length>0&&h.onSelectPoints(o,d,S)},onClear:()=>{Xe.clear(),Z()},hasSelection:()=>Xe.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const n=e.marks.type==="control";He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:n?bn:vn,clickable:()=>n&&!!h.onOpenWafer,onOpen:t=>{n&&h.onOpenWafer?.(t.item,Ye(e.spec))},onContextMenu:n?u:void 0,onHover:t=>{de=t,Z()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";He=$t({card:I,canvas:S,tooltip:z,drawn:()=>se,describe:mn,clickable:()=>!!h.onOpenWafer,onOpen:o=>h.onOpenWafer?.(o.item,Ye(e.spec)),onHover:o=>{de=o,Z()},select:h.onSelectPoints?{pick:({x0:o,y0:d,x1:$,y1:w})=>{if(!K)return[];const b=[];return n.values.forEach((c,m)=>{W.size>0&&!W.has(m)||c.forEach((P,v)=>{const g=it(v,c.length),y=k+K.x.frac(P)*K.plotW,p=M+(1-K.y.frac(t?g:_t(g)))*K.plotH;if(y<o||y>$||p<d||p>w)return;const{item:f,die:E}=n.unit(n.units[m][v]);b.push({x:P,y:g,group:m,item:f,die:E})})}),b},onPicked:(o,d)=>{o.length>0&&h.onSelectPoints(o,d,S)},onClear:()=>{},hasSelection:()=>!1}:void 0})}else if(e.marks.type==="histogram"){sn(),S.addEventListener("mousemove",t=>{const o=It(t);if(!o){z.style.display="none",me>=0&&(me=-1,Z());return}z.innerHTML=o,z.style.display="block",ht(z,I,t.clientX,t.clientY),Z()}),S.addEventListener("mouseleave",()=>{z.style.display="none",me>=0&&(me=-1,Z())});const n=e.marks;h.onSelectPoints&&(S.style.cursor="pointer",S.addEventListener("click",t=>{if(!Ae||It(t)===null)return;const o=me,{edges:d}=Ae,$=K?.x.log,w=$?Math.log10(d[0]):d[0],b=$?Math.log10(d[d.length-1]):d[d.length-1],c=d.length-1,m=[];n.values.forEach((P,v)=>{if(W.size>0&&!W.has(v))return;const g=[];P.forEach((y,p)=>{const f=$?y>0?Math.log10(y):NaN:y;!Number.isFinite(f)||f<w||f>b||Math.min(c-1,Math.floor((f-w)/(b-w)*c))===o&&g.push(n.units[v][p])}),m.push(...nt(n.unit,g,v))}),m.length>0&&(z.style.display="none",h.onSelectPoints(m,{x:t.clientX,y:t.clientY},S,{range:{lo:d[o],hi:d[o+1]},...W.size===1?{group:e.groups[[...W][0]]}:{}}))}))}else if(e.marks.type==="heatmap"){const n=e.marks;S.addEventListener("mousemove",t=>{const o=Wt(t);if(S.style.cursor=o&&h.onSelectPoints&&n.cellUnits[o.r][o.c].length?"pointer":"default",!o){z.style.display="none",pe&&(pe=null,Z());return}z.innerHTML=gn(o),z.style.display="block",ht(z,I,t.clientX,t.clientY),(!pe||pe.r!==o.r||pe.c!==o.c)&&(pe=o,Z())}),S.addEventListener("mouseleave",()=>{z.style.display="none",pe&&(pe=null,Z())}),S.addEventListener("click",t=>{const o=Wt(t);if(!o||!h.onSelectPoints)return;const d=n.cellUnits[o.r][o.c];d.length&&(z.style.display="none",h.onSelectPoints(nt(n.unit,d,0),{x:t.clientX,y:t.clientY},S))})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const t=R.createElement("div");t.dataset.wmapRowScroll="1",t.tabIndex=0,t.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(t.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const o=R.createElement("div");o.style.width="1px",t.appendChild(o),t.addEventListener("scroll",()=>{Math.abs(t.scrollTop-tt)<1||(tt=t.scrollTop,z.style.display="none",Z())}),S.addEventListener("wheel",d=>{if(t.style.display==="none")return;const $=t.scrollTop;t.scrollTop+=d.deltaMode===1?d.deltaY*16:d.deltaY,t.scrollTop!==$&&d.preventDefault()},{passive:!1}),B.appendChild(t),$e=t}S.addEventListener("mousemove",t=>{const o=vt(t);if(S.style.cursor=o&&(n.categoryItems&&h.onOpenWafer||h.onSelectPoints&&n.cellUnits[o.g][o.c].length>0)?"pointer":"default",!o){z.style.display="none",ie&&(ie=null,Z());return}z.innerHTML=un(o),z.style.display="block",ht(z,I,t.clientX,t.clientY),(!ie||ie.g!==o.g||ie.c!==o.c)&&(ie=o,Z())}),S.addEventListener("mouseleave",()=>{z.style.display="none",ie&&(ie=null,Z())}),h.onWaferMenu&&n.categoryItems&&S.addEventListener("contextmenu",t=>{const o=vt(t),d=o?n.categoryItems[o.c]:void 0;d===void 0||d<0||(z.style.display="none",h.onWaferMenu(d,Ye(e.spec),t))}),S.addEventListener("click",t=>{const o=vt(t);if(!o)return;const d=n.categoryItems?.[o.c];if(d!==void 0&&d>=0&&h.onOpenWafer){h.onOpenWafer(d,Ye(e.spec));return}const $=n.cellUnits[o.g][o.c];$.length>0&&h.onSelectPoints&&(z.style.display="none",h.onSelectPoints(nt(n.unit,$,o.g),{x:t.clientX,y:t.clientY},S,{category:n.categories[o.c],...e.groups.length>1?{group:e.groups[o.g]}:{},...cn(n.categories[o.c])}))})}else if(e.marks.type==="line"){S.addEventListener("mousemove",t=>{const o=Mt(t);if(!o){z.style.display="none",Z();return}z.innerHTML=o,z.style.display="block",ht(z,I,t.clientX,t.clientY),Z()}),S.addEventListener("mouseleave",()=>{z.style.display="none",Me>=0&&(Me=-1,Z())});const n=e.marks;if(h.onWaferMenu&&S.addEventListener("contextmenu",t=>{const o=Mt(t)===null?void 0:Bt(Me);o!==void 0&&(z.style.display="none",h.onWaferMenu(o,Ye(e.spec),t))}),h.onSelectPoints){S.style.cursor="pointer";let t=!1;S.addEventListener("mousedown",o=>{if(o.button!==0)return;t=!1;const d=S.getBoundingClientRect(),$=o.clientX-d.left,w=b=>{R.removeEventListener("mouseup",w);const c=b.clientX-d.left;if(Math.abs(c-$)<4)return;t=!0;const[m,P]=$<c?[$,c]:[c,$],v=he.map((y,p)=>y>=m&&y<=P?p:-1).filter(y=>y>=0),g=n.cellUnits.flatMap((y,p)=>W.size>0&&!W.has(p)?[]:v.flatMap(f=>nt(n.unit,y[f]??[],p)));g.length>0&&(z.style.display="none",h.onSelectPoints(g,{x:b.clientX,y:b.clientY},S))};R.addEventListener("mouseup",w)}),S.addEventListener("click",o=>{if(t){t=!1;return}if(Mt(o)===null||Me<0)return;const d=n.cellUnits.flatMap(($,w)=>W.size>0&&!W.has(w)?[]:nt(n.unit,$[Me]??[],w));d.length>0&&(z.style.display="none",h.onSelectPoints(d,{x:o.clientX,y:o.clientY},S))})}}Z()}V(()=>{const e=i;if(!e||!e.marks)return;const l=dt();return{caption:[Xt(e),...e.fitNotes??[],...e.notes,...Hn(Ut(e))],legend:e.groups.length>1&&!e.colorRepeatsX?e.groups.map((s,r)=>({label:s||"(none)",color:oe(r)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:ee(e.colorScale.lo,e.colorScale.unit),hi:ee(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const $n=Fn(I,()=>Z());return{card:I,actions:q,setPlot(e){i=e,ve(Kn(e.spec)),Sn()},setMenuRows:Se,setActiveGroups(e){W.clear();for(const l of e)W.add(l);et.forEach((l,s)=>l.setState({selected:W.has(s),dimmed:W.size>0&&!W.has(s)})),Z()},destroy(){$n.disconnect(),He?.destroy();for(const e of ce)e.destroy()}}}
|
|
@@ -18,6 +18,8 @@ export interface PointInteractionOptions<P> {
|
|
|
18
18
|
/** Whether a click on this point does anything. */
|
|
19
19
|
clickable: (p: P) => boolean;
|
|
20
20
|
onOpen?: (p: P) => void;
|
|
21
|
+
/** A right-click on a point (a wafer's own point opens the wafer's menu). Absent = the browser's menu. */
|
|
22
|
+
onContextMenu?: (p: P, e: MouseEvent) => void;
|
|
21
23
|
/** The point under the pointer changed (null when it left all points): redraw. */
|
|
22
24
|
onHover: (p: P | null) => void;
|
|
23
25
|
/** Present to enable drag-to-select. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CLR as E}from"../toolbar.js";import{positionChartTooltip as L}from"./chartShell.js";const
|
|
1
|
+
import{CLR as E}from"../toolbar.js";import{positionChartTooltip as L}from"./chartShell.js";const g=7,C=4;export function wirePointInteractions(n){const{card:u,canvas:s,tooltip:c}=n;let d=null;const b=t=>{if(n.locate)return n.locate(t);const e=s.getBoundingClientRect(),l=t.clientX-e.left,r=t.clientY-e.top;let p=null,i=g*g;for(const o of n.drawn()){const a=o.cx-l,y=o.cy-r,h=a*a+y*y;h<=i&&(i=h,p=o.p)}return p};s.addEventListener("mousemove",t=>{const e=b(t);if(s.style.cursor=e&&n.clickable(e)?"pointer":"crosshair",!e){c.style.display="none",d&&(d=null,n.onHover(null));return}c.innerHTML=n.describe(e),c.style.display="block",L(c,u,t.clientX,t.clientY),d!==e&&(d=e,n.onHover(e))}),s.addEventListener("mouseleave",()=>{c.style.display="none",d&&(d=null,n.onHover(null))});let x=!1;const m=u.ownerDocument.createElement("div");Object.assign(m.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"40",boxSizing:"border-box",border:`1px dashed ${E.iconActive}`,background:"rgba(120,150,200,0.15)"}),u.appendChild(m);const f=n.select;return f&&s.addEventListener("mousedown",t=>{if(t.button!==0)return;x=!1;const e=s.getBoundingClientRect(),l=t.clientX-e.left,r=t.clientY-e.top;let p=!1,i=l,o=r;const a=u.ownerDocument,y=v=>{if(i=Math.min(Math.max(v.clientX-e.left,0),e.width),o=Math.min(Math.max(v.clientY-e.top,0),e.height),!p&&Math.hypot(i-l,o-r)<C)return;p=!0,c.style.display="none";const M=u.getBoundingClientRect();Object.assign(m.style,{display:"block",left:`${e.left-M.left+Math.min(l,i)}px`,top:`${e.top-M.top+Math.min(r,o)}px`,width:`${Math.abs(i-l)}px`,height:`${Math.abs(o-r)}px`})},h=v=>{a.removeEventListener("mousemove",y),a.removeEventListener("mouseup",h),m.style.display="none",p&&(x=!0,f.onPicked(f.pick({x0:Math.min(l,i),y0:Math.min(r,o),x1:Math.max(l,i),y1:Math.max(r,o)}),{x:v.clientX,y:v.clientY}))};a.addEventListener("mousemove",y),a.addEventListener("mouseup",h)}),s.addEventListener("click",t=>{if(x){x=!1;return}const e=b(t);if(!e){f?.hasSelection()&&f.onClear();return}n.clickable(e)&&n.onOpen?.(e)}),n.onContextMenu&&s.addEventListener("contextmenu",t=>{const e=b(t);e&&(c.style.display="none",n.onContextMenu(e,t))}),{destroy:()=>m.remove()}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseRegionKey as D,parseReticleCellKey as
|
|
1
|
+
import{parseRegionKey as D,parseReticleCellKey as H}from"../../stats/regions.js";import{yieldFill as _}from"./palette.js";import{fontPx as L}from"../toolbar.js";import{escHtml as K}from"../../core/utils.js";import{makeTooltip as Q,positionChartTooltip as Z,cardShell as U,resolveChartCanvasColors as z,observeResize as J,growCardToFitContent as V,setChartGrow as x,isExpandedCard as ee,bodyRoom as te,renderEmptyState as ne,prepareCanvas as oe}from"./chartShell.js";import{cardAbout as le}from"./cardAbout.js";const N=320,ie=220,Y={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function B(e,l,o,m,M,i){e.beginPath(),e.moveTo(l+i,o),e.arcTo(l+m,o,l+m,o+M,i),e.arcTo(l+m,o+M,l,o+M,i),e.arcTo(l,o+M,l,o,i),e.arcTo(l,o,l+m,o,i),e.closePath()}function A(e,l,o,m,M,i){e.font=`${L(-1)}px system-ui, sans-serif`;const p=e.measureText(m).width;e.font="700 11px system-ui, sans-serif";const E=e.measureText(M).width,R=Math.max(p,E)+12,y=30;e.fillStyle=i.bg,B(e,l-R/2,o-y/2,R,y,4),e.fill(),e.strokeStyle=i.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=i.textMuted,e.font=`${L(-1)}px system-ui, sans-serif`,e.fillText(m,l,o-7),e.fillStyle=i.text,e.font="700 11px system-ui, sans-serif",e.fillText(M,l,o+7)}function re(e,l,o,m,M){e.font="700 11px system-ui, sans-serif";const i=e.measureText(m).width+8;e.fillStyle=M.bg,B(e,l-i/2,o-8,i,16,3),e.fill(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=M.text,e.fillText(m,l,o+.5)}export function renderRegionYieldDiagram(e){const{mode:l,rows:o,onSaveImage:m}=e,M=e.title??(l==="ring"?"Ring yield":l==="quadrant"?"Quadrant yield":"Reticle cell yield"),{card:i,body:p,setAbout:E}=U(M,m,e.ownerDocument);E(le(l==="ring"?"ring-yield":l==="quadrant"?"quadrant-yield":"reticle-yield")),x(i,"square");const R=o.length>0;if(!R)return ne(p,"No bin data available for regional yield."),{card:i,hasData:R,destroy:()=>{}};Object.assign(p.style,{display:"flex",justifyContent:"center",alignItems:"center"});const y=i.ownerDocument.createElement("canvas");Object.assign(y.style,{display:"block",flex:"none"}),p.appendChild(y);let C={cx:0,cy:0,R:0};const W=new Map;let S=0,P=0;if(l==="reticleCell"){for(const n of o){const r=H(n.key);r&&(W.set(`${r.column},${r.row}`,n),S=Math.max(S,r.column+1),P=Math.max(P,r.row+1))}S=Math.max(S,e.grid?.width??0),P=Math.max(P,e.grid?.height??0)}let k={x0:0,y0:0,side:0};const T=Q(i);function O(n,r,c,t){const a=Math.max(4,Math.floor(Math.min((r-40)/S,(r-40)/P))),f=Math.round((r-a*S)/2),s=Math.round((r-a*P)/2);k={x0:f,y0:s,side:a};for(let I=0;I<P;I++)for(let u=0;u<S;u++){const h=f+u*a,d=s+(P-1-I)*a,g=W.get(`${u},${I}`);n.fillStyle=g?t(g.yieldPercent):c.bg,n.fillRect(h,d,a,a),n.strokeStyle=c.border,n.lineWidth=1,n.strokeRect(h+.5,d+.5,a-1,a-1),!(!g||a<30)&&(a>=54?A(n,h+a/2,d+a/2,`(${u}, ${I})`,`${g.yieldPercent.toFixed(1)}%`,c):re(n,h+a/2,d+a/2,`${g.yieldPercent.toFixed(0)}%`,c))}n.strokeStyle=c.text,n.lineWidth=1.5,n.strokeRect(f+.5,s+.5,a*S-1,a*P-1)}function F(){const n=Math.max(ie,Math.min(p.clientWidth||N,N));V(i,p,n);const r=ee(i)?Math.max(n,Math.floor(Math.min(p.clientWidth,te(i,p,y)))):n,c=oe(y,i,r,r);if(!c)return;const{ctx:t}=c,b=z(i),a=_;if(l==="reticleCell"){O(t,r,b,a);return}const f=r/2,s=r/2,u=r/2-34;if(C={cx:f,cy:s,R:u},l==="ring"){const h=o.length;for(let d=0;d<h;d++){const g=d/h*u,w=(d+1)/h*u;t.beginPath(),t.arc(f,s,w,0,2*Math.PI),t.arc(f,s,g,0,2*Math.PI,!0),t.closePath(),t.fillStyle=a(o[d].yieldPercent),t.fill(),t.strokeStyle=b.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(f,s,u,0,2*Math.PI),t.strokeStyle=b.text,t.lineWidth=1.5,t.stroke();for(let d=0;d<h;d++){const g=(d+.5)/h*u,w=-Math.PI/2+d/h*2*Math.PI,$=f+Math.cos(w)*g,v=s+Math.sin(w)*g;A(t,$,v,o[d].label,`${o[d].yieldPercent.toFixed(1)}%`,b)}}else{for(const h of o){const d=D(h.key).quadrant,g=d?Y[d]:void 0;if(!g)continue;const[w,$]=g;t.beginPath(),t.moveTo(f,s),t.arc(f,s,u,w,$),t.closePath(),t.fillStyle=a(h.yieldPercent),t.fill(),t.strokeStyle=b.border,t.lineWidth=1,t.stroke();const v=(w+$)/2,j=f+Math.cos(v)*u*.6,G=s+Math.sin(v)*u*.6;A(t,j,G,h.label,`${h.yieldPercent.toFixed(1)}%`,b)}t.beginPath(),t.arc(f,s,u,0,2*Math.PI),t.strokeStyle=b.text,t.lineWidth=1.5,t.stroke()}}function q(n,r){if(l==="reticleCell"){const f=Math.floor((n-k.x0)/k.side),s=Math.floor((r-k.y0)/k.side);return k.side<=0||f<0||f>=S||s<0||s>=P?null:W.get(`${f},${P-1-s}`)??null}const c=n-C.cx,t=r-C.cy,b=Math.hypot(c,t);if(!(b<=C.R))return null;if(l==="ring")return o[Math.min(o.length-1,Math.floor(b/C.R*o.length))]??null;const a=(Math.atan2(t,c)+2*Math.PI)%(2*Math.PI);return o.find(f=>{const s=Y[D(f.key).quadrant??""];return!!s&&a>=s[0]&&a<s[1]})??null}y.addEventListener("mousemove",n=>{const r=y.getBoundingClientRect(),c=q(n.clientX-r.left,n.clientY-r.top);if(!c){T.style.display="none";return}T.innerHTML=`<strong>${K(c.label)}</strong><br>${c.yieldPercent.toFixed(1)}% yield (${c.passDies} of ${c.n} dies)`+(e.onSelectRegion?"<br><em>click to chart or tabulate these dies</em>":""),T.style.display="block",Z(T,i,n.clientX,n.clientY)}),y.addEventListener("mouseleave",()=>{T.style.display="none"}),e.onSelectRegion&&(y.style.cursor="pointer",y.addEventListener("click",n=>{const r=y.getBoundingClientRect(),c=q(n.clientX-r.left,n.clientY-r.top);c&&e.onSelectRegion(c,n)}));const X=J(i,()=>F());return F(),{card:i,hasData:R,destroy:()=>X.disconnect()}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildSweepData as
|
|
1
|
+
import{buildSweepData as ue,sweepAppliesTo as he}from"../../stats/sweep.js";import{fmt as N}from"../../renderer/fmt.js";import{SPACE as oe,fontPx as me,FONT as ie,CLR as Y,ALPHA as xe}from"../toolbar.js";import{categorical as ge}from"./palette.js";import{cardShell as be,observeResize as ye,makeTooltip as $e,positionChartTooltip as Te,renderEmptyState as re,chartFillHeight as ve,populationPhrase as Se,PADDING as J,prepareCanvas as Me,makeAxisFormat as we,VERTICAL_TICK_SPACING_PX as Le}from"./chartShell.js";import{fitTicks as Pe}from"../../renderer/axisTicks.js";import{escHtml as m}from"../../core/utils.js";import{unmarkedLabel as ke,derivedTestNote as Ae,DERIVED_MARK as Q,DERIVED_KEY as Ce}from"../../renderer/testLabel.js";import{plotAbout as Ee}from"./cardAbout.js";function O(c,x){return x?N(c,x).replace(/(\.\d*?)0+(?=\D|$)/,"$1").replace(/\.(?=\D|$)/,""):Number.isInteger(c)?String(c):String(Number(c.toPrecision(3)))}function Ie(c){const x=ke(c.label),E=x.length>9?`${x.slice(0,8)}\u2026`:x;return c.derived?`${Q} ${E}`:E}const le=260,Ne=62,De=56,He=3;function Be(c,x){const E=c.series[0]?.points[0]?.testNumber;return E===void 0?void 0:x?.find(j=>j.testNumber===E)?.unit}export function renderSweepPanel(c){const{testDefs:x,onSaveImage:E,population:j}=c;let $=c.spec,z=c.dies;const{card:g,body:w,heading:ae,controlsRow:ce,setAbout:fe}=be($.title,E,c.ownerDocument);fe(Ee({id:$.id,chart:"sweep"})),g.style.alignSelf="start";const V=g.ownerDocument,D=V.createElement("div");D.dataset.wmapCaption="1",Object.assign(D.style,{color:Y.label,fontSize:ie.body,marginBottom:oe.sm}),g.insertBefore(D,w);const W=V.createElement("div");Object.assign(W.style,{color:Y.label,fontSize:ie.body,marginTop:oe.sm}),g.appendChild(W);const L=$e(g);let F=null,M=null,T;const R=n=>$.series[n]?.color??ge(n);function K(){if(w.innerHTML="",W.innerHTML="",F?.disconnect(),F=null,$.series.length===0){D.textContent="",re(w,"This sweep defines no series.");return}if(M=ue(z,x,$),T=Be(M,x),M.series.filter(s=>s.points.some(d=>d.count>0)).length===0){D.textContent="",re(w,he($,x)?"No values recorded for the tests in this sweep.":"None of this sweep\u2019s tests are in this data \u2014 it may belong to another test program."),Z();return}D.textContent=`Line = median across ${Se(M.dieCount,z.length,j)}, band = p10\u2013p90`+($.series.length>2?" \xB7 crossing and separation measured between the first two series":"")+(c.onSelectPoint?" \xB7 click a level to chart or tabulate the dies measured there":"");const l=V.createElement("canvas");l.style.display="block",w.appendChild(l);let i=null;const P=()=>{const s=M;if(s===null)return;const d=Math.max(1,w.clientWidth),b=Math.max(le,ve(g,w,l,le)),y=Me(l,g,d,b);if(!y)return;const{ctx:e,theme:f}=y,v=t=>s.xScale==="log"?Math.log10(t):t;let a=1/0,o=-1/0,u=1/0,h=-1/0;for(const t of s.series)for(const r of t.points)r.count!==0&&(a=Math.min(a,r.p10),o=Math.max(o,r.p90),u=Math.min(u,v(r.x)),h=Math.max(h,v(r.x)));for(const t of s.separations)a=Math.min(a,t.y),o=Math.max(o,t.y);if(!Number.isFinite(a)||!Number.isFinite(o))return;a===o&&(a-=1,o+=1);const ee=(o-a)*.08;if(a-=ee,o+=ee,u===h&&(u-=.5,h+=.5),s.xScale==="log"){const t=(h-u)*.03;u-=t,h+=t}e.font=`${me(-1)}px system-ui, sans-serif`;const S=J+Ne,H=d-J-8,X=J,k=b-De,A=t=>k-(t-a)/(o-a)*(k-X),B=t=>S+(v(t)-u)/(h-u)*(H-S);i={left:S,right:H,xLo:u,xHi:h,yOf:A,ax:v},e.strokeStyle=f.border,e.lineWidth=1,e.beginPath(),e.moveTo(S,X),e.lineTo(S,k),e.lineTo(H,k),e.stroke(),e.fillStyle=f.text,e.textAlign="right",e.textBaseline="middle";const te=Pe(a,o,k-X,()=>Le),pe=we(Math.max(Math.abs(a),Math.abs(o)),T,te.step||void 0);for(const t of te.ticks)e.fillText(pe.tickWithUnit(t),S-6,A(t));for(const t of s.separations){const r=A(t.y);e.save(),e.strokeStyle=f.limitLine,e.globalAlpha=.55,e.setLineDash([4,3]),e.beginPath(),e.moveTo(S,r),e.lineTo(H,r),e.stroke(),e.restore()}if(s.series.forEach((t,r)=>{const C=t.points.filter(p=>p.count>0);if(!(C.length<2)){e.save(),e.fillStyle=R(r),e.globalAlpha=.14,e.beginPath(),C.forEach((p,I)=>{const _=B(p.x),se=A(p.p90);I===0?e.moveTo(_,se):e.lineTo(_,se)});for(let p=C.length-1;p>=0;p--){const I=C[p];e.lineTo(B(I.x),A(I.p10))}e.closePath(),e.fill(),e.restore()}}),s.series.forEach((t,r)=>{e.strokeStyle=R(r),e.lineWidth=1.75,e.beginPath();let C=!1;for(const p of t.points){if(p.count===0){C=!1;continue}const I=B(p.x),_=A(p.median);C?e.lineTo(I,_):e.moveTo(I,_),C=!0}e.stroke(),e.fillStyle=R(r);for(const p of t.points)p.count!==0&&(e.beginPath(),e.arc(B(p.x),A(p.median),He,0,Math.PI*2),e.fill())}),s.crossing){const t=B(s.crossing.x),r=A(s.crossing.y);e.save(),e.strokeStyle=f.text,e.globalAlpha=.45,e.setLineDash([3,3]),e.beginPath(),e.moveTo(t,r),e.lineTo(t,k),e.stroke(),e.restore(),e.save(),e.strokeStyle=f.text,e.lineWidth=2,e.beginPath(),e.arc(t,r,5.5,0,Math.PI*2),e.stroke(),e.restore()}e.fillStyle=f.text,e.textBaseline="top",e.textAlign="center";const G=s.xIsPhysical?[...new Set(s.series.flatMap(t=>t.points.map(r=>r.x)))].sort((t,r)=>t-r).map(t=>({x:t,label:O(t,s.xUnit)})):(s.series[0]?.points??[]).map(t=>({x:t.x,label:Ie(t)})),de=Math.max(1,Math.ceil(G.length*46/Math.max(1,H-S)));G.forEach((t,r)=>{r%de!==0&&r!==G.length-1||e.fillText(t.label,B(t.x),k+6)}),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.textAlign="center",e.textBaseline="bottom",e.fillText(s.xLabel,(S+H)/2,b-4),e.restore(),e.save(),e.fillStyle=f.text,e.globalAlpha=.75,e.translate(12,(X+k)/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(s.yLabel+(T?` (${T})`:""),0,0),e.restore(),e.textAlign="left",e.textBaseline="middle";let U=S+4;const ne=X+8;s.series.forEach((t,r)=>{e.fillStyle=R(r),e.fillRect(U,ne-4,10,3),U+=14,e.fillStyle=f.text,e.fillText(t.label,U,ne),U+=e.measureText(t.label).width+16})};P(),F=ye(w,P);const q=s=>{const d=M;if(d===null||i===null)return null;const b=s.clientX-l.getBoundingClientRect().left,y=i.xLo+(b-i.left)/Math.max(1,i.right-i.left)*(i.xHi-i.xLo);let e=null;for(const f of d.series)for(const v of f.points){if(v.count===0)continue;const a=Math.abs(i.ax(v.x)-y);(e===null||a<e.dist)&&(e={x:v.x,dist:a})}return e===null?null:e.x};l.addEventListener("mousemove",s=>{const d=M,b=q(s);if(d===null||b===null){L.style.display="none";return}const y={x:b},e=d.series.map(o=>o.points.find(u=>u.x===y.x&&u.count>0)),f=d.series.map((o,u)=>{const h=e[u];return h===void 0?"":`<span style="color:${R(u)}">\u25A0</span> ${h.derived?`${Q} `:""}${m(o.label)}: <strong>${m(N(h.median,T))}</strong><br><span style="opacity:${xe.muted}">p10 ${m(N(h.p10,T))} \u2013 p90 ${m(N(h.p90,T))} \xB7 n=${h.count.toLocaleString()}</span>`}).filter(Boolean);if(f.length===0){L.style.display="none";return}const v=d.series.flatMap(o=>o.points).find(o=>o.x===y.x&&o.count>0),a=[...new Set(e.map(o=>Ae(o)).filter(o=>o!==void 0))];L.innerHTML=`<strong>${m(v?.label??"")}</strong><br>`+f.join("<br>")+a.map(o=>`<br><em>${m(o)}</em>`).join(""),L.style.display="block",Te(L,g,s.clientX,s.clientY)}),l.addEventListener("mouseleave",()=>{L.style.display="none"}),c.onSelectPoint&&(l.style.cursor="pointer",l.addEventListener("click",s=>{const d=M,b=q(s);if(d===null||b===null)return;const y=d.series.flatMap(e=>e.points.filter(f=>f.x===b&&f.count>0));y.length!==0&&(L.style.display="none",c.onSelectPoint({testNumbers:y.map(e=>e.testNumber),label:y[0].label},s))})),Z()}function Z(){const n=M;if(n===null)return;const l=[];n.notMeasured!==void 0?l.push(`<strong>Crossing and widths:</strong> not measured \u2014 ${m(n.notMeasured)}`):n.crossing?l.push(`<strong>Crossing:</strong> ${m(`${n.xLabel} = ${O(n.crossing.x,n.xUnit)}`)} \xB7 ${m(`${n.yLabel} ${N(n.crossing.y,T)}`)}`+(n.crossing.multiple?" <em>(first of several \u2014 the curves cross more than once)</em>":"")):($.crossing??!0)&&$.series.length>=2&&l.push("<strong>Crossing:</strong> the first two series do not cross over the swept range");for(const i of n.separations)if(i.distance!==null){const P=i.ratio!==void 0&&i.from!==void 0&&i.to!==void 0?`\xD7${Number(i.ratio.toPrecision(3))} on the ${n.xLabel} axis (${O(i.from,n.xUnit)} \u2192 ${O(i.to,n.xUnit)})`:`${O(i.distance,n.xUnit)} on the ${n.xLabel} axis`;l.push(`<strong>Width at ${m(N(i.y,T))}:</strong> ${m(P)}`)}else{const P=i.reason==="second-series-never-reaches"?n.series[1]?.label:n.series[0]?.label;l.push(`<strong>Width at ${m(N(i.y,T))}:</strong> not measurable \u2014 ${m(P??"a series")} never reaches this level`)}n.series.some(i=>i.points.some(P=>P.derived))&&l.push(`${Q} ${m(Ce)} \u2014 hover a point for the expression`);for(const i of n.warnings)l.push(`<span style="color:${Y.errText}">${m(i)}</span>`);W.innerHTML=l.join("<br>")}return K(),{card:g,destroy:()=>{F?.disconnect(),L.remove(),g.remove()},setDies:n=>{z=n,K()},setSpec:n=>{$=n,ae.textContent=n.title,g.dataset.wmapChartTitle=n.title,K()},actions:ce}}
|
|
@@ -13,6 +13,8 @@ export interface DataItem {
|
|
|
13
13
|
dies: Die[];
|
|
14
14
|
waferIndex: number;
|
|
15
15
|
wafer?: Wafer;
|
|
16
|
+
/** Every die of the wafer, when `dies` is a part of it: PAT limits are set from the whole wafer. Absent = `dies` is the wafer. */
|
|
17
|
+
allDies?: Die[];
|
|
16
18
|
/** The wafer's own pass bins: the Wafers view's yield judges by them. */
|
|
17
19
|
passBins: readonly number[];
|
|
18
20
|
statsSummary?: InsightsItem['statsSummary'];
|
|
@@ -86,6 +88,7 @@ export interface DataTablesInput {
|
|
|
86
88
|
items: ReadonlyArray<{
|
|
87
89
|
label: string;
|
|
88
90
|
dies: Die[];
|
|
91
|
+
allDies?: Die[];
|
|
89
92
|
waferIndex?: number;
|
|
90
93
|
wafer?: Wafer;
|
|
91
94
|
passBins: readonly number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isYieldEligibleDie as O}from"../core/dies.js";import{testValue as W}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as z}from"../stats/facets.js";import{tableToTsv as A}from"../core/tableCsv.js";import{commonMetadata as H}from"../stats/facets.js";import{buildYieldData as Y}from"../stats/yield.js";import{isParametricTest as E}from"../renderer/buildWaferMap.js";import{fmt as G}from"../renderer/fmt.js";import{testLabel as N}from"../renderer/testLabel.js";import{resolveDieColumns as U}from"./dieList.js";import{createVirtualTable as R}from"./virtualTable.js";import{exportCsv as $}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as V,SPACE as C,controlStyle as K,wireControlHover as j,wireTooltip as T}from"./toolbar.js";import{buildTestSection as q,buildFunctionalTestSection as X}from"./summaryPanel.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,i,s=i+"s")=>`${e.toLocaleString()} ${e===1?i:s}`;export function renderDataSection(e){const{doc:i}=e,s=i.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=i.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),s.appendChild(c);const p=i.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),s.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),l=F(i,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(l.el);let d;switch(e.view){case"dies":d=Q(e);break;case"wafers":d=Z(e);break;default:d=J(e)}let u=()=>{};if(e.view==="dies"){const f=F(i,"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),d.actions?.setLayout?.(t),u()});T(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 r=i.createElement("span");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const o=i.createElement("span");o.textContent="Export format:",Object.assign(o.style,{color:y.label,fontSize:L.body}),r.append(o,f.el),c.appendChild(r)}if(d.actions){const f=d.actions,r=i.createElement("div");r.style.flex="1",c.appendChild(r);const o=B(i,"Export CSV");o.dataset.wmapDataExport="1",o.addEventListener("click",()=>{if(o.disabled)return;const m=o.textContent,h=f.exportCsv();h&&(o.disabled=!0,o.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=m}))});const t=B(i,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(T(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=i.defaultView?.navigator?.clipboard;if(!h)return;const w=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",i.defaultView?.setTimeout(()=>{t.textContent=w},1500)}).catch(()=>{})})):(t.disabled=!0,T(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,o);const a=i.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}),s.insertBefore(a,p)}return p.appendChild(d.el),{card:s,destroy:()=>d.destroy()}}function J(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.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 l of g){if(p){const u=i.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${l.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),s.appendChild(u)}const d=e.buildStatistics(l.items);c.push(d.destroy);for(const u of d.cards)s.appendChild(u)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:y.label,fontSize:L.body})),{el:s,destroy:()=>{for(const l of c)l()}}}function Q(e){const{doc:i,items:s}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,l=[];let d=!1;for(const n of s){n.wafer&&(d=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),l.push(b)}if(l.length===0)return M(i,"No dies to show.");const{columns:u,visibleColumns:f}=U(l,e.allTestDefs,{...e.dieListOptions,metadataFields:e.metadataFields,extraColumn:s.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:d?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:s.some(n=>n.wafer)?H(s.map(n=>({metadata:n.wafer?.metadata}))):void 0,ownerDocument:i}),r=f.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&E(n.test),...n.test!==void 0&&E(n.test)?{sortKey:b=>W(b,n.test.testNumber)}:{}})),o=R({columns:r,rows:l,ariaLabel:`Dies (${l.length})`,ownerDocument:i,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});o.el.style.maxHeight="70vh",o.el.style.minHeight="240px";const t=e.population?`-${e.population.fileTag}`:"",a=u.filter(n=>n.test!==void 0),m=u.filter(n=>n.test===void 0),h=l.length*u.length,w=l.length*a.length,x=()=>u.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),v=()=>[...m.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>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*_(){for(const n of o.orderedRows())for(const b of a){const S=(b.csvGet??b.get)(n);S===""||S===void 0||S===null||(yield{die:n,test:b.test,value:S})}}let k=e.diesLayout==="long"&&a.length>0;const P=()=>k?`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(l.length,"row")} \xD7 ${D(u.length,"column")}`+(l.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:o.el,destroy:()=>o.destroy(),actions:{note:()=>`${D(l.length,"die")} ${e.population?.phrase??`on ${D(s.length,"wafer")}`}. ${P()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{k=n==="long"&&a.length>0},exportCsv:()=>k?$(v(),_(),`die-list-long${t}.csv`,e.onSaveText,{rowCount:w}):$(x(),o.orderedRows(),`die-list${t}.csv`,e.onSaveText,{rowCount:l.length}),copyText:h<=COPY_CELL_LIMIT?()=>A(x(),o.orderedRows()):null}}}function Z(e){const{doc:i,items:s}=e;if(s.length===0)return M(i,"No wafers to show.");const c=s.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=Y([{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),l=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(x=>x.testNumber===a.testNumber);if(m)return m.mean;let h=0,w=0;for(const x of t.item.dies){if(!O(x))continue;const v=W(x,a.testNumber);v!==void 0&&Number.isFinite(v)&&(h++,w+=v)}return h?w/h:void 0},d=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:z(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=>O(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:`${N(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>l(a,t),show:a=>{const m=l(a,t);return m===void 0?"":G(m,t.unit)},numeric:!0}))],u=d.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=R({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:i,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 r=()=>d.map(t=>({header:t.header,get:t.cell})),o=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")}.${o}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>$(r(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*d.length<=COPY_CELL_LIMIT?()=>A(r(),f.orderedRows()):null}}}function M(e,i){const s=e.createElement("div");return s.textContent=i,Object.assign(s.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:s,destroy:()=>{}}}function B(e,i){const s=e.createElement("button");return s.type="button",s.textContent=i,Object.assign(s.style,{fontSize:L.body,padding:"3px 10px",borderRadius:V.control,...K("outlined"),background:y.menuBg}),j(s),s}function F(e,i,s,c,p,g){const l=e.createElement("div");l.setAttribute("role","radiogroup"),l.setAttribute("aria-label",i),Object.assign(l.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:V.control,overflow:"hidden"});const d=[];let u=c;const f=()=>{for(const r of d){const o=r.dataset[p]===u;r.setAttribute("aria-checked",String(o)),r.tabIndex=o?0:-1,Object.assign(r.style,{background:o?y.bgActive:"transparent",color:o?y.iconActive:y.label,fontWeight:o?"600":"400"})}};for(const r of s){const o=e.createElement("button");r.hint&&T(o,r.hint),o.type="button",o.textContent=r.label,o.dataset[p]=r.key,o.setAttribute("role","radio"),Object.assign(o.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(o,"bare"),o.addEventListener("click",()=>{u!==r.key&&g(r.key)}),d.push(o),l.appendChild(o)}return f(),l.addEventListener("keydown",r=>{if(r.key!=="ArrowLeft"&&r.key!=="ArrowRight")return;const o=d.indexOf(e.activeElement);if(o<0)return;r.preventDefault();const t=d[(o+(r.key==="ArrowRight"?1:-1)+d.length)%d.length];t.click(),t.focus()}),{el:l,set:r=>{u=r,f()}}}export function renderDataTables(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.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??[],l=g.filter(E),d=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=d.includes(e.view)?e.view:d[0],r="wide",o=null;const t=()=>{o?.destroy(),o=renderDataSection({doc:i,items:c,testDefs:l,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:d,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(v=>v.dies),h=[],w=q(m,l,void 0,void 0,e.onSaveText,u,a.map(v=>({dies:v.dies})),void 0,"full");w&&h.push(w);const x=X(m,g,void 0,e.onSaveText,u);return x&&h.push(x),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:r,onDiesLayoutChange:a=>{r=a}}),s.replaceChildren(o.card)};return t(),{el:s,destroy:()=>o?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
|
|
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"]})}
|
|
@@ -3,6 +3,7 @@ import type { Wafer } from '../core/index.js';
|
|
|
3
3
|
import { type MetadataFieldDef, type TestDef } from '../renderer/buildWaferMap.js';
|
|
4
4
|
import type { WaferMetadata } from '../core/metadata.js';
|
|
5
5
|
import { type MetadataKeySelection } from '../stats/metadataColumns.js';
|
|
6
|
+
import type { FacetCuration } from '../stats/facets.js';
|
|
6
7
|
import { type SaveTextHandler } from './toolbar.js';
|
|
7
8
|
import { type CsvCell } from './tableExport.js';
|
|
8
9
|
/** Display preferences for the built-in die-list table. Everything here is a
|
|
@@ -84,6 +85,8 @@ export interface DieListDisplayOptions {
|
|
|
84
85
|
export interface DieListOptions extends DieListDisplayOptions {
|
|
85
86
|
/** Heading text. Default: `Die list (N)`. */
|
|
86
87
|
title?: string;
|
|
88
|
+
/** The host's own names for wafer attributes, so a wafer-metadata column is headed as Group by and the plots name it. */
|
|
89
|
+
attributes?: Record<string, FacetCuration>;
|
|
87
90
|
/** Optional note shown under the heading, e.g. explaining why this replaced the map. */
|
|
88
91
|
note?: string;
|
|
89
92
|
/** Host hook for "Export CSV" — see `saveTextFile` (toolbar.ts). */
|
|
@@ -97,6 +100,15 @@ export interface DieListOptions extends DieListDisplayOptions {
|
|
|
97
100
|
label: string;
|
|
98
101
|
get: (die: Die) => string | undefined;
|
|
99
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* Each die's part-average-testing verdict (`stats/pat.ts`) and, for an outlier, the tests that put it outside, as
|
|
105
|
+
* two columns after Soft bin. Offered only for whole wafers: PAT limits are set from every die of a wafer.
|
|
106
|
+
*/
|
|
107
|
+
patColumns?: {
|
|
108
|
+
verdict: (die: Die) => string | undefined;
|
|
109
|
+
tests: (die: Die) => string;
|
|
110
|
+
anyOutlier: boolean;
|
|
111
|
+
};
|
|
100
112
|
/**
|
|
101
113
|
* Per-die wafer lookup for Ring/Quadrant classification. A single-wafer
|
|
102
114
|
* caller passes a constant `() => wafer`; the lot-pooled combined list
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{requireRingCount as K}from"../core/ringCount.js";import{hasPosition as
|
|
1
|
+
import{requireRingCount as K}from"../core/ringCount.js";import{hasPosition as P,isPositionedDie as M}from"../core/dies.js";import{testsPresent as G,testValue as R}from"../core/dieTable.js";import{DIE_REGIONS as D,DIE_REGION_KEYS as O}from"../stats/dieRegions.js";import{isParametricTest as _,getTestPassStatus as E}from"../renderer/buildWaferMap.js";import{resolveMetadataColumns as z}from"../stats/metadataColumns.js";import{LEADING as N,TRACKING as B,wireControlHover as W,controlStyle as j,SPACE as V,RADIUS as k,FONT as w,CLR as f}from"./toolbar.js";import{exportCsv as Y}from"./tableExport.js";import{fmt as U}from"../renderer/fmt.js";import{testLabel as A,markedTestLabel as H,derivedFields as X,derivedKeyText as q,derivedTestSource as J,isDerivedTest as Q,DERIVED_KEY as Z}from"../renderer/testLabel.js";const L=(n,r)=>r?`${n} (${r})`:n,ee=5e4,F=new WeakSet;export function ensureStylesInjected(n){if(F.has(n))return;F.add(n);const r=n.createElement("style");r.textContent=`
|
|
2
2
|
.wmap-dielist-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
|
|
3
3
|
.wmap-dielist-th {
|
|
4
4
|
text-align: left; padding: 4px 8px; position: sticky; top: 0;
|
|
@@ -9,4 +9,4 @@ import{requireRingCount as K}from"../core/ringCount.js";import{hasPosition as D,
|
|
|
9
9
|
padding: 4px 8px; color: ${f.text};
|
|
10
10
|
border-bottom: 1px solid ${f.menuBorder}; white-space: nowrap;
|
|
11
11
|
}
|
|
12
|
-
`,
|
|
12
|
+
`,n.head.appendChild(r)}function c(n,r,t,l){const s=n.createElement(r);return t&&Object.assign(s.style,t),l!==void 0&&(s.textContent=l),s}function te(n){return P(n)?String(n.x):""}function ne(n){return P(n)?String(n.y):""}function le(n,r){return r!==void 0?r.filter(t=>t.testNumber!==void 0):G(n,"values").map(t=>({testNumber:t,name:A(void 0,t)}))}function re(n,r,t){if(!r)return[];const l=K(t,"the die list"),s=[];for(const v of O){const p=D[v],u=o=>({wafer:r(o),ringCount:l});if(!n.some(o=>M(o)&&p.valueOf(o,u(o))!==void 0))continue;const h=new Map,a=o=>{let e=h.get(o);return e===void 0&&(e=p.valueOf(o,u(o))??"",h.set(o,e)),e};s.push({label:p.label,get:a,...p.rawOf?{csvGet:o=>p.rawOf(o,u(o))??""}:{}})}return s}export function resolveDieColumns(n,r,t={}){const l=le(n,r),s=re(n,t.getWafer,t),v=n.some(e=>e.edgeExcluded===!0),p=[...t.extraColumn?[t.extraColumn.label]:[],"X","Y",...O.map(e=>D[e].label),"Edge excluded","Site","Hard bin","Soft bin","PAT","PAT tests",...l.map(e=>L(A(e,e.testNumber),e.unit))],{columns:u,truncatedKeys:h}=z({dies:n,waferMetadata:t.waferMetadata,metadataFields:t.metadataFields,dieKeys:t.metadataColumns,waferKeys:t.waferMetadataColumns==="none"?"none":void 0,waferPlacement:t.waferMetadataColumns??"csv",reservedLabels:p,curation:t.attributes}),a=[...t.extraColumn?[{label:t.extraColumn.label,get:e=>t.extraColumn.get(e)??""}]:[],{label:"X",get:te},{label:"Y",get:ne},...s,...v?[{label:"Edge excluded",get:e=>e.edgeExcluded?"Yes":"No"}]:[],{label:"Site",get:e=>e.siteNum!==void 0?String(e.siteNum):""},{label:"Hard bin",get:e=>e.hbin!==void 0?String(e.hbin):""},{label:"Soft bin",get:e=>e.sbin!==void 0?String(e.sbin):""},...t.patColumns?[{label:"PAT",get:e=>t.patColumns.verdict(e)??""},...t.patColumns.anyOutlier?[{label:"PAT tests",get:e=>t.patColumns.tests(e)}]:[]]:[],...l.map(e=>{const y=!_(e);return{test:e,label:L(H(e,e.testNumber),e.unit),...Q(e)?{csvLabel:`${L(A(e,e.testNumber),e.unit)} [derived from ${J(e)??Z}]`}:{},get:d=>{if(y){const m=E(d,e.testNumber,e);return m===void 0?"":m?"PASS":"FAIL"}const x=R(d,e.testNumber);if(x!==void 0)return U(x,e.unit);const C=E(d,e.testNumber,e);return C===void 0?"":C?"PASS":"FAIL"},csvGet:d=>{if(y){const m=E(d,e.testNumber,e);return m===void 0?"":m?"PASS":"FAIL"}const x=R(d,e.testNumber);if(x!==void 0)return x;const C=E(d,e.testNumber,e);return C===void 0?"":C?"PASS":"FAIL"}}}),...u.map(e=>({label:e.label,get:e.get,csvOnly:e.csvOnly}))],o=a.filter(e=>!e.csvOnly);return{columns:a,visibleColumns:o,testColumns:l,truncatedKeys:h}}export function buildDieListSection(n,r,t={}){if(!n.length)return null;const l=t.ownerDocument??document;ensureStylesInjected(l);const s=t.maxRows??ee,v=Math.max(0,n.length-s),p=v>0?n.slice(0,s):n,u=c(l,"div",{display:"flex",flexDirection:"column",gap:V.md,flex:"1",minHeight:"0",minWidth:"0"}),h=c(l,"div",{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:"0"});h.appendChild(c(l,"div",{fontSize:w.meta,fontWeight:"700",letterSpacing:B,textTransform:"uppercase",color:f.label},t.title??`Die list (${n.length})`));const a=c(l,"button",{fontSize:w.body,padding:"3px 8px",borderRadius:k.control,...j("outlined"),background:f.menuBg},"Export CSV");a.type="button",W(a),h.appendChild(a),u.appendChild(h),t.note&&u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},t.note));const{columns:o,visibleColumns:e,testColumns:y,truncatedKeys:d}=resolveDieColumns(n,r,t),x=q(y.map(i=>({label:H(i,i.testNumber),...X(i)})));x&&u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},x));const C=c(l,"div",{overflow:"auto",flex:"1",minHeight:"0",minWidth:"0",border:`1px solid ${f.menuBorder}`,borderRadius:k.control,...t.maxHeight?{maxHeight:t.maxHeight}:{}}),m=l.createElement("table");m.className="wmap-dielist-table",m.setAttribute("aria-label",t.title??`Die list (${n.length} dies)`);const $=c(l,"thead"),T=c(l,"tr");for(const i of e){const b=l.createElement("th");b.className="wmap-dielist-th",b.scope="col",b.textContent=i.label,T.appendChild(b)}$.appendChild(T),m.appendChild($);const I=c(l,"tbody");for(const i of p){const b=c(l,"tr");for(const g of e){const S=l.createElement("td");S.className="wmap-dielist-td",S.textContent=g.get(i),b.appendChild(S)}I.appendChild(b)}if(m.appendChild(I),C.appendChild(m),u.appendChild(C),v>0||d.length>0){const i=[];v>0&&i.push(`Showing the first ${s.toLocaleString()} of ${n.length.toLocaleString()} dies. The CSV export contains all ${n.length.toLocaleString()}.`),d.length>0&&i.push(`${d.length} further metadata field${d.length===1?"":"s"} not shown.`),u.appendChild(c(l,"div",{fontSize:w.body,color:f.label,lineHeight:N.base,flexShrink:"0"},i.join(" ")))}return a.addEventListener("click",()=>{if(a.disabled)return;const i=a.textContent,b=Y(o.map(g=>({header:g.csvLabel??g.label,get:g.csvGet??g.get})),n,"die-list.csv",t.onSaveText,{onProgress:(g,S)=>{a.textContent=S?`Exporting ${Math.floor(100*g/S)}%`:`Exporting ${g.toLocaleString()} rows`}});b&&(a.disabled=!0,a.setAttribute("aria-busy","true"),b.catch(()=>{}).finally(()=>{a.disabled=!1,a.removeAttribute("aria-busy"),a.textContent=i}))}),u}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type TestDef } from '../renderer/buildWaferMap.js';
|
|
2
|
+
import type { Die } from '../core/dies.js';
|
|
3
|
+
import { type SaveImageHandler } from './charts/chartShell.js';
|
|
4
|
+
import { type RenderableWaferMap } from './renderWaferMap.js';
|
|
5
|
+
export interface DifferenceMapPanelOptions {
|
|
6
|
+
groups: ReadonlyArray<{
|
|
7
|
+
key: string;
|
|
8
|
+
items: ReadonlyArray<{
|
|
9
|
+
dies: readonly Die[];
|
|
10
|
+
passBins: readonly number[];
|
|
11
|
+
source?: RenderableWaferMap;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
testDefs: readonly TestDef[];
|
|
15
|
+
groupLabelText?: string;
|
|
16
|
+
/** The test the other panels show: the map starts on it, and follows it until the reader picks a measure here. */
|
|
17
|
+
selectedTestNumber?: number;
|
|
18
|
+
onSaveImage?: SaveImageHandler;
|
|
19
|
+
ownerDocument?: Document;
|
|
20
|
+
}
|
|
21
|
+
export declare function renderDifferenceMapPanel(o: DifferenceMapPanelOptions): {
|
|
22
|
+
card: HTMLElement;
|
|
23
|
+
setTest: (n: number) => void;
|
|
24
|
+
destroy: () => void;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=differenceMapPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{differenceMap as z}from"../stats/differenceMap.js";import{isParametricTest as F}from"../renderer/buildWaferMap.js";import{testLabel as E}from"../renderer/testLabel.js";import{fmt as A}from"../renderer/fmt.js";import{CLR as I,FONT as M,SPACE as R}from"./toolbar.js";import{cardShell as Y,guideCite as W,makeListSelect as k,renderEmptyState as _}from"./charts/chartShell.js";import{GUIDE_SECTIONS as U}from"../stats/guideSections.js";import{renderWaferMap as q}from"./renderWaferMap.js";import{cardAbout as H}from"./charts/cardAbout.js";const c="\0yield";export function renderDifferenceMapPanel(s){const n=s.ownerDocument??document,{card:y,body:x,controlsRow:O,setAbout:B}=Y("Difference map",s.onSaveImage,n,{png:!1});B(H("difference-map")),y.dataset.wmapDifferenceMap="1";const p=s.groups.map(e=>e.key),l=s.testDefs.filter(F);let a=p[0],i=p[1],t=s.selectedTestNumber!==void 0&&l.some(e=>e.testNumber===s.selectedTestNumber)?String(s.selectedTestNumber):l[0]?String(l[0].testNumber):c,C=!0,b;if(p.length<2)return _(x,"Needs two groups to subtract."),{card:y,setTest:()=>{},destroy:()=>{}};const D=(s.groupLabelText??"Group").toLowerCase(),T=(e,m,u,S)=>k(p.map(o=>({value:o,label:o})),e,o=>{S(o),h()},{ownerDocument:n,ariaLabel:m,hook:u}),w=n.createElement("span");w.textContent="minus",Object.assign(w.style,{color:I.label,fontSize:M.body});const L=()=>k([{value:c,label:"Yield"},...l.map(e=>({value:String(e.testNumber),label:E(e,e.testNumber)}))],t,e=>{t=e,C=!1,h()},{ownerDocument:n,ariaLabel:"Measure",hook:"difference-measure",searchPlaceholder:"Filter tests\u2026"});let $=L();O.append(T(a,`First ${D}`,"difference-a",e=>{a=e}),w,T(i,`Second ${D}`,"difference-b",e=>{i=e}),$);const d=n.createElement("div");Object.assign(d.style,{color:I.label,fontSize:M.body,marginBottom:R.sm});const g=n.createElement("div");Object.assign(g.style,{position:"relative",height:"380px"}),x.append(d,g);function h(){if(b?.destroy(),b=void 0,g.replaceChildren(),a===i){d.textContent="Choose two different groups.";return}const e=s.groups.find(f=>f.key===a),m=s.groups.find(f=>f.key===i),u=t===c?{yield:!0}:{test:Number(t)},S=t===c?void 0:l.find(f=>f.testNumber===Number(t)),o=t===c?"Yield":E(S,Number(t)),v=t===c?"%":S?.unit,r=z(e.items,m.items,u);d.textContent=r.compared?`${o}: ${a} (${e.items.length} wafer${e.items.length===1?"":"s"}) minus ${i} (${m.items.length}), each the mean over its wafers at the position${t===c?" of the share passing":""}. ${r.compared.toLocaleString("en-GB")} positions compared; the colours run from \u2212${A(r.maxAbs,v)} to +${A(r.maxAbs,v)}, zero in the middle. Grey: a position one group has no value at.`:`${a} and ${i} have no position with a value of ${o} in common.`,r.compared&&d.append(W(n,U.heatmap),".");const N=e.items[0]?.source;if(!N||!r.compared)return;const{metadata:J,...G}=N.wafer,P={...N,wafer:G,dies:r.dies,passBins:[...e.items[0].passBins],testDefs:[{testNumber:0,name:`${o}: ${a} \u2212 ${i}`,unit:v}]},j=[-(r.maxAbs||1),r.maxAbs||1];b=q(g,P,{viewOptions:{plotMode:"value",activeTest:0,valueRange:j},showIdentity:!1,insights:{enabled:!1},onSaveImage:s.onSaveImage})}return h(),{card:y,setTest:e=>{if(!C||!l.some(u=>u.testNumber===e)||String(e)===t)return;t=String(e);const m=L();$.replaceWith(m),$=m,h()},destroy:()=>{b?.destroy()}}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Die } from '../core/dies.js';
|
|
2
|
+
import type { BinColors } from '../renderer/binColors.js';
|
|
2
3
|
import type { FacetCuration } from '../stats/facets.js';
|
|
3
4
|
import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
|
|
4
5
|
import type { DrilldownSource, DrilldownItem } from './chartPopulation.js';
|
|
@@ -10,6 +11,8 @@ export interface DrilldownContext {
|
|
|
10
11
|
attributes?: Record<string, FacetCuration>;
|
|
11
12
|
/** The reader's saved plots: each is a row in the menu, opened on the selection. */
|
|
12
13
|
plots?: PlotStore;
|
|
14
|
+
/** The maps' bin colours, read when a plot is drawn: a plot coloured by bin draws each bin in its map colour. */
|
|
15
|
+
getBinColors?: () => BinColors;
|
|
13
16
|
onSaveImage?: SaveImageHandler;
|
|
14
17
|
/** The host's CSV save hook, for the tables' Export CSV. */
|
|
15
18
|
onSaveText?: SaveTextHandler;
|