Skip to content
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

139 better color class #140

Merged
merged 4 commits into from
Aug 2, 2024
Merged

Conversation

bbean23
Copy link
Collaborator

@bbean23 bbean23 commented Jul 30, 2024

  • add more conversion methods (to/from hex, to/from HSV)
  • expand on matplotlib color palette definition
  • add build_colormap() method
  • add unit tests

@bbean23 bbean23 added the enhancement New feature or request label Jul 30, 2024
@bbean23 bbean23 self-assigned this Jul 30, 2024
self.assertAlmostEqual(color_map(0.5)[0], 0.5, places=2)
self.assertAlmostEqual(color_map(0.5)[1], 0.0, places=2)
self.assertAlmostEqual(color_map(0.5)[2], 0.5, places=2)

Copy link
Collaborator

Choose a reason for hiding this comment

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

For clarification, this is testing the middle of the colormap of red and blue, so the color purple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, that's correct. Do you think it needs a comment clarifying that?

r2, g2, b2 = mpl_colors[i]
self.assertAlmostEqual(r1, r2)
self.assertAlmostEqual(g1, g2)
self.assertAlmostEqual(b1, b2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comparing the _plotColors class with the matplotlib tab10 colors?
Why would plot_colors_names also not be tested in the unit tests? Is this since throughout this file it calls the colors by name? Such as cl.blue

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The purpose of this test isn't to verify that the color names match those from matplotlib, but rather to verify that the color values continue to match those in matplotlib into the future. I added the following comment to this test:

The matplotlib tab10 colors are encoded in color.py. This test is here
to catch any change in the matplotlib colors, if there ever is any.

Hopefully this answers your question?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it unnecessary to test for invalid Hex strings and HSV values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Two answers:

  1. Hopefully not. Hopefully those invalid values will be caught by the underlying matplotlib library calls.
  2. I could add those tests, but that's starting to lean towards the excessive side of the "get it done" vs "test everything" balancing act. The interaction then between the author and the reviewer then determines if it is necessary.

@mhhwang1 mhhwang1 self-requested a review August 1, 2024 21:16
@bbean23 bbean23 merged commit 1a9a573 into sandialabs:develop Aug 2, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants