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,334 @@
1
+ import { ChartPropertyView } from "@/components/ChartPropertyView";
2
+ import { EchartsAxisType } from "@/configs/cartesianAxisConfig";
3
+ import { eChartConfigOmitChildren } from "@/configs/echartConfig";
4
+ import { AxisFormatterComp } from "@/controls";
5
+ import { getEchartsLocale, trans } from "@/i18n/comps";
6
+ import { formatAllStyles } from "@/utils/chartStyle.util";
7
+ import { deepEqual } from "@/utils/deepEqual.util";
8
+ import { ChartSize, echartProps, getEChartConfig } from "@/utils/echarts.util";
9
+ import { getDataKeys } from "@/utils/getDataKey.util";
10
+ import { getSelectedPoints } from "@/utils/selection.util";
11
+ import ReactECharts from "echarts-for-react";
12
+ import EChartsReactCore from "echarts-for-react/lib/core";
13
+ import {
14
+ changeChildAction,
15
+ changeValueAction,
16
+ chartColorPalette,
17
+ childrenToProps,
18
+ CompAction,
19
+ CompActionTypes,
20
+ depsConfig,
21
+ genRandomKey,
22
+ getPromiseAfterDispatch,
23
+ JSONObject,
24
+ NameConfig,
25
+ Theme,
26
+ ThemeContext,
27
+ UICompBuilder,
28
+ valueComp,
29
+ withDefault,
30
+ withExposingConfigs,
31
+ withViewFn,
32
+ wrapChildAction,
33
+ } from "lowcoder-sdk";
34
+ import { useContext, useEffect, useMemo, useRef, useState } from "react";
35
+ import { useResizeDetector } from "react-resize-detector";
36
+ import { chartUiProps } from "./constants";
37
+
38
+ let clickEventCallback = () => {};
39
+
40
+ let PiechartsTmpComp = (function () {
41
+ return new UICompBuilder(
42
+ {
43
+ ...echartProps,
44
+ ...chartUiProps,
45
+ },
46
+ () => null
47
+ )
48
+ .setPropertyViewFn(ChartPropertyView)
49
+ .build();
50
+ })();
51
+
52
+ PiechartsTmpComp = withViewFn(PiechartsTmpComp, (comp) => {
53
+ const onUIEvent = comp.children.onUIEvent.getView();
54
+ const onEvent = comp.children.onEvent.getView();
55
+ const eChartCompRef = useRef<EChartsReactCore | null>();
56
+ const containerRef = useRef<HTMLDivElement>(null);
57
+ const [chartSize, setChartSize] = useState<ChartSize>();
58
+ const firstResize = useRef(true);
59
+ const theme: Theme = useContext(ThemeContext);
60
+
61
+ const defaultChartTheme = {
62
+ color: chartColorPalette,
63
+ backgroundColor: "#fff",
64
+ };
65
+
66
+ let themeConfig = defaultChartTheme;
67
+ try {
68
+ themeConfig = theme?.theme?.chart
69
+ ? JSON.parse(theme.theme.chart)
70
+ : defaultChartTheme;
71
+ } catch (error) {
72
+ console.error("theme chart error: ", error);
73
+ }
74
+
75
+ const triggerClickEvent = async (dispatch: any, action: CompAction) => {
76
+ await getPromiseAfterDispatch(dispatch, action, {
77
+ autoHandleAfterReduce: true,
78
+ });
79
+ onEvent("click");
80
+ };
81
+
82
+ useEffect(() => {
83
+ const eChartCompInstance = eChartCompRef?.current?.getEchartsInstance();
84
+ if (!eChartCompInstance) {
85
+ return undefined;
86
+ }
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
+ console.log({ option });
176
+
177
+ useResizeDetector({
178
+ targetRef: containerRef,
179
+ onResize: ({ width, height }) => {
180
+ if (width && height) {
181
+ setChartSize({ w: width, h: height });
182
+ }
183
+ if (!firstResize.current) {
184
+ // ignore the first resize, which will impact the loading animation
185
+ eChartCompRef.current?.getEchartsInstance().resize();
186
+ } else {
187
+ firstResize.current = false;
188
+ }
189
+ },
190
+ });
191
+
192
+ return (
193
+ <div ref={containerRef} style={{ height: "100%" }}>
194
+ <ReactECharts
195
+ ref={(e) => (eChartCompRef.current = e)}
196
+ style={{ height: "100%" }}
197
+ notMerge
198
+ lazyUpdate
199
+ opts={{ locale: getEchartsLocale() }}
200
+ option={option}
201
+ />
202
+ </div>
203
+ );
204
+ });
205
+
206
+ function getYAxisFormatContextValue(
207
+ data: Array<JSONObject>,
208
+ yAxisType: EchartsAxisType,
209
+ yAxisName?: string
210
+ ) {
211
+ const dataSample = yAxisName && data.length > 0 && data[0][yAxisName];
212
+ let contextValue = dataSample;
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
+ PiechartsTmpComp = class extends PiechartsTmpComp {
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
+ }
264
+ return resultComp;
265
+ }
266
+
267
+ reduce(action: CompAction): this {
268
+ const comp = super.reduce(action);
269
+
270
+ if (action.type === CompActionTypes.UPDATE_NODES_V2) {
271
+ const newData = comp.children.data.getView();
272
+
273
+ // data changes
274
+ if (comp.children.data !== this.children.data) {
275
+ setTimeout(() => {
276
+ // update x-axis value
277
+ const keys = getDataKeys({ data: newData, dataType: "string" });
278
+
279
+ if (
280
+ keys.length > 0 &&
281
+ !keys.includes(comp.children.xAxisKey.getView())
282
+ ) {
283
+ comp.children.xAxisKey.dispatch(changeValueAction(keys[0] || ""));
284
+ }
285
+ // pass to child series comp
286
+ comp.children.series.dispatchDataChanged(newData);
287
+ }, 0);
288
+ }
289
+ return this.updateContext(comp);
290
+ }
291
+ return comp;
292
+ }
293
+
294
+ autoHeight(): boolean {
295
+ return false;
296
+ }
297
+ };
298
+
299
+ let PieChartComp = withExposingConfigs(PiechartsTmpComp, [
300
+ depsConfig({
301
+ name: "selectedPoints",
302
+ desc: trans("chart.selectedPointsDesc"),
303
+ depKeys: ["selectedPoints"],
304
+ func: (input) => {
305
+ return input.selectedPoints;
306
+ },
307
+ }),
308
+ depsConfig({
309
+ name: "lastInteractionData",
310
+ desc: trans("chart.lastInteractionDataDesc"),
311
+ depKeys: ["lastInteractionData"],
312
+ func: (input) => {
313
+ return input.lastInteractionData;
314
+ },
315
+ }),
316
+ depsConfig({
317
+ name: "data",
318
+ desc: trans("chart.dataDesc"),
319
+ depKeys: ["data", "mode"],
320
+ func: (input) => [],
321
+ }),
322
+ new NameConfig("title", trans("chart.titleDesc")),
323
+ ]);
324
+
325
+ export const PieChartCompWithDefault = withDefault(PieChartComp, {
326
+ xAxisKey: valueComp<string>("value"),
327
+ series: [
328
+ {
329
+ dataIndex: genRandomKey(),
330
+ name: "Name",
331
+ chartType: "pie",
332
+ },
333
+ ],
334
+ });
@@ -0,0 +1,48 @@
1
+ import { createSeriesListComp } from "@/components/SeriesComp";
2
+ import { ChartOptionMap } from "@/controls";
3
+ import { trans } from "@/i18n/comps";
4
+ import {
5
+ jsonControl,
6
+ RecordConstructorToView,
7
+ StringControl,
8
+ toJSONObjectArray,
9
+ uiChildren,
10
+ withDefault,
11
+ withType,
12
+ } from "lowcoder-sdk";
13
+
14
+ const defaultChartData = [
15
+ { value: 1048, name: "Search Engine" },
16
+ { value: 735, name: "Direct" },
17
+ { value: 580, name: "Email" },
18
+ { value: 484, name: "Union Ads" },
19
+ { value: 300, name: "Video Ads" },
20
+ ];
21
+
22
+ export const chartUiProps = {
23
+ chartConfig: withType(ChartOptionMap, "pie"),
24
+ chartType: withDefault(StringControl, "pie"),
25
+ title: withDefault(StringControl, trans("pieChart.defaultTitle")),
26
+ defaultData: jsonControl(toJSONObjectArray, defaultChartData),
27
+ series: createSeriesListComp("pie"),
28
+ };
29
+
30
+ const chartUiChildrenMap = uiChildren(chartUiProps);
31
+ export type ChartUiPropsType = RecordConstructorToView<
32
+ typeof chartUiChildrenMap
33
+ >;
34
+
35
+ export type UIChartDataType = {
36
+ seriesName: string;
37
+ // coordinate chart
38
+ x?: any;
39
+ y?: any;
40
+ // pie or funnel
41
+ itemName?: any;
42
+ value?: any;
43
+ };
44
+
45
+ export type NonUIChartDataType = {
46
+ name: string;
47
+ value: any;
48
+ };