@danielmcsheehy/isopleth 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/auto.d.ts +61 -0
  2. package/dist/auto.d.ts.map +1 -0
  3. package/dist/auto.js +213 -0
  4. package/dist/auto.js.map +1 -0
  5. package/dist/backend/index.d.ts +24 -0
  6. package/dist/backend/index.d.ts.map +1 -0
  7. package/dist/backend/index.js +42 -0
  8. package/dist/backend/index.js.map +1 -0
  9. package/dist/backend/js/index.d.ts +7 -0
  10. package/dist/backend/js/index.d.ts.map +1 -0
  11. package/dist/backend/js/index.js +33 -0
  12. package/dist/backend/js/index.js.map +1 -0
  13. package/dist/backend/js/insights.d.ts +30 -0
  14. package/dist/backend/js/insights.d.ts.map +1 -0
  15. package/dist/backend/js/insights.js +663 -0
  16. package/dist/backend/js/insights.js.map +1 -0
  17. package/dist/backend/js/kernels.d.ts +22 -0
  18. package/dist/backend/js/kernels.d.ts.map +1 -0
  19. package/dist/backend/js/kernels.js +562 -0
  20. package/dist/backend/js/kernels.js.map +1 -0
  21. package/dist/backend/js/stats.d.ts +26 -0
  22. package/dist/backend/js/stats.d.ts.map +1 -0
  23. package/dist/backend/js/stats.js +237 -0
  24. package/dist/backend/js/stats.js.map +1 -0
  25. package/dist/backend/types.d.ts +139 -0
  26. package/dist/backend/types.d.ts.map +1 -0
  27. package/dist/backend/types.js +12 -0
  28. package/dist/backend/types.js.map +1 -0
  29. package/dist/backend/wasm-wrap.d.ts +9 -0
  30. package/dist/backend/wasm-wrap.d.ts.map +1 -0
  31. package/dist/backend/wasm-wrap.js +52 -0
  32. package/dist/backend/wasm-wrap.js.map +1 -0
  33. package/dist/backend/wasm.d.ts +30 -0
  34. package/dist/backend/wasm.d.ts.map +1 -0
  35. package/dist/backend/wasm.js +29 -0
  36. package/dist/backend/wasm.js.map +1 -0
  37. package/dist/channel.d.ts +41 -0
  38. package/dist/channel.d.ts.map +1 -0
  39. package/dist/channel.js +205 -0
  40. package/dist/channel.js.map +1 -0
  41. package/dist/chart.d.ts +70 -0
  42. package/dist/chart.d.ts.map +1 -0
  43. package/dist/chart.js +68 -0
  44. package/dist/chart.js.map +1 -0
  45. package/dist/compile/index.d.ts +28 -0
  46. package/dist/compile/index.d.ts.map +1 -0
  47. package/dist/compile/index.js +391 -0
  48. package/dist/compile/index.js.map +1 -0
  49. package/dist/compile/palette.d.ts +41 -0
  50. package/dist/compile/palette.d.ts.map +1 -0
  51. package/dist/compile/palette.js +102 -0
  52. package/dist/compile/palette.js.map +1 -0
  53. package/dist/compile/resolve.d.ts +41 -0
  54. package/dist/compile/resolve.d.ts.map +1 -0
  55. package/dist/compile/resolve.js +155 -0
  56. package/dist/compile/resolve.js.map +1 -0
  57. package/dist/compile/scales.d.ts +49 -0
  58. package/dist/compile/scales.d.ts.map +1 -0
  59. package/dist/compile/scales.js +348 -0
  60. package/dist/compile/scales.js.map +1 -0
  61. package/dist/compile/series.d.ts +65 -0
  62. package/dist/compile/series.d.ts.map +1 -0
  63. package/dist/compile/series.js +948 -0
  64. package/dist/compile/series.js.map +1 -0
  65. package/dist/editor/index.d.ts +46 -0
  66. package/dist/editor/index.d.ts.map +1 -0
  67. package/dist/editor/index.js +342 -0
  68. package/dist/editor/index.js.map +1 -0
  69. package/dist/index.d.ts +47 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +41 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/insights/index.d.ts +21 -0
  74. package/dist/insights/index.d.ts.map +1 -0
  75. package/dist/insights/index.js +461 -0
  76. package/dist/insights/index.js.map +1 -0
  77. package/dist/interval.d.ts +19 -0
  78. package/dist/interval.d.ts.map +1 -0
  79. package/dist/interval.js +166 -0
  80. package/dist/interval.js.map +1 -0
  81. package/dist/isopleth.browser.js +44 -0
  82. package/dist/isopleth.browser.js.LEGAL.txt +28 -0
  83. package/dist/isopleth.browser.js.map +7 -0
  84. package/dist/marks.d.ts +62 -0
  85. package/dist/marks.d.ts.map +1 -0
  86. package/dist/marks.js +176 -0
  87. package/dist/marks.js.map +1 -0
  88. package/dist/render.d.ts +21 -0
  89. package/dist/render.d.ts.map +1 -0
  90. package/dist/render.js +117 -0
  91. package/dist/render.js.map +1 -0
  92. package/dist/spec.d.ts +56 -0
  93. package/dist/spec.d.ts.map +1 -0
  94. package/dist/spec.js +191 -0
  95. package/dist/spec.js.map +1 -0
  96. package/dist/theme.d.ts +82 -0
  97. package/dist/theme.d.ts.map +1 -0
  98. package/dist/theme.js +136 -0
  99. package/dist/theme.js.map +1 -0
  100. package/dist/transforms/basic.d.ts +35 -0
  101. package/dist/transforms/basic.d.ts.map +1 -0
  102. package/dist/transforms/basic.js +174 -0
  103. package/dist/transforms/basic.js.map +1 -0
  104. package/dist/transforms/group.d.ts +32 -0
  105. package/dist/transforms/group.d.ts.map +1 -0
  106. package/dist/transforms/group.js +419 -0
  107. package/dist/transforms/group.js.map +1 -0
  108. package/dist/transforms/interval.d.ts +24 -0
  109. package/dist/transforms/interval.d.ts.map +1 -0
  110. package/dist/transforms/interval.js +104 -0
  111. package/dist/transforms/interval.js.map +1 -0
  112. package/dist/transforms/map.d.ts +48 -0
  113. package/dist/transforms/map.d.ts.map +1 -0
  114. package/dist/transforms/map.js +192 -0
  115. package/dist/transforms/map.js.map +1 -0
  116. package/dist/transforms/select.d.ts +9 -0
  117. package/dist/transforms/select.d.ts.map +1 -0
  118. package/dist/transforms/select.js +50 -0
  119. package/dist/transforms/select.js.map +1 -0
  120. package/dist/transforms/stack.d.ts +23 -0
  121. package/dist/transforms/stack.d.ts.map +1 -0
  122. package/dist/transforms/stack.js +306 -0
  123. package/dist/transforms/stack.js.map +1 -0
  124. package/dist/types.d.ts +369 -0
  125. package/dist/types.d.ts.map +1 -0
  126. package/dist/types.js +11 -0
  127. package/dist/types.js.map +1 -0
  128. package/package.json +70 -4
  129. package/README.md +0 -3
