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()
|
||||
|
||||
@@ -97,10 +97,8 @@ class GraphControlPanel(wx.Panel):
|
||||
self.fitList = FitList(graphFrame, self)
|
||||
self.fitList.SetMinSize((270, -1))
|
||||
srcTgtSizer.Add(self.fitList, 1, wx.EXPAND | wx.ALL, 0)
|
||||
self.targets = []
|
||||
self.targetList = TargetList(graphFrame, self)
|
||||
self.targetList.SetMinSize((270, -1))
|
||||
self.targetList.update(self.targets)
|
||||
srcTgtSizer.Add(self.targetList, 1, wx.EXPAND | wx.LEFT, 10)
|
||||
mainSizer.Add(srcTgtSizer, 1, wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, 10)
|
||||
|
||||
@@ -116,11 +114,11 @@ class GraphControlPanel(wx.Panel):
|
||||
self.ySubSelection.Clear()
|
||||
self.xSubSelection.Clear()
|
||||
for yDef in view.yDefs:
|
||||
self.ySubSelection.Append(self._formatLabel(yDef), (yDef.handle, yDef.unit))
|
||||
self.ySubSelection.Append(self.formatLabel(yDef), yDef)
|
||||
self.ySubSelection.SetSelection(0)
|
||||
self.ySubSelection.Enable(len(view.yDefs) > 1)
|
||||
for xDef in view.xDefs:
|
||||
self.xSubSelection.Append(self._formatLabel(xDef), (xDef.handle, xDef.unit))
|
||||
self.xSubSelection.Append(self.formatLabel(xDef), xDef)
|
||||
self.xSubSelection.SetSelection(0)
|
||||
self.xSubSelection.Enable(len(view.xDefs) > 1)
|
||||
|
||||
@@ -184,12 +182,11 @@ class GraphControlPanel(wx.Panel):
|
||||
vector.SetDirectionOnly(vectorDef.lengthHandle == mainInputHandle)
|
||||
|
||||
view = self.graphFrame.getView()
|
||||
selectedX = view.xDefMap[self.xType]
|
||||
handledHandles = set()
|
||||
if view.srcVectorDef is not None:
|
||||
handleVector(view.srcVectorDef, self.srcVector, handledHandles, selectedX.mainInput[0])
|
||||
handleVector(view.srcVectorDef, self.srcVector, handledHandles, self.xType.mainInput[0])
|
||||
if view.tgtVectorDef is not None:
|
||||
handleVector(view.tgtVectorDef, self.tgtVector, handledHandles, selectedX.mainInput[0])
|
||||
handleVector(view.tgtVectorDef, self.tgtVector, handledHandles, self.xType.mainInput[0])
|
||||
|
||||
# Update inputs
|
||||
def addInputField(inputDef, handledHandles, mainInput=False):
|
||||
@@ -208,7 +205,7 @@ class GraphControlPanel(wx.Panel):
|
||||
fieldIcon = wx.StaticBitmap(self)
|
||||
fieldIcon.SetBitmap(icon)
|
||||
fieldSizer.Add(fieldIcon, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3)
|
||||
fieldLabel = wx.StaticText(self, wx.ID_ANY, self._formatLabel(inputDef))
|
||||
fieldLabel = wx.StaticText(self, wx.ID_ANY, self.formatLabel(inputDef))
|
||||
fieldSizer.Add(fieldLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0)
|
||||
self.inputsSizer.Add(fieldSizer, 0, wx.EXPAND | wx.BOTTOM, 5)
|
||||
# Store info about added input box
|
||||
@@ -219,7 +216,7 @@ class GraphControlPanel(wx.Panel):
|
||||
self._miscInputBoxes.append(inputBox)
|
||||
|
||||
|
||||
addInputField(view.inputMap[selectedX.mainInput], handledHandles, mainInput=True)
|
||||
addInputField(view.inputMap[self.xType.mainInput], handledHandles, mainInput=True)
|
||||
for inputDef in view.inputs:
|
||||
if inputDef.mainOnly:
|
||||
continue
|
||||
@@ -254,7 +251,6 @@ class GraphControlPanel(wx.Panel):
|
||||
|
||||
def getValues(self):
|
||||
view = self.graphFrame.getView()
|
||||
main = None
|
||||
misc = []
|
||||
processedHandles = set()
|
||||
|
||||
@@ -296,10 +292,18 @@ class GraphControlPanel(wx.Panel):
|
||||
def xType(self):
|
||||
return self.xSubSelection.GetClientData(self.xSubSelection.GetSelection())
|
||||
|
||||
@property
|
||||
def fits(self):
|
||||
return self.fitList.fits
|
||||
|
||||
@property
|
||||
def targets(self):
|
||||
return self.targetList.targetFits
|
||||
|
||||
def unbindExternalEvents(self):
|
||||
self.fitList.unbindExternalEvents()
|
||||
|
||||
def _formatLabel(self, axisDef):
|
||||
def formatLabel(self, axisDef):
|
||||
if axisDef.unit is None:
|
||||
return axisDef.label
|
||||
return '{}, {}'.format(axisDef.label, axisDef.unit)
|
||||
|
||||
Reference in New Issue
Block a user