private static void ProcessEdges(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Edge drawingEdge in graph.Edges) { Microsoft.Msagl.Node sourceNode = msaglGraph.FindNode(drawingEdge.Source); Microsoft.Msagl.Node targetNode = msaglGraph.FindNode(drawingEdge.Target); if (sourceNode == null) { sourceNode = CreateGeometryNode(msaglGraph, graph.FindNode(drawingEdge.Source) as Node, Connection.Connected); } if (targetNode == null) { targetNode = CreateGeometryNode(msaglGraph, graph.FindNode(drawingEdge.Target) as Node, Connection.Connected); } Microsoft.Msagl.Edge msaglEdge = new Microsoft.Msagl.Edge(sourceNode, targetNode); if (drawingEdge.Label != null && graph.LayoutAlgorithmSettings is SugiyamaLayoutSettings) { msaglEdge.Label = drawingEdge.Label.GeometryLabel; msaglEdge.Label.Parent = msaglEdge; } msaglEdge.Weight = drawingEdge.Attr.Weight; msaglEdge.Length = drawingEdge.Attr.Length; msaglEdge.Separation = drawingEdge.Attr.Separation; msaglEdge.ArrowheadAtSource = drawingEdge.Attr.ArrowAtSource; msaglEdge.ArrowheadAtTarget = drawingEdge.Attr.ArrowAtTarget; msaglGraph.AddEdge(msaglEdge); msaglEdge.UserData = drawingEdge; msaglEdge.ArrowheadLength = drawingEdge.Attr.ArrowheadLength; msaglEdge.LineWidth = drawingEdge.Attr.LineWidth; } }
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 static void ProcessPhyloEdges(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Edge e in graph.Edges) { Microsoft.Msagl.Node sourceNode = msaglGraph.FindNode(e.Source); Microsoft.Msagl.Node targetNode = msaglGraph.FindNode(e.Target); if (sourceNode == null) { sourceNode = CreateGeometryNode(msaglGraph, graph.FindNode(e.Source) as Node, Connection.Connected); } if (targetNode == null) { targetNode = CreateGeometryNode(msaglGraph, graph.FindNode(e.Target) as Node, Connection.Connected); } Microsoft.Msagl.Edge msaglEdge = new Microsoft.Msagl.PhyloEdge(sourceNode, targetNode); msaglEdge.Weight = e.Attr.Weight; msaglEdge.Separation = e.Attr.Separation; msaglEdge.ArrowheadAtSource = e.Attr.ArrowAtSource; msaglEdge.ArrowheadAtTarget = e.Attr.ArrowAtTarget; msaglGraph.AddEdge(msaglEdge); msaglEdge.UserData = e; msaglEdge.ArrowheadLength = e.Attr.ArrowheadLength; msaglEdge.LineWidth = e.Attr.LineWidth; } }
void ProcessEdges(GeometryGraph msaglGraph) { foreach (Edge drawingEdge in drawingGraph.Edges) { Core.Layout.Node sourceNode = nodeMapping[drawingEdge.SourceNode]; Core.Layout.Node targetNode = nodeMapping[drawingEdge.TargetNode]; if (sourceNode == null) { sourceNode = CreateGeometryNode(drawingGraph, msaglGraph, drawingGraph.FindNode(drawingEdge.Source), ConnectionToGraph.Connected); nodeMapping[drawingEdge.SourceNode] = sourceNode; } if (targetNode == null) { targetNode = CreateGeometryNode(drawingGraph, msaglGraph, drawingGraph.FindNode(drawingEdge.Target), ConnectionToGraph.Connected); nodeMapping[drawingEdge.TargetNode] = targetNode; } var msaglEdge = CreateGeometryEdgeAndAddItToGeometryGraph(drawingEdge, msaglGraph); } }
public Form1() { InitializeComponent(); GViewer gViewer = new GViewer() { Dock = DockStyle.Fill }; SuspendLayout(); Controls.Add(gViewer); ResumeLayout(); Graph graph = new Graph(); var sugiyamaSettings = (SugiyamaLayoutSettings)graph.LayoutAlgorithmSettings; sugiyamaSettings.NodeSeparation *= 2; graph.AddEdge("A", "B"); graph.AddEdge("A", "C"); graph.AddEdge("A", "D"); graph.LayerConstraints.PinNodesToSameLayer(new[] { graph.FindNode("A"), graph.FindNode("B"), graph.FindNode("C") }); gViewer.Graph = graph; }
/// <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 void ReadEdge() { CheckToken(Tokens.Edge); XmlRead(); object userData = null; if (TokenIs(Tokens.UserData)) { userData = ReadUserData(); } string srcId = ReadStringElement(Tokens.SourceNodeID); string targetId = ReadStringElement(Tokens.TargetNodeID); Edge edge = null; try { // Only try reading to ensure backward compatibility with older MSAGL file formates string edgeTypeName = ReadEdgeType(); Type edgeTpye = GetTypeByName(edgeTypeName); Node srcNode = graph.FindNode(srcId); Node targetNode = graph.FindNode(targetId); edge = (Edge)Activator.CreateInstance(edgeTpye, new object[] { srcNode, targetNode }); graph.AddPrecalculatedEdge(edge); } catch { edge = graph.AddEdge(srcId, targetId); } try { // Only try reading to ensure backward compatibility with older MSAGL file formates edge.IsVisible = ReadVisibility(); } catch { edge.IsVisible = true; } edge.Attr = new EdgeAttr(); edge.UserData = userData; ReadEdgeAttr(edge.Attr); ReadLabel(edge); EdgeList.Add(edge); ReadEndElement(); }
static void ProcessLinks(DgmlGraph g, Dictionary <string, Subgraph> subgraphTable, Microsoft.Msagl.Drawing.Graph drawingGraph) { foreach (GraphLink gl in g.Links) { var sourceId = gl.Source.Id.LiteralValue; var targetId = gl.Target.Id.LiteralValue; Subgraph sourceSubgraph; Node source = !subgraphTable.TryGetValue(sourceId, out sourceSubgraph) ? drawingGraph.FindNode(sourceId) : sourceSubgraph; Subgraph targetSubgraph; Node target = !subgraphTable.TryGetValue(targetId, out targetSubgraph) ? drawingGraph.FindNode(targetId) : targetSubgraph; bool containment = false; foreach (GraphCategory gc in gl.Categories) { string c = gc.ToString().Replace("CodeSchema_", ""); if (c == "Contains") { if (targetSubgraph != null) { sourceSubgraph.AddSubgraph(targetSubgraph); } else { sourceSubgraph.AddNode(target); } containment = true; } } if (!containment) { Edge edge = new Edge(source, target, ConnectionToGraph.Connected); // edge.Label = new Label(c); } } }
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 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.ToString("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; }
void ProcessPhyloEdges(Graph graph, GeometryGraph msaglGraph) { foreach (Edge e in graph.Edges) { Core.Layout.Node sourceNode = nodeMapping[e.SourceNode]; Core.Layout.Node targetNode = nodeMapping[e.TargetNode]; if (sourceNode == null) { sourceNode = CreateGeometryNode(graph, msaglGraph, graph.FindNode(e.Source), ConnectionToGraph.Connected); nodeMapping[e.SourceNode] = sourceNode; } if (targetNode == null) { targetNode = CreateGeometryNode(graph, msaglGraph, graph.FindNode(e.Target), ConnectionToGraph.Connected); nodeMapping[e.TargetNode] = targetNode; } Core.Layout.Edge msaglEdge = new Prototype.Phylo.PhyloEdge(sourceNode, targetNode); msaglEdge.Weight = e.Attr.Weight; msaglEdge.Separation = e.Attr.Separation; if (e.Attr.ArrowAtSource) { msaglEdge.EdgeGeometry.SourceArrowhead = new Arrowhead { Length = e.Attr.ArrowheadLength }; } if (e.Attr.ArrowAtTarget) { msaglEdge.EdgeGeometry.TargetArrowhead = new Arrowhead { Length = e.Attr.ArrowheadLength }; } msaglGraph.Edges.Add(msaglEdge); msaglEdge.UserData = e; msaglEdge.LineWidth = e.Attr.LineWidth; } }
private void Load_Graph_Click(object sender, RoutedEventArgs e) // Membuat graf satu arah dari file peta yang sudah diload sebelumnya { try { map = new Graf(dirGraph); Enter_Query.IsEnabled = true; Open_Query.IsEnabled = true; Next.IsEnabled = false; this.gViewer.Graph = null; graph = new Msagl.Graph("graph"); for (int i = map.getHouses() - 1; i > 0; i--) { for (int j = map.getPath(i).Count() - 1; j >= 0; j--) { string str1 = i.ToString(); string str2 = map.getPath(i)[j].ToString(); graph.AddEdge(str1, str2).Attr.ArrowheadAtTarget = Msagl.ArrowStyle.None; Microsoft.Msagl.Drawing.Node from = graph.FindNode(str1); Microsoft.Msagl.Drawing.Node to = graph.FindNode(str2); from.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; from.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; to.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; to.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; } } this.gViewer.Graph = graph; } catch { MessageBox.Show(" Error Code 0x05021999\n File Input Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void drawGraph() { //create a form 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 = new Microsoft.Msagl.Drawing.Graph("graph"); for (int i = 0; i < nodes.Count; i++) { Console.WriteLine("i:" + i); Console.WriteLine("children count: " + nodes[i].children.Count); for (int j = 0; j < nodes[i].children.Count; j++) { Console.WriteLine("j:" + j); Console.WriteLine("Parent node: " + nodes[i].getNodeName()); Console.WriteLine("node name: " + nodes[i].children[j].getNodeName()); int flow = nodes[i].edges[j][0]; var newEdge = graph.AddEdge(nodes[i].getNodeName(), nodes[i].children[j].getNodeName()); Microsoft.Msagl.Drawing.Node childNode = graph.FindNode(nodes[i].getNodeName()); string cap = nodes[i].edges[j][0].ToString() + "/" + nodes[i].edges[j][1].ToString(); newEdge.LabelText = cap; childNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; childNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; if (flow > 0) { string tempStringg = nodes[i].getNodeName() + nodes[i].children[j].getNodeName(); if (nameofnodes.Contains(tempStringg)) { newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Orange; } } else { newEdge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; } } } viewer.Graph = graph; form.SuspendLayout(); viewer.CurrentLayoutMethod = LayoutMethod.MDS; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.ShowDialog(); }
public void Generate() { log = new List <Microsoft.Msagl.Drawing.Graph>(); graph = ConstGraph(); //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form viewer.Dock = DockStyle.Fill; pictureBox1.Controls.Add(viewer); //show the form foreach (var elem in Graph.visitedNode) { Microsoft.Msagl.Drawing.Graph gtemp = ConstGraph(); gtemp.FindNode(Graph.graphEl[elem]).Attr.FillColor = Color.Yellow; log.Add(gtemp); } log.Add(graph); timer2.Interval = 1300; idx = 0; timer2.Tick += new EventHandler(Animate); timer2.Enabled = true; }
private void GenerateGraph(GraphStructure stGraph) { Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph(stGraph.Header.GraphName); if (stGraph.Records.Count > 1) { for (int i = 0; i < stGraph.Records.Count; i++) { for (int j = 0; j < stGraph.Records.Count; j++) { string source = stGraph.Records.ElementAt(i).VertexName; string target = stGraph.Header.Vertices.ElementAt(j); string label = stGraph.Records.ElementAt(i).Edges.ElementAt(j); if (i != j && !(label.ToLower().Equals("inf"))) //if it's not pointing to itself or Inf(doesn't has an edge to target vertex) { graph.AddEdge(source: source, edgeLabel: label, target: target); //add vertices and make an edge between them RequireAttributes(graph.FindNode(source) as Node); } } } } this.gViewer.Graph = graph; }
/* * BROWSE FILE SECTION */ // Browse Button private void button1_Click(object sender, EventArgs e) { // ---- INPUT HANDLER ---- OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Graph File"; ofd.Filter = "Text File|*.txt"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Path : ofd.FileName // Name : ofd.SafeFileName // filename is the Label name inside the filename container filename.Text = ofd.SafeFileName; filepath = ofd.FileName; // ---- SHOWING DATA ---- // > ---- Read Graph File ---- < logicFunctions.BacaFile(filepath); // Get Nodes List List <String> explore = new List <String>(); List <String> friend = new List <String>(); foreach (var map in logicFunctions.getGraf()) { explore.Add(map.Key); friend.Add(map.Key); } // > ---- Dropdown Explore Friends ---- < dropdownExploreFriends.DataSource = explore; // > ---- Dropdown Account ---- < dropdownAccount.DataSource = friend; // > ---- Display Graph ---- < // Create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); // Add edges List <Tuple <String, String> > addedEdge = new List <Tuple <String, String> >(); foreach (var map in logicFunctions.getGraf()) { foreach (var vals in map.Value) { Tuple <String, String> check1 = new Tuple <String, String>(map.Key, vals); Tuple <String, String> check2 = new Tuple <String, String>(vals, map.Key); if (!addedEdge.Contains(check1) && !addedEdge.Contains(check2)) { var ed = graph.AddEdge(map.Key, vals); ed.Attr.ArrowheadAtTarget = ArrowStyle.None; addedEdge.Add(check1); addedEdge.Add(check2); } } // Change to circle graph.FindNode(map.Key).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; } // Bind with viewer fileGraphViewer.Graph = graph; } }
void ShowGraph(bool showMes) { this.groupBoxResult.Controls.Clear(); Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); graph.CreateGeometryGraph(); int i = 1; foreach (var item in lstPoint) { Node node = new Node(i.ToString()); node.Attr.Shape = Shape.Circle; graph.AddNode(node); i++; } graph.FindNode((this.start + 1).ToString()).Attr.FillColor = Color.Blue; graph.FindNode((this.end + 1).ToString()).Attr.FillColor = Color.Red; viewer.Pan(5, 2); for (int j = 0; j < this.soDinh; j++) { for (int k = 0; k < this.soDinh; k++) { if (this.distance[j, k] != this.VOCUNG && this.distance[j, k] != 0) { String tmp = "," + (j + 1).ToString() + "," + (k + 1).ToString() + ","; double dis = Math.Round(this.distance[j, k], 2); if (this.path.Contains(tmp)) { if (this.checkBox.Checked) { graph.AddEdge((j + 1).ToString(), dis.ToString(), (k + 1).ToString()).Attr.Color = Color.Green; } else { graph.AddEdge((j + 1).ToString(), (k + 1).ToString()).Attr.Color = Color.Green; } // Microsoft.Msagl.Core.Layout.Node node = new Microsoft.Msagl.Core.Layout.Node(1, 2); } else { if (this.checkBox.Checked) { graph.AddEdge((j + 1).ToString(), dis.ToString(), (k + 1).ToString()); } else { graph.AddEdge((j + 1).ToString(), (k + 1).ToString()); } } } } } /*graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; * Edge edge = new Edge("14","sonnx","15"); * * graph.AddEdge("14", "sonnx", "15"); * graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; * graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; * Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); * c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; * c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle;*/ /* * * Microsoft.Msagl.Core.Geometry.Point p1 = new Microsoft.Msagl.Core.Geometry.Point(-497.12352212078628, 1689.84931190121); * Microsoft.Msagl.Core.Geometry.Point p2 = new Microsoft.Msagl.Core.Geometry.Point(198.64235142705752, 2139.4677380013277); * Microsoft.Msagl.Core.Geometry.Point bl = new Microsoft.Msagl.Core.Geometry.Point(-5191.0147700187063, -4395.7850131819132); * double gridSize = 553.23948409846571; * * GridTraversal grid = new GridTraversal(new Rectangle(bl, bl + new Microsoft.Msagl.Core.Geometry.Point(gridSize, gridSize)), 20); * var tiles = grid.GetTilesIntersectedByLineSeg(p1, p2); */ //bind the graph to the viewer viewer.Graph = graph; // viewer.Click += new EventHandler(Group_Click); // viewer.MouseClick += new MouseEventHandler(Group_Click); this.groupBoxResult.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBoxResult.Controls.Add(viewer); this.groupBoxResult.ResumeLayout(); if (showMes) { if (this.daxet[this.end]) { MessageBox.Show("Độ dài đường đi ngắn nhất " + (Math.Round(d[this.end], 2)).ToString(), "Thành công"); this.txtLoTrinh.Text = this.path; this.txtDoDai.Text = (Math.Round(d[this.end], 2)).ToString(); } else { MessageBox.Show("Không tìm được đường đi ngắn nhất", "Có lỗi xảy ra"); this.txtLoTrinh.Text = ""; this.txtDoDai.Text = ""; } } }
public FormGraph() { InitializeComponent(); 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 = new Microsoft.Msagl.Drawing.Graph("graph"); this.Text = "Graph"; myGraph = InputControls.getMyGraph(); var nodeList = new List <Node>(); foreach (var myNode in myGraph.Nodes) { graph.AddNode(new Node(myNode.Name)); } foreach (var myPipe in myGraph.Pipes) { if (myPipe.StartingValue != 0) { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint); } if (myPipe.EndingValue != 0) { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint); } } string startingPointName = myGraph.Nodes.Where(x => x.IsStartingPoint == true) .Select(x => x.Name).FirstOrDefault(); string endPointName = myGraph.Nodes.Where(x => x.IsEndPoint == true) .Select(x => x.Name).FirstOrDefault(); if (startingPointName != null && endPointName != null) { graph.FindNode(startingPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(startingPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(endPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(endPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } //Microsoft.Msagl.Drawing.Node node = new Microsoft.Msagl.Drawing.Node("a"); //graph.AddEdge("Ali", "Veli"); //graph.AddEdge("B", "C"); //graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; //graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; //graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; //Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); //c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; //c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; viewer.Graph = graph; this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(viewer); this.ResumeLayout(); }
private void CreateGraph() { Graph graph = new Graph("graph"); graph.Attr.BackgroundColor = Color.DodgerBlue; Edge edge = (Edge)graph.AddEdge("S24", "27"); edge.LabelText = "Edge Label Test"; graph.AddEdge("S24", "25"); edge = graph.AddEdge("S1", "10") as Edge; edge.LabelText = "Init"; edge.Attr.ArrowheadAtTarget = ArrowStyle.Tee; // edge.Attr.Weight = 10; edge = graph.AddEdge("S1", "2") as Edge; // edge.Attr.Weight = 10; graph.AddEdge("S35", "36"); graph.AddEdge("S35", "43"); graph.AddEdge("S30", "31"); graph.AddEdge("S30", "33"); graph.AddEdge("9", "42"); graph.AddEdge("9", "T1"); graph.AddEdge("25", "T1"); graph.AddEdge("25", "26"); graph.AddEdge("27", "T24"); graph.AddEdge("2", "3"); graph.AddEdge("2", "16"); graph.AddEdge("2", "17"); graph.AddEdge("2", "T1"); graph.AddEdge("2", "18"); graph.AddEdge("10", "11"); graph.AddEdge("10", "14"); graph.AddEdge("10", "T1"); graph.AddEdge("10", "13"); graph.AddEdge("10", "12"); graph.AddEdge("31", "T1"); edge = (Edge)graph.AddEdge("31", "32"); edge.Attr.ArrowheadAtTarget = ArrowStyle.Tee; edge.Attr.LineWidth = 10; edge.Attr.Weight = 10; edge.Attr.ArrowheadLength *= 2; edge = (Edge)graph.AddEdge("33", "T30"); edge.Attr.LineWidth = 15; edge.Attr.AddStyle(Microsoft.Msagl.Drawing.Style.Dashed); graph.AddEdge("33", "34"); graph.AddEdge("42", "4"); graph.AddEdge("26", "4"); graph.AddEdge("3", "4"); graph.AddEdge("16", "15"); graph.AddEdge("17", "19"); graph.AddEdge("18", "29"); graph.AddEdge("11", "4"); graph.AddEdge("14", "15"); graph.AddEdge("37", "39"); graph.AddEdge("37", "41"); graph.AddEdge("37", "38"); graph.AddEdge("37", "40"); graph.AddEdge("13", "19"); graph.AddEdge("12", "29"); graph.AddEdge("43", "38"); graph.AddEdge("43", "40"); graph.AddEdge("36", "19"); graph.AddEdge("32", "23"); graph.AddEdge("34", "29"); graph.AddEdge("39", "15"); graph.AddEdge("41", "29"); graph.AddEdge("38", "4"); graph.AddEdge("40", "19"); graph.AddEdge("4", "5"); graph.AddEdge("19", "21"); graph.AddEdge("19", "20"); graph.AddEdge("19", "28"); graph.AddEdge("5", "6"); graph.AddEdge("5", "T35"); graph.AddEdge("5", "23"); edge = graph.AddEdge("21", "22"); edge.Attr.ArrowheadLength *= 3; graph.AddEdge("20", "15"); graph.AddEdge("28", "29"); graph.AddEdge("6", "7"); graph.AddEdge("15", "T1"); graph.AddEdge("22", "23"); graph.AddEdge("22", "T35"); graph.AddEdge("29", "T30"); graph.AddEdge("7", "T8"); graph.AddEdge("23", "T24"); graph.AddEdge("23", "T1"); Node node = graph.FindNode("S1") as Node; node.LabelText = "Label Test"; CreateSourceNode(graph.FindNode("S1") as Node); CreateSourceNode(graph.FindNode("S24") as Node); CreateSourceNode(graph.FindNode("S35") as Node); CreateTargetNode(graph.FindNode("T24") as Node); CreateTargetNode(graph.FindNode("T1") as Node); CreateTargetNode(graph.FindNode("T30") as Node); CreateTargetNode(graph.FindNode("T8") as Node); //layout the graph and draw it //graph.AddEdge("f", "a"); //graph.AddEdge("a", "l").LabelText = "from node a\n to node l\n with sincerity"; //graph.AddEdge("a", "b").LabelText="a=>b"; //graph.AddEdge("b", "a"); //changing the order of a and b causes a crash //graph.AddEdge("a", "l"); //graph.AddEdge("a", "b").LabelText = "a=>b label\n number 2"; //graph.AddEdge("a", "c"); //graph.AddEdge("b", "d"); //graph.AddEdge("d", "c"); //graph.AddEdge("c", "b"); //graph.AddEdge("b", "c"); //graph.AddEdge("a", "e"); //graph.AddEdge("d", "k").LabelText="dk label"; //Microsoft.Msagl.SugiyamaLayoutSettings settings = graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings; //settings.PinNodesToMaxLayer("2","S35"); //settings.AddUpDownVerticalConstraint("39", "15"); //settings.AddSameLayerNeighbors("S24", "2"); //settings.AddUpDownVerticalConstraint("9", "3"); //settings.AddUpDownVerticalConstraint("S1", "T8"); #if DEBUG Microsoft.Msagl.GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif //settings.AddUpDownVerticalConstraints("3", "28"); //settings.PinNodesToMinLayer("T1", "T8", "T24"); //settings.PinNodesToSameLayer("12", "S30", "19"); //settings.PinNodesToSameLayer("29", "31", "4"); //settings.AddUpDownConstraint("29", "12"); // Add vertical and horizontal constraints //settings.AddUpDownVerticalConstraint("37", "38"); //settings.AddUpDownVerticalConstraint("38", "4"); //settings.AddUpDownVerticalConstraint("4", "5"); //settings.AddSameLayerNeighbors("2", "10"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("19", "40"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("17", "40"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddSameLayerNeighbors("43", "S24"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T1"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T245"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("7", "T30"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("5", "4"); //(graph.LayoutAlgorithmSettings as Microsoft.Msagl.SugiyamaLayoutSettings).AddUpDownConstraint("4", "3"); gViewer.Graph = graph; // Verify vertical and neighbour constraints var node2 = graph.FindNode("2"); var node4 = graph.FindNode("4"); var node5 = graph.FindNode("5"); var node10 = graph.FindNode("10"); var node37 = graph.FindNode("37"); var node38 = graph.FindNode("38"); bool fXalign_37_38 = (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001) && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y); bool fXalign_38_4 = (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001) && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y); bool fXalign_4_5 = (Math.Abs(node37.GeometryNode.Center.X - node38.GeometryNode.Center.X) < 0.0001) && (node37.GeometryNode.Center.Y > node38.GeometryNode.Center.Y); bool fXalign = true; if (!fXalign_37_38 || !fXalign_38_4 || !fXalign_4_5) { Console.WriteLine(); Console.WriteLine("Xalign tests failed"); Console.WriteLine(); fXalign = false; } bool fYalign = (Math.Abs(node2.GeometryNode.Center.Y - node10.GeometryNode.Center.Y) < 0.0001) && (node2.GeometryNode.Center.X < node10.GeometryNode.Center.Y); if (!fYalign) { Console.WriteLine(); Console.WriteLine("Yalign tests failed"); Console.WriteLine(); } if (fXalign && fYalign) { Console.WriteLine(); Console.WriteLine("Xalign and Yalign tests passed"); Console.WriteLine(); } this.propertyGrid1.SelectedObject = graph; }
public void update_Vertex_terinfeksi(City kota) { guiGraph.FindNode(kota.get_nama()).Attr.FillColor = Color.Red; }
public Microsoft.Msagl.Drawing.Graph LoadResult(List <string> exploreFriendResult, int countEdges, List <string> rawEdges) { Microsoft.Msagl.Drawing.Graph graphDFS = new Microsoft.Msagl.Drawing.Graph(); this.countEdges = countEdges; // extract nodes in BFS/DFS List <string> resultEdges = new List <string>(); for (int i = 0; i < exploreFriendResult.Count - 1; i++) { resultEdges.Add(exploreFriendResult[i] + " " + exploreFriendResult[i + 1]); } // make a reverse list to account for either direction // ex: A G || G A List <string> resultEdgesReversed = new List <string>(); foreach (string edge in resultEdges) { char[] charArray = edge.ToCharArray(); Array.Reverse(charArray); resultEdgesReversed.Add(new string(charArray)); } // add edges to graph plus coloring for (int i = 0; i < rawEdges.Count; i++) { string rawNode1 = rawEdges[i].Split(" ")[0]; string rawnode2 = rawEdges[i].Split(" ")[1]; if (resultEdges.Contains(rawEdges[i]) || resultEdgesReversed.Contains(rawEdges[i])) // kalo edge ada di result { var Edge = graphDFS.AddEdge(rawNode1, rawnode2); Edge.Attr.ArrowheadAtTarget = ArrowStyle.None; Edge.Attr.ArrowheadAtSource = ArrowStyle.None; Edge.Attr.Color = Color.MediumVioletRed; } else { var Edge = graphDFS.AddEdge(rawNode1, rawnode2); Edge.Attr.ArrowheadAtTarget = ArrowStyle.None; Edge.Attr.ArrowheadAtSource = ArrowStyle.None; } } // change nodes color foreach (string node in exploreFriendResult) { if (node == exploreFriendResult[0]) { graphDFS.FindNode(node).Attr.FillColor = Color.LightSeaGreen; } else if (node == exploreFriendResult[exploreFriendResult.Count - 1]) { graphDFS.FindNode(node).Attr.FillColor = Color.SeaGreen; } else { graphDFS.FindNode(node).Attr.FillColor = Color.MediumSeaGreen; } } return(graphDFS); }
public static void Create_Graph(List<note_node> DTArray) { int index; //String Temp_str = null; System.Windows.Forms.Form GDIForm = new System.Windows.Forms.Form(); GDIForm.Size = new System.Drawing.Size(1000, 1000); //GDIForm.WindowState = FormWindowState.Maximized; //create a viewer object GViewerewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); //Sort DT Awway by position List<note_node> sorted_list = DTArray.OrderBy(o => o.NoteDetails.position).ToList(); foreach (note_node temp_node in sorted_list) { index = DTArray.IndexOf(temp_node); String Parent_Note; String Current_Note; // Check if it's a route node if (temp_node.parent_node == null) { // Route node so skip Current_Note = temp_node.ToStringSmall() + " Index" + temp_node.tree_index; Node graph_node = new Node(Current_Note); Microsoft.Msagl.Drawing.Color tempcolor = new Microsoft.Msagl.Drawing.Color(); graph_node.Attr.FillColor = Color.AliceBlue; graph_node.Attr.Shape = Shape.Diamond; graph.AddNode(graph_node); } else { //Build the Node string values //Parent_Note = temp_node.parent_node_index.GetValueOrDefault().ToString() + "\r\n" + DTArray[temp_node.parent_node_index.GetValueOrDefault()].ToStringSmall(); ///Current_Note = DTArray.IndexOf(temp_node).ToString() + "\r\n" + temp_node.ToStringSmall(); Parent_Note = temp_node.parent_node.ToStringSmall() + " Index" + temp_node.parent_node.tree_index; Current_Note = temp_node.ToStringSmall() + " Index" + temp_node.tree_index; //Current_Note = temp_node.ToStringSmall(); // 255,0,0 = Red // 0,255,0 = Green // Not route node so add edge details graph.AddEdge(Parent_Note, temp_node.cost.ToString(), Current_Note); //graph.AddNode() //Microsoft.Msagl.Drawing.Color tempcol = Microsoft.Msagl.Drawing.Color. // FromArgb(255,255,255); if (temp_node.Excluded) { graph.FindNode(Current_Note).Attr.FillColor = Color.Red; } } } //bind the graph to the viewer GViewerewer.Graph = graph; //GViewerewer.Size = new System.Drawing.Size(800, 800); //associate the viewer with the GDIForm GDIForm.SuspendLayout(); GViewerewer.Dock = System.Windows.Forms.DockStyle.Fill; GDIForm.Controls.Add(GViewerewer); GDIForm.ResumeLayout(); //show the GDIForm GDIForm.Show(); }
//maxFlowPath => { "A", "B", "C", "E" } //Constructor 2 public FormGraph(List <string> maxFlowPath, bool isMaxFlowPath) { //this.Text = flow.ToString(); List <string[]> binaryList = new List <string[]>(); InitializeComponent(); 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 = new Microsoft.Msagl.Drawing.Graph("graph"); //listOfNodes = InputControls.getListOfNodes(); myGraph = InputControls.getMyGraph(); var nodeList = new List <Node>(); //node ekle foreach (var myNode in myGraph.Nodes) { graph.AddNode(new Node(myNode.Name)); } List <List <string> > binaryPaths = new List <List <string> >(); for (int i = 0; i < maxFlowPath.Count() - 1; i++) { binaryPaths.Add(new List <string> { maxFlowPath[i], maxFlowPath[i + 1] }); } //edge ekle foreach (var myPipe in myGraph.Pipes) { if (myPipe.StartingValue != 0) { if (IsOnThePath(myPipe, binaryPaths)) { if (isMaxFlowPath) { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Blue; } } else { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint); } } if (myPipe.EndingValue != 0) { if (IsOnThePath(myPipe, binaryPaths)) { if (isMaxFlowPath) { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Blue; } } else { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint); } } } string startingPointName = myGraph.Nodes.Where(x => x.IsStartingPoint == true) .Select(x => x.Name).FirstOrDefault(); string endPointName = myGraph.Nodes.Where(x => x.IsEndPoint == true) .Select(x => x.Name).FirstOrDefault(); if (startingPointName != null && endPointName != null) { graph.FindNode(startingPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(startingPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(endPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(endPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } viewer.Graph = graph; this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(viewer); this.ResumeLayout(); }
private Graph BuildGraphFrom(VisualGraphGeneratedMessage affectedGraph) { var graph = new Graph("graph") { Attr = {BackgroundColor = Color.Transparent} }; if (affectedGraph.Connections != null) { _gViewer.LayoutAlgorithmSettingsButtonVisible = true; _gViewer.ForeColor = System.Drawing.Color.FromArgb(1,2,3); foreach (var x in affectedGraph.Connections) { var edge = graph.AddEdge(x.From, x.To); if (_mode == DisplayMode.Dark) { edge.Attr.Color = Color.White; } } } graph.Attr.LayerDirection = LayerDirection.LR; if (affectedGraph.Nodes != null) foreach (var y in affectedGraph.Nodes) { var n = graph.FindNode(y.FullName) ?? graph.AddNode(y.FullName); n.LabelText = y.DisplayName; n.Attr.Shape = Shape.Box; if (y.IsRootNode) n.Attr.FillColor = Color.LightGreen; else if (y.IsChange) n.Attr.FillColor = Color.Maroon; else if (y.IsTest && y.IsProfiledTest) n.Attr.FillColor = Color.Yellow; else if (y.IsTest) n.Attr.FillColor = Color.DarkGoldenrod; else if (y.IsInterface) n.Attr.FillColor = Color.LightBlue; //TODO GREG PUT ON FEATURE TOGGLE else if (false && y.Complexity > 15) n.Attr.FillColor = Color.LightPink; else n.Attr.FillColor = Color.White; } return graph; }
void CreateAndLayoutAndDisplayGraph(object sender, ExecutedRoutedEventArgs ex) { try { // Graph graph = new Graph(); // // //graph.LayoutAlgorithmSettings=new MdsLayoutSettings(); // // graph.AddEdge("1", "2"); // graph.AddEdge("1", "3"); // var e = graph.AddEdge("4", "5"); // e.LabelText = "Some edge label"; // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // graph.AddEdge("4", "6"); // e = graph.AddEdge("7", "8"); // e.Attr.LineWidth *= 2; // e.Attr.Color = Color.Red; // // graph.AddEdge("7", "9"); // e = graph.AddEdge("5", "7"); // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // graph.AddEdge("2", "7"); // graph.AddEdge("10", "11"); // graph.AddEdge("10", "12"); // graph.AddEdge("2", "10"); // graph.AddEdge("8", "10"); // graph.AddEdge("5", "10"); // graph.AddEdge("13", "14"); // graph.AddEdge("13", "15"); // graph.AddEdge("8", "13"); // graph.AddEdge("2", "13"); // graph.AddEdge("5", "13"); // graph.AddEdge("16", "17"); // graph.AddEdge("16", "18"); // graph.AddEdge("16", "18"); // graph.AddEdge("19", "20"); // graph.AddEdge("19", "21"); // graph.AddEdge("17", "19"); // graph.AddEdge("2", "19"); // graph.AddEdge("22", "23"); // // e = graph.AddEdge("22", "24"); // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // e = graph.AddEdge("8", "22"); // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // graph.AddEdge("20", "22"); // graph.AddEdge("25", "26"); // graph.AddEdge("25", "27"); // graph.AddEdge("20", "25"); // graph.AddEdge("28", "29"); // graph.AddEdge("28", "30"); // graph.AddEdge("31", "32"); // graph.AddEdge("31", "33"); // graph.AddEdge("5", "31"); // graph.AddEdge("8", "31"); // graph.AddEdge("2", "31"); // graph.AddEdge("20", "31"); // graph.AddEdge("17", "31"); // graph.AddEdge("29", "31"); // graph.AddEdge("34", "35"); // graph.AddEdge("34", "36"); // graph.AddEdge("20", "34"); // graph.AddEdge("29", "34"); // graph.AddEdge("5", "34"); // graph.AddEdge("2", "34"); // graph.AddEdge("8", "34"); // graph.AddEdge("17", "34"); // graph.AddEdge("37", "38"); // graph.AddEdge("37", "39"); // graph.AddEdge("29", "37"); // graph.AddEdge("5", "37"); // graph.AddEdge("20", "37"); // graph.AddEdge("8", "37"); // graph.AddEdge("2", "37"); // graph.AddEdge("40", "41"); // graph.AddEdge("40", "42"); // graph.AddEdge("17", "40"); // graph.AddEdge("2", "40"); // graph.AddEdge("8", "40"); // graph.AddEdge("5", "40"); // graph.AddEdge("20", "40"); // graph.AddEdge("29", "40"); // graph.AddEdge("43", "44"); // graph.AddEdge("43", "45"); // graph.AddEdge("8", "43"); // graph.AddEdge("2", "43"); // graph.AddEdge("20", "43"); // graph.AddEdge("17", "43"); // graph.AddEdge("5", "43"); // graph.AddEdge("29", "43"); // graph.AddEdge("46", "47"); // graph.AddEdge("46", "48"); // graph.AddEdge("29", "46"); // graph.AddEdge("5", "46"); // graph.AddEdge("17", "46"); // graph.AddEdge("49", "50"); // graph.AddEdge("49", "51"); // graph.AddEdge("5", "49"); // graph.AddEdge("2", "49"); // graph.AddEdge("52", "53"); // graph.AddEdge("52", "54"); // graph.AddEdge("17", "52"); // graph.AddEdge("20", "52"); // graph.AddEdge("2", "52"); // graph.AddEdge("50", "52"); // graph.AddEdge("55", "56"); // graph.AddEdge("55", "57"); // graph.AddEdge("58", "59"); // graph.AddEdge("58", "60"); // graph.AddEdge("20", "58"); // graph.AddEdge("29", "58"); // graph.AddEdge("5", "58"); // graph.AddEdge("47", "58"); // // var subgraph = new Subgraph("subgraph 1"); // graph.RootSubgraph.AddSubgraph(subgraph); // subgraph.AddNode(graph.FindNode("47")); // subgraph.AddNode(graph.FindNode("58")); // // graph.AddEdge(subgraph.Id, "55"); // // var node = graph.FindNode("5"); // node.LabelText = "Label of node 5"; // node.Label.FontSize = 5; // node.Label.FontName = "New Courier"; // node.Label.FontColor = Microsoft.Msagl.Drawing.Color.Blue; // // node = graph.FindNode("55"); // // // graph.Attr.LayerDirection= LayerDirection.LR; // // graph.LayoutAlgorithmSettings.EdgeRoutingSettings.RouteMultiEdgesAsBundles = true; // //graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.SplineBundling; // //layout the graph and draw it Graph graph = new Graph(); graph.AddEdge("47", "58"); graph.AddEdge("70", "71"); var subgraph = new Subgraph("subgraph1"); graph.RootSubgraph.AddSubgraph(subgraph); subgraph.AddNode(graph.FindNode("47")); subgraph.AddNode(graph.FindNode("58")); var subgraph2 = new Subgraph("subgraph2"); subgraph2.Attr.Color = Color.Black; subgraph2.Attr.FillColor = Color.Yellow; subgraph2.AddNode(graph.FindNode("70")); subgraph2.AddNode(graph.FindNode("71")); subgraph.AddSubgraph(subgraph2); graph.AddEdge("58", subgraph2.Id); graph.Attr.LayerDirection = LayerDirection.LR; graphViewer.Graph = graph; } catch (Exception e) { MessageBox.Show(e.ToString(), "Load Failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
void CreateGraph() { #if DEBUG DisplayGeometryGraph.SetShowFunctions(); #endif Graph graph = new Graph(); graph.AddEdge("47", "58"); graph.AddEdge("70", "71"); var subgraph = new Subgraph("subgraph1"); graph.RootSubgraph.AddSubgraph(subgraph); subgraph.AddNode(graph.FindNode("47")); subgraph.AddNode(graph.FindNode("58")); var subgraph2 = new Subgraph("subgraph2"); subgraph2.Attr.Color = Color.Black; subgraph2.Attr.FillColor = Color.Yellow; subgraph2.AddNode(graph.FindNode("70")); subgraph2.AddNode(graph.FindNode("71")); subgraph.AddSubgraph(subgraph2); graph.AddEdge("58", subgraph2.Id); graph.Attr.LayerDirection = LayerDirection.LR; gViewer.Graph = graph; // Graph graph = new Graph("graph"); // //graph.LayoutAlgorithmSettings=new MdsLayoutSettings(); // gViewer.BackColor = System.Drawing.Color.FromArgb(10, System.Drawing.Color.Red); // // /* // 4->5 //5->7 //7->8 //8->22 //22->24 //*/ // // //int wm = 80; // graph.AddEdge("1", "2"); // graph.AddEdge("1", "3"); // var e = graph.AddEdge("4", "5"); // //e.Attr.Weight *= wm; // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // e = graph.AddEdge("4", "6"); // e.LabelText = "Changing label"; // this.labelToChange = e.Label; // e=graph.AddEdge("7", "8"); // //e.Attr.Weight *= wm; // e.Attr.LineWidth *= 2; // e.Attr.Color = Color.Red; // // graph.AddEdge("7", "9"); // e=graph.AddEdge("5", "7"); // //e.Attr.Weight *= wm; // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // graph.AddEdge("2", "7"); // graph.AddEdge("10", "11"); // graph.AddEdge("10", "12"); // graph.AddEdge("2", "10"); // graph.AddEdge("8", "10"); // graph.AddEdge("5", "10"); // graph.AddEdge("13", "14"); // graph.AddEdge("13", "15"); // graph.AddEdge("8", "13"); // graph.AddEdge("2", "13"); // graph.AddEdge("5", "13"); // graph.AddEdge("16", "17"); // graph.AddEdge("16", "18"); // graph.AddEdge("19", "20"); // graph.AddEdge("19", "21"); // graph.AddEdge("17", "19"); // graph.AddEdge("2", "19"); // graph.AddEdge("22", "23"); // // e=graph.AddEdge("22", "24"); // //e.Attr.Weight *= wm; // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // e = graph.AddEdge("8", "22"); // //e.Attr.Weight *= wm; // e.Attr.Color = Color.Red; // e.Attr.LineWidth *= 2; // // graph.AddEdge("20", "22"); // graph.AddEdge("25", "26"); // graph.AddEdge("25", "27"); // graph.AddEdge("20", "25"); // graph.AddEdge("28", "29"); // graph.AddEdge("28", "30"); // graph.AddEdge("31", "32"); // graph.AddEdge("31", "33"); // graph.AddEdge("5", "31"); // graph.AddEdge("8", "31"); // graph.AddEdge("2", "31"); // graph.AddEdge("20", "31"); // graph.AddEdge("17", "31"); // graph.AddEdge("29", "31"); // graph.AddEdge("34", "35"); // graph.AddEdge("34", "36"); // graph.AddEdge("20", "34"); // graph.AddEdge("29", "34"); // graph.AddEdge("5", "34"); // graph.AddEdge("2", "34"); // graph.AddEdge("8", "34"); // graph.AddEdge("17", "34"); // graph.AddEdge("37", "38"); // graph.AddEdge("37", "39"); // graph.AddEdge("29", "37"); // graph.AddEdge("5", "37"); // graph.AddEdge("20", "37"); // graph.AddEdge("8", "37"); // graph.AddEdge("2", "37"); // graph.AddEdge("40", "41"); // graph.AddEdge("40", "42"); // graph.AddEdge("17", "40"); // graph.AddEdge("2", "40"); // graph.AddEdge("8", "40"); // graph.AddEdge("5", "40"); // graph.AddEdge("20", "40"); // graph.AddEdge("29", "40"); // graph.AddEdge("43", "44"); // graph.AddEdge("43", "45"); // graph.AddEdge("8", "43"); // graph.AddEdge("2", "43"); // graph.AddEdge("20", "43"); // graph.AddEdge("17", "43"); // graph.AddEdge("5", "43"); // graph.AddEdge("29", "43"); // graph.AddEdge("46", "47"); // graph.AddEdge("46", "48"); // graph.AddEdge("29", "46"); // graph.AddEdge("5", "46"); // graph.AddEdge("17", "46"); // graph.AddEdge("49", "50"); // graph.AddEdge("49", "51"); // graph.AddEdge("5", "49"); // graph.AddEdge("2", "49"); // graph.AddEdge("52", "53"); // graph.AddEdge("52", "54"); // graph.AddEdge("17", "52"); // graph.AddEdge("20", "52"); // graph.AddEdge("2", "52"); // graph.AddEdge("50", "52"); // graph.AddEdge("55", "56"); // graph.AddEdge("55", "57"); // graph.AddEdge("58", "59"); // graph.AddEdge("58", "60"); // graph.AddEdge("20", "58"); // graph.AddEdge("29", "58"); // graph.AddEdge("5", "58"); // graph.AddEdge("47", "58"); // // //ChangeNodeSizes(graph); // // //var sls = graph.LayoutAlgorithmSettings as SugiyamaLayoutSettings; // //if (sls != null) // //{ // // sls.GridSizeByX = 30; // // // sls.GridSizeByY = 0; // //} // var subgraph = new Subgraph("subgraph label"); // graph.RootSubgraph.AddSubgraph(subgraph); // subgraph.AddNode(graph.FindNode("47")); // subgraph.AddNode(graph.FindNode("58")); // //layout the graph and draw it // gViewer.Graph = graph; this.propertyGrid1.SelectedObject = graph; }
private void addNode(Graph g, string label) { g.AddNode(label); g.FindNode(label).UserData = new NodeData(); }
private void instantSearch() { //no button, just instant search if (!(comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)) { for (int i = 0; i < textData.getTotalPeople(); i++) { graph.FindNode(textData.getPerson(i)).Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; graph.FindNode(textData.getPerson(i)).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Octagon; } List <string> test = g.SearchPath(comboBox1.SelectedItem.ToString(), comboBox2.SelectedItem.ToString(), method); textBox2.Text = "Nama akun: " + comboBox1.SelectedItem.ToString() + " dan " + comboBox2.SelectedItem.ToString() + "\r\n"; if (test[test.Count - 1] != "") { if (test.Count == 1) { textBox2.Text += ("1st - degree connection\r\n"); } else if (test.Count == 2) { textBox2.Text += ("2nd - degree connection\r\n"); } else if (test.Count == 3) { textBox2.Text += ("3rd - degree connection\r\n"); } else { textBox2.Text += (test.Count + "th - degree connection\r\n"); } for (int i = 0; i < test.Count; i++) { graph.FindNode(test[i]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; if (i == 0) { graph.FindNode(test[i]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue; } textBox2.Text += (test[i]); if (i != test.Count - 1) { textBox2.Text += (" → "); } } graph.FindNode(test[0]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; graph.FindNode(test[test.Count - 1]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; } else { textBox2.Text += ("tidak ada relasi pada kedua akun\r\n"); graph.FindNode(test[0]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue; graph.FindNode(test[test.Count - 2]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(test[0]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; graph.FindNode(test[test.Count - 2]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; } printGraph(); } }
void ProcessPhyloEdges(Graph graph, GeometryGraph msaglGraph) { foreach (Edge e in graph.Edges) { Core.Layout.Node sourceNode = nodeMapping[e.SourceNode]; Core.Layout.Node targetNode = nodeMapping[e.TargetNode]; if (sourceNode == null) { sourceNode = CreateGeometryNode(graph, msaglGraph, graph.FindNode(e.Source), ConnectionToGraph.Connected); nodeMapping[e.SourceNode] = sourceNode; } if (targetNode == null) { targetNode = CreateGeometryNode(graph, msaglGraph, graph.FindNode(e.Target), ConnectionToGraph.Connected); nodeMapping[e.TargetNode] = targetNode; } Core.Layout.Edge msaglEdge = new Prototype.Phylo.PhyloEdge(sourceNode, targetNode); msaglEdge.Weight = e.Attr.Weight; msaglEdge.Separation = e.Attr.Separation; if (e.Attr.ArrowAtSource) { msaglEdge.EdgeGeometry.SourceArrowhead = new Arrowhead {Length = e.Attr.ArrowheadLength}; } if (e.Attr.ArrowAtTarget) { msaglEdge.EdgeGeometry.TargetArrowhead = new Arrowhead {Length = e.Attr.ArrowheadLength}; } msaglGraph.Edges.Add(msaglEdge); msaglEdge.UserData = e; msaglEdge.LineWidth = e.Attr.LineWidth; } }
static Node AddSchemaBox(Hashtable table, string uri, Graph g) { Node b1; if (table.ContainsKey(uri)) { b1 = (Node) table[uri]; } else { // Make sure labels are unique. string baseLabel = GetFileName(uri); string label = baseLabel; int count = 0; Node found = g.FindNode(baseLabel); while (found != null) { count++; label = baseLabel + "(" + count + ")"; found = g.FindNode(label); } b1 = g.AddNode(uri); SetNodeColors(b1); b1.Attr.Shape = Shape.Box; b1.LabelText = label; b1.Attr.XRadius = b1.Attr.YRadius = 2; // rounded box. b1.Attr.LabelMargin = 5; table[uri] = b1; } return b1; }
static Node Dn(Graph g, string s) { return g.FindNode(s); }
public static void DrawArrow(GViewer gLocalViewer, GraphItem nodeId1, GraphItem nodeId2, bool isSelected, Microsoft.Msagl.Drawing.Graph graph, IGraphPath path) { ReportQueryItemPathResult prevItem = null; int index = 1; bool isSelectedEdgeDrawn = false; foreach (ReportQueryItemPathResult item in nodeId1.QueryItem.Paths) { Node sourceNode = graph.FindNode(item.UniqueID); if (sourceNode == null) { sourceNode = new Node(item.UniqueID); if (item.Name.Length > 12) { sourceNode.Label.Text = string.Format("{0}...", item.Name.Substring(0, 6)); } else { sourceNode.Label.Text = item.Name; } graph.AddNode(sourceNode); } GraphItem newItem = new GraphItem(); newItem.Column = nodeId1.Column; newItem.CurrentPathIndex = item.NodeId; newItem.FileName = nodeId1.FileName; newItem.GraphX = nodeId1.GraphX; newItem.GraphY = nodeId1.GraphY; newItem.IsMultiReletions = nodeId1.IsMultiReletions; newItem.IsPrimary = nodeId1.IsPrimary; newItem.IsSelected = nodeId1.IsSelected; newItem.Length = nodeId1.Length; newItem.Line = nodeId1.Line; newItem.Name = nodeId1.Name; newItem.Parent = nodeId1.Parent; newItem.QueryItem = nodeId1.QueryItem; newItem.RelatedTo = nodeId1.RelatedTo; newItem.RelationsFrom = nodeId1.RelationsFrom; sourceNode.UserData = newItem; if (isSelected && item.UniqueID == DrawingHelper.SelectedPathItemUniqueID && !isEdgeSelected) { newItem.IsSelected = true; SetDrawDelegateByNode(sourceNode, NodeTypes.NormalSelected); } else { newItem.IsSelected = false; SetDrawDelegateByNode(sourceNode, NodeTypes.Normal); } if (prevItem != null) { Edge edge = IsEdgeExisted(sourceNode, prevItem.UniqueID); if (edge == null) { edge = graph.AddEdge(prevItem.UniqueID, item.UniqueID); edge.Attr.ArrowheadAtTarget = ArrowStyle.Normal; edge.Attr.ArrowheadLength = 10; edge.Attr.LineWidth = 2; edge.Attr.Weight = 2; path.QueryItemResult = nodeId1.QueryItem; edge.UserData = path; } SetMaxReletions(edge); if (isSelected && ((SelectedNodeUniqueID == nodeId1.UniqueID && !isEdgeSelected) || (IsContainPath(nodeId1.QueryItem.Paths) && isEdgeSelected) || (DrawingHelper.SelectedNodeUniqueID == null) )) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; isSelectedEdgeDrawn = true; } else { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.DarkGray; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; } } prevItem = item; index++; } prevItem = null; index = 1; foreach (ReportQueryItemPathResult item in nodeId2.QueryItem.Paths) { Node sourceNode = graph.FindNode(item.UniqueID); if (sourceNode == null) { sourceNode = new Node(item.UniqueID); if (item.Name.Length > 12) { sourceNode.Label.Text = string.Format("{0}...", item.Name.Substring(0, 6)); } else { sourceNode.Label.Text = item.Name; } graph.AddNode(sourceNode); } GraphItem newItem = new GraphItem(); newItem.Column = nodeId2.Column; newItem.CurrentPathIndex = item.NodeId; newItem.FileName = nodeId2.FileName; newItem.GraphX = nodeId2.GraphX; newItem.GraphY = nodeId2.GraphY; newItem.IsMultiReletions = nodeId2.IsMultiReletions; newItem.IsPrimary = nodeId2.IsPrimary; newItem.IsSelected = nodeId2.IsSelected; newItem.Length = nodeId2.Length; newItem.Line = nodeId2.Line; newItem.Name = nodeId2.Name; newItem.Parent = nodeId2.Parent; newItem.QueryItem = nodeId2.QueryItem; newItem.RelatedTo = nodeId2.RelatedTo; newItem.RelationsFrom = nodeId2.RelationsFrom; sourceNode.UserData = newItem; if (isSelected && item.UniqueID == DrawingHelper.SelectedPathItemUniqueID && !isEdgeSelected) { newItem.IsSelected = true; SetDrawDelegateByNode(sourceNode, NodeTypes.NormalSelected); } else { newItem.IsSelected = false; SetDrawDelegateByNode(sourceNode, NodeTypes.Normal); } if (prevItem != null) { Edge edge = IsEdgeExisted(sourceNode, prevItem.UniqueID); if (edge == null) { edge = graph.AddEdge(prevItem.UniqueID, item.UniqueID); edge.Attr.ArrowheadAtTarget = ArrowStyle.Normal; edge.Attr.ArrowheadLength = 10; path.QueryItemResult = nodeId2.QueryItem; edge.UserData = path; } SetMaxReletions(edge); if (isSelected && ((SelectedNodeUniqueID == nodeId2.UniqueID && !isEdgeSelected) || (IsContainPath(nodeId2.QueryItem.Paths) && isEdgeSelected) || (DrawingHelper.SelectedNodeUniqueID == null) )) { if (!isSelectedEdgeDrawn || isEdgeSelected) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.Black; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; } } else { //if (!isSelectedEdgeDrawn || !isEdgeSelected) if (!isSelectedEdgeDrawn) { edge.Attr.Color = Microsoft.Msagl.Drawing.Color.DarkGray; edge.Attr.Weight = 2; edge.Attr.LineWidth = 2; } } } prevItem = item; index++; } bool isTopNodeFound = false; if (isSelected && ((IsContainPath(nodeId1.QueryItem.Paths) && isEdgeSelected) || (DrawingHelper.SelectedNodeUniqueID == null)) ) { Node firstNode = graph.FindNode(nodeId1.QueryItem.Paths[0].UniqueID); IGraphItem item = firstNode.UserData as IGraphItem; item.IsSelected = true; SetDrawDelegateByNode(firstNode, NodeTypes.NormalSelected); isTopNodeFound = true; SelectedNodeUniqueID = nodeId1.UniqueID; } if (!isTopNodeFound && isSelected && ((IsContainPath(nodeId2.QueryItem.Paths) && isEdgeSelected) || (DrawingHelper.SelectedNodeUniqueID == null)) ) { Node firstNode = graph.FindNode(nodeId2.QueryItem.Paths[0].UniqueID); IGraphItem item = firstNode.UserData as IGraphItem; item.IsSelected = true; SetDrawDelegateByNode(firstNode, NodeTypes.NormalSelected); SelectedNodeUniqueID = nodeId2.UniqueID; } }
public static void _DrawArrow(GViewer gLocalViewer, GraphItem nodeId1, GraphItem nodeId2, bool isSelected, Microsoft.Msagl.Drawing.Graph graph, IGraphPath path) { #region Set node 1 caption bool isNewEdge = false; //Microsoft.Msagl.Drawing.Graph graph = gLocalViewer.Graph; Node sourceNode = graph.FindNode(nodeId1.UniqueID); if (sourceNode == null) { isNewEdge = true; sourceNode = new Node(nodeId1.UniqueID); if (nodeId1.Name.Length > 12) { sourceNode.Label.Text = string.Format("{0}...", nodeId1.Name.Substring(0, 6)); } else { sourceNode.Label.Text = nodeId1.Name; } } #endregion #region Set node 2 caption Node targetNode = graph.FindNode(nodeId2.UniqueID); if (targetNode == null) { isNewEdge = true; targetNode = new Node(nodeId2.UniqueID); if (nodeId2.Name.Length > 12) { targetNode.Label.Text = string.Format("{0}...", nodeId2.Name.Substring(0, 6)); } else { targetNode.Label.Text = nodeId2.Name; } } #endregion #region Set Drawing type GraphItem nodeItem1 = sourceNode.UserData as GraphItem; GraphItem nodeItem2 = targetNode.UserData as GraphItem; sourceNode.UserData = nodeId1; targetNode.UserData = nodeId2; #endregion if (isNewEdge) { graph.AddNode(sourceNode); graph.AddNode(targetNode); if (nodeId1.UniqueID != nodeId2.UniqueID) { Edge edge = graph.AddEdge(nodeId1.UniqueID, nodeId2.UniqueID); edge.UserData = path; } } else { if (!IsNodesConnected(sourceNode, targetNode)) { if (nodeId1.UniqueID != nodeId2.UniqueID) { Edge edge = graph.AddEdge(nodeId1.UniqueID, nodeId2.UniqueID); edge.UserData = path; } } } SetNodeColor(graph, nodeId1, nodeId2, sourceNode, targetNode, isSelected); }
//Constructor 3 public FormGraph(int[,] pipeArray) { InitializeComponent(); 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 = new Microsoft.Msagl.Drawing.Graph("graph"); myGraph = InputControls.getMyGraph(); var minCutPipes = new List <MyPipe>(); for (int i = 0; i < myGraph.Pipes.Count(); i++) { //if (MinCut.getNodeNum(myGraph.Pipes[i].StartingPoint) == pipeList[i, 0] // && MinCut.getNodeNum(myGraph.Pipes[i].EndPoint) == pipeList[i, 1]) //{ // minCutPipes.Add(myGraph.Pipes[i]); //} for (int k = 0; k < pipeArray.GetLength(0); k++) { if (MinCut.getNodeNum(myGraph.Pipes[i].StartingPoint) == pipeArray[k, 0] && MinCut.getNodeNum(myGraph.Pipes[i].EndPoint) == pipeArray[k, 1]) { minCutPipes.Add(myGraph.Pipes[i]); } } } var nodeList = new List <Node>(); //node ekle foreach (var myNode in myGraph.Nodes) { graph.AddNode(new Node(myNode.Name)); } //edge ekle foreach (var myPipe in myGraph.Pipes) { if (myPipe.StartingValue != 0) { if (IsMinCutPipe(myPipe, minCutPipes)) { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.StartingPoint, myPipe.StartingValue.ToString(), myPipe.EndPoint); } } if (myPipe.EndingValue != 0) { if (true) { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } else { graph.AddEdge(myPipe.EndPoint, myPipe.EndingValue.ToString(), myPipe.StartingPoint); } } } string startingPointName = myGraph.Nodes.Where(x => x.IsStartingPoint == true) .Select(x => x.Name).FirstOrDefault(); string endPointName = myGraph.Nodes.Where(x => x.IsEndPoint == true) .Select(x => x.Name).FirstOrDefault(); if (startingPointName != null && endPointName != null) { graph.FindNode(startingPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(startingPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode(endPointName).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(endPointName).Attr.Color = Microsoft.Msagl.Drawing.Color.Red; } viewer.Graph = graph; this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(viewer); this.ResumeLayout(); }