@tsingroc/tsingroc-components 3.14.0 → 4.0.0

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 (38) hide show
  1. package/dist/components/Auth.d.ts +98 -15
  2. package/dist/components/Auth.js +147 -63
  3. package/dist/components/Auth.js.map +1 -1
  4. package/dist/components/TsingrocTheme.js +1 -1
  5. package/dist/components/TsingrocTheme.js.map +1 -1
  6. package/dist/components/UserButton.js +24 -17
  7. package/dist/components/UserButton.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/package.json +11 -11
  11. package/src/components/Auth.tsx +608 -0
  12. package/src/components/Calendar.tsx +182 -0
  13. package/src/components/CircularProgress.tsx +38 -0
  14. package/src/components/Header.tsx +136 -0
  15. package/src/components/ImageBackground.tsx +58 -0
  16. package/src/components/IndicatorLight.tsx +106 -0
  17. package/src/components/LineChartEditor.tsx +558 -0
  18. package/src/components/LineChartTable.tsx +285 -0
  19. package/src/components/LinkedLineChart.tsx +223 -0
  20. package/src/components/QuickDateRangePicker.tsx +84 -0
  21. package/src/components/SegmentedButtons.tsx +46 -0
  22. package/src/components/Sidebar.tsx +250 -0
  23. package/src/components/TsingrocDatePicker.tsx +103 -0
  24. package/src/components/TsingrocTheme.tsx +47 -0
  25. package/src/components/UserButton.tsx +168 -0
  26. package/src/components/VerticalColorLegend.tsx +73 -0
  27. package/src/components/WeatherMap.tsx +521 -0
  28. package/src/deckgl/TiandituLayer.ts +56 -0
  29. package/src/deckgl/WeatherData.ts +157 -0
  30. package/src/deckgl/index.ts +4 -0
  31. package/src/echarts/coordinateSystem.ts +132 -0
  32. package/src/echarts/gl.ts +158 -0
  33. package/src/echarts/index.ts +120 -0
  34. package/src/echarts/legend.ts +36 -0
  35. package/src/echarts/radar.ts +46 -0
  36. package/src/echarts/series.ts +441 -0
  37. package/src/echarts/tooltip.ts +17 -0
  38. package/src/index.ts +82 -0
