@tsingroc/tsingroc-components 5.0.0-alpha.10 → 5.0.0-alpha.12

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 (140) hide show
  1. package/dist/components/Auth.d.ts +310 -0
  2. package/dist/components/Auth.js +267 -0
  3. package/dist/components/AutoResizedECharts.d.ts +21 -0
  4. package/dist/components/AutoResizedECharts.js +98 -0
  5. package/dist/components/Calendar.d.ts +50 -0
  6. package/dist/components/Calendar.js +130 -0
  7. package/dist/components/CircularProgress.d.ts +21 -0
  8. package/dist/components/CircularProgress.js +34 -0
  9. package/dist/components/ConnectedECharts.d.ts +31 -0
  10. package/dist/components/ConnectedECharts.js +100 -0
  11. package/dist/components/ECharts.d.ts +57 -0
  12. package/dist/components/ECharts.js +255 -0
  13. package/dist/components/Header.d.ts +67 -0
  14. package/dist/components/Header.js +171 -0
  15. package/dist/components/ImageBackground.d.ts +32 -0
  16. package/dist/components/ImageBackground.js +76 -0
  17. package/dist/components/IndicatorLight.d.ts +44 -0
  18. package/dist/components/IndicatorLight.js +124 -0
  19. package/dist/components/LeftAlignedECharts.d.ts +42 -0
  20. package/dist/components/LeftAlignedECharts.js +270 -0
  21. package/dist/components/LineChartEditor.d.ts +74 -0
  22. package/dist/components/LineChartEditor.js +458 -0
  23. package/dist/components/LineChartTable.d.ts +38 -0
  24. package/dist/components/LineChartTable.js +245 -0
  25. package/dist/components/LinkedLineChart.d.ts +45 -0
  26. package/dist/components/LinkedLineChart.js +159 -0
  27. package/dist/components/QuickDateRangePicker.d.ts +30 -0
  28. package/dist/components/QuickDateRangePicker.js +58 -0
  29. package/dist/components/SegmentedButtons.d.ts +22 -0
  30. package/dist/components/SegmentedButtons.js +86 -0
  31. package/dist/components/Sidebar.d.ts +79 -0
  32. package/dist/components/Sidebar.js +178 -0
  33. package/dist/components/TsingrocDatePicker.d.ts +38 -0
  34. package/dist/components/TsingrocDatePicker.js +64 -0
  35. package/dist/components/TsingrocTheme.d.ts +15 -0
  36. package/dist/components/TsingrocTheme.js +72 -0
  37. package/dist/components/UserButton.d.ts +42 -0
  38. package/dist/components/UserButton.js +105 -0
  39. package/dist/components/VerticalColorLegend.d.ts +7 -0
  40. package/dist/components/VerticalColorLegend.js +208 -0
  41. package/dist/components/WeatherMap.d.ts +18 -0
  42. package/dist/components/WeatherMap.js +658 -0
  43. package/dist/deckgl/TiandituLayer.d.ts +13 -0
  44. package/dist/deckgl/TiandituLayer.js +44 -0
  45. package/dist/deckgl/WeatherData.d.ts +53 -0
  46. package/dist/deckgl/WeatherData.js +94 -0
  47. package/dist/deckgl/index.d.ts +1 -0
  48. package/dist/deckgl/index.js +1 -0
  49. package/dist/echarts/coordinateSystems/grid.d.ts +43 -0
  50. package/dist/echarts/coordinateSystems/grid.js +107 -0
  51. package/dist/echarts/coordinateSystems/index.js +2 -0
  52. package/dist/echarts/coordinateSystems/polar.d.ts +45 -0
  53. package/dist/echarts/coordinateSystems/polar.js +96 -0
  54. package/dist/echarts/gl-types.d.js +0 -0
  55. package/dist/echarts/gl.d.ts +115 -0
  56. package/dist/echarts/gl.js +47 -0
  57. package/dist/echarts/index.d.ts +46 -0
  58. package/dist/echarts/index.js +46 -0
  59. package/dist/echarts/legend.d.ts +17 -0
  60. package/dist/echarts/legend.js +15 -0
  61. package/dist/echarts/radar.d.ts +24 -0
  62. package/dist/echarts/radar.js +22 -0
  63. package/dist/echarts/series/barSeries.d.ts +23 -0
  64. package/dist/echarts/series/barSeries.js +18 -0
  65. package/dist/echarts/series/boxplotSeries.d.ts +21 -0
  66. package/dist/echarts/series/boxplotSeries.js +40 -0
  67. package/dist/echarts/series/index.js +7 -0
  68. package/dist/echarts/series/intervalSeries.d.ts +32 -0
  69. package/dist/echarts/series/intervalSeries.js +55 -0
  70. package/dist/echarts/series/lineSeries.d.ts +36 -0
  71. package/dist/echarts/series/lineSeries.js +45 -0
  72. package/dist/echarts/series/maxBarSeries.d.ts +18 -0
  73. package/dist/echarts/series/maxBarSeries.js +39 -0
  74. package/dist/echarts/series/pieSeries.d.ts +31 -0
  75. package/dist/echarts/series/pieSeries.js +47 -0
  76. package/dist/echarts/series/windLineSeries.d.ts +47 -0
  77. package/dist/echarts/series/windLineSeries.js +51 -0
  78. package/{src/echarts/tooltip.ts → dist/echarts/tooltip.d.ts} +1 -5
  79. package/dist/echarts/tooltip.js +18 -0
  80. package/dist/env.d.js +0 -0
  81. package/dist/index.d.ts +20 -0
  82. package/dist/index.js +20 -0
  83. package/dist/utils/debug.d.ts +1 -0
  84. package/dist/utils/debug.js +25 -0
  85. package/dist/utils/index.d.ts +4 -0
  86. package/dist/utils/index.js +4 -0
  87. package/dist/utils/math.d.ts +9 -0
  88. package/{src/utils/math.ts → dist/utils/math.js} +2 -2
  89. package/dist/utils/mock.d.ts +8 -0
  90. package/dist/utils/mock.js +40 -0
  91. package/dist/utils/startOfQuarter.d.ts +2 -0
  92. package/dist/utils/startOfQuarter.js +4 -0
  93. package/package.json +26 -14
  94. package/src/components/Auth.tsx +0 -623
  95. package/src/components/AutoResizedECharts.tsx +0 -70
  96. package/src/components/Calendar.tsx +0 -182
  97. package/src/components/CircularProgress.tsx +0 -38
  98. package/src/components/ConnectedECharts.tsx +0 -62
  99. package/src/components/ECharts.tsx +0 -206
  100. package/src/components/Header.tsx +0 -136
  101. package/src/components/ImageBackground.tsx +0 -58
  102. package/src/components/IndicatorLight.tsx +0 -106
  103. package/src/components/LeftAlignedECharts.tsx +0 -190
  104. package/src/components/LineChartEditor.tsx +0 -558
  105. package/src/components/LineChartTable.tsx +0 -286
  106. package/src/components/LinkedECharts.tsx +0 -51
  107. package/src/components/LinkedLineChart.tsx +0 -144
  108. package/src/components/QuickDateRangePicker.tsx +0 -84
  109. package/src/components/SegmentedButtons.tsx +0 -46
  110. package/src/components/Sidebar.tsx +0 -271
  111. package/src/components/StrictECharts.d.ts +0 -47
  112. package/src/components/StrictECharts.js +0 -1
  113. package/src/components/TsingrocDatePicker.tsx +0 -103
  114. package/src/components/TsingrocTheme.tsx +0 -48
  115. package/src/components/UserButton.tsx +0 -165
  116. package/src/components/VerticalColorLegend.tsx +0 -73
  117. package/src/components/WeatherMap.tsx +0 -522
  118. package/src/deckgl/TiandituLayer.ts +0 -56
  119. package/src/deckgl/WeatherData.ts +0 -157
  120. package/src/deckgl/index.ts +0 -4
  121. package/src/echarts/coordinateSystems/grid.ts +0 -143
  122. package/src/echarts/coordinateSystems/polar.ts +0 -148
  123. package/src/echarts/gl.ts +0 -159
  124. package/src/echarts/index.ts +0 -129
  125. package/src/echarts/legend.ts +0 -36
  126. package/src/echarts/radar.ts +0 -46
  127. package/src/echarts/series/barSeries.ts +0 -37
  128. package/src/echarts/series/boxplotSeries.ts +0 -62
  129. package/src/echarts/series/intervalSeries.ts +0 -70
  130. package/src/echarts/series/lineSeries.ts +0 -78
  131. package/src/echarts/series/maxBarSeries.ts +0 -55
  132. package/src/echarts/series/pieSeries.ts +0 -76
  133. package/src/echarts/series/windLineSeries.ts +0 -113
  134. package/src/index.ts +0 -118
  135. package/src/types.d.ts +0 -5
  136. package/src/utils/debug.ts +0 -39
  137. package/src/utils/mock.ts +0 -69
  138. package/src/utils/startOfQuarter.ts +0 -6
  139. /package/{src/echarts/coordinateSystems/index.ts → dist/echarts/coordinateSystems/index.d.ts} +0 -0
  140. /package/{src/echarts/series/index.ts → dist/echarts/series/index.d.ts} +0 -0
