- fix out of bounds when changing to the chart widget (happens only when empty history)

This commit is contained in:
Serhiy Mytrovtsiy
2020-11-05 13:30:50 +01:00
parent f9b90bc3ba
commit d05b47ec0d

View File

@@ -251,7 +251,9 @@ public class LineChart: Widget {
public override func setValues(_ values: [value_t]) {
let historyValues = values.map{ $0.widget_value }.suffix(60)
let end = self.chart.points!.count
self.chart.points!.replaceSubrange(end-historyValues.count...end-1, with: historyValues)
if historyValues.count != 0 {
self.chart.points!.replaceSubrange(end-historyValues.count...end-1, with: historyValues)
}
self.display()
}