@rtemis/draw 0.1.1 → 0.3.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 (51) hide show
  1. package/README.md +12 -0
  2. package/dist/charts/bar/config.d.ts +64 -0
  3. package/dist/charts/bar/config.d.ts.map +1 -0
  4. package/dist/charts/bar/config.js +172 -0
  5. package/dist/charts/bar/config.js.map +1 -0
  6. package/dist/charts/bar/index.d.ts +3 -0
  7. package/dist/charts/bar/index.d.ts.map +1 -0
  8. package/dist/charts/bar/index.js +2 -0
  9. package/dist/charts/bar/index.js.map +1 -0
  10. package/dist/charts/line/config.d.ts +104 -0
  11. package/dist/charts/line/config.d.ts.map +1 -0
  12. package/dist/charts/line/config.js +372 -0
  13. package/dist/charts/line/config.js.map +1 -0
  14. package/dist/charts/line/index.d.ts +3 -0
  15. package/dist/charts/line/index.d.ts.map +1 -0
  16. package/dist/charts/line/index.js +2 -0
  17. package/dist/charts/line/index.js.map +1 -0
  18. package/dist/index.d.ts +27 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +19 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/rtemis-draw-builders.cjs +832 -2
  23. package/dist/shared/format.d.ts +14 -0
  24. package/dist/shared/format.d.ts.map +1 -0
  25. package/dist/shared/format.js +27 -0
  26. package/dist/shared/format.js.map +1 -0
  27. package/dist/shared/labels.d.ts +21 -0
  28. package/dist/shared/labels.d.ts.map +1 -0
  29. package/dist/shared/labels.js +31 -0
  30. package/dist/shared/labels.js.map +1 -0
  31. package/dist/shared/layout.d.ts +29 -0
  32. package/dist/shared/layout.d.ts.map +1 -0
  33. package/dist/shared/layout.js +59 -0
  34. package/dist/shared/layout.js.map +1 -0
  35. package/dist/shared/legend.d.ts +14 -0
  36. package/dist/shared/legend.d.ts.map +1 -0
  37. package/dist/shared/legend.js +2 -0
  38. package/dist/shared/legend.js.map +1 -0
  39. package/dist/shared/limits.d.ts +32 -0
  40. package/dist/shared/limits.d.ts.map +1 -0
  41. package/dist/shared/limits.js +62 -0
  42. package/dist/shared/limits.js.map +1 -0
  43. package/dist/shared/source.d.ts +57 -0
  44. package/dist/shared/source.d.ts.map +1 -0
  45. package/dist/shared/source.js +71 -0
  46. package/dist/shared/source.js.map +1 -0
  47. package/dist/theme/tokens.d.ts +76 -0
  48. package/dist/theme/tokens.d.ts.map +1 -0
  49. package/dist/theme/tokens.js +207 -0
  50. package/dist/theme/tokens.js.map +1 -0
  51. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Number formatting shared by the builders' tooltips and labels.
