@rtemis/draw 0.1.1 → 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.
package/README.md CHANGED
@@ -27,11 +27,18 @@ const option = builders.a3(a3Document, config)
27
27
  | Type | Builder | Data | Config schema |
28
28
  |---|---|---|---|
29
29
  | `a3` | `buildA3Option(document, config, appearance)` | an A3 document (`@rtemis/a3` `A3Data`) | `https://schema.rtemis.org/chart/a3/v1/schema.json` |
30
+ | `bar` | `buildBarOption(data, config, appearance)` | tabular data, `{columns, levels}` | `https://schema.rtemis.org/chart/bar/v1/schema.json` |
31
+
32
+ Tabular data holds the columns the config binds, each an array or typed array, and optionally the level order of categorical columns. A bar chart draws one bar per row; with `group`, one bar per distinct category and group, in level order. When `group` or `aggregate` is set, the data must hold one row per category and group: the host combines rows as `aggregate` says (rtemislive in DuckDB, rtemis.draw in R) before building.
30
33
 
31
34
  `appearance` holds what every chart type shares and the config does not: the light or dark theme, the font family, the title inset, the legend gap, and animation. Every member of `config` and `appearance` is optional.
32
35
 
33
36
  `a3SurfaceHints(document, config, appearance)` returns the height that keeps the layout's row spacing, the plot body height, and the glyph sizes, for a renderer that sizes its surface before drawing.
34
37
 
38
+ ## Themes
39
+
40
+ `themeOption(tokens)` projects a theme's tokens (fonts, text sizes, surface colors, the palette, sign colors, axis colors, and gridline colors) to the ECharts theme object a host registers with `echarts.registerTheme()` or `chart.setTheme()`. `lightThemeTokens()` and `darkThemeTokens()` give rtemis.draw's light and dark themes, whose projections equal the objects `theme_light()` and `theme_dark()` register. Builders write no path the theme owns.
41
+
35
42
  ## In rtemis.draw
36
43
 
37
44
  rtemis.draw ships the builders as one script, `r/inst/htmlwidgets/lib/draw/rtemis-draw-builders.js`, which defines the global `RtemisDraw` in a browser and is a CommonJS module in Node.js. The `rtemis-draw` widget declares it as a dependency and builds the option of a `BuildRequest` with it; `save_drawing()` builds the same request in Node.js. From the repository root:
