@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
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { Button, ConfigProvider, Flex, Input, Modal, Table, message, theme } from "antd";
|
|
2
|
+
import { createStyles } from "antd-style";
|
|
3
|
+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import * as echarts from "../echarts";
|
|
5
|
+
import ECharts from "./ECharts";
|
|
6
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
|
+
/**
|
|
8
|
+
* 一个折线图编辑器,由折线图、数据表格和确认/撤销按钮三部分组成。
|
|
9
|
+
* 可以在曲线上使用键盘上下/WS 键,或者在表格中编辑数据。
|
|
10
|
+
*
|
|
11
|
+
* 除了文档列出的属性外,多余的属性会被传递给最外层的 [Flex][1] 组件。
|
|
12
|
+
*
|
|
13
|
+
* [1]: https://ant-design.antgroup.com/components/flex-cn#api
|
|
14
|
+
*/
|
|
15
|
+
function LineChartEditor(props) {
|
|
16
|
+
const {
|
|
17
|
+
xData,
|
|
18
|
+
origData,
|
|
19
|
+
xName = "时间",
|
|
20
|
+
yName = "数值",
|
|
21
|
+
yUnit,
|
|
22
|
+
origName = "原始曲线",
|
|
23
|
+
newName = "修正曲线",
|
|
24
|
+
origColor,
|
|
25
|
+
newColor,
|
|
26
|
+
smooth = true,
|
|
27
|
+
chartHeight = 175,
|
|
28
|
+
controlsLocation = "bottom",
|
|
29
|
+
confirmPopup = true,
|
|
30
|
+
onConfirm,
|
|
31
|
+
adjustStep: defaultAdjustStep = 0.1,
|
|
32
|
+
...rest
|
|
33
|
+
} = props;
|
|
34
|
+
// TODO i18n
|
|
35
|
+
const unitString = yUnit !== undefined ? `(${yUnit})` : "";
|
|
36
|
+
const {
|
|
37
|
+
cx,
|
|
38
|
+
styles,
|
|
39
|
+
theme: token
|
|
40
|
+
} = useStyles();
|
|
41
|
+
const isDark = useContext(ConfigProvider.ConfigContext).theme?.algorithm === theme.darkAlgorithm;
|
|
42
|
+
const [modal, modalContextHolder] = Modal.useModal();
|
|
43
|
+
const [messageApi, messageContextHolder] = message.useMessage();
|
|
44
|
+
const [newData, setNewData] = useState(origData);
|
|
45
|
+
const echartsRef = useRef(null);
|
|
46
|
+
const tableRef = useRef(null);
|
|
47
|
+
const [chartFocused, setChartFocused] = useState(false);
|
|
48
|
+
const [hoverIndex, setHoverIndex] = useState();
|
|
49
|
+
const [selectedIndex, setSelectedIndex] = useState();
|
|
50
|
+
const highlightIndex = selectedIndex ?? hoverIndex;
|
|
51
|
+
const [adjustStep, setAdjustStep] = useState(defaultAdjustStep);
|
|
52
|
+
const option = echarts.buildEChartsOption({
|
|
53
|
+
backgroundColor: "transparent"
|
|
54
|
+
}, echarts.useGrid({
|
|
55
|
+
option: {
|
|
56
|
+
id: "grid",
|
|
57
|
+
left: 12,
|
|
58
|
+
right: 42,
|
|
59
|
+
bottom: 40
|
|
60
|
+
},
|
|
61
|
+
xAxis: {
|
|
62
|
+
name: xName,
|
|
63
|
+
data: xData,
|
|
64
|
+
axisPointer: {
|
|
65
|
+
value: xData[highlightIndex ?? 0]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
yAxis: {
|
|
69
|
+
name: yName + unitString,
|
|
70
|
+
axisPointer: {
|
|
71
|
+
value: newData[highlightIndex ?? 0]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
series: [echarts.lineSeries({
|
|
75
|
+
name: origName,
|
|
76
|
+
data: origData,
|
|
77
|
+
option: {
|
|
78
|
+
color: origColor,
|
|
79
|
+
lineStyle: {
|
|
80
|
+
type: "dashed"
|
|
81
|
+
},
|
|
82
|
+
smooth
|
|
83
|
+
}
|
|
84
|
+
}), echarts.lineSeries({
|
|
85
|
+
name: newName,
|
|
86
|
+
data: newData,
|
|
87
|
+
option: {
|
|
88
|
+
color: newColor,
|
|
89
|
+
smooth
|
|
90
|
+
}
|
|
91
|
+
})]
|
|
92
|
+
}), echarts.legend({
|
|
93
|
+
data: [origName, newName],
|
|
94
|
+
option: {
|
|
95
|
+
right: 42
|
|
96
|
+
}
|
|
97
|
+
}), {
|
|
98
|
+
axisPointer: [{
|
|
99
|
+
show: true,
|
|
100
|
+
status: highlightIndex !== undefined ? "show" : "hide",
|
|
101
|
+
triggerOn: "none"
|
|
102
|
+
}],
|
|
103
|
+
dataZoom: [{
|
|
104
|
+
orient: "horizontal",
|
|
105
|
+
bottom: 8,
|
|
106
|
+
filterMode: "empty"
|
|
107
|
+
}],
|
|
108
|
+
graphic: [{
|
|
109
|
+
type: "text",
|
|
110
|
+
ignore: highlightIndex === undefined,
|
|
111
|
+
left: "center",
|
|
112
|
+
top: 0,
|
|
113
|
+
style: {
|
|
114
|
+
// TODO i18n
|
|
115
|
+
text: !chartFocused ? "" : selectedIndex !== undefined ? "可使用键盘 ↑/↓/W/S 键调节选中数据,使用 +/- 键修改调节步长" : hoverIndex !== undefined ? "点击可选中当前数据点" : "",
|
|
116
|
+
fill: token.colorTextLabel
|
|
117
|
+
}
|
|
118
|
+
}]
|
|
119
|
+
});
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const inst = echartsRef.current?.instance?.getZr();
|
|
122
|
+
if (!inst) return () => {};
|
|
123
|
+
const onMousemove = event => {
|
|
124
|
+
const inst = echartsRef.current?.instance;
|
|
125
|
+
if (!inst) return;
|
|
126
|
+
const coord = [event.offsetX, event.offsetY];
|
|
127
|
+
if (inst.containPixel("grid", coord)) {
|
|
128
|
+
const [index] = inst.convertFromPixel("grid", coord);
|
|
129
|
+
setChartFocused(true);
|
|
130
|
+
setHoverIndex(index);
|
|
131
|
+
} else {
|
|
132
|
+
setHoverIndex(undefined);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const onGlobalout = () => setHoverIndex(undefined);
|
|
136
|
+
const onClick = () => setHoverIndex(hoverIndex => {
|
|
137
|
+
setSelectedIndex(hoverIndex);
|
|
138
|
+
return hoverIndex;
|
|
139
|
+
});
|
|
140
|
+
inst.on("mousemove", onMousemove);
|
|
141
|
+
inst.on("globalout", onGlobalout);
|
|
142
|
+
inst.on("click", onClick);
|
|
143
|
+
return () => {
|
|
144
|
+
inst.off("mousemove", onMousemove);
|
|
145
|
+
inst.off("globalout", onGlobalout);
|
|
146
|
+
inst.off("click", onClick);
|
|
147
|
+
};
|
|
148
|
+
}, []);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const inst = echartsRef.current?.instance;
|
|
151
|
+
if (!inst) return;
|
|
152
|
+
if (highlightIndex !== undefined) {
|
|
153
|
+
inst.dispatchAction({
|
|
154
|
+
type: "highlight",
|
|
155
|
+
seriesIndex: 1,
|
|
156
|
+
dataIndex: highlightIndex
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
inst.dispatchAction({
|
|
160
|
+
type: "downplay",
|
|
161
|
+
seriesIndex: 1
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (selectedIndex !== undefined) {
|
|
165
|
+
tableScrollTo(selectedIndex);
|
|
166
|
+
}
|
|
167
|
+
}, [highlightIndex, selectedIndex]);
|
|
168
|
+
const onKeyDown = event => {
|
|
169
|
+
if (selectedIndex === undefined) return;
|
|
170
|
+
switch (event.code) {
|
|
171
|
+
case "ArrowUp":
|
|
172
|
+
case "KeyW":
|
|
173
|
+
setNewData(prev => {
|
|
174
|
+
const next = [...prev];
|
|
175
|
+
next[selectedIndex] += adjustStep;
|
|
176
|
+
return next;
|
|
177
|
+
});
|
|
178
|
+
break;
|
|
179
|
+
case "ArrowDown":
|
|
180
|
+
case "KeyS":
|
|
181
|
+
setNewData(prev => {
|
|
182
|
+
const next = [...prev];
|
|
183
|
+
next[selectedIndex] -= adjustStep;
|
|
184
|
+
return next;
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
case "Equal":
|
|
188
|
+
setAdjustStep(prev => prev + defaultAdjustStep / 10);
|
|
189
|
+
break;
|
|
190
|
+
case "Minus":
|
|
191
|
+
setAdjustStep(prev => prev - defaultAdjustStep / 10);
|
|
192
|
+
break;
|
|
193
|
+
case "Escape":
|
|
194
|
+
case "Enter":
|
|
195
|
+
setSelectedIndex(undefined);
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
};
|
|
202
|
+
const tableData = useMemo(() => xData.map((x, i) => ({
|
|
203
|
+
key: i,
|
|
204
|
+
x,
|
|
205
|
+
orig: origData[i],
|
|
206
|
+
new: newData[i]
|
|
207
|
+
})), [xData, origData, newData]);
|
|
208
|
+
const tableColumns = useMemo(() => [{
|
|
209
|
+
key: "x",
|
|
210
|
+
dataIndex: "x",
|
|
211
|
+
title: xName
|
|
212
|
+
}, {
|
|
213
|
+
key: "orig",
|
|
214
|
+
dataIndex: "orig",
|
|
215
|
+
title: origName + unitString,
|
|
216
|
+
width: "50%"
|
|
217
|
+
}, {
|
|
218
|
+
key: "new",
|
|
219
|
+
dataIndex: "new",
|
|
220
|
+
title: newName + unitString,
|
|
221
|
+
width: "50%",
|
|
222
|
+
onCell: (data, index) => ({
|
|
223
|
+
value: data.new,
|
|
224
|
+
onChange: value => {
|
|
225
|
+
setNewData(prev => {
|
|
226
|
+
const next = [...prev];
|
|
227
|
+
next[index] = value;
|
|
228
|
+
return next;
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
step: adjustStep
|
|
232
|
+
}),
|
|
233
|
+
onHeaderCell: () => ({
|
|
234
|
+
style: {
|
|
235
|
+
paddingInlineStart: token.paddingXS + token.paddingSM
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
}], [xName, origName, newName, adjustStep, unitString, token]);
|
|
239
|
+
const onRow = useCallback((data, index) => {
|
|
240
|
+
if (index === undefined) return {};
|
|
241
|
+
const modified = data.orig != data.new;
|
|
242
|
+
const selected = index === selectedIndex;
|
|
243
|
+
return {
|
|
244
|
+
className: cx(styles.editableRow, {
|
|
245
|
+
[styles.modified]: modified,
|
|
246
|
+
[styles.selected]: selected
|
|
247
|
+
}),
|
|
248
|
+
onMouseEnter: () => {
|
|
249
|
+
setChartFocused(false);
|
|
250
|
+
setHoverIndex(index);
|
|
251
|
+
},
|
|
252
|
+
onMouseLeave: () => setHoverIndex(undefined)
|
|
253
|
+
};
|
|
254
|
+
}, [cx, styles, selectedIndex]);
|
|
255
|
+
const tableScrollTo = index => {
|
|
256
|
+
const table = tableRef.current?.nativeElement;
|
|
257
|
+
if (table) {
|
|
258
|
+
const header = table.getElementsByTagName("thead")[0];
|
|
259
|
+
const row = table.getElementsByTagName("tr")[index];
|
|
260
|
+
table.scrollTo({
|
|
261
|
+
top: row.offsetTop + row.offsetHeight / 2 - (table.offsetHeight - header.offsetHeight) / 2,
|
|
262
|
+
behavior: "smooth"
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const onSave = async () => {
|
|
267
|
+
const modifiedData = tableData.filter(item => item.new !== item.orig);
|
|
268
|
+
if (modifiedData.length === 0) {
|
|
269
|
+
messageApi.warning("您尚未做任何修改!");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
let confirmed = true;
|
|
273
|
+
if (confirmPopup) {
|
|
274
|
+
// TODO i18n
|
|
275
|
+
confirmed = await modal.confirm({
|
|
276
|
+
title: "确定要保存修改吗?",
|
|
277
|
+
width: "fit-content",
|
|
278
|
+
content: /*#__PURE__*/_jsxs(_Fragment, {
|
|
279
|
+
children: [/*#__PURE__*/_jsxs("p", {
|
|
280
|
+
children: ["\u60A8\u4FEE\u6539\u4E86\u4EE5\u4E0B", xName, "\u7684", yName, "\uFF1A"]
|
|
281
|
+
}), /*#__PURE__*/_jsx(Table, {
|
|
282
|
+
ref: tableRef,
|
|
283
|
+
dataSource: modifiedData,
|
|
284
|
+
columns: tableColumns.map(col => ({
|
|
285
|
+
...col,
|
|
286
|
+
onCell: undefined,
|
|
287
|
+
onHeaderCell: undefined
|
|
288
|
+
})),
|
|
289
|
+
size: "small",
|
|
290
|
+
pagination: false,
|
|
291
|
+
style: {
|
|
292
|
+
marginTop: token.marginSM,
|
|
293
|
+
maxHeight: "50vh",
|
|
294
|
+
overflowY: "auto"
|
|
295
|
+
}
|
|
296
|
+
})]
|
|
297
|
+
})
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (confirmed) {
|
|
301
|
+
onConfirm?.(newData, xData);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const controls = /*#__PURE__*/_jsxs(Flex, {
|
|
305
|
+
gap: token.marginXXS,
|
|
306
|
+
align: "baseline",
|
|
307
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
308
|
+
style: {
|
|
309
|
+
flexShrink: 0
|
|
310
|
+
},
|
|
311
|
+
children: "\u8C03\u8282\u6B65\u957F\uFF1A"
|
|
312
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
313
|
+
type: "number",
|
|
314
|
+
step: defaultAdjustStep / 10,
|
|
315
|
+
value: adjustStep,
|
|
316
|
+
onChange: event => setAdjustStep(event.currentTarget.valueAsNumber),
|
|
317
|
+
style: {
|
|
318
|
+
width: 120
|
|
319
|
+
}
|
|
320
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
321
|
+
style: {
|
|
322
|
+
flexBasis: "100%"
|
|
323
|
+
}
|
|
324
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
325
|
+
type: "primary",
|
|
326
|
+
onClick: () => void onSave(),
|
|
327
|
+
children: "\u4FDD\u5B58"
|
|
328
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
329
|
+
danger: true,
|
|
330
|
+
onClick: () => setNewData(origData),
|
|
331
|
+
children: "\u91CD\u7F6E"
|
|
332
|
+
})]
|
|
333
|
+
});
|
|
334
|
+
return /*#__PURE__*/_jsxs(Flex, {
|
|
335
|
+
vertical: true,
|
|
336
|
+
gap: token.marginXS,
|
|
337
|
+
...rest,
|
|
338
|
+
children: [modalContextHolder, messageContextHolder, controlsLocation === "top" ? controls : "", /*#__PURE__*/_jsx("div", {
|
|
339
|
+
tabIndex: 0,
|
|
340
|
+
style: {
|
|
341
|
+
flexShrink: 0,
|
|
342
|
+
outline: "none"
|
|
343
|
+
},
|
|
344
|
+
onKeyDown: onKeyDown,
|
|
345
|
+
onBlur: () => {
|
|
346
|
+
setChartFocused(false);
|
|
347
|
+
setSelectedIndex(undefined);
|
|
348
|
+
},
|
|
349
|
+
children: /*#__PURE__*/_jsx(ECharts, {
|
|
350
|
+
ref: echartsRef,
|
|
351
|
+
option: option,
|
|
352
|
+
theme: isDark ? "dark" : undefined,
|
|
353
|
+
style: {
|
|
354
|
+
height: chartHeight
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
}), useMemo(() => /*#__PURE__*/_jsx(Table, {
|
|
358
|
+
ref: tableRef,
|
|
359
|
+
dataSource: tableData,
|
|
360
|
+
columns: tableColumns,
|
|
361
|
+
size: "small",
|
|
362
|
+
pagination: false,
|
|
363
|
+
style: {
|
|
364
|
+
flexBasis: "100%",
|
|
365
|
+
overflowY: "auto"
|
|
366
|
+
},
|
|
367
|
+
components: {
|
|
368
|
+
body: {
|
|
369
|
+
cell: EditorCell
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
onHeaderRow: () => ({
|
|
373
|
+
style: {
|
|
374
|
+
position: "sticky",
|
|
375
|
+
top: 0,
|
|
376
|
+
zIndex: 1
|
|
377
|
+
}
|
|
378
|
+
}),
|
|
379
|
+
onRow: onRow
|
|
380
|
+
}), [tableData, tableColumns, onRow]), controlsLocation === "bottom" ? controls : ""]
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
export default LineChartEditor;
|
|
384
|
+
function EditorCell({
|
|
385
|
+
value,
|
|
386
|
+
onChange,
|
|
387
|
+
step,
|
|
388
|
+
...props
|
|
389
|
+
}) {
|
|
390
|
+
if (value === undefined) {
|
|
391
|
+
return /*#__PURE__*/_jsx("td", {
|
|
392
|
+
...props
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
396
|
+
const {
|
|
397
|
+
styles
|
|
398
|
+
} = useStyles();
|
|
399
|
+
const [editing, setEditing] = useState(false);
|
|
400
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
401
|
+
return /*#__PURE__*/_jsx("td", {
|
|
402
|
+
...props,
|
|
403
|
+
style: {
|
|
404
|
+
paddingBlock: 0
|
|
405
|
+
},
|
|
406
|
+
children: editing ? /*#__PURE__*/_jsx(Input, {
|
|
407
|
+
ref: input => input?.focus(),
|
|
408
|
+
type: "number",
|
|
409
|
+
step: step,
|
|
410
|
+
style: {
|
|
411
|
+
margin: 0
|
|
412
|
+
},
|
|
413
|
+
defaultValue: value,
|
|
414
|
+
onChange: event => onChange(event.currentTarget.valueAsNumber),
|
|
415
|
+
onPressEnter: () => setEditing(false),
|
|
416
|
+
onBlur: () => setEditing(false)
|
|
417
|
+
}) : /*#__PURE__*/_jsx("div", {
|
|
418
|
+
className: styles.editableWrapper,
|
|
419
|
+
onClick: () => setEditing(true),
|
|
420
|
+
children: value
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const useStyles = createStyles(({
|
|
425
|
+
css,
|
|
426
|
+
cx,
|
|
427
|
+
token
|
|
428
|
+
}) => {
|
|
429
|
+
const editableWrapper = css`
|
|
430
|
+
padding: ${token.paddingXXS}px ${token.paddingSM - 1 + 24}px
|
|
431
|
+
${token.paddingXXS}px ${token.paddingSM - 1}px;
|
|
432
|
+
cursor: text;
|
|
433
|
+
border-radius: ${token.borderRadius}px;
|
|
434
|
+
border: 1px solid transparent;
|
|
435
|
+
transition: border ${token.motionDurationFast};
|
|
436
|
+
`;
|
|
437
|
+
const modified = css`
|
|
438
|
+
color: ${token.colorSuccess};
|
|
439
|
+
background: ${token.colorSuccessBg};
|
|
440
|
+
`;
|
|
441
|
+
const selected = css`
|
|
442
|
+
background: ${token.colorFillTertiary};
|
|
443
|
+
`;
|
|
444
|
+
const editableRow = css`
|
|
445
|
+
&:hover:not(.${cx(selected)}) {
|
|
446
|
+
background: ${token.colorFillQuaternary};
|
|
447
|
+
}
|
|
448
|
+
&:hover .${cx(editableWrapper)} {
|
|
449
|
+
border-color: ${token.colorBorder};
|
|
450
|
+
}
|
|
451
|
+
`;
|
|
452
|
+
return {
|
|
453
|
+
editableRow,
|
|
454
|
+
editableWrapper,
|
|
455
|
+
modified,
|
|
456
|
+
selected
|
|
457
|
+
};
|
|
458
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type FlexProps } from "antd";
|
|
2
|
+
import type { LineSeriesOption } from "echarts";
|
|
3
|
+
export interface LineChartTableProps extends Omit<FlexProps, "children"> {
|
|
4
|
+
/** X 轴的数据。*/
|
|
5
|
+
xData: (string | number)[];
|
|
6
|
+
/**
|
|
7
|
+
* X 轴的名称。
|
|
8
|
+
* @default "时间"
|
|
9
|
+
*/
|
|
10
|
+
xName?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Y 轴的名称。
|
|
13
|
+
* @default "数值"
|
|
14
|
+
*/
|
|
15
|
+
yName?: string;
|
|
16
|
+
/** Y 轴的单位,默认不显示。*/
|
|
17
|
+
yUnit?: string;
|
|
18
|
+
/** 各个曲线的名称、数据和其它选项(颜色、插值模式等)。*/
|
|
19
|
+
series?: {
|
|
20
|
+
name: string;
|
|
21
|
+
data: number[];
|
|
22
|
+
option?: LineSeriesOption;
|
|
23
|
+
}[];
|
|
24
|
+
/**
|
|
25
|
+
* 折线图的高度。表格会自动占满剩余的高度。
|
|
26
|
+
* @default 175
|
|
27
|
+
*/
|
|
28
|
+
chartHeight?: string | number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 折线图与表格的组合,用鼠标指向表格中的数据时会高亮折线图中的对应数据,反之亦然。
|
|
32
|
+
*
|
|
33
|
+
* 除了文档列出的属性外,多余的属性会被传递给最外层的 [Flex][1] 组件。
|
|
34
|
+
*
|
|
35
|
+
* [1]: https://ant-design.antgroup.com/components/flex-cn#api
|
|
36
|
+
*/
|
|
37
|
+
declare function LineChartTable(props: LineChartTableProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export default LineChartTable;
|