/// <summary> /// Draw all the <see cref="ErrorBar"/>'s to the specified <see cref="Graphics"/> /// device as a an error bar at each defined point. /// </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="curve">A <see cref="CurveItem"/> object representing the /// <see cref="Bar"/>'s to be drawn.</param> /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent) /// axis for the <see cref="Bar"/></param> /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent) /// axis for the <see cref="Bar"/></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="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public void Draw( Graphics g, GraphPane pane, ErrorBarItem curve, Axis baseAxis, Axis valueAxis, double scaleFactor ) { BarValueHandler valueHandler = new BarValueHandler( pane ); float pixBase, pixValue, pixLowValue; double scaleBase, scaleValue, scaleLowValue; if ( curve.Points != null && this.IsVisible ) { Pen pen = new Pen( color, penWidth ); // Loop over each defined point for ( int i=0; i<curve.Points.Count; i++ ) { valueHandler.GetBarValues( curve, i, out scaleBase, out scaleLowValue, out scaleValue ); // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if ( !curve.Points[i].IsInvalid3D && ( scaleBase > 0 || !baseAxis.IsLog ) && ( ( scaleValue > 0 && scaleLowValue > 0 ) || !valueAxis.IsLog ) ) { pixBase = baseAxis.Transform( scaleBase ); pixValue = valueAxis.Transform( scaleValue ); pixLowValue = valueAxis.Transform( scaleLowValue ); //if ( this.fill.IsGradientValueType ) // brush = fill.MakeBrush( rect, points[i] ); this.Draw( g, pane, baseAxis is XAxis, pixBase, pixValue, pixLowValue, scaleFactor, pen ); } } } }
/// <summary> /// Protected internal routine that draws the specified single bar (an individual "point") /// of this series to the specified <see cref="Graphics"/> device. /// </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="curve">A <see cref="CurveItem"/> object representing the /// <see cref="Bar"/>'s to be drawn.</param> /// <param name="index"> /// The zero-based index number for the single bar to be drawn. /// </param> /// <param name="pos"> /// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.) /// in the cluster of bars. /// </param> /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent) /// axis for the <see cref="Bar"/></param> /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent) /// axis for the <see cref="Bar"/></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="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> protected virtual void DrawSingleBar( Graphics g, GraphPane pane, CurveItem curve, int index, int pos, Axis baseAxis, Axis valueAxis, double scaleFactor ) { // pixBase = pixel value for the bar center on the base axis // pixHiVal = pixel value for the bar top on the value axis // pixLowVal = pixel value for the bar bottom on the value axis float pixBase, pixHiVal, pixLowVal; float clusterWidth = pane.GetClusterWidth(); float barWidth = curve.GetBarWidth( pane ); float clusterGap = pane.MinClusterGap * barWidth; float barGap = barWidth * pane.MinBarGap; // curBase = the scale value on the base axis of the current bar // curHiVal = the scale value on the value axis of the current bar // curLowVal = the scale value of the bottom of the bar double curBase, curLowVal, curHiVal; BarValueHandler valueHandler = new BarValueHandler( pane ); valueHandler.GetBarValues( curve, index, out curBase, out curLowVal, out curHiVal ); // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if ( !curve.Points[index].IsInvalid ) { // calculate a pixel value for the top of the bar on value axis pixLowVal = valueAxis.Transform( index, curLowVal ); pixHiVal = valueAxis.Transform( index, curHiVal ); // calculate a pixel value for the center of the bar on the base axis pixBase = baseAxis.Transform( index, curBase ); // Calculate the pixel location for the side of the bar (on the base axis) float pixSide = pixBase - clusterWidth / 2.0F + clusterGap / 2.0F + pos * ( barWidth + barGap ); // Draw the bar if ( pane.BarBase == BarBase.X ) this.Draw( g, pane, pixSide, pixSide + barWidth, pixLowVal, pixHiVal, scaleFactor, true ); else this.Draw( g, pane, pixLowVal, pixHiVal, pixSide, pixSide + barWidth, scaleFactor, true ); } }
/// <summary> /// Protected internal routine that draws the specified single bar (an individual "point") /// of this series to the specified <see cref="Graphics"/> device. /// </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="curve">A <see cref="CurveItem"/> object representing the /// <see cref="Bar"/>'s to be drawn.</param> /// <param name="index"> /// The zero-based index number for the single bar to be drawn. /// </param> /// <param name="pos"> /// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.) /// in the cluster of bars. /// </param> /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent) /// axis for the <see cref="Bar"/></param> /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent) /// axis for the <see cref="Bar"/></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="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> protected override void DrawSingleBar( Graphics g, GraphPane pane, CurveItem curve, int index, int pos, Axis baseAxis, Axis valueAxis, double scaleFactor ) { float scaledSize = GetBarWidth( pane, baseAxis, scaleFactor ); // pixBase = pixel value for the bar center on the base axis // pixValue = pixel value for the bar top on the value axis // pixLow = pixel value for the bar bottom on the value axis float pixBase, pixHiVal, pixLowVal; // curBase = the scale value on the base axis of the current bar // curValue = the scale value on the value axis of the current bar // double curBase = ( baseAxis is XAxis ) ? points[index].X : points[index].Y; // double curValue = ( baseAxis is XAxis ) ? points[index].Y : points[index].X; double curBase, curLowVal, curHiVal; BarValueHandler valueHandler = new BarValueHandler( pane ); valueHandler.GetBarValues( curve, index, out curBase, out curLowVal, out curHiVal ); // curLow = the scale value on the value axis for the bottom of the current bar // Get a "low" value for the bottom of the bar and verify validity //double curLow = points[index].LowValue; if ( curLowVal == PointPair.Missing || System.Double.IsNaN( curLowVal ) || System.Double.IsInfinity( curLowVal ) ) curLowVal = 0; // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if ( !curve.Points[index].IsInvalid ) { // calculate a pixel value for the top of the bar on value axis pixHiVal = valueAxis.Transform( index, curHiVal ); // calculate a pixel value for the center of the bar on the base axis pixBase = baseAxis.Transform( index, curBase ); pixLowVal = valueAxis.Transform( index, curLowVal ); // Calculate the pixel location for the side of the bar (on the base axis) float pixSide = pixBase - scaledSize / 2.0F; // Draw the bar if ( baseAxis is XAxis ) this.Draw( g, pane, pixSide, pixSide + scaledSize, pixLowVal, pixHiVal, scaleFactor, true ); else this.Draw( g, pane, pixLowVal, pixHiVal, pixSide, pixSide + scaledSize, scaleFactor, true ); } }