@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,260 @@
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 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
+ export default function getLineTransformProps (props, chartData, fontSize, callBackMethodMap){
17
+ const yAxisLabelFormatter = props.yAxisLabelFormatter
18
+ const xAxisLabelFormatter = props.xAxisLabelFormatter
19
+ const dataSource = ref(chartData.dataset)
20
+ const dimensions = ref(chartData.dimensions)
21
+ const dataset = chartData.dataset
22
+ const series = computed(() => {
23
+ const temp = [] as { [key: string]: any }[]
24
+ const len = dataset.length
25
+ for (let i = 0; i < len; i++) {
26
+ const shadowStyle: any = {}
27
+ if (props.shadowColor) {
28
+ shadowStyle.shadowColor = props.shadowColor
29
+ shadowStyle.shadowBlur = props.shadowBlur
30
+ shadowStyle.shadowOffsetY = props.shadowOffsetY
31
+ shadowStyle.shadowOffsetX = props.shadowOffsetX
32
+ }
33
+ let gcolor = props.colors[i]
34
+ if (!gcolor && props.colors.length) {
35
+ const colorIndex = (i + 1) % props.colors.length - 1
36
+ gcolor = colorIndex > 0 ? props.colors[colorIndex] : props.colors[0]
37
+ }
38
+ if (!gcolor) {
39
+ gcolor = '#5470C6'
40
+ }
41
+ temp.push({
42
+ type: 'line',
43
+ ...dataset[i],
44
+ symbolSize: props.symbolSize,
45
+ smooth: props.smooth,
46
+ areaStyle: {
47
+ color: props.areaGradientShow
48
+ ? {
49
+ type: 'linear',
50
+ x: 0,
51
+ y: 0,
52
+ x2: 0,
53
+ y2: 1,
54
+ colorStops: [
55
+ {
56
+ offset: 0,
57
+ color: gcolor
58
+ },
59
+ {
60
+ offset: 1,
61
+ color: props.areaGradientColor || 'transparent'
62
+ }
63
+ ],
64
+ global: false
65
+ }
66
+ : gcolor,
67
+ opacity: props.areaStyleOpacity
68
+ },
69
+ lineStyle: {
70
+ width: props.lineStyleWidth,
71
+ ...shadowStyle
72
+ },
73
+ ...getMarkLineData(props)
74
+ })
75
+ }
76
+ return temp
77
+ })
78
+ return {
79
+ tooltip: {
80
+ trigger: 'axis',
81
+ textStyle: {
82
+ fontSize: fontSize.value,
83
+ color: props.tooltipTextStyleColor
84
+ },
85
+ show: props.tooltipShow,
86
+ formatter: (params) => {
87
+ const len = params.length
88
+ let formatter = ''
89
+ let tooltipFormatter = props.tooltipFormatter
90
+ if (callBackMethodMap?.getCurrentData) {
91
+ // currentData = params[0]?.data
92
+ callBackMethodMap.getCurrentData(params[0]?.data)
93
+ }
94
+ if (tooltipFormatter === '') {
95
+ tooltipFormatter = '{marker} {a} {c}'
96
+ }
97
+ for (let i = 0; i < len; i++) {
98
+ const { marker, seriesName, name, value, data } = params[i] || {}
99
+ if (i === 0) {
100
+ let formatName = name
101
+ if (typeof name === 'string' && name[0] === '0' && !isNaN(+name)) {
102
+ formatName = (+name).toString()
103
+ }
104
+ formatter += `${useValueFormatter(xAxisLabelFormatter, formatName)}<br/>`
105
+ }
106
+ formatter += useVariablesInText(
107
+ tooltipFormatter,
108
+ {
109
+ textData: {
110
+ marker,
111
+ name,
112
+ value,
113
+ a: seriesName,
114
+ b: name,
115
+ c: value || 0,
116
+ ...data
117
+ }
118
+ },
119
+ {
120
+ useNewline: true,
121
+ useSpace: true
122
+ }
123
+ )
124
+ formatter += '<br/>'
125
+ }
126
+ return formatter
127
+ },
128
+ position: props.tooltipPosition || undefined
129
+ },
130
+ xAxis: {
131
+ type: 'category',
132
+ boundaryGap: props.isBoundaryGap,
133
+ data: unref(dimensions).map((item) => {
134
+ let result = {}
135
+ if (item && typeof item === 'object') {
136
+ result = {
137
+ ...item
138
+ }
139
+ } else {
140
+ result = {
141
+ value: item
142
+ }
143
+ }
144
+ return result
145
+ }),
146
+ minInterval: props.xAxisMinInterval,
147
+ splitLine: {
148
+ show: props.xAxisSplitLineShow,
149
+ lineStyle: {
150
+ color: props.xAxisSplitLineStyleColor
151
+ },
152
+ interval: props.xAxisSplitLineInterval
153
+ },
154
+ splitArea: {
155
+ show: props.xAxisSplitAreaShow
156
+ },
157
+ axisLabel: {
158
+ show: props.xAxisLabelShow,
159
+ color: props.xAxisLabelColor,
160
+ interval: props.xAxisLabelInterval || 0,
161
+ rotate: props.xAxisLabelRotate,
162
+ width: props.xAxisLabelWidth,
163
+ overflow: props.xAxisLabelOverflow,
164
+ fontSize: props.xAxisLabelFontSize,
165
+ formatter(value: string) {
166
+ if (typeof value === 'string' && value[0] === '0' && !isNaN(+value)) {
167
+ value = (+value).toString()
168
+ }
169
+ return useValueFormatter(xAxisLabelFormatter, value)
170
+ }
171
+ },
172
+ axisLine: {
173
+ show: props.xAxisLineShow,
174
+ lineStyle: {
175
+ color: props.xAxisLineStyleColor
176
+ }
177
+ },
178
+ axisTick: {
179
+ show: props.xAxisTickShow
180
+ },
181
+ name: props.xAxisName,
182
+ nameTextStyle: {
183
+ fontSize: props.xAxisLabelFontSize,
184
+ color: props.xAxisLabelColor,
185
+ align: 'left'
186
+ },
187
+ max: props.xAxisMaxValue || null
188
+ },
189
+ yAxis: {
190
+ type: 'value',
191
+ minInterval: props.yAxisMinInterval,
192
+ splitLine: {
193
+ show: props.yAxisSplitLineShow,
194
+ lineStyle: {
195
+ color: props.yAxisSplitLineStyleColor,
196
+ type: props.yAxisSplitLineType
197
+ }
198
+ },
199
+ splitArea: {
200
+ show: props.yAxisSplitAreaShow
201
+ },
202
+ axisLabel: {
203
+ show: props.yAxisLabelShow,
204
+ fontSize: props.yAxisLabelFontSize,
205
+ color: props.yAxisLabelColor,
206
+ formatter(value: string) {
207
+ return useValueFormatter(yAxisLabelFormatter, value)
208
+ }
209
+ },
210
+ axisLine: {
211
+ show: props.yAxisLineAlwaysDisplay,
212
+ lineStyle: {
213
+ color: props.yAxisLineStyleColor
214
+ }
215
+ },
216
+ name: props.yAxisName,
217
+ nameTextStyle: {
218
+ fontSize: props.yAxisLabelFontSize,
219
+ color: props.yAxisLabelColor,
220
+ align: 'right'
221
+ },
222
+ max: props.yAxisMaxValue || null
223
+ },
224
+ // 图例
225
+ legend: {
226
+ type: props.legendScroll ? 'scroll' : 'plain',
227
+ width: props.legendWidth,
228
+ height: props.legendHeight,
229
+ show: props.legendShow,
230
+ orient: props.legendOrient,
231
+ top: props.legendTop,
232
+ left: props.legendLeft,
233
+ textStyle: {
234
+ lineHeight: parseFloat(props.legendFontSize) + 8,
235
+ rich: {
236
+ text: {
237
+ width: props.legendTextWidth,
238
+ color: props.legendTextStyleColor,
239
+ fontSize: props.legendFontSize
240
+ }
241
+ }
242
+ },
243
+ itemHeight: props.legendItemHeight,
244
+ itemWidth: props.legendItemWidth,
245
+ itemGap: props.legendItemGap,
246
+ data: unref(dataSource).map((value) => {
247
+ return {
248
+ name: value.name,
249
+ icon: props.legendType
250
+ }
251
+ }),
252
+ formatter: (name: string) => {
253
+ return getLegendFormat(props.legendFormatter, {
254
+ name
255
+ })
256
+ }
257
+ },
258
+ series: unref(series)
259
+ }
260
+ }
@@ -0,0 +1,138 @@
1
+ import { unref, ref } from 'vue'
2
+ import { getLegendFormat, handleFormatter } from '../util'
3
+ import useVariablesInText from '../../hooks/useVariablesInText'
4
+ export default function getPieTransformProps(props, chartData, fontSize) {
5
+ const dataset = ref(chartData.dataset)
6
+ let { data = [] } = unref(dataset)[0] || {}
7
+ if (Array.isArray(props.colors)) {
8
+ const isUseLabelColors = props.isUseLabelColors
9
+ const colors = props.colors
10
+ data = data.map((item, index) => ({
11
+ label: isUseLabelColors ? { color: colors[index] } : {},
12
+ ...item
13
+ }))
14
+ }
15
+ return {
16
+ tooltip: {
17
+ show: props.tooltipShow,
18
+ trigger: props.tooltipTrigger,
19
+ formatter: (params) => {
20
+ const { marker, seriesName, name, value, percent, data } = params || {}
21
+ return useVariablesInText(
22
+ props.tooltipFormatter,
23
+ {
24
+ textData: {
25
+ marker,
26
+ name,
27
+ value,
28
+ percent,
29
+ a: seriesName,
30
+ b: name,
31
+ c: value,
32
+ d: percent,
33
+ ...data
34
+ }
35
+ },
36
+ {
37
+ useNewline: true,
38
+ useSpace: true
39
+ }
40
+ )
41
+ },
42
+ textStyle: {
43
+ color: props.tooltipTextStyleColor
44
+ },
45
+ position: props.tooltipPosition || undefined
46
+ },
47
+ // 图例
48
+ legend: {
49
+ type: props.legendScroll ? 'scroll' : 'plain',
50
+ width: props.legendWidth,
51
+ height: props.legendHeight,
52
+ show: props.legendShow,
53
+ orient: props.legendOrient,
54
+ top: props.legendTop,
55
+ left: props.legendLeft,
56
+ align: 'left',
57
+ textStyle: {
58
+ lineHeight: fontSize + 8,
59
+ rich: {
60
+ text: {
61
+ width: props.legendTextWidth,
62
+ color: props.legendTextStyleColor,
63
+ fontSize
64
+ }
65
+ }
66
+ },
67
+ itemHeight: props.legendItemHeight,
68
+ itemWidth: props.legendItemWidth,
69
+ itemGap: props.legendItemGap,
70
+ data: unref(dataset)[0]?.data?.map((value: any) => {
71
+ return {
72
+ name: value.name,
73
+ icon: props.legendType
74
+ }
75
+ }),
76
+ formatter: (name: string) => {
77
+ const { data } = dataset.value[0] || {}
78
+ let total = 0
79
+ let value: number
80
+ let percent = '0%'
81
+ if (data) {
82
+ for (const item of data) {
83
+ if (item.name === name) {
84
+ value = +item.value
85
+ }
86
+ total += +item.value
87
+ }
88
+ }
89
+ if (total) {
90
+ percent = `${((value / total) * 100).toFixed(2)}%`
91
+ }
92
+ return getLegendFormat(props.legendFormatter, {
93
+ name,
94
+ value,
95
+ percent
96
+ })
97
+ }
98
+ },
99
+ series: [
100
+ {
101
+ data,
102
+ type: 'pie',
103
+ radius: [props.innerRadius, props.outerRadius],
104
+ center: [props.centerLeft, props.centerTop],
105
+ roseType: props.roseType,
106
+ avoidLabelOverlap: true,
107
+ minAngle: props.minAngle,
108
+ // data: data.value,
109
+ // data: props.data,
110
+ // dimensions: ['name', 'count'],
111
+ label: {
112
+ show: props.labelPosition !== 'center' && props.labelShow,
113
+ color: props.labelColor,
114
+ fontSize: props.labelFontSize,
115
+ position: props.labelPosition,
116
+ formatter: handleFormatter(props.labelFormatter),
117
+ width: props.labelWidth,
118
+ overflow: props.labelOverflow
119
+ },
120
+ labelLine: {
121
+ show: props.labelLineShow,
122
+ length: props.labelLineLength,
123
+ length2: props.labelLineLength2
124
+ },
125
+ emphasis: {
126
+ itemStyle: {
127
+ shadowBlur: 10,
128
+ shadowOffsetX: 0,
129
+ shadowColor: 'rgba(0, 0, 0, 0.5)'
130
+ },
131
+ label: {
132
+ // show: props.labelPosition === 'center'
133
+ }
134
+ }
135
+ }
136
+ ]
137
+ }
138
+ }
@@ -0,0 +1,229 @@
1
+ import { unref, ref, computed } from 'vue'
2
+ import useVariablesInText from '../../hooks/useVariablesInText'
3
+ import { getLegendFormat } from '../util'
4
+
5
+ export default function getRadarTransformProps(props, chartData, fontSize) {
6
+
7
+ const dimensions = ref(chartData.dimensions)
8
+ const dataSource = ref(chartData.dataset)
9
+
10
+ const radarIndicator = computed(() => {
11
+ const result = []
12
+ // const map = {}
13
+ const valList = []
14
+ const ds = unref(dataSource)
15
+ const len = ds.length
16
+ for (let i = 0; i < len; i++) {
17
+ const { data = [] } = ds[i]
18
+ // if (data?.length) {
19
+ // for (let j = 0; j < data.length; j++) {
20
+ // if (map[data[j][fieldName.value]]) {
21
+ // map[data[j][fieldName.value]].push(data[j].value)
22
+ // } else {
23
+ // map[data[j][fieldName.value]] = [data[j].value]
24
+ // }
25
+ // }
26
+ // }
27
+ for (let j = 0; j < data.length; j++) {
28
+ valList.push(data[j].value)
29
+ }
30
+ }
31
+ if (dimensions.value?.length) {
32
+ const maxValue = valList?.length ? Math.max(...valList) * 1.2 : 0
33
+ for (const item of dimensions.value) {
34
+ result.push({
35
+ name: item,
36
+ max: maxValue
37
+ })
38
+ }
39
+ }
40
+ return result
41
+ })
42
+ const series = computed(() => {
43
+ const ds = unref(dataSource)
44
+ const len = ds.length
45
+ const series = []
46
+ for (let i = 0; i < len; i++) {
47
+ const { name, data = [] } = ds[i]
48
+ const radarData = [
49
+ {
50
+ name,
51
+ value: data.map((v: any) => v.value)
52
+ }
53
+ ]
54
+ let gcolor = props.colors[i]
55
+ if (!gcolor && props.colors.length) {
56
+ const colorIndex = ((i + 1) % props.colors.length) - 1
57
+ gcolor = colorIndex > 0 ? props.colors[colorIndex] : props.colors[0]
58
+ }
59
+ if (!gcolor) {
60
+ gcolor = '#5470C6'
61
+ }
62
+ let color: any = gcolor
63
+ if (props.gradientShow) {
64
+ const { gradientOffset, gradientColors } = props
65
+ color = {
66
+ x: 0.7,
67
+ y: 0,
68
+ x2: 0,
69
+ y2: 0,
70
+ colorStops: [
71
+ {
72
+ offset: 0,
73
+ color: gcolor
74
+ },
75
+ {
76
+ offset: gradientOffset,
77
+ color: gradientColors[i]
78
+ },
79
+ {
80
+ offset: 1,
81
+ color: gradientColors[i]
82
+ }
83
+ ]
84
+ }
85
+ }
86
+ const item = {
87
+ type: 'radar',
88
+ name,
89
+ data: radarData,
90
+ areaStyle: {
91
+ color,
92
+ opacity: props.areaStyleOpacity
93
+ },
94
+ tooltip: {
95
+ trigger: 'item'
96
+ },
97
+ symbolSize: props.symbolSize,
98
+ lineStyle: {
99
+ width: props.lineStyleWidth
100
+ },
101
+ label: {
102
+ show: props.labelShow,
103
+ fontSize: props.labelFontSize,
104
+ position: props.labelPosition,
105
+ color: props.labelColor,
106
+ width: props.labelWidth,
107
+ overflow: props.labelOverflow,
108
+ formatter: (params: any) => {
109
+ const { data, value } = params
110
+ let total = 0
111
+ let percent = '0%'
112
+ if (data) {
113
+ for (const item of data.value) {
114
+ total += +item
115
+ }
116
+ }
117
+ if (total) {
118
+ percent = `${((value / total) * 100).toFixed(2)}%`
119
+ }
120
+ return useVariablesInText(
121
+ props.labelFormatter,
122
+ {
123
+ textData: {
124
+ value,
125
+ percent
126
+ }
127
+ },
128
+ {
129
+ useNewline: false,
130
+ useSpace: false
131
+ }
132
+ )
133
+ }
134
+ }
135
+ } as { [key: string]: any }
136
+ series.push(item)
137
+ }
138
+ return series
139
+ })
140
+ const options = computed(() => ({
141
+ tooltip: {
142
+ trigger: 'axis',
143
+ textStyle: {
144
+ fontSize: fontSize.value
145
+ },
146
+ show: props.tooltipShow,
147
+ formatter: (params) => {
148
+ let formatter = ''
149
+ let tooltipFormatter = props.tooltipFormatter
150
+ if (tooltipFormatter === '') {
151
+ tooltipFormatter = '{marker} {a} {c}'
152
+ }
153
+ for (let i = 0; i < unref(radarIndicator).length; i++) {
154
+ const item = unref(radarIndicator)[i]
155
+ const { marker, seriesName, value } = params || {}
156
+ if (i === 0 && seriesName) {
157
+ formatter += `${seriesName}<br/>`
158
+ }
159
+ formatter += useVariablesInText(
160
+ tooltipFormatter,
161
+ {
162
+ textData: {
163
+ marker,
164
+ name: item.name,
165
+ value: value[i],
166
+ a: item.name,
167
+ b: item.name,
168
+ c: value[i] || 0,
169
+ type: seriesName
170
+ }
171
+ },
172
+ {
173
+ useNewline: true,
174
+ useSpace: true
175
+ }
176
+ )
177
+ formatter += '<br/>'
178
+ }
179
+ return formatter
180
+ },
181
+ position: props.tooltipPosition || undefined
182
+ },
183
+ radar: {
184
+ indicator: unref(radarIndicator),
185
+ axisName: {
186
+ color: props.axisNameColor
187
+ }
188
+ },
189
+ // 图例
190
+ legend: {
191
+ type: props.legendScroll ? 'scroll' : 'plain',
192
+ width: props.legendWidth,
193
+ height: props.legendHeight,
194
+ show: props.legendShow,
195
+ orient: props.legendOrient,
196
+ top: props.legendTop,
197
+ left: props.legendLeft,
198
+ textStyle: {
199
+ // lineHeight: (visible.value ? ZOOM_FONT_SIZE : parseFloat(props.legendFontSize)) + 8,
200
+ lineHeight: parseFloat(props.legendFontSize) + 8,
201
+
202
+ rich: {
203
+ text: {
204
+ width: props.legendTextWidth,
205
+ color: props.legendTextStyleColor,
206
+ // fontSize: visible.value ? ZOOM_FONT_SIZE : props.legendFontSize
207
+ fontSize: props.legendFontSize
208
+ }
209
+ }
210
+ },
211
+ itemHeight: props.legendItemHeight,
212
+ itemWidth: props.legendItemWidth,
213
+ itemGap: props.legendItemGap,
214
+ data: unref(dataSource).map((value) => {
215
+ return {
216
+ name: value.name,
217
+ icon: props.legendType
218
+ }
219
+ }),
220
+ formatter: (name: string) => {
221
+ return getLegendFormat(props.legendFormatter, {
222
+ name
223
+ })
224
+ }
225
+ },
226
+ series: unref(series)
227
+ }))
228
+ return unref(options)
229
+ }