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(); } }
private void Draw(GraphPath <Token, Token> path) { Graph graph = new Graph("Graph"); for (int i = 0; i < graphToken.Nodes.Count; i++) { string str = "Root"; if (graphToken.Nodes[i].Info != null) { str = graphToken.Nodes[i].Info.ToString() + " - " + graphToken.Nodes[i].Id.ToString(); } Node no = graph.AddNode(graphToken.Nodes[i].Name); no.Attr.Shape = Shape.Circle; no.LabelText = str; if (graphToken.Nodes[i].Info != null && graphToken.Nodes[i].Info.RecToken != null) { var color = graphToken.Nodes[i].Info.RecToken.Color; no.Attr.FillColor = new Microsoft.Msagl.Drawing.Color((byte)color.R, (byte)color.G, (byte)color.B); } foreach (var transition in graphToken.Nodes[i].Edges) { Edge arco = graph.AddEdge(graphToken.Nodes[i].Name, transition.Cost.ToString("n2"), 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); if (path != null) { if (path.Nodes.Contains(transition.Destiny) && path.Nodes.Contains(graphToken.Nodes[i])) { arco.Attr.Color = color; } else { arco.Attr.Color = Microsoft.Msagl.Drawing.Color.Gray; } } else { arco.Attr.Color = color; } arco.Attr.AddStyle(Style.Bold); arco.Attr.LineWidth = 5; } } GViewer viewer = new GViewer(); 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); }
private Microsoft.Msagl.Drawing.Color ConvertSystemDrawingToMsaglColor(SoftwareComponent component) { string colorName = component.Color.Name; Type type = typeof(Microsoft.Msagl.Drawing.Color); PropertyInfo property = type.GetProperty(colorName); Microsoft.Msagl.Drawing.Color adaptedColor = (Microsoft.Msagl.Drawing.Color)property.GetValue(null); return(adaptedColor); }
public MainFrom(string connection) : this() { if (!string.IsNullOrEmpty(connection)) { this.connectionString = connection; } oldNode = null; oldFillColor = Microsoft.Msagl.Drawing.Color.White; }
private void HighlightEntity(Object entity, MSAGLColor color, bool reloadLayout = true) { if (entity is Edge) { (entity as Edge).Attr.Color = color; } else if (entity is Node) { (entity as Node).Attr.Color = color; } this.viewer.Invalidate(); }
/// <summary> /// Constructs a NodeTypeEntry with the supplied parameters. /// </summary> /// <param name="name">The name for the node type</param> /// <param name="shape">The initial node shape</param> /// <param name="fillcolor">The initial node fillcolor</param> /// <param name="fontcolor">The initial node fontcolor</param> /// <param name="fontsize">The initial node fontsize</param> /// <param name="userdata">A string which will be copied into the node userdata</param> /// <param name="deflabel">The initial label for the node</param> /// <param name="button">An image which will be used to create a button in the toolbar to insert a node</param> internal NodeTypeEntry(string name, Shape shape, Color fillcolor, Color fontcolor, int fontsize, string userdata, string deflabel, Image button) { Name = name; Shape = shape; FillColor = fillcolor; FontColor = fontcolor; FontSize = fontsize; UserData = userdata; ButtonImage = button; DefaultLabel = deflabel; }
/// <summary> /// Constructs a NodeTypeEntry with the supplied parameters. /// </summary> /// <param name="name">The name for the node type</param> /// <param name="shape">The initial node shape</param> /// <param name="fillcolor">The initial node fillcolor</param> /// <param name="fontcolor">The initial node fontcolor</param> /// <param name="fontsize">The initial node fontsize</param> /// <param name="userdata">A string which will be copied into the node userdata</param> /// <param name="deflabel">The initial label for the node</param> /// <param name="button">An image which will be used to create a button in the toolbar to insert a node</param> public NodeTypeEntry(string name, Shape shape, Microsoft.Msagl.Drawing.Color fillcolor, Microsoft.Msagl.Drawing.Color fontcolor, int fontsize, string userdata, string deflabel, Image button) { Name = name; Shape = shape; FillColor = fillcolor; FontColor = fontcolor; FontSize = fontsize; UserData = userdata; ButtonImage = button; DefaultLabel = deflabel; }
/// <summary> /// /// </summary> /// <param name="text"></param> private void UpdateGraphByQuery(string text) { _graph.Edges.Clear(); PolarionItem[] polarionItems = PolarionItem.GetItemsFromQuery(text); if (polarionItems == null) { _graph.Edges.Clear(); return; } foreach (PolarionItem polarionItem in polarionItems) { if (polarionItem.WorkItem == null) { continue; } foreach (PolarionItem polarionChildItem in polarionItem.Childs) { _graph.AddEdge($"{polarionItem.WorkItem.id}-{polarionItem.WorkItem.title}", $"{polarionChildItem.WorkItem.id}-{polarionChildItem.WorkItem.title}"); Node node = _graph.FindNode($"{polarionChildItem.WorkItem.id}-{polarionChildItem.WorkItem.title}"); node.UserData = polarionChildItem; Color color = Color.White; if (polarionChildItem.WorkItem.type != null) { color = cyclicColorConfiguration.GetColor(polarionChildItem.WorkItem.type.id); } NodeStyle nodeStyle = new NodeStyle(color); nodeStyle.ApplyToNode(node); } Node mainNode = _graph.FindNode($"{polarionItem.WorkItem.id}-{polarionItem.WorkItem.title}"); if (mainNode != null) { mainNode.UserData = polarionItem; } else { //we shouldn't get here normally. } } _gviewer.Graph = null; _gviewer.Graph = _graph; }
private void HighlightCollection <Object>(IEnumerable <Object> collection, MSAGLColor color) { //FreezeGraphLayout(); foreach (Object element in collection) { if (element is Node) { HighlightEntity(this.graph.Nodes.First(n => n.UserData == (element as Node).UserData), color, false); } else if (element is Edge) { HighlightEntity(this.graph.Edges.First(e => e == (element as Edge)), color, false); } } this.viewer.Invalidate(); //ResumeGraphLayout(); }
private void DrawAutoma(AutomaFuzzy.Automa <Symbol> automma) { Graph graph = new Graph("Automa"); //graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.Black; for (int i = 0; i < automma.States.Count; i++) { string str = automma.States[i].ToString(); Node no = graph.AddNode(automma.States[i].Name); no.Attr.Shape = Shape.Box; no.LabelText = str; } foreach (var transition in automma.Transitions) { string symbol = ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule <Symbol>)transition.Rule).Symbol.ToString(); string label = ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule <Symbol>)transition.Rule).Symbol.ToString() + " - " + transition.Rule.Pertinence.ToString(); label = symbol; Edge arco = graph.AddEdge(transition.From.Name, label , transition.To.Name); System.Drawing.Color c = Utils.GetColor(transition.Rule.Pertinence); var color = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B); arco.Attr.Color = color; //arco.Attr.Fontcolor = color; arco.Attr.AddStyle(Style.Bold); arco.Attr.LineWidth = 5; } GViewer viewer = new GViewer(); viewer.NavigationVisible = false; viewer.OutsideAreaBrush = Brushes.White; viewer.ToolBarIsVisible = false; viewer.Graph = graph; viewer.Dock = System.Windows.Forms.DockStyle.Fill; pnlAutoma.Controls.Clear(); pnlAutoma.Controls.Add(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); }
private void DrawAutoma(AutomaFuzzy.Automa<Symbol> automma) { Graph graph = new Graph("Automa"); //graph.GraphAttr.Backgroundcolor = Microsoft.Glee.Drawing.Color.Black; for (int i = 0; i < automma.States.Count; i++) { string str = automma.States[i].ToString(); Node no = graph.AddNode(automma.States[i].Name); no.Attr.Shape = Shape.Box; no.LabelText = str; } foreach (var transition in automma.Transitions) { string symbol = ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule<Symbol>)transition.Rule).Symbol.ToString(); string label = ((CompilerWithFuzzy.AutomaFuzzy.Rules.SimpleIncludeRule<Symbol>)transition.Rule).Symbol.ToString() + " - " + transition.Rule.Pertinence.ToString(); label = symbol; Edge arco = graph.AddEdge(transition.From.Name, label , transition.To.Name); System.Drawing.Color c = Utils.GetColor(transition.Rule.Pertinence); var color = new Microsoft.Msagl.Drawing.Color((byte)c.R, (byte)c.G, (byte)c.B); arco.Attr.Color = color; //arco.Attr.Fontcolor = color; arco.Attr.AddStyle(Style.Bold); arco.Attr.LineWidth = 5; } GViewer viewer = new GViewer(); viewer.NavigationVisible = false; viewer.OutsideAreaBrush = Brushes.White; viewer.ToolBarIsVisible = false; viewer.Graph = graph; viewer.Dock = System.Windows.Forms.DockStyle.Fill; pnlAutoma.Controls.Clear(); pnlAutoma.Controls.Add(viewer); }
/// <summary> /// Paint a path in the graph /// </summary> /// <param name="graph">The graph that contains the path</param> /// <param name="path">The collection of the ids of the nodes on the path</param> /// <param name="color">The color to be painted</param> /// <exception cref="ArgumentException"></exception> public static void PaintPath(this Graph graph, IEnumerable <string> path, Microsoft.Msagl.Drawing.Color color) { var enumerator = path.GetEnumerator(); if (!enumerator.MoveNext()) { return; } var srcId = enumerator.Current; var srcNode = graph.FindNode(srcId); if (srcNode == null) { throw new ArgumentException($"Id \"{srcId}\" doesn't exist in graph"); } string dstId; Node dstNode; while (enumerator.MoveNext()) { dstId = enumerator.Current; dstNode = graph.FindNode(dstId); if (dstNode == null) { throw new ArgumentException($"Node \"{dstId}\" doesn't exist in graph"); } var edge = dstNode.InEdges.FirstOrDefault(edge => edge.Source == srcId); if (edge == default) { throw new ArgumentException($"No edge found between \"{srcId}\" and \"{dstNode}\""); } else { edge.Attr.Color = color; } srcId = dstId; srcNode = dstNode; } }
private void graphViewer_ObjectUnderMouseCursorChanged(object sender, ObjectUnderMouseCursorChangedEventArgs e) { if (graphViewer.SelectedObject != null) { object selectedObject = graphViewer.SelectedObject; if (selectedObject is Node) { if (oldNode != null) { oldNode.Attr.Color = Microsoft.Msagl.Drawing.Color.Blue; oldNode.Attr.FillColor = oldFillColor; } Node selectedNode = (Node)selectedObject; oldFillColor = selectedNode.Attr.FillColor; selectedNode.Attr.Color = Microsoft.Msagl.Drawing.Color.DarkRed; selectedNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightSalmon; int objID = Int32.Parse(selectedNode.Id); try { lvObjectProperties.BeginUpdate(); lvObjectProperties.Items.Clear(); lvObjectProperties.Groups.Clear(); while (objID > 0) { AddObjectDetails(objID); GetParent(objID, out objID); } lvObjectProperties.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); lvObjectProperties.Columns[0].Width += 10; } finally { this.lvObjectProperties.EndUpdate(); } oldNode = selectedNode; graphViewer.Invalidate(); } } }
// ReSharper disable UnusedMethodReturnValue.Local static Edge AddEdge(Hashtable edges, // ReSharper restore UnusedMethodReturnValue.Local Graph g, Node from, Node to, Color color) { var toEdges = edges[from] as Hashtable; if (toEdges == null) { toEdges = new Hashtable(); edges[from] = toEdges; } var e = toEdges[to] as Edge; if (e == null) { e = g.AddEdge(from.Attr.Id, to.Attr.Id); e.Attr.Color = color; toEdges[to] = e; e.Attr.Id = from.Attr.Id + " -> " + to.Attr.Id; } return(e); }
private void addEdges(Graph graph, String src, List <String> edges, int recursionDepth, TreeNode initRoot) { // If a user entered in a html link with a forward slash at the beginning, // it's possible for the site with and without the forward slash to be identified as different sites when in fact // they are the same. So, we'll just remove it if it exists if (src.EndsWith("/")) { src = src.Remove(src.Length - 1); } // Generate random color to use as nodes and edges for this src to aesthetically distinguish them from others Random rand = new Random(); Microsoft.Msagl.Drawing.Color randomColor = new Microsoft.Msagl.Drawing.Color((byte)rand.Next(80, 255), (byte)rand.Next(80, 255), (byte)rand.Next(80, 255)); // Strip http(s):// prefix if user chose to if (chkbox_stripPrefixes.Checked && src.Length > 5) { src = src.Substring(src.IndexOf("://") + 3); } // Add the initial root/src node with the random color from above graph.AddNode(src).Attr.FillColor = randomColor; // Our user has specified a "Recursion Depth" in the gui that corresponds to // how many links after the src we should visit. This means we should // also add the edges and nodes of the initial list of links we have, // and continue until the recursion depth is zero. txt_DisplayLinks.AppendText("\nScraping links from : (" + src + ")\n"); txt_DisplayLinks.AppendText("--------------------------------------\n"); // Iterate through all of the edges in our list foreach (String edge in edges) { // Our users have the option of stripping the prefixes (https:// or http://) from the links, // but if are going to recur on the edges, then we need to keep the initial prefix hanging around // Likewise, we need to do the same for its suffix String sedge = (chkbox_stripPrefixes.Checked && edge.Contains("//") && edge.Length > 5) ? edge.Substring(edge.IndexOf("//") + 2) : edge; if (chkbox_stripSuffixes.Checked) { try { Uri targetURI = new Uri(edge); Console.Write("Found : " + sedge); sedge = targetURI.Host.ToString(); Console.Write("Converted to : " + sedge + '\n'); } catch { // couldn't convert it to a link, so that means it must be some sort of relative path. the predefined sedge is fine } } // append the edge to the logs or display links textbox with a new line // if the site hasn't already been added if (graph.FindNode(sedge) == null) { // Add the edge as a node graph.AddNode(sedge); } // Create an edge from the src to the new edge node, if one does not exist already if (sedge != "" && (chkbox_AllowMultEdges.Checked || !hasEdge(graph, src, sedge))) { // Console.WriteLine("Making edge: " + src + " -> " + sedge); graph.AddEdge(src, sedge).Attr.Color = randomColor; txt_DisplayLinks.AppendText(sedge + '\n'); } // Now that we've added the current node, we are ready to recurse on it if we our depth is greater than or equal to 1, // and if the edge is a valid URI if (recursionDepth >= 1 && edge.StartsWith("http")) { if (chkbox_stripSuffixes.Checked && src.Contains(sedge)) { // we don't want to add any nodes that contain the same domain name since we don't care // about its subpages (local pages) Console.WriteLine("Successfully blocked same domain name node"); } else { // We have to maintain the current "root node" of our tree viewer and pass it along so we can append nodes to it TreeNode recursiveRoot = new TreeNode(sedge); initRoot.Nodes.Add(recursiveRoot); addEdges(graph, edge, retrieveLinks(edge, chkbox_excludeLocal.Checked), recursionDepth - 1, recursiveRoot); } } else { // Leaves, we don't recurse on 0 recursion depth initRoot.Nodes.Add(new TreeNode(sedge)); } } }
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(); } }
public override Graph ToMicrosoftGraph(ITheme theme, FontSettings font) { var newGraph = CreateEmptyGraph(); Color textColor = theme.GetColor(ColorType.Text).Foreground is SolidColorBrush sb ? BrushToColor(sb) : theme.IsDark ? Color.LightGray : Color.DarkGray; Color fillColor = theme.GetColor(ColorType.Text).Background is SolidColorBrush sb2 ? BrushToColor(sb2) : theme.IsDark ? Color.Black : Color.White; Color green = theme.GetColor(ColorType.Green).Foreground is SolidColorBrush sb3 ? BrushToColor(sb3) : Color.Green; Color red = theme.GetColor(ColorType.Red).Foreground is SolidColorBrush sb4 ? BrushToColor(sb4) : Color.Red; Color gray = theme.GetColor(ColorType.Gray).Foreground is SolidColorBrush sb5 ? BrushToColor(sb5) : Color.Gray; foreach (var node in graph.Nodes) { var newNode = new Node(getId(node)) { LabelText = GetBlockText(node.Contents), Attr = { FillColor = fillColor, LabelMargin = 4, }, Label = { FontColor = textColor, FontName = font.FontFamily.ToString(), FontSize = font.FontSize, }, UserData = node.Id, }; newGraph.AddNode(newNode); } foreach (var edge in graph.GetEdges()) { var newEdge = newGraph.AddEdge(getId(edge.Origin), getId(edge.Target)); newEdge.Attr.Color = edge.Type switch { ControlFlowEdgeType.Abnormal => gray, ControlFlowEdgeType.FallThrough when edge.Origin.ConditionalEdges.Count > 0 => red, ControlFlowEdgeType.Conditional => green, ControlFlowEdgeType.FallThrough => textColor, ControlFlowEdgeType.None => throw new InvalidOperationException("Found a None node in control flow graph, Echo bug?"), _ => throw new IndexOutOfRangeException("Unknown edge type: " + edge.Type), }; } return(newGraph);
/// <summary> /// Constructs a NodeTypeEntry with the supplied parameters. /// </summary> /// <param name="name">The name for the node type</param> /// <param name="shape">The initial node shape</param> /// <param name="fillcolor">The initial node fillcolor</param> /// <param name="fontcolor">The initial node fontcolor</param> /// <param name="fontsize">The initial node fontsize</param> /// <param name="userdata">A string which will be copied into the node userdata</param> /// <param name="deflabel">The initial label for the node</param> internal NodeTypeEntry(string name, Shape shape, Color fillcolor, Color fontcolor, int fontsize, string userdata, string deflabel) : this(name, shape, fillcolor, fontcolor, fontsize, userdata, deflabel, null) { }
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 void SelectEdge(State from, State to) { var edge = Graph.FindEdge(from, to); memoryColor = edge.Attr.Color; edge.Attr.Color = selectColor; }
private void SimulatorViewer_SelectionChanged(object sender, EventArgs e) { lock (this) { string tooltipstring; if (selectedObject != null) { if (selectedObject is Edge) { Edge edge = (selectedObject as Edge); edge.Attr = selectedObjectAttr as EdgeAttr; if (edge.Label != null) { edge.Label.FontColor = selectedObjectColor; } } else if (selectedObject is Node) { (selectedObject as Node).Attr = selectedObjectAttr as NodeAttr; (selectedObject as Node).Label.FontColor = selectedObjectColor; } selectedObject = null; } if (SimulatorViewer.SelectedObject == null) { tooltipstring = ""; //label1.Text = "No object under the mouse"; //this.SimulatorViewer.SetToolTip(ToolTip_Graph, ""); //ToolTip_Graph.Show("", SimulatorViewer, Cursor.Position, 20000); ToolTip_Graph.Hide(SimulatorViewer); } else { selectedObject = SimulatorViewer.SelectedObject; if (selectedObject is Edge) { Edge selectedEdge = SimulatorViewer.SelectedObject as Edge; selectedObjectAttr = selectedEdge.Attr.Clone(); selectedEdge.Attr.Color = Color.Blue; if (selectedEdge.Label != null) { selectedObjectColor = selectedEdge.Label.FontColor; selectedEdge.Label.FontColor = Color.Blue; } //here you can use e.Attr.Id or e.UserData to get back to you data //this.SimulatorViewer.SetToolTip(this.ToolTip_Graph, String.Format("edge " + selectedEdge.LabelText + " from {0} to {1}", selectedEdge.SourceNode.LabelText == "" ? "init" : selectedEdge.SourceNode.LabelText, selectedEdge.TargetNode.LabelText)); //String.Format("edge", selectedEdge.SourceNode.UserData, selectedEdge.TargetNode.UserData)); Point p = System.Windows.Forms.Control.MousePosition; Point q = SimulatorViewer.PointToScreen(new Point(0, 0)); p.X = p.X - q.X + 15; p.Y = p.Y - q.Y + 15; ToolTip_Graph.Show( String.Format("edge " + selectedEdge.LabelText + " from {0} to {1}", selectedEdge.SourceNode.LabelText == "" ? "init" : selectedEdge.SourceNode.LabelText, selectedEdge.TargetNode.LabelText), SimulatorViewer, p, ToolTipDisplayTime); } else if (selectedObject is Node) { Node selectedNode = SimulatorViewer.SelectedObject as Node; selectedObjectAttr = selectedNode.Attr.Clone(); selectedObjectColor = selectedNode.Label.FontColor; if (selectedNode != null && selectedNode.Id != INITIAL_STATE) { selectedNode.Attr.Color = Color.Blue; selectedNode.Label.FontColor = Color.Blue; //here you can use e.Attr.Id to get back to your data //this.SimulatorViewer.SetToolTip(this.ToolTip_Graph, String.Format("node {0}", selectedNode.UserData)); Point p = System.Windows.Forms.Control.MousePosition; Point q = SimulatorViewer.PointToScreen(new Point(0, 0)); p.X = p.X - q.X + 15; p.Y = p.Y - q.Y + 15; //here you can use e.Attr.Id to get back to your data //this.SimulatorViewer.SetToolTip(this.ToolTip_Graph, String.Format("node {0}", selectedNode.UserData)); ToolTip_Graph.Show(String.Format("{0}", selectedNode.UserData), SimulatorViewer, p, ToolTipDisplayTime); //ToolTip_Graph.Show(String.Format("node {0}", selectedNode.UserData), SimulatorViewer, System.Windows.Forms.Control.MousePosition, ToolTipDisplayTime); } } } SimulatorViewer.Invalidate(); } }
/// <summary> /// Constructs a NodeTypeEntry with the supplied parameters. /// </summary> /// <param name="name">The name for the node type</param> /// <param name="shape">The initial node shape</param> /// <param name="fillcolor">The initial node fillcolor</param> /// <param name="fontcolor">The initial node fontcolor</param> /// <param name="fontsize">The initial node fontsize</param> /// <param name="userdata">A string which will be copied into the node userdata</param> /// <param name="deflabel">The initial label for the node</param> public NodeTypeEntry(string name, Shape shape, Microsoft.Msagl.Drawing.Color fillcolor, Microsoft.Msagl.Drawing.Color fontcolor, int fontsize, string userdata, string deflabel) : this(name, shape, fillcolor, fontcolor, fontsize, userdata, deflabel, null) { }
public Tuple <int, Dictionary <Edge, MSAGLColor> > Execute(DGraph graph) { Tuple <int, Dictionary <Edge, MSAGLColor> > result; Dictionary <Edge, MSAGLColor> edgeColorMap = new Dictionary <Edge, MSAGLColor>(); var independentSets = FindIndependentSets(graph); List <Tuple <byte, byte, byte> > usedColors = new List <Tuple <byte, byte, byte> >(); Random rand = new Random(); Tuple <byte, byte, byte> randomColor; foreach (List <Node> set in independentSets) { foreach (Node n in set) { foreach (Edge nEdge in n.Edges) { do { randomColor = new Tuple <byte, byte, byte>((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255)); } while (usedColors.Contains(randomColor)); MSAGLColor currentColor = new MSAGLColor(randomColor.Item1, randomColor.Item2, randomColor.Item3); if (!edgeColorMap.ContainsKey(nEdge)) { edgeColorMap.Add(nEdge, currentColor); usedColors.Add(randomColor); } else { currentColor = edgeColorMap[nEdge]; } foreach (Node m in set) { if (n != m) { Edge mEdge = null; try { mEdge = m.Edges.First(edge => !edgeColorMap.ContainsKey(edge) && !nEdge.isAdjasentTo(edge)); } catch { } finally { if (mEdge != null && edgeColorMap.Count(pair => nEdge.isAdjasentTo(mEdge)) == 0 && edgeColorMap.Count(pair => pair.Key.isAdjasentTo(mEdge) && pair.Value == currentColor) == 0) { edgeColorMap.Add(mEdge, currentColor); } } } } } } } var remainingEdges = graph.Edges.Where(edge => !edgeColorMap.ContainsKey(edge)); foreach (Edge e in remainingEdges) { do { randomColor = new Tuple <byte, byte, byte>((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255)); } while (usedColors.Contains(randomColor)); usedColors.Add(randomColor); edgeColorMap.Add(e, new MSAGLColor(randomColor.Item1, randomColor.Item2, randomColor.Item3)); } result = new Tuple <int, Dictionary <Edge, MSAGLColor> >(usedColors.Count, edgeColorMap); return(result); }
public static void ParseFields(this Graph graph, User user, Func <User, List <string> > dataType, double threshold, Color edgeColor, int possibleReplaces = 0) { foreach (User friend in user.Friends) { var fieldValues = friend.Friends .SelectMany(dataType) .GroupBy(x => x) .Select(g => new { Name = g.Key, Count = g.Count() }) .OrderByDescending(x => x.Count) .ToList(); if (!fieldValues.Any()) { continue; } int sum = fieldValues.Select(x => x.Count).Sum(); if (dataType(friend).Count <= possibleReplaces && fieldValues.First().Count > sum * threshold) { friend.WasEdited = true; dataType(friend).Add(fieldValues.First().Name); } } AddNode(graph, user); foreach (User friend in user.Friends) { Node node = AddNode(graph, friend); string theirCommonField = dataType(friend).Intersect(dataType(user)).LastOrDefault(); if (theirCommonField != null) { Edge edge = graph.AddEdge(user.Name, friend.Name); edge.Attr.ArrowheadAtTarget = ArrowStyle.None; edge.Attr.LineWidth = 3; edge.Attr.Color = edgeColor; ++friend.Multiplexity; } } foreach (User friend in user.Friends) { foreach (User friendsFriend in friend.Friends) { Node node = graph.FindNode(friendsFriend.Name); if (!node.InEdges.Any(x => x.Source == friend.Name && x.Attr.Color == edgeColor)) { string theirCommonField = dataType(friend).Intersect(dataType(friendsFriend)).LastOrDefault(); if (theirCommonField != null) { Edge edge = graph.AddEdge(friendsFriend.Name, friend.Name); edge.Attr.LineWidth = 3; edge.Attr.ArrowheadAtTarget = ArrowStyle.None; edge.Attr.Color = edgeColor; } } } } }
// ReSharper disable UnusedMethodReturnValue.Local static Edge AddEdge(Hashtable edges, // ReSharper restore UnusedMethodReturnValue.Local Graph g, Node from, Node to, Color color) { var toEdges = edges[from] as Hashtable; if (toEdges == null) { toEdges = new Hashtable(); edges[from] = toEdges; } var e = toEdges[to] as Edge; if (e == null) { e = g.AddEdge(from.Attr.Id, to.Attr.Id); e.Attr.Color = color; toEdges[to] = e; e.Attr.Id = from.Attr.Id + " -> " + to.Attr.Id; } return e; }
static public System.Drawing.Color MsaglColorToDrawingColor(Microsoft.Msagl.Drawing.Color gleeColor) { return(System.Drawing.Color.FromArgb(gleeColor.A, gleeColor.R, gleeColor.G, gleeColor.B)); }
/// <summary> /// Overloaded. Adds a new node type to the list. If the parameters contain an image, a button with that image will be added to the toolbar. /// </summary> /// <param name="name">The name for the new node type</param> /// <param name="shape">The initial node shape</param> /// <param name="fillcolor">The initial node fillcolor</param> /// <param name="fontcolor">The initial node fontcolor</param> /// <param name="fontsize">The initial node fontsize</param> /// <param name="userdata">A string which will be copied into the node userdata</param> /// <param name="deflabel">The initial node label</param> internal void AddNodeType(string name, Shape shape, Color fillcolor, Color fontcolor, int fontsize, string userdata, string deflabel) { AddNodeType(new NodeTypeEntry(name, shape, fillcolor, fontcolor, fontsize, userdata, deflabel)); }
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(); }
/// <summary> /// Function to Add and Edge to the Graph (Only if it doesn't already Exist) /// Assigns to user Data and Attributes to Target /// </summary> /// <param name="sourceID"></param> /// <param name="targetID"></param> /// <param name="nodeColor"></param> /// <param name="userData"></param> private Boolean AE(Graph g, List <DrawingEdge> edgeList, String sourceID, String targetID, DrawingColor nodeColor, object userData) { //Search for Edge in allEdgesMaster before adding it. bool isUnique = true; // Add by default foreach (DrawingEdge item in edgeList) { if (item.Source == sourceID && item.Target == targetID) { isUnique = false; break; } } if (isUnique) { //Create an edge DrawingEdge edge = new DrawingEdge(sourceID, null, targetID); edgeList.Add(edge); // Add edge to list for keeping Unique Edges g.AddEdge(sourceID, targetID).Attr.Color = nodeColor; //Add Edge //FN(g, sourceID).Attr.FillColor = nodeColor; //FN(g, sourceID).UserData = userData; FN(g, targetID).Attr.FillColor = nodeColor; FN(g, targetID).UserData = userData; } return(isUnique); }