-
Notifications
You must be signed in to change notification settings - Fork 695
Expand file tree
/
Copy pathLine.ts
More file actions
137 lines (127 loc) · 3.34 KB
/
Line.ts
File metadata and controls
137 lines (127 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { BaseG2Chart } from '@/views/chat/component/BaseG2Chart.ts'
import type { ChartAxis, ChartData } from '@/views/chat/component/BaseChart.ts'
import type { G2Spec } from '@antv/g2'
import {
checkIsPercent,
getAxesWithFilter,
processMultiQuotaData,
} from '@/views/chat/component/charts/utils.ts'
export class Line extends BaseG2Chart {
constructor(id: string) {
super(id, 'line')
}
init(axis: Array<ChartAxis>, data: Array<ChartData>) {
super.init(axis, data)
const axes = getAxesWithFilter(this.axis)
if (axes.x.length == 0 || axes.y.length == 0) {
console.debug({ instance: this })
return
}
let config = {
data: data,
y: axes.y,
series: axes.series,
}
if (axes.multiQuota.length > 0) {
config = processMultiQuotaData(
axes.x,
config.y,
axes.multiQuota,
axes.multiQuotaName,
config.data
)
}
const x = axes.x
const y = config.y
const series = config.series
const _data = checkIsPercent(y, config.data)
console.debug({ 'render-info': { x: x, y: y, series: series, data: _data }, instance: this })
const options: G2Spec = {
...this.chart.options(),
type: 'view',
data: _data.data,
encode: {
x: x[0].value,
y: y[0].value,
color: series.length > 0 ? series[0].value : undefined,
},
axis: {
x: {
title: false, // x[0].name,
labelFontSize: 12,
labelAutoHide: {
type: 'hide',
keepHeader: true,
keepTail: true,
},
labelAutoRotate: false,
labelAutoWrap: true,
labelAutoEllipsis: true,
},
y: {
title: false, // y[0].name,
},
},
scale: {
x: {
nice: true,
},
y: {
nice: true,
type: 'linear',
},
},
children: [
{
type: 'line',
encode: {
shape: 'smooth',
},
labels: this.showLabel
? [
{
text: (data: any) => {
const value = data[y[0].value]
if (value === undefined || value === null) {
return ''
}
return `${value}${_data.isPercent ? '%' : ''}`
},
style: {
dx: -10,
dy: -12,
},
transform: [
{ type: 'contrastReverse' },
{ type: 'exceedAdjust' },
{ type: 'overlapHide' },
],
},
]
: [],
tooltip: (data: any) => {
if (series.length > 0) {
return {
name: data[series[0].value],
value: `${data[y[0].value]}${_data.isPercent ? '%' : ''}`,
}
} else {
return { name: y[0].name, value: `${data[y[0].value]}${_data.isPercent ? '%' : ''}` }
}
},
},
{
type: 'point',
style: {
fill: 'white',
},
encode: {
size: 1.5,
},
tooltip: false,
},
],
} as G2Spec
this.chart.options(options)
}
}