@gravitee/graphene-charts 0.0.1-graphene-92.ffb4eff

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/USAGE_GUIDE.md +151 -0
  2. package/dist/components/BarChart/BarChart.d.ts +60 -0
  3. package/dist/components/BarChart/BarChart.d.ts.map +1 -0
  4. package/dist/components/BarChart/index.d.ts +3 -0
  5. package/dist/components/BarChart/index.d.ts.map +1 -0
  6. package/dist/components/ChartContainer/ChartContainer.d.ts +21 -0
  7. package/dist/components/ChartContainer/ChartContainer.d.ts.map +1 -0
  8. package/dist/components/ChartContainer/index.d.ts +3 -0
  9. package/dist/components/ChartContainer/index.d.ts.map +1 -0
  10. package/dist/components/ChartLegend/ChartLegend.d.ts +28 -0
  11. package/dist/components/ChartLegend/ChartLegend.d.ts.map +1 -0
  12. package/dist/components/ChartLegend/index.d.ts +3 -0
  13. package/dist/components/ChartLegend/index.d.ts.map +1 -0
  14. package/dist/components/ChartTooltip/ChartTooltip.d.ts +43 -0
  15. package/dist/components/ChartTooltip/ChartTooltip.d.ts.map +1 -0
  16. package/dist/components/ChartTooltip/index.d.ts +3 -0
  17. package/dist/components/ChartTooltip/index.d.ts.map +1 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +543 -0
  21. package/dist/lib/utils.d.ts +2 -0
  22. package/dist/lib/utils.d.ts.map +1 -0
  23. package/dist/primitives/Axis.d.ts +26 -0
  24. package/dist/primitives/Axis.d.ts.map +1 -0
  25. package/dist/primitives/ChartSlots.d.ts +49 -0
  26. package/dist/primitives/ChartSlots.d.ts.map +1 -0
  27. package/dist/primitives/Grid.d.ts +22 -0
  28. package/dist/primitives/Grid.d.ts.map +1 -0
  29. package/dist/primitives/index.d.ts +19 -0
  30. package/dist/primitives/index.d.ts.map +1 -0
  31. package/dist/primitives/roundedRect.d.ts +18 -0
  32. package/dist/primitives/roundedRect.d.ts.map +1 -0
  33. package/dist/primitives/useChartDimensions.d.ts +18 -0
  34. package/dist/primitives/useChartDimensions.d.ts.map +1 -0
  35. package/dist/primitives/useResolvedCssLength.d.ts +14 -0
  36. package/dist/primitives/useResolvedCssLength.d.ts.map +1 -0
  37. package/dist/primitives/useTooltipState.d.ts +37 -0
  38. package/dist/primitives/useTooltipState.d.ts.map +1 -0
  39. package/dist/styles/globals.css +2 -0
  40. package/dist/types/index.d.ts +31 -0
  41. package/dist/types/index.d.ts.map +1 -0
  42. package/package.json +73 -0
