static void ProcessLine(Graph graph, string str, StreamReader f) {
            if (str.Contains("node"))
                ReadNode(graph, f);
            else if(str.Contains("edge"))
                ReadEdge(graph, f);

        }
Example #2
1
        private void SetGraph()
        {
            var graph = new Graph();
            graph.AddEdge("a", "b");
            graph.AddEdge("e", "b");
            graph.AddEdge("d", "b");
            graph.AddEdge("b", "c");

            graph.AddEdge("a22", "b22");
            graph.AddEdge("e22", "b22");
            graph.AddEdge("d22", "b22");
            graph.AddEdge("b22", "c22");

            graph.AddEdge("a0", "b0");
            graph.AddEdge("b0", "c0");

            graph.AddEdge("a33", "b33");
            graph.AddEdge("e33", "b33");
            graph.AddEdge("d33", "b33");
            graph.AddEdge("b33", "c33");

            graph.AddEdge("a11", "b11");
            graph.AddEdge("b11", "c11").LabelText = "Test labels!";

            graph.CreateGeometryGraph();
            foreach (Node node in graph.Nodes)
                node.GeometryNode.BoundaryCurve = CreateLabelAndBoundary(node);

            foreach (var edge in graph.Edges) {
                if (edge.Label != null) {
                    var geomEdge = edge.GeometryEdge;
                    double width;
                    double height;
                    StringMeasure.MeasureWithFont(edge.LabelText,
                                                  new Font(edge.Label.FontName, (float)edge.Label.FontSize), out width, out height);
                    edge.Label.GeometryLabel=geomEdge.Label = new Label(width, height, geomEdge);
                }

            }

            var geomGraph=graph.GeometryGraph;

            var geomGraphComponents = GraphConnectedComponents.CreateComponents(geomGraph.Nodes, geomGraph.Edges);
            var settings = new SugiyamaLayoutSettings();
            foreach (var subgraph in geomGraphComponents) {

                var layout=new LayeredLayout(subgraph, settings);
                subgraph.Margins = settings.NodeSeparation/2;
                layout.Run();

            }

               Microsoft.Msagl.Layout.MDS.MdsGraphLayout.PackGraphs(geomGraphComponents, settings);

            geomGraph.UpdateBoundingBox();

            gViewer1.NeedToCalculateLayout = false;
            gViewer1.Graph = graph;
        }
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            GraphViewer graphViewer = new GraphViewer();
            graphViewer.BindToPanel(Panel);
            Graph graph = new Graph();

            graph.AddEdge("A", "B");
            graph.Attr.LayerDirection = LayerDirection.LR;
            graphViewer.Graph = graph; // throws exception
        }
Example #4
0
        public static void SomeClass()
        {
            var graph = new MSAGL.Drawing.Graph("");
            graph.AddEdge("A", "B");
            graph.AddEdge("A", "B");
            graph.FindNode("A").Attr.FillColor = MSAGL.Drawing.Color.BlanchedAlmond;
            graph.FindNode("B").Attr.FillColor = MSAGL.Drawing.Color.BurlyWood;
            var renderer = new MSAGL.GraphViewerGdi.GraphRenderer(graph);
            renderer.CalculateLayout();
            const int width = 50;
            int height = (int)(graph.Height * (width / graph.Width));
            const PixelFormat pixfmt = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
            using (var bitmap = new System.Drawing.Bitmap(width, height, pixfmt))
            {
                using (var gfx = System.Drawing.Graphics.FromImage(bitmap))
                {
                    gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    var rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    renderer.Render(gfx, rect);
                    bitmap.Save("test.png");

                }

            }
           
        }
 public virtual void UpdateGraph(Graph graph)
 {
     Node graphNode = graph.AddNode(NodeFile.Id);
     graphNode.LabelText = NodeFile.Name;
     UpdateGraphNode(graphNode);
     UpdateOutEdges(graph);
 }
