-
Notifications
You must be signed in to change notification settings - Fork 153
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
Legend background and foreground colors can be modified #2146
Conversation
- Change in visual properties of the legend do not require to get the handles anymore - Background and foreground can be changed - Defaults for these properties are taken from the settings - The legend is also set to be draggable
It mostly works and is reasonable, except for the edge of the frame. There are several options:
I would tend to prefer 4, but it is not really set in the settings either. Maybe it should ? The default is pretty good on black on white, but not that great for any other... It requires a bit of playing around |
Codecov Report
@@ Coverage Diff @@
## master #2146 +/- ##
==========================================
- Coverage 87.87% 87.85% -0.03%
==========================================
Files 246 246
Lines 22596 22659 +63
==========================================
+ Hits 19857 19906 +49
- Misses 2739 2753 +14
Continue to review full report at Codecov.
|
In this commit, I also set the legend to be draggable so it can be drag around so the user can do whatever he wants. That's quite useful (at least for me), but it might mess up with other redraw... @astrofrog what do you think ? |
@specmicp - thanks for fixing this! Just to make sure I understand, what is the difference between options 1 and 4? The axes frame color is set to the foreground color anyway, right? |
The dragging is very nice by the way! I guess at the end of the day it depends if it causes all drawing-related tests to fail, but so far from playing around with it it works nicely. If it's a problem for redraws, you could allow location to be set to 'draggable' or something like that, so that it's opt-in? |
Thinking about the actual frame color a bit more, I think maybe having it be the same as the text (option 1) for now might make sense, and in future we could consider having separate global options for the text and frame colors for both axes and legend? (I'm not convinced this is needed) However, it might be nice to have a toggle for turning the frame on/off on the legend? |
Sorry for all the comments, but I'm also wondering whether as we add more of these properties for the legend it might be worth having a dedicated State class for the legend, so that then options would be set with |
Add option for draggable legend
@ astrofrog
frame is the property name for the box in the matplotlib API, that's why I went with that name, but I can see now how it can be confusing. I also added the option to draw or not the edge, and set up the edge color to the font color. We can play with it a bit before deciding. I agree that it does not make sense to allow full customization of the legend, because it's going to clutter the options for sure. |
I saw some strange things when resizing the plot, so I added the drag-behavior as an option. It's also clearer that it's a feature also ! |
I though of the same idea, so I think it's a good thing indeed. |
Solve's legend inconsistency between qt interface and glue interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 👍 Just a couple of minor comments below.
glue/viewers/matplotlib/state.py
Outdated
|
||
visible = DeferredDrawCallbackProperty(False, docstring="Whether to show the legend") | ||
|
||
loc_and_drag = DeferredDrawSelectionCallbackProperty(0, docstring="The location of the legend in the axis") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be clearer as just location
as it was before - then the option can be draggable
when it is draggable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,
I changed back that name.
To have the argument to pass to matplotlib API, the property 'mpl_location' need to be used now
glue/viewers/matplotlib/state.py
Outdated
@@ -34,13 +37,69 @@ def notify(self, *args, **kwargs): | |||
|
|||
VALID_WEIGHTS = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black'] | |||
|
|||
VALID_LOCATIONS = ['best', | |||
VALID_LOCATIONS = ['best (draggable)', 'best', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just 'draggable'
for the first option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better indeed !
08f2f87
to
55567d0
Compare
@astrofrog I changed the naming according to your requests, and corrected some bugs. So I think this PR is ready to be merged for more testing. I will do a new PR soon, with more tests and the documentation of the API, if no big problem is discovered soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Resolves #2145