Skip to content

Commit 045a90f

Browse files
committed
themeriver chart constants
1 parent 53d007e commit 045a90f

File tree

1 file changed

+299
-0
lines changed

1 file changed

+299
-0
lines changed
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
import {
2+
jsonControl,
3+
JSONObject,
4+
stateComp,
5+
toJSONObjectArray,
6+
toObject,
7+
BoolControl,
8+
withDefault,
9+
StringControl,
10+
NumberControl,
11+
FunctionControl,
12+
dropdownControl,
13+
eventHandlerControl,
14+
valueComp,
15+
withType,
16+
uiChildren,
17+
clickEvent,
18+
styleControl,
19+
EchartsStyle
20+
} from "lowcoder-sdk";
21+
import { RecordConstructorToComp, RecordConstructorToView } from "lowcoder-core";
22+
import { BarChartConfig } from "../chartComp/chartConfigs/barChartConfig";
23+
import { XAxisConfig, YAxisConfig } from "../chartComp/chartConfigs/cartesianAxisConfig";
24+
import { LegendConfig } from "../chartComp/chartConfigs/legendConfig";
25+
import { EchartsLegendConfig } from "../chartComp/chartConfigs/echartsLegendConfig";
26+
import { EchartsLabelConfig } from "../chartComp/chartConfigs/echartsLabelConfig";
27+
import { LineChartConfig } from "../chartComp/chartConfigs/lineChartConfig";
28+
import { PieChartConfig } from "../chartComp/chartConfigs/pieChartConfig";
29+
import { ScatterChartConfig } from "../chartComp/chartConfigs/scatterChartConfig";
30+
import { SeriesListComp } from "../chartComp/seriesComp";
31+
import { EChartsOption } from "echarts";
32+
import { i18nObjs, trans } from "i18n/comps";
33+
import { ThemeriverChartConfig } from "comps/chartComp/chartConfigs/themeriverChartConfig";
34+
35+
export const ChartTypeOptions = [
36+
{
37+
label: trans("chart.bar"),
38+
value: "bar",
39+
},
40+
{
41+
label: trans("chart.line"),
42+
value: "line",
43+
},
44+
{
45+
label: trans("chart.scatter"),
46+
value: "scatter",
47+
},
48+
{
49+
label: trans("chart.pie"),
50+
value: "pie",
51+
},
52+
] as const;
53+
54+
export const UIEventOptions = [
55+
{
56+
label: trans("chart.select"),
57+
value: "select",
58+
description: trans("chart.selectDesc"),
59+
},
60+
{
61+
label: trans("chart.unSelect"),
62+
value: "unselect",
63+
description: trans("chart.unselectDesc"),
64+
},
65+
] as const;
66+
67+
export const MapEventOptions = [
68+
{
69+
label: trans("chart.mapReady"),
70+
value: "mapReady",
71+
description: trans("chart.mapReadyDesc"),
72+
},
73+
{
74+
label: trans("chart.zoomLevelChange"),
75+
value: "zoomLevelChange",
76+
description: trans("chart.zoomLevelChangeDesc"),
77+
},
78+
{
79+
label: trans("chart.centerPositionChange"),
80+
value: "centerPositionChange",
81+
description: trans("chart.centerPositionChangeDesc"),
82+
},
83+
] as const;
84+
85+
export const XAxisDirectionOptions = [
86+
{
87+
label: trans("chart.horizontal"),
88+
value: "horizontal",
89+
},
90+
{
91+
label: trans("chart.vertical"),
92+
value: "vertical",
93+
},
94+
] as const;
95+
96+
export type XAxisDirectionType = ValueFromOption<typeof XAxisDirectionOptions>;
97+
98+
export const noDataAxisConfig = {
99+
animation: false,
100+
xAxis: {
101+
type: "category",
102+
name: trans("chart.noData"),
103+
nameLocation: "middle",
104+
data: [],
105+
axisLine: {
106+
lineStyle: {
107+
color: "#8B8FA3",
108+
},
109+
},
110+
},
111+
yAxis: {
112+
type: "value",
113+
axisLabel: {
114+
color: "#8B8FA3",
115+
},
116+
splitLine: {
117+
lineStyle: {
118+
color: "#F0F0F0",
119+
},
120+
},
121+
},
122+
tooltip: {
123+
show: false,
124+
},
125+
series: [
126+
{
127+
data: [700],
128+
type: "line",
129+
itemStyle: {
130+
opacity: 0,
131+
},
132+
},
133+
],
134+
} as EChartsOption;
135+
136+
export const noDataPieChartConfig = {
137+
animation: false,
138+
tooltip: {
139+
show: false,
140+
},
141+
legend: {
142+
formatter: trans("chart.unknown"),
143+
top: "bottom",
144+
selectedMode: false,
145+
},
146+
color: ["#B8BBCC", "#CED0D9", "#DCDEE6", "#E6E6EB"],
147+
series: [
148+
{
149+
type: "pie",
150+
radius: "35%",
151+
center: ["25%", "50%"],
152+
silent: true,
153+
label: {
154+
show: false,
155+
},
156+
data: [
157+
{
158+
name: "1",
159+
value: 70,
160+
},
161+
{
162+
name: "2",
163+
value: 68,
164+
},
165+
{
166+
name: "3",
167+
value: 48,
168+
},
169+
{
170+
name: "4",
171+
value: 40,
172+
},
173+
],
174+
},
175+
{
176+
type: "pie",
177+
radius: "35%",
178+
center: ["75%", "50%"],
179+
silent: true,
180+
label: {
181+
show: false,
182+
},
183+
data: [
184+
{
185+
name: "1",
186+
value: 70,
187+
},
188+
{
189+
name: "2",
190+
value: 68,
191+
},
192+
{
193+
name: "3",
194+
value: 48,
195+
},
196+
{
197+
name: "4",
198+
value: 40,
199+
},
200+
],
201+
},
202+
],
203+
} as EChartsOption;
204+
205+
export type ChartSize = { w: number; h: number };
206+
207+
export const getDataKeys = (data: Array<JSONObject>) => {
208+
if (!data) {
209+
return [];
210+
}
211+
const dataKeys: Array<string> = [];
212+
data.slice(0, 50).forEach((d) => {
213+
Object.keys(d).forEach((key) => {
214+
if (!dataKeys.includes(key)) {
215+
dataKeys.push(key);
216+
}
217+
});
218+
});
219+
return dataKeys;
220+
};
221+
222+
const ChartOptionMap = {
223+
bar: BarChartConfig,
224+
line: LineChartConfig,
225+
pie: PieChartConfig,
226+
scatter: ScatterChartConfig,
227+
};
228+
229+
const EchartsOptionMap = {
230+
themeriver: ThemeriverChartConfig,
231+
};
232+
233+
const ChartOptionComp = withType(ChartOptionMap, "bar");
234+
const EchartsOptionComp = withType(EchartsOptionMap, "themeriver");
235+
export type CharOptionCompType = keyof typeof ChartOptionMap;
236+
237+
export const chartUiModeChildren = {
238+
title: StringControl,
239+
data: jsonControl(toJSONObjectArray, i18nObjs.defaultDataSource),
240+
xAxisKey: valueComp<string>(""), // x-axis, key from data
241+
xAxisDirection: dropdownControl(XAxisDirectionOptions, "horizontal"),
242+
series: SeriesListComp,
243+
xConfig: XAxisConfig,
244+
yConfig: YAxisConfig,
245+
legendConfig: LegendConfig,
246+
chartConfig: ChartOptionComp,
247+
onUIEvent: eventHandlerControl(UIEventOptions),
248+
};
249+
250+
const chartJsonModeChildren = {
251+
echartsOption: jsonControl(toObject, i18nObjs.defaultThemeriverChartOption),
252+
echartsTitle: withDefault(StringControl, trans("themeriverChart.defaultTitle")),
253+
echartsLegendConfig: EchartsLegendConfig,
254+
echartsLabelConfig: EchartsLabelConfig,
255+
echartsConfig: EchartsOptionComp,
256+
style: styleControl(EchartsStyle),
257+
tooltip: withDefault(BoolControl, true),
258+
legendVisibility: withDefault(BoolControl, true),
259+
}
260+
261+
const chartMapModeChildren = {
262+
mapInstance: stateComp(),
263+
getMapInstance: FunctionControl,
264+
mapApiKey: withDefault(StringControl, ''),
265+
mapZoomLevel: withDefault(NumberControl, 3),
266+
mapCenterLng: withDefault(NumberControl, 15.932644),
267+
mapCenterLat: withDefault(NumberControl, 50.942063),
268+
mapOptions: jsonControl(toObject, i18nObjs.defaultMapJsonOption),
269+
onMapEvent: eventHandlerControl(MapEventOptions),
270+
showCharts: withDefault(BoolControl, true),
271+
}
272+
273+
export type UIChartDataType = {
274+
seriesName: string;
275+
// coordinate chart
276+
x?: any;
277+
y?: any;
278+
// pie or funnel
279+
itemName?: any;
280+
value?: any;
281+
};
282+
283+
export type NonUIChartDataType = {
284+
name: string;
285+
value: any;
286+
}
287+
288+
export const themeriverChartChildrenMap = {
289+
selectedPoints: stateComp<Array<UIChartDataType>>([]),
290+
lastInteractionData: stateComp<Array<UIChartDataType> | NonUIChartDataType>({}),
291+
onEvent: eventHandlerControl([clickEvent] as const),
292+
...chartUiModeChildren,
293+
...chartJsonModeChildren,
294+
...chartMapModeChildren,
295+
};
296+
297+
const chartUiChildrenMap = uiChildren(themeriverChartChildrenMap);
298+
export type ChartCompPropsType = RecordConstructorToView<typeof chartUiChildrenMap>;
299+
export type ChartCompChildrenType = RecordConstructorToComp<typeof chartUiChildrenMap>;

0 commit comments

Comments
 (0)