public void RenderFromInMemoryGraph()
        {
            const string graph    = @"digraph G { node [style=filled, shape=rect]

# Nodes
""String age"" -> ""Int64.Parse()"" -> {""Int64"", ""Collector""}


# Formatting
""String age"" [color=green]
""Int64"" [color=""#9fbff4""]
""Int64.Parse()"" [shape=invhouse]
""Collector"" [color = ""#c361f4""]

{ rank=same; ""Int64.Parse()"", ""Collector""}


}";
            var          graphViz = new GraphViz();


            byte[] result = graphViz.LayoutAndRenderDotGraph(graph, "png");

            Approvals.VerifyBinaryFile(result, ".png");
        }
        public void RenderFromGraphInFileToFile()
        {
            string outputFilePath = Path.Combine(Directory.GetCurrentDirectory(), "RenderFromGraphInFile.png");

            const string graph         = @"digraph G { node [style=filled, shape=rect]

# Nodes
""String age"" -> ""Int64.Parse()"" -> {""Int64"", ""Collector""}


# Formatting
""String age"" [color=green]
""Int64"" [color=""#9fbff4""]
""Int64.Parse()"" [shape=invhouse]
""Collector"" [color = ""#c361f4""]

{ rank=same; ""Int64.Parse()"", ""Collector""}


}";
            string       inputFilePath = Path.Combine(Directory.GetCurrentDirectory(), "RenderFromInGraphInFile.dot");

            File.WriteAllText(inputFilePath, graph);

            var graphViz = new GraphViz();


            graphViz.LayoutAndRenderDotGraphFromFile(inputFilePath, outputFilePath, "png");

            Approvals.VerifyFile(outputFilePath);
        }
示例#3
0
        public void RenderError()
        {
            const string graph = @"invalid";

            var graphViz = new GraphViz();

            graphViz.LayoutAndRender(null, graph, null, null, "svg");
        }
示例#4
0
        private void spitOutGraph()
        {
            routesGraph = new GraphViz();
            pathsGraph  = new GraphViz();
            addToGraph(mR0, routesGraph, pathsGraph);

            var str  = routesGraph.ToString();
            var str2 = pathsGraph.ToString();
        }
示例#5
0
        private static void VerifyAsRenderedGraph(IGraphNode input, string format)
        {
            var dotGraph = DotGraph.DotGraph.FromPipeline(input);
            var graphViz = new GraphViz();

            graphViz.Config.TreatWarningsAsErrors = true;

            var output = graphViz.LayoutAndRenderDotGraph(dotGraph.ToString(), format);

            Approvals.VerifyBinaryFile(output, "." + format);
        }
示例#6
0
        private void addVariable(object sender, RoutedEventArgs e)
        {
            var newDialog = new FunctionsDialog();

            newDialog.ShowDialog();
            if (newDialog.DialogResult == true)
            {
                booleanFunctions.Add(newDialog.Result, "");
            }

            ReloadFunctions(sender, e);


            wiringDiagram.WithGraphAttributesOf(
                RankDir.TB,
                Font.Name("Arial"),
                Font.Size(55))
            .WithNodeAttributesOf(
                Shape.Ellipse,
                Color.Black);

            wiringDiagram.Containing(DotBuilder.Statements.Node.Name(newDialog.Result));


            // to get the raw dot output
            var dot = wiringDiagram.Render();

            // to render to a file stream

            var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }
示例#7
0
        private void addToGraph(TestRoute mR0, GraphViz graph, GraphViz pathsGraph)
        {
            graph.Add(mR0.GetName());
            graph.SetGroup("level" + mR0.Level, mR0.GetName());
            foreach (TestRoute next in mR0.NextRoutes)
            {
                graph.Connect(mR0.GetName(), next.GetName());
                addToGraph(next, graph, pathsGraph);
            }

            foreach (TestPath path in mR0.Paths)
            {
                pathsGraph.SetGroup(mR0.GetName(), path.GetName());
                var left = path.LeftParralel as TestPath;
                if (left != null)
                {
                    pathsGraph.Connect(path.GetName(), left.GetName());
                }
                var right = path.RightParralel as TestPath;
                if (right != null)
                {
                    pathsGraph.Connect(path.GetName(), right.GetName());
                }
                foreach (TestPath next in path.NextPaths)
                {
                    pathsGraph.Connect(path.GetName(), next.GetName(), new Dictionary <string, string>()
                    {
                        { "style", "bold" }
                    });

                    left = next.LeftParralel as TestPath;
                    if (left != null)
                    {
                        pathsGraph.Connect(path.GetName(), left.GetName(), new Dictionary <string, string>()
                        {
                            { "style", "dotted" }
                        }, overwrite: false);
                    }
                    right = next.RightParralel as TestPath;
                    if (right != null)
                    {
                        pathsGraph.Connect(path.GetName(), right.GetName(), new Dictionary <string, string>()
                        {
                            { "style", "dotted" }
                        }, overwrite: false);
                    }
                }
            }
        }
示例#8
0
        public static void Run(IExample ex, int numero)
        {
            string path = @"c:\lammesoftHSM_Examples";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            CSharpGenerator x = ex.Generator();

            x.Nom  = "lammesoftHSM.examples.ExampleEx" + numero;
            x.Path = path;
            x.GenerateCode();
            GraphViz.ToGraphviz(dot, x.Nom, x.Path, x.level1, true, x.Startup, 10);
        }
示例#9
0
        public void RenderWithWarningAsException()
        {
            const string graph = @"digraph G { node [style=filled, shape=rec] 
# Nodes
""String age""

# Formatting
""String age"" [color=green]
}
";

            var graphViz = new GraphViz();

            graphViz.Config.TreatWarningsAsErrors = true;

            graphViz.LayoutAndRender(null, graph, null, null, "svg");
        }
示例#10
0
        public void RenderWithWarning()
        {
            const string graph = @"digraph G { node [style=filled, shape=rec] 
# Nodes
""String age""

# Formatting
""String age"" [color=green]
}
";

            const string expectedOutput = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>
<!DOCTYPE svg PUBLIC ""-//W3C//DTD SVG 1.1//EN""
 ""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"">
<!-- Generated by graphviz version 2.43.20200408.0903 (20200408.0903)
 -->
<!-- Title: G Pages: 1 -->
<svg width=""80pt"" height=""44pt""
 viewBox=""0.00 0.00 80.00 44.00"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"">
<g id=""graph0"" class=""graph"" transform=""scale(1 1) rotate(0) translate(4 40)"">
<title>G</title>
<polygon fill=""white"" stroke=""transparent"" points=""-4,4 -4,-40 76,-40 76,4 -4,4""/>
<!-- String age -->
<g id=""node1"" class=""node"">
<title>String age</title>
<polygon fill=""green"" stroke=""green"" points=""72,-36 0,-36 0,0 72,0 72,-36""/>
<text text-anchor=""middle"" x=""36"" y=""-14.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">String age</text>
</g>
</g>
</svg>
";

            var graphViz = new GraphViz();

            byte[] result = graphViz.LayoutAndRender(null, graph, null, null, "svg");
            string output = Encoding.ASCII.GetString(result);

            Assert.AreEqual(expectedOutput, output);
        }
