@lobehub/charts 6.0.1 → 6.1.0
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/README.md +8 -10
- package/es/AccuracyBarChart/index.d.mts +7 -5
- package/es/AccuracyBarChart/index.mjs +36 -37
- package/es/AccuracyBarChart/index.mjs.map +1 -1
- package/es/AccuracyBarChart/styles.d.mts +1 -4
- package/es/AccuracyBarChart/styles.mjs +6 -7
- package/es/AccuracyBarChart/styles.mjs.map +1 -1
- package/es/AreaChart/index.d.mts +11 -7
- package/es/AreaChart/index.mjs +100 -60
- package/es/AreaChart/index.mjs.map +1 -1
- package/es/AreaChart/styles.d.mts +1 -4
- package/es/AreaChart/styles.mjs +1 -2
- package/es/BarChart/A2uiBarChart.d.mts +56 -0
- package/es/BarChart/A2uiBarChart.mjs +368 -0
- package/es/BarChart/A2uiBarChart.mjs.map +1 -0
- package/es/BarChart/index.d.mts +10 -6
- package/es/BarChart/index.mjs +70 -33
- package/es/BarChart/index.mjs.map +1 -1
- package/es/BarChart/renderShape.d.mts +1 -4
- package/es/BarChart/renderShape.mjs +5 -6
- package/es/BarChart/renderShape.mjs.map +1 -1
- package/es/BarChart/styles.d.mts +1 -4
- package/es/BarChart/styles.mjs +1 -2
- package/es/BarList/index.d.mts +8 -6
- package/es/BarList/index.mjs +13 -14
- package/es/BarList/index.mjs.map +1 -1
- package/es/BarList/styles.d.mts +1 -4
- package/es/BarList/styles.mjs +3 -5
- package/es/BarList/styles.mjs.map +1 -1
- package/es/BenchmarkColumnChart/index.d.mts +8 -6
- package/es/BenchmarkColumnChart/index.mjs +38 -39
- package/es/BenchmarkColumnChart/index.mjs.map +1 -1
- package/es/BenchmarkColumnChart/styles.d.mts +1 -4
- package/es/BenchmarkColumnChart/styles.mjs +6 -8
- package/es/BenchmarkColumnChart/styles.mjs.map +1 -1
- package/es/BenchmarkRankingChart/index.d.mts +8 -6
- package/es/BenchmarkRankingChart/index.mjs +16 -17
- package/es/BenchmarkRankingChart/index.mjs.map +1 -1
- package/es/BenchmarkRankingChart/styles.d.mts +1 -4
- package/es/BenchmarkRankingChart/styles.mjs +25 -27
- package/es/BenchmarkRankingChart/styles.mjs.map +1 -1
- package/es/BenchmarkScatterChart/index.d.mts +7 -5
- package/es/BenchmarkScatterChart/index.mjs +22 -23
- package/es/BenchmarkScatterChart/index.mjs.map +1 -1
- package/es/BenchmarkScatterChart/styles.d.mts +1 -4
- package/es/BenchmarkScatterChart/styles.mjs +3 -2
- package/es/BenchmarkScatterChart/styles.mjs.map +1 -1
- package/es/BenchmarkScatterChart/utils.d.mts +1 -4
- package/es/BenchmarkScatterChart/utils.mjs +4 -5
- package/es/BenchmarkScatterChart/utils.mjs.map +1 -1
- package/es/CandlestickChart/index.d.mts +52 -0
- package/es/CandlestickChart/index.mjs +205 -0
- package/es/CandlestickChart/index.mjs.map +1 -0
- package/es/CandlestickChart/styles.d.mts +5 -0
- package/es/CandlestickChart/styles.mjs +24 -0
- package/es/CandlestickChart/styles.mjs.map +1 -0
- package/es/CandlestickChart/utils.d.mts +17 -0
- package/es/CandlestickChart/utils.mjs +56 -0
- package/es/CandlestickChart/utils.mjs.map +1 -0
- package/es/ChartFrame/index.d.mts +40 -0
- package/es/ChartFrame/index.mjs +18 -0
- package/es/ChartFrame/index.mjs.map +1 -0
- package/es/ComposedChart/index.d.mts +7 -5
- package/es/ComposedChart/index.mjs +37 -38
- package/es/ComposedChart/index.mjs.map +1 -1
- package/es/ComposedChart/styles.d.mts +1 -4
- package/es/ComposedChart/styles.mjs +1 -2
- package/es/ComposedChart/types.d.mts +3 -6
- package/es/DataBars/CategoryBar.d.mts +8 -6
- package/es/DataBars/CategoryBar.mjs +13 -14
- package/es/DataBars/CategoryBar.mjs.map +1 -1
- package/es/DataBars/DeltaBar.d.mts +7 -5
- package/es/DataBars/DeltaBar.mjs +10 -12
- package/es/DataBars/DeltaBar.mjs.map +1 -1
- package/es/DataBars/MarkerBar.d.mts +7 -5
- package/es/DataBars/MarkerBar.mjs +10 -12
- package/es/DataBars/MarkerBar.mjs.map +1 -1
- package/es/DataBars/ProgressBar.d.mts +7 -5
- package/es/DataBars/ProgressBar.mjs +10 -12
- package/es/DataBars/ProgressBar.mjs.map +1 -1
- package/es/DataBars/styles.d.mts +1 -4
- package/es/DataBars/styles.mjs +2 -3
- package/es/DataBars/styles.mjs.map +1 -1
- package/es/DonutChart/A2uiDonutChart.d.mts +35 -0
- package/es/DonutChart/A2uiDonutChart.mjs +189 -0
- package/es/DonutChart/A2uiDonutChart.mjs.map +1 -0
- package/es/DonutChart/DonutChartTooltip.d.mts +2 -5
- package/es/DonutChart/DonutChartTooltip.mjs +3 -4
- package/es/DonutChart/DonutChartTooltip.mjs.map +1 -1
- package/es/DonutChart/a2uiStyles.d.mts +13 -0
- package/es/DonutChart/a2uiStyles.mjs +90 -0
- package/es/DonutChart/a2uiStyles.mjs.map +1 -0
- package/es/DonutChart/index.d.mts +42 -9
- package/es/DonutChart/index.mjs +48 -16
- package/es/DonutChart/index.mjs.map +1 -1
- package/es/DonutChart/inputParser.d.mts +1 -4
- package/es/DonutChart/inputParser.mjs +1 -2
- package/es/DonutChart/inputParser.mjs.map +1 -1
- package/es/DonutChart/renderInactiveShape.d.mts +1 -4
- package/es/DonutChart/renderInactiveShape.mjs +1 -2
- package/es/DonutChart/styles.d.mts +1 -4
- package/es/DonutChart/styles.mjs +1 -2
- package/es/FunnelChart/ArrowRightIcon.d.mts +1 -4
- package/es/FunnelChart/ArrowRightIcon.mjs +1 -2
- package/es/FunnelChart/index.d.mts +7 -5
- package/es/FunnelChart/index.mjs +43 -44
- package/es/FunnelChart/index.mjs.map +1 -1
- package/es/FunnelChart/styles.d.mts +1 -4
- package/es/FunnelChart/styles.mjs +1 -2
- package/es/FunnelChart/types.d.mts +1 -4
- package/es/GaugeChart/index.d.mts +49 -0
- package/es/GaugeChart/index.mjs +77 -0
- package/es/GaugeChart/index.mjs.map +1 -0
- package/es/GaugeChart/styles.d.mts +9 -0
- package/es/GaugeChart/styles.mjs +73 -0
- package/es/GaugeChart/styles.mjs.map +1 -0
- package/es/GaugeChart/utils.d.mts +5 -0
- package/es/GaugeChart/utils.mjs +32 -0
- package/es/GaugeChart/utils.mjs.map +1 -0
- package/es/HeatmapChart/index.d.mts +68 -0
- package/es/HeatmapChart/index.mjs +162 -0
- package/es/HeatmapChart/index.mjs.map +1 -0
- package/es/HeatmapChart/styles.d.mts +4 -0
- package/es/HeatmapChart/styles.mjs +24 -0
- package/es/HeatmapChart/styles.mjs.map +1 -0
- package/es/HeatmapChart/utils.d.mts +18 -0
- package/es/HeatmapChart/utils.mjs +40 -0
- package/es/HeatmapChart/utils.mjs.map +1 -0
- package/es/Heatmaps/Calendar.d.mts +2 -5
- package/es/Heatmaps/Calendar.mjs +8 -9
- package/es/Heatmaps/Calendar.mjs.map +1 -1
- package/es/Heatmaps/ChartLabels.d.mts +2 -5
- package/es/Heatmaps/ChartLabels.mjs +3 -4
- package/es/Heatmaps/ChartLabels.mjs.map +1 -1
- package/es/Heatmaps/Footer.d.mts +1 -4
- package/es/Heatmaps/Footer.mjs +3 -4
- package/es/Heatmaps/index.d.mts +10 -8
- package/es/Heatmaps/index.mjs +10 -11
- package/es/Heatmaps/index.mjs.map +1 -1
- package/es/Heatmaps/styles.d.mts +1 -4
- package/es/Heatmaps/styles.mjs +2 -3
- package/es/Heatmaps/styles.mjs.map +1 -1
- package/es/Legend/LegendItem.d.mts +1 -4
- package/es/Legend/LegendItem.mjs +7 -8
- package/es/Legend/LegendItem.mjs.map +1 -1
- package/es/Legend/ScrollButton.d.mts +1 -4
- package/es/Legend/ScrollButton.mjs +6 -7
- package/es/Legend/ScrollButton.mjs.map +1 -1
- package/es/Legend/index.d.mts +7 -5
- package/es/Legend/index.mjs +13 -18
- package/es/Legend/index.mjs.map +1 -1
- package/es/LineChart/index.d.mts +11 -7
- package/es/LineChart/index.mjs +91 -53
- package/es/LineChart/index.mjs.map +1 -1
- package/es/LineChart/styles.d.mts +1 -4
- package/es/LineChart/styles.mjs +1 -2
- package/es/RadarChart/A2uiRadarChart.d.mts +37 -0
- package/es/RadarChart/A2uiRadarChart.mjs +203 -0
- package/es/RadarChart/A2uiRadarChart.mjs.map +1 -0
- package/es/RadarChart/index.d.mts +11 -7
- package/es/RadarChart/index.mjs +51 -18
- package/es/RadarChart/index.mjs.map +1 -1
- package/es/RadarChart/styles.d.mts +1 -4
- package/es/RadarChart/styles.mjs +1 -2
- package/es/SankeyChart/index.d.mts +73 -0
- package/es/SankeyChart/index.mjs +156 -0
- package/es/SankeyChart/index.mjs.map +1 -0
- package/es/SankeyChart/utils.d.mts +54 -0
- package/es/SankeyChart/utils.mjs +270 -0
- package/es/SankeyChart/utils.mjs.map +1 -0
- package/es/ScatterChart/A2uiScatterChart.d.mts +41 -0
- package/es/ScatterChart/A2uiScatterChart.mjs +259 -0
- package/es/ScatterChart/A2uiScatterChart.mjs.map +1 -0
- package/es/ScatterChart/ScatterChartTooltip.d.mts +2 -5
- package/es/ScatterChart/ScatterChartTooltip.mjs +7 -8
- package/es/ScatterChart/ScatterChartTooltip.mjs.map +1 -1
- package/es/ScatterChart/ScatterChartTooltipRow.d.mts +1 -4
- package/es/ScatterChart/ScatterChartTooltipRow.mjs +3 -4
- package/es/ScatterChart/ScatterChartTooltipRow.mjs.map +1 -1
- package/es/ScatterChart/index.d.mts +15 -9
- package/es/ScatterChart/index.mjs +70 -33
- package/es/ScatterChart/index.mjs.map +1 -1
- package/es/ScatterChart/renderShape.d.mts +1 -4
- package/es/ScatterChart/renderShape.mjs +4 -5
- package/es/ScatterChart/renderShape.mjs.map +1 -1
- package/es/ScatterChart/styles.d.mts +1 -4
- package/es/ScatterChart/styles.mjs +1 -2
- package/es/SparkChart/A2uiSparkChart.d.mts +41 -0
- package/es/SparkChart/A2uiSparkChart.mjs +179 -0
- package/es/SparkChart/A2uiSparkChart.mjs.map +1 -0
- package/es/SparkChart/SparkAreaChart.d.mts +12 -7
- package/es/SparkChart/SparkAreaChart.mjs +47 -22
- package/es/SparkChart/SparkAreaChart.mjs.map +1 -1
- package/es/SparkChart/SparkBarChart.d.mts +11 -6
- package/es/SparkChart/SparkBarChart.mjs +39 -16
- package/es/SparkChart/SparkBarChart.mjs.map +1 -1
- package/es/SparkChart/SparkLineChart.d.mts +12 -7
- package/es/SparkChart/SparkLineChart.mjs +41 -16
- package/es/SparkChart/SparkLineChart.mjs.map +1 -1
- package/es/SparkChart/index.d.mts +2 -1
- package/es/Tracker/TrackerBlock.d.mts +5 -5
- package/es/Tracker/TrackerBlock.mjs +8 -9
- package/es/Tracker/TrackerBlock.mjs.map +1 -1
- package/es/Tracker/index.d.mts +8 -6
- package/es/Tracker/index.mjs +11 -13
- package/es/Tracker/index.mjs.map +1 -1
- package/es/Tracker/styles.d.mts +1 -4
- package/es/Tracker/styles.mjs +1 -2
- package/es/TreemapChart/index.d.mts +64 -0
- package/es/TreemapChart/index.mjs +140 -0
- package/es/TreemapChart/index.mjs.map +1 -0
- package/es/TreemapChart/utils.d.mts +23 -0
- package/es/TreemapChart/utils.mjs +175 -0
- package/es/TreemapChart/utils.mjs.map +1 -0
- package/es/common/BaseAnimationTimingProps.d.mts +1 -4
- package/es/common/BaseChartProps.d.mts +3 -6
- package/es/common/BaseSparkChartProps.d.mts +2 -5
- package/es/common/ChartLegend.d.mts +1 -4
- package/es/common/ChartLegend.mjs +4 -5
- package/es/common/ChartLegend.mjs.map +1 -1
- package/es/common/ChartTooltip/ChartTooltipFrame.d.mts +1 -4
- package/es/common/ChartTooltip/ChartTooltipFrame.mjs +1 -2
- package/es/common/ChartTooltip/ChartTooltipFrame.mjs.map +1 -1
- package/es/common/ChartTooltip/ChartTooltipRow.d.mts +1 -4
- package/es/common/ChartTooltip/ChartTooltipRow.mjs +5 -6
- package/es/common/ChartTooltip/ChartTooltipRow.mjs.map +1 -1
- package/es/common/ChartTooltip/index.d.mts +2 -5
- package/es/common/ChartTooltip/index.mjs +3 -4
- package/es/common/ChartTooltip/index.mjs.map +1 -1
- package/es/common/CustomTooltipProps.d.mts +3 -6
- package/es/common/CustomYAxisTick.d.mts +2 -5
- package/es/common/CustomYAxisTick.mjs +1 -2
- package/es/common/CustomYAxisTick.mjs.map +1 -1
- package/es/common/NoData.d.mts +1 -4
- package/es/common/NoData.mjs +2 -3
- package/es/common/NoData.mjs.map +1 -1
- package/es/common/a2ui/A2uiTrendChart.d.mts +43 -0
- package/es/common/a2ui/A2uiTrendChart.mjs +353 -0
- package/es/common/a2ui/A2uiTrendChart.mjs.map +1 -0
- package/es/common/a2ui/Frame.d.mts +20 -0
- package/es/common/a2ui/Frame.mjs +43 -0
- package/es/common/a2ui/Frame.mjs.map +1 -0
- package/es/common/a2ui/HoverTooltip.d.mts +28 -0
- package/es/common/a2ui/HoverTooltip.mjs +36 -0
- package/es/common/a2ui/HoverTooltip.mjs.map +1 -0
- package/es/common/a2ui/Legend.d.mts +11 -0
- package/es/common/a2ui/Legend.mjs +33 -0
- package/es/common/a2ui/Legend.mjs.map +1 -0
- package/es/common/a2ui/PlacedTooltip.d.mts +22 -0
- package/es/common/a2ui/PlacedTooltip.mjs +58 -0
- package/es/common/a2ui/PlacedTooltip.mjs.map +1 -0
- package/es/common/a2ui/Tooltip.d.mts +13 -0
- package/es/common/a2ui/Tooltip.mjs +33 -0
- package/es/common/a2ui/Tooltip.mjs.map +1 -0
- package/es/common/a2ui/axis.d.mts +38 -0
- package/es/common/a2ui/axis.mjs +48 -0
- package/es/common/a2ui/axis.mjs.map +1 -0
- package/es/common/a2ui/curve.d.mts +20 -0
- package/es/common/a2ui/curve.mjs +58 -0
- package/es/common/a2ui/curve.mjs.map +1 -0
- package/es/common/a2ui/format.d.mts +17 -0
- package/es/common/a2ui/format.mjs +56 -0
- package/es/common/a2ui/format.mjs.map +1 -0
- package/es/common/a2ui/index.d.mts +16 -0
- package/es/common/a2ui/index.mjs +15 -0
- package/es/common/a2ui/scale.d.mts +20 -0
- package/es/common/a2ui/scale.mjs +112 -0
- package/es/common/a2ui/scale.mjs.map +1 -0
- package/es/common/a2ui/styles.d.mts +35 -0
- package/es/common/a2ui/styles.mjs +254 -0
- package/es/common/a2ui/styles.mjs.map +1 -0
- package/es/common/a2ui/tokens.d.mts +20 -0
- package/es/common/a2ui/tokens.mjs +103 -0
- package/es/common/a2ui/tokens.mjs.map +1 -0
- package/es/common/a2ui/types.d.mts +25 -0
- package/es/common/a2ui/types.mjs +0 -0
- package/es/common/a2ui/useA2uiTheme.d.mts +2 -0
- package/es/common/a2ui/useA2uiTheme.mjs +11 -0
- package/es/common/a2ui/useA2uiTheme.mjs.map +1 -0
- package/es/common/a2ui/useElementWidth.d.mts +2 -0
- package/es/common/a2ui/useElementWidth.mjs +31 -0
- package/es/common/a2ui/useElementWidth.mjs.map +1 -0
- package/es/common/benchmark/types.d.mts +2 -5
- package/es/common/benchmark/utils.d.mts +1 -4
- package/es/common/benchmark/utils.mjs +1 -2
- package/es/common/utils.d.mts +1 -4
- package/es/common/utils.mjs +1 -2
- package/es/hooks/useOnWindowResize.d.mts +1 -4
- package/es/hooks/useOnWindowResize.mjs +2 -3
- package/es/hooks/usePrefersReducedMotion.d.mts +1 -4
- package/es/hooks/usePrefersReducedMotion.mjs +2 -3
- package/es/hooks/useThemeColorRange.d.mts +1 -4
- package/es/hooks/useThemeColorRange.mjs +1 -2
- package/es/index.d.mts +20 -9
- package/es/index.mjs +15 -9
- package/es/types/charts.d.mts +1 -4
- package/es/types/charts.mjs +1 -2
- package/es/utils/calendar.d.mts +2 -5
- package/es/utils/calendar.mjs +2 -3
- package/es/utils/getMaxLabelLength.d.mts +1 -4
- package/es/utils/getMaxLabelLength.mjs +1 -2
- package/es/utils/getMaxLabelLength.mjs.map +1 -1
- package/es/utils/index.d.mts +1 -4
- package/es/utils/index.mjs +1 -2
- package/es/utils/index.mjs.map +1 -1
- package/es/utils/theme.d.mts +1 -4
- package/es/utils/theme.mjs +1 -2
- package/package.json +32 -8
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Skeleton } from "@lobehub/ui";
|
|
3
|
+
import { useId, useMemo, useState } from "react";
|
|
4
|
+
import { Area, CartesianGrid, ComposedChart, Line, Tooltip as Tooltip$1, XAxis, YAxis } from "recharts";
|
|
5
|
+
import { A2uiXTick, A2uiYTick, rightMarginFor, yAxisWidthFor } from "./axis.mjs";
|
|
6
|
+
import { curveA2uiMonotone } from "./curve.mjs";
|
|
7
|
+
import { createTickFormatter, createValueFormatter } from "./format.mjs";
|
|
8
|
+
import A2uiFrame from "./Frame.mjs";
|
|
9
|
+
import A2uiPlacedTooltip from "./PlacedTooltip.mjs";
|
|
10
|
+
import { niceScale } from "./scale.mjs";
|
|
11
|
+
import { styles } from "./styles.mjs";
|
|
12
|
+
import { A2UI_GRID, A2UI_PALETTE, a2uiPaletteAt } from "./tokens.mjs";
|
|
13
|
+
import A2uiTooltip from "./Tooltip.mjs";
|
|
14
|
+
import { useElementWidth } from "./useElementWidth.mjs";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
// src/common/a2ui/A2uiTrendChart.tsx
|
|
17
|
+
/** Official plot margins: line charts sit 9px from the top, areas 10px; both keep 22.8px for x ticks. */
|
|
18
|
+
const TOP = {
|
|
19
|
+
area: 10,
|
|
20
|
+
line: 9
|
|
21
|
+
};
|
|
22
|
+
const BOTTOM = 22.8;
|
|
23
|
+
const RIGHT = 4;
|
|
24
|
+
/** scalePoint padding of the official x axis. */
|
|
25
|
+
const POINT_PADDING = {
|
|
26
|
+
area: .02,
|
|
27
|
+
line: .25
|
|
28
|
+
};
|
|
29
|
+
const isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
30
|
+
const A2uiTrendChart = ({ kind, data = [], index, categories = [], colors = A2UI_PALETTE, stack = false, connectNulls = false, curveType, format, currency, unit, valueFormatter, xAxisLabelFormatter, title, subtitle, height, loading, noDataText, showAnimation = false, showGradient = true, showGridLines = true, showLegend = true, showTooltip = true, showXAxis = true, showYAxis = true, minValue, maxValue, customCategories, onValueChange, className, style, ref }) => {
|
|
31
|
+
const uid = useId().replaceAll(":", "");
|
|
32
|
+
const [plotRef, width, fontFamily] = useElementWidth();
|
|
33
|
+
const [focus, setFocus] = useState();
|
|
34
|
+
const plotHeight = typeof height === "number" ? height : 220;
|
|
35
|
+
const names = categories;
|
|
36
|
+
const colorOf = (name) => {
|
|
37
|
+
const i = Math.max(0, names.indexOf(name));
|
|
38
|
+
return a2uiPaletteAt(i, colors);
|
|
39
|
+
};
|
|
40
|
+
const labelOf = (name) => customCategories?.[name] ?? name;
|
|
41
|
+
const single = names.length === 1;
|
|
42
|
+
const stacked = kind === "area" && stack && names.length > 1;
|
|
43
|
+
const curve = curveType ?? curveA2uiMonotone;
|
|
44
|
+
const formatTooltip = useMemo(() => valueFormatter ?? createValueFormatter({
|
|
45
|
+
currency,
|
|
46
|
+
format,
|
|
47
|
+
unit
|
|
48
|
+
}), [
|
|
49
|
+
valueFormatter,
|
|
50
|
+
currency,
|
|
51
|
+
format,
|
|
52
|
+
unit
|
|
53
|
+
]);
|
|
54
|
+
const formatTick = useMemo(() => valueFormatter ?? createTickFormatter({
|
|
55
|
+
currency,
|
|
56
|
+
format,
|
|
57
|
+
unit
|
|
58
|
+
}), [
|
|
59
|
+
valueFormatter,
|
|
60
|
+
currency,
|
|
61
|
+
format,
|
|
62
|
+
unit
|
|
63
|
+
]);
|
|
64
|
+
const { domain, ticks } = useMemo(() => {
|
|
65
|
+
const values = [];
|
|
66
|
+
let nonNegative = true;
|
|
67
|
+
for (const row of data) {
|
|
68
|
+
let total = 0;
|
|
69
|
+
for (const name of names) {
|
|
70
|
+
const v = row?.[name];
|
|
71
|
+
if (!isNum(v)) continue;
|
|
72
|
+
if (v < 0) nonNegative = false;
|
|
73
|
+
total += v;
|
|
74
|
+
if (!stacked) values.push(v);
|
|
75
|
+
}
|
|
76
|
+
if (stacked) values.push(total);
|
|
77
|
+
}
|
|
78
|
+
if (isNum(minValue)) values.push(minValue);
|
|
79
|
+
if (isNum(maxValue)) values.push(maxValue);
|
|
80
|
+
return niceScale(values, { includeZero: kind === "area" || single && nonNegative });
|
|
81
|
+
}, [
|
|
82
|
+
data,
|
|
83
|
+
names,
|
|
84
|
+
stacked,
|
|
85
|
+
kind,
|
|
86
|
+
single,
|
|
87
|
+
minValue,
|
|
88
|
+
maxValue
|
|
89
|
+
]);
|
|
90
|
+
const fillUnderLine = kind === "line" && single && domain[0] >= 0;
|
|
91
|
+
const yLabels = ticks.map((t) => formatTick(t));
|
|
92
|
+
const left = showYAxis ? yAxisWidthFor(yLabels, 0, fontFamily) + 8 : RIGHT;
|
|
93
|
+
const n = data.length;
|
|
94
|
+
const p = POINT_PADDING[kind];
|
|
95
|
+
const lastLabel = n > 0 ? String((xAxisLabelFormatter ?? String)(data[n - 1]?.[index])) : "";
|
|
96
|
+
const right = showXAxis ? rightMarginFor(lastLabel, p * (width - left - RIGHT) / (n - 1 + 2 * p || 1), fontFamily) : RIGHT;
|
|
97
|
+
const plotWidth = Math.max(0, width - left - right);
|
|
98
|
+
const step = n > 1 ? plotWidth / (n - 1 + 2 * p) : plotWidth;
|
|
99
|
+
const xPad = n > 1 ? step * p : plotWidth / 2;
|
|
100
|
+
const top = TOP[kind];
|
|
101
|
+
const bottom = showXAxis ? BOTTOM : 4;
|
|
102
|
+
const legend = showLegend && names.length > 1 ? names.map((name) => ({
|
|
103
|
+
color: colorOf(name),
|
|
104
|
+
label: labelOf(name)
|
|
105
|
+
})) : void 0;
|
|
106
|
+
const empty = !loading && (data.length === 0 || names.length === 0);
|
|
107
|
+
const fadeId = (i) => `a2ui-fade-${uid}-${i}`;
|
|
108
|
+
const renderTooltip = ({ active, payload, label }) => {
|
|
109
|
+
if (!active || !payload?.length) return null;
|
|
110
|
+
const seen = /* @__PURE__ */ new Set();
|
|
111
|
+
const items = payload.filter((p) => {
|
|
112
|
+
const key = String(p.dataKey);
|
|
113
|
+
if (seen.has(key) || !names.includes(key)) return false;
|
|
114
|
+
seen.add(key);
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
|
+
if (stacked) items.reverse();
|
|
118
|
+
else items.sort((a, b) => (isNum(b.value) ? b.value : -1e400) - (isNum(a.value) ? a.value : -1e400));
|
|
119
|
+
const total = items.reduce((s, p) => s + (isNum(p.value) ? p.value : 0), 0);
|
|
120
|
+
if (!focus) return null;
|
|
121
|
+
return /* @__PURE__ */ jsx(A2uiPlacedTooltip, {
|
|
122
|
+
height: plotHeight,
|
|
123
|
+
width,
|
|
124
|
+
x: focus.x,
|
|
125
|
+
y: focus.y,
|
|
126
|
+
children: /* @__PURE__ */ jsx(A2uiTooltip, {
|
|
127
|
+
title: xAxisLabelFormatter ? xAxisLabelFormatter(label) : String(label ?? ""),
|
|
128
|
+
rows: [...items.map((p) => ({
|
|
129
|
+
color: colorOf(String(p.dataKey)),
|
|
130
|
+
label: single && title ? title : labelOf(String(p.dataKey)),
|
|
131
|
+
value: formatTooltip(p.value)
|
|
132
|
+
})), ...stacked ? [{
|
|
133
|
+
active: true,
|
|
134
|
+
label: "Total",
|
|
135
|
+
value: formatTooltip(total)
|
|
136
|
+
}] : []]
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const plotBottom = plotHeight - bottom;
|
|
141
|
+
const yPixel = (v) => top + (1 - (v - domain[0]) / (domain[1] - domain[0] || 1)) * (plotBottom - top);
|
|
142
|
+
const onMouseMove = (state) => {
|
|
143
|
+
const i = state?.activeTooltipIndex;
|
|
144
|
+
const x = state?.activeCoordinate?.x;
|
|
145
|
+
if (!state?.isTooltipActive || typeof i !== "number" || !isNum(x) || !isNum(state.chartY)) {
|
|
146
|
+
setFocus(void 0);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const row = data[i];
|
|
150
|
+
let acc = 0;
|
|
151
|
+
let best;
|
|
152
|
+
for (const name of names) {
|
|
153
|
+
const v = row?.[name];
|
|
154
|
+
if (!isNum(v)) continue;
|
|
155
|
+
acc += v;
|
|
156
|
+
const y = yPixel(stacked ? acc : v);
|
|
157
|
+
if (!best || Math.abs(y - state.chartY) < Math.abs(best.y - state.chartY)) best = {
|
|
158
|
+
name,
|
|
159
|
+
x,
|
|
160
|
+
y
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (best?.name !== focus?.name || best?.x !== focus?.x || best?.y !== focus?.y) setFocus(best);
|
|
164
|
+
};
|
|
165
|
+
const activeDot = (name) => focus?.name === name && {
|
|
166
|
+
fill: "var(--a2-surface)",
|
|
167
|
+
onClick: onValueChange ? (_, payload) => onValueChange({
|
|
168
|
+
categoryClicked: name,
|
|
169
|
+
eventType: "dot",
|
|
170
|
+
...payload?.payload
|
|
171
|
+
}) : void 0,
|
|
172
|
+
r: 4.5,
|
|
173
|
+
stroke: colorOf(name),
|
|
174
|
+
strokeWidth: 2
|
|
175
|
+
};
|
|
176
|
+
return /* @__PURE__ */ jsx(A2uiFrame, {
|
|
177
|
+
className,
|
|
178
|
+
empty,
|
|
179
|
+
emptyText: noDataText,
|
|
180
|
+
legend,
|
|
181
|
+
ref,
|
|
182
|
+
style,
|
|
183
|
+
subtitle,
|
|
184
|
+
title,
|
|
185
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
186
|
+
className: styles.plot,
|
|
187
|
+
ref: plotRef,
|
|
188
|
+
style: { height: plotHeight },
|
|
189
|
+
children: loading ? /* @__PURE__ */ jsx(Skeleton, {
|
|
190
|
+
height: plotHeight,
|
|
191
|
+
width: "100%"
|
|
192
|
+
}) : width > 0 ? /* @__PURE__ */ jsxs(ComposedChart, {
|
|
193
|
+
data,
|
|
194
|
+
height: plotHeight,
|
|
195
|
+
margin: {
|
|
196
|
+
bottom: 0,
|
|
197
|
+
left: 0,
|
|
198
|
+
right,
|
|
199
|
+
top
|
|
200
|
+
},
|
|
201
|
+
width,
|
|
202
|
+
onMouseLeave: () => setFocus(void 0),
|
|
203
|
+
onMouseMove,
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ jsx("defs", { children: names.map((name, i) => /* @__PURE__ */ jsxs("linearGradient", {
|
|
206
|
+
id: fadeId(i),
|
|
207
|
+
x1: "0",
|
|
208
|
+
x2: "0",
|
|
209
|
+
y1: "0",
|
|
210
|
+
y2: "1",
|
|
211
|
+
children: [
|
|
212
|
+
/* @__PURE__ */ jsx("stop", {
|
|
213
|
+
offset: "0",
|
|
214
|
+
stopColor: colorOf(name),
|
|
215
|
+
stopOpacity: .34
|
|
216
|
+
}),
|
|
217
|
+
/* @__PURE__ */ jsx("stop", {
|
|
218
|
+
offset: "0.65",
|
|
219
|
+
stopColor: colorOf(name),
|
|
220
|
+
stopOpacity: .08
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ jsx("stop", {
|
|
223
|
+
offset: "1",
|
|
224
|
+
stopColor: colorOf(name),
|
|
225
|
+
stopOpacity: 0
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
}, name)) }),
|
|
229
|
+
showGridLines && /* @__PURE__ */ jsx(CartesianGrid, {
|
|
230
|
+
...A2UI_GRID,
|
|
231
|
+
horizontal: true,
|
|
232
|
+
vertical: false
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ jsx(XAxis, {
|
|
235
|
+
axisLine: false,
|
|
236
|
+
dataKey: index,
|
|
237
|
+
height: showXAxis ? bottom : 0,
|
|
238
|
+
hide: !showXAxis,
|
|
239
|
+
interval: "preserveStartEnd",
|
|
240
|
+
minTickGap: 6,
|
|
241
|
+
padding: {
|
|
242
|
+
left: xPad,
|
|
243
|
+
right: xPad
|
|
244
|
+
},
|
|
245
|
+
tick: /* @__PURE__ */ jsx(A2uiXTick, { formatter: xAxisLabelFormatter }),
|
|
246
|
+
tickLine: false,
|
|
247
|
+
tickMargin: 0,
|
|
248
|
+
tickSize: 0
|
|
249
|
+
}),
|
|
250
|
+
/* @__PURE__ */ jsx(YAxis, {
|
|
251
|
+
axisLine: false,
|
|
252
|
+
domain,
|
|
253
|
+
hide: !showYAxis,
|
|
254
|
+
interval: 0,
|
|
255
|
+
tick: /* @__PURE__ */ jsx(A2uiYTick, { formatter: formatTick }),
|
|
256
|
+
tickLine: false,
|
|
257
|
+
tickMargin: 8,
|
|
258
|
+
tickSize: 0,
|
|
259
|
+
ticks,
|
|
260
|
+
type: "number",
|
|
261
|
+
width: left
|
|
262
|
+
}),
|
|
263
|
+
showTooltip && /* @__PURE__ */ jsx(Tooltip$1, {
|
|
264
|
+
allowEscapeViewBox: {
|
|
265
|
+
x: true,
|
|
266
|
+
y: true
|
|
267
|
+
},
|
|
268
|
+
content: renderTooltip,
|
|
269
|
+
cursor: {
|
|
270
|
+
stroke: "var(--a2-chart-fg)",
|
|
271
|
+
strokeOpacity: .35,
|
|
272
|
+
strokeWidth: 1
|
|
273
|
+
},
|
|
274
|
+
isAnimationActive: false,
|
|
275
|
+
position: {
|
|
276
|
+
x: 0,
|
|
277
|
+
y: 0
|
|
278
|
+
},
|
|
279
|
+
wrapperStyle: {
|
|
280
|
+
height: 0,
|
|
281
|
+
outline: "none",
|
|
282
|
+
width: 0,
|
|
283
|
+
zIndex: 1
|
|
284
|
+
}
|
|
285
|
+
}),
|
|
286
|
+
kind === "area" && names.map((name, i) => stacked ? /* @__PURE__ */ jsx(Area, {
|
|
287
|
+
activeDot: activeDot(name),
|
|
288
|
+
animationDuration: 900,
|
|
289
|
+
connectNulls,
|
|
290
|
+
dataKey: name,
|
|
291
|
+
fill: colorOf(name),
|
|
292
|
+
fillOpacity: .62,
|
|
293
|
+
isAnimationActive: showAnimation,
|
|
294
|
+
name,
|
|
295
|
+
stackId: "a2ui",
|
|
296
|
+
stroke: "var(--a2-surface)",
|
|
297
|
+
strokeWidth: 1,
|
|
298
|
+
type: curve
|
|
299
|
+
}, name) : /* @__PURE__ */ jsx(Area, {
|
|
300
|
+
activeDot: activeDot(name),
|
|
301
|
+
animationDuration: 900,
|
|
302
|
+
connectNulls,
|
|
303
|
+
dataKey: name,
|
|
304
|
+
fill: showGradient ? `url(#${fadeId(i)})` : colorOf(name),
|
|
305
|
+
fillOpacity: showGradient ? 1 : .2,
|
|
306
|
+
isAnimationActive: showAnimation,
|
|
307
|
+
name,
|
|
308
|
+
stroke: colorOf(name),
|
|
309
|
+
strokeLinecap: "round",
|
|
310
|
+
strokeLinejoin: "round",
|
|
311
|
+
strokeWidth: 1.75,
|
|
312
|
+
type: curve
|
|
313
|
+
}, name)),
|
|
314
|
+
kind === "line" && fillUnderLine && showGradient && names.map((name, i) => /* @__PURE__ */ jsx(Area, {
|
|
315
|
+
activeDot: false,
|
|
316
|
+
connectNulls,
|
|
317
|
+
dataKey: name,
|
|
318
|
+
fill: `url(#${fadeId(i)})`,
|
|
319
|
+
fillOpacity: 1,
|
|
320
|
+
isAnimationActive: showAnimation,
|
|
321
|
+
legendType: "none",
|
|
322
|
+
stroke: "none",
|
|
323
|
+
tooltipType: "none",
|
|
324
|
+
type: curve
|
|
325
|
+
}, `fill-${name}`)),
|
|
326
|
+
kind === "line" && names.map((name) => /* @__PURE__ */ jsx(Line, {
|
|
327
|
+
activeDot: activeDot(name),
|
|
328
|
+
animationDuration: 900,
|
|
329
|
+
connectNulls,
|
|
330
|
+
dataKey: name,
|
|
331
|
+
isAnimationActive: showAnimation,
|
|
332
|
+
name,
|
|
333
|
+
stroke: colorOf(name),
|
|
334
|
+
strokeLinecap: "round",
|
|
335
|
+
strokeLinejoin: "round",
|
|
336
|
+
strokeWidth: 2,
|
|
337
|
+
type: curve,
|
|
338
|
+
dot: n * names.length <= 16 ? {
|
|
339
|
+
fill: colorOf(name),
|
|
340
|
+
r: 2.5,
|
|
341
|
+
stroke: "none",
|
|
342
|
+
strokeWidth: 0
|
|
343
|
+
} : false
|
|
344
|
+
}, name))
|
|
345
|
+
]
|
|
346
|
+
}) : null
|
|
347
|
+
})
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
A2uiTrendChart.displayName = "A2uiTrendChart";
|
|
351
|
+
export { A2uiTrendChart as default };
|
|
352
|
+
|
|
353
|
+
//# sourceMappingURL=A2uiTrendChart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2uiTrendChart.mjs","names":["Tooltip"],"sources":["../../../src/common/a2ui/A2uiTrendChart.tsx"],"sourcesContent":["'use client';\n\nimport { Skeleton } from '@lobehub/ui';\nimport type { CSSProperties, ReactNode, Ref } from 'react';\nimport { useId, useMemo, useState } from 'react';\nimport { Area, CartesianGrid, ComposedChart, Line, Tooltip, XAxis, YAxis } from 'recharts';\n\nimport type { EventProps } from '@/common/BaseChartProps';\nimport type { CurveType, ValueFormatter } from '@/types/charts';\n\nimport { A2uiXTick, A2uiYTick, rightMarginFor, Y_TICK_PADDING, yAxisWidthFor } from './axis';\nimport { curveA2uiMonotone } from './curve';\nimport { type ChartNumberFormat, createTickFormatter, createValueFormatter } from './format';\nimport A2uiFrame from './Frame';\nimport A2uiPlacedTooltip from './PlacedTooltip';\nimport { niceScale } from './scale';\nimport { styles } from './styles';\nimport { A2UI_GRID, A2UI_PALETTE, A2UI_SURFACE, a2uiPaletteAt } from './tokens';\nimport A2uiTooltip from './Tooltip';\nimport { useElementWidth } from './useElementWidth';\n\nexport interface A2uiTrendChartProps {\n categories: string[];\n className?: string;\n colors?: string[];\n connectNulls?: boolean;\n currency?: string;\n curveType?: CurveType;\n customCategories?: Record<string, string>;\n data: any[];\n format?: ChartNumberFormat;\n height?: number | string;\n index: string;\n kind: 'line' | 'area';\n loading?: boolean;\n maxValue?: number;\n minValue?: number;\n noDataText?: ReactNode;\n onValueChange?: (value: EventProps) => void;\n ref?: Ref<HTMLElement>;\n showAnimation?: boolean;\n showGradient?: boolean;\n showGridLines?: boolean;\n showLegend?: boolean;\n showTooltip?: boolean;\n showXAxis?: boolean;\n showYAxis?: boolean;\n stack?: boolean;\n style?: CSSProperties;\n subtitle?: string;\n title?: string;\n unit?: string;\n valueFormatter?: ValueFormatter;\n xAxisLabelFormatter?: (v: any) => string;\n}\n\n/** Official plot margins: line charts sit 9px from the top, areas 10px; both keep 22.8px for x ticks. */\nconst TOP = { area: 10, line: 9 } as const;\nconst BOTTOM = 22.8;\nconst RIGHT = 4;\n/** scalePoint padding of the official x axis. */\nconst POINT_PADDING = { area: 0.02, line: 0.25 } as const;\n\nconst isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\n\n// Adapted from CopilotKit a2ui-playground (MIT): charts.tsx `LineChart` / `AreaChart`.\nconst A2uiTrendChart = ({\n kind,\n data = [],\n index,\n categories = [],\n colors = A2UI_PALETTE,\n stack = false,\n connectNulls = false,\n curveType,\n format,\n currency,\n unit,\n valueFormatter,\n xAxisLabelFormatter,\n title,\n subtitle,\n height,\n loading,\n noDataText,\n showAnimation = false,\n showGradient = true,\n showGridLines = true,\n showLegend = true,\n showTooltip = true,\n showXAxis = true,\n showYAxis = true,\n minValue,\n maxValue,\n customCategories,\n onValueChange,\n className,\n style,\n ref,\n}: A2uiTrendChartProps) => {\n const uid = useId().replaceAll(':', '');\n const [plotRef, width, fontFamily] = useElementWidth();\n const [focus, setFocus] = useState<{ name: string; x: number; y: number } | undefined>();\n const plotHeight = typeof height === 'number' ? height : 220;\n\n const names = categories;\n const colorOf = (name: string) => {\n const i = Math.max(0, names.indexOf(name));\n return a2uiPaletteAt(i, colors);\n };\n const labelOf = (name: string) => customCategories?.[name] ?? name;\n const single = names.length === 1;\n const stacked = kind === 'area' && stack && names.length > 1;\n const curve = curveType ?? curveA2uiMonotone;\n\n const formatTooltip = useMemo(\n () => valueFormatter ?? createValueFormatter({ currency, format, unit }),\n [valueFormatter, currency, format, unit],\n );\n const formatTick = useMemo(\n () => valueFormatter ?? createTickFormatter({ currency, format, unit }),\n [valueFormatter, currency, format, unit],\n );\n\n const { domain, ticks } = useMemo(() => {\n const values: number[] = [];\n let nonNegative = true;\n for (const row of data) {\n let total = 0;\n for (const name of names) {\n const v = row?.[name];\n if (!isNum(v)) continue;\n if (v < 0) nonNegative = false;\n total += v;\n if (!stacked) values.push(v);\n }\n if (stacked) values.push(total);\n }\n if (isNum(minValue)) values.push(minValue);\n if (isNum(maxValue)) values.push(maxValue);\n // An area (or the fill under a lone line) starts at zero, so zero is in the domain.\n const includeZero = kind === 'area' || (single && nonNegative);\n return niceScale(values, { includeZero });\n }, [data, names, stacked, kind, single, minValue, maxValue]);\n\n const fillUnderLine = kind === 'line' && single && domain[0] >= 0;\n\n const yLabels = ticks.map((t) => formatTick(t));\n const left = showYAxis ? yAxisWidthFor(yLabels, 0, fontFamily) + Y_TICK_PADDING : RIGHT;\n const n = data.length;\n const p = POINT_PADDING[kind];\n const lastLabel = n > 0 ? String((xAxisLabelFormatter ?? String)(data[n - 1]?.[index])) : '';\n // Keep the last x label inside the card.\n const right = showXAxis\n ? rightMarginFor(lastLabel, (p * (width - left - RIGHT)) / (n - 1 + 2 * p || 1), fontFamily)\n : RIGHT;\n const plotWidth = Math.max(0, width - left - right);\n const step = n > 1 ? plotWidth / (n - 1 + 2 * p) : plotWidth;\n const xPad = n > 1 ? step * p : plotWidth / 2;\n const top = TOP[kind];\n const bottom = showXAxis ? BOTTOM : 4;\n\n const legend =\n showLegend && names.length > 1\n ? names.map((name) => ({ color: colorOf(name), label: labelOf(name) }))\n : undefined;\n\n const empty = !loading && (data.length === 0 || names.length === 0);\n\n const fadeId = (i: number) => `a2ui-fade-${uid}-${i}`;\n\n const renderTooltip = ({ active, payload, label }: any) => {\n if (!active || !payload?.length) return null;\n const seen = new Set<string>();\n const items = (payload as any[]).filter((p) => {\n const key = String(p.dataKey);\n if (seen.has(key) || !names.includes(key)) return false;\n seen.add(key);\n return true;\n });\n // Rows read top-down like the marks: reversed stack order, otherwise by value.\n if (stacked) items.reverse();\n else\n items.sort(\n (a, b) => (isNum(b.value) ? b.value : -Infinity) - (isNum(a.value) ? a.value : -Infinity),\n );\n const total = items.reduce((s, p) => s + (isNum(p.value) ? p.value : 0), 0);\n if (!focus) return null;\n return (\n <A2uiPlacedTooltip height={plotHeight} width={width} x={focus.x} y={focus.y}>\n <A2uiTooltip\n title={xAxisLabelFormatter ? xAxisLabelFormatter(label) : String(label ?? '')}\n rows={[\n ...items.map((p) => ({\n color: colorOf(String(p.dataKey)),\n label: single && title ? title : labelOf(String(p.dataKey)),\n value: formatTooltip(p.value),\n })),\n ...(stacked ? [{ active: true, label: 'Total', value: formatTooltip(total) }] : []),\n ]}\n />\n </A2uiPlacedTooltip>\n );\n };\n\n // The official chart focuses the series nearest the pointer: one ring, and the tooltip above it.\n const plotBottom = plotHeight - bottom;\n const yPixel = (v: number) =>\n top + (1 - (v - domain[0]) / (domain[1] - domain[0] || 1)) * (plotBottom - top);\n const onMouseMove = (state: any) => {\n const i = state?.activeTooltipIndex;\n const x = state?.activeCoordinate?.x;\n if (!state?.isTooltipActive || typeof i !== 'number' || !isNum(x) || !isNum(state.chartY)) {\n setFocus(undefined);\n return;\n }\n const row = data[i];\n let acc = 0;\n let best: { name: string; x: number; y: number } | undefined;\n for (const name of names) {\n const v = row?.[name];\n if (!isNum(v)) continue;\n acc += v;\n const y = yPixel(stacked ? acc : v);\n if (!best || Math.abs(y - state.chartY) < Math.abs(best.y - state.chartY))\n best = { name, x, y };\n }\n if (best?.name !== focus?.name || best?.x !== focus?.x || best?.y !== focus?.y) setFocus(best);\n };\n\n const activeDot = (name: string) =>\n focus?.name === name && {\n fill: A2UI_SURFACE,\n onClick: onValueChange\n ? (_: any, payload: any) =>\n onValueChange({ categoryClicked: name, eventType: 'dot', ...payload?.payload })\n : undefined,\n r: 4.5,\n stroke: colorOf(name),\n strokeWidth: 2,\n };\n\n return (\n <A2uiFrame\n className={className}\n empty={empty}\n emptyText={noDataText}\n legend={legend}\n ref={ref}\n style={style}\n subtitle={subtitle}\n title={title}\n >\n <div className={styles.plot} ref={plotRef} style={{ height: plotHeight }}>\n {loading ? (\n <Skeleton height={plotHeight} width={'100%'} />\n ) : width > 0 ? (\n <ComposedChart\n data={data}\n height={plotHeight}\n margin={{ bottom: 0, left: 0, right, top }}\n width={width}\n onMouseLeave={() => setFocus(undefined)}\n onMouseMove={onMouseMove}\n >\n <defs>\n {names.map((name, i) => (\n <linearGradient id={fadeId(i)} key={name} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n <stop offset=\"0\" stopColor={colorOf(name)} stopOpacity={0.34} />\n <stop offset=\"0.65\" stopColor={colorOf(name)} stopOpacity={0.08} />\n <stop offset=\"1\" stopColor={colorOf(name)} stopOpacity={0} />\n </linearGradient>\n ))}\n </defs>\n {showGridLines && <CartesianGrid {...A2UI_GRID} horizontal vertical={false} />}\n <XAxis\n axisLine={false}\n dataKey={index}\n height={showXAxis ? bottom : 0}\n hide={!showXAxis}\n interval=\"preserveStartEnd\"\n minTickGap={6}\n padding={{ left: xPad, right: xPad }}\n tick={<A2uiXTick formatter={xAxisLabelFormatter} />}\n tickLine={false}\n tickMargin={0}\n tickSize={0}\n />\n <YAxis\n axisLine={false}\n domain={domain}\n hide={!showYAxis}\n interval={0}\n tick={<A2uiYTick formatter={formatTick} />}\n tickLine={false}\n tickMargin={Y_TICK_PADDING}\n tickSize={0}\n ticks={ticks}\n type=\"number\"\n width={left}\n />\n {showTooltip && (\n <Tooltip\n allowEscapeViewBox={{ x: true, y: true }}\n content={renderTooltip}\n cursor={{ stroke: 'var(--a2-chart-fg)', strokeOpacity: 0.35, strokeWidth: 1 }}\n isAnimationActive={false}\n position={{ x: 0, y: 0 }}\n wrapperStyle={{ height: 0, outline: 'none', width: 0, zIndex: 1 }}\n />\n )}\n {kind === 'area' &&\n names.map((name, i) =>\n stacked ? (\n <Area\n activeDot={activeDot(name)}\n animationDuration={900}\n connectNulls={connectNulls}\n dataKey={name}\n fill={colorOf(name)}\n fillOpacity={0.62}\n isAnimationActive={showAnimation}\n key={name}\n name={name}\n stackId=\"a2ui\"\n stroke={A2UI_SURFACE}\n strokeWidth={1}\n type={curve as any}\n />\n ) : (\n <Area\n activeDot={activeDot(name)}\n animationDuration={900}\n connectNulls={connectNulls}\n dataKey={name}\n fill={showGradient ? `url(#${fadeId(i)})` : colorOf(name)}\n fillOpacity={showGradient ? 1 : 0.2}\n isAnimationActive={showAnimation}\n key={name}\n name={name}\n stroke={colorOf(name)}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={1.75}\n type={curve as any}\n />\n ),\n )}\n {kind === 'line' &&\n fillUnderLine &&\n showGradient &&\n names.map((name, i) => (\n <Area\n activeDot={false}\n connectNulls={connectNulls}\n dataKey={name}\n fill={`url(#${fadeId(i)})`}\n fillOpacity={1}\n isAnimationActive={showAnimation}\n key={`fill-${name}`}\n legendType=\"none\"\n stroke=\"none\"\n tooltipType=\"none\"\n type={curve as any}\n />\n ))}\n {kind === 'line' &&\n names.map((name) => (\n <Line\n activeDot={activeDot(name)}\n animationDuration={900}\n connectNulls={connectNulls}\n dataKey={name}\n isAnimationActive={showAnimation}\n key={name}\n name={name}\n stroke={colorOf(name)}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth={2}\n type={curve as any}\n dot={\n n * names.length <= 16\n ? { fill: colorOf(name), r: 2.5, stroke: 'none', strokeWidth: 0 }\n : false\n }\n />\n ))}\n </ComposedChart>\n ) : null}\n </div>\n </A2uiFrame>\n );\n};\n\nA2uiTrendChart.displayName = 'A2uiTrendChart';\n\nexport default A2uiTrendChart;\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,MAAM,MAAM;CAAE,MAAM;CAAI,MAAM;AAAE;AAChC,MAAM,SAAS;AACf,MAAM,QAAQ;;AAEd,MAAM,gBAAgB;CAAE,MAAM;CAAM,MAAM;AAAK;AAE/C,MAAM,SAAS,MAA4B,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC;AAGrF,MAAM,kBAAkB,EACtB,MACA,OAAO,CAAC,GACR,OACA,aAAa,CAAC,GACd,SAAS,cACT,QAAQ,OACR,eAAe,OACf,WACA,QACA,UACA,MACA,gBACA,qBACA,OACA,UACA,QACA,SACA,YACA,gBAAgB,OAChB,eAAe,MACf,gBAAg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ANM,IAMN,IAED,oBAAC,MAAD;MACE,WAAW,UAAU,IAAI;MACzB,mBAAmB;MACL;MACd,SAAS;MACT,MAAM,eAAe,QAAQ,OAAO,CAAC,EAAE,KAAK,QAAQ,IAAI;MACxD,aAAa,eAAe,IAAI;MAChC,mBAAmB;MAEb;MACN,QAAQ,QAAQ,IAAI;MACpB,eAAc;MACd,gBAAe;MACf,aAAa;MACb,MAAM;KACP,GAPM,IAON,CAEL;KACD,SAAS,UACR,iBACA,gBACA,MAAM,KAAK,MAAM,MACf,oBAAC,MAAD;MACE,WAAW;MACG;MACd,SAAS;MACT,MAAM,QAAQ,OAAO,CAAC,EAAE;MACxB,aAAa;MACb,mBAAmB;MAEnB,YAAW;MACX,QAAO;MACP,aAAY;MACZ,MAAM;KACP,GALM,QAAQ,MAKd,CACF;KACF,SAAS,UACR,MAAM,KAAK,SACT,oBAAC,MAAD;MACE,WAAW,UAAU,IAAI;MACzB,mBAAmB;MACL;MACd,SAAS;MACT,mBAAmB;MAEb;MACN,QAAQ,QAAQ,IAAI;MACpB,eAAc;MACd,gBAAe;MACf,aAAa;MACb,MAAM;MACN,KACE,IAAI,MAAM,UAAU,KAChB;OAAE,MAAM,QAAQ,IAAI;OAAG,GAAG;OAAK,QAAQ;OAAQ,aAAa;MAAE,IAC9D;KAEP,GAZM,IAYN,CACF;IACU;GACb,CAAA,IAAA;EACD,CAAA;CACI,CAAA;AAEf;AAEA,eAAe,cAAc"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode, Ref } from "react";
|
|
2
|
+
import { ChartFrameLegendItem } from "./Legend.mjs";
|
|
3
|
+
export interface A2uiFrameProps {
|
|
4
|
+
aside?: ReactNode;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
empty?: boolean;
|
|
8
|
+
emptyText?: ReactNode;
|
|
9
|
+
footer?: ReactNode;
|
|
10
|
+
legend?: ChartFrameLegendItem[];
|
|
11
|
+
ref?: Ref<HTMLElement>;
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
subtitle?: ReactNode;
|
|
14
|
+
title?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const A2uiEmpty: ({ children }: {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}) => import("react").JSX.Element;
|
|
19
|
+
declare const A2uiFrame: ({ title, subtitle, legend, aside, footer, children, className, style, empty, emptyText, ref }: A2uiFrameProps) => import("react").JSX.Element;
|
|
20
|
+
export { A2uiFrame as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { cx } from "@lobehub/ui";
|
|
2
|
+
import A2uiLegend from "./Legend.mjs";
|
|
3
|
+
import { styles } from "./styles.mjs";
|
|
4
|
+
import { useA2uiThemeClass } from "./useA2uiTheme.mjs";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/common/a2ui/Frame.tsx
|
|
7
|
+
const A2uiEmpty = ({ children = "No data yet" }) => /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: styles.empty,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
const A2uiFrame = ({ title, subtitle, legend, aside, footer, children, className, style, empty, emptyText, ref }) => {
|
|
12
|
+
const themeClass = useA2uiThemeClass();
|
|
13
|
+
const showLegend = !!legend && legend.length > 1;
|
|
14
|
+
const hasHeader = !!(title || subtitle || showLegend || aside);
|
|
15
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
16
|
+
className: cx(themeClass, styles.card, styles.frame, className),
|
|
17
|
+
ref,
|
|
18
|
+
style: {
|
|
19
|
+
margin: 0,
|
|
20
|
+
...style
|
|
21
|
+
},
|
|
22
|
+
children: [
|
|
23
|
+
hasHeader && /* @__PURE__ */ jsxs("figcaption", {
|
|
24
|
+
className: styles.header,
|
|
25
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
26
|
+
className: styles.headerText,
|
|
27
|
+
children: [title ? /* @__PURE__ */ jsx("div", {
|
|
28
|
+
className: styles.title,
|
|
29
|
+
children: title
|
|
30
|
+
}) : null, subtitle ? /* @__PURE__ */ jsx("div", {
|
|
31
|
+
className: styles.subtitle,
|
|
32
|
+
children: subtitle
|
|
33
|
+
}) : null]
|
|
34
|
+
}), aside || (showLegend ? /* @__PURE__ */ jsx(A2uiLegend, { items: legend }) : null)]
|
|
35
|
+
}),
|
|
36
|
+
empty ? /* @__PURE__ */ jsx(A2uiEmpty, { children: emptyText }) : children,
|
|
37
|
+
footer && !empty ? footer : null
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export { A2uiEmpty, A2uiFrame as default };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=Frame.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Frame.mjs","names":[],"sources":["../../../src/common/a2ui/Frame.tsx"],"sourcesContent":["import { cx } from '@lobehub/ui';\nimport type { CSSProperties, ReactNode, Ref } from 'react';\n\nimport A2uiLegend, { type ChartFrameLegendItem } from './Legend';\nimport { styles } from './styles';\nimport { useA2uiThemeClass } from './useA2uiTheme';\n\nexport interface A2uiFrameProps {\n aside?: ReactNode;\n children?: ReactNode;\n className?: string;\n empty?: boolean;\n emptyText?: ReactNode;\n footer?: ReactNode;\n legend?: ChartFrameLegendItem[];\n ref?: Ref<HTMLElement>;\n style?: CSSProperties;\n subtitle?: ReactNode;\n title?: ReactNode;\n}\n\nexport const A2uiEmpty = ({ children = 'No data yet' }: { children?: ReactNode }) => (\n <div className={styles.empty}>{children}</div>\n);\n\n// Adapted from CopilotKit a2ui-playground (MIT): chart-kit.tsx `ChartFrame`.\nconst A2uiFrame = ({\n title,\n subtitle,\n legend,\n aside,\n footer,\n children,\n className,\n style,\n empty,\n emptyText,\n ref,\n}: A2uiFrameProps) => {\n const themeClass = useA2uiThemeClass();\n const showLegend = !!legend && legend.length > 1;\n const hasHeader = !!(title || subtitle || showLegend || aside);\n return (\n <figure\n className={cx(themeClass, styles.card, styles.frame, className)}\n ref={ref}\n style={{ margin: 0, ...style }}\n >\n {hasHeader && (\n <figcaption className={styles.header}>\n <div className={styles.headerText}>\n {title ? <div className={styles.title}>{title}</div> : null}\n {subtitle ? <div className={styles.subtitle}>{subtitle}</div> : null}\n </div>\n {aside || (showLegend ? <A2uiLegend items={legend} /> : null)}\n </figcaption>\n )}\n {empty ? <A2uiEmpty>{emptyText}</A2uiEmpty> : children}\n {footer && !empty ? footer : null}\n </figure>\n );\n};\n\nexport default A2uiFrame;\n"],"mappings":";;;;;;AAqBA,MAAa,aAAa,EAAE,WAAW,oBACrC,oBAAC,OAAD;CAAK,WAAW,OAAO;CAAQ;AAAc,CAAA;AAI/C,MAAM,aAAa,EACjB,OACA,UACA,QACA,OACA,QACA,UACA,WACA,OACA,OACA,WACA,UACoB;CACpB,MAAM,aAAa,kBAAkB;CACrC,MAAM,aAAa,CAAC,CAAC,UAAU,OAAO,SAAS;CAC/C,MAAM,YAAY,CAAC,EAAE,SAAS,YAAY,cAAc;CACxD,OACE,qBAAC,UAAD;EACE,WAAW,GAAG,YAAY,OAAO,MAAM,OAAO,OAAO,SAAS;EACzD;EACL,OAAO;GAAE,QAAQ;GAAG,GAAG;EAAM;EAH/B,UAAA;GAKG,aACC,qBAAC,cAAD;IAAY,WAAW,OAAO;IAA9B,UAAA,CACE,qBAAC,OAAD;KAAK,WAAW,OAAO;KAAvB,UAAA,CACG,QAAQ,oBAAC,OAAD;MAAK,WAAW,OAAO;MAAQ,UAAA;KAAW,CAAA,IAAI,MACtD,WAAW,oBAAC,OAAD;MAAK,WAAW,OAAO;MAAW,UAAA;KAAc,CAAA,IAAI,IAC7D;IACJ,CAAA,GAAA,UAAU,aAAa,oBAAC,YAAD,EAAY,OAAO,OAAS,CAAA,IAAI,KAC9C;;GAEb,QAAQ,oBAAC,WAAD,EAAA,UAAY,UAAqB,CAAA,IAAI;GAC7C,UAAU,CAAC,QAAQ,SAAS;EACvB;;AAEZ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MouseEvent } from "react";
|
|
2
|
+
import { A2uiTooltipProps } from "./Tooltip.mjs";
|
|
3
|
+
export interface A2uiHoverState<T = unknown> {
|
|
4
|
+
datum: T;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
/** Hover state for plain-SVG charts: pointer position inside the plot plus the hovered datum. */
|
|
9
|
+
export declare const useA2uiHover: <T>() => {
|
|
10
|
+
bind: (datum: T) => {
|
|
11
|
+
onMouseLeave: () => void;
|
|
12
|
+
onMouseMove: (e: MouseEvent<SVGElement>) => void;
|
|
13
|
+
};
|
|
14
|
+
clear: () => void;
|
|
15
|
+
hover: A2uiHoverState<T> | undefined;
|
|
16
|
+
setHover: import("react").Dispatch<import("react").SetStateAction<A2uiHoverState<T> | undefined>>;
|
|
17
|
+
};
|
|
18
|
+
export interface A2uiFloatingTooltipProps extends A2uiTooltipProps {
|
|
19
|
+
/** Plot height, used to keep the tooltip inside. */
|
|
20
|
+
height: number;
|
|
21
|
+
/** Plot width, used to keep the tooltip inside. */
|
|
22
|
+
width: number;
|
|
23
|
+
/** Focused point in plot coordinates. */
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
}
|
|
27
|
+
/** The a2ui tooltip placed at a focus point inside a `position: relative` plot. */
|
|
28
|
+
export declare const A2uiFloatingTooltip: ({ x, y, width, height, ...rest }: A2uiFloatingTooltipProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
import A2uiPlacedTooltip from "./PlacedTooltip.mjs";
|
|
3
|
+
import A2uiTooltip from "./Tooltip.mjs";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/common/a2ui/HoverTooltip.tsx
|
|
6
|
+
/** Hover state for plain-SVG charts: pointer position inside the plot plus the hovered datum. */
|
|
7
|
+
const useA2uiHover = () => {
|
|
8
|
+
const [hover, setHover] = useState();
|
|
9
|
+
return {
|
|
10
|
+
bind: useCallback((datum) => ({
|
|
11
|
+
onMouseLeave: () => setHover(void 0),
|
|
12
|
+
onMouseMove: (e) => {
|
|
13
|
+
const rect = (e.currentTarget.ownerSVGElement ?? e.currentTarget).getBoundingClientRect();
|
|
14
|
+
setHover({
|
|
15
|
+
datum,
|
|
16
|
+
x: e.clientX - rect.left,
|
|
17
|
+
y: e.clientY - rect.top
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}), []),
|
|
21
|
+
clear: () => setHover(void 0),
|
|
22
|
+
hover,
|
|
23
|
+
setHover
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** The a2ui tooltip placed at a focus point inside a `position: relative` plot. */
|
|
27
|
+
const A2uiFloatingTooltip = ({ x, y, width, height, ...rest }) => /* @__PURE__ */ jsx(A2uiPlacedTooltip, {
|
|
28
|
+
height,
|
|
29
|
+
width,
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
children: /* @__PURE__ */ jsx(A2uiTooltip, { ...rest })
|
|
33
|
+
});
|
|
34
|
+
export { A2uiFloatingTooltip, useA2uiHover };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=HoverTooltip.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HoverTooltip.mjs","names":[],"sources":["../../../src/common/a2ui/HoverTooltip.tsx"],"sourcesContent":["import type { MouseEvent } from 'react';\nimport { useCallback, useState } from 'react';\n\nimport A2uiPlacedTooltip from './PlacedTooltip';\nimport A2uiTooltip, { type A2uiTooltipProps } from './Tooltip';\n\nexport interface A2uiHoverState<T = unknown> {\n datum: T;\n x: number;\n y: number;\n}\n\n/** Hover state for plain-SVG charts: pointer position inside the plot plus the hovered datum. */\nexport const useA2uiHover = <T,>() => {\n const [hover, setHover] = useState<A2uiHoverState<T> | undefined>();\n const bind = useCallback(\n (datum: T) => ({\n onMouseLeave: () => setHover(undefined),\n onMouseMove: (e: MouseEvent<SVGElement>) => {\n const svg =\n (e.currentTarget as SVGElement).ownerSVGElement ?? (e.currentTarget as SVGSVGElement);\n const rect = svg.getBoundingClientRect();\n setHover({ datum, x: e.clientX - rect.left, y: e.clientY - rect.top });\n },\n }),\n [],\n );\n return { bind, clear: () => setHover(undefined), hover, setHover };\n};\n\nexport interface A2uiFloatingTooltipProps extends A2uiTooltipProps {\n /** Plot height, used to keep the tooltip inside. */\n height: number;\n /** Plot width, used to keep the tooltip inside. */\n width: number;\n /** Focused point in plot coordinates. */\n x: number;\n y: number;\n}\n\n/** The a2ui tooltip placed at a focus point inside a `position: relative` plot. */\nexport const A2uiFloatingTooltip = ({ x, y, width, height, ...rest }: A2uiFloatingTooltipProps) => (\n <A2uiPlacedTooltip height={height} width={width} x={x} y={y}>\n <A2uiTooltip {...rest} />\n </A2uiPlacedTooltip>\n);\n"],"mappings":";;;;;;AAaA,MAAa,qBAAyB;CACpC,MAAM,CAAC,OAAO,YAAY,SAAwC;CAalE,OAAO;EAAE,MAZI,aACV,WAAc;GACb,oBAAoB,SAAS,KAAA,CAAS;GACtC,cAAc,MAA8B;IAG1C,MAAM,QADH,EAAE,cAA6B,mBAAoB,EAAE,cAAA,CACvC,sBAAsB;IACvC,SAAS;KAAE;KAAO,GAAG,EAAE,UAAU,KAAK;KAAM,GAAG,EAAE,UAAU,KAAK;IAAI,CAAC;GACvE;EACF,IACA,CAAC,CAES;EAAG,aAAa,SAAS,KAAA,CAAS;EAAG;EAAO;CAAS;AACnE;;AAaA,MAAa,uBAAuB,EAAE,GAAG,GAAG,OAAO,QAAQ,GAAG,WAC5D,oBAAC,mBAAD;CAA2B;CAAe;CAAU;CAAM;CACxD,UAAA,oBAAC,aAAD,EAAa,GAAI,KAAO,CAAA;AACP,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ChartFrameLegendItem = string | {
|
|
2
|
+
color?: string;
|
|
3
|
+
label: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
};
|
|
6
|
+
export interface A2uiLegendProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
items: ChartFrameLegendItem[];
|
|
9
|
+
}
|
|
10
|
+
declare const A2uiLegend: import("react").NamedExoticComponent<A2uiLegendProps>;
|
|
11
|
+
export { A2uiLegend as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cx } from "@lobehub/ui";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { styles } from "./styles.mjs";
|
|
4
|
+
import { a2uiPaletteAt } from "./tokens.mjs";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/common/a2ui/Legend.tsx
|
|
7
|
+
const A2uiLegend = memo(({ items, className }) => /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: cx(styles.legend, className),
|
|
9
|
+
children: items.map((it, i) => {
|
|
10
|
+
const item = typeof it === "string" ? { label: it } : it;
|
|
11
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
12
|
+
className: styles.legendItem,
|
|
13
|
+
children: [
|
|
14
|
+
/* @__PURE__ */ jsx("span", {
|
|
15
|
+
className: styles.swatch,
|
|
16
|
+
style: { background: item.color ?? a2uiPaletteAt(i) }
|
|
17
|
+
}),
|
|
18
|
+
/* @__PURE__ */ jsx("span", {
|
|
19
|
+
className: styles.legendLabel,
|
|
20
|
+
children: item.label
|
|
21
|
+
}),
|
|
22
|
+
item.value ? /* @__PURE__ */ jsx("span", {
|
|
23
|
+
className: styles.legendValue,
|
|
24
|
+
children: item.value
|
|
25
|
+
}) : null
|
|
26
|
+
]
|
|
27
|
+
}, `${item.label}-${i}`);
|
|
28
|
+
})
|
|
29
|
+
}));
|
|
30
|
+
A2uiLegend.displayName = "A2uiLegend";
|
|
31
|
+
export { A2uiLegend as default };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=Legend.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Legend.mjs","names":[],"sources":["../../../src/common/a2ui/Legend.tsx"],"sourcesContent":["import { cx } from '@lobehub/ui';\nimport { memo } from 'react';\n\nimport { styles } from './styles';\nimport { a2uiPaletteAt } from './tokens';\n\nexport type ChartFrameLegendItem = string | { color?: string; label: string; value?: string };\n\nexport interface A2uiLegendProps {\n className?: string;\n items: ChartFrameLegendItem[];\n}\n\n// Adapted from CopilotKit a2ui-playground (MIT): chart-kit.tsx `Legend`.\nconst A2uiLegend = memo<A2uiLegendProps>(({ items, className }) => (\n <div className={cx(styles.legend, className)}>\n {items.map((it, i) => {\n const item = typeof it === 'string' ? { label: it } : it;\n return (\n <span className={styles.legendItem} key={`${item.label}-${i}`}>\n <span className={styles.swatch} style={{ background: item.color ?? a2uiPaletteAt(i) }} />\n <span className={styles.legendLabel}>{item.label}</span>\n {item.value ? <span className={styles.legendValue}>{item.value}</span> : null}\n </span>\n );\n })}\n </div>\n));\n\nA2uiLegend.displayName = 'A2uiLegend';\n\nexport default A2uiLegend;\n"],"mappings":";;;;;;AAcA,MAAM,aAAa,MAAuB,EAAE,OAAO,gBACjD,oBAAC,OAAD;CAAK,WAAW,GAAG,OAAO,QAAQ,SAAS;CACxC,UAAA,MAAM,KAAK,IAAI,MAAM;EACpB,MAAM,OAAO,OAAO,OAAO,WAAW,EAAE,OAAO,GAAG,IAAI;EACtD,OACE,qBAAC,QAAD;GAAM,WAAW,OAAO;GAAxB,UAAA;IACE,oBAAC,QAAD;KAAM,WAAW,OAAO;KAAQ,OAAO,EAAE,YAAY,KAAK,SAAS,cAAc,CAAC,EAAE;IAAI,CAAA;IACxF,oBAAC,QAAD;KAAM,WAAW,OAAO;KAAc,UAAA,KAAK;IAAY,CAAA;IACtD,KAAK,QAAQ,oBAAC,QAAD;KAAM,WAAW,OAAO;KAAc,UAAA,KAAK;IAAY,CAAA,IAAI;GACrE;EAJmC,GAAA,GAAG,KAAK,MAAM,GAAG,GAIpD;CAEV,CAAC;AACE,CAAA,CACN;AAED,WAAW,cAAc"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export interface A2uiPlacedTooltipProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
/** Plot height, to keep the tooltip inside. */
|
|
5
|
+
height: number;
|
|
6
|
+
/**
|
|
7
|
+
* Preferred side: `top` (then bottom, then the sides), or `side` (right, then left) as for points.
|
|
8
|
+
* @default 'top'
|
|
9
|
+
*/
|
|
10
|
+
prefer?: 'top' | 'side';
|
|
11
|
+
/** Plot width, to keep the tooltip inside. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Focused point, in plot coordinates. */
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Places a tooltip like the official charts: centred above the focused point when it fits, else below
|
|
19
|
+
* it, else to its right (or left); always clamped inside the plot.
|
|
20
|
+
*/
|
|
21
|
+
declare const A2uiPlacedTooltip: ({ x, y, width, height, prefer, children }: A2uiPlacedTooltipProps) => import("react").JSX.Element;
|
|
22
|
+
export { A2uiPlacedTooltip as default };
|