Commit 7718da56 by Dmitriy Stepanets

Added logic to reduce timeline items count

parent 7ca65c2c
...@@ -80,25 +80,25 @@ class MapTimeControlView: UIView { ...@@ -80,25 +80,25 @@ class MapTimeControlView: UIView {
} }
public func configure(items:[MapTimeControlItem], timeZone:TimeZone) { public func configure(items:[MapTimeControlItem], timeZone:TimeZone) {
//Reduce count if needed self.currentItems = items
if items.count > 5 { stackView.removeAll()
var modifiedItems = items
while modifiedItems.count > 5 { //Reduce count if needed for displaying
let centerIndex = modifiedItems.count / 2 let maxValues = 5
modifiedItems.remove(at: centerIndex) 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 { 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() stackView.layoutIfNeeded()
} }
......
import Foundation import Foundation
import UIKit 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