@@ -0,0 +1,47 @@
1
+ /**
2
+ * isopleth — composable charts on Apache ECharts 6 with built-in insights.
3
+ *
4
+ * ```ts
5
+ * import * as ip from "@danielmcsheehy/isopleth";
6
+ *
7
+ * const chart = ip.plot({
8
+ * marks: [
9
+ * ip.areaY(data, ip.windowY(7, { x: "date", y: "value", fill: "series", fillOpacity: 0.3 })),
10
+ * ip.lineY(data, { x: "date", y: "value", stroke: "series" }),
11
+ * ip.ruleY([0]),
12
+ * ],
13
+ * insights: { anomalies: true, forecast: { horizon: 30 } },
14
+ * });
15
+ * await chart.render(document.getElementById("chart")!);
16
+ * ```
17
+ */
18
+ export { plot, Chart } from "./chart.js";
19
+ export type { ChartInstance, RenderOptions } from "./chart.js";
20
+ export { compile } from "./compile/index.js";
21
+ export { renderChart, renderSVG, disposeChart, registerECharts } from "./render.js";
22
+ export { line, lineX, lineY, area, areaX, areaY, barX, barY, rect, rectX, rectY, cell, dot, dotX, dotY, ruleX, ruleY, text, textX, textY, differenceX, differenceY, frame, gridX, gridY, marks, createMark, flattenMarks, } from "./marks.js";
23
+ export type { DifferenceOptions } from "./marks.js";
24
+ export { auto, autoSpec } from "./auto.js";
25
+ export { fromSpec, specMarks, specToCode, inspectFields } from "./spec.js";
26
+ export type { ChartSpec, SpecMark, FieldInfo } from "./spec.js";
27
+ export type { AutoOptions, AutoSpec, AutoChannel } from "./auto.js";
28
+ export { filter, sort, reverse, shuffle, basic, column, composeTransform, seriesOf, zOf, isDataChannel } from "./transforms/basic.js";
29
+ export { bin, binX, binY, group, groupX, groupY, groupZ } from "./transforms/group.js";
30
+ export type { BinOutputs, GroupOutputs, Thresholds } from "./transforms/group.js";
31
+ export { stackX, stackY, stackX1, stackX2, stackY1, stackY2 } from "./transforms/stack.js";
32
+ export type { StackOptions, StackOffset, StackOrder } from "./transforms/stack.js";
33
+ export { map, mapX, mapY, window, windowX, windowY, normalizeX, normalizeY, imputeX, imputeY, diffY, cumsumY, shiftX } from "./transforms/map.js";
34
+ export type { MapFn, MapMethod, WindowOptions, Basis, ImputeMethod } from "./transforms/map.js";
35
+ export { intervalX, intervalY } from "./transforms/interval.js";
36
+ export type { IntervalTransformOptions } from "./transforms/interval.js";
37
+ export { selectFirst, selectLast, selectMinX, selectMaxX, selectMinY, selectMaxY } from "./transforms/select.js";
38
+ export { identity, indexOf, valueof, inferType, isColor, formatValue } from "./channel.js";
39
+ export { numberInterval, utcInterval, maybeInterval, medianStep, guessTimeInterval } from "./interval.js";
40
+ export { SCHEMES, INSIGHT_COLORS, fadeGradient, withOpacity } from "./compile/palette.js";
41
+ export { themes, light as lightTheme, dark as darkTheme, ink as inkTheme, defineTheme, resolveTheme, themeToCSSVars } from "./theme.js";
42
+ export type { Theme, ThemeInsightColors, ThemeMarkSpecs } from "./theme.js";
43
+ export { getBackend, useBackend, init, jsBackend } from "./backend/index.js";
44
+ export type { Backend, AnomalyResult, ForecastResult, ChangepointResult, SeasonalityResult, TrendResult, Decomposition, FrequencyOutlierResult, CategoryOutlierResult, SeriesOutlierResult } from "./backend/types.js";
45
+ export { BackendError } from "./backend/types.js";
46
+ export type * from "./types.js";
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGpF,OAAO,EACL,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,E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GlD,mBAAmB,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * isopleth — composable charts on Apache ECharts 6 with built-in insights.
3
+ *
4
+ * ```ts
5
+ * import * as ip from "@danielmcsheehy/isopleth";
6
+ *
7
+ * const chart = ip.plot({
8
+ * marks: [
9
+ * ip.areaY(data, ip.windowY(7, { x: "date", y: "value", fill: "series", fillOpacity: 0.3 })),
10
+ * ip.lineY(data, { x: "date", y: "value", stroke: "series" }),
11
+ * ip.ruleY([0]),
12
+ * ],
13
+ * insights: { anomalies: true, forecast: { horizon: 30 } },
14
+ * });
15
+ * await chart.render(document.getElementById("chart")!);
16
+ * ```
17
+ */
18
+ // Core
19
+ export { plot, Chart } from "./chart.js";
20
+ export { compile } from "./compile/index.js";
21
+ export { renderChart, renderSVG, disposeChart, registerECharts } from "./render.js";
22
+ // Marks
23
+ export { line, lineX, lineY, area, areaX, areaY, barX, barY, rect, rectX, rectY, cell, dot, dotX, dotY, ruleX, ruleY, text, textX, textY, differenceX, differenceY, frame, gridX, gridY, marks, createMark, flattenMarks, } from "./marks.js";
24
+ export { auto, autoSpec } from "./auto.js";
25
+ export { fromSpec, specMarks, specToCode, inspectFields } from "./spec.js";
26
+ // Transforms
27
+ export { filter, sort, reverse, shuffle, basic, column, composeTransform, seriesOf, zOf, isDataChannel } from "./transforms/basic.js";
28
+ export { bin, binX, binY, group, groupX, groupY, groupZ } from "./transforms/group.js";
29
+ export { stackX, stackY, stackX1, stackX2, stackY1, stackY2 } from "./transforms/stack.js";
30
+ export { map, mapX, mapY, window, windowX, windowY, normalizeX, normalizeY, imputeX, imputeY, diffY, cumsumY, shiftX } from "./transforms/map.js";
31
+ export { intervalX, intervalY } from "./transforms/interval.js";
32
+ export { selectFirst, selectLast, selectMinX, selectMaxX, selectMinY, selectMaxY } from "./transforms/select.js";
33
+ // Channels, intervals, scales
34
+ export { identity, indexOf, valueof, inferType, isColor, formatValue } from "./channel.js";
35
+ export { numberInterval, utcInterval, maybeInterval, medianStep, guessTimeInterval } from "./interval.js";
36
+ export { SCHEMES, INSIGHT_COLORS, fadeGradient, withOpacity } from "./compile/palette.js";
37
+ export { themes, light as lightTheme, dark as darkTheme, ink as inkTheme, defineTheme, resolveTheme, themeToCSSVars } from "./theme.js";
38
+ // Backend
39
+ export { getBackend, useBackend, init, jsBackend } from "./backend/index.js";
40
+ export { BackendError } from "./backend/types.js";
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO;AACP,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpF,QAAQ;AACR,OAAO,EACL,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAC7F,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,GACjH,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAI3E,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,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AS,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Insights: run the analytics configured in `insights` (plot- or mark-level)
3
+ * against resolved marks, and turn the results into extra marks (anomaly
4
+ * dots, forecast bands, changepoint rules, trend lines), per-item highlights
5
+ * (outlying bars/dots), per-series styles (outlying series) and a summary.
6
+ */
7
+ import type { Insight, Mark, PlotOptions } from "../types.js";
8
+ import type { Theme } from "../theme.js";
9
+ import type { ResolvedMark } from "../compile/resolve.js";
10
+ import type { FacetPlan } from "../compile/resolve.js";
11
+ import { type ItemHighlight, type SeriesStyle } from "../compile/series.js";
12
+ export interface InsightOutput {
13
+ marks: Mark[];
14
+ insights: Insight[];
15
+ highlights: Map<string, Map<number, ItemHighlight>>;
16
+ seriesStyles: Map<string, Map<string | number | boolean | null, SeriesStyle>>;
17
+ notes: string[];
18
+ warnings: string[];
19
+ }
20
+ export declare function applyInsights(resolved: ResolvedMark[], plan: FacetPlan, options: PlotOptions, theme: Theme): InsightOutput;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/insights/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAMV,OAAO,EAIP,IAAI,EACJ,WAAW,EAMZ,MAAM,aAAa,CAAC;AAMrB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEzF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IACpD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAmED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,aAAa,CAkD1H"}
@@ -0,0 +1,461 @@
1
+ /**
2
+ * Insights: run the analytics configured in `insights` (plot- or mark-level)
3
+ * against resolved marks, and turn the results into extra marks (anomaly
4
+ * dots, forecast bands, changepoint rules, trend lines), per-item highlights
5
+ * (outlying bars/dots), per-series styles (outlying series) and a summary.
6
+ */
7
+ import { getBackend } from "../backend/index.js";
8
+ import { formatValue, inferType, keyof, toNumber } from "../channel.js";
9
+ import { guessTimeInterval, medianStep } from "../interval.js";
10
+ import { createMark } from "../marks.js";
11
+ import { groupSeries } from "../compile/series.js";
12
+ const SERIES_MARKS = new Set(["line", "lineY", "lineX", "area", "areaY", "dot", "barY", "rectY"]);
13
+ const BAR_MARKS = new Set(["barY", "barX", "rectY", "rectX"]);
14
+ function normalize(config, markId) {
15
+ const out = {};
16
+ if (!config)
17
+ return out;
18
+ for (const kind of ["anomalies", "forecast", "changepoints", "seasonality", "trend", "frequencyOutliers", "categoryOutliers", "seriesOutliers"]) {
19
+ const v = config[kind];
20
+ if (!v)
21
+ continue;
22
+ const c = v === true ? {} : { ...v };
23
+ if (c.target !== undefined) {
24
+ const targets = Array.isArray(c.target) ? c.target : [c.target];
25
+ if (!targets.includes(markId))
26
+ continue;
27
+ }
28
+ out[kind] = c;
29
+ }
30
+ return out;
31
+ }
32
+ /** Extract numeric (x, y) per series of a mark, sorted by x. */
33
+ function seriesData(rm, I) {
34
+ const X = rm.channels.x;
35
+ const Y1 = rm.channels.y1;
36
+ const Y2 = rm.channels.y2;
37
+ const Y = rm.channels.y;
38
+ if (!X)
39
+ return [];
40
+ const stacked = Boolean(rm.mark.options.__stacked);
41
+ const temporal = inferType(X) === "temporal";
42
+ if (inferType(X) === "ordinal")
43
+ return [];
44
+ const out = [];
45
+ for (const g of groupSeries(rm, I)) {
46
+ const idx = g.index.filter((i) => Number.isFinite(toNumber(X[i]))).sort((a, b) => toNumber(X[a]) - toNumber(X[b]));
47
+ const x = Float64Array.from(idx, (i) => toNumber(X[i]));
48
+ const y = Float64Array.from(idx, (i) => {
49
+ if (stacked && Y1 && Y2) {
50
+ const a = toNumber(Y1[i]);
51
+ const b = toNumber(Y2[i]);
52
+ return Number.isFinite(a) && Number.isFinite(b) ? b - a : NaN;
53
+ }
54
+ const v = Y2 ?? Y;
55
+ return v ? toNumber(v[i]) : NaN;
56
+ });
57
+ if (idx.length === 0)
58
+ continue;
59
+ out.push({ index: idx, x, y, temporal, key: g.key, name: g.value !== undefined ? formatValue(g.value) : rm.mark.id, value: g.value });
60
+ }
61
+ return out;
62
+ }
63
+ const xValue = (v, temporal) => (temporal ? new Date(v) : v);
64
+ let IC;
65
+ export function applyInsights(resolved, plan, options, theme) {
66
+ IC = theme.insight;
67
+ const out = { marks: [], insights: [], highlights: new Map(), seriesStyles: new Map(), notes: [], warnings: [] };
68
+ const backend = getBackend();
69
+ for (const rm of resolved) {
70
+ if (rm.mark.generated)
71
+ continue;
72
+ const cfg = { ...normalize(options.insights, rm.mark.id), ...normalize(rm.mark.options.insights, rm.mark.id) };
73
+ if (Object.keys(cfg).length === 0)
74
+ continue;
75
+ const facetsToRun = rm.faceted ? rm.facets.map((_, f) => f) : [0];
76
+ for (const f of facetsToRun) {
77
+ const I = rm.facets[f] ?? [];
78
+ const facetKey = rm.faceted ? plan.keys[f] : {};
79
+ const facetFields = (row) => ({ ...row, ...(facetKey.fx !== undefined ? { fx: facetKey.fx } : {}), ...(facetKey.fy !== undefined ? { fy: facetKey.fy } : {}) });
80
+ const facetOpts = { ...(facetKey.fx !== undefined ? { fx: "fx" } : {}), ...(facetKey.fy !== undefined ? { fy: "fy" } : {}) };
81
+ const series = SERIES_MARKS.has(rm.mark.type) ? seriesData(rm, I) : [];
82
+ for (const [kind, c] of Object.entries(cfg)) {
83
+ try {
84
+ switch (kind) {
85
+ case "anomalies":
86
+ for (const s of series)
87
+ runAnomalies(rm, s, { ...c, kind }, out, facetFields, facetOpts, backend.name);
88
+ break;
89
+ case "forecast":
90
+ for (const s of series)
91
+ runForecast(rm, s, { ...c, kind }, out, facetFields, facetOpts, backend.name);
92
+ break;
93
+ case "changepoints":
94
+ for (const s of series)
95
+ runChangepoints(rm, s, { ...c, kind }, out, facetFields, facetOpts, backend.name);
96
+ break;
97
+ case "seasonality":
98
+ for (const s of series)
99
+ runSeasonality(rm, s, { ...c, kind }, out, backend.name);
100
+ break;
101
+ case "trend":
102
+ for (const s of series)
103
+ runTrend(rm, s, { ...c, kind }, out, facetFields, facetOpts, backend.name);
104
+ break;
105
+ case "frequencyOutliers":
106
+ runFrequencyOutliers(rm, I, { ...c, kind }, out, facetFields, facetOpts, backend.name);
107
+ break;
108
+ case "categoryOutliers":
109
+ runCategoryOutliers(rm, I, { ...c, kind }, out, facetFields, facetOpts, backend.name);
110
+ break;
111
+ case "seriesOutliers":
112
+ runSeriesOutliers(rm, series, { ...c, kind }, out, facetFields, facetOpts, backend.name);
113
+ break;
114
+ }
115
+ }
116
+ catch (err) {
117
+ out.warnings.push(`${kind} on ${rm.mark.id}: ${err instanceof Error ? err.message : String(err)}`);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ return out;
123
+ }
124
+ function note(out, insight) {
125
+ out.insights.push(insight);
126
+ out.notes.push(insight.summary);
127
+ }
128
+ function seriesLabel(rm, s) {
129
+ return s.value !== undefined ? ` (${s.name})` : "";
130
+ }
131
+ function highlight(out, markId, i, h) {
132
+ let m = out.highlights.get(markId);
133
+ if (!m)
134
+ out.highlights.set(markId, (m = new Map()));
135
+ m.set(i, { ...(m.get(i) ?? {}), ...h });
136
+ }
137
+ // ------------------------------------------------------------- anomalies ---
138
+ function runAnomalies(rm, s, c, out, ff, fo, backendName) {
139
+ if (s.y.filter(Number.isFinite).length < 8)
140
+ return;
141
+ const r = getBackend().anomalies(s.y, { method: c.method, sensitivity: c.sensitivity, threshold: c.threshold, window: c.window, period: c.period, lambda: c.lambda });
142
+ const color = c.color ?? IC.anomaly;
143
+ const points = r.indices.map((j) => ff({ x: xValue(s.x[j], s.temporal), y: s.y[j], score: r.scores[j], expected: (r.lower[j] + r.upper[j]) / 2, series: s.name }));
144
+ const when = r.indices.slice(0, 3).map((j) => formatValue(xValue(s.x[j], s.temporal)));
145
+ const n = r.indices.length;
146
+ note(out, {
147
+ kind: "anomalies",
148
+ mark: rm.mark.id,
149
+ series: s.value,
150
+ method: r.method,
151
+ backend: backendName,
152
+ data: r,
153
+ summary: n === 0 ? `no anomalies${seriesLabel(rm, s)}` : `${n} anomal${n === 1 ? "y" : "ies"}${seriesLabel(rm, s)} at ${when.join(", ")}${n > 3 ? ", …" : ""}`,
154
+ });
155
+ if (c.show === false)
156
+ return;
157
+ if (c.band !== false) {
158
+ const band = s.index.map((_, j) => ff({ x: xValue(s.x[j], s.temporal), lower: r.lower[j], upper: r.upper[j] }));
159
+ out.marks.push(createMark("areaY", band, { ...fo, x: "x", y1: "lower", y2: "upper", fill: IC.band, fillOpacity: 0.07, silent: true, legend: false, id: `${rm.mark.id}:anomaly-band:${s.key ?? ""}`, z2: -1 }, true));
160
+ }
161
+ if (points.length) {
162
+ out.marks.push(createMark("dot", points, { ...fo, x: "x", y: "y", fill: color, stroke: "#fff", strokeWidth: 1, r: 5, id: `${rm.mark.id}:anomalies:${s.key ?? ""}`, name: "anomaly", channels: { score: (d) => `z = ${formatValue(d.score)}` }, z2: 5 }, true));
163
+ }
164
+ for (const j of r.indices)
165
+ highlight(out, rm.mark.id, s.index[j], { color, size: 10 });
166
+ }
167
+ // -------------------------------------------------------------- forecast ---
168
+ function runForecast(rm, s, c, out, ff, fo, backendName) {
169
+ if (s.y.filter(Number.isFinite).length < 5)
170
+ return;
171
+ const horizon = c.horizon ?? 10;
172
+ const level = c.level === undefined ? 0.95 : c.level;
173
+ const r = getBackend().forecast(s.y, { method: c.method, horizon, level, period: c.period });
174
+ const warnings = [];
175
+ if (backendName === "js" && (c.method === "ets" || c.method === "mstl"))
176
+ warnings.push(`${c.method} needs the wasm backend; used ${r.method}`);
177
+ // Extend x by whole steps.
178
+ const step = medianStep(s.x);
179
+ const last = s.x[s.x.length - 1];
180
+ const iv = s.temporal ? guessTimeInterval(step) : undefined;
181
+ const future = [];
182
+ let cur = last;
183
+ for (let h = 0; h < horizon; h++) {
184
+ cur = iv ? iv.offset(cur, 1) : cur + (Number.isFinite(step) ? step : 1);
185
+ future.push(cur);
186
+ }
187
+ const color = c.color ?? IC.forecast;
188
+ const lastY = s.y[s.y.length - 1];
189
+ note(out, {
190
+ kind: "forecast",
191
+ mark: rm.mark.id,
192
+ series: s.value,
193
+ method: r.method,
194
+ backend: backendName,
195
+ data: { ...r, x: future.map((v) => xValue(v, s.temporal)) },
196
+ summary: `forecast${seriesLabel(rm, s)}: ${r.method}, ${horizon} steps${r.level ? `, ${Math.round(r.level * 100)}% interval` : ""}${r.period ? `, period ${r.period}` : ""}`,
197
+ warnings: warnings.length ? warnings : undefined,
198
+ });
199
+ if (c.show === false)
200
+ return;
201
+ const line = [ff({ x: xValue(last, s.temporal), y: Number.isFinite(lastY) ? lastY : null }), ...future.map((x, h) => ff({ x: xValue(x, s.temporal), y: r.point[h] }))];
202
+ if (r.level) {
203
+ const band = future.map((x, h) => ff({ x: xValue(x, s.temporal), lower: r.lower[h], upper: r.upper[h] }));
204
+ band.unshift(ff({ x: xValue(last, s.temporal), lower: Number.isFinite(lastY) ? lastY : null, upper: Number.isFinite(lastY) ? lastY : null }));
205
+ out.marks.push(createMark("areaY", band, { ...fo, x: "x", y1: "lower", y2: "upper", fill: color, fillOpacity: 0.15, silent: true, legend: false, id: `${rm.mark.id}:forecast-band:${s.key ?? ""}`, z2: -1 }, true));
206
+ }
207
+ out.marks.push(createMark("lineY", line, { ...fo, x: "x", y: "y", stroke: color, strokeWidth: 1.5, strokeDasharray: "5 3", id: `${rm.mark.id}:forecast:${s.key ?? ""}`, name: `forecast (${r.method})`, z2: 2 }, true));
208
+ if (c.shade !== false) {
209
+ out.marks.push(createMark("ruleX", [ff({ x: xValue(last, s.temporal) })], { ...fo, x: "x", stroke: color, strokeOpacity: 0.5, strokeDasharray: "2 2", id: `${rm.mark.id}:forecast-start:${s.key ?? ""}` }, true));
210
+ }
211
+ if (c.fitted) {
212
+ const fit = s.index.map((_, j) => ff({ x: xValue(s.x[j], s.temporal), y: Number.isFinite(r.fitted[j]) ? r.fitted[j] : null }));
213
+ out.marks.push(createMark("lineY", fit, { ...fo, x: "x", y: "y", stroke: color, strokeOpacity: 0.5, strokeWidth: 1, id: `${rm.mark.id}:fitted:${s.key ?? ""}` }, true));
214
+ }
215
+ }
216
+ // ---------------------------------------------------------- changepoints ---
217
+ function runChangepoints(rm, s, c, out, ff, fo, backendName) {
218
+ if (s.y.filter(Number.isFinite).length < 10)
219
+ return;
220
+ const r = getBackend().changepoints(s.y, { method: c.method, model: c.model, minSegment: c.minSegment, maxChangepoints: c.maxChangepoints, penalty: c.penalty });
221
+ const color = c.color ?? IC.changepoint;
222
+ const n = r.indices.length;
223
+ const when = r.indices.slice(0, 3).map((j) => formatValue(xValue(s.x[j], s.temporal)));
224
+ note(out, {
225
+ kind: "changepoints",
226
+ mark: rm.mark.id,
227
+ series: s.value,
228
+ method: r.method,
229
+ backend: backendName,
230
+ data: { ...r, x: r.indices.map((j) => xValue(s.x[j], s.temporal)) },
231
+ summary: n === 0 ? `no changepoints${seriesLabel(rm, s)}` : `${n} changepoint${n === 1 ? "" : "s"}${seriesLabel(rm, s)} at ${when.join(", ")}${n > 3 ? ", …" : ""}`,
232
+ });
233
+ if (c.show === false || n === 0)
234
+ return;
235
+ out.marks.push(createMark("ruleX", r.indices.map((j) => ff({ x: xValue(s.x[j], s.temporal) })), { ...fo, x: "x", stroke: color, strokeDasharray: "4 2", strokeWidth: 1.5, id: `${rm.mark.id}:changepoints:${s.key ?? ""}`, z2: 2 }, true));
236
+ if (c.segments !== false) {
237
+ const bounds = [0, ...r.indices, s.x.length - 1];
238
+ const segs = r.segmentMeans.map((m, k) => ff({ x1: xValue(s.x[bounds[k]], s.temporal), x2: xValue(s.x[Math.min(bounds[k + 1], s.x.length - 1)], s.temporal), y: m }));
239
+ out.marks.push(createMark("ruleY", segs, { ...fo, y: "y", x1: "x1", x2: "x2", stroke: color, strokeOpacity: 0.8, strokeWidth: 1.5, id: `${rm.mark.id}:segments:${s.key ?? ""}`, z2: 2 }, true));
240
+ }
241
+ }
242
+ // ----------------------------------------------------------- seasonality ---
243
+ function runSeasonality(rm, s, c, out, backendName) {
244
+ if (s.y.filter(Number.isFinite).length < 12)
245
+ return;
246
+ const r = getBackend().seasonality(s.y, { method: c.method, minPeriod: c.minPeriod, maxPeriod: c.maxPeriod, threshold: c.threshold, minStrength: c.minStrength });
247
+ const step = medianStep(s.x);
248
+ const unit = s.temporal && Number.isFinite(step) ? guessTimeInterval(step).name : undefined;
249
+ const describe = (p) => {
250
+ if (!unit)
251
+ return String(p);
252
+ const named = { "day:7": "weekly", "day:365": "yearly", "day:366": "yearly", "month:12": "yearly", "month:3": "quarterly", "hour:24": "daily", "hour:168": "weekly", "minute:60": "hourly", "week:52": "yearly", "quarter:4": "yearly" };
253
+ const n = named[`${unit}:${p}`];
254
+ return n ? `${p} ${unit}s (${n})` : `${p} ${unit}${p === 1 ? "" : "s"}`;
255
+ };
256
+ note(out, {
257
+ kind: "seasonality",
258
+ mark: rm.mark.id,
259
+ series: s.value,
260
+ method: r.method,
261
+ backend: backendName,
262
+ data: r,
263
+ summary: r.periods.length === 0 ? `no seasonality${seriesLabel(rm, s)}` : `seasonality${seriesLabel(rm, s)}: period ${describe(r.periods[0])} (strength ${r.strengths[0].toFixed(2)})${r.periods.length > 1 ? `, also ${r.periods.slice(1, 3).map(describe).join(", ")}` : ""}`,
264
+ });
265
+ }
266
+ // ----------------------------------------------------------------- trend ---
267
+ function runTrend(rm, s, c, out, ff, fo, backendName) {
268
+ if (s.y.filter(Number.isFinite).length < 3)
269
+ return;
270
+ const r = getBackend().trend(s.x, s.y, c.method ?? "ols");
271
+ const color = c.color ?? IC.trend;
272
+ const total = r.slope * (s.x[s.x.length - 1] - s.x[0]);
273
+ note(out, {
274
+ kind: "trend",
275
+ mark: rm.mark.id,
276
+ series: s.value,
277
+ method: r.method,
278
+ backend: backendName,
279
+ data: r,
280
+ summary: `trend${seriesLabel(rm, s)}: ${total >= 0 ? "+" : ""}${formatValue(total)} ${s.temporal ? "over the period" : "across the x range"} (R² ${Number.isFinite(r.r2) ? r.r2.toFixed(2) : "–"})`,
281
+ });
282
+ if (c.show === false)
283
+ return;
284
+ const pts = [0, s.x.length - 1].map((j) => ff({ x: xValue(s.x[j], s.temporal), y: r.fitted[j] }));
285
+ out.marks.push(createMark("lineY", pts, { ...fo, x: "x", y: "y", stroke: color, strokeDasharray: "6 3", strokeWidth: 1.5, id: `${rm.mark.id}:trend:${s.key ?? ""}`, name: `trend (${r.method})`, z2: 2 }, true));
286
+ }
287
+ // ---------------------------------------------------------- frequencies ---
288
+ /** Category → total height for ordinal bar marks. */
289
+ function categoryTotals(rm, I) {
290
+ const horizontal = rm.mark.type === "barX" || rm.mark.type === "rectX";
291
+ const K = horizontal ? rm.channels.y : rm.channels.x;
292
+ if (!K || inferType(K) !== "ordinal")
293
+ return undefined;
294
+ const B1 = horizontal ? rm.channels.x1 : rm.channels.y1;
295
+ const B2 = horizontal ? (rm.channels.x2 ?? rm.channels.x) : (rm.channels.y2 ?? rm.channels.y);
296
+ if (!B2)
297
+ return undefined;
298
+ const groups = new Map();
299
+ for (const i of I) {
300
+ const k = keyof(K[i]);
301
+ if (k === null)
302
+ continue;
303
+ let g = groups.get(k);
304
+ if (!g)
305
+ groups.set(k, (g = { v: K[i], total: 0, rows: [] }));
306
+ const h = toNumber(B2[i]) - (B1 ? toNumber(B1[i]) : 0);
307
+ if (Number.isFinite(h))
308
+ g.total += h;
309
+ g.rows.push(i);
310
+ }
311
+ const list = [...groups.values()];
312
+ return { values: list.map((g) => g.v), totals: Float64Array.from(list, (g) => g.total), rows: list.map((g) => g.rows) };
313
+ }
314
+ function runFrequencyOutliers(rm, I, c, out, ff, fo, backendName) {
315
+ if (!BAR_MARKS.has(rm.mark.type))
316
+ return;
317
+ const cats = categoryTotals(rm, I);
318
+ if (!cats || cats.values.length < 3)
319
+ return;
320
+ const r = getBackend().frequencyOutliers(cats.totals, c.sensitivity, c.threshold);
321
+ const name = (k) => formatValue(cats.values[k]);
322
+ const parts = [];
323
+ if (r.rare.length)
324
+ parts.push(`rare: ${r.rare.map(name).join(", ")}`);
325
+ if (r.dominant.length)
326
+ parts.push(`dominant: ${r.dominant.map(name).join(", ")}`);
327
+ note(out, { kind: "frequencyOutliers", mark: rm.mark.id, method: "robust-z(log count)", backend: backendName, data: { ...r, categories: cats.values }, summary: parts.length ? `frequency outliers — ${parts.join("; ")}` : "no frequency outliers" });
328
+ if (c.show === false)
329
+ return;
330
+ const single = groupSeries(rm, I).length === 1;
331
+ const horizontal = rm.mark.type === "barX" || rm.mark.type === "rectX";
332
+ const labels = [];
333
+ for (const [list, kind] of [[r.rare, "rare"], [r.dominant, "dominant"]]) {
334
+ const color = c.color ?? IC[kind];
335
+ for (const k of list) {
336
+ if (single)
337
+ for (const i of cats.rows[k])
338
+ highlight(out, rm.mark.id, i, { color });
339
+ labels.push(ff(horizontal ? { x: cats.totals[k], y: cats.values[k], text: kind, color } : { x: cats.values[k], y: cats.totals[k], text: kind, color }));
340
+ }
341
+ }
342
+ if (labels.length) {
343
+ out.marks.push(createMark("text", labels, { ...fo, x: "x", y: "y", text: "text", fill: c.color ?? IC.anomaly, fontSize: 10, fontWeight: "bold", position: horizontal ? "right" : "top", id: `${rm.mark.id}:frequency-labels`, z2: 6 }, true));
344
+ }
345
+ }
346
+ // ------------------------------------------------------------ categories ---
347
+ function runCategoryOutliers(rm, I, c, out, ff, fo, backendName) {
348
+ const horizontal = rm.mark.type === "barX" || rm.mark.type === "rectX";
349
+ const K = horizontal ? rm.channels.y : rm.channels.x;
350
+ const V = horizontal ? (rm.channels.x2 ?? rm.channels.x) : (rm.channels.y2 ?? rm.channels.y);
351
+ if (!K || !V || inferType(K) !== "ordinal")
352
+ return;
353
+ const B1 = horizontal ? rm.channels.x1 : rm.channels.y1;
354
+ const Z = rm.channels.z ?? rm.channels.fill ?? rm.channels.stroke;
355
+ const domain = new Map();
356
+ const seriesIndex = new Map();
357
+ const codes = new Int32Array(I.length);
358
+ const scodes = new Int32Array(I.length);
359
+ const values = new Float64Array(I.length);
360
+ I.forEach((i, j) => {
361
+ const k = keyof(K[i]);
362
+ if (k === null) {
363
+ codes[j] = -1;
364
+ return;
365
+ }
366
+ let d = domain.get(k);
367
+ if (!d)
368
+ domain.set(k, (d = { v: K[i], code: domain.size }));
369
+ codes[j] = d.code;
370
+ const sk = Z ? keyof(Z[i]) : null;
371
+ let si = seriesIndex.get(sk);
372
+ if (si === undefined)
373
+ seriesIndex.set(sk, (si = seriesIndex.size));
374
+ scodes[j] = si;
375
+ values[j] = toNumber(V[i]) - (B1 ? toNumber(B1[i]) : 0);
376
+ });
377
+ if (domain.size < 3)
378
+ return;
379
+ const reducer = typeof c.reduce === "string" ? c.reduce : undefined;
380
+ const backend = getBackend();
381
+ // Category level: compare each category's aggregate with the others.
382
+ const r = backend.categoryOutliers(codes, values, domain.size, reducer, c.sensitivity, c.threshold);
383
+ // Within level: a point against its own (category × series) group.
384
+ const nSeries = Math.max(1, seriesIndex.size);
385
+ const combined = Int32Array.from(codes, (cc, j) => (cc < 0 ? -1 : cc * nSeries + scodes[j]));
386
+ const rw = nSeries > 1 ? backend.categoryOutliers(combined, values, domain.size * nSeries, reducer, c.sensitivity, c.threshold) : r;
387
+ const cats = [...domain.values()];
388
+ const name = (k) => formatValue(cats[k].v);
389
+ const within = c.within === false || BAR_MARKS.has(rm.mark.type) ? [] : rw.within;
390
+ const parts = [];
391
+ if (r.categories.length)
392
+ parts.push(`outlying categor${r.categories.length === 1 ? "y" : "ies"}: ${r.categories.map((k) => `${name(k)} (z ${r.scores[k].toFixed(1)})`).join(", ")}`);
393
+ if (within.length)
394
+ parts.push(`${within.length} within-category outlier${within.length === 1 ? "" : "s"}`);
395
+ note(out, {
396
+ kind: "categoryOutliers",
397
+ mark: rm.mark.id,
398
+ method: `robust-z(${reducer ?? "median"})`,
399
+ backend: backendName,
400
+ data: { ...r, within, withinScores: rw.withinScores, categories: cats.map((d) => d.v) },
401
+ summary: parts.length ? parts.join("; ") : "no category outliers",
402
+ });
403
+ if (c.show === false)
404
+ return;
405
+ const color = c.color ?? IC.outlier;
406
+ const single = groupSeries(rm, I).length === 1;
407
+ const isBar = BAR_MARKS.has(rm.mark.type);
408
+ const labels = [];
409
+ for (const k of r.categories) {
410
+ I.forEach((i, j) => {
411
+ if (codes[j] !== k)
412
+ return;
413
+ if (isBar && single)
414
+ highlight(out, rm.mark.id, i, { color });
415
+ else if (!isBar)
416
+ highlight(out, rm.mark.id, i, { border: color });
417
+ });
418
+ const agg = r.aggregates[k];
419
+ labels.push(ff(horizontal ? { x: agg, y: cats[k].v, text: `z ${r.scores[k].toFixed(1)}` } : { x: cats[k].v, y: agg, text: `z ${r.scores[k].toFixed(1)}` }));
420
+ }
421
+ for (const j of within)
422
+ highlight(out, rm.mark.id, I[j], { color, size: 10 });
423
+ if (labels.length)
424
+ out.marks.push(createMark("text", labels, { ...fo, x: "x", y: "y", text: "text", fill: color, fontSize: 10, fontWeight: "bold", position: horizontal ? "right" : "top", id: `${rm.mark.id}:category-labels`, z2: 6 }, true));
425
+ }
426
+ // ---------------------------------------------------------------- series ---
427
+ function runSeriesOutliers(rm, series, c, out, ff, fo, backendName) {
428
+ if (series.length < 3)
429
+ return;
430
+ // Align every series on the union of x positions.
431
+ const xsSet = new Set();
432
+ for (const s of series)
433
+ for (const x of s.x)
434
+ xsSet.add(x);
435
+ const xs = [...xsSet].sort((a, b) => a - b);
436
+ const pos = new Map(xs.map((x, i) => [x, i]));
437
+ const aligned = series.map((s) => {
438
+ const a = new Float64Array(xs.length).fill(NaN);
439
+ s.x.forEach((x, j) => (a[pos.get(x)] = s.y[j]));
440
+ return a;
441
+ });
442
+ const method = c.method ?? "dbscan";
443
+ const r = getBackend().seriesOutliers(aligned, method, c.sensitivity);
444
+ const warnings = backendName === "js" && method === "dbscan" ? ["dbscan needs the wasm backend; used mad"] : undefined;
445
+ const names = r.outlying.map((k) => series[k].name);
446
+ note(out, { kind: "seriesOutliers", mark: rm.mark.id, method: r.method, backend: backendName, data: { ...r, series: series.map((s) => s.name) }, summary: names.length ? `outlying series: ${names.join(", ")}` : "no outlying series", warnings });
447
+ if (c.show === false || r.outlying.length === 0)
448
+ return;
449
+ const color = c.color ?? IC.seriesOutlier;
450
+ let styles = out.seriesStyles.get(rm.mark.id);
451
+ if (!styles)
452
+ out.seriesStyles.set(rm.mark.id, (styles = new Map()));
453
+ const outlying = new Set(r.outlying);
454
+ series.forEach((s, k) => styles.set(s.key, outlying.has(k) ? { color, width: 2.5 } : { opacity: 0.35 }));
455
+ if (c.band !== false && r.bandMin.some(Number.isFinite)) {
456
+ const temporal = series[0].temporal;
457
+ const band = xs.map((x, i) => ff({ x: xValue(x, temporal), lower: Number.isFinite(r.bandMin[i]) ? r.bandMin[i] : null, upper: Number.isFinite(r.bandMax[i]) ? r.bandMax[i] : null }));
458
+ out.marks.push(createMark("areaY", band, { ...fo, x: "x", y1: "lower", y2: "upper", fill: IC.band, fillOpacity: 0.1, silent: true, legend: false, id: `${rm.mark.id}:series-band`, z2: -1 }, true));
459
+ }
460
+ }
461
+ //# sourceMappingURL=index.js.map