Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bugfix: enable picking of AsteriskCollection instances #72

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

Merged
merged 1 commit into from
Apr 13, 2011
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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2011-04-03 Fixed broken pick interface to AsteriskCollection objects
used by scatter. - EF

2011-03-29 Wrapped ViewVCCachedServer definition in a factory function.
This class now inherits from urllib2.HTTPSHandler in order
to fetch data from github, but HTTPSHandler is not defined
Expand Down
38 changes: 30 additions & 8 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self,
self.set_linewidth(linewidths)
self.set_linestyle(linestyles)
self.set_antialiased(antialiaseds)
self.set_pickradius(pickradius)
self.set_urls(urls)


Expand All @@ -105,7 +106,6 @@ def __init__(self,
else:
self._uniform_offsets = offsets

self._pickradius = pickradius
self.update(kwargs)
self._paths = None

Expand Down Expand Up @@ -221,26 +221,48 @@ def draw(self, renderer):
gc.restore()
renderer.close_group(self.__class__.__name__)

def set_pickradius(self, pr):
self._pickradius = pr

def get_pickradius(self):
return self._pickradius

Copy link
Member

Choose a reason for hiding this comment

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

Noticing that this, Line and Axis all have a pickradius, maybe it belongs in Artist? Doesn't necessarily have to be done for this pull, but it seems like a useful refactoring to make.

def contains(self, mouseevent):
"""
Test whether the mouse event occurred in the collection.

Returns True | False, ``dict(ind=itemlist)``, where every
item in itemlist contains the event.
"""
if callable(self._contains): return self._contains(self,mouseevent)
if not self.get_visible(): return False,{}
if callable(self._contains):
return self._contains(self,mouseevent)

if not self.get_visible():
return False, {}

if self._picker is True: # the Boolean constant, not just nonzero or 1
pickradius = self._pickradius
else:
try:
pickradius = float(self._picker)
except TypeError:
# This should not happen if "contains" is called via
# pick, the normal route; the check is here in case
# it is called through some unanticipated route.
warnings.warn(
"Collection picker %s could not be converted to float"
% self._picker)
pickradius = self._pickradius

transform, transOffset, offsets, paths = self._prepare_points()

ind = mpath.point_in_path_collection(
mouseevent.x, mouseevent.y, self._pickradius,
mouseevent.x, mouseevent.y, pickradius,
transform.frozen(), paths, self.get_transforms(),
offsets, transOffset, len(self._facecolors)>0)
return len(ind)>0,dict(ind=ind)
offsets, transOffset, pickradius <= 0)

return len(ind)>0, dict(ind=ind)

def set_pickradius(self,pickradius): self.pickradius = 5
def get_pickradius(self): return self.pickradius

def set_urls(self, urls):
if urls is None:
Expand Down