@@ -1517,8 +1517,7 @@ def _validate_gantt(df):
1517
1517
1518
1518
@staticmethod
1519
1519
def _gantt (chart , colors , title , bar_width , showgrid_x , showgrid_y ,
1520
- height , width , tasks = None ,
1521
- task_names = None , data = None ):
1520
+ height , width , tasks = None , task_names = None , data = None ):
1522
1521
"""
1523
1522
Refer to FigureFactory.create_gantt() for docstring
1524
1523
"""
@@ -1636,6 +1635,8 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1636
1635
if data is None :
1637
1636
data = []
1638
1637
1638
+ #if chart[index_col]
1639
+
1639
1640
for index in range (len (chart )):
1640
1641
task = dict (x0 = chart [index ]['Start' ],
1641
1642
x1 = chart [index ]['Finish' ],
@@ -1663,18 +1664,25 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1663
1664
tasks [index ]['y0' ] = index - bar_width
1664
1665
tasks [index ]['y1' ] = index + bar_width
1665
1666
1666
- colors = FigureFactory ._unlabel_rgb (colors )
1667
+ # unlabel color
1668
+ colors = FigureFactory ._color_parser (
1669
+ colors , FigureFactory ._unlabel_rgb
1670
+ )
1667
1671
lowcolor = colors [0 ]
1668
1672
highcolor = colors [1 ]
1669
1673
1670
1674
intermed = (chart [index ][index_col ])/ 100.0
1671
- intermed_color = FigureFactory ._find_intermediate_color (lowcolor ,
1672
- highcolor ,
1673
- intermed )
1674
- intermed_color = FigureFactory ._label_rgb (intermed_color )
1675
+ intermed_color = FigureFactory ._find_intermediate_color (
1676
+ lowcolor , highcolor , intermed
1677
+ )
1678
+ intermed_color = FigureFactory ._color_parser (
1679
+ intermed_color , FigureFactory ._label_rgb
1680
+ )
1675
1681
tasks [index ]['fillcolor' ] = intermed_color
1676
1682
# relabel colors with 'rgb'
1677
- colors = FigureFactory ._label_rgb (colors )
1683
+ colors = FigureFactory ._color_parser (
1684
+ colors , FigureFactory ._label_rgb
1685
+ )
1678
1686
1679
1687
# add a line for hover text and autorange
1680
1688
data .append (
@@ -1798,7 +1806,6 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
1798
1806
"""
1799
1807
Refer to FigureFactory.create_gantt() for docstring
1800
1808
"""
1801
- from plotly .graph_objs import graph_objs
1802
1809
if tasks is None :
1803
1810
tasks = []
1804
1811
if task_names is None :
@@ -1833,10 +1840,10 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
1833
1840
# verify each value in index column appears in colors dictionary
1834
1841
for key in index_vals :
1835
1842
if key not in colors :
1836
- raise exceptions .PlotlyError ("If you are using colors as a "
1837
- " dictionary, all of its keys "
1838
- " must be all the values in the "
1839
- "index column." )
1843
+ raise exceptions .PlotlyError (
1844
+ "If you are using colors as a dictionary, all of its "
1845
+ "keys must be all the values in the index column. "
1846
+ )
1840
1847
1841
1848
for index in range (len (tasks )):
1842
1849
tn = tasks [index ]['name' ]
@@ -1858,21 +1865,20 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
1858
1865
)
1859
1866
)
1860
1867
1861
- if show_colorbar is True :
1868
+ # if show_colorbar is True:
1862
1869
# generate dummy data for colorscale visibility
1863
- trace2 = dict (
1864
- #x=[tasks[0]['x0'], tasks[0]['x0']],
1865
- x = [2 , 6 ],
1866
- y = [4 , 2 ],
1867
- name = 'asdf' ,
1868
- visible = 'legendonly' ,
1869
- marker = dict (
1870
- size = 10 ,
1871
- color = 'rgb(25, 50, 150)' ),
1872
- showlegend = True
1873
- )
1874
-
1875
- data .append (trace2 )
1870
+ # trace2 = dict(
1871
+ # #x=[tasks[0]['x0'], tasks[0]['x0']],
1872
+ # x=[2, 6],
1873
+ # y=[4, 2],
1874
+ # name='asdf',
1875
+ # visible='legendonly',
1876
+ # marker=dict(
1877
+ # size=10,
1878
+ # color='rgb(25, 50, 150)'),
1879
+ # showlegend=True
1880
+ # )
1881
+ # data.append(trace2)
1876
1882
1877
1883
layout = dict (
1878
1884
title = title ,
@@ -2049,206 +2055,69 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2049
2055
py.iplot(fig, filename='dictioanry colors', world_readable=True)
2050
2056
```
2051
2057
"""
2052
- plotly_scales = {'Greys' : ['rgb(0,0,0)' , 'rgb(255,255,255)' ],
2053
- 'YlGnBu' : ['rgb(8,29,88)' , 'rgb(255,255,217)' ],
2054
- 'Greens' : ['rgb(0,68,27)' , 'rgb(247,252,245)' ],
2055
- 'YlOrRd' : ['rgb(128,0,38)' , 'rgb(255,255,204)' ],
2056
- 'Bluered' : ['rgb(0,0,255)' , 'rgb(255,0,0)' ],
2057
- 'RdBu' : ['rgb(5,10,172)' , 'rgb(178,10,28)' ],
2058
- 'Reds' : ['rgb(220,220,220)' , 'rgb(178,10,28)' ],
2059
- 'Blues' : ['rgb(5,10,172)' , 'rgb(220,220,220)' ],
2060
- 'Picnic' : ['rgb(0,0,255)' , 'rgb(255,0,0)' ],
2061
- 'Rainbow' : ['rgb(150,0,90)' , 'rgb(255,0,0)' ],
2062
- 'Portland' : ['rgb(12,51,131)' , 'rgb(217,30,30)' ],
2063
- 'Jet' : ['rgb(0,0,131)' , 'rgb(128,0,0)' ],
2064
- 'Hot' : ['rgb(0,0,0)' , 'rgb(255,255,255)' ],
2065
- 'Blackbody' : ['rgb(0,0,0)' , 'rgb(160,200,255)' ],
2066
- 'Earth' : ['rgb(0,0,130)' , 'rgb(255,255,255)' ],
2067
- 'Electric' : ['rgb(0,0,0)' , 'rgb(255,250,220)' ],
2068
- 'Viridis' : ['rgb(68,1,84)' , 'rgb(253,231,37)' ]}
2069
-
2070
2058
# validate gantt input data
2071
2059
chart = FigureFactory ._validate_gantt (df )
2072
2060
2073
2061
if index_col :
2074
2062
if index_col not in chart [0 ]:
2075
- raise exceptions .PlotlyError ("In order to use an indexing "
2076
- "column and assign colors to "
2077
- "the values of the index, you "
2078
- "must choose an actual column "
2079
- "name in the dataframe or key "
2080
- "if a list of dictionaries is "
2081
- "being used." )
2063
+ raise exceptions .PlotlyError (
2064
+ "In order to use an indexing column and assign colors to "
2065
+ "the values of the index, you must choose an actual "
2066
+ "column name in the dataframe or key if a list of "
2067
+ "dictionaries is being used." )
2068
+
2082
2069
# validate gantt index column
2083
2070
index_list = []
2084
2071
for dictionary in chart :
2085
2072
index_list .append (dictionary [index_col ])
2086
2073
FigureFactory ._validate_index (index_list )
2087
2074
2088
2075
# Validate colors
2089
- if colors is None :
2090
- colors = DEFAULT_PLOTLY_COLORS
2091
-
2092
- if isinstance (colors , str ):
2093
- if colors in plotly_scales :
2094
- colors = plotly_scales [colors ]
2095
-
2096
- elif 'rgb' in colors :
2097
- colors = FigureFactory ._unlabel_rgb (colors )
2098
- for value in colors :
2099
- if value > 255.0 :
2100
- raise exceptions .PlotlyError ("Whoops! The "
2101
- "elements in your "
2102
- "rgb colors "
2103
- "tuples cannot "
2104
- "exceed 255.0." )
2105
- colors = FigureFactory ._label_rgb (colors )
2106
-
2107
- # put colors in list
2108
- colors_list = []
2109
- colors_list .append (colors )
2110
- colors = colors_list
2111
-
2112
- elif '#' in colors :
2113
- colors = FigureFactory ._hex_to_rgb (colors )
2114
- colors = FigureFactory ._label_rgb (colors )
2115
-
2116
- # put colors in list
2117
- colors_list = []
2118
- colors_list .append (colors )
2119
- colors = colors_list
2120
-
2121
- else :
2122
- scale_keys = list (plotly_scales .keys ())
2123
- raise exceptions .PlotlyError ("If you input a string "
2124
- "for 'colors', it must "
2125
- "either be a Plotly "
2126
- "colorscale, an 'rgb' "
2127
- "color or a hex color."
2128
- "Valid plotly colorscale "
2129
- "names are {}" .format (scale_keys ))
2130
- elif isinstance (colors , tuple ):
2131
- for value in colors :
2132
- if value > 1.0 :
2133
- raise exceptions .PlotlyError ("Whoops! The "
2134
- "elements in "
2135
- "your colors "
2136
- "tuples cannot "
2137
- "exceed 1.0." )
2138
-
2139
- colors_list = []
2140
- colors_list .append (colors )
2141
- colors = colors_list
2142
-
2143
- colors = FigureFactory ._convert_to_RGB_255 (colors )
2144
- colors = FigureFactory ._label_rgb (colors )
2145
-
2146
- elif isinstance (colors , list ):
2147
- new_colormap = []
2148
- for color in colors :
2149
- if 'rgb' in color :
2150
- color = FigureFactory ._unlabel_rgb (color )
2151
-
2152
- for value in color :
2153
- if value > 255.0 :
2154
- raise exceptions .PlotlyError ("Whoops! The "
2155
- "elements in your "
2156
- "rgb colors "
2157
- "tuples cannot "
2158
- "exceed 255.0." )
2159
-
2160
- color = FigureFactory ._label_rgb (color )
2161
- new_colormap .append (color )
2162
- elif '#' in color :
2163
- color = FigureFactory ._hex_to_rgb (color )
2164
- color = FigureFactory ._label_rgb (color )
2165
- new_colormap .append (color )
2166
- elif isinstance (color , tuple ):
2167
- for value in color :
2168
- if value > 1.0 :
2169
- raise exceptions .PlotlyError ("Whoops! The "
2170
- "elements in "
2171
- "your colors "
2172
- "tuples cannot "
2173
- "exceed 1.0." )
2174
- color = FigureFactory ._convert_to_RGB_255 (color )
2175
- color = FigureFactory ._label_rgb (color )
2176
- new_colormap .append (color )
2177
- colors = new_colormap
2178
-
2179
- elif isinstance (colors , dict ):
2180
- for name in colors :
2181
- if 'rgb' in colors [name ]:
2182
- color = FigureFactory ._unlabel_rgb (colors [name ])
2183
- for value in color :
2184
- if value > 255.0 :
2185
- raise exceptions .PlotlyError ("Whoops! The "
2186
- "elements in your "
2187
- "rgb colors "
2188
- "tuples cannot "
2189
- "exceed 255.0." )
2190
-
2191
- elif '#' in colors [name ]:
2192
- color = FigureFactory ._hex_to_rgb (colors [name ])
2193
- color = FigureFactory ._label_rgb (color )
2194
- colors [name ] = color
2195
-
2196
- elif isinstance (colors [name ], tuple ):
2197
- for value in colors [name ]:
2198
- if value > 1.0 :
2199
- raise exceptions .PlotlyError ("Whoops! The "
2200
- "elements in "
2201
- "your colors "
2202
- "tuples cannot "
2203
- "exceed 1.0." )
2204
- color = FigureFactory ._convert_to_RGB_255 (colors [name ])
2205
- color = FigureFactory ._label_rgb (color )
2206
- colors [name ] = color
2207
-
2076
+ if isinstance (colors , dict ):
2077
+ colors = FigureFactory ._validate_colors_dict (colors , 'rgb' )
2208
2078
else :
2209
- raise exceptions .PlotlyError ("You must input a valid colors. "
2210
- "Valid types include a plotly scale, "
2211
- "rgb, hex or tuple color, a list of "
2212
- "any color types, or a dictionary "
2213
- "with index names each assigned "
2214
- "to a color." )
2079
+ colors = FigureFactory ._validate_colors (colors , 'rgb' )
2215
2080
2216
2081
if reverse_colors is True :
2217
2082
colors .reverse ()
2218
2083
2219
2084
if not index_col :
2220
2085
if isinstance (colors , dict ):
2221
- raise exceptions .PlotlyError ("Error. You have set colors to "
2222
- "a dictionary but have not "
2223
- "picked an index. An index is "
2224
- "required if you are assigning "
2225
- "colors to particular values "
2226
- "in a dictioanry." )
2227
-
2228
- fig = FigureFactory ._gantt (chart , colors , title , bar_width ,
2229
- showgrid_x , showgrid_y , height , width ,
2230
- tasks = None , task_names = None , data = None )
2086
+ raise exceptions .PlotlyError (
2087
+ "Error. You have set colors to a dictionary but have not "
2088
+ "picked an index. An index is required if you are "
2089
+ "assigning colors to particular values in a dictioanry."
2090
+ )
2091
+ fig = FigureFactory ._gantt (
2092
+ chart , colors , title , bar_width , showgrid_x , showgrid_y ,
2093
+ height , width , tasks = None , task_names = None , data = None
2094
+ )
2231
2095
return fig
2232
-
2233
2096
else :
2234
2097
if not isinstance (colors , dict ):
2235
- fig = FigureFactory ._gantt_colorscale (chart , colors ,
2236
- title , index_col ,
2237
- show_colorbar ,
2238
- bar_width , showgrid_x ,
2239
- showgrid_y , height ,
2240
- width , tasks = None ,
2241
- task_names = None ,
2242
- data = None )
2098
+ # check that colors has at least 2 colors
2099
+ if len (colors ) < 2 :
2100
+ raise exceptions .PlotlyError (
2101
+ "You must use at least 2 colors in 'colors' if you "
2102
+ "are using a colorscale. However only the first two "
2103
+ "colors given will be used for the lower and upper "
2104
+ "bounds on the colormap."
2105
+ )
2106
+ fig = FigureFactory ._gantt_colorscale (
2107
+ chart , colors , title , index_col , show_colorbar , bar_width ,
2108
+ showgrid_x , showgrid_y , height , width ,
2109
+ tasks = None , task_names = None , data = None
2110
+ )
2243
2111
return fig
2244
2112
else :
2245
- fig = FigureFactory ._gantt_dict (chart , colors , title ,
2246
- index_col , show_colorbar ,
2247
- bar_width , showgrid_x ,
2248
- showgrid_y , height , width ,
2249
- tasks = None , task_names = None ,
2250
- data = None )
2113
+ fig = FigureFactory ._gantt_dict (
2114
+ chart , colors , title , index_col , show_colorbar , bar_width ,
2115
+ showgrid_x , showgrid_y , height , width ,
2116
+ tasks = None , task_names = None , data = None
2117
+ )
2118
+ return fig
2251
2119
2120
+ @staticmethod
2252
2121
def _validate_colors (colors , colortype = 'tuple' ):
2253
2122
"""
2254
2123
Validates color(s) and returns a list of color(s) of a specified type
0 commit comments