@nice2dev/ui 1.4.22 → 1.4.24

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 (38) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/{NicePivotGrid-BshofJh1.cjs → NicePivotGrid-D53CQ2cY.cjs} +1 -1
  3. package/dist/charts/NiceAdvancedCharts.mjs +621 -764
  4. package/dist/charts/NiceBarGauge.mjs +100 -65
  5. package/dist/charts/NiceBullet.mjs +103 -98
  6. package/dist/charts/NiceChart.mjs +269 -266
  7. package/dist/charts/NiceChartRangeSelector.mjs +159 -0
  8. package/dist/charts/NiceCircularGauge.mjs +99 -70
  9. package/dist/charts/NiceHeatMap.mjs +140 -70
  10. package/dist/charts/NiceLinearGauge.mjs +168 -119
  11. package/dist/charts/NiceOrganizationChart.mjs +183 -90
  12. package/dist/charts/NicePieChart.mjs +94 -49
  13. package/dist/charts/NicePolarChart.mjs +2 -2
  14. package/dist/charts/NiceSankey.mjs +166 -93
  15. package/dist/charts/NiceStockChart.mjs +258 -157
  16. package/dist/charts-CSgOgfES.cjs +867 -0
  17. package/dist/charts.cjs +1 -1
  18. package/dist/charts.d.ts +150 -104
  19. package/dist/charts.mjs +22 -24
  20. package/dist/core/lazy.mjs +50 -63
  21. package/dist/core-lazy-sO0xvg64.cjs +1 -0
  22. package/dist/data.cjs +1 -1
  23. package/dist/demo/docs/docPreviews.mjs +450 -466
  24. package/dist/demo/docs/docRegistry.mjs +5 -35
  25. package/dist/index.cjs +60 -67
  26. package/dist/index.d.ts +145 -174
  27. package/dist/index.mjs +831 -836
  28. package/dist/lazy.cjs +1 -1
  29. package/dist/lazy.d.ts +49 -23
  30. package/dist/lazy.mjs +1 -1
  31. package/dist/style.css +1 -1
  32. package/dist/tools/NiceShowcase.mjs +1 -2
  33. package/package.json +4 -4
  34. package/dist/charts/NiceRangeSelector.mjs +0 -135
  35. package/dist/charts/NiceTreeMap.mjs +0 -100
  36. package/dist/charts/NiceVectorMap.mjs +0 -59
  37. package/dist/charts-C3Q3r8Yz.cjs +0 -918
  38. package/dist/core-lazy-CUnBYI-T.cjs +0 -1
