@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,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { m } from "motion/react";
|
|
4
|
+
import { memo, useMemo } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import {
|
|
8
|
+
useChart,
|
|
9
|
+
useChartPortalContainer,
|
|
10
|
+
useChartStable
|
|
11
|
+
} from "./chart-context";
|
|
12
|
+
function BarYAxisLabel({
|
|
13
|
+
label,
|
|
14
|
+
y,
|
|
15
|
+
bandHeight,
|
|
16
|
+
isHovered
|
|
17
|
+
}) {
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"div",
|
|
20
|
+
{
|
|
21
|
+
className: "absolute right-0 flex items-center justify-end pr-2",
|
|
22
|
+
style: {
|
|
23
|
+
top: y,
|
|
24
|
+
height: bandHeight
|
|
25
|
+
},
|
|
26
|
+
children: /* @__PURE__ */ jsx(
|
|
27
|
+
m.span,
|
|
28
|
+
{
|
|
29
|
+
animate: {
|
|
30
|
+
opacity: isHovered ? 1 : 0.7,
|
|
31
|
+
color: isHovered ? "var(--chart-foreground)" : "var(--chart-label, var(--chart-foreground-muted))"
|
|
32
|
+
},
|
|
33
|
+
className: cn("truncate whitespace-nowrap text-right text-xs"),
|
|
34
|
+
initial: {
|
|
35
|
+
opacity: 0.7,
|
|
36
|
+
color: "var(--chart-label, var(--chart-foreground-muted))"
|
|
37
|
+
},
|
|
38
|
+
style: { maxWidth: "var(--bar-y-label-max, 70px)" },
|
|
39
|
+
transition: { duration: 0.15 },
|
|
40
|
+
children: label
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function BarYAxis(props) {
|
|
47
|
+
const { containerRef, barScale } = useChartStable();
|
|
48
|
+
const container = useChartPortalContainer(containerRef);
|
|
49
|
+
if (!container) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!barScale) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ jsx(BarYAxisInner, { ...props, container });
|
|
56
|
+
}
|
|
57
|
+
const BarYAxisInner = memo(function BarYAxisInner2({
|
|
58
|
+
showAllLabels = true,
|
|
59
|
+
maxLabels = 20,
|
|
60
|
+
container
|
|
61
|
+
}) {
|
|
62
|
+
const { margin, barScale, bandWidth, barXAccessor, data, hoveredBarIndex } = useChart();
|
|
63
|
+
const labelsToShow = useMemo(() => {
|
|
64
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const allLabels = data.map((d, i) => {
|
|
68
|
+
const label = barXAccessor(d);
|
|
69
|
+
const bandY = barScale(label) ?? 0;
|
|
70
|
+
const y = bandY + margin.top;
|
|
71
|
+
return { label, y, bandHeight: bandWidth, index: i };
|
|
72
|
+
});
|
|
73
|
+
if (showAllLabels || allLabels.length <= maxLabels) {
|
|
74
|
+
return allLabels;
|
|
75
|
+
}
|
|
76
|
+
const step = Math.ceil(allLabels.length / maxLabels);
|
|
77
|
+
return allLabels.filter((_, i) => i % step === 0);
|
|
78
|
+
}, [
|
|
79
|
+
barScale,
|
|
80
|
+
bandWidth,
|
|
81
|
+
barXAccessor,
|
|
82
|
+
data,
|
|
83
|
+
margin.top,
|
|
84
|
+
showAllLabels,
|
|
85
|
+
maxLabels
|
|
86
|
+
]);
|
|
87
|
+
return createPortal(
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"div",
|
|
90
|
+
{
|
|
91
|
+
className: "pointer-events-none absolute top-0 bottom-0",
|
|
92
|
+
style: {
|
|
93
|
+
left: 0,
|
|
94
|
+
width: margin.left
|
|
95
|
+
},
|
|
96
|
+
children: labelsToShow.map((item) => /* @__PURE__ */ jsx(
|
|
97
|
+
BarYAxisLabel,
|
|
98
|
+
{
|
|
99
|
+
bandHeight: item.bandHeight,
|
|
100
|
+
isHovered: hoveredBarIndex === item.index,
|
|
101
|
+
label: item.label,
|
|
102
|
+
y: item.y
|
|
103
|
+
},
|
|
104
|
+
`${item.label}-${item.y}`
|
|
105
|
+
))
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
container
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
BarYAxis.displayName = "BarYAxis";
|
|
112
|
+
var bar_y_axis_default = BarYAxis;
|
|
113
|
+
export {
|
|
114
|
+
BarYAxis,
|
|
115
|
+
bar_y_axis_default as default
|
|
116
|
+
};
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m } from "motion/react";
|
|
4
|
+
import { memo, useId, useMemo } from "react";
|
|
5
|
+
import { barDepthAndRise, barDepthMaxDepth } from "./bar-depth-geometry";
|
|
6
|
+
import {
|
|
7
|
+
getBarValueLabelLayout
|
|
8
|
+
} from "./bar-value-label-layout";
|
|
9
|
+
import {
|
|
10
|
+
chartCssVars,
|
|
11
|
+
useChartHover,
|
|
12
|
+
useChartStable,
|
|
13
|
+
useYScale
|
|
14
|
+
} from "./chart-context";
|
|
15
|
+
import { valueLabelFmt } from "./chart-formatters";
|
|
16
|
+
import { useChartLegendHover } from "./chart-legend-hover";
|
|
17
|
+
import { estaEsmaecido, useInteracaoAic } from "../aic/interacao";
|
|
18
|
+
import { transitionWithDelay } from "./motion-utils";
|
|
19
|
+
function barDepthPerspectiveRise(barScale, bandWidth, barXAccessor, innerWidth, datum, topY, baselineY) {
|
|
20
|
+
const centerX = innerWidth / 2;
|
|
21
|
+
if (centerX <= 0) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
const step = barScale.step?.() ?? bandWidth;
|
|
25
|
+
const maxDepth = barDepthMaxDepth(step, bandWidth);
|
|
26
|
+
const bandX = barScale(barXAccessor(datum)) ?? 0;
|
|
27
|
+
const cx = bandX + bandWidth / 2;
|
|
28
|
+
const absOffset = Math.min(1, Math.abs((cx - centerX) / centerX));
|
|
29
|
+
const naturalHeight = Math.abs(baselineY - topY);
|
|
30
|
+
return barDepthAndRise(absOffset, naturalHeight, maxDepth).perspectiveRise;
|
|
31
|
+
}
|
|
32
|
+
function AnimatedBar({
|
|
33
|
+
x,
|
|
34
|
+
y,
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
fill,
|
|
38
|
+
rx,
|
|
39
|
+
ry,
|
|
40
|
+
index,
|
|
41
|
+
isFaded,
|
|
42
|
+
animationType,
|
|
43
|
+
fadedOpacity,
|
|
44
|
+
staggerDelay,
|
|
45
|
+
enterTransition,
|
|
46
|
+
revealEpoch,
|
|
47
|
+
isHorizontal,
|
|
48
|
+
growOrigin,
|
|
49
|
+
valueLabel,
|
|
50
|
+
valueLabelColor,
|
|
51
|
+
labelX,
|
|
52
|
+
labelY,
|
|
53
|
+
labelTransform,
|
|
54
|
+
valueLabelClassName
|
|
55
|
+
}) {
|
|
56
|
+
const enterAnim = transitionWithDelay(enterTransition, index * staggerDelay);
|
|
57
|
+
const label = valueLabel ? /* @__PURE__ */ jsx(
|
|
58
|
+
m.text,
|
|
59
|
+
{
|
|
60
|
+
animate: { opacity: isFaded ? fadedOpacity : 1 },
|
|
61
|
+
className: valueLabelClassName,
|
|
62
|
+
dominantBaseline: "middle",
|
|
63
|
+
fill: valueLabelColor,
|
|
64
|
+
fontSize: 12,
|
|
65
|
+
fontWeight: 600,
|
|
66
|
+
initial: { opacity: 0 },
|
|
67
|
+
textAnchor: "middle",
|
|
68
|
+
transform: labelTransform,
|
|
69
|
+
transition: enterAnim,
|
|
70
|
+
x: labelX,
|
|
71
|
+
y: labelY,
|
|
72
|
+
children: valueLabel
|
|
73
|
+
}
|
|
74
|
+
) : null;
|
|
75
|
+
if (animationType === "fade") {
|
|
76
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
m.rect,
|
|
79
|
+
{
|
|
80
|
+
animate: {
|
|
81
|
+
opacity: isFaded ? fadedOpacity : 1,
|
|
82
|
+
filter: "blur(0px)"
|
|
83
|
+
},
|
|
84
|
+
fill,
|
|
85
|
+
height,
|
|
86
|
+
initial: { opacity: 0, filter: "blur(2px)" },
|
|
87
|
+
rx,
|
|
88
|
+
ry,
|
|
89
|
+
transition: enterAnim,
|
|
90
|
+
width,
|
|
91
|
+
x,
|
|
92
|
+
y
|
|
93
|
+
},
|
|
94
|
+
`fade-${index}-${revealEpoch}`
|
|
95
|
+
),
|
|
96
|
+
label
|
|
97
|
+
] });
|
|
98
|
+
}
|
|
99
|
+
const initial = isHorizontal ? { width: 0, height, x: growOrigin, y } : { width, height: 0, x, y: growOrigin };
|
|
100
|
+
const target = isHorizontal ? { width, height, x, y } : { width, height, x, y };
|
|
101
|
+
return /* @__PURE__ */ jsxs(
|
|
102
|
+
"g",
|
|
103
|
+
{
|
|
104
|
+
opacity: isFaded ? fadedOpacity : 1,
|
|
105
|
+
style: { transition: "opacity 0.15s ease-in-out" },
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ jsx(
|
|
108
|
+
m.rect,
|
|
109
|
+
{
|
|
110
|
+
animate: target,
|
|
111
|
+
fill,
|
|
112
|
+
initial,
|
|
113
|
+
rx,
|
|
114
|
+
ry,
|
|
115
|
+
transition: enterAnim
|
|
116
|
+
},
|
|
117
|
+
`grow-${index}-${revealEpoch}`
|
|
118
|
+
),
|
|
119
|
+
label
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const STATIC_BAR_STYLE = {
|
|
125
|
+
cursor: "default",
|
|
126
|
+
transition: "opacity 0.15s ease-in-out"
|
|
127
|
+
};
|
|
128
|
+
const STATIC_LABEL_STYLE = { transition: "opacity 0.15s ease-in-out" };
|
|
129
|
+
const StaticBar = memo(function StaticBar2({
|
|
130
|
+
geometry,
|
|
131
|
+
fill,
|
|
132
|
+
opacity,
|
|
133
|
+
valueLabelColor,
|
|
134
|
+
valueLabelClassName
|
|
135
|
+
}) {
|
|
136
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
137
|
+
/* @__PURE__ */ jsx(
|
|
138
|
+
"rect",
|
|
139
|
+
{
|
|
140
|
+
fill,
|
|
141
|
+
height: geometry.height,
|
|
142
|
+
opacity,
|
|
143
|
+
rx: geometry.rx,
|
|
144
|
+
ry: geometry.rx,
|
|
145
|
+
style: STATIC_BAR_STYLE,
|
|
146
|
+
width: geometry.width,
|
|
147
|
+
x: geometry.x,
|
|
148
|
+
y: geometry.y
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
geometry.valueLabel ? /* @__PURE__ */ jsx(
|
|
152
|
+
"text",
|
|
153
|
+
{
|
|
154
|
+
className: valueLabelClassName,
|
|
155
|
+
dominantBaseline: "middle",
|
|
156
|
+
fill: valueLabelColor,
|
|
157
|
+
fontSize: 12,
|
|
158
|
+
fontWeight: 600,
|
|
159
|
+
opacity,
|
|
160
|
+
style: STATIC_LABEL_STYLE,
|
|
161
|
+
textAnchor: "middle",
|
|
162
|
+
transform: geometry.labelTransform,
|
|
163
|
+
x: geometry.labelX,
|
|
164
|
+
y: geometry.labelY,
|
|
165
|
+
children: geometry.valueLabel
|
|
166
|
+
}
|
|
167
|
+
) : null
|
|
168
|
+
] });
|
|
169
|
+
});
|
|
170
|
+
const BarInner = memo(function BarInner2({
|
|
171
|
+
dataKey,
|
|
172
|
+
yAxisId,
|
|
173
|
+
fill = chartCssVars.linePrimary,
|
|
174
|
+
lineCap = "round",
|
|
175
|
+
animate = true,
|
|
176
|
+
animationType = "grow",
|
|
177
|
+
fadedOpacity = 0.3,
|
|
178
|
+
staggerDelay,
|
|
179
|
+
stackGap = 0,
|
|
180
|
+
groupGap = 4,
|
|
181
|
+
perspective = false,
|
|
182
|
+
minBarHeight = 0,
|
|
183
|
+
showValue = false,
|
|
184
|
+
valueLabelFormatter = valueLabelFmt,
|
|
185
|
+
valueLabelColor = "white",
|
|
186
|
+
valueLabelOrientation = "auto",
|
|
187
|
+
valueLabelPosition = "center",
|
|
188
|
+
valueLabelClassName,
|
|
189
|
+
barScale,
|
|
190
|
+
bandWidth,
|
|
191
|
+
barXAccessor
|
|
192
|
+
}) {
|
|
193
|
+
const {
|
|
194
|
+
data,
|
|
195
|
+
yScale: chartYScale,
|
|
196
|
+
innerHeight,
|
|
197
|
+
innerWidth,
|
|
198
|
+
isLoaded,
|
|
199
|
+
lines,
|
|
200
|
+
orientation,
|
|
201
|
+
stacked,
|
|
202
|
+
stackOffsets,
|
|
203
|
+
animationDuration,
|
|
204
|
+
enterTransition,
|
|
205
|
+
revealEpoch = 0
|
|
206
|
+
} = useChartStable();
|
|
207
|
+
const { hoveredBarIndex = null } = useChartHover();
|
|
208
|
+
const { selecionados } = useInteracaoAic();
|
|
209
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
210
|
+
const staggerSpread = totalAnimDuration * 0.4;
|
|
211
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1e3 / data.length : 0);
|
|
212
|
+
const uniqueId = useId();
|
|
213
|
+
const isHorizontal = orientation === "horizontal";
|
|
214
|
+
const { hoveredIndex: legendHoveredIndex } = useChartLegendHover();
|
|
215
|
+
const seriesIndex = useMemo(() => {
|
|
216
|
+
const idx = lines.findIndex((l) => l.dataKey === dataKey);
|
|
217
|
+
return idx >= 0 ? idx : 0;
|
|
218
|
+
}, [lines, dataKey]);
|
|
219
|
+
const seriesConfig = lines[seriesIndex];
|
|
220
|
+
const valueScale = useYScale(yAxisId ?? seriesConfig?.yAxisId);
|
|
221
|
+
const isLegendDimmed = legendHoveredIndex !== null && legendHoveredIndex !== seriesIndex;
|
|
222
|
+
const seriesCount = lines.length;
|
|
223
|
+
const isLastSeries = seriesIndex === seriesCount - 1;
|
|
224
|
+
const barWidth = useMemo(() => {
|
|
225
|
+
if (!bandWidth || seriesCount === 0) {
|
|
226
|
+
return 0;
|
|
227
|
+
}
|
|
228
|
+
if (stacked) {
|
|
229
|
+
return bandWidth;
|
|
230
|
+
}
|
|
231
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
232
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
233
|
+
}, [bandWidth, seriesCount, stacked, groupGap]);
|
|
234
|
+
const cornerRadius = useMemo(() => {
|
|
235
|
+
if (perspective) {
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
if (typeof lineCap === "number") {
|
|
239
|
+
return lineCap;
|
|
240
|
+
}
|
|
241
|
+
if (lineCap === "round" && barWidth) {
|
|
242
|
+
return Math.min(barWidth / 2, 8);
|
|
243
|
+
}
|
|
244
|
+
return 0;
|
|
245
|
+
}, [lineCap, barWidth, perspective]);
|
|
246
|
+
const geometries = useMemo(() => {
|
|
247
|
+
const result = [];
|
|
248
|
+
const scale = isHorizontal ? chartYScale : valueScale;
|
|
249
|
+
const zeroX = isHorizontal ? scale(0) ?? 0 : 0;
|
|
250
|
+
const zeroY = isHorizontal ? 0 : scale(0) ?? innerHeight;
|
|
251
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
252
|
+
const applyRounding = !stacked || stackGap > 0 || isLastSeries;
|
|
253
|
+
const effectiveRx = applyRounding ? cornerRadius : 0;
|
|
254
|
+
for (let i = 0; i < data.length; i++) {
|
|
255
|
+
const d = data[i];
|
|
256
|
+
const value = d[dataKey];
|
|
257
|
+
if (typeof value !== "number") {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const categoryValue = barXAccessor(d);
|
|
261
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
262
|
+
let x = 0;
|
|
263
|
+
let y = 0;
|
|
264
|
+
let barHeight;
|
|
265
|
+
let barW;
|
|
266
|
+
if (isHorizontal) {
|
|
267
|
+
const valuePos = scale(value) ?? 0;
|
|
268
|
+
barW = valuePos;
|
|
269
|
+
barHeight = barWidth;
|
|
270
|
+
if (stacked && stackOffsets) {
|
|
271
|
+
const offset = stackOffsets.get(i)?.get(dataKey) ?? 0;
|
|
272
|
+
x = scale(offset) ?? 0;
|
|
273
|
+
barW = (scale(offset + value) ?? 0) - x;
|
|
274
|
+
const gapOffset = seriesIndex * stackGap;
|
|
275
|
+
x += gapOffset;
|
|
276
|
+
if (!isLastSeries && stackGap > 0) {
|
|
277
|
+
barW = Math.max(0, barW - stackGap);
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
x = Math.min(valuePos, zeroX);
|
|
281
|
+
barW = Math.abs(valuePos - zeroX);
|
|
282
|
+
}
|
|
283
|
+
y = stacked ? bandPos : bandPos + seriesIndex * (barWidth + effectiveGroupGap);
|
|
284
|
+
} else {
|
|
285
|
+
const valuePos = scale(value) ?? 0;
|
|
286
|
+
barHeight = Math.abs(zeroY - valuePos);
|
|
287
|
+
barW = barWidth;
|
|
288
|
+
if (stacked && stackOffsets) {
|
|
289
|
+
const offset = stackOffsets.get(i)?.get(dataKey) ?? 0;
|
|
290
|
+
const offsetY = scale(offset) ?? innerHeight;
|
|
291
|
+
const gapOffset = seriesIndex * stackGap;
|
|
292
|
+
y = offsetY - barHeight - gapOffset;
|
|
293
|
+
if (!isLastSeries && stackGap > 0) {
|
|
294
|
+
barHeight = Math.max(0, barHeight - stackGap);
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
y = Math.min(valuePos, zeroY);
|
|
298
|
+
}
|
|
299
|
+
x = stacked ? bandPos : bandPos + seriesIndex * (barWidth + effectiveGroupGap);
|
|
300
|
+
let isFloored = false;
|
|
301
|
+
if (!stacked && minBarHeight > 0 && value >= 0 && barHeight < minBarHeight) {
|
|
302
|
+
barHeight = minBarHeight;
|
|
303
|
+
y = zeroY - minBarHeight;
|
|
304
|
+
isFloored = true;
|
|
305
|
+
}
|
|
306
|
+
if (perspective && value > 0 && !isFloored && (!stacked || isLastSeries)) {
|
|
307
|
+
const rise = barDepthPerspectiveRise(
|
|
308
|
+
barScale,
|
|
309
|
+
bandWidth,
|
|
310
|
+
barXAccessor,
|
|
311
|
+
innerWidth,
|
|
312
|
+
d,
|
|
313
|
+
y,
|
|
314
|
+
zeroY
|
|
315
|
+
);
|
|
316
|
+
const trim = Math.min(rise, Math.max(0, barHeight - 1));
|
|
317
|
+
y += trim;
|
|
318
|
+
barHeight -= trim;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
let labelX = 0;
|
|
322
|
+
let labelY = 0;
|
|
323
|
+
let labelTransform;
|
|
324
|
+
let valueLabel;
|
|
325
|
+
if (showValue) {
|
|
326
|
+
const text = valueLabelFormatter(value);
|
|
327
|
+
const labelLayout = getBarValueLabelLayout({
|
|
328
|
+
x,
|
|
329
|
+
y,
|
|
330
|
+
width: barW,
|
|
331
|
+
height: barHeight,
|
|
332
|
+
labelWidth: text.length * 7.2,
|
|
333
|
+
isHorizontal,
|
|
334
|
+
orientation: valueLabelOrientation,
|
|
335
|
+
position: valueLabelPosition
|
|
336
|
+
});
|
|
337
|
+
labelX = labelLayout.x;
|
|
338
|
+
labelY = labelLayout.y;
|
|
339
|
+
labelTransform = labelLayout.rotated ? `rotate(-90 ${labelLayout.x} ${labelLayout.y})` : void 0;
|
|
340
|
+
valueLabel = labelLayout.fits ? text : void 0;
|
|
341
|
+
}
|
|
342
|
+
let growOrigin = zeroY;
|
|
343
|
+
if (isHorizontal) {
|
|
344
|
+
growOrigin = stacked ? x : zeroX;
|
|
345
|
+
}
|
|
346
|
+
result.push({
|
|
347
|
+
// Use categoryValue as key since it's the unique identifier from data
|
|
348
|
+
key: `bar-${dataKey}-${categoryValue}`,
|
|
349
|
+
index: i,
|
|
350
|
+
x,
|
|
351
|
+
y,
|
|
352
|
+
width: barW,
|
|
353
|
+
height: barHeight,
|
|
354
|
+
rx: effectiveRx,
|
|
355
|
+
growOrigin,
|
|
356
|
+
valueLabel,
|
|
357
|
+
labelX,
|
|
358
|
+
labelY,
|
|
359
|
+
labelTransform
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
}, [
|
|
364
|
+
bandWidth,
|
|
365
|
+
barScale,
|
|
366
|
+
barWidth,
|
|
367
|
+
barXAccessor,
|
|
368
|
+
chartYScale,
|
|
369
|
+
cornerRadius,
|
|
370
|
+
data,
|
|
371
|
+
dataKey,
|
|
372
|
+
groupGap,
|
|
373
|
+
innerHeight,
|
|
374
|
+
innerWidth,
|
|
375
|
+
isHorizontal,
|
|
376
|
+
isLastSeries,
|
|
377
|
+
minBarHeight,
|
|
378
|
+
perspective,
|
|
379
|
+
seriesCount,
|
|
380
|
+
seriesIndex,
|
|
381
|
+
showValue,
|
|
382
|
+
stackGap,
|
|
383
|
+
stackOffsets,
|
|
384
|
+
stacked,
|
|
385
|
+
valueLabelFormatter,
|
|
386
|
+
valueLabelOrientation,
|
|
387
|
+
valueLabelPosition,
|
|
388
|
+
valueScale
|
|
389
|
+
]);
|
|
390
|
+
const animating = animate && !isLoaded;
|
|
391
|
+
return /* @__PURE__ */ jsx("g", { className: `bar-series-${uniqueId}`, children: geometries.map((bar) => {
|
|
392
|
+
const isFaded = estaEsmaecido(bar.index, hoveredBarIndex, selecionados) || isLegendDimmed;
|
|
393
|
+
if (animating) {
|
|
394
|
+
return /* @__PURE__ */ jsx(
|
|
395
|
+
AnimatedBar,
|
|
396
|
+
{
|
|
397
|
+
animationType,
|
|
398
|
+
enterTransition,
|
|
399
|
+
fadedOpacity,
|
|
400
|
+
fill,
|
|
401
|
+
growOrigin: bar.growOrigin,
|
|
402
|
+
height: bar.height,
|
|
403
|
+
index: bar.index,
|
|
404
|
+
isFaded,
|
|
405
|
+
isHorizontal,
|
|
406
|
+
labelTransform: bar.labelTransform,
|
|
407
|
+
labelX: bar.labelX,
|
|
408
|
+
labelY: bar.labelY,
|
|
409
|
+
revealEpoch,
|
|
410
|
+
rx: bar.rx,
|
|
411
|
+
ry: bar.rx,
|
|
412
|
+
staggerDelay: calculatedStaggerDelay,
|
|
413
|
+
valueLabel: bar.valueLabel,
|
|
414
|
+
valueLabelClassName,
|
|
415
|
+
valueLabelColor,
|
|
416
|
+
width: bar.width,
|
|
417
|
+
x: bar.x,
|
|
418
|
+
y: bar.y
|
|
419
|
+
},
|
|
420
|
+
bar.key
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
return /* @__PURE__ */ jsx(
|
|
424
|
+
StaticBar,
|
|
425
|
+
{
|
|
426
|
+
fill,
|
|
427
|
+
geometry: bar,
|
|
428
|
+
opacity: isFaded ? fadedOpacity : 1,
|
|
429
|
+
valueLabelClassName,
|
|
430
|
+
valueLabelColor
|
|
431
|
+
},
|
|
432
|
+
bar.key
|
|
433
|
+
);
|
|
434
|
+
}) });
|
|
435
|
+
});
|
|
436
|
+
function Bar(props) {
|
|
437
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
438
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
439
|
+
console.warn("Bar component must be used within a BarChart");
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
return /* @__PURE__ */ jsx(
|
|
443
|
+
BarInner,
|
|
444
|
+
{
|
|
445
|
+
...props,
|
|
446
|
+
bandWidth,
|
|
447
|
+
barScale,
|
|
448
|
+
barXAccessor
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
Bar.displayName = "Bar";
|
|
453
|
+
var bar_default = Bar;
|
|
454
|
+
export {
|
|
455
|
+
Bar,
|
|
456
|
+
bar_default as default
|
|
457
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function withBollingerBands(data, options) {
|
|
2
|
+
const {
|
|
3
|
+
dataKey,
|
|
4
|
+
period = 20,
|
|
5
|
+
multiplier = 2,
|
|
6
|
+
upperKey = `${dataKey}Upper`,
|
|
7
|
+
lowerKey = `${dataKey}Lower`,
|
|
8
|
+
middleKey = `${dataKey}Sma`,
|
|
9
|
+
minPeriods = period
|
|
10
|
+
} = options;
|
|
11
|
+
const windowSize = Math.max(1, Math.floor(period));
|
|
12
|
+
const requiredCount = Math.min(
|
|
13
|
+
windowSize,
|
|
14
|
+
Math.max(
|
|
15
|
+
1,
|
|
16
|
+
Number.isFinite(minPeriods) ? Math.floor(minPeriods) : windowSize
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
return data.map((row, index) => {
|
|
20
|
+
let upper = null;
|
|
21
|
+
let lower = null;
|
|
22
|
+
let middle = null;
|
|
23
|
+
const values = [];
|
|
24
|
+
for (let offset = Math.max(0, index - windowSize + 1); offset <= index; offset++) {
|
|
25
|
+
const value = data[offset]?.[dataKey];
|
|
26
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
27
|
+
values.push(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (values.length >= requiredCount) {
|
|
31
|
+
const count = values.length;
|
|
32
|
+
const mean = values.reduce((sum, value) => sum + value, 0) / count;
|
|
33
|
+
const variance = values.reduce((sum, value) => sum + (value - mean) ** 2, 0) / count;
|
|
34
|
+
const spread = multiplier * Math.sqrt(variance);
|
|
35
|
+
middle = mean;
|
|
36
|
+
upper = mean + spread;
|
|
37
|
+
lower = mean - spread;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...row,
|
|
41
|
+
[upperKey]: upper,
|
|
42
|
+
[lowerKey]: lower,
|
|
43
|
+
[middleKey]: middle
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
withBollingerBands
|
|
49
|
+
};
|