public static void SetGraphTransform(GeometryGraph geometryGraph, System.DrawingCore.Rectangle rectangle, Graphics graphics) { RectangleF clientRectangle = rectangle; var gr = geometryGraph.BoundingBox; if (clientRectangle.Height > 1 && clientRectangle.Width > 1) { var scale = Math.Min(clientRectangle.Width * 0.9 / gr.Width, clientRectangle.Height * 0.9 / gr.Height); var g0 = (gr.Left + gr.Right) / 2; var g1 = (gr.Top + gr.Bottom) / 2; var c0 = (clientRectangle.Left + clientRectangle.Right) / 2; var c1 = (clientRectangle.Top + clientRectangle.Bottom) / 2; var dx = c0 - scale * g0; var dy = c1 - scale * g1; /* * //instead of setting transormation for graphics it is possible to transform the geometry graph, just to test that GeometryGraph.Transform() works * * var planeTransformation=new PlaneTransformation(scale,0,dx, 0, scale, dy); * geometryGraph.Transform(planeTransformation); */ graphics.Transform = new Matrix((float)scale, 0, 0, (float)scale, (float)dx, (float)dy); } }
public static void DrawFromGraph(System.DrawingCore.Rectangle clientRectangle, GeometryGraph geometryGraph, Graphics graphics) { SetGraphTransform(geometryGraph, clientRectangle, graphics); var pen = new Pen(Brushes.Black); DrawNodes(geometryGraph, pen, graphics); DrawEdges(geometryGraph, pen, graphics); }