2 from utils import Logger
5 _PICKER_PRECISION = 20 #pts
7 def __init__(self, controller, parentXYView):
8 View.__init__(self, controller)
11 self._isHighlighted = False
12 self._initialLineWidth = None
13 self._parentXYView = parentXYView
17 self._lineStyle = None
19 def setMPLAxes(self, axes):
23 self._mplAxes.lines.remove(self._mplLines[0])
28 x_idx, y_idx = m.getXAxisIndex(), m.getYAxisIndex()
29 d = self._model.getTable().getData()
30 self._mplLines = self._mplAxes.plot(d[:, x_idx], d[:, y_idx], label=m._title,
31 picker=self._PICKER_PRECISION)
32 self._initialLineWidth = self._mplLines[0].get_linewidth()
34 def onCurveTitleChange(self):
35 if self._mplLines is None:
37 self._mplLines[0].set_label(self._model._title)
40 Logger.Debug("CurveView::udpate")
41 if self._mplLines is None:
43 lineStyle, marker, color = self.getLineStyle(), self.getMarker(), self.getColor()
46 # Reset correctly color, marker and highlight state
47 self.setLineStyle(lineStyle)
48 self.setMarker(marker)
50 self.toggleHighlight(self._isHighlighted, force=True)
52 def setLineStyle(self, lin_style):
53 lin = self._mplLines[0]
54 lin.set_linestyle(lin_style)
56 def getLineStyle(self):
57 if self._mplLines is None:
59 return self._mplLines[0].get_linestyle()
61 def setMarker(self, marker):
62 lin = self._mplLines[0]
63 lin.set_marker(marker)
66 if self._mplLines is None:
68 return self._mplLines[0].get_marker()
70 def toggleHighlight(self, highlight, force=False):
71 lin = self._mplLines[0]
72 if highlight and (force or not self._isHighlighted):
73 lin.set_linewidth(2*self._initialLineWidth)
74 self._isHighlighted = True
75 elif not highlight and (force or self._isHighlighted):
76 lin.set_linewidth(self._initialLineWidth)
77 self._isHighlighted = False
79 # Nothing to do, already the correct state
82 def isHighlighted(self):
83 return self._isHighlighted
85 def setColor(self, rgb_color):
86 lin = self._mplLines[0]
87 lin.set_color(rgb_color)
90 if self._mplLines is None:
92 return self._mplLines[0].get_color()