@nice2dev/ui 1.4.23 → 1.4.25
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 +100 -0
- package/README.md +2 -4
- package/dist/NiceModuleLifecyclePanel-bsHwj1pO.cjs +1 -0
- package/dist/{NicePivotGrid-B5Fgi5E_.cjs → NicePivotGrid-D53CQ2cY.cjs} +1 -1
- package/dist/{NiceStreamDashboard.doc-74KUXya1.cjs → NiceStreamDashboard.doc-CdkHFf4Y.cjs} +2 -2
- package/dist/charts/NiceAdvancedCharts.mjs +586 -773
- package/dist/charts/NiceChartRangeSelector.mjs +159 -0
- package/dist/charts/NiceHeatMap.mjs +140 -70
- package/dist/charts/NiceOrganizationChart.mjs +183 -90
- 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 +126 -102
- 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 +504 -546
- package/dist/demo/docs/docRegistry.mjs +9 -94
- package/dist/docs/NiceStreamDashboard.doc.json.mjs +1 -1
- package/dist/documentation/utils.mjs +1 -1
- package/dist/index.cjs +95 -121
- package/dist/index.d.ts +126 -217
- package/dist/index.mjs +829 -836
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.d.ts +41 -23
- package/dist/lazy.mjs +1 -1
- package/dist/navigation/NiceDock.mjs +55 -48
- package/dist/navigation/NiceMenuTypes.mjs +197 -251
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.d.ts +5 -16
- package/dist/navigation.mjs +53 -54
- package/dist/style.css +2 -2
- package/dist/tools/NiceShowcase.mjs +2 -4
- package/package.json +4 -4
- package/dist/NiceDiagram.doc-CASS0Tnj.cjs +0 -8
- package/dist/NiceModuleLifecyclePanel-jckyVqqt.cjs +0 -1
- package/dist/charts/NiceRangeSelector.mjs +0 -135
- package/dist/charts/NiceTreeMap.mjs +0 -100
- package/dist/charts/NiceVectorMap.mjs +0 -59
- package/dist/charts-C9B548D2.cjs +0 -924
- package/dist/core-lazy-B54FdghB.cjs +0 -1
- package/dist/docs/NiceDiagram.doc.json.mjs +0 -32
- package/dist/tools/NiceChat.mjs +0 -98
|
@@ -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,102 +1,175 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsx as m, jsxs as N } from "react/jsx-runtime";
|
|
2
|
+
import { useId as F, useMemo as G } from "react";
|
|
3
|
+
import { CHART_COLORS as R } from "./colors.mjs";
|
|
4
|
+
const H = [], K = [];
|
|
5
|
+
function q(d, h) {
|
|
6
|
+
const n = new Map(d.map((o) => [o.id, 0]));
|
|
7
|
+
for (let o = 0; o < d.length; o++) {
|
|
8
|
+
let _ = !1;
|
|
9
|
+
for (const p of h) {
|
|
10
|
+
const M = (n.get(p.source) ?? 0) + 1;
|
|
11
|
+
n.has(p.target) && M > (n.get(p.target) ?? 0) && M < d.length && (n.set(p.target, M), _ = !0);
|
|
12
|
+
}
|
|
13
|
+
if (!_)
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
const k = Math.max(0, ...n.values()), g = new Set(h.map((o) => o.source)), v = new Set(h.map((o) => o.target));
|
|
17
|
+
for (const o of d)
|
|
18
|
+
v.has(o.id) && !g.has(o.id) && n.set(o.id, k);
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
const W = ({
|
|
22
|
+
nodes: d = H,
|
|
23
|
+
links: h = K,
|
|
24
|
+
width: n = 600,
|
|
25
|
+
height: k = 400,
|
|
26
|
+
nodeWidth: g = 20,
|
|
27
|
+
nodePadding: v = 10,
|
|
28
|
+
title: o,
|
|
29
|
+
showValues: _ = !1,
|
|
30
|
+
showTooltip: p = !0,
|
|
31
|
+
gradientLinks: M = !0,
|
|
32
|
+
onNodeClick: A,
|
|
33
|
+
onLinkClick: C,
|
|
34
|
+
className: T,
|
|
35
|
+
style: U,
|
|
36
|
+
testId: Y,
|
|
37
|
+
"data-testid": Z
|
|
15
38
|
}) => {
|
|
16
|
-
const a = { top:
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
const B = F().replace(/[^a-zA-Z0-9_-]/g, ""), y = { top: o ? 40 : 16, bottom: 16, left: 12, right: 12 }, I = n - y.left - y.right, j = k - y.top - y.bottom, b = (t) => t.label ?? t.name ?? t.id, f = G(() => {
|
|
40
|
+
const t = q(d, h), l = Math.max(1, ...[...t.values()].map((e) => e + 1)), c = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const e of d) {
|
|
42
|
+
const r = h.filter((s) => s.source === e.id).reduce((s, O) => s + O.value, 0), u = h.filter((s) => s.target === e.id).reduce((s, O) => s + O.value, 0);
|
|
43
|
+
c.set(e.id, Math.max(r, u));
|
|
44
|
+
}
|
|
45
|
+
const i = Array.from({ length: l }, () => []);
|
|
46
|
+
d.forEach((e) => i[t.get(e.id) ?? 0].push(e));
|
|
47
|
+
const w = Math.min(
|
|
48
|
+
...i.filter((e) => e.length > 0).map((e) => {
|
|
49
|
+
const r = e.reduce((u, s) => u + (c.get(s.id) || 0), 0);
|
|
50
|
+
return r > 0 ? (j - (e.length - 1) * v) / r : 1 / 0;
|
|
51
|
+
})
|
|
52
|
+
), $ = Number.isFinite(w) ? Math.max(0, w) : 0, a = /* @__PURE__ */ new Map();
|
|
53
|
+
i.forEach((e, r) => {
|
|
54
|
+
const u = y.left + (l > 1 ? r / (l - 1) * (I - g) : (I - g) / 2), s = e.reduce((x, E) => x + (c.get(E.id) || 0) * $, 0) + (e.length - 1) * v;
|
|
55
|
+
let O = y.top + Math.max(0, (j - s) / 2);
|
|
56
|
+
e.forEach((x) => {
|
|
57
|
+
const E = (c.get(x.id) || 0) * $;
|
|
58
|
+
a.set(x.id, {
|
|
59
|
+
node: x,
|
|
60
|
+
color: x.color || R[d.indexOf(x) % R.length],
|
|
61
|
+
depth: r,
|
|
62
|
+
value: c.get(x.id) || 0,
|
|
63
|
+
x: u,
|
|
64
|
+
y: O,
|
|
65
|
+
h: E
|
|
66
|
+
}), O += E + v;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
const S = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), z = [...[...h].sort(
|
|
70
|
+
(e, r) => (a.get(e.target)?.y ?? 0) - (a.get(r.target)?.y ?? 0)
|
|
71
|
+
).map((e) => {
|
|
72
|
+
const r = a.get(e.source), u = S.get(e.source) ?? 0, s = e.value * $;
|
|
73
|
+
return S.set(e.source, u + s), { link: e, y0: (r?.y ?? 0) + u, w: s };
|
|
74
|
+
})].sort(
|
|
75
|
+
(e, r) => (a.get(e.link.source)?.y ?? 0) - (a.get(r.link.source)?.y ?? 0)
|
|
76
|
+
).map((e) => {
|
|
77
|
+
const r = a.get(e.link.target), u = D.get(e.link.target) ?? 0;
|
|
78
|
+
return D.set(e.link.target, u + e.w), { ...e, y1: (r?.y ?? 0) + u };
|
|
32
79
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
E.set(t.id, 0), _.set(t.id, 0);
|
|
37
|
-
}), /* @__PURE__ */ l(
|
|
80
|
+
return { placed: a, flows: z };
|
|
81
|
+
}, [d, h, j, I, v, g, y.left, y.top]);
|
|
82
|
+
return /* @__PURE__ */ m(
|
|
38
83
|
"div",
|
|
39
84
|
{
|
|
40
|
-
className: `nice-sankey ${
|
|
41
|
-
style:
|
|
42
|
-
"data-testid":
|
|
43
|
-
children: /* @__PURE__ */
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
className: `nice-sankey ${T || ""}`,
|
|
86
|
+
style: U,
|
|
87
|
+
"data-testid": Z ?? Y,
|
|
88
|
+
children: /* @__PURE__ */ N(
|
|
89
|
+
"svg",
|
|
90
|
+
{
|
|
91
|
+
width: n,
|
|
92
|
+
height: k,
|
|
93
|
+
viewBox: `0 0 ${n} ${k}`,
|
|
94
|
+
style: { maxWidth: "100%", height: "auto" },
|
|
95
|
+
children: [
|
|
96
|
+
o && /* @__PURE__ */ m("text", { x: n / 2, y: 22, textAnchor: "middle", className: "nice-chart__title", children: o }),
|
|
97
|
+
M && /* @__PURE__ */ m("defs", { children: f.flows.map((t, l) => {
|
|
98
|
+
const c = f.placed.get(t.link.source), i = f.placed.get(t.link.target);
|
|
99
|
+
return !c || !i || t.link.color ? null : /* @__PURE__ */ N(
|
|
100
|
+
"linearGradient",
|
|
101
|
+
{
|
|
102
|
+
id: `${B}-g${l}`,
|
|
103
|
+
gradientUnits: "userSpaceOnUse",
|
|
104
|
+
x1: c.x + g,
|
|
105
|
+
x2: i.x,
|
|
106
|
+
y1: 0,
|
|
107
|
+
y2: 0,
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ m("stop", { offset: "0%", stopColor: c.color }),
|
|
110
|
+
/* @__PURE__ */ m("stop", { offset: "100%", stopColor: i.color })
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
l
|
|
114
|
+
);
|
|
115
|
+
}) }),
|
|
116
|
+
f.flows.map((t, l) => {
|
|
117
|
+
const c = f.placed.get(t.link.source), i = f.placed.get(t.link.target);
|
|
118
|
+
if (!c || !i)
|
|
119
|
+
return null;
|
|
120
|
+
const w = c.x + g, $ = i.x, a = (w + $) / 2, S = t.link.color ?? (M ? `url(#${B}-g${l})` : c.color);
|
|
121
|
+
return /* @__PURE__ */ m(
|
|
122
|
+
"path",
|
|
123
|
+
{
|
|
124
|
+
className: "nice-sankey__link",
|
|
125
|
+
d: `M${w},${t.y0} C${a},${t.y0} ${a},${t.y1} ${$},${t.y1} L${$},${t.y1 + t.w} C${a},${t.y1 + t.w} ${a},${t.y0 + t.w} ${w},${t.y0 + t.w} Z`,
|
|
126
|
+
fill: S,
|
|
127
|
+
fillOpacity: 0.45,
|
|
128
|
+
onClick: C ? () => C(t.link) : void 0,
|
|
129
|
+
style: C ? { cursor: "pointer" } : void 0,
|
|
130
|
+
children: p && /* @__PURE__ */ m("title", { children: `${b(c.node)} → ${b(i.node)}: ${t.link.value}` })
|
|
131
|
+
},
|
|
132
|
+
l
|
|
133
|
+
);
|
|
134
|
+
}),
|
|
135
|
+
[...f.placed.values()].map((t) => {
|
|
136
|
+
const l = t.x + g / 2 > n / 2;
|
|
137
|
+
return /* @__PURE__ */ N("g", { children: [
|
|
138
|
+
/* @__PURE__ */ m(
|
|
139
|
+
"rect",
|
|
140
|
+
{
|
|
141
|
+
x: t.x,
|
|
142
|
+
y: t.y,
|
|
143
|
+
width: g,
|
|
144
|
+
height: Math.max(t.h, 2),
|
|
145
|
+
fill: t.color,
|
|
146
|
+
onClick: A ? () => A(t.node) : void 0,
|
|
147
|
+
style: A ? { cursor: "pointer" } : void 0,
|
|
148
|
+
children: p && /* @__PURE__ */ m("title", { children: `${b(t.node)}: ${t.value}` })
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
/* @__PURE__ */ N(
|
|
152
|
+
"text",
|
|
153
|
+
{
|
|
154
|
+
x: l ? t.x - 6 : t.x + g + 6,
|
|
155
|
+
y: t.y + t.h / 2,
|
|
156
|
+
textAnchor: l ? "end" : "start",
|
|
157
|
+
dominantBaseline: "middle",
|
|
158
|
+
className: "nice-sankey__label",
|
|
159
|
+
children: [
|
|
160
|
+
b(t.node),
|
|
161
|
+
_ ? ` (${t.value})` : ""
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
] }, t.node.id);
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
)
|
|
97
170
|
}
|
|
98
171
|
);
|
|
99
172
|
};
|
|
100
173
|
export {
|
|
101
|
-
|
|
174
|
+
W as NiceSankey
|
|
102
175
|
};
|