@wafertools/wafermap 0.33.0 → 0.35.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 (158) hide show
  1. package/AGENTS.md +6 -6
  2. package/CHANGELOG.md +271 -0
  3. package/README.md +5 -5
  4. package/dist/packages/canvas-adapter/chartPopulation.d.ts +15 -10
  5. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +8 -1
  7. package/dist/packages/canvas-adapter/charts/barPanel.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +7 -1
  9. package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +72 -5
  13. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  14. package/dist/packages/canvas-adapter/charts/correlation.js +1 -2
  15. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +2 -0
  16. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +1 -1
  17. package/dist/packages/canvas-adapter/charts/histogram.d.ts +16 -0
  18. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  19. package/dist/packages/canvas-adapter/charts/palette.d.ts +2 -0
  20. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  21. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +27 -0
  22. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -0
  23. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +45 -0
  24. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -0
  25. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +8 -1
  26. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  27. package/dist/packages/canvas-adapter/charts/scatter.d.ts +19 -0
  28. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  29. package/dist/packages/canvas-adapter/charts/sweep.d.ts +12 -0
  30. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  31. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +7 -0
  32. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  33. package/dist/packages/canvas-adapter/charts/trend.d.ts +11 -0
  34. package/dist/packages/canvas-adapter/charts/trend.js +1 -1
  35. package/dist/packages/canvas-adapter/confirmDialog.d.ts +13 -0
  36. package/dist/packages/canvas-adapter/confirmDialog.js +1 -0
  37. package/dist/packages/canvas-adapter/dataTab.d.ts +137 -0
  38. package/dist/packages/canvas-adapter/dataTab.js +1 -0
  39. package/dist/packages/canvas-adapter/dieList.d.ts +39 -4
  40. package/dist/packages/canvas-adapter/dieList.js +6 -7
  41. package/dist/packages/canvas-adapter/drilldown.d.ts +23 -3
  42. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  43. package/dist/packages/canvas-adapter/guideWindow.d.ts +96 -0
  44. package/dist/packages/canvas-adapter/guideWindow.js +1 -0
  45. package/dist/packages/canvas-adapter/identityHeader.d.ts +19 -0
  46. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  47. package/dist/packages/canvas-adapter/index.d.ts +3 -3
  48. package/dist/packages/canvas-adapter/index.js +1 -1
  49. package/dist/packages/canvas-adapter/insightsTab.d.ts +75 -54
  50. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  51. package/dist/packages/canvas-adapter/maplessSummary.d.ts +2 -2
  52. package/dist/packages/canvas-adapter/plotEditor.d.ts +29 -0
  53. package/dist/packages/canvas-adapter/plotEditor.js +1 -0
  54. package/dist/packages/canvas-adapter/plotItems.d.ts +32 -0
  55. package/dist/packages/canvas-adapter/plotItems.js +1 -0
  56. package/dist/packages/canvas-adapter/plotModal.d.ts +30 -0
  57. package/dist/packages/canvas-adapter/plotModal.js +1 -0
  58. package/dist/packages/canvas-adapter/plotStore.d.ts +52 -0
  59. package/dist/packages/canvas-adapter/plotStore.js +1 -0
  60. package/dist/packages/canvas-adapter/plotTab.d.ts +33 -0
  61. package/dist/packages/canvas-adapter/plotTab.js +1 -0
  62. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +11 -2
  63. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  64. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +29 -2
  65. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  66. package/dist/packages/canvas-adapter/summaryPanel.d.ts +34 -10
  67. package/dist/packages/canvas-adapter/summaryPanel.js +2 -4
  68. package/dist/packages/canvas-adapter/summaryRail.d.ts +7 -0
  69. package/dist/packages/canvas-adapter/summaryRail.js +1 -0
  70. package/dist/packages/canvas-adapter/sweepEditor.d.ts +17 -0
  71. package/dist/packages/canvas-adapter/sweepEditor.js +1 -0
  72. package/dist/packages/canvas-adapter/tableExport.d.ts +22 -0
  73. package/dist/packages/canvas-adapter/tableExport.js +3 -0
  74. package/dist/packages/canvas-adapter/toolbar.d.ts +25 -97
  75. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  76. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  77. package/dist/packages/canvas-adapter/userGuideHtml.js +354 -45
  78. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  79. package/dist/packages/canvas-adapter/version.js +1 -1
  80. package/dist/packages/canvas-adapter/viewSwitch.d.ts +13 -0
  81. package/dist/packages/canvas-adapter/viewSwitch.js +1 -0
  82. package/dist/packages/canvas-adapter/virtualTable.d.ts +44 -0
  83. package/dist/packages/canvas-adapter/virtualTable.js +1 -0
  84. package/dist/packages/core/classify.d.ts +3 -2
  85. package/dist/packages/core/classify.js +1 -1
  86. package/dist/packages/core/index.d.ts +1 -1
  87. package/dist/packages/core/index.js +1 -1
  88. package/dist/packages/core/passBins.d.ts +17 -4
  89. package/dist/packages/core/passBins.js +1 -1
  90. package/dist/packages/core/reticle.d.ts +20 -0
  91. package/dist/packages/core/reticle.js +1 -1
  92. package/dist/packages/core/ringCount.d.ts +22 -0
  93. package/dist/packages/core/ringCount.js +1 -0
  94. package/dist/packages/core/tableCsv.d.ts +43 -0
  95. package/dist/packages/core/tableCsv.js +3 -0
  96. package/dist/packages/core/wafer.d.ts +15 -0
  97. package/dist/packages/core/wafer.js +1 -1
  98. package/dist/packages/renderer/binColors.d.ts +6 -6
  99. package/dist/packages/renderer/binColors.js +1 -1
  100. package/dist/packages/renderer/buildView.d.ts +1 -1
  101. package/dist/packages/renderer/buildView.js +1 -1
  102. package/dist/packages/renderer/buildWaferMap.js +1 -1
  103. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  104. package/dist/packages/renderer/derivedTests/evaluate.d.ts +3 -1
  105. package/dist/packages/renderer/derivedTests/evaluate.js +1 -1
  106. package/dist/packages/renderer/derivedTests/parser.d.ts +7 -0
  107. package/dist/packages/renderer/derivedTests/parser.js +2 -2
  108. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  109. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  110. package/dist/packages/stats/binPareto.d.ts +1 -1
  111. package/dist/packages/stats/binPareto.js +1 -1
  112. package/dist/packages/stats/dieRegions.d.ts +42 -0
  113. package/dist/packages/stats/dieRegions.js +1 -0
  114. package/dist/packages/stats/facets.d.ts +8 -0
  115. package/dist/packages/stats/facets.js +1 -1
  116. package/dist/packages/stats/histogram.d.ts +27 -0
  117. package/dist/packages/stats/histogram.js +1 -1
  118. package/dist/packages/stats/index.d.ts +4 -1
  119. package/dist/packages/stats/index.js +1 -1
  120. package/dist/packages/stats/lotDrift.js +1 -1
  121. package/dist/packages/stats/lotPattern.js +1 -1
  122. package/dist/packages/stats/math.d.ts +9 -6
  123. package/dist/packages/stats/math.js +1 -1
  124. package/dist/packages/stats/metadataColumns.js +1 -1
  125. package/dist/packages/stats/patternClassification.d.ts +1 -1
  126. package/dist/packages/stats/patternClassification.js +1 -1
  127. package/dist/packages/stats/plotData.d.ts +258 -0
  128. package/dist/packages/stats/plotData.js +1 -0
  129. package/dist/packages/stats/plotId.d.ts +3 -0
  130. package/dist/packages/stats/plotId.js +1 -0
  131. package/dist/packages/stats/plotSpec.d.ts +119 -0
  132. package/dist/packages/stats/plotSpec.js +4 -0
  133. package/dist/packages/stats/presentation.d.ts +2 -0
  134. package/dist/packages/stats/presentation.js +1 -1
  135. package/dist/packages/stats/regions.d.ts +15 -0
  136. package/dist/packages/stats/regions.js +1 -1
  137. package/dist/packages/stats/renderSummaryReport.d.ts +8 -3
  138. package/dist/packages/stats/renderSummaryReport.js +15 -15
  139. package/dist/packages/stats/reportHtml.d.ts +1 -1
  140. package/dist/packages/stats/reportHtml.js +36 -29
  141. package/dist/packages/stats/scatter.d.ts +6 -0
  142. package/dist/packages/stats/scatter.js +1 -1
  143. package/dist/packages/stats/sweep.d.ts +37 -1
  144. package/dist/packages/stats/sweep.js +1 -1
  145. package/dist/packages/stats/sweepText.d.ts +14 -0
  146. package/dist/packages/stats/sweepText.js +1 -0
  147. package/dist/packages/stats/sweepXFromName.d.ts +14 -0
  148. package/dist/packages/stats/sweepXFromName.js +1 -1
  149. package/dist/packages/stats/synthesis.d.ts +14 -4
  150. package/dist/packages/stats/synthesis.js +1 -1
  151. package/dist/packages/stats/testPassRate.d.ts +6 -0
  152. package/dist/packages/stats/testPassRate.js +1 -1
  153. package/dist/packages/stats/trend.js +1 -1
  154. package/dist/packages/stats/types.d.ts +1 -1
  155. package/dist/packages/stats/yield.d.ts +15 -6
  156. package/dist/packages/stats/yield.js +1 -1
  157. package/llms.txt +15 -3
  158. package/package.json +3 -3
@@ -1,31 +1,37 @@
1
- import type { LotStatsSummary } from '../stats/types.js';
1
+ import type { Die } from '../core/dies.js';
2
+ import type { Wafer } from '../core/wafer.js';
3
+ import type { LotStatsSummary, StatsSummary } from '../stats/types.js';
4
+ import { type FacetCuration, type FacetItem } from '../stats/facets.js';
5
+ import { type TestDef } from '../renderer/buildWaferMap.js';
2
6
  import type { WaferMapDisplayItem } from './renderWaferGallery.js';
7
+ import { type PlotStore } from './plotStore.js';
8
+ import type { PlotSpec } from '../stats/plotSpec.js';
3
9
  import type { BinColors } from '../renderer/binColors.js';
4
10
  import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
5
- import { type SweepSpec } from '../stats/sweep.js';
6
- export type InsightsView = 'overview' | 'distributions' | 'correlation' | 'sweeps';
11
+ import type { SweepSpec } from '../stats/sweep.js';
12
+ export type InsightsView = 'overview' | 'distributions' | 'correlation' | 'sweeps' | 'data' | 'plot';
7
13
  /** Public option shape for `RenderOptions.insights`/`GalleryOptions.insights`. */
