@@ -12,6 +12,8 @@ import { chartColorPalette, isNumeric, JSONObject, loadScript } from "lowcoder-s
12
12
import { calcXYConfig } from "comps/chartComp/chartConfigs/cartesianAxisConfig" ;
13
13
import Big from "big.js" ;
14
14
import { googleMapsApiUrl } from "./chartConfigs/chartUrls" ;
15
+ import { chartStyleWrapper , styleWrapper } from "../../util/styleWrapper" ;
16
+ import parseBackground from "../../util/gradientBackgroundColor" ;
15
17
16
18
export function transformData (
17
19
originData : JSONObject [ ] ,
@@ -134,52 +136,15 @@ export function getEchartsConfig(
134
136
theme ?: any ,
135
137
) : EChartsOptionWithMap {
136
138
if ( props . mode === "json" ) {
137
- let opt = {
138
- "title" : {
139
- "text" : props . echartsTitle ,
140
- 'top' : props . echartsLegendConfig . top === 'bottom' ?'top' :'bottom' ,
141
- "left" :"center"
142
- } ,
143
- "backgroundColor" : props ?. style ?. background || theme ?. style ?. background ,
144
- "color" : props . echartsOption . data ?. map ( data => data . color ) ,
145
- "tooltip" : props . tooltip && {
146
- "trigger" : "item" ,
147
- "formatter" : "{a} <br/>{b} : {c}%"
148
- } ,
149
- "legend" :props . legendVisibility && {
150
- "data" : props . echartsOption . data ?. map ( data => data . name ) ,
151
- "top" : props . echartsLegendConfig . top ,
152
- } ,
153
- "series" : [
154
- {
155
- "name" : props . echartsConfig . type ,
156
- "type" : props . echartsConfig . type ,
157
- "left" : "10%" ,
158
- "top" : 60 ,
159
- "bottom" : 60 ,
160
- "width" : "80%" ,
161
- "min" : 0 ,
162
- "max" : 100 ,
163
- "gap" : 2 ,
164
- "label" : {
165
- "show" : true ,
166
- "position" : props . echartsLabelConfig . top
167
- } ,
168
- "data" : props . echartsOption . data
169
- }
170
- ]
171
- }
172
- return props . echartsOption ? opt : { } ;
173
-
139
+ return props . echartsOption ? props . echartsOption : { } ;
174
140
}
175
-
176
141
if ( props . mode === "map" ) {
177
142
const {
178
143
mapZoomLevel,
179
144
mapCenterLat,
180
145
mapCenterLng,
181
- mapOptions,
182
- showCharts,
146
+ mapOptions,
147
+ showCharts,
183
148
} = props ;
184
149
185
150
const echartsOption = mapOptions && showCharts ? mapOptions : { } ;
@@ -197,18 +162,38 @@ export function getEchartsConfig(
197
162
// axisChart
198
163
const axisChart = isAxisChart ( props . chartConfig . type ) ;
199
164
const gridPos = {
200
- left : 20 ,
201
- right : props . legendConfig . left === " right" ? "10%" : 20 ,
202
- top : 50 ,
203
- bottom : 35 ,
165
+ left : ` ${ props ?. left } %` ,
166
+ right : ` ${ props ?. right } %` ,
167
+ bottom : ` ${ props ?. bottom } %` ,
168
+ top : ` ${ props ?. top } %` ,
204
169
} ;
205
- let config : EChartsOptionWithMap = {
206
- title : { text : props . title , left : "center" } ,
207
- tooltip : {
208
- confine : true ,
209
- trigger : axisChart ? "axis" : "item" ,
170
+ let config : any = {
171
+ title : {
172
+ text : props . title ,
173
+ top : props . echartsTitleVerticalConfig . top ,
174
+ left :props . echartsTitleConfig . top ,
175
+ textStyle : {
176
+ ...styleWrapper ( props ?. titleStyle , theme ?. titleStyle )
177
+ }
178
+ } ,
179
+ backgroundColor : parseBackground ( props ?. chartStyle ?. background || theme ?. chartStyle ?. backgroundColor || "#FFFFFF" ) ,
180
+ legend : {
181
+ ...props . legendConfig ,
182
+ textStyle : {
183
+ ...styleWrapper ( props ?. legendStyle , theme ?. legendStyle , 15 )
184
+ }
185
+ } ,
186
+ tooltip : props . tooltip && {
187
+ trigger : "axis" ,
188
+ axisPointer : {
189
+ type : "line" ,
190
+ lineStyle : {
191
+ color : "rgba(0,0,0,0.2)" ,
192
+ width : 2 ,
193
+ type : "solid"
194
+ }
195
+ }
210
196
} ,
211
- legend : props . legendConfig ,
212
197
grid : {
213
198
...gridPos ,
214
199
containLabel : true ,
@@ -227,9 +212,7 @@ export function getEchartsConfig(
227
212
. map ( ( s ) => s . getView ( ) . columnName ) ;
228
213
// y-axis is category and time, data doesn't need to aggregate
229
214
const transformedData =
230
- yAxisConfig . type === "category" || yAxisConfig . type === "time"
231
- ? props . data
232
- : transformData ( props . data , props . xAxisKey , seriesColumnNames ) ;
215
+ yAxisConfig . type === "category" || yAxisConfig . type === "time" ? props . echartsData . length && props . echartsData || props . data : transformData ( props . echartsData . length && props . echartsData || props . data , props . xAxisKey , seriesColumnNames ) ;
233
216
config = {
234
217
...config ,
235
218
dataset : [
@@ -238,7 +221,16 @@ export function getEchartsConfig(
238
221
sourceHeader : false ,
239
222
} ,
240
223
] ,
241
- series : getSeriesConfig ( props ) ,
224
+ series : getSeriesConfig ( props ) . map ( series => ( {
225
+ ...series ,
226
+ itemStyle : {
227
+ ...series . itemStyle ,
228
+ ...chartStyleWrapper ( props ?. chartStyle , theme ?. chartStyle )
229
+ } ,
230
+ lineStyle : {
231
+ ...chartStyleWrapper ( props ?. chartStyle , theme ?. chartStyle )
232
+ }
233
+ } ) ) ,
242
234
} ;
243
235
if ( axisChart ) {
244
236
// pure chart's size except the margin around
@@ -266,9 +258,19 @@ export function getEchartsConfig(
266
258
config = {
267
259
...config ,
268
260
// @ts -ignore
269
- xAxis : finalXyConfig . xConfig ,
261
+ xAxis : {
262
+ ...finalXyConfig . xConfig ,
263
+ axisLabel : {
264
+ ...styleWrapper ( props ?. xAxisStyle , theme ?. xAxisStyle , 11 )
265
+ }
266
+ } ,
270
267
// @ts -ignore
271
- yAxis : finalXyConfig . yConfig ,
268
+ yAxis : {
269
+ ...finalXyConfig . yConfig ,
270
+ axisLabel : {
271
+ ...styleWrapper ( props ?. yAxisStyle , theme ?. yAxisStyle , 11 )
272
+ }
273
+ } ,
272
274
} ;
273
275
}
274
276
// log.log("Echarts transformedData and config", transformedData, config);
0 commit comments