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.
Files changed (123) hide show
  1. package/README.md +37 -0
  2. package/icons/demo-icon.svg +10 -0
  3. package/icons/hills.svg +17 -0
  4. package/index.css +27 -0
  5. package/index.html +35 -0
  6. package/index.tsx +20 -0
  7. package/loader.mjs +11 -0
  8. package/package.json +175 -0
  9. package/src/README.md +35 -0
  10. package/src/components/ChartPropertyView.tsx +961 -0
  11. package/src/components/SeriesComp.tsx +368 -0
  12. package/src/components/TabPropertyView.tsx +127 -0
  13. package/src/comps/Barcharts/comp.tsx +338 -0
  14. package/src/comps/Barcharts/constants.tsx +77 -0
  15. package/src/comps/Linecharts/comp.tsx +350 -0
  16. package/src/comps/Linecharts/constants.tsx +53 -0
  17. package/src/comps/Linechartsv2/comp.tsx +350 -0
  18. package/src/comps/Linechartsv2/constants.tsx +68 -0
  19. package/src/comps/Mapcharts/comp.tsx +381 -0
  20. package/src/comps/Mapcharts/constants.tsx +312 -0
  21. package/src/comps/Mapchartsv2/comp.tsx +393 -0
  22. package/src/comps/Mapchartsv2/constants.tsx +340 -0
  23. package/src/comps/MixedLineBarCharts/comp.tsx +353 -0
  24. package/src/comps/MixedLineBarCharts/constants.tsx +60 -0
  25. package/src/comps/MultiLineCharts/comp.tsx +362 -0
  26. package/src/comps/MultiLineCharts/constants.tsx +96 -0
  27. package/src/comps/PercentageCharts/comp.tsx +359 -0
  28. package/src/comps/PercentageCharts/constants.tsx +98 -0
  29. package/src/comps/Piecharts/comp.tsx +334 -0
  30. package/src/comps/Piecharts/constants.tsx +48 -0
  31. package/src/comps/Tablecharts/comp.tsx +429 -0
  32. package/src/comps/Tablecharts/constants.tsx +97 -0
  33. package/src/comps/Totalcharts/comp.tsx +463 -0
  34. package/src/comps/Totalcharts/constants.tsx +66 -0
  35. package/src/comps/TwoLineCharts/comp.tsx +350 -0
  36. package/src/comps/TwoLineCharts/constants.tsx +82 -0
  37. package/src/comps/mapComponent/comp.tsx +338 -0
  38. package/src/comps/mapComponent/constants.tsx +2149 -0
  39. package/src/comps/tab/comp.tsx +283 -0
  40. package/src/comps/tab/constants.tsx +79 -0
  41. package/src/configs/barChartConfig.tsx +153 -0
  42. package/src/configs/baseConfig.tsx +66 -0
  43. package/src/configs/candleStickChartConfig.tsx +35 -0
  44. package/src/configs/cartesianAxisConfig.tsx +314 -0
  45. package/src/configs/chartUrls.tsx +9 -0
  46. package/src/configs/echartConfig.tsx +260 -0
  47. package/src/configs/echartsLabelConfig.tsx +47 -0
  48. package/src/configs/echartsLegendConfig.tsx +29 -0
  49. package/src/configs/echartsTitleConfig.tsx +49 -0
  50. package/src/configs/echartsTitleVerticalConfig.tsx +50 -0
  51. package/src/configs/funnelChartConfig.tsx +35 -0
  52. package/src/configs/gaugeChartConfig.tsx +31 -0
  53. package/src/configs/graphChartConfig.tsx +31 -0
  54. package/src/configs/heatmapChartConfig.tsx +31 -0
  55. package/src/configs/legendConfig.tsx +55 -0
  56. package/src/configs/lineChartConfig.tsx +246 -0
  57. package/src/configs/lineChartConfigv2.tsx +246 -0
  58. package/src/configs/mapChartConfig.tsx +106 -0
  59. package/src/configs/mapChartConfigv2.tsx +106 -0
  60. package/src/configs/mixedChartConfig.tsx +21 -0
  61. package/src/configs/pieChartConfig.tsx +156 -0
  62. package/src/configs/radarChartConfig.tsx +31 -0
  63. package/src/configs/sankeyChartConfig.tsx +35 -0
  64. package/src/configs/scatterChartConfig.tsx +152 -0
  65. package/src/configs/sunburstChartConfig.tsx +31 -0
  66. package/src/configs/tabConfig.tsx +0 -0
  67. package/src/configs/tableChartConfig.tsx +81 -0
  68. package/src/configs/themeriverChartConfig.tsx +31 -0
  69. package/src/configs/totalChartConfig.tsx +670 -0
  70. package/src/configs/treeChartConfig.tsx +31 -0
  71. package/src/configs/treemapChartConfig.tsx +31 -0
  72. package/src/controls/AnimationsControls.tsx +3 -0
  73. package/src/controls/AutoHeightControl.tsx +2 -0
  74. package/src/controls/AxisControls.tsx +146 -0
  75. package/src/controls/AxisVisibilityControl.tsx +14 -0
  76. package/src/controls/ChartTypeControl.tsx +15 -0
  77. package/src/controls/ColorScaleControl.tsx +221 -0
  78. package/src/controls/ColumnControl.tsx +204 -0
  79. package/src/controls/ConfigControl.tsx +37 -0
  80. package/src/controls/DirectionControls.tsx +20 -0
  81. package/src/controls/IconControl.tsx +88 -0
  82. package/src/controls/LegendControl.tsx +8 -0
  83. package/src/controls/RowLimitControl.tsx +91 -0
  84. package/src/controls/StyleControls.tsx +22 -0
  85. package/src/controls/TimeControls.tsx +41 -0
  86. package/src/controls/TrendlineControl.tsx +89 -0
  87. package/src/controls/UIEventControl.tsx +21 -0
  88. package/src/controls/index.ts +16 -0
  89. package/src/controls/radioControl.tsx +88 -0
  90. package/src/exposing/index.ts +3 -0
  91. package/src/exposing/setPoint.ts +19 -0
  92. package/src/geo/vn.geo.json +369897 -0
  93. package/src/geo/world.geo.json +32127 -0
  94. package/src/i18n/comps/index.tsx +39 -0
  95. package/src/i18n/comps/locales/en.ts +558 -0
  96. package/src/i18n/comps/locales/enObj.tsx +7186 -0
  97. package/src/i18n/comps/locales/index.ts +7 -0
  98. package/src/i18n/comps/locales/pt.ts +37 -0
  99. package/src/i18n/comps/locales/ptObj.tsx +40 -0
  100. package/src/i18n/comps/locales/types.tsx +622 -0
  101. package/src/i18n/comps/locales/zh.ts +3 -0
  102. package/src/i18n/comps/locales/zhObj.tsx +4 -0
  103. package/src/index.ts +31 -0
  104. package/src/types/global.d.ts +9 -0
  105. package/src/types/lowcoder-sdk.d.ts +578 -0
  106. package/src/utils/chartStyle.util.ts +121 -0
  107. package/src/utils/columnExtractor.util.ts +41 -0
  108. package/src/utils/dataTransform.util.ts +37 -0
  109. package/src/utils/deepEqual.util.ts +29 -0
  110. package/src/utils/echarts.util.tsx +822 -0
  111. package/src/utils/getDataKey.util.ts +115 -0
  112. package/src/utils/getLinearRegression.util.ts +46 -0
  113. package/src/utils/googleMaps.util.ts +28 -0
  114. package/src/utils/isEmpty.util.ts +10 -0
  115. package/src/utils/move.util.ts +6 -0
  116. package/src/utils/selection.util.ts +73 -0
  117. package/src/utils/style.util.ts +315 -0
  118. package/src/utils/time.util.ts +221 -0
  119. package/src/utils/timeFormatter.util.ts +104 -0
  120. package/src/utils/timeProcessing.util.ts +38 -0
  121. package/src/utils/trendline.util.ts +342 -0
  122. package/tsconfig.json +25 -0
  123. package/vite.config.js +19 -0
