fix #3962
This commit is contained in:
parent
1825c92bbc
commit
55a0a6b7f0
|
@ -33,7 +33,7 @@ from electrum.util import block_explorer_URL
|
||||||
from electrum.util import timestamp_to_datetime, profiler
|
from electrum.util import timestamp_to_datetime, profiler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from electrum.plot import plot_history
|
from electrum.plot import plot_history, NothingToPlotException
|
||||||
except:
|
except:
|
||||||
plot_history = None
|
plot_history = None
|
||||||
|
|
||||||
|
@ -195,11 +195,11 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
||||||
_("Can't plot history.") + '\n' +
|
_("Can't plot history.") + '\n' +
|
||||||
_("Perhaps some dependencies are missing...") + " (matplotlib?)")
|
_("Perhaps some dependencies are missing...") + " (matplotlib?)")
|
||||||
return
|
return
|
||||||
if len(self.transactions) > 0:
|
try:
|
||||||
plt = plot_history(self.transactions)
|
plt = plot_history(self.transactions)
|
||||||
plt.show()
|
plt.show()
|
||||||
else:
|
except NothingToPlotException as e:
|
||||||
self.parent.show_message(_("Nothing to plot."))
|
self.parent.show_message(str(e))
|
||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
|
|
16
lib/plot.py
16
lib/plot.py
|
@ -14,7 +14,14 @@ from matplotlib.patches import Ellipse
|
||||||
from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker
|
from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker
|
||||||
|
|
||||||
|
|
||||||
|
class NothingToPlotException(Exception):
|
||||||
|
def __str__(self):
|
||||||
|
return _("Nothing to plot.")
|
||||||
|
|
||||||
|
|
||||||
def plot_history(history):
|
def plot_history(history):
|
||||||
|
if len(history) == 0:
|
||||||
|
raise NothingToPlotException()
|
||||||
hist_in = defaultdict(int)
|
hist_in = defaultdict(int)
|
||||||
hist_out = defaultdict(int)
|
hist_out = defaultdict(int)
|
||||||
for item in history:
|
for item in history:
|
||||||
|
@ -42,7 +49,12 @@ def plot_history(history):
|
||||||
xfmt = md.DateFormatter('%Y-%m')
|
xfmt = md.DateFormatter('%Y-%m')
|
||||||
ax.xaxis.set_major_formatter(xfmt)
|
ax.xaxis.set_major_formatter(xfmt)
|
||||||
width = 20
|
width = 20
|
||||||
dates, values = zip(*sorted(hist_in.items()))
|
|
||||||
|
r1 = None
|
||||||
|
r2 = None
|
||||||
|
dates_values = list(zip(*sorted(hist_in.items())))
|
||||||
|
if dates_values and len(dates_values) == 2:
|
||||||
|
dates, values = dates_values
|
||||||
r1 = axarr[0].bar(dates, values, width, label='incoming')
|
r1 = axarr[0].bar(dates, values, width, label='incoming')
|
||||||
axarr[0].legend(loc='upper left')
|
axarr[0].legend(loc='upper left')
|
||||||
dates_values = list(zip(*sorted(hist_out.items())))
|
dates_values = list(zip(*sorted(hist_out.items())))
|
||||||
|
@ -50,4 +62,6 @@ def plot_history(history):
|
||||||
dates, values = dates_values
|
dates, values = dates_values
|
||||||
r2 = axarr[1].bar(dates, values, width, color='r', label='outgoing')
|
r2 = axarr[1].bar(dates, values, width, color='r', label='outgoing')
|
||||||
axarr[1].legend(loc='upper left')
|
axarr[1].legend(loc='upper left')
|
||||||
|
if r1 is None and r2 is None:
|
||||||
|
raise NothingToPlotException()
|
||||||
return plt
|
return plt
|
||||||
|
|
Loading…
Reference in New Issue