@wafertools/wafermap 0.37.1 → 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 (86) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +21 -13
  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/chartPopulation.d.ts +8 -3
  6. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +45 -19
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/correlation.d.ts +11 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +23 -0
  13. package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/palette.d.ts +10 -3
  16. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  17. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +3 -7
  18. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  19. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  20. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +1 -0
  21. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
  22. package/dist/packages/canvas-adapter/drilldown.d.ts +5 -0
  23. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  24. package/dist/packages/canvas-adapter/filterJson.d.ts +25 -0
  25. package/dist/packages/canvas-adapter/filterJson.js +5 -0
  26. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  27. package/dist/packages/canvas-adapter/index.js +1 -1
  28. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  29. package/dist/packages/canvas-adapter/pageFilter.js +2 -2
  30. package/dist/packages/canvas-adapter/pinnedTests.d.ts +10 -0
  31. package/dist/packages/canvas-adapter/pinnedTests.js +1 -0
  32. package/dist/packages/canvas-adapter/plotCard.d.ts +1 -1
  33. package/dist/packages/canvas-adapter/plotCard.js +1 -1
  34. package/dist/packages/canvas-adapter/plotEditor.js +10 -1
  35. package/dist/packages/canvas-adapter/plotJsonComplete.d.ts +46 -0
  36. package/dist/packages/canvas-adapter/plotJsonComplete.js +4 -0
  37. package/dist/packages/canvas-adapter/plotJsonHistory.d.ts +12 -0
  38. package/dist/packages/canvas-adapter/plotJsonHistory.js +1 -0
  39. package/dist/packages/canvas-adapter/plotJsonSuggest.d.ts +16 -0
  40. package/dist/packages/canvas-adapter/plotJsonSuggest.js +1 -0
  41. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  42. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  43. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  44. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  45. package/dist/packages/canvas-adapter/summaryPanel.d.ts +3 -3
  46. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  47. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  48. package/dist/packages/canvas-adapter/userGuideHtml.js +68 -33
  49. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  50. package/dist/packages/canvas-adapter/version.js +1 -1
  51. package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
  52. package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -0
  53. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  54. package/dist/packages/core/utils.d.ts +6 -0
  55. package/dist/packages/core/utils.js +1 -1
  56. package/dist/packages/renderer/buildWaferMap.js +1 -1
  57. package/dist/packages/renderer/derivedTests/apply.d.ts +10 -0
  58. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  59. package/dist/packages/renderer/derivedTests/check.d.ts +35 -0
  60. package/dist/packages/renderer/derivedTests/check.js +1 -0
  61. package/dist/packages/renderer/fmt.d.ts +5 -0
  62. package/dist/packages/renderer/fmt.js +1 -1
  63. package/dist/packages/renderer/index.d.ts +2 -0
  64. package/dist/packages/renderer/index.js +1 -1
  65. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  66. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  67. package/dist/packages/stats/chartCatalogue.js +1 -1
  68. package/dist/packages/stats/clusterDetection.js +1 -1
  69. package/dist/packages/stats/coFailure.d.ts +11 -0
  70. package/dist/packages/stats/coFailure.js +1 -0
  71. package/dist/packages/stats/correlation.d.ts +7 -0
  72. package/dist/packages/stats/correlation.js +1 -1
  73. package/dist/packages/stats/differenceMap.d.ts +2 -0
  74. package/dist/packages/stats/differenceMap.js +1 -1
  75. package/dist/packages/stats/plotData.d.ts +18 -2
  76. package/dist/packages/stats/plotData.js +1 -1
  77. package/dist/packages/stats/plotSpec.d.ts +31 -2
  78. package/dist/packages/stats/plotSpec.js +4 -4
  79. package/dist/packages/stats/plotTable.d.ts +18 -0
  80. package/dist/packages/stats/plotTable.js +1 -0
  81. package/dist/packages/stats/reportHtml.js +33 -29
  82. package/dist/packages/stats/synthesis.d.ts +7 -1
  83. package/dist/packages/stats/synthesis.js +1 -1
  84. package/dist/packages/stats/testsByWafer.d.ts +11 -0
  85. package/dist/packages/stats/testsByWafer.js +1 -0
  86. package/package.json +8 -4
package/CHANGELOG.md CHANGED
@@ -24,6 +24,113 @@ under `### Breaking`.
24
24
 
25
25
  ## [Unreleased]
