@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.
- 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/SelectableECharts.d.ts +22 -0
- package/dist/components/SelectableECharts.js +402 -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 +108 -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 +22 -0
- package/dist/env.d.js +0 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +25 -0
- package/dist/utils/destructureLineDataItem.d.ts +6 -0
- package/dist/utils/destructureLineDataItem.js +17 -0
- package/dist/utils/filterMap.d.ts +1 -0
- package/dist/utils/filterMap.js +11 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +8 -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/normalizeIntoArray.d.ts +1 -0
- package/dist/utils/normalizeIntoArray.js +3 -0
- package/dist/utils/startOfQuarter.d.ts +2 -0
- package/dist/utils/startOfQuarter.js +4 -0
- package/dist/utils/timeAxisLabel.d.ts +5 -0
- package/dist/utils/timeAxisLabel.js +18 -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 -120
- 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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Dayjs } from "dayjs";
|
|
2
|
+
export interface CalendarProps extends Omit<React.HTMLAttributes<HTMLTableElement>, "onChange"> {
|
|
3
|
+
/**
|
|
4
|
+
* 当前显示的月份。
|
|
5
|
+
*
|
|
6
|
+
* 注意:传入的月份的时区会决定整个日历所用的时区。
|
|
7
|
+
*/
|
|
8
|
+
month: Dayjs;
|
|
9
|
+
/** 当前选中的日期。*/
|
|
10
|
+
selected?: Dayjs;
|
|
11
|
+
/** 选中日期更改时的回调函数。*/
|
|
12
|
+
onChange?: (selected: Dayjs) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 无论一个月需要占用多少周,都总是显示 6 周。
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
alwaysSixWeeks?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 淡化第一周和最后几周不属于本月的日期。
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
fadeAdjacentDays?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 表头单元格的属性,详见 [MDN][1]。可以通过设置这里的 `children` 来自定义表头内容。
|
|
25
|
+
*
|
|
26
|
+
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
|
|
27
|
+
*/
|
|
28
|
+
thProps?: (
|
|
29
|
+
/**
|
|
30
|
+
* 范围 0-6,表示一周的第几天
|
|
31
|
+
*
|
|
32
|
+
* 注意:这个数字的含义会受到地区设置的影响!请使用 `dayjs.weekdays()` 获取每一天的名称。
|
|
33
|
+
*/
|
|
34
|
+
weekday: number) => React.HTMLAttributes<HTMLTableCellElement>;
|
|
35
|
+
/**
|
|
36
|
+
* 日期单元格的属性,详见 [MDN][1]。可以通过设置这里的 `children` 来自定义单元格内容。
|
|
37
|
+
*
|
|
38
|
+
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
|
|
39
|
+
*/
|
|
40
|
+
tdProps?: (date: Dayjs, selected: boolean) => React.HTMLAttributes<HTMLTableCellElement>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 一个日历组件。
|
|
44
|
+
*
|
|
45
|
+
* 除了文档列出的属性之外,也接受所有 [HTML Table 元素][1] 接受的属性。
|
|
46
|
+
*
|
|
47
|
+
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
|
|
48
|
+
*/
|
|
49
|
+
declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export default Calendar;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createStyles } from "antd-style";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import localeData from "dayjs/plugin/localeData";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
dayjs.extend(localeData);
|
|
7
|
+
const useStyles = createStyles(({
|
|
8
|
+
token,
|
|
9
|
+
css,
|
|
10
|
+
cx
|
|
11
|
+
}) => {
|
|
12
|
+
const calendarFade = css`
|
|
13
|
+
color: ${token.colorTextDisabled};
|
|
14
|
+
`;
|
|
15
|
+
const calendarSelected = css`
|
|
16
|
+
background: ${token.colorPrimaryBg};
|
|
17
|
+
color: ${token.colorPrimary};
|
|
18
|
+
`;
|
|
19
|
+
const calendar = css`
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
border-collapse: collapse;
|
|
24
|
+
font-family: ${token.fontFamily};
|
|
25
|
+
font-size: ${token.fontSize}px;
|
|
26
|
+
line-height: ${token.lineHeight};
|
|
27
|
+
user-select: none;
|
|
28
|
+
|
|
29
|
+
> thead > tr > th {
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
height: ${token.fontSize * token.lineHeight + token.paddingXXS * 2}px;
|
|
32
|
+
padding: ${token.paddingXXS}px;
|
|
33
|
+
font-weight: normal;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
> tbody > tr > td {
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
width: calc(100% / 7);
|
|
39
|
+
border: 1px solid ${token.colorBorder};
|
|
40
|
+
padding: ${token.paddingXXS}px;
|
|
41
|
+
vertical-align: bottom;
|
|
42
|
+
transition:
|
|
43
|
+
background ease ${token.motionDurationFast},
|
|
44
|
+
color ease ${token.motionDurationFast};
|
|
45
|
+
|
|
46
|
+
&:hover:not(.${cx(calendarSelected)}) {
|
|
47
|
+
background: ${token.colorBgTextHover};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
return {
|
|
52
|
+
calendar,
|
|
53
|
+
calendarFade,
|
|
54
|
+
calendarSelected
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 一个日历组件。
|
|
60
|
+
*
|
|
61
|
+
* 除了文档列出的属性之外,也接受所有 [HTML Table 元素][1] 接受的属性。
|
|
62
|
+
*
|
|
63
|
+
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
|
|
64
|
+
*/
|
|
65
|
+
function Calendar(props) {
|
|
66
|
+
const {
|
|
67
|
+
month,
|
|
68
|
+
selected: propsSelected,
|
|
69
|
+
onChange,
|
|
70
|
+
alwaysSixWeeks,
|
|
71
|
+
fadeAdjacentDays = true,
|
|
72
|
+
thProps,
|
|
73
|
+
tdProps,
|
|
74
|
+
className,
|
|
75
|
+
...rest
|
|
76
|
+
} = props;
|
|
77
|
+
const {
|
|
78
|
+
cx,
|
|
79
|
+
styles
|
|
80
|
+
} = useStyles();
|
|
81
|
+
const [selected, setSelected] = propsSelected === undefined ?
|
|
82
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
83
|
+
useState() : [propsSelected, () => {}];
|
|
84
|
+
const monthStart = month.startOf("month");
|
|
85
|
+
const calendarStart = monthStart.startOf("week");
|
|
86
|
+
const monthEnd = month.endOf("month");
|
|
87
|
+
const minWeeks = Math.ceil(monthEnd.diff(calendarStart, "week", true));
|
|
88
|
+
const weekdays = [...dayjs.weekdaysShort()];
|
|
89
|
+
// 按地区设置调整一周的第一天
|
|
90
|
+
weekdays.splice(0, 0, ...weekdays.splice(calendarStart.day()));
|
|
91
|
+
return /*#__PURE__*/_jsxs("table", {
|
|
92
|
+
...rest,
|
|
93
|
+
className: cx(styles.calendar, className),
|
|
94
|
+
children: [/*#__PURE__*/_jsx("thead", {
|
|
95
|
+
children: /*#__PURE__*/_jsx("tr", {
|
|
96
|
+
children: weekdays.map((name, weekday) => /*#__PURE__*/_jsx("th", {
|
|
97
|
+
children: name,
|
|
98
|
+
...thProps?.(weekday)
|
|
99
|
+
}, weekday))
|
|
100
|
+
})
|
|
101
|
+
}), /*#__PURE__*/_jsx("tbody", {
|
|
102
|
+
children: Array.from({
|
|
103
|
+
length: alwaysSixWeeks ? 6 : minWeeks
|
|
104
|
+
}, (_, week) => /*#__PURE__*/_jsx("tr", {
|
|
105
|
+
children: Array(7).fill(null).map((_, weekday) => {
|
|
106
|
+
const date = calendarStart.add(week * 7 + weekday, "day");
|
|
107
|
+
const fade = fadeAdjacentDays && date.month() != monthStart.month();
|
|
108
|
+
const isSelected = Math.floor(selected?.diff(date, "day", true) ?? NaN) === 0;
|
|
109
|
+
const {
|
|
110
|
+
className,
|
|
111
|
+
...props
|
|
112
|
+
} = tdProps?.(date, false) ?? {};
|
|
113
|
+
return /*#__PURE__*/_jsx("td", {
|
|
114
|
+
children: date.date(),
|
|
115
|
+
onClick: () => {
|
|
116
|
+
setSelected(date);
|
|
117
|
+
onChange?.(date);
|
|
118
|
+
},
|
|
119
|
+
...props,
|
|
120
|
+
className: cx({
|
|
121
|
+
[styles.calendarFade]: fade,
|
|
122
|
+
[styles.calendarSelected]: isSelected
|
|
123
|
+
}, className)
|
|
124
|
+
}, weekday);
|
|
125
|
+
})
|
|
126
|
+
}, week))
|
|
127
|
+
})]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
export default Calendar;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ProgressProps } from "antd";
|
|
2
|
+
import type { ProgressGradient } from "antd/es/progress/progress";
|
|
3
|
+
export interface CircularProgressProps extends ProgressProps, React.RefAttributes<HTMLDivElement> {
|
|
4
|
+
/** 进度百分比,范围是 0-100。*/
|
|
5
|
+
progress?: number;
|
|
6
|
+
/**
|
|
7
|
+
* 进度条已完成部分的颜色。
|
|
8
|
+
* @default "#34A9D4"
|
|
9
|
+
*/
|
|
10
|
+
color?: string | string[] | ProgressGradient;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 环形进度条。
|
|
14
|
+
*
|
|
15
|
+
* 本组件基于 [Ant Design 的 `Progress`][1] 自定义而来。
|
|
16
|
+
* 因此,除了文档中列出的属性以外,也兼容 `Progress` 的所有属性。
|
|
17
|
+
*
|
|
18
|
+
* [1]: https://ant-design.antgroup.com/components/progress-cn
|
|
19
|
+
*/
|
|
20
|
+
declare function CircularProgress(props: CircularProgressProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export default CircularProgress;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { Progress } from "antd";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* 环形进度条。
|
|
6
|
+
*
|
|
7
|
+
* 本组件基于 [Ant Design 的 `Progress`][1] 自定义而来。
|
|
8
|
+
* 因此,除了文档中列出的属性以外,也兼容 `Progress` 的所有属性。
|
|
9
|
+
*
|
|
10
|
+
* [1]: https://ant-design.antgroup.com/components/progress-cn
|
|
11
|
+
*/
|
|
12
|
+
function CircularProgress(props) {
|
|
13
|
+
const $ = _c(3);
|
|
14
|
+
const t0 = props.color ?? "#34A9D4";
|
|
15
|
+
let t1;
|
|
16
|
+
if ($[0] !== props || $[1] !== t0) {
|
|
17
|
+
t1 = /*#__PURE__*/_jsx(Progress, {
|
|
18
|
+
type: "circle",
|
|
19
|
+
percent: props.progress,
|
|
20
|
+
strokeLinecap: "butt",
|
|
21
|
+
strokeWidth: 9,
|
|
22
|
+
strokeColor: t0,
|
|
23
|
+
trailColor: "#22405A",
|
|
24
|
+
...props
|
|
25
|
+
});
|
|
26
|
+
$[0] = props;
|
|
27
|
+
$[1] = t0;
|
|
28
|
+
$[2] = t1;
|
|
29
|
+
} else {
|
|
30
|
+
t1 = $[2];
|
|
31
|
+
}
|
|
32
|
+
return t1;
|
|
33
|
+
}
|
|
34
|
+
export default CircularProgress;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as echarts from "echarts/core";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { EChartsHOCType, EChartsProps } from "./ECharts";
|
|
4
|
+
/**
|
|
5
|
+
* 为 {@linkcode ConnectedECharts}/{@linkcode withConnector | withConnector(ECharts)}
|
|
6
|
+
* 提供联动上下文,只有同一个上下文内的 ECharts 会联动。
|
|
7
|
+
*/
|
|
8
|
+
export declare function EChartsConnector({ children }: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* 为 ECharts 增加联动能力。所有添加了该能力的 ECharts 都会相互联动。
|
|
13
|
+
*
|
|
14
|
+
* 可以使用 {@linkcode EChartsConnector} 将同一个页面上的 ECharts
|
|
15
|
+
* 划分为多个组,不同组的 ECharts 不会联动。也可以使用 `group` 属性手动指定联动组。
|
|
16
|
+
*/
|
|
17
|
+
export declare const withConnector: EChartsHOCType<{
|
|
18
|
+
group?: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* 预置了联动和自适应容器尺寸能力的 ECharts。
|
|
22
|
+
*
|
|
23
|
+
* @see {@linkcode withConnector}
|
|
24
|
+
* @see {@linkcode withAutoResize}
|
|
25
|
+
*/
|
|
26
|
+
declare const ConnectedECharts: import("./ECharts").EChartsComponentType<EChartsProps<echarts.EChartsCoreOption> & {
|
|
27
|
+
group?: string;
|
|
28
|
+
}> & {
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
31
|
+
export default ConnectedECharts;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import * as echarts from "echarts/core";
|
|
3
|
+
import { createContext, use, useId } from "react";
|
|
4
|
+
import AutoResizedECharts from "./AutoResizedECharts"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const EChartsConnectorContext = /*#__PURE__*/createContext("default");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 为 {@linkcode ConnectedECharts}/{@linkcode withConnector | withConnector(ECharts)}
|
|
10
|
+
* 提供联动上下文,只有同一个上下文内的 ECharts 会联动。
|
|
11
|
+
*/
|
|
12
|
+
export function EChartsConnector(t0) {
|
|
13
|
+
const $ = _c(3);
|
|
14
|
+
const {
|
|
15
|
+
children
|
|
16
|
+
} = t0;
|
|
17
|
+
const group = useId();
|
|
18
|
+
let t1;
|
|
19
|
+
if ($[0] !== children || $[1] !== group) {
|
|
20
|
+
t1 = /*#__PURE__*/_jsx(EChartsConnectorContext.Provider, {
|
|
21
|
+
value: group,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
24
|
+
$[0] = children;
|
|
25
|
+
$[1] = group;
|
|
26
|
+
$[2] = t1;
|
|
27
|
+
} else {
|
|
28
|
+
t1 = $[2];
|
|
29
|
+
}
|
|
30
|
+
return t1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 为 ECharts 增加联动能力。所有添加了该能力的 ECharts 都会相互联动。
|
|
35
|
+
*
|
|
36
|
+
* 可以使用 {@linkcode EChartsConnector} 将同一个页面上的 ECharts
|
|
37
|
+
* 划分为多个组,不同组的 ECharts 不会联动。也可以使用 `group` 属性手动指定联动组。
|
|
38
|
+
*/
|
|
39
|
+
export const withConnector = ECharts => props => {
|
|
40
|
+
"use memo";
|
|
41
|
+
|
|
42
|
+
const $ = _c(10);
|
|
43
|
+
const contextGroup = use(EChartsConnectorContext);
|
|
44
|
+
let onInit;
|
|
45
|
+
let rest;
|
|
46
|
+
let t0;
|
|
47
|
+
if ($[0] !== props) {
|
|
48
|
+
({
|
|
49
|
+
onInit,
|
|
50
|
+
group: t0,
|
|
51
|
+
...rest
|
|
52
|
+
} = props);
|
|
53
|
+
$[0] = props;
|
|
54
|
+
$[1] = onInit;
|
|
55
|
+
$[2] = rest;
|
|
56
|
+
$[3] = t0;
|
|
57
|
+
} else {
|
|
58
|
+
onInit = $[1];
|
|
59
|
+
rest = $[2];
|
|
60
|
+
t0 = $[3];
|
|
61
|
+
}
|
|
62
|
+
const group = t0 === undefined ? contextGroup : t0;
|
|
63
|
+
let t1;
|
|
64
|
+
if ($[4] !== group || $[5] !== onInit) {
|
|
65
|
+
t1 = instance => {
|
|
66
|
+
instance.group = group;
|
|
67
|
+
echarts.connect(group);
|
|
68
|
+
return onInit?.(instance);
|
|
69
|
+
};
|
|
70
|
+
$[4] = group;
|
|
71
|
+
$[5] = onInit;
|
|
72
|
+
$[6] = t1;
|
|
73
|
+
} else {
|
|
74
|
+
t1 = $[6];
|
|
75
|
+
}
|
|
76
|
+
let t2;
|
|
77
|
+
if ($[7] !== rest || $[8] !== t1) {
|
|
78
|
+
t2 = /*#__PURE__*/_jsx(ECharts, {
|
|
79
|
+
onInit: t1,
|
|
80
|
+
...rest
|
|
81
|
+
});
|
|
82
|
+
$[7] = rest;
|
|
83
|
+
$[8] = t1;
|
|
84
|
+
$[9] = t2;
|
|
85
|
+
} else {
|
|
86
|
+
t2 = $[9];
|
|
87
|
+
}
|
|
88
|
+
return t2;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 预置了联动和自适应容器尺寸能力的 ECharts。
|
|
93
|
+
*
|
|
94
|
+
* @see {@linkcode withConnector}
|
|
95
|
+
* @see {@linkcode withAutoResize}
|
|
96
|
+
*/
|
|
97
|
+
const ConnectedECharts = Object.assign(withConnector(AutoResizedECharts), {
|
|
98
|
+
displayName: "ConnectedECharts"
|
|
99
|
+
});
|
|
100
|
+
export default ConnectedECharts;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { EChartsOption } from "echarts";
|
|
2
|
+
import type { EChartsCoreOption, EChartsInitOpts, ECharts as EChartsInstance, SetOptionOpts } from "echarts/core";
|
|
3
|
+
import { type ComponentType, type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
4
|
+
export interface EChartsProps<Option extends EChartsCoreOption = EChartsOption> extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* 用于命令式操作 ECharts 容器和实例的 ref。
|
|
7
|
+
*
|
|
8
|
+
* 注意 effect 首次执行时 ECharts 实例尚未被创建。如果需要在 ECharts
|
|
9
|
+
* 实例上添加事件监听器或者执行其它的初始化操作,请使用 {@linkcode onInit}。
|
|
10
|
+
*/
|
|
11
|
+
ref?: Ref<EChartsRef>;
|
|
12
|
+
/** 主题。 @default "default" */
|
|
13
|
+
theme?: string | Record<string, any> | null;
|
|
14
|
+
/**
|
|
15
|
+
* 初始化实例时的选项。
|
|
16
|
+
*
|
|
17
|
+
* 修改该属性会导致 ECharts 实例被销毁并重新创建,因此建议不要频繁修改该属性,并且推荐使用
|
|
18
|
+
* React Compiler 或者 useMemo 将该属性记忆化。
|
|
19
|
+
*/
|
|
20
|
+
initOpts?: EChartsInitOpts;
|
|
21
|
+
/** 配置对象。 */
|
|
22
|
+
option?: Option;
|
|
23
|
+
/**
|
|
24
|
+
* 更新 {@linkcode option} 时的选项。其中的 {@linkcode SetOptionOpts.silent | silent}
|
|
25
|
+
* 选项也会在更新 {@linkcode theme} 时使用。
|
|
26
|
+
*
|
|
27
|
+
* 注意该属性变化后只会从下一次 option 更新开始生效。
|
|
28
|
+
*/
|
|
29
|
+
setOptionOpts?: SetOptionOpts;
|
|
30
|
+
/**
|
|
31
|
+
* 初始化实例(`echarts.init()`)后执行的回调。如果返回函数,则会在销毁实例(`instance.dispose()`)之前调用。
|
|
32
|
+
*
|
|
33
|
+
* 推荐在这个回调中为 ECharts 实例添加事件监听器。
|
|
34
|
+
*/
|
|
35
|
+
onInit?: (instance: EChartsInstance) => void | undefined | (() => void);
|
|
36
|
+
/** option 更新(`instance.setOption()`)后执行的回调。注意如果设置了 {@linkcode lazyUpdate},那么这个回调大概率没什么用。 */
|
|
37
|
+
onSetOption?: (instance: EChartsInstance) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface EChartsRef {
|
|
40
|
+
/** 容纳 ECharts 画布的 div 容器。 */
|
|
41
|
+
container: HTMLDivElement;
|
|
42
|
+
/** ECharts 实例。注意该实例在 ref 连接时尚未创建,如果要在实例创建时执行代码请使用 {@linkcode EChartsProps.onInit | onInit} 属性。 */
|
|
43
|
+
instance?: EChartsInstance;
|
|
44
|
+
}
|
|
45
|
+
/** 用于 HOC 的返回值。 */
|
|
46
|
+
export type EChartsComponentType<Extra> = <Option extends EChartsCoreOption = EChartsOption>(props: EChartsProps<Option> & Extra) => ReactNode;
|
|
47
|
+
/** 用于方便定义 HOC。 */
|
|
48
|
+
export interface EChartsHOCType<Extra = {}> {
|
|
49
|
+
<PrevExtra>(ECharts: EChartsComponentType<PrevExtra>): EChartsComponentType<PrevExtra & Extra>;
|
|
50
|
+
<Props extends EChartsProps>(ECharts: (props: Props) => ReactNode): (props: Props & Extra) => ReactNode;
|
|
51
|
+
<Props extends EChartsProps>(ECharts: ComponentType<Props>): ComponentType<Props & Extra>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* ECharts 的 React 封装,支持 `theme`、`opts` 等初始化参数和 `option` 配置的响应式更新。
|
|
55
|
+
*/
|
|
56
|
+
declare const ECharts: EChartsComponentType<{}>;
|
|
57
|
+
export default ECharts;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-invalid-void-type */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
import * as echarts from "echarts/core";
|
|
6
|
+
import { useEffect, useEffectEvent, useImperativeHandle, useRef } from "react";
|
|
7
|
+
import { debugAssert } from "../utils/debug";
|
|
8
|
+
|
|
9
|
+
/** 用于 HOC 的返回值。 */
|
|
10
|
+
|
|
11
|
+
/** 用于方便定义 HOC。 */
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* ECharts 的 React 封装,支持 `theme`、`opts` 等初始化参数和 `option` 配置的响应式更新。
|
|
15
|
+
*/
|
|
16
|
+
const ECharts = props => {
|
|
17
|
+
const $ = _c(39);
|
|
18
|
+
let onInit;
|
|
19
|
+
let onSetOption;
|
|
20
|
+
let option;
|
|
21
|
+
let opts;
|
|
22
|
+
let outerRef;
|
|
23
|
+
let rest;
|
|
24
|
+
let setOptionOpts;
|
|
25
|
+
let theme;
|
|
26
|
+
if ($[0] !== props) {
|
|
27
|
+
({
|
|
28
|
+
ref: outerRef,
|
|
29
|
+
theme,
|
|
30
|
+
initOpts: opts,
|
|
31
|
+
option,
|
|
32
|
+
setOptionOpts,
|
|
33
|
+
onInit,
|
|
34
|
+
onSetOption,
|
|
35
|
+
...rest
|
|
36
|
+
} = props);
|
|
37
|
+
$[0] = props;
|
|
38
|
+
$[1] = onInit;
|
|
39
|
+
$[2] = onSetOption;
|
|
40
|
+
$[3] = option;
|
|
41
|
+
$[4] = opts;
|
|
42
|
+
$[5] = outerRef;
|
|
43
|
+
$[6] = rest;
|
|
44
|
+
$[7] = setOptionOpts;
|
|
45
|
+
$[8] = theme;
|
|
46
|
+
} else {
|
|
47
|
+
onInit = $[1];
|
|
48
|
+
onSetOption = $[2];
|
|
49
|
+
option = $[3];
|
|
50
|
+
opts = $[4];
|
|
51
|
+
outerRef = $[5];
|
|
52
|
+
rest = $[6];
|
|
53
|
+
setOptionOpts = $[7];
|
|
54
|
+
theme = $[8];
|
|
55
|
+
}
|
|
56
|
+
const ref = useRef(null);
|
|
57
|
+
useForwardEChartsRef(outerRef, ref);
|
|
58
|
+
let t0;
|
|
59
|
+
if ($[9] !== setOptionOpts?.silent) {
|
|
60
|
+
t0 = theme_0 => {
|
|
61
|
+
debugAssert(ref.current, "effect should run after ref is connected");
|
|
62
|
+
ref.current.instance?.setTheme(theme_0 ?? "default", {
|
|
63
|
+
silent: setOptionOpts?.silent
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
$[9] = setOptionOpts?.silent;
|
|
67
|
+
$[10] = t0;
|
|
68
|
+
} else {
|
|
69
|
+
t0 = $[10];
|
|
70
|
+
}
|
|
71
|
+
const setTheme = useEffectEvent(t0);
|
|
72
|
+
let t1;
|
|
73
|
+
if ($[11] !== setTheme || $[12] !== theme) {
|
|
74
|
+
t1 = () => setTheme(theme);
|
|
75
|
+
$[11] = setTheme;
|
|
76
|
+
$[12] = theme;
|
|
77
|
+
$[13] = t1;
|
|
78
|
+
} else {
|
|
79
|
+
t1 = $[13];
|
|
80
|
+
}
|
|
81
|
+
let t2;
|
|
82
|
+
if ($[14] !== theme) {
|
|
83
|
+
t2 = [theme];
|
|
84
|
+
$[14] = theme;
|
|
85
|
+
$[15] = t2;
|
|
86
|
+
} else {
|
|
87
|
+
t2 = $[15];
|
|
88
|
+
}
|
|
89
|
+
useEffect(t1, t2);
|
|
90
|
+
let t3;
|
|
91
|
+
if ($[16] !== onSetOption || $[17] !== setOptionOpts) {
|
|
92
|
+
t3 = (option_0, t4) => {
|
|
93
|
+
const isInit = t4 === undefined ? false : t4;
|
|
94
|
+
debugAssert(ref.current, "effect should run after ref is connected");
|
|
95
|
+
const {
|
|
96
|
+
instance
|
|
97
|
+
} = ref.current;
|
|
98
|
+
if (instance) {
|
|
99
|
+
instance.setOption(option_0, {
|
|
100
|
+
...setOptionOpts,
|
|
101
|
+
lazyUpdate: !isInit && setOptionOpts?.lazyUpdate
|
|
102
|
+
});
|
|
103
|
+
onSetOption?.(instance);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
$[16] = onSetOption;
|
|
107
|
+
$[17] = setOptionOpts;
|
|
108
|
+
$[18] = t3;
|
|
109
|
+
} else {
|
|
110
|
+
t3 = $[18];
|
|
111
|
+
}
|
|
112
|
+
const setOption = useEffectEvent(t3);
|
|
113
|
+
let t4;
|
|
114
|
+
if ($[19] !== option || $[20] !== setOption) {
|
|
115
|
+
t4 = () => option && setOption(option);
|
|
116
|
+
$[19] = option;
|
|
117
|
+
$[20] = setOption;
|
|
118
|
+
$[21] = t4;
|
|
119
|
+
} else {
|
|
120
|
+
t4 = $[21];
|
|
121
|
+
}
|
|
122
|
+
let t5;
|
|
123
|
+
if ($[22] !== option) {
|
|
124
|
+
t5 = [option];
|
|
125
|
+
$[22] = option;
|
|
126
|
+
$[23] = t5;
|
|
127
|
+
} else {
|
|
128
|
+
t5 = $[23];
|
|
129
|
+
}
|
|
130
|
+
useEffect(t4, t5);
|
|
131
|
+
const onDisposeRef = useRef(null);
|
|
132
|
+
let t6;
|
|
133
|
+
if ($[24] !== onInit || $[25] !== option || $[26] !== setOption || $[27] !== theme) {
|
|
134
|
+
t6 = opts_0 => {
|
|
135
|
+
debugAssert(ref.current, "effect should run after ref is connected");
|
|
136
|
+
const {
|
|
137
|
+
container,
|
|
138
|
+
instance: existingInstance
|
|
139
|
+
} = ref.current;
|
|
140
|
+
if (existingInstance) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const instance_0 = echarts.init(container, theme, opts_0);
|
|
144
|
+
ref.current = {
|
|
145
|
+
container,
|
|
146
|
+
instance: instance_0
|
|
147
|
+
};
|
|
148
|
+
onDisposeRef.current = onInit?.(instance_0) ?? null;
|
|
149
|
+
if (option) {
|
|
150
|
+
setOption(option, true);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
$[24] = onInit;
|
|
154
|
+
$[25] = option;
|
|
155
|
+
$[26] = setOption;
|
|
156
|
+
$[27] = theme;
|
|
157
|
+
$[28] = t6;
|
|
158
|
+
} else {
|
|
159
|
+
t6 = $[28];
|
|
160
|
+
}
|
|
161
|
+
const init = useEffectEvent(t6);
|
|
162
|
+
let t7;
|
|
163
|
+
if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
|
|
164
|
+
t7 = () => {
|
|
165
|
+
if (ref.current) {
|
|
166
|
+
const {
|
|
167
|
+
container: container_0,
|
|
168
|
+
instance: instance_1
|
|
169
|
+
} = ref.current;
|
|
170
|
+
if (instance_1) {
|
|
171
|
+
onDisposeRef.current?.();
|
|
172
|
+
instance_1.dispose();
|
|
173
|
+
ref.current = {
|
|
174
|
+
container: container_0
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
$[29] = t7;
|
|
180
|
+
} else {
|
|
181
|
+
t7 = $[29];
|
|
182
|
+
}
|
|
183
|
+
const dispose = useEffectEvent(t7);
|
|
184
|
+
let t8;
|
|
185
|
+
if ($[30] !== dispose || $[31] !== init || $[32] !== opts) {
|
|
186
|
+
t8 = () => {
|
|
187
|
+
const animationFrame = requestAnimationFrame(() => init(opts));
|
|
188
|
+
return () => {
|
|
189
|
+
cancelAnimationFrame(animationFrame);
|
|
190
|
+
dispose();
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
$[30] = dispose;
|
|
194
|
+
$[31] = init;
|
|
195
|
+
$[32] = opts;
|
|
196
|
+
$[33] = t8;
|
|
197
|
+
} else {
|
|
198
|
+
t8 = $[33];
|
|
199
|
+
}
|
|
200
|
+
let t9;
|
|
201
|
+
if ($[34] !== opts) {
|
|
202
|
+
t9 = [opts];
|
|
203
|
+
$[34] = opts;
|
|
204
|
+
$[35] = t9;
|
|
205
|
+
} else {
|
|
206
|
+
t9 = $[35];
|
|
207
|
+
}
|
|
208
|
+
useEffect(t8, t9);
|
|
209
|
+
let t10;
|
|
210
|
+
if ($[36] === Symbol.for("react.memo_cache_sentinel")) {
|
|
211
|
+
t10 = container_1 => {
|
|
212
|
+
if (container_1 === null) {
|
|
213
|
+
ref.current = null;
|
|
214
|
+
} else {
|
|
215
|
+
ref.current = {
|
|
216
|
+
container: container_1
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
$[36] = t10;
|
|
221
|
+
} else {
|
|
222
|
+
t10 = $[36];
|
|
223
|
+
}
|
|
224
|
+
let t11;
|
|
225
|
+
if ($[37] !== rest) {
|
|
226
|
+
t11 = /*#__PURE__*/_jsx("div", {
|
|
227
|
+
ref: t10,
|
|
228
|
+
...rest
|
|
229
|
+
});
|
|
230
|
+
$[37] = rest;
|
|
231
|
+
$[38] = t11;
|
|
232
|
+
} else {
|
|
233
|
+
t11 = $[38];
|
|
234
|
+
}
|
|
235
|
+
return t11;
|
|
236
|
+
};
|
|
237
|
+
export default ECharts;
|
|
238
|
+
|
|
239
|
+
// React Compiler 无法处理 getter
|
|
240
|
+
function useForwardEChartsRef(outerRef, innerRef) {
|
|
241
|
+
useImperativeHandle(outerRef, () => {
|
|
242
|
+
debugAssert(innerRef.current, "ref should be connected");
|
|
243
|
+
return {
|
|
244
|
+
get container() {
|
|
245
|
+
debugAssert(innerRef.current, "ref should be connected");
|
|
246
|
+
return innerRef.current.container;
|
|
247
|
+
},
|
|
248
|
+
get instance() {
|
|
249
|
+
debugAssert(innerRef.current, "ref should be connected");
|
|
250
|
+
return innerRef.current.instance;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
+
}, []);
|
|
255
|
+
}
|