@wafertools/wafermap 0.40.1 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/AGENTS.md +20 -21
  2. package/CHANGELOG.md +140 -0
  3. package/README.md +6 -6
  4. package/dist/packages/canvas-adapter/canvasTheme.d.ts +12 -0
  5. package/dist/packages/canvas-adapter/canvasTheme.js +1 -1
  6. package/dist/packages/canvas-adapter/cellShade.d.ts +2 -2
  7. package/dist/packages/canvas-adapter/cellShade.js +1 -1
  8. package/dist/packages/canvas-adapter/chartPopulation.d.ts +3 -0
  9. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/capability.d.ts +3 -0
  11. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +2 -1
  13. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -1
  14. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +47 -27
  15. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/commonality.js +4 -4
  17. package/dist/packages/canvas-adapter/charts/correlation.d.ts +6 -12
  18. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  19. package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +45 -15
  20. package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -1
  21. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/palette.d.ts +16 -30
  23. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  24. package/dist/packages/canvas-adapter/charts/patCard.js +1 -1
  25. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +24 -1
  26. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  27. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.d.ts +3 -0
  28. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  29. package/dist/packages/canvas-adapter/charts/sweep.d.ts +3 -0
  30. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  31. package/dist/packages/canvas-adapter/chromeRow.d.ts +68 -0
  32. package/dist/packages/canvas-adapter/chromeRow.js +1 -0
  33. package/dist/packages/canvas-adapter/chunked.d.ts +6 -0
  34. package/dist/packages/canvas-adapter/chunked.js +1 -1
  35. package/dist/packages/canvas-adapter/columnFilterPopup.d.ts +25 -0
  36. package/dist/packages/canvas-adapter/columnFilterPopup.js +1 -0
  37. package/dist/packages/canvas-adapter/composePng.d.ts +37 -0
  38. package/dist/packages/canvas-adapter/composePng.js +1 -0
  39. package/dist/packages/canvas-adapter/dataTab.d.ts +27 -0
  40. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  41. package/dist/packages/canvas-adapter/dieList.js +1 -1
  42. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +3 -1
  43. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
  44. package/dist/packages/canvas-adapter/drilldown.d.ts +19 -0
  45. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  46. package/dist/packages/canvas-adapter/filterEditor.d.ts +5 -0
  47. package/dist/packages/canvas-adapter/filterEditor.js +1 -1
  48. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  49. package/dist/packages/canvas-adapter/icons.js +1 -1
  50. package/dist/packages/canvas-adapter/identityHeader.d.ts +5 -0
  51. package/dist/packages/canvas-adapter/identityHeader.js +1 -1
  52. package/dist/packages/canvas-adapter/index.d.ts +7 -0
  53. package/dist/packages/canvas-adapter/index.js +1 -1
  54. package/dist/packages/canvas-adapter/insightsTab.d.ts +23 -5
  55. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  56. package/dist/packages/canvas-adapter/maplessSummary.d.ts +4 -2
  57. package/dist/packages/canvas-adapter/maplessSummary.js +1 -1
  58. package/dist/packages/canvas-adapter/openWaferMode.js +1 -1
  59. package/dist/packages/canvas-adapter/panelChart.d.ts +7 -0
  60. package/dist/packages/canvas-adapter/panelChart.js +1 -0
  61. package/dist/packages/canvas-adapter/panelTable.d.ts +50 -0
  62. package/dist/packages/canvas-adapter/panelTable.js +1 -0
  63. package/dist/packages/canvas-adapter/plotCard.js +1 -1
  64. package/dist/packages/canvas-adapter/plotEditor.d.ts +12 -0
  65. package/dist/packages/canvas-adapter/plotEditor.js +10 -10
  66. package/dist/packages/canvas-adapter/plotItems.d.ts +9 -4
  67. package/dist/packages/canvas-adapter/plotItems.js +1 -1
  68. package/dist/packages/canvas-adapter/plotJsonComplete.js +1 -1
  69. package/dist/packages/canvas-adapter/plotModal.d.ts +7 -0
  70. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  71. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  72. package/dist/packages/canvas-adapter/plotTab.d.ts +59 -1
  73. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  74. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +7 -0
  75. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  76. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +41 -9
  77. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  78. package/dist/packages/canvas-adapter/reportCharts.d.ts +41 -0
  79. package/dist/packages/canvas-adapter/reportCharts.js +1 -0
  80. package/dist/packages/canvas-adapter/reportExport.d.ts +91 -0
  81. package/dist/packages/canvas-adapter/reportExport.js +1 -0
  82. package/dist/packages/canvas-adapter/reportFigures.d.ts +29 -0
  83. package/dist/packages/canvas-adapter/reportFigures.js +1 -0
  84. package/dist/packages/canvas-adapter/reportRun.d.ts +9 -0
  85. package/dist/packages/canvas-adapter/reportRun.js +1 -0
  86. package/dist/packages/canvas-adapter/selectionOverlay.d.ts +12 -0
  87. package/dist/packages/canvas-adapter/selectionOverlay.js +1 -0
  88. package/dist/packages/canvas-adapter/summaryPanel.d.ts +150 -109
  89. package/dist/packages/canvas-adapter/summaryPanel.js +7 -4
  90. package/dist/packages/canvas-adapter/summaryToggle.js +1 -1
  91. package/dist/packages/canvas-adapter/tableDrilldown.d.ts +48 -0
  92. package/dist/packages/canvas-adapter/tableDrilldown.js +1 -0
  93. package/dist/packages/canvas-adapter/tableFilter.d.ts +42 -0
  94. package/dist/packages/canvas-adapter/tableFilter.js +1 -0
  95. package/dist/packages/canvas-adapter/tablePlots.d.ts +85 -0
  96. package/dist/packages/canvas-adapter/tablePlots.js +1 -0
  97. package/dist/packages/canvas-adapter/themeWatch.d.ts +7 -0
  98. package/dist/packages/canvas-adapter/themeWatch.js +1 -0
  99. package/dist/packages/canvas-adapter/toCanvas.d.ts +3 -0
  100. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  101. package/dist/packages/canvas-adapter/toolbar.d.ts +125 -36
  102. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  103. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  104. package/dist/packages/canvas-adapter/userGuideHtml.js +521 -412
  105. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  106. package/dist/packages/canvas-adapter/version.js +1 -1
  107. package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
  108. package/dist/packages/canvas-adapter/virtualTable.d.ts +35 -6
  109. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  110. package/dist/packages/core/aggregates.d.ts +14 -0
  111. package/dist/packages/core/aggregates.js +1 -1
  112. package/dist/packages/core/dies.d.ts +7 -0
  113. package/dist/packages/core/dies.js +1 -1
  114. package/dist/packages/core/utils.d.ts +2 -0
  115. package/dist/packages/core/utils.js +1 -1
  116. package/dist/packages/experimental/charts.d.ts +4 -0
  117. package/dist/packages/experimental/charts.js +1 -0
  118. package/dist/packages/renderer/binColors.d.ts +6 -2
  119. package/dist/packages/renderer/binColors.js +1 -1
  120. package/dist/packages/renderer/buildView.d.ts +36 -14
  121. package/dist/packages/renderer/buildView.js +1 -1
  122. package/dist/packages/renderer/buildWaferMap.d.ts +8 -0
  123. package/dist/packages/renderer/buildWaferMap.js +1 -1
  124. package/dist/packages/renderer/categoryColors.d.ts +3 -0
  125. package/dist/packages/renderer/categoryColors.js +1 -0
  126. package/dist/packages/renderer/colorMap.d.ts +15 -16
  127. package/dist/packages/renderer/colorMap.js +1 -1
  128. package/dist/packages/renderer/colorSchemes.d.ts +34 -30
  129. package/dist/packages/renderer/colorSchemes.js +1 -1
  130. package/dist/packages/renderer/dataColors.d.ts +126 -0
  131. package/dist/packages/renderer/dataColors.js +1 -0
  132. package/dist/packages/renderer/deprecate.js +1 -1
  133. package/dist/packages/renderer/fmt.d.ts +14 -0
  134. package/dist/packages/renderer/fmt.js +1 -1
  135. package/dist/packages/renderer/index.d.ts +2 -0
  136. package/dist/packages/renderer/index.js +1 -1
  137. package/dist/packages/renderer/spec.d.ts +5 -0
  138. package/dist/packages/renderer/spec.js +1 -1
  139. package/dist/packages/renderer/stacks.d.ts +21 -0
  140. package/dist/packages/renderer/stacks.js +1 -0
  141. package/dist/packages/renderer/timeAxis.d.ts +19 -0
  142. package/dist/packages/renderer/timeAxis.js +1 -0
  143. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  144. package/dist/packages/stats/analyzeWaferMap.d.ts +2 -4
  145. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  146. package/dist/packages/stats/binRows.js +1 -1
  147. package/dist/packages/stats/binShifts.d.ts +59 -0
  148. package/dist/packages/stats/binShifts.js +1 -0
  149. package/dist/packages/stats/capability.d.ts +6 -1
  150. package/dist/packages/stats/capability.js +1 -1
  151. package/dist/packages/stats/chartCatalogue.d.ts +3 -0
  152. package/dist/packages/stats/chartCatalogue.js +1 -1
  153. package/dist/packages/stats/clusterDetection.js +1 -1
  154. package/dist/packages/stats/columnPlot.d.ts +38 -0
  155. package/dist/packages/stats/columnPlot.js +1 -0
  156. package/dist/packages/stats/commonality.d.ts +7 -0
  157. package/dist/packages/stats/commonality.js +1 -1
  158. package/dist/packages/stats/correlation.d.ts +7 -2
  159. package/dist/packages/stats/correlation.js +1 -1
  160. package/dist/packages/stats/dataTable.d.ts +44 -0
  161. package/dist/packages/stats/dataTable.js +1 -0
  162. package/dist/packages/stats/dieRegions.js +1 -1
  163. package/dist/packages/stats/facets.d.ts +11 -0
  164. package/dist/packages/stats/facets.js +1 -1
  165. package/dist/packages/stats/filterFindings.d.ts +21 -0
  166. package/dist/packages/stats/filterFindings.js +1 -1
  167. package/dist/packages/stats/math.d.ts +2 -0
  168. package/dist/packages/stats/math.js +1 -1
  169. package/dist/packages/stats/overview.d.ts +114 -0
  170. package/dist/packages/stats/overview.js +1 -0
  171. package/dist/packages/stats/pat.d.ts +0 -2
  172. package/dist/packages/stats/pat.js +1 -1
  173. package/dist/packages/stats/patternClassification.d.ts +20 -3
  174. package/dist/packages/stats/patternClassification.js +1 -1
  175. package/dist/packages/stats/permutationNull.d.ts +16 -0
  176. package/dist/packages/stats/permutationNull.js +1 -0
  177. package/dist/packages/stats/plotData.d.ts +131 -10
  178. package/dist/packages/stats/plotData.js +1 -1
  179. package/dist/packages/stats/plotSpec.d.ts +10 -1
  180. package/dist/packages/stats/plotSpec.js +3 -3
  181. package/dist/packages/stats/plotTable.js +1 -1
  182. package/dist/packages/stats/plotWords.d.ts +52 -0
  183. package/dist/packages/stats/plotWords.js +1 -0
  184. package/dist/packages/stats/presentation.d.ts +63 -14
  185. package/dist/packages/stats/presentation.js +1 -1
  186. package/dist/packages/stats/presentationPresets.d.ts +35 -0
  187. package/dist/packages/stats/presentationPresets.js +1 -0
  188. package/dist/packages/stats/presentationSections.d.ts +83 -0
  189. package/dist/packages/stats/presentationSections.js +1 -0
  190. package/dist/packages/stats/renderSummaryReport.d.ts +80 -2
  191. package/dist/packages/stats/renderSummaryReport.js +1 -67
  192. package/dist/packages/stats/reportBlocks.d.ts +249 -0
  193. package/dist/packages/stats/reportBlocks.js +1 -0
  194. package/dist/packages/stats/reportContents.d.ts +22 -0
  195. package/dist/packages/stats/reportContents.js +1 -0
  196. package/dist/packages/stats/reportDeck.d.ts +245 -0
  197. package/dist/packages/stats/reportDeck.js +212 -0
  198. package/dist/packages/stats/reportHtml.d.ts +44 -43
  199. package/dist/packages/stats/reportHtml.js +82 -46
  200. package/dist/packages/stats/reportMaps.d.ts +67 -0
  201. package/dist/packages/stats/reportMaps.js +1 -0
  202. package/dist/packages/stats/reportSections.d.ts +55 -0
  203. package/dist/packages/stats/reportSections.js +1 -0
  204. package/dist/packages/stats/sweep.d.ts +14 -6
  205. package/dist/packages/stats/sweep.js +1 -1
  206. package/dist/packages/stats/synthesis.d.ts +79 -9
  207. package/dist/packages/stats/synthesis.js +1 -1
  208. package/dist/packages/stats/types.d.ts +22 -0
  209. package/dist/packages/stats/worthItems.d.ts +15 -0
  210. package/dist/packages/stats/worthItems.js +1 -0
  211. package/dist/packages/stats/yield.d.ts +13 -0
  212. package/dist/packages/stats/yield.js +1 -1
  213. package/llms.txt +1 -1
  214. package/package.json +6 -1
@@ -1,3 +1,5 @@
1
+ import { type PngDecor, type PngHeader } from '../composePng.js';
2
+ import type { QuietColors } from './divergingScale.js';
1
3
  import { type OverlayHandle, type SaveImageHandler } from '../toolbar.js';
2
4
  import type { CardAboutLine } from './cardAbout.js';
3
5
  import type { GuideSection } from '../../stats/guideSections.js';
@@ -62,8 +64,14 @@ export declare function withAlpha(color: string, alpha: number): string;
62
64
  * drawing. Call once per draw (not cached) so a live theme change is picked
63
65
  * up on the next redraw, matching `resolveCanvasTheme`'s own contract. */
64
66
  export declare function resolveChartCanvasColors(el: HTMLElement): ChartCanvasColors;
67
+ /** The card and text colours the theme draws with, which pick the form of a data colour scale. */
68
+ export declare function quietOf(el: HTMLElement): QuietColors;
65
69
  export declare const PADDING = 12;
66
70
  export declare const VALUE_WIDTH = 100;
71
+ /** Register how `card` draws itself again with the reader's current data colours. */
72
+ export declare function onRepaint(card: HTMLElement, repaint: () => void): void;
73
+ /** Repaint every registered card under `root`, in place. Returns how many were repainted. */
74
+ export declare function repaintCards(root: ParentNode): number;
67
75
  export declare function observeResize(el: HTMLElement, onResize: () => void): {
68
76
  disconnect: () => void;
69
77
  };
