@ecan-bi/tools 1.0.63 → 1.0.65

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.
@@ -0,0 +1,409 @@
1
+ import { computed, unref, ref } from 'vue'
2
+ import useVariablesInText from '../../hooks/useVariablesInText'
3
+ import useValueFormatter from '../../hooks/useValueFormatter'
4
+ import { getLegendFormat } from '../util'
5
+ function getUnitName(type: number) {
6
+ let result = ''
7
+ switch (type) {
8
+ case 1:
9
+ result = '万'
10
+ break
11
+ case 3:
12
+ result = '百万'
13
+ break
14
+ case 4:
15
+ result = '千万'
16
+ break
17
+ default:
18
+ break
19
+ }
20
+ return result
21
+ }
22
+
23
+ export default function getComboGraphTransformProps(props, chartData, fontSize, callBackMethodMap) {
24
+ const dimensions = ref(chartData.dimensions)
25
+ const dataSource = ref(chartData.dataset)
26
+ const dataset = chartData.dataset
27
+ const doAdapt = (type: number) => {
28
+ const datas = []
29
+ let result = 0
30
+ props.seriesTypes.forEach((v: any, i: number) => {
31
+ if (v.axisIndex === type && unref(dataSource)[i]?.data?.length) {
32
+ datas.push(...unref(dataSource)[i].data.map((d: any) => +d.value))
33
+ }
34
+ })
35
+ if (datas.some((v) => v >= 10000000)) {
36
+ result = 4
37
+ } else if (datas.some((v) => v >= 1000000)) {
38
+ result = 3
39
+ } else if (datas.some((v) => v >= 10000)) {
40
+ result = 1
41
+ }
42
+ return result
43
+ }
44
+ // y轴单位适配类型,正常显示=0,万级数据=1,百万级数据=3,千万级数据=4
45
+ const yUnitType = ref([0, 0])
46
+ // 处理单位适配
47
+ const handleUnitAdapt = () => {
48
+ yUnitType.value[0] = props.yAxisLeftUnitAdapt ? doAdapt(0) : 0
49
+ yUnitType.value[1] = props.yAxisRightUnitAdapt ? doAdapt(1) : 0
50
+ }
51
+ function getTemp(dataset: any) {
52
+ const temp = [] as { [key: string]: any }[]
53
+ const len = dataset.length
54
+ const seriesTypes = props.seriesTypes
55
+ for (let i = 0; i < len; i++) {
56
+ const seriesType = seriesTypes[i]
57
+ const { type, axisIndex } = seriesType || {}
58
+ let series = {
59
+ type: type,
60
+ yAxisIndex: axisIndex,
61
+ ...dataset[i]
62
+ } as { [key: string]: any }
63
+ let gcolor = props.colors[i]
64
+ if (!gcolor && props.colors.length) {
65
+ const colorIndex = ((i + 1) % props.colors.length) - 1
66
+ gcolor = colorIndex > 0 ? props.colors[colorIndex] : props.colors[0]
67
+ }
68
+ if (!gcolor) {
69
+ gcolor = '#5470C6'
70
+ }
71
+ if (type === 'line') {
72
+ const shadowStyle: any = {}
73
+ if (props.shadowColor) {
74
+ shadowStyle.shadowColor = props.shadowColor
75
+ shadowStyle.shadowBlur = props.shadowBlur
76
+ shadowStyle.shadowOffsetY = props.shadowOffsetY
77
+ shadowStyle.shadowOffsetX = props.shadowOffsetX
78
+ }
79
+ series = {
80
+ ...series,
81
+ symbolSize: props.symbolSize,
82
+ smooth: props.smooth,
83
+ itemStyle: {
84
+ color: gcolor
85
+ },
86
+ areaStyle: {
87
+ color: props.areaGradientShow
88
+ ? {
89
+ type: 'linear',
90
+ x: 0,
91
+ y: 0,
92
+ x2: 0,
93
+ y2: 1,
94
+ colorStops: [
95
+ {
96
+ offset: 0,
97
+ color: gcolor
98
+ },
99
+ {
100
+ offset: 1,
101
+ color: props.areaGradientColor || 'transparent'
102
+ }
103
+ ],
104
+ global: false
105
+ }
106
+ : gcolor,
107
+ opacity: props.areaStyleOpacity
108
+ },
109
+ lineStyle: {
110
+ width: props.lineStyleWidth,
111
+ ...shadowStyle
112
+ }
113
+ }
114
+ }
115
+ if (type === 'bar') {
116
+ const { gradientShow, gradientColors, gradientOffset } = props
117
+ const itemStyle: any = {
118
+ color: gcolor
119
+ }
120
+ if (props.barBorderRadius) {
121
+ const radius = props.barBorderRadius.split(',')
122
+ if (radius?.length) {
123
+ const radiusItems = []
124
+ for (const rs of radius) {
125
+ const value = parseFloat(rs)
126
+ if (!isNaN(value)) {
127
+ radiusItems.push(value)
128
+ }
129
+ }
130
+ itemStyle.borderRadius = radiusItems
131
+ }
132
+ }
133
+ if (gradientShow) {
134
+ itemStyle.color = {
135
+ x: 0,
136
+ y: 0,
137
+ x2: 0,
138
+ y2: 1,
139
+ colorStops: [
140
+ {
141
+ offset: 0,
142
+ color: gcolor
143
+ },
144
+ {
145
+ offset: gradientOffset,
146
+ color: gradientColors[i]
147
+ },
148
+ {
149
+ offset: 1,
150
+ color: gradientColors[i]
151
+ }
152
+ ]
153
+ }
154
+ }
155
+ series = {
156
+ ...series,
157
+ barWidth: props.barWidth.value + props.barWidth.suffix,
158
+ itemStyle,
159
+ label: {
160
+ show: props.labelShow,
161
+ fontSize: props.labelFontSize,
162
+ position: props.labelPosition,
163
+ color: props.labelColor,
164
+ width: props.labelWidth,
165
+ overflow: props.labelOverflow,
166
+ formatter: (params) => {
167
+ let formatter = ''
168
+ let labelFormatter = props.labelFormatter
169
+ if (labelFormatter === '') {
170
+ labelFormatter = '{c}'
171
+ }
172
+ const { seriesName, name, value, data } = params || {}
173
+ formatter += useVariablesInText(
174
+ labelFormatter,
175
+ {
176
+ textData: {
177
+ name,
178
+ value,
179
+ a: seriesName,
180
+ b: name,
181
+ c: value || 0,
182
+ ...data
183
+ }
184
+ },
185
+ {
186
+ useNewline: true,
187
+ useSpace: true
188
+ }
189
+ )
190
+ return formatter
191
+ }
192
+ }
193
+ }
194
+ }
195
+ if (props.isShowMarkLine) {
196
+ series.markLine = {
197
+ data: [{ type: props.markLineType }]
198
+ }
199
+ }
200
+ temp.push(series)
201
+ }
202
+ return temp
203
+ }
204
+ const yAxis = computed(() => {
205
+ const yAxis = props.yAxis
206
+ return yAxis?.map((axis, index) => {
207
+ const unitType = yUnitType.value[index]
208
+ let unitValue: number
209
+ if (unitType) {
210
+ unitValue = 10000 * Math.pow(10, unitType - 1)
211
+ }
212
+ return {
213
+ type: 'value',
214
+ minInterval: props.yAxisMinInterval,
215
+ splitLine: {
216
+ show: index === 0 ? props.yAxisLeftSplitLineShow : props.yAxisRightSplitLineShow,
217
+ lineStyle: {
218
+ color: props.yAxisSplitLineStyleColor,
219
+ type: index === 0 ? props.yAxisLeftSplitLineType : props.yAxisRightSplitLineType
220
+ }
221
+ },
222
+ splitArea: {
223
+ show: props.yAxisSplitAreaShow
224
+ },
225
+ axisLabel: {
226
+ show: props.yAxisLabelShow,
227
+ fontSize: props.yAxisLabelFontSize,
228
+ color: props.yAxisLabelColor,
229
+ formatter(value: string) {
230
+ let val = value
231
+ if (unitValue) {
232
+ val = (+value / unitValue).toString()
233
+ }
234
+ return useValueFormatter(axis.axisLabelFormatter, val)
235
+ }
236
+ },
237
+ axisLine: {
238
+ show: props.yAxisLineAlwaysDisplay,
239
+ lineStyle: {
240
+ color: props.yAxisLineStyleColor
241
+ }
242
+ },
243
+ name: getUnitName(unitType) + (index === 0 ? props.yAxisLeftName : props.yAxisRightName),
244
+ nameTextStyle: {
245
+ fontSize: props.yAxisLabelFontSize,
246
+ color: props.yAxisLabelColor,
247
+ align: index === 0 ? 'right' : 'left'
248
+ },
249
+ max: props.yAxisMaxValue || null
250
+ }
251
+ })
252
+ })
253
+ handleUnitAdapt()
254
+ const option = {
255
+ legend: {
256
+ type: props.legendScroll ? 'scroll' : 'plain',
257
+ width: props.legendWidth,
258
+ height: props.legendHeight,
259
+ show: props.legendShow,
260
+ orient: props.legendOrient,
261
+ top: props.legendTop,
262
+ left: props.legendLeft,
263
+ textStyle: {
264
+ lineHeight: parseFloat(props.legendFontSize) + 8,
265
+ rich: {
266
+ text: {
267
+ width: props.legendTextWidth,
268
+ color: props.legendTextStyleColor,
269
+ fontSize: props.legendFontSize
270
+ }
271
+ }
272
+ },
273
+ itemHeight: props.legendItemHeight,
274
+ itemWidth: props.legendItemWidth,
275
+ itemGap: props.legendItemGap,
276
+ data: unref(dataSource).map((value, index) => {
277
+ return {
278
+ name: value.name,
279
+ itemStyle: {
280
+ color: props.colors[index]
281
+ },
282
+ icon: props.legendType
283
+ }
284
+ }),
285
+ formatter: (name: string) => {
286
+ return getLegendFormat(props.legendFormatter, {
287
+ name
288
+ })
289
+ }
290
+ },
291
+ tooltip: {
292
+ trigger: 'axis',
293
+ show: props.tooltipShow,
294
+ formatter: (params) => {
295
+ const len = params.length
296
+ let formatter = ''
297
+ let tooltipFormatter = props.tooltipFormatter
298
+ if (callBackMethodMap?.getCurrentData) {
299
+ // currentData = params[0]?.data
300
+ callBackMethodMap.getCurrentData(params[0]?.data)
301
+ }
302
+ if (tooltipFormatter === '') {
303
+ tooltipFormatter = '{marker} {a} {c}'
304
+ }
305
+ const seriesTypes = props.seriesTypes
306
+ for (let i = 0; i < len; i++) {
307
+ const seriesType = seriesTypes[i]
308
+ const { tooltipFormatter: _tooltipFormatter } = seriesType || {}
309
+ const { marker, seriesName, name, value, data } = params[i] || {}
310
+ if (i === 0) {
311
+ let formatName = name
312
+ if (typeof name === 'string' && name[0] === '0' && !isNaN(+name)) {
313
+ formatName = (+name).toString()
314
+ }
315
+ formatter += `${useValueFormatter(props.xAxisLabelFormatter, formatName)}<br/>`
316
+ }
317
+ formatter += useVariablesInText(
318
+ // 如果系列有提示框组件就使用自定义,没有就用默认的
319
+ _tooltipFormatter || tooltipFormatter,
320
+ {
321
+ textData: {
322
+ marker,
323
+ name,
324
+ value,
325
+ seriesName,
326
+ a: seriesName,
327
+ b: name,
328
+ c: value || 0,
329
+ ...data
330
+ }
331
+ },
332
+ {
333
+ useNewline: true,
334
+ useSpace: true
335
+ }
336
+ )
337
+ formatter += '<br/>'
338
+ }
339
+ return formatter
340
+ },
341
+ textStyle: {
342
+ color: props.tooltipTextStyleColor,
343
+ fontSize: fontSize.value
344
+ },
345
+ position: props.tooltipPosition || undefined
346
+ },
347
+ xAxis: {
348
+ minInterval: props.xAxisMinInterval,
349
+ type: 'category',
350
+ data: unref(dimensions).map((item) => {
351
+ let result = {}
352
+ if (item && typeof item === 'object') {
353
+ result = {
354
+ ...item
355
+ }
356
+ } else {
357
+ result = {
358
+ value: item
359
+ }
360
+ }
361
+ return result
362
+ }),
363
+ splitLine: {
364
+ show: props.xAxisSplitLineShow,
365
+ lineStyle: {
366
+ color: props.xAxisSplitLineStyleColor
367
+ },
368
+ interval: props.xAxisSplitLineInterval
369
+ },
370
+ splitArea: {
371
+ show: props.xAxisSplitAreaShow
372
+ },
373
+ axisLabel: {
374
+ show: props.xAxisLabelShow,
375
+ color: props.xAxisLabelColor,
376
+ interval: props.xAxisLabelInterval || 0,
377
+ rotate: props.xAxisLabelRotate,
378
+ width: props.xAxisLabelWidth,
379
+ overflow: props.xAxisLabelOverflow,
380
+ fontSize: props.xAxisLabelFontSize,
381
+ formatter(value: string) {
382
+ if (typeof value === 'string' && value[0] === '0' && !isNaN(+value)) {
383
+ value = (+value).toString()
384
+ }
385
+ return useValueFormatter(props.xAxisLabelFormatter, value)
386
+ }
387
+ },
388
+ axisLine: {
389
+ show: props.xAxisLineShow,
390
+ lineStyle: {
391
+ color: props.xAxisLineStyleColor
392
+ }
393
+ },
394
+ axisTick: {
395
+ show: props.xAxisTickShow
396
+ },
397
+ name: props.xAxisName,
398
+ nameTextStyle: {
399
+ fontSize: props.xAxisLabelFontSize,
400
+ color: props.xAxisLabelColor,
401
+ align: 'left'
402
+ },
403
+ max: props.xAxisMaxValue || null
404
+ },
405
+ yAxis: unref(yAxis),
406
+ series: getTemp(dataset)
407
+ }
408
+ return option
409
+ }
@@ -0,0 +1,76 @@
1
+ import { unref} from 'vue'
2
+ export default function getCommonTransformProps(props, fontFamily, callBackMethodMap) {
3
+ const options = {
4
+ textStyle: {
5
+ fontFamily: unref(fontFamily)
6
+ },
7
+ toolbox: {
8
+ show: props.toolboxShow,
9
+ left: props.toolboxLeft,
10
+ top: props.toolboxTop,
11
+ itemSize: props.toolboxItemSize,
12
+ itemGap: props.toolboxItemGap,
13
+ feature: {
14
+ myLocation: {
15
+ show: !!props.toolboxLocation,
16
+ title: '快速定位',
17
+ icon: 'path://M512 512m-80 0a80 80 0 1 0 160 0 80 80 0 1 0-160 0Z, M960 480h-33.632C910.752 276.16 747.84 113.248 544 97.632V64a32 32 0 1 0-64 0v33.632C276.16 113.248 113.248 276.16 97.632 480H64a32 32 0 0 0 0 64h33.632C113.248 747.84 276.16 910.752 480 926.368V960a32 32 0 1 0 64 0v-33.632C747.84 910.752 910.752 747.84 926.368 544H960a32 32 0 1 0 0-64zM544 862.368V800a32 32 0 1 0-64 0v62.368C311.424 847.104 176.896 712.576 161.632 544H224a32 32 0 1 0 0-64H161.632C176.896 311.424 311.424 176.896 480 161.632V224a32 32 0 0 0 64 0V161.632c168.576 15.296 303.104 149.792 318.368 318.368H800a32 32 0 1 0 0 64h62.368c-15.264 168.576-149.792 303.104-318.368 318.368z',
18
+ onclick() {
19
+ callBackMethodMap.toolboxLocationFun && callBackMethodMap.toolboxLocationFun(props)
20
+ }
21
+ },
22
+ myDownload: {
23
+ show: props.toolboxDownloadUrl && props.toolboxDownloadShow,
24
+ title: '数据下载',
25
+ icon: 'path://M502.010485 765.939573c3.773953 3.719718 8.686846 5.573949 13.596669 5.573949 0.075725 0 0.151449-0.010233 0.227174-0.011256 0.329505 0.016373 0.654916 0.050142 0.988514 0.050142 0.706081 0 1.400906-0.042979 2.087545-0.116657 4.352121-0.366344 8.607028-2.190899 11.961426-5.496178l335.053985-330.166675c7.619538-7.509021 7.709589-19.773346 0.200568-27.393907s-19.774369-7.711636-27.39493-0.201591L536.193005 706.304358 536.193005 50.019207c0-10.698666-8.67252-19.371186-19.371186-19.371186s-19.371186 8.67252-19.371186 19.371186l0 657.032164-306.881342-302.44838c-7.618515-7.509021-19.883863-7.419993-27.393907 0.199545-7.509021 7.619538-7.419993 19.884886 0.199545 27.393907L502.010485 765.939573z, M867.170139 711.020776c-10.698666 0-19.371186 8.67252-19.371186 19.371186l0 165.419494c0 13.054317-10.620895 23.675212-23.676236 23.675212L205.182103 919.486668c-13.054317 0-23.676236-10.620895-23.676236-23.675212L181.505867 730.391962c0-10.698666-8.67252-19.371186-19.371186-19.371186s-19.371186 8.67252-19.371186 19.371186l0 165.419494c0 34.416857 28.000728 62.416562 62.417585 62.416562l618.941638 0c34.417881 0 62.417585-27.999704 62.417585-62.416562L886.540302 730.391962C886.541325 719.693296 877.868805 711.020776 867.170139 711.020776z',
26
+ onclick() {
27
+ callBackMethodMap.toolboxDownloadShowFun && callBackMethodMap.toolboxDownloadShowFun(props)
28
+ }
29
+ },
30
+ myDataZoom: {
31
+ show: props.toolboxDataZoomShow,
32
+ title: '放大',
33
+ icon: 'path://M932.42 902.246667L792 761.793333A403.84 403.84 0 0 0 896 490.666667c0-223.86-181.473333-405.333333-405.333333-405.333334S85.333333 266.806667 85.333333 490.666667s181.473333 405.333333 405.333334 405.333333a403.84 403.84 0 0 0 271.126666-104l140.453334 140.453333a21.333333 21.333333 0 0 0 30.173333-30.173333zM128 490.666667c0-200.293333 162.373333-362.666667 362.666667-362.666667s362.666667 162.373333 362.666666 362.666667-162.373333 362.666667-362.666666 362.666666-362.666667-162.373333-362.666667-362.666666z m512 0a21.333333 21.333333 0 0 1-21.333333 21.333333H512v106.666667a21.333333 21.333333 0 0 1-42.666667 0V512H362.666667a21.333333 21.333333 0 0 1 0-42.666667h106.666666V362.666667a21.333333 21.333333 0 0 1 42.666667 0v106.666666h106.666667a21.333333 21.333333 0 0 1 21.333333 21.333334z',
34
+ onclick() {
35
+ callBackMethodMap.toolboxDataZoomShowFun && callBackMethodMap.toolboxDataZoomShowFun(props)
36
+ }
37
+ },
38
+ myInfo: {
39
+ show: props.toolboxInfoShow,
40
+ title: '详情',
41
+ icon: 'path://M512.50142 958.397886c-119.320573 0-231.499491-46.465265-315.871087-130.837884C112.258737 743.188406 65.792449 631.010511 65.792449 511.688915c0-119.319549 46.466288-231.499491 130.837884-315.871087C281.002952 111.445208 393.180847 64.979944 512.50142 64.979944s231.499491 46.465265 315.871087 130.837884c84.372619 84.372619 130.837884 196.551538 130.837884 315.871087 0 119.321596-46.465265 231.499491-130.837884 315.871087C744.000911 911.932622 631.821993 958.397886 512.50142 958.397886zM512.50142 105.962334c-223.718271 0-405.726581 182.00831-405.726581 405.726581s182.00831 405.726581 405.726581 405.726581c223.718271 0 405.727605-182.00831 405.727605-405.726581S736.220714 105.962334 512.50142 105.962334z M510.150886 775.953647c-18.107403 0-32.745798-14.678304-32.745798-32.785707L477.405087 452.191846c0-18.108426 14.638395-32.785707 32.745798-32.785707 18.107403 0 32.745798 14.678304 32.745798 32.785707l0 290.976094C542.896684 761.275343 528.258289 775.953647 510.150886 775.953647z M511.357364 296.458969m-45.080731 0a44.054 44.054 0 1 0 90.161463 0 44.054 44.054 0 1 0-90.161463 0Z',
42
+ onclick() {
43
+ callBackMethodMap.toolboxInfoShowFun && callBackMethodMap.toolboxInfoShowFun(props)
44
+ }
45
+ },
46
+ mySource: {
47
+ show: props.toolboxInfoSource,
48
+ title: '指标来源',
49
+ icon: 'path://M473 71a8 8 0 0 1 8-8h64a8 8 0 0 1 8 8v77.161C722.848 166.622 857.812 301.289 876.729 471H952a8 8 0 0 1 8 8v64a8 8 0 0 1-8 8h-75.053C858.871 721.652 723.515 857.305 553 875.839V951a8 8 0 0 1-8 8h-64a8 8 0 0 1-8-8v-75.161C302.818 857.341 167.659 722.182 149.161 552H72a8 8 0 0 1-8-8v-64a8 8 0 0 1 8-8h77.161C167.659 301.818 302.818 166.659 473 148.161V71z m326 441c0-157.953-128.047-286-286-286S227 354.047 227 512s128.047 286 286 286 286-128.047 286-286z m-286 60c33.137 0 60-26.863 60-60s-26.863-60-60-60-60 26.863-60 60 26.863 60 60 60z',
50
+ onclick () {
51
+ callBackMethodMap.toolboxSourceShowFun && callBackMethodMap.toolboxSourceShowFun(props)
52
+ }
53
+ }
54
+ }
55
+ },
56
+ title: {
57
+ text: props.titleText,
58
+ subtext: props.titleSubtext,
59
+ textStyle: {
60
+ fontSize: props.titleFontSize,
61
+ fontWeight: props.fontWeight,
62
+ color: props.titleColor
63
+ },
64
+ left: props.textAlign
65
+ },
66
+ grid: {
67
+ top: props.gridTop,
68
+ bottom: props.gridBottom,
69
+ left: props.gridLeft,
70
+ right: props.gridRight,
71
+ containLabel: props.gridContainLabel
72
+ },
73
+ color: props.colors
74
+ }
75
+ return options
76
+ }