3
+ * spec: draw/shared-builders#numbers
4
+ */
5
+ /** Significant digits a non-integer is shown with. */
6
+ export declare const SIGNIFICANT_DIGITS = 3;
7
+ /**
8
+ * A number as text with `digits` significant digits: an integer as it is; a
9
+ * non-integer rounded to `digits` significant digits, keeping every digit of
10
+ * its integer part, in exponent form below 1e-3 or from 1e15; anything that
11
+ * is not a finite number as it is.
12
+ */
13
+ export declare function formatNumber(value: unknown, digits?: number): unknown;
14
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/shared/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAqB,GAAG,OAAO,CASjF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Number formatting shared by the builders' tooltips and labels.
3
+ * spec: draw/shared-builders#numbers
4
+ */
5
+ /** Significant digits a non-integer is shown with. */
6
+ export const SIGNIFICANT_DIGITS = 3;
7
+ /**
8
+ * A number as text with `digits` significant digits: an integer as it is; a
9
+ * non-integer rounded to `digits` significant digits, keeping every digit of
10
+ * its integer part, in exponent form below 1e-3 or from 1e15; anything that
11
+ * is not a finite number as it is.
12
+ */
13
+ export function formatNumber(value, digits = SIGNIFICANT_DIGITS) {
14
+ if (typeof value !== "number" || !Number.isFinite(value))
15
+ return value;
16
+ if (Number.isInteger(value))
17
+ return String(value);
18
+ const magnitude = Math.abs(value);
19
+ if (magnitude < 1e-3 || magnitude >= 1e15)
20
+ return value.toExponential(digits - 1);
21
+ if (Math.floor(Math.log10(magnitude)) + 1 >= digits)
22
+ return value.toFixed(0);
23
+ const rounded = Number(value.toPrecision(digits));
24
+ const decimals = Math.max(0, digits - 1 - Math.floor(Math.log10(Math.abs(rounded))));
25
+ return rounded.toFixed(decimals);
26
+ }
27
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/shared/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,MAAM,GAAG,kBAAkB;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,SAAS,GAAG,IAAI,IAAI,SAAS,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClF,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,IAAI,MAAM;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7E,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Axis names a host derives from a config when the author sets none.
3
+ * spec: draw/shared-builders#bar
4
+ */
5
+ import { type ColumnNames } from "./source.ts";
6
+ /** The value-axis members a measure is named from. */
7
+ export interface MeasureMembers {
8
+ readonly y?: ColumnNames | null;
9
+ readonly aggregate?: "none" | "sum" | "mean" | "median";
10
+ }
11
+ /**
12
+ * The name of a value axis: the measure the chart shows. With `y` unset,
13
+ * "Count" (a bar chart counting rows); one `y` column gives its name, prefixed
14
+ * by the aggregate ("Mean X", "Median X", "Sum of X"); several give the
15
+ * aggregate alone, or `null` without one, since the legend names each
16
+ * series. `name` maps a column name to its display text. Hosts set it as the
17
+ * value axis's name unless the author set one. rtemis.draw's `resolve()`
18
+ * derives the same text.
19
+ */
20
+ export declare function valueLabel(config: MeasureMembers, name?: (column: string) => string): string | null;
21
+ //# sourceMappingURL=labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/shared/labels.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,sDAAsD;AACtD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;CACzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,cAAc,EACtB,IAAI,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAA2B,GACpD,MAAM,GAAG,IAAI,CAcf"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Axis names a host derives from a config when the author sets none.
3
+ * spec: draw/shared-builders#bar
4
+ */
5
+ import { asArray } from "./source.js";
6
+ /**
7
+ * The name of a value axis: the measure the chart shows. With `y` unset,
8
+ * "Count" (a bar chart counting rows); one `y` column gives its name, prefixed
9
+ * by the aggregate ("Mean X", "Median X", "Sum of X"); several give the
10
+ * aggregate alone, or `null` without one, since the legend names each
11
+ * series. `name` maps a column name to its display text. Hosts set it as the
12
+ * value axis's name unless the author set one. rtemis.draw's `resolve()`
13
+ * derives the same text.
14
+ */
15
+ export function valueLabel(config, name = (column) => column) {
16
+ const ys = asArray(config.y);
17
+ if (ys.length === 0)
18
+ return "Count";
19
+ const only = ys.length === 1 ? name(ys[0]) : null;
20
+ switch (config.aggregate ?? "none") {
21
+ case "mean":
22
+ return only === null ? "Mean" : `Mean ${only}`;
23
+ case "median":
24
+ return only === null ? "Median" : `Median ${only}`;
25
+ case "sum":
26
+ return only === null ? "Sum" : `Sum of ${only}`;
27
+ default:
28
+ return only;
29
+ }
30
+ }
31
+ //# sourceMappingURL=labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.js","sourceRoot":"","sources":["../../src/shared/labels.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAoB,MAAM,aAAa,CAAC;AAQxD;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,MAAsB,EACtB,OAAmC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;IAErD,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACpC,MAAM,IAAI,GAAG,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5D,QAAQ,MAAM,CAAC,SAAS,IAAI,MAAM,EAAE,CAAC;QACnC,KAAK,MAAM;YACT,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;QACjD,KAAK,QAAQ;YACX,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC;QACrD,KAAK,KAAK;YACR,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC;QAClD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Grid margins and zoom presets shared by the cartesian builders.
3
+ * spec: draw/shared-builders#appearance
4
+ */
5
+ /** The four plot-margin members of a config. */
6
+ export interface MarginMembers {
7
+ readonly margin_top?: number | null;
8
+ readonly margin_right?: number | null;
9
+ readonly margin_bottom?: number | null;
10
+ readonly margin_left?: number | null;
11
+ }
12
+ /** Margin in pixels on every side when a config sets none. */
13
+ export declare const DEFAULT_MARGIN = 36;
14
+ /**
15
+ * The grid of a cartesian chart. With no margin member set, every side takes
16
+ * {@link DEFAULT_MARGIN}; otherwise only the sides set are fixed. The grid's
17
+ * outer bounds hold the axis labels, and the axis names when an axis has one.
18
+ */
19
+ export declare function cartesianGrid(config: MarginMembers, axisNames: boolean): Record<string, unknown>;
20
+ /** Identifies the slider of a zoom preset, so static export can return its band. */
21
+ export declare const ZOOM_SLIDER_ID = "rtemis-zoom-slider";
22
+ /**
23
+ * The zoom preset on one axis: a slider placed in a band the grid reserves on
24
+ * the axis side, and an inside zoom on Shift+wheel with drag panning, so the
25
+ * plain wheel scrolls the host page. Mutates `grid` to reserve the band.
26
+ * spec: draw/zoom-controls#design
27
+ */
28
+ export declare function axisZoom(axis: "x" | "y", grid: Record<string, unknown>): Record<string, unknown>[];
29
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/shared/layout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,8DAA8D;AAC9D,eAAO,MAAM,cAAc,KAAK,CAAC;AAKjC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWhG;AAED,oFAAoF;AACpF,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAQnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,GAAG,GAAG,GAAG,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAkB3B"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Grid margins and zoom presets shared by the cartesian builders.
3
+ * spec: draw/shared-builders#appearance
4
+ */
5
+ /** Margin in pixels on every side when a config sets none. */
6
+ export const DEFAULT_MARGIN = 36;
7
+ const SIDES = ["top", "right", "bottom", "left"];
8
+ /**
9
+ * The grid of a cartesian chart. With no margin member set, every side takes
10
+ * {@link DEFAULT_MARGIN}; otherwise only the sides set are fixed. The grid's
11
+ * outer bounds hold the axis labels, and the axis names when an axis has one.
12
+ */
13
+ export function cartesianGrid(config, axisNames) {
14
+ const set = SIDES.filter((side) => typeof config[`margin_${side}`] === "number");
15
+ const grid = {};
16
+ for (const side of SIDES) {
17
+ const value = config[`margin_${side}`];
18
+ if (set.length === 0)
19
+ grid[side] = DEFAULT_MARGIN;
20
+ else if (typeof value === "number")
21
+ grid[side] = value;
22
+ }
23
+ grid.outerBoundsMode = "same";
24
+ grid.outerBoundsContain = axisNames ? "all" : "axisLabel";
25
+ return grid;
26
+ }
27
+ /** Identifies the slider of a zoom preset, so static export can return its band. */
28
+ export const ZOOM_SLIDER_ID = "rtemis-zoom-slider";
29
+ // ECharts' slider filler size, the brush handle drawn outside it, the gap to
30
+ // the plot, and its default grid margin on each side (SliderZoomView.ts).
31
+ const SLIDER_SIZE = 30;
32
+ const SLIDER_HANDLE = 7;
33
+ const SLIDER_GAP = 8;
34
+ /**
35
+ * The zoom preset on one axis: a slider placed in a band the grid reserves on
36
+ * the axis side, and an inside zoom on Shift+wheel with drag panning, so the
37
+ * plain wheel scrolls the host page. Mutates `grid` to reserve the band.
38
+ * spec: draw/zoom-controls#design
39
+ */
40
+ export function axisZoom(axis, grid) {
41
+ const side = axis === "x" ? "bottom" : "right";
42
+ const current = grid[side];
43
+ const margin = typeof current === "number" ? current : axis === "x" ? 80 : 15;
44
+ const index = axis === "x" ? { xAxisIndex: 0 } : { yAxisIndex: 0 };
45
+ grid[side] = margin + SLIDER_HANDLE + SLIDER_SIZE + SLIDER_GAP;
46
+ return [
47
+ {
48
+ type: "slider",
49
+ id: ZOOM_SLIDER_ID,
50
+ start: 0,
51
+ end: 100,
52
+ ...index,
53
+ [side]: margin + SLIDER_HANDLE,
54
+ ...(axis === "x" ? { height: SLIDER_SIZE } : { width: SLIDER_SIZE }),
55
+ },
56
+ { type: "inside", ...index, zoomOnMouseWheel: "shift", moveOnMouseMove: true },
57
+ ];
58
+ }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,UAAU,QAAQ,CACtB,IAAe,EACf,IAA6B;IAE7B,MAAM,IAAI,GAAS,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9E,MAAM,KAAK,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACnE,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;IAC/D,OAAO;QACL;YACE,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,cAAc;YAClB,KAAK,EAAE,CAAC;YACR,GAAG,EAAE,GAAG;YACR,GAAG,KAAK;YACR,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa;YAC9B,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;SACrE;QACD,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE;KAC/E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The legend members of a config. rtemis.draw's widget and SVG export place
3
+ * the legend from them after the option is built.
4
+ * spec: draw/shared-builders#appearance
5
+ */
6
+ export interface LegendMembers {
7
+ /** Edge or corner of the plotting area the legend anchors to. Default `"top"`. */
8
+ readonly legend_position?: "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
9
+ /** Outside or inside the plotting area. Default `"outside"`. */
10
+ readonly legend_placement?: "outside" | "inside";
11
+ /** Legend title; unset draws none. */
12
+ readonly legend_title?: string | null;
13
+ }
14
+ //# sourceMappingURL=legend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/shared/legend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,eAAe,CAAC,EACrB,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,CAAC;IACnB,gEAAgE;IAChE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjD,sCAAsC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=legend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legend.js","sourceRoot":"","sources":["../../src/shared/legend.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Axis limits derived from data, shared by the cartesian builders. They equal
3
+ * rtemis.draw's `calc_limits()` and `equal_axis_limits()`, which `resolve()`
4
+ * runs to record the limits in a config. spec: draw/shared-builders#line
5
+ */
6
+ /** An axis's `[min, max]`. */
7
+ export type AxisLimits = readonly [number, number];
8
+ /** Fraction of the data range each axis extends by when its limits are unset. */
9
+ export declare const DEFAULT_PAD = 0.04;
10
+ /**
11
+ * The range of the finite values extended by `pad` times the range on each
12
+ * side, or `null` without a finite value. A range of zero extends by `pad`
13
+ * times a tenth of the value's magnitude.
14
+ */
15
+ export declare function calcLimits(values: readonly unknown[], pad?: number): AxisLimits | null;
16
+ /**
17
+ * The limits of an axis that shows magnitudes from zero, such as a filled
18
+ * area's: the range of the finite values and zero, extended by `pad` times
19
+ * that range on each side away from zero, so zero is an end of the axis when
20
+ * the values do not cross it. `null` without a finite value.
21
+ */
22
+ export declare function calcLimitsFromZero(values: readonly unknown[], pad?: number): AxisLimits | null;
23
+ /**
24
+ * The limits of a plot that is both square and equally scaled, whose two axes
25
+ * span one interval: the limits given for either axis, or the padded range of
26
+ * both axes' values. Either request alone leaves the limits as given.
27
+ */
28
+ export declare function equalAxisLimits(x: readonly unknown[] | null, y: readonly unknown[], xlim: AxisLimits | null, ylim: AxisLimits | null, pad: number, square: boolean, equalAxes: boolean): {
29
+ xlim: AxisLimits | null;
30
+ ylim: AxisLimits | null;
31
+ };
32
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/shared/limits.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnD,iFAAiF;AACjF,eAAO,MAAM,WAAW,OAAO,CAAC;AAEhC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,GAAG,SAAc,GAAG,UAAU,GAAG,IAAI,CAW3F;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,OAAO,EAAE,EAC1B,GAAG,SAAc,GAChB,UAAU,GAAG,IAAI,CAOnB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,EAC5B,CAAC,EAAE,SAAS,OAAO,EAAE,EACrB,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,OAAO,GACjB;IAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;CAAE,CAetD"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Axis limits derived from data, shared by the cartesian builders. They equal
3
+ * rtemis.draw's `calc_limits()` and `equal_axis_limits()`, which `resolve()`
4
+ * runs to record the limits in a config. spec: draw/shared-builders#line
5
+ */
6
+ /** Fraction of the data range each axis extends by when its limits are unset. */
7
+ export const DEFAULT_PAD = 0.04;
8
+ /**
9
+ * The range of the finite values extended by `pad` times the range on each
10
+ * side, or `null` without a finite value. A range of zero extends by `pad`
11
+ * times a tenth of the value's magnitude.
12
+ */
13
+ export function calcLimits(values, pad = DEFAULT_PAD) {
14
+ let min = Number.POSITIVE_INFINITY;
15
+ let max = Number.NEGATIVE_INFINITY;
16
+ for (const v of values) {
17
+ if (typeof v !== "number" || !Number.isFinite(v))
18
+ continue;
19
+ if (v < min)
20
+ min = v;
21
+ if (v > max)
22
+ max = v;
23
+ }
24
+ if (min > max)
25
+ return null;
26
+ const span = max - min === 0 ? Math.abs(min) * 0.1 : max - min;
27
+ return [min - pad * span, max + pad * span];
28
+ }
29
+ /**
30
+ * The limits of an axis that shows magnitudes from zero, such as a filled
31
+ * area's: the range of the finite values and zero, extended by `pad` times
32
+ * that range on each side away from zero, so zero is an end of the axis when
33
+ * the values do not cross it. `null` without a finite value.
34
+ */
35
+ export function calcLimitsFromZero(values, pad = DEFAULT_PAD) {
36
+ const range = calcLimits(values, 0);
37
+ if (!range)
38
+ return null;
39
+ const min = Math.min(range[0], 0);
40
+ const max = Math.max(range[1], 0);
41
+ const span = max - min;
42
+ return [min === 0 ? 0 : min - pad * span, max === 0 ? 0 : max + pad * span];
43
+ }
44
+ /**
45
+ * The limits of a plot that is both square and equally scaled, whose two axes
46
+ * span one interval: the limits given for either axis, or the padded range of
47
+ * both axes' values. Either request alone leaves the limits as given.
48
+ */
49
+ export function equalAxisLimits(x, y, xlim, ylim, pad, square, equalAxes) {
50
+ if (!square || !equalAxes)
51
+ return { xlim, ylim };
52
+ if (xlim && ylim) {
53
+ const same = xlim.every((v, i) => Math.abs(v - ylim[i]) <= 1.5e-8 * Math.max(1, Math.abs(v)));
54
+ if (!same) {
55
+ throw new Error(`\`square\` and \`equal_axes\` together require both axes to span the same interval, but \`xlim\` is [${xlim.join(", ")}] and \`ylim\` is [${ylim.join(", ")}]. Give them the same limits, or unset one of the two.`);
56
+ }
57
+ return { xlim, ylim };
58
+ }
59
+ const common = xlim ?? ylim ?? calcLimits([...(x ?? []), ...y], pad);
60
+ return common ? { xlim: common, ylim: common } : { xlim, ylim };
61
+ }
62
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/shared/limits.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,iFAAiF;AACjF,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC;AAEhC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAA0B,EAAE,GAAG,GAAG,WAAW;IACtE,IAAI,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACnC,IAAI,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACnC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,SAAS;QAC3D,IAAI,CAAC,GAAG,GAAG;YAAE,GAAG,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG;YAAE,GAAG,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,GAAG,GAAG,GAAG;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GA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CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACjF,CAAC;QACF,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,wGAAwG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,wDAAwD,CACrN,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,IAAI,IAAI,IAAI,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Columns by name: an object from column name to the column's values, as an
3
+ * array or a typed array (rtemislive reads numeric columns from Arrow as
4
+ * `Float64Array`, with missing values as `NaN`).
5
+ */
6
+ export type ColumnarSource = Readonly<Record<string, ArrayLike<unknown>>>;
7
+ /**
8
+ * A tabular chart's data: the columns the config binds, and the level order of
9
+ * any categorical column among them. spec: draw/shared-builders#tabular-data
10
+ */
11
+ export interface TabularData {
12
+ readonly columns: ColumnarSource;
13
+ /** Level order of categorical columns, by column name. */
14
+ readonly levels?: Readonly<Record<string, readonly string[]>>;
15
+ /** The type of a column whose values are not read as stored, by column name. */
16
+ readonly types?: Readonly<Record<string, ColumnType>>;
17
+ /**
18
+ * Column holding the number of rows each row stands for, when the host has
19
+ * combined rows. A chart that counts rows sums it; unset, each row is one.
20
+ */
21
+ readonly frequency?: string;
22
+ }
23
+ /**
24
+ * A column type the data declares. `"time"`: a date or date-time, held as
25
+ * epoch milliseconds of its wall-clock reading in UTC, or as ISO 8601 text
26
+ * whose wall-clock fields are read and whose offset is ignored.
27
+ */
28
+ export type ColumnType = "time";
29
+ /** Whether the data declares a column as a time. */
30
+ export declare function isTime(data: TabularData, name: string): boolean;
31
+ /**
32
+ * A time cell as epoch milliseconds of its wall-clock reading in UTC, or
33
+ * `null` for a missing or unreadable one. Charts place and label times in UTC,
34
+ * so a time reads the same wherever it is viewed.
35
+ */
36
+ export declare function timeMs(value: unknown): number | null;
37
+ /** A time as text in UTC: the date at midnight, otherwise the date and the time. */
38
+ export declare function timeLabel(ms: number): string;
39
+ /** The values of a column as text; a time column's as {@link timeLabel}. */
40
+ export declare function textColumn(data: TabularData, name: string, member: string): string[];
41
+ /**
42
+ * The distinct values of a column in level order: the levels that occur, then
43
+ * values not among the levels in order of appearance.
44
+ */
45
+ export declare function distinct(values: readonly string[], levels?: readonly string[]): string[];
46
+ /** A config member that names one or more columns, as JSON may carry it. */
47
+ export type ColumnNames = string | readonly string[];
48
+ /**
49
+ * The values of a column as an array, or an error naming the column and the
50
+ * member. A typed array is copied, so mapping it to text keeps the text.
51
+ */
52
+ export declare function column(source: ColumnarSource, name: string, member: string): readonly unknown[];
53
+ /** A one-or-many member as an array; a JSON scalar is one element. */
54
+ export declare function asArray<T>(value: T | readonly T[] | null | undefined): readonly T[];
55
+ /** A numeric cell, or `null` for a missing or non-finite one. */
56
+ export declare function numberOrNull(value: unknown): number | null;
57
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/shared/source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAA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GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC,EAAE,CAGnF;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAE1D"}
@@ -0,0 +1,71 @@
1
+ /** Whether the data declares a column as a time. */
2
+ export function isTime(data, name) {
3
+ return data.types?.[name] === "time";
4
+ }
5
+ const ISO_TIME = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?)?/;
6
+ /**
7
+ * A time cell as epoch milliseconds of its wall-clock reading in UTC, or
8
+ * `null` for a missing or unreadable one. Charts place and label times in UTC,
9
+ * so a time reads the same wherever it is viewed.
10
+ */
11
+ export function timeMs(value) {
12
+ if (typeof value === "number")
13
+ return Number.isFinite(value) ? value : null;
14
+ if (typeof value !== "string")
15
+ return null;
16
+ const m = ISO_TIME.exec(value);
17
+ if (!m)
18
+ return null;
19
+ const [, y, mo, d, h, mi, s, frac] = m;
20
+ const ms = frac ? Math.round(Number(`0.${frac}`) * 1000) : 0;
21
+ return Date.UTC(Number(y), Number(mo) - 1, Number(d), Number(h ?? 0), Number(mi ?? 0), Number(s ?? 0), ms);
22
+ }
23
+ /** A time as text in UTC: the date at midnight, otherwise the date and the time. */
24
+ export function timeLabel(ms) {
25
+ const iso = new Date(ms).toISOString();
26
+ if (ms % 86_400_000 === 0)
27
+ return iso.slice(0, 10);
28
+ return `${iso.slice(0, 10)} ${iso.slice(11, ms % 1000 === 0 ? 19 : 23)}`;
29
+ }
30
+ /** The values of a column as text; a time column's as {@link timeLabel}. */
31
+ export function textColumn(data, name, member) {
32
+ const values = column(data.columns, name, member);
33
+ if (!isTime(data, name))
34
+ return values.map((v) => String(v));
35
+ return values.map((v) => {
36
+ const ms = timeMs(v);
37
+ return ms === null ? String(v) : timeLabel(ms);
38
+ });
39
+ }
40
+ /**
41
+ * The distinct values of a column in level order: the levels that occur, then
42
+ * values not among the levels in order of appearance.
43
+ */
44
+ export function distinct(values, levels) {
45
+ const seen = new Set(values);
46
+ const ordered = (levels ?? []).filter((level) => seen.has(level));
47
+ const known = new Set(ordered);
48
+ return [...ordered, ...[...seen].filter((v) => !known.has(v))];
49
+ }
50
+ /**
51
+ * The values of a column as an array, or an error naming the column and the
52
+ * member. A typed array is copied, so mapping it to text keeps the text.
53
+ */
54
+ export function column(source, name, member) {
55
+ const values = source[name];
56
+ if (values === undefined) {
57
+ throw new Error(`Column '${name}' (config member '${member}') is not in the data.`);
58
+ }
59
+ return Array.isArray(values) ? values : Array.from(values);
60
+ }
61
+ /** A one-or-many member as an array; a JSON scalar is one element. */
62
+ export function asArray(value) {
63
+ if (value === null || value === undefined)
64
+ return [];
65
+ return Array.isArray(value) ? value : [value];
66
+ }
67
+ /** A numeric cell, or `null` for a missing or non-finite one. */
68
+ export function numberOrNull(value) {
69
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
70
+ }
71
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/shared/source.ts"],"names":[],"mappings":"AA+BA,oDAAoD;AACpD,MAAM,UAAU,MAAM,CAAC,IAAiB,EAAE,IAAY;IACpD,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC;AACvC,CAAC;AAED,MAAM,QAAQ,GAAG,2EAA2E,CAAC;AAE7F;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,CAAC,CAAC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AM,CAAC,CAAC,CAAC,CAAE,MAA6B,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACrF,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,OAAO,CAAI,KAA0C;IACnE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAsB,CAAC,CAAC,CAAC,CAAC,KAAU,CAAC,CAAC;AACvE,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Theme tokens: the constants chosen once for a set of charts, independent of
3
+ * the data and the surface, and their projection to the ECharts theme object.
4
+ * The token document is generated from rtemis.draw's `Theme` class.
5
+ * spec: draw/chart-appearance#the-theme
6
+ */
7
+ /** Light or dark: which set of neutral control colors the projection uses. */
8
+ export type ColorScheme = "light" | "dark";
9
+ /** A theme's tokens. Unset text sizes follow `base_font_size`; unset text colors follow `fg_color`. */
10
+ export interface ThemeTokens {
11
+ readonly scheme: ColorScheme;
12
+ /** Font family or CSS font stack; unset is the system UI font stack. */
13
+ readonly font_family?: string | null;
14
+ readonly base_font_size: number;
15
+ /** Unset is `base_font_size` × 1.2, rounded half to even. */
16
+ readonly title_font_size?: number | null;
17
+ readonly subtitle_font_size?: number | null;
18
+ readonly axis_label_font_size?: number | null;
19
+ readonly legend_font_size?: number | null;
20
+ readonly tooltip_font_size?: number | null;
21
+ /** Categorical palette. */
22
+ readonly palette: readonly string[];
23
+ readonly bg_color: string;
24
+ readonly fg_color: string;
25
+ readonly title_color?: string | null;
26
+ readonly subtitle_color?: string | null;
27
+ readonly legend_color?: string | null;
28
+ readonly axis_color?: string | null;
29
+ readonly grid_color?: string | null;
30
+ readonly tooltip_bg?: string | null;
31
+ readonly tooltip_border_color?: string | null;
32
+ readonly tooltip_color?: string | null;
33
+ /** Colors of negative values, values of neither sign, and positive values. */
34
+ readonly negative_color: string;
35
+ readonly neutral_color: string;
36
+ readonly positive_color: string;
37
+ }
38
+ /** rtemis' categorical palette. */
39
+ export declare const RTEMIS_PALETTE: readonly string[];
40
+ /** Sign colors of equal perceived lightness: blue, gray, orange. */
41
+ export declare const SIGN_COLORS: Readonly<{
42
+ negative: "#2D83D3";
43
+ neutral: "#808080";
44
+ positive: "#C55E28";
45
+ }>;
46
+ /** The light theme's tokens, as rtemis.draw's `theme_light()` sets them. */
47
+ export declare function lightThemeTokens(overrides?: Partial<ThemeTokens>): ThemeTokens;
48
+ /** The dark theme's tokens, as rtemis.draw's `theme_dark()` sets them. */
49
+ export declare function darkThemeTokens(overrides?: Partial<ThemeTokens>): ThemeTokens;
50
+ /** Font stack that follows a font family, and the whole stack when none is set. */
51
+ export declare const DEFAULT_FONT_FAMILY = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
52
+ /**
53
+ * A complete CSS font stack: every family name that is not a sequence of CSS
54
+ * identifiers is quoted, and {@link DEFAULT_FONT_FAMILY} follows unless the
55
+ * stack ends in a generic family. Matches rtemis.draw's `font_stack()`.
56
+ */
57
+ export declare function fontStack(fontFamily?: string | null): string;
58
+ /** The text sizes of a theme, each resolved from `base_font_size` when unset. */
59
+ export declare function themeFontSizes(tokens: ThemeTokens): {
60
+ base: number;
61
+ title: number;
62
+ subtitle: number;
63
+ axisLabel: number;
64
+ legend: number;
65
+ tooltip: number;
66
+ };
67
+ type Json = Record<string, unknown>;
68
+ /**
69
+ * The ECharts theme object of a theme's tokens, for `echarts.registerTheme()`
70
+ * or `chart.setTheme()`. Every component with its own default text size takes
71
+ * the global text style, since a global `textStyle` does not reach them; log
72
+ * and time axes take the value axis's style.
73
+ */
74
+ export declare function themeOption(tokens: ThemeTokens): Json;
75
+ export {};
76
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/theme/tokens.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3C,uGAAuG;AACvG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,6DAA6D;IAC7D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,2BAA2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC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