lowcoder-map-component 0.1.1
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/README.md +37 -0
- package/icons/demo-icon.svg +10 -0
- package/icons/hills.svg +17 -0
- package/index.css +27 -0
- package/index.html +35 -0
- package/index.tsx +20 -0
- package/loader.mjs +11 -0
- package/package.json +175 -0
- package/src/README.md +35 -0
- package/src/components/ChartPropertyView.tsx +961 -0
- package/src/components/SeriesComp.tsx +368 -0
- package/src/components/TabPropertyView.tsx +127 -0
- package/src/comps/Barcharts/comp.tsx +338 -0
- package/src/comps/Barcharts/constants.tsx +77 -0
- package/src/comps/Linecharts/comp.tsx +350 -0
- package/src/comps/Linecharts/constants.tsx +53 -0
- package/src/comps/Linechartsv2/comp.tsx +350 -0
- package/src/comps/Linechartsv2/constants.tsx +68 -0
- package/src/comps/Mapcharts/comp.tsx +381 -0
- package/src/comps/Mapcharts/constants.tsx +312 -0
- package/src/comps/Mapchartsv2/comp.tsx +393 -0
- package/src/comps/Mapchartsv2/constants.tsx +340 -0
- package/src/comps/MixedLineBarCharts/comp.tsx +353 -0
- package/src/comps/MixedLineBarCharts/constants.tsx +60 -0
- package/src/comps/MultiLineCharts/comp.tsx +362 -0
- package/src/comps/MultiLineCharts/constants.tsx +96 -0
- package/src/comps/PercentageCharts/comp.tsx +359 -0
- package/src/comps/PercentageCharts/constants.tsx +98 -0
- package/src/comps/Piecharts/comp.tsx +334 -0
- package/src/comps/Piecharts/constants.tsx +48 -0
- package/src/comps/Tablecharts/comp.tsx +429 -0
- package/src/comps/Tablecharts/constants.tsx +97 -0
- package/src/comps/Totalcharts/comp.tsx +463 -0
- package/src/comps/Totalcharts/constants.tsx +66 -0
- package/src/comps/TwoLineCharts/comp.tsx +350 -0
- package/src/comps/TwoLineCharts/constants.tsx +82 -0
- package/src/comps/mapComponent/comp.tsx +338 -0
- package/src/comps/mapComponent/constants.tsx +2149 -0
- package/src/comps/tab/comp.tsx +283 -0
- package/src/comps/tab/constants.tsx +79 -0
- package/src/configs/barChartConfig.tsx +153 -0
- package/src/configs/baseConfig.tsx +66 -0
- package/src/configs/candleStickChartConfig.tsx +35 -0
- package/src/configs/cartesianAxisConfig.tsx +314 -0
- package/src/configs/chartUrls.tsx +9 -0
- package/src/configs/echartConfig.tsx +260 -0
- package/src/configs/echartsLabelConfig.tsx +47 -0
- package/src/configs/echartsLegendConfig.tsx +29 -0
- package/src/configs/echartsTitleConfig.tsx +49 -0
- package/src/configs/echartsTitleVerticalConfig.tsx +50 -0
- package/src/configs/funnelChartConfig.tsx +35 -0
- package/src/configs/gaugeChartConfig.tsx +31 -0
- package/src/configs/graphChartConfig.tsx +31 -0
- package/src/configs/heatmapChartConfig.tsx +31 -0
- package/src/configs/legendConfig.tsx +55 -0
- package/src/configs/lineChartConfig.tsx +246 -0
- package/src/configs/lineChartConfigv2.tsx +246 -0
- package/src/configs/mapChartConfig.tsx +106 -0
- package/src/configs/mapChartConfigv2.tsx +106 -0
- package/src/configs/mixedChartConfig.tsx +21 -0
- package/src/configs/pieChartConfig.tsx +156 -0
- package/src/configs/radarChartConfig.tsx +31 -0
- package/src/configs/sankeyChartConfig.tsx +35 -0
- package/src/configs/scatterChartConfig.tsx +152 -0
- package/src/configs/sunburstChartConfig.tsx +31 -0
- package/src/configs/tabConfig.tsx +0 -0
- package/src/configs/tableChartConfig.tsx +81 -0
- package/src/configs/themeriverChartConfig.tsx +31 -0
- package/src/configs/totalChartConfig.tsx +670 -0
- package/src/configs/treeChartConfig.tsx +31 -0
- package/src/configs/treemapChartConfig.tsx +31 -0
- package/src/controls/AnimationsControls.tsx +3 -0
- package/src/controls/AutoHeightControl.tsx +2 -0
- package/src/controls/AxisControls.tsx +146 -0
- package/src/controls/AxisVisibilityControl.tsx +14 -0
- package/src/controls/ChartTypeControl.tsx +15 -0
- package/src/controls/ColorScaleControl.tsx +221 -0
- package/src/controls/ColumnControl.tsx +204 -0
- package/src/controls/ConfigControl.tsx +37 -0
- package/src/controls/DirectionControls.tsx +20 -0
- package/src/controls/IconControl.tsx +88 -0
- package/src/controls/LegendControl.tsx +8 -0
- package/src/controls/RowLimitControl.tsx +91 -0
- package/src/controls/StyleControls.tsx +22 -0
- package/src/controls/TimeControls.tsx +41 -0
- package/src/controls/TrendlineControl.tsx +89 -0
- package/src/controls/UIEventControl.tsx +21 -0
- package/src/controls/index.ts +16 -0
- package/src/controls/radioControl.tsx +88 -0
- package/src/exposing/index.ts +3 -0
- package/src/exposing/setPoint.ts +19 -0
- package/src/geo/vn.geo.json +369897 -0
- package/src/geo/world.geo.json +32127 -0
- package/src/i18n/comps/index.tsx +39 -0
- package/src/i18n/comps/locales/en.ts +558 -0
- package/src/i18n/comps/locales/enObj.tsx +7186 -0
- package/src/i18n/comps/locales/index.ts +7 -0
- package/src/i18n/comps/locales/pt.ts +37 -0
- package/src/i18n/comps/locales/ptObj.tsx +40 -0
- package/src/i18n/comps/locales/types.tsx +622 -0
- package/src/i18n/comps/locales/zh.ts +3 -0
- package/src/i18n/comps/locales/zhObj.tsx +4 -0
- package/src/index.ts +31 -0
- package/src/types/global.d.ts +9 -0
- package/src/types/lowcoder-sdk.d.ts +578 -0
- package/src/utils/chartStyle.util.ts +121 -0
- package/src/utils/columnExtractor.util.ts +41 -0
- package/src/utils/dataTransform.util.ts +37 -0
- package/src/utils/deepEqual.util.ts +29 -0
- package/src/utils/echarts.util.tsx +822 -0
- package/src/utils/getDataKey.util.ts +115 -0
- package/src/utils/getLinearRegression.util.ts +46 -0
- package/src/utils/googleMaps.util.ts +28 -0
- package/src/utils/isEmpty.util.ts +10 -0
- package/src/utils/move.util.ts +6 -0
- package/src/utils/selection.util.ts +73 -0
- package/src/utils/style.util.ts +315 -0
- package/src/utils/time.util.ts +221 -0
- package/src/utils/timeFormatter.util.ts +104 -0
- package/src/utils/timeProcessing.util.ts +38 -0
- package/src/utils/trendline.util.ts +342 -0
- package/tsconfig.json +25 -0
- package/vite.config.js +19 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { ChartPropertyView } from "@/components/ChartPropertyView";
|
|
2
|
+
import { EchartsAxisType } from "@/configs/cartesianAxisConfig";
|
|
3
|
+
import { eChartConfigOmitChildren } from "@/configs/echartConfig";
|
|
4
|
+
import { formatValue } from "@/configs/totalChartConfig";
|
|
5
|
+
import { AxisFormatterComp } from "@/controls";
|
|
6
|
+
import { renderIcon } from "@/controls/IconControl";
|
|
7
|
+
import { getEchartsLocale, trans } from "@/i18n/comps";
|
|
8
|
+
import { formatAllStyles } from "@/utils/chartStyle.util";
|
|
9
|
+
import { deepEqual } from "@/utils/deepEqual.util";
|
|
10
|
+
import { ChartSize, echartProps, getEChartConfig } from "@/utils/echarts.util";
|
|
11
|
+
import { getSelectedPoints } from "@/utils/selection.util";
|
|
12
|
+
import {
|
|
13
|
+
FallOutlined,
|
|
14
|
+
LineOutlined,
|
|
15
|
+
RiseOutlined,
|
|
16
|
+
WarningOutlined,
|
|
17
|
+
} from "@ant-design/icons";
|
|
18
|
+
import { Button, Card, Flex, Statistic } from "antd";
|
|
19
|
+
import ReactECharts from "echarts-for-react";
|
|
20
|
+
import EChartsReactCore from "echarts-for-react/lib/core";
|
|
21
|
+
import {
|
|
22
|
+
changeChildAction,
|
|
23
|
+
chartColorPalette,
|
|
24
|
+
childrenToProps,
|
|
25
|
+
CompAction,
|
|
26
|
+
depsConfig,
|
|
27
|
+
genRandomKey,
|
|
28
|
+
getPromiseAfterDispatch,
|
|
29
|
+
JSONObject,
|
|
30
|
+
NameConfig,
|
|
31
|
+
Theme,
|
|
32
|
+
ThemeContext,
|
|
33
|
+
UICompBuilder,
|
|
34
|
+
valueComp,
|
|
35
|
+
withDefault,
|
|
36
|
+
withExposingConfigs,
|
|
37
|
+
withViewFn,
|
|
38
|
+
wrapChildAction,
|
|
39
|
+
} from "lowcoder-sdk";
|
|
40
|
+
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
41
|
+
import { useResizeDetector } from "react-resize-detector";
|
|
42
|
+
import { chartUiProps } from "./constants";
|
|
43
|
+
|
|
44
|
+
let clickEventCallback = () => {};
|
|
45
|
+
|
|
46
|
+
let TotalchartsTmpComp = (function () {
|
|
47
|
+
return new UICompBuilder(
|
|
48
|
+
{
|
|
49
|
+
...echartProps,
|
|
50
|
+
...chartUiProps,
|
|
51
|
+
},
|
|
52
|
+
() => null
|
|
53
|
+
)
|
|
54
|
+
.setPropertyViewFn(ChartPropertyView)
|
|
55
|
+
.build();
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
function calculateGrowth(
|
|
59
|
+
newValue: number,
|
|
60
|
+
oldValue: number
|
|
61
|
+
): {
|
|
62
|
+
percent: number;
|
|
63
|
+
status: "increase" | "decrease" | string;
|
|
64
|
+
} {
|
|
65
|
+
const percent = ((newValue - oldValue) / oldValue) * 100;
|
|
66
|
+
|
|
67
|
+
let status = "";
|
|
68
|
+
|
|
69
|
+
if (percent > 0) {
|
|
70
|
+
status = "increase";
|
|
71
|
+
} else if (percent < 0) {
|
|
72
|
+
status = "decrease";
|
|
73
|
+
} else {
|
|
74
|
+
status = "-";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
percent: Math.round(percent * 100) / 100,
|
|
79
|
+
status,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
TotalchartsTmpComp = withViewFn(TotalchartsTmpComp, (comp) => {
|
|
84
|
+
const onUIEvent = comp.children.onUIEvent.getView();
|
|
85
|
+
const onEvent = comp.children.onEvent.getView();
|
|
86
|
+
const eChartCompRef = useRef<EChartsReactCore | null>();
|
|
87
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
88
|
+
const theme: Theme = useContext(ThemeContext);
|
|
89
|
+
|
|
90
|
+
const defaultChartTheme = {
|
|
91
|
+
color: chartColorPalette,
|
|
92
|
+
backgroundColor: "#fff",
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
let themeConfig = defaultChartTheme;
|
|
96
|
+
try {
|
|
97
|
+
themeConfig = theme?.theme?.chart
|
|
98
|
+
? JSON.parse(theme.theme.chart)
|
|
99
|
+
: defaultChartTheme;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error("theme chart error: ", error);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const triggerClickEvent = async (dispatch: any, action: CompAction) => {
|
|
105
|
+
await getPromiseAfterDispatch(dispatch, action, {
|
|
106
|
+
autoHandleAfterReduce: true,
|
|
107
|
+
});
|
|
108
|
+
onEvent("click");
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const eChartCompInstance = eChartCompRef?.current?.getEchartsInstance();
|
|
113
|
+
if (!eChartCompInstance) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
eChartCompInstance?.on("click", (param: any) => {
|
|
118
|
+
document.dispatchEvent(
|
|
119
|
+
new CustomEvent("clickEvent", {
|
|
120
|
+
bubbles: true,
|
|
121
|
+
detail: {
|
|
122
|
+
action: "click",
|
|
123
|
+
data: param.data,
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
triggerClickEvent(
|
|
128
|
+
comp.dispatch,
|
|
129
|
+
changeChildAction("lastInteractionData", param.data, false)
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
return () => {
|
|
133
|
+
eChartCompInstance?.off("click");
|
|
134
|
+
document.removeEventListener("clickEvent", clickEventCallback);
|
|
135
|
+
};
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
// bind events
|
|
140
|
+
const eChartCompInstance = eChartCompRef?.current?.getEchartsInstance();
|
|
141
|
+
if (!eChartCompInstance) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
eChartCompInstance?.on("selectchanged", (param: any) => {
|
|
145
|
+
const option: any = eChartCompInstance?.getOption();
|
|
146
|
+
document.dispatchEvent(
|
|
147
|
+
new CustomEvent("clickEvent", {
|
|
148
|
+
bubbles: true,
|
|
149
|
+
detail: {
|
|
150
|
+
action: param.fromAction,
|
|
151
|
+
data: getSelectedPoints(param, option),
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (param.fromAction === "select") {
|
|
157
|
+
comp.dispatch(
|
|
158
|
+
changeChildAction(
|
|
159
|
+
"selectedPoints",
|
|
160
|
+
getSelectedPoints(param, option),
|
|
161
|
+
false
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
onUIEvent("select");
|
|
165
|
+
} else if (param.fromAction === "unselect") {
|
|
166
|
+
comp.dispatch(
|
|
167
|
+
changeChildAction(
|
|
168
|
+
"selectedPoints",
|
|
169
|
+
getSelectedPoints(param, option),
|
|
170
|
+
false
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
onUIEvent("unselect");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
triggerClickEvent(
|
|
177
|
+
comp.dispatch,
|
|
178
|
+
changeChildAction(
|
|
179
|
+
"lastInteractionData",
|
|
180
|
+
getSelectedPoints(param, option),
|
|
181
|
+
false
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
// unbind
|
|
186
|
+
return () => {
|
|
187
|
+
eChartCompInstance?.off("selectchanged");
|
|
188
|
+
document.removeEventListener("clickEvent", clickEventCallback);
|
|
189
|
+
};
|
|
190
|
+
}, [onUIEvent]);
|
|
191
|
+
|
|
192
|
+
const eChartConfigChildren: any = {};
|
|
193
|
+
for (const [key, value] of Object.entries(comp.children)) {
|
|
194
|
+
if (!eChartConfigOmitChildren.includes(key as any)) {
|
|
195
|
+
eChartConfigChildren[key] = value;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const childrenProps = formatAllStyles(childrenToProps(comp.children));
|
|
200
|
+
|
|
201
|
+
const { chartConfig, data } = childrenProps;
|
|
202
|
+
|
|
203
|
+
const { chartData, trend, subData, title, value, unit } = data?.[0] || {};
|
|
204
|
+
const { dataStyle, iconStyle, titleStyle } = chartConfig;
|
|
205
|
+
|
|
206
|
+
let xAxisKey = childrenProps.xAxisKey;
|
|
207
|
+
if (!xAxisKey && chartData && chartData.length > 0) {
|
|
208
|
+
const firstItem = chartData[0];
|
|
209
|
+
xAxisKey = firstItem.hasOwnProperty("date")
|
|
210
|
+
? "date"
|
|
211
|
+
: Object.keys(firstItem)[0];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const updatedChildrenProps: any = {
|
|
215
|
+
...childrenProps,
|
|
216
|
+
data: chartData,
|
|
217
|
+
xAxisKey: xAxisKey || childrenProps.xAxisKey,
|
|
218
|
+
};
|
|
219
|
+
const trendGrowth = calculateGrowth(trend?.value, trend?.oldValue);
|
|
220
|
+
const color =
|
|
221
|
+
(trendGrowth.status === "increase" &&
|
|
222
|
+
(chartConfig.increaseColor || "#0CD12E")) ||
|
|
223
|
+
(trendGrowth.status === "decrease" &&
|
|
224
|
+
(chartConfig.decreaseColor || "#ED3333")) ||
|
|
225
|
+
"";
|
|
226
|
+
const subGrowth = calculateGrowth(subData?.value, subData?.oldValue);
|
|
227
|
+
const subColor =
|
|
228
|
+
(subGrowth.status === "increase" && chartConfig?.subIncreaseColor) ||
|
|
229
|
+
(subGrowth.status === "decrease" && chartConfig?.subDecreaseColor) ||
|
|
230
|
+
"";
|
|
231
|
+
|
|
232
|
+
const [chartSize, setChartSize] = useState<ChartSize>();
|
|
233
|
+
const firstResize = useRef(true);
|
|
234
|
+
|
|
235
|
+
const option = useMemo(() => {
|
|
236
|
+
return getEChartConfig(updatedChildrenProps, chartSize, themeConfig);
|
|
237
|
+
}, [themeConfig, updatedChildrenProps, chartSize]);
|
|
238
|
+
|
|
239
|
+
useResizeDetector({
|
|
240
|
+
targetRef: containerRef,
|
|
241
|
+
onResize: ({ width, height }) => {
|
|
242
|
+
if (width && height) {
|
|
243
|
+
setChartSize({ w: width, h: height });
|
|
244
|
+
}
|
|
245
|
+
if (!firstResize.current) {
|
|
246
|
+
eChartCompRef.current?.getEchartsInstance().resize();
|
|
247
|
+
} else {
|
|
248
|
+
firstResize.current = false;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<div ref={containerRef} style={{ height: "100%" }}>
|
|
255
|
+
<Card
|
|
256
|
+
style={{
|
|
257
|
+
borderRadius: 12,
|
|
258
|
+
...dataStyle,
|
|
259
|
+
}}
|
|
260
|
+
styles={{ body: { padding: 16 } }}
|
|
261
|
+
>
|
|
262
|
+
<Flex vertical gap={5}>
|
|
263
|
+
<Flex gap={12} justify="space-between" align="center">
|
|
264
|
+
{chartConfig.showIcon ? (
|
|
265
|
+
<Button
|
|
266
|
+
icon={
|
|
267
|
+
chartConfig.icon ? (
|
|
268
|
+
renderIcon(chartConfig.icon)
|
|
269
|
+
) : (
|
|
270
|
+
<WarningOutlined />
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
type="primary"
|
|
274
|
+
style={{
|
|
275
|
+
...iconStyle,
|
|
276
|
+
backgroundColor: iconStyle.backgroundColor || color,
|
|
277
|
+
cursor: "unset",
|
|
278
|
+
}}
|
|
279
|
+
></Button>
|
|
280
|
+
) : (
|
|
281
|
+
<div></div>
|
|
282
|
+
)}
|
|
283
|
+
{chartConfig.showTrendIndicator && trend && (
|
|
284
|
+
<Statistic
|
|
285
|
+
value={trendGrowth.percent}
|
|
286
|
+
precision={chartConfig?.precisionTrend || 0}
|
|
287
|
+
valueStyle={{ color, fontSize: 14 }}
|
|
288
|
+
prefix={
|
|
289
|
+
(trendGrowth.status === "increase" &&
|
|
290
|
+
(chartConfig?.increaseIcon ? (
|
|
291
|
+
renderIcon(chartConfig.increaseIcon)
|
|
292
|
+
) : (
|
|
293
|
+
<RiseOutlined />
|
|
294
|
+
))) ||
|
|
295
|
+
(trendGrowth.status === "decrease" &&
|
|
296
|
+
(chartConfig?.decreaseIcon ? (
|
|
297
|
+
renderIcon(chartConfig.decreaseIcon)
|
|
298
|
+
) : (
|
|
299
|
+
<FallOutlined />
|
|
300
|
+
))) || <LineOutlined />
|
|
301
|
+
}
|
|
302
|
+
suffix={trend.suffix}
|
|
303
|
+
/>
|
|
304
|
+
)}
|
|
305
|
+
</Flex>
|
|
306
|
+
|
|
307
|
+
<Flex align="center" vertical>
|
|
308
|
+
<Flex gap={5} align="center">
|
|
309
|
+
<Statistic
|
|
310
|
+
value={value}
|
|
311
|
+
valueStyle={{ color, fontWeight: "bold" }}
|
|
312
|
+
precision={chartConfig?.precision || 0}
|
|
313
|
+
valueRender={(val: any) =>
|
|
314
|
+
formatValue(val, chartConfig.unit, unit)
|
|
315
|
+
}
|
|
316
|
+
/>
|
|
317
|
+
</Flex>
|
|
318
|
+
{chartConfig.showTitle && (
|
|
319
|
+
<b style={titleStyle}>{chartConfig.title || title}</b>
|
|
320
|
+
)}
|
|
321
|
+
{chartConfig.showSubData && (
|
|
322
|
+
<Statistic
|
|
323
|
+
value={subData?.value}
|
|
324
|
+
precision={chartConfig?.precisionSub || 0}
|
|
325
|
+
valueStyle={{ fontSize: 14, color: subColor }}
|
|
326
|
+
suffix={subData?.suffix}
|
|
327
|
+
valueRender={(val) => <b>{val}</b>}
|
|
328
|
+
prefix={
|
|
329
|
+
chartConfig.subIncreaseIcon
|
|
330
|
+
? (subGrowth.status === "increase" &&
|
|
331
|
+
renderIcon(chartConfig.subIncreaseIcon)) ||
|
|
332
|
+
(subGrowth.status === "decrease" &&
|
|
333
|
+
renderIcon(chartConfig.subDecreaseIcon)) || (
|
|
334
|
+
<LineOutlined />
|
|
335
|
+
)
|
|
336
|
+
: null
|
|
337
|
+
}
|
|
338
|
+
/>
|
|
339
|
+
)}
|
|
340
|
+
</Flex>
|
|
341
|
+
</Flex>
|
|
342
|
+
|
|
343
|
+
{chartConfig.showTrendLine && chartData?.length ? (
|
|
344
|
+
<div style={{ marginTop: 12, height: "10em" }}>
|
|
345
|
+
<ReactECharts
|
|
346
|
+
ref={(e) => (eChartCompRef.current = e)}
|
|
347
|
+
style={{ height: "100%" }}
|
|
348
|
+
notMerge
|
|
349
|
+
lazyUpdate
|
|
350
|
+
opts={{ locale: getEchartsLocale() }}
|
|
351
|
+
option={option}
|
|
352
|
+
/>
|
|
353
|
+
</div>
|
|
354
|
+
) : null}
|
|
355
|
+
</Card>
|
|
356
|
+
</div>
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
function getYAxisFormatContextValue(
|
|
361
|
+
data: Array<JSONObject>,
|
|
362
|
+
yAxisType: EchartsAxisType,
|
|
363
|
+
yAxisName?: string
|
|
364
|
+
) {
|
|
365
|
+
const dataSample = yAxisName && data.length > 0 && data[0][yAxisName];
|
|
366
|
+
let contextValue = dataSample;
|
|
367
|
+
if (yAxisType === "time") {
|
|
368
|
+
// to timestamp
|
|
369
|
+
const time =
|
|
370
|
+
typeof dataSample === "number" || typeof dataSample === "string"
|
|
371
|
+
? new Date(dataSample).getTime()
|
|
372
|
+
: null;
|
|
373
|
+
if (time) contextValue = time;
|
|
374
|
+
}
|
|
375
|
+
return contextValue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
TotalchartsTmpComp = class extends TotalchartsTmpComp {
|
|
379
|
+
updateContext(comp: any) {
|
|
380
|
+
// the context value of axis format
|
|
381
|
+
let resultComp = comp;
|
|
382
|
+
const data = comp.children.data.getView();
|
|
383
|
+
const sampleSeries = comp.children.series
|
|
384
|
+
.getView()
|
|
385
|
+
.find((s: any) => !s.getView().hide);
|
|
386
|
+
const yAxisContextValue = getYAxisFormatContextValue(
|
|
387
|
+
data,
|
|
388
|
+
comp.children.yConfig.children.yAxisType.getView(),
|
|
389
|
+
sampleSeries?.children.columnName.getView()
|
|
390
|
+
);
|
|
391
|
+
if (yAxisContextValue !== comp.lastYAxisFormatContextVal) {
|
|
392
|
+
comp.lastYAxisFormatContextVal = yAxisContextValue;
|
|
393
|
+
resultComp = comp.setChild(
|
|
394
|
+
"yConfig",
|
|
395
|
+
comp.children.yConfig.reduce(
|
|
396
|
+
wrapChildAction(
|
|
397
|
+
"formatter",
|
|
398
|
+
AxisFormatterComp.changeContextDataAction({
|
|
399
|
+
value: yAxisContextValue,
|
|
400
|
+
})
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
// item color context
|
|
406
|
+
const colorContextVal = {
|
|
407
|
+
seriesName: sampleSeries?.children.seriesName.getView(),
|
|
408
|
+
value: yAxisContextValue,
|
|
409
|
+
};
|
|
410
|
+
if (
|
|
411
|
+
comp.children.chartConfig.children.comp.children.hasOwnProperty(
|
|
412
|
+
"itemColor"
|
|
413
|
+
) &&
|
|
414
|
+
!deepEqual(colorContextVal, comp.lastColorContext)
|
|
415
|
+
) {
|
|
416
|
+
comp.lastColorContext = colorContextVal;
|
|
417
|
+
}
|
|
418
|
+
return resultComp;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
reduce(action: CompAction): this {
|
|
422
|
+
return super.reduce(action);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
autoHeight(): boolean {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
let TotalChartComp = withExposingConfigs(TotalchartsTmpComp, [
|
|
431
|
+
depsConfig({
|
|
432
|
+
name: "selectedPoints",
|
|
433
|
+
desc: trans("chart.selectedPointsDesc"),
|
|
434
|
+
depKeys: ["selectedPoints"],
|
|
435
|
+
func: (input) => {
|
|
436
|
+
return input.selectedPoints;
|
|
437
|
+
},
|
|
438
|
+
}),
|
|
439
|
+
depsConfig({
|
|
440
|
+
name: "lastInteractionData",
|
|
441
|
+
desc: trans("chart.lastInteractionDataDesc"),
|
|
442
|
+
depKeys: ["lastInteractionData"],
|
|
443
|
+
func: (input) => {
|
|
444
|
+
return input.lastInteractionData;
|
|
445
|
+
},
|
|
446
|
+
}),
|
|
447
|
+
depsConfig({
|
|
448
|
+
name: "data",
|
|
449
|
+
desc: trans("chart.dataDesc"),
|
|
450
|
+
depKeys: ["data", "mode"],
|
|
451
|
+
func: (input) => [],
|
|
452
|
+
}),
|
|
453
|
+
new NameConfig("title", trans("chart.titleDesc")),
|
|
454
|
+
]);
|
|
455
|
+
|
|
456
|
+
export const TotalChartCompWithDefault = withDefault(TotalChartComp, {
|
|
457
|
+
xAxisKey: valueComp<string>("value"),
|
|
458
|
+
series: [
|
|
459
|
+
{
|
|
460
|
+
dataIndex: genRandomKey(),
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createSeriesListComp } from "@/components/SeriesComp";
|
|
2
|
+
import { ChartOptionMap } from "@/controls";
|
|
3
|
+
import {
|
|
4
|
+
EchartDefaultTextStyle,
|
|
5
|
+
jsonControl,
|
|
6
|
+
NumberControl,
|
|
7
|
+
RecordConstructorToView,
|
|
8
|
+
StringControl,
|
|
9
|
+
styleControl,
|
|
10
|
+
toJSONObjectArray,
|
|
11
|
+
uiChildren,
|
|
12
|
+
withDefault,
|
|
13
|
+
withType,
|
|
14
|
+
} from "lowcoder-sdk";
|
|
15
|
+
|
|
16
|
+
const defaultChartData = [
|
|
17
|
+
{
|
|
18
|
+
trend: { value: 9.2, oldValue: 9.5, suffix: "% kỳ trước" },
|
|
19
|
+
subData: { value: 10.2, oldValue: 9.8, suffix: "% kế hoạch" },
|
|
20
|
+
value: 30,
|
|
21
|
+
unit: "Văn bản",
|
|
22
|
+
title: "Văn bản chậm tiến độ",
|
|
23
|
+
chartData: [
|
|
24
|
+
{ date: "25-01-2025", value: 320 },
|
|
25
|
+
{ date: "30-03-2025", value: 450 },
|
|
26
|
+
{ date: "12-05-2025", value: 380 },
|
|
27
|
+
{ date: "07-07-2025", value: 520 },
|
|
28
|
+
{ date: "09-08-2025", value: 480 },
|
|
29
|
+
{ date: "10-09-2025", value: 600 },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export const chartUiProps = {
|
|
35
|
+
chartConfig: withType(ChartOptionMap, "total"),
|
|
36
|
+
chartType: withDefault(StringControl, "total"),
|
|
37
|
+
title: StringControl,
|
|
38
|
+
defaultData: jsonControl(toJSONObjectArray, defaultChartData),
|
|
39
|
+
series: createSeriesListComp("line"),
|
|
40
|
+
xAxisStyle: styleControl(EchartDefaultTextStyle, "xAxis"),
|
|
41
|
+
yAxisStyle: styleControl(EchartDefaultTextStyle, "yAxisStyle"),
|
|
42
|
+
top: withDefault(NumberControl, 30),
|
|
43
|
+
bottom: withDefault(NumberControl, 0),
|
|
44
|
+
left: withDefault(NumberControl, 0),
|
|
45
|
+
right: withDefault(NumberControl, 0),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const chartUiChildrenMap = uiChildren(chartUiProps);
|
|
49
|
+
export type ChartUiPropsType = RecordConstructorToView<
|
|
50
|
+
typeof chartUiChildrenMap
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
export type UIChartDataType = {
|
|
54
|
+
seriesName: string;
|
|
55
|
+
// coordinate chart
|
|
56
|
+
x?: any;
|
|
57
|
+
y?: any;
|
|
58
|
+
// pie or funnel
|
|
59
|
+
itemName?: any;
|
|
60
|
+
value?: any;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type NonUIChartDataType = {
|
|
64
|
+
name: string;
|
|
65
|
+
value: any;
|
|
66
|
+
};
|