Change how rounding on Y ticks happens - now it relies on shown Y range
This commit is contained in:
@@ -188,6 +188,7 @@ class GraphCanvasPanel(wx.Panel):
|
||||
if minX is not None and maxX is not None:
|
||||
minY = min(allYs, default=None)
|
||||
maxY = max(allYs, default=None)
|
||||
yDiff = (maxY or 0) - (minY or 0)
|
||||
xMark = max(min(self.xMark, maxX), minX)
|
||||
# If in top 10% of X coordinates, align labels differently
|
||||
if xMark > canvasMinX + 0.9 * (canvasMaxX - canvasMinX):
|
||||
@@ -214,7 +215,12 @@ class GraphCanvasPanel(wx.Panel):
|
||||
def addYMark(val):
|
||||
if val is None:
|
||||
return
|
||||
rounded = roundToPrec(val, 4)
|
||||
# Round according to shown Y range - the bigger the range,
|
||||
# the rougher the rounding
|
||||
if yDiff != 0:
|
||||
rounded = roundToPrec(val, 4, nsValue=yDiff)
|
||||
else:
|
||||
rounded = val
|
||||
# If due to some bug or insufficient plot density we're
|
||||
# out of bounds, do not add anything
|
||||
if minY <= val <= maxY or minY <= rounded <= maxY:
|
||||
|
||||
@@ -99,12 +99,15 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
return result
|
||||
|
||||
|
||||
def roundToPrec(val, prec):
|
||||
def roundToPrec(val, prec, nsValue=None):
|
||||
"""
|
||||
nsValue: custom value which should be used to determine normalization shift
|
||||
"""
|
||||
# We're not rounding integers anyway
|
||||
# Also make sure that we do not ask to calculate logarithm of zero
|
||||
if int(val) == val:
|
||||
return int(val)
|
||||
roundFactor = int(prec - getNormalizationShift(val) - 1)
|
||||
roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1)
|
||||
# But we don't want to round integers
|
||||
if roundFactor < 0:
|
||||
roundFactor = 0
|
||||
@@ -116,16 +119,6 @@ def roundToPrec(val, prec):
|
||||
return val
|
||||
|
||||
|
||||
def getNormalizationShift(val):
|
||||
"""
|
||||
Given a value, return how many positions to the left we should shift
|
||||
decimal separator to get number in range of [1, 10)
|
||||
"""
|
||||
if val == 0:
|
||||
return None
|
||||
return math.floor(math.log10(abs(val)))
|
||||
|
||||
|
||||
def roundDec(val, prec):
|
||||
if int(val) == val:
|
||||
return int(val)
|
||||
|
||||
Reference in New Issue
Block a user