Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda4ab07

Browse files
committed
fix: fixed logarithmic scaling in different than Network charts (#2418)
1 parent74a7609 commitda4ab07

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

‎Kit/Widgets/NetworkChart.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ public class NetworkChart: WidgetWrapper {
177177

178178
lettopYPoint={(point:Int)->CGFloatin
179179
letvalue=self.reverseOrderState?points[point].1:points[point].0
180-
returnscaleValue(scale:self.scaleState, value: value, maxValue: topMax, maxHeight: chartFrame.height/2, limit:1)+ xCenter
180+
returnscaleValue(scale:self.scaleState, value: value, maxValue: topMax,zeroValue:256.0,maxHeight: chartFrame.height/2, limit:1)+ xCenter
181181
}
182182
letbottomYPoint={(point:Int)->CGFloatin
183183
letvalue=self.reverseOrderState?points[point].0:points[point].1
184-
return xCenter- scaleValue(scale:self.scaleState, value: value, maxValue: bottomMax, maxHeight: chartFrame.height/2, limit:1)
184+
return xCenter- scaleValue(scale:self.scaleState, value: value, maxValue: bottomMax,zeroValue:256.0,maxHeight: chartFrame.height/2, limit:1)
185185
}
186186

187187
lettopLinePath=NSBezierPath()

‎Kit/plugins/Charts.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct circle_segment {
2121
}
2222
}
2323

24-
internalfunc scaleValue(scale:Scale=.linear, value:Double, maxValue:Double, maxHeight:CGFloat, limit:Double)->CGFloat{
24+
internalfunc scaleValue(scale:Scale=.linear, value:Double, maxValue:Double,zeroValue:Double,maxHeight:CGFloat, limit:Double)->CGFloat{
2525
varvalue= value
2626
if scale==.none && value>1 && maxValue!=0{
2727
value/= maxValue
@@ -45,12 +45,11 @@ internal func scaleValue(scale: Scale = .linear, value: Double, maxValue: Double
4545
localMaxValue=cbrt(maxValue)
4646
}
4747
case.logarithmic:
48-
letzeroVal=256.0
4948
if value>0{
50-
value=log(value/zeroVal)
49+
value=log(value/zeroValue)
5150
}
5251
if localMaxValue>0{
53-
localMaxValue=log(maxValue/zeroVal)
52+
localMaxValue=log(maxValue/zeroValue)
5453
}
5554
case.fixed:
5655
if value> limit{
@@ -132,16 +131,18 @@ public class LineChartView: NSView {
132131

133132
privatevarscale:Scale
134133
privatevarfixedScale:Double
134+
privatevarzeroValue:Double
135135

136136
privatevarcursor:NSPoint?=nil
137137
privatevarstop:Bool=false
138138

139-
publicinit(frame:NSRect, num:Int, suffix:String="%", color:NSColor=.controlAccentColor, scale:Scale=.none, fixedScale:Double=1){
139+
publicinit(frame:NSRect, num:Int, suffix:String="%", color:NSColor=.controlAccentColor, scale:Scale=.none, fixedScale:Double=1, zeroValue:Double=0.01){
140140
self.points=Array(repeating:nil, count: num)
141141
self.suffix= suffix
142142
self.color= color
143143
self.scale= scale
144144
self.fixedScale= fixedScale
145+
self.zeroValue= zeroValue
145146

146147
super.init(frame: frame)
147148

@@ -194,7 +195,7 @@ public class LineChartView: NSView {
194195
continue
195196
}
196197

197-
vary=scaleValue(scale:self.scale, value: v.value, maxValue: maxValue, maxHeight: height, limit:self.fixedScale)
198+
vary=scaleValue(scale:self.scale, value: v.value, maxValue: maxValue,zeroValue:self.zeroValue,maxHeight: height, limit:self.fixedScale)
198199
ifself.flipY{
199200
y= height- y
200201
}
@@ -400,8 +401,8 @@ public class NetworkChartView: NSView {
400401
letbottomFrame=NSRect(x:0, y:0, width: frame.width, height: frame.height/2)
401402
letinFrame=self.reversedOrder? topFrame: bottomFrame
402403
letoutFrame=self.reversedOrder? bottomFrame: topFrame
403-
self.inChart=LineChartView(frame: inFrame, num: num, color: inColor, scale: scale, fixedScale: fixedScale)
404-
self.outChart=LineChartView(frame: outFrame, num: num, color: outColor, scale: scale, fixedScale: fixedScale)
404+
self.inChart=LineChartView(frame: inFrame, num: num, color: inColor, scale: scale, fixedScale: fixedScale, zeroValue:256.0)
405+
self.outChart=LineChartView(frame: outFrame, num: num, color: outColor, scale: scale, fixedScale: fixedScale, zeroValue:256.0)
405406

406407
super.init(frame: frame)
407408

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp