@wafertools/wafermap 0.34.0 → 0.35.1

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 (104) hide show
  1. package/AGENTS.md +7 -1
  2. package/CHANGELOG.md +189 -1
  3. package/README.md +6 -3
  4. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +1 -1
  5. package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
  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/chartShell.d.ts +17 -2
  9. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  13. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +6 -1
  14. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  17. package/dist/packages/canvas-adapter/dataTab.d.ts +6 -0
  18. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  19. package/dist/packages/canvas-adapter/dieList.js +6 -6
  20. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  21. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  22. package/dist/packages/canvas-adapter/identityHeader.d.ts +4 -1
  23. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  24. package/dist/packages/canvas-adapter/insightsTab.d.ts +3 -1
  25. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  26. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  27. package/dist/packages/canvas-adapter/plotTab.d.ts +3 -0
  28. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  29. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +8 -0
  30. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  31. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +22 -1
  32. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  33. package/dist/packages/canvas-adapter/summaryPanel.d.ts +39 -11
  34. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  35. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  36. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  37. package/dist/packages/canvas-adapter/sweepEditor.js +1 -1
  38. package/dist/packages/canvas-adapter/toolbar.d.ts +8 -0
  39. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  40. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  41. package/dist/packages/canvas-adapter/userGuideHtml.js +57 -27
  42. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  43. package/dist/packages/canvas-adapter/version.js +1 -1
  44. package/dist/packages/canvas-adapter/warnings.js +1 -1
  45. package/dist/packages/core/classify.d.ts +5 -0
  46. package/dist/packages/core/classify.js +1 -1
  47. package/dist/packages/core/dieTable.d.ts +26 -0
  48. package/dist/packages/core/dieTable.js +1 -1
  49. package/dist/packages/core/index.d.ts +1 -1
  50. package/dist/packages/core/index.js +1 -1
  51. package/dist/packages/core/passBins.d.ts +6 -0
  52. package/dist/packages/core/passBins.js +1 -1
  53. package/dist/packages/core/reticle.d.ts +20 -0
  54. package/dist/packages/core/reticle.js +1 -1
  55. package/dist/packages/core/wafer.d.ts +15 -0
  56. package/dist/packages/core/wafer.js +1 -1
  57. package/dist/packages/renderer/buildView.js +1 -1
  58. package/dist/packages/renderer/buildWaferMap.d.ts +32 -1
  59. package/dist/packages/renderer/buildWaferMap.js +1 -1
  60. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  61. package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
  62. package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
  63. package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
  64. package/dist/packages/renderer/derivedTests/parser.js +2 -2
  65. package/dist/packages/renderer/spec.d.ts +4 -0
  66. package/dist/packages/renderer/spec.js +1 -1
  67. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  68. package/dist/packages/renderer/valueFilter.js +1 -0
  69. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  70. package/dist/packages/stats/analyzeWaferMap.d.ts +44 -3
  71. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  72. package/dist/packages/stats/capability.d.ts +5 -0
  73. package/dist/packages/stats/capability.js +1 -1
  74. package/dist/packages/stats/clusterDetection.js +1 -1
  75. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  76. package/dist/packages/stats/connectedComponents.js +1 -1
  77. package/dist/packages/stats/dieRegions.d.ts +42 -0
  78. package/dist/packages/stats/dieRegions.js +1 -0
  79. package/dist/packages/stats/facets.d.ts +8 -0
  80. package/dist/packages/stats/facets.js +1 -1
  81. package/dist/packages/stats/index.d.ts +2 -1
  82. package/dist/packages/stats/index.js +1 -1
  83. package/dist/packages/stats/lotPattern.js +1 -1
  84. package/dist/packages/stats/math.d.ts +25 -3
  85. package/dist/packages/stats/math.js +1 -1
  86. package/dist/packages/stats/metadataColumns.js +1 -1
  87. package/dist/packages/stats/patternClassification.d.ts +44 -18
  88. package/dist/packages/stats/patternClassification.js +1 -1
  89. package/dist/packages/stats/plotData.d.ts +12 -1
  90. package/dist/packages/stats/plotData.js +1 -1
  91. package/dist/packages/stats/plotSpec.d.ts +1 -1
  92. package/dist/packages/stats/plotSpec.js +1 -1
  93. package/dist/packages/stats/regions.d.ts +15 -0
  94. package/dist/packages/stats/regions.js +1 -1
  95. package/dist/packages/stats/renderSummaryReport.js +33 -33
  96. package/dist/packages/stats/reportHtml.d.ts +7 -6
  97. package/dist/packages/stats/reportHtml.js +39 -37
  98. package/dist/packages/stats/synthesis.d.ts +44 -17
  99. package/dist/packages/stats/synthesis.js +1 -1
  100. package/dist/packages/stats/types.d.ts +12 -0
  101. package/llms.txt +2 -2
  102. package/package.json +1 -1
  103. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  104. 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
