@wafertools/wafermap 0.36.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +385 -0
  3. package/README.md +7 -7
  4. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  6. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  10. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  13. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  15. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/patCard.d.ts +23 -0
  17. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  18. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  19. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  20. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  21. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  23. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  24. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  25. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  26. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  27. package/dist/packages/canvas-adapter/dieList.js +2 -2
  28. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  29. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  30. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  31. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  32. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  34. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  35. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  36. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  37. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  38. package/dist/packages/canvas-adapter/icons.js +1 -1
  39. package/dist/packages/canvas-adapter/insightsTab.d.ts +52 -2
  40. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  41. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  42. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  43. package/dist/packages/canvas-adapter/patMode.d.ts +27 -0
  44. package/dist/packages/canvas-adapter/patMode.js +1 -0
  45. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  46. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  47. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  48. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  49. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  50. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  51. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  52. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  53. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  54. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  55. package/dist/packages/canvas-adapter/summaryPanel.d.ts +15 -5
  56. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  57. package/dist/packages/canvas-adapter/toolbar.d.ts +17 -2
  58. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  59. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  60. package/dist/packages/canvas-adapter/userGuideHtml.js +590 -140
  61. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  62. package/dist/packages/canvas-adapter/version.js +1 -1
  63. package/dist/packages/core/classify.d.ts +11 -0
  64. package/dist/packages/core/classify.js +1 -1
  65. package/dist/packages/core/dies.d.ts +2 -0
  66. package/dist/packages/core/dies.js +1 -1
  67. package/dist/packages/core/wafer.d.ts +2 -2
  68. package/dist/packages/renderer/buildView.js +1 -1
  69. package/dist/packages/renderer/buildWaferMap.d.ts +2 -0
  70. package/dist/packages/renderer/buildWaferMap.js +1 -1
  71. package/dist/packages/renderer/deprecate.d.ts +2 -8
  72. package/dist/packages/renderer/deprecate.js +1 -1
  73. package/dist/packages/renderer/fmt.js +1 -1
  74. package/dist/packages/renderer/testLabel.d.ts +0 -11
  75. package/dist/packages/renderer/testLabel.js +1 -1
  76. package/dist/packages/stats/analyzeWaferLot.d.ts +6 -0
  77. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  78. package/dist/packages/stats/analyzeWaferMap.d.ts +8 -0
  79. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  80. package/dist/packages/stats/binPareto.d.ts +2 -54
  81. package/dist/packages/stats/binPareto.js +1 -1
  82. package/dist/packages/stats/binRows.js +1 -1
  83. package/dist/packages/stats/capability.d.ts +10 -0
  84. package/dist/packages/stats/capability.js +1 -1
  85. package/dist/packages/stats/cardSpec.d.ts +53 -0
  86. package/dist/packages/stats/cardSpec.js +1 -0
  87. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  88. package/dist/packages/stats/chartCatalogue.js +1 -0
  89. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  90. package/dist/packages/stats/clusterDetection.js +1 -1
  91. package/dist/packages/stats/commonality.d.ts +62 -0
  92. package/dist/packages/stats/commonality.js +1 -0
  93. package/dist/packages/stats/control.d.ts +21 -0
  94. package/dist/packages/stats/control.js +1 -0
  95. package/dist/packages/stats/correlation.d.ts +9 -3
  96. package/dist/packages/stats/correlation.js +1 -1
  97. package/dist/packages/stats/dieRegions.d.ts +4 -1
  98. package/dist/packages/stats/dieRegions.js +1 -1
  99. package/dist/packages/stats/differenceMap.d.ts +22 -0
  100. package/dist/packages/stats/differenceMap.js +1 -0
  101. package/dist/packages/stats/examplePicks.d.ts +22 -0
  102. package/dist/packages/stats/examplePicks.js +1 -0
  103. package/dist/packages/stats/filterFile.d.ts +41 -0
  104. package/dist/packages/stats/filterFile.js +2 -0
  105. package/dist/packages/stats/filterFindings.d.ts +20 -5
  106. package/dist/packages/stats/filterFindings.js +1 -1
  107. package/dist/packages/stats/groupCompare.d.ts +87 -0
  108. package/dist/packages/stats/groupCompare.js +1 -0
  109. package/dist/packages/stats/guideSections.d.ts +55 -0
  110. package/dist/packages/stats/guideSections.js +1 -0
  111. package/dist/packages/stats/index.d.ts +3 -1
  112. package/dist/packages/stats/index.js +1 -1
  113. package/dist/packages/stats/math.d.ts +29 -4
  114. package/dist/packages/stats/math.js +1 -1
  115. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  116. package/dist/packages/stats/metadataColumns.js +1 -1
  117. package/dist/packages/stats/pat.d.ts +58 -0
  118. package/dist/packages/stats/pat.js +1 -0
  119. package/dist/packages/stats/patSummary.d.ts +45 -0
  120. package/dist/packages/stats/patSummary.js +1 -0
  121. package/dist/packages/stats/patternClassification.d.ts +3 -3
  122. package/dist/packages/stats/patternClassification.js +1 -1
  123. package/dist/packages/stats/plotData.d.ts +294 -17
  124. package/dist/packages/stats/plotData.js +1 -1
  125. package/dist/packages/stats/plotId.d.ts +2 -0
  126. package/dist/packages/stats/plotId.js +1 -1
  127. package/dist/packages/stats/plotReferences.d.ts +17 -0
  128. package/dist/packages/stats/plotReferences.js +1 -0
  129. package/dist/packages/stats/plotSpec.d.ts +239 -3
  130. package/dist/packages/stats/plotSpec.js +4 -4
  131. package/dist/packages/stats/regions.js +1 -1
  132. package/dist/packages/stats/renderSummaryReport.js +31 -31
  133. package/dist/packages/stats/reportHtml.js +9 -13
  134. package/dist/packages/stats/synthesis.d.ts +44 -16
  135. package/dist/packages/stats/synthesis.js +1 -1
  136. package/dist/packages/stats/testPassRate.d.ts +7 -0
  137. package/dist/packages/stats/testPassRate.js +1 -1
  138. package/dist/packages/stats/types.d.ts +13 -8
  139. package/dist/packages/stats/yield.d.ts +3 -11
  140. package/dist/packages/stats/yield.js +1 -1
  141. package/llms.txt +1 -1
  142. package/package.json +10 -2
  143. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  144. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  145. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  146. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  147. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  148. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  149. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  150. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  151. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  152. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  153. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  154. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  155. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  156. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  157. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  158. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1,15 +1,13 @@
1
1
  import { type OverlayHandle, type SaveImageHandler } from '../toolbar.js';
2
+ import type { CardAboutLine } from './cardAbout.js';
3
+ import type { GuideSection } from '../../stats/guideSections.js';
2
4
  import { robustFence } from '../../stats/math.js';
3
5
  export type { SaveImageHandler };
4
6
  /**
5
- * The card's own expand button is hidden for the modal's duration and shown
6
- * again on close — a card already sitting inside its own expand modal must
7
- * not offer a second "expand" of itself: clicking it would reparent the same
8
- * card into a *second*, nested modal, leaving the first one open but empty
9
- * (found via exactly that — every card kept its expand icon once expanded).
10
- * The button is found on the card (`data-wmap-chart-expand`) rather than
11
- * passed in, so a card opened straight into a modal by something other than
12
- * its own button — a drilldown — gets the same treatment.
7
+ * Opens a card in its own resizable window. While it is there (`data-wmap-expanded`) the card's Expand button is
8
+ * hidden: expanding a card already in its window would reparent it into a second, nested window and leave the first
9
+ * one empty. The flag is on the card, so a card opened straight into a window by something other than its own button
10
+ * (a drilldown) gets the same treatment.
13
11
  *
14
12
  * `opts.anchor` is for a card that is not on the page yet (see
15
13
  * `ReparentModalOptions.anchor`); `opts.onClosed` runs once the modal has
@@ -44,6 +42,8 @@ export interface ChartCanvasColors {
44
42
  * limit line and its label need.
45
43
  */
46
44
  limitLine: string;
45
+ /** A point that breaks a rule (a control chart's out-of-control wafer): the theme's error text colour, readable on a panel. */
46
+ alert: string;
47
47
  /**
48
48
  * Gridlines: `border` at `GRID_ALPHA`. A gridline is a reading aid behind the
49
49
  * data; drawn at full `border` strength (the axis colour) it competed with the
@@ -289,6 +289,23 @@ export interface CardShell {
289
289
  body: HTMLElement;
290
290
  /** What the card's Save as PNG adds under the title, besides the canvas (a caption, a legend). Read at the moment of saving. */
291
291
  setPngDecor(read: () => PngDecor | undefined): void;
292
+ /** The canvas Save as PNG saves, made at the moment of saving, for a card that draws more than one (a grid of panels).
293
+ * Absent = the card's first canvas. */
294
+ setPngCanvas(make: () => HTMLCanvasElement | null): void;
295
+ /** The one line "About this chart" (or "About this table") shows (`cardAbout`). Absent = the menu has no About row. */
296
+ setAbout(line: CardAboutLine | undefined): void;
297
+ /** Rows of the card's own in its ⋯ menu, after Save as PNG (Edit as plot). Read each time the menu opens. */
298
+ setMenuRows(read: () => CardMenuRow[]): void;
299
+ }
300
+ /** A row of a card's own in its ⋯ menu: an action, or one greyed with the reason it cannot run now. */
301
+ export interface CardMenuRow {
302
+ label: string;
303
+ onClick: () => void;
304
+ disabledHint?: string;
305
+ }
306
+ export interface CardShellOptions {
307
+ /** Default true. False for a card whose image is saved by something else (a panel of a grid, saved with the grid). */
308
+ png?: boolean;
292
309
  }
293
310
  /**
294
311
  * THE colour chip that stands for a data series, everywhere in the chart suite.
@@ -342,13 +359,36 @@ export interface SeriesLegendItem {
342
359
  */
343
360
  export declare function makeSeriesLegendItem(label: string, color: string, ownerDocument?: Document): SeriesLegendItem;
344
361
  export declare function cardFrameStyle(): Partial<CSSStyleDeclaration>;
345
- export declare function cardShell(title: string, onSaveImage?: SaveImageHandler, ownerDocument?: Document): CardShell;
362
+ export declare function cardShell(title: string, onSaveImage?: SaveImageHandler, ownerDocument?: Document, opts?: CardShellOptions): CardShell;
363
+ /**
364
+ * "How to read this: *Control charts* in the user guide" (no full stop), the title a link that opens the guide at that
365
+ * section, beside the app (a separate window where the platform allows one, otherwise a floating window over it); an
366
+ * open guide moves there. A saved image or print carries `guideCiteText` instead.
367
+ */
368
+ export declare function guideCite(doc: Document, section: GuideSection, lead?: string): HTMLSpanElement;
369
+ /** A footnote's "how to read this: *A* and *B* in the user guide", each title a link (`guideCite`). Nothing for none. */
370
+ export declare function appendGuideCites(el: HTMLElement, sections: readonly GuideSection[]): void;
371
+ /** A text box's look in an editor: the one style the plot, sweep and filter editors' boxes share. */
372
+ export declare function inputStyle(): Partial<CSSStyleDeclaration>;
346
373
  export declare function makeSegmented(
347
374
  /** An option's optional third element is its hover hint, for a label that does not explain itself. */
348
375
  options: Array<[value: string, label: string, hint?: string]>, current: string, onChange: (value: string) => void, ownerDocument?: Document,
349
376
  /** Smaller type/padding for the summary panel's 260px column, where the
350
377
  * chart-card sizing overflows a section header. Charts keep the default. */
351
378
  compact?: boolean): HTMLElement;
379
+ /**
380
+ * A table that lists its first `first` rows, with a button to list every one and back. Listed in full it scrolls inside
381
+ * `scroller` after `ALL_ROWS_MAX_PX`, so a lot of a hundred wafers is a scrolling table in a card of the usual size,
382
+ * never a card as tall as all its rows (which also stretches every card beside it in the grid). `fill(all)` writes the
383
+ * rows; the button is returned for the caller to place under the table. No button shows when every row fits the first.
384
+ */
385
+ export declare function firstRowsToggle(doc: Document, o: {
386
+ total: number;
387
+ first: number;
388
+ noun: string;
389
+ scroller: HTMLElement;
390
+ fill: (all: boolean) => void;
391
+ }): HTMLButtonElement;
352
392
  export declare function makeBackButton(onBack: () => void, ownerDocument?: Document): HTMLButtonElement;
353
393
  export declare function renderEmptyState(body: HTMLElement, message: string, styleOverrides?: Partial<CSSStyleDeclaration>): void;
