Example #1
0
        public override string ToDot(DotFormatOptions dotOption = null)
        {
            var suboption = dotOption?.Clone() ?? new DotFormatOptions();

            suboption.BodyOnly = true;

            var strict      = IsStrict ? ModelHelper.StrictGraphName + " " : "";
            var graphType   = IsDirected ? ModelHelper.DirectedGraphName : ModelHelper.UndirectedGraphName;
            var graphId     = " " + Id;
            var graphString = FormattableString.Invariant($"{strict}{graphType}{graphId} ") +
                              base.ToDot(suboption);

            return(graphString);
        }
Example #2
0
        public virtual string ToDot(DotFormatOptions dotOption = null)
        {
            var subOption = dotOption?.Clone() ?? new DotFormatOptions();
            var bodyOnly  = subOption.BodyOnly;

            subOption.BodyOnly = false;

            const string newLine   = "\n";
            var          depth     = SubGraphDepth;
            var          indent    = string.Concat(Enumerable.Repeat("  ", depth));
            var          subIndent = string.Concat(Enumerable.Repeat("  ", depth + 1));

            var graphString = "";

            if (!bodyOnly)
            {
                var idStr = Id != null ? Id + " " : "";
                graphString += indent + "subgraph " + idStr;
            }
            graphString += "{" + newLine;


            if (Attributes.Count > 0)
            {
                graphString += subIndent + "graph " + Attributes + newLine;
            }
            if (NodeAttributes.Count > 0)
            {
                graphString += subIndent + "node " + NodeAttributes + newLine;
            }
            if (EdgeAttributes.Count > 0)
            {
                graphString += subIndent + "edge " + EdgeAttributes + newLine;
            }

            var subgraphs = subOption.OrderByName
                ? GetSubGraphSubGraphs(false).OrderBy(v => v)
                : GetSubGraphSubGraphs(false);

            foreach (var subgraph in subgraphs)
            {
                graphString += subgraph.ToDot(subOption);
            }

            var nodes = subOption.OrderByName
                ? GetSubGraphNodes(false).OrderBy(v => v)
                : GetSubGraphNodes(false);
            var edges = subOption.OrderByName
                ? GetSubGraphEdges(false).OrderBy(v => v)
                : GetSubGraphEdges(false);
            var allEdges = Root.GetEdges().ToList();

            if (subOption.NodeSelector != null)
            {
                nodes    = nodes.Where(subOption.NodeSelector);
                edges    = edges.Where(e => subOption.NodeSelector(e.SourceNode) && subOption.NodeSelector(e.EndNode));
                allEdges =
                    allEdges.Where(e => subOption.NodeSelector(e.SourceNode) && subOption.NodeSelector(e.EndNode))
                    .ToList();
            }

            foreach (var node in nodes)
            {
                if (ShouldShowNode(node, allEdges, subOption.ShowRedundantNodes))
                {
                    graphString += subIndent + node + newLine;
                }
            }

            foreach (var edge in edges)
            {
                graphString += subIndent + edge + newLine;
            }

            graphString += indent + "}" + newLine;

            return(graphString);
        }