mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: adjust RAM color zones (orange: 0.8, red: 0.95) in BarChart for utilization mode
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user