feat: added Bar chart view to the Sensors module (for Fans only!) (#839)

This commit is contained in:
Serhiy Mytrovtsiy
2022-03-08 17:04:10 +01:00
parent 5d939588f6
commit 69219a2902
4 changed files with 26 additions and 2 deletions

View File

@@ -83,7 +83,7 @@ public enum widget_t: String {
case is BarChart:
if module == "GPU" || module == "RAM" || module == "Disk" || module == "Battery" {
width = 11 + (Constants.Widget.margin.x*2)
} else if module == "Fans" {
} else if module == "Sensors" {
width = 22 + (Constants.Widget.margin.x*2)
} else if module == "CPU" {
width = 30 + (Constants.Widget.margin.x*2)

View File

@@ -27,6 +27,24 @@
<key>Order</key>
<integer>1</integer>
</dict>
<key>bar_chart</key>
<dict>
<key>Default</key>
<false/>
<key>Preview</key>
<dict>
<key>Value</key>
<string>0.36,0.3</string>
<key>Color</key>
<true/>
</dict>
<key>Unsupported colors</key>
<array>
<string>pressure</string>
</array>
<key>Order</key>
<integer>2</integer>
</dict>
</dict>
</dict>
</plist>

View File

@@ -67,9 +67,14 @@ public class Sensors: Module {
}
var list: [KeyValue_t] = []
var flatList: [[ColorValue]] = []
value.forEach { (s: Sensor_p) in
if s.state {
list.append(KeyValue_t(key: s.key, value: s.formattedMiniValue))
if let f = s as? Fan {
flatList.append([ColorValue(((f.value*100)/f.maxSpeed)/100)])
}
}
}
@@ -78,6 +83,7 @@ public class Sensors: Module {
self.widgets.filter{ $0.isActive }.forEach { (w: Widget) in
switch w.item {
case let widget as SensorsWidget: widget.setValues(list)
case let widget as BarChart: widget.setValue(flatList)
default: break
}
}

View File

@@ -597,7 +597,7 @@ internal class FanView: NSStackView {
var speed = ""
if value.value != 1 {
if self.fan.maxSpeed == 1 || self.fan.maxSpeed == 0 {
speed = "\(Int(value.value))RPM"
speed = "\(Int(value.value)) RPM"
} else {
speed = "\((100*Int(value.value)) / Int(self.fan.maxSpeed))%"
}