public ICurve GetNodeBoundary(DrawingNode node) { double width = treeImage.Width / 2.0; double height = treeImage.Height / 2.0; return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new Point())); }
static Graph CtreateDrawingGraph(out FastIncrementalLayoutSettings settings) { settings = new FastIncrementalLayoutSettings { RouteEdges = true, NodeSeparation = 30 }; var drawingGraph = new Graph(); AddEdge(drawingGraph, "0", "1"); AddEdge(drawingGraph, "0", "2"); AddEdge(drawingGraph, "1", "3"); AddEdge(drawingGraph, "2", "4"); AddEdge(drawingGraph, "2", "5"); AddEdge(drawingGraph, "2", "6"); AddEdge(drawingGraph, "5", "7"); AddEdge(drawingGraph, "5", "6"); AddEdge(drawingGraph, "7", "8"); AddEdge(drawingGraph, "8", "6"); drawingGraph.CreateGeometryGraph(); foreach (DrawingNode node in drawingGraph.Nodes) { double w, h; var label = node.Label; var font = new Font(label.FontName, (float)label.FontSize); StringMeasure.MeasureWithFont(label.Text, font, out w, out h); node.Label.Width = w; node.Label.Height = h; node.Attr.Shape = Shape.DrawFromGeometry; node.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(1.2 * w, 1.2 * h, 3, 3, new Point()); } return(drawingGraph); }
private static ICurve GetRandomShape(Random random) { //we support rectangle, roundedRectangle, circle, ellipse, diamond, Octagon, triangle, star int index = random.Next(8); switch (index) { case 0: return(CurveFactory.CreateRectangle(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 1: return(CurveFactory.CreateRectangleWithRoundedCorners(35, 25, 3, 3, new Microsoft.Msagl.Core.Geometry.Point())); case 2: return(CurveFactory.CreateCircle(19, new Microsoft.Msagl.Core.Geometry.Point())); case 3: return(CurveFactory.CreateEllipse(26, 18, new Microsoft.Msagl.Core.Geometry.Point())); case 4: return(CurveFactory.CreateDiamond(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 5: return(CurveFactory.CreateOctagon(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 6: return(CurveFactory.CreateInteriorTriangle(30, 20, new Microsoft.Msagl.Core.Geometry.Point())); case 7: return(CurveFactory.CreateStar(33, new Microsoft.Msagl.Core.Geometry.Point())); } return(null); }
public void DoubleEdge() { #if TEST_MSAGL GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif var g = new GeometryGraph(); var a = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 20, 20, 3, 3, new Point(0, 0)) }; g.Nodes.Add(a); var b = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 20, 20, 3, 3, new Point(0, 200)) }; g.Nodes.Add(b); var e = new Edge(a, b); g.Edges.Add(e); e = new Edge(a, b); g.Edges.Add(e); var sr = new SplineRouter(g, 2, 4, Math.PI / 6); sr.Run(); #if TEST_MSAGL // GraphViewerGdi.DisplayGeometryGraph.ShowGraph(g); GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif }
static Node SetNode( GeometryGraph g, string id, double xRad, double yRad) { var geomNode = g.FindNodeByUserData(id); if (geomNode == null) { g.Nodes.Add(geomNode = new Node() { UserData = id }); } var size = MeasureTextSize(id); geomNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( size.Width, size.Height, xRad, yRad, new Point(0, 0) ); return(geomNode); }
static void Main(string[] args) { var drawingGraph = new Graph(); drawingGraph.AddNode("A").LabelText = "AText"; drawingGraph.AddNode("B").LabelText = "BText"; var e = drawingGraph.AddEdge("A", "B"); // now the drawing graph has nodes A,B and and an edge A -> B\ // the geometry graph is still null, so we are going to create it e.LabelText = "from " + e.SourceNode.LabelText + " to " + e.TargetNode.LabelText; drawingGraph.CreateGeometryGraph(); // Now the drawing graph elements point to the corresponding geometry elements, // however the node boundary curves are not set. // Setting the node boundaries foreach (var n in drawingGraph.Nodes) { // Ideally we should look at the drawing node attributes, and figure out, the required node size // I am not sure how to find out the size of a string rendered in SVG. Here, we just blindly assign to each node a rectangle with width 60 and height 40, and round its corners. n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(60, 40, 3, 2, new Point(0, 0)); } AssignLabelsDimensions(drawingGraph); LayoutHelpers.CalculateLayout(drawingGraph.GeometryGraph, new SugiyamaLayoutSettings(), null); PrintSvgAsString(drawingGraph); }
ICurve GetNodeBoundaryCurve(DrawingNode node) { double width = 0; double height = 0; if (graphObjectsToFrameworkElements.ContainsKey(node)) { FrameworkElement fe = graphObjectsToFrameworkElements[node]; if (fe == null) { return(CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 1, 1, new Point())); } width = fe.Width + 2 * node.Attr.LabelMargin; height = fe.Height + 2 * node.Attr.LabelMargin; } else { return(CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 5, 5, new Point())); } if (width < drawingGraph.Attr.MinNodeWidth * 2) { width = drawingGraph.Attr.MinNodeWidth * 2; } if (height < drawingGraph.Attr.MinNodeHeight * 2) { height = drawingGraph.Attr.MinNodeHeight * 2; } return(NodeBoundaryCurves.GetNodeBoundaryCurve(node, width, height)); }
ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node node) { Image image = ImageOfNode(node); double width = image.Width; double height = image.Height; return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new MSAGLPoint())); }
/// <summary> /// a helper function to creat a node boundary curve /// </summary> /// <param name="node">the node</param> /// <param name="width">the node width</param> /// <param name="height">the node height</param> /// <returns></returns> public static ICurve GetNodeBoundaryCurve(Node node, double width, double height) { if (node == null) { throw new InvalidOperationException(); } NodeAttr nodeAttr = node.Attr; switch (nodeAttr.Shape) { case Shape.Ellipse: case Shape.DoubleCircle: return(CurveFactory.CreateEllipse(width, height, new P2(0, 0))); case Shape.Circle: { double r = Math.Max(width / 2, height / 2); return(CurveFactory.CreateEllipse(r, r, new P2(0, 0))); } case Shape.Box: if (nodeAttr.XRadius != 0 || nodeAttr.YRadius != 0) { return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, nodeAttr.XRadius, nodeAttr.YRadius, new P2(0, 0))); } return(CurveFactory.CreateRectangle(width, height, new P2(0, 0))); case Shape.Diamond: return(CurveFactory.CreateDiamond( width, height, new P2(0, 0))); case Shape.House: return(CurveFactory.CreateHouse(width, height, new P2())); case Shape.InvHouse: return(CurveFactory.CreateInvertedHouse(width, height, new P2())); case Shape.Hexagon: return(CurveFactory.CreateHexagon(width, height, new P2())); case Shape.Octagon: return(CurveFactory.CreateOctagon(width, height, new P2())); #if DEBUG case Shape.TestShape: return(CurveFactory.CreateTestShape(width, height)); #endif default: { // Console.WriteLine("creating ellipse for shape {0}",nodeAttr.Shape); return(new Ellipse( new P2(width / 2, 0), new P2(0, height / 2), new P2())); } } }
/// <summary> /// Compute the size of the block /// </summary> /// <param name="node"></param> /// <returns></returns> public ICurve GetNodeBoundary(Node node) { const double radiusRatio = 0.3; var extent = Layout.CalculateExtent(); double height = extent.Height; double width = extent.Width; return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new P2())); }
/// <summary> /// The rectangular hull of all the points of all the nodes in the cluster, as set by /// ProjectionSolver.Solve(). /// Note: This rectangle may not originate at the barycenter. Drawing uses only the results /// of this function; the barycenter is used only for gravity computations. /// </summary> /// <returns></returns> public ICurve RectangularHull() { Debug.Assert(rectangle.Bottom <= rectangle.Top); if (RadiusX > 0 || RadiusY > 0) { return(CurveFactory.CreateRectangleWithRoundedCorners(rectangle.Width, rectangle.Height, RadiusX, RadiusY, rectangle.Center)); } else { return(CurveFactory.CreateRectangle(rectangle.Width, rectangle.Height, rectangle.Center)); } }
private void CreateBoundaryCurve(Microsoft.Msagl.Drawing.Node node) { double w, h; var label = node.Label; var font = new Font(label.FontName, (float)label.FontSize); StringMeasure.MeasureWithFont(label.Text, font, out w, out h); node.Label.Width = w; node.Label.Height = h; node.Attr.Shape = Shape.DrawFromGeometry; node.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(1.2 * w, 1.2 * h, 3, 3, new Microsoft.Msagl.Core.Geometry.Point()); }
/// <summary> /// Code Copied from GraphEditor.cs in automatic-graph-layout\graphlayout\samples\editing\grapheditor.cs /// Modified to allow an image to be considered on the left side of the Node and still have space for the Label Text /// </summary> /// <param name="node"></param> /// <returns></returns> ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node node) { int ImagePadding = 4; Graphics g = this.CreateGraphics(); Image image = getGroupImage(node.UserData); // Just a sample Image //Image image = ImageOfNode(node); Font f = new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle); double width = image.Width + g.MeasureString(node.LabelText, f).Width + ImagePadding; double height = image.Height + ImagePadding;// + 30; return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * .02, width * .02, new P2())); //return CurveFactory.CreateRectangleWithRoundedCorners( width, height, width * radiusRatio, height * radiusRatio, new P2()); }
public void OneEdgeWithTwoObstacles() { #if TEST_MSAGL GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); #endif var g = new GeometryGraph(); var a = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 20, 20, 3, 3, new Point(0, 0)) }; g.Nodes.Add(a); var b = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 40, 20, 3, 3, new Point(-10, 200)) }; g.Nodes.Add(b); var c = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 60, 20, 3, 3, new Point(35, 170)) }; g.Nodes.Add(c); var d = new Node { BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners( 20, 20, 3, 3, new Point(0, 270)) }; g.Nodes.Add(d); var e = new Edge(a, d); g.Edges.Add(e); var sr = new SplineRouter(g, 2, 4, Math.PI / 6); sr.Run(); #if TEST_MSAGL GraphViewerGdi.DisplayGeometryGraph.ShowGraph(g); #endif }
private static void SetNodeBoundary(Microsoft.Msagl.Drawing.Node drawingNode) { var font = new System.Drawing.Font(drawingNode.Label.FontName, (float)drawingNode.Label.FontSize); StringMeasure.MeasureWithFont(drawingNode.LabelText, font, out double width, out double height); drawingNode.Label.GeometryLabel = new Microsoft.Msagl.Core.Layout.Label(); drawingNode.Label.GeometryLabel.Width = width; drawingNode.Label.GeometryLabel.Height = width; drawingNode.Label.Width = width; drawingNode.Label.Height = height; int r = drawingNode.Attr.LabelMargin; drawingNode.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point()); }
static ICurve CreateLabelAndBoundary(Node node) { node.Attr.Shape = Shape.DrawFromGeometry; node.Attr.LabelMargin *= 2; double width; double height; StringMeasure.MeasureWithFont(node.Label.Text, new Font(node.Label.FontName, (float)node.Label.FontSize), out width, out height); node.Label.Width = width; node.Label.Height = height; int r = node.Attr.LabelMargin; return(CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point())); }
static ICurve GetRandomShape(Random random) { //we support rectangle, roundedRectangle, circle, ellipse, diamond, Octagon, triangle, star int index = random.Next(3); var center = new Microsoft.Msagl.Core.Geometry.Point(); switch (index) { case 0: return(CurveFactory.CreateRectangle(20 + random.Next(10), 10 + random.Next(10), center)); case 1: return(CurveFactory.CreateRectangleWithRoundedCorners(30 + random.Next(10), 20 + random.Next(10), 1 + random.Next(8), 1 + random.Next(8), center)); case 2: return(CurveFactory.CreateEllipse(26, 18, center)); } return(null); }
private Node CreateUserNode(string user) { Node node; if (userNodes.TryGetValue(user, out node)) { Debug.LogError("Node " + user + " already exists"); return(node); } var info = new GameEventNodeInfo(user) { type = NodeType.User, color = Color.black }; ICurve curve = CurveFactory.CreateRectangleWithRoundedCorners(info.baseSize.x, info.baseSize.y, nodeRadii.x, nodeRadii.y, new Point()); //ICurve curve = CurveFactory.CreateDiamond(info.baseSize.x, info.baseSize.y, new Point()); // ICurve curve = CurveFactory.CreateRectangle(info.baseSize.x, info.baseSize.y, new Point()); node = new Node(curve, info); userNodes.Add(user, node); graph.Nodes.Add(node); return(node); }
static ICurve CreateCurveAt(double x, double y, double size) { return(CurveFactory.CreateRectangleWithRoundedCorners(size, size, size / 10, size / 10, new Point(x, y))); }
public static ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node n) { double cell = s_random.Next(50, 80); double ecc = (((double)s_random.Next(20, 100) / 100.00) * cell); switch (n.Id.Split()[0]) { case "Rhombus": return(CurveFactory.CreateDiamond(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Circle": return(CurveFactory.CreateCircle(cell / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Ellipse": return(CurveFactory.CreateEllipse(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Rectangle": return(CurveFactory.CreateRectangle(cell, ecc, new Point())); case "Parallelogram": { ICurve baseRect = CurveFactory.CreateRectangle(cell, ecc, new Point()); return(baseRect.Transform(new PlaneTransformation(1, (double)s_random.Next(0, 100) / 100.00, 0, 0, 1, 0))); } case "CurvedRectangle": return(CurveFactory.CreateRectangleWithRoundedCorners(cell * 2, ecc, ecc / 4, ecc / 4, new Microsoft.Msagl.Core.Geometry.Point())); case "Process": { Curve curve = (Curve)CurveFactory.CreateRectangle(cell * 2, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve curveInner = (Curve)CurveFactory.CreateRectangle(cell * 1.5, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve.CloseCurve(curve); Curve.CloseCurve(curveInner); Curve.AddLineSegment(curve, curve.Start, curveInner.Start); curve.AddSegment(curveInner); return(curve); } case "ElongatedEllipse": { var curve = new Curve(); double x = cell; double y = ecc; double r = x / 2; curve.AddSegment(new Ellipse(1.5 * Math.PI, 2.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(x, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, y))); curve.AddSegment(new Ellipse(0.5 * Math.PI, 1.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(-1 * x, 0))); Curve.CloseCurve(curve); return(curve); } case "Database": { var curve = new Curve(); double x = ecc; double y = cell; double r = y / 2; curve.AddSegment(new Ellipse(new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new Ellipse(0, Math.PI, new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, -1 * y))); curve.AddSegment(new LineSegment(curve.End, new Point(x, -1 * y))); Curve.CloseCurve(curve); return(curve); } } throw new Exception("unrecognised shape type"); }
internal static GeometryGraph FlatGraph(GeometryGraph graph) { // it is a new graph with clusters replaced by nodes and edges connecting nodes to their parent cluster node var flatGraph = new GeometryGraph(); // from the original graph, foreach node v create a new node u with u.UserData pointing back to v // and set v.AlgorithmData to a wrapper of u foreach (var v in graph.Nodes) { Debug.Assert(!(v is Cluster)); var u = new Node(v.BoundaryCurve.Clone()) { UserData = v }; v.AlgorithmData = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, u); flatGraph.Nodes.Add(u); } double avgLength = 0; foreach (var e in graph.Edges) { avgLength += e.Length; if (e.Source is Cluster || e.Target is Cluster) { continue; } flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); } if (graph.Edges.Count != 0) { avgLength /= graph.Edges.Count; } else { avgLength = 100; } Cluster rootCluster = graph.RootCluster; // create edges from the children of each parent cluster to the parent cluster node foreach (var c in rootCluster.AllClustersDepthFirst()) { if (c == rootCluster) { continue; } if (c.BoundaryCurve == null) { c.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 1, 1, new Point()); } var uOfCluster = new Node(c.BoundaryCurve.Clone()) { UserData = c }; var uuOfCluster = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, uOfCluster); c.AlgorithmData = uuOfCluster; flatGraph.Nodes.Add(uOfCluster); foreach (var v in c.Nodes.Concat(from cc in c.Clusters select(Node) cc)) { flatGraph.Edges.Add( AlgorithmDataEdgeWrap.MakeDummyEdgeFromNodeToItsCluster( v.AlgorithmData as AlgorithmDataNodeWrap, uuOfCluster, avgLength)); } } // mark top-level nodes and clusters foreach (var v in rootCluster.Nodes.Concat(from cc in rootCluster.Clusters select(Node) cc)) { ((AlgorithmDataNodeWrap)v.AlgorithmData).TopLevel = true; } // create edges between clusters foreach (var e in graph.Edges) { if (e.Source is Cluster || e.Target is Cluster) { flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); } } return(flatGraph); }
public static ICurve CreateCurve(double w, double h) { //return CurveFactory.CreateRectangle(w, h, new Point()); //return CurveFactory.CreateEllipse(w/2,h/2, new Point()); return(CurveFactory.CreateRectangleWithRoundedCorners(w, h, 10, 10, new Point())); }