@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,90 @@
1
+ import {
2
+ Children,
3
+ Fragment,
4
+ isValidElement
5
+ } from "react";
6
+ import { isChartClipPassthrough } from "./chart-child-passthrough";
7
+ import {
8
+ projectionDateExtents,
9
+ projectionValueExtents
10
+ } from "./projection-utils";
11
+ import { normalizeYAxisId } from "./y-axis-scales";
12
+ function getChildComponentName(child) {
13
+ const childType = child.type;
14
+ return typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
15
+ }
16
+ function isProjectionLineElement(child) {
17
+ return getChildComponentName(child) === "ProjectionLine";
18
+ }
19
+ function normalizeProjectionData(data) {
20
+ if (!data?.length) {
21
+ return [];
22
+ }
23
+ return data.map((point) => ({
24
+ date: point.date instanceof Date ? point.date : new Date(point.date),
25
+ value: point.value
26
+ }));
27
+ }
28
+ function extractProjectionLineConfigs(children) {
29
+ const configs = [];
30
+ const visit = (node) => {
31
+ Children.forEach(node, (child) => {
32
+ if (!isValidElement(child)) {
33
+ return;
34
+ }
35
+ if (child.type === Fragment) {
36
+ visit(child.props.children);
37
+ return;
38
+ }
39
+ if (isProjectionLineElement(child)) {
40
+ const props = child.props;
41
+ const data = normalizeProjectionData(props?.data);
42
+ if (data.length >= 2) {
43
+ configs.push({
44
+ yAxisId: normalizeYAxisId(props?.yAxisId),
45
+ data
46
+ });
47
+ }
48
+ return;
49
+ }
50
+ if (isChartClipPassthrough(child.type)) {
51
+ visit(child.props.children);
52
+ return;
53
+ }
54
+ const childProps = child.props;
55
+ if (childProps?.children) {
56
+ visit(childProps.children);
57
+ }
58
+ });
59
+ };
60
+ visit(children);
61
+ return configs;
62
+ }
63
+ function mergeProjectionYDomain(domain, configs, yAxisId) {
64
+ const paths = configs.filter((config) => config.yAxisId === yAxisId).map((config) => config.data);
65
+ const extents = projectionValueExtents(paths);
66
+ if (!extents) {
67
+ return domain;
68
+ }
69
+ const [min, max] = domain;
70
+ const nextMin = Math.min(min, extents.minValue);
71
+ const nextMax = Math.max(max, extents.maxValue);
72
+ if (nextMin >= 0 && min >= 0) {
73
+ return [0, nextMax <= 0 ? 100 : nextMax * 1.1];
74
+ }
75
+ const padding = (nextMax - nextMin) * 0.05 || 1;
76
+ return [nextMin - padding, nextMax + padding];
77
+ }
78
+ function mergeProjectionXDomainMax(maxTime, configs) {
79
+ const paths = configs.map((config) => config.data);
80
+ const extents = projectionDateExtents(paths);
81
+ if (!extents) {
82
+ return maxTime;
83
+ }
84
+ return Math.max(maxTime, extents.maxTime);
85
+ }
86
+ export {
87
+ extractProjectionLineConfigs,
88
+ mergeProjectionXDomainMax,
89
+ mergeProjectionYDomain
90
+ };
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useCallback } from "react";
4
+ import { useChartStable, useYScale } from "./chart-context";
5
+ function ProjectionLineEndMarker({
6
+ data,
7
+ yAxisId,
8
+ stroke = "var(--chart-3)",
9
+ strokeOpacity = 1,
10
+ radius = 5
11
+ }) {
12
+ const { xScale, chartPhase, innerWidth } = useChartStable();
13
+ const yScale = useYScale(yAxisId);
14
+ const getX = useCallback(
15
+ (point) => xScale(point.date) ?? 0,
16
+ [xScale]
17
+ );
18
+ const getY = useCallback(
19
+ (point) => yScale(point.value) ?? 0,
20
+ [yScale]
21
+ );
22
+ const showStroke = chartPhase === "revealing" || chartPhase === "ready" || chartPhase === "exitingReady";
23
+ if (!showStroke || data.length < 2) {
24
+ return null;
25
+ }
26
+ const endPoint = data.at(-1);
27
+ if (!endPoint) {
28
+ return null;
29
+ }
30
+ const edgePadding = radius + 1;
31
+ const endX = Math.min(getX(endPoint), Math.max(0, innerWidth - edgePadding));
32
+ const endY = getY(endPoint);
33
+ return /* @__PURE__ */ jsx(
34
+ "circle",
35
+ {
36
+ cx: endX,
37
+ cy: endY,
38
+ fill: stroke,
39
+ fillOpacity: strokeOpacity,
40
+ r: radius * 0.85
41
+ }
42
+ );
43
+ }
44
+ ProjectionLineEndMarker.displayName = "ProjectionLineEndMarker";
45
+ ProjectionLineEndMarker.__isPostOverlay = true;
46
+ var projection_line_end_marker_default = ProjectionLineEndMarker;
47
+ export {
48
+ ProjectionLineEndMarker,
49
+ projection_line_end_marker_default as default
50
+ };
@@ -0,0 +1,466 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { curveLinear } from "d3-shape";
4
+ import { m } from "motion/react";
5
+ import { useCallback, useId, useMemo } from "react";
6
+ import { useChartStable, useYScale } from "./chart-context";
7
+ import { LinePath, linePathD } from "./line-path";
8
+ import { renderPatternPreset } from "./pattern-preset";
9
+ import {
10
+ buildHorizontalTangentBezierPath,
11
+ projectionCrossingX
12
+ } from "./projection-utils";
13
+ const ENTER_FADE = { duration: 0.42, ease: "easeOut" };
14
+ const LABEL_GAP = 8;
15
+ const LABEL_FONT_SIZE = 12;
16
+ function defaultAreaOpacity(areaFill) {
17
+ if (areaFill === "pattern") {
18
+ return 0.5;
19
+ }
20
+ if (areaFill === "gradient") {
21
+ return 0.3;
22
+ }
23
+ return 0.12;
24
+ }
25
+ function verticalFadeStops(fadeBottom) {
26
+ const zone = Math.min(100, Math.max(0, fadeBottom)) / 100;
27
+ return [
28
+ { offset: 0, opacity: 1 },
29
+ { offset: 1 - zone, opacity: 1 },
30
+ { offset: 1, opacity: zone > 0 ? 0 : 1 }
31
+ ];
32
+ }
33
+ function ProjectionArea({
34
+ d,
35
+ uid,
36
+ top,
37
+ bottom,
38
+ areaFill,
39
+ color,
40
+ opacity,
41
+ fadeBottom,
42
+ pattern,
43
+ patternScale,
44
+ patternTint
45
+ }) {
46
+ const resolvedOpacity = opacity ?? defaultAreaOpacity(areaFill);
47
+ const resolvedFade = fadeBottom ?? (areaFill === "gradient" ? 100 : 0);
48
+ const tint = areaFill === "pattern" ? patternTint : 0;
49
+ const fadeId = `chart-projection-area-fade-${uid}`;
50
+ const maskId = `chart-projection-area-mask-${uid}`;
51
+ const tintId = `chart-projection-area-tint-${uid}`;
52
+ const patternId = `chart-projection-area-pattern-${uid}`;
53
+ const span = { gradientUnits: "userSpaceOnUse", x1: 0, x2: 0 };
54
+ const useFade = resolvedFade > 0;
55
+ const patternNode = areaFill === "pattern" ? renderPatternPreset(pattern, patternId, {
56
+ color,
57
+ scale: patternScale
58
+ }) : null;
59
+ let fill = color;
60
+ if (areaFill === "pattern" && patternNode) {
61
+ fill = `url(#${patternId})`;
62
+ }
63
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
64
+ /* @__PURE__ */ jsxs("defs", { children: [
65
+ useFade ? /* @__PURE__ */ jsxs(Fragment, { children: [
66
+ /* @__PURE__ */ jsx("linearGradient", { id: fadeId, ...span, y1: top, y2: bottom, children: verticalFadeStops(resolvedFade).map((stop) => /* @__PURE__ */ jsx(
67
+ "stop",
68
+ {
69
+ offset: stop.offset,
70
+ stopColor: "white",
71
+ stopOpacity: stop.opacity
72
+ },
73
+ stop.offset
74
+ )) }),
75
+ /* @__PURE__ */ jsx("mask", { id: maskId, maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d, fill: `url(#${fadeId})` }) })
76
+ ] }) : null,
77
+ tint > 0 ? /* @__PURE__ */ jsxs("linearGradient", { id: tintId, ...span, y1: top, y2: bottom, children: [
78
+ /* @__PURE__ */ jsx("stop", { offset: 0, stopColor: color, stopOpacity: tint }),
79
+ /* @__PURE__ */ jsx("stop", { offset: 1, stopColor: color, stopOpacity: 0 })
80
+ ] }) : null
81
+ ] }),
82
+ patternNode,
83
+ tint > 0 ? /* @__PURE__ */ jsx("path", { d, fill: `url(#${tintId})` }) : null,
84
+ /* @__PURE__ */ jsx(
85
+ "path",
86
+ {
87
+ d,
88
+ fill,
89
+ mask: useFade ? `url(#${maskId})` : void 0,
90
+ opacity: resolvedOpacity
91
+ }
92
+ )
93
+ ] });
94
+ }
95
+ function resolveVisibleEndX(endX, innerWidth, endpointRadius, strokeWidth) {
96
+ const edgePadding = endpointRadius + strokeWidth * 0.5 + 1;
97
+ return Math.min(endX, Math.max(0, innerWidth - edgePadding));
98
+ }
99
+ function renderProjectionStroke({
100
+ bezierPath,
101
+ curve,
102
+ curveKind,
103
+ data,
104
+ getX,
105
+ getY,
106
+ linearPath,
107
+ strokeProps
108
+ }) {
109
+ if (curveKind === "bezier" && bezierPath) {
110
+ return /* @__PURE__ */ jsx("path", { d: bezierPath, fill: "none", ...strokeProps });
111
+ }
112
+ if (curveKind === "linear" && linearPath) {
113
+ return /* @__PURE__ */ jsx("path", { d: linearPath, fill: "none", ...strokeProps });
114
+ }
115
+ return /* @__PURE__ */ jsx(
116
+ LinePath,
117
+ {
118
+ d: linePathD(data, { curve: curve ?? curveLinear, x: getX, y: getY }),
119
+ ...strokeProps
120
+ }
121
+ );
122
+ }
123
+ function useProjectionGeometry({
124
+ data,
125
+ yAxisId,
126
+ showMarker,
127
+ endpointRadius,
128
+ strokeWidth
129
+ }) {
130
+ const { xScale, innerWidth } = useChartStable();
131
+ const yScale = useYScale(yAxisId);
132
+ const getX = useCallback(
133
+ (point) => xScale(point.date) ?? 0,
134
+ [xScale]
135
+ );
136
+ const getY = useCallback(
137
+ (point) => yScale(point.value) ?? 0,
138
+ [yScale]
139
+ );
140
+ const startPoint = data[0];
141
+ const endPoint = data.at(-1);
142
+ const geometry = useMemo(() => {
143
+ if (!(startPoint && endPoint)) {
144
+ return null;
145
+ }
146
+ return {
147
+ startX: getX(startPoint),
148
+ startY: getY(startPoint),
149
+ visibleEndX: resolveVisibleEndX(
150
+ getX(endPoint),
151
+ innerWidth,
152
+ showMarker ? endpointRadius : 0,
153
+ strokeWidth
154
+ ),
155
+ endY: getY(endPoint)
156
+ };
157
+ }, [
158
+ endPoint,
159
+ endpointRadius,
160
+ getX,
161
+ getY,
162
+ innerWidth,
163
+ showMarker,
164
+ startPoint,
165
+ strokeWidth
166
+ ]);
167
+ return { geometry, getX, getY, yScale };
168
+ }
169
+ function projectionSegmentPaths(geometry, curveKind) {
170
+ if (!geometry) {
171
+ return { bezierPath: null, linearPath: null, topPath: null };
172
+ }
173
+ const { startX, startY, visibleEndX, endY } = geometry;
174
+ const linear = `M ${startX},${startY} L ${visibleEndX},${endY}`;
175
+ const bezierPath = curveKind === "bezier" ? buildHorizontalTangentBezierPath(startX, startY, visibleEndX, endY) : null;
176
+ return {
177
+ bezierPath,
178
+ linearPath: curveKind === "linear" ? linear : null,
179
+ topPath: bezierPath ?? linear
180
+ };
181
+ }
182
+ function ProjectionTargetOverlay({
183
+ geometry,
184
+ targetY,
185
+ crossingX,
186
+ color,
187
+ markerRadius,
188
+ endpointRadius,
189
+ markerFill,
190
+ showTargetMarker,
191
+ showGuides,
192
+ targetStroke,
193
+ targetDasharray,
194
+ targetStrokeOpacity,
195
+ guideStroke,
196
+ guideStrokeOpacity
197
+ }) {
198
+ const { innerWidth, innerHeight } = useChartStable();
199
+ const targetInPlot = targetY != null && targetY >= 0 && targetY <= innerHeight;
200
+ const crossing = crossingX != null && targetY != null ? { x: crossingX, y: targetY } : null;
201
+ const guideXs = [geometry.startX, ...crossing ? [crossing.x] : []];
202
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
203
+ showGuides ? guideXs.map((x) => /* @__PURE__ */ jsx(
204
+ "line",
205
+ {
206
+ stroke: guideStroke,
207
+ strokeDasharray: "3,3",
208
+ strokeOpacity: guideStrokeOpacity,
209
+ x1: x,
210
+ x2: x,
211
+ y1: 0,
212
+ y2: innerHeight
213
+ },
214
+ x
215
+ )) : null,
216
+ targetInPlot ? /* @__PURE__ */ jsx(
217
+ "line",
218
+ {
219
+ stroke: targetStroke,
220
+ strokeDasharray: targetDasharray,
221
+ strokeOpacity: targetStrokeOpacity,
222
+ x1: 0,
223
+ x2: innerWidth,
224
+ y1: targetY,
225
+ y2: targetY
226
+ }
227
+ ) : null,
228
+ showTargetMarker && crossing ? /* @__PURE__ */ jsxs("g", { className: "chart-projection-target-marker", children: [
229
+ /* @__PURE__ */ jsx(
230
+ "circle",
231
+ {
232
+ cx: crossing.x,
233
+ cy: crossing.y,
234
+ fill: color,
235
+ opacity: 0.18,
236
+ r: endpointRadius * 2
237
+ }
238
+ ),
239
+ /* @__PURE__ */ jsx(
240
+ "circle",
241
+ {
242
+ cx: crossing.x,
243
+ cy: crossing.y,
244
+ fill: markerFill,
245
+ r: markerRadius,
246
+ stroke: color,
247
+ strokeWidth: 1.5
248
+ }
249
+ )
250
+ ] }) : null
251
+ ] });
252
+ }
253
+ function ProjectionHorizon({
254
+ x,
255
+ y,
256
+ value,
257
+ color,
258
+ radius,
259
+ fill,
260
+ fillOpacity,
261
+ showMarker,
262
+ showLabel,
263
+ formatLabel,
264
+ labelColor
265
+ }) {
266
+ const hollow = fill != null;
267
+ const labelBelow = y < radius + LABEL_GAP + LABEL_FONT_SIZE;
268
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
269
+ showMarker ? /* @__PURE__ */ jsx(
270
+ "circle",
271
+ {
272
+ cx: x,
273
+ cy: y,
274
+ fill: fill ?? color,
275
+ fillOpacity,
276
+ r: radius,
277
+ stroke: hollow ? color : void 0,
278
+ strokeWidth: hollow ? 1.5 : void 0
279
+ }
280
+ ) : null,
281
+ showLabel ? /* @__PURE__ */ jsx(
282
+ "text",
283
+ {
284
+ dominantBaseline: labelBelow ? "hanging" : "auto",
285
+ fill: labelColor ?? color,
286
+ fontSize: LABEL_FONT_SIZE,
287
+ fontWeight: 600,
288
+ style: { fontVariantNumeric: "tabular-nums" },
289
+ textAnchor: "end",
290
+ x: x + radius,
291
+ y: labelBelow ? y + radius + LABEL_GAP : y - radius - LABEL_GAP,
292
+ children: formatLabel ? formatLabel(value) : value.toLocaleString("pt-BR")
293
+ }
294
+ ) : null
295
+ ] });
296
+ }
297
+ function ProjectionLine({
298
+ data,
299
+ yAxisId,
300
+ stroke = "var(--chart-3)",
301
+ strokeStyle = "solid",
302
+ gradientStart,
303
+ gradientEnd = "var(--chart-5)",
304
+ strokeWidth = 2,
305
+ curveKind = "linear",
306
+ curve,
307
+ strokeDasharray = "6,4",
308
+ strokeOpacity = 1,
309
+ showEndMarker,
310
+ showEndpoints,
311
+ endpointRadius = 5,
312
+ endMarkerFill,
313
+ showEndLabel = false,
314
+ formatEndLabel,
315
+ endLabelColor,
316
+ areaFill = "none",
317
+ areaColor,
318
+ areaOpacity,
319
+ areaFadeBottom,
320
+ areaPattern = "diagonal-up",
321
+ areaPatternScale = 1.5,
322
+ areaPatternTint = 0,
323
+ target,
324
+ targetStroke = "var(--chart-foreground-muted)",
325
+ targetDasharray = "4,4",
326
+ targetStrokeOpacity = 0.6,
327
+ showTargetMarker = true,
328
+ showGuides = false,
329
+ guideStroke = "var(--chart-foreground-muted)",
330
+ guideStrokeOpacity = 0.35,
331
+ className
332
+ }) {
333
+ const { chartPhase, innerHeight } = useChartStable();
334
+ const gradientId = useId().replace(/:/g, "");
335
+ const showMarker = showEndMarker ?? showEndpoints ?? true;
336
+ const isGradient = strokeStyle === "gradient";
337
+ const { geometry, getX, getY, yScale } = useProjectionGeometry({
338
+ data,
339
+ yAxisId,
340
+ showMarker,
341
+ endpointRadius,
342
+ strokeWidth
343
+ });
344
+ const { bezierPath, linearPath, topPath } = useMemo(
345
+ () => projectionSegmentPaths(geometry, curveKind),
346
+ [curveKind, geometry]
347
+ );
348
+ const targetY = target != null && Number.isFinite(target) ? yScale(target) ?? null : null;
349
+ const crossingX = useMemo(
350
+ () => geometry && targetY != null ? projectionCrossingX(
351
+ geometry.startX,
352
+ geometry.startY,
353
+ geometry.visibleEndX,
354
+ geometry.endY,
355
+ targetY,
356
+ curveKind
357
+ ) : null,
358
+ [curveKind, geometry, targetY]
359
+ );
360
+ const showStroke = chartPhase === "revealing" || chartPhase === "ready" || chartPhase === "exitingReady";
361
+ if (data.length < 2 || !geometry) {
362
+ return null;
363
+ }
364
+ const endColor = isGradient ? gradientEnd : stroke;
365
+ const markerRadius = endpointRadius * 0.85;
366
+ const strokeProps = {
367
+ stroke: isGradient ? `url(#${gradientId})` : stroke,
368
+ strokeDasharray,
369
+ strokeLinecap: "round",
370
+ strokeOpacity,
371
+ strokeWidth
372
+ };
373
+ return /* @__PURE__ */ jsxs(
374
+ m.g,
375
+ {
376
+ animate: { opacity: showStroke ? 1 : 0 },
377
+ className: className ?? "chart-projection-line",
378
+ initial: { opacity: 0 },
379
+ transition: ENTER_FADE,
380
+ children: [
381
+ isGradient ? /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
382
+ "linearGradient",
383
+ {
384
+ gradientUnits: "userSpaceOnUse",
385
+ id: gradientId,
386
+ x1: geometry.startX,
387
+ x2: geometry.visibleEndX,
388
+ y1: geometry.startY,
389
+ y2: geometry.endY,
390
+ children: [
391
+ /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: gradientStart ?? stroke }),
392
+ /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: gradientEnd })
393
+ ]
394
+ }
395
+ ) }) : null,
396
+ areaFill !== "none" && topPath ? /* @__PURE__ */ jsx(
397
+ ProjectionArea,
398
+ {
399
+ areaFill,
400
+ bottom: innerHeight,
401
+ color: areaColor ?? endColor,
402
+ d: `${topPath} L ${geometry.visibleEndX},${innerHeight} L ${geometry.startX},${innerHeight} Z`,
403
+ fadeBottom: areaFadeBottom,
404
+ opacity: areaOpacity,
405
+ pattern: areaPattern,
406
+ patternScale: areaPatternScale,
407
+ patternTint: areaPatternTint,
408
+ top: Math.min(geometry.startY, geometry.endY),
409
+ uid: gradientId
410
+ }
411
+ ) : null,
412
+ /* @__PURE__ */ jsx(
413
+ ProjectionTargetOverlay,
414
+ {
415
+ color: endColor,
416
+ crossingX,
417
+ endpointRadius,
418
+ geometry,
419
+ guideStroke,
420
+ guideStrokeOpacity,
421
+ markerFill: endMarkerFill ?? "var(--chart-background)",
422
+ markerRadius,
423
+ showGuides,
424
+ showTargetMarker,
425
+ targetDasharray,
426
+ targetStroke,
427
+ targetStrokeOpacity,
428
+ targetY
429
+ }
430
+ ),
431
+ renderProjectionStroke({
432
+ bezierPath,
433
+ curve,
434
+ curveKind,
435
+ data,
436
+ getX,
437
+ getY,
438
+ linearPath,
439
+ strokeProps
440
+ }),
441
+ /* @__PURE__ */ jsx(
442
+ ProjectionHorizon,
443
+ {
444
+ color: endColor,
445
+ fill: endMarkerFill,
446
+ fillOpacity: strokeOpacity,
447
+ formatLabel: formatEndLabel,
448
+ labelColor: endLabelColor,
449
+ radius: markerRadius,
450
+ showLabel: showEndLabel,
451
+ showMarker,
452
+ value: data.at(-1)?.value ?? 0,
453
+ x: geometry.visibleEndX,
454
+ y: geometry.endY
455
+ }
456
+ )
457
+ ]
458
+ }
459
+ );
460
+ }
461
+ ProjectionLine.displayName = "ProjectionLine";
462
+ var projection_line_default = ProjectionLine;
463
+ export {
464
+ ProjectionLine,
465
+ projection_line_default as default
466
+ };