@wafertools/wafermap 0.35.1 → 0.36.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.
Files changed (73) hide show
  1. package/AGENTS.md +11 -8
  2. package/CHANGELOG.md +117 -0
  3. package/README.md +3 -3
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  8. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  9. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  10. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  11. package/dist/packages/canvas-adapter/index.js +1 -1
  12. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  13. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  14. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  15. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
  17. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  18. package/dist/packages/canvas-adapter/summaryPanel.d.ts +7 -4
  19. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  20. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  21. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  22. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  23. package/dist/packages/canvas-adapter/toolbar.d.ts +0 -6
  24. package/dist/packages/canvas-adapter/toolbar.js +1 -1
  25. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  26. package/dist/packages/canvas-adapter/userGuideHtml.js +10 -3
  27. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  28. package/dist/packages/canvas-adapter/version.js +1 -1
  29. package/dist/packages/canvas-adapter/warnings.js +1 -1
  30. package/dist/packages/core/aggregates.d.ts +10 -0
  31. package/dist/packages/core/aggregates.js +1 -1
  32. package/dist/packages/core/dieTable.d.ts +5 -0
  33. package/dist/packages/core/dieTable.js +1 -1
  34. package/dist/packages/core/wafer.d.ts +10 -1
  35. package/dist/packages/core/wafer.js +1 -1
  36. package/dist/packages/renderer/buildView.d.ts +5 -0
  37. package/dist/packages/renderer/buildView.js +1 -1
  38. package/dist/packages/renderer/buildWaferMap.d.ts +19 -4
  39. package/dist/packages/renderer/buildWaferMap.js +1 -1
  40. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  41. package/dist/packages/renderer/fmt.d.ts +10 -0
  42. package/dist/packages/renderer/fmt.js +1 -1
  43. package/dist/packages/renderer/index.d.ts +1 -0
  44. package/dist/packages/renderer/index.js +1 -1
  45. package/dist/packages/renderer/valueFilter.d.ts +1 -1
  46. package/dist/packages/renderer/valueFilter.js +1 -1
  47. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  48. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  49. package/dist/packages/stats/analyzeWaferMap.d.ts +18 -1
  50. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  51. package/dist/packages/stats/clusterDetection.js +1 -1
  52. package/dist/packages/stats/connectedComponents.js +1 -1
  53. package/dist/packages/stats/correlation.d.ts +36 -4
  54. package/dist/packages/stats/correlation.js +1 -1
  55. package/dist/packages/stats/filterFindings.d.ts +1 -1
  56. package/dist/packages/stats/filterFindings.js +1 -1
  57. package/dist/packages/stats/findingText.d.ts +8 -0
  58. package/dist/packages/stats/findingText.js +2 -2
  59. package/dist/packages/stats/index.d.ts +2 -1
  60. package/dist/packages/stats/index.js +1 -1
  61. package/dist/packages/stats/lotDrift.js +1 -1
  62. package/dist/packages/stats/mergeTestDefs.js +1 -1
  63. package/dist/packages/stats/plotData.js +1 -1
  64. package/dist/packages/stats/renderSummaryReport.js +27 -27
  65. package/dist/packages/stats/reportHtml.d.ts +5 -12
  66. package/dist/packages/stats/reportHtml.js +96 -34
  67. package/dist/packages/stats/synthesis.d.ts +4 -0
  68. package/dist/packages/stats/synthesis.js +1 -1
  69. package/dist/packages/stats/testPassRate.js +1 -1
  70. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  71. package/dist/packages/stats/testValueBudget.js +1 -0
  72. package/dist/packages/stats/types.d.ts +77 -22
  73. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -176,15 +176,18 @@ it is handed, because it has no way to know which tests anyone will look at.
176
176
  parse and build only the chosen tests. A scan that reads test identity without
177
177
  reading every value is dramatically cheaper than a full load, and it is what makes
178
178
  a large file feel instant.
