Skip to content

Commit

Permalink
Merge pull request #25 from MineralsCloud:LayeredLayouts
Browse files Browse the repository at this point in the history
Rewrite `WorkflowPlot`
  • Loading branch information
singularitti authored Oct 30, 2023
2 parents a46c7d2 + e5480c0 commit cdf6f4c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ version = "0.1.0"
[deps]
EasyJobsBase = "db8ca866-b61f-4bd1-a9b9-75c107d645d4"
GraphRecipes = "bd48cda9-67a9-57be-86fa-5b3c104eda73"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LayeredLayouts = "f4a74d36-062a-4d48-97cd-1356bad1de4e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SimpleWorkflows = "6a97d125-85da-4b66-b300-4bba10360563"

Expand Down
64 changes: 51 additions & 13 deletions src/SimpleWorkflowRecipes.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module SimpleWorkflowRecipes

using EasyJobsBase: JobStatus, PENDING, RUNNING, SUCCEEDED, FAILED, getstatus
using Graphs: edges
using GraphRecipes: GraphPlot, get_source_destiny_weight, get_adjacency_list
using RecipesBase: @userplot, @recipe
using SimpleWorkflows: eachjob, findjob
using LayeredLayouts: Zarate, solve_positions
using RecipesBase: @userplot, @recipe, @series
using SimpleWorkflows: Workflow, indexin

function getcolor(status::JobStatus)
if status == PENDING
Expand All @@ -20,17 +22,53 @@ function getcolor(status::JobStatus)
end

@userplot WorkflowPlot
@recipe function f(plot::WorkflowPlot)
workflow = plot.args[end]
root := :bottom
curves --> false
nodeshape --> :ellipse
nodesize --> 0.2
nodecolor --> map(getcolor getstatus, eachjob(workflow))
names --> map(Base.Fix2(findjob, workflow), eachjob(workflow))
fontsize --> 9
method --> :spring
return GraphPlot(get_source_destiny_weight(get_adjacency_list(workflow.graph)))
@recipe function f(
plot::WorkflowPlot;
edgewidth=1,
edgestrokecolor=:black,
nodeshape=:circle,
nodesize=5,
root=:left,
)
if root == :right
# FIXME
elseif root == :bottom
permute --> (:x, :y)
elseif root == :top
# FIXME
elseif root == :left
# do nothing
else
throw(ArgumentError("unknown root `$root`!"))
end
workflow = only(plot.args)
framestyle --> :none
grid --> false
legend --> false
label --> ""
guide --> ""
nodes_x, nodes_y, paths = solve_positions(Zarate(), workflow.graph)
for edge in edges(workflow.graph)
edge_x, edge_y = paths[edge]
@series begin
seriestype --> :path
arrow --> true
linewidth --> edgewidth
linecolor --> edgestrokecolor
edge_x, edge_y
end
end
for (job, (x, y)) in zip(workflow, zip(nodes_x, nodes_y))
@series begin
seriestype --> :scatter
markershape --> nodeshape
markersize --> nodesize
markerstrokewidth --> 0
seriescolor --> getcolor(getstatus(job))
series_annotations --> string(only(indexin(job, workflow)))
Base.vect(x), Base.vect(y)
end
end
end

end

0 comments on commit cdf6f4c

Please sign in to comment.