Example #6
0
        void DrawGraph(Automaton automaton)
        {
            var graph = new Graph();
            graph.Attr.LayerDirection = LayerDirection.LR;
            int i = 0;
            foreach (var s in automaton.States)
            {
                foreach (var o in s.Output)
                {
                    var index = automaton.States.IndexOf(o.End);
                    var end = ReferenceEquals(automaton.StartState, o.End) ? "Start" : index.ToString();
                    if (ReferenceEquals(s, automaton.StartState))
                    {
                        graph.AddEdge("Start", o.ToString(), end);
                    }
                    else if (o.End.IsFinalState)
                    {
                        graph.AddEdge(i.ToString(), o.ToString(), "End");
                    }
                    else
                    {
                        graph.AddEdge(i.ToString(), o.ToString(), end);
                    }

                }
                i++;
            }
            graphViewer.Graph = graph;
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="streamPar"></param>
 /// <param name="graphP"></param>
 public SvgGraphWriter(Stream streamPar, Graph graphP) {
     InitColorSet();
     stream = streamPar;
     graph = graphP;
     var xmlWriterSettings = new XmlWriterSettings { Indent = true };
     xmlWriter = XmlWriter.Create(stream, xmlWriterSettings);
 }
 public static Graph CreateDrawingGraph(GeometryGraph gg)
 {
     counter = 0;
     localMap = new Dictionary<GeometryNode,Node>();
     dg = new Graph(counter++.ToString()) { GeometryGraph = gg };
     foreach (GeometryNode n in gg.Nodes)
     {
         Node node = new Node(counter++.ToString());
         node.Attr.Shape = Shape.Ellipse;
         node.GeometryNode = n;
         dg.AddNode(node);
         localMap[n]=node;
     }
     Subgraph cluster = new Subgraph(counter++.ToString());
     cluster.GeometryNode = gg.RootCluster;
     dg.RootSubgraph = cluster;
     PopulateClusters(cluster, gg.RootCluster);
 
     foreach (GeometryEdge e in gg.Edges)
     {
         Edge edge = new Edge(localMap[e.Source], localMap[e.Target], ConnectionToGraph.Disconnected);
         edge.Attr.ArrowheadAtSource = e.ArrowheadAtSource ? ArrowStyle.Normal : ArrowStyle.None;
         edge.Attr.ArrowheadAtTarget = e.ArrowheadAtTarget ? ArrowStyle.Normal : ArrowStyle.None;
         edge.GeometryEdge = e;
         dg.AddPrecalculatedEdge(edge);
     }
     //PopulateClusterEdges(dg.RootSubgraph, gg.RootCluster);
     
     return dg;
 }
 ///<summary>
 ///</summary>
 ///<param name="streamPar"></param>
 ///<param name="graphP"></param>
 public GraphWriter(Stream streamPar, Graph graphP) {
     stream = streamPar;
     graph = graphP;
     var xmlWriterSettings = new XmlWriterSettings();
     xmlWriterSettings.Indent = true;
     xmlWriter = XmlWriter.Create(stream, xmlWriterSettings);
 }
Example #10
0
        static Graph CtreateDrawingGraph(out FastIncrementalLayoutSettings settings)
        {
            settings = new FastIncrementalLayoutSettings { RouteEdges = true, NodeSeparation = 30};
            var drawingGraph = new Graph();
            const string id0 = "0";
            const string id1 = "1";
            AddEdge(drawingGraph, id0, id1);
            AddEdge(drawingGraph, "0", "2");
            AddEdge(drawingGraph, "1", "3");
            AddEdge(drawingGraph, "2", "4");
            AddEdge(drawingGraph, "2", "5");
            AddEdge(drawingGraph, "2", "6");
            AddEdge(drawingGraph, "5", "7");
            AddEdge(drawingGraph, "5", "6");
            AddEdge(drawingGraph, "7", "8");
            AddEdge(drawingGraph, "8", "6");

            drawingGraph.CreateGeometryGraph();
            foreach (Microsoft.Msagl.Drawing.Node node in drawingGraph.Nodes) {
                double w, h;
                var label = node.Label;
                var font = new Font(label.FontName, (float)label.FontSize);
                StringMeasure.MeasureWithFont(label.Text, font, out w, out h);
                node.Label.Width = w;
                node.Label.Height = h;
                node.Attr.Shape = Shape.DrawFromGeometry;
                node.GeometryNode.BoundaryCurve=CurveFactory.CreateRectangleWithRoundedCorners(1.2*w,1.2*h,3,3,new Point());
            }

            return drawingGraph;
        }
Example #11
0
        private void ModulesGraph()
        {
            Graph g = new Graph();

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select name from modules";

                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                    g.AddNode(DataReader["name"].ToString());
            }

            using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
            {
                command.CommandText = @"select * from moddeps";
                SQLiteDataReader DataReader = command.ExecuteReader();
                while (DataReader.Read())
                {
                    Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
                    e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
                    //e.Attr.Color = Microsoft.Msagl.Drawing.Color.Yellow;
                    e.LabelText = DataReader["rate"].ToString();
                }
            }
            gViewer.Graph = g;
        }
 static Node WalkImports(Hashtable nodes, Hashtable edges, XmlSchema s, string uri, Graph g) {
     if (nodes.ContainsKey(uri)) {
         return (Node) nodes[uri]; // already visited
     }
     Node b1 = AddSchemaBox(nodes, uri, g);
     if (s != null) {
         foreach (var o in s.Includes) {
             XmlSchema si = null;
             var include = o as XmlSchemaInclude;
             var baseUri = new Uri(o.SourceUri);
             Uri suri = null;
             var color = new Color(0, 0, 128); //Colors.Navy;
             if (include != null) {
                 si = include.Schema;
                 suri = new Uri(baseUri, include.SchemaLocation);
                 color = new Color(0, 128, 0); //Colors.Green;
             } else {
                 var import = o as XmlSchemaImport;
                 if (import != null) {
                     si = import.Schema;
                     suri = new Uri(baseUri, import.SchemaLocation);
                 }
             }
             Node b2 = WalkImports(nodes, edges, si, suri.AbsoluteUri, g);
             if (b2 != b1) {
                 AddEdge(edges, g, b1, b2, color);
             }
         }
     }
     return b1;
 }
