@ecan-bi/tools 1.0.62 → 1.0.64

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