@@ -1,129 +0,0 @@
1
- import type {
2
- AngleAxisComponentOption,
3
- AxisPointerComponentOption,
4
- Color,
5
- DataZoomComponentOption,
6
- EChartsOption,
7
- GraphicComponentOption,
8
- GridComponentOption,
9
- LegendComponentOption,
10
- PolarComponentOption,
11
- RadarComponentOption,
12
- RadiusAxisComponentOption,
13
- SeriesOption,
14
- TooltipComponentOption,
15
- XAXisComponentOption,
16
- YAXisComponentOption,
17
- } from "echarts";
18
- import { useMemo } from "react";
19
-
20
- export * from "./coordinateSystems";
21
- export * from "./radar";
22
- export * from "./legend";
23
- export * from "./tooltip";
24
- export * from "./series";
25
-
26
- /** 一个可组合的 ECharts 组件。*/
27
- export interface EChartsComponent {
28
- grid?: GridComponentOption[];
29
- xAxis?: XAXisComponentOption[];
30
- yAxis?: YAXisComponentOption[];
31
- polar?: PolarComponentOption[];
32
- angleAxis?: AngleAxisComponentOption[];
33
- radiusAxis?: RadiusAxisComponentOption[];
34
- radar?: RadarComponentOption[];
35
- legend?: LegendComponentOption[];
36
- tooltip?: TooltipComponentOption[];
37
- axisPointer?: AxisPointerComponentOption[];
38
- dataZoom?: DataZoomComponentOption[];
39
- graphic?: GraphicComponentOption[];
40
- series?: SeriesOption[];
41
- }
42
-
43
- /** 一个 ECharts 系列。*/
44
- export interface EChartsSeries<T = SeriesOption> {
45
- series: T[];
46
- }
47
-
48
- /** ECharts 中不可组合的设置项。*/
49
- export interface EChartsNonComposableOption {
50
- color?: Color[];
51
- backgroundColor?: string;
52
- }
53
-
54
- export type DataItem = number | string | Date | undefined;
55
-
56
- /**
57
- * 第一个参数 `base` 中可以填入不可组合的 ECharts 配置项,例如 `color`。
58
- * 剩余的参数就是需要组合的各个 ECharts 组件。
59
- */
60
- export function buildEChartsOption(
61
- base: EChartsNonComposableOption,
62
- ...components: EChartsComponent[]
63
- ) {
64
- const option: EChartsComponent & EChartsNonComposableOption = { ...base };
65
- for (const component of components) {
66
- Object.entries(component).forEach(([k, value]) => {
67
- const key = k as keyof EChartsComponent;
68
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
69
- (option[key] ??= []).push(...(value ?? []));
70
- });
71
- }
72
- return option as EChartsOption;
73
- }
74
-
75
- /**
76
- * 用组件组合出 ECharts 的配置对象,并将其缓存以减少重渲染。
77
- *
78
- * **注意**:该优化只有在传入的每个组件都已经分别被缓存的情况下才有效!
79
- * 如果不需要细粒度的记忆化,可以直接将所有组件和 `buildEChartsOption`
80
- * 整个用 `useMemo` 包裹起来。
81
- */
82
- export function useMemoizedEChartsOption(
83
- base: EChartsNonComposableOption,
84
- ...components: EChartsComponent[]
85
- ) {
86
- return useMemo(
87
- () => buildEChartsOption(base, ...components),
88
- components, // eslint-disable-line react-hooks/exhaustive-deps
89
- );
90
- }
91
-
92
- // 一些零散工具
93
-
94
- /** 一个从 01:00 到 24:00 的数组,可以在等待数据加载时填充 X 轴。*/
95
- export const HOURS_OF_DAY = Array.from(
96
- { length: 24 },
97
- (_, index) => (index + 1).toString().padStart(2, "0") + ":00",
98
- );
99
-
100
- /** 虚线图标,可用于图例。*/
101
- export const DASHES_ICON: string =
102
- "path://M304.43 532.76H221.4c-11.47 0-20.76-9.3-20.76-20.76s9.29-20.76 20.76-20.76h83.03c11.47 0 20.76 9.3 20.76 20.76s-9.29 20.76-20.76 20.76zM581.19 532.76H442.81c-11.47 0-20.76-9.3-20.76-20.76s9.29-20.76 20.76-20.76h138.38c11.47 0 20.76 9.3 20.76 20.76s-9.3 20.76-20.76 20.76zM802.59 532.76h-83.03c-11.47 0-20.76-9.3-20.76-20.76s9.29-20.76 20.76-20.76h83.03c11.47 0 20.76 9.3 20.76 20.76s-9.29 20.76-20.76 20.76z";
103
-
104
- /** 公用调色板 1。*/
105
- export const PALETTE_1 = [
106
- "#2FDAFF",
107
- "#77DA9B",
108
- "#FFB82E",
109
- "#5470C6",
110
- "#91CC75",
111
- "#FAC858",
112
- "#EE6666",
113
- "#73C0DE",
114
- "#3BA272",
115
- "#FC8452",
116
- "#9A60B4",
117
- "#EA7CCC",
118
- ];
119
-
120
- /** 公用调色板 2。*/
121
- export const PALETTE_2 = [
122
- "#ECA926",
123
- "#32ADF4",
124
- "#DC7756",
125
- "#62CE89",
126
- "#4256B9",
127
- "#00D0FF",
128
- "#96D0DD",
129
- ];
@@ -1,36 +0,0 @@
1
- import type { LegendComponentOption } from "echarts";
2
-
3
- import type { EChartsComponent } from ".";
4
-
5
- export type LegendDataItem = Exclude<
6
- (LegendComponentOption["data"] & {})[0],
7
- string
8
- >;
9
-
10
- export interface LegendOption {
11
- /**
12
- * 图例中要显示的系列或数据项。
13
- */
14
- data: (string | LegendDataItem)[];
15
- /**
16
- * 其它图例设置项,参见 [ECharts 文档][1]。
17
- *
18
- * [1]: https://echarts.apache.org/zh/option.html#legend
19
- */
20
- option?: LegendComponentOption;
21
- }
22
-
23
- /** 添加一个图例。 */
24
- export function legend(option: LegendOption): EChartsComponent {
25
- return {
26
- legend: [
27
- {
28
- top: 0,
29
- right: 0,
30
- padding: 0,
31
- data: option.data,
32
- ...option.option,
33
- },
34
- ],
35
- };
36
- }
@@ -1,46 +0,0 @@
1
- import type { RadarComponentOption, RadarSeriesOption } from "echarts";
2
-
3
- import type { EChartsComponent } from ".";
4
-
5
- export interface RadarOption {
6
- /** 名称,不可与其它组件和系列重名。*/
7
- name: string;
8
- /** 雷达图的各维度。*/
9
- dimensions: RadarComponentOption["indicator"] & {};
10
- /** 雷达图的数据。*/
11
- data: RadarSeriesOption["data"] & {};
12
- /**
13
- * 其它传递给雷达图组件的设置项,参见 [ECharts 文档][1]。
14
- *
15
- * [1]: https://echarts.apache.org/zh/option.html#radar
16
- */
17
- option?: RadarComponentOption;
18
- /**
19
- * 其它传递给雷达系列的设置项,参见 [ECharts 文档][1]。
20
- *
21
- * [1]: https://echarts.apache.org/zh/option.html#series-radar
22
- */
23
- series?: RadarSeriesOption;
24
- }
25
-
26
- /** 添加一张雷达图。*/
27
- export function radar(option: RadarOption): EChartsComponent {
28
- return {
29
- radar: [
30
- {
31
- id: option.name + "-radar",
32
- indicator: option.dimensions,
33
- ...option.option,
34
- },
35
- ],
36
- series: [
37
- {
38
- type: "radar",
39
- name: option.name,
40
- radarId: option.name + "-radar",
41
- data: option.data,
42
- ...option.series,
43
- },
44
- ],
45
- };
46
- }
@@ -1,37 +0,0 @@
1
- import type { BarSeriesOption as OrigBarSeriesOption } from "echarts";
2
-
3
- import type { DataItem, EChartsSeries } from "..";
4
-
5
- export interface BarSeriesOption {
6
- /** 系列名称,不可与其他系列重名。*/
7
- name: string;
8
- /**
9
- * 条形的数据。
10
- *
11
- * 数据的结构是二维数组,每一行表示一个数据点,第一、第二列分别代表两个轴。
12
- * 若两个轴中有且只有一个是类目轴,则数据类型可以是一维数组,表示另一个轴的值。
13
- */
14
- data: [DataItem, DataItem, ...DataItem[]][] | DataItem[];
15
- /**
16
- * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
17
- *
18
- * [1]: https://echarts.apache.org/zh/option.html#series-bar
19
- */
20
- option?: OrigBarSeriesOption;
21
- }
22
-
23
- /**
24
- * 在坐标系上添加一组条形图。
25
- */
26
- export function barSeries(
27
- option: BarSeriesOption,
28
- ): EChartsSeries<OrigBarSeriesOption> {
29
- const series: OrigBarSeriesOption = {
30
- type: "bar",
31
- id: option.name,
32
- name: option.name,
33
- data: option.data,
34
- ...option.option,
35
- };
36
- return { series: [series] };
37
- }
@@ -1,62 +0,0 @@
1
- import type { BoxplotSeriesOption as OrigBoxplotSeriesOption } from "echarts";
2
-
3
- import type { EChartsSeries } from "..";
4
-
5
- export interface BoxplotSeriesOption {
6
- /** 系列名称,不可与其他系列重名。*/
7
- name: string;
8
- /** 箱线图的数据,每一行按顺序分别是最小值、下四分位数、中位数、上四分位数、最大值。*/
9
- data: [number, number, number, number, number][];
10
- /**
11
- * 每个数据值的格式化函数。
12
- * @default (value) => value.toFixed(2)
13
- */
14
- valueFormatter?: (value: number) => string;
15
- /**
16
- * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
17
- *
18
- * [1]: https://echarts.apache.org/zh/option.html#series-boxplot
19
- */
20
- option?: OrigBoxplotSeriesOption;
21
- }
22
-
23
- /** 在坐标系上添加一组箱线图。*/
24
- export function boxplotSeries(
25
- option: BoxplotSeriesOption,
26
- ): EChartsSeries<OrigBoxplotSeriesOption> {
27
- const valueFormatter = option.valueFormatter ?? ((value) => value.toFixed(2));
28
- const series: OrigBoxplotSeriesOption = {
29
- type: "boxplot",
30
- id: option.name,
31
- name: option.name,
32
- data: option.data,
33
- ...option.option,
34
- tooltip: {
35
- formatter: (param) => {
36
- // prettier-ignore
37
- const data = param.data as (
38
- [number | string, number, number, number, number, number]
39
- );
40
- const strong = (body: string) =>
41
- `<strong style="text-align: right;">${body}</strong>`;
42
- // TODO i18n
43
- return `
44
- ${param.name}<br>
45
- <div style="
46
- display: inline-grid;
47
- grid: auto-flow / auto auto;
48
- gap: 0 20px;
49
- ">
50
- 最大值 ${strong(valueFormatter(data[5]))}
51
- 上四分位数 ${strong(valueFormatter(data[4]))}
52
- 中位数 ${strong(valueFormatter(data[3]))}
53
- 下四分位数 ${strong(valueFormatter(data[2]))}
54
- 最小值 ${strong(valueFormatter(data[1]))}
55
- </div>
56
- `;
57
- },
58
- ...option.option?.tooltip,
59
- },
60
- };
61
- return { series: [series] };
62
- }
@@ -1,70 +0,0 @@
1
- import type { Color, LineSeriesOption as OrigLineSeriesOption } from "echarts";
2
-
3
- import type { EChartsSeries } from "..";
4
-
5
- export interface IntervalSeriesOption {
6
- /** 系列名称,不可与其他系列重名。*/
7
- name: string;
8
- /**
9
- * 区间的下边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
10
- *
11
- * [1]: https://echarts.apache.org/zh/option.html#series-line
12
- */
13
- min: OrigLineSeriesOption & { data: number[] };
14
- /**
15
- * 区间的上边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
16
- *
17
- * [1]: https://echarts.apache.org/zh/option.html#series-line
18
- */
19
- max: OrigLineSeriesOption & { data: number[] };
20
- /**
21
- * 区间条带,此处必须设置一个颜色。其它设置参见 [ECharts 文档][1]。
22
- *
23
- * [1]: https://echarts.apache.org/zh/option.html#series-line
24
- */
25
- interval: OrigLineSeriesOption & { color: Color };
26
- }
27
-
28
- const INTERVAL_SERIES_DEFAULTS: OrigLineSeriesOption = {
29
- type: "line",
30
- smooth: true,
31
- showSymbol: false,
32
- lineStyle: { opacity: 0 },
33
- emphasis: { disabled: true },
34
- };
35
-
36
- /** 绘制一个从下边界到上边界的带状区间。*/
37
- export function intervalSeries(
38
- option: IntervalSeriesOption,
39
- ): EChartsSeries<OrigLineSeriesOption> {
40
- // TODO i18n
41
- const min: OrigLineSeriesOption = {
42
- id: option.name + "下边界",
43
- name: option.name + "下边界",
44
- stack: option.name,
45
- ...INTERVAL_SERIES_DEFAULTS,
46
- ...option.min,
47
- };
48
- const max: OrigLineSeriesOption = {
49
- id: option.name + "上边界",
50
- name: option.name + "上边界",
51
- ...INTERVAL_SERIES_DEFAULTS,
52
- ...option.max,
53
- };
54
- const interval: OrigLineSeriesOption = {
55
- id: option.name,
56
- name: option.name,
57
- stack: option.name,
58
- stackStrategy: "all",
59
- symbol: "none",
60
- data: Array.from(
61
- { length: option.min.data.length },
62
- (_, i) => option.max.data[i] - option.min.data[i],
63
- ),
64
- ...INTERVAL_SERIES_DEFAULTS,
65
- ...option.interval,
66
- tooltip: { show: false, ...option.interval.tooltip },
67
- areaStyle: { color: option.interval.color, ...option.interval.areaStyle },
68
- };
69
- return { series: [min, interval, max] };
70
- }
@@ -1,78 +0,0 @@
1
- import type { LineSeriesOption as OrigLineSeriesOption } from "echarts";
2
-
3
- import type { DataItem, EChartsSeries } from "..";
4
-
5
- export type LineSeriesPreset = (option: OrigLineSeriesOption) => void;
6
-
7
- export interface LineSeriesOption {
8
- /** 系列名称,不可与其他系列重名。*/
9
- name: string;
10
- /**
11
- * 折线的数据。
12
- *
13
- * 数据的结构是二维数组,每一行表示一个数据点,第一、第二列分别代表两个轴。
14
- * 若两个轴中有且只有一个是类目轴,则数据类型可以是一维数组,表示另一个轴的值。
15
- */
16
- data: [DataItem, DataItem, ...DataItem[]][] | DataItem[];
17
- /**
18
- * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
19
- *
20
- * [1]: https://echarts.apache.org/zh/option.html#series-line
21
- */
22
- option?: OrigLineSeriesOption;
23
- /**
24
- * 需要应用的配置预设。预设的优先级**高于** `option`。
25
- *
26
- * 可用的预设:{@linkcode gradientArea}
27
- */
28
- presets?: LineSeriesPreset[];
29
- }
30
-
31
- /**
32
- * 在坐标系上添加一条折线。
33
- */
34
- export function lineSeries(
35
- option: LineSeriesOption,
36
- ): EChartsSeries<OrigLineSeriesOption> {
37
- const series: OrigLineSeriesOption = {
38
- type: "line",
39
- id: option.name,
40
- name: option.name,
41
- data: option.data,
42
- smooth: true,
43
- showSymbol: false,
44
- ...option.option,
45
- };
46
- option.presets?.forEach((preset) => preset(series));
47
- return { series: [series] };
48
- }
49
-
50
- /**
51
- * 折线图预设,使折线下方区域在纵向呈现线性渐变色。
52
- *
53
- * 参数 `top` 表示顶部颜色;参数 `bottom` 表示底部颜色,默认为全透明 `"transparent"`。
54
- */
55
- export function gradientArea(
56
- top: string,
57
- bottom: string = "transparent",
58
- ): LineSeriesPreset {
59
- return (option) => {
60
- (option.areaStyle ??= {}).color = {
61
- type: "linear",
62
- x: 0,
63
- y: 0,
64
- x2: 0,
65
- y2: 1,
66
- colorStops: [
67
- {
68
- offset: 0,
69
- color: top,
70
- },
71
- {
72
- offset: 1,
73
- color: bottom,
74
- },
75
- ],
76
- };
77
- };
78
- }
@@ -1,55 +0,0 @@
1
- import type { Color, BarSeriesOption as OrigBarSeriesOption } from "echarts";
2
-
3
- import type { EChartsSeries } from "..";
4
-
5
- export interface MaxBarSeriesOption {
6
- /** 系列名称,不可与其他系列重名。*/
7
- name: string;
8
- /** 需要求最大值的各个系列的数据。*/
9
- data: (number | undefined)[][];
10
- /** 各个系列的颜色,各个最大值条形将被设为对应的颜色。若留空,则使用默认颜色。*/
11
- palette?: Color[];
12
- /**
13
- * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
14
- *
15
- * [1]: https://echarts.apache.org/zh/option.html#series-bar
16
- */
17
- option?: OrigBarSeriesOption;
18
- }
19
-
20
- /** 求出多个系列的最大值,显示为条形图。*/
21
- export function maxBarSeries(
22
- option: MaxBarSeriesOption,
23
- ): EChartsSeries<OrigBarSeriesOption> {
24
- const series: OrigBarSeriesOption = {
25
- type: "bar",
26
- id: option.name,
27
- name: option.name,
28
- data: Array.from({ length: option.data[0].length }, (_, i) => {
29
- // prettier-ignore
30
- const [max, maxJ] = option.data
31
- .map((series) => series[i])
32
- .reduce<[number | undefined, number]>(
33
- ([max, maxJ], y, j) =>
34
- max === undefined || (y !== undefined && y > max)
35
- ? [y, j]
36
- : [max, maxJ],
37
- [undefined, -1]
38
- );
39
- if (max !== undefined && option.palette) {
40
- return {
41
- value: max,
42
- itemStyle: {
43
- color: option.palette[maxJ],
44
- },
45
- };
46
- } else {
47
- return max;
48
- }
49
- }),
50
- ...option.option,
51
- itemStyle: { opacity: 0.7, ...option.option?.itemStyle },
52
- tooltip: { show: false, ...option.option?.tooltip },
53
- };
54
- return { series: [series] };
55
- }
@@ -1,76 +0,0 @@
1
- import type { PieSeriesOption as OrigPieSeriesOption } from "echarts";
2
-
3
- import type { EChartsSeries } from "..";
4
-
5
- /** 饼图的数据项。*/
6
- export type PieDataItem = (OrigPieSeriesOption["data"] & {})[0] extends
7
- | number
8
- | string
9
- | unknown[]
10
- | infer T
11
- ? T
12
- : never;
13
-
14
- export type PieSeriesPreset = (option: OrigPieSeriesOption) => void;
15
-
16
- export interface PieSeriesOption {
17
- /** 系列名称,不可与其他系列重名。*/
18
- name: string;
19
- /** 饼图的数据,数组元素可以是单个数值或者一个对象。*/
20
- data: (number | PieDataItem)[];
21
- /**
22
- * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
23
- *
24
- * [1]: https://echarts.apache.org/zh/option.html#series-pie
25
- */
26
- option?: OrigPieSeriesOption;
27
- /**
28
- * 需要应用的配置预设。预设的优先级**高于** `option`。
29
- *
30
- * 可用的预设:{@linkcode ringPie}
31
- */
32
- presets?: PieSeriesPreset[];
33
- }
34
-
35
- /**
36
- * 添加一个饼图。
37
- *
38
- * 请使用 ECharts 的 legend 组件来添加图例,不要手动编写 React 代码制作图例。
39
- */
40
- export function pieSeries(
41
- option: PieSeriesOption,
42
- ): EChartsSeries<OrigPieSeriesOption> {
43
- const series: OrigPieSeriesOption = {
44
- type: "pie",
45
- id: option.name,
46
- name: option.name,
47
- data: option.data,
48
- ...option.option,
49
- };
50
- option.presets?.forEach((preset) => preset(series));
51
- return { series: [series] };
52
- }
53
-
54
- const RING_PIE = (option: OrigPieSeriesOption) => {
55
- option.radius = ["43%", "75%"];
56
- option.avoidLabelOverlap = false;
57
- option.label = {
58
- show: false,
59
- position: "center",
60
- };
61
- option.labelLine = {
62
- show: false,
63
- };
64
- option.emphasis = {
65
- label: {
66
- show: true,
67
- fontSize: 16,
68
- fontWeight: "bold",
69
- },
70
- };
71
- };
72
-
73
- /** 饼图预设,使饼图变为环状,标签出现在环的中央。*/
74
- export function ringPie(): PieSeriesPreset {
75
- return RING_PIE;
76
- }