@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,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
  };