@@ -0,0 +1,441 @@
1
+ import type {
2
+ Color,
3
+ BarSeriesOption as OrigBarSeriesOption,
4
+ BoxplotSeriesOption as OrigBoxplotSeriesOption,
5
+ LineSeriesOption as OrigLineSeriesOption,
6
+ PieSeriesOption as OrigPieSeriesOption,
7
+ } from "echarts";
8
+
9
+ import type { EChartsSeries } from ".";
10
+
11
+ export type DataItem = number | string | undefined;
12
+
13
+ export type LineSeriesPreset = (option: OrigLineSeriesOption) => void;
14
+
15
+ export interface LineSeriesOption {
16
+ /** 系列名称,不可与其他系列重名。*/
17
+ name: string;
18
+ /**
19
+ * 折线的数据。
20
+ *
21
+ * 数据的结构是二维数组,每一行表示一个数据点,第一、第二列分别代表两个轴。
22
+ * 若两个轴中有且只有一个是类目轴,则数据类型可以是一维数组,表示另一个轴的值。
23
+ */
24
+ data: [DataItem, DataItem, ...DataItem[]][] | DataItem[];
25
+ /**
26
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
27
+ *
28
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
29
+ */
30
+ option?: OrigLineSeriesOption;
31
+ /**
32
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
33
+ *
34
+ * 可用的预设:{@linkcode gradientArea}
35
+ */
36
+ presets?: LineSeriesPreset[];
37
+ }
38
+
39
+ /**
40
+ * 在坐标系上添加一条折线。
41
+ */
42
+ export function lineSeries(
43
+ option: LineSeriesOption,
44
+ ): EChartsSeries<OrigLineSeriesOption> {
45
+ const series: OrigLineSeriesOption = {
46
+ type: "line",
47
+ id: option.name,
48
+ name: option.name,
49
+ data: option.data,
50
+ smooth: true,
51
+ showSymbol: false,
52
+ ...option.option,
53
+ };
54
+ option.presets?.forEach((preset) => preset(series));
55
+ return { series: [series] };
56
+ }
57
+
58
+ /**
59
+ * 折线图预设,使折线下方区域在纵向呈现线性渐变色。
60
+ *
61
+ * 参数 `top` 表示顶部颜色;参数 `bottom` 表示底部颜色,默认为全透明 `"transparent"`。
62
+ */
63
+ export function gradientArea(
64
+ top: string,
65
+ bottom: string = "transparent",
66
+ ): LineSeriesPreset {
67
+ return (option) => {
68
+ (option.areaStyle ??= {}).color = {
69
+ type: "linear",
70
+ x: 0,
71
+ y: 0,
72
+ x2: 0,
73
+ y2: 1,
74
+ colorStops: [
75
+ {
76
+ offset: 0,
77
+ color: top,
78
+ },
79
+ {
80
+ offset: 1,
81
+ color: bottom,
82
+ },
83
+ ],
84
+ };
85
+ };
86
+ }
87
+
88
+ export interface IntervalSeriesOption {
89
+ /** 系列名称,不可与其他系列重名。*/
90
+ name: string;
91
+ /**
92
+ * 区间的下边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
93
+ *
94
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
95
+ */
96
+ min: OrigLineSeriesOption & { data: number[] };
97
+ /**
98
+ * 区间的上边界,请将最小值数据填入此处。其它设置参见 [ECharts 文档][1]。
99
+ *
100
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
101
+ */
102
+ max: OrigLineSeriesOption & { data: number[] };
103
+ /**
104
+ * 区间条带,此处必须设置一个颜色。其它设置参见 [ECharts 文档][1]。
105
+ *
106
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
107
+ */
108
+ interval: OrigLineSeriesOption & { color: Color };
109
+ }
110
+
111
+ const INTERVAL_SERIES_DEFAULTS: OrigLineSeriesOption = {
112
+ type: "line",
113
+ smooth: true,
114
+ showSymbol: false,
115
+ lineStyle: { opacity: 0 },
116
+ emphasis: { disabled: true },
117
+ };
118
+
119
+ /** 绘制一个从下边界到上边界的带状区间。*/
120
+ export function intervalSeries(
121
+ option: IntervalSeriesOption,
122
+ ): EChartsSeries<OrigLineSeriesOption> {
123
+ // TODO i18n
124
+ const min: OrigLineSeriesOption = {
125
+ id: option.name + "下边界",
126
+ name: option.name + "下边界",
127
+ stack: option.name,
128
+ ...INTERVAL_SERIES_DEFAULTS,
129
+ ...option.min,
130
+ };
131
+ const max: OrigLineSeriesOption = {
132
+ id: option.name + "上边界",
133
+ name: option.name + "上边界",
134
+ ...INTERVAL_SERIES_DEFAULTS,
135
+ ...option.max,
136
+ };
137
+ const interval: OrigLineSeriesOption = {
138
+ id: option.name,
139
+ name: option.name,
140
+ stack: option.name,
141
+ stackStrategy: "all",
142
+ symbol: "none",
143
+ data: Array.from(
144
+ { length: option.min.data.length },
145
+ (_, i) => option.max.data[i] - option.min.data[i],
146
+ ),
147
+ ...INTERVAL_SERIES_DEFAULTS,
148
+ ...option.interval,
149
+ tooltip: { show: false, ...option.interval.tooltip },
150
+ areaStyle: { color: option.interval.color, ...option.interval.areaStyle },
151
+ };
152
+ return { series: [min, interval, max] };
153
+ }
154
+
155
+ export interface WindLineSeriesOption {
156
+ /** 系列名称,不可与其他系列重名。*/
157
+ name: string;
158
+ /**
159
+ * 风力数据,支持两种形式:
160
+ *
161
+ * - `type: "cartesian"`,用沿经线和沿纬线的风速分量表示风力;
162
+ * - `type: "polar"`,用风速和风向表示风力。
163
+ */
164
+ data:
165
+ | {
166
+ type: "cartesian";
167
+ /** 沿纬线向**东**吹(西风)的风速分量,单位 m/s。*/
168
+ u: number[];
169
+ /** 沿经线向**北**吹(南风)的风速分量,单位 m/s。*/
170
+ v: number[];
171
+ }
172
+ | {
173
+ type: "polar";
174
+ /** 风速,单位 m/s。*/
175
+ speed: number[];
176
+ /** 风向,单位是角度(deg),`0` 表示**北风**(往南吹),随着角度增大,风向**顺时针**旋转。*/
177
+ direction: number[];
178
+ };
179
+ /**
180
+ * 风向标的宽度和长度。
181
+ * @default [10, 20]
182
+ */
183
+ symbolSize?: [number, number];
184
+ /**
185
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
186
+ *
187
+ * [1]: https://echarts.apache.org/zh/option.html#series-line
188
+ */
189
+ option?: OrigLineSeriesOption;
190
+ /**
191
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
192
+ *
193
+ * 可用的预设:{@linkcode gradientArea}
194
+ */
195
+ presets?: LineSeriesPreset[];
196
+ }
197
+
198
+ /**
199
+ * 风速风向折线图。
200
+ */
201
+ export function windLineSeries(
202
+ option: WindLineSeriesOption,
203
+ ): EChartsSeries<OrigLineSeriesOption> {
204
+ const data = option.data;
205
+ const { speed, direction } =
206
+ data.type === "polar"
207
+ ? data
208
+ : {
209
+ speed: data.u.map((u, i) => Math.sqrt(u * u + data.v[i] * data.v[i])),
210
+ direction: data.u.map(
211
+ (u, i) => (Math.atan2(-u, -data.v[i]) / Math.PI) * 180,
212
+ ),
213
+ };
214
+ const symbolSize = option.symbolSize ?? [10, 20];
215
+ const series: OrigLineSeriesOption = {
216
+ type: "line",
217
+ id: option.name,
218
+ name: option.name,
219
+ data: speed,
220
+ smooth: true,
221
+ symbol: "arrow",
222
+ symbolSize: symbolSize,
223
+ symbolOffset: (data, param) => {
224
+ const rad = (direction[param.dataIndex] / 180) * Math.PI;
225
+ const halfSize = symbolSize[1] / 2;
226
+ return [-halfSize * Math.sin(rad), halfSize * Math.cos(rad)];
227
+ },
228
+ symbolRotate: (data, param) => 180 - direction[param.dataIndex],
229
+ ...option.option,
230
+ itemStyle: {
231
+ borderWidth: 1,
232
+ borderColor: "#fff",
233
+ ...option.option?.itemStyle,
234
+ },
235
+ tooltip: {
236
+ valueFormatter: (value, index) =>
237
+ (value as number).toFixed(2) +
238
+ " m/s," +
239
+ WIND_DIRECTIONS[(Math.round(direction[index] / 45) + 8) % 8] +
240
+ "风",
241
+ ...option.option?.tooltip,
242
+ },
243
+ };
244
+ option.presets?.forEach((preset) => preset(series));
245
+ return { series: [series] };
246
+ }
247
+
248
+ const WIND_DIRECTIONS = [
249
+ "北",
250
+ "东北",
251
+ "东",
252
+ "东南",
253
+ "南",
254
+ "西南",
255
+ "西",
256
+ "西北",
257
+ ];
258
+
259
+ export interface MaxBarSeriesOption {
260
+ /** 系列名称,不可与其他系列重名。*/
261
+ name: string;
262
+ /** 需要求最大值的各个系列的数据。*/
263
+ data: (number | undefined)[][];
264
+ /** 各个系列的颜色,各个最大值条形将被设为对应的颜色。若留空,则使用默认颜色。*/
265
+ palette?: Color[];
266
+ /**
267
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
268
+ *
269
+ * [1]: https://echarts.apache.org/zh/option.html#series-bar
270
+ */
271
+ option?: OrigBarSeriesOption;
272
+ }
273
+
274
+ /** 求出多个系列的最大值,显示为条形图。*/
275
+ export function maxBarSeries(
276
+ option: MaxBarSeriesOption,
277
+ ): EChartsSeries<OrigBarSeriesOption> {
278
+ const series: OrigBarSeriesOption = {
279
+ type: "bar",
280
+ id: option.name,
281
+ name: option.name,
282
+ data: Array.from({ length: option.data[0].length }, (_, i) => {
283
+ // prettier-ignore
284
+ const [max, maxJ] = option.data
285
+ .map((series) => series[i])
286
+ .reduce<[number | undefined, number]>(
287
+ ([max, maxJ], y, j) =>
288
+ max === undefined || (y !== undefined && y > max)
289
+ ? [y, j]
290
+ : [max, maxJ],
291
+ [undefined, -1]
292
+ );
293
+ if (max !== undefined && option.palette) {
294
+ return {
295
+ value: max,
296
+ itemStyle: {
297
+ color: option.palette[maxJ],
298
+ },
299
+ };
300
+ } else {
301
+ return max;
302
+ }
303
+ }),
304
+ ...option.option,
305
+ itemStyle: { opacity: 0.7, ...option.option?.itemStyle },
306
+ tooltip: { show: false, ...option.option?.tooltip },
307
+ };
308
+ return { series: [series] };
309
+ }
310
+
311
+ /** 饼图的数据项。*/
312
+ export type PieDataItem = (OrigPieSeriesOption["data"] & {})[0] extends
313
+ | number
314
+ | string
315
+ | unknown[]
316
+ | infer T
317
+ ? T
318
+ : never;
319
+
320
+ export type PieSeriesPreset = (option: OrigPieSeriesOption) => void;
321
+
322
+ export interface PieSeriesOption {
323
+ /** 系列名称,不可与其他系列重名。*/
324
+ name: string;
325
+ /** 饼图的数据,数组元素可以是单个数值或者一个对象。*/
326
+ data: (number | PieDataItem)[];
327
+ /**
328
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。优先级**低于**预设 `presets`。
329
+ *
330
+ * [1]: https://echarts.apache.org/zh/option.html#series-pie
331
+ */
332
+ option?: OrigPieSeriesOption;
333
+ /**
334
+ * 需要应用的配置预设。预设的优先级**高于** `option`。
335
+ *
336
+ * 可用的预设:{@linkcode ringPie}
337
+ */
338
+ presets?: PieSeriesPreset[];
339
+ }
340
+
341
+ /**
342
+ * 添加一个饼图。
343
+ *
344
+ * 请使用 ECharts 的 legend 组件来添加图例,不要手动编写 React 代码制作图例。
345
+ */
346
+ export function pieSeries(
347
+ option: PieSeriesOption,
348
+ ): EChartsSeries<OrigPieSeriesOption> {
349
+ const series: OrigPieSeriesOption = {
350
+ type: "pie",
351
+ id: option.name,
352
+ name: option.name,
353
+ data: option.data,
354
+ ...option.option,
355
+ };
356
+ option.presets?.forEach((preset) => preset(series));
357
+ return { series: [series] };
358
+ }
359
+
360
+ const RING_PIE = (option: OrigPieSeriesOption) => {
361
+ option.radius = ["43%", "75%"];
362
+ option.avoidLabelOverlap = false;
363
+ option.label = {
364
+ show: false,
365
+ position: "center",
366
+ };
367
+ option.labelLine = {
368
+ show: false,
369
+ };
370
+ option.emphasis = {
371
+ label: {
372
+ show: true,
373
+ fontSize: 16,
374
+ fontWeight: "bold",
375
+ },
376
+ };
377
+ };
378
+
379
+ /** 饼图预设,使饼图变为环状,标签出现在环的中央。*/
380
+ export function ringPie(): PieSeriesPreset {
381
+ return RING_PIE;
382
+ }
383
+
384
+ export interface BoxplotSeriesOption {
385
+ /** 系列名称,不可与其他系列重名。*/
386
+ name: string;
387
+ /** 箱线图的数据,每一行按顺序分别是最小值、下四分位数、中位数、上四分位数、最大值。*/
388
+ data: [number, number, number, number, number][];
389
+ /**
390
+ * 每个数据值的格式化函数。
391
+ * @default (value) => value.toFixed(2)
392
+ */
393
+ valueFormatter?: (value: number) => string;
394
+ /**
395
+ * 其它需要添加到系列上的选项,参见 [ECharts 文档][1]。
396
+ *
397
+ * [1]: https://echarts.apache.org/zh/option.html#series-boxplot
398
+ */
399
+ option?: OrigBoxplotSeriesOption;
400
+ }
401
+
402
+ /** 在坐标系上添加一组箱线图。*/
403
+ export function boxplotSeries(
404
+ option: BoxplotSeriesOption,
405
+ ): EChartsSeries<OrigBoxplotSeriesOption> {
406
+ const valueFormatter = option.valueFormatter ?? ((value) => value.toFixed(2));
407
+ const series: OrigBoxplotSeriesOption = {
408
+ type: "boxplot",
409
+ id: option.name,
410
+ name: option.name,
411
+ data: option.data,
412
+ ...option.option,
413
+ tooltip: {
414
+ formatter: (param) => {
415
+ // prettier-ignore
416
+ const data = param.data as (
417
+ [number | string, number, number, number, number, number]
418
+ );
419
+ const strong = (body: string) =>
420
+ `<strong style="text-align: right;">${body}</strong>`;
421
+ // TODO i18n
422
+ return `
423
+ ${param.name}<br>
424
+ <div style="
425
+ display: inline-grid;
426
+ grid: auto-flow / auto auto;
427
+ gap: 0 20px;
428
+ ">
429
+ 最大值 ${strong(valueFormatter(data[5]))}
430
+ 上四分位数 ${strong(valueFormatter(data[4]))}
431
+ 中位数 ${strong(valueFormatter(data[3]))}
432
+ 下四分位数 ${strong(valueFormatter(data[2]))}
433
+ 最小值 ${strong(valueFormatter(data[1]))}
434
+ </div>
435
+ `;
436
+ },
437
+ ...option.option?.tooltip,
438
+ },
439
+ };
440
+ return { series: [series] };
441
+ }
@@ -0,0 +1,17 @@
1
+ import type { TooltipComponentOption } from "echarts";
2
+
3
+ import type { EChartsComponent } from ".";
4
+
5
+ /**
6
+ * 添加悬停提示。这只是对官方 tooltip 组件的简单包装,设置参见 [ECharts 文档][1]。
7
+ *
8
+ * **注意**:ECharts 尚不支持多个 tooltip,在含有多个图表的
9
+ * ECharts 实例中 tooltip 的 `trigger` 值必须支持所有图表。
10
+ * 因此,若需要对每个图表使用不同的 tooltip 设置,请将其拆分成多个
11
+ * ECharts 实例。
12
+ *
13
+ * [1]: https://echarts.apache.org/zh/option.html#tooltip
14
+ */
15
+ export function tooltip(option: TooltipComponentOption = {}): EChartsComponent {
16
+ return { tooltip: [option] };
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ export {
2
+ AuthProvider,
3
+ type AuthProviderProps,
4
+ AuthCheck,
5
+ type AuthCheckProps,
6
+ AuthCallback,
7
+ type AuthCallbackProps,
8
+ useAuth,
9
+ type Auth,
10
+ type CasdoorAuth,
11
+ type LocalAuth,
12
+ } from "./components/Auth";
13
+
14
+ export { default as Calendar, type CalendarProps } from "./components/Calendar";
15
+
16
+ export {
17
+ default as CircularProgress,
18
+ type CircularProgressProps,
19
+ } from "./components/CircularProgress";
20
+
21
+ export { default as Header, type HeaderProps } from "./components/Header";
22
+
23
+ export {
24
+ default as ImageBackground,
25
+ type ImageBackgroundProps,
26
+ } from "./components/ImageBackground";
27
+
28
+ export {
29
+ default as IndicatorLight,
30
+ type IndicatorLightProps,
31
+ } from "./components/IndicatorLight";
32
+
33
+ export {
34
+ default as LineChartEditor,
35
+ type LineChartEditorProps,
36
+ } from "./components/LineChartEditor";
37
+
38
+ export {
39
+ default as LineChartTable,
40
+ type LineChartTableProps,
41
+ } from "./components/LineChartTable";
42
+
43
+ export {
44
+ default as LinkedLineChart,
45
+ LineChartLinkProvider,
46
+ type LinkedLineChartProps,
47
+ type LineChartLinkProviderProps,
48
+ } from "./components/LinkedLineChart";
49
+
50
+ export {
51
+ default as QuickDateRangePicker,
52
+ type QuickDateRangePickerProps,
53
+ } from "./components/QuickDateRangePicker";
54
+
55
+ export {
56
+ default as SegmentedButtons,
57
+ TimeUnitSwitcher,
58
+ type TimeUnitSwitcherProps,
59
+ } from "./components/SegmentedButtons";
60
+
61
+ export { default as Sidebar, type SidebarProps } from "./components/Sidebar";
62
+
63
+ export {
64
+ default as TsingrocDatePicker,
65
+ type DatePickerProps,
66
+ } from "./components/TsingrocDatePicker";
67
+
68
+ export {
69
+ default as TsingrocTheme,
70
+ type TsingrocThemeProps,
71
+ } from "./components/TsingrocTheme";
72
+
73
+ export {
74
+ default as UserButton,
75
+ type UserButtonProps,
76
+ } from "./components/UserButton";
77
+
78
+ export {
79
+ default as WeatherMap,
80
+ type WeatherMapProps,
81
+ type WeatherData,
82
+ } from "./components/WeatherMap";