@wafertools/wafermap 0.35.0 → 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 (97) hide show
  1. package/AGENTS.md +18 -9
  2. package/CHANGELOG.md +246 -0
  3. package/README.md +7 -4
  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/capability.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  10. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  11. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  12. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  13. package/dist/packages/canvas-adapter/index.js +1 -1
  14. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  15. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  17. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  18. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +85 -38
  19. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  20. package/dist/packages/canvas-adapter/summaryPanel.d.ts +38 -12
  21. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  22. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  23. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  24. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  25. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  26. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  27. package/dist/packages/canvas-adapter/toolbar.d.ts +2 -0
  28. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  29. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  30. package/dist/packages/canvas-adapter/userGuideHtml.js +46 -23
  31. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  32. package/dist/packages/canvas-adapter/version.js +1 -1
  33. package/dist/packages/canvas-adapter/warnings.js +1 -1
  34. package/dist/packages/core/aggregates.d.ts +10 -0
  35. package/dist/packages/core/aggregates.js +1 -1
  36. package/dist/packages/core/classify.d.ts +5 -0
  37. package/dist/packages/core/classify.js +1 -1
  38. package/dist/packages/core/dieTable.d.ts +31 -0
  39. package/dist/packages/core/dieTable.js +1 -1
  40. package/dist/packages/core/passBins.d.ts +6 -0
  41. package/dist/packages/core/passBins.js +1 -1
  42. package/dist/packages/core/wafer.d.ts +10 -1
  43. package/dist/packages/core/wafer.js +1 -1
  44. package/dist/packages/renderer/buildView.d.ts +5 -0
  45. package/dist/packages/renderer/buildView.js +1 -1
  46. package/dist/packages/renderer/buildWaferMap.d.ts +50 -4
  47. package/dist/packages/renderer/buildWaferMap.js +1 -1
  48. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  49. package/dist/packages/renderer/fmt.d.ts +10 -0
  50. package/dist/packages/renderer/fmt.js +1 -1
  51. package/dist/packages/renderer/index.d.ts +1 -0
  52. package/dist/packages/renderer/index.js +1 -1
  53. package/dist/packages/renderer/spec.d.ts +4 -0
  54. package/dist/packages/renderer/spec.js +1 -1
  55. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  56. package/dist/packages/renderer/valueFilter.js +1 -0
  57. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  58. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  59. package/dist/packages/stats/analyzeWaferMap.d.ts +62 -4
  60. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  61. package/dist/packages/stats/capability.d.ts +5 -0
  62. package/dist/packages/stats/capability.js +1 -1
  63. package/dist/packages/stats/clusterDetection.js +1 -1
  64. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  65. package/dist/packages/stats/connectedComponents.js +1 -1
  66. package/dist/packages/stats/correlation.d.ts +36 -4
  67. package/dist/packages/stats/correlation.js +1 -1
  68. package/dist/packages/stats/filterFindings.d.ts +1 -1
  69. package/dist/packages/stats/filterFindings.js +1 -1
  70. package/dist/packages/stats/findingText.d.ts +8 -0
  71. package/dist/packages/stats/findingText.js +2 -2
  72. package/dist/packages/stats/index.d.ts +2 -1
  73. package/dist/packages/stats/index.js +1 -1
  74. package/dist/packages/stats/lotDrift.js +1 -1
  75. package/dist/packages/stats/lotPattern.js +1 -1
  76. package/dist/packages/stats/math.d.ts +25 -3
  77. package/dist/packages/stats/math.js +1 -1
  78. package/dist/packages/stats/mergeTestDefs.js +1 -1
  79. package/dist/packages/stats/patternClassification.d.ts +44 -18
  80. package/dist/packages/stats/patternClassification.js +1 -1
  81. package/dist/packages/stats/plotData.d.ts +11 -0
  82. package/dist/packages/stats/plotData.js +1 -1
  83. package/dist/packages/stats/regions.d.ts +6 -0
  84. package/dist/packages/stats/regions.js +1 -1
  85. package/dist/packages/stats/renderSummaryReport.js +33 -33
  86. package/dist/packages/stats/reportHtml.d.ts +12 -18
  87. package/dist/packages/stats/reportHtml.js +112 -48
  88. package/dist/packages/stats/synthesis.d.ts +48 -17
  89. package/dist/packages/stats/synthesis.js +1 -1
  90. package/dist/packages/stats/testPassRate.js +1 -1
  91. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  92. package/dist/packages/stats/testValueBudget.js +1 -0
  93. package/dist/packages/stats/types.d.ts +89 -22
  94. package/llms.txt +2 -2
  95. package/package.json +1 -1
  96. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  97. package/dist/packages/canvas-adapter/summaryRail.js +0 -1
package/AGENTS.md CHANGED
@@ -117,6 +117,12 @@ worth reporting, not a pattern to build on.
117
117
  lot. Supply or replace the analysis later with `setStatsSummary()`. There is no
118
118
  chart-data API to hand-build them from. Charting a selection or one wafer (right-click → histogram, capability,
119
119
  saved plots and sweeps) is built in too, with no wiring.
120
+ - **Keep the reader's plots in the host, hand them back in.** The library stores nothing: supply `insights.plots` and keep
121
+ it current from `insights.onPlotsChange` (the whole list, after every change). Wafer attribute names (`attributes`) and the
122
+ Data tab need no wiring beyond that.
123
+ - **A value that is not a measurement is excluded by limits, not by editing the data.** A tester clamp or open-circuit reading is
124
+ handled by `TestDef.validLow`/`validHigh` and `valueFilter` (default `'validity'`). Removing or zeroing such values in the host hides
125
+ them from the count the library would have shown; deleting the dies changes the yield.
120
126
  - **A value computed from other tests is a derived test, not a host-side column.** Pass
121
127
  `derivedTests` (a `TestDef` plus an `expression`, e.g. `'abs(t[1020] - t[1010])'`) to
122
128
  `buildWaferMap`; it then behaves as a measured test everywhere, marked `†` as not
@@ -170,15 +176,18 @@ it is handed, because it has no way to know which tests anyone will look at.
170
176
  parse and build only the chosen tests. A scan that reads test identity without
171
177
  reading every value is dramatically cheaper than a full load, and it is what makes
172
178
  a large file feel instant.
173
- - **Above 250 discovered tests, `analyzeWaferMap` gives up on test-value analysis
174
- entirely** — it returns no test findings rather than a trimmed set, and records a
175
- `WaferWarning` with code `'test-count-capped'` in `stats.warnings`. Silence is not
176
- success here: an empty findings list is indistinguishable from "nothing to report"
177
- 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.
178
187
  - **Reach for options deliberately.** Plain `analyzeWaferMap()` is cheap;
179
- `computePerTestStats` is modest; `enableTestValueAnalysis` is the expensive one
180
- (roughly 10× the base analysis on a large wafer) and exists to find spatial
181
- 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.
182
191
  - **A Web Worker buys responsiveness, not speed.** `createWafermapWorker` moves a
