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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/components/Auth.d.ts +310 -0
  2. package/dist/components/Auth.js +267 -0
  3. package/dist/components/AutoResizedECharts.d.ts +21 -0
  4. package/dist/components/AutoResizedECharts.js +98 -0
  5. package/dist/components/Calendar.d.ts +50 -0
  6. package/dist/components/Calendar.js +130 -0
  7. package/dist/components/CircularProgress.d.ts +21 -0
  8. package/dist/components/CircularProgress.js +34 -0
  9. package/dist/components/ConnectedECharts.d.ts +31 -0
  10. package/dist/components/ConnectedECharts.js +100 -0
  11. package/dist/components/ECharts.d.ts +57 -0
  12. package/dist/components/ECharts.js +255 -0
  13. package/dist/components/Header.d.ts +67 -0
  14. package/dist/components/Header.js +171 -0
  15. package/dist/components/ImageBackground.d.ts +32 -0
  16. package/dist/components/ImageBackground.js +76 -0
  17. package/dist/components/IndicatorLight.d.ts +44 -0
  18. package/dist/components/IndicatorLight.js +124 -0
  19. package/dist/components/LeftAlignedECharts.d.ts +42 -0
  20. package/dist/components/LeftAlignedECharts.js +270 -0
  21. package/dist/components/LineChartEditor.d.ts +74 -0
  22. package/dist/components/LineChartEditor.js +458 -0
  23. package/dist/components/LineChartTable.d.ts +38 -0
  24. package/dist/components/LineChartTable.js +245 -0
  25. package/dist/components/LinkedLineChart.d.ts +45 -0
  26. package/dist/components/LinkedLineChart.js +159 -0
  27. package/dist/components/QuickDateRangePicker.d.ts +30 -0
  28. package/dist/components/QuickDateRangePicker.js +58 -0
  29. package/dist/components/SegmentedButtons.d.ts +22 -0
  30. package/dist/components/SegmentedButtons.js +86 -0
  31. package/dist/components/Sidebar.d.ts +79 -0
  32. package/dist/components/Sidebar.js +178 -0
  33. package/dist/components/TsingrocDatePicker.d.ts +38 -0
  34. package/dist/components/TsingrocDatePicker.js +64 -0
  35. package/dist/components/TsingrocTheme.d.ts +15 -0
  36. package/dist/components/TsingrocTheme.js +72 -0
  37. package/dist/components/UserButton.d.ts +42 -0
  38. package/dist/components/UserButton.js +105 -0
  39. package/dist/components/VerticalColorLegend.d.ts +7 -0
  40. package/dist/components/VerticalColorLegend.js +208 -0
  41. package/dist/components/WeatherMap.d.ts +18 -0
  42. package/dist/components/WeatherMap.js +658 -0
  43. package/dist/deckgl/TiandituLayer.d.ts +13 -0
  44. package/dist/deckgl/TiandituLayer.js +44 -0
  45. package/dist/deckgl/WeatherData.d.ts +53 -0
  46. package/dist/deckgl/WeatherData.js +94 -0
  47. package/dist/deckgl/index.d.ts +1 -0
  48. package/dist/deckgl/index.js +1 -0
  49. package/dist/echarts/coordinateSystems/grid.d.ts +43 -0
  50. package/dist/echarts/coordinateSystems/grid.js +107 -0
  51. package/dist/echarts/coordinateSystems/index.js +2 -0
  52. package/dist/echarts/coordinateSystems/polar.d.ts +45 -0
  53. package/dist/echarts/coordinateSystems/polar.js +96 -0
  54. package/dist/echarts/gl-types.d.js +0 -0
  55. package/dist/echarts/gl.d.ts +115 -0
  56. package/dist/echarts/gl.js +47 -0
  57. package/dist/echarts/index.d.ts +46 -0
  58. package/dist/echarts/index.js +46 -0
  59. package/dist/echarts/legend.d.ts +17 -0
  60. package/dist/echarts/legend.js +15 -0
  61. package/dist/echarts/radar.d.ts +24 -0
  62. package/dist/echarts/radar.js +22 -0
  63. package/dist/echarts/series/barSeries.d.ts +23 -0
  64. package/dist/echarts/series/barSeries.js +18 -0
  65. package/dist/echarts/series/boxplotSeries.d.ts +21 -0
  66. package/dist/echarts/series/boxplotSeries.js +40 -0
  67. package/dist/echarts/series/index.js +7 -0
  68. package/dist/echarts/series/intervalSeries.d.ts +32 -0
  69. package/dist/echarts/series/intervalSeries.js +55 -0
  70. package/dist/echarts/series/lineSeries.d.ts +36 -0
  71. package/dist/echarts/series/lineSeries.js +45 -0
  72. package/dist/echarts/series/maxBarSeries.d.ts +18 -0
  73. package/dist/echarts/series/maxBarSeries.js +39 -0
  74. package/dist/echarts/series/pieSeries.d.ts +31 -0
  75. package/dist/echarts/series/pieSeries.js +47 -0
  76. package/dist/echarts/series/windLineSeries.d.ts +47 -0
  77. package/dist/echarts/series/windLineSeries.js +51 -0
  78. package/{src/echarts/tooltip.ts → dist/echarts/tooltip.d.ts} +1 -5
  79. package/dist/echarts/tooltip.js +18 -0
  80. package/dist/env.d.js +0 -0
  81. package/dist/index.d.ts +20 -0
  82. package/dist/index.js +20 -0
  83. package/dist/utils/debug.d.ts +1 -0
  84. package/dist/utils/debug.js +25 -0
  85. package/dist/utils/index.d.ts +4 -0
  86. package/dist/utils/index.js +4 -0
  87. package/dist/utils/math.d.ts +9 -0
  88. package/{src/utils/math.ts → dist/utils/math.js} +2 -2
  89. package/dist/utils/mock.d.ts +8 -0
  90. package/dist/utils/mock.js +40 -0
  91. package/dist/utils/startOfQuarter.d.ts +2 -0
  92. package/dist/utils/startOfQuarter.js +4 -0
  93. package/package.json +26 -14
  94. package/src/components/Auth.tsx +0 -623
  95. package/src/components/AutoResizedECharts.tsx +0 -70
  96. package/src/components/Calendar.tsx +0 -182
  97. package/src/components/CircularProgress.tsx +0 -38
  98. package/src/components/ConnectedECharts.tsx +0 -62
  99. package/src/components/ECharts.tsx +0 -206
  100. package/src/components/Header.tsx +0 -136
  101. package/src/components/ImageBackground.tsx +0 -58
  102. package/src/components/IndicatorLight.tsx +0 -106
  103. package/src/components/LeftAlignedECharts.tsx +0 -190
  104. package/src/components/LineChartEditor.tsx +0 -558
  105. package/src/components/LineChartTable.tsx +0 -286
  106. package/src/components/LinkedECharts.tsx +0 -51
  107. package/src/components/LinkedLineChart.tsx +0 -144
  108. package/src/components/QuickDateRangePicker.tsx +0 -84
  109. package/src/components/SegmentedButtons.tsx +0 -46
  110. package/src/components/Sidebar.tsx +0 -271
  111. package/src/components/StrictECharts.d.ts +0 -47
  112. package/src/components/StrictECharts.js +0 -1
  113. package/src/components/TsingrocDatePicker.tsx +0 -103
  114. package/src/components/TsingrocTheme.tsx +0 -48
  115. package/src/components/UserButton.tsx +0 -165
  116. package/src/components/VerticalColorLegend.tsx +0 -73
  117. package/src/components/WeatherMap.tsx +0 -522
  118. package/src/deckgl/TiandituLayer.ts +0 -56
  119. package/src/deckgl/WeatherData.ts +0 -157
  120. package/src/deckgl/index.ts +0 -4
  121. package/src/echarts/coordinateSystems/grid.ts +0 -143
  122. package/src/echarts/coordinateSystems/polar.ts +0 -148
  123. package/src/echarts/gl.ts +0 -159
  124. package/src/echarts/index.ts +0 -129
  125. package/src/echarts/legend.ts +0 -36
  126. package/src/echarts/radar.ts +0 -46
  127. package/src/echarts/series/barSeries.ts +0 -37
  128. package/src/echarts/series/boxplotSeries.ts +0 -62
  129. package/src/echarts/series/intervalSeries.ts +0 -70
  130. package/src/echarts/series/lineSeries.ts +0 -78
  131. package/src/echarts/series/maxBarSeries.ts +0 -55
  132. package/src/echarts/series/pieSeries.ts +0 -76
  133. package/src/echarts/series/windLineSeries.ts +0 -113
  134. package/src/index.ts +0 -118
  135. package/src/types.d.ts +0 -5
  136. package/src/utils/debug.ts +0 -39
  137. package/src/utils/mock.ts +0 -69
  138. package/src/utils/startOfQuarter.ts +0 -6
  139. /package/{src/echarts/coordinateSystems/index.ts → dist/echarts/coordinateSystems/index.d.ts} +0 -0
  140. /package/{src/echarts/series/index.ts → dist/echarts/series/index.d.ts} +0 -0
