@aiconstructions/graficos 0.0.0-stage → 0.2.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 (267) hide show
  1. package/ALTERACOES.md +53 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +188 -2
  5. package/dist/aic/cores.js +83 -0
  6. package/dist/aic/index.js +22 -0
  7. package/dist/aic/interacao.js +55 -0
  8. package/dist/charts/animation.js +55 -0
  9. package/dist/charts/arc-geometry.js +58 -0
  10. package/dist/charts/arc-path.js +15 -0
  11. package/dist/charts/area-chart-loading.js +89 -0
  12. package/dist/charts/area-chart.js +149 -0
  13. package/dist/charts/area-gradient-defs.js +90 -0
  14. package/dist/charts/area-value-label-layout.js +70 -0
  15. package/dist/charts/area-value-labels.js +211 -0
  16. package/dist/charts/area.js +272 -0
  17. package/dist/charts/background.js +198 -0
  18. package/dist/charts/band-config.js +82 -0
  19. package/dist/charts/band-geometry.js +186 -0
  20. package/dist/charts/band.js +346 -0
  21. package/dist/charts/bar-chart-loading.js +27 -0
  22. package/dist/charts/bar-chart.js +545 -0
  23. package/dist/charts/bar-depth-geometry.js +18 -0
  24. package/dist/charts/bar-depth.js +608 -0
  25. package/dist/charts/bar-lollipop.js +278 -0
  26. package/dist/charts/bar-squares-layout.js +66 -0
  27. package/dist/charts/bar-squares.js +467 -0
  28. package/dist/charts/bar-value-label-layout.js +42 -0
  29. package/dist/charts/bar-x-axis.js +133 -0
  30. package/dist/charts/bar-y-axis.js +116 -0
  31. package/dist/charts/bar.js +457 -0
  32. package/dist/charts/bollinger.js +49 -0
  33. package/dist/charts/candlestick-chart.js +370 -0
  34. package/dist/charts/candlestick.js +368 -0
  35. package/dist/charts/chart-brush-handle.js +91 -0
  36. package/dist/charts/chart-brush-layout.js +91 -0
  37. package/dist/charts/chart-brush-selection-overlay.js +87 -0
  38. package/dist/charts/chart-brush-state.js +253 -0
  39. package/dist/charts/chart-brush-track-overlay.js +103 -0
  40. package/dist/charts/chart-brush.js +517 -0
  41. package/dist/charts/chart-center-typography.js +8 -0
  42. package/dist/charts/chart-child-passthrough.js +119 -0
  43. package/dist/charts/chart-config-context.js +56 -0
  44. package/dist/charts/chart-context.js +337 -0
  45. package/dist/charts/chart-crosshair.js +262 -0
  46. package/dist/charts/chart-data-override.js +186 -0
  47. package/dist/charts/chart-defs.js +56 -0
  48. package/dist/charts/chart-formatters.js +77 -0
  49. package/dist/charts/chart-legend-hover.js +27 -0
  50. package/dist/charts/chart-legend.js +163 -0
  51. package/dist/charts/chart-loading-label.js +52 -0
  52. package/dist/charts/chart-parent-size.js +138 -0
  53. package/dist/charts/chart-phase.js +29 -0
  54. package/dist/charts/chart-reveal-clip.js +62 -0
  55. package/dist/charts/chart-scale.js +19 -0
  56. package/dist/charts/chart-stat-flow.js +72 -0
  57. package/dist/charts/choropleth/choropleth-background.js +29 -0
  58. package/dist/charts/choropleth/choropleth-camera.js +379 -0
  59. package/dist/charts/choropleth/choropleth-chart.js +644 -0
  60. package/dist/charts/choropleth/choropleth-context.js +152 -0
  61. package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
  62. package/dist/charts/choropleth/choropleth-feature.js +291 -0
  63. package/dist/charts/choropleth/choropleth-graticule.js +40 -0
  64. package/dist/charts/choropleth/choropleth-marker.js +222 -0
  65. package/dist/charts/choropleth/choropleth-projection.js +37 -0
  66. package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
  67. package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
  68. package/dist/charts/choropleth/index.js +44 -0
  69. package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
  70. package/dist/charts/composed-chart.js +346 -0
  71. package/dist/charts/crosshair-store.js +49 -0
  72. package/dist/charts/dash-tail-stroke.js +58 -0
  73. package/dist/charts/date-pill-store.js +50 -0
  74. package/dist/charts/date-ranges.js +131 -0
  75. package/dist/charts/deadline.js +295 -0
  76. package/dist/charts/decimate-time-series.js +112 -0
  77. package/dist/charts/fade-edges.js +171 -0
  78. package/dist/charts/fast-path.js +78 -0
  79. package/dist/charts/filter-data-by-x-domain.js +45 -0
  80. package/dist/charts/funnel-chart.js +773 -0
  81. package/dist/charts/gauge-arc-layers.js +479 -0
  82. package/dist/charts/gauge-dial.js +329 -0
  83. package/dist/charts/gauge-label-layout.js +148 -0
  84. package/dist/charts/gauge.js +946 -0
  85. package/dist/charts/generate-chart-skeleton-data.js +27 -0
  86. package/dist/charts/gradients.js +158 -0
  87. package/dist/charts/grid-lines.js +114 -0
  88. package/dist/charts/grid.js +225 -0
  89. package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
  90. package/dist/charts/heatmap/heatmap-animation.js +128 -0
  91. package/dist/charts/heatmap/heatmap-cells.js +519 -0
  92. package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
  93. package/dist/charts/heatmap/heatmap-chart.js +548 -0
  94. package/dist/charts/heatmap/heatmap-colors.js +127 -0
  95. package/dist/charts/heatmap/heatmap-context.js +107 -0
  96. package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
  97. package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
  98. package/dist/charts/heatmap/heatmap-legend.js +165 -0
  99. package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
  100. package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
  101. package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
  102. package/dist/charts/heatmap/heatmap-separator.js +168 -0
  103. package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
  104. package/dist/charts/heatmap/heatmap-utils.js +633 -0
  105. package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
  106. package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
  107. package/dist/charts/heatmap/index.js +208 -0
  108. package/dist/charts/highlight-segment-bounds.js +34 -0
  109. package/dist/charts/highlight-segment.js +119 -0
  110. package/dist/charts/index.js +944 -0
  111. package/dist/charts/indicator-fade.js +44 -0
  112. package/dist/charts/legend/index.js +22 -0
  113. package/dist/charts/legend/legend-context.js +47 -0
  114. package/dist/charts/legend/legend-item.js +30 -0
  115. package/dist/charts/legend/legend-label.js +14 -0
  116. package/dist/charts/legend/legend-marker.js +18 -0
  117. package/dist/charts/legend/legend-progress.js +39 -0
  118. package/dist/charts/legend/legend-value.js +31 -0
  119. package/dist/charts/legend/legend.js +69 -0
  120. package/dist/charts/line-backdrop.js +129 -0
  121. package/dist/charts/line-chart-loading.js +85 -0
  122. package/dist/charts/line-chart.js +182 -0
  123. package/dist/charts/line-loading-pulse.js +185 -0
  124. package/dist/charts/line-loading-timing.js +12 -0
  125. package/dist/charts/line-path.js +58 -0
  126. package/dist/charts/line-series-terminal-marker.js +75 -0
  127. package/dist/charts/line.js +499 -0
  128. package/dist/charts/live-line-chart.js +494 -0
  129. package/dist/charts/live-line.js +277 -0
  130. package/dist/charts/live-x-axis.js +116 -0
  131. package/dist/charts/live-y-axis.js +164 -0
  132. package/dist/charts/loading-sweep.js +344 -0
  133. package/dist/charts/local-point.js +56 -0
  134. package/dist/charts/markers/chart-markers.js +149 -0
  135. package/dist/charts/markers/index.js +14 -0
  136. package/dist/charts/markers/marker-group.js +411 -0
  137. package/dist/charts/motion-utils.js +29 -0
  138. package/dist/charts/notch-gauge-shared.js +146 -0
  139. package/dist/charts/particle-line.js +1340 -0
  140. package/dist/charts/path-stroke-utils.js +51 -0
  141. package/dist/charts/pattern-area.js +127 -0
  142. package/dist/charts/pattern-preset.js +287 -0
  143. package/dist/charts/pattern-tile.js +31 -0
  144. package/dist/charts/patterns/circles.js +62 -0
  145. package/dist/charts/patterns/constants.js +9 -0
  146. package/dist/charts/patterns/hexagons.js +38 -0
  147. package/dist/charts/patterns/index.js +16 -0
  148. package/dist/charts/patterns/lines.js +65 -0
  149. package/dist/charts/patterns/path.js +37 -0
  150. package/dist/charts/patterns/pattern.js +16 -0
  151. package/dist/charts/patterns/waves.js +40 -0
  152. package/dist/charts/pie-center-shell.js +127 -0
  153. package/dist/charts/pie-center.js +87 -0
  154. package/dist/charts/pie-chart.js +377 -0
  155. package/dist/charts/pie-context.js +116 -0
  156. package/dist/charts/pie-slice.js +394 -0
  157. package/dist/charts/pie-ticks.js +332 -0
  158. package/dist/charts/profit-loss-legend-hover.js +18 -0
  159. package/dist/charts/profit-loss-legend.js +53 -0
  160. package/dist/charts/profit-loss-line.js +162 -0
  161. package/dist/charts/profit-loss-segments.js +88 -0
  162. package/dist/charts/projection-config.js +90 -0
  163. package/dist/charts/projection-line-end-marker.js +50 -0
  164. package/dist/charts/projection-line.js +466 -0
  165. package/dist/charts/projection-utils.js +303 -0
  166. package/dist/charts/radar-area.js +192 -0
  167. package/dist/charts/radar-axis.js +41 -0
  168. package/dist/charts/radar-chart.js +184 -0
  169. package/dist/charts/radar-context.js +104 -0
  170. package/dist/charts/radar-grid.js +121 -0
  171. package/dist/charts/radar-labels.js +62 -0
  172. package/dist/charts/radial-area.js +498 -0
  173. package/dist/charts/radial-axis.js +652 -0
  174. package/dist/charts/radial-bar.js +316 -0
  175. package/dist/charts/radial-center.js +67 -0
  176. package/dist/charts/radial-chart.js +740 -0
  177. package/dist/charts/radial-dot-bar-layout.js +68 -0
  178. package/dist/charts/radial-dot-bar.js +387 -0
  179. package/dist/charts/radial-geometry.js +114 -0
  180. package/dist/charts/radial-legend.js +66 -0
  181. package/dist/charts/radial-line.js +280 -0
  182. package/dist/charts/radial-ring-bar.js +255 -0
  183. package/dist/charts/radial-scrubber.js +120 -0
  184. package/dist/charts/radial-series-color.js +10 -0
  185. package/dist/charts/reference-area-config.js +43 -0
  186. package/dist/charts/reference-area-geometry.js +76 -0
  187. package/dist/charts/reference-area-registration-context.js +10 -0
  188. package/dist/charts/reference-area.js +241 -0
  189. package/dist/charts/responsive-chart-label-count.js +18 -0
  190. package/dist/charts/ring-center.js +78 -0
  191. package/dist/charts/ring-chart.js +362 -0
  192. package/dist/charts/ring-context.js +122 -0
  193. package/dist/charts/ring-grid.js +175 -0
  194. package/dist/charts/ring-labels.js +109 -0
  195. package/dist/charts/ring.js +237 -0
  196. package/dist/charts/sankey/index.js +22 -0
  197. package/dist/charts/sankey/sankey-chart.js +199 -0
  198. package/dist/charts/sankey/sankey-context.js +32 -0
  199. package/dist/charts/sankey/sankey-link.js +232 -0
  200. package/dist/charts/sankey/sankey-node.js +348 -0
  201. package/dist/charts/sankey/sankey-tooltip.js +94 -0
  202. package/dist/charts/scatter-chart-shell.js +279 -0
  203. package/dist/charts/scatter-chart.js +150 -0
  204. package/dist/charts/scatter-jitter.js +86 -0
  205. package/dist/charts/scatter-svg.js +17 -0
  206. package/dist/charts/scatter.js +92 -0
  207. package/dist/charts/segment.js +107 -0
  208. package/dist/charts/series-bar-layout.js +42 -0
  209. package/dist/charts/series-bar.js +241 -0
  210. package/dist/charts/series-dash-tail-overlay.js +53 -0
  211. package/dist/charts/series-highlight-layer.js +43 -0
  212. package/dist/charts/series-hover-dim.js +32 -0
  213. package/dist/charts/series-markers.js +239 -0
  214. package/dist/charts/series-path-utils.js +185 -0
  215. package/dist/charts/series-point-marker.js +150 -0
  216. package/dist/charts/sparkline-geometry.js +197 -0
  217. package/dist/charts/sparkline.js +910 -0
  218. package/dist/charts/static-chart-preview-context.js +16 -0
  219. package/dist/charts/sunburst-breadcrumb.js +33 -0
  220. package/dist/charts/sunburst-center.js +37 -0
  221. package/dist/charts/sunburst-chart.js +408 -0
  222. package/dist/charts/sunburst-context.js +140 -0
  223. package/dist/charts/sunburst-data.js +0 -0
  224. package/dist/charts/sunburst-hint.js +42 -0
  225. package/dist/charts/sunburst-labels.js +130 -0
  226. package/dist/charts/sunburst-segment.js +144 -0
  227. package/dist/charts/sunburst.js +419 -0
  228. package/dist/charts/time-series-chart-shell.js +688 -0
  229. package/dist/charts/tooltip/chart-tooltip.js +516 -0
  230. package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
  231. package/dist/charts/tooltip/date-ticker.js +376 -0
  232. package/dist/charts/tooltip/index.js +32 -0
  233. package/dist/charts/tooltip/liquid-glass.js +142 -0
  234. package/dist/charts/tooltip/tooltip-box.js +502 -0
  235. package/dist/charts/tooltip/tooltip-content.js +59 -0
  236. package/dist/charts/tooltip/tooltip-dot.js +170 -0
  237. package/dist/charts/tooltip/tooltip-indicator.js +175 -0
  238. package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
  239. package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
  240. package/dist/charts/trend-line-utils.js +64 -0
  241. package/dist/charts/trend-line.js +318 -0
  242. package/dist/charts/use-animated-band.js +175 -0
  243. package/dist/charts/use-animated-series-path.js +208 -0
  244. package/dist/charts/use-animated-y-domains.js +192 -0
  245. package/dist/charts/use-category-slots.js +29 -0
  246. package/dist/charts/use-chart-interaction.js +296 -0
  247. package/dist/charts/use-chart-phase-orchestrator.js +183 -0
  248. package/dist/charts/use-enter-complete.js +18 -0
  249. package/dist/charts/use-grid-shimmer.js +88 -0
  250. package/dist/charts/use-highlight-segment.js +65 -0
  251. package/dist/charts/use-mount-progress.js +23 -0
  252. package/dist/charts/use-scatter-chart-interaction.js +364 -0
  253. package/dist/charts/use-scheduled-tooltip.js +84 -0
  254. package/dist/charts/visx-pattern.js +30 -0
  255. package/dist/charts/weekends.js +174 -0
  256. package/dist/charts/x-axis-hover.js +46 -0
  257. package/dist/charts/x-axis.js +523 -0
  258. package/dist/charts/y-axis-scales.js +71 -0
  259. package/dist/charts/y-axis-ticks.js +22 -0
  260. package/dist/charts/y-axis.js +233 -0
  261. package/dist/charts/y-domain-utils.js +189 -0
  262. package/dist/index.d.ts +7346 -0
  263. package/dist/index.js +2 -0
  264. package/dist/lib/utils.js +8 -0
  265. package/dist/shimmering-text.js +54 -0
  266. package/package.json +78 -4
  267. package/tema.css +202 -0