179
- - **Above 250 discovered tests, `analyzeWaferMap` gives up on test-value analysis
180
- entirely** — it returns no test findings rather than a trimmed set, and records a
181
- `WaferWarning` with code `'test-count-capped'` in `stats.warnings`. Silence is not
182
- success here: an empty findings list is indistinguishable from "nothing to report"
183
- unless you check. Pass `testNumbers: [...]` to scope the analysis explicitly.
179
+ - **By default (`enableTestValueAnalysis: 'auto'`), above 1,500,000 test values
180
+ (dies × parametric tests, summed over a lot's wafers, e.g. 150 tests on 10,000 dies)
181
+ `analyzeWaferMap` skips test-value analysis entirely** — no regional test-value findings
182
+ or per-test statistics rather than a trimmed set (limit-failure findings still run) —
183
+ and records it in `stats.testValueAnalysis` (`state: 'skipped'`). Read that rather than
184
+ assuming a findings list without test-value findings means "nothing to report". The
185
+ renderers offer the analysis to the reader; `true` runs it regardless, and
186
+ `testNumbers: [...]` scopes it.
184
187
  - **Reach for options deliberately.** Plain `analyzeWaferMap()` is cheap;
185
- `computePerTestStats` is modest; `enableTestValueAnalysis` is the expensive one
186
- (roughly 10× the base analysis on a large wafer) and exists to find spatial
187
- patterns automatically — do not enable it by default just because it sounds good.
188
+ `computePerTestStats` is modest; the test-value analysis is the expensive one
189
+ (roughly 10× the base analysis on a large wafer). Its default, `'auto'`, runs it only
190
+ within the budget above; pass `true` only when you mean to pay for it on any size.
188
191
  - **A Web Worker buys responsiveness, not speed.** `createWafermapWorker` moves a
189
192
  result's test values to the page without copying them, but still copies the dies and the
190
193
  input, so total time goes *up*. Use it when a build would otherwise visibly freeze the
package/CHANGELOG.md CHANGED
@@ -24,6 +24,123 @@ under `### Breaking`.
24
24
 
25
25
  ## [Unreleased]
26
26
 
27
+ ## [0.36.0] — 2026-10-13
28
+
29
+ ### Breaking
30
+
31
+ - **Rotation, mirroring, the compact layout and log scale are display state, not preferences.** `rotation`, `flipX`, `flipY`,
32
+ `compact` and `logScale` move from `WaferPreferences` to `WaferDisplayState`, and `onViewOptionsChange` reports a change to
33
+ them as `'state'`. Each describes the data on screen (orientation relative to that data, a layout for multi-project wafers,
34
+ the test's own scale), so a host keeping preferences between sessions no longer carries them to a lot they do not fit.
35
+ `showLegend`, already reported as state, moves with them: whether a map's legend can safely be off depends on the view.
36
+ The flat `WaferViewOptions` is unchanged.
37
+ - **Test-value analysis runs by default when it fits a budget, and the renderers offer it when it does not.**
38
+ `enableTestValueAnalysis` takes `true | false | 'auto'`, and the default is now `'auto'` (it was `false`): the regional
39
+ test-value comparisons and per-test statistics run when the analysis reads at most 1,500,000 values (dies × parametric
40
+ tests: 150 tests on 10,000 dies, 500 on 3,000), summed over the wafers for `analyzeWaferLot` so a lot decides once. Over
41
+ the budget they are skipped and limit-failure findings still run. A host that relied on the old default gets these
42
+ findings, and their cost, on small data; pass `false` to keep them off. `true` now runs the analysis whatever its size (it
43
+ was capped at 250 discovered tests), and `computePerTestStats` is no longer capped.
44
+ - **`test-count-capped` is no longer raised.** A skipped analysis is recorded in `stats.testValueAnalysis` instead, and the
45
+ Findings section of `renderWaferMap` and `renderWaferGallery` says the test-value findings are not included, with the
46
+ tests, dies and an estimated time, and an **Analyse** button that re-runs the analysis (for a gallery, the whole lot at
47
+ once). The code stays in the warning type. The results summary's **Compared** line reads "N tests (against their limits
48
+ only)" when the analysis was skipped, and names no tests when it was off.
49
+
50
+ ### Added
51
+
52
+ - **`WAFER_PREFERENCE_KEYS`** from `/render`: the view-option keys that are preferences, for a host to keep exactly those
53
+ between sessions.
54
+ - **The Insights charts' axis settings are preferences:** `chartAxisIncludesLimits`, `chartClipOutliers` and `chartLimitLines`
55
+ on the view options start the charts' axis menu, and a reader's change is reported through `onViewOptionsChange` like any
56
+ preference, without redrawing a map.
57
+ - **`stats.testValueAnalysis`** on `StatsSummary` and `LotStatsSummary`: `state` (`'done'`, `'skipped'` or `'off'`), the
58
+ tests, dies and values the analysis covers, and an estimated time in the slower browser engine.
59
+ - **`analysisOptions`** on `StatsSummary` and `LotStatsSummary`: the options the summary was analysed with, which the
60
+ renderers reuse when the reader asks for the skipped analysis.
61
+ - **`analyzeWaferLotAsync(items, options)`**: `analyzeWaferLot` that hands control back to the browser whenever about 100 ms
62
+ of work has passed, with `onProgress` and an `AbortSignal`, for lots large enough to hang a page.
63
+ - **`onStatsSummaryChange`** on `renderWaferMap` and `renderWaferGallery`: called with the new summary (for a gallery, each
64
+ item's and the lot's) after the reader runs the skipped test-value analysis from the Findings section.
65
+
66
+ - **`StatsFinding.variable.measure`** says which statistic a test finding compares: `'mean'` (the values, in the test's unit)
67
+ or `'limitFailRate'` (the share of dies outside the test's limits, a fraction like a bin rate). Set on every `kind: 'test'`
68
+ finding, wafer, lot and drift alike. A limit-fail-rate finding carries no `unit`.
69
+
70
+ ### Deprecated
71
+
72
+ - **`FindingsNotice`, the `findingsNotice` render option and `setFindingsNotice`.** The renderers raise the test-value offer
73
+ themselves. A notice a host still passes replaces the built-in offer.
74
+
75
+ ### Changed
76
+
77
+ - **Report links stay in the report, and bar figures sit beside their bars.** The contents line and the "See" links scroll
78
+ to their target in every embedding, including the in-app report modal, and briefly outline it. After a jump a **Back**
79
+ button (or Alt+←) returns to where the reader was; a report open as a page of its own also records each jump in the
80
+ browser's history. In the bin breakdown and yield tables each figure
81
+ is printed beside its bar rather than on it, so it reads on any bin colour.
82
+ - **The HTML reports' Findings table names the statistic and states every rate in points.** The Metric column reads
83
+ "CONT_V_00000 mean" or "CONT_V_00000 limit fail rate", and a limit fail rate's or functional pass rate's delta is in
84
+ percentage points, as the Summary panel states it. A spatial-pattern row's delta reads "—" (its extent is in the N column).
85
+ The findings a pattern explains are listed most severe first, in the panel and the reports, and a table with a pattern
86
+ carries a line saying how the rows are ordered.
87
+ - **A supplied wafer centre far outside the probed dies is ignored, with a warning.** When `waferConfig.center` is given without a
88
+ `diameter` and lies more than the dies' own span outside their bounding box on either axis (with at least 20 dies), the centre is
89
+ inferred from the dies instead and an `implausible-center` warning names the supplied value and the die extent. A wafer is
90
+ otherwise sized to reach the dies from that centre. A centre at the edge or corner of partial data, a centre with a diameter, and
91
+ a centre for fewer than 20 dies are used as given. This can move the plotted wafer outline and ring assignment for such input.
92
+ - **A wafer sized in die pitches draws no flat or notch into its outline.** With no die size, the diameter is a count of die
93
+ pitches, and the SEMI flat and notch sizes are millimetres, so `waferConfig.notch` keeps its side (the orientation marker) and
94
+ `wafer.notch.length` is 0. A wafer whose diameter is in millimetres keeps its standard flat or notch. This changes the drawn outline,
95
+ and the dies counted inside the wafer, for a pitch-sized wafer with a notch side set.
96
+ - **The correlation matrix pairs at most 300 tests.** Above 300 parametric tests, the tests entering the matrix are chosen first:
97
+ the most dies outside their test limits, then the widest spread against the limit window. The panel says so ("Among the 300 of
98
+ 2,002 tests with the most dies outside their limits, then the widest spread"), and the matrix carries `testSample`. A file with
99
+ thousands of tests opens the Correlation view in about a second.
100
+ - **A bin-count stack is analysed as counts, and has no yield.** A `countBin` or `percent` lot stack, and each card of the gallery's
101
+ stacked hard and soft bin view, carries the counted bin on every die so the map can name it; its data is the count per position.
102
+ Its analysis no longer reads that bin as every die's verdict, so such a card no longer reports "near-full — 100% of dies failing"
103
+ or a 0% yield: its yield is not stated, and value findings on the count follow the same option as a stacked test value. A value
104
+ stack (`mean`, `median` and the rest) likewise no longer reports soft-bin findings from its template wafer's bins.
105
+ - **Stored numbers are shown in their stored digits.** A limits conflict between wafers and the categories of a box or bar
106
+ plot over a numeric X show a float32 value (STDF stores limits and results that way) in its shortest exact form, `1.6`
107
+ rather than `1.600000023841858`. The same text is exported as `fmtExact` for a host that shows limits itself.
108
+ - **A dense map is drawn without light bands.** When the kerf between dies would be narrower than one device pixel, each die
109
+ is drawn on whole device pixels without an outline: a die of 4 device pixels or more keeps a kerf of exactly one pixel, a
110
+ smaller one is drawn edge to edge across its pitch. A kerf and edges a fraction of a pixel wide had beaten against the pixel
111
+ grid into horizontal bands and washed the colours out; small and mid-sized maps (a gallery card, the compact view) now show
112
+ a crisp one-pixel gap between dies where they had a soft outline. Zoomed in until the kerf is a pixel or more, the map is
113
+ drawn as before.
114
+ - **Out-of-spec marks are left off dies smaller than 5 CSS pixels.** Below that size a ▽/△ mark is larger than its die and covers
115
+ its neighbours. The colorbar says "▽△ limit marks: zoom in" in place of the marks' key; zooming in brings them back.
116
+ - **The correlation matrix caps its work at 250 million pair updates.** Past that (300 tests over more than ~5,600 dies), the dies are
117
+ thinned to an even spread that fits, and the panel's sample note gives the count.
118
+ - **Large lots analyse and render faster.** Per-wafer pass-rate tallies are counted once and reused by the load-time pass, the Summary
119
+ panel and Insights; a wafer without retests skips the retest grouping; 8-connected components are labelled over a grid index; a
120
+ cluster search stops when every die or none fails; regions are built only when a finding can use them; and the lot report's test
121
+ table takes its statistics from the pooled pass the panel already ran when wafers carry none of their own.
122
+ - **Insights hides a single map's docked Summary panel completely.** The panel's title row and close button no longer show over the
123
+ chart suite while Insights is open in `renderWaferMap`.
124
+
125
+ - **The Insights Data tab and the Tables menu list Statistics, Wafers, then Dies.** The views run from the coarsest to the finest; a
126
+ single-wafer population still lists Statistics and Dies.
127
+ - **A toolbar divider shows only where a visible control sits on both sides of it.** A bordered toolbar with no visible control is
128
+ hidden, so a toolbar whose groups are hidden (Insights open, no warnings, no Summary button) leaves no stray line.
129
+ - **"What stands out" shows at most five test chips per item.** When more tests fail on an item's dies, the five failing the most
130
+ dies are chips and the rest are counted ("and 25 more tests"), in the Summary panel and the summary report alike. The tests named
131
+ in the item's sentence are likewise the ones failing the most dies.
132
+ - **A lone regional gain is re-tested without the regions that lean towards a loss.** A region reported as better than the rest of
133
+ the wafer must still hold when the regions leaning the other way are left out of the rest, whether or not another finding shares
134
+ its group, so some wafers list one fewer smaller finding.
135
+ - **The cluster permutation test draws as many shuffles as the significance level needs.** 99 at the default level, up to 9,999
136
+ below it, so a stricter `significanceLevel` can still report a cluster.
137
+ - **A derived-test constant named `site`, `hbin`, `sbin`, `dieX` or `dieY` reads as that constant when written without parentheses.**
138
+ With parentheses the name is the die's own field, as before.
139
+ - **The excluded-values note counts one test over the yield-eligible dies**, the population the chart draws, and the report's note
140
+ escapes test names. The Reticle cell yield grid takes the field size as whole dies, as cell placement does. The compact "What
141
+ stands out" rows keep their button role inside a list. The map's default bin mode is one function (`defaultBinMode`) for
142
+ `buildWaferMap` and both renderers.
143
+
27
144
  ## [0.35.1] — 2026-10-09
28
145
 
29
146
  ### Added
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![CI and deploy](https://github.com/wafertools/wafermap/actions/workflows/deploy.yml/badge.svg)](https://github.com/wafertools/wafermap/actions/workflows/deploy.yml)
6
6
  [![npm](https://img.shields.io/npm/v/@wafertools/wafermap.svg)](https://www.npmjs.com/package/@wafertools/wafermap)
7
7
  ![runtime deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen)
8
- ![bundle](https://img.shields.io/badge/data%20layer%20min%2Bgz-~70%20kB-blue)
8
+ ![bundle](https://img.shields.io/badge/data%20layer%20min%2Bgz-~73%20kB-blue)
9
9
  [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
10
10
 
11
11
  <img src="docs/images/hero-test-values.png" alt="wafermap demo" style="max-width:640px; display:block; margin:8px 0;" />
@@ -13,7 +13,7 @@
13
13
  Browser-first wafer map visualization for semiconductor test data.
14
14
 
15
15
  **Zero runtime dependencies.** Pure ES modules with TypeScript types — works in React,
16
- Svelte, Vue, plain HTML, or a Web Worker. The DOM-free data-and-stats layer is ~70 kB
16
+ Svelte, Vue, plain HTML, or a Web Worker. The DOM-free data-and-stats layer is ~73 kB
17
17
  min+gz; the interactive renderer is larger, and its chart suite and in-app guide are
18
18
  loaded on demand rather than shipped up front — [measured sizes](docs/performance.md).
19
19
 
@@ -78,7 +78,7 @@ export. Add `analyzeWaferMap` for the findings and summary panel, swap in
78
78
 
79
79
  The API reference is long because it documents every option, not because you need
80
80
  them: [tsmap](https://github.com/wafertools/tsmap), a complete cross-platform desktop
81
- application built on this library, imports **18** of its ~100 exports. Read the
81
+ application built on this library, imports **20** of its ~100 exports. Read the
82
82
  [Quick Start](https://wafertools.github.io/wafermap/quickstart/) first and treat the
83
83
  [API reference](https://wafertools.github.io/wafermap/api/) as something to search,
84
84
  not to read.
@@ -0,0 +1,16 @@
1
+ import type { AxisPrefs } from './charts/chartShell.js';
2
+ /** The charts' axis settings from a renderer's view options (the `chart*` preferences). */
3
+ export declare function axisPrefsFromOptions(o: {
4
+ chartAxisIncludesLimits?: boolean;
5
+ chartClipOutliers?: boolean;
6
+ chartLimitLines?: AxisPrefs['limits'];
7
+ }): AxisPrefs;
8
+ /** The `chart*` preferences an axis-settings change sets. */
9
+ export declare function optionsFromAxisPrefs(p: AxisPrefs): {
10
+ chartAxisIncludesLimits: boolean | undefined;
11
+ chartClipOutliers: boolean;
12
+ chartLimitLines: import("./charts/chartShell.js").LimitsShown;
13
+ };
14
+ /** The view-option keys that are the charts' axis settings: a change to them redraws no map. */
15
+ export declare const CHART_PREF_KEYS: readonly ["chartAxisIncludesLimits", "chartClipOutliers", "chartLimitLines"];
16
+ //# sourceMappingURL=chartPrefs.d.ts.map
@@ -0,0 +1 @@
1
+ export function axisPrefsFromOptions(i){return{includeLimits:i.chartAxisIncludesLimits,clipOutliers:i.chartClipOutliers??!1,limits:i.chartLimitLines??"both"}}export function optionsFromAxisPrefs(i){return{chartAxisIncludesLimits:i.includeLimits,chartClipOutliers:i.clipOutliers,chartLimitLines:i.limits??"both"}}export const CHART_PREF_KEYS=["chartAxisIncludesLimits","chartClipOutliers","chartLimitLines"];
@@ -1 +1 @@
1
- import{buildTestBoxplotData as rt}from"../../stats/boxplot.js";import{SPACE as De,fontPx as _,FONT as ct,CLR as ft}from"../toolbar.js";import{fmt as ge}from"../../renderer/fmt.js";import{fitTicks as ut}from"../../renderer/axisTicks.js";import{QUANTITY as Ee}from"./palette.js";import{cardShell as mt,observeResize as dt,makeTooltip as xt,positionChartTooltip as pt,makeBackButton as ht,makeLinkedTestSelect as gt,makeToggle as bt,makeLinkedAxisPrefs as wt,renderEmptyState as Oe,fitRowsHeight as yt,setChartGrow as Tt,resolveChartCanvasColors as vt,makeAxisFormat as We,horizontalTickSpacing as kt,resolveAxisRange as Mt,shouldIncludeLimitsByDefault as Lt,drawOffAxisLimits as Ct,limitLabelSide as At,limitLines as Pe,limitExtent as $t,hasBothLimitKinds as St,stackLabelRows as It,strokeLimitLine as Bt,PADDING as L,VALUE_WIDTH as Rt,WAFER_MENU_HINT as Ht,prepareCanvas as Dt}from"./chartShell.js";import{escHtml as C,maxOf as Et,minOf as Ot}from"../../core/utils.js";import{excludedNote as Wt}from"../../renderer/valueFilter.js";const A=24,$=5,_e=110,Pt=12,Ne=20;export function renderBoxplotPanel(u){const{title:ne="Test value distribution",items:Ge,testDefs:be,onSaveImage:Xe,groups:g,groupLabelText:oe="group",onOpen:Q}=u,qe=u.openActionLabel??"open that wafer",Ye=u.openActionLabel??"open this wafer",{card:a,heading:ze,body:x,controlsRow:U}=mt(ne,Xe,u.ownerDocument);Tt(a,"rows"),a.style.flex="0 0 auto",x.style.flex="0 0 auto",a.style.alignSelf="start";const ie=be.filter(i=>i.testNumber!==void 0);let b=u.selectedTestNumber??ie[0]?.testNumber??null,le=!1,F=0,w=null,D=null,se=null,we=null;function ye(){const i=!g||g.length===0?"":w??"\0overview";if(se&&we===i)return se;const p=!g||g.length===0?Ge:w!==null?g.find(k=>k.key===w)?.items??[]:g.map(k=>({label:k.key,dies:k.items.flatMap(T=>T.dies??[])}));return se=p,we=i,p}function Te(){w!==null&&!D?(D=ht(()=>{ve(null),u.onGroupChange?.(null)},a.ownerDocument),U.appendChild(D)):w===null&&D&&(D.remove(),D=null),ze.textContent=w!==null?`${ne} \u2014 ${oe}: ${w}`:ne}function ve(i){return w===i||i!==null&&!(g??[]).some(p=>p.key===i)?!1:(w=i,Te(),j(),S(),!0)}const ke=gt(ie,b,i=>{b=i,S(),u.onTestChange?.(i)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:a.ownerDocument}),Qe=ke.el;U.appendChild(Qe),U.appendChild(bt("Log scale",le,i=>{le=i,S()},a.ownerDocument,"Draw the value axis on a logarithmic scale"));const ae=a.ownerDocument.createElement("span");Object.assign(ae.style,{display:"inline-flex",gap:De.lg,alignItems:"center"}),U.appendChild(ae);const re=wt(ae,u.axisPrefs,i=>{u.onAxisPrefsChange?.(i),S()},a.ownerDocument),V=a.ownerDocument.createElement("div");V.dataset.wmapCaption="1",Object.assign(V.style,{color:ft.label,fontSize:ct.body,marginBottom:De.sm}),a.insertBefore(V,x);function j(){const i=!!g&&g.length>0&&w===null,p=[];i?p.push(`click a ${oe}'s box to see it by wafer`):Q&&p.push(`click a box to ${qe}`);const k=p.length?`${p[0][0].toUpperCase()}${p[0].slice(1)} \xB7 `:"";V.textContent=`${k}box = Q1\u2013Q3, line = median, whiskers = min/max \xB7 value shown is the median`+(F?` \xB7 axis clipped, ${F} value${F===1?"":"s"} outside`:"")+(b!==null?Wt(ye().flatMap(T=>T.dies??[]),b):"")}j(),Te();const E=xt(a);let ce=null;function S(){const{includeLimits:i,clipOutliers:p,limits:k}=re.get();if(j(),x.innerHTML="",ie.length===0||b===null){Oe(x,"No parametric test data available for box plots.");return}const T=ye(),h=rt(T,b),K=be.find(t=>t.testNumber===b),O=K?.unit,fe=Pe(K,k),{lo:Ve,hi:je}=$t(fe);if(h.every(t=>t.count===0)){Oe(x,"No parametric test data available for box plots.");return}const m=a.ownerDocument.createElement("canvas");m.style.display="block",m.style.cursor="default",x.appendChild(m);const Me=L*2+Math.min(h.length,Pt)*(A+$)+Ne;x.style.maxHeight=`${Me}px`,x.style.overflowY="auto",x.style.scrollbarGutter="stable";let N=-1;const ue=h.filter(t=>t.count>0),Le=Ot(ue.map(t=>t.min)),Ce=Et(ue.map(t=>t.max)),Ae=i??Lt(Le,Ce,Ve,je);re.sync(Ae,Pe(K).length>0,St(K));const G=Mt({dataMin:Le,dataMax:Ce,limits:fe,includeLimits:Ae,clipOutliers:p,values:ue.flatMap(t=>[t.min,t.q1,t.median,t.q3,t.max])});F=G.clippedCount,j();const W=G.lo,J=G.hi,Ke=J-W||1,Z=le&&W>0,me=Z?Math.log10(W):0,$e=(Z?Math.log10(J):0)-me||1,de=Math.max(Math.abs(W),Math.abs(J));function Je(){const t=L+_e,s=m.clientWidth-t-Rt-L;return{plotX:t,plotMaxWidth:Math.max(10,s)}}function I(t,s,n){return Z?s+(Math.log10(t)-me)/$e*n:s+(t-W)/Ke*n}function Ze(t,s){if(Z){const d=[];for(let e=0;e<=4;e++)d.push(Math.pow(10,me+$e*e/4));return{ticks:d,axis:We(de,O)}}const n=ut(W,J,s,kt(t,de,O));return{ticks:n.ticks,axis:We(de,O,n.step||void 0)}}function ee(){const t=vt(a),s=L*2+h.length*(A+$)+Ne;x.style.maxHeight=`${yt(a,x,Me,s)}px`;const n=x.clientWidth,d=Dt(m,a,n,s);if(!d)return;const{ctx:e}=d;e.font=`${_(-1)}px system-ui, sans-serif`,e.textBaseline="middle";const{plotX:l,plotMaxWidth:c}=Je();h.forEach((o,f)=>{const y=L+f*(A+$),r=y+A/2;f===N&&(e.fillStyle=t.bgHover,e.fillRect(0,y-$/2,n,A+$)),e.fillStyle=t.text,e.textAlign="right";const te=o.label.length>16?`${o.label.slice(0,15)}\u2026`:o.label;if(e.fillText(te,L+_e-8,r),o.count===0){e.fillStyle=t.textMuted,e.textAlign="left",e.fillText("no data",l,r);return}const it=l+c,q=at=>Math.min(it,Math.max(l,at)),Be=I(o.min,l,c),Re=I(o.max,l,c),B=q(Be),Y=q(I(o.q1,l,c)),He=q(I(o.median,l,c)),he=q(I(o.q3,l,c)),R=q(Re),lt=Be<B,st=Re>R,H=y+3,z=y+A-3;e.strokeStyle=t.textMuted,e.lineWidth=1,e.beginPath(),e.moveTo(B,r),e.lineTo(Y,r),e.moveTo(he,r),e.lineTo(R,r);const M=3;lt?(e.moveTo(B+M,r-M),e.lineTo(B,r),e.lineTo(B+M,r+M)):(e.moveTo(B,H),e.lineTo(B,z)),st?(e.moveTo(R-M,r-M),e.lineTo(R,r),e.lineTo(R-M,r+M)):(e.moveTo(R,H),e.lineTo(R,z)),e.stroke(),e.fillStyle=Ee,e.globalAlpha=.35,e.fillRect(Y,H,Math.max(1,he-Y),z-H),e.globalAlpha=1,e.strokeStyle=Ee,e.strokeRect(Y,H,Math.max(1,he-Y),z-H),e.strokeStyle=t.text,e.lineWidth=2,e.beginPath(),e.moveTo(He,H),e.lineTo(He,z),e.stroke(),e.lineWidth=1,e.fillStyle=t.textMuted,e.textAlign="left",e.fillText(ge(o.median,O,"engineering"),l+c+10,r)});const v=L+h.length*(A+$);e.font=`${_(-1)}px system-ui, sans-serif`,Ct(e,G.offAxis,{left:l,right:l+c,top:0,bottom:v},"horizontal",t.limitLine,o=>ge(o,O,"engineering"));const et=new Set(G.offAxis.map(o=>o.value)),Ie=fe.filter(o=>!et.has(o.value)).map(o=>{const f=I(o.value,l,c),y=e.measureText(o.label).width,r=At(f,y,l,l+c,o.end==="lo"),te=r<0?f-3-y:f+3;return{l:o,x:f,dir:r,start:te,end:te+y}}),tt=It(Ie),nt=_(-1)+2;Ie.forEach(({l:o,x:f,dir:y},r)=>{Bt(e,o,t.limitLine,f,0,f,v),e.fillStyle=t.limitLine,e.textAlign=y<0?"right":"left",e.textBaseline="bottom",e.fillText(o.label,f+y*3,v-1-tt[r]*nt)}),e.font=`${_(-1)}px system-ui, sans-serif`,e.strokeStyle=t.border,e.lineWidth=1,e.beginPath(),e.moveTo(l,v),e.lineTo(l+c,v),e.stroke(),e.fillStyle=t.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:ot,axis:pe}=Ze(e,c);for(const o of ot){const f=I(o,l,c);e.beginPath(),e.moveTo(f,v),e.lineTo(f,v+4),e.stroke(),e.fillText(pe.tick(o),f,v+6)}pe.unitLabel&&(e.textAlign="left",e.font=`${_(-1)}px system-ui, sans-serif`,e.fillText(`(${pe.unitLabel})`,l+c+22,v+6),e.font=`${_(-1)}px system-ui, sans-serif`),e.textBaseline="middle"}function xe(t){const s=Math.floor((t-L+$/2)/(A+$));return s>=0&&s<h.length?s:-1}function X(t){return ge(t,O,"engineering")}const P=!!g&&g.length>0&&w===null,Se=t=>!P&&!!Q&&T[t]?.waferIndex!==void 0;m.addEventListener("mousemove",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n>=0&&h[n].count>0&&(P||Se(n));if(n!==N&&(N=n,m.style.cursor=d?"pointer":"default",ee()),n>=0&&h[n].count>0){const e=h[n],l=P?`<br><em>click to see this ${C(oe)} by wafer</em>`:Se(n)?`<br><em>click to ${C(Ye)}</em>`:"",c=!P&&u.onWaferContextMenu&&T[n]?.waferIndex!==void 0?Ht:"";E.innerHTML=`<strong>${C(e.label)}</strong> (${e.count} dies)<br>max ${C(X(e.max))}<br>q3 ${C(X(e.q3))}<br>median ${C(X(e.median))}<br>q1 ${C(X(e.q1))}<br>min ${C(X(e.min))}${l}${c}`,E.style.display="block",pt(E,a,t.clientX,t.clientY)}else E.style.display="none"}),m.addEventListener("mouseleave",()=>{N!==-1&&(N=-1,ee()),E.style.display="none"}),m.addEventListener("click",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top);if(n===-1||h[n].count===0)return;if(P){const e=h[n].label;ve(e),u.onGroupChange?.(e);return}const d=T[n]?.waferIndex;Q&&d!==void 0&&b!==null&&Q(d,b)}),m.addEventListener("contextmenu",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n===-1?void 0:T[n]?.waferIndex;P||d===void 0||!u.onWaferContextMenu||(E.style.display="none",u.onWaferContextMenu(d,b??void 0,t))}),ce?.disconnect(),ce=dt(a,()=>ee()),ee()}S();function Ue(i){ke.set(i)&&(b=i,S())}function Fe(i){re.set(i)&&S()}return{card:a,setTest:Ue,setAxisPrefs:Fe,destroy:()=>ce?.disconnect()}}
1
+ import{buildTestBoxplotData as rt}from"../../stats/boxplot.js";import{SPACE as De,fontPx as _,FONT as ct,CLR as ft}from"../toolbar.js";import{fmt as ge}from"../../renderer/fmt.js";import{fitTicks as ut}from"../../renderer/axisTicks.js";import{QUANTITY as Ee}from"./palette.js";import{cardShell as mt,observeResize as dt,makeTooltip as xt,positionChartTooltip as pt,makeBackButton as ht,makeLinkedTestSelect as gt,makeToggle as bt,makeLinkedAxisPrefs as wt,renderEmptyState as Oe,fitRowsHeight as yt,setChartGrow as Tt,resolveChartCanvasColors as vt,makeAxisFormat as We,horizontalTickSpacing as kt,resolveAxisRange as Mt,shouldIncludeLimitsByDefault as Lt,drawOffAxisLimits as Ct,limitLabelSide as At,limitLines as Pe,limitExtent as $t,hasBothLimitKinds as St,stackLabelRows as It,strokeLimitLine as Bt,PADDING as L,VALUE_WIDTH as Rt,WAFER_MENU_HINT as Ht,prepareCanvas as Dt}from"./chartShell.js";import{escHtml as C,maxOf as Et,minOf as Ot}from"../../core/utils.js";import{excludedNote as Wt}from"../../renderer/valueFilter.js";const A=24,$=5,_e=110,Pt=12,Ne=20;export function renderBoxplotPanel(u){const{title:ne="Test value distribution",items:Ge,testDefs:be,onSaveImage:Xe,groups:g,groupLabelText:oe="group",onOpen:Q}=u,qe=u.openActionLabel??"open that wafer",Ye=u.openActionLabel??"open this wafer",{card:a,heading:ze,body:x,controlsRow:U}=mt(ne,Xe,u.ownerDocument);Tt(a,"rows"),a.style.flex="0 0 auto",x.style.flex="0 0 auto",a.style.alignSelf="start";const ie=be.filter(i=>i.testNumber!==void 0);let y=u.selectedTestNumber??ie[0]?.testNumber??null,le=!1,F=0,b=null,D=null,se=null,we=null;function ye(){const i=!g||g.length===0?"":b??"\0overview";if(se&&we===i)return se;const p=!g||g.length===0?Ge:b!==null?g.find(k=>k.key===b)?.items??[]:g.map(k=>({label:k.key,dies:k.items.flatMap(T=>T.dies??[])}));return se=p,we=i,p}function Te(){b!==null&&!D?(D=ht(()=>{ve(null),u.onGroupChange?.(null)},a.ownerDocument),U.appendChild(D)):b===null&&D&&(D.remove(),D=null),ze.textContent=b!==null?`${ne} \u2014 ${oe}: ${b}`:ne}function ve(i){return b===i||i!==null&&!(g??[]).some(p=>p.key===i)?!1:(b=i,Te(),j(),S(),!0)}const ke=gt(ie,y,i=>{y=i,S(),u.onTestChange?.(i)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:a.ownerDocument}),Qe=ke.el;U.appendChild(Qe),U.appendChild(bt("Log scale",le,i=>{le=i,S()},a.ownerDocument,"Draw the value axis on a logarithmic scale"));const ae=a.ownerDocument.createElement("span");Object.assign(ae.style,{display:"inline-flex",gap:De.lg,alignItems:"center"}),U.appendChild(ae);const re=wt(ae,u.axisPrefs,i=>{u.onAxisPrefsChange?.(i),S()},a.ownerDocument),V=a.ownerDocument.createElement("div");V.dataset.wmapCaption="1",Object.assign(V.style,{color:ft.label,fontSize:ct.body,marginBottom:De.sm}),a.insertBefore(V,x);function j(){const i=!!g&&g.length>0&&b===null,p=[];i?p.push(`click a ${oe}'s box to see it by wafer`):Q&&p.push(`click a box to ${qe}`);const k=p.length?`${p[0][0].toUpperCase()}${p[0].slice(1)} \xB7 `:"";V.textContent=`${k}box = Q1\u2013Q3, line = median, whiskers = min/max \xB7 value shown is the median`+(F?` \xB7 axis clipped, ${F} value${F===1?"":"s"} outside`:"")+Wt(ye().flatMap(T=>T.dies??[]),y)}j(),Te();const E=xt(a);let ce=null;function S(){const{includeLimits:i,clipOutliers:p,limits:k}=re.get();if(j(),x.innerHTML="",ie.length===0||y===null){Oe(x,"No parametric test data available for box plots.");return}const T=ye(),h=rt(T,y),K=be.find(t=>t.testNumber===y),O=K?.unit,fe=Pe(K,k),{lo:Ve,hi:je}=$t(fe);if(h.every(t=>t.count===0)){Oe(x,"No parametric test data available for box plots.");return}const m=a.ownerDocument.createElement("canvas");m.style.display="block",m.style.cursor="default",x.appendChild(m);const Me=L*2+Math.min(h.length,Pt)*(A+$)+Ne;x.style.maxHeight=`${Me}px`,x.style.overflowY="auto",x.style.scrollbarGutter="stable";let N=-1;const ue=h.filter(t=>t.count>0),Le=Ot(ue.map(t=>t.min)),Ce=Et(ue.map(t=>t.max)),Ae=i??Lt(Le,Ce,Ve,je);re.sync(Ae,Pe(K).length>0,St(K));const G=Mt({dataMin:Le,dataMax:Ce,limits:fe,includeLimits:Ae,clipOutliers:p,values:ue.flatMap(t=>[t.min,t.q1,t.median,t.q3,t.max])});F=G.clippedCount,j();const W=G.lo,J=G.hi,Ke=J-W||1,Z=le&&W>0,me=Z?Math.log10(W):0,$e=(Z?Math.log10(J):0)-me||1,de=Math.max(Math.abs(W),Math.abs(J));function Je(){const t=L+_e,s=m.clientWidth-t-Rt-L;return{plotX:t,plotMaxWidth:Math.max(10,s)}}function I(t,s,n){return Z?s+(Math.log10(t)-me)/$e*n:s+(t-W)/Ke*n}function Ze(t,s){if(Z){const d=[];for(let e=0;e<=4;e++)d.push(Math.pow(10,me+$e*e/4));return{ticks:d,axis:We(de,O)}}const n=ut(W,J,s,kt(t,de,O));return{ticks:n.ticks,axis:We(de,O,n.step||void 0)}}function ee(){const t=vt(a),s=L*2+h.length*(A+$)+Ne;x.style.maxHeight=`${yt(a,x,Me,s)}px`;const n=x.clientWidth,d=Dt(m,a,n,s);if(!d)return;const{ctx:e}=d;e.font=`${_(-1)}px system-ui, sans-serif`,e.textBaseline="middle";const{plotX:l,plotMaxWidth:c}=Je();h.forEach((o,f)=>{const w=L+f*(A+$),r=w+A/2;f===N&&(e.fillStyle=t.bgHover,e.fillRect(0,w-$/2,n,A+$)),e.fillStyle=t.text,e.textAlign="right";const te=o.label.length>16?`${o.label.slice(0,15)}\u2026`:o.label;if(e.fillText(te,L+_e-8,r),o.count===0){e.fillStyle=t.textMuted,e.textAlign="left",e.fillText("no data",l,r);return}const it=l+c,q=at=>Math.min(it,Math.max(l,at)),Be=I(o.min,l,c),Re=I(o.max,l,c),B=q(Be),Y=q(I(o.q1,l,c)),He=q(I(o.median,l,c)),he=q(I(o.q3,l,c)),R=q(Re),lt=Be<B,st=Re>R,H=w+3,z=w+A-3;e.strokeStyle=t.textMuted,e.lineWidth=1,e.beginPath(),e.moveTo(B,r),e.lineTo(Y,r),e.moveTo(he,r),e.lineTo(R,r);const M=3;lt?(e.moveTo(B+M,r-M),e.lineTo(B,r),e.lineTo(B+M,r+M)):(e.moveTo(B,H),e.lineTo(B,z)),st?(e.moveTo(R-M,r-M),e.lineTo(R,r),e.lineTo(R-M,r+M)):(e.moveTo(R,H),e.lineTo(R,z)),e.stroke(),e.fillStyle=Ee,e.globalAlpha=.35,e.fillRect(Y,H,Math.max(1,he-Y),z-H),e.globalAlpha=1,e.strokeStyle=Ee,e.strokeRect(Y,H,Math.max(1,he-Y),z-H),e.strokeStyle=t.text,e.lineWidth=2,e.beginPath(),e.moveTo(He,H),e.lineTo(He,z),e.stroke(),e.lineWidth=1,e.fillStyle=t.textMuted,e.textAlign="left",e.fillText(ge(o.median,O,"engineering"),l+c+10,r)});const v=L+h.length*(A+$);e.font=`${_(-1)}px system-ui, sans-serif`,Ct(e,G.offAxis,{left:l,right:l+c,top:0,bottom:v},"horizontal",t.limitLine,o=>ge(o,O,"engineering"));const et=new Set(G.offAxis.map(o=>o.value)),Ie=fe.filter(o=>!et.has(o.value)).map(o=>{const f=I(o.value,l,c),w=e.measureText(o.label).width,r=At(f,w,l,l+c,o.end==="lo"),te=r<0?f-3-w:f+3;return{l:o,x:f,dir:r,start:te,end:te+w}}),tt=It(Ie),nt=_(-1)+2;Ie.forEach(({l:o,x:f,dir:w},r)=>{Bt(e,o,t.limitLine,f,0,f,v),e.fillStyle=t.limitLine,e.textAlign=w<0?"right":"left",e.textBaseline="bottom",e.fillText(o.label,f+w*3,v-1-tt[r]*nt)}),e.font=`${_(-1)}px system-ui, sans-serif`,e.strokeStyle=t.border,e.lineWidth=1,e.beginPath(),e.moveTo(l,v),e.lineTo(l+c,v),e.stroke(),e.fillStyle=t.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:ot,axis:pe}=Ze(e,c);for(const o of ot){const f=I(o,l,c);e.beginPath(),e.moveTo(f,v),e.lineTo(f,v+4),e.stroke(),e.fillText(pe.tick(o),f,v+6)}pe.unitLabel&&(e.textAlign="left",e.font=`${_(-1)}px system-ui, sans-serif`,e.fillText(`(${pe.unitLabel})`,l+c+22,v+6),e.font=`${_(-1)}px system-ui, sans-serif`),e.textBaseline="middle"}function xe(t){const s=Math.floor((t-L+$/2)/(A+$));return s>=0&&s<h.length?s:-1}function X(t){return ge(t,O,"engineering")}const P=!!g&&g.length>0&&b===null,Se=t=>!P&&!!Q&&T[t]?.waferIndex!==void 0;m.addEventListener("mousemove",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n>=0&&h[n].count>0&&(P||Se(n));if(n!==N&&(N=n,m.style.cursor=d?"pointer":"default",ee()),n>=0&&h[n].count>0){const e=h[n],l=P?`<br><em>click to see this ${C(oe)} by wafer</em>`:Se(n)?`<br><em>click to ${C(Ye)}</em>`:"",c=!P&&u.onWaferContextMenu&&T[n]?.waferIndex!==void 0?Ht:"";E.innerHTML=`<strong>${C(e.label)}</strong> (${e.count} dies)<br>max ${C(X(e.max))}<br>q3 ${C(X(e.q3))}<br>median ${C(X(e.median))}<br>q1 ${C(X(e.q1))}<br>min ${C(X(e.min))}${l}${c}`,E.style.display="block",pt(E,a,t.clientX,t.clientY)}else E.style.display="none"}),m.addEventListener("mouseleave",()=>{N!==-1&&(N=-1,ee()),E.style.display="none"}),m.addEventListener("click",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top);if(n===-1||h[n].count===0)return;if(P){const e=h[n].label;ve(e),u.onGroupChange?.(e);return}const d=T[n]?.waferIndex;Q&&d!==void 0&&y!==null&&Q(d,y)}),m.addEventListener("contextmenu",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n===-1?void 0:T[n]?.waferIndex;P||d===void 0||!u.onWaferContextMenu||(E.style.display="none",u.onWaferContextMenu(d,y??void 0,t))}),ce?.disconnect(),ce=dt(a,()=>ee()),ee()}S();function Ue(i){ke.set(i)&&(y=i,S())}function Fe(i){re.set(i)&&S()}return{card:a,setTest:Ue,setAxisPrefs:Fe,destroy:()=>ce?.disconnect()}}
@@ -1 +1 @@
1
- import{buildCorrelationMatrix as $t,filterCorrelationMatrix as It,correlationSampleNote as Tt}from"../../stats/correlation.js";import{maxOf as St}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Dt}from"../../stats/facets.js";import{wireControlHover as Rt,wireTooltip as pt,controlStyle as At,SPACE as L,RADIUS as lt,fontPx as ft,FONT as j,CLR as g}from"../toolbar.js";import{exportCsv as kt}from"../tableExport.js";import{attachChartTip as _t,cardShell as Bt,setChartGrow as Nt,isExpandedCard as Ot,bodyRoom as Wt,observeResize as Ht,makeTooltip as Xt,positionChartTooltip as jt,makeWaferSelect as Vt,renderEmptyState as zt,resolveChartCanvasColors as Ft,prepareCanvas as Pt,chartDpr as ut}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as gt,DERIVED_MARK as Yt,DERIVED_KEY as Gt}from"../../renderer/testLabel.js";const it=5,at=100,bt=20;function q(b){const d=b.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=b.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function Ut(b){const d=q(b);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(b,d,h){const O=q(b);if(!O)return b;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(b){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=b,{card:l,body:$,controlsRow:Q,setPngDecor:wt}=Bt(d,J,b.ownerDocument);wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Nt(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=bt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",pt(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:g.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:g.menuBg,color:g.value,border:`1px solid ${g.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||bt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(Vt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Ct(){return V!==null?h[V]?[h[V]]:[]:h}if(b.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",pt(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...At("outlined"),color:g.text}),Rt(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),p=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&p.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}kt([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${gt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${gt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],p,"test-correlation.csv",b.onSaveText)}),Q.appendChild(e)}const k=l.ownerDocument.createElement("div");Object.assign(k.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(k,$);const I=Xt(l);_t(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Mt(e,o,m,p,s,a,y,x){k.innerHTML="";const _=Tt(y);if(_){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`${_} \u2014 r is an estimate, not the whole population.`,Object.assign(f.style,{color:g.label,fontSize:j.body}),k.appendChild(f)}if(s.length>0){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(f.style,{color:g.warnText,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),k.appendChild(f)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:g.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Yt} ${Gt} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const T=l.ownerDocument.createElement("span");T.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${g.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${g.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(T,P,z),C.appendChild(i),k.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:g.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=p?`No significant correlations found \u2014 strongest pair: ${p.xLabel} \u2194 ${p.yLabel} (r = ${p.r.toFixed(2)})`:"No significant correlations found";else{const f=[];e>0&&f.push(`${e} strong (|r| \u2265 0.7)`),o>0&&f.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=f.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}k.appendChild(v)}function Et(e){if($.innerHTML="",e.tests.length<2)return zt($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,p=r=>r.label.split(" (#")[0],s=Math.min(14,St(e.tests.map(r=>p(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,_=14,C=28,B=44;let i=-1,T=-1;const P=96;function z(r){const c=Math.max(0,r-a),u=Math.floor(c/m);if(!Ot(l))return Math.max(_,Math.min(B,u));const n=Math.floor((Wt(l,$,o)-x-4)/m);return Math.max(_,Math.min(P,u,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function f(){const r=Ft(l),c=q(r.bg)??[255,255,255],u=$.clientWidth,n=z(u),X=n*m,S=x+n*m+4,D=a+X,R=Pt(o,l,D,S);if(!R)return;const{ctx:t}=R;t.font=`${ft(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((A,w)=>{const M=p(A),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((A,w)=>{const M=p(A),N=x+w*n,et=N+n/2;t.font=`${ft(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===T?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,Lt=nt===i&&w===T,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=Ut(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),Lt&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let A=0;A<=m;A++){const w=a+A*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+A*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),u=$.clientWidth,n=z(u),X=(r.clientX-c.left)*(o.width/ut(o)/c.width),S=(r.clientY-c.top)*(o.height/ut(o)/c.height),D=Math.floor((X-a)/n),R=Math.floor((S-x)/n);return D>=0&&D<m&&R>=0&&R<m?{xi:D,yi:R}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:u,yi:n}=c,X=u===n;o.style.cursor=X||!W?"default":"pointer";const S=e.cells.find(t=>t.xIndex===u&&t.yIndex===n),D=e.tests[u].label,R=e.tests[n].label;X?I.innerHTML=`<strong>${K(D)}</strong>`:S?.r!==null&&S?.r!==void 0?I.innerHTML=`<strong>${K(p(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(p(e.tests[u]))}</strong> (#${e.tests[u].testNumber})<br>r = ${S.r.toFixed(4)} \xB7 n = ${S.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${R} vs ${D}`)}<br><em>insufficient data</em>`,I.style.display="block",jt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:u,yi:n}=c;u!==n&&(i=u,T=n,f(),W(e.tests[u].testNumber,e.tests[n].testNumber))}),f}let ct=null;function tt(){const e=Ct(),o=e.flatMap(i=>i.dies??[]),m=$t(o,O),{matrix:p,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=It(m,{minTests:6,maxTests:F}),_=Dt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=p.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,T)=>i-T),B=C.length?C[Math.floor(C.length/2)]:null;ct=p,Mt(s,a,y,x,_,B,m.sample,p.tests.some(i=>i.derived)),Z=Et(p),Z()}const vt=Ht(l,()=>Z());return tt(),{card:l,destroy:()=>vt.disconnect()}}
1
+ import{buildCorrelationMatrix as $t,filterCorrelationMatrix as It,correlationSampleNote as Tt}from"../../stats/correlation.js";import{maxOf as St}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Dt}from"../../stats/facets.js";import{wireControlHover as Rt,wireTooltip as ft,controlStyle as At,SPACE as L,RADIUS as lt,fontPx as pt,FONT as j,CLR as g}from"../toolbar.js";import{exportCsv as kt}from"../tableExport.js";import{attachChartTip as _t,cardShell as Bt,setChartGrow as Nt,isExpandedCard as Ot,bodyRoom as Wt,observeResize as Ht,makeTooltip as Xt,positionChartTooltip as jt,makeWaferSelect as Vt,renderEmptyState as zt,resolveChartCanvasColors as Ft,prepareCanvas as Pt,chartDpr as ut}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as gt,DERIVED_MARK as Yt,DERIVED_KEY as Gt}from"../../renderer/testLabel.js";const it=5,at=100,bt=20;function q(b){const d=b.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=b.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function Ut(b){const d=q(b);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(b,d,h){const O=q(b);if(!O)return b;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(b){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=b,{card:l,body:$,controlsRow:Q,setPngDecor:wt}=Bt(d,J,b.ownerDocument);wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Nt(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=bt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",ft(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:g.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:g.menuBg,color:g.value,border:`1px solid ${g.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||bt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(Vt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Ct(){return V!==null?h[V]?[h[V]]:[]:h}if(b.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",ft(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...At("outlined"),color:g.text}),Rt(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),f=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&f.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}kt([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${gt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${gt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],f,"test-correlation.csv",b.onSaveText)}),Q.appendChild(e)}const _=l.ownerDocument.createElement("div");Object.assign(_.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(_,$);const I=Xt(l);_t(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Mt(e,o,m,f,s,a,y,x){_.innerHTML="";const T=Tt(y);if(T){const p=l.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=y.sample?`${T} \u2014 r is an estimate, not the whole population.`:`${T}.`,Object.assign(p.style,{color:g.label,fontSize:j.body}),_.appendChild(p)}if(s.length>0){const p=l.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(p.style,{color:g.warnText,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),_.appendChild(p)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:g.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Yt} ${Gt} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const S=l.ownerDocument.createElement("span");S.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${g.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${g.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(S,P,z),C.appendChild(i),_.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:g.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=f?`No significant correlations found \u2014 strongest pair: ${f.xLabel} \u2194 ${f.yLabel} (r = ${f.r.toFixed(2)})`:"No significant correlations found";else{const p=[];e>0&&p.push(`${e} strong (|r| \u2265 0.7)`),o>0&&p.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=p.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}_.appendChild(v)}function Et(e){if($.innerHTML="",e.tests.length<2)return zt($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,f=r=>r.label.split(" (#")[0],s=Math.min(14,St(e.tests.map(r=>f(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,T=14,C=28,B=44;let i=-1,S=-1;const P=96;function z(r){const c=Math.max(0,r-a),u=Math.floor(c/m);if(!Ot(l))return Math.max(T,Math.min(B,u));const n=Math.floor((Wt(l,$,o)-x-4)/m);return Math.max(T,Math.min(P,u,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function p(){const r=Ft(l),c=q(r.bg)??[255,255,255],u=$.clientWidth,n=z(u),X=n*m,D=x+n*m+4,R=a+X,A=Pt(o,l,R,D);if(!A)return;const{ctx:t}=A;t.font=`${pt(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((k,w)=>{const M=f(k),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((k,w)=>{const M=f(k),N=x+w*n,et=N+n/2;t.font=`${pt(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===S?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,Lt=nt===i&&w===S,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=Ut(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),Lt&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let k=0;k<=m;k++){const w=a+k*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+k*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),u=$.clientWidth,n=z(u),X=(r.clientX-c.left)*(o.width/ut(o)/c.width),D=(r.clientY-c.top)*(o.height/ut(o)/c.height),R=Math.floor((X-a)/n),A=Math.floor((D-x)/n);return R>=0&&R<m&&A>=0&&A<m?{xi:R,yi:A}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:u,yi:n}=c,X=u===n;o.style.cursor=X||!W?"default":"pointer";const D=e.cells.find(t=>t.xIndex===u&&t.yIndex===n),R=e.tests[u].label,A=e.tests[n].label;X?I.innerHTML=`<strong>${K(R)}</strong>`:D?.r!==null&&D?.r!==void 0?I.innerHTML=`<strong>${K(f(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(f(e.tests[u]))}</strong> (#${e.tests[u].testNumber})<br>r = ${D.r.toFixed(4)} \xB7 n = ${D.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${A} vs ${R}`)}<br><em>insufficient data</em>`,I.style.display="block",jt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:u,yi:n}=c;u!==n&&(i=u,S=n,p(),W(e.tests[u].testNumber,e.tests[n].testNumber))}),p}let ct=null;function tt(){const e=Ct(),o=e.flatMap(i=>i.dies??[]),m=$t(o,O),{matrix:f,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=It(m,{minTests:6,maxTests:F}),T=Dt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=f.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,S)=>i-S),B=C.length?C[Math.floor(C.length/2)]:null;ct=f,Mt(s,a,y,x,T,B,m,f.tests.some(i=>i.derived)),Z=Et(f),Z()}const vt=Ht(l,()=>Z());return tt(),{card:l,destroy:()=>vt.disconnect()}}
@@ -1 +1 @@
1
- import{isYieldEligibleDie as O}from"../core/dies.js";import{testValue as W}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as z}from"../stats/facets.js";import{tableToTsv as A}from"../core/tableCsv.js";import{commonMetadata as H}from"../stats/facets.js";import{buildYieldData as Y}from"../stats/yield.js";import{isParametricTest as E}from"../renderer/buildWaferMap.js";import{fmt as G}from"../renderer/fmt.js";import{testLabel as N}from"../renderer/testLabel.js";import{resolveDieColumns as U}from"./dieList.js";import{createVirtualTable as R}from"./virtualTable.js";import{exportCsv as $}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as V,SPACE as C,controlStyle as K,wireControlHover as j,wireTooltip as T}from"./toolbar.js";import{buildTestSection as q,buildFunctionalTestSection as X}from"./summaryPanel.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,i,s=i+"s")=>`${e.toLocaleString()} ${e===1?i:s}`;export function renderDataSection(e){const{doc:i}=e,s=i.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=i.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),s.appendChild(c);const p=i.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),s.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),l=F(i,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(l.el);let d;switch(e.view){case"dies":d=Q(e);break;case"wafers":d=Z(e);break;default:d=J(e)}let u=()=>{};if(e.view==="dies"){const f=F(i,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),d.actions?.setLayout?.(t),u()});T(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const r=i.createElement("span");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const o=i.createElement("span");o.textContent="Export format:",Object.assign(o.style,{color:y.label,fontSize:L.body}),r.append(o,f.el),c.appendChild(r)}if(d.actions){const f=d.actions,r=i.createElement("div");r.style.flex="1",c.appendChild(r);const o=B(i,"Export CSV");o.dataset.wmapDataExport="1",o.addEventListener("click",()=>{if(o.disabled)return;const m=o.textContent,h=f.exportCsv();h&&(o.disabled=!0,o.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=m}))});const t=B(i,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(T(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=i.defaultView?.navigator?.clipboard;if(!h)return;const w=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",i.defaultView?.setTimeout(()=>{t.textContent=w},1500)}).catch(()=>{})})):(t.disabled=!0,T(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,o);const a=i.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),s.insertBefore(a,p)}return p.appendChild(d.el),{card:s,destroy:()=>d.destroy()}}function J(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const l of g){if(p){const u=i.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${l.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),s.appendChild(u)}const d=e.buildStatistics(l.items);c.push(d.destroy);for(const u of d.cards)s.appendChild(u)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:y.label,fontSize:L.body})),{el:s,destroy:()=>{for(const l of c)l()}}}function Q(e){const{doc:i,items:s}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,l=[];let d=!1;for(const n of s){n.wafer&&(d=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),l.push(b)}if(l.length===0)return M(i,"No dies to show.");const{columns:u,visibleColumns:f}=U(l,e.allTestDefs,{...e.dieListOptions,metadataFields:e.metadataFields,extraColumn:s.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:d?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:s.some(n=>n.wafer)?H(s.map(n=>({metadata:n.wafer?.metadata}))):void 0,ownerDocument:i}),r=f.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&E(n.test),...n.test!==void 0&&E(n.test)?{sortKey:b=>W(b,n.test.testNumber)}:{}})),o=R({columns:r,rows:l,ariaLabel:`Dies (${l.length})`,ownerDocument:i,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});o.el.style.maxHeight="70vh",o.el.style.minHeight="240px";const t=e.population?`-${e.population.fileTag}`:"",a=u.filter(n=>n.test!==void 0),m=u.filter(n=>n.test===void 0),h=l.length*u.length,w=l.length*a.length,x=()=>u.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),v=()=>[...m.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>N(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*_(){for(const n of o.orderedRows())for(const b of a){const S=(b.csvGet??b.get)(n);S===""||S===void 0||S===null||(yield{die:n,test:b.test,value:S})}}let k=e.diesLayout==="long"&&a.length>0;const P=()=>k?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(l.length,"row")} \xD7 ${D(u.length,"column")}`+(l.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:o.el,destroy:()=>o.destroy(),actions:{note:()=>`${D(l.length,"die")} ${e.population?.phrase??`on ${D(s.length,"wafer")}`}. ${P()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{k=n==="long"&&a.length>0},exportCsv:()=>k?$(v(),_(),`die-list-long${t}.csv`,e.onSaveText,{rowCount:w}):$(x(),o.orderedRows(),`die-list${t}.csv`,e.onSaveText,{rowCount:l.length}),copyText:h<=COPY_CELL_LIMIT?()=>A(x(),o.orderedRows()):null}}}function Z(e){const{doc:i,items:s}=e;if(s.length===0)return M(i,"No wafers to show.");const c=s.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=Y([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),l=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(x=>x.testNumber===a.testNumber);if(m)return m.mean;let h=0,w=0;for(const x of t.item.dies){if(!O(x))continue;const v=W(x,a.testNumber);v!==void 0&&Number.isFinite(v)&&(h++,w+=v)}return h?w/h:void 0},d=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:z(t,e.attributes),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>O(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${N(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>l(a,t),show:a=>{const m=l(a,t);return m===void 0?"":G(m,t.unit)},numeric:!0}))],u=d.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=R({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:i,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const r=()=>d.map(t=>({header:t.header,get:t.cell})),o=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${o}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>$(r(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*d.length<=COPY_CELL_LIMIT?()=>A(r(),f.orderedRows()):null}}}function M(e,i){const s=e.createElement("div");return s.textContent=i,Object.assign(s.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:s,destroy:()=>{}}}function B(e,i){const s=e.createElement("button");return s.type="button",s.textContent=i,Object.assign(s.style,{fontSize:L.body,padding:"3px 10px",borderRadius:V.control,...K("outlined"),background:y.menuBg}),j(s),s}function F(e,i,s,c,p,g){const l=e.createElement("div");l.setAttribute("role","radiogroup"),l.setAttribute("aria-label",i),Object.assign(l.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:V.control,overflow:"hidden"});const d=[];let u=c;const f=()=>{for(const r of d){const o=r.dataset[p]===u;r.setAttribute("aria-checked",String(o)),r.tabIndex=o?0:-1,Object.assign(r.style,{background:o?y.bgActive:"transparent",color:o?y.iconActive:y.label,fontWeight:o?"600":"400"})}};for(const r of s){const o=e.createElement("button");r.hint&&T(o,r.hint),o.type="button",o.textContent=r.label,o.dataset[p]=r.key,o.setAttribute("role","radio"),Object.assign(o.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(o,"bare"),o.addEventListener("click",()=>{u!==r.key&&g(r.key)}),d.push(o),l.appendChild(o)}return f(),l.addEventListener("keydown",r=>{if(r.key!=="ArrowLeft"&&r.key!=="ArrowRight")return;const o=d.indexOf(e.activeElement);if(o<0)return;r.preventDefault();const t=d[(o+(r.key==="ArrowRight"?1:-1)+d.length)%d.length];t.click(),t.focus()}),{el:l,set:r=>{u=r,f()}}}export function renderDataTables(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],l=g.filter(E),d=e.views??(c.length>1?["statistics","dies","wafers"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=d.includes(e.view)?e.view:d[0],r="wide",o=null;const t=()=>{o?.destroy(),o=renderDataSection({doc:i,items:c,testDefs:l,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:d,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,attributes:e.attributes,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(v=>v.dies),h=[],w=q(m,l,void 0,void 0,e.onSaveText,u,a.map(v=>({dies:v.dies})),void 0,"full");w&&h.push(w);const x=X(m,g,void 0,e.onSaveText,u);return x&&h.push(x),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:r,onDiesLayoutChange:a=>{r=a}}),s.replaceChildren(o.card)};return t(),{el:s,destroy:()=>o?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","dies","wafers"]:["statistics","dies"]})}
1
+ import{isYieldEligibleDie as O}from"../core/dies.js";import{testValue as W}from"../core/dieTable.js";import{metadataDisplayValue as I}from"../core/metadata.js";import{attributeLabel as z}from"../stats/facets.js";import{tableToTsv as A}from"../core/tableCsv.js";import{commonMetadata as H}from"../stats/facets.js";import{buildYieldData as Y}from"../stats/yield.js";import{isParametricTest as E}from"../renderer/buildWaferMap.js";import{fmt as G}from"../renderer/fmt.js";import{testLabel as N}from"../renderer/testLabel.js";import{resolveDieColumns as U}from"./dieList.js";import{createVirtualTable as R}from"./virtualTable.js";import{exportCsv as $}from"./tableExport.js";import{CLR as y,FONT as L,RADIUS as V,SPACE as C,controlStyle as K,wireControlHover as j,wireTooltip as T}from"./toolbar.js";import{buildTestSection as q,buildFunctionalTestSection as X}from"./summaryPanel.js";export const DATA_VIEWS=[{key:"statistics",label:"Statistics",hint:"One row per test: count, spread, limits and limit yield"},{key:"wafers",label:"Wafers",hint:"One row per wafer: its attributes, die counts, yield and test means"},{key:"dies",label:"Dies",hint:"One row per die, with its position, bins and every test"}],EXCEL_ROW_LIMIT=1048576,COPY_CELL_LIMIT=2e5,WAFER_TEST_COLUMNS=50;const D=(e,i,s=i+"s")=>`${e.toLocaleString()} ${e===1?i:s}`;export function renderDataSection(e){const{doc:i}=e,s=i.createElement("div");s.dataset.wmapDataTab="1",Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"});const c=i.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",gap:C.md,flexWrap:"wrap"}),s.appendChild(c);const p=i.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:C.md,minWidth:"0"}),s.appendChild(p);const g=DATA_VIEWS.filter(f=>!e.views||e.views.includes(f.key)),l=F(i,"Table",g,e.view,"wmapDataView",f=>e.onViewChange(f));c.appendChild(l.el);let d;switch(e.view){case"dies":d=Q(e);break;case"wafers":d=Z(e);break;default:d=J(e)}let u=()=>{};if(e.view==="dies"){const f=F(i,"Export format",[{key:"wide",label:"Wide",hint:"A column for each test"},{key:"long",label:"Long",hint:"A row for each die and test, the shape statistics tools prefer"}],e.diesLayout,"wmapDataLayout",t=>{f.set(t),e.onDiesLayoutChange(t),d.actions?.setLayout?.(t),u()});T(f.el,"Wide: a column per test. Long: a row per die per test, for tools that want tidy data. The table on screen is always wide.");const r=i.createElement("span");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.sm});const o=i.createElement("span");o.textContent="Export format:",Object.assign(o.style,{color:y.label,fontSize:L.body}),r.append(o,f.el),c.appendChild(r)}if(d.actions){const f=d.actions,r=i.createElement("div");r.style.flex="1",c.appendChild(r);const o=B(i,"Export CSV");o.dataset.wmapDataExport="1",o.addEventListener("click",()=>{if(o.disabled)return;const m=o.textContent,h=f.exportCsv();h&&(o.disabled=!0,o.setAttribute("aria-busy","true"),h.catch(()=>{}).finally(()=>{o.disabled=!1,o.removeAttribute("aria-busy"),o.textContent=m}))});const t=B(i,"Copy");t.dataset.wmapDataCopy="1",f.copyText?(T(t,"Copy the table as tab-separated text, to paste into a spreadsheet"),t.addEventListener("click",()=>{const m=f.copyText(),h=i.defaultView?.navigator?.clipboard;if(!h)return;const w=t.textContent;h.writeText(m).then(()=>{t.textContent="Copied",i.defaultView?.setTimeout(()=>{t.textContent=w},1500)}).catch(()=>{})})):(t.disabled=!0,T(t,`Too large to copy (over ${COPY_CELL_LIMIT.toLocaleString()} cells). Use Export CSV.`)),c.append(t,o);const a=i.createElement("div");a.dataset.wmapDataNote="1",a.textContent=f.note(),u=()=>{a.textContent=f.note()},Object.assign(a.style,{color:y.label,fontSize:L.body}),s.insertBefore(a,p)}return p.appendChild(d.el),{card:s,destroy:()=>d.destroy()}}function J(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:C.lg,minWidth:"0"});const c=[],p=e.groups&&e.groups.length>0?e.groups:void 0,g=p??[{key:"",items:e.items}];for(const l of g){if(p){const u=i.createElement("div");u.textContent=`${e.groupLabelText??"Group"}: ${l.key}`,Object.assign(u.style,{fontWeight:"700",color:y.text,fontSize:L.body}),s.appendChild(u)}const d=e.buildStatistics(l.items);c.push(d.destroy);for(const u of d.cards)s.appendChild(u)}return!s.querySelector("table")&&!s.textContent&&(s.textContent="No test statistics to show for these wafers.",Object.assign(s.style,{color:y.label,fontSize:L.body})),{el:s,destroy:()=>{for(const l of c)l()}}}function Q(e){const{doc:i,items:s}=e,c=new WeakMap,p=new WeakMap,g=new WeakMap,l=[];let d=!1;for(const n of s){n.wafer&&(d=!0);for(const b of n.dies)c.set(b,n.label),g.set(b,n.waferIndex),n.wafer&&p.set(b,n.wafer),l.push(b)}if(l.length===0)return M(i,"No dies to show.");const{columns:u,visibleColumns:f}=U(l,e.allTestDefs,{...e.dieListOptions,metadataFields:e.metadataFields,extraColumn:s.length>1||e.population?{label:"Wafer",get:n=>c.get(n)}:void 0,getWafer:d?(n=>p.get(n)):void 0,ringCount:e.ringCount,waferMetadata:s.some(n=>n.wafer)?H(s.map(n=>({metadata:n.wafer?.metadata}))):void 0,ownerDocument:i}),r=f.map(n=>({header:n.label,get:n.get,numeric:n.test!==void 0&&E(n.test),...n.test!==void 0&&E(n.test)?{sortKey:b=>W(b,n.test.testNumber)}:{}})),o=R({columns:r,rows:l,ariaLabel:`Dies (${l.length})`,ownerDocument:i,onRowClick:e.onLocateDie?n=>e.onLocateDie(n,g.get(n)):void 0});o.el.style.maxHeight="70vh",o.el.style.minHeight="240px";const t=e.population?`-${e.population.fileTag}`:"",a=u.filter(n=>n.test!==void 0),m=u.filter(n=>n.test===void 0),h=l.length*u.length,w=l.length*a.length,x=()=>u.map(n=>({header:n.csvLabel??n.label,get:n.csvGet??n.get})),v=()=>[...m.map(n=>({header:n.csvLabel??n.label,get:b=>(n.csvGet??n.get)(b.die)})),{header:"Test",get:n=>N(n.test,n.test.testNumber)},{header:"Test number",get:n=>n.test.testNumber},{header:"Unit",get:n=>n.test.unit??""},{header:"Value",get:n=>n.value}];function*_(){for(const n of o.orderedRows())for(const b of a){const S=(b.csvGet??b.get)(n);S===""||S===void 0||S===null||(yield{die:n,test:b.test,value:S})}}let k=e.diesLayout==="long"&&a.length>0;const P=()=>k?`Long format: up to ${D(w,"row")} (a die with no result for a test has no row)`+(w>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()}).`:"."):`Wide format: ${D(l.length,"row")} \xD7 ${D(u.length,"column")}`+(l.length>EXCEL_ROW_LIMIT?` \u2014 more than Excel opens (${EXCEL_ROW_LIMIT.toLocaleString()} rows).`:".");return{el:o.el,destroy:()=>o.destroy(),actions:{note:()=>`${D(l.length,"die")} ${e.population?.phrase??`on ${D(s.length,"wafer")}`}. ${P()} Export follows the order shown.${e.onLocateDie?" Click a row to show that die on the map.":""}`,setLayout:n=>{k=n==="long"&&a.length>0},exportCsv:()=>k?$(v(),_(),`die-list-long${t}.csv`,e.onSaveText,{rowCount:w}):$(x(),o.orderedRows(),`die-list${t}.csv`,e.onSaveText,{rowCount:l.length}),copyText:h<=COPY_CELL_LIMIT?()=>A(x(),o.orderedRows()):null}}}function Z(e){const{doc:i,items:s}=e;if(s.length===0)return M(i,"No wafers to show.");const c=s.map(t=>{const a=e.yieldByWaferIndex.get(t.waferIndex),m=Y([{label:t.label,dies:t.dies,passBins:t.passBins,yieldPercent:a,key:t.waferIndex}])[0]?.percent;return{item:t,yieldPercent:t.dies.length?m??null:null}}),p=[];for(const{item:t}of c)for(const a of Object.keys(t.wafer?.metadata??{}))!p.includes(a)&&I((t.wafer?.metadata)[a])!==void 0&&p.push(a);const g=e.testDefs.slice(0,WAFER_TEST_COLUMNS),l=(t,a)=>{const m=t.item.statsSummary?.stats.perTestStats?.find(x=>x.testNumber===a.testNumber);if(m)return m.mean;let h=0,w=0;for(const x of t.item.dies){if(!O(x))continue;const v=W(x,a.testNumber);v!==void 0&&Number.isFinite(v)&&(h++,w+=v)}return h?w/h:void 0},d=[{header:"Wafer",cell:t=>t.item.label},...p.map(t=>({header:z(t,e.attributes),cell:a=>I(a.item.wafer?.metadata?.[t])??""})),{header:"Dies",cell:t=>t.item.dies.length,numeric:!0},{header:"Yield-eligible dies",cell:t=>t.item.dies.filter(a=>O(a)).length,numeric:!0},{header:"Yield %",cell:t=>t.yieldPercent===null?"":t.yieldPercent,show:t=>t.yieldPercent===null?"":t.yieldPercent.toFixed(1),numeric:!0},...g.map(t=>({header:`${N(t,t.testNumber)}${t.unit?` (${t.unit})`:""} mean`,cell:a=>l(a,t),show:a=>{const m=l(a,t);return m===void 0?"":G(m,t.unit)},numeric:!0}))],u=d.map(t=>({header:t.header,get:a=>t.show?t.show(a):String(t.cell(a)??""),numeric:t.numeric,...t.numeric?{sortKey:a=>{const m=t.cell(a);return typeof m=="number"?m:void 0}}:{}})),f=R({columns:u,rows:c,ariaLabel:`Wafers (${c.length})`,ownerDocument:i,onRowClick:e.onOpenWafer?t=>e.onOpenWafer(t.item.waferIndex,t.item.label):void 0});f.el.style.maxHeight="70vh",f.el.style.minHeight="120px";const r=()=>d.map(t=>({header:t.header,get:t.cell})),o=e.testDefs.length>g.length?` Mean columns cover the first ${g.length} of ${e.testDefs.length} tests.`:"";return{el:f.el,destroy:()=>f.destroy(),actions:{note:()=>`${D(c.length,"wafer")}.${o}${e.onOpenWafer?" Click a row to open that wafer.":""} Export follows the order shown.`,exportCsv:()=>$(r(),f.orderedRows(),"wafers.csv",e.onSaveText,{rowCount:c.length}),copyText:c.length*d.length<=COPY_CELL_LIMIT?()=>A(r(),f.orderedRows()):null}}}function M(e,i){const s=e.createElement("div");return s.textContent=i,Object.assign(s.style,{color:y.label,fontSize:L.body,padding:C.md}),{el:s,destroy:()=>{}}}function B(e,i){const s=e.createElement("button");return s.type="button",s.textContent=i,Object.assign(s.style,{fontSize:L.body,padding:"3px 10px",borderRadius:V.control,...K("outlined"),background:y.menuBg}),j(s),s}function F(e,i,s,c,p,g){const l=e.createElement("div");l.setAttribute("role","radiogroup"),l.setAttribute("aria-label",i),Object.assign(l.style,{display:"inline-flex",background:y.menuBg,border:`1px solid ${y.menuBorder}`,borderRadius:V.control,overflow:"hidden"});const d=[];let u=c;const f=()=>{for(const r of d){const o=r.dataset[p]===u;r.setAttribute("aria-checked",String(o)),r.tabIndex=o?0:-1,Object.assign(r.style,{background:o?y.bgActive:"transparent",color:o?y.iconActive:y.label,fontWeight:o?"600":"400"})}};for(const r of s){const o=e.createElement("button");r.hint&&T(o,r.hint),o.type="button",o.textContent=r.label,o.dataset[p]=r.key,o.setAttribute("role","radio"),Object.assign(o.style,{border:"none",cursor:"pointer",fontSize:L.body,padding:`${C.xs} ${C.md}`,whiteSpace:"nowrap"}),j(o,"bare"),o.addEventListener("click",()=>{u!==r.key&&g(r.key)}),d.push(o),l.appendChild(o)}return f(),l.addEventListener("keydown",r=>{if(r.key!=="ArrowLeft"&&r.key!=="ArrowRight")return;const o=d.indexOf(e.activeElement);if(o<0)return;r.preventDefault();const t=d[(o+(r.key==="ArrowRight"?1:-1)+d.length)%d.length];t.click(),t.focus()}),{el:l,set:r=>{u=r,f()}}}export function renderDataTables(e){const{doc:i}=e,s=i.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1",padding:C.md});const c=e.items.map((a,m)=>({...a,waferIndex:a.waferIndex??m})),p=c.flatMap(a=>a.dies),g=e.testDefs??[],l=g.filter(E),d=e.views??(c.length>1?["statistics","wafers","dies"]:["statistics","dies"]),u=e.population?{populationLabel:`${D(p.length,"die")} ${e.population}`}:c.length>1?{perWaferMetadata:c.map(a=>a.wafer?.metadata??{}),populationLabel:`${D(c.length,"wafer")} pooled`}:{waferMetadata:c[0]?.wafer?.metadata};let f=d.includes(e.view)?e.view:d[0],r="wide",o=null;const t=()=>{o?.destroy(),o=renderDataSection({doc:i,items:c,testDefs:l,allTestDefs:g,ringCount:e.ringCount,yieldByWaferIndex:new Map,onSaveText:e.onSaveText,views:d,view:f,dieListOptions:e.dieListOptions,metadataFields:e.metadataFields,attributes:e.attributes,onLocateDie:e.onLocateDie,population:e.population?{phrase:e.population,fileTag:"selection"}:void 0,buildStatistics:a=>{const m=a.flatMap(v=>v.dies),h=[],w=q(m,l,void 0,void 0,e.onSaveText,u,a.map(v=>({dies:v.dies})),void 0,"full");w&&h.push(w);const x=X(m,g,void 0,e.onSaveText,u);return x&&h.push(x),{cards:h,destroy:()=>{}}},onViewChange:a=>{f=a,t()},diesLayout:r,onDiesLayoutChange:a=>{r=a}}),s.replaceChildren(o.card)};return t(),{el:s,destroy:()=>o?.destroy()}}export function renderSelectionTables(e){return renderDataTables({...e,views:e.items.length>1?["statistics","wafers","dies"]:["statistics","dies"]})}
@@ -1 +1 @@
1
- import{isYieldEligibleDie as P}from"../core/dies.js";import{testValue as k}from"../core/dieTable.js";import{isParametricTest as C}from"../renderer/buildWaferMap.js";import{buildSweepData as L}from"../stats/sweep.js";import{plotToSweep as x}from"../stats/plotSpec.js";import{renderHistogramPanel as O}from"./charts/histogram.js";import{renderCapabilityPanel as W}from"./charts/capability.js";import{openChartExpandModal as A,populationPhrase as D}from"./charts/chartShell.js";import{buildCheckMenuEl as F,createToolbarHelpers as V,getTooltip as H,menuLayerFor as j,wireMenuA11y as q,CLR as z,FONT as B,SPACE as M,openReparentedModal as _,controlStyle as K,wireControlHover as U}from"./toolbar.js";import{requireRingCount as Y}from"../core/ringCount.js";import{defaultPlot as G,defaultSweep as J,fieldCatalogue as Q,plotTitle as X,resolvePlot as Z}from"../stats/plotData.js";import{newPlotId as y}from"../stats/plotSpec.js";import{sourceFromPoints as ee,toPlotItems as S}from"./plotItems.js";const E=30,g=e=>e.items.flatMap(t=>t.dies);function te(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>P(n))}))}function N(e,t,n){return(e.testDefs??[]).filter(C).map(a=>a.testNumber).filter(a=>{let o=0;for(const s of t){const d=k(s,a);if(d!==void 0&&Number.isFinite(d)&&++o>=n)return!0}return!1})}function $(e,t,n,a,o,s){const d=e.ownerDocument,l=d.createElement("div"),f=d.createElement("span");f.textContent=n,f.dataset.wmapPopulation="1",Object.assign(l.style,{color:z.label,fontSize:B.body,marginBottom:M.sm,display:"flex",alignItems:"center",gap:M.lg,flexWrap:"wrap"}),l.appendChild(f);let h=null;if(s){const c=d.createElement("button");c.type="button",c.textContent=s.label,c.dataset[s.hook]="1",Object.assign(c.style,K("outlined")),U(c),c.addEventListener("click",()=>s.run(()=>h?.close())),l.appendChild(c)}const i=e.querySelector("[data-wmap-chart-expand]")?.parentElement;i?.parentElement===e?i.after(l):e.prepend(l),h=A(e,t,{anchor:a,onClosed:o})}function ne(e,t){const n=g(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(o=>P(o))?L(n,t.testDefs,e).series.some(o=>o.points.some(s=>s.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function oe(e,t,n){const a=te(e),o=g(e).length,s=a.flatMap(r=>r.dies),d=D(s.length,o,e.population),l=(e.testDefs??[]).filter(C),f=n.ownerDocument,h=(r,p)=>e.notMeasuredReason?e.notMeasuredReason:s.length===0?"These dies are all partial or edge-excluded, which charts leave out":N(e,s,r).length>0?null:p,i={section:"Distributions",label:"Value histogram",unavailable:h(1,"These dies have no parametric test values"),open:()=>{let r=e.activeTest??l[0]?.testNumber;const p=O({title:"Value histogram",items:a,testDefs:l,selectedTestNumber:e.activeTest,onTestChange:m=>{r=m},onSaveImage:t.onSaveImage,ownerDocument:f}),u=I(e,t,n),b=u&&r!==void 0?{label:"Edit as new plot",hook:"wmapEditAsPlot",run:m=>{const w=l.find(v=>v.testNumber===r);m(),u({id:y(),chart:"histogram",fields:{y:{test:r,...w?.name?{name:w.name}:{}},color:{none:!0}}},!0)()}}:void 0;$(p.card,`Value histogram \u2014 ${d}`,`Population: ${d}`,n,()=>p.destroy(),b)}},c={section:"Distributions",label:"Process capability",unavailable:h(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const r=W({title:"Process capability",items:a,testDefs:l,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:f}),p=s.length<E?` \xB7 fewer than ${E} dies, so each Ppk is a rough estimate`:"";$(r.card,`Process capability \u2014 ${d}`,`Population: ${d}${p}`,n,()=>r.destroy())}};return[i,c]}function I(e,t,n){const a=t.plots;if(!a)return null;const o=n.ownerDocument,s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=D(l.length,l.length,e.population),h=D(l.filter(i=>P(i)).length,l.length,e.population);return(i,c)=>()=>{const r=i.chart==="sweep",p=r?h:f;import("./plotModal.js").then(({openPlotEditor:u})=>u({doc:o,anchor:n,store:a,plot:i,draft:c,items:s,ctx:d,population:p,rawPopulation:e.population,title:`${c?r?"New sweep":"New plot":r?"Sweep":"Plot"} \u2014 ${p}`,chart:{onSaveImage:t.onSaveImage,onSelectPoints:(b,m,w)=>{const v=ee(b,s,e.testDefs);v&&openDrilldownMenu(m,w,v,t)}}}))}}function se(e,t,n){const a=t.plots,o=I(e,t,n);if(!a||!o)return[];const s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=e.notMeasuredReason??(l.length===0?"Nothing is selected":null),h=a.get().map(p=>{const u=x(p);if(u)return{section:"Plots",label:u.title,unavailable:ne(u,e),open:o(p,!1)};const b=Z(p,s,d);return{section:"Plots",label:X(b)||"Plot",unavailable:f??b.issues[0]??(b.plotted===0?"No die here has the values this plot needs":null),open:o(p,!1)}}),i=Q(s,d),c=i.some(p=>p.group==="Tests");h.push({section:"Plots",label:"New plot\u2026",unavailable:f??(c?null:"These dies have no parametric test values"),open:o(G(i,y()),!0)});const r=(e.testDefs??[]).filter(p=>C(p));return h.push({section:"Plots",label:"New sweep\u2026",unavailable:f??(r.length>0?null:"These dies have no parametric test values"),open:o(J(e.testDefs??[],y()),!0)}),h}function ae(e,t,n){const a=g(e),o=e.notMeasuredReason??(a.length===0?"Nothing is selected":null),s=a.length,d=D(s,s,e.population),l=(f,h)=>()=>{import("./dataTab.js").then(({renderSelectionTables:i})=>{const c=n.ownerDocument;let r;const p=i({doc:c,ringCount:Y(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:f,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(b,m)=>{r?.(),t.onLocateDie(b,m)}:void 0}),u=_([p.el],{title:`${h} \u2014 ${d}`,anchor:n,ownerDocument:c,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:p.destroy});u?r=()=>u.close():p.destroy()})};return[{section:"Tables",label:"Dies",unavailable:o,open:l("dies","Dies")},{section:"Tables",label:"Test statistics",unavailable:o??(N(e,a,1).length>0?null:"These dies have no parametric test values"),open:l("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:o,open:l("wafers","Wafers")}]:[]]}function le(e,t,n){return[...oe(e,t,n),...se(e,t,n),...ae(e,t,n)]}const T=new WeakMap;export function openDrilldownMenu(e,t,n,a){const o=t.ownerDocument,s=o.defaultView??window;T.get(o)?.();const d=le(n,a,t),l=[];if(a.narrower){const{label:m,source:w,ctx:v}=a.narrower,R={label:`${a.narrower.backLabel??"All selected"} \u2014 ${D(g(n).length,g(n).length,n.population)}`,source:n,ctx:a};l.push({section:"Dies"}),l.push({label:m,active:!1,action:!0,enabled:!0,onClick:()=>{u(),openDrilldownMenu(e,t,w,{...v??a,narrower:R})}})}let f;for(const m of d)m.section!==f&&(l.push({section:m.section}),f=m.section),l.push({label:m.label,active:!1,action:!0,enabled:m.unavailable===null,disabledHint:m.unavailable??void 0,onClick:()=>{u(),m.open()}});const{makeMenuSection:h}=V(H(o)),i=F(new DOMRect(e.x,e.y-4,0,0),l,{makeMenuSection:h},s),c=g(n).length;i.setAttribute("role","menu"),i.setAttribute("aria-label",`Open a chart or table of ${D(c,c,n.population)}`),i.dataset.wmapDrilldownMenu="1",j(t).appendChild(i);const r=i.getBoundingClientRect();r.bottom>s.innerHeight-4&&(i.style.top=`${Math.max(4,e.y-r.height)}px`),r.right>s.innerWidth-4&&(i.style.left=`${Math.max(4,s.innerWidth-r.width-4)}px`);let p=!1;function u(){p||(p=!0,i.remove(),o.removeEventListener("pointerdown",b,!0),s.removeEventListener("blur",u),T.get(o)===u&&T.delete(o))}function b(m){i.contains(m.target)||u()}return o.addEventListener("pointerdown",b,!0),s.addEventListener("blur",u),q(i,t,u),T.set(o,u),u}
1
+ import{isYieldEligibleDie as P}from"../core/dies.js";import{testValue as k}from"../core/dieTable.js";import{isParametricTest as C}from"../renderer/buildWaferMap.js";import{buildSweepData as L}from"../stats/sweep.js";import{plotToSweep as x}from"../stats/plotSpec.js";import{renderHistogramPanel as O}from"./charts/histogram.js";import{renderCapabilityPanel as W}from"./charts/capability.js";import{openChartExpandModal as A,populationPhrase as D}from"./charts/chartShell.js";import{buildCheckMenuEl as F,createToolbarHelpers as V,getTooltip as H,menuLayerFor as j,wireMenuA11y as q,CLR as z,FONT as B,SPACE as M,openReparentedModal as _,controlStyle as K,wireControlHover as U}from"./toolbar.js";import{requireRingCount as Y}from"../core/ringCount.js";import{defaultPlot as G,defaultSweep as J,fieldCatalogue as Q,plotTitle as X,resolvePlot as Z}from"../stats/plotData.js";import{newPlotId as y}from"../stats/plotSpec.js";import{sourceFromPoints as ee,toPlotItems as S}from"./plotItems.js";const E=30,g=e=>e.items.flatMap(t=>t.dies);function te(e){return e.items.map(t=>({...t,dies:t.dies.filter(n=>P(n))}))}function N(e,t,n){return(e.testDefs??[]).filter(C).map(a=>a.testNumber).filter(a=>{let o=0;for(const s of t){const d=k(s,a);if(d!==void 0&&Number.isFinite(d)&&++o>=n)return!0}return!1})}function $(e,t,n,a,o,s){const d=e.ownerDocument,l=d.createElement("div"),f=d.createElement("span");f.textContent=n,f.dataset.wmapPopulation="1",Object.assign(l.style,{color:z.label,fontSize:B.body,marginBottom:M.sm,display:"flex",alignItems:"center",gap:M.lg,flexWrap:"wrap"}),l.appendChild(f);let h=null;if(s){const c=d.createElement("button");c.type="button",c.textContent=s.label,c.dataset[s.hook]="1",Object.assign(c.style,K("outlined")),U(c),c.addEventListener("click",()=>s.run(()=>h?.close())),l.appendChild(c)}const i=e.querySelector("[data-wmap-chart-expand]")?.parentElement;i?.parentElement===e?i.after(l):e.prepend(l),h=A(e,t,{anchor:a,onClosed:o})}function ne(e,t){const n=g(t);return t.notMeasuredReason?t.notMeasuredReason:n.some(o=>P(o))?L(n,t.testDefs,e).series.some(o=>o.points.some(s=>s.count>0))?null:"These dies have no values for this sweep\u2019s tests":"These dies are all partial or edge-excluded, which charts leave out"}function oe(e,t,n){const a=te(e),o=g(e).length,s=a.flatMap(r=>r.dies),d=D(s.length,o,e.population),l=(e.testDefs??[]).filter(C),f=n.ownerDocument,h=(r,p)=>e.notMeasuredReason?e.notMeasuredReason:s.length===0?"These dies are all partial or edge-excluded, which charts leave out":N(e,s,r).length>0?null:p,i={section:"Distributions",label:"Value histogram",unavailable:h(1,"These dies have no parametric test values"),open:()=>{let r=e.activeTest??l[0]?.testNumber;const p=O({title:"Value histogram",items:a,testDefs:l,selectedTestNumber:e.activeTest,onTestChange:m=>{r=m},onSaveImage:t.onSaveImage,ownerDocument:f}),u=I(e,t,n),b=u&&r!==void 0?{label:"Edit as new plot",hook:"wmapEditAsPlot",run:m=>{const w=l.find(v=>v.testNumber===r);m(),u({id:y(),chart:"histogram",fields:{y:{test:r,...w?.name?{name:w.name}:{}},color:{none:!0}}},!0)()}}:void 0;$(p.card,`Value histogram \u2014 ${d}`,`Population: ${d}`,n,()=>p.destroy(),b)}},c={section:"Distributions",label:"Process capability",unavailable:h(2,"Needs at least 2 of these dies with values for one test"),open:()=>{const r=W({title:"Process capability",items:a,testDefs:l,selectedTestNumber:e.activeTest,onSaveImage:t.onSaveImage,ownerDocument:f}),p=s.length<E?` \xB7 fewer than ${E} dies, so each Ppk is a rough estimate`:"";$(r.card,`Process capability \u2014 ${d}`,`Population: ${d}${p}`,n,()=>r.destroy())}};return[i,c]}function I(e,t,n){const a=t.plots;if(!a)return null;const o=n.ownerDocument,s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=D(l.length,l.length,e.population),h=D(l.filter(i=>P(i)).length,l.length,e.population);return(i,c)=>()=>{const r=i.chart==="sweep",p=r?h:f;import("./plotModal.js").then(({openPlotEditor:u})=>u({doc:o,anchor:n,store:a,plot:i,draft:c,items:s,ctx:d,population:p,rawPopulation:e.population,title:`${c?r?"New sweep":"New plot":r?"Sweep":"Plot"} \u2014 ${p}`,chart:{onSaveImage:t.onSaveImage,onSelectPoints:(b,m,w)=>{const v=ee(b,s,e.testDefs);v&&openDrilldownMenu(m,w,v,t)}}}))}}function se(e,t,n){const a=t.plots,o=I(e,t,n);if(!a||!o)return[];const s=S(e.items),d={testDefs:e.testDefs,curation:t.attributes},l=g(e),f=e.notMeasuredReason??(l.length===0?"Nothing is selected":null),h=a.get().map(p=>{const u=x(p);if(u)return{section:"Plots",label:u.title,unavailable:ne(u,e),open:o(p,!1)};const b=Z(p,s,d);return{section:"Plots",label:X(b)||"Plot",unavailable:f??b.issues[0]??(b.plotted===0?"No die here has the values this plot needs":null),open:o(p,!1)}}),i=Q(s,d),c=i.some(p=>p.group==="Tests");h.push({section:"Plots",label:"New plot\u2026",unavailable:f??(c?null:"These dies have no parametric test values"),open:o(G(i,y()),!0)});const r=(e.testDefs??[]).filter(p=>C(p));return h.push({section:"Plots",label:"New sweep\u2026",unavailable:f??(r.length>0?null:"These dies have no parametric test values"),open:o(J(e.testDefs??[],y()),!0)}),h}function ae(e,t,n){const a=g(e),o=e.notMeasuredReason??(a.length===0?"Nothing is selected":null),s=a.length,d=D(s,s,e.population),l=(f,h)=>()=>{import("./dataTab.js").then(({renderSelectionTables:i})=>{const c=n.ownerDocument;let r;const p=i({doc:c,ringCount:Y(e.items[0],"the drilldown tables"),items:e.items,testDefs:e.testDefs,population:e.population,view:f,onSaveText:t.onSaveText,onLocateDie:t.onLocateDie?(b,m)=>{r?.(),t.onLocateDie(b,m)}:void 0}),u=_([p.el],{title:`${h} \u2014 ${d}`,anchor:n,ownerDocument:c,boxSize:{width:"min(96vw, 1200px)",height:"min(92vh, 780px)"},onClosed:p.destroy});u?r=()=>u.close():p.destroy()})};return[{section:"Tables",label:"Test statistics",unavailable:o??(N(e,a,1).length>0?null:"These dies have no parametric test values"),open:l("statistics","Test statistics")},...e.items.length>1?[{section:"Tables",label:"Wafers",unavailable:o,open:l("wafers","Wafers")}]:[],{section:"Tables",label:"Dies",unavailable:o,open:l("dies","Dies")}]}function le(e,t,n){return[...oe(e,t,n),...se(e,t,n),...ae(e,t,n)]}const T=new WeakMap;export function openDrilldownMenu(e,t,n,a){const o=t.ownerDocument,s=o.defaultView??window;T.get(o)?.();const d=le(n,a,t),l=[];if(a.narrower){const{label:m,source:w,ctx:v}=a.narrower,R={label:`${a.narrower.backLabel??"All selected"} \u2014 ${D(g(n).length,g(n).length,n.population)}`,source:n,ctx:a};l.push({section:"Dies"}),l.push({label:m,active:!1,action:!0,enabled:!0,onClick:()=>{u(),openDrilldownMenu(e,t,w,{...v??a,narrower:R})}})}let f;for(const m of d)m.section!==f&&(l.push({section:m.section}),f=m.section),l.push({label:m.label,active:!1,action:!0,enabled:m.unavailable===null,disabledHint:m.unavailable??void 0,onClick:()=>{u(),m.open()}});const{makeMenuSection:h}=V(H(o)),i=F(new DOMRect(e.x,e.y-4,0,0),l,{makeMenuSection:h},s),c=g(n).length;i.setAttribute("role","menu"),i.setAttribute("aria-label",`Open a chart or table of ${D(c,c,n.population)}`),i.dataset.wmapDrilldownMenu="1",j(t).appendChild(i);const r=i.getBoundingClientRect();r.bottom>s.innerHeight-4&&(i.style.top=`${Math.max(4,e.y-r.height)}px`),r.right>s.innerWidth-4&&(i.style.left=`${Math.max(4,s.innerWidth-r.width-4)}px`);let p=!1;function u(){p||(p=!0,i.remove(),o.removeEventListener("pointerdown",b,!0),s.removeEventListener("blur",u),T.get(o)===u&&T.delete(o))}function b(m){i.contains(m.target)||u()}return o.addEventListener("pointerdown",b,!0),s.addEventListener("blur",u),q(i,t,u),T.set(o,u),u}
@@ -2,6 +2,7 @@ export { WMAP_VERSION, WMAP_BUILD_TIME } from './version.js';
2
2
  export type { ToCanvasOptions, ViewportTransform } from './toCanvas.js';
3
3
  export { renderWaferMap } from './renderWaferMap.js';
4
4
  export type { RenderOptions, WaferMapController, WaferViewOptions, WaferPreferences, WaferDisplayState } from './renderWaferMap.js';
5
+ export { WAFER_PREFERENCE_KEYS } from './renderWaferMap.js';
5
6
  export { renderWaferGallery } from './renderWaferGallery.js';
6
7
  export type { WaferMapDisplayItem, WaferMapDisplayItemFactory, GalleryOptions, GalleryController } from './renderWaferGallery.js';
7
8
  export type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
@@ -1 +1 @@
1
- export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
1
+ export{WMAP_VERSION,WMAP_BUILD_TIME}from"./version.js";export{renderWaferMap}from"./renderWaferMap.js";export{WAFER_PREFERENCE_KEYS}from"./renderWaferMap.js";export{renderWaferGallery}from"./renderWaferGallery.js";export{collectWarnings,severityOf}from"./warnings.js";export{setDetachWindowOpener}from"./toolbar.js";export{openWaferMapGuide}from"./guideWindow.js";export{ICONS}from"./icons.js";export{openReportModal}from"./guideWindow.js";
@@ -9,6 +9,7 @@ import type { PlotSpec } from '../stats/plotSpec.js';
9
9
  import type { BinColors } from '../renderer/binColors.js';
10
10
  import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
11
11
  import type { SweepSpec } from '../stats/sweep.js';
12
+ import { type AxisPrefs } from './charts/chartShell.js';
12
13
  export type InsightsView = 'overview' | 'distributions' | 'correlation' | 'sweeps' | 'data' | 'plot';
13
14
  /** Public option shape for `RenderOptions.insights`/`GalleryOptions.insights`. */
14
15
  export interface InsightsOptions {
@@ -83,6 +84,10 @@ export interface InsightsOptions {
83
84
  defaultOpen?: boolean;
84
85
  }
85
86
  export interface InsightsTabDeps {
87
+ /** The charts' axis settings to start from: the host's `chart*` preferences (see `axisPrefsFromOptions`). */
88
+ initialAxisPrefs?: AxisPrefs;
89
+ /** Called when the reader changes an axis setting, so the renderer can report it as a preference. */
90
+ onAxisPrefsChange?: (prefs: AxisPrefs) => void;
86
91
  /** The host's own wafer attributes (`attributes` on the render options): what Group by offers and calls each, the plot fields, the Wafers table's columns and the strip. Over the defaults. */
87
92
  attributes?: Record<string, FacetCuration>;
88
93
  /** Current gallery/single-wafer items — read fresh each render (a gallery's list can still be building). `null` entries (not-yet-built cards) are skipped. */
@@ -185,6 +190,8 @@ export interface InsightsTabHandle {
185
190
  render: () => void;
186
191
  /** Tears down every live panel's observers and removes `el`. */
187
192
  destroy: () => void;
193
+ /** Adopt axis settings set from outside (the host's `setOptions`), in every chart. */
194
+ setAxisPrefs: (prefs: AxisPrefs) => void;
188
195
  }
189
196
  type Item = FacetItem & {
190
197
  dies: Die[];
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as qe}from"../stats/presentation.js";import{buildFacetTable as Ke,facetValueOf as Qe,FACET_NONE_VALUE as Xe,DEFAULT_FACET_CURATION as Je}from"../stats/facets.js";import{mergeTestDefs as Se}from"../stats/mergeTestDefs.js";import{isParametricTest as xe}from"../renderer/buildWaferMap.js";import{dieFailsTest as Ze}from"../stats/testPassRate.js";import{fmt as ke}from"../renderer/fmt.js";import{testLabel as et}from"../renderer/testLabel.js";import{waferDisplayLabel as tt,waferIdentityLabel as nt}from"../core/waferLabel.js";import{waferPopulation as ot}from"./chartPopulation.js";import{openDrilldownMenu as se}from"./drilldown.js";import{plotStoreFor as it}from"./plotStore.js";import{itemPassBins as rt,passBinsLabel as Te}from"../core/passBins.js";import{NO_DATA_FILL as ve}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as st}from"../stats/population.js";import{LEADING as lt,ALPHA as dt,SPACE as T,EDGE_GUTTER as le,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as de,wireTooltip as ft}from"./toolbar.js";import{ICONS as mt}from"./icons.js";import{renderCapabilityPanel as bt}from"./charts/capability.js";import{renderBoxplotPanel as ht}from"./charts/boxplot.js";import{renderTrendPanel as gt}from"./charts/trend.js";import{renderHistogramPanel as yt}from"./charts/histogram.js";import{renderCorrelationPanel as wt}from"./charts/correlation.js";import{renderScatterPanel as Ct}from"./charts/scatter.js";import{renderBarPanel as De}from"./charts/barPanel.js";import{renderBinClusterPanel as St}from"./charts/binCluster.js";import{renderTestPassRatePanel as xt}from"./charts/testPassRate.js";import{QUANTITY as kt}from"./charts/palette.js";import{cardFrameStyle as Tt,makeChartGridWrap as ce,makeLabeledSelect as vt,makeLinkedGroupSelect as Dt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as Be}from"../stats/yield.js";import{buildBinParetoData as Bt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as $t,buildLotFunctionalSection as Lt,buildMetadataStripBox as It}from"./summaryPanel.js";import{runChunked as Et}from"./chunked.js";import{buildRegionYieldData as ue,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as Pt,diesInRegion as At}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as pe}from"./charts/regionYieldDiagram.js";const Wt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Mt={key:"data",label:"Data"},Ft={key:"plot",label:"Plot"};export function createInsightsTab(v){const{getItems:Ie,getLotStats:fe,getBinColors:me,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,be={...Je,...v.attributes},Ee=v.showMetadataStrip??!0,z=v.contentInset??le,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Pe=le,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Pe});const E=f.createElement("div");Object.assign(E.style,{display:"flex",gap:T.xs,alignItems:"center",background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:ct.container,boxShadow:ut.panel,padding:`0 ${T.lg}`,marginBottom:T.lg,marginLeft:z,marginRight:z}),E.setAttribute("role","tablist"),E.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(E.querySelectorAll('[role="tab"]')),r=n.indexOf(f.activeElement);if(r===-1)return;e.preventDefault();const l=n[(r+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];l.focus(),l.click()});const U=f.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:T.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),Y.appendChild(j),Y.appendChild(E),Y.appendChild(U);const Ae=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,he="statistics",ge="wide",P=null,A=null,K={includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,ye=(e,n)=>{K=e;for(const r of ee.values())for(const l of r)l!==n&&l.setAxisPrefs(e)},te=e=>{A!==e&&(A=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function ne(e,n,r){R?.(e,n,r)}function oe(e){return(n,r,l)=>{const i=e.find(c=>c.waferIndex===n);if(!i)return;l.preventDefault();const u=ot(i.dies,{waferLabel:i.identity,testDefs:i.testDefs,activeTest:r??P??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});se({x:l.clientX,y:l.clientY},l.target,u,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}}function Q(e,n,r,l,i){Ce({x:e.clientX,y:e.clientY},e.target,n,r,l,i)}function Ce(e,n,r,l,i,u){const c=Rt(r.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:N()})),l,i,Se(r).defs,u);c&&se(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function ie(e){return R?{open:(n,r)=>ne(n,`Wafer ${e.find(l=>l.waferIndex===n)?.label??n}`,r)}:Z&&e.length===1?{open:(n,r)=>Z(r),label:"show this test on the map"}:null}function Oe(){return Ie().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:tt(e,n),identity:nt(e),waferIndex:n,passBins:rt(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Re(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${$.iconActive}`:"2px solid transparent",color:n?$.iconActive:$.label,fontWeight:n?"700":"500",fontSize:F.body,padding:`${T.sm} ${le} ${T.md}`,cursor:"pointer",marginBottom:"-1px"})}function We(e,n){const r=f.createElement("button");r.type="button",r.textContent=n;const l=e===L;return Re(r,l),r.dataset.on=l?"true":"false",de(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",l?"true":"false"),r.tabIndex=l?0:-1,r.addEventListener("click",()=>{L!==e&&(L=e,H({keepSections:!0}))}),r}function Me(e,n,r,l=!0){const i=ce(f),u=me();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=fe?.(),m=new Map(d?.lotYieldSeries.map(p=>[p.waferIndex,p.yieldPercent])),a=p=>({...p,label:p.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(p.waferIndex),key:p.waferIndex}),b=e.map(a),y=n?.map(p=>({key:p.key,items:p.items.map(a)})),w=()=>y?Be(y,c):J(b,c),t={title:n?`Yield by ${s} (pass: ${h})`:`Yield by wafer (pass: ${h})`,data:w(),selfControl:{current:c,options:[["yield","Sort: yield"],["label",n?`Sort: ${s}`:"Sort: wafer ID"]],onChange:p=>(c=p,{data:w()})},barColor:()=>kt,valueLabel:p=>`${p.percent.toFixed(1)}%`,reference:p=>{if(p.length<3)return null;const S=p.map(I=>I.percent).sort((I,_)=>I-_),B=S.length%2?S[(S.length-1)/2]:(S[S.length/2-1]+S[S.length/2])/2;return{value:B,label:`median ${B.toFixed(1)}%`}},drill:y?{onOpenGroup:p=>{const S=y.find(B=>B.key===p.label)?.items??[];return{data:J(S,c),title:`Yield by wafer \u2014 ${s}: ${p.label} (pass: ${h})`}},onBack:()=>({data:w(),title:`Yield by ${s} (pass: ${h})`}),groupLabelText:s}:void 0,onOpen:R?p=>{typeof p.key=="number"&&ne(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:oe(e),ownerDocument:f};let o=null;if(l&&(o=De(t,k),o.card.style.minHeight="360px",i.appendChild(o.card)),n){const p=St({title:"Hard bin pareto",groups:n.map(S=>({key:S.key,items:S.items.map(B=>({dies:B.dies,hardBinCounts:B.statsSummary?.stats.hardBinCounts,softBinCounts:B.statsSummary?.stats.softBinCounts}))})),onSelectBin:(S,B)=>{const I=n.find(X=>X.key===S.groupKey);if(!I)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,I.items,`in ${_} bin ${S.bin} of ${S.groupKey}`,X=>(S.binType==="hbin"?X.hbin:X.sbin)===S.bin)},onSaveImage:k,ownerDocument:f});return p.card.style.minHeight="360px",i.appendChild(p.card),{card:i,destroy:()=>{o?.destroy(),p.destroy()}}}let g="hbin";const C=p=>p===void 0?ve:(g==="hbin"?u.hard:u.soft).get(p)??ve,x=e.map(p=>({dies:p.dies,hardBinCounts:p.statsSummary?.stats.hardBinCounts,softBinCounts:p.statsSummary?.stats.softBinCounts})),W=()=>Bt(x,g),ae={title:"Hard bin pareto",data:W(),selfControl:{current:g,options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],onChange:p=>(g=p,{data:W(),title:`${g==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:p=>C(p.binCode),onSelectBar:(p,S)=>{const B=g==="hbin"?"hard":"soft",I=p.binCode;Q(S,e,I===void 0?`with no ${B} bin recorded`:`in ${B} bin ${I}`,_=>(g==="hbin"?_.hbin:_.sbin)===I)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(ae,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function re(){const e=f.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Tt(),display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"}),e}function Fe(e){if(j.innerHTML="",j.style.marginBottom="0",!Ee)return;const n=It(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",j.appendChild(n),j.style.marginBottom=T.xs)}function Ne(e,n,r,l){if(!e.length)return{elements:[],destroy:()=>{}};const i=e.map(t=>t.wafer),u=e.map(t=>t.dies),c=N(),s=[],h=[],m=xt({groups:(l??[{key:"",items:e}]).map(t=>({key:t.key,items:t.items.map(o=>({dies:o.dies,testSpecYield:o.statsSummary?.stats.testSpecYield,functionalYield:o.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:k,onSelectTest:(t,o)=>{const g=r.find(C=>C.testNumber===t.testNumber);g&&Q(o,e,`failing ${t.label}`,C=>Ze(C,g,t.kind)===!0,xe(g)?t.testNumber:void 0)},ownerDocument:f});m.card.style.minHeight="300px",s.push(m.card),h.push(m.destroy);const a=t=>(o,g)=>{const C=new Set;for(const x of e)for(const W of At(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=ue(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=pe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=ue(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=pe({title:"Quadrant yield",mode:"quadrant",rows:y,onSelectRegion:a(Le),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const w=i.find(t=>t.reticle!==void 0)?.reticle;if(w){const t=(g,C)=>Pt(g,C.reticle),o=ue(u,i,c,g=>e[g].passBins,t);if(o.length){const g=pe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:w.width,height:w.height},onSelectRegion:a(t),onSaveImage:k,ownerDocument:f});s.push(g.card),h.push(g.destroy)}}return{elements:s,destroy:()=>{for(const t of h)t()}}}function Ye(e,n,r){if(!e.length)return{cards:[],destroy:()=>{}};const l=e.map(a=>a.dies),i=e.flatMap(a=>a.dies),u=e.map(a=>a.statsSummary),c=u.every(a=>a!==void 0)?u:void 0,s=[],h=[];let d=null;if(n.length){const a=re();let b=null;const y=Et($t(i,n,void 0,c,O,l.map(w=>({dies:w})),void 0,"full"),{onDone:w=>{b=w,a.removeAttribute("aria-busy"),w?a.replaceChildren(w):a.remove()}});if(y.done)b&&(d=a);else{const w=f.createElement("div");w.textContent="Computing test statistics\u2026",Object.assign(w.style,{color:$.label,fontSize:F.body}),a.setAttribute("aria-busy","true"),a.appendChild(w),d=a,s.push(()=>y.cancel())}}let m=null;if(r.length){const a=Lt(i,r,c,O);if(a){const b=re();b.appendChild(a),m=b}}return d&&h.push(d),m&&h.push(m),{cards:h,destroy:()=>{for(const a of s)a()}}}function je(e){const n=Te(e.map(d=>d.passBins)),r=e.length===1,l=e[0],i=re();Object.assign(i.style,{flexDirection:"row",flexWrap:"wrap",gap:T.md});const u=d=>{const m=d.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function c(d,m,a){const b=f.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:T.sm,paddingRight:T.xxl,marginRight:T.md,borderRight:`1px solid ${$.menuBorder}`});const y=f.createElement("div");y.textContent=d,Object.assign(y.style,{fontSize:F.heading,fontWeight:"700",color:$.value,lineHeight:lt.tight});const w=f.createElement("div");if(w.textContent=m,Object.assign(w.style,{fontSize:F.body,color:$.label}),b.append(y,w),a){const t=f.createElement("div");t.textContent=a,Object.assign(t.style,{fontSize:F.meta,color:$.label,opacity:dt.muted}),b.appendChild(t)}return b}if(r){const d=J([{...l,key:l.waferIndex}])[0]?.percent;return d!==void 0&&i.appendChild(c(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),i.appendChild(c(String(l.dies.length),"Total dies")),u(i)}i.appendChild(c(String(e.length),"Wafers"));const s=J(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(s.length){const d=s.reduce((b,y)=>b+y,0)/s.length,m=Be([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,a=m!==void 0&&m.toFixed(1)!==d.toFixed(1);i.appendChild(c(`${d.toFixed(1)}%`,`${qe} \xB7 pass: ${n}`,a?`${m.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((a,b)=>a+b.stats.analyzedDies,0),m=h.reduce((a,b)=>a+b.stats.excludedDies,0);i.appendChild(c(d.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else i.appendChild(c(e.reduce((d,m)=>d+m.dies.length,0).toLocaleString(),"Total dies"));return u(i)}function Ge(e,n,r,l,i){const u=f.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:T.lg});const c=e.length===1&&!l;e.length&&!l&&u.appendChild(je(e));const s=Me(e,l,i,!c);u.appendChild(s.card);const h=Ne(e,n,r,l);for(const d of h.elements)s.card.appendChild(d);return u.appendChild(He()),{card:u,destroy:()=>{s.destroy(),h.destroy()}}}function He(){const e=f.createElement("div");Object.assign(e.style,{fontSize:F.body,color:$.label});const n=f.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:$.iconActive,textDecoration:"underline"}),de(n,"bare"),n.addEventListener("click",()=>{L="data",H({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function _e(e,n,r,l){const i=f.createElement("div");i.style.width="100%";let u,c=!1;return import("./plotTab.js").then(({createPlotSection:s})=>{if(c)return;const h=s({doc:f,store:q,items:e,testDefs:n,ringCount:N(),attributes:v.attributes,groupBy:r,groupLabel:l,onSaveImage:k,onSaveText:O,openWafer:R?(d,m,a)=>R(d,m,a):void 0,focusTest:Z,locateDie:V,pickPlotsFile:v.onPickPlotsFile});i.appendChild(h.card),u=h}),{card:i,destroy:()=>{c=!0,u?.destroy()}}}function Ve(e,n,r,l,i){const u=fe?.(),c=()=>{G.get("data")?.destroy(),G.delete("data"),H({keepSections:!0})};return Ot({doc:f,items:e,testDefs:n,allTestDefs:r,groups:l,groupLabelText:i,ringCount:N(),attributes:v.attributes,yieldByWaferIndex:new Map(u?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),onSaveText:O,onLocateDie:V,onOpenWafer:R?(s,h)=>R(s,h):void 0,buildStatistics:s=>Ye(s,n,r),view:he,onViewChange:s=>{he=s,c()},diesLayout:ge,onDiesLayoutChange:s=>{ge=s}})}function ze(e,n,r,l){const i=ce(f),u=ie(e),c=t=>o=>ye(o,t()),s=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),h=e.map(s),d=r?.map(t=>({key:t.key,items:t.items.map(s)})),m=ht({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:c(()=>m),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>te(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:oe(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>te(t),onSaveImage:k,onSelectBucket:(t,o)=>{const g=n.find(D=>D.testNumber===t.testNumber),C=new Set(t.items.map(D=>D.item)),x=new Set(t.items.flatMap(D=>D.dies)),W=ke(t.low,g?.unit,"engineering"),ae=ke(t.high,g?.unit,"engineering");Q(o,e.filter(D=>C.has(D)),`with ${g?et(g,g.testNumber):`test ${t.testNumber}`} from ${W} to ${ae}${t.group?` in ${t.group}`:""}`,D=>x.has(D),t.testNumber)},ownerDocument:f}),b=gt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:c(()=>b),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:st(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>ne(t,`Wafer ${e.find(g=>g.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,g)=>{const C=new Set(t.keys);Ce(o,g,e.filter(x=>C.has(x.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:oe(e),ownerDocument:f}),y=t=>{P=t,m.setTest(t),a.setTest(t),b.setTest(t),w.setTest(t)};ee.set("distribution",[m,a,b]);const w=bt({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:P??void 0,onSelectTest:t=>y(t),ownerDocument:f});return i.append(w.card,m.card,a.card,b.card),{card:i,destroy:()=>{w.destroy(),m.destroy(),a.destroy(),b.destroy()}}}function Ue(e,n,r){const l=ce(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:me().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>ye(c,i),onOpen:ie(e)?.open,openActionLabel:ie(e)?.label,onSelect:(c,s,h,d)=>{const m=new Map;for(const y of c){if(y.waferIndex===void 0||!y.die)continue;const w=m.get(y.waferIndex);w?w.push(y.die):m.set(y.waferIndex,[y.die])}const a=[...m].flatMap(([y,w])=>{const t=e.find(o=>o.waferIndex===y);return t?[{label:t.identity??t.label,dies:w,waferIndex:y,wafer:t.wafer,passBins:t.passBins,ringCount:N()}]:[]});if(a.length===0)return;const b=a.length===1?`selected on ${a[0].label} in the scatter`:`selected in the scatter, across ${a.length} wafers`;se(s,h,{items:a,population:b,testDefs:n,activeTest:d},{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})},ownerDocument:f});ee.set("correlation",[i]);const u=wt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:O,onSelectPair:(c,s)=>i.setXY(c,s),ownerDocument:f});return l.append(u.card,i.card),{card:l,destroy:()=>{u.destroy(),i.destroy()}}}function H(e){e?.keepSections||we(),U.innerHTML="",E.innerHTML="";for(const o of Ae)E.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:be}).filter(o=>o.splittable),l=f.createElement("div");Object.assign(l.style,{display:"flex",gap:T.md,alignItems:"center",marginLeft:T.xxl,paddingBottom:T.xs});let i;r.length>0?(l.appendChild(vt("Group by:",[{value:"",label:"None"},...r.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],M??"",o=>{M=o||void 0,A=null,H()},{hook:"group-by",ownerDocument:f})),i=r.find(o=>o.key===M)?.label):M=void 0;let u;if(M){const o=new Map,g=[];for(const C of n){const x=Qe(C.metadata,M,be)??Xe;o.has(x)||(o.set(x,[]),g.push(x)),o.get(x).push(C)}u=g.map(C=>({key:C,items:o.get(C)}))}A!==null&&!u?.some(o=>o.key===A)&&(A=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",A,o=>te(o),{ownerDocument:f}).el);let c=null;if(v.onOpenGuide){const o=f.createElement("button");o.type="button",o.innerHTML=mt.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...pt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),de(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}E.appendChild(l),c&&E.appendChild(c);const s=A!==null?u?.find(o=>o.key===A):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);P!==null&&!b.some(o=>o.testNumber===P)&&(P=null);const y=e?.keepSections?G.get(L):void 0,w=y??(L==="overview"?Ge(h,b,a,d,i):L==="distributions"?ze(h,b,d,i):L==="data"?Ve(h,b,a,d,i):L==="plot"?_e(h,a,s?void 0:M,s?void 0:i):Ue(h,b,d));y||G.set(L,w);const t=m.conflicts.filter(o=>o.excluded);if(t.length>0){const o=f.createElement("div");Object.assign(o.style,{color:$.label,fontSize:F.body,padding:`0 ${z} ${T.sm}`});const g=t.slice(0,6).map(W=>W.testNumber).join(", "),C=t.length>6?`, and ${t.length-6} more`:"",x=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${g}${C}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${i??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(w.card)}return{el:Y,render:H,destroy:()=>{we(),q.flush(),Y.remove()}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as qe}from"../stats/presentation.js";import{buildFacetTable as Ke,facetValueOf as Qe,FACET_NONE_VALUE as Xe,DEFAULT_FACET_CURATION as Je}from"../stats/facets.js";import{mergeTestDefs as Se}from"../stats/mergeTestDefs.js";import{isParametricTest as xe}from"../renderer/buildWaferMap.js";import{dieFailsTest as Ze}from"../stats/testPassRate.js";import{fmt as ke}from"../renderer/fmt.js";import{testLabel as et}from"../renderer/testLabel.js";import{waferDisplayLabel as tt,waferIdentityLabel as nt}from"../core/waferLabel.js";import{waferPopulation as ot}from"./chartPopulation.js";import{openDrilldownMenu as le}from"./drilldown.js";import{plotStoreFor as it}from"./plotStore.js";import{itemPassBins as rt,passBinsLabel as Te}from"../core/passBins.js";import{NO_DATA_FILL as ve}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as st}from"../stats/population.js";import{LEADING as lt,ALPHA as dt,SPACE as T,EDGE_GUTTER as de,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as ce,wireTooltip as ft}from"./toolbar.js";import{ICONS as mt}from"./icons.js";import{renderCapabilityPanel as bt}from"./charts/capability.js";import{renderBoxplotPanel as ht}from"./charts/boxplot.js";import{renderTrendPanel as gt}from"./charts/trend.js";import{renderHistogramPanel as yt}from"./charts/histogram.js";import{renderCorrelationPanel as wt}from"./charts/correlation.js";import{renderScatterPanel as Ct}from"./charts/scatter.js";import{renderBarPanel as De}from"./charts/barPanel.js";import{renderBinClusterPanel as St}from"./charts/binCluster.js";import{renderTestPassRatePanel as xt}from"./charts/testPassRate.js";import{QUANTITY as kt}from"./charts/palette.js";import{cardFrameStyle as Tt,makeChartGridWrap as ue,makeLabeledSelect as vt,makeLinkedGroupSelect as Dt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as Be}from"../stats/yield.js";import{buildBinParetoData as Bt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as $t,buildLotFunctionalSection as Lt,buildMetadataStripBox as Pt}from"./summaryPanel.js";import{runChunked as At}from"./chunked.js";import{buildRegionYieldData as pe,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as It,diesInRegion as Et}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as fe}from"./charts/regionYieldDiagram.js";const Wt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Mt={key:"data",label:"Data"},Ft={key:"plot",label:"Plot"};export function createInsightsTab(v){const{getItems:Pe,getLotStats:me,getBinColors:be,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,he={...Je,...v.attributes},Ae=v.showMetadataStrip??!0,z=v.contentInset??de,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Ie=de,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Ie});const A=f.createElement("div");Object.assign(A.style,{display:"flex",gap:T.xs,alignItems:"center",background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:ct.container,boxShadow:ut.panel,padding:`0 ${T.lg}`,marginBottom:T.lg,marginLeft:z,marginRight:z}),A.setAttribute("role","tablist"),A.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(A.querySelectorAll('[role="tab"]')),r=n.indexOf(f.activeElement);if(r===-1)return;e.preventDefault();const l=n[(r+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];l.focus(),l.click()});const U=f.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:T.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),Y.appendChild(j),Y.appendChild(A),Y.appendChild(U);const Ee=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,ge="statistics",ye="wide",I=null,E=null,K=v.initialAxisPrefs??{includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,te=(e,n,r=!1)=>{K=e;for(const l of ee.values())for(const i of l)i!==n&&i.setAxisPrefs(e);r||v.onAxisPrefsChange?.(e)},ne=e=>{E!==e&&(E=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function oe(e,n,r){R?.(e,n,r)}function ie(e){return(n,r,l)=>{const i=e.find(c=>c.waferIndex===n);if(!i)return;l.preventDefault();const u=ot(i.dies,{waferLabel:i.identity,testDefs:i.testDefs,activeTest:r??I??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});le({x:l.clientX,y:l.clientY},l.target,u,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}}function Q(e,n,r,l,i){Ce({x:e.clientX,y:e.clientY},e.target,n,r,l,i)}function Ce(e,n,r,l,i,u){const c=Rt(r.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:N()})),l,i,Se(r).defs,u);c&&le(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function re(e){return R?{open:(n,r)=>oe(n,`Wafer ${e.find(l=>l.waferIndex===n)?.label??n}`,r)}:Z&&e.length===1?{open:(n,r)=>Z(r),label:"show this test on the map"}:null}function Oe(){return Pe().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:tt(e,n),identity:nt(e),waferIndex:n,passBins:rt(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Re(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${$.iconActive}`:"2px solid transparent",color:n?$.iconActive:$.label,fontWeight:n?"700":"500",fontSize:F.body,padding:`${T.sm} ${de} ${T.md}`,cursor:"pointer",marginBottom:"-1px"})}function We(e,n){const r=f.createElement("button");r.type="button",r.textContent=n;const l=e===L;return Re(r,l),r.dataset.on=l?"true":"false",ce(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",l?"true":"false"),r.tabIndex=l?0:-1,r.addEventListener("click",()=>{L!==e&&(L=e,H({keepSections:!0}))}),r}function Me(e,n,r,l=!0){const i=ue(f),u=be();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=me?.(),m=new Map(d?.lotYieldSeries.map(p=>[p.waferIndex,p.yieldPercent])),a=p=>({...p,label:p.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(p.waferIndex),key:p.waferIndex}),b=e.map(a),y=n?.map(p=>({key:p.key,items:p.items.map(a)})),w=()=>y?Be(y,c):J(b,c),t={title:n?`Yield by ${s} (pass: ${h})`:`Yield by wafer (pass: ${h})`,data:w(),selfControl:{current:c,options:[["yield","Sort: yield"],["label",n?`Sort: ${s}`:"Sort: wafer ID"]],onChange:p=>(c=p,{data:w()})},barColor:()=>kt,valueLabel:p=>`${p.percent.toFixed(1)}%`,reference:p=>{if(p.length<3)return null;const S=p.map(P=>P.percent).sort((P,_)=>P-_),B=S.length%2?S[(S.length-1)/2]:(S[S.length/2-1]+S[S.length/2])/2;return{value:B,label:`median ${B.toFixed(1)}%`}},drill:y?{onOpenGroup:p=>{const S=y.find(B=>B.key===p.label)?.items??[];return{data:J(S,c),title:`Yield by wafer \u2014 ${s}: ${p.label} (pass: ${h})`}},onBack:()=>({data:w(),title:`Yield by ${s} (pass: ${h})`}),groupLabelText:s}:void 0,onOpen:R?p=>{typeof p.key=="number"&&oe(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:ie(e),ownerDocument:f};let o=null;if(l&&(o=De(t,k),o.card.style.minHeight="360px",i.appendChild(o.card)),n){const p=St({title:"Hard bin pareto",groups:n.map(S=>({key:S.key,items:S.items.map(B=>({dies:B.dies,hardBinCounts:B.statsSummary?.stats.hardBinCounts,softBinCounts:B.statsSummary?.stats.softBinCounts}))})),onSelectBin:(S,B)=>{const P=n.find(X=>X.key===S.groupKey);if(!P)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,P.items,`in ${_} bin ${S.bin} of ${S.groupKey}`,X=>(S.binType==="hbin"?X.hbin:X.sbin)===S.bin)},onSaveImage:k,ownerDocument:f});return p.card.style.minHeight="360px",i.appendChild(p.card),{card:i,destroy:()=>{o?.destroy(),p.destroy()}}}let g="hbin";const C=p=>p===void 0?ve:(g==="hbin"?u.hard:u.soft).get(p)??ve,x=e.map(p=>({dies:p.dies,hardBinCounts:p.statsSummary?.stats.hardBinCounts,softBinCounts:p.statsSummary?.stats.softBinCounts})),W=()=>Bt(x,g),se={title:"Hard bin pareto",data:W(),selfControl:{current:g,options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],onChange:p=>(g=p,{data:W(),title:`${g==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:p=>C(p.binCode),onSelectBar:(p,S)=>{const B=g==="hbin"?"hard":"soft",P=p.binCode;Q(S,e,P===void 0?`with no ${B} bin recorded`:`in ${B} bin ${P}`,_=>(g==="hbin"?_.hbin:_.sbin)===P)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(se,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function ae(){const e=f.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Tt(),display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"}),e}function Fe(e){if(j.innerHTML="",j.style.marginBottom="0",!Ae)return;const n=Pt(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",j.appendChild(n),j.style.marginBottom=T.xs)}function Ne(e,n,r,l){if(!e.length)return{elements:[],destroy:()=>{}};const i=e.map(t=>t.wafer),u=e.map(t=>t.dies),c=N(),s=[],h=[],m=xt({groups:(l??[{key:"",items:e}]).map(t=>({key:t.key,items:t.items.map(o=>({dies:o.dies,testSpecYield:o.statsSummary?.stats.testSpecYield,functionalYield:o.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:k,onSelectTest:(t,o)=>{const g=r.find(C=>C.testNumber===t.testNumber);g&&Q(o,e,`failing ${t.label}`,C=>Ze(C,g,t.kind)===!0,xe(g)?t.testNumber:void 0)},ownerDocument:f});m.card.style.minHeight="300px",s.push(m.card),h.push(m.destroy);const a=t=>(o,g)=>{const C=new Set;for(const x of e)for(const W of Et(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=pe(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=fe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=pe(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=fe({title:"Quadrant yield",mode:"quadrant",rows:y,onSelectRegion:a(Le),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const w=i.find(t=>t.reticle!==void 0)?.reticle;if(w){const t=(g,C)=>It(g,C.reticle),o=pe(u,i,c,g=>e[g].passBins,t);if(o.length){const g=fe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:Math.max(1,Math.floor(w.width)),height:Math.max(1,Math.floor(w.height))},onSelectRegion:a(t),onSaveImage:k,ownerDocument:f});s.push(g.card),h.push(g.destroy)}}return{elements:s,destroy:()=>{for(const t of h)t()}}}function Ye(e,n,r){if(!e.length)return{cards:[],destroy:()=>{}};const l=e.map(a=>a.dies),i=e.flatMap(a=>a.dies),u=e.map(a=>a.statsSummary),c=u.every(a=>a!==void 0)?u:void 0,s=[],h=[];let d=null;if(n.length){const a=ae();let b=null;const y=At($t(i,n,void 0,c,O,l.map(w=>({dies:w})),void 0,"full"),{onDone:w=>{b=w,a.removeAttribute("aria-busy"),w?a.replaceChildren(w):a.remove()}});if(y.done)b&&(d=a);else{const w=f.createElement("div");w.textContent="Computing test statistics\u2026",Object.assign(w.style,{color:$.label,fontSize:F.body}),a.setAttribute("aria-busy","true"),a.appendChild(w),d=a,s.push(()=>y.cancel())}}let m=null;if(r.length){const a=Lt(i,r,c,O);if(a){const b=ae();b.appendChild(a),m=b}}return d&&h.push(d),m&&h.push(m),{cards:h,destroy:()=>{for(const a of s)a()}}}function je(e){const n=Te(e.map(d=>d.passBins)),r=e.length===1,l=e[0],i=ae();Object.assign(i.style,{flexDirection:"row",flexWrap:"wrap",gap:T.md});const u=d=>{const m=d.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function c(d,m,a){const b=f.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:T.sm,paddingRight:T.xxl,marginRight:T.md,borderRight:`1px solid ${$.menuBorder}`});const y=f.createElement("div");y.textContent=d,Object.assign(y.style,{fontSize:F.heading,fontWeight:"700",color:$.value,lineHeight:lt.tight});const w=f.createElement("div");if(w.textContent=m,Object.assign(w.style,{fontSize:F.body,color:$.label}),b.append(y,w),a){const t=f.createElement("div");t.textContent=a,Object.assign(t.style,{fontSize:F.meta,color:$.label,opacity:dt.muted}),b.appendChild(t)}return b}if(r){const d=J([{...l,key:l.waferIndex}])[0]?.percent;return d!==void 0&&i.appendChild(c(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),i.appendChild(c(String(l.dies.length),"Total dies")),u(i)}i.appendChild(c(String(e.length),"Wafers"));const s=J(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(s.length){const d=s.reduce((b,y)=>b+y,0)/s.length,m=Be([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,a=m!==void 0&&m.toFixed(1)!==d.toFixed(1);i.appendChild(c(`${d.toFixed(1)}%`,`${qe} \xB7 pass: ${n}`,a?`${m.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((a,b)=>a+b.stats.analyzedDies,0),m=h.reduce((a,b)=>a+b.stats.excludedDies,0);i.appendChild(c(d.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else i.appendChild(c(e.reduce((d,m)=>d+m.dies.length,0).toLocaleString(),"Total dies"));return u(i)}function Ge(e,n,r,l,i){const u=f.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:T.lg});const c=e.length===1&&!l;e.length&&!l&&u.appendChild(je(e));const s=Me(e,l,i,!c);u.appendChild(s.card);const h=Ne(e,n,r,l);for(const d of h.elements)s.card.appendChild(d);return u.appendChild(He()),{card:u,destroy:()=>{s.destroy(),h.destroy()}}}function He(){const e=f.createElement("div");Object.assign(e.style,{fontSize:F.body,color:$.label});const n=f.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:$.iconActive,textDecoration:"underline"}),ce(n,"bare"),n.addEventListener("click",()=>{L="data",H({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function _e(e,n,r,l){const i=f.createElement("div");i.style.width="100%";let u,c=!1;return import("./plotTab.js").then(({createPlotSection:s})=>{if(c)return;const h=s({doc:f,store:q,items:e,testDefs:n,ringCount:N(),attributes:v.attributes,groupBy:r,groupLabel:l,onSaveImage:k,onSaveText:O,openWafer:R?(d,m,a)=>R(d,m,a):void 0,focusTest:Z,locateDie:V,pickPlotsFile:v.onPickPlotsFile});i.appendChild(h.card),u=h}),{card:i,destroy:()=>{c=!0,u?.destroy()}}}function Ve(e,n,r,l,i){const u=me?.(),c=()=>{G.get("data")?.destroy(),G.delete("data"),H({keepSections:!0})};return Ot({doc:f,items:e,testDefs:n,allTestDefs:r,groups:l,groupLabelText:i,ringCount:N(),attributes:v.attributes,yieldByWaferIndex:new Map(u?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),onSaveText:O,onLocateDie:V,onOpenWafer:R?(s,h)=>R(s,h):void 0,buildStatistics:s=>Ye(s,n,r),view:ge,onViewChange:s=>{ge=s,c()},diesLayout:ye,onDiesLayoutChange:s=>{ye=s}})}function ze(e,n,r,l){const i=ue(f),u=re(e),c=t=>o=>te(o,t()),s=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),h=e.map(s),d=r?.map(t=>({key:t.key,items:t.items.map(s)})),m=ht({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:c(()=>m),onTestChange:t=>y(t),selectedTestNumber:I??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>ne(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:ie(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:I??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>ne(t),onSaveImage:k,onSelectBucket:(t,o)=>{const g=n.find(D=>D.testNumber===t.testNumber),C=new Set(t.items.map(D=>D.item)),x=new Set(t.items.flatMap(D=>D.dies)),W=ke(t.low,g?.unit,"engineering"),se=ke(t.high,g?.unit,"engineering");Q(o,e.filter(D=>C.has(D)),`with ${g?et(g,g.testNumber):`test ${t.testNumber}`} from ${W} to ${se}${t.group?` in ${t.group}`:""}`,D=>x.has(D),t.testNumber)},ownerDocument:f}),b=gt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:c(()=>b),onTestChange:t=>y(t),selectedTestNumber:I??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:st(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>oe(t,`Wafer ${e.find(g=>g.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,g)=>{const C=new Set(t.keys);Ce(o,g,e.filter(x=>C.has(x.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:ie(e),ownerDocument:f}),y=t=>{I=t,m.setTest(t),a.setTest(t),b.setTest(t),w.setTest(t)};ee.set("distribution",[m,a,b]);const w=bt({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:I??void 0,onSelectTest:t=>y(t),ownerDocument:f});return i.append(w.card,m.card,a.card,b.card),{card:i,destroy:()=>{w.destroy(),m.destroy(),a.destroy(),b.destroy()}}}function Ue(e,n,r){const l=ue(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:be().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>te(c,i),onOpen:re(e)?.open,openActionLabel:re(e)?.label,onSelect:(c,s,h,d)=>{const m=new Map;for(const y of c){if(y.waferIndex===void 0||!y.die)continue;const w=m.get(y.waferIndex);w?w.push(y.die):m.set(y.waferIndex,[y.die])}const a=[...m].flatMap(([y,w])=>{const t=e.find(o=>o.waferIndex===y);return t?[{label:t.identity??t.label,dies:w,waferIndex:y,wafer:t.wafer,passBins:t.passBins,ringCount:N()}]:[]});if(a.length===0)return;const b=a.length===1?`selected on ${a[0].label} in the scatter`:`selected in the scatter, across ${a.length} wafers`;le(s,h,{items:a,population:b,testDefs:n,activeTest:d},{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})},ownerDocument:f});ee.set("correlation",[i]);const u=wt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:O,onSelectPair:(c,s)=>i.setXY(c,s),ownerDocument:f});return l.append(u.card,i.card),{card:l,destroy:()=>{u.destroy(),i.destroy()}}}function H(e){e?.keepSections||we(),U.innerHTML="",A.innerHTML="";for(const o of Ee)A.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:he}).filter(o=>o.splittable),l=f.createElement("div");Object.assign(l.style,{display:"flex",gap:T.md,alignItems:"center",marginLeft:T.xxl,paddingBottom:T.xs});let i;r.length>0?(l.appendChild(vt("Group by:",[{value:"",label:"None"},...r.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],M??"",o=>{M=o||void 0,E=null,H()},{hook:"group-by",ownerDocument:f})),i=r.find(o=>o.key===M)?.label):M=void 0;let u;if(M){const o=new Map,g=[];for(const C of n){const x=Qe(C.metadata,M,he)??Xe;o.has(x)||(o.set(x,[]),g.push(x)),o.get(x).push(C)}u=g.map(C=>({key:C,items:o.get(C)}))}E!==null&&!u?.some(o=>o.key===E)&&(E=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",E,o=>ne(o),{ownerDocument:f}).el);let c=null;if(v.onOpenGuide){const o=f.createElement("button");o.type="button",o.innerHTML=mt.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...pt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),ce(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}A.appendChild(l),c&&A.appendChild(c);const s=E!==null?u?.find(o=>o.key===E):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);I!==null&&!b.some(o=>o.testNumber===I)&&(I=null);const y=e?.keepSections?G.get(L):void 0,w=y??(L==="overview"?Ge(h,b,a,d,i):L==="distributions"?ze(h,b,d,i):L==="data"?Ve(h,b,a,d,i):L==="plot"?_e(h,a,s?void 0:M,s?void 0:i):Ue(h,b,d));y||G.set(L,w);const t=m.conflicts.filter(o=>o.excluded);if(t.length>0){const o=f.createElement("div");Object.assign(o.style,{color:$.label,fontSize:F.body,padding:`0 ${z} ${T.sm}`});const g=t.slice(0,6).map(W=>W.testNumber).join(", "),C=t.length>6?`, and ${t.length-6} more`:"",x=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${g}${C}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${i??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(w.card)}return{el:Y,render:H,destroy:()=>{we(),q.flush(),Y.remove()},setAxisPrefs:e=>te(e,null,!0)}}