Пример #1
0
        public static DotGraphBuilder UndirectedGraph(string graphName)
        {
            var builder = new DotGraphBuilder
            {
                g = new Graph(graphName, false, true)
            };

            return(builder);
        }
Пример #2
0
        public void JustNodes()
        {
            var dot = DotGraphBuilder.DirectedGraph("NoEdges")
                      .AddNode("n1")
                      .AddNode("n2")
                      .Build();

            AssertAreSame("digraph NoEdges { n1; n2 }", dot);
        }
Пример #3
0
        public void JustNodesWithAttributes()
        {
            var dot = DotGraphBuilder.DirectedGraph("NoEdges")
                      .AddNode("n1").With(c => c.Color("black").Shape(NodeShape.Box))
                      .AddNode("n2").With(c => c.Shape(NodeShape.Ellipse).FontSize(12).Label("node №2"))
                      .Build();

            AssertAreSame(@"digraph NoEdges { 
n1 [color=black; shape=box]; n2 [fontsize=12; label=""node №2""; shape=ellipse] }", dot);
        }
Пример #4
0
        public void WithAcceptsEmptyAction()
        {
            var dot =
                DotGraphBuilder.NondirectedGraph("G")
                .AddNode("node").With(c => { })
                .AddEdge("a", "b").With(c => { })
                .Build();

            AssertAreSame("graph G { node; a -- b }", dot);
        }
Пример #5
0
        public void JustEdges()
        {
            var dot =
                DotGraphBuilder
                .DirectedGraph("G")
                .AddEdge("a", "b")
                .AddEdge("a", "x")
                .Build();

            AssertAreSame("digraph G { a -> b; a -> x }", dot);
        }
Пример #6
0
        public void EdgesBeforeNodes()
        {
            var dot =
                DotGraphBuilder
                .UndirectedGraph("G")
                .AddEdge("a", "b").With(e => e.Weight(3.14))
                .AddNode("b").With(a => a.Shape(NodeShape.Box))
                .Build();

            AssertAreSame("graph G { b [shape=box]; a -- b [weight=3.14] }", dot);
        }
Пример #7
0
        public void NodesAreBeforeEdges()
        {
            var dot =
                DotGraphBuilder
                .NondirectedGraph("G")
                .AddEdge("a", "b")
                .AddNode("b").With(a => a.Shape(NodeShape.Box))
                .Build();

            AssertAreSame("graph G { b [shape=box]; a -- b }", dot);
        }
Пример #8
0
 public static DotGraphBuilder With(this DotGraphBuilder graphBuilder, Action <object> action)
 {
     if (graphBuilder.nodeOrEdge == "node")
     {
         action(graphBuilder.currentNode);
     }
     else if (graphBuilder.nodeOrEdge == "edge")
     {
         action(graphBuilder.currentEdge);
     }
     return(graphBuilder);
 }
//=============================================================================================
        public static DotGraphBuilder AddEdge(this DotGraphBuilder graphBuilder, string NODE_BEG, string NODE_END)
        {
            graphBuilder.GGRAPH.AddEdge(NODE_BEG, NODE_END);
            graphBuilder.NODE_EDGE = "edge";
            foreach (var edge in graphBuilder.GGRAPH.Edges)
            {
                if (edge.SourceNode == NODE_BEG && edge.DestinationNode == NODE_END)
                {
                    graphBuilder.cur_EDGE = edge;
                }
            }
            return(graphBuilder);
        }
Пример #10
0
 public static DotGraphBuilder AddNode(this DotGraphBuilder graphBuilder, string nodeName)
 {
     graphBuilder.graph.AddNode(nodeName);
     foreach (var node in graphBuilder.graph.Nodes)
     {
         if (node.Name == nodeName)
         {
             graphBuilder.currentNode = node;
         }
     }
     graphBuilder.nodeOrEdge = "node";
     return(graphBuilder);
 }
Пример #11
0
        public void JustEdgesWithAttributes()
        {
            var dot =
                DotGraphBuilder
                .NondirectedGraph("G")
                .AddEdge("a", "b").With(a => a.Label("ab").FontSize(12).Color("black"))
                .AddEdge("a", "x")
                .AddEdge("x", "y").With(a => a.Weight(2))
                .Build();

            AssertAreSame(@"graph G { 
a -- b [color=black; fontsize=12; label=ab]; a -- x; x -- y [weight=2] }", dot);
        }