@@ -0,0 +1,232 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { m, useTransform } from "motion/react";
4
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import { useMountProgress } from "../use-mount-progress";
6
+ import {
7
+ useSankey
8
+ } from "./sankey-context";
9
+ function getNodeIndex(nodeOrIndex) {
10
+ if (typeof nodeOrIndex === "number") {
11
+ return nodeOrIndex;
12
+ }
13
+ return nodeOrIndex.index;
14
+ }
15
+ function getNodeObject(nodeOrIndex) {
16
+ if (typeof nodeOrIndex === "number") {
17
+ return null;
18
+ }
19
+ return nodeOrIndex;
20
+ }
21
+ const defaultColors = [
22
+ "var(--chart-1)",
23
+ "var(--chart-2)",
24
+ "var(--chart-3)",
25
+ "var(--chart-4)",
26
+ "var(--chart-5)"
27
+ ];
28
+ function getDefaultNodeColor(node) {
29
+ const index = node.index ?? 0;
30
+ return defaultColors[index % defaultColors.length] ?? "var(--chart-1)";
31
+ }
32
+ function AnimatedLink({
33
+ path,
34
+ width,
35
+ stroke,
36
+ strokeOpacity,
37
+ index,
38
+ totalLinks,
39
+ isFaded,
40
+ isHighlighted,
41
+ fadedOpacity,
42
+ animationDuration,
43
+ onMouseEnter,
44
+ onMouseLeave
45
+ }) {
46
+ const { enterTransition, revealEpoch } = useSankey();
47
+ const pathRef = useRef(null);
48
+ const [pathLength, setPathLength] = useState(0);
49
+ const linkStartDelay = animationDuration * 0.2;
50
+ const linkAnimDuration = animationDuration * 0.8;
51
+ const staggerDelaySeconds = (linkStartDelay + index / totalLinks * linkAnimDuration * 0.4) / 1e3;
52
+ useLayoutEffect(() => {
53
+ if (pathRef.current) {
54
+ const length = pathRef.current.getTotalLength();
55
+ setPathLength(length);
56
+ }
57
+ });
58
+ const progress = useMountProgress(
59
+ enterTransition,
60
+ staggerDelaySeconds,
61
+ `${revealEpoch}-${index}`
62
+ );
63
+ const strokeDashoffset = useTransform(progress, [0, 1], [pathLength, 0]);
64
+ const getTargetOpacity = () => {
65
+ if (isFaded) {
66
+ return fadedOpacity;
67
+ }
68
+ if (isHighlighted) {
69
+ return Math.min(1, strokeOpacity * 1.3);
70
+ }
71
+ return strokeOpacity;
72
+ };
73
+ const targetOpacity = getTargetOpacity();
74
+ const dashArray = pathLength > 0 ? `${pathLength} ${pathLength}` : "none";
75
+ const initialOpacity = strokeOpacity ?? 0.5;
76
+ const animatedOpacity = targetOpacity ?? initialOpacity;
77
+ return /* @__PURE__ */ jsx(
78
+ m.path,
79
+ {
80
+ animate: { opacity: animatedOpacity },
81
+ d: path,
82
+ fill: "none",
83
+ initial: { opacity: initialOpacity },
84
+ onMouseEnter,
85
+ onMouseLeave,
86
+ ref: pathRef,
87
+ stroke,
88
+ strokeDasharray: dashArray,
89
+ strokeWidth: Math.max(1, width),
90
+ style: {
91
+ cursor: "pointer",
92
+ strokeDashoffset
93
+ },
94
+ transition: { duration: 0.18, ease: "easeOut" }
95
+ }
96
+ );
97
+ }
98
+ function SankeyLink({
99
+ stroke,
100
+ strokeOpacity = 0.5,
101
+ fadedOpacity = 0.1,
102
+ useGradient = true,
103
+ getNodeColor,
104
+ getLinkColor,
105
+ patterns,
106
+ getLinkPattern
107
+ }) {
108
+ const {
109
+ links,
110
+ hoveredNodeIndex,
111
+ hoveredLinkIndex,
112
+ setHoveredLinkIndex,
113
+ setTooltipData,
114
+ animationDuration,
115
+ createPath
116
+ } = useSankey();
117
+ const getNodeColorFn = useCallback(
118
+ (node) => {
119
+ if (getNodeColor) {
120
+ return getNodeColor(node, node.index ?? 0);
121
+ }
122
+ return getDefaultNodeColor(node);
123
+ },
124
+ [getNodeColor]
125
+ );
126
+ const getLinkColorFn = useCallback(
127
+ (link, index) => {
128
+ if (getLinkColor) {
129
+ return getLinkColor(link, index);
130
+ }
131
+ return stroke || "var(--chart-line-primary)";
132
+ },
133
+ [getLinkColor, stroke]
134
+ );
135
+ const isAnyHovered = hoveredNodeIndex !== null || hoveredLinkIndex !== null;
136
+ const gradientDefs = useMemo(() => {
137
+ if (!useGradient || stroke || getLinkColor) {
138
+ return null;
139
+ }
140
+ return links.map((link, index) => {
141
+ const sourceNode = getNodeObject(link.source);
142
+ const targetNode = getNodeObject(link.target);
143
+ const sourceColor = sourceNode ? getNodeColorFn(sourceNode) : "var(--chart-1)";
144
+ const targetColor = targetNode ? getNodeColorFn(targetNode) : "var(--chart-1)";
145
+ const gradientId = `link-gradient-${index}`;
146
+ const x1 = sourceNode?.x1 ?? 0;
147
+ const x2 = targetNode?.x0 ?? 100;
148
+ return /* @__PURE__ */ jsxs(
149
+ "linearGradient",
150
+ {
151
+ gradientUnits: "userSpaceOnUse",
152
+ id: gradientId,
153
+ x1,
154
+ x2,
155
+ y1: "0",
156
+ y2: "0",
157
+ children: [
158
+ /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: sourceColor, stopOpacity: 1 }),
159
+ /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: targetColor, stopOpacity: 1 })
160
+ ]
161
+ },
162
+ gradientId
163
+ );
164
+ });
165
+ }, [links, useGradient, stroke, getLinkColor, getNodeColorFn]);
166
+ return /* @__PURE__ */ jsxs("g", { className: "sankey-links", children: [
167
+ /* @__PURE__ */ jsxs("defs", { children: [
168
+ patterns,
169
+ gradientDefs
170
+ ] }),
171
+ links.map((link, index) => {
172
+ const path = createPath(link);
173
+ const linkWidth = link.width ?? 1;
174
+ if (!path || path.trim() === "") {
175
+ return null;
176
+ }
177
+ const sIdx = getNodeIndex(link.source);
178
+ const tIdx = getNodeIndex(link.target);
179
+ const sourceIdx = sIdx ?? (typeof link.source === "number" ? link.source : -1);
180
+ const targetIdx = tIdx ?? (typeof link.target === "number" ? link.target : -1);
181
+ const isHighlighted = hoveredLinkIndex === index || hoveredNodeIndex === sourceIdx || hoveredNodeIndex === targetIdx;
182
+ const isFaded = isAnyHovered && !isHighlighted;
183
+ const handleMouseEnter = () => {
184
+ setHoveredLinkIndex(index);
185
+ setTooltipData({
186
+ type: "link",
187
+ linkIndex: index,
188
+ x: 0,
189
+ y: 0,
190
+ data: link
191
+ });
192
+ };
193
+ const handleMouseLeave = () => {
194
+ setHoveredLinkIndex(null);
195
+ setTooltipData(null);
196
+ };
197
+ let linkStroke;
198
+ const patternId = getLinkPattern?.(link, index);
199
+ if (patternId) {
200
+ linkStroke = `url(#${patternId})`;
201
+ } else if (useGradient && !stroke && !getLinkColor) {
202
+ linkStroke = `url(#link-gradient-${index})`;
203
+ } else {
204
+ linkStroke = getLinkColorFn(link, index);
205
+ }
206
+ return /* @__PURE__ */ jsx(
207
+ AnimatedLink,
208
+ {
209
+ animationDuration,
210
+ fadedOpacity,
211
+ index,
212
+ isFaded,
213
+ isHighlighted,
214
+ onMouseEnter: handleMouseEnter,
215
+ onMouseLeave: handleMouseLeave,
216
+ path,
217
+ stroke: linkStroke,
218
+ strokeOpacity,
219
+ totalLinks: links.length,
220
+ width: linkWidth
221
+ },
222
+ `link-${sourceIdx}-${targetIdx}-${link.width ?? link.value ?? ""}`
223
+ );
224
+ })
225
+ ] });
226
+ }
227
+ SankeyLink.displayName = "SankeyLink";
228
+ var sankey_link_default = SankeyLink;
229
+ export {
230
+ SankeyLink,
231
+ sankey_link_default as default
232
+ };
@@ -0,0 +1,348 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { m } from "motion/react";
4
+ import { useCallback, useMemo } from "react";
5
+ import { intFmt } from "../chart-formatters";
6
+ import { transitionWithDelay } from "../motion-utils";
7
+ import {
8
+ useSankey
9
+ } from "./sankey-context";
10
+ function getNodeIndex(nodeOrIndex) {
11
+ if (typeof nodeOrIndex === "number") {
12
+ return nodeOrIndex;
13
+ }
14
+ return nodeOrIndex.index;
15
+ }
16
+ const LABEL_OFFSET = 12;
17
+ const VALUE_LABEL_GAP = 16;
18
+ function getNodeLabelLayouts({
19
+ labelOrientation,
20
+ isLeftSide,
21
+ x,
22
+ y,
23
+ width,
24
+ height,
25
+ showValueLabels
26
+ }) {
27
+ const centerY = y + height / 2;
28
+ const initialX = isLeftSide ? x + 8 : x + width - 8;
29
+ if (labelOrientation === "horizontal") {
30
+ const labelX2 = isLeftSide ? x - LABEL_OFFSET : x + width + LABEL_OFFSET;
31
+ const textAnchor = isLeftSide ? "end" : "start";
32
+ return {
33
+ name: {
34
+ x: labelX2,
35
+ y: centerY,
36
+ textAnchor,
37
+ dy: "0.35em",
38
+ textLocalX: 0,
39
+ rotate: 0,
40
+ initialX,
41
+ initialY: centerY
42
+ },
43
+ value: showValueLabels ? {
44
+ x: labelX2,
45
+ y: centerY + VALUE_LABEL_GAP,
46
+ textAnchor,
47
+ dy: "0.35em",
48
+ textLocalX: 0,
49
+ rotate: 0,
50
+ initialX,
51
+ initialY: centerY + VALUE_LABEL_GAP
52
+ } : null
53
+ };
54
+ }
55
+ const labelX = isLeftSide ? x - LABEL_OFFSET : x + width + LABEL_OFFSET;
56
+ const rotate = isLeftSide ? -90 : 90;
57
+ const halfGap = VALUE_LABEL_GAP / 2;
58
+ let nameLocalX = 0;
59
+ if (showValueLabels) {
60
+ nameLocalX = isLeftSide ? halfGap : -halfGap;
61
+ }
62
+ const valueLocalX = isLeftSide ? -halfGap : halfGap;
63
+ return {
64
+ name: {
65
+ x: labelX,
66
+ y: centerY,
67
+ textAnchor: "middle",
68
+ dy: "0.35em",
69
+ textLocalX: nameLocalX,
70
+ rotate,
71
+ initialX,
72
+ initialY: centerY
73
+ },
74
+ value: showValueLabels ? {
75
+ x: labelX,
76
+ y: centerY,
77
+ textAnchor: "middle",
78
+ dy: "0.35em",
79
+ textLocalX: valueLocalX,
80
+ rotate,
81
+ initialX,
82
+ initialY: centerY
83
+ } : null
84
+ };
85
+ }
86
+ function NodeLabel({
87
+ layout,
88
+ opacity,
89
+ transition,
90
+ className,
91
+ children
92
+ }) {
93
+ return /* @__PURE__ */ jsx(
94
+ m.g,
95
+ {
96
+ animate: {
97
+ opacity,
98
+ x: layout.x,
99
+ y: layout.y,
100
+ rotate: layout.rotate
101
+ },
102
+ initial: {
103
+ opacity: 0,
104
+ x: layout.initialX,
105
+ y: layout.initialY,
106
+ rotate: layout.rotate
107
+ },
108
+ transition,
109
+ children: /* @__PURE__ */ jsx(
110
+ "text",
111
+ {
112
+ className,
113
+ dy: layout.dy,
114
+ textAnchor: layout.textAnchor,
115
+ x: layout.textLocalX,
116
+ children
117
+ }
118
+ )
119
+ }
120
+ );
121
+ }
122
+ function AnimatedNode({
123
+ x,
124
+ y,
125
+ width,
126
+ height,
127
+ fill,
128
+ rx,
129
+ index,
130
+ totalNodes,
131
+ isFaded,
132
+ fadedOpacity,
133
+ animationDuration,
134
+ onMouseEnter,
135
+ onMouseLeave,
136
+ name,
137
+ value,
138
+ isLeftSide,
139
+ showLabels,
140
+ showValueLabels,
141
+ labelOrientation
142
+ }) {
143
+ const { enterTransition, revealEpoch } = useSankey();
144
+ const nodeAnimDuration = animationDuration * 0.6;
145
+ const staggerDelaySec = index / totalNodes * nodeAnimDuration * 0.4 / 1e3;
146
+ const nameLabelDelaySec = staggerDelaySec + nodeAnimDuration * 0.6 * 0.3 / 1e3;
147
+ const valueLabelDelaySec = nameLabelDelaySec + 0.06;
148
+ const nodeEnter = transitionWithDelay(enterTransition, staggerDelaySec);
149
+ const nameEnter = transitionWithDelay(enterTransition, nameLabelDelaySec);
150
+ const valueEnter = transitionWithDelay(enterTransition, valueLabelDelaySec);
151
+ const nodeOpacity = isFaded ? fadedOpacity : 1;
152
+ const nameOpacity = isFaded ? fadedOpacity : 1;
153
+ const valueOpacity = isFaded ? fadedOpacity * 0.8 : 0.6;
154
+ const labelLayouts = getNodeLabelLayouts({
155
+ labelOrientation,
156
+ isLeftSide,
157
+ x,
158
+ y,
159
+ width,
160
+ height,
161
+ showValueLabels
162
+ });
163
+ return /* @__PURE__ */ jsxs(
164
+ m.g,
165
+ {
166
+ onMouseEnter,
167
+ onMouseLeave,
168
+ style: { cursor: "pointer" },
169
+ children: [
170
+ /* @__PURE__ */ jsx(
171
+ m.rect,
172
+ {
173
+ animate: { opacity: nodeOpacity, scaleY: 1 },
174
+ fill,
175
+ height,
176
+ initial: { opacity: 0, scaleY: 0 },
177
+ rx,
178
+ ry: rx,
179
+ style: { originY: 0.5 },
180
+ transition: nodeEnter,
181
+ width,
182
+ x,
183
+ y
184
+ },
185
+ `node-${index}-${revealEpoch}`
186
+ ),
187
+ showLabels ? /* @__PURE__ */ jsxs(Fragment, { children: [
188
+ /* @__PURE__ */ jsx(
189
+ NodeLabel,
190
+ {
191
+ className: "fill-chart-foreground font-medium text-[13px]",
192
+ layout: labelLayouts.name,
193
+ opacity: nameOpacity,
194
+ transition: nameEnter,
195
+ children: name
196
+ },
197
+ `name-${index}-${revealEpoch}`
198
+ ),
199
+ labelLayouts.value ? /* @__PURE__ */ jsx(
200
+ NodeLabel,
201
+ {
202
+ className: "fill-chart-foreground text-[11px]",
203
+ layout: labelLayouts.value,
204
+ opacity: valueOpacity,
205
+ transition: valueEnter,
206
+ children: intFmt(value)
207
+ },
208
+ `value-${index}-${revealEpoch}`
209
+ ) : null
210
+ ] }) : null
211
+ ]
212
+ }
213
+ );
214
+ }
215
+ function SankeyNode({
216
+ fill,
217
+ lineCap = 4,
218
+ fadedOpacity = 0.4,
219
+ showLabels = true,
220
+ showValueLabels = true,
221
+ labelOrientation = "horizontal",
222
+ getNodeColor: getNodeColorProp
223
+ }) {
224
+ const {
225
+ nodes,
226
+ links,
227
+ width,
228
+ margin,
229
+ hoveredNodeIndex,
230
+ hoveredLinkIndex,
231
+ setHoveredNodeIndex,
232
+ setTooltipData,
233
+ animationDuration
234
+ } = useSankey();
235
+ const defaultColors = useMemo(
236
+ () => [
237
+ "var(--chart-1)",
238
+ "var(--chart-2)",
239
+ "var(--chart-3)",
240
+ "var(--chart-4)",
241
+ "var(--chart-5)"
242
+ ],
243
+ []
244
+ );
245
+ const getColor = useCallback(
246
+ (node, index) => {
247
+ if (fill) {
248
+ return fill;
249
+ }
250
+ if (getNodeColorProp) {
251
+ return getNodeColorProp(node, index);
252
+ }
253
+ return defaultColors[index % defaultColors.length] ?? "var(--chart-1)";
254
+ },
255
+ [fill, getNodeColorProp, defaultColors]
256
+ );
257
+ const isNodeConnected = useCallback(
258
+ (nodeIndex) => {
259
+ if (hoveredNodeIndex !== null) {
260
+ if (hoveredNodeIndex === nodeIndex) {
261
+ return true;
262
+ }
263
+ return links.some((link) => {
264
+ const sIdx = getNodeIndex(link.source);
265
+ const tIdx = getNodeIndex(link.target);
266
+ return sIdx === hoveredNodeIndex && tIdx === nodeIndex || tIdx === hoveredNodeIndex && sIdx === nodeIndex;
267
+ });
268
+ }
269
+ if (hoveredLinkIndex !== null) {
270
+ const link = links[hoveredLinkIndex];
271
+ if (!link) {
272
+ return false;
273
+ }
274
+ const sIdx = getNodeIndex(link.source);
275
+ const tIdx = getNodeIndex(link.target);
276
+ return sIdx === nodeIndex || tIdx === nodeIndex;
277
+ }
278
+ return false;
279
+ },
280
+ [hoveredNodeIndex, hoveredLinkIndex, links]
281
+ );
282
+ const isAnyHovered = hoveredNodeIndex !== null || hoveredLinkIndex !== null;
283
+ const innerWidth = width - margin.left - margin.right;
284
+ return /* @__PURE__ */ jsx("g", { className: "sankey-nodes", children: nodes.map((node, index) => {
285
+ const nodeX = node.x0 ?? 0;
286
+ const nodeY = node.y0 ?? 0;
287
+ const nodeWidth = (node.x1 ?? 0) - nodeX;
288
+ const nodeHeight = (node.y1 ?? 0) - nodeY;
289
+ const isConnected = isNodeConnected(index);
290
+ const isFaded = isAnyHovered && !isConnected;
291
+ const isLeftSide = nodeX < innerWidth / 2;
292
+ let displayValue = 0;
293
+ for (const l of links) {
294
+ const sIdx = getNodeIndex(l.source);
295
+ const tIdx = getNodeIndex(l.target);
296
+ if (node.category === "source" && sIdx === index) {
297
+ displayValue += l.value;
298
+ } else if (node.category !== "source" && tIdx === index) {
299
+ displayValue += l.value;
300
+ }
301
+ }
302
+ const handleMouseEnter = () => {
303
+ setHoveredNodeIndex(index);
304
+ setTooltipData({
305
+ type: "node",
306
+ nodeIndex: index,
307
+ x: 0,
308
+ y: 0,
309
+ data: node
310
+ });
311
+ };
312
+ const handleMouseLeave = () => {
313
+ setHoveredNodeIndex(null);
314
+ setTooltipData(null);
315
+ };
316
+ return /* @__PURE__ */ jsx(
317
+ AnimatedNode,
318
+ {
319
+ animationDuration,
320
+ fadedOpacity,
321
+ fill: getColor(node, index),
322
+ height: nodeHeight,
323
+ index,
324
+ isFaded,
325
+ isLeftSide,
326
+ labelOrientation,
327
+ name: node.name,
328
+ onMouseEnter: handleMouseEnter,
329
+ onMouseLeave: handleMouseLeave,
330
+ rx: lineCap,
331
+ showLabels,
332
+ showValueLabels,
333
+ totalNodes: nodes.length,
334
+ value: displayValue,
335
+ width: nodeWidth,
336
+ x: nodeX,
337
+ y: nodeY
338
+ },
339
+ `node-${node.name}`
340
+ );
341
+ }) });
342
+ }
343
+ SankeyNode.displayName = "SankeyNode";
344
+ var sankey_node_default = SankeyNode;
345
+ export {
346
+ SankeyNode,
347
+ sankey_node_default as default
348
+ };
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { intFmt } from "../chart-formatters";
4
+ import { TooltipBox } from "../tooltip/tooltip-box";
5
+ import { TooltipContent } from "../tooltip/tooltip-content";
6
+ import {
7
+ useSankey
8
+ } from "./sankey-context";
9
+ function getNodeName(nodeOrIndex, fallbackIndex) {
10
+ if (typeof nodeOrIndex === "number") {
11
+ return `Node ${nodeOrIndex}`;
12
+ }
13
+ return nodeOrIndex.name ?? `Node ${fallbackIndex}`;
14
+ }
15
+ function SankeyTooltip({
16
+ nodeContent,
17
+ linkContent,
18
+ formatValue = intFmt,
19
+ className = "",
20
+ panelStyle,
21
+ exit = true
22
+ }) {
23
+ const {
24
+ tooltipData,
25
+ containerRef,
26
+ width,
27
+ height,
28
+ margin,
29
+ nodes,
30
+ links,
31
+ mousePos
32
+ } = useSankey();
33
+ let x = 0;
34
+ let y = 0;
35
+ if (tooltipData) {
36
+ x = mousePos ? mousePos.x : tooltipData.x + margin.left;
37
+ y = mousePos ? mousePos.y : tooltipData.y + margin.top;
38
+ }
39
+ let body = null;
40
+ const node = tooltipData?.type === "node" && tooltipData.nodeIndex !== void 0 ? nodes[tooltipData.nodeIndex] : void 0;
41
+ const link = tooltipData?.type === "link" && tooltipData.linkIndex !== void 0 ? links[tooltipData.linkIndex] : void 0;
42
+ if (node && tooltipData?.nodeIndex !== void 0) {
43
+ body = nodeContent ? nodeContent({ node, index: tooltipData.nodeIndex }) : /* @__PURE__ */ jsx(
44
+ TooltipContent,
45
+ {
46
+ rows: [
47
+ {
48
+ color: "var(--chart-line-primary)",
49
+ label: "Sessions",
50
+ value: formatValue(node.value ?? 0)
51
+ }
52
+ ],
53
+ title: node.name
54
+ }
55
+ );
56
+ } else if (link && tooltipData?.linkIndex !== void 0) {
57
+ const index = tooltipData.linkIndex;
58
+ if (linkContent) {
59
+ body = linkContent({ link, index });
60
+ } else {
61
+ const sourceName = getNodeName(link.source, index);
62
+ const targetName = getNodeName(link.target, index);
63
+ const rows = [
64
+ {
65
+ color: "var(--chart-foreground-muted)",
66
+ label: "Flow",
67
+ value: formatValue(link.value)
68
+ }
69
+ ];
70
+ body = /* @__PURE__ */ jsx(TooltipContent, { rows, title: `${sourceName} \u2192 ${targetName}` });
71
+ }
72
+ }
73
+ return /* @__PURE__ */ jsx(
74
+ TooltipBox,
75
+ {
76
+ className,
77
+ containerHeight: height,
78
+ containerRef,
79
+ containerWidth: width,
80
+ exit,
81
+ panelStyle,
82
+ visible: body !== null,
83
+ x,
84
+ y,
85
+ children: body
86
+ }
87
+ );
88
+ }
89
+ SankeyTooltip.displayName = "SankeyTooltip";
90
+ var sankey_tooltip_default = SankeyTooltip;
91
+ export {
92
+ SankeyTooltip,
93
+ sankey_tooltip_default as default
94
+ };