lowcoder-comps 0.0.29 → 0.0.31
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 +120 -0
- package/index.html +26 -0
- package/index.tsx +21 -0
- package/jest.config.js +6 -0
- package/package.json +3 -4
- package/src/__test__/allComp.test.tsx +61 -0
- package/src/app-env.d.ts +3 -0
- package/src/comps/calendarComp/calendarComp.tsx +633 -0
- package/src/comps/calendarComp/calendarConstants.tsx +1048 -0
- package/src/comps/calendarComp/errorBoundary.tsx +30 -0
- package/src/comps/chartComp/chartComp.tsx +442 -0
- package/src/comps/chartComp/chartConfigs/barChartConfig.tsx +51 -0
- package/src/comps/chartComp/chartConfigs/cartesianAxisConfig.tsx +307 -0
- package/src/comps/chartComp/chartConfigs/chartUrls.tsx +9 -0
- package/src/comps/chartComp/chartConfigs/legendConfig.tsx +55 -0
- package/src/comps/chartComp/chartConfigs/lineChartConfig.tsx +96 -0
- package/src/comps/chartComp/chartConfigs/pieChartConfig.tsx +83 -0
- package/src/comps/chartComp/chartConfigs/scatterChartConfig.tsx +62 -0
- package/src/comps/chartComp/chartConstants.tsx +299 -0
- package/src/comps/chartComp/chartPropertyView.tsx +235 -0
- package/src/comps/chartComp/chartUtils.ts +291 -0
- package/src/comps/chartComp/reactEcharts/core.tsx +194 -0
- package/src/comps/chartComp/reactEcharts/index.ts +21 -0
- package/src/comps/chartComp/reactEcharts/types.ts +76 -0
- package/src/comps/chartComp/seriesComp.tsx +119 -0
- package/src/comps/imageEditorComp/imageEditorClass.tsx +52 -0
- package/src/comps/imageEditorComp/imageEditorConstants.tsx +109 -0
- package/src/comps/imageEditorComp/index.tsx +184 -0
- package/src/comps/mermaidComp/index.tsx +44 -0
- package/src/comps/mermaidComp/mermaid.tsx +29 -0
- package/src/global.ts +1 -0
- package/src/i18n/comps/index.tsx +29 -0
- package/src/i18n/comps/locales/en.ts +163 -0
- package/src/i18n/comps/locales/enObj.tsx +198 -0
- package/src/i18n/comps/locales/index.ts +7 -0
- package/src/i18n/comps/locales/types.tsx +10 -0
- package/src/i18n/comps/locales/zh.ts +156 -0
- package/src/i18n/comps/locales/zhObj.tsx +4 -0
- package/src/index.ts +11 -0
- package/tsconfig.json +22 -0
- package/vite.config.js +10 -0
- package/2085da13.js +0 -960
- package/250691b5.js +0 -5
- package/256b619e.js +0 -92
- package/274f545c.js +0 -881
- package/289305a1.js +0 -208
- package/2eae45c2.js +0 -34
- package/2ff2c7a6.js +0 -6
- package/2ff7471d.js +0 -9
- package/335b22a2.js +0 -220
- package/38c826fe.js +0 -1127
- package/44011c1d.js +0 -818
- package/4fc06812.js +0 -64
- package/56a787cf.js +0 -915
- package/590941ff.js +0 -86
- package/6341867f.js +0 -804
- package/657fd065.js +0 -8
- package/78a5e50d.js +0 -1579
- package/820c3641.js +0 -25
- package/88b4e75a.js +0 -2967
- package/8d999722.js +0 -1102
- package/92e85b65.js +0 -65
- package/989caea2.js +0 -505
- package/99b984d1.js +0 -237
- package/9e5f02d6.js +0 -19104
- package/a40faea7.js +0 -11624
- package/abac9104.js +0 -1536
- package/af2f19b3.js +0 -819
- package/af5ee3de.js +0 -268
- package/b24707c2.js +0 -48428
- package/b68f8b69.js +0 -1276
- package/ba68ba65.js +0 -391
- package/bafb8599.js +0 -319
- package/bba60c35.js +0 -2501
- package/bd7c2a8e.js +0 -1089
- package/c71dadea.js +0 -455
- package/d05c1762.js +0 -933
- package/d073ab24.js +0 -134353
- package/d838cd10.js +0 -769
- package/dc36a6eb.js +0 -796
- package/ed143450.js +0 -1284
- package/ee8ec8f2.js +0 -2284
- package/f6755210.js +0 -1269
- package/f9637058.js +0 -16
- package/fba4c8e4.js +0 -447
- package/index.js +0 -5
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { XAXisComponentOption, YAXisComponentOption } from "echarts";
|
|
2
|
+
import { ChartSize, XAxisDirectionType } from "../chartConstants";
|
|
3
|
+
import { i18n } from "lowcoder-core";
|
|
4
|
+
import {
|
|
5
|
+
MultiCompBuilder,
|
|
6
|
+
withContext,
|
|
7
|
+
NumberControl,
|
|
8
|
+
StringControl,
|
|
9
|
+
dropdownControl,
|
|
10
|
+
JSONValue,
|
|
11
|
+
isNumeric,
|
|
12
|
+
} from "lowcoder-sdk";
|
|
13
|
+
import { i18nObjs, trans } from "i18n/comps";
|
|
14
|
+
import _, { isNil } from "lodash";
|
|
15
|
+
import { xAxisTypeUrl } from "./chartUrls";
|
|
16
|
+
|
|
17
|
+
const XAxisTypeOptions = [
|
|
18
|
+
{
|
|
19
|
+
label: trans("chart.auto"),
|
|
20
|
+
value: "default",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: trans("chart.categoryAxis"),
|
|
24
|
+
value: "category",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: trans("chart.valueAxis"),
|
|
28
|
+
value: "value",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: trans("chart.timeAxis"),
|
|
32
|
+
value: "time",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: trans("chart.logAxis"),
|
|
36
|
+
value: "log",
|
|
37
|
+
},
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
const YAxisTypeOptions = [
|
|
41
|
+
{
|
|
42
|
+
label: trans("chart.valueAxis"),
|
|
43
|
+
value: "value",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: trans("chart.categoryAxis"),
|
|
47
|
+
value: "category",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: trans("chart.timeAxis"),
|
|
51
|
+
value: "time",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: trans("chart.logAxis"),
|
|
55
|
+
value: "log",
|
|
56
|
+
},
|
|
57
|
+
] as const;
|
|
58
|
+
|
|
59
|
+
export type EchartsAxisType = "category" | "value" | "time" | "log";
|
|
60
|
+
|
|
61
|
+
const axisCommonMap = {
|
|
62
|
+
axisName: StringControl,
|
|
63
|
+
logBase: NumberControl,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const AxisFormatterComp = withContext(
|
|
67
|
+
new MultiCompBuilder({ value: StringControl }, (props) => props.value)
|
|
68
|
+
.setPropertyViewFn((children) =>
|
|
69
|
+
children.value.propertyView({
|
|
70
|
+
label: trans("chart.yAxisDataFormat"),
|
|
71
|
+
placeholder: "{{value}}",
|
|
72
|
+
tooltip: trans("chart.yAxisDataFormatTooltip"),
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
.build(),
|
|
76
|
+
["value"] as const
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export const XAxisConfig = (function () {
|
|
80
|
+
return new MultiCompBuilder(
|
|
81
|
+
{
|
|
82
|
+
...axisCommonMap,
|
|
83
|
+
type: dropdownControl(XAxisTypeOptions, "default"),
|
|
84
|
+
},
|
|
85
|
+
(props): XAXisComponentOption => {
|
|
86
|
+
const config: XAXisComponentOption = {
|
|
87
|
+
name: props.axisName,
|
|
88
|
+
nameGap: 22,
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
nameLocation: "middle",
|
|
91
|
+
};
|
|
92
|
+
if (props.type !== "default") {
|
|
93
|
+
// don't assign value for default value, compute it in the end
|
|
94
|
+
config.type = props.type;
|
|
95
|
+
}
|
|
96
|
+
return config;
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
.setPropertyViewFn((children) => (
|
|
100
|
+
<>
|
|
101
|
+
{children.axisName.propertyView({
|
|
102
|
+
label: trans("chart.xAxisName"),
|
|
103
|
+
})}
|
|
104
|
+
{children.type.propertyView({
|
|
105
|
+
label: trans("chart.xAxisType"),
|
|
106
|
+
tooltip: (
|
|
107
|
+
<>
|
|
108
|
+
{trans("chart.xAxisTypeTooltip")}
|
|
109
|
+
<a href={xAxisTypeUrl} target="_blank" rel="noreferrer">
|
|
110
|
+
{trans("chart.xAxisType")}
|
|
111
|
+
</a>
|
|
112
|
+
</>
|
|
113
|
+
),
|
|
114
|
+
})}
|
|
115
|
+
{children.type.getView() === "log" &&
|
|
116
|
+
children.logBase.propertyView({
|
|
117
|
+
label: trans("chart.logBase"),
|
|
118
|
+
})}
|
|
119
|
+
</>
|
|
120
|
+
))
|
|
121
|
+
.build();
|
|
122
|
+
})();
|
|
123
|
+
|
|
124
|
+
export const YAxisConfig = (function () {
|
|
125
|
+
return new MultiCompBuilder(
|
|
126
|
+
{
|
|
127
|
+
...axisCommonMap,
|
|
128
|
+
// the old data has "type" field with default value "category". change field name to "yAxisType" for compatibility
|
|
129
|
+
yAxisType: dropdownControl(YAxisTypeOptions, "value"),
|
|
130
|
+
formatter: AxisFormatterComp,
|
|
131
|
+
},
|
|
132
|
+
(props) => () => {
|
|
133
|
+
const config: YAXisComponentOption = {
|
|
134
|
+
name: props.axisName,
|
|
135
|
+
type: props.yAxisType,
|
|
136
|
+
nameTextStyle: {
|
|
137
|
+
align: "left",
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const numberFormat = new Intl.NumberFormat(i18n.locales, {
|
|
141
|
+
notation: "compact",
|
|
142
|
+
});
|
|
143
|
+
(config.axisLabel as any) = {
|
|
144
|
+
formatter: (value: string | number) => {
|
|
145
|
+
const res = (props.formatter as any)({ value: value });
|
|
146
|
+
if (!isNil(res) && res !== "") {
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
149
|
+
if (
|
|
150
|
+
(props.yAxisType === "value" || props.yAxisType === "log") &&
|
|
151
|
+
typeof value === "number"
|
|
152
|
+
) {
|
|
153
|
+
return numberFormat.format(value);
|
|
154
|
+
}
|
|
155
|
+
return value + "";
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
if (props.yAxisType === "log") {
|
|
159
|
+
(config as any).logBase = props.logBase || 10;
|
|
160
|
+
}
|
|
161
|
+
return config;
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
.setPropertyViewFn((children) => (
|
|
165
|
+
<>
|
|
166
|
+
{children.axisName.propertyView({
|
|
167
|
+
label: trans("chart.yAxisName"),
|
|
168
|
+
})}
|
|
169
|
+
{children.yAxisType.propertyView({
|
|
170
|
+
label: trans("chart.yAxisType"),
|
|
171
|
+
})}
|
|
172
|
+
{children.yAxisType.getView() === "log" &&
|
|
173
|
+
children.logBase.propertyView({
|
|
174
|
+
label: trans("chart.logBase"),
|
|
175
|
+
})}
|
|
176
|
+
{children.formatter.getPropertyView()}
|
|
177
|
+
</>
|
|
178
|
+
))
|
|
179
|
+
.build();
|
|
180
|
+
})();
|
|
181
|
+
|
|
182
|
+
function calcXAxisType(xAxisData: Array<JSONValue | undefined>): EchartsAxisType {
|
|
183
|
+
if (!xAxisData || xAxisData.length <= 0) {
|
|
184
|
+
return "category";
|
|
185
|
+
}
|
|
186
|
+
const sampleData = xAxisData[0];
|
|
187
|
+
if (!sampleData) {
|
|
188
|
+
return "category";
|
|
189
|
+
}
|
|
190
|
+
if (isNumeric(sampleData)) {
|
|
191
|
+
return "value";
|
|
192
|
+
} else if (!isNaN(new Date(sampleData.toString()).getDate())) {
|
|
193
|
+
return "time";
|
|
194
|
+
} else {
|
|
195
|
+
return "category";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const dateInterval = {
|
|
200
|
+
year: 3600 * 24 * 1000 * 365,
|
|
201
|
+
month: 3600 * 24 * 1000 * 28,
|
|
202
|
+
day: 3600 * 24 * 1000,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
function calcTimeInterval(xAxisData: Array<JSONValue | undefined>) {
|
|
206
|
+
const minIntervals = xAxisData.map((data) => {
|
|
207
|
+
if (!data) {
|
|
208
|
+
// 1 is echarts default value, to make sure axis tick is integer
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
const dataLen = data.toString().length;
|
|
212
|
+
if (dataLen === 4) {
|
|
213
|
+
// year 2022
|
|
214
|
+
return dateInterval.year;
|
|
215
|
+
} else if (dataLen === 6 || dataLen === 7) {
|
|
216
|
+
// month 2022-01 222201
|
|
217
|
+
return dateInterval.month;
|
|
218
|
+
} else if (dataLen === 10 || dataLen === 8) {
|
|
219
|
+
// day 2022-01-01 20220101
|
|
220
|
+
return dateInterval.day;
|
|
221
|
+
} else {
|
|
222
|
+
return 1;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return _.min(minIntervals);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let measureCanvas: HTMLCanvasElement;
|
|
229
|
+
|
|
230
|
+
// calculate x-axis text width
|
|
231
|
+
function getXAxisDataLength(xAxisData: Array<JSONValue | undefined>) {
|
|
232
|
+
const canvas = measureCanvas || (measureCanvas = document.createElement("canvas"));
|
|
233
|
+
const context = canvas.getContext("2d");
|
|
234
|
+
if (!context) {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
// echarts default font
|
|
238
|
+
context.font = "normal 12px sans-serif";
|
|
239
|
+
return xAxisData.map((d) => (d ? context.measureText(d.toString()).width + 2 : 0));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function calcXYConfig(
|
|
243
|
+
xConfig: XAXisComponentOption,
|
|
244
|
+
yConfig: YAXisComponentOption,
|
|
245
|
+
xAxisDirection: XAxisDirectionType,
|
|
246
|
+
xAxisData: Array<JSONValue | undefined>,
|
|
247
|
+
chartSize?: ChartSize & { right: number }
|
|
248
|
+
) {
|
|
249
|
+
const resXConfig = { ...xConfig };
|
|
250
|
+
const resYConfig = { ...yConfig };
|
|
251
|
+
|
|
252
|
+
if (!resXConfig.type) {
|
|
253
|
+
// simple calculate x-axis type
|
|
254
|
+
resXConfig.type = calcXAxisType(xAxisData);
|
|
255
|
+
}
|
|
256
|
+
// x-axis label style adaptive
|
|
257
|
+
if (resXConfig.type === "category" && chartSize) {
|
|
258
|
+
const xAxisDataLenList = getXAxisDataLength(xAxisData);
|
|
259
|
+
// get x-axis single data's max width
|
|
260
|
+
const maxDataWidth = _.max(xAxisDataLenList);
|
|
261
|
+
const lastDataWidth = xAxisDataLenList[xAxisDataLenList.length - 1];
|
|
262
|
+
// grid width
|
|
263
|
+
let eachDataWidth = chartSize.w / xAxisData.length;
|
|
264
|
+
let rotate = 0;
|
|
265
|
+
let labelWidth = maxDataWidth;
|
|
266
|
+
// rotate when width is not enough
|
|
267
|
+
if (maxDataWidth && eachDataWidth < maxDataWidth && xAxisDirection === "horizontal") {
|
|
268
|
+
labelWidth = Math.min(maxDataWidth, 150);
|
|
269
|
+
// vertical rotate 0.87 => sin(60) when exceeding the right boundary
|
|
270
|
+
const verticalRotate =
|
|
271
|
+
lastDataWidth && lastDataWidth * 0.87 > eachDataWidth / 2 + chartSize.right;
|
|
272
|
+
rotate = verticalRotate ? 270 : 330;
|
|
273
|
+
// to keep x-axis name under label, nameGap is related to label rotation angle
|
|
274
|
+
resXConfig.nameGap = verticalRotate ? labelWidth + 5 : labelWidth / 2 + 10;
|
|
275
|
+
} else if (xAxisDirection === "vertical" && maxDataWidth) {
|
|
276
|
+
// vertical direction
|
|
277
|
+
resXConfig.nameGap = maxDataWidth + 10;
|
|
278
|
+
}
|
|
279
|
+
resXConfig.axisLabel = {
|
|
280
|
+
interval: 0,
|
|
281
|
+
width: labelWidth,
|
|
282
|
+
// @ts-ignore
|
|
283
|
+
overflow: "truncate",
|
|
284
|
+
rotate: rotate,
|
|
285
|
+
};
|
|
286
|
+
} else if (resXConfig.type === "time") {
|
|
287
|
+
(resXConfig as any).minInterval = calcTimeInterval(xAxisData);
|
|
288
|
+
const timeXAxisLabel = i18nObjs.timeXAxisLabel;
|
|
289
|
+
if (timeXAxisLabel) {
|
|
290
|
+
resXConfig.axisLabel = timeXAxisLabel;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (xAxisDirection === "vertical") {
|
|
294
|
+
resYConfig.nameLocation = "middle";
|
|
295
|
+
resYConfig.nameGap = 25;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return xAxisDirection === "horizontal"
|
|
299
|
+
? {
|
|
300
|
+
xConfig: resXConfig,
|
|
301
|
+
yConfig: resYConfig,
|
|
302
|
+
}
|
|
303
|
+
: {
|
|
304
|
+
xConfig: resYConfig,
|
|
305
|
+
yConfig: resXConfig,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { language } from "i18n/comps";
|
|
2
|
+
|
|
3
|
+
const echartsUrlLocale = language === "zh" ? "zh" : "en";
|
|
4
|
+
export const optionUrl = `https://echarts.apache.org/${echartsUrlLocale}/option.html`;
|
|
5
|
+
export const examplesUrl = `https://echarts.apache.org/examples/${echartsUrlLocale}/index.html`;
|
|
6
|
+
export const xAxisTypeUrl = `${optionUrl}#xAxis.type`;
|
|
7
|
+
export const googleMapsApiUrl = `https://maps.googleapis.com/maps/api/js`;
|
|
8
|
+
export const mapOptionUrl = `https://github.com/plainheart/echarts-extension-gmap`;
|
|
9
|
+
export const mapExamplesUrl = `https://codepen.io/plainheart/pen/VweLGbR`;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlignBottom,
|
|
3
|
+
AlignClose,
|
|
4
|
+
AlignRight,
|
|
5
|
+
dropdownControl,
|
|
6
|
+
MultiCompBuilder,
|
|
7
|
+
} from "lowcoder-sdk";
|
|
8
|
+
import { LegendComponentOption } from "echarts";
|
|
9
|
+
import { trans } from "i18n/comps";
|
|
10
|
+
|
|
11
|
+
const LegendPositionOptions = [
|
|
12
|
+
{
|
|
13
|
+
label: <AlignBottom />,
|
|
14
|
+
value: "bottom",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: <AlignRight />,
|
|
18
|
+
value: "right",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: <AlignClose />,
|
|
22
|
+
value: "close",
|
|
23
|
+
},
|
|
24
|
+
] as const;
|
|
25
|
+
|
|
26
|
+
export const LegendConfig = (function () {
|
|
27
|
+
return new MultiCompBuilder(
|
|
28
|
+
{
|
|
29
|
+
position: dropdownControl(LegendPositionOptions, "bottom"),
|
|
30
|
+
},
|
|
31
|
+
(props): LegendComponentOption => {
|
|
32
|
+
const config: LegendComponentOption = {
|
|
33
|
+
top: "bottom",
|
|
34
|
+
type: "scroll",
|
|
35
|
+
};
|
|
36
|
+
if (props.position === "right") {
|
|
37
|
+
config.top = "center";
|
|
38
|
+
config.left = "right";
|
|
39
|
+
config.orient = "vertical";
|
|
40
|
+
} else if (props.position === "close") {
|
|
41
|
+
config.show = false;
|
|
42
|
+
}
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
.setPropertyViewFn((children) => (
|
|
47
|
+
<>
|
|
48
|
+
{children.position.propertyView({
|
|
49
|
+
label: trans("chart.legendPosition"),
|
|
50
|
+
radioButton: true,
|
|
51
|
+
})}
|
|
52
|
+
</>
|
|
53
|
+
))
|
|
54
|
+
.build();
|
|
55
|
+
})();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { LineSeriesOption } from "echarts";
|
|
2
|
+
import {
|
|
3
|
+
MultiCompBuilder,
|
|
4
|
+
BoolControl,
|
|
5
|
+
dropdownControl,
|
|
6
|
+
showLabelPropertyView,
|
|
7
|
+
withContext,
|
|
8
|
+
StringControl,
|
|
9
|
+
ColorOrBoolCodeControl,
|
|
10
|
+
} from "lowcoder-sdk";
|
|
11
|
+
import { trans } from "i18n/comps";
|
|
12
|
+
|
|
13
|
+
const BarTypeOptions = [
|
|
14
|
+
{
|
|
15
|
+
label: trans("chart.basicLine"),
|
|
16
|
+
value: "basicLine",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: trans("chart.stackedLine"),
|
|
20
|
+
value: "stackedLine",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: trans("chart.areaLine"),
|
|
24
|
+
value: "areaLine",
|
|
25
|
+
},
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
export const ItemColorComp = withContext(
|
|
29
|
+
new MultiCompBuilder({ value: ColorOrBoolCodeControl }, (props) => props.value)
|
|
30
|
+
.setPropertyViewFn((children) =>
|
|
31
|
+
children.value.propertyView({
|
|
32
|
+
label: trans("chart.pointColorLabel"),
|
|
33
|
+
placeholder: "{{value < 25000}}",
|
|
34
|
+
tooltip: trans("chart.pointColorTooltip"),
|
|
35
|
+
})
|
|
36
|
+
)
|
|
37
|
+
.build(),
|
|
38
|
+
["seriesName", "value"] as const
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const LineChartConfig = (function () {
|
|
42
|
+
return new MultiCompBuilder(
|
|
43
|
+
{
|
|
44
|
+
showLabel: BoolControl,
|
|
45
|
+
type: dropdownControl(BarTypeOptions, "basicLine"),
|
|
46
|
+
smooth: BoolControl,
|
|
47
|
+
itemColor: ItemColorComp,
|
|
48
|
+
},
|
|
49
|
+
(props): LineSeriesOption => {
|
|
50
|
+
const config: LineSeriesOption = {
|
|
51
|
+
type: "line",
|
|
52
|
+
label: {
|
|
53
|
+
show: props.showLabel,
|
|
54
|
+
},
|
|
55
|
+
itemStyle: {
|
|
56
|
+
color: (params) => {
|
|
57
|
+
if (!params.encode || !params.dimensionNames) {
|
|
58
|
+
return params.color;
|
|
59
|
+
}
|
|
60
|
+
const dataKey = params.dimensionNames[params.encode["y"][0]];
|
|
61
|
+
const color = (props.itemColor as any)({
|
|
62
|
+
seriesName: params.seriesName,
|
|
63
|
+
value: (params.data as any)[dataKey],
|
|
64
|
+
});
|
|
65
|
+
if (color === "true") {
|
|
66
|
+
return "red";
|
|
67
|
+
} else if (color === "false" || !color) {
|
|
68
|
+
return params.color;
|
|
69
|
+
}
|
|
70
|
+
return color;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
if (props.type === "stackedLine") {
|
|
75
|
+
config.stack = "stackValue";
|
|
76
|
+
} else if (props.type === "areaLine") {
|
|
77
|
+
config.areaStyle = {};
|
|
78
|
+
}
|
|
79
|
+
if (props.smooth) {
|
|
80
|
+
config.smooth = true;
|
|
81
|
+
}
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
.setPropertyViewFn((children) => (
|
|
86
|
+
<>
|
|
87
|
+
{children.type.propertyView({
|
|
88
|
+
label: trans("chart.lineType"),
|
|
89
|
+
})}
|
|
90
|
+
{showLabelPropertyView(children)}
|
|
91
|
+
{children.smooth.propertyView({ label: trans("chart.smooth") })}
|
|
92
|
+
{children.itemColor.getPropertyView()}
|
|
93
|
+
</>
|
|
94
|
+
))
|
|
95
|
+
.build();
|
|
96
|
+
})();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { MultiCompBuilder } from "lowcoder-sdk";
|
|
2
|
+
import { PieSeriesOption } from "echarts";
|
|
3
|
+
import { dropdownControl } from "lowcoder-sdk";
|
|
4
|
+
import { ConstructorToView } from "lowcoder-core";
|
|
5
|
+
import { trans } from "i18n/comps";
|
|
6
|
+
|
|
7
|
+
const BarTypeOptions = [
|
|
8
|
+
{
|
|
9
|
+
label: trans("chart.basicPie"),
|
|
10
|
+
value: "basicPie",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: trans("chart.doughnutPie"),
|
|
14
|
+
value: "doughnutPie",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: trans("chart.rosePie"),
|
|
18
|
+
value: "rosePie",
|
|
19
|
+
},
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
// radius percent for each pie chart when one line has [1, 2, 3] pie charts
|
|
23
|
+
const pieRadiusConfig = [65, 35, 20];
|
|
24
|
+
|
|
25
|
+
type PieConfigViewType = ConstructorToView<typeof PieChartConfig>;
|
|
26
|
+
|
|
27
|
+
export const PieChartConfig = (function () {
|
|
28
|
+
return new MultiCompBuilder(
|
|
29
|
+
{
|
|
30
|
+
type: dropdownControl(BarTypeOptions, "basicPie"),
|
|
31
|
+
},
|
|
32
|
+
(props): PieSeriesOption => {
|
|
33
|
+
const config: PieSeriesOption = {
|
|
34
|
+
type: "pie",
|
|
35
|
+
label: {
|
|
36
|
+
show: true,
|
|
37
|
+
formatter: "{d}%",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
if (props.type === "rosePie") {
|
|
41
|
+
config.roseType = "area";
|
|
42
|
+
} else if (props.type === "doughnutPie") {
|
|
43
|
+
config.radius = ["40%", "60%"];
|
|
44
|
+
}
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
.setPropertyViewFn((children) => (
|
|
49
|
+
<>
|
|
50
|
+
{children.type.propertyView({
|
|
51
|
+
label: trans("chart.pieType"),
|
|
52
|
+
})}
|
|
53
|
+
</>
|
|
54
|
+
))
|
|
55
|
+
.build();
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
export function getPieRadiusAndCenter(
|
|
59
|
+
seriesLength: number,
|
|
60
|
+
pieIndex: number,
|
|
61
|
+
pieConfig: PieConfigViewType
|
|
62
|
+
) {
|
|
63
|
+
const columnPieNum = Math.min(seriesLength, pieRadiusConfig.length);
|
|
64
|
+
const radiusNumber = pieRadiusConfig[columnPieNum - 1];
|
|
65
|
+
const isDoughnutPie = Array.isArray(pieConfig.radius);
|
|
66
|
+
const radius = isDoughnutPie
|
|
67
|
+
? [(radiusNumber / 1.6).toFixed(2) + "%", radiusNumber + "%"]
|
|
68
|
+
: radiusNumber + "%";
|
|
69
|
+
|
|
70
|
+
/*** calculate center coordinates ***/
|
|
71
|
+
const pieDiameter = 100 / columnPieNum;
|
|
72
|
+
const xPosition = (pieDiameter * (pieIndex % columnPieNum) + pieDiameter / 2).toFixed(2) + "%";
|
|
73
|
+
const rowIndex = Math.floor(pieIndex / columnPieNum) + 1;
|
|
74
|
+
const yPosition =
|
|
75
|
+
((100 / Math.floor((columnPieNum * 2 + seriesLength - 1) / columnPieNum)) * rowIndex).toFixed(
|
|
76
|
+
2
|
|
77
|
+
) + "%";
|
|
78
|
+
// log.log("Echarts height: index:", pieConfig, radius, pieIndex, xPosition, yPosition);
|
|
79
|
+
return {
|
|
80
|
+
radius: radius,
|
|
81
|
+
center: [xPosition, yPosition],
|
|
82
|
+
} as const;
|
|
83
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MultiCompBuilder,
|
|
3
|
+
dropdownControl,
|
|
4
|
+
BoolControl,
|
|
5
|
+
showLabelPropertyView,
|
|
6
|
+
} from "lowcoder-sdk";
|
|
7
|
+
import { ScatterSeriesOption } from "echarts";
|
|
8
|
+
import { trans } from "i18n/comps";
|
|
9
|
+
|
|
10
|
+
const ScatterShapeOptions = [
|
|
11
|
+
{
|
|
12
|
+
label: trans("chart.circle"),
|
|
13
|
+
value: "circle",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: trans("chart.rect"),
|
|
17
|
+
value: "rect",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: trans("chart.triangle"),
|
|
21
|
+
value: "triangle",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: trans("chart.diamond"),
|
|
25
|
+
value: "diamond",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: trans("chart.pin"),
|
|
29
|
+
value: "pin",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: trans("chart.arrow"),
|
|
33
|
+
value: "arrow",
|
|
34
|
+
},
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
export const ScatterChartConfig = (function () {
|
|
38
|
+
return new MultiCompBuilder(
|
|
39
|
+
{
|
|
40
|
+
showLabel: BoolControl,
|
|
41
|
+
shape: dropdownControl(ScatterShapeOptions, "circle"),
|
|
42
|
+
},
|
|
43
|
+
(props): ScatterSeriesOption => {
|
|
44
|
+
return {
|
|
45
|
+
type: "scatter",
|
|
46
|
+
symbol: props.shape,
|
|
47
|
+
label: {
|
|
48
|
+
show: props.showLabel,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
.setPropertyViewFn((children) => (
|
|
54
|
+
<>
|
|
55
|
+
{showLabelPropertyView(children)}
|
|
56
|
+
{children.shape.propertyView({
|
|
57
|
+
label: trans("chart.scatterShape"),
|
|
58
|
+
})}
|
|
59
|
+
</>
|
|
60
|
+
))
|
|
61
|
+
.build();
|
|
62
|
+
})();
|