@@ -1,106 +0,0 @@
1
- import { createStyles, keyframes } from "antd-style";
2
- import type { HTMLAttributes } from "react";
3
-
4
- export interface IndicatorLightProps extends HTMLAttributes<HTMLDivElement> {
5
- /**
6
- * 指示灯的直径。
7
- * @default token.sizeXL
8
- */
9
- size?: number | string;
10
- /**
11
- * 指示的状态。设置了这一项时,{@linkcode onColor}、{@linkcode mode} 和 {@linkcode period} 会被忽略。
12
- *
13
- * `"healthy"` 表示常绿,`"attention"` 表示绿色闪烁,
14
- * `"danger"` 表示常红,`"emergency"` 表示红色闪烁,
15
- * `"off"` 表示关闭。
16
- * 具体色值取自 design token。
17
- */
18
- status?: "healthy" | "attention" | "danger" | "emergency" | "off";
19
- /**
20
- * 灯亮时的颜色。
21
- * @default token.colorError
22
- */
23
- onColor?: string;
24
- /**
25
- * 灯灭时的颜色。
26
- * @default token.colorFill
27
- */
28
- offColor?: string;
29
- /**
30
- * 灯的状态。`"on"` 表示常亮,`"flash"` 表示闪烁,`"off"` 表示常暗。
31
- * @default "on"
32
- */
33
- mode?: "on" | "flash" | "off";
34
- /**
35
- * 闪烁周期(一亮一暗)的时长,以秒为单位。不可为 `0`、`NaN` 或 `Infinity`。
36
- * @default 1
37
- */
38
- period?: number;
39
- }
40
-
41
- const ANIMATION_MAP: Record<IndicatorLightProps["mode"] & {}, string> = {
42
- on: "linear(0, 0) paused",
43
- flash: "cubic-bezier(0.9, 0, 0.1, 1) infinite alternate",
44
- off: "linear(1, 1) paused",
45
- };
46
-
47
- const useStyles = createStyles(({ token, css }, props: IndicatorLightProps) => {
48
- const size = props.size ?? token.sizeXL;
49
- const sizeCss = typeof size === "number" ? `${size}px` : size;
50
- const colorMap: Record<
51
- IndicatorLightProps["status"] & {},
52
- { onColor: string; mode: "on" | "flash" | "off" }
53
- > = {
54
- healthy: { onColor: token.colorSuccess, mode: "on" },
55
- attention: { onColor: token.colorSuccess, mode: "flash" },
56
- danger: { onColor: token.colorError, mode: "on" },
57
- emergency: { onColor: token.colorError, mode: "flash" },
58
- off: { onColor: token.colorError, mode: "off" },
59
- };
60
- const { onColor = token.colorError, mode = "on" } = props.status
61
- ? colorMap[props.status]
62
- : props;
63
- const offColor = props.offColor ?? token.colorFillSecondary;
64
- const halfPeriod = (props.period ?? 1) / 2;
65
- const flash = keyframes`
66
- from {
67
- background-color: ${onColor};
68
- box-shadow: 0 0 6px 2px ${onColor};
69
- }
70
- to {
71
- background-color: ${offColor};
72
- }
73
- `;
74
- return {
75
- light: css`
76
- width: 100%;
77
- height: 100%;
78
- border-radius: 50%;
79
- animation: ${flash} ${halfPeriod}s ${ANIMATION_MAP[mode]};
80
- `,
81
- lightBorder: css`
82
- height: ${sizeCss};
83
- aspect-ratio: 1;
84
- border: ${token.colorBorder} 2px solid;
85
- border-radius: 50%;
86
- `,
87
- };
88
- });
89
-
90
- /**
91
- * 一个指示灯。
92
- *
93
- * 文档内未列出的属性会被传递给组件顶层的 `div` 元素。
94
- */
95
- function IndicatorLight(props: IndicatorLightProps) {
96
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
97
- const { size, status, onColor, offColor, mode, period, ...rest } = props;
98
- const { cx, styles } = useStyles(props);
99
- return (
100
- <div {...rest} className={cx(styles.lightBorder, rest.className)}>
101
- <div className={cx(styles.light)}></div>
102
- </div>
103
- );
104
- }
105
-
106
- export default IndicatorLight;
@@ -1,190 +0,0 @@
1
- import type { ECharts } from "echarts/core";
2
- import {
3
- createContext,
4
- use,
5
- useEffect,
6
- useEffectEvent,
7
- useId,
8
- useImperativeHandle,
9
- useRef,
10
- useState,
11
- type ComponentType,
12
- type ReactNode,
13
- } from "react";
14
- import type { Element, ElementProps, Group } from "zrender";
15
-
16
- import { debugAssert } from "../utils/debug";
17
- import type { withAutoResize } from "./AutoResizedECharts"; // eslint-disable-line @typescript-eslint/no-unused-vars
18
- import ConnectedECharts, { type withConnector } from "./ConnectedECharts"; // eslint-disable-line @typescript-eslint/no-unused-vars
19
- import type { EChartsHOCType, EChartsProps, EChartsRef } from "./ECharts";
20
-
21
- interface LeftAlignContext {
22
- maxLabelsWidth: number;
23
- register: (id: string, size: number) => void;
24
- unregister: (id: string) => void;
25
- }
26
-
27
- const LeftAlignContext = createContext<LeftAlignContext | null>(null);
28
-
29
- /**
30
- * 为 {@linkcode LeftAlignedECharts} 和
31
- * {@linkcode withLeftAlign | withLeftAlign(ECharts)}
32
- * 提供对齐上下文。
33
- */
34
- export function EChartsLeftAligner({ children }: { children: ReactNode }) {
35
- const [labelsWidthMap, setLabelsWidthMap] = useState(
36
- new Map<string, number>(),
37
- );
38
- return (
39
- <LeftAlignContext.Provider
40
- value={{
41
- maxLabelsWidth: Math.max(...labelsWidthMap.values()),
42
- register: (id, size) =>
43
- setLabelsWidthMap((map) => new Map(map).set(id, size)),
44
- unregister: (id) =>
45
- setLabelsWidthMap(
46
- (map) => ((map = new Map(map)), map.delete(id), map),
47
- ),
48
- }}
49
- >
50
- {children}
51
- </LeftAlignContext.Provider>
52
- );
53
- }
54
-
55
- function findLabelsGroup<T extends ElementProps>(
56
- element: Element<T>,
57
- ): Group | undefined {
58
- if (element.isGroup) {
59
- const group = element as Group;
60
- if (group.children().every((el) => el.type === "text")) {
61
- return group;
62
- } else {
63
- for (const child of group.children()) {
64
- const found = findLabelsGroup(child);
65
- if (found) {
66
- return found;
67
- }
68
- }
69
- }
70
- }
71
- }
72
-
73
- function getLabelsWidth(instance: ECharts) {
74
- const yAxis = instance
75
- .getZr()
76
- .storage.getRoots()
77
- .find(
78
- (it: unknown) =>
79
- (it as { __ecComponentInfo: { mainType: string } }).__ecComponentInfo
80
- .mainType === "yAxis",
81
- );
82
- if (!yAxis) {
83
- return undefined;
84
- }
85
- const labelsGroup = findLabelsGroup(yAxis as unknown as Element);
86
- if (!labelsGroup) {
87
- return undefined;
88
- }
89
- // 不知道为什么,直接在 labelsGroup 上使用 getBoundingRect 测量到的宽度有时是错误的
90
- const childrenWidths = labelsGroup
91
- .children()
92
- .map((it) => it.getBoundingRect().width);
93
- return Math.max(...childrenWidths);
94
- }
95
-
96
- /**
97
- * 为 ECharts 添加与其它 ECharts 纵轴左对齐的能力。
98
- *
99
- * 使用该组件时必须满足下列限制:
100
- *
101
- * - 必须包裹在 {@linkcode EChartsLeftAligner} 内,否则会立即抛出错误。
102
- * - 图像所在的容器本身必须已经左对齐。
103
- * - 图像中必须包含且仅包含一个 grid 坐标系。
104
- * 如果图像不包含 grid,那么该组件不会产生任何效果。
105
- * 如果图像包含多个 grid,那么该组件只会对齐其中一个 grid,且无法保证是哪一个。
106
- * - grid 必须有且仅有一个纵轴,并且在左侧,不满足这一条件的影响同上一条。
107
- * - grid 坐标系必须被设置为 `{ containLabel: true }` 或者
108
- * `{ outerBoundsMode: "same", outerBoundsContain: "axisLabel" }`。
109
- * 这也是组件库内的 `echarts.grid()` 的默认设置。
110
- * 如果你不这么设置,而是使用 `left` 和 `bottom` 来手动对齐轴线,那就没必要使用这个组件,强行使用可能导致布局异常。
111
- * - grid 坐标系的 `left` 属性会被该组件覆盖,最终效果总是会使得纵轴标签最宽的坐标系的标签紧贴容器左边缘(即 `left === 0`)。
112
- * - 左对齐时原本的过渡动画会被打断。
113
- */
114
- export const withLeftAlign: EChartsHOCType =
115
- <Props extends EChartsProps>(ECharts: ComponentType<Props>) =>
116
- (props: Props) => {
117
- "use memo";
118
- const { ref: outerRef, option, onSetOption, ...rest } = props;
119
-
120
- const ref = useRef<EChartsRef>(null);
121
- useImperativeHandle(outerRef, () => {
122
- debugAssert(ref.current, "ref should be connected");
123
- return ref.current;
124
- }, []);
125
-
126
- const context = use(LeftAlignContext);
127
- if (!context) {
128
- throw new Error(
129
- "LeftAlignedECharts or withLeftAlign(ECharts) must be wrapped inside an EChartsLeftAligner!",
130
- );
131
- }
132
- const { maxLabelsWidth, register, unregister } = context;
133
- const id = useId();
134
- const [labelsWidth, setLabelsWidth] = useState<number | undefined>();
135
-
136
- // 布局变化时,测量并报告最新的 labelsWidth 值
137
- const reportLayoutChange = useEffectEvent((instance: ECharts) => {
138
- const labelsWidth = getLabelsWidth(instance);
139
- if (labelsWidth !== undefined) {
140
- setLabelsWidth(labelsWidth);
141
- register(id, labelsWidth);
142
- }
143
- });
144
-
145
- // 卸载时,注销自身
146
- const dispose = useEffectEvent(() => unregister(id));
147
- useEffect(() => dispose, []);
148
-
149
- return (
150
- // @ts-expect-error 见 ./AutoResizedECharts.tsx
151
- <ECharts
152
- ref={ref}
153
- option={
154
- option === undefined ||
155
- option.grid === undefined ||
156
- labelsWidth === undefined ||
157
- Number.isNaN(labelsWidth) ||
158
- labelsWidth >= maxLabelsWidth
159
- ? option
160
- : {
161
- ...option,
162
- grid: (Array.isArray(option.grid)
163
- ? option.grid
164
- : [option.grid]
165
- ).map((it) => ({
166
- ...it,
167
- left: maxLabelsWidth - labelsWidth,
168
- })),
169
- }
170
- }
171
- onSetOption={(instance) => {
172
- reportLayoutChange(instance);
173
- return onSetOption?.(instance);
174
- }}
175
- {...rest}
176
- />
177
- );
178
- };
179
-
180
- /**
181
- * 预置了纵轴左对齐、联动和自适应容器尺寸能力的 ECharts 组件。
182
- *
183
- * @see {@linkcode withLeftAlign}
184
- * @see {@linkcode withConnector}
185
- * @see {@linkcode withAutoResize}
186
- */
187
- const LeftAlignedECharts = Object.assign(withLeftAlign(ConnectedECharts), {
188
- displayName: "ConnectedECharts",
189
- });
190
- export default LeftAlignedECharts;