@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,277 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { curveMonotoneX } from "d3-shape";
|
|
4
|
+
import { m } from "motion/react";
|
|
5
|
+
import { useCallback, useId, useMemo } from "react";
|
|
6
|
+
import { chartCssVars, useChart } from "./chart-context";
|
|
7
|
+
import { areaClosedD, LinePath, linePathD } from "./line-path";
|
|
8
|
+
function detectMomentum(data, dataKey, lookback = 20) {
|
|
9
|
+
if (data.length < 5) {
|
|
10
|
+
return "flat";
|
|
11
|
+
}
|
|
12
|
+
const start = Math.max(0, data.length - lookback);
|
|
13
|
+
let min = Number.POSITIVE_INFINITY;
|
|
14
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
15
|
+
for (let i = start; i < data.length; i++) {
|
|
16
|
+
const v = data[i]?.[dataKey];
|
|
17
|
+
if (typeof v === "number") {
|
|
18
|
+
if (v < min) {
|
|
19
|
+
min = v;
|
|
20
|
+
}
|
|
21
|
+
if (v > max) {
|
|
22
|
+
max = v;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const range = max - min;
|
|
27
|
+
if (range === 0) {
|
|
28
|
+
return "flat";
|
|
29
|
+
}
|
|
30
|
+
const tailStart = Math.max(start, data.length - 5);
|
|
31
|
+
const first = data[tailStart]?.[dataKey] ?? 0;
|
|
32
|
+
const last = data.at(-1)?.[dataKey] ?? 0;
|
|
33
|
+
const delta = last - first;
|
|
34
|
+
const threshold = range * 0.12;
|
|
35
|
+
if (delta > threshold) {
|
|
36
|
+
return "up";
|
|
37
|
+
}
|
|
38
|
+
if (delta < -threshold) {
|
|
39
|
+
return "down";
|
|
40
|
+
}
|
|
41
|
+
return "flat";
|
|
42
|
+
}
|
|
43
|
+
LiveLine.displayName = "LiveLine";
|
|
44
|
+
function LiveLine({
|
|
45
|
+
dataKey,
|
|
46
|
+
stroke = chartCssVars.linePrimary,
|
|
47
|
+
strokeWidth = 2,
|
|
48
|
+
curve = curveMonotoneX,
|
|
49
|
+
fill = true,
|
|
50
|
+
pulse = true,
|
|
51
|
+
dotSize = 4,
|
|
52
|
+
badge = true,
|
|
53
|
+
formatValue = (v) => v.toFixed(2),
|
|
54
|
+
momentumColors
|
|
55
|
+
}) {
|
|
56
|
+
const {
|
|
57
|
+
data,
|
|
58
|
+
xScale,
|
|
59
|
+
yScale,
|
|
60
|
+
innerWidth,
|
|
61
|
+
innerHeight,
|
|
62
|
+
xAccessor,
|
|
63
|
+
lines,
|
|
64
|
+
tooltipData
|
|
65
|
+
} = useChart();
|
|
66
|
+
const isScrubbing = tooltipData !== null;
|
|
67
|
+
const uid = useId();
|
|
68
|
+
const gradientId = `live-line-grad-${uid}`;
|
|
69
|
+
const areaGradientId = `live-area-grad-${uid}`;
|
|
70
|
+
const fadeId = `live-fade-${uid}`;
|
|
71
|
+
const fadeMaskId = `live-fade-mask-${uid}`;
|
|
72
|
+
const getX = useCallback(
|
|
73
|
+
(d) => xScale(xAccessor(d)) ?? 0,
|
|
74
|
+
[xScale, xAccessor]
|
|
75
|
+
);
|
|
76
|
+
const getY = useCallback(
|
|
77
|
+
(d) => {
|
|
78
|
+
const v = d[dataKey];
|
|
79
|
+
return typeof v === "number" ? yScale(v) ?? 0 : 0;
|
|
80
|
+
},
|
|
81
|
+
[dataKey, yScale]
|
|
82
|
+
);
|
|
83
|
+
const showFill = fill && data.length > 1;
|
|
84
|
+
const areaPathD = useMemo(
|
|
85
|
+
() => showFill ? areaClosedD(data, { curve, x: getX, y: getY, yScale }) : "",
|
|
86
|
+
[curve, data, getX, getY, showFill, yScale]
|
|
87
|
+
);
|
|
88
|
+
const strokePathD = useMemo(
|
|
89
|
+
() => data.length > 1 ? linePathD(data, { curve, x: getX, y: getY }) : "",
|
|
90
|
+
[curve, data, getX, getY]
|
|
91
|
+
);
|
|
92
|
+
const nowPoint = data.length >= 2 ? data.at(-2) : data.at(-1);
|
|
93
|
+
const liveValue = nowPoint && typeof nowPoint[dataKey] === "number" ? nowPoint[dataKey] : 0;
|
|
94
|
+
const liveDotX = nowPoint ? xScale(xAccessor(nowPoint)) ?? 0 : innerWidth;
|
|
95
|
+
const liveDotY = yScale(liveValue) ?? 0;
|
|
96
|
+
const momentum = useMemo(
|
|
97
|
+
() => detectMomentum(data, dataKey),
|
|
98
|
+
[data, dataKey]
|
|
99
|
+
);
|
|
100
|
+
const defaultMomentumColors = {
|
|
101
|
+
up: "var(--chart-1)",
|
|
102
|
+
down: "var(--chart-5)",
|
|
103
|
+
flat: stroke
|
|
104
|
+
};
|
|
105
|
+
const dotMomentumColors = momentumColors ?? defaultMomentumColors;
|
|
106
|
+
const dotColor = dotMomentumColors[momentum];
|
|
107
|
+
const lineConfig = lines.find((l) => l.dataKey === dataKey);
|
|
108
|
+
const baseStroke = lineConfig?.stroke ?? stroke;
|
|
109
|
+
const resolvedStroke = momentumColors ? momentumColors[momentum] : baseStroke;
|
|
110
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
111
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
112
|
+
/* @__PURE__ */ jsxs("linearGradient", { id: gradientId, x1: "0", x2: "0", y1: "0", y2: "1", children: [
|
|
113
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: resolvedStroke, stopOpacity: 1 }),
|
|
114
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: resolvedStroke, stopOpacity: 0.6 })
|
|
115
|
+
] }),
|
|
116
|
+
/* @__PURE__ */ jsxs("linearGradient", { id: areaGradientId, x1: "0", x2: "0", y1: "0", y2: "1", children: [
|
|
117
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: resolvedStroke, stopOpacity: 0.1 }),
|
|
118
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: resolvedStroke, stopOpacity: 0 })
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ jsxs("linearGradient", { id: fadeId, x1: "0", x2: "1", y1: "0", y2: "0", children: [
|
|
121
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "white", stopOpacity: 0 }),
|
|
122
|
+
/* @__PURE__ */ jsx("stop", { offset: "4%", stopColor: "white", stopOpacity: 1 }),
|
|
123
|
+
liveDotX < innerWidth - 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
124
|
+
/* @__PURE__ */ jsx(
|
|
125
|
+
"stop",
|
|
126
|
+
{
|
|
127
|
+
offset: `${liveDotX / innerWidth * 100}%`,
|
|
128
|
+
stopColor: "white",
|
|
129
|
+
stopOpacity: 1
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "white", stopOpacity: 0 })
|
|
133
|
+
] }) : /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "white", stopOpacity: 1 })
|
|
134
|
+
] }),
|
|
135
|
+
/* @__PURE__ */ jsx("mask", { id: fadeMaskId, children: /* @__PURE__ */ jsx(
|
|
136
|
+
"rect",
|
|
137
|
+
{
|
|
138
|
+
fill: `url(#${fadeId})`,
|
|
139
|
+
height: innerHeight + 40,
|
|
140
|
+
width: innerWidth,
|
|
141
|
+
x: 0,
|
|
142
|
+
y: -20
|
|
143
|
+
}
|
|
144
|
+
) })
|
|
145
|
+
] }),
|
|
146
|
+
showFill && /* @__PURE__ */ jsx("g", { mask: `url(#${fadeMaskId})`, children: /* @__PURE__ */ jsx(
|
|
147
|
+
"path",
|
|
148
|
+
{
|
|
149
|
+
d: areaPathD,
|
|
150
|
+
fill: `url(#${areaGradientId})`,
|
|
151
|
+
strokeWidth: 0
|
|
152
|
+
}
|
|
153
|
+
) }),
|
|
154
|
+
data.length > 1 && /* @__PURE__ */ jsx("g", { mask: `url(#${fadeMaskId})`, children: /* @__PURE__ */ jsx(
|
|
155
|
+
LinePath,
|
|
156
|
+
{
|
|
157
|
+
d: strokePathD,
|
|
158
|
+
stroke: `url(#${gradientId})`,
|
|
159
|
+
strokeLinecap: "round",
|
|
160
|
+
strokeLinejoin: "round",
|
|
161
|
+
strokeWidth
|
|
162
|
+
}
|
|
163
|
+
) }),
|
|
164
|
+
/* @__PURE__ */ jsx(
|
|
165
|
+
"line",
|
|
166
|
+
{
|
|
167
|
+
opacity: 0.25,
|
|
168
|
+
stroke: resolvedStroke,
|
|
169
|
+
strokeDasharray: "4,4",
|
|
170
|
+
strokeWidth: 1,
|
|
171
|
+
x1: 0,
|
|
172
|
+
x2: innerWidth,
|
|
173
|
+
y1: liveDotY,
|
|
174
|
+
y2: liveDotY
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsxs(
|
|
178
|
+
m.g,
|
|
179
|
+
{
|
|
180
|
+
animate: { opacity: isScrubbing ? 0.25 : 1 },
|
|
181
|
+
initial: false,
|
|
182
|
+
transition: { duration: 0.3, ease: "easeInOut" },
|
|
183
|
+
children: [
|
|
184
|
+
/* @__PURE__ */ jsxs("g", { children: [
|
|
185
|
+
pulse && /* @__PURE__ */ jsxs(
|
|
186
|
+
"circle",
|
|
187
|
+
{
|
|
188
|
+
cx: liveDotX,
|
|
189
|
+
cy: liveDotY,
|
|
190
|
+
fill: "none",
|
|
191
|
+
opacity: 0.4,
|
|
192
|
+
r: dotSize * 2,
|
|
193
|
+
stroke: dotColor,
|
|
194
|
+
strokeWidth: 1.5,
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
"animate",
|
|
198
|
+
{
|
|
199
|
+
attributeName: "r",
|
|
200
|
+
dur: "1.5s",
|
|
201
|
+
from: String(dotSize),
|
|
202
|
+
repeatCount: "indefinite",
|
|
203
|
+
to: String(dotSize * 3.5)
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
/* @__PURE__ */ jsx(
|
|
207
|
+
"animate",
|
|
208
|
+
{
|
|
209
|
+
attributeName: "opacity",
|
|
210
|
+
dur: "1.5s",
|
|
211
|
+
from: "0.5",
|
|
212
|
+
repeatCount: "indefinite",
|
|
213
|
+
to: "0"
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
),
|
|
219
|
+
/* @__PURE__ */ jsx(
|
|
220
|
+
"circle",
|
|
221
|
+
{
|
|
222
|
+
cx: liveDotX,
|
|
223
|
+
cy: liveDotY,
|
|
224
|
+
fill: dotColor,
|
|
225
|
+
opacity: 0.1,
|
|
226
|
+
r: dotSize + 2
|
|
227
|
+
}
|
|
228
|
+
),
|
|
229
|
+
/* @__PURE__ */ jsx(
|
|
230
|
+
"circle",
|
|
231
|
+
{
|
|
232
|
+
cx: liveDotX,
|
|
233
|
+
cy: liveDotY,
|
|
234
|
+
fill: dotColor,
|
|
235
|
+
r: dotSize,
|
|
236
|
+
stroke: chartCssVars.background,
|
|
237
|
+
strokeWidth: 2
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
] }),
|
|
241
|
+
badge && /* @__PURE__ */ jsxs("g", { transform: `translate(${liveDotX + 12},${liveDotY})`, children: [
|
|
242
|
+
/* @__PURE__ */ jsx(
|
|
243
|
+
"rect",
|
|
244
|
+
{
|
|
245
|
+
fill: "var(--chart-tooltip-background)",
|
|
246
|
+
height: 24,
|
|
247
|
+
opacity: 0.95,
|
|
248
|
+
rx: 6,
|
|
249
|
+
width: formatValue(liveValue).length * 7.5 + 16,
|
|
250
|
+
x: 0,
|
|
251
|
+
y: -12
|
|
252
|
+
}
|
|
253
|
+
),
|
|
254
|
+
/* @__PURE__ */ jsx(
|
|
255
|
+
"text",
|
|
256
|
+
{
|
|
257
|
+
fill: "var(--chart-tooltip-foreground)",
|
|
258
|
+
fontFamily: "SF Mono, Menlo, Monaco, monospace",
|
|
259
|
+
fontSize: 11,
|
|
260
|
+
fontWeight: 500,
|
|
261
|
+
x: 8,
|
|
262
|
+
y: 4,
|
|
263
|
+
children: formatValue(liveValue)
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
] })
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
] });
|
|
271
|
+
}
|
|
272
|
+
var live_line_default = LiveLine;
|
|
273
|
+
export {
|
|
274
|
+
LiveLine,
|
|
275
|
+
live_line_default as default,
|
|
276
|
+
detectMomentum
|
|
277
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m, useSpring } from "motion/react";
|
|
4
|
+
import { memo, useEffect, useMemo } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import {
|
|
7
|
+
useChart,
|
|
8
|
+
useChartPortalContainer,
|
|
9
|
+
useChartStable
|
|
10
|
+
} from "./chart-context";
|
|
11
|
+
import { hmsTimeFmt } from "./chart-formatters";
|
|
12
|
+
const TICKER_HALF_WIDTH = 50;
|
|
13
|
+
const FADE_BUFFER = 20;
|
|
14
|
+
const crosshairSpringConfig = { stiffness: 300, damping: 30 };
|
|
15
|
+
function labelFadeOpacity(labelX, crosshairX, isHovering) {
|
|
16
|
+
if (!isHovering || crosshairX === null) {
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
const distance = Math.abs(labelX - crosshairX);
|
|
20
|
+
if (distance < TICKER_HALF_WIDTH) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
if (distance < TICKER_HALF_WIDTH + FADE_BUFFER) {
|
|
24
|
+
return (distance - TICKER_HALF_WIDTH) / FADE_BUFFER;
|
|
25
|
+
}
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
const defaultFormatTime = (t) => hmsTimeFmt.format(new Date(t));
|
|
29
|
+
function LiveXAxis(props) {
|
|
30
|
+
const { containerRef } = useChartStable();
|
|
31
|
+
const container = useChartPortalContainer(containerRef);
|
|
32
|
+
if (!container) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ jsx(LiveXAxisInner, { ...props, container });
|
|
36
|
+
}
|
|
37
|
+
const LiveXAxisInner = memo(function LiveXAxisInner2({
|
|
38
|
+
numTicks = 5,
|
|
39
|
+
formatTime = defaultFormatTime,
|
|
40
|
+
container
|
|
41
|
+
}) {
|
|
42
|
+
const { xScale, margin, tooltipData } = useChart();
|
|
43
|
+
const domain = xScale.domain();
|
|
44
|
+
const startMs = domain[0]?.getTime() ?? 0;
|
|
45
|
+
const endMs = domain[1]?.getTime() ?? 0;
|
|
46
|
+
const labels = useMemo(() => {
|
|
47
|
+
const step = (endMs - startMs) / (numTicks - 1);
|
|
48
|
+
return Array.from({ length: numTicks }, (_, i) => {
|
|
49
|
+
const t = startMs + i * step;
|
|
50
|
+
const x = (xScale(new Date(t)) ?? 0) + margin.left;
|
|
51
|
+
return { x, label: formatTime(t), stableKey: i };
|
|
52
|
+
});
|
|
53
|
+
}, [startMs, endMs, numTicks, xScale, margin.left, formatTime]);
|
|
54
|
+
const isHovering = tooltipData !== null;
|
|
55
|
+
const crosshairX = tooltipData ? tooltipData.x + margin.left : null;
|
|
56
|
+
const pillLabel = useMemo(() => {
|
|
57
|
+
if (!tooltipData) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const timeMs = xScale.invert(tooltipData.x).getTime();
|
|
61
|
+
return formatTime(timeMs);
|
|
62
|
+
}, [tooltipData, xScale, formatTime]);
|
|
63
|
+
const pillX = tooltipData ? tooltipData.x + margin.left : 0;
|
|
64
|
+
const animatedPillX = useSpring(pillX, crosshairSpringConfig);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
animatedPillX.set(pillX);
|
|
67
|
+
}, [animatedPillX, pillX]);
|
|
68
|
+
return createPortal(
|
|
69
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-none absolute inset-0", children: [
|
|
70
|
+
labels.map((l) => /* @__PURE__ */ jsx(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
className: "absolute",
|
|
74
|
+
style: {
|
|
75
|
+
left: l.x,
|
|
76
|
+
bottom: 12,
|
|
77
|
+
width: 0,
|
|
78
|
+
display: "flex",
|
|
79
|
+
justifyContent: "center"
|
|
80
|
+
},
|
|
81
|
+
children: /* @__PURE__ */ jsx(
|
|
82
|
+
m.span,
|
|
83
|
+
{
|
|
84
|
+
animate: {
|
|
85
|
+
opacity: labelFadeOpacity(l.x, crosshairX, isHovering)
|
|
86
|
+
},
|
|
87
|
+
className: "whitespace-nowrap text-chart-label text-xs",
|
|
88
|
+
transition: { duration: 0.15, ease: "easeOut" },
|
|
89
|
+
children: l.label
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
},
|
|
93
|
+
l.stableKey
|
|
94
|
+
)),
|
|
95
|
+
isHovering && pillLabel && /* @__PURE__ */ jsx(
|
|
96
|
+
m.div,
|
|
97
|
+
{
|
|
98
|
+
className: "absolute z-50",
|
|
99
|
+
style: {
|
|
100
|
+
left: animatedPillX,
|
|
101
|
+
x: "-50%",
|
|
102
|
+
bottom: 4
|
|
103
|
+
},
|
|
104
|
+
children: /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-full bg-chart-pill px-4 py-1 text-chart-pill-foreground shadow-lg", children: /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap font-medium text-sm", children: pillLabel }) })
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
] }),
|
|
108
|
+
container
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
LiveXAxis.displayName = "LiveXAxis";
|
|
112
|
+
var live_x_axis_default = LiveXAxis;
|
|
113
|
+
export {
|
|
114
|
+
LiveXAxis,
|
|
115
|
+
live_x_axis_default as default
|
|
116
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { AnimatePresence, m } from "motion/react";
|
|
4
|
+
import { memo, useMemo, useState } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { useChartPortalContainer, useChartStable } from "./chart-context";
|
|
7
|
+
function pickNiceInterval(valRange, chartHeight, minGap, prevInterval) {
|
|
8
|
+
if (valRange <= 0 || chartHeight <= 0) {
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
const pxPerUnit = chartHeight / valRange;
|
|
12
|
+
if (prevInterval > 0) {
|
|
13
|
+
const px = prevInterval * pxPerUnit;
|
|
14
|
+
if (px >= minGap * 0.5 && px <= minGap * 3) {
|
|
15
|
+
return prevInterval;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const divisorSets = [
|
|
19
|
+
[2, 2.5, 2],
|
|
20
|
+
[2, 2, 2.5],
|
|
21
|
+
[2.5, 2, 2]
|
|
22
|
+
];
|
|
23
|
+
let best = Number.POSITIVE_INFINITY;
|
|
24
|
+
for (const divs of divisorSets) {
|
|
25
|
+
let span = 10 ** Math.ceil(Math.log10(valRange));
|
|
26
|
+
let i = 0;
|
|
27
|
+
let d = divs[i % 3] ?? 2;
|
|
28
|
+
while (span / d * pxPerUnit >= minGap) {
|
|
29
|
+
span /= d;
|
|
30
|
+
i++;
|
|
31
|
+
d = divs[i % 3] ?? 2;
|
|
32
|
+
}
|
|
33
|
+
if (span < best) {
|
|
34
|
+
best = span;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return best === Number.POSITIVE_INFINITY ? valRange / 5 : best;
|
|
38
|
+
}
|
|
39
|
+
const EDGE_FADE_PX = 28;
|
|
40
|
+
function edgeOpacity(y, chartHeight) {
|
|
41
|
+
const fromEdge = Math.min(y, chartHeight - y);
|
|
42
|
+
if (fromEdge >= EDGE_FADE_PX) {
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
if (fromEdge <= 0) {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
return fromEdge / EDGE_FADE_PX;
|
|
49
|
+
}
|
|
50
|
+
const tickSpring = { type: "spring", stiffness: 180, damping: 24 };
|
|
51
|
+
function useLiveYAxisTickValues({
|
|
52
|
+
minGap = 36,
|
|
53
|
+
allowDecimals = true
|
|
54
|
+
} = {}) {
|
|
55
|
+
const { yScale, innerHeight } = useChartStable();
|
|
56
|
+
const [prevInterval, setPrevInterval] = useState(0);
|
|
57
|
+
const domain = yScale.domain();
|
|
58
|
+
const minVal = domain[0];
|
|
59
|
+
const maxVal = domain[1];
|
|
60
|
+
const valRange = maxVal - minVal;
|
|
61
|
+
const interval = useMemo(
|
|
62
|
+
() => pickNiceInterval(valRange, innerHeight, minGap, prevInterval),
|
|
63
|
+
[valRange, innerHeight, minGap, prevInterval]
|
|
64
|
+
);
|
|
65
|
+
if (!Object.is(interval, prevInterval)) {
|
|
66
|
+
setPrevInterval(interval);
|
|
67
|
+
}
|
|
68
|
+
const quantizedMin = interval > 0 ? Math.floor(minVal / interval) : 0;
|
|
69
|
+
const quantizedMax = interval > 0 ? Math.ceil(maxVal / interval) : 0;
|
|
70
|
+
return useMemo(() => {
|
|
71
|
+
if (interval <= 0 || valRange <= 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const expandedMin = minVal - interval * 0.5;
|
|
75
|
+
const expandedMax = maxVal + interval * 0.5;
|
|
76
|
+
const first = Math.ceil(expandedMin / interval) * interval;
|
|
77
|
+
const values = [];
|
|
78
|
+
for (let v = first; v <= expandedMax; v += interval) {
|
|
79
|
+
const rounded = Math.round(v * 1e10) / 1e10;
|
|
80
|
+
const isDecimal = !Number.isInteger(rounded);
|
|
81
|
+
if (isDecimal && !allowDecimals) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
values.push(rounded);
|
|
85
|
+
}
|
|
86
|
+
return values;
|
|
87
|
+
}, [
|
|
88
|
+
quantizedMin,
|
|
89
|
+
quantizedMax,
|
|
90
|
+
interval,
|
|
91
|
+
minVal,
|
|
92
|
+
maxVal,
|
|
93
|
+
valRange,
|
|
94
|
+
allowDecimals
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
function LiveYAxis(props) {
|
|
98
|
+
const { containerRef } = useChartStable();
|
|
99
|
+
const container = useChartPortalContainer(containerRef);
|
|
100
|
+
if (!container) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return /* @__PURE__ */ jsx(LiveYAxisInner, { ...props, container });
|
|
104
|
+
}
|
|
105
|
+
const LiveYAxisInner = memo(function LiveYAxisInner2({
|
|
106
|
+
minGap = 36,
|
|
107
|
+
position = "left",
|
|
108
|
+
formatValue = (v) => v.toFixed(2),
|
|
109
|
+
allowDecimals = true,
|
|
110
|
+
container
|
|
111
|
+
}) {
|
|
112
|
+
const { yScale, margin, innerHeight } = useChartStable();
|
|
113
|
+
const stableTickValues = useLiveYAxisTickValues({ minGap, allowDecimals });
|
|
114
|
+
const tickData = useMemo(
|
|
115
|
+
() => stableTickValues.map((value) => {
|
|
116
|
+
const y = yScale(value) ?? 0;
|
|
117
|
+
return {
|
|
118
|
+
value,
|
|
119
|
+
y,
|
|
120
|
+
label: formatValue(value),
|
|
121
|
+
key: value.toPrecision(10),
|
|
122
|
+
edgeAlpha: edgeOpacity(y, innerHeight)
|
|
123
|
+
};
|
|
124
|
+
}).filter((t) => t.y >= -10 && t.y <= innerHeight + 10),
|
|
125
|
+
[stableTickValues, yScale, innerHeight, formatValue]
|
|
126
|
+
);
|
|
127
|
+
const isLeft = position === "left";
|
|
128
|
+
return createPortal(
|
|
129
|
+
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0", children: /* @__PURE__ */ jsx(
|
|
130
|
+
"div",
|
|
131
|
+
{
|
|
132
|
+
className: "absolute overflow-hidden",
|
|
133
|
+
style: {
|
|
134
|
+
top: margin.top,
|
|
135
|
+
height: innerHeight,
|
|
136
|
+
...isLeft ? { left: 0, width: margin.left } : { right: 0, width: margin.right }
|
|
137
|
+
},
|
|
138
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: tickData.map((tick) => /* @__PURE__ */ jsx(
|
|
139
|
+
m.div,
|
|
140
|
+
{
|
|
141
|
+
animate: { opacity: tick.edgeAlpha, y: tick.y },
|
|
142
|
+
className: "absolute w-full",
|
|
143
|
+
exit: { opacity: 0 },
|
|
144
|
+
initial: { opacity: 0, y: tick.y },
|
|
145
|
+
style: {
|
|
146
|
+
...isLeft ? { right: 0, paddingRight: 8, textAlign: "right" } : { left: 0, paddingLeft: 8, textAlign: "left" }
|
|
147
|
+
},
|
|
148
|
+
transition: tickSpring,
|
|
149
|
+
children: /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap font-mono text-chart-label text-xs", children: tick.label })
|
|
150
|
+
},
|
|
151
|
+
tick.key
|
|
152
|
+
)) })
|
|
153
|
+
}
|
|
154
|
+
) }),
|
|
155
|
+
container
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
LiveYAxis.displayName = "LiveYAxis";
|
|
159
|
+
var live_y_axis_default = LiveYAxis;
|
|
160
|
+
export {
|
|
161
|
+
LiveYAxis,
|
|
162
|
+
live_y_axis_default as default,
|
|
163
|
+
useLiveYAxisTickValues
|
|
164
|
+
};
|