HadoopDetailController.swift
7.1 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
// HadoopDetailController.swift
// AoleiSports
//
// Created by ilCode on 2024/6/25.
//
import UIKit
import DGCharts
class HadoopDetailController: BaseController {
let yqId: Int
var provider: HadoopProvider<HadoopTarget>?
let activities = ["进攻", "排名", "技术", "状态", "防守"]
private lazy var header: UIView = {
let view = UIView(frame: CGRect(x: 0, y: -30, width: kScreenW, height: kNavBarH + 90))
view.backgroundColor = UIColor.colorWith(hexString: "122063")
view.corners(radius: 30)
return view
}()
private lazy var teamView: UIView = {
let view = UIView(frame: CGRect(x: 10, y: kNavBarH, width: kScreenW - 20, height: 100))
view.backgroundColor = UIColor.colorWith(hexString: "ECECED")
view.corners(radius: 20)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = view.bounds
gradientLayer.colors = [UIColor.colorWith(hexString: "DADADA").cgColor, UIColor.colorWith(hexString: "F4F4F4").cgColor, UIColor.colorWith(hexString: "DADADA").cgColor]
gradientLayer.locations = [0.0, 0.5, 1.0]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
view.layer.insertSublayer(gradientLayer, at: 0)
return view
}()
private lazy var radarView: UIView = {
let view = UIView()
view.backgroundColor = kWhite
view.corners(radius: 10)
view.border(borderColor: UIColor.colorWith(hexString: "F2F1F1"))
return view
}()
private lazy var radarChartView: RadarChartView = {
let chartView = RadarChartView()
chartView.chartDescription.enabled = false
chartView.webLineWidth = 1
chartView.innerWebLineWidth = 1
chartView.webColor = UIColor.colorWith(hexString: "CADEF1")
chartView.innerWebColor = UIColor.colorWith(hexString: "CADEF1")
chartView.webAlpha = 1
chartView.backgroundColor = .clear
chartView.rotationEnabled = false
return chartView
}()
init(yqId: Int) {
self.yqId = yqId
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
gk_navTitle = "大数据研究"
gk_navBackgroundColor = UIColor.colorWith(hexString: "122063")
gk_navTitleColor = kWhite
gk_backImage = R.image.btn_back_white()
// view.addSubview(header)
// view.addSubview(teamView)
// view.addSubview(radarView)
// radarView.addSubview(radarChartView)
//
// radarView.snp.makeConstraints { make in
// make.left.equalToSuperview().offset(10)
// make.right.equalToSuperview().offset(-10)
// make.top.equalTo(teamView.snp.bottom).offset(10)
// }
// radarChartView.snp.makeConstraints { make in
// make.centerX.equalToSuperview()
// make.top.equalToSuperview().offset(10)
// make.width.height.equalTo(300)
// make.bottom.equalToSuperview().offset(-10)
// }
//
// self.initRadarChartView()
// self.showRadarChartView()
initProvider()
handleRefresh()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func handleRefresh() {
super.handleRefresh()
provider?.bigDataDetailRequest(yqId: yqId, completion: { logicResult in
if case .failure(let err) = logicResult {
if case AsError.netErr(let message) = err {
self.showEmpty(type: .netErr, message: message)
} else {
self.showEmpty(type: .other, message: err.localizedDescription)
}
}
})
}
private func initRadarChartView() {
let xAxis = radarChartView.xAxis
xAxis.labelFont = kBoldFontSize(12)
xAxis.xOffset = 0
xAxis.yOffset = 0
xAxis.valueFormatter = self
xAxis.labelTextColor = UIColor.colorWith(hexString: "475086")
let yAxis = radarChartView.yAxis
yAxis.labelFont = kBoldFontSize(12)
yAxis.axisMinimum = 0
yAxis.drawLabelsEnabled = false
yAxis.labelTextColor = UIColor.colorWith(hexString: "475086")
let l = radarChartView.legend
l.form = .circle
l.horizontalAlignment = .center
l.verticalAlignment = .bottom
l.orientation = .horizontal
l.drawInside = true
l.font = kFontSize(12)
l.xEntrySpace = 10
l.textColor = kMainTitleColor
}
func showRadarChartView() {
let hostList = [44, 85, 71, 86, 80]
let guestList = [17, 91, 45, 83, 77]
let axisRanges: [(min: Double, max: Double)] = [
(min: 0, max: 54),
(min: 0, max: 100),
(min: 0, max: 100),
(min: 0, max: 100),
(min: 0, max: 100)
]
// 归一化数据
let normalizedHostList = zip(hostList, axisRanges).map { value, range in
return RadarChartDataEntry(value: (Double(value) - range.min) / (range.max - range.min))
}
let normalizedGuestList = zip(guestList, axisRanges).map { value, range in
return RadarChartDataEntry(value: (Double(value) - range.min) / (range.max - range.min))
}
let set1 = RadarChartDataSet(entries: normalizedHostList, label: "主队")
set1.setColor(UIColor.colorWith(hexString: "1EA1FC"))
set1.fillColor = UIColor.colorWith(hexString: "73C4FD")
set1.drawFilledEnabled = true
set1.fillAlpha = 0.7
set1.lineWidth = 2
set1.drawHighlightCircleEnabled = true
set1.setDrawHighlightIndicators(false)
let set2 = RadarChartDataSet(entries: normalizedGuestList, label: "客队")
set2.setColor(UIColor.colorWith(hexString: "FC9377"))
set2.fillColor = UIColor.colorWith(hexString: "FBBAAA")
set2.drawFilledEnabled = true
set2.fillAlpha = 0.7
set2.lineWidth = 2
set2.drawHighlightCircleEnabled = true
set2.setDrawHighlightIndicators(false)
let data: RadarChartData = [set1, set2]
data.setDrawValues(false)
radarChartView.data = data
radarChartView.animate(xAxisDuration: 0, yAxisDuration: 1.4, easingOption: .linear)
}
}
extension HadoopDetailController: AxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return activities[Int(value) % activities.count]
}
}
extension HadoopDetailController {
private func initProvider() {
provider = HadoopProvider(vc: self, showErr: false)
// provider?.matchList
// .asObservable()
// .subscribe(onNext: { [weak self] tmpModels in
// guard let self = self else { return }
//
//
// })
// .disposed(by: disposeBag)
}
}