Skip to content

Commit

Permalink
Set the correct range for Y-axis of the token balance graph
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Dec 20, 2021
1 parent 3e01be8 commit 9ee1369
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tribler-gui/tribler_gui/widgets/trustpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tribler_common.sentry_reporter.sentry_mixin import AddBreadcrumbOnShowMixin

from tribler_gui.defs import GB, PB
from tribler_gui.defs import PB, TB
from tribler_gui.dialogs.trustexplanationdialog import TrustExplanationDialog
from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import connect
Expand All @@ -18,7 +18,7 @@ def __init__(self, parent, **kargs):
]
super().__init__(parent, 'Token balance over time', series, **kargs)
self.setLabel('left', 'Data', units='B')
self.setLimits(yMin=-GB, yMax=PB)
self.setLimits(yMin=-TB, yMax=PB)


class TrustPage(AddBreadcrumbOnShowMixin, QWidget):
Expand Down Expand Up @@ -83,6 +83,15 @@ def plot_absolute_values(self) -> None:
"""
Plot the evolution of the token balance.
"""
if self.history:
min_balance = min(item['balance'] for item in self.history)
max_balance = max(item['balance'] for item in self.history)
half = (max_balance - min_balance) / 2
min_limit = min(-TB, min_balance - half)
max_limit = max(PB, max_balance + half)
self.trust_plot.setLimits(yMin=min_limit, yMax=max_limit)
self.trust_plot.setYRange(min_balance, max_balance)

# Convert all dates to a datetime object
for history_item in self.history:
timestamp = history_item["timestamp"] // 1000
Expand Down

0 comments on commit 9ee1369

Please sign in to comment.