package/dist/index.js ADDED
@@ -0,0 +1,543 @@
1
+ import { Empty as e, EmptyDescription as t, EmptyHeader as n, EmptyTitle as r, cn as i } from "@gravitee/graphene-core";
2
+ import * as a from "react";
3
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
4
+ import { max as l } from "d3-array";
5
+ import { scaleBand as u, scaleLinear as d } from "d3-scale";
6
+ //#region src/types/index.ts
7
+ var f = {
8
+ light: "",
9
+ dark: ".dark"
10
+ }, p = {
11
+ top: 20,
12
+ right: 20,
13
+ bottom: 30,
14
+ left: 40
15
+ }, m = a.createContext(null);
16
+ function h() {
17
+ let e = a.useContext(m);
18
+ if (!e) throw Error("useChartConfig must be used within a <ChartContainer>");
19
+ return e;
20
+ }
21
+ function g(e, t) {
22
+ return t && (t.height !== void 0 || t.minHeight !== void 0 || t.maxHeight !== void 0) ? !0 : e ? /(?:^|\s)!?(?:min-|max-)?h-[^\s]+/.test(e) : !1;
23
+ }
24
+ function _({ id: e, config: t, className: n, children: r, style: o, ...l }) {
25
+ let u = a.useId(), d = `chart-${e ?? u.replace(/:/g, "")}`, f = a.useMemo(() => Object.entries(t).filter(([, e]) => e.color || e.theme), [t]), p = g(n, o);
26
+ return /* @__PURE__ */ s(m.Provider, {
27
+ value: {
28
+ config: t,
29
+ id: d
30
+ },
31
+ children: /* @__PURE__ */ c("div", {
32
+ "data-chart": d,
33
+ "data-slot": "chart",
34
+ className: i("flex w-full justify-center text-xs", !p && "aspect-video", n),
35
+ style: o,
36
+ ...l,
37
+ children: [f.length > 0 && /* @__PURE__ */ s(v, {
38
+ id: d,
39
+ config: t
40
+ }), r]
41
+ })
42
+ });
43
+ }
44
+ function v({ id: e, config: t }) {
45
+ return /* @__PURE__ */ s("style", { dangerouslySetInnerHTML: { __html: Object.entries(f).map(([n, r]) => `${r} [data-chart=${e}] {\n${Object.entries(t).map(([e, t]) => {
46
+ let r = t.theme?.[n] ?? t.color;
47
+ return r ? ` --color-${e}: ${r};` : null;
48
+ }).filter(Boolean).join("\n")}\n}`).join("\n") } });
49
+ }
50
+ //#endregion
51
+ //#region src/primitives/useChartDimensions.ts
52
+ function y(e) {
53
+ let [t, n] = a.useState({
54
+ width: 0,
55
+ height: 0
56
+ });
57
+ return a.useEffect(() => {
58
+ let t = e.current;
59
+ if (!t) return;
60
+ let r = new ResizeObserver(([e]) => {
61
+ let { width: t, height: r } = e.contentRect;
62
+ n({
63
+ width: t,
64
+ height: r
65
+ });
66
+ });
67
+ return r.observe(t), () => r.disconnect();
68
+ }, [e]), t;
69
+ }
70
+ //#endregion
71
+ //#region src/primitives/useTooltipState.ts
72
+ var b = 12, ee = -12, x = 180, S = 120;
73
+ function C(e, t, n, r) {
74
+ return {
75
+ x: Math.max(0, Math.min(e + b, n - x)),
76
+ y: Math.max(0, Math.min(t + ee, r - S))
77
+ };
78
+ }
79
+ function te() {
80
+ let [e, t] = a.useState(null);
81
+ return {
82
+ state: e,
83
+ show: a.useCallback((e, n, r, i) => {
84
+ let a = C(r.clientX - i.left, r.clientY - i.top, i.width, i.height);
85
+ t({
86
+ items: e,
87
+ label: n,
88
+ x: a.x,
89
+ y: a.y
90
+ });
91
+ }, []),
92
+ move: a.useCallback((e, n) => {
93
+ t((t) => {
94
+ if (!t) return t;
95
+ let r = C(e.clientX - n.left, e.clientY - n.top, n.width, n.height);
96
+ return {
97
+ ...t,
98
+ x: r.x,
99
+ y: r.y
100
+ };
101
+ });
102
+ }, []),
103
+ hide: a.useCallback(() => t(null), [])
104
+ };
105
+ }
106
+ //#endregion
107
+ //#region src/primitives/Grid.tsx
108
+ function ne({ scale: e, length: t, orientation: n, tickCount: r = 5 }) {
109
+ let i = e.ticks(r), a = n === "horizontal";
110
+ return /* @__PURE__ */ s("g", {
111
+ "aria-hidden": "true",
112
+ children: i.map((n) => a ? /* @__PURE__ */ s("line", {
113
+ x1: 0,
114
+ x2: t,
115
+ y1: e(n),
116
+ y2: e(n),
117
+ className: "stroke-border",
118
+ strokeDasharray: "4 4",
119
+ strokeOpacity: .5
120
+ }, n) : /* @__PURE__ */ s("line", {
121
+ x1: e(n),
122
+ x2: e(n),
123
+ y1: 0,
124
+ y2: t,
125
+ className: "stroke-border",
126
+ strokeDasharray: "4 4",
127
+ strokeOpacity: .5
128
+ }, n))
129
+ });
130
+ }
131
+ //#endregion
132
+ //#region src/primitives/Axis.tsx
133
+ function re({ scale: e, orientation: t, length: n }) {
134
+ let r = e.domain();
135
+ return t === "bottom" ? /* @__PURE__ */ s("g", {
136
+ transform: `translate(0,${n})`,
137
+ "aria-hidden": "true",
138
+ children: r.map((t) => /* @__PURE__ */ s("text", {
139
+ x: (e(t) ?? 0) + e.bandwidth() / 2,
140
+ y: 20,
141
+ textAnchor: "middle",
142
+ className: "fill-muted-foreground text-xs",
143
+ children: t
144
+ }, t))
145
+ }) : /* @__PURE__ */ s("g", {
146
+ "aria-hidden": "true",
147
+ children: r.map((t) => /* @__PURE__ */ s("text", {
148
+ x: -8,
149
+ y: (e(t) ?? 0) + e.bandwidth() / 2,
150
+ textAnchor: "end",
151
+ dominantBaseline: "middle",
152
+ className: "fill-muted-foreground text-xs",
153
+ children: t
154
+ }, t))
155
+ });
156
+ }
157
+ function ie({ scale: e, orientation: t, length: n, tickCount: r = 5, tickFormatter: i = String }) {
158
+ let a = e.ticks(r);
159
+ return t === "left" ? /* @__PURE__ */ s("g", {
160
+ "aria-hidden": "true",
161
+ children: a.map((t) => /* @__PURE__ */ s("text", {
162
+ x: -8,
163
+ y: e(t),
164
+ textAnchor: "end",
165
+ dominantBaseline: "middle",
166
+ className: "fill-muted-foreground text-xs",
167
+ children: i(t)
168
+ }, t))
169
+ }) : /* @__PURE__ */ s("g", {
170
+ "aria-hidden": "true",
171
+ children: a.map((t) => /* @__PURE__ */ s("text", {
172
+ x: e(t),
173
+ y: n + 20,
174
+ textAnchor: "middle",
175
+ className: "fill-muted-foreground text-xs",
176
+ children: i(t)
177
+ }, t))
178
+ });
179
+ }
180
+ //#endregion
181
+ //#region src/primitives/roundedRect.ts
182
+ function w(e, t, n, r, i) {
183
+ let a = Math.min(i.tl, n / 2, r / 2), o = Math.min(i.tr, n / 2, r / 2), s = Math.min(i.br, n / 2, r / 2), c = Math.min(i.bl, n / 2, r / 2);
184
+ return [
185
+ `M${e + a},${t}`,
186
+ `H${e + n - o}`,
187
+ o ? `A${o},${o},0,0,1,${e + n},${t + o}` : `L${e + n},${t}`,
188
+ `V${t + r - s}`,
189
+ s ? `A${s},${s},0,0,1,${e + n - s},${t + r}` : `L${e + n},${t + r}`,
190
+ `H${e + c}`,
191
+ c ? `A${c},${c},0,0,1,${e},${t + r - c}` : `L${e},${t + r}`,
192
+ `V${t + a}`,
193
+ a ? `A${a},${a},0,0,1,${e + a},${t}` : `L${e},${t}`,
194
+ "Z"
195
+ ].join("");
196
+ }
197
+ //#endregion
198
+ //#region src/primitives/ChartSlots.tsx
199
+ var T = a.createContext(null);
200
+ function E() {
201
+ return a.useContext(T) || {
202
+ tooltip: null,
203
+ legend: null,
204
+ setTooltip: () => void 0,
205
+ setLegend: () => void 0
206
+ };
207
+ }
208
+ function D({ children: e }) {
209
+ let [t, n] = a.useState(null), [r, i] = a.useState(null), o = a.useMemo(() => ({
210
+ tooltip: t,
211
+ legend: r,
212
+ setTooltip: n,
213
+ setLegend: i
214
+ }), [t, r]);
215
+ return /* @__PURE__ */ s(T.Provider, {
216
+ value: o,
217
+ children: e
218
+ });
219
+ }
220
+ //#endregion
221
+ //#region src/primitives/useResolvedCssLength.tsx
222
+ function ae(e, t) {
223
+ let n = a.useRef(null), [r, i] = a.useState(t);
224
+ return a.useLayoutEffect(() => {
225
+ let e = n.current;
226
+ if (!e) return;
227
+ let t = getComputedStyle(e).borderTopLeftRadius, r = Number.parseFloat(t);
228
+ Number.isNaN(r) || i(r);
229
+ }, [e]), [r, /* @__PURE__ */ s("span", {
230
+ ref: n,
231
+ "aria-hidden": "true",
232
+ className: "pointer-events-none absolute h-0 w-0 opacity-0",
233
+ style: { borderTopLeftRadius: e }
234
+ })];
235
+ }
236
+ //#endregion
237
+ //#region src/components/ChartTooltip/ChartTooltip.tsx
238
+ function O(e) {
239
+ return typeof e == "number" ? e.toLocaleString() : e;
240
+ }
241
+ function k(e, t, n) {
242
+ return t && e[t] ? e[t] : e[n];
243
+ }
244
+ function A({ label: e, items: t = [], active: n = !0, hideLabel: r = !1, hideIndicator: a = !1, indicator: o = "dot", labelKey: l, nameKey: u, labelFormatter: d, labelClassName: f, valueFormatter: p = O, className: m, ...g }) {
245
+ let { config: _ } = h();
246
+ if (!n || t.length === 0) return null;
247
+ let v = t.length === 1 && o !== "dot", y = l ? k(_, l, l)?.label ?? e : typeof e == "string" ? _[e]?.label ?? e : e, b = r ? null : /* @__PURE__ */ s("div", {
248
+ className: i("font-medium", f),
249
+ children: d ? d(e ?? "", t) : y
250
+ });
251
+ return /* @__PURE__ */ c("div", {
252
+ "data-slot": "chart-tooltip-content",
253
+ className: i("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", m),
254
+ ...g,
255
+ children: [v ? null : b, /* @__PURE__ */ s("div", {
256
+ className: "grid gap-1.5",
257
+ children: t.map((e, t) => {
258
+ let n = k(_, `${u ?? e.dataKey ?? e.name ?? "value"}`, e.name), r = e.color ?? `var(--color-${e.dataKey ?? e.name})`;
259
+ return /* @__PURE__ */ c("div", {
260
+ className: i("flex w-full flex-wrap items-stretch gap-2 [&>svg]:text-muted-foreground [&>svg]:h-2.5 [&>svg]:w-2.5", o === "dot" && "items-center"),
261
+ children: [n?.icon ? /* @__PURE__ */ s(n.icon, {}) : !a && /* @__PURE__ */ s("div", {
262
+ className: i("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", {
263
+ "h-2.5 w-2.5": o === "dot",
264
+ "w-1": o === "line",
265
+ "w-0 border-[1.5px] border-dashed bg-transparent": o === "dashed",
266
+ "my-0.5": v && o === "dashed"
267
+ }),
268
+ style: {
269
+ "--color-bg": r,
270
+ "--color-border": r
271
+ }
272
+ }), /* @__PURE__ */ c("div", {
273
+ className: i("flex flex-1 justify-between leading-none", v ? "items-end" : "items-center"),
274
+ children: [/* @__PURE__ */ c("div", {
275
+ className: "grid gap-1.5",
276
+ children: [v ? b : null, /* @__PURE__ */ s("span", {
277
+ className: "text-muted-foreground",
278
+ children: n?.label ?? e.name
279
+ })]
280
+ }), e.value !== void 0 && /* @__PURE__ */ s("span", {
281
+ className: "text-foreground font-mono font-medium tabular-nums",
282
+ children: p(e.value, e, t)
283
+ })]
284
+ })]
285
+ }, `${e.name}-${t}`);
286
+ })
287
+ })]
288
+ });
289
+ }
290
+ function j({ content: e }) {
291
+ let { setTooltip: t } = E();
292
+ return a.useLayoutEffect(() => (t({ content: e }), () => t(null)), [e, t]), null;
293
+ }
294
+ //#endregion
295
+ //#region src/components/ChartLegend/ChartLegend.tsx
296
+ function M({ items: e = [], hideIcon: t = !1, nameKey: n, verticalAlign: r = "bottom", className: a, ...o }) {
297
+ let { config: l } = h();
298
+ return e.length === 0 ? null : /* @__PURE__ */ s("div", {
299
+ "data-slot": "chart-legend-content",
300
+ className: i("flex items-center justify-center gap-4", r === "top" ? "pb-3" : "pt-3", a),
301
+ ...o,
302
+ children: e.map((e) => {
303
+ let r = l[`${n ?? e.dataKey ?? e.value}`], i = e.color ?? `var(--color-${e.dataKey ?? e.value})`;
304
+ return /* @__PURE__ */ c("div", {
305
+ className: "flex items-center gap-1.5 text-xs [&>svg]:text-muted-foreground [&>svg]:h-3 [&>svg]:w-3",
306
+ children: [r?.icon && !t ? /* @__PURE__ */ s(r.icon, {}) : !t && /* @__PURE__ */ s("div", {
307
+ className: "h-2 w-2 shrink-0 rounded-[2px]",
308
+ style: { backgroundColor: i }
309
+ }), /* @__PURE__ */ s("span", {
310
+ className: "text-muted-foreground",
311
+ children: r?.label ?? e.value
312
+ })]
313
+ }, e.value);
314
+ })
315
+ });
316
+ }
317
+ function N({ content: e, verticalAlign: t = "bottom" }) {
318
+ let { setLegend: n } = E();
319
+ return a.useLayoutEffect(() => (n({
320
+ content: e,
321
+ verticalAlign: t
322
+ }), () => n(null)), [
323
+ e,
324
+ t,
325
+ n
326
+ ]), null;
327
+ }
328
+ //#endregion
329
+ //#region src/components/BarChart/BarChart.tsx
330
+ function oe(e, t) {
331
+ if (e.length === 0) return [];
332
+ let n = Object.keys(e[0]).filter((t) => t !== "category" && typeof e[0][t] == "number"), r = t.filter((e) => n.includes(e));
333
+ return r.length > 0 ? r : n;
334
+ }
335
+ var P = "\n[data-graphene-chart-bar][data-animated='true'] {\n transform-box: fill-box;\n transform-origin: center bottom;\n transition:\n transform 450ms cubic-bezier(0.32, 0.72, 0, 1),\n opacity 250ms ease-out;\n}\n[data-graphene-chart-bar][data-animated='true'][data-layout='horizontal'] {\n transform-origin: left center;\n}\n@starting-style {\n [data-graphene-chart-bar][data-animated='true'] {\n opacity: 0;\n transform: scaleY(0);\n }\n [data-graphene-chart-bar][data-animated='true'][data-layout='horizontal'] {\n transform: scaleX(0);\n }\n}\n@media (prefers-reduced-motion: reduce) {\n [data-graphene-chart-bar][data-animated='true'] {\n transition: none;\n }\n @starting-style {\n [data-graphene-chart-bar][data-animated='true'] {\n opacity: 1;\n transform: none;\n }\n }\n}\n[data-graphene-chart-bar]:focus-visible {\n outline: 2px solid var(--ring);\n outline-offset: 2px;\n}\n";
336
+ function F(e) {
337
+ return /* @__PURE__ */ s(D, { children: /* @__PURE__ */ s(I, { ...e }) });
338
+ }
339
+ function I({ data: f, dataKeys: m, layout: g = "vertical", variant: _ = "grouped", margin: v, barRadius: b, barGap: ee = .1, showGrid: x = !0, showCategoryAxis: S = !0, showValueAxis: C = !0, valueTickFormatter: T = String, ariaLabel: D, animated: O = !0, onBarHover: k, onBarLeave: A, className: j, children: M, ...N }) {
340
+ let { config: F } = h(), { tooltip: I, legend: L } = E(), R = m ?? oe(f, Object.keys(F)), z = {
341
+ ...p,
342
+ ...v
343
+ }, B = g === "vertical", V = a.useRef(null), H = a.useRef(null), U = y(H), W = te(), [se, G] = ae("var(--chart-bar-radius, 4px)", 4), K = b ?? se, q = Math.max(0, U.width - z.left - z.right), J = Math.max(0, U.height - z.top - z.bottom), ce = f.map((e) => e.category), le = a.useMemo(() => _ === "stacked" ? l(f, (e) => R.reduce((t, n) => t + (Number(e[n]) || 0), 0)) ?? 0 : l(f, (e) => l(R, (t) => Number(e[t]) || 0)) ?? 0, [
344
+ f,
345
+ R,
346
+ _
347
+ ]), Y = u().domain(ce).range([0, B ? q : J]).padding(.2), X = d().domain([0, le * 1.1]).nice().range(B ? [J, 0] : [0, q]), Z = u().domain(R).range([0, Y.bandwidth()]).padding(ee), ue = R.map((e) => ({
348
+ dataKey: e,
349
+ value: e
350
+ }));
351
+ function Q(e) {
352
+ return R.map((t) => ({
353
+ dataKey: t,
354
+ name: t,
355
+ value: Number(e[t]) || 0
356
+ }));
357
+ }
358
+ function de(e, t) {
359
+ let n = Q(e);
360
+ if (I) {
361
+ let r = V.current?.getBoundingClientRect();
362
+ r && W.show(n, e.category, t, r);
363
+ }
364
+ k?.(n, e.category, t);
365
+ }
366
+ function fe(e) {
367
+ if (!I) return;
368
+ let t = V.current?.getBoundingClientRect();
369
+ t && W.move(e, t);
370
+ }
371
+ function pe() {
372
+ W.hide(), A?.();
373
+ }
374
+ function me(e, t) {
375
+ if (!I) return;
376
+ let n = V.current?.getBoundingClientRect();
377
+ if (!n) return;
378
+ let r = t.currentTarget.getBoundingClientRect(), i = Q(e), a = {
379
+ clientX: r.left + r.width / 2,
380
+ clientY: r.top + r.height / 2
381
+ };
382
+ W.show(i, e.category, a, n);
383
+ }
384
+ function he() {
385
+ W.hide();
386
+ }
387
+ let ge = L?.verticalAlign ?? "bottom", $ = D ?? `Bar chart with ${f.length} categor${f.length === 1 ? "y" : "ies"} and ${R.length} series`;
388
+ return f.length === 0 ? /* @__PURE__ */ c(o, { children: [
389
+ /* @__PURE__ */ s("style", {
390
+ precedence: "graphene-charts",
391
+ children: P
392
+ }),
393
+ G,
394
+ M,
395
+ /* @__PURE__ */ s("div", {
396
+ role: "img",
397
+ "aria-label": $,
398
+ className: i("flex h-full w-full items-center justify-center", j),
399
+ ...N,
400
+ children: /* @__PURE__ */ s(e, { children: /* @__PURE__ */ c(n, { children: [/* @__PURE__ */ s(r, { children: "No data to display" }), /* @__PURE__ */ s(t, { children: "This chart will render as soon as data becomes available." })] }) })
401
+ })
402
+ ] }) : /* @__PURE__ */ c(o, { children: [
403
+ /* @__PURE__ */ s("style", {
404
+ precedence: "graphene-charts",
405
+ children: P
406
+ }),
407
+ G,
408
+ M,
409
+ /* @__PURE__ */ c("div", {
410
+ className: i("flex h-full w-full flex-col", j),
411
+ ...N,
412
+ children: [
413
+ L && ge === "top" && a.cloneElement(L.content, {
414
+ items: ue,
415
+ verticalAlign: "top"
416
+ }),
417
+ /* @__PURE__ */ c("div", {
418
+ ref: V,
419
+ className: "relative min-h-0 flex-1",
420
+ children: [
421
+ /* @__PURE__ */ s("svg", {
422
+ ref: H,
423
+ role: "img",
424
+ "aria-label": $,
425
+ className: "h-full w-full",
426
+ children: U.width > 0 && U.height > 0 && /* @__PURE__ */ c("g", {
427
+ transform: `translate(${z.left},${z.top})`,
428
+ children: [
429
+ x && /* @__PURE__ */ s(ne, {
430
+ scale: X,
431
+ length: B ? q : J,
432
+ orientation: B ? "horizontal" : "vertical"
433
+ }),
434
+ f.map((e) => {
435
+ let t = 0;
436
+ return /* @__PURE__ */ s("g", {
437
+ transform: B ? `translate(${Y(e.category)},0)` : `translate(0,${Y(e.category)})`,
438
+ onMouseEnter: (t) => de(e, t),
439
+ onMouseMove: fe,
440
+ onMouseLeave: pe,
441
+ children: R.map((n, r) => {
442
+ let i = Number(e[n]) || 0, a = `var(--color-${n})`, o = _ === "stacked", c = r === R.length - 1, l = typeof F[n]?.label == "string" ? F[n]?.label : n, u = `${e.category} — ${l}: ${T(i)}`, d = "";
443
+ if (B && !o) d = w(Z(n) ?? 0, X(i), Z.bandwidth(), J - X(i), {
444
+ tl: K,
445
+ tr: K,
446
+ br: 0,
447
+ bl: 0
448
+ });
449
+ else if (B && o) {
450
+ let e = X(t + i), n = X(t) - e;
451
+ t += i, d = w(0, e, Y.bandwidth(), n, {
452
+ tl: c ? K : 0,
453
+ tr: c ? K : 0,
454
+ br: 0,
455
+ bl: 0
456
+ });
457
+ } else if (!B && !o) d = w(0, Z(n) ?? 0, X(i), Z.bandwidth(), {
458
+ tl: 0,
459
+ tr: K,
460
+ br: K,
461
+ bl: 0
462
+ });
463
+ else {
464
+ let e = X(t), n = X(t + i) - e;
465
+ t += i, d = w(e, 0, n, Y.bandwidth(), {
466
+ tl: 0,
467
+ tr: c ? K : 0,
468
+ br: c ? K : 0,
469
+ bl: 0
470
+ });
471
+ }
472
+ return /* @__PURE__ */ s("path", {
473
+ d,
474
+ fill: a,
475
+ tabIndex: 0,
476
+ role: "img",
477
+ "aria-label": u,
478
+ "data-graphene-chart-bar": !0,
479
+ "data-layout": B ? "vertical" : "horizontal",
480
+ "data-animated": O ? "true" : "false",
481
+ className: "transition-opacity hover:opacity-80 focus:outline-none",
482
+ onFocus: (t) => me(e, t),
483
+ onBlur: he
484
+ }, n);
485
+ })
486
+ }, e.category);
487
+ }),
488
+ S && /* @__PURE__ */ s(re, {
489
+ scale: Y,
490
+ orientation: B ? "bottom" : "left",
491
+ length: B ? J : 0
492
+ }),
493
+ C && /* @__PURE__ */ s(ie, {
494
+ scale: X,
495
+ orientation: B ? "left" : "bottom",
496
+ length: B ? 0 : J,
497
+ tickFormatter: T
498
+ })
499
+ ]
500
+ })
501
+ }),
502
+ /* @__PURE__ */ s("div", {
503
+ className: "sr-only",
504
+ children: /* @__PURE__ */ c("table", { children: [
505
+ /* @__PURE__ */ s("caption", { children: $ }),
506
+ /* @__PURE__ */ s("thead", { children: /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
507
+ scope: "col",
508
+ children: "Category"
509
+ }), R.map((e) => /* @__PURE__ */ s("th", {
510
+ scope: "col",
511
+ children: typeof F[e]?.label == "string" ? F[e]?.label : e
512
+ }, e))] }) }),
513
+ /* @__PURE__ */ s("tbody", { children: f.map((e) => /* @__PURE__ */ c("tr", { children: [/* @__PURE__ */ s("th", {
514
+ scope: "row",
515
+ children: e.category
516
+ }), R.map((t) => /* @__PURE__ */ s("td", { children: T(Number(e[t]) || 0) }, t))] }, e.category)) })
517
+ ] })
518
+ }),
519
+ I && W.state && /* @__PURE__ */ s("div", {
520
+ role: "tooltip",
521
+ className: "pointer-events-none absolute transition-[left,top] duration-75 ease-out",
522
+ style: {
523
+ left: W.state.x,
524
+ top: W.state.y
525
+ },
526
+ children: a.cloneElement(I.content, {
527
+ label: W.state.label,
528
+ items: W.state.items,
529
+ active: !0
530
+ })
531
+ })
532
+ ]
533
+ }),
534
+ L && ge === "bottom" && a.cloneElement(L.content, {
535
+ items: ue,
536
+ verticalAlign: "bottom"
537
+ })
538
+ ]
539
+ })
540
+ ] });
541
+ }
542
+ //#endregion
543
+ export { F as BarChart, f as CHART_THEMES, _ as ChartContainer, N as ChartLegend, M as ChartLegendContent, v as ChartStyle, j as ChartTooltip, A as ChartTooltipContent, p as DEFAULT_MARGIN, i as cn, h as useChartConfig };
@@ -0,0 +1,2 @@
1
+ export { cn } from '@gravitee/graphene-core';
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { ScaleBand, ScaleLinear } from 'd3-scale';
2
+ type AxisOrientation = 'top' | 'right' | 'bottom' | 'left';
3
+ export interface CategoryAxisProps {
4
+ scale: ScaleBand<string>;
5
+ orientation: Extract<AxisOrientation, 'bottom' | 'left'>;
6
+ /** Inner plot width/height the axis sits against. */
7
+ length: number;
8
+ }
9
+ /**
10
+ * Renders category-axis labels centered on each band of a `d3-scale` band
11
+ * scale. No axis line is drawn — visual separation comes from the grid
12
+ * primitive when enabled.
13
+ */
14
+ export declare function CategoryAxis({ scale, orientation, length }: CategoryAxisProps): import("react/jsx-runtime").JSX.Element;
15
+ export interface ValueAxisProps {
16
+ scale: ScaleLinear<number, number>;
17
+ orientation: Extract<AxisOrientation, 'bottom' | 'left'>;
18
+ /** Inner plot width/height the axis sits against. */
19
+ length: number;
20
+ tickCount?: number;
21
+ tickFormatter?: (value: number) => string;
22
+ }
23
+ /** Linear axis tick labels for the value axis. */
24
+ export declare function ValueAxis({ scale, orientation, length, tickCount, tickFormatter }: ValueAxisProps): import("react/jsx-runtime").JSX.Element;
25
+ export {};
26
+ //# sourceMappingURL=Axis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Axis.d.ts","sourceRoot":"","sources":["../../src/primitives/Axis.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvD,KAAK,eAAe,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC;IACzD,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,iBAAiB,2CAqC7E;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,WAAW,EAAE,OAAO,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC;IACzD,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,kDAAkD;AAClD,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAa,EAAE,aAAsB,EAAE,EAAE,cAAc,2CA+B9G"}
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Slot payload registered by `<ChartTooltip>`. `content` is the element
4
+ * cloned by the chart at render time with injected `label` / `items` /
5
+ * `active` props.
6
+ */
7
+ export interface TooltipSlot {
8
+ content: React.ReactElement;
9
+ }
10
+ /**
11
+ * Slot payload registered by `<ChartLegend>`. `verticalAlign` determines
12
+ * where in the chart layout the legend is rendered.
13
+ */
14
+ export interface LegendSlot {
15
+ content: React.ReactElement;
16
+ verticalAlign: 'top' | 'bottom';
17
+ }
18
+ interface ChartSlotsState {
19
+ tooltip: TooltipSlot | null;
20
+ legend: LegendSlot | null;
21
+ }
22
+ interface ChartSlotsContextValue extends ChartSlotsState {
23
+ setTooltip: (slot: TooltipSlot | null) => void;
24
+ setLegend: (slot: LegendSlot | null) => void;
25
+ }
26
+ /**
27
+ * Reads the slots registered by `<ChartTooltip>` / `<ChartLegend>` for the
28
+ * nearest enclosing chart. Returns an inert fallback when used outside of
29
+ * a chart so the slot components themselves never throw (they just render
30
+ * nothing, matching `<ChartTooltip>`'s documented "marker that renders
31
+ * null" contract).
32
+ */
33
+ export declare function useChartSlots(): ChartSlotsContextValue;
34
+ export interface ChartSlotsProviderProps {
35
+ children: React.ReactNode;
36
+ }
37
+ /**
38
+ * Wraps a chart's render tree so that `<ChartTooltip>` and `<ChartLegend>`
39
+ * markers can register their content via a `useLayoutEffect` regardless of
40
+ * how deeply they are nested (arbitrary fragments, HOCs, conditional
41
+ * rendering, …). Charts consume the registered slots via `useChartSlots`.
42
+ *
43
+ * Registration runs in `useLayoutEffect` so the chart re-renders with the
44
+ * registered slots before the browser paints — no visible layout shift
45
+ * between the first "no slots" frame and the "with slots" frame.
46
+ */
47
+ export declare function ChartSlotsProvider({ children }: ChartSlotsProviderProps): import("react/jsx-runtime").JSX.Element;
48
+ export {};
49
+ //# sourceMappingURL=ChartSlots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartSlots.d.ts","sourceRoot":"","sources":["../../src/primitives/ChartSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC;IAC5B,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC;CACjC;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;CAC3B;AAED,UAAU,sBAAuB,SAAQ,eAAe;IACtD,UAAU,EAAE,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,SAAS,EAAE,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC;CAC9C;AAID;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,sBAAsB,CAWtD;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,uBAAuB,2CAUvE"}
@@ -0,0 +1,22 @@
1
+ import { ScaleLinear } from 'd3-scale';
2
+ export interface GridProps {
3
+ /**
4
+ * Linear scale whose tick positions are used to draw grid lines. For a
5
+ * vertical chart the grid is horizontal (ticks on the Y axis); for a
6
+ * horizontal chart the grid is vertical (ticks on the X axis).
7
+ */
8
+ scale: ScaleLinear<number, number>;
9
+ /** Perpendicular extent of each grid line (inner chart width or height). */
10
+ length: number;
11
+ /** Orientation of the grid lines. */
12
+ orientation: 'horizontal' | 'vertical';
13
+ /** Number of ticks to request from the scale. */
14
+ tickCount?: number;
15
+ }
16
+ /**
17
+ * Dashed grid lines aligned on a linear scale. Styling uses the Graphene
18
+ * semantic `border` token so grids automatically adapt to light/dark mode
19
+ * without the chart having to know about them.
20
+ */
21
+ export declare function Grid({ scale, length, orientation, tickCount }: GridProps): import("react/jsx-runtime").JSX.Element;
22
+ //# sourceMappingURL=Grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../src/primitives/Grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,WAAW,EAAE,YAAY,GAAG,UAAU,CAAC;IACvC,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,SAAa,EAAE,EAAE,SAAS,2CAiC5E"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Internal D3 primitives shared by chart types. These are intentionally
3
+ * **not** re-exported from the package barrel (`src/index.ts`): their shape
4
+ * is an implementation detail that should be free to evolve as new chart
5
+ * types land. Consumers must only import the public chart components.
6
+ */
7
+ export { useChartDimensions } from './useChartDimensions';
8
+ export { useTooltipState } from './useTooltipState';
9
+ export type { UseTooltipStateApi } from './useTooltipState';
10
+ export { Grid } from './Grid';
11
+ export type { GridProps } from './Grid';
12
+ export { CategoryAxis, ValueAxis } from './Axis';
13
+ export type { CategoryAxisProps, ValueAxisProps } from './Axis';
14
+ export { roundedRectPath } from './roundedRect';
15
+ export type { CornerRadii } from './roundedRect';
16
+ export { ChartSlotsProvider, useChartSlots } from './ChartSlots';
17
+ export type { ChartSlotsProviderProps, LegendSlot, TooltipSlot } from './ChartSlots';
18
+ export { useResolvedCssLength } from './useResolvedCssLength';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EAAE,uBAAuB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}