26
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
+
80
+ ## [0.38.0] — 2026-10-28
81
+
82
+ ### Breaking
83
+
84
+ - **The Summary panel docks on the `right` or the `left`.** `SummaryPanelOptions.placement` no longer accepts `'top'` or `'bottom'`: the panel's stat tiles, tables and findings list are laid out for a narrow, tall panel. A value other than `'left'` docks the panel on the right.
85
+
86
+ ### Added
87
+
88
+ - **Ring yield by wafer and Quadrant yield by wafer.** Heatmaps on **Insights ▸ Overview**, beside the ring and quadrant diagrams: each region's yield on each wafer (or group), so a pattern on every wafer reads differently from one on a single wafer. Each is a plot, so **Edit as plot** opens it.
89
+ - **Views on the Insights cards.** With **Group by** on, *Yield by group* offers **Group, then wafer** (each group's wafers inside it), *Test value distribution* offers the same nesting coloured by group, the bin pareto offers **Bin mix** (a bar per group split into its bins), and *Pass rate by test* offers a **Grid** of the worst 25 tests by group. *Wafer-to-wafer trend* offers a **Control chart** from three wafers. The pass-rate bars and the soft-bin pareto keep the worst 25 and the largest 15, and the card's note says how many were left out.
90
+ - **A fitted line on the Insights test scatter** for each group when **Group by** is on.
91
+ - **The Plot tab's examples.** The histogram is coloured and normalised by the split, the yield bar carries its values and the median, the tests with limits are drawn as one box each placed between their limits, a pass-rate grid shows which tests fail in which split, and the probability plot is coloured by the split.
92
+
93
+ - **`checkDerivedExpression(input, testDefs, otherDerived?)`.** Checks one derived test's expression without building a map, for a host's own editor: it returns `{ ok: true, produces, reads, warnings }` (a number or a verdict, every test read and how, and advice such as units combined by `+`) or `{ ok: false, message, position }`. It runs the same parser, namespace, kind rule and test-number rules as `buildWaferMap` (a whole STDF number, not a measured test's and not another derived test's), so the editor and the build agree. A cycle between derived tests is still reported by the build as `derived-test-invalid`.
94
+ - **The number keys set the columns of cards.** Over a gallery (or with focus in it, so no click is needed first), on the Insights tab and over a plot of panels, **1** to **5** set that many columns
95
+ and **0** returns to Auto. The gallery's Columns control shows each choice's key, and the Insights tab has a **Columns** control of its
96
+ own beside Group by and Show, which sets every chart grid in the tab. A plot of panels has a **Columns** control above its panels, and the
97
+ keys set its columns while the pointer is over it; an expanded plot of panels scrolls when its panels are taller than the window. The keys do nothing in a text box, a menu or a window, or with Ctrl, Cmd, Alt or Shift
98
+ held.
99
+ - **A selection charted against the rest of its wafer.** The right-click menu of a single map with a selection adds a **Selection vs the rest of the wafer** section: a **Value histogram** with one colour per side, and a **Box plot** of the two. The sides are named in the title, the legend and the footnote ("661 dies · selection vs the rest of W01") with their die counts, so neither can be mistaken for the whole wafer. A plot's footnote can now say what its items are when they are not wafers (`PlotContext.populationLabel`).
100
+ - **Pinned tests.** Each row of the Insights test pickers (and of the test pickers in the charts opened from a map) has a ☆ (or **P** on the focused row) that pins the test. Pinned tests are listed first under a "Pinned" heading, in every picker at once. `getPinnedTests`, `setPinnedTests` and `onPinnedTestsChange` (from `@wafertools/wafermap/render`) let a host keep the set between sessions.
101
+ - **Invert selection.** Right-clicking a single map that has a selection offers **Invert selection** as the first row of the menu: the selection becomes the dies it did not hold.
102
+ - **Hover hints on the Insights tabs and controls.** Each tab, and the Group by, Show and Columns controls, says what it does (Correlation: "How tests move together"), and a hovered tab's tint stays inside the tab bar's outline.
103
+ - **A `funding` link.** `package.json` names the project's [support page](https://wafertools.github.io/support/), so `npm fund` lists it.
104
+
105
+ ### Changed
106
+
107
+ - **Value histogram over groups shows each group as a share of its own dies** (a **Counts** choice keeps the numbers), so groups of different sizes compare by shape.
108
+ - **Group-shift charts in Worth a look draw each wafer once.** The box of a split's shift is drawn over wafer means, the figure the comparison counts, and a field that moves several tests draws them together, each rescaled. A test's mean off the median is drawn against the median of the plot.
109
+ - **Worth a look charts of a lot's losses show where.** A region's loss is a region-by-wafer grid, a failing test is its pass rate by wafer, and an outlier wafer is its yield against control limits in wafer order.
110
+ - **A plot of a set of tests at wafer level** draws one value per wafer for each test.
111
+ - **The probability plot keeps its selection and has the wafer menu.** A box dragged over a probability plot stays marked until a click on empty space clears it, as on the scatter, and right-clicking a point that is one wafer opens that wafer's menu.
112
+ - **A group's box on the Insights box plot drills only that card.** Clicking it shows that group's wafers in the box plot, with **Back**, as on Yield by group; **Show** is the one control that narrows the whole tab.
113
+ - **A legend click filters only its own plot.** On the Insights value histogram, clicking a group in the legend shows just that group in that plot, as on every other plot; **Show** (and the box plot's drill-down) still narrow the whole tab.
114
+ - **"What stands out" is built once for a lot.** The summary panel, Insights and the report share one result for the same lot and pass bins, so a plot-mode switch or opening Insights after the lot has loaded no longer rebuilds it (about a second saved on a 266,000-die lot, in Chrome). The result is read-only.
115
+ - **The Maps | Insights switch shows its whole focus ring.** The ring round the focused tab is drawn in full, on every side, following the switch's rounded corners.
116
+ - **The Insights tab bar stays in view.** The Overview / Distributions / Correlation tabs and their Group-by controls stick beneath the gallery header while the charts scroll, as the bin legend does in the maps view.
117
+ - **A demo lot cut at its own wafer size keeps its pattern.** `docs/examples/data/generate-demos.js --geometry` places each lot's patterns by where its outermost reachable die sits and scales the edge-ring failure rate so the expected share of failing dies is the default wafer's. A coarse wafer (300 mm with 10×8 mm dies) had lost about a third of the edge-ring lot's failures, so its pattern was no longer found. The default geometry is unchanged, byte for byte.
118
+ - **A gallery card is sized for dies of 6 px.** Auto layout sizes cards so each die is at least 6 px across (it was 4 px), so on a dense wafer
119
+ (about 1,000 dies and up) a die is wide enough to aim a pointer at and the kerf between dies stays a clear single line. A card is wider than
120
+ before at the same density, and a window that cannot hold another column at that width keeps the columns it has: the cards then fill the row.
121
+ The compact layout keeps its own 4 px cell.
122
+ - **The summary report prints at paper size.** Printing or saving a report as a PDF scales the whole document up by a quarter, so the 12 px body text is about 11 pt on paper instead of 9 pt. The on-screen report is unchanged.
123
+ - **A reticle cell's repeated failures do not turn an edge arc into a scratch.** When a wafer's pattern reads as a scratch and a reticle cell has a finding of its own, the wafer is classified again with that cell's failing dies set aside. If the line goes, the pattern is what remains (an edge pattern, say) and its note names the cell. A scratch that is still a scratch without those dies stays one, and wafers with no reticle-cell finding are unchanged.
124
+ - **Reticle fields over supplied dies take the dies' own size.** With `dies` passed to `buildWaferMap`, field boundaries are drawn at the dies' width and height, so a field of 3 × 2 dies over 10 × 8 mm dies is 30 × 16 mm.
125
+ - **Cluster detection reads the die size from a sample of the dies.** The neighbourhood it searches is sized from the median die width and height over an even sample, not from the first die, so a layout whose dies differ in size is treated alike wherever its first die sits.
126
+ - **"Seen on N/M wafers" counts the wafers that can show the pattern.** A lot's spatial-pattern and regional findings take M from the wafers that have at least one positioned die, and say so when the lot has others ("2/2 wafers with positions, 1 without"). The share that grades the finding's severity uses the same count, so a lot with unpositioned wafers is graded on the wafers that can carry a pattern.
127
+ - **A test whose name states its unit keeps it on the colour bar and chart axes.** `fmax_MHz` is titled "fmax_MHz" with ticks in MHz, not "fmax_MHz (GHz)"; a name with a base unit and very small or large values (`Idsat_A`) keeps its name and takes an exponent note ("Idsat_A (×10E-6)"); a name without its unit is still rescaled and given the scaled unit.
128
+ - **Limit labels on a narrow chart stay on their own side of the line.** A vertical limit's label is shortened ("Hi 380 mV", then "Hi") before it flips towards the other limit, and never runs across another limit's line.
129
+ - **The Test Value range control is "Colour bar range".** The toolbar button, its tooltip and the guides use the same spelling as the rest of the interface. The `colorbarRangeMode` option keeps its name.
130
+ - **The wafer-centre advisory is worded for the reader.** The "Wafer centre ignored" message says what was ignored and why; the advice to supply `waferConfig.diameter` is in the console warning.
131
+ - **The build uses TypeScript 6.** The package is compiled and type-checked with TypeScript 6 and current development dependencies; the published API and behaviour are unchanged.
132
+ - **Opening the dies of a histogram bin works for a bin of any size.** The point list is built with a loop rather than a spread, which has an argument limit near 125,000.
133
+
27
134
  ## [0.37.1] — 2026-10-22
28
135
 
29
136
  ### Added
package/README.md CHANGED
@@ -5,15 +5,17 @@
5
5
  [![CI and deploy](https://github.com/wafertools/wafermap/actions/workflows/deploy.yml/badge.svg)](https://github.com/wafertools/wafermap/actions/workflows/deploy.yml)
6
6
  [![npm](https://img.shields.io/npm/v/@wafertools/wafermap.svg)](https://www.npmjs.com/package/@wafertools/wafermap)
7
7
  ![runtime deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen)
8
- ![bundle](https://img.shields.io/badge/data%20layer%20min%2Bgz-~81%20kB-blue)
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
+ [![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)
10
12
 
11
13
  <img src="docs/images/hero-test-values.png" alt="wafermap demo" style="max-width:640px; display:block; margin:8px 0;" />
12
14
 
13
- Browser-first wafer map visualization for semiconductor test data.
15
+ Browser-first wafer map visualisation for semiconductor test data.
14
16
 
15
17
  **Zero runtime dependencies.** Pure ES modules with TypeScript types — works in React,
16
- Svelte, Vue, plain HTML, or a Web Worker. The DOM-free data-and-stats layer is ~81 kB
18
+ Svelte, Vue, plain HTML, or a Web Worker. The DOM-free data-and-stats layer is ~82 kB
17
19
  min+gz; the interactive renderer is larger, and its chart suite and in-app guide are
18
20
  loaded on demand rather than shipped up front — [measured sizes](docs/performance.md).
19
21
 
@@ -21,7 +23,7 @@ loaded on demand rather than shipped up front — [measured sizes](docs/performa
21
23
 
22
24
  ## Community
23
25
 
24
- Questions, ideas, or want to show off a wafer map you built? Use [GitHub
26
+ Questions or ideas? Use [GitHub
25
27
  Discussions](https://github.com/wafertools/.github/discussions).
26
28
 
27
29
  ## Overview
@@ -45,7 +47,7 @@ wafermap renders interactive wafer maps from semiconductor prober output. Hard b
45
47
 
46
48
  **[tsmap](https://github.com/wafertools/tsmap)** is a finished, free, MIT-licensed
47
49
  application built on this library. It opens STDF, ATDF, CSV, JSON and Parquet (plus
48
- `.gz` and `.zip`), runs on Linux, macOS and Windows, and also runs
50
+ `.gz`, `.bz2` and `.zip`), runs on Linux, macOS and Windows, and also runs
49
51
  [in the browser](https://wafertools.github.io/tsmap/app/) with no install — files are
50
52
  parsed locally and never uploaded. Plot modes, findings, the Insights charts, lot
51
53
  galleries, splits and reports, without writing any code.
@@ -78,7 +80,7 @@ export. Add `analyzeWaferMap` for the findings and summary panel, swap in
78
80
 
79
81
  The API reference is long because it documents every option, not because you need
80
82
  them: [tsmap](https://github.com/wafertools/tsmap), a complete cross-platform desktop
81
- application built on this library, imports **22** of its ~100 exports. Read the
83
+ application built on this library, imports **26** of its ~100 exports. Read the
82
84
  [Quick Start](https://wafertools.github.io/wafermap/quickstart/) first and treat the
83
85
  [API reference](https://wafertools.github.io/wafermap/api/) as something to search,
84
86
  not to read.
@@ -122,15 +124,21 @@ example pages under `docs/examples/`.
122
124
 
123
125
  ## Author and licence
124
126
 
125
- Written by **Paul Robins**, after nearly four decades in semiconductor test — most
126
- of it building test data analysis tools: wafer map and chart viewers, and the
127
- platforms they were built on.
127
+ Written by **Paul Robins**, who has spent over 30 years building test data analysis
128
+ software: wafer map and chart viewers, and the platforms they were built on.
128
129
 
129
- That work leaned on free software throughout — zlib, Tcl/Tk, SQLite, GCC — and it
130
- was a good deal. wafermap is some of it going back the other way, prompted by
131
- finding out that engineers doing this job today still have no decent free option
132
- for wafer map analysis.
130
+ A lot of that work leaned on free software, and it was a good deal. wafermap is some
131
+ of it going back the other way, prompted by finding out that engineers doing this job
132
+ today still have no decent free option for wafer test map analysis.
133
133
 
134
134
  [MIT](LICENSE): free to use, modify and redistribute, including in commercial and
135
135
  closed-source products. The only condition is that the copyright notice travels
136
136
  with it.
137
+
138
+ ## Support
139
+
140
+ wafermap is free, open-source and MIT-licensed, and will stay that way. If it saves you
141
+ time, you can support it on [Ko-fi](https://ko-fi.com/wafertools). If your company relies
142
+ on it, please consider sponsoring it monthly:
143
+ [how to support wafertools](https://wafertools.github.io/support/). Bug reports and sample
144
+ files help just as much.
@@ -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)}
@@ -1,4 +1,4 @@
1
- import type { Die } from '../core/dies.js';
1
+ import { type Die } from '../core/dies.js';
2
2
  import type { Wafer } from '../core/wafer.js';
3
3
  import type { TestDef } from '../renderer/buildWaferMap.js';
4
4
  /** One wafer's share of a population. */
@@ -29,6 +29,11 @@ export interface DrilldownSource {
29
29
  /** Set when the dies are not measured dies (a lot stack's per-position
30
30
  * aggregates): every chart is then unavailable, with this as the reason. */
31
31
  notMeasuredReason?: string;
32
+ /**
33
+ * For a selection on one wafer: that wafer's other dies, so the selection can be charted against them. Absent for
34
+ * anything else (a whole wafer, several wafers, a bin). Like `items`, a snapshot.
35
+ */
36
+ rest?: DrilldownItem;
32
37
  }
33
38
  export declare const LOT_STACK_REASON = "This map stacks a lot: its dies are per-position aggregates, not measured dies";
34
39
  interface WaferFacts {
@@ -45,8 +50,8 @@ interface WaferFacts {
45
50
  /** The wafer's ring count, from its built result. */
46
51
  ringCount: number;
47
52
  }
48
- /** Dies the user selected on one wafer's map. */
49
- export declare function selectionPopulation(selected: Die[], f: WaferFacts): DrilldownSource;
53
+ /** Dies the user selected on one wafer's map, with the wafer's other dies (`all` less the selection) as `rest`. */
54
+ export declare function selectionPopulation(selected: Die[], f: WaferFacts, all?: readonly Die[]): DrilldownSource;
50
55
  /** Every die of one wafer. */
51
56
  export declare function waferPopulation(dies: Die[], f: WaferFacts): DrilldownSource;
52
57
  export {};
@@ -1 +1 @@
1
- export const LOT_STACK_REASON="This map stacks a lot: its dies are per-position aggregates, not measured dies";function s(a,e,t){return{items:[{label:t.waferLabel??"this wafer",dies:a,waferIndex:t.waferIndex,wafer:t.wafer,passBins:t.passBins,ringCount:t.ringCount}],population:e,testDefs:t.testDefs,activeTest:t.activeTest,notMeasuredReason:t.isLotStack?LOT_STACK_REASON:void 0}}export function selectionPopulation(a,e){return s(a,e.waferLabel?`selected on ${e.waferLabel}`:"selected",e)}export function waferPopulation(a,e){return s(a,e.waferLabel?`on ${e.waferLabel}`:"on this wafer",e)}
1
+ import{getDieKey as o}from"../core/dies.js";export const LOT_STACK_REASON="This map stacks a lot: its dies are per-position aggregates, not measured dies";function i(s,t,e){return{items:[{label:e.waferLabel??"this wafer",dies:s,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:e.ringCount}],population:t,testDefs:e.testDefs,activeTest:e.activeTest,notMeasuredReason:e.isLotStack?LOT_STACK_REASON:void 0}}export function selectionPopulation(s,t,e){const n=i(s,t.waferLabel?`selected on ${t.waferLabel}`:"selected",t);if(!e||t.isLotStack)return n;const c=new Set(s.map(r=>o(r))),a=e.filter(r=>!c.has(o(r)));if(a.length===0)return n;const u=n.items[0];return{...n,rest:{...u,dies:a}}}export function waferPopulation(s,t){return i(s,t.waferLabel?`on ${t.waferLabel}`:"on this wafer",t)}
@@ -206,21 +206,7 @@ export declare function applyCanvasFlow(canvas: HTMLCanvasElement, above?: HTMLE
206
206
  * `3.33e-11`) to a misleading "0.00".
207
207
  */
208
208
  export declare function formatValue(v: number): string;
209
- /**
210
- * Shared axis formatter for a numeric chart axis: one SI scale chosen from
211
- * the largest-magnitude endpoint, applied to every tick, with the scaled
212
- * unit returned once as the axis label (e.g. ticks "861 · 1040 · 1220"
213
- * with label "(µA)") — the same `fmtColorbarAxis` contract the map's
214
- * colorbar uses, so axes never show raw exponent soup like "861E-6" next
215
- * to a tooltip that says "861 µA". Falls back to `formatValue` ticks and
216
- * no label when the test has no unit.
217
- *
218
- * Pass `step` — the tick spacing from `fitTicks` (`renderer/axisTicks.ts`) —
219
- * and every label carries exactly the decimals that step needs. `tickWithUnit`
220
- * is the same label with the scaled unit appended, for an axis with no
221
- * separate unit label.
222
- */
223
- export declare function makeAxisFormat(vRef: number, unit: string | undefined, step?: number): {
209
+ export declare function makeAxisFormat(vRef: number, unit: string | undefined, step?: number, name?: string): {
224
210
  tick: (v: number) => string;
225
211
  tickWithUnit: (v: number) => string;
226
212
  unitLabel: string;
@@ -359,6 +345,15 @@ export interface SeriesLegendItem {
359
345
  */
360
346
  export declare function makeSeriesLegendItem(label: string, color: string, ownerDocument?: Document): SeriesLegendItem;
361
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;
362
357
  export declare function cardShell(title: string, onSaveImage?: SaveImageHandler, ownerDocument?: Document, opts?: CardShellOptions): CardShell;
363
358
  /**
364
359
  * "How to read this: *Control charts* in the user guide" (no full stop), the title a link that opens the guide at that
@@ -375,7 +370,9 @@ export declare function makeSegmented(
375
370
  options: Array<[value: string, label: string, hint?: string]>, current: string, onChange: (value: string) => void, ownerDocument?: Document,
376
371
  /** Smaller type/padding for the summary panel's 260px column, where the
377
372
  * chart-card sizing overflows a section header. Charts keep the default. */
378
- compact?: boolean): HTMLElement;
373
+ compact?: boolean): HTMLElement & {
374
+ setValue(value: string): void;
375
+ };
379
376
  /**
380
377
  * A table that lists its first `first` rows, with a button to list every one and back. Listed in full it scrolls inside
381
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,
@@ -398,6 +395,11 @@ export interface ListSelectOption {
398
395
  group?: string;
399
396
  /** Why this option cannot be chosen now. It stays in the list, dimmed, with the reason after it, and does nothing when picked. */
400
397
  disabled?: string;
398
+ /** A pin toggle at the end of the row: whether it is pinned, and the reader's pin or unpin. The list is rebuilt after it. */
399
+ pin?: {
400
+ pinned: boolean;
401
+ toggle: () => void;
402
+ };
401
403
  }
402
404
  /**
403
405
  * A themed single-select picker: a trigger button plus an on-demand popup
@@ -410,7 +412,7 @@ export interface ListSelectOption {
410
412
  * sync from an external click-through (the correlation matrix picking a cell)
411
413
  * without re-entering their own change handler.
412
414
  */
413
- export declare function makeListSelect(options: readonly ListSelectOption[], selected: string, onChange: (value: string) => void, opts?: {
415
+ export declare function makeListSelect(optionsOrGetter: readonly ListSelectOption[] | (() => readonly ListSelectOption[]), selected: string, onChange: (value: string) => void, opts?: {
414
416
  maxWidth?: string;
415
417
  ownerDocument?: Document;
416
418
  ariaLabel?: string;
@@ -540,6 +542,7 @@ export interface LinkedGroupSelect {
540
542
  export declare function makeLinkedGroupSelect(groupKeys: readonly string[], labelText: string, initial: string | null, onUserChange: (key: string | null) => void, opts?: {
541
543
  maxWidth?: string;
542
544
  ownerDocument?: Document;
545
+ hint?: string;
543
546
  }): LinkedGroupSelect;
544
547
  export interface WaferSelectItem {
545
548
  label?: string;
@@ -552,14 +555,26 @@ export declare function makeWaferSelect(items: readonly WaferSelectItem[], selec
552
555
  value: string;
553
556
  };
554
557
  export declare function makeToggle(labelText: string, checked: boolean, onChange: (v: boolean) => void, ownerDocument?: Document, hint?: string): HTMLLabelElement;
555
- 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 {
556
561
  value: string;
557
562
  label: string;
558
- }[], selected: string, onChange: (value: string) => void, opts?: {
563
+ }[] | (() => readonly {
564
+ value: string;
565
+ label: string;
566
+ }[]), selected: string, onChange: (value: string) => void,
567
+ /** `hint` is the hover tooltip over the label and its trigger, for a control whose name alone does not say what it does. */
568
+ opts?: {
559
569
  maxWidth?: string;
560
570
  hook?: string;
561
571
  ownerDocument?: Document;
572
+ hint?: string;
562
573
  }): HTMLLabelElement;
574
+ /**
575
+ * A grid of chart cards. Its tracks are as many 420 px-or-wider columns as fit, unless an ancestor sets `--wmap-insights-cols` (a
576
+ * count) and `--wmap-insights-min` (`0px`), as the Insights tab does when the reader picks a number of columns.
577
+ */
563
578
  export declare function makeChartGridWrap(ownerDocument?: Document): HTMLDivElement;
564
579
  /** Small positioned hover tooltip, matching the pattern each ported panel builds for itself. */
565
580
  export declare function makeTooltip(card: HTMLElement): HTMLElement;
@@ -762,6 +777,17 @@ export declare function resolveAxisRange(opts: {
762
777
  * +1 to draw left-aligned right of it.
763
778
  */
764
779
  export declare function limitLabelSide(x: number, textWidth: number, plotLeft: number, plotRight: number, isLowLimit: boolean, pad?: number): -1 | 1;
780
+ /**
781
+ * Text and side for a vertical limit line's label. The label stays on its semantic side (outside the in-spec region)
782
+ * and never runs across another limit's line: when the full text does not fit there it is shortened first
783
+ * ("Hi limit 380 mV" → "Hi 380 mV" → "Hi"), and only when no variant fits on that side does it flip, again
784
+ * preferring the longest variant that clears every line. `otherXs` are the other limit lines' x positions.
785
+ * If nothing clears them, the full text goes on the side `limitLabelSide` picks.
786
+ */
787
+ export declare function limitLabelPlacement(x: number, variants: readonly string[], measure: (text: string) => number, plotLeft: number, plotRight: number, isLowLimit: boolean, otherXs?: readonly number[], pad?: number): {
788
+ text: string;
789
+ side: -1 | 1;
790
+ };
765
791
  export declare function drawOffAxisLimits(ctx: CanvasRenderingContext2D, offAxis: AxisRange['offAxis'], axis: {
766
792
  left: number;
767
793
  right: number;
@@ -1 +1 @@
1
- import{SHADOW as G,LEADING as re,wireTooltip as U,wireControlHover as O,controlStyle as _,SPACE as v,RADIUS as $,fontPx as D,FONT as A,CLR as g,Z_BASE as le,menuLayerFor as se,wireListNavigation as ae,MENU_SEARCH_THRESHOLD as X,makeMenuSearchBox as ce,markMenuTrigger as W,markNoPrint as j,openCommandMenu as de,saveImageBlob as ue,openReparentedModal as pe}from"../toolbar.js";import{ICONS as Y}from"../icons.js";import{openGuideAt as fe}from"../guideWindow.js";import{minOf as me,maxOf as he}from"../../core/utils.js";import{robustFence as K}from"../../stats/math.js";import{fmt as ge,fmtColorbarAxis as xe}from"../../renderer/fmt.js";import{markedTestLabel as be,DERIVED_LANE_PAD as ye}from"../../renderer/testLabel.js";export function openChartExpandModal(e,o,t={}){for(const a of e.querySelectorAll('div[style*="position: absolute"]'))a.style.display==="block"&&a.style.pointerEvents==="none"&&(a.style.display="none");const i=e.getAttribute("style")??"",n=e.dataset.wmapChartGrow??"plot";Object.assign(e.style,{flex:"1",minHeight:"0",alignSelf:"stretch",border:"none",borderRadius:"0"}),e.dataset.wmapExpanded="1";const r=e.querySelector(":scope > div > [data-wmap-card-expand]"),l=a=>{r&&(r.style.display=a?"flex":"none")};l(!1);const s=pe([e],{title:o,anchor:t.anchor,ownerDocument:e.ownerDocument,boxSize:we[n],onClosed:()=>{delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),t.onClosed?.()}});if(!s)return delete e.dataset.wmapExpanded,e.setAttribute("style",i),l(!0),null;if(n==="rows"){const a=()=>{const d=Number(e.dataset.wmapChartFullH);if(!d)return;const c=s.box.offsetHeight-s.contentWrap.clientHeight;s.setNaturalHeight(`min(90vh, ${Math.ceil(c+d)}px)`)};a(),(e.ownerDocument.defaultView??window).requestAnimationFrame(a)}return s}const we={plot:{width:"min(94vw, 1100px)",height:"min(90vh, 760px)"},rows:{width:"min(94vw, 960px)",height:"min(90vh, 700px)"},square:{width:"min(94vw, 820px)",height:"min(90vh, 860px)"}};export const GRID_ALPHA=.4;export function withAlpha(e,o){const t=e.trim();let i,n,r,l=1;const s=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i),a=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i);if(s){const d=s[1].length===3?s[1].split("").map(c=>c+c).join(""):s[1];[i,n,r]=[0,2,4].map(c=>parseInt(d.slice(c,c+2),16)),d.length===8&&(l=parseInt(d.slice(6,8),16)/255)}else if(a)[i,n,r]=[a[1],a[2],a[3]].map(Number),a[4]!==void 0&&(l=a[4].endsWith("%")?parseFloat(a[4])/100:Number(a[4]));else return e;return`rgba(${i}, ${n}, ${r}, ${+(l*o).toFixed(3)})`}const Ce={text:"#333",textMuted:"#66788a",border:"rgba(0,0,0,0.12)",bg:"#fff",bgHover:"#edf0f8",track:"#fafbfc",warnBorder:"#f0c040",accent:"#1a66cc",limitLine:"#b45309",alert:"#7a1c1c"},Z={text:"text",textMuted:"text-muted",border:"border",bg:"surface",bgHover:"bg-hover",track:"panel-bg",warnBorder:"warn-border",accent:"icon-active",limitLine:"warn-text",alert:"err-text"};export function resolveChartCanvasColors(e){const o=getComputedStyle(e),t={};for(const i of Object.keys(Z)){const n=o.getPropertyValue(`--wmap-${Z[i]}`).trim();t[i]=n||Ce[i]}return t.grid=withAlpha(t.border,GRID_ALPHA),t}export const PADDING=12,VALUE_WIDTH=100;export function observeResize(e,o){const t=e.ownerDocument.defaultView??window;let i=0;const n=new t.ResizeObserver(()=>{i||(i=t.requestAnimationFrame(()=>{i=0,o()}))});return n.observe(e),{disconnect:()=>{i&&t.cancelAnimationFrame(i),i=0,n.disconnect()}}}export function growCardToFitContent(e,o,t){const i=`${z(e,o)+t}px`;e.style.minHeight!==i&&(e.style.minHeight=i)}function z(e,o){const t=e.ownerDocument.defaultView??window,i=t.getComputedStyle(e);let n=0;for(const r of Array.from(e.children)){if(r===o)continue;const l=r,s=t.getComputedStyle(l);s.display==="none"||s.position==="absolute"||s.position==="fixed"||(n+=l.offsetHeight+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}return i.boxSizing==="border-box"&&(n+=(parseFloat(i.paddingTop)||0)+(parseFloat(i.paddingBottom)||0)+(parseFloat(i.borderTopWidth)||0)+(parseFloat(i.borderBottomWidth)||0)),n}function J(e,o){const t=e.ownerDocument.defaultView??window;let i=0;for(const n of Array.from(e.children)){if(n===o)continue;const r=n,l=t.getComputedStyle(r);l.display==="none"||l.position==="absolute"||l.position==="fixed"||(i+=r.offsetHeight+(parseFloat(l.marginTop)||0)+(parseFloat(l.marginBottom)||0))}return i}export const WAFER_MENU_HINT="<br><em>right-click to chart this wafer</em>";export function populationPhrase(e,o,t){const i=e.toLocaleString(),n=e===1?"die":"dies";return t?e===o?`${i} ${n} ${t}`:`${i} of ${o.toLocaleString()} dies ${t} (partial and edge-excluded dies left out)`:`${i} ${n}`}export function setChartGrow(e,o){e.dataset.wmapChartGrow=o}export function isExpandedCard(e){return e.dataset.wmapExpanded==="1"}export function bodyRoom(e,o,t){const n=(e.ownerDocument.defaultView??window).getComputedStyle(e),r=e.clientHeight-(parseFloat(n.paddingTop)||0)-(parseFloat(n.paddingBottom)||0),l=n.boxSizing==="border-box"?(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0)+(parseFloat(n.borderTopWidth)||0)+(parseFloat(n.borderBottomWidth)||0):0;return r-(z(e,o)-l)-(t?J(o,t):0)}export function fitRowsHeight(e,o,t,i,n=0){if(growCardToFitContent(e,o,n+t),e.dataset.wmapChartFullH=String(Math.ceil(z(e,o)+n+i)),!isExpandedCard(e))return t;const r=bodyRoom(e,o)-n;return Math.max(t,Math.min(i,Math.floor(r)))}export function chartFillHeight(e,o,t,i){const n=J(o,t);return growCardToFitContent(e,o,n+i),Math.max(i,o.clientHeight-n)}export function chartDpr(e){return(e.ownerDocument.defaultView??window).devicePixelRatio||1}export function prepareCanvas(e,o,t,i){const n=chartDpr(e);e.width=Math.max(1,Math.floor(t*n)),e.height=Math.max(1,Math.floor(i*n)),e.style.width=`${t}px`,e.style.height=`${i}px`;const r=e.getContext("2d");return r?(r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,t,i),r.font=`${D(-1)}px system-ui, sans-serif`,r.textBaseline="middle",{ctx:r,theme:resolveChartCanvasColors(o)}):null}export function applyCanvasFlow(e,o=0){let t;if(typeof o=="number")t=o;else{const i=(o.ownerDocument.defaultView??window).getComputedStyle(o);t=o.offsetTop+o.offsetHeight+(parseFloat(i.marginBottom)||0)}e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top=`${t}px`,e.style.bottom="0"}export function formatValue(e){return Number.isFinite(e)?Number.isInteger(e)?`${e}`:ge(e,void 0,"engineering"):"\u2014"}export function makeAxisFormat(e,o,t){if(!o&&t===void 0)return{tick:formatValue,tickWithUnit:formatValue,unitLabel:""};const{tickFmt:i,axisLabel:n,scaledUnit:r}=xe(e,null,o,"engineering",t);return{tick:i,tickWithUnit:r?l=>`${i(l)} ${r}`:i,unitLabel:n}}const ve=8;export const VERTICAL_TICK_SPACING_PX=28;export function horizontalTickSpacing(e,o,t){return(i,n)=>{const r=makeAxisFormat(o,t,i).tick;return n.reduce((l,s)=>Math.max(l,e.measureText(r(s)).width),0)+ve}}export function drawAxisUnit(e,o,t,i,n){const r={textAlign:e.textAlign,textBaseline:e.textBaseline,fillStyle:e.fillStyle,font:e.font};e.font=`${D(-1)}px system-ui, sans-serif`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n,e.fillText(`(${o})`,t,i),Object.assign(e,r)}export function captionText(e){return e.split(" \xB7 ").map(o=>o.replace(/[\s·]+$/,"").trim()).filter(o=>o&&!/\b(click|clicks|drag|hover|right-click)\b/i.test(o)&&!/\(.*(click|drag).*\)/i.test(o)).join(" \xB7 ")}const P=(e,o)=>{for(let t=e;t&&t!==o.parentElement;t=t.parentElement)if(t.style.display==="none")return!1;return!0},Se=/\s*[▾▼]\s*$/,q=new WeakMap;export function describeCard(e){const o=[],t=e.querySelector("[data-wmap-controls]");if(t){for(const l of t.querySelectorAll("button[aria-haspopup]")){if(!P(l,t))continue;const s=(l.textContent??"").replace(Se,"").trim();if(!s)continue;const a=l.closest("label"),c=(a?(a.textContent??"").replace(l.textContent??"","").replace(/[:\s]+$/,"").trim():"")||l.getAttribute("aria-label")||"";o.push(c&&c!==s?`${c}: ${s}`:s)}for(const l of t.querySelectorAll('[role="radiogroup"]')){if(!P(l,t))continue;const a=l.querySelector("input:checked")?.closest("label")?.textContent?.trim();a&&o.push(a)}for(const l of t.querySelectorAll('input[type="checkbox"]:checked')){if(!P(l,t))continue;const s=l.closest("label")?.textContent?.trim();s&&o.push(s)}}const i=[];for(const l of e.querySelectorAll("[data-wmap-caption]")){if(!P(l,e))continue;const s=captionText((l.textContent??"").replace(/\s+/g," ").trim());s&&i.push(s)}const n=[];for(const l of e.querySelectorAll("button[aria-pressed]")){const s=l.querySelector("span"),a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}for(const l of e.querySelectorAll("[data-wmap-legend] > span")){const s=l.firstElementChild,a=s?.style.backgroundColor||s?.style.borderColor,d=(l.textContent??"").trim();d&&a&&a!=="transparent"&&n.push({label:d,color:a})}const r=q.get(e)?.();return r&&(r.controls&&o.push(...r.controls),r.caption!==void 0&&(i.length=0,i.push(...typeof r.caption=="string"?[r.caption]:r.caption)),r.legend&&(n.length=0,n.push(...r.legend))),{controls:o,captions:i,legend:n}}function ke(e){const o=describeCard(e),t=q.get(e)?.();return{controls:o.controls,caption:o.captions,legend:o.legend.length?o.legend:void 0,colorbar:t?.colorbar}}function Q(e){for(const o of e.querySelectorAll("[data-wmap-chart-card]")){const t=o.querySelector(":scope > [data-wmap-print-only]");if(!t)continue;const i=describeCard(o);t.replaceChildren();const n=[i.controls.length?i.controls.join(" \xB7 "):"",...i.captions].filter(Boolean);for(const r of n){const l=e.createElement("div");l.textContent=r,t.appendChild(l)}for(const r of o.querySelectorAll("[data-wmap-caption]"))r.setAttribute("data-wmap-noprint","1")}}const ee=new WeakSet;function Le(e){if(ee.has(e))return;ee.add(e);const o=e.createElement("style");o.textContent="@media print{[data-wmap-print-only]{display:block!important}}",e.head.appendChild(o);const t=e.defaultView;t?.addEventListener("beforeprint",()=>Q(e));try{t?.matchMedia?.("print").addEventListener?.("change",i=>{i.matches&&Q(e)})}catch{}}function Ae(e){const o=e.ownerDocument.defaultView;for(let t=e;t&&o;t=t.parentElement){const i=o.getComputedStyle(t).backgroundColor;if(i&&i!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(i))return i}return"#ffffff"}export function composeChartPng(e,o){const t=e.ownerDocument,i=t.createElement("canvas"),n=Math.max(1,e.width/(e.clientWidth||e.width)),r=e.width,l=t.createElement("canvas").getContext("2d"),s=12*n,a=(f,x="400")=>`${x} ${f*n}px system-ui, -apple-system, "Segoe UI", sans-serif`,d=(f,x)=>l?(l.font=x,l.measureText(f).width):f.length*7*n,c=[];let u=0;if(o){u=s,c.push({kind:"text",text:o.title,x:s,y:u+14*n,font:a(16,"600"),alpha:1}),u+=24*n;const f=o.decor,x=[];f?.controls?.length&&x.push({text:f.controls.join(" \xB7 "),alpha:1});for(const m of f?.caption===void 0?[]:typeof f.caption=="string"?[f.caption]:f.caption)x.push({text:m,alpha:.75});const b=a(12);for(const{text:m,alpha:C}of x){let y="";for(const S of m.split(" ")){const T=y?`${y} ${S}`:S;y&&d(T,b)>r-2*s?(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n,y=S):y=T}y&&(c.push({kind:"text",text:y,x:s,y:u+11*n,font:b,alpha:C}),u+=17*n)}if(f?.legend?.length){u+=4*n;const m=a(12);let C=s;for(const y of f.legend){const S=14*n+d(y.label,m)+14*n;C>s&&C+S>r-s&&(C=s,u+=18*n),c.push({kind:"dot",x:C+5*n,y:u+7*n,r:5*n,color:y.color}),c.push({kind:"text",text:y.label,x:C+14*n,y:u+11*n,font:m,alpha:1}),C+=S}u+=20*n}if(f?.colorbar){u+=4*n;const m=a(12),C=f.colorbar;let y=s;c.push({kind:"text",text:C.label,x:y,y:u+10*n,font:m,alpha:1}),y+=d(C.label,m)+10*n,c.push({kind:"text",text:C.lo,x:y,y:u+10*n,font:m,alpha:.75}),y+=d(C.lo,m)+6*n,c.push({kind:"strip",x:y,y:u+1*n,w:200*n,h:10*n,color:C.color}),y+=206*n,c.push({kind:"text",text:C.hi,x:y,y:u+10*n,font:m,alpha:.75}),u+=20*n}u+=6*n}i.width=r,i.height=Math.ceil(e.height+u);const p=i.getContext("2d");if(p.fillStyle=o?Ae(o.card):"#ffffff",p.fillRect(0,0,i.width,i.height),o){const f=t.defaultView,x=f&&f.getComputedStyle(o.card).color||"#222222";p.textBaseline="alphabetic";for(const b of c)if(b.kind==="text")p.font=b.font,p.fillStyle=x,p.globalAlpha=b.alpha,p.fillText(b.text,b.x,b.y),p.globalAlpha=1;else if(b.kind==="dot")p.fillStyle=b.color,p.beginPath(),p.arc(b.x,b.y,b.r,0,Math.PI*2),p.fill();else for(let m=0;m<b.w;m++)p.fillStyle=b.color(m/Math.max(1,b.w-1)),p.fillRect(b.x+m,b.y,1,b.h)}return p.drawImage(e,0,u),i}export function saveCanvasPng(e,o,t,i){composeChartPng(e,i).toBlob(n=>{n&&ue(n,o,t)},"image/png")}const te="10px";export function chartSwatchCss(e,o="solid"){return["display:inline-block",`width:${te}`,`height:${te}`,`border-radius:${$.pill}`,`background:${o==="outline"?"transparent":e}`,`border:1px ${o==="outline"?"dashed":"solid"} ${e}`,"box-sizing:border-box","flex-shrink:0"].join(";")}const Ee="0.35";export function makeSeriesLegendItem(e,o,t=document){const i=t.createElement("button");i.type="button",Object.assign(i.style,{display:"inline-flex",alignItems:"center",gap:v.xs,padding:`${v.xs} ${v.md}`,borderRadius:$.pill,border:`1px solid ${g.menuBorder}`,background:"none",cursor:"pointer",fontSize:A.body,color:g.text,whiteSpace:"nowrap"}),O(i,"bare");const n=t.createElement("span");return n.style.cssText=chartSwatchCss(o),i.append(n,t.createTextNode(e)),{el:i,setState({selected:r,dimmed:l}){i.style.borderColor=r?g.iconActive:g.menuBorder,i.style.fontWeight=r?"600":"400",i.style.opacity=l?Ee:"1",i.setAttribute("aria-pressed",r?"true":"false")}}}export function cardFrameStyle(){return{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.container,padding:v.xl,fontVariantNumeric:"tabular-nums"}}function ne(e){Object.assign(e.style,{..._("outlined"),color:g.label,padding:"0",width:"22px",height:"22px",lineHeight:re.none,flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center"}),O(e)}export function cardShell(e,o,t=document,i={}){const n=t.createElement("div");n.dataset.wmapChartCard="1",n.dataset.wmapChartTitle=e,Object.assign(n.style,{display:"flex",flexDirection:"column",...cardFrameStyle(),minWidth:"0",minHeight:"0",flex:"1 1 0",position:"relative"});const r=n.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",gap:v.sm,paddingBottom:"6px",marginBottom:v.md,borderBottom:`1px solid ${g.menuBorder}`});const l=n.ownerDocument.createElement("div");l.textContent=e,Object.assign(l.style,{color:g.value,fontSize:A.heading,fontWeight:"600",flex:"1"}),r.appendChild(l);const s=makeTooltip(n),a=n.ownerDocument.createElement("button");a.type="button",a.setAttribute("aria-label","Expand"),a.innerHTML=Y.expand,a.dataset.wmapCardExpand="1",ne(a),attachChartTip(a,n,s,"Expand"),j(a),a.addEventListener("click",()=>{isExpandedCard(n)||openChartExpandModal(n,l.textContent??e)}),r.appendChild(a);const d=n.ownerDocument.createElement("button");d.type="button",d.setAttribute("aria-label","Chart actions"),d.innerHTML=Y.more,d.dataset.wmapCardMenu="1",ne(d),attachChartTip(d,n,s,"Chart actions"),W(d,!1),j(d),r.appendChild(d);const c=n.ownerDocument.createElement("div");c.dataset.wmapCardAbout="1",c.setAttribute("role","note"),Object.assign(c.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.md}),j(c);let u;const p=h=>{c.textContent=h?u?.text??"":"",c.style.display=h?"":"none"};let f,x;const b=()=>{const h=f?f():n.querySelector("canvas");h&&saveCanvasPng(h,l.textContent||e,o,{card:n,title:l.textContent||e,decor:ke(n)})},m=()=>{const h=[],M=(E,N,B)=>({label:E,active:!1,action:!0,enabled:!B,disabledHint:B,onClick:()=>{C?.(),N()}});i.png!==!1&&(f||n.querySelector("canvas"))&&h.push(M("Save as PNG",b));for(const E of x?.()??[])h.push(M(E.label,E.onClick,E.disabledHint));if(u){const E=c.style.display!=="none";h.push({label:`About this ${u.noun}`,active:E,onClick:()=>{C?.(),p(!E)}})}return h};let C;d.addEventListener("click",()=>{if(d.getAttribute("aria-expanded")==="true"){C?.();return}const h=m();h.length!==0&&(C=de(d.getBoundingClientRect(),d,h,`${l.textContent||e}: chart actions`,{trigger:d,hook:"wmapCardMenuList"}))}),n.appendChild(r),n.appendChild(c);const y=n.ownerDocument.createElement("div");y.dataset.wmapPrintOnly="1",Object.assign(y.style,{display:"none",color:g.label,fontSize:A.body,marginBottom:v.sm}),n.appendChild(y),Le(n.ownerDocument);const S=n.ownerDocument.createElement("div");S.dataset.wmapControls="1",Object.assign(S.style,{display:"flex",gap:v.sm,marginBottom:v.md,flexWrap:"wrap",alignItems:"center"}),j(S),n.appendChild(S);const T=n.ownerDocument.createElement("div");return Object.assign(T.style,{overflowX:"hidden",overflowY:"hidden",minHeight:"0",flex:"1",position:"relative"}),n.appendChild(T),{card:n,heading:l,controlsRow:S,body:T,setPngDecor:h=>{q.set(n,h)},setPngCanvas:h=>{f=h},setAbout:h=>{u=h,p(!!h&&c.style.display!=="none")},setMenuRows:h=>{x=h}}}export function guideCite(e,o,t="How to read this"){const i=e.createElement("span");return i.append(`${t}: `,oe(e,o)," in the user guide"),i}function oe(e,o){const t=e.createElement("button");return t.type="button",t.textContent=o.title,t.dataset.wmapGuideLink=o.id,Object.assign(t.style,{border:"none",background:"none",padding:"0",font:"inherit",color:g.iconActive,textDecoration:"underline",cursor:"pointer"}),O(t),t.addEventListener("click",()=>fe(o.id,t)),t}export function appendGuideCites(e,o){if(o.length===0)return;const t=e.ownerDocument;e.append(" \xB7 how to read this: "),o.forEach((i,n)=>{n>0&&e.append(n===o.length-1?" and ":", "),e.append(oe(t,i))}),e.append(" in the user guide")}export function inputStyle(){return{background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,padding:`${v.xs} ${v.sm}`,fontSize:A.body,fontFamily:A.family,boxSizing:"border-box",minWidth:"0"}}export function makeSegmented(e,o,t,i=document,n=!1){const r=i.createElement("div");r.setAttribute("role","radiogroup"),Object.assign(r.style,{display:"inline-flex",flexWrap:"wrap",maxWidth:"100%",padding:"1px 0 0 1px"});const l=e.length-1,s=`seg-${Math.random().toString(36).slice(2,9)}`,a=[];return e.forEach(([d,c,u],p)=>{const f=i.createElement("label");u&&U(f,u),Object.assign(f.style,{display:"inline-flex",alignItems:"center",fontSize:A.body,padding:n?"1px 6px":"3px 10px",cursor:"pointer",userSelect:"none",border:`1px solid ${g.menuBorder}`,margin:"-1px 0 0 -1px",borderTopLeftRadius:p===0?$.control:"0",borderBottomLeftRadius:p===0?$.control:"0",borderTopRightRadius:p===l?$.control:"0",borderBottomRightRadius:p===l?$.control:"0"}),O(f,"bare");const x=i.createElement("input");x.type="radio",x.name=s,x.value=d,x.checked=d===o,Object.assign(x.style,{position:"absolute",opacity:"0",width:"0",height:"0"});const b=()=>{f.style.background=x.checked?g.bgActive:g.menuBg,f.style.color=x.checked?g.iconActive:g.text,f.dataset.on=x.checked?"true":"false"};a.push(b),b(),x.addEventListener("change",()=>{if(x.checked){for(const m of a)m();t(d)}}),f.append(x,i.createTextNode(c)),r.appendChild(f)}),r}const $e=360;export function firstRowsToggle(e,o){let t=!1;const i=e.createElement("button");i.type="button",Object.assign(i.style,{..._("outlined"),marginTop:v.sm}),O(i);const n=()=>{o.fill(t),Object.assign(o.scroller.style,{maxHeight:t?`${$e}px`:"",overflowY:t?"auto":""}),i.textContent=t?`Show the first ${o.noun}`:`Show all ${o.total} ${o.noun}`,i.style.display=o.total>o.first?"":"none"};return i.addEventListener("click",()=>{t=!t,n()}),n(),i}export function makeBackButton(e,o=document){const t=o.createElement("button");return t.type="button",t.textContent="\u2190 Back",Object.assign(t.style,{..._("outlined"),background:g.menuBg,color:g.label}),O(t),t.addEventListener("click",e),t}export function renderEmptyState(e,o,t){const i=e.ownerDocument.createElement("div");i.textContent=o,Object.assign(i.style,{color:g.label,fontSize:A.body,padding:"8px 0"}),t&&Object.assign(i.style,t),e.appendChild(i)}export function makeListSelect(e,o,t,i={}){const{maxWidth:n="200px",ownerDocument:r=document,ariaLabel:l,emptyText:s,searchPlaceholder:a="Filter\u2026",hook:d}=i;let c=o;const u=h=>e.find(M=>M.value===h)?.label??"",p=r.createElement("button");p.type="button",d&&(p.dataset.wmapSelect=d),l&&p.setAttribute("aria-label",l),Object.assign(p.style,{fontSize:A.body,padding:`${v.xxs} ${v.sm}`,background:g.menuBg,color:g.text,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,maxWidth:n,textAlign:"left",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:v.sm,justifyContent:"space-between"}),O(p),W(p,!1);const f=r.createElement("span");Object.assign(f.style,{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const x=r.createElement("span");x.textContent="\u25BE",x.style.flex="0 0 auto",p.append(f,x);const b=()=>{f.textContent=e.length===0?s??"(none)":u(c)||s||"(none)"};if(b(),e.length===0)return p.disabled=!0,p.style.opacity="0.6",p.style.cursor="default",Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}});let m=null;const C=()=>{m&&(m.remove(),m=null,W(p,!1))},y=()=>{C(),p.focus()};function S(){const h=p.getBoundingClientRect(),M=r.defaultView??window,E=Math.max(h.width,220),N=Math.min(h.left,Math.max(4,(M.innerWidth??1/0)-E-4));m=r.createElement("div"),m.setAttribute("role","listbox"),m.setAttribute("aria-label",l??"Options"),Object.assign(m.style,{position:"fixed",top:`${h.bottom+4}px`,left:`${N}px`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:$.control,boxShadow:G.menu,zIndex:le,minWidth:`${E}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"});const B=[],H=()=>B.filter(w=>w.row.style.display!=="none").map(w=>w.row),F=[],ie=()=>{for(const w of F)w.el.style.display=B.slice(w.first,w.last+1).some(k=>k.row.style.display!=="none")?"":"none"};if(e.length>X){const w=ce(k=>{for(const L of B)L.row.style.display=L.label.includes(k)?"":"none";ie()},a,r,H);Object.assign(w.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),w.addEventListener("keydown",k=>{if(k.key==="Escape"){k.preventDefault(),y();return}k.key==="ArrowDown"&&(k.preventDefault(),H()[0]?.focus())}),m.appendChild(w)}let V;for(const w of e){if(w.group!==void 0&&w.group!==V){const R=r.createElement("div");R.textContent=w.group,R.setAttribute("role","presentation"),Object.assign(R.style,{padding:`${v.sm} ${v.xl} ${v.xxs}`,fontSize:A.sub,color:g.label,fontWeight:"600"}),m.appendChild(R),F.push({el:R,first:B.length,last:B.length})}V=w.group;const k=w.value===c,L=r.createElement("div");L.textContent=w.disabled?`${w.label} \u2014 ${w.disabled}`:w.label,L.setAttribute("role","option"),L.setAttribute("aria-selected",k?"true":"false"),w.disabled&&L.setAttribute("aria-disabled","true"),L.tabIndex=-1,Object.assign(L.style,{padding:`${v.sm} ${v.xl}`,fontSize:A.body,cursor:w.disabled?"default":"pointer",color:w.disabled?g.label:k?g.iconActive:g.text,fontWeight:k?"700":"400",opacity:w.disabled?"0.7":"",background:k?g.menuActive:"transparent",whiteSpace:"nowrap"}),L.addEventListener("mouseenter",()=>{!k&&!w.disabled&&(L.style.background=g.menuHover)}),L.addEventListener("mouseleave",()=>{k||(L.style.background="transparent")}),L.addEventListener("click",R=>{R.stopPropagation(),!w.disabled&&(c=w.value,b(),y(),t(w.value))}),m.appendChild(L),B.push({row:L,label:w.label.toLowerCase()}),F.length&&(F[F.length-1].last=B.length-1)}if(ae(m,H,y),se(p).appendChild(m),W(p,!0),e.length<=X){const w=e.findIndex(k=>k.value===c);H()[w>=0?w:0]?.focus()}}p.addEventListener("click",h=>{if(h.stopPropagation(),m){C();return}S()});const T=h=>{if(!p.isConnected){r.removeEventListener("click",T);return}m&&!m.contains(h.target)&&!p.contains(h.target)&&C()};return r.addEventListener("click",T),Object.defineProperty(p,"value",{get:()=>c,set:h=>{c=h,b()}})}export function testOptionLabels(e){const o=e.some(t=>t.derived);return e.map(t=>(o&&!t.derived?ye:"")+be(t,t.testNumber))}export function makeTestSelect(e,o,t,i={}){const{maxWidth:n="200px",emptyText:r="No parametric tests",ownerDocument:l=document}=i;return makeListSelect(testOptionLabels(e).map((s,a)=>({value:String(e[a].testNumber),label:s})),o!==null?String(o):"",s=>t(Number(s)),{maxWidth:n,ownerDocument:l,ariaLabel:"Test",emptyText:r,searchPlaceholder:"Filter tests\u2026"})}export function makeLinkedAxisPrefs(e,o,t,i=document){let n=o?.includeLimits,r=o?.clipOutliers??!1,l=o?.limits??"both";const s=()=>t({includeLimits:n,clipOutliers:r,limits:l});return{get:()=>({includeLimits:n,clipOutliers:r,limits:l}),sync(a,d,c=!1){e.innerHTML="",c&&e.appendChild(makeLimitsSelect(l,u=>{l=u,s()},i)),d&&e.appendChild(makeToggle("Axis includes limits",a,u=>{n=u,s()},i,"Widen the axis to show every limit, even where the data sits well clear of them")),e.appendChild(makeToggle("Clip outliers",r,u=>{r=u,s()},i,"Narrow the axis so a few extreme values do not flatten the rest. Statistics still use every value"))},set(a){const d=a.limits??"both";return a.includeLimits===n&&a.clipOutliers===r&&d===l?!1:(n=a.includeLimits,r=a.clipOutliers,l=d,!0)}}}export function makeLinkedTestSelect(e,o,t,i={}){let n=o;const r=makeTestSelect(e,n,l=>{l!==n&&(n=l,t(l))},i);return{el:r,get:()=>n,set(l){return n===l||!e.some(s=>s.testNumber===l)?!1:(n=l,r.value=String(l),!0)}}}export const ALL_GROUPS="\0all";export function makeLinkedGroupSelect(e,o,t,i,n={}){let r=t;const l=c=>c??ALL_GROUPS,s=c=>c===ALL_GROUPS?null:c,a=makeLabeledSelect(o,[{value:ALL_GROUPS,label:"All groups"},...e.map(c=>({value:c,label:c}))],l(r),c=>{const u=s(c);u!==r&&(r=u,i(u))},{...n,hook:"group-scope"}),d=a.querySelector('[data-wmap-select="group-scope"]');return{el:a,get:()=>r,set(c){return r===c||c!==null&&!e.includes(c)?!1:(r=c,d&&(d.value=l(c)),!0)}}}export function makeWaferSelect(e,o,t,i={}){const{maxWidth:n="160px",allLabel:r="All wafers",ownerDocument:l=document}=i,s="\0all";return makeListSelect([{value:s,label:r},...e.map((a,d)=>({value:String(d),label:a.label??`#${d}`}))],o===null?s:String(o),a=>t(a===s?null:Number(a)),{maxWidth:n,ownerDocument:l,ariaLabel:"Wafer",searchPlaceholder:"Filter wafers\u2026"})}export function makeToggle(e,o,t,i=document,n){const r=i.createElement("label");Object.assign(r.style,{display:"inline-flex",alignItems:"center",gap:v.xs,fontSize:A.body,color:g.label,cursor:"pointer",userSelect:"none"}),O(r,"bare");const l=i.createElement("input");return l.type="checkbox",l.checked=o,l.style.cssText="margin:0;cursor:pointer;",l.addEventListener("change",()=>t(l.checked)),r.append(l,i.createTextNode(e)),n&&U(r,n),r}export function makeLabeledSelect(e,o,t,i,n={}){const{maxWidth:r="160px",hook:l,ownerDocument:s=document}=n,a=s.createElement("label");a.textContent=e,Object.assign(a.style,{color:g.label,fontSize:A.body,display:"flex",alignItems:"center",gap:v.xs});const d=makeListSelect(o,t,i,{maxWidth:r,ownerDocument:s,hook:l,ariaLabel:e.replace(/:\s*$/,"")});return a.appendChild(d),a}export function makeChartGridWrap(e=document){const o=e.createElement("div");return o.dataset.wmapChartGrid="1",Object.assign(o.style,{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(420px, 1fr))",gap:v.lg,flex:"0 0 auto"}),o}export function makeTooltip(e){const o=e.ownerDocument.createElement("div");return Object.assign(o.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"50",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",borderRadius:$.control,padding:`${v.sm} ${v.xl}`,fontSize:A.sub,fontFamily:A.family,maxWidth:"320px",whiteSpace:"normal",overflowWrap:"break-word",boxShadow:G.menu}),e.appendChild(o),o}export function attachChartTip(e,o,t,i){e.removeAttribute("title"),e.textContent?.trim()||(e.ariaLabel=i),e.addEventListener("mouseenter",n=>{t.textContent=i,t.style.display="block",positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mousemove",n=>{t.style.display==="block"&&positionChartTooltip(t,o,n.clientX,n.clientY)}),e.addEventListener("mouseleave",()=>{t.style.display="none"}),e.addEventListener("click",()=>{t.style.display="none"}),e.addEventListener("focus",()=>{t.textContent=i,t.style.display="block";const n=e.getBoundingClientRect();positionChartTooltip(t,o,n.left+n.width/2,n.bottom)}),e.addEventListener("blur",()=>{t.style.display="none"})}export function positionChartTooltip(e,o,t,i){const n=o.getBoundingClientRect(),r=14,l=4;e.style.left="0",e.style.top="0";const s=e.offsetWidth,a=e.offsetHeight;let d=t-n.left+r,c=i-n.top+r;d+s+l>n.width&&(d=t-n.left-r-s),c+a+l>n.height&&(c=i-n.top-r-a),d=Math.max(l,d),c=Math.max(l,c),e.style.left=`${d}px`,e.style.top=`${c}px`}export const LIMIT_LABEL={test:{lo:"Lo limit",hi:"Hi limit"},spec:{lo:"LSL",hi:"USL"},pat:{lo:"PAT lo",hi:"PAT hi"},whatif:{lo:"What-if lo",hi:"What-if hi"},ref:{lo:"",hi:""}},LIMIT_DASH={test:[3,3],spec:[10,4],pat:[1,3],whatif:[8,3,2,3],ref:[6,2,1,2]},LIMITS_SHOWN_OPTIONS=[{value:"both",label:"Test + spec"},{value:"test",label:"Test limits"},{value:"spec",label:"Spec limits (LSL/USL)"},{value:"none",label:"None"}];function I(e,o){const[t,i]=o==="test"?[e?.limitLow,e?.limitHigh]:o==="spec"?[e?.specLow,e?.specHigh]:o==="pat"?[e?.patLow,e?.patHigh]:o==="whatif"?[e?.whatIfLow,e?.whatIfHigh]:[void 0,void 0],n=[];return t!==void 0&&Number.isFinite(t)&&n.push({value:t,kind:o,end:"lo",label:LIMIT_LABEL[o].lo}),i!==void 0&&Number.isFinite(i)&&n.push({value:i,kind:o,end:"hi",label:LIMIT_LABEL[o].hi}),n}export function hasBothLimitKinds(e){return I(e,"test").length>0&&I(e,"spec").length>0}export function limitLines(e,o="both"){if(o==="none")return[];const t=I(e,"test"),i=I(e,"spec"),n=o==="test"?t:o==="spec"?i:[...t,...i];return[...n.length?n:[...t,...i],...I(e,"pat"),...I(e,"whatif")]}export function limitExtent(e){if(!e.length)return{};const o=e.map(t=>t.value);return{lo:me(o),hi:he(o)}}export function placeClearOf(e,o,t,i=6){const n=l=>e.some(s=>l.x0<s.x1&&l.x1>s.x0&&l.y0<s.y1&&l.y1>s.y0);let r=o;for(let l=0;l<i&&n(r);l++)r={x0:r.x0,x1:r.x1,y0:r.y0+t,y1:r.y1+t};return e.push(r),r}export function stackLabelRows(e,o=4){const t=e.map((r,l)=>({...r,i:l})).sort((r,l)=>r.start-l.start),i=[],n=new Array(e.length).fill(0);for(const r of t){let l=i.findIndex(s=>r.start>=s+o);l===-1?(l=i.length,i.push(r.end)):i[l]=r.end,n[r.i]=l}return n}export function fillTextOnHalo(e,o,t,i,n){if(n){const r=e.measureText(o),l=2,s=e.fillStyle;e.fillStyle=n,e.fillRect(t-r.actualBoundingBoxLeft-l,i-r.actualBoundingBoxAscent-l,r.actualBoundingBoxLeft+r.actualBoundingBoxRight+2*l,r.actualBoundingBoxAscent+r.actualBoundingBoxDescent+2*l),e.fillStyle=s}e.fillText(o,t,i)}export function strokeLimitLine(e,o,t,i,n,r,l){e.save(),e.strokeStyle=t,e.lineWidth=1,e.setLineDash(LIMIT_DASH[o.kind]),e.beginPath(),e.moveTo(i,n),e.lineTo(r,l),e.stroke(),e.restore()}export function makeLimitsSelect(e,o,t=document){return makeLabeledSelect("Limits:",LIMITS_SHOWN_OPTIONS,e,i=>o(i),{maxWidth:"170px",hook:"limits-shown",ownerDocument:t})}export{K as robustFence};export function shouldIncludeLimitsByDefault(e,o,t,i,n=1/3){if(t===void 0&&i===void 0||!Number.isFinite(e)||!Number.isFinite(o))return!1;const r=Math.min(e,t??e),s=Math.max(o,i??o)-r;if(s<=0)return!0;const a=o-e;return a===0?!0:a/s>=n}export function resolveAxisRange(e){const{dataMin:o,dataMax:t,limits:i=[],includeLimits:n,clipOutliers:r,values:l}=e;let s=o,a=t,d=0;if(r&&l?.length){const u=K(l);if(u){const p=Math.max(s,u.lo),f=Math.min(a,u.hi);f>p&&(d=l.filter(x=>Number.isFinite(x)&&(x<p||x>f)).length,s=p,a=f)}}if(n)for(const u of i)s=Math.min(s,u.value),a=Math.max(a,u.value);s===a&&(s-=1,a+=1);const c=[];for(const u of i)u.value<s?c.push({value:u.value,label:u.label,side:"lo"}):u.value>a&&c.push({value:u.value,label:u.label,side:"hi"});return{lo:s,hi:a,offAxis:c,clippedCount:d}}export function limitLabelSide(e,o,t,i,n,r=3){const l=n?-1:1;return(l<0?e-r-o>=t:e+r+o<=i)?l:-l}export function drawOffAxisLimits(e,o,t,i,n,r,l,s){if(!o.length)return;e.save(),e.fillStyle=n,e.font=`${D(-1)}px system-ui, sans-serif`;const a={lo:0,hi:0},d=D(-1)+2;for(const{value:c,label:u,side:p}of o){const f=a[p]++*d,x=i==="horizontal"?p==="lo"?"\u2190":"\u2192":p==="lo"?"\u2193":"\u2191",b=p==="lo"?`${x} ${u} ${r(c)}`:`${u} ${r(c)} ${x}`,m=e.measureText(b).width;if(i==="horizontal"){const C=p==="lo"?t.left+2:t.right-2-m,y={x0:C,x1:C+m,y0:t.top+2+f,y1:t.top+2+f+d},S=s?placeClearOf(s,y,d):y;e.textBaseline="top",e.textAlign=p==="lo"?"left":"right",fillTextOnHalo(e,b,p==="lo"?t.left+2:t.right-2,S.y0,l)}else{const C=p==="lo"?t.bottom-2-f-d:t.top+2+f,y={x0:t.left+4,x1:t.left+4+m,y0:C,y1:C+d},S=s?placeClearOf(s,y,p==="lo"?-d:d):y;e.textBaseline="top",e.textAlign="left",fillTextOnHalo(e,b,t.left+4,S.y0,l)}}e.restore()}
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()}