@rudra-studio/rudra-charts 1.0.1

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 (42) hide show
  1. package/README.md +7 -0
  2. package/components/AnimatedLineChart/index.d.ts +29 -0
  3. package/components/AnimatedLineChart/index.js +109 -0
  4. package/components/BubbleChart/index.d.ts +24 -0
  5. package/components/BubbleChart/index.js +126 -0
  6. package/components/CandleStickChart/index.d.ts +24 -0
  7. package/components/CandleStickChart/index.js +116 -0
  8. package/components/DonutChart/index.d.ts +19 -0
  9. package/components/DonutChart/index.js +77 -0
  10. package/components/FunnelChart/index.d.ts +22 -0
  11. package/components/FunnelChart/index.js +105 -0
  12. package/components/GaugeChart/index.d.ts +25 -0
  13. package/components/GaugeChart/index.js +85 -0
  14. package/components/HeatMap/index.d.ts +24 -0
  15. package/components/HeatMap/index.js +146 -0
  16. package/components/Histogram/index.d.ts +20 -0
  17. package/components/Histogram/index.js +158 -0
  18. package/components/HorizontalBarChart/index.d.ts +22 -0
  19. package/components/HorizontalBarChart/index.js +82 -0
  20. package/components/HundredPercentBarChart/index.d.ts +21 -0
  21. package/components/HundredPercentBarChart/index.js +96 -0
  22. package/components/MultiLineChart/index.d.ts +21 -0
  23. package/components/MultiLineChart/index.js +128 -0
  24. package/components/PipelineChart/index.d.ts +26 -0
  25. package/components/PipelineChart/index.js +174 -0
  26. package/components/ScatterPlot/index.d.ts +23 -0
  27. package/components/ScatterPlot/index.js +118 -0
  28. package/components/SpiderChart/index.d.ts +27 -0
  29. package/components/SpiderChart/index.js +169 -0
  30. package/components/StackedArea/index.d.ts +22 -0
  31. package/components/StackedArea/index.js +101 -0
  32. package/components/StackedBarChart/index.d.ts +21 -0
  33. package/components/StackedBarChart/index.js +96 -0
  34. package/components/TreeMap/index.d.ts +19 -0
  35. package/components/TreeMap/index.js +137 -0
  36. package/components/VerticalBarChart/index.d.ts +21 -0
  37. package/components/VerticalBarChart/index.js +97 -0
  38. package/components/WaterfallChart/index.d.ts +26 -0
  39. package/components/WaterfallChart/index.js +147 -0
  40. package/index.d.ts +38 -0
  41. package/index.js +23 -0
  42. package/package.json +46 -0
