Skip to content

Commit

Permalink
Merge pull request #31 from raphaelquast/dev
Browse files Browse the repository at this point in the history
merge for v2.1.1
  • Loading branch information
raphaelquast authored Dec 7, 2021
2 parents 3225cdb + ae2170b commit 8292223
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 150 deletions.
7 changes: 3 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ use:
MapsGrid


If you want to create multiple maps-objects with similar properties, use:
(you can of course adjust the properties of the copied object afterwards!)
To get a copy of a `Maps`-object with the same specifications, use:

.. code-block:: python
from eomaps import Maps
m = Maps()
...
m2 = m.copy()
m2 = m.copy(...)
.. currentmodule:: eomaps

Expand Down Expand Up @@ -123,7 +122,7 @@ Once the map is generated, a snapshot of the map can be saved at any time by usi

.. code-block:: python
m.savefig( "snapshot1.png", dpi=300 )
m.savefig( "snapshot1.png", dpi=300, ... )
.. currentmodule:: eomaps.Maps
Expand Down
2 changes: 1 addition & 1 deletion docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Here's a yaml-file that you can use to install all you need in one go:
dependencies:
- python=3.7
- defaults::rtree
- rtree
- numpy
- scipy
- pandas
Expand Down
83 changes: 47 additions & 36 deletions eomaps/_cb_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,18 @@ def _onpick(self, event):
) and self._m.figure.f.canvas.toolbar.mode != "":
return

if event.artist != self._m.figure.coll:
return
if event.artist != self._m.figure.coll or event.artist is None:
clickdict = dict(
ID=event.ind if hasattr(event, "ind") else None,
pos=(event.mouseevent.xdata, event.mouseevent.ydata),
val=None,
ind=event.ind,
)
event = event.mouseevent
# return
else:
clickdict = self._get_pickdict(event)

clickdict = self._get_pickdict(event)

if event.dblclick:
cbs = self.get.cbs["double"]
else:
Expand All @@ -616,36 +621,38 @@ def _onpick(self, event):
if clickdict is not None:
cb(**clickdict)

def _add_pick_callback(self):
def _add_pick_callback(self, pickcb=None):
# only attach pick-callbacks if there is a collection available!
if self._m.figure.coll is None:
return
# if self._m.figure.coll is None:
# return
# ------------- add a callback
# execute onpick on the parent and all its children
# (_add_pick_callback() is only called on the parent object!)
def pickcb(event):
self._event = event

# ignore callbacks while dragging axes
if self._m._draggable_axes._modifier_pressed:
return
# don't execute callbacks if a toolbar-action is active
if (
self._m.figure.f.canvas.toolbar is not None
) and self._m.figure.f.canvas.toolbar.mode != "":
return

# execute "_onpick" on the maps-object that belongs to the clicked axes
# and forward the event to all forwarded maps-objects
for obj in self.objs:
obj._onpick(event)
obj._m.BM._after_update_actions.append(obj._clear_temporary_artists)
# forward callbacks to the connected maps-objects
obj._fwd_cb(event)

# self._m.parent.BM.update(clear=self._method)
# don't update here... the click-callback will take care of it!
self._m.parent.BM._clear_temp_artists(self._method)
if pickcb is None:

def pickcb(event):
self._event = event

# ignore callbacks while dragging axes
if self._m._draggable_axes._modifier_pressed:
return
# don't execute callbacks if a toolbar-action is active
if (
self._m.figure.f.canvas.toolbar is not None
) and self._m.figure.f.canvas.toolbar.mode != "":
return

# execute "_onpick" on the maps-object that belongs to the clicked axes
# and forward the event to all forwarded maps-objects
for obj in self.objs:
obj._onpick(event)
obj._m.BM._after_update_actions.append(obj._clear_temporary_artists)
# forward callbacks to the connected maps-objects
obj._fwd_cb(event)

# self._m.parent.BM.update(clear=self._method)
# don't update here... the click-callback will take care of it!
self._m.parent.BM._clear_temp_artists(self._method)

if self._cid_pick_event is None:
# ------------- add a callback
Expand All @@ -671,11 +678,6 @@ def _fwd_cb(self, event):
event.mouseevent.xdata, event.mouseevent.ydata
)

dummyevent = SimpleNamespace(
artist=m.figure.coll,
dblclick=event.dblclick,
button=event.button,
)
dummymouseevent = SimpleNamespace(
inaxes=m.figure.ax,
dblclick=event.dblclick,
Expand All @@ -685,8 +687,17 @@ def _fwd_cb(self, event):
# x=event.mouseevent.x,
# y=event.mouseevent.y,
)
dummyevent = SimpleNamespace(
artist=m.figure.coll,
dblclick=event.dblclick,
button=event.button,
inaxes=m.figure.ax,
xdata=xdata,
ydata=ydata,
mouseevent=dummymouseevent,
)

pick = m._pick_pixel(None, dummymouseevent)
pick = m._pick_pixel(None, event.mouseevent)
if pick[1] is not None:
dummyevent.ind = pick[1]["ind"]
if "dist" in pick[1]:
Expand Down
3 changes: 2 additions & 1 deletion eomaps/_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def __init__(
):
self._m = m

# self.coll is assigned in "m.plot_map()"
self.coll = None
# self.coll is assigned in "m.plot_map()"

@property
def f(self):
Expand Down
20 changes: 14 additions & 6 deletions eomaps/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _get_values_cleanup(self):

def mark(
self,
radius="pixel",
radius=None,
radius_crs="in",
shape="ellipses",
buffer=1,
Expand All @@ -310,11 +310,10 @@ def mark(
Parameters
----------
radius : float, string or None, optional
The radius of the marker.
If None, it will be evaluated based on the pixel-spacing of the
provided dataset
If float: The radius of the marker in units of the "radius_crs".
If "pixel" the pixel dimensions of the clicked pixel are used
If None: The radius of the data used for plotting (if available),
otherwise 1/10 of the width and height
The default is None.
radius_crs : any
The crs specification in which the radius is provided.
Expand Down Expand Up @@ -344,6 +343,15 @@ def mark(
kwargs passed to the matplotlib patch.
(e.g. `facecolor`, `edgecolor`, `linewidth`, `alpha` etc.)
"""
if radius is None:
if self.m.figure.coll is not None:
radius = "pixel"
else:
# make a dot with 1/20 of the widht & height of the figure
t = self.m.figure.ax.bbox.transformed(
self.m.figure.ax.transData.inverted()
)
radius = (t.width / 10.0, t.height / 10.0)

ID, pos, val, ind = self._popargs(kwargs)

Expand All @@ -362,7 +370,7 @@ def mark(
if not hasattr(self.m.shape, "radius"):
print(
"EOmaps: You cannot attach markers with 'radius=pixel'"
+ "if the shape {self.m.shape.name} is used for plotting!"
+ f"if the shape {self.m.shape.name} is used for plotting!"
)
return
radius = self.m.shape.radius
Expand Down
Loading

0 comments on commit 8292223

Please sign in to comment.