static void ProcessLine(Graph graph, string str, StreamReader f) { if (str.Contains("node")) ReadNode(graph, f); else if(str.Contains("edge")) ReadEdge(graph, f); }
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 }
public void drawEdgewithColor(Microsoft.Msagl.Drawing.Graph graph, List <string> list) { List <Tuple <string, string> > visited = new List <Tuple <string, string> >(); Node node; Edge edge; for (int i = 0; i < list.Count - 1; i++) { edge = this.graphVisualizer.EdgeById(list[i] + list[i + 1]); if (edge == null) { edge = this.graphVisualizer.EdgeById(list[i + 1] + list[i]); } edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Orange; node = this.graphVisualizer.FindNode(list[i]); if (node != null) { node.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow; } visited.Add(Tuple.Create(list[i], list[i + 1])); } node = this.graphVisualizer.FindNode(list[list.Count - 1]); if (node != null) { node.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow; } drawContainer(this.graphVisualizer); }
// Visualizer public void resetNodeColor(Microsoft.Msagl.Drawing.Graph graph) // mengubah color suatu node { foreach (var node in graph.Nodes) { node.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; } }
internal static DGraph CreateDGraphAndGeometryInfo(DrawingGraph drawingGraph, GeometryGraph gleeGraph) { DGraph ret = new DGraph(drawingGraph); //create dnodes and glee node boundary curves foreach (GeometryNode geomNode in gleeGraph.NodeMap.Values) { DrawingNode drawingNode = geomNode.UserData as DrawingNode; CreateDNodeAndSetNodeBoundaryCurve(drawingGraph, ret, geomNode, drawingNode); } foreach (GeometryEdge gleeEdge in gleeGraph.Edges) { DEdge dEdge = new DEdge(ret.GetNode(gleeEdge.Source), ret.GetNode(gleeEdge.Target), gleeEdge.UserData as DrawingEdge, Connection.Connected); ret.AddEdge(dEdge); DrawingEdge drawingEdge = dEdge.Edge; Microsoft.Msagl.Drawing.Label label = drawingEdge.Label; if (label != null) { double width, height; CreateDLabel(dEdge, label, out width, out height); } } return(ret); }
public Microsoft.Msagl.GraphViewerGdi.GViewer BuildGraph(List <PrimaryGraph.Verticle> new_graph, string verticle) { //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content for (int i = 0; i < new_graph.Count; i++) { for (int j = 0; j < new_graph[i].connections.Count; j++) { string verticle_out = new_graph[i].verticle_id; string verticle_in = new_graph[i].connections[j].connectedTo; if (verticle_out == verticle || verticle_in == verticle) { graph.AddEdge(verticle_out, new_graph[i].connections[j].strength.ToString(), verticle_in); } } } //graph.FindNode(verticle).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; viewer.Graph = graph; viewer.Height = 300; viewer.Width = 930; return(viewer); }
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; }
public static void SetColorOfMultiReletionNodes(Microsoft.Msagl.Drawing.Graph graph) { foreach (Edge item in graph.Edges) { List <Edge> list = new List <Edge>(item.SourceNode.Edges); if (maxReletions == list.Count && maxReletions != 2) { IGraphItem graphItem = item.SourceNode.UserData as IGraphItem; if (graphItem.IsSelected) { SetDrawDelegateByNode(item.SourceNode, NodeTypes.MultiRelaitionsSelected); } else { SetDrawDelegateByNode(item.SourceNode, NodeTypes.MultiRelaitions); } } list = new List <Edge>(item.TargetNode.Edges); if (maxReletions == list.Count && maxReletions != 2) { IGraphItem graphItem = item.TargetNode.UserData as IGraphItem; if (graphItem.IsSelected) { SetDrawDelegateByNode(item.TargetNode, NodeTypes.MultiRelaitionsSelected); } else { SetDrawDelegateByNode(item.TargetNode, NodeTypes.MultiRelaitions); } } } }
public void Execute(Repl repl, ReplParser.AglContext tree, bool piped) { string lines = repl.input_output_stack.Pop(); var doc = repl.stack.Peek(); var pr = ParsingResultsFactory.Create(doc); var lexer = pr.Lexer; var parser = pr.Parser; var serializeOptions = new JsonSerializerOptions(); serializeOptions.Converters.Add(new AntlrJson.ParseTreeConverter()); serializeOptions.WriteIndented = false; var parse_info = JsonSerializer.Deserialize <AntlrJson.ParsingResultSet>(lines, serializeOptions); var nodes = parse_info.Nodes; System.Windows.Forms.Form form = new System.Windows.Forms.Form(); Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); Microsoft.Msagl.Drawing.Graph graph = CreateGraph(nodes, parser.RuleNames.ToList()); graph.LayoutAlgorithmSettings = new Microsoft.Msagl.Layout.Layered.SugiyamaLayoutSettings(); viewer.Graph = graph; form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); form.ShowDialog(); }
/// <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; }
//browse private void button1_Click(object sender, EventArgs e) { comboBox2.Items.Clear(); comboBox3.Items.Clear(); //string directory; Microsoft.Msagl.Drawing.Graph grafVisualization = new Microsoft.Msagl.Drawing.Graph("graf"); browse.Filter = "*.txt (file berekstensi txt) | *.txt"; if (browse.ShowDialog() == DialogResult.OK) { int i; string fileDirectory = browse.FileName; string filename = browse.SafeFileName; input = File.ReadAllLines(fileDirectory); label4.Text = filename; graf = new Graf(input); //menambahkan simpul simpul pada comboBox for (i = 1; i <= graf.getGraphNode().Count; i++) { comboBox2.Items.Add(graf.getGraphNode()[i - 1].getNamaNode()); comboBox3.Items.Add(graf.getGraphNode()[i - 1].getNamaNode()); } //visualisasi graf awal grafVisualization = FrontEndUtility.grafVisualization(graf); gViewer1.Graph = grafVisualization; } }
private void button1_Click(object sender, EventArgs e) { ofd.Filter = "Text Documents (*.txt)|*.txt"; if (ofd.ShowDialog() == DialogResult.OK) { comboBox1.Items.Clear(); comboBox2.Items.Clear(); g.clearGraph(); // Dekalrasi graph drawer Microsoft.Msagl.Drawing.Graph graphDrawer = new Microsoft.Msagl.Drawing.Graph("graph"); // Membuat graph dari text yang di buka path.Text = ofd.SafeFileName; string[] isi = File.ReadAllLines(ofd.FileName); g.setGraph(isi); //textBox2.Text = g.Edges[0].Node1; // Membuat graph drawer for (int i = 0; i < g.Total; i++) { graphDrawer.AddEdge(g.Edges[i].Node1, g.Edges[i].Node2).Attr.ArrowheadLength = 1; } gViewer1.Graph = graphDrawer; // Menambah item pada box choose account foreach (string node in g.Nodes) { comboBox1.Items.Add(node); } // Assign file ke field contents this.contents = new string[int.Parse(isi[0]) + 1]; this.contents = isi; } }
void LoadData(string DatFile) { uniqD = new Dictionary <long, long>(); using (var fs = File.OpenRead(DatFile)) { using (var br = new BinaryReader(fs)) { graphViewer = new GraphViewer(); graphViewer.LayoutEditingEnabled = false; graphViewer.BindToPanel(gvPanel); var dgraph = new Drawing.Graph(); Drawing.Edge edg = null; while (fs.Position < fs.Length - 128) { var tid = br.ReadInt32(); var flags = br.ReadInt32(); var rip = br.ReadInt64(); var rsp = br.ReadInt64(); var from_rip = br.ReadInt64(); if (!uniqD.ContainsKey(from_rip)) { uniqD.Add(from_rip, rip); edg = dgraph.AddEdge(from_rip.ToString("X"), rip.ToString("X"), rip.ToString("X")); } } graphViewer.Graph = dgraph; } } }
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; }
private void LoadRoute() { Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach (string[] line in InputData) { graph.AddEdge(line[0], line[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; } foreach (Edge edge in graph.Edges) { for (int i = 0; i < this.PathNode.Count() - 1; i++) { if (edge.Source == PathNode[i] && edge.Target == PathNode[i + 1]) { edge.Attr.ArrowheadAtTarget = ArrowStyle.Normal; edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(edge.Source).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(edge.Target).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } if (edge.Source == PathNode[i + 1] && edge.Target == PathNode[i]) { edge.Attr.ArrowheadAtSource = ArrowStyle.Normal; edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(edge.Source).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(edge.Target).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } } } gViewer1.Graph = graph; }
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"); } } }
private void DrawPathConnections(IGraphPath path, bool isSelected, Microsoft.Msagl.Drawing.Graph graph) { if (path == null || path.DirectFlow.Count <= 1) { return; } graph.Attr.MinNodeHeight = 40; graph.Attr.MinNodeWidth = 110; GraphItem prev = path.DirectFlow[0]; GraphItem next = path.DirectFlow[1]; if (prev.RelatedTo != null) { prev = (GraphItem)prev.RelatedTo; } if (next.RelatedTo != null) { next = (GraphItem)next.RelatedTo; } if (prev == null || next == null) { return; } DrawingHelper.DrawArrow(gLocalViewer, prev, next, isSelected, graph, path); }
/// <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); }
///<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); }
public virtual void UpdateGraph(Graph graph) { Node graphNode = graph.AddNode(NodeFile.Id); graphNode.LabelText = NodeFile.Name; UpdateGraphNode(graphNode); UpdateOutEdges(graph); }
public static void SetEdgeByNodes(Microsoft.Msagl.Drawing.Graph graph, string sourceId, string targetId) { foreach (Edge edge in graph.Edges) { if (edge.Source == sourceId && edge.Target == targetId) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; } else { if (edge.Source == targetId && edge.Target == sourceId) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; } else { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.LightGray; edge.Attr.Weight = 1; edge.Attr.LineWidth = 1; } } } }
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; }
private void Form1_Load(object sender, EventArgs e) { //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content //var allServices = ServiceController.GetServices().Where(ser => Services.Contains(ser.ServiceName)); foreach (ServiceController serviceController in ServiceController.GetServices()) { var service = $"{serviceController.DisplayName} ({serviceController.ServiceName})"; graph.AddNode(service); foreach (var dependentService in serviceController.DependentServices) { string dependent = $"{dependentService.DisplayName} ({dependentService.ServiceName})"; graph.AddNode(dependent); graph.AddEdge(dependent, service); } } //bind the graph to the viewer graph.Attr.LayerDirection = LayerDirection.None; graph.Attr.OptimizeLabelPositions = true; graph.CreateLayoutSettings(); graph.LayoutAlgorithmSettings = new MdsLayoutSettings(); viewer.Graph = graph; SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; Controls.Add(viewer); ResumeLayout(); }
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; }
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; }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { Panel.Children.Clear(); var nodes = main.storedata.scenicnode; GraphViewer graphViewer = new GraphViewer(); graphViewer.BindToPanel(Panel); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph(); foreach (var node in nodes) { if (node.edges.Count == 0) { graph.AddNode(new Node(node.name)); } foreach (var edge in node.edges) { graph.AddEdge(node.name, edge.GetDest(nodes).name); } } //graph.AddEdge("A", "B"); foreach (var node in graph.Nodes) { node.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; node.Attr.Color = Microsoft.Msagl.Drawing.Color.Purple; node.Attr.LabelMargin = 10; } graph.Attr.LayerDirection = LayerDirection.LR; graphViewer.Graph = graph; // throws exception }
void ProcessGraphml(string fileName) { var parser = new GraphmlParser(fileName); Microsoft.Msagl.Drawing.Graph graph = parser.Parse(); GiveGraphToControl(graph); }
public void resetEdgeColor(Microsoft.Msagl.Drawing.Graph graph) { foreach (var edge in graph.Edges) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; } }
internal static DNode CreateDNodeAndSetNodeBoundaryCurve(DrawingGraph drawingGraph, DGraph dGraph, GeometryNode geomNode, DrawingNode drawingNode) { double width = 0; double height = 0; DNode dNode = new DNode(drawingNode); dGraph.AddNode(dNode); Microsoft.Msagl.Drawing.Label label = drawingNode.Label; if (label != null) { CreateDLabel(dNode, label, out width, out height); width += 2 * dNode.DrawingNode.Attr.LabelMargin; height += 2 * dNode.DrawingNode.Attr.LabelMargin; } if (width < drawingGraph.Attr.MinNodeWidth) { width = drawingGraph.Attr.MinNodeWidth; } if (height < drawingGraph.Attr.MinNodeHeight) { height = drawingGraph.Attr.MinNodeHeight; } // Filippo Polo: I'm taking this out because I've modified the drawing of a double circle // so that it can be used with ellipses too. //if (drawingNode.Attr.Shape == Shape.DoubleCircle) //width = height = Math.Max(width, height) * Draw.DoubleCircleOffsetRatio; if (geomNode.BoundaryCurve == null) { geomNode.BoundaryCurve = Microsoft.Msagl.Drawing.NodeBoundaryCurves.GetNodeBoundaryCurve(dNode.DrawingNode, width, height); } return(dNode); }
public Microsoft.Msagl.Drawing.Graph GetGraph() { Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); foreach (Edge edge in edges) { graph.AddEdge(edge.source.ToString(), edge.target.ToString()); } foreach (Vertex vertex in vertexes) { Node n = graph.FindNode($"{vertex.Name}"); if (n != null) { n.Attr.FillColor = vertex.color; if (vertex.IsCorrect == false) { n.Attr.LineWidth = 3; n.Attr.Color = Color.Red; } n.Attr.Shape = Shape.Circle; } } return(graph); }
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; }
public GViewer Visualize(int t) { //create a form Form form = new Form(); //create a viewer object GViewer viewer = new GViewer(); //create a graph object Msagl.Graph graph = new Msagl.Graph("Corruption"); //create the graph content foreach (City city in this.cities.Values) { graph.AddNode(city.name); if (city.isInfected) { int red = 255, other = 255; if (city.isInfected) { red = 250; other = 150 - (int)(city.InfectedPercentage(t) * 150); } graph.FindNode(city.name).Attr.FillColor = new Msagl.Color(255, (byte)red, (byte)other, (byte)other); } foreach (City neigh in city.neighbors.Keys) { bool tmp = false; foreach (Edge e in this.infectedEdge) { if ((e.fromCity == city && e.toCity == neigh)) { tmp = true; } } if (!tmp) { graph.AddEdge(city.name, neigh.name).Attr.Color = Msagl.Color.Gray; } } } foreach (Edge e in this.infectedEdge) { graph.AddEdge(e.fromCity.name, e.toCity.name).Attr.Color = Msagl.Color.Red; } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = DockStyle.Fill; return(viewer); //form.Controls.Add(viewer); //form.ResumeLayout(); //show the form //form.ShowDialog(); }
private static int DrawAnchor(Graphics g, Pen myPen, DrawingGraph dg, int i, Anchor p) { string stringToShow = i.ToString() + " " + p.Id; DrawStringInRectCenter(g, Brushes.Blue, new Font(FontFamily.GenericSerif, 10), stringToShow, new RectangleF((float)p.Left, (float)p.Bottom, (float)p.RightAnchor + (float)p.LeftAnchor, (float)p.TopAnchor + (float)p.BottomAnchor)); i++; return(i); }
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; }
// ----Конструктор public MsaglSettingsWrapper(GViewer gViewer, MsaglGraphs.Graph msaglGraph, SgvlGraphs.Graph sgvlGraph, DrawingSettings drawingSettings) { MsaglGraph = msaglGraph; GViewer = gViewer; DrawingSettings = drawingSettings; // Подписываемся на событие изменения цвета фона drawingSettings.BackgroundColorChanged += UpdateBackgroundColor; }
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>(); }
private void btnRender_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(SymFile) || string.IsNullOrWhiteSpace(TraceFile)) { return; } string source, target; graphViewer = new GraphViewer(); graphViewer.LayoutEditingEnabled = false; graphViewer.BindToPanel(gvPanel); Drawing.Edge edg = null; var dgraph = new Drawing.Graph(); var sugiyamaSettings = (SugiyamaLayoutSettings)dgraph.LayoutAlgorithmSettings; sugiyamaSettings.NodeSeparation *= 2; sugiyamaSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear; var tot = new totts(SymFile, TraceFile); var blocks = tot.GetBlocks(); foreach (var block in blocks) { if (block == null) { break; } source = block.StepEvent.FROM_RIP.ToString("X"); target = block.StepEvent.RIP.ToString("X"); //var edge = new Drawing.Edge(source, "", target); edg = dgraph.AddEdge(source, target); } foreach (var block in blocks) { var blockLabel = new StringBuilder(); foreach (var line in block.Lines.Values) { blockLabel.Append($"{line.Address:X} \t + {line.NasmDisLine}"); } var node = dgraph.FindNode(block.StepEvent.FROM_RIP.ToString("X")); if (node == null) { continue; } node.LabelText = blockLabel.ToString(); node.Label.FontSize = 10; node.Label.FontName = "New Courier"; node.Label.FontColor = Drawing.Color.Blue; } dgraph.Attr.LayerDirection = Drawing.LayerDirection.TB; dgraph.Attr.OptimizeLabelPositions = false; graphViewer.Graph = dgraph; }
// inisialisasi graf dfs public DFS(Graph graf, ref Microsoft.Msagl.Drawing.Graph graphVisualizer, ref Panel draw_graph, ref Microsoft.Msagl.GraphViewerGdi.GViewer viewer) { this.adjacent = graf.adjacent; this.totalEdges = graf.totalEdges; this.totalNodes = graf.totalNodes; this.graphVisualizer = graphVisualizer; this.viewer = viewer; this.panel_DrawGraph = draw_graph; }
public static void Setup() { _form = new System.Windows.Forms.Form(); _viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); _graph = new Microsoft.Msagl.Drawing.Graph("graph"); _colorAdapter = new ColorAdapter(); _arrowAdapter = new LineArrowAdapter(); _figureAdapter = new FigureAdapter(); }
///<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); }
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(); } }
///<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 button2_Click(object sender, EventArgs e) { //upload button if (!(textBox1.Text.Equals(""))) { //for (int i = 0; i < textData.getTotalPeople(); i++) graph.RemoveNode(graph.FindNode(textData.getPerson(i))); //g.Clear(); textData = new TextHandler(); prevAccount = ""; prevExplore = ""; comboBox1.Items.Clear(); comboBox2.Items.Clear(); textData.Load(textBox1.Text); graph = new Microsoft.Msagl.Drawing.Graph("graph"); g = new GraphKita(textData); for (int i = 0; i < textData.getTotalConnection(); i++) { g.NewEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]); var edge = graph.AddEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]); edge.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None; edge.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; } for (int i = 0; i < textData.getTotalPeople(); i++) { comboBox1.Items.Add(textData.getPerson(i)); comboBox2.Items.Add(textData.getPerson(i)); } if ((textData.getTotalPeople() == 1)) { comboBox1.SelectedItem = (textData.getPerson(0)); comboBox2.SelectedItem = (textData.getPerson(0)); button3.Enabled = true; } else if ((textData.getTotalPeople() > 1)) { comboBox1.SelectedItem = (textData.getPerson(0)); comboBox2.SelectedItem = (textData.getPerson(1)); comboBox1.Items.Remove(comboBox2.SelectedItem.ToString()); comboBox2.Items.Remove(comboBox1.SelectedItem.ToString()); comboBox1.Enabled = true; comboBox2.Enabled = true; button3.Enabled = true; } printGraph(); instantSearch(); } else { Console.WriteLine("Path file tidak valid"); } }
internal void DrawGraph(Graphics g) { #region drawing of database for debugging only #if DEBUGGLEE Pen myPen = new Pen(System.Drawing.Color.Blue, (float)(1 / 1000.0)); DrawingGraph dg = this.DrawingGraph; if (dg.DataBase != null) { Draw.DrawDataBase(g, myPen, dg); } bool debugDrawing = Draw.DrawDebugStuff(g, this, myPen); if (debugDrawing) { return; } #endif #endregion if (this.drawingGraph.Attr.Border > 0) { DrawGraphBorder(this.drawingGraph.Attr.Border, g); } bool renderEdgeLabels = this.EdgeLabelsAreRendered; //we need to draw the edited edges last DEdge dEdgeSelectedForEditing = null; foreach (DEdge dEdge in Edges) { if (!dEdge.SelectedForEditing) { DrawEdge(g, dEdge, renderEdgeLabels); } else //there must be no more than one edge selected for editing { dEdgeSelectedForEditing = dEdge; } } foreach (DNode dnode in nodeMap.Values) { DrawNode(g, dnode); } //draw the selected edge if (dEdgeSelectedForEditing != null) { DrawEdge(g, dEdgeSelectedForEditing, renderEdgeLabels); DrawUnderlyingPolyline(g, dEdgeSelectedForEditing); } }
public GraphCity() { Vertex = new Dictionary <City, List <City> >(); probability = new Dictionary <KeyValuePair <City, City>, float>(); guiGraph = new Microsoft.Msagl.Drawing.Graph(); inputanNode = new Dictionary <string, City>(); jumlahKota = 0; kotaAwal = "noname"; jumlahEdge = 0; jalurInfek = new Dictionary <int, KeyValuePair <string, string> >(); }
/** * 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; }
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); } }
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; }
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; }
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 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(); }
private void LoadData() { Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //create the graph content foreach (string[] line in InputData) { graph.AddEdge(line[0], line[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; } gViewer1.Graph = graph; }
public PATModelFileParser(Graph graph, PAT.GenericDiff.graph.Side side, bool compareParameterizedSystem, bool compareConfigGraph, bool matchProcessParameters, int infinity, int cutnumber) { this.Graph = graph; this.side = side; this.configGraphBuilder = new ConfigurationGraphBuilder(compareParameterizedSystem, matchProcessParameters); this.compareParameterizedSystem = compareParameterizedSystem; this.compareConfigGraph = compareConfigGraph; this.infinity = infinity; this.cutnumber = cutnumber; }
public static void DrawNode(GViewer gLocalViewer, GraphItem item, bool selected, bool maxRelations) { if (gLocalViewer.InvokeRequired) { gLocalViewer.Invoke(new MethodInvoker(delegate() { DrawNode(gLocalViewer, item, selected, maxRelations); })); return; } Microsoft.Msagl.Drawing.Graph graph = gLocalViewer.Graph; Node node = new Node(item.UniqueID); if (item.Name.Length > 12) { node.Label.Text = string.Format("{0}...", item.Name.Substring(0, 6)); } else { node.Label.Text = item.Name; } node.UserData = item; if (selected || maxRelations) { if (selected && maxRelations) { node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(CustomDrawMultiRelaitionsSelectedNode); } else { if (selected) { node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(CustomDrawNormalSelectedNode); } else { if (maxRelations) { node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(CustomDrawMultiRelaitionsNode); } else { node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(CustomDrawNormalNode); } } } } else { node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(CustomDrawNormalNode); } graph.AddNode(node); gLocalViewer.Graph = graph; }
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(); }
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); } }
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; } }