Skip to content

text update properties does not handle bbox properly #4942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2015

Conversation

jrevans
Copy link

@jrevans jrevans commented Aug 17, 2015

Added a check to make sure any existing bbox is not overridden.

The previous behavior would overwrite the bbox property to None even if it was not specified. This now keeps the bbox property as it was unless bbox is specified as a parameter to 'update'.

This addresses an issue in #4897.

@@ -240,7 +240,8 @@ def update(self, kwargs):
"""
bbox = kwargs.pop('bbox', None)
super(Text, self).update(kwargs)
self.set_bbox(bbox) # depends on font properties
if bbox:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably to be safe, this should be if bbox is not None:. I can't be sure if bbox is ever a numpy array or not, and doing a test like that on a numpy array will result in errors in some versions, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is the case, we have a whole bunch of other places in the code have the same issue.

@tacaswell
Copy link
Member

@efiring You put this in in 2eb4313 as part of #4178 can you comment on why?

@tacaswell tacaswell modified the milestone: next point release Aug 18, 2015
@efiring
Copy link
Member

efiring commented Aug 19, 2015

@tacaswell, I put in the override update method to ensure the bbox setting is processed after everything else; setting the bbox depends on the font size, so if both are changed, we have to process the font change first.

@efiring
Copy link
Member

efiring commented Aug 19, 2015

I think this PR is fine. I originally overlooked the case that it is addressing. When bbox is supplied as a kwarg, it has to be a dictionary, not a numpy array. Using if bbox is not None: would be a little more clear, but is not mandatory.

@efiring
Copy link
Member

efiring commented Aug 19, 2015

What is a little confusing is that there used to be a bbox and/or a bbox_patch, and I eliminated the former--but the API still uses set_bbox. This makes it look at first glance like a "bbox" attribute is not getting initialized with this PR. But it's OK, because _bbox_patch is initialized to None in the init method. Maybe it would all be clarified if the _bbox_patch attribute were renamed to _bbox--although it is really more of a "patch" than a "bbox". Endlessly confusing...

@tacaswell
Copy link
Member

@jrevans Can you add a test for this? It does't need to be an image test, just that calling update does not blow away a previously set bbox.

@efiring If I am following you, we use bbox lots of places to mean 'the bounding box that the artist will fall with in when drawn' and here it means 'the patch that is drawn behind the text that is strictly bigger than the other meaning of the bounding box of the text' ?

tacaswell added a commit that referenced this pull request Aug 22, 2015
FIX: only update bbox_patch if passed in to `Text.update`
@tacaswell tacaswell merged commit c29c773 into matplotlib:master Aug 22, 2015
@tacaswell
Copy link
Member

@jrevans Can you add the test in a new PR?

@efiring
Copy link
Member

efiring commented Aug 25, 2015

On 2015/08/22 8:19 AM, Thomas A Caswell wrote:

@efiring https://github.com/efiring If I am following you, we use
|bbox| lots of places to mean 'the bounding box that the artist will
fall with in when drawn' and here it means 'the patch that is drawn
behind the text that is strictly bigger than the other meaning of the
bounding box of the text' ?

Exactly. It's really a background patch, potentially a very fancy one.
Originally it might have been just a simple patch corresponding to the
true bounding box of the text, but those days are long gone. It might
be worth deprecating the "bbox" kwarg in favor of "patch" or
"background". Even plain "box" would be an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants