Skip to content

Commit

Permalink
Merge 43efe15 into 40a4738
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Nov 5, 2014
2 parents 40a4738 + 43efe15 commit 8012f41
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
9 changes: 5 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ What's new in Chaco 4.5.0

Change summary since 4.4.1

New features
New features/Improvements

* Added perceptual colormaps by Matteo Niccoli, Dave Green and Kenneth Moreland.

* Added asynchronous_updates.py demo that shows a pattern for generating
* Added `asynchronous_updates.py` demo that shows a pattern for generating
expensive plots while keeping the interface responsive (PR#170).
* Speeded up by 10x the data mappers of the `GridMapper` class (mapping of 2D data
to/from screen space).

Fixes

Expand All @@ -22,7 +23,7 @@ Fixes
* Make the `alpha` attribute of scatter plots work as intended (PR#164).
* Resume running test for empty container that has been skipped (PR#190).
* Improved handling of missing or empty data in scatterplot (PR#210)
* Avoid a numpy crash when using a data source of a unicode array (PR#213).
* Avoid a NumPy crash when using a data source of a unicode array (PR#213).
* PanTool with `restrict_to_data` selected works with empty data sources
(PR#215).
* RangeSelection properly clips bounds when leaving selection area (PR#217).
Expand Down
8 changes: 5 additions & 3 deletions chaco/grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import contextmanager

# Major library imports
from numpy import transpose
from numpy import column_stack, transpose

# Enthought library imports
from traits.api import Bool, DelegatesTo, Instance, Float, Property
Expand Down Expand Up @@ -119,7 +119,8 @@ def map_screen(self, data_pts):
xs, ys = transpose(data_pts)
screen_xs = self._xmapper.map_screen(xs)
screen_ys = self._ymapper.map_screen(ys)
return zip(screen_xs, screen_ys)
screen_pts = column_stack([screen_xs, screen_ys])
return screen_pts

def map_data(self, screen_pts):
""" map_data(screen_pts) -> data_vals
Expand All @@ -129,7 +130,8 @@ def map_data(self, screen_pts):
screen_xs, screen_ys = transpose(screen_pts)
xs = self._xmapper.map_data(screen_xs)
ys = self._ymapper.map_data(screen_ys)
return zip(xs, ys)
data_pts = column_stack([xs, ys])
return data_pts

def map_data_array(self, screen_pts):
return self.map_data(screen_pts)
Expand Down
48 changes: 38 additions & 10 deletions chaco/tests/grid_mapper_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,48 @@

class GridMapperTestCase(unittest.TestCase):

def test_basic(self):
x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
ds = GridDataSource(xdata=x_ary, ydata=y_ary)
def setUp(self):
self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary)
r = DataRange2D(ds)
mapper = GridMapper(range=r)
mapper.x_low_pos=50
mapper.x_high_pos=100
mapper.y_low_pos=0
mapper.y_high_pos=10
result = mapper.map_screen(transpose((x_ary, y_ary)))
self.mapper = GridMapper(range=r)

def test_basic(self):
self.mapper.x_low_pos=50
self.mapper.x_high_pos=100
self.mapper.y_low_pos=0
self.mapper.y_high_pos=10
result = self.mapper.map_screen(transpose((self.x_ary, self.y_ary)))
assert_equal(result, [(50,0), (60,0), (70,5),
(80,5), (90,10), (100,10)])

def test_map_screen_scalar(self):
self.mapper.x_low_pos=50
self.mapper.x_high_pos=100
self.mapper.y_low_pos=0
self.mapper.y_high_pos=10
result = self.mapper.map_screen(transpose((6.0, 1.0)))
assert_equal(result, [[60, 0]])

def test_map_data(self):
self.mapper.x_low_pos=50
self.mapper.x_high_pos=100
self.mapper.y_low_pos=0
self.mapper.y_high_pos=10
screen_ary = array([(50,0), (60,0), (70,5), (80,5), (90,10), (100,10)])
result = self.mapper.map_data(screen_ary)
assert_equal(result, transpose((self.x_ary, self.y_ary)))

def test_map_data_scalar(self):
self.mapper.x_low_pos=50
self.mapper.x_high_pos=100
self.mapper.y_low_pos=0
self.mapper.y_high_pos=10
screen_ary = (60, 0)
result = self.mapper.map_data(screen_ary)
assert_equal(result, [[6.0, 1.0]])


if __name__ == '__main__':
import nose
Expand Down

0 comments on commit 8012f41

Please sign in to comment.