@flux-ui/statistics 3.0.0-next.67 → 3.0.0-next.69
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 +1 -1
- package/dist/component/FluxStatisticsAreaChart.vue.d.ts +11 -4
- package/dist/component/FluxStatisticsBarChart.vue.d.ts +11 -4
- package/dist/component/FluxStatisticsBase.vue.d.ts +1 -0
- package/dist/component/FluxStatisticsBoxPlotChart.vue.d.ts +15 -0
- package/dist/component/FluxStatisticsBubbleChart.vue.d.ts +14 -0
- package/dist/component/FluxStatisticsCandlestickChart.vue.d.ts +15 -0
- package/dist/component/FluxStatisticsChart.vue.d.ts +7 -5
- package/dist/component/FluxStatisticsChartPane.vue.d.ts +1 -0
- package/dist/component/FluxStatisticsComparison.vue.d.ts +16 -0
- package/dist/component/FluxStatisticsDonutChart.vue.d.ts +8 -4
- package/dist/component/FluxStatisticsEmpty.vue.d.ts +19 -0
- package/dist/component/FluxStatisticsHeatmapChart.vue.d.ts +15 -0
- package/dist/component/FluxStatisticsLegendItem.vue.d.ts +1 -0
- package/dist/component/FluxStatisticsLegendScope.vue.d.ts +13 -0
- package/dist/component/FluxStatisticsLineChart.vue.d.ts +11 -4
- package/dist/component/FluxStatisticsMixedChart.vue.d.ts +17 -0
- package/dist/component/FluxStatisticsPercentageBar.vue.d.ts +8 -0
- package/dist/component/FluxStatisticsPieChart.vue.d.ts +8 -4
- package/dist/component/FluxStatisticsPolarAreaChart.vue.d.ts +14 -0
- package/dist/component/FluxStatisticsRadarChart.vue.d.ts +12 -0
- package/dist/component/FluxStatisticsRadialBar.vue.d.ts +11 -0
- package/dist/component/FluxStatisticsScatterChart.vue.d.ts +14 -0
- package/dist/component/FluxStatisticsSparkline.vue.d.ts +13 -0
- package/dist/component/FluxStatisticsTreemapChart.vue.d.ts +11 -0
- package/dist/component/index.d.ts +15 -0
- package/dist/composable/index.d.ts +12 -0
- package/dist/composable/useChartBaseSetup.d.ts +8 -0
- package/dist/composable/useChartHoverSync.d.ts +9 -0
- package/dist/composable/useChartLegend.d.ts +14 -0
- package/dist/composable/useChartSeriesSetup.d.ts +23 -0
- package/dist/composable/useChartSlicesSetup.d.ts +14 -0
- package/dist/composable/useECharts.d.ts +9 -0
- package/dist/echarts.d.ts +1 -0
- package/dist/index.css +262 -34
- package/dist/index.d.ts +5 -2
- package/dist/index.js +9176 -6895
- package/dist/index.js.map +1 -1
- package/dist/util/colors.d.ts +4 -0
- package/dist/util/icons.d.ts +2 -0
- package/dist/util/index.d.ts +6 -0
- package/dist/util/options/buildBaseOptions.d.ts +2 -0
- package/dist/util/options/buildCartesianBaseOptions.d.ts +13 -0
- package/dist/util/options/buildCircularBaseOptions.d.ts +2 -0
- package/dist/util/options/cartesian/buildAreaChartOptions.d.ts +17 -0
- package/dist/util/options/cartesian/buildBarChartOptions.d.ts +17 -0
- package/dist/util/options/cartesian/buildBoxPlotChartOptions.d.ts +16 -0
- package/dist/util/options/cartesian/buildBubbleChartOptions.d.ts +15 -0
- package/dist/util/options/cartesian/buildCandlestickChartOptions.d.ts +17 -0
- package/dist/util/options/cartesian/buildHeatmapChartOptions.d.ts +15 -0
- package/dist/util/options/cartesian/buildLineChartOptions.d.ts +17 -0
- package/dist/util/options/cartesian/buildMixedChartOptions.d.ts +17 -0
- package/dist/util/options/cartesian/buildScatterChartOptions.d.ts +15 -0
- package/dist/util/options/cartesian/index.d.ts +18 -0
- package/dist/util/options/circular/buildDonutChartOptions.d.ts +15 -0
- package/dist/util/options/circular/buildGaugeChartOptions.d.ts +14 -0
- package/dist/util/options/circular/buildPieChartOptions.d.ts +15 -0
- package/dist/util/options/circular/buildPolarAreaChartOptions.d.ts +15 -0
- package/dist/util/options/circular/buildRadarChartOptions.d.ts +13 -0
- package/dist/util/options/circular/buildTreemapChartOptions.d.ts +12 -0
- package/dist/util/options/circular/index.d.ts +12 -0
- package/dist/util/options/index.d.ts +6 -0
- package/dist/util/series/chartColors.d.ts +3 -0
- package/dist/util/series/converters.d.ts +17 -0
- package/dist/util/series/defaults.d.ts +15 -0
- package/dist/util/series/index.d.ts +4 -0
- package/dist/util/series/labels.d.ts +5 -0
- package/dist/util/sparkline.d.ts +7 -0
- package/dist/util/tooltips/buildBoxPlotTooltip.d.ts +22 -0
- package/dist/util/tooltips/buildCartesianTooltip.d.ts +10 -0
- package/dist/util/tooltips/buildGaugeTooltip.d.ts +14 -0
- package/dist/util/tooltips/buildHeatmapTooltip.d.ts +17 -0
- package/dist/util/tooltips/buildRadarTooltip.d.ts +11 -0
- package/dist/util/tooltips/buildSharedItemTooltip.d.ts +10 -0
- package/dist/util/tooltips/buildTreemapTooltip.d.ts +12 -0
- package/dist/util/tooltips/index.d.ts +15 -0
- package/dist/util/tooltips/render.d.ts +4 -0
- package/dist/util/tooltips/types.d.ts +24 -0
- package/package.json +14 -15
- package/src/component/FluxStatisticsAreaChart.vue +36 -43
- package/src/component/FluxStatisticsBarChart.vue +36 -35
- package/src/component/FluxStatisticsBase.vue +14 -1
- package/src/component/FluxStatisticsBoxPlotChart.vue +49 -0
- package/src/component/FluxStatisticsBubbleChart.vue +46 -0
- package/src/component/FluxStatisticsCandlestickChart.vue +50 -0
- package/src/component/FluxStatisticsChart.vue +19 -169
- package/src/component/FluxStatisticsChartPane.vue +22 -11
- package/src/component/FluxStatisticsComparison.vue +113 -0
- package/src/component/FluxStatisticsDonutChart.vue +31 -19
- package/src/component/FluxStatisticsEmpty.vue +44 -0
- package/src/component/FluxStatisticsHeatmapChart.vue +47 -0
- package/src/component/FluxStatisticsLegend.vue +33 -1
- package/src/component/FluxStatisticsLegendItem.vue +3 -1
- package/src/component/FluxStatisticsLegendScope.vue +16 -0
- package/src/component/FluxStatisticsLineChart.vue +36 -43
- package/src/component/FluxStatisticsMixedChart.vue +52 -0
- package/src/component/FluxStatisticsPercentageBar.vue +90 -0
- package/src/component/FluxStatisticsPieChart.vue +31 -19
- package/src/component/FluxStatisticsPolarAreaChart.vue +44 -0
- package/src/component/FluxStatisticsRadarChart.vue +40 -0
- package/src/component/FluxStatisticsRadialBar.vue +39 -0
- package/src/component/FluxStatisticsScatterChart.vue +46 -0
- package/src/component/FluxStatisticsSparkline.vue +67 -0
- package/src/component/FluxStatisticsTreemapChart.vue +35 -0
- package/src/component/index.ts +15 -0
- package/src/composable/index.ts +12 -0
- package/src/composable/useChartBaseSetup.ts +16 -0
- package/src/composable/useChartHoverSync.ts +92 -0
- package/src/composable/useChartLegend.ts +23 -0
- package/src/composable/useChartSeriesSetup.ts +75 -0
- package/src/composable/useChartSlicesSetup.ts +58 -0
- package/src/composable/useECharts.ts +55 -0
- package/src/css/Base.module.scss +28 -1
- package/src/css/Chart.module.scss +59 -30
- package/src/css/ChartPane.module.scss +20 -12
- package/src/css/Comparison.module.scss +52 -0
- package/src/css/Empty.module.scss +39 -0
- package/src/css/Grid.module.scss +1 -0
- package/src/css/Legend.module.scss +22 -4
- package/src/css/Meter.module.scss +1 -0
- package/src/css/Metric.module.scss +6 -0
- package/src/css/PercentageBar.module.scss +36 -0
- package/src/css/Sparkline.module.scss +13 -0
- package/src/echarts.ts +47 -0
- package/src/index.ts +7 -3
- package/src/util/colors.ts +86 -0
- package/src/util/icons.ts +20 -0
- package/src/util/index.ts +6 -0
- package/src/util/options/buildBaseOptions.ts +31 -0
- package/src/util/options/buildCartesianBaseOptions.ts +67 -0
- package/src/util/options/buildCircularBaseOptions.ts +10 -0
- package/src/util/options/cartesian/buildAreaChartOptions.ts +44 -0
- package/src/util/options/cartesian/buildBarChartOptions.ts +44 -0
- package/src/util/options/cartesian/buildBoxPlotChartOptions.ts +63 -0
- package/src/util/options/cartesian/buildBubbleChartOptions.ts +48 -0
- package/src/util/options/cartesian/buildCandlestickChartOptions.ts +77 -0
- package/src/util/options/cartesian/buildHeatmapChartOptions.ts +72 -0
- package/src/util/options/cartesian/buildLineChartOptions.ts +44 -0
- package/src/util/options/cartesian/buildMixedChartOptions.ts +44 -0
- package/src/util/options/cartesian/buildScatterChartOptions.ts +48 -0
- package/src/util/options/cartesian/index.ts +18 -0
- package/src/util/options/circular/buildDonutChartOptions.ts +31 -0
- package/src/util/options/circular/buildGaugeChartOptions.ts +45 -0
- package/src/util/options/circular/buildPieChartOptions.ts +31 -0
- package/src/util/options/circular/buildPolarAreaChartOptions.ts +31 -0
- package/src/util/options/circular/buildRadarChartOptions.ts +52 -0
- package/src/util/options/circular/buildTreemapChartOptions.ts +28 -0
- package/src/util/options/circular/index.ts +12 -0
- package/src/util/options/index.ts +6 -0
- package/src/util/series/chartColors.ts +20 -0
- package/src/util/series/converters.ts +318 -0
- package/src/util/series/defaults.ts +210 -0
- package/src/util/series/index.ts +4 -0
- package/src/util/series/labels.ts +30 -0
- package/src/util/sparkline.ts +67 -0
- package/src/util/tooltips/buildBoxPlotTooltip.ts +66 -0
- package/src/util/tooltips/buildCartesianTooltip.ts +44 -0
- package/src/util/tooltips/buildGaugeTooltip.ts +49 -0
- package/src/util/tooltips/buildHeatmapTooltip.ts +57 -0
- package/src/util/tooltips/buildRadarTooltip.ts +53 -0
- package/src/util/tooltips/buildSharedItemTooltip.ts +38 -0
- package/src/util/tooltips/buildTreemapTooltip.ts +49 -0
- package/src/util/tooltips/index.ts +15 -0
- package/src/util/tooltips/render.ts +66 -0
- package/src/util/tooltips/types.ts +29 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FluxStatisticsChartPieSlice } from '@flux-ui/types';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
import type { EChartsOption } from '~flux/statistics/composable';
|
|
4
|
+
import { toPieSeries } from '../../series';
|
|
5
|
+
import type { ChartTooltipValueFormatter, SharedTooltipItem, TooltipStyleClasses, Translator } from '../../tooltips';
|
|
6
|
+
import { buildSharedItemTooltip } from '../../tooltips';
|
|
7
|
+
import { buildCircularBaseOptions } from '../buildCircularBaseOptions';
|
|
8
|
+
|
|
9
|
+
export interface PieChartOptionsInput {
|
|
10
|
+
readonly slices: readonly FluxStatisticsChartPieSlice[];
|
|
11
|
+
readonly palette: readonly string[];
|
|
12
|
+
readonly tooltipItems: readonly SharedTooltipItem[];
|
|
13
|
+
readonly title?: string;
|
|
14
|
+
readonly t: Translator;
|
|
15
|
+
readonly styles: TooltipStyleClasses;
|
|
16
|
+
readonly tooltip?: boolean;
|
|
17
|
+
readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
|
|
18
|
+
readonly advancedOptions?: EChartsOption;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function buildPieChartOptions(input: PieChartOptionsInput): EChartsOption {
|
|
22
|
+
const { slices, palette, tooltipItems, title, t, styles, tooltip = false, tooltipValueFormatter, advancedOptions = {} } = input;
|
|
23
|
+
|
|
24
|
+
const tooltipOptions: EChartsOption = tooltip
|
|
25
|
+
? buildSharedItemTooltip({ t, styles, getItems: () => tooltipItems, getTitle: () => title, valueFormatter: tooltipValueFormatter })
|
|
26
|
+
: { tooltip: { show: false } };
|
|
27
|
+
|
|
28
|
+
const echartsSeries = [toPieSeries(slices, palette)];
|
|
29
|
+
|
|
30
|
+
return merge({}, buildCircularBaseOptions(), tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FluxStatisticsChartPieSlice } from '@flux-ui/types';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
import type { EChartsOption } from '~flux/statistics/composable';
|
|
4
|
+
import { toPolarAreaSeries } from '../../series';
|
|
5
|
+
import type { ChartTooltipValueFormatter, SharedTooltipItem, TooltipStyleClasses, Translator } from '../../tooltips';
|
|
6
|
+
import { buildSharedItemTooltip } from '../../tooltips';
|
|
7
|
+
import { buildCircularBaseOptions } from '../buildCircularBaseOptions';
|
|
8
|
+
|
|
9
|
+
export interface PolarAreaChartOptionsInput {
|
|
10
|
+
readonly slices: readonly FluxStatisticsChartPieSlice[];
|
|
11
|
+
readonly palette: readonly string[];
|
|
12
|
+
readonly tooltipItems: readonly SharedTooltipItem[];
|
|
13
|
+
readonly title?: string;
|
|
14
|
+
readonly t: Translator;
|
|
15
|
+
readonly styles: TooltipStyleClasses;
|
|
16
|
+
readonly tooltip?: boolean;
|
|
17
|
+
readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
|
|
18
|
+
readonly advancedOptions?: EChartsOption;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function buildPolarAreaChartOptions(input: PolarAreaChartOptionsInput): EChartsOption {
|
|
22
|
+
const { slices, palette, tooltipItems, title, t, styles, tooltip = false, tooltipValueFormatter, advancedOptions = {} } = input;
|
|
23
|
+
|
|
24
|
+
const tooltipOptions: EChartsOption = tooltip
|
|
25
|
+
? buildSharedItemTooltip({ t, styles, getItems: () => tooltipItems, getTitle: () => title, valueFormatter: tooltipValueFormatter })
|
|
26
|
+
: { tooltip: { show: false } };
|
|
27
|
+
|
|
28
|
+
const echartsSeries = [toPolarAreaSeries(slices, palette)];
|
|
29
|
+
|
|
30
|
+
return merge({}, buildCircularBaseOptions(), tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
|
|
31
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FluxStatisticsChartRadarIndicator, FluxStatisticsChartRadarSeries } from '@flux-ui/types';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
import type { EChartsOption } from '~flux/statistics/composable';
|
|
4
|
+
import { toRadarSeries } from '../../series';
|
|
5
|
+
import type { TooltipStyleClasses, Translator } from '../../tooltips';
|
|
6
|
+
import { buildRadarTooltip } from '../../tooltips';
|
|
7
|
+
import { buildCircularBaseOptions } from '../buildCircularBaseOptions';
|
|
8
|
+
|
|
9
|
+
export interface RadarChartOptionsInput {
|
|
10
|
+
readonly series: readonly FluxStatisticsChartRadarSeries[];
|
|
11
|
+
readonly indicators: readonly FluxStatisticsChartRadarIndicator[];
|
|
12
|
+
readonly palette: readonly string[];
|
|
13
|
+
readonly t: Translator;
|
|
14
|
+
readonly styles: TooltipStyleClasses;
|
|
15
|
+
readonly tooltip?: boolean;
|
|
16
|
+
readonly advancedOptions?: EChartsOption;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function buildRadarChartOptions(input: RadarChartOptionsInput): EChartsOption {
|
|
20
|
+
const { series, indicators, palette, t, styles, tooltip = false, advancedOptions = {} } = input;
|
|
21
|
+
|
|
22
|
+
const radarConfig: EChartsOption = {
|
|
23
|
+
radar: {
|
|
24
|
+
indicator: indicators.map(i => ({ name: t(String(i.name)), max: i.max })),
|
|
25
|
+
splitLine: { lineStyle: { color: 'var(--gray-200)' } },
|
|
26
|
+
splitArea: { show: false },
|
|
27
|
+
axisLine: { lineStyle: { color: 'var(--gray-200)' } },
|
|
28
|
+
axisName: {
|
|
29
|
+
color: 'var(--foreground-secondary)',
|
|
30
|
+
fontSize: 12,
|
|
31
|
+
fontWeight: 500
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const tooltipOptions: EChartsOption = tooltip
|
|
37
|
+
? buildRadarTooltip({
|
|
38
|
+
t,
|
|
39
|
+
styles,
|
|
40
|
+
getSeries: () => series,
|
|
41
|
+
getIndicators: () => indicators,
|
|
42
|
+
getPalette: () => palette
|
|
43
|
+
})
|
|
44
|
+
: { tooltip: { show: false } };
|
|
45
|
+
|
|
46
|
+
const echartsSeries = [toRadarSeries(
|
|
47
|
+
series.map(s => ({ ...s, name: s.name ? t(String(s.name)) : undefined })),
|
|
48
|
+
palette
|
|
49
|
+
)];
|
|
50
|
+
|
|
51
|
+
return merge({}, buildCircularBaseOptions(), radarConfig, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FluxStatisticsChartTreemapNode } from '@flux-ui/types';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
import type { EChartsOption } from '~flux/statistics/composable';
|
|
4
|
+
import { CHART_DEFAULT_COLORS, toTreemapSeries } from '../../series';
|
|
5
|
+
import type { TooltipStyleClasses, Translator } from '../../tooltips';
|
|
6
|
+
import { buildTreemapTooltip } from '../../tooltips';
|
|
7
|
+
import { buildCircularBaseOptions } from '../buildCircularBaseOptions';
|
|
8
|
+
|
|
9
|
+
export interface TreemapChartOptionsInput {
|
|
10
|
+
readonly nodes: readonly FluxStatisticsChartTreemapNode[];
|
|
11
|
+
readonly palette?: readonly string[];
|
|
12
|
+
readonly t: Translator;
|
|
13
|
+
readonly styles: TooltipStyleClasses;
|
|
14
|
+
readonly tooltip?: boolean;
|
|
15
|
+
readonly advancedOptions?: EChartsOption;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function buildTreemapChartOptions(input: TreemapChartOptionsInput): EChartsOption {
|
|
19
|
+
const { nodes, palette = CHART_DEFAULT_COLORS, t, styles, tooltip = false, advancedOptions = {} } = input;
|
|
20
|
+
|
|
21
|
+
const tooltipOptions: EChartsOption = tooltip
|
|
22
|
+
? buildTreemapTooltip({ t, styles })
|
|
23
|
+
: { tooltip: { show: false } };
|
|
24
|
+
|
|
25
|
+
const echartsSeries = [toTreemapSeries(nodes, palette)];
|
|
26
|
+
|
|
27
|
+
return merge({}, buildCircularBaseOptions(), tooltipOptions, advancedOptions, { series: echartsSeries });
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { DonutChartOptionsInput } from './buildDonutChartOptions';
|
|
2
|
+
export { buildDonutChartOptions } from './buildDonutChartOptions';
|
|
3
|
+
export type { GaugeChartOptionsInput } from './buildGaugeChartOptions';
|
|
4
|
+
export { buildGaugeChartOptions, gaugeLegendItemBuilder } from './buildGaugeChartOptions';
|
|
5
|
+
export type { PieChartOptionsInput } from './buildPieChartOptions';
|
|
6
|
+
export { buildPieChartOptions } from './buildPieChartOptions';
|
|
7
|
+
export type { PolarAreaChartOptionsInput } from './buildPolarAreaChartOptions';
|
|
8
|
+
export { buildPolarAreaChartOptions } from './buildPolarAreaChartOptions';
|
|
9
|
+
export type { RadarChartOptionsInput } from './buildRadarChartOptions';
|
|
10
|
+
export { buildRadarChartOptions } from './buildRadarChartOptions';
|
|
11
|
+
export type { TreemapChartOptionsInput } from './buildTreemapChartOptions';
|
|
12
|
+
export { buildTreemapChartOptions } from './buildTreemapChartOptions';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './cartesian';
|
|
2
|
+
export * from './circular';
|
|
3
|
+
export { buildBaseOptions } from './buildBaseOptions';
|
|
4
|
+
export type { CartesianBaseConfig } from './buildCartesianBaseOptions';
|
|
5
|
+
export { buildCartesianBaseOptions, buildCartesianGrid } from './buildCartesianBaseOptions';
|
|
6
|
+
export { buildCircularBaseOptions } from './buildCircularBaseOptions';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FluxStatisticsChartColor } from '@flux-ui/types';
|
|
2
|
+
|
|
3
|
+
export const CHART_DEFAULT_COLORS = [
|
|
4
|
+
'var(--chart-1)',
|
|
5
|
+
'var(--chart-2)',
|
|
6
|
+
'var(--chart-3)',
|
|
7
|
+
'var(--chart-4)'
|
|
8
|
+
] as const;
|
|
9
|
+
|
|
10
|
+
export function resolveChartColor(color?: FluxStatisticsChartColor): string | undefined {
|
|
11
|
+
if (!color) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (color.startsWith('#') || color.startsWith('var(')) {
|
|
16
|
+
return color;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return `var(--${color}-600)`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FluxStatisticsChartAreaSeries,
|
|
3
|
+
FluxStatisticsChartBarSeries,
|
|
4
|
+
FluxStatisticsChartBoxPlotSeries,
|
|
5
|
+
FluxStatisticsChartBubbleSeries,
|
|
6
|
+
FluxStatisticsChartCandlestickSeries,
|
|
7
|
+
FluxStatisticsChartCategoryPoint,
|
|
8
|
+
FluxStatisticsChartGaugeSeries,
|
|
9
|
+
FluxStatisticsChartHeatmapSeries,
|
|
10
|
+
FluxStatisticsChartLineSeries,
|
|
11
|
+
FluxStatisticsChartMixedSeries,
|
|
12
|
+
FluxStatisticsChartPieSlice,
|
|
13
|
+
FluxStatisticsChartRadarSeries,
|
|
14
|
+
FluxStatisticsChartScatterSeries,
|
|
15
|
+
FluxStatisticsChartTreemapNode
|
|
16
|
+
} from '@flux-ui/types';
|
|
17
|
+
import type {
|
|
18
|
+
BarSeriesOption,
|
|
19
|
+
BoxplotSeriesOption,
|
|
20
|
+
CandlestickSeriesOption,
|
|
21
|
+
GaugeSeriesOption,
|
|
22
|
+
HeatmapSeriesOption,
|
|
23
|
+
LineSeriesOption,
|
|
24
|
+
PieSeriesOption,
|
|
25
|
+
RadarSeriesOption,
|
|
26
|
+
ScatterSeriesOption,
|
|
27
|
+
TreemapSeriesOption
|
|
28
|
+
} from 'echarts/charts';
|
|
29
|
+
import { resolveChartColor } from './chartColors';
|
|
30
|
+
import {
|
|
31
|
+
AREA_SERIES_DEFAULTS,
|
|
32
|
+
BAR_SERIES_DEFAULTS,
|
|
33
|
+
BOXPLOT_SERIES_DEFAULTS,
|
|
34
|
+
BUBBLE_SERIES_DEFAULTS,
|
|
35
|
+
CANDLESTICK_SERIES_DEFAULTS,
|
|
36
|
+
DONUT_SERIES_DEFAULTS,
|
|
37
|
+
GAUGE_SERIES_DEFAULTS,
|
|
38
|
+
HEATMAP_SERIES_DEFAULTS,
|
|
39
|
+
LINE_SERIES_DEFAULTS,
|
|
40
|
+
PIE_SERIES_DEFAULTS,
|
|
41
|
+
POLAR_AREA_SERIES_DEFAULTS,
|
|
42
|
+
RADAR_SERIES_DEFAULTS,
|
|
43
|
+
SCATTER_SERIES_DEFAULTS,
|
|
44
|
+
TREEMAP_SERIES_DEFAULTS
|
|
45
|
+
} from './defaults';
|
|
46
|
+
|
|
47
|
+
function extractValues(data: readonly (number | FluxStatisticsChartCategoryPoint)[]): number[] {
|
|
48
|
+
return data.map(point => typeof point === 'number' ? point : point.value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function toLineSeries(s: FluxStatisticsChartLineSeries, fallbackColor: string): LineSeriesOption {
|
|
52
|
+
return {
|
|
53
|
+
...LINE_SERIES_DEFAULTS,
|
|
54
|
+
name: s.name,
|
|
55
|
+
data: extractValues(s.data),
|
|
56
|
+
color: resolveChartColor(s.color) ?? fallbackColor
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function toAreaSeries(s: FluxStatisticsChartAreaSeries, fallbackColor: string): LineSeriesOption {
|
|
61
|
+
return {
|
|
62
|
+
...AREA_SERIES_DEFAULTS,
|
|
63
|
+
name: s.name,
|
|
64
|
+
data: extractValues(s.data),
|
|
65
|
+
color: resolveChartColor(s.color) ?? fallbackColor
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function toBarSeries(s: FluxStatisticsChartBarSeries, fallbackColor: string): BarSeriesOption {
|
|
70
|
+
return {
|
|
71
|
+
...BAR_SERIES_DEFAULTS,
|
|
72
|
+
name: s.name,
|
|
73
|
+
data: extractValues(s.data),
|
|
74
|
+
color: resolveChartColor(s.color) ?? fallbackColor
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function toMixedSeries(s: FluxStatisticsChartMixedSeries, fallbackColor: string): LineSeriesOption | BarSeriesOption {
|
|
79
|
+
const color = resolveChartColor(s.color) ?? fallbackColor;
|
|
80
|
+
const values = extractValues(s.data);
|
|
81
|
+
|
|
82
|
+
if (s.type === 'bar') {
|
|
83
|
+
return {
|
|
84
|
+
...BAR_SERIES_DEFAULTS,
|
|
85
|
+
barCategoryGap: '55%',
|
|
86
|
+
name: s.name,
|
|
87
|
+
data: values,
|
|
88
|
+
color
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (s.type === 'area') {
|
|
93
|
+
return {
|
|
94
|
+
...AREA_SERIES_DEFAULTS,
|
|
95
|
+
name: s.name,
|
|
96
|
+
data: values,
|
|
97
|
+
color
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...LINE_SERIES_DEFAULTS,
|
|
103
|
+
lineStyle: { width: 2 },
|
|
104
|
+
name: s.name,
|
|
105
|
+
data: values,
|
|
106
|
+
color
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface PieDataItem {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly value: number;
|
|
113
|
+
readonly itemStyle?: { readonly color: string };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function buildPieData(slices: readonly FluxStatisticsChartPieSlice[], palette: readonly string[]): PieDataItem[] {
|
|
117
|
+
return slices.map((slice, idx) => {
|
|
118
|
+
const color = resolveChartColor(slice.color) ?? palette[idx % palette.length];
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
name: slice.label,
|
|
122
|
+
value: slice.value,
|
|
123
|
+
itemStyle: { color }
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function toPieSeries(slices: readonly FluxStatisticsChartPieSlice[], palette: readonly string[]): PieSeriesOption {
|
|
129
|
+
return {
|
|
130
|
+
...PIE_SERIES_DEFAULTS,
|
|
131
|
+
data: buildPieData(slices, palette)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function toDonutSeries(slices: readonly FluxStatisticsChartPieSlice[], palette: readonly string[]): PieSeriesOption {
|
|
136
|
+
return {
|
|
137
|
+
...DONUT_SERIES_DEFAULTS,
|
|
138
|
+
data: buildPieData(slices, palette)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function toPolarAreaSeries(slices: readonly FluxStatisticsChartPieSlice[], palette: readonly string[]): PieSeriesOption {
|
|
143
|
+
return {
|
|
144
|
+
...POLAR_AREA_SERIES_DEFAULTS,
|
|
145
|
+
data: buildPieData(slices, palette)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface RadarRing {
|
|
150
|
+
readonly value: readonly number[];
|
|
151
|
+
readonly name?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function toRadarSeries(series: readonly FluxStatisticsChartRadarSeries[], palette: readonly string[]): RadarSeriesOption {
|
|
155
|
+
const data: RadarRing[] = series.map(ring => ({
|
|
156
|
+
value: ring.values,
|
|
157
|
+
name: ring.name
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...RADAR_SERIES_DEFAULTS,
|
|
162
|
+
data,
|
|
163
|
+
color: palette as string[]
|
|
164
|
+
} as RadarSeriesOption;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function toScatterSeries(s: FluxStatisticsChartScatterSeries, fallbackColor: string): ScatterSeriesOption {
|
|
168
|
+
return {
|
|
169
|
+
...SCATTER_SERIES_DEFAULTS,
|
|
170
|
+
name: s.name,
|
|
171
|
+
data: s.data.map(point => [point.x, point.y]),
|
|
172
|
+
color: resolveChartColor(s.color) ?? fallbackColor
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function toBubbleSeries(s: FluxStatisticsChartBubbleSeries, fallbackColor: string): ScatterSeriesOption {
|
|
177
|
+
const sizes = s.data.map(p => p.size);
|
|
178
|
+
const maxSize = Math.max(1, ...sizes);
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
...BUBBLE_SERIES_DEFAULTS,
|
|
182
|
+
name: s.name,
|
|
183
|
+
data: s.data.map(point => [point.x, point.y, point.size]),
|
|
184
|
+
symbolSize: (val: unknown) => {
|
|
185
|
+
const size = Array.isArray(val) ? (val[2] as number) : 0;
|
|
186
|
+
return 14 + (size / maxSize) * 30;
|
|
187
|
+
},
|
|
188
|
+
color: resolveChartColor(s.color) ?? fallbackColor
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function toCandlestickSeries(s: FluxStatisticsChartCandlestickSeries): CandlestickSeriesOption {
|
|
193
|
+
const positive = resolveChartColor(s.positiveColor) ?? 'var(--success-500)';
|
|
194
|
+
const negative = resolveChartColor(s.negativeColor) ?? 'var(--danger-500)';
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
...CANDLESTICK_SERIES_DEFAULTS,
|
|
198
|
+
name: s.name,
|
|
199
|
+
data: s.data.map(point => [point.open, point.close, point.low, point.high]),
|
|
200
|
+
itemStyle: {
|
|
201
|
+
color: positive,
|
|
202
|
+
color0: negative,
|
|
203
|
+
borderColor: positive,
|
|
204
|
+
borderColor0: negative
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function toBoxPlotSeries(s: FluxStatisticsChartBoxPlotSeries, fallbackColor: string): BoxplotSeriesOption {
|
|
210
|
+
const color = resolveChartColor(s.color) ?? fallbackColor;
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
...BOXPLOT_SERIES_DEFAULTS,
|
|
214
|
+
name: s.name,
|
|
215
|
+
data: s.data.map(point => [point.min, point.q1, point.median, point.q3, point.max]),
|
|
216
|
+
itemStyle: {
|
|
217
|
+
color,
|
|
218
|
+
borderColor: 'var(--foreground-prominent)',
|
|
219
|
+
borderWidth: 1
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function toHeatmapSeries(
|
|
225
|
+
s: FluxStatisticsChartHeatmapSeries,
|
|
226
|
+
xLabels: readonly (string | number)[],
|
|
227
|
+
yLabels: readonly (string | number)[]
|
|
228
|
+
): HeatmapSeriesOption {
|
|
229
|
+
const data = s.data.map(point => {
|
|
230
|
+
const xIdx = typeof point.x === 'number' ? point.x : xLabels.indexOf(point.x);
|
|
231
|
+
const yIdx = typeof point.y === 'number' ? point.y : yLabels.indexOf(point.y);
|
|
232
|
+
|
|
233
|
+
return [xIdx, yIdx, point.value];
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
...HEATMAP_SERIES_DEFAULTS,
|
|
238
|
+
name: s.name,
|
|
239
|
+
data
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
interface TreemapDataItem {
|
|
244
|
+
readonly name: string;
|
|
245
|
+
readonly value?: number;
|
|
246
|
+
readonly itemStyle?: { readonly color: string };
|
|
247
|
+
readonly children?: TreemapDataItem[];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function mapTreemapNode(node: FluxStatisticsChartTreemapNode, palette: readonly string[], index: number): TreemapDataItem {
|
|
251
|
+
const resolved = resolveChartColor(node.color);
|
|
252
|
+
const color = resolved ?? palette[index % palette.length];
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
name: node.name,
|
|
256
|
+
value: node.value,
|
|
257
|
+
itemStyle: { color },
|
|
258
|
+
children: node.children?.map((child, idx) => mapTreemapNode(child, palette, idx))
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function toTreemapSeries(
|
|
263
|
+
nodes: readonly FluxStatisticsChartTreemapNode[],
|
|
264
|
+
palette: readonly string[]
|
|
265
|
+
): TreemapSeriesOption {
|
|
266
|
+
return {
|
|
267
|
+
...TREEMAP_SERIES_DEFAULTS,
|
|
268
|
+
data: nodes.map((node, idx) => mapTreemapNode(node, palette, idx)),
|
|
269
|
+
levels: [{
|
|
270
|
+
itemStyle: { borderColor: 'var(--surface)', borderWidth: 3, gapWidth: 0 }
|
|
271
|
+
}, {
|
|
272
|
+
itemStyle: { gapWidth: 1 }
|
|
273
|
+
}, {
|
|
274
|
+
itemStyle: { gapWidth: 1 }
|
|
275
|
+
}]
|
|
276
|
+
} as TreemapSeriesOption;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function toGaugeSeries(
|
|
280
|
+
s: FluxStatisticsChartGaugeSeries,
|
|
281
|
+
fallbackColor: string,
|
|
282
|
+
index: number,
|
|
283
|
+
total: number
|
|
284
|
+
): GaugeSeriesOption {
|
|
285
|
+
const color = resolveChartColor(s.color) ?? fallbackColor;
|
|
286
|
+
const ringStep = total > 1 ? 30 : 0;
|
|
287
|
+
const baseRadius = s.radius ?? (90 - index * ringStep);
|
|
288
|
+
const labelOffset = (total - 1 - index) * 22 - 30;
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
...GAUGE_SERIES_DEFAULTS,
|
|
292
|
+
radius: `${baseRadius}%`,
|
|
293
|
+
data: [{ value: s.value, name: s.name, itemStyle: { color } }],
|
|
294
|
+
progress: {
|
|
295
|
+
show: true,
|
|
296
|
+
width: 14,
|
|
297
|
+
roundCap: true,
|
|
298
|
+
itemStyle: { color }
|
|
299
|
+
},
|
|
300
|
+
title: {
|
|
301
|
+
show: true,
|
|
302
|
+
color: 'var(--foreground-secondary)',
|
|
303
|
+
fontSize: 12,
|
|
304
|
+
fontWeight: 500,
|
|
305
|
+
fontFamily: 'inherit',
|
|
306
|
+
offsetCenter: [0, `${labelOffset}%`]
|
|
307
|
+
},
|
|
308
|
+
detail: {
|
|
309
|
+
show: total === 1,
|
|
310
|
+
color: 'var(--foreground-prominent)',
|
|
311
|
+
fontSize: 28,
|
|
312
|
+
fontWeight: 800,
|
|
313
|
+
fontFamily: 'inherit',
|
|
314
|
+
offsetCenter: [0, '10%'],
|
|
315
|
+
formatter: '{value}%'
|
|
316
|
+
}
|
|
317
|
+
} as GaugeSeriesOption;
|
|
318
|
+
}
|