1
1
""" Defines the ColorBar class.
4
from __future__ import with_statement
3
6
# Major library imports
4
7
from numpy import array, arange, ones, transpose, uint8
6
9
# Enthought library imports
7
from enthought.traits.api import Any, Bool, Enum, Instance, Property
8
from enthought.kiva.backend_image import GraphicsContext
10
from enthought.traits.api import Any, Bool, Enum, Instance, Property, \
11
cached_property, on_trait_change
12
from enthought.kiva.image import GraphicsContext
11
15
from base_xy_plot import BaseXYPlot
25
29
# Screen mapper for color data
26
30
color_mapper = Property #Instance(ColorMapper)
32
# Screen mapper for value data (synonym for color_mapper)
33
value_mapper = Property(depends_on='color_mapper')
28
35
# Optional index data source for generic tools to attach metadata to.
123
130
""" Draws the 'plot' layer.
125
132
self._update_mappers()
127
if self.orientation == 'h':
128
perpendicular_dim = 1
131
perpendicular_dim = 0
134
mapper = self.index_mapper
136
scrn_points = arange(mapper.low_pos, mapper.high_pos+1)
138
# Get the data values associated with the list of screen points.
139
if mapper.range.low == mapper.range.high:
140
# LogMapper.map_data() returns something unexpected if low==high,
141
# so we'll handle that case here.
142
data_points = array([mapper.range.high])
144
data_points = mapper.map_data(scrn_points)
146
if self.direction == 'flipped':
147
data_points = data_points[::-1]
149
# Get the colors associated with the data points.
150
colors = self.color_mapper.map_screen(data_points)
152
img = self._make_color_image(colors, self.bounds[perpendicular_dim],
153
self.orientation, self.direction)
134
if self.orientation == 'h':
135
perpendicular_dim = 1
138
perpendicular_dim = 0
141
mapper = self.index_mapper
143
scrn_points = arange(mapper.low_pos, mapper.high_pos+1)
145
# Get the data values associated with the list of screen points.
146
if mapper.range.low == mapper.range.high:
147
# LogMapper.map_data() returns something unexpected if low==high,
148
# so we'll handle that case here.
149
data_points = array([mapper.range.high])
151
data_points = mapper.map_data(scrn_points)
153
if self.direction == 'flipped':
154
data_points = data_points[::-1]
156
# Get the colors associated with the data points.
157
colors = self.color_mapper.map_screen(data_points)
159
img = self._make_color_image(colors, self.bounds[perpendicular_dim],
160
self.orientation, self.direction)
155
161
gc.draw_image(img, (self.x, self.y, self.width, self.height))
159
163
def _make_color_image(self, color_values, width, orientation, direction):
268
276
def _set_color_mapper(self, val):
269
277
self._color_mapper = val
280
def _get_value_mapper(self):
281
return self._get_color_mapper()
283
def _set_value_mapper(self, val):
284
self._set_color_mapper(val)
271
286
def _get_index(self):
272
287
if self.plot and hasattr(self.plot, "color_data"):