Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions chaco/horizon_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import with_statement

from numpy import array, transpose, ndarray, empty
from numpy import array, float64, full_like, ndarray, transpose
from traits.api import Instance, DelegatesTo, Bool, Int

from enable.api import transparent_color_trait
Expand All @@ -16,9 +16,7 @@ def map_screen(self, data_array):

if self._null_data_range:
if isinstance(data_array, (tuple, list, ndarray)):
x = empty(data_array.shape)
x.fill(self.low_pos)
return x
return full_like(data_array, self.low_pos, dtype=float64)
else:
return array([self.low_pos])
else:
Expand Down Expand Up @@ -82,7 +80,7 @@ def _render(self, gc, points):
# Get color bands
bands = array(self.color_mapper._get_color_bands())

with gc:
with gc:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor made these fixes, by auto-trimming trailing whitespace. I can revert them if that's preferred.

gc.clip_to_rect(self.x, self.y, self.width, self.height)
# draw positive bands
inc = -1 * array([0, y_plus_height])
Expand All @@ -93,10 +91,10 @@ def _render(self, gc, points):

# draw negative bands
if self.negative_bands:
if self.mirror:
if self.mirror:
points[:,1] = oy - points[:,1]
zeroy = oy
else:
else:
points[:,1] += y_plus_height
inc *= -1
zeroy = int(yhigh) + 2
Expand All @@ -114,14 +112,14 @@ def _render_fill(self, gc, face_col, points, ox, oy):
gc.set_fill_color(tuple(face_col))
gc.begin_path()
startx, starty = points[0]
gc.move_to(startx, oy)
gc.move_to(startx, oy)
gc.line_to(startx, starty)

gc.lines(points)

endx, endy = points[-1]
gc.line_to(endx, oy)
gc.line_to(startx, oy)
gc.line_to(endx, oy)
gc.line_to(startx, oy)

gc.close_path()
gc.fill_path()
6 changes: 2 additions & 4 deletions chaco/linear_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

# Major library imports
from numpy import array, empty, ndarray
from numpy import array, float64, full_like, ndarray

# Enthought library imports
from traits.api import Bool, Float
Expand Down Expand Up @@ -45,9 +45,7 @@ def map_screen(self, data_array):
self._compute_scale()
if self._null_data_range:
if isinstance(data_array, (tuple, list, ndarray)):
x = empty(data_array.shape)
x.fill(self.low_pos)
return x
return full_like(data_array, self.low_pos, dtype=float64)
else:
return array([self.low_pos])
else:
Expand Down
26 changes: 25 additions & 1 deletion chaco/tests/test_linearmapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import unittest
from numpy import array
from numpy import array, ndarray
from numpy.testing import assert_array_almost_equal, assert_equal


Expand Down Expand Up @@ -289,3 +289,27 @@ def test_update_high_pos_dont_stretch_data_with_zero(self):
mapper.high_pos = 100.0
result = mapper.map_screen(ary)
assert_array_almost_equal(result, array([50, 60, 70, 80, 90, 100]))

def test_map_screen_with_null_data_range(self):
r = DataRange1D()
mapper = LinearMapper(range=r)
low_pos = mapper.low_pos

data = array([5.6])
result = mapper.map_screen(data)
self.assertIsInstance(result, ndarray)
self.assertEqual(result.shape, (1,))
assert_array_almost_equal(result, array([low_pos]))

# Test support for lists and tuples
data = [5.6]
result = mapper.map_screen(data)
self.assertIsInstance(result, ndarray)
self.assertEqual(result.shape, (1,))
assert_array_almost_equal(result, array([low_pos]))

data = (5.6,)
result = mapper.map_screen(data)
self.assertIsInstance(result, ndarray)
self.assertEqual(result.shape, (1,))
assert_array_almost_equal(result, array([low_pos]))