@wafertools/wafermap 0.40.0 → 0.41.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 +20 -21
- package/CHANGELOG.md +154 -0
- package/README.md +6 -6
- package/dist/packages/canvas-adapter/canvasTheme.d.ts +12 -0
- package/dist/packages/canvas-adapter/canvasTheme.js +1 -1
- package/dist/packages/canvas-adapter/cellShade.d.ts +2 -2
- package/dist/packages/canvas-adapter/cellShade.js +1 -1
- package/dist/packages/canvas-adapter/chartPopulation.d.ts +3 -0
- package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
- package/dist/packages/canvas-adapter/charts/capability.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/capability.js +1 -1
- package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +2 -1
- package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -1
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +47 -27
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/commonality.js +4 -4
- package/dist/packages/canvas-adapter/charts/correlation.d.ts +6 -12
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +45 -15
- package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -1
- package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
- package/dist/packages/canvas-adapter/charts/palette.d.ts +16 -30
- package/dist/packages/canvas-adapter/charts/palette.js +1 -1
- package/dist/packages/canvas-adapter/charts/patCard.js +1 -1
- package/dist/packages/canvas-adapter/charts/plotChart.d.ts +29 -3
- package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
- package/dist/packages/canvas-adapter/charts/sweep.d.ts +3 -0
- package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
- package/dist/packages/canvas-adapter/chromeRow.d.ts +68 -0
- package/dist/packages/canvas-adapter/chromeRow.js +1 -0
- package/dist/packages/canvas-adapter/chunked.d.ts +6 -0
- package/dist/packages/canvas-adapter/chunked.js +1 -1
- package/dist/packages/canvas-adapter/columnFilterPopup.d.ts +25 -0
- package/dist/packages/canvas-adapter/columnFilterPopup.js +1 -0
- package/dist/packages/canvas-adapter/composePng.d.ts +37 -0
- package/dist/packages/canvas-adapter/composePng.js +1 -0
- package/dist/packages/canvas-adapter/dataTab.d.ts +39 -6
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/dieList.js +1 -1
- package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +3 -1
- package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.d.ts +20 -1
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/filterButton.d.ts +2 -0
- package/dist/packages/canvas-adapter/filterButton.js +1 -1
- package/dist/packages/canvas-adapter/filterEditor.d.ts +5 -0
- package/dist/packages/canvas-adapter/filterEditor.js +1 -1
- package/dist/packages/canvas-adapter/guideWindow.js +1 -1
- package/dist/packages/canvas-adapter/icons.js +1 -1
- package/dist/packages/canvas-adapter/identityHeader.d.ts +5 -0
- package/dist/packages/canvas-adapter/identityHeader.js +1 -1
- package/dist/packages/canvas-adapter/index.d.ts +7 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +32 -9
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/maplessSummary.d.ts +4 -2
- package/dist/packages/canvas-adapter/maplessSummary.js +1 -1
- package/dist/packages/canvas-adapter/openWaferMode.d.ts +7 -0
- package/dist/packages/canvas-adapter/openWaferMode.js +1 -0
- package/dist/packages/canvas-adapter/panelChart.d.ts +7 -0
- package/dist/packages/canvas-adapter/panelChart.js +1 -0
- package/dist/packages/canvas-adapter/panelTable.d.ts +50 -0
- package/dist/packages/canvas-adapter/panelTable.js +1 -0
- package/dist/packages/canvas-adapter/plotCard.js +1 -1
- package/dist/packages/canvas-adapter/plotEditor.d.ts +12 -0
- package/dist/packages/canvas-adapter/plotEditor.js +10 -10
- package/dist/packages/canvas-adapter/plotItems.d.ts +9 -4
- package/dist/packages/canvas-adapter/plotItems.js +1 -1
- package/dist/packages/canvas-adapter/plotJsonComplete.js +1 -1
- package/dist/packages/canvas-adapter/plotModal.d.ts +7 -0
- 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 +60 -2
- package/dist/packages/canvas-adapter/plotTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +7 -0
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +41 -9
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/reportCharts.d.ts +41 -0
- package/dist/packages/canvas-adapter/reportCharts.js +1 -0
- package/dist/packages/canvas-adapter/reportExport.d.ts +91 -0
- package/dist/packages/canvas-adapter/reportExport.js +1 -0
- package/dist/packages/canvas-adapter/reportFigures.d.ts +29 -0
- package/dist/packages/canvas-adapter/reportFigures.js +1 -0
- package/dist/packages/canvas-adapter/reportRun.d.ts +9 -0
- package/dist/packages/canvas-adapter/reportRun.js +1 -0
- package/dist/packages/canvas-adapter/selectionOverlay.d.ts +12 -0
- package/dist/packages/canvas-adapter/selectionOverlay.js +1 -0
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +152 -111
- package/dist/packages/canvas-adapter/summaryPanel.js +7 -4
- package/dist/packages/canvas-adapter/summaryToggle.js +1 -1
- package/dist/packages/canvas-adapter/tableDrilldown.d.ts +48 -0
- package/dist/packages/canvas-adapter/tableDrilldown.js +1 -0
- package/dist/packages/canvas-adapter/tableFilter.d.ts +42 -0
- package/dist/packages/canvas-adapter/tableFilter.js +1 -0
- package/dist/packages/canvas-adapter/tablePlots.d.ts +85 -0
- package/dist/packages/canvas-adapter/tablePlots.js +1 -0
- package/dist/packages/canvas-adapter/themeWatch.d.ts +7 -0
- package/dist/packages/canvas-adapter/themeWatch.js +1 -0
- package/dist/packages/canvas-adapter/toCanvas.d.ts +3 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +125 -36
- 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 +530 -414
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
- package/dist/packages/canvas-adapter/virtualTable.d.ts +37 -7
- package/dist/packages/canvas-adapter/virtualTable.js +1 -1
- package/dist/packages/core/aggregates.d.ts +14 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/dies.d.ts +7 -0
- package/dist/packages/core/dies.js +1 -1
- package/dist/packages/core/utils.d.ts +2 -0
- package/dist/packages/core/utils.js +1 -1
- package/dist/packages/experimental/charts.d.ts +4 -0
- package/dist/packages/experimental/charts.js +1 -0
- package/dist/packages/renderer/binColors.d.ts +6 -2
- package/dist/packages/renderer/binColors.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +36 -14
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +8 -0
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/categoryColors.d.ts +3 -0
- package/dist/packages/renderer/categoryColors.js +1 -0
- package/dist/packages/renderer/colorMap.d.ts +15 -16
- package/dist/packages/renderer/colorMap.js +1 -1
- package/dist/packages/renderer/colorSchemes.d.ts +34 -30
- package/dist/packages/renderer/colorSchemes.js +1 -1
- package/dist/packages/renderer/dataColors.d.ts +126 -0
- package/dist/packages/renderer/dataColors.js +1 -0
- package/dist/packages/renderer/deprecate.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +16 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +2 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/renderer/spec.d.ts +5 -0
- package/dist/packages/renderer/spec.js +1 -1
- package/dist/packages/renderer/stacks.d.ts +21 -0
- package/dist/packages/renderer/stacks.js +1 -0
- package/dist/packages/renderer/timeAxis.d.ts +19 -0
- package/dist/packages/renderer/timeAxis.js +1 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +2 -4
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/binRows.js +1 -1
- package/dist/packages/stats/binShifts.d.ts +59 -0
- package/dist/packages/stats/binShifts.js +1 -0
- package/dist/packages/stats/capability.d.ts +6 -1
- package/dist/packages/stats/capability.js +1 -1
- package/dist/packages/stats/chartCatalogue.d.ts +3 -0
- package/dist/packages/stats/chartCatalogue.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/columnPlot.d.ts +38 -0
- package/dist/packages/stats/columnPlot.js +1 -0
- package/dist/packages/stats/commonality.d.ts +8 -1
- package/dist/packages/stats/commonality.js +1 -1
- package/dist/packages/stats/correlation.d.ts +7 -2
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/dataTable.d.ts +44 -0
- package/dist/packages/stats/dataTable.js +1 -0
- package/dist/packages/stats/dieRegions.js +1 -1
- package/dist/packages/stats/examplePicks.js +1 -1
- package/dist/packages/stats/facets.d.ts +11 -0
- package/dist/packages/stats/facets.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +21 -0
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/groupEffects.d.ts +8 -0
- package/dist/packages/stats/groupEffects.js +1 -1
- package/dist/packages/stats/math.d.ts +2 -0
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/overview.d.ts +114 -0
- package/dist/packages/stats/overview.js +1 -0
- package/dist/packages/stats/pat.d.ts +0 -2
- package/dist/packages/stats/pat.js +1 -1
- package/dist/packages/stats/patternClassification.d.ts +20 -3
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/permutationNull.d.ts +16 -0
- package/dist/packages/stats/permutationNull.js +1 -0
- package/dist/packages/stats/plotData.d.ts +138 -12
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/plotSpec.d.ts +10 -1
- package/dist/packages/stats/plotSpec.js +3 -3
- package/dist/packages/stats/plotTable.js +1 -1
- package/dist/packages/stats/plotWords.d.ts +52 -0
- package/dist/packages/stats/plotWords.js +1 -0
- package/dist/packages/stats/presentation.d.ts +63 -14
- package/dist/packages/stats/presentation.js +1 -1
- package/dist/packages/stats/presentationPresets.d.ts +35 -0
- package/dist/packages/stats/presentationPresets.js +1 -0
- package/dist/packages/stats/presentationSections.d.ts +83 -0
- package/dist/packages/stats/presentationSections.js +1 -0
- package/dist/packages/stats/renderSummaryReport.d.ts +80 -2
- package/dist/packages/stats/renderSummaryReport.js +1 -67
- package/dist/packages/stats/reportBlocks.d.ts +249 -0
- package/dist/packages/stats/reportBlocks.js +1 -0
- package/dist/packages/stats/reportContents.d.ts +22 -0
- package/dist/packages/stats/reportContents.js +1 -0
- package/dist/packages/stats/reportDeck.d.ts +245 -0
- package/dist/packages/stats/reportDeck.js +212 -0
- package/dist/packages/stats/reportHtml.d.ts +44 -43
- package/dist/packages/stats/reportHtml.js +82 -46
- package/dist/packages/stats/reportMaps.d.ts +67 -0
- package/dist/packages/stats/reportMaps.js +1 -0
- package/dist/packages/stats/reportSections.d.ts +55 -0
- package/dist/packages/stats/reportSections.js +1 -0
- package/dist/packages/stats/sweep.d.ts +14 -6
- package/dist/packages/stats/sweep.js +1 -1
- package/dist/packages/stats/synthesis.d.ts +87 -10
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/types.d.ts +22 -0
- package/dist/packages/stats/worthItems.d.ts +15 -0
- package/dist/packages/stats/worthItems.js +1 -0
- package/dist/packages/stats/yield.d.ts +13 -0
- package/dist/packages/stats/yield.js +1 -1
- package/llms.txt +1 -1
- package/package.json +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compareTestsByGroup as
|
|
1
|
+
import{compareTestsByGroup as Q,formatP as N,groupKeys as Y}from"../../stats/groupCompare.js";import{fmt as S}from"../../renderer/fmt.js";import{testLabel as G,unmarkedLabel as Z}from"../../renderer/testLabel.js";import{CLR as d,FONT as q,SPACE as C,controlStyle as K,wireControlHover as R,wireTooltip as k}from"../toolbar.js";import{exportCsv as ee}from"../tableExport.js";import{cardShell as te,guideCite as oe,makeListSelect as ne,renderEmptyState as V}from"./chartShell.js";import{GUIDE_SECTIONS as se}from"../../stats/guideSections.js";import{cardAbout as re,cardKindId as ae}from"./cardAbout.js";import{shadesAmong as ie}from"../cellShade.js";const L="\0none",de=6;export function renderGroupComparisonPanel(s){const r=s.ownerDocument??document,O=s.groupLabelText??"group",{card:b,body:$,controlsRow:B,setAbout:I,setCardId:P}=te(s.title??`Comparison by ${O.toLowerCase()}`,void 0,r);P(ae("comparison")),I(re("comparison")),b.dataset.wmapGroupComparison="1",b.style.gridColumn="1 / -1";const A=s.groups.flatMap(t=>t.items.map(e=>({dies:e.dies,group:t.key}))),p=Y(A),a=s.control!==null&&p.includes(s.control)?s.control:null,f=Q(A,s.testDefs,a??void 0),E=p.length<=de?p:[],U=ne([{value:L,label:"No control: compare all groups"},...p.map(t=>({value:t,label:`Control: ${t}`}))],a??L,t=>s.onControlChange(t===L?null:t),{ownerDocument:r,ariaLabel:"Control group",hook:"compare-control"});if(B.appendChild(U),s.onSaveText&&f.length){const t=r.createElement("button");t.type="button",t.textContent="Comparison CSV",k(t,"Save this table as a CSV file, one row per test"),Object.assign(t.style,{...K("outlined"),color:d.text}),R(t),t.addEventListener("click",()=>ee([{header:"Test",get:e=>Z(G(e.test,e.test.testNumber))},{header:"Test number",get:e=>e.test.testNumber},{header:"Unit",get:e=>e.test.unit??""},...p.flatMap(e=>[{header:`${e} wafers`,get:o=>o.comparison.groups.find(n=>n.key===e)?.n??0},{header:`${e} mean`,get:o=>c(o.comparison.groups.find(n=>n.key===e)?.mean)},...a&&e!==a?[{header:`${e} minus ${a}`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.delta)},{header:`${e} vs ${a} p (Holm)`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.pAdjusted)}]:[]]),{header:"Welch p",get:e=>c(e.comparison.welch?.p)},{header:"Kruskal-Wallis p",get:e=>c(e.comparison.kruskal?.p)},{header:"q (Benjamini-Hochberg)",get:e=>c(e.pAdjusted)},{header:"Largest shift (wafer SDs)",get:e=>c(e.effect)},{header:"Largest shift (share of limit window)",get:e=>c(e.windowShare)},{header:"Note",get:e=>e.comparison.issue??""}],f,"group-comparison.csv",s.onSaveText)),B.appendChild(t)}if(p.length<2)return V($,`Needs two or more ${O.toLowerCase()} groups to compare.`),{card:b,setTest:()=>{},destroy:()=>{}};if(f.length===0)return V($,"No measured test has values in these wafers."),{card:b,setTest:()=>{},destroy:()=>{}};const y=r.createElement("div"),z=p.map(t=>`${t} ${A.filter(e=>e.group===t).length}`).join(", ");y.textContent=`Each wafer is one value, the mean of its dies, so n is wafers (${z}). Welch: Welch's ANOVA (Welch's t for two groups). Rank: Kruskal\u2013Wallis${f.some(t=>t.comparison.kruskal?.approximate)?", approximate with fewer than five wafers in a group":""}. q: Benjamini\u2013Hochberg across the ${f.length} tests, which the table is ranked by.`+(a?` Each group's difference from ${a} has a Holm-adjusted p.`:"")+" ",y.append(oe(r,se.groups),"."),Object.assign(y.style,{color:d.label,fontSize:q.body,marginBottom:C.sm}),$.appendChild(y);const j=r.createElement("div");Object.assign(j.style,{overflow:"auto",maxHeight:"420px",border:`1px solid ${d.menuBorder}`});const x=r.createElement("table");Object.assign(x.style,{borderCollapse:"collapse",width:"100%",fontSize:q.body,fontVariantNumeric:"tabular-nums"});const W=r.createElement("thead"),D=r.createElement("tr"),h=(t,e,o="right")=>{const n=r.createElement("th");n.scope="col",n.textContent=t,e&&k(n,e),Object.assign(n.style,{position:"sticky",top:"0",background:d.menuBg,textAlign:o,padding:`${C.xs} ${C.sm}`,borderBottom:`1px solid ${d.menuBorder}`,color:d.label,fontWeight:"600",whiteSpace:"nowrap"}),D.appendChild(n)};h("Test",void 0,"left");for(const t of E)h(t===a?`${t} (control)`:t,a&&t!==a?`Mean of the wafer means, and the difference from ${a}`:"Mean of the wafer means");h("Welch p","Do the group means differ? Welch\u2019s ANOVA on wafer means, not assuming equal spreads"),h("Rank p","The same question on ranks (Kruskal\u2013Wallis): one odd wafer cannot drive it"),h("q","Welch p adjusted for the number of tests compared (Benjamini\u2013Hochberg); the table is ranked by it"),h("Largest shift","The largest difference between group means: in wafer-to-wafer standard deviations, and as a share of the limit window where the test has both limits"),W.appendChild(D),x.appendChild(W);const M=r.createElement("tbody"),H=new Map,g=(t,e,o={})=>{const n=r.createElement("td");typeof e=="string"?n.textContent=e:n.appendChild(e),o.title&&k(n,o.title),Object.assign(n.style,{padding:`${C.xs} ${C.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${d.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400",color:o.muted?d.label:d.text}),o.shade&&(n.style.background=o.shade),t.appendChild(n)};for(const t of f){const e=r.createElement("tr"),o=t.comparison,n=t.test.unit,l=r.createElement("button");l.type="button",l.textContent=G(t.test,t.test.testNumber),l.dataset.wmapCompareTest=String(t.test.testNumber),k(l,`Show ${l.textContent} in the panels below${o.issue?`. ${o.issue}`:""}`),Object.assign(l.style,{...K("bare"),padding:"0",textAlign:"left",color:d.text,textDecoration:"underline",textDecorationColor:d.menuBorder}),R(l,"bare"),l.addEventListener("click",()=>{s.onSelectTest(t.test.testNumber),v(t.test.testNumber)}),g(e,l,{align:"left"});const _=ie(E.map(w=>{const m=o.groups.find(i=>i.key===w);return m&&m.n?m.mean:NaN}),w=>S(w,n));for(const[w,m]of E.entries()){const i=o.groups.find(T=>T.key===m),u=o.contrasts?.find(T=>T.key===m),F=i&&i.n?S(i.mean,n):"\u2014",J=u&&Number.isFinite(u.delta)?`${F} (${u.delta>=0?"+":""}${S(u.delta,n)}, p ${N(u.pAdjusted)})`:F;g(e,J,{shade:_[w],title:i?`${m}: ${i.n} wafer${i.n===1?"":"s"}${i.n>=2?`, wafer-to-wafer SD ${S(i.sd,n)}`:""}`:void 0,muted:!i||i.n<2,strong:!!u&&u.pAdjusted<.05})}g(e,N(o.welch?.p??NaN),{title:o.issue}),g(e,N(o.kruskal?.p??NaN)),g(e,N(t.pAdjusted),{strong:t.pAdjusted<.05});const X=Number.isFinite(t.effect)?`${Math.abs(t.effect).toFixed(1)} SD${t.windowShare!==void 0?` \xB7 ${Math.abs(t.windowShare*100).toFixed(0)}% of limits`:""}`:"\u2014";g(e,X),H.set(t.test.testNumber,e),M.appendChild(e)}x.appendChild(M),j.appendChild(x),$.appendChild(j);function v(t){for(const[e,o]of H)o.style.background=e===t?d.bgActive:"",e===t?o.setAttribute("aria-current","true"):o.removeAttribute("aria-current")}return v(s.selectedTestNumber),{card:b,setTest:v,destroy:()=>{}}}const c=s=>s===void 0||!Number.isFinite(s)?"":String(s);
|
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
/** The neutral single fill for "how much" encodings (bars, boxes, histogram). */
|
|
2
|
+
export declare const quantityColor: (dataColors?: string) => string;
|
|
3
|
+
/** How much of the quantity colour a bar or mark takes against the card colour, in percent: pale, but strong enough to read as a mark. */
|
|
4
|
+
export declare const QUANTITY_MIX = 78;
|
|
5
|
+
export { categorical } from '../../renderer/categoryColors.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* "more saturated = higher yield", monotonic in lightness, CVD-safe, and
|
|
12
|
-
* never reads as an alarm. The visible label chips remain the primary
|
|
13
|
-
* carrier of the number; this fill is reinforcement only.
|
|
7
|
+
* Capability colour from Ppk against the conventional 1.33 threshold: capable (≥ 1.33) is the quantity colour, as any
|
|
8
|
+
* normal bar is; marginal (≥ 1.0) and poor (< 1.0) are two steps of the rating scale's bad side, so what needs attention
|
|
9
|
+
* carries the colour and no class rests on telling green from orange. The per-column Ppk in the tooltip and the
|
|
10
|
+
* worst-first sort carry the same information positionally.
|
|
14
11
|
*/
|
|
15
|
-
export declare function
|
|
12
|
+
export declare function capabilityColor(ppk: number | null, dataColors?: string, dark?: boolean): string;
|
|
16
13
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* hues (bluish green / orange / vermillion) rather than pure green/red so
|
|
20
|
-
* the distinction survives the common colour-vision deficiencies; the
|
|
21
|
-
* per-column Ppk value in the tooltip and the worst-first sort carry the
|
|
22
|
-
* same information positionally.
|
|
14
|
+
* The two ends of every signed scale (a correlation, a z-score, a difference): the scheme's below and above, so one colour
|
|
15
|
+
* never means "high" on one chart and "low" on the next.
|
|
23
16
|
*/
|
|
24
|
-
export declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* which stay far apart under every common colour-vision deficiency.
|
|
29
|
-
*/
|
|
30
|
-
export declare const SIGNED_LOW = "#0072B2";
|
|
31
|
-
export declare const SIGNED_HIGH = "#D55E00";
|
|
32
|
-
/** Correlation sign hues (vermillion = positive, blue = negative); |r| sets intensity via background blend. */
|
|
33
|
-
export declare const CORRELATION_POSITIVE = "#D55E00";
|
|
34
|
-
export declare const CORRELATION_NEGATIVE = "#0072B2";
|
|
17
|
+
export declare function signedEnds(dataColors?: string, dark?: boolean): {
|
|
18
|
+
low: string;
|
|
19
|
+
high: string;
|
|
20
|
+
};
|
|
35
21
|
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{dataColorsFor as n,ratingColor as c,cssRgb as e,signedColor as s}from"../../renderer/dataColors.js";export const quantityColor=o=>n(o).quantity,QUANTITY_MIX=78;export{categorical}from"../../renderer/categoryColors.js";export function capabilityColor(o,t,r=!1){if(o===null)return"#999999";const i=n(t);return o>=1.33?i.quantity:e(c(o>=1?.2:0,i,r))}export function signedEnds(o,t=!1){const r=n(o);return{low:e(s(0,r,t)),high:e(s(1,r,t))}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{summarisePat as
|
|
1
|
+
import{summarisePat as j}from"../../stats/patSummary.js";import{PAT_K as B,PAT_MIN_DIES as W,PAT_SKEW_WARN as L}from"../../stats/pat.js";import{CLR as d,FONT as f,SPACE as i,controlStyle as G,wireControlHover as D,wireTooltip as $}from"../toolbar.js";import{cardShell as I,firstRowsToggle as M,guideCite as _}from"./chartShell.js";import{GUIDE_SECTIONS as k}from"../../stats/guideSections.js";import{cardAbout as F,cardKindId as R}from"./cardAbout.js";const v=8,T=(l,o)=>o>0?`${(l/o*100).toFixed(o>=1e3?2:1)}%`:"\u2013";export function renderPatCard(l){const o=j(l.items,l.testDefs);if(!o)return;const s=l.ownerDocument??document,{card:p,body:h,setAbout:x,setCardId:E}=I("Part average testing (PAT)",void 0,s);E(R("pat")),x(F("pat")),p.dataset.wmapPatCard="1",p.style.gridColumn="1 / -1",p.style.flex="0 0 auto";const u=s.createElement("div");u.textContent=`Dynamic limits for each of the ${o.tests} test${o.tests===1?"":"s"} with both limits, set per wafer at the median \xB1 ${B} robust standard deviations (interquartile range \xF7 1.35) of the dies that pass, never wider than the specification limits (the test's own where a test has none), and only where a wafer has ${W} or more passing values. An outlier passes its bin and every test limit but lies outside the PAT limits of at least one test. Overall: ${o.total.outliers.toLocaleString("en-GB")} outlier${o.total.outliers===1?"":"s"} in ${o.total.judged.toLocaleString("en-GB")} dies (${T(o.total.outliers,o.total.judged)}). `,u.append(_(s,k.pat,"How to read this, and how it differs from AEC-Q001"),"."),Object.assign(u.style,{color:d.label,fontSize:f.body,marginBottom:i.sm}),h.appendChild(u);const w=t=>{const e=s.createElement("table");Object.assign(e.style,{borderCollapse:"collapse",width:"100%",fontSize:f.body,fontVariantNumeric:"tabular-nums"});const r=s.createElement("tr");t.forEach(([C,c],O)=>{const m=s.createElement("th");m.scope="col",m.textContent=C,c&&$(m,c),Object.assign(m.style,{textAlign:O===0?"left":"right",padding:`${i.xs} ${i.sm}`,borderBottom:`1px solid ${d.menuBorder}`,color:d.label,fontWeight:"600",whiteSpace:"nowrap"}),r.appendChild(m)});const a=s.createElement("thead");a.appendChild(r);const n=s.createElement("tbody");return e.append(a,n),{table:e,tbody:n}},b=(t,e,r=!1)=>{const a=s.createElement("tr");e.forEach((n,C)=>{const c=s.createElement("td");c.textContent=n,Object.assign(c.style,{padding:`${i.xs} ${i.sm}`,textAlign:C===0?"left":"right",borderBottom:`1px solid ${d.menuBorder}`,whiteSpace:"nowrap",fontWeight:r?"700":"400"}),a.appendChild(c)}),t.appendChild(a)},y=[...o.wafers].sort((t,e)=>e.outliers/e.judged-t.outliers/t.judged||e.outliers-t.outliers),{table:A,tbody:S}=w([["Wafer"],["Dies judged","Dies with a PAT verdict"],["Within","Pass and inside the PAT limits"],["Outliers","Pass every limit and bin, but outside the PAT limits of a test"],["Outlier rate"],["Fail anyway","Fail their bin or a test limit"]]),g=s.createElement("div");g.style.overflowX="auto",g.appendChild(A);const P=M(s,{total:y.length,first:v,noun:"wafers",scroller:g,fill:t=>{S.replaceChildren();for(const e of t?y:y.slice(0,v))b(S,[e.label,e.judged.toLocaleString("en-GB"),e.within.toLocaleString("en-GB"),e.outliers.toLocaleString("en-GB"),T(e.outliers,e.judged),e.fails.toLocaleString("en-GB")],e.outliers>0)}});if(h.append(g,P),l.showMap){const t=s.createElement("button");t.type="button",t.textContent="Map the verdicts",t.dataset.wmapPatMaps="1",$(t,"Show the maps with their dies coloured by PAT verdict: within the limits, outlier, fails anyway"),Object.assign(t.style,{...G("outlined"),marginTop:i.sm,marginLeft:i.sm}),D(t),t.addEventListener("click",()=>l.showMap()),h.appendChild(t)}if(o.byTest.length){const t=s.createElement("div");t.textContent="Where the outliers are outside",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const{table:e,tbody:r}=w([["Test"],["Outliers","Outlier dies outside the PAT limits of this test; a die outside on several tests counts for each"]]);for(const a of o.byTest.slice(0,5))b(r,[a.name,a.outliers.toLocaleString("en-GB")]);h.append(t,e)}if(o.skewed.length){const t=s.createElement("div");t.textContent="Lopsided distributions",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const e=s.createElement("div");e.textContent=`The middle half of these tests' values is lopsided (quartile skewness of ${L} or more either way), so limits placed symmetrically about the median sit too close on one side and too far on the other: they flag normal dies on the short side and miss outliers on the long one. Read their counts with care.`,Object.assign(e.style,{color:d.label,fontSize:f.body,marginBottom:i.xs});const{table:r,tbody:a}=w([["Test"],["Wafers lopsided","Wafers where the test is lopsided, of the wafers that have PAT limits for it"],["Most lopsided","Quartile skewness of the most lopsided wafer: positive means a long tail towards high values"]]);for(const n of o.skewed.slice(0,5))b(a,[n.name,`${n.wafers} of ${n.of}`,`${n.worst>0?"+":"\u2212"}${Math.abs(n.worst).toFixed(2)}`]);h.append(t,e,r)}return{card:p,destroy:()=>{}}}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type PlotPoint, type ResolvedPlot } from '../../stats/plotData.js';
|
|
2
2
|
import { type SaveTextHandler } from '../toolbar.js';
|
|
3
|
-
import { type CardMenuRow, type SaveImageHandler, type WaferContextMenuHandler } from './chartShell.js';
|
|
3
|
+
import { type CardChrome, type CardMenuRow, type SaveImageHandler, type WaferContextMenuHandler } from './chartShell.js';
|
|
4
4
|
import type { BinColors } from '../../renderer/binColors.js';
|
|
5
|
+
import { type ReaderColors } from './divergingScale.js';
|
|
5
6
|
/**
|
|
6
7
|
* @internal Where each colour group's mark sits within its category, as fractions of the category's slot. Only the
|
|
7
8
|
* groups with a value in that category take a place, centred, so a category that one group fills (a ring coloured by
|
|
@@ -18,6 +19,15 @@ export declare function categoryLayout(present: ReadonlyArray<readonly number[]>
|
|
|
18
19
|
};
|
|
19
20
|
export interface PlotChartOptions {
|
|
20
21
|
ownerDocument?: Document;
|
|
22
|
+
/**
|
|
23
|
+
* @internal Which of the card's chrome to draw (all of it when absent): the title, the ⋯ menu, the expand button, the
|
|
24
|
+
* border and padding (`frame`), the statement line under the title (`footnote`) and the colour legend (`legend`). With
|
|
25
|
+
* this set, the row for a host's own buttons is left out too.
|
|
26
|
+
*/
|
|
27
|
+
chrome?: CardChrome & {
|
|
28
|
+
footnote?: boolean;
|
|
29
|
+
legend?: boolean;
|
|
30
|
+
};
|
|
21
31
|
onSaveImage?: SaveImageHandler;
|
|
22
32
|
/** Where the card's Save data as CSV goes (the host's save dialog); absent = the browser's download. */
|
|
23
33
|
onSaveText?: SaveTextHandler;
|
|
@@ -25,15 +35,27 @@ export interface PlotChartOptions {
|
|
|
25
35
|
waferLabel: (item: number) => string;
|
|
26
36
|
/** The maps' bin colours: a plot coloured by hard or soft bin draws each bin in its map colour. */
|
|
27
37
|
binColors?: BinColors;
|
|
38
|
+
/** The bin colours as they are now, read when the reader's colours change so a repaint draws with the new ones. */
|
|
39
|
+
getBinColors?: () => BinColors | undefined;
|
|
40
|
+
/** The reader's colour preferences (the map's value gradient and Reverse): a measured value takes that gradient. */
|
|
41
|
+
readerColors?: ReaderColors;
|
|
28
42
|
/** Right-click a mark that is one wafer (a wafer's bar or box, a point per wafer): that wafer's menu, as on the maps. */
|
|
29
43
|
onWaferMenu?: WaferContextMenuHandler;
|
|
30
|
-
/**
|
|
31
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Click a point: open its wafer, on `testNumber` (the plot's own measurement) when it has one, or on its bins (`view`)
|
|
46
|
+
* for a plot of yield or bins (stats/plotData.ts says which). Omit where there is no wafer to open.
|
|
47
|
+
*/
|
|
48
|
+
onOpenWafer?: (item: number, testNumber?: number, view?: 'bins') => void;
|
|
32
49
|
/** What a click on a bar or box that is not one wafer (or on a line's point) does, in the reader's words. Default `chart
|
|
33
50
|
* or tabulate what it counts`. Read at each draw. */
|
|
34
51
|
selectActionLabel?: string;
|
|
35
52
|
/** What a drag across a line chart selects, in the reader's words ("wafers"). Default `a run of points`. */
|
|
36
53
|
selectRangeLabel?: string;
|
|
54
|
+
/** Said after the title, to tell two charts of the same kind apart ("Yield by split · Ring 4"). */
|
|
55
|
+
titleNote?: string;
|
|
56
|
+
/** The statement of what the chart shows (its wafers and dies, how it counts) goes in the card's About this chart line
|
|
57
|
+
* instead of above the chart: for a card that leads with one sentence of its own. */
|
|
58
|
+
footnoteInAbout?: boolean;
|
|
37
59
|
/** What a click on a point does, in the reader's words. Default `open this wafer`. */
|
|
38
60
|
openActionLabel?: string;
|
|
39
61
|
/** Drag a rectangle over a scatter: the dies inside it, the pointer position and the canvas to anchor a menu on. */
|
|
@@ -65,6 +87,10 @@ export interface SelectInfo {
|
|
|
65
87
|
row: string;
|
|
66
88
|
column: string;
|
|
67
89
|
};
|
|
90
|
+
/** The mark in words, as its axis and legend name it ("Split TT", "Split TT and Hard bin 2"), for the population's name. */
|
|
91
|
+
what?: string;
|
|
92
|
+
/** The mark counts the passing or the failing dies of its wafers (Passing dies, Failing dies): only those are its dies. */
|
|
93
|
+
counts?: 'pass' | 'fail';
|
|
68
94
|
}
|
|
69
95
|
export interface PlotChartHandle {
|
|
70
96
|
card: HTMLElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{escHtml as X,maxOf as Te,minOf as jt}from"../../core/utils.js";import{fiveNumberSummary as Ut,normalQuantile as Yt,sampleVariance as Rn}from"../../stats/math.js";import{CONTROL_RULE_TEXT as On}from"../../stats/control.js";import{PAT_VERDICT_LABEL as qt}from"../../stats/pat.js";import{fmt as J}from"../../renderer/fmt.js";import{fitTicks as pt}from"../../renderer/axisTicks.js";import{binOfLabel as In,plotFootnote as Ht,plotGuideSections as Kt,plotTestNumber as Ve,plotTitle as Nn,probabilityPosition as ct}from"../../stats/plotData.js";import{SPACE as me,RADIUS as Fn,fontPx as Q,FONT as gt,CLR as nt,markNoPrint as Vt}from"../toolbar.js";import{exportCsv as zn}from"../tableExport.js";import{tableToTsv as _n}from"../../core/tableCsv.js";import{plotTable as Dn}from"../../stats/plotTable.js";import{cardShell as Gn,appendGuideCites as Xn,observeResize as jn,makeTooltip as Un,attachChartTip as Yn,chartFillHeight as qn,applyCanvasFlow as Ge,prepareCanvas as Xe,positionChartTooltip as yt,resolveChartCanvasColors as je,makeAxisFormat as Hn,horizontalTickSpacing as Zt,VERTICAL_TICK_SPACING_PX as Kn,makeSeriesLegendItem as Vn,renderEmptyState as Jt,isExpandedCard as Qt,makeLabeledSelect as Zn,fillTextOnHalo as Ct,limitLines as Jn,limitExtent as Qn,stackLabelRows as en,placeClearOf as tn,strokeLimitLine as nn,drawOffAxisLimits as eo,limitLabelPlacement as to,shouldIncludeLimitsByDefault as no,WAFER_MENU_HINT as Et}from"./chartShell.js";import{guideCitesText as oo}from"../../stats/guideSections.js";import{categorical as lo}from"./palette.js";import{NO_DATA_FILL as on}from"../../renderer/colorMap.js";import{darkTextOnColor as so,plotGradient as bt}from"./divergingScale.js";import{wirePointInteractions as Bt}from"./pointInteractions.js";import{plotAbout as io}from"./cardAbout.js";const Wt=64,xt=16,Rt=12,Ue=52,ao=16,ro=92,co=16,vt=5e3,ln=1500,ft=100,fo=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],sn=m=>`${+(m*100).toPrecision(4)}%`;export function categoryLayout(m){const W=.8/Math.max(1,...m.map(R=>R.length)),U=R=>(1-m[R].length*W)/2;return{width:W,left:(R,Y)=>{const V=m[R].indexOf(Y);return V<0?void 0:U(R)+V*W},groupAt:(R,Y)=>{const V=Math.floor((Y-U(R))/W);return V>=0&&V<m[R].length?m[R][V]:void 0}}}function uo(m){if(m<=ln)return Array.from({length:m},(R,Y)=>Y);const z=[];for(let R=0;R<ft;R++)z.push(R);const W=ln-2*ft,U=m-2*ft;for(let R=0;R<W;R++)z.push(ft+Math.floor(R*U/W));for(let R=m-ft;R<m;R++)z.push(R);return z}function Ot(m,z,W){return W?Math.round(m).toLocaleString("en-GB"):z?J(m,z):`${m<=-.005?"\u2212":""}${Math.abs(m).toFixed(2)}`}const ho=260;function mo(m){const z=[...m.querySelectorAll("[data-wmap-plot-panel]")],W=z[0]?.querySelector("canvas");if(!W)return null;const U=W.width/Math.max(1,W.getBoundingClientRect().width)||1,R=m.getBoundingClientRect(),Y=m.ownerDocument.createElement("canvas");Y.width=Math.ceil(R.width*U),Y.height=Math.ceil(R.height*U);const V=Y.getContext("2d");if(!V)return null;const we=getComputedStyle(m);V.fillStyle=we.backgroundColor&&we.backgroundColor!=="rgba(0, 0, 0, 0)"?we.backgroundColor:"#fff",V.fillRect(0,0,Y.width,Y.height);for(const Me of z){const Se=Me.querySelector("canvas"),ce=Me.dataset.wmapChartTitle??"",_=(Se??Me).getBoundingClientRect(),s=Me.getBoundingClientRect();V.fillStyle=getComputedStyle(Me).color||"#333",V.font=`600 ${Math.round(13*U)}px system-ui, sans-serif`,V.textBaseline="top",V.fillText(ce,(s.left-R.left+8)*U,(s.top-R.top+6)*U),Se&&V.drawImage(Se,(_.left-R.left)*U,(_.top-R.top)*U,_.width*U,_.height*U)}return Y}const Re=(m,z)=>z.extent?[...m,...z.extent]:m;function ue(m,z,W={}){const U=z.scale==="log";let R=m.length?jt(m):0,Y=m.length?Te(m):1;U&&(R=Math.log10(Math.max(R,Number.MIN_VALUE)),Y=Math.log10(Math.max(Y,Number.MIN_VALUE)));const V=(Y-R)*.05||(U?.5:1);R=W.floorAtZero&&!U&&R>=0?0:R-V,Y+=V;const Me=Pe=>Pe===void 0||!Number.isFinite(Pe)?void 0:U?Pe>0?Math.log10(Pe):void 0:Pe,Se=Me(z.min),ce=Me(z.max);Se!==void 0&&(R=Se),ce!==void 0&&(Y=ce),Y>R||(Y=R+1);const _=Y-R,s=!!z.reverse,Oe=Pe=>{const $=((U?Math.log10(Math.max(Pe,Number.MIN_VALUE)):Pe)-R)/_;return s?1-$:$};return{lo:U?10**R:R,hi:U?10**Y:Y,log:U,reverse:s,frac:Oe}}function It(m,z,W,U){if(z/m<10)return pt(m,z,W,U);const R=Math.floor(Math.log10(m)),Y=Math.ceil(Math.log10(z)),V=Se=>{const ce=[];for(let _=R;_<=Y;_++)for(const s of Se){const Oe=s*10**_;Oe>=m&&Oe<=z&&ce.push(Oe)}return ce},we=V([1]);return{ticks:we.length>=4?we:V([1,2,5]),step:0}}export function renderPlotChart(m){const z=m.ownerDocument??document,{card:W,heading:U,body:R,controlsRow:Y,setPngDecor:V,setPngCanvas:we,setAbout:Me,setMenuRows:Se}=Gn(m.panel?.title??"Plot",m.onSaveImage,z,{png:!m.panel});m.panel&&(W.dataset.wmapPlotPanel="1");let ce=[];W.dataset.wmapPlotCard="1";const _=Un(W);let s,Oe=()=>[];const Pe=()=>{const e=s&&(s.marks||s.facets?.length)?Dn(s,m.waferLabel):void 0;return e?[{label:"Save data as CSV",onClick:()=>{zn(e.columns,e.rows,`${e.name}.csv`,m.onSaveText)}},{label:"Copy data",onClick:()=>{z.defaultView?.navigator.clipboard?.writeText(_n(e.columns,e.rows))}}]:[]};Se(()=>[...Pe(),...Oe()]);let $,pe,te,Ze,Ie,ut,ht=!1;W.addEventListener("pointerenter",()=>{ht=!0,W.dataset.wmapPlotPanelsOwner&&(W.dataset.wmapPanelsHover="1")}),W.addEventListener("pointerleave",()=>{ht=!1,delete W.dataset.wmapPanelsHover});let ot=[];const O=new Set,he=new Set;let ge=null,ye=-1,le=[],Z,Ee,ne,se=null,lt=0,$e,dt;const an=()=>!!s?.facets;let de=[],be=-1,kt=new Map,Ye=[],qe=Ue,w=Wt,M=Rt;const rn={[qt.outlier]:"#e69f00",[qt.fails]:"#c0392b"},ee=e=>{const l=s?.groups[e]??"";if(s?.colorBins&&m.binColors){const a=In(l);return a===void 0?on:(s.colorBins==="hard"?m.binColors.hard:m.binColors.soft).get(a)??on}return rn[l]??lo(e)},He=e=>s?.groups[e]||"";function Ne(){const e=R.clientWidth,l=(m.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(qe-Ue),a=qn(W,R,$,l);return{w:e,h:a,plotW:Math.max(10,e-w-xt),plotH:Math.max(10,a-M-qe)}}const Be=e=>{const l=(e?.references??[]).flatMap(a=>a.to===void 0?[{value:a.at,kind:"ref",end:"lo",label:a.label??""}]:[{value:a.at,kind:"ref",end:"lo",label:a.label??"",bandTo:a.to},{value:a.to,kind:"ref",end:"hi",label:a.label??""}]);return[...Jn(e?.limits,s?.spec.limits??"both"),...l].filter(a=>e?.scale!=="log"||a.value>0)},Fe=(e,l,a)=>{const h=a?.clip,r=h?[...e.filter(c=>c>=h.lo&&c<=h.hi),h.lo,h.hi]:e,d=r.filter(Number.isFinite);if(!l.length||d.length===0)return r;const{lo:n,hi:t}=Qn(l);return(a?s?.spec.axes?.[a===s?.x?"x":"y"]?.includeLimits:void 0)??no(jt(d),Te(d),n,t)?[...r,...l.map(c=>c.value)]:r};let Mt;function Je(e,l,a,h=!1){return!h&&!s?.x?.clip&&!s?.y?.clip?()=>{}:(e.save(),e.beginPath(),e.rect(w,M,l,a),e.clip(),Mt=e,Nt)}function Nt(){Mt?.restore(),Mt=void 0}function ze(e,l,a,h,r,d,n,t,o){const c=[];if(d.length===0)return()=>{};const y=d.filter(p=>p.value>=r.lo&&p.value<=r.hi),x=d.filter(p=>!y.includes(p)).map(p=>({value:p.value,label:p.label,side:p.value<r.lo?"lo":"hi"}));e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`;const g=p=>`${p.label} ${J(p.value,n.unit)}`.trim(),f=Q(-1)+2;for(const p of d){if(p.bandTo===void 0)continue;const L=r.frac(Math.min(p.value,p.bandTo)),P=r.frac(Math.max(p.value,p.bandTo)),b=Math.max(0,Math.min(L,P)),C=Math.min(1,Math.max(L,P));C<=b||(e.save(),e.globalAlpha=.1,e.fillStyle=l,t==="y"?e.fillRect(w,M+(1-C)*h,a,(C-b)*h):e.fillRect(w+b*a,M,(C-b)*a,h),e.restore())}if(t==="y"){const p=y.map(b=>{const C=M+(1-r.frac(b.value))*h;return{l:b,y:C,start:C-6-f/2,end:C-6+f/2}}),L=en(p,1),P=p.length?Te(p.map(b=>e.measureText(g(b.l)).width))+8:0;p.forEach(({l:b,y:C},u)=>{e.globalAlpha=.7,nn(e,b,l,w,C,w+a,C),e.globalAlpha=1,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic";const i=w+3+L[u]*P,v=tn(Ye,{x0:i,x1:i+e.measureText(g(b)).width,y0:C-4-f+2,y1:C-4+2},f);if(!o){e.fillText(g(b),i,v.y1-2);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign="left",e.textBaseline="alphabetic",Ct(e,g(b),i,v.y1-2,o.halo),e.restore()})})}else{const p=y.map(P=>{const b=w+r.frac(P.value)*a,C=g(P),u=P.label.split(/\s+/)[0],i=J(P.value,n.unit),v=u&&u!==P.label?[C,`${u} ${i}`,u]:[C],B=y.filter(E=>E!==P).map(E=>w+r.frac(E.value)*a),{text:F,side:T}=to(b,v,E=>e.measureText(E).width,w,w+a,P.end==="lo",B),A=e.measureText(F).width;return{l:P,x:b,side:T,shown:F,start:T<0?b-3-A:b+3,end:T<0?b-3:b+3+A}}),L=en(p,4);p.forEach(({l:P,x:b,side:C,shown:u,start:i,end:v},B)=>{e.globalAlpha=.7,nn(e,P,l,b,M,b,M+h),e.globalAlpha=1;const F=C<0?"right":"left";e.fillStyle=l,e.textAlign=F,e.textBaseline="top";const T=M+2+L[B]*f,A=tn(Ye,{x0:i,x1:v,y0:T,y1:T+f},f);if(!o){e.fillText(u,b+C*3,A.y0);return}c.push(()=>{e.save(),e.font=`${Q(-1)}px system-ui, sans-serif`,e.fillStyle=l,e.textAlign=F,e.textBaseline="top",Ct(e,u,b+C*3,A.y0,o.halo),e.restore()})})}return e.restore(),eo(e,x,{left:w,right:w+a,top:M,bottom:M+h},t==="y"?"vertical":"horizontal",l,p=>J(p,n.unit),void 0,Ye),()=>c.forEach(p=>p())}function Tt(e,l,a,h){return Hn(Math.max(Math.abs(l),Math.abs(a)),e.unit,h,e.label)}function mt(e,l){return l?`${e.label} (${l})`:e.label}const wt=18,St=(e,l,a)=>{if(e.measureText(l).width<=a)return l;for(let h=l.length-1;h>0;h--){const r=`${l.slice(0,h)}\u2026`;if(e.measureText(r).width<=a)return r}return""};function Ke(e,l,a,h,r,d,n,t,o,c,y){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const x=()=>Kn,g=y?{ticks:y.map(b=>b.at),step:0}:t.log?It(t.lo,t.hi,d,x):pt(t.lo,t.hi,d,x),f=new Map(y?.map(b=>[b.at,b.label])),p=Tt(c,t.lo,t.hi,g.step||void 0),L=y?{tick:b=>f.get(b)??"",unitLabel:""}:p;e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;let P="";if("labels"in n){const b=n.labels.length;if(n.labels.forEach((C,u)=>{const i=w+(u+.5)/b*r,v=C.length>22?`${C.slice(0,21)}\u2026`:C;n.rotate?(e.save(),e.translate(i,M+d+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(v,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(v,i,M+d+4))}),n.nest){const C=n.nest[0]?.length??0,u=r/b;for(let i=C-2;i>=0;i--){const v=h-6-wt-i*wt,B=T=>n.nest[T].slice(0,i+1).join("");let F=0;for(let T=1;T<=b;T++){if(T<b&&B(T)===B(F))continue;const E=w+F*u,j=w+T*u;e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(St(e,n.nest[F][i],j-E-4),(E+j)/2,v),T<b&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=i===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(j,M),e.lineTo(j,v-2),e.stroke(),e.restore()),F=T}}e.fillStyle=l.textMuted}}else{const b=Zt(e,Math.max(Math.abs(n.lo),Math.abs(n.hi)),o.unit),C=n.log?It(n.lo,n.hi,r,b):pt(n.lo,n.hi,r,b),u=Tt(o,n.lo,n.hi,C.step||void 0);P=u.unitLabel;for(const i of C.ticks){const v=w+n.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(u.tick(i),v,M+d+4)}}for(const b of g.ticks){const C=M+(1-t.frac(b))*d;e.beginPath(),e.moveTo(w,C),e.lineTo(w+r,C),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(L.tick(b),w-4,C)}e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(mt(o,P),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(c,L.unitLabel),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function cn(e,l,a,h,r,d,n,t,o,c,y,x={along:d,offset:0}){Ye=[],e.font=`${Q(-1)}px system-ui, sans-serif`;const g=Zt(e,Math.max(Math.abs(o.lo),Math.abs(o.hi)),y.unit),f=o.log?It(o.lo,o.hi,r,g):pt(o.lo,o.hi,r,g),p=Tt(y,o.lo,o.hi,f.step||void 0);e.strokeStyle=l.grid,e.lineWidth=.5,e.fillStyle=l.textMuted;for(const i of f.ticks){const v=w+o.frac(i)*r;e.beginPath(),e.moveTo(v,M),e.lineTo(v,M+d),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(p.tick(i),v,M+d+4)}const L=n.labels.length,P=x.along/Math.max(1,L),b=M-x.offset;e.save(),e.beginPath(),e.rect(0,M-1,w+r+1,d+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const C=Math.max(0,Math.floor(x.offset/P)),u=Math.min(L,Math.ceil((x.offset+d)/P));for(let i=C;i<u;i++)e.fillText(St(e,n.labels[i],t.inner),w-6,b+(i+.5)*P);if(n.nest){const i=n.nest[0]?.length??0;let v=w-6-t.inner-10;for(let B=i-2;B>=0;B--){const F=t.outer[B]??0,T=E=>n.nest[E].slice(0,B+1).join("");let A=0;for(let E=1;E<=L;E++){if(E<L&&T(E)===T(A))continue;const j=b+A*P,k=b+E*P;e.fillStyle=l.text,e.textAlign="right",e.textBaseline="middle",e.fillText(St(e,n.nest[A][B],F),v,(j+k)/2),E<L&&(e.save(),e.strokeStyle=l.border,e.globalAlpha=B===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(v-F,k),e.lineTo(w+r,k),e.stroke(),e.restore()),A=E}v-=F+10}e.fillStyle=l.textMuted}e.restore(),e.font=`${Q(0)}px system-ui, sans-serif`,e.fillStyle=l.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(mt(y,p.unitLabel),w+r/2,h-6),e.save(),e.translate(14,M+d/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(mt(c,""),0,0),e.restore(),e.strokeStyle=l.border,e.lineWidth=1,e.beginPath(),e.moveTo(w,M),e.lineTo(w,M+d),e.moveTo(w,M+d),e.lineTo(w+r,M+d),e.stroke()}function fn(){if(!s||!$||s.marks?.type!=="scatter"||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,t=s.marks.points,o=O.size===0?t:t.filter(T=>O.has(T.group)),c=s.colorScale,y=bt(s.spec.colorGradient,s.spec.colorReverse,c?.diverging,c?.rating),x=Be(s.x),g=Be(s.y),f=ue(Fe(Re(t.map(T=>T.x),s.x),x,s.x),s.x),p=ue(Fe(Re(t.map(T=>T.y),s.y),g,s.y),s.y);Z={x:f,y:p,plotW:h,plotH:r},Ke(n,e,l,a,h,r,f,p,s.x,s.y),ze(n,e.limitLine,h,r,f,x,s.x,"x"),ze(n,e.limitLine,h,r,p,g,s.y,"y"),Je(n,h,r);const L=o.length>vt?Math.ceil(o.length/vt):1,P=[];for(let T=0;T<o.length;T+=L)P.push(o[T]);n.globalAlpha=Math.max(.15,Math.min(.7,200/P.length));let b;if(c)b=[P];else{const T=new Map;for(const A of P){const E=T.get(A.group);E?E.push(A):T.set(A.group,[A])}b=[...T.values()].sort((A,E)=>E.length-A.length)}le=[];const C=w,u=w+h,i=M,v=M+r;for(const T of b)for(const A of T){const E=w+f.frac(A.x)*h,j=M+(1-p.frac(A.y))*r;E<C||E>u||j<i||j>v||(le.push({p:A,cx:E,cy:j}),n.beginPath(),n.arc(E,j,2.5,0,Math.PI*2),n.fillStyle=c&&A.value!==void 0?y((A.value-c.lo)/(c.hi-c.lo||1)):ee(A.group),n.fill())}n.globalAlpha=1;const B=s.marks;if(B.type==="scatter"&&(B.identity||B.fits)){const T=(E,j)=>[w+f.frac(E)*h,M+(1-p.frac(j))*r],A=(E,j,k)=>{n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=j,n.lineWidth=2,n.setLineDash(k),n.beginPath();for(let ie=0;ie<=60;ie++){const We=ie/60,De=f.log?10**(Math.log10(f.lo)+(Math.log10(f.hi)-Math.log10(f.lo))*We):f.lo+(f.hi-f.lo)*We,[Le,fe]=T(De,E(De));ie===0?n.moveTo(Le,fe):n.lineTo(Le,fe)}n.stroke(),n.restore()};B.identity&&A(E=>E,e.textMuted,[6,4]);for(const E of B.fits??[])O.size>0&&!O.has(E.group)&&!c||A(j=>E.intercept+E.slope*j,c?e.text:ee(E.group),[])}const F=ge?le.find(T=>T.p===ge):void 0;if(F&&(n.beginPath(),n.arc(F.cx,F.cy,5,0,Math.PI*2),n.lineWidth=2,n.strokeStyle=e.text,n.stroke()),he.size>0){n.lineWidth=1.5,n.strokeStyle=e.text;let T=0;for(const A of he)if(!(O.size>0&&!O.has(A.group))){if(++T>vt)break;n.beginPath(),n.arc(w+f.frac(A.x)*h,M+(1-p.frac(A.y))*r,4,0,Math.PI*2),n.stroke()}}}function un(){if(Ee=void 0,!s||s.marks?.type!=="histogram"||!s.x)return;const e=s.marks.values,l=e.flat();if(l.length===0)return;const a=ue(Fe(Re(l,s.x),Be(s.x),s.x),s.x),h=Math.max(1,s.spec.bins??co),r=a.log?Math.log10(a.lo):a.lo,d=a.log?Math.log10(a.hi):a.hi,n=Array.from({length:h+1},(g,f)=>{const p=r+(d-r)*f/h;return a.log?10**p:p}),t=e.map(()=>new Array(h).fill(0));e.forEach((g,f)=>{for(const p of g){const L=a.log?p>0?Math.log10(p):NaN:p;if(!Number.isFinite(L)||L<r||L>d)continue;const P=Math.min(h-1,Math.floor((L-r)/(d-r)*h));t[f][P]++}});const o=s.spec.histNorm==="percent",c=o?t.map(g=>{const f=g.reduce((p,L)=>p+L,0);return g.map(p=>f?p/f*100:0)}):t;let y=0;const x=e.map(()=>{});if(s.spec.normalCurve&&!a.log){const g=(n[n.length-1]-n[0])/h;e.forEach((f,p)=>{const L=f.filter(Number.isFinite);if(L.length<2)return;const P=L.reduce((C,u)=>C+u,0)/L.length,b=Math.sqrt(Rn(L,P));b>0&&(x[p]={mean:P,sd:b},y=Math.max(y,(o?100:t[p].reduce((C,u)=>C+u,0))*g/(b*Math.sqrt(2*Math.PI))))})}Ee={edges:n,counts:t,heights:c,normal:x,maxCount:Math.max(o?.001:1,y,...c.map(g=>Te(g)))}}function hn(){if(!s||!$||!Ee||!s.x||!s.y)return;Ge($,te??0);const e=je(W),{w:l,h:a,plotW:h,plotH:r}=Ne(),d=Xe($,W,l,a);if(!d)return;const{ctx:n}=d,{edges:t,counts:o,heights:c,normal:y,maxCount:x}=Ee,g=ue([t[0],t[t.length-1]],{...s.x,min:t[0],max:t[t.length-1]}),f=ue([0,x],{label:s.y.label,scale:"linear",min:0,max:x*1.05});Z={x:g,y:f,plotW:h,plotH:r},Ke(n,e,l,a,h,r,g,f,s.x,s.y),ze(n,e.limitLine,h,r,g,Be(s.x),s.x,"x"),Je(n,h,r);const p=o.map((u,i)=>i).filter(u=>O.size===0||O.has(u)),L=p.length>1,P=p.length>=3,b=u=>w+Math.min(g.frac(t[u]),g.frac(t[u+1]))*h,C=u=>w+Math.max(g.frac(t[u]),g.frac(t[u+1]))*h;for(const u of p){if(P){n.fillStyle=ee(u),n.strokeStyle=ee(u),n.lineWidth=1.75,n.lineJoin="round",n.globalAlpha=.1,c[u].forEach((v,B)=>{if(v===0)return;const F=M+(1-f.frac(v))*r;n.fillRect(b(B),F,Math.max(1,C(B)-b(B)),M+r-F)}),n.globalAlpha=1,n.beginPath();let i=!1;c[u].forEach((v,B)=>{const F=M+(1-f.frac(v))*r;i||(n.moveTo(b(B),M+r),i=!0),n.lineTo(b(B),F),n.lineTo(C(B),F),B===c[u].length-1&&n.lineTo(C(B),M+r)}),n.stroke();continue}n.globalAlpha=L?.55:.85,n.fillStyle=ee(u),c[u].forEach((i,v)=>{if(i===0)return;const B=M+(1-f.frac(i))*r;n.fillRect(b(v),B,Math.max(1,C(v)-b(v)-1),M+r-B)})}if(n.globalAlpha=1,s.spec.normalCurve&&!g.log){const u=(t[t.length-1]-t[0])/(t.length-1);for(const i of p){const v=y[i];if(!v)continue;const{mean:B,sd:F}=v,T=(s.spec.histNorm==="percent"?100:o[i].reduce((A,E)=>A+E,0))*u;n.save(),n.beginPath(),n.rect(w,M,h,r),n.clip(),n.strokeStyle=ee(i),n.lineWidth=2,n.beginPath();for(let A=0;A<=120;A++){const E=t[0]+(t[t.length-1]-t[0])*A/120,j=Math.exp(-.5*((E-B)/F)**2)/(F*Math.sqrt(2*Math.PI)),k=w+g.frac(E)*h,ie=M+(1-f.frac(T*j))*r;A===0?n.moveTo(k,ie):n.lineTo(k,ie)}n.stroke(),n.restore()}}if(ye>=0){const u=w+Math.min(g.frac(t[ye]),g.frac(t[ye+1]))*h,i=w+Math.max(g.frac(t[ye]),g.frac(t[ye+1]))*h;n.lineWidth=1.5,n.strokeStyle=e.text,n.strokeRect(u,M,Math.max(1,i-u),r)}}function dn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="box"&&e.type!=="bar")return;Ge($,te??0);const l=je(W),a=s.spec.orientation==="horizontal",h=e.nest?e.nest.parts.map(S=>S[S.length-1]):e.categories,r=e.categories.length,d=s.groups.length,n=S=>O.size===0||O.has(S),t=e.type==="bar"&&!!e.stack,o=(S,N)=>e.type==="bar"?Number.isFinite(e.values[S][N]):e.cells[S][N].length>0,c=Array.from({length:r},(S,N)=>Array.from({length:d},(I,D)=>D).filter(I=>n(I)&&o(I,N))),y=categoryLayout(t?c.map(S=>S.length?[0]:[]):c),x=$.getContext("2d"),g=S=>x?x.measureText(S).width:S.length*6;x&&(x.font=`${Q(-1)}px system-ui, sans-serif`);const f=(S,N)=>S.length>N?`${S.slice(0,N-1)}\u2026`:S;let p=!1,L={inner:0,outer:[]},P=0;if(a){L={inner:Math.min(200,Te(h.map(N=>g(f(N,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((N,I)=>Math.min(140,Te(e.nest.parts.map(D=>g(f(D[I],20)))))):[]},w=Math.max(Wt,30+L.inner+6+L.outer.reduce((N,I)=>N+I+10,0)),e.cumulative&&(M=Rt+18),qe=Ue;const S=Math.max(1,...c.map(N=>t?Math.min(1,N.length):N.length));P=Math.max(22,S*ao/.8)}else{const S=Te(h.map(D=>g(f(D,22)))),N=Math.max(10,R.clientWidth-w-xt)/Math.max(1,r);p=S+8>N;const I=e.nest?e.nest.levels.length-1:0;qe=(p?Ue+Math.min(110,S*.72):Ue)+I*wt}const b=e.type==="bar"&&!t&&!!s.spec.valueLabels,C=s.y.unit,u=S=>J(S,C),i=b?Te(e.values.flat().filter(Number.isFinite).map(S=>g(u(S))).concat(0))+8:0,v=a?i:e.cumulative?40:0,{w:B,h:F,plotW:T,plotH:A}=Ne(),E=Math.max(10,T-v),j=Xe($,W,B,F);if(!j)return;const{ctx:k}=j,ie=S=>S.filter(Number.isFinite),We=Be(s.y),De=t?e.categories.map((S,N)=>e.values.reduce((I,D,q)=>I+(n(q)&&Number.isFinite(D[N])?D[N]:0),0)):[],Le=e.type==="bar"?[...t?De:ie(e.values.flat()),0]:ie(e.cells.flat(2));k.font=`${Q(-1)}px system-ui, sans-serif`;const fe=a?i:Q(-1)+6;if(b&&!a&&Le.length){const S=Te(Le);S>0&&Le.push(S*(1+fe/Math.max(1,A-fe)))}const Ae=ue(Fe(Re(Le,s.y),We,s.y),s.y,{floorAtZero:e.type==="bar"});Z={x:Ae,y:Ae,plotW:E,plotH:A};const it=a?A:E,Qe=a&&r*P>A+.5,at=Qe?r*P:it,rt=Qe?Math.max(0,Math.min(lt,at-it)):0;lt=rt,Pn(Qe,at,rt,E+v,A),a?cn(k,l,B,F,E,A,{labels:h,rotate:!1,nest:e.nest?.parts},L,Ae,s.x,s.y,{along:at,offset:rt}):Ke(k,l,B,F,E,A,{labels:h,rotate:p,nest:e.nest?.parts},Ae,s.x,s.y);const ve=at/r,Ce=y.width*ve;ne={slotW:ve,n:r,plotW:at,layout:y,across:a,offset:rt,view:it};const oe=S=>a?w+Ae.frac(S)*E:M+(1-Ae.frac(S))*A,ke=S=>a?M+S-rt:w+S,Lt=Ae.log?a?w:M+A:oe(0),et=(S,N,I,D)=>a?[Math.min(I,D),ke(S),Math.max(1,Math.abs(D-I)),N-S]:[ke(S),Math.min(I,D),N-S,Math.max(1,Math.abs(D-I))],At=(S,N,I,D)=>{k.beginPath(),a?(k.moveTo(N,ke(S)),k.lineTo(D,ke(I))):(k.moveTo(ke(S),N),k.lineTo(ke(I),D)),k.stroke()},tt=S=>a?S>=Lt:S<=Lt,En=S=>a?Q(-1)<=Ce+4:k.measureText(u(S)).width<=Ce+6,Dt=b&&e.values.every(S=>S.every(N=>!Number.isFinite(N)||En(N)));if(Dt){for(let S=0;S<d;S++)if(n(S))for(let N=0;N<r;N++){const I=y.left(N,S),D=e.values[S][N];if(I===void 0||!Number.isFinite(D))continue;const q=ke(N*ve+I*ve+Ce/2),H=k.measureText(u(D)).width,G=oe(D);a?Ye.push(tt(G)?{x0:G,x1:G+H+6,y0:q-fe/2,y1:q+fe/2}:{x0:G-H-6,x1:G,y0:q-8,y1:q+8}):Ye.push(tt(G)?{x0:q-H/2,x1:q+H/2,y0:G-fe,y1:G}:{x0:q-H/2,x1:q+H/2,y0:G,y1:G+fe})}}const Bn=ze(k,l.limitLine,E,A,Ae,We,s.y,a?"x":"y",{halo:l.bg}),Wn=Je(k,E,A,Qe);if(t){ne.stacks=[];for(let S=0;S<r;S++){const N=y.left(S,0),I=[];if(ne.stacks.push(I),N===void 0)continue;let D=0;for(let q=0;q<d;q++){const H=e.values[q][S];if(!n(q)||!Number.isFinite(H)||H<=0)continue;const G=oe(D),ae=oe(D+H);k.fillStyle=ee(q),k.globalAlpha=.9;const re=S*ve+N*ve;k.fillRect(...et(re+1,re+Ce-1,G,ae)),k.globalAlpha=1,I.push({g:q,p0:Math.min(G,ae),p1:Math.max(G,ae)}),D+=H}}}for(let S=0;S<d&&!t;S++){if(O.size>0&&!O.has(S))continue;const N=ee(S);for(let I=0;I<r;I++){const D=y.left(I,S);if(D===void 0)continue;const q=I*ve+D*ve;if(e.type==="bar"){const H=e.values[S][I];if(!Number.isFinite(H))continue;const G=oe(H);if(k.fillStyle=N,k.globalAlpha=.9,k.fillRect(...et(q+1,q+Ce-1,Lt,G)),k.globalAlpha=1,Dt){k.fillStyle=l.text,k.font=`${Q(-1)}px system-ui, sans-serif`;const ae=ke(q+Ce/2);a?(k.textBaseline="middle",k.textAlign=tt(G)?"left":"right",k.fillText(u(H),G+(tt(G)?3:-3),ae)):(k.textAlign="center",k.textBaseline=tt(G)?"bottom":"top",k.fillText(u(H),ae,G+(tt(G)?-2:2)))}}else{const H=e.cells[S][I];if(H.length===0)continue;const G=q+Ce/2,ae=Math.max(3,Math.min(Ce*.7,46)),re=Ut(Float64Array.from(H));if(k.strokeStyle=N,k.fillStyle=N,k.lineWidth=1.5,H.length===1){k.beginPath(),a?k.arc(oe(re.median),ke(G),3,0,Math.PI*2):k.arc(ke(G),oe(re.median),3,0,Math.PI*2),k.fill();continue}At(G,oe(re.min),G,oe(re.max));for(const Xt of[re.min,re.max])At(G-ae/4,oe(Xt),G+ae/4,oe(Xt));k.globalAlpha=.35,k.fillRect(...et(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.globalAlpha=1,k.strokeRect(...et(G-ae/2,G+ae/2,oe(re.q1),oe(re.q3))),k.lineWidth=2.5,At(G-ae/2,oe(re.median),G+ae/2,oe(re.median))}}}Wn(),Bn();const Gt=se?y.left(se.c,t?0:se.g):void 0;if(se&&Gt!==void 0){Qe&&(k.save(),k.beginPath(),k.rect(w-1,M,E+2,A),k.clip()),k.lineWidth=1.5,k.strokeStyle=l.text;const S=se.c*ve+Gt*ve,N=t?ne.stacks?.[se.c]?.find(I=>I.g===se.g):void 0;t&&N?k.strokeRect(...et(S,S+Ce,N.p0,N.p1)):t||k.strokeRect(...et(S,S+Ce,a?w:M,a?w+E:M+A)),Qe&&k.restore()}if(e.cumulative){const S=I=>a?w+I/100*E:M+(1-I/100)*A,N=(I,D)=>a?[S(D),ke((I+.5)*ve)]:[ke((I+.5)*ve),S(D)];if(k.save(),k.strokeStyle=l.text,k.fillStyle=l.text,k.lineWidth=1.5,k.beginPath(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);D===0?k.moveTo(q,H):k.lineTo(q,H)}),k.stroke(),e.cumulative.forEach((I,D)=>{const[q,H]=N(D,I);k.beginPath(),k.arc(q,H,2.5,0,Math.PI*2),k.fill()}),k.strokeStyle=l.border,k.lineWidth=1,k.beginPath(),a?(k.moveTo(w,M),k.lineTo(w+E,M)):(k.moveTo(w+E,M),k.lineTo(w+E,M+A)),k.stroke(),k.fillStyle=l.textMuted,k.font=`${Q(-1)}px system-ui, sans-serif`,a){k.textAlign="center",k.textBaseline="bottom";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,S(I),M-3)}else{k.textAlign="left",k.textBaseline="middle";for(const I of[0,25,50,75,100])k.fillText(`${I}%`,w+E+4,S(I))}k.restore()}}function mn(e){const l=s?.setTests,a=l?l.labels.indexOf(e):-1;return a>=0?{test:l.tests[a]}:{}}function Pt(e){if(!ne||!$)return null;const l=$.getBoundingClientRect(),a=ne.across?e.clientY-l.top-M:e.clientX-l.left-w;if(a<0||a>ne.view)return null;const h=a+ne.offset,r=Math.min(ne.n-1,Math.floor(h/ne.slotW)),d=ne.layout.groupAt(r,(h-r*ne.slotW)/ne.slotW);if(d===void 0)return null;if(!ne.stacks)return{g:d,c:r};const n=ne.across?e.clientX-l.left:e.clientY-l.top,t=ne.stacks[r]?.find(o=>n>=o.p0&&n<=o.p1);return t?{g:t.g,c:r}:null}function pn(e,l,a){let h=0,r=0,d=0;for(const o of l)o===100&&h++;if(e.failSide)for(const o of a){const c=e.failSide[o];c<0?r++:c>0&&d++}const n=o=>o.toLocaleString("en-GB"),t=r+d>0?` (${n(r)} below the low limit \xB7 ${n(d)} above the high limit)`:"";return`${n(h)} pass \xB7 ${n(l.length-h)} fail${t} \xB7 n = ${n(l.length)}`}function gn(e){const l=s,a=l.marks,h=l.level==="die"?"dies":"wafers",r=a.cells[e.g][e.c],d=a.nest?a.nest.parts[e.c]:[a.categories[e.c]],n=l.groups.length>1&&!d.includes(He(e.g))?` \xB7 ${X(He(e.g))}`:"",t=`<strong>${X(a.categories[e.c])}${n}</strong><br>`,o=l.y?.unit;if(r.length===0)return`${t}no ${h}`;const c=`${r.length.toLocaleString("en-GB")} ${h}`,y=(a.categoryItems&&m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(a.categoryItems&&m.onWaferMenu?Et:"");if(a.type==="bar"){const g=a.values[e.g][e.c],f=a.cumulative?`<br>${X(`cumulative: ${a.cumulative[e.c].toFixed(1)}% of the whole`)}`:"";return`${t}${X(`${l.y.label}: ${J(g,o)}`)}<br>${X(a.passFail?pn(a.passFail,r,a.cellUnits[e.g][e.c]):c)}${f}${y}`}const x=Ut(Float64Array.from(r));return`${t}${["max","q3","median","q1","min"].map(g=>X(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[g]}: ${J(x[g],o)}`)).join("<br>")}<br>${X(c)}${y}`}function yn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||!e||e.type!=="line")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Be(s.x),c=Be(s.y),y=ue(Fe(Re(e.xs,s.x),o,s.x),s.x),x=e.band?[...e.band.lo.flat(),...e.band.hi.flat()]:[],g=ue(Fe(Re([...e.values.flat(),...x].filter(Number.isFinite),s.y),c,s.y),s.y);if(Z={x:y,y:g,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,g,s.x,s.y),ze(t,l.limitLine,r,d,y,o,s.x,"x"),ze(t,l.limitLine,r,d,g,c,s.y,"y"),Je(t,r,d),de=e.xs.map(f=>w+y.frac(f)*r),e.band){const f=p=>M+(1-g.frac(p))*d;e.band.lo.forEach((p,L)=>{if(O.size>0&&!O.has(L))return;const P=e.band.hi[L];t.save(),t.fillStyle=ee(L),t.globalAlpha=.16;let b=[];const C=()=>{if(b.length===1){const u=b[0],i=de[u];t.globalAlpha=.55,t.strokeStyle=ee(L),t.lineWidth=2,t.beginPath(),t.moveTo(i,f(p[u])),t.lineTo(i,f(P[u])),t.moveTo(i-4,f(p[u])),t.lineTo(i+4,f(p[u])),t.moveTo(i-4,f(P[u])),t.lineTo(i+4,f(P[u])),t.stroke(),t.globalAlpha=.16}else if(b.length){t.beginPath(),b.forEach((u,i)=>{i===0?t.moveTo(de[u],f(P[u])):t.lineTo(de[u],f(P[u]))});for(let u=b.length-1;u>=0;u--)t.lineTo(de[b[u]],f(p[b[u]]));t.closePath(),t.fill()}b=[]};p.forEach((u,i)=>{Number.isFinite(u)&&Number.isFinite(P[i])?b.push(i):C()}),C(),t.restore()})}e.values.forEach((f,p)=>{if(O.size>0&&!O.has(p))return;t.strokeStyle=ee(p),t.fillStyle=ee(p),t.lineWidth=2;let L=!1;t.beginPath(),f.forEach((P,b)=>{if(!Number.isFinite(P)){L=!1;return}const C=de[b],u=M+(1-g.frac(P))*d;L?t.lineTo(C,u):t.moveTo(C,u),L=!0}),t.stroke(),f.forEach((P,b)=>{Number.isFinite(P)&&(t.beginPath(),t.arc(de[b],M+(1-g.frac(P))*d,be===b?4.5:3,0,Math.PI*2),t.fill())})}),be>=0&&(t.lineWidth=1,t.strokeStyle=l.textMuted,t.beginPath(),t.moveTo(de[be],M),t.lineTo(de[be],M+d),t.stroke())}function $t(e){const l=s?.marks;if(!l||l.type!=="line"||!$||!s?.x||de.length===0)return null;const a=e.clientX-$.getBoundingClientRect().left;let h=-1,r=24;if(de.forEach((t,o)=>{const c=Math.abs(t-a);c<r&&(r=c,h=o)}),be=h,h<0)return null;const d=s.level==="die"?"dies":"wafers",n=l.values.map((t,o)=>({g:o,v:t[h],n:l.counts[o][h]})).filter(t=>Number.isFinite(t.v)&&(O.size===0||O.has(t.g)));return`<strong>${X(`${s.x.label}: ${J(l.xs[h],s.x.unit)}`)}</strong><br>`+n.map(t=>{const o=l.band?.lo[t.g][h],c=l.band?.hi[t.g][h],y=o!==void 0&&c!==void 0&&Number.isFinite(o)&&Number.isFinite(c)?`, band ${J(o,s.y.unit)} to ${J(c,s.y.unit)}`:"";return X(`${s.groups.length>1?`${He(t.g)}: `:""}${J(t.v,s.y.unit)}${y} (${t.n.toLocaleString("en-GB")} ${d})`)}).join("<br>")+(m.onWaferMenu&&Ft(h)!==void 0?Et:"")}function Ft(e){const l=s?.marks;if(l?.type!=="line")return;const a=new Set(l.cellUnits.flatMap((h,r)=>O.size>0&&!O.has(r)?[]:(h[e]??[]).map(d=>l.unit(d).item)));return a.size===1?[...a][0]:void 0}function bn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="probability")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=s.spec.probabilityAxis==="linear",c=e.values.map((T,A)=>A).filter(T=>e.values[T].length>0&&(O.size===0||O.has(T))),y=Math.max(1,...c.map(T=>e.values[T].length)),x=Math.min(.01,ct(0,y)),g=T=>o?T:Yt(T),f=o?0:g(x),p=o?1:g(1-x),L=o?0:(p-f)*.03,P=ue([f-L,p+L],{label:s.y.label,scale:"linear",min:f-L,max:p+L}),b=o?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:fo.filter(T=>T>=x&&T<=1-x),C=[],u=T=>M+(1-P.frac(T))*d,i=b.indexOf(.5);C.push({at:g(.5),label:sn(.5)});for(const T of[b.slice(i+1),b.slice(0,i).reverse()]){let A=u(g(.5));for(const E of T){const j=u(g(E));Math.abs(j-A)<16||(C.push({at:g(E),label:sn(E)}),A=j)}}const v=Be(s.x),B=ue(Fe(Re(c.flatMap(T=>[e.values[T][0],e.values[T][e.values[T].length-1]]),s.x),v,s.x),s.x);Z={x:B,y:P,plotW:r,plotH:d},Ke(t,l,a,h,r,d,B,P,s.x,s.y,C),ze(t,l.limitLine,r,d,B,v,s.x,"x"),Je(t,r,d),le=[],t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();for(const T of c){const A=e.values[T],E=A.length,j=uo(E);if(t.strokeStyle=ee(T),t.fillStyle=ee(T),t.lineWidth=1.5,t.beginPath(),j.forEach((k,ie)=>{const We=w+B.frac(A[k])*r,De=u(g(ct(k,E)));ie===0?t.moveTo(We,De):t.lineTo(We,De);const Le=T*2**26+k;let fe=kt.get(Le);if(!fe){const{item:Ae,die:it}=e.unit(e.units[T][k]);fe={x:A[k],y:ct(k,E),group:T,item:Ae,die:it},kt.set(Le,fe)}le.push({p:fe,cx:We,cy:De})}),t.stroke(),E<=300)for(const k of j)t.beginPath(),t.arc(w+B.frac(A[k])*r,u(g(ct(k,E))),2.5,0,Math.PI*2),t.fill()}if(t.restore(),he.size>0){t.lineWidth=1.5,t.strokeStyle=l.text;let T=0;for(const A of he)if(!(O.size>0&&!O.has(A.group))){if(++T>vt)break;t.beginPath(),t.arc(w+B.frac(A.x)*r,u(g(A.y)),4,0,Math.PI*2),t.stroke()}}const F=ge?le.find(T=>T.p===ge):void 0;F&&(t.beginPath(),t.arc(F.cx,F.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function xn(e){const l=s,h=l.marks.values[e.group].length,r=Math.round(e.y*h+.5),d=m.waferLabel(e.item),n=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[d,n].filter(Boolean).join(" \xB7 ");return(t?`<strong>${X(t)}</strong><br>`:"")+X(`${l.x.label}: ${J(e.x,l.x.unit)}`)+"<br>"+X(`rank ${r.toLocaleString("en-GB")} of ${h.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")+(m.onWaferMenu&&!e.die?Et:"")}let _e,xe=null;function vn(){const e=s?.marks;if(!s||!$||e?.type!=="heatmap")return;Ge($,te??0);const l=je(W),a=$.getContext("2d");let h=0,r=0;a&&(a.font=`${Q(-1)}px system-ui, sans-serif`,h=Te(e.rows.map(u=>a.measureText(u.length>24?`${u.slice(0,23)}\u2026`:u).width)),r=Te(e.cols.map(u=>a.measureText(u.length>22?`${u.slice(0,21)}\u2026`:u).width)));const d=Math.min(180,Math.max(w,h+24)),n=Math.max(8,R.clientWidth-d-xt)/Math.max(1,e.cols.length),t=r+8>n;qe=t?Ue+Math.min(110,r*.72):Ue;const{w:o,h:c}=Ne(),y=Math.max(10,o-d-xt),x=Math.max(10,c-M-qe),g=Xe($,W,o,c);if(!g)return;const{ctx:f}=g,p=y/e.cols.length,L=x/e.rows.length;_e={left:d,cw:p,ch:L,rows:e.rows.length,cols:e.cols.length};const P=s.colorScale,b=bt(s.spec.colorGradient,s.spec.colorReverse,P?.diverging,P?.rating),C=P&&P.hi-P.lo||1;f.font=`${Q(-1)}px system-ui, sans-serif`;for(let u=0;u<e.rows.length;u++)for(let i=0;i<e.cols.length;i++){const v=e.values[u][i],B=d+i*p,F=M+u*L,T=Number.isFinite(v)&&P?b((v-P.lo)/C):l.track;if(f.fillStyle=T,f.fillRect(B,F,p,L),Number.isFinite(v)&&p>=40&&L>=16){const A=so(T);f.fillStyle=A?"#1a1a1a":"#fff",f.textAlign="center",f.textBaseline="middle",Ct(f,Ot(v,s.y?.unit,P?.integer),B+p/2,F+L/2,A?"rgba(255,255,255,0.55)":"rgba(0,0,0,0.55)")}}f.lineWidth=1,f.setLineDash([]),f.strokeStyle=l.border,f.beginPath();for(let u=1;u<e.rows.length;u++){const i=Math.round(M+u*L)+.5;f.moveTo(d,i),f.lineTo(d+y,i)}for(let u=1;u<e.cols.length;u++){const i=Math.round(d+u*p)+.5;f.moveTo(i,M),f.lineTo(i,M+x)}f.stroke(),f.strokeStyle=l.textMuted,f.strokeRect(d+.5,M+.5,y-1,x-1),f.beginPath();for(let u=0;u<e.rows.length;u++){const i=Math.round(M+(u+.5)*L)+.5;f.moveTo(d-4,i),f.lineTo(d,i)}for(let u=0;u<e.cols.length;u++){const i=Math.round(d+(u+.5)*p)+.5;f.moveTo(i,M+x),f.lineTo(i,M+x+4)}f.stroke(),xe&&(f.lineWidth=2,f.strokeStyle=l.text,f.strokeRect(d+xe.c*p,M+xe.r*L,p,L)),f.fillStyle=l.textMuted,f.textAlign="right",f.textBaseline="middle",e.rows.forEach((u,i)=>f.fillText(u.length>24?`${u.slice(0,23)}\u2026`:u,d-8,M+(i+.5)*L)),e.cols.forEach((u,i)=>{const v=u.length>22?`${u.slice(0,21)}\u2026`:u,B=d+(i+.5)*p;t?(f.save(),f.translate(B,M+x+8),f.rotate(-Math.PI/4),f.textAlign="right",f.textBaseline="middle",f.fillText(v,0,0),f.restore()):(f.textAlign="center",f.textBaseline="top",f.fillText(v,B,M+x+7))}),f.font=`${Q(0)}px system-ui, sans-serif`,f.fillStyle=l.text,f.textAlign="center",f.textBaseline="bottom",f.fillText(s.x?.label??"",d+y/2,c-6)}function zt(e){if(!_e||!$)return null;const l=$.getBoundingClientRect(),a=Math.floor((e.clientX-l.left-_e.left)/_e.cw),h=Math.floor((e.clientY-l.top-M)/_e.ch);return h>=0&&h<_e.rows&&a>=0&&a<_e.cols?{r:h,c:a}:null}function kn(e){const l=s,a=l.marks,h=a.values[e.r][e.c],r=a.cellUnits[e.r][e.c].length,d=l.level==="die"?"dies":"wafers";return`<strong>${X(`${a.rows[e.r]} \xB7 ${a.cols[e.c]}`)}</strong><br>`+(Number.isFinite(h)?X(`${l.y?.label??"Count"}: ${Ot(h,l.y?.unit,l.colorScale?.integer)}`)+"<br>":"")+X(`${r.toLocaleString("en-GB")} ${d}`)+(r&&m.onSelectPoints?"<br><em>click or right-click to chart or tabulate them</em>":"")}function Mn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="control")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=e.limits,c=Be(s.y),y=ue(Re(e.xs,s.x),s.x),x=ue(Fe(Re([...e.values,o.ucl,o.lcl],s.y),c,s.y),s.y);Z={x:y,y:x,plotW:r,plotH:d},Ke(t,l,a,h,r,d,y,x,s.x,s.y),ze(t,l.limitLine,r,d,x,c,s.y,"y"),Je(t,r,d);const g=i=>w+y.frac(e.xs[i])*r,f=i=>M+(1-x.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip();const p=(i,v,B,F=1)=>{t.globalAlpha=B,t.setLineDash(v),t.lineWidth=F,t.strokeStyle=l.text,t.beginPath(),t.moveTo(w,f(i)),t.lineTo(w+r,f(i)),t.stroke()};for(const i of[-2,-1,1,2])p(o.centre+i*o.sigma,[2,4],.25);p(o.centre,[],.6,1.5),p(o.ucl,[6,4],.85),p(o.lcl,[6,4],.85),t.restore(),t.fillStyle=l.textMuted,t.font=`${Q(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const L=i=>J(i,s.y.unit);if(t.fillText(`UCL ${L(o.ucl)}`,w+r-4,f(o.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${L(o.lcl)}`,w+r-4,f(o.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${L(o.centre)}`,w+r-4,f(o.centre)-2),o.baseline<e.values.length){const i=(g(o.baseline-1)+g(o.baseline))/2;t.save(),t.strokeStyle=l.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(i,M),t.lineTo(i,M+d),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",w+4,M+2)}t.strokeStyle=ee(0),t.lineWidth=1.5,t.setLineDash([]);const P=O.size>0,b=i=>e.group?.[i]??0;if(!P)t.beginPath(),e.values.forEach((i,v)=>{v===0?t.moveTo(g(v),f(i)):t.lineTo(g(v),f(i))}),t.stroke();else{for(const i of[!1,!0]){t.globalAlpha=i?1:.2,t.beginPath();for(let v=1;v<e.values.length;v++)(O.has(b(v-1))&&O.has(b(v)))===i&&(t.moveTo(g(v-1),f(e.values[v-1])),t.lineTo(g(v),f(e.values[v])));t.stroke()}t.globalAlpha=1}const C=new Map(e.violations.map(i=>[i.index,i.rules]));le=[],e.values.forEach((i,v)=>{const B=C.get(v),F=b(v),T=P&&O.has(F),A=P&&!T;t.globalAlpha=A?.2:1,t.beginPath(),t.arc(g(v),f(i),(B?4.5:3)+(T?1.5:0),0,Math.PI*2),t.fillStyle=B?l.alert:ee(F),t.fill(),T&&(t.lineWidth=1.5,t.strokeStyle=l.text,t.stroke()),B&&(t.fillStyle=l.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(B.join(","),g(v),f(i)-(T?8:6))),t.globalAlpha=1,le.push({p:{x:e.xs[v],y:i,group:F,item:e.items[v]},cx:g(v),cy:f(i)})});const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Tn(e){const l=s,a=l.marks,h=a.items.indexOf(e.item),r=(e.y-a.limits.centre)/a.limits.sigma,d=a.violations.find(n=>n.index===h)?.rules;return`<strong>${X(m.waferLabel(e.item))}</strong><br>`+X(`${l.y.label}: ${J(e.y,l.y.unit)} (${r>=0?"+":"\u2212"}${Math.abs(r).toFixed(1)}\u03C3)`)+(d?`<br>${X(`breaks rule ${d.map(n=>`${n} (${On[n]})`).join(", ")}`)}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function wn(){const e=s?.marks;if(!s||!$||!s.x||!s.y||e?.type!=="goal")return;Ge($,te??0);const l=je(W),{w:a,h,plotW:r,plotH:d}=Ne(),n=Xe($,W,a,h);if(!n)return;const{ctx:t}=n,o=Math.max(.5,...e.points.map(i=>Math.abs(i.x))),c=ue([-o,o],{...s.x,min:s.x.min??-o*1.05,max:s.x.max??o*1.05}),y=ue([0,...e.points.map(i=>i.y),1/6],{...s.y,min:s.y.min??0},{floorAtZero:!0});Z={x:c,y,plotW:r,plotH:d},Ke(t,l,a,h,r,d,c,y,s.x,s.y);const x=i=>w+c.frac(i)*r,g=i=>M+(1-y.frac(i))*d;t.save(),t.beginPath(),t.rect(w,M,r,d),t.clip(),t.font=`${Q(-1)}px system-ui, sans-serif`;const f=[[1,[6,4]],[1.33,[]]];for(const[i,v]of f){const B=1/(6*i);t.strokeStyle=l.textMuted,t.lineWidth=1,t.setLineDash(v),t.beginPath(),t.moveTo(x(-.5),g(0)),t.lineTo(x(0),g(B)),t.lineTo(x(.5),g(0)),t.stroke(),t.fillStyle=l.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${i}`,x(0)+4,g(B)-2)}t.restore(),le=[];const p=e.points.filter(i=>O.size===0||O.has(i.group));for(const i of p)t.beginPath(),t.arc(x(i.x),g(i.y),4,0,Math.PI*2),t.fillStyle=ee(i.group),t.fill(),le.push({p:{x:i.x,y:i.y,group:i.group,item:-1,value:i.testNumber},cx:x(i.x),cy:g(i.y)});const L=p.map(i=>({x0:x(i.x)-5,x1:x(i.x)+5,y0:g(i.y)-5,y1:g(i.y)+5})),P={x0:w,x1:w+r,y0:M,y1:M+d},b=i=>i.x0>=P.x0&&i.x1<=P.x1&&i.y0>=P.y0&&i.y1<=P.y1&&!L.some(v=>i.x0<v.x1&&i.x1>v.x0&&i.y0<v.y1&&i.y1>v.y0),C=Q(-1)+2;t.fillStyle=l.text,t.textBaseline="middle";for(const i of[...p].filter(v=>v.ppk<1.33).sort((v,B)=>v.ppk-B.ppk)){const v=x(i.x),B=g(i.y),F=t.measureText(i.label).width,T=[[v+7,B,"left"],[v-7,B,"right"],[v,B-13,"center"],[v,B+13,"center"]];for(const[A,E,j]of T){const k=j==="left"?A:j==="right"?A-F:A-F/2,ie={x0:k,x1:k+F,y0:E-C/2,y1:E+C/2};if(b(ie)){L.push(ie),t.textAlign=j,t.fillText(i.label,A,E);break}}}const u=ge?le.find(i=>i.p===ge):void 0;u&&(t.beginPath(),t.arc(u.cx,u.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=l.text,t.stroke())}function Sn(e){const l=s,h=l.marks.points.find(r=>r.testNumber===e.value&&r.group===e.group);return h?`<strong>${X(h.label)}</strong>${l.groups.length>1?` \xB7 ${X(He(h.group))}`:""}<br>`+X(`Ppk ${h.ppk.toFixed(2)} \xB7 ${h.n.toLocaleString("en-GB")} dies`)+"<br>"+X(`mean ${h.x>=0?"+":"\u2212"}${Math.abs(h.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(h.y*100).toFixed(1)}% of it (${h.basis==="spec"?"spec":"test"} limits)`):""}function Pn(e,l,a,h,r){!$e||!$||($e.style.display=e?"block":"none",e&&(Object.assign($e.style,{top:`${$.offsetTop+M}px`,height:`${r}px`,left:`${$.offsetLeft+w+h+1}px`}),$e.firstElementChild.style.height=`${l}px`,Math.abs($e.scrollTop-a)>=1&&($e.scrollTop=a)))}function K(){$e&&($e.style.display="none"),dt&&!an()&&(dt.style.maxHeight=Qt(W)?"":`${ro}px`),pe&&m.panel&&(pe.style.display=Qt(W)?"flex":"none"),w=Wt,M=Rt;const e=s?.marks?.type;e==="scatter"?fn():e==="control"?Mn():e==="heatmap"?vn():e==="goal"?wn():e==="probability"?bn():e==="histogram"?hn():e==="box"||e==="bar"?dn():e==="line"&&yn(),Nt()}function $n(e){const l=s,a=m.waferLabel(e.item),h=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",r=[a,h].filter(Boolean).join(" \xB7 "),d=(n,t)=>`${n.label}: ${J(t,n.unit)}`;return(r?`<strong>${X(r)}</strong><br>`:"")+X(d(l.x,e.x))+"<br>"+X(d(l.y,e.y))+(l.colorScale&&e.value!==void 0?`<br>${X(`${l.colorScale.label}: ${J(e.value,l.colorScale.unit)}`)}`:"")+(l.groups.length>1?`<br>${X(He(e.group))}`:"")+(m.onOpenWafer?`<br><em>click to ${X(m.openActionLabel??"open this wafer")}</em>`:"")}function _t(e){if(!Ee||!Z||!s?.x)return null;const l=$.getBoundingClientRect(),h=(e.clientX-l.left-w)/Z.plotW;if(h<0||h>1)return null;const r=Z.x.reverse?1-h:h,{edges:d,counts:n}=Ee,t=d.length-1,o=Math.min(t-1,Math.max(0,Math.floor(r*t)));ye=o;const c=s.x,y=n.map((x,g)=>({g,n:x[o]})).filter(x=>x.n>0&&(O.size===0||O.has(x.g)));return`<strong>${X(`${J(d[o],c.unit)} to ${J(d[o+1],c.unit)}`)}</strong><br>`+(y.length?y.map(x=>{const g=s.spec.histNorm==="percent"?` (${Ee.heights[x.g][o].toFixed(1)}% of ${s.groups.length>1?"its colour":"them"})`:"";return X(`${s.groups.length>1?`${He(x.g)}: `:""}${x.n.toLocaleString("en-GB")} ${s.level==="die"?"dies":"wafers"}${g}`)}).join("<br>"):"none")}function Ln(e){const l=z.createElement("div");l.dataset.wmapPlotColorbar="1",Object.assign(l.style,{display:"flex",alignItems:"center",gap:me.md,marginTop:me.md,marginBottom:me.xl,fontSize:gt.body,color:nt.label});const a=z.createElement("canvas");a.width=200,a.height=10,Object.assign(a.style,{width:"200px",height:"10px",borderRadius:Fn.control,flex:"0 0 auto"});const h=a.getContext("2d"),r=bt(s?.spec.colorGradient,s?.spec.colorReverse,e.diverging,e.rating);if(h)for(let c=0;c<200;c++)h.fillStyle=r(c/199),h.fillRect(c,0,1,10);const d=c=>s?.marks?.type==="heatmap"?Ot(c,e.unit,e.integer):J(c,e.unit),n=z.createElement("span");n.textContent=d(e.lo);const t=z.createElement("span");t.textContent=d(e.hi);const o=z.createElement("span");return o.textContent=e.label,o.style.color=nt.text,l.append(o,n,a,t),l}const st=(e,l,a)=>l.map(h=>{const{item:r,die:d}=e(h);return{x:0,y:0,group:a,item:r,die:d}});function An(){Ze?.destroy(),Ze=void 0,R.innerHTML="",$=void 0,pe=void 0,te=void 0,ot=[],ge=null,ye=-1,le=[],Z=void 0,ne=void 0,se=null,$e=void 0,lt=0,dt=void 0,_e=void 0,xe=null,de=[],be=-1,qe=Ue,kt=new Map,O.clear(),he.clear();for(const n of ce)n.destroy();ce=[],ut?.(),ut=void 0,R.style.overflowY="hidden",delete W.dataset.wmapPlotPanelsOwner,delete W.dataset.wmapPanelsHover,we(()=>W.querySelector("canvas"));const e=s,l=!!e?.facets&&!m.panel;if(W.style.flex=l?"0 0 auto":"1 1 0px",W.style.gridColumn=l?"1 / -1":"",!e)return;if(U.textContent=m.panel?m.panel.title:Nn(e),W.dataset.wmapChartTitle=U.textContent,e.issues.length||!e.marks){for(const n of e.issues)Jt(R,n);return}const a=z.createElement("div");Object.assign(a.style,{color:nt.label,fontSize:gt.body,marginBottom:me.xs});const h=m.openActionLabel??"open this wafer",r=e.marks.type==="scatter"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="box"||e.marks.type==="bar"?(m.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${h}`:m.onSelectPoints?` \xB7 click or right-click to ${m.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&m.onSelectPoints?" \xB7 click or right-click a bar to chart or tabulate its dies":e.marks.type==="heatmap"&&m.onSelectPoints?` \xB7 click or right-click a cell to chart or tabulate its ${e.level==="die"?"dies":"wafers"}`:e.marks.type==="probability"?(m.onOpenWafer?` \xB7 click a point to ${h}`:"")+(m.onSelectPoints?` \xB7 drag to select ${e.level==="die"?"dies":"wafers"}`:""):e.marks.type==="line"&&m.onSelectPoints?` \xB7 click a point to ${m.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the plot to select ${m.selectRangeLabel??"a run of points"}`:"";a.textContent=m.panel?`${e.population.wafers.toLocaleString("en-GB")} wafer${e.population.wafers===1?"":"s"} \xB7 ${e.population.dies.toLocaleString("en-GB")} dies`:Ht(e)+(e.facets?"":r),m.panel||Xn(a,Kt(e)),Vt(a),te=z.createElement("div"),te.style.display="flow-root",R.appendChild(te),te.appendChild(a);for(const n of e.fitNotes??[]){const t=z.createElement("div");t.dataset.wmapPlotFit="1",t.textContent=n,Object.assign(t.style,{color:nt.text,fontSize:gt.body,marginBottom:me.xxs,fontVariantNumeric:"tabular-nums"}),te.appendChild(t)}for(const n of e.notes){const t=z.createElement("div");Vt(t),t.textContent=n,Object.assign(t.style,{color:nt.warnText,fontSize:gt.body,marginBottom:me.xs}),te.appendChild(t)}if(e.plotted===0){Jt(R,"Nothing to plot: no mark has every value this plot needs.");return}if(e.groups.length>1&&!e.colorRepeatsX&&(pe=z.createElement("div"),pe.dataset.wmapPlotLegend="1",Object.assign(pe.style,{display:m.panel?"none":"flex",flexWrap:"wrap",gap:me.sm,marginTop:me.md,marginBottom:me.xl,overflowY:"auto"}),dt=pe,e.facets&&Object.assign(pe.style,{position:"sticky",top:"0",zIndex:"2",background:nt.menuBg,paddingBottom:me.sm,marginBottom:me.md}),e.groups.forEach((n,t)=>{const o=Vn(n||"(none)",ee(t),z);Yn(o.el,W,_,`${n||"(none)"} \u2014 click to filter`),o.el.addEventListener("click",()=>{if(O.has(t)?O.delete(t):O.add(t),ot.forEach((c,y)=>c.setState({selected:O.has(y),dimmed:O.size>0&&!O.has(y)})),ce.length)for(const c of ce)c.setActiveGroups(O);else K()}),ot.push(o),pe.appendChild(o.el)}),ot.forEach((n,t)=>n.setState({selected:O.has(t),dimmed:O.size>0&&!O.has(t)})),te.appendChild(pe)),e.colorScale&&!m.panel&&(pe=Ln(e.colorScale),te.appendChild(pe)),e.facets){const n=z.createElement("div");n.dataset.wmapPlotPanels="1",n.style.isolation="isolate",Object.assign(n.style,{display:"grid",gap:me.md});const t=()=>{n.style.gridTemplateColumns=Ie?`repeat(${Ie}, minmax(0, 1fr))`:`repeat(auto-fill, minmax(${ho}px, 1fr))`};t();const o=Zn("Columns:",[{value:"auto",label:"Auto (0)"},...[1,2,3,4,5].map(x=>({value:String(x),label:`${x} (${x})`}))],Ie?String(Ie):"auto",x=>{Ie=x==="auto"?void 0:Number(x),t()},{hook:"panel-columns",maxWidth:"90px",ownerDocument:z});Object.assign(o.style,{justifyContent:"flex-end",marginBottom:me.sm});const c=o.querySelector("button");R.append(o,n),R.style.overflowY="auto",W.dataset.wmapPlotPanelsOwner="1",ht&&(W.dataset.wmapPanelsHover="1");const y=x=>{if(!ht||x.ctrlKey||x.metaKey||x.altKey||x.shiftKey||x.defaultPrevented||!/^[0-5]$/.test(x.key))return;const g=x.target;typeof g?.closest=="function"&&g.closest('input, textarea, select, [contenteditable="true"], [role="menu"]')||(x.preventDefault(),Ie=x.key==="0"?void 0:Number(x.key),t(),c&&(c.value=Ie?String(Ie):"auto"))};z.addEventListener("keydown",y),ut=()=>z.removeEventListener("keydown",y);for(const x of e.facets){const g=renderPlotChart({...m,panel:{title:x.label}});n.appendChild(g.card),g.setPlot(x.plot),ce.push(g)}we(()=>mo(n));return}$=z.createElement("canvas"),$.style.display="block",$.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",R.appendChild($);const d=m.onWaferMenu||m.onSelectPoints?(n,t)=>{!n.die&&m.onWaferMenu?m.onWaferMenu(n.item,Ve(e.spec),t):n.die&&m.onSelectPoints&&(t.preventDefault(),m.onSelectPoints([n],{x:t.clientX,y:t.clientY},$))}:void 0;if(e.marks.type==="scatter"){const n=e.marks,t=!!m.onSelectPoints;Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:$n,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:t?{pick:({x0:o,y0:c,x1:y,y1:x})=>Z?(O.size===0?n.points:n.points.filter(f=>O.has(f.group))).filter(f=>{const p=w+Z.x.frac(f.x)*Z.plotW,L=M+(1-Z.y.frac(f.y))*Z.plotH;return p>=o&&p<=y&&L>=c&&L<=x}):[],onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const n=e.marks.type==="control";Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:n?Tn:Sn,clickable:()=>n&&!!m.onOpenWafer,onOpen:t=>{n&&m.onOpenWafer?.(t.item,Ve(e.spec))},onContextMenu:n?d:void 0,onHover:t=>{ge=t,K()}})}else if(e.marks.type==="probability"){const n=e.marks,t=e.spec.probabilityAxis==="linear";Ze=Bt({card:W,canvas:$,tooltip:_,drawn:()=>le,describe:xn,clickable:()=>!!m.onOpenWafer,onOpen:o=>m.onOpenWafer?.(o.item,Ve(e.spec)),onContextMenu:d,onHover:o=>{ge=o,K()},select:m.onSelectPoints?{pick:({x0:o,y0:c,x1:y,y1:x})=>{if(!Z)return[];const g=[];return n.values.forEach((f,p)=>{O.size>0&&!O.has(p)||f.forEach((L,P)=>{const b=ct(P,f.length),C=w+Z.x.frac(L)*Z.plotW,u=M+(1-Z.y.frac(t?b:Yt(b)))*Z.plotH;if(C<o||C>y||u<c||u>x)return;const{item:i,die:v}=n.unit(n.units[p][P]);g.push({x:L,y:b,group:p,item:i,die:v})})}),g},onPicked:(o,c)=>{he.clear();for(const y of o)he.add(y);K(),o.length>0&&m.onSelectPoints(o,c,$)},onClear:()=>{he.clear(),K()},hasSelection:()=>he.size>0}:void 0})}else if(e.marks.type==="histogram"){un(),$.addEventListener("mousemove",t=>{const o=_t(t);if(!o){_.style.display="none",ye>=0&&(ye=-1,K());return}_.innerHTML=o,_.style.display="block",yt(_,W,t.clientX,t.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",ye>=0&&(ye=-1,K())});const n=e.marks;if(m.onSelectPoints){$.style.cursor="pointer";const t=o=>{if(!Ee||_t(o)===null)return!1;const c=ye,{edges:y}=Ee,x=Z?.x.log,g=x?Math.log10(y[0]):y[0],f=x?Math.log10(y[y.length-1]):y[y.length-1],p=y.length-1,L=[];return n.values.forEach((P,b)=>{if(O.size>0&&!O.has(b))return;const C=[];P.forEach((u,i)=>{const v=x?u>0?Math.log10(u):NaN:u;!Number.isFinite(v)||v<g||v>f||Math.min(p-1,Math.floor((v-g)/(f-g)*p))===c&&C.push(n.units[b][i])});for(const u of st(n.unit,C,b))L.push(u)}),L.length===0?!1:(_.style.display="none",m.onSelectPoints(L,{x:o.clientX,y:o.clientY},$,{range:{lo:y[c],hi:y[c+1]},...O.size===1?{group:e.groups[[...O][0]]}:{}}),!0)};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}}else if(e.marks.type==="heatmap"){const n=e.marks;$.addEventListener("mousemove",o=>{const c=zt(o);if($.style.cursor=c&&m.onSelectPoints&&n.cellUnits[c.r][c.c].length?"pointer":"default",!c){_.style.display="none",xe&&(xe=null,K());return}_.innerHTML=kn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!xe||xe.r!==c.r||xe.c!==c.c)&&(xe=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",xe&&(xe=null,K())});const t=o=>{const c=zt(o);if(!c||!m.onSelectPoints)return!1;const y=n.cellUnits[c.r][c.c];return y.length?(_.style.display="none",m.onSelectPoints(st(n.unit,y,0),{x:o.clientX,y:o.clientY},$,{cell:{row:n.rows[c.r],column:n.cols[c.c]}}),!0):!1};$.addEventListener("click",o=>{t(o)}),$.addEventListener("contextmenu",o=>{t(o)&&o.preventDefault()})}else if(e.marks.type==="box"||e.marks.type==="bar"){const n=e.marks;if(e.spec.orientation==="horizontal"){const o=z.createElement("div");o.dataset.wmapRowScroll="1",o.tabIndex=0,o.setAttribute("aria-label",`Scroll the ${n.categories.length} rows`),Object.assign(o.style,{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"});const c=z.createElement("div");c.style.width="1px",o.appendChild(c),o.addEventListener("scroll",()=>{Math.abs(o.scrollTop-lt)<1||(lt=o.scrollTop,_.style.display="none",K())}),$.addEventListener("wheel",y=>{if(o.style.display==="none")return;const x=o.scrollTop;o.scrollTop+=y.deltaMode===1?y.deltaY*16:y.deltaY,o.scrollTop!==x&&y.preventDefault()},{passive:!1}),R.appendChild(o),$e=o}$.addEventListener("mousemove",o=>{const c=Pt(o);if($.style.cursor=c&&(n.categoryItems&&m.onOpenWafer||m.onSelectPoints&&n.cellUnits[c.g][c.c].length>0)?"pointer":"default",!c){_.style.display="none",se&&(se=null,K());return}_.innerHTML=gn(c),_.style.display="block",yt(_,W,o.clientX,o.clientY),(!se||se.g!==c.g||se.c!==c.c)&&(se=c,K())}),$.addEventListener("mouseleave",()=>{_.style.display="none",se&&(se=null,K())});const t=(o,c)=>{const y=n.cellUnits[c.g][c.c];return y.length===0||!m.onSelectPoints?!1:(_.style.display="none",m.onSelectPoints(st(n.unit,y,c.g),{x:o.clientX,y:o.clientY},$,{category:n.categories[c.c],...e.groups.length>1?{group:e.groups[c.g]}:{},...mn(n.categories[c.c])}),!0)};$.addEventListener("contextmenu",o=>{const c=Pt(o);if(!c)return;const y=n.categoryItems?.[c.c];y!==void 0&&y>=0&&m.onWaferMenu?(_.style.display="none",m.onWaferMenu(y,Ve(e.spec),o)):t(o,c)&&o.preventDefault()}),$.addEventListener("click",o=>{const c=Pt(o);if(!c)return;const y=n.categoryItems?.[c.c];if(y!==void 0&&y>=0&&m.onOpenWafer){m.onOpenWafer(y,Ve(e.spec));return}t(o,c)})}else if(e.marks.type==="line"){$.addEventListener("mousemove",o=>{const c=$t(o);if(!c){_.style.display="none",K();return}_.innerHTML=c,_.style.display="block",yt(_,W,o.clientX,o.clientY),K()}),$.addEventListener("mouseleave",()=>{_.style.display="none",be>=0&&(be=-1,K())});const n=e.marks,t=()=>n.cellUnits.flatMap((o,c)=>O.size>0&&!O.has(c)?[]:st(n.unit,o[be]??[],c));if((m.onWaferMenu||m.onSelectPoints)&&$.addEventListener("contextmenu",o=>{if($t(o)===null||be<0)return;const c=Ft(be);if(c!==void 0&&m.onWaferMenu)_.style.display="none",m.onWaferMenu(c,Ve(e.spec),o);else if(m.onSelectPoints){const y=t();y.length>0&&(o.preventDefault(),_.style.display="none",m.onSelectPoints(y,{x:o.clientX,y:o.clientY},$))}}),m.onSelectPoints){$.style.cursor="pointer";let o=!1;$.addEventListener("mousedown",c=>{if(c.button!==0)return;o=!1;const y=$.getBoundingClientRect(),x=c.clientX-y.left,g=f=>{z.removeEventListener("mouseup",g);const p=f.clientX-y.left;if(Math.abs(p-x)<4)return;o=!0;const[L,P]=x<p?[x,p]:[p,x],b=de.map((u,i)=>u>=L&&u<=P?i:-1).filter(u=>u>=0),C=n.cellUnits.flatMap((u,i)=>O.size>0&&!O.has(i)?[]:b.flatMap(v=>st(n.unit,u[v]??[],i)));C.length>0&&(_.style.display="none",m.onSelectPoints(C,{x:f.clientX,y:f.clientY},$))};z.addEventListener("mouseup",g)}),$.addEventListener("click",c=>{if(o){o=!1;return}if($t(c)===null||be<0)return;const y=t();y.length>0&&(_.style.display="none",m.onSelectPoints(y,{x:c.clientX,y:c.clientY},$))})}}K()}V(()=>{const e=s;if(!e||!e.marks)return;const l=bt(e.spec.colorGradient,e.spec.colorReverse,e.colorScale?.diverging,e.colorScale?.rating);return{caption:[Ht(e),...e.fitNotes??[],...e.notes,...oo(Kt(e))],legend:e.groups.length>1&&!e.colorRepeatsX?e.groups.map((a,h)=>({label:a||"(none)",color:ee(h)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,lo:J(e.colorScale.lo,e.colorScale.unit),hi:J(e.colorScale.hi,e.colorScale.unit),color:l}:void 0}});const Cn=jn(W,()=>K());return{card:W,actions:Y,setPlot(e){s=e,Me(io(e.spec)),An()},setMenuRows(e){Oe=e},setActiveGroups(e){O.clear();for(const l of e)O.add(l);ot.forEach((l,a)=>l.setState({selected:O.has(a),dimmed:O.size>0&&!O.has(a)})),K()},destroy(){ut?.(),Cn.disconnect(),Ze?.destroy();for(const e of ce)e.destroy()}}}
|
|
1
|
+
import{escHtml as G,maxOf as pe,minOf as _t}from"../../core/utils.js";import{fiveNumberSummary as Nn,normalQuantile as Rn,sampleVariance as jo}from"../../stats/math.js";import{CONTROL_RULE_TEXT as Yo}from"../../stats/control.js";import{PAT_VERDICT_LABEL as In}from"../../stats/pat.js";import{fmt as Ce,fmtPlainNumber as an}from"../../renderer/fmt.js";import{fitTicks as Dt}from"../../renderer/axisTicks.js";import{timeTicks as rn,formatDay as Go}from"../../renderer/timeAxis.js";import{WAFER_WORDS as cn,counted as fn,isWaferWords as Uo}from"../../stats/plotWords.js";import{PASS_FAIL_LABEL as Fn,axisValues as qo,binOfLabel as Wn,plotFootnote as zn,plotGuideSections as _n,plotOpensBins as Ko,plotTestNumber as Xt,plotTitle as Dn,probabilityPosition as $t}from"../../stats/plotData.js";import{SPACE as se,LEADING as jt,RADIUS as Xn,fontPx as ee,FONT as Ze,CLR as Qe,controlStyle as Ho,markNoPrint as Yt}from"../toolbar.js";import{exportCsv as Vo}from"../tableExport.js";import{tableToTsv as Zo}from"../../core/tableCsv.js";import{plotTable as Qo}from"../../stats/plotTable.js";import{cardShell as Jo,chartCanvasOf as es,appendGuideCites as ts,observeResize as ns,onRepaint as os,makeTooltip as ss,attachChartTip as jn,chartFillHeight as ls,applyCanvasFlow as Je,prepareCanvas as et,positionChartTooltip as Gt,resolveChartCanvasColors as ze,quietOf as un,makeAxisFormat as is,horizontalTickSpacing as Yn,VERTICAL_TICK_SPACING_PX as Gn,makeSeriesLegendItem as as,renderEmptyState as Un,isExpandedCard as qn,makeLabeledSelect as rs,fillTextOnHalo as dn,limitLines as cs,limitExtent as fs,stackLabelRows as Kn,placeClearOf as Hn,strokeLimitLine as Vn,drawOffAxisLimits as us,limitLabelPlacement as ds,shouldIncludeLimitsByDefault as hs,WAFER_MENU_HINT as hn}from"./chartShell.js";import{guideCitesText as ms}from"../../stats/guideSections.js";import{categorical as ps,quantityColor as Zn,QUANTITY_MIX as gs}from"./palette.js";import{passFailFillsFor as ys}from"../../renderer/dataColors.js";import{mixCssColors as bs}from"../../renderer/colorMap.js";import{NO_DATA_FILL as Qn}from"../../renderer/colorMap.js";import{darkTextOnColor as xs,plotGradient as Lt,ratingKeyTicks as Jn,scaleT as mn,shortfallBarColor as Ut}from"./divergingScale.js";import{shortfallStep as vs}from"../../stats/presentation.js";import{wirePointInteractions as pn}from"./pointInteractions.js";import{plotAbout as eo}from"./cardAbout.js";const at=64,mt=16,gn=12,tt=52,Ms=16,ks=8,ws=12,Ts=14,to=8e3,Ss=92,$s=16,qt=5e3,no=1500,Pt=100,Ls=[1e-4,.001,.01,.05,.1,.25,.5,.75,.9,.95,.99,.999,.9999],oo=h=>`${+(h*100).toPrecision(4)}%`;export function categoryLayout(h){const B=.8/Math.max(1,...h.map(I=>I.length)),q=I=>(1-h[I].length*B)/2;return{width:B,left:(I,V)=>{const J=h[I].indexOf(V);return J<0?void 0:q(I)+J*B},groupAt:(I,V)=>{const J=Math.floor((V-q(I))/B);return J>=0&&J<h[I].length?h[I][J]:void 0}}}function Ps(h){if(h<=no)return Array.from({length:h},(I,V)=>V);const N=[];for(let I=0;I<Pt;I++)N.push(I);const B=no-2*Pt,q=h-2*Pt;for(let I=0;I<B;I++)N.push(Pt+Math.floor(I*q/B));for(let I=h-Pt;I<h;I++)N.push(I);return N}const Kt=h=>[Xt(h),Ko(h)?"bins":void 0];function yn(h,N,B){return B?Math.round(h).toLocaleString("en-GB"):N?Ce(h,N):`${h<=-.005?"\u2212":""}${Math.abs(h).toFixed(2)}`}function so(h,N){if(h.limits)return{lo:"Low limit",mid:"Centre",hi:"High limit"};const B=q=>N?yn(q,h.unit,h.integer):Ce(q,h.unit);return{lo:B(h.lo),hi:B(h.hi)}}const Cs=260;function Es(h){const N=[...h.querySelectorAll("[data-wmap-plot-panel]")],B=N[0]?.querySelector("canvas");if(!B)return null;const q=B.width/Math.max(1,B.getBoundingClientRect().width)||1,I=h.getBoundingClientRect(),V=h.ownerDocument.createElement("canvas");V.width=Math.ceil(I.width*q),V.height=Math.ceil(I.height*q);const J=V.getContext("2d");if(!J)return null;const Ee=getComputedStyle(h);J.fillStyle=Ee.backgroundColor&&Ee.backgroundColor!=="rgba(0, 0, 0, 0)"?Ee.backgroundColor:"#fff",J.fillRect(0,0,V.width,V.height);for(const we of N){const Ae=we.querySelector("canvas"),Ne=we.dataset.wmapChartTitle??"",ae=(Ae??we).getBoundingClientRect(),j=we.getBoundingClientRect();J.fillStyle=getComputedStyle(we).color||"#333",J.font=`600 ${Math.round(13*q)}px system-ui, sans-serif`,J.textBaseline="top",J.fillText(Ne,(j.left-I.left+8)*q,(j.top-I.top+6)*q),Ae&&J.drawImage(Ae,(ae.left-I.left)*q,(ae.top-I.top)*q,ae.width*q,ae.height*q)}return V}const _e=(h,N)=>N.extent?[...h,...N.extent]:h;function be(h,N,B={}){const q=N.scale==="log";let I=h.length?_t(h):0,V=h.length?pe(h):1;q&&(I=Math.log10(Math.max(I,Number.MIN_VALUE)),V=Math.log10(Math.max(V,Number.MIN_VALUE)));const J=(V-I)*.05||(q?.5:1);I=B.floorAtZero&&!q&&I>=0?0:I-J,V+=J;const we=Le=>Le===void 0||!Number.isFinite(Le)?void 0:q?Le>0?Math.log10(Le):void 0:Le,Ae=we(N.min),Ne=we(N.max);Ae!==void 0&&(I=Ae),Ne!==void 0&&(V=Ne),V>I||(V=I+1);const ae=V-I,j=!!N.reverse,a=Le=>{const Ct=((q?Math.log10(Math.max(Le,Number.MIN_VALUE)):Le)-I)/ae;return j?1-Ct:Ct};return{lo:q?10**I:I,hi:q?10**V:V,log:q,reverse:j,frac:a}}function lo(h,N){return h.names?.[Math.round(N)-1]??nt(h,N)}function nt(h,N){return h.time?Go(N):h.plainNumbers?an(N):Ce(N,h.unit)}function bn(h,N,B,q){if(N/h<10)return Dt(h,N,B,q);const I=Math.floor(Math.log10(h)),V=Math.ceil(Math.log10(N)),J=Ae=>{const Ne=[];for(let ae=I;ae<=V;ae++)for(const j of Ae){const a=j*10**ae;a>=h&&a<=N&&Ne.push(a)}return Ne},Ee=J([1]);return{ticks:Ee.length>=4?Ee:J([1,2,5]),step:0}}export function renderPlotChart(h){const N=h.ownerDocument??document,{card:B,heading:q,body:I,controlsRow:V,setPngDecor:J,setPngCanvas:Ee,setAbout:we,setCardId:Ae,setMenuRows:Ne}=Jo(h.panel?.title??"Chart",h.onSaveImage,N,{png:!h.panel,chrome:h.chrome});h.chrome&&(V.style.display="none"),h.panel&&(B.dataset.wmapPlotPanel="1");let ae=[];B.dataset.wmapPlotCard="1";const j=ss(B);let a,Le=()=>[];const Ct=()=>{const e=a&&(a.marks||a.facets?.length)?Qo(a,h.waferLabel):void 0;return e?[{label:"Save data as CSV",onClick:()=>{Vo(e.columns,e.rows,`${e.name}.csv`,h.onSaveText)}},{label:"Copy data",onClick:()=>{N.defaultView?.navigator.clipboard?.writeText(Zo(e.columns,e.rows))}}]:[]};Ne(()=>[...Ct(),...Le()]);let E,le,ie,rt,De,Et,At=!1;B.addEventListener("pointerenter",()=>{At=!0,B.dataset.wmapPlotPanelsOwner&&(B.dataset.wmapPanelsHover="1")}),B.addEventListener("pointerleave",()=>{At=!1,delete B.dataset.wmapPanelsHover});let pt=[];const W=new Set,xe=new Set;let ve=null,Te=-1,fe=[],X,te={};const Ht={};let gt;const yt=(e,n)=>te[e]?{...n,min:te[e][0],max:te[e][1]}:n;let Re,re,ue=null,ot=0,Bt=!1,de,Ot;const io=()=>!!a?.facets;let Me=[],ke=-1,Vt=new Map,Xe=[],je=tt,P=at,w=gn;const ao=e=>{const n=h.readerColors?.dataColors,l=a?.spec.fields?.color;if(l&&"builtin"in l&&l.builtin==="passFail"){const u=ys(n);return e===Fn.pass?u.pass:e===Fn.fail?u.failHigh:void 0}return e===In.outlier?Ut(1,void 0,n):e===In.fails?Ut(3,void 0,n):void 0},Pe=()=>a?.words??cn,bt=e=>e==="die"?(Pe().item??cn.item).many:Pe().row.many,xt=(e,n)=>fn(e,n==="die"?Pe().item??cn.item:Pe().row),vt=()=>h.openActionLabel??`open this ${Pe().row.one}`;let xn;const oe=e=>{const n=a?.groups[e]??"";if(a?.colorBins&&h.binColors){const u=Wn(n,Pe());return u===void 0?Qn:(a.colorBins==="hard"?h.binColors.hard:h.binColors.soft).get(u)??Qn}return a&&a.groups.length<=1&&!a.colorLabel&&!a.colorBins?xn??=bs(ze(B).bg,Zn(h.readerColors?.dataColors),gs/100)??Zn(h.readerColors?.dataColors):ao(n)??a?.groupColorOwn?.[e]??ps(a?.groupColorIndex?.[e]??e,h.readerColors?.dataColors)},st=e=>a?.groups[e]||"",ro=e=>{const n=a;if(!n||n.marks?.type!=="bar"||"stack"in n.marks&&n.marks.stack)return;const l={card:e.bg,text:e.text};if(n.shortfallFrom!==void 0){const c=n.shortfallFrom;return s=>{const t=vs(s-c);return t?Ut(t,l,h.readerColors?.dataColors):void 0}}const u=n.colorScale;if(n.spec.colorBars!=="value"||!u)return;const o=Lt(n.spec.colorGradient,n.spec.colorReverse,u.diverging,u.rating,l,u.counts,h.readerColors);return c=>o(mn(u,c))};function Ye(){const e=I.clientWidth,n=(h.panel?Math.max(170,Math.min(280,e*.72)):Math.max(220,Math.min(420,e*.62)))+(je-tt),l=ls(B,I,E,n);return{w:e,h:l,plotW:Math.max(10,e-P-mt),plotH:Math.max(10,l-w-je)}}const Ie=e=>{const n=(e?.references??[]).flatMap(l=>l.to===void 0?[{value:l.at,kind:"ref",end:"lo",label:l.label??""}]:[{value:l.at,kind:"ref",end:"lo",label:l.label??"",bandTo:l.to},{value:l.to,kind:"ref",end:"hi",label:l.label??""}]);return[...cs(e?.limits,a?.spec.limits??"both"),...n].filter(l=>e?.scale!=="log"||l.value>0)},Ge=(e,n,l)=>{const u=l?.clip,o=u?[...e.filter(m=>m>=u.lo&&m<=u.hi),u.lo,u.hi]:e,c=o.filter(Number.isFinite);if(!n.length||c.length===0)return o;const{lo:s,hi:t}=fs(n);return(l?a?.spec.axes?.[l===a?.x?"x":"y"]?.includeLimits:void 0)??hs(_t(c),pe(c),s,t)?[...o,...n.map(m=>m.value)]:o};let Zt;function ct(e,n,l,u=!1){return!u&&!a?.x?.clip&&!a?.y?.clip&&!te.x&&!te.y?()=>{}:(e.save(),e.beginPath(),e.rect(P,w,n,l),e.clip(),Zt=e,vn)}function vn(){Zt?.restore(),Zt=void 0}function Ue(e,n,l,u,o,c,s,t,x){const m=[];if(c.length===0)return()=>{};const p=c.filter(d=>d.value>=o.lo&&d.value<=o.hi),r=c.filter(d=>!p.includes(d)).map(d=>({value:d.value,label:d.label,side:d.value<o.lo?"lo":"hi"}));e.save(),e.font=`${ee(-1)}px system-ui, sans-serif`;const i=d=>`${d.label} ${Ce(d.value,s.unit)}`.trim(),f=ee(-1)+2;for(const d of c){if(d.bandTo===void 0)continue;const k=o.frac(Math.min(d.value,d.bandTo)),M=o.frac(Math.max(d.value,d.bandTo)),S=Math.max(0,Math.min(k,M)),b=Math.min(1,Math.max(k,M));b<=S||(e.save(),e.globalAlpha=.1,e.fillStyle=n,t==="y"?e.fillRect(P,w+(1-b)*u,l,(b-S)*u):e.fillRect(P+S*l,w,(b-S)*l,u),e.restore())}if(t==="y"){const d=p.map(S=>{const b=w+(1-o.frac(S.value))*u;return{l:S,y:b,start:b-6-f/2,end:b-6+f/2}}),k=Kn(d,1),M=d.length?pe(d.map(S=>e.measureText(i(S.l)).width))+8:0;d.forEach(({l:S,y:b},T)=>{e.globalAlpha=.7,Vn(e,S,n,P,b,P+l,b),e.globalAlpha=1,e.fillStyle=n,e.textAlign="left",e.textBaseline="alphabetic";const y=P+3+k[T]*M,g=Hn(Xe,{x0:y,x1:y+e.measureText(i(S)).width,y0:b-4-f+2,y1:b-4+2},f);if(!x){e.fillText(i(S),y,g.y1-2);return}m.push(()=>{e.save(),e.font=`${ee(-1)}px system-ui, sans-serif`,e.fillStyle=n,e.textAlign="left",e.textBaseline="alphabetic",dn(e,i(S),y,g.y1-2,x.halo),e.restore()})})}else{const d=p.map(M=>{const S=P+o.frac(M.value)*l,b=i(M),T=M.label.split(/\s+/)[0],y=Ce(M.value,s.unit),g=T&&T!==M.label?[b,`${T} ${y}`,T]:[b],v=p.filter(A=>A!==M).map(A=>P+o.frac(A.value)*l),{text:R,side:L}=ds(S,g,A=>e.measureText(A).width,P,P+l,M.end==="lo",v),O=e.measureText(R).width;return{l:M,x:S,side:L,shown:R,start:L<0?S-3-O:S+3,end:L<0?S-3:S+3+O}}),k=Kn(d,4);d.forEach(({l:M,x:S,side:b,shown:T,start:y,end:g},v)=>{e.globalAlpha=.7,Vn(e,M,n,S,w,S,w+u),e.globalAlpha=1;const R=b<0?"right":"left";e.fillStyle=n,e.textAlign=R,e.textBaseline="top";const L=w+2+k[v]*f,O=Hn(Xe,{x0:y,x1:g,y0:L,y1:L+f},f);if(!x){e.fillText(T,S+b*3,O.y0);return}m.push(()=>{e.save(),e.font=`${ee(-1)}px system-ui, sans-serif`,e.fillStyle=n,e.textAlign=R,e.textBaseline="top",dn(e,T,S+b*3,O.y0,x.halo),e.restore()})})}return e.restore(),us(e,r,{left:P,right:P+l,top:w,bottom:w+u},t==="y"?"vertical":"horizontal",n,d=>Ce(d,s.unit),void 0,Xe),()=>m.forEach(d=>d())}const Mn=e=>e.measureText("00 Mmm 0000").width+14;function Nt(e,n,l,u){if(e.plainNumbers){const o=c=>an(c,u);return{tick:o,tickWithUnit:o,unitLabel:""}}return is(Math.max(Math.abs(n),Math.abs(l)),e.unit,u,e.label)}function Rt(e,n){return n?`${e.label} (${n})`:e.label}const Qt=18,Jt=(e,n,l)=>{if(e.measureText(n).width<=l)return n;for(let u=n.length-1;u>0;u--){const o=`${n.slice(0,u)}\u2026`;if(e.measureText(o).width<=l)return o}return""};function lt(e,n,l,u,o,c,s,t,x,m,p){Xe=[],e.font=`${ee(-1)}px system-ui, sans-serif`;const r=()=>Gn,i=!p&&m.time?rn(t.lo,t.hi,c,Gn):void 0,f=p||i?void 0:t.log?bn(t.lo,t.hi,c,r):Dt(t.lo,t.hi,c,r),d=m.whole&&f&&f.step>0&&f.step<1?{ticks:Array.from({length:Math.max(0,Math.floor(t.hi)-Math.ceil(t.lo)+1)},(y,g)=>Math.ceil(t.lo)+g),step:1}:void 0,k=p?{ticks:p.map(y=>y.at),step:0}:i?{ticks:i.ticks,step:0}:d??f,M=new Map(p?.map(y=>[y.at,y.label])),S=i?{tick:i.label,unitLabel:""}:Nt(m,t.lo,t.hi,k.step||void 0),b=p?{tick:y=>M.get(y)??"",unitLabel:""}:S;e.strokeStyle=n.grid,e.lineWidth=.5,e.fillStyle=n.textMuted;let T="";if("labels"in s){const y=s.labels.length,g=s.along!==void 0&&s.along>o+.5,v=(g?s.along:o)/y,R=g?s.offset??0:0;if(g&&(e.save(),e.beginPath(),e.rect(P,w+c,o+2,u-w-c),e.clip()),s.labels.forEach((L,O)=>{const A=P+(O+.5)*v-R;if(g&&(A<P-v||A>P+o+v))return;const F=L.length>22?`${L.slice(0,21)}\u2026`:L;s.rotate?(e.save(),e.translate(A,w+c+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.fillText(F,0,0),e.restore()):(e.textAlign="center",e.textBaseline="top",e.fillText(F,A,w+c+4))}),g&&e.restore(),s.nest){const L=s.nest[0]?.length??0,O=v;for(let A=L-2;A>=0;A--){const F=u-6-Qt-A*Qt,D=ne=>s.nest[ne].slice(0,A+1).join("");let Q=0;for(let ne=1;ne<=y;ne++){if(ne<y&&D(ne)===D(Q))continue;const $=P+Q*O-R,he=P+ne*O-R,Ke=Math.max($,P),it=Math.min(he,P+o);if(it<=Ke){Q=ne;continue}e.fillStyle=n.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Jt(e,s.nest[Q][A],it-Ke-4),(Ke+it)/2,F),ne<y&&he>=P&&he<=P+o&&(e.save(),e.strokeStyle=n.border,e.globalAlpha=A===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(he,w),e.lineTo(he,F-2),e.stroke(),e.restore()),Q=ne}}e.fillStyle=n.textMuted}}else if(x.names?.length){const y=x.names,g=pe(y.map(A=>e.measureText(A).width))+10,v=Math.max(1,Math.ceil(s.lo)),R=Math.min(y.length,Math.floor(s.hi)),L=o/Math.max(1,s.hi-s.lo),O=Math.max(1,Math.ceil(g/Math.max(L,1e-9)));for(let A=v;A<=R;A+=O){const F=P+s.frac(A)*o;e.beginPath(),e.moveTo(F,w),e.lineTo(F,w+c),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y[A-1]??"",F,w+c+4)}}else if(x.time){const y=rn(s.lo,s.hi,o,Mn(e));for(const g of y.ticks){const v=P+s.frac(g)*o;e.beginPath(),e.moveTo(v,w),e.lineTo(v,w+c),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(y.label(g),v,w+c+4)}}else{const y=Yn(e,Math.max(Math.abs(s.lo),Math.abs(s.hi)),x.unit),g=s.log?bn(s.lo,s.hi,o,y):Dt(s.lo,s.hi,o,y),v=Nt(x,s.lo,s.hi,g.step||void 0);T=v.unitLabel;for(const R of g.ticks){const L=P+s.frac(R)*o;e.beginPath(),e.moveTo(L,w),e.lineTo(L,w+c),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(v.tick(R),L,w+c+4)}}for(const y of k.ticks){const g=w+(1-t.frac(y))*c;e.beginPath(),e.moveTo(P,g),e.lineTo(P+o,g),e.stroke(),e.textAlign="right",e.textBaseline="middle",e.fillText(b.tick(y),P-4,g)}e.font=`${ee(0)}px system-ui, sans-serif`,e.fillStyle=n.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Rt(x,T),P+o/2,u-6),e.save(),e.translate(14,w+c/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Rt(m,b.unitLabel),0,0),e.restore(),e.strokeStyle=n.border,e.lineWidth=1,e.beginPath(),e.moveTo(P,w),e.lineTo(P,w+c),e.moveTo(P,w+c),e.lineTo(P+o,w+c),e.stroke()}function co(e,n,l,u,o,c,s,t,x,m,p,r={along:c,offset:0}){Xe=[],e.font=`${ee(-1)}px system-ui, sans-serif`;const i=Yn(e,Math.max(Math.abs(x.lo),Math.abs(x.hi)),p.unit),f=p.time?rn(x.lo,x.hi,o,Mn(e)):void 0,d=f?{ticks:f.ticks,step:0}:x.log?bn(x.lo,x.hi,o,i):Dt(x.lo,x.hi,o,i),k=f?{tick:f.label,unitLabel:""}:Nt(p,x.lo,x.hi,d.step||void 0);e.strokeStyle=n.grid,e.lineWidth=.5,e.fillStyle=n.textMuted;for(const g of d.ticks){const v=P+x.frac(g)*o;e.beginPath(),e.moveTo(v,w),e.lineTo(v,w+c),e.stroke(),e.textAlign="center",e.textBaseline="top",e.fillText(k.tick(g),v,w+c+4)}const M=s.labels.length,S=r.along/Math.max(1,M),b=w-r.offset;e.save(),e.beginPath(),e.rect(0,w-1,P+o+1,c+2),e.clip(),e.textAlign="right",e.textBaseline="middle";const T=Math.max(0,Math.floor(r.offset/S)),y=Math.min(M,Math.ceil((r.offset+c)/S));for(let g=T;g<y;g++)e.fillText(Jt(e,s.labels[g],t.inner),P-6,b+(g+.5)*S);if(s.nest){const g=s.nest[0]?.length??0;let v=P-6-t.inner-10;for(let R=g-2;R>=0;R--){const L=t.outer[R]??0,O=F=>s.nest[F].slice(0,R+1).join("");let A=0;for(let F=1;F<=M;F++){if(F<M&&O(F)===O(A))continue;const D=b+A*S,Q=b+F*S;e.fillStyle=n.text,e.textAlign="right",e.textBaseline="middle",e.fillText(Jt(e,s.nest[A][R],L),v,(D+Q)/2),F<M&&(e.save(),e.strokeStyle=n.border,e.globalAlpha=R===0?.9:.45,e.lineWidth=1,e.beginPath(),e.moveTo(v-L,Q),e.lineTo(P+o,Q),e.stroke(),e.restore()),A=F}v-=L+10}e.fillStyle=n.textMuted}e.restore(),e.font=`${ee(0)}px system-ui, sans-serif`,e.fillStyle=n.text,e.textAlign="center",e.textBaseline="bottom",e.fillText(Rt(p,k.unitLabel),P+o/2,u-6),e.save(),e.translate(14,w+c/2),e.rotate(-Math.PI/2),e.textBaseline="top",e.fillText(Rt(m,""),0,0),e.restore(),e.strokeStyle=n.border,e.lineWidth=1,e.beginPath(),e.moveTo(P,w),e.lineTo(P,w+c),e.moveTo(P,w+c),e.lineTo(P+o,w+c),e.stroke()}function fo(){if(!a||!E||a.marks?.type!=="scatter"||!a.x||!a.y)return;Je(E,ie??0);const e=ze(B),{w:n,h:l,plotW:u,plotH:o}=Ye(),c=et(E,B,n,l);if(!c)return;const{ctx:s}=c,t=a.marks.points,x=W.size===0?t:t.filter(L=>W.has(L.group)),m=a.colorScale,p=Lt(a.spec.colorGradient,a.spec.colorReverse,m?.diverging,m?.rating,{card:e.bg,text:e.text},m?.counts,h.readerColors),r=Ie(a.x),i=Ie(a.y),f=be(Ge(_e(t.map(L=>L.x),a.x),r,a.x),yt("x",a.x)),d=be(Ge(_e(t.map(L=>L.y),a.y),i,a.y),yt("y",a.y));X={x:f,y:d,plotW:u,plotH:o},lt(s,e,n,l,u,o,f,d,a.x,a.y),Ue(s,e.limitLine,u,o,f,r,a.x,"x"),Ue(s,e.limitLine,u,o,d,i,a.y,"y"),ct(s,u,o);const k=x.length>qt?Math.ceil(x.length/qt):1,M=[];for(let L=0;L<x.length;L+=k)M.push(x[L]);s.globalAlpha=Math.max(.15,Math.min(.7,200/M.length));let S;if(m)S=[M];else{const L=new Map;for(const O of M){const A=L.get(O.group);A?A.push(O):L.set(O.group,[O])}S=[...L.values()].sort((O,A)=>A.length-O.length)}fe=[];const b=P,T=P+u,y=w,g=w+o;for(const L of S)for(const O of L){const A=P+f.frac(O.x)*u,F=w+(1-d.frac(O.y))*o;A<b||A>T||F<y||F>g||(fe.push({p:O,cx:A,cy:F}),s.beginPath(),s.arc(A,F,2.5,0,Math.PI*2),s.fillStyle=m&&O.value!==void 0?p(mn(m,O.value)):oe(O.group),s.fill())}s.globalAlpha=1;const v=a.marks;if(v.type==="scatter"&&(v.identity||v.fits)){const L=(A,F)=>[P+f.frac(A)*u,w+(1-d.frac(F))*o],O=(A,F,D)=>{s.save(),s.beginPath(),s.rect(P,w,u,o),s.clip(),s.strokeStyle=F,s.lineWidth=2,s.setLineDash(D),s.beginPath();for(let Q=0;Q<=60;Q++){const ne=Q/60,Be=f.log?10**(Math.log10(f.lo)+(Math.log10(f.hi)-Math.log10(f.lo))*ne):f.lo+(f.hi-f.lo)*ne,[$,he]=L(Be,A(Be));Q===0?s.moveTo($,he):s.lineTo($,he)}s.stroke(),s.restore()};v.identity&&O(A=>A,e.textMuted,[6,4]);for(const A of v.fits??[])W.size>0&&!W.has(A.group)&&!m||O(F=>A.intercept+A.slope*F,m?e.text:oe(A.group),[])}const R=ve?fe.find(L=>L.p===ve):void 0;if(R&&(s.beginPath(),s.arc(R.cx,R.cy,5,0,Math.PI*2),s.lineWidth=2,s.strokeStyle=e.text,s.stroke()),xe.size>0){s.lineWidth=1.5,s.strokeStyle=e.text;let L=0;for(const O of xe)if(!(W.size>0&&!W.has(O.group))){if(++L>qt)break;s.beginPath(),s.arc(P+f.frac(O.x)*u,w+(1-d.frac(O.y))*o,4,0,Math.PI*2),s.stroke()}}}function uo(){if(Re=void 0,!a||a.marks?.type!=="histogram"||!a.x)return;const e=a.marks.values,n=e.flat();if(n.length===0)return;const l=be(Ge(_e(n,a.x),Ie(a.x),a.x),a.x),u=Math.max(1,a.spec.bins??$s),o=l.log?Math.log10(l.lo):l.lo,c=l.log?Math.log10(l.hi):l.hi,s=Array.from({length:u+1},(i,f)=>{const d=o+(c-o)*f/u;return l.log?10**d:d}),t=e.map(()=>new Array(u).fill(0));e.forEach((i,f)=>{for(const d of i){const k=l.log?d>0?Math.log10(d):NaN:d;if(!Number.isFinite(k)||k<o||k>c)continue;const M=Math.min(u-1,Math.floor((k-o)/(c-o)*u));t[f][M]++}});const x=a.spec.histNorm==="percent",m=x?t.map(i=>{const f=i.reduce((d,k)=>d+k,0);return i.map(d=>f?d/f*100:0)}):t;let p=0;const r=e.map(()=>{});if(a.spec.normalCurve&&!l.log){const i=(s[s.length-1]-s[0])/u;e.forEach((f,d)=>{const k=f.filter(Number.isFinite);if(k.length<2)return;const M=k.reduce((b,T)=>b+T,0)/k.length,S=Math.sqrt(jo(k,M));S>0&&(r[d]={mean:M,sd:S},p=Math.max(p,(x?100:t[d].reduce((b,T)=>b+T,0))*i/(S*Math.sqrt(2*Math.PI))))})}Re={edges:s,counts:t,heights:m,normal:r,maxCount:Math.max(x?.001:1,p,...m.map(i=>pe(i)))}}function ho(){if(!a||!E||!Re||!a.x||!a.y)return;Je(E,ie??0);const e=ze(B),{w:n,h:l,plotW:u,plotH:o}=Ye(),c=et(E,B,n,l);if(!c)return;const{ctx:s}=c,{edges:t,counts:x,heights:m,normal:p,maxCount:r}=Re,i=be([t[0],t[t.length-1]],{...a.x,min:te.x?.[0]??t[0],max:te.x?.[1]??t[t.length-1]}),f=be([0,r],{label:a.y.label,scale:"linear",min:0,max:r*1.05});X={x:i,y:f,plotW:u,plotH:o},lt(s,e,n,l,u,o,i,f,a.x,a.y),Ue(s,e.limitLine,u,o,i,Ie(a.x),a.x,"x"),ct(s,u,o);const d=x.map((T,y)=>y).filter(T=>W.size===0||W.has(T)),k=d.length>1,M=d.length>=3,S=T=>P+Math.min(i.frac(t[T]),i.frac(t[T+1]))*u,b=T=>P+Math.max(i.frac(t[T]),i.frac(t[T+1]))*u;for(const T of d){if(M){s.fillStyle=oe(T),s.strokeStyle=oe(T),s.lineWidth=1.75,s.lineJoin="round",s.globalAlpha=.1,m[T].forEach((g,v)=>{if(g===0)return;const R=w+(1-f.frac(g))*o;s.fillRect(S(v),R,Math.max(1,b(v)-S(v)),w+o-R)}),s.globalAlpha=1,s.beginPath();let y=!1;m[T].forEach((g,v)=>{const R=w+(1-f.frac(g))*o;y||(s.moveTo(S(v),w+o),y=!0),s.lineTo(S(v),R),s.lineTo(b(v),R),v===m[T].length-1&&s.lineTo(b(v),w+o)}),s.stroke();continue}s.globalAlpha=k?.55:.85,s.fillStyle=oe(T),m[T].forEach((y,g)=>{if(y===0)return;const v=w+(1-f.frac(y))*o;s.fillRect(S(g),v,Math.max(1,b(g)-S(g)-1),w+o-v)})}if(s.globalAlpha=1,a.spec.normalCurve&&!i.log){const T=(t[t.length-1]-t[0])/(t.length-1);for(const y of d){const g=p[y];if(!g)continue;const{mean:v,sd:R}=g,L=(a.spec.histNorm==="percent"?100:x[y].reduce((O,A)=>O+A,0))*T;s.save(),s.beginPath(),s.rect(P,w,u,o),s.clip(),s.strokeStyle=oe(y),s.lineWidth=2,s.beginPath();for(let O=0;O<=120;O++){const A=t[0]+(t[t.length-1]-t[0])*O/120,F=Math.exp(-.5*((A-v)/R)**2)/(R*Math.sqrt(2*Math.PI)),D=P+i.frac(A)*u,Q=w+(1-f.frac(L*F))*o;O===0?s.moveTo(D,Q):s.lineTo(D,Q)}s.stroke(),s.restore()}}if(Te>=0){const T=P+Math.min(i.frac(t[Te]),i.frac(t[Te+1]))*u,y=P+Math.max(i.frac(t[Te]),i.frac(t[Te+1]))*u;s.lineWidth=1.5,s.strokeStyle=e.text,s.strokeRect(T,w,Math.max(1,y-T),o)}}function mo(){const e=a?.marks;if(!a||!E||!a.x||!a.y||!e||e.type!=="box"&&e.type!=="bar")return;Je(E,ie??0);const n=ze(B),l=a.spec.orientation==="horizontal",u=e.nest?e.nest.parts.map(C=>C[C.length-1]):e.categories,o=e.categories.length,c=a.groups.length,s=C=>W.size===0||W.has(C),t=e.type==="bar"&&!!e.stack,x=(C,_)=>e.type==="bar"?Number.isFinite(e.values[C][_]):e.cells[C][_].length>0,m=Array.from({length:o},(C,_)=>Array.from({length:c},(z,U)=>U).filter(z=>s(z)&&x(z,_))),p=categoryLayout(t?m.map(C=>C.length?[0]:[]):m),r=E.getContext("2d"),i=C=>r?r.measureText(C).width:C.length*6;r&&(r.font=`${ee(-1)}px system-ui, sans-serif`);const f=(C,_)=>C.length>_?`${C.slice(0,_-1)}\u2026`:C;let d=!1,k={inner:0,outer:[]},M=0;const S=Math.max(1,...m.map(C=>t?Math.min(1,C.length):C.length));if(l)k={inner:Math.min(200,pe(u.map(C=>i(f(C,28))))),outer:e.nest?e.nest.levels.slice(0,-1).map((C,_)=>Math.min(140,pe(e.nest.parts.map(z=>i(f(z[_],20)))))):[]},P=Math.max(at,30+k.inner+6+k.outer.reduce((C,_)=>C+_+10,0)),e.cumulative&&(w=gn+18),je=tt,M=Math.max(22,S*Ms/.8);else{M=Math.max(ws,S*ks/.8);const C=pe(u.map(U=>i(f(U,22)))),_=Math.max(M,Math.max(10,I.clientWidth-P-mt)/Math.max(1,o));d=C+8>_;const z=e.nest?e.nest.levels.length-1:0;je=(d?tt+Math.min(110,C*.72):tt)+z*Qt}const b=e.type==="bar"&&!t&&!!a.spec.valueLabels,T=a.y.time?void 0:Nt(a.y,0,pe(e.values.flat().filter(Number.isFinite).map(Math.abs).concat(0))),y=C=>T?T.tick(C):nt(a.y,C),g=b?pe(e.values.flat().filter(Number.isFinite).map(C=>i(y(C))).concat(0))+8:0,v=l?g:e.cumulative?40:0,R=Ye(),{plotW:L}=R;let{w:O,h:A,plotH:F}=R;Bt&&l&&o*M>F&&o*M<=to&&(F=o*M,A=F+w+je);let D=Math.max(10,L-v);Bt&&!l&&o*M>D&&o*M<=to&&(D=o*M,O=D+v+P+mt);const Q=I.clientWidth>0,ne=!l&&Q&&o*M>D+.5?Ts:0,Be=et(E,B,O,A+ne);if(!Be)return;const{ctx:$}=Be,he=C=>C.filter(Number.isFinite),Ke=Ie(a.y),it=t?e.categories.map((C,_)=>e.values.reduce((z,U,K)=>z+(s(K)&&Number.isFinite(U[_])?U[_]:0),0)):[],Wt=e.type==="bar"?[...t?it:he(e.values.flat()),0]:he(e.cells.flat(2));$.font=`${ee(-1)}px system-ui, sans-serif`;const Ln=l?F:D,Wo=o*M>Ln+.5&&(l||Q)?o*M:Ln,Pn=p.width*(Wo/o),Cn=b&&!l?g-8:0,En=b&&!l&&Cn<=Pn+6,zt=b&&!l&&!En&&ee(-1)<=Pn+4,ut=l?g:zt?Cn+8:ee(-1)+6;if(b&&!l&&Wt.length){const C=pe(Wt);C>0&&Wt.push(C*(1+ut/Math.max(1,F-ut)))}const He=be(Ge(_e(Wt,a.y),Ke,a.y),a.y,{floorAtZero:e.type==="bar"});X={x:He,y:He,plotW:D,plotH:F};const St=l?F:D,Ve=o*M>St+.5&&(l||Q),dt=Ve?o*M:St,Fe=Ve?Math.max(0,Math.min(ot,dt-St)):0;ot=Fe,Lo(Ve,dt,Fe,D+v,F,l,D,A+ne),l?co($,n,O,A,D,F,{labels:u,rotate:!1,nest:e.nest?.parts},k,He,a.x,a.y,{along:dt,offset:Fe}):lt($,n,O,A,D,F,{labels:u,rotate:d,nest:e.nest?.parts,...Ve?{along:dt,offset:Fe}:{}},He,a.x,a.y);const ye=dt/o,Oe=p.width*ye;if(Ve&&!l){const C=Math.floor(Fe/ye)+1,_=Math.min(o,Math.ceil((Fe+St)/ye));$.save(),$.fillStyle=n.textMuted,$.font=`${ee(-1)}px system-ui, sans-serif`,$.textAlign="right",$.textBaseline="bottom",$.fillText(`${C.toLocaleString("en-GB")}\u2013${_.toLocaleString("en-GB")} of ${o.toLocaleString("en-GB")}`,P+D,A-18),$.restore()}re={slotW:ye,n:o,plotW:dt,layout:p,across:l,offset:Fe,view:St};const ce=C=>l?P+He.frac(C)*D:w+(1-He.frac(C))*F,$e=C=>l?w+C-Fe:P+C-Fe,sn=He.log?l?P:w+F:ce(0),ht=(C,_,z,U)=>l?[Math.min(z,U),$e(C),Math.max(1,Math.abs(U-z)),_-C]:[$e(C),Math.min(z,U),_-C,Math.max(1,Math.abs(U-z))],ln=(C,_,z,U)=>{$.beginPath(),l?($.moveTo(_,$e(C)),$.lineTo(U,$e(z))):($.moveTo($e(C),_),$.lineTo($e(z),U)),$.stroke()},We=C=>l?C>=sn:C<=sn,zo=C=>l?ee(-1)<=Oe+4:$.measureText(y(C)).width<=Oe+6,An=b&&(l?e.values.every(C=>C.every(_=>!Number.isFinite(_)||zo(_))):En||zt);if(An){for(let C=0;C<c;C++)if(s(C))for(let _=0;_<o;_++){const z=p.left(_,C),U=e.values[C][_];if(z===void 0||!Number.isFinite(U))continue;const K=$e(_*ye+z*ye+Oe/2),H=$.measureText(y(U)).width,Y=ce(U);l?Xe.push(We(Y)?{x0:Y,x1:Y+H+6,y0:K-ut/2,y1:K+ut/2}:{x0:Y-H-6,x1:Y,y0:K-8,y1:K+8}):zt?Xe.push(We(Y)?{x0:K-8,x1:K+8,y0:Y-H-6,y1:Y}:{x0:K-8,x1:K+8,y0:Y,y1:Y+H+6}):Xe.push(We(Y)?{x0:K-H/2,x1:K+H/2,y0:Y-ut,y1:Y}:{x0:K-H/2,x1:K+H/2,y0:Y,y1:Y+ut})}}const _o=Ue($,n.limitLine,D,F,He,Ke,a.y,l?"x":"y",{halo:n.bg}),Do=ct($,D,F,Ve);if(t){re.stacks=[];for(let C=0;C<o;C++){const _=p.left(C,0),z=[];if(re.stacks.push(z),_===void 0)continue;let U=0;for(let K=0;K<c;K++){const H=e.values[K][C];if(!s(K)||!Number.isFinite(H)||H<=0)continue;const Y=ce(U),me=ce(U+H);$.fillStyle=oe(K),$.globalAlpha=.9;const ge=C*ye+_*ye;$.fillRect(...ht(ge+1,ge+Oe-1,Y,me)),$.globalAlpha=1,z.push({g:K,p0:Math.min(Y,me),p1:Math.max(Y,me)}),U+=H}}}const Xo=ro(n);for(let C=0;C<c&&!t;C++){if(W.size>0&&!W.has(C))continue;const _=oe(C);for(let z=0;z<o;z++){const U=p.left(z,C);if(U===void 0)continue;const K=z*ye+U*ye;if(e.type==="bar"){const H=e.values[C][z];if(!Number.isFinite(H))continue;const Y=ce(H);if($.fillStyle=Xo?.(H)??_,$.globalAlpha=.9,$.fillRect(...ht(K+1,K+Oe-1,sn,Y)),$.globalAlpha=1,An){$.fillStyle=n.text,$.font=`${ee(-1)}px system-ui, sans-serif`;const me=$e(K+Oe/2);l?($.textBaseline="middle",$.textAlign=We(Y)?"left":"right",$.fillText(y(H),Y+(We(Y)?3:-3),me)):zt?($.save(),$.translate(me,Y+(We(Y)?-3:3)),$.rotate(-Math.PI/2),$.textAlign=We(Y)?"left":"right",$.textBaseline="middle",$.fillText(y(H),0,0),$.restore()):($.textAlign="center",$.textBaseline=We(Y)?"bottom":"top",$.fillText(y(H),me,Y+(We(Y)?-2:2)))}}else{const H=e.cells[C][z];if(H.length===0)continue;const Y=K+Oe/2,me=Math.max(3,Math.min(Oe*.7,46)),ge=Nn(Float64Array.from(H));if($.strokeStyle=_,$.fillStyle=_,$.lineWidth=1.5,H.length===1){$.beginPath(),l?$.arc(ce(ge.median),$e(Y),3,0,Math.PI*2):$.arc($e(Y),ce(ge.median),3,0,Math.PI*2),$.fill();continue}ln(Y,ce(ge.min),Y,ce(ge.max));for(const On of[ge.min,ge.max])ln(Y-me/4,ce(On),Y+me/4,ce(On));$.globalAlpha=.35,$.fillRect(...ht(Y-me/2,Y+me/2,ce(ge.q1),ce(ge.q3))),$.globalAlpha=1,$.strokeRect(...ht(Y-me/2,Y+me/2,ce(ge.q1),ce(ge.q3))),$.lineWidth=2.5,ln(Y-me/2,ce(ge.median),Y+me/2,ce(ge.median))}}}Do(),_o();const Bn=ue?p.left(ue.c,t?0:ue.g):void 0;if(ue&&Bn!==void 0){Ve&&($.save(),$.beginPath(),$.rect(P-1,w,D+2,F),$.clip()),$.lineWidth=1.5,$.strokeStyle=n.text;const C=ue.c*ye+Bn*ye,_=t?re.stacks?.[ue.c]?.find(z=>z.g===ue.g):void 0;t&&_?$.strokeRect(...ht(C,C+Oe,_.p0,_.p1)):t||$.strokeRect(...ht(C,C+Oe,l?P:w,l?P+D:w+F)),Ve&&$.restore()}if(e.cumulative){const C=z=>l?P+z/100*D:w+(1-z/100)*F,_=(z,U)=>l?[C(U),$e((z+.5)*ye)]:[$e((z+.5)*ye),C(U)];if($.save(),$.strokeStyle=n.text,$.fillStyle=n.text,$.lineWidth=1.5,$.beginPath(),e.cumulative.forEach((z,U)=>{const[K,H]=_(U,z);U===0?$.moveTo(K,H):$.lineTo(K,H)}),$.stroke(),e.cumulative.forEach((z,U)=>{const[K,H]=_(U,z);$.beginPath(),$.arc(K,H,2.5,0,Math.PI*2),$.fill()}),$.strokeStyle=n.border,$.lineWidth=1,$.beginPath(),l?($.moveTo(P,w),$.lineTo(P+D,w)):($.moveTo(P+D,w),$.lineTo(P+D,w+F)),$.stroke(),$.fillStyle=n.textMuted,$.font=`${ee(-1)}px system-ui, sans-serif`,l){$.textAlign="center",$.textBaseline="bottom";for(const z of[0,25,50,75,100])$.fillText(`${z}%`,C(z),w-3)}else{$.textAlign="left",$.textBaseline="middle";for(const z of[0,25,50,75,100])$.fillText(`${z}%`,P+D+4,C(z))}$.restore()}}function po(e){const n=a?.setTests,l=n?n.labels.indexOf(e):-1;return l>=0?{test:n.tests[l]}:{}}function en(e){if(!re||!E)return null;const n=E.getBoundingClientRect(),l=re.across?e.clientY-n.top-w:e.clientX-n.left-P;if(l<0||l>re.view)return null;const u=l+re.offset,o=Math.min(re.n-1,Math.floor(u/re.slotW)),c=re.layout.groupAt(o,(u-o*re.slotW)/re.slotW);if(c===void 0)return null;if(!re.stacks)return{g:c,c:o};const s=re.across?e.clientX-n.left:e.clientY-n.top,t=re.stacks[o]?.find(x=>s>=x.p0&&s<=x.p1);return t?{g:t.g,c:o}:null}function go(e,n,l){let u=0,o=0,c=0;for(const x of n)x===100&&u++;if(e.failSide)for(const x of l){const m=e.failSide[x];m<0?o++:m>0&&c++}const s=x=>x.toLocaleString("en-GB"),t=o+c>0?` (${s(o)} below the low limit \xB7 ${s(c)} above the high limit)`:"";return`${s(u)} pass \xB7 ${s(n.length-u)} fail${t} \xB7 n = ${s(n.length)}`}function yo(e){const n=a,l=n.marks,u=bt(n.level),o=l.cells[e.g][e.c],c=l.nest?l.nest.parts[e.c]:[l.categories[e.c]],s=n.groups.length>1&&!c.includes(st(e.g))?` \xB7 ${G(st(e.g))}`:"",t=`<strong>${G(l.categories[e.c])}${s}</strong><br>`;if(o.length===0)return`${t}no ${u}`;const x=l.cellCount?.[e.g][e.c],m=xt(x??o.length,n.level),p=(l.categoryItems&&h.onOpenWafer?`<br><em>click to ${G(vt())}</em>`:"")+(l.categoryItems&&h.onWaferMenu?hn:"");if(l.type==="bar"){const i=l.values[e.g][e.c],f=l.cumulative?`<br>${G(`cumulative: ${l.cumulative[e.c].toFixed(1)}% of the whole`)}`:"",d=x!==void 0&&Number.isFinite(i)?Math.round(i/100*x):void 0,k=l.passFail?d!==void 0?`${d.toLocaleString("en-GB")} pass \xB7 ${(x-d).toLocaleString("en-GB")} fail \xB7 n = ${x.toLocaleString("en-GB")}`:go(l.passFail,o,l.cellUnits[e.g][e.c]):m;return`${t}${G(`${n.y.label}: ${nt(n.y,i)}`)}<br>${G(k)}${f}${p}`}const r=Nn(Float64Array.from(o));return`${t}${["max","q3","median","q1","min"].map(i=>G(`${{max:"max",q3:"upper quartile",median:"median",q1:"lower quartile",min:"min"}[i]}: ${nt(n.y,r[i])}`)).join("<br>")}<br>${G(m)}${p}`}function bo(){const e=a?.marks;if(!a||!E||!a.x||!a.y||!e||e.type!=="line")return;Je(E,ie??0);const n=ze(B),{w:l,h:u,plotW:o,plotH:c}=Ye(),s=et(E,B,l,u);if(!s)return;const{ctx:t}=s,x=Ie(a.x),m=Ie(a.y),p=be(Ge(_e(e.xs,a.x),x,a.x),yt("x",a.x)),r=k=>!te.x||e.xs[k]>=te.x[0]&&e.xs[k]<=te.x[1],i=k=>k.flatMap(M=>M.filter((S,b)=>r(b))),f=e.band?[...i(e.band.lo),...i(e.band.hi)]:[],d=be(Ge(_e([...i(e.values),...f].filter(Number.isFinite),a.y),m,a.y),a.y);if(X={x:p,y:d,plotW:o,plotH:c},lt(t,n,l,u,o,c,p,d,a.x,a.y),Ue(t,n.limitLine,o,c,p,x,a.x,"x"),Ue(t,n.limitLine,o,c,d,m,a.y,"y"),ct(t,o,c),Me=e.xs.map(k=>P+p.frac(k)*o),e.band){const k=M=>w+(1-d.frac(M))*c;e.band.lo.forEach((M,S)=>{if(W.size>0&&!W.has(S))return;const b=e.band.hi[S];t.save(),t.fillStyle=oe(S),t.globalAlpha=.16;let T=[];const y=()=>{if(T.length===1){const g=T[0],v=Me[g];t.globalAlpha=.55,t.strokeStyle=oe(S),t.lineWidth=2,t.beginPath(),t.moveTo(v,k(M[g])),t.lineTo(v,k(b[g])),t.moveTo(v-4,k(M[g])),t.lineTo(v+4,k(M[g])),t.moveTo(v-4,k(b[g])),t.lineTo(v+4,k(b[g])),t.stroke(),t.globalAlpha=.16}else if(T.length){t.beginPath(),T.forEach((g,v)=>{v===0?t.moveTo(Me[g],k(b[g])):t.lineTo(Me[g],k(b[g]))});for(let g=T.length-1;g>=0;g--)t.lineTo(Me[T[g]],k(M[T[g]]));t.closePath(),t.fill()}T=[]};M.forEach((g,v)=>{Number.isFinite(g)&&Number.isFinite(b[v])?T.push(v):y()}),y(),t.restore()})}e.values.forEach((k,M)=>{if(W.size>0&&!W.has(M))return;t.strokeStyle=oe(M),t.fillStyle=oe(M),t.lineWidth=2;let S=!1;t.beginPath(),k.forEach((b,T)=>{if(!Number.isFinite(b)){S=!1;return}const y=Me[T],g=w+(1-d.frac(b))*c;S?t.lineTo(y,g):t.moveTo(y,g),S=!0}),t.stroke(),k.forEach((b,T)=>{Number.isFinite(b)&&(t.beginPath(),t.arc(Me[T],w+(1-d.frac(b))*c,ke===T?4.5:3,0,Math.PI*2),t.fill())})}),ke>=0&&(t.lineWidth=1,t.strokeStyle=n.textMuted,t.beginPath(),t.moveTo(Me[ke],w),t.lineTo(Me[ke],w+c),t.stroke())}function tn(e){const n=a?.marks;if(!n||n.type!=="line"||!E||!a?.x||Me.length===0)return null;const l=e.clientX-E.getBoundingClientRect().left;let u=-1,o=24;if(Me.forEach((s,t)=>{const x=Math.abs(s-l);x<o&&(o=x,u=t)}),ke=u,u<0)return null;const c=n.values.map((s,t)=>({g:t,v:s[u],n:n.counts[t][u]})).filter(s=>Number.isFinite(s.v)&&(W.size===0||W.has(s.g)));return`<strong>${G(`${a.x.label}: ${lo(a.x,n.xs[u])}`)}</strong><br>`+c.map(s=>{const t=n.band?.lo[s.g][u],x=n.band?.hi[s.g][u],m=t!==void 0&&x!==void 0&&Number.isFinite(t)&&Number.isFinite(x)?`, band ${Ce(t,a.y.unit)} to ${Ce(x,a.y.unit)}`:"";return G(`${a.groups.length>1?`${st(s.g)}: `:""}${nt(a.y,s.v)}${m} (${xt(s.n,a.level)})`)}).join("<br>")+(h.onWaferMenu&&kn(u)!==void 0?hn:"")}function kn(e){const n=a?.marks;if(n?.type!=="line")return;const l=new Set(n.cellUnits.flatMap((u,o)=>W.size>0&&!W.has(o)?[]:(u[e]??[]).map(c=>n.unit(c).item)));return l.size===1?[...l][0]:void 0}function xo(){const e=a?.marks;if(!a||!E||!a.x||!a.y||e?.type!=="probability")return;Je(E,ie??0);const n=ze(B),{w:l,h:u,plotW:o,plotH:c}=Ye(),s=et(E,B,l,u);if(!s)return;const{ctx:t}=s,x=a.spec.probabilityAxis==="linear",m=e.values.map((L,O)=>O).filter(L=>e.values[L].length>0&&(W.size===0||W.has(L))),p=Math.max(1,...m.map(L=>e.values[L].length)),r=Math.min(.01,$t(0,p)),i=L=>x?L:Rn(L),f=x?0:i(r),d=x?1:i(1-r),k=x?0:(d-f)*.03,M=be([f-k,d+k],{label:a.y.label,scale:"linear",min:f-k,max:d+k}),S=x?[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:Ls.filter(L=>L>=r&&L<=1-r),b=[],T=L=>w+(1-M.frac(L))*c,y=S.indexOf(.5);b.push({at:i(.5),label:oo(.5)});for(const L of[S.slice(y+1),S.slice(0,y).reverse()]){let O=T(i(.5));for(const A of L){const F=T(i(A));Math.abs(F-O)<16||(b.push({at:i(A),label:oo(A)}),O=F)}}const g=Ie(a.x),v=be(Ge(_e(m.flatMap(L=>[e.values[L][0],e.values[L][e.values[L].length-1]]),a.x),g,a.x),yt("x",a.x));X={x:v,y:M,plotW:o,plotH:c},lt(t,n,l,u,o,c,v,M,a.x,a.y,b),Ue(t,n.limitLine,o,c,v,g,a.x,"x"),ct(t,o,c),fe=[],t.save(),t.beginPath(),t.rect(P,w,o,c),t.clip();for(const L of m){const O=e.values[L],A=O.length,F=Ps(A);if(t.strokeStyle=oe(L),t.fillStyle=oe(L),t.lineWidth=1.5,t.beginPath(),F.forEach((D,Q)=>{const ne=P+v.frac(O[D])*o,Be=T(i($t(D,A)));Q===0?t.moveTo(ne,Be):t.lineTo(ne,Be);const $=L*2**26+D;let he=Vt.get($);if(!he){const{item:Ke,die:it}=e.unit(e.units[L][D]);he={x:O[D],y:$t(D,A),group:L,item:Ke,die:it},Vt.set($,he)}fe.push({p:he,cx:ne,cy:Be})}),t.stroke(),A<=300)for(const D of F)t.beginPath(),t.arc(P+v.frac(O[D])*o,T(i($t(D,A))),2.5,0,Math.PI*2),t.fill()}if(t.restore(),xe.size>0){t.lineWidth=1.5,t.strokeStyle=n.text;let L=0;for(const O of xe)if(!(W.size>0&&!W.has(O.group))){if(++L>qt)break;t.beginPath(),t.arc(P+v.frac(O.x)*o,T(i(O.y)),4,0,Math.PI*2),t.stroke()}}const R=ve?fe.find(L=>L.p===ve):void 0;R&&(t.beginPath(),t.arc(R.cx,R.cy,5,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=n.text,t.stroke())}function vo(e){const n=a,u=n.marks.values[e.group].length,o=Math.round(e.y*u+.5),c=h.waferLabel(e.item),s=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",t=[c,s].filter(Boolean).join(" \xB7 ");return(t?`<strong>${G(t)}</strong><br>`:"")+G(`${n.x.label}: ${lo(n.x,e.x)}`)+"<br>"+G(`rank ${o.toLocaleString("en-GB")} of ${u.toLocaleString("en-GB")}, plotted at ${+(e.y*100).toPrecision(3)}%`)+(n.groups.length>1?`<br>${G(st(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${G(vt())}</em>`:"")+(h.onWaferMenu&&!e.die?hn:"")}let qe,Se=null;function Mo(){const e=a?.marks;if(!a||!E||e?.type!=="heatmap")return;Je(E,ie??0);const n=ze(B),l=E.getContext("2d");let u=0,o=0;l&&(l.font=`${ee(-1)}px system-ui, sans-serif`,u=pe(e.rows.map(b=>l.measureText(b.length>24?`${b.slice(0,23)}\u2026`:b).width)),o=pe(e.cols.map(b=>l.measureText(b.length>22?`${b.slice(0,21)}\u2026`:b).width)));const c=Math.min(180,Math.max(P,u+24)),s=Math.max(8,I.clientWidth-c-mt)/Math.max(1,e.cols.length),t=o+8>s;je=t?tt+Math.min(110,o*.72):tt;const{w:x,h:m}=Ye(),p=Math.max(10,x-c-mt),r=Math.max(10,m-w-je),i=et(E,B,x,m);if(!i)return;const{ctx:f}=i,d=p/e.cols.length,k=r/e.rows.length;qe={left:c,cw:d,ch:k,rows:e.rows.length,cols:e.cols.length};const M=a.colorScale,S=Lt(a.spec.colorGradient,a.spec.colorReverse,M?.diverging,M?.rating,{card:n.bg,text:n.text},M?.counts,h.readerColors);f.font=`${ee(-1)}px system-ui, sans-serif`;for(let b=0;b<e.rows.length;b++)for(let T=0;T<e.cols.length;T++){const y=e.values[b][T],g=c+T*d,v=w+b*k,R=Number.isFinite(y)&&M?S(mn(M,y)):n.track;if(f.fillStyle=R,f.fillRect(g,v,d,k),Number.isFinite(y)&&d>=40&&k>=16){const L=xs(R);f.fillStyle=L?"#1a1a1a":"#fff",f.textAlign="center",f.textBaseline="middle",dn(f,yn(y,M?.unit,M?.integer),g+d/2,v+k/2,L?"rgba(255,255,255,0.55)":"rgba(0,0,0,0.55)")}}f.lineWidth=1,f.setLineDash([]),f.strokeStyle=n.border,f.beginPath();for(let b=1;b<e.rows.length;b++){const T=Math.round(w+b*k)+.5;f.moveTo(c,T),f.lineTo(c+p,T)}for(let b=1;b<e.cols.length;b++){const T=Math.round(c+b*d)+.5;f.moveTo(T,w),f.lineTo(T,w+r)}f.stroke(),f.strokeStyle=n.textMuted,f.strokeRect(c+.5,w+.5,p-1,r-1),f.beginPath();for(let b=0;b<e.rows.length;b++){const T=Math.round(w+(b+.5)*k)+.5;f.moveTo(c-4,T),f.lineTo(c,T)}for(let b=0;b<e.cols.length;b++){const T=Math.round(c+(b+.5)*d)+.5;f.moveTo(T,w+r),f.lineTo(T,w+r+4)}f.stroke(),Se&&(f.lineWidth=2,f.strokeStyle=n.text,f.strokeRect(c+Se.c*d,w+Se.r*k,d,k)),f.fillStyle=n.textMuted,f.textAlign="right",f.textBaseline="middle",e.rows.forEach((b,T)=>f.fillText(b.length>24?`${b.slice(0,23)}\u2026`:b,c-8,w+(T+.5)*k)),e.cols.forEach((b,T)=>{const y=b.length>22?`${b.slice(0,21)}\u2026`:b,g=c+(T+.5)*d;t?(f.save(),f.translate(g,w+r+8),f.rotate(-Math.PI/4),f.textAlign="right",f.textBaseline="middle",f.fillText(y,0,0),f.restore()):(f.textAlign="center",f.textBaseline="top",f.fillText(y,g,w+r+7))}),f.font=`${ee(0)}px system-ui, sans-serif`,f.fillStyle=n.text,f.textAlign="center",f.textBaseline="bottom",f.fillText(a.x?.label??"",c+p/2,m-6)}function wn(e){if(!qe||!E)return null;const n=E.getBoundingClientRect(),l=Math.floor((e.clientX-n.left-qe.left)/qe.cw),u=Math.floor((e.clientY-n.top-w)/qe.ch);return u>=0&&u<qe.rows&&l>=0&&l<qe.cols?{r:u,c:l}:null}function ko(e){const n=a,l=n.marks,u=l.values[e.r][e.c],o=l.cellUnits[e.r][e.c].length;return`<strong>${G(`${l.rows[e.r]} \xB7 ${l.cols[e.c]}`)}</strong><br>`+(Number.isFinite(u)?G(`${n.colorScale?.label??"Count"}: ${yn(u,n.colorScale?.unit,n.colorScale?.integer)}`)+"<br>":"")+G(xt(o,n.level))+(o&&h.onSelectPoints?`<br><em>click or right-click to ${G(h.selectActionLabel??"chart or tabulate them")}</em>`:"")}function wo(){const e=a?.marks;if(!a||!E||!a.x||!a.y||e?.type!=="control")return;Je(E,ie??0);const n=ze(B),{w:l,h:u,plotW:o,plotH:c}=Ye(),s=et(E,B,l,u);if(!s)return;const{ctx:t}=s,x=e.limits,m=Ie(a.y),p=be(_e(e.xs,a.x),yt("x",a.x)),r=te.x?e.values.filter((g,v)=>e.xs[v]>=te.x[0]&&e.xs[v]<=te.x[1]):e.values,i=be(Ge(_e([...r,x.ucl,x.lcl],a.y),m,a.y),a.y);X={x:p,y:i,plotW:o,plotH:c},lt(t,n,l,u,o,c,p,i,a.x,a.y),Ue(t,n.limitLine,o,c,i,m,a.y,"y"),ct(t,o,c);const f=g=>P+p.frac(e.xs[g])*o,d=g=>w+(1-i.frac(g))*c;t.save(),t.beginPath(),t.rect(P,w,o,c),t.clip();const k=(g,v,R,L=1)=>{t.globalAlpha=R,t.setLineDash(v),t.lineWidth=L,t.strokeStyle=n.text,t.beginPath(),t.moveTo(P,d(g)),t.lineTo(P+o,d(g)),t.stroke()};for(const g of[-2,-1,1,2])k(x.centre+g*x.sigma,[2,4],.25);k(x.centre,[],.6,1.5),k(x.ucl,[6,4],.85),k(x.lcl,[6,4],.85),t.restore(),t.fillStyle=n.textMuted,t.font=`${ee(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="bottom";const M=g=>Ce(g,a.y.unit);if(t.fillText(`UCL ${M(x.ucl)}`,P+o-4,d(x.ucl)-2),t.textBaseline="top",t.fillText(`LCL ${M(x.lcl)}`,P+o-4,d(x.lcl)+2),t.textBaseline="bottom",t.fillText(`Centre ${M(x.centre)}`,P+o-4,d(x.centre)-2),x.baseline<e.values.length){const g=(f(x.baseline-1)+f(x.baseline))/2;t.save(),t.strokeStyle=n.textMuted,t.setLineDash([2,3]),t.beginPath(),t.moveTo(g,w),t.lineTo(g,w+c),t.stroke(),t.restore(),t.textAlign="left",t.textBaseline="top",t.fillText("limits from here \u2190",P+4,w+2)}t.strokeStyle=oe(0),t.lineWidth=1.5,t.setLineDash([]);const S=W.size>0,b=g=>e.group?.[g]??0;if(!S)t.beginPath(),e.values.forEach((g,v)=>{v===0?t.moveTo(f(v),d(g)):t.lineTo(f(v),d(g))}),t.stroke();else{for(const g of[!1,!0]){t.globalAlpha=g?1:.2,t.beginPath();for(let v=1;v<e.values.length;v++)(W.has(b(v-1))&&W.has(b(v)))===g&&(t.moveTo(f(v-1),d(e.values[v-1])),t.lineTo(f(v),d(e.values[v])));t.stroke()}t.globalAlpha=1}const T=new Map(e.violations.map(g=>[g.index,g.rules]));fe=[],e.values.forEach((g,v)=>{const R=T.get(v),L=b(v),O=S&&W.has(L),A=S&&!O;t.globalAlpha=A?.2:1,t.beginPath(),t.arc(f(v),d(g),(R?4.5:3)+(O?1.5:0),0,Math.PI*2),t.fillStyle=R?n.alert:oe(L),t.fill(),O&&(t.lineWidth=1.5,t.strokeStyle=n.text,t.stroke()),R&&(t.fillStyle=n.alert,t.textAlign="center",t.textBaseline="bottom",t.fillText(R.join(","),f(v),d(g)-(O?8:6))),t.globalAlpha=1,fe.push({p:{x:e.xs[v],y:g,group:L,item:e.items[v]},cx:f(v),cy:d(g)})});const y=ve?fe.find(g=>g.p===ve):void 0;y&&(t.beginPath(),t.arc(y.cx,y.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=n.text,t.stroke())}function To(e){const n=a,l=n.marks,u=l.items.indexOf(e.item),o=(e.y-l.limits.centre)/l.limits.sigma,c=l.violations.find(s=>s.index===u)?.rules;return`<strong>${G(h.waferLabel(e.item))}</strong><br>`+G(`${n.y.label}: ${Ce(e.y,n.y.unit)} (${o>=0?"+":"\u2212"}${Math.abs(o).toFixed(1)}\u03C3)`)+(c?`<br>${G(`breaks rule ${c.map(s=>`${s} (${Yo[s]})`).join(", ")}`)}`:"")+(h.onOpenWafer?`<br><em>click to ${G(vt())}</em>`:"")}function So(){const e=a?.marks;if(!a||!E||!a.x||!a.y||e?.type!=="goal")return;Je(E,ie??0);const n=ze(B),{w:l,h:u,plotW:o,plotH:c}=Ye(),s=et(E,B,l,u);if(!s)return;const{ctx:t}=s,x=Math.max(.5,...e.points.map(y=>Math.abs(y.x))),m=be([-x,x],{...a.x,min:a.x.min??-x*1.05,max:a.x.max??x*1.05}),p=be([0,...e.points.map(y=>y.y),1/6],{...a.y,min:a.y.min??0},{floorAtZero:!0});X={x:m,y:p,plotW:o,plotH:c},lt(t,n,l,u,o,c,m,p,a.x,a.y);const r=y=>P+m.frac(y)*o,i=y=>w+(1-p.frac(y))*c;t.save(),t.beginPath(),t.rect(P,w,o,c),t.clip(),t.font=`${ee(-1)}px system-ui, sans-serif`;const f=[[1,[6,4]],[1.33,[]]];for(const[y,g]of f){const v=1/(6*y);t.strokeStyle=n.textMuted,t.lineWidth=1,t.setLineDash(g),t.beginPath(),t.moveTo(r(-.5),i(0)),t.lineTo(r(0),i(v)),t.lineTo(r(.5),i(0)),t.stroke(),t.fillStyle=n.textMuted,t.textAlign="left",t.textBaseline="bottom",t.fillText(`Ppk ${y}`,r(0)+4,i(v)-2)}t.restore(),fe=[];const d=e.points.filter(y=>W.size===0||W.has(y.group));for(const y of d)t.beginPath(),t.arc(r(y.x),i(y.y),4,0,Math.PI*2),t.fillStyle=oe(y.group),t.fill(),fe.push({p:{x:y.x,y:y.y,group:y.group,item:-1,value:y.testNumber},cx:r(y.x),cy:i(y.y)});const k=d.map(y=>({x0:r(y.x)-5,x1:r(y.x)+5,y0:i(y.y)-5,y1:i(y.y)+5})),M={x0:P,x1:P+o,y0:w,y1:w+c},S=y=>y.x0>=M.x0&&y.x1<=M.x1&&y.y0>=M.y0&&y.y1<=M.y1&&!k.some(g=>y.x0<g.x1&&y.x1>g.x0&&y.y0<g.y1&&y.y1>g.y0),b=ee(-1)+2;t.fillStyle=n.text,t.textBaseline="middle";for(const y of[...d].filter(g=>g.ppk<1).sort((g,v)=>g.ppk-v.ppk)){const g=r(y.x),v=i(y.y),R=t.measureText(y.label).width,L=[[g+7,v,"left"],[g-7,v,"right"],[g,v-13,"center"],[g,v+13,"center"]];for(const[O,A,F]of L){const D=F==="left"?O:F==="right"?O-R:O-R/2,Q={x0:D,x1:D+R,y0:A-b/2,y1:A+b/2};if(S(Q)){k.push(Q),t.textAlign=F,t.fillText(y.label,O,A);break}}}const T=ve?fe.find(y=>y.p===ve):void 0;T&&(t.beginPath(),t.arc(T.cx,T.cy,6,0,Math.PI*2),t.lineWidth=2,t.strokeStyle=n.text,t.stroke())}function $o(e){const n=a,u=n.marks.points.find(o=>o.testNumber===e.value&&o.group===e.group);return u?`<strong>${G(u.label)}</strong>${n.groups.length>1?` \xB7 ${G(st(u.group))}`:""}<br>`+G(`Ppk ${u.ppk.toFixed(2)} \xB7 ${xt(u.n,"die")}`)+"<br>"+G(`mean ${u.x>=0?"+":"\u2212"}${Math.abs(u.x*100).toFixed(1)}% of the window from its centre, \u03C3 ${(u.y*100).toFixed(1)}% of it (${u.basis==="spec"?"spec":"test"} limits)`):""}function Lo(e,n,l,u,o,c=!0,s=0,t=0){!de||!E||(de.style.display=e?"block":"none",e&&(c?(Object.assign(de.style,{top:`${E.offsetTop+w}px`,height:`${o}px`,left:`${E.offsetLeft+P+u+1}px`}),de.firstElementChild.style.height=`${n}px`,Math.abs(de.scrollTop-l)>=1&&(de.scrollTop=l)):(Object.assign(de.style,{left:`${E.offsetLeft+P}px`,width:`${s}px`,top:`${E.offsetTop+t-12}px`}),de.firstElementChild.style.width=`${n}px`,Math.abs(de.scrollLeft-l)>=1&&(de.scrollLeft=l))))}function Po(){const e=es(B);if(!e||!de||de.style.display==="none")return e;const n=ot;Bt=!0;try{Z();const l=e.ownerDocument.createElement("canvas");return l.width=e.width,l.height=e.height,l.dataset.wmapPixelRatio=String(e.width/(e.clientWidth||e.width)),l.getContext("2d")?.drawImage(e,0,0),l}finally{Bt=!1,ot=n,Z()}}const ft=()=>!!(te.x||te.y),Mt=()=>a?.marks?.type==="scatter"?["x","y"]:["x"],Co=()=>{if(h.panel)return!1;const e=a?.marks?.type;return e==="scatter"||e==="line"||e==="control"||e==="histogram"||e==="probability"};function Eo(){!X||ft()||(Ht.x=[X.x.lo,X.x.hi],Ht.y=[X.y.lo,X.y.hi])}const kt=(e,n)=>{const l=e.reverse?1-n:n;return e.log?10**(Math.log10(e.lo)+l*(Math.log10(e.hi)-Math.log10(e.lo))):e.lo+l*(e.hi-e.lo)};function Ao(e,n,l){const u=r=>l?Math.log10(Math.max(r,Number.MIN_VALUE)):r,o=r=>l?10**r:r;let[c,s]=[u(e[0]),u(e[1])];if(!n)return[o(c),o(s)];const[t,x]=[u(n[0]),u(n[1])],m=s-c;if(!(m>0)||m>=(x-t)*.999)return;const p=(x-t)/1e3;if(m<p){const r=(c+s)/2;c=r-p/2,s=r+p/2}return c<t&&(s+=t-c,c=t),s>x&&(c-=s-x,s=x),[o(c),o(s)]}function It(e){if(te={},X)for(const n of Mt()){const l=e[n],u=l?Ao(l,Ht[n],X[n].log):void 0;u&&(te[n]=u)}j.style.display="none",ve=null,ke=-1,Z()}function nn(){ft()&&It({})}function Ft(e,n,l){if(!X)return;const u={};for(const o of Mt()){const c=X[o],t=kt(c,o==="x"?n:l),x=r=>c.log?Math.log10(r):r,m=r=>c.log?10**r:r,p=x(t);u[o]=[m(p-(p-x(c.lo))*e),m(p+(x(c.hi)-p)*e)]}It(u)}function wt(e,n){if(!X||!ft())return;const l={...te};for(const u of Mt()){const o=te[u];if(!o)continue;const c=u==="x"?e:n,s=X[u],t=p=>s.log?Math.log10(p):p,x=p=>s.log?10**p:p,m=c*(t(o[1])-t(o[0]))*(s.reverse?-1:1);l[u]=[x(t(o[0])+m),x(t(o[1])+m)]}It(l)}function Bo(){!gt||!E||(gt.style.display=ft()?"block":"none",Object.assign(gt.style,{top:`${E.offsetTop+w+4}px`,right:`${mt+8}px`}))}function Oo(){if(!E||!Co())return;const e=E;e.tabIndex=0,e.setAttribute("aria-label",`${B.dataset.wmapChartTitle??"Chart"}. Plus and minus zoom, the arrow keys move once zoomed, 0 or Escape resets.`);const n=N.createElement("button");n.type="button",n.textContent="Reset zoom",n.dataset.wmapZoomReset="1",n.setAttribute("aria-label","Reset zoom"),Object.assign(n.style,{...Ho("outlined"),position:"absolute",display:"none",zIndex:"3",fontSize:Ze.sub,padding:"1px 8px"}),Yt(n),n.addEventListener("click",()=>{nn(),e.focus({preventScroll:!0})}),I.appendChild(n),gt=n;const l=o=>{if(!X)return;const c=e.getBoundingClientRect();return{fx:(o.clientX-c.left-P)/X.plotW,fy:1-(o.clientY-c.top-w)/X.plotH}};e.addEventListener("wheel",o=>{const c=l(o);if(!c)return;const s=o.deltaMode===1?16:o.deltaMode===2?400:1;if(o.ctrlKey||o.metaKey){o.preventDefault();const p=o.deltaY*s,r=Math.abs(p)<40?.012:.002;Ft(Math.min(1.6,Math.max(.6,Math.exp(p*r))),c.fx,c.fy);return}const t=o.deltaX*s,x=o.deltaY*s,m=o.shiftKey?t||x:Math.abs(t)>Math.abs(x)?t:0;te.x&&m&&(o.preventDefault(),wt(m/X.plotW,0))},{passive:!1});let u=1;e.addEventListener("gesturestart",o=>{o.preventDefault(),u=1}),e.addEventListener("gesturechange",o=>{o.preventDefault();const c=o,s=l({clientX:c.clientX??0,clientY:c.clientY??0});!s||!c.scale||!(c.scale>0)||(Ft(Math.min(1.6,Math.max(.6,u/c.scale)),s.fx,s.fy),u=c.scale)}),e.addEventListener("dblclick",()=>nn()),e.addEventListener("mousedown",o=>{if(e.focus({preventScroll:!0}),!o.shiftKey||o.button!==0)return;const c=l(o);if(!c||!X)return;o.stopImmediatePropagation(),o.preventDefault();const s=e.getBoundingClientRect(),t=N.createElement("div");Object.assign(t.style,{position:"absolute",border:`1px dashed ${Qe.value}`,background:"rgba(80,120,200,0.12)",pointerEvents:"none",zIndex:"3"}),Yt(t),I.appendChild(t);const x=o.clientX-s.left,m=o.clientY-s.top,p=(f,d)=>{const k=Math.min(x,f),M=Math.min(m,d);Object.assign(t.style,{left:`${e.offsetLeft+k}px`,top:`${e.offsetTop+M}px`,width:`${Math.abs(f-x)}px`,height:`${Math.abs(d-m)}px`})},r=f=>p(f.clientX-s.left,f.clientY-s.top),i=f=>{N.removeEventListener("mousemove",r),N.removeEventListener("mouseup",i),t.remove();const d=l(f);if(!d||!X||Math.abs(f.clientX-o.clientX)<6)return;const k={},M=[kt(X.x,c.fx),kt(X.x,d.fx)];if(k.x=[_t(M),pe(M)],Mt().includes("y")&&Math.abs(f.clientY-o.clientY)>=6){const S=[kt(X.y,c.fy),kt(X.y,d.fy)];k.y=[_t(S),pe(S)]}else Mt().includes("y")&&(k.y=te.y);It(k)};N.addEventListener("mousemove",r),N.addEventListener("mouseup",i)},!0),e.addEventListener("keydown",o=>{if(!X)return;const c={fx:.5,fy:.5};if(o.key==="Escape"||o.key==="0"){ft()&&(o.preventDefault(),o.stopPropagation(),nn());return}if(o.key==="+"||o.key==="="){o.preventDefault(),Ft(.7,c.fx,c.fy);return}if(o.key==="-"||o.key==="_"){o.preventDefault(),Ft(1/.7,c.fx,c.fy);return}if(!ft())return;const s=.2;o.key==="ArrowLeft"?(o.preventDefault(),wt(-s,0)):o.key==="ArrowRight"?(o.preventDefault(),wt(s,0)):o.key==="ArrowUp"?(o.preventDefault(),wt(0,s)):o.key==="ArrowDown"&&(o.preventDefault(),wt(0,-s))})}function No(){const e=a,n=e?.marks;if(!e||!n||!e.y?.plainNumbers||!E||(n.type==="bar"||n.type==="box")&&e.spec.orientation==="horizontal"||n.type!=="bar"&&n.type!=="box"&&n.type!=="line"&&n.type!=="scatter"&&n.type!=="control")return at;const l=E.getContext("2d");if(!l)return at;l.font=`${ee(-1)}px system-ui, sans-serif`;let u=pe(qo(e,"y").map(Math.abs).concat(0));if(n.type==="bar"&&n.stack==="stack")for(let o=0;o<n.categories.length;o++)u=Math.max(u,n.values.reduce((c,s)=>c+(Number.isFinite(s[o])?s[o]:0),0));return Math.max(at,Math.ceil(l.measureText(an(u*1.1)).width+4+28))}function Z(){xn=void 0,on?.(),de&&(de.style.display="none"),Ot&&!io()&&(Ot.style.maxHeight=qn(B)?"":`${Ss}px`),le&&h.panel&&(le.style.display=qn(B)?"flex":"none"),P=No(),w=gn;const e=a?.marks?.type;e==="scatter"?fo():e==="control"?wo():e==="heatmap"?Mo():e==="goal"?So():e==="probability"?xo():e==="histogram"?ho():e==="box"||e==="bar"?mo():e==="line"&&bo(),Eo(),Bo(),vn()}function Ro(e){const n=a,l=h.waferLabel(e.item),u=e.die&&e.die.x!==void 0?`die (${e.die.x}, ${e.die.y})`:"",o=[l,u].filter(Boolean).join(" \xB7 "),c=(s,t)=>`${s.label}: ${nt(s,t)}`;return(o?`<strong>${G(o)}</strong><br>`:"")+G(c(n.x,e.x))+"<br>"+G(c(n.y,e.y))+(n.colorScale&&e.value!==void 0?`<br>${G(`${n.colorScale.label}: ${Ce(e.value,n.colorScale.unit)}`)}`:"")+(n.groups.length>1?`<br>${G(st(e.group))}`:"")+(h.onOpenWafer?`<br><em>click to ${G(vt())}</em>`:"")}function Tn(e){if(!Re||!X||!a?.x)return null;const n=E.getBoundingClientRect(),u=(e.clientX-n.left-P)/X.plotW;if(u<0||u>1)return null;const o=X.x.reverse?1-u:u,{edges:c,counts:s}=Re,t=c.length-1,x=Math.min(t-1,Math.max(0,Math.floor(o*t)));Te=x;const m=a.x,p=s.map((r,i)=>({g:i,n:r[x]})).filter(r=>r.n>0&&(W.size===0||W.has(r.g)));return`<strong>${G(`${nt(m,c[x])} to ${nt(m,c[x+1])}`)}</strong><br>`+(p.length?p.map(r=>{const i=a.spec.histNorm==="percent"?` (${Re.heights[r.g][x].toFixed(1)}% of ${a.groups.length>1?"its colour":"them"})`:"";return G(`${a.groups.length>1?`${st(r.g)}: `:""}${xt(r.n,a.level)}${i}`)}).join("<br>"):"none")}let on;function Io(e){const n=N.createElement("div");n.dataset.wmapPlotColorbar="1",Object.assign(n.style,{display:"flex",alignItems:"center",gap:se.md,marginTop:se.md,marginBottom:se.xl,fontSize:Ze.body,color:Qe.label});const l=N.createElement("canvas");l.dataset.wmapKey="1",l.width=200,l.height=10,Object.assign(l.style,{width:"200px",height:"10px",borderRadius:Xn.control,flex:"0 0 auto"});const u=l.getContext("2d"),o=()=>{const m=Lt(a?.spec.colorGradient,a?.spec.colorReverse,e.diverging,e.rating,un(B),e.counts,h.readerColors);if(u)for(let p=0;p<200;p++)u.fillStyle=m(p/199),u.fillRect(p,0,1,10)};o(),on=o;const c=so(e,a?.marks?.type==="heatmap"),s=N.createElement("span");s.textContent=c.lo;const t=N.createElement("span");t.textContent=c.hi;const x=N.createElement("span");if(x.textContent=e.label,x.style.color=Qe.text,c.mid){const m=N.createElement("span");Object.assign(m.style,{position:"relative",display:"inline-block",lineHeight:jt.none});const p=N.createElement("span");return p.textContent=c.mid,Object.assign(p.style,{position:"absolute",left:"50%",top:"100%",transform:"translateX(-50%)",fontSize:Ze.body,lineHeight:jt.tight,whiteSpace:"nowrap"}),m.append(l,p),n.style.marginBottom=se.xxl,n.append(x,s,m,t),n}if(e.rating){const m=N.createElement("span");Object.assign(m.style,{position:"relative",display:"inline-block",lineHeight:jt.none});for(const p of Jn()){const r=N.createElement("span");r.textContent=p.text,Object.assign(r.style,{position:"absolute",left:`${p.at*100}%`,top:"100%",transform:"translateX(-50%)",fontSize:Ze.body,lineHeight:jt.tight,whiteSpace:"nowrap"}),m.appendChild(r)}return m.prepend(l),n.style.marginBottom=se.xxl,n.append(x,s,m,t),n}return n.append(x,s,l,t),n}const Tt=(e,n,l)=>n.map(u=>{const{item:o,die:c,dies:s}=e(u);return{x:0,y:0,group:l,item:o,die:c,...s?{dies:s}:{}}});function Sn(){rt?.destroy(),rt=void 0,I.innerHTML="",E=void 0,le=void 0,ie=void 0,pt=[],ve=null,Te=-1,fe=[],X=void 0,re=void 0,ue=null,de=void 0,ot=0,te={},gt=void 0,Ot=void 0,qe=void 0,Se=null,Me=[],ke=-1,je=tt,Vt=new Map,W.clear(),xe.clear(),on=void 0;for(const m of ae)m.destroy();ae=[],Et?.(),Et=void 0,I.style.overflowY="hidden",delete B.dataset.wmapPlotPanelsOwner,delete B.dataset.wmapPanelsHover,Ee(Po);const e=a,n=!!e?.facets&&!h.panel;if(B.style.flex=n?"0 0 auto":"1 1 0px",B.style.gridColumn=n?"1 / -1":"",!e)return;if(q.textContent=h.panel?h.panel.title:h.titleNote?`${Dn(e)} \xB7 ${h.titleNote}`:Dn(e),B.dataset.wmapChartTitle=q.textContent,e.issues.length||!e.marks){for(const m of e.issues)Un(I,m);return}const l=N.createElement("div");Object.assign(l.style,{color:Qe.label,fontSize:Ze.body,marginBottom:se.xs});const u=vt(),o=e.marks.type==="scatter"?(h.onOpenWafer?` \xB7 click a point to ${u}`:"")+(h.onSelectPoints?` \xB7 drag to select ${bt(e.level)}`:""):e.marks.type==="box"||e.marks.type==="bar"?(h.onOpenWafer&&e.marks.categoryItems?` \xB7 click a ${e.marks.type} to ${u}`:h.onSelectPoints?` \xB7 click or right-click to ${h.selectActionLabel??"chart or tabulate what it counts"}`:"")+(e.marks.type==="box"?" \xB7 box: quartiles; whiskers: minimum and maximum":""):e.marks.type==="histogram"&&h.onSelectPoints?` \xB7 click or right-click a bar to chart or tabulate its ${bt(e.level)}`:e.marks.type==="heatmap"&&h.onSelectPoints?` \xB7 click or right-click a cell to ${h.selectActionLabel??`chart or tabulate its ${bt(e.level)}`}`:e.marks.type==="probability"?(h.onOpenWafer?` \xB7 click a point to ${u}`:"")+(h.onSelectPoints?` \xB7 drag to select ${bt(e.level)}`:""):e.marks.type==="line"&&h.onSelectPoints?` \xB7 click a point to ${h.selectActionLabel??"chart or tabulate what it averages"} \xB7 drag across the chart to select ${h.selectRangeLabel??"a run of points"}`:"";l.textContent=h.panel?[fn(e.population.wafers,Pe().row),Uo(Pe())?`${e.population.dies.toLocaleString("en-GB")} dies`:Pe().item?fn(e.population.dies,Pe().item):""].filter(Boolean).join(" \xB7 "):zn(e)+(e.facets?"":o),h.panel||ts(l,_n(e)),Yt(l),ie=N.createElement("div"),ie.style.display="flow-root",I.appendChild(ie),h.footnoteInAbout&&!h.panel?we({text:`${eo(e.spec).text} ${l.textContent}`,noun:"chart"}):h.chrome?.footnote!==!1&&ie.appendChild(l);const c=new Map,s=e.marks?.type==="scatter"?e.marks.fits??[]:[],t=e.groups.length>1&&!e.colorScale&&s.length===(e.fitNotes?.length??0);t&&s.forEach((m,p)=>c.set(m.group,e.fitNotes[p]));for(const m of t?[]:e.fitNotes??[]){const p=N.createElement("div");p.dataset.wmapPlotFit="1",p.textContent=m,Object.assign(p.style,{color:Qe.text,fontSize:Ze.body,marginBottom:se.xxs,fontVariantNumeric:"tabular-nums"}),ie.appendChild(p)}for(const m of e.notes){const p=N.createElement("div");Yt(p),p.textContent=m,Object.assign(p.style,{color:Qe.warnText,fontSize:Ze.body,marginBottom:se.xs}),ie.appendChild(p)}if(e.plotted===0){Un(I,"Nothing to plot: no mark has every value this chart needs.");return}if(e.groups.length>1&&(le=N.createElement("div"),le.dataset.wmapPlotLegend="1",Object.assign(le.style,{display:h.panel?"none":"flex",flexWrap:"wrap",gap:se.sm,marginTop:se.md,marginBottom:se.xl,overflowY:"auto"}),Ot=le,e.facets&&Object.assign(le.style,{position:"sticky",top:"0",zIndex:"2",background:Qe.menuBg,paddingBottom:se.sm,marginBottom:se.md}),e.groups.forEach((m,p)=>{const r=as(m||"(none)",oe(p),N),i=c.get(p),f=h.readerColors?.onEditBinColor&&a?.colorBins?" \xB7 right-click to change its colour":"";jn(r.el,B,j,(i?`${i} \u2014 click to filter`:`${m||"(none)"} \u2014 click to filter`)+f),i&&r.el.setAttribute("aria-description",i),r.el.addEventListener("click",()=>{if(W.has(p)?W.delete(p):W.add(p),pt.forEach((M,S)=>M.setState({selected:W.has(S),dimmed:W.size>0&&!W.has(S)})),ae.length)for(const M of ae)M.setActiveGroups(W);else Z()});const d=h.readerColors?.onEditBinColor,k=a?.colorBins&&d?Wn(m,Pe()):void 0;if(d&&k!==void 0&&a?.colorBins){const M=a.colorBins,S=b=>{import("../drilldown.js").then(({openChangeColourMenu:T})=>{r.el.isConnected&&T(b,r.el,()=>d(k,M))})};r.el.addEventListener("contextmenu",b=>{b.preventDefault(),b.stopPropagation(),S({x:b.clientX,y:b.clientY})}),r.el.addEventListener("keydown",b=>{if(b.key!=="ContextMenu"&&!(b.key==="F10"&&b.shiftKey))return;b.preventDefault();const T=r.el.getBoundingClientRect();S({x:T.left+T.width/2,y:T.bottom})}),r.el.setAttribute("aria-description",`${i?`${i}. `:""}Right-click to change its colour`)}pt.push(r),le.appendChild(r.el)}),pt.forEach((m,p)=>m.setState({selected:W.has(p),dimmed:W.size>0&&!W.has(p)})),h.chrome?.legend!==!1&&ie.appendChild(le)),e.colorScale&&!h.panel&&(le=Io(e.colorScale),h.chrome?.legend!==!1&&ie.appendChild(le)),e.shortfallFrom!==void 0&&!h.panel){le=N.createElement("div"),le.dataset.wmapPlotShortfallKey="1",Object.assign(le.style,{display:"flex",flexWrap:"wrap",gap:se.md,marginTop:se.md,marginBottom:se.xl,fontSize:Ze.body,color:Qe.text});const m=un(B),p=`${e.shortfallFrom.toFixed(1)}%`;for(const[r,i]of[[1,`1 to 2 points below ${p}`],[2,"2 to 4 points below"],[3,"4 or more points below"]]){const f=N.createElement("span");Object.assign(f.style,{display:"inline-flex",alignItems:"center",gap:se.xs});const d=N.createElement("span");Object.assign(d.style,{width:"12px",height:"12px",borderRadius:Xn.control,background:Ut(r,m,h.readerColors?.dataColors)}),f.append(d,N.createTextNode(i)),le.appendChild(f)}jn(le,B,j,`${p} is the yield of all the bars together: passing dies over judged dies.`),h.chrome?.legend!==!1&&ie.appendChild(le)}if(e.facets){const m=N.createElement("div");m.dataset.wmapPlotPanels="1",m.style.isolation="isolate",Object.assign(m.style,{display:"grid",gap:se.md});const p=()=>{m.style.gridTemplateColumns=De?`repeat(${De}, minmax(0, 1fr))`:`repeat(auto-fill, minmax(${Cs}px, 1fr))`};p();const r=rs("Columns:",[{value:"auto",label:"Auto"},...[1,2,3,4,5].map(d=>({value:String(d),label:String(d)}))],De?String(De):"auto",d=>{De=d==="auto"?void 0:Number(d),p()},{hook:"panel-columns",maxWidth:"90px",ownerDocument:N,hint:"The most panels that sit side by side; while the pointer is over this chart, the keys 1 to 5 set it and 0 returns to Auto"});Object.assign(r.style,{justifyContent:"flex-end",marginBottom:se.sm});const i=r.querySelector("button");I.append(r,m),I.style.overflowY="auto",B.dataset.wmapPlotPanelsOwner="1",At&&(B.dataset.wmapPanelsHover="1");const f=d=>{if(!At||d.ctrlKey||d.metaKey||d.altKey||d.shiftKey||d.defaultPrevented||!/^[0-5]$/.test(d.key))return;const k=d.target;typeof k?.closest=="function"&&k.closest('input, textarea, select, [contenteditable="true"], [role="menu"]')||(d.preventDefault(),De=d.key==="0"?void 0:Number(d.key),p(),i&&(i.value=De?String(De):"auto"))};N.addEventListener("keydown",f),Et=()=>N.removeEventListener("keydown",f);for(const d of e.facets){const k=renderPlotChart({...h,panel:{title:d.label}});m.appendChild(k.card),k.setPlot(d.plot),ae.push(k)}Ee(()=>Es(m));return}E=N.createElement("canvas"),E.style.display="block",E.style.cursor=e.marks.type==="scatter"||e.marks.type==="probability"?"crosshair":"default",I.appendChild(E);const x=h.onWaferMenu||h.onSelectPoints?(m,p)=>{!m.die&&h.onWaferMenu?h.onWaferMenu(m.item,Xt(e.spec),p):m.die&&h.onSelectPoints&&(p.preventDefault(),h.onSelectPoints([m],{x:p.clientX,y:p.clientY},E))}:void 0;if(Oo(),e.marks.type==="scatter"){const m=e.marks,p=!!h.onSelectPoints;rt=pn({card:B,canvas:E,tooltip:j,drawn:()=>fe,describe:Ro,clickable:()=>!!h.onOpenWafer,onOpen:r=>h.onOpenWafer?.(r.item,...Kt(e.spec)),onContextMenu:x,onHover:r=>{ve=r,Z()},select:p?{pick:({x0:r,y0:i,x1:f,y1:d})=>X?(W.size===0?m.points:m.points.filter(M=>W.has(M.group))).filter(M=>{const S=P+X.x.frac(M.x)*X.plotW,b=w+(1-X.y.frac(M.y))*X.plotH;return S>=r&&S<=f&&b>=i&&b<=d}):[],onPicked:(r,i)=>{xe.clear();for(const f of r)xe.add(f);Z(),r.length>0&&h.onSelectPoints(r,i,E)},onClear:()=>{xe.clear(),Z()},hasSelection:()=>xe.size>0}:void 0})}else if(e.marks.type==="control"||e.marks.type==="goal"){const m=e.marks.type==="control";rt=pn({card:B,canvas:E,tooltip:j,drawn:()=>fe,describe:m?To:$o,clickable:()=>m&&!!h.onOpenWafer,onOpen:p=>{m&&h.onOpenWafer?.(p.item,...Kt(e.spec))},onContextMenu:m?x:void 0,onHover:p=>{ve=p,Z()}})}else if(e.marks.type==="probability"){const m=e.marks,p=e.spec.probabilityAxis==="linear";rt=pn({card:B,canvas:E,tooltip:j,drawn:()=>fe,describe:vo,clickable:()=>!!h.onOpenWafer,onOpen:r=>h.onOpenWafer?.(r.item,...Kt(e.spec)),onContextMenu:x,onHover:r=>{ve=r,Z()},select:h.onSelectPoints?{pick:({x0:r,y0:i,x1:f,y1:d})=>{if(!X)return[];const k=[];return m.values.forEach((M,S)=>{W.size>0&&!W.has(S)||M.forEach((b,T)=>{const y=$t(T,M.length),g=P+X.x.frac(b)*X.plotW,v=w+(1-X.y.frac(p?y:Rn(y)))*X.plotH;if(g<r||g>f||v<i||v>d)return;const{item:R,die:L}=m.unit(m.units[S][T]);k.push({x:b,y,group:S,item:R,die:L})})}),k},onPicked:(r,i)=>{xe.clear();for(const f of r)xe.add(f);Z(),r.length>0&&h.onSelectPoints(r,i,E)},onClear:()=>{xe.clear(),Z()},hasSelection:()=>xe.size>0}:void 0})}else if(e.marks.type==="histogram"){uo(),E.addEventListener("mousemove",p=>{const r=Tn(p);if(!r){j.style.display="none",Te>=0&&(Te=-1,Z());return}j.innerHTML=r,j.style.display="block",Gt(j,B,p.clientX,p.clientY),Z()}),E.addEventListener("mouseleave",()=>{j.style.display="none",Te>=0&&(Te=-1,Z())});const m=e.marks;if(h.onSelectPoints){E.style.cursor="pointer";const p=r=>{if(!Re||Tn(r)===null)return!1;const i=Te,{edges:f}=Re,d=X?.x.log,k=d?Math.log10(f[0]):f[0],M=d?Math.log10(f[f.length-1]):f[f.length-1],S=f.length-1,b=[];return m.values.forEach((T,y)=>{if(W.size>0&&!W.has(y))return;const g=[];T.forEach((v,R)=>{const L=d?v>0?Math.log10(v):NaN:v;!Number.isFinite(L)||L<k||L>M||Math.min(S-1,Math.floor((L-k)/(M-k)*S))===i&&g.push(m.units[y][R])});for(const v of Tt(m.unit,g,y))b.push(v)}),b.length===0?!1:(j.style.display="none",h.onSelectPoints(b,{x:r.clientX,y:r.clientY},E,{range:{lo:f[i],hi:f[i+1]},...W.size===1?{group:e.groups[[...W][0]]}:{}}),!0)};E.addEventListener("click",r=>{p(r)}),E.addEventListener("contextmenu",r=>{p(r)&&r.preventDefault()})}}else if(e.marks.type==="heatmap"){const m=e.marks;E.addEventListener("mousemove",r=>{const i=wn(r);if(E.style.cursor=i&&h.onSelectPoints&&m.cellUnits[i.r][i.c].length?"pointer":"default",!i){j.style.display="none",Se&&(Se=null,Z());return}j.innerHTML=ko(i),j.style.display="block",Gt(j,B,r.clientX,r.clientY),(!Se||Se.r!==i.r||Se.c!==i.c)&&(Se=i,Z())}),E.addEventListener("mouseleave",()=>{j.style.display="none",Se&&(Se=null,Z())});const p=r=>{const i=wn(r);if(!i||!h.onSelectPoints)return!1;const f=m.cellUnits[i.r][i.c];return f.length?(j.style.display="none",h.onSelectPoints(Tt(m.unit,f,0),{x:r.clientX,y:r.clientY},E,{cell:{row:m.rows[i.r],column:m.cols[i.c]}}),!0):!1};E.addEventListener("click",r=>{p(r)}),E.addEventListener("contextmenu",r=>{p(r)&&r.preventDefault()})}else if(e.marks.type==="box"||e.marks.type==="bar"){const m=e.marks;{const r=e.spec.orientation==="horizontal",i=N.createElement("div");i.dataset.wmapRowScroll="1",i.tabIndex=0,i.setAttribute("aria-label",`Scroll the ${m.categories.length} ${r?"rows":"categories"}`),Object.assign(i.style,r?{position:"absolute",display:"none",width:"12px",overflowY:"auto",overflowX:"hidden",zIndex:"1"}:{position:"absolute",display:"none",height:"12px",overflowX:"auto",overflowY:"hidden",zIndex:"1"});const f=N.createElement("div");r?f.style.width="1px":f.style.height="1px",i.appendChild(f),i.addEventListener("scroll",()=>{const d=r?i.scrollTop:i.scrollLeft;Math.abs(d-ot)<1||(ot=d,j.style.display="none",Z())}),E.addEventListener("wheel",d=>{if(i.style.display==="none")return;const k=d.deltaMode===1?16:1;if(r){const M=i.scrollTop;i.scrollTop+=d.deltaY*k,i.scrollTop!==M&&d.preventDefault()}else{const M=d.deltaX||(d.shiftKey?d.deltaY:0);if(!M)return;const S=i.scrollLeft;i.scrollLeft+=M*k,i.scrollLeft!==S&&d.preventDefault()}},{passive:!1}),I.appendChild(i),de=i}E.addEventListener("mousemove",r=>{const i=en(r);if(E.style.cursor=i&&(m.categoryItems&&h.onOpenWafer||h.onSelectPoints&&m.cellUnits[i.g][i.c].length>0)?"pointer":"default",!i){j.style.display="none",ue&&(ue=null,Z());return}j.innerHTML=yo(i),j.style.display="block",Gt(j,B,r.clientX,r.clientY),(!ue||ue.g!==i.g||ue.c!==i.c)&&(ue=i,Z())}),E.addEventListener("mouseleave",()=>{j.style.display="none",ue&&(ue=null,Z())});const p=(r,i)=>{const f=m.cellUnits[i.g][i.c];if(f.length===0||!h.onSelectPoints)return!1;j.style.display="none";const d=e.spec.fields?.y,k=d&&"builtin"in d?d.builtin==="passDies"?"pass":d.builtin==="failDies"?"fail":void 0:void 0,M=[`${e.x?.label?`${e.x.label} `:""}${m.categories[i.c]}`,...e.groups.length>1&&e.colorLabel&&!e.colorIsX?[`${e.colorLabel} ${e.groups[i.g]}`]:[]].join(" and ");return h.onSelectPoints(Tt(m.unit,f,i.g),{x:r.clientX,y:r.clientY},E,{category:m.categories[i.c],...e.groups.length>1?{group:e.groups[i.g]}:{},...po(m.categories[i.c]),what:M,...k?{counts:k}:{}}),!0};E.addEventListener("contextmenu",r=>{const i=en(r);if(!i)return;const f=m.categoryItems?.[i.c];f!==void 0&&f>=0&&h.onWaferMenu?(j.style.display="none",h.onWaferMenu(f,Xt(e.spec),r)):p(r,i)&&r.preventDefault()}),E.addEventListener("click",r=>{const i=en(r);if(!i)return;const f=m.categoryItems?.[i.c];if(f!==void 0&&f>=0&&h.onOpenWafer){h.onOpenWafer(f,...Kt(e.spec));return}p(r,i)})}else if(e.marks.type==="line"){E.addEventListener("mousemove",r=>{const i=tn(r);if(!i){j.style.display="none",Z();return}j.innerHTML=i,j.style.display="block",Gt(j,B,r.clientX,r.clientY),Z()}),E.addEventListener("mouseleave",()=>{j.style.display="none",ke>=0&&(ke=-1,Z())});const m=e.marks,p=()=>m.cellUnits.flatMap((r,i)=>W.size>0&&!W.has(i)?[]:Tt(m.unit,r[ke]??[],i));if((h.onWaferMenu||h.onSelectPoints)&&E.addEventListener("contextmenu",r=>{if(tn(r)===null||ke<0)return;const i=kn(ke);if(i!==void 0&&h.onWaferMenu)j.style.display="none",h.onWaferMenu(i,Xt(e.spec),r);else if(h.onSelectPoints){const f=p();f.length>0&&(r.preventDefault(),j.style.display="none",h.onSelectPoints(f,{x:r.clientX,y:r.clientY},E))}}),h.onSelectPoints){E.style.cursor="pointer";let r=!1;E.addEventListener("mousedown",i=>{if(i.button!==0)return;r=!1;const f=E.getBoundingClientRect(),d=i.clientX-f.left,k=M=>{N.removeEventListener("mouseup",k);const S=M.clientX-f.left;if(Math.abs(S-d)<4)return;r=!0;const[b,T]=d<S?[d,S]:[S,d],y=Me.map((v,R)=>v>=b&&v<=T?R:-1).filter(v=>v>=0),g=m.cellUnits.flatMap((v,R)=>W.size>0&&!W.has(R)?[]:y.flatMap(L=>Tt(m.unit,v[L]??[],R)));g.length>0&&(j.style.display="none",h.onSelectPoints(g,{x:M.clientX,y:M.clientY},E))};N.addEventListener("mouseup",k)}),E.addEventListener("click",i=>{if(r){r=!1;return}if(tn(i)===null||ke<0)return;const f=p();f.length>0&&(j.style.display="none",h.onSelectPoints(f,{x:i.clientX,y:i.clientY},E))})}}Z()}J(()=>{const e=a;if(!e||!e.marks)return;const n=Lt(e.spec.colorGradient,e.spec.colorReverse,e.colorScale?.diverging,e.colorScale?.rating,un(B),e.colorScale?.counts,h.readerColors);return{caption:[zn(e),...e.fitNotes??[],...e.notes,...ms(_n(e))],legend:e.groups.length>1?e.groups.map((l,u)=>({label:l||"(none)",color:oe(u)})):void 0,colorbar:e.colorScale?{label:e.colorScale.label,...so(e.colorScale,e.marks.type==="heatmap"),ticks:e.colorScale.rating?Jn():void 0,color:n}:void 0}});const Fo=ns(B,()=>Z());let $n=!1;return os(B,()=>{$n||!a||(h.getBinColors&&(h.binColors=h.getBinColors()),Sn())}),{card:B,actions:V,setPlot(e){a=e,h.panel||Ae(e.spec.id),we(eo(e.spec)),Sn()},setMenuRows(e){Le=e},setActiveGroups(e){W.clear();for(const n of e)W.add(n);pt.forEach((n,l)=>n.setState({selected:W.has(l),dimmed:W.size>0&&!W.has(l)})),Z()},destroy(){$n=!0,Et?.(),Fo.disconnect(),rt?.destroy();for(const e of ae)e.destroy()}}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RegionYieldDatum } from '../../stats/regions.js';
|
|
2
|
+
import { type ReaderColors } from './divergingScale.js';
|
|
2
3
|
import { type SaveImageHandler } from './chartShell.js';
|
|
3
4
|
export type RegionYieldMode = 'ring' | 'quadrant' | 'reticleCell';
|
|
4
5
|
export interface RegionYieldDiagramOptions {
|
|
@@ -14,6 +15,8 @@ export interface RegionYieldDiagramOptions {
|
|
|
14
15
|
/** Click a region: called with it and the click, so the host can pick out the dies it counts and open a menu there. */
|
|
15
16
|
onSelectRegion?: (row: RegionYieldDatum, e: MouseEvent) => void;
|
|
16
17
|
onSaveImage?: SaveImageHandler;
|
|
18
|
+
/** The reader's colours: the panel draws from their data colour scheme. */
|
|
19
|
+
readerColors?: ReaderColors;
|
|
17
20
|
/** Document to build this panel's DOM into. Default `document` — pass the
|
|
18
21
|
* host's own `ownerDocument` when the container might live in a
|
|
19
22
|
* different document (e.g. a gallery card detached into its own popup
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseRegionKey as
|
|
1
|
+
import{parseRegionKey as N,parseReticleCellKey as _}from"../../stats/regions.js";import{yieldColor as Q}from"./divergingScale.js";import{fontPx as Y}from"../toolbar.js";import{escHtml as Z}from"../../core/utils.js";import{makeTooltip as U,positionChartTooltip as z,cardShell as J,resolveChartCanvasColors as V,observeResize as x,onRepaint as ee,growCardToFitContent as te,setChartGrow as ne,isExpandedCard as oe,bodyRoom as le,renderEmptyState as re,prepareCanvas as ie}from"./chartShell.js";import{cardAbout as ae,cardKindId as se}from"./cardAbout.js";const B=320,ce=220,O={SE:[0,Math.PI/2],SW:[Math.PI/2,Math.PI],NW:[Math.PI,1.5*Math.PI],NE:[1.5*Math.PI,2*Math.PI]};function X(e,i,o,m,M,r){e.beginPath(),e.moveTo(i+r,o),e.arcTo(i+m,o,i+m,o+M,r),e.arcTo(i+m,o+M,i,o+M,r),e.arcTo(i,o+M,i,o,r),e.arcTo(i,o,i+m,o,r),e.closePath()}function q(e,i,o,m,M,r){e.font=`${Y(-1)}px system-ui, sans-serif`;const P=e.measureText(m).width;e.font="700 11px system-ui, sans-serif";const W=e.measureText(M).width,$=Math.max(P,W)+12,k=30;e.fillStyle=r.bg,X(e,i-$/2,o-k/2,$,k,4),e.fill(),e.strokeStyle=r.border,e.lineWidth=1,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=r.textMuted,e.font=`${Y(-1)}px system-ui, sans-serif`,e.fillText(m,i,o-7),e.fillStyle=r.text,e.font="700 11px system-ui, sans-serif",e.fillText(M,i,o+7)}function de(e,i,o,m,M){e.font="700 11px system-ui, sans-serif";const r=e.measureText(m).width+8;e.fillStyle=M.bg,X(e,i-r/2,o-8,r,16,3),e.fill(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=M.text,e.fillText(m,i,o+.5)}export function renderRegionYieldDiagram(e){const{mode:i,rows:o,onSaveImage:m}=e,M=e.title??(i==="ring"?"Ring yield":i==="quadrant"?"Quadrant yield":"Reticle cell yield"),{card:r,body:P,setAbout:W,setCardId:$}=J(M,m,e.ownerDocument),k=i==="ring"?"ring-yield":i==="quadrant"?"quadrant-yield":"reticle-yield";$(se(k)),W(ae(k)),ne(r,"square");const A=o.length>0;if(!A)return re(P,"No bin data available for regional yield."),{card:r,hasData:A,destroy:()=>{}};Object.assign(P.style,{display:"flex",justifyContent:"center",alignItems:"center"});const b=r.ownerDocument.createElement("canvas");Object.assign(b.style,{display:"block",flex:"none"}),P.appendChild(b);let w={cx:0,cy:0,R:0};const D=new Map;let S=0,p=0;if(i==="reticleCell"){for(const l of o){const n=_(l.key);n&&(D.set(`${n.column},${n.row}`,l),S=Math.max(S,n.column+1),p=Math.max(p,n.row+1))}S=Math.max(S,e.grid?.width??0),p=Math.max(p,e.grid?.height??0)}let I={x0:0,y0:0,side:0};const T=U(r);function j(l,n,c,t){const a=Math.max(4,Math.floor(Math.min((n-40)/S,(n-40)/p))),f=Math.round((n-a*S)/2),s=Math.round((n-a*p)/2);I={x0:f,y0:s,side:a};for(let R=0;R<p;R++)for(let u=0;u<S;u++){const h=f+u*a,d=s+(p-1-R)*a,g=D.get(`${u},${R}`);l.fillStyle=g?t(g.yieldPercent):c.bg,l.fillRect(h,d,a,a),l.strokeStyle=c.border,l.lineWidth=1,l.strokeRect(h+.5,d+.5,a-1,a-1),!(!g||a<30)&&(a>=54?q(l,h+a/2,d+a/2,`(${u}, ${R})`,`${g.yieldPercent.toFixed(1)}%`,c):de(l,h+a/2,d+a/2,`${g.yieldPercent.toFixed(0)}%`,c))}l.strokeStyle=c.text,l.lineWidth=1.5,l.strokeRect(f+.5,s+.5,a*S-1,a*p-1)}function F(){const l=Math.max(ce,Math.min(P.clientWidth||B,B));te(r,P,l);const n=oe(r)?Math.max(l,Math.floor(Math.min(P.clientWidth,le(r,P,b)))):l,c=ie(b,r,n,n);if(!c)return;const{ctx:t}=c,y=V(r),a=h=>Q(h,{card:y.bg,text:y.text},e.readerColors?.dataColors);if(i==="reticleCell"){j(t,n,y,a);return}const f=n/2,s=n/2,u=n/2-34;if(w={cx:f,cy:s,R:u},i==="ring"){const h=o.length;for(let d=0;d<h;d++){const g=d/h*u,C=(d+1)/h*u;t.beginPath(),t.arc(f,s,C,0,2*Math.PI),t.arc(f,s,g,0,2*Math.PI,!0),t.closePath(),t.fillStyle=a(o[d].yieldPercent),t.fill(),t.strokeStyle=y.border,t.lineWidth=1,t.stroke()}t.beginPath(),t.arc(f,s,u,0,2*Math.PI),t.strokeStyle=y.text,t.lineWidth=1.5,t.stroke();for(let d=0;d<h;d++){const g=(d+.5)/h*u,C=-Math.PI/2+d/h*2*Math.PI,v=f+Math.cos(C)*g,E=s+Math.sin(C)*g;q(t,v,E,o[d].label,`${o[d].yieldPercent.toFixed(1)}%`,y)}}else{for(const h of o){const d=N(h.key).quadrant,g=d?O[d]:void 0;if(!g)continue;const[C,v]=g;t.beginPath(),t.moveTo(f,s),t.arc(f,s,u,C,v),t.closePath(),t.fillStyle=a(h.yieldPercent),t.fill(),t.strokeStyle=y.border,t.lineWidth=1,t.stroke();const E=(C+v)/2,H=f+Math.cos(E)*u*.6,K=s+Math.sin(E)*u*.6;q(t,H,K,h.label,`${h.yieldPercent.toFixed(1)}%`,y)}t.beginPath(),t.arc(f,s,u,0,2*Math.PI),t.strokeStyle=y.text,t.lineWidth=1.5,t.stroke()}}function L(l,n){if(i==="reticleCell"){const f=Math.floor((l-I.x0)/I.side),s=Math.floor((n-I.y0)/I.side);return I.side<=0||f<0||f>=S||s<0||s>=p?null:D.get(`${f},${p-1-s}`)??null}const c=l-w.cx,t=n-w.cy,y=Math.hypot(c,t);if(!(y<=w.R))return null;if(i==="ring")return o[Math.min(o.length-1,Math.floor(y/w.R*o.length))]??null;const a=(Math.atan2(t,c)+2*Math.PI)%(2*Math.PI);return o.find(f=>{const s=O[N(f.key).quadrant??""];return!!s&&a>=s[0]&&a<s[1]})??null}if(b.addEventListener("mousemove",l=>{const n=b.getBoundingClientRect(),c=L(l.clientX-n.left,l.clientY-n.top);if(!c){T.style.display="none";return}T.innerHTML=`<strong>${Z(c.label)}</strong><br>${c.yieldPercent.toFixed(1)}% yield (${c.passDies} of ${c.n} dies)`+(e.onSelectRegion?"<br><em>click to chart or tabulate these dies</em>":""),T.style.display="block",z(T,r,l.clientX,l.clientY)}),b.addEventListener("mouseleave",()=>{T.style.display="none"}),e.onSelectRegion){b.style.cursor="pointer";const l=n=>{const c=b.getBoundingClientRect(),t=L(n.clientX-c.left,n.clientY-c.top);return t?(e.onSelectRegion(t,n),!0):!1};b.addEventListener("click",n=>{l(n)}),b.addEventListener("contextmenu",n=>{l(n)&&n.preventDefault()})}const G=x(r,()=>F());return ee(r,()=>F()),F(),{card:r,hasData:A,destroy:()=>G.disconnect()}}
|