File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7676
7777import decimal
7878from numbers import Number
79+ from warnings import warn
7980
8081from _plotly_utils import exceptions
8182
@@ -763,15 +764,27 @@ def hex_to_rgb(value):
763764 '#FFF' --> (255, 255, 255)
764765
765766 """
767+
768+ input_value = value
766769 value = value .lstrip ("#" )
767770 if len (value ) == 3 :
768771 value = "" .join (c * 2 for c in value )
772+ elif len (value ) == 4 :
773+ warn (
774+ "4-character hex color provided; 4th character will be ignored."
775+ "got {!r}" .format (input_value )
776+ )
777+ value = "" .join (c * 2 for c in value )[:6 ]
778+ elif len (value ) == 8 :
779+ warn (
780+ "8-character hex color provided; last two characters will be ignored."
781+ "got {!r}" .format (input_value )
782+ )
783+ value = value [:6 ]
769784 elif len (value ) != 6 :
770- # Any other length silently produced a tuple of the wrong size: the
771- # section width is len // 3, so "#12345" returned a 5-tuple.
772785 raise ValueError (
773786 "hex color must be 3 or 6 hex digits, optionally prefixed with "
774- "'#'; got {!r}" .format (value )
787+ "'#'; got {!r}" .format (input_value )
775788 )
776789 return tuple (int (value [i : i + 2 ], 16 ) for i in range (0 , 6 , 2 ))
777790
You can’t perform that action at this time.
0 commit comments