[GRASS-SVN] r72523 - grass/trunk/gui/wxpython/tplot

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 23 02:54:22 PDT 2018


Author: lucadelu
Date: 2018-03-23 02:54:22 -0700 (Fri, 23 Mar 2018)
New Revision: 72523

Modified:
   grass/trunk/gui/wxpython/tplot/frame.py
Log:
g.gui.tplot: added capabilities to set x,y axis labels and title for the plot

Modified: grass/trunk/gui/wxpython/tplot/frame.py
===================================================================
--- grass/trunk/gui/wxpython/tplot/frame.py	2018-03-23 09:27:40 UTC (rev 72522)
+++ grass/trunk/gui/wxpython/tplot/frame.py	2018-03-23 09:54:22 UTC (rev 72523)
@@ -152,7 +152,6 @@
         self.canvas = FigCanvas(self.mainPanel, wx.ID_ANY, self.fig)
         # axes are initialized later
         self.axes2d = None
-        self.axes3d = None
 
         # Create the navigation toolbar, tied to the canvas
         #
@@ -268,6 +267,35 @@
         self.controlPanelSizerVector.Fit(self)
         self.ntb.AddPage(page=self.controlPanelVector, text=_('STVDS'),
                          name='STVDS')
+        
+        # ------------ITEMS IN NOTEBOOK PAGE (LABELS)------------------------
+        self.controlPanelLabels = wx.Panel(parent=self.ntb, id=wx.ID_ANY)
+        self.titleLabel = wx.StaticText(parent=self.controlPanelLabels,
+                                        id=wx.ID_ANY,
+                                        label=_('Set title for the plot'))
+        self.title = wx.TextCtrl(parent=self.controlPanelLabels, id=wx.ID_ANY,
+                                  size=globalvar.DIALOG_TEXTCTRL_SIZE)
+        self.xLabel = wx.StaticText(parent=self.controlPanelLabels,
+                                        id=wx.ID_ANY,
+                                        label=_('Set label for X axis'))
+        self.x = wx.TextCtrl(parent=self.controlPanelLabels, id=wx.ID_ANY,
+                                  size=globalvar.DIALOG_TEXTCTRL_SIZE)
+        self.yLabel = wx.StaticText(parent=self.controlPanelLabels,
+                                        id=wx.ID_ANY,
+                                        label=_('Set label for Y axis'))
+        self.y = wx.TextCtrl(parent=self.controlPanelLabels, id=wx.ID_ANY,
+                                  size=globalvar.DIALOG_TEXTCTRL_SIZE)
+        self.controlPanelSizerLabels = wx.BoxSizer(wx.VERTICAL)
+        self.controlPanelSizerLabels.Add(self.titleLabel, flag=wx.EXPAND)
+        self.controlPanelSizerLabels.Add(self.title, flag=wx.EXPAND)
+        self.controlPanelSizerLabels.Add(self.xLabel, flag=wx.EXPAND)
+        self.controlPanelSizerLabels.Add(self.x, flag=wx.EXPAND)
+        self.controlPanelSizerLabels.Add(self.yLabel, flag=wx.EXPAND)
+        self.controlPanelSizerLabels.Add(self.y, flag=wx.EXPAND)
+        self.controlPanelLabels.SetSizer(self.controlPanelSizerLabels)
+        self.controlPanelSizerLabels.Fit(self)
+        self.ntb.AddPage(page=self.controlPanelLabels, text=_('Labels'),
+                         name='Labels')
 
         # ------------Buttons on the bottom(draw,help)------------
         self.vButtPanel = wx.Panel(self.mainPanel, id=wx.ID_ANY)
@@ -543,6 +571,9 @@
         self.yticksNames = []
         self.yticksPos = []
         self.plots = []
+        self.drawTitle = self.title.GetValue()
+        self.drawX = self.x.GetValue()
+        self.drawY = self.y.GetValue()
 
         if self.datasetsR:
             self.lookUp = LookUp(self.timeDataR, self.invconvert)
@@ -560,6 +591,23 @@
         self.canvas.draw()
         DataCursor(self.plots, self.lookUp, InfoFormat, self.convert)
 
+    def _setLabels(self, x):
+        """Function to set the right labels"""
+        if self.drawX != '':
+            self.axes2d.set_xlabel(self.drawX)
+        else:
+            if self.temporalType == 'absolute':
+                self.axes2d.set_xlabel(_("Temporal resolution: %s" %  x ))
+            else:
+                self.axes2d.set_xlabel(_("Time [%s]") % self.unit)
+        if self.drawY != '':
+            self.axes2d.set_ylabel(self.drawY)
+        else:
+            self.axes2d.set_ylabel(', '.join(self.yticksNames))
+        print(self.drawTitle)
+        if self.drawTitle != '':
+            self.axes2d.set_title(self.drawTitle)
+        
     def drawR(self):
         for i, name in enumerate(self.datasetsR):
             name = name[0]
@@ -587,13 +635,7 @@
                                                color=color,
                                                label=self.plotNameListR[i])[0])
 
-        if self.temporalType == 'absolute':
-            self.axes2d.set_xlabel(
-                _("Temporal resolution: %s" % self.timeDataR[name]['granularity']))
-        else:
-            self.axes2d.set_xlabel(_("Time [%s]") % self.unit)
-        self.axes2d.set_ylabel(', '.join(self.yticksNames))
-
+        self._setLabels(self.timeDataR[name]['granularity'])
         # legend
         handles, labels = self.axes2d.get_legend_handles_labels()
         self.axes2d.legend(loc=0)
@@ -639,12 +681,7 @@
                     color=color,
                     label=labelname)[0])
         # ============================
-        if self.temporalType == 'absolute':
-            self.axes2d.set_xlabel(
-                _("Temporal resolution: %s" % self.timeDataV[name]['granularity']))
-        else:
-            self.axes2d.set_xlabel(_("Time [%s]") % self.unit)
-        self.axes2d.set_ylabel(', '.join(self.yticksNames))
+        self._setLabels(self.timeDataV[name]['granularity'])
 
         # legend
         handles, labels = self.axes2d.get_legend_handles_labels()
@@ -677,12 +714,7 @@
             self.plots.append(self.axes2d.plot(xdata, ydata, marker='o',
                                                color=color, label=name)[0])
         # ============================
-        if self.temporalType == 'absolute':
-            self.axes2d.set_xlabel(
-                _("Temporal resolution: %s" % self.timeDataV[name]['granularity']))
-        else:
-            self.axes2d.set_xlabel(_("Time [%s]") % self.unit)
-        self.axes2d.set_ylabel(', '.join(self.yticksNames))
+        self._setLabels(self.timeDataV[name]['granularity'])
 
         # legend
         handles, labels = self.axes2d.get_legend_handles_labels()



More information about the grass-commit mailing list