Skip to content

Commit 9cf598c

Browse files
committed
fixed: wrong logic, this should work
1 parent e5fe18a commit 9cf598c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/python/plotly/_plotly_utils/colors/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -694,11 +694,19 @@ def n_colors(lowcolor, highcolor, n_colors, colortype="tuple"):
694694
incr_2 = diff_2 / (n_colors - 1)
695695
list_of_colors = []
696696

697+
def _constrain_color(c):
698+
if c > 255.0:
699+
return 255.0
700+
elif c < 0.0:
701+
return 0.0
702+
else:
703+
return c
704+
697705
for index in range(n_colors):
698706
new_tuple = (
699-
min(max(lowcolor[0] + (index * incr_0), 255.0), 0.0),
700-
min(max(lowcolor[1] + (index * incr_1), 255.0), 0.0),
701-
min(max(lowcolor[2] + (index * incr_2), 255.0), 0.0),
707+
_constrain_color(lowcolor[0] + (index * incr_0)),
708+
_constrain_color(lowcolor[1] + (index * incr_1)),
709+
_constrain_color(lowcolor[2] + (index * incr_2)),
702710
)
703711
list_of_colors.append(new_tuple)
704712

0 commit comments

Comments
 (0)