@@ -0,0 +1,59 @@
1
+ import { type MarginMembers } from "../../shared/layout.ts";
2
+ import type { LegendMembers } from "../../shared/legend.ts";
3
+ import { type ColumnNames, type TabularData } from "../../shared/source.ts";
4
+ /**
5
+ * An instance of the `chart/bar/v1` schema, written by rtemis.draw's
6
+ * `BarConfig` class. Every member is optional. spec: draw/shared-builders#bar
7
+ */
8
+ export interface BarChartConfig extends MarginMembers, LegendMembers {
9
+ readonly type?: "bar";
10
+ /** Column holding the categories. */
11
+ readonly x?: string | null;
12
+ /** Columns holding the values, one series each. */
13
+ readonly y?: ColumnNames | null;
14
+ /** Column whose values split each value column into one series per group. */
15
+ readonly group?: string | null;
16
+ /**
17
+ * How rows sharing a category and group combine into one bar. The host
18
+ * applies it to the data before building (rtemislive in DuckDB, rtemis.draw
19
+ * in R); the builder requires one row per category and group when it is set.
20
+ * Default `"none"`: one bar per row.
21
+ */
22
+ readonly aggregate?: "none" | "sum" | "mean" | "median" | "count";
23
+ /** Category order by total value across series. Default `"input"`. */
24
+ readonly order?: "input" | "increasing" | "decreasing";
25
+ /** Stack the series instead of grouping them. Default `false`. */
26
+ readonly stack?: boolean;
27
+ /** Draw the bars horizontally. Default `false`. */
28
+ readonly horizontal?: boolean;
29
+ /** A slider, Shift+wheel zoom, and drag panning on the category axis. Default `false`. */
30
+ readonly zoom?: boolean;
31
+ /** Bar thickness in pixels; unset uses automatic category spacing. */
32
+ readonly bar_width?: number | null;
33
+ /** Series colors, or bar colors for one series; unset uses the theme palette. */
34
+ readonly palette?: ColumnNames | null;
35
+ /** Value axis limits, `[min, max]`; unset fits the data. */
36
+ readonly ylim?: readonly [number, number] | null;
37
+ /** Bottom axis name; unset draws none. */
38
+ readonly xlab?: string | null;
39
+ /** Left axis name; unset draws none. */
40
+ readonly ylab?: string | null;
41
+ /** Chart title. */
42
+ readonly title?: string | null;
43
+ }
44
+ /** What is not chart config: animation. */
45
+ export interface BarAppearance {
46
+ /** Animate the first render and updates; unset leaves the ECharts default. */
47
+ readonly animation?: boolean;
48
+ }
49
+ /** Every member of {@link BarChartConfig}, checked against `chart/bar/v1`. */
50
+ export declare const BAR_CHART_CONFIG_MEMBERS: readonly ["type", "x", "y", "group", "aggregate", "order", "stack", "horizontal", "zoom", "bar_width", "palette", "ylim", "xlab", "ylab", "title", "margin_top", "margin_right", "margin_bottom", "margin_left", "legend_position", "legend_placement", "legend_title"];
51
+ /**
52
+ * Build the ECharts option of a bar chart from tabular data and its
53
+ * `chart/bar/v1` config. One bar per row and series; with `group`, the
54
+ * categories are the distinct `x` values and each group adds a series per
55
+ * value column, empty where a category lacks the group. Distinct categories
56
+ * and groups follow their column's levels, then order of appearance.
57
+ */
58
+ export declare function buildBarOption(data: TabularData, config: BarChartConfig, appearance?: BarAppearance): Record<string, unknown>;
59
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAEL,KAAK,WAAW,EAIhB,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,aAAa,EAAE,aAAa;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAClE,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,CAAC;IACvD,kEAAkE;IAClE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iFAAiF;IACjF,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACtC,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACjD,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,8EAA8E;AAC9E,eAAO,MAAM,wBAAwB,yQAuBkB,CAAC;AAWxD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,cAAc,EACtB,UAAU,GAAE,aAAkB,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2FzB"}
@@ -0,0 +1,151 @@
1
+ import { axisZoom, cartesianGrid } from "../../shared/layout.js";
2
+ import { asArray, column, distinct, numberOrNull, } from "../../shared/source.js";
3
+ /** Every member of {@link BarChartConfig}, checked against `chart/bar/v1`. */
4
+ export const BAR_CHART_CONFIG_MEMBERS = Object.freeze([
5
+ "type",
6
+ "x",
7
+ "y",
8
+ "group",
9
+ "aggregate",
10
+ "order",
11
+ "stack",
12
+ "horizontal",
13
+ "zoom",
14
+ "bar_width",
15
+ "palette",
16
+ "ylim",
17
+ "xlab",
18
+ "ylab",
19
+ "title",
20
+ "margin_top",
21
+ "margin_right",
22
+ "margin_bottom",
23
+ "margin_left",
24
+ "legend_position",
25
+ "legend_placement",
26
+ "legend_title",
27
+ ]);
28
+ const _everyMember = true;
29
+ void _everyMember;
30
+ /**
31
+ * Build the ECharts option of a bar chart from tabular data and its
32
+ * `chart/bar/v1` config. One bar per row and series; with `group`, the
33
+ * categories are the distinct `x` values and each group adds a series per
34
+ * value column, empty where a category lacks the group. Distinct categories
35
+ * and groups follow their column's levels, then order of appearance.
36
+ */
37
+ export function buildBarOption(data, config, appearance = {}) {
38
+ const source = data.columns;
39
+ const yColumns = asArray(config.y);
40
+ if (!config.x || yColumns.length === 0) {
41
+ throw new Error("A bar chart needs both `x` and `y` set to draw.");
42
+ }
43
+ const xs = column(source, config.x, "x").map((v) => String(v));
44
+ const aggregate = config.aggregate ?? "none";
45
+ let categories;
46
+ let series;
47
+ if (config.group) {
48
+ const groupValues = column(source, config.group, "group").map((v) => String(v));
49
+ requireOneRowPer(xs, groupValues);
50
+ categories = distinct(xs, data.levels?.[config.x]);
51
+ const groups = distinct(groupValues, data.levels?.[config.group]);
52
+ const at = new Map(categories.map((c, i) => [c, i]));
53
+ series = groups.flatMap((g) => yColumns.map((y) => {
54
+ const values = column(source, y, "y");
55
+ const data = categories.map(() => null);
56
+ xs.forEach((x, row) => {
57
+ const i = at.get(x);
58
+ if (groupValues[row] === g && i !== undefined)
59
+ data[i] = numberOrNull(values[row]);
60
+ });
61
+ const name = groups.length > 1 ? (yColumns.length > 1 ? `${y} / ${g}` : g) : y;
62
+ return { name, data };
63
+ }));
64
+ }
65
+ else {
66
+ if (aggregate !== "none")
67
+ requireOneRowPer(xs);
68
+ categories = xs;
69
+ series = yColumns.map((y) => ({ name: y, data: column(source, y, "y").map(numberOrNull) }));
70
+ }
71
+ const permutation = order(categories, series, config.order ?? "input");
72
+ categories = permutation.map((i) => categories[i]);
73
+ series = series.map((s) => ({ ...s, data: permutation.map((i) => s.data[i] ?? null) }));
74
+ const palette = asArray(config.palette);
75
+ const stack = config.stack ? "total" : undefined;
76
+ const barWidth = typeof config.bar_width === "number" ? config.bar_width : undefined;
77
+ const builtSeries = series.map((s, i) => {
78
+ const single = series.length === 1;
79
+ const perBar = single && palette.length > 1;
80
+ const color = perBar ? undefined : palette.length > 0 ? palette[i % palette.length] : undefined;
81
+ return {
82
+ type: "bar",
83
+ ...(single ? {} : { name: s.name }),
84
+ data: perBar
85
+ ? s.data.map((value, j) => ({
86
+ value,
87
+ itemStyle: { color: palette[(permutation[j] ?? j) % palette.length] },
88
+ }))
89
+ : s.data,
90
+ ...(stack ? { stack } : {}),
91
+ ...(barWidth === undefined ? {} : { barWidth }),
92
+ ...(color === undefined ? {} : { itemStyle: { color } }),
93
+ };
94
+ });
95
+ const horizontal = config.horizontal ?? false;
96
+ const category = {
97
+ type: "category",
98
+ data: categories,
99
+ axisPointer: { type: "none" },
100
+ axisTick: { show: false },
101
+ };
102
+ const value = {
103
+ type: "value",
104
+ axisTick: { show: false },
105
+ ...(config.ylim ? { min: config.ylim[0], max: config.ylim[1] } : {}),
106
+ };
107
+ const xAxis = horizontal ? value : category;
108
+ const yAxis = horizontal ? category : value;
109
+ if (config.xlab)
110
+ Object.assign(xAxis, { name: config.xlab, nameLocation: "middle" });
111
+ if (config.ylab)
112
+ Object.assign(yAxis, { name: config.ylab, nameLocation: "middle" });
113
+ const grid = cartesianGrid(config, Boolean(config.xlab || config.ylab));
114
+ const dataZoom = config.zoom ? axisZoom(horizontal ? "y" : "x", grid) : undefined;
115
+ return {
116
+ ...(config.title ? { title: { text: config.title } } : {}),
117
+ tooltip: { trigger: "axis" },
118
+ ...(series.length > 1 ? { legend: { data: series.map((s) => s.name) } } : {}),
119
+ xAxis,
120
+ yAxis,
121
+ grid,
122
+ ...(dataZoom ? { dataZoom } : {}),
123
+ series: builtSeries,
124
+ ...(appearance.animation === undefined ? {} : { animation: appearance.animation }),
125
+ };
126
+ }
127
+ /** The category permutation for an order: input order, or stable by total across series. */
128
+ function order(categories, series, how) {
129
+ const index = categories.map((_, i) => i);
130
+ if (how === "input")
131
+ return index;
132
+ const total = (i) => series.reduce((sum, s) => sum + (s.data[i] ?? 0), 0);
133
+ const sign = how === "increasing" ? 1 : -1;
134
+ return index.sort((a, b) => sign * (total(a) - total(b)) || a - b);
135
+ }
136
+ /**
137
+ * Stop when two rows share a category (and group): with `group` or
138
+ * `aggregate` set, a bar is one category and group, combined by the host.
139
+ */
140
+ function requireOneRowPer(xs, groups) {
141
+ const seen = new Set();
142
+ xs.forEach((x, row) => {
143
+ const key = groups ? `${x}\u0000${groups[row]}` : x;
144
+ if (seen.has(key)) {
145
+ const where = groups ? `category '${x}' in group '${groups[row]}'` : `category '${x}'`;
146
+ throw new Error(`Several rows hold ${where}. Combine them before building, as the \`aggregate\` member says (sum, mean, median, or count).`);
147
+ }
148
+ seen.add(key);
149
+ });
150
+ }
151
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/charts/bar/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAsB,MAAM,wBAAwB,CAAC;AAErF,OAAO,EACL,OAAO,EAEP,MAAM,EACN,QAAQ,EACR,YAAY,GAEb,MAAM,wBAAwB,CAAC;AAiDhC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,MAAM;IACN,GAAG;IACH,GAAG;IACH,OAAO;IACP,WAAW;IACX,OAAO;IACP,OAAO;IACP,YAAY;IACZ,MAAM;IACN,WAAW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3C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,EAAqB,EAAE,MAA0B;IACzE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,eAAe,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC;YACvF,MAAM,IAAI,KAAK,CACb,qBAAqB,KAAK,iGAAiG,CAC5H,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { BarAppearance, BarChartConfig } from "./config.ts";
2
+ export { BAR_CHART_CONFIG_MEMBERS, buildBarOption } from "./config.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { BAR_CHART_CONFIG_MEMBERS, buildBarOption } from "./config.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/charts/bar/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.d.ts CHANGED
@@ -8,11 +8,21 @@
8
8
  * @module