Пример #12
0
 public static DotGraphBuilder AddEdge(this DotGraphBuilder graphBuilder, string nodeBegin, string nodeEnd)
 {
     graphBuilder.graph.AddEdge(nodeBegin, nodeEnd);
     graphBuilder.nodeOrEdge = "edge";
     foreach (var edge in graphBuilder.graph.Edges)
     {
         if (edge.SourceNode == nodeBegin && edge.DestinationNode == nodeEnd)
         {
             graphBuilder.currentEdge = edge;
         }
     }
     return(graphBuilder);
 }
 public static DotGraphBuilder AddNode(this DotGraphBuilder graphBuilder, string NODE_NAME)
 {
     graphBuilder.GGRAPH.AddNode(NODE_NAME);
     foreach (var node in graphBuilder.GGRAPH.Nodes)
     {
         if (node.Name == NODE_NAME)
         {
             graphBuilder.cur_NODE = node;
         }
     }
     graphBuilder.NODE_EDGE = "node";
     return(graphBuilder);
 }
//=============================================================================================
        public static DotGraphBuilder With(this DotGraphBuilder graphBuilder, Action <object> action)
        {
            if (graphBuilder.NODE_EDGE == "node")
            {
                action(graphBuilder.cur_NODE);
            }

            else if (graphBuilder.NODE_EDGE == "edge")
            {
                action(graphBuilder.cur_EDGE);
            }

            return(graphBuilder);
        }
Пример #15
0
        static void Main(string[] args)
        {
            var dot =
                DotGraphBuilder.DirectedGraph("CommentParser")
                .AddNode("START").With(a => a.Shape(NodeShape.Ellipse).Color("green"))
                .AddNode("comment").With(a => a.Shape(NodeShape.Box))
                .AddEdge("START", "slash").With(a => a.Label("'/'"))
                .AddEdge("slash", "comment").With(a => a.Label("'/'"))
                .AddEdge("comment", "comment").With(a => a.Label("other chars"))
                .AddEdge("comment", "START").With(a => a.Label("'\\\\n'"))
                .Build();

            Console.WriteLine(dot);
            ShowRenderedGraph(dot);
        }
Пример #16
0
        public void NamesAreEscaped()
        {
            // Используйте готовый код Graph, DotFormatWriter, чтобы пройти этот тест "за бесплатно"
            var dot = DotGraphBuilder.DirectedGraph("my graph")
                      .AddNode("42 is the answer").With(a => a.Color("#00ff00"))
                      .AddNode("-3.14")
                      .AddNode("\"quotes\"")
                      .AddEdge("3", "abc").With(a => a.Label("long text"))
                      .AddEdge("3x", "a b c").With(a => a.Label("1.234"))
                      .Build();

            AssertAreSame(@"digraph ""my graph"" {
""42 is the answer"" [color=""#00ff00""];
-3.14;
""\""quotes\"""";
3 -> abc [label=""long text""];
""3x"" -> ""a b c"" [label=1.234]
}", dot);
        }
Пример #17
0
        public void EmptyDirectedGraph()
        {
            var dot = DotGraphBuilder.DirectedGraph("EmptyGraph").Build();

            AssertAreSame("digraph EmptyGraph { }", dot);
        }
Пример #18
0
 public NodeBuilder(DotGraphBuilder graphBuilder, GraphNode node) : base(graphBuilder,
                                                                         new AttributeBuilder(node.Attributes))
 {
 }
Пример #19
0
 public EdgeBuilder(DotGraphBuilder graphBuilder, GraphEdge edge) : base(graphBuilder,
                                                                         new AttributeBuilder(edge.Attributes))
 {
 }
Пример #20
0
 public BaseItemBuilder(DotGraphBuilder graphBuilder, AttributeBuilder attributeBuilder)
 {
     this.attributeBuilder = attributeBuilder;
     this.graphBuilder     = graphBuilder;
 }
 public static string Build(this DotGraphBuilder graphBuilder)
 {
     return(graphBuilder.GGRAPH.ToDotFormat());
 }
Пример #22
0
        public void EmptyNondirecterGraph()
        {
            var dot = DotGraphBuilder.NondirectedGraph("EmptyGraph").Build();

            AssertAreSame("graph EmptyGraph { }", dot);
        }