@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +2 -4
  3. package/dist/NiceModuleLifecyclePanel-bsHwj1pO.cjs +1 -0
  4. package/dist/{NicePivotGrid-B5Fgi5E_.cjs → NicePivotGrid-D53CQ2cY.cjs} +1 -1
  5. package/dist/{NiceStreamDashboard.doc-74KUXya1.cjs → NiceStreamDashboard.doc-CdkHFf4Y.cjs} +2 -2
  6. package/dist/charts/NiceAdvancedCharts.mjs +586 -773
  7. package/dist/charts/NiceChartRangeSelector.mjs +159 -0
  8. package/dist/charts/NiceHeatMap.mjs +140 -70
  9. package/dist/charts/NiceOrganizationChart.mjs +183 -90
  10. package/dist/charts/NiceSankey.mjs +166 -93
  11. package/dist/charts/NiceStockChart.mjs +258 -157
  12. package/dist/charts-CSgOgfES.cjs +867 -0
  13. package/dist/charts.cjs +1 -1
  14. package/dist/charts.d.ts +126 -102
  15. package/dist/charts.mjs +22 -24
  16. package/dist/core/lazy.mjs +50 -63
  17. package/dist/core-lazy-sO0xvg64.cjs +1 -0
  18. package/dist/data.cjs +1 -1
  19. package/dist/demo/docs/docPreviews.mjs +504 -546
  20. package/dist/demo/docs/docRegistry.mjs +9 -94
  21. package/dist/docs/NiceStreamDashboard.doc.json.mjs +1 -1
  22. package/dist/documentation/utils.mjs +1 -1
  23. package/dist/index.cjs +95 -121
  24. package/dist/index.d.ts +126 -217
  25. package/dist/index.mjs +829 -836
  26. package/dist/lazy.cjs +1 -1
  27. package/dist/lazy.d.ts +41 -23
  28. package/dist/lazy.mjs +1 -1
  29. package/dist/navigation/NiceDock.mjs +55 -48
  30. package/dist/navigation/NiceMenuTypes.mjs +197 -251
  31. package/dist/navigation.cjs +1 -1
  32. package/dist/navigation.d.ts +5 -16
  33. package/dist/navigation.mjs +53 -54
  34. package/dist/style.css +2 -2
  35. package/dist/tools/NiceShowcase.mjs +2 -4
  36. package/package.json +4 -4
  37. package/dist/NiceDiagram.doc-CASS0Tnj.cjs +0 -8
  38. package/dist/NiceModuleLifecyclePanel-jckyVqqt.cjs +0 -1
  39. package/dist/charts/NiceRangeSelector.mjs +0 -135
  40. package/dist/charts/NiceTreeMap.mjs +0 -100
  41. package/dist/charts/NiceVectorMap.mjs +0 -59
  42. package/dist/charts-C9B548D2.cjs +0 -924
  43. package/dist/core-lazy-B54FdghB.cjs +0 -1
  44. package/dist/docs/NiceDiagram.doc.json.mjs +0 -32
  45. package/dist/tools/NiceChat.mjs +0 -98
@@ -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,102 +1,175 @@
1
- import { jsx as l, jsxs as L } from "react/jsx-runtime";
2
- import { CHART_COLORS as m } from "./colors.mjs";
3
- const Z = [], q = [], J = ({
4
- nodes: r = Z,
5
- links: i = q,
6
- width: p = 600,
7
- height: S = 400,
8
- nodeWidth: h = 20,
9
- nodePadding: C = 10,
10
- title: $,
11
- className: j,
12
- style: H,
13
- testId: P,
14
- "data-testid": R
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: $ ? 40 : 20, bottom: 20, left: 20, right: 20 }, y = p - a.left - a.right, T = S - a.top - a.bottom, V = new Set(i.map((t) => t.source)), M = new Set(i.map((t) => t.target)), Y = r.filter((t) => V.has(t.id) && !M.has(t.id)), B = r.filter((t) => M.has(t.id)), b = r.filter((t) => V.has(t.id) && M.has(t.id)), N = [Y, ...b.length ? [b] : [], B].filter(
17
- (t) => t.length > 0
18
- ), D = N.length, O = /* @__PURE__ */ new Map();
19
- r.forEach((t) => {
20
- const s = i.filter((c) => c.source === t.id).reduce((c, o) => c + o.value, 0), e = i.filter((c) => c.target === t.id).reduce((c, o) => c + o.value, 0);
21
- O.set(t.id, Math.max(s, e));
22
- });
23
- const K = N.map(
24
- (t) => t.reduce((s, e) => s + (O.get(e.id) || 0), 0) + (t.length - 1) * C
25
- ), A = Math.max(...K, 1), f = /* @__PURE__ */ new Map();
26
- N.forEach((t, s) => {
27
- const e = a.left + s / (D - 1 || 1) * (y - h);
28
- let c = 0;
29
- t.forEach((o) => {
30
- const d = (O.get(o.id) || 0) / A * T;
31
- f.set(o.id, { x: e, y: a.top + c, h: d }), c += d + C;
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
- const E = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
35
- return r.forEach((t) => {
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 ${j || ""}`,
41
- style: H,
42
- "data-testid": R ?? P,
43
- children: /* @__PURE__ */ L("svg", { width: p, height: S, children: [
44
- $ && /* @__PURE__ */ l("text", { x: p / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: $ }),
45
- i.map((t, s) => {
46
- const e = f.get(t.source), c = f.get(t.target);
47
- if (!e || !c)
48
- return null;
49
- const o = E.get(t.source) || 0, d = _.get(t.target) || 0, n = t.value / A * T;
50
- E.set(t.source, o + n), _.set(t.target, d + n);
51
- const v = e.x + h, u = e.y + o, w = c.x, x = c.y + d, g = (v + w) / 2, I = r.find((X) => X.id === t.source)?.color || m[s % m.length];
52
- return /* @__PURE__ */ l(
53
- "path",
54
- {
55
- d: `M${v},${u} C${g},${u} ${g},${x} ${w},${x} L${w},${x + n} C${g},${x + n} ${g},${u + n} ${v},${u + n} Z`,
56
- fill: I,
57
- fillOpacity: 0.3,
58
- stroke: I,
59
- strokeOpacity: 0.5,
60
- strokeWidth: 0.5,
61
- children: /* @__PURE__ */ l("title", { children: `${t.source} → ${t.target}: ${t.value}` })
62
- },
63
- s
64
- );
65
- }),
66
- r.map((t, s) => {
67
- const e = f.get(t.id);
68
- if (!e)
69
- return null;
70
- const c = t.color || m[s % m.length];
71
- return /* @__PURE__ */ L("g", { children: [
72
- /* @__PURE__ */ l(
73
- "rect",
74
- {
75
- x: e.x,
76
- y: e.y,
77
- width: h,
78
- height: Math.max(e.h, 2),
79
- fill: c,
80
- rx: 2
81
- }
82
- ),
83
- /* @__PURE__ */ l(
84
- "text",
85
- {
86
- x: e.x < y / 2 ? e.x + h + 4 : e.x - 4,
87
- y: e.y + e.h / 2,
88
- textAnchor: e.x < y / 2 ? "start" : "end",
89
- dominantBaseline: "middle",
90
- className: "nice-chart__legend-text",
91
- children: t.label
92
- }
93
- )
94
- ] }, t.id);
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
- J as NiceSankey
174
+ W as NiceSankey
102
175
  };