@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.
- package/lib/index.es.js +1 -1
- package/package.json +4 -2
- package/rollup.config.dev.js +39 -0
- package/src/index.ts +5 -2
- package/src/indicator.ts +19 -10
- package/src/utils/chartTransProps/bar.ts +322 -0
- package/src/utils/chartTransProps/comboGraph.ts +409 -0
- package/src/utils/chartTransProps/common.ts +76 -0
- package/src/utils/chartTransProps/line.ts +260 -0
- package/src/utils/chartTransProps/pie.ts +138 -0
- package/src/utils/chartTransProps/radar.ts +229 -0
- package/src/utils/chartTransProps/scatter.ts +472 -0
- package/src/utils/transformProps.ts +21 -888
- package/src/utils/util.ts +31 -0
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
export default function getBarTransformProps(props, chartData, fontSize, callBackMethodMap) {
|
|
6
|
+
const yAxisLabelFormatter = props.yAxisLabelFormatter
|
|
7
|
+
const xAxisLabelFormatter = props.xAxisLabelFormatter
|
|
8
|
+
const dataSource = ref(chartData.dataset)
|
|
9
|
+
const dimensions = ref(chartData.dimensions)
|
|
10
|
+
const series = computed(() => {
|
|
11
|
+
const { gradientShow, gradientColors, gradientOffset, barBorderRadius } = props
|
|
12
|
+
const ds = unref(dataSource)
|
|
13
|
+
const len = ds.length
|
|
14
|
+
const series = []
|
|
15
|
+
for (let i = 0; i < len; i++) {
|
|
16
|
+
const item = {
|
|
17
|
+
...ds[i],
|
|
18
|
+
type: 'bar',
|
|
19
|
+
barWidth: props.barWidth.value + props.barWidth.suffix,
|
|
20
|
+
showBackground: props.showBarBackground
|
|
21
|
+
} as { [key: string]: any }
|
|
22
|
+
if (props.isStack) {
|
|
23
|
+
item.stack = 'stack'
|
|
24
|
+
}
|
|
25
|
+
item.label = {
|
|
26
|
+
show: props.labelShow,
|
|
27
|
+
fontSize: props.labelFontSize,
|
|
28
|
+
position: props.labelPosition,
|
|
29
|
+
color: props.labelColor,
|
|
30
|
+
width: props.labelWidth,
|
|
31
|
+
overflow: props.labelOverflow,
|
|
32
|
+
formatter: (params) => {
|
|
33
|
+
let formatter = ''
|
|
34
|
+
let labelFormatter = props.labelFormatter
|
|
35
|
+
if (labelFormatter === '') {
|
|
36
|
+
labelFormatter = '{c}'
|
|
37
|
+
}
|
|
38
|
+
const { seriesName, name, value, data } = params || {}
|
|
39
|
+
formatter += useVariablesInText(
|
|
40
|
+
labelFormatter,
|
|
41
|
+
{
|
|
42
|
+
textData: {
|
|
43
|
+
name,
|
|
44
|
+
value,
|
|
45
|
+
a: seriesName,
|
|
46
|
+
b: name,
|
|
47
|
+
c: value || 0,
|
|
48
|
+
...data
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
useNewline: true,
|
|
53
|
+
useSpace: true
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
return formatter
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
item.itemStyle = {}
|
|
60
|
+
if (gradientShow) {
|
|
61
|
+
let gcolor = props.colors[i]
|
|
62
|
+
if (!gcolor && props.colors.length) {
|
|
63
|
+
const colorIndex = ((i + 1) % props.colors.length) - 1
|
|
64
|
+
gcolor = colorIndex > 0 ? props.colors[colorIndex] : props.colors[0]
|
|
65
|
+
}
|
|
66
|
+
if (!gcolor) {
|
|
67
|
+
gcolor = '#5470C6'
|
|
68
|
+
}
|
|
69
|
+
item.itemStyle = {
|
|
70
|
+
color: {
|
|
71
|
+
x: props.isUseHorizontalAxis ? 1 : 0,
|
|
72
|
+
y: 0,
|
|
73
|
+
x2: 0,
|
|
74
|
+
y2: props.isUseHorizontalAxis ? 0 : 1,
|
|
75
|
+
colorStops: [
|
|
76
|
+
{
|
|
77
|
+
offset: 0,
|
|
78
|
+
color: gcolor
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
offset: gradientOffset,
|
|
82
|
+
color: gradientColors[i]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
offset: 1,
|
|
86
|
+
color: gradientColors[i]
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (barBorderRadius && (!props.isStack || i === len - 1)) {
|
|
93
|
+
const radius = barBorderRadius.split(',')
|
|
94
|
+
if (radius?.length) {
|
|
95
|
+
const radiusItems = []
|
|
96
|
+
for (const rs of radius) {
|
|
97
|
+
const value = parseFloat(rs)
|
|
98
|
+
if (!isNaN(value)) {
|
|
99
|
+
radiusItems.push(value)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
item.itemStyle.borderRadius = radiusItems
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (props.isShowMarkLine) {
|
|
106
|
+
item.markLine = {
|
|
107
|
+
data: [{ type: props.markLineType }]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
series.push(item)
|
|
111
|
+
}
|
|
112
|
+
return series
|
|
113
|
+
})
|
|
114
|
+
const xAxisData = computed(() => {
|
|
115
|
+
return unref(dimensions).map((item) => {
|
|
116
|
+
let result = {}
|
|
117
|
+
if (item && typeof item === 'object') {
|
|
118
|
+
result = {
|
|
119
|
+
...item,
|
|
120
|
+
textStyle: {
|
|
121
|
+
fontSize: fontSize
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
result = {
|
|
126
|
+
value: item,
|
|
127
|
+
textStyle: {
|
|
128
|
+
fontSize: fontSize
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
return {
|
|
136
|
+
tooltip: {
|
|
137
|
+
trigger: 'axis',
|
|
138
|
+
show: props.tooltipShow,
|
|
139
|
+
formatter: (params) => {
|
|
140
|
+
const len = params.length
|
|
141
|
+
let formatter = ''
|
|
142
|
+
let tooltipFormatter = props.tooltipFormatter
|
|
143
|
+
if (callBackMethodMap?.getCurrentData) {
|
|
144
|
+
// currentData = params[0]?.data
|
|
145
|
+
callBackMethodMap.getCurrentData(params[0]?.data)
|
|
146
|
+
}
|
|
147
|
+
if (tooltipFormatter === '') {
|
|
148
|
+
tooltipFormatter = '{marker} {a} {c}'
|
|
149
|
+
}
|
|
150
|
+
for (let i = 0; i < len; i++) {
|
|
151
|
+
const { marker, seriesName, name, value, data } = params[i] || {}
|
|
152
|
+
if (i === 0) {
|
|
153
|
+
let formatName = name
|
|
154
|
+
if (name === 'undefined') {
|
|
155
|
+
formatName = ''
|
|
156
|
+
}
|
|
157
|
+
if (typeof name === 'string' && name[0] === '0' && !isNaN(+name)) {
|
|
158
|
+
formatName = (+name).toString()
|
|
159
|
+
}
|
|
160
|
+
formatter += `${useValueFormatter(xAxisLabelFormatter, formatName)}${formatName ? '<br/>' : ''}`
|
|
161
|
+
}
|
|
162
|
+
formatter += useVariablesInText(
|
|
163
|
+
tooltipFormatter,
|
|
164
|
+
{
|
|
165
|
+
textData: {
|
|
166
|
+
marker,
|
|
167
|
+
name,
|
|
168
|
+
value,
|
|
169
|
+
a: seriesName,
|
|
170
|
+
b: name,
|
|
171
|
+
c: data.sourceValue || value || 0,
|
|
172
|
+
...data
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
useNewline: true,
|
|
177
|
+
useSpace: true
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
formatter += '<br/>'
|
|
181
|
+
}
|
|
182
|
+
return formatter
|
|
183
|
+
},
|
|
184
|
+
// valueFormatter: (value) => {
|
|
185
|
+
// return useVariablesInText(props.tooltipValueFormatter as string, { value })
|
|
186
|
+
// },
|
|
187
|
+
textStyle: {
|
|
188
|
+
color: props.tooltipTextStyleColor,
|
|
189
|
+
fontSize: fontSize.value
|
|
190
|
+
},
|
|
191
|
+
position: props.tooltipPosition || undefined
|
|
192
|
+
},
|
|
193
|
+
legend: {
|
|
194
|
+
type: props.legendScroll ? 'scroll' : 'plain',
|
|
195
|
+
width: props.legendWidth,
|
|
196
|
+
height: props.legendHeight,
|
|
197
|
+
show: props.legendShow,
|
|
198
|
+
orient: props.legendOrient,
|
|
199
|
+
top: props.legendTop,
|
|
200
|
+
left: props.legendLeft,
|
|
201
|
+
textStyle: {
|
|
202
|
+
// lineHeight: (visible.value ? ZOOM_FONT_SIZE : parseFloat(props.legendFontSize)) + 8,
|
|
203
|
+
rich: {
|
|
204
|
+
text: {
|
|
205
|
+
width: props.legendTextWidth,
|
|
206
|
+
color: props.legendTextStyleColor
|
|
207
|
+
// fontSize: visible.value ? ZOOM_FONT_SIZE : props.legendFontSize
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
itemHeight: props.legendItemHeight,
|
|
212
|
+
itemWidth: props.legendItemWidth,
|
|
213
|
+
itemGap: props.legendItemGap,
|
|
214
|
+
data: unref(dataSource).map((value, index) => {
|
|
215
|
+
return {
|
|
216
|
+
name: value.name,
|
|
217
|
+
itemStyle: {
|
|
218
|
+
color: props.colors[index]
|
|
219
|
+
},
|
|
220
|
+
icon: props.legendType
|
|
221
|
+
}
|
|
222
|
+
}),
|
|
223
|
+
formatter: (name: string) => {
|
|
224
|
+
return getLegendFormat(props.legendFormatter, {
|
|
225
|
+
name
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
xAxis: {
|
|
230
|
+
type: props.isUseHorizontalAxis ? 'value' : 'category',
|
|
231
|
+
data: props.isUseHorizontalAxis ? null : unref(xAxisData),
|
|
232
|
+
inverse: props.isUseHorizontalAxis ? props.xAxisInverse : props.axisInverse,
|
|
233
|
+
minInterval: props.xAxisMinInterval,
|
|
234
|
+
splitLine: {
|
|
235
|
+
show: props.xAxisSplitLineShow,
|
|
236
|
+
lineStyle: {
|
|
237
|
+
color: props.xAxisSplitLineStyleColor,
|
|
238
|
+
type: props.xAxisSplitLineType
|
|
239
|
+
},
|
|
240
|
+
interval: props.xAxisSplitLineInterval
|
|
241
|
+
},
|
|
242
|
+
splitArea: {
|
|
243
|
+
show: props.xAxisSplitAreaShow
|
|
244
|
+
},
|
|
245
|
+
axisLabel: {
|
|
246
|
+
show: props.xAxisLabelShow,
|
|
247
|
+
color: props.xAxisLabelColor,
|
|
248
|
+
interval: props.xAxisLabelInterval || 0,
|
|
249
|
+
rotate: props.xAxisLabelRotate,
|
|
250
|
+
width: props.xAxisLabelWidth,
|
|
251
|
+
overflow: props.xAxisLabelOverflow,
|
|
252
|
+
fontSize: props.xAxisLabelFontSize,
|
|
253
|
+
formatter(value: string) {
|
|
254
|
+
if (typeof value === 'string' && value[0] === '0' && !isNaN(+value)) {
|
|
255
|
+
value = (+value).toString()
|
|
256
|
+
}
|
|
257
|
+
return useValueFormatter(xAxisLabelFormatter, value)
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
axisLine: {
|
|
261
|
+
show: props.xAxisLineShow,
|
|
262
|
+
lineStyle: {
|
|
263
|
+
color: props.xAxisLineStyleColor
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
axisTick: {
|
|
267
|
+
show: props.xAxisTickShow
|
|
268
|
+
},
|
|
269
|
+
name: props.xAxisName,
|
|
270
|
+
nameTextStyle: {
|
|
271
|
+
fontSize: props.xAxisLabelFontSize,
|
|
272
|
+
color: props.xAxisLabelColor,
|
|
273
|
+
align: 'left'
|
|
274
|
+
},
|
|
275
|
+
max: props.xAxisMaxValue || null
|
|
276
|
+
},
|
|
277
|
+
yAxis: {
|
|
278
|
+
type: props.isUseHorizontalAxis ? 'category' : 'value',
|
|
279
|
+
data: props.isUseHorizontalAxis ? unref(dimensions) : null,
|
|
280
|
+
inverse: props.isUseHorizontalAxis ? props.axisInverse : props.yAxisInverse,
|
|
281
|
+
minInterval: props.yAxisMinInterval,
|
|
282
|
+
splitLine: {
|
|
283
|
+
show: props.yAxisSplitLineShow,
|
|
284
|
+
lineStyle: {
|
|
285
|
+
color: props.yAxisSplitLineStyleColor,
|
|
286
|
+
type: props.yAxisSplitLineType
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
splitArea: {
|
|
290
|
+
show: props.yAxisSplitAreaShow
|
|
291
|
+
},
|
|
292
|
+
axisTick: {
|
|
293
|
+
show: props.yAxisTickShow
|
|
294
|
+
},
|
|
295
|
+
axisLabel: {
|
|
296
|
+
show: props.yAxisLabelShow,
|
|
297
|
+
fontSize: props.yAxisLabelFontSize,
|
|
298
|
+
color: props.yAxisLabelColor,
|
|
299
|
+
rotate: props.yAxisLabelRotate,
|
|
300
|
+
width: props.yAxisLabelWidth,
|
|
301
|
+
overflow: props.yAxisLabelOverflow,
|
|
302
|
+
formatter(value: string) {
|
|
303
|
+
return useValueFormatter(yAxisLabelFormatter, value)
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
axisLine: {
|
|
307
|
+
show: props.yAxisLineAlwaysDisplay,
|
|
308
|
+
lineStyle: {
|
|
309
|
+
color: props.yAxisLineStyleColor
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
name: props.yAxisName,
|
|
313
|
+
nameTextStyle: {
|
|
314
|
+
fontSize: props.yAxisLabelFontSize,
|
|
315
|
+
color: props.yAxisLabelColor,
|
|
316
|
+
align: 'right'
|
|
317
|
+
},
|
|
318
|
+
max: props.yAxisMaxValue || null
|
|
319
|
+
},
|
|
320
|
+
series: unref(series)
|
|
321
|
+
}
|
|
322
|
+
}
|