-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Bullet Chart FF #872
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
Bullet Chart FF #872
Changes from 17 commits
ff36387
5b9ddaa
939a8ba
5796a9e
bb15f6a
8a5ea2b
4599bc2
beb6d18
8ba62a2
69bd30d
69a541d
e74996c
6da599f
79c67c7
9b9b578
af9cb17
6080d80
082fdfd
dfd1b2c
a2b0ca0
ca9d37a
d0f5251
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,21 +442,37 @@ def make_colorscale(colors, scale=None): | |
return colorscale | ||
|
||
|
||
def find_intermediate_color(lowcolor, highcolor, intermed): | ||
def find_intermediate_color(lowcolor, highcolor, intermed, colortype='tuple'): | ||
""" | ||
Returns the color at a given distance between two colors | ||
|
||
This function takes two color tuples, where each element is between 0 | ||
and 1, along with a value 0 < intermed < 1 and returns a color that is | ||
intermed-percent from lowcolor to highcolor | ||
intermed-percent from lowcolor to highcolor. If colortype is set to 'rgb', | ||
the function will automatically convert the rgb type to a tuple, find the | ||
intermediate color and return it as an rgb color. | ||
""" | ||
if colortype == 'rgb': | ||
# convert to tuple color, eg. (1, 0.45, 0.7) | ||
lowcolor = unlabel_rgb(lowcolor) | ||
highcolor = unlabel_rgb(highcolor) | ||
|
||
diff_0 = float(highcolor[0] - lowcolor[0]) | ||
diff_1 = float(highcolor[1] - lowcolor[1]) | ||
diff_2 = float(highcolor[2] - lowcolor[2]) | ||
|
||
return (lowcolor[0] + intermed * diff_0, | ||
lowcolor[1] + intermed * diff_1, | ||
lowcolor[2] + intermed * diff_2) | ||
inter_med_tuple = ( | ||
lowcolor[0] + intermed * diff_0, | ||
lowcolor[1] + intermed * diff_1, | ||
lowcolor[2] + intermed * diff_2 | ||
) | ||
|
||
if colortype == 'rgb': | ||
# back to an rgb string, e.g. rgb(30, 20, 10) | ||
inter_med_rgb = label_rgb(inter_med_tuple) | ||
return inter_med_rgb | ||
|
||
return inter_med_tuple | ||
|
||
|
||
def unconvert_from_RGB_255(colors): | ||
|
@@ -498,29 +514,39 @@ def convert_to_RGB_255(colors): | |
return (rgb_components[0], rgb_components[1], rgb_components[2]) | ||
|
||
|
||
def n_colors(lowcolor, highcolor, n_colors): | ||
def n_colors(lowcolor, highcolor, n_colors, colortype='tuple'): | ||
""" | ||
Splits a low and high color into a list of n_colors colors in it | ||
|
||
Accepts two color tuples and returns a list of n_colors colors | ||
which form the intermediate colors between lowcolor and highcolor | ||
from linearly interpolating through RGB space | ||
from linearly interpolating through RGB space. If colortype is 'rgb' | ||
the function will return a list of colors in the same form. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a typo? i thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see how there's confusion. If If the input is
If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this function will error if you input tuple-colors and colortype is set to |
||
""" | ||
if colortype == 'rgb': | ||
# convert to tuple | ||
lowcolor = unlabel_rgb(lowcolor) | ||
highcolor = unlabel_rgb(highcolor) | ||
|
||
diff_0 = float(highcolor[0] - lowcolor[0]) | ||
incr_0 = diff_0/(n_colors - 1) | ||
diff_1 = float(highcolor[1] - lowcolor[1]) | ||
incr_1 = diff_1/(n_colors - 1) | ||
diff_2 = float(highcolor[2] - lowcolor[2]) | ||
incr_2 = diff_2/(n_colors - 1) | ||
color_tuples = [] | ||
list_of_colors = [] | ||
|
||
for index in range(n_colors): | ||
new_tuple = (lowcolor[0] + (index * incr_0), | ||
lowcolor[1] + (index * incr_1), | ||
lowcolor[2] + (index * incr_2)) | ||
color_tuples.append(new_tuple) | ||
list_of_colors.append(new_tuple) | ||
|
||
if colortype == 'rgb': | ||
# back to an rgb string | ||
list_of_colors = color_parser(list_of_colors, label_rgb) | ||
|
||
return color_tuples | ||
return list_of_colors | ||
|
||
|
||
def label_rgb(colors): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by
rgb
do you mean like a string likergb(30, 20, 10)
? if so, could we sayconvert back to an rgb string, e.g. rgb(30, 20, 10)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's what I mean. More clearer your way.