@wafertools/wafermap 0.35.1 → 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 +13 -10
- package/CHANGELOG.md +474 -0
- package/README.md +7 -7
- package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
- package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
- 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/index.d.ts +1 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +57 -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.d.ts +20 -5
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +22 -9
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
- package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +12 -6
- 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 +607 -117
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/warnings.js +1 -1
- package/dist/packages/core/aggregates.d.ts +10 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/classify.d.ts +11 -0
- package/dist/packages/core/classify.js +1 -1
- package/dist/packages/core/dieTable.d.ts +5 -0
- package/dist/packages/core/dieTable.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 +10 -1
- package/dist/packages/core/wafer.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +5 -0
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +21 -4
- 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/derivedTests/parser.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +10 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +1 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/renderer/testLabel.d.ts +0 -11
- package/dist/packages/renderer/testLabel.js +1 -1
- package/dist/packages/renderer/valueFilter.d.ts +1 -1
- package/dist/packages/renderer/valueFilter.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.d.ts +22 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +26 -1
- 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/connectedComponents.js +1 -1
- package/dist/packages/stats/control.d.ts +21 -0
- package/dist/packages/stats/control.js +1 -0
- package/dist/packages/stats/correlation.d.ts +42 -4
- 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 +21 -6
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/findingText.d.ts +8 -0
- package/dist/packages/stats/findingText.js +2 -2
- 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 +5 -2
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/lotDrift.js +1 -1
- package/dist/packages/stats/math.d.ts +29 -4
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/mergeTestDefs.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 +33 -33
- package/dist/packages/stats/reportHtml.d.ts +5 -12
- package/dist/packages/stats/reportHtml.js +98 -40
- package/dist/packages/stats/synthesis.d.ts +48 -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/testValueBudget.d.ts +15 -0
- package/dist/packages/stats/testValueBudget.js +1 -0
- package/dist/packages/stats/types.d.ts +90 -30
- 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{hasPosition as be}from"../core/dies.js";import{DIE_REGIONS as G,DIE_REGION_KEYS as He}from"./dieRegions.js";import{excludedBy as Xe,excludedValue as ze,testValue as qe,testsPresent as pe}from"../core/dieTable.js";import{limitSetName as Ke}from"../renderer/valueFilter.js";import{compareNatural as Te,minOf as Oe,maxOf as De}from"../core/utils.js";import{isParametricTest as ne,getTestPassStatus as Ze}from"../renderer/buildWaferMap.js";import{facetValueOf as Je,buildFacetTable as Qe,FACET_NONE_VALUE as Ee}from"./facets.js";import{yieldCounts as Me}from"./yield.js";import{sameTestName as et}from"./sweep.js";import{sameField as ye,plotIssue as tt,isField as we}from"./plotSpec.js";function nt(e){if(!e)return;const r={};for(const i of["limitLow","limitHigh","specLow","specHigh"])Number.isFinite(e[i])&&(r[i]=e[i]);return Object.keys(r).length?r:void 0}function it(e){let r=0;for(const a of e)r+=a.dies.length;const i=new Array(r),o=new Uint32Array(r);let s=0;return e.forEach((a,u)=>{for(const l of a.dies)i[s]=l,o[s++]=u}),{dies:i,item:o}}const J={wafer:"Wafer",x:"Die X",y:"Die Y",ring:G.ring.label,quadrant:G.quadrant.label,reticleCell:G.reticleCell.label,reticleShot:G.reticleShot.label,hbin:"Hard bin",sbin:"Soft bin",site:"Site",yield:"Yield",dieCount:"Dies",waferOrder:"Wafer order"};export function fieldLabel(e,r){if("test"in e){const i=r?.find(s=>s.testNumber===e.test),o=i?.name||e.name||`Test ${e.test}`;return i!==void 0&&!ne(i)?`${o} (pass/fail)`:o}return"builtin"in e?J[e.builtin]??String(e.builtin):ie(e.meta)}function ie(e){const r=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim();return r?r[0].toUpperCase()+r.slice(1):e}const rt=/^[+-]?(?:\d+\.?\d*|\.\d+)$/;function V(e,r){const{items:i,rows:o,ctx:s}=r,a=fieldLabel(e,s.testDefs),u={field:e,label:a},l=o.dies.length,$=i.length;if("test"in e){const c=s.testDefs?.find(h=>h.testNumber===e.test);if(c===void 0){if(r.present??=new Set(o.dies.length?pe(o.dies,"values"):[]),!r.present.has(e.test))return{...u,level:"die",kind:"numeric",issue:`Needs test ${e.test}${e.name?` (${e.name})`:""}, which is not in these dies`}}else if(e.name&&c.name&&!et(e.name,c.name))return{...u,level:"die",kind:"numeric",unit:c.unit,issue:`Test ${e.test} is "${e.name}" in this plot and "${c.name}" here`};if(c!==void 0&&!ne(c)){const h=o.dies.map(g=>{const t=Ze(g,e.test,c);return t===void 0?void 0:t?"Pass":"Fail"});return{...u,level:"die",kind:"categorical",cat:h}}const w=new Float64Array(l);for(let h=0;h<l;h++)w[h]=qe(o.dies[h],e.test)??NaN;return{...u,level:"die",kind:"numeric",unit:c?.unit,num:w,limits:nt(c)}}if("meta"in e){const c=i.map(g=>Je(g.metadata,e.meta,s.curation));if(c.every(g=>g===void 0))return{...u,level:"wafer",kind:"categorical",cat:c,issue:`No wafer has a "${ie(e.meta)}" value`};const w=c.map(g=>g===void 0||!rt.test(g.trim())?NaN:Number(g)),h=c.every((g,t)=>g===void 0||Number.isFinite(w[t]));return{...u,level:"wafer",kind:h?"numeric":"categorical",cat:c,num:h?Float64Array.from(w):void 0}}switch(e.builtin){case"wafer":return{...u,level:"wafer",kind:"categorical",cat:i.map(c=>c.label)};case"waferOrder":return{...u,level:"wafer",kind:"numeric",num:Float64Array.from(i,(c,w)=>w+1)};case"dieCount":return{...u,level:"wafer",kind:"numeric",num:Float64Array.from(i,c=>c.dies.length)};case"yield":{const c=new Float64Array($),w=new Float64Array($);return i.forEach((h,g)=>{const{pass:t,total:b}=Me(h.dies,h.passBins);c[g]=b>0?t/b*100:NaN,w[g]=b}),{...u,level:"wafer",kind:"numeric",unit:"%",num:c,weights:w}}case"x":case"y":{const c=new Float64Array(l);for(let w=0;w<l;w++){const h=o.dies[w];c[w]=be(h)?e.builtin==="x"?h.x:h.y:NaN}return{...u,level:"die",kind:"numeric",num:c}}case"hbin":case"sbin":{const c=o.dies.map(w=>{const h=e.builtin==="hbin"?w.hbin:w.sbin;return h===void 0?void 0:`Bin ${h}`});return{...u,level:"die",kind:"categorical",cat:c}}case"site":return{...u,level:"die",kind:"categorical",cat:o.dies.map(c=>c.siteNum===void 0?void 0:`Site ${c.siteNum}`)};case"ring":case"quadrant":case"reticleCell":case"reticleShot":{const c=G[e.builtin],w=o.dies.map((h,g)=>{const t=i[o.item[g]];return c.valueOf(h,{wafer:t.wafer,ringCount:t.ringCount})});return{...u,level:"die",kind:"categorical",cat:w}}default:return{...u,level:"die",kind:"categorical",issue:"Needs a newer version of this tool"}}}function ot(e,r){const i=e.rows.dies.length,o=new Float64Array(i),s=new Float64Array(i);for(let a=0;a<i;a++){const u=e.items[e.rows.item[a]],{pass:l,total:$}=Me([e.rows.dies[a]],u.passBins);o[a]=$>0?l*100:NaN,s[a]=$}return{...r,level:"die",num:o,weights:s,perDie:!0}}export function combine(e,r){const i=e.filter(Number.isFinite);if(r==="count")return i.length;if(i.length===0)return NaN;switch(r){case"sum":return i.reduce((o,s)=>o+s,0);case"min":return Oe(i);case"max":return De(i);case"median":{const o=[...i].sort((a,u)=>a-u),s=o.length>>1;return o.length%2?o[s]:(o[s-1]+o[s])/2}default:return i.reduce((o,s)=>o+s,0)/i.length}}const re={mean:"Mean",median:"Median",min:"Min",max:"Max",sum:"Sum",count:"Count",yield:"Pooled yield"};function W(e,r,i,o,s,a){const u=o.axes?.[e]??{};let l=u.scale??"linear";if(l==="log"){for(const $ of s)if(Number.isFinite($)&&$<=0){l="linear",a.push(`The ${e.toUpperCase()} axis stays linear: a log axis needs every value above zero`);break}}return{label:u.label??r,unit:i,scale:l,min:u.min,max:u.max,reverse:u.reverse}}function st(e,r){const{chart:i}=e,o=e.fields??{},s=o.x?fieldLabel(o.x,r.testDefs):i==="box"||i==="bar"?"Wafer":void 0,a=o.y?fieldLabel(o.y,r.testDefs):void 0;switch(i){case"scatter":return s&&a?`${a} vs ${s}`:"Scatter";case"histogram":return a??(o.x?fieldLabel(o.x,r.testDefs):void 0)??"Histogram";case"line":return s&&a?`${a} over ${s}`:"Line";case"box":return a&&s?`${a} by ${s}`:"Box";case"bar":return s?a?`${a} by ${s}`:`Dies by ${s}`:"Bar";default:return""}}function Be(e,r,i,o={}){return{spec:e,issues:i,notes:[],level:"die",autoTitle:st(e,o),groups:[""],population:{wafers:r.length,dies:r.reduce((s,a)=>s+a.dies.length,0)},plotted:0,omitted:[]}}export function combinationIssue(e,r,i={}){const o=[r.x,i.continuousColor?void 0:r.color].filter($=>!!$&&$.level==="die"),s=!!r.y&&r.y.yield&&r.y.level==="wafer",a=(e==="bar"||e==="line")&&(i.aggregate===void 0||i.aggregate==="yield"||i.aggregate==="mean");if(s&&o.length&&!a)return{long:`${r.y.label} is one figure per wafer, and ${o[0].label} belongs to dies, so a ${e} of it cannot be split by ${o[0].label}. A bar chart of yield can (pooled yield per ${o[0].label.toLowerCase()}), or plot a measured value instead`,short:`${r.y.label} is per wafer: use a bar or line chart`};const u=[r.x,r.y].filter($=>!!$);let l=i.level??(u.some($=>$.level==="die")?"die":"wafer");if(e==="bar"&&!r.y&&o.length&&(l="die"),r.color?.level==="die"&&l==="wafer"&&!i.continuousColor&&!(s&&(e==="bar"||e==="line")))return{long:`${r.color.label} is per die, so it cannot colour a plot with one mark per wafer. Plot a measured value (one mark per die), or make a bar chart of yield, which can be split by ${r.color.label.toLowerCase()}`,short:`${r.color.label} is per die: this plot has one mark per wafer`}}export function resolvePlot(e,r,i={}){const o=tt(e);if(o)return Be(e,r,[o],i);const s=(...n)=>Be(e,r,n,i);if(e.chart==="sweep")return s("A sweep is drawn by the sweep panel");const a=it(r),u={items:r,rows:a,ctx:i},l=e.chart,$=e.fields??{},c=$.x??(l==="box"||l==="bar"?{builtin:"wafer"}:void 0),w=$.y,h=l==="histogram"?w??c:w;if(l==="scatter"||l==="line"){if(!c)return s("Choose a field for X");if(!w)return s("Choose a field for Y")}if(l==="box"&&!w)return s("Choose a field for Y");if(l==="histogram"&&!h)return s("Choose a field to count");const g=l==="histogram"?void 0:c?V(c,u):void 0;let t=h?V(h,u):void 0;const b=l==="scatter"||l==="line"?[["X",g],["Y",t]]:l==="histogram"?[["to count",t]]:l==="box"||l==="bar"?[["Y",t]]:[];for(const[n,d]of b)if(d&&!d.issue&&d.kind==="categorical"&&!d.num)return s(`${d.label} is a category, not a number, so it cannot be ${n==="to count"?"the field a histogram counts":`the ${n} of a ${l}`}. Use it as the X of a bar or box chart (one bar per ${d.label.toLowerCase()}), or as the colour`);const k=$.color;let y,ve=!1,oe;k===void 0||"follow"in k?i.groupBy?oe=i.groupBy:r.length>1&&(ve=!0):"none"in k||(y=V(k,u)),oe&&(y=V({meta:oe},u)),ve&&(y=V({builtin:"wafer"},u)),y?.issue&&(k===void 0||"follow"in k)&&(y=void 0);const se=[g?.issue,t?.issue,y?.issue].filter(n=>!!n),Q=!!y&&y.kind==="numeric"&&!("meta"in y.field);if(Q&&l!=="scatter"&&se.push(`${y.label} is continuous, so it can colour a scatter but not a ${l}: colour by a category such as wafer, split or bin`),se.length)return s(...se);const Pe=[g,t].filter(n=>!!n);let F=e.level??(Pe.some(n=>n.level==="die")?"die":"wafer");const le=[g,Q?void 0:y].filter(n=>!!n&&n.level==="die"),ae=n=>n&&{label:n.label,level:n.level,kind:n.kind,yield:!!n.weights},Ne=combinationIssue(l,{x:ae(g),y:ae(t),color:ae(y)},{aggregate:e.aggregate,level:e.level,continuousColor:Q});if(Ne)return s(Ne.long);l==="bar"&&!t&&le.length&&(F="die"),t&&t.level==="wafer"&&t.weights&&le.length&&(t=ot(u,t),F="die"),F==="die"&&t?.weights&&!t.perDie&&!le.length&&(F="wafer");const T=F==="die"?a.dies.length:r.length,ee=n=>F==="die"?a.item[n]:n,ue=n=>({item:ee(n),die:F==="die"?a.dies[n]:void 0}),Ce=e.aggregate&&e.aggregate!=="yield"?e.aggregate:"mean",D=n=>{if(!n.num)throw new Error("numeric field expected");if(n.level===F)return n.num;if(n.level==="wafer"){const m=new Float64Array(T);for(let f=0;f<T;f++)m[f]=n.num[ee(f)];return m}const d=r.map(()=>[]);for(let m=0;m<n.num.length;m++)d[a.item[m]].push(n.num[m]);return Float64Array.from(d,m=>combine(m,Ce))},Ae=n=>{if(!n.cat)throw new Error("category field expected");if(n.level===F)return n.cat;if(n.level==="wafer")return Array.from({length:T},(d,m)=>n.cat[ee(m)]);throw new Error("a per-die category cannot be used at wafer level")},We=n=>n.weights&&n.level===F?n.weights:void 0;let ce=[""],E=new Int32Array(T),H,I;if(y&&Q)H=y.label,I=D(y);else if(y){H=y.label;const n=Ae(y),d=new Map,m=[];for(let x=0;x<T;x++){const v=n[x]??Ee;d.has(v)||(d.set(v,0),m.push(v))}const S="builtin"in y.field&&y.field.builtin==="wafer"?m:y.num&&"meta"in y.field?[...m].sort((x,v)=>(Number(x)||0)-(Number(v)||0)):[...m].sort(Te);S.forEach((x,v)=>d.set(x,v)),ce=S;for(let x=0;x<T;x++)E[x]=d.get(n[x]??Ee)}const fe=new Map,M=n=>fe.set(n,(fe.get(n)??0)+1),B=[],Ie=F==="die"?"dies":"wafers";let X,O,_,Y,Fe,z=0;const U=ce.length,te=n=>n.level==="die"&&F==="wafer"?`${re[Ce].toLowerCase()} of ${n.label} per wafer`:void 0;if(l==="scatter"){const n=D(g),d=D(t),m=[];for(let f=0;f<T;f++){if(!Number.isFinite(n[f])){M(g.label);continue}if(!Number.isFinite(d[f])){M(t.label);continue}if(I&&!Number.isFinite(I[f])){M(y.label);continue}m.push({x:n[f],y:d[f],group:E[f],item:ee(f),die:F==="die"?a.dies[f]:void 0,...I?{value:I[f]}:{}})}if(z=m.length,I&&m.length){const f=m.map(S=>S.value);Fe={label:y.label,unit:y.unit,lo:Oe(f),hi:De(f)}}X={type:"scatter",points:m},O=W("x",g.label,g.unit,e,m.map(f=>f.x),B),_=W("y",t.label,t.unit,e,m.map(f=>f.y),B),Y=[te(g),te(t)].filter(Boolean).join("; ")||void 0}else if(l==="histogram"){const n=D(t),d=Array.from({length:U},()=>[]),m=Array.from({length:U},()=>[]);for(let f=0;f<T;f++){if(!Number.isFinite(n[f])){M(t.label);continue}d[E[f]].push(n[f]),m[E[f]].push(f),z++}X={type:"histogram",values:d,units:m,unit:ue},O=W("x",t.label,t.unit,e,d.flat(),B),_={label:"Count",scale:"linear",...e.axes?.y?.label?{label:e.axes.y.label}:{}},Y=te(t)}else if(l==="line"){const n=D(g),d=D(t),m=new Set,f=new Map,S=new Map;for(let N=0;N<T;N++){if(!Number.isFinite(n[N])){M(g.label);continue}if(!Number.isFinite(d[N])){M(t.label);continue}m.add(n[N]);const A=`${E[N]}|${n[N]}`;(f.get(A)??f.set(A,[]).get(A)).push(d[N]),z++,(S.get(A)??S.set(A,[]).get(A)).push(N)}const x=[...m].sort((N,A)=>N-A),v=e.aggregate??"mean",j=Array.from({length:U},(N,A)=>x.map(P=>{const K=f.get(`${A}|${P}`);return K?combine(K,v==="yield"?"mean":v):NaN})),L=Array.from({length:U},(N,A)=>x.map(P=>f.get(`${A}|${P}`)?.length??0)),R=Array.from({length:U},(N,A)=>x.map(P=>S.get(`${A}|${P}`)??[]));X={type:"line",xs:x,values:j,counts:L,cellUnits:R,unit:ue},O=W("x",g.label,g.unit,e,x,B);const q=v==="yield"?"mean":v;_=W("y",t.perDie?t.label:`${re[q]} ${t.label}`,t.unit,e,j.flat(),B),Y=t.perDie?`passing dies over judged dies, per ${g.label.toLowerCase()}`:`${re[q].toLowerCase()} of ${t.label} per ${g.label}`}else{const n=g,d="builtin"in n.field&&(n.field.builtin==="x"||n.field.builtin==="y");if(n.kind==="numeric"&&n.level==="die"&&!d)return s(`${n.label} is continuous, so a ${l} cannot have one ${l==="bar"?"bar":"box"} per value; use a scatter or line, or choose a categorical X such as wafer, ring or bin`);const m=n.cat?Ae(n):Array.from(D(n),p=>Number.isFinite(p)?String(p):void 0),f=new Map,S=[];for(let p=0;p<T;p++){const C=m[p];C!==void 0&&!f.has(C)&&(f.set(C,0),S.push(C))}const x="builtin"in n.field&&n.field.builtin==="wafer",v=x?S:n.kind==="numeric"?[...S].sort((p,C)=>Number(p)-Number(C)):[...S].sort(Te);v.forEach((p,C)=>f.set(p,C));const j=l==="bar"&&!t,L=e.aggregate??(j?"count":t?.weights?"yield":"mean");if(L==="yield"&&!t?.weights)return s("Pooled yield needs Yield as the Y field");if(l==="box"&&L==="count")return s("A box plot needs a measured field for Y");const R=t?D(t):void 0,q=t?We(t):void 0,N=Array.from({length:U},()=>v.map(()=>[])),A=Array.from({length:U},()=>v.map(()=>[])),P=Array.from({length:U},()=>v.map(()=>[]));for(let p=0;p<T;p++){const C=m[p]===void 0?void 0:f.get(m[p]);if(C===void 0){M(n.label);continue}if(R&&!Number.isFinite(R[p])){M(t.label);continue}N[E[p]][C].push(R?R[p]:1),A[E[p]][C].push(p),q&&P[E[p]][C].push(q[p]),z++}const K=N.map((p,C)=>p.map((Z,Ge)=>{if(Z.length===0)return NaN;if(L==="yield"){const ke=P[C][Ge],Le=ke.reduce((ge,he)=>ge+he,0);return Le>0?Z.reduce((ge,he,Ve)=>ge+he*ke[Ve],0)/Le:NaN}return combine(Z,L)})),Re=x?v.map(p=>m.findIndex((C,Z)=>C===p&&Z>=0)):void 0;if(X={type:l==="box"?"box":"bar",categories:v,cells:N,cellUnits:A,unit:ue,values:K,categoryItems:Re?.map(p=>F==="die"?a.item[p]:p)},O={label:e.axes?.x?.label??n.label,scale:"linear"},l==="bar"){const p=L==="count"?"Count":re[L],C=j?`Count of ${Ie}`:L==="yield"?"Pooled yield":`${p} ${t.label}`;_=W("y",C,L==="yield"?"%":L==="count"?void 0:t?.unit,e,K.flat(),B),Y=j?void 0:L==="yield"?`passing dies over judged dies, pooled per ${n.label.toLowerCase()}`:`${p.toLowerCase()} of ${t.label}${t.level==="die"&&F==="wafer"?" per wafer":""} per ${n.label.toLowerCase()}`}else _=W("y",t.label,t.unit,e,N.flat(2),B),Y=te(t)}const de=(n,d)=>n&&!n.perDie&&(d===void 0||d==="mean"||d==="median"||d==="min"||d==="max")?n.limits:void 0,Ye=e.aggregate??"mean";O&&(l==="scatter"||l==="line")&&(O.limits=de(g)),_&&l!=="histogram"&&(_.limits=de(t,l==="scatter"||l==="box"?void 0:Ye)),l==="histogram"&&O&&(O.limits=de(t));const je=()=>{const n=g?.label,d=t?.label,m=l==="scatter"?`${d} vs ${n}`:l==="histogram"?`${d}`:l==="line"?`${d} over ${n}`:l==="box"?`${d} by ${n}`:d?`${d} by ${n}`:`Dies by ${n}`;return H&&y&&!ye(y.field,c)?`${m} \xB7 by ${H}`:m},Se=[];let me;for(const n of new Set([g,t,y])){if(!n||!("test"in n.field))continue;const d=n.field.test;let m=0;for(const f of a.dies)ze(f,d)!==void 0&&(m++,me??=Ke(Xe(f)));m>0&&Se.push({field:n.label,count:m})}return{spec:e,issues:[],notes:B,marks:X,level:F,...me?{excluded:{limitSet:me,fields:Se}}:{},autoTitle:je(),x:O,y:_,groups:ce,colorScale:Fe,colorLabel:H,aggregation:Y,population:{wafers:r.length,dies:a.dies.length},plotted:z,omitted:[...fe].map(([n,d])=>({field:n,count:d}))}}export function plotTitle(e){return e.spec.title?.trim()?e.spec.title:e.autoTitle}export function plotFootnote(e){const{wafers:r,dies:i}=e.population,o=[`${r.toLocaleString("en-GB")} wafer${r===1?"":"s"} \xB7 ${i.toLocaleString("en-GB")} dies`];e.aggregation&&o.push(e.aggregation);for(const s of e.omitted)o.push(`${s.count.toLocaleString("en-GB")} ${e.level==="die"?"dies":"wafers"} without ${s.field} not plotted`);if(e.excluded)for(const s of e.excluded.fields)o.push(`${s.count.toLocaleString("en-GB")} ${s.field} value${s.count===1?"":"s"} outside ${e.excluded.limitSet} excluded`);return o.join(" \xB7 ")}export function fieldKey(e){return"test"in e?`test:${e.test}`:"builtin"in e?`builtin:${e.builtin}`:`meta:${e.meta}`}export function fieldCatalogue(e,r={}){const i=[],o=e.flatMap(t=>t.dies),s=new Set(o.length?pe(o,"values"):[]),a=r.testDefs??[],u=new Map;for(const t of a)t.testType!=="F"&&(s.has(t.testNumber)||!o.length)&&u.set(t.testNumber,t.name);for(const t of s)!u.has(t)&&!a.some(b=>b.testNumber===t&&b.testType==="F")&&u.set(t,void 0);for(const[t,b]of[...u].sort((k,y)=>k[0]-y[0]))i.push({field:{test:t,...b?{name:b}:{}},label:b?`${b} \xB7 ${t}`:`Test ${t}`,name:b||`Test ${t}`,group:"Tests",kind:"numeric",level:"die",categorical:!1});const l=new Set(o.length?pe(o,"all"):[]);for(const t of a){if(ne(t)||!(l.has(t.testNumber)||!o.length))continue;const b=t.name||`Test ${t.testNumber}`;i.push({field:{test:t.testNumber,...t.name?{name:t.name}:{}},label:`${b} \xB7 ${t.testNumber} (pass/fail)`,name:b,group:"Verdicts",kind:"categorical",level:"die",categorical:!0})}const $=t=>o.some(t),c=(t,b,k)=>i.push({field:{builtin:t},label:J[t],name:J[t],group:"Die",kind:b,level:"die",categorical:k});$(t=>be(t))&&(c("x","numeric",!1),c("y","numeric",!1));const w=$(t=>be(t));for(const t of He)e.some(b=>G[t].available({wafer:b.wafer,ringCount:b.ringCount},w))&&c(t,"categorical",!0);$(t=>t.hbin!==void 0)&&c("hbin","categorical",!0),$(t=>t.sbin!==void 0)&&c("sbin","categorical",!0),$(t=>t.siteNum!==void 0)&&c("site","categorical",!0);const h=(t,b,k)=>i.push({field:{builtin:t},label:J[t],name:J[t],group:"Wafer",kind:b,level:"wafer",categorical:k});h("wafer","categorical",!0),e.length>1&&h("waferOrder","numeric",!1),h("yield","numeric",!1),h("dieCount","numeric",!1);const g={items:e,rows:{dies:[],item:new Uint32Array(0)},ctx:r};for(const t of Qe(e.map(b=>({metadata:b.metadata,dieCount:b.dies.length})),{facetableOnly:!0,curation:r.curation})){if(t.values.length===0)continue;const b=V({meta:t.key},g);i.push({field:{meta:t.key},label:t.label||ie(t.key),name:t.label||ie(t.key),group:"Wafer",kind:b.kind,level:"wafer",categorical:!0,distinct:t.values.length})}return i}export function fieldsForRole(e,r,i){const o=i==="y"||i==="x"&&(r==="scatter"||r==="line"||r==="histogram");return i==="color"?e.filter(s=>s.categorical||r==="scatter"&&s.kind==="numeric"):o?e.filter(s=>s.kind==="numeric"):e.filter(s=>s.categorical)}export function defaultPlot(e,r){const i=e.filter(o=>o.group==="Tests");return i.length>=2?{id:r,chart:"scatter",fields:{x:i[0].field,y:i[1].field}}:i.length===1?{id:r,chart:"histogram",fields:{y:i[0].field}}:{id:r,chart:"scatter",fields:{x:{builtin:"waferOrder"},y:{builtin:"yield"}}}}const $e=new Set(["wafer","dies","die x","die y","wafer order"]),lt=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),xe=(e,r)=>r.length>=3&&new RegExp(`(^|[^A-Za-z0-9_])${lt(r)}($|[^A-Za-z0-9_])`,"i").test(e);export function titleDrift(e,r){const i=e.title?.trim(),o={names:[],omits:[]};if(!i)return o;const s=e.fields?.color,a=[e.fields?.x,e.fields?.y,s].filter(t=>we(t)),u=t=>a.some(b=>ye(b,t)),l=r.filter(t=>!$e.has(t.name.toLowerCase())&&!("meta"in t.field)&&!u(t.field)&&xe(i,t.name)).map(t=>t.name),$=[e.fields?.x,e.fields?.y].filter(t=>we(t)),c=t=>r.find(b=>ye(b.field,t))?.name??fieldLabel(t),w=$.filter(t=>!$e.has(c(t).toLowerCase())&&xe(i,c(t))),h=$.filter(t=>!$e.has(c(t).toLowerCase())&&!xe(i,c(t))),g=w.length>0||l.length>0?h.map(c):[];return{names:l,omits:g}}const _e=e=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;export function describeTitleDrift(e){const r=[];return e.names.length&&r.push(`The title names ${_e(e.names)}, which this plot does not show.`),e.omits.length&&r.push(`It does not name ${_e(e.omits)}, which this plot shows.`),r.length?r.join(" "):null}export function examplePlots(e,r,i){const o=e.filter(u=>u.group==="Tests").map(u=>u.field),s=[],a=r>1;if(o.length>=2&&s.push({id:i(),chart:"scatter",fields:{x:o[0],y:o[1]}}),o.length>=1&&s.push({id:i(),chart:"histogram",fields:{y:o[0],color:{none:!0}}}),o.length>=1&&a&&s.push({id:i(),chart:"box",fields:{x:{builtin:"wafer"},y:o[0],color:{none:!0}}}),a){const u=e.find(l=>"meta"in l.field&&l.distinct!==void 0&&l.distinct>=2&&l.distinct<=Math.max(2,Math.floor(r/2)));s.push({id:i(),chart:"bar",fields:{x:u?u.field:{builtin:"wafer"},y:{builtin:"yield"},color:{none:!0}}})}return o.length>=1&&a&&s.push({id:i(),chart:"line",fields:{x:{builtin:"waferOrder"},y:o[0],color:{none:!0}},aggregate:"mean"}),o.length>=2&&s.push({...Ue(o.flatMap(u=>"test"in u?[u]:[]),i()),title:"Example sweep"}),s}export function plotTestNumber(e){const{x:r,y:i,color:o}=e.fields??{},s=e.chart==="scatter"?[r,i,o]:e.chart==="histogram"?[i,r]:[i];for(const a of s)if(we(a)&&"test"in a)return a.test}export function defaultSweep(e,r){return Ue(e.filter(ne).map(i=>({test:i.testNumber,name:i.name})),r)}function Ue(e,r){const i=[...e].sort((s,a)=>s.test-a.test).slice(0,5),o=Object.fromEntries(i.flatMap(s=>s.name?[[String(s.test),s.name]]:[]));return{id:r,chart:"sweep",sweep:{series:[{label:"Series 1",tests:i.map(s=>s.test),...Object.keys(o).length?{testNames:o}:{}}]}}}
|
|
1
|
+
import{GUIDE_SECTIONS as ve}from"./guideSections.js";import{hasPosition as tt,isYieldEligibleDie as Et}from"../core/dies.js";import{DIE_REGIONS as Pe,DIE_REGION_KEYS as un,dieRadialPosition as fn}from"./dieRegions.js";import{excludedBy as cn,excludedValue as dn,testValue as nt,testsPresent as it}from"../core/dieTable.js";import{limitSetName as mn}from"../renderer/valueFilter.js";import{compareNatural as Dt,minOf as je,maxOf as ze}from"../core/utils.js";import{isParametricTest as pe,getTestPassStatus as hn}from"../renderer/buildWaferMap.js";import{attributeLabel as pt,facetValueOf as pn,buildFacetTable as Mt,FACET_NONE_VALUE as gt}from"./facets.js";import{yieldCounts as bt}from"./yield.js";import{sameTestName as yt}from"./sweep.js";import{sameField as ke,plotIssue as gn,plotConditions as Rt,isField as Ie,isTestSet as re,isBinned as We,isStatReference as bn,isPassRateSet as yn,xFieldsOf as xe,PLOT_X_LEVELS as _t,PLOT_FACET_LIMIT as Bt,PLOT_BINS_DEFAULT as wn}from"./plotSpec.js";import{fmtExact as Pt,fmt as Ve}from"../renderer/fmt.js";import{parseTestReference as $n}from"../renderer/derivedTests/parser.js";import{capabilityLimits as jt}from"./capability.js";import{mean as zt,median as wt}from"../core/utils.js";import{sampleVariance as Ut,quantile as $t,tQuantileTwoSided as vn,robustFence as xn}from"./math.js";import{pickExamples as Nn}from"./examplePicks.js";import{compareGroups as kn,formatP as Gt}from"./groupCompare.js";import{dieTestVerdict as Ht}from"./testPassRate.js";import{pearsonOfPairs as Sn}from"./correlation.js";import{individualsLimits as Fn,westernElectric as An,CONTROL_RULE_TEXT as On}from"./control.js";import{buildCapabilityFigures as Ln}from"./capability.js";import{patTests as Wt,waferPatLimits as Tn,waferPatVerdicts as In,PAT_VERDICT_LABEL as Cn,PAT_VERDICT_ORDER as En,PAT_K as Dn}from"./pat.js";function Vt(e){if(!e)return;const t={};for(const i of["limitLow","limitHigh","specLow","specHigh"])Number.isFinite(e[i])&&(t[i]=e[i]);return Object.keys(t).length?t:void 0}export function fitLine(e,t,i){const s=e.length;if(s<3)return;let n=0,o=0;for(let h=0;h<s;h++)n+=e[h],o+=t[h];n/=s,o/=s;let r=0,u=0,f=0;for(let h=0;h<s;h++){const c=e[h]-n,l=t[h]-o;r+=c*c,u+=l*l,f+=c*l}if(!(r>0))return;const a=u>0?f*f/(r*u):1,d=i==="linear"||f===0?f/r:(u-r+Math.sqrt((u-r)**2+4*f*f))/(2*f);return{slope:d,intercept:o-d*n,r2:a,n:s}}function ge(e){let t=0;for(const o of e)t+=o.dies.length;const i=new Array(t),s=new Uint32Array(t);let n=0;return e.forEach((o,r)=>{for(const u of o.dies)i[n]=u,s[n++]=r}),{dies:i,item:s}}const Ce={wafer:"Wafer",x:"Die X",y:"Die Y",ring:Pe.ring.label,quadrant:Pe.quadrant.label,reticleCell:Pe.reticleCell.label,reticleShot:Pe.reticleShot.label,hbin:"Hard bin",sbin:"Soft bin",site:"Site",yield:"Yield",dieCount:"Dies",waferOrder:"Wafer order",test:"Test",pat:"PAT",radius:"Radial position"};export function fieldLabel(e,t,i){if(We(e))return fieldLabel(e.binned,t,i);if(re(e))return _n(e,t);if("passRate"in e)return`${t?.find(n=>n.testNumber===e.passRate)?.name||e.name||`Test ${e.passRate}`} pass rate${e.judge==="flag"?" (tester flag)":""}`;if("test"in e){const s=t?.find(o=>o.testNumber===e.test),n=s?.name||e.name||`Test ${e.test}`;return s!==void 0&&!pe(s)?`${n} (pass/fail)`:n}return"builtin"in e?Ce[e.builtin]??String(e.builtin):pt(e.meta,i)}function Ue(e,t,i){if(We(e)){const s=Yt.get(e);return s?s.filter(n=>t.includes(n)):[...t].sort((n,o)=>parseFloat(n)-parseFloat(o))}return"builtin"in e&&(e.builtin==="wafer"||e.builtin==="test")?[...t]:"builtin"in e&&e.builtin==="pat"?En.filter(s=>t.includes(s)):Xt(t,i)}const Xt=(e,t)=>t?[...e].sort((i,s)=>(Number(i)||0)-(Number(s)||0)):[...e].sort(Dt);export function orderFieldValues(e){return Xt(e,e.every(t=>t===gt||vt.test(t.trim())))}const Xe=e=>!!e.num&&(e.kind==="numeric"||"meta"in e.field),Mn=e=>`Bin ${e}`;export function binOfLabel(e){const t=/^Bin (-?\d+)$/.exec(e);return t?Number(t[1]):void 0}const le=e=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`,Rn=e=>!!e&&"builtin"in e&&e.builtin==="pat",Se=e=>!!e&&"builtin"in e&&e.builtin==="test";function _n(e,t){const{tests:i}=expandTestSet(e,t??[]),s=n=>t?.find(o=>o.testNumber===n)?.name||e.names?.[String(n)]||`Test ${n}`;return e.passRate?e.judge==="flag"?"Pass rate (tester flag)":"Pass rate":i.length===0?e.tests.length===1?`Tests ${e.tests[0]}`:`${e.tests.length} test entries`:i.length>3?`${i.length} tests`:le(i.map(s))}export function passKindOf(e,t){return pe(e)?t==="flag"?"testFlag":"spec":"functional"}export function expandTestSet(e,t){const i=new Map(t.map(o=>[o.testNumber,o])),s=[],n=[];for(const o of e.tests){if(typeof o=="number"){s.includes(o)||s.push(o);continue}const r=$n(String(o),i);if(!r.ok){n.push(`"${o}": ${r.message}`);continue}for(const u of r.tests)s.includes(u)||s.push(u)}return{tests:s,problems:n}}export function withTestSetNames(e,t){const i={};for(const o of expandTestSet(e,t).tests){const r=t.find(u=>u.testNumber===o)?.name;r&&(i[String(o)]=r)}const{names:s,...n}=e;return Object.keys(i).length?{...n,names:i}:n}export const TEST_SET_VALUE_LIMIT=4e6;const vt=/^[+-]?(?:\d+\.?\d*|\.\d+)$/;export function binEdges(e,t,i){const s=Array.from(e).filter(Number.isFinite).sort((u,f)=>u-f);if(s.length===0)return[];const n=s[0],o=s[s.length-1],r=[];for(let u=1;u<t;u++)r.push(i==="width"?n+(o-n)*u/t:$t(s,u/t));return r.filter((u,f)=>u>n&&u<=o&&(f===0||u>r[f-1]))}const Bn=(e,t)=>{let i=0,s=t.length;for(;i<s;){const n=i+s>>1;e>=t[n]?i=n+1:s=n}return i};function Pn(e,t,i,s){const n=[t,...e,i],o=u=>u.every((f,a)=>a===0||f!==u[a-1]);let r=s?n.map(u=>Ve(u,s)):[];if(!o(r)||r.length===0){const u=s==="%"?"%":s?` ${s}`:"";for(let f=3;f<=15&&(r=n.map(a=>`${Number(a.toPrecision(f))}${u}`),!o(r));f++);}return n.slice(0,-1).map((u,f)=>`${r[f]} to ${r[f+1]}`)}const Yt=new WeakMap;function jn(e,t,i){const{ctx:s}=t,n=ee(e.binned,t),o=n.label;if(n.issue)return{...n,...i,label:o,kind:"categorical",num:void 0,issue:n.issue};if(!n.num)return{...n,...i,label:o,kind:"categorical",issue:`${n.label} is already a category: only a measured value or a number can be put into ranges`};const r=e.bins??wn,u=e.by??"count",f=`${JSON.stringify(e)}`;let a=s.binEdges?.get(f),d=n.num;if(!a){if(s.wholeItems&&s.wholeItems!==t.items){const $=ee(e.binned,{items:s.wholeItems,rows:ge(s.wholeItems),ctx:{...s,wholeItems:void 0}});$.num&&(d=$.num)}a=binEdges(d,r,u),s.binEdges?.set(f,a)}let h=1/0,c=-1/0;for(let $=0;$<d.length;$++){const b=d[$];Number.isFinite(b)&&(b<h&&(h=b),b>c&&(c=b))}if(h===1/0)return{...n,...i,label:o,kind:"categorical",num:void 0,issue:`${n.label} has no values to put into ranges`};const l=Pn(a,h,c,n.unit);Yt.set(e,l);const p=Array.from(n.num,$=>Number.isFinite($)?l[Bn($,a)]:void 0);return{...i,label:o,unit:void 0,level:n.level,kind:"categorical",cat:p}}function qt(e,t){const i=new Float64Array(e),s=new Float64Array(e),n=new Int8Array(e);for(let o=0;o<e;o++){const r=t(o);i[o]=r===void 0?NaN:r==="pass"?100:0,s[o]=r===void 0?0:1,n[o]=r==="failLow"?-1:r==="failHigh"?1:0}return{num:i,weights:s,failSide:n}}function ee(e,t){const{items:i,rows:s,ctx:n}=t,o=fieldLabel(e,n.testDefs,n.curation),r={field:e,label:o},u=s.dies.length,f=i.length;if(We(e))return jn(e,t,r);if(re(e)){const a=t.melt;if(!a)return{...r,level:"die",kind:"numeric",issue:"A set of tests can only be the values of a box, bar, line or histogram"};if(e.passRate){const c=a.tests.map(b=>n.testDefs?.find(T=>T.testNumber===b)),{num:l,weights:p,failSide:$}=qt(u,b=>{const T=c[a.testOf[s.item[b]]];return Ht(s.dies[b],T,passKindOf(T,e.judge))});return{...r,level:"die",kind:"numeric",unit:"%",num:l,weights:p,failSide:$,perDie:!0,labelOf:b=>a.labels[a.testOf[b]]}}const d=new Float64Array(u);for(let c=0;c<u;c++)d[c]=nt(s.dies[c],a.tests[a.testOf[s.item[c]]])??NaN;const h=new Set(a.tests.map(c=>n.testDefs?.find(l=>l.testNumber===c)?.unit).filter(c=>!!c));return{...r,level:"die",kind:"numeric",unit:h.size===1?[...h][0]:void 0,num:d,labelOf:c=>a.labels[a.testOf[c]]}}if("passRate"in e){const a=e.passRate,d=n.testDefs?.find($=>$.testNumber===a);if(!d)return{...r,level:"die",kind:"numeric",issue:`Needs test ${a}${e.name?` (${e.name})`:""}, which is not in these dies`};if(e.name&&d.name&&!yt(e.name,d.name))return{...r,level:"die",kind:"numeric",issue:`Test ${a} is "${e.name}" in this plot and "${d.name}" here`};const h=passKindOf(d,e.judge);if(h==="spec"&&d.limitLow===void 0&&d.limitHigh===void 0)return{...r,level:"die",kind:"numeric",issue:`${d.name||`Test ${a}`} has no test limits to judge a pass by`};const{num:c,weights:l,failSide:p}=qt(u,$=>Ht(s.dies[$],d,h));return{...r,level:"die",kind:"numeric",unit:"%",num:c,weights:l,failSide:p,perDie:!0}}if("test"in e){const a=n.testDefs?.find(c=>c.testNumber===e.test);if(a===void 0){if(t.present??=new Set(s.dies.length?it(s.dies,"values"):[]),!t.present.has(e.test))return{...r,level:"die",kind:"numeric",issue:`Needs test ${e.test}${e.name?` (${e.name})`:""}, which is not in these dies`}}else if(e.name&&a.name&&!yt(e.name,a.name))return{...r,level:"die",kind:"numeric",unit:a.unit,issue:`Test ${e.test} is "${e.name}" in this plot and "${a.name}" here`};if(a!==void 0&&!pe(a)){const c=s.dies.map(l=>{const p=hn(l,e.test,a);return p===void 0?void 0:p?"Pass":"Fail"});return{...r,level:"die",kind:"categorical",cat:c}}const d=new Float64Array(u);for(let c=0;c<u;c++)d[c]=nt(s.dies[c],e.test)??NaN;let h=Vt(a);if(i.length===1&&!t.melt&&a){const c=i[0],l=Tn(c.allDies??c.dies,n.testDefs??[],c.passBins).limits.get(e.test);l&&(h={...h,patLow:l.lo,patHigh:l.hi})}return{...r,level:"die",kind:"numeric",unit:a?.unit,num:d,limits:h}}if("meta"in e){const a=i.map(c=>pn(c.metadata,e.meta,n.curation));if(a.every(c=>c===void 0))return{...r,level:"wafer",kind:"categorical",cat:a,issue:`No wafer has a "${o}" value`};const d=a.map(c=>c===void 0||!vt.test(c.trim())?NaN:Number(c)),h=a.every((c,l)=>c===void 0||Number.isFinite(d[l]));return{...r,level:"wafer",kind:h?"numeric":"categorical",cat:a,num:h?Float64Array.from(d):void 0}}switch(e.builtin){case"wafer":return{...r,level:"wafer",kind:"categorical",cat:i.map(a=>a.label)};case"waferOrder":return{...r,level:"wafer",kind:"numeric",num:Float64Array.from(i,(a,d)=>(t.melt?t.melt.realOf[d]:d)+1)};case"test":return t.melt?{...r,level:"wafer",kind:"categorical",cat:i.map((a,d)=>t.melt.labels[t.melt.testOf[d]])}:{...r,level:"wafer",kind:"categorical",issue:"Test divides a set of tests: choose several tests as the values"};case"dieCount":return{...r,level:"wafer",kind:"numeric",num:Float64Array.from(i,a=>a.dies.length)};case"yield":{const a=new Float64Array(f),d=new Float64Array(f);return i.forEach((h,c)=>{const{pass:l,total:p}=bt(h.dies,h.passBins);a[c]=p>0?l/p*100:NaN,d[c]=p}),{...r,level:"wafer",kind:"numeric",unit:"%",num:a,weights:d}}case"x":case"y":{const a=new Float64Array(u);for(let d=0;d<u;d++){const h=s.dies[d];a[d]=tt(h)?e.builtin==="x"?h.x:h.y:NaN}return{...r,level:"die",kind:"numeric",num:a}}case"hbin":case"sbin":{const a=s.dies.map(d=>{const h=e.builtin==="hbin"?d.hbin:d.sbin;return h===void 0?void 0:Mn(h)});return{...r,level:"die",kind:"categorical",cat:a}}case"site":return{...r,level:"die",kind:"categorical",cat:s.dies.map(a=>a.siteNum===void 0?void 0:`Site ${a.siteNum}`)};case"radius":{const a=new Float64Array(u);for(let d=0;d<u;d++){const h=fn(s.dies[d],{wafer:i[s.item[d]].wafer});a[d]=h===void 0?NaN:h*100}return{...r,level:"die",kind:"numeric",unit:"%",num:a}}case"pat":{const a=n.testDefs??[];if(Wt(a).length===0)return{...r,level:"die",kind:"categorical",issue:"PAT needs tests with both a low and a high limit"};const d=new Map,h=s.dies.map((c,l)=>{const p=i[s.item[l]];let $=d.get(p);if(!$){const b=p.allDies??p.dies,T=In(b,a,p.passBins);$=new Map(b.map((v,k)=>[v,T[k].verdict?Cn[T[k].verdict]:void 0])),d.set(p,$)}return $.get(c)});return{...r,level:"die",kind:"categorical",cat:h}}case"ring":case"quadrant":case"reticleCell":case"reticleShot":{const a=Pe[e.builtin],d=s.dies.map((h,c)=>{const l=i[s.item[c]];return a.valueOf(h,{wafer:l.wafer,ringCount:l.ringCount})});return{...r,level:"die",kind:"categorical",cat:d}}default:return{...r,level:"die",kind:"categorical",issue:"Needs a newer version of this tool"}}}function zn(e,t){const i=e.rows.dies.length,s=new Float64Array(i),n=new Float64Array(i);for(let o=0;o<i;o++){const r=e.items[e.rows.item[o]],{pass:u,total:f}=bt([e.rows.dies[o]],r.passBins);s[o]=f>0?u*100:NaN,n[o]=f}return{...t,level:"die",num:s,weights:n,perDie:!0}}export const probabilityPosition=(e,t)=>(e+.5)/t;export function combine(e,t){const i=e.filter(Number.isFinite);if(t==="count")return i.length;if(i.length===0)return NaN;switch(t){case"sum":return i.reduce((s,n)=>s+n,0);case"min":return je(i);case"max":return ze(i);case"median":{const s=[...i].sort((o,r)=>o-r),n=s.length>>1;return s.length%2?s[n]:(s[n-1]+s[n])/2}default:return i.reduce((s,n)=>s+n,0)/i.length}}const xt={mean:"a mean",median:"a median",min:"a minimum",max:"a maximum",sum:"a sum",count:"a count",yield:"a pooled yield"},Ye={mean:"Mean",median:"Median",min:"Min",max:"Max",sum:"Sum",count:"Count",yield:"Pooled yield"};function ue(e,t,i,s,n,o){const r=s.axes?.[e]??{};let u=r.scale??"linear";if(u==="log"){for(const f of n)if(Number.isFinite(f)&&f<=0){u="linear",o.push(`The ${e.toUpperCase()} axis stays linear: a log axis needs every value above zero`);break}}return{label:r.label??t,unit:i,scale:u,min:r.min,max:r.max,reverse:r.reverse}}function Un(e,t){const{chart:i}=e,s=e.fields??{},n=xe(s.x),o=n.filter(f=>!Se(f)),r=n.length?o.length?le(o.map(f=>fieldLabel(f,t.testDefs,t.curation))):void 0:(i==="box"||i==="bar")&&!re(s.y)?"Wafer":void 0,u=s.y?fieldLabel(s.y,t.testDefs,t.curation):void 0;if((i==="box"||i==="bar")&&u&&!r)return u;switch(i){case"scatter":return r&&u?`${u} vs ${r}`:"Scatter";case"histogram":return u??(n[0]?fieldLabel(n[0],t.testDefs,t.curation):void 0)??"Histogram";case"probability":return u?`${u}, cumulative`:"Probability plot";case"control":return u?`${u} control chart`:"Control chart";case"goal":return"Capability goal plot";case"line":return r&&u?`${u} over ${r}`:"Line";case"box":return u&&r?`${u} by ${r}`:"Box";case"bar":return r?u?`${u} by ${r}`:`Dies by ${r}`:"Bar";default:return""}}function Ee(e,t,i,s={}){return{spec:e,issues:i,notes:[],level:"die",autoTitle:Un(e,s),groups:[""],population:{wafers:t.length,dies:t.reduce((n,o)=>n+o.dies.length,0)},plotted:0,omitted:[]}}export function combinationIssue(e,t,i={}){const s=[t.x,i.continuousColor?void 0:t.color].filter(f=>!!f&&f.level==="die"),n=!!t.y&&t.y.yield&&t.y.level==="wafer",o=(e==="bar"||e==="line")&&(i.aggregate===void 0||i.aggregate==="yield"||i.aggregate==="mean");if(n&&s.length&&!o)return{long:`${t.y.label} is one figure per wafer, and ${s[0].label} belongs to dies, so a ${e} of it cannot be split by ${s[0].label}. A bar chart of yield can (pooled yield per ${s[0].label.toLowerCase()}), or plot a measured value instead`,short:`${t.y.label} is per wafer: use a bar or line chart`};const r=[t.x,t.y].filter(f=>!!f);let u=i.level??(r.some(f=>f.level==="die")?"die":"wafer");if(e==="bar"&&!t.y&&s.length&&(u="die"),t.color?.level==="die"&&u==="wafer"&&!i.continuousColor&&!(n&&(e==="bar"||e==="line")))return{long:`${t.color.label} is per die, so it cannot colour a plot with one mark per wafer. Plot a measured value (one mark per die), or make a bar chart of yield, which can be split by ${t.color.label.toLowerCase()}`,short:`${t.color.label} is per die: this plot has one mark per wafer`}}const Gn={limits:"position in limits",zscore:"z-score",robust:"robust z-score"};function Hn(e,t){return e==="limits"?`rescaled to ${t.size===1?t.has("spec")?"spec limits":"test limits":"spec limits, or test limits where a test has no spec"}: 0 is the low limit, 1 the high`:e==="zscore"?"rescaled per test: standard deviations from the mean of the values in view":"rescaled per test: robust standard deviations (1.4826 \xD7 median absolute deviation) from the median of the values in view"}function Kt(e,t,i,s,n){const o=new Map,r=[],u=new Set;for(const f of e){if(s==="limits"){const c=i.find(p=>p.testNumber===f),l=c&&jt(c);if(!l){r.push(`${n(f)} has no low and high limit to place it by`);continue}u.add(l.basis),o.set(f,{offset:l.lsl,scale:l.usl-l.lsl});continue}const a=[];for(const c of t){const l=nt(c,f);l!==void 0&&Number.isFinite(l)&&a.push(l)}if(a.length<2){r.push(`${n(f)} has fewer than two values to measure a spread in`);continue}let d,h;if(s==="zscore"?(d=zt(a),h=Math.sqrt(Ut(a,d))):(d=wt(a),h=1.4826*wt(a.map(c=>Math.abs(c-d)))),!(h>0)||!Number.isFinite(h)){r.push(`${n(f)} has no spread: its values ${s==="robust"?"are mostly":"are all"} the same`);continue}o.set(f,{offset:d,scale:h})}return{scales:o,dropped:r,bases:u}}function Wn(e,t,i){const s={};for(const n of["limitLow","limitHigh","specLow","specHigh","patLow","patHigh"]){let o,r=!0;for(const u of e){const f=t(u)?.[n],a=i.get(u);if(f===void 0||!Number.isFinite(f)||!a){r=!1;break}const d=(f-a.offset)/a.scale;if(o===void 0)o=d;else if(Math.abs(d-o)>1e-9*Math.max(1,Math.abs(o))){r=!1;break}}r&&o!==void 0&&(s[n]=o)}return Object.keys(s).length?s:void 0}function Qt(e,t){let i;switch(e.type){case"scatter":i=e.points.map(n=>t==="x"?n.x:n.y);break;case"histogram":case"probability":i=t==="x"?e.values.flat():[];break;case"box":i=t==="y"?e.cells.flat(2):[];break;case"bar":i=t==="y"?e.values.flat():[];break;case"line":i=t==="x"?e.xs:[...e.values.flat(),...e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[]];break;case"control":i=t==="x"?e.xs:[...e.values,e.limits.ucl,e.limits.lcl];break;case"goal":i=e.points.map(n=>t==="x"?n.x:n.y);break;case"heatmap":i=[];break}const s=i.filter(Number.isFinite);return s.length?[je(s),ze(s)]:void 0}function Vn(e,t,i){if(e.issues.length||!e.marks)return e;const s=e.groups.map(u=>i.groups.indexOf(u));if(s.some(u=>u<0))return e;const n=Zt(e.marks,t,s,i.groups.length),o=i.marks&&Qt(i.marks,"x"),r=i.marks&&Qt(i.marks,"y");return{...e,marks:n,groups:i.groups,colorScale:i.colorScale??e.colorScale,x:e.x&&o?{...e.x,extent:o}:e.x,y:e.y&&r?{...e.y,extent:r}:e.y}}function Xn(e,t){return e.issues.length||!e.marks?e:{...e,marks:Zt(e.marks,t,e.groups.map((i,s)=>s),e.groups.length)}}function Zt(e,t,i,s){const n=(f,a)=>{const d=Array.from({length:s},a);return f.forEach((h,c)=>{d[i[c]]=h}),d},o=f=>t[f],r=f=>a=>{const d=f(a);return{...d,item:o(d.item)}};let u;switch(e.type){case"scatter":u={type:"scatter",points:e.points.map(f=>({...f,item:o(f.item),group:i[f.group]}))};break;case"histogram":u={type:"histogram",values:n(e.values,()=>[]),units:n(e.units,()=>[]),unit:r(e.unit)};break;case"probability":u={type:"probability",values:n(e.values,()=>[]),units:n(e.units,()=>[]),unit:r(e.unit)};break;case"box":case"bar":u={...e,cells:n(e.cells,()=>e.categories.map(()=>[])),cellUnits:n(e.cellUnits,()=>e.categories.map(()=>[])),values:n(e.values,()=>e.categories.map(()=>NaN)),categoryItems:e.categoryItems?.map(f=>f>=0?o(f):f),unit:r(e.unit)};break;case"line":u={...e,values:n(e.values,()=>e.xs.map(()=>NaN)),counts:n(e.counts,()=>e.xs.map(()=>0)),cellUnits:n(e.cellUnits,()=>e.xs.map(()=>[])),unit:r(e.unit),...e.band?{band:{lo:n(e.band.lo,()=>e.xs.map(()=>NaN)),hi:n(e.band.hi,()=>e.xs.map(()=>NaN))}}:{}};break;case"control":u={...e,items:e.items.map(o)};break;case"goal":u={type:"goal",points:e.points.map(f=>({...f,group:i[f.group]}))};break;case"heatmap":u={...e,unit:r(e.unit)};break}return u}function Yn(e,t,i){let s=0,n=0;const o=t.map(u=>{let f;for(let a=0;a<u.dies.length;a++){const d=u.dies[a];if(Et(d)){f?.push(d);continue}f??=u.dies.slice(0,a),d.partial?s++:n++}return f?{...u,dies:f,allDies:u.allDies??u.dies}:u}),r=qn(resolvePlot(e,o,{...i,eligibleOnly:!0}));return s+n>0?{...r,leftOut:{partial:s,edge:n}}:r}export const axisValues=(e,t)=>e.marks?Nt(e.marks,t).filter(Number.isFinite):[];function Nt(e,t){switch(e.type){case"bar":return t==="y"?e.values.flat():[];case"box":return t==="y"?e.cells.flat(2):[];case"scatter":return e.points.map(i=>t==="x"?i.x:i.y);case"line":return t==="y"?e.values.flat():e.xs;case"control":return t==="y"?e.values:e.xs;case"histogram":case"probability":return t==="x"?e.values.flat():[];default:return[]}}function qn(e){const t=[],i=h=>{const c=e.spec.axes?.[h]?.references;if(!c?.length||!e[h])return;let l;return c.flatMap(p=>bn(p)?(l??=e.marks?Nt(e.marks,h).filter(Number.isFinite):[],l.length===0?(t.push(`No ${p.stat} line: nothing is drawn along that axis`),[]):[{at:p.stat==="median"?wt(l):zt(l),label:p.label??p.stat}]):[p])},s=h=>{if(!e.spec.axes?.[h]?.clip||!e[h]||!e.marks)return;const c=Nt(e.marks,h).filter(Number.isFinite),l=xn(c);if(!l||c.length===0)return;const p=Math.max(je(c),l.lo),$=Math.min(ze(c),l.hi);if(!($>p))return;const b=c.reduce((T,v)=>T+(v<p||v>$?1:0),0);return{lo:p,hi:$,outside:b}},n=i("x"),o=i("y"),r=s("x"),u=s("y");if(!n&&!o&&!r&&!u)return e;const f=(h,c,l)=>h&&(c||l)?{...h,...c?{references:c}:{},...l?{clip:l}:{}}:h,a=h=>({...h,x:f(h.x,n,r),y:f(h.y,o,u)}),d=a(e);d.facets&&(d.facets=d.facets.map(h=>({...h,plot:a(h.plot)})));for(const h of[r,u])h?.outside&&t.push(`Axis clipped to the robust range: ${h.outside.toLocaleString("en-GB")} value${h.outside===1?"":"s"} outside it, still counted in every statistic`);return t.length?{...d,notes:[...d.notes,...t]}:d}export function conditionUnit(e,t){if(Ie(e)&&"test"in e)return t?.find(i=>i.testNumber===e.test)?.unit;if(Ie(e)&&"builtin"in e&&(e.builtin==="yield"||e.builtin==="radius"))return"%"}const Jt=(e,t)=>{const i=String(Number(e.toPrecision(6)));return t==="%"?`${i}%`:t?Ve(e,t):i};export function conditionText(e,t,i){const s=fieldLabel(e.field,t,i);if(e.values){const u=e.values.length<2?e.values.join(""):`${e.values.slice(0,-1).join(", ")} or ${e.values[e.values.length-1]}`;return`${s} is ${e.not?"not ":""}${u}`}const n=conditionUnit(e.field,t),o=e.min!==void 0?Jt(e.min,n):void 0,r=e.max!==void 0?Jt(e.max,n):void 0;return o!==void 0&&r!==void 0?`${s} ${e.not?"outside":"from"} ${o} to ${r}`:o!==void 0?`${s} ${e.not?"below":"at least"} ${o}`:`${s} ${e.not?"above":"at most"} ${r}`}export function applyConditions(e,t,i={}){const s=ge(t),n=s.dies.length,o={items:[...t],index:t.map(($,b)=>b),said:"",dies:{kept:n,total:n},wafers:{kept:t.length,total:t.length}};if(e.length===0)return o;const r=new Uint8Array(t.length).fill(1),u=new Uint8Array(n).fill(1),f=[],a=[];for(const $ of e){const b=ee($.field,{items:t,rows:s,ctx:i});if(b.issue)return{...o,issue:b.issue};let T;if($.values){if(!b.cat)return{...o,issue:`${b.label} is a number: keep a range of it, not values`};const k=new Set($.values),_=b.cat;T=B=>_[B]!==void 0&&k.has(_[B])!==!!$.not}else{if(!b.num)return{...o,issue:`${b.label} is a category: keep some of its values, not a range`};const k=b.num,_=$.min??-1/0,B=$.max??1/0;T=Q=>Number.isFinite(k[Q])&&(k[Q]>=_&&k[Q]<=B)!=!!$.not}const v=b.level==="wafer"?r:u;for(let k=0;k<v.length;k++)v[k]&&!T(k)&&(v[k]=0);(b.level==="wafer"?f:a).push(conditionText($,i.testDefs,i.curation))}const d=t.map(()=>[]);let h=0;for(let $=0;$<n;$++)u[$]&&r[s.item[$]]&&(d[s.item[$]].push(s.dies[$]),h++);const c=[],l=[];t.forEach(($,b)=>{if(r[b]){if(a.length===0){c.push($),l.push(b);return}d[b].length&&(c.push({...$,dies:d[b],allDies:$.allDies??$.dies}),l.push(b))}});const p=[f.length?`only wafers where ${le(f)}`:"",a.length?`only dies where ${le(a)}`:""].filter(Boolean).join("; ");return{items:c,index:l,said:p,dies:{kept:h,total:n},wafers:{kept:c.length,total:t.length}}}function Kn(e,t,i){const s=(...r)=>Ee(e,t,r,i),n=applyConditions(Rt(e),t,i);return n.issue?s(n.issue):n.items.length===0?s(`Nothing is left: no ${n.said.replace(/^only /,"").replace(/; only /," and ")}`):{...Xn(resolvePlot(e,n.items,{...i,whereApplied:!0}),n.index),filterNote:n.said}}function Qn(e,t,i){const s=e.fields.facet,{facet:n,...o}=e.fields,r={...e,fields:o},u=(...v)=>Ee(e,t,v,i),f=fieldLabel(s,i.testDefs,i.curation),a=t.flatMap(v=>v.dies),d={...i,inFacet:!0,scaleDies:i.scaleDies??a,wholeWafers:i.wholeWafers??t.length,wholeItems:i.wholeItems??t,binEdges:i.binEdges??new Map},h=Se(s);if(h&&!re(e.fields?.y))return u("Test panels need several tests as the values");if(h&&(xe(e.fields?.x).some(Se)||Se(e.fields?.color)))return u("Test already divides the panels, so it cannot also be on the X axis or the colour");if(xe(e.fields?.x).some(v=>ke(v,s))||e.fields?.color&&Ie(e.fields.color)&&ke(e.fields.color,s))return u(`${f} divides the panels, so on the X axis or the colour as well it would have one value per panel`);const c=resolvePlot(r,t,h?{...d,facetByTest:!0}:d),l=v=>({...v,autoTitle:`${v.autoTitle} \xB7 panels by ${f}`});if(c.issues.length||!c.marks)return l(c);let p=[];const $=[];if(h){const v=c.setTests;if(!v)return u("Test panels need several tests as the values");const k=t.map((_,B)=>B);p=v.tests.map((_,B)=>({label:v.labels[B],items:[...t],index:k,spec:{...r,fields:{...o,y:{test:_,...i.testDefs?.find(Q=>Q.testNumber===_)?.name?{name:i.testDefs.find(Q=>Q.testNumber===_).name}:{}}}}}))}else{const v=ge(t),k=ee(s,{items:t,rows:v,ctx:i});if(k.issue)return u(k.issue);if(!k.cat)return u(`${f} is continuous: panels need a category, such as split, ring or site`);if(k.level==="die"&&c.level==="wafer")return u(`${f} is per die, so it cannot divide a plot with one mark per wafer into panels`);const _=[];for(const D of k.cat)D!==void 0&&!_.includes(D)&&_.push(D);const B=Ue(s,_,Xe(k));if(B.length>Bt)return u(`${f} has ${B.length} values, and a plot draws at most ${Bt} panels: choose a field with fewer, or narrow Show`);const Q=k.cat.filter(D=>D===void 0).length;Q&&$.push(`${Q.toLocaleString("en-GB")} ${k.level==="die"?"dies":"wafers"} with no ${f} value are in no panel`),p=B.map(D=>{const G=[],S=[];if(k.level==="wafer")t.forEach((P,j)=>{k.cat[j]===D&&(G.push(P),S.push(j))});else{const P=t.map(()=>[]);for(let j=0;j<v.dies.length;j++)k.cat[j]===D&&P[v.item[j]].push(v.dies[j]);t.forEach((j,g)=>{P[g].length&&(G.push({...j,dies:P[g],allDies:j.allDies??j.dies}),S.push(g))})}return{label:D,items:G,index:S,spec:r}})}const b=p.map(v=>({label:v.label,plot:Vn(resolvePlot(v.spec,v.items,d),v.index,c)})),T=c.usesPat||Rn(s)||b.some(v=>v.plot.usesPat);return{...l(c),notes:[...c.notes,...$],facets:b,facetLabel:f,...T?{usesPat:!0}:{}}}function Zn(e,t,i){const s=e.fields??{},n=(...B)=>Ee(e,t,B,i),o=xe(s.x)[0]??{builtin:"wafer"},r=s.rows??(re(s.y)?{builtin:"test"}:void 0);if(!r)return n("Choose a field for the rows: a heatmap has one row per value of it");if(ke(r,o))return n("The rows and the columns need two different fields");const{rows:u,...f}=s,a={...e,chart:"bar",fields:{...f,x:[r,o],color:{none:!0}}};delete a.stack,delete a.sort,delete a.top,delete a.cumulative;const d=resolvePlot(a,t,{...i,asHeatmap:!0,inFacet:!0,whereApplied:i.whereApplied});if(d.issues.length||!d.marks||d.marks.type!=="bar")return{...d,spec:e};const h=d.marks,c=h.nest?.parts??[],l=[...new Set(c.map(B=>B[0]))],p=[...new Set(c.map(B=>B[1]))],$=Ue(o,p,p.every(B=>vt.test(B))),b=l.map(()=>$.map(()=>NaN)),T=l.map(()=>$.map(()=>[]));c.forEach((B,Q)=>{const D=l.indexOf(B[0]),G=$.indexOf(B[1]);b[D][G]=h.values[0][Q],T[D][G]=h.cellUnits[0][Q]});const v=b.flat().filter(Number.isFinite),k=fieldLabel(r,i.testDefs,i.curation),_=fieldLabel(o,i.testDefs,i.curation);return{...d,spec:e,marks:{type:"heatmap",rows:l,cols:$,values:b,cellUnits:T,unit:h.unit},autoTitle:`${d.y?.label??"Dies"} by ${k} and ${_}`,x:{label:e.axes?.x?.label??_,scale:"linear"},y:{label:e.axes?.y?.label??k,scale:"linear"},colorScale:v.length?{label:d.y?.label??"Count",unit:d.y?.unit,lo:je(v),hi:ze(v),...v.every(Number.isInteger)?{integer:!0}:{}}:void 0,groups:[""]}}function Jn(e,t,i){const s=(...D)=>Ee(e,t,D,i),n=e.fields??{};if(!n.y)return s("Choose a field for the values");if(re(n.y))return s("A control chart follows one value: choose one test");const o=xe(n.x)[0]??{builtin:"waferOrder"},r=ge(t),u={items:t,rows:r,ctx:i},f=ee(o,u),a=ee(n.y,u),d=f.issue??a.issue;if(d)return s(d);if(f.level!=="wafer"||!f.num)return s(`A control chart runs along a wafer field with a number per wafer, such as wafer order or slot, not ${f.label}`);if(!a.num)return s(`${a.label} is a category, not a number, so it cannot be charted`);const h=e.aggregate&&e.aggregate!=="yield"&&e.aggregate!=="count"?e.aggregate:"mean",c=t.map(()=>[]);if(a.level==="die")for(let D=0;D<r.dies.length;D++)c[r.item[D]].push(a.num[D]);const l=D=>a.level==="wafer"?a.num[D]:combine(c[D],a.perDie?"mean":h),p=t.map((D,G)=>G).filter(D=>Number.isFinite(f.num[D])&&Number.isFinite(l(D))).sort((D,G)=>f.num[D]-f.num[G]||D-G),$=t.length-p.length;if(p.length<3)return s("A control chart needs at least three wafers with a value");const b=p.map(l),T=p.map(D=>f.num[D]),v=Fn(b,e.baseline),k=An(b,v),_=a.perDie||a.level==="wafer"?a.label:`${Ye[h]} ${a.label}`,B=[];n.color&&!("none"in n.color)&&!("follow"in n.color)&&B.push("A control chart is one series: its points are not coloured");const Q=k.length?`${k.length} point${k.length===1?"":"s"} break${k.length===1?"s":""} a Western Electric rule (${[...new Set(k.flatMap(D=>D.rules))].sort().map(D=>`${D}: ${On[D]}`).join("; ")})`:"no point breaks a Western Electric rule";return{spec:e,issues:[],notes:B,level:"wafer",marks:{type:"control",xs:T,values:b,items:p,limits:v,violations:k},autoTitle:`${_} control chart`,x:ue("x",f.label,f.unit,e,T,B),y:{...ue("y",_,a.unit,e,b,B),limits:!a.perDie&&a.level==="die"&&(h==="mean"||h==="median")?a.limits:void 0},groups:[""],aggregation:`individuals chart: centre the mean of ${v.baseline===b.length?"all":`the first ${v.baseline}`} wafers, limits \xB13\u03C3 with \u03C3 the average moving range / 1.128; ${Q}`,population:{wafers:t.length,dies:r.dies.length},plotted:b.length,omitted:$?[{field:a.label,count:$}]:[]}}function ei(e,t,i){const s=(...b)=>Ee(e,t,b,i),n=i.testDefs??[],o=e.fields??{};let r;if(!o.y)r=n.filter(pe);else if(re(o.y)){const b=new Set(expandTestSet(o.y,n).tests);r=n.filter(T=>b.has(T.testNumber))}else if("test"in o.y)r=n.filter(b=>b.testNumber===o.y.test);else return s("A goal plot shows tests: choose tests, or leave the values empty for every test with both limits");if(r=r.filter(b=>pe(b)&&jt(b)!==void 0),r.length===0)return s("No test here has both a low and a high limit to set a goal by");const u=ge(t),f={items:t,rows:u,ctx:i},a=o.color,d=a===void 0||"follow"in a?i.groupBy?{meta:i.groupBy}:void 0:"none"in a?void 0:a;let h=[""],c=()=>0;if(d){const b=ee(d,f);if(b.issue)return s(b.issue);if(!b.cat)return s(`${b.label} is continuous: colour a goal plot by a category such as split`);const T=k=>b.level==="die"?b.cat[k]:b.cat[u.item[k]],v=[];for(let k=0;k<u.dies.length;k++){const _=T(k);_!==void 0&&!v.includes(_)&&v.push(_)}h=Ue(d,v,Xe(b)),c=k=>{const _=T(k);return _===void 0?-1:h.indexOf(_)}}const l=h.map(()=>[]);for(let b=0;b<u.dies.length;b++){const T=c(b);T>=0&&l[T].push(u.dies[b])}const p=[];if(l.forEach((b,T)=>{for(const v of Ln([{dies:b}],r)){if(!v.hasSpec||v.lsl===void 0||v.usl===void 0||!(v.stdOverall>0)||v.ppk===null)continue;const k=v.usl-v.lsl;p.push({x:(v.mean-(v.lsl+v.usl)/2)/k,y:v.stdOverall/k,group:T,testNumber:v.testNumber,label:v.label,ppk:v.ppk,n:v.n,basis:v.limitBasis??"test"})}}),p.length===0)return s("No test has values with a spread to place");const $=[];return{spec:e,issues:[],notes:$,level:"die",marks:{type:"goal",points:p},autoTitle:d?`Capability goal plot \xB7 by ${fieldLabel(d,n,i.curation)}`:"Capability goal plot",x:ue("x","Mean offset from the centre of the limits",void 0,e,p.map(b=>b.x),$),y:ue("y","Standard deviation",void 0,e,p.map(b=>b.y),$),groups:h,colorLabel:d?fieldLabel(d,n,i.curation):void 0,aggregation:"each test's mean offset and standard deviation over its dies, as shares of its limit window (spec limits where it has both, else test limits); triangles: Ppk 1 and 1.33",population:{wafers:t.length,dies:u.dies.length},plotted:p.length,omitted:[]}}export function resolvePlot(e,t,i={}){const s=gn(e);if(s)return Ee(e,t,[s],i);const n=(...m)=>Ee(e,t,m,i);if(e.chart==="sweep")return n("A sweep is drawn by the sweep panel");if(!i.eligibleOnly)return Yn(e,t,i);if(!i.whereApplied&&Rt(e).length)return Kn(e,t,i);if(e.fields?.facet&&!i.inFacet)return Qn(e,t,i);if(e.chart==="control")return Jn(e,t,i);if(e.chart==="goal")return ei(e,t,i);if(e.chart==="heatmap"&&!i.asHeatmap)return Zn(e,t,i);const o=e.chart,r=e.fields??{},u=i.testDefs??[],f=t.flatMap(m=>m.dies),a=[],d=re(r.y)?r.y:void 0;if(re(r.x)||re(r.color))return n("A set of tests can only be the values (Y) of a plot");if(e.normalize&&o==="scatter")return n("Rescaling applies to the values of a box, bar, line or histogram, not to a scatter");if(d&&o==="scatter")return n("A scatter plots one value against another: choose one test for each axis, or a box, bar, line or histogram to show several tests");const h=m=>u.find(x=>x.testNumber===m)?.name||d?.names?.[String(m)]||`Test ${m}`;let c,l,p=new Set,$=t;if(d){const{tests:m,problems:x}=expandTestSet(d,u);if(x.length)return n(...x);const N=new Set(f.length?it(f,"values"):[]),L=[];let w=[];for(const I of m){const R=u.find(Y=>Y.testNumber===I),H=d.names?.[String(I)];if(R&&H&&R.name&&!yt(H,R.name))return n(`Test ${I} is "${H}" in this plot and "${R.name}" here`);if(d.passRate){if(!R){L.push(H?`${H} (test ${I})`:`test ${I}`);continue}if(passKindOf(R,d.judge)==="spec"&&R.limitLow===void 0&&R.limitHigh===void 0){L.push(`${h(I)} (no test limits)`);continue}w.push(I);continue}if(R&&!pe(R)){L.push(`${h(I)} (pass/fail, no value)`);continue}if(!N.has(I)){L.push(H?`${H} (test ${I})`:`test ${I}`);continue}w.push(I)}if(w.length===0)return n(`None of these tests has ${d.passRate?"a verdict to judge":"values"} in these dies${L.length?`: ${L.join(", ")}`:""}`);if(d.passRate&&e.normalize)return n("A pass rate is a share of dies, not a measured value: it cannot be rescaled");if(w.length*f.length>TEST_SET_VALUE_LIMIT){const I=Math.max(1,Math.floor(TEST_SET_VALUE_LIMIT/Math.max(1,f.length)));return n(`${w.length} tests over ${f.length.toLocaleString("en-GB")} dies is ${(w.length*f.length).toLocaleString("en-GB")} values, more than one plot draws (${TEST_SET_VALUE_LIMIT.toLocaleString("en-GB")}): choose at most ${I} tests, or show fewer wafers`)}if(L.length&&a.push(`Left out, with no values here: ${L.join(", ")}`),e.normalize){const I=Kt(w,i.scaleDies??f,u,e.normalize,h);if(I.scales.size===0)return n(...I.dropped);I.dropped.length&&a.push(`Left out: ${I.dropped.join("; ")}`),w=w.filter(R=>I.scales.has(R)),l=I.scales,p=I.bases}else if(!d.passRate){const I=[...new Set(w.map(R=>u.find(H=>H.testNumber===R)?.unit).filter(R=>!!R))];if(I.length>1)return n(`These tests are measured in different units (${I.join(", ")}): rescale them to compare them on one axis`)}const O=w.map(h),A=O.map((I,R)=>O.indexOf(I)!==O.lastIndexOf(I)?`${I} \xB7 ${w[R]}`:I),F=[],W=[],z=[];w.forEach((I,R)=>t.forEach((H,Y)=>{F.push(H),W.push(Y),z.push(R)})),c={realOf:Int32Array.from(W),testOf:Int32Array.from(z),tests:w,labels:A},$=F}const b=m=>c?c.realOf[m]:m,T=ge($),v={items:$,rows:T,ctx:i,melt:c},k=xe(r.x);if(k.length>1&&o!=="box"&&o!=="bar")return n("Nested categories need a box or bar chart: choose one field for X");if(k.length>_t)return n(`At most ${_t} fields can be nested on X`);if(k.some((m,x)=>k.findIndex(N=>ke(m,N))!==x))return n("A field can be only one level of the categories");const _=k.length?k:o==="box"||o==="bar"?[{builtin:d?"test":"wafer"}]:[],B=_[0],Q=_.some(Se),D=r.y,G=o==="histogram"||o==="probability",S=G?D??B:D;if(o==="scatter"||o==="line"){if(!B)return n("Choose a field for X");if(!D)return n("Choose a field for Y")}if(o==="box"&&!D)return n("Choose a field for Y");if(o==="histogram"&&!S)return n("Choose a field to count");if(o==="probability"&&!S)return n("Choose the values to plot");const P=G?[]:_.map(m=>ee(m,v)),j=P[0];let g=S?ee(S,v):void 0;if(e.normalize&&g&&!g.issue){if(!c){if(!("test"in g.field)||!g.num)return n("Rescaling applies to a measured test: choose a test for the values");const A=g.field.test,F=Kt([A],i.scaleDies??T.dies,u,e.normalize,()=>g.label);if(F.scales.size===0)return n(...F.dropped);l=F.scales,p=F.bases}const m=A=>c?c.tests[c.testOf[T.item[A]]]:g.field.test,x=new Float64Array(g.num.length);for(let A=0;A<x.length;A++){const F=l.get(m(A));x[A]=(g.num[A]-F.offset)/F.scale}const N=c?c.tests:[m(0)],L=c?N.length>3?`${N.length} tests`:le(c.labels):g.label,w=g.limits;g={...g,num:x,unit:void 0,limits:Wn(N,c?A=>Vt(u.find(F=>F.testNumber===A)):()=>w,l),label:`${L} (${Gn[e.normalize]})`}}else c&&g&&!g.issue&&!yn(g.field)&&(g={...g,label:c.tests.length>3?`${c.tests.length} tests`:le(c.labels)});const tn=o==="scatter"||o==="line"?[["X",j],["Y",g]]:o==="histogram"?[["to count",g]]:o==="probability"?[["values",g]]:o==="box"||o==="bar"?[["Y",g]]:[];for(const[m,x]of tn)if(x&&!x.issue&&x.kind==="categorical"&&!x.num)return n(`${x.label} is a category, not a number, so it cannot be ${m==="to count"?"the field a histogram counts":m==="values"?"the values of a probability plot":`the ${m} of a ${o}`}. Use it as the X of a bar or box chart (one bar per ${x.label.toLowerCase()}), or as the colour`);const Fe=d&&!Q&&!i.facetByTest&&(r.color===void 0||"follow"in r.color)?{builtin:"test"}:r.color;if(d&&!Q&&!i.facetByTest&&!Se(Fe))return n("Put Test on the X axis or the colour, so each test is drawn on its own");let M,Ft=!1,st;Fe===void 0||"follow"in Fe?i.groupBy?st=i.groupBy:(i.wholeWafers??t.length)>1&&(Ft=!0):"none"in Fe||(M=ee(Fe,v)),st&&(M=ee({meta:st},v)),Ft&&(M=ee({builtin:"wafer"},v)),M?.issue&&(Fe===void 0||"follow"in Fe)&&(M=void 0);const ot=[...P.map(m=>m.issue),g?.issue,M?.issue].filter(m=>!!m),De=!!M&&M.kind==="numeric"&&!("meta"in M.field);if(De&&o!=="scatter"&&ot.push(`${M.label} is continuous, so it can colour a scatter but not a ${o}: colour by a category such as wafer, split or bin`),ot.length)return n(...ot);const nn=[...P,g].filter(m=>!!m);let K=e.level??(nn.some(m=>m.level==="die")?"die":"wafer");const at=[...P,De?void 0:M].filter(m=>!!m&&m.level==="die"),rt=m=>m&&{label:m.label,level:m.level,kind:m.kind,yield:!!m.weights},At=combinationIssue(o,{x:rt(P.find(m=>m.level==="die")??j),y:rt(g),color:rt(M)},{aggregate:e.aggregate,level:e.level,continuousColor:De});if(At)return n(At.long);if(o==="bar"&&!g&&at.length&&(K="die"),g&&g.level==="wafer"&&g.weights&&at.length&&(g=zn(v,g),K="die"),K==="die"&&g?.weights&&!g.perDie&&!at.length&&(K="wafer"),g&&"passRate"in g.field&&K==="die"&&o!=="bar"&&o!=="line")return n(`${g.label} is a share of dies: draw it as a bar or a line, or with one mark per wafer (each wafer's pass rate)`);const se=K==="die"?T.dies.length:t.length,qe=m=>K==="die"?T.item[m]:m,Ke=m=>({item:b(qe(m)),die:K==="die"?T.dies[m]:void 0}),Ot=e.aggregate&&e.aggregate!=="yield"?e.aggregate:"mean",be=m=>{if(!m.num)throw new Error("numeric field expected");if(m.level===K)return m.num;if(m.level==="wafer"){const N=new Float64Array(se);for(let L=0;L<se;L++)N[L]=m.num[qe(L)];return N}const x=t.map(()=>[]);for(let N=0;N<m.num.length;N++)x[T.item[N]].push(m.num[N]);return Float64Array.from(x,N=>combine(N,Ot))},Lt=m=>{if(!m.cat)throw new Error("category field expected");if(m.level===K)return m.cat;if(m.level==="wafer")return Array.from({length:se},(x,N)=>m.cat[qe(N)]);throw new Error("a per-die category cannot be used at wafer level")},sn=m=>m.weights&&m.level===K?m.weights:void 0;let Qe=[""],ye=new Int32Array(se),Ae,we;if(M&&De)Ae=M.label,we=be(M);else if(M){Ae=M.label;const m=Lt(M),x=new Map,N=[];for(let w=0;w<se;w++){const O=m[w]??gt;x.has(O)||(x.set(O,0),N.push(O))}const L=Ue(M.field,N,Xe(M));L.forEach((w,O)=>x.set(w,O)),Qe=L;for(let w=0;w<se;w++)ye[w]=x.get(m[w]??gt)}const lt=new Map,$e=m=>lt.set(m,(lt.get(m)??0)+1),Ge=(m,x)=>m.labelOf?m.labelOf(K==="die"?T.item[x]:x):m.label,Ze=K==="die"?"dies":"wafers";let Me,te,ce,Oe,ut,Tt,ft,Re=0;const X=Qe.length,He=m=>m.level==="die"&&K==="wafer"?`${Ye[Ot].toLowerCase()} of ${m.label} per wafer`:void 0;if(o==="scatter"){const m=be(j),x=be(g),N=[];for(let O=0;O<se;O++){if(!Number.isFinite(m[O])){$e(j.label);continue}if(!Number.isFinite(x[O])){$e(Ge(g,O));continue}if(we&&!Number.isFinite(we[O])){$e(M.label);continue}N.push({x:m[O],y:x[O],group:ye[O],item:qe(O),die:K==="die"?T.dies[O]:void 0,...we?{value:we[O]}:{}})}if(Re=N.length,we&&N.length){const O=N.map(A=>A.value);Tt={label:M.label,unit:M.unit,lo:je(O),hi:ze(O)}}let L;if(e.fit){L=(we?[N]:Array.from({length:X},(F,W)=>N.filter(z=>z.group===W))).flatMap((F,W)=>{const z=fitLine(F.map(I=>I.x),F.map(I=>I.y),e.fit);return z?[{group:W,...z}]:[]});const A=(j.unit??"")===(g.unit??"");ft=L.map(F=>{const W=X>1&&!we?`${Qe[F.group]||"(none)"}: `:"",z=+F.slope.toPrecision(4),I=`${z<0?"\u2212":""}${Pt(Math.abs(z))}`,R=A?I:`${I} ${g.unit??""}/${j.unit??""}`.trim(),H=F.intercept<0?"\u2212":"+";return`${W}y = ${R} x ${H} ${Ve(Math.abs(F.intercept),g.unit)}, R\xB2 ${F.r2.toFixed(3)}, n ${F.n.toLocaleString("en-GB")}`})}let w=!1;if(e.identity&&((j.unit??"")!==(g.unit??"")?a.push(`y = x is left off: ${j.label} and ${g.label} are in different units`):w=!0),Me={type:"scatter",points:N,...L?.length?{fits:L}:{},...w?{identity:!0}:{}},ut=Sn(N),te=ue("x",j.label,j.unit,e,N.map(O=>O.x),a),ce=ue("y",g.label,g.unit,e,N.map(O=>O.y),a),!i.inFacet){const O=[M?.field,e.fields?.facet].flatMap(F=>F&&"meta"in F?[F.meta]:[]),A=Mt(t.map(F=>({metadata:F.metadata,dieCount:F.dies.length})),{facetableOnly:!0,curation:i.curation}).filter(F=>F.splittable&&!O.includes(F.key)).map(F=>F.label);A.length&&a.push(`Mixed ${le(A)} across these points: a trend here may come from the groups' offset rather than the relationship (Simpson's paradox). Colour or panel by it, or keep one value with Only dies where`)}Oe=[He(j),He(g),L?.length?`${e.fit==="orthogonal"?"orthogonal (Deming) fit":"least-squares fit of Y on X"} per ${X>1&&!we?"colour":"plot"}`:void 0].filter(Boolean).join("; ")||void 0}else if(o==="histogram"){const m=be(g),x=Array.from({length:X},()=>[]),N=Array.from({length:X},()=>[]);for(let w=0;w<se;w++){if(!Number.isFinite(m[w])){$e(Ge(g,w));continue}x[ye[w]].push(m[w]),N[ye[w]].push(w),Re++}Me={type:"histogram",values:x,units:N,unit:Ke},te=ue("x",g.label,g.unit,e,x.flat(),a);const L=e.histNorm==="percent";ce={label:L?X>1?`Share of each colour's ${Ze}`:`Share of ${Ze}`:"Count",scale:"linear",...L?{unit:"%"}:{},...e.axes?.y?.label?{label:e.axes.y.label}:{}},e.normalCurve&&te.scale==="log"&&a.push("The normal curve is left off a log axis, where a normal distribution is not the shape its bars would follow"),Oe=[He(g),e.normalCurve&&te.scale!=="log"?`curve: the normal distribution with ${X>1?"each colour's":"the"} mean and standard deviation`:void 0].filter(Boolean).join("; ")||void 0}else if(o==="probability"){const m=be(g),x=Array.from({length:X},()=>[]);for(let w=0;w<se;w++){if(!Number.isFinite(m[w])){$e(Ge(g,w));continue}x[ye[w]].push(w),Re++}for(const w of x)w.sort((O,A)=>m[O]-m[A]);const N=x.map(w=>w.map(O=>m[O]));Me={type:"probability",values:N,units:x,unit:Ke},te=ue("x",g.label,g.unit,e,N.flat(),a);const L=e.probabilityAxis==="linear";ce={label:e.axes?.y?.label??"Cumulative share",scale:"linear"},Oe=[He(g),`each ${K==="die"?"die":"wafer"} at (rank \u2212 \xBD) / n of its ${X>1?"group":"population"}${L?"":", on a normal-probability scale"}`].filter(Boolean).join("; ")}else if(o==="line"){const m=be(j),x=be(g),N=new Set,L=new Map,w=new Map;for(let U=0;U<se;U++){if(!Number.isFinite(m[U])){$e(j.label);continue}if(!Number.isFinite(x[U])){$e(Ge(g,U));continue}N.add(m[U]);const q=`${ye[U]}|${m[U]}`;(L.get(q)??L.set(q,[]).get(q)).push(x[U]),Re++,(w.get(q)??w.set(q,[]).get(q)).push(U)}const O=[...N].sort((U,q)=>U-q),A=e.aggregate??"mean",F=Array.from({length:X},(U,q)=>O.map(de=>{const ne=L.get(`${q}|${de}`);return ne?combine(ne,A==="yield"?"mean":A):NaN})),W=Array.from({length:X},(U,q)=>O.map(de=>L.get(`${q}|${de}`)?.length??0)),z=Array.from({length:X},(U,q)=>O.map(de=>w.get(`${q}|${de}`)??[]));let I;const R=e.spread;if(R){if(g.perDie)return n(`A band shows how values spread, and ${g.label} is a share of passing dies, not a value: leave the band off`);if(A!=="mean"&&A!=="median")return n(`A band goes round a mean or a median, not ${xt[A]}`);const U=new Map,q=(ae,Ne,fe)=>{const Z=(L.get(`${ae}|${Ne}`)??[]).filter(Number.isFinite);if(Z.length===0)return[NaN,NaN];if(R==="minmax")return[je(Z),ze(Z)];if(R==="iqr"){const Te=Z.sort((Be,y)=>Be-y);return[$t(Te,.25),$t(Te,.75)]}if(Z.length<2)return[NaN,NaN];const _e=Z.reduce((Te,Be)=>Te+Be,0)/Z.length,Le=Math.sqrt(Ut(Z,_e));let Je=1;R==="ci95"&&(Je=U.get(Z.length-1)??vn(.05,Z.length-1),U.set(Z.length-1,Je));const et=R==="sd"?Le:Je*Le/Math.sqrt(Z.length);return[F[ae][fe]-et,F[ae][fe]+et]},de=F.map(()=>[]),ne=F.map(()=>[]);F.forEach((ae,Ne)=>O.forEach((fe,Z)=>{const[_e,Le]=q(Ne,fe,Z);de[Ne].push(_e),ne[Ne].push(Le)})),I={lo:de,hi:ne}}Me={type:"line",xs:O,values:F,counts:W,cellUnits:z,unit:Ke,...I?{band:I}:{}},te=ue("x",j.label,j.unit,e,O,a);const H=A==="yield"?"mean":A;ce=ue("y",g.perDie?g.label:`${Ye[H]} ${g.label}`,g.unit,e,F.flat(),a);const Y=K==="die"?"dies":"wafers",oe={sd:`\xB1 1 standard deviation of the ${Y}`,ci95:`the mean's 95% confidence interval (Student's t, n = ${Y})`,iqr:`the quartiles of the ${Y}`,minmax:`the range of the ${Y}`};Oe=(g.perDie?`passing dies over judged dies, per ${j.label.toLowerCase()}`:`${Ye[H].toLowerCase()} of ${g.label} per ${j.label}`)+(R?`; band: ${oe[R]} at each ${j.label.toLowerCase()}`:"")}else{const m=[],x=[];for(const y of P){const C="builtin"in y.field&&(y.field.builtin==="x"||y.field.builtin==="y");if(y.kind==="numeric"&&y.level==="die"&&!C)return n(`${y.label} is continuous, so a ${o} cannot have one ${o==="bar"?"bar":"box"} per value; use a scatter or line, or choose a categorical X such as wafer, ring or bin`);const E=y.cat?Lt(y):Array.from(be(y),ie=>Number.isFinite(ie)?Pt(ie):void 0),V=new Set,J=[];for(let ie=0;ie<se;ie++){const he=E[ie];he!==void 0&&!V.has(he)&&(V.add(he),J.push(he))}const me=Ue(y.field,J,Xe(y));m.push(E),x.push(new Map(me.map((ie,he)=>[ie,he])))}const N="",L=new Map,w=[],O=y=>{const C=[];for(let E=0;E<m.length;E++){const V=m[E][y];if(V===void 0)return{missing:E};C.push(V)}return C.join(N)};for(let y=0;y<se;y++){const C=O(y);typeof C=="string"&&!L.has(C)&&(L.set(C,0),w.push(C.split(N)))}w.sort((y,C)=>{for(let E=0;E<y.length;E++){const V=x[E].get(y[E])-x[E].get(C[E]);if(V)return V}return 0});const A=w.map(y=>y.join(" \xB7 "));w.forEach((y,C)=>L.set(y.join(N),C));const F=m.length===1?m[0]:void 0,W=o==="bar"&&!g,z=e.aggregate??(W?"count":g?.weights?"yield":"mean");if(z==="yield"&&!g?.weights)return n("Pooled yield needs Yield as the Y field");if(o==="box"&&z==="count")return n("A box plot needs a measured field for Y");const I=g?be(g):void 0,R=g?sn(g):void 0,H=Array.from({length:X},()=>A.map(()=>[])),Y=Array.from({length:X},()=>A.map(()=>[])),oe=Array.from({length:X},()=>A.map(()=>[]));for(let y=0;y<se;y++){const C=O(y);if(typeof C!="string"){$e(P[C.missing].label);continue}const E=L.get(C);if(I&&!Number.isFinite(I[y])){$e(Ge(g,y));continue}H[ye[y]][E].push(I?I[y]:1),Y[ye[y]][E].push(y),R&&oe[ye[y]][E].push(R[y]),Re++}const U=H.map((y,C)=>y.map((E,V)=>{if(E.length===0)return NaN;if(z==="yield"){const J=oe[C][V],me=J.reduce((ie,he)=>ie+he,0);return me>0?E.reduce((ie,he,ln)=>ie+he*J[ln],0)/me:NaN}return combine(E,z)})),q=o==="bar"&&(z==="count"||z==="sum");if(e.stack&&o!=="bar")return n("Only a bar chart stacks its colours");if(e.stack&&!q)return n(`Stacking adds the colours' values, which means something for a count or a sum, not ${xt[z]}: combine by count or sum, or draw the colours side by side`);if(e.cumulative&&!(q&&e.sort==="value"))return n("A cumulative line needs a bar of counts or sums sorted by value, largest first");if(e.barNorm==="percent"&&!q)return n(`A share of each colour's total means something for a count or a sum, not ${xt[z]}: combine by count or sum`);if(e.barNorm==="percent"&&e.stack)return n("Bars are either stacked or each colour's share of its own total, not both");if(e.barNorm==="percent"&&q)for(let y=0;y<X;y++){const C=U[y].reduce((E,V)=>E+(Number.isFinite(V)?V:0),0);U[y]=U[y].map(E=>Number.isFinite(E)&&C>0?E/C*100:NaN)}if((e.sort||e.top)&&P.length>1)return n("Sorting by value and keeping the top categories need one category field on X");const de=y=>{if(o==="box"){const E=H.flatMap(V=>V[y]);return E.length?combine(E,"median"):NaN}if(q||e.barNorm==="percent"){let E=0,V=!1;for(const J of U)Number.isFinite(J[y])&&(E+=J[y],V=!0);return V?E:NaN}const C=H.flatMap(E=>E[y]);if(C.length===0)return NaN;if(z==="yield"){const E=oe.flatMap(J=>J[y]),V=E.reduce((J,me)=>J+me,0);return V>0?C.reduce((J,me,ie)=>J+me*E[ie],0)/V:NaN}return combine(C,z)},ne=A.map((y,C)=>de(C));let ae=A.map((y,C)=>C);e.sort==="value"&&ae.sort((y,C)=>(Number.isFinite(ne[C])?ne[C]:-1/0)-(Number.isFinite(ne[y])?ne[y]:-1/0)),e.sort==="ascending"&&ae.sort((y,C)=>(Number.isFinite(ne[y])?ne[y]:1/0)-(Number.isFinite(ne[C])?ne[C]:1/0));const Ne=ne.reduce((y,C)=>y+(Number.isFinite(C)?C:0),0);e.top&&e.top<ae.length&&(a.push(`Showing the first ${e.top} of ${ae.length} ${P[0].label.toLowerCase()} values${e.sort==="value"?", largest first":e.sort==="ascending"?", smallest first":""}`),ae=ae.slice(0,e.top));const fe=y=>ae.map(C=>y[C]);A.splice(0,A.length,...fe(A));for(let y=0;y<X;y++)H[y]=fe(H[y]),Y[y]=fe(Y[y]),U[y]=fe(U[y]);const Z=fe(ne);if(w.length&&w.splice(0,w.length,...fe(w)),e.stack==="percent")for(let y=0;y<X;y++)U[y]=U[y].map((C,E)=>Number.isFinite(C)&&Z[E]>0?C/Z[E]*100:NaN);let _e=0;const Le=e.cumulative&&Ne>0?Z.map(y=>(_e+=Number.isFinite(y)?y:0,_e/Ne*100)):void 0,et=!!F&&"builtin"in P[0].field&&P[0].field.builtin==="wafer"?A.map(y=>F.findIndex((C,E)=>C===y&&E>=0)):void 0,Te=P.length>1?{levels:P.map(y=>y.label),parts:w}:void 0;Me={type:o==="box"?"box":"bar",categories:A,cells:H,cellUnits:Y,unit:Ke,values:U,categoryItems:et?.map(y=>b(K==="die"?T.item[y]:y)),...Te?{nest:Te}:{},...e.stack&&X>1?{stack:e.stack}:{},...Le?{cumulative:Le}:{},...o==="bar"&&K==="die"&&g?.perDie?{passFail:g.failSide?.some(y=>y!==0)?{failSide:g.failSide}:{}}:{}};const Be=le(P.map(y=>y.label.toLowerCase()));if(te={label:e.axes?.x?.label??P.map(y=>y.label).join(" \u203A "),scale:"linear"},o==="bar"){const y=z==="count"?"Count":Ye[z],C=W?`Count of ${Ze}`:z==="yield"?"passRate"in g.field?g.label:"Pooled yield":`${y} ${g.label}`,E=e.stack==="percent"&&X>1,V=e.barNorm==="percent",J=W?Ze:C.toLowerCase(),me=E?`Share of each ${P[0].label.toLowerCase()}'s ${J}`:V?X>1?`Share of each ${Ae?Ae.toLowerCase():"colour"}'s ${J}`:`Share of ${J}`:C,ie=E?[0,100]:e.stack&&X>1?Z.filter(Number.isFinite):U.flat();ce=ue("y",me,E||V||z==="yield"?"%":z==="count"?void 0:g?.unit,e,ie,a),Oe=W?void 0:z==="yield"?`passing dies over judged dies, pooled per ${Be}`:`${y.toLowerCase()} of ${g.label}${g.level==="die"&&K==="wafer"?" per wafer":""} per ${Be}`}else ce=ue("y",g.label,g.unit,e,H.flat(2),a),Oe=He(g)}const ct=(m,x)=>m&&!m.perDie&&(x===void 0||x==="mean"||x==="median"||x==="min"||x==="max")?m.limits:void 0,on=e.aggregate??"mean";te&&(o==="scatter"||o==="line")&&(te.limits=ct(j)),ce&&o!=="histogram"&&(ce.limits=ct(g,o==="scatter"||o==="box"?void 0:on)),G&&te&&(te.limits=ct(g));const an=()=>{const m=g?.label,x=P.filter(w=>!Se(w.field)),N=o==="box"||o==="bar"?x.length?le(x.map(w=>w.label)):void 0:j?.label,L=o==="scatter"?`${m} vs ${N}`:o==="histogram"?`${m}`:o==="probability"?`${m}, cumulative`:o==="line"?`${m} over ${N}`:N?o==="box"?`${m} by ${N}`:m?`${m} by ${N}`:`Dies by ${N}`:`${m}`;return Ae&&M&&!_.some(w=>ke(M.field,w))&&!Se(M.field)?`${L} \xB7 by ${Ae}`:L},It=[];let dt;const Ct=c?c.tests.map((m,x)=>({field:c.labels[x],test:m})):[];for(const m of new Set([...P,c?void 0:g,M]))m&&"test"in m.field&&Ct.push({field:m.label,test:m.field.test});for(const{field:m,test:x}of Ct){let N=0;for(const L of f)dn(L,x)!==void 0&&(N++,dt??=mn(cn(L)));N>0&&It.push({field:m,count:N})}let mt;if((o==="box"||o==="bar")&&!c&&g&&"test"in g.field&&g.level==="die"&&g.num&&!g.perDie){const m=N=>!!N&&N.level==="wafer"&&N.kind==="categorical"&&!!N.cat&&!("builtin"in N.field&&(N.field.builtin==="wafer"||N.field.builtin==="test")),x=P.length===1&&m(P[0])?P[0]:!De&&m(M)?M:void 0;if(x){const N=new Float64Array(t.length),L=new Uint32Array(t.length);for(let A=0;A<T.dies.length;A++){const F=g.num[A];Number.isFinite(F)&&(N[T.item[A]]+=F,L[T.item[A]]++)}const w=new Map;t.forEach((A,F)=>{const W=x.cat[F];W===void 0||L[F]===0||(w.get(W)??w.set(W,[]).get(W)).push(N[F]/L[F])});const O=[...w.keys()].sort(Dt);O.length>=2&&(mt={by:x.label,result:kn(O.map(A=>({key:A,values:w.get(A)})))})}}let ht;if(e.whatIf){if(!(o==="histogram"||o==="probability"))return n("What-if limits go on a histogram or a probability plot of one test");if(c||!g||!("test"in g.field))return n("What-if limits need one measured test as the values");if(e.normalize)return n("What-if limits are in the test's own unit: turn rescaling off to set them");const m=g.field.test,x=u.find(Y=>Y.testNumber===m),N=x?.limitLow??-1/0,L=x?.limitHigh??1/0,w=e.whatIf.lo??x?.limitLow??-1/0,O=e.whatIf.hi??x?.limitHigh??1/0;let A=0,F=0,W=0;for(let Y=0;Y<T.dies.length;Y++){const oe=nt(T.dies[Y],m);oe===void 0||!Number.isFinite(oe)||!Et(T.dies[Y])||(A++,oe>=N&&oe<=L&&F++,oe>=w&&oe<=O&&W++)}const z=Y=>A?`${(Y/A*100).toFixed(1)}%`:"\u2014",I=`${Number.isFinite(w)?Ve(w,g.unit):"\u2212\u221E"} to ${Number.isFinite(O)?Ve(O,g.unit):"\u221E"}`,R=W-F,H=`what-if: ${g.label} passes ${z(F)} of ${A.toLocaleString("en-GB")} dies by its test limits, ${z(W)} from ${I} (${R===0?"no die changes":`${R>0?"+":"\u2212"}${Math.abs(R).toLocaleString("en-GB")} dies`})`;ht={...Number.isFinite(w)?{lo:w}:{},...Number.isFinite(O)?{hi:O}:{},judged:A,passNow:F,passThen:W,sentence:H},te&&(te.limits={...te.limits,...e.whatIf.lo!==void 0?{whatIfLow:e.whatIf.lo}:{},...e.whatIf.hi!==void 0?{whatIfHigh:e.whatIf.hi}:{}})}const rn=[...P,g,M].some(m=>!!m&&"builtin"in m.field&&m.field.builtin==="pat")||[te,ce].some(m=>m?.limits?.patLow!==void 0||m?.limits?.patHigh!==void 0);return{spec:e,issues:[],notes:a,marks:Me,level:K,...mt?{comparison:mt}:{},...rn?{usesPat:!0}:{},...ft?.length?{fitNotes:ft}:{},...ht?{whatIf:ht}:{},...dt?{excluded:{limitSet:dt,fields:It}}:{},autoTitle:an(),x:te,y:ce,groups:Qe,colorScale:Tt,colorLabel:Ae,aggregation:Oe,...ut?{correlation:ut}:{},...M&&!De&&"builtin"in M.field&&(M.field.builtin==="hbin"||M.field.builtin==="sbin")?{colorBins:M.field.builtin==="hbin"?"hard":"soft"}:{},...M&&_.some(m=>ke(M.field,m))?{colorRepeatsX:!0}:{},...e.normalize&&l?{normalization:Hn(e.normalize,p)}:{},population:{wafers:t.length,dies:f.length},...c?{setTests:{tests:c.tests,labels:c.labels}}:{},plotted:Re,omitted:[...lt].map(([m,x])=>({field:m,count:x}))}}export function plotTitle(e){return e.spec.title?.trim()?e.spec.title:e.autoTitle}function ti(e,t){const i=t.groups.map(r=>`${r.key} ${r.n}`).join(", "),s=`by ${e.toLowerCase()}, wafer means (wafers: ${i})`;if(!t.welch&&!t.kruskal)return`${s}: ${t.issue?.toLowerCase()??"not comparable"}`;const n=t.welch?`${t.welch.method==="welch-t"?"Welch t":"Welch ANOVA"} p ${Gt(t.welch.p)}`:void 0,o=t.kruskal?`rank p ${Gt(t.kruskal.p)}${t.kruskal.approximate?" (approximate)":""}`:void 0;return`${s}: ${[n,o].filter(Boolean).join(", ")}`}export function plotFootnote(e){const{wafers:t,dies:i}=e.population,s=[`${t.toLocaleString("en-GB")} wafer${t===1?"":"s"} \xB7 ${i.toLocaleString("en-GB")} dies`];if(e.leftOut){const{partial:n,edge:o}=e.leftOut,r=(u,f)=>`${u.toLocaleString("en-GB")} ${f} di${u===1?"e":"es"}`;s.push(`${le([...o?[r(o,"edge-excluded")]:[],...n?[r(n,"partial")]:[]])} left out, as a yield leaves them out`)}e.filterNote&&s.push(e.filterNote),e.whatIf&&s.push(e.whatIf.sentence),e.aggregation&&s.push(e.aggregation),e.correlation&&s.push(`${e.correlation.r===null?"":`r = ${e.correlation.r.toFixed(3)} \xB7 `}n = ${e.correlation.n.toLocaleString("en-GB")}`),e.normalization&&s.push(e.normalization),e.comparison&&s.push(ti(e.comparison.by,e.comparison.result)),e.usesPat&&s.push(`PAT per wafer: median \xB1 ${Dn} \xD7 (Q3 \u2212 Q1) / 1.35 of its passing dies, within the test's limits`),e.facets&&s.push(`${e.facets.length} panels by ${e.facetLabel.toLowerCase()}, on shared axes`);for(const n of e.omitted)s.push(`${n.count.toLocaleString("en-GB")} ${e.level==="die"?"dies":"wafers"} without ${n.field} not plotted`);if(e.excluded)for(const n of e.excluded.fields)s.push(`${n.count.toLocaleString("en-GB")} ${n.field} value${n.count===1?"":"s"} outside ${e.excluded.limitSet} excluded`);return s.join(" \xB7 ")}export function plotGuideSections(e){const{spec:t}=e,i=t.fields??{},s=[...xe(i.x),i.y,i.color,i.rows,i.facet],n=[ni[t.chart],e.comparison&&ve.groups,(e.fitNotes?.length||t.identity&&e.marks?.type==="scatter")&&ve.fit,e.marks?.type==="line"&&e.marks.band&&ve.bands,e.normalization&&ve.rescaling,(s.some(We)||e.facets||e.whatIf)&&ve.ranges];return[...new Set(n.filter(o=>!!o))]}const ni={probability:ve.probability,control:ve.control,goal:ve.goal,heatmap:ve.heatmap};export function fieldKey(e){return We(e)?`binned:${fieldKey(e.binned)}`:re(e)?`${e.passRate?`passRates:${e.judge??"limits"}`:"tests"}:${e.tests.join(",")}`:"passRate"in e?`passRate:${e.passRate}${e.judge==="flag"?":flag":""}`:"test"in e?`test:${e.test}`:"builtin"in e?`builtin:${e.builtin}`:`meta:${e.meta}`}export function fieldCatalogue(e,t={}){const i=[],s=e.flatMap(l=>l.dies),n=new Set(s.length?it(s,"values"):[]),o=t.testDefs??[],r=new Map;for(const l of o)l.testType!=="F"&&(n.has(l.testNumber)||!s.length)&&r.set(l.testNumber,l.name);for(const l of n)!r.has(l)&&!o.some(p=>p.testNumber===l&&p.testType==="F")&&r.set(l,void 0);for(const[l,p]of[...r].sort(($,b)=>$[0]-b[0]))i.push({field:{test:l,...p?{name:p}:{}},label:p?`${p} \xB7 ${l}`:`Test ${l}`,name:p||`Test ${l}`,group:"Tests",kind:"numeric",level:"die",categorical:!1});r.size>=2&&i.push({field:{builtin:"test"},label:Ce.test,name:Ce.test,group:"Tests",kind:"categorical",level:"wafer",categorical:!0});const u=new Set(s.length?it(s,"all"):[]);for(const l of o){if(pe(l)||!(u.has(l.testNumber)||!s.length))continue;const p=l.name||`Test ${l.testNumber}`;i.push({field:{test:l.testNumber,...l.name?{name:l.name}:{}},label:`${p} \xB7 ${l.testNumber} (pass/fail)`,name:p,group:"Verdicts",kind:"categorical",level:"die",categorical:!0})}for(const l of o){if(!(pe(l)?(l.limitLow!==void 0||l.limitHigh!==void 0)&&(n.has(l.testNumber)||!s.length):u.has(l.testNumber)||!s.length))continue;const $=l.name||`Test ${l.testNumber}`;i.push({field:{passRate:l.testNumber,...l.name?{name:l.name}:{}},label:`${$} \xB7 ${l.testNumber} pass rate`,name:`${$} pass rate`,group:"Pass rates",kind:"numeric",level:"die",categorical:!1})}const f=l=>s.some(l),a=(l,p,$)=>i.push({field:{builtin:l},label:Ce[l],name:Ce[l],group:"Die",kind:p,level:"die",categorical:$});f(l=>tt(l))&&(a("x","numeric",!1),a("y","numeric",!1)),e.some(l=>l.wafer)&&f(l=>tt(l)&&l.physX!==void 0)&&a("radius","numeric",!1);const d=f(l=>tt(l));for(const l of un)e.some(p=>Pe[l].available({wafer:p.wafer,ringCount:p.ringCount},d))&&a(l,"categorical",!0);f(l=>l.hbin!==void 0)&&a("hbin","categorical",!0),f(l=>l.sbin!==void 0)&&a("sbin","categorical",!0),f(l=>l.siteNum!==void 0)&&a("site","categorical",!0),s.length&&Wt(o.filter(l=>n.has(l.testNumber))).length&&a("pat","categorical",!0);const h=(l,p,$)=>i.push({field:{builtin:l},label:Ce[l],name:Ce[l],group:"Wafer",kind:p,level:"wafer",categorical:$});h("wafer","categorical",!0),e.length>1&&h("waferOrder","numeric",!1),h("yield","numeric",!1),h("dieCount","numeric",!1);const c={items:e,rows:{dies:[],item:new Uint32Array(0)},ctx:t};for(const l of Mt(e.map(p=>({metadata:p.metadata,dieCount:p.dies.length})),{facetableOnly:!0,curation:t.curation})){if(l.values.length===0)continue;const p=ee({meta:l.key},c);i.push({field:{meta:l.key},label:l.label||pt(l.key,t.curation),name:l.label||pt(l.key,t.curation),group:"Wafer",kind:p.kind,level:"wafer",categorical:!0,distinct:l.values.length})}return i}export function fieldExtent(e,t,i={}){const s=ee(e,{items:t,rows:ge(t),ctx:i});if(s.issue||!s.num)return;let n=1/0,o=-1/0;for(let r=0;r<s.num.length;r++){const u=s.num[r];Number.isFinite(u)&&(u<n&&(n=u),u>o&&(o=u))}return n===1/0?void 0:[n,o]}export function fieldValues(e,t,i={}){const s=ee(e,{items:t,rows:ge(t),ctx:i});if(s.issue||!s.cat)return[];const n=[];for(const o of s.cat)o!==void 0&&!n.includes(o)&&n.push(o);return Ue(e,n,Xe(s))}export function fieldsForRole(e,t,i){if(t==="control"&&i==="x")return e.filter(n=>n.kind==="numeric"&&n.level==="wafer");const s=i==="y"||i==="x"&&(t==="scatter"||t==="line"||t==="histogram");return i==="color"?e.filter(n=>n.categorical||t==="scatter"&&n.kind==="numeric"):s?e.filter(n=>n.kind==="numeric"&&(i==="y"||n.group!=="Pass rates")):e.filter(n=>n.categorical)}export function defaultPlot(e,t){const i=e.filter(s=>s.group==="Tests"&&"test"in s.field);return i.length>=2?{id:t,chart:"scatter",fields:{x:i[0].field,y:i[1].field}}:i.length===1?{id:t,chart:"histogram",fields:{y:i[0].field}}:{id:t,chart:"scatter",fields:{x:{builtin:"waferOrder"},y:{builtin:"yield"}}}}const kt=new Set(["wafer","dies","die x","die y","wafer order"]),ii=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),St=(e,t)=>t.length>=3&&new RegExp(`(^|[^A-Za-z0-9_])${ii(t)}($|[^A-Za-z0-9_])`,"i").test(e);export function titleDrift(e,t){const i=e.title?.trim(),s={names:[],omits:[]};if(!i)return s;const n=e.fields?.color,o=[...xe(e.fields?.x),e.fields?.y,n,e.fields?.facet].filter(l=>Ie(l)),r=l=>o.some(p=>ke(p,l)),u=t.filter(l=>!kt.has(l.name.toLowerCase())&&!("meta"in l.field)&&!r(l.field)&&St(i,l.name)).map(l=>l.name),f=[...xe(e.fields?.x),e.fields?.y].filter(l=>Ie(l)),a=l=>t.find(p=>ke(p.field,l))?.name??fieldLabel(l),d=f.filter(l=>!kt.has(a(l).toLowerCase())&&St(i,a(l))),h=f.filter(l=>!kt.has(a(l).toLowerCase())&&!St(i,a(l))),c=d.length>0||u.length>0?h.map(a):[];return{names:u,omits:c}}export function describeTitleDrift(e){const t=[];return e.names.length&&t.push(`The title names ${le(e.names)}, which this plot does not show.`),e.omits.length&&t.push(`It does not name ${le(e.omits)}, which this plot shows.`),t.length?t.join(" "):null}function si(e,t={}){const i=ge(e),s=ee({builtin:"ring"},{items:e,rows:i,ctx:t});if(s.issue||!s.cat)return;const n=new Map;let o=0,r=0;for(let a=0;a<i.dies.length;a++){const d=s.cat[a];if(d===void 0)continue;const h=bt([i.dies[a]],e[i.item[a]].passBins),c=n.get(d)??{pass:0,total:0};c.pass+=h.pass,c.total+=h.total,o+=h.pass,r+=h.total,n.set(d,c)}let u,f=r?o/r*100-1:-1/0;for(const[a,d]of n)d.total&&d.pass/d.total*100<f&&(f=d.pass/d.total*100,u=a);return u}function oi(e,t){if(!t||e.length<2)return e[0];const i=ge(t.items);let s=e[0],n=1/0;for(const o of e){const r=ee({passRate:o.d.testNumber},{items:t.items,rows:i,ctx:t.ctx??{}});if(!r.num||!r.weights)continue;let u=0,f=0;for(let a=0;a<r.num.length;a++)r.weights[a]&&(f++,u+=r.num[a]/100);f&&u/f<n&&(n=u/f,s=o)}return s}export function examplePlots(e,t,i,s){const n=e.filter(S=>S.group==="Tests"&&"test"in S.field),o=e.flatMap(S=>"meta"in S.field?[S.field.meta]:[]),r=s?Nn(s.items,n.map(S=>S.field.test),o,s.ctx?.curation):void 0,u=new Map(n.map(S=>[S.field.test,S])),f=r?[...r.ranked.map(S=>u.get(S)).filter(Boolean).filter(S=>S.field.test!==r.partner)]:n;r?.partner!==void 0&&f.length&&f.splice(1,0,u.get(r.partner));const a=f.map(S=>S.field),d=[],h=t>1,c=S=>e.some(P=>"builtin"in P.field&&P.field.builtin===S),l=(r?.splitKey?e.find(S=>"meta"in S.field&&S.field.meta===r.splitKey):void 0)??e.find(S=>"meta"in S.field&&S.distinct!==void 0&&S.distinct>=2&&S.distinct<=Math.max(2,Math.floor(t/2))),p=S=>d.push({id:i(),...S}),$=f.length>=2?{tests:f.slice(0,8).map(S=>S.field.test),names:Object.fromEntries(f.slice(0,8).map(S=>[String(S.field.test),S.name]))}:void 0,b=l?.field,v={color:b??(c("ring")?{builtin:"ring"}:void 0)??{none:!0}},k={color:b??{none:!0}};a.length>=2&&p({chart:"scatter",fields:{x:a[0],y:a[1],...b?{color:b}:{}},fit:"linear"}),a.length>=1&&p({chart:"histogram",fields:{y:a[0],...v},normalCurve:!0}),a.length>=1&&h&&p({chart:"box",fields:{x:{builtin:"wafer"},y:a[0],...k},axes:{y:{references:[{stat:"median"}]}}}),h&&p({chart:"bar",fields:{x:b??{builtin:"wafer"},y:{builtin:"yield"},color:b??{none:!0}}});const _=h&&c("ring")&&s?si(s.items,s.ctx):void 0;_&&p({chart:"bar",fields:{x:{builtin:"wafer"},y:{builtin:"yield"},color:{none:!0}},where:{conditions:[{field:{builtin:"ring"},values:[_]}]}}),a.length>=1&&h&&p({chart:"line",fields:{x:{builtin:"waferOrder"},y:a[0],color:{none:!0}},aggregate:"mean",spread:"sd"}),a.length>=1&&p({chart:"probability",fields:{y:a[0]}}),$&&p({chart:"box",fields:{x:{builtin:"test"},y:$,...k},normalize:"zscore"}),$&&h&&p({chart:"heatmap",fields:{x:{builtin:"wafer"},y:$},aggregate:"mean",normalize:"zscore"}),a.length>=1&&b&&p({chart:"box",fields:{x:b,y:a[0],color:b}}),a.length>=1&&b&&p({chart:"box",fields:{x:[b,{builtin:"wafer"}],y:a[0],color:b}}),a.length>=1&&c("ring")&&p({chart:"histogram",fields:{y:a[0],...k,facet:{builtin:"ring"}}}),a.length>=2&&p({chart:"box",fields:{x:{binned:a[1],bins:5},y:a[0],...v}}),a.length>=1&&c("radius")&&p({chart:"box",fields:{x:{binned:{builtin:"radius"},bins:6,by:"width"},y:a[0],...k}}),c("hbin")&&p({chart:"bar",fields:{x:{builtin:"hbin"},color:{none:!0}},sort:"value",cumulative:!0}),c("hbin")&&h&&p({chart:"bar",fields:{x:{builtin:"wafer"},color:{builtin:"hbin"}},stack:"percent"}),a.length>=1&&c("pat")&&p({chart:"box",fields:{x:{builtin:"pat"},y:a[0],color:{builtin:"pat"}}});const B=e.find(S=>S.group==="Verdicts");a.length>=1&&B&&p({chart:"box",fields:{x:B.field,y:a[0],color:B.field}}),a.length>=1&&t>=5&&p({chart:"control",fields:{x:{builtin:"waferOrder"},y:a[0]}});const Q=s?.ctx?.testDefs??[],D=a.flatMap(S=>{const P="test"in S?Q.find(j=>j.testNumber===S.test):void 0;return P&&pe(P)?[{f:S,d:P}]:[]});D.some(({d:S})=>S.limitLow!==void 0&&S.limitHigh!==void 0)&&p({chart:"goal",fields:l?{color:l.field}:{}});const G=oi(D.filter(({d:S})=>S.limitLow!==void 0||S.limitHigh!==void 0).slice(0,8),s);if(G&&h&&p({chart:"bar",fields:{x:l?l.field:{builtin:"wafer"},y:{passRate:G.f.test,...G.d.name?{name:G.d.name}:{}},color:{none:!0}}}),G&&G.d.limitLow!==void 0&&G.d.limitHigh!==void 0){const S=(G.d.limitHigh-G.d.limitLow)*.1;p({chart:"histogram",fields:{y:G.f,color:{none:!0}},whatIf:{lo:G.d.limitLow-S,hi:G.d.limitHigh+S}})}return a.length>=2&&d.push({...en(n.map(S=>S.field).flatMap(S=>"test"in S?[S]:[]),i()),title:"Example sweep"}),d}export function plotTestNumber(e){const{x:t,y:i,color:s}=e.fields??{},n=e.chart==="scatter"?[t,i,s]:e.chart==="histogram"||e.chart==="probability"?[i,t]:[i];for(const o of n){if(Ie(o)&&"test"in o)return o.test;if(re(o)){const r=o.tests[0],u=typeof r=="number"?r:parseInt(String(r),10);if(Number.isInteger(u))return u;continue}if(Ie(o)&&"passRate"in o)return o.passRate}}export function defaultSweep(e,t){return en(e.filter(pe).map(i=>({test:i.testNumber,name:i.name})),t)}function en(e,t){const i=[...e].sort((n,o)=>n.test-o.test).slice(0,5),s=Object.fromEntries(i.flatMap(n=>n.name?[[String(n.test),n.name]]:[]));return{id:t,chart:"sweep",sweep:{series:[{label:"Series 1",tests:i.map(n=>n.test),...Object.keys(s).length?{testNames:s}:{}}]}}}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/** A new plot id: unique across a session and, with the random part, across files. */
|
|
2
2
|
export declare function newPlotId(): string;
|
|
3
|
+
/** A new saved-filter id, unique across a session and, with the random part, across files. */
|
|
4
|
+
export declare function newFilterId(): string;
|
|
3
5
|
//# sourceMappingURL=plotId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
let r=0;export function newPlotId(){const t=Math.floor(Math.random()*4294967296).toString(36).padStart(7,"0");return`plot-${Date.now().toString(36)}-${t}-${(r++).toString(36)}`}export function newFilterId(){return newPlotId().replace(/^plot-/,"filter-")}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text a reader types for an axis's reference lines and bands, and the reverse: `0.45 Target, 0.3..0.5 Window,
|
|
3
|
+
* median`. A number alone is a line; `lo..hi` is a band between two values; `median` or `mean` is a line at that
|
|
4
|
+
* statistic of what the plot draws; any words after it are its label. Values are in the
|
|
5
|
+
* axis's own unit, as the limits and what-if limits are. At most `PLOT_REFERENCES_MAX` per axis.
|
|
6
|
+
*/
|
|
7
|
+
import type { PlotReference } from './plotSpec.js';
|
|
8
|
+
export type ParsedReferences = {
|
|
9
|
+
ok: true;
|
|
10
|
+
value: PlotReference[];
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
error: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function parseReferences(text: string): ParsedReferences;
|
|
16
|
+
export declare function formatReferences(refs: readonly PlotReference[] | undefined): string;
|
|
17
|
+
//# sourceMappingURL=plotReferences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PLOT_REFERENCES_MAX as u,PLOT_REFERENCE_STATS as l,isStatReference as m}from"./plotSpec.js";const d=String.raw`[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?`,E=new RegExp(String.raw`^(${d})(?:\s*\.\.\s*(${d}))?(?:\s+(.+))?$`),$=new RegExp(String.raw`^(${l.join("|")})(?:\s+(.+))?$`,"i");export function parseReferences(s){const e=s.split(/[;,]/).map(n=>n.trim()).filter(Boolean);if(e.length>u)return{ok:!1,error:`At most ${u} lines or bands on an axis`};const i=[];for(const n of e){const r=$.exec(n);if(r){i.push({stat:r[1].toLowerCase(),...r[2]?{label:r[2].trim()}:{}});continue}const t=E.exec(n);if(!t)return{ok:!1,error:`"${n}": write a number, a range such as 0.3..0.5, or median or mean, then an optional name`};const a=Number(t[1]),o=t[2]===void 0?void 0:Number(t[2]);if(o!==void 0&&o===a)return{ok:!1,error:`"${n}": a band needs two different values`};const[c,f]=o!==void 0&&o<a?[o,a]:[a,o];i.push({at:c,...f!==void 0?{to:f}:{},...t[3]?{label:t[3].trim()}:{}})}return{ok:!0,value:i}}export function formatReferences(s){return(s??[]).map(e=>`${m(e)?e.stat:e.to!==void 0?`${e.at}..${e.to}`:e.at}${e.label?` ${e.label}`:""}`).join(", ")}
|
|
@@ -7,9 +7,9 @@ export declare const PLOTS_VERSION = 1;
|
|
|
7
7
|
export declare const SWEEPS_FORMAT = "tsmap-sweeps";
|
|
8
8
|
/** A sweep's own definition: a `SweepSpec` without the `id` and `title` the plot already carries. */
|
|
9
9
|
export type SweepPayload = Omit<SweepSpec, 'id' | 'title'>;
|
|
10
|
-
export declare const PLOT_CHARTS: readonly ["scatter", "histogram", "box", "bar", "line", "sweep"];
|
|
10
|
+
export declare const PLOT_CHARTS: readonly ["scatter", "histogram", "box", "bar", "line", "sweep", "probability", "control", "goal", "heatmap"];
|
|
11
11
|
export type PlotChart = (typeof PLOT_CHARTS)[number];
|
|
12
|
-
export declare const PLOT_BUILTINS: readonly ["wafer", "x", "y", "ring", "quadrant", "reticleCell", "reticleShot", "hbin", "sbin", "site", "yield", "dieCount", "waferOrder"];
|
|
12
|
+
export declare const PLOT_BUILTINS: readonly ["wafer", "x", "y", "ring", "quadrant", "reticleCell", "reticleShot", "hbin", "sbin", "site", "yield", "dieCount", "waferOrder", "test", "pat", "radius"];
|
|
13
13
|
export type PlotBuiltin = (typeof PLOT_BUILTINS)[number];
|
|
14
14
|
/** A series a plot can put on an axis or use for colour. */
|
|
15
15
|
export type PlotField =
|
|
@@ -24,11 +24,96 @@ export type PlotField =
|
|
|
24
24
|
/** A wafer or lot metadata key (split, slot, temperature…). */
|
|
25
25
|
| {
|
|
26
26
|
meta: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Several measured tests read as one series of values, each value labelled with its test: the Y of a box, bar, line
|
|
30
|
+
* or histogram, divided by the `test` builtin on X or Colour. Entries are test numbers or ranges such as
|
|
31
|
+
* `"1010..1030"`, the syntax a sweep's tests use. `names` holds the name each test had when the plot was made, the
|
|
32
|
+
* same check a single test's `name` is.
|
|
33
|
+
*/
|
|
34
|
+
| PlotTestSet
|
|
35
|
+
/**
|
|
36
|
+
* A test's pass rate: each die 100 when it passes the test and 0 when it fails (a parametric test judged by its test
|
|
37
|
+
* limits, a functional one by its recorded verdict), so a bar or line of it is the share of judged dies that pass.
|
|
38
|
+
* `name` is checked as a test field's is.
|
|
39
|
+
*/
|
|
40
|
+
| {
|
|
41
|
+
passRate: number;
|
|
42
|
+
name?: string;
|
|
43
|
+
judge?: PlotJudge;
|
|
44
|
+
} | PlotBinnedField;
|
|
45
|
+
/**
|
|
46
|
+
* How a pass rate judges a die: `limits` (the default) a parametric test's measured value against its test limits;
|
|
47
|
+
* `flag` the pass or fail the tester recorded (STDF's own flag, which exists whether or not limits do). A functional
|
|
48
|
+
* test has only its recorded verdict, and is judged by it either way.
|
|
49
|
+
*/
|
|
50
|
+
export declare const PLOT_JUDGES: readonly ["limits", "flag"];
|
|
51
|
+
export type PlotJudge = (typeof PLOT_JUDGES)[number];
|
|
52
|
+
/**
|
|
53
|
+
* Several tests as one series. `passRate`: each test's pass rate (each die 100 or 0, as a single test's pass rate is)
|
|
54
|
+
* instead of its measured values, judged by `judge`.
|
|
55
|
+
*/
|
|
56
|
+
export interface PlotTestSet {
|
|
57
|
+
tests: Array<number | string>;
|
|
58
|
+
names?: Record<string, string>;
|
|
59
|
+
passRate?: true;
|
|
60
|
+
judge?: PlotJudge;
|
|
61
|
+
}
|
|
62
|
+
/** A set of tests read as pass rates. */
|
|
63
|
+
export declare const isPassRateSet: (f: unknown) => f is PlotTestSet & {
|
|
64
|
+
passRate: true;
|
|
27
65
|
};
|
|
66
|
+
export declare const PLOT_BIN_BY: readonly ["count", "width"];
|
|
67
|
+
/** Fewest and most bins a binned field takes, and how many it takes when it does not say. */
|
|
68
|
+
export declare const PLOT_BINS_MIN = 2, PLOT_BINS_MAX = 20, PLOT_BINS_DEFAULT = 5;
|
|
69
|
+
/**
|
|
70
|
+
* A continuous field cut into ranges, so it can be a category: the X of a box or bar, a colour, a heatmap's rows or
|
|
71
|
+
* columns, the panels. `binned` is a measured test, a die position (radius, X, Y) or a wafer figure (yield, a lot field
|
|
72
|
+
* of numbers); `bins` how many ranges (default 5); `by` whether each range holds about the same number of values
|
|
73
|
+
* (`'count'`, the default: quintiles, deciles) or spans the same width (`'width'`). The edges are set over the whole
|
|
74
|
+
* population plotted, so every panel and every colour shares them.
|
|
75
|
+
*/
|
|
76
|
+
export interface PlotBinnedField {
|
|
77
|
+
binned: PlotField;
|
|
78
|
+
bins?: number;
|
|
79
|
+
by?: (typeof PLOT_BIN_BY)[number];
|
|
80
|
+
}
|
|
81
|
+
/** A binned field. */
|
|
82
|
+
export declare const isBinned: (f: unknown) => f is PlotBinnedField;
|
|
83
|
+
/** The most reference lines and bands one axis carries. */
|
|
84
|
+
export declare const PLOT_REFERENCES_MAX = 8;
|
|
85
|
+
/**
|
|
86
|
+
* A line the reader draws on a value axis: at `at`, or a shaded band from `at` to `to`. Values are in the axis's own
|
|
87
|
+
* unit, as measured (or as rescaled, when the plot is). `label` names it on the chart; absent = the value alone.
|
|
88
|
+
*/
|
|
89
|
+
export type PlotReference = PlotValueReference | PlotStatReference;
|
|
90
|
+
export interface PlotValueReference {
|
|
91
|
+
at: number;
|
|
92
|
+
to?: number;
|
|
93
|
+
label?: string;
|
|
94
|
+
}
|
|
95
|
+
export declare const PLOT_REFERENCE_STATS: readonly ["median", "mean"];
|
|
96
|
+
/**
|
|
97
|
+
* A line at the median or mean of what the plot draws on that axis: the bars' heights, the points' values, the values
|
|
98
|
+
* in the boxes. Over the whole plot, so every panel shares it. `label` names it; absent = the statistic's name.
|
|
99
|
+
*/
|
|
100
|
+
export interface PlotStatReference {
|
|
101
|
+
stat: (typeof PLOT_REFERENCE_STATS)[number];
|
|
102
|
+
label?: string;
|
|
103
|
+
}
|
|
104
|
+
export declare const isStatReference: (r: PlotReference) => r is PlotStatReference;
|
|
28
105
|
export interface PlotAxis {
|
|
29
106
|
/** Replaces the automatic axis title. Absent = automatic. */
|
|
30
107
|
label?: string;
|
|
108
|
+
/** Reference lines and bands on a value axis: a target, a guard band, a customer's limit. Absent = none. */
|
|
109
|
+
references?: PlotReference[];
|
|
31
110
|
scale?: 'linear' | 'log';
|
|
111
|
+
/** Widen the axis to every limit drawn on it (`true`), or never (`false`). Absent = when that still leaves the data at
|
|
112
|
+
* least a third of the axis. */
|
|
113
|
+
includeLimits?: boolean;
|
|
114
|
+
/** Narrow the axis to a robust range (the quartiles ± 1.5 × their spread) so a few extreme values do not flatten the
|
|
115
|
+
* rest. Only the axis: every statistic still uses every value, and the footnote counts the values outside. */
|
|
116
|
+
clip?: boolean;
|
|
32
117
|
min?: number;
|
|
33
118
|
max?: number;
|
|
34
119
|
reverse?: boolean;
|
|
@@ -42,6 +127,35 @@ export type PlotColor = PlotField | {
|
|
|
42
127
|
} | {
|
|
43
128
|
none: true;
|
|
44
129
|
};
|
|
130
|
+
export declare const PLOT_NORMALIZE: readonly ["limits", "zscore", "robust"];
|
|
131
|
+
/**
|
|
132
|
+
* How a measured test's values are rescaled before they are drawn, each test on its own:
|
|
133
|
+
* - `limits`: 0 at the low limit, 1 at the high one (spec limits when the test has both, else test limits), as the
|
|
134
|
+
* capability chart draws them. A test without both limits cannot be placed and is left out.
|
|
135
|
+
* - `zscore`: standard deviations from the mean of the values in view.
|
|
136
|
+
* - `robust`: the same from the median, with the spread read from the median absolute deviation (×1.4826), so a few
|
|
137
|
+
* outliers do not set the scale.
|
|
138
|
+
*/
|
|
139
|
+
export type PlotNormalize = (typeof PLOT_NORMALIZE)[number];
|
|
140
|
+
/**
|
|
141
|
+
* One condition of a filter. A category field keeps the units whose value is one of `values`; a number keeps those
|
|
142
|
+
* from `min` to `max` inclusive, either end open. `not` keeps everything else. A unit with no value for the field
|
|
143
|
+
* (no bin, no reading) meets no condition, negated or not.
|
|
144
|
+
*/
|
|
145
|
+
export interface PlotCondition {
|
|
146
|
+
field: PlotField;
|
|
147
|
+
values?: string[];
|
|
148
|
+
min?: number;
|
|
149
|
+
max?: number;
|
|
150
|
+
not?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/** Conditions that must all hold. `off` keeps them and applies none, so a filter can be switched off and back on. */
|
|
153
|
+
export interface PlotFilter {
|
|
154
|
+
conditions: PlotCondition[];
|
|
155
|
+
off?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/** The conditions a spec applies: none when it has no filter or the filter is off. */
|
|
158
|
+
export declare function plotConditions(spec: Pick<PlotSpec, 'where'>): PlotCondition[];
|
|
45
159
|
export interface PlotSpec {
|
|
46
160
|
/** Stable, generated once, never reused; survives rename and reorder. */
|
|
47
161
|
id: string;
|
|
@@ -51,10 +165,22 @@ export interface PlotSpec {
|
|
|
51
165
|
chart: PlotChart;
|
|
52
166
|
/** Which field stands for each role. Absent for a sweep, which names runs of tests instead. */
|
|
53
167
|
fields?: {
|
|
54
|
-
|
|
168
|
+
/**
|
|
169
|
+
* A box or bar may take a list, outer level first: one category per combination of their values, drawn as a nested
|
|
170
|
+
* axis (test, then ring within each test). Every other chart takes one field.
|
|
171
|
+
*/
|
|
172
|
+
x?: PlotField | PlotField[];
|
|
55
173
|
y?: PlotField;
|
|
56
174
|
/** Absent = follow the tab's Group by. */
|
|
57
175
|
color?: PlotColor;
|
|
176
|
+
/** A heatmap's rows: a category field (Test, with a set of tests as the values; a bin; a ring). Its columns are `x`. */
|
|
177
|
+
rows?: PlotField;
|
|
178
|
+
/**
|
|
179
|
+
* One panel per value of this category field, each drawing the plot over that part of the population, on shared
|
|
180
|
+
* axes and colours: a wafer field (split, lot) takes whole wafers, a die field (ring, site) the dies in it, and Test,
|
|
181
|
+
* with a set of tests on Y, one test per panel. Absent = one plot.
|
|
182
|
+
*/
|
|
183
|
+
facet?: PlotField;
|
|
58
184
|
};
|
|
59
185
|
/** The unit one mark stands for. Absent = the finest level the X and Y fields allow. */
|
|
60
186
|
level?: 'die' | 'wafer';
|
|
@@ -68,6 +194,63 @@ export interface PlotSpec {
|
|
|
68
194
|
bins?: number;
|
|
69
195
|
/** Which of a plotted test's limits are drawn: `test` limits, `spec` limits (LSL/USL), `both` or `none`. Absent = both. */
|
|
70
196
|
limits?: PlotLimits;
|
|
197
|
+
/**
|
|
198
|
+
* A probability plot's vertical axis: `normal` spaces the cumulative share by the normal quantile, so a normal
|
|
199
|
+
* distribution is a straight line and its tails are spread out; `linear` is the plain cumulative share, 0 to 100%.
|
|
200
|
+
* Absent = normal.
|
|
201
|
+
*/
|
|
202
|
+
probabilityAxis?: 'normal' | 'linear';
|
|
203
|
+
/** A bar's colours stacked into one bar per category (`stack`), or each as its share of the category (`percent`).
|
|
204
|
+
* Only for counts and sums, which add up. Absent = side by side. */
|
|
205
|
+
stack?: 'stack' | 'percent';
|
|
206
|
+
/** Categories in order of their value: `value` largest first (a box by its median), `ascending` smallest first (the
|
|
207
|
+
* worst pass rate at the top). With colours, a category's value is all its colours together. Absent = the field's own order. */
|
|
208
|
+
sort?: 'value' | 'ascending';
|
|
209
|
+
/** Only the first this many categories, after sorting; the rest are counted in a note. Absent = all. */
|
|
210
|
+
top?: number;
|
|
211
|
+
/**
|
|
212
|
+
* A bar of counts or sums as each colour's share of its own total, in percent (`percent`), so groups of different sizes
|
|
213
|
+
* compare: the bin mix of a small split beside a large one. Not with `stack`. Absent = the counts or sums.
|
|
214
|
+
*/
|
|
215
|
+
barNorm?: 'count' | 'percent';
|
|
216
|
+
/** A box or bar plot's categories down the left and its values along the bottom (`horizontal`), for many categories or
|
|
217
|
+
* long names. Absent = categories along the bottom. */
|
|
218
|
+
orientation?: 'vertical' | 'horizontal';
|
|
219
|
+
/** Each bar's value printed at its end (when every value fits its bar's width; else none are). Absent = none. */
|
|
220
|
+
valueLabels?: boolean;
|
|
221
|
+
/** A cumulative-percentage line over a value-sorted bar of counts or sums: a pareto chart. */
|
|
222
|
+
cumulative?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* A band round a line of means or medians at each X: `sd` mean ± one standard deviation of the values combined there,
|
|
225
|
+
* `ci95` the mean's 95% confidence interval (Student's t), `iqr` the quartiles, `minmax` the range. Absent = none.
|
|
226
|
+
*/
|
|
227
|
+
spread?: 'sd' | 'ci95' | 'iqr' | 'minmax';
|
|
228
|
+
/**
|
|
229
|
+
* A scatter's fitted line per colour: `linear` least squares of Y on X, `orthogonal` the line closest to the points
|
|
230
|
+
* at right angles (Deming regression with equal errors), for two measurements of one quantity. Absent = none.
|
|
231
|
+
*/
|
|
232
|
+
fit?: 'linear' | 'orthogonal';
|
|
233
|
+
/** A scatter's y = x line, for X and Y in one unit. */
|
|
234
|
+
identity?: boolean;
|
|
235
|
+
/** A histogram's bars as counts, or as each colour's share of its own values in percent. Absent = counts. */
|
|
236
|
+
histNorm?: 'count' | 'percent';
|
|
237
|
+
/** Each colour's fitted normal distribution over its histogram bars. */
|
|
238
|
+
normalCurve?: boolean;
|
|
239
|
+
/** Proposed limits for the plotted test, on a histogram or probability plot: drawn, and its pass rate under them stated. */
|
|
240
|
+
whatIf?: {
|
|
241
|
+
lo?: number;
|
|
242
|
+
hi?: number;
|
|
243
|
+
};
|
|
244
|
+
/** A control chart's limits set from its first this many points (at least 3). Absent = all of them. */
|
|
245
|
+
baseline?: number;
|
|
246
|
+
/**
|
|
247
|
+
* Only the dies (or, for a wafer field, the wafers) that meet every condition: bin 1 only, the edge ring, one split,
|
|
248
|
+
* Vth within a range. Applied before everything else, panels included; `off` keeps the conditions and applies none.
|
|
249
|
+
* Absent = every die.
|
|
250
|
+
*/
|
|
251
|
+
where?: PlotFilter;
|
|
252
|
+
/** Rescale the measured values on Y, each test on its own. Absent = the values as measured. */
|
|
253
|
+
normalize?: PlotNormalize;
|
|
71
254
|
/** The definition of a `sweep` chart: ordered runs of tests read as curves. Such a plot has no `fields`. */
|
|
72
255
|
sweep?: SweepPayload;
|
|
73
256
|
}
|
|
@@ -78,9 +261,22 @@ export interface ReadPlotsResult {
|
|
|
78
261
|
/** Set when nothing could be read at all: the file as a whole is rejected. */
|
|
79
262
|
error?: string;
|
|
80
263
|
}
|
|
264
|
+
/** Most panels a faceted plot draws. */
|
|
265
|
+
export declare const PLOT_FACET_LIMIT = 24;
|
|
266
|
+
/** Most levels a nested X takes. */
|
|
267
|
+
export declare const PLOT_X_LEVELS = 3;
|
|
268
|
+
/** The X field or fields of a plot as a list, outer first; empty when it has none. */
|
|
269
|
+
export declare const xFieldsOf: (x: PlotField | PlotField[] | undefined) => PlotField[];
|
|
81
270
|
/** Two fields name the same series. */
|
|
82
271
|
export declare function sameField(a: PlotField | undefined, b: PlotField | undefined): boolean;
|
|
272
|
+
/** A field that names several tests. */
|
|
273
|
+
export declare const isTestSet: (f: unknown) => f is PlotTestSet;
|
|
83
274
|
export declare function isField(v: unknown): v is PlotField;
|
|
275
|
+
/**
|
|
276
|
+
* A filter from a file: `{ conditions, off }`. A single condition written without the list (`{ field, values }`) is read
|
|
277
|
+
* as a list of one. A condition that cannot be read is named and left out; a filter left with none is no filter.
|
|
278
|
+
*/
|
|
279
|
+
export declare function readFilter(raw: Record<string, unknown>, where: string, warnings: string[]): PlotFilter | undefined;
|
|
84
280
|
/**
|
|
85
281
|
* A sweep's definition from parsed JSON. Lenient like the rest of the file: a series that cannot be read is named and
|
|
86
282
|
* left out, a setting that is wrong is dropped, and settings this build does not know are kept.
|
|
@@ -95,6 +291,36 @@ export declare function plotToSweep(plot: PlotSpec): SweepSpec | undefined;
|
|
|
95
291
|
* setting that is wrong is dropped with a warning and the rest of the plot is kept.
|
|
96
292
|
*/
|
|
97
293
|
export declare function readPlot(raw: unknown, where: string, warnings: string[]): PlotSpec | null;
|
|
294
|
+
/** Offset of a JSON syntax error as line and column, where the engine's message states a position. */
|
|
295
|
+
export declare function syntaxErrorAt(text: string, message: string): string;
|
|
296
|
+
/**
|
|
297
|
+
* The items of a file's list that can be read, each given an id not yet used (a repeat gets a new one, said in
|
|
298
|
+
* `warnings`). `read` returns an item, or `undefined` after naming what was wrong.
|
|
299
|
+
*/
|
|
300
|
+
export declare function readIdentified<T extends {
|
|
301
|
+
id: string;
|
|
302
|
+
}>(list: readonly unknown[], warnings: string[], o: {
|
|
303
|
+
labelOf: (raw: unknown, index: number) => string;
|
|
304
|
+
read: (raw: unknown, label: string, warnings: string[]) => T | null | undefined;
|
|
305
|
+
newId: () => string;
|
|
306
|
+
}): T[];
|
|
307
|
+
/**
|
|
308
|
+
* The list in a file of `noun` (a plots or a filters file), or why there is none. A bare array is accepted as well as the
|
|
309
|
+
* wrapped form; a file from a newer version is read with a warning. `legacy` reads an older wrapped form of the same
|
|
310
|
+
* list: its list, an error, or `undefined` when the file is not that form.
|
|
311
|
+
*/
|
|
312
|
+
export declare function unwrapListFile(text: string, o: {
|
|
313
|
+
format: string;
|
|
314
|
+
noun: string;
|
|
315
|
+
key: string;
|
|
316
|
+
version: number;
|
|
317
|
+
legacy?: (json: Record<string, unknown>) => unknown[] | string | undefined;
|
|
318
|
+
}): {
|
|
319
|
+
list: unknown[];
|
|
320
|
+
warnings: string[];
|
|
321
|
+
} | {
|
|
322
|
+
error: string;
|
|
323
|
+
};
|
|
98
324
|
/**
|
|
99
325
|
* Reads a plots file. Lenient: every plot that can be read is kept and each problem is named, because a file a
|
|
100
326
|
* user spent time on must not be refused for one bad setting. Only a file with nothing usable is an error.
|
|
@@ -111,6 +337,16 @@ export declare function addPlots(existing: readonly PlotSpec[], incoming: readon
|
|
|
111
337
|
plots: PlotSpec[];
|
|
112
338
|
copies: string[];
|
|
113
339
|
};
|
|
340
|
+
/**
|
|
341
|
+
* `incoming` added to `existing` as copies where an id is already in use, never replacing. Returns the merged list and
|
|
342
|
+
* the names (`nameOf`) of those that became copies.
|
|
343
|
+
*/
|
|
344
|
+
export declare function addIdentified<T extends {
|
|
345
|
+
id: string;
|
|
346
|
+
}>(existing: readonly T[], incoming: readonly T[], nameOf: (item: T) => string, newId: () => string): {
|
|
347
|
+
items: T[];
|
|
348
|
+
copies: string[];
|
|
349
|
+
};
|
|
114
350
|
/**
|
|
115
351
|
* Why this build cannot draw `plot`, or `undefined` when it can: a chart or field kind from a newer version.
|
|
116
352
|
* (A test that is missing from the open lot is a data question, answered by the resolver, not a version one.)
|