@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
@@ -0,0 +1,53 @@
1
+ import type * as wl from "weatherlayers-gl";
2
+ import type { BitmapBoundingBox } from "@deck.gl/layers";
3
+ export interface WeatherData {
4
+ dims: {
5
+ longitude: number;
6
+ latitude: number;
7
+ time: number;
8
+ };
9
+ coords: {
10
+ /** deg */
11
+ longitude: number[];
12
+ /** deg */
13
+ latitude: number[];
14
+ /** Unix 时间戳 */
15
+ time: number[];
16
+ };
17
+ data_vars: {
18
+ /** ℃ */
19
+ temperature_2m?: number[][][];
20
+ /** hPa */
21
+ surface_pressure?: number[][][];
22
+ /** % */
23
+ cloud_cover?: number[][][];
24
+ /** ℃ */
25
+ dew_point_2m?: number[][][];
26
+ /** % */
27
+ relative_humidity_2m?: number[][][];
28
+ /** 风速沿纬线向**东**吹(西风)的分量,m/s */
29
+ wind_component_u_10m?: number[][][];
30
+ /** 风速沿经线向**北**吹(南风)的分量,m/s */
31
+ wind_component_v_10m?: number[][][];
32
+ /** m/s */
33
+ wind_speed_10m?: number[][][];
34
+ /** deg,`0` 表示**北风**(往南吹),随着角度增大,风向**顺时针**旋转。*/
35
+ wind_direction_10m?: number[][][];
36
+ /** mm */
37
+ rain?: number[][][];
38
+ };
39
+ }
40
+ export declare const getBounds: (data: WeatherData) => BitmapBoundingBox;
41
+ export declare function extractScalarData(data: WeatherData, variable: keyof WeatherData["data_vars"]): {
42
+ image: wl.TextureData;
43
+ min: number;
44
+ max: number;
45
+ mean: number;
46
+ }[];
47
+ export declare function extractVectorData(data: WeatherData, variableU: keyof WeatherData["data_vars"], variableV: keyof WeatherData["data_vars"]): wl.TextureData[];
48
+ export declare function extractMagnitudeData(data: WeatherData, variableU: keyof WeatherData["data_vars"], variableV: keyof WeatherData["data_vars"]): {
49
+ image: wl.TextureData;
50
+ min: number;
51
+ max: number;
52
+ mean: number;
53
+ }[];
@@ -0,0 +1,94 @@
1
+ export const getBounds = data => {
2
+ const [lngMin, lngMax] = [data.coords.longitude[0], data.coords.longitude.at(-1)].sort();
3
+ const [latMin, latMax] = [data.coords.latitude[0], data.coords.latitude.at(-1)].sort();
4
+ return [lngMin, latMin, lngMax, latMax];
5
+ };
6
+ export function extractScalarData(data, variable) {
7
+ const result = Array.from({
8
+ length: data.dims.time
9
+ }, () => ({
10
+ image: {
11
+ data: new Float32Array(data.dims.longitude * data.dims.latitude),
12
+ width: data.dims.longitude,
13
+ height: data.dims.latitude
14
+ },
15
+ min: Infinity,
16
+ max: -Infinity,
17
+ mean: 0
18
+ }));
19
+ let p = 0;
20
+ for (let i = 0; i < data.dims.longitude; i++) {
21
+ for (let j = 0; j < data.dims.latitude; j++) {
22
+ for (let t = 0; t < data.dims.time; t++) {
23
+ let value = data.data_vars[variable][i][j][t];
24
+ if (value === -9999) value = NaN;
25
+ result[t].image.data[p] = value;
26
+ if (value > result[t].max) result[t].max = value;
27
+ if (value < result[t].min) result[t].min = value;
28
+ }
29
+ p++;
30
+ }
31
+ }
32
+ for (const item of result) {
33
+ item.mean = item.image.data.reduce((a, b) => a + b) / item.image.data.length;
34
+ }
35
+ return result;
36
+ }
37
+ export function extractVectorData(data, variableU, variableV) {
38
+ const result = Array.from({
39
+ length: data.dims.time
40
+ }, () => ({
41
+ data: new Float32Array(data.dims.longitude * data.dims.latitude * 2),
42
+ width: data.dims.longitude,
43
+ height: data.dims.latitude
44
+ }));
45
+ let p = 0;
46
+ for (let i = 0; i < data.dims.longitude; i++) {
47
+ for (let j = 0; j < data.dims.latitude; j++) {
48
+ for (let t = 0; t < data.dims.time; t++) {
49
+ let u = data.data_vars[variableU][i][j][t];
50
+ let v = data.data_vars[variableV][i][j][t];
51
+ if (u === -9999) u = NaN;
52
+ if (v === -9999) v = NaN;
53
+ result[t].data[p] = u;
54
+ result[t].data[p + 1] = v;
55
+ }
56
+ p += 2;
57
+ }
58
+ }
59
+ return result;
60
+ }
61
+ export function extractMagnitudeData(data, variableU, variableV) {
62
+ const result = Array.from({
63
+ length: data.dims.time
64
+ }, () => ({
65
+ image: {
66
+ data: new Float32Array(data.dims.longitude * data.dims.latitude),
67
+ width: data.dims.longitude,
68
+ height: data.dims.latitude
69
+ },
70
+ min: Infinity,
71
+ max: -Infinity,
72
+ mean: 0
73
+ }));
74
+ let p = 0;
75
+ for (let i = 0; i < data.dims.longitude; i++) {
76
+ for (let j = 0; j < data.dims.latitude; j++) {
77
+ for (let t = 0; t < data.dims.time; t++) {
78
+ let u = data.data_vars[variableU][i][j][t];
79
+ let v = data.data_vars[variableV][i][j][t];
80
+ if (u === -9999) u = NaN;
81
+ if (v === -9999) v = NaN;
82
+ const value = Math.sqrt(u * u + v * v);
83
+ result[t].image.data[p] = value;
84
+ if (value > result[t].max) result[t].max = value;
85
+ if (value < result[t].min) result[t].min = value;
86
+ }
87
+ p++;
88
+ }
89
+ }
90
+ for (const item of result) {
91
+ item.mean = item.image.data.reduce((a, b) => a + b) / item.image.data.length;
92
+ }
93
+ return result;
94
+ }
@@ -0,0 +1 @@
1
+ export { default as TiandituLayer, type TiandituLayerProps, } from "./TiandituLayer";
@@ -0,0 +1 @@
1
+ export { default as TiandituLayer } from "./TiandituLayer";
@@ -0,0 +1,43 @@
1
+ import type { BarSeriesOption, BoxplotSeriesOption, FlowGLSeriesOption, GridComponentOption, LineSeriesOption, XAXisComponentOption, YAXisComponentOption } from "echarts";
2
+ import type { EChartsComponent, EChartsSeries } from "..";
3
+ export type GridPreset = (grid: GridComponentOption, xAxis: XAXisComponentOption, yAxis: YAXisComponentOption) => void;
4
+ export interface GridOption {
5
+ /**
6
+ * 坐标网格的其它设置,参见 [ECharts 文档][1]。
7
+ *
8
+ * [1]: https://echarts.apache.org/zh/option.html#grid
9
+ */
10
+ option?: GridComponentOption;
11
+ /**
12
+ * X 轴的设置,参见 [ECharts 文档][1]。
13
+ *
14
+ * [1]: https://echarts.apache.org/zh/option.html#xAxis
15
+ */
16
+ xAxis?: XAXisComponentOption;
17
+ /**
18
+ * Y 轴的设置,参见 [ECharts 文档][1]。
19
+ *
20
+ * [1]: https://echarts.apache.org/zh/option.html#yAxis
21
+ */
22
+ yAxis?: YAXisComponentOption;
23
+ /**
24
+ * 预设列表。预设的优先级**高于**上述设置。
25
+ *
26
+ * 可用的预设:{@linkcode minimalGrid}
27
+ */
28
+ presets?: GridPreset[];
29
+ /** 要绘制在该坐标系上的系列。*/
30
+ series?: EChartsSeries<LineSeriesOption | BarSeriesOption | BoxplotSeriesOption | FlowGLSeriesOption>[];
31
+ }
32
+ /**
33
+ * 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
34
+ */
35
+ export declare function grid(option: GridOption): EChartsComponent;
36
+ /**
37
+ * 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
38
+ *
39
+ * **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
40
+ */
41
+ export declare function useGrid(option: GridOption): EChartsComponent;
42
+ /** 使用该预设可以隐藏直角坐标系的坐标轴和网格线,只留下图像本身,并且使其填满整个容器。*/
43
+ export declare function minimalGrid(): GridPreset;
@@ -0,0 +1,107 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { GridComponent } from "echarts/components";
3
+ import * as echarts from "echarts/core";
4
+ import { useId } from "react";
5
+ /**
6
+ * 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
7
+ */
8
+ export function grid(option) {
9
+ echarts.use(GridComponent);
10
+ const grid = {
11
+ left: 0,
12
+ right: 0,
13
+ top: 24,
14
+ bottom: 0,
15
+ containLabel: true,
16
+ ...option.option
17
+ };
18
+ const xAxis = {
19
+ id: grid.id === undefined ? undefined : String(grid.id) + "x",
20
+ gridId: grid.id === undefined ? undefined : String(grid.id),
21
+ nameGap: 6,
22
+ ...option.xAxis,
23
+ nameTextStyle: {
24
+ fontWeight: "bold",
25
+ ...option.xAxis?.nameTextStyle
26
+ },
27
+ axisTick: {
28
+ alignWithLabel: true,
29
+ ...option.xAxis?.axisTick
30
+ // 此处需要强转,因为 alignWithLabel 仅当 boundaryGap = true 时有效,但无效也没有影响
31
+ }
32
+ };
33
+ const xAxisId = xAxis.id;
34
+ const yAxis = {
35
+ id: grid.id === undefined ? undefined : String(grid.id) + "y",
36
+ type: "value",
37
+ gridId: grid.id === undefined ? undefined : String(grid.id),
38
+ nameGap: 10,
39
+ ...option.yAxis,
40
+ nameTextStyle: {
41
+ align: "left",
42
+ fontWeight: "bold",
43
+ ...option.yAxis?.nameTextStyle
44
+ }
45
+ };
46
+ const yAxisId = yAxis.id;
47
+ option.presets?.forEach(preset => preset(grid, xAxis, yAxis));
48
+ return {
49
+ grid: [grid],
50
+ xAxis: [xAxis],
51
+ yAxis: [yAxis],
52
+ series: option.series?.flatMap(item => item.series).map(series => ({
53
+ ...series,
54
+ coordinateSystem: "cartesian2d",
55
+ xAxisId,
56
+ yAxisId
57
+ }))
58
+ };
59
+ }
60
+
61
+ /**
62
+ * 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
63
+ *
64
+ * **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
65
+ */
66
+ export function useGrid(option) {
67
+ const $ = _c(3);
68
+ const t0 = useId();
69
+ let t1;
70
+ if ($[0] !== option || $[1] !== t0) {
71
+ t1 = grid({
72
+ ...option,
73
+ option: {
74
+ id: t0,
75
+ ...option.option
76
+ }
77
+ });
78
+ $[0] = option;
79
+ $[1] = t0;
80
+ $[2] = t1;
81
+ } else {
82
+ t1 = $[2];
83
+ }
84
+ return t1;
85
+ }
86
+ const MINIMAL_GRID = (grid, xAxis, yAxis) => {
87
+ grid.top = 0;
88
+ xAxis.show = false;
89
+ if (xAxis.type === undefined && xAxis.data !== undefined || xAxis.type === "category") {
90
+ xAxis.boundaryGap = false;
91
+ } else {
92
+ xAxis.min = "dataMin";
93
+ xAxis.max = "dataMax";
94
+ }
95
+ xAxis.axisLabel = {
96
+ inside: true
97
+ };
98
+ yAxis.show = false;
99
+ yAxis.axisLabel = {
100
+ inside: true
101
+ };
102
+ };
103
+
104
+ /** 使用该预设可以隐藏直角坐标系的坐标轴和网格线,只留下图像本身,并且使其填满整个容器。*/
105
+ export function minimalGrid() {
106
+ return MINIMAL_GRID;
107
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./grid";
2
+ export * from "./polar";
@@ -0,0 +1,45 @@
1
+ import type { AngleAxisComponentOption, BarSeriesOption, LineSeriesOption, PolarComponentOption, RadiusAxisComponentOption } from "echarts";
2
+ import type { EChartsComponent, EChartsSeries } from "..";
3
+ export type PolarPreset = (polar: PolarComponentOption, angleAxis: AngleAxisComponentOption, radiusAxis: RadiusAxisComponentOption) => void;
4
+ export interface PolarOption {
5
+ /**
6
+ * 极坐标系的其它设置,参见 [ECharts 文档][1]。
7
+ *
8
+ * [1]: https://echarts.apache.org/zh/option.html#polar
9
+ */
10
+ option?: PolarComponentOption;
11
+ /**
12
+ * 角度轴的设置,参见 [ECharts 文档][1]。
13
+ *
14
+ * [1]: https://echarts.apache.org/zh/option.html#angleAxis
15
+ */
16
+ angleAxis?: AngleAxisComponentOption;
17
+ /**
18
+ * 半径轴的设置,参见 [ECharts 文档][1]。
19
+ *
20
+ * [1]: https://echarts.apache.org/zh/option.html#radiusAxis
21
+ */
22
+ radiusAxis?: RadiusAxisComponentOption;
23
+ /**
24
+ * 预设列表。预设的优先级**高于**上述设置。
25
+ *
26
+ * 可用的预设:{@linkcode minimalGrid}
27
+ */
28
+ presets?: PolarPreset[];
29
+ /** 要绘制在该坐标系上的系列。*/
30
+ series?: EChartsSeries<LineSeriesOption | BarSeriesOption>[];
31
+ }
32
+ /**
33
+ * 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
34
+ */
35
+ export declare function polar(option: PolarOption): EChartsComponent;
36
+ /**
37
+ * 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
38
+ *
39
+ * **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
40
+ */
41
+ export declare function usePolar(option: PolarOption): EChartsComponent;
42
+ /**
43
+ * 使用该预设可以将极坐标系的角度轴设置为 16 个风向,风向从正北开始,按顺时针方向排列。
44
+ */
45
+ export declare function windPolar(): PolarPreset;
@@ -0,0 +1,96 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { PolarComponent } from "echarts/components";
3
+ import * as echarts from "echarts/core";
4
+ import { useId } from "react";
5
+ /**
6
+ * 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
7
+ */
8
+ export function polar(option) {
9
+ echarts.use(PolarComponent);
10
+ const polar = option.option ?? {};
11
+ const angleAxis = {
12
+ id: polar.id === undefined ? undefined : String(polar.id) + "angle",
13
+ polarId: polar.id === undefined ? undefined : String(polar.id),
14
+ ...option.angleAxis,
15
+ axisLabel: {
16
+ margin: 3,
17
+ fontSize: 10,
18
+ ...option.angleAxis?.axisLabel
19
+ },
20
+ axisLine: {
21
+ show: false,
22
+ ...option.angleAxis?.axisLine
23
+ },
24
+ splitLine: {
25
+ show: true,
26
+ ...option.angleAxis?.splitLine
27
+ }
28
+ };
29
+ const angleAxisId = angleAxis.id;
30
+ const radiusAxis = {
31
+ id: polar.id === undefined ? undefined : String(polar.id) + "radius",
32
+ type: "value",
33
+ polarId: polar.id === undefined ? undefined : String(polar.id),
34
+ ...option.radiusAxis,
35
+ axisLine: {
36
+ show: false,
37
+ ...option.radiusAxis?.axisLine
38
+ }
39
+ };
40
+ const radiusAxisId = radiusAxis.id;
41
+ option.presets?.forEach(preset => preset(polar, angleAxis, radiusAxis));
42
+ return {
43
+ polar: [polar],
44
+ angleAxis: [angleAxis],
45
+ radiusAxis: [radiusAxis],
46
+ series: option.series?.flatMap(item => item.series).map(series => ({
47
+ ...series,
48
+ coordinateSystem: "polar",
49
+ angleAxisId,
50
+ radiusAxisId
51
+ }))
52
+ };
53
+ }
54
+
55
+ /**
56
+ * 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
57
+ *
58
+ * **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
59
+ */
60
+ export function usePolar(option) {
61
+ const $ = _c(3);
62
+ const t0 = useId();
63
+ let t1;
64
+ if ($[0] !== option || $[1] !== t0) {
65
+ t1 = polar({
66
+ ...option,
67
+ option: {
68
+ id: t0,
69
+ ...option.option
70
+ }
71
+ });
72
+ $[0] = option;
73
+ $[1] = t0;
74
+ $[2] = t1;
75
+ } else {
76
+ t1 = $[2];
77
+ }
78
+ return t1;
79
+ }
80
+ const WIND_POLAR = (_, angleAxis, radiusAxis) => {
81
+ angleAxis.type = "category";
82
+ angleAxis.data = WIND_DIRECTION_NAMES;
83
+ angleAxis.startAngle = 101.25;
84
+ radiusAxis.axisLabel = {
85
+ ...radiusAxis.axisLabel,
86
+ verticalAlign: "top"
87
+ };
88
+ };
89
+
90
+ /**
91
+ * 使用该预设可以将极坐标系的角度轴设置为 16 个风向,风向从正北开始,按顺时针方向排列。
92
+ */
93
+ export function windPolar() {
94
+ return WIND_POLAR;
95
+ }
96
+ const WIND_DIRECTION_NAMES = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
File without changes
@@ -0,0 +1,115 @@
1
+ import type { FlowGLSeriesOption as OrigFlowGLSeriesOption } from "echarts";
2
+ import type { ComponentOption, SeriesOnCartesianOptionMixin, SeriesOnGeoOptionMixin } from "echarts/types/src/util/types.js";
3
+ import type { EChartsSeries } from ".";
4
+ declare module "echarts" {
5
+ interface RegisteredSeriesOption {
6
+ flowGL: FlowGLSeriesOption;
7
+ }
8
+ interface FlowGLSeriesOption extends ComponentOption, SeriesOnCartesianOptionMixin, SeriesOnGeoOptionMixin {
9
+ type: "flowGL";
10
+ /**
11
+ * 粒子的密度,实际的粒子数量是设置数目的平方。粒子密度越大迹线效果越好,但是性能开销也会越大。
12
+ * 除了该属性,使用 `particleType` 也可以得到更加清晰连贯的迹线。
13
+ * @default 128
14
+ */
15
+ particleDensity?: number;
16
+ /**
17
+ * 粒子的类型,可以设置为点 `"point"` 或线 `"line"`。
18
+ * 线类型的粒子会用一条线连接上个运动的位置和当前运动的位置,这会让这个轨迹更加连贯。
19
+ * @default "point"
20
+ */
21
+ particleType?: "point" | "line";
22
+ /**
23
+ * 粒子的大小,如果 `particleType == "line"` 则代表线宽。
24
+ * @default 1
25
+ */
26
+ particleSize?: number;
27
+ /**
28
+ * 粒子的速度,默认为 1。注意在 `particleType` 为 `"point"` 的时候过大的速度会让整个轨迹变得断断续续。
29
+ * @default 1
30
+ */
31
+ particleSpeed?: number;
32
+ /**
33
+ * 粒子的轨迹长度,数值越大轨迹越长。
34
+ * @default 2
35
+ */
36
+ particleTrail?: number;
37
+ /**
38
+ * 画面的超采样比率,采用 4 的超采样可以有效的提高画面的清晰度,减少画面锯齿。
39
+ * 但是因为需要处理更多的像素数量,所以也对性能有更高的要求。
40
+ * @default 1
41
+ */
42
+ supersampling?: number;
43
+ /**
44
+ * 传入的网格数据的网格宽度数量。
45
+ * @default "auto"
46
+ */
47
+ gridWidth?: number | "auto";
48
+ /**
49
+ * 传入的网格数据的网格高度数量。
50
+ * @default "auto"
51
+ */
52
+ gridHeight?: number | "auto";
53
+ /**
54
+ * 每行数据包含四个值,分别表示位置 x、y,速度 sx、sy。
55
+ * 如果使用地理坐标系,则分别表示位置 lng、lat,速度 sLng、sLat。
56
+ */
57
+ data: [number, number, number, number][];
58
+ /**
59
+ * 向量场迹线的样式。
60
+ */
61
+ itemStyle?: FlowGLSeriesItemStyle;
62
+ }
63
+ interface FlowGLSeriesItemStyle {
64
+ /**
65
+ * 向量场迹线的颜色。
66
+ * @default "#fff"
67
+ */
68
+ color?: string;
69
+ /**
70
+ * 向量场迹线的透明度。
71
+ * @default 0.8
72
+ */
73
+ opacity?: number;
74
+ }
75
+ }
76
+ export interface FlowGLSeriesOption {
77
+ /** 系列名称,不可与其他系列重名。*/
78
+ name: string;
79
+ /**
80
+ * 每行数据包含四个值,分别表示位置 x、y,速度 sx、sy。
81
+ *
82
+ * 如果需要使用风场数据,可以直接调用 {@linkcode preprocessWindData} 来将数据处理成此处需要的格式。
83
+ */
84
+ data: [number, number, number, number][];
85
+ /**
86
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
87
+ *
88
+ * [1]: https://echarts.apache.org/zh/option-gl.html#series-flowGL
89
+ */
90
+ option?: Partial<OrigFlowGLSeriesOption>;
91
+ }
92
+ /**
93
+ * 在坐标系上绘制一个流场。
94
+ *
95
+ * 推荐使用以下坐标系配置:
96
+ *
97
+ * ```ts
98
+ * echarts.useGrid({
99
+ * xAxis: { type: "value" },
100
+ * yAxis: { min: "dataMin", max: "dataMax" },
101
+ * presets: [echarts.minimalGrid()],
102
+ * })
103
+ * ```
104
+ */
105
+ export declare function flowGLSeries(option: FlowGLSeriesOption): EChartsSeries<OrigFlowGLSeriesOption>;
106
+ export interface WindData {
107
+ /** 位置,由空格分隔的经纬度数字组成。*/
108
+ location: string;
109
+ /** 风向,单位是角度(deg),`0` 表示**东风**,随着角度增大,风向**顺时针**旋转。*/
110
+ wind_direction_80m: number;
111
+ /** 风速。*/
112
+ wind_speed_80m: number;
113
+ }
114
+ /** 将 JSON 格式的天气数据预处理成 FlowGL 接受的格式。*/
115
+ export declare function preprocessWindData(data: WindData[]): [number, number, number, number][];
@@ -0,0 +1,47 @@
1
+ /// <reference types="./gl-types.d.ts" />
2
+
3
+ import { FlowGLChart } from "echarts-gl/charts";
4
+ import * as echarts from "echarts/core";
5
+
6
+ // 由于官方没有提供类型定义,这里只能自行补充
7
+
8
+ /**
9
+ * 在坐标系上绘制一个流场。
10
+ *
11
+ * 推荐使用以下坐标系配置:
12
+ *
13
+ * ```ts
14
+ * echarts.useGrid({
15
+ * xAxis: { type: "value" },
16
+ * yAxis: { min: "dataMin", max: "dataMax" },
17
+ * presets: [echarts.minimalGrid()],
18
+ * })
19
+ * ```
20
+ */
21
+ export function flowGLSeries(option) {
22
+ echarts.use(FlowGLChart);
23
+ return {
24
+ series: [{
25
+ type: "flowGL",
26
+ id: option.name,
27
+ name: option.name,
28
+ data: option.data,
29
+ particleDensity: 20,
30
+ particleSize: 3,
31
+ supersampling: window.devicePixelRatio,
32
+ ...option.option
33
+ }]
34
+ };
35
+ }
36
+ /** 将 JSON 格式的天气数据预处理成 FlowGL 接受的格式。*/
37
+ export function preprocessWindData(data) {
38
+ return data.map(item => {
39
+ const [x, y] = item.location.split(" ").map(Number.parseFloat);
40
+ // prettier-ignore
41
+ const sx = -Math.cos(item.wind_direction_80m * (Math.PI / 180)) * item.wind_speed_80m;
42
+ // prettier-ignore
43
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
44
+ const sy = +Math.sin(item.wind_direction_80m * (Math.PI / 180)) * item.wind_speed_80m;
45
+ return [x, y, sx, sy];
46
+ });
47
+ }
@@ -0,0 +1,46 @@
1
+ import type { AngleAxisComponentOption, AxisPointerComponentOption, Color, DataZoomComponentOption, EChartsOption, GraphicComponentOption, GridComponentOption, LegendComponentOption, PolarComponentOption, RadarComponentOption, RadiusAxisComponentOption, SeriesOption, TooltipComponentOption, XAXisComponentOption, YAXisComponentOption } from "echarts";
2
+ export * from "./coordinateSystems";
3
+ export * from "./gl";
4
+ export * from "./legend";
5
+ export * from "./radar";
6
+ export * from "./series";
7
+ export * from "./tooltip";
8
+ /** 一个可组合的 ECharts 组件。*/
9
+ export interface EChartsComponent {
10
+ grid?: GridComponentOption[];
11
+ xAxis?: XAXisComponentOption[];
12
+ yAxis?: YAXisComponentOption[];
13
+ polar?: PolarComponentOption[];
14
+ angleAxis?: AngleAxisComponentOption[];
15
+ radiusAxis?: RadiusAxisComponentOption[];
16
+ radar?: RadarComponentOption[];
17
+ legend?: LegendComponentOption[];
18
+ tooltip?: TooltipComponentOption[];
19
+ axisPointer?: AxisPointerComponentOption[];
20
+ dataZoom?: DataZoomComponentOption[];
21
+ graphic?: GraphicComponentOption[];
22
+ series?: SeriesOption[];
23
+ }
24
+ /** 一个 ECharts 系列。*/
25
+ export interface EChartsSeries<T = SeriesOption> {
26
+ series: T[];
27
+ }
28
+ /** ECharts 中不可组合的设置项。*/
29
+ export interface EChartsNonComposableOption {
30
+ color?: Color[];
31
+ backgroundColor?: string;
32
+ }
33
+ export type DataItem = number | string | Date | undefined;
34
+ /**
35
+ * 第一个参数 `base` 中可以填入不可组合的 ECharts 配置项,例如 `color`。
36
+ * 剩余的参数就是需要组合的各个 ECharts 组件。
37
+ */
38
+ export declare function buildEChartsOption(base: EChartsNonComposableOption, ...components: EChartsComponent[]): EChartsOption;
39
+ /** 一个从 01:00 到 24:00 的数组,可以在等待数据加载时填充 X 轴。*/
40
+ export declare const HOURS_OF_DAY: string[];
41
+ /** 虚线图标,可用于图例。*/
42
+ export declare const DASHES_ICON: string;
43
+ /** 公用调色板 1。*/
44
+ export declare const PALETTE_1: string[];
45
+ /** 公用调色板 2。*/
46
+ export declare const PALETTE_2: string[];