Changeset b016f17 in sasview for src/sas/qtgui/Plotting/Plotter.py


Ignore:
Timestamp:
Mar 28, 2019 11:24:38 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_opencl
Children:
73fb503
Parents:
b8bdbcc
Message:

Resize matplotlib legend with canvas size. SASVIEW-1000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotting/Plotter.py

    r4c11b2a rb016f17  
    1919import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    2020import sas.qtgui.Plotting.PlotUtilities as PlotUtilities 
     21 
     22def _legendResize(width): 
     23    """ 
     24    resize factor for the legend, based on total canvas width 
     25    """ 
     26    # The factor 4.0 was chosen to look similar in size/ratio to what we had in 4.x 
     27    return (width/100.0)+4.0 
    2128 
    2229class PlotterWidget(PlotterBase): 
     
    194201 
    195202        if self.showLegend: 
    196             self.legend = ax.legend(loc='upper right', shadow=True) 
     203            width=_legendResize(self.canvas.size().width()) 
     204 
     205            self.legend = ax.legend(loc='upper right', shadow=True, prop={'size':width}) 
    197206            if self.legend: 
    198207                self.legend.set_picker(True) 
     
    206215        # refresh canvas 
    207216        self.canvas.draw_idle() 
     217 
     218    def onResize(self, event): 
     219        """ 
     220        Resize the legend window/font on canvas resize 
     221        """ 
     222        width = _legendResize(event.width) 
     223        # resize the legend to follow the canvas width. 
     224        self.legend.prop.set_size(width) 
    208225 
    209226    def createContextMenu(self): 
Note: See TracChangeset for help on using the changeset viewer.