@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,545 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { scaleBand, scaleLinear } from "d3-scale";
|
|
4
|
+
import { domAnimation, LazyMotion } from "motion/react";
|
|
5
|
+
import {
|
|
6
|
+
memo,
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
13
|
+
import { cn } from "../lib/utils";
|
|
14
|
+
import { DEFAULT_ANIMATION_EASING } from "./animation";
|
|
15
|
+
import { topSquareCenterY } from "./bar-squares-layout";
|
|
16
|
+
import {
|
|
17
|
+
forEachChartChild,
|
|
18
|
+
isClipExcludedComponent,
|
|
19
|
+
isPostOverlayComponent,
|
|
20
|
+
isUnderlayComponent,
|
|
21
|
+
renderKeyedChartLayers,
|
|
22
|
+
resolveChartChildElement
|
|
23
|
+
} from "./chart-child-passthrough";
|
|
24
|
+
import {
|
|
25
|
+
ChartProvider
|
|
26
|
+
} from "./chart-context";
|
|
27
|
+
import { useChartDataOverride } from "./chart-data-override";
|
|
28
|
+
import { isGradientDefComponent, isPatternDefComponent } from "./chart-defs";
|
|
29
|
+
import { shortDateFmt } from "./chart-formatters";
|
|
30
|
+
import { ParentSize } from "./chart-parent-size";
|
|
31
|
+
import {
|
|
32
|
+
DEFAULT_CHART_LIFECYCLE,
|
|
33
|
+
resolveRestingChartPhase
|
|
34
|
+
} from "./chart-phase";
|
|
35
|
+
import { BarLoadingSkeleton } from "./loading-sweep";
|
|
36
|
+
import { localPoint } from "./local-point";
|
|
37
|
+
import { extractReferenceAreaConfigs } from "./reference-area-config";
|
|
38
|
+
import { useScheduledTooltip } from "./use-scheduled-tooltip";
|
|
39
|
+
import { InteracaoProvider, useInteracaoAic } from "../aic/interacao";
|
|
40
|
+
import {
|
|
41
|
+
buildYScalesForLines,
|
|
42
|
+
getPrimaryYScale,
|
|
43
|
+
normalizeYAxisId,
|
|
44
|
+
wrapSingleYScale
|
|
45
|
+
} from "./y-axis-scales";
|
|
46
|
+
import {
|
|
47
|
+
collectBarValueExtents,
|
|
48
|
+
resolveBarValueDomain
|
|
49
|
+
} from "./y-domain-utils";
|
|
50
|
+
const FALLBACK_LOADING_BARS = 12;
|
|
51
|
+
const DEFAULT_MARGIN = { top: 40, right: 40, bottom: 40, left: 40 };
|
|
52
|
+
function isSeriesOverlayComponent(child) {
|
|
53
|
+
const childType = child.type;
|
|
54
|
+
const componentName = typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
|
|
55
|
+
return componentName === "TrendLine";
|
|
56
|
+
}
|
|
57
|
+
function extractBarConfigs(children) {
|
|
58
|
+
const configs = [];
|
|
59
|
+
forEachChartChild(children, (child) => {
|
|
60
|
+
const childType = child.type;
|
|
61
|
+
if (childType.__isBarDepthLayer) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const componentName = typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
|
|
65
|
+
if (componentName === "TrendLine") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const props = child.props;
|
|
69
|
+
const isBarComponent = componentName === "Bar" || componentName === "BarSquares" || props && typeof props.dataKey === "string" && props.dataKey.length > 0;
|
|
70
|
+
if (isBarComponent && props?.dataKey) {
|
|
71
|
+
const dotColor = props.stroke || props.fill || "var(--chart-line-primary)";
|
|
72
|
+
configs.push({
|
|
73
|
+
dataKey: props.dataKey,
|
|
74
|
+
stroke: dotColor,
|
|
75
|
+
strokeWidth: 0,
|
|
76
|
+
yAxisId: props.yAxisId
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return configs;
|
|
81
|
+
}
|
|
82
|
+
function ChartInner(props) {
|
|
83
|
+
const { width, height } = props;
|
|
84
|
+
if (width < 10 || height < 10) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return /* @__PURE__ */ jsx(ChartCore, { ...props });
|
|
88
|
+
}
|
|
89
|
+
const ChartCore = memo(function ChartCore2({
|
|
90
|
+
width,
|
|
91
|
+
height,
|
|
92
|
+
data,
|
|
93
|
+
xDataKey,
|
|
94
|
+
margin,
|
|
95
|
+
animationDuration,
|
|
96
|
+
animationEasing,
|
|
97
|
+
enterTransition,
|
|
98
|
+
revealSignature = "",
|
|
99
|
+
barGap,
|
|
100
|
+
barWidthProp,
|
|
101
|
+
orientation,
|
|
102
|
+
stacked,
|
|
103
|
+
stackGap,
|
|
104
|
+
squareSnap,
|
|
105
|
+
children,
|
|
106
|
+
containerRef,
|
|
107
|
+
onPhaseChange,
|
|
108
|
+
status,
|
|
109
|
+
loadingFill
|
|
110
|
+
}) {
|
|
111
|
+
const { tooltipData, setTooltipData, scheduleTooltip, clearTooltip } = useScheduledTooltip();
|
|
112
|
+
const [isLoaded, setIsLoaded] = useState(
|
|
113
|
+
() => animationDuration <= 0 && status !== "loading"
|
|
114
|
+
);
|
|
115
|
+
const [revealEpoch, setRevealEpoch] = useState(1);
|
|
116
|
+
const hoveredBarIndex = tooltipData?.index ?? null;
|
|
117
|
+
const aic = useInteracaoAic();
|
|
118
|
+
const isHorizontal = orientation === "horizontal";
|
|
119
|
+
const lines = useMemo(() => extractBarConfigs(children), [children]);
|
|
120
|
+
const effectiveLoadingFill = loadingFill ?? lines[0]?.stroke ?? "var(--chart-foreground)";
|
|
121
|
+
const innerWidth = width - margin.left - margin.right;
|
|
122
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
123
|
+
const categoryAccessor = useCallback(
|
|
124
|
+
(d) => {
|
|
125
|
+
const value = d[xDataKey];
|
|
126
|
+
if (value instanceof Date) {
|
|
127
|
+
return shortDateFmt.format(value);
|
|
128
|
+
}
|
|
129
|
+
return String(value ?? "");
|
|
130
|
+
},
|
|
131
|
+
[xDataKey]
|
|
132
|
+
);
|
|
133
|
+
const xAccessorDate = useCallback(
|
|
134
|
+
(d) => {
|
|
135
|
+
const value = d[xDataKey];
|
|
136
|
+
if (value instanceof Date) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
return /* @__PURE__ */ new Date();
|
|
140
|
+
},
|
|
141
|
+
[xDataKey]
|
|
142
|
+
);
|
|
143
|
+
const categoryScale = useMemo(() => {
|
|
144
|
+
const domain = data.map((d) => categoryAccessor(d));
|
|
145
|
+
const range = isHorizontal ? [0, innerHeight] : [0, innerWidth];
|
|
146
|
+
return scaleBand().domain(domain).range(range).padding(barGap);
|
|
147
|
+
}, [innerWidth, innerHeight, data, categoryAccessor, barGap, isHorizontal]);
|
|
148
|
+
const bandWidth = barWidthProp ?? categoryScale.bandwidth();
|
|
149
|
+
const valueExtents = useMemo(
|
|
150
|
+
() => collectBarValueExtents(
|
|
151
|
+
data,
|
|
152
|
+
lines.map((line) => line.dataKey),
|
|
153
|
+
stacked
|
|
154
|
+
),
|
|
155
|
+
[data, lines, stacked]
|
|
156
|
+
);
|
|
157
|
+
const valueScale = useMemo(() => {
|
|
158
|
+
const range = isHorizontal ? [0, innerWidth] : [innerHeight, 0];
|
|
159
|
+
return scaleLinear().domain(resolveBarValueDomain(valueExtents)).nice().range(range);
|
|
160
|
+
}, [innerWidth, innerHeight, valueExtents, isHorizontal]);
|
|
161
|
+
const yScales = useMemo(() => {
|
|
162
|
+
if (isHorizontal) {
|
|
163
|
+
return wrapSingleYScale(valueScale);
|
|
164
|
+
}
|
|
165
|
+
return buildYScalesForLines({
|
|
166
|
+
lines,
|
|
167
|
+
data,
|
|
168
|
+
innerHeight,
|
|
169
|
+
resolveDomain: (dataKeys) => resolveBarValueDomain(collectBarValueExtents(data, dataKeys, stacked))
|
|
170
|
+
});
|
|
171
|
+
}, [data, innerHeight, isHorizontal, lines, stacked, valueScale]);
|
|
172
|
+
const primaryYScale = getPrimaryYScale(yScales, valueScale);
|
|
173
|
+
const stackOffsets = useMemo(() => {
|
|
174
|
+
if (!stacked) {
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
178
|
+
for (let i = 0; i < data.length; i++) {
|
|
179
|
+
const d = data[i];
|
|
180
|
+
if (!d) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const pointOffsets = /* @__PURE__ */ new Map();
|
|
184
|
+
let cumulative = 0;
|
|
185
|
+
for (const line of lines) {
|
|
186
|
+
pointOffsets.set(line.dataKey, cumulative);
|
|
187
|
+
const value = d[line.dataKey];
|
|
188
|
+
if (typeof value === "number") {
|
|
189
|
+
cumulative += value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
offsets.set(i, pointOffsets);
|
|
193
|
+
}
|
|
194
|
+
return offsets;
|
|
195
|
+
}, [data, lines, stacked]);
|
|
196
|
+
const columnWidth = useMemo(() => {
|
|
197
|
+
if (data.length < 1) {
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
return isHorizontal ? innerHeight / data.length : innerWidth / data.length;
|
|
201
|
+
}, [innerWidth, innerHeight, data.length, isHorizontal]);
|
|
202
|
+
const dateLabels = useMemo(
|
|
203
|
+
() => data.map((d) => categoryAccessor(d)),
|
|
204
|
+
[data, categoryAccessor]
|
|
205
|
+
);
|
|
206
|
+
const fakeTimeScale = useMemo(() => {
|
|
207
|
+
const now = Date.now();
|
|
208
|
+
const start = now - data.length * 24 * 60 * 60 * 1e3;
|
|
209
|
+
const scale = {
|
|
210
|
+
...categoryScale,
|
|
211
|
+
domain: () => [new Date(start), new Date(now)],
|
|
212
|
+
range: () => [0, innerWidth],
|
|
213
|
+
invert: (x) => new Date(start + x / innerWidth * (now - start)),
|
|
214
|
+
copy: () => scale
|
|
215
|
+
};
|
|
216
|
+
return scale;
|
|
217
|
+
}, [categoryScale, innerWidth, data.length]);
|
|
218
|
+
const [revealKey, setRevealKey] = useState({
|
|
219
|
+
animationDuration,
|
|
220
|
+
revealSignature,
|
|
221
|
+
status
|
|
222
|
+
});
|
|
223
|
+
if (revealKey.animationDuration !== animationDuration || revealKey.revealSignature !== revealSignature || revealKey.status !== status) {
|
|
224
|
+
setRevealKey({ animationDuration, revealSignature, status });
|
|
225
|
+
setRevealEpoch((n) => n + 1);
|
|
226
|
+
setIsLoaded(animationDuration <= 0 && status !== "loading");
|
|
227
|
+
}
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (status === "loading") {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const staggerMs = data.length > 1 ? animationDuration * 0.4 : 0;
|
|
233
|
+
const timer = setTimeout(() => {
|
|
234
|
+
setIsLoaded(true);
|
|
235
|
+
}, animationDuration + staggerMs);
|
|
236
|
+
return () => clearTimeout(timer);
|
|
237
|
+
}, [animationDuration, revealSignature, status]);
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
onPhaseChange?.(isLoaded ? "ready" : "revealing");
|
|
240
|
+
}, [isLoaded, onPhaseChange]);
|
|
241
|
+
const handleMouseMove = useCallback(
|
|
242
|
+
(event) => {
|
|
243
|
+
const point = localPoint(event);
|
|
244
|
+
if (!point) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const pos = isHorizontal ? point.y - margin.top : point.x - margin.left;
|
|
248
|
+
const bandIndex = Math.floor(pos / columnWidth);
|
|
249
|
+
const clampedIndex = Math.max(0, Math.min(data.length - 1, bandIndex));
|
|
250
|
+
const d = data[clampedIndex];
|
|
251
|
+
if (!d) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const yPositions = {};
|
|
255
|
+
const xPositions = {};
|
|
256
|
+
const barPos = categoryScale(categoryAccessor(d)) ?? 0;
|
|
257
|
+
if (isHorizontal) {
|
|
258
|
+
const seriesCount = lines.length;
|
|
259
|
+
const groupGap = seriesCount > 1 ? 4 : 0;
|
|
260
|
+
const individualBarHeight = seriesCount > 0 ? (bandWidth - groupGap * (seriesCount - 1)) / seriesCount : bandWidth;
|
|
261
|
+
if (stacked) {
|
|
262
|
+
let cumulative = 0;
|
|
263
|
+
for (const line of lines) {
|
|
264
|
+
const value = d[line.dataKey];
|
|
265
|
+
if (typeof value === "number") {
|
|
266
|
+
cumulative += value;
|
|
267
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? valueScale;
|
|
268
|
+
xPositions[line.dataKey] = axisScale(cumulative) ?? 0;
|
|
269
|
+
yPositions[line.dataKey] = barPos + bandWidth / 2;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
lines.forEach((line, idx) => {
|
|
274
|
+
const value = d[line.dataKey];
|
|
275
|
+
if (typeof value === "number") {
|
|
276
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? valueScale;
|
|
277
|
+
xPositions[line.dataKey] = axisScale(value) ?? 0;
|
|
278
|
+
yPositions[line.dataKey] = barPos + idx * (individualBarHeight + groupGap) + individualBarHeight / 2;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
} else if (stacked) {
|
|
283
|
+
let cumulative = 0;
|
|
284
|
+
let seriesIdx = 0;
|
|
285
|
+
for (const line of lines) {
|
|
286
|
+
const value = d[line.dataKey];
|
|
287
|
+
if (typeof value === "number") {
|
|
288
|
+
cumulative += value;
|
|
289
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? primaryYScale;
|
|
290
|
+
const gapOffset = seriesIdx * stackGap;
|
|
291
|
+
yPositions[line.dataKey] = (axisScale(cumulative) ?? 0) - gapOffset;
|
|
292
|
+
seriesIdx++;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
const seriesCount = lines.length;
|
|
297
|
+
const groupGap = seriesCount > 1 ? 4 : 0;
|
|
298
|
+
const individualBarWidth = seriesCount > 0 ? (bandWidth - groupGap * (seriesCount - 1)) / seriesCount : bandWidth;
|
|
299
|
+
lines.forEach((line, idx) => {
|
|
300
|
+
const value = d[line.dataKey];
|
|
301
|
+
if (typeof value === "number") {
|
|
302
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? primaryYScale;
|
|
303
|
+
const baselineY = axisScale(0) ?? innerHeight;
|
|
304
|
+
const valueY = axisScale(value) ?? 0;
|
|
305
|
+
const barLengthPx = baselineY - valueY;
|
|
306
|
+
if (squareSnap && !isHorizontal && value > 0) {
|
|
307
|
+
yPositions[line.dataKey] = topSquareCenterY({
|
|
308
|
+
baselineY,
|
|
309
|
+
barLengthPx,
|
|
310
|
+
squareSize: individualBarWidth,
|
|
311
|
+
gap: squareSnap.squareGap,
|
|
312
|
+
fit: squareSnap.fit
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
yPositions[line.dataKey] = valueY;
|
|
316
|
+
}
|
|
317
|
+
xPositions[line.dataKey] = barPos + idx * (individualBarWidth + groupGap) + individualBarWidth / 2;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
let tooltipX;
|
|
322
|
+
if (isHorizontal) {
|
|
323
|
+
const maxX = Math.max(...Object.values(xPositions), valueScale(0) ?? 0);
|
|
324
|
+
tooltipX = maxX;
|
|
325
|
+
} else {
|
|
326
|
+
tooltipX = barPos + bandWidth / 2;
|
|
327
|
+
}
|
|
328
|
+
scheduleTooltip({
|
|
329
|
+
point: d,
|
|
330
|
+
index: clampedIndex,
|
|
331
|
+
x: tooltipX,
|
|
332
|
+
yPositions,
|
|
333
|
+
xPositions: Object.keys(xPositions).length > 0 ? xPositions : void 0
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
[
|
|
337
|
+
categoryScale,
|
|
338
|
+
valueScale,
|
|
339
|
+
data,
|
|
340
|
+
lines,
|
|
341
|
+
margin.left,
|
|
342
|
+
margin.top,
|
|
343
|
+
categoryAccessor,
|
|
344
|
+
columnWidth,
|
|
345
|
+
bandWidth,
|
|
346
|
+
isHorizontal,
|
|
347
|
+
stacked,
|
|
348
|
+
stackGap,
|
|
349
|
+
scheduleTooltip,
|
|
350
|
+
yScales,
|
|
351
|
+
primaryYScale,
|
|
352
|
+
squareSnap,
|
|
353
|
+
innerHeight
|
|
354
|
+
]
|
|
355
|
+
);
|
|
356
|
+
const handleMouseLeave = useCallback(() => {
|
|
357
|
+
clearTooltip();
|
|
358
|
+
}, [clearTooltip]);
|
|
359
|
+
const canInteract = isLoaded;
|
|
360
|
+
const defsChildren = [];
|
|
361
|
+
const clipExcludedChildren = [];
|
|
362
|
+
const underlayChildren = [];
|
|
363
|
+
const preOverlayChildren = [];
|
|
364
|
+
const seriesOverlayChildren = [];
|
|
365
|
+
const postOverlayChildren = [];
|
|
366
|
+
forEachChartChild(children, (child) => {
|
|
367
|
+
const resolvedChild = resolveChartChildElement(child);
|
|
368
|
+
if (isGradientDefComponent(child)) {
|
|
369
|
+
defsChildren.push(child);
|
|
370
|
+
} else if (isPatternDefComponent(child)) {
|
|
371
|
+
preOverlayChildren.push(child);
|
|
372
|
+
} else if (isPostOverlayComponent(resolvedChild)) {
|
|
373
|
+
postOverlayChildren.push(child);
|
|
374
|
+
} else if (isClipExcludedComponent(resolvedChild)) {
|
|
375
|
+
clipExcludedChildren.push(child);
|
|
376
|
+
} else if (isUnderlayComponent(resolvedChild)) {
|
|
377
|
+
underlayChildren.push(child);
|
|
378
|
+
} else if (isSeriesOverlayComponent(resolvedChild)) {
|
|
379
|
+
seriesOverlayChildren.push(child);
|
|
380
|
+
} else {
|
|
381
|
+
preOverlayChildren.push(child);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
const referenceAreas = useMemo(
|
|
385
|
+
() => extractReferenceAreaConfigs(children),
|
|
386
|
+
[children]
|
|
387
|
+
);
|
|
388
|
+
const contextValue = {
|
|
389
|
+
...DEFAULT_CHART_LIFECYCLE,
|
|
390
|
+
chartPhase: resolveRestingChartPhase(status),
|
|
391
|
+
chartStatus: status,
|
|
392
|
+
data,
|
|
393
|
+
renderData: data,
|
|
394
|
+
xScale: fakeTimeScale,
|
|
395
|
+
yScale: isHorizontal ? valueScale : primaryYScale,
|
|
396
|
+
yScales,
|
|
397
|
+
width,
|
|
398
|
+
height,
|
|
399
|
+
innerWidth,
|
|
400
|
+
innerHeight,
|
|
401
|
+
margin,
|
|
402
|
+
columnWidth,
|
|
403
|
+
tooltipData,
|
|
404
|
+
setTooltipData,
|
|
405
|
+
containerRef,
|
|
406
|
+
lines,
|
|
407
|
+
referenceAreas,
|
|
408
|
+
isLoaded,
|
|
409
|
+
animationDuration,
|
|
410
|
+
animationEasing,
|
|
411
|
+
enterTransition,
|
|
412
|
+
revealEpoch,
|
|
413
|
+
xAccessor: xAccessorDate,
|
|
414
|
+
dateLabels,
|
|
415
|
+
// Bar-specific properties
|
|
416
|
+
barScale: categoryScale,
|
|
417
|
+
bandWidth,
|
|
418
|
+
hoveredBarIndex,
|
|
419
|
+
barXAccessor: categoryAccessor,
|
|
420
|
+
orientation,
|
|
421
|
+
stacked,
|
|
422
|
+
stackOffsets,
|
|
423
|
+
squareSnap
|
|
424
|
+
};
|
|
425
|
+
return /* @__PURE__ */ jsx(ChartProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
|
|
426
|
+
"svg",
|
|
427
|
+
{
|
|
428
|
+
"aria-hidden": "true",
|
|
429
|
+
className: "overflow-visible",
|
|
430
|
+
height,
|
|
431
|
+
width,
|
|
432
|
+
children: [
|
|
433
|
+
defsChildren.length > 0 && /* @__PURE__ */ jsx("defs", { children: defsChildren }),
|
|
434
|
+
/* @__PURE__ */ jsx("rect", { fill: "transparent", height, width, x: 0, y: 0 }),
|
|
435
|
+
/* @__PURE__ */ jsxs(
|
|
436
|
+
"g",
|
|
437
|
+
{
|
|
438
|
+
onClick: canInteract && aic.aoClicar && hoveredBarIndex !== null ? () => aic.aoClicar?.(hoveredBarIndex) : void 0,
|
|
439
|
+
onMouseLeave: canInteract ? handleMouseLeave : void 0,
|
|
440
|
+
onMouseMove: canInteract ? handleMouseMove : void 0,
|
|
441
|
+
style: {
|
|
442
|
+
cursor: canInteract ? aic.aoClicar ? "pointer" : "crosshair" : "default"
|
|
443
|
+
},
|
|
444
|
+
transform: `translate(${margin.left},${margin.top})`,
|
|
445
|
+
children: [
|
|
446
|
+
/* @__PURE__ */ jsx(
|
|
447
|
+
"rect",
|
|
448
|
+
{
|
|
449
|
+
fill: "transparent",
|
|
450
|
+
height: innerHeight,
|
|
451
|
+
width: innerWidth,
|
|
452
|
+
x: 0,
|
|
453
|
+
y: 0
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
renderKeyedChartLayers(clipExcludedChildren),
|
|
457
|
+
renderKeyedChartLayers(underlayChildren),
|
|
458
|
+
status === "loading" ? /* @__PURE__ */ jsx(
|
|
459
|
+
BarLoadingSkeleton,
|
|
460
|
+
{
|
|
461
|
+
barCount: data.length || FALLBACK_LOADING_BARS,
|
|
462
|
+
fill: effectiveLoadingFill,
|
|
463
|
+
innerHeight,
|
|
464
|
+
innerWidth
|
|
465
|
+
}
|
|
466
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
467
|
+
renderKeyedChartLayers(preOverlayChildren),
|
|
468
|
+
renderKeyedChartLayers(seriesOverlayChildren)
|
|
469
|
+
] }),
|
|
470
|
+
renderKeyedChartLayers(postOverlayChildren)
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
) });
|
|
477
|
+
});
|
|
478
|
+
function BarChart({
|
|
479
|
+
data: dataProp,
|
|
480
|
+
xDataKey = "name",
|
|
481
|
+
margin: marginProp,
|
|
482
|
+
animationDuration = 1100,
|
|
483
|
+
animationEasing = DEFAULT_ANIMATION_EASING,
|
|
484
|
+
enterTransition,
|
|
485
|
+
revealSignature,
|
|
486
|
+
aspectRatio = "2 / 1",
|
|
487
|
+
className = "",
|
|
488
|
+
barGap = 0.2,
|
|
489
|
+
barWidth,
|
|
490
|
+
orientation = "vertical",
|
|
491
|
+
stacked = false,
|
|
492
|
+
stackGap = 0,
|
|
493
|
+
squareSnap,
|
|
494
|
+
children,
|
|
495
|
+
onPhaseChange,
|
|
496
|
+
status = "ready",
|
|
497
|
+
loadingFill,
|
|
498
|
+
onBarClick,
|
|
499
|
+
selectedIndex
|
|
500
|
+
}) {
|
|
501
|
+
const { data } = useChartDataOverride("BarChart", {
|
|
502
|
+
data: dataProp
|
|
503
|
+
});
|
|
504
|
+
const containerRef = useRef(null);
|
|
505
|
+
const margin = { ...DEFAULT_MARGIN, ...marginProp };
|
|
506
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(InteracaoProvider, { aoClicar: onBarClick, data, selecao: selectedIndex, children: /* @__PURE__ */ jsx(
|
|
507
|
+
"div",
|
|
508
|
+
{
|
|
509
|
+
className: cn("relative w-full overflow-visible", className),
|
|
510
|
+
ref: containerRef,
|
|
511
|
+
style: { aspectRatio },
|
|
512
|
+
children: /* @__PURE__ */ jsx(ParentSize, { debounceTime: 10, children: ({ width, height }) => /* @__PURE__ */ jsx(
|
|
513
|
+
ChartInner,
|
|
514
|
+
{
|
|
515
|
+
animationDuration,
|
|
516
|
+
animationEasing,
|
|
517
|
+
barGap,
|
|
518
|
+
barWidthProp: barWidth,
|
|
519
|
+
containerRef,
|
|
520
|
+
data,
|
|
521
|
+
enterTransition,
|
|
522
|
+
height,
|
|
523
|
+
loadingFill,
|
|
524
|
+
margin,
|
|
525
|
+
onPhaseChange,
|
|
526
|
+
orientation,
|
|
527
|
+
revealSignature,
|
|
528
|
+
squareSnap,
|
|
529
|
+
stacked,
|
|
530
|
+
stackGap,
|
|
531
|
+
status,
|
|
532
|
+
width,
|
|
533
|
+
xDataKey,
|
|
534
|
+
children
|
|
535
|
+
}
|
|
536
|
+
) })
|
|
537
|
+
}
|
|
538
|
+
) }) });
|
|
539
|
+
}
|
|
540
|
+
BarChart.displayName = "BarChart";
|
|
541
|
+
var bar_chart_default = BarChart;
|
|
542
|
+
export {
|
|
543
|
+
BarChart,
|
|
544
|
+
bar_chart_default as default
|
|
545
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const BAR_DEPTH_MAX_PX = 7;
|
|
2
|
+
const BAR_DEPTH_PERSPECTIVE_RATIO = 0.45;
|
|
3
|
+
function barDepthMaxDepth(stepWidth, bandWidth) {
|
|
4
|
+
const gap = Math.max(0, stepWidth - bandWidth);
|
|
5
|
+
return Math.min(bandWidth * 0.22, Math.max(0, gap - 1), BAR_DEPTH_MAX_PX);
|
|
6
|
+
}
|
|
7
|
+
function barDepthAndRise(absOffset, naturalHeight, maxDepth) {
|
|
8
|
+
const offset = Math.min(1, Math.max(0, absOffset));
|
|
9
|
+
const cappedMaxDepth = Math.min(maxDepth, Math.max(0, naturalHeight));
|
|
10
|
+
const depth = offset * cappedMaxDepth;
|
|
11
|
+
return { depth, perspectiveRise: depth * BAR_DEPTH_PERSPECTIVE_RATIO };
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
BAR_DEPTH_MAX_PX,
|
|
15
|
+
BAR_DEPTH_PERSPECTIVE_RATIO,
|
|
16
|
+
barDepthAndRise,
|
|
17
|
+
barDepthMaxDepth
|
|
18
|
+
};
|