@tsingroc/tsingroc-components 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (150) 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/SelectableECharts.d.ts +22 -0
  32. package/dist/components/SelectableECharts.js +402 -0
  33. package/dist/components/Sidebar.d.ts +79 -0
  34. package/dist/components/Sidebar.js +178 -0
  35. package/dist/components/TsingrocDatePicker.d.ts +38 -0
  36. package/dist/components/TsingrocDatePicker.js +64 -0
  37. package/dist/components/TsingrocTheme.d.ts +15 -0
  38. package/dist/components/TsingrocTheme.js +72 -0
  39. package/dist/components/UserButton.d.ts +42 -0
  40. package/dist/components/UserButton.js +105 -0
  41. package/dist/components/VerticalColorLegend.d.ts +7 -0
  42. package/dist/components/VerticalColorLegend.js +208 -0
  43. package/dist/components/WeatherMap.d.ts +18 -0
  44. package/dist/components/WeatherMap.js +658 -0
  45. package/dist/deckgl/TiandituLayer.d.ts +13 -0
  46. package/dist/deckgl/TiandituLayer.js +44 -0
  47. package/dist/deckgl/WeatherData.d.ts +53 -0
  48. package/dist/deckgl/WeatherData.js +94 -0
  49. package/dist/deckgl/index.d.ts +1 -0
  50. package/dist/deckgl/index.js +1 -0
  51. package/dist/echarts/coordinateSystems/grid.d.ts +43 -0
  52. package/dist/echarts/coordinateSystems/grid.js +108 -0
  53. package/dist/echarts/coordinateSystems/index.js +2 -0
  54. package/dist/echarts/coordinateSystems/polar.d.ts +45 -0
  55. package/dist/echarts/coordinateSystems/polar.js +96 -0
  56. package/dist/echarts/gl-types.d.js +0 -0
  57. package/dist/echarts/gl.d.ts +115 -0
  58. package/dist/echarts/gl.js +47 -0
  59. package/dist/echarts/index.d.ts +46 -0
  60. package/dist/echarts/index.js +46 -0
  61. package/dist/echarts/legend.d.ts +17 -0
  62. package/dist/echarts/legend.js +15 -0
  63. package/dist/echarts/radar.d.ts +24 -0
  64. package/dist/echarts/radar.js +22 -0
  65. package/dist/echarts/series/barSeries.d.ts +23 -0
  66. package/dist/echarts/series/barSeries.js +18 -0
  67. package/dist/echarts/series/boxplotSeries.d.ts +21 -0
  68. package/dist/echarts/series/boxplotSeries.js +40 -0
  69. package/dist/echarts/series/index.js +7 -0
  70. package/dist/echarts/series/intervalSeries.d.ts +32 -0
  71. package/dist/echarts/series/intervalSeries.js +55 -0
  72. package/dist/echarts/series/lineSeries.d.ts +36 -0
  73. package/dist/echarts/series/lineSeries.js +45 -0
  74. package/dist/echarts/series/maxBarSeries.d.ts +18 -0
  75. package/dist/echarts/series/maxBarSeries.js +39 -0
  76. package/dist/echarts/series/pieSeries.d.ts +31 -0
  77. package/dist/echarts/series/pieSeries.js +47 -0
  78. package/dist/echarts/series/windLineSeries.d.ts +47 -0
  79. package/dist/echarts/series/windLineSeries.js +51 -0
  80. package/{src/echarts/tooltip.ts → dist/echarts/tooltip.d.ts} +1 -5
  81. package/dist/echarts/tooltip.js +22 -0
  82. package/dist/env.d.js +0 -0
  83. package/dist/index.d.ts +21 -0
  84. package/dist/index.js +21 -0
  85. package/dist/utils/debug.d.ts +1 -0
  86. package/dist/utils/debug.js +25 -0
  87. package/dist/utils/destructureLineDataItem.d.ts +6 -0
  88. package/dist/utils/destructureLineDataItem.js +17 -0
  89. package/dist/utils/filterMap.d.ts +1 -0
  90. package/dist/utils/filterMap.js +11 -0
  91. package/dist/utils/index.d.ts +8 -0
  92. package/dist/utils/index.js +8 -0
  93. package/dist/utils/math.d.ts +9 -0
  94. package/{src/utils/math.ts → dist/utils/math.js} +2 -2
  95. package/dist/utils/mock.d.ts +8 -0
  96. package/dist/utils/mock.js +40 -0
  97. package/dist/utils/normalizeIntoArray.d.ts +1 -0
  98. package/dist/utils/normalizeIntoArray.js +3 -0
  99. package/dist/utils/startOfQuarter.d.ts +2 -0
  100. package/dist/utils/startOfQuarter.js +4 -0
  101. package/dist/utils/timeAxisLabel.d.ts +5 -0
  102. package/dist/utils/timeAxisLabel.js +18 -0
  103. package/package.json +26 -14
  104. package/src/components/Auth.tsx +0 -623
  105. package/src/components/AutoResizedECharts.tsx +0 -70
  106. package/src/components/Calendar.tsx +0 -182
  107. package/src/components/CircularProgress.tsx +0 -38
  108. package/src/components/ConnectedECharts.tsx +0 -62
  109. package/src/components/ECharts.tsx +0 -206
  110. package/src/components/Header.tsx +0 -136
  111. package/src/components/ImageBackground.tsx +0 -58
  112. package/src/components/IndicatorLight.tsx +0 -106
  113. package/src/components/LeftAlignedECharts.tsx +0 -190
  114. package/src/components/LineChartEditor.tsx +0 -558
  115. package/src/components/LineChartTable.tsx +0 -286
  116. package/src/components/LinkedECharts.tsx +0 -51
  117. package/src/components/LinkedLineChart.tsx +0 -144
  118. package/src/components/QuickDateRangePicker.tsx +0 -84
  119. package/src/components/SegmentedButtons.tsx +0 -46
  120. package/src/components/Sidebar.tsx +0 -271
  121. package/src/components/StrictECharts.d.ts +0 -47
  122. package/src/components/StrictECharts.js +0 -1
  123. package/src/components/TsingrocDatePicker.tsx +0 -103
  124. package/src/components/TsingrocTheme.tsx +0 -48
  125. package/src/components/UserButton.tsx +0 -165
  126. package/src/components/VerticalColorLegend.tsx +0 -73
  127. package/src/components/WeatherMap.tsx +0 -522
  128. package/src/deckgl/TiandituLayer.ts +0 -56
  129. package/src/deckgl/WeatherData.ts +0 -157
  130. package/src/deckgl/index.ts +0 -4
  131. package/src/echarts/coordinateSystems/grid.ts +0 -143
  132. package/src/echarts/coordinateSystems/polar.ts +0 -148
  133. package/src/echarts/gl.ts +0 -159
  134. package/src/echarts/index.ts +0 -129
  135. package/src/echarts/legend.ts +0 -36
  136. package/src/echarts/radar.ts +0 -46
  137. package/src/echarts/series/barSeries.ts +0 -37
  138. package/src/echarts/series/boxplotSeries.ts +0 -62
  139. package/src/echarts/series/intervalSeries.ts +0 -70
  140. package/src/echarts/series/lineSeries.ts +0 -78
  141. package/src/echarts/series/maxBarSeries.ts +0 -55
  142. package/src/echarts/series/pieSeries.ts +0 -76
  143. package/src/echarts/series/windLineSeries.ts +0 -113
  144. package/src/index.ts +0 -120
  145. package/src/types.d.ts +0 -5
  146. package/src/utils/debug.ts +0 -39
  147. package/src/utils/mock.ts +0 -69
  148. package/src/utils/startOfQuarter.ts +0 -6
  149. /package/{src/echarts/coordinateSystems/index.ts → dist/echarts/coordinateSystems/index.d.ts} +0 -0
  150. /package/{src/echarts/series/index.ts → dist/echarts/series/index.d.ts} +0 -0
@@ -0,0 +1,46 @@
1
+ export * from "./coordinateSystems";
2
+ export * from "./gl";
3
+ export * from "./legend";
4
+ export * from "./radar";
5
+ export * from "./series";
6
+ export * from "./tooltip";
7
+
8
+ /** 一个可组合的 ECharts 组件。*/
9
+
10
+ /** 一个 ECharts 系列。*/
11
+
12
+ /** ECharts 中不可组合的设置项。*/
13
+
14
+ /**
15
+ * 第一个参数 `base` 中可以填入不可组合的 ECharts 配置项,例如 `color`。
16
+ * 剩余的参数就是需要组合的各个 ECharts 组件。
17
+ */
18
+ export function buildEChartsOption(base, ...components) {
19
+ const option = {
20
+ ...base
21
+ };
22
+ for (const component of components) {
23
+ Object.entries(component).forEach(([k, value]) => {
24
+ const key = k;
25
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
26
+ (option[key] ??= []).push(...(value ?? []));
27
+ });
28
+ }
29
+ return option;
30
+ }
31
+
32
+ // 一些零散工具
33
+
34
+ /** 一个从 01:00 到 24:00 的数组,可以在等待数据加载时填充 X 轴。*/
35
+ export const HOURS_OF_DAY = Array.from({
36
+ length: 24
37
+ }, (_, index) => (index + 1).toString().padStart(2, "0") + ":00");
38
+
39
+ /** 虚线图标,可用于图例。*/
40
+ export const DASHES_ICON = "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";
41
+
42
+ /** 公用调色板 1。*/
43
+ export const PALETTE_1 = ["#2FDAFF", "#77DA9B", "#FFB82E", "#5470C6", "#91CC75", "#FAC858", "#EE6666", "#73C0DE", "#3BA272", "#FC8452", "#9A60B4", "#EA7CCC"];
44
+
45
+ /** 公用调色板 2。*/
46
+ export const PALETTE_2 = ["#ECA926", "#32ADF4", "#DC7756", "#62CE89", "#4256B9", "#00D0FF", "#96D0DD"];
@@ -0,0 +1,17 @@
1
+ import type { LegendComponentOption } from "echarts";
2
+ import type { EChartsComponent } from ".";
3
+ export type LegendDataItem = Exclude<(LegendComponentOption["data"] & {})[0], string>;
4
+ export interface LegendOption {
5
+ /**
6
+ * 图例中要显示的系列或数据项。
7
+ */
8
+ data: (string | LegendDataItem)[];
9
+ /**
10
+ * 其它图例设置项,参见 [ECharts 文档][1]。
11
+ *
12
+ * [1]: https://echarts.apache.org/zh/option.html#legend
13
+ */
14
+ option?: LegendComponentOption;
15
+ }
16
+ /** 添加一个图例。 */
17
+ export declare function legend(option: LegendOption): EChartsComponent;
@@ -0,0 +1,15 @@
1
+ import { LegendComponent } from "echarts/components";
2
+ import * as echarts from "echarts/core";
3
+ /** 添加一个图例。 */
4
+ export function legend(option) {
5
+ echarts.use(LegendComponent);
6
+ return {
7
+ legend: [{
8
+ top: 1,
9
+ right: 0,
10
+ padding: 0,
11
+ data: option.data,
12
+ ...option.option
13
+ }]
14
+ };
15
+ }
@@ -0,0 +1,24 @@
1
+ import type { RadarComponentOption, RadarSeriesOption } from "echarts";
2
+ import type { EChartsComponent } from ".";
3
+ export interface RadarOption {
4
+ /** 名称,不可与其它组件和系列重名。*/
5
+ name: string;
6
+ /** 雷达图的各维度。*/
7
+ dimensions: RadarComponentOption["indicator"] & {};
8
+ /** 雷达图的数据。*/
9
+ data: RadarSeriesOption["data"] & {};
10
+ /**
11
+ * 其它传递给雷达图组件的设置项,参见 [ECharts 文档][1]。
12
+ *
13
+ * [1]: https://echarts.apache.org/zh/option.html#radar
14
+ */
15
+ option?: RadarComponentOption;
16
+ /**
17
+ * 其它传递给雷达系列的设置项,参见 [ECharts 文档][1]。
18
+ *
19
+ * [1]: https://echarts.apache.org/zh/option.html#series-radar
20
+ */
21
+ series?: RadarSeriesOption;
22
+ }
23
+ /** 添加一张雷达图。*/
24
+ export declare function radar(option: RadarOption): EChartsComponent;
@@ -0,0 +1,22 @@
1
+ import { RadarChart } from "echarts/charts";
2
+ import { RadarComponent } from "echarts/components";
3
+ import * as echarts from "echarts/core";
4
+ /** 添加一张雷达图。*/
5
+ export function radar(option) {
6
+ echarts.use(RadarComponent);
7
+ echarts.use(RadarChart);
8
+ return {
9
+ radar: [{
10
+ id: option.name + "-radar",
11
+ indicator: option.dimensions,
12
+ ...option.option
13
+ }],
14
+ series: [{
15
+ type: "radar",
16
+ name: option.name,
17
+ radarId: option.name + "-radar",
18
+ data: option.data,
19
+ ...option.series
20
+ }]
21
+ };
22
+ }
@@ -0,0 +1,23 @@
1
+ import type { BarSeriesOption as OrigBarSeriesOption } from "echarts";
2
+ import type { DataItem, EChartsSeries } from "..";
3
+ export interface BarSeriesOption {
4
+ /** 系列名称,不可与其他系列重名。*/
5
+ name: string;
6
+ /**
7
+ * 条形的数据。
8
+ *
9
+ * 数据的结构是二维数组,每一行表示一个数据点,第一、第二列分别代表两个轴。
10
+ * 若两个轴中有且只有一个是类目轴,则数据类型可以是一维数组,表示另一个轴的值。
11
+ */
12
+ data: [DataItem, DataItem, ...DataItem[]][] | DataItem[];
13
+ /**
14
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
15
+ *
16
+ * [1]: https://echarts.apache.org/zh/option.html#series-bar
17
+ */
18
+ option?: OrigBarSeriesOption;
19
+ }
20
+ /**
21
+ * 在坐标系上添加一组条形图。
22
+ */
23
+ export declare function barSeries(option: BarSeriesOption): EChartsSeries<OrigBarSeriesOption>;
@@ -0,0 +1,18 @@
1
+ import { BarChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ /**
4
+ * 在坐标系上添加一组条形图。
5
+ */
6
+ export function barSeries(option) {
7
+ echarts.use(BarChart);
8
+ const series = {
9
+ type: "bar",
10
+ id: option.name,
11
+ name: option.name,
12
+ data: option.data,
13
+ ...option.option
14
+ };
15
+ return {
16
+ series: [series]
17
+ };
18
+ }
@@ -0,0 +1,21 @@
1
+ import type { BoxplotSeriesOption as OrigBoxplotSeriesOption } from "echarts";
2
+ import type { EChartsSeries } from "..";
3
+ export interface BoxplotSeriesOption {
4
+ /** 系列名称,不可与其他系列重名。*/
5
+ name: string;
6
+ /** 箱线图的数据,每一行按顺序分别是最小值、下四分位数、中位数、上四分位数、最大值。*/
7
+ data: [number, number, number, number, number][];
8
+ /**
9
+ * 每个数据值的格式化函数。
10
+ * @default (value) => value.toFixed(2)
11
+ */
12
+ valueFormatter?: (value: number) => string;
13
+ /**
14
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
15
+ *
16
+ * [1]: https://echarts.apache.org/zh/option.html#series-boxplot
17
+ */
18
+ option?: OrigBoxplotSeriesOption;
19
+ }
20
+ /** 在坐标系上添加一组箱线图。*/
21
+ export declare function boxplotSeries(option: BoxplotSeriesOption): EChartsSeries<OrigBoxplotSeriesOption>;
@@ -0,0 +1,40 @@
1
+ import { BoxplotChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ /** 在坐标系上添加一组箱线图。*/
4
+ export function boxplotSeries(option) {
5
+ echarts.use(BoxplotChart);
6
+ const valueFormatter = option.valueFormatter ?? (value => value.toFixed(2));
7
+ const series = {
8
+ type: "boxplot",
9
+ id: option.name,
10
+ name: option.name,
11
+ data: option.data,
12
+ ...option.option,
13
+ tooltip: {
14
+ formatter: param => {
15
+ // prettier-ignore
16
+ const data = param.data;
17
+ const strong = body => `<strong style="text-align: right;">${body}</strong>`;
18
+ // TODO i18n
19
+ return `
20
+ ${param.name}<br>
21
+ <div style="
22
+ display: inline-grid;
23
+ grid: auto-flow / auto auto;
24
+ gap: 0 20px;
25
+ ">
26
+ 最大值 ${strong(valueFormatter(data[5]))}
27
+ 上四分位数 ${strong(valueFormatter(data[4]))}
28
+ 中位数 ${strong(valueFormatter(data[3]))}
29
+ 下四分位数 ${strong(valueFormatter(data[2]))}
30
+ 最小值 ${strong(valueFormatter(data[1]))}
31
+ </div>
32
+ `;
33
+ },
34
+ ...option.option?.tooltip
35
+ }
36
+ };
37
+ return {
38
+ series: [series]
39
+ };
40
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./lineSeries";
2
+ export * from "./intervalSeries";
3
+ export * from "./windLineSeries";
4
+ export * from "./barSeries";
5
+ export * from "./maxBarSeries";
6
+ export * from "./pieSeries";
7
+ export * from "./boxplotSeries";
@@ -0,0 +1,32 @@
1
+ import type { Color, LineSeriesOption as OrigLineSeriesOption } from "echarts";
2
+ import type { EChartsSeries } from "..";
3
+ export interface IntervalSeriesOption {
4
+ /** 系列名称,不可与其他系列重名。*/
5
+ name: string;
6
+ /**
7
+ * 区间的下边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
8
+ *
9
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
10
+ */
11
+ min: OrigLineSeriesOption & {
12
+ data: number[];
13
+ };
14
+ /**
15
+ * 区间的上边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
16
+ *
17
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
18
+ */
19
+ max: OrigLineSeriesOption & {
20
+ data: number[];
21
+ };
22
+ /**
23
+ * 区间条带,此处必须设置一个颜色。其它设置参见 [ECharts 文档][1]。
24
+ *
25
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
26
+ */
27
+ interval: OrigLineSeriesOption & {
28
+ color: Color;
29
+ };
30
+ }
31
+ /** 绘制一个从下边界到上边界的带状区间。*/
32
+ export declare function intervalSeries(option: IntervalSeriesOption): EChartsSeries<OrigLineSeriesOption>;
@@ -0,0 +1,55 @@
1
+ import { LineChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ const INTERVAL_SERIES_DEFAULTS = {
4
+ type: "line",
5
+ smooth: true,
6
+ showSymbol: false,
7
+ lineStyle: {
8
+ opacity: 0
9
+ },
10
+ emphasis: {
11
+ disabled: true
12
+ }
13
+ };
14
+
15
+ /** 绘制一个从下边界到上边界的带状区间。*/
16
+ export function intervalSeries(option) {
17
+ echarts.use(LineChart);
18
+ // TODO i18n
19
+ const min = {
20
+ id: option.name + "下边界",
21
+ name: option.name + "下边界",
22
+ stack: option.name,
23
+ ...INTERVAL_SERIES_DEFAULTS,
24
+ ...option.min
25
+ };
26
+ const max = {
27
+ id: option.name + "上边界",
28
+ name: option.name + "上边界",
29
+ ...INTERVAL_SERIES_DEFAULTS,
30
+ ...option.max
31
+ };
32
+ const interval = {
33
+ id: option.name,
34
+ name: option.name,
35
+ stack: option.name,
36
+ stackStrategy: "all",
37
+ symbol: "none",
38
+ data: Array.from({
39
+ length: option.min.data.length
40
+ }, (_, i) => option.max.data[i] - option.min.data[i]),
41
+ ...INTERVAL_SERIES_DEFAULTS,
42
+ ...option.interval,
43
+ tooltip: {
44
+ show: false,
45
+ ...option.interval.tooltip
46
+ },
47
+ areaStyle: {
48
+ color: option.interval.color,
49
+ ...option.interval.areaStyle
50
+ }
51
+ };
52
+ return {
53
+ series: [min, interval, max]
54
+ };
55
+ }
@@ -0,0 +1,36 @@
1
+ import type { LineSeriesOption as OrigLineSeriesOption } from "echarts";
2
+ import type { DataItem, EChartsSeries } from "..";
3
+ export type LineSeriesPreset = (option: OrigLineSeriesOption) => void;
4
+ export interface LineSeriesOption {
5
+ /** 系列名称,不可与其他系列重名。*/
6
+ name: string;
7
+ /**
8
+ * 折线的数据。
9
+ *
10
+ * 数据的结构是二维数组,每一行表示一个数据点,第一、第二列分别代表两个轴。
11
+ * 若两个轴中有且只有一个是类目轴,则数据类型可以是一维数组,表示另一个轴的值。
12
+ */
13
+ data: [DataItem, DataItem, ...DataItem[]][] | DataItem[];
14
+ /**
15
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
16
+ *
17
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
18
+ */
19
+ option?: OrigLineSeriesOption;
20
+ /**
21
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
22
+ *
23
+ * 可用的预设:{@linkcode gradientArea}
24
+ */
25
+ presets?: LineSeriesPreset[];
26
+ }
27
+ /**
28
+ * 在坐标系上添加一条折线。
29
+ */
30
+ export declare function lineSeries(option: LineSeriesOption): EChartsSeries<OrigLineSeriesOption>;
31
+ /**
32
+ * 折线图预设,使折线下方区域在纵向呈现线性渐变色。
33
+ *
34
+ * 参数 `top` 表示顶部颜色;参数 `bottom` 表示底部颜色,默认为全透明 `"transparent"`。
35
+ */
36
+ export declare function gradientArea(top: string, bottom?: string): LineSeriesPreset;
@@ -0,0 +1,45 @@
1
+ import { LineChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ /**
4
+ * 在坐标系上添加一条折线。
5
+ */
6
+ export function lineSeries(option) {
7
+ echarts.use(LineChart);
8
+ const series = {
9
+ type: "line",
10
+ id: option.name,
11
+ name: option.name,
12
+ data: option.data,
13
+ smooth: true,
14
+ showSymbol: false,
15
+ ...option.option
16
+ };
17
+ option.presets?.forEach(preset => preset(series));
18
+ return {
19
+ series: [series]
20
+ };
21
+ }
22
+
23
+ /**
24
+ * 折线图预设,使折线下方区域在纵向呈现线性渐变色。
25
+ *
26
+ * 参数 `top` 表示顶部颜色;参数 `bottom` 表示底部颜色,默认为全透明 `"transparent"`。
27
+ */
28
+ export function gradientArea(top, bottom = "transparent") {
29
+ return option => {
30
+ (option.areaStyle ??= {}).color = {
31
+ type: "linear",
32
+ x: 0,
33
+ y: 0,
34
+ x2: 0,
35
+ y2: 1,
36
+ colorStops: [{
37
+ offset: 0,
38
+ color: top
39
+ }, {
40
+ offset: 1,
41
+ color: bottom
42
+ }]
43
+ };
44
+ };
45
+ }
@@ -0,0 +1,18 @@
1
+ import type { Color, BarSeriesOption as OrigBarSeriesOption } from "echarts";
2
+ import type { EChartsSeries } from "..";
3
+ export interface MaxBarSeriesOption {
4
+ /** 系列名称,不可与其他系列重名。*/
5
+ name: string;
6
+ /** 需要求最大值的各个系列的数据。*/
7
+ data: (number | undefined)[][];
8
+ /** 各个系列的颜色,各个最大值条形将被设为对应的颜色。若留空,则使用默认颜色。*/
9
+ palette?: Color[];
10
+ /**
11
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
12
+ *
13
+ * [1]: https://echarts.apache.org/zh/option.html#series-bar
14
+ */
15
+ option?: OrigBarSeriesOption;
16
+ }
17
+ /** 求出多个系列的最大值,显示为条形图。*/
18
+ export declare function maxBarSeries(option: MaxBarSeriesOption): EChartsSeries<OrigBarSeriesOption>;
@@ -0,0 +1,39 @@
1
+ import { BarChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ /** 求出多个系列的最大值,显示为条形图。*/
4
+ export function maxBarSeries(option) {
5
+ echarts.use(BarChart);
6
+ const series = {
7
+ type: "bar",
8
+ id: option.name,
9
+ name: option.name,
10
+ data: Array.from({
11
+ length: option.data[0].length
12
+ }, (_, i) => {
13
+ // prettier-ignore
14
+ const [max, maxJ] = option.data.map(series => series[i]).reduce(([max, maxJ], y, j) => max === undefined || y !== undefined && y > max ? [y, j] : [max, maxJ], [undefined, -1]);
15
+ if (max !== undefined && option.palette) {
16
+ return {
17
+ value: max,
18
+ itemStyle: {
19
+ color: option.palette[maxJ]
20
+ }
21
+ };
22
+ } else {
23
+ return max;
24
+ }
25
+ }),
26
+ ...option.option,
27
+ itemStyle: {
28
+ opacity: 0.7,
29
+ ...option.option?.itemStyle
30
+ },
31
+ tooltip: {
32
+ show: false,
33
+ ...option.option?.tooltip
34
+ }
35
+ };
36
+ return {
37
+ series: [series]
38
+ };
39
+ }
@@ -0,0 +1,31 @@
1
+ import type { PieSeriesOption as OrigPieSeriesOption } from "echarts";
2
+ import type { EChartsSeries } from "..";
3
+ /** 饼图的数据项。*/
4
+ export type PieDataItem = (OrigPieSeriesOption["data"] & {})[0] extends number | string | unknown[] | infer T ? T : never;
5
+ export type PieSeriesPreset = (option: OrigPieSeriesOption) => void;
6
+ export interface PieSeriesOption {
7
+ /** 系列名称,不可与其他系列重名。*/
8
+ name: string;
9
+ /** 饼图的数据,数组元素可以是单个数值或者一个对象。*/
10
+ data: (number | PieDataItem)[];
11
+ /**
12
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
13
+ *
14
+ * [1]: https://echarts.apache.org/zh/option.html#series-pie
15
+ */
16
+ option?: OrigPieSeriesOption;
17
+ /**
18
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
19
+ *
20
+ * 可用的预设:{@linkcode ringPie}
21
+ */
22
+ presets?: PieSeriesPreset[];
23
+ }
24
+ /**
25
+ * 添加一个饼图。
26
+ *
27
+ * 请使用 ECharts 的 legend 组件来添加图例,不要手动编写 React 代码制作图例。
28
+ */
29
+ export declare function pieSeries(option: PieSeriesOption): EChartsSeries<OrigPieSeriesOption>;
30
+ /** 饼图预设,使饼图变为环状,标签出现在环的中央。*/
31
+ export declare function ringPie(): PieSeriesPreset;
@@ -0,0 +1,47 @@
1
+ import { PieChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+
4
+ /** 饼图的数据项。*/
5
+
6
+ /**
7
+ * 添加一个饼图。
8
+ *
9
+ * 请使用 ECharts 的 legend 组件来添加图例,不要手动编写 React 代码制作图例。
10
+ */
11
+ export function pieSeries(option) {
12
+ echarts.use(PieChart);
13
+ const series = {
14
+ type: "pie",
15
+ id: option.name,
16
+ name: option.name,
17
+ data: option.data,
18
+ ...option.option
19
+ };
20
+ option.presets?.forEach(preset => preset(series));
21
+ return {
22
+ series: [series]
23
+ };
24
+ }
25
+ const RING_PIE = option => {
26
+ option.radius = ["43%", "75%"];
27
+ option.avoidLabelOverlap = false;
28
+ option.label = {
29
+ show: false,
30
+ position: "center"
31
+ };
32
+ option.labelLine = {
33
+ show: false
34
+ };
35
+ option.emphasis = {
36
+ label: {
37
+ show: true,
38
+ fontSize: 16,
39
+ fontWeight: "bold"
40
+ }
41
+ };
42
+ };
43
+
44
+ /** 饼图预设,使饼图变为环状,标签出现在环的中央。*/
45
+ export function ringPie() {
46
+ return RING_PIE;
47
+ }
@@ -0,0 +1,47 @@
1
+ import type { LineSeriesOption as OrigLineSeriesOption } from "echarts";
2
+ import type { EChartsSeries } from "..";
3
+ import type { LineSeriesPreset } from "./lineSeries";
4
+ export interface WindLineSeriesOption {
5
+ /** 系列名称,不可与其他系列重名。*/
6
+ name: string;
7
+ /**
8
+ * 风力数据,支持两种形式:
9
+ *
10
+ * - `type: "cartesian"`,用沿经线和沿纬线的风速分量表示风力;
11
+ * - `type: "polar"`,用风速和风向表示风力。
12
+ */
13
+ data: {
14
+ type: "cartesian";
15
+ /** 沿纬线向**东**吹(西风)的风速分量,单位 m/s。*/
16
+ u: number[];
17
+ /** 沿经线向**北**吹(南风)的风速分量,单位 m/s。*/
18
+ v: number[];
19
+ } | {
20
+ type: "polar";
21
+ /** 风速,单位 m/s。*/
22
+ speed: number[];
23
+ /** 风向,单位是角度(deg),`0` 表示**北风**(往南吹),随着角度增大,风向**顺时针**旋转。*/
24
+ direction: number[];
25
+ };
26
+ /**
27
+ * 风向标的宽度和长度。
28
+ * @default [10, 20]
29
+ */
30
+ symbolSize?: [number, number];
31
+ /**
32
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
33
+ *
34
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
35
+ */
36
+ option?: OrigLineSeriesOption;
37
+ /**
38
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
39
+ *
40
+ * 可用的预设:{@linkcode gradientArea}
41
+ */
42
+ presets?: LineSeriesPreset[];
43
+ }
44
+ /**
45
+ * 风速风向折线图。
46
+ */
47
+ export declare function windLineSeries(option: WindLineSeriesOption): EChartsSeries<OrigLineSeriesOption>;
@@ -0,0 +1,51 @@
1
+ import { LineChart } from "echarts/charts";
2
+ import * as echarts from "echarts/core";
3
+ /**
4
+ * 风速风向折线图。
5
+ */
6
+ export function windLineSeries(option) {
7
+ echarts.use(LineChart);
8
+ const data = option.data;
9
+ const {
10
+ speed,
11
+ direction
12
+ } = data.type === "polar" ? data : {
13
+ speed: data.u.map((u, i) => Math.sqrt(u * u + data.v[i] * data.v[i])),
14
+ direction: data.u.map((u, i) => Math.atan2(-u, -data.v[i]) / Math.PI * 180)
15
+ };
16
+ const symbolSize = option.symbolSize ?? [10, 20];
17
+ const series = {
18
+ type: "line",
19
+ id: option.name,
20
+ name: option.name,
21
+ data: speed,
22
+ smooth: true,
23
+ symbol: "arrow",
24
+ symbolSize: symbolSize,
25
+ symbolOffset: (_data, param) => {
26
+ const rad = direction[param.dataIndex] / 180 * Math.PI;
27
+ const halfSize = symbolSize[1] / 2;
28
+ return [-halfSize * Math.sin(rad), halfSize * Math.cos(rad)];
29
+ },
30
+ symbolRotate: (_data, param) => 180 - direction[param.dataIndex],
31
+ ...option.option,
32
+ itemStyle: {
33
+ borderWidth: 1,
34
+ borderColor: "#fff",
35
+ ...option.option?.itemStyle
36
+ },
37
+ tooltip: {
38
+ valueFormatter: (value, index) => {
39
+ const dir = direction[index];
40
+ if (Number.isNaN(dir) || Number.isNaN(value)) return "--";
41
+ return value.toFixed(2) + " m/s," + WIND_DIRECTIONS[(Math.round(dir / 45) + 8) % 8] + "风";
42
+ },
43
+ ...option.option?.tooltip
44
+ }
45
+ };
46
+ option.presets?.forEach(preset => preset(series));
47
+ return {
48
+ series: [series]
49
+ };
50
+ }
51
+ const WIND_DIRECTIONS = ["北", "东北", "东", "东南", "南", "西南", "西", "西北"];
@@ -1,7 +1,5 @@
1
1
  import type { TooltipComponentOption } from "echarts";
2
-
3
2
  import type { EChartsComponent } from ".";
4
-
5
3
  /**
6
4
  * 添加悬停提示。这只是对官方 tooltip 组件的简单包装,设置参见 [ECharts 文档][1]。
7
5
  *
@@ -12,6 +10,4 @@ import type { EChartsComponent } from ".";
12
10
  *
13
11
  * [1]: https://echarts.apache.org/zh/option.html#tooltip
14
12
  */
15
- export function tooltip(option: TooltipComponentOption = {}): EChartsComponent {
16
- return { tooltip: [option] };
17
- }
13
+ export declare function tooltip(option?: TooltipComponentOption): EChartsComponent;