Skip to content

Commit 2ffbe1a

Browse files
authored
Merge pull request #872 from plotly/bullet_charts
Bullet Chart FF
2 parents 1c9405d + d0f5251 commit 2ffbe1a

File tree

8 files changed

+1006
-14
lines changed

8 files changed

+1006
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.2.2] - TBA
6+
### Added
7+
- bullet chart figure factory. Call `help(plotly.figure_factory.create_bullet)` for examples and how to get started making bullet charts with the API.
8+
59
## [2.2.1] - 2017-10-26
610
### Fixed
711
- presentation objects now added to setup.py

plotly/colors.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,37 @@ def make_colorscale(colors, scale=None):
442442
return colorscale
443443

444444

445-
def find_intermediate_color(lowcolor, highcolor, intermed):
445+
def find_intermediate_color(lowcolor, highcolor, intermed, colortype='tuple'):
446446
"""
447447
Returns the color at a given distance between two colors
448448
449449
This function takes two color tuples, where each element is between 0
450450
and 1, along with a value 0 < intermed < 1 and returns a color that is
451-
intermed-percent from lowcolor to highcolor
451+
intermed-percent from lowcolor to highcolor. If colortype is set to 'rgb',
452+
the function will automatically convert the rgb type to a tuple, find the
453+
intermediate color and return it as an rgb color.
452454
"""
455+
if colortype == 'rgb':
456+
# convert to tuple color, eg. (1, 0.45, 0.7)
457+
lowcolor = unlabel_rgb(lowcolor)
458+
highcolor = unlabel_rgb(highcolor)
459+
453460
diff_0 = float(highcolor[0] - lowcolor[0])
454461
diff_1 = float(highcolor[1] - lowcolor[1])
455462
diff_2 = float(highcolor[2] - lowcolor[2])
456463

457-
return (lowcolor[0] + intermed * diff_0,
458-
lowcolor[1] + intermed * diff_1,
459-
lowcolor[2] + intermed * diff_2)
464+
inter_med_tuple = (
465+
lowcolor[0] + intermed * diff_0,
466+
lowcolor[1] + intermed * diff_1,
467+
lowcolor[2] + intermed * diff_2
468+
)
469+
470+
if colortype == 'rgb':
471+
# back to an rgb string, e.g. rgb(30, 20, 10)
472+
inter_med_rgb = label_rgb(inter_med_tuple)
473+
return inter_med_rgb
474+
475+
return inter_med_tuple
460476

461477

462478
def unconvert_from_RGB_255(colors):
@@ -498,29 +514,39 @@ def convert_to_RGB_255(colors):
498514
return (rgb_components[0], rgb_components[1], rgb_components[2])
499515

500516

501-
def n_colors(lowcolor, highcolor, n_colors):
517+
def n_colors(lowcolor, highcolor, n_colors, colortype='tuple'):
502518
"""
503519
Splits a low and high color into a list of n_colors colors in it
504520
505521
Accepts two color tuples and returns a list of n_colors colors
506522
which form the intermediate colors between lowcolor and highcolor
507-
from linearly interpolating through RGB space
523+
from linearly interpolating through RGB space. If colortype is 'rgb'
524+
the function will return a list of colors in the same form.
508525
"""
526+
if colortype == 'rgb':
527+
# convert to tuple
528+
lowcolor = unlabel_rgb(lowcolor)
529+
highcolor = unlabel_rgb(highcolor)
530+
509531
diff_0 = float(highcolor[0] - lowcolor[0])
510532
incr_0 = diff_0/(n_colors - 1)
511533
diff_1 = float(highcolor[1] - lowcolor[1])
512534
incr_1 = diff_1/(n_colors - 1)
513535
diff_2 = float(highcolor[2] - lowcolor[2])
514536
incr_2 = diff_2/(n_colors - 1)
515-
color_tuples = []
537+
list_of_colors = []
516538

517539
for index in range(n_colors):
518540
new_tuple = (lowcolor[0] + (index * incr_0),
519541
lowcolor[1] + (index * incr_1),
520542
lowcolor[2] + (index * incr_2))
521-
color_tuples.append(new_tuple)
543+
list_of_colors.append(new_tuple)
544+
545+
if colortype == 'rgb':
546+
# back to an rgb string
547+
list_of_colors = color_parser(list_of_colors, label_rgb)
522548

523-
return color_tuples
549+
return list_of_colors
524550

525551

526552
def label_rgb(colors):

plotly/figure_factory/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from plotly.figure_factory._2d_density import create_2d_density
77
from plotly.figure_factory._annotated_heatmap import create_annotated_heatmap
8+
from plotly.figure_factory._bullet import create_bullet
89
from plotly.figure_factory._candlestick import create_candlestick
910
from plotly.figure_factory._dendrogram import create_dendrogram
1011
from plotly.figure_factory._distplot import create_distplot

0 commit comments

Comments
 (0)