@@ -79,9 +79,9 @@ def __init__(self, xy, width, height,
79
79
if loc is None :
80
80
loc = 'right'
81
81
self ._loc = loc
82
- self ._text = Text (x = xy [0 ], y = xy [1 ], text = text ,
83
- fontproperties = fontproperties )
84
- self . _text . set_clip_on ( False )
82
+ self ._text = Text (x = xy [0 ], y = xy [1 ], clip_on = False ,
83
+ text = text , fontproperties = fontproperties ,
84
+ horizontalalignment = loc , verticalalignment = 'center' )
85
85
86
86
def set_transform (self , trans ):
87
87
Rectangle .set_transform (self , trans )
@@ -122,35 +122,24 @@ def draw(self, renderer):
122
122
return
123
123
# draw the rectangle
124
124
Rectangle .draw (self , renderer )
125
-
126
125
# position the text
127
126
self ._set_text_position (renderer )
128
127
self ._text .draw (renderer )
129
128
self .stale = False
130
129
131
130
def _set_text_position (self , renderer ):
132
- """Set text up so it draws in the right place.
133
-
134
- Currently support 'left', 'center' and 'right'
135
- """
131
+ """Set text up so it is drawn in the right place."""
136
132
bbox = self .get_window_extent (renderer )
137
- l , b , w , h = bbox .bounds
138
-
139
- # draw in center vertically
140
- self ._text .set_verticalalignment ('center' )
141
- y = b + (h / 2.0 )
142
-
143
- # now position horizontally
144
- if self ._loc == 'center' :
145
- self ._text .set_horizontalalignment ('center' )
146
- x = l + (w / 2.0 )
147
- elif self ._loc == 'left' :
148
- self ._text .set_horizontalalignment ('left' )
149
- x = l + (w * self .PAD )
150
- else :
151
- self ._text .set_horizontalalignment ('right' )
152
- x = l + (w * (1.0 - self .PAD ))
153
-
133
+ # center vertically
134
+ y = bbox .y0 + bbox .height / 2
135
+ # position horizontally
136
+ loc = self ._text .get_horizontalalignment ()
137
+ if loc == 'center' :
138
+ x = bbox .x0 + bbox .width / 2
139
+ elif loc == 'left' :
140
+ x = bbox .x0 + bbox .width * self .PAD
141
+ else : # right.
142
+ x = bbox .x0 + bbox .width * (1 - self .PAD )
154
143
self ._text .set_position ((x , y ))
155
144
156
145
def get_text_bounds (self , renderer ):
0 commit comments