Example #13
0
        /// <summary>
        /// Copies a graph and its GeometryGraph.
        /// </summary>
        /// <param name="parentGraph"></param>
        /// <returns></returns>
        public static Graph CopyGraph(Graph parentGraph)
        {
            GeometryGraph geometryCopy = CopyGraph(parentGraph.GeometryGraph);

            Graph graph=new Graph();
            graph.GeometryGraph = geometryCopy;

            Dictionary<Node,int> nodeId=new Dictionary<Node, int>(geometryCopy.Nodes.Count);
            for (int i = 0; i < geometryCopy.Nodes.Count; i++) {
                nodeId[geometryCopy.Nodes[i]] = i;
                String id = i.ToString();

               graph.AddNode(id);
                var node = graph.FindNode(id);
                node.GeometryNode = geometryCopy.Nodes[i];
                geometryCopy.Nodes[i].UserData = node;

            }

            foreach (var edge in geometryCopy.Edges) {
                String sourceId = nodeId[edge.Source].ToString();
                String targetId = nodeId[edge.Target].ToString();

                var edgeCopy=graph.AddEdge(sourceId, "", targetId);
                edgeCopy.GeometryEdge = edge;
                edge.UserData = edgeCopy;
            }
            return graph;
        }
        private Graph RenderGraph(LangFile langFile)
        {
            var graph = new Graph("OpenFoodFacts Category Taxonomy");

            var languageComparer = new LanguageByImportanceComparer(langFile.TranslationSets);
            var parentsComparer = new ParentsComparer(new AlphabeticalTranslationSetComparer(languageComparer, EvaluateMostImportantTranslation, GetLabel));

            foreach (var translationSet in langFile.TranslationSets.OrderBy(ts => ts.Parents, parentsComparer))
            {
                if (!translationSet.Translations.Any())
                {
                    continue;
                }

                var translation = EvaluateMostImportantTranslation(translationSet, languageComparer);
                var translationLabel = GetLabel(translation);

                if (translationSet.Parents.Any())
                {
                    foreach (var parent in translationSet.Parents)
                    {
                        var parentTranslation = EvaluateMostImportantTranslation(parent, languageComparer);
                        var parentTranslationLabel = GetLabel(parentTranslation);
                        graph.AddEdge(parentTranslationLabel, translationLabel);
                    }
                }
                else
                {
                    graph.AddNode(translationLabel);
                }
            }

            return graph;
        }
