@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.
- package/dist/components/Auth.d.ts +310 -0
- package/dist/components/Auth.js +267 -0
- package/dist/components/AutoResizedECharts.d.ts +21 -0
- package/dist/components/AutoResizedECharts.js +98 -0
- package/dist/components/Calendar.d.ts +50 -0
- package/dist/components/Calendar.js +130 -0
- package/dist/components/CircularProgress.d.ts +21 -0
- package/dist/components/CircularProgress.js +34 -0
- package/dist/components/ConnectedECharts.d.ts +31 -0
- package/dist/components/ConnectedECharts.js +100 -0
- package/dist/components/ECharts.d.ts +57 -0
- package/dist/components/ECharts.js +255 -0
- package/dist/components/Header.d.ts +67 -0
- package/dist/components/Header.js +171 -0
- package/dist/components/ImageBackground.d.ts +32 -0
- package/dist/components/ImageBackground.js +76 -0
- package/dist/components/IndicatorLight.d.ts +44 -0
- package/dist/components/IndicatorLight.js +124 -0
- package/dist/components/LeftAlignedECharts.d.ts +42 -0
- package/dist/components/LeftAlignedECharts.js +270 -0
- package/dist/components/LineChartEditor.d.ts +74 -0
- package/dist/components/LineChartEditor.js +458 -0
- package/dist/components/LineChartTable.d.ts +38 -0
- package/dist/components/LineChartTable.js +245 -0
- package/dist/components/LinkedLineChart.d.ts +45 -0
- package/dist/components/LinkedLineChart.js +159 -0
- package/dist/components/QuickDateRangePicker.d.ts +30 -0
- package/dist/components/QuickDateRangePicker.js +58 -0
- package/dist/components/SegmentedButtons.d.ts +22 -0
- package/dist/components/SegmentedButtons.js +86 -0
- package/dist/components/Sidebar.d.ts +79 -0
- package/dist/components/Sidebar.js +178 -0
- package/dist/components/TsingrocDatePicker.d.ts +38 -0
- package/dist/components/TsingrocDatePicker.js +64 -0
- package/dist/components/TsingrocTheme.d.ts +15 -0
- package/dist/components/TsingrocTheme.js +72 -0
- package/dist/components/UserButton.d.ts +42 -0
- package/dist/components/UserButton.js +105 -0
- package/dist/components/VerticalColorLegend.d.ts +7 -0
- package/dist/components/VerticalColorLegend.js +208 -0
- package/dist/components/WeatherMap.d.ts +18 -0
- package/dist/components/WeatherMap.js +658 -0
- package/dist/deckgl/TiandituLayer.d.ts +13 -0
- package/dist/deckgl/TiandituLayer.js +44 -0
- package/dist/deckgl/WeatherData.d.ts +53 -0
- package/dist/deckgl/WeatherData.js +94 -0
- package/dist/deckgl/index.d.ts +1 -0
- package/dist/deckgl/index.js +1 -0
- package/dist/echarts/coordinateSystems/grid.d.ts +43 -0
- package/dist/echarts/coordinateSystems/grid.js +107 -0
- package/dist/echarts/coordinateSystems/index.js +2 -0
- package/dist/echarts/coordinateSystems/polar.d.ts +45 -0
- package/dist/echarts/coordinateSystems/polar.js +96 -0
- package/dist/echarts/gl-types.d.js +0 -0
- package/dist/echarts/gl.d.ts +115 -0
- package/dist/echarts/gl.js +47 -0
- package/dist/echarts/index.d.ts +46 -0
- package/dist/echarts/index.js +46 -0
- package/dist/echarts/legend.d.ts +17 -0
- package/dist/echarts/legend.js +15 -0
- package/dist/echarts/radar.d.ts +24 -0
- package/dist/echarts/radar.js +22 -0
- package/dist/echarts/series/barSeries.d.ts +23 -0
- package/dist/echarts/series/barSeries.js +18 -0
- package/dist/echarts/series/boxplotSeries.d.ts +21 -0
- package/dist/echarts/series/boxplotSeries.js +40 -0
- package/dist/echarts/series/index.js +7 -0
- package/dist/echarts/series/intervalSeries.d.ts +32 -0
- package/dist/echarts/series/intervalSeries.js +55 -0
- package/dist/echarts/series/lineSeries.d.ts +36 -0
- package/dist/echarts/series/lineSeries.js +45 -0
- package/dist/echarts/series/maxBarSeries.d.ts +18 -0
- package/dist/echarts/series/maxBarSeries.js +39 -0
- package/dist/echarts/series/pieSeries.d.ts +31 -0
- package/dist/echarts/series/pieSeries.js +47 -0
- package/dist/echarts/series/windLineSeries.d.ts +47 -0
- package/dist/echarts/series/windLineSeries.js +51 -0
- package/{src/echarts/tooltip.ts → dist/echarts/tooltip.d.ts} +1 -5
- package/dist/echarts/tooltip.js +18 -0
- package/dist/env.d.js +0 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +25 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/math.d.ts +9 -0
- package/{src/utils/math.ts → dist/utils/math.js} +2 -2
- package/dist/utils/mock.d.ts +8 -0
- package/dist/utils/mock.js +40 -0
- package/dist/utils/startOfQuarter.d.ts +2 -0
- package/dist/utils/startOfQuarter.js +4 -0
- package/package.json +26 -14
- package/src/components/Auth.tsx +0 -623
- package/src/components/AutoResizedECharts.tsx +0 -70
- package/src/components/Calendar.tsx +0 -182
- package/src/components/CircularProgress.tsx +0 -38
- package/src/components/ConnectedECharts.tsx +0 -62
- package/src/components/ECharts.tsx +0 -206
- package/src/components/Header.tsx +0 -136
- package/src/components/ImageBackground.tsx +0 -58
- package/src/components/IndicatorLight.tsx +0 -106
- package/src/components/LeftAlignedECharts.tsx +0 -190
- package/src/components/LineChartEditor.tsx +0 -558
- package/src/components/LineChartTable.tsx +0 -286
- package/src/components/LinkedECharts.tsx +0 -51
- package/src/components/LinkedLineChart.tsx +0 -144
- package/src/components/QuickDateRangePicker.tsx +0 -84
- package/src/components/SegmentedButtons.tsx +0 -46
- package/src/components/Sidebar.tsx +0 -271
- package/src/components/StrictECharts.d.ts +0 -47
- package/src/components/StrictECharts.js +0 -1
- package/src/components/TsingrocDatePicker.tsx +0 -103
- package/src/components/TsingrocTheme.tsx +0 -48
- package/src/components/UserButton.tsx +0 -165
- package/src/components/VerticalColorLegend.tsx +0 -73
- package/src/components/WeatherMap.tsx +0 -522
- package/src/deckgl/TiandituLayer.ts +0 -56
- package/src/deckgl/WeatherData.ts +0 -157
- package/src/deckgl/index.ts +0 -4
- package/src/echarts/coordinateSystems/grid.ts +0 -143
- package/src/echarts/coordinateSystems/polar.ts +0 -148
- package/src/echarts/gl.ts +0 -159
- package/src/echarts/index.ts +0 -129
- package/src/echarts/legend.ts +0 -36
- package/src/echarts/radar.ts +0 -46
- package/src/echarts/series/barSeries.ts +0 -37
- package/src/echarts/series/boxplotSeries.ts +0 -62
- package/src/echarts/series/intervalSeries.ts +0 -70
- package/src/echarts/series/lineSeries.ts +0 -78
- package/src/echarts/series/maxBarSeries.ts +0 -55
- package/src/echarts/series/pieSeries.ts +0 -76
- package/src/echarts/series/windLineSeries.ts +0 -113
- package/src/index.ts +0 -118
- package/src/types.d.ts +0 -5
- package/src/utils/debug.ts +0 -39
- package/src/utils/mock.ts +0 -69
- package/src/utils/startOfQuarter.ts +0 -6
- /package/{src/echarts/coordinateSystems/index.ts → dist/echarts/coordinateSystems/index.d.ts} +0 -0
- /package/{src/echarts/series/index.ts → dist/echarts/series/index.d.ts} +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import type * as wl from "weatherlayers-gl";
|
|
2
|
-
import type { BitmapBoundingBox } from "@deck.gl/layers";
|
|
3
|
-
|
|
4
|
-
export interface WeatherData {
|
|
5
|
-
dims: {
|
|
6
|
-
longitude: number;
|
|
7
|
-
latitude: number;
|
|
8
|
-
time: number;
|
|
9
|
-
};
|
|
10
|
-
coords: {
|
|
11
|
-
/** deg */
|
|
12
|
-
longitude: number[];
|
|
13
|
-
/** deg */
|
|
14
|
-
latitude: number[];
|
|
15
|
-
/** Unix 时间戳 */
|
|
16
|
-
time: number[];
|
|
17
|
-
};
|
|
18
|
-
data_vars: {
|
|
19
|
-
/** ℃ */
|
|
20
|
-
temperature_2m?: number[][][];
|
|
21
|
-
/** hPa */
|
|
22
|
-
surface_pressure?: number[][][];
|
|
23
|
-
/** % */
|
|
24
|
-
cloud_cover?: number[][][];
|
|
25
|
-
/** ℃ */
|
|
26
|
-
dew_point_2m?: number[][][];
|
|
27
|
-
/** % */
|
|
28
|
-
relative_humidity_2m?: number[][][];
|
|
29
|
-
/** 风速沿纬线向**东**吹(西风)的分量,m/s */
|
|
30
|
-
wind_component_u_10m?: number[][][];
|
|
31
|
-
/** 风速沿经线向**北**吹(南风)的分量,m/s */
|
|
32
|
-
wind_component_v_10m?: number[][][];
|
|
33
|
-
/** m/s */
|
|
34
|
-
wind_speed_10m?: number[][][];
|
|
35
|
-
/** deg,`0` 表示**北风**(往南吹),随着角度增大,风向**顺时针**旋转。*/
|
|
36
|
-
wind_direction_10m?: number[][][];
|
|
37
|
-
/** mm */
|
|
38
|
-
rain?: number[][][];
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const getBounds = (data: WeatherData): BitmapBoundingBox => {
|
|
43
|
-
const [lngMin, lngMax] = [
|
|
44
|
-
data.coords.longitude[0],
|
|
45
|
-
data.coords.longitude.at(-1) as number,
|
|
46
|
-
].sort();
|
|
47
|
-
const [latMin, latMax] = [
|
|
48
|
-
data.coords.latitude[0],
|
|
49
|
-
data.coords.latitude.at(-1) as number,
|
|
50
|
-
].sort();
|
|
51
|
-
return [lngMin, latMin, lngMax, latMax];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export function extractScalarData(
|
|
55
|
-
data: WeatherData,
|
|
56
|
-
variable: keyof WeatherData["data_vars"],
|
|
57
|
-
) {
|
|
58
|
-
const result = Array.from({ length: data.dims.time }, () => ({
|
|
59
|
-
image: {
|
|
60
|
-
data: new Float32Array(data.dims.longitude * data.dims.latitude),
|
|
61
|
-
width: data.dims.longitude,
|
|
62
|
-
height: data.dims.latitude,
|
|
63
|
-
} satisfies wl.TextureData as wl.TextureData,
|
|
64
|
-
min: Infinity,
|
|
65
|
-
max: -Infinity,
|
|
66
|
-
mean: 0,
|
|
67
|
-
}));
|
|
68
|
-
let p = 0;
|
|
69
|
-
for (let i = 0; i < data.dims.longitude; i++) {
|
|
70
|
-
for (let j = 0; j < data.dims.latitude; j++) {
|
|
71
|
-
for (let t = 0; t < data.dims.time; t++) {
|
|
72
|
-
let value = (data.data_vars[variable] as number[][][])[i][j][t];
|
|
73
|
-
if (value === -9999) value = NaN;
|
|
74
|
-
result[t].image.data[p] = value;
|
|
75
|
-
if (value > result[t].max) result[t].max = value;
|
|
76
|
-
if (value < result[t].min) result[t].min = value;
|
|
77
|
-
}
|
|
78
|
-
p++;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
for (const item of result) {
|
|
82
|
-
item.mean =
|
|
83
|
-
(item.image.data as Float32Array).reduce((a, b) => a + b) /
|
|
84
|
-
item.image.data.length;
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function extractVectorData(
|
|
90
|
-
data: WeatherData,
|
|
91
|
-
variableU: keyof WeatherData["data_vars"],
|
|
92
|
-
variableV: keyof WeatherData["data_vars"],
|
|
93
|
-
) {
|
|
94
|
-
const result = Array.from(
|
|
95
|
-
{ length: data.dims.time },
|
|
96
|
-
() =>
|
|
97
|
-
({
|
|
98
|
-
data: new Float32Array(data.dims.longitude * data.dims.latitude * 2),
|
|
99
|
-
width: data.dims.longitude,
|
|
100
|
-
height: data.dims.latitude,
|
|
101
|
-
}) satisfies wl.TextureData as wl.TextureData,
|
|
102
|
-
);
|
|
103
|
-
let p = 0;
|
|
104
|
-
for (let i = 0; i < data.dims.longitude; i++) {
|
|
105
|
-
for (let j = 0; j < data.dims.latitude; j++) {
|
|
106
|
-
for (let t = 0; t < data.dims.time; t++) {
|
|
107
|
-
let u = (data.data_vars[variableU] as number[][][])[i][j][t];
|
|
108
|
-
let v = (data.data_vars[variableV] as number[][][])[i][j][t];
|
|
109
|
-
if (u === -9999) u = NaN;
|
|
110
|
-
if (v === -9999) v = NaN;
|
|
111
|
-
result[t].data[p] = u;
|
|
112
|
-
result[t].data[p + 1] = v;
|
|
113
|
-
}
|
|
114
|
-
p += 2;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function extractMagnitudeData(
|
|
121
|
-
data: WeatherData,
|
|
122
|
-
variableU: keyof WeatherData["data_vars"],
|
|
123
|
-
variableV: keyof WeatherData["data_vars"],
|
|
124
|
-
) {
|
|
125
|
-
const result = Array.from({ length: data.dims.time }, () => ({
|
|
126
|
-
image: {
|
|
127
|
-
data: new Float32Array(data.dims.longitude * data.dims.latitude),
|
|
128
|
-
width: data.dims.longitude,
|
|
129
|
-
height: data.dims.latitude,
|
|
130
|
-
} satisfies wl.TextureData as wl.TextureData,
|
|
131
|
-
min: Infinity,
|
|
132
|
-
max: -Infinity,
|
|
133
|
-
mean: 0,
|
|
134
|
-
}));
|
|
135
|
-
let p = 0;
|
|
136
|
-
for (let i = 0; i < data.dims.longitude; i++) {
|
|
137
|
-
for (let j = 0; j < data.dims.latitude; j++) {
|
|
138
|
-
for (let t = 0; t < data.dims.time; t++) {
|
|
139
|
-
let u = (data.data_vars[variableU] as number[][][])[i][j][t];
|
|
140
|
-
let v = (data.data_vars[variableV] as number[][][])[i][j][t];
|
|
141
|
-
if (u === -9999) u = NaN;
|
|
142
|
-
if (v === -9999) v = NaN;
|
|
143
|
-
const value = Math.sqrt(u * u + v * v);
|
|
144
|
-
result[t].image.data[p] = value;
|
|
145
|
-
if (value > result[t].max) result[t].max = value;
|
|
146
|
-
if (value < result[t].min) result[t].min = value;
|
|
147
|
-
}
|
|
148
|
-
p++;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
for (const item of result) {
|
|
152
|
-
item.mean =
|
|
153
|
-
(item.image.data as Float32Array).reduce((a, b) => a + b) /
|
|
154
|
-
item.image.data.length;
|
|
155
|
-
}
|
|
156
|
-
return result;
|
|
157
|
-
}
|
package/src/deckgl/index.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BarSeriesOption,
|
|
3
|
-
BoxplotSeriesOption,
|
|
4
|
-
FlowGLSeriesOption,
|
|
5
|
-
GridComponentOption,
|
|
6
|
-
LineSeriesOption,
|
|
7
|
-
XAXisComponentOption,
|
|
8
|
-
YAXisComponentOption,
|
|
9
|
-
} from "echarts";
|
|
10
|
-
import { useId } from "react";
|
|
11
|
-
|
|
12
|
-
import type { EChartsComponent, EChartsSeries } from "..";
|
|
13
|
-
|
|
14
|
-
export type GridPreset = (
|
|
15
|
-
grid: GridComponentOption,
|
|
16
|
-
xAxis: XAXisComponentOption,
|
|
17
|
-
yAxis: YAXisComponentOption,
|
|
18
|
-
) => void;
|
|
19
|
-
|
|
20
|
-
export interface GridOption {
|
|
21
|
-
/**
|
|
22
|
-
* 坐标网格的其它设置,参见 [ECharts 文档][1]。
|
|
23
|
-
*
|
|
24
|
-
* [1]: https://echarts.apache.org/zh/option.html#grid
|
|
25
|
-
*/
|
|
26
|
-
option?: GridComponentOption;
|
|
27
|
-
/**
|
|
28
|
-
* X 轴的设置,参见 [ECharts 文档][1]。
|
|
29
|
-
*
|
|
30
|
-
* [1]: https://echarts.apache.org/zh/option.html#xAxis
|
|
31
|
-
*/
|
|
32
|
-
xAxis?: XAXisComponentOption;
|
|
33
|
-
/**
|
|
34
|
-
* Y 轴的设置,参见 [ECharts 文档][1]。
|
|
35
|
-
*
|
|
36
|
-
* [1]: https://echarts.apache.org/zh/option.html#yAxis
|
|
37
|
-
*/
|
|
38
|
-
yAxis?: YAXisComponentOption;
|
|
39
|
-
/**
|
|
40
|
-
* 预设列表。预设的优先级**高于**上述设置。
|
|
41
|
-
*
|
|
42
|
-
* 可用的预设:{@linkcode minimalGrid}
|
|
43
|
-
*/
|
|
44
|
-
presets?: GridPreset[];
|
|
45
|
-
/** 要绘制在该坐标系上的系列。*/
|
|
46
|
-
series?: EChartsSeries<
|
|
47
|
-
| LineSeriesOption
|
|
48
|
-
| BarSeriesOption
|
|
49
|
-
| BoxplotSeriesOption
|
|
50
|
-
| FlowGLSeriesOption
|
|
51
|
-
>[];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
|
|
56
|
-
*/
|
|
57
|
-
export function grid(option: GridOption): EChartsComponent {
|
|
58
|
-
const grid: GridComponentOption = {
|
|
59
|
-
left: 0,
|
|
60
|
-
right: 0,
|
|
61
|
-
top: 24,
|
|
62
|
-
bottom: 0,
|
|
63
|
-
containLabel: true,
|
|
64
|
-
...option.option,
|
|
65
|
-
};
|
|
66
|
-
const xAxis: XAXisComponentOption = {
|
|
67
|
-
id: grid.id === undefined ? undefined : String(grid.id) + "x",
|
|
68
|
-
gridId: grid.id === undefined ? undefined : String(grid.id),
|
|
69
|
-
nameGap: 6,
|
|
70
|
-
...option.xAxis,
|
|
71
|
-
nameTextStyle: { fontWeight: "bold", ...option.xAxis?.nameTextStyle },
|
|
72
|
-
axisTick: {
|
|
73
|
-
alignWithLabel: true,
|
|
74
|
-
...option.xAxis?.axisTick,
|
|
75
|
-
// 此处需要强转,因为 alignWithLabel 仅当 boundaryGap = true 时有效,但无效也没有影响
|
|
76
|
-
} as XAXisComponentOption["axisTick"],
|
|
77
|
-
};
|
|
78
|
-
const xAxisId = xAxis.id as string;
|
|
79
|
-
const yAxis = {
|
|
80
|
-
id: grid.id === undefined ? undefined : String(grid.id) + "y",
|
|
81
|
-
type: "value",
|
|
82
|
-
gridId: grid.id === undefined ? undefined : String(grid.id),
|
|
83
|
-
nameGap: 10,
|
|
84
|
-
...option.yAxis,
|
|
85
|
-
nameTextStyle: {
|
|
86
|
-
align: "left",
|
|
87
|
-
fontWeight: "bold",
|
|
88
|
-
...option.yAxis?.nameTextStyle,
|
|
89
|
-
},
|
|
90
|
-
} as YAXisComponentOption;
|
|
91
|
-
const yAxisId = yAxis.id as string;
|
|
92
|
-
option.presets?.forEach((preset) => preset(grid, xAxis, yAxis));
|
|
93
|
-
return {
|
|
94
|
-
grid: [grid],
|
|
95
|
-
xAxis: [xAxis],
|
|
96
|
-
yAxis: [yAxis],
|
|
97
|
-
series: option.series
|
|
98
|
-
?.flatMap((item) => item.series)
|
|
99
|
-
.map((series) => ({
|
|
100
|
-
...series,
|
|
101
|
-
coordinateSystem: "cartesian2d",
|
|
102
|
-
xAxisId,
|
|
103
|
-
yAxisId,
|
|
104
|
-
})),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 添加一个直角坐标系。X 轴和 Y 轴的数据类型默认值与 ECharts 原版一致。
|
|
110
|
-
*
|
|
111
|
-
* **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
|
|
112
|
-
*/
|
|
113
|
-
export function useGrid(option: GridOption): EChartsComponent {
|
|
114
|
-
return grid({
|
|
115
|
-
...option,
|
|
116
|
-
option: {
|
|
117
|
-
id: useId(),
|
|
118
|
-
...option.option,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const MINIMAL_GRID: GridPreset = (grid, xAxis, yAxis) => {
|
|
124
|
-
grid.top = 0;
|
|
125
|
-
xAxis.show = false;
|
|
126
|
-
if (
|
|
127
|
-
(xAxis.type === undefined && (xAxis as { data?: [] }).data !== undefined) ||
|
|
128
|
-
xAxis.type === "category"
|
|
129
|
-
) {
|
|
130
|
-
(xAxis as { boundaryGap: boolean }).boundaryGap = false;
|
|
131
|
-
} else {
|
|
132
|
-
xAxis.min = "dataMin";
|
|
133
|
-
xAxis.max = "dataMax";
|
|
134
|
-
}
|
|
135
|
-
xAxis.axisLabel = { inside: true };
|
|
136
|
-
yAxis.show = false;
|
|
137
|
-
yAxis.axisLabel = { inside: true };
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/** 使用该预设可以隐藏直角坐标系的坐标轴和网格线,只留下图像本身,并且使其填满整个容器。*/
|
|
141
|
-
export function minimalGrid() {
|
|
142
|
-
return MINIMAL_GRID;
|
|
143
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AngleAxisComponentOption,
|
|
3
|
-
BarSeriesOption,
|
|
4
|
-
LineSeriesOption,
|
|
5
|
-
PolarComponentOption,
|
|
6
|
-
RadiusAxisComponentOption,
|
|
7
|
-
} from "echarts";
|
|
8
|
-
import { useId } from "react";
|
|
9
|
-
|
|
10
|
-
import type { EChartsComponent, EChartsSeries } from "..";
|
|
11
|
-
|
|
12
|
-
export type PolarPreset = (
|
|
13
|
-
polar: PolarComponentOption,
|
|
14
|
-
angleAxis: AngleAxisComponentOption,
|
|
15
|
-
radiusAxis: RadiusAxisComponentOption,
|
|
16
|
-
) => void;
|
|
17
|
-
|
|
18
|
-
export interface PolarOption {
|
|
19
|
-
/**
|
|
20
|
-
* 极坐标系的其它设置,参见 [ECharts 文档][1]。
|
|
21
|
-
*
|
|
22
|
-
* [1]: https://echarts.apache.org/zh/option.html#polar
|
|
23
|
-
*/
|
|
24
|
-
option?: PolarComponentOption;
|
|
25
|
-
/**
|
|
26
|
-
* 角度轴的设置,参见 [ECharts 文档][1]。
|
|
27
|
-
*
|
|
28
|
-
* [1]: https://echarts.apache.org/zh/option.html#angleAxis
|
|
29
|
-
*/
|
|
30
|
-
angleAxis?: AngleAxisComponentOption;
|
|
31
|
-
/**
|
|
32
|
-
* 半径轴的设置,参见 [ECharts 文档][1]。
|
|
33
|
-
*
|
|
34
|
-
* [1]: https://echarts.apache.org/zh/option.html#radiusAxis
|
|
35
|
-
*/
|
|
36
|
-
radiusAxis?: RadiusAxisComponentOption;
|
|
37
|
-
/**
|
|
38
|
-
* 预设列表。预设的优先级**高于**上述设置。
|
|
39
|
-
*
|
|
40
|
-
* 可用的预设:{@linkcode minimalGrid}
|
|
41
|
-
*/
|
|
42
|
-
presets?: PolarPreset[];
|
|
43
|
-
/** 要绘制在该坐标系上的系列。*/
|
|
44
|
-
series?: EChartsSeries<LineSeriesOption | BarSeriesOption>[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
|
|
49
|
-
*/
|
|
50
|
-
export function polar(option: PolarOption): EChartsComponent {
|
|
51
|
-
const polar: PolarComponentOption = option.option ?? {};
|
|
52
|
-
const angleAxis = {
|
|
53
|
-
id: polar.id === undefined ? undefined : String(polar.id) + "angle",
|
|
54
|
-
polarId: polar.id === undefined ? undefined : String(polar.id),
|
|
55
|
-
...option.angleAxis,
|
|
56
|
-
axisLabel: {
|
|
57
|
-
margin: 3,
|
|
58
|
-
fontSize: 10,
|
|
59
|
-
...option.angleAxis?.axisLabel,
|
|
60
|
-
},
|
|
61
|
-
axisLine: {
|
|
62
|
-
show: false,
|
|
63
|
-
...option.angleAxis?.axisLine,
|
|
64
|
-
},
|
|
65
|
-
splitLine: {
|
|
66
|
-
show: true,
|
|
67
|
-
...option.angleAxis?.splitLine,
|
|
68
|
-
},
|
|
69
|
-
} as AngleAxisComponentOption;
|
|
70
|
-
const angleAxisId = angleAxis.id as string;
|
|
71
|
-
const radiusAxis = {
|
|
72
|
-
id: polar.id === undefined ? undefined : String(polar.id) + "radius",
|
|
73
|
-
type: "value",
|
|
74
|
-
polarId: polar.id === undefined ? undefined : String(polar.id),
|
|
75
|
-
...option.radiusAxis,
|
|
76
|
-
axisLine: {
|
|
77
|
-
show: false,
|
|
78
|
-
...option.radiusAxis?.axisLine,
|
|
79
|
-
},
|
|
80
|
-
} as RadiusAxisComponentOption;
|
|
81
|
-
const radiusAxisId = radiusAxis.id as string;
|
|
82
|
-
option.presets?.forEach((preset) => preset(polar, angleAxis, radiusAxis));
|
|
83
|
-
return {
|
|
84
|
-
polar: [polar],
|
|
85
|
-
angleAxis: [angleAxis],
|
|
86
|
-
radiusAxis: [radiusAxis],
|
|
87
|
-
series: option.series
|
|
88
|
-
?.flatMap((item) => item.series)
|
|
89
|
-
.map((series) => ({
|
|
90
|
-
...series,
|
|
91
|
-
coordinateSystem: "polar",
|
|
92
|
-
angleAxisId,
|
|
93
|
-
radiusAxisId,
|
|
94
|
-
})),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 添加一个极坐标系。角度轴和半径轴的数据类型默认值与 ECharts 原版一致。
|
|
100
|
-
*
|
|
101
|
-
* **注意**:该组件是一个 React hook,需要遵守正常使用 hook 的准则。
|
|
102
|
-
*/
|
|
103
|
-
export function usePolar(option: PolarOption): EChartsComponent {
|
|
104
|
-
return polar({
|
|
105
|
-
...option,
|
|
106
|
-
option: {
|
|
107
|
-
id: useId(),
|
|
108
|
-
...option.option,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const WIND_POLAR: PolarPreset = (_, angleAxis, radiusAxis) => {
|
|
114
|
-
angleAxis.type = "category";
|
|
115
|
-
(angleAxis as AngleAxisComponentOption & { data: readonly string[] }).data =
|
|
116
|
-
WIND_DIRECTION_NAMES;
|
|
117
|
-
angleAxis.startAngle = 101.25;
|
|
118
|
-
radiusAxis.axisLabel = {
|
|
119
|
-
...radiusAxis.axisLabel,
|
|
120
|
-
verticalAlign: "top",
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 使用该预设可以将极坐标系的角度轴设置为 16 个风向,风向从正北开始,按顺时针方向排列。
|
|
126
|
-
*/
|
|
127
|
-
export function windPolar(): PolarPreset {
|
|
128
|
-
return WIND_POLAR;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const WIND_DIRECTION_NAMES = [
|
|
132
|
-
"N",
|
|
133
|
-
"NNE",
|
|
134
|
-
"NE",
|
|
135
|
-
"ENE",
|
|
136
|
-
"E",
|
|
137
|
-
"ESE",
|
|
138
|
-
"SE",
|
|
139
|
-
"SSE",
|
|
140
|
-
"S",
|
|
141
|
-
"SSW",
|
|
142
|
-
"SW",
|
|
143
|
-
"WSW",
|
|
144
|
-
"W",
|
|
145
|
-
"WNW",
|
|
146
|
-
"NW",
|
|
147
|
-
"NNW",
|
|
148
|
-
] as const;
|
package/src/echarts/gl.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import type { FlowGLSeriesOption as OrigFlowGLSeriesOption } from "echarts";
|
|
2
|
-
import type {
|
|
3
|
-
ComponentOption,
|
|
4
|
-
SeriesOnCartesianOptionMixin,
|
|
5
|
-
SeriesOnGeoOptionMixin,
|
|
6
|
-
} from "echarts/types/src/util/types.js";
|
|
7
|
-
|
|
8
|
-
import "echarts-gl";
|
|
9
|
-
|
|
10
|
-
import type { EChartsSeries } from ".";
|
|
11
|
-
|
|
12
|
-
// 由于官方没有提供类型定义,这里只能自行补充
|
|
13
|
-
declare module "echarts/types/dist/echarts" {
|
|
14
|
-
interface RegisteredSeriesOption {
|
|
15
|
-
flowGL: FlowGLSeriesOption;
|
|
16
|
-
}
|
|
17
|
-
interface FlowGLSeriesOption
|
|
18
|
-
extends ComponentOption,
|
|
19
|
-
SeriesOnCartesianOptionMixin,
|
|
20
|
-
SeriesOnGeoOptionMixin {
|
|
21
|
-
type: "flowGL";
|
|
22
|
-
/**
|
|
23
|
-
* 粒子的密度,实际的粒子数量是设置数目的平方。粒子密度越大迹线效果越好,但是性能开销也会越大。
|
|
24
|
-
* 除了该属性,使用 `particleType` 也可以得到更加清晰连贯的迹线。
|
|
25
|
-
* @default 128
|
|
26
|
-
*/
|
|
27
|
-
particleDensity?: number;
|
|
28
|
-
/**
|
|
29
|
-
* 粒子的类型,可以设置为点 `"point"` 或线 `"line"`。
|
|
30
|
-
* 线类型的粒子会用一条线连接上个运动的位置和当前运动的位置,这会让这个轨迹更加连贯。
|
|
31
|
-
* @default "point"
|
|
32
|
-
*/
|
|
33
|
-
particleType?: "point" | "line";
|
|
34
|
-
/**
|
|
35
|
-
* 粒子的大小,如果 `particleType == "line"` 则代表线宽。
|
|
36
|
-
* @default 1
|
|
37
|
-
*/
|
|
38
|
-
particleSize?: number;
|
|
39
|
-
/**
|
|
40
|
-
* 粒子的速度,默认为 1。注意在 `particleType` 为 `"point"` 的时候过大的速度会让整个轨迹变得断断续续。
|
|
41
|
-
* @default 1
|
|
42
|
-
*/
|
|
43
|
-
particleSpeed?: number;
|
|
44
|
-
/**
|
|
45
|
-
* 粒子的轨迹长度,数值越大轨迹越长。
|
|
46
|
-
* @default 2
|
|
47
|
-
*/
|
|
48
|
-
particleTrail?: number;
|
|
49
|
-
/**
|
|
50
|
-
* 画面的超采样比率,采用 4 的超采样可以有效的提高画面的清晰度,减少画面锯齿。
|
|
51
|
-
* 但是因为需要处理更多的像素数量,所以也对性能有更高的要求。
|
|
52
|
-
* @default 1
|
|
53
|
-
*/
|
|
54
|
-
supersampling?: number;
|
|
55
|
-
/**
|
|
56
|
-
* 传入的网格数据的网格宽度数量。
|
|
57
|
-
* @default "auto"
|
|
58
|
-
*/
|
|
59
|
-
gridWidth?: number | "auto";
|
|
60
|
-
/**
|
|
61
|
-
* 传入的网格数据的网格高度数量。
|
|
62
|
-
* @default "auto"
|
|
63
|
-
*/
|
|
64
|
-
gridHeight?: number | "auto";
|
|
65
|
-
/**
|
|
66
|
-
* 每行数据包含四个值,分别表示位置 x、y,速度 sx、sy。
|
|
67
|
-
* 如果使用地理坐标系,则分别表示位置 lng、lat,速度 sLng、sLat。
|
|
68
|
-
*/
|
|
69
|
-
data: [number, number, number, number][];
|
|
70
|
-
/**
|
|
71
|
-
* 向量场迹线的样式。
|
|
72
|
-
*/
|
|
73
|
-
itemStyle?: FlowGLSeriesItemStyle;
|
|
74
|
-
}
|
|
75
|
-
interface FlowGLSeriesItemStyle {
|
|
76
|
-
/**
|
|
77
|
-
* 向量场迹线的颜色。
|
|
78
|
-
* @default "#fff"
|
|
79
|
-
*/
|
|
80
|
-
color?: string;
|
|
81
|
-
/**
|
|
82
|
-
* 向量场迹线的透明度。
|
|
83
|
-
* @default 0.8
|
|
84
|
-
*/
|
|
85
|
-
opacity?: number;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface FlowGLSeriesOption {
|
|
90
|
-
/** 系列名称,不可与其他系列重名。*/
|
|
91
|
-
name: string;
|
|
92
|
-
/**
|
|
93
|
-
* 每行数据包含四个值,分别表示位置 x、y,速度 sx、sy。
|
|
94
|
-
*
|
|
95
|
-
* 如果需要使用风场数据,可以直接调用 {@linkcode preprocessWindData} 来将数据处理成此处需要的格式。
|
|
96
|
-
*/
|
|
97
|
-
data: [number, number, number, number][];
|
|
98
|
-
/**
|
|
99
|
-
* 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
|
|
100
|
-
*
|
|
101
|
-
* [1]: https://echarts.apache.org/zh/option-gl.html#series-flowGL
|
|
102
|
-
*/
|
|
103
|
-
option?: Partial<OrigFlowGLSeriesOption>;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 在坐标系上绘制一个流场。
|
|
108
|
-
*
|
|
109
|
-
* 推荐使用以下坐标系配置:
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* echarts.useGrid({
|
|
113
|
-
* xAxis: { type: "value" },
|
|
114
|
-
* yAxis: { min: "dataMin", max: "dataMax" },
|
|
115
|
-
* presets: [echarts.minimalGrid()],
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export function flowGLSeries(
|
|
120
|
-
option: FlowGLSeriesOption,
|
|
121
|
-
): EChartsSeries<OrigFlowGLSeriesOption> {
|
|
122
|
-
return {
|
|
123
|
-
series: [
|
|
124
|
-
{
|
|
125
|
-
type: "flowGL",
|
|
126
|
-
id: option.name,
|
|
127
|
-
name: option.name,
|
|
128
|
-
data: option.data,
|
|
129
|
-
particleDensity: 20,
|
|
130
|
-
particleSize: 3,
|
|
131
|
-
supersampling: window.devicePixelRatio,
|
|
132
|
-
...option.option,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface WindData {
|
|
139
|
-
/** 位置,由空格分隔的经纬度数字组成。*/
|
|
140
|
-
location: string;
|
|
141
|
-
/** 风向,单位是角度(deg),`0` 表示**东风**,随着角度增大,风向**顺时针**旋转。*/
|
|
142
|
-
wind_direction_80m: number;
|
|
143
|
-
/** 风速。*/
|
|
144
|
-
wind_speed_80m: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** 将 JSON 格式的天气数据预处理成 FlowGL 接受的格式。*/
|
|
148
|
-
export function preprocessWindData(
|
|
149
|
-
data: WindData[],
|
|
150
|
-
): [number, number, number, number][] {
|
|
151
|
-
return data.map((item) => {
|
|
152
|
-
const [x, y] = item.location.split(" ").map(Number.parseFloat);
|
|
153
|
-
// prettier-ignore
|
|
154
|
-
const sx = -Math.cos(item.wind_direction_80m * (Math.PI / 180)) * item.wind_speed_80m;
|
|
155
|
-
// prettier-ignore
|
|
156
|
-
const sy = +Math.sin(item.wind_direction_80m * (Math.PI / 180)) * item.wind_speed_80m;
|
|
157
|
-
return [x, y, sx, sy];
|
|
158
|
-
});
|
|
159
|
-
}
|