python-plotto 0.6.0__tar.gz → 0.7.0__tar.gz

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 (27) hide show
  1. {python_plotto-0.6.0/python_plotto.egg-info → python_plotto-0.7.0}/PKG-INFO +1 -1
  2. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/__init__.py +1 -1
  3. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/_assets/README.md +10 -1
  4. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/_assets/SPEC.md +59 -13
  5. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/_assets/grammar.json +20 -11
  6. python_plotto-0.7.0/plotto/_assets/plotto.js +36 -0
  7. python_plotto-0.7.0/plotto/_assets/widget.js +36 -0
  8. python_plotto-0.7.0/plotto/data.py +88 -0
  9. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/plot.py +98 -1
  10. {python_plotto-0.6.0 → python_plotto-0.7.0/python_plotto.egg-info}/PKG-INFO +1 -1
  11. {python_plotto-0.6.0 → python_plotto-0.7.0}/tests/test_builder.py +56 -0
  12. python_plotto-0.6.0/plotto/_assets/plotto.js +0 -35
  13. python_plotto-0.6.0/plotto/_assets/widget.js +0 -35
  14. python_plotto-0.6.0/plotto/data.py +0 -49
  15. {python_plotto-0.6.0 → python_plotto-0.7.0}/LICENSE +0 -0
  16. {python_plotto-0.6.0 → python_plotto-0.7.0}/README.md +0 -0
  17. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/_assets/theme.json +0 -0
  18. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/assets.py +0 -0
  19. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/output.py +0 -0
  20. {python_plotto-0.6.0 → python_plotto-0.7.0}/plotto/widget.py +0 -0
  21. {python_plotto-0.6.0 → python_plotto-0.7.0}/pyproject.toml +0 -0
  22. {python_plotto-0.6.0 → python_plotto-0.7.0}/python_plotto.egg-info/SOURCES.txt +0 -0
  23. {python_plotto-0.6.0 → python_plotto-0.7.0}/python_plotto.egg-info/dependency_links.txt +0 -0
  24. {python_plotto-0.6.0 → python_plotto-0.7.0}/python_plotto.egg-info/requires.txt +0 -0
  25. {python_plotto-0.6.0 → python_plotto-0.7.0}/python_plotto.egg-info/top_level.txt +0 -0
  26. {python_plotto-0.6.0 → python_plotto-0.7.0}/setup.cfg +0 -0
  27. {python_plotto-0.6.0 → python_plotto-0.7.0}/tests/test_output.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-plotto
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Grammar-of-graphics plots for notebooks, web pages and slides with one renderer.
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://theoradusz.github.io/plotto/
@@ -3,7 +3,7 @@
3
3
  https://github.com/theoradusz/plotto
