Commit 98174d0b by Dmitry Stepanets

Changed logic of unique temps column rendering

parent 6644c623
...@@ -103,36 +103,24 @@ class MinutelyForecastView: UIView { ...@@ -103,36 +103,24 @@ class MinutelyForecastView: UIView {
var uniqTemps = forecast.compactMap{$0.temp}.unique().sorted{$0.value > $1.value} var uniqTemps = forecast.compactMap{$0.temp}.unique().sorted{$0.value > $1.value}
if uniqTemps.count > 4 { if uniqTemps.count > 4 {
var originalTimes = [Float]() let uniqMax = uniqTemps.removeFirst()
var originalValues = [Float]() let uniqMin = uniqTemps.removeLast()
let midPoint = (uniqTemps.count / 2)
for time in 0..<uniqTemps.count { let firstHalf = uniqTemps[..<midPoint]
originalTimes.append(Float(time)) let firstHalfTemp = firstHalf[firstHalf.startIndex + firstHalf.count % 2]
originalValues.append(Float(uniqTemps[time].value))
}
var newValues = [Float](repeating: 0, count: 4)
let stride = vDSP_Stride(1)
vDSP_vlint(originalValues,
originalTimes, stride,
&newValues, stride,
4,
vDSP_Length(originalValues.count))
// vDSP_vgenpD(originalValues, stride,
// originalTimes, stride,
// &newValues, stride,
// vDSP_Length(newValues.count),
// vDSP_Length(originalValues.count))
let result = newValues.enumerated().map{ return $0 } let seconHalf = uniqTemps[midPoint...]
print("Break") let secondHalfTemp = seconHalf[seconHalf.startIndex + seconHalf.count % 2]
uniqTemps = [uniqMax, firstHalfTemp, secondHalfTemp, uniqMin]
} }
for temp in uniqTemps { for temp in uniqTemps {
let label = UILabel() let label = UILabel()
label.text = temp.settingsConverted.shortString label.text = temp.settingsConverted.shortString
label.font = AppFont.SFPro.regular(size: 10) label.font = AppFont.SFPro.regular(size: 10)
label.setContentHuggingPriority(.fittingSizeLevel, for: .vertical)
label.sizeToFit()
verticalStackView.addArrangedSubview(label) verticalStackView.addArrangedSubview(label)
} }
...@@ -183,14 +171,14 @@ private extension MinutelyForecastView { ...@@ -183,14 +171,14 @@ private extension MinutelyForecastView {
func prepareVerticalStackView() { func prepareVerticalStackView() {
verticalStackView.axis = .vertical verticalStackView.axis = .vertical
verticalStackView.distribution = .fillProportionally verticalStackView.distribution = .fillEqually
verticalStackView.alignment = .fill verticalStackView.alignment = .top
addSubview(verticalStackView) addSubview(verticalStackView)
verticalStackView.snp.makeConstraints { make in verticalStackView.snp.makeConstraints { make in
make.height.equalTo(levelsStackView) make.height.equalTo(levelsStackView)
make.right.equalTo(scrollView.snp.left).offset(-6) make.right.equalTo(scrollView.snp.left).offset(-6)
make.top.equalTo(scrollView).inset(4) make.top.equalTo(scrollView)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment