@ocelescope/core 0.7.0 → 0.9.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.
@@ -0,0 +1,101 @@
1
+ import { t as AreaChart } from "./AreaChart-DoD3LM50.js";
2
+ import { t as BarChart } from "./BarChart-Cixo5Okd.js";
3
+ import { t as LineChart } from "./LineChart-CVz-dkJI.js";
4
+ import { t as PieChart } from "./PieChart-DBiASngC.js";
5
+ import { t as ScatterChart } from "./ScatterChart-jIQOjQes.js";
6
+ import { t as SunburstChart } from "./SunburstChart-D6FhYBHI.js";
7
+ import { Group, SegmentedControl, Text } from "@mantine/core";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { EmptyState, useViewSetting, useViewerConfig } from "@r4pm/components";
10
+ //#region src/components/charts/SqlChart.tsx
11
+ /**
12
+ * A query's result, drawn.
13
+ *
14
+ * This is the r4pm viewer: it reads the result's own column types to decide
15
+ * what goes across and what goes up, takes colours and selection from the
16
+ * ambient `ViewerConfig`, and hands the rows to one of the charts.
17
+ */
18
+ const SqlChart = ({ data, type: initialType = "bar", types = [], x, y, series, path, stacked = false, horizontal = false, yAxes = "shared", colorScope, title, height = "100%", ...config }) => {
19
+ const { colorOf, onSelect } = useViewerConfig(config);
20
+ const [type, setType] = useViewSetting(`chartType:${title ?? ""}`, initialType);
21
+ const { category, measures } = columns(data, {
22
+ x,
23
+ y,
24
+ series
25
+ });
26
+ const chart = {
27
+ rows: data.rows,
28
+ x: category,
29
+ y: measures,
30
+ series,
31
+ ...colorScope && { colorOf: (name) => colorOf?.(colorScope, name) ?? "#888888" },
32
+ onSelect: (name, point) => onSelect?.({
33
+ scope: colorScope ?? category,
34
+ key: name,
35
+ data: point
36
+ })
37
+ };
38
+ return /* @__PURE__ */ jsxs("div", {
39
+ style: {
40
+ display: "flex",
41
+ flexDirection: "column",
42
+ width: "100%",
43
+ height
44
+ },
45
+ children: [(title || types.length > 1) && /* @__PURE__ */ jsxs(Group, {
46
+ gap: "xs",
47
+ mb: "xs",
48
+ pr: 48,
49
+ justify: "flex-start",
50
+ wrap: "wrap",
51
+ children: [title && /* @__PURE__ */ jsx(Text, {
52
+ size: "sm",
53
+ fw: 600,
54
+ truncate: true,
55
+ children: title
56
+ }), types.length > 1 && /* @__PURE__ */ jsx(SegmentedControl, {
57
+ "data-export-ignore": true,
58
+ size: "xs",
59
+ radius: "xl",
60
+ value: type,
61
+ onChange: (value) => setType(value),
62
+ data: types.map((option) => ({
63
+ value: option,
64
+ label: option[0]?.toUpperCase() + option.slice(1)
65
+ }))
66
+ })]
67
+ }), /* @__PURE__ */ jsx("div", {
68
+ style: {
69
+ flex: 1,
70
+ minHeight: 0
71
+ },
72
+ children: data.rows.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
73
+ title: "No data",
74
+ description: "The query returned no rows."
75
+ }) : type === "bar" ? /* @__PURE__ */ jsx(BarChart, {
76
+ ...chart,
77
+ stacked,
78
+ horizontal
79
+ }) : type === "line" ? /* @__PURE__ */ jsx(LineChart, {
80
+ ...chart,
81
+ yAxes
82
+ }) : type === "area" ? /* @__PURE__ */ jsx(AreaChart, { ...chart }) : type === "scatter" ? /* @__PURE__ */ jsx(ScatterChart, { ...chart }) : type === "pie" ? /* @__PURE__ */ jsx(PieChart, { ...chart }) : /* @__PURE__ */ jsx(SunburstChart, {
83
+ ...chart,
84
+ path
85
+ })
86
+ })]
87
+ });
88
+ };
89
+ const NUMERIC = /INT|DEC|DOUBLE|FLOAT|REAL|NUMERIC|HUGEINT/;
90
+ /** What to draw: the first non-numeric column across, the numbers up. */
91
+ const columns = (result, { x, y, series }) => {
92
+ const numeric = (name) => NUMERIC.test(result.columns.find((column) => column.name === name)?.type.toUpperCase() ?? "");
93
+ const category = x ?? result.columns.find((column) => !numeric(column.name))?.name ?? result.columns[0]?.name ?? "";
94
+ const named = y == null ? [] : Array.isArray(y) ? y : [y];
95
+ return {
96
+ category,
97
+ measures: (named.length > 0 ? named : result.columns.map((column) => column.name).filter((name) => numeric(name) && name !== category)).filter((name) => name !== series)
98
+ };
99
+ };
100
+ //#endregion
101
+ export { SqlChart };
@@ -0,0 +1,73 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { i as measureOf, r as label, t as Plot } from "./Plot-CxHHyXot.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/components/charts/SunburstChart.tsx
5
+ var SunburstChart_exports = /* @__PURE__ */ __exportAll({ SunburstChart: () => SunburstChart });
6
+ /** A hierarchy as rings, each one a column of the path. */
7
+ const SunburstChart = ({ path, ...props }) => {
8
+ const rings = path ?? [props.x, props.series].filter(named);
9
+ return /* @__PURE__ */ jsx(Plot, {
10
+ traces: [nest(props.rows, rings, measureOf(props.y), props.colorOf)],
11
+ onSelect: props.onSelect,
12
+ layout: {
13
+ margin: {
14
+ t: 12,
15
+ r: 12,
16
+ b: 12,
17
+ l: 12
18
+ },
19
+ uniformtext: {
20
+ mode: "hide",
21
+ minsize: 10
22
+ }
23
+ }
24
+ });
25
+ };
26
+ /**
27
+ * The rows as a tree: a node's value is the sum of the rows beneath it.
28
+ *
29
+ * Ids keep the rings apart where two of them carry the same name - an activity
30
+ * and an object type both called "order".
31
+ */
32
+ const nest = (rows, path, measure, colorOf) => {
33
+ const nodes = /* @__PURE__ */ new Map();
34
+ for (const row of rows) {
35
+ const value = Number(row[measure] ?? 0);
36
+ let parent = "";
37
+ for (const column of path) {
38
+ const name = label(row[column]);
39
+ const id = parent ? `${parent}/${name}` : name;
40
+ const node = nodes.get(id) ?? {
41
+ label: name,
42
+ parent,
43
+ value: 0
44
+ };
45
+ node.value += value;
46
+ nodes.set(id, node);
47
+ parent = id;
48
+ }
49
+ }
50
+ const entries = [...nodes];
51
+ return {
52
+ type: "sunburst",
53
+ ids: entries.map(([id]) => id),
54
+ labels: entries.map(([, node]) => node.label),
55
+ parents: entries.map(([, node]) => node.parent),
56
+ values: entries.map(([, node]) => node.value),
57
+ branchvalues: "total",
58
+ sort: false,
59
+ insidetextorientation: "radial",
60
+ hovertemplate: "<b>%{label}</b><br>%{value}<br>%{percentParent:.1%} of parent<extra></extra>",
61
+ maxdepth: path.length,
62
+ marker: {
63
+ line: {
64
+ color: "rgba(128,128,128,0.28)",
65
+ width: 1.25
66
+ },
67
+ ...colorOf && { colors: entries.map(([, node]) => colorOf(node.label)) }
68
+ }
69
+ };
70
+ };
71
+ const named = (column) => Boolean(column);
72
+ //#endregion
73
+ export { SunburstChart_exports as n, SunburstChart as t };
@@ -0,0 +1,41 @@
1
+ import { n as toSeries, t as paint } from "./series-BBXVjHHY.js";
2
+ //#region src/components/charts/internal/cartesian.ts
3
+ /**
4
+ * Traces for the charts drawn against two axes.
5
+ *
6
+ * Bars, lines, areas and points differ by a handful of Plotly fields and
7
+ * nothing else, so they share the shape of their traces and each chart says
8
+ * what makes it itself.
9
+ */
10
+ const cartesian = ({ rows, x, y, series, colorOf }, mark, horizontal = false, colorByPoint = true) => {
11
+ const groups = toSeries({
12
+ rows,
13
+ x,
14
+ y,
15
+ series
16
+ });
17
+ return groups.map((group) => {
18
+ const color = paint(group, colorOf, colorByPoint && groups.length === 1);
19
+ const line = mark.line ?? {};
20
+ const marker = mark.marker ?? {};
21
+ return {
22
+ ...mark,
23
+ name: group.name,
24
+ orientation: horizontal ? "h" : "v",
25
+ x: horizontal ? group.values : group.labels,
26
+ y: horizontal ? group.labels : group.values,
27
+ marker: {
28
+ ...marker,
29
+ ...color && { color }
30
+ },
31
+ ...typeof color === "string" && mark.line ? { line: {
32
+ ...line,
33
+ color
34
+ } } : {}
35
+ };
36
+ });
37
+ };
38
+ /** How many traces a chart will draw, which decides whether it needs a legend. */
39
+ const traceCount = (props) => toSeries(props).length;
40
+ //#endregion
41
+ export { traceCount as n, cartesian as t };