Example #15
0
 public static Graph Generate(IUiPreferencesService uiPreferences, Procedure proc, Graphics g, Font defaultFont)
 {
     Graph graph = new Graph();
     var cfgGen = new CfgGraphGenerator(graph, uiPreferences, g, defaultFont);
     cfgGen.Traverse(proc.EntryBlock.Succ[0]);
     graph.Attr.LayerDirection = LayerDirection.TB;
     return graph;
 }
Example #16
0
 public CfgGraphGenerator(Graph graph, IUiPreferencesService uiPreferences, Graphics g, Font defaultFont)
 {
     this.uiPreferences = uiPreferences;
     this.graph = graph;
     this.g = g;
     this.defaultFont = defaultFont;
     this.visited = new HashSet<Block>();
 }
        ///<summary>
        ///</summary>
        ///<param name="graph"></param>
        ///<param name="geomGraph"></param>
        static public void BindGeomGraphToDrawingGraph(Graph graph, GeometryGraph geomGraph) {
            graph.GeometryGraph = geomGraph;
            var nodeIds = new Dictionary<GeomNode, string>();
            BindNodes(graph, geomGraph, nodeIds);

            BindClusters(graph, geomGraph, nodeIds);

            BindEdges(graph, geomGraph, nodeIds);
        }
 ///<summary>
 ///</summary>
 ///<param name="geomGraph"></param>
 static public void ShowGraph(GeometryGraph geomGraph) {
     var graph = new Graph();
     geomGraph.UpdateBoundingBox();
     var bb = geomGraph.BoundingBox;
     bb.Pad(geomGraph.Margins);
     geomGraph.BoundingBox = bb;
     BindGeomGraphToDrawingGraph(graph, geomGraph);
     DisplayGraph(graph, new Form());
 }
 public AutomatonViewModel()
 {
     graph = new Graph();
     graph.Attr.LayerDirection = LayerDirection.LR;
     dummy = new Node(" ");
     dummy.IsVisible = false;
     graph.AddNode(dummy);
     ResetAll();
 }
        private void Draw(Graph<Symbol, double> g)
        {
            treeViewSyn.Nodes.Clear();
            if (g != null && g.Root != null)
            {
                Graph graph = new Graph("Graph");
                //graph.Attr.LayerDirection = LayerDirection.TB;
                Node<Symbol, double> node = g.Root;
                TreeNode treeNode;
                Stack<Node<Symbol, double>> stack = new Stack<Node<Symbol, double>>();
                Stack<TreeNode> stackTreeNode = new Stack<TreeNode>();
                stackTreeNode.Push(null);

                stack.Push(node);
                while (stack.Count > 0)
                {
                    node = stack.Pop();
                    treeNode = stackTreeNode.Pop();
                    var treeNodeNext = AddNode(node, treeNode);

                    string str = "Root";
                    if (node.Info != null)
                        str = node.Info.Name;
                    var no = graph.AddNode(node.Name);
                    no.Attr.Shape = Shape.Circle;
                    no.LabelText = str;

                    foreach (var transition in System.Linq.Enumerable.Reverse(node.Edges))
                    {
                        Edge arco = graph.AddEdge(node.Name, "", transition.Destiny.Name);

                        System.Drawing.Color c = Utils.GetColor(transition.Cost);
                        var color = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B);
                        arco.Attr.Color = color;
                        arco.Attr.AddStyle(Style.Bold);
                        arco.Attr.LineWidth = 5;
                        arco.LabelText = transition.Cost.ToString("n2");

                        stack.Push(transition.Destiny);
                        stackTreeNode.Push(treeNodeNext);
                    }
                }

                GViewer viewer = new GViewer();
                // viewer.CurrentLayoutMethod = LayoutMethod.Ranking;

                viewer.NavigationVisible = false;
                viewer.OutsideAreaBrush = Brushes.White;
                viewer.ToolBarIsVisible = false;
                viewer.Graph = graph;
                viewer.Dock = System.Windows.Forms.DockStyle.Fill;

                pnlGraph.Controls.Clear();
                pnlGraph.Controls.Add(viewer);
                treeViewSyn.ExpandAll();
            }
        }
        Graph GetImportGraph() {
            var g = new Graph("Imports", "id");
            var nodes = new Hashtable();
            var edges = new Hashtable();
            foreach (XmlSchema s in set.Schemas()) {
                WalkImports(nodes, edges, s, s.SourceUri ?? s.TargetNamespace, g);
            }
            g.Attr.LayerDirection = direction;

            return g;
        }
