Skip to content

Commit

Permalink
Merge pull request #558 from sulmar/dev
Browse files Browse the repository at this point in the history
Refactor Add initial transition to GetInitialTransition method
  • Loading branch information
mclift authored Dec 23, 2023
2 parents 4b1abd6 + 5dbf264 commit 3a97ffe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/Stateless/Graph/GraphStyleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public abstract class GraphStyleBase
/// <returns>Prefix text</returns>
public abstract string GetPrefix();

/// <summary>
/// Get initial transition if present
/// </summary>
/// <returns></returns>
public abstract string GetInitialTransition(Reflection.StateInfo initialState);

/// <summary>
/// Returns the formatted text for a single state.
/// For example, for DOT files this would be the description of a single node:
Expand Down
6 changes: 1 addition & 5 deletions src/Stateless/Graph/StateGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ public string ToGraph(GraphStyleBase style)
dirgraphText += System.Environment.NewLine + transit;

// Add initial transition if present
var initialStateName = initialState.UnderlyingState.ToString();
dirgraphText += System.Environment.NewLine + $" init [label=\"\", shape=point];";
dirgraphText += System.Environment.NewLine + $" init -> \"{initialStateName}\"[style = \"solid\"]";

dirgraphText += System.Environment.NewLine + "}";
dirgraphText += style.GetInitialTransition(initialState);

return dirgraphText;
}
Expand Down
19 changes: 18 additions & 1 deletion src/Stateless/Graph/UmlDotGraphStyle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Stateless.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -122,5 +123,21 @@ internal string FormatOneLine(string fromNodeName, string toNodeName, string lab
{
return $"\"{fromNodeName}\" -> \"{toNodeName}\" [style=\"solid\", label=\"{label}\"];";
}

/// <summary>
///
/// </summary>
/// <param name="initialState"></param>
/// <returns></returns>
public override string GetInitialTransition(StateInfo initialState)
{
var initialStateName = initialState.UnderlyingState.ToString();
string dirgraphText = System.Environment.NewLine + $" init [label=\"\", shape=point];";
dirgraphText += System.Environment.NewLine + $" init -> \"{initialStateName}\"[style = \"solid\"]";

dirgraphText += System.Environment.NewLine + "}";

return dirgraphText;
}
}
}

0 comments on commit 3a97ffe

Please sign in to comment.