Skip to content

Commit 5fdd5f1

Browse files
committed
echarts configurations updated
1 parent 92930f7 commit 5fdd5f1

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

client/packages/lowcoder-comps/src/comps/chartComp/chartConstants.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ import {
1313
eventHandlerControl,
1414
valueComp,
1515
withType,
16-
ValueFromOption,
1716
uiChildren,
1817
clickEvent,
18+
styleControl,
19+
EchartsStyle
1920
} from "lowcoder-sdk";
2021
import { RecordConstructorToComp, RecordConstructorToView } from "lowcoder-core";
2122
import { BarChartConfig } from "./chartConfigs/barChartConfig";
2223
import { XAxisConfig, YAxisConfig } from "./chartConfigs/cartesianAxisConfig";
2324
import { LegendConfig } from "./chartConfigs/legendConfig";
25+
import { EchartsLegendConfig } from "./chartConfigs/echartsLegendConfig";
26+
import { EchartsLabelConfig } from "./chartConfigs/echartsLabelConfig";
2427
import { LineChartConfig } from "./chartConfigs/lineChartConfig";
2528
import { PieChartConfig } from "./chartConfigs/pieChartConfig";
2629
import { ScatterChartConfig } from "./chartConfigs/scatterChartConfig";
2730
import { SeriesListComp } from "./seriesComp";
2831
import { EChartsOption } from "echarts";
2932
import { i18nObjs, trans } from "i18n/comps";
33+
import { GaugeChartConfig } from "./chartConfigs/gaugeChartConfig";
34+
import { FunnelChartConfig } from "./chartConfigs/funnelChartConfig";
3035

3136
export const ChartTypeOptions = [
3237
{
@@ -47,32 +52,14 @@ export const ChartTypeOptions = [
4752
},
4853
] as const;
4954

50-
const chartModeOptions = [
55+
export const EchartsTypeOptions = [
5156
{
52-
label: trans("chart.UIMode"),
53-
value: "ui",
57+
label: trans("chart.funnel"),
58+
value: "funnel",
5459
},
5560
{
56-
label: "ECharts JSON",
57-
value: "json",
58-
},
59-
{
60-
label: "Map",
61-
value: "map",
62-
},
63-
] as const;
64-
65-
const mapModeOptions = [
66-
{
67-
label: "Map",
68-
value: "map",
69-
},
70-
] as const;
71-
72-
const eChartModeOptions = [
73-
{
74-
label: "ECharts JSON",
75-
value: "json",
61+
label: trans("chart.gauge"),
62+
value: "gauge",
7663
},
7764
] as const;
7865

@@ -251,7 +238,13 @@ const ChartOptionMap = {
251238
scatter: ScatterChartConfig,
252239
};
253240

241+
const EchartsOptionMap = {
242+
funnel: FunnelChartConfig,
243+
gauge: GaugeChartConfig,
244+
};
245+
254246
const ChartOptionComp = withType(ChartOptionMap, "bar");
247+
const EchartsOptionComp = withType(EchartsOptionMap, "funnel");
255248
export type CharOptionCompType = keyof typeof ChartOptionMap;
256249

257250
export const chartUiModeChildren = {
@@ -269,6 +262,11 @@ export const chartUiModeChildren = {
269262

270263
const chartJsonModeChildren = {
271264
echartsOption: jsonControl(toObject, i18nObjs.defaultEchartsJsonOption),
265+
echartsTitle: withDefault(StringControl, trans("echarts.defaultTitle")),
266+
echartsLegendConfig: EchartsLegendConfig,
267+
echartsLabelConfig: EchartsLabelConfig,
268+
echartsConfig: EchartsOptionComp,
269+
style: styleControl(EchartsStyle),
272270
}
273271

274272
const chartMapModeChildren = {

client/packages/lowcoder-comps/src/comps/chartComp/chartPropertyView.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { changeChildAction, CompAction } from "lowcoder-core";
2-
import { ChartCompChildrenType, ChartTypeOptions, getDataKeys } from "./chartConstants";
2+
import { ChartCompChildrenType, ChartTypeOptions, EchartsTypeOptions,getDataKeys } from "./chartConstants";
33
import { newSeries } from "./seriesComp";
44
import {
55
CustomModal,
@@ -150,10 +150,41 @@ export function chartPropertyView(
150150
</div>
151151
),
152152
})}
153+
<Dropdown
154+
value={children.echartsConfig.children.compType.getView()}
155+
options={EchartsTypeOptions}
156+
label={trans("chart.chartType")}
157+
onChange={(value) => {
158+
// keep the previous value
159+
if (children.echartsConfig.children.comp.children.hasOwnProperty("showLabel")) {
160+
children.echartsConfig.dispatchChangeValueAction({
161+
compType: value as any,
162+
comp: {
163+
showLabel: (
164+
children.echartsConfig.children.comp.children as any
165+
).showLabel.toJsonValue(),
166+
},
167+
});
168+
} else {
169+
children.echartsConfig.dispatchChangeValueAction({
170+
compType: value,
171+
});
172+
}
173+
}}
174+
/>
175+
{children.echartsConfig.children.compType.getView() === "funnel" &&
176+
<>
177+
{children.echartsLegendConfig.getPropertyView()}
178+
{children.echartsLabelConfig.getPropertyView()}
179+
</>}
180+
{children.echartsTitle.propertyView({ label: trans("echarts.title") })}
153181
</Section>
154182
<Section name={sectionNames.interaction}>
155183
{children.onEvent.propertyView()}
156184
</Section>
185+
<Section name={sectionNames.style}>
186+
{children.style.getPropertyView()}
187+
</Section>
157188
<Section name={sectionNames.layout}>{hiddenPropertyView(children)}</Section>
158189
</>
159190
);

client/packages/lowcoder-comps/src/comps/chartComp/chartUtils.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,50 @@ export function getSeriesConfig(props: EchartsConfigProps) {
130130
// https://echarts.apache.org/en/option.html
131131
export function getEchartsConfig(props: EchartsConfigProps, chartSize?: ChartSize): EChartsOptionWithMap {
132132
if (props.mode === "json") {
133-
return props.echartsOption ? props.echartsOption : {};
133+
let opt={
134+
"title": {
135+
"text": props.echartsTitle,
136+
"left": "center"
137+
},
138+
"backgroundColor": props?.style?.background,
139+
"color":props?.style?.color,
140+
"tooltip": {
141+
"trigger": "item",
142+
"formatter": "{a} <br/>{b} : {c}%"
143+
},
144+
"legend": {
145+
"data": [
146+
"Show",
147+
"Click",
148+
"Visit",
149+
"Query",
150+
"Buy"
151+
],
152+
"top": props.echartsLegendConfig.top,
153+
},
154+
"series": [
155+
{
156+
"name": props.echartsConfig.type,
157+
"type": props.echartsConfig.type,
158+
"left": "10%",
159+
"top": 60,
160+
"bottom": 60,
161+
"width": "80%",
162+
"min": 0,
163+
"max": 100,
164+
"gap": 2,
165+
"label": {
166+
"show": true,
167+
"position": props.echartsLabelConfig.top
168+
},
169+
"data": props.echartsOption.series[0].data
170+
}
171+
]
172+
}
173+
return props.echartsOption ? opt : {};
174+
134175
}
176+
135177
if(props.mode === "map") {
136178
const {
137179
mapZoomLevel,

0 commit comments

Comments
 (0)