Skip to content

Commit

Permalink
Add draft implementation of the get_window_extent method
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos authored and tacaswell committed Jan 31, 2015
1 parent cad373f commit 9d1c876
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,5 +2086,39 @@ def draw(self, renderer):

Text.draw(self, renderer)

def get_window_extent(self, renderer=None):
'''
Return a :class:`~matplotlib.transforms.Bbox` object bounding
the text and arrow annotation, in display units.
*renderer* defaults to the _renderer attribute of the text
object. This is not assigned until the first execution of
:meth:`draw`, so you must use this kwarg if you want
to call :meth:`get_window_extent` prior to the first
:meth:`draw`. For getting web page regions, it is
simpler to call the method after saving the figure. The
*dpi* used defaults to self.figure.dpi; the renderer dpi is
irrelevant.
'''
arrow = self.arrow
arrow_patch = self.arrow_patch

text_bbox = Text.get_window_extent(self, renderer=renderer)
if text_bbox.width == 0.0 and text_bbox.height == 0.0:
bboxes = []
else:
bboxes = [text_bbox]

if self.arrow is not None:
bboxes.append(arrow.get_window_extent(renderer=renderer))
elif self.arrow_patch is not None:
bboxes.append(arrow_patch.get_window_extent(renderer=renderer))

if len(bboxes) == 0:
return Bbox.from_bounds(self._x, self._y, 0.0, 0.0)
else:
return Bbox.union(bboxes)


docstring.interpd.update(Annotation=Annotation.__init__.__doc__)

0 comments on commit 9d1c876

Please sign in to comment.