Example #22
0
 public static Graph Generate(Program program)
 {
     Graph graph = new Graph();
     var cfgGen = new CallGraphGenerator(graph);
     foreach (var rootProc in program.Procedures.Values)
     {
         cfgGen.Traverse(program.CallGraph, rootProc);
     }
     graph.Attr.LayerDirection = LayerDirection.TB;
     return graph;
 }
Example #23
0
        /**
         * Print the DA in DOT format to the output stream.
         * This functions expects that the DA is compact.
         * @param da_type a string specifying the type of automaton ("DRA", "DSA").
         * @param out the output stream
         */
        public Graph AutomatonToDot()
        {
            Graph g = new Graph("graph");
            g.Directed = true;

            APSet ap_set = getAPSet();
            Dictionary<int, string> stateToNumber = new Dictionary<int, string>();

            for (int i_state = 0; i_state < this.size(); i_state++)
            {
                //out << "\"" << i_state << "\" [";

                Node d = formatStateForDOT(i_state, g);
                stateToNumber.Add(i_state, d.Id);
            }

            //out << "]\n"; // close parameters for state

            for (int i_state = 0; i_state < this.size(); i_state++)
            {
                // transitions

                DA_State cur_state = this.get(i_state);
                if (cur_state.hasOnlySelfLoop())
                {
                    // get first to-state, as all the to-states are the same
                    DA_State to = cur_state.edges().get(new APElement(ap_set.all_elements_begin()));

                    //out << "\"" << i_state << "\" -> \"" << to->getName();
                    //out << "\" [label=\" true\", color=blue]\n";

                    Edge edge = g.AddEdge(stateToNumber[i_state], "\u03A3", stateToNumber[to.getName()]);
                    //edge.Attr.Color = Color.Blue;

                }
                else
                {
                    //for (APSet::element_iterator el_it=ap_set.all_elements_begin();el_it!=ap_set.all_elements_end();++el_it)
                    for (int el_it = ap_set.all_elements_begin(); el_it != ap_set.all_elements_end(); ++el_it)
                    {
                        APElement label = new APElement(el_it);
                        DA_State to_state = cur_state.edges().get(label);
                        int to_state_index = to_state.getName();
                        //out << "\"" << i_state << "\" -> \"" << to_state_index;
                        //out << "\" [label=\" " << label.toString(getAPSet(), false) << "\"]\n";

                        Edge edge = g.AddEdge(stateToNumber[i_state], label.toString(getAPSet(), false), stateToNumber[to_state_index]);
                        //edge.Attr.Color = Color.Blue;
                    }
                }
            }

            return g;
        }
Example #24
0
 void RerouteEdges(Graph graph, BundlingSettings bundleSettings) {
     bundleSettings.MonotonicityCoefficient = MonotoneBarValue;
     var iViewer = (IViewer)GViewer;
     foreach (var iEdge in iViewer.Entities.Where(edge => edge is IViewerEdge)) {
         iViewer.InvalidateBeforeTheChange(iEdge);
     } 
     RouteBundledEdges(graph.GeometryGraph, false, graph.LayoutAlgorithmSettings.EdgeRoutingSettings);
     foreach (var iEdge in iViewer.Entities.Where(edge=>edge is IViewerEdge) ){
         iViewer.Invalidate(iEdge);
     }
 }
