@nice2dev/ui 1.4.22 → 1.4.23

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.
@@ -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(