@wafertools/wafermap 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -1
  3. package/dist/packages/canvas-adapter/cellShade.d.ts +21 -0
  4. package/dist/packages/canvas-adapter/cellShade.js +1 -0
  5. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +19 -3
  6. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/commonality.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.d.ts +11 -0
  9. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +23 -0
  11. package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -0
  12. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
  13. package/dist/packages/canvas-adapter/charts/palette.d.ts +10 -3
  14. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +3 -0
  16. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  17. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  18. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +1 -0
  19. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
  20. package/dist/packages/canvas-adapter/filterJson.d.ts +25 -0
  21. package/dist/packages/canvas-adapter/filterJson.js +5 -0
  22. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  23. package/dist/packages/canvas-adapter/pageFilter.js +2 -2
  24. package/dist/packages/canvas-adapter/plotEditor.js +10 -1
  25. package/dist/packages/canvas-adapter/plotJsonComplete.d.ts +46 -0
  26. package/dist/packages/canvas-adapter/plotJsonComplete.js +4 -0
  27. package/dist/packages/canvas-adapter/plotJsonHistory.d.ts +12 -0
  28. package/dist/packages/canvas-adapter/plotJsonHistory.js +1 -0
  29. package/dist/packages/canvas-adapter/plotJsonSuggest.d.ts +16 -0
  30. package/dist/packages/canvas-adapter/plotJsonSuggest.js +1 -0
  31. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  32. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  33. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  34. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  35. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  36. package/dist/packages/canvas-adapter/userGuideHtml.js +40 -18
  37. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  38. package/dist/packages/canvas-adapter/version.js +1 -1
  39. package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -0
  40. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  41. package/dist/packages/core/utils.d.ts +6 -0
  42. package/dist/packages/core/utils.js +1 -1
  43. package/dist/packages/renderer/fmt.js +1 -1
  44. package/dist/packages/stats/chartCatalogue.js +1 -1
  45. package/dist/packages/stats/coFailure.d.ts +11 -0
  46. package/dist/packages/stats/coFailure.js +1 -0
  47. package/dist/packages/stats/correlation.d.ts +7 -0
  48. package/dist/packages/stats/correlation.js +1 -1
  49. package/dist/packages/stats/differenceMap.d.ts +2 -0
  50. package/dist/packages/stats/differenceMap.js +1 -1
  51. package/dist/packages/stats/plotData.d.ts +11 -2
  52. package/dist/packages/stats/plotData.js +1 -1
  53. package/dist/packages/stats/plotSpec.d.ts +31 -2
  54. package/dist/packages/stats/plotSpec.js +4 -4
  55. package/dist/packages/stats/plotTable.d.ts +18 -0
  56. package/dist/packages/stats/plotTable.js +1 -0
  57. package/dist/packages/stats/synthesis.d.ts +6 -0
  58. package/dist/packages/stats/synthesis.js +1 -1
  59. package/dist/packages/stats/testsByWafer.d.ts +11 -0
  60. package/dist/packages/stats/testsByWafer.js +1 -0
  61. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -22,6 +22,61 @@ under `### Breaking`.
22
22
 
23
23
  ---
24
24
 
25
+ ## [Unreleased]
26
+
27
+ ## [0.39.0] — 2026-10-31
28
+
29
+ ### Added
30
+
31
+ - **A JSON view in the Filter window.** A **Conditions | JSON** switch shows the filter as text to edit, paste or copy, with suggestions for its keys, the lot's fields and tests and the values a field takes, undo, and a pasted filters file offering its filters to choose from. The preview follows the text as it is typed; the window's Apply is held, with the reason shown, while the text cannot be read.
32
+ - **Save data as CSV and Copy data in a plot card's ⋯ menu.** The numbers behind a chart: a scatter's points, a histogram's values, a box's five-number summary per category, a bar's or line's values, a heatmap's cells, a control chart's points and limits; a plot of panels names the panel. Copy gives tab-separated text for a spreadsheet.
33
+ - **Yield by site.** An Overview card, drawn when a lot's dies come from two test sites or more: the yield of each site over every wafer, with the median as a line from three sites. A site that is low on every wafer points at the probe card, not the wafers.
34
+ - **Shaded cells in the comparison tables.** A group's or wafer's mean is shaded among its peers (blue below the average, warm above, fading to nothing at the average; a set of means that print the same, or differ by under 1%, is left unshaded) in the Comparison by group table, the new statistics table and the Wafers table; a yield or the share inside limits is tinted red only when it falls a point or more short of its reference (the lot's mean per-wafer yield, or the best group's share), by the summary report's one rule, so a lot with nothing wrong has no tint; a Ppk takes the capable, marginal and poor colours in every statistics table (each group's and the docked panel's); in What divides yield a yield's worst group is tinted by the same rule against the wafers' mean yield, and in the Dies table a reading outside its test's limits is tinted. The numbers are always printed.
35
+ - **Statistics compared across groups.** With Group by on, the Data tab's Statistics view opens with one table of every test for every group (a test's groups side by side, with Ppk and the share inside limits) and its own CSV, above each group's own tables.
36
+ - **Log scale on the Value histogram and the Wafer-to-wafer trend**, and **Clip outliers, Axis includes limits and a log scale for each axis on the Test scatter**, so every value-axis card offers the same axis choices.
37
+
38
+ ### Changed
39
+
40
+ - **The difference map is set up as a gallery map is.** In its card the toolbar is one row of map tools (no view controls or Summary, whose choices would stop it being a difference map) and the map is as wide as the card; expanded, it takes the height the box has left under its note, as the other charts do. Its note reads "…has no value at. How to read this: …".
41
+ - **Choosing a colour in a control chart's legend picks out its wafers.** The chosen colours' points are larger and ringed, and the line between points that are not both chosen is dimmed; the centre and limits, which come from every wafer, stay as they are.
42
+ - **Columns never asks for more columns than there are cards.** The gallery offers up to the wafers on show (at most 5), and the keys 1 to 5 follow. On Insights the count is the most columns a grid uses, for every tab: a tab uses the smaller of it and the cards in its fullest grid, so a tab of two cards is two columns and not two cards in four slots, and a count a host sets on a gallery is kept as it is.
43
+ - **A plot card keeps its size at any display scaling.** Its body never scrolls on its own, so a chart no longer redraws every frame, blurred, at a fractional device pixel ratio (125% scaling, for one), where a scrollbar that appeared and went with a sub-pixel overflow resized it each time.
44
+ - **A heatmap has a line between its cells, a frame and a tick for each row and column.** A pale or empty cell reads as a cell against the card, and each label is tied to its row or column.
45
+ - **A name in capitals is labelled as it is written.** A field called `TEMP` is labelled TEMP; a name is split into words where a word starts (`processSplit` is Process Split, `LOT_ID` is LOT ID), not before every capital letter.
46
+ - **A line over a measured value in ranges says so.** Its title reads "… by range of …", and its note says how many ranges, whether each holds about the same number of dies or the same width, and that a point is drawn at the middle of its range; the band is described as the spread in each range. A test name keeps its own capitals in the note (`vth_n_mV`, not `vth_n_mv`).
47
+ - **Overview leads with Worth a look.** Worth a look, then What divides yield, then the fixed cards; a lot with nothing to show has no Worth a look, so its Overview is the fixed cards as before.
48
+ - **Distributions has one Test picker.** It sits in the Test by test row and sets the test for every card below; a card shows its own picker only while it is expanded.
49
+ - **The Wafers table puts the numbers first.** Wafer, the field Group by divides by, dies, yield and the test means come before the other attributes; attributes that are the same on every wafer are named in a line above the table and kept in the export.
50
+ - **With Group by on, a bar of wafers takes the group's colours.** The per-wafer bar cards in Worth a look draw the wafers under their group on a second level of the X axis, coloured by group, so a pattern that belongs to a group (both low wafers are SS) shows as a colour; the Overview's yield card colours its bars by group as the cards beside it do. With no grouping they are drawn as before.
51
+ - **A colour scale is never stretched over noise.** A heatmap of measured values whose cells are within 1% of their mean has a colour key at least 1% of the mean wide, and the difference map's colours span at least 1% of the level it compares, saying so in its note when no difference is larger; the shaded table cells are left plain when a set of means differ by under 1%.
52
+ - **A field that moves several tests is drawn as a grid in Worth a look.** The chart of "N tests differ by Split" is a heatmap of the field's values by those tests, each cell the mean of its wafers in z-scores.
53
+ - **A heatmap of z-scores runs blue to orange around zero; a yield or pass rate runs orange-red to blue.** A heatmap of rescaled values (z-score or robust z-score) is coloured blue below average, a light neutral at zero and orange above, with the colour bar equally far either side of zero; a heatmap of a yield or pass rate runs orange-red for bad to blue for good on a fixed scale from 50% to 100%, so the same yield is always the same colour. Both stay distinguishable for the common kinds of colour blindness. Each cell's value is dark or white as its colour needs; any other heatmap runs from its lowest cell to its highest.
54
+ - **Axis exponents read as powers of ten.** An axis that needs a shared exponent says ×10³ or ×10⁻⁶ (it said ×10E3), and the Simpson's-paradox warning on the correlation matrix points to the Wafer picker, and to Group by only where one of the mixed fields is in its list.
55
+ - **A line can run along a field put in ranges, and the examples use it.** A line's X can be a measured value or a distance put in ranges: the line is drawn along the middles of the ranges, so a profile across the wafer reads as one line per split instead of a crowd of boxes. Under a split, the examples draw the first test by its partner's ranges and by distance from the centre as lines (median with a ±1 SD band), and the tests with limits as a grid of tests by split.
56
+ - **A control chart can colour its points by a wafer field.** A colour (in Insights, Group by) colours each point by its wafer's value and leaves the line and limits as one series in order, so a pattern that belongs to a group shows as a colour. The Wafer-to-wafer control chart follows Group by.
57
+ - **A heatmap of wafers under Group by sits the wafers with their group.** The columns are ordered by the group first, then by wafer, so a pattern that belongs to a group shows as a block of columns.
58
+ - **Re-probed dies.** A **Re-probed** field (the share of dies probed more than once) is a plot field when a lot has re-probes, and the Overview gains a card of it by ring and wafer (or group), so a hotspot of retests shows.
59
+ - **Fails together on the correlation matrix.** A **Values | Fails together** choice draws the matrix of which tests fail on the same dies: each cell is the share of the dies failing either of two tests that fail both, so two symptoms of one defect show as a pair even when their values do not correlate. Tests without limits, and tests that fail on fewer than two dies, are left out.
60
+ - **Examples are a gallery of their own.** A **My plots | Examples** switch above the list shows one or the other, never both. **Examples** draws one of each chart type from the lot, each marked as an example and not saved, with **Add to my plots**; **Add all** adds the ones that are missing and shows My plots, with an **Undo** that removes only what it added. Looking at the examples does not fill the reader's own list. It replaces **Add examples**, which saved all of them at once.
61
+ - **Cumulative on the Value histogram, By radius on the Test value distribution.** The histogram can be drawn as the cumulative curve of the same values (one curve per colour), and the box plot as a box for each ring from the centre to the edge, so a test that drifts across the wafer shows as a trend of boxes.
62
+ - **Within groups on the correlation matrix.** With Group by on, the matrix offers **Pooled | Within <field>**: within takes each group's mean off every test first, so a difference between groups is not read as a relationship between tests. The mixed-set warning points to it.
63
+ - **Tests by wafer.** A card at the top of Distributions: the twelve tests whose wafers (or groups) differ most, as a grid of z-scores, one row per test, so a block of wafers that moved together across several tests is visible without opening each test. Click a cell for its dies.
64
+ - **Ring and quadrant yield are one card each, with a View choice.** The heatmap by wafer (or group) and the pooled diagram of the same regions share one place in the Overview: **Heatmap | Diagram** in the card's header swaps them, so the Overview has two cards fewer.
65
+ - **Histograms of three or more colours are drawn as outlines.** Each colour is a step line over a faint fill, so overlapping groups no longer blend into one another and each one's shape can be read on its own; one or two colours keep their translucent bars.
66
+ - **The difference map is drawn on the signed scale.** Group A minus group B runs blue where A is lower, a light neutral at zero and orange where it is higher, as every other signed scale does. The scale is also listed as **Blue to orange, around zero** in a map's Value colours menu.
67
+ - **Every signed scale is warm above and blue below.** The correlation matrix draws a positive correlation in orange and a negative one in blue, as a z-score or a difference does, so one colour never means high on one chart and low on the next.
68
+ - **A sweep is a chart type of the plot editor.** **Sweep** sits with the other chart types: choosing it shows the series, title and axes form in Setup and the curve beside it, and choosing another type brings back the plot it was. The JSON tab and its suggestions edit a sweep like any plot. The Plot tab has one **+ New plot** (the separate **+ New sweep** button is gone), and **New sweep…** on a selection's menu opens the same window.
69
+ - **Plots files written with the names `mark` and `encoding`** (before `chart` and `fields`) are read as those plots.
70
+ - **Plot messages say what is wrong and what to do.** A chart or built-in field this version does not know names what it was given, lists what is valid and offers the nearest ("The chart "heatmaps" is not one this version draws (…). Did you mean "heatmap"?"); a field that is not a field says what one looks like; a wafer field no wafer has lists the lot's own and the nearest ("No wafer has a "Split" value. Did you mean "split"?"). A setting or field role this version does not use (`normalise`, `fields.colour`) is still kept, and the reader is now told it does nothing, with the nearest name. A test number written in quotes says to drop them. The JSON tab reports a syntax error with its line and column where the browser gives one, and says before Apply when a plot could not be drawn.
71
+ - **A plot whose test no longer matches the lot's says which is which.** "Test 1050 was "Leakage" when this plot was saved; in these dies it is "Vth". Choose the test again to plot "Vth"" replaces the shorter wording, in the plot, pass-rate and test-set checks alike.
72
+
73
+ ### Added
74
+
75
+ - **The colours of a plot are a setting.** A heatmap, or a scatter coloured by a number, has **Colours** and **Reverse colours** in Customise (`colorGradient` and `colorReverse` in the JSON): blue to orange around zero, orange-red to blue for a rating, or any of the map's gradients (Viridis, Cividis, Plasma, Traffic…; Cividis is the colour-blind-safe one). Automatic is blue to orange for values rescaled around zero, orange-red to blue for a yield or pass rate, and the map's gradient for any other. Each heatmap cell's value is dark or white as its colour needs.
76
+ - **A JSON tab in the plot editor.** Beside Setup and Customise, it shows the plot as the JSON of a plots-file entry, which can be copied, edited or replaced by pasted text. **Apply** reads the text with the reader a plots file goes through, so a setting this version does not know is left out and named before it is applied, and text that is not a plot cannot be applied. Suggestions open as you type inside a key or a string, after a comma, brace, colon or bracket, and from the **Suggest** button or **Ctrl/Cmd+Space**: the plot's settings, a chart type, aggregate or other setting that takes a few words, a field's kind, a built-in field, the lot's wafer fields and its test numbers with their names, and accepting one is undone by Ctrl+Z; the words come from the table the reader checks a plot against, so a suggestion is never refused. **Discard edits** drops text not yet applied; changing a test's number leaves its old name out, since the name would no longer match; the window's own Reset and Cancel go back to the plot as it was when the window opened. **Ctrl/Cmd+Z** undoes the text first (typing, an accepted suggestion, a plot chosen from a pasted file, Discard edits) and then each Apply, and **Shift+Ctrl/Cmd+Z** (or **Ctrl/Cmd+Y**) redoes; the editor keeps this history itself, so it is the same in every browser. The text holds the plot without its id, and a plots file or a list of plots can be pasted, the tab listing the plots of a file that holds several to choose from.
77
+
78
+ ---
79
+
25
80
  ## [0.38.0] — 2026-10-28
