Skip to content

Commit 280bb90

Browse files
committed
Fixes Plotly Color error when solving a problem with more than 10 jobs using random colors
1 parent edf47c1 commit 280bb90

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import datetime
55
import json
6-
6+
import numpy as np
77
import plotly
88
import plotly.figure_factory as ff
99
from flask import Flask, render_template, request
@@ -45,6 +45,9 @@ def jobs_to_gantt_fig(scheduled_jobs, nb_machines, nb_jobs):
4545
Returns:
4646
Plotly.figure: a plotly figure for generated gantt chart
4747
"""
48+
r = lambda: np.random.randint(0,256, dtype=int)
49+
colors = ['#%02X%02X%02X' % (r(),r(),r()) for _ in range(nb_jobs)]
50+
4851
tasks = []
4952
curr_date = datetime.datetime.now()
5053
zipped_jobs_list = list(zip(*scheduled_jobs))
@@ -59,7 +62,7 @@ def jobs_to_gantt_fig(scheduled_jobs, nb_machines, nb_jobs):
5962
m_id+1), "Start": start_t, "Finish": finish_t, "Resource": job[m_id]["name"]}
6063
tasks.append(task)
6164
fig = ff.create_gantt(tasks, show_colorbar=True, index_col="Resource",
62-
showgrid_x=True, showgrid_y=True, group_tasks=True, bar_width=0.08)
65+
showgrid_x=True, showgrid_y=True, group_tasks=True, bar_width=0.08, colors=colors)
6366
return fig
6467

6568

0 commit comments

Comments
 (0)