354
394
  export interface ListSelectOption {
@@ -563,7 +603,11 @@ export interface AxisPrefs {
563
603
  /** Which limits the charts draw. Undefined = `'both'`. */
564
604
  limits?: LimitsShown;
565
605
  }
566
- export type LimitKind = 'test' | 'spec';
606
+ /**
607
+ * `pat`: one wafer's part-average-testing limits (stats/pat.ts), drawn only on a plot of that wafer; `whatif`: proposed limits
608
+ * for a histogram or probability plot; `ref`: a line or band the reader put on the axis.
609
+ */
610
+ export type LimitKind = 'test' | 'spec' | 'pat' | 'whatif' | 'ref';
567
611
  /** The Insights "Limits" choice. */
568
612
  export type LimitsShown = 'test' | 'spec' | 'both' | 'none';
569
613
  export interface LimitLine {
@@ -572,12 +616,14 @@ export interface LimitLine {
572
616
  /** Which end of its pair: the low limit or the high one. */
573
617
  end: 'lo' | 'hi';
574
618
  label: string;
619
+ /** A reference band: the other edge, shaded between it and `value`. Set on the band's lower line only. */
620
+ bandTo?: number;
575
621
  }
576
622
  export declare const LIMIT_LABEL: Readonly<Record<LimitKind, {
577
623
  lo: string;
578
624
  hi: string;
579
625
  }>>;
580
- /** Canvas dash pattern per kind: short dashes for test limits, long for spec. */
626
+ /** Canvas dash pattern per kind: short dashes for test limits, long for spec, dots for PAT. */
581
627
  export declare const LIMIT_DASH: Readonly<Record<LimitKind, number[]>>;
582
628
  export declare const LIMITS_SHOWN_OPTIONS: ReadonlyArray<{
583
629
  value: LimitsShown;
@@ -588,6 +634,10 @@ type LimitSource = {
588
634
  limitHigh?: number;
589
635
  specLow?: number;
590
636
  specHigh?: number;
637
+ patLow?: number;
638
+ patHigh?: number;
639
+ whatIfLow?: number;
640
+ whatIfHigh?: number;
591
641
  } | undefined;
592
642
  /** Whether a test has both kinds of limit — the only case with a choice to make. */
593
643
  export declare function hasBothLimitKinds(def: LimitSource): boolean;
@@ -720,5 +770,8 @@ export declare function drawOffAxisLimits(ctx: CanvasRenderingContext2D, offAxis
720
770
  }, orient: 'horizontal' | 'vertical', color: string, format: (v: number) => string,
721
771
  /** Panel colour to back each marker with (`fillTextOnHalo`), for charts
722
772
  * where lines can run under the markers. */
723
- halo?: string): void;
773
+ halo?: string,
774
+ /** Labels already on the plot (the other axis's limits): each marker steps inward clear of them, and is added, so a
775
+ * label placed after it keeps clear of it too. */
776
+ taken?: LabelBox[]): void;
724
777
  //# sourceMappingURL=chartShell.d.ts.map
@@ -1 +1 @@
1
- import{SHADOW as V,LEADING as G,wireTooltip as U,wireControlHover as B,controlStyle as j,SPACE as w,RADIUS as T,fontPx as F,FONT as L,CLR as m,Z_BASE as ie,menuLayerFor as re,wireListNavigation as le,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as se,markMenuTrigger as N,markNoPrint as P,saveImageBlob as ae,openReparentedModal as ce}from"../toolbar.js";import{ICONS as K}from"../icons.js";import{minOf as de,maxOf as ue}from"../../core/utils.js";import{robustFence as Y}from"../../stats/math.js";import{fmt as pe,fmtColorbarAxis as fe}from"../../renderer/fmt.js";import{markedTestLabel as me,DERIVED_LANE_PAD as he}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,n={}){for(const s of e.querySelectorAll('div[style*="position: absolute"]'))s.style.display==="block"&&s.style.pointerEvents==="none"&&(s.style.display="none");const t=e.querySelector("[data-wmap-chart-expand]"),i=e.getAttribute("style")??"",r=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const l=ce([e],{title:o,anchor:n.anchor,ownerDocument:e.ownerDocument,boxSize:xe[r],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),t&&(t.style.display="flex"),n.onClosed?.()}});if(!l)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),null;if(t&&(t.style.display="none"),r==="rows"){const s=()=>{const a=Number(e.dataset.wmapChartFullH);if(!a)return;const p=l.box.offsetHeight-l.contentWrap.clientHeight;l.setNaturalHeight(`min(90vh, ${Math.ceil(p+a)}px)`)};s(),(e.ownerDocument.defaultView??window).requestAnimationFrame(s)}return l}const xe={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 n=e.trim();let t,i,r,l=1;const s=n.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=n.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const p=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[t,i,r]=[0,2,4].map(c=>parseInt(p.slice(c,c+2),16)),p.length===8&&(l=parseInt(p.slice(6,8),16)/255)}else if(a)[t,i,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(${t}, ${i}, ${r}, ${+(l*o).toFixed(3)})`}const ge={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309"},Z={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),n={};for(const t of Object.keys(Z)){const i=o.getPropertyValue(`--wmap-${Z[t]}`).trim();n[t]=i||ge[t]}return n.grid=withAlpha(n.border,GRID_ALPHA),n}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const n=e.ownerDocument.defaultView??window;let t=0;const i=new n.ResizeObserver(()=>{t||(t=n.requestAnimationFrame(()=>{t=0,o()}))});return i.observe(e),{disconnect:()=>{t&&n.cancelAnimationFrame(t),t=0,i.disconnect()}}}export function growCardToFitContent(e,o,n){const t=`${W(e,o)+n}px`;e.style.minHeight!==t&&(e.style.minHeight=t)}function W(e,o){const n=e.ownerDocument.defaultView??window,t=n.getComputedStyle(e);let i=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=n.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(i+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return t.boxSizing==="border-box"&&(i+=(parseFloat(t.paddingTop)||0)+(parseFloat(t.paddingBottom)||0)+(parseFloat(t.borderTopWidth)||0)+(parseFloat(t.borderBottomWidth)||0)),i}function J(e,o){const n=e.ownerDocument.defaultView??window;let t=0;for(const i of Array.from(e.children)){if(i===o)continue;const r=i,l=n.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(t+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return t}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,n){const t=e.toLocaleString(),i=e===1?"die":"dies";return n?e===o?`${t} ${i} ${n}`:`${t} of ${o.toLocaleString()} dies ${n} (partial and edge-excluded dies left out)`:`${t} ${i}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,n){const i=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(i.paddingTop)||0)-(parseFloat(i.paddingBottom)||0),l=i.boxSizing==="border-box"?(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0):0;return r-(W(e,o)-l)-(n?J(o,n):0)}export function fitRowsHeight(e,o,n,t,i=0){if(growCardToFitContent(e,o,i+n),e.dataset.wmapChartFullH=String(Math.ceil(W(e,o)+i+t)),!isExpandedCard(e))return n;const r=bodyRoom(e,o)-i;return Math.max(n,Math.min(t,Math.floor(r)))}export function chartFillHeight(e,o,n,t){const i=J(o,n);return growCardToFitContent(e,o,i+t),Math.max(t,o.clientHeight-i)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,n,t){const i=chartDpr(e);e.width=Math.max(1,Math.floor(n*i)),e.height=Math.max(1,Math.floor(t*i)),e.style.width=`${n}px`,e.style.height=`${t}px`;const r=e.getContext("2d");return r?(r.setTransform(i,0,0,i,0,0),r.clearRect(0,0,n,t),r.font=`${F(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let n;if(typeof o=="number")n=o;else{const t=(o.ownerDocument.defaultView??window).getComputedStyle(o);n=o.offsetTop+o.offsetHeight+(parseFloat(t.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${n}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:pe(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,n){if(!o&&n===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:t,axisLabel:i,scaledUnit:r}=fe(e,null,o,"engineering",n);return{tick:t,tickWithUnit:r?l=>`${t(l)} ${r}`:t,unitLabel:i}}const be=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,n){return(t,i)=>{const r=makeAxisFormat(o,n,t).tick;return i.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+be}}export function drawAxisUnit(e,o,n,t,i){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${F(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=i,e.fillText(`(${o})`,n,t),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 M=(e,o)=>{for(let n=e;n&&n!==o.parentElement;n=n.parentElement)if(n.style.display==="none")return!1;return!0},ye=/\s*[▾▼]\s*$/,_=new WeakMap;export function describeCard(e){const o=[],n=e.querySelector("[data-wmap-controls]");if(n){for(const l of n.querySelectorAll("button[aria-haspopup]")){if(!M(l,n))continue;const s=(l.textContent??"").replace(ye,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of n.querySelectorAll('[role="radiogroup"]')){if(!M(l,n))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of n.querySelectorAll('input[type="checkbox"]:checked')){if(!M(l,n))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const t=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!M(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&t.push(s)}const i=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&i.push({label:p,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,p=(l.textContent??"").trim();p&&a&&a!=="transparent"&&i.push({label:p,color:a})}const r=_.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(t.length=0,t.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(i.length=0,i.push(...r.legend))),{controls:o,captions:t,legend:i}}function we(e){const o=describeCard(e),n=_.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:n?.colorbar}}function Q(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const n=o.querySelector(":scope > [data-wmap-print-only]");if(!n)continue;const t=describeCard(o);n.replaceChildren();const i=[t.controls.length?t.controls.join(" \xB7 "):"",...t.captions].filter(Boolean);for(const r of i){const l=e.createElement("div");l.textContent=r,n.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ee=new WeakSet;function Ce(e){if(ee.has(e))return;ee.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const n=e.defaultView;n?.addEventListener("beforeprint",()=>Q(e));try{n?.matchMedia?.("print").addEventListener?.("change",t=>{t.matches&&Q(e)})}catch{}}function Se(e){const o=e.ownerDocument.defaultView;for(let n=e;n&&o;n=n.parentElement){const t=o.getComputedStyle(n).backgroundColor;if(t&&t!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(t))return t}return"#ffffff"}export function composeChartPng(e,o){const n=e.ownerDocument,t=n.createElement("canvas"),i=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=n.createElement("canvas").getContext("2d"),s=12*i,a=(f,y="400")=>`${y} ${f*i}px system-ui, -apple-system, "Segoe UI", sans-serif`,p=(f,y)=>l?(l.font=y,l.measureText(f).width):f.length*7*i,c=[];let d=0;if(o){d=s,c.push({kind:"text",text:o.title,x:s,y:d+14*i,font:a(16,"600"),alpha:1}),d+=24*i;const f=o.decor,y=[];f?.controls?.length&&y.push({text:f.controls.join(" \xB7 "),alpha:1});for(const h of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)y.push({text:h,alpha:.75});const g=a(12);for(const{text:h,alpha:C}of y){let b="";for(const E of h.split(" ")){const O=b?`${b} ${E}`:E;b&&p(O,g)>r-2*s?(c.push({kind:"text",text:b,x:s,y:d+11*i,font:g,alpha:C}),d+=17*i,b=E):b=O}b&&(c.push({kind:"text",text:b,x:s,y:d+11*i,font:g,alpha:C}),d+=17*i)}if(f?.legend?.length){d+=4*i;const h=a(12);let C=s;for(const b of f.legend){const E=14*i+p(b.label,h)+14*i;C>s&&C+E>r-s&&(C=s,d+=18*i),c.push({kind:"dot",x:C+5*i,y:d+7*i,r:5*i,color:b.color}),c.push({kind:"text",text:b.label,x:C+14*i,y:d+11*i,font:h,alpha:1}),C+=E}d+=20*i}if(f?.colorbar){d+=4*i;const h=a(12),C=f.colorbar;let b=s;c.push({kind:"text",text:C.label,x:b,y:d+10*i,font:h,alpha:1}),b+=p(C.label,h)+10*i,c.push({kind:"text",text:C.lo,x:b,y:d+10*i,font:h,alpha:.75}),b+=p(C.lo,h)+6*i,c.push({kind:"strip",x:b,y:d+1*i,w:200*i,h:10*i,color:C.color}),b+=206*i,c.push({kind:"text",text:C.hi,x:b,y:d+10*i,font:h,alpha:.75}),d+=20*i}d+=6*i}t.width=r,t.height=Math.ceil(e.height+d);const u=t.getContext("2d");if(u.fillStyle=o?Se(o.card):"#ffffff",u.fillRect(0,0,t.width,t.height),o){const f=n.defaultView,y=f&&f.getComputedStyle(o.card).color||"#222222";u.textBaseline="alphabetic";for(const g of c)if(g.kind==="text")u.font=g.font,u.fillStyle=y,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 h=0;h<g.w;h++)u.fillStyle=g.color(h/Math.max(1,g.w-1)),u.fillRect(g.x+h,g.y,1,g.h)}return u.drawImage(e,0,d),t}export function saveCanvasPng(e,o,n,t){composeChartPng(e,t).toBlob(i=>{i&&ae(i,o,n)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${T.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const ve="0.35";export function makeSeriesLegendItem(e,o,n=document){const t=n.createElement("button");t.type="button",Object.assign(t.style,{display:"inline-flex",alignItems:"center",gap:w.xs,padding:`${w.xs} ${w.md}`,borderRadius:T.pill,border:`1px solid ${m.menuBorder}`,background:"none",cursor:"pointer",fontSize:L.body,color:m.text,whiteSpace:"nowrap"}),B(t,"bare");const i=n.createElement("span");return i.style.cssText=chartSwatchCss(o),t.append(i,n.createTextNode(e)),{el:t,setState({selected:r,dimmed:l}){t.style.borderColor=r?m.iconActive:m.menuBorder,t.style.fontWeight=r?"600":"400",t.style.opacity=l?ve:"1",t.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:m.menuBg,border:`1px solid ${m.menuBorder}`,borderRadius:T.container,padding:w.xl,fontVariantNumeric:"tabular-nums"}}export function cardShell(e,o,n=document){const t=n.createElement("div");t.dataset.wmapChartCard="1",t.dataset.wmapChartTitle=e,Object.assign(t.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const i=t.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",gap:w.sm,paddingBottom:"6px",marginBottom:w.md,borderBottom:`1px solid ${m.menuBorder}`});const r=t.ownerDocument.createElement("div");r.textContent=e,Object.assign(r.style,{color:m.value,fontSize:L.heading,fontWeight:"600",flex:"1"}),i.appendChild(r);const l=makeTooltip(t),s=t.ownerDocument.createElement("button");s.type="button",s.setAttribute("aria-label","Save as PNG"),s.innerHTML=K.download,Object.assign(s.style,{...j("outlined"),color:m.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(s),attachChartTip(s,t,l,"Save as PNG"),s.addEventListener("click",()=>{const u=t.querySelector("canvas");u&&saveCanvasPng(u,r.textContent||e,o,{card:t,title:r.textContent||e,decor:we(t)})}),P(s),i.appendChild(s);const a=t.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=K.expand,Object.assign(a.style,{...j("outlined"),color:m.label,padding:"0",width:"22px",height:"22px",lineHeight:G.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),B(a),attachChartTip(a,t,l,"Expand"),a.dataset.wmapChartExpand="1",a.addEventListener("click",()=>openChartExpandModal(t,r.textContent??e)),P(a),i.appendChild(a),t.appendChild(i);const p=t.ownerDocument.createElement("div");p.dataset.wmapPrintOnly="1",Object.assign(p.style,{display:"none",color:m.label,fontSize:L.body,marginBottom:w.sm}),t.appendChild(p),Ce(t.ownerDocument);const c=t.ownerDocument.createElement("div");c.dataset.wmapControls="1",Object.assign(c.style,{display:"flex",gap:w.sm,marginBottom:w.md,flexWrap:"wrap",alignItems:"center"}),P(c),t.appendChild(c);const d=t.ownerDocument.createElement("div");return Object.assign(d.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),t.appendChild(d),{card:t,heading:r,controlsRow:c,body:d,setPngDecor:u=>{_.set(t,u)}}}export function makeSegmented(e,o,n,t=document,i=!1){const r=t.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",border:`1px solid ${m.menuBorder}`,borderRadius:T.control,overflow:"hidden"});const l=`seg-${Math.random().toString(36).slice(2,9)}`,s=[];return e.forEach(([a,p,c],d)=>{const u=t.createElement("label");c&&U(u,c),Object.assign(u.style,{display:"inline-flex",alignItems:"center",fontSize:L.body,padding:i?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",borderLeft:d>0?`1px solid ${m.menuBorder}`:"none"}),B(u,"bare");const f=t.createElement("input");f.type="radio",f.name=l,f.value=a,f.checked=a===o,Object.assign(f.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const y=()=>{u.style.background=f.checked?m.bgActive:m.menuBg,u.style.color=f.checked?m.iconActive:m.text,u.dataset.on=f.checked?"true":"false"};s.push(y),y(),f.addEventListener("change",()=>{if(f.checked){for(const g of s)g();n(a)}}),u.append(f,t.createTextNode(p)),r.appendChild(u)}),r}export function makeBackButton(e,o=document){const n=o.createElement("button");return n.type="button",n.textContent="\u2190 Back",Object.assign(n.style,{...j("outlined"),background:m.menuBg,color:m.label}),B(n),n.addEventListener("click",e),n}export function renderEmptyState(e,o,n){const t=e.ownerDocument.createElement("div");t.textContent=o,Object.assign(t.style,{color:m.label,fontSize:L.body,padding:"8px 0"}),n&&Object.assign(t.style,n),e.appendChild(t)}export function makeListSelect(e,o,n,t={}){const{maxWidth:i="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:p}=t;let c=o;const d=k=>e.find(D=>D.value===k)?.label??"",u=r.createElement("button");u.type="button",p&&(u.dataset.wmapSelect=p),l&&u.setAttribute("aria-label",l),Object.assign(u.style,{fontSize:L.body,padding:`${w.xxs} ${w.sm}`,background:m.menuBg,color:m.text,border:`1px solid ${m.menuBorder}`,borderRadius:T.control,maxWidth:i,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:w.sm,justifyContent:"space-between"}),B(u),N(u,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const y=r.createElement("span");y.textContent="\u25BE",y.style.flex="0 0 auto",u.append(f,y);const g=()=>{f.textContent=e.length===0?s??"(none)":d(c)||s||"(none)"};if(g(),e.length===0)return u.disabled=!0,u.style.opacity="0.6",u.style.cursor="default",Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,g()}});let h=null;const C=()=>{h&&(h.remove(),h=null,N(u,!1))},b=()=>{C(),u.focus()};function E(){const k=u.getBoundingClientRect(),D=r.defaultView??window,z=Math.max(k.width,220),ne=Math.min(k.left,Math.max(4,(D.innerWidth??1/0)-z-4));h=r.createElement("div"),h.setAttribute("role","listbox"),h.setAttribute("aria-label",l??"Options"),Object.assign(h.style,{position:"fixed",top:`${k.bottom+4}px`,left:`${ne}px`,background:m.menuBg,border:`1px solid ${m.menuBorder}`,borderRadius:T.control,boxShadow:V.menu,zIndex:ie,minWidth:`${z}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const A=[],H=()=>A.filter(x=>x.row.style.display!=="none").map(x=>x.row),I=[],oe=()=>{for(const x of I)x.el.style.display=A.slice(x.first,x.last+1).some(S=>S.row.style.display!=="none")?"":"none"};if(e.length>X){const x=se(S=>{for(const v of A)v.row.style.display=v.label.includes(S)?"":"none";oe()},a,r);Object.assign(x.style,{position:"sticky",top:"0",zIndex:"1",background:m.menuBg}),x.addEventListener("keydown",S=>{if(S.key==="Escape"){S.preventDefault(),b();return}S.key==="ArrowDown"&&(S.preventDefault(),H()[0]?.focus())}),h.appendChild(x)}let q;for(const x of e){if(x.group!==void 0&&x.group!==q){const $=r.createElement("div");$.textContent=x.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${w.sm} ${w.xl} ${w.xxs}`,fontSize:L.sub,color:m.label,fontWeight:"600"}),h.appendChild($),I.push({el:$,first:A.length,last:A.length})}q=x.group;const S=x.value===c,v=r.createElement("div");v.textContent=x.disabled?`${x.label} \u2014 ${x.disabled}`:x.label,v.setAttribute("role","option"),v.setAttribute("aria-selected",S?"true":"false"),x.disabled&&v.setAttribute("aria-disabled","true"),v.tabIndex=-1,Object.assign(v.style,{padding:`${w.sm} ${w.xl}`,fontSize:L.body,cursor:x.disabled?"default":"pointer",color:x.disabled?m.label:S?m.iconActive:m.text,fontWeight:S?"700":"400",opacity:x.disabled?"0.7":"",background:S?m.menuActive:"transparent",whiteSpace:"nowrap"}),v.addEventListener("mouseenter",()=>{!S&&!x.disabled&&(v.style.background=m.menuHover)}),v.addEventListener("mouseleave",()=>{S||(v.style.background="transparent")}),v.addEventListener("click",$=>{$.stopPropagation(),!x.disabled&&(c=x.value,g(),b(),n(x.value))}),h.appendChild(v),A.push({row:v,label:x.label.toLowerCase()}),I.length&&(I[I.length-1].last=A.length-1)}if(le(h,H,b),re(u).appendChild(h),N(u,!0),e.length<=X){const x=e.findIndex(S=>S.value===c);H()[x>=0?x:0]?.focus()}}u.addEventListener("click",k=>{if(k.stopPropagation(),h){C();return}E()});const O=k=>{if(!u.isConnected){r.removeEventListener("click",O);return}h&&!h.contains(k.target)&&!u.contains(k.target)&&C()};return r.addEventListener("click",O),Object.defineProperty(u,"value",{get:()=>c,set:k=>{c=k,g()}})}export function testOptionLabels(e){const o=e.some(n=>n.derived);return e.map(n=>(o&&!n.derived?he:"")+me(n,n.testNumber))}export function makeTestSelect(e,o,n,t={}){const{maxWidth:i="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=t;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>n(Number(s)),{maxWidth:i,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,n,t=document){let i=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>n({includeLimits:i,clipOutliers:r,limits:l});return{get:()=>({includeLimits:i,clipOutliers:r,limits:l}),sync(a,p,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,d=>{l=d,s()},t)),p&&e.appendChild(makeToggle("Axis includes limits",a,d=>{i=d,s()},t,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,d=>{r=d,s()},t,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const p=a.limits??"both";return a.includeLimits===i&&a.clipOutliers===r&&p===l?!1:(i=a.includeLimits,r=a.clipOutliers,l=p,!0)}}}export function makeLinkedTestSelect(e,o,n,t={}){let i=o;const r=makeTestSelect(e,i,l=>{l!==i&&(i=l,n(l))},t);return{el:r,get:()=>i,set(l){return i===l||!e.some(s=>s.testNumber===l)?!1:(i=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,n,t,i={}){let r=n;const l=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const d=s(c);d!==r&&(r=d,t(d))},{...i,hook:"group-scope"}),p=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(c){return r===c||c!==null&&!e.includes(c)?!1:(r=c,p&&(p.value=l(c)),!0)}}}export function makeWaferSelect(e,o,n,t={}){const{maxWidth:i="160px",allLabel:r="All wafers",ownerDocument:l=document}=t,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,p)=>({value:String(p),label:a.label??`#${p}`}))],o===null?s:String(o),a=>n(a===s?null:Number(a)),{maxWidth:i,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,n,t=document,i){const r=t.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:w.xs,fontSize:L.body,color:m.label,cursor:"pointer",userSelect:"none"}),B(r,"bare");const l=t.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>n(l.checked)),r.append(l,t.createTextNode(e)),i&&U(r,i),r}export function makeLabeledSelect(e,o,n,t,i={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=i,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:m.label,fontSize:L.body,display:"flex",alignItems:"center",gap:w.xs});const p=makeListSelect(o,n,t,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(p),a}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:w.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:T.control,padding:`${w.sm} ${w.xl}`,fontSize:L.sub,fontFamily:L.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:V.menu}),e.appendChild(o),o}export function attachChartTip(e,o,n,t){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=t),e.addEventListener("mouseenter",i=>{n.textContent=t,n.style.display="block",positionChartTooltip(n,o,i.clientX,i.clientY)}),e.addEventListener("mousemove",i=>{n.style.display==="block"&&positionChartTooltip(n,o,i.clientX,i.clientY)}),e.addEventListener("mouseleave",()=>{n.style.display="none"}),e.addEventListener("click",()=>{n.style.display="none"}),e.addEventListener("focus",()=>{n.textContent=t,n.style.display="block";const i=e.getBoundingClientRect();positionChartTooltip(n,o,i.left+i.width/2,i.bottom)}),e.addEventListener("blur",()=>{n.style.display="none"})}export function positionChartTooltip(e,o,n,t){const i=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let p=n-i.left+r,c=t-i.top+r;p+s+l>i.width&&(p=n-i.left-r-s),c+a+l>i.height&&(c=t-i.top-r-a),p=Math.max(l,p),c=Math.max(l,c),e.style.left=`${p}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"}},LIMIT_DASH={test:[3,3],spec:[10,4]},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 R(e,o){const[n,t]=o==="test"?[e?.limitLow,e?.limitHigh]:[e?.specLow,e?.specHigh],i=[];return n!==void 0&&Number.isFinite(n)&&i.push({value:n,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),t!==void 0&&Number.isFinite(t)&&i.push({value:t,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),i}export function hasBothLimitKinds(e){return R(e,"test").length>0&&R(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const n=R(e,"test"),t=R(e,"spec"),i=o==="test"?n:o==="spec"?t:[...n,...t];return i.length?i:[...n,...t]}export function limitExtent(e){if(!e.length)return{};const o=e.map(n=>n.value);return{lo:de(o),hi:ue(o)}}export function placeClearOf(e,o,n,t=6){const i=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<t&&i(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+n,y1:r.y1+n};return e.push(r),r}export function stackLabelRows(e,o=4){const n=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),t=[],i=new Array(e.length).fill(0);for(const r of n){let l=t.findIndex(s=>r.start>=s+o);l===-1?(l=t.length,t.push(r.end)):t[l]=r.end,i[r.i]=l}return i}export function fillTextOnHalo(e,o,n,t,i){if(i){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=i,e.fillRect(n-r.actualBoundingBoxLeft-l,t-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,n,t)}export function strokeLimitLine(e,o,n,t,i,r,l){e.save(),e.strokeStyle=n,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(t,i),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,n=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,t=>o(t),{maxWidth:"170px",hook:"limits-shown",ownerDocument:n})}export{Y as robustFence};export function shouldIncludeLimitsByDefault(e,o,n,t,i=1/3){if(n===void 0&&t===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,n??e),s=Math.max(o,t??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=i}export function resolveAxisRange(e){const{dataMin:o,dataMax:n,limits:t=[],includeLimits:i,clipOutliers:r,values:l}=e;let s=o,a=n,p=0;if(r&&l?.length){const d=Y(l);if(d){const u=Math.max(s,d.lo),f=Math.min(a,d.hi);f>u&&(p=l.filter(y=>Number.isFinite(y)&&(y<u||y>f)).length,s=u,a=f)}}if(i)for(const d of t)s=Math.min(s,d.value),a=Math.max(a,d.value);s===a&&(s-=1,a+=1);const c=[];for(const d of t)d.value<s?c.push({value:d.value,label:d.label,side:"lo"}):d.value>a&&c.push({value:d.value,label:d.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:p}}export function limitLabelSide(e,o,n,t,i,r=3){const l=i?-1:1;return(l<0?e-r-o>=n:e+r+o<=t)?l:-l}export function drawOffAxisLimits(e,o,n,t,i,r,l){if(!o.length)return;e.save(),e.fillStyle=i,e.font=`${F(-1)}px system-ui, sans-serif`;const s={lo:0,hi:0},a=F(-1)+2;for(const{value:p,label:c,side:d}of o){const u=s[d]++*a,f=t==="horizontal"?d==="lo"?"\u2190":"\u2192":d==="lo"?"\u2193":"\u2191",y=d==="lo"?`${f} ${c} ${r(p)}`:`${c} ${r(p)} ${f}`;t==="horizontal"?(e.textBaseline="top",e.textAlign=d==="lo"?"left":"right",fillTextOnHalo(e,y,d==="lo"?n.left+2:n.right-2,n.top+2+u,l)):(e.textBaseline=d==="lo"?"bottom":"top",e.textAlign="left",fillTextOnHalo(e,y,n.left+4,d==="lo"?n.bottom-2-u:n.top+2+u,l))}e.restore()}
1
+ import{SHADOW as G,LEADING as re,wireTooltip as U,wireControlHover as O,controlStyle as _,SPACE as v,RADIUS as $,fontPx as D,FONT as A,CLR as g,Z_BASE as le,menuLayerFor as se,wireListNavigation as ae,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as ce,markMenuTrigger as W,markNoPrint as j,openCommandMenu as de,saveImageBlob as ue,openReparentedModal as pe}from"../toolbar.js";import{ICONS as Y}from"../icons.js";import{openGuideAt as fe}from"../guideWindow.js";import{minOf as me,maxOf as he}from"../../core/utils.js";import{robustFence as K}from"../../stats/math.js";import{fmt as ge,fmtColorbarAxis as xe}from"../../renderer/fmt.js";import{markedTestLabel as be,DERIVED_LANE_PAD as ye}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=pe([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:we[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 d=Number(e.dataset.wmapChartFullH);if(!d)return;const c=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(c+d)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const we={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 d=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[i,n,r]=[0,2,4].map(c=>parseInt(d.slice(c,c+2),16)),d.length===8&&(l=parseInt(d.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 Ce={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"},Z={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(Z)){const n=o.getPropertyValue(`--wmap-${Z[i]}`).trim();t[i]=n||Ce[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=`${z(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function z(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 J(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-(z(e,o)-l)-(t?J(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(z(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=J(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=`${D(-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}`:ge(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,t){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:i,axisLabel:n,scaledUnit:r}=xe(e,null,o,"engineering",t);return{tick:i,tickWithUnit:r?l=>`${i(l)} ${r}`:i,unitLabel:n}}const ve=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)+ve}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${D(-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 P=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Se=/\s*[▾▼]\s*$/,q=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(!P(l,t))continue;const s=(l.textContent??"").replace(Se,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!P(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(!P(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(!P(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,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}const r=q.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 ke(e){const o=describeCard(e),t=q.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function Q(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 ee=new WeakSet;function Le(e){if(ee.has(e))return;ee.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",()=>Q(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&Q(e)})}catch{}}function Ae(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=(f,x="400")=>`${x} ${f*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,d=(f,x)=>l?(l.font=x,l.measureText(f).width):f.length*7*n,c=[];let u=0;if(o){u=s,c.push({kind:"text",text:o.title,x:s,y:u+14*n,font:a(16,"600"),alpha:1}),u+=24*n;const f=o.decor,x=[];f?.controls?.length&&x.push({text:f.controls.join(" \xB7 "),alpha:1});for(const m of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)x.push({text:m,alpha:.75});const b=a(12);for(const{text:m,alpha:C}of x){let y="";for(const S of m.split(" ")){const T=y?`${y} ${S}`:S;y&&d(T,b)>r-2*s?(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n,y=S):y=T}y&&(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n)}if(f?.legend?.length){u+=4*n;const m=a(12);let C=s;for(const y of f.legend){const S=14*n+d(y.label,m)+14*n;C>s&&C+S>r-s&&(C=s,u+=18*n),c.push({kind:"dot",x:C+5*n,y:u+7*n,r:5*n,color:y.color}),c.push({kind:"text",text:y.label,x:C+14*n,y:u+11*n,font:m,alpha:1}),C+=S}u+=20*n}if(f?.colorbar){u+=4*n;const m=a(12),C=f.colorbar;let y=s;c.push({kind:"text",text:C.label,x:y,y:u+10*n,font:m,alpha:1}),y+=d(C.label,m)+10*n,c.push({kind:"text",text:C.lo,x:y,y:u+10*n,font:m,alpha:.75}),y+=d(C.lo,m)+6*n,c.push({kind:"strip",x:y,y:u+1*n,w:200*n,h:10*n,color:C.color}),y+=206*n,c.push({kind:"text",text:C.hi,x:y,y:u+10*n,font:m,alpha:.75}),u+=20*n}u+=6*n}i.width=r,i.height=Math.ceil(e.height+u);const p=i.getContext("2d");if(p.fillStyle=o?Ae(o.card):"#ffffff",p.fillRect(0,0,i.width,i.height),o){const f=t.defaultView,x=f&&f.getComputedStyle(o.card).color||"#222222";p.textBaseline="alphabetic";for(const b of c)if(b.kind==="text")p.font=b.font,p.fillStyle=x,p.globalAlpha=b.alpha,p.fillText(b.text,b.x,b.y),p.globalAlpha=1;else if(b.kind==="dot")p.fillStyle=b.color,p.beginPath(),p.arc(b.x,b.y,b.r,0,Math.PI*2),p.fill();else for(let m=0;m<b.w;m++)p.fillStyle=b.color(m/Math.max(1,b.w-1)),p.fillRect(b.x+m,b.y,1,b.h)}return p.drawImage(e,0,u),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&ue(n,o,t)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${$.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ee="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:v.xs,padding:`${v.xs} ${v.md}`,borderRadius:$.pill,border:`1px solid ${g.menuBorder}`,background:"none",cursor:"pointer",fontSize:A.body,color:g.text,whiteSpace:"nowrap"}),O(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?g.iconActive:g.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ee:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.container,padding:v.xl,fontVariantNumeric:"tabular-nums"}}function ne(e){Object.assign(e.style,{..._("outlined"),color:g.label,padding:"0",width:"22px",height:"22px",lineHeight:re.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),O(e)}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:v.sm,paddingBottom:"6px",marginBottom:v.md,borderBottom:`1px solid ${g.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:g.value,fontSize:A.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=Y.expand,a.dataset.wmapCardExpand="1",ne(a),attachChartTip(a,n,s,"Expand"),j(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const d=n.ownerDocument.createElement("button");d.type="button",d.setAttribute("aria-label","Chart actions"),d.innerHTML=Y.more,d.dataset.wmapCardMenu="1",ne(d),attachChartTip(d,n,s,"Chart actions"),W(d,!1),j(d),r.appendChild(d);const c=n.ownerDocument.createElement("div");c.dataset.wmapCardAbout="1",c.setAttribute("role","note"),Object.assign(c.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.md}),j(c);let u;const p=h=>{c.textContent=h?u?.text??"":"",c.style.display=h?"":"none"};let f,x;const b=()=>{const h=f?f():n.querySelector("canvas");h&&saveCanvasPng(h,l.textContent||e,o,{card:n,title:l.textContent||e,decor:ke(n)})},m=()=>{const h=[],M=(E,N,B)=>({label:E,active:!1,action:!0,enabled:!B,disabledHint:B,onClick:()=>{C?.(),N()}});i.png!==!1&&(f||n.querySelector("canvas"))&&h.push(M("Save as PNG",b));for(const E of x?.()??[])h.push(M(E.label,E.onClick,E.disabledHint));if(u){const E=c.style.display!=="none";h.push({label:`About this ${u.noun}`,active:E,onClick:()=>{C?.(),p(!E)}})}return h};let C;d.addEventListener("click",()=>{if(d.getAttribute("aria-expanded")==="true"){C?.();return}const h=m();h.length!==0&&(C=de(d.getBoundingClientRect(),d,h,`${l.textContent||e}: chart actions`,{trigger:d,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(c);const y=n.ownerDocument.createElement("div");y.dataset.wmapPrintOnly="1",Object.assign(y.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.sm}),n.appendChild(y),Le(n.ownerDocument);const S=n.ownerDocument.createElement("div");S.dataset.wmapControls="1",Object.assign(S.style,{display:"flex",gap:v.sm,marginBottom:v.md,flexWrap:"wrap",alignItems:"center"}),j(S),n.appendChild(S);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:S,body:T,setPngDecor:h=>{q.set(n,h)},setPngCanvas:h=>{f=h},setAbout:h=>{u=h,p(!!h&&c.style.display!=="none")},setMenuRows:h=>{x=h}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,oe(e,o)," in the user guide"),i}function oe(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:g.iconActive,textDecoration:"underline",cursor:"pointer"}),O(t),t.addEventListener("click",()=>fe(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(oe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,padding:`${v.xs} ${v.sm}`,fontSize:A.body,fontFamily:A.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=[];return e.forEach(([d,c,u],p)=>{const f=i.createElement("label");u&&U(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:A.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${g.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:p===0?$.control:"0",borderBottomLeftRadius:p===0?$.control:"0",borderTopRightRadius:p===l?$.control:"0",borderBottomRightRadius:p===l?$.control:"0"}),O(f,"bare");const x=i.createElement("input");x.type="radio",x.name=s,x.value=d,x.checked=d===o,Object.assign(x.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const b=()=>{f.style.background=x.checked?g.bgActive:g.menuBg,f.style.color=x.checked?g.iconActive:g.text,f.dataset.on=x.checked?"true":"false"};a.push(b),b(),x.addEventListener("change",()=>{if(x.checked){for(const m of a)m();t(d)}}),f.append(x,i.createTextNode(c)),r.appendChild(f)}),r}const $e=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{..._("outlined"),marginTop:v.sm}),O(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${$e}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,{..._("outlined"),background:g.menuBg,color:g.label}),O(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:g.label,fontSize:A.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:d}=i;let c=o;const u=h=>e.find(M=>M.value===h)?.label??"",p=r.createElement("button");p.type="button",d&&(p.dataset.wmapSelect=d),l&&p.setAttribute("aria-label",l),Object.assign(p.style,{fontSize:A.body,padding:`${v.xxs} ${v.sm}`,background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:v.sm,justifyContent:"space-between"}),O(p),W(p,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const x=r.createElement("span");x.textContent="\u25BE",x.style.flex="0 0 auto",p.append(f,x);const b=()=>{f.textContent=e.length===0?s??"(none)":u(c)||s||"(none)"};if(b(),e.length===0)return p.disabled=!0,p.style.opacity="0.6",p.style.cursor="default",Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}});let m=null;const C=()=>{m&&(m.remove(),m=null,W(p,!1))},y=()=>{C(),p.focus()};function S(){const h=p.getBoundingClientRect(),M=r.defaultView??window,E=Math.max(h.width,220),N=Math.min(h.left,Math.max(4,(M.innerWidth??1/0)-E-4));m=r.createElement("div"),m.setAttribute("role","listbox"),m.setAttribute("aria-label",l??"Options"),Object.assign(m.style,{position:"fixed",top:`${h.bottom+4}px`,left:`${N}px`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,boxShadow:G.menu,zIndex:le,minWidth:`${E}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const B=[],H=()=>B.filter(w=>w.row.style.display!=="none").map(w=>w.row),F=[],ie=()=>{for(const w of F)w.el.style.display=B.slice(w.first,w.last+1).some(k=>k.row.style.display!=="none")?"":"none"};if(e.length>X){const w=ce(k=>{for(const L of B)L.row.style.display=L.label.includes(k)?"":"none";ie()},a,r,H);Object.assign(w.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),w.addEventListener("keydown",k=>{if(k.key==="Escape"){k.preventDefault(),y();return}k.key==="ArrowDown"&&(k.preventDefault(),H()[0]?.focus())}),m.appendChild(w)}let V;for(const w of e){if(w.group!==void 0&&w.group!==V){const R=r.createElement("div");R.textContent=w.group,R.setAttribute("role","presentation"),Object.assign(R.style,{padding:`${v.sm} ${v.xl} ${v.xxs}`,fontSize:A.sub,color:g.label,fontWeight:"600"}),m.appendChild(R),F.push({el:R,first:B.length,last:B.length})}V=w.group;const k=w.value===c,L=r.createElement("div");L.textContent=w.disabled?`${w.label} \u2014 ${w.disabled}`:w.label,L.setAttribute("role","option"),L.setAttribute("aria-selected",k?"true":"false"),w.disabled&&L.setAttribute("aria-disabled","true"),L.tabIndex=-1,Object.assign(L.style,{padding:`${v.sm} ${v.xl}`,fontSize:A.body,cursor:w.disabled?"default":"pointer",color:w.disabled?g.label:k?g.iconActive:g.text,fontWeight:k?"700":"400",opacity:w.disabled?"0.7":"",background:k?g.menuActive:"transparent",whiteSpace:"nowrap"}),L.addEventListener("mouseenter",()=>{!k&&!w.disabled&&(L.style.background=g.menuHover)}),L.addEventListener("mouseleave",()=>{k||(L.style.background="transparent")}),L.addEventListener("click",R=>{R.stopPropagation(),!w.disabled&&(c=w.value,b(),y(),t(w.value))}),m.appendChild(L),B.push({row:L,label:w.label.toLowerCase()}),F.length&&(F[F.length-1].last=B.length-1)}if(ae(m,H,y),se(p).appendChild(m),W(p,!0),e.length<=X){const w=e.findIndex(k=>k.value===c);H()[w>=0?w:0]?.focus()}}p.addEventListener("click",h=>{if(h.stopPropagation(),m){C();return}S()});const T=h=>{if(!p.isConnected){r.removeEventListener("click",T);return}m&&!m.contains(h.target)&&!p.contains(h.target)&&C()};return r.addEventListener("click",T),Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?ye:"")+be(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>t(Number(s)),{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,d,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,u=>{l=u,s()},i)),d&&e.appendChild(makeToggle("Axis includes limits",a,u=>{n=u,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,u=>{r=u,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const d=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&d===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=d,!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=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const u=s(c);u!==r&&(r=u,i(u))},{...n,hook:"group-scope"}),d=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(c){return r===c||c!==null&&!e.includes(c)?!1:(r=c,d&&(d.value=l(c)),!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,d)=>({value:String(d),label:a.label??`#${d}`}))],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:v.xs,fontSize:A.body,color:g.label,cursor:"pointer",userSelect:"none"}),O(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&&U(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=n,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:g.label,fontSize:A.body,display:"flex",alignItems:"center",gap:v.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(d),a}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:v.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:$.control,padding:`${v.sm} ${v.xl}`,fontSize:A.sub,fontFamily:A.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:G.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 d=t-n.left+r,c=i-n.top+r;d+s+l>n.width&&(d=t-n.left-r-s),c+a+l>n.height&&(c=i-n.top-r-a),d=Math.max(l,d),c=Math.max(l,c),e.style.left=`${d}px`,e.style.top=`${c}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 I(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 I(e,"test").length>0&&I(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=I(e,"test"),i=I(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...I(e,"pat"),...I(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:me(o),hi:he(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{K 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,d=0;if(r&&l?.length){const u=K(l);if(u){const p=Math.max(s,u.lo),f=Math.min(a,u.hi);f>p&&(d=l.filter(x=>Number.isFinite(x)&&(x<p||x>f)).length,s=p,a=f)}}if(n)for(const u of i)s=Math.min(s,u.value),a=Math.max(a,u.value);s===a&&(s-=1,a+=1);const c=[];for(const u of i)u.value<s?c.push({value:u.value,label:u.label,side:"lo"}):u.value>a&&c.push({value:u.value,label:u.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:d}}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 drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${D(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},d=D(-1)+2;for(const{value:c,label:u,side:p}of o){const f=a[p]++*d,x=i==="horizontal"?p==="lo"?"\u2190":"\u2192":p==="lo"?"\u2193":"\u2191",b=p==="lo"?`${x} ${u} ${r(c)}`:`${u} ${r(c)} ${x}`,m=e.measureText(b).width;if(i==="horizontal"){const C=p==="lo"?t.left+2:t.right-2-m,y={x0:C,x1:C+m,y0:t.top+2+f,y1:t.top+2+f+d},S=s?placeClearOf(s,y,d):y;e.textBaseline="top",e.textAlign=p==="lo"?"left":"right",fillTextOnHalo(e,b,p==="lo"?t.left+2:t.right-2,S.y0,l)}else{const C=p==="lo"?t.bottom-2-f-d:t.top+2+f,y={x0:t.left+4,x1:t.left+4+m,y0:C,y1:C+d},S=s?placeClearOf(s,y,p==="lo"?-d:d):y;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,b,t.left+4,S.y0,l)}}e.restore()}
@@ -0,0 +1,18 @@
1
+ import { type CommonalityField, type CommonalityWafer } from '../../stats/commonality.js';
2
+ import type { FacetCuration } from '../../stats/facets.js';
3
+ export interface CommonalityPanelOptions {
4
+ wafers: readonly CommonalityWafer[];
5
+ /** The wafer fields that divide the wafers (the Group by list). */
6
+ fields: readonly CommonalityField[];
7
+ curation?: Record<string, FacetCuration>;
8
+ /** The field Insights is grouped by now, if any: its row says so instead of offering it. */
9
+ groupedBy?: string;
10
+ /** Group Insights by this field. */
11
+ onGroupBy: (key: string) => void;
12
+ ownerDocument?: Document;
13
+ }
14
+ export declare function renderCommonalityPanel(o: CommonalityPanelOptions): {
15
+ card: HTMLElement;
16
+ destroy: () => void;
17
+ };
18
+ //# sourceMappingURL=commonality.d.ts.map
@@ -0,0 +1 @@
1
+ import{rankCommonality as A,measureLabel as N}from"../../stats/commonality.js";import{formatP as y}from"../../stats/groupCompare.js";import{CLR as h,FONT as E,SPACE as p,controlStyle as O,wireControlHover as B,wireTooltip as b}from"../toolbar.js";import{cardShell as T,firstRowsToggle as G,guideCite as R,renderEmptyState as F}from"./chartShell.js";import{GUIDE_SECTIONS as q}from"../../stats/guideSections.js";import{cardAbout as I}from"./cardAbout.js";const j=8;export function renderCommonalityPanel(l){const r=l.ownerDocument??document,{card:d,body:u,setAbout:v}=T("What divides yield",void 0,r);v(I("commonality")),d.dataset.wmapCommonality="1",d.style.gridColumn="1 / -1",d.style.flex="0 0 auto";const s=A(l.wafers,l.fields,l.curation);if(l.fields.length===0||s.rows.length===0)return F(u,l.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:d,destroy:()=>{}};const f=r.createElement("div"),g=[`Every wafer field, compared for yield and for the ${s.bins.length} most common fail bin${s.bins.length===1?"":"s"}, with each wafer as one value. Ranked by q (Welch's p adjusted for the ${s.rows.length} comparisons). A low q says the groups differ by more than wafer-to-wafer noise; it does not say why.`];s.confounded.length&&g.push(`These fields group the wafers identically, so the wafers cannot tell them apart: ${s.confounded.map(([n,e])=>`${n.label} and ${e.label}`).join("; ")}.`),s.untestable.length&&g.push(`Not compared, with no two groups of two or more wafers: ${s.untestable.map(n=>n.label).join(", ")}.`),f.textContent=g.join(" ")+" ",f.append(R(r,q.dividesYield),"."),Object.assign(f.style,{color:h.label,fontSize:E.body,marginBottom:p.sm}),u.appendChild(f);const c=r.createElement("table");Object.assign(c.style,{borderCollapse:"collapse",width:"100%",fontSize:E.body,fontVariantNumeric:"tabular-nums"});const C=r.createElement("tr"),i=(n,e,t="right")=>{const o=r.createElement("th");o.scope="col",o.textContent=n,e&&b(o,e),Object.assign(o.style,{textAlign:t,padding:`${p.xs} ${p.sm}`,borderBottom:`1px solid ${h.menuBorder}`,color:h.label,fontWeight:"600",whiteSpace:"nowrap"}),C.appendChild(o)};i("Field",void 0,"left"),i("Measure","Yield, or a fail bin\u2019s share of the judged dies","left"),i("Worst group","The group with the lowest yield, or the highest rate of the bin: its mean over its wafers","left"),i("Best group",void 0,"left"),i("Spread","Worst to best, in percentage points"),i("Welch p","Do the groups\u2019 wafer means differ? Welch\u2019s ANOVA, or Welch\u2019s t for two groups"),i("Rank p","The same question on ranks (Kruskal\u2013Wallis)"),i("q","Welch p adjusted for every comparison in the table (Benjamini\u2013Hochberg)"),i("");const $=r.createElement("thead");$.appendChild(C),c.appendChild($);const w=r.createElement("tbody");c.appendChild(w);const a=(n,e,t={})=>{const o=r.createElement("td");typeof e=="string"?o.textContent=e:o.appendChild(e),t.title&&b(o,t.title),Object.assign(o.style,{padding:`${p.xs} ${p.sm}`,textAlign:t.align??"right",borderBottom:`1px solid ${h.menuBorder}`,whiteSpace:"nowrap",fontWeight:t.strong?"700":"400"}),n.appendChild(o)},k=n=>`${n.toFixed(1)}%`,x=(n,e)=>e.comparison.groups.find(t=>t.key===n)?.n??0;function S(n){w.replaceChildren();for(const e of n?s.rows:s.rows.slice(0,j)){const t=r.createElement("tr");if(a(t,e.field.label,{align:"left"}),a(t,N(e.measure),{align:"left"}),a(t,`${e.worst.key}: ${k(e.worst.mean)} (${x(e.worst.key,e)} wafers)`,{align:"left"}),a(t,`${e.best.key}: ${k(e.best.mean)} (${x(e.best.key,e)} wafers)`,{align:"left"}),a(t,`${e.spread.toFixed(1)} pts`),a(t,y(e.comparison.welch?.p??NaN),{title:e.comparison.issue}),a(t,`${y(e.comparison.kruskal?.p??NaN)}${e.comparison.kruskal?.approximate?"*":""}`,{title:e.comparison.kruskal?.approximate?"Approximate: fewer than five wafers in a group":void 0}),a(t,y(e.pAdjusted),{strong:e.pAdjusted<.05}),e.field.key===l.groupedBy)a(t,"Grouped by this",{align:"left"});else{const o=r.createElement("button");o.type="button",o.textContent="Group by",o.dataset.wmapCommonalityGroup=e.field.key,b(o,`Group Insights by ${e.field.label}, so every chart compares its groups`),Object.assign(o.style,O("outlined")),B(o),o.addEventListener("click",()=>l.onGroupBy(e.field.key)),a(t,o,{align:"left"})}w.appendChild(t)}}const m=r.createElement("div");Object.assign(m.style,{overflowX:"auto"}),m.appendChild(c);const W=G(r,{total:s.rows.length,first:j,noun:"rows",scroller:m,fill:S});return u.append(m,W),{card:d,destroy:()=>{}}}
@@ -1 +1 @@
1
- import{buildCorrelationMatrix as $t,filterCorrelationMatrix as It,correlationSampleNote as Tt}from"../../stats/correlation.js";import{maxOf as St}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Dt}from"../../stats/facets.js";import{wireControlHover as Rt,wireTooltip as ft,controlStyle as At,SPACE as L,RADIUS as lt,fontPx as pt,FONT as j,CLR as g}from"../toolbar.js";import{exportCsv as kt}from"../tableExport.js";import{attachChartTip as _t,cardShell as Bt,setChartGrow as Nt,isExpandedCard as Ot,bodyRoom as Wt,observeResize as Ht,makeTooltip as Xt,positionChartTooltip as jt,makeWaferSelect as Vt,renderEmptyState as zt,resolveChartCanvasColors as Ft,prepareCanvas as Pt,chartDpr as ut}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as gt,DERIVED_MARK as Yt,DERIVED_KEY as Gt}from"../../renderer/testLabel.js";const it=5,at=100,bt=20;function q(b){const d=b.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=b.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function Ut(b){const d=q(b);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(b,d,h){const O=q(b);if(!O)return b;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(b){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=b,{card:l,body:$,controlsRow:Q,setPngDecor:wt}=Bt(d,J,b.ownerDocument);wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Nt(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=bt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",ft(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:g.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:g.menuBg,color:g.value,border:`1px solid ${g.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||bt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(Vt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Ct(){return V!==null?h[V]?[h[V]]:[]:h}if(b.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",ft(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...At("outlined"),color:g.text}),Rt(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),f=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&f.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}kt([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${gt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${gt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],f,"test-correlation.csv",b.onSaveText)}),Q.appendChild(e)}const _=l.ownerDocument.createElement("div");Object.assign(_.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(_,$);const I=Xt(l);_t(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Mt(e,o,m,f,s,a,y,x){_.innerHTML="";const T=Tt(y);if(T){const p=l.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=y.sample?`${T} \u2014 r is an estimate, not the whole population.`:`${T}.`,Object.assign(p.style,{color:g.label,fontSize:j.body}),_.appendChild(p)}if(s.length>0){const p=l.ownerDocument.createElement("div");p.dataset.wmapCaption="1",p.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(p.style,{color:g.warnText,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),_.appendChild(p)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:g.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Yt} ${Gt} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const S=l.ownerDocument.createElement("span");S.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${g.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${g.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(S,P,z),C.appendChild(i),_.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:g.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=f?`No significant correlations found \u2014 strongest pair: ${f.xLabel} \u2194 ${f.yLabel} (r = ${f.r.toFixed(2)})`:"No significant correlations found";else{const p=[];e>0&&p.push(`${e} strong (|r| \u2265 0.7)`),o>0&&p.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=p.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}_.appendChild(v)}function Et(e){if($.innerHTML="",e.tests.length<2)return zt($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,f=r=>r.label.split(" (#")[0],s=Math.min(14,St(e.tests.map(r=>f(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,T=14,C=28,B=44;let i=-1,S=-1;const P=96;function z(r){const c=Math.max(0,r-a),u=Math.floor(c/m);if(!Ot(l))return Math.max(T,Math.min(B,u));const n=Math.floor((Wt(l,$,o)-x-4)/m);return Math.max(T,Math.min(P,u,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function p(){const r=Ft(l),c=q(r.bg)??[255,255,255],u=$.clientWidth,n=z(u),X=n*m,D=x+n*m+4,R=a+X,A=Pt(o,l,R,D);if(!A)return;const{ctx:t}=A;t.font=`${pt(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((k,w)=>{const M=f(k),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((k,w)=>{const M=f(k),N=x+w*n,et=N+n/2;t.font=`${pt(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===S?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,Lt=nt===i&&w===S,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=Ut(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),Lt&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let k=0;k<=m;k++){const w=a+k*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+k*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),u=$.clientWidth,n=z(u),X=(r.clientX-c.left)*(o.width/ut(o)/c.width),D=(r.clientY-c.top)*(o.height/ut(o)/c.height),R=Math.floor((X-a)/n),A=Math.floor((D-x)/n);return R>=0&&R<m&&A>=0&&A<m?{xi:R,yi:A}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:u,yi:n}=c,X=u===n;o.style.cursor=X||!W?"default":"pointer";const D=e.cells.find(t=>t.xIndex===u&&t.yIndex===n),R=e.tests[u].label,A=e.tests[n].label;X?I.innerHTML=`<strong>${K(R)}</strong>`:D?.r!==null&&D?.r!==void 0?I.innerHTML=`<strong>${K(f(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(f(e.tests[u]))}</strong> (#${e.tests[u].testNumber})<br>r = ${D.r.toFixed(4)} \xB7 n = ${D.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${A} vs ${R}`)}<br><em>insufficient data</em>`,I.style.display="block",jt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:u,yi:n}=c;u!==n&&(i=u,S=n,p(),W(e.tests[u].testNumber,e.tests[n].testNumber))}),p}let ct=null;function tt(){const e=Ct(),o=e.flatMap(i=>i.dies??[]),m=$t(o,O),{matrix:f,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=It(m,{minTests:6,maxTests:F}),T=Dt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=f.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,S)=>i-S),B=C.length?C[Math.floor(C.length/2)]:null;ct=f,Mt(s,a,y,x,T,B,m,f.tests.some(i=>i.derived)),Z=Et(f),Z()}const vt=Ht(l,()=>Z());return tt(),{card:l,destroy:()=>vt.disconnect()}}
1
+ import{buildCorrelationMatrix as It,filterCorrelationMatrix as Tt,correlationSampleNote as St}from"../../stats/correlation.js";import{maxOf as Dt}from"../../core/utils.js";import{CORRELATION_POSITIVE as st,CORRELATION_NEGATIVE as rt}from"./palette.js";import{buildFacetTable as Rt}from"../../stats/facets.js";import{wireControlHover as At,wireTooltip as ut,controlStyle as kt,SPACE as L,RADIUS as lt,fontPx as ft,FONT as j,CLR as b}from"../toolbar.js";import{exportCsv as _t}from"../tableExport.js";import{attachChartTip as Bt,cardShell as Nt,setChartGrow as Ot,isExpandedCard as Wt,bodyRoom as Ht,observeResize as Xt,makeTooltip as jt,positionChartTooltip as Vt,makeWaferSelect as zt,renderEmptyState as Ft,resolveChartCanvasColors as Pt,prepareCanvas as Yt,chartDpr as pt}from"./chartShell.js";import{escHtml as K}from"../../core/utils.js";import{unmarkedLabel as ht,derivedCsvCell as xt,DERIVED_CSV_HEADER as bt,DERIVED_MARK as Gt,DERIVED_KEY as Ut}from"../../renderer/testLabel.js";import{cardAbout as Kt}from"./cardAbout.js";const it=5,at=100,gt=20;function q(g){const d=g.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(d)return[+d[1],+d[2],+d[3]];const h=g.trim().replace("#","");return h.length===6?[parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]:null}function qt(g){const d=q(g);return d?(d[0]*299+d[1]*587+d[2]*114)/1e3>140?"#111":"#fff":"#000"}function yt(g,d,h){const O=q(g);if(!O)return g;const J=Math.round(d[0]+(O[0]-d[0])*h),W=Math.round(d[1]+(O[1]-d[1])*h),l=Math.round(d[2]+(O[2]-d[2])*h);return`rgb(${J},${W},${l})`}export function renderCorrelationPanel(g){const{title:d="Test correlation matrix",items:h,testDefs:O,onSaveImage:J,onSelectPair:W}=g,{card:l,body:$,controlsRow:Q,setPngDecor:wt,setAbout:Ct}=Nt(d,J,g.ownerDocument);Ct(Kt("correlation")),wt(()=>{const e=q(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:o=>yt(o<.5?rt:st,e,Math.abs(2*o-1))}}}),Ot(l,"square"),$.style.overflowX="auto",l.style.alignSelf="start";let F=gt,V=null;const H=l.ownerDocument.createElement("label");H.textContent="Max tests:",ut(H,`The most tests the matrix shows, from ${it} to ${at}`),Object.assign(H.style,{color:b.label,fontSize:j.body,display:"flex",alignItems:"center",gap:L.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(it),E.max=String(at),E.value=String(F),Object.assign(E.style,{width:"52px",fontSize:j.body,padding:`${L.xxs} ${L.xs}`,background:b.menuBg,color:b.value,border:`1px solid ${b.menuBorder}`,borderRadius:lt.control}),E.addEventListener("change",()=>{const e=Math.max(it,Math.min(at,parseInt(E.value,10)||gt));E.value=String(e),e!==F&&(F=e,tt())}),H.appendChild(E),Q.appendChild(H),h.length>1&&Q.appendChild(zt(h,V,e=>{V=e,tt()},{ownerDocument:l.ownerDocument}));function Mt(){return V!==null?h[V]?[h[V]]:[]:h}if(g.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",ut(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...kt("outlined"),color:b.text}),At(e),e.addEventListener("click",()=>{const o=ct;if(!o)return;const m=o.tests.some(s=>s.derived),u=[];for(let s=0;s<o.tests.length;s++)for(let a=s+1;a<o.tests.length;a++){const y=o.cells.find(x=>x.xIndex===a&&x.yIndex===s);y&&u.push({x:o.tests[a],y:o.tests[s],r:y.r,n:y.n})}_t([{header:"Test X",get:s=>ht(s.x.label)},{header:"Test X number",get:s=>s.x.testNumber},{header:"Test Y",get:s=>ht(s.y.label)},{header:"Test Y number",get:s=>s.y.testNumber},{header:"r",get:s=>s.r===null?"":s.r.toFixed(6)},{header:"n",get:s=>s.n},...m?[{header:`Test X ${bt.toLowerCase()}`,get:s=>xt(s.x)},{header:`Test Y ${bt.toLowerCase()}`,get:s=>xt(s.y)}]:[]],u,"test-correlation.csv",g.onSaveText)}),Q.appendChild(e)}const _=l.ownerDocument.createElement("div");Object.assign(_.style,{display:"flex",flexDirection:"column",gap:L.xs,marginBottom:L.sm}),l.insertBefore(_,$);const I=jt(l);Bt(H,l,I,"Cap on how many tests the matrix includes (strongest correlations kept first)");let Z=()=>{};function Et(e,o,m,u,s,a,y,x){_.innerHTML="";const T=St(y);if(T){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=y.sample?`${T} \u2014 r is an estimate, not the whole population.`:`${T}.`,Object.assign(f.style,{color:b.label,fontSize:j.body}),_.appendChild(f)}if(s.length>0){const f=l.ownerDocument.createElement("div");f.dataset.wmapCaption="1",f.textContent=`\u26A0 Mixed ${s.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). Use Group by, or the Wafer picker, to narrow to a like-for-like set.`,Object.assign(f.style,{color:b.warnText,background:b.warnBg,border:`1px solid ${b.warnBorder}`,borderRadius:lt.control,padding:`${L.xs} ${L.md}`,fontSize:j.body}),_.appendChild(f)}const C=l.ownerDocument.createElement("span");Object.assign(C.style,{display:"inline-flex",alignItems:"center",gap:L.sm,color:b.label,fontSize:j.body,flexWrap:"wrap"});const B=l.ownerDocument.createElement("span");B.dataset.wmapCaption="1",B.textContent=(a!==null?`Pearson r \xB7 n \u2248 ${a.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(x?` ${Gt} ${Ut} \xB7`:""),C.appendChild(B);const i=l.ownerDocument.createElement("span");Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:L.xs});const S=l.ownerDocument.createElement("span");S.textContent="\u22121";const P=l.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:lt.control,border:`1px solid ${b.menuBorder}`,background:`linear-gradient(to right, ${rt}, ${b.menuBg}, ${st})`});const z=l.ownerDocument.createElement("span");z.textContent="+1",i.append(S,P,z),C.appendChild(i),_.appendChild(C);const v=l.ownerDocument.createElement("span");if(v.dataset.wmapCaption="1",Object.assign(v.style,{color:b.value,fontSize:j.body,fontWeight:"500"}),e===0&&o===0)v.textContent=u?`No significant correlations found \u2014 strongest pair: ${u.xLabel} \u2194 ${u.yLabel} (r = ${u.r.toFixed(2)})`:"No significant correlations found";else{const f=[];e>0&&f.push(`${e} strong (|r| \u2265 0.7)`),o>0&&f.push(`${o} moderate (0.4\u20130.7)`);const Y=e+o;let r=f.join(", ")+` pair${Y!==1?"s":""} found`;m>0&&(r+=` \xB7 ${m} weak pair${m!==1?"s":""} not shown`),v.textContent=r}_.appendChild(v)}function vt(e){if($.innerHTML="",e.tests.length<2)return Ft($,"Need at least two parametric tests for a correlation matrix."),()=>{};const o=l.ownerDocument.createElement("canvas");o.style.display="block",o.style.cursor="default",$.appendChild(o);const m=e.tests.length,u=r=>r.label.split(" (#")[0],s=Math.min(14,Dt(e.tests.map(r=>u(r).length))),a=s*6.5+8,y=10,x=Math.round(y*6.5*Math.sin(Math.PI/4))+14,T=14,C=28,B=44;let i=-1,S=-1;const P=96;function z(r){const c=Math.max(0,r-a),p=Math.floor(c/m);if(!Wt(l))return Math.max(T,Math.min(B,p));const n=Math.floor((Ht(l,$,o)-x-4)/m);return Math.max(T,Math.min(P,p,n))}const v=new Map;for(const r of e.cells){let c=v.get(r.yIndex);c||(c=[],v.set(r.yIndex,c)),c.push(r)}function f(){const r=Pt(l),c=q(r.bg)??[255,255,255],p=$.clientWidth,n=z(p),X=n*m,D=x+n*m+4,R=a+X,A=Yt(o,l,R,D);if(!A)return;const{ctx:t}=A;t.font=`${ft(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((k,w)=>{const M=u(k),N=M.length>y?`${M.slice(0,y-1)}\u2026`:M,et=a+w*n+n/2;t.save(),t.translate(et,x-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=w===i?r.text:r.textMuted,t.fillText(N,0,0),t.restore()}),e.tests.forEach((k,w)=>{const M=u(k),N=x+w*n,et=N+n/2;t.font=`${ft(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=w===S?r.text:r.textMuted,t.fillText(M.length>s?`${M.slice(0,s-1)}\u2026`:M,a-4,et),(v.get(w)??[]).forEach(dt=>{const nt=dt.xIndex,G=a+nt*n,$t=nt===i&&w===S,mt=nt===w,U=dt.r;if(U===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(G+1,N+1,n-2,n-2),t.globalAlpha=1;return}let ot=r.bgHover;mt?t.fillStyle=r.bgHover:(ot=yt(U>=0?st:rt,c,Math.abs(U)),t.fillStyle=ot),t.fillRect(G+1,N+1,n-2,n-2),n>=C&&!mt&&(t.font=`${Math.min(10,n*.35)}px system-ui, sans-serif`,t.fillStyle=qt(ot),t.textAlign="center",t.textBaseline="middle",t.fillText(U.toFixed(2),G+n/2,N+n/2)),$t&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(G+1,N+1,n-2,n-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let k=0;k<=m;k++){const w=a+k*n;t.beginPath(),t.moveTo(w,x),t.lineTo(w,x+m*n),t.stroke();const M=x+k*n;t.beginPath(),t.moveTo(a,M),t.lineTo(a+m*n,M),t.stroke()}}function Y(r){const c=o.getBoundingClientRect(),p=$.clientWidth,n=z(p),X=(r.clientX-c.left)*(o.width/pt(o)/c.width),D=(r.clientY-c.top)*(o.height/pt(o)/c.height),R=Math.floor((X-a)/n),A=Math.floor((D-x)/n);return R>=0&&R<m&&A>=0&&A<m?{xi:R,yi:A}:null}return o.addEventListener("mousemove",r=>{const c=Y(r);if(!c){I.style.display="none",o.style.cursor="default";return}const{xi:p,yi:n}=c,X=p===n;o.style.cursor=X||!W?"default":"pointer";const D=e.cells.find(t=>t.xIndex===p&&t.yIndex===n),R=e.tests[p].label,A=e.tests[n].label;X?I.innerHTML=`<strong>${K(R)}</strong>`:D?.r!==null&&D?.r!==void 0?I.innerHTML=`<strong>${K(u(e.tests[n]))}</strong> (#${e.tests[n].testNumber}) vs <strong>${K(u(e.tests[p]))}</strong> (#${e.tests[p].testNumber})<br>r = ${D.r.toFixed(4)} \xB7 n = ${D.n.toLocaleString()}${W?"<br><em>click to view in scatter</em>":""}`:I.innerHTML=`${K(`${A} vs ${R}`)}<br><em>insufficient data</em>`,I.style.display="block",Vt(I,l,r.clientX,r.clientY)}),o.addEventListener("mouseleave",()=>{I.style.display="none"}),o.addEventListener("click",r=>{const c=Y(r);if(!c||!W)return;const{xi:p,yi:n}=c;p!==n&&(i=p,S=n,f(),W(e.tests[p].testNumber,e.tests[n].testNumber))}),f}let ct=null;function tt(){const e=Mt(),o=e.flatMap(i=>i.dies??[]),m=It(o,O),{matrix:u,strongPairs:s,moderatePairs:a,hiddenWeakPairs:y,strongestPair:x}=Tt(m,{minTests:6,maxTests:F}),T=Rt(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),C=u.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,S)=>i-S),B=C.length?C[Math.floor(C.length/2)]:null;ct=u,Et(s,a,y,x,T,B,m,u.tests.some(i=>i.derived)),Z=vt(u),Z()}const Lt=Xt(l,()=>Z());return tt(),{card:l,destroy:()=>Lt.disconnect()}}
@@ -0,0 +1,31 @@
1
+ import { type CompareWafer } from '../../stats/groupCompare.js';
2
+ import type { TestDef } from '../../renderer/buildWaferMap.js';
3
+ import { type SaveTextHandler } from '../toolbar.js';
4
+ export interface GroupComparisonPanelOptions {
5
+ title?: string;
6
+ /** The groups to compare: each a key and its wafers' dies. */
7
+ groups: ReadonlyArray<{
8
+ key: string;
9
+ items: ReadonlyArray<{
10
+ dies: CompareWafer['dies'];
11
+ }>;
12
+ }>;
13
+ testDefs: readonly TestDef[];
14
+ /** What the groups are ("Process split"), for the column heads and the method note. */
15
+ groupLabelText?: string;
16
+ /** The control group, or null for none. */
17
+ control: string | null;
18
+ onControlChange: (control: string | null) => void;
19
+ /** The test the other panels show: its row is marked. */
20
+ selectedTestNumber?: number;
21
+ /** A row was chosen: show this test in the other panels. */
22
+ onSelectTest: (testNumber: number) => void;
23
+ onSaveText?: SaveTextHandler;
24
+ ownerDocument?: Document;
25
+ }
26
+ export declare function renderGroupComparisonPanel(o: GroupComparisonPanelOptions): {
27
+ card: HTMLElement;
28
+ setTest: (n: number) => void;
29
+ destroy: () => void;
30
+ };
31
+ //# sourceMappingURL=groupComparison.d.ts.map
@@ -0,0 +1 @@
1
+ import{compareTestsByGroup as I,formatP as y,groupKeys as X}from"../../stats/groupCompare.js";import{fmt as j}from"../../renderer/fmt.js";import{testLabel as F,unmarkedLabel as J}from"../../renderer/testLabel.js";import{CLR as i,FONT as G,SPACE as b,controlStyle as q,wireControlHover as R,wireTooltip as x}from"../toolbar.js";import{exportCsv as Q}from"../tableExport.js";import{cardShell as Y,guideCite as Z,makeListSelect as ee,renderEmptyState as V}from"./chartShell.js";import{GUIDE_SECTIONS as te}from"../../stats/guideSections.js";import{cardAbout as oe}from"./cardAbout.js";const v="\0none",ne=6;export function renderGroupComparisonPanel(r){const s=r.ownerDocument??document,T=r.groupLabelText??"group",{card:g,body:w,controlsRow:L,setAbout:K}=Y(r.title??`Comparison by ${T.toLowerCase()}`,void 0,s);K(oe("comparison")),g.dataset.wmapGroupComparison="1",g.style.gridColumn="1 / -1";const N=r.groups.flatMap(t=>t.items.map(e=>({dies:e.dies,group:t.key}))),p=X(N),a=r.control!==null&&p.includes(r.control)?r.control:null,u=I(N,r.testDefs,a??void 0),O=p.length<=ne?p:[],P=ee([{value:v,label:"No control: compare all groups"},...p.map(t=>({value:t,label:`Control: ${t}`}))],a??v,t=>r.onControlChange(t===v?null:t),{ownerDocument:s,ariaLabel:"Control group",hook:"compare-control"});if(L.appendChild(P),r.onSaveText&&u.length){const t=s.createElement("button");t.type="button",t.textContent="Comparison CSV",x(t,"Save this table as a CSV file, one row per test"),Object.assign(t.style,{...q("outlined"),color:i.text}),R(t),t.addEventListener("click",()=>Q([{header:"Test",get:e=>J(F(e.test,e.test.testNumber))},{header:"Test number",get:e=>e.test.testNumber},{header:"Unit",get:e=>e.test.unit??""},...p.flatMap(e=>[{header:`${e} wafers`,get:o=>o.comparison.groups.find(n=>n.key===e)?.n??0},{header:`${e} mean`,get:o=>c(o.comparison.groups.find(n=>n.key===e)?.mean)},...a&&e!==a?[{header:`${e} minus ${a}`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.delta)},{header:`${e} vs ${a} p (Holm)`,get:o=>c(o.comparison.contrasts?.find(n=>n.key===e)?.pAdjusted)}]:[]]),{header:"Welch p",get:e=>c(e.comparison.welch?.p)},{header:"Kruskal-Wallis p",get:e=>c(e.comparison.kruskal?.p)},{header:"q (Benjamini-Hochberg)",get:e=>c(e.pAdjusted)},{header:"Largest shift (wafer SDs)",get:e=>c(e.effect)},{header:"Largest shift (share of limit window)",get:e=>c(e.windowShare)},{header:"Note",get:e=>e.comparison.issue??""}],u,"group-comparison.csv",r.onSaveText)),L.appendChild(t)}if(p.length<2)return V(w,`Needs two or more ${T.toLowerCase()} groups to compare.`),{card:g,setTest:()=>{},destroy:()=>{}};if(u.length===0)return V(w,"No measured test has values in these wafers."),{card:g,setTest:()=>{},destroy:()=>{}};const C=s.createElement("div"),U=p.map(t=>`${t} ${N.filter(e=>e.group===t).length}`).join(", ");C.textContent=`Each wafer is one value, the mean of its dies, so n is wafers (${U}). Welch: Welch's ANOVA (Welch's t for two groups). Rank: Kruskal\u2013Wallis${u.some(t=>t.comparison.kruskal?.approximate)?", approximate with fewer than five wafers in a group":""}. q: Benjamini\u2013Hochberg across the ${u.length} tests, which the table is ranked by.`+(a?` Each group's difference from ${a} has a Holm-adjusted p.`:"")+" ",C.append(Z(s,te.groups),"."),Object.assign(C.style,{color:i.label,fontSize:G.body,marginBottom:b.sm}),w.appendChild(C);const S=s.createElement("div");Object.assign(S.style,{overflow:"auto",maxHeight:"420px",border:`1px solid ${i.menuBorder}`});const $=s.createElement("table");Object.assign($.style,{borderCollapse:"collapse",width:"100%",fontSize:G.body,fontVariantNumeric:"tabular-nums"});const B=s.createElement("thead"),W=s.createElement("tr"),f=(t,e,o="right")=>{const n=s.createElement("th");n.scope="col",n.textContent=t,e&&x(n,e),Object.assign(n.style,{position:"sticky",top:"0",background:i.menuBg,textAlign:o,padding:`${b.xs} ${b.sm}`,borderBottom:`1px solid ${i.menuBorder}`,color:i.label,fontWeight:"600",whiteSpace:"nowrap"}),W.appendChild(n)};f("Test",void 0,"left");for(const t of O)f(t===a?`${t} (control)`:t,a&&t!==a?`Mean of the wafer means, and the difference from ${a}`:"Mean of the wafer means");f("Welch p","Do the group means differ? Welch\u2019s ANOVA on wafer means, not assuming equal spreads"),f("Rank p","The same question on ranks (Kruskal\u2013Wallis): one odd wafer cannot drive it"),f("q","Welch p adjusted for the number of tests compared (Benjamini\u2013Hochberg); the table is ranked by it"),f("Largest shift","The largest difference between group means: in wafer-to-wafer standard deviations, and as a share of the limit window where the test has both limits"),B.appendChild(W),$.appendChild(B);const D=s.createElement("tbody"),M=new Map,h=(t,e,o={})=>{const n=s.createElement("td");typeof e=="string"?n.textContent=e:n.appendChild(e),o.title&&x(n,o.title),Object.assign(n.style,{padding:`${b.xs} ${b.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${i.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400",color:o.muted?i.label:i.text}),t.appendChild(n)};for(const t of u){const e=s.createElement("tr"),o=t.comparison,n=t.test.unit,d=s.createElement("button");d.type="button",d.textContent=F(t.test,t.test.testNumber),d.dataset.wmapCompareTest=String(t.test.testNumber),x(d,`Show ${d.textContent} in the panels below${o.issue?`. ${o.issue}`:""}`),Object.assign(d.style,{...q("bare"),padding:"0",textAlign:"left",color:i.text,textDecoration:"underline",textDecorationColor:i.menuBorder}),R(d,"bare"),d.addEventListener("click",()=>{r.onSelectTest(t.test.testNumber),k(t.test.testNumber)}),h(e,d,{align:"left"});for(const E of O){const l=o.groups.find(A=>A.key===E),m=o.contrasts?.find(A=>A.key===E),H=l&&l.n?j(l.mean,n):"\u2014",_=m&&Number.isFinite(m.delta)?`${H} (${m.delta>=0?"+":""}${j(m.delta,n)}, p ${y(m.pAdjusted)})`:H;h(e,_,{title:l?`${E}: ${l.n} wafer${l.n===1?"":"s"}${l.n>=2?`, wafer-to-wafer SD ${j(l.sd,n)}`:""}`:void 0,muted:!l||l.n<2,strong:!!m&&m.pAdjusted<.05})}h(e,y(o.welch?.p??NaN),{title:o.issue}),h(e,y(o.kruskal?.p??NaN)),h(e,y(t.pAdjusted),{strong:t.pAdjusted<.05});const z=Number.isFinite(t.effect)?`${Math.abs(t.effect).toFixed(1)} SD${t.windowShare!==void 0?` \xB7 ${Math.abs(t.windowShare*100).toFixed(0)}% of limits`:""}`:"\u2014";h(e,z),M.set(t.test.testNumber,e),D.appendChild(e)}$.appendChild(D),S.appendChild($),w.appendChild(S);function k(t){for(const[e,o]of M)o.style.background=e===t?i.bgActive:"",e===t?o.setAttribute("aria-current","true"):o.removeAttribute("aria-current")}return k(r.selectedTestNumber),{card:g,setTest:k,destroy:()=>{}}}const c=r=>r===void 0||!Number.isFinite(r)?"":String(r);
@@ -1,16 +1,6 @@
1
1
  export { renderCapabilityPanel } from './capability.js';
2
2
  export type { CapabilityPanelOptions, CapabilityPanelHandle } from './capability.js';
3
- export { renderBoxplotPanel } from './boxplot.js';
4
- export type { BoxplotPanelOptions, BoxplotPanelHandle } from './boxplot.js';
5
- export { renderHistogramPanel } from './histogram.js';
6
- export type { HistogramPanelOptions, HistogramPanelHandle } from './histogram.js';
7
3
  export { renderCorrelationPanel } from './correlation.js';
8
4
  export type { CorrelationPanelOptions, CorrelationPanelHandle } from './correlation.js';
9
- export { renderScatterPanel } from './scatter.js';
10
- export type { ScatterPanelOptions, ScatterPanelHandle } from './scatter.js';
11
- export { renderBarPanel } from './barPanel.js';
12
- export type { ChartPanel, BarPanelHandle } from './barPanel.js';
13
- export { renderBinClusterPanel } from './binCluster.js';
14
- export type { BinClusterPanelOptions, BinClusterPanelHandle } from './binCluster.js';
15
5
  export * from './chartShell.js';
16
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- export{renderCapabilityPanel}from"./capability.js";export{renderBoxplotPanel}from"./boxplot.js";export{renderHistogramPanel}from"./histogram.js";export{renderCorrelationPanel}from"./correlation.js";export{renderScatterPanel}from"./scatter.js";export{renderBarPanel}from"./barPanel.js";export{renderBinClusterPanel}from"./binCluster.js";export*from"./chartShell.js";
1
+ export{renderCapabilityPanel}from"./capability.js";export{renderCorrelationPanel}from"./correlation.js";export*from"./chartShell.js";
@@ -0,0 +1,23 @@
1
+ import type { Die } from '../../core/dies.js';
2
+ import type { TestDef } from '../../renderer/buildWaferMap.js';
3
+ import type { RenderableWaferMap } from '../renderWaferMap.js';
4
+ export interface PatCardOptions {
5
+ items: ReadonlyArray<{
6
+ label: string;
7
+ dies: readonly Die[];
8
+ allDies?: readonly Die[];
9
+ passBins: readonly number[];
10
+ ringCount: number;
11
+ source?: RenderableWaferMap;
12
+ }>;
13
+ testDefs: readonly TestDef[];
14
+ ownerDocument?: Document;
15
+ /** Back to the maps, coloured by PAT verdict: the button is offered when the host can. */
16
+ showMap?: () => void;
17
+ }
18
+ /** The card, or undefined when no test has both limits or no wafer has enough passing dies for PAT limits. */
19
+ export declare function renderPatCard(o: PatCardOptions): {
20
+ card: HTMLElement;
21
+ destroy: () => void;
22
+ } | undefined;
23
+ //# sourceMappingURL=patCard.d.ts.map
@@ -0,0 +1 @@
1
+ import{summarisePat as O}from"../../stats/patSummary.js";import{PAT_K as j,PAT_MIN_DIES as B,PAT_SKEW_WARN as W}from"../../stats/pat.js";import{CLR as d,FONT as f,SPACE as i,controlStyle as L,wireControlHover as G,wireTooltip as $}from"../toolbar.js";import{cardShell as D,firstRowsToggle as M,guideCite as _}from"./chartShell.js";import{GUIDE_SECTIONS as k}from"../../stats/guideSections.js";import{cardAbout as F}from"./cardAbout.js";const v=8,T=(l,o)=>o>0?`${(l/o*100).toFixed(o>=1e3?2:1)}%`:"\u2013";export function renderPatCard(l){const o=O(l.items,l.testDefs);if(!o)return;const s=l.ownerDocument??document,{card:p,body:h,setAbout:x}=D("Part average testing (PAT)",void 0,s);x(F("pat")),p.dataset.wmapPatCard="1",p.style.gridColumn="1 / -1",p.style.flex="0 0 auto";const u=s.createElement("div");u.textContent=`Dynamic limits for each of the ${o.tests} test${o.tests===1?"":"s"} with both limits, set per wafer at the median \xB1 ${j} robust standard deviations (interquartile range \xF7 1.35) of the dies that pass, never wider than the specification limits (the test's own where a test has none), and only where a wafer has ${B} or more passing values. An outlier passes its bin and every test limit but lies outside the PAT limits of at least one test. Overall: ${o.total.outliers.toLocaleString("en-GB")} outlier${o.total.outliers===1?"":"s"} in ${o.total.judged.toLocaleString("en-GB")} dies (${T(o.total.outliers,o.total.judged)}). `,u.append(_(s,k.pat,"How to read this, and how it differs from AEC-Q001"),"."),Object.assign(u.style,{color:d.label,fontSize:f.body,marginBottom:i.sm}),h.appendChild(u);const w=t=>{const e=s.createElement("table");Object.assign(e.style,{borderCollapse:"collapse",width:"100%",fontSize:f.body,fontVariantNumeric:"tabular-nums"});const r=s.createElement("tr");t.forEach(([C,c],P)=>{const m=s.createElement("th");m.scope="col",m.textContent=C,c&&$(m,c),Object.assign(m.style,{textAlign:P===0?"left":"right",padding:`${i.xs} ${i.sm}`,borderBottom:`1px solid ${d.menuBorder}`,color:d.label,fontWeight:"600",whiteSpace:"nowrap"}),r.appendChild(m)});const a=s.createElement("thead");a.appendChild(r);const n=s.createElement("tbody");return e.append(a,n),{table:e,tbody:n}},b=(t,e,r=!1)=>{const a=s.createElement("tr");e.forEach((n,C)=>{const c=s.createElement("td");c.textContent=n,Object.assign(c.style,{padding:`${i.xs} ${i.sm}`,textAlign:C===0?"left":"right",borderBottom:`1px solid ${d.menuBorder}`,whiteSpace:"nowrap",fontWeight:r?"700":"400"}),a.appendChild(c)}),t.appendChild(a)},y=[...o.wafers].sort((t,e)=>e.outliers/e.judged-t.outliers/t.judged||e.outliers-t.outliers),{table:E,tbody:S}=w([["Wafer"],["Dies judged","Dies with a PAT verdict"],["Within","Pass and inside the PAT limits"],["Outliers","Pass every limit and bin, but outside the PAT limits of a test"],["Outlier rate"],["Fail anyway","Fail their bin or a test limit"]]),g=s.createElement("div");g.style.overflowX="auto",g.appendChild(E);const A=M(s,{total:y.length,first:v,noun:"wafers",scroller:g,fill:t=>{S.replaceChildren();for(const e of t?y:y.slice(0,v))b(S,[e.label,e.judged.toLocaleString("en-GB"),e.within.toLocaleString("en-GB"),e.outliers.toLocaleString("en-GB"),T(e.outliers,e.judged),e.fails.toLocaleString("en-GB")],e.outliers>0)}});if(h.append(g,A),l.showMap){const t=s.createElement("button");t.type="button",t.textContent="Map the verdicts",t.dataset.wmapPatMaps="1",$(t,"Show the maps with their dies coloured by PAT verdict: within the limits, outlier, fails anyway"),Object.assign(t.style,{...L("outlined"),marginTop:i.sm,marginLeft:i.sm}),G(t),t.addEventListener("click",()=>l.showMap()),h.appendChild(t)}if(o.byTest.length){const t=s.createElement("div");t.textContent="Where the outliers are outside",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const{table:e,tbody:r}=w([["Test"],["Outliers","Outlier dies outside the PAT limits of this test; a die outside on several tests counts for each"]]);for(const a of o.byTest.slice(0,5))b(r,[a.name,a.outliers.toLocaleString("en-GB")]);h.append(t,e)}if(o.skewed.length){const t=s.createElement("div");t.textContent="Lopsided distributions",Object.assign(t.style,{fontWeight:"600",color:d.text,fontSize:f.body,margin:`${i.md} 0 ${i.xs}`});const e=s.createElement("div");e.textContent=`The middle half of these tests' values is lopsided (quartile skewness of ${W} or more either way), so limits placed symmetrically about the median sit too close on one side and too far on the other: they flag normal dies on the short side and miss outliers on the long one. Read their counts with care.`,Object.assign(e.style,{color:d.label,fontSize:f.body,marginBottom:i.xs});const{table:r,tbody:a}=w([["Test"],["Wafers lopsided","Wafers where the test is lopsided, of the wafers that have PAT limits for it"],["Most lopsided","Quartile skewness of the most lopsided wafer: positive means a long tail towards high values"]]);for(const n of o.skewed.slice(0,5))b(a,[n.name,`${n.wafers} of ${n.of}`,`${n.worst>0?"+":"\u2212"}${Math.abs(n.worst).toFixed(2)}`]);h.append(t,e,r)}return{card:p,destroy:()=>{}}}
@@ -1,19 +1,69 @@
1
1
  import { type PlotPoint, type ResolvedPlot } from '../../stats/plotData.js';
2
- import { type SaveImageHandler } from './chartShell.js';
2
+ import { type CardMenuRow, type SaveImageHandler, type WaferContextMenuHandler } from './chartShell.js';
3
+ import type { BinColors } from '../../renderer/binColors.js';
4
+ /**
5
+ * @internal Where each colour group's mark sits within its category, as fractions of the category's slot. Only the
6
+ * groups with a value in that category take a place, centred, so a category that one group fills (a ring coloured by
7
+ * ring, a wafer coloured by its split) gets one full-width mark rather than a sliver in a row of empty places. Every
8
+ * mark has the same width, the width the fullest category needs, so marks compare across categories.
9
+ * `present[c]` lists the groups with a value in category c, in legend order.
10
+ */
11
+ export declare function categoryLayout(present: ReadonlyArray<readonly number[]>): {
12
+ width: number;
13
+ /** The left edge of group g's mark in category c, or undefined when g has none there. */
14
+ left: (c: number, g: number) => number | undefined;
15
+ /** The group whose mark covers fraction f of category c's slot, or undefined. */
16
+ groupAt: (c: number, f: number) => number | undefined;
17
+ };
3
18
  export interface PlotChartOptions {
4
19
  ownerDocument?: Document;
5
20
  onSaveImage?: SaveImageHandler;
6
21
  /** The label of the wafer an item index names, for tooltips. */
7
22
  waferLabel: (item: number) => string;
23
+ /** The maps' bin colours: a plot coloured by hard or soft bin draws each bin in its map colour. */
24
+ binColors?: BinColors;
25
+ /** Right-click a mark that is one wafer (a wafer's bar or box, a point per wafer): that wafer's menu, as on the maps. */
26
+ onWaferMenu?: WaferContextMenuHandler;
27
+ /**
28
+ * A legend click picks a group for the host to narrow to (an Insights section's group), in place of filtering this
29
+ * plot alone: called with the group clicked, or null when it is `legendPicked` already (show every group again).
30
+ */
31
+ onLegendPick?: (group: string | null) => void;
32
+ /** The group the host has narrowed to, shown selected in the legend. */
33
+ legendPicked?: string | null;
8
34
  /** Click a point: open its wafer, on `testNumber` (the plot's own measurement) when it has one. Omit where there is no wafer to open. */
9
35
  onOpenWafer?: (item: number, testNumber?: number) => void;
36
+ /** What a click on a bar or box that is not one wafer (or on a line's point) does, in the reader's words. Default `chart
37
+ * or tabulate what it counts`. Read at each draw. */
38
+ selectActionLabel?: string;
39
+ /** What a drag across a line chart selects, in the reader's words ("wafers"). Default `a run of points`. */
40
+ selectRangeLabel?: string;
10
41
  /** What a click on a point does, in the reader's words. Default `open this wafer`. */
11
42
  openActionLabel?: string;
12
43
  /** Drag a rectangle over a scatter: the dies inside it, the pointer position and the canvas to anchor a menu on. */
13
44
  onSelectPoints?: (points: PlotPoint[], at: {
14
45
  x: number;
15
46
  y: number;
16
- }, anchor: HTMLElement) => void;
47
+ }, anchor: HTMLElement, info?: SelectInfo) => void;
48
+ /**
49
+ * @internal One panel of a faceted plot: headed by its value, smaller, and without the statement and legend, which
50
+ * the grid above it carries for every panel. Its Save as PNG is the grid's.
51
+ */
52
+ panel?: {
53
+ title: string;
54
+ };
55
+ }
56
+ /** What a click on a box or bar picked, besides its units: the category (and colour) it stands for. */
57
+ export interface SelectInfo {
58
+ category?: string;
59
+ group?: string;
60
+ /** The category's test, when the categories are a set's tests. */
61
+ test?: number;
62
+ /** A histogram bar's range of values. */
63
+ range?: {
64
+ lo: number;
65
+ hi: number;
66
+ };
17
67
  }
18
68
  export interface PlotChartHandle {
19
69
  card: HTMLElement;
@@ -21,6 +71,10 @@ export interface PlotChartHandle {
21
71
  actions: HTMLElement;
22
72
  /** Draw `resolved`, replacing whatever was shown. */
23
73
  setPlot(resolved: ResolvedPlot): void;
74
+ /** Rows of the host's own in the card's ⋯ menu (Edit as plot). Read each time the menu opens. */
75
+ setMenuRows(read: () => CardMenuRow[]): void;
76
+ /** @internal Show only these colour groups (all when empty): a faceted plot's legend filters every panel. */
77
+ setActiveGroups(groups: ReadonlySet<number>): void;
24
78
  destroy(): void;
25
79
  }
26
80
  export declare function renderPlotChart(options: PlotChartOptions): PlotChartHandle;