Esempio n. 1
0
 public void EnterSubGraph(string name)
 {
     subGraph = new DotSubGraph <TVertexId> {
         Name = name
     };
     DotGraph.AddSubGraph(subGraph);
 }
Esempio n. 2
0
        private void CompileSubGraph(StringBuilder builder, DotSubGraph subGraph)
        {
            builder.Append($"subgraph {subGraph.Identifier} {{ ");

            CompileSubGraphAttributes(builder, subGraph.Attributes);

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

            builder.Append("} ");
        }
Esempio n. 3
0
 public abstract void BuildSubGraph(
     double leftX,
     double upperY,
     double rightX,
     double lowerY,
     ISubGraph originalSubGraph,
     DotSubGraph <int> subGraph);
Esempio n. 4
0
        public static DotSubGraph TypeCluster <T>(
            TypedNode <T> typedNode,
            params IDotElement[] elements)
        {
            var typeCluster = new DotSubGraph(typedNode.Id);

            typeCluster.Elements.AddRange(elements);
            return(typeCluster);
        }
Esempio n. 5
0
        public void IndentedSubGraphWithEdge()
        {
            var graph = new DotGraph("TestGraph");

            var subGraph = new DotSubGraph("TestSubGraph");

            subGraph.Elements.Add(new DotEdge("A", "B"));

            graph.Elements.Add(subGraph);

            var compiled = graph.Compile(true);

            _output.WriteLine(compiled);

            Check.That(compiled).HasSameValueAs("graph TestGraph { \n\tsubgraph TestSubGraph { \n\t\tA -- B; \n\t} \n}");
        }
Esempio n. 6
0
        private void AddStepsCluster(AstMacro macro)
        {
            StepsCluster =
                Graph
                .AddSubGraph("Processing");
            //.SetLabel("Optimized Processing Steps".Bold());

            var commands =
                macro
                .OptimizedCommandBlock
                .Commands
                .Where(command => command.IsValidCommandLet);

            foreach (var command in commands)
            {
                command.AcceptVisitor(this);
            }
        }
