Skip to content
Snippets Groups Projects
Commit e8e45d92 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Colour bar tweaks and refactors

parent 721d8704
No related branches found
No related tags found
No related merge requests found
...@@ -26,13 +26,16 @@ import fsl.utils.colourbarbitmap as cbarbmp ...@@ -26,13 +26,16 @@ import fsl.utils.colourbarbitmap as cbarbmp
class ColourBarCanvas(props.HasProperties): class ColourBarCanvas(props.HasProperties):
cmap = props.ColourMap() cmap = props.ColourMap()
vrange = props.Bounds(ndims=1) vrange = props.Bounds(ndims=1)
label = props.String() label = props.String()
orient = props.Choice({ orientation = props.Choice({
'horizontal' : 'Horizontal', 'horizontal' : 'Horizontal',
'vertical' : 'Vertical'}) 'vertical' : 'Vertical'})
labelSide = props.Choice({
'top-left' : 'Top / left',
'bottom-right' : 'Bottom / right'})
def _getSize( self): raise NotImplementedError() def _getSize( self): raise NotImplementedError()
def _setGLContext( self): raise NotImplementedError() def _setGLContext( self): raise NotImplementedError()
...@@ -50,7 +53,7 @@ class ColourBarCanvas(props.HasProperties): ...@@ -50,7 +53,7 @@ class ColourBarCanvas(props.HasProperties):
self._createColourBarTexture() self._createColourBarTexture()
self._refresh() self._refresh()
for prop in ('cmap', 'vrange', 'label', 'orient'): for prop in ('cmap', 'vrange', 'label', 'orientation', 'labelSide'):
self.addListener(prop, self._name, _update) self.addListener(prop, self._name, _update)
...@@ -65,8 +68,15 @@ class ColourBarCanvas(props.HasProperties): ...@@ -65,8 +68,15 @@ class ColourBarCanvas(props.HasProperties):
w, h = self._getSize() w, h = self._getSize()
if w == 0 or h == 0: if w == 0 or h == 0:
if self.orient == 'horizontal': w, h = 600, 200 if self.orientation == 'horizontal': w, h = 600, 200
else: w, h = 200, 600 else: w, h = 200, 600
if self.orientation == 'horizontal':
if self.labelSide == 'top-left': labelSide = 'top'
else: labelSide = 'bottom'
else:
if self.labelSide == 'top-left': labelSide = 'left'
else: labelSide = 'right'
bitmap = cbarbmp.colourBarBitmap( bitmap = cbarbmp.colourBarBitmap(
self.cmap, self.cmap,
...@@ -74,8 +84,8 @@ class ColourBarCanvas(props.HasProperties): ...@@ -74,8 +84,8 @@ class ColourBarCanvas(props.HasProperties):
self.vrange.xhi, self.vrange.xhi,
w, h, w, h,
self.label, self.label,
self.orient, self.orientation,
'bottom') labelSide)
bitmap = np.flipud(bitmap) bitmap = np.flipud(bitmap)
if self._tex is None: if self._tex is None:
......
...@@ -38,6 +38,8 @@ class CanvasPanel(viewpanel.ViewPanel): ...@@ -38,6 +38,8 @@ class CanvasPanel(viewpanel.ViewPanel):
'left' : 'Left', 'left' : 'Left',
'right' : 'Right'}) 'right' : 'Right'})
colourBarLabelSide = colourbarpanel.ColourBarPanel.labelSide
_labels = { _labels = {
'showCursor' : 'Show cursor', 'showCursor' : 'Show cursor',
...@@ -63,6 +65,9 @@ class CanvasPanel(viewpanel.ViewPanel): ...@@ -63,6 +65,9 @@ class CanvasPanel(viewpanel.ViewPanel):
self._imageList, self._imageList,
self._displayCtx) self._displayCtx)
self.bindProps('colourBarLabelSide', self.__colourBar, 'labelSide')
self._configColourBar() self._configColourBar()
self.addListener('showColourBar', self.addListener('showColourBar',
...@@ -75,6 +80,7 @@ class CanvasPanel(viewpanel.ViewPanel): ...@@ -75,6 +80,7 @@ class CanvasPanel(viewpanel.ViewPanel):
def getCanvasPanel(self): def getCanvasPanel(self):
return self.__canvasPanel return self.__canvasPanel
def _configColourBar(self, *a): def _configColourBar(self, *a):
""" """
""" """
...@@ -90,15 +96,21 @@ class CanvasPanel(viewpanel.ViewPanel): ...@@ -90,15 +96,21 @@ class CanvasPanel(viewpanel.ViewPanel):
self.Layout() self.Layout()
return return
self.__colourBar.Show(True) self.__colourBar.Show(True)
if self.colourBarLocation in ('top', 'bottom'): if self.colourBarLocation in ('top', 'bottom'):
self.__colourBar.orientation = 'horizontal'
self.__sizer = wx.BoxSizer(wx.VERTICAL) self.__sizer = wx.BoxSizer(wx.VERTICAL)
else: else:
self.__colourBar.orientation = 'vertical'
self.__sizer = wx.BoxSizer(wx.HORIZONTAL) self.__sizer = wx.BoxSizer(wx.HORIZONTAL)
if self.colourBarLocation in ('top', 'bottom'):
self.__colourBar.orientation = 'horizontal'
elif self.colourBarLocation == 'left':
self.__colourBar.orientation = 'vertical'
elif self.colourBarLocation == 'right':
self.__colourBar.orientation = 'vertical'
if self.colourBarLocation in ('top', 'left'): if self.colourBarLocation in ('top', 'left'):
self.__sizer.Add(self.__colourBar, flag=wx.EXPAND) self.__sizer.Add(self.__colourBar, flag=wx.EXPAND)
self.__sizer.Add(self.__canvasPanel, flag=wx.EXPAND, proportion=1) self.__sizer.Add(self.__canvasPanel, flag=wx.EXPAND, proportion=1)
......
...@@ -27,12 +27,12 @@ class ColourBarPanel(viewpanel.ViewPanel): ...@@ -27,12 +27,12 @@ class ColourBarPanel(viewpanel.ViewPanel):
currently selected image. currently selected image.
""" """
orientation = cbarcanvas.ColourBarCanvas.orient orientation = cbarcanvas.ColourBarCanvas.orientation
"""Draw the colour bar horizontally or vertically. """ """Draw the colour bar horizontally or vertically. """
@classmethod labelSide = cbarcanvas.ColourBarCanvas.labelSide
def isGLView(cls): """Draw colour bar labels on the top/left/right/bottom."""
return True
def __init__(self, def __init__(self,
parent, parent,
...@@ -48,7 +48,8 @@ class ColourBarPanel(viewpanel.ViewPanel): ...@@ -48,7 +48,8 @@ class ColourBarPanel(viewpanel.ViewPanel):
self.SetSizer(self._sizer) self.SetSizer(self._sizer)
self._sizer.Add(self._cbPanel, flag=wx.EXPAND, proportion=1) self._sizer.Add(self._cbPanel, flag=wx.EXPAND, proportion=1)
self.bindProps('orientation', self._cbPanel, 'orient') self.bindProps('orientation', self._cbPanel)
self.bindProps('labelSide' , self._cbPanel)
self.SetBackgroundColour('black') self.SetBackgroundColour('black')
......
...@@ -57,9 +57,10 @@ class OrthoPanel(canvaspanel.CanvasPanel): ...@@ -57,9 +57,10 @@ class OrthoPanel(canvaspanel.CanvasPanel):
'showYCanvas', 'showYCanvas',
'showZCanvas', 'showZCanvas',
'showColourBar', 'showColourBar',
props.Widget( props.Widget('colourBarLocation',
'colourBarLocation', visibleWhen=lambda i: i.showColourBar),
visibleWhen=lambda i: i.showColourBar))), props.Widget('colourBarLabelSide',
visibleWhen=lambda i: i.showColourBar))),
props.VGroup(('xzoom', 'yzoom', 'zzoom')) props.VGroup(('xzoom', 'yzoom', 'zzoom'))
)) ))
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# #
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
# #
"""This module provides a single function, :func:`plotColourBar`, which uses """This module provides a single function, :func:`colourBarBitmap`, which uses
:mod:`matplotlib` to plot a colour bar. The colour bar is rendered off-screen :mod:`matplotlib` to plot a colour bar. The colour bar is rendered off-screen
and returned as an rgba bitmap. and returned as an rgba bitmap.
""" """
...@@ -81,11 +81,6 @@ def colourBarBitmap(cmap, ...@@ -81,11 +81,6 @@ def colourBarBitmap(cmap,
ax.set_xticklabels(('{}'.format(vmin), '{}'.format(vmax))) ax.set_xticklabels(('{}'.format(vmin), '{}'.format(vmax)))
ax.tick_params(colors=textColour, labelsize=fontsize) ax.tick_params(colors=textColour, labelsize=fontsize)
minlbl, maxlbl = ax.get_xticklabels()
minlbl.set_horizontalalignment('left')
maxlbl.set_horizontalalignment('right')
if labelside == 'top': if labelside == 'top':
ax.xaxis.tick_top() ax.xaxis.tick_top()
ax.xaxis.set_label_position('top') ax.xaxis.set_label_position('top')
...@@ -94,6 +89,11 @@ def colourBarBitmap(cmap, ...@@ -94,6 +89,11 @@ def colourBarBitmap(cmap,
ax.xaxis.tick_bottom() ax.xaxis.tick_bottom()
ax.xaxis.set_label_position('bottom') ax.xaxis.set_label_position('bottom')
va = 'bottom' va = 'bottom'
minlbl, maxlbl = ax.get_xticklabels()
minlbl.set_horizontalalignment('left')
maxlbl.set_horizontalalignment('right')
if label is not None: if label is not None:
ax.set_xlabel(label, ax.set_xlabel(label,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment