@aiconstructions/graficos 0.0.0-stage → 0.2.2

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 +57 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +189 -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,368 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { m } from "motion/react";
4
+ import { memo, useMemo } from "react";
5
+ import { useChart, useYScale } from "./chart-context";
6
+ import { useChartLegendHover } from "./chart-legend-hover";
7
+ import { transitionWithDelay } from "./motion-utils";
8
+ const DEFAULT_POSITIVE = "url(#candlestick-positive)";
9
+ const DEFAULT_NEGATIVE = "url(#candlestick-negative)";
10
+ const SOLID_POSITIVE = "var(--chart-positive, var(--chart-positive))";
11
+ const SOLID_NEGATIVE = "var(--chart-negative, var(--chart-negative))";
12
+ const WICK_WIDTH = 1.5;
13
+ function getSolidColor(isPositive) {
14
+ return isPositive ? SOLID_POSITIVE : SOLID_NEGATIVE;
15
+ }
16
+ function computeGeometries(renderData, xScale, yScale, xAccessor, candleWidth, positiveFill, negativeFill, bodyPatternPositive, bodyPatternNegative, insideStrokeWidth) {
17
+ return renderData.map((d) => {
18
+ const date = xAccessor(d);
19
+ const open = d.open;
20
+ const high = d.high;
21
+ const low = d.low;
22
+ const close = d.close;
23
+ const centerX = xScale(date) ?? 0;
24
+ const yHigh = yScale(high) ?? 0;
25
+ const yLow = yScale(low) ?? 0;
26
+ const yOpen = yScale(open) ?? 0;
27
+ const yClose = yScale(close) ?? 0;
28
+ const bodyTop = Math.min(yOpen, yClose);
29
+ const bodyHeight = Math.abs(yClose - yOpen) || 1;
30
+ const bodyLeft = centerX - candleWidth / 2;
31
+ const wickTop = Math.min(yHigh, yLow);
32
+ const wickHeight = Math.abs(yLow - yHigh) || 1;
33
+ const isPositive = close >= open;
34
+ const fill = isPositive ? positiveFill : negativeFill;
35
+ const bodyPattern = isPositive ? bodyPatternPositive : bodyPatternNegative;
36
+ const hasPatternOverlay = Boolean(bodyPattern);
37
+ const bodySolidFill = hasPatternOverlay ? getSolidColor(isPositive) : fill;
38
+ return {
39
+ time: date.getTime(),
40
+ centerX,
41
+ bodyTop,
42
+ bodyHeight,
43
+ bodyLeft,
44
+ candleWidth,
45
+ wickTop,
46
+ wickHeight,
47
+ wickLeft: centerX - WICK_WIDTH / 2,
48
+ bodySolidFill,
49
+ wickFill: hasPatternOverlay ? bodySolidFill : fill,
50
+ bodyPattern: hasPatternOverlay ? bodyPattern : void 0,
51
+ insideStrokeWidth,
52
+ isPositive
53
+ };
54
+ });
55
+ }
56
+ function geometryDimOpacity(geometry, fadedOpacity, legendHoveredIndex, hoveredTime) {
57
+ if (legendHoveredIndex !== null) {
58
+ const dimFromLegend = legendHoveredIndex === 0 && !geometry.isPositive || legendHoveredIndex === 1 && geometry.isPositive;
59
+ return dimFromLegend ? fadedOpacity : 1;
60
+ }
61
+ if (hoveredTime !== null && geometry.time !== hoveredTime) {
62
+ return fadedOpacity;
63
+ }
64
+ return 1;
65
+ }
66
+ const CandlestickBody = memo(function CandlestickBody2({
67
+ geometry
68
+ }) {
69
+ const {
70
+ wickLeft,
71
+ wickTop,
72
+ wickHeight,
73
+ wickFill,
74
+ bodyLeft,
75
+ bodyTop,
76
+ bodyHeight,
77
+ candleWidth,
78
+ bodySolidFill,
79
+ bodyPattern,
80
+ insideStrokeWidth
81
+ } = geometry;
82
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
83
+ /* @__PURE__ */ jsx(
84
+ "rect",
85
+ {
86
+ fill: wickFill,
87
+ height: wickHeight,
88
+ width: WICK_WIDTH,
89
+ x: wickLeft,
90
+ y: wickTop
91
+ }
92
+ ),
93
+ /* @__PURE__ */ jsx(
94
+ "rect",
95
+ {
96
+ fill: bodySolidFill,
97
+ height: bodyHeight,
98
+ rx: 1,
99
+ ry: 1,
100
+ stroke: bodySolidFill,
101
+ strokeWidth: 1,
102
+ width: candleWidth,
103
+ x: bodyLeft,
104
+ y: bodyTop
105
+ }
106
+ ),
107
+ bodyPattern ? /* @__PURE__ */ jsx(
108
+ "rect",
109
+ {
110
+ fill: bodyPattern,
111
+ height: bodyHeight,
112
+ rx: 1,
113
+ ry: 1,
114
+ width: candleWidth,
115
+ x: bodyLeft,
116
+ y: bodyTop
117
+ }
118
+ ) : null,
119
+ insideStrokeWidth > 0 ? /* @__PURE__ */ jsx(
120
+ "rect",
121
+ {
122
+ fill: "none",
123
+ height: Math.max(0, bodyHeight - insideStrokeWidth),
124
+ rx: 1,
125
+ ry: 1,
126
+ stroke: bodySolidFill,
127
+ strokeWidth: insideStrokeWidth,
128
+ width: Math.max(0, candleWidth - insideStrokeWidth),
129
+ x: bodyLeft + insideStrokeWidth / 2,
130
+ y: bodyTop + insideStrokeWidth / 2
131
+ }
132
+ ) : null
133
+ ] });
134
+ });
135
+ const CandlestickBodies = memo(function CandlestickBodies2({
136
+ geometries,
137
+ fadedOpacity,
138
+ legendHoveredIndex,
139
+ hoveredTime
140
+ }) {
141
+ return /* @__PURE__ */ jsx(Fragment, { children: geometries.map((geometry) => /* @__PURE__ */ jsx(
142
+ "g",
143
+ {
144
+ opacity: geometryDimOpacity(
145
+ geometry,
146
+ fadedOpacity,
147
+ legendHoveredIndex,
148
+ hoveredTime
149
+ ),
150
+ style: { transition: "opacity 0.15s ease-in-out" },
151
+ children: /* @__PURE__ */ jsx(CandlestickBody, { geometry })
152
+ },
153
+ geometry.time
154
+ )) });
155
+ });
156
+ function AnimatedCandle({
157
+ geometry,
158
+ delay,
159
+ enterTransition,
160
+ revealEpoch
161
+ }) {
162
+ const t = transitionWithDelay(enterTransition, delay);
163
+ const bodyOrigin = `${geometry.centerX}px ${geometry.bodyTop + geometry.bodyHeight / 2}px`;
164
+ const wickCenterY = geometry.wickTop + geometry.wickHeight / 2;
165
+ return /* @__PURE__ */ jsxs(
166
+ m.g,
167
+ {
168
+ animate: { opacity: 1 },
169
+ initial: { opacity: 0 },
170
+ style: { transformOrigin: `${geometry.centerX}px ${wickCenterY}px` },
171
+ transition: { ...t, opacity: { duration: 0.15 } },
172
+ children: [
173
+ /* @__PURE__ */ jsx(
174
+ m.rect,
175
+ {
176
+ animate: { scaleY: 1 },
177
+ fill: geometry.wickFill,
178
+ height: geometry.wickHeight,
179
+ initial: { scaleY: 0 },
180
+ style: { transformOrigin: `${geometry.centerX}px ${wickCenterY}px` },
181
+ transition: t,
182
+ width: WICK_WIDTH,
183
+ x: geometry.wickLeft,
184
+ y: geometry.wickTop
185
+ }
186
+ ),
187
+ /* @__PURE__ */ jsx(
188
+ m.rect,
189
+ {
190
+ animate: { scaleY: 1 },
191
+ fill: geometry.bodySolidFill,
192
+ height: geometry.bodyHeight,
193
+ initial: { scaleY: 0 },
194
+ rx: 1,
195
+ ry: 1,
196
+ stroke: geometry.bodySolidFill,
197
+ strokeWidth: 1,
198
+ style: { transformOrigin: bodyOrigin },
199
+ transition: t,
200
+ width: geometry.candleWidth,
201
+ x: geometry.bodyLeft,
202
+ y: geometry.bodyTop
203
+ }
204
+ ),
205
+ geometry.bodyPattern ? /* @__PURE__ */ jsx(
206
+ m.rect,
207
+ {
208
+ animate: { scaleY: 1 },
209
+ fill: geometry.bodyPattern,
210
+ height: geometry.bodyHeight,
211
+ initial: { scaleY: 0 },
212
+ rx: 1,
213
+ ry: 1,
214
+ style: { transformOrigin: bodyOrigin },
215
+ transition: t,
216
+ width: geometry.candleWidth,
217
+ x: geometry.bodyLeft,
218
+ y: geometry.bodyTop
219
+ }
220
+ ) : null
221
+ ]
222
+ },
223
+ `candle-enter-${geometry.time}-${revealEpoch}`
224
+ );
225
+ }
226
+ function Candlestick({
227
+ animate = true,
228
+ positiveFill = DEFAULT_POSITIVE,
229
+ negativeFill = DEFAULT_NEGATIVE,
230
+ bodyPatternPositive,
231
+ bodyPatternNegative,
232
+ insideStrokeWidth = 0,
233
+ fadedOpacity = 0.3,
234
+ showHoverFade = true,
235
+ yAxisId,
236
+ widthRatio = 0.6
237
+ }) {
238
+ const {
239
+ data,
240
+ xScale,
241
+ xAccessor,
242
+ animationDuration,
243
+ enterTransition,
244
+ revealEpoch = 0,
245
+ isLoaded,
246
+ bandWidth,
247
+ columnWidth,
248
+ hoveredCandleIndex: chartHoveredCandleIndex,
249
+ tooltipData
250
+ } = useChart();
251
+ const yScale = useYScale(yAxisId);
252
+ const { hoveredIndex: legendHoveredIndex } = useChartLegendHover();
253
+ const inCandlestickChart = bandWidth != null;
254
+ const hoveredCandleIndex = chartHoveredCandleIndex ?? tooltipData?.index ?? null;
255
+ const ratio = Math.min(Math.max(widthRatio, 0.05), 1);
256
+ const candleWidth = Math.max(
257
+ 1,
258
+ Math.min(
259
+ bandWidth ?? columnWidth * ratio,
260
+ columnWidth || Number.POSITIVE_INFINITY
261
+ )
262
+ );
263
+ const resolvedPositiveFill = !inCandlestickChart && positiveFill === DEFAULT_POSITIVE ? SOLID_POSITIVE : positiveFill;
264
+ const resolvedNegativeFill = !inCandlestickChart && negativeFill === DEFAULT_NEGATIVE ? SOLID_NEGATIVE : negativeFill;
265
+ const geometries = useMemo(
266
+ () => computeGeometries(
267
+ data,
268
+ xScale,
269
+ yScale,
270
+ xAccessor,
271
+ candleWidth,
272
+ resolvedPositiveFill,
273
+ resolvedNegativeFill,
274
+ bodyPatternPositive,
275
+ bodyPatternNegative,
276
+ insideStrokeWidth
277
+ ),
278
+ [
279
+ data,
280
+ xScale,
281
+ yScale,
282
+ xAccessor,
283
+ candleWidth,
284
+ resolvedPositiveFill,
285
+ resolvedNegativeFill,
286
+ bodyPatternPositive,
287
+ bodyPatternNegative,
288
+ insideStrokeWidth
289
+ ]
290
+ );
291
+ const hoveredTime = useMemo(() => {
292
+ if (hoveredCandleIndex == null) {
293
+ return null;
294
+ }
295
+ const point = data[hoveredCandleIndex];
296
+ return point ? xAccessor(point).getTime() : null;
297
+ }, [hoveredCandleIndex, data, xAccessor]);
298
+ const highlightGeometry = useMemo(() => {
299
+ if (hoveredCandleIndex == null) {
300
+ return null;
301
+ }
302
+ const point = data[hoveredCandleIndex];
303
+ if (!point) {
304
+ return null;
305
+ }
306
+ return computeGeometries(
307
+ [point],
308
+ xScale,
309
+ yScale,
310
+ xAccessor,
311
+ candleWidth,
312
+ resolvedPositiveFill,
313
+ resolvedNegativeFill,
314
+ bodyPatternPositive,
315
+ bodyPatternNegative,
316
+ insideStrokeWidth
317
+ )[0] ?? null;
318
+ }, [
319
+ hoveredCandleIndex,
320
+ data,
321
+ xScale,
322
+ yScale,
323
+ xAccessor,
324
+ candleWidth,
325
+ resolvedPositiveFill,
326
+ resolvedNegativeFill,
327
+ bodyPatternPositive,
328
+ bodyPatternNegative,
329
+ insideStrokeWidth
330
+ ]);
331
+ const defaultEnter = {
332
+ type: "spring",
333
+ duration: 0.8,
334
+ bounce: 0.15
335
+ };
336
+ const enter = enterTransition ?? defaultEnter;
337
+ const staggerDelayMs = data.length > 0 ? animationDuration * 0.6 / data.length : 0;
338
+ if (animate && !isLoaded) {
339
+ return /* @__PURE__ */ jsx("g", { className: "chart-candlesticks", children: geometries.map((geometry, index) => /* @__PURE__ */ jsx(
340
+ AnimatedCandle,
341
+ {
342
+ delay: index * staggerDelayMs / 1e3,
343
+ enterTransition: enter,
344
+ geometry,
345
+ revealEpoch
346
+ },
347
+ geometry.time
348
+ )) });
349
+ }
350
+ return /* @__PURE__ */ jsxs("g", { className: "chart-candlesticks", children: [
351
+ /* @__PURE__ */ jsx(
352
+ CandlestickBodies,
353
+ {
354
+ fadedOpacity,
355
+ geometries,
356
+ hoveredTime: showHoverFade ? hoveredTime : null,
357
+ legendHoveredIndex
358
+ }
359
+ ),
360
+ highlightGeometry ? /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(CandlestickBody, { geometry: highlightGeometry }) }) : null
361
+ ] });
362
+ }
363
+ Candlestick.displayName = "Candlestick";
364
+ var candlestick_default = Candlestick;
365
+ export {
366
+ Candlestick,
367
+ candlestick_default as default
368
+ };
@@ -0,0 +1,91 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createPortal } from "react-dom";
4
+ import { useChartPortalContainer, useChartStable } from "./chart-context";
5
+ const HANDLE_HEIGHT_PX = 24;
6
+ const HANDLE_WIDTH_PX = 4;
7
+ function brushHandleCursor(className) {
8
+ return className.includes("left") || className.includes("right") ? "ew-resize" : "ns-resize";
9
+ }
10
+ function renderChartBrushHandle({
11
+ x,
12
+ y,
13
+ width,
14
+ height,
15
+ className
16
+ }) {
17
+ return /* @__PURE__ */ jsx(
18
+ "rect",
19
+ {
20
+ className,
21
+ fill: "transparent",
22
+ height,
23
+ style: { cursor: brushHandleCursor(className) },
24
+ width,
25
+ x,
26
+ y
27
+ }
28
+ );
29
+ }
30
+ function ChartBrushHandleOverlayContent({
31
+ containerRef,
32
+ margin,
33
+ innerWidth,
34
+ innerHeight,
35
+ selectionX0,
36
+ selectionX1
37
+ }) {
38
+ const container = useChartPortalContainer(containerRef);
39
+ if (!container) {
40
+ return null;
41
+ }
42
+ const x0 = Math.max(0, Math.min(selectionX0, selectionX1, innerWidth));
43
+ const x1 = Math.max(
44
+ x0,
45
+ Math.min(Math.max(selectionX0, selectionX1), innerWidth)
46
+ );
47
+ const edges = x0 === x1 ? [x0] : [x0, x1];
48
+ const plotLeft = margin.left;
49
+ const plotTop = margin.top;
50
+ const handleTop = plotTop + (innerHeight - HANDLE_HEIGHT_PX) / 2;
51
+ return createPortal(
52
+ /* @__PURE__ */ jsx(
53
+ "div",
54
+ {
55
+ "aria-hidden": "true",
56
+ className: "pointer-events-none absolute inset-0 z-[2]",
57
+ children: edges.map((edgeX) => /* @__PURE__ */ jsx(
58
+ "div",
59
+ {
60
+ className: "absolute shrink-0 rounded-lg",
61
+ style: {
62
+ top: handleTop,
63
+ left: plotLeft + edgeX - HANDLE_WIDTH_PX / 2,
64
+ width: HANDLE_WIDTH_PX,
65
+ height: HANDLE_HEIGHT_PX,
66
+ backgroundColor: "var(--chart-brush-border)"
67
+ }
68
+ },
69
+ edgeX
70
+ ))
71
+ }
72
+ ),
73
+ container
74
+ );
75
+ }
76
+ function ChartBrushHandleOverlay(props) {
77
+ const { containerRef, margin } = useChartStable();
78
+ return /* @__PURE__ */ jsx(
79
+ ChartBrushHandleOverlayContent,
80
+ {
81
+ ...props,
82
+ containerRef,
83
+ margin
84
+ }
85
+ );
86
+ }
87
+ export {
88
+ ChartBrushHandleOverlay,
89
+ ChartBrushHandleOverlayContent,
90
+ renderChartBrushHandle
91
+ };
@@ -0,0 +1,91 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ memo,
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useState
9
+ } from "react";
10
+ import { cn } from "../lib/utils";
11
+ import { useChartDataOverride } from "./chart-data-override";
12
+ import { resolveBrushTrackXExtent } from "./filter-data-by-x-domain";
13
+ function createXAccessor(xDataKey) {
14
+ return (d) => {
15
+ const value = d[xDataKey];
16
+ return value instanceof Date ? value : new Date(value);
17
+ };
18
+ }
19
+ const ChartBrushLayout = memo(function ChartBrushLayout2({
20
+ data: dataProp,
21
+ xDataKey = "date",
22
+ xExtentMax,
23
+ enabled,
24
+ height,
25
+ fitMainContent = false,
26
+ className,
27
+ children,
28
+ brushStrip
29
+ }) {
30
+ const { data } = useChartDataOverride("ChartBrushLayout", { data: dataProp });
31
+ const xAccessor = useMemo(() => createXAccessor(xDataKey), [xDataKey]);
32
+ const fullExtent = useMemo(
33
+ () => resolveBrushTrackXExtent(data, xAccessor, xExtentMax),
34
+ [data, xAccessor, xExtentMax]
35
+ );
36
+ const [brushSelection, setBrushSelection] = useState(null);
37
+ useEffect(() => {
38
+ if (!fullExtent) {
39
+ setBrushSelection(null);
40
+ return;
41
+ }
42
+ setBrushSelection({ start: fullExtent[0], end: fullExtent[1] });
43
+ }, [fullExtent]);
44
+ const handleBrushSelectionChange = useCallback(
45
+ (selection) => {
46
+ if (!selection) {
47
+ if (fullExtent) {
48
+ setBrushSelection({ start: fullExtent[0], end: fullExtent[1] });
49
+ }
50
+ return;
51
+ }
52
+ setBrushSelection(selection);
53
+ },
54
+ [fullExtent]
55
+ );
56
+ const layoutState = useMemo(
57
+ () => ({
58
+ xDomain: enabled && brushSelection ? [brushSelection.start, brushSelection.end] : void 0,
59
+ xDomainSlotCount: enabled ? data.length : void 0,
60
+ brushSelection,
61
+ onBrushSelectionChange: handleBrushSelectionChange
62
+ }),
63
+ [brushSelection, data.length, enabled, handleBrushSelectionChange]
64
+ );
65
+ return /* @__PURE__ */ jsxs(
66
+ "div",
67
+ {
68
+ className: cn(
69
+ "flex size-full min-h-0 min-w-0 flex-col",
70
+ fitMainContent ? "justify-start gap-1" : "gap-3",
71
+ className
72
+ ),
73
+ children: [
74
+ /* @__PURE__ */ jsx(
75
+ "div",
76
+ {
77
+ className: cn(
78
+ "min-h-0 min-w-0",
79
+ fitMainContent ? "shrink-0" : "flex-1"
80
+ ),
81
+ children: children(layoutState)
82
+ }
83
+ ),
84
+ enabled && brushStrip ? /* @__PURE__ */ jsx("div", { className: "min-h-0 shrink-0", style: { height }, children: brushStrip(layoutState) }) : null
85
+ ]
86
+ }
87
+ );
88
+ });
89
+ export {
90
+ ChartBrushLayout
91
+ };
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useId } from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { useChartPortalContainer, useChartStable } from "./chart-context";
6
+ import {
7
+ renderPatternPreset
8
+ } from "./pattern-preset";
9
+ function ChartBrushSelectionOverlayContent({
10
+ containerRef,
11
+ margin,
12
+ innerWidth,
13
+ innerHeight,
14
+ selectionX0,
15
+ selectionX1,
16
+ pattern
17
+ }) {
18
+ const patternId = useId().replace(/:/g, "");
19
+ const container = useChartPortalContainer(containerRef);
20
+ if (!(container && pattern && pattern.preset !== "none")) {
21
+ return null;
22
+ }
23
+ const x0 = Math.max(0, Math.min(selectionX0, selectionX1, innerWidth));
24
+ const x1 = Math.max(
25
+ x0,
26
+ Math.min(Math.max(selectionX0, selectionX1), innerWidth)
27
+ );
28
+ const selectionWidth = x1 - x0;
29
+ if (selectionWidth <= 0) {
30
+ return null;
31
+ }
32
+ const plotLeft = margin.left;
33
+ const plotTop = margin.top;
34
+ const patternNode = renderPatternPreset(pattern.preset, patternId, {
35
+ color: pattern.color,
36
+ scale: pattern.scale,
37
+ strokeWidth: pattern.strokeWidth,
38
+ radius: pattern.radius,
39
+ complement: pattern.complement,
40
+ fill: pattern.fill,
41
+ tileBackground: pattern.tileBackground
42
+ });
43
+ if (!patternNode) {
44
+ return null;
45
+ }
46
+ return createPortal(
47
+ /* @__PURE__ */ jsxs(
48
+ "svg",
49
+ {
50
+ "aria-hidden": "true",
51
+ className: "pointer-events-none absolute inset-0 z-[1]",
52
+ height: "100%",
53
+ width: "100%",
54
+ children: [
55
+ /* @__PURE__ */ jsx("defs", { children: patternNode }),
56
+ /* @__PURE__ */ jsx(
57
+ "rect",
58
+ {
59
+ fill: `url(#${patternId})`,
60
+ fillOpacity: pattern.opacity ?? 1,
61
+ height: innerHeight,
62
+ width: selectionWidth,
63
+ x: plotLeft + x0,
64
+ y: plotTop
65
+ }
66
+ )
67
+ ]
68
+ }
69
+ ),
70
+ container
71
+ );
72
+ }
73
+ function ChartBrushSelectionOverlay(props) {
74
+ const { containerRef, margin } = useChartStable();
75
+ return /* @__PURE__ */ jsx(
76
+ ChartBrushSelectionOverlayContent,
77
+ {
78
+ ...props,
79
+ containerRef,
80
+ margin
81
+ }
82
+ );
83
+ }
84
+ export {
85
+ ChartBrushSelectionOverlay,
86
+ ChartBrushSelectionOverlayContent
87
+ };