Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate code base to QuikGraph. #67

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/Automatonymous.Tests/Visualizer_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,19 @@ public void Setup()
8 [shape=rectangle, label=""Suspend""];
9 [shape=rectangle, label=""Resume""];
10 [shape=rectangle, label=""Restart<RestartData>""];
0 -> 5 [ ];
1 -> 7 [ ];
1 -> 8 [ ];
2 -> 10 [ ];
4 -> 9 [ ];
5 -> 1 [ ];
5 -> 6 [ ];
6 -> 2 [ ];
7 -> 3 [ ];
8 -> 4 [ ];
9 -> 1 [ ];
10 -> 1 [ ];
}
";
0 -> 5;
1 -> 7;
1 -> 8;
2 -> 10;
4 -> 9;
5 -> 1;
5 -> 6;
6 -> 2;
7 -> 3;
8 -> 4;
9 -> 1;
10 -> 1;
}";


class Instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="QuickGraph.NETStandard" Version="3.8.0"/>
<PackageReference Include="QuikGraph" Version="2.2.0"/>
<PackageReference Include="QuikGraph.Graphviz" Version="2.2.0"/>
<ProjectReference Include="..\Automatonymous\Automatonymous.csproj"/>
</ItemGroup>

Expand Down
40 changes: 17 additions & 23 deletions src/Automatonymous.Visualizer/StateMachineGraphGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
using System;
using System.Linq;
using Graphing;
using QuickGraph;
using QuickGraph.Graphviz;
using QuickGraph.Graphviz.Dot;

using QuikGraph;
using QuikGraph.Graphviz;
using QuikGraph.Graphviz.Dot;

public class StateMachineGraphvizGenerator
{
Expand All @@ -20,48 +19,43 @@ public StateMachineGraphvizGenerator(StateMachineGraph data)
public string CreateDotFile()
{
var algorithm = new GraphvizAlgorithm<Vertex, Edge<Vertex>>(_graph);
algorithm.FormatEdge += EdgeStyler;
algorithm.FormatVertex += VertexStyler;
return algorithm.Generate();
}

void EdgeStyler(object sender, FormatEdgeEventArgs<Vertex, Edge<Vertex>> e)
{
}

void VertexStyler(object sender, FormatVertexEventArgs<Vertex> e)
private static void VertexStyler(object sender, FormatVertexEventArgs<Vertex> args)
{
e.VertexFormatter.Label = e.Vertex.Title;
args.VertexFormat.Label = args.Vertex.Title;

if (e.Vertex.VertexType == typeof(Event))
if (args.Vertex.VertexType == typeof(Event))
{
e.VertexFormatter.FontColor = GraphvizColor.Black;
e.VertexFormatter.Shape = GraphvizVertexShape.Rectangle;
args.VertexFormat.FontColor = GraphvizColor.Black;
args.VertexFormat.Shape = GraphvizVertexShape.Rectangle;

if (e.Vertex.TargetType != typeof(Event) && e.Vertex.TargetType != typeof(Exception))
e.VertexFormatter.Label += "<" + e.Vertex.TargetType.Name + ">";
if (args.Vertex.TargetType != typeof(Event) && args.Vertex.TargetType != typeof(Exception))
args.VertexFormat.Label += "<" + args.Vertex.TargetType.Name + ">";
}
else
{
switch (e.Vertex.Title)
switch (args.Vertex.Title)
{
case "Initial":
e.VertexFormatter.FillColor = GraphvizColor.White;
args.VertexFormat.FillColor = GraphvizColor.White;
break;
case "Final":
e.VertexFormatter.FillColor = GraphvizColor.White;
args.VertexFormat.FillColor = GraphvizColor.White;
break;
default:
e.VertexFormatter.FillColor = GraphvizColor.White;
e.VertexFormatter.FontColor = GraphvizColor.Black;
args.VertexFormat.FillColor = GraphvizColor.White;
args.VertexFormat.FontColor = GraphvizColor.Black;
break;
}

e.VertexFormatter.Shape = GraphvizVertexShape.Ellipse;
args.VertexFormat.Shape = GraphvizVertexShape.Ellipse;
}
}

static AdjacencyGraph<Vertex, Edge<Vertex>> CreateAdjacencyGraph(StateMachineGraph data)
private static AdjacencyGraph<Vertex, Edge<Vertex>> CreateAdjacencyGraph(StateMachineGraph data)
{
var graph = new AdjacencyGraph<Vertex, Edge<Vertex>>();

Expand Down