@lobehub/charts 6.0.1 → 6.1.1
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 +26 -28
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparkLineChart.mjs","names":["ReChartsLineChart"],"sources":["../../src/SparkChart/SparkLineChart.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"SparkLineChart.mjs","names":["ReChartsLineChart"],"sources":["../../src/SparkChart/SparkLineChart.tsx"],"sourcesContent":["'use client';\n\nimport { css, cssVar, cx, Flexbox, Skeleton } from '@lobehub/ui';\nimport { Line, LineChart as ReChartsLineChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';\nimport type { AxisDomain } from 'recharts/types/util/types';\n\nimport type { A2uiChartProps } from '@/common/a2ui';\nimport type BaseSparkChartProps from '@/common/BaseSparkChartProps';\nimport NoData from '@/common/NoData';\nimport { constructCategoryColors, getYAxisDomain } from '@/common/utils';\nimport { useThemeColorRange } from '@/hooks/useThemeColorRange';\nimport type { CurveType } from '@/types/charts';\n\nimport A2uiSparkChart, { type A2uiSparkProps } from './A2uiSparkChart';\n\nexport interface SparkLineChartProps\n extends BaseSparkChartProps, Omit<A2uiChartProps, 'subtitle'>, A2uiSparkProps {\n connectNulls?: boolean;\n curveType?: CurveType;\n loading?: boolean;\n}\n\nconst DefaultSparkLineChart = ({\n ref,\n ...props\n}: SparkLineChartProps & { ref?: React.Ref<HTMLDivElement> }) => {\n const themeColorRange = useThemeColorRange();\n const {\n data = [],\n categories = [],\n index,\n colors = themeColorRange,\n animationDuration = 900,\n showAnimation = false,\n curveType = 'linear',\n connectNulls = false,\n noDataText = <div />,\n autoMinValue = false,\n minValue,\n maxValue,\n className,\n width = 112,\n height = 48,\n style,\n loading,\n ...rest\n } = props;\n\n if (loading || !data) return <Skeleton height={height} width={width} />;\n\n const categoryColors = constructCategoryColors(categories, colors);\n const yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);\n\n return (\n <Flexbox\n className={className}\n height={height}\n ref={ref}\n style={{ position: 'relative', ...style }}\n width={width}\n {...rest}\n >\n <ResponsiveContainer>\n {data?.length ? (\n <ReChartsLineChart data={data} margin={{ bottom: 1, left: 1, right: 1, top: 1 }}>\n <YAxis hide domain={yAxisDomain as AxisDomain} />\n <XAxis hide dataKey={index} />\n {categories.map((category) => (\n <Line\n animationDuration={animationDuration}\n connectNulls={connectNulls}\n dataKey={category}\n dot={false}\n isAnimationActive={showAnimation}\n key={category}\n name={category}\n stroke=\"\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeOpacity={1}\n strokeWidth={2}\n type={curveType}\n className={cx(css`\n stroke: ${categoryColors.get(category) ?? cssVar.colorPrimary};\n `)}\n />\n ))}\n </ReChartsLineChart>\n ) : (\n <NoData noDataText={noDataText} />\n )}\n </ResponsiveContainer>\n </Flexbox>\n );\n};\n\nconst SparkLineChart = ({\n variant = 'default',\n format,\n currency = 'USD',\n unit,\n label,\n value,\n delta,\n tone,\n ref,\n ...props\n}: SparkLineChartProps & { ref?: React.Ref<HTMLDivElement> }) => {\n if (variant !== 'a2ui') return <DefaultSparkLineChart ref={ref} {...props} />;\n return (\n <A2uiSparkChart\n categories={props.categories}\n className={props.className}\n connectNulls={props.connectNulls}\n currency={currency}\n curveType={props.curveType}\n data={props.data}\n delta={delta}\n format={format}\n index={props.index}\n kind=\"line\"\n label={label}\n loading={props.loading}\n ref={ref}\n showAnimation={props.showAnimation}\n style={props.style}\n tone={tone}\n unit={unit}\n value={value}\n />\n );\n};\n\nSparkLineChart.displayName = 'SparkLineChart';\n\nexport default SparkLineChart;\n"],"mappings":";;;;;;;;;AAsBA,MAAM,yBAAyB,EAC7B,KACA,GAAG,YAC4D;CAC/D,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,EACJ,OAAO,CAAC,GACR,aAAa,CAAC,GACd,OACA,SAAS,iBACT,oBAAoB,KACpB,gBAAgB,OAChB,YAAY,UACZ,eAAe,OACf,aAAa,oBAAC,OAAD,CAAM,CAAA,GACnB,eAAe,OACf,UACA,UACA,WACA,QAAQ,KACR,SAAS,IACT,OACA,SACA,GAAG,SACD;CAEJ,IAAI,WA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rB,OAAO,MAAM;EACP;EACA;EACC;CACR,CAAA;AAEL;AAEA,eAAe,cAAc"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { A2uiSparkProps, SparkTone } from "./A2uiSparkChart.mjs";
|
|
1
2
|
import SparkAreaChart, { SparkAreaChartProps } from "./SparkAreaChart.mjs";
|
|
2
3
|
import SparkBarChart, { SparkBarChartProps } from "./SparkBarChart.mjs";
|
|
3
4
|
import SparkLineChart, { SparkLineChartProps } from "./SparkLineChart.mjs";
|
|
4
|
-
export { SparkAreaChart, type SparkAreaChartProps, SparkBarChart, type SparkBarChartProps, SparkLineChart, type SparkLineChartProps };
|
|
5
|
+
export { type A2uiSparkProps, SparkAreaChart, type SparkAreaChartProps, SparkBarChart, type SparkBarChartProps, SparkLineChart, type SparkLineChartProps, type SparkTone };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { FlexboxProps } from "@lobehub/ui";
|
|
1
2
|
import { ReactNode } from "react";
|
|
2
|
-
//#region src/Tracker/TrackerBlock.d.ts
|
|
3
3
|
export interface TrackerBlockProps {
|
|
4
4
|
color?: 'success' | 'warning' | 'error' | string;
|
|
5
5
|
key?: string | number;
|
|
6
6
|
tooltip?: ReactNode;
|
|
7
7
|
}
|
|
8
|
-
declare const TrackerBlock:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
declare const TrackerBlock: ({ ref, color, tooltip, width, style, ...rest }: TrackerBlockProps & FlexboxProps & {
|
|
9
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
11
|
+
export { TrackerBlock as default };
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Flexbox, Tooltip, createStaticStyles, cssVar } from "@lobehub/ui";
|
|
3
|
-
import {
|
|
3
|
+
import { useMemo } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
5
|
+
// src/Tracker/TrackerBlock.tsx
|
|
6
6
|
const styles = createStaticStyles(({ css }) => ({ block: css`
|
|
7
7
|
background: ${cssVar.colorFill};
|
|
8
8
|
|
|
9
9
|
&:first-child {
|
|
10
|
-
border-
|
|
11
|
-
border-
|
|
10
|
+
border-start-start-radius: ${cssVar.borderRadiusSM};
|
|
11
|
+
border-end-start-radius: ${cssVar.borderRadiusSM};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
&:last-child {
|
|
15
|
-
border-
|
|
16
|
-
border-
|
|
15
|
+
border-start-end-radius: ${cssVar.borderRadiusSM};
|
|
16
|
+
border-end-end-radius: ${cssVar.borderRadiusSM};
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
&:hover {
|
|
20
20
|
opacity: 0.5;
|
|
21
21
|
}
|
|
22
22
|
` }));
|
|
23
|
-
const TrackerBlock =
|
|
23
|
+
const TrackerBlock = ({ ref, color, tooltip, width, style, ...rest }) => {
|
|
24
24
|
const blockColor = useMemo(() => {
|
|
25
25
|
switch (color) {
|
|
26
26
|
case "success": return cssVar.colorSuccess;
|
|
@@ -43,8 +43,7 @@ const TrackerBlock = forwardRef(({ color, tooltip, width, style, ...rest }, ref)
|
|
|
43
43
|
...rest
|
|
44
44
|
})
|
|
45
45
|
});
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
46
|
+
};
|
|
48
47
|
export { TrackerBlock as default };
|
|
49
48
|
|
|
50
49
|
//# sourceMappingURL=TrackerBlock.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrackerBlock.mjs","names":[],"sources":["../../src/Tracker/TrackerBlock.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"TrackerBlock.mjs","names":[],"sources":["../../src/Tracker/TrackerBlock.tsx"],"sourcesContent":["'use client';\n\nimport type { FlexboxProps } from '@lobehub/ui';\nimport { createStaticStyles, cssVar, Flexbox, Tooltip } from '@lobehub/ui';\nimport type { ReactNode } from 'react';\nimport { useMemo } from 'react';\n\nconst styles = createStaticStyles(({ css }) => ({\n block: css`\n background: ${cssVar.colorFill};\n\n &:first-child {\n border-start-start-radius: ${cssVar.borderRadiusSM};\n border-end-start-radius: ${cssVar.borderRadiusSM};\n }\n\n &:last-child {\n border-start-end-radius: ${cssVar.borderRadiusSM};\n border-end-end-radius: ${cssVar.borderRadiusSM};\n }\n\n &:hover {\n opacity: 0.5;\n }\n `,\n}));\n\nexport interface TrackerBlockProps {\n color?: 'success' | 'warning' | 'error' | string;\n key?: string | number;\n tooltip?: ReactNode;\n}\n\nconst TrackerBlock = ({\n ref,\n color,\n tooltip,\n width,\n style,\n ...rest\n}: TrackerBlockProps & FlexboxProps & { ref?: React.Ref<HTMLDivElement> }) => {\n const blockColor = useMemo(() => {\n switch (color) {\n case 'success': {\n return cssVar.colorSuccess;\n }\n case 'warning': {\n return cssVar.colorWarning;\n }\n case 'error': {\n return cssVar.colorError;\n }\n default: {\n return color;\n }\n }\n }, [color]);\n\n return (\n <Tooltip title={tooltip}>\n <Flexbox\n className={styles.block}\n height={'100%'}\n ref={ref}\n style={{ background: blockColor, ...style }}\n width={width || '100%'}\n {...rest}\n />\n </Tooltip>\n );\n};\n\nexport default TrackerBlock;\n"],"mappings":";;;;;AAOA,MAAM,SAAS,oBAAoB,EAAE,WAAW,EAC9C,OAAO,GAAG;kBACM,OAAO,UAAU;;;mCAGA,OAAO,eAAe;iCACxB,OAAO,eAAe;;;;iCAItB,OAAO,eAAe;+BACxB,OAAO,eAAe;;;;;;IAOrD,EAAE;AAQF,MAAM,gBAAgB,EACpB,KACA,OACA,SACA,OACA,OACA,GAAG,WACyE;CAC5E,MAAM,aAAa,cAAc;EAC/B,QAAQ,OAAR;GACE,KAAK,WACH,OAAO,OAAO;GAEhB,KAAK,WACH,OAAO,OAAO;GAEhB,KAAK,SACH,OAAO,OAAO;GAEhB,SACE,OAAO;EAEX;CACF,GAAG,CAAC,KAAK,CAAC;CAEV,OACE,oBAAC,SAAD;EAAS,OAAO;EACd,UAAA,oBAAC,SAAD;GACE,WAAW,OAAO;GAClB,QAAQ;GACH;GACL,OAAO;IAAE,YAAY;IAAY,GAAG;GAAM;GAC1C,OAAO,SAAS;GAChB,GAAI;EACL,CAAA;CACM,CAAA;AAEb"}
|
package/es/Tracker/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { TrackerBlockProps } from "./TrackerBlock.mjs";
|
|
2
1
|
import { FlexboxProps } from "@lobehub/ui";
|
|
3
2
|
import { ReactNode } from "react";
|
|
4
|
-
|
|
3
|
+
import { TrackerBlockProps } from "./TrackerBlock.mjs";
|
|
5
4
|
interface DataItem extends TrackerBlockProps {
|
|
6
5
|
[key: string]: any;
|
|
7
6
|
}
|
|
@@ -15,7 +14,10 @@ export interface TrackerProps extends FlexboxProps {
|
|
|
15
14
|
onValueChange?: (payload: DataItem) => void;
|
|
16
15
|
rightLabel?: ReactNode;
|
|
17
16
|
}
|
|
18
|
-
declare const Tracker:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
declare const Tracker: {
|
|
18
|
+
({ ref, ...props }: TrackerProps & {
|
|
19
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
};
|
|
23
|
+
export { Tracker as default };
|
package/es/Tracker/index.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import TrackerBlock from "./TrackerBlock.mjs";
|
|
3
|
-
import { styles } from "./styles.mjs";
|
|
4
2
|
import { Flexbox, TooltipGroup, cx } from "@lobehub/ui";
|
|
5
|
-
import {
|
|
3
|
+
import { styles } from "./styles.mjs";
|
|
4
|
+
import TrackerBlock from "./TrackerBlock.mjs";
|
|
6
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
const Tracker =
|
|
6
|
+
// src/Tracker/index.tsx
|
|
7
|
+
const Tracker = ({ ref, ...props }) => {
|
|
9
8
|
const { data = [], className, height, width = "fit-content", blockWidth = 12, blockHeight = 40, blockGap = 4, customTooltip, onValueChange, leftLabel, rightLabel, style, ...rest } = props;
|
|
10
9
|
const content = /* @__PURE__ */ jsx(TooltipGroup, { children: data.map((item, idx) => /* @__PURE__ */ jsx(TrackerBlock, {
|
|
11
10
|
color: item.color,
|
|
12
11
|
height: blockHeight,
|
|
13
|
-
onClick: () => onValueChange?.(item),
|
|
14
|
-
style: { cursor: onValueChange ? "pointer" : "default" },
|
|
15
12
|
tooltip: customTooltip ? customTooltip(item) : item.tooltip,
|
|
16
|
-
width: blockWidth
|
|
13
|
+
width: blockWidth,
|
|
14
|
+
style: { cursor: onValueChange ? "pointer" : "default" },
|
|
15
|
+
onClick: () => onValueChange?.(item)
|
|
17
16
|
}, item.key ?? idx)) });
|
|
18
17
|
if (leftLabel || rightLabel) return /* @__PURE__ */ jsxs(Flexbox, {
|
|
19
18
|
className,
|
|
@@ -27,8 +26,8 @@ const Tracker = forwardRef((props, ref) => {
|
|
|
27
26
|
width,
|
|
28
27
|
...rest,
|
|
29
28
|
children: [/* @__PURE__ */ jsxs(Flexbox, {
|
|
30
|
-
align: "center",
|
|
31
29
|
horizontal: true,
|
|
30
|
+
align: "center",
|
|
32
31
|
justify: "space-between",
|
|
33
32
|
width: "100%",
|
|
34
33
|
children: [/* @__PURE__ */ jsx("div", {
|
|
@@ -40,28 +39,27 @@ const Tracker = forwardRef((props, ref) => {
|
|
|
40
39
|
children: rightLabel
|
|
41
40
|
})]
|
|
42
41
|
}), /* @__PURE__ */ jsx(Flexbox, {
|
|
42
|
+
horizontal: true,
|
|
43
43
|
align: "center",
|
|
44
44
|
gap: blockGap,
|
|
45
45
|
height: blockHeight,
|
|
46
|
-
horizontal: true,
|
|
47
46
|
width: "100%",
|
|
48
47
|
children: content
|
|
49
48
|
})]
|
|
50
49
|
});
|
|
51
50
|
return /* @__PURE__ */ jsx(Flexbox, {
|
|
51
|
+
horizontal: true,
|
|
52
52
|
align: "center",
|
|
53
53
|
className,
|
|
54
54
|
gap: blockGap,
|
|
55
55
|
height: height || blockHeight,
|
|
56
|
-
horizontal: true,
|
|
57
56
|
ref,
|
|
58
57
|
width,
|
|
59
58
|
...rest,
|
|
60
59
|
children: content
|
|
61
60
|
});
|
|
62
|
-
}
|
|
61
|
+
};
|
|
63
62
|
Tracker.displayName = "Tracker";
|
|
64
|
-
//#endregion
|
|
65
63
|
export { Tracker as default };
|
|
66
64
|
|
|
67
65
|
//# sourceMappingURL=index.mjs.map
|
package/es/Tracker/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Tracker/index.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Tracker/index.tsx"],"sourcesContent":["'use client';\n\nimport type { FlexboxProps } from '@lobehub/ui';\nimport { cx, Flexbox, TooltipGroup } from '@lobehub/ui';\nimport type { ReactNode } from 'react';\n\nimport { styles } from './styles';\nimport type { TrackerBlockProps } from './TrackerBlock';\nimport TrackerBlock from './TrackerBlock';\n\ninterface DataItem extends TrackerBlockProps {\n [key: string]: any;\n}\n\nexport interface TrackerProps extends FlexboxProps {\n blockGap?: number | string;\n blockHeight?: number | string;\n blockWidth?: number | string;\n customTooltip?: (payload: DataItem) => ReactNode;\n data: DataItem[];\n leftLabel?: ReactNode;\n onValueChange?: (payload: DataItem) => void;\n rightLabel?: ReactNode;\n}\n\nconst Tracker = ({ ref, ...props }: TrackerProps & { ref?: React.Ref<HTMLDivElement> }) => {\n const {\n data = [],\n className,\n height,\n width = 'fit-content',\n blockWidth = 12,\n blockHeight = 40,\n blockGap = 4,\n customTooltip,\n onValueChange,\n leftLabel,\n rightLabel,\n style,\n ...rest\n } = props;\n\n const content = (\n <TooltipGroup>\n {data.map((item, idx) => (\n <TrackerBlock\n color={item.color}\n height={blockHeight}\n key={item.key ?? idx}\n tooltip={customTooltip ? customTooltip(item) : item.tooltip}\n width={blockWidth}\n style={{\n cursor: onValueChange ? 'pointer' : 'default',\n }}\n onClick={() => onValueChange?.(item)}\n />\n ))}\n </TooltipGroup>\n );\n\n if (leftLabel || rightLabel) {\n return (\n <Flexbox\n className={className}\n gap={8}\n height={height}\n ref={ref}\n style={{ position: 'relative', ...style }}\n width={width}\n {...rest}\n >\n <Flexbox horizontal align={'center'} justify={'space-between'} width={'100%'}>\n <div className={cx(styles.strongLabel, styles.emphasis)}>{leftLabel}</div>\n <div className={cx(styles.label, styles.emphasis)} style={{ textAlign: 'right' }}>\n {rightLabel}\n </div>\n </Flexbox>\n <Flexbox horizontal align={'center'} gap={blockGap} height={blockHeight} width={'100%'}>\n {content}\n </Flexbox>\n </Flexbox>\n );\n }\n\n return (\n <Flexbox\n horizontal\n align={'center'}\n className={className}\n gap={blockGap}\n height={height || blockHeight}\n ref={ref}\n width={width}\n {...rest}\n >\n {content}\n </Flexbox>\n );\n};\n\nTracker.displayName = 'Tracker';\n\nexport default Tracker;\n"],"mappings":";;;;;;AAyBA,MAAM,WAAW,EAAE,KAAK,GAAG,YAAgE;CACzF,MAAM,EACJ,OAAO,CAAC,GACR,WACA,QACA,QAAQ,eACR,aAAa,IACb,cAAc,IACd,WAAW,GACX,eACA,eACA,WACA,YACA,OACA,GAAG,SACD;CAEJ,MAAM,UACJ,oBAAC,cAAD,EAAA,UACG,KAAK,KAAK,MAAM,QACf,oBAAC,cAAD;EACE,OAAO,KAAK;EACZ,QAAQ;EAER,SAAS,gBAAgB,cAAc,IAAI,IAAI,KAAK;EACpD,OAAO;EACP,OAAO,EACL,QAAQ,gBAAgB,YAAY,UACtC;EACA,eAAe,gBAAgB,IAAI;CACpC,GAPM,KAAK,OAAO,GAOlB,CACF,EACW,CAAA;CAGhB,IAAI,aAAa,YACf,OACE,qBAAC,SAAD;EACa;EACX,KAAK;EACG;EACH;EACL,OAAO;GAAE,UAAU;GAAY,GAAG;EAAM;EACjC;EACP,GAAI;EAPN,UAAA,CASE,qBAAC,SAAD;GAAS,YAAA;GAAW,OAAO;GAAU,SAAS;GAAiB,OAAO;GAAtE,UAAA,CACE,oBAAC,OAAD;IAAK,WAAW,GAAG,OAAO,aAAa,OAAO,QAAQ;IAAI,UAAA;GAAe,CAAA,GACzE,oBAAC,OAAD;IAAK,WAAW,GAAG,OAAO,OAAO,OAAO,QAAQ;IAAG,OAAO,EAAE,WAAW,QAAQ;IAC5E,UAAA;GACE,CAAA,CACE;EACT,CAAA,GAAA,oBAAC,SAAD;GAAS,YAAA;GAAW,OAAO;GAAU,KAAK;GAAU,QAAQ;GAAa,OAAO;GAC7E,UAAA;EACM,CAAA,CACF;;CAIb,OACE,oBAAC,SAAD;EACE,YAAA;EACA,OAAO;EACI;EACX,KAAK;EACL,QAAQ,UAAU;EACb;EACE;EACP,GAAI;EAEH,UAAA;CACM,CAAA;AAEb;AAEA,QAAQ,cAAc"}
|
package/es/Tracker/styles.d.mts
CHANGED
package/es/Tracker/styles.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStaticStyles } from "@lobehub/ui";
|
|
2
|
-
|
|
2
|
+
// src/Tracker/styles.ts
|
|
3
3
|
const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
4
4
|
emphasis: css`
|
|
5
5
|
overflow: hidden;
|
|
@@ -18,7 +18,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
18
18
|
fill: ${cssVar.colorTextSecondary};
|
|
19
19
|
`
|
|
20
20
|
}));
|
|
21
|
-
//#endregion
|
|
22
21
|
export { styles };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=styles.mjs.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode, Ref } from "react";
|
|
2
|
+
import "../common/a2ui/index.mjs";
|
|
3
|
+
import { ChartNumberFormat } from "../common/a2ui/format.mjs";
|
|
4
|
+
import { ValueFormatter } from "../types/charts.mjs";
|
|
5
|
+
export interface TreemapChartProps {
|
|
6
|
+
/**
|
|
7
|
+
* Key of the value.
|
|
8
|
+
* @default 'value'
|
|
9
|
+
*/
|
|
10
|
+
category?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Palette, one colour per group (or per item when ungrouped). Defaults to the A2UI palette. */
|
|
13
|
+
colors?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* ISO 4217 code used when `format` is `currency`.
|
|
16
|
+
* @default 'USD'
|
|
17
|
+
*/
|
|
18
|
+
currency?: string;
|
|
19
|
+
/** Rows of `{ name, value, group? }`; keys are set by `index`, `category` and `group`. */
|
|
20
|
+
data: any[];
|
|
21
|
+
/** How values read in the tooltip. `percent` expects 0-100. */
|
|
22
|
+
format?: ChartNumberFormat;
|
|
23
|
+
/**
|
|
24
|
+
* Key of the group a row belongs to. Groups share a colour and are laid out together.
|
|
25
|
+
* @default 'group'
|
|
26
|
+
*/
|
|
27
|
+
group?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Plot height in px.
|
|
30
|
+
* @default 260
|
|
31
|
+
*/
|
|
32
|
+
height?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Key of the item name.
|
|
35
|
+
* @default 'name'
|
|
36
|
+
*/
|
|
37
|
+
index?: string;
|
|
38
|
+
loading?: boolean;
|
|
39
|
+
noDataText?: ReactNode;
|
|
40
|
+
ref?: Ref<HTMLElement>;
|
|
41
|
+
/**
|
|
42
|
+
* Show the groups in the header when there are several.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
showLegend?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
showTooltip?: boolean;
|
|
50
|
+
style?: CSSProperties;
|
|
51
|
+
/** Secondary line under the title. */
|
|
52
|
+
subtitle?: string;
|
|
53
|
+
/** Card title. */
|
|
54
|
+
title?: string;
|
|
55
|
+
/** Unit appended to values. */
|
|
56
|
+
unit?: string;
|
|
57
|
+
/** Formats values; wins over `format`. */
|
|
58
|
+
valueFormatter?: ValueFormatter;
|
|
59
|
+
}
|
|
60
|
+
declare const TreemapChart: {
|
|
61
|
+
({ data, index, category, group, colors, format, currency, unit, valueFormatter, title, subtitle, height, loading, noDataText, showLegend, showTooltip, className, style, ref }: TreemapChartProps): import("react").JSX.Element;
|
|
62
|
+
displayName: string;
|
|
63
|
+
};
|
|
64
|
+
export { TreemapChart as default };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Skeleton } from "@lobehub/ui";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { A2UI_PALETTE, a2uiPaletteAt } from "../common/a2ui/tokens.mjs";
|
|
5
|
+
import { A2uiFloatingTooltip, useA2uiHover } from "../common/a2ui/HoverTooltip.mjs";
|
|
6
|
+
import A2uiFrame from "../common/a2ui/Frame.mjs";
|
|
7
|
+
import { styles } from "../common/a2ui/styles.mjs";
|
|
8
|
+
import { createValueFormatter } from "../common/a2ui/format.mjs";
|
|
9
|
+
import { measureTextWidth } from "../common/a2ui/scale.mjs";
|
|
10
|
+
import { useElementWidth } from "../common/a2ui/useElementWidth.mjs";
|
|
11
|
+
import { layoutTreemap } from "./utils.mjs";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
// src/TreemapChart/index.tsx
|
|
14
|
+
const isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
15
|
+
const LABEL_SIZE = 11.5;
|
|
16
|
+
const TreemapChart = ({ data = [], index = "name", category = "value", group = "group", colors = A2UI_PALETTE, format, currency = "USD", unit, valueFormatter, title, subtitle, height = 260, loading, noDataText, showLegend = true, showTooltip = true, className, style, ref }) => {
|
|
17
|
+
const [plotRef, width, fontFamily] = useElementWidth();
|
|
18
|
+
const { hover, bind } = useA2uiHover();
|
|
19
|
+
const leaves = useMemo(() => {
|
|
20
|
+
const clean = (s) => s.replaceAll("|", "/").trim() || "Other";
|
|
21
|
+
return (data ?? []).filter((d) => typeof d?.[index] === "string" && isNum(d?.[category]) && d[category] > 0).map((d) => ({
|
|
22
|
+
group: typeof d[group] === "string" && d[group] ? clean(d[group]) : "",
|
|
23
|
+
name: clean(d[index]),
|
|
24
|
+
value: d[category]
|
|
25
|
+
}));
|
|
26
|
+
}, [
|
|
27
|
+
data,
|
|
28
|
+
index,
|
|
29
|
+
category,
|
|
30
|
+
group
|
|
31
|
+
]);
|
|
32
|
+
const { cells, keys, total } = useMemo(() => layoutTreemap(leaves, Math.max(0, width), height), [
|
|
33
|
+
leaves,
|
|
34
|
+
width,
|
|
35
|
+
height
|
|
36
|
+
]);
|
|
37
|
+
const colorOf = (key) => a2uiPaletteAt(Math.max(0, keys.indexOf(key)), colors);
|
|
38
|
+
const formatValue = useMemo(() => valueFormatter ?? createValueFormatter({
|
|
39
|
+
currency,
|
|
40
|
+
format,
|
|
41
|
+
unit
|
|
42
|
+
}), [
|
|
43
|
+
valueFormatter,
|
|
44
|
+
currency,
|
|
45
|
+
format,
|
|
46
|
+
unit
|
|
47
|
+
]);
|
|
48
|
+
const hasGroups = leaves.some((l) => l.group);
|
|
49
|
+
const font = `600 ${LABEL_SIZE}px ${fontFamily ?? "sans-serif"}`;
|
|
50
|
+
const fits = (cell) => {
|
|
51
|
+
const w = measureTextWidth(cell.name, font, LABEL_SIZE);
|
|
52
|
+
return cell.x1 - cell.x0 - 12 >= w && cell.y1 - cell.y0 - 12 >= LABEL_SIZE * 1.2;
|
|
53
|
+
};
|
|
54
|
+
const hovered = hover?.datum;
|
|
55
|
+
return /* @__PURE__ */ jsx(A2uiFrame, {
|
|
56
|
+
className,
|
|
57
|
+
empty: !loading && leaves.length === 0,
|
|
58
|
+
emptyText: noDataText,
|
|
59
|
+
ref,
|
|
60
|
+
style,
|
|
61
|
+
subtitle,
|
|
62
|
+
title,
|
|
63
|
+
legend: showLegend && hasGroups ? keys.map((k) => ({
|
|
64
|
+
color: colorOf(k),
|
|
65
|
+
label: k
|
|
66
|
+
})) : void 0,
|
|
67
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
68
|
+
className: styles.plot,
|
|
69
|
+
ref: plotRef,
|
|
70
|
+
style: { height },
|
|
71
|
+
children: [loading ? /* @__PURE__ */ jsx(Skeleton, {
|
|
72
|
+
height,
|
|
73
|
+
width: "100%"
|
|
74
|
+
}) : width > 0 ? /* @__PURE__ */ jsx("svg", {
|
|
75
|
+
"aria-label": title ?? "Treemap",
|
|
76
|
+
height,
|
|
77
|
+
role: "img",
|
|
78
|
+
style: { display: "block" },
|
|
79
|
+
width,
|
|
80
|
+
children: cells.map((cell) => {
|
|
81
|
+
const key = cell.group || cell.name;
|
|
82
|
+
const active = hovered === cell;
|
|
83
|
+
const w = cell.x1 - cell.x0;
|
|
84
|
+
const h = cell.y1 - cell.y0;
|
|
85
|
+
if (w <= 0 || h <= 0) return null;
|
|
86
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
87
|
+
...showTooltip ? bind(cell) : {},
|
|
88
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
89
|
+
fill: colorOf(key),
|
|
90
|
+
fillOpacity: active ? 1 : .88,
|
|
91
|
+
height: h,
|
|
92
|
+
rx: Math.min(6, w / 2, h / 2),
|
|
93
|
+
stroke: active ? "var(--a2-chart-focus)" : void 0,
|
|
94
|
+
strokeWidth: active ? 1.5 : void 0,
|
|
95
|
+
width: w,
|
|
96
|
+
x: cell.x0,
|
|
97
|
+
y: cell.y0
|
|
98
|
+
}), fits(cell) ? /* @__PURE__ */ jsx("text", {
|
|
99
|
+
dominantBaseline: "middle",
|
|
100
|
+
fill: "var(--a2-treemap-ink)",
|
|
101
|
+
fontSize: LABEL_SIZE,
|
|
102
|
+
fontWeight: 600,
|
|
103
|
+
pointerEvents: "none",
|
|
104
|
+
textAnchor: "middle",
|
|
105
|
+
x: cell.x0 + w / 2,
|
|
106
|
+
y: cell.y0 + h / 2,
|
|
107
|
+
children: cell.name
|
|
108
|
+
}) : null]
|
|
109
|
+
}, `${cell.group}\u0000${cell.name}`);
|
|
110
|
+
})
|
|
111
|
+
}) : null, showTooltip && hovered ? /* @__PURE__ */ jsx(A2uiFloatingTooltip, {
|
|
112
|
+
height,
|
|
113
|
+
title: hovered.name,
|
|
114
|
+
width,
|
|
115
|
+
x: (hovered.x0 + hovered.x1) / 2,
|
|
116
|
+
y: (hovered.y0 + hovered.y1) / 2,
|
|
117
|
+
rows: [
|
|
118
|
+
...hovered.group ? [{
|
|
119
|
+
color: colorOf(hovered.group),
|
|
120
|
+
label: "Group",
|
|
121
|
+
value: hovered.group
|
|
122
|
+
}] : [],
|
|
123
|
+
{
|
|
124
|
+
color: hovered.group ? void 0 : colorOf(hovered.name),
|
|
125
|
+
label: "Value",
|
|
126
|
+
value: formatValue(hovered.value)
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
label: "Share",
|
|
130
|
+
value: `${(hovered.value / (total || 1) * 100).toFixed(1)}%`
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}) : null]
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
TreemapChart.displayName = "TreemapChart";
|
|
138
|
+
export { TreemapChart as default };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["a2uiStyles"],"sources":["../../src/TreemapChart/index.tsx"],"sourcesContent":["'use client';\n\nimport { Skeleton } from '@lobehub/ui';\nimport type { CSSProperties, ReactNode, Ref } from 'react';\nimport { useMemo } from 'react';\n\nimport {\n A2UI_PALETTE,\n A2uiFloatingTooltip,\n A2uiFrame,\n a2uiPaletteAt,\n a2uiStyles,\n type ChartNumberFormat,\n createValueFormatter,\n measureTextWidth,\n useA2uiHover,\n useElementWidth,\n} from '@/common/a2ui';\nimport type { ValueFormatter } from '@/types/charts';\n\nimport { layoutTreemap, type TreemapCell } from './utils';\n\nexport interface TreemapChartProps {\n /**\n * Key of the value.\n * @default 'value'\n */\n category?: string;\n className?: string;\n /** Palette, one colour per group (or per item when ungrouped). Defaults to the A2UI palette. */\n colors?: string[];\n /**\n * ISO 4217 code used when `format` is `currency`.\n * @default 'USD'\n */\n currency?: string;\n /** Rows of `{ name, value, group? }`; keys are set by `index`, `category` and `group`. */\n data: any[];\n /** How values read in the tooltip. `percent` expects 0-100. */\n format?: ChartNumberFormat;\n /**\n * Key of the group a row belongs to. Groups share a colour and are laid out together.\n * @default 'group'\n */\n group?: string;\n /**\n * Plot height in px.\n * @default 260\n */\n height?: number;\n /**\n * Key of the item name.\n * @default 'name'\n */\n index?: string;\n loading?: boolean;\n noDataText?: ReactNode;\n ref?: Ref<HTMLElement>;\n /**\n * Show the groups in the header when there are several.\n * @default true\n */\n showLegend?: boolean;\n /**\n * @default true\n */\n showTooltip?: boolean;\n style?: CSSProperties;\n /** Secondary line under the title. */\n subtitle?: string;\n /** Card title. */\n title?: string;\n /** Unit appended to values. */\n unit?: string;\n /** Formats values; wins over `format`. */\n valueFormatter?: ValueFormatter;\n}\n\nconst isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\nconst LABEL_SIZE = 11.5;\nconst LABEL_PADDING = 6;\n\n// Adapted from CopilotKit a2ui-playground (MIT): charts.tsx `Treemap`.\nconst TreemapChart = ({\n data = [],\n index = 'name',\n category = 'value',\n group = 'group',\n colors = A2UI_PALETTE,\n format,\n currency = 'USD',\n unit,\n valueFormatter,\n title,\n subtitle,\n height = 260,\n loading,\n noDataText,\n showLegend = true,\n showTooltip = true,\n className,\n style,\n ref,\n}: TreemapChartProps) => {\n const [plotRef, width, fontFamily] = useElementWidth();\n const { hover, bind } = useA2uiHover<TreemapCell>();\n const leaves = useMemo(() => {\n const clean = (s: string) => s.replaceAll('|', '/').trim() || 'Other';\n return (data ?? [])\n .filter((d) => typeof d?.[index] === 'string' && isNum(d?.[category]) && d[category] > 0)\n .map((d) => ({\n group: typeof d[group] === 'string' && d[group] ? clean(d[group]) : '',\n name: clean(d[index]),\n value: d[category] as number,\n }));\n }, [data, index, category, group]);\n const { cells, keys, total } = useMemo(\n () => layoutTreemap(leaves, Math.max(0, width), height),\n [leaves, width, height],\n );\n const colorOf = (key: string) => a2uiPaletteAt(Math.max(0, keys.indexOf(key)), colors);\n const formatValue = useMemo(\n () => valueFormatter ?? createValueFormatter({ currency, format, unit }),\n [valueFormatter, currency, format, unit],\n );\n const hasGroups = leaves.some((l) => l.group);\n const font = `600 ${LABEL_SIZE}px ${fontFamily ?? 'sans-serif'}`;\n\n const fits = (cell: TreemapCell) => {\n const w = measureTextWidth(cell.name, font, LABEL_SIZE);\n return (\n cell.x1 - cell.x0 - LABEL_PADDING * 2 >= w &&\n cell.y1 - cell.y0 - LABEL_PADDING * 2 >= LABEL_SIZE * 1.2\n );\n };\n\n const hovered = hover?.datum;\n\n return (\n <A2uiFrame\n className={className}\n empty={!loading && leaves.length === 0}\n emptyText={noDataText}\n ref={ref}\n style={style}\n subtitle={subtitle}\n title={title}\n legend={\n showLegend && hasGroups ? keys.map((k) => ({ color: colorOf(k), label: k })) : undefined\n }\n >\n <div className={a2uiStyles.plot} ref={plotRef} style={{ height }}>\n {loading ? (\n <Skeleton height={height} width={'100%'} />\n ) : width > 0 ? (\n <svg\n aria-label={title ?? 'Treemap'}\n height={height}\n role=\"img\"\n style={{ display: 'block' }}\n width={width}\n >\n {cells.map((cell) => {\n const key = cell.group || cell.name;\n const active = hovered === cell;\n const w = cell.x1 - cell.x0;\n const h = cell.y1 - cell.y0;\n if (w <= 0 || h <= 0) return null;\n return (\n <g key={`${cell.group}\\u0000${cell.name}`} {...(showTooltip ? bind(cell) : {})}>\n <rect\n fill={colorOf(key)}\n fillOpacity={active ? 1 : 0.88}\n height={h}\n rx={Math.min(6, w / 2, h / 2)}\n stroke={active ? 'var(--a2-chart-focus)' : undefined}\n strokeWidth={active ? 1.5 : undefined}\n width={w}\n x={cell.x0}\n y={cell.y0}\n />\n {fits(cell) ? (\n <text\n dominantBaseline=\"middle\"\n fill=\"var(--a2-treemap-ink)\"\n fontSize={LABEL_SIZE}\n fontWeight={600}\n pointerEvents=\"none\"\n textAnchor=\"middle\"\n x={cell.x0 + w / 2}\n y={cell.y0 + h / 2}\n >\n {cell.name}\n </text>\n ) : null}\n </g>\n );\n })}\n </svg>\n ) : null}\n {showTooltip && hovered ? (\n <A2uiFloatingTooltip\n height={height}\n title={hovered.name}\n width={width}\n x={(hovered.x0 + hovered.x1) / 2}\n y={(hovered.y0 + hovered.y1) / 2}\n rows={[\n ...(hovered.group\n ? [{ color: colorOf(hovered.group), label: 'Group', value: hovered.group }]\n : []),\n {\n color: hovered.group ? undefined : colorOf(hovered.name),\n label: 'Value',\n value: formatValue(hovered.value),\n },\n { label: 'Share', value: `${((hovered.value / (total || 1)) * 100).toFixed(1)}%` },\n ]}\n />\n ) : null}\n </div>\n </A2uiFrame>\n );\n};\n\nTreemapChart.displayName = 'TreemapChart';\n\nexport default TreemapChart;\n"],"mappings":";;;;;;;;;;;;;AA8EA,MAAM,SAAS,MAA4B,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC;AACrF,MAAM,aAAa;AAInB,MAAM,gBAAgB,EACpB,OAAO,CAAC,GACR,QAAQ,QACR,WAAW,SACX,QAAQ,SACR,SAAS,cACT,QACA,WAAW,OACX,MACA,gBACA,OACA,UACA,SAAS,KACT,SACA,YACA,aAAa,MACb,cAAc,MACd,WACA,OACA,UACuB;CACvB,MAAM,CAAC,SAAS,OAAO,cAAc,gBAAgB;CACrD,MAAM,EAAE,OAAO,SAAS,aAA0B;CAClD,MAAM,SAAS,cAAc;EAC3B,MAAM,SAAS,MAAc,EAAE,WAAW,KAAK,GAAG,CAAC,CAAC,KAAK,KAAK;EAC9D,QAAQ,QAAQ,CAAC,EAAA,CACd,QAAQ,MAAM,OAAO,IAAI,WAAW,YAAY,MAAM,IAAI,SAAS,KAAK,EAAE,YAAY,CAAC,CAAC,CACxF,KAAK,OAAO;GACX,OAAO,OAAO,EAAE,WAAW,YAA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AAS,KAAM,IAAA,CAAK,QAAQ,CAAC,EAAE;KAAG;IACnF;GACD,CAAA,IACC,IACD;;CACI,CAAA;AAEf;AAEA,aAAa,cAAc"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface TreemapLeafInput {
|
|
2
|
+
group: string;
|
|
3
|
+
name: string;
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface TreemapCell extends TreemapLeafInput {
|
|
7
|
+
x0: number;
|
|
8
|
+
x1: number;
|
|
9
|
+
y0: number;
|
|
10
|
+
y1: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Lays out leaves (optionally grouped one level deep) in a `width` x `height` box. Children are sorted by
|
|
14
|
+
* value, largest first, at every level. Returns the leaf cells and the colour keys in input order.
|
|
15
|
+
*/
|
|
16
|
+
export declare const layoutTreemap: (leaves: TreemapLeafInput[], width: number, height: number, { paddingInner, paddingOuter }?: {
|
|
17
|
+
paddingInner?: number | undefined;
|
|
18
|
+
paddingOuter?: number | undefined;
|
|
19
|
+
}) => {
|
|
20
|
+
cells: TreemapCell[];
|
|
21
|
+
keys: string[];
|
|
22
|
+
total: number;
|
|
23
|
+
};
|