@ecan-bi/tools 1.0.20 → 1.0.21
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/.babelrc +6 -0
- package/lib/index.es.js +1 -0
- package/package.json +15 -27
- package/rollup.config.js +30 -0
- package/src/hooks/useTransformChartDataByAttrKey.ts +77 -0
- package/src/hooks/useTransformChartDataByAttrValue.ts +61 -0
- package/src/hooks/useValueFormatter.ts +27 -0
- package/src/hooks/useVariablesInText.ts +44 -0
- package/src/index.ts +22 -0
- package/src/indicator.ts +1215 -0
- package/src/utils/constant.ts +1 -0
- package/src/utils/runCode.ts +26 -0
- package/src/utils/transformProps.ts +901 -0
- package/src/utils/util.ts +195 -0
- package/tsconfig.json +38 -0
- package/dist/index.es.js +0 -1731
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -6
- package/dist/index.umd.js.map +0 -1
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
import { computed, unref } from 'vue'
|
|
2
|
+
import useVariablesInText from '../hooks/useVariablesInText'
|
|
3
|
+
import useValueFormatter from '../hooks/useValueFormatter'
|
|
4
|
+
import { handleFormatter, getLegendFormat, formatQfw } from './util'
|
|
5
|
+
function getMarkLineData (chartsOptions: any) {
|
|
6
|
+
if (chartsOptions.isShowMarkLine) {
|
|
7
|
+
return {
|
|
8
|
+
markLine: {
|
|
9
|
+
data: [{ type: chartsOptions.markLineType }]
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
return {}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const getTransformProps = (chartsOptions, chartData, fontSize) => {
|
|
17
|
+
switch (chartsOptions.type) {
|
|
18
|
+
case 'bar':
|
|
19
|
+
return getBarTransformProps(chartsOptions, chartData, fontSize)
|
|
20
|
+
case 'line':
|
|
21
|
+
return getLineTransformProps(chartsOptions, chartData, fontSize)
|
|
22
|
+
case 'pie':
|
|
23
|
+
return getPieTransformProps(chartsOptions, chartData, fontSize)
|
|
24
|
+
case 'comboGraph':
|
|
25
|
+
return getComboGraphTransformProps(chartsOptions, chartData, fontSize)
|
|
26
|
+
default:
|
|
27
|
+
return {}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getBarTransformProps = (chartsOptions, chartData, fontSize) => {
|
|
32
|
+
const yAxisLabelFormatter = chartsOptions.yAxisLabelFormatter
|
|
33
|
+
const xAxisLabelFormatter = chartsOptions.xAxisLabelFormatter
|
|
34
|
+
const { dimensions = [], dataset = [] } = chartData
|
|
35
|
+
const series = computed(() => {
|
|
36
|
+
const { gradientShow, gradientColors, gradientOffset, barBorderRadius } = chartsOptions
|
|
37
|
+
const ds = dataset
|
|
38
|
+
const len = ds.length
|
|
39
|
+
const series: any = []
|
|
40
|
+
for (let i = 0; i < len; i++) {
|
|
41
|
+
const item = {
|
|
42
|
+
...ds[i],
|
|
43
|
+
type: 'bar',
|
|
44
|
+
barWidth: chartsOptions.barWidth,
|
|
45
|
+
showBackground: chartsOptions.showBarBackground
|
|
46
|
+
} as { [key: string]: any }
|
|
47
|
+
const { isStack, stackColumns } = chartsOptions
|
|
48
|
+
if (isStack && (stackColumns.includes(ds[i].name || !stackColumns))) {
|
|
49
|
+
item.stack = 'stack'
|
|
50
|
+
}
|
|
51
|
+
item.label = {
|
|
52
|
+
show: chartsOptions.labelShow,
|
|
53
|
+
fontSize: chartsOptions.labelFontSize,
|
|
54
|
+
position: chartsOptions.labelPosition,
|
|
55
|
+
color: chartsOptions.labelColor,
|
|
56
|
+
width: chartsOptions.labelWidth,
|
|
57
|
+
overflow: chartsOptions.labelOverflow,
|
|
58
|
+
formatter: (params) => {
|
|
59
|
+
let formatter = ''
|
|
60
|
+
let labelFormatter = chartsOptions.labelFormatter
|
|
61
|
+
if (labelFormatter === '') {
|
|
62
|
+
labelFormatter = '{c}'
|
|
63
|
+
}
|
|
64
|
+
const { seriesName, name, value, data } = params || {}
|
|
65
|
+
formatter += useVariablesInText(
|
|
66
|
+
labelFormatter,
|
|
67
|
+
{
|
|
68
|
+
textData: {
|
|
69
|
+
name,
|
|
70
|
+
value,
|
|
71
|
+
a: seriesName,
|
|
72
|
+
b: name,
|
|
73
|
+
c: value || 0,
|
|
74
|
+
...data
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
useNewline: true,
|
|
79
|
+
useSpace: true
|
|
80
|
+
})
|
|
81
|
+
return formatter
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
item.itemStyle = {}
|
|
85
|
+
if (gradientShow) {
|
|
86
|
+
item.itemStyle = {
|
|
87
|
+
color: {
|
|
88
|
+
x: chartsOptions.isUseHorizontalAxis ? 1 : 0,
|
|
89
|
+
y: 0,
|
|
90
|
+
x2: 0,
|
|
91
|
+
y2: chartsOptions.isUseHorizontalAxis ? 0 : 1,
|
|
92
|
+
colorStops: [{
|
|
93
|
+
offset: 0,
|
|
94
|
+
color: chartsOptions.colors[i]
|
|
95
|
+
}, {
|
|
96
|
+
offset: gradientOffset,
|
|
97
|
+
color: gradientColors[i]
|
|
98
|
+
}, {
|
|
99
|
+
offset: 1,
|
|
100
|
+
color: gradientColors[i]
|
|
101
|
+
}]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (barBorderRadius) {
|
|
106
|
+
const radius = barBorderRadius.split(',')
|
|
107
|
+
if (radius?.length) {
|
|
108
|
+
const radiusItems: any = []
|
|
109
|
+
for (const rs of radius) {
|
|
110
|
+
const value = parseFloat(rs)
|
|
111
|
+
if (!isNaN(value)) {
|
|
112
|
+
radiusItems.push(value)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// item.itemStyle.borderRadius = radiusItems
|
|
116
|
+
// echart4.4版本圆角属性名变更
|
|
117
|
+
item.itemStyle.barBorderRadius = radiusItems
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (chartsOptions.isShowMarkLine) {
|
|
121
|
+
item.markLine = {
|
|
122
|
+
data: [{ type: chartsOptions.markLineType }]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
series.push(item)
|
|
126
|
+
}
|
|
127
|
+
return series
|
|
128
|
+
})
|
|
129
|
+
const xAxisData = computed(() => {
|
|
130
|
+
return dimensions.map((item) => {
|
|
131
|
+
let result = {}
|
|
132
|
+
if (item && typeof item === 'object') {
|
|
133
|
+
result = {
|
|
134
|
+
...item,
|
|
135
|
+
textStyle: {
|
|
136
|
+
fontSize: fontSize
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
result = {
|
|
141
|
+
value: item,
|
|
142
|
+
textStyle: {
|
|
143
|
+
fontSize: fontSize
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
return {
|
|
151
|
+
tooltip: {
|
|
152
|
+
trigger: 'axis',
|
|
153
|
+
show: chartsOptions.tooltipShow,
|
|
154
|
+
formatter: (params) => {
|
|
155
|
+
const len = params.length
|
|
156
|
+
let formatter = ''
|
|
157
|
+
let tooltipFormatter = chartsOptions.tooltipFormatter
|
|
158
|
+
// currentData = params[0]?.data
|
|
159
|
+
if (tooltipFormatter === '') {
|
|
160
|
+
tooltipFormatter = '{marker} {a} {c}'
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0; i < len; i++) {
|
|
163
|
+
const { marker, seriesName, name, value, data } = params[i] || {}
|
|
164
|
+
if (i === 0) {
|
|
165
|
+
let formatName = name
|
|
166
|
+
if (typeof name === 'string' && name[0] === '0' && !isNaN(+name)) {
|
|
167
|
+
formatName = (+name).toString()
|
|
168
|
+
}
|
|
169
|
+
formatter += `${useValueFormatter(xAxisLabelFormatter, formatName)}<br/>`
|
|
170
|
+
}
|
|
171
|
+
formatter += useVariablesInText(
|
|
172
|
+
tooltipFormatter,
|
|
173
|
+
{
|
|
174
|
+
textData: {
|
|
175
|
+
marker,
|
|
176
|
+
name,
|
|
177
|
+
value,
|
|
178
|
+
Qfw: formatQfw,
|
|
179
|
+
a: seriesName,
|
|
180
|
+
b: name,
|
|
181
|
+
c: value || 0,
|
|
182
|
+
...data
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
useNewline: true,
|
|
187
|
+
useSpace: true
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
formatter += '<br/>'
|
|
191
|
+
}
|
|
192
|
+
return formatter
|
|
193
|
+
},
|
|
194
|
+
// valueFormatter: (value) => {
|
|
195
|
+
// return useVariablesInText(chartsOptions.tooltipValueFormatter as string, { value })
|
|
196
|
+
// },
|
|
197
|
+
textStyle: {
|
|
198
|
+
color: chartsOptions.tooltipTextStyleColor,
|
|
199
|
+
fontSize: fontSize
|
|
200
|
+
},
|
|
201
|
+
position: chartsOptions.tooltipPosition || undefined,
|
|
202
|
+
backgroundColor: chartsOptions.tooltipBackgroundColor || '#fff'
|
|
203
|
+
},
|
|
204
|
+
legend: {
|
|
205
|
+
type: chartsOptions.legendScroll ? 'scroll' : 'plain',
|
|
206
|
+
width: chartsOptions.legendWidth,
|
|
207
|
+
height: chartsOptions.legendHeight,
|
|
208
|
+
show: chartsOptions.legendShow,
|
|
209
|
+
orient: chartsOptions.legendOrient,
|
|
210
|
+
top: chartsOptions.legendTop,
|
|
211
|
+
left: chartsOptions.legendLeft,
|
|
212
|
+
textStyle: {
|
|
213
|
+
// lineHeight: parseFloat(chartsOptions.legendFontSize) + 8,
|
|
214
|
+
rich: {
|
|
215
|
+
text: {
|
|
216
|
+
width: chartsOptions.legendTextWidth,
|
|
217
|
+
color: chartsOptions.legendTextStyleColor,
|
|
218
|
+
fontSize: chartsOptions.legendFontSize
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
itemHeight: chartsOptions.legendItemHeight,
|
|
223
|
+
itemWidth: chartsOptions.legendItemWidth,
|
|
224
|
+
itemGap: chartsOptions.legendItemGap,
|
|
225
|
+
data: dataset.map((value, index) => {
|
|
226
|
+
return {
|
|
227
|
+
name: value.name,
|
|
228
|
+
itemStyle: {
|
|
229
|
+
color: chartsOptions.colors[index]
|
|
230
|
+
},
|
|
231
|
+
icon: chartsOptions.legendType
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
formatter: (name: string) => {
|
|
235
|
+
return getLegendFormat(chartsOptions.legendFormatter, {
|
|
236
|
+
name
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
xAxis: {
|
|
241
|
+
type: chartsOptions.isUseHorizontalAxis ? 'value' : 'category',
|
|
242
|
+
data: chartsOptions.isUseHorizontalAxis ? null : unref(xAxisData),
|
|
243
|
+
inverse: chartsOptions.isUseHorizontalAxis ? chartsOptions.xAxisInverse : chartsOptions.axisInverse,
|
|
244
|
+
minInterval: chartsOptions.xAxisMinInterval,
|
|
245
|
+
splitLine: {
|
|
246
|
+
show: chartsOptions.xAxisSplitLineShow,
|
|
247
|
+
lineStyle: {
|
|
248
|
+
color: chartsOptions.xAxisSplitLineStyleColor,
|
|
249
|
+
type: chartsOptions.xAxisSplitLineType
|
|
250
|
+
},
|
|
251
|
+
interval: chartsOptions.xAxisSplitLineInterval
|
|
252
|
+
},
|
|
253
|
+
splitArea: {
|
|
254
|
+
show: chartsOptions.xAxisSplitAreaShow
|
|
255
|
+
},
|
|
256
|
+
axisLabel: {
|
|
257
|
+
color: chartsOptions.xAxisLabelColor,
|
|
258
|
+
interval: chartsOptions.xAxisLabelInterval || 0,
|
|
259
|
+
rotate: chartsOptions.xAxisLabelRotate,
|
|
260
|
+
width: chartsOptions.xAxisLabelWidth,
|
|
261
|
+
overflow: chartsOptions.xAxisLabelOverflow,
|
|
262
|
+
fontSize: chartsOptions.xAxisLabelFontSize,
|
|
263
|
+
formatter (value: string) {
|
|
264
|
+
if (typeof value === 'string' && value[0] === '0' && !isNaN(+value)) {
|
|
265
|
+
value = (+value).toString()
|
|
266
|
+
}
|
|
267
|
+
return useValueFormatter(xAxisLabelFormatter, value)
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
axisLine: {
|
|
271
|
+
show: chartsOptions.xAxisLineShow,
|
|
272
|
+
lineStyle: {
|
|
273
|
+
color: chartsOptions.xAxisLineStyleColor
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
axisTick: {
|
|
277
|
+
show: chartsOptions.xAxisTickShow
|
|
278
|
+
},
|
|
279
|
+
name: chartsOptions.xAxisName,
|
|
280
|
+
nameTextStyle: {
|
|
281
|
+
fontSize: chartsOptions.xAxisLabelFontSize,
|
|
282
|
+
color: chartsOptions.xAxisLabelColor,
|
|
283
|
+
align: 'left'
|
|
284
|
+
},
|
|
285
|
+
max: chartsOptions.xAxisMaxValue || null
|
|
286
|
+
},
|
|
287
|
+
yAxis: {
|
|
288
|
+
type: chartsOptions.isUseHorizontalAxis ? 'category' : 'value',
|
|
289
|
+
data: chartsOptions.isUseHorizontalAxis ? unref(dimensions) : null,
|
|
290
|
+
inverse: chartsOptions.isUseHorizontalAxis ? chartsOptions.axisInverse : chartsOptions.yAxisInverse,
|
|
291
|
+
minInterval: chartsOptions.yAxisMinInterval,
|
|
292
|
+
splitLine: {
|
|
293
|
+
show: chartsOptions.yAxisSplitLineShow,
|
|
294
|
+
lineStyle: {
|
|
295
|
+
color: chartsOptions.yAxisSplitLineStyleColor,
|
|
296
|
+
type: chartsOptions.yAxisSplitLineType
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
splitArea: {
|
|
300
|
+
show: chartsOptions.yAxisSplitAreaShow
|
|
301
|
+
},
|
|
302
|
+
axisLabel: {
|
|
303
|
+
show: chartsOptions.yAxisLabelShow,
|
|
304
|
+
fontSize: chartsOptions.yAxisLabelFontSize,
|
|
305
|
+
color: chartsOptions.yAxisLabelColor,
|
|
306
|
+
rotate: chartsOptions.yAxisLabelRotate,
|
|
307
|
+
width: chartsOptions.yAxisLabelWidth,
|
|
308
|
+
overflow: chartsOptions.yAxisLabelOverflow,
|
|
309
|
+
formatter (value: string) {
|
|
310
|
+
return useValueFormatter(yAxisLabelFormatter, value)
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
axisLine: {
|
|
314
|
+
show: chartsOptions.yAxisLineAlwaysDisplay,
|
|
315
|
+
lineStyle: {
|
|
316
|
+
color: chartsOptions.yAxisLineStyleColor
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
name: chartsOptions.yAxisName,
|
|
320
|
+
nameTextStyle: {
|
|
321
|
+
fontSize: chartsOptions.yAxisLabelFontSize,
|
|
322
|
+
color: chartsOptions.yAxisLabelColor,
|
|
323
|
+
align: 'right'
|
|
324
|
+
},
|
|
325
|
+
max: chartsOptions.yAxisMaxValue || null
|
|
326
|
+
},
|
|
327
|
+
series: unref(series)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const getLineTransformProps = (chartsOptions, chartData, fontSize) => {
|
|
332
|
+
// console.log('xAxisName', chartsOptions, chartsOptions.xAxisName)
|
|
333
|
+
const yAxisLabelFormatter = chartsOptions.yAxisLabelFormatter
|
|
334
|
+
const xAxisLabelFormatter = chartsOptions.xAxisLabelFormatter
|
|
335
|
+
const { dimensions = [], dataset = [] } = chartData
|
|
336
|
+
const xAxisData = computed(() => {
|
|
337
|
+
return dimensions.map((item) => {
|
|
338
|
+
let result = {}
|
|
339
|
+
if (item && typeof item === 'object') {
|
|
340
|
+
result = {
|
|
341
|
+
...item,
|
|
342
|
+
textStyle: {
|
|
343
|
+
fontSize: fontSize
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
result = {
|
|
348
|
+
value: item,
|
|
349
|
+
textStyle: {
|
|
350
|
+
fontSize: fontSize
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return result
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
const series = computed(() => {
|
|
358
|
+
const temp = [] as { [key: string]: any }[]
|
|
359
|
+
const len = dataset.length
|
|
360
|
+
for (let i = 0; i < len; i++) {
|
|
361
|
+
const shadowStyle: any = {}
|
|
362
|
+
if (chartsOptions.shadowColor) {
|
|
363
|
+
shadowStyle.shadowColor = chartsOptions.shadowColor
|
|
364
|
+
shadowStyle.shadowBlur = chartsOptions.shadowBlur
|
|
365
|
+
shadowStyle.shadowOffsetY = chartsOptions.shadowOffsetY
|
|
366
|
+
shadowStyle.shadowOffsetX = chartsOptions.shadowOffsetX
|
|
367
|
+
}
|
|
368
|
+
temp.push({
|
|
369
|
+
type: 'line',
|
|
370
|
+
...dataset[i],
|
|
371
|
+
symbolSize: chartsOptions.symbolSize,
|
|
372
|
+
smooth: chartsOptions.smooth,
|
|
373
|
+
areaStyle: {
|
|
374
|
+
color: chartsOptions.areaGradientShow
|
|
375
|
+
? {
|
|
376
|
+
type: 'linear',
|
|
377
|
+
x: 0,
|
|
378
|
+
y: 0,
|
|
379
|
+
x2: 0,
|
|
380
|
+
y2: 1,
|
|
381
|
+
colorStops: [{
|
|
382
|
+
offset: 0,
|
|
383
|
+
color: chartsOptions.colors[i]
|
|
384
|
+
}, {
|
|
385
|
+
offset: 1,
|
|
386
|
+
color: chartsOptions.areaGradientColor || 'transparent'
|
|
387
|
+
}],
|
|
388
|
+
global: false
|
|
389
|
+
}
|
|
390
|
+
: chartsOptions.colors[i],
|
|
391
|
+
opacity: chartsOptions.areaStyleOpacity
|
|
392
|
+
},
|
|
393
|
+
lineStyle: {
|
|
394
|
+
width: chartsOptions.lineStyleWidth,
|
|
395
|
+
...shadowStyle
|
|
396
|
+
},
|
|
397
|
+
...getMarkLineData(chartsOptions)
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
return temp
|
|
401
|
+
})
|
|
402
|
+
return {
|
|
403
|
+
tooltip: {
|
|
404
|
+
trigger: 'axis',
|
|
405
|
+
show: chartsOptions.tooltipShow,
|
|
406
|
+
formatter: (params) => {
|
|
407
|
+
const len = params.length
|
|
408
|
+
let formatter = ''
|
|
409
|
+
let tooltipFormatter = chartsOptions.tooltipFormatter
|
|
410
|
+
if (tooltipFormatter === '') {
|
|
411
|
+
tooltipFormatter = '{marker} {a} {c}'
|
|
412
|
+
}
|
|
413
|
+
for (let i = 0; i < len; i++) {
|
|
414
|
+
const { marker, seriesName, name, value, data } = params[i] || {}
|
|
415
|
+
if (i === 0) {
|
|
416
|
+
formatter += `${name}<br/>`
|
|
417
|
+
}
|
|
418
|
+
formatter += useVariablesInText(
|
|
419
|
+
tooltipFormatter,
|
|
420
|
+
{
|
|
421
|
+
textData: {
|
|
422
|
+
marker,
|
|
423
|
+
name,
|
|
424
|
+
value,
|
|
425
|
+
a: seriesName,
|
|
426
|
+
b: name,
|
|
427
|
+
c: value,
|
|
428
|
+
...data
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
useNewline: true,
|
|
433
|
+
useSpace: true
|
|
434
|
+
}
|
|
435
|
+
)
|
|
436
|
+
formatter += '<br/>'
|
|
437
|
+
}
|
|
438
|
+
return formatter
|
|
439
|
+
},
|
|
440
|
+
textStyle: {
|
|
441
|
+
color: chartsOptions.tooltipTextStyleColor,
|
|
442
|
+
fontSize: fontSize.value
|
|
443
|
+
},
|
|
444
|
+
position: chartsOptions.tooltipPosition || undefined,
|
|
445
|
+
backgroundColor: chartsOptions.tooltipBackgroundColor || '#fff'
|
|
446
|
+
},
|
|
447
|
+
xAxis: {
|
|
448
|
+
name: chartsOptions.xAxisName,
|
|
449
|
+
type: 'category',
|
|
450
|
+
data: unref(xAxisData),
|
|
451
|
+
minInterval: chartsOptions.xAxisMinInterval,
|
|
452
|
+
splitLine: {
|
|
453
|
+
show: chartsOptions.xAxisSplitLineShow,
|
|
454
|
+
lineStyle: {
|
|
455
|
+
color: chartsOptions.xAxisSplitLineStyleColor
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
axisLabel: {
|
|
459
|
+
color: chartsOptions.xAxisLabelColor,
|
|
460
|
+
interval: chartsOptions.xAxisLabelInterval || 0,
|
|
461
|
+
rotate: chartsOptions.xAxisLabelRotate,
|
|
462
|
+
width: chartsOptions.xAxisLabelWidth,
|
|
463
|
+
overflow: chartsOptions.xAxisLabelOverflow,
|
|
464
|
+
formatter (value: string) {
|
|
465
|
+
return useValueFormatter(xAxisLabelFormatter, value)
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
axisLine: {
|
|
469
|
+
lineStyle: {
|
|
470
|
+
color: chartsOptions.xAxisLineStyleColor
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
axisTick: {
|
|
474
|
+
show: chartsOptions.xAxisTickShow
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
yAxis: {
|
|
478
|
+
type: 'value',
|
|
479
|
+
name: chartsOptions.yAxisName,
|
|
480
|
+
minInterval: chartsOptions.yAxisMinInterval,
|
|
481
|
+
splitLine: {
|
|
482
|
+
show: chartsOptions.yAxisSplitLineShow,
|
|
483
|
+
lineStyle: {
|
|
484
|
+
color: chartsOptions.yAxisSplitLineStyleColor
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
axisLabel: {
|
|
488
|
+
fontSize: fontSize,
|
|
489
|
+
color: chartsOptions.yAxisLabelColor,
|
|
490
|
+
formatter (value: string) {
|
|
491
|
+
return useValueFormatter(yAxisLabelFormatter, value)
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
axisLine: {
|
|
495
|
+
show: chartsOptions.yAxisLineAlwaysDisplay,
|
|
496
|
+
lineStyle: {
|
|
497
|
+
color: chartsOptions.yAxisLineStyleColor
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
// 图例
|
|
502
|
+
legend: {
|
|
503
|
+
show: chartsOptions.legendShow,
|
|
504
|
+
orient: chartsOptions.legendOrient,
|
|
505
|
+
top: chartsOptions.legendTop,
|
|
506
|
+
left: chartsOptions.legendLeft,
|
|
507
|
+
textStyle: {
|
|
508
|
+
fontSize: fontSize
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
series: unref(series)
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const getPieTransformProps = (chartsOptions, chartData, fontSize) => {
|
|
516
|
+
const { dataset = [] } = chartData
|
|
517
|
+
let { data = [] } = dataset[0] || {}
|
|
518
|
+
if (Array.isArray(chartsOptions.colors)) {
|
|
519
|
+
const isUseLabelColors = chartsOptions.isUseLabelColors
|
|
520
|
+
const colors = chartsOptions.colors
|
|
521
|
+
data = data.map((item, index) => ({
|
|
522
|
+
label: isUseLabelColors ? { color: colors[index] } : {},
|
|
523
|
+
...item
|
|
524
|
+
}))
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
title: {
|
|
528
|
+
text: chartsOptions.titleText,
|
|
529
|
+
subtext: chartsOptions.titleSubtext,
|
|
530
|
+
textStyle: {
|
|
531
|
+
fontSize: chartsOptions.titleFontSize,
|
|
532
|
+
fontWeight: chartsOptions.fontWeight,
|
|
533
|
+
color: chartsOptions.titleColor
|
|
534
|
+
},
|
|
535
|
+
left: chartsOptions.textAlign || 'center'
|
|
536
|
+
},
|
|
537
|
+
// 提示
|
|
538
|
+
tooltip: {
|
|
539
|
+
show: chartsOptions.tooltipShow,
|
|
540
|
+
trigger: chartsOptions.tooltipTrigger,
|
|
541
|
+
formatter: (params) => {
|
|
542
|
+
const { marker, seriesName, name, value, percent, data } = params || {}
|
|
543
|
+
return useVariablesInText(
|
|
544
|
+
chartsOptions.tooltipFormatter,
|
|
545
|
+
{
|
|
546
|
+
textData: {
|
|
547
|
+
marker,
|
|
548
|
+
name,
|
|
549
|
+
value,
|
|
550
|
+
percent,
|
|
551
|
+
a: seriesName,
|
|
552
|
+
b: name,
|
|
553
|
+
c: value,
|
|
554
|
+
d: percent,
|
|
555
|
+
...data
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
useNewline: true,
|
|
560
|
+
useSpace: true
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
},
|
|
564
|
+
textStyle: {
|
|
565
|
+
color: chartsOptions.tooltipTextStyleColor || '#333'
|
|
566
|
+
},
|
|
567
|
+
backgroundColor: chartsOptions.tooltipBackgroundColor || '#fff',
|
|
568
|
+
borderColor: chartsOptions.tooltipBorderColor || '#eee'
|
|
569
|
+
},
|
|
570
|
+
// 图例
|
|
571
|
+
legend: {
|
|
572
|
+
show: chartsOptions.legendShow,
|
|
573
|
+
orient: chartsOptions.legendOrient,
|
|
574
|
+
top: chartsOptions.legendTop,
|
|
575
|
+
left: chartsOptions.legendLeft,
|
|
576
|
+
textStyle: {
|
|
577
|
+
color: chartsOptions.legendTextStyleColor,
|
|
578
|
+
fontSize: fontSize === 18 ? fontSize : chartsOptions.labelFontSize
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
series: [
|
|
582
|
+
{
|
|
583
|
+
data,
|
|
584
|
+
type: 'pie',
|
|
585
|
+
radius: [chartsOptions.innerRadius, chartsOptions.outerRadius],
|
|
586
|
+
center: [chartsOptions.centerLeft, chartsOptions.centerTop],
|
|
587
|
+
roseType: chartsOptions.roseType,
|
|
588
|
+
avoidLabelOverlap: false,
|
|
589
|
+
minAngle: chartsOptions.minAngle,
|
|
590
|
+
label: {
|
|
591
|
+
show: chartsOptions.labelPosition !== 'center' && chartsOptions.labelShow,
|
|
592
|
+
color: chartsOptions.labelColor,
|
|
593
|
+
fontSize: fontSize === 18 ? fontSize : chartsOptions.labelFontSize,
|
|
594
|
+
position: chartsOptions.labelPosition,
|
|
595
|
+
formatter: handleFormatter(chartsOptions.labelFormatter)
|
|
596
|
+
},
|
|
597
|
+
labelLine: {
|
|
598
|
+
show: chartsOptions.labelLineShow,
|
|
599
|
+
length: chartsOptions.labelLineLength,
|
|
600
|
+
length2: chartsOptions.labelLineLength2
|
|
601
|
+
},
|
|
602
|
+
emphasis: {
|
|
603
|
+
itemStyle: {
|
|
604
|
+
shadowBlur: 10,
|
|
605
|
+
shadowOffsetX: 0,
|
|
606
|
+
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
|
607
|
+
},
|
|
608
|
+
label: {}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
]
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const getComboGraphTransformProps = (chartsOptions, chartData, fontSize) => {
|
|
616
|
+
const { dimensions = [], dataset = [] } = chartData
|
|
617
|
+
const xAxisData = computed(() => {
|
|
618
|
+
return dimensions.map((item) => {
|
|
619
|
+
let result = {}
|
|
620
|
+
if (item && typeof item === 'object') {
|
|
621
|
+
result = {
|
|
622
|
+
...item,
|
|
623
|
+
textStyle: {
|
|
624
|
+
fontSize: fontSize
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
result = {
|
|
629
|
+
value: item,
|
|
630
|
+
textStyle: {
|
|
631
|
+
fontSize: fontSize
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return result
|
|
636
|
+
})
|
|
637
|
+
})
|
|
638
|
+
const series = computed(() => {
|
|
639
|
+
const temp = [] as { [key: string]: any }[]
|
|
640
|
+
const len = dataset.length
|
|
641
|
+
const seriesTypes = chartsOptions.seriesTypes
|
|
642
|
+
for (let i = 0; i < len; i++) {
|
|
643
|
+
const seriesType = seriesTypes[i]
|
|
644
|
+
const { type, axisIndex } = seriesType || {}
|
|
645
|
+
let series = {
|
|
646
|
+
type: type,
|
|
647
|
+
yAxisIndex: axisIndex,
|
|
648
|
+
...dataset[i]
|
|
649
|
+
} as { [key: string]: any }
|
|
650
|
+
if (type === 'line') {
|
|
651
|
+
const shadowStyle: any = {}
|
|
652
|
+
if (chartsOptions.shadowColor) {
|
|
653
|
+
shadowStyle.shadowColor = chartsOptions.shadowColor
|
|
654
|
+
shadowStyle.shadowBlur = chartsOptions.shadowBlur
|
|
655
|
+
shadowStyle.shadowOffsetY = chartsOptions.shadowOffsetY
|
|
656
|
+
shadowStyle.shadowOffsetX = chartsOptions.shadowOffsetX
|
|
657
|
+
}
|
|
658
|
+
series = {
|
|
659
|
+
...series,
|
|
660
|
+
symbolSize: chartsOptions.symbolSize,
|
|
661
|
+
smooth: chartsOptions.smooth,
|
|
662
|
+
itemStyle: {
|
|
663
|
+
color: chartsOptions.colors[i]
|
|
664
|
+
},
|
|
665
|
+
areaStyle: {
|
|
666
|
+
color: chartsOptions.areaGradientShow
|
|
667
|
+
? {
|
|
668
|
+
type: 'linear',
|
|
669
|
+
x: 0,
|
|
670
|
+
y: 0,
|
|
671
|
+
x2: 0,
|
|
672
|
+
y2: 1,
|
|
673
|
+
colorStops: [{
|
|
674
|
+
offset: 0,
|
|
675
|
+
color: chartsOptions.colors[i]
|
|
676
|
+
}, {
|
|
677
|
+
offset: 1,
|
|
678
|
+
color: chartsOptions.areaGradientColor || 'transparent'
|
|
679
|
+
}],
|
|
680
|
+
global: false
|
|
681
|
+
}
|
|
682
|
+
: chartsOptions.colors[i],
|
|
683
|
+
opacity: chartsOptions.areaStyleOpacity
|
|
684
|
+
},
|
|
685
|
+
lineStyle: {
|
|
686
|
+
width: chartsOptions.lineStyleWidth,
|
|
687
|
+
...shadowStyle
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (type === 'bar') {
|
|
692
|
+
const { gradientShow, gradientColors, gradientOffset } = chartsOptions
|
|
693
|
+
const itemStyle: any = {}
|
|
694
|
+
if (chartsOptions.barBorderRadius) {
|
|
695
|
+
const radius = chartsOptions.barBorderRadius.split(',')
|
|
696
|
+
if (radius?.length) {
|
|
697
|
+
const radiusItems: any = []
|
|
698
|
+
for (const rs of radius) {
|
|
699
|
+
const value = parseFloat(rs)
|
|
700
|
+
if (!isNaN(value)) {
|
|
701
|
+
radiusItems.push(value)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
itemStyle.borderRadius = radiusItems
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (gradientShow) {
|
|
708
|
+
itemStyle.color = {
|
|
709
|
+
x: 0,
|
|
710
|
+
y: 0,
|
|
711
|
+
x2: 0,
|
|
712
|
+
y2: 1,
|
|
713
|
+
colorStops: [{
|
|
714
|
+
offset: 0,
|
|
715
|
+
color: chartsOptions.colors[i]
|
|
716
|
+
}, {
|
|
717
|
+
offset: gradientOffset,
|
|
718
|
+
color: gradientColors[i]
|
|
719
|
+
}, {
|
|
720
|
+
offset: 1,
|
|
721
|
+
color: gradientColors[i]
|
|
722
|
+
}]
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
series = {
|
|
726
|
+
...series,
|
|
727
|
+
barWidth: chartsOptions.barWidth,
|
|
728
|
+
itemStyle
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (chartsOptions.isShowMarkLine) {
|
|
732
|
+
series.markLine = {
|
|
733
|
+
data: [{ type: chartsOptions.markLineType }]
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
temp.push(series)
|
|
737
|
+
}
|
|
738
|
+
return temp
|
|
739
|
+
})
|
|
740
|
+
const yAxis = computed(() => {
|
|
741
|
+
const yAxis = chartsOptions.yAxis
|
|
742
|
+
return yAxis?.map((axis, index) => {
|
|
743
|
+
return {
|
|
744
|
+
type: 'value',
|
|
745
|
+
minInterval: chartsOptions.yAxisMinInterval,
|
|
746
|
+
splitLine: {
|
|
747
|
+
show: index === 0 ? chartsOptions.yAxisLeftSplitLineShow : chartsOptions.yAxisRightSplitLineShow,
|
|
748
|
+
lineStyle: {
|
|
749
|
+
color: chartsOptions.yAxisSplitLineStyleColor,
|
|
750
|
+
type: index === 0 ? chartsOptions.yAxisLeftSplitLineType : chartsOptions.yAxisRightSplitLineType
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
splitArea: {
|
|
754
|
+
show: chartsOptions.yAxisSplitAreaShow
|
|
755
|
+
},
|
|
756
|
+
axisLabel: {
|
|
757
|
+
fontSize: fontSize,
|
|
758
|
+
show: chartsOptions.yAxisLabelShow,
|
|
759
|
+
color: chartsOptions.yAxisLabelColor,
|
|
760
|
+
formatter (value: string) {
|
|
761
|
+
return useValueFormatter(axis.axisLabelFormatter, value)
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
axisLine: {
|
|
765
|
+
show: chartsOptions.yAxisLineAlwaysDisplay,
|
|
766
|
+
lineStyle: {
|
|
767
|
+
color: chartsOptions.yAxisLineStyleColor
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
name: index === 0 ? chartsOptions.yAxisLeftName : chartsOptions.yAxisRightName,
|
|
771
|
+
nameTextStyle: {
|
|
772
|
+
fontSize: chartsOptions.yAxisLabelFontSize,
|
|
773
|
+
color: chartsOptions.yAxisLabelColor,
|
|
774
|
+
align: index === 0 ? 'right' : 'left'
|
|
775
|
+
},
|
|
776
|
+
max: chartsOptions.yAxisMaxValue || null
|
|
777
|
+
}
|
|
778
|
+
})
|
|
779
|
+
})
|
|
780
|
+
return {
|
|
781
|
+
legend: {
|
|
782
|
+
show: chartsOptions.legendShow,
|
|
783
|
+
orient: chartsOptions.legendOrient,
|
|
784
|
+
top: chartsOptions.legendTop,
|
|
785
|
+
left: chartsOptions.legendLeft,
|
|
786
|
+
textStyle: {
|
|
787
|
+
color: chartsOptions.legendTextStyleColor,
|
|
788
|
+
fontSize: fontSize
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
tooltip: {
|
|
792
|
+
trigger: 'axis',
|
|
793
|
+
show: chartsOptions.tooltipShow,
|
|
794
|
+
formatter: (params) => {
|
|
795
|
+
const len = params.length
|
|
796
|
+
let formatter = ''
|
|
797
|
+
let tooltipFormatter = chartsOptions.tooltipFormatter
|
|
798
|
+
if (tooltipFormatter === '') {
|
|
799
|
+
tooltipFormatter = '{marker} {a} {c}'
|
|
800
|
+
}
|
|
801
|
+
const seriesTypes = chartsOptions.seriesTypes
|
|
802
|
+
for (let i = 0; i < len; i++) {
|
|
803
|
+
const seriesType = seriesTypes[i]
|
|
804
|
+
const { tooltipFormatter: _tooltipFormatter } = seriesType || {}
|
|
805
|
+
const { marker, seriesName, name, value, data } = params[i] || {}
|
|
806
|
+
if (i === 0) {
|
|
807
|
+
formatter += `${name}<br/>`
|
|
808
|
+
}
|
|
809
|
+
formatter += useVariablesInText(
|
|
810
|
+
// 如果系列有提示框组件就使用自定义,没有就用默认的
|
|
811
|
+
_tooltipFormatter || tooltipFormatter,
|
|
812
|
+
{
|
|
813
|
+
textData: {
|
|
814
|
+
marker,
|
|
815
|
+
name,
|
|
816
|
+
value,
|
|
817
|
+
seriesName,
|
|
818
|
+
a: seriesName,
|
|
819
|
+
b: name,
|
|
820
|
+
c: value,
|
|
821
|
+
...data
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
useNewline: true,
|
|
826
|
+
useSpace: true
|
|
827
|
+
}
|
|
828
|
+
)
|
|
829
|
+
formatter += '<br/>'
|
|
830
|
+
}
|
|
831
|
+
return formatter
|
|
832
|
+
},
|
|
833
|
+
textStyle: {
|
|
834
|
+
color: chartsOptions.tooltipTextStyleColor || '#333',
|
|
835
|
+
fontSize: fontSize
|
|
836
|
+
},
|
|
837
|
+
backgroundColor: chartsOptions.tooltipBackgroundColor || '#fff',
|
|
838
|
+
borderColor: chartsOptions.tooltipBorderColor || '#eee'
|
|
839
|
+
},
|
|
840
|
+
xAxis: {
|
|
841
|
+
name: chartsOptions.xAxisName,
|
|
842
|
+
minInterval: chartsOptions.xAxisMinInterval,
|
|
843
|
+
type: 'category',
|
|
844
|
+
data: unref(xAxisData),
|
|
845
|
+
splitLine: {
|
|
846
|
+
show: chartsOptions.xAxisSplitLineShow,
|
|
847
|
+
lineStyle: {
|
|
848
|
+
color: chartsOptions.xAxisSplitLineStyleColor
|
|
849
|
+
}
|
|
850
|
+
},
|
|
851
|
+
axisLabel: {
|
|
852
|
+
color: chartsOptions.xAxisLabelColor,
|
|
853
|
+
interval: chartsOptions.xAxisLabelInterval || 0,
|
|
854
|
+
rotate: chartsOptions.xAxisLabelRotate,
|
|
855
|
+
width: chartsOptions.xAxisLabelWidth,
|
|
856
|
+
overflow: chartsOptions.xAxisLabelOverflow
|
|
857
|
+
},
|
|
858
|
+
axisLine: {
|
|
859
|
+
lineStyle: {
|
|
860
|
+
color: chartsOptions.xAxisLineStyleColor
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
axisTick: {
|
|
864
|
+
show: chartsOptions.xAxisTickShow
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
yAxis: unref(yAxis),
|
|
868
|
+
series: unref(series)
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const getCommonTransformProps = (chartsOptions) => {
|
|
873
|
+
return {
|
|
874
|
+
title: {
|
|
875
|
+
text: chartsOptions.titleText,
|
|
876
|
+
subtext: chartsOptions.titleSubtext,
|
|
877
|
+
textStyle: {
|
|
878
|
+
fontSize: chartsOptions.titleFontSize,
|
|
879
|
+
fontWeight: chartsOptions.fontWeight,
|
|
880
|
+
color: chartsOptions.titleColor
|
|
881
|
+
},
|
|
882
|
+
left: chartsOptions.textAlign || 'center'
|
|
883
|
+
},
|
|
884
|
+
grid: {
|
|
885
|
+
top: chartsOptions.gridTop,
|
|
886
|
+
bottom: chartsOptions.gridBottom,
|
|
887
|
+
left: chartsOptions.gridLeft,
|
|
888
|
+
right: chartsOptions.gridRight,
|
|
889
|
+
containLabel: chartsOptions.gridContainLabel
|
|
890
|
+
},
|
|
891
|
+
color: chartsOptions.colors
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const transformProps = (chartsOptions, chartData, fontSize = 12) => {
|
|
896
|
+
return {
|
|
897
|
+
...getCommonTransformProps(chartsOptions),
|
|
898
|
+
...getTransformProps(chartsOptions, chartData, fontSize)
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
export default transformProps
|