示例#11
0
        public void RenderToOutputWithNonDefaultLayout()
        {
            const string graph          = @"digraph G { node [style=filled, shape=rect]

# Nodes
""String age"" -> ""Int64.Parse()"" -> {""Int64"", ""Collector""}


# Formatting
""String age"" [color=green]
""Int64"" [color=""#9fbff4""]
""Int64.Parse()"" [shape=invhouse]
""Collector"" [color = ""#c361f4""]

{ rank=same; ""Int64.Parse()"", ""Collector""}


}";
            const string expectedOutput = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>
<!DOCTYPE svg PUBLIC ""-//W3C//DTD SVG 1.1//EN""
 ""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"">
<!-- Generated by graphviz version 2.43.20200408.0903 (20200408.0903)
 -->
<!-- Title: G Pages: 1 -->
<svg width=""200pt"" height=""171pt""
 viewBox=""0.00 0.00 200.39 171.23"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"">
<g id=""graph0"" class=""graph"" transform=""scale(1 1) rotate(0) translate(4 167.23)"">
<title>G</title>
<polygon fill=""white"" stroke=""transparent"" points=""-4,4 -4,-167.23 196.39,-167.23 196.39,4 -4,4""/>
<!-- String age -->
<g id=""node1"" class=""node"">
<title>String age</title>
<polygon fill=""green"" stroke=""green"" points=""72,-66.12 0,-66.12 0,-30.12 72,-30.12 72,-66.12""/>
<text text-anchor=""middle"" x=""36"" y=""-44.42"" font-family=""Times New Roman,serif"" font-size=""14.00"">String age</text>
</g>
<!-- Int64.Parse() -->
<g id=""node2"" class=""node"">
<title>Int64.Parse()</title>
<polygon fill=""lightgrey"" stroke=""black"" points=""37.91,-65 109.41,-52.56 180.91,-65 180.85,-85.12 37.98,-85.12 37.91,-65""/>
<text text-anchor=""middle"" x=""109.41"" y=""-66.86"" font-family=""Times New Roman,serif"" font-size=""14.00"">Int64.Parse()</text>
</g>
<!-- String age&#45;&gt;Int64.Parse() -->
<g id=""edge1"" class=""edge"">
<title>String age&#45;&gt;Int64.Parse()</title>
<path fill=""none"" stroke=""black"" d=""M72.28,-59.21C72.35,-59.23 72.42,-59.25 72.49,-59.27""/>
<polygon fill=""black"" stroke=""black"" points=""62.12,-59.76 72.71,-59.34 64.17,-53.07 62.12,-59.76""/>
</g>
<!-- Int64 -->
<g id=""node3"" class=""node"">
<title>Int64</title>
<polygon fill=""#9fbff4"" stroke=""#9fbff4"" points=""192.39,-36 138.39,-36 138.39,0 192.39,0 192.39,-36""/>
<text text-anchor=""middle"" x=""165.39"" y=""-14.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">Int64</text>
</g>
<!-- Int64.Parse()&#45;&gt;Int64 -->
<g id=""edge2"" class=""edge"">
<title>Int64.Parse()&#45;&gt;Int64</title>
<path fill=""none"" stroke=""black"" d=""M125.6,-55.36C129.66,-51.55 134.12,-47.36 138.54,-43.21""/>
<polygon fill=""black"" stroke=""black"" points=""140.97,-45.73 145.86,-36.33 136.18,-40.63 140.97,-45.73""/>
</g>
<!-- Collector -->
<g id=""node4"" class=""node"">
<title>Collector</title>
<polygon fill=""#c361f4"" stroke=""#c361f4"" points=""161.24,-163.23 93.24,-163.23 93.24,-127.23 161.24,-127.23 161.24,-163.23""/>
<text text-anchor=""middle"" x=""127.24"" y=""-141.53"" font-family=""Times New Roman,serif"" font-size=""14.00"">Collector</text>
</g>
<!-- Int64.Parse()&#45;&gt;Collector -->
<g id=""edge3"" class=""edge"">
<title>Int64.Parse()&#45;&gt;Collector</title>
<path fill=""none"" stroke=""black"" d=""M112.94,-85.31C115.1,-94.4 117.96,-106.33 120.54,-117.16""/>
<polygon fill=""black"" stroke=""black"" points=""117.18,-118.16 122.91,-127.08 123.99,-116.54 117.18,-118.16""/>
</g>
</g>
</svg>
";

            var graphViz = new GraphViz();

            // ReSharper disable once StringLiteralTypo
            byte[] result = graphViz.LayoutAndRender(null, graph, null, "neato", "svg");
            string output = Encoding.ASCII.GetString(result);

            Assert.AreEqual(expectedOutput, output);
        }
示例#12
0
        public void RenderToOutput()
        {
            const string graph          = @"digraph G { node [style=filled, shape=rect]

# Nodes
""String age"" -> ""Int64.Parse()"" -> {""Int64"", ""Collector""}


# Formatting
""String age"" [color=green]
""Int64"" [color=""#9fbff4""]
""Int64.Parse()"" [shape=invhouse]
""Collector"" [color = ""#c361f4""]

{ rank=same; ""Int64.Parse()"", ""Collector""}


}";
            const string expectedOutput = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>
<!DOCTYPE svg PUBLIC ""-//W3C//DTD SVG 1.1//EN""
 ""http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"">
<!-- Generated by graphviz version 2.43.20200408.0903 (20200408.0903)
 -->
<!-- Title: G Pages: 1 -->
<svg width=""238pt"" height=""188pt""
 viewBox=""0.00 0.00 237.50 188.00"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"">
<g id=""graph0"" class=""graph"" transform=""scale(1 1) rotate(0) translate(4 184)"">
<title>G</title>
<polygon fill=""white"" stroke=""transparent"" points=""-4,4 -4,-184 233.5,-184 233.5,4 -4,4""/>
<!-- String age -->
<g id=""node1"" class=""node"">
<title>String age</title>
<polygon fill=""green"" stroke=""green"" points=""107.5,-180 35.5,-180 35.5,-144 107.5,-144 107.5,-180""/>
<text text-anchor=""middle"" x=""71.5"" y=""-158.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">String age</text>
</g>
<!-- Int64.Parse() -->
<g id=""node2"" class=""node"">
<title>Int64.Parse()</title>
<polygon fill=""lightgrey"" stroke=""black"" points=""-0,-84.44 71.5,-72 143,-84.44 142.93,-104.56 0.07,-104.56 -0,-84.44""/>
<text text-anchor=""middle"" x=""71.5"" y=""-86.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">Int64.Parse()</text>
</g>
<!-- String age&#45;&gt;Int64.Parse() -->
<g id=""edge1"" class=""edge"">
<title>String age&#45;&gt;Int64.Parse()</title>
<path fill=""none"" stroke=""black"" d=""M71.5,-143.7C71.5,-134.99 71.5,-124.3 71.5,-114.83""/>
<polygon fill=""black"" stroke=""black"" points=""75,-114.82 71.5,-104.82 68,-114.82 75,-114.82""/>
</g>
<!-- Int64 -->
<g id=""node3"" class=""node"">
<title>Int64</title>
<polygon fill=""#9fbff4"" stroke=""#9fbff4"" points=""98.5,-36 44.5,-36 44.5,0 98.5,0 98.5,-36""/>
<text text-anchor=""middle"" x=""71.5"" y=""-14.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">Int64</text>
</g>
<!-- Int64.Parse()&#45;&gt;Int64 -->
<g id=""edge2"" class=""edge"">
<title>Int64.Parse()&#45;&gt;Int64</title>
<path fill=""none"" stroke=""black"" d=""M71.5,-71.7C71.5,-63.98 71.5,-54.71 71.5,-46.11""/>
<polygon fill=""black"" stroke=""black"" points=""75,-46.1 71.5,-36.1 68,-46.1 75,-46.1""/>
</g>
<!-- Collector -->
<g id=""node4"" class=""node"">
<title>Collector</title>
<polygon fill=""#c361f4"" stroke=""#c361f4"" points=""229.5,-108 161.5,-108 161.5,-72 229.5,-72 229.5,-108""/>
<text text-anchor=""middle"" x=""195.5"" y=""-86.3"" font-family=""Times New Roman,serif"" font-size=""14.00"">Collector</text>
</g>
<!-- Int64.Parse()&#45;&gt;Collector -->
<g id=""edge3"" class=""edge"">
<title>Int64.Parse()&#45;&gt;Collector</title>
<path fill=""none"" stroke=""black"" d=""M143.19,-90C145.81,-90 148.43,-90 151.05,-90""/>
<polygon fill=""black"" stroke=""black"" points=""151.17,-93.5 161.17,-90 151.17,-86.5 151.17,-93.5""/>
</g>
</g>
</svg>
";

            var graphViz = new GraphViz();

            byte[] result = graphViz.LayoutAndRender(null, graph, null, null, "svg");
            string output = Encoding.ASCII.GetString(result);

            Assert.AreEqual(expectedOutput, output);
        }
示例#13
0
        public void AllNullParameters()
        {
            string arguments = GraphViz.BuildCommandLineArguments(null, null, null, null);

            Assert.AreEqual(string.Empty, arguments);
        }
示例#14
0
        public void DotToPngUsingLayout()
        {
            string arguments = GraphViz.BuildCommandLineArguments("file.dot", "file.png", "neato", "png");

            Assert.AreEqual(" -Kneato -Tpng -o\"file.png\" \"file.dot\"", arguments);
        }
示例#15
0
        public void DotToPng()
        {
            string arguments = GraphViz.BuildCommandLineArguments("file.dot", "file.png", null, "png");

            Assert.AreEqual(" -Tpng -o\"file.png\" \"file.dot\"", arguments);
        }
示例#16
0
        private void removeVariable(object sender, RoutedEventArgs e)
        {
            if (cmbSelectVariable.SelectedItem != null)
            {
                booleanFunctions.Remove(cmbSelectVariable.SelectedItem.ToString());
                cmbSelectVariable.Items.Remove(cmbSelectVariable.SelectedItem);
            }
            else
            {
                MessageBox.Show("Please select a Boolean variable first!");
                return;
            }

            wiringDiagram = Graph.Directed("adiagram");

            wiringDiagram.WithGraphAttributesOf(
                RankDir.TB,
                Font.Name("Arial"),
                Font.Size(55))
            .WithNodeAttributesOf(
                Shape.Ellipse,
                Color.Black);

            foreach (string key in booleanFunctions.Keys)
            {
                wiringDiagram.Containing(DotBuilder.Statements.Node.Name(key)); //make sure all variables are displayed

                string value;
                booleanFunctions.TryGetValue(key, out value);
                foreach (string k in booleanFunctions.Keys)
                {
                    if (value.Contains(k))
                    {
                        wiringDiagram.Containing(Edge.Between(k, key).WithAttributesOf(Color.Black));
                    }
                }
            }

            // to get the raw dot output
            var dot = wiringDiagram.Render();

            // to render to a file stream

            var graphviz = new GraphViz(@"C:\Program Files (x86)\Graphviz2.38\bin", OutputFormat.Png);


            GraphViewer.Source = null;

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            File.Delete(System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png"));
            var path = System.IO.Path.Combine(Environment.CurrentDirectory, "Graphs", "wiringdiagram.png");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                graphviz.RenderGraph(wiringDiagram, stream);

                var bitmap = new BitmapImage();

                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = stream;
                bitmap.EndInit();
                GraphViewer.Source = bitmap;

                stream.Close();
            }
        }
示例#17
0
        private void createGraph(List <Token> ListToken)
        {
            GraphViz graphViz = new GraphViz();

            graph = null;

            for (int i = 0; i < ListToken.Count; i++)
            {
                if (ListToken[i].TypeToken.Equals("Reservada Grafica"))
                {
                    string graphName = removeQuotes(ListToken[i + 5].Value);

                    // Continents
                    List <Continent> continents = new List <Continent>();
                    for (int j = i + 1; j < ListToken.Count; j++)
                    {
                        if (ListToken[j].TypeToken.Equals("Reservada Continente"))
                        {
                            string continentName       = removeQuotes(ListToken[j + 5].Value);
                            int    continentSaturation = 0;
                            int    continentPopulation = 0;

                            // Countries
                            List <Country> countries = new List <Country>();
                            for (int k = j + 1; k < ListToken.Count; k++)
                            {
                                if (ListToken[k].TypeToken.Equals("Reservada Pais"))
                                {
                                    string countryName       = "";
                                    int    countryPopulation = 0;
                                    int    countrySaturation = 0;
                                    string countryFlag       = "";

                                    for (int l = k + 1; l < ListToken.Count; l++)
                                    {
                                        if (ListToken[l].TypeToken.Equals("Reservada Poblacion"))
                                        {
                                            countryPopulation = int.Parse(ListToken[l + 2].Value);
                                        }
                                        else if (ListToken[l].TypeToken.Equals("Reservada Saturacion"))
                                        {
                                            countrySaturation = int.Parse(ListToken[l + 2].Value);
                                        }
                                        else if (ListToken[l].TypeToken.Equals("Reservada Bandera"))
                                        {
                                            countryFlag = removeQuotes(ListToken[l + 2].Value);
                                        }
                                        else if (ListToken[l].TypeToken.Equals("Reservada Nombre"))
                                        {
                                            countryName = removeQuotes(ListToken[l + 2].Value);
                                        }
                                        else if (ListToken[l].TypeToken.Equals("Reservada Pais") || ListToken[l].TypeToken.Equals("Reservada Continente"))
                                        {
                                            break;
                                        }
                                    }

                                    countries.Add(new Country(countryName, countryPopulation, countrySaturation, countryFlag));
                                }
                                else if (ListToken[k].TypeToken.Equals("Reservada Continente"))
                                {
                                    break;
                                }
                            }

                            foreach (Country item in countries)
                            {
                                continentSaturation += item.Saturation;
                                continentPopulation += item.Population;
                            }
                            continentSaturation = continentSaturation / countries.Count;
                            continents.Add(new Continent(continentName, continentPopulation, countries, continentSaturation));
                        }
                    }

                    graph = new Graph(graphName, continents);
                    graphViz.generateGraphViz(graph);
                }
            }
        }