/// <summary> /// Draws the axis horizontally /// </summary> public void DrawHorizontal( IGraphCanvas canvas, Rectangle drawBounds, RectangleF dataBounds ) { if ( m_TickFont == null ) { return; } float cellSize = m_LineStep; float dataX = ( int )( dataBounds.Left / cellSize ) * cellSize; float drawY = ( ( ( -dataBounds.Top / dataBounds.Height ) * drawBounds.Height ) + drawBounds.Top ); if ( drawY < m_TickFont.Height ) { drawY = m_TickFont.Height; } int widthInCells = ( int )( dataBounds.Width / cellSize ) + 1; for ( int cellX = 0; cellX < widthInCells; ++cellX ) { float drawX = ( ( ( dataX - dataBounds.Left ) / dataBounds.Width ) * drawBounds.Width ) + drawBounds.Left; canvas.DrawText( m_TickFont, m_TickFontBrush, drawX, GraphUtils.InvY( drawY, drawBounds ), AxisValueToString( dataX ) ); dataX += cellSize; } }
/// <summary> /// Draws the axis vertically /// </summary> public void DrawVertical( IGraphCanvas canvas, Rectangle drawBounds, RectangleF dataBounds ) { if ( m_TickFont == null ) { return; } float cellSize = m_LineStep; float dataY = ( int )( dataBounds.Top / cellSize ) * cellSize; int heightInCells = ( int )( dataBounds.Height / cellSize ) + 1; float drawX = ( ( -dataBounds.Left / dataBounds.Width ) * drawBounds.Width ) + drawBounds.Left; if ( drawX < 2 ) { drawX = 2; } for ( int cellY = 0; cellY < heightInCells; ++cellY ) { float drawY = ( ( ( dataY - dataBounds.Top ) / dataBounds.Height ) * drawBounds.Height ) + drawBounds.Top; canvas.DrawText( m_TickFont, m_TickFontBrush, drawX, GraphUtils.InvY( drawY, drawBounds ), AxisValueToString( dataY ) ); dataY += cellSize; } }
/// <summary> /// Draws legends for all the graphs /// </summary> public static void DrawLegends( IGraphCanvas graphics, Font font, IEnumerable< GraphComponent > graphComponents ) { int x = 0; int y = 0; using ( SolidBrush fontBrush = new SolidBrush( Color.Black ) ) { using ( Pen pen = new Pen( Color.Black ) ) { foreach ( GraphComponent graphComponent in graphComponents ) { fontBrush.Color = ( graphComponent.Renderer != null ) ? graphComponent.Renderer.Colour : Color.Black; pen.Color = fontBrush.Color; graphics.DrawText( font, fontBrush, x, y, graphComponent.Name ); y += font.Height + 2; //graphics.DrawLine( pen, x, y, x + 30, y ); } } } }