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 Clusterabc() { #if TEST_MSAGL DisplayGeometryGraph.SetShowFunctions(); #endif var geometryGraph = new GeometryGraph(); geometryGraph.RootCluster = new Cluster(); var a = new Node(); a.BoundaryCurve = CurveFactory.CreateCircle(20, new Point()); var b = new Node(); b.BoundaryCurve = CurveFactory.CreateCircle(20, new Point()); var c = new Node(); c.BoundaryCurve = CurveFactory.CreateCircle(20, new Point()); geometryGraph.RootCluster.AddNode(a); geometryGraph.RootCluster.AddNode(b); geometryGraph.RootCluster.AddNode(c); b.AddInEdge(new Edge(a, b)); c.AddInEdge(new Edge(a, c)); var mdsLayoutSettings = new MdsLayoutSettings { RemoveOverlaps = true, NodeSeparation = 10 }; var mdsLayout = new MdsGraphLayout(mdsLayoutSettings, geometryGraph); mdsLayout.Run(); var splineRouter = new SplineRouter(geometryGraph, geometryGraph.Edges, 2, 3, Math.PI / 6, null); splineRouter.Run(); #if TEST_MSAGL DisplayGeometryGraph.ShowGraph(geometryGraph); #endif }
public void TenEdges() { //GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); GeometryGraph graph = new GeometryGraph(); var a = new Node { BoundaryCurve = CurveFactory.CreateCircle(15, new Point(65, 25)), UserData = "a", }; graph.Nodes.Add(a); var b = new Node { UserData = "b", BoundaryCurve = CurveFactory.CreateCircle(15, new Point(25, 25)) }; graph.Nodes.Add(b); graph.Edges.Add(new Edge(b, a)); graph.Edges.Add(new Edge(b, a)); for (int i = 0; i < 8; i++) { graph.Edges.Add(new Edge(a, b)); } var sr = new SplineRouter(graph, 2, 1.5, Math.PI / 6, new BundlingSettings() { EdgeSeparation = 1 }); sr.Run(); //GraphViewerGdi.DisplayGeometryGraph.ShowGraph(graph); }
private static void AddNode(List <Node> l, int n) { if (l[n] == null) { l[n] = new Node(CurveFactory.CreateCircle(5, new Microsoft.Msagl.Core.Geometry.Point())); } }
private static ICurve CreateLabelAndBoundary(NavigationPoint navigationPoint, Microsoft.Msagl.Drawing.Node node) { node.Attr.LabelMargin *= 2; node.Label.IsVisible = false; var y = (navigationPoint.Latitude - airfield.Latitude) * 200000; var x = (navigationPoint.Longitude - airfield.Longitude) * 200000; var positionalPoint = new Microsoft.Msagl.Core.Geometry.Point(x, y); switch (navigationPoint) { case Runway _: node.Attr.Color = Color.Green; return(CurveFactory.CreateCircle(50, positionalPoint)); case Junction _: node.Attr.Shape = Shape.Hexagon; node.Attr.Color = Color.Blue; return(CurveFactory.CreateHexagon(100, 30, positionalPoint)); case ParkingSpot _: node.Attr.Color = Color.Orange; return(CurveFactory.CreateOctagon(100, 30, positionalPoint)); case WayPoint _: node.Attr.Color = Color.Purple; return(CurveFactory.CreateRectangle(100, 30, positionalPoint)); } return(CurveFactory.CreateCircle(5, positionalPoint)); }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, Station highlightedNode) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); List <DebugCurve> debugCurves = hd.CreateDebugCurves(); debugCurves.Add(new DebugCurve(100, 1, "magenta", CurveFactory.CreateCircle(3, highlightedNode.Position))); debugCurves.Add(new DebugCurve(100, 0.1, "green", highlightedNode.BoundaryCurve)); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(debugCurves); }
Graph Run() { xmlReader.MoveToContent(); while (IsStartElement()) { switch (Name) { case "edges": ReadEdges(); break; case "nodes": ReadNodes(); break; case "gexf": Read(); break; case "graph": Read(); break; default: xmlReader.Skip(); break; } } if (!GeometryPresent(graph.Nodes)) { return(graph); } graph.CreateGeometryGraph(); foreach (var n in graph.Nodes) { var geomNode = n.GeometryNode; GexfNodeAttr nodeData; if (idsToGexfNodeAttr.TryGetValue(n.Id, out nodeData)) { n.Label.FontSize *= nodeData.Size; geomNode.BoundaryCurve = CurveFactory.CreateCircle(nodeData.Size, nodeData.Position); } } foreach (var e in graph.Edges) { if (e.GeometryEdge.Source.BoundaryCurve != null && e.GeometryEdge.Target.BoundaryCurve != null) { StraightLineEdges.RouteEdge(e.GeometryEdge, e.Source == e.Target?graph.LayoutAlgorithmSettings.NodeSeparation / 4: 0); } } return(graph); }
//helper function for ToMSALGraph private static void RecursiveCompleteMSALGraphNodes(GeometryGraph target, Node current) { Microsoft.Msagl.Core.Layout.Node msaglNode = new Microsoft.Msagl.Core.Layout.Node( CurveFactory.CreateCircle(20, new Microsoft.Msagl.Core.Geometry.Point()), current); // Add node into MSAGL model. target.Nodes.Add(msaglNode); foreach (Node child in current.getChildren()) { RecursiveCompleteMSALGraphNodes(target, child); } }
private Microsoft.Msagl.Drawing.Node CreateNodeOnCenter(Graph graph, Point nodeCenter) { var node = new Microsoft.Msagl.Drawing.Node(graph.NodeCount.ToString()); node.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle; node.Attr.Color = new Color(0, 100, 100, 100); node.Attr.FillColor = new Color(100, 100, 100, 100); var geomNode = new Node(CurveFactory.CreateCircle(_nodeWidth / 2, nodeCenter)); node.GeometryNode = geomNode; geomNode.UserData = node; graph.AddNode(node); graph.GeometryGraph.Nodes.Add(geomNode); return(node); }
private static void DumpScatterPlotOfDelaunayFacesAreaChange(string graphName, HashSet <Tuple <int, int, int> > proximityTriangles, GeometryGraph geomGraphOld, GeometryGraph geomGraph, string nameAddon) { Graph scatterPlot = new Graph(); for (int i = 0; i < proximityTriangles.Count; i++) { scatterPlot.AddNode(i.ToString()); } scatterPlot.CreateGeometryGraph(); int k = 0; foreach (var triangle in proximityTriangles) { Point a = geomGraphOld.Nodes[triangle.Item1].Center; Point b = geomGraphOld.Nodes[triangle.Item2].Center; Point c = geomGraphOld.Nodes[triangle.Item3].Center; Point d = geomGraph.Nodes[triangle.Item1].Center; Point e = geomGraph.Nodes[triangle.Item2].Center; Point f = geomGraph.Nodes[triangle.Item3].Center; double signOld = Point.SignedDoubledTriangleArea(a, b, c); double signNew = Point.SignedDoubledTriangleArea(d, e, f); var node = scatterPlot.FindNode(k.ToString()); k++; node.GeometryNode.BoundaryCurve = CurveFactory.CreateCircle(1, new Point(signOld, signNew)); if (signNew < 0) { node.Attr.FillColor = node.Attr.Color = Color.Red; } } scatterPlot.GeometryGraph.UpdateBoundingBox(); double w = scatterPlot.GeometryGraph.BoundingBox.Width; double h = scatterPlot.GeometryGraph.BoundingBox.Height; PlaneTransformation p = new PlaneTransformation( 200 / w, 0, 0, 0, 200 / h, 0); scatterPlot.GeometryGraph.Transform(p); scatterPlot.GeometryGraph.UpdateBoundingBox(); SvgGraphWriter.Write(scatterPlot, "cdt_area_change_" + graphName + nameAddon + ".svg"); }
public void OnlyNodes() { // GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions(); var graph = new GeometryGraph(); graph.Nodes.Add(new Node() { BoundaryCurve = CurveFactory.CreateCircle(80, new Point(0, 0)) }); graph.Nodes.Add(new Node() { BoundaryCurve = CurveFactory.CreateCircle(20, new Point(0, 0)) }); graph.Nodes.Add(new Node() { BoundaryCurve = CurveFactory.CreateCircle(100, new Point(0, 0)) }); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); WriteLine("Trying nodes only graph with "); LayoutAndValidate(graph, settings); }
/// <summary> /// Controlling the draw because a need to control the size. /// /// Supporting these shapes : /// Box /// Ellipse /// Circle /// Plaintext /// Point /// </summary> /// <param name="node"></param> /// <param name="centerLocation"></param> /// <param name="width"></param> /// <param name="hight"></param> /// <returns></returns> ICurve DrawCurve(Microsoft.Msagl.Drawing.Node node) { ICurve shape = null; switch (node.Attr.Shape) { case Shape.Box: shape = CurveFactory.CreateRectangle(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Ellipse: shape = CurveFactory.CreateEllipse(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Circle: shape = CurveFactory.CreateCircle(NodeWidth, NodeCenter); break; case Shape.Point: shape = CurveFactory.CreateCircle(0.5, NodeCenter); break; case Shape.Diamond: shape = CurveFactory.CreateDiamond(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Hexagon: shape = CurveFactory.CreateHexagon(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Octagon: shape = CurveFactory.CreateOctagon(NodeWidth, NodeHeight, NodeCenter); break; } return(shape); }
IEnumerable <DebugCurve> BBoxes() { return(mgd.Stations.Where(n => n.IsRealNode).Select(n => new DebugCurve("red", CurveFactory.CreateCircle(n.BoundaryCurve.BoundingBox.Diagonal / 2, n.Position)))); }
IEnumerable <DebugCurve> IdealHubsWithNeighbors() { return(mgd.VirtualNodes().Select(station => new DebugCurve(200, 1, "black", CurveFactory.CreateCircle(HubRadiiCalculator.CalculateIdealHubRadiusWithNeighbors(mgd, bundlingSettings, station), station.Position)))); }
IEnumerable <DebugCurve> Hubs() { return(mgd.Stations.Select(station => new DebugCurve(100, 1, "blue", CurveFactory.CreateCircle(Math.Max(station.Radius, 1.0), station.Position)))); }
static IEnumerable <DebugCurve> DebugCircles(MetroGraphData metroGraphData) { return (metroGraphData.Stations.Select( station => new DebugCurve(100, 0.1, "blue", CurveFactory.CreateCircle(station.Radius, station.Position)))); }
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"); }