Change how rounding on Y ticks happens - now it relies on shown Y range

This commit is contained in:
DarkPhoenix
2019-08-26 03:35:35 +03:00
parent 1c1443c862
commit 380e9c2e87
2 changed files with 12 additions and 13 deletions

View File

@@ -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)