@@ -0,0 +1,350 @@
1
+ import { ChartPropertyView } from "@/components/ChartPropertyView";
2
+ import { EchartsAxisType } from "@/configs/cartesianAxisConfig";
3
+ import { eChartConfigOmitChildren } from "@/configs/echartConfig";
4
+ import { ItemColorComp } from "@/configs/lineChartConfig";
5
+ import { AxisFormatterComp } from "@/controls";
6
+ import { getEchartsLocale, trans } from "@/i18n/comps";
7
+ import { formatAllStyles } from "@/utils/chartStyle.util";
8
+ import { deepEqual } from "@/utils/deepEqual.util";
9
+ import { ChartSize, echartProps, getEChartConfig } from "@/utils/echarts.util";
10
+ import { getDataKeys } from "@/utils/getDataKey.util";
11
+ import { getSelectedPoints } from "@/utils/selection.util";
12
+ import ReactECharts from "echarts-for-react";
13
+ import EChartsReactCore from "echarts-for-react/lib/core";
14
+ import {
15
+ changeChildAction,
16
+ changeValueAction,
17
+ chartColorPalette,
18
+ childrenToProps,
19
+ CompAction,
20
+ CompActionTypes,
21
+ depsConfig,
22
+ genRandomKey,
23
+ getPromiseAfterDispatch,
24
+ JSONObject,
25
+ NameConfig,
26
+ Theme,
27
+ ThemeContext,
28
+ UICompBuilder,
29
+ valueComp,
30
+ withDefault,
31
+ withExposingConfigs,
32
+ withViewFn,
33
+ wrapChildAction,
34
+ } from "lowcoder-sdk";
35
+ import { useContext, useEffect, useMemo, useRef, useState } from "react";
36
+ import { useResizeDetector } from "react-resize-detector";
37
+ import { chartUiProps } from "./constants";
38
+
39
+ let clickEventCallback = () => {};
40
+
41
+ let LineChartTmpComp = (function () {
42
+ return new UICompBuilder(
43
+ {
44
+ ...echartProps,
45
+ ...chartUiProps,
46
+ },
47
+ () => null
48
+ )
49
+ .setPropertyViewFn(ChartPropertyView)
50
+ .build();
51
+ })();
52
+
53
+ LineChartTmpComp = withViewFn(LineChartTmpComp, (comp) => {
54
+ const onUIEvent = comp.children.onUIEvent.getView();
55
+ const onEvent = comp.children.onEvent.getView();
56
+ const eChartCompRef = useRef<EChartsReactCore | null>();
57
+ const containerRef = useRef<HTMLDivElement>(null);
58
+ const [chartSize, setChartSize] = useState<ChartSize>();
59
+ const firstResize = useRef(true);
60
+ const theme: Theme = useContext(ThemeContext);
61
+
62
+ const defaultChartTheme = {
63
+ color: chartColorPalette,
64
+ backgroundColor: "#fff",
65
+ };
66
+
67
+ let themeConfig = defaultChartTheme;
68
+ try {
69
+ themeConfig = theme?.theme?.chart
70
+ ? JSON.parse(theme.theme.chart)
71
+ : defaultChartTheme;
72
+ } catch (error) {
73
+ console.error("theme chart error: ", error);
74
+ }
75
+
76
+ const triggerClickEvent = async (dispatch: any, action: CompAction) => {
77
+ await getPromiseAfterDispatch(dispatch, action, {
78
+ autoHandleAfterReduce: true,
79
+ });
80
+ onEvent("click");
81
+ };
82
+
83
+ useEffect(() => {
84
+ const eChartCompInstance = eChartCompRef?.current?.getEchartsInstance();
85
+ if (!eChartCompInstance) {
86
+ return undefined;
87
+ }
88
+ eChartCompInstance?.on("click", (param: any) => {
89
+ document.dispatchEvent(
90
+ new CustomEvent("clickEvent", {
91
+ bubbles: true,
92
+ detail: {
93
+ action: "click",
94
+ data: param.data,
95
+ },
96
+ })
97
+ );
98
+ triggerClickEvent(
99
+ comp.dispatch,
100
+ changeChildAction("lastInteractionData", param.data, false)
101
+ );
102
+ });
103
+ return () => {
104
+ eChartCompInstance?.off("click");
105
+ document.removeEventListener("clickEvent", clickEventCallback);
106
+ };
107
+ }, []);
108
+
109
+ useEffect(() => {
110
+ // bind events
111
+ const eChartCompInstance = eChartCompRef?.current?.getEchartsInstance();
112
+ if (!eChartCompInstance) {
113
+ return;
114
+ }
115
+ eChartCompInstance?.on("selectchanged", (param: any) => {
116
+ const option: any = eChartCompInstance?.getOption();
117
+ document.dispatchEvent(
118
+ new CustomEvent("clickEvent", {
119
+ bubbles: true,
120
+ detail: {
121
+ action: param.fromAction,
122
+ data: getSelectedPoints(param, option),
123
+ },
124
+ })
125
+ );
126
+
127
+ if (param.fromAction === "select") {
128
+ comp.dispatch(
129
+ changeChildAction(
130
+ "selectedPoints",
131
+ getSelectedPoints(param, option),
132
+ false
133
+ )
134
+ );
135
+ onUIEvent("select");
136
+ } else if (param.fromAction === "unselect") {
137
+ comp.dispatch(
138
+ changeChildAction(
139
+ "selectedPoints",
140
+ getSelectedPoints(param, option),
141
+ false
142
+ )
143
+ );
144
+ onUIEvent("unselect");
145
+ }
146
+
147
+ triggerClickEvent(
148
+ comp.dispatch,
149
+ changeChildAction(
150
+ "lastInteractionData",
151
+ getSelectedPoints(param, option),
152
+ false
153
+ )
154
+ );
155
+ });
156
+ // unbind
157
+ return () => {
158
+ eChartCompInstance?.off("selectchanged");
159
+ document.removeEventListener("clickEvent", clickEventCallback);
160
+ };
161
+ }, [onUIEvent]);
162
+
163
+ const eChartConfigChildren: any = {};
164
+ for (const [key, value] of Object.entries(comp.children)) {
165
+ if (!eChartConfigOmitChildren.includes(key as any)) {
166
+ eChartConfigChildren[key] = value;
167
+ }
168
+ }
169
+
170
+ const childrenProps = formatAllStyles(childrenToProps(comp.children));
171
+
172
+ const option = useMemo(() => {
173
+ return getEChartConfig(childrenProps, chartSize, themeConfig);
174
+ }, [themeConfig, childrenProps, chartSize]);
175
+
176
+ useResizeDetector({
177
+ targetRef: containerRef,
178
+ onResize: ({ width, height }) => {
179
+ if (width && height) {
180
+ setChartSize({ w: width, h: height });
181
+ }
182
+ if (!firstResize.current) {
183
+ // ignore the first resize, which will impact the loading animation
184
+ eChartCompRef.current?.getEchartsInstance().resize();
185
+ } else {
186
+ firstResize.current = false;
187
+ }
188
+ },
189
+ });
190
+
191
+ return (
192
+ <div ref={containerRef} style={{ height: "100%" }}>
193
+ <ReactECharts
194
+ ref={(e) => (eChartCompRef.current = e)}
195
+ style={{ height: "100%" }}
196
+ notMerge
197
+ lazyUpdate
198
+ opts={{ locale: getEchartsLocale() }}
199
+ option={option}
200
+ />
201
+ </div>
202
+ );
203
+ });
204
+
205
+ function getYAxisFormatContextValue(
206
+ data: Array<JSONObject>,
207
+ yAxisType: EchartsAxisType,
208
+ yAxisName?: string
209
+ ) {
210
+ const dataSample = yAxisName && data.length > 0 && data[0][yAxisName];
211
+ let contextValue = dataSample;
212
+
213
+ if (yAxisType === "time") {
214
+ // to timestamp
215
+ const time =
216
+ typeof dataSample === "number" || typeof dataSample === "string"
217
+ ? new Date(dataSample).getTime()
218
+ : null;
219
+ if (time) contextValue = time;
220
+ }
221
+ return contextValue;
222
+ }
223
+
224
+ LineChartTmpComp = class extends LineChartTmpComp {
225
+ updateContext(comp: any) {
226
+ // the context value of axis format
227
+ let resultComp = comp;
228
+ const data = comp.children.data.getView();
229
+ const sampleSeries = comp.children.series
230
+ .getView()
231
+ .find((s: any) => !s.getView().hide);
232
+ const yAxisContextValue = getYAxisFormatContextValue(
233
+ data,
234
+ comp.children.yConfig.children.yAxisType.getView(),
235
+ sampleSeries?.children.columnName.getView()
236
+ );
237
+ if (yAxisContextValue !== comp.lastYAxisFormatContextVal) {
238
+ comp.lastYAxisFormatContextVal = yAxisContextValue;
239
+ resultComp = comp.setChild(
240
+ "yConfig",
241
+ comp.children.yConfig.reduce(
242
+ wrapChildAction(
243
+ "formatter",
244
+ AxisFormatterComp.changeContextDataAction({
245
+ value: yAxisContextValue,
246
+ })
247
+ )
248
+ )
249
+ );
250
+ }
251
+ // item color context
252
+ const colorContextVal = {
253
+ seriesName: sampleSeries?.children.seriesName.getView(),
254
+ value: yAxisContextValue,
255
+ };
256
+ if (
257
+ comp.children.chartConfig.children.comp.children.hasOwnProperty(
258
+ "itemColor"
259
+ ) &&
260
+ !deepEqual(colorContextVal, comp.lastColorContext)
261
+ ) {
262
+ comp.lastColorContext = colorContextVal;
263
+ resultComp = resultComp.setChild(
264
+ "chartConfig",
265
+ comp.children.chartConfig.reduce(
266
+ wrapChildAction(
267
+ "comp",
268
+ wrapChildAction(
269
+ "itemColor",
270
+ ItemColorComp.changeContextDataAction(colorContextVal)
271
+ )
272
+ )
273
+ )
274
+ );
275
+ }
276
+ return resultComp;
277
+ }
278
+
279
+ reduce(action: CompAction): this {
280
+ const comp = super.reduce(action);
281
+ if (action.type === CompActionTypes.UPDATE_NODES_V2) {
282
+ const newData = comp.children.data.getView();
283
+ // data changes
284
+ if (comp.children.data !== this.children.data) {
285
+ setTimeout(() => {
286
+ // update x-axis value
287
+ const keys = getDataKeys({ data: newData, dataType: "string" });
288
+ if (
289
+ keys.length > 0 &&
290
+ !keys.includes(comp.children.xAxisKey.getView())
291
+ ) {
292
+ comp.children.xAxisKey.dispatch(changeValueAction(keys[0] || ""));
293
+ }
294
+ // pass to child series comp
295
+ comp.children.series.dispatchDataChanged(newData);
296
+ }, 0);
297
+ }
298
+ return this.updateContext(comp);
299
+ }
300
+ return comp;
301
+ }
302
+
303
+ autoHeight(): boolean {
304
+ return false;
305
+ }
306
+ };
307
+
308
+ let LineChartComp = withExposingConfigs(LineChartTmpComp, [
309
+ depsConfig({
310
+ name: "selectedPoints",
311
+ desc: trans("chart.selectedPointsDesc"),
312
+ depKeys: ["selectedPoints"],
313
+ func: (input) => {
314
+ return input.selectedPoints;
315
+ },
316
+ }),
317
+ depsConfig({
318
+ name: "lastInteractionData",
319
+ desc: trans("chart.lastInteractionDataDesc"),
320
+ depKeys: ["lastInteractionData"],
321
+ func: (input) => {
322
+ return input.lastInteractionData;
323
+ },
324
+ }),
325
+ depsConfig({
326
+ name: "data",
327
+ desc: trans("chart.dataDesc"),
328
+ depKeys: ["data", "mode"],
329
+ func: (input) => [],
330
+ }),
331
+ new NameConfig("title", trans("chart.titleDesc")),
332
+ ]);
333
+
334
+ export const LineChartCompWithDefault = withDefault(LineChartComp, {
335
+ xAxisKey: valueComp<string>("date"),
336
+ series: [
337
+ {
338
+ dataIndex: genRandomKey(),
339
+ seriesName: "Sales",
340
+ columnName: "sales",
341
+ chartType: "line",
342
+ },
343
+ {
344
+ dataIndex: genRandomKey(),
345
+ seriesName: "Growth",
346
+ columnName: "growth",
347
+ chartType: "line",
348
+ },
349
+ ],
350
+ });
@@ -0,0 +1,53 @@
1
+ import { createSeriesListComp } from "@/components/SeriesComp";
2
+ import { ChartOptionMap } from "@/controls";
3
+ import { trans } from "@/i18n/comps";
4
+ import {
5
+ EchartDefaultTextStyle,
6
+ jsonControl,
7
+ RecordConstructorToView,
8
+ StringControl,
9
+ styleControl,
10
+ toJSONObjectArray,
11
+ uiChildren,
12
+ withDefault,
13
+ withType,
14
+ } from "lowcoder-sdk";
15
+
16
+ const defaultChartData = [
17
+ { date: "25-01-2025", sales: 320, growth: 250 },
18
+ { date: "30-03-2025", sales: 450, growth: 300 },
19
+ { date: "12-05-2025", sales: 380, growth: 340 },
20
+ { date: "07-07-2025", sales: 520, growth: 400 },
21
+ { date: "09-08-2025", sales: 480, growth: 450 },
22
+ { date: "10-09-2025", sales: 600, growth: 500 },
23
+ ];
24
+
25
+ export const chartUiProps = {
26
+ chartConfig: withType(ChartOptionMap, "line"),
27
+ chartType: withDefault(StringControl, "line"),
28
+ title: withDefault(StringControl, trans("lineChart.defaultTitle")),
29
+ defaultData: jsonControl(toJSONObjectArray, defaultChartData),
30
+ series: createSeriesListComp("line"),
31
+ xAxisStyle: styleControl(EchartDefaultTextStyle, "xAxis"),
32
+ yAxisStyle: styleControl(EchartDefaultTextStyle, "yAxisStyle"),
33
+ };
34
+
35
+ const chartUiChildrenMap = uiChildren(chartUiProps);
36
+ export type ChartUiPropsType = RecordConstructorToView<
37
+ typeof chartUiChildrenMap
38
+ >;
39
+
40
+ export type UIChartDataType = {
41
+ seriesName: string;
42
+ // coordinate chart
43
+ x?: any;
44
+ y?: any;
45
+ // pie or funnel
46
+ itemName?: any;
47
+ value?: any;
48
+ };
49
+
50
+ export type NonUIChartDataType = {
51
+ name: string;
52
+ value: any;
53
+ };