@@ -241,7 +247,7 @@ compatibility shims for them.
241
247
  - [API reference](https://wafertools.github.io/wafermap/api/) — every type, option and return value
242
248
  - [Developer guide](https://wafertools.github.io/wafermap/guide/) — worked walkthroughs
243
249
  - [Troubleshooting](https://wafertools.github.io/wafermap/troubleshooting/)
244
- - [Examples](https://wafertools.github.io/wafermap/examples/) — 23 runnable pages, also
250
+ - [Examples](https://wafertools.github.io/wafermap/examples/) — 25 runnable pages, also
245
251
  [downloadable](https://wafertools.github.io/wafermap/wafermap-examples.zip) to run offline
246
252
 
247
253
  When a rule here and the API reference disagree, the API reference wins — tell the
package/CHANGELOG.md CHANGED
@@ -22,6 +22,194 @@ under `### Breaking`.
22
22
 
23
23
  ---
24
24
 
25
+ ## [Unreleased]
26
+
27
+ ## [0.35.1] — 2026-10-09
28
+
29
+ ### Added
30
+
31
+ - **Validity limits, and a value filter that excludes values outside a limit set.** A test can carry `validLow`/`validHigh`: the
32
+ range a real measurement lies in. A value outside it is a tester clamp (a range overflow, an open-circuit rail), not a reading.
33
+ `buildWaferMap`'s `valueFilter` option chooses which limit set a value must lie inside: `'validity'` (the default, which only
34
+ affects tests that have validity limits), `'spec'` or `'test'` to keep only values inside the specification or test limits, or
35
+ `'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
36
+ is computed from the filtered values. Bins and each die's recorded verdict are the tester's own and are unchanged.
37
+ - **Excluded values are counted and shown.** `WaferMapResult.valueFilter` gives the limit set and, per test, how many values were
38
+ excluded, and the result's warnings carry a `values-excluded` line. The tooltip on a grey die names the excluded value and the
39
+ limit set. The Summary panel (a total beside N and an Excl. column), its CSV export, the summary report, the Plot footnote, the
40
+ histogram and boxplot captions and the capability tooltip and caption state the count. `CapabilityDatum.excluded` carries it;
41
+ `n` does not include excluded values.
42
+
43
+ - **`StatsSummary.stats.testFailures`: the dies each test fails.** Per test number, the failing dies' keys (outside its limits for a
44
+ parametric test, failing for a functional one) and `lostDies`, how many of them also fail the wafer's yield. Absent when no test fails
45
+ a die.
46
+
47
+ ### Changed
48
+
49
+ - **"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
50
+ 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
51
+ values with the dies it fails selected. The sentences themselves no longer contain links. The leading item's parts (its fail bins,
52
+ with their legend colours, the spatial pattern, and tests failing on the same dies) are chips under its sentence, each showing that
53
+ part alone.
54
+ - **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
55
+ 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
56
+ 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
57
+ 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
58
+ against it as a second item over the same dies.
59
+ - **A lot of one wafer is described from that wafer.** Its "What stands out" is the wafer's own.
60
+ - **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
61
+ finding, and its region items are now costed by the pass bin's fall (the whole shortfall), with the fail bins as its parts.
62
+ - **When nothing costs a yield point but a finding below is marked Unusual**, "What stands out" says so instead of "Nothing stands
63
+ out".
64
+ - **A map of soft-bin-only data opens in soft-bin mode.** Without a `plotMode` from the host, `renderWaferMap` and
65
+ `renderWaferGallery` open on hard bins when the dies carry any, otherwise soft bins. `WaferMapResult.plotMode` is `'softBin'`
66
+ for such data.
67
+ - **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
68
+ points below the lot median"), or as "Wafer 5 (no ID)" when it has none, as every other surface names it.
69
+ - **The single map's auto-mounted Summary panel shows a clicked finding or row as selected**, and its findings filters apply, as the
70
+ placed panel's do.
71
+ - **Bins are said to "account for" a region's shortfall only when together they fit within it.** When other fail bins fell in the
72
+ 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
73
+ 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.
74
+ - **The spatial pattern classifier finds scratches at any angle and donuts by their radial profile.** A scratch is a thin line
75
+ 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
76
+ the radius long, reaching in from the rim, with the fragments that continue it along the same line counted as one line. A donut
77
+ 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
78
+ 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
79
+ 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
80
+ and near-full are unchanged; exact match 71.1%. `PatternFeatures` gains `lineWidth`, `lineLength`, `lineSize`,
81
+ `lineMinDistNorm`, `lineMaxDistNorm` and `radialFailRates`. Pattern labels, the spatial-pattern finding and "What stands out"
82
+ change accordingly.
83
+ - **A region holds only against the regions that are not themselves deviant.** The significant findings for one variable and region
84
+ family are re-tested against each other: a loss is taken before a gain, each must hold against the rest without the regions that
85
+ 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
86
+ block ("Rings 2–3 lower pass rate"), not as the rings either side of it being better, and a failing quadrant brings no "lower"
87
+ finding from the sectors opposite it: on synthetic lots with a failing quadrant, no wafer or lot reports one. Findings on the
88
+ opposite side of a strong pattern are no longer reported, and "What stands out" and its "also seen as" lists change accordingly.
89
+ - **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
90
+ 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
91
+ ring's item, which costs the ring's loss.
92
+ - **One false-discovery family per analysis.** Benjamini–Hochberg now adjusts every rate comparison on a wafer together (yield,
93
+ hard and soft bins, functional tests and limit fail rates, in every region family) and every regional comparison of a lot
94
+ together. Findings that rested on weak evidence are no longer reported, and severities, `adjustedPValue`,
95
+ `hasNotableFindings` and "What stands out" change accordingly.
96
+ - **Rates with small expected counts are tested exactly.** A region's rate is compared with Fisher's exact test when any expected
97
+ count of its 2×2 table is under 5, and with the two-proportion z-test otherwise; `stats.method` is `'fisher-exact'` or
98
+ `'two-proportion-z'`.
99
+ - **A cluster or edge arc is tested by its size against random placement.** A group of failing dies is found because it fails,
100
+ 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
101
+ from the layout and fail count so a wafer always gets the same answer) and a group is reported when random placement rarely
102
+ makes one that large: `stats.method` is `'permutation'`, the smallest p-value is 0.01, and `adjustedPValue` equals `pValue`
103
+ (the comparison with the largest group is already family-wise). Random failures no longer read as clusters: on synthetic
104
+ 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%
105
+ from 20% up (see Detection analysis). Faint patterns that show only as a contiguous group are found less often: on WM-811K the
106
+ regional analysis rescues 90.3% of the patterns the classifier misses, and combined detection is 98.7%. Cluster p-values,
107
+ severities and the edge arcs listed under an edge ring change accordingly.
108
+ - **Small p-values are exact to double precision.** Every z-based p-value reads the normal tail from W. J. Cody's erfc (about
109
+ 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
110
+ very strong findings are weighed against each other (a sector run against the quadrant over the same angle, the smaller p-value
111
+ 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.
112
+ - **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
113
+ 10°, as an arc anywhere else does.
114
+ - **Quadrants are quarter turns of equal share.** A die is in the quadrant whose quarter turn, counted counter-clockwise from
115
+ 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
116
+ 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
117
+ is NE). Quadrant yields, quadrant findings and the Ring | Quadrant region tables change for such data, by up to two points on a
118
+ wafer of a few hundred dies.
119
+ - **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
120
+ region's dies, as a yield finding does, without picking out the passing dies.
121
+ - **A sector is compared with the other sectors** in "What stands out" ("below the other sectors"), as its finding is: sectors leave
122
+ out the dies near the centre.
123
+ - **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
124
+ 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
125
+ finding or "What stands out" row again restores the plot mode and test in use before it was first clicked.
126
+ - **"Also seen as" counts a long family** ("9 edge arcs") instead of naming each, and the compact list's heading reads "Also, each
127
+ costing at least 1% of the dies".
128
+ - **Gallery cards fill the width they are given.** In auto layout, when there are more cards than columns, the columns share the whole
129
+ row: width too narrow for another column (the Summary panel closing, a wider window) enlarges the cards instead of leaving an empty
130
+ 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.
131
+ - **The Summary panel opens from a labelled Summary button and closes from its own header.** The button sits in the row above the map,
132
+ just before Map | Insights (above the panel it opens), and shows as pressed while the panel is open; its icon takes the findings colour
133
+ 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
134
+ 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 (▸
135
+ 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
136
+ button, shows no close button. For half a second after the panel closes, a click where its close button was goes nowhere:
137
+ closing widens the map or the gallery, which moves an Expand button under the pointer, and a quick second click would
138
+ otherwise open it.
139
+ - **The Findings section's controls are its severity chips.** The header says how many findings are unusual or notable ("1 unusual,
140
+ 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
141
+ map, and a spatial pattern has a "Show 3 supporting findings" line under it that opens the regional findings it explains (open from
142
+ 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
143
+ grouped by region, and the Summary report holds the findings at length.
144
+ - **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
145
+ Functional Tests section. The leading item ends with a "See" line naming its region and its parts. Links are drawn in a link colour.
146
+
147
+ ### Docs
148
+
149
+ - **Validity limits and the value filter are documented** in the API reference (`TestDef.validLow`/`validHigh`, `valueFilter`, `WaferMapResult.valueFilter`, the `values-excluded` warning),
150
+ 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
151
+ sample data carries validity limits and a few clamped readings.
152
+ - **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,
153
+ 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
154
+ (`hbin()`); the retests example shows `supersedes`; `findingsNotice` and `setFindingsNotice` are in the API reference.
155
+
156
+ ## [0.35.0] — 2026-10-06
157
+
158
+ ### Added
159
+
160
+ - **Reticle cell and Reticle shot, as die fields.** With a `reticleConfig`, a die's position within the mask (**Reticle cell**,
161
+ `Reticle cell (1, 3)`) and where on the wafer the mask was placed for it (**Reticle shot**, `Reticle shot (-1, 2)`) join ring and
162
+ quadrant as categories to colour a plot by, to put on a bar or box's axis and to split yield by, as columns of the Dies table, and
163
+ **Reticle cell** is a third choice beside Ring | Quadrant in the Summary panel's region yield, one row per cell in numeric order.
164
+ They are offered only when a reticle is set. The wafer carries it as `wafer.reticle`. A cell repeats in every shot, so it shows a
165
+ problem with the mask; a shot is one place on the wafer, so it shows one that varies across it. `getReticleShot` is exported
166
+ beside `getReticleCell`.
167
+ - **Pass/fail tests are plot fields, under Verdicts.** A functional test, or a derived test that gives a verdict, is offered as a
168
+ category (`Scan Chain (pass/fail)`: Pass or Fail per die) to colour a plot by, to compare on a bar or box's axis, and to split
169
+ yield by, so "Vth for dies that pass the scan chain and dies that fail it" is a box with two boxes. It is never an axis value, and a
170
+ die with no recorded outcome is in neither group.
171
+ - **A derived-test expression can read a die's own fields.** `dieX()`, `dieY()`, `hbin()`, `sbin()` and `site()` give a die's position,
172
+ bins and probe site, so a derived test can be cut by bin (`hbin() == 5`) or position (`if(dieX() < 5, t[1010], 0 - 1)`). A field
173
+ the die lacks is no value, not zero. Written without its parentheses it is refused with the call to use.
174
+ - **Reticle cell yield, a card on the Overview.** With a `reticleConfig` the Overview gains a grid of the stepper field, one cell per
175
+ position in it (row 0 at the bottom), filled from the same yield ramp as the ring and quadrant cards and labelled with its yield.
176
+ A cell pools every field on every wafer, so a low one points at the mask, not the wafer. Hover a cell for which it is and its dies;
177
+ click it to chart or tabulate them. `renderRegionYieldDiagram` takes `mode: 'reticleCell'` and `grid`, and `parseReticleCellKey`
178
+ reads a cell's column and row from its key.
179
+
180
+ - **`attributes` on `renderWaferMap` and `renderWaferGallery`: your own names for wafer attributes.** One entry per metadata key
181
+ (`{ label, facet?, date? }`, over the defaults) says what an attribute is called, whether it is a Group by and Compare by choice
182
+ (`facet: false` keeps a low-value field such as a program revision out of those lists while it still shows on the header strip,
183
+ in the Wafers table and in reports), and whether it is a date, grouped by day. The header strip and its popover, Group by, the
184
+ plot fields (also in the right-click plot menu), the Wafers table and the reports name an attribute through one function,
185
+ `attributeLabel(key, curation?)`, so they cannot disagree. `WaferAttributeDef` is the entry's type.
186
+
187
+ ### Changed
188
+
189
+ - **A wafer attribute has one name everywhere.** Group by and the plot fields call the test program **Test Program** and the date
190
+ **Test Date**, as the header strip, the Wafers table and the reports already did (they were "Program" and "Test date" there). The
191
+ plot fields no longer list an attribute that is unique to each wafer (`waferId`): the Wafer field is that.
192
+ - **The plot editor's Categories and Colour hints say what they compare.** A hint now reads "Compare by this field" and names the two kinds
193
+ of field it takes, a wafer attribute or a die region, and the guide explains how that differs from Group by.
194
+ - **Ring, quadrant and the reticle regions are defined once.** The plot fields and the Dies table read one definition
195
+ (`stats/dieRegions.ts`: `DIE_REGIONS`, `availableRegions`), so a region is offered, named and valued the same way in both, and findings and region yield group dies by the same definition. The
196
+ Dies table says `Ring 2` where it said `2` (the exported file keeps the bare number) and shows Ring and Quadrant only for dies
197
+ whose position in millimetres is known.
198
+ - **Escape in a menu closes the menu and leaves its window open.** A menu opened from a plot or sweep editor, or any other
199
+ window, closes on Escape; a second Escape closes the window. Keys that something inside a window has already handled no
200
+ longer also close it.
201
+ - **The segmented toggles say what each choice means.** Hard bins and Soft bins, Ring, Quadrant and Reticle cell, the pass-rate
202
+ judgements (Test limits, Tester flag, Functional), the plot editor's chart types and its Setup and Customise tabs, a sweep's X
203
+ value source, and the Data tab's Statistics, Dies, Wafers and Wide, Long switches carry a hover hint. A segmented control's option
204
+ takes an optional third element, its hint.
205
+ - **The Plot tab's buttons, the chart axis toggles and the CSV buttons carry a hover hint.** New plot, New sweep, Add
206
+ examples, Import, Export, Delete all and each card's Edit, Duplicate and Delete say what they do; so do Axis includes
207
+ limits, Clip outliers, Log scale, Max tests, and the Test values, Functional and Correlation CSV buttons. A hint's text is
208
+ recorded on its element as `data-wmap-tip`.
209
+ - **Limit labels on a scatter's two axes keep clear of each other.** A high limit on Y and a low limit on X both labelled
210
+ the top-left corner and drew on top of one another; a label now moves down a row until it overlaps none already drawn, in
211
+ the Plot tab's scatter and the Insights scatter alike (`placeClearOf` in `charts/chartShell.ts` is the one rule).
212
+
25
213
  ## [0.34.0] — 2026-10-06
26
214
 
27
215
  ### Added
@@ -231,7 +419,7 @@ under `### Breaking`.
231
419
  - **One σ rule: the sample standard deviation (n−1).** The Test Values table, per-test statistics, the
232
420
  lot trend, the lot drift σ and the report's pooled σ all divide by n−1, as the capability indices
233
421
  already did, so a cell shows the same σ whichever path filled it. A displayed σ is √(n/(n−1)) times
234
- the population σ of the same values (about 2.5% at n = 20; negligible on large lots). Exported
422
+ the population σ of the same values (about 2.6% at n = 20; negligible on large lots). Exported
235
423
  `sampleVariance` in `stats/math.ts` is the single implementation.
236
424
 
237
425
  ## [0.33.0] — 2026-10-02
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-~64%20kB-blue)
8
+ ![bundle](https://img.shields.io/badge/data%20layer%20min%2Bgz-~70%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 ~64 kB
16
+ Svelte, Vue, plain HTML, or a Web Worker. The DOM-free data-and-stats layer is ~70 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
 
@@ -12,7 +12,7 @@ export interface ChartPanel {
12
12
  */
13
13
  selfControl?: {
14
14
  current: string;
15
- options: Array<[value: string, label: string]>;
15
+ options: Array<[value: string, label: string, hint?: string]>;
16
16
  onChange: (value: string) => {
17
17
  data: ChartDatum[];
18
18
  title?: string;
@@ -1 +1 @@
1
- import{buildBinClusterData as x}from"../../stats/binPareto.js";import{SPACE as H,FONT as T,CLR as E}from"../toolbar.js";import{cardShell as L,makeTooltip as $,makeSegmented as D,renderEmptyState as I}from"./chartShell.js";import{renderGroupedBarPlot as R}from"./groupedBarPlot.js";import{escHtml as g}from"../../core/utils.js";const k=90,M=8;export function renderBinClusterPanel(e){const{groups:f,onSaveImage:S}=e;let i="hbin",u=e.title??"Hard bin pareto";const{card:n,heading:h,body:l,controlsRow:B}=L(u,S,e.ownerDocument);B.appendChild(D([["hbin","Hard bins"],["sbin","Soft bins"]],i,o=>{i=o,u=`${i==="hbin"?"Hard":"Soft"} bin pareto`,h.textContent=u,m()},n.ownerDocument));const s=n.ownerDocument.createElement("div");s.dataset.wmapCaption="1",s.textContent="One cluster per bin \xB7 a sub-bar per group"+(e.onSelectBin?" \xB7 click a sub-bar to chart or tabulate its dies":""),Object.assign(s.style,{color:E.label,fontSize:T.body,marginBottom:H.sm}),n.insertBefore(s,l);const C=$(n);let c=null;function m(){c?.destroy(),c=null,l.innerHTML="";const o=x(f,i);if(o.bins.length===0||o.groups.length===0){I(l,"No bin data available for the current grouping.");return}const d=o.groups,b=o.bins,y=Math.max(1,...b.flatMap(t=>t.counts));c=R(n,l,C,{rows:b.map(t=>({label:t.label,bars:t.counts.map(r=>({fraction:r/y})),trailing:`${t.total}`})),groups:d,labelWidth:k,maxVisibleRows:M,onRowClick:e.onSelectBin?(t,r,a)=>e.onSelectBin({bin:b[t].binCode,binType:i,groupKey:d[r]},a):void 0,tooltipHtml:(t,r)=>{const a=b[t],p=a.counts[r],w=a.total>0?p/a.total*100:0;return`<strong>${g(a.label)}</strong> \xB7 ${g(String(d[r]))}<br>${p} dies (${w.toFixed(1)}% of bin)`}})}return m(),{card:n,destroy:()=>c?.destroy()}}
1
+ import{buildBinClusterData as T}from"../../stats/binPareto.js";import{SPACE as x,FONT as H,CLR as E}from"../toolbar.js";import{cardShell as L,makeTooltip as $,makeSegmented as D,renderEmptyState as I}from"./chartShell.js";import{renderGroupedBarPlot as R}from"./groupedBarPlot.js";import{escHtml as g}from"../../core/utils.js";const k=90,M=8;export function renderBinClusterPanel(e){const{groups:h,onSaveImage:f}=e;let i="hbin",u=e.title??"Hard bin pareto";const{card:o,heading:S,body:l,controlsRow:y}=L(u,f,e.ownerDocument);y.appendChild(D([["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],i,n=>{i=n,u=`${i==="hbin"?"Hard":"Soft"} bin pareto`,S.textContent=u,m()},o.ownerDocument));const s=o.ownerDocument.createElement("div");s.dataset.wmapCaption="1",s.textContent="One cluster per bin \xB7 a sub-bar per group"+(e.onSelectBin?" \xB7 click a sub-bar to chart or tabulate its dies":""),Object.assign(s.style,{color:E.label,fontSize:H.body,marginBottom:x.sm}),o.insertBefore(s,l);const B=$(o);let c=null;function m(){c?.destroy(),c=null,l.innerHTML="";const n=T(h,i);if(n.bins.length===0||n.groups.length===0){I(l,"No bin data available for the current grouping.");return}const d=n.groups,b=n.bins,C=Math.max(1,...b.flatMap(t=>t.counts));c=R(o,l,B,{rows:b.map(t=>({label:t.label,bars:t.counts.map(r=>({fraction:r/C})),trailing:`${t.total}`})),groups:d,labelWidth:k,maxVisibleRows:M,onRowClick:e.onSelectBin?(t,r,a)=>e.onSelectBin({bin:b[t].binCode,binType:i,groupKey:d[r]},a):void 0,tooltipHtml:(t,r)=>{const a=b[t],p=a.counts[r],w=a.total>0?p/a.total*100:0;return`<strong>${g(a.label)}</strong> \xB7 ${g(String(d[r]))}<br>${p} dies (${w.toFixed(1)}% of bin)`}})}return m(),{card:o,destroy:()=>c?.destroy()}}
@@ -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 yt,renderEmptyState as Ee,fitRowsHeight as Tt,setChartGrow as wt,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);wt(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 T=u.selectedTestNumber??ie[0]?.testNumber??null,le=!1,F=0,b=null,D=null,se=null,ye=null;function ze(){const i=!g||g.length===0?"":b??"\0overview";if(se&&ye===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,ye=i,p}function Te(){b!==null&&!D?(D=ht(()=>{we(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 we(i){return b===i||i!==null&&!(g??[]).some(p=>p.key===i)?!1:(b=i,Te(),j(),$(),!0)}const ve=gt(ie,T,i=>{T=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));const ae=a.ownerDocument.createElement("span");Object.assign(ae.style,{display:"inline-flex",gap:He.lg,alignItems:"center"}),U.appendChild(ae);const re=yt(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(),Te();const E=xt(a);let ce=null;function $(){const{includeLimits:i,clipOutliers:p,limits:v}=re.get();if(j(),x.innerHTML="",ie.length===0||T===null){Ee(x,"No parametric test data available for box plots.");return}const S=ze(),h=rt(S,T),K=be.find(t=>t.testNumber===T),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=`${Tt(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 y=M+f*(C+A),r=y+C/2;f===G&&(e.fillStyle=t.bgHover,e.fillRect(0,y-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=y+3,z=y+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 w=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:w},"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),y=e.measureText(o.label).width,r=At(f,y,l,l+c,o.end==="lo"),te=r<0?f-3-y:f+3;return{l:o,x:f,dir:r,start:te,end:te+y}}),tt=It(Se),nt=_(-1)+2;Se.forEach(({l:o,x:f,dir:y},r)=>{Bt(e,o,t.limitLine,f,0,f,w),e.fillStyle=t.limitLine,e.textAlign=y<0?"right":"left",e.textBaseline="bottom",e.fillText(o.label,f+y*3,w-1-tt[r]*nt)}),e.font=`${_(-1)}px system-ui, sans-serif`,e.strokeStyle=t.border,e.lineWidth=1,e.beginPath(),e.moveTo(l,w),e.lineTo(l+c,w),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,w),e.lineTo(f,w+4),e.stroke(),e.fillText(pe.tick(o),f,w+6)}pe.unitLabel&&(e.textAlign="left",e.font=`${_(-1)}px system-ui, sans-serif`,e.fillText(`(${pe.unitLabel})`,l+c+22,w+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;we(e),u.onGroupChange?.(e);return}const d=S[n]?.waferIndex;Q&&d!==void 0&&T!==null&&Q(d,T)}),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,T??void 0,t))}),ce?.disconnect(),ce=dt(a,()=>ee()),ee()}$();function Ue(i){ve.set(i)&&(T=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 b=u.selectedTestNumber??ie[0]?.testNumber??null,le=!1,F=0,w=null,D=null,se=null,we=null;function ye(){const i=!g||g.length===0?"":w??"\0overview";if(se&&we===i)return se;const p=!g||g.length===0?Ge:w!==null?g.find(k=>k.key===w)?.items??[]:g.map(k=>({label:k.key,dies:k.items.flatMap(T=>T.dies??[])}));return se=p,we=i,p}function Te(){w!==null&&!D?(D=ht(()=>{ve(null),u.onGroupChange?.(null)},a.ownerDocument),U.appendChild(D)):w===null&&D&&(D.remove(),D=null),ze.textContent=w!==null?`${ne} \u2014 ${oe}: ${w}`:ne}function ve(i){return w===i||i!==null&&!(g??[]).some(p=>p.key===i)?!1:(w=i,Te(),j(),S(),!0)}const ke=gt(ie,b,i=>{b=i,S(),u.onTestChange?.(i)},{maxWidth:"240px",emptyText:"No parametric tests",ownerDocument:a.ownerDocument}),Qe=ke.el;U.appendChild(Qe),U.appendChild(bt("Log scale",le,i=>{le=i,S()},a.ownerDocument,"Draw the value axis on a logarithmic scale"));const ae=a.ownerDocument.createElement("span");Object.assign(ae.style,{display:"inline-flex",gap:De.lg,alignItems:"center"}),U.appendChild(ae);const re=wt(ae,u.axisPrefs,i=>{u.onAxisPrefsChange?.(i),S()},a.ownerDocument),V=a.ownerDocument.createElement("div");V.dataset.wmapCaption="1",Object.assign(V.style,{color:ft.label,fontSize:ct.body,marginBottom:De.sm}),a.insertBefore(V,x);function j(){const i=!!g&&g.length>0&&w===null,p=[];i?p.push(`click a ${oe}'s box to see it by wafer`):Q&&p.push(`click a box to ${qe}`);const k=p.length?`${p[0][0].toUpperCase()}${p[0].slice(1)} \xB7 `:"";V.textContent=`${k}box = Q1\u2013Q3, line = median, whiskers = min/max \xB7 value shown is the median`+(F?` \xB7 axis clipped, ${F} value${F===1?"":"s"} outside`:"")+(b!==null?Wt(ye().flatMap(T=>T.dies??[]),b):"")}j(),Te();const E=xt(a);let ce=null;function S(){const{includeLimits:i,clipOutliers:p,limits:k}=re.get();if(j(),x.innerHTML="",ie.length===0||b===null){Oe(x,"No parametric test data available for box plots.");return}const T=ye(),h=rt(T,b),K=be.find(t=>t.testNumber===b),O=K?.unit,fe=Pe(K,k),{lo:Ve,hi:je}=$t(fe);if(h.every(t=>t.count===0)){Oe(x,"No parametric test data available for box plots.");return}const m=a.ownerDocument.createElement("canvas");m.style.display="block",m.style.cursor="default",x.appendChild(m);const Me=L*2+Math.min(h.length,Pt)*(A+$)+Ne;x.style.maxHeight=`${Me}px`,x.style.overflowY="auto",x.style.scrollbarGutter="stable";let N=-1;const ue=h.filter(t=>t.count>0),Le=Ot(ue.map(t=>t.min)),Ce=Et(ue.map(t=>t.max)),Ae=i??Lt(Le,Ce,Ve,je);re.sync(Ae,Pe(K).length>0,St(K));const G=Mt({dataMin:Le,dataMax:Ce,limits:fe,includeLimits:Ae,clipOutliers:p,values:ue.flatMap(t=>[t.min,t.q1,t.median,t.q3,t.max])});F=G.clippedCount,j();const W=G.lo,J=G.hi,Ke=J-W||1,Z=le&&W>0,me=Z?Math.log10(W):0,$e=(Z?Math.log10(J):0)-me||1,de=Math.max(Math.abs(W),Math.abs(J));function Je(){const t=L+_e,s=m.clientWidth-t-Rt-L;return{plotX:t,plotMaxWidth:Math.max(10,s)}}function I(t,s,n){return Z?s+(Math.log10(t)-me)/$e*n:s+(t-W)/Ke*n}function Ze(t,s){if(Z){const d=[];for(let e=0;e<=4;e++)d.push(Math.pow(10,me+$e*e/4));return{ticks:d,axis:We(de,O)}}const n=ut(W,J,s,kt(t,de,O));return{ticks:n.ticks,axis:We(de,O,n.step||void 0)}}function ee(){const t=vt(a),s=L*2+h.length*(A+$)+Ne;x.style.maxHeight=`${yt(a,x,Me,s)}px`;const n=x.clientWidth,d=Dt(m,a,n,s);if(!d)return;const{ctx:e}=d;e.font=`${_(-1)}px system-ui, sans-serif`,e.textBaseline="middle";const{plotX:l,plotMaxWidth:c}=Je();h.forEach((o,f)=>{const y=L+f*(A+$),r=y+A/2;f===N&&(e.fillStyle=t.bgHover,e.fillRect(0,y-$/2,n,A+$)),e.fillStyle=t.text,e.textAlign="right";const te=o.label.length>16?`${o.label.slice(0,15)}\u2026`:o.label;if(e.fillText(te,L+_e-8,r),o.count===0){e.fillStyle=t.textMuted,e.textAlign="left",e.fillText("no data",l,r);return}const it=l+c,q=at=>Math.min(it,Math.max(l,at)),Be=I(o.min,l,c),Re=I(o.max,l,c),B=q(Be),Y=q(I(o.q1,l,c)),He=q(I(o.median,l,c)),he=q(I(o.q3,l,c)),R=q(Re),lt=Be<B,st=Re>R,H=y+3,z=y+A-3;e.strokeStyle=t.textMuted,e.lineWidth=1,e.beginPath(),e.moveTo(B,r),e.lineTo(Y,r),e.moveTo(he,r),e.lineTo(R,r);const M=3;lt?(e.moveTo(B+M,r-M),e.lineTo(B,r),e.lineTo(B+M,r+M)):(e.moveTo(B,H),e.lineTo(B,z)),st?(e.moveTo(R-M,r-M),e.lineTo(R,r),e.lineTo(R-M,r+M)):(e.moveTo(R,H),e.lineTo(R,z)),e.stroke(),e.fillStyle=Ee,e.globalAlpha=.35,e.fillRect(Y,H,Math.max(1,he-Y),z-H),e.globalAlpha=1,e.strokeStyle=Ee,e.strokeRect(Y,H,Math.max(1,he-Y),z-H),e.strokeStyle=t.text,e.lineWidth=2,e.beginPath(),e.moveTo(He,H),e.lineTo(He,z),e.stroke(),e.lineWidth=1,e.fillStyle=t.textMuted,e.textAlign="left",e.fillText(ge(o.median,O,"engineering"),l+c+10,r)});const v=L+h.length*(A+$);e.font=`${_(-1)}px system-ui, sans-serif`,Ct(e,G.offAxis,{left:l,right:l+c,top:0,bottom:v},"horizontal",t.limitLine,o=>ge(o,O,"engineering"));const et=new Set(G.offAxis.map(o=>o.value)),Ie=fe.filter(o=>!et.has(o.value)).map(o=>{const f=I(o.value,l,c),y=e.measureText(o.label).width,r=At(f,y,l,l+c,o.end==="lo"),te=r<0?f-3-y:f+3;return{l:o,x:f,dir:r,start:te,end:te+y}}),tt=It(Ie),nt=_(-1)+2;Ie.forEach(({l:o,x:f,dir:y},r)=>{Bt(e,o,t.limitLine,f,0,f,v),e.fillStyle=t.limitLine,e.textAlign=y<0?"right":"left",e.textBaseline="bottom",e.fillText(o.label,f+y*3,v-1-tt[r]*nt)}),e.font=`${_(-1)}px system-ui, sans-serif`,e.strokeStyle=t.border,e.lineWidth=1,e.beginPath(),e.moveTo(l,v),e.lineTo(l+c,v),e.stroke(),e.fillStyle=t.textMuted,e.textAlign="center",e.textBaseline="top";const{ticks:ot,axis:pe}=Ze(e,c);for(const o of ot){const f=I(o,l,c);e.beginPath(),e.moveTo(f,v),e.lineTo(f,v+4),e.stroke(),e.fillText(pe.tick(o),f,v+6)}pe.unitLabel&&(e.textAlign="left",e.font=`${_(-1)}px system-ui, sans-serif`,e.fillText(`(${pe.unitLabel})`,l+c+22,v+6),e.font=`${_(-1)}px system-ui, sans-serif`),e.textBaseline="middle"}function xe(t){const s=Math.floor((t-L+$/2)/(A+$));return s>=0&&s<h.length?s:-1}function X(t){return ge(t,O,"engineering")}const P=!!g&&g.length>0&&w===null,Se=t=>!P&&!!Q&&T[t]?.waferIndex!==void 0;m.addEventListener("mousemove",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n>=0&&h[n].count>0&&(P||Se(n));if(n!==N&&(N=n,m.style.cursor=d?"pointer":"default",ee()),n>=0&&h[n].count>0){const e=h[n],l=P?`<br><em>click to see this ${C(oe)} by wafer</em>`:Se(n)?`<br><em>click to ${C(Ye)}</em>`:"",c=!P&&u.onWaferContextMenu&&T[n]?.waferIndex!==void 0?Ht:"";E.innerHTML=`<strong>${C(e.label)}</strong> (${e.count} dies)<br>max ${C(X(e.max))}<br>q3 ${C(X(e.q3))}<br>median ${C(X(e.median))}<br>q1 ${C(X(e.q1))}<br>min ${C(X(e.min))}${l}${c}`,E.style.display="block",pt(E,a,t.clientX,t.clientY)}else E.style.display="none"}),m.addEventListener("mouseleave",()=>{N!==-1&&(N=-1,ee()),E.style.display="none"}),m.addEventListener("click",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top);if(n===-1||h[n].count===0)return;if(P){const e=h[n].label;ve(e),u.onGroupChange?.(e);return}const d=T[n]?.waferIndex;Q&&d!==void 0&&b!==null&&Q(d,b)}),m.addEventListener("contextmenu",t=>{const s=m.getBoundingClientRect(),n=xe(t.clientY-s.top),d=n===-1?void 0:T[n]?.waferIndex;P||d===void 0||!u.onWaferContextMenu||(E.style.display="none",u.onWaferContextMenu(d,b??void 0,t))}),ce?.disconnect(),ce=dt(a,()=>ee()),ee()}S();function Ue(i){ke.set(i)&&(b=i,S())}function Fe(i){re.set(i)&&S()}return{card:a,setTest:Ue,setAxisPrefs:Fe,destroy:()=>ce?.disconnect()}}
@@ -1 +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()}}
@@ -343,7 +343,9 @@ export interface SeriesLegendItem {
343
343
  export declare function makeSeriesLegendItem(label: string, color: string, ownerDocument?: Document): SeriesLegendItem;
344
344
  export declare function cardFrameStyle(): Partial<CSSStyleDeclaration>;
345
345
  export declare function cardShell(title: string, onSaveImage?: SaveImageHandler, ownerDocument?: Document): CardShell;
346
- export declare function makeSegmented(options: Array<[value: string, label: string]>, current: string, onChange: (value: string) => void, ownerDocument?: Document,
346
+ export declare function makeSegmented(
347
+ /** An option's optional third element is its hover hint, for a label that does not explain itself. */
348
+ options: Array<[value: string, label: string, hint?: string]>, current: string, onChange: (value: string) => void, ownerDocument?: Document,
347
349
  /** Smaller type/padding for the summary panel's 260px column, where the
348
350
  * chart-card sizing overflows a section header. Charts keep the default. */
349
351
  compact?: boolean): HTMLElement;
@@ -509,7 +511,7 @@ export declare function makeWaferSelect(items: readonly WaferSelectItem[], selec
509
511
  }): HTMLElement & {
510
512
  value: string;
511
513
  };
512
- export declare function makeToggle(labelText: string, checked: boolean, onChange: (v: boolean) => void, ownerDocument?: Document): HTMLLabelElement;
514
+ export declare function makeToggle(labelText: string, checked: boolean, onChange: (v: boolean) => void, ownerDocument?: Document, hint?: string): HTMLLabelElement;
513
515
  export declare function makeLabeledSelect(labelText: string, options: readonly {
514
516
  value: string;
515
517
  label: string;
@@ -610,6 +612,19 @@ export declare function limitExtent(lines: readonly LimitLine[]): {
610
612
  * (0 = the chart's usual label position), in input order. Greedy by position,
611
613
  * so it is stable: labels that never collide all stay on row 0.
612
614
  */
615
+ export interface LabelBox {
616
+ x0: number;
617
+ y0: number;
618
+ x1: number;
619
+ y1: number;
620
+ }
621
+ /**
622
+ * Where a label goes so it does not sit on one already drawn: `box` moved down in whole `step`s until it overlaps none of
623
+ * `taken` (at most `maxSteps`, so a crowded chart gives up rather than pushes a label off the plot). The result is added to
624
+ * `taken`. The x-axis and y-axis limit labels of one chart are placed independently, so a high limit on Y and a low limit on X
625
+ * both want the top-left corner; this is what keeps them apart.
626
+ */
627
+ export declare function placeClearOf(taken: LabelBox[], box: LabelBox, step: number, maxSteps?: number): LabelBox;
613
628
  export declare function stackLabelRows(spans: ReadonlyArray<{
614
629
  start: number;
615
630
  end: number;