fix: add a sensor value to the chart in the popup view even if the popup is closed

This commit is contained in:
Serhiy Mytrovtsiy
2022-03-11 19:02:40 +01:00
parent c8904a27c5
commit fa266ffc32
2 changed files with 12 additions and 3 deletions

View File

@@ -97,11 +97,11 @@ public class LineChartView: NSView {
underLinePath.fill()
}
public func addValue(_ value: Double) {
public func addValue(_ value: Double, redraw: Bool = true) {
self.points.remove(at: 0)
self.points.append(value)
if self.window?.isVisible ?? true {
if redraw && self.window?.isVisible ?? true {
self.display()
}
}

View File

@@ -101,6 +101,12 @@ internal class Popup: NSStackView, Popup_p {
}
internal func usageCallback(_ values: [Sensor_p]) {
values.filter({ $0 is Sensor }).forEach { (s: Sensor_p) in
if let sensor = self.list[s.key] as? SensorView {
sensor.addHistoryPoint(s)
}
}
DispatchQueue.main.async(execute: {
if self.window?.isVisible ?? false {
values.forEach { (s: Sensor_p) in
@@ -165,6 +171,9 @@ internal class SensorView: NSStackView {
public func update(_ sensor: Sensor_p) {
self.valueView.update(sensor.formattedValue)
}
public func addHistoryPoint(_ sensor: Sensor_p) {
self.chartView.update(sensor.value)
}
@@ -274,7 +283,7 @@ internal class ChartSensorView: NSStackView {
}
public func update(_ value: Double) {
self.chart?.addValue(value/100)
self.chart?.addValue(value/100, redraw: false)
}
}