@object-ui/plugin-charts 3.1.3 → 3.1.5

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,134 @@
1
+ import { t as e } from "./jsx-runtime-C8d0IhUE.js";
2
+ import { Y as t, d as n, en as r, f as i, sn as a, t as o, u as s, v as c } from "./BarChart-XZkfLmcU.js";
3
+ //#region src/ChartImpl.tsx
4
+ var l = e();
5
+ function u({ data: e = [], dataKey: u = "value", xAxisKey: d = "name", height: f = 400, className: p = "", color: m = "hsl(var(--primary))" }) {
6
+ return /* @__PURE__ */ (0, l.jsx)("div", {
7
+ className: `p-2 sm:p-3 md:p-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm shadow-lg shadow-background/5 ${p}`,
8
+ children: /* @__PURE__ */ (0, l.jsx)(a, {
9
+ width: "100%",
10
+ height: f,
11
+ children: /* @__PURE__ */ (0, l.jsxs)(o, {
12
+ data: e,
13
+ margin: {
14
+ top: 10,
15
+ right: 10,
16
+ left: 10,
17
+ bottom: 5
18
+ },
19
+ children: [
20
+ /* @__PURE__ */ (0, l.jsxs)("defs", { children: [/* @__PURE__ */ (0, l.jsxs)("linearGradient", {
21
+ id: "barGradient",
22
+ x1: "0",
23
+ y1: "0",
24
+ x2: "0",
25
+ y2: "1",
26
+ children: [
27
+ /* @__PURE__ */ (0, l.jsx)("stop", {
28
+ offset: "0%",
29
+ stopColor: m,
30
+ stopOpacity: 1
31
+ }),
32
+ /* @__PURE__ */ (0, l.jsx)("stop", {
33
+ offset: "90%",
34
+ stopColor: m,
35
+ stopOpacity: .6
36
+ }),
37
+ /* @__PURE__ */ (0, l.jsx)("stop", {
38
+ offset: "100%",
39
+ stopColor: m,
40
+ stopOpacity: .3
41
+ })
42
+ ]
43
+ }), /* @__PURE__ */ (0, l.jsxs)("filter", {
44
+ id: "glow",
45
+ height: "130%",
46
+ children: [
47
+ /* @__PURE__ */ (0, l.jsx)("feGaussianBlur", {
48
+ in: "SourceAlpha",
49
+ stdDeviation: "3",
50
+ result: "blur"
51
+ }),
52
+ /* @__PURE__ */ (0, l.jsx)("feOffset", {
53
+ in: "blur",
54
+ dx: "0",
55
+ dy: "0",
56
+ result: "offsetBlur"
57
+ }),
58
+ /* @__PURE__ */ (0, l.jsx)("feFlood", {
59
+ floodColor: m,
60
+ floodOpacity: "0.5",
61
+ result: "offsetColor"
62
+ }),
63
+ /* @__PURE__ */ (0, l.jsx)("feComposite", {
64
+ in: "offsetColor",
65
+ in2: "offsetBlur",
66
+ operator: "in",
67
+ result: "offsetBlur"
68
+ }),
69
+ /* @__PURE__ */ (0, l.jsxs)("feMerge", { children: [/* @__PURE__ */ (0, l.jsx)("feMergeNode", { in: "offsetBlur" }), /* @__PURE__ */ (0, l.jsx)("feMergeNode", { in: "SourceGraphic" })] })
70
+ ]
71
+ })] }),
72
+ /* @__PURE__ */ (0, l.jsx)(c, {
73
+ strokeDasharray: "3 3",
74
+ stroke: "hsl(var(--border))",
75
+ vertical: !1
76
+ }),
77
+ /* @__PURE__ */ (0, l.jsx)(n, {
78
+ dataKey: d,
79
+ tick: {
80
+ fill: "hsl(var(--muted-foreground))",
81
+ fontSize: 12,
82
+ fontFamily: "monospace"
83
+ },
84
+ tickLine: !1,
85
+ axisLine: { stroke: "hsl(var(--border))" },
86
+ dy: 10
87
+ }),
88
+ /* @__PURE__ */ (0, l.jsx)(s, {
89
+ tick: {
90
+ fill: "hsl(var(--muted-foreground))",
91
+ fontSize: 12,
92
+ fontFamily: "monospace"
93
+ },
94
+ tickLine: !1,
95
+ axisLine: !1
96
+ }),
97
+ /* @__PURE__ */ (0, l.jsx)(t, {
98
+ cursor: {
99
+ fill: "hsl(var(--muted))",
100
+ opacity: .2
101
+ },
102
+ contentStyle: {
103
+ backgroundColor: "hsl(var(--popover))",
104
+ borderColor: "hsl(var(--border))",
105
+ color: "hsl(var(--popover-foreground))",
106
+ borderRadius: "8px",
107
+ fontFamily: "monospace",
108
+ boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)"
109
+ },
110
+ itemStyle: { color: "hsl(var(--primary))" }
111
+ }),
112
+ /* @__PURE__ */ (0, l.jsx)(r, { wrapperStyle: {
113
+ paddingTop: "20px",
114
+ fontFamily: "monospace"
115
+ } }),
116
+ /* @__PURE__ */ (0, l.jsx)(i, {
117
+ dataKey: u,
118
+ fill: "url(#barGradient)",
119
+ radius: [
120
+ 4,
121
+ 4,
122
+ 0,
123
+ 0
124
+ ],
125
+ filter: "url(#glow)",
126
+ animationDuration: 1500
127
+ })
128
+ ]
129
+ })
130
+ })
131
+ });
132
+ }
133
+ //#endregion
134
+ export { u as default };
package/dist/index.js CHANGED
@@ -1,8 +1,409 @@
1
- import "@object-ui/core";
2
- import { C as t, a as o, O as s, c as C } from "./index-CYV5Bp-d.js";
3
- export {
4
- t as ChartBarRenderer,
5
- o as ChartRenderer,
6
- s as ObjectChart,
7
- C as chartComponents
1
+ import { t as e } from "./jsx-runtime-C8d0IhUE.js";
2
+ import { ComponentRegistry as t, extractRecords as n } from "@object-ui/core";
3
+ import r, { Suspense as i, useContext as a, useEffect as o, useState as s } from "react";
4
+ import { Skeleton as c } from "@object-ui/components";
5
+ import { SchemaRendererContext as l, useDataScope as u } from "@object-ui/react";
6
+ //#region src/ChartRenderer.tsx
7
+ var d = e(), f = r.lazy(() => import("./ChartImpl-0VlpsMWG.js")), p = r.lazy(() => import("./AdvancedChartImpl-DmHTUUVD.js")), m = ({ schema: e }) => /* @__PURE__ */ (0, d.jsx)(i, {
8
+ fallback: /* @__PURE__ */ (0, d.jsx)(c, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
9
+ children: /* @__PURE__ */ (0, d.jsx)(f, {
10
+ data: e.data,
11
+ dataKey: e.dataKey,
12
+ xAxisKey: e.xAxisKey,
13
+ height: e.height,
14
+ className: e.className,
15
+ color: e.color
16
+ })
17
+ }), h = ({ schema: e }) => {
18
+ let t = r.useMemo(() => {
19
+ let t = e.series, n = e.xAxisKey, r = e.config;
20
+ if (n || (e.index ? n = e.index : e.category && (n = e.category)), t || (e.categories ? t = e.categories.map((e) => ({ dataKey: e })) : e.value && (t = [{ dataKey: e.value }])), !r && t) {
21
+ let n = e.colors || [
22
+ "hsl(var(--chart-1))",
23
+ "hsl(var(--chart-2))",
24
+ "hsl(var(--chart-3))"
25
+ ], i = {};
26
+ t.forEach((e, t) => {
27
+ i[e.dataKey] = {
28
+ label: e.dataKey,
29
+ color: n[t % n.length]
30
+ };
31
+ }), r = i;
32
+ }
33
+ return {
34
+ chartType: e.chartType,
35
+ data: Array.isArray(e.data) ? e.data : [],
36
+ config: r,
37
+ xAxisKey: n,
38
+ series: t,
39
+ className: e.className
40
+ };
41
+ }, [e]);
42
+ return /* @__PURE__ */ (0, d.jsx)(i, {
43
+ fallback: /* @__PURE__ */ (0, d.jsx)(c, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
44
+ children: /* @__PURE__ */ (0, d.jsx)(p, {
45
+ chartType: t.chartType,
46
+ data: t.data,
47
+ config: t.config,
48
+ xAxisKey: t.xAxisKey,
49
+ series: t.series,
50
+ className: t.className
51
+ })
52
+ });
8
53
  };
54
+ //#endregion
55
+ //#region src/ObjectChart.tsx
56
+ function g(e, t) {
57
+ let { field: n, function: r, groupBy: i } = t, a = {};
58
+ for (let t of e) {
59
+ let e = String(t[i] ?? "Unknown");
60
+ a[e] || (a[e] = []), a[e].push(t);
61
+ }
62
+ return Object.entries(a).map(([e, t]) => {
63
+ let a = t.map((e) => Number(e[n]) || 0), o;
64
+ switch (r) {
65
+ case "count":
66
+ o = t.length;
67
+ break;
68
+ case "avg":
69
+ o = a.length > 0 ? a.reduce((e, t) => e + t, 0) / a.length : 0;
70
+ break;
71
+ case "min":
72
+ o = a.length > 0 ? Math.min(...a) : 0;
73
+ break;
74
+ case "max":
75
+ o = a.length > 0 ? Math.max(...a) : 0;
76
+ break;
77
+ default:
78
+ o = a.reduce((e, t) => e + t, 0);
79
+ break;
80
+ }
81
+ return {
82
+ [i]: e,
83
+ [n]: o
84
+ };
85
+ });
86
+ }
87
+ var _ = (e) => {
88
+ let { schema: t } = e, r = a(l), i = e.dataSource || r?.dataSource, c = u(t.bind), [f, p] = s([]), [m, _] = s(!1);
89
+ o(() => {
90
+ let e = !0;
91
+ return t.objectName && !c && !t.data && (async () => {
92
+ if (!(!i || !t.objectName)) {
93
+ e && _(!0);
94
+ try {
95
+ let r;
96
+ if (t.aggregate && typeof i.aggregate == "function") {
97
+ let e = await i.aggregate(t.objectName, {
98
+ field: t.aggregate.field,
99
+ function: t.aggregate.function,
100
+ groupBy: t.aggregate.groupBy,
101
+ filter: t.filter
102
+ });
103
+ r = Array.isArray(e) ? e : [];
104
+ } else if (typeof i.find == "function") r = n(await i.find(t.objectName, { $filter: t.filter })), t.aggregate && r.length > 0 && (r = g(r, t.aggregate));
105
+ else return;
106
+ e && p(r);
107
+ } catch (e) {
108
+ console.error("[ObjectChart] Fetch error:", e);
109
+ } finally {
110
+ e && _(!1);
111
+ }
112
+ }
113
+ })(), () => {
114
+ e = !1;
115
+ };
116
+ }, [
117
+ t.objectName,
118
+ i,
119
+ c,
120
+ t.data,
121
+ t.filter,
122
+ t.aggregate
123
+ ]);
124
+ let v = c || t.data || f, y = Array.isArray(v) ? v : [], b = {
125
+ ...t,
126
+ data: y
127
+ };
128
+ return m && y.length === 0 ? /* @__PURE__ */ (0, d.jsx)("div", {
129
+ className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (t.className || ""),
130
+ children: "Loading chart data…"
131
+ }) : !i && t.objectName && y.length === 0 ? /* @__PURE__ */ (0, d.jsxs)("div", {
132
+ className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (t.className || ""),
133
+ children: [
134
+ "No data source available for \"",
135
+ t.objectName,
136
+ "\""
137
+ ]
138
+ }) : /* @__PURE__ */ (0, d.jsx)(h, {
139
+ ...e,
140
+ schema: b
141
+ });
142
+ };
143
+ t.register("object-chart", _, {
144
+ namespace: "plugin-charts",
145
+ label: "Object Chart",
146
+ category: "view",
147
+ inputs: [
148
+ {
149
+ name: "objectName",
150
+ type: "string",
151
+ label: "Object Name",
152
+ required: !0
153
+ },
154
+ {
155
+ name: "data",
156
+ type: "array",
157
+ label: "Data",
158
+ description: "Optional static data"
159
+ },
160
+ {
161
+ name: "filter",
162
+ type: "array",
163
+ label: "Filter"
164
+ },
165
+ {
166
+ name: "aggregate",
167
+ type: "object",
168
+ label: "Aggregate",
169
+ description: "Aggregation config: { field, function, groupBy }"
170
+ }
171
+ ]
172
+ });
173
+ //#endregion
174
+ //#region src/index.tsx
175
+ var v = {
176
+ "bar-chart": m,
177
+ chart: h
178
+ };
179
+ t.register("bar-chart", m, {
180
+ namespace: "plugin-charts",
181
+ label: "Bar Chart",
182
+ category: "plugin",
183
+ inputs: [
184
+ {
185
+ name: "data",
186
+ type: "array",
187
+ label: "Data",
188
+ required: !0
189
+ },
190
+ {
191
+ name: "dataKey",
192
+ type: "string",
193
+ label: "Data Key",
194
+ defaultValue: "value"
195
+ },
196
+ {
197
+ name: "xAxisKey",
198
+ type: "string",
199
+ label: "X-Axis Key",
200
+ defaultValue: "name"
201
+ },
202
+ {
203
+ name: "height",
204
+ type: "number",
205
+ label: "Height",
206
+ defaultValue: 400
207
+ },
208
+ {
209
+ name: "color",
210
+ type: "color",
211
+ label: "Color",
212
+ defaultValue: "#8884d8"
213
+ }
214
+ ],
215
+ defaultProps: {
216
+ data: [
217
+ {
218
+ name: "Jan",
219
+ value: 400
220
+ },
221
+ {
222
+ name: "Feb",
223
+ value: 300
224
+ },
225
+ {
226
+ name: "Mar",
227
+ value: 600
228
+ },
229
+ {
230
+ name: "Apr",
231
+ value: 800
232
+ },
233
+ {
234
+ name: "May",
235
+ value: 500
236
+ }
237
+ ],
238
+ dataKey: "value",
239
+ xAxisKey: "name",
240
+ height: 400,
241
+ color: "#8884d8"
242
+ }
243
+ }), t.register("chart", _, {
244
+ namespace: "view",
245
+ category: "view",
246
+ label: "Chart",
247
+ inputs: [
248
+ {
249
+ name: "objectName",
250
+ type: "string",
251
+ label: "Object Name",
252
+ required: !0
253
+ },
254
+ {
255
+ name: "type",
256
+ type: "string",
257
+ label: "Chart Type"
258
+ },
259
+ {
260
+ name: "categoryField",
261
+ type: "string",
262
+ label: "Category Field"
263
+ },
264
+ {
265
+ name: "valueField",
266
+ type: "string",
267
+ label: "Value Field"
268
+ }
269
+ ]
270
+ }), t.register("chart", h, {
271
+ namespace: "plugin-charts",
272
+ label: "Chart",
273
+ category: "plugin",
274
+ inputs: [
275
+ {
276
+ name: "chartType",
277
+ type: "enum",
278
+ label: "Chart Type",
279
+ enum: [
280
+ {
281
+ label: "Bar",
282
+ value: "bar"
283
+ },
284
+ {
285
+ label: "Line",
286
+ value: "line"
287
+ },
288
+ {
289
+ label: "Area",
290
+ value: "area"
291
+ },
292
+ {
293
+ label: "Pie",
294
+ value: "pie"
295
+ },
296
+ {
297
+ label: "Donut",
298
+ value: "donut"
299
+ },
300
+ {
301
+ label: "Radar",
302
+ value: "radar"
303
+ },
304
+ {
305
+ label: "Scatter",
306
+ value: "scatter"
307
+ }
308
+ ],
309
+ defaultValue: "bar"
310
+ },
311
+ {
312
+ name: "data",
313
+ type: "code",
314
+ label: "Data (JSON)",
315
+ required: !0
316
+ },
317
+ {
318
+ name: "config",
319
+ type: "code",
320
+ label: "Config (JSON)"
321
+ },
322
+ {
323
+ name: "xAxisKey",
324
+ type: "string",
325
+ label: "X Axis Key",
326
+ defaultValue: "name"
327
+ },
328
+ {
329
+ name: "series",
330
+ type: "code",
331
+ label: "Series (JSON Array)",
332
+ required: !0
333
+ },
334
+ {
335
+ name: "className",
336
+ type: "string",
337
+ label: "CSS Class"
338
+ }
339
+ ],
340
+ defaultProps: {
341
+ chartType: "bar",
342
+ data: [
343
+ {
344
+ name: "Jan",
345
+ sales: 400,
346
+ revenue: 240
347
+ },
348
+ {
349
+ name: "Feb",
350
+ sales: 300,
351
+ revenue: 139
352
+ },
353
+ {
354
+ name: "Mar",
355
+ sales: 600,
356
+ revenue: 380
357
+ },
358
+ {
359
+ name: "Apr",
360
+ sales: 800,
361
+ revenue: 430
362
+ },
363
+ {
364
+ name: "May",
365
+ sales: 500,
366
+ revenue: 220
367
+ }
368
+ ],
369
+ config: {
370
+ sales: {
371
+ label: "Sales",
372
+ color: "#8884d8"
373
+ },
374
+ revenue: {
375
+ label: "Revenue",
376
+ color: "#82ca9d"
377
+ }
378
+ },
379
+ xAxisKey: "name",
380
+ series: [{ dataKey: "sales" }, { dataKey: "revenue" }]
381
+ }
382
+ }), t.register("chart:bar", h, {
383
+ namespace: "plugin-charts",
384
+ label: "Bar Chart (Alias)",
385
+ category: "plugin",
386
+ defaultProps: { chartType: "bar" }
387
+ }), t.register("pie-chart", h, {
388
+ namespace: "plugin-charts",
389
+ label: "Pie Chart",
390
+ category: "plugin",
391
+ defaultProps: { chartType: "pie" }
392
+ }), t.register("donut-chart", h, {
393
+ namespace: "plugin-charts",
394
+ label: "Donut Chart",
395
+ category: "plugin",
396
+ defaultProps: { chartType: "donut" }
397
+ }), t.register("radar-chart", h, {
398
+ namespace: "plugin-charts",
399
+ label: "Radar Chart",
400
+ category: "plugin",
401
+ defaultProps: { chartType: "radar" }
402
+ }), t.register("scatter-chart", h, {
403
+ namespace: "plugin-charts",
404
+ label: "Scatter Chart",
405
+ category: "plugin",
406
+ defaultProps: { chartType: "scatter" }
407
+ });
408
+ //#endregion
409
+ export { m as ChartBarRenderer, h as ChartRenderer, _ as ObjectChart, v as chartComponents };