GitHubDashboard/FDG/Diagram.cs
/// <summary>
/// Draws the diagram using GDI+, centering and scaling within the specified bounds.
/// </summary>
/// <param name="graphics">GDI+ Graphics surface.</param>
/// <param name="bounds">Bounds in which to draw the diagram.</param>
Draws the diagram using GDI+, centering and scaling within the specified bounds.
Draws the diagram using GDI + centering and scaling within the specified bounds .
public void Draw(Graphics graphics, Rectangle bounds)
		{
			Rectangle logicalBounds = GetDiagramBounds();
			Point midPoint = new Point(logicalBounds.X + (logicalBounds.Width / 2), logicalBounds.Y + (logicalBounds.Height / 2));
			foreach (Node node in nodes)
			{
				node.Location -= (Size)midPoint;
			}
			PointF center = new Point(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2));
			double scale = 1;
			if (logicalBounds.Width > logicalBounds.Height)
			{
				if (logicalBounds.Width != 0)
				{
					scale = (double)Math.Min(bounds.Width, bounds.Height) / (double)logicalBounds.Width;
				}
			}
			else
			{
				if (logicalBounds.Height != 0)
				{
					scale = (double)Math.Min(bounds.Width, bounds.Height) / (double)logicalBounds.Height;
				}
			}
			foreach (Node node in nodes)
			{
				PointF destination = ScalePoint(node.Location, scale);
				Size nodeSize = node.Size;
				RectangleF nodeBounds = new RectangleF(center.X + destination.X - (nodeSize.Width / 2), center.Y + destination.Y - (nodeSize.Height / 2), nodeSize.Width, nodeSize.Height);
				node.DrawNode(graphics, nodeBounds);
			}
		}
public void Draw ( Graphics graphics , Rectangle bounds ) { Rectangle logicalBounds = GetDiagramBounds ( ) ; Point midPoint = new Point ( logicalBounds . X + ( logicalBounds . Width / 2 ) , logicalBounds . Y + ( logicalBounds . Height / 2 ) ) ; foreach ( Node node in nodes ) { node . Location -= ( Size ) midPoint ; } PointF center = new Point ( bounds . X + ( bounds . Width / 2 ) , bounds . Y + ( bounds . Height / 2 ) ) ; double scale = 1 ; if ( logicalBounds . Width > logicalBounds . Height ) { if ( logicalBounds . Width != 0 ) { scale = ( double ) Math . Min ( bounds . Width , bounds . Height ) / ( double ) logicalBounds . Width ; } } else { if ( logicalBounds . Height != 0 ) { scale = ( double ) Math . Min ( bounds . Width , bounds . Height ) / ( double ) logicalBounds . Height ; } } foreach ( Node node in nodes ) { PointF destination = ScalePoint ( node . Location , scale ) ; Size nodeSize = node . Size ; RectangleF nodeBounds = new RectangleF ( center . X + destination . X - ( nodeSize . Width / 2 ) , center . Y + destination . Y - ( nodeSize . Height / 2 ) , nodeSize . Width , nodeSize . Height ) ; node . DrawNode ( graphics , nodeBounds ) ; } }
Draws the diagram using GDI+, centering and scaling within the specified bounds.
Draws the diagram using GDI + centering and scaling within the specified bounds .
// center the diagram around the origin // determine the scaling factor /*
			// draw all of the connectors first
			foreach (Node node in nodes)
			{
				PointF source = ScalePoint(node.Location, scale);

				// connectors
				foreach (Node other in node.Connections)
				{
					PointF destination = ScalePoint(other.Location, scale);
					node.DrawConnector(graphics, center + new SizeF(source), center + new SizeF(destination), other);
				}
			}
				*/ // then draw all of the nodes
graphics
Graphics
GDI+ Graphics surface.
GDI + Graphics surface .
bounds
Rectangle
Bounds in which to draw the diagram.
Bounds in which to draw the diagram .