Skip to content

Commit

Permalink
color edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
maclandrol committed Jan 17, 2024
1 parent 854643a commit 4f94acf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions datamol/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ def to_rdkit_color(color: Optional[DatamolColor]) -> Optional[RDKitColor]:
Args:
color: A datamol color: hex, rgb, rgba or None.
"""
if color is None:
return None

if isinstance(color, str):
return mcolors.to_rgba(color) # type: ignore

if len(color) in [3, 4] and any(x > 1 for x in color):
if isinstance(color, (tuple, list)) and len(color) in [3, 4] and any(x > 1 for x in color):
return tuple(x / 255 if i < 3 else x for i, x in enumerate(color))

return color

0 comments on commit 4f94acf

Please sign in to comment.