Example #1
0
        private void CompileNode(StringBuilder builder, DotNode node, bool indented, int indentationLevel, bool formatStrings)
        {
            builder.AddIndentation(indented, indentationLevel);

            builder.Append(SurroundStringWithQuotes(node.Identifier, formatStrings));

            CompileAttributes(builder, node.Attributes, formatStrings);

            builder.Append("; ");

            builder.AddIndentationNewLine(indented);
        }
Example #2
0
        private void CompileSubGraph(StringBuilder builder, DotSubGraph subGraph, bool indented, int indentationLevel, bool formatStrings)
        {
            builder.AddIndentation(indented, indentationLevel);

            builder.Append($"subgraph {SurroundStringWithQuotes(subGraph.Identifier, formatStrings)} {{ ");

            builder.AddIndentationNewLine(indented);

            indentationLevel++;

            CompileSubGraphAttributes(builder, subGraph.Attributes, formatStrings);

            foreach (var element in subGraph.Elements)
            {
                if (element is DotEdge edge)
                {
                    CompileEdge(builder, edge, indented, indentationLevel, formatStrings);
                }
                else if (element is DotNode node)
                {
                    CompileNode(builder, node, indented, indentationLevel, formatStrings);
                }
                else if (element is DotSubGraph subSubGraph)
                {
                    CompileSubGraph(builder, subSubGraph, indented, indentationLevel, formatStrings);
                }
                else
                {
                    throw new DotException($"Subgraph body can't contain element of type: {element.GetType()}");
                }
            }

            indentationLevel--;

            builder.AddIndentation(indented, indentationLevel);

            builder.Append("} ");

            builder.AddIndentationNewLine(indented);
        }
Example #3
0
        private void CompileEdge(StringBuilder builder, DotEdge edge, bool indented, int indentationLevel, bool formatStrings)
        {
            builder.AddIndentation(indented, indentationLevel);

            CompileEdgeEndPoint(builder, edge.Left, formatStrings);

            builder.Append(_graph.Directed ? " -> " : " -- ");

            CompileEdgeEndPoint(builder, edge.Right, formatStrings);

            CompileAttributes(builder, edge.Attributes, formatStrings);

            builder.Append("; ");

            builder.AddIndentationNewLine(indented);
        }
Example #4
0
        private void CompileGraph(StringBuilder builder, bool indented, bool formatStrings)
        {
            var indentationLevel = 0;

            if (_graph.Strict)
            {
                builder.Append("strict ");
            }

            builder.Append(_graph.Directed ? "digraph " : "graph ");

            builder.Append($"{SurroundStringWithQuotes(_graph.Identifier, formatStrings)} {{ ");

            builder.AddIndentationNewLine(indented);

            indentationLevel++;

            foreach (var element in _graph.Elements)
            {
                if (element is DotEdge edge)
                {
                    CompileEdge(builder, edge, indented, indentationLevel, formatStrings);
                }
                else if (element is DotNode node)
                {
                    CompileNode(builder, node, indented, indentationLevel, formatStrings);
                }
                else if (element is DotSubGraph subGraph)
                {
                    CompileSubGraph(builder, subGraph, indented, indentationLevel, formatStrings);
                }
                else
                {
                    throw new DotException($"Graph body can't contain element of type: {element.GetType()}");
                }
            }

            indentationLevel--;

            builder.Append("}");
        }