Skip to content

Commit 7f3b58c

Browse files
committed
Refactor to remove duplicate function
1 parent 6cdf265 commit 7f3b58c

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

_plotly_utils/colors/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,16 @@ def hex_to_rgb(value):
752752
"""
753753
Calculates rgb values from a hex color code.
754754
755-
:param (string) value: Hex color string
755+
:param (string) value: Hex color string. May be a full 6-character code
756+
or a 3-character shorthand code.
756757
757758
:rtype (tuple) (r_value, g_value, b_value): tuple of rgb values
759+
760+
Example:
761+
762+
'#FFFFFF' --> (255, 255, 255)
763+
'#FFF' --> (255, 255, 255)
764+
758765
"""
759766
value = value.lstrip("#")
760767
if len(value) == 3:

plotly/matplotlylib/mpltools.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import warnings
1111
import matplotlib.dates
1212

13+
from _plotly_utils.colors import hex_to_rgb
14+
1315

1416
def check_bar_match(old_bar, new_bar):
1517
"""Check if two bars belong in the same collection (bar chart).
@@ -104,25 +106,6 @@ def convert_symbol(mpl_symbol):
104106
return "circle" # default
105107

106108

107-
def hex_to_rgb(value):
108-
"""
109-
Change a hex color to an rgb tuple
110-
111-
:param (str|unicode) value: The hex string we want to convert.
112-
:return: (int, int, int) The red, green, blue int-tuple.
113-
114-
Example:
115-
116-
'#FFFFFF' --> (255, 255, 255)
117-
118-
"""
119-
value = value.lstrip("#")
120-
if len(value) == 3:
121-
value = "".join(c * 2 for c in value)
122-
lv = len(value)
123-
return tuple(int(value[i : i + lv // 3], 16) for i in range(0, lv, lv // 3))
124-
125-
126109
def merge_color_and_opacity(color, opacity):
127110
"""
128111
Merge hex color with an alpha (opacity) to get an rgba tuple.

0 commit comments

Comments
 (0)