@@ -1724,7 +1724,7 @@ def _validate_gantt(df):
1724
1724
1725
1725
@staticmethod
1726
1726
def _gantt (chart , colors , title , bar_width , showgrid_x , showgrid_y ,
1727
- height , width , tasks = None , task_names = None , data = None ):
1727
+ height , width , tasks = None , task_names = None , data = None , group_tasks = False ):
1728
1728
"""
1729
1729
Refer to FigureFactory.create_gantt() for docstring
1730
1730
"""
@@ -1751,15 +1751,30 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
1751
1751
},
1752
1752
'yref' : 'y' ,
1753
1753
}
1754
+ # create the list of task names
1755
+ for index in range (len (tasks )):
1756
+ tn = tasks [index ]['name' ]
1757
+ # Is added to task_names if group_tasks is set to False,
1758
+ # or if the option is used (True) it only adds them if the
1759
+ # name is not already in the list
1760
+ if not group_tasks or tn not in task_names :
1761
+ task_names .append (tn )
1762
+ task_names .reverse ()
1763
+
1754
1764
1755
1765
color_index = 0
1756
1766
for index in range (len (tasks )):
1757
1767
tn = tasks [index ]['name' ]
1758
- task_names .append (tn )
1759
1768
del tasks [index ]['name' ]
1760
1769
tasks [index ].update (shape_template )
1761
- tasks [index ]['y0' ] = index - bar_width
1762
- tasks [index ]['y1' ] = index + bar_width
1770
+
1771
+ # If group_tasks is True, all tasks with the same name belong
1772
+ # to the same row.
1773
+ groupID = index
1774
+ if group_tasks :
1775
+ groupID = task_names .index (tn )
1776
+ tasks [index ]['y0' ] = groupID - bar_width
1777
+ tasks [index ]['y1' ] = groupID + bar_width
1763
1778
1764
1779
# check if colors need to be looped
1765
1780
if color_index >= len (colors ):
@@ -1769,7 +1784,7 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
1769
1784
data .append (
1770
1785
dict (
1771
1786
x = [tasks [index ]['x0' ], tasks [index ]['x1' ]],
1772
- y = [index , index ],
1787
+ y = [groupID , groupID ],
1773
1788
name = '' ,
1774
1789
marker = {'color' : 'white' }
1775
1790
)
@@ -1786,8 +1801,8 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
1786
1801
yaxis = dict (
1787
1802
showgrid = showgrid_y ,
1788
1803
ticktext = task_names ,
1789
- tickvals = list (range (len (tasks ))),
1790
- range = [- 1 , len (tasks ) + 1 ],
1804
+ tickvals = list (range (len (task_names ))),
1805
+ range = [- 1 , len (task_names ) + 1 ],
1791
1806
autorange = False ,
1792
1807
zeroline = False ,
1793
1808
),
@@ -1830,7 +1845,7 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
1830
1845
@staticmethod
1831
1846
def _gantt_colorscale (chart , colors , title , index_col , show_colorbar ,
1832
1847
bar_width , showgrid_x , showgrid_y , height ,
1833
- width , tasks = None , task_names = None , data = None ):
1848
+ width , tasks = None , task_names = None , data = None , group_tasks = False ):
1834
1849
"""
1835
1850
Refer to FigureFactory.create_gantt() for docstring
1836
1851
"""
@@ -1870,13 +1885,29 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1870
1885
"colors given will be used for the lower and upper "
1871
1886
"bounds on the colormap."
1872
1887
)
1888
+
1889
+ # create the list of task names
1890
+ for index in range (len (tasks )):
1891
+ tn = tasks [index ]['name' ]
1892
+ # Is added to task_names if group_tasks is set to False,
1893
+ # or if the option is used (True) it only adds them if the
1894
+ # name is not already in the list
1895
+ if not group_tasks or tn not in task_names :
1896
+ task_names .append (tn )
1897
+ task_names .reverse ()
1898
+
1873
1899
for index in range (len (tasks )):
1874
1900
tn = tasks [index ]['name' ]
1875
- task_names .append (tn )
1876
1901
del tasks [index ]['name' ]
1877
1902
tasks [index ].update (shape_template )
1878
- tasks [index ]['y0' ] = index - bar_width
1879
- tasks [index ]['y1' ] = index + bar_width
1903
+
1904
+ # If group_tasks is True, all tasks with the same name belong
1905
+ # to the same row.
1906
+ groupID = index
1907
+ if group_tasks :
1908
+ groupID = task_names .index (tn )
1909
+ tasks [index ]['y0' ] = groupID - bar_width
1910
+ tasks [index ]['y1' ] = groupID + bar_width
1880
1911
1881
1912
# unlabel color
1882
1913
colors = FigureFactory ._color_parser (
@@ -1902,7 +1933,7 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1902
1933
data .append (
1903
1934
dict (
1904
1935
x = [tasks [index ]['x0' ], tasks [index ]['x1' ]],
1905
- y = [index , index ],
1936
+ y = [groupID , groupID ],
1906
1937
name = '' ,
1907
1938
marker = {'color' : 'white' }
1908
1939
)
@@ -1948,13 +1979,27 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1948
1979
index_vals_dict [key ] = colors [c_index ]
1949
1980
c_index += 1
1950
1981
1982
+ # create the list of task names
1983
+ for index in range (len (tasks )):
1984
+ tn = tasks [index ]['name' ]
1985
+ # Is added to task_names if group_tasks is set to False,
1986
+ # or if the option is used (True) it only adds them if the
1987
+ # name is not already in the list
1988
+ if not group_tasks or tn not in task_names :
1989
+ task_names .append (tn )
1990
+ task_names .reverse ()
1991
+
1951
1992
for index in range (len (tasks )):
1952
1993
tn = tasks [index ]['name' ]
1953
- task_names .append (tn )
1954
1994
del tasks [index ]['name' ]
1955
1995
tasks [index ].update (shape_template )
1956
- tasks [index ]['y0' ] = index - bar_width
1957
- tasks [index ]['y1' ] = index + bar_width
1996
+ # If group_tasks is True, all tasks with the same name belong
1997
+ # to the same row.
1998
+ groupID = index
1999
+ if group_tasks :
2000
+ groupID = task_names .index (tn )
2001
+ tasks [index ]['y0' ] = groupID - bar_width
2002
+ tasks [index ]['y1' ] = groupID + bar_width
1958
2003
1959
2004
tasks [index ]['fillcolor' ] = index_vals_dict [
1960
2005
chart [index ][index_col ]
@@ -1964,7 +2009,7 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1964
2009
data .append (
1965
2010
dict (
1966
2011
x = [tasks [index ]['x0' ], tasks [index ]['x1' ]],
1967
- y = [index , index ],
2012
+ y = [groupID , groupID ],
1968
2013
name = '' ,
1969
2014
marker = {'color' : 'white' }
1970
2015
)
@@ -1998,8 +2043,8 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1998
2043
yaxis = dict (
1999
2044
showgrid = showgrid_y ,
2000
2045
ticktext = task_names ,
2001
- tickvals = list (range (len (tasks ))),
2002
- range = [- 1 , len (tasks ) + 1 ],
2046
+ tickvals = list (range (len (task_names ))),
2047
+ range = [- 1 , len (task_names ) + 1 ],
2003
2048
autorange = False ,
2004
2049
zeroline = False ,
2005
2050
),
@@ -2042,7 +2087,7 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
2042
2087
@staticmethod
2043
2088
def _gantt_dict (chart , colors , title , index_col , show_colorbar , bar_width ,
2044
2089
showgrid_x , showgrid_y , height , width , tasks = None ,
2045
- task_names = None , data = None ):
2090
+ task_names = None , data = None , group_tasks = False ):
2046
2091
"""
2047
2092
Refer to FigureFactory.create_gantt() for docstring
2048
2093
"""
@@ -2086,21 +2131,36 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
2086
2131
"keys must be all the values in the index column."
2087
2132
)
2088
2133
2134
+ # create the list of task names
2135
+ for index in range (len (tasks )):
2136
+ tn = tasks [index ]['name' ]
2137
+ # Is added to task_names if group_tasks is set to False,
2138
+ # or if the option is used (True) it only adds them if the
2139
+ # name is not already in the list
2140
+ if not group_tasks or tn not in task_names :
2141
+ task_names .append (tn )
2142
+ task_names .reverse ()
2143
+
2089
2144
for index in range (len (tasks )):
2090
2145
tn = tasks [index ]['name' ]
2091
- task_names .append (tn )
2092
2146
del tasks [index ]['name' ]
2093
2147
tasks [index ].update (shape_template )
2094
- tasks [index ]['y0' ] = index - bar_width
2095
- tasks [index ]['y1' ] = index + bar_width
2148
+
2149
+ # If group_tasks is True, all tasks with the same name belong
2150
+ # to the same row.
2151
+ groupID = index
2152
+ if group_tasks :
2153
+ groupID = task_names .index (tn )
2154
+ tasks [index ]['y0' ] = groupID - bar_width
2155
+ tasks [index ]['y1' ] = groupID + bar_width
2096
2156
2097
2157
tasks [index ]['fillcolor' ] = colors [chart [index ][index_col ]]
2098
2158
2099
2159
# add a line for hover text and autorange
2100
2160
data .append (
2101
2161
dict (
2102
2162
x = [tasks [index ]['x0' ], tasks [index ]['x1' ]],
2103
- y = [index , index ],
2163
+ y = [groupID , groupID ],
2104
2164
name = '' ,
2105
2165
marker = {'color' : 'white' }
2106
2166
)
@@ -2134,8 +2194,8 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
2134
2194
yaxis = dict (
2135
2195
showgrid = showgrid_y ,
2136
2196
ticktext = task_names ,
2137
- tickvals = list (range (len (tasks ))),
2138
- range = [- 1 , len (tasks ) + 1 ],
2197
+ tickvals = list (range (len (task_names ))),
2198
+ range = [- 1 , len (task_names ) + 1 ],
2139
2199
autorange = False ,
2140
2200
zeroline = False ,
2141
2201
),
@@ -2180,7 +2240,7 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2180
2240
reverse_colors = False , title = 'Gantt Chart' ,
2181
2241
bar_width = 0.2 , showgrid_x = False , showgrid_y = False ,
2182
2242
height = 600 , width = 900 , tasks = None ,
2183
- task_names = None , data = None ):
2243
+ task_names = None , data = None , group_tasks = False ):
2184
2244
"""
2185
2245
Returns figure for a gantt chart
2186
2246
@@ -2359,22 +2419,23 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2359
2419
)
2360
2420
fig = FigureFactory ._gantt (
2361
2421
chart , colors , title , bar_width , showgrid_x , showgrid_y ,
2362
- height , width , tasks = None , task_names = None , data = None
2422
+ height , width , tasks = None , task_names = None , data = None ,
2423
+ group_tasks = group_tasks
2363
2424
)
2364
2425
return fig
2365
2426
else :
2366
2427
if not isinstance (colors , dict ):
2367
2428
fig = FigureFactory ._gantt_colorscale (
2368
2429
chart , colors , title , index_col , show_colorbar , bar_width ,
2369
2430
showgrid_x , showgrid_y , height , width ,
2370
- tasks = None , task_names = None , data = None
2431
+ tasks = None , task_names = None , data = None , group_tasks = group_tasks
2371
2432
)
2372
2433
return fig
2373
2434
else :
2374
2435
fig = FigureFactory ._gantt_dict (
2375
2436
chart , colors , title , index_col , show_colorbar , bar_width ,
2376
2437
showgrid_x , showgrid_y , height , width ,
2377
- tasks = None , task_names = None , data = None
2438
+ tasks = None , task_names = None , data = None , group_tasks = group_tasks
2378
2439
)
2379
2440
return fig
2380
2441
@@ -2403,6 +2464,7 @@ def _validate_colors(colors, colortype='tuple'):
2403
2464
else :
2404
2465
colors = list (colors )
2405
2466
2467
+
2406
2468
# convert color elements in list to tuple color
2407
2469
for j , each_color in enumerate (colors ):
2408
2470
if 'rgb' in each_color :
0 commit comments