@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,523 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useMemo } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
import {
|
|
7
|
+
chartCssVars,
|
|
8
|
+
selectTooltipData,
|
|
9
|
+
useChartHoverSelector,
|
|
10
|
+
useChartPortalContainer,
|
|
11
|
+
useChartStable
|
|
12
|
+
} from "./chart-context";
|
|
13
|
+
import { shortDateFmt } from "./chart-formatters";
|
|
14
|
+
import { DEFAULT_Y_DOMAIN_TWEEN_MS } from "./chart-phase";
|
|
15
|
+
import { useDatePillPresent } from "./date-pill-store";
|
|
16
|
+
import { LINE_LOADING_PULSE_EASE } from "./line-loading-timing";
|
|
17
|
+
import {
|
|
18
|
+
resolveResponsiveChartLabelCount
|
|
19
|
+
} from "./responsive-chart-label-count";
|
|
20
|
+
import {
|
|
21
|
+
xAxisLabelColor,
|
|
22
|
+
xAxisLabelHighlight,
|
|
23
|
+
xAxisLabelOpacity
|
|
24
|
+
} from "./x-axis-hover";
|
|
25
|
+
const X_AXIS_POSITION_TWEEN_MS = DEFAULT_Y_DOMAIN_TWEEN_MS;
|
|
26
|
+
const XAxisLabel = memo(function XAxisLabel2({
|
|
27
|
+
label,
|
|
28
|
+
x,
|
|
29
|
+
opacity,
|
|
30
|
+
color,
|
|
31
|
+
animatePosition,
|
|
32
|
+
className
|
|
33
|
+
}) {
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
className: "absolute",
|
|
38
|
+
style: {
|
|
39
|
+
left: x,
|
|
40
|
+
bottom: 12,
|
|
41
|
+
width: 0,
|
|
42
|
+
display: "flex",
|
|
43
|
+
justifyContent: "center",
|
|
44
|
+
transition: animatePosition ? `left ${X_AXIS_POSITION_TWEEN_MS}ms cubic-bezier(${LINE_LOADING_PULSE_EASE.join(", ")})` : void 0
|
|
45
|
+
},
|
|
46
|
+
children: /* @__PURE__ */ jsx(
|
|
47
|
+
"span",
|
|
48
|
+
{
|
|
49
|
+
className: cn("whitespace-nowrap text-chart-label text-xs", className),
|
|
50
|
+
style: {
|
|
51
|
+
opacity,
|
|
52
|
+
color,
|
|
53
|
+
transition: "opacity 0.4s ease-in-out, color 0.2s ease-out"
|
|
54
|
+
},
|
|
55
|
+
children: label
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
const MAX_GAP_LAYOUTS = 400;
|
|
62
|
+
function binomial(n, k) {
|
|
63
|
+
if (k < 0 || k > n) {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
let result = 1;
|
|
67
|
+
for (let i = 0; i < k; i++) {
|
|
68
|
+
result = result * (n - i) / (i + 1);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function composePositiveSum(sum, parts) {
|
|
73
|
+
if (parts === 1) {
|
|
74
|
+
return sum >= 1 ? [[sum]] : [];
|
|
75
|
+
}
|
|
76
|
+
const layouts = [];
|
|
77
|
+
for (let gap = 1; gap <= sum - (parts - 1); gap++) {
|
|
78
|
+
for (const tail of composePositiveSum(sum - gap, parts - 1)) {
|
|
79
|
+
layouts.push([gap, ...tail]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return layouts;
|
|
83
|
+
}
|
|
84
|
+
function gapsToIndices(gaps) {
|
|
85
|
+
const indices = [0];
|
|
86
|
+
let position = 0;
|
|
87
|
+
for (const gap of gaps) {
|
|
88
|
+
position += gap;
|
|
89
|
+
indices.push(position);
|
|
90
|
+
}
|
|
91
|
+
return indices;
|
|
92
|
+
}
|
|
93
|
+
function indicesForTickCount(length, tickCount) {
|
|
94
|
+
const span = length - 1;
|
|
95
|
+
if (span <= 0) {
|
|
96
|
+
return [0];
|
|
97
|
+
}
|
|
98
|
+
const rawIndices = Array.from(
|
|
99
|
+
{ length: tickCount },
|
|
100
|
+
(_, index) => Math.round(index / (tickCount - 1) * span)
|
|
101
|
+
);
|
|
102
|
+
const indices = [...new Set(rawIndices)].sort((a, b) => a - b);
|
|
103
|
+
if (indices[0] !== 0) {
|
|
104
|
+
indices.unshift(0);
|
|
105
|
+
}
|
|
106
|
+
if (indices.at(-1) !== span) {
|
|
107
|
+
indices.push(span);
|
|
108
|
+
}
|
|
109
|
+
return [...new Set(indices)].sort((a, b) => a - b);
|
|
110
|
+
}
|
|
111
|
+
function allIndexLayouts(length, tickCount) {
|
|
112
|
+
const span = length - 1;
|
|
113
|
+
if (span <= 0) {
|
|
114
|
+
return [[0]];
|
|
115
|
+
}
|
|
116
|
+
const gapCount = tickCount - 1;
|
|
117
|
+
if (gapCount <= 0) {
|
|
118
|
+
return [[0]];
|
|
119
|
+
}
|
|
120
|
+
const layoutCount = binomial(span - 1, gapCount - 1);
|
|
121
|
+
if (layoutCount > MAX_GAP_LAYOUTS) {
|
|
122
|
+
return [indicesForTickCount(length, tickCount)];
|
|
123
|
+
}
|
|
124
|
+
return composePositiveSum(span, gapCount).map(gapsToIndices);
|
|
125
|
+
}
|
|
126
|
+
function dedupeIndicesByLabel(indices, data, dateLabels, xAccessor) {
|
|
127
|
+
const seenLabels = /* @__PURE__ */ new Set();
|
|
128
|
+
const deduped = [];
|
|
129
|
+
for (const index of indices) {
|
|
130
|
+
const point = data[index];
|
|
131
|
+
if (!point) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const label = dateLabels[index] ?? shortDateFmt.format(xAccessor(point));
|
|
135
|
+
if (seenLabels.has(label)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
seenLabels.add(label);
|
|
139
|
+
deduped.push(index);
|
|
140
|
+
}
|
|
141
|
+
return deduped;
|
|
142
|
+
}
|
|
143
|
+
function indexGaps(indices) {
|
|
144
|
+
const gaps = [];
|
|
145
|
+
for (let i = 1; i < indices.length; i++) {
|
|
146
|
+
const current = indices[i];
|
|
147
|
+
const previous = indices[i - 1];
|
|
148
|
+
if (current == null || previous == null) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
gaps.push(current - previous);
|
|
152
|
+
}
|
|
153
|
+
return gaps;
|
|
154
|
+
}
|
|
155
|
+
function smallestGapEdgePreference(indices) {
|
|
156
|
+
const gaps = indexGaps(indices);
|
|
157
|
+
const smallestGap = Math.min(...gaps);
|
|
158
|
+
const smallestGapIndex = gaps.indexOf(smallestGap);
|
|
159
|
+
if (smallestGapIndex === gaps.length - 1) {
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
if (smallestGapIndex === 0) {
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
return 2;
|
|
166
|
+
}
|
|
167
|
+
function scoreTickLayout(indices, resolveXPx, targetCount) {
|
|
168
|
+
if (indices.length < 2) {
|
|
169
|
+
return {
|
|
170
|
+
score: Number.POSITIVE_INFINITY,
|
|
171
|
+
symmetryPenalty: Number.POSITIVE_INFINITY,
|
|
172
|
+
countDistance: Number.POSITIVE_INFINITY,
|
|
173
|
+
edgePreference: Number.POSITIVE_INFINITY
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const pixelGaps = [];
|
|
177
|
+
for (let i = 1; i < indices.length; i++) {
|
|
178
|
+
const current = indices[i];
|
|
179
|
+
const previous = indices[i - 1];
|
|
180
|
+
if (current == null || previous == null) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
pixelGaps.push(resolveXPx(current) - resolveXPx(previous));
|
|
184
|
+
}
|
|
185
|
+
const minGap = Math.min(...pixelGaps);
|
|
186
|
+
const maxGap = Math.max(...pixelGaps);
|
|
187
|
+
const meanGap = pixelGaps.reduce((sum, gap) => sum + gap, 0) / pixelGaps.length;
|
|
188
|
+
const spreadRatio = meanGap > 0 ? (maxGap - minGap) / meanGap : maxGap - minGap;
|
|
189
|
+
const countDistance = Math.abs(indices.length - targetCount);
|
|
190
|
+
const gaps = indexGaps(indices);
|
|
191
|
+
const smallestGap = Math.min(...gaps);
|
|
192
|
+
const smallestGapIndex = gaps.indexOf(smallestGap);
|
|
193
|
+
const interiorPenalty = smallestGapIndex > 0 && smallestGapIndex < gaps.length - 1 ? 0.08 : 0;
|
|
194
|
+
const symmetryPenalty = gaps.reduce((penalty, gap, index) => {
|
|
195
|
+
return penalty + Math.abs(gap - (gaps.at(-1 - index) ?? gap));
|
|
196
|
+
}, 0) / gaps.length;
|
|
197
|
+
return {
|
|
198
|
+
score: spreadRatio + 0.1 * countDistance + interiorPenalty + symmetryPenalty * 0.02,
|
|
199
|
+
symmetryPenalty,
|
|
200
|
+
countDistance,
|
|
201
|
+
edgePreference: smallestGapEdgePreference(indices)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function isBetterTickLayout(next, best, nextCountDistance, bestCountDistance) {
|
|
205
|
+
if (next.score < best.score - 1e-6) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
if (Math.abs(next.score - best.score) > 1e-6) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (nextCountDistance < bestCountDistance) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
if (nextCountDistance > bestCountDistance) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (next.symmetryPenalty < best.symmetryPenalty - 1e-6) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
if (next.symmetryPenalty > best.symmetryPenalty + 1e-6) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return next.edgePreference < best.edgePreference;
|
|
224
|
+
}
|
|
225
|
+
function selectEvenlySpacedIndices(length, targetCount, options) {
|
|
226
|
+
if (length <= 0) {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
if (length === 1) {
|
|
230
|
+
return [0];
|
|
231
|
+
}
|
|
232
|
+
if (length <= targetCount) {
|
|
233
|
+
return Array.from({ length }, (_, index) => index);
|
|
234
|
+
}
|
|
235
|
+
const resolveXPx = options?.resolveXPx ?? ((index) => index);
|
|
236
|
+
const minCount = Math.max(2, targetCount - 1);
|
|
237
|
+
const maxCount = Math.min(length, targetCount + 1);
|
|
238
|
+
let bestIndices = indicesForTickCount(length, targetCount);
|
|
239
|
+
let bestScore = scoreTickLayout(bestIndices, resolveXPx, targetCount);
|
|
240
|
+
let bestCountDistance = bestScore.countDistance;
|
|
241
|
+
for (let tickCount = minCount; tickCount <= maxCount; tickCount++) {
|
|
242
|
+
for (const rawIndices of allIndexLayouts(length, tickCount)) {
|
|
243
|
+
const indices = options?.data && options.dateLabels && options.xAccessor ? dedupeIndicesByLabel(
|
|
244
|
+
rawIndices,
|
|
245
|
+
options.data,
|
|
246
|
+
options.dateLabels,
|
|
247
|
+
options.xAccessor
|
|
248
|
+
) : rawIndices;
|
|
249
|
+
if (indices.length < 2) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const layoutScore = scoreTickLayout(indices, resolveXPx, targetCount);
|
|
253
|
+
const countDistance = Math.abs(indices.length - targetCount);
|
|
254
|
+
if (isBetterTickLayout(
|
|
255
|
+
layoutScore,
|
|
256
|
+
bestScore,
|
|
257
|
+
countDistance,
|
|
258
|
+
bestCountDistance
|
|
259
|
+
)) {
|
|
260
|
+
bestIndices = indices;
|
|
261
|
+
bestScore = layoutScore;
|
|
262
|
+
bestCountDistance = countDistance;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return bestIndices;
|
|
267
|
+
}
|
|
268
|
+
function buildDataAlignedTicks({
|
|
269
|
+
data,
|
|
270
|
+
dateLabels,
|
|
271
|
+
marginLeft,
|
|
272
|
+
targetTickCount,
|
|
273
|
+
xAccessor,
|
|
274
|
+
xScale
|
|
275
|
+
}) {
|
|
276
|
+
const seenLabels = /* @__PURE__ */ new Set();
|
|
277
|
+
const ticks = [];
|
|
278
|
+
const resolveXPx = (index) => {
|
|
279
|
+
const point = data[index];
|
|
280
|
+
if (!point) {
|
|
281
|
+
return index;
|
|
282
|
+
}
|
|
283
|
+
return xScale(xAccessor(point)) ?? 0;
|
|
284
|
+
};
|
|
285
|
+
for (const index of selectEvenlySpacedIndices(data.length, targetTickCount, {
|
|
286
|
+
data,
|
|
287
|
+
dateLabels,
|
|
288
|
+
resolveXPx,
|
|
289
|
+
xAccessor
|
|
290
|
+
})) {
|
|
291
|
+
const point = data[index];
|
|
292
|
+
if (!point) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const date = xAccessor(point);
|
|
296
|
+
const label = dateLabels[index] ?? shortDateFmt.format(date);
|
|
297
|
+
if (seenLabels.has(label)) {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
seenLabels.add(label);
|
|
301
|
+
ticks.push({
|
|
302
|
+
date,
|
|
303
|
+
label,
|
|
304
|
+
x: (xScale(date) ?? 0) + marginLeft
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return ticks;
|
|
308
|
+
}
|
|
309
|
+
function buildDomainTicks({
|
|
310
|
+
marginLeft,
|
|
311
|
+
numTicks,
|
|
312
|
+
xScale
|
|
313
|
+
}) {
|
|
314
|
+
const domain = xScale.domain();
|
|
315
|
+
const startDate = domain[0];
|
|
316
|
+
const endDate = domain[1];
|
|
317
|
+
if (!(startDate && endDate)) {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
const startTime = startDate.getTime();
|
|
321
|
+
const endTime = endDate.getTime();
|
|
322
|
+
const timeRange = endTime - startTime;
|
|
323
|
+
const tickCount = Math.max(2, numTicks);
|
|
324
|
+
const seenLabels = /* @__PURE__ */ new Set();
|
|
325
|
+
const ticks = [];
|
|
326
|
+
for (let i = 0; i < tickCount; i++) {
|
|
327
|
+
const t = i / (tickCount - 1);
|
|
328
|
+
const date = new Date(startTime + t * timeRange);
|
|
329
|
+
const label = shortDateFmt.format(date);
|
|
330
|
+
if (seenLabels.has(label)) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
seenLabels.add(label);
|
|
334
|
+
ticks.push({
|
|
335
|
+
date,
|
|
336
|
+
label,
|
|
337
|
+
x: (xScale(date) ?? 0) + marginLeft
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return ticks;
|
|
341
|
+
}
|
|
342
|
+
function domainExtendsPastData(data, xAccessor, xScale) {
|
|
343
|
+
if (data.length === 0) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
const domainEnd = xScale.domain()[1];
|
|
347
|
+
const lastPoint = data.at(-1);
|
|
348
|
+
if (!(domainEnd && lastPoint)) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
return domainEnd.getTime() > xAccessor(lastPoint).getTime();
|
|
352
|
+
}
|
|
353
|
+
function appendProjectionTailTicks(ticks, data, xAccessor, xScale, marginLeft, maxExtraTicks) {
|
|
354
|
+
if (data.length === 0 || maxExtraTicks <= 0) {
|
|
355
|
+
return ticks;
|
|
356
|
+
}
|
|
357
|
+
const lastPoint = data.at(-1);
|
|
358
|
+
const domainEnd = xScale.domain()[1];
|
|
359
|
+
if (!(lastPoint && domainEnd)) {
|
|
360
|
+
return ticks;
|
|
361
|
+
}
|
|
362
|
+
const lastDate = xAccessor(lastPoint);
|
|
363
|
+
const startTime = lastDate.getTime();
|
|
364
|
+
const endTime = domainEnd.getTime();
|
|
365
|
+
if (endTime <= startTime) {
|
|
366
|
+
return ticks;
|
|
367
|
+
}
|
|
368
|
+
const seenLabels = new Set(ticks.map((tick) => tick.label));
|
|
369
|
+
const extras = [];
|
|
370
|
+
const extraCount = Math.min(maxExtraTicks, 3);
|
|
371
|
+
for (let i = 1; i <= extraCount; i++) {
|
|
372
|
+
const date = new Date(
|
|
373
|
+
startTime + i / (extraCount + 1) * (endTime - startTime)
|
|
374
|
+
);
|
|
375
|
+
const label = shortDateFmt.format(date);
|
|
376
|
+
if (seenLabels.has(label)) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
seenLabels.add(label);
|
|
380
|
+
extras.push({
|
|
381
|
+
date,
|
|
382
|
+
label,
|
|
383
|
+
x: (xScale(date) ?? 0) + marginLeft
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
const endLabel = shortDateFmt.format(domainEnd);
|
|
387
|
+
if (!seenLabels.has(endLabel)) {
|
|
388
|
+
extras.push({
|
|
389
|
+
date: domainEnd,
|
|
390
|
+
label: endLabel,
|
|
391
|
+
x: (xScale(domainEnd) ?? 0) + marginLeft
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (extras.length === 0) {
|
|
395
|
+
return ticks;
|
|
396
|
+
}
|
|
397
|
+
return [...ticks, ...extras].sort((a, b) => a.x - b.x);
|
|
398
|
+
}
|
|
399
|
+
function XAxis(props) {
|
|
400
|
+
const { containerRef } = useChartStable();
|
|
401
|
+
const container = useChartPortalContainer(containerRef);
|
|
402
|
+
if (!container) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
return /* @__PURE__ */ jsx(XAxisInner, { ...props, container });
|
|
406
|
+
}
|
|
407
|
+
const XAxisInner = memo(function XAxisInner2({
|
|
408
|
+
numTicks = 5,
|
|
409
|
+
tickerHalfWidth = 50,
|
|
410
|
+
tickMode = "data",
|
|
411
|
+
labels: labelsProp,
|
|
412
|
+
hoverEffect = "auto",
|
|
413
|
+
activeLabelColor = chartCssVars.indicatorColor,
|
|
414
|
+
nearbyLabelColor,
|
|
415
|
+
highlightRadius = 80,
|
|
416
|
+
labelClassName,
|
|
417
|
+
container
|
|
418
|
+
}) {
|
|
419
|
+
const {
|
|
420
|
+
xScale,
|
|
421
|
+
margin,
|
|
422
|
+
data,
|
|
423
|
+
xAccessor,
|
|
424
|
+
dateLabels: contextDateLabels,
|
|
425
|
+
xDomain,
|
|
426
|
+
width
|
|
427
|
+
} = useChartStable();
|
|
428
|
+
const tooltipData = useChartHoverSelector(selectTooltipData);
|
|
429
|
+
const datePillPresent = useDatePillPresent(container);
|
|
430
|
+
const autoEffect = datePillPresent ? "fade" : "highlight";
|
|
431
|
+
const effect = hoverEffect === "auto" ? autoEffect : hoverEffect;
|
|
432
|
+
const nearbyColor = nearbyLabelColor ?? activeLabelColor;
|
|
433
|
+
const dateLabels = labelsProp ?? contextDateLabels;
|
|
434
|
+
const resolvedNumTicks = useMemo(
|
|
435
|
+
() => resolveResponsiveChartLabelCount(numTicks, width, 5),
|
|
436
|
+
[numTicks, width]
|
|
437
|
+
);
|
|
438
|
+
const labelsToShow = useMemo(() => {
|
|
439
|
+
const projectionExtendsScale = tickMode === "data" && domainExtendsPastData(data, xAccessor, xScale);
|
|
440
|
+
if (tickMode === "domain") {
|
|
441
|
+
return buildDomainTicks({
|
|
442
|
+
marginLeft: margin.left,
|
|
443
|
+
numTicks: resolvedNumTicks,
|
|
444
|
+
xScale
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (projectionExtendsScale && xDomain == null) {
|
|
448
|
+
return buildDomainTicks({
|
|
449
|
+
marginLeft: margin.left,
|
|
450
|
+
numTicks: resolvedNumTicks,
|
|
451
|
+
xScale
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const dataTicks = buildDataAlignedTicks({
|
|
455
|
+
data,
|
|
456
|
+
dateLabels,
|
|
457
|
+
marginLeft: margin.left,
|
|
458
|
+
targetTickCount: resolvedNumTicks,
|
|
459
|
+
xAccessor,
|
|
460
|
+
xScale
|
|
461
|
+
});
|
|
462
|
+
if (projectionExtendsScale && xDomain != null) {
|
|
463
|
+
return appendProjectionTailTicks(
|
|
464
|
+
dataTicks,
|
|
465
|
+
data,
|
|
466
|
+
xAccessor,
|
|
467
|
+
xScale,
|
|
468
|
+
margin.left,
|
|
469
|
+
Math.max(1, resolvedNumTicks - dataTicks.length + 1)
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
return dataTicks;
|
|
473
|
+
}, [
|
|
474
|
+
tickMode,
|
|
475
|
+
xDomain,
|
|
476
|
+
data,
|
|
477
|
+
dateLabels,
|
|
478
|
+
xAccessor,
|
|
479
|
+
xScale,
|
|
480
|
+
margin.left,
|
|
481
|
+
resolvedNumTicks
|
|
482
|
+
]);
|
|
483
|
+
const crosshairX = tooltipData && effect !== "none" ? tooltipData.x + margin.left : null;
|
|
484
|
+
const hoveredLabel = tooltipData ? dateLabels[tooltipData.index] ?? shortDateFmt.format(xAccessor(tooltipData.point)) : null;
|
|
485
|
+
return createPortal(
|
|
486
|
+
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0", children: labelsToShow.map((item) => /* @__PURE__ */ jsx(
|
|
487
|
+
XAxisLabel,
|
|
488
|
+
{
|
|
489
|
+
animatePosition: xDomain == null,
|
|
490
|
+
className: labelClassName,
|
|
491
|
+
color: effect === "highlight" ? xAxisLabelColor(
|
|
492
|
+
xAxisLabelHighlight(
|
|
493
|
+
item.label,
|
|
494
|
+
item.x,
|
|
495
|
+
crosshairX,
|
|
496
|
+
hoveredLabel,
|
|
497
|
+
highlightRadius
|
|
498
|
+
),
|
|
499
|
+
activeLabelColor,
|
|
500
|
+
nearbyColor
|
|
501
|
+
) : void 0,
|
|
502
|
+
label: item.label,
|
|
503
|
+
opacity: effect === "fade" ? xAxisLabelOpacity(
|
|
504
|
+
item.label,
|
|
505
|
+
item.x,
|
|
506
|
+
crosshairX,
|
|
507
|
+
hoveredLabel,
|
|
508
|
+
tickerHalfWidth
|
|
509
|
+
) : 1,
|
|
510
|
+
x: item.x
|
|
511
|
+
},
|
|
512
|
+
`${item.date.getTime()}-${item.x}`
|
|
513
|
+
)) }),
|
|
514
|
+
container
|
|
515
|
+
);
|
|
516
|
+
});
|
|
517
|
+
XAxis.displayName = "XAxis";
|
|
518
|
+
var x_axis_default = XAxis;
|
|
519
|
+
export {
|
|
520
|
+
XAxis,
|
|
521
|
+
x_axis_default as default,
|
|
522
|
+
selectEvenlySpacedIndices
|
|
523
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { scaleLinear } from "d3-scale";
|
|
2
|
+
const DEFAULT_Y_AXIS_ID = "left";
|
|
3
|
+
function normalizeYAxisId(id) {
|
|
4
|
+
if (id == null || id === "") {
|
|
5
|
+
return DEFAULT_Y_AXIS_ID;
|
|
6
|
+
}
|
|
7
|
+
return String(id);
|
|
8
|
+
}
|
|
9
|
+
function groupLinesByYAxisId(lines) {
|
|
10
|
+
const groups = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const line of lines) {
|
|
12
|
+
const axisId = normalizeYAxisId(line.yAxisId);
|
|
13
|
+
const bucket = groups.get(axisId) ?? [];
|
|
14
|
+
bucket.push(line);
|
|
15
|
+
groups.set(axisId, bucket);
|
|
16
|
+
}
|
|
17
|
+
return groups;
|
|
18
|
+
}
|
|
19
|
+
function getPrimaryYScale(yScales, fallback) {
|
|
20
|
+
const primary = yScales[DEFAULT_Y_AXIS_ID];
|
|
21
|
+
if (primary) {
|
|
22
|
+
return primary;
|
|
23
|
+
}
|
|
24
|
+
const first = Object.values(yScales)[0];
|
|
25
|
+
return first ?? fallback;
|
|
26
|
+
}
|
|
27
|
+
function buildYScalesForLines({
|
|
28
|
+
lines,
|
|
29
|
+
innerHeight,
|
|
30
|
+
resolveDomain
|
|
31
|
+
}) {
|
|
32
|
+
const groups = groupLinesByYAxisId(lines);
|
|
33
|
+
const scales = {};
|
|
34
|
+
for (const [axisId, axisLines] of groups) {
|
|
35
|
+
const dataKeys = axisLines.map((line) => line.dataKey);
|
|
36
|
+
const domain = resolveDomain(dataKeys);
|
|
37
|
+
scales[axisId] = scaleLinear().domain(domain).nice().range([innerHeight, 0]);
|
|
38
|
+
}
|
|
39
|
+
if (!scales[DEFAULT_Y_AXIS_ID]) {
|
|
40
|
+
scales[DEFAULT_Y_AXIS_ID] = scaleLinear().domain([0, 100]).nice().range([innerHeight, 0]);
|
|
41
|
+
}
|
|
42
|
+
return scales;
|
|
43
|
+
}
|
|
44
|
+
function buildYScalesFromDomains({
|
|
45
|
+
lines,
|
|
46
|
+
innerHeight,
|
|
47
|
+
domainsByAxis
|
|
48
|
+
}) {
|
|
49
|
+
const groups = groupLinesByYAxisId(lines);
|
|
50
|
+
const scales = {};
|
|
51
|
+
for (const [axisId] of groups) {
|
|
52
|
+
const domain = domainsByAxis[axisId] ?? domainsByAxis[DEFAULT_Y_AXIS_ID] ?? [0, 100];
|
|
53
|
+
scales[axisId] = scaleLinear().domain(domain).range([innerHeight, 0]);
|
|
54
|
+
}
|
|
55
|
+
if (!scales[DEFAULT_Y_AXIS_ID]) {
|
|
56
|
+
scales[DEFAULT_Y_AXIS_ID] = scaleLinear().domain(domainsByAxis[DEFAULT_Y_AXIS_ID] ?? [0, 100]).range([innerHeight, 0]);
|
|
57
|
+
}
|
|
58
|
+
return scales;
|
|
59
|
+
}
|
|
60
|
+
function wrapSingleYScale(yScale) {
|
|
61
|
+
return { [DEFAULT_Y_AXIS_ID]: yScale };
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
DEFAULT_Y_AXIS_ID,
|
|
65
|
+
buildYScalesForLines,
|
|
66
|
+
buildYScalesFromDomains,
|
|
67
|
+
getPrimaryYScale,
|
|
68
|
+
groupLinesByYAxisId,
|
|
69
|
+
normalizeYAxisId,
|
|
70
|
+
wrapSingleYScale
|
|
71
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const Y_AXIS_DEFAULT_TICK_COUNT = 5;
|
|
2
|
+
const Y_AXIS_MIN_TICK_COUNT = 1;
|
|
3
|
+
const Y_AXIS_MAX_TICK_COUNT = 10;
|
|
4
|
+
function resolveYAxisTickCount(numTicks) {
|
|
5
|
+
if (numTicks == null || !Number.isFinite(numTicks)) {
|
|
6
|
+
return Y_AXIS_DEFAULT_TICK_COUNT;
|
|
7
|
+
}
|
|
8
|
+
const rounded = Math.round(numTicks);
|
|
9
|
+
if (rounded < Y_AXIS_MIN_TICK_COUNT) {
|
|
10
|
+
return Y_AXIS_MIN_TICK_COUNT;
|
|
11
|
+
}
|
|
12
|
+
if (rounded > Y_AXIS_MAX_TICK_COUNT) {
|
|
13
|
+
return Y_AXIS_MAX_TICK_COUNT;
|
|
14
|
+
}
|
|
15
|
+
return rounded;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
Y_AXIS_DEFAULT_TICK_COUNT,
|
|
19
|
+
Y_AXIS_MAX_TICK_COUNT,
|
|
20
|
+
Y_AXIS_MIN_TICK_COUNT,
|
|
21
|
+
resolveYAxisTickCount
|
|
22
|
+
};
|