Commit 7718da56 by Dmitriy Stepanets

Added logic to reduce timeline items count

parent 7ca65c2c
......@@ -80,25 +80,25 @@ class MapTimeControlView: UIView {
}
public func configure(items:[MapTimeControlItem], timeZone:TimeZone) {
//Reduce count if needed
if items.count > 5 {
var modifiedItems = items
while modifiedItems.count > 5 {
let centerIndex = modifiedItems.count / 2
modifiedItems.remove(at: centerIndex)
self.currentItems = items
stackView.removeAll()
//Reduce count if needed for displaying
let maxValues = 5
if items.count > maxValues {
let steps = (items.count - 1) / (maxValues - 1)
for index in 0..<maxValues {
let view = MapTimeView(item: items[index * steps])
stackView.addArrangedSubview(view)
}
self.currentItems = modifiedItems
}
else {
self.currentItems = items
items.forEach {
let view = MapTimeView(item: $0)
stackView.addArrangedSubview(view)
}
}
stackView.removeAll()
self.currentItems.forEach {
let view = MapTimeView(item: $0)
stackView.addArrangedSubview(view)
}
stackView.layoutIfNeeded()
}
......
import Foundation
import UIKit
var arr = [3, 0, 6, 22, 55, 45, 232, 534, 1, 7, 9, 10]
let maxValues = 6
let steps = (arr.count - 1) / (maxValues - 1)
var result = [Int]()
for index in 0..<maxValues {
print("Fraction: \(index * steps)")
result.append(arr[index * steps])
}
print("Orig: \(arr)")
print("Result: \(result)")
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