Revision: 8227 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8227&view=rev Author: leejjoon Date: 2010-04-13 22:55:23 +0000 (Tue, 13 Apr 2010)
Log Message: ----------- fix a bug that _bbox_patch of annotation is not correctly updated Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/offsetbox.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py =================================================================== --- trunk/matplotlib/lib/matplotlib/offsetbox.py 2010-04-06 20:38:31 UTC (rev 8226) +++ trunk/matplotlib/lib/matplotlib/offsetbox.py 2010-04-13 22:55:23 UTC (rev 8227) @@ -159,7 +159,7 @@ if a: return a, b return False, {} - + def set_offset(self, xy): """ Set the offset @@ -1307,11 +1307,10 @@ else: ox0, oy0 = self._get_xy(renderer, x, y, self.textcoords) - #self.offsetbox.set_bbox_to_anchor((ox0, oy0)) w, h, xd, yd = self.offsetbox.get_extent(renderer) _fw, _fh = self._box_alignment - self.offsetbox.set_offset((ox0-_fw*w, oy0-_fh*h)) + self.offsetbox.set_offset((ox0-_fw*w+xd, oy0-_fh*h+yd)) # update patch position bbox = self.offsetbox.get_window_extent(renderer) @@ -1401,7 +1400,7 @@ offset from the point where the mouse drag started. Optionally you may override following two methods. - + def artist_picker(self, artist, evt): return self.ref_artist.contains(evt) @@ -1420,7 +1419,7 @@ self.ref_artist = ref_artist self.got_artist = False self._use_blit = use_blit - + self.canvas = self.ref_artist.figure.canvas c2 = self.canvas.mpl_connect('pick_event', self.on_pick) c3 = self.canvas.mpl_connect('button_release_event', self.on_release) @@ -1484,7 +1483,7 @@ def update_offset(self, dx, dy): pass - + def finalize_offset(self): pass @@ -1504,7 +1503,7 @@ def update_offset(self, dx, dy): loc_in_canvas = self.offsetbox_x + dx, self.offsetbox_y + dy self.offsetbox.set_offset(loc_in_canvas) - + def get_loc_in_canvas(self): offsetbox=self.offsetbox @@ -1514,8 +1513,8 @@ loc_in_canvas = (ox-xd, oy-yd) return loc_in_canvas - + class DraggableAnnotation(DraggableBase): def __init__(self, annotation, use_blit=False): DraggableBase.__init__(self, annotation, use_blit=use_blit) Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2010-04-06 20:38:31 UTC (rev 8226) +++ trunk/matplotlib/lib/matplotlib/text.py 2010-04-13 22:55:23 UTC (rev 8227) @@ -468,11 +468,6 @@ be updated before actually drawing the bbox. """ - # For arrow_patch, use textbox as patchA by default. - - if not isinstance(self.arrow_patch, FancyArrowPatch): - return - if self._bbox_patch: trans = self.get_transform() @@ -495,32 +490,7 @@ self._bbox_patch.set_mutation_scale(fontsize_in_pixel) #self._bbox_patch.draw(renderer) - else: - props = self._bbox - if props is None: props = {} - props = props.copy() # don't want to alter the pad externally - pad = props.pop('pad', 4) - pad = renderer.points_to_pixels(pad) - if self.get_text() == "": - self.arrow_patch.set_patchA(None) - return - bbox = self.get_window_extent(renderer) - l,b,w,h = bbox.bounds - l-=pad/2. - b-=pad/2. - w+=pad - h+=pad - r = Rectangle(xy=(l,b), - width=w, - height=h, - ) - r.set_transform(mtransforms.IdentityTransform()) - r.set_clip_on( False ) - r.update(props) - - self.arrow_patch.set_patchA(r) - def _draw_bbox(self, renderer, posx, posy): """ Update the location and the size of the bbox @@ -1425,7 +1395,7 @@ x, y = self._artist.transform_point(self._ref_coord) else: raise RuntimeError("unknown type") - + sc = self._get_scale(renderer) tr = Affine2D().scale(sc, sc).translate(x, y) @@ -1501,7 +1471,7 @@ tr = PolarAxes.PolarTransform() trans = tr + self.axes.transData return trans - + s_ = s.split() if len(s_) != 2: raise ValueError("%s is not a recognized coodinate" % s) @@ -1611,8 +1581,8 @@ y = b + y*sc return x, y - + def set_annotation_clip(self, b): """ set *annotation_clip* attribute. @@ -1896,13 +1866,38 @@ mutation_scale = renderer.points_to_pixels(mutation_scale) self.arrow_patch.set_mutation_scale(mutation_scale) - if self._bbox_patch: - patchA = d.pop("patchA", self._bbox_patch) - self.arrow_patch.set_patchA(patchA) + if "patchA" in d: + self.arrow_patch.set_patchA(d.pop("patchA")) else: - patchA = d.pop("patchA", self._bbox) - self.arrow_patch.set_patchA(patchA) + if self._bbox_patch: + self.arrow_patch.set_patchA(self._bbox_patch) + else: + patchA = d.pop("patchA", None) + props = self._bbox + if props is None: props = {} + props = props.copy() # don't want to alter the pad externally + pad = props.pop('pad', 4) + pad = renderer.points_to_pixels(pad) + if self.get_text() == "": + self.arrow_patch.set_patchA(None) + return + bbox = self.get_window_extent(renderer) + l,b,w,h = bbox.bounds + l-=pad/2. + b-=pad/2. + w+=pad + h+=pad + r = Rectangle(xy=(l,b), + width=w, + height=h, + ) + r.set_transform(mtransforms.IdentityTransform()) + r.set_clip_on( False ) + r.update(props) + + self.arrow_patch.set_patchA(r) + else: # pick the x,y corner of the text bbox closest to point @@ -1933,6 +1928,34 @@ self.arrow.set_clip_box(self.get_clip_box()) + def update_bbox_position_size(self, renderer): + """ + Update the location and the size of the bbox. This method + should be used when the position and size of the bbox needs to + be updated before actually drawing the bbox. + """ + + # For arrow_patch, use textbox as patchA by default. + + if not isinstance(self.arrow_patch, FancyArrowPatch): + return + + if self._bbox_patch: + posx, posy = self._x, self._y + print posx, posy + + x_box, y_box, w_box, h_box = _get_textbox(self, renderer) + self._bbox_patch.set_bounds(0., 0., + w_box, h_box) + theta = self.get_rotation()/180.*math.pi + tr = mtransforms.Affine2D().rotate(theta) + tr = tr.translate(posx+x_box, posy+y_box) + self._bbox_patch.set_transform(tr) + fontsize_in_pixel = renderer.points_to_pixels(self.get_size()) + self._bbox_patch.set_mutation_scale(fontsize_in_pixel) + + + @allow_rasterization def draw(self, renderer): """ @@ -1944,14 +1967,13 @@ if not self.get_visible(): return xy_pixel = self._get_position_xy(renderer) - if not self._check_xy(renderer, xy_pixel): return self._update_position_xytext(renderer, xy_pixel) - self.update_bbox_position_size(renderer) + if self.arrow is not None: if self.arrow.figure is None and self.figure is not None: self.arrow.figure = self.figure This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins