@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.
- package/CHANGELOG.md +96 -0
- package/dist/{NicePivotGrid-BshofJh1.cjs → NicePivotGrid-D53CQ2cY.cjs} +1 -1
- package/dist/charts/NiceAdvancedCharts.mjs +621 -764
- package/dist/charts/NiceBarGauge.mjs +100 -65
- package/dist/charts/NiceBullet.mjs +103 -98
- package/dist/charts/NiceChart.mjs +269 -266
- package/dist/charts/NiceChartRangeSelector.mjs +159 -0
- package/dist/charts/NiceCircularGauge.mjs +99 -70
- package/dist/charts/NiceHeatMap.mjs +140 -70
- package/dist/charts/NiceLinearGauge.mjs +168 -119
- package/dist/charts/NiceOrganizationChart.mjs +183 -90
- package/dist/charts/NicePieChart.mjs +94 -49
- package/dist/charts/NicePolarChart.mjs +2 -2
- package/dist/charts/NiceSankey.mjs +166 -93
- package/dist/charts/NiceStockChart.mjs +258 -157
- package/dist/charts-CSgOgfES.cjs +867 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.d.ts +150 -104
- package/dist/charts.mjs +22 -24
- package/dist/core/lazy.mjs +50 -63
- package/dist/core-lazy-sO0xvg64.cjs +1 -0
- package/dist/data.cjs +1 -1
- package/dist/demo/docs/docPreviews.mjs +450 -466
- package/dist/demo/docs/docRegistry.mjs +5 -35
- package/dist/index.cjs +60 -67
- package/dist/index.d.ts +145 -174
- package/dist/index.mjs +831 -836
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.d.ts +49 -23
- package/dist/lazy.mjs +1 -1
- package/dist/style.css +1 -1
- package/dist/tools/NiceShowcase.mjs +1 -2
- package/package.json +4 -4
- package/dist/charts/NiceRangeSelector.mjs +0 -135
- package/dist/charts/NiceTreeMap.mjs +0 -100
- package/dist/charts/NiceVectorMap.mjs +0 -59
- package/dist/charts-C3Q3r8Yz.cjs +0 -918
- package/dist/core-lazy-CUnBYI-T.cjs +0 -1
|
@@ -1,116 +1,183 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useNiceTranslation as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { downloadBlob as
|
|
5
|
-
import { orgChartToSvg as
|
|
6
|
-
|
|
7
|
-
|
|
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:
|
|
10
|
-
renderNode:
|
|
18
|
+
data: a,
|
|
19
|
+
renderNode: h,
|
|
11
20
|
selectable: c,
|
|
12
|
-
selectedKey:
|
|
13
|
-
onSelect:
|
|
14
|
-
direction:
|
|
15
|
-
collapsible:
|
|
16
|
-
zoomable:
|
|
17
|
-
exportable:
|
|
18
|
-
onExport:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
const
|
|
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
|
|
37
|
-
|
|
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
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
}, []),
|
|
112
|
+
}, []), H = I(
|
|
48
113
|
(t) => {
|
|
49
|
-
c &&
|
|
114
|
+
A?.(t), c && m?.(t.key);
|
|
50
115
|
},
|
|
51
|
-
[c,
|
|
52
|
-
),
|
|
116
|
+
[c, m, A]
|
|
117
|
+
), K = I(
|
|
53
118
|
(t) => {
|
|
54
|
-
const
|
|
55
|
-
return /* @__PURE__ */
|
|
56
|
-
/* @__PURE__ */
|
|
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 ?
|
|
61
|
-
className: `nice-org-chart__node${
|
|
62
|
-
onClick: () =>
|
|
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
|
-
|
|
66
|
-
|
|
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: (
|
|
72
|
-
|
|
136
|
+
onClick: (o) => {
|
|
137
|
+
o.stopPropagation(), D(t.key);
|
|
73
138
|
},
|
|
74
|
-
"aria-label":
|
|
75
|
-
children: /* @__PURE__ */
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
150
|
+
L,
|
|
151
|
+
u,
|
|
152
|
+
_,
|
|
153
|
+
W,
|
|
154
|
+
h,
|
|
88
155
|
c,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
156
|
+
v,
|
|
157
|
+
H,
|
|
158
|
+
D,
|
|
92
159
|
i
|
|
93
160
|
]
|
|
94
161
|
);
|
|
95
|
-
return /* @__PURE__ */
|
|
162
|
+
return /* @__PURE__ */ f(
|
|
96
163
|
"div",
|
|
97
164
|
{
|
|
98
|
-
ref:
|
|
99
|
-
id:
|
|
100
|
-
className: `nice-org-chart nice-org-chart--${
|
|
101
|
-
style:
|
|
102
|
-
"data-testid":
|
|
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
|
-
(
|
|
171
|
+
(g || F.length > 0 || z) && /* @__PURE__ */ f(
|
|
105
172
|
"div",
|
|
106
173
|
{
|
|
107
|
-
ref:
|
|
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
|
-
|
|
113
|
-
/* @__PURE__ */
|
|
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__ */
|
|
188
|
+
children: /* @__PURE__ */ r(y, { name: "zoom-out", size: 14 })
|
|
122
189
|
}
|
|
123
190
|
),
|
|
124
|
-
/* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
203
|
+
children: /* @__PURE__ */ r(y, { name: "zoom-in", size: 14 })
|
|
137
204
|
}
|
|
138
205
|
),
|
|
139
|
-
/* @__PURE__ */
|
|
206
|
+
/* @__PURE__ */ r(
|
|
140
207
|
"button",
|
|
141
208
|
{
|
|
142
209
|
type: "button",
|
|
143
210
|
className: "nice-org-chart__tool",
|
|
144
|
-
onClick:
|
|
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__ */
|
|
214
|
+
children: /* @__PURE__ */ r(y, { name: "expand", size: 14 })
|
|
148
215
|
}
|
|
149
216
|
)
|
|
150
217
|
] }),
|
|
151
|
-
|
|
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
|
|
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__ */
|
|
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__ */
|
|
173
|
-
"
|
|
254
|
+
/* @__PURE__ */ r(
|
|
255
|
+
"div",
|
|
174
256
|
{
|
|
175
|
-
ref:
|
|
176
|
-
className: "nice-org-
|
|
177
|
-
|
|
178
|
-
children:
|
|
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
|
-
|
|
282
|
+
Nt as NiceOrganizationChart
|
|
190
283
|
};
|
|
@@ -1,56 +1,81 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
const
|
|
32
|
-
return { ...t, path:
|
|
33
|
-
});
|
|
34
|
-
return /* @__PURE__ */
|
|
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 ${
|
|
38
|
-
style:
|
|
39
|
-
"data-testid":
|
|
40
|
-
children: /* @__PURE__ */
|
|
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 ${
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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 ?
|
|
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:
|
|
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(
|