@flux-ui/statistics 3.0.0-next.68 → 3.0.0-next.70

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 +917 -517
  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 +13 -13
  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
@@ -19,6 +19,7 @@
19
19
  height: 6px;
20
20
  background: var(--gray-100);
21
21
  border-radius: var(--radius);
22
+ contain: paint;
22
23
  }
23
24
 
24
25
  .statisticsMeterBarValue {
@@ -0,0 +1,36 @@
1
+ .statisticsPercentageBar {
2
+ display: flex;
3
+ flex-flow: column;
4
+ gap: 12px;
5
+ }
6
+
7
+ .statisticsPercentageBarTrack {
8
+ display: flex;
9
+ flex-flow: row nowrap;
10
+ gap: 3px;
11
+ }
12
+
13
+ .statisticsPercentageBarSegment {
14
+ height: 12px;
15
+ border-radius: calc(var(--radius) / 3);
16
+ transition: var(--transition-default);
17
+ transition-property: height, margin, flex-grow, opacity;
18
+ }
19
+
20
+ .statisticsPercentageBarSegment:hover,
21
+ .statisticsPercentageBarSegment.isHovered {
22
+ height: 16px;
23
+ margin-top: -2px;
24
+ margin-bottom: -2px;
25
+ }
26
+
27
+ .statisticsPercentageBarTrack.isHoverActive .statisticsPercentageBarSegment:not(.isHovered):not(:hover) {
28
+ opacity: 0.5;
29
+ }
30
+
31
+ .statisticsPercentageBarTooltip {
32
+ display: flex;
33
+ align-items: center;
34
+ flex-flow: row nowrap;
35
+ gap: 9px;
36
+ }
package/src/util/index.ts CHANGED
@@ -1,7 +1,6 @@
1
- export * from './baseOptions';
2
1
  export * from './colors';
3
- export * from './convert';
4
- export * from './defaultOptions';
5
- export * from './iconSvg';
6
- export * from './seriesDefaults';
7
- export * from './sparklineOptions';
2
+ export * from './icons';
3
+ export * from './options';
4
+ export * from './series';
5
+ export * from './sparkline';
6
+ export * from './tooltips';
@@ -0,0 +1,31 @@
1
+ import type { EChartsOption } from '~flux/statistics/composable';
2
+
3
+ export function buildBaseOptions(): EChartsOption {
4
+ return {
5
+ color: [
6
+ 'var(--chart-1)',
7
+ 'var(--chart-2)',
8
+ 'var(--chart-3)',
9
+ 'var(--chart-4)'
10
+ ],
11
+ animation: true,
12
+ animationDuration: 1000,
13
+ animationDurationUpdate: 400,
14
+ animationEasing: 'cubicOut',
15
+ animationEasingUpdate: 'cubicInOut',
16
+ tooltip: {
17
+ show: false,
18
+ backgroundColor: 'transparent',
19
+ borderWidth: 0,
20
+ padding: 0,
21
+ extraCssText: 'box-shadow: none;',
22
+ axisPointer: {
23
+ appendTo: 'body',
24
+ snap: true
25
+ }
26
+ },
27
+ legend: {
28
+ show: false
29
+ }
30
+ };
31
+ }
@@ -4,7 +4,7 @@ const FOREGROUND_LABEL = { show: true, color: 'var(--foreground-secondary)' } as
4
4
  const HIDDEN_AXIS = { show: false } as const;
5
5
  const DASHED_SPLIT_LINE = { show: true, lineStyle: { type: 'dashed' as const, color: 'var(--gray-200)' } } as const;
6
6
 
7
- interface CartesianBaseConfig {
7
+ export interface CartesianBaseConfig {
8
8
  readonly xAxisType?: 'category' | 'value';
9
9
  readonly yAxisType?: 'value' | 'category';
10
10
  readonly scale?: boolean;
@@ -12,18 +12,19 @@ interface CartesianBaseConfig {
12
12
  readonly xAxisLabels?: boolean;
13
13
  readonly yAxisLabels?: boolean;
14
14
  readonly splitLines?: boolean;
15
+ readonly minPadding?: number;
15
16
  }
16
17
 
17
- export function buildCartesianGrid(xAxisLabels: boolean, yAxisLabels: boolean): EChartsOption['grid'] {
18
+ export function buildCartesianGrid(xAxisLabels: boolean, yAxisLabels: boolean, minPadding: number = 0): EChartsOption['grid'] {
18
19
  if (!xAxisLabels && !yAxisLabels) {
19
- return { left: 0, right: 0, top: 0, bottom: 0, containLabel: false };
20
+ return { left: minPadding, right: minPadding, top: minPadding, bottom: minPadding, containLabel: false };
20
21
  }
21
22
 
22
23
  return {
23
- left: yAxisLabels ? 9 : 0,
24
- right: 9,
25
- top: 9,
26
- bottom: xAxisLabels ? 9 : 0,
24
+ left: yAxisLabels ? 21 : minPadding,
25
+ right: 21,
26
+ top: 21,
27
+ bottom: xAxisLabels ? 21 : minPadding,
27
28
  containLabel: true
28
29
  };
29
30
  }
@@ -32,13 +33,18 @@ export function buildCartesianBaseOptions(config: CartesianBaseConfig = {}): ECh
32
33
  const xAxisLabels = config.xAxisLabels ?? false;
33
34
  const yAxisLabels = config.yAxisLabels ?? false;
34
35
  const showSplitLines = config.splitLines ?? false;
36
+ const minPadding = config.minPadding ?? 0;
35
37
 
36
38
  const xSplitLine = showSplitLines && config.xAxisType === 'value' ? DASHED_SPLIT_LINE : HIDDEN_AXIS;
37
39
  const ySplitLine = showSplitLines && config.yAxisType !== 'category' ? DASHED_SPLIT_LINE : HIDDEN_AXIS;
38
40
 
39
41
  return {
40
- grid: buildCartesianGrid(xAxisLabels, yAxisLabels),
41
- tooltip: { trigger: config.tooltipTrigger ?? 'item' },
42
+ grid: buildCartesianGrid(xAxisLabels, yAxisLabels, minPadding),
43
+ tooltip: {
44
+ appendTo: 'body',
45
+ snap: true,
46
+ trigger: config.tooltipTrigger ?? 'item'
47
+ },
42
48
  xAxis: {
43
49
  type: config.xAxisType ?? 'category',
44
50
  show: true,
@@ -59,16 +65,3 @@ export function buildCartesianBaseOptions(config: CartesianBaseConfig = {}): ECh
59
65
  }
60
66
  };
61
67
  }
62
-
63
- export const POLAR_BASE_OPTIONS: EChartsOption = {
64
- tooltip: { show: false },
65
- xAxis: { show: false },
66
- yAxis: { show: false },
67
- grid: { show: false }
68
- };
69
-
70
- export const SPARKLINE_AXIS_BASE: EChartsOption = {
71
- tooltip: { trigger: 'axis' },
72
- xAxis: { show: false, boundaryGap: false },
73
- yAxis: { show: false, min: 'dataMin', max: 'dataMax' }
74
- };
@@ -0,0 +1,10 @@
1
+ import type { EChartsOption } from '~flux/statistics/composable';
2
+
3
+ export function buildCircularBaseOptions(): EChartsOption {
4
+ return {
5
+ tooltip: { show: false },
6
+ xAxis: { show: false },
7
+ yAxis: { show: false },
8
+ grid: { show: false }
9
+ };
10
+ }
@@ -0,0 +1,44 @@
1
+ import type { FluxStatisticsChartAreaSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { cartesianFallbackLabels, extractLabels, toAreaSeries } from '../../series';
5
+ import type { ChartTooltipValueFormatter, TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface AreaChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartAreaSeries[];
11
+ readonly labels?: readonly string[];
12
+ readonly palette: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
17
+ readonly xAxisLabels?: boolean;
18
+ readonly yAxisLabels?: boolean;
19
+ readonly splitLines?: boolean;
20
+ readonly advancedOptions?: EChartsOption;
21
+ }
22
+
23
+ export function buildAreaChartOptions(input: AreaChartOptionsInput): EChartsOption {
24
+ const {
25
+ series, labels, palette, t, styles,
26
+ tooltip = false, tooltipValueFormatter,
27
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
28
+ advancedOptions = {}
29
+ } = input;
30
+
31
+ const xLabels = labels ?? extractLabels(series) ?? cartesianFallbackLabels(series);
32
+ const base = buildCartesianBaseOptions({ xAxisLabels, yAxisLabels, splitLines });
33
+ const xAxisOverride: EChartsOption = { xAxis: { type: 'category', data: xLabels as string[], boundaryGap: false } };
34
+
35
+ const tooltipOptions: EChartsOption = tooltip
36
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon), valueFormatter: tooltipValueFormatter })
37
+ : { tooltip: { show: false } };
38
+
39
+ const echartsSeries = series.map((s, i) =>
40
+ toAreaSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
41
+ );
42
+
43
+ return merge({}, base, xAxisOverride, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
44
+ }
@@ -0,0 +1,44 @@
1
+ import type { FluxStatisticsChartBarSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { cartesianFallbackLabels, extractLabels, toBarSeries } from '../../series';
5
+ import type { ChartTooltipValueFormatter, TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface BarChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartBarSeries[];
11
+ readonly labels?: readonly string[];
12
+ readonly palette: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
17
+ readonly xAxisLabels?: boolean;
18
+ readonly yAxisLabels?: boolean;
19
+ readonly splitLines?: boolean;
20
+ readonly advancedOptions?: EChartsOption;
21
+ }
22
+
23
+ export function buildBarChartOptions(input: BarChartOptionsInput): EChartsOption {
24
+ const {
25
+ series, labels, palette, t, styles,
26
+ tooltip = false, tooltipValueFormatter,
27
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
28
+ advancedOptions = {}
29
+ } = input;
30
+
31
+ const xLabels = labels ?? extractLabels(series) ?? cartesianFallbackLabels(series);
32
+ const base = buildCartesianBaseOptions({ xAxisLabels, yAxisLabels, splitLines, minPadding: 12 });
33
+ const xAxisOverride: EChartsOption = { xAxis: { type: 'category', data: xLabels as string[] } };
34
+
35
+ const tooltipOptions: EChartsOption = tooltip
36
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon), valueFormatter: tooltipValueFormatter })
37
+ : { tooltip: { show: false } };
38
+
39
+ const echartsSeries = series.map((s, i) =>
40
+ toBarSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
41
+ );
42
+
43
+ return merge({}, base, xAxisOverride, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
44
+ }
@@ -0,0 +1,63 @@
1
+ import type { FluxStatisticsChartBoxPlotSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { toBoxPlotSeries } from '../../series';
5
+ import type { TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildBoxPlotTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface BoxPlotChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartBoxPlotSeries[];
11
+ readonly labels?: readonly string[];
12
+ readonly palette: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly xAxisLabels?: boolean;
17
+ readonly yAxisLabels?: boolean;
18
+ readonly splitLines?: boolean;
19
+ readonly advancedOptions?: EChartsOption;
20
+ }
21
+
22
+ function resolveBoxPlotLabels(
23
+ series: readonly FluxStatisticsChartBoxPlotSeries[],
24
+ labels?: readonly string[]
25
+ ): readonly string[] | undefined {
26
+ if (labels) {
27
+ return labels;
28
+ }
29
+
30
+ for (const s of series) {
31
+ const fromPoints = s.data.map(p => p.label ?? '').filter(Boolean);
32
+ if (fromPoints.length > 0) {
33
+ return s.data.map(p => p.label ?? '');
34
+ }
35
+ }
36
+
37
+ return undefined;
38
+ }
39
+
40
+ export function buildBoxPlotChartOptions(input: BoxPlotChartOptionsInput): EChartsOption {
41
+ const {
42
+ series, labels, palette, t, styles,
43
+ tooltip = false,
44
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
45
+ advancedOptions = {}
46
+ } = input;
47
+
48
+ const xLabels = resolveBoxPlotLabels(series, labels);
49
+ const base = buildCartesianBaseOptions({ xAxisLabels, yAxisLabels, splitLines, minPadding: 12 });
50
+ const xAxisOverride: EChartsOption | undefined = xLabels
51
+ ? { xAxis: { type: 'category', data: xLabels as string[] } }
52
+ : undefined;
53
+
54
+ const tooltipOptions: EChartsOption = tooltip
55
+ ? buildBoxPlotTooltip({ t, styles, getSeries: () => series, getPalette: () => palette })
56
+ : { tooltip: { show: false } };
57
+
58
+ const echartsSeries = series.map((s, i) =>
59
+ toBoxPlotSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
60
+ );
61
+
62
+ return merge({}, base, xAxisOverride ?? {}, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
63
+ }
@@ -0,0 +1,48 @@
1
+ import type { FluxStatisticsChartBubbleSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { toBubbleSeries } from '../../series';
5
+ import type { TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface BubbleChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartBubbleSeries[];
11
+ readonly palette: readonly string[];
12
+ readonly t: Translator;
13
+ readonly styles: TooltipStyleClasses;
14
+ readonly tooltip?: boolean;
15
+ readonly xAxisLabels?: boolean;
16
+ readonly yAxisLabels?: boolean;
17
+ readonly splitLines?: boolean;
18
+ readonly advancedOptions?: EChartsOption;
19
+ }
20
+
21
+ export function buildBubbleChartOptions(input: BubbleChartOptionsInput): EChartsOption {
22
+ const {
23
+ series, palette, t, styles,
24
+ tooltip = false,
25
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
26
+ advancedOptions = {}
27
+ } = input;
28
+
29
+ const base = buildCartesianBaseOptions({
30
+ xAxisType: 'value',
31
+ yAxisType: 'value',
32
+ scale: true,
33
+ xAxisLabels,
34
+ yAxisLabels,
35
+ splitLines,
36
+ minPadding: 12
37
+ });
38
+
39
+ const tooltipOptions: EChartsOption = tooltip
40
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon) })
41
+ : { tooltip: { show: false } };
42
+
43
+ const echartsSeries = series.map((s, i) =>
44
+ toBubbleSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
45
+ );
46
+
47
+ return merge({}, base, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
48
+ }
@@ -0,0 +1,77 @@
1
+ import type { FluxStatisticsChartCandlestickSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { ChartLegendItem } from '~flux/statistics/composable/useChartLegend';
4
+ import type { EChartsOption } from '~flux/statistics/composable/useECharts';
5
+ import { resolveChartColor, toCandlestickSeries } from '../../series';
6
+ import type { TooltipStyleClasses, Translator } from '../../tooltips';
7
+ import { buildCartesianTooltip } from '../../tooltips';
8
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
9
+
10
+ export interface CandlestickChartOptionsInput {
11
+ readonly series: readonly FluxStatisticsChartCandlestickSeries[];
12
+ readonly labels?: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly xAxisLabels?: boolean;
17
+ readonly yAxisLabels?: boolean;
18
+ readonly splitLines?: boolean;
19
+ readonly advancedOptions?: EChartsOption;
20
+ }
21
+
22
+ function resolveCandlestickLabels(
23
+ series: readonly FluxStatisticsChartCandlestickSeries[],
24
+ labels?: readonly string[]
25
+ ): readonly string[] | undefined {
26
+ if (labels) {
27
+ return labels;
28
+ }
29
+
30
+ for (const s of series) {
31
+ const fromPoints = s.data.map(p => p.label ?? '').filter(Boolean);
32
+ if (fromPoints.length > 0) {
33
+ return s.data.map(p => p.label ?? '');
34
+ }
35
+ }
36
+
37
+ return undefined;
38
+ }
39
+
40
+ export function candlestickLegendItemBuilder(s: FluxStatisticsChartCandlestickSeries): readonly ChartLegendItem[] {
41
+ return [
42
+ {
43
+ color: resolveChartColor(s.positiveColor) ?? 'var(--success-500)',
44
+ icon: s.icon,
45
+ label: 'Up'
46
+ },
47
+ {
48
+ color: resolveChartColor(s.negativeColor) ?? 'var(--danger-500)',
49
+ label: 'Down'
50
+ }
51
+ ];
52
+ }
53
+
54
+ export function buildCandlestickChartOptions(input: CandlestickChartOptionsInput): EChartsOption {
55
+ const {
56
+ series, labels, t, styles,
57
+ tooltip = false,
58
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
59
+ advancedOptions = {}
60
+ } = input;
61
+
62
+ const xLabels = resolveCandlestickLabels(series, labels);
63
+ const base = buildCartesianBaseOptions({ scale: true, xAxisLabels, yAxisLabels, splitLines, minPadding: 12 });
64
+ const xAxisOverride: EChartsOption | undefined = xLabels
65
+ ? { xAxis: { type: 'category', data: xLabels as string[] } }
66
+ : undefined;
67
+
68
+ const tooltipOptions: EChartsOption = tooltip
69
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon) })
70
+ : { tooltip: { show: false } };
71
+
72
+ const echartsSeries = series.map(s =>
73
+ toCandlestickSeries({ ...s, name: s.name ? t(String(s.name)) : undefined })
74
+ );
75
+
76
+ return merge({}, base, xAxisOverride ?? {}, tooltipOptions, advancedOptions, { series: echartsSeries });
77
+ }
@@ -0,0 +1,72 @@
1
+ import { blue100, blue300, blue500, blue700 } from '@flux-ui/internals';
2
+ import type { FluxStatisticsChartHeatmapSeries } from '@flux-ui/types';
3
+ import { merge } from 'lodash-es';
4
+ import type { EChartsOption } from '~flux/statistics/composable';
5
+ import { toHeatmapSeries } from '../../series';
6
+ import type { TooltipStyleClasses, Translator } from '../../tooltips';
7
+ import { buildHeatmapTooltip } from '../../tooltips';
8
+ import { buildCartesianGrid } from '../buildCartesianBaseOptions';
9
+
10
+ export interface HeatmapChartOptionsInput {
11
+ readonly series: readonly FluxStatisticsChartHeatmapSeries[];
12
+ readonly xLabels: readonly string[];
13
+ readonly yLabels: readonly string[];
14
+ readonly t: Translator;
15
+ readonly styles: TooltipStyleClasses;
16
+ readonly tooltip?: boolean;
17
+ readonly xAxisLabels?: boolean;
18
+ readonly yAxisLabels?: boolean;
19
+ readonly advancedOptions?: EChartsOption;
20
+ }
21
+
22
+ const HIDDEN = { show: false } as const;
23
+ const labelStyle = (show: boolean) => ({ show, color: 'var(--foreground-secondary)' });
24
+
25
+ export function buildHeatmapChartOptions(input: HeatmapChartOptionsInput): EChartsOption {
26
+ const {
27
+ series, xLabels, yLabels, t, styles,
28
+ tooltip = false,
29
+ xAxisLabels = false, yAxisLabels = false,
30
+ advancedOptions = {}
31
+ } = input;
32
+
33
+ const translatedXLabels = xLabels.map(label => t(String(label)));
34
+ const translatedYLabels = yLabels.map(label => t(String(label)));
35
+
36
+ const base: EChartsOption = {
37
+ grid: buildCartesianGrid(xAxisLabels, yAxisLabels, 12),
38
+ color: [blue500],
39
+ visualMap: {
40
+ show: false,
41
+ min: 0,
42
+ max: 100,
43
+ inRange: { color: [blue100, blue300, blue500, blue700] }
44
+ },
45
+ xAxis: {
46
+ type: 'category',
47
+ data: translatedXLabels as string[],
48
+ axisLabel: labelStyle(xAxisLabels),
49
+ axisLine: HIDDEN,
50
+ axisTick: HIDDEN,
51
+ splitLine: HIDDEN
52
+ },
53
+ yAxis: {
54
+ type: 'category',
55
+ data: translatedYLabels as string[],
56
+ axisLabel: labelStyle(yAxisLabels),
57
+ axisLine: HIDDEN,
58
+ axisTick: HIDDEN,
59
+ splitLine: HIDDEN
60
+ }
61
+ };
62
+
63
+ const tooltipOptions: EChartsOption = tooltip
64
+ ? buildHeatmapTooltip({ t, styles, getSeries: () => series })
65
+ : { tooltip: { show: false } };
66
+
67
+ const echartsSeries = series.map(s =>
68
+ toHeatmapSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, xLabels, yLabels)
69
+ );
70
+
71
+ return merge({}, base, tooltipOptions, advancedOptions, { series: echartsSeries });
72
+ }
@@ -0,0 +1,44 @@
1
+ import type { FluxStatisticsChartLineSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { cartesianFallbackLabels, extractLabels, toLineSeries } from '../../series';
5
+ import type { ChartTooltipValueFormatter, TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface LineChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartLineSeries[];
11
+ readonly labels?: readonly string[];
12
+ readonly palette: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
17
+ readonly xAxisLabels?: boolean;
18
+ readonly yAxisLabels?: boolean;
19
+ readonly splitLines?: boolean;
20
+ readonly advancedOptions?: EChartsOption;
21
+ }
22
+
23
+ export function buildLineChartOptions(input: LineChartOptionsInput): EChartsOption {
24
+ const {
25
+ series, labels, palette, t, styles,
26
+ tooltip = false, tooltipValueFormatter,
27
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
28
+ advancedOptions = {}
29
+ } = input;
30
+
31
+ const xLabels = labels ?? extractLabels(series) ?? cartesianFallbackLabels(series);
32
+ const base = buildCartesianBaseOptions({ xAxisLabels, yAxisLabels, splitLines });
33
+ const xAxisOverride: EChartsOption = { xAxis: { type: 'category', data: xLabels as string[], boundaryGap: false } };
34
+
35
+ const tooltipOptions: EChartsOption = tooltip
36
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon), valueFormatter: tooltipValueFormatter })
37
+ : { tooltip: { show: false } };
38
+
39
+ const echartsSeries = series.map((s, i) =>
40
+ toLineSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
41
+ );
42
+
43
+ return merge({}, base, xAxisOverride, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
44
+ }
@@ -0,0 +1,44 @@
1
+ import type { FluxStatisticsChartMixedSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { cartesianFallbackLabels, extractLabels, toMixedSeries } from '../../series';
5
+ import type { ChartTooltipValueFormatter, TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface MixedChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartMixedSeries[];
11
+ readonly labels?: readonly string[];
12
+ readonly palette: readonly string[];
13
+ readonly t: Translator;
14
+ readonly styles: TooltipStyleClasses;
15
+ readonly tooltip?: boolean;
16
+ readonly tooltipValueFormatter?: ChartTooltipValueFormatter;
17
+ readonly xAxisLabels?: boolean;
18
+ readonly yAxisLabels?: boolean;
19
+ readonly splitLines?: boolean;
20
+ readonly advancedOptions?: EChartsOption;
21
+ }
22
+
23
+ export function buildMixedChartOptions(input: MixedChartOptionsInput): EChartsOption {
24
+ const {
25
+ series, labels, palette, t, styles,
26
+ tooltip = false, tooltipValueFormatter,
27
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
28
+ advancedOptions = {}
29
+ } = input;
30
+
31
+ const xLabels = labels ?? extractLabels(series) ?? cartesianFallbackLabels(series);
32
+ const base = buildCartesianBaseOptions({ tooltipTrigger: 'axis', xAxisLabels, yAxisLabels, splitLines, minPadding: 12 });
33
+ const xAxisOverride: EChartsOption = { xAxis: { type: 'category', data: xLabels as string[] } };
34
+
35
+ const tooltipOptions: EChartsOption = tooltip
36
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon), valueFormatter: tooltipValueFormatter })
37
+ : { tooltip: { show: false } };
38
+
39
+ const echartsSeries = series.map((s, i) =>
40
+ toMixedSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
41
+ );
42
+
43
+ return merge({}, base, xAxisOverride, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
44
+ }
@@ -0,0 +1,48 @@
1
+ import type { FluxStatisticsChartScatterSeries } from '@flux-ui/types';
2
+ import { merge } from 'lodash-es';
3
+ import type { EChartsOption } from '~flux/statistics/composable';
4
+ import { toScatterSeries } from '../../series';
5
+ import type { TooltipStyleClasses, Translator } from '../../tooltips';
6
+ import { buildCartesianTooltip } from '../../tooltips';
7
+ import { buildCartesianBaseOptions } from '../buildCartesianBaseOptions';
8
+
9
+ export interface ScatterChartOptionsInput {
10
+ readonly series: readonly FluxStatisticsChartScatterSeries[];
11
+ readonly palette: readonly string[];
12
+ readonly t: Translator;
13
+ readonly styles: TooltipStyleClasses;
14
+ readonly tooltip?: boolean;
15
+ readonly xAxisLabels?: boolean;
16
+ readonly yAxisLabels?: boolean;
17
+ readonly splitLines?: boolean;
18
+ readonly advancedOptions?: EChartsOption;
19
+ }
20
+
21
+ export function buildScatterChartOptions(input: ScatterChartOptionsInput): EChartsOption {
22
+ const {
23
+ series, palette, t, styles,
24
+ tooltip = false,
25
+ xAxisLabels = false, yAxisLabels = false, splitLines = false,
26
+ advancedOptions = {}
27
+ } = input;
28
+
29
+ const base = buildCartesianBaseOptions({
30
+ xAxisType: 'value',
31
+ yAxisType: 'value',
32
+ scale: true,
33
+ xAxisLabels,
34
+ yAxisLabels,
35
+ splitLines,
36
+ minPadding: 12
37
+ });
38
+
39
+ const tooltipOptions: EChartsOption = tooltip
40
+ ? buildCartesianTooltip({ t, styles, getSeriesIcons: () => series.map(s => s.icon) })
41
+ : { tooltip: { show: false } };
42
+
43
+ const echartsSeries = series.map((s, i) =>
44
+ toScatterSeries({ ...s, name: s.name ? t(String(s.name)) : undefined }, palette[i])
45
+ );
46
+
47
+ return merge({}, base, tooltipOptions, advancedOptions, { series: echartsSeries, color: palette });
48
+ }