@@ -0,0 +1,169 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import * as r from "d3";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ //#region src/components/SpiderChart/index.tsx
5
+ var a = ({ data: a = [
6
+ {
7
+ id: 1,
8
+ category: "Warrior",
9
+ axes: [
10
+ {
11
+ axis: "Strength",
12
+ value: 95
13
+ },
14
+ {
15
+ axis: "Agility",
16
+ value: 30
17
+ },
18
+ {
19
+ axis: "Intelligence",
20
+ value: 20
21
+ },
22
+ {
23
+ axis: "Charisma",
24
+ value: 50
25
+ },
26
+ {
27
+ axis: "Defense",
28
+ value: 85
29
+ },
30
+ {
31
+ axis: "Magic",
32
+ value: 10
33
+ }
34
+ ]
35
+ },
36
+ {
37
+ id: 2,
38
+ category: "Mage",
39
+ axes: [
40
+ {
41
+ axis: "Strength",
42
+ value: 15
43
+ },
44
+ {
45
+ axis: "Agility",
46
+ value: 40
47
+ },
48
+ {
49
+ axis: "Intelligence",
50
+ value: 100
51
+ },
52
+ {
53
+ axis: "Charisma",
54
+ value: 60
55
+ },
56
+ {
57
+ axis: "Defense",
58
+ value: 30
59
+ },
60
+ {
61
+ axis: "Magic",
62
+ value: 95
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ id: 3,
68
+ category: "Rogue",
69
+ axes: [
70
+ {
71
+ axis: "Strength",
72
+ value: 50
73
+ },
74
+ {
75
+ axis: "Agility",
76
+ value: 90
77
+ },
78
+ {
79
+ axis: "Intelligence",
80
+ value: 60
81
+ },
82
+ {
83
+ axis: "Charisma",
84
+ value: 85
85
+ },
86
+ {
87
+ axis: "Defense",
88
+ value: 40
89
+ },
90
+ {
91
+ axis: "Magic",
92
+ value: 25
93
+ }
94
+ ]
95
+ }
96
+ ], themeColors: o = [
97
+ "#ef4444",
98
+ "#3b82f6",
99
+ "#10b981",
100
+ "#f59e0b",
101
+ "#8b5cf6"
102
+ ], gridLevels: s = 5, maxValue: c, marginTop: l = 40, marginBottom: u = 40, marginLeft: d = 40, marginRight: f = 40, className: p = "" }) => {
103
+ let m = t(null), h = t(null), [g, _] = n({
104
+ width: 0,
105
+ height: 400
106
+ });
107
+ return e(() => {
108
+ let e = m.current;
109
+ if (!e) return;
110
+ let t = new ResizeObserver((e) => {
111
+ e[0] && _({
112
+ width: e[0].contentRect.width,
113
+ height: e[0].contentRect.height || 400
114
+ });
115
+ });
116
+ return t.observe(e), () => t.unobserve(e);
117
+ }, []), e(() => {
118
+ if (!h.current || g.width === 0 || a.length === 0) return;
119
+ let { width: e, height: t } = g, n = r.select(h.current), i = e / 2, p = t / 2, m = Math.min((e - d - f) / 2, (t - l - u) / 2), _ = a[0].axes.map((e) => e.axis), v = _.length, y = Math.PI * 2 / v, b = r.max(a, (e) => r.max(e.axes, (e) => e.value)) || 100, x = c === void 0 ? b : c, S = r.scaleLinear().domain([0, x]).range([0, m]), C = r.scaleOrdinal().domain(a.map((e) => e.category)).range(o), w = n.select(".radar-group");
120
+ w.empty() && (w = n.append("g").attr("class", "radar-group")), w.attr("transform", `translate(${i},${p})`);
121
+ let T = w.select(".grid-group");
122
+ T.empty() && (T = w.append("g").attr("class", "grid-group"));
123
+ let E = r.range(1, s + 1).reverse(), D = T.selectAll(".grid-polygon").data(E);
124
+ D.exit().remove(), D.enter().append("polygon").attr("class", "grid-polygon").attr("fill", "#f8fafc").attr("stroke", "#cbd5e1").attr("stroke-width", 1).merge(D).transition().duration(500).attr("points", (e) => {
125
+ let t = S(e / s * x);
126
+ return _.map((e, n) => {
127
+ let r = y * n - Math.PI / 2;
128
+ return `${t * Math.cos(r)},${t * Math.sin(r)}`;
129
+ }).join(" ");
130
+ });
131
+ let O = T.selectAll(".grid-line").data(_);
132
+ O.exit().remove(), O.enter().append("line").attr("class", "grid-line").attr("stroke", "#cbd5e1").attr("stroke-width", 1).merge(O).transition().duration(500).attr("x1", 0).attr("y1", 0).attr("x2", (e, t) => S(x) * Math.cos(y * t - Math.PI / 2)).attr("y2", (e, t) => S(x) * Math.sin(y * t - Math.PI / 2));
133
+ let k = w.select(".labels-group");
134
+ k.empty() && (k = w.append("g").attr("class", "labels-group"));
135
+ let A = k.selectAll(".axis-label").data(_);
136
+ A.exit().remove(), A.enter().append("text").attr("class", "axis-label").attr("font-size", "12px").attr("font-weight", "600").attr("font-family", "ui-sans-serif, system-ui").attr("fill", "#475569").attr("text-anchor", "middle").attr("alignment-baseline", "middle").merge(A).transition().duration(500).attr("x", (e, t) => (S(x) + 20) * Math.cos(y * t - Math.PI / 2)).attr("y", (e, t) => (S(x) + 20) * Math.sin(y * t - Math.PI / 2)).text((e) => e);
137
+ let j = r.lineRadial().curve(r.curveLinearClosed).angle((e, t) => t * y).radius((e) => S(e.value)), M = r.lineRadial().curve(r.curveLinearClosed).angle((e, t) => t * y).radius(0), N = w.select(".blobs-group");
138
+ N.empty() && (N = w.append("g").attr("class", "blobs-group"));
139
+ let P = N.selectAll(".radar-blob").data(a, (e) => e.id);
140
+ P.exit().transition().duration(300).attr("d", (e) => M(e.axes)).attr("opacity", 0).remove();
141
+ let F = P.enter().append("path").attr("class", "radar-blob").attr("d", (e) => M(e.axes)).attr("fill", (e) => C(e.category)).attr("fill-opacity", .2).attr("stroke", (e) => C(e.category)).attr("stroke-width", 2.5).style("cursor", "pointer");
142
+ F.transition().duration(800).delay((e, t) => t * 150).ease(r.easeBackOut.overshoot(1.1)).attr("d", (e) => j(e.axes)), P.transition().duration(750).ease(r.easeCubicOut).attr("d", (e) => j(e.axes)).attr("fill", (e) => C(e.category)).attr("stroke", (e) => C(e.category)), F.merge(P).on("mouseenter", function() {
143
+ N.selectAll(".radar-blob").transition().duration(200).attr("fill-opacity", .05).attr("stroke-opacity", .2), r.select(this).raise().transition().duration(200).attr("fill-opacity", .6).attr("stroke-opacity", 1).attr("stroke-width", 4);
144
+ }).on("mouseleave", function() {
145
+ N.selectAll(".radar-blob").transition().duration(200).attr("fill-opacity", .2).attr("stroke-opacity", 1).attr("stroke-width", 2.5);
146
+ });
147
+ }, [
148
+ a,
149
+ g,
150
+ s,
151
+ c,
152
+ o,
153
+ l,
154
+ u,
155
+ d,
156
+ f
157
+ ]), /* @__PURE__ */ i("div", {
158
+ ref: m,
159
+ className: `w-full min-h-[400px] h-full relative ${p}`,
160
+ children: /* @__PURE__ */ i("svg", {
161
+ ref: h,
162
+ width: "100%",
163
+ height: "100%",
164
+ className: "block absolute inset-0 overflow-visible"
165
+ })
166
+ });
167
+ };
168
+ //#endregion
169
+ export { a as default };
@@ -0,0 +1,22 @@
1
+ import { default as React } from 'react';
2
+ export interface StackedAreaDataPoint {
3
+ x: string;
4
+ [key: string]: any;
5
+ }
6
+ export interface AnimatedStackedAreaChartProps {
7
+ /** The dataset */
8
+ data?: StackedAreaDataPoint[];
9
+ /** The keys inside the data objects that should be stacked on top of each other */
10
+ keys?: string[];
11
+ /** Line curve style */
12
+ curveType?: 'linear' | 'smooth' | 'step';
13
+ /** Default palette for the stacked layers */
14
+ themeColors?: string[];
15
+ marginTop?: number;
16
+ marginBottom?: number;
17
+ marginLeft?: number;
18
+ marginRight?: number;
19
+ className?: string;
20
+ }
21
+ export declare const AnimatedStackedAreaChart: React.FC<AnimatedStackedAreaChartProps>;
22
+ export default AnimatedStackedAreaChart;
@@ -0,0 +1,101 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import * as r from "d3";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ //#region src/components/StackedArea/index.tsx
5
+ var a = ({ data: a = [
6
+ {
7
+ x: "Jan",
8
+ Mobile: 30,
9
+ Desktop: 20,
10
+ Tablet: 10
11
+ },
12
+ {
13
+ x: "Feb",
14
+ Mobile: 40,
15
+ Desktop: 30,
16
+ Tablet: 15
17
+ },
18
+ {
19
+ x: "Mar",
20
+ Mobile: 35,
21
+ Desktop: 45,
22
+ Tablet: 25
23
+ },
24
+ {
25
+ x: "Apr",
26
+ Mobile: 50,
27
+ Desktop: 40,
28
+ Tablet: 30
29
+ },
30
+ {
31
+ x: "May",
32
+ Mobile: 65,
33
+ Desktop: 55,
34
+ Tablet: 40
35
+ }
36
+ ], keys: o = [
37
+ "Mobile",
38
+ "Desktop",
39
+ "Tablet"
40
+ ], curveType: s = "smooth", themeColors: c = [
41
+ "#3b82f6",
42
+ "#10b981",
43
+ "#f59e0b",
44
+ "#ef4444",
45
+ "#8b5cf6"
46
+ ], marginTop: l = 20, marginBottom: u = 30, marginLeft: d = 50, marginRight: f = 20, className: p = "" }) => {
47
+ let m = t(null), h = t(null), [g, _] = n({
48
+ width: 0,
49
+ height: 300
50
+ });
51
+ return e(() => {
52
+ let e = m.current;
53
+ if (!e) return;
54
+ let t = new ResizeObserver((e) => {
55
+ e[0] && _({
56
+ width: e[0].contentRect.width,
57
+ height: e[0].contentRect.height || 300
58
+ });
59
+ });
60
+ return t.observe(e), () => t.unobserve(e);
61
+ }, []), e(() => {
62
+ if (!h.current || g.width === 0 || a.length === 0 || o.length === 0) return;
63
+ let { width: e, height: t } = g, n = r.select(h.current), i = r.stack().keys(o)(a), p = r.max(i, (e) => r.max(e, (e) => e[1])) || 100, m = a.map((e) => e.x), _ = r.scalePoint().domain(m).range([d, e - f]).padding(0), v = r.scaleLinear().domain([0, p]).nice().range([t - u, l]), y = r.scaleOrdinal().domain(o).range(c), b = r.area().x((e) => _(e.data.x)).y0((e) => v(e[0])).y1((e) => v(e[1]));
64
+ s === "smooth" ? b.curve(r.curveMonotoneX) : s === "step" ? b.curve(r.curveStepAfter) : b.curve(r.curveLinear), n.select(".x-axis").empty() && (n.append("g").attr("class", "axis x-axis"), n.append("g").attr("class", "axis y-axis")), n.select(".x-axis").attr("transform", `translate(0,${t - u})`).transition().duration(500).call(r.axisBottom(_)).attr("font-size", "12px").attr("font-family", "ui-sans-serif, system-ui").attr("color", "#64748b"), n.select(".y-axis").attr("transform", `translate(${d},0)`).transition().duration(500).call(r.axisLeft(v).ticks(6)).attr("font-size", "12px").attr("font-family", "ui-sans-serif, system-ui").attr("color", "#64748b").call((e) => e.select(".domain").remove()).call((t) => t.selectAll(".tick line").attr("x2", e - d - f).attr("stroke-opacity", .1));
65
+ let x = n.select("defs");
66
+ x.empty() && (x = n.append("defs"));
67
+ let S = x.select("#area-clip");
68
+ S.empty() && (S = x.append("clipPath").attr("id", "area-clip"), S.append("rect").attr("x", d).attr("y", 0).attr("width", 0).attr("height", t)), S.select("rect").transition().duration(1200).ease(r.easeCubicInOut).attr("width", e - d);
69
+ let C = n.select(".areas-group");
70
+ C.empty() && (C = n.append("g").attr("class", "areas-group").attr("clip-path", "url(#area-clip)"));
71
+ let w = C.selectAll(".area-layer").data(i, (e) => e.key);
72
+ w.exit().transition().duration(400).style("opacity", 0).remove();
73
+ let T = w.enter().append("path").attr("class", "area-layer").attr("fill", (e) => y(e.key)).attr("opacity", .8).attr("d", b);
74
+ T.on("mouseenter", function() {
75
+ C.selectAll(".area-layer").transition().duration(200).attr("opacity", .2), r.select(this).transition().duration(200).attr("opacity", 1);
76
+ }).on("mouseleave", function() {
77
+ C.selectAll(".area-layer").transition().duration(200).attr("opacity", .8);
78
+ }), T.merge(w).transition().duration(750).ease(r.easeCubicOut).attr("d", b).attr("fill", (e) => y(e.key));
79
+ }, [
80
+ a,
81
+ o,
82
+ g,
83
+ s,
84
+ c,
85
+ l,
86
+ u,
87
+ d,
88
+ f
89
+ ]), /* @__PURE__ */ i("div", {
90
+ ref: m,
91
+ className: `w-full min-h-[300px] h-full relative ${p}`,
92
+ children: /* @__PURE__ */ i("svg", {
93
+ ref: h,
94
+ width: "100%",
95
+ height: "100%",
96
+ className: "block absolute inset-0 overflow-visible"
97
+ })
98
+ });
99
+ };
100
+ //#endregion
101
+ export { a as default };
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ export interface StackedBarDataPoint {
3
+ id: string | number;
4
+ category: string;
5
+ [key: string]: any;
6
+ }
7
+ export interface AnimatedStackedBarChartProps {
8
+ /** The dataset containing the categories and their sub-components. */
9
+ data?: StackedBarDataPoint[];
10
+ /** The exact keys in the data objects that should be stacked on top of each other. */
11
+ stackKeys?: string[];
12
+ /** Default palette for the stacked layers */
13
+ themeColors?: string[];
14
+ marginTop?: number;
15
+ marginBottom?: number;
16
+ marginLeft?: number;
17
+ marginRight?: number;
18
+ className?: string;
19
+ }
20
+ export declare const AnimatedStackedBarChart: React.FC<AnimatedStackedBarChartProps>;
21
+ export default AnimatedStackedBarChart;
@@ -0,0 +1,96 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import * as r from "d3";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ //#region src/components/StackedBarChart/index.tsx
5
+ var a = ({ data: a = [
6
+ {
7
+ id: "1",
8
+ category: "Q1",
9
+ mobile: 120,
10
+ desktop: 80,
11
+ tablet: 40
12
+ },
13
+ {
14
+ id: "2",
15
+ category: "Q2",
16
+ mobile: 150,
17
+ desktop: 90,
18
+ tablet: 30
19
+ },
20
+ {
21
+ id: "3",
22
+ category: "Q3",
23
+ mobile: 180,
24
+ desktop: 110,
25
+ tablet: 50
26
+ },
27
+ {
28
+ id: "4",
29
+ category: "Q4",
30
+ mobile: 240,
31
+ desktop: 140,
32
+ tablet: 60
33
+ }
34
+ ], stackKeys: o = [
35
+ "mobile",
36
+ "desktop",
37
+ "tablet"
38
+ ], themeColors: s = [
39
+ "#3b82f6",
40
+ "#10b981",
41
+ "#f59e0b",
42
+ "#ef4444",
43
+ "#8b5cf6"
44
+ ], marginTop: c = 20, marginBottom: l = 40, marginLeft: u = 50, marginRight: d = 20, className: f = "" }) => {
45
+ let p = t(null), m = t(null), [h, g] = n({
46
+ width: 0,
47
+ height: 350
48
+ });
49
+ return e(() => {
50
+ let e = p.current;
51
+ if (!e) return;
52
+ let t = new ResizeObserver((e) => {
53
+ e[0] && g({
54
+ width: e[0].contentRect.width,
55
+ height: e[0].contentRect.height || 350
56
+ });
57
+ });
58
+ return t.observe(e), () => t.unobserve(e);
59
+ }, []), e(() => {
60
+ if (!m.current || h.width === 0 || a.length === 0 || o.length === 0) return;
61
+ let { width: e, height: t } = h, n = r.select(m.current), i = r.stack().keys(o)(a), f = a.map((e) => e.category), p = r.max(i, (e) => r.max(e, (e) => e[1])) || 100, g = r.scaleBand().domain(f).range([u, e - d]).padding(.3), _ = r.scaleLinear().domain([0, p * 1.1]).nice().range([t - l, c]), v = r.scaleOrdinal().domain(o).range(s);
62
+ n.select(".x-axis").empty() && (n.append("g").attr("class", "axis x-axis"), n.append("g").attr("class", "axis y-axis")), n.select(".x-axis").attr("transform", `translate(0,${t - l})`).transition().duration(500).call(r.axisBottom(g).tickSizeOuter(0)).attr("font-size", "12px").attr("font-family", "ui-sans-serif, system-ui").attr("color", "#64748b").call((e) => e.select(".domain").remove()), n.select(".y-axis").attr("transform", `translate(${u},0)`).transition().duration(500).call(r.axisLeft(_).ticks(6).tickSize(-(e - u - d))).attr("font-size", "12px").attr("font-family", "ui-sans-serif, system-ui").attr("color", "#64748b").call((e) => e.select(".domain").remove()).call((e) => e.selectAll(".tick line").attr("stroke-opacity", .1).attr("stroke-dasharray", "4,4"));
63
+ let y = n.select(".stacks-group");
64
+ y.empty() && (y = n.append("g").attr("class", "stacks-group"));
65
+ let b = y.selectAll(".layer").data(i, (e) => e.key);
66
+ b.exit().remove();
67
+ let x = b.enter().append("g").attr("class", "layer").attr("fill", (e) => v(e.key)).merge(b).transition().duration(500).attr("fill", (e) => v(e.key)).selection().selectAll("rect").data((e) => e, (e) => e.data.id);
68
+ x.exit().transition().duration(300).attr("y", (e) => _(e[0])).attr("height", 0).remove();
69
+ let S = x.enter().append("rect").attr("x", (e) => g(e.data.category) || 0).attr("width", g.bandwidth()).attr("y", (e) => _(e[0])).attr("height", 0).style("cursor", "pointer");
70
+ S.transition().duration(700).delay((e, t) => t * 50).ease(r.easeCubicOut).attr("y", (e) => _(e[1])).attr("height", (e) => _(e[0]) - _(e[1])), x.transition().duration(750).ease(r.easeCubicOut).attr("x", (e) => g(e.data.category) || 0).attr("width", g.bandwidth()).attr("y", (e) => _(e[1])).attr("height", (e) => _(e[0]) - _(e[1])), S.merge(x).on("mouseenter", function() {
71
+ y.selectAll("rect").transition().duration(200).attr("opacity", .4), r.select(this).transition().duration(200).attr("opacity", 1).attr("stroke", "#fff").attr("stroke-width", 2);
72
+ }).on("mouseleave", function() {
73
+ y.selectAll("rect").transition().duration(200).attr("opacity", 1).attr("stroke", "none");
74
+ });
75
+ }, [
76
+ a,
77
+ o,
78
+ h,
79
+ s,
80
+ c,
81
+ l,
82
+ u,
83
+ d
84
+ ]), /* @__PURE__ */ i("div", {
85
+ ref: p,
86
+ className: `w-full min-h-[350px] h-full relative ${f}`,
87
+ children: /* @__PURE__ */ i("svg", {
88
+ ref: m,
89
+ width: "100%",
90
+ height: "100%",
91
+ className: "block absolute inset-0 overflow-visible"
92
+ })
93
+ });
94
+ };
95
+ //#endregion
96
+ export { a as default };
@@ -0,0 +1,19 @@
1
+ import { default as React } from 'react';
2
+ export interface TreemapDataNode {
3
+ name: string;
4
+ value?: number;
5
+ children?: TreemapDataNode[];
6
+ }
7
+ export interface AnimatedTreemapProps {
8
+ /** The hierarchical dataset (must have a single root node) */
9
+ data?: TreemapDataNode;
10
+ /** Default palette mapped to the top-level categories */
11
+ themeColors?: string[];
12
+ marginTop?: number;
13
+ marginBottom?: number;
14
+ marginLeft?: number;
15
+ marginRight?: number;
16
+ className?: string;
17
+ }
18
+ export declare const AnimatedTreemap: React.FC<AnimatedTreemapProps>;
19
+ export default AnimatedTreemap;
@@ -0,0 +1,137 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import * as r from "d3";
3
+ import { jsx as i } from "react/jsx-runtime";
4
+ //#region src/components/TreeMap/index.tsx
5
+ var a = ({ data: a = {
6
+ name: "Root",
7
+ children: [
8
+ {
9
+ name: "Marketing",
10
+ children: [
11
+ {
12
+ name: "Social Media",
13
+ value: 250
14
+ },
15
+ {
16
+ name: "SEO",
17
+ value: 150
18
+ },
19
+ {
20
+ name: "Events",
21
+ value: 300
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ name: "Engineering",
27
+ children: [
28
+ {
29
+ name: "Frontend",
30
+ value: 400
31
+ },
32
+ {
33
+ name: "Backend",
34
+ value: 350
35
+ },
36
+ {
37
+ name: "DevOps",
38
+ value: 200
39
+ },
40
+ {
41
+ name: "QA",
42
+ value: 100
43
+ }
44
+ ]
45
+ },
46
+ {
47
+ name: "Sales",
48
+ children: [{
49
+ name: "Enterprise",
50
+ value: 500
51
+ }, {
52
+ name: "SMB",
53
+ value: 250
54
+ }]
55
+ },
56
+ {
57
+ name: "HR",
58
+ children: [{
59
+ name: "Recruiting",
60
+ value: 120
61
+ }, {
62
+ name: "Benefits",
63
+ value: 80
64
+ }]
65
+ }
66
+ ]
67
+ }, themeColors: o = [
68
+ "#3b82f6",
69
+ "#10b981",
70
+ "#f59e0b",
71
+ "#ef4444",
72
+ "#8b5cf6",
73
+ "#06b6d4"
74
+ ], marginTop: s = 10, marginBottom: c = 10, marginLeft: l = 10, marginRight: u = 10, className: d = "" }) => {
75
+ let f = t(null), p = t(null), [m, h] = n({
76
+ width: 0,
77
+ height: 400
78
+ });
79
+ return e(() => {
80
+ let e = f.current;
81
+ if (!e) return;
82
+ let t = new ResizeObserver((e) => {
83
+ e[0] && h({
84
+ width: e[0].contentRect.width,
85
+ height: e[0].contentRect.height || 400
86
+ });
87
+ });
88
+ return t.observe(e), () => t.unobserve(e);
89
+ }, []), e(() => {
90
+ if (!p.current || m.width === 0 || !a) return;
91
+ let { width: e, height: t } = m, n = r.select(p.current), i = e - l - u, d = t - s - c, f = r.hierarchy(a).sum((e) => e.value || 0).sort((e, t) => (t.value || 0) - (e.value || 0));
92
+ r.treemap().size([i, d]).paddingInner(2).paddingOuter(2).paddingTop(24).round(!0)(f);
93
+ let h = f.children ? f.children.map((e) => e.data.name) : [], g = r.scaleOrdinal().domain(h).range(o), _ = n.select(".chart-group");
94
+ _.empty() && (_ = n.append("g").attr("class", "chart-group")), _.attr("transform", `translate(${l},${s})`);
95
+ let v = f.descendants().filter((e) => e.depth === 1), y = _.select(".parents-group");
96
+ y.empty() && (y = _.append("g").attr("class", "parents-group"));
97
+ let b = y.selectAll(".parent-node").data(v, (e) => e.data.name);
98
+ b.exit().remove();
99
+ let x = b.enter().append("g").attr("class", "parent-node").attr("transform", (e) => `translate(${e.x0},${e.y0})`);
100
+ x.append("text").attr("class", "parent-label").attr("x", 4).attr("y", 16).attr("font-size", "13px").attr("font-weight", "700").attr("font-family", "ui-sans-serif, system-ui").attr("fill", "#475569").style("opacity", 0).text((e) => e.data.name), x.merge(b).transition().duration(750).ease(r.easeCubicOut).attr("transform", (e) => `translate(${e.x0},${e.y0})`).select(".parent-label").style("opacity", 1).text((e) => e.data.name);
101
+ let S = f.leaves(), C = _.select(".leaves-group");
102
+ C.empty() && (C = _.append("g").attr("class", "leaves-group"));
103
+ let w = C.selectAll(".leaf-node").data(S, (e) => e.data.name);
104
+ w.exit().transition().duration(300).style("opacity", 0).remove();
105
+ let T = w.enter().append("g").attr("class", "leaf-node").attr("transform", (e) => `translate(${e.x0},${e.y0})`);
106
+ T.append("rect").attr("class", "leaf-rect").attr("width", (e) => e.x1 - e.x0).attr("height", (e) => e.y1 - e.y0).attr("fill", (e) => {
107
+ let t = e;
108
+ for (; t.depth > 1 && t.parent;) t = t.parent;
109
+ return g(t.data.name);
110
+ }).attr("rx", 4).style("opacity", 0).style("cursor", "pointer"), T.append("text").attr("class", "leaf-label").attr("x", 6).attr("y", 18).attr("font-size", "11px").attr("font-weight", "500").attr("font-family", "ui-sans-serif, system-ui").attr("fill", "#ffffff").style("opacity", 0).text((e) => e.x1 - e.x0 > 50 && e.y1 - e.y0 > 24 ? e.data.name : ""), T.append("text").attr("class", "leaf-value").attr("x", 6).attr("y", 32).attr("font-size", "10px").attr("font-family", "ui-sans-serif, system-ui").attr("fill", "#f8fafc").style("opacity", 0).text((e) => e.x1 - e.x0 > 50 && e.y1 - e.y0 > 40 ? e.value : ""), T.select(".leaf-rect").transition().duration(600).delay((e, t) => t * 30).ease(r.easeCubicOut).style("opacity", .85), T.selectAll("text").transition().duration(600).delay((e, t) => t * 30 + 300).style("opacity", 1);
111
+ let E = T.merge(w);
112
+ E.transition().duration(750).ease(r.easeCubicOut).attr("transform", (e) => `translate(${e.x0},${e.y0})`), E.select(".leaf-rect").transition().duration(750).ease(r.easeCubicOut).attr("width", (e) => Math.max(0, e.x1 - e.x0)).attr("height", (e) => Math.max(0, e.y1 - e.y0)), E.select(".leaf-label").text((e) => e.x1 - e.x0 > 50 && e.y1 - e.y0 > 24 ? e.data.name : ""), E.select(".leaf-value").text((e) => e.x1 - e.x0 > 50 && e.y1 - e.y0 > 40 ? e.value : ""), E.on("mouseenter", function() {
113
+ C.selectAll(".leaf-rect").transition().duration(200).style("opacity", .4), r.select(this).select(".leaf-rect").transition().duration(200).style("opacity", 1).attr("filter", "brightness(1.1)");
114
+ }).on("mouseleave", function() {
115
+ C.selectAll(".leaf-rect").transition().duration(200).style("opacity", .85).attr("filter", "none");
116
+ });
117
+ }, [
118
+ a,
119
+ m,
120
+ o,
121
+ s,
122
+ c,
123
+ l,
124
+ u
125
+ ]), /* @__PURE__ */ i("div", {
126
+ ref: f,
127
+ className: `w-full min-h-[400px] h-full relative ${d}`,
128
+ children: /* @__PURE__ */ i("svg", {
129
+ ref: p,
130
+ width: "100%",
131
+ height: "100%",
132
+ className: "block absolute inset-0 overflow-visible"
133
+ })
134
+ });
135
+ };
136
+ //#endregion
137
+ export { a as default };
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ export interface ColumnDataPoint {
3
+ id: string | number;
4
+ category: string;
5
+ value: number;
6
+ }
7
+ export interface AnimatedVerticalBarChartProps {
8
+ /** The categorical dataset. */
9
+ data?: ColumnDataPoint[];
10
+ /** Default palette for the bars */
11
+ themeColors?: string[];
12
+ /** Show the exact number on top of each bar */
13
+ showValues?: boolean;
14
+ marginTop?: number;
15
+ marginBottom?: number;
16
+ marginLeft?: number;
17
+ marginRight?: number;
18
+ className?: string;
19
+ }
20
+ export declare const AnimatedVerticalBarChart: React.FC<AnimatedVerticalBarChartProps>;
21
+ export default AnimatedVerticalBarChart;