4
4
  """
5
5
 
6
- __version__ = "0.6.0"
6
+ __version__ = "0.7.0"
7
7
 
8
8
  from .plot import Plot, plot # noqa: E402
9
9
 
@@ -70,7 +70,7 @@ draw(plot(rows, { x: "time", y: "value", color: "sensor" }).line().facet("indica
70
70
  ### Data
71
71
 
72
72
  - Use long format: one row per observation, one column per variable.
73
- - Python takes a pandas DataFrame or a list of dicts. JavaScript takes an array of row objects.
73
+ - Python takes a pandas DataFrame (also a GeoDataFrame) or a list of dicts. JavaScript takes an array of row objects. Both take a GeoJSON FeatureCollection.
74
74
  - A time-zone-aware datetime column shows its local clock time.
75
75
  - To set the order of categories, use a pandas categorical column or `x(limits=[...])`.
76
76
 
@@ -81,6 +81,15 @@ draw(plot(rows, { x: "time", y: "value", color: "sensor" }).line().facet("indica
81
81
  | Axis range | `x(limits=[0, 10])`; `y(limits=[0, None])` keeps the data bound on the `None` side |
82
82
  | Category order | `x(limits=["low", "mid", "high"])` |
83
83
  | Log axis, time labels | `y(type="log")`; `x(format="%a %H:%M")` |
84
+ | Set ticks and their text | `x(type="log", breaks=[1, 1.5, 2, 3, 5, 10])`; `y(breaks=[0, 50], labels=["none", "50"])` |
85
+ | Colors side by side in a category | `point(position="dodge")`, `segment(..., position="dodge")`: on a category x or y |
86
+ | Name lines at their ends | `line(direct=True)` with `theme(legend="none")` |
87
+ | Areas from GeoJSON or a GeoDataFrame | `plot(geojson).polygon(fill="households", tooltip="name")`; outlines only: `polygon()` |
88
+ | Classes with a stepped legend | `fill(breaks=[0, 50, 1000, 10000])`; class names: `labels=[...]`; the same for `color()` |
89
+ | Maps | `coord("geo")`: x = longitude, y = latitude, equal distance per px, degree labels; `coord("geo", scalebar=True, north=True)` |
90
+ | Distant areas in the same figure | `inset(x=[122.9, 131.4], y=[24.0, 28.6], at=[0.02, 0.6, 0.3, 0.98])` |
91
+ | Labels that do not overlap | `text(label="name", repel=True)` |
92
+ | A grid under the map (1 km intensity mesh) | `raster(data=grid, x="lon", y="lat", fill="intensity")` with `fill(breaks=...)` |
84
93
  | Category colors | `color(palette="sakura")`, or `color(values={"a": "red", "b": "#123456"})` |
85
94
  | Number colors | `color(scheme="ai")`; diverging: `color(scheme="aiaka", mid=0)` |
86
95
 
@@ -39,9 +39,11 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
39
39
  | `layers[].mapping` | Layer channels → column names |
40
40
  | `layers[].set` | Constants: channel values and options |
41
41
  | `facet` | `{wrap, free, ncol}`, `{rows, cols, free}` or `null` |
42
- | `scales` | `x`, `y`: `type`, `limits`, `format`. `color`: `values`, `palette`, `scheme`, `limits`, `mid`, `clamp`. |
43
- | `labels` | `title`, `subtitle`, `caption`, `x`, `y`, `color`. `null` removes a title. A missing key uses the first mapped column name. |
42
+ | `scales` | `x`, `y`: `type`, `limits`, `format`, `breaks`, `labels`. `color`, `fill`: `values`, `palette`, `scheme`, `limits`, `mid`, `clamp`, `breaks`, `labels`. |
43
+ | `labels` | `title`, `subtitle`, `caption`, `x`, `y`, `color`, `fill`. `null` removes a title. A missing key uses the first mapped column name. |
44
44
  | `info` | Optional. `entries`: `[key, value]` pairs in order; a value is a string, a number, a boolean or `null`. `position`: `right` or `bottom`; without it, `right`, or the place with the most room in a fixed size. |
45
+ | `coord` | Optional. `{type: "geo", scalebar?, north?}`: map coordinates, with the corners of the scale bar and the north arrow (§5) |
46
+ | `insets` | Optional. `[{x: [low, high], y: [low, high], at: [left, bottom, right, top]}]`: inset panels (§6) |
45
47
  | `theme` | `style`, `format`, and the overrides `width`, `height`, `size`, `legend` |
46
48
 
47
49
  ### Column types
@@ -51,10 +53,13 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
51
53
  | `number` | numbers | numeric dtypes | `number` |
52
54
  | `time` | wall-clock epoch ms | `datetime64`. A time-zone-aware column keeps its local clock time. | `Date` (local clock time) |
53
55
  | `string` | strings | object, string, bool (`"true"`, `"false"`), categorical (with `levels`) | any other value |
56
+ | `geometry` | GeoJSON geometries (`{type, coordinates}`) | values with `__geo_interface__` (a GeoDataFrame geometry column, shapely) or GeoJSON dicts | GeoJSON geometry objects |
54
57
 
55
58
  - Times are wall-clock times. The axis shows the clock time of the data, in every output and every time zone.
56
59
  - A float that is not an integer keeps 6 significant digits.
57
60
  - The builders send only the columns that a mapping or a facet uses.
61
+ - Geometry coordinates keep 5 decimals (about 1 m in degrees).
62
+ - `plot()` and the `data` of a layer also take a GeoJSON FeatureCollection: one row per feature, with its properties as columns and its geometry in the column `geometry`.
58
63
 
59
64
  ## 3. Builder rules
60
65
 
@@ -73,10 +78,10 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
73
78
 
74
79
  | Method | Channels | Options | Statistic | Observable Plot mark |
75
80
  |---|---|---|---|---|
76
- | `line` | x, y, color, group, tooltip | size, alpha, dash, summary | `summary` | `line`, sorted by x |
81
+ | `line` | x, y, color, group, tooltip | size, alpha, dash, summary, direct | `summary` | `line`, sorted by x; `text` for the direct labels |
77
82
  | `path` | x, y, color, group, tooltip | size, alpha, dash | – | `line`, in row order |
78
83
  | `step` | x, y, color, group, tooltip | size, alpha, dash | – | `line`, step after each point |
79
- | `point` | x, y, color, tooltip | size, alpha, jitter, summary | `summary` | `dot` |
84
+ | `point` | x, y, color, tooltip | size, alpha, jitter, summary, position | `summary`, dodge | `dot` |
80
85
  | `bar` | x, y, color, tooltip | alpha, position | stack or dodge | `barY` (category x), `rect` (number or time x, 90% of the data step) |
81
86
  | `hist` | x, color | alpha, bins, density, position | bins | `rect` |
82
87
  | `density` | x, color | size, alpha, dash | Gaussian kernel density | `areaY` + `line` |
@@ -85,12 +90,14 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
85
90
  | `smooth` | x, y, color | size, alpha, dash, method, span, band | linear fit or loess | `areaY` (band) + `line` |
86
91
  | `hline`, `vline` | y or x, color | size, alpha, dash | – | `ruleY`, `ruleX` |
87
92
  | `abline` | color | slope, intercept, size, alpha, dash | – | `line` across the x domain |
88
- | `segment` | x, y, xend, yend, color | size, alpha, dash | – | `link` |
93
+ | `segment` | x, y, xend, yend, color | size, alpha, dash, position | dodge | `link` |
89
94
  | `rect` | xmin, xmax, ymin, ymax, color, tooltip | alpha | – | `rect` |
90
95
  | `band` | xmin, xmax, ymin, ymax, color | alpha | – | `rect`. A missing bound is the panel edge. |
91
96
  | `tile` | x, y, color, tooltip | alpha | – | `cell` (two categories), `barX`/`barY` (one category), `rect` (two numbers) |
92
- | `text` | x, y, label, color | size, alpha | – | `text` |
93
- | `errorbar` | x, ymin, ymax, color | size, alpha | – | `ruleX` and two caps |
97
+ | `text` | x, y, label, color | size, alpha, repel | – | `text`; with `repel`, leader lines (`path`) |
98
+ | `errorbar` | x, ymin, ymax, color | size, alpha, position | dodge | `ruleX` and two caps |
99
+ | `polygon` | geometry, fill, color, tooltip | size, alpha | – | `geo`, through the x and y scales |
100
+ | `raster` | x, y, fill | alpha | the grid of the cells | one `image` (a PNG) in an `svg` clipped to the frame |
94
101
  | `box` | x, y, color | alpha (of the box fill, default 0.3) | Tukey box per category (`boxStats` in `stats.js`): quartiles, whiskers to the last values within 1.5 IQR, outliers | `barY` (q1 to q3, outlined in the series color), `tickY` (bold median and whisker caps), `ruleX` (whiskers), `dot` (outliers, in the series color) |
95
102
 
96
103
  | Option | Values | Meaning |
@@ -100,18 +107,25 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
100
107
  | `dash` | `solid`, `dashed`, `dotted`, `dashdot` | Line pattern |
101
108
  | `jitter` | number | Random horizontal offset, as a share of the category width or of the x step. The seed is fixed, so each output is the same. |
102
109
  | `summary` | `mean`, `median`, `min`, `max`, `sum` | One row per (x, color, group), with the summary of y |
103
- | `position` | `stack` (default), `dodge` (bar only), `overlay` | Stack: the colors add up at each x, in the legend order. Dodge: one bar per color, side by side. Overlay: each color starts at 0; fills are see-through. |
110
+ | `position` | `stack`, `dodge`, `overlay` | Bars and areas (default `stack`): the colors add up at each x, in the legend order. Dodge (bars): one bar per color, side by side. Overlay: each color starts at 0; fills are see-through. Points, segments and error bars (default `overlay`; `stack` is an error): dodge puts each color in its own slot of the category band (below). |
104
111
  | `bins` | number | About this number of bins on round values (default 30). All panels and colors use the same bins. |
105
112
  | `density` | `true`, `false` | `hist` counts divided by (rows × bin width), so the area is 1 |
106
113
  | `method` | `lm` (default), `loess` | `lm`: least squares with a 95% confidence band (Student t). `loess`: local linear fit with tricube weights, without a band. |
107
114
  | `span` | 0–1 | The share of the points in each local fit of `loess` (default 0.75) |
108
115
  | `band` | `true` (default), `false` | The confidence band of `lm` |
116
+ | `direct` | `true`, `false` (default) | The name of each line at its end (below) |
117
+ | `repel` | `true`, `false` (default) | Text labels move to a free place near their point (below) |
109
118
 
110
- - `color` maps the stroke of lines and the fill of points, bars, areas, rects, tiles and text.
119
+ - `color` maps the stroke of lines and the fill of points, bars, areas, rects, tiles and text, and the outline of polygons. `fill` maps the fill of polygons and rasters.
111
120
  - A line, path or step without `group` has one line per color value. A missing value (`null`) makes a gap.
112
121
  - A layer without columns, for example `hline(y=0)`, draws once in each panel.
113
122
  - A layer table without the facet column draws in each panel.
114
123
  - A statistic runs on the rows of each panel, after the legend filter. Bin edges do not depend on the panel.
124
+ - Dodge of `point`, `segment` and `errorbar`: the band of each category has one slot per color of the plot, in the legend order, so a color has the same place in every category, panel and layer, and the segments of a color meet its points. A color that the legend hides leaves its slot empty. The slots are along the category axis: x, else y (`errorbar` draws vertical bars, so it needs a category x). Dodge needs a category axis and a color mapped to a string column; a constant color takes the center. The caps of an error bar are 30% of the band, or 60% of a slot.
125
+ - `polygon` draws the GeoJSON `Polygon` and `MultiPolygon` geometries of a geometry column, with x as the first coordinate (longitude) and y as the second (latitude). Holes stay empty (even-odd rule). Without `geometry`, it takes the column named `geometry`. `fill` fills the areas (a column, through the fill scale, or a color); `color` is the outline. Without `fill`, it draws outlines in `muted`, 0.6 px; with `fill`, thin outlines (0.5 px) in the `background` color separate the areas. `size` is the outline width; `alpha` the opacity of the fill (or of the outline without fill). The bounding boxes of the geometries train the axis domains. A geometry column goes to `geometry` only.
126
+ - `raster` draws a regular grid of cells (one row per cell center, for example a 1 km mesh of seismic intensity) as one image of one pixel per cell, colored by the fill scale, without smoothing, under the layers after it. The grid step in x and y is the mean of the gaps between neighbouring distinct values over the number of steps that each gap spans (refined three times), so values with 6 significant digits keep their columns; a missing cell, or a `null` fill, is transparent. A value more than a quarter of a step off the grid is an error. The cell edges train the axis domains. x and y must be number or time axes. The PNG is made once per figure and a zoom moves it; Node and the browser write the same bytes.
127
+ - `text(repel=true)` places each label, in row order (put the important ones first), at the first free place around its anchor: right, upper right, lower right, left, upper left, lower left, above, below (0.4 em beside, 0.2 em above or below, beyond a point drawn there), then on rings 0.5 em apart, up to 10 em. A place is free when the label is inside the panel and clear of the labels placed before, of the anchors, of the points of the `point` layers of the panel, of the insets and of the scale bar and north arrow. When no place is free, the label goes to the right of its anchor anyway. A label further than 1.5 em from its anchor gets a thin leader line in `muted`. The placement uses the font metrics (the same in Node and the browser) and runs again at each zoom.
128
+ - Direct labels (`line(direct=true)`): each series (the `group` value, else the `color` value) gets its name right of its last point in view, in its color, darkened (or lightened on a dark background) to a contrast of 3:1 at least. A long name wraps to 2 lines, at most 160 px or 20% of the figure width. Labels that would overlap move apart vertically, and stay in the panel when there is room. Each panel gets a right margin for the longest name; the legend stays unless `theme(legend="none")`.
115
129
 
116
130
  ## 5. Scales
117
131
 
@@ -121,7 +135,8 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
121
135
  - The axis domain trains on the layer views, which include the statistics. For example, it includes the 0 of a bar and the top of a stack.
122
136
  - The first view is `limits` when it is set. A `null` bound keeps the data bound on that side, with its 5% space. Without limits, the first view is the data range plus 5% on each side.
123
137
  - A category axis shows the categories in the `limits` order, then in the `levels` order, then in natural sort order. A label that is too wide for its band wraps at its spaces, to 3 lines at most. If a word is still too wide, all labels rotate by 40°; a rotated label gets 60% of the panel height (at least 10 em) and ends with an ellipsis beyond it, and the left margin grows so that the first one is not cut off.
124
- - Continuous axes have major ticks and minor grid lines at the midpoints. A log axis has ticks at the powers of ten, with minor lines at 2–9 times each power.
138
+ - Continuous axes have major ticks and minor grid lines at the midpoints. A log axis has ticks at the powers of ten, with minor lines at 2–9 times each power; with fewer than three powers of ten in view, it has ticks at 1, 2 and 5 times each power.
139
+ - `breaks` (a list of numbers or times) sets the major ticks of a number, log or time axis, with no minor grid lines; a zoom keeps them, and a break outside the view does not show. `labels` (strings, one per break) are the tick labels; without them, the label is `format`, or `~g` (log), `,~r` (linear) or the time pattern. Breaks on a category axis are an error.
125
140
  - Time labels are on one line. The pattern follows the tick step: `%Y-%m`, `%m-%d`, `%m-%d %H:%M` (more than one day in view), `%H:%M` or `%H:%M:%S`. `format`, a d3-format or d3-time-format string, replaces it.
126
141
 
127
142
  ### Color
@@ -130,15 +145,42 @@ builder → spec → normalize (spec.js) → views (views.js, stats.js) → scal
130
145
  |---|---|---|
131
146
  | `string` | One color per category: `values` (a list, or a map category → color), else `palette`, else the style palette, in order | Swatches: a square for fills, a line for lines, a point for points |
132
147
  | `number`, `time` | `values` (a list of colors), else `scheme`, else the style scheme | A color ramp |
148
+ | `number`, `time`, with `breaks` | One color per class: `values` (a list of one color per break), else the scheme at the middle of each class | Steps: one box per class |
133
149
 
150
+ There are two color scales: `color` (`color()`, the `color` channel) and `fill` (`fill()`, the `fill` channel of `polygon` and `raster`). They have the same options, each its own legend, and they can map different columns: for example the outage of each area (`fill`) and the class of each town (`color`).
151
+
152
+ - `breaks` (numbers or times that increase) make a binned scale. The classes are `[b0, b1)`, …, `[b(n-1), bn)` and `[bn, ∞)`: one class per break, closed on the left. They depend on the breaks only, so two plots with the same breaks have the same colors. A value below `b0` is `muted` (with `clamp: true`, the first class) and has no legend entry; `null` is `muted`. `labels` (one per break) names the classes. `mid` and a map of `values` do not apply. Breaks on a string column are an error.
153
+ - The steps legend has one box per class, low to high: left to right at the bottom, bottom to top on the right. The break values (format `,~r`, or the time pattern) are at the lower edge of each box; class names (`labels`) are on the boxes.
134
154
  - `limits` sets the categories (and their order) or the range of the color scale. A `null` bound keeps the data bound.
135
155
  - `mid` makes a diverging scale: `mid` takes the center color of the scheme, and each side stretches to its limit.
136
156
  - A list of colors and a plotto scheme interpolate in Lab space. A d3 scheme name (such as `viridis` or `blues`) uses the d3 interpolator.
137
157
  - A continuous value outside the domain is `muted`. `clamp: true` gives it the end color.
138
- - All color mappings of one plot must use the same column.
158
+ - All the color mappings of one scale must use the same column.
159
+ - A plot with mappings on both scales stacks the two legends (color first), at the right or at the bottom. The fill legend does not toggle values.
139
160
  - A long legend wraps into columns.
161
+ - A horizontal color ramp has fewer ticks when their labels would touch.
140
162
  - A right legend keeps a narrow column (20% of the width, 110 to 200 px): a long label wraps to 3 lines at most, then ends with an ellipsis, and its full text is its SVG title. A bottom legend has one line per label.
141
163
 
164
+ ### Map coordinates
165
+
166
+ `coord("geo")` makes x the longitude and y the latitude, in degrees, at the same distance per px in x and y.
167
+
168
+ - One degree of longitude is `cos φ` degrees of latitude, at the center latitude φ of the view. This is exact for a region and about 10% off east-west at the edges of a map of all Japan (no projection).
169
+ - The panels take the shape of the map (the median shape when the panels have their own extent), unless `theme(aspect=)` sets it. Each panel then grows its extent in x or in y, around its center, to fill its box. `limits` is the area that must show; one side can grow.
170
+ - The stored view does not change: zoom, pan, reset, a resize and "Copy for a slide" draw it at equal scale again.
171
+ - Tick labels are in degrees: `135°E`, `35°N` (W and S for negative values), unless `format` is set. There are no axis titles unless `labels()` sets them.
172
+ - x and y must be number axes (not log, time or category), and `facet(free=)` must be `both` or unset.
173
+ - `coord("geo", scalebar=, north=)`: `true` or a corner (`bottom-left`, `bottom-right`, `top-left`, `top-right`). `scalebar=true` is at the bottom left, `north=true` at the top right, 0.8 em inside the frame of each main panel (not the insets). The scale bar is a round length (1, 2 or 5 × 10^k km) near a fifth of the panel width, at 111.32 km × cos φ per degree of longitude, with its length as text above it; it follows the zoom. The north arrow points up.
174
+
175
+ ### Insets
176
+
177
+ `inset(x=[low, high], y=[low, high], at=[left, bottom, right, top])` draws the extent x × y in a box of each panel; `at` is in shares of the panel, from its bottom left. For example the Okinawa islands, the Izu and Ogasawara islands, or eastern Hokkaido on a map of Japan, so that no point is left out of the main extent. Each call adds one inset.
178
+
179
+ - An inset draws the layers of its panel (with the rows of that panel), on the `background` color, with a frame in `tick` and without axes and grid lines. It covers the panel under it.
180
+ - In map coordinates, the extent grows on one side to fill the box at the same distance per px in x and y.
181
+ - An inset keeps its extent: zoom, pan and the zoom buttons apply to the main panels only. Hover and pinned labels work in insets.
182
+ - Insets need number or time axes.
183
+
142
184
  ## 6. Facets
143
185
 
144
186
  | Call | Panels | Strips |
@@ -201,7 +243,7 @@ A style can also list theme color names as its palette: the `paper` and `dark` s
201
243
  - A bottom legend has its title on its first row, before the items.
202
244
  - A format with `shrink` makes the facet strip text smaller (the same size for all strips) before it cuts a label, down to that share of its size.
203
245
  - `aspect` is the shape of each panel, height / width: `1` gives square panels (for observed-against-predicted plots, with the same `limits` on x and y). The panels shrink in one direction to get that shape. A `screen` plot without `height` changes its height instead (at most 1.2 times its usual height), so the panels fill it. The space that is left goes half on each side of the panels.
204
- - The title and the subtitle align left with the panels and wrap to two lines at most. A format with `shrink` first makes a long title or subtitle smaller, down to that share of its size, so that it stays on one line; one that does not fit even then keeps its size and wraps. A `screen` plot keeps room on the right for the toolbar; a fixed size uses the full width. The caption is at the bottom left.
246
+ - The title and the subtitle align left with the panels and wrap to two lines at most. A format with `shrink` first makes a long title or subtitle smaller, down to that share of its size, so that it stays on one line; one that does not fit even then keeps its size and wraps. A `screen` plot keeps room on the right for the toolbar; a fixed size uses the full width. The caption is at the bottom left, aligned with the panels: it wraps at the width of the figure less the y axis, to 4 lines at most (a longer one ends with an ellipsis), and starts further left only when it would run off the figure.
205
247
  - A bottom info table puts its entries in up to 3 columns, as many as fit on one line each; else one column whose values wrap.
206
248
  - `src/metrics.js` holds the glyph widths of each style font for the layout. CJK characters are one em wide.
207
249
 
@@ -253,6 +295,8 @@ Hover:
253
295
  | bar, hist | The column nearest the pointer: one row per color, the segment under the pointer in bold, and the total of a stack | Outline of the segment |
254
296
  | box | The box under the pointer: whiskers, quartiles, median, count and outliers. It wins over the points drawn with it. | – |
255
297
  | tile | The value of the cell, and its x and y | Outline of the cell |
298
+ | polygon | The area under the pointer (the top one): its tooltip value as the header, and its fill and color values. A point near the pointer wins. | – |
299
+ | raster | The cell under the pointer: its fill value as the header, and its x and y | – |
256
300
  | point, path, errorbar | The nearest point within 40 px. It stays picked until another point is at least 4 px nearer. | Dot |
257
301
 
258
302
  - The label box is flat and square. Its header has the color of the hovered series. A light color gets dark text; any other color gets white text, on the color darkened until the contrast is at least 4:1. On several series, the header is dark and each row has a color swatch.
@@ -279,7 +323,9 @@ The Node SVG and the browser SVG are the same, except for the numbers of the cli
279
323
  ## 10. Limits
280
324
 
281
325
  - Themes are styles and formats with four overrides. There is no `element_*` theming.
282
- - There is one color scale per plot. Size and shape are constants, not mappings.
326
+ - There are two color scales per plot: `color` and `fill`. Size and shape are constants, not mappings.
327
+ - A raster has one row per cell in the spec (about 30 bytes per cell) and an image of 4 bytes per cell, without compression: crop the grid to the map (90 000 cells make a spec of about 3 MB).
328
+ - A geometry column is JSON in the spec and in the notebook HTML: simplify the geometries first (for example `GeoSeries.simplify` or mapshaper). Each zoom and pan draws every area again.
283
329
  - There is no plot composition.
284
330
  - More than about 20 000 points make a large SVG: the SVG of 20 000 points is about 1.7 MB.
285
331
  - A saved SVG uses the fonts of the viewer. Without the style font, the text has other widths.
@@ -12,13 +12,15 @@
12
12
  "density": "boolean",
13
13
  "method": ["lm", "loess"],
14
14
  "span": "number",
15
- "band": "boolean"
15
+ "band": "boolean",
16
+ "direct": "boolean",
17
+ "repel": "boolean"
16
18
  },
17
19
  "layers": {
18
- "line": { "channels": ["x", "y", "color", "group", "tooltip"], "options": ["size", "alpha", "dash", "summary"], "requires": ["x", "y"] },
20
+ "line": { "channels": ["x", "y", "color", "group", "tooltip"], "options": ["size", "alpha", "dash", "summary", "direct"], "requires": ["x", "y"] },
19
21
  "path": { "channels": ["x", "y", "color", "group", "tooltip"], "options": ["size", "alpha", "dash"], "requires": ["x", "y"] },
20
22
  "step": { "channels": ["x", "y", "color", "group", "tooltip"], "options": ["size", "alpha", "dash"], "requires": ["x", "y"] },
21
- "point": { "channels": ["x", "y", "color", "tooltip"], "options": ["size", "alpha", "jitter", "summary"], "requires": ["x", "y"] },
23
+ "point": { "channels": ["x", "y", "color", "tooltip"], "options": ["size", "alpha", "jitter", "summary", "position"], "requires": ["x", "y"] },
22
24
  "bar": { "channels": ["x", "y", "color", "tooltip"], "options": ["alpha", "position"], "requires": ["x", "y"] },
23
25
  "hist": { "channels": ["x", "color"], "options": ["alpha", "bins", "density", "position"], "requires": ["x"] },
24
26
  "density": { "channels": ["x", "color"], "options": ["size", "alpha", "dash"], "requires": ["x"] },
@@ -28,24 +30,31 @@
28
30
  "hline": { "channels": ["y", "color"], "options": ["size", "alpha", "dash"], "requires": ["y"], "inherit": false },
29
31
  "vline": { "channels": ["x", "color"], "options": ["size", "alpha", "dash"], "requires": ["x"], "inherit": false },
30
32
  "abline": { "channels": ["color"], "options": ["slope", "intercept", "size", "alpha", "dash"], "requires": [], "inherit": false },
31
- "segment": { "channels": ["x", "y", "xend", "yend", "color"], "options": ["size", "alpha", "dash"], "requires": ["x", "y", "xend", "yend"] },
33
+ "segment": { "channels": ["x", "y", "xend", "yend", "color"], "options": ["size", "alpha", "dash", "position"], "requires": ["x", "y", "xend", "yend"] },
32
34
  "rect": { "channels": ["xmin", "xmax", "ymin", "ymax", "color", "tooltip"], "options": ["alpha"], "requires": ["xmin", "xmax", "ymin", "ymax"] },
33
35
  "band": { "channels": ["xmin", "xmax", "ymin", "ymax", "color"], "options": ["alpha"], "requires": [], "inherit": false },
34
36
  "tile": { "channels": ["x", "y", "color", "tooltip"], "options": ["alpha"], "requires": ["x", "y", "color"] },
35
- "text": { "channels": ["x", "y", "label", "color"], "options": ["size", "alpha"], "requires": ["x", "y", "label"] },
36
- "errorbar": { "channels": ["x", "ymin", "ymax", "color"], "options": ["size", "alpha"], "requires": ["x", "ymin", "ymax"] },
37
- "box": { "channels": ["x", "y", "color"], "options": ["alpha"], "requires": ["x", "y"] }
37
+ "text": { "channels": ["x", "y", "label", "color"], "options": ["size", "alpha", "repel"], "requires": ["x", "y", "label"] },
38
+ "errorbar": { "channels": ["x", "ymin", "ymax", "color"], "options": ["size", "alpha", "position"], "requires": ["x", "ymin", "ymax"] },
39
+ "box": { "channels": ["x", "y", "color"], "options": ["alpha"], "requires": ["x", "y"] },
40
+ "polygon": { "channels": ["geometry", "fill", "color", "tooltip"], "options": ["size", "alpha"], "requires": ["geometry"] },
41
+ "raster": { "channels": ["x", "y", "fill"], "options": ["alpha"], "requires": ["x", "y", "fill"] }
38
42
  },
39
43
  "scales": {
40
- "x": ["type", "limits", "format"],
41
- "y": ["type", "limits", "format"],
42
- "color": ["values", "palette", "scheme", "limits", "mid", "clamp"]
44
+ "x": ["type", "limits", "format", "breaks", "labels"],
45
+ "y": ["type", "limits", "format", "breaks", "labels"],
46
+ "color": ["values", "palette", "scheme", "limits", "mid", "clamp", "breaks", "labels"],
47
+ "fill": ["values", "palette", "scheme", "limits", "mid", "clamp", "breaks", "labels"]
43
48
  },
44
49
  "scaleTypes": ["linear", "log", "time", "category"],
45
50
  "facet": ["free", "ncol"],
46
51
  "grid": ["free"],
47
52
  "free": ["x", "y", "both"],
48
- "labels": ["title", "subtitle", "x", "y", "color", "caption"],
53
+ "labels": ["title", "subtitle", "x", "y", "color", "fill", "caption"],
54
+ "coord": ["geo"],
55
+ "coordOptions": ["scalebar", "north"],
56
+ "corners": ["bottom-left", "bottom-right", "top-left", "top-right"],
57
+ "inset": ["x", "y", "at"],
49
58
  "theme": ["format", "width", "height", "size", "legend", "aspect"],
50
59
  "legend": ["right", "bottom", "none"],
51
60
  "info": ["position"],
@@ -0,0 +1,36 @@
1
+ var j={options:{size:"number",alpha:"number",dash:["solid","dashed","dotted","dashdot"],jitter:"number",summary:["mean","median","min","max","sum"],slope:"number",intercept:"number",position:["stack","dodge","overlay"],bins:"number",density:"boolean",method:["lm","loess"],span:"number",band:"boolean",direct:"boolean",repel:"boolean"},layers:{line:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash","summary","direct"],requires:["x","y"]},path:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},step:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},point:{channels:["x","y","color","tooltip"],options:["size","alpha","jitter","summary","position"],requires:["x","y"]},bar:{channels:["x","y","color","tooltip"],options:["alpha","position"],requires:["x","y"]},hist:{channels:["x","color"],options:["alpha","bins","density","position"],requires:["x"]},density:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"]},area:{channels:["x","y","color","group"],options:["alpha","position"],requires:["x","y"]},ribbon:{channels:["x","ymin","ymax","color","group"],options:["alpha"],requires:["x","ymin","ymax"]},smooth:{channels:["x","y","color"],options:["size","alpha","dash","method","span","band"],requires:["x","y"]},hline:{channels:["y","color"],options:["size","alpha","dash"],requires:["y"],inherit:!1},vline:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"],inherit:!1},abline:{channels:["color"],options:["slope","intercept","size","alpha","dash"],requires:[],inherit:!1},segment:{channels:["x","y","xend","yend","color"],options:["size","alpha","dash","position"],requires:["x","y","xend","yend"]},rect:{channels:["xmin","xmax","ymin","ymax","color","tooltip"],options:["alpha"],requires:["xmin","xmax","ymin","ymax"]},band:{channels:["xmin","xmax","ymin","ymax","color"],options:["alpha"],requires:[],inherit:!1},tile:{channels:["x","y","color","tooltip"],options:["alpha"],requires:["x","y","color"]},text:{channels:["x","y","label","color"],options:["size","alpha","repel"],requires:["x","y","label"]},errorbar:{channels:["x","ymin","ymax","color"],options:["size","alpha","position"],requires:["x","ymin","ymax"]},box:{channels:["x","y","color"],options:["alpha"],requires:["x","y"]},polygon:{channels:["geometry","fill","color","tooltip"],options:["size","alpha"],requires:["geometry"]},raster:{channels:["x","y","fill"],options:["alpha"],requires:["x","y","fill"]}},scales:{x:["type","limits","format","breaks","labels"],y:["type","limits","format","breaks","labels"],color:["values","palette","scheme","limits","mid","clamp","breaks","labels"],fill:["values","palette","scheme","limits","mid","clamp","breaks","labels"]},scaleTypes:["linear","log","time","category"],facet:["free","ncol"],grid:["free"],free:["x","y","both"],labels:["title","subtitle","x","y","color","fill","caption"],coord:["geo"],coordOptions:["scalebar","north"],corners:["bottom-left","bottom-right","top-left","top-right"],inset:["x","y","at"],theme:["format","width","height","size","legend","aspect"],legend:["right","bottom","none"],info:["position"],infoPosition:["right","bottom"]};var Y={styles:{pastel:{font:"Helvetica, Arial, 'Liberation Sans', sans-serif",metrics:"arial",background:"#FFFEFB",ink:"#3A3631",muted:"#7A736A",grid:"#ECE8E1",gridMinor:"#F6F3EE",tick:"#D6D0C6",strip:"#F4F0E9",accent:"#3E8A99",palette:"pastel",scheme:"ai",colors:{blue:"#7AA6DA",orange:"#EF977F",green:"#7DB89A",purple:"#A79BD6",pink:"#E48FAE",yellow:"#DDB459",teal:"#63B7C1",red:"#CF7468",brown:"#BB9C84",gray:"#97A1AD"},weight:1.25},wota:{font:"'M PLUS 1p', sans-serif",metrics:"mplus",ink:"#333333",muted:"#666666",grid:"#D9D9D9",gridMinor:"#EFEFEF",tick:"#BBBBBB",strip:"#EEF1FA",accent:"#5C6BC0",palette:"wota",scheme:"sakura",colors:{pink:"#E4007F",blue:"#5C6BC0",teal:"#00A3A3",orange:"#F5A623",purple:"#8E44AD",gray:"#7F7F7F",green:"#3BA55C",red:"#D7263D",yellow:"#F2C14E",brown:"#8D6E63"},weight:1,background:"#FFFFFF"},paper:{ink:"#000000",muted:"#333333",grid:"#E6E6E6",gridMinor:"#F5F5F5",tick:"#8C8C8C",strip:"#EBEBEB",accent:"#0072B2",palette:["blue","orange","green","pink","yellow","teal","red","brown","purple","gray"],scheme:"viridis",colors:{blue:"#0072B2",orange:"#E69F00",green:"#009E73",pink:"#CC79A7",yellow:"#F0E442",teal:"#56B4E9",red:"#D55E00",brown:"#8C6D31",purple:"#6A3D9A",gray:"#7F7F7F"},weight:1,background:"#FFFFFF"},dark:{background:"#16181D",ink:"#E8EAED",muted:"#A6ABB3",grid:"#2E323A",gridMinor:"#22252B",tick:"#4F5560",strip:"#252933",accent:"#8AB4F8",palette:["blue","orange","green","purple","pink","yellow","teal","red","brown","gray"],scheme:"yuhi",colors:{blue:"#8AB4F8",orange:"#FBA94C",green:"#81C995",purple:"#C58AF9",pink:"#FF8BCB",yellow:"#FDD663",teal:"#78D9D3",red:"#F28B82",brown:"#C8A27A",gray:"#9AA0A6"},weight:1.15}},palettes:{pastel:["#7AA6DA","#EF977F","#7DB89A","#A79BD6","#E48FAE","#DDB459","#63B7C1","#CF7468","#BB9C84","#97A1AD"],wota:["#E4007F","#5C6BC0","#00A3A3","#F5A623","#8E44AD","#7F7F7F","#3BA55C","#D7263D","#F2C14E","#8D6E63"],sakura:["#E16B8C","#5DAC81","#8B81C3","#FFB11B","#7DB9DE","#F596AA","#B9887D","#91AD70"],aizome:["#0F2540","#51A8DD","#66BAB7","#656765","#0D5661","#A5DEE4","#7B90D2"],momiji:["#CB4042","#FFB11B","#6C6A2D","#6D2E5B","#ED784A","#734338","#C99833"],tableau:["#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC"]},schemes:{ai:["#F4F8F8","#A5DEE4","#33A6B8","#0D5661","#0F2540"],sakura:["#FEF4F4","#FEDFE1","#F596AA","#D05A6E","#8E354A","#4A1D30"],matcha:["#F8F6E3","#D7E3B5","#91AD70","#5DAC81","#1B813E","#0B3B2A"],yuhi:["#FFF3D6","#FFB11B","#ED784A","#CB4042","#6D2E5B","#26113A"],sumi:["#FCFAF2","#BDC0BA","#828282","#434343","#1C1C1C"],aiaka:["#0F2540","#33A6B8","#A5DEE4","#F7F6F0","#F4A7A0","#CB4042","#5C1A1B"]},formats:{screen:{width:900,height:500,size:12,line:1.5,point:2.5,reflow:!0},report:{width:640,height:400,size:10,line:1.2,point:2,reflow:!1},slide:{width:691,height:403,size:13,shrink:.8,line:1.6,point:2.7,pad:.3,flat:.55,legend:"bottom",reflow:!1}}};var Ze=j.layers,Ve=[...new Set(Object.values(Ze).flatMap(t=>t.channels))],ko=["point","segment","errorbar"];function Qe(t,e={}){let n=[tn(t,"plot()")];for(let[o,r]of Object.entries(e))Ve.includes(o)||st("plot()","channel",o,Ve),xe(n[0],r,"plot()");return new ye({data:n,mapping:e,layers:[],facet:null,scales:{},labels:{},info:null,coord:null,insets:[],theme:{style:"pastel"}})}var ye=class t{#e;constructor(e){this.#e=e}#n(e){return new t({...this.#e,...e})}#t(e,n={}){let o=Ze[e],r=`${e}()`,{data:s,...l}=n,i=this.#e.data,a=0;s!==void 0&&(i=[...i,tn(s,r)],a=i.length-1);let u=i[a].columns,c={type:e,mapping:{},set:{}};a&&(c.data=a);for(let[p,f]of Object.entries(l))o.channels.includes(p)&&typeof f=="string"&&f in u?c.mapping[p]=f:o.channels.includes(p)||o.options.includes(p)?c.set[p]=Eo(p,f,r,u):st(r,"option",p,["data",...o.channels,...o.options]);if(c.set.position==="stack"&&ko.includes(e))throw new Error(`${r}: position must be overlay or dodge`);return e==="polygon"&&!c.mapping.geometry&&!(this.#e.mapping.geometry in u)&&"geometry"in u&&(c.mapping.geometry="geometry"),this.#n({data:i,layers:[...this.#e.layers,c]})}line(e){return this.#t("line",e)}step(e){return this.#t("step",e)}bar(e){return this.#t("bar",e)}hist(e){return this.#t("hist",e)}density(e){return this.#t("density",e)}area(e){return this.#t("area",e)}ribbon(e){return this.#t("ribbon",e)}smooth(e){return this.#t("smooth",e)}path(e){return this.#t("path",e)}point(e){return this.#t("point",e)}hline(e){return this.#t("hline",e)}vline(e){return this.#t("vline",e)}abline(e){return this.#t("abline",e)}segment(e){return this.#t("segment",e)}rect(e){return this.#t("rect",e)}band(e){return this.#t("band",e)}tile(e){return this.#t("tile",e)}text(e){return this.#t("text",e)}errorbar(e){return this.#t("errorbar",e)}box(e){return this.#t("box",e)}polygon(e){return this.#t("polygon",e)}raster(e){return this.#t("raster",e)}facet(e,n={}){return xe(this.#e.data[0],e,"facet()"),$t(n,j.facet,"facet()"),Je(n.free,"facet()"),this.#n({facet:{wrap:e,free:n.free??null,ncol:n.ncol??null}})}grid({rows:e=null,cols:n=null,...o}={}){if(e===null&&n===null)throw new Error("grid(): set rows, cols or both");for(let r of[e,n])r!==null&&xe(this.#e.data[0],r,"grid()");return $t(o,j.grid,"grid()"),Je(o.free,"grid()"),this.#n({facet:{rows:e,cols:n,free:o.free??null}})}x(e){return this.#o("x",e)}y(e){return this.#o("y",e)}color(e){return this.#o("color",e)}fill(e){return this.#o("fill",e)}#o(e,n={}){let o=`${e}()`;if($t(n,j.scales[e],o),n.type!==void 0&&!j.scaleTypes.includes(n.type)&&st(o,"type",n.type,j.scaleTypes),n.palette!==void 0&&!Array.isArray(n.palette)&&!(n.palette in Y.palettes)&&st(o,"palette",n.palette,Object.keys(Y.palettes)),n.mid!==void 0&&typeof n.mid!="number")throw new Error(`${o}: mid must be a number`);let r={...n};if(r.limits){if(!Array.isArray(r.limits))throw new Error(`${o}: limits must be a list, for example [0, 10] or [0, null]`);r.limits=r.limits.map(s=>s==null?null:Ct(s))}if(r.breaks!==void 0){if(!Array.isArray(r.breaks)||!r.breaks.every(s=>typeof s=="number"||s instanceof Date))throw new Error(`${o}: breaks must be a list of numbers or dates, for example [1, 2, 5, 10]`);r.breaks=r.breaks.map(Ct)}if(r.labels!==void 0){if(r.breaks===void 0)throw new Error(`${o}: labels need breaks: one label per break`);if(!Array.isArray(r.labels)||r.labels.length!==r.breaks.length||!r.labels.every(s=>typeof s=="string"))throw new Error(`${o}: labels must have one entry per break, as strings`)}return r.breaks!==void 0&&(e==="color"||e==="fill")&&So(r,o),this.#n({scales:{...this.#e.scales,[e]:r}})}coord(e,n={}){j.coord.includes(e)||st("coord()","type",e,j.coord),$t(n,j.coordOptions,"coord()");let o={type:e};for(let[r,s]of[["scalebar","bottom-left"],["north","top-right"]]){let l=n[r];l==null||l===!1||(l!==!0&&!j.corners.includes(l)&&st("coord()",r,l,["true",...j.corners]),o[r]=l===!0?s:l)}return this.#n({coord:o})}inset(e={}){$t(e,j.inset,"inset()");let{x:n,y:o,at:r}=e;for(let[s,l]of[["x",n],["y",o]])if(!Array.isArray(l)||l.length!==2||!l.every(i=>typeof i=="number"||i instanceof Date)||+l[0]>=+l[1])throw new Error(`inset(): ${s} must be [low, high], for example [122.9, 131.4]`);if(!Array.isArray(r)||r.length!==4||!r.every(s=>typeof s=="number"&&s>=0&&s<=1)||r[0]>=r[2]||r[1]>=r[3])throw new Error("inset(): at must be [left, bottom, right, top] as shares of the panel (0 to 1), for example [0.02, 0.6, 0.3, 0.98]");return this.#n({insets:[...this.#e.insets,{x:n.map(Ct),y:o.map(Ct),at:r.map(Ct)}]})}labels(e={}){return $t(e,j.labels,"labels()"),this.#n({labels:{...this.#e.labels,...e}})}info(e,n={}){$t(n,j.info,"info()");let{position:o}=n;if(o!==void 0&&!j.infoPosition.includes(o)&&st("info()","position",o,j.infoPosition),e==null)return this.#n({info:null});let r=Array.isArray(e)?e:typeof e=="object"?Object.entries(e):null;if(!r)throw new Error("info(): entries must be an object or a list of [key, value] pairs");return this.#n({info:{entries:r.map(s=>Ao(s)),...o?{position:o}:{}}})}theme(e="pastel",n={}){if($t(n,j.theme,"theme()"),e in Y.styles||st("theme()","style",e,Object.keys(Y.styles)),n.format!==void 0&&!(n.format in Y.formats)&&st("theme()","format",n.format,Object.keys(Y.formats)),n.legend!==void 0&&!j.legend.includes(n.legend)&&st("theme()","legend",n.legend,j.legend),n.aspect!=null&&!(typeof n.aspect=="number"&&n.aspect>0))throw new Error("theme(): aspect must be a positive number (panel height / width), for example 1 for square panels");return this.#n({theme:{style:e,...n}})}spec(){let e=this.#e,n=e.data.map(()=>new Set);for(let r of Object.values(e.mapping))n.forEach((s,l)=>r in e.data[l].columns&&s.add(r));for(let r of e.layers)for(let s of Object.values(r.mapping))n[r.data??0].add(s);for(let r of[e.facet?.wrap,e.facet?.rows,e.facet?.cols])r&&n.forEach((s,l)=>r in e.data[l].columns&&s.add(r));return{version:1,data:e.data.map((r,s)=>({columns:Object.fromEntries([...n[s]].map(l=>[l,r.columns[l]]))})),mapping:e.mapping,layers:e.layers,facet:e.facet,scales:e.scales,labels:e.labels,...e.info?{info:e.info}:{},...e.coord?{coord:e.coord}:{},...e.insets.length?{insets:e.insets}:{},theme:e.theme}}};function tn(t,e){if(t?.type==="FeatureCollection"&&Array.isArray(t.features)&&(t=t.features.map(r=>({...r.properties,geometry:r.geometry}))),!Array.isArray(t))throw new Error(`${e}: data must be an array of row objects or a GeoJSON FeatureCollection`);let n=[...new Set(t.flatMap(Object.keys))],o={};for(let r of n){let s=t.map(u=>u[r]??null),l=s.find(u=>u!==null&&!Number.isNaN(u));if(vo(l)){o[r]={type:"geometry",values:s.map(u=>u===null?null:Mo(u))};continue}let i=l instanceof Date?"time":typeof l=="number"?"number":"string",a=s.map(u=>u===null||Number.isNaN(u)?null:i==="string"?String(u):Ct(u));o[r]={type:i,values:a}}return{columns:o}}function vo(t){return typeof t=="object"&&t!==null&&typeof t.type=="string"&&Array.isArray(t.coordinates)}var Ke=1e5;function Mo({type:t,coordinates:e}){let n=o=>typeof o=="number"?Math.round(o*Ke)/Ke:o.map(n);return{type:t,coordinates:n(e)}}function Ct(t){return t instanceof Date?t.getTime()-t.getTimezoneOffset()*6e4:typeof t=="number"&&!Number.isInteger(t)?Number(t.toPrecision(6)):t}function Eo(t,e,n,o){let r=j.options[t];if(t==="tooltip"||t==="group")throw new Error(`${n}: ${t} must be a column. Columns: ${Object.keys(o).join(", ")}`);if(Array.isArray(r)&&!r.includes(e)&&st(n,t,e,r),r==="number"&&typeof e!="number")throw new Error(`${n}: ${t} must be a number`);if(r==="boolean"&&typeof e!="boolean")throw new Error(`${n}: ${t} must be true or false`);if(t==="color"||t==="fill"||t==="label")return e;if(typeof e=="string"&&!r)throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(o).join(", ")}`);return Ct(e)}function Ao(t){if(!Array.isArray(t)||t.length!==2||typeof t[0]!="string")throw new Error("info(): each entry must be a [key, value] pair with a string key");let[e,n]=t;if(n==null||typeof n=="number"&&Number.isNaN(n))return[e,null];if(!["string","number","boolean"].includes(typeof n))throw new Error(`info(): the value of "${e}" must be a string, a number, a boolean or null. Format other values as a string`);return[e,Ct(n)]}function So(t,e){if(t.breaks.some((n,o)=>o&&n<=t.breaks[o-1]))throw new Error(`${e}: breaks must increase`);if(t.mid!==void 0)throw new Error(`${e}: mid does not apply with breaks`);if(t.values!==void 0&&(!Array.isArray(t.values)||t.values.length!==t.breaks.length))throw new Error(`${e}: with breaks, values must be a list of one color per break (class)`)}function xe(t,e,n){if(!(e in t.columns))throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(t.columns).join(", ")}`)}function $t(t,e,n){for(let o of Object.keys(t))e.includes(o)||st(n,"option",o,e)}function Je(t,e){t!=null&&!j.free.includes(t)&&st(e,"free",t,j.free)}function st(t,e,n,o){throw new Error(`${t}: unknown ${e} "${n}". Valid: ${o.join(", ")}`)}import*as et from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as pt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as T from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as U from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Fo=Object.keys(Y.styles),$o=Object.keys(Y.formats),Co=Object.keys(Y.palettes),Do=Object.keys(Y.schemes),en=["ink","muted","grid","tick","strip","accent","background"];function nn({style:t="pastel",format:e="screen",legend:n,...o}={}){if(!Y.styles[t])throw new Error(`theme(): unknown style "${t}". Valid: ${Fo.join(", ")}`);if(!Y.formats[e])throw new Error(`theme(): unknown format "${e}". Valid: ${$o.join(", ")}`);let r=Y.styles.pastel,s=Y.styles[t],l=Y.formats[e],i=o.width!=null;for(let u of Object.keys(o))o[u]==null&&delete o[u];let a={...r,...s,colors:{...r.colors,...s.colors},...l,legend:n??l.legend??"right",...o,style:t,format:e};return a.reflow=l.reflow&&!i,a.line=l.line*(s.weight??r.weight??1),a.point=l.point*Math.sqrt(s.weight??r.weight??1),o.width!=null&&o.height==null&&(a.height=Math.round(o.width*l.height/l.width)),a.fixedHeight=o.height!=null,a.fitHeight=l.reflow&&!a.fixedHeight,a.fixedFormat=!l.reflow,a.pad=l.pad??.9,a.palette=ge(a,a.palette),a}function ge(t,e){let n=Array.isArray(e)?e:Y.palettes[e];if(!n)throw new Error(`color(): unknown palette "${e}". Valid: ${Co.join(", ")}`);return n.map(o=>zt(t,o)??o)}function be(t,e){let n=r=>U.piecewise(U.interpolateLab,r.map(s=>zt(t,s)??s));if(Array.isArray(e))return n(e);if(Y.schemes[e])return n(Y.schemes[e]);let o=typeof e=="string"&&U[`interpolate${e[0].toUpperCase()}${e.slice(1)}`];if(!o)throw new Error(`color(): unknown scheme "${e}". plotto schemes: ${Do.join(", ")}; or a d3 scheme such as viridis, magma, blues`);return o}function zt(t,e){if(typeof e=="string")return t.colors[e]?t.colors[e]:en.includes(e)?t[e]:U.color(e)?e:void 0}function on(t){return[...Object.keys(t.colors),...en]}function Kt(t){let e=[t.r,t.g,t.b].map(n=>(n/=255,n<=.03928?n/12.92:((n+.055)/1.055)**2.4));return .2126*e[0]+.7152*e[1]+.0722*e[2]}function rn(t,e){let n=U.rgb(e);if(!U.color(t))return t;let o=l=>{let[i,a]=[Kt(U.rgb(l)),Kt(n)];return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)},r=Kt(n)>.2?-4:4,s=U.hcl(t);for(let l=0;l<25&&o(s)<3;l++)s=U.hcl(s.h,s.c,s.l+r);return U.rgb(s).formatHex()}function we(t){let e=U.rgb(t);if(Kt(e)>.42)return{bg:e.formatHex(),fg:"#1F2328"};let n=U.hcl(e);for(let o=0;o<20&&1.05/(Kt(U.rgb(n))+.05)<4;o++)n=U.hcl(n.h,n.c,n.l-4);return{bg:U.rgb(n).formatHex(),fg:"#FFFFFF"}}function sn(t){return we(t).fg}function ke(t){let e=t.size;return{base:e,tick:e-1,title:Math.round(e*1.35),subtitle:e,strip:e-1,legend:e-1,axisTitle:e,hover:Math.max(11,e-1)}}var Jt={x:["x","xmin","xmax","xend"],y:["y","ymin","ymax","yend"]},ln=.05,ve=864e5;function Me(t,e){let n=t.scales[e]?.type;if(n)return n;for(let o of t.layers)for(let r of Jt[e]){let s=o.channels[r]?.column;if(!s)continue;let l=t.tables[o.table].columns[s].type;return l==="time"?"time":l==="string"?"category":"linear"}return"linear"}function un(t,e,n,o){let r=e.channels[n];if(!r)return;if("value"in r)return o.map(()=>r.value);let s=t.tables[e.table].columns[r.column].values;return o.map(l=>s[l])}function pn(t,e,n,o){let r=[];for(let l of o)for(let i of l.views)for(let a of Jt[e]){let u=i.cols[a];if(u)for(let c of u)c!=null&&(n==="category"||Number.isFinite(c))&&r.push(c)}if(n==="category")return Po(t,e,r);let s=T.extent(r.filter(l=>n!=="log"||l>0));return s[0]===void 0?n==="log"?[1,10]:[0,1]:fn(s,n)}function Po(t,e,n){let o=t.layers.map(s=>s.channels[e]?.column&&t.tables[s.table].columns[s.channels[e].column].levels).find(Boolean),r=new Set(n.map(String));return o?o.filter(s=>r.has(s)):[...r].sort(ee)}function ee(t,e){return String(t).localeCompare(String(e),void 0,{numeric:!0})}function fn([t,e],n){if(n==="log"){let[r,s]=fn([Math.log10(t),Math.log10(e)],"linear");return[10**r,10**s]}let o=e>t?(e-t)*ln:n==="time"?36e5:Math.abs(t)*ln||1;return[t-o,e+o]}function Dt(t,e,n,{format:o,breaks:r,labels:s,degrees:l}={}){if(r&&t==="category")throw new Error("plotto: breaks apply to number, log and time axes, not to a category axis");if(t==="category")return{major:e,minor:[],format:String};let[i,a]=e,u=p=>l&&!o?Lo(p,l):p;if(r){let p=t==="time"?r.map(d=>new Date(d)):r,f=u(t==="time"?T.utcFormat(o??cn(p,a-i)):T.format(o??(t==="log"?"~g":",~r"))),h=s&&new Map(r.map((d,m)=>[+d,s[m]]));return{major:p,minor:[],format:h?d=>h.get(+d)??f(d):f}}if(t==="time"){let p=T.scaleUtc().domain([new Date(i),new Date(a)]).ticks(n),f=o??cn(p,a-i);return{major:p,minor:an(p,e,h=>+h).map(h=>new Date(h)),format:T.utcFormat(f)}}if(t==="log"){let p=T.range(Math.ceil(Math.log10(i)),Math.floor(Math.log10(a))+1).map(d=>10**d),f=p.length>=3?p:T.scaleLog().domain(e).ticks(n).filter(d=>[1,2,5].includes(Math.round(d/10**Math.floor(Math.log10(d)+1e-9)))),h=p.flatMap(d=>T.range(2,10).map(m=>d/10*m)).filter(d=>d>i&&d<a);return{major:f,minor:h,format:T.format(o??"~g")}}let c=T.ticks(i,a,n);return{major:c,minor:an(c,e,Number),format:o?T.format(o):u(T.tickFormat(i,a,n))}}function Lo(t,e){let[n,o]=e==="lon"?["E","W"]:["N","S"];return r=>`${t(Math.abs(r))}\xB0${r>0?n:r<0?o:""}`}function dn({x:t,y:e},n,o){let r=Math.cos((e[0]+e[1])/2*Math.PI/180),s=n/((t[1]-t[0])*r),l=o/(e[1]-e[0]),i=([a,u],c)=>[(a+u)/2-c/2,(a+u)/2+c/2];return s>l?{x:i(t,n/l/r),y:e}:{x:t,y:i(e,o/s)}}function hn({x:t,y:e}){return(e[1]-e[0])/((t[1]-t[0])*Math.cos((e[0]+e[1])/2*Math.PI/180))}function an(t,[e,n],o){if(t.length<2)return[];let r=o(t[1])-o(t[0]);return[o(t[0])-r/2,...t.map(l=>o(l)+r/2)].filter(l=>l>e&&l<n)}function cn(t,e){let n=t.length>=2?t[1]-t[0]:e;return n>=28*ve?"%Y-%m":n>=ve?"%m-%d":n>=6e4?e>ve?"%m-%d %H:%M":"%H:%M":"%H:%M:%S"}var Oo=T.format(",.4~r"),mn={number:t=>t==null?"\u2013":Math.abs(t)>=1e15||t!==0&&Math.abs(t)<1e-4?T.format(".3~e")(t):Oo(t),time:T.utcFormat("%m-%d %H:%M"),string:t=>t==null?"\u2013":String(t)};function Ee(t,e="color"){let n=t.theme,o=t.scales[e]??{},r=t.layers.filter(x=>x.channels[e]?.column);if(!r.length)return{kind:"none",channel:e};let s=r[0].channels[e].column,l=r.find(x=>x.channels[e].column!==s);if(l)throw new Error(`plotto: ${e} maps "${s}" and "${l.channels[e].column}". Map ${e} to one column only`);let i=r.map(x=>t.tables[x.table].columns[s]),a=i[0].type,u=i.flatMap(x=>x.values).filter(x=>x!==null),c=x=>zt(n,x)??x;if(o.breaks&&a==="string")throw new Error(`${e}(): breaks apply to a number or time column, not to "${s}"`);if(o.breaks)return zo(n,o,{channel:e,column:s,type:a});if(a==="string"){let x=i.find(v=>v.levels)?.levels,y=new Set(u),M=o.limits??(x?x.filter(v=>y.has(v)):[...y].sort(ee)),F=o.palette?ge(n,o.palette):n.palette,k=o.values,S=Array.isArray(k)?(v,A)=>c(k[A%k.length]):k?(v,A)=>c(k[v]??F[A%F.length]):(v,A)=>F[A%F.length],E=new Map(M.map((v,A)=>[v,S(v,A)]));return{kind:"ordinal",channel:e,column:s,domain:M,apply:v=>E.get(v)??n.muted}}let[p,f]=No(o.limits,T.extent(u)),h=be(n,o.values??o.scheme??n.scheme),d=o.mid,m=x=>d===void 0?(x-p)/(f-p||1):x<d?.5*((x-p)/(d-p||1)):.5+.5*((x-d)/(f-d||1)),w=x=>x>=p&&x<=f,g=x=>x===null?n.muted:o.clamp||w(x)?h(Math.max(0,Math.min(1,m(x)))):n.muted;return{kind:"continuous",channel:e,column:s,domain:[p,f],type:a,interpolate:h,apply:g,ramp:x=>g(p+x*(f-p))}}function zo(t,e,{channel:n,column:o,type:r}){let s=e.breaks,l=s.length,i=Array.isArray(e.values)?e.values.map(c=>zt(t,c)??c):T.range(l).map(c=>be(t,e.scheme??t.scheme)((c+.5)/l)),a=c=>c==null||Number.isNaN(c)?-1:c<s[0]?e.clamp?0:-1:T.bisectRight(s,c)-1,u=c=>i[a(c)]??t.muted;return{kind:"binned",channel:n,column:o,type:r,breaks:s,labels:e.labels,colors:i,classOf:a,apply:u}}function No(t,e){return t?[t[0]??e[0],t[1]??e[1]]:e}function yn(t){let e=t.facet;if(!e)return{kind:"none",nrow:1,ncol:1,panels:[Se(t,0,0,{},{})]};if(e.kind==="wrap"){let s=Ae(t,e.by),l=e.ncol??Bo(s.length),i=s.map((a,u)=>Se(t,Math.floor(u/l),u%l,{[e.by]:a},{top:a}));return{kind:"wrap",nrow:Math.ceil(s.length/l),ncol:l,panels:i}}let n=e.rows?Ae(t,e.rows):[null],o=e.cols?Ae(t,e.cols):[null],r=[];return n.forEach((s,l)=>o.forEach((i,a)=>{let u={};e.rows&&(u[e.rows]=s),e.cols&&(u[e.cols]=i),r.push(Se(t,l,a,u,{top:l===0?i:null,right:a===o.length-1?s:null}))})),{kind:"grid",nrow:n.length,ncol:o.length,panels:r}}function Bo(t){return t<=3?t:t<=6?Math.ceil(t/2):t<=12?Math.ceil(t/3):Math.ceil(Math.sqrt(t))}function Ae(t,e){let n=t.tables[0].columns[e];return n.levels?n.levels.filter(o=>n.values.includes(o)):[...new Set(n.values.filter(o=>o!==null).map(String))].sort(ee)}function Se(t,e,n,o,r){let s=t.layers.map(l=>{let i=t.tables[l.table];if(!Object.values(l.channels).some(c=>c.column))return[0];let a=Object.entries(o).filter(([c])=>c in i.columns),u=Array.from({length:i.n},(c,p)=>p);return a.length?u.filter(c=>a.every(([p,f])=>String(i.columns[p].values[c])===f)):u});return{row:e,col:n,strips:r,rows:s}}import*as yt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var To="http://www.w3.org/2000/svg";function O(t,e,n={}){let o=t.createElementNS(To,e);for(let[r,s]of Object.entries(n))s!=null&&o.setAttribute(r,String(s));return o}function Z(t,e,n,o="text"){let r=O(t,o,n);return r.textContent=e,r}var xn={arial:{regular:[.278,.278,.355,.556,.556,.889,.667,.191,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.278,.278,.584,.584,.584,.556,1.015,.667,.667,.722,.722,.667,.611,.778,.722,.278,.5,.667,.556,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.278,.278,.278,.469,.556,.333,.556,.556,.5,.556,.556,.278,.556,.556,.222,.222,.5,.222,.833,.556,.556,.556,.556,.333,.5,.278,.556,.5,.722,.5,.5,.5,.334,.26,.334,.584],bold:[.278,.333,.474,.556,.556,.889,.722,.238,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.333,.333,.584,.584,.584,.611,.975,.722,.722,.722,.722,.667,.611,.778,.722,.278,.556,.722,.611,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.333,.278,.333,.584,.556,.333,.556,.611,.556,.611,.556,.333,.611,.611,.278,.278,.556,.278,.889,.611,.611,.611,.611,.389,.556,.333,.611,.556,.778,.556,.556,.5,.389,.28,.389,.584]},mplus:{regular:[.29,.363,.4,.678,.605,.847,.712,.237,.385,.385,.527,.733,.304,.457,.283,.507,.62,.62,.62,.62,.62,.62,.62,.62,.62,.62,.363,.384,.667,.753,.667,.611,.823,.693,.598,.695,.682,.587,.572,.745,.71,.317,.527,.633,.585,.857,.713,.793,.6,.785,.62,.573,.653,.683,.693,.953,.65,.67,.637,.47,.507,.47,.653,.583,.278,.548,.578,.522,.578,.552,.522,.573,.573,.307,.347,.562,.307,.805,.568,.57,.573,.573,.453,.497,.512,.558,.557,.81,.553,.557,.547,.513,.343,.513,.69],bold:[.304,.425,.478,.692,.625,.901,.753,.291,.426,.426,.536,.735,.351,.471,.338,.546,.64,.64,.64,.64,.64,.64,.64,.64,.64,.64,.418,.431,.681,.755,.681,.628,.818,.715,.62,.703,.696,.601,.586,.756,.735,.351,.558,.678,.6,.878,.735,.798,.628,.798,.651,.608,.668,.705,.715,.971,.678,.698,.651,.501,.546,.501,.695,.609,.336,.576,.606,.54,.606,.57,.543,.601,.605,.335,.378,.603,.335,.843,.6,.585,.601,.601,.485,.525,.533,.59,.581,.831,.585,.585,.568,.535,.381,.535,.705]}};var jo=11904;function ut(t,e,n=!1,o="arial"){let r=xn[o][n?"bold":"regular"],s=0;for(let l of String(t)){let i=l.codePointAt(0);i>=32&&i<127?s+=r[i-32]:s+=i>=jo?1:.6}return s*e}function Pt(t,e,n,o,r){if(t=String(t),ut(t,e,o,r)<=n)return t;let s=[...t];for(;s.length>1&&ut(s.join("")+"\u2026",e,o,r)>n;)s.pop();return s.join("")+"\u2026"}function mt(t,e,n,o,r,s=2){let l=String(t).split(/\s+/),i=[],a="";for(let c of l){let p=a?`${a} ${c}`:c;a&&ut(p,e,o,r)>n?(i.push(a),a=c):a=p}if(i.push(a),i.length<=s)return i;let u=i.slice(0,s);return u[s-1]=Pt(i.slice(s-1).join(" "),e,n,o,r),u}var Ho=3,Io=.45,Ro={right:.3,bottom:.9},Wo={right:.6,bottom:.3},qo=3;function gn(t,e,{W:n,H:o,narrow:r,place:s=t.info?.position}){if(!t.info)return null;let l=r?"bottom":s;return Yo(t,e,t.info.entries,l,n,o*Wo[l])}function Yo(t,e,n,o,r,s){let l=t.theme.metrics,i=e.legend,a=Math.round(i*.8),u=i*1.35,c=i,p=i*2,f=n.map(([y,M])=>({key:String(y),value:M===null?"\u2013":String(M)})),h=y=>ut(y,i,!1,l),d=(y,M)=>{let F=Math.min(yt.max(y,A=>h(A.key))??0,M*Io),k=Math.max(i*3,M-F-c),S=0,E=y.map(A=>{let P=mt(A.value,i,k,!1,l,Ho),$={key:Pt(A.key,i,F,!1,l),full:A.key,lines:P,y:S};return S+=P.length*u,$}),v=yt.max(E,A=>yt.max(A.lines,h))??0;return{rows:E,keyW:F,width:F+c+v,height:S}},m=r*Ro[o]-2*a,w=y=>{let M;if(o==="bottom"){let k=E=>{let v=Math.ceil(y.length/E);return yt.range(E).map(A=>d(y.slice(A*v,(A+1)*v),1/0))};M=yt.range(Math.min(qo,y.length),1,-1).map(k).find(E=>yt.sum(E,v=>v.width)+p*(E.length-1)<=m)??[d(y,m)]}else M=[d(y,m)];let F=a;for(let k of M)k.x=F,F+=k.width+p;return{columns:M,width:F-p+a,height:(yt.max(M,k=>k.height)??0)+2*a}},g=f.length,b=w(f);for(;b.height>s&&g>1;)g--,b=w([...f.slice(0,g),{key:`+${f.length-g} more`,value:""}]);let x=b.columns.flatMap(y=>y.rows).filter(y=>y.key!==y.full).length;return{position:o,size:i,pad:a,lineH:u,keyGap:c,cut:f.length-g+x,...b}}function bn(t,e,n,{x:o,y:r}){let s=O(t,"g",{class:"pt-info",transform:`translate(${o},${r})`,"font-size":e.size});s.append(O(t,"rect",{width:e.width,height:e.height,fill:n.strip}));let l=e.lineH*.75;for(let i of e.columns)for(let a of i.rows){let u=e.pad+a.y+l,c=Z(t,a.key,{x:i.x,y:u,fill:n.muted,"text-anchor":"start"});a.key!==a.full&&c.append(Z(t,a.full,{},"title")),s.append(c),a.lines.forEach((p,f)=>s.append(Z(t,p,{x:i.x+i.keyW+e.keyGap,y:u+f*e.lineH,fill:n.ink,"text-anchor":"start"})))}return s}import*as D from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as K from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as H from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Mt={size:4,padding:3},wn=40,Uo=3,Fe=1.15,Xo=.22,Go=4,kn=1.3,Lt={lines:2,line:1.15,gap:.4,width:160,share:.2};function vn(t,e,n){let o=new Set;for(let a of t.layers){let u=a.type==="line"&&a.options.direct&&(a.channels.group?.column??a.channels.color?.column);if(u)for(let c of t.tables[a.table].columns[u].values)c!==null&&o.add(String(c))}if(!o.size)return null;let r=t.theme.metrics,s=Math.min(Lt.width,n*Lt.share),l=new Map([...o].map(a=>[a,mt(a,e,s,!1,r,Lt.lines)])),i=H.max([...l.values()].flat(),a=>ut(a,e,!1,r));return{lines:l,width:i,size:e}}function Mn({ns:t,grid:e,kind:n,home:o,legend:r,info:s,direct:l,fonts:i,W:a,H:u}){let c=t.theme,p=c.metrics,f=(C,R,_)=>ut(C,R,_,p),h=i.base,d=Math.round(h*c.pad),m=Math.round(h*.8),{title:w,subtitle:g,caption:b,x,y}=t.labels,M=C=>s?.position===C?s:null,F=x?i.axisTitle*1.7:0,k=y?i.axisTitle*1.7:0,S=H.max(e.panels,(C,R)=>{let _=Dt(n.y,o[R].y,5,t.scales.y);return H.max(_.major,rt=>f(_.format(rt),i.tick))}),E=k+(S??0)+Mt.size+Mt.padding+3,v=a-2*d-(c.fixedFormat?E:Math.min(180,a*Xo)),A=(C,R,_)=>{let rt=C?v/f(C,R,_):1;return rt<1&&rt>=(c.shrink??1)?Math.floor(R*rt*10)/10:R},P=A(w,i.title,!0),$=A(g,i.subtitle,!1),N=w?mt(w,P,v,!0,p):[],X=g?mt(g,$,v,!1,p):[],V=N.length*P*1.25+X.length*$*1.4,B=d+V+(V?h*.7:0),Q=b?mt(b,i.tick,a-2*d-E,!1,p,Go):[],qt=Q.length?Q.length*i.tick*kn+i.tick*.5:0,nt=Math.max(r&&!r.horizontal?r.width:0,M("right")?.width??0),Bt=nt?nt+h*1.5:0,I=r?.horizontal?r.height+h*.8:0,wt=M("bottom")?M("bottom").height+m:0,at=l?Math.ceil(l.width+l.size*Lt.gap+2):0,ot={x:d+k,y:B,w:a-2*d-k-Bt,h:u-B-d-F-I-qt-wt},ft=e.kind==="none"?0:Math.round(i.strip*2),Yt=e.kind==="wrap"?ft:0,Qt=e.kind==="grid"&&t.facet.cols?ft+2:0,He=e.kind==="grid"&&t.facet.rows?ft+2:0,Ie=t.facet?.free??{x:!1,y:!1},uo=e.panels.length,Re=C=>Ie.y||C.col===0,Ut=(C,R)=>Ie.x||(e.kind==="wrap"?R+e.ncol>=uo:C.row===e.nrow-1),W=ot.w/e.ncol,G=ot.h/e.nrow,kt,vt,Xt,ce,Ft,Tt;for(let C=0;C<2;C++){ce={x:Math.max(2,W/(n.x==="time"||t.scales.x?.degrees?110:75)),y:Math.max(3,G/45)},kt=Array(e.ncol).fill(0),vt=Array(e.nrow).fill(0),Ft=!1,Tt=new Map,Xt=0;let R=0;e.panels.forEach((q,tt)=>{if(Re(q)){let ct=Dt(n.y,o[tt].y,ce.y,t.scales.y),Rt=H.max(ct.major,ht=>f(ct.format(ht),i.tick))??0;if(kt[q.col]=Math.max(kt[q.col],Math.ceil(Rt+Mt.size+Mt.padding+3)),q.row===0&&!Yt&&!Qt&&n.y!=="category"){let[ht,_t]=o[tt].y,Vt=(n.y==="log"?H.scaleLog():H.scaleLinear()).domain([ht,_t]).range([G,0]),te=H.max(ct.major.filter(_e=>+_e>=+ht&&+_e<=+_t));te!==void 0&&(Xt=Math.max(Xt,Math.ceil(i.tick*.6-Vt(te))))}}if(n.x==="category"&&Ut(q,tt)){let ct=o[tt].x,Rt=W/(ct.length+.2)*.95;for(let ht of ct){let _t=f(ht,i.tick);if(R=Math.max(R,_t),_t<=Rt)continue;let Vt=mt(ht,i.tick,Rt,!1,p,Uo);Vt.at(-1).endsWith("\u2026")||H.max(Vt,te=>f(te,i.tick))>Rt?Ft=!0:Tt.set(String(ht),Vt)}}});let _=Math.min(R,Math.max(G*.6,i.tick*10));Ft&&(Tt.clear(),e.panels.forEach((q,tt)=>{if(!(n.x!=="category"||!Ut(q,tt)))for(let ct of o[tt].x)f(ct,i.tick)>_&&Tt.set(String(ct),[Pt(ct,i.tick,_,!1,p)])}));let rt=Ft?1:H.max(Tt.values(),q=>q.length)??1,It=Ft?_*Math.sin(wn*Math.PI/180)+i.tick:i.tick*(1.2+Fe*(rt-1));Ft&&e.panels.forEach((q,tt)=>{if(q.col!==0||!Ut(q,tt))return;let ct=W/(o[tt].x.length+.2),ht=Math.min(f(o[tt].x[0],i.tick),_)*Math.cos(wn*Math.PI/180)+i.tick*.5;kt[0]=Math.max(kt[0],Math.ceil(ht-.6*ct))}),e.panels.forEach((q,tt)=>{Ut(q,tt)&&(vt[q.row]=Math.max(vt[q.row],Math.ceil(It+Mt.size+Mt.padding+3)))}),W=(ot.w-H.sum(kt)-at*e.ncol-m*(e.ncol-1)-He)/e.ncol,G=(ot.h-Xt-H.sum(vt)-e.nrow*Yt-Qt-m*(e.nrow-1))/e.nrow}W=Math.max(20,W),G=Math.max(20,G);let ue={w:W,h:G};c.aspect?G>W*c.aspect?G=W*c.aspect:W=G/c.aspect:c.flat&&e.panels.length===1&&(G=Math.min(G,W*c.flat));let po=(ue.h-G)*e.nrow/2,We=(ue.w-W)*e.ncol/2,fo=H.cumsum([ot.x+We,...kt.slice(0,-1).map(C=>C+W+at+m)]),ho=H.cumsum([ot.y+Xt+Qt+po,...vt.slice(0,-1).map(C=>Yt+G+C+m)]),Gt=e.panels.map((C,R)=>({x:fo[C.col],y:ho[C.row]+Yt,w:kt[C.col]+W+at,h:G+vt[C.row],ml:kt[C.col],mr:at,mb:vt[C.row],innerW:W,innerH:G,count:ce,rotateX:Ft,wrapX:Tt,showX:Ut(C,R),showY:Re(C)})),mo=C=>[C.strips.top!=null&&[C.strips.top,W],C.strips.right!=null&&[C.strips.right,G]].filter(Boolean),yo=Math.max(c.shrink??1,Math.min(1,H.min(e.panels.flatMap(mo),([C,R])=>(R-8)/f(C,i.strip,!0))??1)),pe=Math.round(i.strip*yo*10)/10,fe=[];e.panels.forEach((C,R)=>{let _=Gt[R],rt=_.x+_.ml,It=(q,tt)=>Pt(q,pe,tt-8,!0,p);C.strips.top!=null&&fe.push({x:rt,y:_.y-Yt-Qt,w:W,h:ft,text:It(C.strips.top,W),full:C.strips.top,size:pe}),C.strips.right!=null&&fe.push({x:rt+W+at+2,y:_.y,w:ft,h:G,text:It(C.strips.right,G),full:C.strips.right,vertical:!0,size:pe})});let de=Gt[0],qe=Gt.find((C,R)=>e.panels[R].col===e.ncol-1)??de,jt=de.x+de.ml,he=qe.x+qe.ml+W,Ye=H.max(Gt,C=>C.y+C.h),Ht=[],me=d;for(let C of N)Ht.push({text:C,attrs:{x:jt,y:me+=P*1.05,"font-size":P,"font-weight":"bold",fill:c.ink,"text-anchor":"start"}}),me+=P*.2;for(let C of X)Ht.push({text:C,attrs:{x:jt,y:me+=$*1.3,"font-size":$,fill:c.muted,"text-anchor":"start"}});if(x&&Ht.push({text:x,attrs:{x:(jt+he)/2,y:Ye+i.axisTitle*1.35,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}}),y){let C=ot.y+(ot.h-H.sum(vt))/2;Ht.push({text:y,attrs:{transform:`translate(${d+We+i.axisTitle*.85},${C}) rotate(-90)`,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}})}if(Q.length){let C=H.max(Q,rt=>f(rt,i.tick)),R=Math.max(d,Math.min(jt,a-d-C)),_=u-d-I+i.tick*.2;Q.forEach((rt,It)=>{let q=_-(Q.length-1-It)*i.tick*kn;Ht.push({text:rt,attrs:{class:"pt-caption",x:R,y:q,"font-size":i.tick,fill:c.muted,"text-anchor":"start"}})})}let Ue=he+at+He+h*1.5,Xe=Ue<a-d-nt-1?Ue:a-d-nt,xo=s?s.position==="right"?{x:Xe,y:ot.y}:{x:Math.max(d,Math.min(jt,a-d-s.width)),y:Ye+F+m/2}:null,Ge=M("right")?s.height+h:0,go=r?r.horizontal?{x:Math.max(d,(jt+he-r.width)/2),y:u-d-r.height}:{x:Xe,y:ot.y+Ge+Math.max(0,(ot.h-H.sum(vt)-Ge-r.height)/2)}:null;return{panels:Gt,strips:fe,texts:Ht,legend:go,info:xo,area:ot,room:ue,rotateX:Ft}}function En(t,e,n){let o=t*4,r=new Uint8Array(e*(o+1));for(let a=0;a<e;a++)r.set(n.subarray(a*o,(a+1)*o),a*(o+1)+1);let s=new Uint8Array(13),l=new DataView(s.buffer);l.setUint32(0,t),l.setUint32(4,e),s.set([8,6,0,0,0],8);let i=Jo([new Uint8Array([137,80,78,71,13,10,26,10]),$e("IHDR",s),$e("IDAT",_o(r)),$e("IEND",new Uint8Array(0))]);return`data:image/png;base64,${Zo(i)}`}function $e(t,e){let n=new Uint8Array(12+e.length),o=new DataView(n.buffer);o.setUint32(0,e.length);for(let r=0;r<4;r++)n[4+r]=t.charCodeAt(r);return n.set(e,8),o.setUint32(8+e.length,Ko(n.subarray(4,8+e.length))),n}function _o(t){let e=Math.max(1,Math.ceil(t.length/65535)),n=new Uint8Array(2+t.length+e*5+4);n.set([120,1]);let o=2;for(let l=0;l<e;l++){let i=t.subarray(l*65535,Math.min(t.length,(l+1)*65535));n[o]=l===e-1?1:0,n[o+1]=i.length&255,n[o+2]=i.length>>8,n[o+3]=~i.length&255,n[o+4]=~i.length>>8&255,n.set(i,o+5),o+=5+i.length}let r=1,s=0;for(let l=0;l<t.length;l++)r=(r+t[l])%65521,s=(s+r)%65521;return new DataView(n.buffer).setUint32(o,(s<<16|r)>>>0),n}var Vo=Array.from({length:256},(t,e)=>{let n=e;for(let o=0;o<8;o++)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Ko(t){let e=4294967295;for(let n of t)e=Vo[(e^n)&255]^e>>>8;return(e^4294967295)>>>0}function Jo(t){let e=new Uint8Array(t.reduce((o,r)=>o+r.length,0)),n=0;for(let o of t)e.set(o,(n+=o.length)-o.length);return e}var ne="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Zo(t){let e="";for(let n=0;n<t.length;n+=3){let[o,r=0,s=0]=[t[n],t[n+1],t[n+2]],l=o<<16|r<<8|s;e+=ne[l>>18]+ne[l>>12&63]+(n+1<t.length?ne[l>>6&63]:"=")+(n+2<t.length?ne[l&63]:"=")}return e}var Ce={step:.5,max:10},Qo=1.5;function An(t,e,n,o,r,s=[]){let l=[...s];return t.map((i,a)=>{let{w:u,h:c}=e[a],p=b=>{let x={x0:b.x-u/2,x1:b.x+u/2,y0:b.y-c/2,y1:b.y+c/2};return x.x0<o.x0||x.x1>o.x1||x.y0<o.y0||x.y1>o.y1||l.some(y=>x.x0<y.x1&&x.x1>y.x0&&x.y0<y.y1&&x.y1>y.y0)||n.some(y=>er(y,x))?null:x},f=Math.max(0,...n.filter(b=>Math.abs(b.x-i.x)<1&&Math.abs(b.y-i.y)<1).map(b=>b.r)),h=tr(i,u,c,r,f),d=h[0],m=null;for(let b of h)if(m=p(b),m){d=b;break}m??={x0:d.x-u/2,x1:d.x+u/2,y0:d.y-c/2,y1:d.y+c/2},l.push(m);let w={x:oe(i.x,m.x0,m.x1),y:oe(i.y,m.y0,m.y1)},g=Math.hypot(w.x-i.x,w.y-i.y)>Qo*r;return{x:d.x,y:d.y,leader:g?w:null}})}function tr(t,e,n,o,r){let[s,l]=[e/2+.4*o+r,n/2+.2*o+r],i=[[s,0],[s,-l],[s,l],[-s,0],[-s,-l],[-s,l],[0,-l],[0,l]].map(([a,u])=>({x:t.x+a,y:t.y+u}));for(let a=Ce.step;a<=Ce.max;a+=Ce.step){let u=Math.max(16,Math.ceil(2*Math.PI*(a*o+Math.max(e,n)/2)/n));for(let c=0;c<u;c++){let p=c/u*2*Math.PI;i.push({x:t.x+Math.cos(p)*(e/2+a*o),y:t.y+Math.sin(p)*(n/2+a*o)})}}return i}function er({x:t,y:e,r:n},o){let r=t-oe(t,o.x0,o.x1),s=e-oe(e,o.y0,o.y1);return r*r+s*s<n*n}function oe(t,e,n){return Math.max(e,Math.min(n,t))}import*as L from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var re=80;function Zt(t,e,n){let o=new Map;for(let r=0;r<n;r++){let s=e.map(i=>t[i]?.[r]??null),l=JSON.stringify(s);o.has(l)||o.set(l,{key:s,idx:[]}),o.get(l).idx.push(r)}return[...o.values()]}function Sn(t,e,n){let o={mean:L.mean,median:L.median,min:L.min,max:L.max,sum:L.sum}[n],r={x:[],y:[],color:[],group:[]};for(let{key:s,idx:l}of Zt(t,["x","color","group"],e))s[0]!==null&&(r.x.push(s[0]),r.y.push(o(l,i=>t.y[i])),r.color.push(s[1]),r.group.push(s[2]));return r}function Fn(t,e,n,o){let r=i=>t.color?o.indexOf(t.color[i]):0,s=t.color?o.filter(i=>t.color.includes(i)):[null],l={...t,ymin:new Array(e),ymax:new Array(e),value:t.y.slice(),slot:new Array(e),slots:new Array(e)};for(let{idx:i}of Zt(t,n==="dodge"?["x","color"]:["x"],e)){i.sort((c,p)=>r(c)-r(p));let a=0,u=0;i.forEach((c,p)=>{let f=t.y[c]??0;if(n!=="overlay"){let h=f>=0?a:u;[l.ymin[c],l.ymax[c]]=[h,h+f],f>=0?a+=f:u+=f}else[l.ymin[c],l.ymax[c]]=[0,f];l.slot[c]=n==="dodge"&&t.color?s.indexOf(t.color[c]):0,l.slots[c]=n==="dodge"?s.length:1})}return l.y=l.ymax,l}function $n(t,e){let n=[...new Set(t.x.filter(i=>i!==null))].sort((i,a)=>i-a),r=(L.min(L.pairs(n),([i,a])=>a-i)??1)*.9,s=[],l=[];for(let i=0;i<e;i++){let a=r/t.slots[i];s.push(t.x[i]-r/2+t.slot[i]*a),l.push(t.x[i]-r/2+(t.slot[i]+1)*a)}return{...t,xmin:s,xmax:l}}function Cn(t,e){let n=t.filter(l=>l!==null&&Number.isFinite(l)),[o,r]=L.extent(n);if(o===void 0)return[0,1];if(o===r)return[o-.5,r+.5];let s=L.ticks(...L.nice(o,r,e),e);return s[0]>o&&s.unshift(s[0]-(s[1]-s[0])),s.at(-1)<r&&s.push(s.at(-1)+(s[1]-s[0])),s}function Dn(t,e,n,o){let r={x:[],xmin:[],xmax:[],y:[],color:[]},s=L.bin().domain([n[0],n.at(-1)]).thresholds(n.slice(1,-1));for(let{key:l,idx:i}of Zt(t,["color"],e)){let a=i.map(u=>t.x[u]).filter(u=>u!==null&&Number.isFinite(u));for(let u of s(a)){let c=u.length;r.x.push((u.x0+u.x1)/2),r.xmin.push(u.x0),r.xmax.push(u.x1),r.y.push(o?c/(a.length*(u.x1-u.x0)||1):c),r.color.push(l[0])}}return r}function se(t){let e=t.filter(a=>a!==null&&Number.isFinite(a)).sort(L.ascending),[n,o,r]=[.25,.5,.75].map(a=>L.quantile(e,a)),s=r-n,l=L.min(e.filter(a=>a>=n-1.5*s)),i=L.max(e.filter(a=>a<=r+1.5*s));return{n:e.length,q1:n,median:o,q3:r,low:l,high:i,outliers:e.filter(a=>a<l||a>i)}}function Pn(t,e){let n={x:[],y:[],color:[],group:[]};for(let{key:o,idx:r}of Zt(t,["color"],e)){let s=r.map(p=>t.x[p]).filter(p=>p!==null&&Number.isFinite(p));if(s.length<2)continue;let l=L.deviation(s),i=L.quantile(s,.75)-L.quantile(s,.25),a=.9*Math.min(l,i/1.34||l)*s.length**-.2||1,[u,c]=L.extent(s);for(let p of L.range(re).map(f=>u-3*a+(c-u+6*a)*f/(re-1))){let f=L.sum(s,h=>Math.exp(-.5*((p-h)/a)**2))/(s.length*a*Math.sqrt(2*Math.PI));n.x.push(p),n.y.push(f),n.color.push(o[0]),n.group.push(o[0])}}return n}function Ln(t,e,{method:n="lm",span:o=.75,band:r=!0}){let s={x:[],y:[],ymin:[],ymax:[],color:[],group:[]};for(let{key:l,idx:i}of Zt(t,["color"],e)){let a=i.map(h=>[t.x[h],t.y[h]]).filter(([h,d])=>h!==null&&d!==null&&Number.isFinite(h)&&Number.isFinite(d));if(a.length<3)continue;a.sort((h,d)=>h[0]-d[0]);let[u,c]=[a[0][0],a.at(-1)[0]],p=L.range(re).map(h=>u+(c-u)*h/(re-1));(n==="loess"?or(a,p,o):nr(a,p)).forEach(({x:h,y:d,se:m})=>{let w=rr(a.length-2);s.x.push(h),s.y.push(d),s.ymin.push(r&&m!==void 0?d-w*m:null),s.ymax.push(r&&m!==void 0?d+w*m:null),s.color.push(l[0]),s.group.push(l[0])})}return s}function nr(t,e){let n=t.length,o=L.mean(t,u=>u[0]),r=L.mean(t,u=>u[1]),s=L.sum(t,u=>(u[0]-o)**2)||1,l=L.sum(t,u=>(u[0]-o)*(u[1]-r))/s,i=r-l*o,a=Math.sqrt(L.sum(t,u=>(u[1]-i-l*u[0])**2)/Math.max(1,n-2));return e.map(u=>({x:u,y:i+l*u,se:a*Math.sqrt(1/n+(u-o)**2/s)}))}function or(t,e,n){let o=Math.max(3,Math.ceil(n*t.length));return e.map(r=>{let s=t.map(([m,w])=>[Math.abs(m-r),m,w]).sort((m,w)=>m[0]-w[0]).slice(0,o),l=s.at(-1)[0]||1,[i,a,u,c,p]=[0,0,0,0,0];for(let[m,w,g]of s){let b=(1-(m/l)**3)**3;i+=b,a+=b*w,u+=b*g,c+=b*w*w,p+=b*w*g}let f=i*c-a*a,h=Math.abs(f)<1e-12?0:(i*p-a*u)/f,d=(u-h*a)/i;return{x:r,y:d+h*r}})}function rr(t){let e=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13,2.12,2.11,2.1,2.09,2.09];return t<1?NaN:t<=e.length?e[t-1]:t<=30?2.05:t<=60?2:1.96}var sr={solid:void 0,dashed:"6,4",dotted:"1.5,3",dashdot:"6,3,1.5,3"},z="frame",xt=(t,e)=>({stroke:t.colors(e),strokeWidth:t.options.size??t.theme.line,strokeOpacity:t.options.alpha??1,strokeDasharray:sr[t.options.dash],strokeLinejoin:"round",strokeLinecap:"round"}),Et=(t,e,n=1)=>({fill:t.colors(e),fillOpacity:t.options.alpha??n}),it=t=>t.theme.palette[0],ir=t=>e=>[D.line(e.index,{x:e.v("x"),y:e.v("y"),z:e.groups(),curve:t,...xt(e,it(e)),clip:z})],On={line:t=>[D.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},...xt(t,it(t)),clip:z}),...t.options.direct?lr(t):[]],path:ir("linear"),step:t=>[D.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},curve:"step-after",...xt(t,it(t)),clip:z})],point:t=>{let e={x:cr(t),y:t.v("y"),r:t.options.size??t.theme.point,...Et(t,it(t)),clip:z},n=t.options.jitter&&t.kind.x==="category"?hr(t.options.jitter):null,o=[Pe(t),n].filter(Boolean);return o.length&&(e.render=o.reduce(dr)),[D.dot(t.index,e)]},bar:t=>{let e={...Et(t,it(t),De(t,1)),clip:z};if(t.kind.x!=="category")return[D.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let n=t.v("slots")[0]??1;if(n===1)return[D.barY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let o=t.bandwidth.x/n,r=(s,l)=>Array.isArray(s)?l.map(i=>s[i]):s;return K.range(n).map(s=>{let l=t.index.filter(a=>t.v("slot")[a]===s),i={x:r(t.v("x"),l),y1:r(t.v("ymin"),l),y2:r(t.v("ymax"),l),fill:r(e.fill,l)};return D.barY(K.range(l.length),{...e,...i,insetLeft:s*o+.5,insetRight:(n-1-s)*o+.5})})},hist:t=>[D.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),insetLeft:.5,insetRight:.5,...Et(t,it(t),De(t)),clip:z})],density:t=>[D.areaY(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),fill:t.colors(it(t)),fillOpacity:.15,clip:z}),D.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...xt(t,it(t)),clip:z})],area:t=>[D.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...Et(t,it(t),De(t,.8)),clip:z})],ribbon:t=>[D.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...Et(t,it(t),.2),clip:z})],smooth:t=>{let e=[];return t.v("ymin").some(n=>n!==null)&&e.push(D.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),fill:t.colors(t.theme.muted),fillOpacity:.15,clip:z})),e.push(D.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...xt(t,t.theme.accent),clip:z})),e},hline:t=>[D.ruleY(t.index,{y:t.v("y"),...xt(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})],vline:t=>[D.ruleX(t.index,{x:t.v("x"),...xt(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})],abline:t=>{let[e,n]=t.domain.x.map(Number),{slope:o=1,intercept:r=0}=t.options;return[D.line([0,1],{x:[e,n],y:[r+o*e,r+o*n],...xt(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})]},segment:t=>[D.link(t.index,{x1:t.v("x"),y1:t.v("y"),x2:t.v("xend"),y2:t.v("yend"),...xt(t,t.theme.ink),render:Pe(t),clip:z})],rect:t=>[D.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...Et(t,it(t)),clip:z})],band:t=>{let e=(o,r,s)=>t.v(o)??t.index.map(()=>t.domain[r][s]),n={x1:e("xmin","x",0),x2:e("xmax","x",1),y1:e("ymin","y",0),y2:e("ymax","y",1)};return[D.rect(t.index,{...n,...Et(t,t.theme.muted,.12),clip:z})]},tile:t=>{let e=Et(t,it(t)),[n,o]=[t.kind.x==="category",t.kind.y==="category"];if(n&&o)return[D.cell(t.index,{x:t.v("x"),y:t.v("y"),...e,inset:.5,clip:z})];let[r,s]=n?[]:ie(t.v("x")),[l,i]=o?[]:ie(t.v("y"));return n?[D.barY(t.index,{x:t.v("x"),y1:l,y2:i,...e,clip:z})]:o?[D.barX(t.index,{y:t.v("y"),x1:r,x2:s,...e,insetTop:.5,insetBottom:.5,clip:z})]:[D.rect(t.index,{x1:r,x2:s,y1:l,y2:i,...e,clip:z})]},text:t=>{let e=t.options.size??t.fonts.tick,n={x:t.v("x"),y:t.v("y"),text:t.v("label"),fontSize:e,...Et(t,t.theme.ink),clip:z};return t.options.repel&&(n.render=pr(t,e)),[D.text(t.index,n)]},errorbar:t=>{let e={...xt(t,t.theme.ink),strokeWidth:t.options.size??1.2,render:Pe(t)},n=D.ruleX(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e,clip:z});if(t.kind.x==="category"){let l=(t.bandwidth.x-Math.min(.3,.6/(t.shift?.slots??1))*t.bandwidth.x)/2,i=a=>D.tickY(t.index,{x:t.v("x"),y:t.v(a),...e,insetLeft:l,insetRight:l,clip:z});return[n,i("ymin"),i("ymax")]}let[o,r]=ie(t.v("x"),.25),s=l=>D.link(t.index,{x1:o,x2:r,y1:t.v(l),y2:t.v(l),...e,clip:z});return[n,s("ymin"),s("ymax")]},polygon:t=>{let e=t.fills(null),n=t.colors(e?t.theme.background:t.theme.muted),o=t.options.size??(e?.5:.6),r=e?{fill:e,fillOpacity:t.options.alpha??1}:{fill:"none",strokeOpacity:t.options.alpha??1};return[D.geo(t.index,{geometry:t.v("geometry"),...r,stroke:n,strokeWidth:o,strokeLinejoin:"round",render:fr,clip:z})]},raster:t=>{if(t.kind.x==="log"||t.kind.y==="log"||t.kind.x==="category"||t.kind.y==="category")throw new Error("raster(): x and y must be number or time axes, not log or category axes");let{x:e,y:n}=t.grid,o=t.cache.png??=ur(t);return[(r,s,l,i,a)=>{let u=a.document,c=(S,E)=>{let v=u.createElementNS("http://www.w3.org/2000/svg",S);for(let[A,P]of Object.entries(E))P!==void 0&&v.setAttribute(A,P);return v},{marginLeft:p,marginTop:f,marginRight:h,marginBottom:d,width:m,height:w}=i,[g,b]=[s.x(e.edges[0]),s.x(e.edges[1])],[x,y]=[s.y(n.edges[1]),s.y(n.edges[0])],M=c("svg",{"aria-label":"raster",x:p,y:f,width:m-p-h,height:w-f-d,overflow:"hidden"}),F={href:o,x:g-p,y:x-f,width:b-g,height:y-x,preserveAspectRatio:"none"},k={"image-rendering":"optimizeSpeed",style:"image-rendering:pixelated;image-rendering:optimizeSpeed",opacity:t.options.alpha};return M.append(c("image",{...F,...k})),M}]},box:t=>{let[e,n,o]=[t.v("x"),t.v("y"),t.colors(t.theme.muted)],r=[];for(let[a,u]of K.group(t.index,c=>e[c])){let c=se(u.map(p=>n[p]));c.n&&r.push({key:a,color:Array.isArray(o)?o[u[0]]:o,...c})}let s=r.flatMap(a=>a.outliers.map(u=>({key:a.key,v:u,color:a.color}))),l=a=>({insetLeft:t.bandwidth.x*a,insetRight:t.bandwidth.x*a}),i={x:"key",stroke:"color",strokeWidth:1.25,clip:z};return[D.ruleX(r,{...i,y1:"q3",y2:"high"}),D.ruleX(r,{...i,y1:"low",y2:"q1"}),D.tickY(r,{...i,y:"high",...l(.38)}),D.tickY(r,{...i,y:"low",...l(.38)}),D.barY(r,{...i,y1:"q1",y2:"q3",fill:"color",fillOpacity:t.options.alpha??.3,...l(.22)}),D.tickY(r,{x:"key",y:"median",stroke:t.theme.ink,strokeWidth:2.25,...l(.22),clip:z}),D.dot(s,{x:"key",y:"v",fill:"color",r:t.theme.point,clip:z})]}};function lr(t){let e=t.groups();if(!e||!t.direct)return[];let[n,o,r]=[t.v("x"),t.v("y"),t.colors(it(t))],[s,l]=t.domain.x.map(Number),i=new Map;for(let c of t.index){if(n[c]===null||o[c]===null||+n[c]<s||+n[c]>l)continue;let p=e[c];(!i.has(p)||+n[c]>+n[i.get(p)])&&i.set(p,c)}let a=t.direct.size,u=[...i].map(([c,p])=>{let f=t.direct.lines.get(String(c))??[String(c)];return{x:n[p],y:o[p],text:f.join(`
2
+ `),h:f.length*a*Lt.line,color:rn(Array.isArray(r)?r[p]:r,t.theme.background)}});return[D.text(u,{x:"x",y:"y",text:"text",fill:"color",fontSize:a,lineHeight:Lt.line,textAnchor:"start",dx:a*Lt.gap,render:ar(u.map(c=>c.h))})]}function ar(t){return(e,n,o,r,s,l)=>{let i=Float64Array.from(o.y),[a,u]=[r.marginTop,r.height-r.marginBottom],c=[...e].sort((d,m)=>i[d]-i[m]),p=(d,m)=>(t[d]+t[m])/2;for(let d=1;d<c.length;d++)i[c[d]]=Math.max(i[c[d]],i[c[d-1]]+p(c[d-1],c[d]));let f=c.at(-1);f!==void 0&&(i[f]=Math.min(i[f],u-t[f]/2));for(let d=c.length-2;d>=0;d--)i[c[d]]=Math.min(i[c[d]],i[c[d+1]]-p(c[d],c[d+1]));let h=c[0];h!==void 0&&(i[h]=Math.max(i[h],a+t[h]/2));for(let d=1;d<c.length;d++)i[c[d]]=Math.max(i[c[d]],i[c[d-1]]+p(c[d-1],c[d]));return l(e,n,{...o,y:i},r,s)}}function De(t,e=.9){return t.options.position==="overlay"?.45:e}function ie(t,e=.5){let n=t.map(Number),o=[...new Set(n)].sort((l,i)=>l-i),r=K.min(K.pairs(o),([l,i])=>i-l)??1,s=t[0]instanceof Date?l=>new Date(l):l=>l;return[n.map(l=>s(l-r*e)),n.map(l=>s(l+r*e))]}function cr(t){let e=t.v("x");if(!t.options.jitter||t.kind.x==="category")return e;let n=K.randomUniform.source(K.randomLcg(42))(-1,1),[o]=ie(e,t.options.jitter);return e.map((r,s)=>+r+(+r-+o[s])*n()).map(r=>e[0]instanceof Date?new Date(r):r)}function Pe(t){if(!t.shift)return;let{axis:e,frac:n}=t.shift,o=t.bandwidth[e],r=e==="x"?["x","x1","x2"]:["y","y1","y2"];return(s,l,i,a,u,c)=>{let p={...i};for(let f of r)i[f]&&(p[f]=Float64Array.from(i[f],(h,d)=>h+n[d]*o));return c(s,l,p,a,u)}}function ur(t){let{x:e,y:n}=t.grid,[o,r]=[t.v("fill"),t.fills(null)],s=new Uint8Array(e.n*n.n*4),l=new Map;for(let i=0;i<o.length;i++){let[a,u]=[e.index[i],n.index[i]];if(a<0||u<0||o[i]===null)continue;let c=Array.isArray(r)?r[i]:r;if(!l.has(c)){let p=K.rgb(c);l.set(c,[p.r,p.g,p.b,Math.round((Number.isNaN(p.opacity)?1:p.opacity)*255)])}s.set(l.get(c),((n.n-1-u)*e.n+a)*4)}return En(e.n,n.n,s)}function pr(t,e){return(n,o,r,s,l,i)=>{let a=t.v("label"),u=Array.from(n,E=>({x:r.x[E],y:r.y[E]})),c=Array.from(n,E=>({w:ut(String(a[E]??""),e,!1,t.theme.metrics),h:e*1.2})),p=t.obstacles().flatMap(E=>E.x.map((v,A)=>({x:o.x(v),y:o.y(E.y[A]),r:E.r+1}))),f=[...u.map(E=>({...E,r:2})),...p.filter(E=>Number.isFinite(E.x)&&Number.isFinite(E.y))],{marginLeft:h,marginTop:d,marginRight:m,marginBottom:w,width:g,height:b}=s,x={x0:h,y0:d,x1:g-m,y1:b-w},y=An(u,c,f,x,e,t.blocked??[]),[M,F]=[Float64Array.from(r.x),Float64Array.from(r.y)];Array.from(n).forEach((E,v)=>[M[E],F[E]]=[y[v].x,y[v].y]);let k=i(n,o,{...r,x:M,y:F},s,l),S=y.flatMap((E,v)=>E.leader?[`M${u[v].x},${u[v].y}L${E.leader.x},${E.leader.y}`]:[]);if(S.length){let E=l.document.createElementNS("http://www.w3.org/2000/svg","path");for(let[v,A]of Object.entries({d:S.join(""),fill:"none",stroke:t.theme.muted,"stroke-width":.8}))E.setAttribute(v,A);k.insertBefore(E,k.firstChild)}return k}}function fr(t,e,n,o,r,s){let l=s(t,e,n,o,r);return l.setAttribute("fill-rule","evenodd"),l}function dr(t,e){return(n,o,r,s,l,i)=>t(n,o,r,s,l,(a,u,c,p,f)=>e(a,u,c,p,f,i))}function hr(t){return(e,n,o,r,s,l)=>{let i=K.randomUniform.source(K.randomLcg(42))(-1,1),a=n.scales.x?.bandwidth??20,u=Float64Array.from(o.x,c=>c+i()*a*t*.5);return l(e,n,{...o,x:u},r,s)}}import*as gt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Wt=18,Ot=6,J={thick:12,long:150,slices:48},zn={min:30},mr=3,yr=1.25,xr=["line","path","step","density","smooth","hline","vline","abline","segment","errorbar","polygon"],gr=["bar","hist","area","ribbon","rect","tile","box"];function Nn(t,e,n,{horizontal:o,maxWidth:r,maxHeight:s}){let l=n.legend*1.2,i=e.filter(h=>h.kind!=="none"),a=i.length>1?(s-l)/i.length:s,u=i.map(h=>br(t,h,n,{horizontal:o,maxWidth:r,maxHeight:a})).filter(Boolean);if(u.length<=1)return u[0]??null;let c=0,p=u.map(h=>({model:h,x:0,y:(c+=h.height+l)-h.height-l})),f=u.find(h=>h.channel==="color")?.items??[];return{kind:"stack",parts:p,items:f,width:gt.max(u,h=>h.width),height:c-l,horizontal:o}}function br(t,e,n,{horizontal:o,maxWidth:r,maxHeight:s}){if(e.kind==="none"||t.theme.legend==="none")return null;let l=e.channel??"color",i=t.theme.metrics,a=(k,S,E)=>ut(k,S,E,i),u=t.labels[l]===null?null:t.labels[l]??e.column,c=u?n.legend*1.8:0,p=u?a(u,n.legend+1,!0):0;if(e.kind==="binned"){let k=e.breaks.length,S=Dt(e.type==="time"?"time":"linear",[e.breaks[0],e.breaks[k-1]],k,{breaks:e.breaks}),E=!!e.labels,v=E?e.labels:S.major.map(S.format),A=gt.max(v,N=>a(N,n.legend))??0,P={kind:"steps",channel:l,title:u,color:e,texts:v,named:E,horizontal:o};if(o){let N=Math.max(zn.min,A+n.legend),X=(u?p+n.legend:0)+(E?0:a(v[0],n.legend)/2);return{...P,titleH:0,inline:!0,rowH:J.thick,box:N,x0:X,width:X+k*N,height:J.thick+n.legend*1.6}}let $=Math.max(zn.min*.6,n.legend*1.6);return{...P,titleH:c,box:$,width:Math.max(p,J.thick+Ot+A),height:c+k*$+(E?0:n.legend*.6)}}if(e.kind==="continuous"){let k=Math.min(J.long,o?r:s-c-4),S=N=>Dt(e.type==="time"?"time":"linear",e.domain,N),E=S(4);for(let N=3;o&&N>=1&&gt.sum(E.major,X=>a(E.format(X),n.legend)+n.legend)>k;N--)E=S(N);let v=E.major.map(E.format),A=gt.max(v,N=>a(N,n.legend))??0,[P,$]=o?[k,J.thick+n.legend*1.6]:[J.thick+Ot+A,k];return{kind:"ramp",channel:l,title:u,titleH:c,color:e,long:k,ticks:E.major,labels:v,width:Math.max(p,P),height:c+$,horizontal:o}}let f=t.layers.filter(k=>k.channels[l]?.column),d=l==="fill"||f.some(k=>gr.includes(k.type))?"square":f.some(k=>xr.includes(k.type))?"line":"point",m=Math.round(n.legend*1.75),w=n.legend*yr,g=o?Math.max(80,r-Wt-Ot):Math.max(110,Math.min(200,r*.2)),b=e.domain.map(k=>{let S=o?[Pt(k,n.legend,g,!1,i)]:mt(k,n.legend,g,!1,i,mr),E=Wt+Ot+(gt.max(S,v=>a(v,n.legend))??0);return{value:k,label:S.join(" "),lines:S,color:e.apply(k),w:E,h:m+(S.length-1)*w}});if(!o){let k=[[]],S=c;for(let A of b)S+A.h>s&&k.at(-1).length&&(k.push([]),S=c),k.at(-1).push(Object.assign(A,{y:S})),S+=A.h;let E=0;for(let A of k){for(let P of A)P.x=E;E+=(gt.max(A,P=>P.w)??0)+n.legend}let v=gt.max(k,A=>A.at(-1).y+A.at(-1).h)??c;return{kind:"swatches",channel:l,title:u,titleH:c,key:d,rowH:m,lineH:w,items:b,width:Math.max(p,E-n.legend),height:v,horizontal:o}}let x=u?p+n.legend:0,y=x,M=0;for(let k of b)y>x&&y+k.w>r&&([y,M]=[x,M+m]),Object.assign(k,{x:y,y:M}),y+=k.w+n.legend*1.5;let F=gt.max(b,k=>k.x+k.w)??p;return{kind:"swatches",channel:l,title:u,titleH:0,inline:!0,key:d,rowH:m,lineH:w,items:b,width:F,height:M+m,horizontal:o}}function Le(t,e,n,o,r=new Set){let s=O(t,"g",{class:"pt-legend","font-size":o.legend});if(e.kind==="stack"){for(let i of e.parts){let a=Le(t,i.model,n,o,r);a.setAttribute("class","pt-legend-part"),a.setAttribute("transform",`translate(${i.x},${i.y})`),s.append(a)}return s}let l=e.inline?{y:e.rowH/2,dy:"0.35em"}:{y:o.legend};return e.title&&s.append(Z(t,e.title,{...l,"font-weight":"bold","font-size":o.legend+1,fill:n.ink})),e.kind==="ramp"?vr(t,s,e,n,o):e.kind==="steps"?kr(t,s,e,n,o):e.items.forEach((i,a)=>s.append(wr(t,e,i,a,n,e.channel==="color"&&r.has(i.value)))),s}function wr(t,e,n,o,r,s){let l=e.rowH/2,i=e.channel==="fill"?"pt-fill-key":"pt-key",a=O(t,"g",{class:i,"data-index":o,transform:`translate(${n.x},${n.y})`,opacity:s?.35:1}),u=O(t,"rect",{width:n.w,height:n.h,fill:"transparent"}),c=e.key==="line"?O(t,"line",{x1:1,x2:Wt-1,y1:l,y2:l,stroke:n.color,"stroke-width":Math.max(2.5,r.line+1)}):e.key==="point"?O(t,"circle",{cx:Wt/2,cy:l,r:Math.max(3.5,r.point+1),fill:n.color}):O(t,"rect",{x:3,y:l-6,width:12,height:12,fill:n.color}),p=O(t,"text",{x:Wt+Ot,y:l,dy:"0.35em",fill:r.muted,"text-decoration":s?"line-through":null});return n.lines.forEach((f,h)=>p.append(h?Z(t,f,{x:Wt+Ot,dy:e.lineH},"tspan"):t.createTextNode(f))),n.lines.at(-1).endsWith("\u2026")&&p.append(Z(t,n.value,{},"title")),a.append(u,c,p),a}function kr(t,e,n,o,r){let{color:s,texts:l,named:i,box:a,horizontal:u}=n,c=s.colors.length,p=n.titleH;s.colors.forEach((f,h)=>{let d=u?{x:n.x0+h*a,y:0,width:a-1,height:J.thick}:{x:0,y:p+(c-1-h)*a,width:J.thick,height:a-1};e.append(O(t,"rect",{...d,fill:f}))}),l.forEach((f,h)=>{let d=u?{x:n.x0+h*a+(i?a/2:0),y:J.thick+r.legend*1.2,"text-anchor":"middle"}:{x:J.thick+Ot,y:p+(i?(c-1-h)*a+a/2:(c-h)*a),dy:"0.35em"};e.append(Z(t,f,{...d,fill:o.muted}))})}function vr(t,e,n,o,r){let{color:s,horizontal:l,long:i}=n,[a,u]=s.domain.map(Number),c=f=>(Number(f)-a)/(u-a||1),p=n.titleH;for(let f=0;f<J.slices;f++){let h=f/J.slices,d=i/J.slices+.5,m=s.ramp(l?h:1-h),w=l?{x:h*i,y:p,width:d,height:J.thick}:{x:0,y:p+h*i,width:J.thick,height:d};e.append(O(t,"rect",{...w,fill:m}))}n.ticks.forEach((f,h)=>{let d=c(f)*i,m=l?{x:d,y:p+J.thick+r.legend*1.2,"text-anchor":"middle"}:{x:J.thick+Ot,y:p+i-d,dy:"0.35em"};e.append(Z(t,n.labels[h],{...m,fill:o.muted}))})}function Bn(t,e={}){if(typeof t?.spec=="function"&&(t=t.spec()),t?.version!==1)throw new Error("plotto: unknown spec version");let n=nn({...t.theme,...e});n.legendSet=(e.legend??t.theme?.legend)!=null;let o=t.data.map(Mr),r=t.layers.map(p=>Er(p,t.mapping??{},o,n));if(!r.length)throw new Error("plotto: the plot has no layers. Add one, for example .line() or .point()");let s=Ar(t.facet),l=t.coord??null,i=t.scales??{},a={};if(l?.type==="geo"){if(s&&s.free.x!==s.free.y)throw new Error('coord("geo"): facet free must be "both" or unset, so that each panel keeps the same distance per px in x and y');i={...i,x:{...i.x,degrees:"lon"},y:{...i.y,degrees:"lat"}},a={x:null,y:null}}let u={...Sr(r),...a,...t.labels},c=t.info?.entries?.length?{entries:t.info.entries,position:t.info.position??"right",set:!!t.info.position}:null;return{tables:o,layers:r,facet:s,scales:i,labels:u,info:c,coord:l,insets:t.insets??[],theme:n}}function Mr({columns:t}){let e=Object.keys(t),n=e.length?t[e[0]].values.length:1;return{columns:t,n}}function Er(t,e,n,o){let r=j.layers[t.type];if(!r)throw new Error(`plotto: unknown layer type "${t.type}". Valid: ${Object.keys(j.layers).join(", ")}`);let s=t.data??0,l=n[s].columns,i={};for(let c of r.channels)t.mapping?.[c]!==void 0?i[c]={column:t.mapping[c]}:t.set?.[c]!==void 0?i[c]={value:t.set[c]}:r.inherit!==!1&&e[c]in l&&(i[c]={column:e[c]});let a=r.requires.filter(c=>!i[c]);if(a.length)throw new Error(`${t.type}(): set ${a.join(" and ")}, as a column name or a value`);for(let c of["color","fill"]){if(!i[c]||!("value"in i[c]))continue;let p=zt(o,i[c].value);if(!p)throw new Error(`${t.type}(): "${i[c].value}" is not a column or a color. Theme colors: ${on(o).join(", ")}`);i[c]={value:p}}for(let[c,p]of Object.entries(i)){if((p.column&&l[p.column].type)==="geometry"!=(c==="geometry"))throw new Error(c==="geometry"?`${t.type}(): geometry must be a geometry column (GeoJSON Polygon or MultiPolygon)`:`${t.type}(): "${p.column}" is a geometry column; use it as geometry`);if(c==="geometry"){let h=l[p.column].values.find(d=>d&&d.type!=="Polygon"&&d.type!=="MultiPolygon");if(h)throw new Error(`${t.type}(): geometry must be Polygon or MultiPolygon, not ${h.type}`)}}let u={};for(let c of r.options)t.set?.[c]!==void 0&&(u[c]=t.set[c]);return{type:t.type,table:s,channels:i,options:u}}function Ar(t){if(!t)return null;let e={x:["x","both"].includes(t.free),y:["y","both"].includes(t.free)};return t.wrap?{kind:"wrap",by:t.wrap,ncol:t.ncol??null,free:e}:{kind:"grid",rows:t.rows??null,cols:t.cols??null,free:e}}function Sr(t){let e=r=>{for(let s of t)for(let l of r)if(s.channels[l]?.column)return s.channels[l].column},n=t.find(r=>r.type==="hist"||r.type==="density"),o=e(["y","ymin","yend"])??(n?n.type==="density"||n.options.density?"density":"count":void 0);return{x:e(["x","xmin","xend"]),y:o,color:e(["color"]),fill:e(["fill"])}}import*as At from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";function Tn(t){return t.layers.map(e=>e.type!=="hist"||!e.channels.x.column?null:Cn(t.tables[e.table].columns[e.channels.x.column].values,e.options.bins??30))}function ze(t,e,n,o){let{ns:r,kind:s,colorLevels:l,edges:i}=t;if(o.size&&e.channels.color?.column){let b=r.tables[e.table].columns[e.channels.color.column].values;n=n.filter(x=>!o.has(b[x]))}let a={};for(let b of Object.keys(e.channels))a[b]=un(r,e,b,n);let u=n.length,c=e.options,p=(b,x,y)=>Fn(b,x,y,l),f=b=>b.x?.length??0,h=a,d=n;if(c.summary&&(e.type==="line"||e.type==="point"))h=Sn(a,u,c.summary);else if(e.type==="bar")h=p(a,u,c.position??"stack"),s.x!=="category"&&(h=$n(h,u));else if(e.type==="area")h=p(a,u,c.position??"stack");else if(e.type==="hist"){let b=Dn(a,u,i[r.layers.indexOf(e)],c.density);h=p(b,f(b),c.position??"stack")}else e.type==="density"?h=Pn(a,u):e.type==="smooth"?h=Ln(a,u,c):e.type==="polygon"&&(h={...a,...Dr(a.geometry)});let m;e.type==="raster"&&(m=Cr(a.x,a.y),h={...a,xmin:[m.x.edges[0]],xmax:[m.x.edges[1]],ymin:[m.y.edges[0]],ymax:[m.y.edges[1]]});let w=h!==a&&e.type!=="polygon"&&e.type!=="raster";w&&(d=null);let g={cols:h,n:w?f(h):u,rows:d,grid:m};return c.position==="dodge"&&Fr.includes(e.type)&&(g.shift=$r(t,e,h,g.n)),g.hover=Pr(r,e,g),g}var Fr=["point","segment","errorbar"];function $r({kind:t,colorLevels:e,colorKind:n},o,r,s){let l=`${o.type}()`,i=t.x==="category"?"x":t.y==="category"&&o.type!=="errorbar"?"y":null;if(!i)throw new Error(`${l}: dodge needs a category ${o.type==="errorbar"?"x":"x or y"} axis`);if(!o.channels.color?.column)return{axis:i,frac:new Array(s).fill(0)};if(n!=="ordinal")throw new Error(`${l}: dodge needs color mapped to a category column`);let a=e.length;return{axis:i,frac:Array.from({length:s},(u,c)=>(e.indexOf(r.color[c])+.5)/a-.5),slots:a}}function Cr(t,e){let n=(o,r)=>{let s=[...new Set(o.filter(p=>p!==null&&Number.isFinite(p)))].sort((p,f)=>p-f);if(s.length<2){let p=s[0]??0;return{lo:p,step:1,n:1,edges:[p-.5,p+.5],index:o.map(f=>f===null?-1:0)}}let l=At.pairs(s,(p,f)=>f-p),i=At.median(l);for(let p=0;p<3;p++)i=At.sum(l)/At.sum(l,f=>Math.max(1,Math.round(f/i)));let a=s[0],u=o.map(p=>{if(p===null||!Number.isFinite(p))return-1;let f=Math.round((p-a)/i);if(Math.abs((p-a)/i-f)>.25)throw new Error(`raster(): ${r} = ${p} is not on a regular grid (step ${At.format(".6~g")(i)} from ${a})`);return f}),c=Math.round((s.at(-1)-a)/i)+1;return{lo:a,step:i,n:c,edges:[a-i/2,a+(c-.5)*i],index:u}};return{x:n(t,"x"),y:n(e,"y")}}var Oe=new WeakMap;function Dr(t){let e={xmin:[],xmax:[],ymin:[],ymax:[]};for(let n of t){if(n&&!Oe.has(n)){let[i,a,u,c]=[1/0,-1/0,1/0,-1/0],p=f=>{if(typeof f[0]=="number")[i,a,u,c]=[Math.min(i,f[0]),Math.max(a,f[0]),Math.min(u,f[1]),Math.max(c,f[1])];else for(let h of f)p(h)};p(n.coordinates),Oe.set(n,i<=a?[i,a,u,c]:[null,null,null,null])}let[o,r,s,l]=n?Oe.get(n):[null,null,null,null];e.xmin.push(o),e.xmax.push(r),e.ymin.push(s),e.ymax.push(l)}return e}function Pr(t,e,{cols:n,rows:o}){let r=t.labels.x||e.channels.x?.column||"x",s=t.labels.y||e.channels.y?.column||"y",l=(u,c,p,f)=>({label:u,axis:c,values:p,values2:f}),i=l(r,"x",n.x),a=e.channels.tooltip?.column&&o?[l(e.channels.tooltip.column,null,n.tooltip)]:[];switch(e.type){case"line":case"path":case"step":case"point":return{hx:n.x,hy:n.y,fields:[i,l(s,"y",n.y),...a]};case"bar":case"area":return{hx:n.x,hy:n.ymax,fields:[i,l(s,"y",n.value),...a]};case"hist":return{hx:n.x,hy:n.ymax,fields:[l(r,"x",n.xmin,n.xmax),l(e.options.density?"density":"count",null,n.value)]};case"density":return{hx:n.x,hy:n.y,fields:[i,l("density",null,n.y)]};case"smooth":{let u=n.ymin.some(c=>c!==null)?[l("95% CI","y",n.ymin,n.ymax)]:[];return{hx:n.x,hy:n.y,fields:[i,l(s,"y",n.y),...u]}}case"ribbon":return{hx:n.x,hy:n.ymax,fields:[i,l(s,"y",n.ymin,n.ymax)]};case"errorbar":return{hx:n.x,hy:n.ymax,fields:[i,l(s,"y",n.ymin,n.ymax)]};case"tile":{let u=e.channels.color?.column?[l(t.labels.color??"value",null,n.color)]:[];return{hx:n.x,hy:n.y,fields:[i,l(s,"y",n.y),...u,...a],tile:!0}}case"box":return{hx:n.x,hy:n.y,fields:[i,l(s,"y",n.y)]};case"raster":return{fields:[i,l(s,"y",n.y),l(t.labels.fill??e.channels.fill.column??"value",null,n.fill)]};case"polygon":{let u=c=>e.channels[c]?.column?[l(t.labels[c]??e.channels[c].column,null,n[c])]:[];return{fields:[...u("fill"),...u("color")],header:a[0]??null,polygon:!0}}default:return null}}var jn=560,Hn=240,Lr=1.2,Or=.05,zr=.2,Nr=.3;function le(t,{document:e=globalThis.document,width:n,domains:o,hidden:r=new Set}={}){let s=Bn(t),l=s.theme,i=Math.round(n??l.width),u=n&&l.reflow&&!l.fixedHeight?Math.max(Hn,Math.round(i*l.height/l.width)):l.height;l.legend==="right"&&i<jn&&(l.legend="bottom");let c=yn(s),p={x:Me(s,"x"),y:Me(s,"y")},f=s.coord?.type==="geo";if(f&&(p.x!=="linear"||p.y!=="linear"))throw new Error('coord("geo"): x and y must be number axes (longitude and latitude), not log, time or category');let h=Ee(s),d=Ee(s,"fill"),m={ns:s,kind:p,colorLevels:h.domain??[],colorKind:h.kind,edges:Tn(s)};for(let $ of c.panels)$.views=s.layers.map((N,X)=>ze(m,N,$.rows[X],new Set));let w=qr(s,c,p),g=vn(s,ke(l).tick,i);f&&!l.aspect&&(l.aspect=pt.median(w,hn));let b=($,N,X)=>{let V=ke(l),B={...V,legend:Math.round(V.legend*X*10)/10},Q=gn(s,B,{W:i,H:$,narrow:i<jn,place:N.info}),qt=Q?.position==="right"?Q.height+B.base:0,nt=Nn(s,[h,d],B,{horizontal:N.legend==="bottom",maxWidth:i*.9,maxHeight:$*.8-qt}),Bt=Mn({ns:s,grid:c,kind:p,home:w,legend:nt,info:Q,direct:g,fonts:B,W:i,H:$}),I=nt?.kind==="stack"?nt.parts.flatMap(ft=>ft.model.items??[]):nt?.items??[],wt=I.filter(ft=>ft.lines.at(-1).endsWith("\u2026")).length+(I.some(ft=>!nt.horizontal&&ft.x>0)?1:0)+(Q?.cut??0),at=Bt.panels[0],ot=N.legend===l.legend&&N.info===s.info?.position;return{fonts:B,info:Q,legend:nt,layout:Bt,k:X,cut:wt,usual:ot,area:Math.min(at.innerW,at.innerH/Nr)*at.innerH}},x=$=>{let N=!l.fitHeight,X=N&&!l.legendSet&&l.legend!=="none"?["right","bottom"]:[l.legend],V=N&&s.info&&!s.info.set?["right","bottom"]:[s.info?.position],B=[];for(let I=1;I>=(l.shrink??1)-1e-9;I-=Or)B.push(I);let Q=X.flatMap(I=>V.flatMap(wt=>B.map(at=>b($,{legend:I,info:wt},at)))),qt=pt.min(Q,I=>I.cut),nt=Q.filter(I=>I.cut===qt),Bt=pt.max(nt,I=>I.area);return nt.filter(I=>I.area>=Bt*(1-zr)).sort((I,wt)=>wt.k-I.k||wt.usual-I.usual||wt.area-I.area)[0]},{fonts:y,info:M,legend:F,layout:k}=x(u);if(l.aspect&&l.fitHeight){let $=u+c.nrow*(k.room.w*l.aspect-k.room.h);u=Math.round(Math.min(u*Lr,Math.max(Hn,$))),{fonts:y,info:M,legend:F,layout:k}=x(u)}let S=O(e,"svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:u,viewBox:`0 0 ${i} ${u}`,"font-family":l.font,"font-size":y.base,style:`color:${l.ink}`});S.append(O(e,"rect",{width:i,height:u,fill:l.background}));for(let $ of k.texts)S.append(Z(e,$.text,$.attrs));M&&S.append(bn(e,M,l,k.info));for(let $ of k.strips)S.append(Ur(e,$,l));let E=c.panels.length,v=Tr(s,p,k.panels);k.panels.push(...v.map($=>$.box));let A=[...w,...v.map($=>$.domain)],P={spec:t,ns:s,doc:e,svg:S,theme:l,fonts:y,grid:c,kind:p,geo:f,color:h,fill:d,ctx:m,legend:F,info:M,layout:k,home:A,direct:g,insets:v,mainCount:E,W:i,H:u};return P.domains=o??A,P.hidden=r,P.panelLayer=S.appendChild(O(e,"g",{class:"pt-panels"})),F&&(P.legendG=S.appendChild(Yn(P))),St(P),P}function qn(t,e){return le(t,e).svg.outerHTML}function St(t){let{ns:e,grid:n,ctx:o,hidden:r}=t;if(r.size||t.filtered){for(let l of n.panels)l.views=e.layers.map((i,a)=>ze(o,i,l.rows[a],r));t.filtered=r.size>0}t.panelLayer.replaceChildren();let s=[...n.panels,...t.insets.map(l=>n.panels[l.parent])];t.panels=s.map((l,i)=>Br(t,l,i)),t.legendG&&t.legendG.replaceWith(t.legendG=Yn(t))}function Yn(t){let e=Le(t.doc,t.legend,t.theme,t.fonts,t.hidden);return e.setAttribute("transform",`translate(${t.layout.legend.x},${t.layout.legend.y})`),e}function Br(t,e,n){let{ns:o,doc:r,theme:s,fonts:l,kind:i,color:a,fill:u}=t,c=t.layout.panels[n],p=t.geo?dn(t.domains[n],c.innerW,c.innerH):t.domains[n],f={x:Rn(i.x,p.x),y:Rn(i.y,p.y)},h=(v,A)=>i[v]==="category"?A/(f[v].length+.2)*.8:0,d={x:h("x",c.innerW),y:h("y",c.innerH)},m=t.geo&&!c.inset?Ir(t,p,c):{},w=[...Object.values(m),...t.insets.filter(v=>!c.inset&&v.parent===n).map(({box:v})=>({x:v.x-c.x,y:v.y-c.y,w:v.w,h:v.h}))].map(({x:v,y:A,w:P,h:$})=>({x0:v,y0:A,x1:v+P,y1:A+$})),g=o.layers.map((v,A)=>{let P=e.views[A],$=Wr({view:P,layer:v,kind:i,color:a,fill:u,theme:s,fonts:l,domain:f,bandwidth:d,direct:c.inset?null:t.direct,obstacles:()=>jr(o,e,s),blocked:w});return{layer:v,view:P,c:$,marks:P.n?On[v.type]($):[]}}),b=v=>{let A=Dt(i[v],p[v],c.count[v],o.scales[v]),P=$=>i[v]==="category"||+$>=+f[v][0]&&+$<=+f[v][1];return{major:A.major.filter(P),minor:A.minor,format:A.format}},x=b("x"),y=b("y"),M=v=>({stroke:v?s.gridMinor:s.grid,strokeOpacity:1,strokeWidth:v?.6:.9}),F={tickSize:Mt.size,tickPadding:Mt.padding,fontSize:l.tick,stroke:s.tick,fill:s.muted,label:null},k=[];if(c.inset&&k.push(et.frame({fill:s.background,stroke:null})),i.x!=="category"&&!c.inset&&k.push(et.gridX(x.minor,M(!0)),et.gridX(x.major,M(!1))),i.y!=="category"&&!c.inset&&k.push(et.gridY(y.minor,M(!0)),et.gridY(y.major,M(!1))),k.push(...g.flatMap(v=>v.marks)),c.inset&&k.push(et.frame({stroke:s.tick,strokeWidth:1})),c.showX){let v=c.rotateX?{tickRotate:-40,textAnchor:"end"}:{},A=$=>c.wrapX.get(String($))?.join(`
3
+ `)??x.format($),P=c.wrapX.size?{tickFormat:A,lineHeight:Fe}:In(i.x,x.format);k.push(et.axisX(x.major,{...F,...v,anchor:"bottom",...P}))}c.showY&&k.push(et.axisY(y.major,{...F,anchor:"left",...In(i.y,y.format)}));let S=et.plot({document:r,width:c.w,height:c.h,marginLeft:c.ml,marginRight:c.mr,marginTop:0,marginBottom:c.mb,x:Wn(i.x,f.x),y:Wn(i.y,f.y),color:{type:"identity"},marks:k}),E=O(r,"g",{class:"pt-panel","data-panel":n,transform:`translate(${c.x},${c.y})`,fill:"currentColor","text-anchor":"middle"});for(let v of[...S.childNodes])v.nodeName.toLowerCase()!=="style"&&E.append(v);return t.geo&&!c.inset&&E.append(Rr(t,m)),t.panelLayer.append(E),{g:E,plot:S,box:c,layers:g}}function Tr(t,e,n){if(!t.insets.length)return[];if(e.x==="category"||e.y==="category")throw new Error("inset(): x and y must be number or time axes, not category axes");return n.flatMap((o,r)=>t.insets.map(({x:s,y:l,at:[i,a,u,c]})=>{let[p,f]=[(u-i)*o.innerW,(c-a)*o.innerH],h={x:o.x+o.ml+i*o.innerW,y:o.y+(1-c)*o.innerH,w:p,h:f,ml:0,mr:0,mb:0,innerW:p,innerH:f};return Object.assign(h,{count:{x:2,y:2},showX:!1,showY:!1,rotateX:!1,wrapX:new Map,inset:!0}),{parent:r,box:h,domain:{x:s,y:l}}}))}function jr(t,e,n){return t.layers.flatMap((o,r)=>o.type==="point"&&e.views[r].n?[{x:e.views[r].cols.x,y:e.views[r].cols.y,r:o.options.size??n.point}]:[])}var Hr=111.32;function Ir(t,e,n){let{fonts:o,ns:r}=t,{scalebar:s,north:l}=r.coord,i=o.base*.8,a=(c,p,f)=>({x:n.ml+(c.endsWith("left")?i:n.innerW-i-p),y:c.startsWith("top")?i:n.innerH-i-f,w:p,h:f}),u={};if(s){let c=(e.y[0]+e.y[1])/2*(Math.PI/180),p=(e.x[1]-e.x[0])*Hr*Math.cos(c)/n.innerW,f=p*n.innerW*.2,h=10**Math.floor(Math.log10(f)),d=[5,2,1].map(m=>m*h).find(m=>m<=f);u.scalebar={...a(s,d/p,o.tick*1.3+5),km:d}}return l&&(u.north=a(l,o.tick,o.tick*2.5)),u}function Rr(t,e){let{doc:n,theme:o,fonts:r}=t,s=O(n,"g",{class:"pt-map-keys","font-size":r.tick,fill:o.ink}),l={stroke:o.background,"stroke-width":3,"stroke-linejoin":"round","paint-order":"stroke"};if(e.scalebar){let{x:i,y:a,w:u,h:c,km:p}=e.scalebar,f=a+c-1,h=O(n,"g",{class:"pt-scalebar","data-km":p,"data-px":u}),d=`M${i},${f-4}V${f}H${i+u}V${f-4}`;h.append(O(n,"path",{d,fill:"none",stroke:o.background,"stroke-width":4,"stroke-linejoin":"round"})),h.append(O(n,"path",{d,fill:"none",stroke:o.ink,"stroke-width":1.5})),h.append(Z(n,`${pt.format(",~r")(p)} km`,{x:i+u/2,y:f-7,"text-anchor":"middle",...l})),s.append(h)}if(e.north){let{x:i,y:a,w:u,h:c}=e.north,p=i+u/2,f=O(n,"g",{class:"pt-north"});f.append(Z(n,"N",{x:p,y:a+r.tick*.85,"text-anchor":"middle","font-weight":"bold",...l}));let h=a+r.tick*1.15,d=`${p},${h} ${i+u},${a+c} ${p},${a+c-u*.4} ${i},${a+c}`;f.append(O(n,"polygon",{points:d,fill:o.ink,stroke:o.background,"stroke-width":1,"stroke-linejoin":"round"})),s.append(f)}return s}function Wr({view:t,layer:e,kind:n,color:o,fill:r,theme:s,fonts:l,domain:i,bandwidth:a,direct:u,obstacles:c,blocked:p}){let f=g=>Jt.x.includes(g)?"x":Jt.y.includes(g)?"y":null,h={},d=g=>{if(g in h)return h[g];let b=t.cols[g];return b&&n[f(g)]==="time"&&(b=b.map(x=>x===null?null:new Date(x))),h[g]=b},m=e.channels.color,w=e.channels.fill;return{index:pt.range(t.n),v:d,options:e.options,colors:g=>m?"value"in m?m.value:d("color").map(o.apply):g,fills:g=>w?"value"in w?w.value:d("fill").map(r.apply):g,shift:t.shift,grid:t.grid,cache:t,groups:()=>d("group")??(m?.column?d("color"):void 0),kind:n,theme:s,fonts:l,domain:i,bandwidth:a,direct:u,obstacles:c,blocked:p}}function In(t,e){return t==="log"?{text:n=>e(n)}:{tickFormat:e}}function Rn(t,e){return t==="time"?e.map(n=>new Date(n)):e}function Wn(t,e){return{type:{linear:"linear",log:"log",time:"utc",category:"band"}[t],domain:e,axis:null,...t==="category"?{padding:.2,round:!1}:{}}}function qr(t,e,n){let o=t.facet?.free??{x:!1,y:!1},r=(l,i,a)=>o[l]?e.kind==="grid"?l==="x"?`c${i.col}`:`r${i.row}`:`p${a}`:"all",s=e.panels.map(()=>({}));for(let l of["x","y"]){let i=pt.group(e.panels.map((a,u)=>[a,u]),([a,u])=>r(l,a,u));for(let a of i.values()){let u=Yr(t,l,n[l],a.map(([c])=>c));for(let[,c]of a)s[c][l]=u}}return s}function Yr(t,e,n,o){let r=t.scales[e]?.limits;if(r&&(n==="category"||r.every(l=>l!==null)))return r;let s=pn(t,e,n,o);return r?[r[0]??s[0],r[1]??s[1]]:s}function Ur(t,e,n){let o=O(t,"g",{class:"pt-strip"});o.append(O(t,"rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:n.strip}));let r=e.vertical?{transform:`translate(${e.x+e.w/2},${e.y+e.h/2}) rotate(90)`,dy:"0.35em"}:{x:e.x+e.w/2,y:e.y+e.h/2,dy:"0.35em"},s=Z(t,e.text,{...r,"text-anchor":"middle","font-weight":"bold","font-size":e.size,fill:n.ink});return e.text!==String(e.full)&&s.append(Z(t,e.full,{},"title")),o.append(s),o}async function Ne(t,e,n=2){let o=Gn(t,e?n*e.width/t.viewBox.baseVal.width:n),r={"image/png":o.then(Xr)};if(e){let s=l=>`<img src="${l.toDataURL("image/png")}" width="${e.width}" height="${e.height}">`;r["text/html"]=o.then(l=>new Blob([s(l)],{type:"text/html"}))}try{return await navigator.clipboard.write([new ClipboardItem(r)]),"Copied"}catch{return Be((await o).toDataURL("image/png"),"plot.png"),"Downloaded"}}async function Un(t){Be((await Gn(t)).toDataURL("image/png"),"plot.png")}function Xn(t){Be(_n(t),"plot.svg")}async function Gn(t,e=2){let n=new Image;n.src=_n(t),await n.decode();let{width:o,height:r}=t.viewBox.baseVal,s=document.createElement("canvas");return s.width=Math.round(o*e),s.height=Math.round(r*e),s.getContext("2d").drawImage(n,0,0,s.width,s.height),s}function _n(t){let e=t.cloneNode(!0);e.querySelector(".pt-overlay")?.remove();let{width:n,height:o}=t.viewBox.baseVal;e.setAttribute("width",n),e.setAttribute("height",o);let r=new TextEncoder().encode(new XMLSerializer().serializeToString(e)),s="";for(let l of r)s+=String.fromCharCode(l);return`data:image/svg+xml;base64,${btoa(s)}`}var Xr=t=>new Promise(e=>t.toBlob(e,"image/png"));function Be(t,e){let n=document.createElement("a");n.href=t,n.download=e,n.click()}import*as lt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Jn=40,Gr=10,_r=6,Zn=4,Vr=6,Kr=["line","step","area","density","smooth","ribbon"],Jr=["bar","hist","tile","box","polygon","raster"],Zr=["point","path","errorbar"];function Qn(t,e,n,o,r){let s=t.panels[e],l=s.plot.scale("x"),i=s.plot.scale("y"),c={state:t,sx:l,sy:i,px:m=>l.apply(m)+(l.bandwidth??0)/2,py:m=>i.apply(m)+(i.bandwidth??0)/2},p=os(c,s,n);if(p)return{...p,panel:e};let f=ts(c,s,n,o,r?.panel===e?r:null);if(f&&f.d<=Gr)return{...Vn(c,f),panel:e};let h=es(c,s,n,o,r?.panel===e?r:null);if(h)return{...h,panel:e};let d=rs(c,s,n,o);return d?{...d,panel:e}:f?{...Vn(c,f),panel:e}:null}function Nt(t,e,n,o,r){let s=e.channels.color;return s?"value"in s?s.value:t.color.apply(n.cols.color[r]):e.type==="smooth"?t.theme.accent:t.theme.palette[0]}function dt(t,e,n){return n==null||Number.isNaN(n)?"\u2013":e&&t.kind[e]==="time"?Qr(t,e)(n):e&&t.kind[e]==="category"?String(n):typeof n=="number"?mn.number(n):String(n)}function Qr(t,e){if(t.timeFormats??={},t.timeFormats[e])return t.timeFormats[e];let n=t.grid.panels.flatMap(s=>s.views.flatMap(l=>l.cols[e]??[])).filter(s=>s!==null),o=s=>n.every(l=>s(new Date(l))),r=o(s=>s.getUTCDate()===1&&s.getUTCHours()===0&&s.getUTCMinutes()===0)?"%Y-%m":o(s=>s.getUTCHours()===0&&s.getUTCMinutes()===0)?"%Y-%m-%d":o(s=>s.getUTCSeconds()===0)?"%m-%d %H:%M":"%m-%d %H:%M:%S";return t.timeFormats[e]=lt.utcFormat(r)}function bt(t,e,n){return e.values2?`${dt(t,e.axis,e.values[n])} \u2013 ${dt(t,e.axis,e.values2[n])}`:dt(t,e.axis,e.values[n])}function ts({sx:t,sy:e,px:n,py:o},r,s,l,i){let a=null,u=null;for(let{layer:c,view:p,c:f}of r.layers){if(!Zr.includes(c.type)||!p.hover||!p.n)continue;let{hx:h,hy:d}=p.hover,m=p.shift,w=m?(m.axis==="x"?t:e).bandwidth??0:0,g=x=>m?.axis==="x"?m.frac[x]*w:0,b=x=>m?.axis==="y"?m.frac[x]*w:0;for(let x=0;x<p.n;x++){if(h[x]===null||d[x]===null)continue;let[y,M]=[n(h[x])+g(x),o(d[x])+b(x)],F=Math.hypot(y-s,M-l);if(F>Jn)continue;let k={layer:c,view:p,c:f,k:x,d:F,x:y,y:M};(!a||F<a.d)&&(a=k),i?.layer===c&&i.k===x&&(u=k)}}return u&&a&&a.d>u.d-Zn?u:a}function Vn({state:t},{layer:e,view:n,c:o,k:r,x:s,y:l,d:i}){let a=Nt(t,e,n,o,r),u=e.channels.color?.column?dt(t,null,n.cols.color[r]):null,c=n.hover.fields.map(p=>({label:p.label,value:bt(t,p,r)})).filter(p=>p.value!==u);return{layer:e,k:r,d:i,color:a,header:u,rows:c,marks:[{x:s,y:l,color:a}],anchor:{x:s,y:l}}}function es({state:t,px:e,py:n},o,r,s,l){let i=[];for(let{layer:y,view:M,c:F}of o.layers){if(!Kr.includes(y.type)||!M.hover||!M.n)continue;let{hx:k,hy:S}=M.hover,E=F.groups()??[],v=new Map;for(let A=0;A<M.n;A++){if(k[A]===null||S[A]===null)continue;let P=Math.abs(e(k[A])-r),$=E[A]??"";P<=Jn&&(!v.has($)||P<v.get($).dx)&&v.set($,{layer:y,view:M,c:F,k:A,dx:P,series:$})}i.push(...v.values())}if(!i.length)return null;let a=lt.least(i,y=>y.dx),u=e(a.view.hover.hx[a.k]),c=i.filter(y=>Math.abs(e(y.view.hover.hx[y.k])-u)<=_r);for(let y of c)y.y=n(y.view.hover.hy[y.k]);let p=lt.least(c,y=>Math.abs(y.y-s)),f=l?.series!==void 0&&c.find(y=>y.layer===l.layer&&y.series===l.series);f&&Math.abs(f.y-s)<Math.abs(p.y-s)+Zn&&(p=f);let h=y=>y.layer.channels.color?.column?dt(t,null,y.view.cols.color[y.k]):y.series!==""?String(y.series):y.view.hover.fields[1]?.label??y.layer.type,d=y=>Nt(t,y.layer,y.view,y.c,y.k),m=a.view.hover.fields[0],w=dt(t,"x",a.view.hover.hx[a.k]),g={crosshair:u,anchor:{x:u,y:s},layer:p.layer,series:p.series};if(c.length===1||c.length>Vr){let y=[{label:m?.label??"x",value:w},{label:p.view.hover.fields[1]?.label??"y",value:Kn(t,p.layer,p.view,p.k)}],M=c.length-1;return{...g,color:d(p),header:h(p),rows:y,note:M?`${M} other series at this x`:null,marks:[{x:u,y:p.y,color:d(p)}]}}let b=ns(t);c.sort((y,M)=>b(y)-b(M)||y.y-M.y);let x=c.map(y=>({swatch:d(y),label:h(y),value:Kn(t,y.layer,y.view,y.k),strong:y===p}));return{...g,color:t.theme.ink,header:m?`${m.label} ${w}`:w,rows:x,marks:c.map(y=>({x:u,y:y.y,color:d(y)}))}}function ns(t){let{color:e}=t;return n=>{let o=n.layer.channels.color?.column?n.view.cols.color[n.k]:null;return o===null?t.ns.layers.indexOf(n.layer):e.kind==="ordinal"?e.domain.indexOf(o):typeof o=="number"?o:0}}function Kn(t,e,n,o){let r=n.hover.fields;return e.type==="smooth"&&r[2]?`${bt(t,r[1],o)} (${bt(t,r[2],o)})`:bt(t,r[1],o)}function os(t,e,n){for(let{layer:o,view:r,c:s}of e.layers)if(o.type==="box"&&r.n)return cs(t,o,r,s,n);return null}function rs(t,e,n,o){let{state:r,sx:s,sy:l}=t;for(let{layer:i,view:a,c:u}of[...e.layers].reverse()){if(!Jr.includes(i.type)||i.type==="box"||!a.n)continue;if(i.type==="polygon"||i.type==="raster"){let m=i.type==="polygon"?ss(t,i,a,u,n,o):is(t,i,a,n,o);if(m)return m;continue}let c=i.type==="tile",p=null;for(let m=0;m<a.n;m++){let[w,g]=us(i,a,m,s),b=Math.abs((w+g)/2-n);if(c?n<w-Te(s,g-w)||n>g+Te(s,g-w):b>g-w)continue;let[x,y]=ps(i,a,m,l),[M,F]=[Math.min(x,y),Math.max(x,y)],k=c?Te(l,F-M):0,S=o>=M-k&&o<=F+k;if(c&&!S)continue;let E=Math.round(b)*1e6+(S?0:1e5+M);(!p||E<p.score)&&(p={k:m,score:E,rect:{x:w,y:M,width:g-w,height:F-M}})}if(!p)continue;let{k:f,rect:h}=p,d=Nt(r,i,a,u,f);if(c){let m=r.ns.labels.color??i.channels.color?.column??"value",w=i.channels.color?.column?dt(r,null,a.cols.color[f]):null,g=a.hover.fields.filter(b=>b.label!==m).map(b=>({label:b.label,value:bt(r,b,f)}));return{color:d,header:w!==null?`${m} ${w}`:null,rows:g,marks:[{rect:h,color:r.theme.ink}],anchor:{x:h.x+h.width,y:o}}}return as(r,i,a,u,f,h)}return null}function ss({state:t,sx:e,sy:n},o,r,s,l,i){if(!e.invert||!n.invert)return null;let[a,u]=[e.invert(l),n.invert(i)],{xmin:c,xmax:p,ymin:f,ymax:h,geometry:d}=r.cols;for(let m=r.n-1;m>=0;m--){if(!d[m]||a<c[m]||a>p[m]||u<f[m]||u>h[m]||!ls(d[m],[a,u]))continue;let w=o.channels.fill,g=w?.column?t.fill.apply(r.cols.fill[m]):w?.value??Nt(t,o,r,s,m),b=r.hover.header?bt(t,r.hover.header,m):null,x=r.hover.fields.map(y=>({label:y.label,value:bt(t,y,m)}));return{layer:o,k:m,color:g,header:b,rows:x,marks:[],anchor:{x:l,y:i}}}return null}function is({state:t,sx:e,sy:n},o,r,s,l){let i=r.grid;if(!i||!e.invert||!n.invert)return null;let a=Math.round((e.invert(s)-i.x.lo)/i.x.step),u=Math.round((n.invert(l)-i.y.lo)/i.y.step);if(a<0||u<0||a>=i.x.n||u>=i.y.n)return null;i.cells??=new Map(i.x.index.map((g,b)=>[i.y.index[b]*i.x.n+g,b]));let c=i.cells.get(u*i.x.n+a);if(c===void 0||r.cols.fill[c]===null)return null;let[p,f,h]=r.hover.fields,d=o.channels.fill,m=d.column?t.fill.apply(r.cols.fill[c]):d.value,w=[p,f].map(g=>({label:g.label,value:bt(t,g,c)}));return{layer:o,k:c,color:m,header:`${h.label} ${bt(t,h,c)}`,rows:w,marks:[],anchor:{x:s,y:l}}}function ls(t,e){return(t.type==="Polygon"?[t.coordinates]:t.coordinates).some(o=>o.filter(r=>lt.polygonContains(r,e)).length%2===1)}function Te(t,e){return t.bandwidth!==void 0?(t.step-t.bandwidth)/2||e*.125:.5}function as(t,e,n,o,r,s){let l=e.type==="hist"?f=>n.cols.xmin[f]===n.cols.xmin[r]:f=>String(n.cols.x[f])===String(n.cols.x[r]),i=lt.range(n.n).filter(l),a=!!e.channels.color?.column,u=i.sort((f,h)=>a&&t.color.kind==="ordinal"?t.color.domain.indexOf(n.cols.color[f])-t.color.domain.indexOf(n.cols.color[h]):n.cols.ymax[h]-n.cols.ymax[f]).map(f=>({swatch:Nt(t,e,n,o,f),label:a?dt(t,null,n.cols.color[f]):n.hover.fields[1].label,value:dt(t,null,n.cols.value[f]),strong:f===r&&i.length>1}));(e.options.position??"stack")==="stack"&&i.length>1&&u.push({label:"total",value:dt(t,null,lt.sum(i,f=>n.cols.value[f])),strong:!1,total:!0});let p=n.hover.fields[0];return{color:Nt(t,e,n,o,r),header:`${p.label} ${bt(t,p,r)}`,rows:u,marks:[{rect:s,color:t.theme.ink}],anchor:{x:s.x+s.width,y:s.y}}}function cs({state:t,sx:e},n,o,r,s){if(e.bandwidth===void 0)return null;let l=lt.range(o.n).find(x=>{let y=e.apply(o.cols.x[x]);return s>=y&&s<=y+e.bandwidth});if(l===void 0)return null;let i=String(o.cols.x[l]),{n:a,q1:u,median:c,q3:p,low:f,high:h,outliers:d}=se(lt.range(o.n).filter(x=>String(o.cols.x[x])===i).map(x=>o.cols.y[x])),m=x=>dt(t,"y",x),w=[{label:"max (whisker)",value:m(h)},{label:"q3",value:m(p)},{label:"median",value:m(c),strong:!0},{label:"q1",value:m(u)},{label:"min (whisker)",value:m(f)},{label:"n",value:String(a)}];d.length&&w.push({label:"outliers",value:String(d.length)});let g=e.apply(o.cols.x[l]);return{color:n.channels.color?.column?Nt(t,n,o,r,l):t.theme.ink,header:`${o.hover.fields[0].label} ${i}`,rows:w,marks:[],anchor:{x:g+e.bandwidth,y:null}}}function us(t,e,n,o){if(e.cols.xmin&&t.type!=="tile")return[o.apply(e.cols.xmin[n]),o.apply(e.cols.xmax[n])];if(o.bandwidth!==void 0){let l=e.cols.slots?.[n]??1,i=o.bandwidth/l,a=o.apply(e.cols.x[n])+(e.cols.slot?.[n]??0)*i;return[a,a+i]}let r=to(e.cols.x,o),s=o.apply(e.cols.x[n]);return[s-r,s+r]}function ps(t,e,n,o){if(t.type==="tile"){if(o.bandwidth!==void 0)return[o.apply(e.cols.y[n]),o.apply(e.cols.y[n])+o.bandwidth];let r=to(e.cols.y,o),s=o.apply(e.cols.y[n]);return[s-r,s+r]}return[o.apply(e.cols.ymin[n]),o.apply(e.cols.ymax[n])]}function to(t,e){let n=[...new Set(t.map(Number))].sort((r,s)=>r-s),o=1/0;for(let r=1;r<n.length;r++)o=Math.min(o,n[r]-n[r-1]);return Number.isFinite(o)?Math.abs(e.apply(n[0]+o)-e.apply(n[0]))/2:6}var fs={zoom:'<path d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5"/><rect x="9" y="9" width="6" height="6"/>',pan:'<path d="M12 3v18M3 12h18M12 3l-2.5 2.5M12 3l2.5 2.5M12 21l-2.5-2.5M12 21l2.5-2.5M3 12l2.5-2.5M3 12l2.5 2.5M21 12l-2.5-2.5M21 12l-2.5 2.5"/>',zoomIn:'<path d="M12 5v14M5 12h14"/>',zoomOut:'<path d="M5 12h14"/>',home:'<path d="M4 11l8-7 8 7M6 9.5V20h12V9.5"/>',copy:'<rect x="8.5" y="8.5" width="11" height="11"/><path d="M15.5 8.5V4.5h-11v11h4"/>',slide:'<rect x="3.5" y="4.5" width="17" height="11"/><path d="M12 15.5v4M8 19.5h8M7 12.5l3-3 2.5 2 4.5-4"/>',download:'<path d="M12 4v11M7.5 10.5L12 15l4.5-4.5M5 19.5h14"/>',check:'<path d="M5 12.5l4.5 4.5L19 7.5"/>'},ds=`
4
+ .pt-root{position:relative;--pt-size:24px}
5
+ .pt-root svg{display:block;user-select:none;-webkit-user-select:none}
6
+ .pt-root .pt-key{cursor:pointer}
7
+ .pt-root:focus{outline:none}
8
+ .pt-bar{position:absolute;top:6px;right:6px;display:flex;align-items:stretch;z-index:3;background:var(--pt-bg);
9
+ border:1px solid var(--pt-line);opacity:0;transition:opacity .12s ease}
10
+ .pt-root:hover .pt-bar,.pt-root:focus-within .pt-bar,.pt-bar.pt-open{opacity:1}
11
+ @media (hover:none){.pt-bar{opacity:1}}
12
+ .pt-btn{all:unset;box-sizing:border-box;display:grid;place-items:center;width:var(--pt-size);height:var(--pt-size);
13
+ color:var(--pt-muted);cursor:pointer}
14
+ .pt-btn svg{width:58%;height:58%;fill:none;stroke:currentColor;stroke-width:1.75;stroke-linecap:square;stroke-linejoin:miter}
15
+ .pt-btn:hover{color:var(--pt-ink);background:var(--pt-soft)}
16
+ .pt-btn:focus-visible{outline:2px solid var(--pt-accent);outline-offset:-2px}
17
+ .pt-btn.pt-on{color:var(--pt-on-accent);background:var(--pt-accent)}
18
+ .pt-sep{width:1px;background:var(--pt-line)}
19
+ .pt-menu{position:absolute;top:100%;right:-1px;display:none;flex-direction:column;min-width:72px;margin-top:-1px;
20
+ background:var(--pt-bg);border:1px solid var(--pt-line)}
21
+ .pt-menu.pt-open{display:flex}
22
+ .pt-menu button{all:unset;padding:5px 12px;font:600 11px/1.4 system-ui,sans-serif;letter-spacing:.04em;color:var(--pt-ink);cursor:pointer}
23
+ .pt-menu button:hover{color:var(--pt-on-accent);background:var(--pt-accent)}
24
+ .pt-tip{position:absolute;display:none;pointer-events:none;z-index:4;min-width:110px;max-width:280px;background:var(--pt-bg);
25
+ color:var(--pt-ink);border:1px solid var(--pt-c);line-height:1.3;font-variant-numeric:tabular-nums}
26
+ .pt-tip.pt-pinned{border-width:2px;box-shadow:3px 3px 0 color-mix(in srgb,var(--pt-c) 35%,transparent)}
27
+ .pt-tip .pt-head{padding:3px 7px;background:var(--pt-c);color:var(--pt-on-c);font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
28
+ .pt-tip .pt-rows{display:grid;grid-template-columns:auto minmax(0,1fr) auto;column-gap:7px;row-gap:0;padding:4px 7px 5px}
29
+ .pt-tip .pt-sw{width:8px;height:8px;align-self:center}
30
+ .pt-tip .pt-k{color:var(--pt-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
31
+ .pt-tip .pt-v{text-align:right;white-space:nowrap}
32
+ .pt-tip .pt-b{color:var(--pt-ink);font-weight:700}
33
+ .pt-tip .pt-t{border-top:1px solid var(--pt-line);padding-top:2px;margin-top:1px}
34
+ .pt-tip .pt-more{grid-column:1/-1;color:var(--pt-muted);font-size:.9em}
35
+ .pt-error{padding:8px 10px;border-left:3px solid #d93025;background:#fdecea;color:#5f2120;font:12px/1.4 ui-monospace,monospace;white-space:pre-wrap}
36
+ `;function no(t){if(t.getElementById("plotto-style"))return;let e=(t.ownerDocument??t).createElement("style");e.id="plotto-style",e.textContent=ds,(t.head??t).append(e)}function oo(t,e){let n={bg:e.background,ink:e.ink,muted:e.muted,line:e.grid,soft:e.strip,accent:e.accent,"on-accent":sn(e.accent)};for(let[o,r]of Object.entries(n))t.style.setProperty(`--pt-${o}`,r)}function ro(t,e){let n=t.createElement("div");n.className="pt-bar";let o={},r=null;e.forEach((l,i)=>{i&&n.append(Object.assign(t.createElement("div"),{className:"pt-sep"}));for(let a of l){let u=t.createElement("button");u.className="pt-btn",u.type="button",u.title=a.title,u.setAttribute("aria-label",a.title),u.innerHTML=eo(a.name),u.addEventListener("pointerdown",c=>c.stopPropagation()),u.addEventListener("click",c=>(c.stopPropagation(),a.menu?s():a.action(u))),n.append(u),o[a.name]=u,a.menu&&(r=hs(t,n,a.menu))}});function s(){let l=!r.classList.contains("pt-open");r.classList.toggle("pt-open",l),n.classList.toggle("pt-open",l)}return r&&t.addEventListener("click",()=>r.classList.contains("pt-open")&&s()),{el:n,button:l=>o[l],setSize:l=>n.parentElement?.style.setProperty("--pt-size",`${Math.round(Math.min(30,Math.max(22,l/34)))}px`),flash(l,i){let a=o[l],[u,c]=[a.innerHTML,a.title];a.innerHTML=eo("check"),a.title=i,a.classList.add("pt-on"),setTimeout(()=>(a.innerHTML=u,a.title=c,a.classList.remove("pt-on")),1100)}}}function hs(t,e,n){let o=t.createElement("div");o.className="pt-menu";for(let[r,s]of n){let l=t.createElement("button");l.type="button",l.textContent=r,l.addEventListener("click",i=>(i.stopPropagation(),o.classList.remove("pt-open"),e.classList.remove("pt-open"),s())),o.append(l)}return e.append(o),o}function eo(t){return`<svg viewBox="0 0 24 24" aria-hidden="true">${fs[t]}</svg>`}var ae=5,je=320,so=.75,ms=300,ys=4;function xs(t,e){let n=typeof t?.spec=="function"?t.spec():t,o={...n.theme,format:"slide",width:null,height:null,size:null},r=e.domains===e.home?void 0:e.domains;return le({...n,theme:o},{document:e.doc,domains:r,hidden:e.hidden})}function gs(t,e){let n=xs(t,e);return Ne(n.svg,{width:n.W,height:n.H},ys)}function lo(t,e,{interactive:n=!1,width:o}={}){let r=e.ownerDocument,s=e.getRootNode();no(s.nodeType===11?s:r);let l=r.createElement("div");l.className="pt-root";let i=Object.assign(r.createElement("div"),{className:"pt-tip"}),a={state:null,mode:"zoom"},u=null,c=d=>{let m=a.state&&{domains:a.state.domains===a.state.home?void 0:a.state.domains,hidden:a.state.hidden},w=le(t,{document:r,width:d,...m}),g=a.state?.svg;w.overlay=w.svg.appendChild(O(r,"g",{class:"pt-overlay","pointer-events":"none"})),w.theme.reflow||(w.svg.setAttribute("width","100%"),w.svg.removeAttribute("height"),l.style.maxWidth=`${w.W}px`),g?g.replaceWith(w.svg):l.prepend(w.svg),a.state=w,oo(l,w.theme),f.setSize(w.theme.reflow?w.W:Math.min(w.W,e.clientWidth||w.W))},p=[[{name:"copy",title:"Copy as PNG",action:d=>Ne(a.state.svg).then(m=>f.flash("copy",m))},{name:"slide",title:"Copy for a slide",action:()=>gs(t,a.state).then(d=>f.flash("slide",d))},{name:"download",title:"Download",menu:[["PNG",()=>Un(a.state.svg)],["SVG",()=>Xn(a.state.svg)]]}]];n&&p.unshift([{name:"zoom",title:"Zoom: drag a box",action:()=>h("zoom")},{name:"pan",title:"Pan: drag the view",action:()=>h("pan")}],[{name:"zoomIn",title:"Zoom in",action:()=>io(a,so)},{name:"zoomOut",title:"Zoom out",action:()=>io(a,1/so)},{name:"home",title:"Reset view (double-click)",action:()=>ao(a)}]);let f=ro(r,p);l.append(f.el,i);let h=d=>{a.mode=d,f.button("zoom").classList.toggle("pt-on",d==="zoom"),f.button("pan").classList.toggle("pt-on",d==="pan"),l.style.cursor=d==="pan"?"grab":""};try{let d=o??(e.clientWidth?Math.max(je,e.clientWidth):void 0);c(d),e.replaceChildren(l)}catch(d){let m=Object.assign(r.createElement("div"),{className:"pt-error",textContent:`plotto: ${d.message}`});throw e.prepend(m),d}if(n&&(h("zoom"),bs(a,l,i)),a.state.theme.reflow&&o===void 0&&typeof ResizeObserver<"u"){let d;u=new ResizeObserver(()=>{clearTimeout(d),d=setTimeout(()=>{let m=Math.max(je,Math.round(e.clientWidth));m&&m!==a.state.W&&c(m)},100)}),u.observe(e)}return a.redraw=()=>St(a.state),a.resize=d=>c(Math.max(je,d)),a.destroy=()=>u?.disconnect(),a}function bs(t,e,n){let o=null,r=null,s=()=>t.state.svg,l=g=>{let b=s().getBoundingClientRect(),x=t.state.W/b.width;return[(g.clientX-b.left)*x,(g.clientY-b.top)*x,x]},i=(g,b)=>{let x=t.state.layout.panels;for(let y=x.length-1;y>=0;y--){let M=x[y];if(g>=M.x+M.ml&&g<=M.x+M.ml+M.innerW&&b>=M.y&&b<=M.y+M.innerH)return y}return-1},a=!1;e.addEventListener("pointerdown",g=>{if(g.button!==0||!s().contains(g.target))return;let[b,x]=l(g),y=i(b,x);y<0||(g.preventDefault(),e.focus({preventScroll:!0}),o={i:y,x:b,y:x,domains:t.state.domains,moving:!1,id:g.pointerId})}),e.addEventListener("pointermove",g=>{let[b,x,y]=l(g);if(o&&!o.moving&&Math.hypot(b-o.x,x-o.y)>=ae&&(o.moving=!0,e.setPointerCapture(o.id),c(),w(),t.mode==="pan"&&(e.style.cursor="grabbing")),!o?.moving){!a&&!r&&(r=requestAnimationFrame(()=>(r=null,m(b,x,y))));return}if(o.i>=t.state.mainCount)return;if(t.mode==="pan")return Ms(t,o,b,x);let M=t.state.layout.panels[o.i],F=V=>Math.max(M.x+M.ml,Math.min(M.x+M.ml+M.innerW,V)),k=V=>Math.max(M.y,Math.min(M.y+M.innerH,V)),[S,E]=[o.x,F(b)].sort((V,B)=>V-B),[v,A]=[o.y,k(x)].sort((V,B)=>V-B),P=A-v<ae||t.state.kind.y==="category",$=E-S<ae||t.state.kind.x==="category";if(P&&$)return t.state.overlay.replaceChildren();let N={x:$?M.x+M.ml:S,y:P?M.y:v,width:$?M.innerW:E-S,height:P?M.innerH:A-v},X=t.state.theme.accent;t.state.overlay.replaceChildren(O(t.state.doc,"rect",{...N,fill:X,"fill-opacity":.1,stroke:X,"stroke-opacity":.7,"stroke-width":1})),o.box={x0:S,x1:E,y0:v,y1:A}}),e.addEventListener("pointerup",g=>{if(o?.moving&&t.mode==="zoom"&&o.box)vs(t,o.i,o.box);else if(o&&!o.moving){let[b,x,y]=l(g);a?(c(),m(b,x,y)):(m(b,x,y),n.style.display==="block"&&u())}t.mode==="pan"&&(e.style.cursor="grab"),a||t.state.overlay.replaceChildren(),o=null}),e.addEventListener("pointerleave",()=>!o&&!a&&w()),e.addEventListener("keydown",g=>g.key==="Escape"&&(c(),w())),e.tabIndex=-1,t.clearHover=()=>(c(),w());function u(){a=!0,n.classList.add("pt-pinned")}function c(){a=!1,n.classList.remove("pt-pinned")}let p=g=>e.getRootNode().elementFromPoint(g.clientX,g.clientY),f=g=>p(g)?.closest?.(".pt-key");e.addEventListener("dblclick",g=>{let[b,x]=l(g);i(b,x)<0||(c(),w(),ao(t))});let h={value:void 0,time:0,before:null};e.addEventListener("click",g=>{let b=f(g);if(!b)return;let x=t.state.legend.items[Number(b.dataset.index)].value;t.clearHover();let y=performance.now();if(x===h.value&&y-h.time<ms)return t.state.hidden=h.before,h={value:void 0,time:0,before:null},ks(t,x);h={value:x,time:y,before:t.state.hidden};let M=new Set(t.state.hidden);M.has(x)?M.delete(x):M.add(x),t.state.hidden=M,St(t.state)});let d=null;function m(g,b,x){let y=t.state,M=i(g,b),F=M<0?null:y.layout.panels[M],k=F?Qn(y,M,g-F.x,b-F.y,d):null;if(d=k,!k)return w();let S=y.doc,E=[];if(k.crosshair!==void 0){let B=F.x+k.crosshair;E.push(O(S,"line",{x1:B,x2:B,y1:F.y,y2:F.y+F.innerH,stroke:y.theme.muted,"stroke-opacity":.55,"stroke-width":1}))}for(let B of k.marks)B.rect?E.push(O(S,"rect",{x:F.x+B.rect.x,y:F.y+B.rect.y,width:B.rect.width,height:B.rect.height,fill:"none",stroke:B.color,"stroke-width":1.5})):E.push(O(S,"circle",{cx:F.x+B.x,cy:F.y+B.y,r:y.theme.point+1.5,fill:B.color,stroke:y.theme.background,"stroke-width":1.5}));y.overlay.replaceChildren(...E);let v=we(k.color);n.style.setProperty("--pt-c",v.bg),n.style.setProperty("--pt-on-c",v.fg),n.style.font=`${y.fonts.hover}px ${y.theme.font}`,n.replaceChildren(...ws(S,k)),n.style.display="block";let A=(F.x+k.anchor.x)/x,P=b/x,$=e.clientWidth,N=e.clientHeight,X=A+16+n.offsetWidth>$?A-16-n.offsetWidth:A+16,V=Math.min(Math.max(0,P-18),Math.max(0,N-n.offsetHeight));n.style.left=`${Math.max(0,X)}px`,n.style.top=`${V}px`}function w(){n.style.display="none",o||t.state.overlay.replaceChildren()}}function ws(t,e){let n=(s,l,i)=>Object.assign(t.createElement(s),{className:l,textContent:i??""}),o=[];e.header&&o.push(n("div","pt-head",e.header));let r=n("div","pt-rows");for(let s of e.rows){let l=n("span","pt-sw");s.swatch&&(l.style.background=s.swatch);let i=[l,n("span","pt-k",s.label),n("span","pt-v",s.value)];s.strong&&i.forEach(a=>a.classList.add("pt-b")),s.total&&i.forEach(a=>a.classList.add("pt-t")),r.append(...i)}return e.note&&r.append(n("span","pt-more",e.note)),o.push(r),o}function ao(t){t.clearHover?.(),t.state.domains=t.state.home,St(t.state)}function ks(t,e){let n=t.state.legend.items.map(r=>r.value),o=t.state.hidden.size===n.length-1&&!t.state.hidden.has(e);t.state.hidden=o?new Set:new Set(n.filter(r=>r!==e)),St(t.state)}function vs(t,e,{x0:n,x1:o,y0:r,y1:s}){let l=t.state,i=l.layout.panels[e],a=l.panels[e].plot,u=l.domains.map(p=>({...p})),c=(p,f,h)=>{if(l.kind[p]==="category"||h-f<ae)return;let d=a.scale(p),m=p==="x"?i.x:i.y,w=[d.invert(f-m),d.invert(h-m)].map(Number).sort((g,b)=>g-b);co(l,p,e).forEach(g=>u[g][p]=w)};c("x",n,o),c("y",r,s),l.domains=u,St(l)}function io(t,e){t.clearHover?.();let n=t.state;n.domains=n.domains.map((o,r)=>{if(r>=n.mainCount)return o;let s={...o};for(let l of["x","y"]){let i=n.kind[l];if(i==="category")continue;let a=i==="log"?Math.log10:h=>h,u=i==="log"?h=>10**h:h=>h,[c,p]=o[l].map(h=>a(+h)),f=(c+p)/2;s[l]=[u(f-(p-c)/2*e),u(f+(p-c)/2*e)]}return s}),St(n)}function Ms(t,e,n,o){let r=t.state,s=r.layout.panels[e.i],l=r.panels[e.i].plot,i=e.domains.map(a=>({...a}));for(let[a,u,c,p]of[["x",e.x,n,s.x],["y",e.y,o,s.y]]){if(r.kind[a]==="category")continue;let f=l.scale(a),h=r.kind[a]==="log",d=g=>h?Math.log10(g):g,m=d(+f.invert(u-p))-d(+f.invert(c-p)),w=e.domains[e.i][a].map(g=>h?10**(d(g)+m):+g+m);co(r,a,e.i).forEach(g=>i[g][a]=w)}r.domains=i,r.frame||(r.frame=requestAnimationFrame(()=>(r.frame=null,St(r))))}function co(t,e,n){let o=t.ns.facet?.free?.[e],r=t.grid.panels[n];return t.grid.panels.flatMap((s,l)=>o?t.grid.kind!=="grid"?l===n?[l]:[]:(e==="x"?s.col===r.col:s.row===r.row)?[l]:[]:[l])}globalThis.plotto={plot:Qe,draw:lo,toSVG:qn};