diff --git a/ModuleKit/Widgets/BarChart.swift b/ModuleKit/Widgets/BarChart.swift index e807250a..dd4d1169 100644 --- a/ModuleKit/Widgets/BarChart.swift +++ b/ModuleKit/Widgets/BarChart.swift @@ -22,6 +22,7 @@ public class BarChart: WidgetWrapper { private var colors: [widget_c] = widget_c.allCases private var value: [Double] = [] private var pressureLevel: Int = 0 + private var colorZones: colorZones = (0.6, 0.8) private var boxSettingsView: NSView? = nil private var frameSettingsView: NSView? = nil @@ -178,7 +179,7 @@ public class BarChart: WidgetWrapper { switch self.colorState { case .systemAccent: NSColor.controlAccentColor.set() - case .utilization: partitionValue.usageColor().setFill() + case .utilization: partitionValue.usageColor(zones: self.colorZones).setFill() case .pressure: self.pressureLevel.pressureColor().setFill() case .monochrome: if self.boxState { @@ -226,6 +227,17 @@ public class BarChart: WidgetWrapper { }) } + public func setColorZones(_ zones: colorZones) { + guard self.colorZones != zones else { + return + } + + self.colorZones = zones + DispatchQueue.main.async(execute: { + self.display() + }) + } + // MARK: - Settings public override func settings(width: CGFloat) -> NSView { diff --git a/Modules/RAM/main.swift b/Modules/RAM/main.swift index 828752c0..39632503 100644 --- a/Modules/RAM/main.swift +++ b/Modules/RAM/main.swift @@ -119,6 +119,7 @@ public class RAM: Module { widget.setPressure(value.pressureLevel) case let widget as BarChart: widget.setValue([value.usage]) + widget.setColorZones((0.8, 0.95)) widget.setPressure(value.pressureLevel) case let widget as PieChart: let total: Double = value.total == 0 ? 1 : value.total diff --git a/StatsKit/extensions.swift b/StatsKit/extensions.swift index cb9ea518..bbb4d820 100644 --- a/StatsKit/extensions.swift +++ b/StatsKit/extensions.swift @@ -126,25 +126,25 @@ public extension Double { return (self * divisor).rounded() / divisor } - func usageColor(reversed: Bool = false) -> NSColor { + func usageColor(zones: colorZones = (0.6, 0.8), reversed: Bool = false) -> NSColor { let firstColor: NSColor = NSColor.systemBlue let secondColor: NSColor = NSColor.orange let thirdColor: NSColor = NSColor.red if reversed { switch self { - case 0.6...0.8: + case zones.orange...zones.red: return secondColor - case 0.8...1: + case zones.red...1: return firstColor default: return thirdColor } } else { switch self { - case 0.6...0.8: + case zones.orange...zones.red: return secondColor - case 0.8...1: + case zones.red...1: return thirdColor default: return firstColor diff --git a/StatsKit/helpers.swift b/StatsKit/helpers.swift index ef5ea607..89c3f55e 100644 --- a/StatsKit/helpers.swift +++ b/StatsKit/helpers.swift @@ -137,6 +137,8 @@ public enum widget_c: String { } extension widget_c: CaseIterable {} +public typealias colorZones = (orange: Double, red: Double) + public struct Units { public let bytes: Int64