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; } }
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; } }
private static GeometryGraph FillPhyloTree(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { ProcessGraphAttrs(graph, msaglGraph); ProcessNodes(graph, msaglGraph); ProcessPhyloEdges(graph, msaglGraph); return(msaglGraph); }
private static void ProcessNodes(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { foreach (Node n in graph.NodeMap.Values) { Microsoft.Msagl.Node msaglNode = msaglGraph.FindNode(n.Id); if (msaglNode == null) { msaglNode = CreateGeometryNode(msaglGraph, n, Connection.Connected); } else { msaglGraph.NodeMap[msaglNode.Id] = msaglNode; } } }
/// <summary> /// a helper function creating a geometry node /// </summary> /// <param name="graph"></param> /// <param name="node"></param> /// <param name="connection">controls if the node is connected to the graph</param> /// <returns></returns> public static Microsoft.Msagl.Node CreateGeometryNode(Microsoft.Msagl.GeometryGraph graph, Node node, Connection connection) { Microsoft.Msagl.Node geomNode = new Microsoft.Msagl.Node(node.Id, null); if (connection == Connection.Connected) { graph.AddNode(geomNode); } if (node.Label != null) { geomNode.Label = node.Label.GeometryLabel; if (geomNode.Label != null) { geomNode.Label.Parent = geomNode; } } geomNode.UserData = node; geomNode.Padding = node.Attr.Padding; return(geomNode); }
private static void ProcessGraphAttrs(Graph graph, Microsoft.Msagl.GeometryGraph msaglGraph) { msaglGraph.LayoutAlgorithmSettings = graph.LayoutAlgorithmSettings; msaglGraph.Margins = graph.Attr.Margin; msaglGraph.NodeSeparation = graph.Attr.NodeSeparation; msaglGraph.LayerSeparation = graph.Attr.LayerSeparation; msaglGraph.AspectRatio = graph.attr.AspectRatio; switch (graph.Attr.LayerDirection) { case LayerDirection.None: case LayerDirection.TB: break; case LayerDirection.LR: msaglGraph.Transformation = Microsoft.Msagl.Splines.PlaneTransformation.Rotation(Math.PI / 2); if (msaglGraph.AspectRatio != 0) { msaglGraph.AspectRatio = 1 / msaglGraph.AspectRatio; } break; case LayerDirection.RL: msaglGraph.Transformation = Microsoft.Msagl.Splines.PlaneTransformation.Rotation(-Math.PI / 2); if (msaglGraph.AspectRatio != 0) { msaglGraph.AspectRatio = 1 / msaglGraph.AspectRatio; } break; case LayerDirection.BT: msaglGraph.Transformation = Microsoft.Msagl.Splines.PlaneTransformation.Rotation(Math.PI); break; default: throw new InvalidOperationException(); //"unexpected layout direction"); } }
static internal Microsoft.Msagl.GeometryGraph Create(Graph graph) { Microsoft.Msagl.GeometryGraph msaglGraph = new Microsoft.Msagl.GeometryGraph(); return(FillGraph(graph, msaglGraph)); }
private static bool CustomDrawNode(Microsoft.Msagl.Drawing.Node node, object graphics, NodeTypes nodeType) { try { double width = 110; double height = 40; Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph(); GeomNode geomCreek = new Microsoft.Msagl.Node(node.Id, Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center)); node.Attr.GeometryNode.BoundaryCurve = Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center); Graphics g = (Graphics)graphics; MemoryStream ms = new MemoryStream(); switch (nodeType) { case NodeTypes.Normal: CxViewerResources.NormalNode.Save(ms, ImageFormat.Png); break; case NodeTypes.NormalSelected: CxViewerResources.NormalSelected.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitions: CxViewerResources.MultiRelaitions.Save(ms, ImageFormat.Png); break; case NodeTypes.MultiRelaitionsSelected: CxViewerResources.MultiRelaitionsSelected.Save(ms, ImageFormat.Png); break; } System.Drawing.Image image = System.Drawing.Image.FromStream(ms); //flip the image around its center using (System.Drawing.Drawing2D.Matrix m = g.Transform) { using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) { float c = (float)node.Attr.GeometryNode.Center.Y; using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c)) m.Multiply(m2); g.Transform = m; g.SetClip(FillTheGraphicsPath(node.Attr.GeometryNode.BoundaryCurve)); g.DrawImage(image, new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2))); Font myFont = new System.Drawing.Font("Helvetica", 10, System.Drawing.FontStyle.Italic); System.Drawing.Brush myBrush = new SolidBrush(System.Drawing.Color.Blue); Rectangle rectString = new Rectangle(Convert.ToInt32(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), Convert.ToInt32(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2), Convert.ToInt32(width), Convert.ToInt32(height)); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(node.Label.Text, myFont, myBrush, rectString, stringFormat // new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - 5)) ); g.Transform = saveM; } } } catch (Exception err) { Common.Logger.Create().Error(err.ToString()); } return(true);//returning false would enable the default rendering }