-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allow bgcolor to be set to any color, not just string #177
Open
kjordahl
wants to merge
7
commits into
main
Choose a base branch
from
bug/color_traits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c67dbe
ENH: Utility function to compare colors
881a437
ENH: Add colors_equal function to chaco.api
081bf8b
TST: Tests for colors_equal function
05b57e6
CLN: Refactor color standardization from colors_equal function
01466b2
BUG: Use colors_equal function to compare colors in DataView
265bbe5
TST: Tests of setting a DataView bgcolor
4b7b7be
TST: Simple tests for the Plot class
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
|
||
from chaco.api import Plot | ||
|
||
|
||
class PlotTestCase(unittest.TestCase): | ||
|
||
def test_empty(self): | ||
plot = Plot() | ||
self.assertEqual(plot.orientation, "h") | ||
self.assertEqual(plot.index_scale, "linear") | ||
self.assertEqual(plot.bgcolor, "white") | ||
self.assertEqual(plot.overlay_border, True) | ||
|
||
self.assertEqual(plot.range2d.x_range, plot.index_range) | ||
self.assertEqual(plot.range2d.y_range, plot.value_range) | ||
self.assertEqual(plot.bgcolor, "white") | ||
|
||
def test_bgcolor(self): | ||
""" Test setting background color """ | ||
color = 'blue' | ||
plot = Plot(bgcolor=color) | ||
self.assertEqual(plot.bgcolor, color) | ||
color = (0,0,0,0) | ||
plot = Plot(bgcolor=color) | ||
self.assertEqual(plot.bgcolor, color) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
bgcolor
is a ColorTrait (amapped
trait type). The RGBA value of all ColorTraits is available asself.<trait>_
. if we change this lineif self.bgcolor_ == color_table[grid_color]
it would be enough to fix this bug. In general comparing between mapped traits should always happen through the shadow<trait>_
attribute.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 would suggest to rework the code as suggested above. The
colors_equal
can stay since it might be useful somewhere else.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.
@itziakos That's not quite sufficient, because the user could set the
bgcolor
to a 3-tuple with no alpha. Even if there is an alpha value, we probably don't want to compare it in this case. Usingif self.bgcolor_[:3] == color_table[grid_color][:3]:
works, but IMO is not as clean as using thecolors_equal
function.We probably want something like
colors_almost_equal
as well, because it could be set to a color indistinguishable by eye. I think that's overkill in this case, though. In fact, I am tempted to take out this check altogether and let the user be responsible for grid color. A simple check here does no harm, though, I suppose.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 agree, I think that it would be better if grid_color is an attribute in
DataView
with some basic default value given the bgcolor.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.
👍 for making the grid_color an attribute controlled by the user. I don't see a strong necessity for the check then.
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.
OK, I won't have time to do this for a couple weeks, so if anyone feels like taking it on, feel free.