Beispiel #1
0
        public void MultipleNodesWithAttributes()
        {
            DotGraph gr   = new DotGraph();
            var      node = new DotNode();

            node.Attributes.Add("label", "beta");
            gr.Nodes.Add("7cbeb388-085b-4087-9fec-50d7f180e334", node);
            node = new DotNode();
            node.Attributes.Add("label", "delta");
            node.Attributes.Add("pos", "43,67");
            node.Attributes.Add("color", "blueishgrey");
            gr.Nodes.Add("some id", node);
            node = new DotNode();
            node.Attributes.Add("label", "theta");
            node.Attributes.Add("type", "function-node");
            gr.Nodes.Add("other id", node);

            string result = DotFileGenerator.Serialize(gr);

            Assert.Equal(@"digraph {
""7cbeb388-085b-4087-9fec-50d7f180e334""[""label""=""beta""]
""some id""[""label""=""delta"", ""pos""=""43,67"", ""color""=""blueishgrey""]
""other id""[""label""=""theta"", ""type""=""function-node""]
}", result, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Beispiel #2
0
        public void MultipleEdgeOnSameNodes()
        {
            DotGraph gr = new DotGraph();

            gr.Nodes.Add("abc", new DotNode()
            {
                Attributes = { ["label"] = "beta" }
            });
            gr.Nodes.Add("some id", new DotNode()
            {
                Attributes = { ["label"] = "delta" }
            });
            gr.Nodes.Add("third", new DotNode()
            {
                Attributes = { ["other label"] = "asd" }
            });

            gr.Edges.Add(("abc", "some id"), new List <DotEdge> {
                new DotEdge(), new DotEdge(), new DotEdge()
            });

            string result = DotFileGenerator.Serialize(gr);

            Assert.Equal(@"digraph {
""abc""[""label""=""beta""]
""some id""[""label""=""delta""]
""third""[""other label""=""asd""]
""abc"" -> ""some id""
""abc"" -> ""some id""
""abc"" -> ""some id""
}", result, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Beispiel #3
0
        public string SerializeGraphAsDotString()
        {
            DotGraph gr  = DotGraphConverter.ToDot(GraphArea.ToGraph());
            string   dot = DotFileGenerator.Serialize(gr);

            return(dot);
        }
Beispiel #4
0
        public void SimpleNode()
        {
            DotGraph gr   = new DotGraph();
            var      node = new DotNode();

            gr.Nodes.Add("7cbeb388-085b-4087-9fec-50d7f180e334", node);

            string result = DotFileGenerator.Serialize(gr);

            Assert.Equal(@"digraph {
""7cbeb388-085b-4087-9fec-50d7f180e334""
}", result, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Beispiel #5
0
        public void NodeWithAttribute()
        {
            DotGraph gr   = new DotGraph();
            var      node = new DotNode();

            node.Attributes.Add("label", "beta");
            gr.Nodes.Add("7cbeb388-085b-4087-9fec-50d7f180e334", node);

            string result = DotFileGenerator.Serialize(gr);

            Assert.Equal(@"digraph {
""7cbeb388-085b-4087-9fec-50d7f180e334""[""label""=""beta""]
}", result, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Beispiel #6
0
        public void GraphAttributes()
        {
            DotGraph gr = new DotGraph();

            gr.GraphAttributes.Add("lex parse", "lorem");
            gr.Nodes.Add("abc", new DotNode()
            {
                Attributes = { ["label"] = "beta" }
            });

            string result = DotFileGenerator.Serialize(gr);

            Assert.Equal(@"digraph {
graph [""lex parse""=""lorem""]
""abc""[""label""=""beta""]
}", result, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
Beispiel #7
0
        public static DotGraph LayoutNodes(DotGraph dg)
        {
            // call graphviz dot to layout the nodes
            string dotFile     = DotFileGenerator.Serialize(dg);
            string resultDot   = "";
            string errorOutput = "";

            using (Process proc = new Process())
            {
                // TODO: We will need to give a full path to the dot.exe, for now it should be in the path
                proc.StartInfo.FileName               = "dot.exe";
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardInput  = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;

                proc.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    resultDot += e.Data;
                });
                proc.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    errorOutput += e.Data;
                });

                proc.Start();

                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();

                proc.StandardInput.Write(dotFile + "\n");

                while (!resultDot.TrimEnd().EndsWith("}"))
                {
                    System.Threading.Thread.Sleep(10);
                }
                proc.Kill();
            }
            if (errorOutput != "")
            {
                Debug.WriteLine(errorOutput);
            }
            return(DotLoader.Load(resultDot));
        }