53
53
DEFAULT_HISTNORM = 'probability density'
54
54
ALTERNATIVE_HISTNORM = 'probability'
55
55
56
+
56
57
# Warning format
57
58
def warning_on_one_line (message , category , filename , lineno ,
58
59
file = None , line = None ):
@@ -1484,12 +1485,10 @@ def _validate_gantt(df):
1484
1485
# validate that df has all the required keys
1485
1486
for key in REQUIRED_GANTT_KEYS :
1486
1487
if key not in df :
1487
- raise exceptions .PlotlyError ("The columns in your data"
1488
- "frame must include the "
1489
- "keys" .format (
1490
- REQUIRED_GANTT_KEYS
1491
- )
1492
- )
1488
+ raise exceptions .PlotlyError (
1489
+ "The columns in your dataframe must include the "
1490
+ "keys" .format (REQUIRED_GANTT_KEYS )
1491
+ )
1493
1492
1494
1493
num_of_rows = len (df .index )
1495
1494
chart = []
@@ -1634,8 +1633,7 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1634
1633
task_names = []
1635
1634
if data is None :
1636
1635
data = []
1637
-
1638
- #if chart[index_col]
1636
+ showlegend = False
1639
1637
1640
1638
for index in range (len (chart )):
1641
1639
task = dict (x0 = chart [index ]['Start' ],
@@ -1656,6 +1654,14 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1656
1654
1657
1655
# compute the color for task based on indexing column
1658
1656
if isinstance (chart [0 ][index_col ], Number ):
1657
+ # check that colors has at least 2 colors
1658
+ if len (colors ) < 2 :
1659
+ raise exceptions .PlotlyError (
1660
+ "You must use at least 2 colors in 'colors' if you "
1661
+ "are using a colorscale. However only the first two "
1662
+ "colors given will be used for the lower and upper "
1663
+ "bounds on the colormap."
1664
+ )
1659
1665
for index in range (len (tasks )):
1660
1666
tn = tasks [index ]['name' ]
1661
1667
task_names .append (tn )
@@ -1693,6 +1699,22 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1693
1699
marker = {'color' : 'white' }
1694
1700
)
1695
1701
)
1702
+
1703
+ if show_colorbar is True :
1704
+ # generate dummy data for colorscale visibility
1705
+ data .append (
1706
+ dict (
1707
+ x = [tasks [index ]['x0' ], tasks [index ]['x0' ]],
1708
+ y = [index , index ],
1709
+ name = '' ,
1710
+ marker = {'color' : 'white' ,
1711
+ 'colorscale' : [[0 , colors [0 ]], [1 , colors [1 ]]],
1712
+ 'showscale' : True ,
1713
+ 'cmax' : 100 ,
1714
+ 'cmin' : 0 }
1715
+ )
1716
+ )
1717
+
1696
1718
if isinstance (chart [0 ][index_col ], str ):
1697
1719
index_vals = []
1698
1720
for row in range (len (tasks )):
@@ -1701,6 +1723,13 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1701
1723
1702
1724
index_vals .sort ()
1703
1725
1726
+ if len (colors ) < len (index_vals ):
1727
+ raise exceptions .PlotlyError (
1728
+ "Error. The number of colors in 'colors' must be no less "
1729
+ "than the number of unique index values in your group "
1730
+ "column."
1731
+ )
1732
+
1704
1733
# make a dictionary assignment to each index value
1705
1734
index_vals_dict = {}
1706
1735
# define color index
@@ -1733,24 +1762,27 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
1733
1762
)
1734
1763
)
1735
1764
1736
- if show_colorbar is True :
1737
- # generate dummy data for colorscale visibility
1738
- data .append (
1739
- dict (
1740
- x = [tasks [index ]['x0' ], tasks [index ]['x0' ]],
1741
- y = [index , index ],
1742
- name = '' ,
1743
- marker = {'color' : 'white' ,
1744
- 'colorscale' : [[0 , colors [0 ]], [1 , colors [1 ]]],
1745
- 'showscale' : True ,
1746
- 'cmax' : 100 ,
1747
- 'cmin' : 0 }
1748
- )
1749
- )
1765
+ if show_colorbar is True :
1766
+ # generate dummy data to generate legend
1767
+ showlegend = True
1768
+ for k , index_value in enumerate (index_vals ):
1769
+ data .append (
1770
+ dict (
1771
+ x = [tasks [index ]['x0' ], tasks [index ]['x0' ]],
1772
+ y = [k , k ],
1773
+ showlegend = True ,
1774
+ name = str (index_value ),
1775
+ hoverinfo = 'none' ,
1776
+ marker = dict (
1777
+ color = colors [k ],
1778
+ size = 1
1779
+ )
1780
+ )
1781
+ )
1750
1782
1751
1783
layout = dict (
1752
1784
title = title ,
1753
- showlegend = False ,
1785
+ showlegend = showlegend ,
1754
1786
height = height ,
1755
1787
width = width ,
1756
1788
shapes = [],
@@ -1812,6 +1844,7 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
1812
1844
task_names = []
1813
1845
if data is None :
1814
1846
data = []
1847
+ showlegend = False
1815
1848
1816
1849
for index in range (len (chart )):
1817
1850
task = dict (x0 = chart [index ]['Start' ],
@@ -1865,24 +1898,27 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
1865
1898
)
1866
1899
)
1867
1900
1868
- #if show_colorbar is True:
1869
- # generate dummy data for colorscale visibility
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)
1901
+ if show_colorbar is True :
1902
+ # generate dummy data to generate legend
1903
+ showlegend = True
1904
+ for k , index_value in enumerate (index_vals ):
1905
+ data .append (
1906
+ dict (
1907
+ x = [tasks [index ]['x0' ], tasks [index ]['x0' ]],
1908
+ y = [k , k ],
1909
+ showlegend = True ,
1910
+ hoverinfo = 'none' ,
1911
+ name = str (index_value ),
1912
+ marker = dict (
1913
+ color = colors [index_value ],
1914
+ size = 1
1915
+ )
1916
+ )
1917
+ )
1882
1918
1883
1919
layout = dict (
1884
1920
title = title ,
1885
- showlegend = False ,
1921
+ showlegend = showlegend ,
1886
1922
height = height ,
1887
1923
width = width ,
1888
1924
shapes = [],
@@ -1946,9 +1982,9 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
1946
1982
used for indexing. If a list, its elements must be dictionaries
1947
1983
with the same required column headers: 'Task', 'Start' and
1948
1984
'Finish'.
1949
- :param (str|list|dict) colors: either a plotly scale name, an rgb
1950
- or hex color, a color tuple or a list of colors. An rgb color is
1951
- of the form 'rgb(x, y, z)' where x, y, z belong to the interval
1985
+ :param (str|list|dict|tuple ) colors: either a plotly scale name, an
1986
+ rgb or hex color, a color tuple or a list of colors. An rgb color
1987
+ is of the form 'rgb(x, y, z)' where x, y, z belong to the interval
1952
1988
[0, 255] and a color tuple is a tuple of the form (a, b, c) where
1953
1989
a, b and c belong to [0, 1]. If colors is a list, it must
1954
1990
contain the valid color types aforementioned as its members.
@@ -2024,7 +2060,8 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2024
2060
(1, 0, 1),
2025
2061
'#6c4774'],
2026
2062
index_col='Resource',
2027
- reverse_colors=True)
2063
+ reverse_colors=True,
2064
+ show_colorbar=True)
2028
2065
2029
2066
# Plot the data
2030
2067
py.iplot(fig, filename='String Entries', world_readable=True)
@@ -2049,7 +2086,9 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2049
2086
'Banana': (1, 1, 0.2)}
2050
2087
2051
2088
# Create a figure with Plotly colorscale
2052
- fig = FF.create_gantt(df, colors=colors, index_col='Resource')
2089
+ fig = FF.create_gantt(df, colors=colors,
2090
+ index_col='Resource',
2091
+ show_colorbar=True)
2053
2092
2054
2093
# Plot the data
2055
2094
py.iplot(fig, filename='dictioanry colors', world_readable=True)
@@ -2095,14 +2134,6 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2095
2134
return fig
2096
2135
else :
2097
2136
if not isinstance (colors , dict ):
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
2137
fig = FigureFactory ._gantt_colorscale (
2107
2138
chart , colors , title , index_col , show_colorbar , bar_width ,
2108
2139
showgrid_x , showgrid_y , height , width ,
0 commit comments