Example #25
0
 public static Microsoft.Msagl.Drawing.Graph ToMsaglGraph(this Graph g) {
     var msaglGraph = new Microsoft.Msagl.Drawing.Graph();
     for (var v = 0; v < g.V; v++) {
         foreach (var w in g.AdjacentVertices(v)) {
             var e = msaglGraph.AddEdge(v.ToString(), w.ToString());
             e.SourceNode.Attr.Shape = Shape.Circle;
             e.TargetNode.Attr.Shape = Shape.Circle;
         }
     }
     return msaglGraph;
 }
        static void ReadEdge(Graph graph, StreamReader f) {
            f.ReadLine();
            var s = f.ReadLine();
            s = s.Trim(' ', '\t', '"');
            var source = s.Split(' ')[1];
            s = f.ReadLine();

            s = s.Trim(' ', '\t', '"');
            var target = s.Split(' ')[1];
            graph.AddEdge(source, target);
            f.ReadLine();
        }
 static void ReadNode(Graph graph, StreamReader f) {
     f.ReadLine();
     var s=f.ReadLine();
     s = s.Trim(' ', '\t', '"');
     var id = s.Split(' ')[1];
     s = f.ReadLine();
     s = s.Trim(' ', '\t', '"');
     var split = s.Split(' ');
     var label = split[1].Trim('"');
     graph.AddNode(id).LabelText = label;
     f.ReadLine();            
 }
Example #28
0
 public GraphPanel(State start)
 {
     viewer = new GViewer();
     Graph = new Graph("graph");
     Graph.AddNodes(start);
     viewer.ToolBarIsVisible = false;
     viewer.Graph = Graph;
     viewer.Dock = DockStyle.Fill;
     var magnificationCoeff = 560.0 / viewer.Height;
     Height = 560;
     Width = (int)(viewer.Width * magnificationCoeff);
     Controls.Add(viewer);
 }
        static void ProcessLine(Graph graph, string str) {
            if (String.IsNullOrEmpty(str))
                return;
            if (str[0] == '*') return;

            var arrayStr = str.Split(new []{' '},StringSplitOptions.RemoveEmptyEntries).ToArray();
            if (arrayStr.Length == 0)
                return;
            var source = graph.AddNode(arrayStr[0]);
            for (int i = 1; i < arrayStr.Length; i++) {
                var e = new Edge(source, graph.AddNode(arrayStr[i]), ConnectionToGraph.Connected);
                graph.AddPrecalculatedEdge(e);
            }
        }
Example #30
0
        public static Graph GenerateGraph(DrawItem drawItem, ref Palette palette, ref string message, string savePath = null)
        {
            try
            {
                var graph = new Graph(GetTitle(drawItem));

                switch (drawItem.ViewLevel)
                {
                    case ViewLevel.Activity:
                        DrawActivity(ref graph, drawItem, ref palette);
                        break;
                    case ViewLevel.SubProcess:
                        DrawTask(ref graph, drawItem, ref palette);
                        break;
                }


                //Saves the graph to file if a file name is specified
                if (!string.IsNullOrEmpty(savePath))
                {
                    try
                    {
                        var renderer = new Microsoft.Msagl.GraphViewerGdi.GraphRenderer(graph);

                        renderer.CalculateLayout();
                        
                        var img = new System.Drawing.Bitmap((int) graph.Width, (int) graph.Height, PixelFormat.Format32bppPArgb);
                        renderer.Render(img);

                        var encoderParameters = new EncoderParameters(1);
                        encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                        img.Save(savePath, ImageCodecInfo.GetImageDecoders().Where(e => e.FormatID == ImageFormat.Png.Guid).First(), encoderParameters);
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        return null;
                    }
                }

                return graph;

            } catch (Exception ex)
            {
                message = ex.Message;
                return null;
            }
         
        }