private String GetObjectDotDeclaration(DotNode <T> node, DotNotationSettings settings) { var shape = node.Shape == null ? DotShapes.Box : node.Shape; var text = String.IsNullOrEmpty(node.Text) ? node.GetType().Name : node.Text; String strSettings = $"fontsize={settings.FontSize.ToString()} margin={settings.Margin}"; return($"\"{node.Id}\" [shape=\"{shape.ToString()}\" label=\"{text}\" tooltip=\"{text}\" {strSettings}]"); }
private String GetLinkDotDeclaration(DotNode <T> node, DotNotationSettings settings) { String strSettings = $"fontsize={settings.FontSize.ToString()} margin={settings.Margin}"; var sb = new StringBuilder(); foreach (var nodeRef in node.ParentNodes) { sb.AppendLine($"\"{nodeRef.DotNode.Id.ToString()}\" -> \"{node.Id.ToString()}\" [label=\"{nodeRef.Name}\" {strSettings}]"); } return(sb.ToString()); }
public string Convert(Flow <T> flow) { DotNotationSettings _settings = this.Settings == null ? DotNotationSettings.Default : this.Settings; var notations = ReadFlow(flow.Actions).Nodes; var result = ToDotNotation(notations, Settings); return($"digraph G {{\n" + $"compound=true;\n" + // allow links between edges $"{result.Nodes}\n" + // declare all the nodes and subgraphs $"{result.Links}\n" + // links must always be declared all together at the end; including links within subgraphs $"}}"); }
private (string Nodes, string Links) ToDotNotation(List <DotNode <T> > nodes, DotNotationSettings settings = null) { if (settings == null) { settings = DotNotationSettings.Default; } String strSettings = $"fontsize={settings.FontSize.ToString()} margin={settings.Margin}"; StringBuilder dotSb = new StringBuilder(); StringBuilder linkSb = new StringBuilder(); foreach (var node in nodes) { if (node.SubNodes.Count > 0) { // cluster id is based on the group node id, replacing the guid - by _ dotSb.AppendLine($"subgraph cluster_{node.Id.ToString().Replace('-', '_')} {{"); dotSb.AppendLine($" label = \"{node.Text}\""); var subNotation = ToDotNotation(node.SubNodes, settings); dotSb.AppendLine(subNotation.Nodes); linkSb.AppendLine(subNotation.Links); dotSb.AppendLine("}"); } else { dotSb.AppendLine(GetObjectDotDeclaration(node, settings)); linkSb.AppendLine(GetLinkDotDeclaration(node, settings)); } } dotSb.AppendLine(); // just a separation line before declaring the links return(dotSb.ToString(), linkSb.ToString()); }
public DotNotationProvider(DotNotationSettings settings = null) { this.Settings = settings; }