@object-ui/plugin-charts 4.0.6 → 4.0.8

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/dist/index.js CHANGED
@@ -1,28 +1,28 @@
1
- import { ComponentRegistry as e, extractRecords as t } from "@object-ui/core";
2
- import * as n from "react";
3
- import r, { Suspense as i, useCallback as a, useContext as o, useEffect as s, useMemo as c, useRef as l, useState as u } from "react";
4
- import { Skeleton as d } from "@object-ui/components";
5
- import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
6
- import { Area as h, AreaChart as g, Bar as _, BarChart as v, CartesianGrid as y, Cell as b, Legend as x, Line as S, LineChart as C, Pie as w, PieChart as T, PolarAngleAxis as E, PolarGrid as D, PolarRadiusAxis as ee, Radar as te, RadarChart as O, ResponsiveContainer as k, Scatter as ne, ScatterChart as A, Tooltip as j, XAxis as M, YAxis as N, ZAxis as re } from "recharts";
7
- import { SchemaRendererContext as ie, useDataScope as ae } from "@object-ui/react";
8
- import { AlertCircle as oe } from "lucide-react";
9
- import { useSafeFieldLabel as se } from "@object-ui/i18n";
1
+ import { ComponentRegistry as e, computeDrillFilter as t, extractRecords as n, isDrillEnabled as r, resolveDateMacros as i, resolveDrillTitle as a } from "@object-ui/core";
2
+ import * as o from "react";
3
+ import s, { Suspense as c, useCallback as l, useContext as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
4
+ import { Dialog as h, DialogContent as g, DialogHeader as _, DialogTitle as v, Sheet as ee, SheetContent as te, SheetHeader as ne, SheetTitle as re, Skeleton as y } from "@object-ui/components";
5
+ import { Fragment as ie, jsx as b, jsxs as x } from "react/jsx-runtime";
6
+ import { Area as S, AreaChart as C, Bar as w, BarChart as T, CartesianGrid as E, Cell as D, Funnel as ae, FunnelChart as O, LabelList as k, Legend as A, Line as j, LineChart as M, Pie as N, PieChart as P, PolarAngleAxis as F, PolarGrid as I, PolarRadiusAxis as L, Radar as R, RadarChart as oe, ResponsiveContainer as se, Scatter as ce, ScatterChart as le, Tooltip as ue, XAxis as z, YAxis as B, ZAxis as de } from "recharts";
7
+ import { SchemaRenderer as fe, SchemaRendererContext as pe, useDataScope as me } from "@object-ui/react";
8
+ import { AlertCircle as he } from "lucide-react";
9
+ import { useSafeFieldLabel as ge } from "@object-ui/i18n";
10
10
  //#region \0rolldown/runtime.js
11
- var P = Object.defineProperty, F = (e, t) => () => (e && (t = e(e = 0)), t), I = (e, t) => {
11
+ var _e = Object.defineProperty, V = (e, t) => () => (e && (t = e(e = 0)), t), ve = (e, t) => {
12
12
  let n = {};
13
- for (var r in e) P(n, r, {
13
+ for (var r in e) _e(n, r, {
14
14
  get: e[r],
15
15
  enumerable: !0
16
16
  });
17
- return t || P(n, Symbol.toStringTag, { value: "Module" }), n;
18
- }, ce = /* @__PURE__ */ I({ default: () => le });
19
- function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height: r = 400, className: i = "", color: a = "hsl(var(--primary))" }) {
20
- return /* @__PURE__ */ p("div", {
17
+ return t || _e(n, Symbol.toStringTag, { value: "Module" }), n;
18
+ }, ye = /* @__PURE__ */ ve({ default: () => be });
19
+ function be({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height: r = 400, className: i = "", color: a = "hsl(var(--primary))" }) {
20
+ return /* @__PURE__ */ b("div", {
21
21
  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 ${i}`,
22
- children: /* @__PURE__ */ p(k, {
22
+ children: /* @__PURE__ */ b(se, {
23
23
  width: "100%",
24
24
  height: r,
25
- children: /* @__PURE__ */ m(v, {
25
+ children: /* @__PURE__ */ x(T, {
26
26
  data: e,
27
27
  margin: {
28
28
  top: 10,
@@ -31,64 +31,64 @@ function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height:
31
31
  bottom: 5
32
32
  },
33
33
  children: [
34
- /* @__PURE__ */ m("defs", { children: [/* @__PURE__ */ m("linearGradient", {
34
+ /* @__PURE__ */ x("defs", { children: [/* @__PURE__ */ x("linearGradient", {
35
35
  id: "barGradient",
36
36
  x1: "0",
37
37
  y1: "0",
38
38
  x2: "0",
39
39
  y2: "1",
40
40
  children: [
41
- /* @__PURE__ */ p("stop", {
41
+ /* @__PURE__ */ b("stop", {
42
42
  offset: "0%",
43
43
  stopColor: a,
44
44
  stopOpacity: 1
45
45
  }),
46
- /* @__PURE__ */ p("stop", {
46
+ /* @__PURE__ */ b("stop", {
47
47
  offset: "90%",
48
48
  stopColor: a,
49
49
  stopOpacity: .6
50
50
  }),
51
- /* @__PURE__ */ p("stop", {
51
+ /* @__PURE__ */ b("stop", {
52
52
  offset: "100%",
53
53
  stopColor: a,
54
54
  stopOpacity: .3
55
55
  })
56
56
  ]
57
- }), /* @__PURE__ */ m("filter", {
57
+ }), /* @__PURE__ */ x("filter", {
58
58
  id: "glow",
59
59
  height: "130%",
60
60
  children: [
61
- /* @__PURE__ */ p("feGaussianBlur", {
61
+ /* @__PURE__ */ b("feGaussianBlur", {
62
62
  in: "SourceAlpha",
63
63
  stdDeviation: "3",
64
64
  result: "blur"
65
65
  }),
66
- /* @__PURE__ */ p("feOffset", {
66
+ /* @__PURE__ */ b("feOffset", {
67
67
  in: "blur",
68
68
  dx: "0",
69
69
  dy: "0",
70
70
  result: "offsetBlur"
71
71
  }),
72
- /* @__PURE__ */ p("feFlood", {
72
+ /* @__PURE__ */ b("feFlood", {
73
73
  floodColor: a,
74
74
  floodOpacity: "0.5",
75
75
  result: "offsetColor"
76
76
  }),
77
- /* @__PURE__ */ p("feComposite", {
77
+ /* @__PURE__ */ b("feComposite", {
78
78
  in: "offsetColor",
79
79
  in2: "offsetBlur",
80
80
  operator: "in",
81
81
  result: "offsetBlur"
82
82
  }),
83
- /* @__PURE__ */ m("feMerge", { children: [/* @__PURE__ */ p("feMergeNode", { in: "offsetBlur" }), /* @__PURE__ */ p("feMergeNode", { in: "SourceGraphic" })] })
83
+ /* @__PURE__ */ x("feMerge", { children: [/* @__PURE__ */ b("feMergeNode", { in: "offsetBlur" }), /* @__PURE__ */ b("feMergeNode", { in: "SourceGraphic" })] })
84
84
  ]
85
85
  })] }),
86
- /* @__PURE__ */ p(y, {
86
+ /* @__PURE__ */ b(E, {
87
87
  strokeDasharray: "3 3",
88
88
  stroke: "hsl(var(--border))",
89
89
  vertical: !1
90
90
  }),
91
- /* @__PURE__ */ p(M, {
91
+ /* @__PURE__ */ b(z, {
92
92
  dataKey: n,
93
93
  tick: {
94
94
  fill: "hsl(var(--muted-foreground))",
@@ -99,7 +99,7 @@ function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height:
99
99
  axisLine: { stroke: "hsl(var(--border))" },
100
100
  dy: 10
101
101
  }),
102
- /* @__PURE__ */ p(N, {
102
+ /* @__PURE__ */ b(B, {
103
103
  tick: {
104
104
  fill: "hsl(var(--muted-foreground))",
105
105
  fontSize: 12,
@@ -108,7 +108,7 @@ function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height:
108
108
  tickLine: !1,
109
109
  axisLine: !1
110
110
  }),
111
- /* @__PURE__ */ p(j, {
111
+ /* @__PURE__ */ b(ue, {
112
112
  cursor: {
113
113
  fill: "hsl(var(--muted))",
114
114
  opacity: .2
@@ -123,11 +123,11 @@ function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height:
123
123
  },
124
124
  itemStyle: { color: "hsl(var(--primary))" }
125
125
  }),
126
- /* @__PURE__ */ p(x, { wrapperStyle: {
126
+ /* @__PURE__ */ b(A, { wrapperStyle: {
127
127
  paddingTop: "20px",
128
128
  fontFamily: "monospace"
129
129
  } }),
130
- /* @__PURE__ */ p(_, {
130
+ /* @__PURE__ */ b(w, {
131
131
  dataKey: t,
132
132
  fill: "url(#barGradient)",
133
133
  radius: [
@@ -144,79 +144,79 @@ function le({ data: e = [], dataKey: t = "value", xAxisKey: n = "name", height:
144
144
  })
145
145
  });
146
146
  }
147
- var ue = F((() => {}));
147
+ var xe = V((() => {}));
148
148
  //#endregion
149
149
  //#region src/ChartContainerImpl.tsx
150
- function L() {
151
- let e = n.useContext(W);
150
+ function Se() {
151
+ let e = o.useContext(we);
152
152
  if (!e) throw Error("useChart must be used within a <ChartContainer />");
153
153
  return e;
154
154
  }
155
- function R({ id: e, className: t, children: r, config: i, ...a }) {
156
- let o = n.useId(), s = `chart-${e || o.replace(/:/g, "")}`;
157
- return /* @__PURE__ */ p(W.Provider, {
158
- value: { config: i },
159
- children: /* @__PURE__ */ m("div", {
155
+ function H({ id: e, className: t, children: n, config: r, ...i }) {
156
+ let a = o.useId(), s = `chart-${e || a.replace(/:/g, "")}`;
157
+ return /* @__PURE__ */ b(we.Provider, {
158
+ value: { config: r },
159
+ children: /* @__PURE__ */ x("div", {
160
160
  "data-slot": "chart",
161
161
  "data-chart": s,
162
- className: H("flex w-full h-[350px] justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground", t),
163
- ...a,
164
- children: [/* @__PURE__ */ p(G, {
162
+ className: K("flex w-full h-[350px] justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground", t),
163
+ ...i,
164
+ children: [/* @__PURE__ */ b(Te, {
165
165
  id: s,
166
- config: i
167
- }), /* @__PURE__ */ p(k, {
166
+ config: r
167
+ }), /* @__PURE__ */ b(se, {
168
168
  width: "100%",
169
169
  height: "100%",
170
- children: r
170
+ children: n
171
171
  })]
172
172
  })
173
173
  });
174
174
  }
175
- function z({ active: e, payload: t, className: r, indicator: i = "dot", hideLabel: a = !1, hideIndicator: o = !1, label: s, labelFormatter: c, labelClassName: l, formatter: u, color: d, nameKey: h, labelKey: g }) {
176
- let { config: _ } = L(), v = n.useMemo(() => {
177
- if (a || !t?.length) return null;
178
- let [e] = t, n = V(_, e, `${g || e?.dataKey || e?.name || "value"}`), r = !g && typeof s == "string" ? _[s]?.label || s : n?.label;
179
- return c ? /* @__PURE__ */ p("div", {
180
- className: H("font-medium", l),
175
+ function U({ active: e, payload: t, className: n, indicator: r = "dot", hideLabel: i = !1, hideIndicator: a = !1, label: s, labelFormatter: c, labelClassName: l, formatter: u, color: d, nameKey: f, labelKey: p }) {
176
+ let { config: m } = Se(), h = o.useMemo(() => {
177
+ if (i || !t?.length) return null;
178
+ let [e] = t, n = G(m, e, `${p || e?.dataKey || e?.name || "value"}`), r = !p && typeof s == "string" ? m[s]?.label || s : n?.label;
179
+ return c ? /* @__PURE__ */ b("div", {
180
+ className: K("font-medium", l),
181
181
  children: c(r, t)
182
- }) : r ? /* @__PURE__ */ p("div", {
183
- className: H("font-medium", l),
182
+ }) : r ? /* @__PURE__ */ b("div", {
183
+ className: K("font-medium", l),
184
184
  children: r
185
185
  }) : null;
186
186
  }, [
187
187
  s,
188
188
  c,
189
189
  t,
190
- a,
190
+ i,
191
191
  l,
192
- _,
193
- g
192
+ m,
193
+ p
194
194
  ]);
195
195
  if (!e || !t?.length) return null;
196
- let y = t.length === 1 && i !== "dot";
197
- return /* @__PURE__ */ m("div", {
198
- className: H("border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl", r),
199
- children: [y ? null : v, /* @__PURE__ */ p("div", {
196
+ let g = t.length === 1 && r !== "dot";
197
+ return /* @__PURE__ */ x("div", {
198
+ className: K("border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl", n),
199
+ children: [g ? null : h, /* @__PURE__ */ b("div", {
200
200
  className: "grid gap-1.5",
201
201
  children: t.filter((e) => e.type !== "none").map((e, t) => {
202
- let n = V(_, e, `${h || e.name || e.dataKey || "value"}`), r = d || e.payload.fill || e.color;
203
- return /* @__PURE__ */ p("div", {
204
- className: H("[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5", i === "dot" ? "items-center" : ""),
205
- children: u && e?.value !== void 0 && e.name ? u(e.value, e.name, e, t, e.payload) : /* @__PURE__ */ m(f, { children: [n?.icon ? /* @__PURE__ */ p(n.icon, {}) : !o && /* @__PURE__ */ p("div", {
206
- className: H("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", i === "dot" ? "h-2.5 w-2.5" : "", i === "line" ? "w-1" : "", i === "dashed" ? "w-0 border-[1.5px] border-dashed bg-transparent" : "", y && i === "dashed" ? "my-0.5" : ""),
202
+ let n = G(m, e, `${f || e.name || e.dataKey || "value"}`), i = d || e.payload.fill || e.color;
203
+ return /* @__PURE__ */ b("div", {
204
+ className: K("[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5", r === "dot" ? "items-center" : ""),
205
+ children: u && e?.value !== void 0 && e.name ? u(e.value, e.name, e, t, e.payload) : /* @__PURE__ */ x(ie, { children: [n?.icon ? /* @__PURE__ */ b(n.icon, {}) : !a && /* @__PURE__ */ b("div", {
206
+ className: K("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", r === "dot" ? "h-2.5 w-2.5" : "", r === "line" ? "w-1" : "", r === "dashed" ? "w-0 border-[1.5px] border-dashed bg-transparent" : "", g && r === "dashed" ? "my-0.5" : ""),
207
207
  style: {
208
- "--color-bg": r,
209
- "--color-border": r
208
+ "--color-bg": i,
209
+ "--color-border": i
210
210
  }
211
- }), /* @__PURE__ */ m("div", {
212
- className: H("flex flex-1 justify-between leading-none", y ? "items-end" : "items-center"),
213
- children: [/* @__PURE__ */ m("div", {
211
+ }), /* @__PURE__ */ x("div", {
212
+ className: K("flex flex-1 justify-between leading-none", g ? "items-end" : "items-center"),
213
+ children: [/* @__PURE__ */ x("div", {
214
214
  className: "grid gap-1.5",
215
- children: [y ? v : null, /* @__PURE__ */ p("span", {
215
+ children: [g ? h : null, /* @__PURE__ */ b("span", {
216
216
  className: "text-muted-foreground",
217
217
  children: n?.label || e.name
218
218
  })]
219
- }), e.value && /* @__PURE__ */ p("span", {
219
+ }), e.value && /* @__PURE__ */ b("span", {
220
220
  className: "text-foreground font-mono font-medium tabular-nums",
221
221
  children: e.value.toLocaleString()
222
222
  })]
@@ -226,15 +226,15 @@ function z({ active: e, payload: t, className: r, indicator: i = "dot", hideLabe
226
226
  })]
227
227
  });
228
228
  }
229
- function B({ className: e, hideIcon: t = !1, payload: n, verticalAlign: r = "bottom", nameKey: i }) {
230
- let { config: a } = L();
231
- return n?.length ? /* @__PURE__ */ p("div", {
232
- className: H("flex items-center justify-center gap-4", r === "top" ? "pb-3" : "pt-3", e),
229
+ function W({ className: e, hideIcon: t = !1, payload: n, verticalAlign: r = "bottom", nameKey: i }) {
230
+ let { config: a } = Se();
231
+ return n?.length ? /* @__PURE__ */ b("div", {
232
+ className: K("flex items-center justify-center gap-4", r === "top" ? "pb-3" : "pt-3", e),
233
233
  children: n.filter((e) => e.type !== "none").map((e) => {
234
- let n = V(a, e, `${i || e.dataKey || "value"}`);
235
- return /* @__PURE__ */ m("div", {
236
- className: H("[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"),
237
- children: [n?.icon && !t ? /* @__PURE__ */ p(n.icon, {}) : /* @__PURE__ */ p("div", {
234
+ let n = G(a, e, `${i || e.dataKey || "value"}`);
235
+ return /* @__PURE__ */ x("div", {
236
+ className: K("[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"),
237
+ children: [n?.icon && !t ? /* @__PURE__ */ b(n.icon, {}) : /* @__PURE__ */ b("div", {
238
238
  className: "h-2 w-2 shrink-0 rounded-[2px]",
239
239
  style: { backgroundColor: e.color }
240
240
  }), n?.label]
@@ -242,18 +242,18 @@ function B({ className: e, hideIcon: t = !1, payload: n, verticalAlign: r = "bot
242
242
  })
243
243
  }) : null;
244
244
  }
245
- function V(e, t, n) {
245
+ function G(e, t, n) {
246
246
  if (typeof t != "object" || !t) return;
247
247
  let r = "payload" in t && typeof t.payload == "object" && t.payload !== null ? t.payload : void 0, i = n;
248
248
  return n in t && typeof t[n] == "string" ? i = t[n] : r && n in r && typeof r[n] == "string" && (i = r[n]), i in e ? e[i] : e[n];
249
249
  }
250
- var H, U, W, G, K, q, de = F((() => {
251
- H = (...e) => e.filter(Boolean).join(" "), U = {
250
+ var K, Ce, we, Te, q, J, Ee = V((() => {
251
+ K = (...e) => e.filter(Boolean).join(" "), Ce = {
252
252
  light: "",
253
253
  dark: ".dark"
254
- }, W = n.createContext(null), G = ({ id: e, config: t }) => {
254
+ }, we = o.createContext(null), Te = ({ id: e, config: t }) => {
255
255
  let n = Object.entries(t).filter(([, e]) => e.theme || e.color);
256
- return n.length ? /* @__PURE__ */ p("style", { dangerouslySetInnerHTML: { __html: Object.entries(U).map(([t, r]) => `
256
+ return n.length ? /* @__PURE__ */ b("style", { dangerouslySetInnerHTML: { __html: Object.entries(Ce).map(([t, r]) => `
257
257
  ${r} [data-chart=${e}] {
258
258
  ${n.map(([e, n]) => {
259
259
  let r = n.theme?.[t] || n.color;
@@ -261,24 +261,77 @@ ${n.map(([e, n]) => {
261
261
  }).join("\n")}
262
262
  }
263
263
  `).join("\n") } }) : null;
264
- }, K = j, q = x;
265
- })), fe = /* @__PURE__ */ I({ default: () => pe });
266
- function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i = "name", series: a = [], className: o = "" }) {
267
- let s = Array.isArray(t) ? t : [], [c, l] = n.useState(!1);
268
- n.useEffect(() => {
269
- let e = () => l(window.innerWidth < 640);
264
+ }, q = ue, J = A;
265
+ })), De = /* @__PURE__ */ ve({ default: () => Oe });
266
+ function Oe({ chartType: e = "bar", data: t = [], config: n = {}, xAxisKey: r = "name", series: i = [], className: a = "", onChartClick: s }) {
267
+ let c = Array.isArray(t) ? t : [], [l, u] = o.useState(!1), d = o.useCallback((e) => {
268
+ if (!s || !e) return;
269
+ let t = Array.isArray(e.activePayload) ? e.activePayload[0] : void 0;
270
+ s({
271
+ category: e.activeLabel == null ? void 0 : String(e.activeLabel),
272
+ series: t?.dataKey ? String(t.dataKey) : void 0,
273
+ value: typeof t?.value == "number" ? t.value : void 0
274
+ });
275
+ }, [s]), f = o.useCallback((e) => {
276
+ if (!s || !e) return;
277
+ let t = e.payload?.[r], n = i[0]?.dataKey || "value";
278
+ s({
279
+ category: t == null ? void 0 : String(t),
280
+ series: n,
281
+ value: typeof e.payload?.[n] == "number" ? e.payload[n] : void 0
282
+ });
283
+ }, [
284
+ s,
285
+ r,
286
+ i
287
+ ]), p = s ? {
288
+ onClick: d,
289
+ style: { cursor: "pointer" }
290
+ } : {}, m = s ? {
291
+ onClick: f,
292
+ style: { cursor: "pointer" }
293
+ } : {};
294
+ o.useEffect(() => {
295
+ let e = () => u(window.innerWidth < 640);
270
296
  return e(), window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
271
297
  }, []);
272
- let u = {
273
- bar: v,
274
- line: C,
275
- area: g,
276
- pie: T,
277
- donut: T,
278
- radar: O,
279
- scatter: A,
280
- combo: v
281
- }[e] || v, d = n.useMemo(() => s.some((e) => String(e[i] || "").length > 5), [s, i]), f = () => [
298
+ let h = {
299
+ bar: T,
300
+ "horizontal-bar": T,
301
+ line: M,
302
+ area: C,
303
+ pie: P,
304
+ donut: P,
305
+ radar: oe,
306
+ scatter: le,
307
+ funnel: O,
308
+ combo: T
309
+ }[e] || T, g = o.useCallback((e) => {
310
+ if (e == null || e === "") return "";
311
+ let t = typeof e == "string" ? e : String(e);
312
+ if (/^\d{4}-\d{2}-\d{2}/.test(t)) {
313
+ let e = new Date(t);
314
+ if (!Number.isNaN(e.getTime())) {
315
+ let t = (c.length > 1 ? Math.abs(new Date(String(c[c.length - 1][r] ?? "")).getTime() - new Date(String(c[0][r] ?? "")).getTime()) : 0) / (1e3 * 60 * 60 * 24);
316
+ try {
317
+ return t <= 62 ? e.toLocaleDateString(void 0, {
318
+ month: "short",
319
+ day: "numeric"
320
+ }) : e.toLocaleDateString(void 0, {
321
+ month: "short",
322
+ year: "numeric"
323
+ });
324
+ } catch {
325
+ return e.toISOString().slice(0, 10);
326
+ }
327
+ }
328
+ }
329
+ return l && t.length > 8 ? t.slice(0, 8) + "…" : t;
330
+ }, [
331
+ c,
332
+ r,
333
+ l
334
+ ]), _ = o.useMemo(() => c.some((e) => String(e[r] || "").length > 5), [c, r]), v = () => [
282
335
  "hsl(var(--chart-1))",
283
336
  "hsl(var(--chart-2))",
284
337
  "hsl(var(--chart-3))",
@@ -287,34 +340,35 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
287
340
  ];
288
341
  if (e === "pie" || e === "donut") {
289
342
  let t = e === "donut" ? 60 : 0;
290
- return /* @__PURE__ */ p(R, {
291
- config: r,
292
- className: o,
293
- children: /* @__PURE__ */ m(T, { children: [
294
- /* @__PURE__ */ p(K, {
343
+ return /* @__PURE__ */ b(H, {
344
+ config: n,
345
+ className: a,
346
+ children: /* @__PURE__ */ x(P, { children: [
347
+ /* @__PURE__ */ b(q, {
295
348
  cursor: !1,
296
- content: /* @__PURE__ */ p(z, { hideLabel: !0 })
349
+ content: /* @__PURE__ */ b(U, { hideLabel: !0 })
297
350
  }),
298
- /* @__PURE__ */ p(w, {
299
- data: s,
300
- dataKey: a[0]?.dataKey || "value",
301
- nameKey: i || "name",
351
+ /* @__PURE__ */ b(N, {
352
+ data: c,
353
+ dataKey: i[0]?.dataKey || "value",
354
+ nameKey: r || "name",
302
355
  innerRadius: t,
303
356
  strokeWidth: 5,
304
357
  paddingAngle: 2,
305
358
  outerRadius: 80,
306
- children: s.map((e, t) => {
307
- let n = r[e[i]]?.color;
308
- if (!n) {
309
- let e = f();
310
- n = e[t % e.length];
359
+ ...m,
360
+ children: c.map((e, t) => {
361
+ let i = n[e[r]]?.color;
362
+ if (!i) {
363
+ let e = v();
364
+ i = e[t % e.length];
311
365
  }
312
- return /* @__PURE__ */ p(b, { fill: Y(n) }, `cell-${t}`);
366
+ return /* @__PURE__ */ b(D, { fill: X(i) }, `cell-${t}`);
313
367
  })
314
368
  }),
315
- /* @__PURE__ */ p(q, {
316
- content: /* @__PURE__ */ p(B, { nameKey: i }),
317
- ...c && {
369
+ /* @__PURE__ */ b(J, {
370
+ content: /* @__PURE__ */ b(W, { nameKey: r }),
371
+ ...l && {
318
372
  verticalAlign: "bottom",
319
373
  wrapperStyle: {
320
374
  fontSize: "11px",
@@ -325,19 +379,47 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
325
379
  ] })
326
380
  });
327
381
  }
328
- return e === "radar" ? /* @__PURE__ */ p(R, {
329
- config: r,
330
- className: o,
331
- children: /* @__PURE__ */ m(O, {
332
- data: s,
382
+ if (e === "funnel") {
383
+ let e = i[0]?.dataKey || "value", t = v(), o = s ? (t) => {
384
+ t && s({
385
+ category: t?.payload?.[r] ?? t?.[r],
386
+ value: t?.payload?.[e] ?? t?.[e]
387
+ });
388
+ } : void 0;
389
+ return /* @__PURE__ */ b(H, {
390
+ config: n,
391
+ className: a,
392
+ children: /* @__PURE__ */ x(O, { children: [/* @__PURE__ */ b(q, { content: /* @__PURE__ */ b(U, {}) }), /* @__PURE__ */ x(ae, {
393
+ dataKey: e,
394
+ data: c,
395
+ nameKey: r,
396
+ isAnimationActive: !0,
397
+ ...o ? {
398
+ onClick: o,
399
+ style: { cursor: "pointer" }
400
+ } : {},
401
+ children: [/* @__PURE__ */ b(k, {
402
+ position: "right",
403
+ fill: "hsl(var(--foreground))",
404
+ stroke: "none",
405
+ dataKey: r
406
+ }), c.map((e, n) => /* @__PURE__ */ b(D, { fill: X(t[n % t.length]) }, `funnel-cell-${n}`))]
407
+ })] })
408
+ });
409
+ }
410
+ if (e === "radar") return /* @__PURE__ */ b(H, {
411
+ config: n,
412
+ className: a,
413
+ children: /* @__PURE__ */ x(oe, {
414
+ data: c,
333
415
  children: [
334
- /* @__PURE__ */ p(D, {}),
335
- /* @__PURE__ */ p(E, { dataKey: i }),
336
- /* @__PURE__ */ p(ee, {}),
337
- /* @__PURE__ */ p(K, { content: /* @__PURE__ */ p(z, {}) }),
338
- /* @__PURE__ */ p(q, {
339
- content: /* @__PURE__ */ p(B, {}),
340
- ...c && {
416
+ /* @__PURE__ */ b(I, {}),
417
+ /* @__PURE__ */ b(F, { dataKey: r }),
418
+ /* @__PURE__ */ b(L, {}),
419
+ /* @__PURE__ */ b(q, { content: /* @__PURE__ */ b(U, {}) }),
420
+ /* @__PURE__ */ b(J, {
421
+ content: /* @__PURE__ */ b(W, {}),
422
+ ...l && {
341
423
  verticalAlign: "bottom",
342
424
  wrapperStyle: {
343
425
  fontSize: "11px",
@@ -345,9 +427,9 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
345
427
  }
346
428
  }
347
429
  }),
348
- a.map((e) => {
349
- let t = Y(r[e.dataKey]?.color || J);
350
- return /* @__PURE__ */ p(te, {
430
+ i.map((e) => {
431
+ let t = X(n[e.dataKey]?.color || Y);
432
+ return /* @__PURE__ */ b(R, {
351
433
  dataKey: e.dataKey,
352
434
  stroke: t,
353
435
  fill: t,
@@ -356,34 +438,35 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
356
438
  })
357
439
  ]
358
440
  })
359
- }) : e === "scatter" ? /* @__PURE__ */ p(R, {
360
- config: r,
361
- className: o,
362
- children: /* @__PURE__ */ m(A, { children: [
363
- /* @__PURE__ */ p(y, { vertical: !1 }),
364
- /* @__PURE__ */ p(M, {
441
+ });
442
+ if (e === "scatter") return /* @__PURE__ */ b(H, {
443
+ config: n,
444
+ className: a,
445
+ children: /* @__PURE__ */ x(le, { children: [
446
+ /* @__PURE__ */ b(E, { vertical: !1 }),
447
+ /* @__PURE__ */ b(z, {
365
448
  type: "number",
366
- dataKey: i,
367
- name: String(r[i]?.label || i),
449
+ dataKey: r,
450
+ name: String(n[r]?.label || r),
368
451
  tickLine: !1,
369
452
  axisLine: !1,
370
- interval: c ? Math.ceil(s.length / 5) : 0
453
+ interval: l ? Math.ceil(c.length / 5) : 0
371
454
  }),
372
- /* @__PURE__ */ p(N, {
455
+ /* @__PURE__ */ b(B, {
373
456
  type: "number",
374
- dataKey: a[0]?.dataKey || "value",
375
- name: String(r[a[0]?.dataKey]?.label || a[0]?.dataKey),
457
+ dataKey: i[0]?.dataKey || "value",
458
+ name: String(n[i[0]?.dataKey]?.label || i[0]?.dataKey),
376
459
  tickLine: !1,
377
460
  axisLine: !1
378
461
  }),
379
- /* @__PURE__ */ p(re, {
462
+ /* @__PURE__ */ b(de, {
380
463
  type: "number",
381
464
  range: [60, 400]
382
465
  }),
383
- /* @__PURE__ */ p(K, { content: /* @__PURE__ */ p(z, {}) }),
384
- /* @__PURE__ */ p(q, {
385
- content: /* @__PURE__ */ p(B, {}),
386
- ...c && {
466
+ /* @__PURE__ */ b(q, { content: /* @__PURE__ */ b(U, {}) }),
467
+ /* @__PURE__ */ b(J, {
468
+ content: /* @__PURE__ */ b(W, {}),
469
+ ...l && {
387
470
  verticalAlign: "bottom",
388
471
  wrapperStyle: {
389
472
  fontSize: "11px",
@@ -391,50 +474,51 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
391
474
  }
392
475
  }
393
476
  }),
394
- a.map((e, t) => {
395
- let n = f(), i = Y(r[e.dataKey]?.color || n[t % n.length]);
396
- return /* @__PURE__ */ p(ne, {
397
- name: r[e.dataKey]?.label || e.dataKey,
398
- data: s,
477
+ i.map((e, t) => {
478
+ let r = v(), i = X(n[e.dataKey]?.color || r[t % r.length]);
479
+ return /* @__PURE__ */ b(ce, {
480
+ name: n[e.dataKey]?.label || e.dataKey,
481
+ data: c,
399
482
  fill: i
400
483
  }, e.dataKey);
401
484
  })
402
485
  ] })
403
- }) : e === "combo" ? /* @__PURE__ */ p(R, {
404
- config: r,
405
- className: o,
406
- children: /* @__PURE__ */ m(v, {
407
- data: s,
486
+ });
487
+ if (e === "combo") return /* @__PURE__ */ b(H, {
488
+ config: n,
489
+ className: a,
490
+ children: /* @__PURE__ */ x(T, {
491
+ data: c,
408
492
  children: [
409
- /* @__PURE__ */ p(y, { vertical: !1 }),
410
- /* @__PURE__ */ p(M, {
411
- dataKey: i,
493
+ /* @__PURE__ */ b(E, { vertical: !1 }),
494
+ /* @__PURE__ */ b(z, {
495
+ dataKey: r,
412
496
  tickLine: !1,
413
497
  tickMargin: 10,
414
498
  axisLine: !1,
415
- interval: c ? Math.ceil(s.length / 5) : 0,
416
- tickFormatter: (e) => !e || typeof e != "string" ? e : c && e.length > 8 ? e.slice(0, 8) + "…" : e,
417
- ...!c && d && {
499
+ interval: l ? Math.ceil(c.length / 5) : 0,
500
+ tickFormatter: g,
501
+ ...!l && _ && {
418
502
  angle: -35,
419
503
  textAnchor: "end",
420
504
  height: 60
421
505
  }
422
506
  }),
423
- /* @__PURE__ */ p(N, {
507
+ /* @__PURE__ */ b(B, {
424
508
  yAxisId: "left",
425
509
  tickLine: !1,
426
510
  axisLine: !1
427
511
  }),
428
- /* @__PURE__ */ p(N, {
512
+ /* @__PURE__ */ b(B, {
429
513
  yAxisId: "right",
430
514
  orientation: "right",
431
515
  tickLine: !1,
432
516
  axisLine: !1
433
517
  }),
434
- /* @__PURE__ */ p(K, { content: /* @__PURE__ */ p(z, {}) }),
435
- /* @__PURE__ */ p(q, {
436
- content: /* @__PURE__ */ p(B, {}),
437
- ...c && {
518
+ /* @__PURE__ */ b(q, { content: /* @__PURE__ */ b(U, {}) }),
519
+ /* @__PURE__ */ b(J, {
520
+ content: /* @__PURE__ */ b(W, {}),
521
+ ...l && {
438
522
  verticalAlign: "bottom",
439
523
  wrapperStyle: {
440
524
  fontSize: "11px",
@@ -442,55 +526,70 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
442
526
  }
443
527
  }
444
528
  }),
445
- a.map((e, t) => {
446
- let n = Y(r[e.dataKey]?.color || J), i = e.chartType || (t === 0 ? "bar" : "line"), a = i === "bar" ? "left" : "right";
447
- return i === "line" ? /* @__PURE__ */ p(S, {
529
+ i.map((e, t) => {
530
+ let r = X(n[e.dataKey]?.color || Y), i = e.chartType || (t === 0 ? "bar" : "line"), a = i === "bar" ? "left" : "right";
531
+ return i === "line" ? /* @__PURE__ */ b(j, {
448
532
  yAxisId: a,
449
533
  type: "monotone",
450
534
  dataKey: e.dataKey,
451
- stroke: n,
535
+ stroke: r,
452
536
  strokeWidth: 2,
453
537
  dot: !1
454
- }, e.dataKey) : i === "area" ? /* @__PURE__ */ p(h, {
538
+ }, e.dataKey) : i === "area" ? /* @__PURE__ */ b(S, {
455
539
  yAxisId: a,
456
540
  type: "monotone",
457
541
  dataKey: e.dataKey,
458
- fill: n,
459
- stroke: n,
542
+ fill: r,
543
+ stroke: r,
460
544
  fillOpacity: .4
461
- }, e.dataKey) : /* @__PURE__ */ p(_, {
545
+ }, e.dataKey) : /* @__PURE__ */ b(w, {
462
546
  yAxisId: a,
463
547
  dataKey: e.dataKey,
464
- fill: n,
548
+ fill: r,
465
549
  radius: 4
466
550
  }, e.dataKey);
467
551
  })
468
552
  ]
469
553
  })
470
- }) : /* @__PURE__ */ p(R, {
471
- config: r,
472
- className: o,
473
- children: /* @__PURE__ */ m(u, {
474
- data: s,
554
+ });
555
+ let ee = e === "horizontal-bar";
556
+ return /* @__PURE__ */ b(H, {
557
+ config: n,
558
+ className: a,
559
+ children: /* @__PURE__ */ x(h, {
560
+ data: c,
561
+ layout: ee ? "vertical" : "horizontal",
562
+ ...p,
475
563
  children: [
476
- /* @__PURE__ */ p(y, { vertical: !1 }),
477
- /* @__PURE__ */ p(M, {
478
- dataKey: i,
564
+ /* @__PURE__ */ b(E, { vertical: !1 }),
565
+ ee ? /* @__PURE__ */ x(ie, { children: [/* @__PURE__ */ b(z, {
566
+ type: "number",
567
+ tickLine: !1,
568
+ axisLine: !1
569
+ }), /* @__PURE__ */ b(B, {
570
+ type: "category",
571
+ dataKey: r,
572
+ tickLine: !1,
573
+ axisLine: !1,
574
+ width: Math.min(140, Math.max(60, Math.max(...c.map((e) => String(e[r] ?? "").length)) * 7)),
575
+ tickFormatter: g
576
+ })] }) : /* @__PURE__ */ b(z, {
577
+ dataKey: r,
479
578
  tickLine: !1,
480
579
  tickMargin: 10,
481
580
  axisLine: !1,
482
- interval: c ? Math.ceil(s.length / 5) : 0,
483
- tickFormatter: (e) => !e || typeof e != "string" ? e : c && e.length > 8 ? e.slice(0, 8) + "…" : e,
484
- ...!c && d && {
581
+ interval: l ? Math.ceil(c.length / 5) : 0,
582
+ tickFormatter: g,
583
+ ...!l && _ && {
485
584
  angle: -35,
486
585
  textAnchor: "end",
487
586
  height: 60
488
587
  }
489
588
  }),
490
- /* @__PURE__ */ p(K, { content: /* @__PURE__ */ p(z, {}) }),
491
- /* @__PURE__ */ p(q, {
492
- content: /* @__PURE__ */ p(B, {}),
493
- ...c && {
589
+ /* @__PURE__ */ b(q, { content: /* @__PURE__ */ b(U, {}) }),
590
+ /* @__PURE__ */ b(J, {
591
+ content: /* @__PURE__ */ b(W, {}),
592
+ ...l && {
494
593
  verticalAlign: "bottom",
495
594
  wrapperStyle: {
496
595
  fontSize: "11px",
@@ -498,24 +597,24 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
498
597
  }
499
598
  }
500
599
  }),
501
- a.map((t, n) => {
502
- let i = f(), o = Y(r[t.dataKey]?.color || i[n % i.length] || J);
503
- if (e === "bar") {
504
- let e = a.length === 1 && s.length > 1;
505
- return /* @__PURE__ */ p(_, {
600
+ i.map((t, r) => {
601
+ let a = v(), o = X(n[t.dataKey]?.color || a[r % a.length] || Y);
602
+ if (e === "bar" || e === "horizontal-bar") {
603
+ let e = i.length === 1 && c.length > 1;
604
+ return /* @__PURE__ */ b(w, {
506
605
  dataKey: t.dataKey,
507
606
  fill: o,
508
607
  radius: 4,
509
- children: e && s.map((e, t) => /* @__PURE__ */ p(b, { fill: Y(i[t % i.length]) }, `cell-${t}`))
608
+ children: e && c.map((e, t) => /* @__PURE__ */ b(D, { fill: X(a[t % a.length]) }, `cell-${t}`))
510
609
  }, t.dataKey);
511
610
  }
512
- return e === "line" ? /* @__PURE__ */ p(S, {
611
+ return e === "line" ? /* @__PURE__ */ b(j, {
513
612
  type: "monotone",
514
613
  dataKey: t.dataKey,
515
614
  stroke: o,
516
615
  strokeWidth: 2,
517
616
  dot: !1
518
- }, t.dataKey) : e === "area" ? /* @__PURE__ */ p(h, {
617
+ }, t.dataKey) : e === "area" ? /* @__PURE__ */ b(S, {
519
618
  type: "monotone",
520
619
  dataKey: t.dataKey,
521
620
  fill: o,
@@ -527,8 +626,8 @@ function pe({ chartType: e = "bar", data: t = [], config: r = {}, xAxisKey: i =
527
626
  })
528
627
  });
529
628
  }
530
- var J, me, Y, he = F((() => {
531
- de(), J = "hsl(var(--primary))", me = {
629
+ var Y, ke, X, Ae = V((() => {
630
+ Ee(), Y = "hsl(var(--primary))", ke = {
532
631
  slate: "#64748b",
533
632
  gray: "#6b7280",
534
633
  zinc: "#71717a",
@@ -551,10 +650,10 @@ var J, me, Y, he = F((() => {
551
650
  fuchsia: "#d946ef",
552
651
  pink: "#ec4899",
553
652
  rose: "#f43f5e"
554
- }, Y = (e) => me[e] || e;
555
- })), ge = r.lazy(() => Promise.resolve().then(() => (ue(), ce))), _e = r.lazy(() => Promise.resolve().then(() => (he(), fe))), X = ({ schema: e }) => /* @__PURE__ */ p(i, {
556
- fallback: /* @__PURE__ */ p(d, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
557
- children: /* @__PURE__ */ p(ge, {
653
+ }, X = (e) => ke[e] || e;
654
+ })), je = s.lazy(() => Promise.resolve().then(() => (xe(), ye))), Me = s.lazy(() => Promise.resolve().then(() => (Ae(), De))), Ne = ({ schema: e }) => /* @__PURE__ */ b(c, {
655
+ fallback: /* @__PURE__ */ b(y, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
656
+ children: /* @__PURE__ */ b(je, {
558
657
  data: e.data,
559
658
  dataKey: e.dataKey,
560
659
  xAxisKey: e.xAxisKey,
@@ -562,8 +661,8 @@ var J, me, Y, he = F((() => {
562
661
  className: e.className,
563
662
  color: e.color
564
663
  })
565
- }), Z = ({ schema: e }) => {
566
- let t = r.useMemo(() => {
664
+ }), Z = ({ schema: e, onChartClick: t }) => {
665
+ let n = s.useMemo(() => {
567
666
  let t = e.series, n = e.xAxisKey, r = e.config;
568
667
  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) {
569
668
  let n = e.colors || [
@@ -587,15 +686,16 @@ var J, me, Y, he = F((() => {
587
686
  className: e.className
588
687
  };
589
688
  }, [e]);
590
- return /* @__PURE__ */ p(i, {
591
- fallback: /* @__PURE__ */ p(d, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
592
- children: /* @__PURE__ */ p(_e, {
593
- chartType: t.chartType,
594
- data: t.data,
595
- config: t.config,
596
- xAxisKey: t.xAxisKey,
597
- series: t.series,
598
- className: t.className
689
+ return /* @__PURE__ */ b(c, {
690
+ fallback: /* @__PURE__ */ b(y, { className: "w-full h-48 sm:h-64 md:h-80 lg:h-[400px]" }),
691
+ children: /* @__PURE__ */ b(Me, {
692
+ chartType: n.chartType,
693
+ data: n.data,
694
+ config: n.config,
695
+ xAxisKey: n.xAxisKey,
696
+ series: n.series,
697
+ className: n.className,
698
+ onChartClick: t
599
699
  })
600
700
  });
601
701
  };
@@ -604,7 +704,7 @@ var J, me, Y, he = F((() => {
604
704
  function Q(e) {
605
705
  return e.replace(/[_-]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
606
706
  }
607
- function ve(e, t) {
707
+ function Pe(e, t) {
608
708
  let { field: n, function: r, groupBy: i } = t, a = {};
609
709
  for (let t of e) {
610
710
  let e = String(t[i] ?? "Unknown");
@@ -635,154 +735,243 @@ function ve(e, t) {
635
735
  };
636
736
  });
637
737
  }
638
- async function ye(e, n, r, i, a) {
639
- if (!e.length || !n) return e;
640
- let o = a || ((e, t) => t), s = r?.fields?.[n];
641
- if (!s) return e.map((e) => {
642
- let t = String(e[n] ?? ""), r = Q(t);
643
- return {
644
- ...e,
645
- [n]: o(t, r)
646
- };
647
- });
648
- let c = s.type;
649
- if (c === "select" || c === "picklist" || c === "dropdown") {
650
- let t = s.options || [];
651
- if (t.length === 0) return e.map((e) => {
652
- let t = String(e[n] ?? ""), r = Q(t);
738
+ async function Fe(e, t, r, i, a) {
739
+ if (!e.length || !t) return e;
740
+ let o = a || ((e, t) => t), s = `__raw_${t}`, c = r?.fields?.[t];
741
+ if (!c) {
742
+ let n = /^\d{4}-\d{2}-\d{2}/;
743
+ return e.map((e) => {
744
+ let r = e[t], i = String(r ?? ""), a = n.test(i) ? i : Q(i);
653
745
  return {
654
746
  ...e,
655
- [n]: o(t, r)
747
+ [t]: o(i, a),
748
+ [s]: r
749
+ };
750
+ });
751
+ }
752
+ let l = c.type;
753
+ if (l === "select" || l === "picklist" || l === "dropdown") {
754
+ let n = c.options || [];
755
+ if (n.length === 0) return e.map((e) => {
756
+ let n = e[t], r = String(n ?? ""), i = Q(r);
757
+ return {
758
+ ...e,
759
+ [t]: o(r, i),
760
+ [s]: n
656
761
  };
657
762
  });
658
763
  let r = {};
659
- for (let e of t) typeof e == "string" ? r[e] = e : e && typeof e == "object" && (r[String(e.value)] = e.label || String(e.value));
764
+ for (let e of n) typeof e == "string" ? r[e] = e : e && typeof e == "object" && (r[String(e.value)] = e.label || String(e.value));
660
765
  return e.map((e) => {
661
- let t = String(e[n] ?? ""), i = r[t] || Q(t);
766
+ let n = e[t], i = String(n ?? ""), a = r[i] || Q(i);
662
767
  return {
663
768
  ...e,
664
- [n]: o(t, i)
769
+ [t]: o(i, a),
770
+ [s]: n
665
771
  };
666
772
  });
667
773
  }
668
- if (c === "lookup" || c === "master_detail") {
669
- let r = s.reference_to || s.reference;
670
- if (!r || !i || typeof i.find != "function") return e;
671
- let a = [...new Set(e.map((e) => e[n]).filter((e) => e != null))];
672
- if (a.length === 0) return e;
673
- let o = s.id_field || "id";
774
+ if (l === "lookup" || l === "master_detail") {
775
+ let r = c.reference_to || c.reference;
776
+ if (!r || !i || typeof i.find != "function") return e.map((e) => ({
777
+ ...e,
778
+ [s]: e[t]
779
+ }));
780
+ let a = [...new Set(e.map((e) => e[t]).filter((e) => e != null))];
781
+ if (a.length === 0) return e.map((e) => ({
782
+ ...e,
783
+ [s]: e[t]
784
+ }));
785
+ let o = c.id_field || "id";
674
786
  try {
675
- let c = t(await i.find(r, {
787
+ let l = n(await i.find(r, {
676
788
  $filter: { [o]: { $in: a } },
677
789
  $top: a.length
678
- })), l = s.reference_field || s.display_field || "name", u = {};
679
- for (let e of c) {
680
- let t = String(e[o] ?? e.id ?? e._id ?? ""), n = e[l] || e.name || e.label || e.title || t;
681
- t && (u[t] = String(n));
790
+ })), u = c.reference_field || c.display_field || "name", d = {};
791
+ for (let e of l) {
792
+ let t = String(e[o] ?? e.id ?? e._id ?? ""), n = e[u] || e.name || e.label || e.title || t;
793
+ t && (d[t] = String(n));
682
794
  }
683
795
  return e.map((e) => {
684
- let t = String(e[n] ?? "");
796
+ let n = e[t], r = String(n ?? "");
685
797
  return {
686
798
  ...e,
687
- [n]: u[t] || t
799
+ [t]: d[r] || r,
800
+ [s]: n
688
801
  };
689
802
  });
690
- } catch (t) {
691
- return console.warn("[ObjectChart] Failed to resolve lookup labels:", t), e;
803
+ } catch (n) {
804
+ return console.warn("[ObjectChart] Failed to resolve lookup labels:", n), e.map((e) => ({
805
+ ...e,
806
+ [s]: e[t]
807
+ }));
692
808
  }
693
809
  }
694
- return e.map((e) => ({
810
+ if (l === "date" || l === "datetime" || l === "date_time" || l === "timestamp" || l === "time") return e.map((e) => ({
695
811
  ...e,
696
- [n]: Q(String(e[n] ?? ""))
812
+ [s]: e[t]
697
813
  }));
814
+ let u = /^\d{4}-\d{2}-\d{2}/;
815
+ return e.map((e) => {
816
+ let n = e[t], r = String(n ?? "");
817
+ return {
818
+ ...e,
819
+ [t]: u.test(r) ? r : Q(r),
820
+ [s]: n
821
+ };
822
+ });
698
823
  }
699
824
  var $ = (e) => {
700
- let { schema: n } = e, r = o(ie), i = e.dataSource || r?.dataSource, d = ae(n.bind), { fieldOptionLabel: f } = se(), h = l(f);
701
- s(() => {
702
- h.current = f;
703
- }, [f]);
704
- let [g, _] = u([]), [v, y] = u(!1), [b, x] = u(null), S = c(() => n.aggregate ? JSON.stringify(n.aggregate) : "", [n.aggregate]), C = c(() => n.filter ? JSON.stringify(n.filter) : "", [n.filter]), w = a(async (e, r) => {
705
- if (!(!e || !n.objectName)) {
706
- r.current && (y(!0), x(null));
825
+ let { schema: o } = e, s = u(pe), c = e.dataSource || s?.dataSource, y = me(o.bind), { fieldOptionLabel: S } = ge(), C = p(S);
826
+ d(() => {
827
+ C.current = S;
828
+ }, [S]);
829
+ let [w, T] = m([]), [E, D] = m(!1), [ae, O] = m(null), [k, A] = m(null), j = f(() => o.aggregate ? JSON.stringify(o.aggregate) : "", [o.aggregate]), M = f(() => o.filter ? JSON.stringify(o.filter) : "", [o.filter]), N = l(async (e, t) => {
830
+ if (!(!e || !o.objectName)) {
831
+ t.current && (D(!0), O(null));
707
832
  try {
708
- let i;
709
- if (n.aggregate && typeof e.aggregate == "function") {
710
- let t = await e.aggregate(n.objectName, {
711
- field: n.aggregate.field,
712
- function: n.aggregate.function,
713
- groupBy: n.aggregate.groupBy,
714
- filter: n.filter
833
+ let r, a = i(o.filter);
834
+ if (o.aggregate && typeof e.aggregate == "function") {
835
+ let t = await e.aggregate(o.objectName, {
836
+ field: o.aggregate.field,
837
+ function: o.aggregate.function,
838
+ groupBy: o.aggregate.groupBy,
839
+ filter: a
715
840
  });
716
- i = Array.isArray(t) ? t : [];
717
- } else if (typeof e.find == "function") i = t(await e.find(n.objectName, { $filter: n.filter })), n.aggregate && i.length > 0 && (i = ve(i, n.aggregate));
841
+ r = Array.isArray(t) ? t : [];
842
+ } else if (typeof e.find == "function") r = n(await e.find(o.objectName, { $filter: a })), o.aggregate && r.length > 0 && (r = Pe(r, o.aggregate));
718
843
  else return;
719
- let a = n.aggregate?.groupBy || n.xAxisKey;
720
- if (a && typeof e.getObjectSchema == "function") try {
721
- let t = await e.getObjectSchema(n.objectName);
722
- i = await ye(i, a, t, e, (e, t) => h.current(n.objectName, a, e, t));
844
+ let s = o.aggregate?.groupBy || o.xAxisKey;
845
+ if (s && typeof e.getObjectSchema == "function") try {
846
+ let t = await e.getObjectSchema(o.objectName);
847
+ r = await Fe(r, s, t, e, (e, t) => C.current(o.objectName, s, e, t));
723
848
  } catch {}
724
- r.current && _(i);
849
+ t.current && T(r);
725
850
  } catch (e) {
726
- console.error("[ObjectChart] Fetch error:", e), r.current && x(e instanceof Error ? e.message : "Failed to load chart data");
851
+ console.error("[ObjectChart] Fetch error:", e), t.current && O(e instanceof Error ? e.message : "Failed to load chart data");
727
852
  } finally {
728
- r.current && y(!1);
853
+ t.current && D(!1);
729
854
  }
730
855
  }
731
856
  }, [
732
- n.objectName,
733
- S,
734
- C,
735
- n.xAxisKey
857
+ o.objectName,
858
+ j,
859
+ M,
860
+ o.xAxisKey
736
861
  ]);
737
- s(() => {
862
+ d(() => {
738
863
  let e = { current: !0 };
739
- return n.objectName && !d && !n.data && w(i, e), () => {
864
+ return o.objectName && !y && !o.data && N(c, e), () => {
740
865
  e.current = !1;
741
866
  };
742
867
  }, [
743
- n.objectName,
744
- i,
745
- d,
746
- n.data,
747
- C,
748
- S,
749
- w
868
+ o.objectName,
869
+ c,
870
+ y,
871
+ o.data,
872
+ M,
873
+ j,
874
+ N
750
875
  ]);
751
- let T = d || n.data || g, E = Array.isArray(T) ? T : [], D = {
752
- ...n,
753
- data: E
876
+ let P = y || o.data || w, F = Array.isArray(P) ? P : [], I = o.drillDown, L = o.aggregate?.groupBy || o.xAxisKey, R = f(() => {
877
+ if (!L) return /* @__PURE__ */ new Map();
878
+ let e = /* @__PURE__ */ new Map(), t = `__raw_${L}`;
879
+ for (let n of F) {
880
+ let r = n?.[L];
881
+ if (r == null) continue;
882
+ let i = t in (n || {}) ? n[t] : r;
883
+ e.set(String(r), i);
884
+ }
885
+ return e;
886
+ }, [F, L]), oe = {
887
+ ...o,
888
+ data: F
754
889
  };
755
- return v && E.length === 0 ? /* @__PURE__ */ p("div", {
756
- className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (n.className || ""),
890
+ if (E && F.length === 0) return /* @__PURE__ */ b("div", {
891
+ className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (o.className || ""),
757
892
  "data-testid": "chart-loading",
758
893
  children: "Loading chart data…"
759
- }) : b ? /* @__PURE__ */ m("div", {
760
- className: "flex flex-col items-center justify-center gap-2 p-4 " + (n.className || ""),
894
+ });
895
+ if (ae) return /* @__PURE__ */ x("div", {
896
+ className: "flex flex-col items-center justify-center gap-2 p-4 " + (o.className || ""),
761
897
  "data-testid": "chart-error",
762
898
  role: "alert",
763
899
  children: [
764
- /* @__PURE__ */ p(oe, { className: "h-6 w-6 text-destructive opacity-60" }),
765
- /* @__PURE__ */ p("p", {
900
+ /* @__PURE__ */ b(he, { className: "h-6 w-6 text-destructive opacity-60" }),
901
+ /* @__PURE__ */ b("p", {
766
902
  className: "text-xs text-destructive font-medium",
767
903
  children: "Failed to load chart data"
768
904
  }),
769
- /* @__PURE__ */ p("p", {
905
+ /* @__PURE__ */ b("p", {
770
906
  className: "text-xs text-muted-foreground max-w-xs text-center",
771
- children: b
907
+ children: ae
772
908
  })
773
909
  ]
774
- }) : !i && n.objectName && E.length === 0 ? /* @__PURE__ */ m("div", {
775
- className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (n.className || ""),
910
+ });
911
+ if (!c && o.objectName && F.length === 0) return /* @__PURE__ */ x("div", {
912
+ className: "flex items-center justify-center text-muted-foreground text-sm p-4 " + (o.className || ""),
776
913
  "data-testid": "chart-no-datasource",
777
914
  children: [
778
915
  "No data source available for “",
779
- n.objectName,
916
+ o.objectName,
780
917
  "”"
781
918
  ]
782
- }) : /* @__PURE__ */ p(Z, {
783
- ...e,
784
- schema: D
785
919
  });
920
+ let se = r(I) ? (e) => {
921
+ let t = e.category, n = t != null && R.has(String(t)) ? R.get(String(t)) : t;
922
+ A({
923
+ ...e,
924
+ category: n,
925
+ categoryLabel: t,
926
+ scope: "cell"
927
+ });
928
+ } : void 0, ce = k && o.objectName ? (() => {
929
+ let e = t(I, k, { groupByField: L }), n = {
930
+ ...o.filter || {},
931
+ ...e
932
+ }, r = a(I, k, o.title || "Details"), i = I?.target ?? "drawer", s = /* @__PURE__ */ b("div", {
933
+ className: "overflow-auto",
934
+ "data-testid": "chart-drill-body",
935
+ children: /* @__PURE__ */ b(fe, {
936
+ schema: {
937
+ type: "object-data-table",
938
+ objectName: o.objectName,
939
+ filter: n,
940
+ pagination: !0,
941
+ pageSize: I?.maxRows,
942
+ columns: I?.columns?.map((e) => ({
943
+ accessorKey: e,
944
+ header: e
945
+ }))
946
+ },
947
+ dataSource: c
948
+ })
949
+ });
950
+ return i === "dialog" ? /* @__PURE__ */ b(h, {
951
+ open: !0,
952
+ onOpenChange: (e) => !e && A(null),
953
+ children: /* @__PURE__ */ x(g, {
954
+ className: "max-w-4xl",
955
+ children: [/* @__PURE__ */ b(_, { children: /* @__PURE__ */ b(v, { children: r }) }), s]
956
+ })
957
+ }) : /* @__PURE__ */ b(ee, {
958
+ open: !0,
959
+ onOpenChange: (e) => !e && A(null),
960
+ children: /* @__PURE__ */ x(te, {
961
+ side: "right",
962
+ className: "w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col",
963
+ children: [/* @__PURE__ */ b(ne, { children: /* @__PURE__ */ b(re, { children: r }) }), /* @__PURE__ */ b("div", {
964
+ className: "flex-1 overflow-hidden mt-2",
965
+ children: s
966
+ })]
967
+ })
968
+ });
969
+ })() : null;
970
+ return /* @__PURE__ */ x(ie, { children: [/* @__PURE__ */ b(Z, {
971
+ ...e,
972
+ schema: oe,
973
+ onChartClick: se
974
+ }), ce] });
786
975
  };
787
976
  e.register("object-chart", $, {
788
977
  namespace: "plugin-charts",
@@ -816,11 +1005,11 @@ e.register("object-chart", $, {
816
1005
  });
817
1006
  //#endregion
818
1007
  //#region src/index.tsx
819
- var be = {
820
- "bar-chart": X,
1008
+ var Ie = {
1009
+ "bar-chart": Ne,
821
1010
  chart: Z
822
1011
  };
823
- e.register("bar-chart", X, {
1012
+ e.register("bar-chart", Ne, {
824
1013
  namespace: "plugin-charts",
825
1014
  label: "Bar Chart",
826
1015
  category: "plugin",
@@ -1050,4 +1239,4 @@ e.register("bar-chart", X, {
1050
1239
  defaultProps: { chartType: "scatter" }
1051
1240
  });
1052
1241
  //#endregion
1053
- export { X as ChartBarRenderer, Z as ChartRenderer, $ as ObjectChart, be as chartComponents };
1242
+ export { Ne as ChartBarRenderer, Z as ChartRenderer, $ as ObjectChart, Ie as chartComponents };