8
14
  export interface InsightsOptions {
9
15
  /**
10
- * Show an "Insights" tab in the toolbar. Selecting it replaces the canvas/
16
+ * Show an "Insights" tab in the toolbar and a Maps | Insights switch. Selecting it replaces the canvas/
11
17
  * grid with wmap's own chart suite across three sub-tabs — Overview
12
- * (yield, bins, ring/quadrant yield, test values), Distributions
18
+ * (yield, bins, ring/quadrant yield), Distributions
13
19
  * (process capability, boxplot, histogram), and Correlation (matrix +
14
- * scatter) — plus a fourth, Sweeps, when `sweeps` defines any. Default false.
20
+ * scatter) — a Data tab (the scope as tables: statistics, dies, wafers, with CSV
21
+ * export) and a Plot tab, where the reader's own plots and sweeps live. Default true with a toolbar
22
+ * (a gallery always has one); `false` opts out.
15
23
  */
16
24
  enabled?: boolean;
17
- /** Which sub-tab is shown first. Default 'overview'. `'sweeps'` with no
18
- * `sweeps` defined falls back to 'overview' — there is no such tab to open. */
25
+ /** Which sub-tab is shown first. Default 'overview'. `'sweeps'` opens the Plot tab, where sweeps are drawn. */
19
26
  defaultView?: InsightsView;
20
27
  /**
21
- * Parametric sweeps, one card each in their own Sweeps sub-tab — which appears
22
- * only when this is non-empty.
28
+ * @deprecated Sweeps are plots now: give them in `plots` as sweep plots, or read a sweeps file with
29
+ * `readPlotsFile`. Each entry here is still drawn, as a sweep plot on the Plot tab (and offered on selected dies),
30
+ * under the same `id`; a plot saved under that id takes precedence. The first use logs a notice.
23
31
  *
24
- * A sweep reads an ordered run of tests as a response curve rather than as
25
- * independent tests, and measures the PAIR: where the first two series cross,
26
- * and how far apart they are at given levels. The case it exists for is the
27
- * same quantity measured at a series of power levels, recorded as a block of
28
- * consecutive test numbers, swept up in one block and down in another.
32
+ * A sweep reads an ordered run of tests as a response curve rather than as independent tests, and measures the
33
+ * PAIR: where the first two series cross, and how far apart they are at given levels. It carries no population:
34
+ * the dies it aggregates are whatever the view is scoped to or the reader selected.
29
35
  *
30
36
  * ```ts
31
37
  * insights: { enabled: true, sweeps: [{
@@ -38,41 +44,32 @@ export interface InsightsOptions {
38
44
  * }] }
39
45
  * ```
40
46
  *
41
- * Deliberately carries no population scope of its own: a sweep definition
42
- * says which tests form the curve, and is therefore valid for any population
43
- * and portable between hosts. The dies it aggregates are whatever the
44
- * Insights view is currently scoped to.
45
- *
46
- * The same definitions drive drilldown: a user can select dies on a map and
47
- * right-click (or use the toolbar's "Chart the selection") to sweep just
48
- * those dies. A single map offers this even when `enabled` is off.
49
- *
50
- * **Provisional.** This arrived as one site's request. The mechanism — an
51
- * ordered run of tests read as a curve — is a recurring semiconductor shape
52
- * (shmoo, VDD/temperature sweeps, retention, endurance, IV), which is the case
53
- * for it being library-level; against it is that only one host has asked. It
54
- * is shipping so tsmap can put it in front of that user, and the answer
55
- * decides it: a second sweep-shaped use means it is general and stays, while
56
- * "also measure X, and split by Y" means it is a bespoke chart and belongs
57
- * behind a host-contributed-panel extension point instead. `separationAt` is
58
- * the narrowest part of the surface and the first thing to drop if it is not
59
- * used. Do not widen this shape before that question is settled.
60
- *
61
- * Range strings in `tests` (`"1010..1030"`) are NOT a widening in that sense:
62
- * they are input syntax for the same list of tests, and add nothing to what a
63
- * sweep measures. They were added because ranges are the first thing anyone
64
- * writing a sweep by hand asks for, and they share the derived-test parser so
65
- * the syntax is one syntax library-wide.
47
+ * Range strings in `tests` (`"1010..1030"`) share the derived-test parser, so the syntax is one syntax library-wide.
66
48
  */
67
49
  sweeps?: SweepSpec[];
68
50
  /**
69
- * Offers a "Remove" button on the Sweeps tab's notice about sweeps that name
70
- * none of the data's tests — typically sweeps a host kept from another test
71
- * program. Called with those sweeps' ids; the host drops them and re-renders
72
- * with the remaining `sweeps`. Without it the notice still shows, with no
73
- * button. The library never edits the host's sweep list itself.
51
+ * @deprecated With `sweeps`. Called with the id of a sweep from `sweeps` that the reader deletes on the Plot tab, so the
52
+ * host stops supplying it (otherwise the next render brings it back). Plots deleted from `plots` arrive through
53
+ * `onPlotsChange` like any other.
74
54
  */
75
55
  onRemoveSweeps?: (ids: string[]) => void;
56
+ /**
57
+ * The reader's saved plots: the recipes behind the **Plot** tab, in the order the reader keeps them. The
58
+ * library never stores anything itself: hand the list in here (from a file, `localStorage`, a server) and keep
59
+ * it current from `onPlotsChange`. A plot carries no population, so the same list works on any lot; one that
60
+ * needs a test the open lot lacks is kept and shown greyed with the reason, never dropped.
61
+ */
62
+ plots?: PlotSpec[];
63
+ /**
64
+ * Called with the whole list after the reader adds, edits, duplicates, deletes or imports a plot (a burst of
65
+ * typing is one call). Keep it, and pass it back as `plots` next time.
66
+ */
67
+ onPlotsChange?: (plots: PlotSpec[]) => void;
68
+ /**
69
+ * Choose a plots file to import, resolving to its text, or `null` when cancelled. Without it the Plot tab uses
70
+ * the browser's own file input; a desktop host passes its native dialog.
71
+ */
72
+ onPickPlotsFile?: () => Promise<string | null>;
76
73
  /**
77
74
  * Open the Insights view on mount instead of starting on the map/grid.
78
75
  * Default false — the tab is offered, the map is what you see first.
@@ -86,6 +83,8 @@ export interface InsightsOptions {
86
83
  defaultOpen?: boolean;
87
84
  }
88
85
  export interface InsightsTabDeps {
86
+ /** The host's own wafer attributes (`attributes` on the render options): what Group by offers and calls each, the plot fields, the Wafers table's columns and the strip. Over the defaults. */
87
+ attributes?: Record<string, FacetCuration>;
89
88
  /** Current gallery/single-wafer items — read fresh each render (a gallery's list can still be building). `null` entries (not-yet-built cards) are skipped. */
90
89
  getItems: () => Array<WaferMapDisplayItem | null>;
91
90
  /** Precomputed lot-level yield, when the host has one — reused directly instead of recomputing (see stats/yield.ts). Omit when there is no lot (e.g. a single wafer). */
@@ -97,7 +96,7 @@ export interface InsightsTabDeps {
97
96
  */
98
97
  getBinColors: () => BinColors;
99
98
  /** Read fresh each render — used by the Overview tab's ring/quadrant regional yield cards. Default 4. */
100
- getRingCount?: () => number;
99
+ getRingCount: () => number;
101
100
  onSaveImage?: SaveImageHandler;
102
101
  /** Optional host hook for the Overview tab's test-values "Export CSV" button — see `saveTextFile` (toolbar.ts). */
103
102
  onSaveText?: SaveTextHandler;
@@ -127,6 +126,11 @@ export interface InsightsTabDeps {
127
126
  * lands on this test), and only consulted for a leaf row of the sole item.
128
127
  */
129
128
  focusTest?: (testNumber: number) => void;
129
+ /**
130
+ * A die row clicked in a table (the Data tab, or a table opened from a chart): leave Insights and show
131
+ * that die on its map. Omit where there is no map to go back to; the rows are then not clickable.
132
+ */
133
+ locateDie?: (die: Die, waferIndex: number | undefined) => void;
130
134
  /** Default sub-tab shown on first render. Default 'overview'. */
131
135
  defaultView?: InsightsView;
132
136
  /** Sweep definitions to render in the Distributions view — see `InsightsOptions.sweeps`. */
@@ -134,15 +138,13 @@ export interface InsightsTabDeps {
134
138
  /** See `InsightsOptions.onRemoveSweeps`. */
135
139
  onRemoveSweeps?: (ids: string[]) => void;
136
140
  /**
137
- * When provided, the tab bar gets a leading "‹ Map"/"‹ Gallery" tab that
138
- * exits Insights back to the host's normal view — one visible navigation
139
- * model (a tab row) instead of relying on the host toolbar's icon-swap
140
- * toggle alone, whose "way back" is discoverable only via tooltip.
141
+ * The live list of saved plots, shared with the drilldown menu so a plot edited here is the one a right-click
142
+ * opens. Created from `plots`/`onPlotsChange` when omitted.
141
143
  */
142
- backTab?: {
143
- label: string;
144
- onBack: () => void;
145
- };
144
+ plotStore?: PlotStore;
145
+ plots?: PlotSpec[];
146
+ onPlotsChange?: (plots: PlotSpec[]) => void;
147
+ onPickPlotsFile?: () => Promise<string | null>;
146
148
  /** Opens the user guide. Rendered as an icon at the end of the tab row —
147
149
  * while Insights is showing, the map toolbar is hidden (it held only a
148
150
  * back-to-gallery button, which the back tab already provides, and this
@@ -184,5 +186,24 @@ export interface InsightsTabHandle {
184
186
  /** Tears down every live panel's observers and removes `el`. */
185
187
  destroy: () => void;
186
188
  }
189
+ type Item = FacetItem & {
190
+ dies: Die[];
191
+ label: string;
192
+ waferIndex: number;
193
+ wafer: Wafer;
194
+ statsSummary?: StatsSummary;
195
+ /** This wafer's OWN pass bins — a lot can mix wafers built with different ones. */
196
+ passBins: readonly number[];
197
+ /** This wafer's OWN test defs, carried through so a scoped population can be
198
+ * reconciled (`mergeTestDefs`) over just the wafers in scope. */
199
+ testDefs?: TestDef[];
200
+ /** The wafer's real identity (`waferIdentityLabel`) — never the positional
201
+ * "Wafer N (no ID)" that `label` falls back to, which in a chart title would
202
+ * read as an ID. */
203
+ identity?: string;
204
+ };
205
+ /** One wafer (or the lot's single stand-in) as the Insights views see it. */
206
+ export type InsightsItem = Item;
187
207
  export declare function createInsightsTab(deps: InsightsTabDeps): InsightsTabHandle;
208
+ export {};
188
209
  //# sourceMappingURL=insightsTab.d.ts.map
@@ -1 +1 @@
1
- import{MEAN_WAFER_YIELD_LABEL as He}from"../stats/presentation.js";import{buildFacetTable as Fe,facetValueOf as Ne,FACET_NONE_VALUE as _e}from"../stats/facets.js";import{mergeTestDefs as de}from"../stats/mergeTestDefs.js";import{isParametricTest as Ve}from"../renderer/buildWaferMap.js";import{waferDisplayLabel as ze,waferIdentityLabel as Ue}from"../core/waferLabel.js";import{hasDrilldownTargets as ce,waferPopulation as qe}from"./chartPopulation.js";import{openDrilldownMenu as Qe}from"./drilldown.js";import{INPUT_DEFAULT_PASS_BINS as M,itemPassBins as Ke,passBinsLabel as pe}from"../core/passBins.js";import{NO_DATA_FILL as ue}from"../renderer/colorMap.js";import{describeWaferPopulation as Xe,populationStat as Je}from"../stats/population.js";import{LEADING as fe,ALPHA as Ze,SPACE as w,EDGE_GUTTER as te,FONT as O,CLR as k,RADIUS as me,SHADOW as et,controlStyle as be,wireControlHover as ne,wireTooltip as tt}from"./toolbar.js";import{ICONS as nt}from"./icons.js";import{renderCapabilityPanel as ot}from"./charts/capability.js";import{renderBoxplotPanel as at}from"./charts/boxplot.js";import{renderTrendPanel as st}from"./charts/trend.js";import{renderSweepPanel as rt}from"./charts/sweep.js";import{sweepAppliesTo as it}from"../stats/sweep.js";import{renderHistogramPanel as lt}from"./charts/histogram.js";import{renderCorrelationPanel as dt}from"./charts/correlation.js";import{renderScatterPanel as ct}from"./charts/scatter.js";import{renderBarPanel as ge}from"./charts/barPanel.js";import{renderBinClusterPanel as pt}from"./charts/binCluster.js";import{renderTestPassRatePanel as ut}from"./charts/testPassRate.js";import{QUANTITY as ft}from"./charts/palette.js";import{cardFrameStyle as mt,makeChartGridWrap as V,makeLabeledSelect as bt,makeLinkedGroupSelect as gt}from"./charts/chartShell.js";import{buildYieldData as z,buildYieldDataCombined as he}from"../stats/yield.js";import{buildBinParetoData as ht}from"../stats/binPareto.js";import{buildLotTestSectionSteps as yt,buildLotFunctionalSection as wt,buildMetadataStripBox as Ct}from"./summaryPanel.js";import{runChunked as xt}from"./chunked.js";import{buildRegionYieldData as ye,buildRingRegions as St,buildQuadrantRegions as vt}from"../stats/regions.js";import{renderRegionYieldDiagram as we}from"./charts/regionYieldDiagram.js";const Ce=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Tt={key:"sweeps",label:"Sweeps"};export function createInsightsTab(x){const{getItems:xe,getLotStats:Se,getBinColors:oe,getRingCount:ve,onSaveImage:T,onSaveText:U,openWafer:F,focusTest:ae}=x,Te=x.showMetadataStrip??!0,Y=x.contentInset??te,p=x.ownerDocument??document,R=p.createElement("div");Object.assign(R.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const ke=te,W=p.createElement("div");Object.assign(W.style,{paddingLeft:ke});const $=p.createElement("div");Object.assign($.style,{display:"flex",gap:w.xs,alignItems:"center",background:k.menuBg,border:`1px solid ${k.menuBorder}`,borderRadius:me.container,boxShadow:et.panel,padding:`0 ${w.lg}`,marginBottom:w.lg,marginLeft:Y,marginRight:Y}),$.setAttribute("role","tablist"),$.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from($.querySelectorAll('[role="tab"]')),o=t.indexOf(p.activeElement);if(o===-1)return;e.preventDefault();const s=t[(o+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];s.focus(),s.click()});const G=p.createElement("div");Object.assign(G.style,{display:"flex",flexDirection:"column",gap:w.lg,marginTop:"0",paddingLeft:Y,paddingRight:Y}),R.appendChild(W),R.appendChild($),R.appendChild(G);const se=(x.sweeps?.length??0)>0,De=se?[...Ce,Tt]:Ce;let P=x.defaultView==="sweeps"&&!se?"overview":x.defaultView??"overview",j,E=null,L=null,H={includeLimits:void 0,clipOutliers:!1,limits:"both"};const q=new Map,re=(e,t)=>{H=e;for(const o of q.values())for(const s of o)s!==t&&s.setAxisPrefs(e)},Q=e=>{L!==e&&(L=e,_())};let N=new Map;function ie(){for(const e of N.values())e.destroy();N=new Map}function K(e,t,o){F?.(e,t,o)}function X(e){if(e.some(t=>ce(t.testDefs,x.sweeps)))return(t,o,s)=>{const r=e.find(u=>u.waferIndex===t);if(!r||!ce(r.testDefs,x.sweeps))return;s.preventDefault();const i=qe(r.dies,{waferLabel:r.identity,testDefs:r.testDefs,activeTest:o??E??void 0,waferIndex:t});Qe({x:s.clientX,y:s.clientY},s.target,i,{sweeps:x.sweeps,onSaveImage:T})}}function Be(e){return F?{open:(t,o)=>K(t,`Wafer ${e.find(s=>s.waferIndex===t)?.label??t}`,o)}:ae&&e.length===1?{open:(t,o)=>ae(o),label:"show this test on the map"}:null}function $e(){return xe().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:ze(e,t),identity:Ue(e),waferIndex:t,passBins:Ke(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function le(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${k.iconActive}`:"2px solid transparent",color:t?k.iconActive:k.label,fontWeight:t?"700":"500",fontSize:O.body,padding:`${w.sm} ${te} ${w.md}`,cursor:"pointer",marginBottom:"-1px"})}function Ee(e,t){const o=p.createElement("button");o.type="button",o.textContent=t;const s=e===P;return le(o,s),o.dataset.on=s?"true":"false",ne(o,"bare"),o.dataset.wmapInsightsTab=e,o.setAttribute("role","tab"),o.setAttribute("aria-selected",s?"true":"false"),o.tabIndex=s?0:-1,o.addEventListener("click",()=>{P!==e&&(P=e,_({keepSections:!0}))}),o}function Le(e){const t=p.createElement("button");return t.type="button",t.textContent=`\u2039 ${e.label}`,le(t,!1),t.dataset.wmapInsightsBack="1",t.addEventListener("click",e.onBack),t}function Pe(e,t,o,s=!0){const r=V(p),i=oe();let u="label";const f=o??"group",g=pe(e.map(d=>d.passBins)),c=Se?.(),m=new Map(c?.lotYieldSeries.map(d=>[d.waferIndex,d.yieldPercent])),h=d=>({...d,label:d.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(d.waferIndex),key:d.waferIndex}),b=e.map(h),y=t?.map(d=>({key:d.key,items:d.items.map(h)})),S=()=>y?he(y,M,u):z(b,M,u),a={title:t?`Yield by ${f} (pass: ${g})`:`Yield by wafer (pass: ${g})`,data:S(),selfControl:{current:u,options:[["yield","Sort: yield"],["label",t?`Sort: ${f}`:"Sort: wafer ID"]],onChange:d=>(u=d,{data:S()})},barColor:()=>ft,valueLabel:d=>`${d.percent.toFixed(1)}%`,reference:d=>{if(d.length<3)return null;const D=d.map(ee=>ee.percent).sort((ee,Ge)=>ee-Ge),A=D.length%2?D[(D.length-1)/2]:(D[D.length/2-1]+D[D.length/2])/2;return{value:A,label:`median ${A.toFixed(1)}%`}},drill:y?{onOpenGroup:d=>{const D=y.find(A=>A.key===d.label)?.items??[];return{data:z(D,M,u),title:`Yield by wafer \u2014 ${f}: ${d.label} (pass: ${g})`}},onBack:()=>({data:S(),title:`Yield by ${f} (pass: ${g})`}),groupLabelText:f}:void 0,onOpen:F?d=>{typeof d.key=="number"&&K(d.key,`Wafer ${d.label}`)}:void 0,onWaferContextMenu:X(e),ownerDocument:p};let n=null;if(s&&(n=ge(a,T),n.card.style.minHeight="360px",r.appendChild(n.card)),t){const d=pt({title:"Hard bin pareto",groups:t.map(D=>({key:D.key,items:D.items.map(A=>({dies:A.dies,hardBinCounts:A.statsSummary?.stats.hardBinCounts,softBinCounts:A.statsSummary?.stats.softBinCounts}))})),onSaveImage:T,ownerDocument:p});return d.card.style.minHeight="360px",r.appendChild(d.card),{card:r,destroy:()=>{n?.destroy(),d.destroy()}}}let v="hbin";const l=d=>d===void 0?ue:(v==="hbin"?i.hard:i.soft).get(d)??ue,C=e.map(d=>({dies:d.dies,hardBinCounts:d.statsSummary?.stats.hardBinCounts,softBinCounts:d.statsSummary?.stats.softBinCounts})),I=()=>ht(C,v),B={title:"Hard bin pareto",data:I(),selfControl:{current:v,options:[["hbin","Hard bins"],["sbin","Soft bins"]],onChange:d=>(v=d,{data:I(),title:`${v==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:d=>l(d.binCode),ownerDocument:p},Z=ge(B,T);return Z.card.style.minHeight="360px",r.appendChild(Z.card),{card:r,destroy:()=>{n?.destroy(),Z.destroy()}}}function J(){const e=p.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...mt(),display:"flex",flexDirection:"column",gap:w.lg,minWidth:"0"}),e}function Ae(e){if(W.innerHTML="",W.style.marginBottom="0",!Te)return;const t=Ct(e.map(o=>({metadata:o.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",W.appendChild(t),W.style.marginBottom=w.xs)}function Ie(e,t,o,s){if(!e.length)return{elements:[],testValuesCard:null,functionalCard:null,destroy:()=>{}};const r=e.map(l=>l.wafer),i=e.map(l=>l.dies),u=e.flatMap(l=>l.dies),f=e.map(l=>l.statsSummary),g=f.every(l=>l!==void 0)?f:void 0,c=ve?.()??4,m=[],h=[],y=ut({groups:(s??[{key:"",items:e}]).map(l=>({key:l.key,items:l.items.map(C=>({dies:C.dies,testSpecYield:C.statsSummary?.stats.testSpecYield,functionalYield:C.statsSummary?.stats.functionalYield}))})),testDefs:o,onSaveImage:T,ownerDocument:p});y.card.style.minHeight="300px",m.push(y.card),h.push(y.destroy);const S=ye(i,r,c,l=>e[l].passBins,St);if(S.length){const l=we({title:"Ring yield",mode:"ring",rows:S,onSaveImage:T,ownerDocument:p});m.push(l.card),h.push(l.destroy)}const a=ye(i,r,c,l=>e[l].passBins,vt);if(a.length){const l=we({title:"Quadrant yield",mode:"quadrant",rows:a,onSaveImage:T,ownerDocument:p});m.push(l.card),h.push(l.destroy)}let n=null;if(t.length){const l=J();let C=null;const I=xt(yt(u,t,void 0,g,U,i.map(B=>({dies:B})),void 0,"full"),{onDone:B=>{C=B,l.removeAttribute("aria-busy"),B?l.replaceChildren(B):l.remove()}});if(I.done)C&&(n=l);else{const B=p.createElement("div");B.textContent="Computing test statistics\u2026",Object.assign(B.style,{color:k.label,fontSize:O.body}),l.setAttribute("aria-busy","true"),l.appendChild(B),n=l,h.push(()=>I.cancel())}}let v=null;if(o.length){const l=wt(u,o,g,U);if(l){const C=J();C.appendChild(l),v=C}}return{elements:m,testValuesCard:n,functionalCard:v,destroy:()=>{for(const l of h)l()}}}function Oe(e){const t=pe(e.map(c=>c.passBins)),o=e.length===1,s=e[0],r=J();Object.assign(r.style,{flexDirection:"row",flexWrap:"wrap",gap:w.md});const i=c=>{const m=c.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),c};function u(c,m,h){const b=p.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:w.sm,paddingRight:w.xxl,marginRight:w.md,borderRight:`1px solid ${k.menuBorder}`});const y=p.createElement("div");y.textContent=c,Object.assign(y.style,{fontSize:O.heading,fontWeight:"700",color:k.value,lineHeight:fe.tight});const S=p.createElement("div");if(S.textContent=m,Object.assign(S.style,{fontSize:O.body,color:k.label}),b.append(y,S),h){const a=p.createElement("div");a.textContent=h,Object.assign(a.style,{fontSize:O.meta,color:k.label,opacity:Ze.muted}),b.appendChild(a)}return b}if(o){const c=z([{...s,key:s.waferIndex}],M)[0]?.percent;return c!==void 0&&r.appendChild(u(`${c.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),r.appendChild(u(String(s.dies.length),"Total dies")),i(r)}r.appendChild(u(String(e.length),"Wafers"));const f=z(e.map(c=>({...c,key:c.waferIndex})),M).map(c=>c.percent).filter(c=>Number.isFinite(c));if(f.length){const c=f.reduce((b,y)=>b+y,0)/f.length,m=he([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}],M)[0]?.percent,h=m!==void 0&&m.toFixed(1)!==c.toFixed(1);r.appendChild(u(`${c.toFixed(1)}%`,`${He} \xB7 pass: ${t}`,h?`${m.toFixed(1)}% by dies`:void 0))}const g=e.map(c=>c.statsSummary);if(g.every(c=>c!==void 0)){const c=g.reduce((h,b)=>h+b.stats.analyzedDies,0),m=g.reduce((h,b)=>h+b.stats.excludedDies,0);r.appendChild(u(c.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else r.appendChild(u(e.reduce((c,m)=>c+m.dies.length,0).toLocaleString(),"Total dies"));return i(r)}function Re(e,t,o,s,r){const i=p.createElement("div");Object.assign(i.style,{display:"flex",flexDirection:"column",gap:w.lg});const u=e.length===1&&!s;e.length&&!s&&i.appendChild(Oe(e));const f=Pe(e,s,r,!u);i.appendChild(f.card);const g=Ie(e,t,o,s);for(const c of g.elements)f.card.appendChild(c);return g.testValuesCard&&i.appendChild(g.testValuesCard),g.functionalCard&&i.appendChild(g.functionalCard),{card:i,destroy:()=>{f.destroy(),g.destroy()}}}function We(e,t,o,s){const r=V(p),i=Be(e),u=a=>n=>re(n,a()),f=a=>({...a,testStats:a.statsSummary?.stats.perTestStats}),g=e.map(f),c=o?.map(a=>({key:a.key,items:a.items.map(f)})),m=at({title:"Test value distribution",axisPrefs:H,onAxisPrefsChange:u(()=>m),onTestChange:a=>y(a),selectedTestNumber:E??void 0,items:g,testDefs:t,groups:c,groupLabelText:s,onSaveImage:T,onGroupChange:a=>Q(a),onOpen:i?.open,openActionLabel:i?.label,onWaferContextMenu:X(e),ownerDocument:p}),h=lt({title:"Value histogram",axisPrefs:H,onAxisPrefsChange:u(()=>h),onTestChange:a=>y(a),selectedTestNumber:E??void 0,items:e,testDefs:t,groups:o,onGroupChange:a=>Q(a),onSaveImage:T,ownerDocument:p}),b=st({title:"Wafer-to-wafer trend",axisPrefs:H,onAxisPrefsChange:u(()=>b),onTestChange:a=>y(a),selectedTestNumber:E??void 0,items:e.map(a=>({label:a.label,key:a.waferIndex,dies:a.dies,testStats:a.statsSummary?.stats.perTestStats})),testDefs:t,onSaveImage:T,centreLabel:Je(Xe(e.map(a=>a.wafer.metadata)),"mean"),onOpen:F?(a,n)=>K(a,`Wafer ${e.find(v=>v.waferIndex===a)?.label??a}`,n):void 0,onWaferContextMenu:X(e),ownerDocument:p}),y=a=>{E=a,m.setTest(a),h.setTest(a),b.setTest(a),S.setTest(a)};q.set("distribution",[m,h,b]);const S=ot({title:"Process capability",items:e,testDefs:t,onSaveImage:T,selectedTestNumber:E??void 0,onSelectTest:a=>y(a),ownerDocument:p});return r.append(S.card,m.card,h.card,b.card),{card:r,destroy:()=>{S.destroy(),m.destroy(),h.destroy(),b.destroy()}}}function je(e){const t=V(p),o=de(e).defs,s=e.flatMap(f=>f.dies),r=x.sweeps??[],i=r.filter(f=>!it(f,o));i.length>0&&t.appendChild(Me(i,r.length));const u=r.map(f=>rt({spec:f,dies:s,testDefs:o,onSaveImage:T,ownerDocument:p}));for(const f of u)t.appendChild(f.card);return{card:t,destroy:()=>{for(const f of u)f.destroy()}}}function Me(e,t){const o=p.createElement("div");o.setAttribute("role","status"),Object.assign(o.style,{gridColumn:"1 / -1",display:"flex",flexWrap:"wrap",alignItems:"center",gap:w.md,padding:`${w.sm} ${w.md}`,background:k.warnBg,border:`1px solid ${k.warnBorder}`,borderRadius:me.container,color:k.warnText,fontSize:O.body,lineHeight:fe.base});const s=e.length,r=p.createElement("span");if(r.style.flex="1 1 24ch",r.textContent=(s===t?s===1?"This sweep names no test in this data":"None of these sweeps names a test in this data":`${s} of ${t} sweeps name no test in this data: ${e.map(i=>i.title).join(", ")}`)+` \u2014 ${s===1?"it":"they"} may belong to another test program.`,o.appendChild(r),x.onRemoveSweeps){const i=p.createElement("button");i.type="button",Object.assign(i.style,be("outlined")),i.textContent=s===1?"Remove this sweep":`Remove these ${s} sweeps`,ne(i);const u=e.map(f=>f.id);i.addEventListener("click",()=>x.onRemoveSweeps(u)),o.appendChild(i)}return o}function Ye(e,t,o){const s=V(p),r=ct({title:"Test scatter",items:e,testDefs:t,groups:o,binColors:oe().hard,onSaveImage:T,axisPrefs:H,onAxisPrefsChange:u=>re(u,r),ownerDocument:p});q.set("correlation",[r]);const i=dt({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:T,onSaveText:U,onSelectPair:(u,f)=>r.setXY(u,f),ownerDocument:p});return s.append(i.card,r.card),{card:s,destroy:()=>{i.destroy(),r.destroy()}}}function _(e){e?.keepSections||ie(),G.innerHTML="",$.innerHTML="",x.backTab&&$.appendChild(Le(x.backTab));for(const n of De)$.appendChild(Ee(n.key,n.label));const t=$e();Ae(t);const o=Fe(t,{facetableOnly:!0}).filter(n=>n.splittable),s=p.createElement("div");Object.assign(s.style,{display:"flex",gap:w.md,alignItems:"center",marginLeft:w.xxl,paddingBottom:w.xs});let r;o.length>0?(s.appendChild(bt("Group by:",[{value:"",label:"None"},...o.map(n=>({value:n.key,label:`${n.label} (${n.values.length})`}))],j??"",n=>{j=n||void 0,L=null,_()},{hook:"group-by",ownerDocument:p})),r=o.find(n=>n.key===j)?.label):j=void 0;let i;if(j){const n=new Map,v=[];for(const l of t){const C=Ne(l.metadata,j)??_e;n.has(C)||(n.set(C,[]),v.push(C)),n.get(C).push(l)}i=v.map(l=>({key:l,items:n.get(l)}))}L!==null&&!i?.some(n=>n.key===L)&&(L=null),i&&i.length>0&&s.appendChild(gt(i.map(n=>n.key),"Show:",L,n=>Q(n),{ownerDocument:p}).el);let u=null;if(x.onOpenGuide){const n=p.createElement("button");n.type="button",n.innerHTML=nt.help,n.setAttribute("aria-label","User guide"),Object.assign(n.style,{...be("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),ne(n,"bare"),tt(n,"User guide"),n.addEventListener("click",()=>x.onOpenGuide()),Object.assign(n.style,{marginLeft:"auto"}),u=n}$.appendChild(s),u&&$.appendChild(u);const f=L!==null?i?.find(n=>n.key===L):void 0,g=f?.items??t,c=f?void 0:i,m=de(g),h=m.defs,b=h.filter(Ve);E!==null&&!b.some(n=>n.testNumber===E)&&(E=null);const y=e?.keepSections?N.get(P):void 0,S=y??(P==="overview"?Re(g,b,h,c,r):P==="distributions"?We(g,b,c,r):P==="sweeps"?je(g):Ye(g,b,c));y||N.set(P,S);const a=m.conflicts.filter(n=>n.excluded);if(a.length>0){const n=p.createElement("div");Object.assign(n.style,{color:k.label,fontSize:O.body,padding:`0 ${Y} ${w.sm}`});const v=a.slice(0,6).map(I=>I.testNumber).join(", "),l=a.length>6?`, and ${a.length-6} more`:"",C=a.length===1?"it":"them";n.textContent=`${a.length} test ${a.length===1?"number is":"numbers are"} hidden (${v}${l}) \u2014 the wafers in view describe ${C} differently, so their values cannot be pooled. `+(i&&i.length>0?`Pick one ${r??"group"} under "Show:" to analyse ${C}.`:"Load one test program at a time to analyse them."),n.dataset.wmapWithheldTests=String(a.length),G.appendChild(n)}G.appendChild(S.card)}return{el:R,render:_,destroy:()=>{ie(),R.remove()}}}
1
+ import{MEAN_WAFER_YIELD_LABEL as qe}from"../stats/presentation.js";import{buildFacetTable as Ke,facetValueOf as Qe,FACET_NONE_VALUE as Xe,DEFAULT_FACET_CURATION as Je}from"../stats/facets.js";import{mergeTestDefs as Se}from"../stats/mergeTestDefs.js";import{isParametricTest as xe}from"../renderer/buildWaferMap.js";import{dieFailsTest as Ze}from"../stats/testPassRate.js";import{fmt as ke}from"../renderer/fmt.js";import{testLabel as et}from"../renderer/testLabel.js";import{waferDisplayLabel as tt,waferIdentityLabel as nt}from"../core/waferLabel.js";import{waferPopulation as ot}from"./chartPopulation.js";import{openDrilldownMenu as se}from"./drilldown.js";import{plotStoreFor as it}from"./plotStore.js";import{itemPassBins as rt,passBinsLabel as Te}from"../core/passBins.js";import{NO_DATA_FILL as ve}from"../renderer/colorMap.js";import{describeWaferPopulation as at,populationStat as st}from"../stats/population.js";import{LEADING as lt,ALPHA as dt,SPACE as T,EDGE_GUTTER as le,FONT as F,CLR as $,RADIUS as ct,SHADOW as ut,controlStyle as pt,wireControlHover as de,wireTooltip as ft}from"./toolbar.js";import{ICONS as mt}from"./icons.js";import{renderCapabilityPanel as bt}from"./charts/capability.js";import{renderBoxplotPanel as ht}from"./charts/boxplot.js";import{renderTrendPanel as gt}from"./charts/trend.js";import{renderHistogramPanel as yt}from"./charts/histogram.js";import{renderCorrelationPanel as wt}from"./charts/correlation.js";import{renderScatterPanel as Ct}from"./charts/scatter.js";import{renderBarPanel as De}from"./charts/barPanel.js";import{renderBinClusterPanel as St}from"./charts/binCluster.js";import{renderTestPassRatePanel as xt}from"./charts/testPassRate.js";import{QUANTITY as kt}from"./charts/palette.js";import{cardFrameStyle as Tt,makeChartGridWrap as ce,makeLabeledSelect as vt,makeLinkedGroupSelect as Dt}from"./charts/chartShell.js";import{buildYieldData as J,buildYieldDataCombined as Be}from"../stats/yield.js";import{buildBinParetoData as Bt}from"../stats/binPareto.js";import{buildLotTestSectionSteps as $t,buildLotFunctionalSection as Lt,buildMetadataStripBox as It}from"./summaryPanel.js";import{runChunked as Et}from"./chunked.js";import{buildRegionYieldData as ue,buildRingRegions as $e,buildQuadrantRegions as Le,buildReticlePositionRegions as Pt,diesInRegion as At}from"../stats/regions.js";import{renderDataSection as Ot}from"./dataTab.js";import{sourceFromDies as Rt}from"./plotItems.js";import{renderRegionYieldDiagram as pe}from"./charts/regionYieldDiagram.js";const Wt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}],Mt={key:"data",label:"Data"},Ft={key:"plot",label:"Plot"};export function createInsightsTab(v){const{getItems:Ie,getLotStats:fe,getBinColors:me,getRingCount:N,onSaveImage:k,onSaveText:O,openWafer:R,focusTest:Z,locateDie:V}=v,be={...Je,...v.attributes},Ee=v.showMetadataStrip??!0,z=v.contentInset??le,f=v.ownerDocument??document,Y=f.createElement("div");Object.assign(Y.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const Pe=le,j=f.createElement("div");Object.assign(j.style,{paddingLeft:Pe});const E=f.createElement("div");Object.assign(E.style,{display:"flex",gap:T.xs,alignItems:"center",background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:ct.container,boxShadow:ut.panel,padding:`0 ${T.lg}`,marginBottom:T.lg,marginLeft:z,marginRight:z}),E.setAttribute("role","tablist"),E.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(E.querySelectorAll('[role="tab"]')),r=n.indexOf(f.activeElement);if(r===-1)return;e.preventDefault();const l=n[(r+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];l.focus(),l.click()});const U=f.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"column",gap:T.lg,marginTop:"0",paddingLeft:z,paddingRight:z}),Y.appendChild(j),Y.appendChild(E),Y.appendChild(U);const Ae=[...Wt,Mt,Ft],q=v.plotStore??it(v);let L=v.defaultView==="sweeps"?"plot":v.defaultView??"overview",M,he="statistics",ge="wide",P=null,A=null,K={includeLimits:void 0,clipOutliers:!1,limits:"both"};const ee=new Map,ye=(e,n)=>{K=e;for(const r of ee.values())for(const l of r)l!==n&&l.setAxisPrefs(e)},te=e=>{A!==e&&(A=e,H())};let G=new Map;function we(){for(const e of G.values())e.destroy();G=new Map}function ne(e,n,r){R?.(e,n,r)}function oe(e){return(n,r,l)=>{const i=e.find(c=>c.waferIndex===n);if(!i)return;l.preventDefault();const u=ot(i.dies,{waferLabel:i.identity,testDefs:i.testDefs,activeTest:r??P??void 0,waferIndex:n,wafer:i.wafer,passBins:i.passBins,ringCount:N()});se({x:l.clientX,y:l.clientY},l.target,u,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}}function Q(e,n,r,l,i){Ce({x:e.clientX,y:e.clientY},e.target,n,r,l,i)}function Ce(e,n,r,l,i,u){const c=Rt(r.map(s=>({label:s.identity??s.label,dies:s.dies,waferIndex:s.waferIndex,wafer:s.wafer,passBins:s.passBins,ringCount:N()})),l,i,Se(r).defs,u);c&&se(e,n,c,{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})}function ie(e){return R?{open:(n,r)=>ne(n,`Wafer ${e.find(l=>l.waferIndex===n)?.label??n}`,r)}:Z&&e.length===1?{open:(n,r)=>Z(r),label:"show this test on the map"}:null}function Oe(){return Ie().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:tt(e,n),identity:nt(e),waferIndex:n,passBins:rt(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function Re(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${$.iconActive}`:"2px solid transparent",color:n?$.iconActive:$.label,fontWeight:n?"700":"500",fontSize:F.body,padding:`${T.sm} ${le} ${T.md}`,cursor:"pointer",marginBottom:"-1px"})}function We(e,n){const r=f.createElement("button");r.type="button",r.textContent=n;const l=e===L;return Re(r,l),r.dataset.on=l?"true":"false",de(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",l?"true":"false"),r.tabIndex=l?0:-1,r.addEventListener("click",()=>{L!==e&&(L=e,H({keepSections:!0}))}),r}function Me(e,n,r,l=!0){const i=ce(f),u=me();let c="label";const s=r??"group",h=Te(e.map(p=>p.passBins)),d=fe?.(),m=new Map(d?.lotYieldSeries.map(p=>[p.waferIndex,p.yieldPercent])),a=p=>({...p,label:p.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:m.get(p.waferIndex),key:p.waferIndex}),b=e.map(a),y=n?.map(p=>({key:p.key,items:p.items.map(a)})),w=()=>y?Be(y,c):J(b,c),t={title:n?`Yield by ${s} (pass: ${h})`:`Yield by wafer (pass: ${h})`,data:w(),selfControl:{current:c,options:[["yield","Sort: yield"],["label",n?`Sort: ${s}`:"Sort: wafer ID"]],onChange:p=>(c=p,{data:w()})},barColor:()=>kt,valueLabel:p=>`${p.percent.toFixed(1)}%`,reference:p=>{if(p.length<3)return null;const S=p.map(I=>I.percent).sort((I,_)=>I-_),B=S.length%2?S[(S.length-1)/2]:(S[S.length/2-1]+S[S.length/2])/2;return{value:B,label:`median ${B.toFixed(1)}%`}},drill:y?{onOpenGroup:p=>{const S=y.find(B=>B.key===p.label)?.items??[];return{data:J(S,c),title:`Yield by wafer \u2014 ${s}: ${p.label} (pass: ${h})`}},onBack:()=>({data:w(),title:`Yield by ${s} (pass: ${h})`}),groupLabelText:s}:void 0,onOpen:R?p=>{typeof p.key=="number"&&ne(p.key,`Wafer ${p.label}`)}:void 0,onWaferContextMenu:oe(e),ownerDocument:f};let o=null;if(l&&(o=De(t,k),o.card.style.minHeight="360px",i.appendChild(o.card)),n){const p=St({title:"Hard bin pareto",groups:n.map(S=>({key:S.key,items:S.items.map(B=>({dies:B.dies,hardBinCounts:B.statsSummary?.stats.hardBinCounts,softBinCounts:B.statsSummary?.stats.softBinCounts}))})),onSelectBin:(S,B)=>{const I=n.find(X=>X.key===S.groupKey);if(!I)return;const _=S.binType==="hbin"?"hard":"soft";Q(B,I.items,`in ${_} bin ${S.bin} of ${S.groupKey}`,X=>(S.binType==="hbin"?X.hbin:X.sbin)===S.bin)},onSaveImage:k,ownerDocument:f});return p.card.style.minHeight="360px",i.appendChild(p.card),{card:i,destroy:()=>{o?.destroy(),p.destroy()}}}let g="hbin";const C=p=>p===void 0?ve:(g==="hbin"?u.hard:u.soft).get(p)??ve,x=e.map(p=>({dies:p.dies,hardBinCounts:p.statsSummary?.stats.hardBinCounts,softBinCounts:p.statsSummary?.stats.softBinCounts})),W=()=>Bt(x,g),ae={title:"Hard bin pareto",data:W(),selfControl:{current:g,options:[["hbin","Hard bins","The physical sort result: where the part goes on the handler"],["sbin","Soft bins","The test program\u2019s failure category: many soft bins can map to one hard bin"]],onChange:p=>(g=p,{data:W(),title:`${g==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:p=>C(p.binCode),onSelectBar:(p,S)=>{const B=g==="hbin"?"hard":"soft",I=p.binCode;Q(S,e,I===void 0?`with no ${B} bin recorded`:`in ${B} bin ${I}`,_=>(g==="hbin"?_.hbin:_.sbin)===I)},selectLabel:"chart or tabulate its dies",ownerDocument:f},D=De(ae,k);return D.card.style.minHeight="360px",i.appendChild(D.card),{card:i,destroy:()=>{o?.destroy(),D.destroy()}}}function re(){const e=f.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Tt(),display:"flex",flexDirection:"column",gap:T.lg,minWidth:"0"}),e}function Fe(e){if(j.innerHTML="",j.style.marginBottom="0",!Ee)return;const n=It(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",j.appendChild(n),j.style.marginBottom=T.xs)}function Ne(e,n,r,l){if(!e.length)return{elements:[],destroy:()=>{}};const i=e.map(t=>t.wafer),u=e.map(t=>t.dies),c=N(),s=[],h=[],m=xt({groups:(l??[{key:"",items:e}]).map(t=>({key:t.key,items:t.items.map(o=>({dies:o.dies,testSpecYield:o.statsSummary?.stats.testSpecYield,functionalYield:o.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:k,onSelectTest:(t,o)=>{const g=r.find(C=>C.testNumber===t.testNumber);g&&Q(o,e,`failing ${t.label}`,C=>Ze(C,g,t.kind)===!0,xe(g)?t.testNumber:void 0)},ownerDocument:f});m.card.style.minHeight="300px",s.push(m.card),h.push(m.destroy);const a=t=>(o,g)=>{const C=new Set;for(const x of e)for(const W of At(x.dies,x.wafer,c,o.key,t))C.add(W);Q(g,e,`in ${o.label}`,x=>C.has(x))},b=ue(u,i,c,t=>e[t].passBins,$e);if(b.length){const t=pe({title:"Ring yield",mode:"ring",rows:b,onSelectRegion:a($e),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const y=ue(u,i,c,t=>e[t].passBins,Le);if(y.length){const t=pe({title:"Quadrant yield",mode:"quadrant",rows:y,onSelectRegion:a(Le),onSaveImage:k,ownerDocument:f});s.push(t.card),h.push(t.destroy)}const w=i.find(t=>t.reticle!==void 0)?.reticle;if(w){const t=(g,C)=>Pt(g,C.reticle),o=ue(u,i,c,g=>e[g].passBins,t);if(o.length){const g=pe({title:"Reticle cell yield",mode:"reticleCell",rows:o,grid:{width:w.width,height:w.height},onSelectRegion:a(t),onSaveImage:k,ownerDocument:f});s.push(g.card),h.push(g.destroy)}}return{elements:s,destroy:()=>{for(const t of h)t()}}}function Ye(e,n,r){if(!e.length)return{cards:[],destroy:()=>{}};const l=e.map(a=>a.dies),i=e.flatMap(a=>a.dies),u=e.map(a=>a.statsSummary),c=u.every(a=>a!==void 0)?u:void 0,s=[],h=[];let d=null;if(n.length){const a=re();let b=null;const y=Et($t(i,n,void 0,c,O,l.map(w=>({dies:w})),void 0,"full"),{onDone:w=>{b=w,a.removeAttribute("aria-busy"),w?a.replaceChildren(w):a.remove()}});if(y.done)b&&(d=a);else{const w=f.createElement("div");w.textContent="Computing test statistics\u2026",Object.assign(w.style,{color:$.label,fontSize:F.body}),a.setAttribute("aria-busy","true"),a.appendChild(w),d=a,s.push(()=>y.cancel())}}let m=null;if(r.length){const a=Lt(i,r,c,O);if(a){const b=re();b.appendChild(a),m=b}}return d&&h.push(d),m&&h.push(m),{cards:h,destroy:()=>{for(const a of s)a()}}}function je(e){const n=Te(e.map(d=>d.passBins)),r=e.length===1,l=e[0],i=re();Object.assign(i.style,{flexDirection:"row",flexWrap:"wrap",gap:T.md});const u=d=>{const m=d.lastElementChild;return m&&Object.assign(m.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),d};function c(d,m,a){const b=f.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"baseline",gap:T.sm,paddingRight:T.xxl,marginRight:T.md,borderRight:`1px solid ${$.menuBorder}`});const y=f.createElement("div");y.textContent=d,Object.assign(y.style,{fontSize:F.heading,fontWeight:"700",color:$.value,lineHeight:lt.tight});const w=f.createElement("div");if(w.textContent=m,Object.assign(w.style,{fontSize:F.body,color:$.label}),b.append(y,w),a){const t=f.createElement("div");t.textContent=a,Object.assign(t.style,{fontSize:F.meta,color:$.label,opacity:dt.muted}),b.appendChild(t)}return b}if(r){const d=J([{...l,key:l.waferIndex}])[0]?.percent;return d!==void 0&&i.appendChild(c(`${d.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),i.appendChild(c(String(l.dies.length),"Total dies")),u(i)}i.appendChild(c(String(e.length),"Wafers"));const s=J(e.map(d=>({...d,key:d.waferIndex}))).map(d=>d.percent).filter(d=>Number.isFinite(d));if(s.length){const d=s.reduce((b,y)=>b+y,0)/s.length,m=Be([{key:"all",items:e.map(b=>({...b,key:b.waferIndex}))}])[0]?.percent,a=m!==void 0&&m.toFixed(1)!==d.toFixed(1);i.appendChild(c(`${d.toFixed(1)}%`,`${qe} \xB7 pass: ${n}`,a?`${m.toFixed(1)}% by dies`:void 0))}const h=e.map(d=>d.statsSummary);if(h.every(d=>d!==void 0)){const d=h.reduce((a,b)=>a+b.stats.analyzedDies,0),m=h.reduce((a,b)=>a+b.stats.excludedDies,0);i.appendChild(c(d.toLocaleString(),"Dies analysed",m?`${m.toLocaleString()} excluded`:void 0))}else i.appendChild(c(e.reduce((d,m)=>d+m.dies.length,0).toLocaleString(),"Total dies"));return u(i)}function Ge(e,n,r,l,i){const u=f.createElement("div");Object.assign(u.style,{display:"flex",flexDirection:"column",gap:T.lg});const c=e.length===1&&!l;e.length&&!l&&u.appendChild(je(e));const s=Me(e,l,i,!c);u.appendChild(s.card);const h=Ne(e,n,r,l);for(const d of h.elements)s.card.appendChild(d);return u.appendChild(He()),{card:u,destroy:()=>{s.destroy(),h.destroy()}}}function He(){const e=f.createElement("div");Object.assign(e.style,{fontSize:F.body,color:$.label});const n=f.createElement("button");return n.type="button",n.textContent="Data tab",n.dataset.wmapOpenDataTab="1",Object.assign(n.style,{border:"none",background:"none",padding:"0",cursor:"pointer",font:"inherit",color:$.iconActive,textDecoration:"underline"}),de(n,"bare"),n.addEventListener("click",()=>{L="data",H({keepSections:!0})}),e.append("Test statistics, every die and every wafer as tables, with CSV export: see the ",n,"."),e}function _e(e,n,r,l){const i=f.createElement("div");i.style.width="100%";let u,c=!1;return import("./plotTab.js").then(({createPlotSection:s})=>{if(c)return;const h=s({doc:f,store:q,items:e,testDefs:n,ringCount:N(),attributes:v.attributes,groupBy:r,groupLabel:l,onSaveImage:k,onSaveText:O,openWafer:R?(d,m,a)=>R(d,m,a):void 0,focusTest:Z,locateDie:V,pickPlotsFile:v.onPickPlotsFile});i.appendChild(h.card),u=h}),{card:i,destroy:()=>{c=!0,u?.destroy()}}}function Ve(e,n,r,l,i){const u=fe?.(),c=()=>{G.get("data")?.destroy(),G.delete("data"),H({keepSections:!0})};return Ot({doc:f,items:e,testDefs:n,allTestDefs:r,groups:l,groupLabelText:i,ringCount:N(),attributes:v.attributes,yieldByWaferIndex:new Map(u?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),onSaveText:O,onLocateDie:V,onOpenWafer:R?(s,h)=>R(s,h):void 0,buildStatistics:s=>Ye(s,n,r),view:he,onViewChange:s=>{he=s,c()},diesLayout:ge,onDiesLayoutChange:s=>{ge=s}})}function ze(e,n,r,l){const i=ce(f),u=ie(e),c=t=>o=>ye(o,t()),s=t=>({...t,testStats:t.statsSummary?.stats.perTestStats}),h=e.map(s),d=r?.map(t=>({key:t.key,items:t.items.map(s)})),m=ht({title:"Test value distribution",axisPrefs:K,onAxisPrefsChange:c(()=>m),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:h,testDefs:n,groups:d,groupLabelText:l,onSaveImage:k,onGroupChange:t=>te(t),onOpen:u?.open,openActionLabel:u?.label,onWaferContextMenu:oe(e),ownerDocument:f}),a=yt({title:"Value histogram",axisPrefs:K,onAxisPrefsChange:c(()=>a),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e,testDefs:n,groups:r,onGroupChange:t=>te(t),onSaveImage:k,onSelectBucket:(t,o)=>{const g=n.find(D=>D.testNumber===t.testNumber),C=new Set(t.items.map(D=>D.item)),x=new Set(t.items.flatMap(D=>D.dies)),W=ke(t.low,g?.unit,"engineering"),ae=ke(t.high,g?.unit,"engineering");Q(o,e.filter(D=>C.has(D)),`with ${g?et(g,g.testNumber):`test ${t.testNumber}`} from ${W} to ${ae}${t.group?` in ${t.group}`:""}`,D=>x.has(D),t.testNumber)},ownerDocument:f}),b=gt({title:"Wafer-to-wafer trend",axisPrefs:K,onAxisPrefsChange:c(()=>b),onTestChange:t=>y(t),selectedTestNumber:P??void 0,items:e.map(t=>({label:t.label,key:t.waferIndex,dies:t.dies,testStats:t.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:k,centreLabel:st(at(e.map(t=>t.wafer.metadata)),"mean"),onOpen:R?(t,o)=>ne(t,`Wafer ${e.find(g=>g.waferIndex===t)?.label??t}`,o):void 0,onSelectWafers:(t,o,g)=>{const C=new Set(t.keys);Ce(o,g,e.filter(x=>C.has(x.waferIndex)),"selected in the trend",()=>!0,t.testNumber)},onWaferContextMenu:oe(e),ownerDocument:f}),y=t=>{P=t,m.setTest(t),a.setTest(t),b.setTest(t),w.setTest(t)};ee.set("distribution",[m,a,b]);const w=bt({title:"Process capability",items:e,testDefs:n,onSaveImage:k,selectedTestNumber:P??void 0,onSelectTest:t=>y(t),ownerDocument:f});return i.append(w.card,m.card,a.card,b.card),{card:i,destroy:()=>{w.destroy(),m.destroy(),a.destroy(),b.destroy()}}}function Ue(e,n,r){const l=ce(f),i=Ct({title:"Test scatter",items:e,testDefs:n,groups:r,binColors:me().hard,onSaveImage:k,axisPrefs:K,onAxisPrefsChange:c=>ye(c,i),onOpen:ie(e)?.open,openActionLabel:ie(e)?.label,onSelect:(c,s,h,d)=>{const m=new Map;for(const y of c){if(y.waferIndex===void 0||!y.die)continue;const w=m.get(y.waferIndex);w?w.push(y.die):m.set(y.waferIndex,[y.die])}const a=[...m].flatMap(([y,w])=>{const t=e.find(o=>o.waferIndex===y);return t?[{label:t.identity??t.label,dies:w,waferIndex:y,wafer:t.wafer,passBins:t.passBins,ringCount:N()}]:[]});if(a.length===0)return;const b=a.length===1?`selected on ${a[0].label} in the scatter`:`selected in the scatter, across ${a.length} wafers`;se(s,h,{items:a,population:b,testDefs:n,activeTest:d},{plots:q,onSaveImage:k,onSaveText:O,onLocateDie:V})},ownerDocument:f});ee.set("correlation",[i]);const u=wt({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:k,onSaveText:O,onSelectPair:(c,s)=>i.setXY(c,s),ownerDocument:f});return l.append(u.card,i.card),{card:l,destroy:()=>{u.destroy(),i.destroy()}}}function H(e){e?.keepSections||we(),U.innerHTML="",E.innerHTML="";for(const o of Ae)E.appendChild(We(o.key,o.label));const n=Oe();Fe(n);const r=Ke(n,{facetableOnly:!0,curation:be}).filter(o=>o.splittable),l=f.createElement("div");Object.assign(l.style,{display:"flex",gap:T.md,alignItems:"center",marginLeft:T.xxl,paddingBottom:T.xs});let i;r.length>0?(l.appendChild(vt("Group by:",[{value:"",label:"None"},...r.map(o=>({value:o.key,label:`${o.label} (${o.values.length})`}))],M??"",o=>{M=o||void 0,A=null,H()},{hook:"group-by",ownerDocument:f})),i=r.find(o=>o.key===M)?.label):M=void 0;let u;if(M){const o=new Map,g=[];for(const C of n){const x=Qe(C.metadata,M,be)??Xe;o.has(x)||(o.set(x,[]),g.push(x)),o.get(x).push(C)}u=g.map(C=>({key:C,items:o.get(C)}))}A!==null&&!u?.some(o=>o.key===A)&&(A=null),u&&u.length>0&&l.appendChild(Dt(u.map(o=>o.key),"Show:",A,o=>te(o),{ownerDocument:f}).el);let c=null;if(v.onOpenGuide){const o=f.createElement("button");o.type="button",o.innerHTML=mt.help,o.setAttribute("aria-label","User guide"),Object.assign(o.style,{...pt("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),de(o,"bare"),ft(o,"User guide"),o.addEventListener("click",()=>v.onOpenGuide()),Object.assign(o.style,{marginLeft:"auto"}),c=o}E.appendChild(l),c&&E.appendChild(c);const s=A!==null?u?.find(o=>o.key===A):void 0,h=s?.items??n,d=s?void 0:u,m=Se(h),a=m.defs,b=a.filter(xe);P!==null&&!b.some(o=>o.testNumber===P)&&(P=null);const y=e?.keepSections?G.get(L):void 0,w=y??(L==="overview"?Ge(h,b,a,d,i):L==="distributions"?ze(h,b,d,i):L==="data"?Ve(h,b,a,d,i):L==="plot"?_e(h,a,s?void 0:M,s?void 0:i):Ue(h,b,d));y||G.set(L,w);const t=m.conflicts.filter(o=>o.excluded);if(t.length>0){const o=f.createElement("div");Object.assign(o.style,{color:$.label,fontSize:F.body,padding:`0 ${z} ${T.sm}`});const g=t.slice(0,6).map(W=>W.testNumber).join(", "),C=t.length>6?`, and ${t.length-6} more`:"",x=t.length===1?"it":"them";o.textContent=`${t.length} test ${t.length===1?"number is":"numbers are"} hidden (${g}${C}) \u2014 the wafers in view describe ${x} differently, so their values cannot be pooled. `+(u&&u.length>0?`Pick one ${i??"group"} under "Show:" to analyse ${x}.`:"Load one test program at a time to analyse them."),o.dataset.wmapWithheldTests=String(t.length),U.appendChild(o)}U.appendChild(w.card)}return{el:Y,render:H,destroy:()=>{we(),q.flush(),Y.remove()}}}
@@ -7,8 +7,8 @@ export interface MaplessSummaryOptions {
7
7
  activeTest?: number;
8
8
  hbinDefs?: BinDef[];
9
9
  sbinDefs?: BinDef[];
10
- /** The map's resolved bin colours (`View.binColors`), so bars match its legend. */
11
- binColors?: BinColors;
10
+ /** The map's resolved bin colours (`View.binColors`), so bars match its legend and judge by the map's own pass bins. Required: there is no default to resolve them by. */
11
+ binColors: BinColors;
12
12
  /** The map's value gradient name, so histogram bars match its colorbar. */
13
13
  valueColorScheme?: string;
14
14
  /** The map's `View.reverseValueScheme` — must travel with the name, or the
@@ -0,0 +1,29 @@
1
+ import { type FieldOption } from '../stats/plotData.js';
2
+ import { type PlotSpec } from '../stats/plotSpec.js';
3
+ export interface PlotEditorOptions {
4
+ doc: Document;
5
+ plot: PlotSpec;
6
+ catalogue: readonly FieldOption[];
7
+ /** What "Follow Group by" means right now ("Split", or "a colour per wafer" with no grouping), or undefined for a single colour. */
8
+ followLabel: () => string | undefined;
9
+ /** The automatic title and axis titles, shown as placeholders so the reader sees what clearing a box gives back. */
10
+ autoText: () => {
11
+ title: string;
12
+ x?: string;
13
+ y?: string;
14
+ };
15
+ /** Called with the new spec after every change. */
16
+ onChange: (next: PlotSpec) => void;
17
+ }
18
+ export interface PlotEditorHandle {
19
+ el: HTMLElement;
20
+ /** The spec changed elsewhere (undo, a rebind): show it. */
21
+ setPlot(plot: PlotSpec): void;
22
+ /** The automatic text changed (the data did): refresh the placeholders. */
23
+ refreshAuto(): void;
24
+ }
25
+ export declare function inputStyle(): Partial<CSSStyleDeclaration>;
26
+ /** A labelled control with an optional hint beneath it: the one layout every editor field uses. */
27
+ export declare function fieldRow(doc: Document, label: string, control: HTMLElement, hint?: string): HTMLElement;
28
+ export declare function createPlotEditor(o: PlotEditorOptions): PlotEditorHandle;
29
+ //# sourceMappingURL=plotEditor.d.ts.map
@@ -0,0 +1 @@
1
+ import{combinationIssue as le,describeTitleDrift as oe,fieldKey as k,fieldsForRole as q,titleDrift as ae}from"../stats/plotData.js";import{sameField as $}from"../stats/plotSpec.js";import{CLR as m,FONT as S,RADIUS as V,SPACE as b,controlStyle as K,wireControlHover as _,wireTooltip as se}from"./toolbar.js";import{makeListSelect as X,makeSegmented as N,makeToggle as re}from"./charts/chartShell.js";const Y="\0follow",z="\0none",ce=[["scatter","Scatter","One point per die or wafer, one value against another"],["histogram","Histogram","How often each value occurs"],["box","Box","Quartiles, with whiskers to the minimum and maximum, for each category"],["bar","Bar","One combined value for each category, or a count"],["line","Line","One combined value at each X, joined"]],A="\0auto",G="\0count",Q={mean:"Mean",median:"Median",min:"Minimum",max:"Maximum",sum:"Sum",count:"Count",yield:"Pooled yield (passing over judged dies)"};export function inputStyle(){return{background:m.menuBg,color:m.text,border:`1px solid ${m.menuBorder}`,borderRadius:V.control,padding:`${b.xs} ${b.sm}`,fontSize:S.body,fontFamily:S.family,boxSizing:"border-box",minWidth:"0"}}export function fieldRow(d,r,B,a){const p=d.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:b.xxs,minWidth:"0"});const x=d.createElement("div");if(x.textContent=r,Object.assign(x.style,{fontSize:S.sub,color:m.label,fontWeight:"600"}),p.append(x,B),a){const T=d.createElement("div");T.textContent=a,Object.assign(T.style,{fontSize:S.sub,color:m.label}),p.appendChild(T)}return p}export function createPlotEditor(d){const{doc:r}=d,B=t=>t.fields?t:{...t,fields:{}};let a=B(d.plot),p="setup";const x=r.createElement("div");x.dataset.wmapPlotEditor="1",Object.assign(x.style,{display:"flex",flexDirection:"column",gap:b.lg,minWidth:"0"});const T=t=>{a=t,d.onChange(t)},y=t=>{const e=JSON.parse(JSON.stringify(a));t(e),T(e)},c=(t,e,i)=>fieldRow(r,t,e,i),D=t=>{const e=t&&d.catalogue.find(i=>$(i.field,t));return e?{label:e.name,level:e.level,kind:e.kind,yield:"builtin"in e.field&&e.field.builtin==="yield"}:void 0};function Z(t,e){const i=a.fields??{},n=i.color&&!("follow"in i.color)&&!("none"in i.color)?i.color:void 0,o={x:D(i.x),y:D(i.y),color:D(n)};o[t]=D(e.field);const l=a.chart==="scatter"&&o.color?.kind==="numeric"&&!!n&&!("meta"in n);return le(a.chart,o,{aggregate:a.aggregate,level:a.level,continuousColor:l})?.short}const I=t=>{const e=a.fields?.[t],i=e&&!("follow"in e)&&!("none"in e)?e:void 0;return q(d.catalogue,a.chart,t).map(n=>{const o=i&&$(n.field,i)?void 0:Z(t,n);return{value:k(n.field),label:n.label,group:n.group,...o?{disabled:o}:{}}})},H=t=>d.catalogue.find(e=>k(e.field)===t)?.field;function w(t,e,i={}){const n=a.fields[t],o=I(t);if(i.optional&&o.unshift({value:G,label:i.optional,group:"Count"}),n&&!o.some(u=>u.value===k(n))){const u=d.catalogue.some(C=>$(C.field,n)),h="test"in n?n.name??`Test ${n.test}`:"meta"in n?n.meta:n.builtin;o.unshift({value:k(n),label:`${h} (${u?"not usable here":"not in this lot"})`,group:"Saved"})}const l=n?k(n):i.optional?G:"",s=X(o,l,u=>{if(u===G){y(C=>{delete C.fields[t]});return}const h=H(u)??a.fields[t];h&&y(C=>{C.fields[t]=h})},{maxWidth:"100%",ownerDocument:r,ariaLabel:e,emptyText:"Choose a field\u2026",searchPlaceholder:"Filter fields\u2026",hook:`plot-${t}`});return s.style.width="100%",s}const P={},F={};function ee(t){y(e=>{e.chart=t;for(const i of["x","y"]){const n=q(d.catalogue,t,i),o=h=>!!h&&n.some(C=>$(C.field,h)),l=e.fields[i];if(l&&!o(l)&&($(l,F[i])||(P[i]=l),delete e.fields[i]),e.fields[i]||i==="y"&&t==="bar")continue;const s=P[i];if(o(s)){e.fields[i]=s,delete P[i],delete F[i];continue}const u=i==="x"&&(t==="box"||t==="bar")?{builtin:"wafer"}:i==="x"&&t==="line"?n.find(h=>h.group==="Wafer")?.field??n[0]?.field:n[0]?.field;u&&!(i==="x"&&t==="histogram")&&(e.fields[i]=u,F[i]=u)}}),O()}function te(){const t=!!a.fields.y&&"builtin"in a.fields.y&&a.fields.y.builtin==="yield",e=[{value:A,label:"Automatic"},...["mean","median","min","max","sum","count"].map(n=>({value:n,label:Q[n]}))];t&&e.push({value:"yield",label:Q.yield});const i=X(e,a.aggregate??A,n=>y(o=>{n===A?delete o.aggregate:o.aggregate=n}),{maxWidth:"100%",ownerDocument:r,ariaLabel:"Combine values by",hook:"plot-aggregate"});return i.style.width="100%",i}function ie(){const t=a.fields.color,e=d.followLabel(),i=[{value:Y,label:e?`Follow Group by (${e})`:"Follow Group by (single colour)",group:"Colour"},{value:z,label:"None",group:"Colour"},...I("color")],n=t===void 0||"follow"in t?Y:"none"in t?z:k(t),o=X(i,n,l=>{y(s=>{if(l===Y)delete s.fields.color;else if(l===z)s.fields.color={none:!0};else{const u=H(l);u&&(s.fields.color=u)}})},{maxWidth:"100%",ownerDocument:r,ariaLabel:"Colour",searchPlaceholder:"Filter fields\u2026",hook:"plot-color"});return o.style.width="100%",o}function J(t,e,i,n){const o=r.createElement("input");return o.type="text",o.value=t,o.placeholder=e,o.setAttribute("aria-label",i),Object.assign(o.style,inputStyle(),{width:"100%"}),o.addEventListener("input",()=>n(o.value)),o.addEventListener("keydown",l=>{l.key==="Escape"&&(l.stopPropagation(),o.blur())}),o}function W(t,e,i){const n=r.createElement("input");n.type="text",n.inputMode="decimal",n.value=t===void 0?"":String(t),n.placeholder="auto",n.setAttribute("aria-label",e),Object.assign(n.style,inputStyle(),{width:"100%",fontVariantNumeric:"tabular-nums"});const o=()=>{const l=n.value.trim();if(l===""){i(void 0);return}const s=Number(l);Number.isFinite(s)?i(s):n.value=t===void 0?"":String(t)};return n.addEventListener("change",o),n.addEventListener("keydown",l=>{l.key==="Enter"&&o(),l.key==="Escape"&&(l.stopPropagation(),n.value=t===void 0?"":String(t),n.blur())}),n}function U(t,e,i,n){const o=a.axes?.[t]??{},l=g=>y(f=>{f.axes=f.axes??{};const E=f.axes[t]=f.axes[t]??{};g(E);for(const j of Object.keys(E))(E[j]===void 0||E[j]===""||j==="reverse"&&E[j]===!1)&&delete E[j];Object.keys(E).length===0&&delete f.axes[t],Object.keys(f.axes).length===0&&delete f.axes}),s=r.createElement("div");Object.assign(s.style,{display:"flex",flexDirection:"column",gap:b.md,padding:b.lg,border:`1px solid ${m.menuBorder}`,borderRadius:V.control});const u=r.createElement("div");u.textContent=e,Object.assign(u.style,{fontSize:S.body,fontWeight:"600",color:m.value}),s.appendChild(u);const h=J(o.label??"",i??"",`${e} title`,g=>l(f=>{f.label=g.trim()===""?void 0:g}));if(h.dataset.wmapPlotAxisTitle=t,s.appendChild(c("Title",h)),n.limits===!1)return s;const C=r.createElement("div");return Object.assign(C.style,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:b.md}),C.append(c("Minimum",W(o.min,`${e} minimum`,g=>l(f=>{f.min=g}))),c("Maximum",W(o.max,`${e} maximum`,g=>l(f=>{f.max=g})))),s.appendChild(C),n.scale&&s.appendChild(c("Scale",N([["linear","Linear"],["log","Log"]],o.scale??"linear",g=>l(f=>{f.scale=g==="log"?"log":void 0}),r))),s.appendChild(re("Reverse direction",!!o.reverse,g=>l(f=>{f.reverse=g}),r)),s}const ne=t=>x.querySelector(`[role="tab"][data-tab="${t}"]`);let L,v;const R=new Map;function M(){if(!v)return;const t=oe(ae(a,d.catalogue));if(v.replaceChildren(),v.style.display=t?"flex":"none",!t)return;const e=r.createElement("span");e.textContent=t;const i=r.createElement("button");i.type="button",i.textContent="Use the automatic title",i.dataset.wmapPlotAutoTitle="1",Object.assign(i.style,K("outlined")),_(i),i.addEventListener("click",()=>{y(n=>{delete n.title}),O()}),v.append(e,i)}function O(){x.replaceChildren(),R.clear();const t=r.createElement("div");t.setAttribute("role","tablist"),Object.assign(t.style,{display:"flex",gap:b.sm,borderBottom:`1px solid ${m.menuBorder}`});for(const[i,n,o]of[["setup","Setup","Which fields to plot and how they are combined"],["customise","Customise","Titles, axis limits, scale and direction"]]){const l=r.createElement("button");l.type="button",l.textContent=n,se(l,o),l.setAttribute("role","tab"),l.dataset.tab=i,l.setAttribute("aria-selected",String(p===i)),Object.assign(l.style,{...K("bare"),padding:`${b.sm} ${b.lg}`,fontSize:S.body,borderBottom:`2px solid ${p===i?m.iconActive:"transparent"}`,borderRadius:"0",color:p===i?m.iconActive:m.text,fontWeight:p===i?"600":"400"}),_(l,"bare"),l.tabIndex=p===i?0:-1,l.addEventListener("click",()=>{p=i,O()}),l.addEventListener("keydown",s=>{s.key!=="ArrowLeft"&&s.key!=="ArrowRight"||(s.preventDefault(),p=i==="setup"?"customise":"setup",O(),ne(p)?.focus())}),t.appendChild(l)}x.appendChild(t);const e=r.createElement("div");if(e.setAttribute("role","tabpanel"),Object.assign(e.style,{display:"flex",flexDirection:"column",gap:b.lg}),p==="setup"){e.appendChild(c("Chart type",N(ce,a.chart,n=>ee(n),r,!0)));const i=a.level==="wafer"?"wafers":"dies";switch(a.chart){case"scatter":e.appendChild(c("X axis",w("x","X axis"))),e.appendChild(c("Y axis",w("y","Y axis")));break;case"histogram":e.appendChild(c("Values",w("y","Values")));break;case"box":e.appendChild(c("Categories (X axis)",w("x","Categories"),"Compare by this field: one box per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell).")),e.appendChild(c("Values (Y axis)",w("y","Values")));break;case"bar":e.appendChild(c("Categories (X axis)",w("x","Categories"),"Compare by this field: one bar per value, whether it is a wafer attribute (lot, split) or a die region (ring, reticle cell).")),e.appendChild(c("Values (Y axis)",w("y","Values",{optional:`Count of ${i}`})));break;case"line":e.appendChild(c("X axis",w("x","X axis"),"A line joins the value at each X.")),e.appendChild(c("Y axis",w("y","Y axis")));break}e.appendChild(c("Colour",ie(),"Compare by this field: each value gets its own colour. Follow Group by takes it from the Group by control.")),(a.chart==="bar"||a.chart==="line"||a.level==="wafer")&&e.appendChild(c("Combine values by",te())),e.appendChild(c("One mark per",N([[A,"Automatic"],["die","Die"],["wafer","Wafer"]],a.level??A,n=>{y(o=>{n===A?delete o.level:o.level=n}),O()},r,!0),a.level==="wafer"?"Die-level values are combined per wafer.":"Automatic uses the finest level the chosen fields allow."))}else{L=J(a.title??"",d.autoText().title,"Plot title",l=>{y(s=>{l.trim()===""?delete s.title:Object.assign(s,{title:l})}),M()}),L.dataset.wmapPlotTitle="1",v=r.createElement("div"),v.dataset.wmapPlotTitleDrift="1",Object.assign(v.style,{display:"none",flexDirection:"column",gap:b.sm,alignItems:"flex-start",padding:`${b.sm} ${b.md}`,background:m.warnBg,border:`1px solid ${m.warnBorder}`,borderRadius:V.control,color:m.warnText,fontSize:S.body}),e.appendChild(c("Title",L)),e.appendChild(v),M();const i=d.autoText(),n=a.chart==="box"||a.chart==="bar";e.appendChild(U("x",a.chart==="histogram"?"Values axis":n?"Categories axis":"X axis",i.x,{scale:!n,limits:!n})),e.appendChild(U("y",a.chart==="histogram"?"Count axis":n||a.chart==="line"?"Values axis":"Y axis",i.y,{scale:a.chart!=="histogram"})),a.chart==="histogram"&&e.appendChild(c("Bins",W(a.bins,"Number of bins",l=>y(s=>{l===void 0||!Number.isInteger(l)||l<1?delete s.bins:s.bins=Math.min(l,200)})),"Automatic is 16 equal bins."));const o=a.fields??{};(o.x&&"test"in o.x||o.y&&"test"in o.y)&&e.appendChild(c("Limits",N([["both","Test + spec"],["test","Test"],["spec","Spec"],["none","None"]],a.limits??"both",l=>y(s=>{l==="both"?delete s.limits:s.limits=l}),r),"Drawn as dashed lines on the axis of a test that has them: short dashes for test limits, long for spec limits."));for(const l of e.querySelectorAll("[data-wmap-plot-axis-title]"))R.set(l.dataset.wmapPlotAxisTitle,l)}x.appendChild(e)}return O(),{el:x,setPlot(t){const e=B(t);JSON.stringify(e)!==JSON.stringify(a)&&(a=e,O())},refreshAuto(){const t=d.autoText();L&&(L.placeholder=t.title),M();for(const[e,i]of R)i.placeholder=(e==="x"?t.x:t.y)??""}}}
@@ -0,0 +1,32 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { Wafer } from '../core/wafer.js';
3
+ import type { TestDef } from '../renderer/buildWaferMap.js';
4
+ import type { PlotItem, PlotPoint } from '../stats/plotData.js';
5
+ import { type DrilldownSource } from './chartPopulation.js';
6
+ /** What a population hands over for each wafer: a drilldown source's items, or the Insights tab's. */
7
+ export interface WaferShare {
8
+ label: string;
9
+ dies: readonly Die[];
10
+ waferIndex?: number;
11
+ wafer?: Wafer;
12
+ passBins: readonly number[];
13
+ ringCount: number;
14
+ }
15
+ export declare function toPlotItems(items: readonly WaferShare[]): PlotItem[];
16
+ /**
17
+ * The dies a drag on a plot picked out, per wafer, as a drilldown population: charts and tables of just these.
18
+ * `null` when the drag caught no die (a wafer-level plot has none to pick).
19
+ */
20
+ export declare function sourceFromPoints(points: readonly PlotPoint[], items: readonly PlotItem[], testDefs: readonly TestDef[] | undefined): DrilldownSource | null;
21
+ /**
22
+ * The dies of each wafer that satisfy `keep`, as a drilldown population worded "`what` on W03" or "`what`, across N
23
+ * wafers". `null` when none does. Per wafer, so the tables name each die's wafer and a chart opened on it is of
24
+ * exactly those dies.
25
+ */
26
+ export declare function sourceFromDies(shares: readonly WaferShare[], what: string, keep: (d: Die) => boolean, testDefs: readonly TestDef[] | undefined, activeTest?: number): DrilldownSource | null;
27
+ /**
28
+ * The dies in `bins` (hard or soft), per wafer, for a legend entry's right-click: the same population a bin pareto bar
29
+ * opens. `null` when no die is in them. A stack of a lot holds aggregates, not dies, so it is named as not measured.
30
+ */
31
+ export declare function sourceFromBins(shares: readonly WaferShare[], kind: 'hard' | 'soft', bins: readonly number[], testDefs: readonly TestDef[] | undefined, activeTest?: number, stacked?: boolean): DrilldownSource | null;
32
+ //# sourceMappingURL=plotItems.d.ts.map
@@ -0,0 +1 @@
1
+ import{LOT_STACK_REASON as d}from"./chartPopulation.js";export function toPlotItems(l){return l.map(e=>({label:e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:e.ringCount,metadata:e.wafer?.metadata}))}export function sourceFromPoints(l,e,o){const s=new Map;for(const r of l){const n=s.get(r.item);if(!r.die){s.set(r.item,"all");continue}n!=="all"&&(n?n.push(r.die):s.set(r.item,[r.die]))}const t=[...s].map(([r,n])=>({label:e[r].label,dies:n==="all"?[...e[r].dies]:n,waferIndex:e[r].waferIndex,wafer:e[r].wafer,passBins:e[r].passBins,ringCount:e[r].ringCount}));if(t.length===0)return null;const a=t.length===1?`selected on ${t[0].label} in the plot`:`selected in the plot, across ${t.length} wafers`;return{items:t,population:a,testDefs:o?[...o]:void 0}}export function sourceFromDies(l,e,o,s,t){const a=l.map(n=>({it:n,dies:n.dies.filter(o)})).filter(n=>n.dies.length>0).map(({it:n,dies:f})=>({label:n.label,dies:f,waferIndex:n.waferIndex,wafer:n.wafer,passBins:n.passBins,ringCount:n.ringCount}));if(a.length===0)return null;const r=a.length===1?`${e} on ${a[0].label}`:`${e}, across ${a.length} wafers`;return{items:a,population:r,testDefs:s?[...s]:void 0,activeTest:t}}export function sourceFromBins(l,e,o,s,t,a=!1){const r=new Set(o),n=`in ${e} bin${o.length===1?"":"s"} ${o.join(", ")}`,f=sourceFromDies(l,n,i=>{const u=e==="hard"?i.hbin:i.sbin;return u!==void 0&&r.has(u)},s,t);return f&&a&&(f.notMeasuredReason=d),f}
@@ -0,0 +1,30 @@
1
+ import type { PlotContext, PlotItem } from '../stats/plotData.js';
2
+ import { type PlotSpec } from '../stats/plotSpec.js';
3
+ import { type PlotChartOptions } from './charts/plotChart.js';
4
+ import { type SweepPanelOptions } from './charts/sweep.js';
5
+ import type { PlotStore } from './plotStore.js';
6
+ export interface PlotEditorWindowOptions {
7
+ doc: Document;
8
+ anchor: HTMLElement;
9
+ store: PlotStore;
10
+ plot: PlotSpec;
11
+ /** A draft is not in the store until added. */
12
+ draft: boolean;
13
+ items: PlotItem[];
14
+ ctx: PlotContext;
15
+ /** The label "Follow Group by" resolves to, when the tab has one. */
16
+ groupLabel?: string;
17
+ /** Pointer callbacks for the chart (open a wafer, drag-select). */
18
+ chart: Omit<PlotChartOptions, 'ownerDocument' | 'waferLabel'>;
19
+ /** What the plot is drawn over, in words, when it is not the whole tab ("selected on W03"). */
20
+ population?: string;
21
+ /** The population before any count ("selected on W03"), which a sweep's own hint puts its count in front of. */
22
+ rawPopulation?: string;
23
+ /** Click a level of a sweep's curve: the menu on the dies measured there. Sweeps only. */
24
+ onSelectLevel?: SweepPanelOptions['onSelectPoint'];
25
+ /** The window's heading. Default: Edit plot, or New plot for a draft. */
26
+ title?: string;
27
+ onClosed?: () => void;
28
+ }
29
+ export declare function openPlotEditor(o: PlotEditorWindowOptions): void;
30
+ //# sourceMappingURL=plotModal.d.ts.map
@@ -0,0 +1 @@
1
+ import{fieldCatalogue as z,resolvePlot as I,plotTitle as $}from"../stats/plotData.js";import{plotToSweep as J}from"../stats/plotSpec.js";import{renderPlotChart as F}from"./charts/plotChart.js";import{renderSweepPanel as H}from"./charts/sweep.js";import{createPlotEditor as M}from"./plotEditor.js";import{createSweepEditor as Y}from"./sweepEditor.js";import{CLR as b,FONT as T,SPACE as i,controlStyle as B,openReparentedModal as q,wireControlHover as L}from"./toolbar.js";export function openPlotEditor(e){const{doc:n,store:c}=e;let o=e.plot,a=!e.draft;const W=z(e.items,e.ctx),h=t=>I(t,e.items,e.ctx),p=n.createElement("div");p.dataset.wmapPlotWindow="1",Object.assign(p.style,{display:"flex",flexWrap:"wrap",gap:i.xxl,alignItems:"flex-start",width:"100%",boxSizing:"border-box",padding:i.xl});const f=n.createElement("div");if(Object.assign(f.style,{flex:"3 1 420px",minWidth:"0",display:"flex",flexDirection:"column",gap:i.md}),e.population){const t=n.createElement("div");t.textContent=`Population: ${e.population}`,t.dataset.wmapPopulation="1",Object.assign(t.style,{color:b.label,fontSize:T.body}),f.appendChild(t)}const w=o.chart==="sweep";let r;if(w){const t=H({spec:J(o),dies:e.items.flatMap(l=>l.dies),testDefs:e.ctx.testDefs?[...e.ctx.testDefs]:void 0,population:e.rawPopulation??e.population,onSaveImage:e.chart.onSaveImage,onSelectPoint:e.onSelectLevel,ownerDocument:n});r={card:t.card,setPlot:l=>t.setSpec(J(l)),destroy:()=>t.destroy()}}else{const t=F({...e.chart,ownerDocument:n,waferLabel:l=>e.items[l]?.label??""});r={card:t.card,setPlot:l=>t.setPlot(h(l)),destroy:()=>t.destroy()}}r.card.style.alignSelf="stretch",f.appendChild(r.card);const m=n.createElement("div");Object.assign(m.style,{flex:"1 1 300px",minWidth:"260px",maxWidth:"420px",display:"flex",flexDirection:"column",gap:i.lg,maxHeight:"calc(min(92vh, 800px) - 110px)",overflowY:"auto",paddingRight:i.sm});const C=t=>{o=t,a&&c.upsert(t),y()},u=w?{...Y({doc:n,plot:o,testDefs:e.ctx.testDefs,onChange:C}),refreshAuto:()=>{}}:M({doc:n,plot:o,catalogue:W,followLabel:()=>e.groupLabel??(e.items.length>1?"a colour per wafer":void 0),autoText:()=>{const t=h(o);return{title:t.autoTitle,x:t.x?.label,y:t.y?.label}},onChange:C});m.appendChild(u.el);const g=n.createElement("div");Object.assign(g.style,{display:"flex",flexDirection:"column",gap:i.sm,color:b.label,fontSize:T.body,position:"sticky",bottom:"0",background:b.menuBg,borderTop:`1px solid ${b.menuBorder}`,paddingTop:i.sm,paddingBottom:i.md});const P=n.createElement("div");g.appendChild(P);const s=n.createElement("button");s.type="button",s.textContent="Add to my plots",s.dataset.wmapPlotAdd="1",Object.assign(s.style,{...B("outlined"),alignSelf:"flex-start"}),L(s),s.addEventListener("click",()=>{a=!0,c.upsert(o),N()});const E=JSON.parse(JSON.stringify(e.plot)),O=(t,l,R)=>{const d=n.createElement("button");return d.type="button",d.textContent=t,d.dataset[l]="1",Object.assign(d.style,B("outlined")),L(d),d.addEventListener("click",R),d},x=O("Reset","wmapPlotReset",()=>D()),k=O("Cancel","wmapPlotCancel",()=>{D(),v?.close()}),S=n.createElement("div");Object.assign(S.style,{display:"flex",gap:i.md,flexWrap:"wrap"}),S.append(x,k,s),g.appendChild(S),m.appendChild(g);const A=()=>JSON.stringify(o)!==JSON.stringify(E);function D(){o=JSON.parse(JSON.stringify(E)),a&&c.upsert(o),u.setPlot(o),y()}function N(){P.textContent=a?`Changes are saved to \u201C${w?o.title??"Sweep":$(h(o))}\u201D.`:"This is a draft: it is not kept until you add it to your plots.",s.style.display=a?"none":"",x.disabled=!A(),x.style.opacity=x.disabled?"0.5":"1"}function y(){r.setPlot(o),u.refreshAuto(),N()}y(),p.append(f,m);const j=c.subscribe(()=>{if(!a)return;const t=c.get().find(l=>l.id===o.id);if(!t){v?.close();return}JSON.stringify(t)!==JSON.stringify(o)&&(o=t,u.setPlot(t),y())}),v=q([p],{title:e.title??(a?"Edit plot":"New plot"),anchor:e.anchor,ownerDocument:n,boxSize:{width:"min(96vw, 1180px)",height:"min(92vh, 800px)"},onClosed:()=>{j(),r.destroy(),e.onClosed?.()}});v||(j(),r.destroy())}
@@ -0,0 +1,52 @@
1
+ import type { PlotSpec } from '../stats/plotSpec.js';
2
+ import type { SweepSpec } from '../stats/sweep.js';
3
+ export interface PlotStore {
4
+ get(): readonly PlotSpec[];
5
+ /** Replaces the plot with this id, or appends it. */
6
+ upsert(plot: PlotSpec): void;
7
+ /** Inserts at a position (undo of a delete puts the plot back where it was). */
8
+ insertAt(index: number, plot: PlotSpec): void;
9
+ remove(id: string): {
10
+ plot: PlotSpec;
11
+ index: number;
12
+ } | undefined;
13
+ /** A copy with a new id, placed after the original. A typed title gains "(copy)"; an untitled plot stays untitled, so its title keeps following its fields. */
14
+ duplicate(id: string): PlotSpec | undefined;
15
+ /** Replaces the whole list (an import). A sweep the host still supplies that is not in it is reported through `onRemove`, as `remove` does. */
16
+ replaceAll(plots: readonly PlotSpec[]): void;
17
+ subscribe(fn: () => void): () => void;
18
+ /** Sends a change still waiting for the debounce. */
19
+ flush(): void;
20
+ }
21
+ /**
22
+ * The title for a copy of a plot titled `title`: the original's name with a copy mark, numbered once there are several
23
+ * ("Vth (copy)", "Vth (copy 2)"). A copy of a copy is a copy of the original, not a copy of a copy: marks do not pile up.
24
+ */
25
+ export declare function copyTitle(title: string, existing: ReadonlyArray<string | undefined>): string;
26
+ /** Sweeps a host still supplies through `insights.sweeps`: they become sweep plots in the list. */
27
+ export interface LegacySweeps {
28
+ sweeps: readonly SweepSpec[] | undefined;
29
+ /** Told when the reader deletes one of them, so the host stops supplying it (else the next render brings it back). */
30
+ onRemove?: (ids: string[]) => void;
31
+ }
32
+ /**
33
+ * The store for a host's `insights` options: its saved plots, with any `sweeps` it still supplies turned into sweep
34
+ * plots. A plot already saved under a sweep's id wins, so a host that keeps both does not show a sweep twice and an
35
+ * edit the reader made is not undone by the host's older definition.
36
+ */
37
+ export declare function plotStoreFor(insights: {
38
+ plots?: PlotSpec[];
39
+ onPlotsChange?: (plots: PlotSpec[]) => void;
40
+ sweeps?: SweepSpec[];
41
+ onRemoveSweeps?: (ids: string[]) => void;
42
+ } | undefined): PlotStore;
43
+ export declare function createPlotStore(initial: readonly PlotSpec[] | undefined, onChange?: (plots: PlotSpec[]) => void, delayMs?: number, legacy?: LegacySweeps): PlotStore;
44
+ /**
45
+ * How a gallery hands its own store to the maps it draws on its cards. Not a public option: a card's map would
46
+ * otherwise build a store of its own from nothing, and the plots saved on the Plot tab would be missing from the
47
+ * right-click menu on every card.
48
+ */
49
+ export interface WithPlotStore {
50
+ plotStore?: PlotStore;
51
+ }
52
+ //# sourceMappingURL=plotStore.d.ts.map
@@ -0,0 +1 @@
1
+ import{sweepToPlot as O}from"../stats/plotSpec.js";import{newPlotId as g}from"../stats/plotId.js";import{noticeOnce as x}from"../renderer/deprecate.js";export function copyTitle(i,m){const l=i.replace(/(?:\s*\(copy(?: \d+)?\))+$/,"")||i,r=new Set(m);let d=`${l} (copy)`;for(let f=2;r.has(d);f++)d=`${l} (copy ${f})`;return d}export function plotStoreFor(i){return createPlotStore(i?.plots,i?.onPlotsChange,void 0,{sweeps:i?.sweeps,onRemove:i?.onRemoveSweeps})}export function createPlotStore(i,m,l=400,r){const d=new Set((i??[]).map(e=>e.id)),f=(r?.sweeps??[]).filter(e=>!d.has(e.id));(r?.sweeps?.length??0)>0&&x("insights.sweeps","`insights.sweeps` is deprecated: sweeps are plots now. Pass them in `insights.plots` as sweep plots (readPlotsFile reads a sweeps file), which the Plot tab can also save and share.");const h=new Set((r?.sweeps??[]).map(e=>e.id));let t=[...i??[],...f.map(O)].map(e=>JSON.parse(JSON.stringify(e)));const u=new Set;let p,w=!1;const S=()=>{p!==void 0&&(clearTimeout(p),p=void 0),w&&(w=!1,m?.(t.map(e=>JSON.parse(JSON.stringify(e)))))},a=()=>{for(const e of[...u])e();w=!0,p!==void 0&&clearTimeout(p),p=setTimeout(S,l)};return{get:()=>t,upsert(e){const s=t.findIndex(n=>n.id===e.id);t=s<0?[...t,e]:t.map((n,o)=>o===s?e:n),a()},insertAt(e,s){const n=Math.max(0,Math.min(e,t.length));t=[...t.slice(0,n),s,...t.slice(n)],a()},remove(e){const s=t.findIndex(o=>o.id===e);if(s<0)return;const n=t[s];return t=t.filter((o,c)=>c!==s),a(),h.has(e)&&r?.onRemove?.([e]),{plot:n,index:s}},duplicate(e){const s=t.findIndex(c=>c.id===e);if(s<0)return;const n=t[s],o=JSON.parse(JSON.stringify(n));return o.id=g(),n.title&&Object.assign(o,{title:copyTitle(n.title,t.map(c=>c.title))}),t=[...t.slice(0,s+1),o,...t.slice(s+1)],a(),o},replaceAll(e){const s=[...h].filter(n=>t.some(o=>o.id===n)&&!e.some(o=>o.id===n));t=e.map(n=>JSON.parse(JSON.stringify(n))),a(),s.length>0&&r?.onRemove?.(s)},subscribe(e){return u.add(e),()=>{u.delete(e)}},flush:S}}
@@ -0,0 +1,33 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { TestDef } from '../renderer/buildWaferMap.js';
3
+ import type { FacetCuration } from '../stats/facets.js';
4
+ import type { PlotStore } from './plotStore.js';
5
+ import type { InsightsItem } from './insightsTab.js';
6
+ import { type SaveImageHandler, type SaveTextHandler } from './toolbar.js';
7
+ export interface PlotSectionDeps {
8
+ /** The host's own wafer attributes: which are offered as fields, and what they are called. Over the defaults. */
9
+ attributes?: Record<string, FacetCuration>;
10
+ doc: Document;
11
+ store: PlotStore;
12
+ items: InsightsItem[];
13
+ /** The population's reconciled test list. */
14
+ testDefs: TestDef[];
15
+ ringCount: number;
16
+ /** The tab's Group by key and its label, which "follow Group by" resolves to. */
17
+ groupBy?: string;
18
+ groupLabel?: string;
19
+ onSaveImage?: SaveImageHandler;
20
+ onSaveText?: SaveTextHandler;
21
+ /** Click a point: open its wafer, on a test's values when the plot is about one. */
22
+ openWafer?: (waferIndex: number, label: string, testNumber?: number) => void;
23
+ /** A single-wafer host's version of the same: show the test on the map that is already there. */
24
+ focusTest?: (testNumber: number) => void;
25
+ locateDie?: (die: Die, waferIndex: number | undefined) => void;
26
+ /** The host's own way to choose a plots file (a native dialog). Without it a file input is used. */
27
+ pickPlotsFile?: () => Promise<string | null>;
28
+ }
29
+ export declare function createPlotSection(d: PlotSectionDeps): {
30
+ card: HTMLElement;
31
+ destroy: () => void;
32
+ };
33
+ //# sourceMappingURL=plotTab.d.ts.map
@@ -0,0 +1 @@
1
+ import{defaultPlot as Z,defaultSweep as ee,describeTitleDrift as te,examplePlots as oe,fieldCatalogue as ne,resolvePlot as se,titleDrift as re}from"../stats/plotData.js";import{addPlots as le,newPlotId as T,readPlotsFile as ae,writePlotsFile as ie}from"../stats/plotSpec.js";import{isYieldEligibleDie as ce}from"../core/dies.js";import{testValue as pe}from"../core/dieTable.js";import{sweepAppliesTo as de}from"../stats/sweep.js";import{plotToSweep as L}from"../stats/plotSpec.js";import{renderPlotChart as fe}from"./charts/plotChart.js";import{renderSweepPanel as ue}from"./charts/sweep.js";import{makeChartGridWrap as me}from"./charts/chartShell.js";import{confirmDialog as he}from"./confirmDialog.js";import{openDrilldownMenu as O}from"./drilldown.js";import{openPlotEditor as ge}from"./plotModal.js";import{sourceFromDies as ye,sourceFromPoints as we,toPlotItems as be}from"./plotItems.js";import{CLR as g,FONT as S,RADIUS as F,SPACE as u,controlStyle as xe,markNoPrint as E,saveTextFile as Pe,wireControlHover as ve,wireTooltip as De}from"./toolbar.js";const R=1e4;export function createPlotSection(r){const{doc:i,store:l}=r,c=be(r.items.map(e=>({label:e.identity??e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:r.ringCount}))),C={testDefs:r.testDefs,groupBy:r.groupBy,curation:r.attributes},U=e=>se(e,c,C),b=ne(c,C),m=i.createElement("div");m.dataset.wmapPlotTab="1",Object.assign(m.style,{display:"flex",flexDirection:"column",gap:u.lg,width:"100%"});const x=i.createElement("div");Object.assign(x.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const d=(e,t,n,o)=>{const s=i.createElement("button");return s.type="button",s.textContent=e,s.dataset[t]="1",Object.assign(s.style,{...xe("outlined"),fontSize:S.body}),ve(s),De(s,n),s.addEventListener("click",o),s},P=d("Delete all plots\u2026","wmapPlotDeleteAll","Remove every plot and sweep. You are asked first, and Undo brings them back for ten seconds",()=>{V()});x.append(d("+ New plot","wmapPlotNew","Start a chart of your own: choose its type, what goes on each axis and how it is coloured",()=>z()),d("+ New sweep","wmapPlotNewSweep","Read an ordered run of tests as a response curve, and measure where two curves cross",()=>M()),d("Add examples","wmapPlotExamples","Draw one example of each chart type this lot can show, to edit or delete",()=>Y()),d("Import plots\u2026","wmapPlotImport","Add the plots from a file written by Export plots\u2026",()=>{Q()}),d("Export plots\u2026","wmapPlotExport","Save all your plots to a file, to share or to keep a copy",()=>X()),P),E(x),m.appendChild(x);const p=i.createElement("div");p.setAttribute("role","status"),Object.assign(p.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",padding:`${u.sm} ${u.md}`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:F.container,color:g.text,fontSize:S.body}),E(p),m.appendChild(p);let h;function y(e,t,n=[]){h!==void 0&&clearTimeout(h),p.replaceChildren();const o=i.createElement("span");if(o.textContent=e,p.appendChild(o),t){const s=d(t.label,"wmapPlotNoticeAction",t.label==="Undo"?"Put back what was just removed":t.label,()=>{t.run(),I()});p.appendChild(s)}for(const s of n){const a=i.createElement("div");a.textContent=s,Object.assign(a.style,{flexBasis:"100%",color:g.label}),p.appendChild(a)}p.style.display="flex",h=setTimeout(I,t?R:R*2)}function I(){h!==void 0&&(clearTimeout(h),h=void 0),p.style.display="none",p.replaceChildren()}const v=i.createElement("div");v.textContent="No plots yet. A plot is any measured value against another, or a distribution, that you choose: New plot starts one, and it is kept for the next lot. Add examples draws one of each chart type from this lot to start from.",Object.assign(v.style,{color:g.label,fontSize:S.body,padding:`${u.lg} 0`});const D=me(i);m.append(v,D);const w=new Map,A=()=>({onSaveImage:r.onSaveImage,onOpenWafer:r.openWafer?(e,t)=>r.openWafer(c[e].waferIndex??e,c[e].label,t):r.focusTest&&c.length===1?(e,t)=>{t!==void 0&&r.focusTest(t)}:void 0,openActionLabel:!r.openWafer&&r.focusTest&&c.length===1?"show this test on the map":void 0,onSelectPoints:(e,t,n)=>W(e,t,n)}),$=()=>({plots:l,onSaveImage:r.onSaveImage,onSaveText:r.onSaveText,onLocateDie:r.locateDie});function W(e,t,n){const o=we(e,c,r.testDefs);o&&O(t,n,o,$())}function k(e,t=!1){ge({doc:i,anchor:m,store:l,plot:e,draft:t,items:c,ctx:C,groupLabel:r.groupLabel,chart:A(),onSelectLevel:j})}function M(){const e=ee(r.testDefs,T());l.upsert(e),k(e)}function j(e,t){const n=s=>e.testNumbers.some(a=>{const f=pe(s,a);return f!==void 0&&Number.isFinite(f)}),o=ye(c,`measured at ${e.label}`,s=>ce(s)&&n(s),r.testDefs,e.testNumbers[0]);o&&O({x:t.clientX,y:t.clientY},t.target,o,$())}function z(){const e=Z(b,T());l.upsert(e),k(e)}function Y(){const e=o=>JSON.stringify([o.chart,o.fields,o.aggregate??null,o.sweep??null]),t=new Set(l.get().map(e)),n=oe(b,c.length,T).filter(o=>!t.has(e(o)));if(n.length===0){y(b.some(o=>o.group==="Tests")?"The examples for this lot are already in your plots.":"There are no measured values in this lot to draw examples from.");return}for(const o of n)l.upsert(o);y(`Added ${n.length} example plot${n.length===1?"":"s"}: ${n.map(o=>o.chart).join(", ")}. Edit one to make it yours, or Delete what you do not need.`)}function N(e,t){const n=(o,s,a,f)=>e.appendChild(d(o,s,a,f));n("Edit","wmapPlotEdit","Change this plot\u2019s type, fields, titles, limits and axes",()=>{const o=l.get().find(s=>s.id===t.id);o&&k(o)}),n("Duplicate","wmapPlotDuplicate","Make a copy of this plot to vary",()=>{l.duplicate(t.id)}),n("Delete","wmapPlotDelete","Remove this plot. Undo brings it back for ten seconds",()=>{const o=l.remove(t.id);o&&y(`Deleted \u201C${o.plot.title??"plot"}\u201D.`,{label:"Undo",run:()=>l.insertAt(o.index,o.plot)})})}function _(e){return e.chart==="sweep"?J(e):H(e)}function H(e){const t=fe({ownerDocument:i,waferLabel:s=>c[s]?.label??"",...A()});t.card.dataset.wmapPlotId=e.id,E(t.actions),N(t.actions,e);const n=i.createElement("div");n.dataset.wmapPlotTitleDrift="1",Object.assign(n.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",flexBasis:"100%",padding:`${u.xs} ${u.md}`,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:F.control,color:g.warnText,fontSize:S.body}),t.actions.appendChild(n);const o={card:t.card,actions:t.actions,json:"",driftNote:n,destroy:()=>t.destroy(),update:s=>{const a=U(s);t.setPlot(a),t.card.style.opacity=a.issues.length?"0.7":"1",G(n,s)}};return w.set(e.id,o),o}function J(e){const t=L(e),n=c.flatMap(a=>a.dies),o=ue({spec:t,dies:n,testDefs:r.testDefs,onSaveImage:r.onSaveImage,ownerDocument:i,onSelectPoint:j});o.card.dataset.wmapPlotId=e.id,o.card.dataset.wmapSweepPlot="1",E(o.actions),N(o.actions,e);const s={card:o.card,actions:o.actions,json:"",destroy:()=>o.destroy(),update:a=>{const f=L(a);o.setSpec(f),o.card.style.opacity=de(f,r.testDefs)?"1":"0.7"}};return w.set(e.id,s),s}function G(e,t){const n=te(re(t,b));if(e.replaceChildren(),e.style.display=n?"flex":"none",!n)return;const o=i.createElement("span");o.textContent=n,e.append(o,d("Use the automatic title","wmapPlotAutoTitle","Replace the title you typed with the one written from the plot\u2019s settings",()=>{const s=l.get().find(f=>f.id===t.id);if(!s)return;const a={...s};delete a.title,l.upsert(a)}))}function B(){const e=l.get();for(const[t,n]of w)e.some(o=>o.id===t)||(n.destroy(),n.card.remove(),w.delete(t));e.forEach((t,n)=>{const o=w.get(t.id)??_(t),s=JSON.stringify(t);o.json!==s&&(o.json=s,o.update(t)),D.children[n]!==o.card&&D.insertBefore(o.card,D.children[n]??null)}),v.style.display=e.length===0?"":"none",P.disabled=e.length===0,P.style.opacity=e.length===0?"0.5":"1",P.style.cursor=e.length===0?"default":"pointer"}const K=l.subscribe(B);B();async function V(){const e=l.get().slice();if(e.length===0)return;const t=e.length;if(!await he({doc:i,anchor:m,title:"Delete all plots",message:t===1?"Delete your 1 saved plot? It is kept on this computer for the next lot, so it will not be there for the next file either. Export plots\u2026 first to keep a copy.":`Delete all ${t} saved plots, sweeps included? They are kept on this computer for the next lot, so they will not be there for the next file either. Export plots\u2026 first to keep a copy.`,confirmLabel:t===1?"Delete 1 plot":`Delete ${t} plots`}))return;const o=l.get().slice();o.length!==0&&(l.replaceAll([]),y(`Deleted ${o.length===1?"1 plot":`all ${o.length} plots`}.`,{label:"Undo",run:()=>l.replaceAll(o)}))}function X(){const e=l.get();if(e.length===0){y("There are no plots to export yet.");return}Pe(ie(e),"wafermap-plots.json","application/json",r.onSaveText)}async function q(){return r.pickPlotsFile?r.pickPlotsFile():new Promise(e=>{const t=i.createElement("input");t.type="file",t.accept=".json,application/json",t.addEventListener("change",()=>{const n=t.files?.[0];if(!n){e(null);return}n.text().then(e,()=>e(null))}),t.addEventListener("cancel",()=>e(null)),t.click()})}async function Q(){const e=await q();if(e===null)return;const t=ae(e);if(t.error){y(`Could not import: ${t.error}`);return}const{plots:n,copies:o}=le(l.get(),t.plots);l.replaceAll(n);const s=[...t.warnings,...o.length?[`Kept as copies, since a plot with the same id already existed: ${o.join(", ")}`]:[]];y(`Imported ${t.plots.length} plot${t.plots.length===1?"":"s"}.`,void 0,s)}return{card:m,destroy:()=>{K(),h!==void 0&&clearTimeout(h);for(const e of w.values())e.destroy();w.clear(),l.flush()}}}