Skip to content

Commit

Permalink
Added sorting parameter and task sorting code block
Browse files Browse the repository at this point in the history
  • Loading branch information
Wright4TheJob committed Dec 13, 2024
1 parent 66a47bc commit 9285ed9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions processscheduler/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def render_gantt_plotly(
sort: Optional[str] = None,
fig_filename: Optional[str] = None,
html_filename: Optional[str] = None,
sort_by_start: bool = False,
) -> None:
"""Use plotly.create_gantt method, see
https://plotly.github.io/plotly.py-docs/generated/plotly.figure_factory.create_gantt.html
Expand All @@ -121,6 +122,14 @@ def render_gantt_plotly(
# tasks to render
if render_mode == "Task":
tasks_to_render = solution.get_scheduled_tasks()
if sort_by_start:
tasks_to_render = dict(
sorted(
tasks_to_render.items(),
key=lambda item: solution.tasks[item[0]].start,
reverse=True
)
)
else:
tasks_to_render = solution.tasks

Expand Down Expand Up @@ -209,6 +218,7 @@ def render_gantt_matplotlib(
show_indicators: Optional[bool] = True,
render_mode: Optional[str] = "Resource",
fig_filename: Optional[str] = None,
sort_by_start: bool = False
) -> None:
"""generate a gantt diagram using matplotlib.
Inspired by
Expand All @@ -228,6 +238,14 @@ def render_gantt_matplotlib(
tasks_to_render = (
solution.get_scheduled_tasks()
) # get_all_tasks_but_unavailable()
if sort_by_start:
tasks_to_render = dict(
sorted(
tasks_to_render.items(),
key=lambda item: solution.tasks[item[0]].start,
reverse=True
)
)
else:
tasks_to_render = solution.tasks

Expand Down

0 comments on commit 9285ed9

Please sign in to comment.