183
192
  result's test values to the page without copying them, but still copies the dies and the
184
193
  input, so total time goes *up*. Use it when a build would otherwise visibly freeze the
@@ -241,7 +250,7 @@ compatibility shims for them.
241
250
  - [API reference](https://wafertools.github.io/wafermap/api/) — every type, option and return value
242
251
  - [Developer guide](https://wafertools.github.io/wafermap/guide/) — worked walkthroughs
243
252
  - [Troubleshooting](https://wafertools.github.io/wafermap/troubleshooting/)
244
- - [Examples](https://wafertools.github.io/wafermap/examples/) — 23 runnable pages, also
253
+ - [Examples](https://wafertools.github.io/wafermap/examples/) — 25 runnable pages, also
245
254
  [downloadable](https://wafertools.github.io/wafermap/wafermap-examples.zip) to run offline
246
255
 
247
256
  When a rule here and the API reference disagree, the API reference wins — tell the
package/CHANGELOG.md CHANGED
@@ -24,6 +24,252 @@ 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
+
144
+ ## [0.35.1] — 2026-10-09
145
+
146
+ ### Added
147
+
148
+ - **Validity limits, and a value filter that excludes values outside a limit set.** A test can carry `validLow`/`validHigh`: the
149
+ range a real measurement lies in. A value outside it is a tester clamp (a range overflow, an open-circuit rail), not a reading.
150
+ `buildWaferMap`'s `valueFilter` option chooses which limit set a value must lie inside: `'validity'` (the default, which only
151
+ affects tests that have validity limits), `'spec'` or `'test'` to keep only values inside the specification or test limits, or
152
+ `'none'`. An excluded value is no value for that test on that die, in the map, the statistics and every chart, and a derived test
153
+ is computed from the filtered values. Bins and each die's recorded verdict are the tester's own and are unchanged.
154
+ - **Excluded values are counted and shown.** `WaferMapResult.valueFilter` gives the limit set and, per test, how many values were
155
+ excluded, and the result's warnings carry a `values-excluded` line. The tooltip on a grey die names the excluded value and the
156
+ limit set. The Summary panel (a total beside N and an Excl. column), its CSV export, the summary report, the Plot footnote, the
157
+ histogram and boxplot captions and the capability tooltip and caption state the count. `CapabilityDatum.excluded` carries it;
158
+ `n` does not include excluded values.
159
+
160
+ - **`StatsSummary.stats.testFailures`: the dies each test fails.** Per test number, the failing dies' keys (outside its limits for a
161
+ parametric test, failing for a functional one) and `lostDies`, how many of them also fail the wafer's yield. Absent when no test fails
162
+ a die.
163
+
164
+ ### Changed
165
+
166
+ - **"What stands out" items are rows that act, every one the same way.** Each item, the further items below it and each Watch line is a
167
+ row that shows its dies on the map when clicked, marked by a wafer icon at its end: a region or wafer its finding, a test the test's
168
+ values with the dies it fails selected. The sentences themselves no longer contain links. The leading item's parts (its fail bins,
169
+ with their legend colours, the spatial pattern, and tests failing on the same dies) are chips under its sentence, each showing that
170
+ part alone.
171
+ - **A test is costed by the dies it fails that also fail yield.** Dies outside a test's limits but binned as passing cost no yield, so
172
+ they no longer rank the test; the item says how many there are, and past one yield point they are a Watch line ("Voltage is outside
173
+ its limits on 432 dies binned as passing"). A test whose failing dies lie mostly on a region item's dies (at least half of them, and
174
+ at least twice the region's share of the dies) is said in that region's item and shown as one of its chips, rather than ranked
175
+ against it as a second item over the same dies.
176
+ - **A lot of one wafer is described from that wafer.** Its "What stands out" is the wafer's own.
177
+ - **With a single pass bin, a fall in that bin is a region's pass rate.** Data with soft bins only has no separate yield
178
+ finding, and its region items are now costed by the pass bin's fall (the whole shortfall), with the fail bins as its parts.
179
+ - **When nothing costs a yield point but a finding below is marked Unusual**, "What stands out" says so instead of "Nothing stands
180
+ out".
181
+ - **A map of soft-bin-only data opens in soft-bin mode.** Without a `plotMode` from the host, `renderWaferMap` and
182
+ `renderWaferGallery` open on hard bins when the dies carry any, otherwise soft bins. `WaferMapResult.plotMode` is `'softBin'`
183
+ for such data.
184
+ - **An outlier wafer is named by its ID** in its finding, "What stands out" and the report's per-wafer findings ("W05 yield is 16.1
185
+ points below the lot median"), or as "Wafer 5 (no ID)" when it has none, as every other surface names it.
186
+ - **The single map's auto-mounted Summary panel shows a clicked finding or row as selected**, and its findings filters apply, as the
187
+ placed panel's do.
188
+ - **Bins are said to "account for" a region's shortfall only when together they fit within it.** When other fail bins fell in the
189
+ region, the named bins are given as points higher instead. A test is said as part of a region's item only when it fails on at
190
+ least 1% of the dies, the floor for listing it on its own; the dies counted "in" the region are the named region's own.
191
+ - **The spatial pattern classifier finds scratches at any angle and donuts by their radial profile.** A scratch is a thin line
192
+ of failing dies along its own principal axis, whatever its angle: at most 0.8 die pitches across, at least 8 pitches and 0.3 of
193
+ the radius long, reaching in from the rim, with the fragments that continue it along the same line counted as one line. A donut
194
+ is a band of failures at mid-radius, at least 15 points above both the centre and the rim, read from the fail rate in five rings
195
+ of equal width. A symmetric pattern on the centre that is not a donut is a centre cluster. On WM-811K, recall and precision are
196
+ now: scratch 40.7% / 87.4%, donut 77.5% / 68.6%, centre 84.5% / 88.1%, edge-local 68.2% / 52.2%, random 60.4% / 51.6%; edge-ring
197
+ and near-full are unchanged; exact match 71.1%. `PatternFeatures` gains `lineWidth`, `lineLength`, `lineSize`,
198
+ `lineMinDistNorm`, `lineMaxDistNorm` and `radialFailRates`. Pattern labels, the spatial-pattern finding and "What stands out"
199
+ change accordingly.
200
+ - **A region holds only against the regions that are not themselves deviant.** The significant findings for one variable and region
201
+ family are re-tested against each other: a loss is taken before a gain, each must hold against the rest without the regions that
202
+ stand, and a gain is compared only with the regions that do not lean towards a loss. A failing block of rings is reported as the
203
+ block ("Rings 2–3 lower pass rate"), not as the rings either side of it being better, and a failing quadrant brings no "lower"
204
+ finding from the sectors opposite it: on synthetic lots with a failing quadrant, no wafer or lot reports one. Findings on the
205
+ opposite side of a strong pattern are no longer reported, and "What stands out" and its "also seen as" lists change accordingly.
206
+ - **An item is costed by its largest loss.** Findings on the same dies are one item, led by the finding that loses the most dies, or
207
+ by its own region's pass rate when there is one. A small edge arc or cluster on an edge ring's dies is "also seen as" under the
208
+ ring's item, which costs the ring's loss.
209
+ - **One false-discovery family per analysis.** Benjamini–Hochberg now adjusts every rate comparison on a wafer together (yield,
210
+ hard and soft bins, functional tests and limit fail rates, in every region family) and every regional comparison of a lot
211
+ together. Findings that rested on weak evidence are no longer reported, and severities, `adjustedPValue`,
212
+ `hasNotableFindings` and "What stands out" change accordingly.
213
+ - **Rates with small expected counts are tested exactly.** A region's rate is compared with Fisher's exact test when any expected
214
+ count of its 2×2 table is under 5, and with the two-proportion z-test otherwise; `stats.method` is `'fisher-exact'` or
215
+ `'two-proportion-z'`.
216
+ - **A cluster or edge arc is tested by its size against random placement.** A group of failing dies is found because it fails,
217
+ so its fail rate is no evidence of a cluster. The wafer's fails are scattered at random over the same dies (up to 99 times, seeded
218
+ from the layout and fail count so a wafer always gets the same answer) and a group is reported when random placement rarely
219
+ makes one that large: `stats.method` is `'permutation'`, the smallest p-value is 0.01, and `adjustedPValue` equals `pValue`
220
+ (the comparison with the largest group is already family-wise). Random failures no longer read as clusters: on synthetic
221
+ wafers of random failures, the share reporting any regional finding is 2.7% at a 2% fail rate, 5.5% at 5%, 5.3% at 10% and 1–2%
222
+ from 20% up (see Detection analysis). Faint patterns that show only as a contiguous group are found less often: on WM-811K the
223
+ regional analysis rescues 90.3% of the patterns the classifier misses, and combined detection is 98.7%. Cluster p-values,
224
+ severities and the edge arcs listed under an edge ring change accordingly.
225
+ - **Small p-values are exact to double precision.** Every z-based p-value reads the normal tail from W. J. Cody's erfc (about
226
+ 1e-15 relative), so a p-value below 1e-7 is a number rather than rounding noise or 0. The gates are unchanged, but where two
227
+ very strong findings are weighed against each other (a sector run against the quadrant over the same angle, the smaller p-value
228
+ kept), the stronger one is now the one kept: on the bin-rich sample a Vmin pattern reads as the NE quadrant, not Sectors E–N.
229
+ - **An edge arc across due east is an edge arc.** Its angular span is measured round the circle, so an arc from 355° to 5° spans
230
+ 10°, as an arc anywhere else does.
231
+ - **Quadrants are quarter turns of equal share.** A die is in the quadrant whose quarter turn, counted counter-clockwise from
232
+ east, holds its angle: NE holds the positive x axis, NW the positive y axis, SW the negative x axis and SE the negative y axis, as
233
+ sectors are bucketed. On a die grid with a centre row and column each quadrant now holds the same number of dies (the centre die
234
+ is NE). Quadrant yields, quadrant findings and the Ring | Quadrant region tables change for such data, by up to two points on a
235
+ wafer of a few hundred dies.
236
+ - **A pass bin's finding is shown as its region.** Clicking a finding or row about a pass bin that fell in a region highlights the
237
+ region's dies, as a yield finding does, without picking out the passing dies.
238
+ - **A sector is compared with the other sectors** in "What stands out" ("below the other sectors"), as its finding is: sectors leave
239
+ out the dies near the centre.
240
+ - **Showing a finding keeps the map's bin mode.** A finding that is not about one bin (a yield region, a spatial pattern) is shown
241
+ in the bin mode the map is in, or from another mode in a bin type the dies carry, never one the data lacks. Clicking the same
242
+ finding or "What stands out" row again restores the plot mode and test in use before it was first clicked.
243
+ - **"Also seen as" counts a long family** ("9 edge arcs") instead of naming each, and the compact list's heading reads "Also, each
244
+ costing at least 1% of the dies".
245
+ - **Gallery cards fill the width they are given.** In auto layout, when there are more cards than columns, the columns share the whole
246
+ row: width too narrow for another column (the Summary panel closing, a wider window) enlarges the cards instead of leaving an empty
247
+ band beside them. The size cap applies while every card fits in one row, so a few wafers still do not stretch across a wide screen.
248
+ - **The Summary panel opens from a labelled Summary button and closes from its own header.** The button sits in the row above the map,
249
+ just before Map | Insights (above the panel it opens), and shows as pressed while the panel is open; its icon takes the findings colour
250
+ while the panel is closed and a finding is notable. It replaces the toolbar's Summary icon and the "◂ Summary" tab on the edge of the
251
+ map area, so a closed panel leaves no column behind. The panel's title ends with a close button pointing to the edge it folds into (▸
252
+ for a panel on the right), and the title stays at the top while the panel scrolls. A map without a toolbar, which has no Summary
253
+ button, shows no close button. For half a second after the panel closes, a click where its close button was goes nowhere:
254
+ closing widens the map or the gallery, which moves an Expand button under the pointer, and a quick second click would
255
+ otherwise open it.
256
+ - **The Findings section's controls are its severity chips.** The header says how many findings are unusual or notable ("1 unusual,
257
+ 2 notable"), also while the section is collapsed. Every finding row ends with the wafer icon of the rows that show their dies on the
258
+ map, and a spatial pattern has a "Show 3 supporting findings" line under it that opens the regional findings it explains (open from
259
+ the start when the finding on the map is one of them). The Kind and Region dropdowns and the Detail modal are gone: the list is
260
+ grouped by region, and the Summary report holds the findings at length.
261
+ - **In the reports, every item links to its evidence**: a finding to its row in the Findings table, a test to the Test Values or
262
+ Functional Tests section. The leading item ends with a "See" line naming its region and its parts. Links are drawn in a link colour.
263
+
264
+ ### Docs
265
+
266
+ - **Validity limits and the value filter are documented** in the API reference (`TestDef.validLow`/`validHigh`, `valueFilter`, `WaferMapResult.valueFilter`, the `values-excluded` warning),
267
+ the developer guide, the user guide and the glossary, with a new **Validity limits** example in which tester clamps are kept out of the map and statistics and counted. The RF analog
268
+ sample data carries validity limits and a few clamped readings.
269
+ - **A Plots, tables and attributes example and guide section.** It shows `insights.plots` and `onPlotsChange` keeping the reader's plots, the Data tab, drilldown, whole-wafer picks and Select on every wafer,
270
+ and `attributes` naming wafer attributes. The reticle guide and example explain reticle cell and shot and the Reticle cell yield card; the derived-tests example reads a die's own fields
271
+ (`hbin()`); the retests example shows `supersedes`; `findingsNotice` and `setFindingsNotice` are in the API reference.
272
+
27
273
  ## [0.35.0] — 2026-10-06
28
274
 
29
275
  ### 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-~65%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 ~65 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
 
@@ -26,7 +26,7 @@ Discussions](https://github.com/wafertools/.github/discussions).
26
26
 
27
27
  ## Overview
28
28
 
29
- wafermap renders interactive wafer maps from semiconductor prober output. Hard bins, soft bins, test values, retest runs, edge exclusion, and spec limits are native inputs.
29
+ wafermap renders interactive wafer maps from semiconductor prober output. Hard bins, soft bins, test values, retest runs, edge exclusion, and spec and validity limits are native inputs.
30
30
 
31
31
  - Geometry inference — pass full physical dimensions or raw prober step positions; die pitch, wafer diameter, and coordinate origin are resolved automatically
32
32
  - `renderWaferMap` — interactive canvas map with toolbar, zoom/pan, tooltips, die selection, and summary panel
@@ -35,6 +35,9 @@ wafermap renders interactive wafer maps from semiconductor prober output. Hard b
35
35
  - Derived tests (`derivedTests`) — tests computed per die from other tests (`abs(t[1020] - t[1010])`), which then work everywhere a measured test does, marked † as not measured
36
36
  - Parametric sweeps (plots with `chart: 'sweep'`, edited on the Plot tab) — an ordered run of tests read as a response curve, with the crossing and widths between two curves measured; x values given directly or read from the test names, on a linear or log axis
37
37
  - Drilldown — right-click selected dies, a wafer card or a wafer's bar to chart just that population, with the population stated on the chart
38
+ - Plot tab and Data tab — a chart builder (scatter, histogram, box, bar, line, sweep over any test, die field or wafer attribute) whose saved plots your app keeps with `insights.plots` and `onPlotsChange`, and the lot as sortable tables (statistics, dies, wafers) with CSV export
39
+ - Validity limits (`TestDef.validLow` / `validHigh`, `valueFilter`) — tester clamps and open-circuit readings are kept out of the map, statistics and charts, and counted wherever a population is shown
40
+ - Reticle and multi-project wafers — stepper-field overlay, reticle cell and shot as die fields to colour, split and chart by, reticle-position findings, and a compact layout for sparse multi-project reticles
38
41
  - `analyzeWaferMap` / `analyzeWaferLot` — spatial analysis across rings, quadrants, sectors, and reticle positions; failure cluster detection; lot trend series
39
42
  - Pure ES modules, no server, no runtime dependencies — works in React, Svelte, Vue, plain HTML, or a Web Worker
40
43
 
@@ -75,7 +78,7 @@ export. Add `analyzeWaferMap` for the findings and summary panel, swap in
75
78
 
76
79
  The API reference is long because it documents every option, not because you need
77
80
  them: [tsmap](https://github.com/wafertools/tsmap), a complete cross-platform desktop
78
- 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
79
82
  [Quick Start](https://wafertools.github.io/wafermap/quickstart/) first and treat the
80
83
  [API reference](https://wafertools.github.io/wafermap/api/) as something to search,
81
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 He,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 De}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 Ee,fitRowsHeight as yt,setChartGrow as Tt,resolveChartCanvasColors as vt,makeAxisFormat as Oe,horizontalTickSpacing as kt,resolveAxisRange as Mt,shouldIncludeLimitsByDefault as Lt,drawOffAxisLimits as Ct,limitLabelSide as At,limitLines as We,limitExtent as $t,hasBothLimitKinds as St,stackLabelRows as It,strokeLimitLine as Bt,PADDING as M,VALUE_WIDTH as Rt,WAFER_MENU_HINT as Ht,prepareCanvas as Dt}from"./chartShell.js";import{escHtml as L,maxOf as Et,minOf as Ot}from"../../core/utils.js";const C=24,A=5,Pe=110,Wt=12,_e=20;export function renderBoxplotPanel(u){const{title:ne="Test value distribution",items:Ge,testDefs:be,onSaveImage:Ne,groups:g,groupLabelText:oe="group",onOpen:Q}=u,Xe=u.openActionLabel??"open that wafer",qe=u.openActionLabel??"open this wafer",{card:a,heading:Ye,body:x,controlsRow:U}=mt(ne,Ne,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 ze(){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(v=>v.key===b)?.items??[]:g.map(v=>({label:v.key,dies:v.items.flatMap(S=>S.dies??[])}));return se=p,we=i,p}function ye(){b!==null&&!D?(D=ht(()=>{Te(null),u.onGroupChange?.(null)},a.ownerDocument),U.appendChild(D)):b===null&&D&&(D.remove(),D=null),Ye.textContent=b!==null?`${ne} \u2014 ${oe}: ${b}`:ne}function Te(i){return b===i||i!==null&&!(g??[]).some(p=>p.key===i)?!1:(b=i,ye(),j(),$(),!0)}const ve=gt(ie,y,i=>{y=i,$(),u.onTestChange?.(i)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:a.ownerDocument}),Qe=ve.el;U.appendChild(Qe),U.appendChild(bt("Log scale",le,i=>{le=i,$()},a.ownerDocument,"Draw the value axis on a logarithmic scale"));const ae=a.ownerDocument.createElement("span");Object.assign(ae.style,{display:"inline-flex",gap:He.lg,alignItems:"center"}),U.appendChild(ae);const re=wt(ae,u.axisPrefs,i=>{u.onAxisPrefsChange?.(i),$()},a.ownerDocument),V=a.ownerDocument.createElement("div");V.dataset.wmapCaption="1",Object.assign(V.style,{color:ft.label,fontSize:ct.body,marginBottom:He.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 ${Xe}`);const v=p.length?`${p[0][0].toUpperCase()}${p[0].slice(1)} \xB7 `:"";V.textContent=`${v}box = Q1\u2013Q3, line = median, whiskers = min/max \xB7 value shown is the median`+(F?` \xB7 axis clipped, ${F} value${F===1?"":"s"} outside`:"")}j(),ye();const E=xt(a);let ce=null;function $(){const{includeLimits:i,clipOutliers:p,limits:v}=re.get();if(j(),x.innerHTML="",ie.length===0||y===null){Ee(x,"No parametric test data available for box plots.");return}const S=ze(),h=rt(S,y),K=be.find(t=>t.testNumber===y),O=K?.unit,fe=We(K,v),{lo:Ve,hi:je}=$t(fe);if(h.every(t=>t.count===0)){Ee(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 ke=M*2+Math.min(h.length,Wt)*(C+A)+_e;x.style.maxHeight=`${ke}px`,x.style.overflowY="auto",x.style.scrollbarGutter="stable";let G=-1;const ue=h.filter(t=>t.count>0),Me=Ot(ue.map(t=>t.min)),Le=Et(ue.map(t=>t.max)),Ce=i??Lt(Me,Le,Ve,je);re.sync(Ce,We(K).length>0,St(K));const N=Mt({dataMin:Me,dataMax:Le,limits:fe,includeLimits:Ce,clipOutliers:p,values:ue.flatMap(t=>[t.min,t.q1,t.median,t.q3,t.max])});F=N.clippedCount,j();const W=N.lo,J=N.hi,Ke=J-W||1,Z=le&&W>0,me=Z?Math.log10(W):0,Ae=(Z?Math.log10(J):0)-me||1,de=Math.max(Math.abs(W),Math.abs(J));function Je(){const t=M+Pe,s=m.clientWidth-t-Rt-M;return{plotX:t,plotMaxWidth:Math.max(10,s)}}function I(t,s,n){return Z?s+(Math.log10(t)-me)/Ae*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+Ae*e/4));return{ticks:d,axis:Oe(de,O)}}const n=ut(W,J,s,kt(t,de,O));return{ticks:n.ticks,axis:Oe(de,O,n.step||void 0)}}function ee(){const t=vt(a),s=M*2+h.length*(C+A)+_e;x.style.maxHeight=`${yt(a,x,ke,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=M+f*(C+A),r=w+C/2;f===G&&(e.fillStyle=t.bgHover,e.fillRect(0,w-A/2,n,C+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,M+Pe-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)),Ie=I(o.min,l,c),Be=I(o.max,l,c),B=q(Ie),Y=q(I(o.q1,l,c)),Re=q(I(o.median,l,c)),he=q(I(o.q3,l,c)),R=q(Be),lt=Ie<B,st=Be>R,H=w+3,z=w+C-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 k=3;lt?(e.moveTo(B+k,r-k),e.lineTo(B,r),e.lineTo(B+k,r+k)):(e.moveTo(B,H),e.lineTo(B,z)),st?(e.moveTo(R-k,r-k),e.lineTo(R,r),e.lineTo(R-k,r+k)):(e.moveTo(R,H),e.lineTo(R,z)),e.stroke(),e.fillStyle=De,e.globalAlpha=.35,e.fillRect(Y,H,Math.max(1,he-Y),z-H),e.globalAlpha=1,e.strokeStyle=De,e.strokeRect(Y,H,Math.max(1,he-Y),z-H),e.strokeStyle=t.text,e.lineWidth=2,e.beginPath(),e.moveTo(Re,H),e.lineTo(Re,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 T=M+h.length*(C+A);e.font=`${_(-1)}px system-ui, sans-serif`,Ct(e,N.offAxis,{left:l,right:l+c,top:0,bottom:T},"horizontal",t.limitLine,o=>ge(o,O,"engineering"));const et=new Set(N.offAxis.map(o=>o.value)),Se=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(Se),nt=_(-1)+2;Se.forEach(({l:o,x:f,dir:w},r)=>{Bt(e,o,t.limitLine,f,0,f,T),e.fillStyle=t.limitLine,e.textAlign=w<0?"right":"left",e.textBaseline="bottom",e.fillText(o.label,f+w*3,T-1-tt[r]*nt)}),e.font=`${_(-1)}px system-ui, sans-serif`,e.strokeStyle=t.border,e.lineWidth=1,e.beginPath(),e.moveTo(l,T),e.lineTo(l+c,T),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,T),e.lineTo(f,T+4),e.stroke(),e.fillText(pe.tick(o),f,T+6)}pe.unitLabel&&(e.textAlign="left",e.font=`${_(-1)}px system-ui, sans-serif`,e.fillText(`(${pe.unitLabel})`,l+c+22,T+6),e.font=`${_(-1)}px system-ui, sans-serif`),e.textBaseline="middle"}function xe(t){const s=Math.floor((t-M+A/2)/(C+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,$e=t=>!P&&!!Q&&S[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||$e(n));if(n!==G&&(G=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 ${L(oe)} by wafer</em>`:$e(n)?`<br><em>click to ${L(qe)}</em>`:"",c=!P&&u.onWaferContextMenu&&S[n]?.waferIndex!==void 0?Ht:"";E.innerHTML=`<strong>${L(e.label)}</strong> (${e.count} dies)<br>max ${L(X(e.max))}<br>q3 ${L(X(e.q3))}<br>median ${L(X(e.median))}<br>q1 ${L(X(e.q1))}<br>min ${L(X(e.min))}${l}${c}`,E.style.display="block",pt(E,a,t.clientX,t.clientY)}else E.style.display="none"}),m.addEventListener("mouseleave",()=>{G!==-1&&(G=-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;Te(e),u.onGroupChange?.(e);return}const d=S[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:S[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()}$();function Ue(i){ve.set(i)&&(y=i,$())}function Fe(i){re.set(i)&&$()}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{buildCapabilityData as ve}from"../../stats/capability.js";import{capabilityColor as U}from"./palette.js";import{LEADING as Se,SPACE as T,fontPx as J,FONT as Z,CLR as _}from"../toolbar.js";import{cardShell as Me,isExpandedCard as Te,chartFillHeight as $e,applyCanvasFlow as Ce,observeResize as Le,makeTooltip as ke,positionChartTooltip as Pe,renderEmptyState as Ee,resolveChartCanvasColors as we,chartSwatchCss as De,prepareCanvas as Ae,chartDpr as We}from"./chartShell.js";import{fmt as Ne}from"../../renderer/fmt.js";import{escHtml as V}from"../../core/utils.js";import{DERIVED_MARK as ee,DERIVED_KEY as le}from"../../renderer/testLabel.js";function N(S){return S==="spec"?{lo:"LSL",hi:"USL",noun:"spec limits"}:{lo:"Lo limit",hi:"Hi limit",noun:"test limits"}}function ae(S){let w;for(const z of S){if(!z.hasSpec)continue;const D=z.limitBasis??"test";if(w===void 0)w=D;else if(w!==D)return"mixed"}return w}const Ie=30,re=160,ce=90,me=28,C=42;function j(S){return S===null?"\u2014":S.toFixed(2)}export function renderCapabilityPanel(S){const{title:w="Process capability",items:z,testDefs:D,onSaveImage:de,onSelectTest:X}=S;let q=S.selectedTestNumber??null;const{card:m,body:L}=Me(w,de,S.ownerDocument),pe=D.some(t=>t.testNumber!==void 0);L.style.overflowX="auto";function he(){return z}const A=m.ownerDocument.createElement("div");Object.assign(A.style,{display:"flex",flexDirection:"column",gap:T.xs,marginBottom:T.sm}),m.insertBefore(A,L);const I=ke(m);let F=()=>{};function fe(t,l,M,u,b){A.innerHTML="";const $=m.ownerDocument.createElement("span");Object.assign($.style,{display:"inline-flex",alignItems:"center",gap:T.sm,color:_.value,fontSize:Z.body,fontWeight:"500"});const d=M-t,y=l>0?` \xB7 ${l} without both limits`:"",x=m.ownerDocument.createElement("span");x.dataset.wmapCaption="1",x.textContent=d>0?`${t} of ${M} tests shown${y} \xB7 ${d} excluded (no recorded values)`:`${t} test${t!==1?"s":""} shown${y}`,$.appendChild(x),A.appendChild($);const k=l>=t,p=m.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=k?"No test has both limits, so each is normalised to its own observed range (min = 0, max = 1) and sorted most-variable first. Ppk needs limits, so none is shown.":(b==="mixed"?"Normalised to each test's spec limits (LSL = 0, USL = 1), or its test limits (Lo limit = 0, Hi limit = 1) where it has no spec limits, worst Ppk first. ":`Normalised to ${N(b).noun} (${N(b).lo} = 0, ${N(b).hi} = 1), worst Ppk first. `)+"Tests without both limits are normalised to their own observed range and drawn muted/dashed.",Object.assign(p.style,{color:_.label,fontSize:Z.body,lineHeight:Se.base,marginTop:T.xs,maxWidth:"78ch"}),A.appendChild(p),A.appendChild(ue(m.ownerDocument,l>0,k,u>0))}function ue(t,l,M=!1,u=!1){const b=t.createElement("div");Object.assign(b.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${T.xs} ${T.xl}`,marginTop:T.xl,marginBottom:T.xs,fontSize:Z.body,color:_.label});const $=M?[]:[{color:U(2),label:"Capable \xB7 Ppk \u2265 1.33"},{color:U(1.1),label:"Marginal \xB7 Ppk \u2265 1.0"},{color:U(.5),label:"Poor \xB7 Ppk < 1.0"}];l&&$.push({color:_.label,label:"No limits \xB7 no Ppk",dashed:!0});for(const d of $){const y=t.createElement("span");Object.assign(y.style,{display:"inline-flex",alignItems:"center",gap:T.sm});const x=t.createElement("span");x.style.cssText=De(d.color,d.dashed?"outline":"solid");const k=t.createElement("span");k.textContent=d.label,y.append(x,k),b.appendChild(y)}if(u){const d=t.createElement("span");Object.assign(d.style,{display:"inline-flex",alignItems:"center",gap:T.sm});const y=t.createElement("span");y.textContent=ee,Object.assign(y.style,{color:_.value,fontWeight:"600"});const x=t.createElement("span");x.textContent=le,d.append(y,x),b.appendChild(d)}return b}function be(t){if(L.innerHTML="",t.length===0)return Ee(L,"No parametric tests have any recorded values.",{maxWidth:"480px"}),()=>{};const l=m.ownerDocument.createElement("canvas");l.style.display="block",l.style.cursor="default",L.appendChild(l);const M=t.length,u=Math.min(0,...t.map(n=>n.min)),b=Math.max(1,...t.map(n=>n.max)),$=(b-u)*.05||.1,d=u-$,x=b+$-d||1;function k(n){const o=Math.floor(n/M);return Math.max(Ie,Te(m)?o:Math.min(re,o))}function p(n,o,i){return o+(1-(n-d)/x)*i}function ge(n,o,i,s,P){const g=t.filter(v=>v.hasSpec).length,W=g===t.length,h=g===0,E=ae(t),e=E==="mixed"?{lo:"Lo",hi:"Hi",noun:"limits"}:N(E),f=h?"max":E==="spec"?e.hi:"Hi",a=h?"min":E==="spec"?e.lo:"Lo",H=W?`normalised to ${e.noun}`:h?"normalised to range":"normalised (per test)";n.font=`${J(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(const[v,r]of[[1,f],[0,a]]){const c=p(v,i,s);c<i-1||c>i+s+1||(n.strokeStyle=o.limitLine,n.lineWidth=1,n.beginPath(),n.moveTo(C-5,c),n.lineTo(C,c),n.stroke(),n.fillStyle=o.textMuted,n.fillText(r,C-8,c))}n.save(),n.translate(9,i+s/2),n.rotate(-Math.PI/2),n.textAlign="center",n.fillStyle=o.textMuted,n.fillText(H,0,0),n.restore()}let B=-1;function G(){Ce(l);const n=L.clientWidth,o=k(n-C),i=o*M,s=me,P=C+i,g=$e(m,L,l,me+200+ce),W=Math.max(s+60,g-ce),h=W-s,E=Ae(l,m,P,g);if(!E)return;const{ctx:e}=E,f=we(m);t.forEach((a,H)=>{const v=C+H*o,r=v+o/2,c=Math.max(4,Math.min(o,re)*.55);if(H===B&&(e.fillStyle=f.bgHover,e.fillRect(v,s,o,W-s)),t[H].testNumber===q&&(e.fillStyle=f.accent,e.fillRect(v,W-2,o,2)),a.hasSpec){const oe=p(0,s,h),se=p(1,s,h);e.strokeStyle=f.limitLine,e.setLineDash([3,3]),e.lineWidth=1,e.beginPath(),e.moveTo(v,oe),e.lineTo(v+o,oe),e.moveTo(v,se),e.lineTo(v+o,se),e.stroke(),e.setLineDash([])}const K=a.hasSpec?U(a.ppk):f.textMuted,Q=p(a.min,s,h),R=p(a.q1,s,h),ne=p(a.median,s,h),O=p(a.q3,s,h),Y=p(a.max,s,h);e.strokeStyle=f.textMuted,e.lineWidth=1,e.beginPath(),e.moveTo(r,Q),e.lineTo(r,R),e.moveTo(r,O),e.lineTo(r,Y),e.moveTo(r-c/4,Q),e.lineTo(r+c/4,Q),e.moveTo(r-c/4,Y),e.lineTo(r+c/4,Y),e.stroke(),e.fillStyle=K,e.globalAlpha=.5,e.fillRect(r-c/2,Math.min(R,O),c,Math.max(1,Math.abs(O-R))),e.globalAlpha=1,e.strokeStyle=K,a.hasSpec||e.setLineDash([4,2]),e.strokeRect(r-c/2,Math.min(R,O),c,Math.max(1,Math.abs(O-R))),e.setLineDash([]),e.strokeStyle=f.text,e.lineWidth=2,e.beginPath(),e.moveTo(r-c/2,ne),e.lineTo(r+c/2,ne),e.stroke(),e.lineWidth=1,e.font=`${J(-1)}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=a.hasSpec?K:f.textMuted,e.fillText(a.hasSpec?j(a.ppk):"\u2014",r,s-8);const ie=a.label.length>12?`${a.label.slice(0,11)}\u2026`:a.label;e.save(),e.translate(r,W+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.font=`${J(-1)}px system-ui, sans-serif`,e.fillStyle=f.textMuted,e.fillText(ie,0,0),a.derived&&(e.fillStyle=f.text,e.fillText(`${ee} `,-e.measureText(ie).width,0)),e.restore()}),e.strokeStyle=f.border,e.lineWidth=1,e.strokeRect(C,s,i,h),ge(e,f,s,h,i)}function te(n){const o=l.getBoundingClientRect(),i=L.clientWidth,s=k(i-C),P=(n.clientX-o.left)*(l.width/We(l)/o.width)-C,g=Math.floor(P/s);return g>=0&&g<M?g:-1}return l.addEventListener("mousemove",n=>{const o=te(n);if(o!==B&&(B=o,G()),o===-1){I.style.display="none";return}const i=t[o],s=g=>V(Ne(g,i.unit)),P=i.derived?`<em>${ee} ${V(le)}</em>`+(i.expression?`<br><code>${V(i.expression)}</code>`:"")+"<br>":"";I.innerHTML=`<strong>${V(i.label)}</strong> (n=${i.n})<br>${P}`+(i.hasSpec?`${N(i.limitBasis).lo} ${s(i.lsl)} \xB7 ${N(i.limitBasis).hi} ${s(i.usl)}<br>mean ${s(i.mean)}<br>Cp ${j(i.cp)} \xB7 Cpk ${j(i.cpk)}<br>Pp ${j(i.pp)} \xB7 Ppk ${j(i.ppk)}`:`<em>No limits \u2014 sorted by variability</em><br>mean ${s(i.mean)} \xB7 stddev ${s(i.stdOverall)}`)+(X?"<br><em>click to view in boxplot</em>":""),I.style.display="block",Pe(I,m,n.clientX,n.clientY),l.style.cursor=X?"pointer":"default"}),l.addEventListener("mouseleave",()=>{B!==-1&&(B=-1,G()),I.style.display="none"}),l.addEventListener("click",n=>{if(!X)return;const o=te(n);o!==-1&&X(t[o].testNumber)}),G}function ye(){const t=ve(he(),D),l=D.filter(u=>u.testNumber!==void 0).length,M=t.filter(u=>!u.hasSpec).length;fe(t.length,M,l,t.filter(u=>u.derived).length,ae(t)),F=be(t),F()}const xe=Le(m,()=>F());return ye(),{card:m,hasData:pe,setTest:t=>{q!==t&&(q=t,F())},destroy:()=>xe.disconnect()}}
1
+ import{buildCapabilityData as Se}from"../../stats/capability.js";import{capabilityColor as G}from"./palette.js";import{LEADING as $e,SPACE as M,fontPx as Z,FONT as ee,CLR as j}from"../toolbar.js";import{cardShell as Me,isExpandedCard as Te,chartFillHeight as Ce,applyCanvasFlow as Le,observeResize as ke,makeTooltip as Pe,positionChartTooltip as Ee,renderEmptyState as we,resolveChartCanvasColors as De,chartSwatchCss as Ae,prepareCanvas as We,chartDpr as Ne}from"./chartShell.js";import{fmt as Ie}from"../../renderer/fmt.js";import{limitSetName as ae}from"../../renderer/valueFilter.js";import{escHtml as q}from"../../core/utils.js";import{DERIVED_MARK as te,DERIVED_KEY as re}from"../../renderer/testLabel.js";function I(v){return v==="spec"?{lo:"LSL",hi:"USL",noun:"spec limits"}:{lo:"Lo limit",hi:"Hi limit",noun:"test limits"}}function ce(v){let w;for(const X of v){if(!X.hasSpec)continue;const D=X.limitBasis??"test";if(w===void 0)w=D;else if(w!==D)return"mixed"}return w}const Be=30,me=160,de=90,pe=28,L=42;function z(v){return v===null?"\u2014":v.toFixed(2)}export function renderCapabilityPanel(v){const{title:w="Process capability",items:X,testDefs:D,onSaveImage:fe,onSelectTest:F}=v;let K=v.selectedTestNumber??null;const{card:p,body:k}=Me(w,fe,v.ownerDocument),he=D.some(t=>t.testNumber!==void 0);k.style.overflowX="auto";function ue(){return X}const A=p.ownerDocument.createElement("div");Object.assign(A.style,{display:"flex",flexDirection:"column",gap:M.xs,marginBottom:M.sm}),p.insertBefore(A,k);const B=Pe(p);let U=()=>{};function be(t,s,S,T,f,a){A.innerHTML="";const c=p.ownerDocument.createElement("span");Object.assign(c.style,{display:"inline-flex",alignItems:"center",gap:M.sm,color:j.value,fontSize:ee.body,fontWeight:"500"});const b=S-t,$=(s>0?` \xB7 ${s} without both limits`:"")+(a?` \xB7 ${a.total.toLocaleString("en-GB")} values outside ${ae(a.limitSet)} excluded`:""),C=p.ownerDocument.createElement("span");C.dataset.wmapCaption="1",C.textContent=b>0?`${t} of ${S} tests shown${$} \xB7 ${b} excluded (no recorded values)`:`${t} test${t!==1?"s":""} shown${$}`,c.appendChild(C),A.appendChild(c);const x=s>=t,W=p.ownerDocument.createElement("div");W.dataset.wmapCaption="1",W.textContent=x?"No test has both limits, so each is normalised to its own observed range (min = 0, max = 1) and sorted most-variable first. Ppk needs limits, so none is shown.":(f==="mixed"?"Normalised to each test's spec limits (LSL = 0, USL = 1), or its test limits (Lo limit = 0, Hi limit = 1) where it has no spec limits, worst Ppk first. ":`Normalised to ${I(f).noun} (${I(f).lo} = 0, ${I(f).hi} = 1), worst Ppk first. `)+"Tests without both limits are normalised to their own observed range and drawn muted/dashed.",Object.assign(W.style,{color:j.label,fontSize:ee.body,lineHeight:$e.base,marginTop:M.xs,maxWidth:"78ch"}),A.appendChild(W),A.appendChild(xe(p.ownerDocument,s>0,x,T>0))}function xe(t,s,S=!1,T=!1){const f=t.createElement("div");Object.assign(f.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${M.xs} ${M.xl}`,marginTop:M.xl,marginBottom:M.xs,fontSize:ee.body,color:j.label});const a=S?[]:[{color:G(2),label:"Capable \xB7 Ppk \u2265 1.33"},{color:G(1.1),label:"Marginal \xB7 Ppk \u2265 1.0"},{color:G(.5),label:"Poor \xB7 Ppk < 1.0"}];s&&a.push({color:j.label,label:"No limits \xB7 no Ppk",dashed:!0});for(const c of a){const b=t.createElement("span");Object.assign(b.style,{display:"inline-flex",alignItems:"center",gap:M.sm});const $=t.createElement("span");$.style.cssText=Ae(c.color,c.dashed?"outline":"solid");const C=t.createElement("span");C.textContent=c.label,b.append($,C),f.appendChild(b)}if(T){const c=t.createElement("span");Object.assign(c.style,{display:"inline-flex",alignItems:"center",gap:M.sm});const b=t.createElement("span");b.textContent=te,Object.assign(b.style,{color:j.value,fontWeight:"600"});const $=t.createElement("span");$.textContent=re,c.append(b,$),f.appendChild(c)}return f}function ye(t){if(k.innerHTML="",t.length===0)return we(k,"No parametric tests have any recorded values.",{maxWidth:"480px"}),()=>{};const s=p.ownerDocument.createElement("canvas");s.style.display="block",s.style.cursor="default",k.appendChild(s);const S=t.length,T=Math.min(0,...t.map(n=>n.min)),f=Math.max(1,...t.map(n=>n.max)),a=(f-T)*.05||.1,c=T-a,$=f+a-c||1;function C(n){const o=Math.floor(n/S);return Math.max(Be,Te(p)?o:Math.min(me,o))}function x(n,o,i){return o+(1-(n-c)/$)*i}function W(n,o,i,l,P){const y=t.filter(g=>g.hasSpec).length,N=y===t.length,h=y===0,E=ce(t),e=E==="mixed"?{lo:"Lo",hi:"Hi",noun:"limits"}:I(E),u=h?"max":E==="spec"?e.hi:"Hi",r=h?"min":E==="spec"?e.lo:"Lo",R=N?`normalised to ${e.noun}`:h?"normalised to range":"normalised (per test)";n.font=`${Z(-1)}px system-ui, sans-serif`,n.textAlign="right",n.textBaseline="middle";for(const[g,m]of[[1,u],[0,r]]){const d=x(g,i,l);d<i-1||d>i+l+1||(n.strokeStyle=o.limitLine,n.lineWidth=1,n.beginPath(),n.moveTo(L-5,d),n.lineTo(L,d),n.stroke(),n.fillStyle=o.textMuted,n.fillText(m,L-8,d))}n.save(),n.translate(9,i+l/2),n.rotate(-Math.PI/2),n.textAlign="center",n.fillStyle=o.textMuted,n.fillText(R,0,0),n.restore()}let H=-1;function Q(){Le(s);const n=k.clientWidth,o=C(n-L),i=o*S,l=pe,P=L+i,y=Ce(p,k,s,pe+200+de),N=Math.max(l+60,y-de),h=N-l,E=We(s,p,P,y);if(!E)return;const{ctx:e}=E,u=De(p);t.forEach((r,R)=>{const g=L+R*o,m=g+o/2,d=Math.max(4,Math.min(o,me)*.55);if(R===H&&(e.fillStyle=u.bgHover,e.fillRect(g,l,o,N-l)),t[R].testNumber===K&&(e.fillStyle=u.accent,e.fillRect(g,N-2,o,2)),r.hasSpec){const le=x(0,l,h),se=x(1,l,h);e.strokeStyle=u.limitLine,e.setLineDash([3,3]),e.lineWidth=1,e.beginPath(),e.moveTo(g,le),e.lineTo(g+o,le),e.moveTo(g,se),e.lineTo(g+o,se),e.stroke(),e.setLineDash([])}const V=r.hasSpec?G(r.ppk):u.textMuted,Y=x(r.min,l,h),O=x(r.q1,l,h),ie=x(r.median,l,h),_=x(r.q3,l,h),J=x(r.max,l,h);e.strokeStyle=u.textMuted,e.lineWidth=1,e.beginPath(),e.moveTo(m,Y),e.lineTo(m,O),e.moveTo(m,_),e.lineTo(m,J),e.moveTo(m-d/4,Y),e.lineTo(m+d/4,Y),e.moveTo(m-d/4,J),e.lineTo(m+d/4,J),e.stroke(),e.fillStyle=V,e.globalAlpha=.5,e.fillRect(m-d/2,Math.min(O,_),d,Math.max(1,Math.abs(_-O))),e.globalAlpha=1,e.strokeStyle=V,r.hasSpec||e.setLineDash([4,2]),e.strokeRect(m-d/2,Math.min(O,_),d,Math.max(1,Math.abs(_-O))),e.setLineDash([]),e.strokeStyle=u.text,e.lineWidth=2,e.beginPath(),e.moveTo(m-d/2,ie),e.lineTo(m+d/2,ie),e.stroke(),e.lineWidth=1,e.font=`${Z(-1)}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=r.hasSpec?V:u.textMuted,e.fillText(r.hasSpec?z(r.ppk):"\u2014",m,l-8);const oe=r.label.length>12?`${r.label.slice(0,11)}\u2026`:r.label;e.save(),e.translate(m,N+6),e.rotate(-Math.PI/4),e.textAlign="right",e.textBaseline="middle",e.font=`${Z(-1)}px system-ui, sans-serif`,e.fillStyle=u.textMuted,e.fillText(oe,0,0),r.derived&&(e.fillStyle=u.text,e.fillText(`${te} `,-e.measureText(oe).width,0)),e.restore()}),e.strokeStyle=u.border,e.lineWidth=1,e.strokeRect(L,l,i,h),W(e,u,l,h,i)}function ne(n){const o=s.getBoundingClientRect(),i=k.clientWidth,l=C(i-L),P=(n.clientX-o.left)*(s.width/Ne(s)/o.width)-L,y=Math.floor(P/l);return y>=0&&y<S?y:-1}return s.addEventListener("mousemove",n=>{const o=ne(n);if(o!==H&&(H=o,Q()),o===-1){B.style.display="none";return}const i=t[o],l=y=>q(Ie(y,i.unit)),P=i.derived?`<em>${te} ${q(re)}</em>`+(i.expression?`<br><code>${q(i.expression)}</code>`:"")+"<br>":"";B.innerHTML=`<strong>${q(i.label)}</strong> (n=${i.n}${i.excluded?`, ${i.excluded.count} outside ${ae(i.excluded.limitSet)} excluded`:""})<br>${P}`+(i.hasSpec?`${I(i.limitBasis).lo} ${l(i.lsl)} \xB7 ${I(i.limitBasis).hi} ${l(i.usl)}<br>mean ${l(i.mean)}<br>Cp ${z(i.cp)} \xB7 Cpk ${z(i.cpk)}<br>Pp ${z(i.pp)} \xB7 Ppk ${z(i.ppk)}`:`<em>No limits \u2014 sorted by variability</em><br>mean ${l(i.mean)} \xB7 stddev ${l(i.stdOverall)}`)+(F?"<br><em>click to view in boxplot</em>":""),B.style.display="block",Ee(B,p,n.clientX,n.clientY),s.style.cursor=F?"pointer":"default"}),s.addEventListener("mouseleave",()=>{H!==-1&&(H=-1,Q()),B.style.display="none"}),s.addEventListener("click",n=>{if(!F)return;const o=ne(n);o!==-1&&F(t[o].testNumber)}),Q}function ge(){const t=Se(ue(),D),s=D.filter(a=>a.testNumber!==void 0).length,S=t.filter(a=>!a.hasSpec).length,T=t.reduce((a,c)=>a+(c.excluded?.count??0),0),f=t.find(a=>a.excluded)?.excluded?.limitSet;be(t.length,S,s,t.filter(a=>a.derived).length,ce(t),T>0&&f?{total:T,limitSet:f}:void 0),U=ye(t),U()}const ve=ke(p,()=>U());return ge(),{card:p,hasData:he,setTest:t=>{K!==t&&(K=t,U())},destroy:()=>ve.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()}}