9
9
  */
10
10
  import { buildA3Option } from "./charts/a3/index.ts";
11
+ import { buildBarOption } from "./charts/bar/index.ts";
11
12
  export type { A3Appearance, A3ChartConfig, A3EChartsOption, A3PtmPlacement, A3SurfaceHints, } from "./charts/a3/index.ts";
12
13
  export { A3_CHART_CONFIG_MEMBERS, a3SurfaceHints, buildA3Option } from "./charts/a3/index.ts";
14
+ export type { BarAppearance, BarChartConfig } from "./charts/bar/index.ts";
15
+ export { BAR_CHART_CONFIG_MEMBERS, buildBarOption } from "./charts/bar/index.ts";
16
+ export type { MarginMembers } from "./shared/layout.ts";
17
+ export { DEFAULT_MARGIN, ZOOM_SLIDER_ID } from "./shared/layout.ts";
18
+ export type { LegendMembers } from "./shared/legend.ts";
19
+ export type { ColumnarSource, ColumnNames, TabularData } from "./shared/source.ts";
20
+ export type { ColorScheme, ThemeTokens } from "./theme/tokens.ts";
21
+ export { DEFAULT_FONT_FAMILY, darkThemeTokens, fontStack, lightThemeTokens, RTEMIS_PALETTE, SIGN_COLORS, themeFontSizes, themeOption, } from "./theme/tokens.ts";
13
22
  /** The builder of each chart type, by `chart/<type>/v1` type name. */
14
23
  export declare const builders: Readonly<{
15
24
  a3: typeof buildA3Option;
25
+ bar: typeof buildBarOption;
16
26
  }>;
17
27
  /** A chart type with a builder in this package. */
18
28
  export type ChartType = keyof typeof builders;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,a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AAM,mBAAmB,CAAC;AAE3B,sEAAsE;AACtE,eAAO,MAAM,QAAQ;;;EAGnB,CAAC;AAEH,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -8,9 +8,14 @@
8
8
  * @module
9
9
  */
10
10
  import { buildA3Option } from "./charts/a3/index.js";
11
+ import { buildBarOption } from "./charts/bar/index.js";
11
12
  export { A3_CHART_CONFIG_MEMBERS, a3SurfaceHints, buildA3Option } from "./charts/a3/index.js";
13
+ export { BAR_CHART_CONFIG_MEMBERS, buildBarOption } from "./charts/bar/index.js";
14
+ export { DEFAULT_MARGIN, ZOOM_SLIDER_ID } from "./shared/layout.js";
15
+ export { DEFAULT_FONT_FAMILY, darkThemeTokens, fontStack, lightThemeTokens, RTEMIS_PALETTE, SIGN_COLORS, themeFontSizes, themeOption, } from "./theme/tokens.js";
12
16
  /** The builder of each chart type, by `chart/<type>/v1` type name. */
13
17
  export const builders = Object.freeze({
14
18
  a3: buildA3Option,
19
+ bar: buildBarOption,
15
20
  });
16
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AASrD,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE9F,sEAAsE;AACtE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,aAAa;CAClB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AASvD,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpE,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,sEAAsE;AACtE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,aAAa;IACjB,GAAG,EAAE,cAAc;CACpB,CAAC,CAAC"}
@@ -22,9 +22,21 @@ var RtemisDraw = (() => {
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
24
  A3_CHART_CONFIG_MEMBERS: () => A3_CHART_CONFIG_MEMBERS,
25
+ BAR_CHART_CONFIG_MEMBERS: () => BAR_CHART_CONFIG_MEMBERS,
26
+ DEFAULT_FONT_FAMILY: () => DEFAULT_FONT_FAMILY,
27
+ DEFAULT_MARGIN: () => DEFAULT_MARGIN,
28
+ RTEMIS_PALETTE: () => RTEMIS_PALETTE,
29
+ SIGN_COLORS: () => SIGN_COLORS,
30
+ ZOOM_SLIDER_ID: () => ZOOM_SLIDER_ID,
25
31
  a3SurfaceHints: () => a3SurfaceHints,
26
32
  buildA3Option: () => buildA3Option,
27
- builders: () => builders
33
+ buildBarOption: () => buildBarOption,
34
+ builders: () => builders,
35
+ darkThemeTokens: () => darkThemeTokens,
36
+ fontStack: () => fontStack,
37
+ lightThemeTokens: () => lightThemeTokens,
38
+ themeFontSizes: () => themeFontSizes,
39
+ themeOption: () => themeOption
28
40
  });
29
41
 
30
42
  // src/charts/a3/layout.ts
