@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.
- package/ALTERACOES.md +53 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +188 -2
- package/dist/aic/cores.js +83 -0
- package/dist/aic/index.js +22 -0
- package/dist/aic/interacao.js +55 -0
- package/dist/charts/animation.js +55 -0
- package/dist/charts/arc-geometry.js +58 -0
- package/dist/charts/arc-path.js +15 -0
- package/dist/charts/area-chart-loading.js +89 -0
- package/dist/charts/area-chart.js +149 -0
- package/dist/charts/area-gradient-defs.js +90 -0
- package/dist/charts/area-value-label-layout.js +70 -0
- package/dist/charts/area-value-labels.js +211 -0
- package/dist/charts/area.js +272 -0
- package/dist/charts/background.js +198 -0
- package/dist/charts/band-config.js +82 -0
- package/dist/charts/band-geometry.js +186 -0
- package/dist/charts/band.js +346 -0
- package/dist/charts/bar-chart-loading.js +27 -0
- package/dist/charts/bar-chart.js +545 -0
- package/dist/charts/bar-depth-geometry.js +18 -0
- package/dist/charts/bar-depth.js +608 -0
- package/dist/charts/bar-lollipop.js +278 -0
- package/dist/charts/bar-squares-layout.js +66 -0
- package/dist/charts/bar-squares.js +467 -0
- package/dist/charts/bar-value-label-layout.js +42 -0
- package/dist/charts/bar-x-axis.js +133 -0
- package/dist/charts/bar-y-axis.js +116 -0
- package/dist/charts/bar.js +457 -0
- package/dist/charts/bollinger.js +49 -0
- package/dist/charts/candlestick-chart.js +370 -0
- package/dist/charts/candlestick.js +368 -0
- package/dist/charts/chart-brush-handle.js +91 -0
- package/dist/charts/chart-brush-layout.js +91 -0
- package/dist/charts/chart-brush-selection-overlay.js +87 -0
- package/dist/charts/chart-brush-state.js +253 -0
- package/dist/charts/chart-brush-track-overlay.js +103 -0
- package/dist/charts/chart-brush.js +517 -0
- package/dist/charts/chart-center-typography.js +8 -0
- package/dist/charts/chart-child-passthrough.js +119 -0
- package/dist/charts/chart-config-context.js +56 -0
- package/dist/charts/chart-context.js +337 -0
- package/dist/charts/chart-crosshair.js +262 -0
- package/dist/charts/chart-data-override.js +186 -0
- package/dist/charts/chart-defs.js +56 -0
- package/dist/charts/chart-formatters.js +77 -0
- package/dist/charts/chart-legend-hover.js +27 -0
- package/dist/charts/chart-legend.js +163 -0
- package/dist/charts/chart-loading-label.js +52 -0
- package/dist/charts/chart-parent-size.js +138 -0
- package/dist/charts/chart-phase.js +29 -0
- package/dist/charts/chart-reveal-clip.js +62 -0
- package/dist/charts/chart-scale.js +19 -0
- package/dist/charts/chart-stat-flow.js +72 -0
- package/dist/charts/choropleth/choropleth-background.js +29 -0
- package/dist/charts/choropleth/choropleth-camera.js +379 -0
- package/dist/charts/choropleth/choropleth-chart.js +644 -0
- package/dist/charts/choropleth/choropleth-context.js +152 -0
- package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
- package/dist/charts/choropleth/choropleth-feature.js +291 -0
- package/dist/charts/choropleth/choropleth-graticule.js +40 -0
- package/dist/charts/choropleth/choropleth-marker.js +222 -0
- package/dist/charts/choropleth/choropleth-projection.js +37 -0
- package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
- package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
- package/dist/charts/choropleth/index.js +44 -0
- package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
- package/dist/charts/composed-chart.js +346 -0
- package/dist/charts/crosshair-store.js +49 -0
- package/dist/charts/dash-tail-stroke.js +58 -0
- package/dist/charts/date-pill-store.js +50 -0
- package/dist/charts/date-ranges.js +131 -0
- package/dist/charts/deadline.js +295 -0
- package/dist/charts/decimate-time-series.js +112 -0
- package/dist/charts/fade-edges.js +171 -0
- package/dist/charts/fast-path.js +78 -0
- package/dist/charts/filter-data-by-x-domain.js +45 -0
- package/dist/charts/funnel-chart.js +773 -0
- package/dist/charts/gauge-arc-layers.js +479 -0
- package/dist/charts/gauge-dial.js +329 -0
- package/dist/charts/gauge-label-layout.js +148 -0
- package/dist/charts/gauge.js +946 -0
- package/dist/charts/generate-chart-skeleton-data.js +27 -0
- package/dist/charts/gradients.js +158 -0
- package/dist/charts/grid-lines.js +114 -0
- package/dist/charts/grid.js +225 -0
- package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
- package/dist/charts/heatmap/heatmap-animation.js +128 -0
- package/dist/charts/heatmap/heatmap-cells.js +519 -0
- package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
- package/dist/charts/heatmap/heatmap-chart.js +548 -0
- package/dist/charts/heatmap/heatmap-colors.js +127 -0
- package/dist/charts/heatmap/heatmap-context.js +107 -0
- package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
- package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
- package/dist/charts/heatmap/heatmap-legend.js +165 -0
- package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
- package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
- package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
- package/dist/charts/heatmap/heatmap-separator.js +168 -0
- package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
- package/dist/charts/heatmap/heatmap-utils.js +633 -0
- package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
- package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
- package/dist/charts/heatmap/index.js +208 -0
- package/dist/charts/highlight-segment-bounds.js +34 -0
- package/dist/charts/highlight-segment.js +119 -0
- package/dist/charts/index.js +944 -0
- package/dist/charts/indicator-fade.js +44 -0
- package/dist/charts/legend/index.js +22 -0
- package/dist/charts/legend/legend-context.js +47 -0
- package/dist/charts/legend/legend-item.js +30 -0
- package/dist/charts/legend/legend-label.js +14 -0
- package/dist/charts/legend/legend-marker.js +18 -0
- package/dist/charts/legend/legend-progress.js +39 -0
- package/dist/charts/legend/legend-value.js +31 -0
- package/dist/charts/legend/legend.js +69 -0
- package/dist/charts/line-backdrop.js +129 -0
- package/dist/charts/line-chart-loading.js +85 -0
- package/dist/charts/line-chart.js +182 -0
- package/dist/charts/line-loading-pulse.js +185 -0
- package/dist/charts/line-loading-timing.js +12 -0
- package/dist/charts/line-path.js +58 -0
- package/dist/charts/line-series-terminal-marker.js +75 -0
- package/dist/charts/line.js +499 -0
- package/dist/charts/live-line-chart.js +494 -0
- package/dist/charts/live-line.js +277 -0
- package/dist/charts/live-x-axis.js +116 -0
- package/dist/charts/live-y-axis.js +164 -0
- package/dist/charts/loading-sweep.js +344 -0
- package/dist/charts/local-point.js +56 -0
- package/dist/charts/markers/chart-markers.js +149 -0
- package/dist/charts/markers/index.js +14 -0
- package/dist/charts/markers/marker-group.js +411 -0
- package/dist/charts/motion-utils.js +29 -0
- package/dist/charts/notch-gauge-shared.js +146 -0
- package/dist/charts/particle-line.js +1340 -0
- package/dist/charts/path-stroke-utils.js +51 -0
- package/dist/charts/pattern-area.js +127 -0
- package/dist/charts/pattern-preset.js +287 -0
- package/dist/charts/pattern-tile.js +31 -0
- package/dist/charts/patterns/circles.js +62 -0
- package/dist/charts/patterns/constants.js +9 -0
- package/dist/charts/patterns/hexagons.js +38 -0
- package/dist/charts/patterns/index.js +16 -0
- package/dist/charts/patterns/lines.js +65 -0
- package/dist/charts/patterns/path.js +37 -0
- package/dist/charts/patterns/pattern.js +16 -0
- package/dist/charts/patterns/waves.js +40 -0
- package/dist/charts/pie-center-shell.js +127 -0
- package/dist/charts/pie-center.js +87 -0
- package/dist/charts/pie-chart.js +377 -0
- package/dist/charts/pie-context.js +116 -0
- package/dist/charts/pie-slice.js +394 -0
- package/dist/charts/pie-ticks.js +332 -0
- package/dist/charts/profit-loss-legend-hover.js +18 -0
- package/dist/charts/profit-loss-legend.js +53 -0
- package/dist/charts/profit-loss-line.js +162 -0
- package/dist/charts/profit-loss-segments.js +88 -0
- package/dist/charts/projection-config.js +90 -0
- package/dist/charts/projection-line-end-marker.js +50 -0
- package/dist/charts/projection-line.js +466 -0
- package/dist/charts/projection-utils.js +303 -0
- package/dist/charts/radar-area.js +192 -0
- package/dist/charts/radar-axis.js +41 -0
- package/dist/charts/radar-chart.js +184 -0
- package/dist/charts/radar-context.js +104 -0
- package/dist/charts/radar-grid.js +121 -0
- package/dist/charts/radar-labels.js +62 -0
- package/dist/charts/radial-area.js +498 -0
- package/dist/charts/radial-axis.js +652 -0
- package/dist/charts/radial-bar.js +316 -0
- package/dist/charts/radial-center.js +67 -0
- package/dist/charts/radial-chart.js +740 -0
- package/dist/charts/radial-dot-bar-layout.js +68 -0
- package/dist/charts/radial-dot-bar.js +387 -0
- package/dist/charts/radial-geometry.js +114 -0
- package/dist/charts/radial-legend.js +66 -0
- package/dist/charts/radial-line.js +280 -0
- package/dist/charts/radial-ring-bar.js +255 -0
- package/dist/charts/radial-scrubber.js +120 -0
- package/dist/charts/radial-series-color.js +10 -0
- package/dist/charts/reference-area-config.js +43 -0
- package/dist/charts/reference-area-geometry.js +76 -0
- package/dist/charts/reference-area-registration-context.js +10 -0
- package/dist/charts/reference-area.js +241 -0
- package/dist/charts/responsive-chart-label-count.js +18 -0
- package/dist/charts/ring-center.js +78 -0
- package/dist/charts/ring-chart.js +362 -0
- package/dist/charts/ring-context.js +122 -0
- package/dist/charts/ring-grid.js +175 -0
- package/dist/charts/ring-labels.js +109 -0
- package/dist/charts/ring.js +237 -0
- package/dist/charts/sankey/index.js +22 -0
- package/dist/charts/sankey/sankey-chart.js +199 -0
- package/dist/charts/sankey/sankey-context.js +32 -0
- package/dist/charts/sankey/sankey-link.js +232 -0
- package/dist/charts/sankey/sankey-node.js +348 -0
- package/dist/charts/sankey/sankey-tooltip.js +94 -0
- package/dist/charts/scatter-chart-shell.js +279 -0
- package/dist/charts/scatter-chart.js +150 -0
- package/dist/charts/scatter-jitter.js +86 -0
- package/dist/charts/scatter-svg.js +17 -0
- package/dist/charts/scatter.js +92 -0
- package/dist/charts/segment.js +107 -0
- package/dist/charts/series-bar-layout.js +42 -0
- package/dist/charts/series-bar.js +241 -0
- package/dist/charts/series-dash-tail-overlay.js +53 -0
- package/dist/charts/series-highlight-layer.js +43 -0
- package/dist/charts/series-hover-dim.js +32 -0
- package/dist/charts/series-markers.js +239 -0
- package/dist/charts/series-path-utils.js +185 -0
- package/dist/charts/series-point-marker.js +150 -0
- package/dist/charts/sparkline-geometry.js +197 -0
- package/dist/charts/sparkline.js +910 -0
- package/dist/charts/static-chart-preview-context.js +16 -0
- package/dist/charts/sunburst-breadcrumb.js +33 -0
- package/dist/charts/sunburst-center.js +37 -0
- package/dist/charts/sunburst-chart.js +408 -0
- package/dist/charts/sunburst-context.js +140 -0
- package/dist/charts/sunburst-data.js +0 -0
- package/dist/charts/sunburst-hint.js +42 -0
- package/dist/charts/sunburst-labels.js +130 -0
- package/dist/charts/sunburst-segment.js +144 -0
- package/dist/charts/sunburst.js +419 -0
- package/dist/charts/time-series-chart-shell.js +688 -0
- package/dist/charts/tooltip/chart-tooltip.js +516 -0
- package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
- package/dist/charts/tooltip/date-ticker.js +376 -0
- package/dist/charts/tooltip/index.js +32 -0
- package/dist/charts/tooltip/liquid-glass.js +142 -0
- package/dist/charts/tooltip/tooltip-box.js +502 -0
- package/dist/charts/tooltip/tooltip-content.js +59 -0
- package/dist/charts/tooltip/tooltip-dot.js +170 -0
- package/dist/charts/tooltip/tooltip-indicator.js +175 -0
- package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
- package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
- package/dist/charts/trend-line-utils.js +64 -0
- package/dist/charts/trend-line.js +318 -0
- package/dist/charts/use-animated-band.js +175 -0
- package/dist/charts/use-animated-series-path.js +208 -0
- package/dist/charts/use-animated-y-domains.js +192 -0
- package/dist/charts/use-category-slots.js +29 -0
- package/dist/charts/use-chart-interaction.js +296 -0
- package/dist/charts/use-chart-phase-orchestrator.js +183 -0
- package/dist/charts/use-enter-complete.js +18 -0
- package/dist/charts/use-grid-shimmer.js +88 -0
- package/dist/charts/use-highlight-segment.js +65 -0
- package/dist/charts/use-mount-progress.js +23 -0
- package/dist/charts/use-scatter-chart-interaction.js +364 -0
- package/dist/charts/use-scheduled-tooltip.js +84 -0
- package/dist/charts/visx-pattern.js +30 -0
- package/dist/charts/weekends.js +174 -0
- package/dist/charts/x-axis-hover.js +46 -0
- package/dist/charts/x-axis.js +523 -0
- package/dist/charts/y-axis-scales.js +71 -0
- package/dist/charts/y-axis-ticks.js +22 -0
- package/dist/charts/y-axis.js +233 -0
- package/dist/charts/y-domain-utils.js +189 -0
- package/dist/index.d.ts +7346 -0
- package/dist/index.js +2 -0
- package/dist/lib/utils.js +8 -0
- package/dist/shimmering-text.js +54 -0
- package/package.json +78 -4
- package/tema.css +202 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m, useSpring, useTransform } from "motion/react";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { useChartConfig } from "../chart-config-context";
|
|
6
|
+
import { chartCssVars } from "../chart-context";
|
|
7
|
+
const DEFAULT_HALO_SCALE = 2.6;
|
|
8
|
+
const DEFAULT_HALO_OPACITY = 0.3;
|
|
9
|
+
const HALO_SPRING = { type: "spring", stiffness: 420, damping: 28 };
|
|
10
|
+
function ringCornerRadius(halfExtent, cornerRadiusFraction) {
|
|
11
|
+
const side = halfExtent * 2;
|
|
12
|
+
return side * Math.max(0, Math.min(0.5, cornerRadiusFraction));
|
|
13
|
+
}
|
|
14
|
+
function AnimatedRingDot({
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
halfExtent,
|
|
18
|
+
cornerRadiusFraction,
|
|
19
|
+
fill,
|
|
20
|
+
stroke,
|
|
21
|
+
strokeWidth,
|
|
22
|
+
springConfig
|
|
23
|
+
}) {
|
|
24
|
+
const { tooltipSpring } = useChartConfig();
|
|
25
|
+
const effectiveSpring = springConfig ?? tooltipSpring;
|
|
26
|
+
const animatedX = useSpring(x, effectiveSpring);
|
|
27
|
+
const animatedY = useSpring(y, effectiveSpring);
|
|
28
|
+
const side = halfExtent * 2;
|
|
29
|
+
const rx = ringCornerRadius(halfExtent, cornerRadiusFraction);
|
|
30
|
+
const rectX = useTransform(animatedX, (value) => value - halfExtent);
|
|
31
|
+
const rectY = useTransform(animatedY, (value) => value - halfExtent);
|
|
32
|
+
animatedX.set(x);
|
|
33
|
+
animatedY.set(y);
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
m.rect,
|
|
36
|
+
{
|
|
37
|
+
fill,
|
|
38
|
+
height: side,
|
|
39
|
+
rx,
|
|
40
|
+
ry: rx,
|
|
41
|
+
stroke,
|
|
42
|
+
strokeWidth,
|
|
43
|
+
width: side,
|
|
44
|
+
x: rectX,
|
|
45
|
+
y: rectY
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function TooltipDot({
|
|
50
|
+
x,
|
|
51
|
+
y,
|
|
52
|
+
visible,
|
|
53
|
+
color,
|
|
54
|
+
size = 5,
|
|
55
|
+
strokeColor = chartCssVars.background,
|
|
56
|
+
strokeWidth,
|
|
57
|
+
haloScale = DEFAULT_HALO_SCALE,
|
|
58
|
+
haloOpacity = DEFAULT_HALO_OPACITY,
|
|
59
|
+
haloBlur = 0,
|
|
60
|
+
variant = "dot",
|
|
61
|
+
cornerRadiusFraction = 0.25,
|
|
62
|
+
springConfig,
|
|
63
|
+
animate = true
|
|
64
|
+
}) {
|
|
65
|
+
const { tooltipSpring } = useChartConfig();
|
|
66
|
+
const effectiveSpring = springConfig ?? tooltipSpring;
|
|
67
|
+
const animatedX = useSpring(x, effectiveSpring);
|
|
68
|
+
const animatedY = useSpring(y, effectiveSpring);
|
|
69
|
+
const haloFilterId = `tooltip-dot-halo-${useId()}`;
|
|
70
|
+
const isRing = variant === "ring";
|
|
71
|
+
if (animate && !isRing) {
|
|
72
|
+
animatedX.set(x);
|
|
73
|
+
animatedY.set(y);
|
|
74
|
+
}
|
|
75
|
+
if (!visible) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (isRing) {
|
|
79
|
+
const ringStrokeWidth = strokeWidth ?? 1.5;
|
|
80
|
+
if (animate) {
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
AnimatedRingDot,
|
|
83
|
+
{
|
|
84
|
+
cornerRadiusFraction,
|
|
85
|
+
fill: "transparent",
|
|
86
|
+
halfExtent: size,
|
|
87
|
+
springConfig,
|
|
88
|
+
stroke: color,
|
|
89
|
+
strokeWidth: ringStrokeWidth,
|
|
90
|
+
x,
|
|
91
|
+
y
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const side = size * 2;
|
|
96
|
+
const rx = ringCornerRadius(size, cornerRadiusFraction);
|
|
97
|
+
return /* @__PURE__ */ jsx(
|
|
98
|
+
"rect",
|
|
99
|
+
{
|
|
100
|
+
fill: "transparent",
|
|
101
|
+
height: side,
|
|
102
|
+
rx,
|
|
103
|
+
ry: rx,
|
|
104
|
+
stroke: color,
|
|
105
|
+
strokeWidth: ringStrokeWidth,
|
|
106
|
+
width: side,
|
|
107
|
+
x: x - size,
|
|
108
|
+
y: y - size
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const outlineWidth = strokeWidth ?? 0;
|
|
113
|
+
const outline = outlineWidth > 0 ? { stroke: strokeColor, strokeWidth: outlineWidth } : void 0;
|
|
114
|
+
const haloRadius = Math.max(0, size * haloScale);
|
|
115
|
+
const showHalo = haloRadius > size && haloOpacity > 0;
|
|
116
|
+
const blurHalo = showHalo && haloBlur > 0;
|
|
117
|
+
const haloFilter = blurHalo ? `url(#${haloFilterId})` : void 0;
|
|
118
|
+
const haloFilterDefs = blurHalo ? /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("filter", { height: "300%", id: haloFilterId, width: "300%", x: "-100%", y: "-100%", children: /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: haloBlur }) }) }) : null;
|
|
119
|
+
if (!animate) {
|
|
120
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
121
|
+
haloFilterDefs,
|
|
122
|
+
showHalo && /* @__PURE__ */ jsx(
|
|
123
|
+
"circle",
|
|
124
|
+
{
|
|
125
|
+
cx: x,
|
|
126
|
+
cy: y,
|
|
127
|
+
fill: color,
|
|
128
|
+
fillOpacity: haloOpacity,
|
|
129
|
+
filter: haloFilter,
|
|
130
|
+
r: haloRadius
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsx("circle", { cx: x, cy: y, fill: color, r: size, ...outline })
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
137
|
+
haloFilterDefs,
|
|
138
|
+
showHalo && /* @__PURE__ */ jsx(
|
|
139
|
+
m.circle,
|
|
140
|
+
{
|
|
141
|
+
animate: { r: haloRadius },
|
|
142
|
+
cx: animatedX,
|
|
143
|
+
cy: animatedY,
|
|
144
|
+
fill: color,
|
|
145
|
+
fillOpacity: haloOpacity,
|
|
146
|
+
filter: haloFilter,
|
|
147
|
+
initial: { r: size },
|
|
148
|
+
transition: HALO_SPRING
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
/* @__PURE__ */ jsx(
|
|
152
|
+
m.circle,
|
|
153
|
+
{
|
|
154
|
+
animate: { r: size },
|
|
155
|
+
cx: animatedX,
|
|
156
|
+
cy: animatedY,
|
|
157
|
+
fill: color,
|
|
158
|
+
initial: { r: size * 0.5 },
|
|
159
|
+
transition: HALO_SPRING,
|
|
160
|
+
...outline
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
TooltipDot.displayName = "TooltipDot";
|
|
166
|
+
var tooltip_dot_default = TooltipDot;
|
|
167
|
+
export {
|
|
168
|
+
TooltipDot,
|
|
169
|
+
tooltip_dot_default as default
|
|
170
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m, useSpring } from "motion/react";
|
|
4
|
+
import { useEffect, useId } from "react";
|
|
5
|
+
import { useChartConfig } from "../chart-config-context";
|
|
6
|
+
import { chartCssVars } from "../chart-context";
|
|
7
|
+
import {
|
|
8
|
+
indicatorFadeGradientStops,
|
|
9
|
+
resolveVerticalFadeSides
|
|
10
|
+
} from "../indicator-fade";
|
|
11
|
+
function resolveWidth(width) {
|
|
12
|
+
if (typeof width === "number") {
|
|
13
|
+
return width;
|
|
14
|
+
}
|
|
15
|
+
switch (width) {
|
|
16
|
+
case "line":
|
|
17
|
+
return 1;
|
|
18
|
+
case "thin":
|
|
19
|
+
return 2;
|
|
20
|
+
case "medium":
|
|
21
|
+
return 4;
|
|
22
|
+
case "thick":
|
|
23
|
+
return 8;
|
|
24
|
+
default:
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function verticalRampColor(top, end, offset) {
|
|
29
|
+
const percent = Number.parseFloat(offset);
|
|
30
|
+
if (percent <= 0) {
|
|
31
|
+
return top;
|
|
32
|
+
}
|
|
33
|
+
if (percent >= 100) {
|
|
34
|
+
return end;
|
|
35
|
+
}
|
|
36
|
+
return `color-mix(in srgb, ${end} ${percent}%, ${top})`;
|
|
37
|
+
}
|
|
38
|
+
function TooltipIndicator(props) {
|
|
39
|
+
if (!props.visible) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ jsx(TooltipIndicatorInner, { ...props });
|
|
43
|
+
}
|
|
44
|
+
function TooltipIndicatorInner({
|
|
45
|
+
x,
|
|
46
|
+
visible,
|
|
47
|
+
height,
|
|
48
|
+
width = "line",
|
|
49
|
+
span,
|
|
50
|
+
columnWidth,
|
|
51
|
+
colorEdge = chartCssVars.crosshair,
|
|
52
|
+
colorMid = chartCssVars.crosshair,
|
|
53
|
+
colorEnd,
|
|
54
|
+
bottom,
|
|
55
|
+
fadeEdges = "both",
|
|
56
|
+
fadeLength = 10,
|
|
57
|
+
animate = true,
|
|
58
|
+
gradientId: gradientIdProp,
|
|
59
|
+
springConfig,
|
|
60
|
+
strokeDasharray
|
|
61
|
+
}) {
|
|
62
|
+
const generatedId = useId();
|
|
63
|
+
const gradientId = gradientIdProp ?? `tooltip-indicator-gradient-${generatedId}`;
|
|
64
|
+
const { tooltipSpring } = useChartConfig();
|
|
65
|
+
const effectiveSpring = springConfig ?? tooltipSpring;
|
|
66
|
+
const pixelWidth = span !== void 0 && columnWidth !== void 0 ? span * columnWidth : resolveWidth(width);
|
|
67
|
+
const rectX = x - pixelWidth / 2;
|
|
68
|
+
const lineX = x;
|
|
69
|
+
const endY = Math.max(0, Math.min(height, bottom ?? height));
|
|
70
|
+
const animatedX = useSpring(rectX, effectiveSpring);
|
|
71
|
+
const animatedLineX = useSpring(lineX, effectiveSpring);
|
|
72
|
+
const animatedEndY = useSpring(endY, effectiveSpring);
|
|
73
|
+
if (animate) {
|
|
74
|
+
animatedX.set(rectX);
|
|
75
|
+
animatedLineX.set(lineX);
|
|
76
|
+
animatedEndY.set(endY);
|
|
77
|
+
}
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
animatedX.set(rectX);
|
|
80
|
+
animatedLineX.set(lineX);
|
|
81
|
+
animatedEndY.set(endY);
|
|
82
|
+
}, [animatedLineX, animatedX, animatedEndY, endY, lineX, rectX, visible]);
|
|
83
|
+
const indicatorFill = colorMid || colorEdge;
|
|
84
|
+
const fadeSides = resolveVerticalFadeSides(fadeEdges);
|
|
85
|
+
const dashed = Boolean(strokeDasharray);
|
|
86
|
+
if (dashed) {
|
|
87
|
+
const strokeWidth = Math.max(1, pixelWidth);
|
|
88
|
+
return animate ? /* @__PURE__ */ jsx(
|
|
89
|
+
m.line,
|
|
90
|
+
{
|
|
91
|
+
stroke: indicatorFill,
|
|
92
|
+
strokeDasharray,
|
|
93
|
+
strokeWidth,
|
|
94
|
+
x1: animatedLineX,
|
|
95
|
+
x2: animatedLineX,
|
|
96
|
+
y1: 0,
|
|
97
|
+
y2: animatedEndY
|
|
98
|
+
}
|
|
99
|
+
) : /* @__PURE__ */ jsx(
|
|
100
|
+
"line",
|
|
101
|
+
{
|
|
102
|
+
stroke: indicatorFill,
|
|
103
|
+
strokeDasharray,
|
|
104
|
+
strokeWidth,
|
|
105
|
+
x1: lineX,
|
|
106
|
+
x2: lineX,
|
|
107
|
+
y1: 0,
|
|
108
|
+
y2: endY
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (!(fadeSides.any || colorEnd)) {
|
|
113
|
+
return animate ? /* @__PURE__ */ jsx(
|
|
114
|
+
m.rect,
|
|
115
|
+
{
|
|
116
|
+
fill: indicatorFill,
|
|
117
|
+
height: animatedEndY,
|
|
118
|
+
width: pixelWidth,
|
|
119
|
+
x: animatedX,
|
|
120
|
+
y: 0
|
|
121
|
+
}
|
|
122
|
+
) : /* @__PURE__ */ jsx(
|
|
123
|
+
"rect",
|
|
124
|
+
{
|
|
125
|
+
fill: indicatorFill,
|
|
126
|
+
height: endY,
|
|
127
|
+
width: pixelWidth,
|
|
128
|
+
x: rectX,
|
|
129
|
+
y: 0
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const fadeStops = indicatorFadeGradientStops(fadeSides, fadeLength);
|
|
134
|
+
if (colorEnd && fadeStops.length === 1) {
|
|
135
|
+
fadeStops.push({ offset: "100%", opacity: 1 });
|
|
136
|
+
}
|
|
137
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
138
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("linearGradient", { id: gradientId, x1: "0%", x2: "0%", y1: "0%", y2: "100%", children: fadeStops.map((stop) => /* @__PURE__ */ jsx(
|
|
139
|
+
"stop",
|
|
140
|
+
{
|
|
141
|
+
offset: stop.offset,
|
|
142
|
+
style: {
|
|
143
|
+
stopColor: colorEnd ? verticalRampColor(indicatorFill, colorEnd, stop.offset) : indicatorFill,
|
|
144
|
+
stopOpacity: stop.opacity
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
stop.offset
|
|
148
|
+
)) }) }),
|
|
149
|
+
animate ? /* @__PURE__ */ jsx(
|
|
150
|
+
m.rect,
|
|
151
|
+
{
|
|
152
|
+
fill: `url(#${gradientId})`,
|
|
153
|
+
height: animatedEndY,
|
|
154
|
+
width: pixelWidth,
|
|
155
|
+
x: animatedX,
|
|
156
|
+
y: 0
|
|
157
|
+
}
|
|
158
|
+
) : /* @__PURE__ */ jsx(
|
|
159
|
+
"rect",
|
|
160
|
+
{
|
|
161
|
+
fill: `url(#${gradientId})`,
|
|
162
|
+
height: endY,
|
|
163
|
+
width: pixelWidth,
|
|
164
|
+
x: rectX,
|
|
165
|
+
y: 0
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
] });
|
|
169
|
+
}
|
|
170
|
+
TooltipIndicator.displayName = "TooltipIndicator";
|
|
171
|
+
var tooltip_indicator_default = TooltipIndicator;
|
|
172
|
+
export {
|
|
173
|
+
TooltipIndicator,
|
|
174
|
+
tooltip_indicator_default as default
|
|
175
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
const TOOLTIP_HIDE_DELAY_MS = 120;
|
|
4
|
+
function useDelayedTooltipData(tooltipData, showDelay = 0, hideDelay = TOOLTIP_HIDE_DELAY_MS) {
|
|
5
|
+
const [displayData, setDisplayData] = useState(null);
|
|
6
|
+
const [prevTooltipData, setPrevTooltipData] = useState(null);
|
|
7
|
+
const isShowing = displayData !== null;
|
|
8
|
+
if (prevTooltipData !== tooltipData) {
|
|
9
|
+
setPrevTooltipData(tooltipData);
|
|
10
|
+
if (tooltipData) {
|
|
11
|
+
if (isShowing || showDelay === 0) {
|
|
12
|
+
setDisplayData(tooltipData);
|
|
13
|
+
}
|
|
14
|
+
} else if (hideDelay === 0) {
|
|
15
|
+
setDisplayData(null);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (tooltipData) {
|
|
20
|
+
if (displayData === tooltipData) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const showTimer = setTimeout(() => {
|
|
24
|
+
setDisplayData(tooltipData);
|
|
25
|
+
}, showDelay);
|
|
26
|
+
return () => clearTimeout(showTimer);
|
|
27
|
+
}
|
|
28
|
+
if (displayData === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const hideTimer = setTimeout(() => {
|
|
32
|
+
setDisplayData(null);
|
|
33
|
+
}, hideDelay);
|
|
34
|
+
return () => clearTimeout(hideTimer);
|
|
35
|
+
}, [tooltipData, displayData, showDelay, hideDelay]);
|
|
36
|
+
return displayData;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
TOOLTIP_HIDE_DELAY_MS,
|
|
40
|
+
useDelayedTooltipData
|
|
41
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useSpring,
|
|
4
|
+
useTransform,
|
|
5
|
+
useVelocity
|
|
6
|
+
} from "motion/react";
|
|
7
|
+
import { useLayoutEffect, useRef } from "react";
|
|
8
|
+
const DEFAULTS = {
|
|
9
|
+
scale: 0.06,
|
|
10
|
+
stretch: 0.08,
|
|
11
|
+
maxVelocity: 1600
|
|
12
|
+
};
|
|
13
|
+
const SWELL_SPRING = { stiffness: 420, damping: 32, mass: 0.6 };
|
|
14
|
+
function resolveDatePillVelocity(value) {
|
|
15
|
+
if (!value) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return value === true ? DEFAULTS : { ...DEFAULTS, ...value };
|
|
19
|
+
}
|
|
20
|
+
function velocitySwell(velocity, maxVelocity) {
|
|
21
|
+
if (maxVelocity <= 0) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
const t = Math.min(Math.abs(velocity) / maxVelocity, 1);
|
|
25
|
+
return t * (2 - t);
|
|
26
|
+
}
|
|
27
|
+
function useVelocityStretch(x, config) {
|
|
28
|
+
const configRef = useRef(config);
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
configRef.current = config;
|
|
31
|
+
});
|
|
32
|
+
const velocity = useVelocity(x);
|
|
33
|
+
const swell = useTransform(velocity, (v) => {
|
|
34
|
+
const c = configRef.current;
|
|
35
|
+
return c ? velocitySwell(v, c.maxVelocity) : 0;
|
|
36
|
+
});
|
|
37
|
+
const smooth = useSpring(swell, SWELL_SPRING);
|
|
38
|
+
const scaleX = useTransform(smooth, (a) => {
|
|
39
|
+
const c = configRef.current;
|
|
40
|
+
return c ? 1 + a * (c.scale + c.stretch) : 1;
|
|
41
|
+
});
|
|
42
|
+
const scaleY = useTransform(smooth, (a) => {
|
|
43
|
+
const c = configRef.current;
|
|
44
|
+
return c ? 1 + a * c.scale : 1;
|
|
45
|
+
});
|
|
46
|
+
return { scaleX, scaleY };
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
resolveDatePillVelocity,
|
|
50
|
+
useVelocityStretch,
|
|
51
|
+
velocitySwell
|
|
52
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function computeLinearRegression(points) {
|
|
2
|
+
let n = 0;
|
|
3
|
+
let sumX = 0;
|
|
4
|
+
let sumY = 0;
|
|
5
|
+
for (const { x, y } of points) {
|
|
6
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
7
|
+
n += 1;
|
|
8
|
+
sumX += x;
|
|
9
|
+
sumY += y;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (n < 2) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const meanX = sumX / n;
|
|
16
|
+
const meanY = sumY / n;
|
|
17
|
+
let covXY = 0;
|
|
18
|
+
let varX = 0;
|
|
19
|
+
for (const { x, y } of points) {
|
|
20
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
21
|
+
const dx = x - meanX;
|
|
22
|
+
covXY += dx * (y - meanY);
|
|
23
|
+
varX += dx * dx;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (varX === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const slope = covXY / varX;
|
|
30
|
+
return { slope, intercept: meanY - slope * meanX };
|
|
31
|
+
}
|
|
32
|
+
function computeTrendSegment(points) {
|
|
33
|
+
const fit = computeLinearRegression(points);
|
|
34
|
+
if (!fit) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
38
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
39
|
+
for (const { x, y } of points) {
|
|
40
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
41
|
+
minX = Math.min(minX, x);
|
|
42
|
+
maxX = Math.max(maxX, x);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
x1: minX,
|
|
47
|
+
y1: fit.slope * minX + fit.intercept,
|
|
48
|
+
x2: maxX,
|
|
49
|
+
y2: fit.slope * maxX + fit.intercept
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function interpolateTrendSegment(from, to, t) {
|
|
53
|
+
return {
|
|
54
|
+
x1: from.x1 + (to.x1 - from.x1) * t,
|
|
55
|
+
y1: from.y1 + (to.y1 - from.y1) * t,
|
|
56
|
+
x2: from.x2 + (to.x2 - from.x2) * t,
|
|
57
|
+
y2: from.y2 + (to.y2 - from.y2) * t
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
computeLinearRegression,
|
|
62
|
+
computeTrendSegment,
|
|
63
|
+
interpolateTrendSegment
|
|
64
|
+
};
|