mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: fixed logarithmic scaling in different than Network charts (#2418)
This commit is contained in:
@@ -177,11 +177,11 @@ public class NetworkChart: WidgetWrapper {
|
|||||||
|
|
||||||
let topYPoint = { (point: Int) -> CGFloat in
|
let topYPoint = { (point: Int) -> CGFloat in
|
||||||
let value = self.reverseOrderState ? points[point].1 : points[point].0
|
let value = self.reverseOrderState ? points[point].1 : points[point].0
|
||||||
return scaleValue(scale: self.scaleState, value: value, maxValue: topMax, maxHeight: chartFrame.height/2, limit: 1) + xCenter
|
return scaleValue(scale: self.scaleState, value: value, maxValue: topMax, zeroValue: 256.0, maxHeight: chartFrame.height/2, limit: 1) + xCenter
|
||||||
}
|
}
|
||||||
let bottomYPoint = { (point: Int) -> CGFloat in
|
let bottomYPoint = { (point: Int) -> CGFloat in
|
||||||
let value = self.reverseOrderState ? points[point].0 : points[point].1
|
let value = self.reverseOrderState ? points[point].0 : points[point].1
|
||||||
return xCenter - scaleValue(scale: self.scaleState, value: value, maxValue: bottomMax, maxHeight: chartFrame.height/2, limit: 1)
|
return xCenter - scaleValue(scale: self.scaleState, value: value, maxValue: bottomMax, zeroValue: 256.0, maxHeight: chartFrame.height/2, limit: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
let topLinePath = NSBezierPath()
|
let topLinePath = NSBezierPath()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public struct circle_segment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func scaleValue(scale: Scale = .linear, value: Double, maxValue: Double, maxHeight: CGFloat, limit: Double) -> CGFloat {
|
internal func scaleValue(scale: Scale = .linear, value: Double, maxValue: Double, zeroValue: Double, maxHeight: CGFloat, limit: Double) -> CGFloat {
|
||||||
var value = value
|
var value = value
|
||||||
if scale == .none && value > 1 && maxValue != 0 {
|
if scale == .none && value > 1 && maxValue != 0 {
|
||||||
value /= maxValue
|
value /= maxValue
|
||||||
@@ -45,12 +45,11 @@ internal func scaleValue(scale: Scale = .linear, value: Double, maxValue: Double
|
|||||||
localMaxValue = cbrt(maxValue)
|
localMaxValue = cbrt(maxValue)
|
||||||
}
|
}
|
||||||
case .logarithmic:
|
case .logarithmic:
|
||||||
let zeroVal = 256.0
|
|
||||||
if value > 0 {
|
if value > 0 {
|
||||||
value = log(value/zeroVal)
|
value = log(value/zeroValue)
|
||||||
}
|
}
|
||||||
if localMaxValue > 0 {
|
if localMaxValue > 0 {
|
||||||
localMaxValue = log(maxValue/zeroVal)
|
localMaxValue = log(maxValue/zeroValue)
|
||||||
}
|
}
|
||||||
case .fixed:
|
case .fixed:
|
||||||
if value > limit {
|
if value > limit {
|
||||||
@@ -132,16 +131,18 @@ public class LineChartView: NSView {
|
|||||||
|
|
||||||
private var scale: Scale
|
private var scale: Scale
|
||||||
private var fixedScale: Double
|
private var fixedScale: Double
|
||||||
|
private var zeroValue: Double
|
||||||
|
|
||||||
private var cursor: NSPoint? = nil
|
private var cursor: NSPoint? = nil
|
||||||
private var stop: Bool = false
|
private var stop: Bool = false
|
||||||
|
|
||||||
public init(frame: NSRect, num: Int, suffix: String = "%", color: NSColor = .controlAccentColor, scale: Scale = .none, fixedScale: Double = 1) {
|
public init(frame: NSRect, num: Int, suffix: String = "%", color: NSColor = .controlAccentColor, scale: Scale = .none, fixedScale: Double = 1, zeroValue: Double = 0.01) {
|
||||||
self.points = Array(repeating: nil, count: num)
|
self.points = Array(repeating: nil, count: num)
|
||||||
self.suffix = suffix
|
self.suffix = suffix
|
||||||
self.color = color
|
self.color = color
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.fixedScale = fixedScale
|
self.fixedScale = fixedScale
|
||||||
|
self.zeroValue = zeroValue
|
||||||
|
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
@@ -194,7 +195,7 @@ public class LineChartView: NSView {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var y = scaleValue(scale: self.scale, value: v.value, maxValue: maxValue, maxHeight: height, limit: self.fixedScale)
|
var y = scaleValue(scale: self.scale, value: v.value, maxValue: maxValue, zeroValue: self.zeroValue, maxHeight: height, limit: self.fixedScale)
|
||||||
if self.flipY {
|
if self.flipY {
|
||||||
y = height - y
|
y = height - y
|
||||||
}
|
}
|
||||||
@@ -400,8 +401,8 @@ public class NetworkChartView: NSView {
|
|||||||
let bottomFrame = NSRect(x: 0, y: 0, width: frame.width, height: frame.height/2)
|
let bottomFrame = NSRect(x: 0, y: 0, width: frame.width, height: frame.height/2)
|
||||||
let inFrame = self.reversedOrder ? topFrame : bottomFrame
|
let inFrame = self.reversedOrder ? topFrame : bottomFrame
|
||||||
let outFrame = self.reversedOrder ? bottomFrame : topFrame
|
let outFrame = self.reversedOrder ? bottomFrame : topFrame
|
||||||
self.inChart = LineChartView(frame: inFrame, num: num, color: inColor, scale: scale, fixedScale: fixedScale)
|
self.inChart = LineChartView(frame: inFrame, num: num, color: inColor, scale: scale, fixedScale: fixedScale, zeroValue: 256.0)
|
||||||
self.outChart = LineChartView(frame: outFrame, num: num, color: outColor, scale: scale, fixedScale: fixedScale)
|
self.outChart = LineChartView(frame: outFrame, num: num, color: outColor, scale: scale, fixedScale: fixedScale, zeroValue: 256.0)
|
||||||
|
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user