26
81
 
27
82
  ### Breaking
package/README.md CHANGED
@@ -7,7 +7,8 @@
7
7
  ![runtime deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen)
8
8
  ![bundle](https://img.shields.io/badge/data%20layer%20min%2Bgz-~82%20kB-blue)
9
9
  [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
10
- [![support](https://img.shields.io/badge/support-wafertools-ff5e5b)](https://wafertools.github.io/support/)
10
+ [![sponsor on GitHub](https://img.shields.io/badge/sponsor-GitHub%20Sponsors-ea4aaa?logo=githubsponsors&logoColor=white)](https://github.com/sponsors/wafertools)
11
+ [![support on Ko-fi](https://img.shields.io/badge/support-Ko--fi-ff5e5b?logo=ko-fi&logoColor=white)](https://ko-fi.com/wafertools)
11
12
 
12
13
  <img src="docs/images/hero-test-values.png" alt="wafermap demo" style="max-width:640px; display:block; margin:8px 0;" />
13
14
 
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A value among its peers, as a shade: `fraction` is its deviation from their average over the largest deviation among
3
+ * them, from −1 to 1. Blue below, warm above, stronger the further it is, nothing at the average.
4
+ */
5
+ export declare function signedShade(fraction: number): string | undefined;
6
+ /**
7
+ * The shade of each value among the others of its set, by `signedShade`: the deviation from the set's mean over the
8
+ * set's largest deviation. A set of one, or of equal values, has no shade, and neither has a set whose values print the
9
+ * same (`show`) or differ by under 1% of their mean: a colour must not tell apart numbers the table shows as one.
10
+ */
11
+ export declare function shadesAmong(values: readonly number[], show?: (v: number) => string): Array<string | undefined>;
12
+ /**
13
+ * A yield's shortfall below its reference, in points (yield minus reference, so negative is short), tinted by the summary
14
+ * report's rule: a point or more short is light, two medium, four strong; nothing at or above the reference.
15
+ */
16
+ export declare function shortfallShade(points: number | null | undefined): string | undefined;
17
+ /** A Ppk as capable (1.33 and over), marginal (1.0 and over) or poor, in the capability chart's colours. */
18
+ export declare function capabilityShade(ppk: number | null | undefined): string | undefined;
19
+ /** A value outside its limits, in the warm hue. */
20
+ export declare function outOfLimitsShade(): string;
21
+ //# sourceMappingURL=cellShade.d.ts.map
@@ -0,0 +1 @@
1
+ import{SIGNED_HIGH as o,SIGNED_LOW as s,capabilityColor as c}from"./charts/palette.js";import{NEGLIGIBLE_SPREAD as h,maxOf as d,minOf as l}from"../core/utils.js";import{shortfallColor as p,shortfallStep as b}from"../stats/presentation.js";const f=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)],a=([n,e,t],r)=>`rgba(${Math.round(n)}, ${Math.round(e)}, ${Math.round(t)}, ${r.toFixed(2)})`,S=.42,x=.05;export function signedShade(n){if(!Number.isFinite(n))return;const e=Math.max(-1,Math.min(1,n));if(!(Math.abs(e)<x))return a(f(e<0?s:o),S*Math.abs(e))}export function shadesAmong(n,e){const t=n.filter(Number.isFinite);if(t.length<2)return n.map(()=>{});if(e&&new Set(t.map(e)).size<2)return n.map(()=>{});const r=t.reduce((i,m)=>i+m,0)/t.length,u=d(t.map(i=>Math.abs(i-r)));return u>0?r!==0&&(d(t)-l(t))/Math.abs(r)<h?n.map(()=>{}):n.map(i=>signedShade((i-r)/u)):n.map(()=>{})}export function shortfallShade(n){if(n==null||!Number.isFinite(n))return;const e=b(n);return e?p(e):void 0}export function capabilityShade(n){if(!(n==null||!Number.isFinite(n)))return a(f(c(n)),.3)}export function outOfLimitsShade(){return a(f(o),.3)}
@@ -345,6 +345,15 @@ export interface SeriesLegendItem {
345
345
  */
346
346
  export declare function makeSeriesLegendItem(label: string, color: string, ownerDocument?: Document): SeriesLegendItem;
347
347
  export declare function cardFrameStyle(): Partial<CSSStyleDeclaration>;
348
+ /**
349
+ * Two cards that are two views of one idea (a heatmap and a diagram of the same regions) as one place in the grid: a
350
+ * View choice in each card's header shows one and hides the other. Each stays a whole card, so its menu, About line and
351
+ * Expand are its own; the first is shown to begin with.
352
+ */
353
+ export declare function pairCards(views: Array<{
354
+ label: string;
355
+ card: HTMLElement;
356
+ }>, ownerDocument?: Document): HTMLElement;
348
357
  export declare function cardShell(title: string, onSaveImage?: SaveImageHandler, ownerDocument?: Document, opts?: CardShellOptions): CardShell;
349
358
  /**
350
359
  * "How to read this: *Control charts* in the user guide" (no full stop), the title a link that opens the guide at that
@@ -361,7 +370,9 @@ export declare function makeSegmented(
361
370
  options: Array<[value: string, label: string, hint?: string]>, current: string, onChange: (value: string) => void, ownerDocument?: Document,
362
371
  /** Smaller type/padding for the summary panel's 260px column, where the
363
372
  * chart-card sizing overflows a section header. Charts keep the default. */
364
- compact?: boolean): HTMLElement;
373
+ compact?: boolean): HTMLElement & {
374
+ setValue(value: string): void;
375
+ };
365
376
  /**
366
377
  * A table that lists its first `first` rows, with a button to list every one and back. Listed in full it scrolls inside
367
378
  * `scroller` after `ALL_ROWS_MAX_PX`, so a lot of a hundred wafers is a scrolling table in a card of the usual size,
@@ -544,10 +555,15 @@ export declare function makeWaferSelect(items: readonly WaferSelectItem[], selec
544
555
  value: string;
545
556
  };
546
557
  export declare function makeToggle(labelText: string, checked: boolean, onChange: (v: boolean) => void, ownerDocument?: Document, hint?: string): HTMLLabelElement;
547
- export declare function makeLabeledSelect(labelText: string, options: readonly {
558
+ export declare function makeLabeledSelect(labelText: string,
559
+ /** A getter is read each time the list opens (see `makeListSelect`). */
560
+ options: readonly {
561
+ value: string;
562
+ label: string;
563
+ }[] | (() => readonly {
548
564
  value: string;
549
565
  label: string;
550
- }[], selected: string, onChange: (value: string) => void,
566
+ }[]), selected: string, onChange: (value: string) => void,
551
567
  /** `hint` is the hover tooltip over the label and its trigger, for a control whose name alone does not say what it does. */
552
568
  opts?: {
553
569
  maxWidth?: string;
@@ -1 +1 @@
1
- import{SHADOW as te,LEADING as me,wireTooltip as z,wireControlHover as P,controlStyle as X,SPACE as C,RADIUS as B,fontPx as q,FONT as E,CLR as g,Z_BASE as he,menuLayerFor as ge,wireListNavigation as be,MENU_SEARCH_THRESHOLD as ne,makeMenuSearchBox as xe,markMenuTrigger as V,markNoPrint as G,openCommandMenu as ye,saveImageBlob as we,openReparentedModal as Ce}from"../toolbar.js";import{ICONS as oe}from"../icons.js";import{openGuideAt as ve}from"../guideWindow.js";import{minOf as Se,maxOf as ke}from"../../core/utils.js";import{robustFence as ie}from"../../stats/math.js";import{fmt as Ae,fmtColorbarAxis as Le,nameStatesUnit as Ee}from"../../renderer/fmt.js";import{isTestPinned as $e,toggleTestPinned as Be}from"../pinnedTests.js";import{markedTestLabel as Te,DERIVED_LANE_PAD as Oe}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=Ce([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:Re[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const c=Number(e.dataset.wmapChartFullH);if(!c)return;const d=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(d+c)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const Re={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const c=s[1].length===3?s[1].split("").map(d=>d+d).join(""):s[1];[i,n,r]=[0,2,4].map(d=>parseInt(c.slice(d,d+2),16)),c.length===8&&(l=parseInt(c.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Pe={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},re={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(re)){const n=o.getPropertyValue(`--wmap-${re[i]}`).trim();t[i]=n||Pe[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${K(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function K(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function le(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(K(e,o)-l)-(t?le(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(K(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=le(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${q(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:Ae(e,void 0,"engineering"):"\u2014"}function Me(e,o){const t=`${o} (`;return e.startsWith(t)&&e.endsWith(")")?e.slice(t.length,-1):""}export function makeAxisFormat(e,o,t,i){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const n=Ee(i,o),{tickFmt:r,axisLabel:l,scaledUnit:s}=Le(e,n?i:null,o,"engineering",t);return{tick:r,tickWithUnit:s?a=>`${r(a)} ${s}`:r,unitLabel:n?Me(l,i):l}}const Ie=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+Ie}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${q(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const U=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Fe=/\s*[▾▼]\s*$/,Y=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!U(l,t))continue;const s=(l.textContent??"").replace(Fe,"").trim();if(!s)continue;const a=l.closest("label"),d=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(d&&d!==s?`${d}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!U(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!U(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!U(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}const r=Y.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function De(e){const o=describeCard(e),t=Y.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function se(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ae=new WeakSet;function He(e){if(ae.has(e))return;ae.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>se(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&se(e)})}catch{}}function je(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(m,f="400")=>`${f} ${m*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,c=(m,f)=>l?(l.font=f,l.measureText(m).width):m.length*7*n,d=[];let p=0;if(o){p=s,d.push({kind:"text",text:o.title,x:s,y:p+14*n,font:a(16,"600"),alpha:1}),p+=24*n;const m=o.decor,f=[];m?.controls?.length&&f.push({text:m.controls.join(" \xB7 "),alpha:1});for(const w of m?.caption===void 0?[]:typeof m.caption=="string"?[m.caption]:m.caption)f.push({text:w,alpha:.75});const x=a(12);for(const{text:w,alpha:y}of f){let h="";for(const k of w.split(" ")){const T=h?`${h} ${k}`:k;h&&c(T,x)>r-2*s?(d.push({kind:"text",text:h,x:s,y:p+11*n,font:x,alpha:y}),p+=17*n,h=k):h=T}h&&(d.push({kind:"text",text:h,x:s,y:p+11*n,font:x,alpha:y}),p+=17*n)}if(m?.legend?.length){p+=4*n;const w=a(12);let y=s;for(const h of m.legend){const k=14*n+c(h.label,w)+14*n;y>s&&y+k>r-s&&(y=s,p+=18*n),d.push({kind:"dot",x:y+5*n,y:p+7*n,r:5*n,color:h.color}),d.push({kind:"text",text:h.label,x:y+14*n,y:p+11*n,font:w,alpha:1}),y+=k}p+=20*n}if(m?.colorbar){p+=4*n;const w=a(12),y=m.colorbar;let h=s;d.push({kind:"text",text:y.label,x:h,y:p+10*n,font:w,alpha:1}),h+=c(y.label,w)+10*n,d.push({kind:"text",text:y.lo,x:h,y:p+10*n,font:w,alpha:.75}),h+=c(y.lo,w)+6*n,d.push({kind:"strip",x:h,y:p+1*n,w:200*n,h:10*n,color:y.color}),h+=206*n,d.push({kind:"text",text:y.hi,x:h,y:p+10*n,font:w,alpha:.75}),p+=20*n}p+=6*n}i.width=r,i.height=Math.ceil(e.height+p);const u=i.getContext("2d");if(u.fillStyle=o?je(o.card):"#ffffff",u.fillRect(0,0,i.width,i.height),o){const m=t.defaultView,f=m&&m.getComputedStyle(o.card).color||"#222222";u.textBaseline="alphabetic";for(const x of d)if(x.kind==="text")u.font=x.font,u.fillStyle=f,u.globalAlpha=x.alpha,u.fillText(x.text,x.x,x.y),u.globalAlpha=1;else if(x.kind==="dot")u.fillStyle=x.color,u.beginPath(),u.arc(x.x,x.y,x.r,0,Math.PI*2),u.fill();else for(let w=0;w<x.w;w++)u.fillStyle=x.color(w/Math.max(1,x.w-1)),u.fillRect(x.x+w,x.y,1,x.h)}return u.drawImage(e,0,p),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&we(n,o,t)},"image/png")}const ce="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${ce}`,`height:${ce}`,`border-radius:${B.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ne="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:C.xs,padding:`${C.xs} ${C.md}`,borderRadius:B.pill,border:`1px solid ${g.menuBorder}`,background:"none",cursor:"pointer",fontSize:E.body,color:g.text,whiteSpace:"nowrap"}),P(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?g.iconActive:g.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ne:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:B.container,padding:C.xl,fontVariantNumeric:"tabular-nums"}}function de(e){Object.assign(e.style,{...X("outlined"),color:g.label,padding:"0",width:"22px",height:"22px",lineHeight:me.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),P(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:C.sm,paddingBottom:"6px",marginBottom:C.md,borderBottom:`1px solid ${g.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:g.value,fontSize:E.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=oe.expand,a.dataset.wmapCardExpand="1",de(a),attachChartTip(a,n,s,"Expand"),G(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const c=n.ownerDocument.createElement("button");c.type="button",c.setAttribute("aria-label","Chart actions"),c.innerHTML=oe.more,c.dataset.wmapCardMenu="1",de(c),attachChartTip(c,n,s,"Chart actions"),V(c,!1),G(c),r.appendChild(c);const d=n.ownerDocument.createElement("div");d.dataset.wmapCardAbout="1",d.setAttribute("role","note"),Object.assign(d.style,{display:"none",color:g.label,fontSize:E.body,marginBottom:C.md}),G(d);let p;const u=v=>{d.textContent=v?p?.text??"":"",d.style.display=v?"":"none"};let m,f;const x=()=>{const v=m?m():n.querySelector("canvas");v&&saveCanvasPng(v,l.textContent||e,o,{card:n,title:l.textContent||e,decor:De(n)})},w=()=>{const v=[],H=(S,j,N)=>({label:S,active:!1,action:!0,enabled:!N,disabledHint:N,onClick:()=>{y?.(),j()}});i.png!==!1&&(m||n.querySelector("canvas"))&&v.push(H("Save as PNG",x));for(const S of f?.()??[])v.push(H(S.label,S.onClick,S.disabledHint));if(p){const S=d.style.display!=="none";v.push({label:`About this ${p.noun}`,active:S,onClick:()=>{y?.(),u(!S)}})}return v};let y;c.addEventListener("click",()=>{if(c.getAttribute("aria-expanded")==="true"){y?.();return}const v=w();v.length!==0&&(y=ye(c.getBoundingClientRect(),c,v,`${l.textContent||e}: chart actions`,{trigger:c,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(d);const h=n.ownerDocument.createElement("div");h.dataset.wmapPrintOnly="1",Object.assign(h.style,{display:"none",color:g.label,fontSize:E.body,marginBottom:C.sm}),n.appendChild(h),He(n.ownerDocument);const k=n.ownerDocument.createElement("div");k.dataset.wmapControls="1",Object.assign(k.style,{display:"flex",gap:C.sm,marginBottom:C.md,flexWrap:"wrap",alignItems:"center"}),G(k),n.appendChild(k);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:k,body:T,setPngDecor:v=>{Y.set(n,v)},setPngCanvas:v=>{m=v},setAbout:v=>{p=v,u(!!v&&d.style.display!=="none")},setMenuRows:v=>{f=v}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,pe(e,o)," in the user guide"),i}function pe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:g.iconActive,textDecoration:"underline",cursor:"pointer"}),P(t),t.addEventListener("click",()=>ve(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(pe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:B.control,padding:`${C.xs} ${C.sm}`,fontSize:E.body,fontFamily:E.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(([c,d,p],u)=>{const m=i.createElement("label");p&&z(m,p),Object.assign(m.style,{display:"inline-flex",alignItems:"center",fontSize:E.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${g.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:u===0?B.control:"0",borderBottomLeftRadius:u===0?B.control:"0",borderTopRightRadius:u===l?B.control:"0",borderBottomRightRadius:u===l?B.control:"0"}),P(m,"bare");const f=i.createElement("input");f.type="radio",f.name=s,f.value=c,f.checked=c===o,Object.assign(f.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const x=()=>{m.style.background=f.checked?g.bgActive:g.menuBg,m.style.color=f.checked?g.iconActive:g.text,m.dataset.on=f.checked?"true":"false"};a.push(x),x(),f.addEventListener("change",()=>{if(f.checked){for(const w of a)w();t(c)}}),m.append(f,i.createTextNode(d)),r.appendChild(m)}),r}const We=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{...X("outlined"),marginTop:C.sm}),P(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${We}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{...X("outlined"),background:g.menuBg,color:g.label}),P(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:g.label,fontSize:E.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:c}=i,d=()=>typeof e=="function"?e():e;let p=d(),u=o;const m=S=>p.find(j=>j.value===S)?.label??"",f=r.createElement("button");f.type="button",c&&(f.dataset.wmapSelect=c),l&&f.setAttribute("aria-label",l),Object.assign(f.style,{fontSize:E.body,padding:`${C.xxs} ${C.sm}`,background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:B.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:C.sm,justifyContent:"space-between"}),P(f),V(f,!1);const x=r.createElement("span");Object.assign(x.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const w=r.createElement("span");w.textContent="\u25BE",w.style.flex="0 0 auto",f.append(x,w);const y=()=>{x.textContent=p.length===0?s??"(none)":m(u)||s||"(none)"};if(y(),p.length===0)return f.disabled=!0,f.style.opacity="0.6",f.style.cursor="default",Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}});let h=null;const k=()=>{h&&(h.remove(),h=null,V(f,!1))},T=()=>{k(),f.focus()};function v(){p=d();const S=f.getBoundingClientRect(),j=r.defaultView??window,N=Math.max(S.width,220),ue=Math.min(S.left,Math.max(4,(j.innerWidth??1/0)-N-4));h=r.createElement("div"),h.setAttribute("role","listbox"),h.setAttribute("aria-label",l??"Options"),Object.assign(h.style,{position:"fixed",top:`${S.bottom+4}px`,left:`${ue}px`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:B.control,boxShadow:te.menu,zIndex:he,minWidth:`${N}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const M=[],_=()=>M.filter(b=>b.row.style.display!=="none").map(b=>b.row),W=[],fe=()=>{for(const b of W)b.el.style.display=M.slice(b.first,b.last+1).some(L=>L.row.style.display!=="none")?"":"none"};if(p.length>ne){const b=xe(L=>{for(const A of M)A.row.style.display=A.label.includes(L)?"":"none";fe()},a,r,_);Object.assign(b.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),b.addEventListener("keydown",L=>{if(L.key==="Escape"){L.preventDefault(),T();return}L.key==="ArrowDown"&&(L.preventDefault(),_()[0]?.focus())}),h.appendChild(b)}let Z;for(const b of p){if(b.group!==void 0&&b.group!==Z){const $=r.createElement("div");$.textContent=b.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${C.sm} ${C.xl} ${C.xxs}`,fontSize:E.sub,color:g.label,fontWeight:"600"}),h.appendChild($),W.push({el:$,first:M.length,last:M.length})}Z=b.group;const L=b.value===u,A=r.createElement("div"),J=r.createElement("span");if(J.textContent=b.disabled?`${b.label} \u2014 ${b.disabled}`:b.label,A.appendChild(J),A.setAttribute("role","option"),A.setAttribute("aria-selected",L?"true":"false"),b.disabled&&A.setAttribute("aria-disabled","true"),A.tabIndex=-1,Object.assign(A.style,{padding:`${C.sm} ${C.xl}`,fontSize:E.body,cursor:b.disabled?"default":"pointer",color:b.disabled?g.label:L?g.iconActive:g.text,fontWeight:L?"700":"400",opacity:b.disabled?"0.7":"",background:L?g.menuActive:"transparent",whiteSpace:"nowrap",...b.pin?{display:"flex",alignItems:"center",justifyContent:"space-between",gap:C.xl}:{}}),b.pin){const $=b.pin;A.setAttribute("aria-keyshortcuts","P");const O=r.createElement("span"),Q="http://www.w3.org/2000/svg",I=r.createElementNS(Q,"svg");I.setAttribute("viewBox","0 0 24 24"),I.setAttribute("width","14"),I.setAttribute("height","14"),I.setAttribute("aria-hidden","true");const F=r.createElementNS(Q,"path");F.setAttribute("d","M12 2.5l2.9 6.2 6.8.8-5 4.7 1.3 6.7L12 17.5 6 20.9l1.3-6.7-5-4.7 6.8-.8z"),F.setAttribute("fill",$.pinned?"currentColor":"none"),F.setAttribute("stroke","currentColor"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linejoin","round"),I.appendChild(F),O.appendChild(I),O.dataset.wmapPin=$.pinned?"pinned":"unpinned",O.setAttribute("role","button"),O.setAttribute("aria-label",`${$.pinned?"Unpin":"Pin"} ${b.label} (or press P on the row)`),Object.assign(O.style,{cursor:"pointer",color:$.pinned?g.iconActive:g.label,flex:"0 0 auto",padding:`0 ${C.xs}`,display:"inline-flex",alignItems:"center"}),P(O,"bare"),z(O,$.pinned?"Unpin this test":"Pin this test to the top of every test list");const ee=R=>{R.preventDefault(),R.stopPropagation(),k(),$.toggle(),v()};O.addEventListener("click",ee),A.addEventListener("keydown",R=>{(R.key==="p"||R.key==="P")&&!R.ctrlKey&&!R.metaKey&&!R.altKey&&ee(R)}),A.appendChild(O)}A.addEventListener("mouseenter",()=>{!L&&!b.disabled&&(A.style.background=g.menuHover)}),A.addEventListener("mouseleave",()=>{L||(A.style.background="transparent")}),A.addEventListener("click",$=>{$.stopPropagation(),!b.disabled&&(u=b.value,y(),T(),t(b.value))}),h.appendChild(A),M.push({row:A,label:b.label.toLowerCase()}),W.length&&(W[W.length-1].last=M.length-1)}if(be(h,_,T),ge(f).appendChild(h),V(f,!0),p.length<=ne){const b=p.findIndex(L=>L.value===u);_()[b>=0?b:0]?.focus()}}f.addEventListener("click",S=>{if(S.stopPropagation(),h){k();return}v()});const H=S=>{if(!f.isConnected){r.removeEventListener("click",H);return}h&&!h.contains(S.target)&&!f.contains(S.target)&&k()};return r.addEventListener("click",H),Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?Oe:"")+Te(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i,s=testOptionLabels(e);return makeListSelect(()=>{const c=e.map((u,m)=>({item:u,label:s[m],pinned:$e(u.testNumber)})),d=c.some(u=>u.pinned),p=(u,m)=>({value:String(u.item.testNumber),label:u.label,...m?{group:m}:{},pin:{pinned:u.pinned,toggle:()=>Be(u.item.testNumber)}});return d?[...c.filter(u=>u.pinned).map(u=>p(u,"Pinned")),...c.filter(u=>!u.pinned).map(u=>p(u,"All tests"))]:c.map(u=>p(u))},o!==null?String(o):"",c=>t(Number(c)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,c,d=!1){e.innerHTML="",d&&e.appendChild(makeLimitsSelect(l,p=>{l=p,s()},i)),c&&e.appendChild(makeToggle("Axis includes limits",a,p=>{n=p,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,p=>{r=p,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const c=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&c===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=c,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=d=>d??ALL_GROUPS,s=d=>d===ALL_GROUPS?null:d,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(d=>({value:d,label:d}))],l(r),d=>{const p=s(d);p!==r&&(r=p,i(p))},{...n,hook:"group-scope"}),c=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(d){return r===d||d!==null&&!e.includes(d)?!1:(r=d,c&&(c.value=l(d)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,c)=>({value:String(c),label:a.label??`#${c}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.xs,fontSize:E.body,color:g.label,cursor:"pointer",userSelect:"none"}),P(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&z(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document,hint:a}=n,c=s.createElement("label");c.textContent=e,Object.assign(c.style,{color:g.label,fontSize:E.body,display:"flex",alignItems:"center",gap:C.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return c.appendChild(d),a&&z(c,a),c}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(var(--wmap-insights-cols, auto-fit), minmax(var(--wmap-insights-min, 420px), 1fr))",gap:C.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:B.control,padding:`${C.sm} ${C.xl}`,fontSize:E.sub,fontFamily:E.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:te.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let c=t-n.left+r,d=i-n.top+r;c+s+l>n.width&&(c=t-n.left-r-s),d+a+l>n.height&&(d=i-n.top-r-a),c=Math.max(l,c),d=Math.max(l,d),e.style.left=`${c}px`,e.style.top=`${d}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function D(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 D(e,"test").length>0&&D(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=D(e,"test"),i=D(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...D(e,"pat"),...D(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:Se(o),hi:ke(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{ie as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,c=0;if(r&&l?.length){const p=ie(l);if(p){const u=Math.max(s,p.lo),m=Math.min(a,p.hi);m>u&&(c=l.filter(f=>Number.isFinite(f)&&(f<u||f>m)).length,s=u,a=m)}}if(n)for(const p of i)s=Math.min(s,p.value),a=Math.max(a,p.value);s===a&&(s-=1,a+=1);const d=[];for(const p of i)p.value<s?d.push({value:p.value,label:p.label,side:"lo"}):p.value>a&&d.push({value:p.value,label:p.label,side:"hi"});return{lo:s,hi:a,offAxis:d,clippedCount:c}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function limitLabelPlacement(e,o,t,i,n,r,l=[],s=3){const a=r?-1:1;for(const c of[a,-a])for(const d of o){const p=t(d),u=c<0?e-s-p:e+s,m=c<0?e-s:e+s+p;if(!(u<i||m>n)&&!l.some(f=>f>u&&f<m))return{text:d,side:c}}return{text:o[0],side:limitLabelSide(e,t(o[0]),i,n,r,s)}}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${q(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},c=q(-1)+2;for(const{value:d,label:p,side:u}of o){const m=a[u]++*c,f=i==="horizontal"?u==="lo"?"\u2190":"\u2192":u==="lo"?"\u2193":"\u2191",x=u==="lo"?`${f} ${p} ${r(d)}`:`${p} ${r(d)} ${f}`,w=e.measureText(x).width;if(i==="horizontal"){const y=u==="lo"?t.left+2:t.right-2-w,h={x0:y,x1:y+w,y0:t.top+2+m,y1:t.top+2+m+c},k=s?placeClearOf(s,h,c):h;e.textBaseline="top",e.textAlign=u==="lo"?"left":"right",fillTextOnHalo(e,x,u==="lo"?t.left+2:t.right-2,k.y0,l)}else{const y=u==="lo"?t.bottom-2-m-c:t.top+2+m,h={x0:t.left+4,x1:t.left+4+w,y0:y,y1:y+c},k=s?placeClearOf(s,h,u==="lo"?-c:c):h;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,x,t.left+4,k.y0,l)}}e.restore()}
1
+ import{SHADOW as te,LEADING as me,wireTooltip as z,wireControlHover as P,controlStyle as X,SPACE as C,RADIUS as B,fontPx as q,FONT as L,CLR as b,Z_BASE as he,menuLayerFor as ge,wireListNavigation as be,MENU_SEARCH_THRESHOLD as ne,makeMenuSearchBox as xe,markMenuTrigger as V,markNoPrint as G,openCommandMenu as ye,saveImageBlob as we,openReparentedModal as Ce}from"../toolbar.js";import{ICONS as oe}from"../icons.js";import{openGuideAt as ve}from"../guideWindow.js";import{minOf as Se,maxOf as ke}from"../../core/utils.js";import{robustFence as ie}from"../../stats/math.js";import{fmt as Ae,fmtColorbarAxis as Ee,nameStatesUnit as Le}from"../../renderer/fmt.js";import{isTestPinned as $e,toggleTestPinned as Be}from"../pinnedTests.js";import{markedTestLabel as Te,DERIVED_LANE_PAD as Oe}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=Ce([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:Re[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const c=Number(e.dataset.wmapChartFullH);if(!c)return;const d=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(d+c)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const Re={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const c=s[1].length===3?s[1].split("").map(d=>d+d).join(""):s[1];[i,n,r]=[0,2,4].map(d=>parseInt(c.slice(d,d+2),16)),c.length===8&&(l=parseInt(c.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Pe={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},re={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(re)){const n=o.getPropertyValue(`--wmap-${re[i]}`).trim();t[i]=n||Pe[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${K(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function K(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function le(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(K(e,o)-l)-(t?le(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(K(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=le(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${q(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:Ae(e,void 0,"engineering"):"\u2014"}function Me(e,o){const t=`${o} (`;return e.startsWith(t)&&e.endsWith(")")?e.slice(t.length,-1):""}export function makeAxisFormat(e,o,t,i){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const n=Le(i,o),{tickFmt:r,axisLabel:l,scaledUnit:s}=Ee(e,n?i:null,o,"engineering",t);return{tick:r,tickWithUnit:s?a=>`${r(a)} ${s}`:r,unitLabel:n?Me(l,i):l}}const Ie=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+Ie}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${q(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const U=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Fe=/\s*[▾▼]\s*$/,Y=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!U(l,t))continue;const s=(l.textContent??"").replace(Fe,"").trim();if(!s)continue;const a=l.closest("label"),d=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(d&&d!==s?`${d}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!U(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!U(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!U(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,c=(l.textContent??"").trim();c&&a&&a!=="transparent"&&n.push({label:c,color:a})}const r=Y.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function He(e){const o=describeCard(e),t=Y.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function se(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ae=new WeakSet;function je(e){if(ae.has(e))return;ae.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>se(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&se(e)})}catch{}}function De(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(m,f="400")=>`${f} ${m*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,c=(m,f)=>l?(l.font=f,l.measureText(m).width):m.length*7*n,d=[];let p=0;if(o){p=s,d.push({kind:"text",text:o.title,x:s,y:p+14*n,font:a(16,"600"),alpha:1}),p+=24*n;const m=o.decor,f=[];m?.controls?.length&&f.push({text:m.controls.join(" \xB7 "),alpha:1});for(const w of m?.caption===void 0?[]:typeof m.caption=="string"?[m.caption]:m.caption)f.push({text:w,alpha:.75});const g=a(12);for(const{text:w,alpha:y}of f){let h="";for(const k of w.split(" ")){const T=h?`${h} ${k}`:k;h&&c(T,g)>r-2*s?(d.push({kind:"text",text:h,x:s,y:p+11*n,font:g,alpha:y}),p+=17*n,h=k):h=T}h&&(d.push({kind:"text",text:h,x:s,y:p+11*n,font:g,alpha:y}),p+=17*n)}if(m?.legend?.length){p+=4*n;const w=a(12);let y=s;for(const h of m.legend){const k=14*n+c(h.label,w)+14*n;y>s&&y+k>r-s&&(y=s,p+=18*n),d.push({kind:"dot",x:y+5*n,y:p+7*n,r:5*n,color:h.color}),d.push({kind:"text",text:h.label,x:y+14*n,y:p+11*n,font:w,alpha:1}),y+=k}p+=20*n}if(m?.colorbar){p+=4*n;const w=a(12),y=m.colorbar;let h=s;d.push({kind:"text",text:y.label,x:h,y:p+10*n,font:w,alpha:1}),h+=c(y.label,w)+10*n,d.push({kind:"text",text:y.lo,x:h,y:p+10*n,font:w,alpha:.75}),h+=c(y.lo,w)+6*n,d.push({kind:"strip",x:h,y:p+1*n,w:200*n,h:10*n,color:y.color}),h+=206*n,d.push({kind:"text",text:y.hi,x:h,y:p+10*n,font:w,alpha:.75}),p+=20*n}p+=6*n}i.width=r,i.height=Math.ceil(e.height+p);const u=i.getContext("2d");if(u.fillStyle=o?De(o.card):"#ffffff",u.fillRect(0,0,i.width,i.height),o){const m=t.defaultView,f=m&&m.getComputedStyle(o.card).color||"#222222";u.textBaseline="alphabetic";for(const g of d)if(g.kind==="text")u.font=g.font,u.fillStyle=f,u.globalAlpha=g.alpha,u.fillText(g.text,g.x,g.y),u.globalAlpha=1;else if(g.kind==="dot")u.fillStyle=g.color,u.beginPath(),u.arc(g.x,g.y,g.r,0,Math.PI*2),u.fill();else for(let w=0;w<g.w;w++)u.fillStyle=g.color(w/Math.max(1,g.w-1)),u.fillRect(g.x+w,g.y,1,g.h)}return u.drawImage(e,0,p),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&we(n,o,t)},"image/png")}const ce="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${ce}`,`height:${ce}`,`border-radius:${B.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ne="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:C.xs,padding:`${C.xs} ${C.md}`,borderRadius:B.pill,border:`1px solid ${b.menuBorder}`,background:"none",cursor:"pointer",fontSize:L.body,color:b.text,whiteSpace:"nowrap"}),P(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?b.iconActive:b.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ne:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:B.container,padding:C.xl,fontVariantNumeric:"tabular-nums"}}function de(e){Object.assign(e.style,{...X("outlined"),color:b.label,padding:"0",width:"22px",height:"22px",lineHeight:me.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),P(e)}export function pairCards(e,o=document){const t=o.createElement("div");t.dataset.wmapCardPair="1",Object.assign(t.style,{display:"flex",flexDirection:"column",minWidth:"0",minHeight:"0",flex:"1 1 0"});const i=e.map(l=>l.card.style.display),n=[],r=l=>{e.forEach((s,a)=>{s.card.style.display=a===l?i[a]:"none"});for(const s of n)s.setValue(String(l))};return e.forEach((l,s)=>{const a=[...l.card.children].find(d=>d.querySelector("[data-wmap-card-expand]")),c=makeSegmented(e.map((d,p)=>[String(p),d.label]),String(s),d=>{r(Number(d))},o);n.push(c),c.dataset.wmapCardView="1",a?.firstElementChild&&a.firstElementChild.after(c),t.appendChild(l.card)}),r(0),t}export function cardShell(e,o,t=document,i={}){const n=t.createElement("div");n.dataset.wmapChartCard="1",n.dataset.wmapChartTitle=e,Object.assign(n.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=n.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:C.sm,paddingBottom:"6px",marginBottom:C.md,borderBottom:`1px solid ${b.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:b.value,fontSize:L.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=oe.expand,a.dataset.wmapCardExpand="1",de(a),attachChartTip(a,n,s,"Expand"),G(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const c=n.ownerDocument.createElement("button");c.type="button",c.setAttribute("aria-label","Chart actions"),c.innerHTML=oe.more,c.dataset.wmapCardMenu="1",de(c),attachChartTip(c,n,s,"Chart actions"),V(c,!1),G(c),r.appendChild(c);const d=n.ownerDocument.createElement("div");d.dataset.wmapCardAbout="1",d.setAttribute("role","note"),Object.assign(d.style,{display:"none",color:b.label,fontSize:L.body,marginBottom:C.md}),G(d);let p;const u=v=>{d.textContent=v?p?.text??"":"",d.style.display=v?"":"none"};let m,f;const g=()=>{const v=m?m():n.querySelector("canvas");v&&saveCanvasPng(v,l.textContent||e,o,{card:n,title:l.textContent||e,decor:He(n)})},w=()=>{const v=[],j=(S,D,N)=>({label:S,active:!1,action:!0,enabled:!N,disabledHint:N,onClick:()=>{y?.(),D()}});i.png!==!1&&(m||n.querySelector("canvas"))&&v.push(j("Save as PNG",g));for(const S of f?.()??[])v.push(j(S.label,S.onClick,S.disabledHint));if(p){const S=d.style.display!=="none";v.push({label:`About this ${p.noun}`,active:S,onClick:()=>{y?.(),u(!S)}})}return v};let y;c.addEventListener("click",()=>{if(c.getAttribute("aria-expanded")==="true"){y?.();return}const v=w();v.length!==0&&(y=ye(c.getBoundingClientRect(),c,v,`${l.textContent||e}: chart actions`,{trigger:c,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(d);const h=n.ownerDocument.createElement("div");h.dataset.wmapPrintOnly="1",Object.assign(h.style,{display:"none",color:b.label,fontSize:L.body,marginBottom:C.sm}),n.appendChild(h),je(n.ownerDocument);const k=n.ownerDocument.createElement("div");k.dataset.wmapControls="1",Object.assign(k.style,{display:"flex",gap:C.sm,marginBottom:C.md,flexWrap:"wrap",alignItems:"center"}),G(k),n.appendChild(k);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:k,body:T,setPngDecor:v=>{Y.set(n,v)},setPngCanvas:v=>{m=v},setAbout:v=>{p=v,u(!!v&&d.style.display!=="none")},setMenuRows:v=>{f=v}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,pe(e,o)," in the user guide"),i}function pe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:b.iconActive,textDecoration:"underline",cursor:"pointer"}),P(t),t.addEventListener("click",()=>ve(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(pe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:b.menuBg,color:b.text,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,padding:`${C.xs} ${C.sm}`,fontSize:L.body,fontFamily:L.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,o,t,i=document,n=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const l=e.length-1,s=`seg-${Math.random().toString(36).slice(2,9)}`,a=[],c=[];return e.forEach(([d,p,u],m)=>{const f=i.createElement("label");u&&z(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:L.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${b.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:m===0?B.control:"0",borderBottomLeftRadius:m===0?B.control:"0",borderTopRightRadius:m===l?B.control:"0",borderBottomRightRadius:m===l?B.control:"0"}),P(f,"bare");const g=i.createElement("input");g.type="radio",g.name=s,g.value=d,g.checked=d===o,c.push(g),Object.assign(g.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const w=()=>{f.style.background=g.checked?b.bgActive:b.menuBg,f.style.color=g.checked?b.iconActive:b.text,f.dataset.on=g.checked?"true":"false"};a.push(w),w(),g.addEventListener("change",()=>{if(g.checked){for(const y of a)y();t(d)}}),f.append(g,i.createTextNode(p)),r.appendChild(f)}),Object.assign(r,{setValue(d){for(const p of c)p.checked=p.value===d;for(const p of a)p()}})}const We=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{...X("outlined"),marginTop:C.sm}),P(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${We}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{...X("outlined"),background:b.menuBg,color:b.label}),P(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:b.label,fontSize:L.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:c}=i,d=()=>typeof e=="function"?e():e;let p=d(),u=o;const m=S=>p.find(D=>D.value===S)?.label??"",f=r.createElement("button");f.type="button",c&&(f.dataset.wmapSelect=c),l&&f.setAttribute("aria-label",l),Object.assign(f.style,{fontSize:L.body,padding:`${C.xxs} ${C.sm}`,background:b.menuBg,color:b.text,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:C.sm,justifyContent:"space-between"}),P(f),V(f,!1);const g=r.createElement("span");Object.assign(g.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const w=r.createElement("span");w.textContent="\u25BE",w.style.flex="0 0 auto",f.append(g,w);const y=()=>{g.textContent=p.length===0?s??"(none)":m(u)||s||"(none)"};if(y(),p.length===0)return f.disabled=!0,f.style.opacity="0.6",f.style.cursor="default",Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}});let h=null;const k=()=>{h&&(h.remove(),h=null,V(f,!1))},T=()=>{k(),f.focus()};function v(){p=d();const S=f.getBoundingClientRect(),D=r.defaultView??window,N=Math.max(S.width,220),ue=Math.min(S.left,Math.max(4,(D.innerWidth??1/0)-N-4));h=r.createElement("div"),h.setAttribute("role","listbox"),h.setAttribute("aria-label",l??"Options"),Object.assign(h.style,{position:"fixed",top:`${S.bottom+4}px`,left:`${ue}px`,background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:B.control,boxShadow:te.menu,zIndex:he,minWidth:`${N}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const M=[],_=()=>M.filter(x=>x.row.style.display!=="none").map(x=>x.row),W=[],fe=()=>{for(const x of W)x.el.style.display=M.slice(x.first,x.last+1).some(E=>E.row.style.display!=="none")?"":"none"};if(p.length>ne){const x=xe(E=>{for(const A of M)A.row.style.display=A.label.includes(E)?"":"none";fe()},a,r,_);Object.assign(x.style,{position:"sticky",top:"0",zIndex:"1",background:b.menuBg}),x.addEventListener("keydown",E=>{if(E.key==="Escape"){E.preventDefault(),T();return}E.key==="ArrowDown"&&(E.preventDefault(),_()[0]?.focus())}),h.appendChild(x)}let Z;for(const x of p){if(x.group!==void 0&&x.group!==Z){const $=r.createElement("div");$.textContent=x.group,$.setAttribute("role","presentation"),Object.assign($.style,{padding:`${C.sm} ${C.xl} ${C.xxs}`,fontSize:L.sub,color:b.label,fontWeight:"600"}),h.appendChild($),W.push({el:$,first:M.length,last:M.length})}Z=x.group;const E=x.value===u,A=r.createElement("div"),J=r.createElement("span");if(J.textContent=x.disabled?`${x.label} \u2014 ${x.disabled}`:x.label,A.appendChild(J),A.setAttribute("role","option"),A.setAttribute("aria-selected",E?"true":"false"),x.disabled&&A.setAttribute("aria-disabled","true"),A.tabIndex=-1,Object.assign(A.style,{padding:`${C.sm} ${C.xl}`,fontSize:L.body,cursor:x.disabled?"default":"pointer",color:x.disabled?b.label:E?b.iconActive:b.text,fontWeight:E?"700":"400",opacity:x.disabled?"0.7":"",background:E?b.menuActive:"transparent",whiteSpace:"nowrap",...x.pin?{display:"flex",alignItems:"center",justifyContent:"space-between",gap:C.xl}:{}}),x.pin){const $=x.pin;A.setAttribute("aria-keyshortcuts","P");const O=r.createElement("span"),Q="http://www.w3.org/2000/svg",I=r.createElementNS(Q,"svg");I.setAttribute("viewBox","0 0 24 24"),I.setAttribute("width","14"),I.setAttribute("height","14"),I.setAttribute("aria-hidden","true");const F=r.createElementNS(Q,"path");F.setAttribute("d","M12 2.5l2.9 6.2 6.8.8-5 4.7 1.3 6.7L12 17.5 6 20.9l1.3-6.7-5-4.7 6.8-.8z"),F.setAttribute("fill",$.pinned?"currentColor":"none"),F.setAttribute("stroke","currentColor"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linejoin","round"),I.appendChild(F),O.appendChild(I),O.dataset.wmapPin=$.pinned?"pinned":"unpinned",O.setAttribute("role","button"),O.setAttribute("aria-label",`${$.pinned?"Unpin":"Pin"} ${x.label} (or press P on the row)`),Object.assign(O.style,{cursor:"pointer",color:$.pinned?b.iconActive:b.label,flex:"0 0 auto",padding:`0 ${C.xs}`,display:"inline-flex",alignItems:"center"}),P(O,"bare"),z(O,$.pinned?"Unpin this test":"Pin this test to the top of every test list");const ee=R=>{R.preventDefault(),R.stopPropagation(),k(),$.toggle(),v()};O.addEventListener("click",ee),A.addEventListener("keydown",R=>{(R.key==="p"||R.key==="P")&&!R.ctrlKey&&!R.metaKey&&!R.altKey&&ee(R)}),A.appendChild(O)}A.addEventListener("mouseenter",()=>{!E&&!x.disabled&&(A.style.background=b.menuHover)}),A.addEventListener("mouseleave",()=>{E||(A.style.background="transparent")}),A.addEventListener("click",$=>{$.stopPropagation(),!x.disabled&&(u=x.value,y(),T(),t(x.value))}),h.appendChild(A),M.push({row:A,label:x.label.toLowerCase()}),W.length&&(W[W.length-1].last=M.length-1)}if(be(h,_,T),ge(f).appendChild(h),V(f,!0),p.length<=ne){const x=p.findIndex(E=>E.value===u);_()[x>=0?x:0]?.focus()}}f.addEventListener("click",S=>{if(S.stopPropagation(),h){k();return}v()});const j=S=>{if(!f.isConnected){r.removeEventListener("click",j);return}h&&!h.contains(S.target)&&!f.contains(S.target)&&k()};return r.addEventListener("click",j),Object.defineProperty(f,"value",{get:()=>u,set:S=>{u=S,y()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?Oe:"")+Te(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i,s=testOptionLabels(e);return makeListSelect(()=>{const c=e.map((u,m)=>({item:u,label:s[m],pinned:$e(u.testNumber)})),d=c.some(u=>u.pinned),p=(u,m)=>({value:String(u.item.testNumber),label:u.label,...m?{group:m}:{},pin:{pinned:u.pinned,toggle:()=>Be(u.item.testNumber)}});return d?[...c.filter(u=>u.pinned).map(u=>p(u,"Pinned")),...c.filter(u=>!u.pinned).map(u=>p(u,"All tests"))]:c.map(u=>p(u))},o!==null?String(o):"",c=>t(Number(c)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,c,d=!1){e.innerHTML="",d&&e.appendChild(makeLimitsSelect(l,p=>{l=p,s()},i)),c&&e.appendChild(makeToggle("Axis includes limits",a,p=>{n=p,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,p=>{r=p,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const c=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&c===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=c,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=d=>d??ALL_GROUPS,s=d=>d===ALL_GROUPS?null:d,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(d=>({value:d,label:d}))],l(r),d=>{const p=s(d);p!==r&&(r=p,i(p))},{...n,hook:"group-scope"}),c=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(d){return r===d||d!==null&&!e.includes(d)?!1:(r=d,c&&(c.value=l(d)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,c)=>({value:String(c),label:a.label??`#${c}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:C.xs,fontSize:L.body,color:b.label,cursor:"pointer",userSelect:"none"}),P(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&z(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document,hint:a}=n,c=s.createElement("label");c.textContent=e,Object.assign(c.style,{color:b.label,fontSize:L.body,display:"flex",alignItems:"center",gap:C.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return c.appendChild(d),a&&z(c,a),c}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(var(--wmap-insights-cols, auto-fit), minmax(var(--wmap-insights-min, 420px), 1fr))",gap:C.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:B.control,padding:`${C.sm} ${C.xl}`,fontSize:L.sub,fontFamily:L.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:te.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let c=t-n.left+r,d=i-n.top+r;c+s+l>n.width&&(c=t-n.left-r-s),d+a+l>n.height&&(d=i-n.top-r-a),c=Math.max(l,c),d=Math.max(l,d),e.style.left=`${c}px`,e.style.top=`${d}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function H(e,o){const[t,i]=o==="test"?[e?.limitLow,e?.limitHigh]:o==="spec"?[e?.specLow,e?.specHigh]:o==="pat"?[e?.patLow,e?.patHigh]:o==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],n=[];return t!==void 0&&Number.isFinite(t)&&n.push({value:t,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),i!==void 0&&Number.isFinite(i)&&n.push({value:i,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),n}export function hasBothLimitKinds(e){return H(e,"test").length>0&&H(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=H(e,"test"),i=H(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...H(e,"pat"),...H(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:Se(o),hi:ke(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{ie as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,c=0;if(r&&l?.length){const p=ie(l);if(p){const u=Math.max(s,p.lo),m=Math.min(a,p.hi);m>u&&(c=l.filter(f=>Number.isFinite(f)&&(f<u||f>m)).length,s=u,a=m)}}if(n)for(const p of i)s=Math.min(s,p.value),a=Math.max(a,p.value);s===a&&(s-=1,a+=1);const d=[];for(const p of i)p.value<s?d.push({value:p.value,label:p.label,side:"lo"}):p.value>a&&d.push({value:p.value,label:p.label,side:"hi"});return{lo:s,hi:a,offAxis:d,clippedCount:c}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function limitLabelPlacement(e,o,t,i,n,r,l=[],s=3){const a=r?-1:1;for(const c of[a,-a])for(const d of o){const p=t(d),u=c<0?e-s-p:e+s,m=c<0?e-s:e+s+p;if(!(u<i||m>n)&&!l.some(f=>f>u&&f<m))return{text:d,side:c}}return{text:o[0],side:limitLabelSide(e,t(o[0]),i,n,r,s)}}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${q(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},c=q(-1)+2;for(const{value:d,label:p,side:u}of o){const m=a[u]++*c,f=i==="horizontal"?u==="lo"?"\u2190":"\u2192":u==="lo"?"\u2193":"\u2191",g=u==="lo"?`${f} ${p} ${r(d)}`:`${p} ${r(d)} ${f}`,w=e.measureText(g).width;if(i==="horizontal"){const y=u==="lo"?t.left+2:t.right-2-w,h={x0:y,x1:y+w,y0:t.top+2+m,y1:t.top+2+m+c},k=s?placeClearOf(s,h,c):h;e.textBaseline="top",e.textAlign=u==="lo"?"left":"right",fillTextOnHalo(e,g,u==="lo"?t.left+2:t.right-2,k.y0,l)}else{const y=u==="lo"?t.bottom-2-m-c:t.top+2+m,h={x0:t.left+4,x1:t.left+4+w,y0:y,y1:y+c},k=s?placeClearOf(s,h,u==="lo"?-c:c):h;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,g,t.left+4,k.y0,l)}}e.restore()}
@@ -1 +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
+ import{rankCommonality as O,measureLabel as B}from"../../stats/commonality.js";import{formatP as b}from"../../stats/groupCompare.js";import{CLR as u,FONT as j,SPACE as p,controlStyle as T,wireControlHover as F,wireTooltip as C}from"../toolbar.js";import{shortfallShade as G}from"../cellShade.js";import{cardShell as R,firstRowsToggle as q,guideCite as I,renderEmptyState as D}from"./chartShell.js";import{GUIDE_SECTIONS as L}from"../../stats/guideSections.js";import{cardAbout as P}from"./cardAbout.js";const S=8;export function renderCommonalityPanel(l){const r=l.ownerDocument??document,{card:d,body:g,setAbout:v}=R("What divides yield",void 0,r);v(P("commonality")),d.dataset.wmapCommonality="1",d.style.gridColumn="1 / -1",d.style.flex="0 0 auto";const s=O(l.wafers,l.fields,l.curation);if(l.fields.length===0||s.rows.length===0)return D(g,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"),w=[`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&&w.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&&w.push(`Not compared, with no two groups of two or more wafers: ${s.untestable.map(n=>n.label).join(", ")}.`),f.textContent=w.join(" ")+" ",f.append(I(r,L.dividesYield),"."),Object.assign(f.style,{color:u.label,fontSize:j.body,marginBottom:p.sm}),g.appendChild(f);const c=r.createElement("table");Object.assign(c.style,{borderCollapse:"collapse",width:"100%",fontSize:j.body,fontVariantNumeric:"tabular-nums"});const $=r.createElement("tr"),i=(n,e,o="right")=>{const t=r.createElement("th");t.scope="col",t.textContent=n,e&&C(t,e),Object.assign(t.style,{textAlign:o,padding:`${p.xs} ${p.sm}`,borderBottom:`1px solid ${u.menuBorder}`,color:u.label,fontWeight:"600",whiteSpace:"nowrap"}),$.appendChild(t)};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 k=r.createElement("thead");k.appendChild($),c.appendChild(k);const y=r.createElement("tbody");c.appendChild(y);const a=(n,e,o={})=>{const t=r.createElement("td");typeof e=="string"?t.textContent=e:t.appendChild(e),o.title&&C(t,o.title),o.shade&&(t.style.background=o.shade),Object.assign(t.style,{padding:`${p.xs} ${p.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${u.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400"}),n.appendChild(t)},x=n=>`${n.toFixed(1)}%`,E=(n,e)=>e.comparison.groups.find(o=>o.key===n)?.n??0,N=n=>{if(n.measure.kind!=="yield")return;const e=n.comparison.groups.filter(t=>Number.isFinite(t.mean)&&t.n>0),o=e.reduce((t,h)=>t+h.n,0);return o>0?G(n.worst.mean-e.reduce((t,h)=>t+h.mean*h.n,0)/o):void 0};function W(n){y.replaceChildren();for(const e of n?s.rows:s.rows.slice(0,S)){const o=r.createElement("tr");if(a(o,e.field.label,{align:"left"}),a(o,B(e.measure),{align:"left"}),a(o,`${e.worst.key}: ${x(e.worst.mean)} (${E(e.worst.key,e)} wafers)`,{align:"left",shade:N(e)}),a(o,`${e.best.key}: ${x(e.best.mean)} (${E(e.best.key,e)} wafers)`,{align:"left"}),a(o,`${e.spread.toFixed(1)} pts`),a(o,b(e.comparison.welch?.p??NaN),{title:e.comparison.issue}),a(o,`${b(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(o,b(e.pAdjusted),{strong:e.pAdjusted<.05}),e.field.key===l.groupedBy)a(o,"Grouped by this",{align:"left"});else{const t=r.createElement("button");t.type="button",t.textContent="Group by",t.dataset.wmapCommonalityGroup=e.field.key,C(t,`Group Insights by ${e.field.label}, so every chart compares its groups`),Object.assign(t.style,T("outlined")),F(t),t.addEventListener("click",()=>l.onGroupBy(e.field.key)),a(o,t,{align:"left"})}y.appendChild(o)}}const m=r.createElement("div");Object.assign(m.style,{overflowX:"auto"}),m.appendChild(c);const A=q(r,{total:s.rows.length,first:S,noun:"rows",scroller:m,fill:W});return g.append(m,A),{card:d,destroy:()=>{}}}
@@ -23,6 +23,17 @@ export interface CorrelationPanelOptions {
23
23
  */
24
24
  /** Clicking a non-diagonal cell calls this — the Analysis tab wires it to drive the scatter panel's X/Y in place. */
25
25
  onSelectPair?: (xTestNumber: number, yTestNumber: number) => void;
26
+ /**
27
+ * With Group by on (two groups or more), the groups' wafers: the matrix then offers **Within groups**, the correlation
28
+ * left once each group's mean is taken off every test. Not a restriction to one group (see above): the choice is how
29
+ * the same wafers are correlated.
30
+ */
31
+ groups?: ReadonlyArray<{
32
+ key: string;
33
+ items: CorrelationItem[];
34
+ }>;
35
+ /** The field the groups are values of, for the choice's label. */
36
+ groupLabelText?: string;
26
37
  /** Document to build this panel's DOM into. Default `document` — pass the
27
38
  * host's own `ownerDocument` when the container might live in a
28
39
  * different document (e.g. a gallery card detached into its own popup
@@ -1 +1 @@
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()}}
1
+ import{buildCoFailureMatrix as De}from"../../stats/coFailure.js";import{buildCorrelationMatrix as Re,demeanWithinGroups as ke,filterCorrelationMatrix as Ae,correlationSampleNote as _e}from"../../stats/correlation.js";import{maxOf as We}from"../../core/utils.js";import{CORRELATION_POSITIVE as Q,CORRELATION_NEGATIVE as re}from"./palette.js";import{buildFacetTable as Be}from"../../stats/facets.js";import{wireControlHover as Oe,wireTooltip as me,controlStyle as Ne,SPACE as I,RADIUS as ie,fontPx as pe,FONT as z,CLR as x}from"../toolbar.js";import{exportCsv as He}from"../tableExport.js";import{attachChartTip as Xe,cardShell as je,makeSegmented as ge,setChartGrow as Fe,isExpandedCard as Ve,bodyRoom as ze,observeResize as Ye,makeTooltip as Ge,positionChartTooltip as Pe,makeWaferSelect as Ke,renderEmptyState as Ue,resolveChartCanvasColors as qe,prepareCanvas as Je,chartDpr as be}from"./chartShell.js";import{escHtml as Z}from"../../core/utils.js";import{unmarkedLabel as xe,derivedCsvCell as ye,DERIVED_CSV_HEADER as we,DERIVED_MARK as Qe,DERIVED_KEY as Ze}from"../../renderer/testLabel.js";import{cardAbout as et}from"./cardAbout.js";const ae=5,ce=100,Ce=20;function ee(d){const h=d.match(/rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)/);if(h)return[+h[1],+h[2],+h[3]];const g=d.trim().replace("#","");return g.length===6?[parseInt(g.slice(0,2),16),parseInt(g.slice(2,4),16),parseInt(g.slice(4,6),16)]:null}function tt(d){const h=ee(d);return h?(h[0]*299+h[1]*587+h[2]*114)/1e3>140?"#111":"#fff":"#000"}function $e(d,h,g){const v=ee(d);if(!v)return d;const te=Math.round(h[0]+(v[0]-h[0])*g),X=Math.round(h[1]+(v[1]-h[1])*g),l=Math.round(h[2]+(v[2]-h[2])*g);return`rgb(${te},${X},${l})`}export function renderCorrelationPanel(d){const{title:h="Test correlation matrix",items:g,testDefs:v,onSaveImage:te,onSelectPair:X}=d,{card:l,body:D,controlsRow:Y,setPngDecor:Me,setAbout:Le}=je(h,te,d.ownerDocument);Le(et("correlation")),Me(()=>{const e=ee(l.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor??"")??[255,255,255];return{colorbar:{label:"Pearson r",lo:"\u22121",hi:"+1",color:n=>$e(n<.5?re:Q,e,Math.abs(2*n-1))}}}),Fe(l,"square"),D.style.overflowX="auto",l.style.alignSelf="start";let K=Ce,j=null;const F=l.ownerDocument.createElement("label");F.textContent="Max tests:",me(F,`The most tests the matrix shows, from ${ae} to ${ce}`),Object.assign(F.style,{color:x.label,fontSize:z.body,display:"flex",alignItems:"center",gap:I.xs});const E=l.ownerDocument.createElement("input");E.type="number",E.min=String(ae),E.max=String(ce),E.value=String(K),Object.assign(E.style,{width:"52px",fontSize:z.body,padding:`${I.xxs} ${I.xs}`,background:x.menuBg,color:x.value,border:`1px solid ${x.menuBorder}`,borderRadius:ie.control}),E.addEventListener("change",()=>{const e=Math.max(ae,Math.min(ce,parseInt(E.value,10)||Ce));E.value=String(e),e!==K&&(K=e,G())}),F.appendChild(E),Y.appendChild(F),g.length>1&&Y.appendChild(Ke(g,j,e=>{j=e,G()},{ownerDocument:l.ownerDocument}));let de=!1,y=!1;if(v.filter(e=>e.limitLow!==void 0||e.limitHigh!==void 0).length>=2){const e=ge([["values","Values","How the tests\u2019 values move together (Pearson r)"],["fails","Fails together","Which tests fail on the same dies: the share of the dies failing either of two tests that fail both"]],"values",n=>{y=n==="fails",G()},l.ownerDocument);e.dataset.wmapCorrelationKind="1",Y.appendChild(e)}if(d.groups&&d.groups.length>=2){const e=ge([["pooled","Pooled"],["within",`Within ${d.groupLabelText??"groups"}`,"The correlation left once each group\u2019s mean is taken off every test, so a difference between groups is not read as a relationship between tests"]],"pooled",n=>{de=n==="within",G()},l.ownerDocument);e.dataset.wmapCorrelationMode="1",Y.appendChild(e)}function ve(){return j!==null?g[j]?[g[j]]:[]:g}if(d.onSaveText){const e=l.ownerDocument.createElement("button");e.type="button",e.textContent="Correlation CSV",me(e,"Save the correlation coefficients as a CSV file, one row per pair of tests"),Object.assign(e.style,{...Ne("outlined"),color:x.text}),Oe(e),e.addEventListener("click",()=>{const n=fe;if(!n)return;const u=n.tests.some(o=>o.derived),a=[];for(let o=0;o<n.tests.length;o++)for(let c=o+1;c<n.tests.length;c++){const w=n.cells.find(b=>b.xIndex===c&&b.yIndex===o);w&&a.push({x:n.tests[c],y:n.tests[o],r:w.r,n:w.n})}He([{header:"Test X",get:o=>xe(o.x.label)},{header:"Test X number",get:o=>o.x.testNumber},{header:"Test Y",get:o=>xe(o.y.label)},{header:"Test Y number",get:o=>o.y.testNumber},{header:y?"Share failing both":"r",get:o=>o.r===null?"":o.r.toFixed(6)},{header:y?"Dies failing either":"n",get:o=>o.n},...u?[{header:`Test X ${we.toLowerCase()}`,get:o=>ye(o.x)},{header:`Test Y ${we.toLowerCase()}`,get:o=>ye(o.y)}]:[]],a,"test-correlation.csv",d.onSaveText)}),Y.appendChild(e)}const N=l.ownerDocument.createElement("div");Object.assign(N.style,{display:"flex",flexDirection:"column",gap:I.xs,marginBottom:I.sm}),l.insertBefore(N,D);const R=Ge(l);Xe(F,l,R,"Cap on how many tests the matrix includes (strongest correlations kept first)");let ne=()=>{};function Ee(e,n,u,a,o,c,w,b){N.innerHTML="";const k=_e(w);if(k){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=w.sample?`${k} \u2014 r is an estimate, not the whole population.`:`${k}.`,Object.assign(m.style,{color:x.label,fontSize:z.body}),N.appendChild(m)}if(o.length>0){const m=l.ownerDocument.createElement("div");m.dataset.wmapCaption="1",m.textContent=`\u26A0 Mixed ${o.join(", ")} within this set \u2014 correlations may be misleading (Simpson's paradox). ${d.groups&&d.groups.length>=2?`Choose Within ${d.groupLabelText??"groups"} to take the groups\u2019 differences out, or use the Wafer picker`:"Use the Wafer picker to narrow to a like-for-like set, or Group by one of these fields where it is in the list"}.`,Object.assign(m.style,{color:x.warnText,background:x.warnBg,border:`1px solid ${x.warnBorder}`,borderRadius:ie.control,padding:`${I.xs} ${I.md}`,fontSize:z.body}),N.appendChild(m)}const A=l.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-flex",alignItems:"center",gap:I.sm,color:x.label,fontSize:z.body,flexWrap:"wrap"});const S=l.ownerDocument.createElement("span");S.dataset.wmapCaption="1",S.textContent=y?`Share of the dies failing either that fail both${c!==null?` \xB7 ${c.toLocaleString()} failing dies per pair (median)`:""} \xB7 click a cell to view that pair in scatter \xB7`:(c!==null?`Pearson r \xB7 n \u2248 ${c.toLocaleString()} dies per pair \xB7 click a cell to view that pair in scatter \xB7`:"Pearson r \xB7 click a cell to view that pair in scatter \xB7")+(b?` ${Qe} ${Ze} \xB7`:""),A.appendChild(S);const T=l.ownerDocument.createElement("span");Object.assign(T.style,{display:"inline-flex",alignItems:"center",gap:I.xs});const i=l.ownerDocument.createElement("span");i.textContent=y?"0":"\u22121";const _=l.ownerDocument.createElement("span");Object.assign(_.style,{display:"inline-block",width:"64px",height:"8px",borderRadius:ie.control,border:`1px solid ${x.menuBorder}`,background:y?`linear-gradient(to right, ${x.menuBg}, ${Q})`:`linear-gradient(to right, ${re}, ${x.menuBg}, ${Q})`});const P=l.ownerDocument.createElement("span");P.textContent=y?"1":"+1",T.append(i,_,P),A.appendChild(T),N.appendChild(A);const $=l.ownerDocument.createElement("span");if($.dataset.wmapCaption="1",Object.assign($.style,{color:x.value,fontSize:z.body,fontWeight:"500"}),y)$.textContent=a&&a.r>0?`Most shared failures: ${a.xLabel} \u2194 ${a.yLabel} (${Math.round(100*a.r)}% of the dies failing either fail both)`:"No two tests fail on the same dies";else if(e===0&&n===0)$.textContent=a?`No significant correlations found \u2014 strongest pair: ${a.xLabel} \u2194 ${a.yLabel} (r = ${a.r.toFixed(2)})`:"No significant correlations found";else{const m=[];e>0&&m.push(`${e} strong (|r| \u2265 0.7)`),n>0&&m.push(`${n} moderate (0.4\u20130.7)`);const U=e+n;let r=m.join(", ")+` pair${U!==1?"s":""} found`;u>0&&(r+=` \xB7 ${u} weak pair${u!==1?"s":""} not shown`),$.textContent=r}N.appendChild($)}function Se(e){if(D.innerHTML="",e.tests.length<2)return Ue(D,"Need at least two parametric tests for a correlation matrix."),()=>{};const n=l.ownerDocument.createElement("canvas");n.style.display="block",n.style.cursor="default",D.appendChild(n);const u=e.tests.length,a=r=>r.label.split(" (#")[0],o=Math.min(14,We(e.tests.map(r=>a(r).length))),c=o*6.5+8,w=10,b=Math.round(w*6.5*Math.sin(Math.PI/4))+14,k=14,A=28,S=44;let T=-1,i=-1;const _=96;function P(r){const f=Math.max(0,r-c),p=Math.floor(f/u);if(!Ve(l))return Math.max(k,Math.min(S,p));const s=Math.floor((ze(l,D,n)-b-4)/u);return Math.max(k,Math.min(_,p,s))}const $=new Map;for(const r of e.cells){let f=$.get(r.yIndex);f||(f=[],$.set(r.yIndex,f)),f.push(r)}function m(){const r=qe(l),f=ee(r.bg)??[255,255,255],p=D.clientWidth,s=P(p),V=s*u,M=b+s*u+4,W=c+V,B=Je(n,l,W,M);if(!B)return;const{ctx:t}=B;t.font=`${pe(-1)}px system-ui, sans-serif`,t.fillStyle=r.text,e.tests.forEach((O,C)=>{const L=a(O),H=L.length>w?`${L.slice(0,w-1)}\u2026`:L,oe=c+C*s+s/2;t.save(),t.translate(oe,b-4),t.rotate(-Math.PI/4),t.textAlign="left",t.textBaseline="bottom",t.fillStyle=C===T?r.text:r.textMuted,t.fillText(H,0,0),t.restore()}),e.tests.forEach((O,C)=>{const L=a(O),H=b+C*s,oe=H+s/2;t.font=`${pe(-1)}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=C===i?r.text:r.textMuted,t.fillText(L.length>o?`${L.slice(0,o-1)}\u2026`:L,c-4,oe),($.get(C)??[]).forEach(he=>{const se=he.xIndex,q=c+se*s,Ie=se===T&&C===i,ue=se===C,J=he.r;if(J===null){t.fillStyle=r.border,t.globalAlpha=.4,t.fillRect(q+1,H+1,s-2,s-2),t.globalAlpha=1;return}let le=r.bgHover;ue?t.fillStyle=r.bgHover:(le=$e(J>=0?Q:re,f,Math.abs(J)),t.fillStyle=le),t.fillRect(q+1,H+1,s-2,s-2),s>=A&&!ue&&(t.font=`${Math.min(10,s*.35)}px system-ui, sans-serif`,t.fillStyle=tt(le),t.textAlign="center",t.textBaseline="middle",t.fillText(J.toFixed(2),q+s/2,H+s/2)),Ie&&(t.strokeStyle=r.text,t.lineWidth=2,t.strokeRect(q+1,H+1,s-2,s-2),t.lineWidth=1)})}),t.strokeStyle=r.bg,t.lineWidth=1;for(let O=0;O<=u;O++){const C=c+O*s;t.beginPath(),t.moveTo(C,b),t.lineTo(C,b+u*s),t.stroke();const L=b+O*s;t.beginPath(),t.moveTo(c,L),t.lineTo(c+u*s,L),t.stroke()}}function U(r){const f=n.getBoundingClientRect(),p=D.clientWidth,s=P(p),V=(r.clientX-f.left)*(n.width/be(n)/f.width),M=(r.clientY-f.top)*(n.height/be(n)/f.height),W=Math.floor((V-c)/s),B=Math.floor((M-b)/s);return W>=0&&W<u&&B>=0&&B<u?{xi:W,yi:B}:null}return n.addEventListener("mousemove",r=>{const f=U(r);if(!f){R.style.display="none",n.style.cursor="default";return}const{xi:p,yi:s}=f,V=p===s;n.style.cursor=V||!X?"default":"pointer";const M=e.cells.find(t=>t.xIndex===p&&t.yIndex===s),W=e.tests[p].label,B=e.tests[s].label;V?R.innerHTML=`<strong>${Z(W)}</strong>`:M?.r!==null&&M?.r!==void 0?R.innerHTML=`<strong>${Z(a(e.tests[s]))}</strong> (#${e.tests[s].testNumber}) vs <strong>${Z(a(e.tests[p]))}</strong> (#${e.tests[p].testNumber})<br>${y?`${(100*M.r).toFixed(0)}% of the dies failing either fail both \xB7 ${M.n.toLocaleString()} fail either`:`r = ${M.r.toFixed(4)} \xB7 n = ${M.n.toLocaleString()}`}${X?"<br><em>click to view in scatter</em>":""}`:R.innerHTML=`${Z(`${B} vs ${W}`)}<br><em>insufficient data</em>`,R.style.display="block",Pe(R,l,r.clientX,r.clientY)}),n.addEventListener("mouseleave",()=>{R.style.display="none"}),n.addEventListener("click",r=>{const f=U(r);if(!f||!X)return;const{xi:p,yi:s}=f;p!==s&&(T=p,i=s,m(),X(e.tests[p].testNumber,e.tests[s].testNumber))}),m}let fe=null;function G(){const e=ve(),n=!y&&de&&j===null&&!!d.groups,u=n?ke(d.groups.map(i=>i.items.flatMap(_=>_.dies??[])),v):e.flatMap(i=>i.dies??[]),a=y?De(u,v):Re(u,v),{matrix:o,strongPairs:c,moderatePairs:w,hiddenWeakPairs:b,strongestPair:k}=Ae(a,{minTests:6,maxTests:K}),A=n||y?[]:Be(e,{facetableOnly:!0}).filter(i=>i.splittable).map(i=>i.label),S=o.cells.filter(i=>i.xIndex!==i.yIndex).map(i=>i.n).sort((i,_)=>i-_),T=S.length?S[Math.floor(S.length/2)]:null;fe=o,Ee(c,w,b,k,A,T,a,o.tests.some(i=>i.derived)),ne=Se(o),ne()}const Te=Ye(l,()=>ne());return G(),{card:l,destroy:()=>Te.disconnect()}}
@@ -0,0 +1,23 @@
1
+ type Rgb = [number, number, number];
2
+ /** The colour at `t` in [0, 1] on the signed scale (blue below, warm above), where 0.5 is zero. */
3
+ export declare const divergingRgb: (t: number) => Rgb;
4
+ export declare const divergingColor: (t: number) => string;
5
+ /** The colour at `t` on the rating scale (vermillion for bad to blue for good). */
6
+ export declare const ratingRgb: (t: number) => Rgb;
7
+ /** The gradients only a plot offers, beside the map's own (`listValueColorSchemes`). */
8
+ export declare const PLOT_GRADIENTS: ReadonlyArray<{
9
+ name: string;
10
+ label: string;
11
+ }>;
12
+ /**
13
+ * The colour of a value at `t` in [0, 1] of a plot's key. `scheme` is a name from `PLOT_GRADIENTS` or a map gradient;
14
+ * unset, a value rescaled around zero (`diverging`) takes the signed scale, a rating (a yield, a pass rate) the rating
15
+ * scale, and any other the map's default. `reversed` flips the key.
16
+ */
17
+ export declare function plotGradient(scheme: string | undefined, reversed: boolean | undefined, diverging: boolean | undefined, rating?: boolean): (t: number) => string;
18
+ /** Whether dark text reads better than white on `rgb` (WCAG relative luminance: the crossover of the two contrasts). */
19
+ export declare const darkTextOn: (rgb: Rgb) => boolean;
20
+ /** Whether dark text reads better on a CSS colour (`rgb(...)` or `#rgb`/`#rrggbb`); white when the colour cannot be read. */
21
+ export declare function darkTextOnColor(color: string): boolean;
22
+ export {};
23
+ //# sourceMappingURL=divergingScale.d.ts.map
@@ -0,0 +1 @@
1
+ import{registerValueColorScheme as f,resolveValueColorFn as b}from"../../renderer/colorSchemes.js";import{SIGNED_HIGH as x,SIGNED_LOW as p}from"./palette.js";const c=n=>[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)],s=[247,247,247],l=(n,e,r)=>[n[0]+(e[0]-n[0])*r,n[1]+(e[1]-n[1])*r,n[2]+(e[2]-n[2])*r],g=c(p),u=c(x),I=[g,l(g,s,.5),s,l(u,s,.5),u],h=[[213,94,0],[230,159,0],[240,228,66],[86,180,233],[0,114,178]];function d(n,e){const r=Math.min(1,Math.max(0,Number.isFinite(e)?e:.5))*(n.length-1),t=Math.min(n.length-2,Math.floor(r)),i=r-t,o=n[t],a=n[t+1];return[o[0]+(a[0]-o[0])*i,o[1]+(a[1]-o[1])*i,o[2]+(a[2]-o[2])*i]}const m=([n,e,r])=>`rgb(${Math.round(n)}, ${Math.round(e)}, ${Math.round(r)})`;export const divergingRgb=n=>d(I,n),divergingColor=n=>m(divergingRgb(n)),ratingRgb=n=>d(h,n),PLOT_GRADIENTS=[{name:"diverging",label:"Blue to orange, around zero"},{name:"rating",label:"Rating: orange-red to blue (colour-blind safe)"}];f("diverging",{label:PLOT_GRADIENTS[0].label,forValue:divergingColor});export function plotGradient(n,e,r,t){const i=n??(r?"diverging":t?"rating":void 0),o=i==="diverging"?divergingColor:i==="rating"?a=>m(ratingRgb(a)):b(i);return e?a=>o(1-a):o}function N([n,e,r]){const t=i=>{const o=i/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4};return .2126*t(n)+.7152*t(e)+.0722*t(r)}export const darkTextOn=n=>N(n)>.179;export function darkTextOnColor(n){const e=/^rgba?\(\s*(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)/i.exec(n);if(e)return darkTextOn([Number(e[1]),Number(e[2]),Number(e[3])]);const r=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());if(!r)return!1;const t=r[1].length===3?[...r[1]].map(i=>i+i).join(""):r[1];return darkTextOn([parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)])}
@@ -1 +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
+ import{compareTestsByGroup as J,formatP as N,groupKeys as Q}from"../../stats/groupCompare.js";import{fmt as S}from"../../renderer/fmt.js";import{testLabel as G,unmarkedLabel as Y}from"../../renderer/testLabel.js";import{CLR as l,FONT as q,SPACE as C,controlStyle as R,wireControlHover as V,wireTooltip as k}from"../toolbar.js";import{exportCsv as Z}from"../tableExport.js";import{cardShell as ee,guideCite as te,makeListSelect as oe,renderEmptyState as K}from"./chartShell.js";import{GUIDE_SECTIONS as ne}from"../../stats/guideSections.js";import{cardAbout as se}from"./cardAbout.js";import{shadesAmong as re}from"../cellShade.js";const L="\0none",ae=6;export function renderGroupComparisonPanel(s){const r=s.ownerDocument??document,O=s.groupLabelText??"group",{card:b,body:$,controlsRow:B,setAbout:P}=ee(s.title??`Comparison by ${O.toLowerCase()}`,void 0,r);P(se("comparison")),b.dataset.wmapGroupComparison="1",b.style.gridColumn="1 / -1";const A=s.groups.flatMap(t=>t.items.map(e=>({dies:e.dies,group:t.key}))),p=Q(A),a=s.control!==null&&p.includes(s.control)?s.control:null,f=J(A,s.testDefs,a??void 0),E=p.length<=ae?p:[],U=oe([{value:L,label:"No control: compare all groups"},...p.map(t=>({value:t,label:`Control: ${t}`}))],a??L,t=>s.onControlChange(t===L?null:t),{ownerDocument:r,ariaLabel:"Control group",hook:"compare-control"});if(B.appendChild(U),s.onSaveText&&f.length){const t=r.createElement("button");t.type="button",t.textContent="Comparison CSV",k(t,"Save this table as a CSV file, one row per test"),Object.assign(t.style,{...R("outlined"),color:l.text}),V(t),t.addEventListener("click",()=>Z([{header:"Test",get:e=>Y(G(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??""}],f,"group-comparison.csv",s.onSaveText)),B.appendChild(t)}if(p.length<2)return K($,`Needs two or more ${O.toLowerCase()} groups to compare.`),{card:b,setTest:()=>{},destroy:()=>{}};if(f.length===0)return K($,"No measured test has values in these wafers."),{card:b,setTest:()=>{},destroy:()=>{}};const y=r.createElement("div"),z=p.map(t=>`${t} ${A.filter(e=>e.group===t).length}`).join(", ");y.textContent=`Each wafer is one value, the mean of its dies, so n is wafers (${z}). Welch: Welch's ANOVA (Welch's t for two groups). Rank: Kruskal\u2013Wallis${f.some(t=>t.comparison.kruskal?.approximate)?", approximate with fewer than five wafers in a group":""}. q: Benjamini\u2013Hochberg across the ${f.length} tests, which the table is ranked by.`+(a?` Each group's difference from ${a} has a Holm-adjusted p.`:"")+" ",y.append(te(r,ne.groups),"."),Object.assign(y.style,{color:l.label,fontSize:q.body,marginBottom:C.sm}),$.appendChild(y);const j=r.createElement("div");Object.assign(j.style,{overflow:"auto",maxHeight:"420px",border:`1px solid ${l.menuBorder}`});const x=r.createElement("table");Object.assign(x.style,{borderCollapse:"collapse",width:"100%",fontSize:q.body,fontVariantNumeric:"tabular-nums"});const W=r.createElement("thead"),D=r.createElement("tr"),h=(t,e,o="right")=>{const n=r.createElement("th");n.scope="col",n.textContent=t,e&&k(n,e),Object.assign(n.style,{position:"sticky",top:"0",background:l.menuBg,textAlign:o,padding:`${C.xs} ${C.sm}`,borderBottom:`1px solid ${l.menuBorder}`,color:l.label,fontWeight:"600",whiteSpace:"nowrap"}),D.appendChild(n)};h("Test",void 0,"left");for(const t of E)h(t===a?`${t} (control)`:t,a&&t!==a?`Mean of the wafer means, and the difference from ${a}`:"Mean of the wafer means");h("Welch p","Do the group means differ? Welch\u2019s ANOVA on wafer means, not assuming equal spreads"),h("Rank p","The same question on ranks (Kruskal\u2013Wallis): one odd wafer cannot drive it"),h("q","Welch p adjusted for the number of tests compared (Benjamini\u2013Hochberg); the table is ranked by it"),h("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"),W.appendChild(D),x.appendChild(W);const M=r.createElement("tbody"),H=new Map,g=(t,e,o={})=>{const n=r.createElement("td");typeof e=="string"?n.textContent=e:n.appendChild(e),o.title&&k(n,o.title),Object.assign(n.style,{padding:`${C.xs} ${C.sm}`,textAlign:o.align??"right",borderBottom:`1px solid ${l.menuBorder}`,whiteSpace:"nowrap",fontWeight:o.strong?"700":"400",color:o.muted?l.label:l.text}),o.shade&&(n.style.background=o.shade),t.appendChild(n)};for(const t of f){const e=r.createElement("tr"),o=t.comparison,n=t.test.unit,d=r.createElement("button");d.type="button",d.textContent=G(t.test,t.test.testNumber),d.dataset.wmapCompareTest=String(t.test.testNumber),k(d,`Show ${d.textContent} in the panels below${o.issue?`. ${o.issue}`:""}`),Object.assign(d.style,{...R("bare"),padding:"0",textAlign:"left",color:l.text,textDecoration:"underline",textDecorationColor:l.menuBorder}),V(d,"bare"),d.addEventListener("click",()=>{s.onSelectTest(t.test.testNumber),v(t.test.testNumber)}),g(e,d,{align:"left"});const _=re(E.map(w=>{const m=o.groups.find(i=>i.key===w);return m&&m.n?m.mean:NaN}),w=>S(w,n));for(const[w,m]of E.entries()){const i=o.groups.find(T=>T.key===m),u=o.contrasts?.find(T=>T.key===m),F=i&&i.n?S(i.mean,n):"\u2014",X=u&&Number.isFinite(u.delta)?`${F} (${u.delta>=0?"+":""}${S(u.delta,n)}, p ${N(u.pAdjusted)})`:F;g(e,X,{shade:_[w],title:i?`${m}: ${i.n} wafer${i.n===1?"":"s"}${i.n>=2?`, wafer-to-wafer SD ${S(i.sd,n)}`:""}`:void 0,muted:!i||i.n<2,strong:!!u&&u.pAdjusted<.05})}g(e,N(o.welch?.p??NaN),{title:o.issue}),g(e,N(o.kruskal?.p??NaN)),g(e,N(t.pAdjusted),{strong:t.pAdjusted<.05});const I=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";g(e,I),H.set(t.test.testNumber,e),M.appendChild(e)}x.appendChild(M),j.appendChild(x),$.appendChild(j);function v(t){for(const[e,o]of H)o.style.background=e===t?l.bgActive:"",e===t?o.setAttribute("aria-current","true"):o.removeAttribute("aria-current")}return v(s.selectedTestNumber),{card:b,setTest:v,destroy:()=>{}}}const c=s=>s===void 0||!Number.isFinite(s)?"":String(s);
@@ -22,7 +22,14 @@ export declare function yieldFill(yieldPercent: number): string;
22
22
  * same information positionally.
23
23
  */
24
24
  export declare function capabilityColor(ppk: number | null): string;
25
- /** Correlation sign hues (blue = positive, vermillion = negative); |r| sets intensity via background blend. */
26
- export declare const CORRELATION_POSITIVE = "#0072B2";
27
- export declare const CORRELATION_NEGATIVE = "#D55E00";
25
+ /**
26
+ * The two ends of every signed scale (a correlation, a z-score, a difference): warm is positive or above average, blue is
27
+ * negative or below, so one colour never means "high" on one chart and "low" on the next. Okabe-Ito blue and vermillion,
28
+ * which stay far apart under every common colour-vision deficiency.
29
+ */
30
+ export declare const SIGNED_LOW = "#0072B2";
31
+ export declare const SIGNED_HIGH = "#D55E00";
32
+ /** Correlation sign hues (vermillion = positive, blue = negative); |r| sets intensity via background blend. */
33
+ export declare const CORRELATION_POSITIVE = "#D55E00";
34
+ export declare const CORRELATION_NEGATIVE = "#0072B2";
28
35
  //# sourceMappingURL=palette.d.ts.map
@@ -1 +1 @@
1
- import{clamp01 as i}from"../../core/utils.js";export const QUANTITY="#4e79a7";const E=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#8C6D31","#999999"],p=["#1f1ff9","#f91ff9","#05d105","#65188b","#f91f68","#607afb","#8b1818","#1f4951"],n=[...E,...p];export function categorical(t){return n[(t%n.length+n.length)%n.length]}export const CATEGORICAL_COUNT=n.length;function I(t,e,c){const s=[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)],l=[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)],r=s.map((o,f)=>Math.round(o+(l[f]-o)*c));return`rgb(${r[0]},${r[1]},${r[2]})`}export function yieldFill(t){const e=i((t-50)/50);return I("#e7eef6","#2f6395",e)}export function capabilityColor(t){return t===null?"#999999":t>=1.33?"#009E73":t>=1?"#E69F00":"#D55E00"}export const CORRELATION_POSITIVE="#0072B2",CORRELATION_NEGATIVE="#D55E00";
1
+ import{clamp01 as f}from"../../core/utils.js";export const QUANTITY="#4e79a7";const p=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#8C6D31","#999999"],I=["#1f1ff9","#f91ff9","#05d105","#65188b","#f91f68","#607afb","#8b1818","#1f4951"],n=[...p,...I];export function categorical(t){return n[(t%n.length+n.length)%n.length]}export const CATEGORICAL_COUNT=n.length;function i(t,e,c){const s=[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)],l=[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)],o=s.map((r,E)=>Math.round(r+(l[E]-r)*c));return`rgb(${o[0]},${o[1]},${o[2]})`}export function yieldFill(t){const e=f((t-50)/50);return i("#e7eef6","#2f6395",e)}export function capabilityColor(t){return t===null?"#999999":t>=1.33?"#009E73":t>=1?"#E69F00":"#D55E00"}export const SIGNED_LOW="#0072B2",SIGNED_HIGH="#D55E00",CORRELATION_POSITIVE=SIGNED_HIGH,CORRELATION_NEGATIVE=SIGNED_LOW;