@@ -930,9 +942,377 @@ var RtemisDraw = (() => {
930
942
  return value ? { [key]: value } : {};
931
943
  }
932
944
 
945
+ // src/shared/layout.ts
946
+ var DEFAULT_MARGIN = 36;
947
+ var SIDES = ["top", "right", "bottom", "left"];
948
+ function cartesianGrid(config, axisNames) {
949
+ const set = SIDES.filter((side) => typeof config[`margin_${side}`] === "number");
950
+ const grid = {};
951
+ for (const side of SIDES) {
952
+ const value = config[`margin_${side}`];
953
+ if (set.length === 0) grid[side] = DEFAULT_MARGIN;
954
+ else if (typeof value === "number") grid[side] = value;
955
+ }
956
+ grid.outerBoundsMode = "same";
957
+ grid.outerBoundsContain = axisNames ? "all" : "axisLabel";
958
+ return grid;
959
+ }
960
+ var ZOOM_SLIDER_ID = "rtemis-zoom-slider";
961
+ var SLIDER_SIZE = 30;
962
+ var SLIDER_HANDLE = 7;
963
+ var SLIDER_GAP = 8;
964
+ function axisZoom(axis, grid) {
965
+ const side = axis === "x" ? "bottom" : "right";
966
+ const current = grid[side];
967
+ const margin = typeof current === "number" ? current : axis === "x" ? 80 : 15;
968
+ const index = axis === "x" ? { xAxisIndex: 0 } : { yAxisIndex: 0 };
969
+ grid[side] = margin + SLIDER_HANDLE + SLIDER_SIZE + SLIDER_GAP;
970
+ return [
971
+ {
972
+ type: "slider",
973
+ id: ZOOM_SLIDER_ID,
974
+ start: 0,
975
+ end: 100,
976
+ ...index,
977
+ [side]: margin + SLIDER_HANDLE,
978
+ ...axis === "x" ? { height: SLIDER_SIZE } : { width: SLIDER_SIZE }
979
+ },
980
+ { type: "inside", ...index, zoomOnMouseWheel: "shift", moveOnMouseMove: true }
981
+ ];
982
+ }
983
+
984
+ // src/shared/source.ts
985
+ function distinct(values, levels) {
986
+ const seen = new Set(values);
987
+ const ordered = (levels ?? []).filter((level) => seen.has(level));
988
+ const known = new Set(ordered);
989
+ return [...ordered, ...[...seen].filter((v) => !known.has(v))];
990
+ }
991
+ function column(source, name, member) {
992
+ const values = source[name];
993
+ if (values === void 0) {
994
+ throw new Error(`Column '${name}' (config member '${member}') is not in the data.`);
995
+ }
996
+ return Array.isArray(values) ? values : Array.from(values);
997
+ }
998
+ function asArray(value) {
999
+ if (value === null || value === void 0) return [];
1000
+ return Array.isArray(value) ? value : [value];
1001
+ }
1002
+ function numberOrNull(value) {
1003
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
1004
+ }
1005
+
1006
+ // src/charts/bar/config.ts
1007
+ var BAR_CHART_CONFIG_MEMBERS = Object.freeze([
1008
+ "type",
1009
+ "x",
1010
+ "y",
1011
+ "group",
1012
+ "aggregate",
1013
+ "order",
1014
+ "stack",
1015
+ "horizontal",
1016
+ "zoom",
1017
+ "bar_width",
1018
+ "palette",
1019
+ "ylim",
1020
+ "xlab",
1021
+ "ylab",
1022
+ "title",
1023
+ "margin_top",
1024
+ "margin_right",
1025
+ "margin_bottom",
1026
+ "margin_left",
1027
+ "legend_position",
1028
+ "legend_placement",
1029
+ "legend_title"
1030
+ ]);
1031
+ function buildBarOption(data, config, appearance = {}) {
1032
+ const source = data.columns;
1033
+ const yColumns = asArray(config.y);
1034
+ if (!config.x || yColumns.length === 0) {
1035
+ throw new Error("A bar chart needs both `x` and `y` set to draw.");
1036
+ }
1037
+ const xs = column(source, config.x, "x").map((v) => String(v));
1038
+ const aggregate = config.aggregate ?? "none";
1039
+ let categories;
1040
+ let series;
1041
+ if (config.group) {
1042
+ const groupValues = column(source, config.group, "group").map((v) => String(v));
1043
+ requireOneRowPer(xs, groupValues);
1044
+ categories = distinct(xs, data.levels?.[config.x]);
1045
+ const groups = distinct(groupValues, data.levels?.[config.group]);
1046
+ const at = new Map(categories.map((c, i) => [c, i]));
1047
+ series = groups.flatMap(
1048
+ (g) => yColumns.map((y) => {
1049
+ const values = column(source, y, "y");
1050
+ const data2 = categories.map(() => null);
1051
+ xs.forEach((x, row) => {
1052
+ const i = at.get(x);
1053
+ if (groupValues[row] === g && i !== void 0) data2[i] = numberOrNull(values[row]);
1054
+ });
1055
+ const name = groups.length > 1 ? yColumns.length > 1 ? `${y} / ${g}` : g : y;
1056
+ return { name, data: data2 };
1057
+ })
1058
+ );
1059
+ } else {
1060
+ if (aggregate !== "none") requireOneRowPer(xs);
1061
+ categories = xs;
1062
+ series = yColumns.map((y) => ({ name: y, data: column(source, y, "y").map(numberOrNull) }));
1063
+ }
1064
+ const permutation = order(categories, series, config.order ?? "input");
1065
+ categories = permutation.map((i) => categories[i]);
1066
+ series = series.map((s) => ({ ...s, data: permutation.map((i) => s.data[i] ?? null) }));
1067
+ const palette = asArray(config.palette);
1068
+ const stack = config.stack ? "total" : void 0;
1069
+ const barWidth = typeof config.bar_width === "number" ? config.bar_width : void 0;
1070
+ const builtSeries = series.map((s, i) => {
1071
+ const single = series.length === 1;
1072
+ const perBar = single && palette.length > 1;
1073
+ const color = perBar ? void 0 : palette.length > 0 ? palette[i % palette.length] : void 0;
1074
+ return {
1075
+ type: "bar",
1076
+ ...single ? {} : { name: s.name },
1077
+ data: perBar ? s.data.map((value2, j) => ({
1078
+ value: value2,
1079
+ itemStyle: { color: palette[(permutation[j] ?? j) % palette.length] }
1080
+ })) : s.data,
1081
+ ...stack ? { stack } : {},
1082
+ ...barWidth === void 0 ? {} : { barWidth },
1083
+ ...color === void 0 ? {} : { itemStyle: { color } }
1084
+ };
1085
+ });
1086
+ const horizontal = config.horizontal ?? false;
1087
+ const category = {
1088
+ type: "category",
1089
+ data: categories,
1090
+ axisPointer: { type: "none" },
1091
+ axisTick: { show: false }
1092
+ };
1093
+ const value = {
1094
+ type: "value",
1095
+ axisTick: { show: false },
1096
+ ...config.ylim ? { min: config.ylim[0], max: config.ylim[1] } : {}
1097
+ };
1098
+ const xAxis = horizontal ? value : category;
1099
+ const yAxis = horizontal ? category : value;
1100
+ if (config.xlab) Object.assign(xAxis, { name: config.xlab, nameLocation: "middle" });
1101
+ if (config.ylab) Object.assign(yAxis, { name: config.ylab, nameLocation: "middle" });
1102
+ const grid = cartesianGrid(config, Boolean(config.xlab || config.ylab));
1103
+ const dataZoom = config.zoom ? axisZoom(horizontal ? "y" : "x", grid) : void 0;
1104
+ return {
1105
+ ...config.title ? { title: { text: config.title } } : {},
1106
+ tooltip: { trigger: "axis" },
1107
+ ...series.length > 1 ? { legend: { data: series.map((s) => s.name) } } : {},
1108
+ xAxis,
1109
+ yAxis,
1110
+ grid,
1111
+ ...dataZoom ? { dataZoom } : {},
1112
+ series: builtSeries,
1113
+ ...appearance.animation === void 0 ? {} : { animation: appearance.animation }
1114
+ };
1115
+ }
1116
+ function order(categories, series, how) {
1117
+ const index = categories.map((_, i) => i);
1118
+ if (how === "input") return index;
1119
+ const total = (i) => series.reduce((sum, s) => sum + (s.data[i] ?? 0), 0);
1120
+ const sign = how === "increasing" ? 1 : -1;
1121
+ return index.sort((a, b) => sign * (total(a) - total(b)) || a - b);
1122
+ }
1123
+ function requireOneRowPer(xs, groups) {
1124
+ const seen = /* @__PURE__ */ new Set();
1125
+ xs.forEach((x, row) => {
1126
+ const key = groups ? `${x}\0${groups[row]}` : x;
1127
+ if (seen.has(key)) {
1128
+ const where = groups ? `category '${x}' in group '${groups[row]}'` : `category '${x}'`;
1129
+ throw new Error(
1130
+ `Several rows hold ${where}. Combine them before building, as the \`aggregate\` member says (sum, mean, median, or count).`
1131
+ );
1132
+ }
1133
+ seen.add(key);
1134
+ });
1135
+ }
1136
+
1137
+ // src/theme/tokens.ts
1138
+ var RTEMIS_PALETTE = Object.freeze([
1139
+ "#6CA3A0",
1140
+ "#F08904",
1141
+ "#BE2E5F",
1142
+ "#B3CFE8",
1143
+ "#0F6A66",
1144
+ "#FDB808",
1145
+ "#EA384A",
1146
+ "#466D96",
1147
+ "#526551",
1148
+ "#F384FF",
1149
+ "#7D0830",
1150
+ "#375D86",
1151
+ "#B1A7B3",
1152
+ "#7364F2",
1153
+ "#895140",
1154
+ "#C5A267"
1155
+ ]);
1156
+ var SIGN_COLORS = Object.freeze({
1157
+ negative: "#2D83D3",
1158
+ neutral: "#808080",
1159
+ positive: "#C55E28"
1160
+ });
1161
+ function lightThemeTokens(overrides = {}) {
1162
+ return Object.freeze({
1163
+ scheme: "light",
1164
+ base_font_size: 12,
1165
+ palette: RTEMIS_PALETTE,
1166
+ bg_color: "#ffffff",
1167
+ fg_color: "rgba(0, 0, 0, 0.7)",
1168
+ negative_color: SIGN_COLORS.negative,
1169
+ neutral_color: SIGN_COLORS.neutral,
1170
+ positive_color: SIGN_COLORS.positive,
1171
+ ...overrides
1172
+ });
1173
+ }
1174
+ function darkThemeTokens(overrides = {}) {
1175
+ return Object.freeze({
1176
+ scheme: "dark",
1177
+ base_font_size: 12,
1178
+ palette: RTEMIS_PALETTE,
1179
+ bg_color: "#181818",
1180
+ fg_color: "rgba(255, 255, 255, 0.7)",
1181
+ title_color: "rgba(255, 255, 255, 0.9)",
1182
+ subtitle_color: "rgba(255, 255, 255, 0.5)",
1183
+ axis_color: "rgba(255, 255, 255, 0.3)",
1184
+ grid_color: "rgba(255, 255, 255, 0.1)",
1185
+ tooltip_bg: "rgba(20, 20, 20, 0.9)",
1186
+ tooltip_border_color: "rgba(255, 255, 255, 0.1)",
1187
+ negative_color: SIGN_COLORS.negative,
1188
+ neutral_color: SIGN_COLORS.neutral,
1189
+ positive_color: SIGN_COLORS.positive,
1190
+ ...overrides
1191
+ });
1192
+ }
1193
+ var DEFAULT_FONT_FAMILY = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
1194
+ var GENERIC_FONT_FAMILIES = /* @__PURE__ */ new Set([
1195
+ "serif",
1196
+ "sans-serif",
1197
+ "monospace",
1198
+ "cursive",
1199
+ "fantasy",
1200
+ "math",
1201
+ "emoji",
1202
+ "fangsong",
1203
+ "system-ui",
1204
+ "ui-serif",
1205
+ "ui-sans-serif",
1206
+ "ui-monospace",
1207
+ "ui-rounded",
1208
+ "-apple-system",
1209
+ "blinkmacsystemfont"
1210
+ ]);
1211
+ function fontStack(fontFamily) {
1212
+ if (fontFamily === void 0 || fontFamily === null) return DEFAULT_FONT_FAMILY;
1213
+ const entries = fontFamily.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
1214
+ if (entries.length === 0) throw new Error("`font_family` must be a nonempty font family.");
1215
+ const ident = /^-?[A-Za-z_][A-Za-z0-9_-]*( +-?[A-Za-z_][A-Za-z0-9_-]*)*$/;
1216
+ const quoted = /^(['"]).*\1$/;
1217
+ const out = entries.map((e) => {
1218
+ const generic = GENERIC_FONT_FAMILIES.has(e.toLowerCase());
1219
+ return quoted.test(e) || generic || ident.test(e) ? e : `'${e.replaceAll("'", "\\'")}'`;
1220
+ });
1221
+ const last = entries[entries.length - 1] ?? "";
1222
+ if (!GENERIC_FONT_FAMILIES.has(last.toLowerCase())) out.push(DEFAULT_FONT_FAMILY);
1223
+ return out.join(", ");
1224
+ }
1225
+ function roundHalfEven(x) {
1226
+ const floor = Math.floor(x);
1227
+ const diff = x - floor;
1228
+ if (Math.abs(diff - 0.5) > 1e-9) return Math.round(x);
1229
+ return floor % 2 === 0 ? floor : floor + 1;
1230
+ }
1231
+ function themeFontSizes(tokens) {
1232
+ const base = tokens.base_font_size;
1233
+ return {
1234
+ base,
1235
+ title: tokens.title_font_size ?? roundHalfEven(base * 1.2),
1236
+ subtitle: tokens.subtitle_font_size ?? base,
1237
+ axisLabel: tokens.axis_label_font_size ?? base,
1238
+ legend: tokens.legend_font_size ?? base,
1239
+ tooltip: tokens.tooltip_font_size ?? base
1240
+ };
1241
+ }
1242
+ function present(entries) {
1243
+ return Object.fromEntries(
1244
+ Object.entries(entries).filter(([, v]) => v !== void 0 && v !== null)
1245
+ );
1246
+ }
1247
+ function themeOption(tokens) {
1248
+ const sizes = themeFontSizes(tokens);
1249
+ const dark = tokens.scheme === "dark";
1250
+ const fg = tokens.fg_color;
1251
+ const textStyle = { color: fg, fontFamily: fontStack(tokens.font_family), fontSize: sizes.base };
1252
+ const withText = (style) => ({ ...textStyle, ...style });
1253
+ const axisLabel = { fontSize: sizes.axisLabel, color: fg };
1254
+ const axisLine = tokens.axis_color ? { lineStyle: { color: tokens.axis_color } } : void 0;
1255
+ const valueAxis = present({
1256
+ axisLabel,
1257
+ axisLine,
1258
+ splitLine: tokens.grid_color ? { lineStyle: { color: tokens.grid_color } } : void 0
1259
+ });
1260
+ return {
1261
+ color: [...tokens.palette],
1262
+ backgroundColor: tokens.bg_color,
1263
+ textStyle,
1264
+ title: {
1265
+ textStyle: withText(present({ color: tokens.title_color, fontSize: sizes.title })),
1266
+ subtextStyle: withText(present({ color: tokens.subtitle_color, fontSize: sizes.subtitle }))
1267
+ },
1268
+ legend: {
1269
+ textStyle: withText({ color: tokens.legend_color ?? fg, fontSize: sizes.legend })
1270
+ },
1271
+ tooltip: present({
1272
+ backgroundColor: tokens.tooltip_bg,
1273
+ borderColor: tokens.tooltip_border_color,
1274
+ textStyle: withText({ color: tokens.tooltip_color ?? fg, fontSize: sizes.tooltip })
1275
+ }),
1276
+ visualMap: { textStyle },
1277
+ // Neutral controls leave the palette to encode data; every accent-bearing
1278
+ // slider state is set so ECharts' blue defaults cannot show.
1279
+ // spec: draw/visual-qa-docs#neutral-data-zoom-sliders
1280
+ dataZoom: {
1281
+ backgroundColor: "rgba(128,128,128,0.06)",
1282
+ borderColor: dark ? "#606060" : "#b0b0b0",
1283
+ fillerColor: "rgba(128,128,128,0.18)",
1284
+ dataBackground: {
1285
+ lineStyle: { color: "#808080" },
1286
+ areaStyle: { color: "#808080", opacity: 0.12 }
1287
+ },
1288
+ selectedDataBackground: {
1289
+ lineStyle: { color: dark ? "#b0b0b0" : "#707070" },
1290
+ areaStyle: { color: "#808080", opacity: 0.25 }
1291
+ },
1292
+ handleStyle: {
1293
+ color: dark ? "#303030" : "#ffffff",
1294
+ borderColor: dark ? "#909090" : "#808080"
1295
+ },
1296
+ moveHandleStyle: { color: "#909090", opacity: 0.6 },
1297
+ brushStyle: { color: "#808080", opacity: 0.3 },
1298
+ textStyle: axisLabel,
1299
+ emphasis: {
1300
+ handleStyle: { borderColor: dark ? "#cccccc" : "#505050" },
1301
+ moveHandleStyle: { color: dark ? "#b0b0b0" : "#707070" }
1302
+ }
1303
+ },
1304
+ line: { symbol: "circle" },
1305
+ categoryAxis: present({ axisLabel, axisLine, splitLine: { show: false } }),
1306
+ valueAxis,
1307
+ logAxis: valueAxis,
1308
+ timeAxis: valueAxis
1309
+ };
1310
+ }
1311
+
933
1312
  // src/index.ts
934
1313
  var builders = Object.freeze({
935
- a3: buildA3Option
1314
+ a3: buildA3Option,
1315
+ bar: buildBarOption
936
1316
  });
937
1317
  return __toCommonJS(index_exports);
938
1318
  })();
@@ -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
+ }
59
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/shared/layout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAG1D;;;;G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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
+ * 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
+ }
16
+ /**
17
+ * The distinct values of a column in level order: the levels that occur, then
18
+ * values not among the levels in order of appearance.
19
+ */
20
+ export declare function distinct(values: readonly string[], levels?: readonly string[]): string[];
21
+ /** A config member that names one or more columns, as JSON may carry it. */
22
+ export type ColumnNames = string | readonly string[];
23
+ /**
24
+ * The values of a column as an array, or an error naming the column and the
25
+ * member. A typed array is copied, so mapping it to text keeps the text.
26
+ */
27
+ export declare function column(source: ColumnarSource, name: string, member: string): readonly unknown[];
28
+ /** A one-or-many member as an array; a JSON scalar is one element. */
29
+ export declare function asArray<T>(value: T | readonly T[] | null | undefined): readonly T[];
30
+ /** A numeric cell, or `null` for a missing or non-finite one. */
31
+ export declare function numberOrNull(value: unknown): number | null;
32
+ //# 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,EAAE,cAAc,CAAC;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAKxF;AAED,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAM/F;AAED,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,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,32 @@
1
+ /**
2
+ * The distinct values of a column in level order: the levels that occur, then
3
+ * values not among the levels in order of appearance.
4
+ */
5
+ export function distinct(values, levels) {
6
+ const seen = new Set(values);
7
+ const ordered = (levels ?? []).filter((level) => seen.has(level));
8
+ const known = new Set(ordered);
9
+ return [...ordered, ...[...seen].filter((v) => !known.has(v))];
10
+ }
11
+ /**
12
+ * The values of a column as an array, or an error naming the column and the
13
+ * member. A typed array is copied, so mapping it to text keeps the text.
14
+ */
15
+ export function column(source, name, member) {
16
+ const values = source[name];
17
+ if (values === undefined) {
18
+ throw new Error(`Column '${name}' (config member '${member}') is not in the data.`);
19
+ }
20
+ return Array.isArray(values) ? values : Array.from(values);
21
+ }
22
+ /** A one-or-many member as an array; a JSON scalar is one element. */
23
+ export function asArray(value) {
24
+ if (value === null || value === undefined)
25
+ return [];
26
+ return Array.isArray(value) ? value : [value];
27
+ }
28
+ /** A numeric cell, or `null` for a missing or non-finite one. */
29
+ export function numberOrNull(value) {
30
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
31
+ }
32
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/shared/source.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAyB,EAAE,MAA0B;IAC5E,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAKD;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,MAAsB,EAAE,IAAY,EAAE,MAAc;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,qBAAqB,MAAM,wBAAwB,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,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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,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAQpC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CA+DrD"}
@@ -0,0 +1,205 @@
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
+ /** rtemis' categorical palette. */
8
+ export const RTEMIS_PALETTE = Object.freeze([
9
+ "#6CA3A0",
10
+ "#F08904",
11
+ "#BE2E5F",
12
+ "#B3CFE8",
13
+ "#0F6A66",
14
+ "#FDB808",
15
+ "#EA384A",
16
+ "#466D96",
17
+ "#526551",
18
+ "#F384FF",
19
+ "#7D0830",
20
+ "#375D86",
21
+ "#B1A7B3",
22
+ "#7364F2",
23
+ "#895140",
24
+ "#C5A267",
25
+ ]);
26
+ /** Sign colors of equal perceived lightness: blue, gray, orange. */
27
+ export const SIGN_COLORS = Object.freeze({
28
+ negative: "#2D83D3",
29
+ neutral: "#808080",
30
+ positive: "#C55E28",
31
+ });
32
+ /** The light theme's tokens, as rtemis.draw's `theme_light()` sets them. */
33
+ export function lightThemeTokens(overrides = {}) {
34
+ return Object.freeze({
35
+ scheme: "light",
36
+ base_font_size: 12,
37
+ palette: RTEMIS_PALETTE,
38
+ bg_color: "#ffffff",
39
+ fg_color: "rgba(0, 0, 0, 0.7)",
40
+ negative_color: SIGN_COLORS.negative,
41
+ neutral_color: SIGN_COLORS.neutral,
42
+ positive_color: SIGN_COLORS.positive,
43
+ ...overrides,
44
+ });
45
+ }
46
+ /** The dark theme's tokens, as rtemis.draw's `theme_dark()` sets them. */
47
+ export function darkThemeTokens(overrides = {}) {
48
+ return Object.freeze({
49
+ scheme: "dark",
50
+ base_font_size: 12,
51
+ palette: RTEMIS_PALETTE,
52
+ bg_color: "#181818",
53
+ fg_color: "rgba(255, 255, 255, 0.7)",
54
+ title_color: "rgba(255, 255, 255, 0.9)",
55
+ subtitle_color: "rgba(255, 255, 255, 0.5)",
56
+ axis_color: "rgba(255, 255, 255, 0.3)",
57
+ grid_color: "rgba(255, 255, 255, 0.1)",
58
+ tooltip_bg: "rgba(20, 20, 20, 0.9)",
59
+ tooltip_border_color: "rgba(255, 255, 255, 0.1)",
60
+ negative_color: SIGN_COLORS.negative,
61
+ neutral_color: SIGN_COLORS.neutral,
62
+ positive_color: SIGN_COLORS.positive,
63
+ ...overrides,
64
+ });
65
+ }
66
+ /** Font stack that follows a font family, and the whole stack when none is set. */
67
+ export const DEFAULT_FONT_FAMILY = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
68
+ // CSS generic family names and the vendor keywords for the system UI font,
69
+ // which are keywords: quoting one turns it into a family name no font has.
70
+ const GENERIC_FONT_FAMILIES = new Set([
71
+ "serif",
72
+ "sans-serif",
73
+ "monospace",
74
+ "cursive",
75
+ "fantasy",
76
+ "math",
77
+ "emoji",
78
+ "fangsong",
79
+ "system-ui",
80
+ "ui-serif",
81
+ "ui-sans-serif",
82
+ "ui-monospace",
83
+ "ui-rounded",
84
+ "-apple-system",
85
+ "blinkmacsystemfont",
86
+ ]);
87
+ /**
88
+ * A complete CSS font stack: every family name that is not a sequence of CSS
89
+ * identifiers is quoted, and {@link DEFAULT_FONT_FAMILY} follows unless the
90
+ * stack ends in a generic family. Matches rtemis.draw's `font_stack()`.
91
+ */
92
+ export function fontStack(fontFamily) {
93
+ if (fontFamily === undefined || fontFamily === null)
94
+ return DEFAULT_FONT_FAMILY;
95
+ const entries = fontFamily
96
+ .split(",")
97
+ .map((e) => e.trim())
98
+ .filter((e) => e.length > 0);
99
+ if (entries.length === 0)
100
+ throw new Error("`font_family` must be a nonempty font family.");
101
+ const ident = /^-?[A-Za-z_][A-Za-z0-9_-]*( +-?[A-Za-z_][A-Za-z0-9_-]*)*$/;
102
+ const quoted = /^(['"]).*\1$/;
103
+ const out = entries.map((e) => {
104
+ const generic = GENERIC_FONT_FAMILIES.has(e.toLowerCase());
105
+ return quoted.test(e) || generic || ident.test(e) ? e : `'${e.replaceAll("'", "\\'")}'`;
106
+ });
107
+ const last = entries[entries.length - 1] ?? "";
108
+ if (!GENERIC_FONT_FAMILIES.has(last.toLowerCase()))
109
+ out.push(DEFAULT_FONT_FAMILY);
110
+ return out.join(", ");
111
+ }
112
+ /** Round half to even, as R's `round()` does. */
113
+ function roundHalfEven(x) {
114
+ const floor = Math.floor(x);
115
+ const diff = x - floor;
116
+ if (Math.abs(diff - 0.5) > 1e-9)
117
+ return Math.round(x);
118
+ return floor % 2 === 0 ? floor : floor + 1;
119
+ }
120
+ /** The text sizes of a theme, each resolved from `base_font_size` when unset. */
121
+ export function themeFontSizes(tokens) {
122
+ const base = tokens.base_font_size;
123
+ return {
124
+ base,
125
+ title: tokens.title_font_size ?? roundHalfEven(base * 1.2),
126
+ subtitle: tokens.subtitle_font_size ?? base,
127
+ axisLabel: tokens.axis_label_font_size ?? base,
128
+ legend: tokens.legend_font_size ?? base,
129
+ tooltip: tokens.tooltip_font_size ?? base,
130
+ };
131
+ }
132
+ function present(entries) {
133
+ return Object.fromEntries(Object.entries(entries).filter(([, v]) => v !== undefined && v !== null));
134
+ }
135
+ /**
136
+ * The ECharts theme object of a theme's tokens, for `echarts.registerTheme()`
137
+ * or `chart.setTheme()`. Every component with its own default text size takes
138
+ * the global text style, since a global `textStyle` does not reach them; log
139
+ * and time axes take the value axis's style.
140
+ */
141
+ export function themeOption(tokens) {
142
+ const sizes = themeFontSizes(tokens);
143
+ const dark = tokens.scheme === "dark";
144
+ const fg = tokens.fg_color;
145
+ const textStyle = { color: fg, fontFamily: fontStack(tokens.font_family), fontSize: sizes.base };
146
+ const withText = (style) => ({ ...textStyle, ...style });
147
+ const axisLabel = { fontSize: sizes.axisLabel, color: fg };
148
+ const axisLine = tokens.axis_color ? { lineStyle: { color: tokens.axis_color } } : undefined;
149
+ const valueAxis = present({
150
+ axisLabel,
151
+ axisLine,
152
+ splitLine: tokens.grid_color ? { lineStyle: { color: tokens.grid_color } } : undefined,
153
+ });
154
+ return {
155
+ color: [...tokens.palette],
156
+ backgroundColor: tokens.bg_color,
157
+ textStyle,
158
+ title: {
159
+ textStyle: withText(present({ color: tokens.title_color, fontSize: sizes.title })),
160
+ subtextStyle: withText(present({ color: tokens.subtitle_color, fontSize: sizes.subtitle })),
161
+ },
162
+ legend: {
163
+ textStyle: withText({ color: tokens.legend_color ?? fg, fontSize: sizes.legend }),
164
+ },
165
+ tooltip: present({
166
+ backgroundColor: tokens.tooltip_bg,
167
+ borderColor: tokens.tooltip_border_color,
168
+ textStyle: withText({ color: tokens.tooltip_color ?? fg, fontSize: sizes.tooltip }),
169
+ }),
170
+ visualMap: { textStyle },
171
+ // Neutral controls leave the palette to encode data; every accent-bearing
172
+ // slider state is set so ECharts' blue defaults cannot show.
173
+ // spec: draw/visual-qa-docs#neutral-data-zoom-sliders
174
+ dataZoom: {
175
+ backgroundColor: "rgba(128,128,128,0.06)",
176
+ borderColor: dark ? "#606060" : "#b0b0b0",
177
+ fillerColor: "rgba(128,128,128,0.18)",
178
+ dataBackground: {
179
+ lineStyle: { color: "#808080" },
180
+ areaStyle: { color: "#808080", opacity: 0.12 },
181
+ },
182
+ selectedDataBackground: {
183
+ lineStyle: { color: dark ? "#b0b0b0" : "#707070" },
184
+ areaStyle: { color: "#808080", opacity: 0.25 },
185
+ },
186
+ handleStyle: {
187
+ color: dark ? "#303030" : "#ffffff",
188
+ borderColor: dark ? "#909090" : "#808080",
189
+ },
190
+ moveHandleStyle: { color: "#909090", opacity: 0.6 },
191
+ brushStyle: { color: "#808080", opacity: 0.3 },
192
+ textStyle: axisLabel,
193
+ emphasis: {
194
+ handleStyle: { borderColor: dark ? "#cccccc" : "#505050" },
195
+ moveHandleStyle: { color: dark ? "#b0b0b0" : "#707070" },
196
+ },
197
+ },
198
+ line: { symbol: "circle" },
199
+ categoryAxis: present({ axisLabel, axisLine, splitLine: { show: false } }),
200
+ valueAxis,
201
+ logAxis: valueAxis,
202
+ timeAxis: valueAxis,
203
+ };
204
+ }
205
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/theme/tokens.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmCH,mCAAmC;AACnC,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC7D,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,SAAS;IACnB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;CACpB,CAAC,CAAC;AAEH,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAAC,YAAkC,EAAE;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO;QACf,cAAc,EAAE,EAAE;QAClB,OAAO,EAAE,cAAc;QACvB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,oBAAoB;QAC9B,cAAc,EAAE,WAAW,CAAC,QAAQ;QACpC,aAAa,EAAE,WAAW,CAAC,OAAO;QAClC,cAAc,EAAE,WAAW,CAAC,QAAQ;QACpC,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,YAAkC,EAAE;IAClE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM;QACd,cAAc,EAAE,EAAE;QAClB,OAAO,EAAE,cAAc;QACvB,QAAQ,EAAE,SAAS;QACnB,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  "name": "@rtemis/draw",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "ECharts option builders shared by rtemis.draw and rtemislive",
5
5
  "homepage": "https://rtemis.org",
6
6
  "keywords": ["rtemis", "echarts", "visualization"],