@@ -769,10 +769,11 @@ def draw(self, renderer):
769769
770770class TextArea (OffsetBox ):
771771 """
772- The TextArea is contains a single Text instance. The text is
773- placed at (0, 0) with baseline+left alignment. The width and height
774- of the TextArea instance is the width and height of the its child
775- text.
772+ The TextArea is a container artist for a single Text instance.
773+
774+ The text is placed at (0, 0) with baseline+left alignment, by default. The
775+ width and height of the TextArea instance is the width and height of its
776+ child text.
776777 """
777778 def __init__ (self , s ,
778779 textprops = None ,
@@ -876,37 +877,43 @@ def get_offset(self):
876877 def get_window_extent (self , renderer ):
877878 """Return the bounding box in display space."""
878879 w , h , xd , yd = self .get_extent (renderer )
879- ox , oy = self .get_offset () # w, h, xd, yd)
880+ ox , oy = self .get_offset ()
880881 return mtransforms .Bbox .from_bounds (ox - xd , oy - yd , w , h )
881882
882883 def get_extent (self , renderer ):
883884 _ , h_ , d_ = renderer .get_text_width_height_descent (
884885 "lp" , self ._text ._fontproperties , ismath = False )
885886
886- bbox , info , d = self ._text ._get_layout (renderer )
887+ bbox , info , yd = self ._text ._get_layout (renderer )
887888 w , h = bbox .width , bbox .height
888889
889890 self ._baseline_transform .clear ()
890891
891892 if len (info ) > 1 and self ._multilinebaseline :
892- d_new = 0.5 * h - 0.5 * (h_ - d_ )
893- self ._baseline_transform .translate (0 , d - d_new )
894- d = d_new
893+ yd_new = 0.5 * h - 0.5 * (h_ - d_ )
894+ self ._baseline_transform .translate (0 , yd - yd_new )
895+ yd = yd_new
895896
896897 else : # single line
897898
898- h_d = max (h_ - d_ , h - d )
899+ h_d = max (h_ - d_ , h - yd )
899900
900901 if self .get_minimumdescent ():
901- ## to have a minimum descent, #i.e., "l" and "p" have same
902- ## descents.
903- d = max (d , d_ )
904- #else:
905- # d = d
902+ # To have a minimum descent, i.e., "l" and "p" have same
903+ # descents.
904+ yd = max (yd , d_ )
906905
907- h = h_d + d
906+ h = h_d + yd
908907
909- return w , h , 0. , d
908+ ha = self ._text .get_horizontalalignment ()
909+ if ha == 'left' :
910+ xd = 0
911+ elif ha == 'center' :
912+ xd = w / 2
913+ elif ha == 'right' :
914+ xd = w
915+
916+ return w , h , xd , yd
910917
911918 def draw (self , renderer ):
912919 # docstring inherited
@@ -1288,11 +1295,10 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
12881295
12891296 if prop is None :
12901297 prop = {}
1291- badkwargs = {'ha' , 'horizontalalignment' , ' va' , 'verticalalignment' }
1298+ badkwargs = {'va' , 'verticalalignment' }
12921299 if badkwargs & set (prop ):
12931300 raise ValueError (
1294- "Mixing horizontalalignment or verticalalignment with "
1295- "AnchoredText is not supported." )
1301+ 'Mixing verticalalignment with AnchoredText is not supported.' )
12961302
12971303 self .txt = TextArea (s , textprops = prop , minimumdescent = False )
12981304 fp = self .txt ._text .get_fontproperties ()
0 commit comments