mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 08:14:19 +09:00
fix: removed label from bar and pie charts
This commit is contained in:
@@ -13,7 +13,6 @@ import Cocoa
|
||||
import StatsKit
|
||||
|
||||
public class BarChart: WidgetWrapper {
|
||||
private var labelState: Bool = false
|
||||
private var boxState: Bool = true
|
||||
private var frameState: Bool = false
|
||||
private var colorState: widget_c = .systemAccent
|
||||
@@ -44,9 +43,6 @@ public class BarChart: WidgetWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
if let label = configuration["Label"] as? Bool {
|
||||
self.labelState = label
|
||||
}
|
||||
if let box = configuration["Box"] as? Bool {
|
||||
self.boxState = box
|
||||
}
|
||||
@@ -74,7 +70,6 @@ public class BarChart: WidgetWrapper {
|
||||
if !preview {
|
||||
self.boxState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_box", defaultValue: self.boxState)
|
||||
self.frameState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_frame", defaultValue: self.frameState)
|
||||
self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState)
|
||||
self.colorState = widget_c(rawValue: Store.shared.string(key: "\(self.title)_\(self.type.rawValue)_color", defaultValue: self.colorState.rawValue)) ?? self.colorState
|
||||
}
|
||||
|
||||
@@ -126,30 +121,6 @@ public class BarChart: WidgetWrapper {
|
||||
break
|
||||
}
|
||||
|
||||
if self.labelState {
|
||||
let style = NSMutableParagraphStyle()
|
||||
style.alignment = .center
|
||||
let stringAttributes = [
|
||||
NSAttributedString.Key.font: NSFont.systemFont(ofSize: 7, weight: .regular),
|
||||
NSAttributedString.Key.foregroundColor: NSColor.textColor,
|
||||
NSAttributedString.Key.paragraphStyle: style
|
||||
]
|
||||
|
||||
let letterHeight = self.frame.height / 3
|
||||
let letterWidth: CGFloat = 6.0
|
||||
|
||||
var yMargin: CGFloat = 0
|
||||
for char in String(self.title.prefix(3)).uppercased().reversed() {
|
||||
let rect = CGRect(x: x, y: yMargin, width: letterWidth, height: letterHeight)
|
||||
let str = NSAttributedString.init(string: "\(char)", attributes: stringAttributes)
|
||||
str.draw(with: rect)
|
||||
yMargin += letterHeight
|
||||
}
|
||||
|
||||
width = width + letterWidth + Constants.Widget.spacing
|
||||
x = letterWidth + Constants.Widget.spacing
|
||||
}
|
||||
|
||||
let box = NSBezierPath(roundedRect: NSRect(
|
||||
x: x + offset,
|
||||
y: offset,
|
||||
@@ -240,7 +211,7 @@ public class BarChart: WidgetWrapper {
|
||||
|
||||
public override func settings(width: CGFloat) -> NSView {
|
||||
let rowHeight: CGFloat = 30
|
||||
let settingsNumber: CGFloat = 4
|
||||
let settingsNumber: CGFloat = 3
|
||||
let height: CGFloat = ((rowHeight + Constants.Settings.margin) * settingsNumber) + Constants.Settings.margin
|
||||
|
||||
let view: NSView = NSView(frame: NSRect(
|
||||
@@ -250,13 +221,6 @@ public class BarChart: WidgetWrapper {
|
||||
height: height
|
||||
))
|
||||
|
||||
view.addSubview(ToggleTitleRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 3, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Label"),
|
||||
action: #selector(toggleLabel),
|
||||
state: self.labelState
|
||||
))
|
||||
|
||||
self.boxSettingsView = ToggleTitleRow(
|
||||
frame: NSRect(x: 0, y: (rowHeight + Constants.Settings.margin) * 2, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Box"),
|
||||
@@ -284,18 +248,6 @@ public class BarChart: WidgetWrapper {
|
||||
return view
|
||||
}
|
||||
|
||||
@objc private func toggleLabel(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
self.labelState = state! == .on ? true : false
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_label", value: self.labelState)
|
||||
self.display()
|
||||
}
|
||||
|
||||
@objc private func toggleBox(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
|
||||
@@ -13,8 +13,6 @@ import Cocoa
|
||||
import StatsKit
|
||||
|
||||
public class PieChart: WidgetWrapper {
|
||||
private var labelState: Bool = false
|
||||
|
||||
private var chart: PieChartView = PieChartView(
|
||||
frame: NSRect(
|
||||
x: Constants.Widget.margin.x,
|
||||
@@ -24,7 +22,6 @@ public class PieChart: WidgetWrapper {
|
||||
),
|
||||
segments: [], filled: true, drawValue: false
|
||||
)
|
||||
private var labelView: NSView? = nil
|
||||
|
||||
private let size: CGFloat = Constants.Widget.height - (Constants.Widget.margin.y*2) + (Constants.Widget.margin.x*2)
|
||||
|
||||
@@ -45,10 +42,6 @@ public class PieChart: WidgetWrapper {
|
||||
|
||||
self.canDrawConcurrently = true
|
||||
|
||||
if !preview {
|
||||
self.labelState = Store.shared.bool(key: "\(self.title)_\(self.type.rawValue)_label", defaultValue: self.labelState)
|
||||
}
|
||||
|
||||
if preview {
|
||||
if self.title == "CPU" {
|
||||
self.chart.setSegments([
|
||||
@@ -72,20 +65,14 @@ public class PieChart: WidgetWrapper {
|
||||
}
|
||||
|
||||
private func draw() {
|
||||
let x: CGFloat = self.labelState ? 8 + Constants.Widget.spacing : 0
|
||||
|
||||
self.labelView = WidgetLabelView(self.title, height: self.frame.height)
|
||||
self.labelView!.isHidden = !self.labelState
|
||||
|
||||
self.addSubview(self.labelView!)
|
||||
self.addSubview(self.chart)
|
||||
|
||||
var frame = self.chart.frame
|
||||
frame = NSRect(x: x, y: 0, width: self.frame.size.height, height: self.frame.size.height)
|
||||
frame = NSRect(x: 0, y: 0, width: self.frame.size.height, height: self.frame.size.height)
|
||||
self.chart.frame = frame
|
||||
|
||||
self.setFrameSize(NSSize(width: self.size + x, height: self.frame.size.height))
|
||||
self.setWidth(self.size + x)
|
||||
self.setFrameSize(NSSize(width: self.size, height: self.frame.size.height))
|
||||
self.setWidth(self.size)
|
||||
}
|
||||
|
||||
public func setValue(_ segments: [circle_segment]) {
|
||||
@@ -93,44 +80,4 @@ public class PieChart: WidgetWrapper {
|
||||
self.chart.setSegments(segments)
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Settings
|
||||
|
||||
public override func settings(width: CGFloat) -> NSView {
|
||||
let rowHeight: CGFloat = 30
|
||||
let height: CGFloat = ((rowHeight + Constants.Settings.margin) * 1) + Constants.Settings.margin
|
||||
|
||||
let view: NSView = NSView(frame: NSRect(
|
||||
x: Constants.Settings.margin,
|
||||
y: Constants.Settings.margin,
|
||||
width: width - (Constants.Settings.margin*2),
|
||||
height: height
|
||||
))
|
||||
|
||||
view.addSubview(ToggleTitleRow(
|
||||
frame: NSRect(x: 0, y: 0, width: view.frame.width, height: rowHeight),
|
||||
title: LocalizedString("Label"),
|
||||
action: #selector(toggleLabel),
|
||||
state: self.labelState
|
||||
))
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@objc private func toggleLabel(_ sender: NSControl) {
|
||||
var state: NSControl.StateValue? = nil
|
||||
if #available(OSX 10.15, *) {
|
||||
state = sender is NSSwitch ? (sender as! NSSwitch).state: nil
|
||||
} else {
|
||||
state = sender is NSButton ? (sender as! NSButton).state: nil
|
||||
}
|
||||
|
||||
self.labelState = state! == .on ? true : false
|
||||
Store.shared.set(key: "\(self.title)_\(self.type.rawValue)_label", value: self.labelState)
|
||||
|
||||
let x = self.labelState ? 6 + Constants.Widget.spacing : 0
|
||||
self.labelView!.isHidden = !self.labelState
|
||||
self.chart.setFrameOrigin(NSPoint(x: x, y: 0))
|
||||
self.setWidth(self.labelState ? self.size+x : self.size)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user