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

Fix to_rgb_color_list when passing rgba colors #3478

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## UNRELEASED

### Fixed
- Fixed ValueError when `ff.create_annotated_heatmap` passes `rgba()` colors into `to_rgb_color_list` [#3478](https://github.com/plotly/plotly.py/issues/3478)

### Updated
- Updated Plotly.js to from version 2.6.3 to version 2.8.0. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#280----2021-12-10) for more information. Notable changes include:
- Horizontal color bars
- texttemplate for histogram-like traces
- text for heatmap-like traces


## [5.4.0] - 2021-11-15

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, division

from plotly import exceptions, optional_imports
import plotly.colors as clrs
from plotly import exceptions, optional_imports
from plotly.figure_factory import utils
from plotly.graph_objs import graph_objs
from plotly.validators.heatmap import ColorscaleValidator
Expand Down Expand Up @@ -147,9 +147,10 @@ def create_annotated_heatmap(


def to_rgb_color_list(color_str, default):
if "rgb" in color_str:
return [int(v) for v in color_str.strip("rgb()").split(",")]
elif "#" in color_str:
color_str = color_str.strip()
if color_str.startswith("rgb"):
return [int(v) for v in color_str.strip("rgba()").split(",")]
Copy link
Contributor

Choose a reason for hiding this comment

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

does this now still work with rbg(...) and rgba(...) both ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it does. Tested it. As I mentioned, doesn't handle HSL(A) yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. After this next release I won't be accepting any more PRs to this deprecated code so let's not work on any HSL stuff please :)

elif color_str.startswith("#"):
return clrs.hex_to_rgb(color_str)
else:
return default
Expand Down