Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup map_screen return types #726

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1f7a059
make return types of map_screen consistent
aaronayres35 May 4, 2021
9e219a0
use np for numpy
aaronayres35 May 4, 2021
8eedf6c
flake8
aaronayres35 May 4, 2021
32f6c07
update cursor_tool.py to expect Nx2 array output from map_screen
aaronayres35 May 4, 2021
8861984
expect correct return type
aaronayres35 May 4, 2021
74175b8
add a regression test for 272
aaronayres35 May 5, 2021
9c85c5a
run same test on a couple more renderers
aaronayres35 May 5, 2021
ad93274
add a test for SegmentPlot which does its own thing
aaronayres35 May 5, 2021
527bdb9
add explicit map_screen specific test for ImagePlot
aaronayres35 May 5, 2021
db31b7b
test map screen on no data points ImagePlot
aaronayres35 May 5, 2021
206bc72
have Plot tests also test map_screen on no data points
aaronayres35 May 5, 2021
d85658a
Revert "use np for numpy"
aaronayres35 May 5, 2021
fabfc25
follow existing lead of using numpy / remove unneeded [0]
aaronayres35 May 5, 2021
8639b2d
add regression test for enthought/chaco#289
aaronayres35 May 5, 2021
48e7f9f
add comment
aaronayres35 May 5, 2021
77436ac
add regression test for 550
aaronayres35 May 6, 2021
e7fd534
flake8
aaronayres35 May 6, 2021
0bf267e
more updates
aaronayres35 May 6, 2021
8106488
Merge branch 'master' into cleanup-mapscreen
aaronayres35 May 10, 2021
9e6da2e
remove debugging print statement
aaronayres35 May 12, 2021
2f9a95a
clean up map_screen use in LinearMapper hittest method
aaronayres35 May 12, 2021
edcd163
Merge branch 'master' into cleanup-mapscreen
aaronayres35 Jun 2, 2021
a35b264
flake8
aaronayres35 Jun 2, 2021
58f3a00
be less strict in BaseXYPlot
aaronayres35 Jun 2, 2021
b961f4c
Merge branch 'master' into cleanup-mapscreen
aaronayres35 Jun 8, 2021
b8345bf
Merge branch 'master' into cleanup-mapscreen
aaronayres35 Jul 7, 2021
704c758
Remove repeated test_segment_plot_map_screen
aaronayres35 Jul 7, 2021
095d4dc
Merge branch 'master' into cleanup-mapscreen
aaronayres35 Jul 7, 2021
32e2ec6
Remove redundant import
aaronayres35 Jul 7, 2021
dd3774c
dont remove copyright header
aaronayres35 Jul 7, 2021
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
6 changes: 5 additions & 1 deletion chaco/data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ def map_screen(self, data_array):
"""Maps an array of data points to screen space and returns an array
of screen space points.
"""
# data_array is Nx2 array

# ensure data_array is an Nx2 ndarray
data_array = array(data_array)
data_array = data_array.reshape(-1,2)
Comment on lines +246 to +248
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are actually redundant / unneeded as in the return statement we call array


if len(data_array) == 0:
return empty(shape=(0,2))
x_ary, y_ary = transpose(data_array)
Expand Down
2 changes: 1 addition & 1 deletion chaco/examples/demo/basic/hittest_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def normal_mouse_move(self, event):
def overlay(self, plot, gc, view_bounds=None, mode="normal"):
# If we have a point, draw it to the screen as a small square
if self.pt is not None:
x, y = plot.map_screen(self.pt)
x, y = plot.map_screen(self.pt)[0]
gc.draw_rect((int(x) - 2, int(y) - 2, 4, 4))


Expand Down
6 changes: 5 additions & 1 deletion chaco/grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from contextlib import contextmanager

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

# Enthought library imports
from traits.api import Bool, DelegatesTo, Instance, Float, Property
Expand Down Expand Up @@ -126,6 +126,10 @@ def map_screen(self, data_pts):

Maps values from data space into screen space.
"""
# ensure data_array is an Nx2 ndarray
data_pts = array(data_pts)
data_pts = data_pts.reshape(-1, 2)
Comment on lines +130 to +131
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the column_stack call below actually avoids any errors here making this code un-necessary. Ref:

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]])


xs, ys = transpose(data_pts)
screen_xs = self._xmapper.map_screen(xs)
screen_ys = self._ymapper.map_screen(ys)
Expand Down
2 changes: 2 additions & 0 deletions chaco/plots/horizon_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def map_screen(self, data_array):
return array([self.low_pos])
else:
# Scale the data by the number of bands
if not isinstance(data_array, ndarray):
data_array = array(data_array, ndmin=1)
return (
data_array * self.bands - self.range.low
) * self._scale + self.low_pos
Expand Down
19 changes: 19 additions & 0 deletions chaco/plots/tests/test_image_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ def test_vertical_bottom_right(self):
RGB, (IMAGE.T)[::-1, ::-1], origin="bottom right", orientation="v"
)

def test_map_screen(self):
data_source = ImageData(data=RGB)
index, index_mapper = get_image_index_and_mapper(RGB)
renderer = ImagePlot(
value=data_source,
index=index,
index_mapper=index_mapper,
)

# ImagePlot map screen is used tto find the screen_bbox, not on data
# itself.
screen_pt = renderer.map_screen([(0, 0)])
self.assertEqual(type(screen_pt), np.ndarray)
self.assertEqual(screen_pt.shape, (1, 2))

screen_pt = renderer.map_screen([])
self.assertEqual(type(screen_pt), np.ndarray)
self.assertEqual(screen_pt.shape, (0, 2))

# regression test for enthought/chaco#528
@unittest.skipIf(is_null, "Skip on 'null' toolkit")
def test_resize_to_zero(self):
Expand Down
4 changes: 2 additions & 2 deletions chaco/polar_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
Defines the PolarMapper class, which maps from a 1-D region in data space
into a 1-D output space.
"""

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

# Enthought library imports
Expand Down Expand Up @@ -62,6 +60,8 @@ def map_screen(self, data_array):
else:
return array([self.low_pos])
else:
if not isinstance(data_array, ndarray):
data_array = array(data_array, ndmin=1)
return (data_array - self.range.low) * self._scale + self.low_pos

def map_data(self, screen_val):
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/scipy2008/custom_overlay_dataspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CustomOverlay(AbstractOverlay):

def overlay(self, component, gc, view_bounds=None, mode="normal"):
if self.dataspace:
self.x, self.y = component.map_screen(self._anchor)
self.x, self.y = component.map_screen(self._anchor)[0]
gc.set_fill_color(self.color_)
x = self.x + component.x
y = self.y + component.y
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/scipy2008/custom_overlay_movetool.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CustomOverlay(AbstractOverlay):

def overlay(self, component, gc, view_bounds=None, mode="normal"):
if self.dataspace:
self.x, self.y = component.map_screen(self._anchor)
self.x, self.y = component.map_screen(self._anchor)[0]
gc.set_fill_color(self.color_)
x = self.x + component.x
y = self.y + component.y
Expand Down