Esempio n. 7
0
        public AstVisitorDotGraph ToGraphViz()
        {
            Graph
            .SetRankDir(DotRankDirection.LeftToRight);

            ExprSubGraph =
                Graph
                .AddSubGraph();

            AddConstantInputs();

            AddConstantOutputs();

            AddExpressions();

            LinkInputs();

            return(Graph);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public override void BuildSubGraph(
            double leftX,
            double upperY,
            double rightX,
            double lowerY,
            ISubGraph originalSubGraph,
            DotSubGraph <int> subGraph)
        {
            var element = this.elementsFactory.CreateSubGraphBorder(new BorderViewModel(subGraph.Label, originalSubGraph));

            canvas.Children.Add(element);
            element.Width  = rightX - leftX;
            element.Height = upperY - lowerY;
            var orig = new Primitives.Point(leftX, upperY);
            var p    = TransformCoordinates(orig, canvas);

            Canvas.SetLeft(element, p.X);
            Canvas.SetTop(element, p.Y);

            Panel.SetZIndex(element, -1);
            this.verticesElements.Add(originalSubGraph, element);
        }
Esempio n. 10
0
        public override void BuildSubGraph(
            double leftX,
            double upperY,
            double rightX,
            double lowerY,
            ISubGraph originalSubGraph,
            DotSubGraph <int> subGraph)
        {
            var element = this.elementsFactory.CreateSubGraphBorder(new BorderViewModel(subGraph.Label, originalSubGraph));

            canvas.Children.Add(element);
            element.Width  = rightX - leftX;
            element.Height = upperY - lowerY;
            Point orig = new Point(leftX, upperY);
            Point p    = TransformCoordinates(orig, canvas);

            Canvas.SetLeft(element, p.X);
            Canvas.SetTop(element, p.Y);

#if !SILVERLIGHT
            Panel.SetZIndex(element, -1);   // TODO: implement this functionality for silverlight
#endif
            this.verticesElements.Add(originalSubGraph, element);
        }
Esempio n. 11
0
        private void AddRankingSubGraphs(AstRoot ast)
        {
            _namespacesSubGraphs.Clear();

            var maxNamespaceDepth =
                1 + ast.Namespaces.Select(n => n.ParentSymbolsCount).Max();

            Graph
            .AddSubGraph()
            .AddEdge(
                Enumerable
                .Range(1, maxNamespaceDepth)
                .Select(n => "Namespaces " + n)
                )
            .AddSides(
                "Frames",
                "Basis Vectors",
                "Structures",
                "Subspaces",
                "Constants",
                "Macros"
                )
            .SetPenWdith(0)
            .SetArrowSize(0);

            for (var i = 1; i <= maxNamespaceDepth; i++)
            {
                var subGraph =
                    Graph
                    .AddSubGraph("GMacAST Namespaces " + i)
                    .SetRank(DotRankType.Same);

                subGraph
                .AddNode("Namespaces " + i)
                .SetLabel(
                    Graph.Table("Namespace", "Namespaces " + i)
                    );

                _namespacesSubGraphs.Add(subGraph);
            }

            _framesSubGraph =
                Graph
                .AddSubGraph("GMacAST Frames")
                .SetRank(DotRankType.Same);

            _basisVectorsSubGraph =
                Graph
                .AddSubGraph("GMacAST Basis Vectors")
                .SetRank(DotRankType.Same);

            _subspacesSubGraph =
                Graph
                .AddSubGraph("GMacAST Subspaces")
                .SetRank(DotRankType.Same);

            _constsSubGraph =
                Graph
                .AddSubGraph("GMacAST Constants")
                .SetRank(DotRankType.Same);

            _structsSubGraph =
                Graph
                .AddSubGraph("GMacAST Structures")
                .SetRank(DotRankType.Same);

            _macrosSubGraph =
                Graph
                .AddSubGraph("GMacAST Macros")
                .SetRank(DotRankType.Same);

            _framesSubGraph.AddNode("Frames").SetLabel(Graph.Table("Frame", "Frames"));
            _basisVectorsSubGraph.AddNode("Basis Vectors").SetLabel(Graph.Table("BasisVector", "Basis Vectors"));
            _subspacesSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Subspace", "Subspaces"));
            _constsSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Constant", "Constants"));
            _structsSubGraph.AddNode("Subspaces").SetLabel(Graph.Table("Structure", "Structures"));
            _macrosSubGraph.AddNode("Macros").SetLabel(Graph.Table("Macro", "Macros"));
        }
Esempio n. 12
0
 public void LeaveSubGraph()
 {
     subGraph = null;
 }
Esempio n. 13
0
 public void LeaveSubGraph()
 {
     this.subGraph = null;
 }
        public void CreateGraphTest()
        {
            var graph = new DotGraph("MyGraph");

            var directedGraph = new DotGraph("MyDirectedGraph", true);

            //******************************************

            var myNode1 = new DotNode("Node 1")
            {
                Shape     = DotNodeShape.Ellipse,
                Label     = "Node 1",
                FillColor = Color.Coral,
                FontColor = Color.Black,
                Style     = DotNodeStyle.Solid,
                Width     = 0.5f,
                Height    = 0.5f,
                PenWidth  = 0.5f
            };

            // Add the node to the graph
            graph.Elements.Add(myNode1);

            var myNode2 = new DotNode("Node 2")
            {
                Shape     = DotNodeShape.Oval,
                Label     = "Node 2",
                FillColor = Color.Coral,
                FontColor = Color.Black,
                Style     = DotNodeStyle.Solid,
                Width     = 0.5f,
                Height    = 0.5f,
                PenWidth  = 0.5f
            };

            // Add the node to the graph
            graph.Elements.Add(myNode2);

            //******************************************

            // Create an edge with identifiers
            //var myEdge = new DotEdge("myNode1", "myNode2");

            // Create an edge with nodes and attributes
            var myEdge = new DotEdge(myNode1, myNode2)
            {
                ArrowHead = DotEdgeArrowType.Vee,
                ArrowTail = DotEdgeArrowType.Dot,
                //Color = Color.Red,
                FontColor = Color.Black,
                //Label = "1->2",
                Style    = DotEdgeStyle.Solid,
                PenWidth = 0.5f,
            };

            // Add the edge to the graph
            graph.Elements.Add(myEdge);


            //******************************************

            // Subgraph identifier need to start with "cluster" to be identified as a cluster
            //var mySubGraph = new DotSubGraph("cluster_0");

            // Create a subgraph with attributes (only used for cluster)
            var subGraph = new DotSubGraph("cluster_0")
            {
                //Color = Color.Red,
                //Style = DotSubGraphStyle.Dashed,
                Label = "My subgraph!"
            };

            // Add node, edge, subgraph
            //subGraph.Elements.Add(myNode);
            subGraph.Elements.Add(myEdge);
            //subGraph.Elements.Add(mySubGraph2);

            // Add subgraph to main graph
            graph.Elements.Add(subGraph);

            //******************************************

            // Non indented version
            //var dot = graph.Compile();
            // Indented version
            var dot = graph.Compile(true);

            // Save it to a file
            File.WriteAllText("myFile.dot", dot);
        }