@@ -110,7 +118,7 @@ export declare function growCardToFitContent(card: HTMLElement, body: HTMLElemen
110
118
  */
111
119
  export type WaferContextMenuHandler = (waferIndex: number, testNumber: number | undefined, e: MouseEvent) => void;
112
120
  /** The tooltip line saying a mark has one — one wording on every chart. */
113
- export declare const WAFER_MENU_HINT = "<br><em>right-click to chart this wafer</em>";
121
+ export declare const WAFER_MENU_HINT = "<br><em>right-click: charts for this wafer</em>";
114
122
  /**
115
123
  * How many dies a chart is drawn from, and who they are: "12 dies", "12 dies
116
124
  * selected on W03", or "10 of 12 dies selected on W03 (partial and
@@ -236,37 +244,31 @@ export interface CardContext {
236
244
  * its caption elements (marked `data-wmap-caption`, with instructions to click or drag removed), and its legend.
237
245
  */
238
246
  export declare function describeCard(card: HTMLElement): CardContext;
239
- /** What a saved chart carries besides its canvas: the legend and the statement of what it shows are DOM, not canvas. */
240
- export interface PngDecor {
241
- /** Which test, wafer, group or sort the card's controls are set to ("Test: vth_n_mV · 1001"): a chart saved without them is unlabelled. */
242
- controls?: readonly string[];
243
- /** The population and what was combined or left out, under the title: a line, or several. */
244
- caption?: string | readonly string[];
245
- /** The colour key of a chart coloured by category. */
246
- legend?: ReadonlyArray<{
247
- label: string;
248
- color: string;
249
- }>;
250
- /** The colour key of a chart coloured on a gradient. */
251
- colorbar?: {
252
- label: string;
253
- lo: string;
254
- hi: string;
255
- color: (t: number) => string;
256
- };
247
+ export { composeChartPng, type PngDecor, type PngHeader } from '../composePng.js';
248
+ /**
249
+ * A host's report, as Insights cards see it: whether a chart is in it, and a way to add or remove one. Given, every chart
250
+ * card in Insights has "Add to report" (or "Remove from report") in its ⋯ menu.
251
+ */
252
+ export interface CardReportHook {
253
+ /** Whether the report has this chart, by the catalogue's id for it (`catalogueCardId`). */
254
+ has(cardId: string): boolean;
255
+ /** Adds the chart, or removes it when the report has it. `title` is the card's heading as it is now. */
256
+ toggle(cardId: string, title: string): void;
257
257
  }
258
- export interface PngHeader {
259
- /** The card the chart lives in: its colours are the saved image's, so a dark theme saves a legible dark image. */
260
- card: HTMLElement;
258
+ /** Gives the chart cards inside `root` the host's report row (or takes it away). */
259
+ export declare function setCardReportHook(root: HTMLElement, hook: CardReportHook | undefined): void;
260
+ /** A card's chart canvas: its first canvas that is not a colour key (a heatmap's key strip comes before its chart). */
261
+ export declare function chartCanvasOf(card: HTMLElement): HTMLCanvasElement | null;
262
+ /** A chart card's picture, as its Save as PNG makes it. */
263
+ export interface CardPicture {
261
264
  title: string;
262
- decor?: PngDecor;
265
+ canvas: HTMLCanvasElement;
263
266
  }
264
267
  /**
265
- * The canvas as it is saved: under a header that names the chart, states what it shows, and carries the legend.
266
- * A bare canvas saved with none of these is a picture of unlabelled marks: the title, the population ("6 wafers · 3,966
267
- * dies"), and the key to the colours live in the card around the canvas, not in it.
268
+ * The picture a chart card's Save as PNG saves, made now from the card as it is: for a writer that shows charts (a
269
+ * report). Undefined for a card with nothing to save (a table, a panel saved with its grid).
268
270
  */
269
- export declare function composeChartPng(canvas: HTMLCanvasElement, header?: PngHeader): HTMLCanvasElement;
271
+ export declare function cardPicture(card: HTMLElement): CardPicture | undefined;
270
272
  export declare function saveCanvasPng(canvas: HTMLCanvasElement, filenameStem: string, onSaveImage?: SaveImageHandler, header?: PngHeader): void;
271
273
  export interface CardShell {
272
274
  card: HTMLElement;
@@ -282,6 +284,11 @@ export interface CardShell {
282
284
  setAbout(line: CardAboutLine | undefined): void;
283
285
  /** Rows of the card's own in its ⋯ menu, after Save as PNG (Edit as plot). Read each time the menu opens. */
284
286
  setMenuRows(read: () => CardMenuRow[]): void;
287
+ /**
288
+ * The card's stable id (`data-wmap-card-id`): what a saved choice of cards (a report's contents) names it by. A plot card's
289
+ * is its plot's id; a built-in card that is not a plot has `cardKindId(kind)`. Never renamed once released.
290
+ */
291
+ setCardId(id: string): void;
285
292
  }
286
293
  /** A row of a card's own in its ⋯ menu: an action, or one greyed with the reason it cannot run now. */
287
294
  export interface CardMenuRow {
@@ -289,9 +296,22 @@ export interface CardMenuRow {
289
296
  onClick: () => void;
290
297
  disabledHint?: string;
291
298
  }
299
+ /** Which of a card's own chrome is drawn. Every part is drawn unless it is set to false. */
300
+ export interface CardChrome {
301
+ /** The title row's text. */
302
+ title?: boolean;
303
+ /** The ⋯ menu (save as PNG, save or copy data, about this chart). */
304
+ menu?: boolean;
305
+ /** The expand button. */
306
+ expand?: boolean;
307
+ /** The card's own border, background and padding: false leaves the chart on whatever is behind it. */
308
+ frame?: boolean;
309
+ }
292
310
  export interface CardShellOptions {
293
311
  /** Default true. False for a card whose image is saved by something else (a panel of a grid, saved with the grid). */
294
312
  png?: boolean;
313
+ /** Which of the card's chrome to draw; all of it when absent. */
314
+ chrome?: CardChrome;
295
315
  }
296
316
  /**
297
317
  * THE colour chip that stands for a data series, everywhere in the chart suite.
@@ -1 +1 @@
1
- import{SHADOW as te,LEADING as me,wireTooltip as z,wireControlHover as P,controlStyle as X,SPACE as C,RADIUS as B,fontPx as q,FONT as L,CLR as b,Z_BASE as he,menuLayerFor as ge,wireListNavigation as be,MENU_SEARCH_THRESHOLD as ne,makeMenuSearchBox as xe,markMenuTrigger as V,markNoPrint as G,openCommandMenu as ye,saveImageBlob as we,openReparentedModal as Ce}from"../toolbar.js";import{ICONS as oe}from"../icons.js";import{openGuideAt as ve}from"../guideWindow.js";import{minOf as Se,maxOf as ke}from"../../core/utils.js";import{robustFence as ie}from"../../stats/math.js";import{fmt as Ae,fmtColorbarAxis as Ee,nameStatesUnit as Le}from"../../renderer/fmt.js";import{isTestPinned as $e,toggleTestPinned as Be}from"../pinnedTests.js";import{markedTestLabel as Te,DERIVED_LANE_PAD as Oe}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=Ce([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:Re[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const c=Number(e.dataset.wmapChartFullH);if(!c)return;const d=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(d+c)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const Re={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const c=s[1].length===3?s[1].split("").map(d=>d+d).join(""):s[1];[i,n,r]=[0,2,4].map(d=>parseInt(c.slice(d,d+2),16)),c.length===8&&(l=parseInt(c.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Pe={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},re={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(re)){const n=o.getPropertyValue(`--wmap-${re[i]}`).trim();t[i]=n||Pe[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${K(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function K(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function le(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(K(e,o)-l)-(t?le(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(K(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=le(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${q(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:Ae(e,void 0,"engineering"):"\u2014"}function Me(e,o){const t=`${o} (`;return e.startsWith(t)&&e.endsWith(")")?e.slice(t.length,-1):""}export function makeAxisFormat(e,o,t,i){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const n=Le(i,o),{tickFmt:r,axisLabel:l,scaledUnit:s}=Ee(e,n?i:null,o,"engineering",t);return{tick:r,tickWithUnit:s?a=>`${r(a)} ${s}`:r,unitLabel:n?Me(l,i):l}}const Ie=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+Ie}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${q(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const U=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Fe=/\s*[▾▼]\s*$/,Y=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!U(l,t))continue;const s=(l.textContent??"").replace(Fe,"").trim();if(!s)continue;const a=l.closest("label"),d=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(d&&d!==s?`${d}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!U(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!U(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!U(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}const r=Y.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function He(e){const o=describeCard(e),t=Y.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function se(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ae=new WeakSet;function je(e){if(ae.has(e))return;ae.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>se(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&se(e)})}catch{}}function De(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(m,f="400")=>`${f} ${m*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,c=(m,f)=>l?(l.font=f,l.measureText(m).width):m.length*7*n,d=[];let p=0;if(o){p=s,d.push({kind:"text",text:o.title,x:s,y:p+14*n,font:a(16,"600"),alpha:1}),p+=24*n;const m=o.decor,f=[];m?.controls?.length&&f.push({text:m.controls.join(" \xB7 "),alpha:1});for(const w of m?.caption===void 0?[]:typeof m.caption=="string"?[m.caption]:m.caption)f.push({text:w,alpha:.75});const g=a(12);for(const{text:w,alpha:y}of f){let h="";for(const k of w.split(" ")){const T=h?`${h} ${k}`:k;h&&c(T,g)>r-2*s?(d.push({kind:"text",text:h,x:s,y:p+11*n,font:g,alpha:y}),p+=17*n,h=k):h=T}h&&(d.push({kind:"text",text:h,x:s,y:p+11*n,font:g,alpha:y}),p+=17*n)}if(m?.legend?.length){p+=4*n;const w=a(12);let y=s;for(const h of m.legend){const k=14*n+c(h.label,w)+14*n;y>s&&y+k>r-s&&(y=s,p+=18*n),d.push({kind:"dot",x:y+5*n,y:p+7*n,r:5*n,color:h.color}),d.push({kind:"text",text:h.label,x:y+14*n,y:p+11*n,font:w,alpha:1}),y+=k}p+=20*n}if(m?.colorbar){p+=4*n;const w=a(12),y=m.colorbar;let h=s;d.push({kind:"text",text:y.label,x:h,y:p+10*n,font:w,alpha:1}),h+=c(y.label,w)+10*n,d.push({kind:"text",text:y.lo,x:h,y:p+10*n,font:w,alpha:.75}),h+=c(y.lo,w)+6*n,d.push({kind:"strip",x:h,y:p+1*n,w:200*n,h:10*n,color:y.color}),h+=206*n,d.push({kind:"text",text:y.hi,x:h,y:p+10*n,font:w,alpha:.75}),p+=20*n}p+=6*n}i.width=r,i.height=Math.ceil(e.height+p);const u=i.getContext("2d");if(u.fillStyle=o?De(o.card):"#ffffff",u.fillRect(0,0,i.width,i.height),o){const m=t.defaultView,f=m&&m.getComputedStyle(o.card).color||"#222222";u.textBaseline="alphabetic";for(const g of d)if(g.kind==="text")u.font=g.font,u.fillStyle=f,u.globalAlpha=g.alpha,u.fillText(g.text,g.x,g.y),u.globalAlpha=1;else if(g.kind==="dot")u.fillStyle=g.color,u.beginPath(),u.arc(g.x,g.y,g.r,0,Math.PI*2),u.fill();else for(let w=0;w<g.w;w++)u.fillStyle=g.color(w/Math.max(1,g.w-1)),u.fillRect(g.x+w,g.y,1,g.h)}return u.drawImage(e,0,p),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&we(n,o,t)},"image/png")}const ce="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${ce}`,`height:${ce}`,`border-radius:${B.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ne="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:C.xs,padding:`${C.xs} ${C.md}`,borderRadius:B.pill,border:`1px solid ${b.menuBorder}`,background:"none",cursor:"pointer",fontSize:L.body,color:b.text,whiteSpace:"nowrap"}),P(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?b.iconActive:b.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ne:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:B.container,padding:C.xl,fontVariantNumeric:"tabular-nums"}}function de(e){Object.assign(e.style,{...X("outlined"),color:b.label,padding:"0",width:"22px",height:"22px",lineHeight:me.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),P(e)}export function pairCards(e,o=document){const t=o.createElement("div");t.dataset.wmapCardPair="1",Object.assign(t.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1 1 0"});const i=e.map(l=>l.card.style.display),n=[],r=l=>{e.forEach((s,a)=>{s.card.style.display=a===l?i[a]:"none"});for(const s of n)s.setValue(String(l))};return e.forEach((l,s)=>{const a=[...l.card.children].find(d=>d.querySelector("[data-wmap-card-expand]")),c=makeSegmented(e.map((d,p)=>[String(p),d.label]),String(s),d=>{r(Number(d))},o);n.push(c),c.dataset.wmapCardView="1",a?.firstElementChild&&a.firstElementChild.after(c),t.appendChild(l.card)}),r(0),t}export function cardShell(e,o,t=document,i={}){const n=t.createElement("div");n.dataset.wmapChartCard="1",n.dataset.wmapChartTitle=e,Object.assign(n.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=n.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:C.sm,paddingBottom:"6px",marginBottom:C.md,borderBottom:`1px solid ${b.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:b.value,fontSize:L.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=oe.expand,a.dataset.wmapCardExpand="1",de(a),attachChartTip(a,n,s,"Expand"),G(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const c=n.ownerDocument.createElement("button");c.type="button",c.setAttribute("aria-label","Chart actions"),c.innerHTML=oe.more,c.dataset.wmapCardMenu="1",de(c),attachChartTip(c,n,s,"Chart actions"),V(c,!1),G(c),r.appendChild(c);const d=n.ownerDocument.createElement("div");d.dataset.wmapCardAbout="1",d.setAttribute("role","note"),Object.assign(d.style,{display:"none",color:b.label,fontSize:L.body,marginBottom:C.md}),G(d);let p;const u=v=>{d.textContent=v?p?.text??"":"",d.style.display=v?"":"none"};let m,f;const g=()=>{const v=m?m():n.querySelector("canvas");v&&saveCanvasPng(v,l.textContent||e,o,{card:n,title:l.textContent||e,decor:He(n)})},w=()=>{const v=[],j=(S,D,N)=>({label:S,active:!1,action:!0,enabled:!N,disabledHint:N,onClick:()=>{y?.(),D()}});i.png!==!1&&(m||n.querySelector("canvas"))&&v.push(j("Save as PNG",g));for(const S of f?.()??[])v.push(j(S.label,S.onClick,S.disabledHint));if(p){const S=d.style.display!=="none";v.push({label:`About this ${p.noun}`,active:S,onClick:()=>{y?.(),u(!S)}})}return v};let y;c.addEventListener("click",()=>{if(c.getAttribute("aria-expanded")==="true"){y?.();return}const v=w();v.length!==0&&(y=ye(c.getBoundingClientRect(),c,v,`${l.textContent||e}: chart actions`,{trigger:c,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(d);const h=n.ownerDocument.createElement("div");h.dataset.wmapPrintOnly="1",Object.assign(h.style,{display:"none",color:b.label,fontSize:L.body,marginBottom:C.sm}),n.appendChild(h),je(n.ownerDocument);const k=n.ownerDocument.createElement("div");k.dataset.wmapControls="1",Object.assign(k.style,{display:"flex",gap:C.sm,marginBottom:C.md,flexWrap:"wrap",alignItems:"center"}),G(k),n.appendChild(k);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:k,body:T,setPngDecor:v=>{Y.set(n,v)},setPngCanvas:v=>{m=v},setAbout:v=>{p=v,u(!!v&&d.style.display!=="none")},setMenuRows:v=>{f=v}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,pe(e,o)," in the user guide"),i}function pe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:b.iconActive,textDecoration:"underline",cursor:"pointer"}),P(t),t.addEventListener("click",()=>ve(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(pe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:b.menuBg,color:b.text,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,padding:`${C.xs} ${C.sm}`,fontSize:L.body,fontFamily:L.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,o,t,i=document,n=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const l=e.length-1,s=`seg-${Math.random().toString(36).slice(2,9)}`,a=[],c=[];return e.forEach(([d,p,u],m)=>{const f=i.createElement("label");u&&z(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:L.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${b.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:m===0?B.control:"0",borderBottomLeftRadius:m===0?B.control:"0",borderTopRightRadius:m===l?B.control:"0",borderBottomRightRadius:m===l?B.control:"0"}),P(f,"bare");const g=i.createElement("input");g.type="radio",g.name=s,g.value=d,g.checked=d===o,c.push(g),Object.assign(g.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const w=()=>{f.style.background=g.checked?b.bgActive:b.menuBg,f.style.color=g.checked?b.iconActive:b.text,f.dataset.on=g.checked?"true":"false"};a.push(w),w(),g.addEventListener("change",()=>{if(g.checked){for(const y of a)y();t(d)}}),f.append(g,i.createTextNode(p)),r.appendChild(f)}),Object.assign(r,{setValue(d){for(const p of c)p.checked=p.value===d;for(const p of a)p()}})}const We=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{...X("outlined"),marginTop:C.sm}),P(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${We}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{...X("outlined"),background:b.menuBg,color:b.label}),P(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:b.label,fontSize:L.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:c}=i,d=()=>typeof e=="function"?e():e;let p=d(),u=o;const m=S=>p.find(D=>D.value===S)?.label??"",f=r.createElement("button");f.type="button",c&&(f.dataset.wmapSelect=c),l&&f.setAttribute("aria-label",l),Object.assign(f.style,{fontSize:L.body,padding:`${C.xxs} ${C.sm}`,background:b.menuBg,color:b.text,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:C.sm,justifyContent:"space-between"}),P(f),V(f,!1);const g=r.createElement("span");Object.assign(g.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const w=r.createElement("span");w.textContent="\u25BE",w.style.flex="0 0 auto",f.append(g,w);const y=()=>{g.textContent=p.length===0?s??"(none)":m(u)||s||"(none)"};if(y(),p.length===0)return f.disabled=!0,f.style.opacity="0.6",f.style.cursor="default",Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}});let h=null;const k=()=>{h&&(h.remove(),h=null,V(f,!1))},T=()=>{k(),f.focus()};function v(){p=d();const S=f.getBoundingClientRect(),D=r.defaultView??window,N=Math.max(S.width,220),ue=Math.min(S.left,Math.max(4,(D.innerWidth??1/0)-N-4));h=r.createElement("div"),h.setAttribute("role","listbox"),h.setAttribute("aria-label",l??"Options"),Object.assign(h.style,{position:"fixed",top:`${S.bottom+4}px`,left:`${ue}px`,background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,boxShadow:te.menu,zIndex:he,minWidth:`${N}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const M=[],_=()=>M.filter(x=>x.row.style.display!=="none").map(x=>x.row),W=[],fe=()=>{for(const x of W)x.el.style.display=M.slice(x.first,x.last+1).some(E=>E.row.style.display!=="none")?"":"none"};if(p.length>ne){const x=xe(E=>{for(const A of M)A.row.style.display=A.label.includes(E)?"":"none";fe()},a,r,_);Object.assign(x.style,{position:"sticky",top:"0",zIndex:"1",background:b.menuBg}),x.addEventListener("keydown",E=>{if(E.key==="Escape"){E.preventDefault(),T();return}E.key==="ArrowDown"&&(E.preventDefault(),_()[0]?.focus())}),h.appendChild(x)}let Z;for(const x of p){if(x.group!==void 0&&x.group!==Z){const $=r.createElement("div");$.textContent=x.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${C.sm} ${C.xl} ${C.xxs}`,fontSize:L.sub,color:b.label,fontWeight:"600"}),h.appendChild($),W.push({el:$,first:M.length,last:M.length})}Z=x.group;const E=x.value===u,A=r.createElement("div"),J=r.createElement("span");if(J.textContent=x.disabled?`${x.label} \u2014 ${x.disabled}`:x.label,A.appendChild(J),A.setAttribute("role","option"),A.setAttribute("aria-selected",E?"true":"false"),x.disabled&&A.setAttribute("aria-disabled","true"),A.tabIndex=-1,Object.assign(A.style,{padding:`${C.sm} ${C.xl}`,fontSize:L.body,cursor:x.disabled?"default":"pointer",color:x.disabled?b.label:E?b.iconActive:b.text,fontWeight:E?"700":"400",opacity:x.disabled?"0.7":"",background:E?b.menuActive:"transparent",whiteSpace:"nowrap",...x.pin?{display:"flex",alignItems:"center",justifyContent:"space-between",gap:C.xl}:{}}),x.pin){const $=x.pin;A.setAttribute("aria-keyshortcuts","P");const O=r.createElement("span"),Q="http://www.w3.org/2000/svg",I=r.createElementNS(Q,"svg");I.setAttribute("viewBox","0 0 24 24"),I.setAttribute("width","14"),I.setAttribute("height","14"),I.setAttribute("aria-hidden","true");const F=r.createElementNS(Q,"path");F.setAttribute("d","M12 2.5l2.9 6.2 6.8.8-5 4.7 1.3 6.7L12 17.5 6 20.9l1.3-6.7-5-4.7 6.8-.8z"),F.setAttribute("fill",$.pinned?"currentColor":"none"),F.setAttribute("stroke","currentColor"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linejoin","round"),I.appendChild(F),O.appendChild(I),O.dataset.wmapPin=$.pinned?"pinned":"unpinned",O.setAttribute("role","button"),O.setAttribute("aria-label",`${$.pinned?"Unpin":"Pin"} ${x.label} (or press P on the row)`),Object.assign(O.style,{cursor:"pointer",color:$.pinned?b.iconActive:b.label,flex:"0 0 auto",padding:`0 ${C.xs}`,display:"inline-flex",alignItems:"center"}),P(O,"bare"),z(O,$.pinned?"Unpin this test":"Pin this test to the top of every test list");const ee=R=>{R.preventDefault(),R.stopPropagation(),k(),$.toggle(),v()};O.addEventListener("click",ee),A.addEventListener("keydown",R=>{(R.key==="p"||R.key==="P")&&!R.ctrlKey&&!R.metaKey&&!R.altKey&&ee(R)}),A.appendChild(O)}A.addEventListener("mouseenter",()=>{!E&&!x.disabled&&(A.style.background=b.menuHover)}),A.addEventListener("mouseleave",()=>{E||(A.style.background="transparent")}),A.addEventListener("click",$=>{$.stopPropagation(),!x.disabled&&(u=x.value,y(),T(),t(x.value))}),h.appendChild(A),M.push({row:A,label:x.label.toLowerCase()}),W.length&&(W[W.length-1].last=M.length-1)}if(be(h,_,T),ge(f).appendChild(h),V(f,!0),p.length<=ne){const x=p.findIndex(E=>E.value===u);_()[x>=0?x:0]?.focus()}}f.addEventListener("click",S=>{if(S.stopPropagation(),h){k();return}v()});const j=S=>{if(!f.isConnected){r.removeEventListener("click",j);return}h&&!h.contains(S.target)&&!f.contains(S.target)&&k()};return r.addEventListener("click",j),Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?Oe:"")+Te(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i,s=testOptionLabels(e);return makeListSelect(()=>{const c=e.map((u,m)=>({item:u,label:s[m],pinned:$e(u.testNumber)})),d=c.some(u=>u.pinned),p=(u,m)=>({value:String(u.item.testNumber),label:u.label,...m?{group:m}:{},pin:{pinned:u.pinned,toggle:()=>Be(u.item.testNumber)}});return d?[...c.filter(u=>u.pinned).map(u=>p(u,"Pinned")),...c.filter(u=>!u.pinned).map(u=>p(u,"All tests"))]:c.map(u=>p(u))},o!==null?String(o):"",c=>t(Number(c)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,c,d=!1){e.innerHTML="",d&&e.appendChild(makeLimitsSelect(l,p=>{l=p,s()},i)),c&&e.appendChild(makeToggle("Axis includes limits",a,p=>{n=p,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,p=>{r=p,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const c=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&c===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=c,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=d=>d??ALL_GROUPS,s=d=>d===ALL_GROUPS?null:d,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(d=>({value:d,label:d}))],l(r),d=>{const p=s(d);p!==r&&(r=p,i(p))},{...n,hook:"group-scope"}),c=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(d){return r===d||d!==null&&!e.includes(d)?!1:(r=d,c&&(c.value=l(d)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,c)=>({value:String(c),label:a.label??`#${c}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.xs,fontSize:L.body,color:b.label,cursor:"pointer",userSelect:"none"}),P(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&z(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document,hint:a}=n,c=s.createElement("label");c.textContent=e,Object.assign(c.style,{color:b.label,fontSize:L.body,display:"flex",alignItems:"center",gap:C.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return c.appendChild(d),a&&z(c,a),c}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(var(--wmap-insights-cols, auto-fit), minmax(var(--wmap-insights-min, 420px), 1fr))",gap:C.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:B.control,padding:`${C.sm} ${C.xl}`,fontSize:L.sub,fontFamily:L.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:te.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let c=t-n.left+r,d=i-n.top+r;c+s+l>n.width&&(c=t-n.left-r-s),d+a+l>n.height&&(d=i-n.top-r-a),c=Math.max(l,c),d=Math.max(l,d),e.style.left=`${c}px`,e.style.top=`${d}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function H(e,o){const[t,i]=o==="test"?[e?.limitLow,e?.limitHigh]:o==="spec"?[e?.specLow,e?.specHigh]:o==="pat"?[e?.patLow,e?.patHigh]:o==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],n=[];return t!==void 0&&Number.isFinite(t)&&n.push({value:t,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),i!==void 0&&Number.isFinite(i)&&n.push({value:i,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),n}export function hasBothLimitKinds(e){return H(e,"test").length>0&&H(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=H(e,"test"),i=H(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...H(e,"pat"),...H(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:Se(o),hi:ke(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{ie as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,c=0;if(r&&l?.length){const p=ie(l);if(p){const u=Math.max(s,p.lo),m=Math.min(a,p.hi);m>u&&(c=l.filter(f=>Number.isFinite(f)&&(f<u||f>m)).length,s=u,a=m)}}if(n)for(const p of i)s=Math.min(s,p.value),a=Math.max(a,p.value);s===a&&(s-=1,a+=1);const d=[];for(const p of i)p.value<s?d.push({value:p.value,label:p.label,side:"lo"}):p.value>a&&d.push({value:p.value,label:p.label,side:"hi"});return{lo:s,hi:a,offAxis:d,clippedCount:c}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function limitLabelPlacement(e,o,t,i,n,r,l=[],s=3){const a=r?-1:1;for(const c of[a,-a])for(const d of o){const p=t(d),u=c<0?e-s-p:e+s,m=c<0?e-s:e+s+p;if(!(u<i||m>n)&&!l.some(f=>f>u&&f<m))return{text:d,side:c}}return{text:o[0],side:limitLabelSide(e,t(o[0]),i,n,r,s)}}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${q(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},c=q(-1)+2;for(const{value:d,label:p,side:u}of o){const m=a[u]++*c,f=i==="horizontal"?u==="lo"?"\u2190":"\u2192":u==="lo"?"\u2193":"\u2191",g=u==="lo"?`${f} ${p} ${r(d)}`:`${p} ${r(d)} ${f}`,w=e.measureText(g).width;if(i==="horizontal"){const y=u==="lo"?t.left+2:t.right-2-w,h={x0:y,x1:y+w,y0:t.top+2+m,y1:t.top+2+m+c},k=s?placeClearOf(s,h,c):h;e.textBaseline="top",e.textAlign=u==="lo"?"left":"right",fillTextOnHalo(e,g,u==="lo"?t.left+2:t.right-2,k.y0,l)}else{const y=u==="lo"?t.bottom-2-m-c:t.top+2+m,h={x0:t.left+4,x1:t.left+4+w,y0:y,y1:y+c},k=s?placeClearOf(s,h,u==="lo"?-c:c):h;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,g,t.left+4,k.y0,l)}}e.restore()}
1
+ import{composeChartPng as ie}from"../composePng.js";import{ALPHA as re,SHADOW as se,LEADING as Ce,wireTooltip as V,wireControlHover as I,controlStyle as Y,SPACE as x,RADIUS as O,fontPx as G,FONT as k,CLR as h,Z_BASE as ve,menuLayerFor as Se,wireListNavigation as Ae,MENU_SEARCH_THRESHOLD as ae,makeMenuSearchBox as ke,markMenuTrigger as U,markNoPrint as X,openCommandMenu as Le,saveImageBlob as le,openReparentedModal as Ee}from"../toolbar.js";import{ICONS as ce}from"../icons.js";import{openGuideAt as $e}from"../guideWindow.js";import{catalogueCardId as Be}from"../../stats/reportSections.js";import{minOf as Oe,maxOf as Te}from"../../core/utils.js";import{robustFence as de}from"../../stats/math.js";import{fmt as Re,fmtColorbarAxis as Pe,nameStatesUnit as Ie}from"../../renderer/fmt.js";import{isTestPinned as Me,toggleTestPinned as He}from"../pinnedTests.js";import{markedTestLabel as je,DERIVED_LANE_PAD as We}from"../../renderer/testLabel.js";export function openChartExpandModal(e,n,t={}){for(const l of e.querySelectorAll('div[style*="position: absolute"]'))l.style.display==="block"&&l.style.pointerEvents==="none"&&(l.style.display="none");const i=e.getAttribute("style")??"",o=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),s=l=>{r&&(r.style.display=l?"flex":"none")};s(!1);const a=Ee([e],{title:n,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:Fe[o],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),s(!0),t.onClosed?.()}});if(!a)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),s(!0),null;if(o==="plot"&&(a.contentWrap.style.overflowY="auto"),o==="rows"){const l=()=>{const c=Number(e.dataset.wmapChartFullH);if(!c)return;const d=a.box.offsetHeight-a.contentWrap.clientHeight;a.setNaturalHeight(`min(90vh, ${Math.ceil(d+c)}px)`)};l(),(e.ownerDocument.defaultView??window).requestAnimationFrame(l)}return a}const Fe={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,n){const t=e.trim();let i,o,r,s=1;const a=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),l=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(a){const c=a[1].length===3?a[1].split("").map(d=>d+d).join(""):a[1];[i,o,r]=[0,2,4].map(d=>parseInt(c.slice(d,d+2),16)),c.length===8&&(s=parseInt(c.slice(6,8),16)/255)}else if(l)[i,o,r]=[l[1],l[2],l[3]].map(Number),l[4]!==void 0&&(s=l[4].endsWith("%")?parseFloat(l[4])/100:Number(l[4]));else return e;return`rgba(${i}, ${o}, ${r}, ${+(s*n).toFixed(3)})`}const Ne={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},pe={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const n=getComputedStyle(e),t={};for(const i of Object.keys(pe)){const o=n.getPropertyValue(`--wmap-${pe[i]}`).trim();t[i]=o||Ne[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export function quietOf(e){const n=resolveChartCanvasColors(e);return{card:n.bg,text:n.text}}export const PADDING=12,VALUE_WIDTH=100;const ue=new WeakMap,fe="data-wmap-repaints";export function onRepaint(e,n){ue.set(e,n),e.setAttribute(fe,"")}export function repaintCards(e){let n=0;for(const t of Array.from(e.querySelectorAll(`[${fe}]`))){const i=ue.get(t);i&&(i(),n++)}return n}export function observeResize(e,n){const t=e.ownerDocument.defaultView??window;let i=0;const o=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,n()}))});return o.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,o.disconnect()}}}export function growCardToFitContent(e,n,t){const i=`${Z(e,n)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function Z(e,n){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let o=0;for(const r of Array.from(e.children)){if(r===n)continue;const s=r,a=t.getComputedStyle(s);a.display==="none"||a.position==="absolute"||a.position==="fixed"||(o+=s.offsetHeight+(parseFloat(a.marginTop)||0)+(parseFloat(a.marginBottom)||0))}return i.boxSizing==="border-box"&&(o+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),o}function me(e,n){const t=e.ownerDocument.defaultView??window;let i=0;for(const o of Array.from(e.children)){if(o===n)continue;const r=o,s=t.getComputedStyle(r);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(i+=r.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click: charts for this wafer</em>";export function populationPhrase(e,n,t){const i=e.toLocaleString(),o=e===1?"die":"dies";return t?e===n?`${i} ${o} ${t}`:`${i} of ${n.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${o}`}export function setChartGrow(e,n){e.dataset.wmapChartGrow=n}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,n,t){const o=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(o.paddingTop)||0)-(parseFloat(o.paddingBottom)||0),s=o.boxSizing==="border-box"?(parseFloat(o.paddingTop)||0)+(parseFloat(o.paddingBottom)||0)+(parseFloat(o.borderTopWidth)||0)+(parseFloat(o.borderBottomWidth)||0):0;return r-(Z(e,n)-s)-(t?me(n,t):0)}export function fitRowsHeight(e,n,t,i,o=0){if(growCardToFitContent(e,n,o+t),e.dataset.wmapChartFullH=String(Math.ceil(Z(e,n)+o+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,n)-o;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,n,t,i){const o=me(n,t);return growCardToFitContent(e,n,o+i),Math.max(i,n.clientHeight-o)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,n,t,i){const o=chartDpr(e);e.width=Math.max(1,Math.floor(t*o)),e.height=Math.max(1,Math.floor(i*o)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(o,0,0,o,0,0),r.clearRect(0,0,t,i),r.font=`${G(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(n)}):null}export function applyCanvasFlow(e,n=0){let t;if(typeof n=="number")t=n;else{const i=(n.ownerDocument.defaultView??window).getComputedStyle(n);t=n.offsetTop+n.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:Re(e,void 0,"engineering"):"\u2014"}function De(e,n){const t=`${n} (`;return e.startsWith(t)&&e.endsWith(")")?e.slice(t.length,-1):""}export function makeAxisFormat(e,n,t,i){if(!n&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const o=Ie(i,n),{tickFmt:r,axisLabel:s,scaledUnit:a}=Pe(e,o?i:null,n,"engineering",t);return{tick:r,tickWithUnit:a?l=>`${r(l)} ${a}`:r,unitLabel:o?De(s,i):s}}const _e=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,n,t){return(i,o)=>{const r=makeAxisFormat(n,t,i).tick;return o.reduce((s,a)=>Math.max(s,e.measureText(r(a)).width),0)+_e}}export function drawAxisUnit(e,n,t,i,o){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${G(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=o,e.fillText(`(${n})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(n=>n.replace(/[\s·]+$/,"").trim()).filter(n=>n&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(n)&&!/\(.*(click|drag).*\)/i.test(n)).join(" \xB7 ")}const K=(e,n)=>{for(let t=e;t&&t!==n.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},ze=/\s*[▾▼]\s*$/,J=new WeakMap;export function describeCard(e){const n=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const s of t.querySelectorAll("button[aria-haspopup]")){if(!K(s,t))continue;const a=(s.textContent??"").replace(ze,"").trim();if(!a)continue;const l=s.closest("label"),d=(l?(l.textContent??"").replace(s.textContent??"","").replace(/[:\s]+$/,"").trim():"")||s.getAttribute("aria-label")||"";n.push(d&&d!==a?`${d}: ${a}`:a)}for(const s of t.querySelectorAll('[role="radiogroup"]')){if(!K(s,t))continue;const l=s.querySelector("input:checked")?.closest("label")?.textContent?.trim();l&&n.push(l)}for(const s of t.querySelectorAll('input[type="checkbox"]:checked')){if(!K(s,t))continue;const a=s.closest("label")?.textContent?.trim();a&&n.push(a)}}const i=[];for(const s of e.querySelectorAll("[data-wmap-caption]")){if(!K(s,e))continue;const a=captionText((s.textContent??"").replace(/\s+/g," ").trim());a&&i.push(a)}const o=[];for(const s of e.querySelectorAll("button[aria-pressed]")){const a=s.querySelector("span"),l=a?.style.backgroundColor||a?.style.borderColor,c=(s.textContent??"").trim();c&&l&&l!=="transparent"&&o.push({label:c,color:l})}for(const s of e.querySelectorAll("[data-wmap-legend] > span")){const a=s.firstElementChild,l=a?.style.backgroundColor||a?.style.borderColor,c=(s.textContent??"").trim();c&&l&&l!=="transparent"&&o.push({label:c,color:l})}const r=J.get(e)?.();return r&&(r.controls&&n.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(o.length=0,o.push(...r.legend))),{controls:n,captions:i,legend:o}}function qe(e){const n=describeCard(e),t=J.get(e)?.();return{controls:n.controls,caption:n.captions,legend:n.legend.length?n.legend:void 0,colorbar:t?.colorbar}}function he(e){for(const n of e.querySelectorAll("[data-wmap-chart-card]")){const t=n.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(n);t.replaceChildren();const o=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of o){const s=e.createElement("div");s.textContent=r,t.appendChild(s)}for(const r of n.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ge=new WeakSet;function Ve(e){if(ge.has(e))return;ge.add(e);const n=e.createElement("style");n.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(n);const t=e.defaultView;t?.addEventListener("beforeprint",()=>he(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&he(e)})}catch{}}export{composeChartPng}from"../composePng.js";const Q=new WeakMap;export function setCardReportHook(e,n){n?(Q.set(e,n),e.dataset.wmapReportScope="1"):(Q.delete(e),delete e.dataset.wmapReportScope)}export function chartCanvasOf(e){return e.querySelector("canvas:not([data-wmap-key])")}const be=new WeakMap;export function cardPicture(e){return be.get(e)?.()}export function saveCanvasPng(e,n,t,i){ie(e,i).toBlob(o=>{o&&le(o,n,t)},"image/png")}const xe="10px";export function chartSwatchCss(e,n="solid"){return["display:inline-block",`width:${xe}`,`height:${xe}`,`border-radius:${O.pill}`,`background:${n==="outline"?"transparent":e}`,`border:1px ${n==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ge="0.35";export function makeSeriesLegendItem(e,n,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:x.xs,padding:`${x.xs} ${x.md}`,borderRadius:O.pill,border:`1px solid ${h.menuBorder}`,background:"none",cursor:"pointer",fontSize:k.body,color:h.text,whiteSpace:"nowrap"}),I(i,"bare");const o=t.createElement("span");return o.style.cssText=chartSwatchCss(n),i.append(o,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:s}){i.style.borderColor=r?h.iconActive:h.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=s?Ge:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:O.container,padding:x.xl,fontVariantNumeric:"tabular-nums"}}function ye(e){Object.assign(e.style,{...Y("outlined"),color:h.label,padding:"0",width:"22px",height:"22px",lineHeight:Ce.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),I(e)}export function pairCards(e,n=document){const t=n.createElement("div");t.dataset.wmapCardPair="1",Object.assign(t.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1 1 0"});const i=e.map(s=>s.card.style.display),o=[],r=s=>{e.forEach((a,l)=>{a.card.style.display=l===s?i[l]:"none"});for(const a of o)a.setValue(String(s))};return e.forEach((s,a)=>{const l=[...s.card.children].find(d=>d.querySelector("[data-wmap-card-expand]")),c=makeSegmented(e.map((d,p)=>[String(p),d.label]),String(a),d=>{r(Number(d))},n);o.push(c),c.dataset.wmapCardView="1",l?.firstElementChild&&l.firstElementChild.after(c),t.appendChild(s.card)}),r(0),t}export function cardShell(e,n,t=document,i={}){const o=t.createElement("div");o.dataset.wmapChartCard="1",o.dataset.wmapChartTitle=e,Object.assign(o.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=o.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:x.sm,paddingBottom:"6px",marginBottom:x.md,borderBottom:`1px solid ${h.menuBorder}`});const s=o.ownerDocument.createElement("div");s.textContent=e,Object.assign(s.style,{color:h.value,fontSize:k.heading,fontWeight:"600",flex:"1"}),r.appendChild(s);const a=makeTooltip(o),l=o.ownerDocument.createElement("button");l.type="button",l.setAttribute("aria-label","Expand"),l.innerHTML=ce.expand,l.dataset.wmapCardExpand="1",ye(l),attachChartTip(l,o,a,"Expand"),X(l),l.addEventListener("click",()=>{isExpandedCard(o)||openChartExpandModal(o,s.textContent??e)}),r.appendChild(l);const c=o.ownerDocument.createElement("button");c.type="button",c.setAttribute("aria-label","Chart actions"),c.innerHTML=ce.more,c.dataset.wmapCardMenu="1",ye(c),attachChartTip(c,o,a,"Chart actions"),U(c,!1),X(c),r.appendChild(c);const d=o.ownerDocument.createElement("div");d.dataset.wmapCardAbout="1",d.setAttribute("role","note"),Object.assign(d.style,{display:"none",color:h.label,fontSize:k.body,marginBottom:x.md}),X(d);let p;const u=f=>{d.textContent=f?p?.text??"":"",d.style.display=f?"":"none"};let b,m;const w=()=>{const f=b?b():chartCanvasOf(o);if(!f)return;const S=s.textContent||e;return{title:S,canvas:ie(f,{card:o,title:S,decor:qe(o)})}};i.png!==!1&&be.set(o,w);const $=()=>{const f=w();f?.canvas.toBlob(S=>{S&&le(S,f.title,n)},"image/png")},L=()=>{const f=[],S=(A,F,q)=>({label:A,active:!1,action:!0,enabled:!q,disabledHint:q,onClick:()=>{y?.(),F()}});i.png!==!1&&(b||chartCanvasOf(o))&&f.push(S("Save as PNG",$));for(const A of m?.()??[])f.push(S(A.label,A.onClick,A.disabledHint));const H=o.closest("[data-wmap-report-scope]"),W=H?Q.get(H):void 0,T=o.dataset.wmapCardId;if(W&&T&&i.png!==!1&&(b||chartCanvasOf(o))){const A=Be(T);f.push(S(W.has(A)?"Remove from report":"Add to report",()=>W.toggle(A,s.textContent||e)))}if(p){const A=d.style.display!=="none";f.push({label:`About this ${p.noun}`,active:A,onClick:()=>{y?.(),u(!A)}})}return f};let y;c.addEventListener("click",()=>{if(c.getAttribute("aria-expanded")==="true"){y?.();return}const f=L();f.length!==0&&(y=Le(c.getBoundingClientRect(),c,f,`${s.textContent||e}: chart actions`,{trigger:c,hook:"wmapCardMenuList"}))});const B=i.chrome;if(B){const{title:f,expand:S,menu:H,frame:W}=B;f===!1&&(s.style.display="none"),S===!1&&(l.style.display="none"),H===!1&&(c.style.display="none"),f===!1&&S===!1&&H===!1?r.style.display="none":f===!1&&Object.assign(r.style,{justifyContent:"flex-end",borderBottom:"none",paddingBottom:"0",marginBottom:x.xs}),W===!1&&Object.assign(o.style,{background:"transparent",border:"none",borderRadius:"0",padding:"0"})}o.appendChild(r),o.appendChild(d);const j=o.ownerDocument.createElement("div");j.dataset.wmapPrintOnly="1",Object.assign(j.style,{display:"none",color:h.label,fontSize:k.body,marginBottom:x.sm}),o.appendChild(j),Ve(o.ownerDocument);const M=o.ownerDocument.createElement("div");M.dataset.wmapControls="1",Object.assign(M.style,{display:"flex",gap:x.sm,marginBottom:x.md,flexWrap:"wrap",alignItems:"center"}),X(M),o.appendChild(M);const N=o.ownerDocument.createElement("div");return Object.assign(N.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),o.appendChild(N),{card:o,heading:s,controlsRow:M,body:N,setPngDecor:f=>{J.set(o,f)},setPngCanvas:f=>{b=f},setAbout:f=>{p=f,u(!!f&&d.style.display!=="none")},setCardId:f=>{o.dataset.wmapCardId=f},setMenuRows:f=>{m=f}}}export function guideCite(e,n,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,we(e,n)," in the user guide"),i}function we(e,n){const t=e.createElement("button");return t.type="button",t.textContent=n.title,t.dataset.wmapGuideLink=n.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:h.iconActive,textDecoration:"underline",cursor:"pointer"}),I(t),t.addEventListener("click",()=>$e(n.id,t)),t}export function appendGuideCites(e,n){if(n.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),n.forEach((i,o)=>{o>0&&e.append(o===n.length-1?" and ":", "),e.append(we(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:h.menuBg,color:h.text,border:`1px solid ${h.menuBorder}`,borderRadius:O.control,padding:`${x.xs} ${x.sm}`,fontSize:k.body,fontFamily:k.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,n,t,i=document,o=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const s=e.length-1,a=`seg-${Math.random().toString(36).slice(2,9)}`,l=[],c=[];return e.forEach(([d,p,u],b)=>{const m=i.createElement("label");u&&V(m,u),Object.assign(m.style,{display:"inline-flex",alignItems:"center",fontSize:k.body,padding:o?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${h.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:b===0?O.control:"0",borderBottomLeftRadius:b===0?O.control:"0",borderTopRightRadius:b===s?O.control:"0",borderBottomRightRadius:b===s?O.control:"0"}),I(m,"bare");const w=i.createElement("input");w.type="radio",w.name=a,w.value=d,w.checked=d===n,c.push(w),Object.assign(w.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const $=()=>{m.style.background=w.checked?h.bgActive:h.menuBg,m.style.color=w.checked?h.iconActive:h.text,m.dataset.on=w.checked?"true":"false"};l.push($),$(),w.addEventListener("change",()=>{if(w.checked){for(const L of l)L();t(d)}}),m.append(w,i.createTextNode(p)),r.appendChild(m)}),Object.assign(r,{setValue(d){for(const p of c)p.checked=p.value===d;for(const p of l)p()}})}const Ue=360;export function firstRowsToggle(e,n){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{...Y("outlined"),marginTop:x.sm}),I(i);const o=()=>{n.fill(t),Object.assign(n.scroller.style,{maxHeight:t?`${Ue}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${n.noun}`:`Show all ${n.total} ${n.noun}`,i.style.display=n.total>n.first?"":"none"};return i.addEventListener("click",()=>{t=!t,o()}),o(),i}export function makeBackButton(e,n=document){const t=n.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{...Y("outlined"),background:h.menuBg,color:h.label}),I(t),t.addEventListener("click",e),t}export function renderEmptyState(e,n,t){const i=e.ownerDocument.createElement("div");i.textContent=n,Object.assign(i.style,{color:h.label,fontSize:k.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,n,t,i={}){const{maxWidth:o="200px",ownerDocument:r=document,ariaLabel:s,emptyText:a,searchPlaceholder:l="Filter\u2026",hook:c}=i,d=()=>typeof e=="function"?e():e;let p=d(),u=n;const b=f=>p.find(S=>S.value===f)?.label??"",m=r.createElement("button");m.type="button",c&&(m.dataset.wmapSelect=c),s&&m.setAttribute("aria-label",s),Object.assign(m.style,{fontSize:k.body,padding:`${x.xxs} ${x.sm}`,background:h.menuBg,color:h.text,border:`1px solid ${h.menuBorder}`,borderRadius:O.control,maxWidth:o,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:x.sm,justifyContent:"space-between"}),I(m),U(m,!1);const w=r.createElement("span");Object.assign(w.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const $=r.createElement("span");$.textContent="\u25BE",$.style.flex="0 0 auto",m.append(w,$);const L=()=>{w.textContent=p.length===0?a??"(none)":b(u)||a||"(none)"};if(L(),p.length===0)return m.disabled=!0,m.style.opacity=re.disabled,m.style.cursor="default",Object.defineProperty(m,"value",{get:()=>u,set:f=>{u=f,L()}});let y=null;const B=()=>{y&&(y.remove(),y=null,U(m,!1))},j=()=>{B(),m.focus()};function M(){p=d();const f=m.getBoundingClientRect(),S=r.defaultView??window,H=Math.max(f.width,220),W=Math.min(f.left,Math.max(4,(S.innerWidth??1/0)-H-4));y=r.createElement("div"),y.setAttribute("role","listbox"),y.setAttribute("aria-label",s??"Options"),Object.assign(y.style,{position:"fixed",top:`${f.bottom+4}px`,left:`${W}px`,background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:O.control,boxShadow:se.menu,zIndex:ve,minWidth:`${H}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const T=[],A=()=>T.filter(g=>g.row.style.display!=="none").map(g=>g.row),F=[],q=()=>{for(const g of F)g.el.style.display=T.slice(g.first,g.last+1).some(v=>v.row.style.display!=="none")?"":"none"};if(p.length>ae){const g=ke(v=>{for(const C of T)C.row.style.display=C.label.includes(v)?"":"none";q()},l,r,A);Object.assign(g.style,{position:"sticky",top:"0",zIndex:"1",background:h.menuBg}),g.addEventListener("keydown",v=>{if(v.key==="Escape"){v.preventDefault(),j();return}v.key==="ArrowDown"&&(v.preventDefault(),A()[0]?.focus())}),y.appendChild(g)}let ee;for(const g of p){if(g.group!==void 0&&g.group!==ee){const E=r.createElement("div");E.textContent=g.group,E.setAttribute("role","presentation"),Object.assign(E.style,{padding:`${x.sm} ${x.xl} ${x.xxs}`,fontSize:k.sub,color:h.label,fontWeight:"600"}),y.appendChild(E),F.push({el:E,first:T.length,last:T.length})}ee=g.group;const v=g.value===u,C=r.createElement("div"),te=r.createElement("span");if(te.textContent=g.disabled?`${g.label} \u2014 ${g.disabled}`:g.label,C.appendChild(te),C.setAttribute("role","option"),C.setAttribute("aria-selected",v?"true":"false"),g.disabled&&C.setAttribute("aria-disabled","true"),C.tabIndex=-1,Object.assign(C.style,{padding:`${x.sm} ${x.xl}`,fontSize:k.body,cursor:g.disabled?"default":"pointer",color:g.disabled?h.label:v?h.iconActive:h.text,fontWeight:v?"700":"400",opacity:g.disabled?re.disabled:"",background:v?h.menuActive:"transparent",whiteSpace:"nowrap",...g.pin?{display:"flex",alignItems:"center",justifyContent:"space-between",gap:x.xl}:{}}),g.pin){const E=g.pin;C.setAttribute("aria-keyshortcuts","P");const R=r.createElement("span"),ne="http://www.w3.org/2000/svg",D=r.createElementNS(ne,"svg");D.setAttribute("viewBox","0 0 24 24"),D.setAttribute("width","14"),D.setAttribute("height","14"),D.setAttribute("aria-hidden","true");const _=r.createElementNS(ne,"path");_.setAttribute("d","M12 2.5l2.9 6.2 6.8.8-5 4.7 1.3 6.7L12 17.5 6 20.9l1.3-6.7-5-4.7 6.8-.8z"),_.setAttribute("fill",E.pinned?"currentColor":"none"),_.setAttribute("stroke","currentColor"),_.setAttribute("stroke-width","2"),_.setAttribute("stroke-linejoin","round"),D.appendChild(_),R.appendChild(D),R.dataset.wmapPin=E.pinned?"pinned":"unpinned",R.setAttribute("role","button"),R.setAttribute("aria-label",`${E.pinned?"Unpin":"Pin"} ${g.label} (or press P on the row)`),Object.assign(R.style,{cursor:"pointer",color:E.pinned?h.iconActive:h.label,flex:"0 0 auto",padding:`0 ${x.xs}`,display:"inline-flex",alignItems:"center"}),I(R,"bare"),V(R,E.pinned?"Unpin this test":"Pin this test to the top of every test list");const oe=P=>{P.preventDefault(),P.stopPropagation(),B(),E.toggle(),M()};R.addEventListener("click",oe),C.addEventListener("keydown",P=>{(P.key==="p"||P.key==="P")&&!P.ctrlKey&&!P.metaKey&&!P.altKey&&oe(P)}),C.appendChild(R)}C.addEventListener("mouseenter",()=>{!v&&!g.disabled&&(C.style.background=h.menuHover)}),C.addEventListener("mouseleave",()=>{v||(C.style.background="transparent")}),C.addEventListener("click",E=>{E.stopPropagation(),!g.disabled&&(u=g.value,L(),j(),t(g.value))}),y.appendChild(C),T.push({row:C,label:g.label.toLowerCase()}),F.length&&(F[F.length-1].last=T.length-1)}if(Ae(y,A,j),Se(m).appendChild(y),U(m,!0),p.length<=ae){const g=p.findIndex(v=>v.value===u);A()[g>=0?g:0]?.focus()}}m.addEventListener("click",f=>{if(f.stopPropagation(),y){B();return}M()});const N=f=>{if(!m.isConnected){r.removeEventListener("click",N);return}y&&!y.contains(f.target)&&!m.contains(f.target)&&B()};return r.addEventListener("click",N),Object.defineProperty(m,"value",{get:()=>u,set:f=>{u=f,L()}})}export function testOptionLabels(e){const n=e.some(t=>t.derived);return e.map(t=>(n&&!t.derived?We:"")+je(t,t.testNumber))}export function makeTestSelect(e,n,t,i={}){const{maxWidth:o="200px",emptyText:r="No parametric tests",ownerDocument:s=document}=i,a=testOptionLabels(e);return makeListSelect(()=>{const c=e.map((u,b)=>({item:u,label:a[b],pinned:Me(u.testNumber)})),d=c.some(u=>u.pinned),p=(u,b)=>({value:String(u.item.testNumber),label:u.label,...b?{group:b}:{},pin:{pinned:u.pinned,toggle:()=>He(u.item.testNumber)}});return d?[...c.filter(u=>u.pinned).map(u=>p(u,"Pinned")),...c.filter(u=>!u.pinned).map(u=>p(u,"All tests"))]:c.map(u=>p(u))},n!==null?String(n):"",c=>t(Number(c)),{maxWidth:o,ownerDocument:s,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,n,t,i=document){let o=n?.includeLimits,r=n?.clipOutliers??!1,s=n?.limits??"both";const a=()=>t({includeLimits:o,clipOutliers:r,limits:s});return{get:()=>({includeLimits:o,clipOutliers:r,limits:s}),sync(l,c,d=!1){e.innerHTML="",d&&e.appendChild(makeLimitsSelect(s,p=>{s=p,a()},i)),c&&e.appendChild(makeToggle("Axis includes limits",l,p=>{o=p,a()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,p=>{r=p,a()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(l){const c=l.limits??"both";return l.includeLimits===o&&l.clipOutliers===r&&c===s?!1:(o=l.includeLimits,r=l.clipOutliers,s=c,!0)}}}export function makeLinkedTestSelect(e,n,t,i={}){let o=n;const r=makeTestSelect(e,o,s=>{s!==o&&(o=s,t(s))},i);return{el:r,get:()=>o,set(s){return o===s||!e.some(a=>a.testNumber===s)?!1:(o=s,r.value=String(s),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,n,t,i,o={}){let r=t;const s=d=>d??ALL_GROUPS,a=d=>d===ALL_GROUPS?null:d,l=makeLabeledSelect(n,[{value:ALL_GROUPS,label:"All groups"},...e.map(d=>({value:d,label:d}))],s(r),d=>{const p=a(d);p!==r&&(r=p,i(p))},{...o,hook:"group-scope"}),c=l.querySelector('[data-wmap-select="group-scope"]');return{el:l,get:()=>r,set(d){return r===d||d!==null&&!e.includes(d)?!1:(r=d,c&&(c.value=s(d)),!0)}}}export function makeWaferSelect(e,n,t,i={}){const{maxWidth:o="160px",allLabel:r="All wafers",ownerDocument:s=document}=i,a="\0all";return makeListSelect([{value:a,label:r},...e.map((l,c)=>({value:String(c),label:l.label??`#${c}`}))],n===null?a:String(n),l=>t(l===a?null:Number(l)),{maxWidth:o,ownerDocument:s,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,n,t,i=document,o){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:x.xs,fontSize:k.body,color:h.label,cursor:"pointer",userSelect:"none"}),I(r,"bare");const s=i.createElement("input");return s.type="checkbox",s.checked=n,s.style.cssText="margin:0;cursor:pointer;",s.addEventListener("change",()=>t(s.checked)),r.append(s,i.createTextNode(e)),o&&V(r,o),r}export function makeLabeledSelect(e,n,t,i,o={}){const{maxWidth:r="160px",hook:s,ownerDocument:a=document,hint:l}=o,c=a.createElement("label");c.textContent=e,Object.assign(c.style,{color:h.label,fontSize:k.body,display:"flex",alignItems:"center",gap:x.xs});const d=makeListSelect(n,t,i,{maxWidth:r,ownerDocument:a,hook:s,ariaLabel:e.replace(/:\s*$/,"")});return c.appendChild(d),l&&V(c,l),c}export function makeChartGridWrap(e=document){const n=e.createElement("div");return n.dataset.wmapChartGrid="1",Object.assign(n.style,{display:"grid",gridTemplateColumns:"repeat(var(--wmap-insights-cols, auto-fit), minmax(var(--wmap-insights-min, 420px), 1fr))",gap:x.lg,flex:"0 0 auto"}),n}export function makeTooltip(e){const n=e.ownerDocument.createElement("div");return Object.assign(n.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:O.control,padding:`${x.sm} ${x.xl}`,fontSize:k.sub,fontFamily:k.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:se.menu}),e.appendChild(n),n}export function attachChartTip(e,n,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",o=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,n,o.clientX,o.clientY)}),e.addEventListener("mousemove",o=>{t.style.display==="block"&&positionChartTooltip(t,n,o.clientX,o.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const o=e.getBoundingClientRect();positionChartTooltip(t,n,o.left+o.width/2,o.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,n,t,i){const o=n.getBoundingClientRect(),r=14,s=4;e.style.left="0",e.style.top="0";const a=e.offsetWidth,l=e.offsetHeight;let c=t-o.left+r,d=i-o.top+r;c+a+s>o.width&&(c=t-o.left-r-a),d+l+s>o.height&&(d=i-o.top-r-l),c=Math.max(s,c),d=Math.max(s,d),e.style.left=`${c}px`,e.style.top=`${d}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function z(e,n){const[t,i]=n==="test"?[e?.limitLow,e?.limitHigh]:n==="spec"?[e?.specLow,e?.specHigh]:n==="pat"?[e?.patLow,e?.patHigh]:n==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],o=[];return t!==void 0&&Number.isFinite(t)&&o.push({value:t,kind:n,end:"lo",label:LIMIT_LABEL[n].lo}),i!==void 0&&Number.isFinite(i)&&o.push({value:i,kind:n,end:"hi",label:LIMIT_LABEL[n].hi}),o}export function hasBothLimitKinds(e){return z(e,"test").length>0&&z(e,"spec").length>0}export function limitLines(e,n="both"){if(n==="none")return[];const t=z(e,"test"),i=z(e,"spec"),o=n==="test"?t:n==="spec"?i:[...t,...i];return[...o.length?o:[...t,...i],...z(e,"pat"),...z(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const n=e.map(t=>t.value);return{lo:Oe(n),hi:Te(n)}}export function placeClearOf(e,n,t,i=6){const o=s=>e.some(a=>s.x0<a.x1&&s.x1>a.x0&&s.y0<a.y1&&s.y1>a.y0);let r=n;for(let s=0;s<i&&o(r);s++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,n=4){const t=e.map((r,s)=>({...r,i:s})).sort((r,s)=>r.start-s.start),i=[],o=new Array(e.length).fill(0);for(const r of t){let s=i.findIndex(a=>r.start>=a+n);s===-1?(s=i.length,i.push(r.end)):i[s]=r.end,o[r.i]=s}return o}export function fillTextOnHalo(e,n,t,i,o){if(o){const r=e.measureText(n),s=2,a=e.fillStyle;e.fillStyle=o,e.fillRect(t-r.actualBoundingBoxLeft-s,i-r.actualBoundingBoxAscent-s,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*s,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*s),e.fillStyle=a}e.fillText(n,t,i)}export function strokeLimitLine(e,n,t,i,o,r,s){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[n.kind]),e.beginPath(),e.moveTo(i,o),e.lineTo(r,s),e.stroke(),e.restore()}export function makeLimitsSelect(e,n,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>n(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{de as robustFence};export function shouldIncludeLimitsByDefault(e,n,t,i,o=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(n))return!1;const r=Math.min(e,t??e),a=Math.max(n,i??n)-r;if(a<=0)return!0;const l=n-e;return l===0?!0:l/a>=o}export function resolveAxisRange(e){const{dataMin:n,dataMax:t,limits:i=[],includeLimits:o,clipOutliers:r,values:s}=e;let a=n,l=t,c=0;if(r&&s?.length){const p=de(s);if(p){const u=Math.max(a,p.lo),b=Math.min(l,p.hi);b>u&&(c=s.filter(m=>Number.isFinite(m)&&(m<u||m>b)).length,a=u,l=b)}}if(o)for(const p of i)a=Math.min(a,p.value),l=Math.max(l,p.value);a===l&&(a-=1,l+=1);const d=[];for(const p of i)p.value<a?d.push({value:p.value,label:p.label,side:"lo"}):p.value>l&&d.push({value:p.value,label:p.label,side:"hi"});return{lo:a,hi:l,offAxis:d,clippedCount:c}}export function limitLabelSide(e,n,t,i,o,r=3){const s=o?-1:1;return(s<0?e-r-n>=t:e+r+n<=i)?s:-s}export function limitLabelPlacement(e,n,t,i,o,r,s=[],a=3){const l=r?-1:1;for(const c of[l,-l])for(const d of n){const p=t(d),u=c<0?e-a-p:e+a,b=c<0?e-a:e+a+p;if(!(u<i||b>o)&&!s.some(m=>m>u&&m<b))return{text:d,side:c}}return{text:n[0],side:limitLabelSide(e,t(n[0]),i,o,r,a)}}export function drawOffAxisLimits(e,n,t,i,o,r,s,a){if(!n.length)return;e.save(),e.fillStyle=o,e.font=`${G(-1)}px system-ui, sans-serif`;const l={lo:0,hi:0},c=G(-1)+2;for(const{value:d,label:p,side:u}of n){const b=l[u]++*c,m=i==="horizontal"?u==="lo"?"\u2190":"\u2192":u==="lo"?"\u2193":"\u2191",w=u==="lo"?`${m} ${p} ${r(d)}`:`${p} ${r(d)} ${m}`,$=e.measureText(w).width;if(i==="horizontal"){const L=u==="lo"?t.left+2:t.right-2-$,y={x0:L,x1:L+$,y0:t.top+2+b,y1:t.top+2+b+c},B=a?placeClearOf(a,y,c):y;e.textBaseline="top",e.textAlign=u==="lo"?"left":"right",fillTextOnHalo(e,w,u==="lo"?t.left+2:t.right-2,B.y0,s)}else{const L=u==="lo"?t.bottom-2-b-c:t.top+2+b,y={x0:t.left+4,x1:t.left+4+$,y0:L,y1:L+c},B=a?placeClearOf(a,y,u==="lo"?-c:c):y;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,w,t.left+4,B.y0,s)}}e.restore()}
@@ -1,4 +1,4 @@
1
- import{rankCommonality as se,measureLabel as V,groupCommonalityRows as ae,commonalityConfidence as X,CONFIDENCE_LABEL as ie}from"../../stats/commonality.js";import{formatP as I}from"../../stats/groupCompare.js";import{maxGroups as re}from"../../stats/groupEffects.js";import{CLR as m,FONT as N,RADIUS as le,SPACE as c,controlStyle as Y,wireControlHover as z,wireTooltip as g}from"../toolbar.js";import{shortfallShade as de}from"../cellShade.js";import{cardShell as ce,firstRowsToggle as pe,guideCite as me,renderEmptyState as fe}from"./chartShell.js";import{GUIDE_SECTIONS as he}from"../../stats/guideSections.js";import{cardAbout as ue}from"./cardAbout.js";const J=8,we=5,be=110;export function renderCommonalityPanel(f){const s=f.ownerDocument??document,{card:$,body:E,setAbout:K}=ce("What divides yield",void 0,s);K(ue("commonality")),$.dataset.wmapCommonality="1",$.style.gridColumn="1 / -1",$.style.flex="0 0 auto";const p=se(f.wafers,f.fields,f.curation);if(f.fields.length===0||p.rows.length===0)return fe(E,f.fields.length===0?"No wafer field divides these wafers, so there is nothing to compare.":"No wafer field has two groups of two or more wafers, so there is nothing to compare."),{card:$,destroy:()=>{}};const B=ae(p.rows,p.tied),v=e=>`${e.slice(0,-1).map(t=>t.label).join(", ")}${e.length>1?" and ":""}${e[e.length-1].label}`,T=s.createElement("div"),R=[`Each wafer field, compared for yield and for the ${p.bins.length} most common fail bin${p.bins.length===1?"":"s"}, with each wafer as one value. The clearest fields come first. A clear difference is more than wafer-to-wafer noise; it does not say why.`];p.overlapping.length&&R.push(`These fields nearly match, so the wafers cannot fully tell them apart: ${p.overlapping.map(e=>`${v(e.fields)} and ${v(e.with)} put ${e.agree} of ${e.of} wafers in the same groups`).join("; ")}.`),p.untestable.length&&R.push(`Not compared: ${p.untestable.map(e=>e.label).join(", ")}. A field is compared when two of its groups have two wafers or more and it has no more than ${re(f.wafers.length)} groups.`),T.textContent=R.join(" "),Object.assign(T.style,{color:m.label,fontSize:N.body,marginBottom:c.xs}),E.appendChild(T);const W=s.createElement("details"),j=s.createElement("summary");j.textContent="How to read this",Object.assign(j.style,{cursor:"pointer"}),z(j,"bare");const G=s.createElement("div");G.textContent=`Clear means q is under 0.05 and possible under 0.2, where q is Welch\u2019s p adjusted for the ${p.rows.length} comparisons in the table (Benjamini\u2013Hochberg). Hover a word for the p-values. Each field is read after allowing for the strongest other field that explains the same measure and does not contain it, and its row says so. The bars show the worst (in bold) and the best group\u2019s mean, filled from zero on a scale of 0 to 100%; hover a bar for its group\u2019s median, spread and wafers. `,G.append(me(s,he.dividesYield),"."),W.append(j,G),Object.assign(W.style,{color:m.label,fontSize:N.body,marginBottom:c.sm}),E.appendChild(W);const O=s.createElement("table");Object.assign(O.style,{borderCollapse:"collapse",width:"100%",fontSize:N.body,fontVariantNumeric:"tabular-nums"});const D=s.createElement("tr"),S=(e,t)=>{const n=s.createElement("th");n.scope="col",n.textContent=e,t&&g(n,t),Object.assign(n.style,{textAlign:"left",padding:`${c.xs} ${c.sm}`,borderBottom:`1px solid ${m.menuBorder}`,color:m.label,fontWeight:"600",whiteSpace:"nowrap"}),D.appendChild(n)};S("Field"),S("Effect","The worst and the best group\u2019s mean over their wafers, and how far apart they are"),S("Confidence","Whether the groups differ by more than wafer-to-wafer noise: clear (q under 0.05), possible (under 0.2), or not clear"),S("");const H=s.createElement("thead");H.appendChild(D),O.appendChild(H);const L=s.createElement("tbody");O.appendChild(L);const y=(e,t,n={})=>{const o=s.createElement("td");return typeof t=="string"?o.textContent=t:o.appendChild(t),n.title&&g(o,n.title),n.shade&&(o.style.background=n.shade),Object.assign(o.style,{padding:`${c.xs} ${c.sm}`,textAlign:"left",borderBottom:`1px solid ${m.menuBorder}`,verticalAlign:"top",fontWeight:n.strong?"700":"400"}),e.appendChild(o),o},A=e=>`${e.toFixed(1)}%`,M=e=>`${e.toFixed(1)} pts`,_=(e,t)=>t.comparison.groups.find(n=>n.key===e)?.n??0,Q=e=>e.comparison.groups.filter(t=>!e.comparison.tooSmall.includes(t.key)&&Number.isFinite(t.mean)),Z=e=>{if(e.measure.kind!=="yield")return;const t=e.comparison.groups.filter(o=>Number.isFinite(o.mean)&&o.n>0),n=t.reduce((o,r)=>o+r.n,0);return n>0?de(e.worst.mean-t.reduce((o,r)=>o+r.mean*r.n,0)/n):void 0},ee=e=>{const t=e.measure.kind==="yield"?`${e.worst.key} is ${M(e.spread)} below ${e.best.key}`:`${V(e.measure)} is ${M(e.spread)} higher in ${e.worst.key} than in ${e.best.key}`,[n,o]=[_(e.worst.key,e),_(e.best.key,e)];return Math.min(n,o)<we?`${t} (${n} vs ${o} wafers)`:t},te=e=>{const t=Q(e),n=100,o=s.createElement("div");Object.assign(o.style,{display:"flex",flexDirection:"column",gap:"2px",flex:"0 0 auto"});const r=(i,l)=>{const b=s.createElement("div");b.dataset.wmapBar=l,Object.assign(b.style,{display:"flex",alignItems:"center",gap:c.sm});const a=s.createElement("span");a.textContent=i.key,Object.assign(a.style,{width:"72px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:m.label,fontWeight:l==="worst"?"700":"400"});const d=s.createElement("div");Object.assign(d.style,{width:`${be}px`,height:"10px",border:`1px solid ${m.label}`,boxSizing:"border-box",flex:"0 0 auto"});const C=s.createElement("div");Object.assign(C.style,{width:`${Math.max(0,Math.min(100,i.mean/n*100)).toFixed(1)}%`,height:"100%",background:m.label}),d.appendChild(C);const k=s.createElement("span");return k.textContent=A(i.mean),Object.assign(k.style,{width:"52px",textAlign:"right"}),b.append(a,d,k),g(b,[`${i.key}${l==="worst"?" (worst group)":" (best group)"}`,`mean ${A(i.mean)} \xB7 median ${A(i.median)}`,Number.isFinite(i.sd)?`standard deviation ${i.sd.toFixed(1)} pts between wafers`:"",`${i.n} wafer${i.n===1?"":"s"}`].filter(Boolean).join(`
2
- `)),b},u=t.find(i=>i.key===e.worst.key),w=t.find(i=>i.key===e.best.key);u&&o.appendChild(r(u,"worst")),w&&o.appendChild(r(w,"best"));const h=t.filter(i=>i!==u&&i!==w);if(h.length){const i=s.createElement("div");i.textContent=`+ ${h.length} other group${h.length===1?"":"s"}`,Object.assign(i.style,{color:m.label}),g(i,h.map(l=>`${l.key}: ${A(l.mean)} (${l.n} wafer${l.n===1?"":"s"})`).join(`
3
- `)),o.appendChild(i)}return o},ne=e=>{const t=e.adjusted??e.comparison,n=t.kruskal;return[`q ${I(e.pAdjusted)} \xB7 Welch p ${I(t.welch?.p??NaN)} \xB7 rank p ${I(n?.p??NaN)}${n?.approximate?"* (approximate: fewer than five wafers in a group)":""}`,t.issue].filter(Boolean).join(`
4
- `)},x=new Set;let q=!1;const P=(e,t,n)=>{const o=s.createElement("tr");o.dataset.wmapCommonalityRow=n?"field":"measure";const r=s.createElement("div");if(n){const a=s.createElement("div");a.textContent=v(t.fields),a.style.fontWeight="600",t.fields.length>1&&g(a,"These fields group the wafers identically, so the wafers cannot tell them apart: one row stands for all of them."),r.appendChild(a)}const u=s.createElement("div");if(u.textContent=V(e.measure)+(e.allowedFor?`, allowing for ${e.allowedFor.map(a=>a.label).join(", ")}`:""),Object.assign(u.style,{color:m.label,paddingLeft:n?"0":c.md}),e.allowedFor&&g(u,`Read after allowing for ${e.allowedFor.map(a=>a.label).join(", ")}: each wafer's value less its ${e.allowedFor.length===1?"group\u2019s":"groups\u2019"} mean on ${e.allowedFor.length===1?"that field":"those fields"}, so a difference the other field explains does not hide this one. The bars and the points are the measure's own means.`),r.appendChild(u),n&&t.others.length){const a=t.others.filter(k=>X(k.pAdjusted)!=="none").length,d=s.createElement("button");d.type="button",d.dataset.wmapCommonalityMore=t.field.key;const C=x.has(t.field.key);d.setAttribute("aria-expanded",String(C)),d.textContent=C?"Hide other measures":a?`+${a} other measure${a===1?"":"s"} ${a===1?"differs":"differ"}`:`${t.others.length} other measure${t.others.length===1?"":"s"}`,Object.assign(d.style,{...Y("outlined"),marginTop:c.xs,fontSize:N.body}),z(d),d.addEventListener("click",()=>{x.has(t.field.key)?x.delete(t.field.key):x.add(t.field.key),U(q)}),r.appendChild(d)}y(o,r);const w=s.createElement("div");Object.assign(w.style,{display:"flex",alignItems:"flex-start",gap:c.md});const h=s.createElement("span");h.textContent=ee(e);const i=Z(e);i&&Object.assign(h.style,{background:i,padding:`0 ${c.xs}`,borderRadius:le.control}),h.dataset.wmapSentence="1",w.append(te(e),h),y(o,w);const l=X(e.pAdjusted),b=y(o,ie[l],{strong:l==="clear",title:ne(e)});if(b.dataset.wmapConfidence=l,n)if(t.fields.some(a=>a.key===f.groupedBy))y(o,"Grouped by this");else{const a=s.createElement("button");a.type="button",a.textContent="Group by",a.dataset.wmapCommonalityGroup=t.field.key,g(a,`Group Insights by ${t.field.label}, so every chart compares its groups${t.fields.length>1?`; ${v(t.fields.slice(1))} give the same groups`:""}`),Object.assign(a.style,Y("outlined")),z(a),a.addEventListener("click",()=>f.onGroupBy(t.field.key)),y(o,a)}else y(o,"");L.appendChild(o)};function U(e){q=e,L.replaceChildren();for(const t of e?B:B.slice(0,J))if(P(t.primary,t,!0),x.has(t.field.key))for(const n of t.others)P(n,t,!1)}const F=s.createElement("div");Object.assign(F.style,{overflowX:"auto"}),F.appendChild(O);const oe=pe(s,{total:B.length,first:J,noun:"rows",scroller:F,fill:U});return E.append(F,oe),{card:$,destroy:()=>{}}}
1
+ import{QUANTITY_BAR as oe}from"../panelTable.js";import{rankCommonality as ne,measureLabel as se,groupCommonalityRows as ae,commonalityConfidence as P,commonalityFieldNames as ie,commonalitySentence as re,CONFIDENCE_LABEL as le}from"../../stats/commonality.js";import{formatP as G}from"../../stats/groupCompare.js";import{maxGroups as de}from"../../stats/groupEffects.js";import{CLR as h,FONT as N,RADIUS as ce,SPACE as c,controlStyle as U,wireControlHover as H,wireTooltip as b}from"../toolbar.js";import{shortfallShade as me}from"../cellShade.js";import{cardShell as pe,firstRowsToggle as fe,guideCite as he,renderEmptyState as ue}from"./chartShell.js";import{GUIDE_SECTIONS as we}from"../../stats/guideSections.js";import{cardAbout as ge,cardKindId as be}from"./cardAbout.js";const Y=8,ye=110;export function renderCommonalityPanel(p){const o=p.ownerDocument??document,{card:x,body:v,setAbout:K,setCardId:Q}=pe("What divides yield",void 0,o);Q(be("commonality")),K(ge("commonality")),x.dataset.wmapCommonality="1",x.style.gridColumn="1 / -1",x.style.flex="0 0 auto";const m=ne(p.wafers,p.fields,p.curation);if(p.fields.length===0||m.rows.length===0)return ue(v,p.fields.length===0?"No wafer field divides these wafers, so there is nothing to compare.":"No wafer field has two groups of two or more wafers, so there is nothing to compare."),{card:x,destroy:()=>{}};const T=ae(m.rows,m.tied),j=ie,B=o.createElement("div"),R=[`Each wafer field, compared for yield and for the ${m.bins.length} most common fail bin${m.bins.length===1?"":"s"}, with each wafer as one value. The clearest fields come first. A clear difference is more than wafer-to-wafer noise; it does not say why.`];m.overlapping.length&&R.push(`These fields nearly match, so the wafers cannot fully tell them apart: ${m.overlapping.map(t=>`${j(t.fields)} and ${j(t.with)} put ${t.agree} of ${t.of} wafers in the same groups`).join("; ")}.`),m.untestable.length&&R.push(`Not compared: ${m.untestable.map(t=>t.label).join(", ")}. A field is compared when two of its groups have two wafers or more and it has no more than ${de(p.wafers.length)} groups.`),B.textContent=R.join(" "),Object.assign(B.style,{color:h.label,fontSize:N.body,marginBottom:c.xs}),v.appendChild(B);const I=o.createElement("details"),k=o.createElement("summary");k.textContent="How to read this",Object.assign(k.style,{cursor:"pointer"}),H(k,"bare");const L=o.createElement("div");L.textContent=`Confidence is High when q is under 0.05, Medium when q is under 0.2, and Low otherwise. q is Welch\u2019s p adjusted for the ${m.rows.length} comparisons in the table (Benjamini\u2013Hochberg). Hover a word for the p-values. Each field is read after allowing for the strongest other field that explains the same measure and does not contain it, and its row says so. The bars show the worst (in bold) and the best group\u2019s mean, filled from zero on a scale of 0 to 100%; hover a bar for its group\u2019s median, spread and wafers. `,L.append(he(o,we.dividesYield),"."),I.append(k,L),Object.assign(I.style,{color:h.label,fontSize:N.body,marginBottom:c.sm}),v.appendChild(I);const O=o.createElement("table");Object.assign(O.style,{borderCollapse:"collapse",width:"100%",fontSize:N.body,fontVariantNumeric:"tabular-nums"});const z=o.createElement("tr"),S=(t,e)=>{const a=o.createElement("th");a.scope="col",a.textContent=t,e&&b(a,e),Object.assign(a.style,{textAlign:"left",padding:`${c.xs} ${c.sm}`,borderBottom:`1px solid ${h.menuBorder}`,color:h.label,fontWeight:"600",whiteSpace:"nowrap"}),z.appendChild(a)};S("Field"),S("Effect","The worst and the best group\u2019s mean over their wafers, and how far apart they are"),S("Confidence","How sure it is that the groups differ by more than wafer-to-wafer noise: High (q under 0.05), Medium (under 0.2) or Low"),S("");const q=o.createElement("thead");q.appendChild(z),O.appendChild(q);const W=o.createElement("tbody");O.appendChild(W);const y=(t,e,a={})=>{const n=o.createElement("td");return typeof e=="string"?n.textContent=e:n.appendChild(e),a.title&&b(n,a.title),a.shade&&(n.style.background=a.shade),Object.assign(n.style,{padding:`${c.xs} ${c.sm}`,textAlign:"left",borderBottom:`1px solid ${h.menuBorder}`,verticalAlign:"top",fontWeight:a.strong?"700":"400"}),t.appendChild(n),n},A=t=>`${t.toFixed(1)}%`,V=t=>t.comparison.groups.filter(e=>!t.comparison.tooSmall.includes(e.key)&&Number.isFinite(e.mean)),X=t=>{if(t.measure.kind!=="yield")return;const e=t.comparison.groups.filter(n=>Number.isFinite(n.mean)&&n.n>0),a=e.reduce((n,r)=>n+r.n,0);return a>0?me(t.worst.mean-e.reduce((n,r)=>n+r.mean*r.n,0)/a):void 0},J=re,Z=t=>{const e=V(t),a=100,n=o.createElement("div");Object.assign(n.style,{display:"flex",flexDirection:"column",gap:"2px",flex:"0 0 auto"});const r=(i,l)=>{const g=o.createElement("div");g.dataset.wmapBar=l,Object.assign(g.style,{display:"flex",alignItems:"center",gap:c.sm});const s=o.createElement("span");s.textContent=i.key,Object.assign(s.style,{width:"72px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:h.label,fontWeight:l==="worst"?"700":"400"});const d=o.createElement("div");Object.assign(d.style,{width:`${ye}px`,height:"10px",border:`1px solid ${h.label}`,boxSizing:"border-box",flex:"0 0 auto"});const $=o.createElement("div");Object.assign($.style,{width:`${Math.max(0,Math.min(100,i.mean/a*100)).toFixed(1)}%`,height:"100%",background:oe}),d.appendChild($);const E=o.createElement("span");return E.textContent=A(i.mean),Object.assign(E.style,{width:"52px",textAlign:"right"}),g.append(s,d,E),b(g,[`${i.key}${l==="worst"?" (worst group)":" (best group)"}`,`mean ${A(i.mean)} \xB7 median ${A(i.median)}`,Number.isFinite(i.sd)?`standard deviation ${i.sd.toFixed(1)} pts between wafers`:"",`${i.n} wafer${i.n===1?"":"s"}`].filter(Boolean).join(`
2
+ `)),g},u=e.find(i=>i.key===t.worst.key),w=e.find(i=>i.key===t.best.key);u&&n.appendChild(r(u,"worst")),w&&n.appendChild(r(w,"best"));const f=e.filter(i=>i!==u&&i!==w);if(f.length){const i=o.createElement("div");i.textContent=`+ ${f.length} other group${f.length===1?"":"s"}`,Object.assign(i.style,{color:h.label}),b(i,f.map(l=>`${l.key}: ${A(l.mean)} (${l.n} wafer${l.n===1?"":"s"})`).join(`
3
+ `)),n.appendChild(i)}return n},ee=t=>{const e=t.adjusted??t.comparison,a=e.kruskal;return[`q ${G(t.pAdjusted)} \xB7 Welch p ${G(e.welch?.p??NaN)} \xB7 rank p ${G(a?.p??NaN)}${a?.approximate?"* (approximate: fewer than five wafers in a group)":""}`,e.issue].filter(Boolean).join(`
4
+ `)},C=new Set;let D=!1;const M=(t,e,a)=>{const n=o.createElement("tr");n.dataset.wmapCommonalityRow=a?"field":"measure";const r=o.createElement("div");if(a){const s=o.createElement("div");s.textContent=j(e.fields),s.style.fontWeight="600",e.fields.length>1&&b(s,"These fields group the wafers identically, so the wafers cannot tell them apart: one row stands for all of them."),r.appendChild(s)}const u=o.createElement("div");if(u.textContent=se(t.measure)+(t.allowedFor?`, allowing for ${t.allowedFor.map(s=>s.label).join(", ")}`:""),Object.assign(u.style,{color:h.label,paddingLeft:a?"0":c.md}),t.allowedFor&&b(u,`Read after allowing for ${t.allowedFor.map(s=>s.label).join(", ")}: each wafer's value less its ${t.allowedFor.length===1?"group\u2019s":"groups\u2019"} mean on ${t.allowedFor.length===1?"that field":"those fields"}, so a difference the other field explains does not hide this one. The bars and the points are the measure's own means.`),r.appendChild(u),a&&e.others.length){const s=e.others.filter(E=>P(E.pAdjusted)!=="none").length,d=o.createElement("button");d.type="button",d.dataset.wmapCommonalityMore=e.field.key;const $=C.has(e.field.key);d.setAttribute("aria-expanded",String($)),d.textContent=$?"Hide other measures":s?`+${s} other measure${s===1?"":"s"} ${s===1?"differs":"differ"}`:`${e.others.length} other measure${e.others.length===1?"":"s"}`,Object.assign(d.style,{...U("outlined"),marginTop:c.xs,fontSize:N.body}),H(d),d.addEventListener("click",()=>{C.has(e.field.key)?C.delete(e.field.key):C.add(e.field.key),_(D)}),r.appendChild(d)}y(n,r);const w=o.createElement("div");Object.assign(w.style,{display:"flex",alignItems:"flex-start",gap:c.md});const f=o.createElement("span");f.textContent=J(t);const i=X(t);i&&Object.assign(f.style,{background:i,padding:`0 ${c.xs}`,borderRadius:ce.control}),f.dataset.wmapSentence="1",w.append(Z(t),f),y(n,w);const l=P(t.pAdjusted),g=y(n,le[l],{strong:l==="clear",title:ee(t)});if(g.dataset.wmapConfidence=l,a)if(e.fields.some(s=>s.key===p.groupedBy))y(n,"Grouped by this");else{const s=o.createElement("button");s.type="button",s.textContent="Group by",s.dataset.wmapCommonalityGroup=e.field.key,b(s,`Group Insights by ${e.field.label}, so every chart compares its groups${e.fields.length>1?`; ${j(e.fields.slice(1))} give the same groups`:""}`),Object.assign(s.style,U("outlined")),H(s),s.addEventListener("click",()=>p.onGroupBy(e.field.key)),y(n,s)}else y(n,"");W.appendChild(n)};function _(t){D=t,W.replaceChildren();for(const e of t?T:T.slice(0,Y))if(M(e.primary,e,!0),C.has(e.field.key))for(const a of e.others)M(a,e,!1)}const F=o.createElement("div");Object.assign(F.style,{overflowX:"auto"}),F.appendChild(O);const te=fe(o,{total:T.length,first:Y,noun:"rows",scroller:F,fill:_});return v.append(F,te),{card:x,destroy:()=>{}}}
@@ -1,4 +1,5 @@
1
- import { type FacetItem } from '../../stats/facets.js';
1
+ import type { ReaderColors } from './divergingScale.js';
2
+ import { type FacetItem, type FacetCuration } from '../../stats/facets.js';
2
3
  import type { Die } from '../../core/dies.js';
3
4
  import type { TestDef } from '../../renderer/buildWaferMap.js';
4
5
  import { type SaveTextHandler } from '../toolbar.js';
@@ -15,6 +16,8 @@ export interface CorrelationPanelOptions {
15
16
  items: CorrelationItem[];
16
17
  testDefs: TestDef[];
17
18
  onSaveImage?: SaveImageHandler;
19
+ /** The reader's colours: the panel draws from their data colour scheme. */
20
+ readerColors?: ReaderColors;
18
21
  /**
19
22
  * Grouping is NOT this panel's concern — the Insights tab owns one "Show:"
20
23
  * scope for every view and hands each panel the population it names. This
@@ -23,17 +26,8 @@ export interface CorrelationPanelOptions {
23
26
  */
24
27
  /** Clicking a non-diagonal cell calls this — the Analysis tab wires it to drive the scatter panel's X/Y in place. */
25
28
  onSelectPair?: (xTestNumber: number, yTestNumber: number) => void;
26
- /**
27
- * With Group by on (two groups or more), the groups' wafers: the matrix then offers **Within groups**, the correlation
28
- * left once each group's mean is taken off every test. Not a restriction to one group (see above): the choice is how
29
- * the same wafers are correlated.
30
- */
31
- groups?: ReadonlyArray<{
32
- key: string;
33
- items: CorrelationItem[];
34
- }>;
35
- /** The field the groups are values of, for the choice's label. */
36
- groupLabelText?: string;
29
+ /** The host's wafer attributes (`attributes` on the render options), so the mixed-fields warning names each field as the rest of Insights does. */
30
+ attributes?: Record<string, FacetCuration>;
37
31
  /** Document to build this panel's DOM into. Default `document` — pass the
38
32
  * host's own `ownerDocument` when the container might live in a
39
33
  * different document (e.g. a gallery card detached into its own popup
@@ -1 +1 @@
1
- import{buildCoFailureMatrix as De}from"../../stats/coFailure.js";import{buildCorrelationMatrix as Re,demeanWithinGroups as ke,filterCorrelationMatrix as Ae,correlationSampleNote as _e}from"../../stats/correlation.js";import{maxOf as We}from"../../core/utils.js";import{CORRELATION_POSITIVE as Q,CORRELATION_NEGATIVE as re}from"./palette.js";import{buildFacetTable as Be}from"../../stats/facets.js";import{wireControlHover as Oe,wireTooltip as me,controlStyle as Ne,SPACE as I,RADIUS as ie,fontPx as pe,FONT as z,CLR as x}from"../toolbar.js";import{exportCsv as He}from"../tableExport.js";import{attachChartTip as Xe,cardShell as je,makeSegmented as ge,setChartGrow as Fe,isExpandedCard as Ve,bodyRoom as ze,observeResize as Ye,makeTooltip as Ge,positionChartTooltip as Pe,makeWaferSelect as Ke,renderEmptyState as Ue,resolveChartCanvasColors as qe,prepareCanvas as Je,chartDpr as be}from"./chartShell.js";import{escHtml as Z}from"../../core/utils.js";import{unmarkedLabel as xe,derivedCsvCell as ye,DERIVED_CSV_HEADER as we,DERIVED_MARK as Qe,DERIVED_KEY as Ze}from"../../renderer/testLabel.js";import{cardAbout as et}from"./cardAbout.js";const ae=5,ce=100,Ce=20;function ee(d){const h=d.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(h)return[+h[1],+h[2],+h[3]];const g=d.trim().replace("#","");return g.length===6?[parseInt(g.slice(0,2),16),parseInt(g.slice(2,4),16),parseInt(g.slice(4,6),16)]:null}function tt(d){const h=ee(d);return h?(h[0]*299+h[1]*587+h[2]*114)/1e3>140?"#111":"#fff":"#000"}function $e(d,h,g){const v=ee(d);if(!v)return d;const te=Math.round(h[0]+(v[0]-h[0])*g),X=Math.round(h[1]+(v[1]-h[1])*g),l=Math.round(h[2]+(v[2]-h[2])*g);return`rgb(${te},${X},${l})`}export function renderCorrelationPanel(d){const{title:h="Test correlation matrix",items:g,testDefs:v,onSaveImage:te,onSelectPair:X}=d,{card:l,body:D,controlsRow:Y,setPngDecor:Me,setAbout:Le}=je(h,te,d.ownerDocument);Le(et("correlation")),Me(()=>{const e=ee(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:n=>$e(n<.5?re:Q,e,Math.abs(2*n-1))}}}),Fe(l,"square"),D.style.overflowX="auto",l.style.alignSelf="start";let K=Ce,j=null;const F=l.ownerDocument.createElement("label");F.textContent="Max tests:",me(F,`The most tests the matrix shows, from ${ae} to ${ce}`),Object.assign(F.style,{color:x.label,fontSize:z.body,display:"flex",alignItems:"center",gap:I.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(ae),E.max=String(ce),E.value=String(K),Object.assign(E.style,{width:"52px",fontSize:z.body,padding:`${I.xxs} ${I.xs}`,background:x.menuBg,color:x.value,border:`1px solid ${x.menuBorder}`,borderRadius:ie.control}),E.addEventListener("change",()=>{const e=Math.max(ae,Math.min(ce,parseInt(E.value,10)||Ce));E.value=String(e),e!==K&&(K=e,G())}),F.appendChild(E),Y.appendChild(F),g.length>1&&Y.appendChild(Ke(g,j,e=>{j=e,G()},{ownerDocument:l.ownerDocument}));let de=!1,y=!1;if(v.filter(e=>e.limitLow!==void 0||e.limitHigh!==void 0).length>=2){const e=ge([["values","Values","How the tests\u2019 values move together (Pearson r)"],["fails","Fails together","Which tests fail on the same dies: the share of the dies failing either of two tests that fail both"]],"values",n=>{y=n==="fails",G()},l.ownerDocument);e.dataset.wmapCorrelationKind="1",Y.appendChild(e)}if(d.groups&&d.groups.length>=2){const e=ge([["pooled","Pooled"],["within",`Within ${d.groupLabelText??"groups"}`,"The correlation left once each group\u2019s mean is taken off every test, so a difference between groups is not read as a relationship between tests"]],"pooled",n=>{de=n==="within",G()},l.ownerDocument);e.dataset.wmapCorrelationMode="1",Y.appendChild(e)}function ve(){return j!==null?g[j]?[g[j]]:[]:g}if(d.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",me(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...Ne("outlined"),color:x.text}),Oe(e),e.addEventListener("click",()=>{const n=fe;if(!n)return;const u=n.tests.some(o=>o.derived),a=[];for(let o=0;o<n.tests.length;o++)for(let c=o+1;c<n.tests.length;c++){const w=n.cells.find(b=>b.xIndex===c&&b.yIndex===o);w&&a.push({x:n.tests[c],y:n.tests[o],r:w.r,n:w.n})}He([{header:"Test X",get:o=>xe(o.x.label)},{header:"Test X number",get:o=>o.x.testNumber},{header:"Test Y",get:o=>xe(o.y.label)},{header:"Test Y number",get:o=>o.y.testNumber},{header:y?"Share failing both":"r",get:o=>o.r===null?"":o.r.toFixed(6)},{header:y?"Dies failing either":"n",get:o=>o.n},...u?[{header:`Test X ${we.toLowerCase()}`,get:o=>ye(o.x)},{header:`Test Y ${we.toLowerCase()}`,get:o=>ye(o.y)}]:[]],a,"test-correlation.csv",d.onSaveText)}),Y.appendChild(e)}const N=l.ownerDocument.createElement("div");Object.assign(N.style,{display:"flex",flexDirection:"column",gap:I.xs,marginBottom:I.sm}),l.insertBefore(N,D);const R=Ge(l);Xe(F,l,R,"Cap on how many tests the matrix includes (strongest correlations kept first)");let ne=()=>{};function Ee(e,n,u,a,o,c,w,b){N.innerHTML="";const k=_e(w);if(k){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=w.sample?`${k} \u2014 r is an estimate, not the whole population.`:`${k}.`,Object.assign(m.style,{color:x.label,fontSize:z.body}),N.appendChild(m)}if(o.length>0){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=`\u26A0 Mixed ${o.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). ${d.groups&&d.groups.length>=2?`Choose Within ${d.groupLabelText??"groups"} to take the groups\u2019 differences out, or use the Wafer picker`:"Use the Wafer picker to narrow to a like-for-like set, or Group by one of these fields where it is in the list"}.`,Object.assign(m.style,{color:x.warnText,background:x.warnBg,border:`1px solid ${x.warnBorder}`,borderRadius:ie.control,padding:`${I.xs} ${I.md}`,fontSize:z.body}),N.appendChild(m)}const A=l.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-flex",alignItems:"center",gap:I.sm,color:x.label,fontSize:z.body,flexWrap:"wrap"});const S=l.ownerDocument.createElement("span");S.dataset.wmapCaption="1",S.textContent=y?`Share of the dies failing either that fail both${c!==null?` \xB7 ${c.toLocaleString()} failing dies per pair (median)`:""} \xB7 click a cell to view that pair in scatter \xB7`:(c!==null?`Pearson r \xB7 n \u2248 ${c.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(b?` ${Qe} ${Ze} \xB7`:""),A.appendChild(S);const T=l.ownerDocument.createElement("span");Object.assign(T.style,{display:"inline-flex",alignItems:"center",gap:I.xs});const i=l.ownerDocument.createElement("span");i.textContent=y?"0":"\u22121";const _=l.ownerDocument.createElement("span");Object.assign(_.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:ie.control,border:`1px solid ${x.menuBorder}`,background:y?`linear-gradient(to right, ${x.menuBg}, ${Q})`:`linear-gradient(to right, ${re}, ${x.menuBg}, ${Q})`});const P=l.ownerDocument.createElement("span");P.textContent=y?"1":"+1",T.append(i,_,P),A.appendChild(T),N.appendChild(A);const $=l.ownerDocument.createElement("span");if($.dataset.wmapCaption="1",Object.assign($.style,{color:x.value,fontSize:z.body,fontWeight:"500"}),y)$.textContent=a&&a.r>0?`Most shared failures: ${a.xLabel} \u2194 ${a.yLabel} (${Math.round(100*a.r)}% of the dies failing either fail both)`:"No two tests fail on the same dies";else if(e===0&&n===0)$.textContent=a?`No significant correlations found \u2014 strongest pair: ${a.xLabel} \u2194 ${a.yLabel} (r = ${a.r.toFixed(2)})`:"No significant correlations found";else{const m=[];e>0&&m.push(`${e} strong (|r| \u2265 0.7)`),n>0&&m.push(`${n} moderate (0.4\u20130.7)`);const U=e+n;let r=m.join(", ")+` pair${U!==1?"s":""} found`;u>0&&(r+=` \xB7 ${u} weak pair${u!==1?"s":""} not shown`),$.textContent=r}N.appendChild($)}function Se(e){if(D.innerHTML="",e.tests.length<2)return Ue(D,"Need at least two parametric tests for a correlation matrix."),()=>{};const n=l.ownerDocument.createElement("canvas");n.style.display="block",n.style.cursor="default",D.appendChild(n);const u=e.tests.length,a=r=>r.label.split(" (#")[0],o=Math.min(14,We(e.tests.map(r=>a(r).length))),c=o*6.5+8,w=10,b=Math.round(w*6.5*Math.sin(Math.PI/4))+14,k=14,A=28,S=44;let T=-1,i=-1;const _=96;function P(r){const f=Math.max(0,r-c),p=Math.floor(f/u);if(!Ve(l))return Math.max(k,Math.min(S,p));const s=Math.floor((ze(l,D,n)-b-4)/u);return Math.max(k,Math.min(_,p,s))}const $=new Map;for(const r of e.cells){let f=$.get(r.yIndex);f||(f=[],$.set(r.yIndex,f)),f.push(r)}function m(){const r=qe(l),f=ee(r.bg)??[255,255,255],p=D.clientWidth,s=P(p),V=s*u,M=b+s*u+4,W=c+V,B=Je(n,l,W,M);if(!B)return;const{ctx:t}=B;t.font=`${pe(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((O,C)=>{const L=a(O),H=L.length>w?`${L.slice(0,w-1)}\u2026`:L,oe=c+C*s+s/2;t.save(),t.translate(oe,b-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=C===T?r.text:r.textMuted,t.fillText(H,0,0),t.restore()}),e.tests.forEach((O,C)=>{const L=a(O),H=b+C*s,oe=H+s/2;t.font=`${pe(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=C===i?r.text:r.textMuted,t.fillText(L.length>o?`${L.slice(0,o-1)}\u2026`:L,c-4,oe),($.get(C)??[]).forEach(he=>{const se=he.xIndex,q=c+se*s,Ie=se===T&&C===i,ue=se===C,J=he.r;if(J===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(q+1,H+1,s-2,s-2),t.globalAlpha=1;return}let le=r.bgHover;ue?t.fillStyle=r.bgHover:(le=$e(J>=0?Q:re,f,Math.abs(J)),t.fillStyle=le),t.fillRect(q+1,H+1,s-2,s-2),s>=A&&!ue&&(t.font=`${Math.min(10,s*.35)}px system-ui, sans-serif`,t.fillStyle=tt(le),t.textAlign="center",t.textBaseline="middle",t.fillText(J.toFixed(2),q+s/2,H+s/2)),Ie&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(q+1,H+1,s-2,s-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let O=0;O<=u;O++){const C=c+O*s;t.beginPath(),t.moveTo(C,b),t.lineTo(C,b+u*s),t.stroke();const L=b+O*s;t.beginPath(),t.moveTo(c,L),t.lineTo(c+u*s,L),t.stroke()}}function U(r){const f=n.getBoundingClientRect(),p=D.clientWidth,s=P(p),V=(r.clientX-f.left)*(n.width/be(n)/f.width),M=(r.clientY-f.top)*(n.height/be(n)/f.height),W=Math.floor((V-c)/s),B=Math.floor((M-b)/s);return W>=0&&W<u&&B>=0&&B<u?{xi:W,yi:B}:null}return n.addEventListener("mousemove",r=>{const f=U(r);if(!f){R.style.display="none",n.style.cursor="default";return}const{xi:p,yi:s}=f,V=p===s;n.style.cursor=V||!X?"default":"pointer";const M=e.cells.find(t=>t.xIndex===p&&t.yIndex===s),W=e.tests[p].label,B=e.tests[s].label;V?R.innerHTML=`<strong>${Z(W)}</strong>`:M?.r!==null&&M?.r!==void 0?R.innerHTML=`<strong>${Z(a(e.tests[s]))}</strong> (#${e.tests[s].testNumber}) vs <strong>${Z(a(e.tests[p]))}</strong> (#${e.tests[p].testNumber})<br>${y?`${(100*M.r).toFixed(0)}% of the dies failing either fail both \xB7 ${M.n.toLocaleString()} fail either`:`r = ${M.r.toFixed(4)} \xB7 n = ${M.n.toLocaleString()}`}${X?"<br><em>click to view in scatter</em>":""}`:R.innerHTML=`${Z(`${B} vs ${W}`)}<br><em>insufficient data</em>`,R.style.display="block",Pe(R,l,r.clientX,r.clientY)}),n.addEventListener("mouseleave",()=>{R.style.display="none"}),n.addEventListener("click",r=>{const f=U(r);if(!f||!X)return;const{xi:p,yi:s}=f;p!==s&&(T=p,i=s,m(),X(e.tests[p].testNumber,e.tests[s].testNumber))}),m}let fe=null;function G(){const e=ve(),n=!y&&de&&j===null&&!!d.groups,u=n?ke(d.groups.map(i=>i.items.flatMap(_=>_.dies??[])),v):e.flatMap(i=>i.dies??[]),a=y?De(u,v):Re(u,v),{matrix:o,strongPairs:c,moderatePairs:w,hiddenWeakPairs:b,strongestPair:k}=Ae(a,{minTests:6,maxTests:K}),A=n||y?[]:Be(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),S=o.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,_)=>i-_),T=S.length?S[Math.floor(S.length/2)]:null;fe=o,Ee(c,w,b,k,A,T,a,o.tests.some(i=>i.derived)),ne=Se(o),ne()}const Te=Ye(l,()=>ne());return G(),{card:l,destroy:()=>Te.disconnect()}}
1
+ import{buildCoFailureMatrix as Be}from"../../stats/coFailure.js";import{buildCorrelationMatrix as We,demeanWithinGroups as Oe,groupMeans as Ne,filterCorrelationMatrix as He,correlationSampleNote as Xe}from"../../stats/correlation.js";import{maxOf as Fe}from"../../core/utils.js";import{parseCssColor as ne}from"../../renderer/colorMap.js";import{signedEnds as xe}from"./palette.js";import{mixedFieldLabels as je,mixedFieldsWarning as Ve}from"../../stats/facets.js";import{wireControlHover as ze,wireTooltip as be,controlStyle as Ye,SPACE as D,RADIUS as de,fontPx as we,FONT as G,CLR as p}from"../toolbar.js";import{exportCsv as Ge}from"../tableExport.js";import{attachChartTip as Ke,cardShell as Pe,onRepaint as Ue,makeSegmented as ye,setChartGrow as qe,isExpandedCard as Je,bodyRoom as Qe,observeResize as Ze,makeTooltip as et,positionChartTooltip as tt,makeWaferSelect as nt,renderEmptyState as ot,resolveChartCanvasColors as st,prepareCanvas as it,chartDpr as Ce}from"./chartShell.js";import{escHtml as oe}from"../../core/utils.js";import{unmarkedLabel as $e,derivedCsvCell as Me,DERIVED_CSV_HEADER as ve,DERIVED_MARK as rt,DERIVED_KEY as lt}from"../../renderer/testLabel.js";import{cardAbout as at,cardKindId as ct}from"./cardAbout.js";const fe=5,he=100,Ee=20;function dt(x){const g=ne(x);return g?(g[0]*299+g[1]*587+g[2]*114)/1e3>140?"#111":"#fff":"#000"}function Le(x,g,b){const M=ne(x);if(!M)return x;const se=Math.round(g[0]+(M[0]-g[0])*b),j=Math.round(g[1]+(M[1]-g[1])*b),O=Math.round(g[2]+(M[2]-g[2])*b);return`rgb(${se},${j},${O})`}export function renderCorrelationPanel(x){const{title:g="Test correlation matrix",items:b,testDefs:M,onSaveImage:se,onSelectPair:j}=x;let O=xe(x.readerColors?.dataColors),q=O.low,K=O.high;const{card:r,body:I,controlsRow:P,setPngDecor:Se,setAbout:De,setCardId:Ie}=Pe(g,se,x.ownerDocument);Ie(ct("correlation")),De(at("correlation")),Se(()=>{const e=ne(r.ownerDocument.defaultView?.getComputedStyle(r).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:n=>Le(n<.5?q:K,e,Math.abs(2*n-1))}}}),qe(r,"square"),I.style.overflowX="auto",r.style.alignSelf="start";let J=Ee,V=null;const z=r.ownerDocument.createElement("label");z.textContent="Max tests:",be(z,`The most tests the matrix shows, from ${fe} to ${he}`),Object.assign(z.style,{color:p.label,fontSize:G.body,display:"flex",alignItems:"center",gap:D.xs});const S=r.ownerDocument.createElement("input");S.type="number",S.min=String(fe),S.max=String(he),S.value=String(J),Object.assign(S.style,{width:"52px",fontSize:G.body,padding:`${D.xxs} ${D.xs}`,background:p.menuBg,color:p.value,border:`1px solid ${p.menuBorder}`,borderRadius:de.control}),S.addEventListener("change",()=>{const e=Math.max(fe,Math.min(he,parseInt(S.value,10)||Ee));S.value=String(e),e!==J&&(J=e,U())}),z.appendChild(S),P.appendChild(z),b.length>1&&P.appendChild(nt(b,V,e=>{V=e,U()},{ownerDocument:r.ownerDocument}));let me="within",Q="within",w=!1;if(M.filter(e=>e.limitLow!==void 0||e.limitHigh!==void 0).length>=2){const e=ye([["values","Values","How the tests\u2019 values move together (Pearson r)"],["fails","Fails together","Which tests fail on the same dies: the share of the dies failing either of two tests that fail both"]],"values",n=>{w=n==="fails",U()},r.ownerDocument);e.dataset.wmapCorrelationKind="1",P.appendChild(e)}if(b.length>=2){const e=ye([["within","Within wafers","Die to die, once each wafer\u2019s mean is taken off every test: a difference between wafers or splits is not read as a relationship between tests"],...b.length>=5?[["between","Between wafers","One point per wafer, its mean of each test: whether a wafer high on one test is high on another"]]:[],["pooled","All dies together","Every die as it is: the relationship within wafers and the difference between them together"]],"within",n=>{me=n,U()},r.ownerDocument);e.dataset.wmapCorrelationMode="1",P.appendChild(e)}function Te(){return V!==null?b[V]?[b[V]]:[]:b}if(x.onSaveText){const e=r.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",be(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...Ye("outlined"),color:p.text}),ze(e),e.addEventListener("click",()=>{const n=ue;if(!n)return;const c=n.tests.some(s=>s.derived),a=[];for(let s=0;s<n.tests.length;s++)for(let l=s+1;l<n.tests.length;l++){const y=n.cells.find(m=>m.xIndex===l&&m.yIndex===s);y&&a.push({x:n.tests[l],y:n.tests[s],r:y.r,n:y.n})}Ge([{header:"Test X",get:s=>$e(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>$e(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:w?"Share failing both":"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:w?"Dies failing either":"n",get:s=>s.n},...c?[{header:`Test X ${ve.toLowerCase()}`,get:s=>Me(s.x)},{header:`Test Y ${ve.toLowerCase()}`,get:s=>Me(s.y)}]:[]],a,"test-correlation.csv",x.onSaveText)}),P.appendChild(e)}const N=r.ownerDocument.createElement("div");Object.assign(N.style,{display:"flex",flexDirection:"column",gap:D.xs,marginBottom:D.sm}),r.insertBefore(N,I);const T=et(r);Ke(z,r,T,"Cap on how many tests the matrix includes (strongest correlations kept first)");let ie=()=>{};function Re(e,n,c,a,s,l,y,m){N.innerHTML="";const R=Xe(y);if(R){const f=r.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=y.sample?`${R} \u2014 r is an estimate, not the whole population.`:`${R}.`,Object.assign(f.style,{color:p.label,fontSize:G.body}),N.appendChild(f)}if(s.length>0){const f=r.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`\u26A0 ${Ve(s,"correlation")} Choose Within wafers to take the wafers\u2019 differences out.`,Object.assign(f.style,{color:p.warnText,background:p.warnBg,border:`1px solid ${p.warnBorder}`,borderRadius:de.control,padding:`${D.xs} ${D.md}`,fontSize:G.body}),N.appendChild(f)}const A=r.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-flex",alignItems:"center",gap:D.sm,color:p.label,fontSize:G.body,flexWrap:"wrap"});const H=r.ownerDocument.createElement("span");H.dataset.wmapCaption="1",H.textContent=w?`Share of the dies failing either that fail both${l!==null?` \xB7 ${l.toLocaleString()} failing dies per pair (median)`:""} \xB7 click a cell to view that pair in scatter \xB7`:(l!==null?`Pearson r${Q==="within"?" within wafers":Q==="between"?" of wafer means":""} \xB7 n \u2248 ${l.toLocaleString()} ${Q==="between"?"wafers":"dies"} per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(m?` ${rt} ${lt} \xB7`:""),A.appendChild(H);const C=r.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:D.xs});const k=r.ownerDocument.createElement("span");k.textContent=w?"0":"\u22121";const u=r.ownerDocument.createElement("span");Object.assign(u.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:de.control,border:`1px solid ${p.menuBorder}`,background:w?`linear-gradient(to right, ${p.menuBg}, ${K})`:`linear-gradient(to right, ${q}, ${p.menuBg}, ${K})`});const X=r.ownerDocument.createElement("span");X.textContent=w?"1":"+1",C.append(k,u,X),A.appendChild(C),N.appendChild(A);const v=r.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:p.value,fontSize:G.body,fontWeight:"500"}),w)v.textContent=a&&a.r>0?`Most shared failures: ${a.xLabel} \u2194 ${a.yLabel} (${Math.round(100*a.r)}% of the dies failing either fail both)`:"No two tests fail on the same dies";else if(e===0&&n===0)v.textContent=a?`No significant correlations found \u2014 strongest pair: ${a.xLabel} \u2194 ${a.yLabel} (r = ${a.r.toFixed(2)})`:"No significant correlations found";else{const f=[];e>0&&f.push(`${e} strong (|r| \u2265 0.7)`),n>0&&f.push(`${n} moderate (0.4\u20130.7)`);const Z=e+n;let i=f.join(", ")+` pair${Z!==1?"s":""} found`;c>0&&(i+=` \xB7 ${c} weak pair${c!==1?"s":""} not shown`),v.textContent=i}N.appendChild(v)}function Ae(e){if(I.innerHTML="",e.tests.length<2)return ot(I,"Need at least two parametric tests for a correlation matrix."),()=>{};const n=r.ownerDocument.createElement("canvas");n.style.display="block",n.style.cursor="default",I.appendChild(n);const c=e.tests.length,a=i=>i.label.split(" (#")[0],s=Math.min(14,Fe(e.tests.map(i=>a(i).length))),l=s*6.5+8,y=10,m=Math.round(y*6.5*Math.sin(Math.PI/4))+14,R=14,A=28,H=44;let C=-1,k=-1;const u=96;function X(i){const d=Math.max(0,i-l),h=Math.floor(d/c);if(!Je(r))return Math.max(R,Math.min(H,h));const o=Math.floor((Qe(r,I,n)-m-4)/c);return Math.max(R,Math.min(u,h,o))}const v=new Map;for(const i of e.cells){let d=v.get(i.yIndex);d||(d=[],v.set(i.yIndex,d)),d.push(i)}function f(){const i=st(r),d=ne(i.bg)??[255,255,255],h=I.clientWidth,o=X(h),Y=o*c,E=m+o*c+4,_=l+Y,B=it(n,r,_,E);if(!B)return;const{ctx:t}=B;t.font=`${we(-1)}px system-ui, sans-serif`,t.fillStyle=i.text,e.tests.forEach((W,$)=>{const L=a(W),F=L.length>y?`${L.slice(0,y-1)}\u2026`:L,le=l+$*o+o/2;t.save(),t.translate(le,m-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=$===C?i.text:i.textMuted,t.fillText(F,0,0),t.restore()}),e.tests.forEach((W,$)=>{const L=a(W),F=m+$*o,le=F+o/2;t.font=`${we(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=$===k?i.text:i.textMuted,t.fillText(L.length>s?`${L.slice(0,s-1)}\u2026`:L,l-4,le),(v.get($)??[]).forEach(pe=>{const ae=pe.xIndex,ee=l+ae*o,_e=ae===C&&$===k,ge=ae===$,te=pe.r;if(te===null){t.fillStyle=i.border,t.globalAlpha=.4,t.fillRect(ee+1,F+1,o-2,o-2),t.globalAlpha=1;return}let ce=i.bgHover;ge?t.fillStyle=i.bgHover:(ce=Le(te>=0?K:q,d,Math.abs(te)),t.fillStyle=ce),t.fillRect(ee+1,F+1,o-2,o-2),o>=A&&!ge&&(t.font=`${Math.min(10,o*.35)}px system-ui, sans-serif`,t.fillStyle=dt(ce),t.textAlign="center",t.textBaseline="middle",t.fillText(te.toFixed(2),ee+o/2,F+o/2)),_e&&(t.strokeStyle=i.text,t.lineWidth=2,t.strokeRect(ee+1,F+1,o-2,o-2),t.lineWidth=1)})}),t.strokeStyle=i.bg,t.lineWidth=1;for(let W=0;W<=c;W++){const $=l+W*o;t.beginPath(),t.moveTo($,m),t.lineTo($,m+c*o),t.stroke();const L=m+W*o;t.beginPath(),t.moveTo(l,L),t.lineTo(l+c*o,L),t.stroke()}}function Z(i){const d=n.getBoundingClientRect(),h=I.clientWidth,o=X(h),Y=(i.clientX-d.left)*(n.width/Ce(n)/d.width),E=(i.clientY-d.top)*(n.height/Ce(n)/d.height),_=Math.floor((Y-l)/o),B=Math.floor((E-m)/o);return _>=0&&_<c&&B>=0&&B<c?{xi:_,yi:B}:null}return n.addEventListener("mousemove",i=>{const d=Z(i);if(!d){T.style.display="none",n.style.cursor="default";return}const{xi:h,yi:o}=d,Y=h===o;n.style.cursor=Y||!j?"default":"pointer";const E=e.cells.find(t=>t.xIndex===h&&t.yIndex===o),_=e.tests[h].label,B=e.tests[o].label;Y?T.innerHTML=`<strong>${oe(_)}</strong>`:E?.r!==null&&E?.r!==void 0?T.innerHTML=`<strong>${oe(a(e.tests[o]))}</strong> (#${e.tests[o].testNumber}) vs <strong>${oe(a(e.tests[h]))}</strong> (#${e.tests[h].testNumber})<br>${w?`${(100*E.r).toFixed(0)}% of the dies failing either fail both \xB7 ${E.n.toLocaleString()} fail either`:`r = ${E.r.toFixed(4)} \xB7 n = ${E.n.toLocaleString()}`}${j?"<br><em>click to view in scatter</em>":""}`:T.innerHTML=`${oe(`${B} vs ${_}`)}<br><em>insufficient data</em>`,T.style.display="block",tt(T,r,i.clientX,i.clientY)}),n.addEventListener("mouseleave",()=>{T.style.display="none"}),n.addEventListener("click",i=>{const d=Z(i);if(!d||!j)return;const{xi:h,yi:o}=d;h!==o&&(C=h,k=o,f(),j(e.tests[h].testNumber,e.tests[o].testNumber))}),f}let ue=null,re;function U(){const e=Te(),n=!w&&V===null&&e.length>=2?me:"pooled",c=e.map(u=>u.dies??[]),a=n==="within"?Oe(c,M):n==="between"?Ne(c,M):c.flat();Q=n;const s=w?Be(a,M):We(a,M),{matrix:l,strongPairs:y,moderatePairs:m,hiddenWeakPairs:R,strongestPair:A}=He(s,{minTests:6,maxTests:J}),H=n==="within"||w?[]:je(e,{curation:x.attributes}),C=l.cells.filter(u=>u.xIndex!==u.yIndex).map(u=>u.n).sort((u,X)=>u-X),k=C.length?C[Math.floor(C.length/2)]:null;ue=l,re=()=>{Re(y,m,R,A,H,k,s,l.tests.some(u=>u.derived)),ie=Ae(l),ie()},re()}const ke=Ze(r,()=>ie());return U(),Ue(r,()=>{O=xe(x.readerColors?.dataColors),q=O.low,K=O.high,re?.()}),{card:r,destroy:()=>ke.disconnect()}}
@@ -1,23 +1,53 @@
1
- type Rgb = [number, number, number];
2
- /** The colour at `t` in [0, 1] on the signed scale (blue below, warm above), where 0.5 is zero. */
3
- export declare const divergingRgb: (t: number) => Rgb;
4
- export declare const divergingColor: (t: number) => string;
5
- /** The colour at `t` on the rating scale (vermillion for bad to blue for good). */
6
- export declare const ratingRgb: (t: number) => Rgb;
7
- /** The gradients only a plot offers, beside the map's own (`listValueColorSchemes`). */
8
- export declare const PLOT_GRADIENTS: ReadonlyArray<{
9
- name: string;
10
- label: string;
1
+ import { type Rgb } from '../../renderer/dataColors.js';
2
+ /** The card and text colours a theme draws with: whether it is dark picks the form of the scales. */
3
+ export interface QuietColors {
4
+ card: string;
5
+ text: string;
6
+ }
7
+ /** The colour at `t` in [0, 1] on the signed scale (the lowest value at 0, the centre at 0.5), in the form for a theme. */
8
+ export declare const divergingRgb: (t: number, dataColors?: string, quiet?: QuietColors) => Rgb;
9
+ export declare const divergingColor: (t: number, dataColors?: string, quiet?: QuietColors) => string;
10
+ /** The colour at `t` on the rating scale, `t` = 0 the floor (worst) and 1 the best, in the form for a theme's card. */
11
+ export declare const ratingRgb: (t: number, quiet?: QuietColors, dataColors?: string) => Rgb;
12
+ /**
13
+ * A bar's colour for a yield `step` short of the yield of all the bars together (1: a point or more, 2: two, 3: four),
14
+ * from the rating scale's bad side: opaque, so a bar stays a solid mark.
15
+ */
16
+ export declare const shortfallBarColor: (step: 1 | 2 | 3, quiet?: QuietColors, dataColors?: string) => string;
17
+ /** The colour of a yield or pass rate, in percent, on the fixed key: 0% the worst, 100% the best, breakpoints between. */
18
+ export declare const yieldColor: (percent: number, quiet?: QuietColors, dataColors?: string) => string;
19
+ /**
20
+ * Where a value sits on a plot's colour key, in [0, 1]: a rating (a yield, a pass rate) linearly from 0% to 100%
21
+ * (`ratingT`); any other value linearly over its range.
22
+ */
23
+ export declare const scaleT: (scale: {
24
+ lo: number;
25
+ hi: number;
26
+ rating?: true;
27
+ }, v: number) => number;
28
+ /** The captions under a rating key: each named point between its ends (25, 50, 75%), at its place along the key. */
29
+ export declare const ratingKeyTicks: () => Array<{
30
+ at: number;
31
+ text: string;
11
32
  }>;
33
+ /** The reader's colour preferences a chart follows: the data colour scheme and Reverse for a measured value. */
34
+ export interface ReaderColors {
35
+ dataColors?: string;
36
+ reverseValueScheme?: boolean;
37
+ /** A measured value in greys (`greyscaleValues`). */
38
+ greyscaleValues?: boolean;
39
+ /** The host's hook for changing one bin's colour: a bin's chip in a chart key then offers **Change colour…** on right-click. */
40
+ onEditBinColor?: (bin: number, kind: 'hard' | 'soft') => void;
41
+ }
12
42
  /**
13
- * The colour of a value at `t` in [0, 1] of a plot's key. `scheme` is a name from `PLOT_GRADIENTS` or a map gradient;
14
- * unset, a value rescaled around zero (`diverging`) takes the signed scale, a rating (a yield, a pass rate) the rating
15
- * scale, and any other the map's default. `reversed` flips the key.
43
+ * The colour of a value at `t` in [0, 1] of a plot's key. A value rescaled around zero (`diverging`) takes the signed
44
+ * scale, a rating (a yield, a pass rate) the rating scale and a count the counts scale, all of the reader's data colour
45
+ * scheme, and any other value its measured ramp with the reader's Reverse. `scheme` is a plot's own choice of gradient
46
+ * (`listValueColorSchemes`) and wins over all of these. `reversed` is the plot's own flip.
16
47
  */
17
- export declare function plotGradient(scheme: string | undefined, reversed: boolean | undefined, diverging: boolean | undefined, rating?: boolean): (t: number) => string;
48
+ export declare function plotGradient(scheme: string | undefined, reversed: boolean | undefined, diverging: boolean | undefined, rating?: boolean, quiet?: QuietColors, counts?: boolean, reader?: ReaderColors): (t: number) => string;
18
49
  /** Whether dark text reads better than white on `rgb` (WCAG relative luminance: the crossover of the two contrasts). */
19
50
  export declare const darkTextOn: (rgb: Rgb) => boolean;
20
51
  /** Whether dark text reads better on a CSS colour (`rgb(...)` or `#rgb`/`#rrggbb`); white when the colour cannot be read. */
21
52
  export declare function darkTextOnColor(color: string): boolean;
22
- export {};
23
53
  //# sourceMappingURL=divergingScale.d.ts.map
@@ -1 +1 @@
1
- import{registerValueColorScheme as f,resolveValueColorFn as b}from"../../renderer/colorSchemes.js";import{SIGNED_HIGH as x,SIGNED_LOW as p}from"./palette.js";const c=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)],s=[247,247,247],l=(n,e,r)=>[n[0]+(e[0]-n[0])*r,n[1]+(e[1]-n[1])*r,n[2]+(e[2]-n[2])*r],g=c(p),u=c(x),I=[g,l(g,s,.5),s,l(u,s,.5),u],h=[[213,94,0],[230,159,0],[240,228,66],[86,180,233],[0,114,178]];function d(n,e){const r=Math.min(1,Math.max(0,Number.isFinite(e)?e:.5))*(n.length-1),t=Math.min(n.length-2,Math.floor(r)),i=r-t,o=n[t],a=n[t+1];return[o[0]+(a[0]-o[0])*i,o[1]+(a[1]-o[1])*i,o[2]+(a[2]-o[2])*i]}const m=([n,e,r])=>`rgb(${Math.round(n)}, ${Math.round(e)}, ${Math.round(r)})`;export const divergingRgb=n=>d(I,n),divergingColor=n=>m(divergingRgb(n)),ratingRgb=n=>d(h,n),PLOT_GRADIENTS=[{name:"diverging",label:"Blue to orange, around zero"},{name:"rating",label:"Rating: orange-red to blue (colour-blind safe)"}];f("diverging",{label:PLOT_GRADIENTS[0].label,forValue:divergingColor});export function plotGradient(n,e,r,t){const i=n??(r?"diverging":t?"rating":void 0),o=i==="diverging"?divergingColor:i==="rating"?a=>m(ratingRgb(a)):b(i);return e?a=>o(1-a):o}function N([n,e,r]){const t=i=>{const o=i/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4};return .2126*t(n)+.7152*t(e)+.0722*t(r)}export const darkTextOn=n=>N(n)>.179;export function darkTextOnColor(n){const e=/^rgba?\(\s*(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)/i.exec(n);if(e)return darkTextOn([Number(e[1]),Number(e[2]),Number(e[3])]);const r=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());if(!r)return!1;const t=r[1].length===3?[...r[1]].map(i=>i+i).join(""):r[1];return darkTextOn([parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)])}
1
+ import{resolveValueColorFn as F}from"../../renderer/colorSchemes.js";import{countColor as v,cssRgb as s,dataColorsFor as a,measuredColor as y,ratingColor as d,ratingT as m,RATING_BREAKS as C,shortfallRgb as A,signedColor as b}from"../../renderer/dataColors.js";import{parseCssColor as T,relativeLuminance as R}from"../../renderer/colorMap.js";const p={card:"#f5f5f5",text:"#111111"},c=o=>{const e=T(o.card);return!!e&&R(e)<.2};export const divergingRgb=(o,e,r=p)=>b(o,a(e),c(r)),divergingColor=(o,e,r)=>s(divergingRgb(o,e,r)),ratingRgb=(o,e=p,r)=>d(Number.isFinite(o)?o:1,a(r),c(e)),shortfallBarColor=(o,e=p,r)=>s(A(o,a(r),c(e))),yieldColor=(o,e,r)=>s(ratingRgb(m(o),e,r)),scaleT=(o,e)=>o.rating?m(e):(e-o.lo)/(o.hi-o.lo||1),ratingKeyTicks=()=>C.slice(1,-1).map((o,e)=>({at:(e+1)/(C.length-1),text:`${o}`}));export function plotGradient(o,e,r,h,u,k,f={}){const l=u?c(u):!1,i=a(f.dataColors),x=o||void 0;let n,g=!!e;return x?n=F(x,!1,l):r?n=t=>s(b(t,i,l)):h?n=t=>s(d(Number.isFinite(t)?t:1,i,l)):k?n=t=>s(v(t,i,l)):(n=t=>s(y(t,i,!1,f.greyscaleValues)),f.reverseValueScheme&&(g=!g)),g?t=>n(1-t):n}export const darkTextOn=o=>R(o)>.179;export function darkTextOnColor(o){const e=T(o);return e?darkTextOn(e):!1}