Integrate graph frame with new APIs
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
# =============================================================================
|
||||
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import traceback
|
||||
|
||||
@@ -188,90 +189,92 @@ class GraphFrame(wx.Frame):
|
||||
if not self:
|
||||
pyfalog.warning('GraphFrame handled event, however GraphFrame no longer exists. Ignoring event')
|
||||
return
|
||||
values = self.ctrlPanel.getValues()
|
||||
# view = self.getView()
|
||||
# self.subplot.clear()
|
||||
# self.subplot.grid(True)
|
||||
# legend = []
|
||||
#
|
||||
# min_y = 0 if self.ctrlPanel.showY0 else None
|
||||
# max_y = 0 if self.ctrlPanel.showY0 else None
|
||||
#
|
||||
# xRange = values['x']
|
||||
# extraInputs = {ih: values[ih] for ih in view.extraInputs}
|
||||
# try:
|
||||
# chosenY = [i for i in view.yDefs.keys()][self.ctrlPanel.selectedY or 0]
|
||||
# except IndexError:
|
||||
# chosenY = [i for i in view.yDefs.keys()][0]
|
||||
#
|
||||
# self.subplot.set(xlabel=view.xDef.axisLabel, ylabel=view.yDefs[chosenY].axisLabel)
|
||||
#
|
||||
# for fit in self.ctrlPanel.fitList.fits:
|
||||
# try:
|
||||
# xs, ys = view.getPlotPoints(fit, extraInputs, xRange, 100, chosenY)
|
||||
#
|
||||
# # Figure out min and max Y
|
||||
# min_y_this = min(ys, default=None)
|
||||
# if min_y is None:
|
||||
# min_y = min_y_this
|
||||
# elif min_y_this is not None:
|
||||
# min_y = min(min_y, min_y_this)
|
||||
# max_y_this = max(ys, default=None)
|
||||
# if max_y is None:
|
||||
# max_y = max_y_this
|
||||
# elif max_y_this is not None:
|
||||
# max_y = max(max_y, max_y_this)
|
||||
#
|
||||
# self.subplot.plot(xs, ys)
|
||||
# legend.append('{} ({})'.format(fit.name, fit.ship.item.getShortName()))
|
||||
# except Exception as ex:
|
||||
# pyfalog.warning('Invalid values in "{0}"', fit.name)
|
||||
# self.canvas.draw()
|
||||
# return
|
||||
#
|
||||
# # Special case for when we do not show Y = 0 and have no fits
|
||||
# if min_y is None:
|
||||
# min_y = 0
|
||||
# if max_y is None:
|
||||
# max_y = 0
|
||||
# # Extend range a little for some visual space
|
||||
# y_range = max_y - min_y
|
||||
# min_y -= y_range * 0.05
|
||||
# max_y += y_range * 0.05
|
||||
# if min_y == max_y:
|
||||
# min_y -= min_y * 0.05
|
||||
# max_y += min_y * 0.05
|
||||
# if min_y == max_y:
|
||||
# min_y -= 5
|
||||
# max_y += 5
|
||||
# self.subplot.set_ylim(bottom=min_y, top=max_y)
|
||||
#
|
||||
# legend2 = []
|
||||
# legend_colors = {
|
||||
# 0: 'blue',
|
||||
# 1: 'orange',
|
||||
# 2: 'green',
|
||||
# 3: 'red',
|
||||
# 4: 'purple',
|
||||
# 5: 'brown',
|
||||
# 6: 'pink',
|
||||
# 7: 'grey',
|
||||
# }
|
||||
#
|
||||
# for i, i_name in enumerate(legend):
|
||||
# try:
|
||||
# selected_color = legend_colors[i]
|
||||
# except:
|
||||
# selected_color = None
|
||||
# legend2.append(Patch(color=selected_color, label=i_name), )
|
||||
#
|
||||
# if len(legend2) > 0:
|
||||
# leg = self.subplot.legend(handles=legend2)
|
||||
# for t in leg.get_texts():
|
||||
# t.set_fontsize('small')
|
||||
#
|
||||
# for l in leg.get_lines():
|
||||
# l.set_linewidth(1)
|
||||
#
|
||||
# self.canvas.draw()
|
||||
|
||||
self.subplot.clear()
|
||||
self.subplot.grid(True)
|
||||
legend = []
|
||||
|
||||
min_y = 0 if self.ctrlPanel.showY0 else None
|
||||
max_y = 0 if self.ctrlPanel.showY0 else None
|
||||
|
||||
chosenX = self.ctrlPanel.xType
|
||||
chosenY = self.ctrlPanel.yType
|
||||
self.subplot.set(xlabel=self.ctrlPanel.formatLabel(chosenX), ylabel=self.ctrlPanel.formatLabel(chosenY))
|
||||
|
||||
mainInput, miscInputs = self.ctrlPanel.getValues()
|
||||
view = self.getView()
|
||||
fits = self.ctrlPanel.fits
|
||||
if view.hasTargets:
|
||||
targets = self.ctrlPanel.targets
|
||||
iterList = tuple(itertools.combinations(fits, targets))
|
||||
else:
|
||||
iterList = tuple((f, None) for f in fits)
|
||||
for fit, target in iterList:
|
||||
try:
|
||||
xs, ys = view.getPlotPoints(mainInput, miscInputs, chosenX, chosenY, fit, target)
|
||||
|
||||
# Figure out min and max Y
|
||||
min_y_this = min(ys, default=None)
|
||||
if min_y is None:
|
||||
min_y = min_y_this
|
||||
elif min_y_this is not None:
|
||||
min_y = min(min_y, min_y_this)
|
||||
max_y_this = max(ys, default=None)
|
||||
if max_y is None:
|
||||
max_y = max_y_this
|
||||
elif max_y_this is not None:
|
||||
max_y = max(max_y, max_y_this)
|
||||
|
||||
self.subplot.plot(xs, ys)
|
||||
legend.append('{} ({})'.format(fit.name, fit.ship.item.getShortName()))
|
||||
except Exception as ex:
|
||||
pyfalog.warning('Invalid values in "{0}"', fit.name)
|
||||
self.canvas.draw()
|
||||
return
|
||||
|
||||
# Special case for when we do not show Y = 0 and have no fits
|
||||
if min_y is None:
|
||||
min_y = 0
|
||||
if max_y is None:
|
||||
max_y = 0
|
||||
# Extend range a little for some visual space
|
||||
y_range = max_y - min_y
|
||||
min_y -= y_range * 0.05
|
||||
max_y += y_range * 0.05
|
||||
if min_y == max_y:
|
||||
min_y -= min_y * 0.05
|
||||
max_y += min_y * 0.05
|
||||
if min_y == max_y:
|
||||
min_y -= 5
|
||||
max_y += 5
|
||||
self.subplot.set_ylim(bottom=min_y, top=max_y)
|
||||
|
||||
legend2 = []
|
||||
legend_colors = {
|
||||
0: 'blue',
|
||||
1: 'orange',
|
||||
2: 'green',
|
||||
3: 'red',
|
||||
4: 'purple',
|
||||
5: 'brown',
|
||||
6: 'pink',
|
||||
7: 'grey',
|
||||
}
|
||||
|
||||
for i, i_name in enumerate(legend):
|
||||
try:
|
||||
selected_color = legend_colors[i]
|
||||
except:
|
||||
selected_color = None
|
||||
legend2.append(Patch(color=selected_color, label=i_name), )
|
||||
|
||||
if len(legend2) > 0:
|
||||
leg = self.subplot.legend(handles=legend2)
|
||||
for t in leg.get_texts():
|
||||
t.set_fontsize('small')
|
||||
|
||||
for l in leg.get_lines():
|
||||
l.set_linewidth(1)
|
||||
|
||||
self.canvas.draw()
|
||||
self.Refresh()
|
||||
|
||||
Reference in New Issue
Block a user