Skip to content

Commit

Permalink
MIN: fix several issues with ColorBarWidget/ColorBarVisual
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Sep 17, 2016
1 parent d2ae4eb commit bf5d6d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/basics/scene/colorbar_widget.py
Expand Up @@ -16,11 +16,11 @@
canvas.show()
grid = canvas.central_widget.add_grid(margin=10)


cbar_widget = scene.ColorBarWidget(cmap="cool", orientation="right")
cbar_widget = scene.ColorBarWidget(label="ColorBarWidget", clim=(0, 99),
cmap="cool", orientation="right",
border_width=1)
grid.add_widget(cbar_widget)

cbar_widget.pos = (300, 100)
cbar_widget.border_color = "#212121"
grid.bgcolor = "#ffffff"

Expand Down
33 changes: 31 additions & 2 deletions vispy/scene/widgets/colorbar.py
Expand Up @@ -67,13 +67,14 @@ class ColorBarWidget(Widget):
minor_axis_ratio = 0.05

def __init__(self, cmap, orientation,
label="", clim=("", ""),
label="", clim=("", ""), label_color='black',
border_width=0.0, border_color="black", **kwargs):

dummy_size = (1, 1)
self._colorbar = ColorBarVisual(size=dummy_size, cmap=cmap,
orientation=orientation,
label=label, clim=clim,
label_str=label, clim=clim,
label_color=label_color,
border_width=border_width,
border_color=border_color, **kwargs)

Expand Down Expand Up @@ -141,6 +142,14 @@ def label(self):
def label(self, label):
self._colorbar.label = label

@property
def ticks(self):
return self._colorbar.ticks

@ticks.setter
def ticks(self, ticks):
self._colorbar.ticks = ticks

@property
def clim(self):
return self._colorbar.clim
Expand All @@ -149,6 +158,26 @@ def clim(self):
def clim(self, clim):
self._colorbar.clim = clim

@property
def border_color(self):
""" The color of the border around the ColorBar in pixels
"""
return self._colorbar.border_color

@border_color.setter
def border_color(self, border_color):
self._colorbar.border_color = border_color

@property
def border_width(self):
""" The width of the border around the ColorBar in pixels
"""
return self._colorbar.border_width

@border_width.setter
def border_width(self, border_width):
self._colorbar.border_width = border_width

@property
def orientation(self):
return self._colorbar.orientation
10 changes: 6 additions & 4 deletions vispy/visuals/colorbar.py
Expand Up @@ -275,23 +275,25 @@ class ColorBarVisual(CompoundVisual):
def __init__(self, cmap, orientation, size,
pos=[0, 0],
label_str="",
label_color='black',
clim=(0.0, 1.0),
border_width=1.0,
border_color="black",
**kwargs):

self._label_str = label_str
self._label_color = label_color
self._cmap = get_colormap(cmap)
self._clim = clim
self._pos = pos
self._size = size
self._orientation = orientation

self._label = TextVisual(text=self._label_str)
self._label = TextVisual(self._label_str, color=self._label_color)

self._ticks = []
self._ticks.append(TextVisual(str(self._clim[0])))
self._ticks.append(TextVisual(str(self._clim[1])))
self._ticks.append(TextVisual(str(self._clim[0]), color=self._label_color))
self._ticks.append(TextVisual(str(self._clim[1]), color=self._label_color))

if orientation in ["top", "bottom"]:
(width, height) = size
Expand Down Expand Up @@ -323,7 +325,6 @@ def _update(self):
self._colorbar.halfdim = self._halfdim
self._border.halfdim = self._halfdim

self._label.text = self._label_str
self._ticks[0].text = str(self._clim[0])
self._ticks[1].text = str(self._clim[1])

Expand Down Expand Up @@ -634,6 +635,7 @@ def border_color(self):
@border_color.setter
def border_color(self, border_color):
self._border.border_color = border_color
self._update()

@property
def orientation(self):
Expand Down

0 comments on commit bf5d6d0

Please sign in to comment.