@flux-ui/statistics 3.0.0-next.68 → 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.
Files changed (119) hide show
  1. package/dist/component/FluxStatisticsLegendScope.vue.d.ts +13 -0
  2. package/dist/component/FluxStatisticsPercentageBar.vue.d.ts +8 -0
  3. package/dist/component/index.d.ts +2 -0
  4. package/dist/composable/index.d.ts +4 -2
  5. package/dist/composable/useChartBaseSetup.d.ts +8 -0
  6. package/dist/composable/{usePieSlicesSetup.d.ts → useChartSlicesSetup.d.ts} +2 -2
  7. package/dist/index.css +67 -32
  8. package/dist/index.js +913 -510
  9. package/dist/index.js.map +1 -1
  10. package/dist/util/index.d.ts +5 -6
  11. package/dist/util/options/buildBaseOptions.d.ts +2 -0
  12. package/dist/util/{baseOptions.d.ts → options/buildCartesianBaseOptions.d.ts} +4 -6
  13. package/dist/util/options/buildCircularBaseOptions.d.ts +2 -0
  14. package/dist/util/options/cartesian/buildAreaChartOptions.d.ts +17 -0
  15. package/dist/util/options/cartesian/buildBarChartOptions.d.ts +17 -0
  16. package/dist/util/options/cartesian/buildBoxPlotChartOptions.d.ts +16 -0
  17. package/dist/util/options/cartesian/buildBubbleChartOptions.d.ts +15 -0
  18. package/dist/util/options/cartesian/buildCandlestickChartOptions.d.ts +17 -0
  19. package/dist/util/options/cartesian/buildHeatmapChartOptions.d.ts +15 -0
  20. package/dist/util/options/cartesian/buildLineChartOptions.d.ts +17 -0
  21. package/dist/util/options/cartesian/buildMixedChartOptions.d.ts +17 -0
  22. package/dist/util/options/cartesian/buildScatterChartOptions.d.ts +15 -0
  23. package/dist/util/options/cartesian/index.d.ts +18 -0
  24. package/dist/util/options/circular/buildDonutChartOptions.d.ts +15 -0
  25. package/dist/util/options/circular/buildGaugeChartOptions.d.ts +14 -0
  26. package/dist/util/options/circular/buildPieChartOptions.d.ts +15 -0
  27. package/dist/util/options/circular/buildPolarAreaChartOptions.d.ts +15 -0
  28. package/dist/util/options/circular/buildRadarChartOptions.d.ts +13 -0
  29. package/dist/util/options/circular/buildTreemapChartOptions.d.ts +12 -0
  30. package/dist/util/options/circular/index.d.ts +12 -0
  31. package/dist/util/options/index.d.ts +6 -0
  32. package/dist/util/series/chartColors.d.ts +3 -0
  33. package/dist/util/{convert.d.ts → series/converters.d.ts} +1 -6
  34. package/dist/util/series/index.d.ts +4 -0
  35. package/dist/util/series/labels.d.ts +5 -0
  36. package/dist/util/tooltips/buildBoxPlotTooltip.d.ts +22 -0
  37. package/dist/util/tooltips/buildCartesianTooltip.d.ts +10 -0
  38. package/dist/util/tooltips/buildGaugeTooltip.d.ts +14 -0
  39. package/dist/util/tooltips/buildHeatmapTooltip.d.ts +17 -0
  40. package/dist/util/tooltips/buildRadarTooltip.d.ts +11 -0
  41. package/dist/util/tooltips/buildSharedItemTooltip.d.ts +10 -0
  42. package/dist/util/tooltips/buildTreemapTooltip.d.ts +12 -0
  43. package/dist/util/tooltips/index.d.ts +15 -0
  44. package/dist/util/tooltips/render.d.ts +4 -0
  45. package/dist/util/tooltips/types.d.ts +24 -0
  46. package/package.json +4 -4
  47. package/src/component/FluxStatisticsAreaChart.vue +15 -19
  48. package/src/component/FluxStatisticsBarChart.vue +15 -19
  49. package/src/component/FluxStatisticsBoxPlotChart.vue +14 -34
  50. package/src/component/FluxStatisticsBubbleChart.vue +13 -23
  51. package/src/component/FluxStatisticsCandlestickChart.vue +14 -45
  52. package/src/component/FluxStatisticsChart.vue +2 -2
  53. package/src/component/FluxStatisticsChartPane.vue +12 -13
  54. package/src/component/FluxStatisticsDonutChart.vue +15 -24
  55. package/src/component/FluxStatisticsHeatmapChart.vue +15 -48
  56. package/src/component/FluxStatisticsLegendScope.vue +16 -0
  57. package/src/component/FluxStatisticsLineChart.vue +15 -19
  58. package/src/component/FluxStatisticsMixedChart.vue +15 -18
  59. package/src/component/FluxStatisticsPercentageBar.vue +90 -0
  60. package/src/component/FluxStatisticsPieChart.vue +15 -24
  61. package/src/component/FluxStatisticsPolarAreaChart.vue +15 -24
  62. package/src/component/FluxStatisticsRadarChart.vue +11 -79
  63. package/src/component/FluxStatisticsRadialBar.vue +11 -20
  64. package/src/component/FluxStatisticsScatterChart.vue +13 -23
  65. package/src/component/FluxStatisticsTreemapChart.vue +11 -15
  66. package/src/component/index.ts +2 -0
  67. package/src/composable/index.ts +4 -2
  68. package/src/composable/useChartBaseSetup.ts +16 -0
  69. package/src/composable/{usePieSlicesSetup.ts → useChartSlicesSetup.ts} +3 -3
  70. package/src/css/Chart.module.scss +10 -15
  71. package/src/css/ChartPane.module.scss +3 -10
  72. package/src/css/Empty.module.scss +2 -2
  73. package/src/css/Legend.module.scss +16 -8
  74. package/src/css/Meter.module.scss +1 -0
  75. package/src/css/PercentageBar.module.scss +36 -0
  76. package/src/util/index.ts +5 -6
  77. package/src/util/options/buildBaseOptions.ts +31 -0
  78. package/src/util/{baseOptions.ts → options/buildCartesianBaseOptions.ts} +15 -22
  79. package/src/util/options/buildCircularBaseOptions.ts +10 -0
  80. package/src/util/options/cartesian/buildAreaChartOptions.ts +44 -0
  81. package/src/util/options/cartesian/buildBarChartOptions.ts +44 -0
  82. package/src/util/options/cartesian/buildBoxPlotChartOptions.ts +63 -0
  83. package/src/util/options/cartesian/buildBubbleChartOptions.ts +48 -0
  84. package/src/util/options/cartesian/buildCandlestickChartOptions.ts +77 -0
  85. package/src/util/options/cartesian/buildHeatmapChartOptions.ts +72 -0
  86. package/src/util/options/cartesian/buildLineChartOptions.ts +44 -0
  87. package/src/util/options/cartesian/buildMixedChartOptions.ts +44 -0
  88. package/src/util/options/cartesian/buildScatterChartOptions.ts +48 -0
  89. package/src/util/options/cartesian/index.ts +18 -0
  90. package/src/util/options/circular/buildDonutChartOptions.ts +31 -0
  91. package/src/util/options/circular/buildGaugeChartOptions.ts +45 -0
  92. package/src/util/options/circular/buildPieChartOptions.ts +31 -0
  93. package/src/util/options/circular/buildPolarAreaChartOptions.ts +31 -0
  94. package/src/util/options/circular/buildRadarChartOptions.ts +52 -0
  95. package/src/util/options/circular/buildTreemapChartOptions.ts +28 -0
  96. package/src/util/options/circular/index.ts +12 -0
  97. package/src/util/options/index.ts +6 -0
  98. package/src/util/series/chartColors.ts +20 -0
  99. package/src/util/{convert.ts → series/converters.ts} +2 -44
  100. package/src/util/series/index.ts +4 -0
  101. package/src/util/series/labels.ts +30 -0
  102. package/src/util/tooltips/buildBoxPlotTooltip.ts +66 -0
  103. package/src/util/tooltips/buildCartesianTooltip.ts +44 -0
  104. package/src/util/tooltips/buildGaugeTooltip.ts +49 -0
  105. package/src/util/tooltips/buildHeatmapTooltip.ts +57 -0
  106. package/src/util/tooltips/buildRadarTooltip.ts +53 -0
  107. package/src/util/tooltips/buildSharedItemTooltip.ts +38 -0
  108. package/src/util/tooltips/buildTreemapTooltip.ts +49 -0
  109. package/src/util/tooltips/index.ts +15 -0
  110. package/src/util/tooltips/render.ts +66 -0
  111. package/src/util/tooltips/types.ts +29 -0
  112. package/dist/util/defaultOptions.d.ts +0 -76
  113. package/src/util/defaultOptions.ts +0 -398
  114. /package/dist/util/{iconSvg.d.ts → icons.d.ts} +0 -0
  115. /package/dist/util/{seriesDefaults.d.ts → series/defaults.d.ts} +0 -0
  116. /package/dist/util/{sparklineOptions.d.ts → sparkline.d.ts} +0 -0
  117. /package/src/util/{iconSvg.ts → icons.ts} +0 -0
  118. /package/src/util/{seriesDefaults.ts → series/defaults.ts} +0 -0
  119. /package/src/util/{sparklineOptions.ts → sparkline.ts} +0 -0
@@ -0,0 +1,38 @@
1
+ import type { EChartsOption } from '~flux/statistics/composable';
2
+ import { renderTooltip } from './render';
3
+ import type { ChartTooltipValueFormatter, SharedTooltipItem, TooltipParam, TooltipStyleClasses, Translator } from './types';
4
+
5
+ export interface SharedItemTooltipInput {
6
+ readonly t: Translator;
7
+ readonly styles: TooltipStyleClasses;
8
+ readonly getItems: () => readonly SharedTooltipItem[];
9
+ readonly getTitle?: () => string | undefined;
10
+ readonly valueFormatter?: ChartTooltipValueFormatter;
11
+ }
12
+
13
+ export function buildSharedItemTooltip(input: SharedItemTooltipInput): EChartsOption {
14
+ const { t, styles, getItems, getTitle, valueFormatter } = input;
15
+
16
+ const formatter = (params: TooltipParam | TooltipParam[]): string => {
17
+ const param = Array.isArray(params) ? params[0] : params;
18
+
19
+ if (!param) {
20
+ return '';
21
+ }
22
+
23
+ const items = getItems();
24
+ const activeIndex = param.dataIndex ?? -1;
25
+ const rawTitle = getTitle?.() ?? '';
26
+ const title = rawTitle ? t(String(rawTitle)) : '';
27
+
28
+ return renderTooltip(t, styles, title, items, activeIndex, valueFormatter);
29
+ };
30
+
31
+ return {
32
+ tooltip: {
33
+ show: true,
34
+ trigger: 'item',
35
+ formatter: formatter as never
36
+ }
37
+ };
38
+ }
@@ -0,0 +1,49 @@
1
+ import type { EChartsOption } from '~flux/statistics/composable';
2
+ import { renderTooltip } from './render';
3
+ import type { SharedTooltipItem, TooltipParam, TooltipStyleClasses, Translator } from './types';
4
+
5
+ export interface TreemapTooltipNode {
6
+ readonly name: string;
7
+ readonly value?: number;
8
+ readonly color?: string;
9
+ }
10
+
11
+ export interface TreemapTooltipInput {
12
+ readonly t: Translator;
13
+ readonly styles: TooltipStyleClasses;
14
+ }
15
+
16
+ export function buildTreemapTooltip(input: TreemapTooltipInput): EChartsOption {
17
+ const { t, styles } = input;
18
+
19
+ const formatter = (params: TooltipParam | TooltipParam[]): string => {
20
+ const param = Array.isArray(params) ? params[0] : params;
21
+
22
+ if (!param) {
23
+ return '';
24
+ }
25
+
26
+ const data = param.data as TreemapTooltipNode | undefined;
27
+
28
+ if (!data) {
29
+ return '';
30
+ }
31
+
32
+ const color = data.color ?? 'var(--primary-600)';
33
+ const title = data.name ? t(String(data.name)) : '';
34
+
35
+ const items: SharedTooltipItem[] = [
36
+ { name: '', value: data.value ?? '', color }
37
+ ];
38
+
39
+ return renderTooltip(t, styles, title, items);
40
+ };
41
+
42
+ return {
43
+ tooltip: {
44
+ show: true,
45
+ trigger: 'item',
46
+ formatter: formatter as never
47
+ }
48
+ };
49
+ }
@@ -0,0 +1,15 @@
1
+ export type { BoxPlotTooltipInput, BoxPlotTooltipPoint } from './buildBoxPlotTooltip';
2
+ export { buildBoxPlotTooltip } from './buildBoxPlotTooltip';
3
+ export type { CartesianTooltipInput } from './buildCartesianTooltip';
4
+ export { buildCartesianTooltip } from './buildCartesianTooltip';
5
+ export type { GaugeTooltipInput } from './buildGaugeTooltip';
6
+ export { buildGaugeTooltip } from './buildGaugeTooltip';
7
+ export type { HeatmapTooltipInput, HeatmapTooltipPoint } from './buildHeatmapTooltip';
8
+ export { buildHeatmapTooltip } from './buildHeatmapTooltip';
9
+ export type { RadarTooltipInput } from './buildRadarTooltip';
10
+ export { buildRadarTooltip } from './buildRadarTooltip';
11
+ export type { SharedItemTooltipInput } from './buildSharedItemTooltip';
12
+ export { buildSharedItemTooltip } from './buildSharedItemTooltip';
13
+ export type { TreemapTooltipInput, TreemapTooltipNode } from './buildTreemapTooltip';
14
+ export { buildTreemapTooltip } from './buildTreemapTooltip';
15
+ export type { ChartTooltipValueFormatter, SharedTooltipItem, TooltipParam, TooltipStyleClasses, Translator } from './types';
@@ -0,0 +1,66 @@
1
+ import { formatNumber } from '@basmilius/utils';
2
+ import { renderIconSvg } from '../icons';
3
+ import type { ChartTooltipValueFormatter, SharedTooltipItem, TooltipParam, TooltipStyleClasses, Translator } from './types';
4
+
5
+ export function renderTooltip(
6
+ t: Translator,
7
+ styles: TooltipStyleClasses,
8
+ title: string,
9
+ items: readonly SharedTooltipItem[],
10
+ activeIndex: number = -1,
11
+ valueFormatter?: ChartTooltipValueFormatter
12
+ ): string {
13
+ if (items.length === 0) {
14
+ return '';
15
+ }
16
+
17
+ const titleHtml = title
18
+ ? `<div class="${styles.statisticsChartTooltipTitle}">${title}</div>`
19
+ : '';
20
+
21
+ const hasActive = activeIndex !== -1;
22
+
23
+ const body = items.map((item, idx) => {
24
+ const isActive = !hasActive || idx === activeIndex;
25
+ const activeClass = isActive ? ` ${styles.isActive}` : '';
26
+ const translatedName = item.name ? t(String(item.name)) : '';
27
+
28
+ const marker = item.icon
29
+ ? `<div class="${styles.statisticsChartTooltipSeriesIcon}${activeClass}" style="color: ${item.color}">${renderIconSvg(item.icon, item.color, 14)}</div>`
30
+ : `<div class="${styles.statisticsChartTooltipSeriesColor}${activeClass}" style="background: ${item.color}"></div>`;
31
+
32
+ const display = valueFormatter ? valueFormatter(item.value, item) : formatValue(item.value);
33
+
34
+ return `
35
+ ${marker}
36
+ <div class="${styles.statisticsChartTooltipSeriesName}${activeClass}">${translatedName}</div>
37
+ <div class="${styles.statisticsChartTooltipSeriesValue}${activeClass}">${display}</div>
38
+ `;
39
+ }).join('');
40
+
41
+ return `<div class="${styles.statisticsChartTooltip}">${titleHtml}<div class="${styles.statisticsChartTooltipBody}">${body}</div></div>`;
42
+ }
43
+
44
+ export function extractValue(value: TooltipParam['value']): number | string {
45
+ if (Array.isArray(value)) {
46
+ const last = value[value.length - 1];
47
+ return typeof last === 'number' || typeof last === 'string' ? last : '';
48
+ }
49
+
50
+ return value ?? '';
51
+ }
52
+
53
+ export function formatValue(value: TooltipParam['value']): string {
54
+ if (Array.isArray(value)) {
55
+ const last = value[value.length - 1];
56
+ return formatValue(last);
57
+ }
58
+
59
+ if (typeof value === 'number') {
60
+ return Number.isInteger(value)
61
+ ? formatNumber(value)
62
+ : value.toString();
63
+ }
64
+
65
+ return String(value ?? '');
66
+ }
@@ -0,0 +1,29 @@
1
+ import type { FluxIconName } from '@flux-ui/types';
2
+
3
+ export interface TooltipParam {
4
+ readonly seriesName?: string;
5
+ readonly seriesIndex: number;
6
+ readonly color: string;
7
+ readonly value: number | string | (number | string)[];
8
+ readonly name: string;
9
+ readonly dataIndex?: number;
10
+ readonly axisValue?: string;
11
+ readonly axisValueLabel?: string;
12
+ readonly data?: unknown;
13
+ readonly marker?: string;
14
+ }
15
+
16
+ export type TooltipStyleClasses = Readonly<Record<string, string>>;
17
+
18
+ export type Translator = (key: string) => string;
19
+
20
+ export interface SharedTooltipItem {
21
+ readonly name: string;
22
+ readonly value: number | string;
23
+ readonly color: string;
24
+ readonly icon?: FluxIconName;
25
+ readonly seriesIndex?: number;
26
+ readonly dataIndex?: number;
27
+ }
28
+
29
+ export type ChartTooltipValueFormatter = (value: number | string, item: SharedTooltipItem) => string;
@@ -1,76 +0,0 @@
1
- import { FluxIconName } from '@flux-ui/types';
2
- import { EChartsOption } from '../composable';
3
- export interface TooltipParam {
4
- readonly seriesName?: string;
5
- readonly seriesIndex: number;
6
- readonly color: string;
7
- readonly value: number | string | (number | string)[];
8
- readonly name: string;
9
- readonly dataIndex?: number;
10
- readonly axisValue?: string;
11
- readonly axisValueLabel?: string;
12
- readonly data?: unknown;
13
- readonly marker?: string;
14
- }
15
- export type TooltipStyleClasses = {
16
- readonly statisticsChartTooltipTitle: string;
17
- readonly statisticsChartTooltipBody: string;
18
- readonly statisticsChartTooltipSection: string;
19
- readonly statisticsChartTooltipSectionTitle: string;
20
- readonly statisticsChartTooltipSectionBody: string;
21
- readonly statisticsChartTooltipSeriesColor: string;
22
- readonly statisticsChartTooltipSeriesIcon: string;
23
- readonly statisticsChartTooltipSeriesName: string;
24
- readonly statisticsChartTooltipSeriesValue: string;
25
- readonly isActive: string;
26
- readonly isDimmed: string;
27
- };
28
- export type Translator = (key: string) => string;
29
- export interface SharedTooltipItem {
30
- readonly name: string;
31
- readonly value: number | string;
32
- readonly color: string;
33
- readonly icon?: FluxIconName;
34
- readonly seriesIndex?: number;
35
- readonly dataIndex?: number;
36
- }
37
- export type ChartTooltipValueFormatter = (value: number | string, item: SharedTooltipItem) => string;
38
- export declare const CHART_DEFAULT_COLORS: readonly ["var(--chart-1)", "var(--chart-2)", "var(--chart-3)", "var(--chart-4)"];
39
- export declare function buildTooltipFormatter(t: Translator, styles: TooltipStyleClasses, getSeriesIcons?: () => readonly (FluxIconName | undefined)[], valueFormatter?: ChartTooltipValueFormatter): (params: TooltipParam | TooltipParam[]) => string;
40
- export declare function buildCartesianTooltipOptions(t: Translator, styles: TooltipStyleClasses, getSeriesIcons: () => readonly (FluxIconName | undefined)[], valueFormatter?: ChartTooltipValueFormatter): EChartsOption;
41
- export declare function buildSharedItemTooltipFormatter(t: Translator, styles: TooltipStyleClasses, getItems: () => readonly SharedTooltipItem[], getTitle?: () => string | undefined, valueFormatter?: ChartTooltipValueFormatter): (params: TooltipParam | TooltipParam[]) => string;
42
- export interface BoxPlotTooltipPoint {
43
- readonly label?: string;
44
- readonly min: number;
45
- readonly q1: number;
46
- readonly median: number;
47
- readonly q3: number;
48
- readonly max: number;
49
- }
50
- export declare function buildBoxPlotTooltipOptions(t: Translator, styles: TooltipStyleClasses, getSeries: () => readonly {
51
- readonly name?: string;
52
- readonly icon?: FluxIconName;
53
- readonly data: readonly BoxPlotTooltipPoint[];
54
- }[], getPalette: () => readonly string[]): EChartsOption;
55
- export interface HeatmapTooltipPoint {
56
- readonly x: string | number;
57
- readonly y: string | number;
58
- readonly value: number;
59
- readonly formatted?: string;
60
- }
61
- export declare function buildHeatmapTooltipOptions(t: Translator, styles: TooltipStyleClasses, getSeries: () => readonly {
62
- readonly name?: string;
63
- readonly data: readonly HeatmapTooltipPoint[];
64
- }[]): EChartsOption;
65
- export interface TreemapTooltipNode {
66
- readonly name: string;
67
- readonly value?: number;
68
- readonly color?: string;
69
- }
70
- export declare function buildTreemapTooltipOptions(t: Translator, styles: TooltipStyleClasses): EChartsOption;
71
- export declare function buildGaugeTooltipOptions(t: Translator, styles: TooltipStyleClasses, getSeries: () => readonly {
72
- readonly name?: string;
73
- readonly value: number;
74
- readonly icon?: FluxIconName;
75
- }[], getPalette: () => readonly string[]): EChartsOption;
76
- export declare function buildDefaultOptions(): EChartsOption;
@@ -1,398 +0,0 @@
1
- import { formatNumber } from '@basmilius/utils';
2
- import type { FluxIconName } from '@flux-ui/types';
3
- import type { EChartsOption } from '~flux/statistics/composable';
4
- import { renderIconSvg } from './iconSvg';
5
-
6
- export interface TooltipParam {
7
- readonly seriesName?: string;
8
- readonly seriesIndex: number;
9
- readonly color: string;
10
- readonly value: number | string | (number | string)[];
11
- readonly name: string;
12
- readonly dataIndex?: number;
13
- readonly axisValue?: string;
14
- readonly axisValueLabel?: string;
15
- readonly data?: unknown;
16
- readonly marker?: string;
17
- }
18
-
19
- export type TooltipStyleClasses = {
20
- readonly statisticsChartTooltipTitle: string;
21
- readonly statisticsChartTooltipBody: string;
22
- readonly statisticsChartTooltipSection: string;
23
- readonly statisticsChartTooltipSectionTitle: string;
24
- readonly statisticsChartTooltipSectionBody: string;
25
- readonly statisticsChartTooltipSeriesColor: string;
26
- readonly statisticsChartTooltipSeriesIcon: string;
27
- readonly statisticsChartTooltipSeriesName: string;
28
- readonly statisticsChartTooltipSeriesValue: string;
29
- readonly isActive: string;
30
- readonly isDimmed: string;
31
- };
32
-
33
- export type Translator = (key: string) => string;
34
-
35
- export interface SharedTooltipItem {
36
- readonly name: string;
37
- readonly value: number | string;
38
- readonly color: string;
39
- readonly icon?: FluxIconName;
40
- readonly seriesIndex?: number;
41
- readonly dataIndex?: number;
42
- }
43
-
44
- export type ChartTooltipValueFormatter = (value: number | string, item: SharedTooltipItem) => string;
45
-
46
- export const CHART_DEFAULT_COLORS = [
47
- 'var(--chart-1)',
48
- 'var(--chart-2)',
49
- 'var(--chart-3)',
50
- 'var(--chart-4)'
51
- ] as const;
52
-
53
- export function buildTooltipFormatter(
54
- t: Translator,
55
- styles: TooltipStyleClasses,
56
- getSeriesIcons?: () => readonly (FluxIconName | undefined)[],
57
- valueFormatter?: ChartTooltipValueFormatter
58
- ) {
59
- return (params: TooltipParam | TooltipParam[]): string => {
60
- const items = Array.isArray(params) ? params : [params];
61
-
62
- if (items.length === 0) {
63
- return '';
64
- }
65
-
66
- const rawTitle = items[0].axisValueLabel ?? items[0].axisValue ?? items[0].name ?? '';
67
- const title = rawTitle ? t(String(rawTitle)) : '';
68
- const icons = getSeriesIcons?.();
69
-
70
- return renderTooltip(t, styles, title, items.map(param => ({
71
- name: param.seriesName ?? '',
72
- value: extractValue(param.value),
73
- color: param.color,
74
- icon: icons?.[param.seriesIndex],
75
- seriesIndex: param.seriesIndex,
76
- dataIndex: param.dataIndex
77
- })), -1, valueFormatter);
78
- };
79
- }
80
-
81
- export function buildCartesianTooltipOptions(
82
- t: Translator,
83
- styles: TooltipStyleClasses,
84
- getSeriesIcons: () => readonly (FluxIconName | undefined)[],
85
- valueFormatter?: ChartTooltipValueFormatter
86
- ): EChartsOption {
87
- return {
88
- tooltip: {
89
- show: true,
90
- trigger: 'axis',
91
- formatter: buildTooltipFormatter(t, styles, getSeriesIcons, valueFormatter) as never
92
- }
93
- };
94
- }
95
-
96
- export function buildSharedItemTooltipFormatter(
97
- t: Translator,
98
- styles: TooltipStyleClasses,
99
- getItems: () => readonly SharedTooltipItem[],
100
- getTitle?: () => string | undefined,
101
- valueFormatter?: ChartTooltipValueFormatter
102
- ) {
103
- return (params: TooltipParam | TooltipParam[]): string => {
104
- const param = Array.isArray(params) ? params[0] : params;
105
-
106
- if (!param) {
107
- return '';
108
- }
109
-
110
- const items = getItems();
111
- const activeIndex = param.dataIndex ?? -1;
112
- const rawTitle = getTitle?.() ?? '';
113
- const title = rawTitle ? t(String(rawTitle)) : '';
114
-
115
- return renderTooltip(t, styles, title, items, activeIndex, valueFormatter);
116
- };
117
- }
118
-
119
- function renderTooltip(
120
- t: Translator,
121
- styles: TooltipStyleClasses,
122
- title: string,
123
- items: readonly SharedTooltipItem[],
124
- activeIndex: number = -1,
125
- valueFormatter?: ChartTooltipValueFormatter
126
- ): string {
127
- if (items.length === 0) {
128
- return '';
129
- }
130
-
131
- const titleHtml = title
132
- ? `<div class="${styles.statisticsChartTooltipTitle}">${title}</div>`
133
- : '';
134
-
135
- const hasActive = activeIndex !== -1;
136
-
137
- const body = items.map((item, idx) => {
138
- const isActive = !hasActive || idx === activeIndex;
139
- const activeClass = isActive ? ` ${styles.isActive}` : '';
140
- const translatedName = item.name ? t(String(item.name)) : '';
141
-
142
- const marker = item.icon
143
- ? `<div class="${styles.statisticsChartTooltipSeriesIcon}${activeClass}" style="color: ${item.color}">${renderIconSvg(item.icon, item.color, 14)}</div>`
144
- : `<div class="${styles.statisticsChartTooltipSeriesColor}${activeClass}" style="background: ${item.color}"></div>`;
145
-
146
- const display = valueFormatter ? valueFormatter(item.value, item) : formatValue(item.value);
147
-
148
- return `
149
- ${marker}
150
- <div class="${styles.statisticsChartTooltipSeriesName}${activeClass}">${translatedName}</div>
151
- <div class="${styles.statisticsChartTooltipSeriesValue}${activeClass}">${display}</div>
152
- `;
153
- }).join('');
154
-
155
- return `${titleHtml}<div class="${styles.statisticsChartTooltipBody}">${body}</div>`;
156
- }
157
-
158
- function extractValue(value: TooltipParam['value']): number | string {
159
- if (Array.isArray(value)) {
160
- const last = value[value.length - 1];
161
- return typeof last === 'number' || typeof last === 'string' ? last : '';
162
- }
163
-
164
- return value ?? '';
165
- }
166
-
167
- function formatValue(value: TooltipParam['value']): string {
168
- if (Array.isArray(value)) {
169
- const last = value[value.length - 1];
170
- return formatValue(last);
171
- }
172
-
173
- if (typeof value === 'number') {
174
- return Number.isInteger(value)
175
- ? formatNumber(value)
176
- : value.toString();
177
- }
178
-
179
- return String(value ?? '');
180
- }
181
-
182
- export interface BoxPlotTooltipPoint {
183
- readonly label?: string;
184
- readonly min: number;
185
- readonly q1: number;
186
- readonly median: number;
187
- readonly q3: number;
188
- readonly max: number;
189
- }
190
-
191
- export function buildBoxPlotTooltipOptions(
192
- t: Translator,
193
- styles: TooltipStyleClasses,
194
- getSeries: () => readonly { readonly name?: string; readonly icon?: FluxIconName; readonly data: readonly BoxPlotTooltipPoint[] }[],
195
- getPalette: () => readonly string[]
196
- ): EChartsOption {
197
- const formatter = (params: TooltipParam | TooltipParam[]): string => {
198
- const param = Array.isArray(params) ? params[0] : params;
199
-
200
- if (!param) {
201
- return '';
202
- }
203
-
204
- const series = getSeries();
205
- const palette = getPalette();
206
- const seriesIndex = param.seriesIndex ?? 0;
207
- const dataIndex = param.dataIndex ?? 0;
208
- const s = series[seriesIndex];
209
- const point = s?.data[dataIndex];
210
-
211
- if (!s || !point) {
212
- return '';
213
- }
214
-
215
- const color = palette[seriesIndex % palette.length];
216
- const seriesName = s.name ? t(String(s.name)) : '';
217
- const pointLabel = point.label ? t(String(point.label)) : '';
218
- const title = [seriesName, pointLabel].filter(Boolean).join(' — ');
219
-
220
- const items: SharedTooltipItem[] = [
221
- { name: 'Min', value: point.min, color },
222
- { name: 'Q1', value: point.q1, color },
223
- { name: 'Median', value: point.median, color },
224
- { name: 'Q3', value: point.q3, color },
225
- { name: 'Max', value: point.max, color }
226
- ];
227
-
228
- return renderTooltip(t, styles, title, items);
229
- };
230
-
231
- return {
232
- tooltip: {
233
- show: true,
234
- trigger: 'item',
235
- formatter: formatter as never
236
- }
237
- };
238
- }
239
-
240
- export interface HeatmapTooltipPoint {
241
- readonly x: string | number;
242
- readonly y: string | number;
243
- readonly value: number;
244
- readonly formatted?: string;
245
- }
246
-
247
- export function buildHeatmapTooltipOptions(
248
- t: Translator,
249
- styles: TooltipStyleClasses,
250
- getSeries: () => readonly { readonly name?: string; readonly data: readonly HeatmapTooltipPoint[] }[]
251
- ): EChartsOption {
252
- const formatter = (params: TooltipParam | TooltipParam[]): string => {
253
- const param = Array.isArray(params) ? params[0] : params;
254
-
255
- if (!param) {
256
- return '';
257
- }
258
-
259
- const series = getSeries();
260
- const seriesIndex = param.seriesIndex ?? 0;
261
- const dataIndex = param.dataIndex ?? 0;
262
- const s = series[seriesIndex];
263
- const point = s?.data[dataIndex];
264
-
265
- if (!s || !point) {
266
- return '';
267
- }
268
-
269
- const seriesName = s.name ? t(String(s.name)) : '';
270
- const xLabel = t(String(point.x));
271
- const yLabel = t(String(point.y));
272
- const title = [seriesName, `${xLabel} · ${yLabel}`].filter(Boolean).join(' — ');
273
-
274
- const items: SharedTooltipItem[] = [
275
- { name: '', value: point.formatted ?? point.value, color: 'var(--primary-600)' }
276
- ];
277
-
278
- return renderTooltip(t, styles, title, items);
279
- };
280
-
281
- return {
282
- tooltip: {
283
- show: true,
284
- trigger: 'item',
285
- formatter: formatter as never
286
- }
287
- };
288
- }
289
-
290
- export interface TreemapTooltipNode {
291
- readonly name: string;
292
- readonly value?: number;
293
- readonly color?: string;
294
- }
295
-
296
- export function buildTreemapTooltipOptions(
297
- t: Translator,
298
- styles: TooltipStyleClasses
299
- ): EChartsOption {
300
- const formatter = (params: TooltipParam | TooltipParam[]): string => {
301
- const param = Array.isArray(params) ? params[0] : params;
302
-
303
- if (!param) {
304
- return '';
305
- }
306
-
307
- const data = param.data as TreemapTooltipNode | undefined;
308
-
309
- if (!data) {
310
- return '';
311
- }
312
-
313
- const color = data.color ?? 'var(--primary-600)';
314
- const title = data.name ? t(String(data.name)) : '';
315
-
316
- const items: SharedTooltipItem[] = [
317
- { name: '', value: data.value ?? '', color }
318
- ];
319
-
320
- return renderTooltip(t, styles, title, items);
321
- };
322
-
323
- return {
324
- tooltip: {
325
- show: true,
326
- trigger: 'item',
327
- formatter: formatter as never
328
- }
329
- };
330
- }
331
-
332
- export function buildGaugeTooltipOptions(
333
- t: Translator,
334
- styles: TooltipStyleClasses,
335
- getSeries: () => readonly { readonly name?: string; readonly value: number; readonly icon?: FluxIconName }[],
336
- getPalette: () => readonly string[]
337
- ): EChartsOption {
338
- const formatter = (params: TooltipParam | TooltipParam[]): string => {
339
- const param = Array.isArray(params) ? params[0] : params;
340
-
341
- if (!param) {
342
- return '';
343
- }
344
-
345
- const series = getSeries();
346
- const palette = getPalette();
347
- const seriesIndex = param.seriesIndex ?? 0;
348
- const s = series[seriesIndex];
349
-
350
- if (!s) {
351
- return '';
352
- }
353
-
354
- const color = palette[seriesIndex % palette.length];
355
- const title = s.name ? t(String(s.name)) : '';
356
-
357
- const items: SharedTooltipItem[] = [
358
- { name: '', value: s.value, color, icon: s.icon }
359
- ];
360
-
361
- return renderTooltip(t, styles, title, items);
362
- };
363
-
364
- return {
365
- tooltip: {
366
- show: true,
367
- trigger: 'item',
368
- formatter: formatter as never
369
- }
370
- };
371
- }
372
-
373
- export function buildDefaultOptions(): EChartsOption {
374
- return {
375
- color: [
376
- 'var(--chart-1)',
377
- 'var(--chart-2)',
378
- 'var(--chart-3)',
379
- 'var(--chart-4)'
380
- ],
381
- animation: true,
382
- animationDuration: 1000,
383
- animationDurationUpdate: 400,
384
- animationEasing: 'cubicOut',
385
- animationEasingUpdate: 'cubicInOut',
386
- tooltip: {
387
- show: false,
388
- backgroundColor: 'transparent',
389
- borderWidth: 0,
390
- padding: 0,
391
- extraCssText: 'box-shadow: none;',
392
- className: 'flux-statistics-tooltip'
393
- },
394
- legend: {
395
- show: false
396
- }
397
- };
398
- }
File without changes
File without changes
File without changes