Skip to content

Commit f7eaefa

Browse files
Andreas SchmitzAndreas Schmitz
Andreas Schmitz
authored and
Andreas Schmitz
committed
[tools.py] Gantt Chart: added code to allow for description texts in Gantt chart tasks
1 parent d79605d commit f7eaefa

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

plotly/tools.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,8 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
17391739
task = dict(x0=chart[index]['Start'],
17401740
x1=chart[index]['Finish'],
17411741
name=chart[index]['Task'])
1742+
if 'Description' in chart[index]:
1743+
task['description'] = chart[index]['Description']
17421744
tasks.append(task)
17431745

17441746
shape_template = {
@@ -1781,14 +1783,16 @@ def _gantt(chart, colors, title, bar_width, showgrid_x, showgrid_y,
17811783
color_index = 0
17821784
tasks[index]['fillcolor'] = colors[color_index]
17831785
# Add a line for hover text and autorange
1784-
data.append(
1785-
dict(
1786+
entry = dict(
17861787
x=[tasks[index]['x0'], tasks[index]['x1']],
17871788
y=[groupID, groupID],
17881789
name='',
17891790
marker={'color': 'white'}
17901791
)
1791-
)
1792+
if "description" in tasks[index]:
1793+
entry['text'] = tasks[index]['description']
1794+
del tasks[index]['description']
1795+
data.append(entry)
17921796
color_index += 1
17931797

17941798
layout = dict(
@@ -1862,6 +1866,8 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
18621866
task = dict(x0=chart[index]['Start'],
18631867
x1=chart[index]['Finish'],
18641868
name=chart[index]['Task'])
1869+
if 'Description' in chart[index]:
1870+
task['description'] = chart[index]['Description']
18651871
tasks.append(task)
18661872

18671873
shape_template = {
@@ -1930,14 +1936,17 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
19301936
)
19311937

19321938
# add a line for hover text and autorange
1933-
data.append(
1934-
dict(
1939+
entry = dict(
19351940
x=[tasks[index]['x0'], tasks[index]['x1']],
19361941
y=[groupID, groupID],
19371942
name='',
19381943
marker={'color': 'white'}
19391944
)
1940-
)
1945+
if "description" in tasks[index]:
1946+
entry['text'] = tasks[index]['description']
1947+
del tasks[index]['description']
1948+
data.append(entry)
1949+
19411950

19421951
if show_colorbar is True:
19431952
# generate dummy data for colorscale visibility
@@ -2006,14 +2015,16 @@ def _gantt_colorscale(chart, colors, title, index_col, show_colorbar,
20062015
]
20072016

20082017
# add a line for hover text and autorange
2009-
data.append(
2010-
dict(
2018+
entry = dict(
20112019
x=[tasks[index]['x0'], tasks[index]['x1']],
20122020
y=[groupID, groupID],
20132021
name='',
20142022
marker={'color': 'white'}
20152023
)
2016-
)
2024+
if "description" in tasks[index]:
2025+
entry['text'] = tasks[index]['description']
2026+
del tasks[index]['description']
2027+
data.append(entry)
20172028

20182029
if show_colorbar is True:
20192030
# generate dummy data to generate legend
@@ -2103,6 +2114,8 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
21032114
task = dict(x0=chart[index]['Start'],
21042115
x1=chart[index]['Finish'],
21052116
name=chart[index]['Task'])
2117+
if 'Description' in chart[index]:
2118+
task['description'] = chart[index]['Description']
21062119
tasks.append(task)
21072120

21082121
shape_template = {
@@ -2157,14 +2170,16 @@ def _gantt_dict(chart, colors, title, index_col, show_colorbar, bar_width,
21572170
tasks[index]['fillcolor'] = colors[chart[index][index_col]]
21582171

21592172
# add a line for hover text and autorange
2160-
data.append(
2161-
dict(
2173+
entry = dict(
21622174
x=[tasks[index]['x0'], tasks[index]['x1']],
21632175
y=[groupID, groupID],
21642176
name='',
21652177
marker={'color': 'white'}
21662178
)
2167-
)
2179+
if "description" in tasks[index]:
2180+
entry['text'] = tasks[index]['description']
2181+
del tasks[index]['description']
2182+
data.append(entry)
21682183

21692184
if show_colorbar is True:
21702185
# generate dummy data to generate legend

0 commit comments

Comments
 (0)