@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.
- package/ALTERACOES.md +57 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +189 -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,344 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { scaleLinear } from "d3-scale";
|
|
4
|
+
import { m, useReducedMotion } from "motion/react";
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
13
|
+
import { chartCssVars, useChartStable } from "./chart-context";
|
|
14
|
+
import {
|
|
15
|
+
LINE_LOADING_PULSE_EASE,
|
|
16
|
+
LOADING_LABEL_EXIT_S
|
|
17
|
+
} from "./line-loading-timing";
|
|
18
|
+
import { areaClosedD, LinePath, linePathD } from "./line-path";
|
|
19
|
+
const DEFAULT_SWEEP_DURATION_S = 2;
|
|
20
|
+
const SWEEP_START_X = -1;
|
|
21
|
+
const SWEEP_END_X = 2;
|
|
22
|
+
const SWEEP_ANGLE_DEG = 25;
|
|
23
|
+
const HEIGHT_MIN_PCT = 20;
|
|
24
|
+
const HEIGHT_MAX_PCT = 80;
|
|
25
|
+
const DEFAULT_POINT_COUNT = 14;
|
|
26
|
+
const DEFAULT_BAR_COUNT = 12;
|
|
27
|
+
const DEFAULT_FILL = "var(--chart-foreground)";
|
|
28
|
+
const DEFAULT_BAR_FILL_OPACITY = 0.45;
|
|
29
|
+
const LINE_STROKE_OPACITY = 0.55;
|
|
30
|
+
const AREA_FILL_TOP_OPACITY = 0.18;
|
|
31
|
+
const AREA_FILL_BOTTOM_OPACITY = 0.02;
|
|
32
|
+
const DEFAULT_BAR_FRACTION = 0.7;
|
|
33
|
+
function hashFract(n) {
|
|
34
|
+
const x = Math.sin(n) * 43758.5453;
|
|
35
|
+
return x - Math.floor(x);
|
|
36
|
+
}
|
|
37
|
+
function getSkeletonHeights(count, seed = 0, min = HEIGHT_MIN_PCT, max = HEIGHT_MAX_PCT) {
|
|
38
|
+
const range = max - min;
|
|
39
|
+
return Array.from(
|
|
40
|
+
{ length: count },
|
|
41
|
+
(_, i) => min + Math.floor(hashFract((i + 1) * 12.9898 + seed) * range)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
function getSkeletonSigns(count, seed = 0) {
|
|
45
|
+
return Array.from(
|
|
46
|
+
{ length: count },
|
|
47
|
+
(_, i) => hashFract((i + 1) * 78.233 + seed) < 0.5 ? -1 : 1
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function generateEasedGradientStops(steps = 17, minOpacity = 0.05, maxOpacity = 0.9) {
|
|
51
|
+
return Array.from({ length: steps }, (_, i) => {
|
|
52
|
+
const t = i / (steps - 1);
|
|
53
|
+
const eased = Math.sin(t * Math.PI) ** 2;
|
|
54
|
+
const opacity = minOpacity + eased * (maxOpacity - minOpacity);
|
|
55
|
+
return {
|
|
56
|
+
offset: `${(t * 100).toFixed(0)}%`,
|
|
57
|
+
opacity: Number(opacity.toFixed(3))
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function LoadingSweepMask({
|
|
62
|
+
chartId,
|
|
63
|
+
width,
|
|
64
|
+
height,
|
|
65
|
+
durationSeconds,
|
|
66
|
+
onSweepComplete
|
|
67
|
+
}) {
|
|
68
|
+
const gradientStops = useMemo(() => generateEasedGradientStops(), []);
|
|
69
|
+
const lastXRef = useRef(SWEEP_START_X);
|
|
70
|
+
const handleUpdate = useCallback(
|
|
71
|
+
(latest) => {
|
|
72
|
+
const xValue = typeof latest.x === "number" ? latest.x : SWEEP_START_X;
|
|
73
|
+
if (xValue >= 1 && lastXRef.current < 1) {
|
|
74
|
+
onSweepComplete();
|
|
75
|
+
}
|
|
76
|
+
lastXRef.current = xValue;
|
|
77
|
+
},
|
|
78
|
+
[onSweepComplete]
|
|
79
|
+
);
|
|
80
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
+
/* @__PURE__ */ jsx("linearGradient", { id: `${chartId}-grad`, x1: "0", x2: "1", y1: "0", y2: "0", children: gradientStops.map(({ offset, opacity }) => /* @__PURE__ */ jsx(
|
|
82
|
+
"stop",
|
|
83
|
+
{
|
|
84
|
+
offset,
|
|
85
|
+
stopColor: "white",
|
|
86
|
+
stopOpacity: opacity
|
|
87
|
+
},
|
|
88
|
+
offset
|
|
89
|
+
)) }),
|
|
90
|
+
/* @__PURE__ */ jsx(
|
|
91
|
+
"pattern",
|
|
92
|
+
{
|
|
93
|
+
height: "1",
|
|
94
|
+
id: `${chartId}-pattern`,
|
|
95
|
+
patternContentUnits: "objectBoundingBox",
|
|
96
|
+
patternTransform: `rotate(${SWEEP_ANGLE_DEG})`,
|
|
97
|
+
patternUnits: "objectBoundingBox",
|
|
98
|
+
width: 3,
|
|
99
|
+
x: "0",
|
|
100
|
+
y: "0",
|
|
101
|
+
children: /* @__PURE__ */ jsx(
|
|
102
|
+
m.rect,
|
|
103
|
+
{
|
|
104
|
+
animate: { x: SWEEP_END_X },
|
|
105
|
+
fill: `url(#${chartId}-grad)`,
|
|
106
|
+
height: "1",
|
|
107
|
+
initial: { x: SWEEP_START_X },
|
|
108
|
+
onUpdate: handleUpdate,
|
|
109
|
+
transition: {
|
|
110
|
+
duration: durationSeconds,
|
|
111
|
+
ease: "linear",
|
|
112
|
+
repeat: Number.POSITIVE_INFINITY,
|
|
113
|
+
repeatType: "loop"
|
|
114
|
+
},
|
|
115
|
+
width: "1",
|
|
116
|
+
y: "0"
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
/* @__PURE__ */ jsx("mask", { id: `${chartId}-mask`, maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("rect", { fill: `url(#${chartId}-pattern)`, height, width }) })
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
function LineLoadingSweep({
|
|
125
|
+
curve,
|
|
126
|
+
withArea = false,
|
|
127
|
+
mode = "loop",
|
|
128
|
+
onTransitionComplete,
|
|
129
|
+
stroke = chartCssVars.foreground,
|
|
130
|
+
strokeOpacity = LINE_STROKE_OPACITY,
|
|
131
|
+
strokeWidth = 2,
|
|
132
|
+
pointCount = DEFAULT_POINT_COUNT,
|
|
133
|
+
durationSeconds = DEFAULT_SWEEP_DURATION_S
|
|
134
|
+
}) {
|
|
135
|
+
const { innerWidth, innerHeight } = useChartStable();
|
|
136
|
+
const reduceMotion = useReducedMotion();
|
|
137
|
+
const reactId = useId();
|
|
138
|
+
const chartId = `line-sweep-${reactId.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
139
|
+
const isLoop = mode === "loop";
|
|
140
|
+
const [tick, setTick] = useState(0);
|
|
141
|
+
const onSweepComplete = useCallback(() => {
|
|
142
|
+
if (isLoop) {
|
|
143
|
+
setTick((prev) => prev + 1);
|
|
144
|
+
}
|
|
145
|
+
}, [isLoop]);
|
|
146
|
+
const heights = useMemo(
|
|
147
|
+
() => getSkeletonHeights(pointCount, tick),
|
|
148
|
+
[pointCount, tick]
|
|
149
|
+
);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (reduceMotion && !isLoop) {
|
|
152
|
+
onTransitionComplete?.();
|
|
153
|
+
}
|
|
154
|
+
}, [reduceMotion, isLoop, onTransitionComplete]);
|
|
155
|
+
if (innerWidth <= 0 || innerHeight <= 0 || heights.length < 2) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const xScale = scaleLinear().domain([0, heights.length - 1]).range([0, innerWidth]);
|
|
159
|
+
const yScale = scaleLinear().domain([0, 100]).range([innerHeight, 0]);
|
|
160
|
+
const points = heights.map((value, index) => ({ index, value }));
|
|
161
|
+
const getX = (d) => xScale(d.index);
|
|
162
|
+
const getY = (d) => yScale(d.value);
|
|
163
|
+
const silhouette = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
164
|
+
withArea ? /* @__PURE__ */ jsx(
|
|
165
|
+
"path",
|
|
166
|
+
{
|
|
167
|
+
d: areaClosedD(points, { curve, x: getX, y: getY, yScale }),
|
|
168
|
+
fill: `url(#${chartId}-area)`
|
|
169
|
+
}
|
|
170
|
+
) : null,
|
|
171
|
+
/* @__PURE__ */ jsx(
|
|
172
|
+
LinePath,
|
|
173
|
+
{
|
|
174
|
+
d: linePathD(points, { curve, x: getX, y: getY }),
|
|
175
|
+
fill: "none",
|
|
176
|
+
stroke,
|
|
177
|
+
strokeLinecap: "round",
|
|
178
|
+
strokeOpacity,
|
|
179
|
+
strokeWidth
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
] });
|
|
183
|
+
const areaGradient = withArea ? /* @__PURE__ */ jsxs("linearGradient", { id: `${chartId}-area`, x1: "0", x2: "0", y1: "0", y2: "1", children: [
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
"stop",
|
|
186
|
+
{
|
|
187
|
+
offset: "0%",
|
|
188
|
+
stopColor: stroke,
|
|
189
|
+
stopOpacity: AREA_FILL_TOP_OPACITY
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
"stop",
|
|
194
|
+
{
|
|
195
|
+
offset: "100%",
|
|
196
|
+
stopColor: stroke,
|
|
197
|
+
stopOpacity: AREA_FILL_BOTTOM_OPACITY
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
] }) : null;
|
|
201
|
+
if (reduceMotion) {
|
|
202
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
203
|
+
areaGradient ? /* @__PURE__ */ jsx("defs", { children: areaGradient }) : null,
|
|
204
|
+
silhouette
|
|
205
|
+
] });
|
|
206
|
+
}
|
|
207
|
+
const maskUrl = `url(#${chartId}-mask)`;
|
|
208
|
+
const defs = /* @__PURE__ */ jsxs("defs", { children: [
|
|
209
|
+
areaGradient,
|
|
210
|
+
/* @__PURE__ */ jsx(
|
|
211
|
+
LoadingSweepMask,
|
|
212
|
+
{
|
|
213
|
+
chartId,
|
|
214
|
+
durationSeconds,
|
|
215
|
+
height: innerHeight,
|
|
216
|
+
onSweepComplete,
|
|
217
|
+
width: innerWidth
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
] });
|
|
221
|
+
if (isLoop) {
|
|
222
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223
|
+
defs,
|
|
224
|
+
/* @__PURE__ */ jsx("g", { mask: maskUrl, children: silhouette })
|
|
225
|
+
] });
|
|
226
|
+
}
|
|
227
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
228
|
+
defs,
|
|
229
|
+
/* @__PURE__ */ jsx(
|
|
230
|
+
m.g,
|
|
231
|
+
{
|
|
232
|
+
animate: { opacity: mode === "exit" ? 0 : 1 },
|
|
233
|
+
initial: { opacity: mode === "exit" ? 1 : 0 },
|
|
234
|
+
mask: maskUrl,
|
|
235
|
+
onAnimationComplete: onTransitionComplete,
|
|
236
|
+
transition: {
|
|
237
|
+
duration: LOADING_LABEL_EXIT_S,
|
|
238
|
+
ease: [...LINE_LOADING_PULSE_EASE]
|
|
239
|
+
},
|
|
240
|
+
children: silhouette
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
] });
|
|
244
|
+
}
|
|
245
|
+
LineLoadingSweep.displayName = "LineLoadingSweep";
|
|
246
|
+
function SkeletonBars({
|
|
247
|
+
heights,
|
|
248
|
+
signs,
|
|
249
|
+
innerWidth,
|
|
250
|
+
innerHeight,
|
|
251
|
+
baseline,
|
|
252
|
+
barFraction,
|
|
253
|
+
fill,
|
|
254
|
+
fillOpacity
|
|
255
|
+
}) {
|
|
256
|
+
const bandWidth = innerWidth / heights.length;
|
|
257
|
+
const barW = bandWidth * barFraction;
|
|
258
|
+
const cornerRadius = Math.min(barW / 2, 8);
|
|
259
|
+
const xOffset = bandWidth * (1 - barFraction) / 2;
|
|
260
|
+
const isCenter = baseline === "center";
|
|
261
|
+
const baselineY = isCenter ? innerHeight / 2 : innerHeight;
|
|
262
|
+
const halfBarH = isCenter ? innerHeight / 2 : innerHeight;
|
|
263
|
+
return /* @__PURE__ */ jsx(Fragment, { children: heights.map((value, i) => {
|
|
264
|
+
const sign = isCenter ? signs[i] ?? 1 : 1;
|
|
265
|
+
const barH = Math.max(1, halfBarH * (value / 100));
|
|
266
|
+
const x = i * bandWidth + xOffset;
|
|
267
|
+
const y = sign === 1 ? baselineY - barH : baselineY;
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
"rect",
|
|
270
|
+
{
|
|
271
|
+
fill,
|
|
272
|
+
fillOpacity,
|
|
273
|
+
height: barH,
|
|
274
|
+
rx: cornerRadius,
|
|
275
|
+
width: barW,
|
|
276
|
+
x,
|
|
277
|
+
y
|
|
278
|
+
},
|
|
279
|
+
`${x.toFixed(2)}-${value}`
|
|
280
|
+
);
|
|
281
|
+
}) });
|
|
282
|
+
}
|
|
283
|
+
function BarLoadingSkeleton({
|
|
284
|
+
innerWidth,
|
|
285
|
+
innerHeight,
|
|
286
|
+
barCount = DEFAULT_BAR_COUNT,
|
|
287
|
+
fill = DEFAULT_FILL,
|
|
288
|
+
fillOpacity = DEFAULT_BAR_FILL_OPACITY,
|
|
289
|
+
baseline = "bottom",
|
|
290
|
+
barFraction = DEFAULT_BAR_FRACTION,
|
|
291
|
+
durationSeconds = DEFAULT_SWEEP_DURATION_S
|
|
292
|
+
}) {
|
|
293
|
+
const reduceMotion = useReducedMotion();
|
|
294
|
+
const reactId = useId();
|
|
295
|
+
const chartId = `bar-sweep-${reactId.replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
296
|
+
const [tick, setTick] = useState(0);
|
|
297
|
+
const onSweepComplete = useCallback(() => setTick((prev) => prev + 1), []);
|
|
298
|
+
const heights = useMemo(
|
|
299
|
+
() => getSkeletonHeights(barCount, tick),
|
|
300
|
+
[barCount, tick]
|
|
301
|
+
);
|
|
302
|
+
const signs = useMemo(
|
|
303
|
+
() => getSkeletonSigns(barCount, tick),
|
|
304
|
+
[barCount, tick]
|
|
305
|
+
);
|
|
306
|
+
if (innerWidth <= 0 || innerHeight <= 0) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
const bars = /* @__PURE__ */ jsx(
|
|
310
|
+
SkeletonBars,
|
|
311
|
+
{
|
|
312
|
+
barFraction,
|
|
313
|
+
baseline,
|
|
314
|
+
fill,
|
|
315
|
+
fillOpacity,
|
|
316
|
+
heights,
|
|
317
|
+
innerHeight,
|
|
318
|
+
innerWidth,
|
|
319
|
+
signs
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
if (reduceMotion) {
|
|
323
|
+
return bars;
|
|
324
|
+
}
|
|
325
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
326
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
|
|
327
|
+
LoadingSweepMask,
|
|
328
|
+
{
|
|
329
|
+
chartId,
|
|
330
|
+
durationSeconds,
|
|
331
|
+
height: innerHeight,
|
|
332
|
+
onSweepComplete,
|
|
333
|
+
width: innerWidth
|
|
334
|
+
}
|
|
335
|
+
) }),
|
|
336
|
+
/* @__PURE__ */ jsx("g", { mask: `url(#${chartId}-mask)`, children: bars })
|
|
337
|
+
] });
|
|
338
|
+
}
|
|
339
|
+
BarLoadingSkeleton.displayName = "BarLoadingSkeleton";
|
|
340
|
+
export {
|
|
341
|
+
BarLoadingSkeleton,
|
|
342
|
+
LineLoadingSweep,
|
|
343
|
+
getSkeletonHeights
|
|
344
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function isElement(value) {
|
|
2
|
+
return typeof Element !== "undefined" && value instanceof Element;
|
|
3
|
+
}
|
|
4
|
+
function isEvent(value) {
|
|
5
|
+
if (typeof Event === "undefined" || !value) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return value instanceof Event || "nativeEvent" in value && value.nativeEvent instanceof Event;
|
|
9
|
+
}
|
|
10
|
+
function clientCoords(event) {
|
|
11
|
+
if ("changedTouches" in event) {
|
|
12
|
+
const touch = event.changedTouches[0];
|
|
13
|
+
return touch ? { x: touch.clientX, y: touch.clientY } : { x: 0, y: 0 };
|
|
14
|
+
}
|
|
15
|
+
if ("clientX" in event) {
|
|
16
|
+
return { x: event.clientX, y: event.clientY };
|
|
17
|
+
}
|
|
18
|
+
const target = event.target;
|
|
19
|
+
if (target && typeof target === "object" && "getBoundingClientRect" in target) {
|
|
20
|
+
const rect = target.getBoundingClientRect();
|
|
21
|
+
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
|
|
22
|
+
}
|
|
23
|
+
return { x: 0, y: 0 };
|
|
24
|
+
}
|
|
25
|
+
function localPointFromNode(node, event) {
|
|
26
|
+
const coords = clientCoords(event);
|
|
27
|
+
const svg = typeof SVGElement !== "undefined" && node instanceof SVGElement || "ownerSVGElement" in node ? node.ownerSVGElement : node;
|
|
28
|
+
const screenCTM = svg && "getScreenCTM" in svg ? svg.getScreenCTM() : null;
|
|
29
|
+
if (svg && "createSVGPoint" in svg && screenCTM) {
|
|
30
|
+
const point = svg.createSVGPoint();
|
|
31
|
+
point.x = coords.x;
|
|
32
|
+
point.y = coords.y;
|
|
33
|
+
const local = point.matrixTransform(screenCTM.inverse());
|
|
34
|
+
return { x: local.x, y: local.y };
|
|
35
|
+
}
|
|
36
|
+
const rect = node.getBoundingClientRect();
|
|
37
|
+
return {
|
|
38
|
+
x: coords.x - rect.left - node.clientLeft,
|
|
39
|
+
y: coords.y - rect.top - node.clientTop
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function localPoint(nodeOrEvent, maybeEvent) {
|
|
43
|
+
if (isElement(nodeOrEvent) && maybeEvent) {
|
|
44
|
+
return localPointFromNode(nodeOrEvent, maybeEvent);
|
|
45
|
+
}
|
|
46
|
+
if (isEvent(nodeOrEvent)) {
|
|
47
|
+
const node = nodeOrEvent.target;
|
|
48
|
+
if (isElement(node)) {
|
|
49
|
+
return localPointFromNode(node, nodeOrEvent);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
localPoint
|
|
56
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
import { chartCssVars, useChart, useChartHover } from "../chart-context";
|
|
5
|
+
import { MarkerGroup } from "./marker-group";
|
|
6
|
+
const MAX_TOOLTIP_MARKERS = 2;
|
|
7
|
+
function MarkerTooltipContent({ markers }) {
|
|
8
|
+
if (markers.length === 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const visibleMarkers = markers.slice(0, MAX_TOOLTIP_MARKERS);
|
|
12
|
+
const hiddenCount = markers.length - MAX_TOOLTIP_MARKERS;
|
|
13
|
+
return /* @__PURE__ */ jsxs("div", { className: "mt-2 space-y-2 border-t pt-2", children: [
|
|
14
|
+
visibleMarkers.map((marker) => {
|
|
15
|
+
const isClickable = !!(marker.onClick || marker.href);
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
17
|
+
/* @__PURE__ */ jsx(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full",
|
|
21
|
+
style: {
|
|
22
|
+
backgroundColor: marker.color || chartCssVars.markerBackground,
|
|
23
|
+
border: `1px solid ${chartCssVars.markerBorder}`
|
|
24
|
+
},
|
|
25
|
+
children: /* @__PURE__ */ jsx(
|
|
26
|
+
"span",
|
|
27
|
+
{
|
|
28
|
+
className: "text-xs",
|
|
29
|
+
style: { color: chartCssVars.markerForeground },
|
|
30
|
+
children: marker.icon
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: marker.content ? marker.content : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
36
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 truncate font-medium text-chart-tooltip-foreground text-sm", children: [
|
|
37
|
+
marker.title,
|
|
38
|
+
isClickable && /* @__PURE__ */ jsx("span", { className: "text-[10px] text-chart-tooltip-muted", children: "\u2197" })
|
|
39
|
+
] }),
|
|
40
|
+
marker.description && /* @__PURE__ */ jsx("div", { className: "truncate text-chart-tooltip-muted text-xs", children: marker.description })
|
|
41
|
+
] }) })
|
|
42
|
+
] }, marker.title);
|
|
43
|
+
}),
|
|
44
|
+
hiddenCount > 0 && /* @__PURE__ */ jsxs("div", { className: "pl-7 text-chart-tooltip-muted text-xs", children: [
|
|
45
|
+
"+",
|
|
46
|
+
hiddenCount,
|
|
47
|
+
" more..."
|
|
48
|
+
] })
|
|
49
|
+
] });
|
|
50
|
+
}
|
|
51
|
+
function ChartMarkers({
|
|
52
|
+
items,
|
|
53
|
+
size = 28,
|
|
54
|
+
showLines = true,
|
|
55
|
+
animate = true
|
|
56
|
+
}) {
|
|
57
|
+
const {
|
|
58
|
+
xScale,
|
|
59
|
+
innerHeight,
|
|
60
|
+
margin,
|
|
61
|
+
containerRef,
|
|
62
|
+
tooltipData,
|
|
63
|
+
setTooltipData,
|
|
64
|
+
animationDuration
|
|
65
|
+
} = useChart();
|
|
66
|
+
const handleMarkerHover = useCallback(
|
|
67
|
+
(markers) => {
|
|
68
|
+
if (markers) {
|
|
69
|
+
setTooltipData(null);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[setTooltipData]
|
|
73
|
+
);
|
|
74
|
+
const markersByDate = useMemo(() => {
|
|
75
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const marker of items) {
|
|
77
|
+
const dateKey = marker.date.toDateString();
|
|
78
|
+
const existing = grouped.get(dateKey) || [];
|
|
79
|
+
grouped.set(dateKey, [...existing, marker]);
|
|
80
|
+
}
|
|
81
|
+
return grouped;
|
|
82
|
+
}, [items]);
|
|
83
|
+
const _activeMarkers = useMemo(() => {
|
|
84
|
+
if (!tooltipData) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const point = tooltipData.point;
|
|
88
|
+
const date = point.date instanceof Date ? point.date : new Date(point.date);
|
|
89
|
+
const dateKey = date.toDateString();
|
|
90
|
+
return markersByDate.get(dateKey) || [];
|
|
91
|
+
}, [tooltipData, markersByDate]);
|
|
92
|
+
const markerY = -8;
|
|
93
|
+
return /* @__PURE__ */ jsx(Fragment, { children: Array.from(markersByDate.entries()).map(
|
|
94
|
+
([dateKey, dateMarkers], groupIndex) => {
|
|
95
|
+
const markerDate = dateMarkers[0]?.date;
|
|
96
|
+
if (!markerDate) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const markerX = xScale(markerDate) ?? 0;
|
|
100
|
+
const isActive = tooltipData ? (() => {
|
|
101
|
+
const point = tooltipData.point;
|
|
102
|
+
const date = point.date instanceof Date ? point.date : new Date(point.date);
|
|
103
|
+
return date.toDateString() === dateKey;
|
|
104
|
+
})() : void 0;
|
|
105
|
+
const markerDelay = animate ? animationDuration / 1e3 + groupIndex * 0.1 : 0;
|
|
106
|
+
return /* @__PURE__ */ jsx(
|
|
107
|
+
MarkerGroup,
|
|
108
|
+
{
|
|
109
|
+
animate,
|
|
110
|
+
animationDelay: markerDelay,
|
|
111
|
+
containerRef,
|
|
112
|
+
isActive,
|
|
113
|
+
lineHeight: innerHeight,
|
|
114
|
+
marginLeft: margin.left,
|
|
115
|
+
marginTop: margin.top,
|
|
116
|
+
markers: dateMarkers,
|
|
117
|
+
onHover: handleMarkerHover,
|
|
118
|
+
showLine: showLines,
|
|
119
|
+
size,
|
|
120
|
+
x: markerX,
|
|
121
|
+
y: markerY
|
|
122
|
+
},
|
|
123
|
+
dateKey
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
) });
|
|
127
|
+
}
|
|
128
|
+
function useActiveMarkers(items) {
|
|
129
|
+
const { tooltipData } = useChartHover();
|
|
130
|
+
return useMemo(() => {
|
|
131
|
+
if (!tooltipData) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const point = tooltipData.point;
|
|
135
|
+
const date = point.date instanceof Date ? point.date : new Date(point.date);
|
|
136
|
+
const dateKey = date.toDateString();
|
|
137
|
+
return items.filter((m) => m.date.toDateString() === dateKey);
|
|
138
|
+
}, [tooltipData, items]);
|
|
139
|
+
}
|
|
140
|
+
ChartMarkers.displayName = "ChartMarkers";
|
|
141
|
+
ChartMarkers.__isChartMarkers = true;
|
|
142
|
+
MarkerTooltipContent.displayName = "MarkerTooltipContent";
|
|
143
|
+
var chart_markers_default = ChartMarkers;
|
|
144
|
+
export {
|
|
145
|
+
ChartMarkers,
|
|
146
|
+
MarkerTooltipContent,
|
|
147
|
+
chart_markers_default as default,
|
|
148
|
+
useActiveMarkers
|
|
149
|
+
};
|