/// <summary> /// Render the label for this <see cref="GasGaugeNeedle"/>. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="rect">Bounding rectangle for this <see cref="GasGaugeNeedle"/>.</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public override void DrawLegendKey( Graphics g, GraphPane pane, RectangleF rect, float scaleFactor ) { if ( !_isVisible ) return; float yMid = rect.Top + rect.Height / 2.0F; Pen pen = new Pen( NeedleColor, pane.ScaledPenWidth( NeedleWidth / 2, scaleFactor ) ); pen.StartCap = LineCap.Round; pen.EndCap = LineCap.ArrowAnchor; pen.DashStyle = DashStyle.Solid; g.DrawLine( pen, rect.Left, yMid, rect.Right, yMid ); }
/// <summary> /// Draw the scale, including the tic marks, value labels, and grid lines as /// required for this <see cref="Axis"/>. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> /// <param name="shiftPos"> /// The number of pixels to shift to account for non-primary axis position (e.g., /// the second, third, fourth, etc. <see cref="YAxis" /> or <see cref="Y2Axis" />. /// </param> internal void Draw( Graphics g, GraphPane pane, float scaleFactor, float shiftPos ) { MajorGrid majorGrid = _ownerAxis._majorGrid; MajorTic majorTic = _ownerAxis._majorTic; MinorTic minorTic = _ownerAxis._minorTic; float rightPix, topPix; GetTopRightPix( pane, out topPix, out rightPix ); // calculate the total number of major tics required int nTics = CalcNumTics(); // get the first major tic value double baseVal = CalcBaseTic(); using ( Pen pen = new Pen( _ownerAxis.Color, pane.ScaledPenWidth( majorTic._penWidth, scaleFactor ) ) ) { // redraw the axis border if ( _ownerAxis.IsAxisSegmentVisible ) g.DrawLine( pen, 0.0F, shiftPos, rightPix, shiftPos ); // Draw a zero-value line if needed if ( majorGrid._isZeroLine && _min < 0.0 && _max > 0.0 ) { float zeroPix = LocalTransform( 0.0 ); g.DrawLine( pen, zeroPix, 0.0F, zeroPix, topPix ); } } // draw the major tics and labels DrawLabels( g, pane, baseVal, nTics, topPix, shiftPos, scaleFactor ); // _ownerAxis.DrawMinorTics( g, pane, baseVal, shiftPos, scaleFactor, topPix ); _ownerAxis.DrawTitle( g, pane, shiftPos, scaleFactor ); }
/// <summary> /// Draw the minor tic marks as required for this <see cref="Axis"/>. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="baseVal"> /// The scale value for the first major tic position. This is the reference point /// for all other tic marks. /// </param> /// <param name="shift">The number of pixels to shift this axis, based on the /// value of <see cref="Cross"/>. A positive value is into the ChartRect relative to /// the default axis position.</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> /// <param name="topPix"> /// The pixel location of the far side of the ChartRect from this axis. /// This value is the ChartRect.Height for the XAxis, or the ChartRect.Width /// for the YAxis and Y2Axis. /// </param> public void DrawMinorTics( Graphics g, GraphPane pane, double baseVal, float shift, float scaleFactor, float topPix ) { if ( ( this.MinorTic.IsOutside || this.MinorTic.IsOpposite || this.MinorTic.IsInside || this.MinorTic._isCrossOutside || this.MinorTic._isCrossInside || _minorGrid._isVisible ) && _isVisible ) { double tMajor = _scale._majorStep * _scale.MajorUnitMultiplier, tMinor = _scale._minorStep * _scale.MinorUnitMultiplier; if ( _scale.IsLog || tMinor < tMajor ) { float minorScaledTic = this.MinorTic.ScaledTic( scaleFactor ); // Minor tics start at the minimum value and step all the way thru // the full scale. This means that if the minor step size is not // an even division of the major step size, the minor tics won't // line up with all of the scale labels and major tics. double first = _scale._minLinTemp, last = _scale._maxLinTemp; double dVal = first; float pixVal; int iTic = _scale.CalcMinorStart( baseVal ); int MajorTic = 0; double majorVal = _scale.CalcMajorTicValue( baseVal, MajorTic ); using ( Pen pen = new Pen( _minorTic._color, pane.ScaledPenWidth( MinorTic._penWidth, scaleFactor ) ) ) using ( Pen minorGridPen = _minorGrid.GetPen( pane, scaleFactor ) ) { // Draw the minor tic marks while ( dVal < last && iTic < 5000 ) { // Calculate the scale value for the current tic dVal = _scale.CalcMinorTicValue( baseVal, iTic ); // Maintain a value for the current major tic if ( dVal > majorVal ) majorVal = _scale.CalcMajorTicValue( baseVal, ++MajorTic ); // Make sure that the current value does not match up with a major tic if ( ( ( Math.Abs( dVal ) < 1e-20 && Math.Abs( dVal - majorVal ) > 1e-20 ) || ( Math.Abs( dVal ) > 1e-20 && Math.Abs( ( dVal - majorVal ) / dVal ) > 1e-10 ) ) && ( dVal >= first && dVal <= last ) ) { pixVal = _scale.LocalTransform( dVal ); _minorGrid.Draw( g, minorGridPen, pixVal, topPix ); _minorTic.Draw( g, pane, pen, pixVal, topPix, shift, minorScaledTic ); } iTic++; } } } } }
internal Pen GetPen( GraphPane pane, float scaleFactor ) { Pen pen = new Pen( _color, pane.ScaledPenWidth( _penWidth, scaleFactor ) ); if ( _dashOff > 1e-10 && _dashOn > 1e-10 ) { pen.DashStyle = DashStyle.Custom; float[] pattern = new float[2]; pattern[0] = _dashOn; pattern[1] = _dashOff; pen.DashPattern = pattern; } return pen; }
internal void FixZeroLine( Graphics g, GraphPane pane, float scaleFactor, float left, float right ) { // restore the zero line if needed (since the fill tends to cover it up) if ( _isVisible && _majorGrid._isZeroLine && _scale._min < 0.0 && _scale._max > 0.0 ) { float zeroPix = _scale.Transform( 0.0 ); using ( Pen zeroPen = new Pen( _color, pane.ScaledPenWidth( _majorGrid._penWidth, scaleFactor ) ) ) { g.DrawLine( zeroPen, left, zeroPix, right, zeroPix ); //zeroPen.Dispose(); } } }