@@ -1,116 +1,183 @@
1
- import { jsxs as r, jsx as n, Fragment as D } from "react/jsx-runtime";
2
- import { useNiceTranslation as K, useControlId as q, useRovingFocus as G, clickOnActivationKey as J, NiceIcon as l } from "@nice2dev/ui-core";
3
- import { forwardRef as L, useState as Z, useRef as C, useCallback as f } from "react";
4
- import { downloadBlob as B } from "../tools/NiceExport.mjs";
5
- import { orgChartToSvg as Q, orgChartToPng as V } from "./orgChartExport.mjs";
6
- const at = /* @__PURE__ */ Object.assign(
7
- /* @__PURE__ */ L(
1
+ import { jsxs as f, jsx as r, Fragment as lt } from "react/jsx-runtime";
2
+ import { useNiceTranslation as ht, useControlId as ut, useRovingFocus as gt, clickOnActivationKey as dt, NiceIcon as y } from "@nice2dev/ui-core";
3
+ import { forwardRef as mt, useState as k, useRef as S, useMemo as U, useLayoutEffect as pt, useEffect as X, useCallback as I } from "react";
4
+ import { downloadBlob as Q } from "../tools/NiceExport.mjs";
5
+ import { orgChartToSvg as ft, orgChartToPng as _t } from "./orgChartExport.mjs";
6
+ function G(a, h, c = 0, u = /* @__PURE__ */ new Set()) {
7
+ return a.children?.length && (c >= h && u.add(a.key), a.children.forEach((m) => G(m, h, c + 1, u))), u;
8
+ }
9
+ function vt(a, h) {
10
+ const c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), m = (p, v) => {
11
+ String(p.label ?? "").toLowerCase().includes(h) && (c.add(p.key), v.forEach((g) => u.add(g))), p.children?.forEach((g) => m(g, [...v, p.key]));
12
+ };
13
+ return h && m(a, []), { matches: c, ancestors: u };
14
+ }
15
+ const Nt = /* @__PURE__ */ Object.assign(
16
+ /* @__PURE__ */ mt(
8
17
  ({
9
- data: g,
10
- renderNode: m,
18
+ data: a,
19
+ renderNode: h,
11
20
  selectable: c,
12
- selectedKey: z,
13
- onSelect: _,
14
- direction: v = "top-down",
15
- collapsible: N = !0,
16
- zoomable: d = !1,
17
- exportable: u = !1,
18
- onExport: h,
19
- className: F,
20
- style: S,
21
- id: $,
22
- testId: j,
23
- "data-testid": T
24
- }, A) => {
25
- const { t: i } = K(), H = q($), [w, P] = Z(/* @__PURE__ */ new Set()), [s, y] = Z(1), b = C(null), k = C(null), x = C(null);
26
- G(x, { orientation: "horizontal" });
27
- const M = (t) => y((o) => Math.min(2, Math.max(0.2, Math.round(o * t * 100) / 100))), U = () => {
28
- const t = b.current, o = k.current;
29
- if (!t || !o)
21
+ selectedKey: u,
22
+ onSelect: m,
23
+ direction: p = "top-down",
24
+ collapsible: v = !0,
25
+ zoomable: g = !1,
26
+ exportable: E = !1,
27
+ onExport: w,
28
+ pannable: O = !0,
29
+ wheelZoom: b = "ctrl",
30
+ searchable: z = !1,
31
+ collapsedDepth: P,
32
+ highlightKeys: T,
33
+ onNodeClick: A,
34
+ className: J,
35
+ style: V,
36
+ id: tt,
37
+ testId: et,
38
+ "data-testid": nt
39
+ }, ot) => {
40
+ const { t: i } = ht(), rt = ut(tt), [L, j] = k(
41
+ () => P != null ? G(a, P) : /* @__PURE__ */ new Set()
42
+ ), [s, q] = k(1), [C, B] = k({ x: 0, y: 0 }), [x, it] = k(""), R = S(null), _ = U(() => vt(a, x.trim().toLowerCase()), [a, x]), W = U(() => new Set(T ?? []), [T]), N = S(null), $ = S(null), Y = S(null);
43
+ gt(Y, { orientation: "horizontal" });
44
+ const M = (t) => q((n) => Math.min(2, Math.max(0.2, Math.round(n * t * 100) / 100))), at = () => {
45
+ const t = N.current, n = $.current;
46
+ if (!t || !n)
30
47
  return;
31
- const a = o.scrollWidth / s, e = o.scrollHeight / s;
32
- a > 0 && e > 0 && y(Math.max(0.2, Math.min(1, t.clientWidth / a, t.clientHeight / e)));
33
- }, p = u === !0 ? ["svg", "png"] : u === !1 ? [] : u, W = async (t) => {
34
- const o = { direction: v };
48
+ const e = n.scrollWidth / s, o = n.scrollHeight / s;
49
+ e > 0 && o > 0 && q(Math.max(0.2, Math.min(1, t.clientWidth / e, t.clientHeight / o)));
50
+ }, F = E === !0 ? ["svg", "png"] : E === !1 ? [] : E, ct = async (t) => {
51
+ const n = { direction: p };
35
52
  if (t === "svg") {
36
- const e = Q(g, o);
37
- h ? h("svg", e) : B(new Blob([e], { type: "image/svg+xml" }), "organization-chart.svg");
53
+ const o = ft(a, n);
54
+ w ? w("svg", o) : Q(new Blob([o], { type: "image/svg+xml" }), "organization-chart.svg");
38
55
  return;
39
56
  }
40
- const a = await V(g, o);
41
- h ? h("png", a) : B(a, "organization-chart.png");
42
- }, O = f((t) => {
43
- P((o) => {
44
- const a = new Set(o);
45
- return a.has(t) ? a.delete(t) : a.add(t), a;
57
+ const e = await _t(a, n);
58
+ w ? w("png", e) : Q(e, "organization-chart.png");
59
+ }, Z = () => $.current?.querySelector(
60
+ ":scope > .nice-org-chart__item > .nice-org-chart__node"
61
+ ) ?? null;
62
+ pt(() => {
63
+ const t = R.current, n = Z();
64
+ if (R.current = null, !t || !n)
65
+ return;
66
+ const e = n.getBoundingClientRect(), o = (t.left - e.left) / s, l = (t.top - e.top) / s;
67
+ (o || l) && B((d) => ({ x: d.x + o, y: d.y + l }));
68
+ }, [L, s]), X(() => {
69
+ if (_.ancestors.size === 0)
70
+ return;
71
+ j((n) => {
72
+ const e = new Set(n);
73
+ return _.ancestors.forEach((o) => e.delete(o)), e.size === n.size ? n : e;
74
+ });
75
+ const t = window.requestAnimationFrame(() => {
76
+ const n = N.current, e = n?.querySelector(".nice-org-chart__node--match");
77
+ if (!n || !e)
78
+ return;
79
+ const o = n.getBoundingClientRect(), l = e.getBoundingClientRect();
80
+ B((d) => ({
81
+ x: d.x + (o.left + o.width / 2 - (l.left + l.width / 2)) / s,
82
+ y: d.y + (o.top + o.height / 2 - (l.top + l.height / 2)) / s
83
+ }));
84
+ });
85
+ return () => window.cancelAnimationFrame(t);
86
+ }, [_]), X(() => {
87
+ const t = N.current;
88
+ if (!t || !g || !b)
89
+ return;
90
+ const n = (e) => {
91
+ b === "ctrl" && !(e.ctrlKey || e.metaKey) || (e.preventDefault(), M(e.deltaY > 0 ? 1 / 1.1 : 1.1));
92
+ };
93
+ return t.addEventListener("wheel", n, { passive: !1 }), () => t.removeEventListener("wheel", n);
94
+ }, [g, b]);
95
+ const st = (t) => {
96
+ if (!O || t.button !== 0 || t.target.closest(".nice-org-chart__node, button, input"))
97
+ return;
98
+ const n = { x: t.clientX, y: t.clientY, pan: C }, e = t.currentTarget;
99
+ e.setPointerCapture(t.pointerId), e.classList.add("nice-org-chart__view--panning");
100
+ const o = (d) => B({
101
+ x: n.pan.x + (d.clientX - n.x) / s,
102
+ y: n.pan.y + (d.clientY - n.y) / s
103
+ }), l = () => {
104
+ e.classList.remove("nice-org-chart__view--panning"), e.removeEventListener("pointermove", o), e.removeEventListener("pointerup", l), e.removeEventListener("pointercancel", l);
105
+ };
106
+ e.addEventListener("pointermove", o), e.addEventListener("pointerup", l), e.addEventListener("pointercancel", l);
107
+ }, D = I((t) => {
108
+ R.current = Z()?.getBoundingClientRect() ?? null, j((n) => {
109
+ const e = new Set(n);
110
+ return e.has(t) ? e.delete(t) : e.add(t), e;
46
111
  });
47
- }, []), R = f(
112
+ }, []), H = I(
48
113
  (t) => {
49
- c && _?.(t);
114
+ A?.(t), c && m?.(t.key);
50
115
  },
51
- [c, _]
52
- ), I = f(
116
+ [c, m, A]
117
+ ), K = I(
53
118
  (t) => {
54
- const o = w.has(t.key), a = t.children && t.children.length > 0;
55
- return /* @__PURE__ */ r("li", { className: "nice-org-chart__item", children: [
56
- /* @__PURE__ */ r(
119
+ const n = L.has(t.key), e = t.children && t.children.length > 0;
120
+ return /* @__PURE__ */ f("li", { className: "nice-org-chart__item", children: [
121
+ /* @__PURE__ */ f(
57
122
  "div",
58
123
  {
59
124
  tabIndex: c ? 0 : void 0,
60
- onKeyDown: c ? J : void 0,
61
- className: `nice-org-chart__node${z === t.key ? " nice-org-chart__node--selected" : ""}`,
62
- onClick: () => R(t.key),
125
+ onKeyDown: c ? dt : void 0,
126
+ className: `nice-org-chart__node${u === t.key ? " nice-org-chart__node--selected" : ""}${_.matches.has(t.key) ? " nice-org-chart__node--match" : ""}${W.has(t.key) ? " nice-org-chart__node--highlight" : ""}`,
127
+ onClick: () => H(t),
63
128
  role: c ? "button" : void 0,
64
129
  children: [
65
- m ? m(t) : /* @__PURE__ */ n("span", { children: t.label }),
66
- N && a && /* @__PURE__ */ n(
130
+ h ? h(t) : /* @__PURE__ */ r("span", { children: t.label }),
131
+ v && e && /* @__PURE__ */ r(
67
132
  "button",
68
133
  {
69
134
  type: "button",
70
135
  className: "nice-org-chart__toggle",
71
- onClick: (e) => {
72
- e.stopPropagation(), O(t.key);
136
+ onClick: (o) => {
137
+ o.stopPropagation(), D(t.key);
73
138
  },
74
- "aria-label": o ? i("organizationChart.expand", "Expand") : i("organizationChart.collapse", "Collapse"),
75
- children: /* @__PURE__ */ n(l, { name: o ? "plus" : "minus", size: 14 })
139
+ "aria-label": n ? i("organizationChart.expand", "Expand") : i("organizationChart.collapse", "Collapse"),
140
+ children: /* @__PURE__ */ r(y, { name: n ? "plus" : "minus", size: 14 })
76
141
  }
77
142
  )
78
143
  ]
79
144
  }
80
145
  ),
81
- a && !o && /* @__PURE__ */ n("ul", { className: "nice-org-chart__children", children: t.children.map((e) => I(e)) })
146
+ e && !n && /* @__PURE__ */ r("ul", { className: "nice-org-chart__children", children: t.children.map((o) => K(o)) })
82
147
  ] }, t.key);
83
148
  },
84
149
  [
85
- w,
86
- z,
87
- m,
150
+ L,
151
+ u,
152
+ _,
153
+ W,
154
+ h,
88
155
  c,
89
- N,
90
- R,
91
- O,
156
+ v,
157
+ H,
158
+ D,
92
159
  i
93
160
  ]
94
161
  );
95
- return /* @__PURE__ */ r(
162
+ return /* @__PURE__ */ f(
96
163
  "div",
97
164
  {
98
- ref: A,
99
- id: H,
100
- className: `nice-org-chart nice-org-chart--${v}${d || p.length ? " nice-org-chart--tools" : ""} ${F || ""}`,
101
- style: S,
102
- "data-testid": T ?? j,
165
+ ref: ot,
166
+ id: rt,
167
+ className: `nice-org-chart nice-org-chart--${p}${g || F.length || z ? " nice-org-chart--tools" : ""} ${J || ""}`,
168
+ style: V,
169
+ "data-testid": nt ?? et,
103
170
  children: [
104
- (d || p.length > 0) && /* @__PURE__ */ r(
171
+ (g || F.length > 0 || z) && /* @__PURE__ */ f(
105
172
  "div",
106
173
  {
107
- ref: x,
174
+ ref: Y,
108
175
  className: "nice-org-chart__tools",
109
176
  role: "toolbar",
110
177
  "aria-label": i("organizationChart.tools", "Chart tools"),
111
178
  children: [
112
- d && /* @__PURE__ */ r(D, { children: [
113
- /* @__PURE__ */ n(
179
+ g && /* @__PURE__ */ f(lt, { children: [
180
+ /* @__PURE__ */ r(
114
181
  "button",
115
182
  {
116
183
  type: "button",
@@ -118,14 +185,14 @@ const at = /* @__PURE__ */ Object.assign(
118
185
  onClick: () => M(1 / 1.2),
119
186
  "aria-label": i("organizationChart.zoomOut", "Zoom out"),
120
187
  title: i("organizationChart.zoomOut", "Zoom out"),
121
- children: /* @__PURE__ */ n(l, { name: "zoom-out", size: 14 })
188
+ children: /* @__PURE__ */ r(y, { name: "zoom-out", size: 14 })
122
189
  }
123
190
  ),
124
- /* @__PURE__ */ r("span", { className: "nice-org-chart__zoom", "aria-live": "polite", children: [
191
+ /* @__PURE__ */ f("span", { className: "nice-org-chart__zoom", "aria-live": "polite", children: [
125
192
  Math.round(s * 100),
126
193
  "%"
127
194
  ] }),
128
- /* @__PURE__ */ n(
195
+ /* @__PURE__ */ r(
129
196
  "button",
130
197
  {
131
198
  type: "button",
@@ -133,33 +200,48 @@ const at = /* @__PURE__ */ Object.assign(
133
200
  onClick: () => M(1.2),
134
201
  "aria-label": i("organizationChart.zoomIn", "Zoom in"),
135
202
  title: i("organizationChart.zoomIn", "Zoom in"),
136
- children: /* @__PURE__ */ n(l, { name: "zoom-in", size: 14 })
203
+ children: /* @__PURE__ */ r(y, { name: "zoom-in", size: 14 })
137
204
  }
138
205
  ),
139
- /* @__PURE__ */ n(
206
+ /* @__PURE__ */ r(
140
207
  "button",
141
208
  {
142
209
  type: "button",
143
210
  className: "nice-org-chart__tool",
144
- onClick: U,
211
+ onClick: at,
145
212
  "aria-label": i("organizationChart.fit", "Fit to view"),
146
213
  title: i("organizationChart.fit", "Fit to view"),
147
- children: /* @__PURE__ */ n(l, { name: "expand", size: 14 })
214
+ children: /* @__PURE__ */ r(y, { name: "expand", size: 14 })
148
215
  }
149
216
  )
150
217
  ] }),
151
- p.map((t) => /* @__PURE__ */ r(
218
+ z && /* @__PURE__ */ r(
219
+ "input",
220
+ {
221
+ type: "search",
222
+ className: "nice-org-chart__search",
223
+ value: x,
224
+ onChange: (t) => it(t.target.value),
225
+ placeholder: i("organizationChart.search", "Search people…"),
226
+ "aria-label": i("organizationChart.search", "Search people…")
227
+ }
228
+ ),
229
+ z && x.trim() && /* @__PURE__ */ r("span", { className: "nice-org-chart__zoom", "aria-live": "polite", children: i("organizationChart.found", "{count} found").replace(
230
+ "{count}",
231
+ String(_.matches.size)
232
+ ) }),
233
+ F.map((t) => /* @__PURE__ */ f(
152
234
  "button",
153
235
  {
154
236
  type: "button",
155
237
  className: "nice-org-chart__tool",
156
- onClick: () => void W(t),
238
+ onClick: () => void ct(t),
157
239
  title: i("organizationChart.export", "Export as {format}").replace(
158
240
  "{format}",
159
241
  t.toUpperCase()
160
242
  ),
161
243
  children: [
162
- /* @__PURE__ */ n(l, { name: "download", size: 14 }),
244
+ /* @__PURE__ */ r(y, { name: "download", size: 14 }),
163
245
  " ",
164
246
  t.toUpperCase()
165
247
  ]
@@ -169,15 +251,26 @@ const at = /* @__PURE__ */ Object.assign(
169
251
  ]
170
252
  }
171
253
  ),
172
- /* @__PURE__ */ n("div", { ref: b, className: "nice-org-chart__view", children: /* @__PURE__ */ n(
173
- "ul",
254
+ /* @__PURE__ */ r(
255
+ "div",
174
256
  {
175
- ref: k,
176
- className: "nice-org-chart__root",
177
- style: s !== 1 ? { zoom: s } : void 0,
178
- children: I(g)
257
+ ref: N,
258
+ className: `nice-org-chart__view${O ? " nice-org-chart__view--pannable" : ""}`,
259
+ onPointerDown: st,
260
+ children: /* @__PURE__ */ r(
261
+ "ul",
262
+ {
263
+ ref: $,
264
+ className: "nice-org-chart__root",
265
+ style: {
266
+ ...s !== 1 ? { zoom: s } : {},
267
+ ...C.x || C.y ? { transform: `translate(${C.x}px, ${C.y}px)` } : {}
268
+ },
269
+ children: K(a)
270
+ }
271
+ )
179
272
  }
180
- ) })
273
+ )
181
274
  ]
182
275
  }
183
276
  );
@@ -186,5 +279,5 @@ const at = /* @__PURE__ */ Object.assign(
186
279
  { displayName: "NiceOrganizationChart" }
187
280
  );
188
281
  export {
189
- at as NiceOrganizationChart
282
+ Nt as NiceOrganizationChart
190
283
  };
@@ -1,56 +1,81 @@
1
- import { jsx as s, jsxs as M } from "react/jsx-runtime";
2
- import { CHART_COLORS as x } from "./colors.mjs";
3
- const q = [], F = ({
4
- data: p = q,
5
- width: _ = 400,
6
- height: A = 400,
7
- innerRadius: o = 0,
8
- title: g,
9
- showLegend: N = !0,
10
- showLabels: Z = !0,
11
- className: j,
12
- style: B,
13
- testId: H,
14
- "data-testid": L
1
+ import { jsx as a, jsxs as y } from "react/jsx-runtime";
2
+ import { useId as ht } from "react";
3
+ import { CHART_COLORS as N } from "./colors.mjs";
4
+ const rt = [], n = 12, J = 20, K = 7, Q = 22, mt = ({
5
+ data: M = rt,
6
+ width: $ = 400,
7
+ height: p = 400,
8
+ innerRadius: h = 0,
9
+ title: k,
10
+ showLegend: E = !0,
11
+ legendPlacement: r = "right",
12
+ showLabels: S = !0,
13
+ splitSize: b = 2,
14
+ className: V,
15
+ style: P,
16
+ testId: z,
17
+ "data-testid": R
15
18
  }) => {
16
- const e = _ / 2, l = (A - (N ? 30 : 0)) / 2 + (g ? 10 : 0), c = Math.min(e, l) - 40, d = p.reduce((t, a) => t + a.value, 0);
17
- let f = -Math.PI / 2;
18
- const O = p.map((t, a) => {
19
- const y = t.value / (d || 1) * Math.PI * 2, h = f;
20
- f += y;
21
- const $ = f, P = (h + $) / 2, I = e + c * Math.cos(h), Y = l + c * Math.sin(h), k = e + c * Math.cos($), u = l + c * Math.sin($), b = y > Math.PI ? 1 : 0, W = t.color || x[a % x.length], v = y >= Math.PI * 2 - 1e-9;
22
- let i;
23
- if (v) {
24
- const r = (n, m) => `M${e - n},${l} A${n},${n} 0 1,${m} ${e + n},${l} A${n},${n} 0 1,${m} ${e - n},${l} Z`;
25
- i = o > 0 ? `${r(c, 1)} ${r(o, 0)}` : r(c, 1);
26
- } else if (o > 0) {
27
- const r = e + o * Math.cos(h), n = l + o * Math.sin(h), m = e + o * Math.cos($), S = l + o * Math.sin($);
28
- i = `M${I},${Y} A${c},${c} 0 ${b},1 ${k},${u} L${m},${S} A${o},${o} 0 ${b},0 ${r},${n} Z`;
19
+ const L = `nice-pie-gaps-${ht().replace(/[^a-zA-Z0-9_-]/g, "")}`, H = M.reduce((t, c) => t + c.value, 0), I = k ? 32 : 0, tt = M.reduce((t, c) => Math.max(t, c.label.length), 0), O = r === "left" || r === "right", x = Math.min($ * (O ? 0.42 : 0.9), Q + tt * K), d = O ? 1 : Math.max(1, Math.floor(($ - 2 * n) / (x + 12))), f = (E ? Math.ceil(M.length / d) : 0) * J, l = { x: n, y: I + n / 2, w: $ - 2 * n, h: p - I - n };
20
+ E && M.length > 0 && (r === "right" ? l.w -= x + n : r === "left" ? (l.x += x + n, l.w -= x + n) : (r === "top" && (l.y += f + 8), l.h -= f + 8));
21
+ const e = l.x + l.w / 2, s = l.y + l.h / 2, o = Math.max(10, Math.min(l.w, l.h) / 2 - 4), ct = r === "right" ? $ - n - x : n, ot = r === "top" ? I + 4 : r === "bottom" ? p - n / 2 - f : s - f / 2, T = (t) => {
22
+ const c = Math.max(3, Math.floor((x - Q) / K));
23
+ return t.length > c ? `${t.slice(0, c - 1)}…` : t;
24
+ };
25
+ let C = -Math.PI / 2;
26
+ const D = [], Z = M.map((t, c) => {
27
+ const _ = t.value / (H || 1) * Math.PI * 2, m = C;
28
+ C += _;
29
+ const A = C, X = (m + A) / 2;
30
+ _ > 0 && D.push(m);
31
+ const j = e + o * Math.cos(m), w = s + o * Math.sin(m), B = e + o * Math.cos(A), U = s + o * Math.sin(A), W = _ > Math.PI ? 1 : 0, st = t.color || N[c % N.length], Y = _ >= Math.PI * 2 - 1e-9;
32
+ let u;
33
+ if (Y) {
34
+ const g = (i, v) => `M${e - i},${s} A${i},${i} 0 1,${v} ${e + i},${s} A${i},${i} 0 1,${v} ${e - i},${s} Z`;
35
+ u = h > 0 ? `${g(o, 1)} ${g(h, 0)}` : g(o, 1);
36
+ } else if (h > 0) {
37
+ const g = e + h * Math.cos(m), i = s + h * Math.sin(m), v = e + h * Math.cos(A), at = s + h * Math.sin(A);
38
+ u = `M${j},${w} A${o},${o} 0 ${W},1 ${B},${U} L${v},${at} A${h},${h} 0 ${W},0 ${g},${i} Z`;
29
39
  } else
30
- i = `M${e},${l} L${I},${Y} A${c},${c} 0 ${b},1 ${k},${u} Z`;
31
- const C = Math.min(Math.max(o, 0), c), T = C > 0 ? (C + c) / 2 : c * 0.65, X = v ? e : e + T * Math.cos(P), D = v ? l : l + T * Math.sin(P), E = d > 0 ? Math.round(t.value / d * 100) : 0;
32
- return { ...t, path: i, labelX: X, labelY: D, pct: E, color: W };
33
- });
34
- return /* @__PURE__ */ s(
40
+ u = `M${e},${s} L${j},${w} A${o},${o} 0 ${W},1 ${B},${U} Z`;
41
+ const q = Math.min(Math.max(h, 0), o), F = q > 0 ? (q + o) / 2 : o * 0.65, lt = Y ? e : e + F * Math.cos(X), et = Y ? s : s + F * Math.sin(X), nt = H > 0 ? Math.round(t.value / H * 100) : 0;
42
+ return { ...t, path: u, labelX: lt, labelY: et, pct: nt, color: st };
43
+ }), G = b > 0 && D.length > 1;
44
+ return /* @__PURE__ */ a(
35
45
  "div",
36
46
  {
37
- className: `nice-piechart ${j || ""}`,
38
- style: B,
39
- "data-testid": L ?? H,
40
- children: /* @__PURE__ */ M(
47
+ className: `nice-piechart ${V || ""}`,
48
+ style: P,
49
+ "data-testid": R ?? z,
50
+ children: /* @__PURE__ */ y(
41
51
  "svg",
42
52
  {
43
- viewBox: `0 0 ${_} ${A}`,
53
+ viewBox: `0 0 ${$} ${p}`,
44
54
  preserveAspectRatio: "xMidYMid meet",
45
55
  width: "100%",
46
56
  height: "100%",
47
57
  style: { display: "block", maxWidth: "100%", maxHeight: "100%" },
48
58
  className: "nice-piechart__svg",
49
59
  children: [
50
- g && /* @__PURE__ */ s("text", { x: e, y: 20, textAnchor: "middle", className: "nice-chart__title", children: g }),
51
- O.map((t, a) => /* @__PURE__ */ M("g", { children: [
52
- /* @__PURE__ */ s("path", { d: t.path, fill: t.color, stroke: "var(--nice-bg-primary, #fff)", strokeWidth: 2, children: /* @__PURE__ */ s("title", { children: `${t.label}: ${t.value} (${t.pct}%)` }) }),
53
- Z && t.pct >= 5 && /* @__PURE__ */ M(
60
+ G && /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ y("mask", { id: L, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: $, height: p, children: [
61
+ /* @__PURE__ */ a("rect", { x: 0, y: 0, width: $, height: p, fill: "white" }),
62
+ D.map((t, c) => /* @__PURE__ */ a(
63
+ "line",
64
+ {
65
+ x1: e,
66
+ y1: s,
67
+ x2: e + (o + b) * Math.cos(t),
68
+ y2: s + (o + b) * Math.sin(t),
69
+ stroke: "black",
70
+ strokeWidth: b
71
+ },
72
+ c
73
+ ))
74
+ ] }) }),
75
+ k && /* @__PURE__ */ a("text", { x: $ / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: k }),
76
+ /* @__PURE__ */ a("g", { mask: G ? `url(#${L})` : void 0, children: Z.map((t, c) => /* @__PURE__ */ a("path", { d: t.path, fill: t.color, children: /* @__PURE__ */ a("title", { children: `${t.label}: ${t.value} (${t.pct}%)` }) }, c)) }),
77
+ S && Z.map(
78
+ (t, c) => t.pct >= 5 ? /* @__PURE__ */ y(
54
79
  "text",
55
80
  {
56
81
  x: t.labelX,
@@ -62,13 +87,33 @@ const q = [], F = ({
62
87
  t.pct,
63
88
  "%"
64
89
  ]
65
- }
66
- )
67
- ] }, a)),
68
- N && /* @__PURE__ */ s("g", { transform: `translate(10, ${A - 25})`, children: p.map((t, a) => /* @__PURE__ */ M("g", { transform: `translate(${a * 100}, 0)`, children: [
69
- /* @__PURE__ */ s("rect", { width: 10, height: 10, rx: 2, fill: t.color || x[a % x.length] }),
70
- /* @__PURE__ */ s("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: t.label })
71
- ] }, a)) })
90
+ },
91
+ c
92
+ ) : null
93
+ ),
94
+ E && /* @__PURE__ */ a("g", { transform: `translate(${ct}, ${ot})`, children: M.map((t, c) => /* @__PURE__ */ y(
95
+ "g",
96
+ {
97
+ transform: `translate(${c % d * (x + 12)}, ${Math.floor(c / d) * J})`,
98
+ children: [
99
+ /* @__PURE__ */ a(
100
+ "rect",
101
+ {
102
+ y: 3,
103
+ width: 10,
104
+ height: 10,
105
+ rx: 2,
106
+ fill: t.color || N[c % N.length]
107
+ }
108
+ ),
109
+ /* @__PURE__ */ y("text", { x: 16, y: 12, className: "nice-chart__legend-text", children: [
110
+ T(t.label) !== t.label && /* @__PURE__ */ a("title", { children: t.label }),
111
+ T(t.label)
112
+ ] })
113
+ ]
114
+ },
115
+ c
116
+ )) })
72
117
  ]
73
118
  }
74
119
  )
@@ -76,5 +121,5 @@ const q = [], F = ({
76
121
  );
77
122
  };
78
123
  export {
79
- F as NicePieChart
124
+ mt as NicePieChart
80
125
  };
@@ -13,7 +13,7 @@ const R = [], T = [], B = ({
13
13
  testId: I,
14
14
  "data-testid": S
15
15
  }) => {
16
- const u = g ? 44 : 0, $ = p - (M ? 30 : 0) - u, s = f / 2, y = u + $ / 2, P = Math.min(s, $ / 2) - 60, b = x.length, _ = N ?? Math.max(...m.flatMap((t) => t.data), 1), k = Math.PI * 2 / b, E = 5, i = (t, n) => {
16
+ const u = g ? 54 : 0, $ = p - (M ? 30 : 0) - u, s = f / 2, y = u + $ / 2, P = Math.min(s, $ / 2) - 60, b = x.length, _ = N ?? Math.max(...m.flatMap((t) => t.data), 1), k = Math.PI * 2 / b, E = 5, i = (t, n) => {
17
17
  const a = t * k - Math.PI / 2, o = n / _ * P;
18
18
  return { x: s + o * Math.cos(a), y: y + o * Math.sin(a) };
19
19
  };
@@ -24,7 +24,7 @@ const R = [], T = [], B = ({
24
24
  style: A,
25
25
  "data-testid": S ?? I,
26
26
  children: /* @__PURE__ */ d("svg", { width: f, height: p, className: "nice-polarchart__svg", children: [
27
- g && /* @__PURE__ */ c("text", { x: s, y: 20, textAnchor: "middle", className: "nice-chart__title", children: g }),
27
+ g && /* @__PURE__ */ c("text", { x: s, y: 30, textAnchor: "middle", className: "nice-chart__title", children: g }),
28
28
  Array.from({ length: E }, (t, n) => {
29
29
  const a = P * ((n + 1) / E);
30
30
  return /* @__PURE__ */ c(