private void Synchronize( Axis source, Axis dest ) { dest._scale._min = source._scale._min; dest._scale._max = source._scale._max; dest._scale._majorStep = source._scale._majorStep; dest._scale._minorStep = source._scale._minorStep; dest._scale._minAuto = source._scale._minAuto; dest._scale._maxAuto = source._scale._maxAuto; dest._scale._majorStepAuto = source._scale._majorStepAuto; dest._scale._minorStepAuto = source._scale._minorStepAuto; }
static string XAxis_ScaleFormatEvent(GraphPane pane, ZedGraph.Axis axis, double val, int index) { if (_chartGrouping.Text == "Monthly") { return(DateTime.FromOADate(val).ToString("MM/yyyy")); } else { pane.XAxis.Scale.FontSpec.Angle = 45; return(DateTime.FromOADate(val).ToString("dd/MM/yyyy")); } }
string XAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index) { string name = pane.Title.Text; if (name.StartsWith("T")) { return(index + "ns"); } else { return(index * 5 + "Ghz"); } //根据 val值 返回你需要的 string }
static string YAxis_ScaleFormatEvent(GraphPane pane, ZedGraph.Axis axis, double val, int index) { if (_chartType.Text == "Total Duration") { TimeSpan timeVal = TimeSpan.FromHours(val); return(string.Format("{0:D2}:{1:D2}:{2:D2}", Convert.ToInt32(Math.Floor(timeVal.TotalHours)), timeVal.Minutes, timeVal.Seconds )); } else { return(val.ToString()); } }
/// <summary> /// Construct a <see cref="ScaleState"/> from the specified <see cref="Axis"/> /// </summary> /// <param name="axis">The <see cref="Axis"/> from which to collect the scale /// range settings.</param> public ScaleState(Axis axis) { _min = axis._scale._min; _minorStep = axis._scale._minorStep; _majorStep = axis._scale._majorStep; _max = axis._scale._max; _majorUnit = axis._scale._majorUnit; _minorUnit = axis._scale._minorUnit; _format = axis._scale._format; _mag = axis._scale._mag; //this.numDec = axis.NumDec; _minAuto = axis._scale._minAuto; _majorStepAuto = axis._scale._majorStepAuto; _minorStepAuto = axis._scale._minorStepAuto; _maxAuto = axis._scale._maxAuto; _formatAuto = axis._scale._formatAuto; _magAuto = axis._scale._magAuto; }
/// <summary> /// Create a new clone of the current item, with a new owner assignment /// </summary> /// <param name="owner">The new <see cref="Axis" /> instance that will be /// the owner of the new Scale</param> /// <returns>A new <see cref="Scale" /> clone.</returns> public override Scale Clone(Axis owner) { return new LinearAsOrdinalScale(this, owner); }
/// <summary> /// Default constructor that defines the owner <see cref="Axis" /> /// (containing object) for this new object. /// </summary> /// <param name="owner">The owner, or containing object, of this instance</param> public LinearAsOrdinalScale(Axis owner) : base(owner) { }
/// <summary> /// Default constructor that defines the owner <see cref="Axis" /> /// (containing object) for this new object. /// </summary> /// <param name="owner">The owner, or containing object, of this instance</param> public OrdinalScale( Axis owner ) : base(owner) { }
/// <summary> /// The Copy Constructor. /// </summary> /// <param name="rhs">The Axis object from which to copy</param> public Axis( Axis rhs ) { _scale = rhs._scale.Clone( this ); _cross = rhs._cross; _crossAuto = rhs._crossAuto; _majorTic = rhs.MajorTic.Clone(); _minorTic = rhs.MinorTic.Clone(); _majorGrid = rhs._majorGrid.Clone(); _minorGrid = rhs._minorGrid.Clone(); _isVisible = rhs.IsVisible; _isAxisSegmentVisible = rhs._isAxisSegmentVisible; _title = (AxisLabel) rhs.Title.Clone(); _axisGap = rhs._axisGap; _minSpace = rhs.MinSpace; _color = rhs.Color; }
public TextScale(Axis owner) : base(owner) { }
/// <summary> /// Returns the width of the candleStick, in pixels, based on the settings for /// <see cref="Size"/> and <see cref="IsAutoSize"/>. /// </summary> /// <param name="pane">The parent <see cref="GraphPane"/> object.</param> /// <param name="baseAxis">The <see cref="Axis"/> object that /// represents the bar base (independent axis).</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> /// <returns>The width of each bar, in pixel units</returns> public float GetBarWidth( GraphPane pane, Axis baseAxis, float scaleFactor ) { float width; if ( _isAutoSize ) width = baseAxis._scale.GetClusterWidth( _userScaleSize ) / ( 1.0F + pane._barSettings.MinClusterGap ) / 2.0f; else width = (float)( _size * scaleFactor ) / 2.0f; // use integral size return (int)(width + 0.5f); }
/// <summary> /// Basic constructor -- requires that the <see cref="Scale" /> object be intialized with /// a pre-existing owner <see cref="Axis" />. /// </summary> /// <param name="ownerAxis">The <see cref="Axis" /> object that is the owner of this /// <see cref="Scale" /> instance.</param> public Scale( Axis ownerAxis ) { _ownerAxis = ownerAxis; _min = 0.0; _max = 1.0; _majorStep = 0.1; _minorStep = 0.1; _exponent = 1.0; _mag = 0; _baseTic = PointPair.Missing; _minGrace = Default.MinGrace; _maxGrace = Default.MaxGrace; _minAuto = true; _maxAuto = true; _majorStepAuto = true; _minorStepAuto = true; _magAuto = true; _formatAuto = true; _isReverse = Default.IsReverse; _isUseTenPower = true; _isPreventLabelOverlap = true; _isVisible = true; _isSkipFirstLabel = false; _isSkipLastLabel = false; _isSkipCrossLabel = false; _majorUnit = DateUnit.Day; _minorUnit = DateUnit.Day; _format = null; _textLabels = null; _isLabelsInside = Default.IsLabelsInside; _align = Default.Align; _alignH = Default.AlignH; _fontSpec = new FontSpec( Default.FontFamily, Default.FontSize, Default.FontColor, Default.FontBold, Default.FontUnderline, Default.FontItalic, Default.FillColor, Default.FillBrush, Default.FillType ); _fontSpec.Border.IsVisible = false; _labelGap = Default.LabelGap; }
string XAxis_ScaleFormatEvent1(GraphPane pane, ZedGraph.Axis axis, double val, int index) { return(val.ToString("e3") + "G"); }
string XAxis_ScaleFormatEvent(GraphPane pane, ZedGraph.Axis axis, double val, int index) { val = Time.ChangeUnit((float)val, Time.TimeUnit.sec, Time.TimeUnit.ns); return(val.ToString("e3") + "ns"); }
string XAxis_ScaleTitleEvent(ZedGraph.Axis axis) { //When the scale is very large , the title will display the scale information //So we need hide it! return(""); }
/// <summary> /// Draw the specified single bar (an individual "point") of this series to the specified /// <see cref="Graphics"/> device. This method is not as efficient as /// <see cref="DrawBars"/>, which draws the bars for all points. It is intended to be used /// only for <see cref="BarType.SortedOverlay"/>, which requires special handling of each bar. /// </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="pos"> /// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.) /// in the cluster of bars. /// </param> /// <param name="index"> /// The zero-based index number for the single bar to be drawn. /// </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 DrawSingleBar( Graphics g, GraphPane pane, CurveItem curve, Axis baseAxis, Axis valueAxis, int pos, int index, double scaleFactor ) { if ( index >= curve.Points.Count ) return; //SetupBarStack( valueAxis, curve.Points.Count ); // For Overlay and Stack bars, the position is always zero since the bars are on top // of eachother if ( pane.BarType == BarType.Overlay || pane.BarType == BarType.Stack || pane.BarType == BarType.PercentStack ) pos = 0; DrawSingleBar( g, pane, curve, index, pos, baseAxis, valueAxis, scaleFactor ); }
private void ForceNumTics( Axis axis, int numTics ) { if ( axis._scale.MaxAuto ) { int nTics = axis._scale.CalcNumTics(); if ( nTics < numTics ) axis._scale._maxLinearized += axis._scale._majorStep * ( numTics - nTics ); } }
/// <summary> /// Define suitable default ranges for an axis in the event that /// no data were available /// </summary> /// <param name="pane">The <see cref="GraphPane"/> of interest</param> /// <param name="axis">The <see cref="Axis"/> for which to set the range</param> internal void SetRange( GraphPane pane, Axis axis ) { if ( _rangeMin >= Double.MaxValue || _rangeMax <= Double.MinValue ) { // If this is a Y axis, and the main Y axis is valid, use it for defaults if ( axis != pane.XAxis && axis != pane.X2Axis && pane.YAxis.Scale._rangeMin < double.MaxValue && pane.YAxis.Scale._rangeMax > double.MinValue ) { _rangeMin = pane.YAxis.Scale._rangeMin; _rangeMax = pane.YAxis.Scale._rangeMax; } // Otherwise, if this is a Y axis, and the main Y2 axis is valid, use it for defaults else if ( axis != pane.XAxis && axis != pane.X2Axis && pane.Y2Axis.Scale._rangeMin < double.MaxValue && pane.Y2Axis.Scale._rangeMax > double.MinValue ) { _rangeMin = pane.Y2Axis.Scale._rangeMin; _rangeMax = pane.Y2Axis.Scale._rangeMax; } // Otherwise, just use 0 and 1 else { _rangeMin = 0; _rangeMax = 1; } } /* if ( yMinVal >= Double.MaxValue || yMaxVal <= Double.MinValue ) { if ( y2MinVal < Double.MaxValue && y2MaxVal > Double.MinValue ) { yMinVal = y2MinVal; yMaxVal = y2MaxVal; } else { yMinVal = 0; yMaxVal = 0.01; } } if ( y2MinVal >= Double.MaxValue || y2MaxVal <= Double.MinValue ) { if ( yMinVal < Double.MaxValue && yMaxVal > Double.MinValue ) { y2MinVal = yMinVal; y2MaxVal = yMaxVal; } else { y2MinVal = 0; y2MaxVal = 1; } } */ }
/// <summary> /// Draw all the <see cref="OHLCBar"/>'s to the specified <see cref="Graphics"/> /// device as a candlestick 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="OHLCBarItem"/> object representing the /// <see cref="OHLCBar"/>'s to be drawn.</param> /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent) /// axis for the <see cref="OHLCBar"/></param> /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent) /// axis for the <see cref="OHLCBar"/></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 void Draw( Graphics g, GraphPane pane, OHLCBarItem curve, Axis baseAxis, Axis valueAxis, float scaleFactor ) { //ValueHandler valueHandler = new ValueHandler( pane, false ); float pixBase, pixHigh, pixLow, pixOpen, pixClose; if ( curve.Points != null ) { //float halfSize = _size * scaleFactor; float halfSize = GetBarWidth( pane, baseAxis, scaleFactor ); using ( Pen pen = !curve.IsSelected ? new Pen( _color, _width ) : new Pen( Selection.Border.Color, Selection.Border.Width ) ) // using ( Pen pen = new Pen( _color, _penWidth ) ) { // Loop over each defined point for ( int i = 0; i < curve.Points.Count; i++ ) { PointPair pt = curve.Points[i]; double date = pt.X; double high = pt.Y; double low = pt.Z; double open = PointPair.Missing; double close = PointPair.Missing; if ( pt is StockPt ) { open = ( pt as StockPt ).Open; close = ( pt as StockPt ).Close; } // 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 && ( date > 0 || !baseAxis._scale.IsLog ) && ( ( high > 0 && low > 0 ) || !valueAxis._scale.IsLog ) ) { pixBase = (int)( baseAxis.Scale.Transform( curve.IsOverrideOrdinal, i, date ) + 0.5 ); //pixBase = baseAxis.Scale.Transform( curve.IsOverrideOrdinal, i, date ); pixHigh = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, high ); pixLow = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, low ); if ( PointPair.IsValueInvalid( open ) ) pixOpen = Single.MaxValue; else pixOpen = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, open ); if ( PointPair.IsValueInvalid( close ) ) pixClose = Single.MaxValue; else pixClose = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, close ); if ( !curve.IsSelected && this._gradientFill.IsGradientValueType ) { using ( Pen tPen = GetPen( pane, scaleFactor, pt ) ) Draw( g, pane, baseAxis is XAxis || baseAxis is X2Axis, pixBase, pixHigh, pixLow, pixOpen, pixClose, halfSize, tPen ); } else Draw( g, pane, baseAxis is XAxis || baseAxis is X2Axis, pixBase, pixHigh, pixLow, pixOpen, pixClose, halfSize, pen ); } } } } }
/// <summary> /// Copy Constructor. Create a new <see cref="Scale" /> object based on the specified /// existing one. /// </summary> /// <param name="rhs">The <see cref="Scale" /> object to be copied.</param> /// <param name="owner">The <see cref="Axis" /> object that will own the /// new instance of <see cref="Scale" /></param> public Scale( Scale rhs, Axis owner ) { _ownerAxis = owner; _min = rhs._min; _max = rhs._max; _majorStep = rhs._majorStep; _minorStep = rhs._minorStep; _exponent = rhs._exponent; _baseTic = rhs._baseTic; _minAuto = rhs._minAuto; _maxAuto = rhs._maxAuto; _majorStepAuto = rhs._majorStepAuto; _minorStepAuto = rhs._minorStepAuto; _magAuto = rhs._magAuto; _formatAuto = rhs._formatAuto; _minGrace = rhs._minGrace; _maxGrace = rhs._maxGrace; _mag = rhs._mag; _isUseTenPower = rhs._isUseTenPower; _isReverse = rhs._isReverse; _isPreventLabelOverlap = rhs._isPreventLabelOverlap; _isVisible = rhs._isVisible; _isSkipFirstLabel = rhs._isSkipFirstLabel; _isSkipLastLabel = rhs._isSkipLastLabel; _isSkipCrossLabel = rhs._isSkipCrossLabel; _majorUnit = rhs._majorUnit; _minorUnit = rhs._minorUnit; _format = rhs._format; _isLabelsInside = rhs._isLabelsInside; _align = rhs._align; _alignH = rhs._alignH; _fontSpec = (FontSpec) rhs._fontSpec.Clone(); _labelGap = rhs._labelGap; if ( rhs._textLabels != null ) _textLabels = (string[])rhs._textLabels.Clone(); else _textLabels = null; }
/// <summary> /// Create a new clone of the current item, with a new owner assignment /// </summary> /// <param name="owner">The new <see cref="Axis" /> instance that will be /// the owner of the new Scale</param> /// <returns>A new <see cref="Scale" /> clone.</returns> public override Scale Clone(Axis owner) { return new TextScale(this, owner); }
/// <summary> /// Draw the specified single bar (an individual "point") of this series to the specified /// <see cref="Graphics"/> device. This method is not as efficient as /// <see cref="DrawBars"/>, which draws the bars for all points. It is intended to be used /// only for <see cref="BarType.SortedOverlay"/>, which requires special handling of each bar. /// </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="pos"> /// The ordinal position of the this bar series (0=first bar, 1=second bar, etc.) /// in the cluster of bars. /// </param> /// <param name="index"> /// The zero-based index number for the single bar to be drawn. /// </param> /// <param name="barWidth"> /// The width of each bar, in pixels. /// </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 void DrawSingleBar(Graphics g, GraphPane pane, CurveItem curve, Axis baseAxis, Axis valueAxis, int pos, int index, float barWidth, float scaleFactor) { // Make sure that a bar value exists for the current curve and current ordinal position if (index >= curve.Points.Count) return; // For Overlay and Stack bars, the position is always zero since the bars are on top // of eachother if (pane._barSettings.Type == BarType.Overlay || pane._barSettings.Type == BarType.Stack || pane._barSettings.Type == BarType.PercentStack) pos = 0; // Draw the specified bar DrawSingleBar(g, pane, curve, index, pos, baseAxis, valueAxis, barWidth, scaleFactor); }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="TextScale" /> object from which to copy</param> /// <param name="owner">The <see cref="Axis" /> object that will own the /// new instance of <see cref="TextScale" /></param> public TextScale(Scale rhs, Axis owner) : base(rhs, owner) { }
/// <summary> /// Make a string label that corresponds to a user scale value. /// </summary> /// <param name="axis">The axis from which to obtain the scale value. This determines /// if it's a date value, linear, log, etc.</param> /// <param name="val">The value to be made into a label</param> /// <param name="iPt">The ordinal position of the value</param> /// <param name="isOverrideOrdinal">true to override the ordinal settings of the axis, /// and prefer the actual value instead.</param> /// <returns>The string label.</returns> protected string MakeValueLabel(Axis axis, double val, int iPt, bool isOverrideOrdinal) { if (axis != null) { if (axis.Scale.IsDate || axis.Scale.Type == AxisType.DateAsOrdinal) { return XDate.ToString(val, _pointDateFormat); } else if (axis._scale.IsText && axis._scale._textLabels != null) { int i = iPt; if (isOverrideOrdinal) i = (int)(val - 0.5); if (i >= 0 && i < axis._scale._textLabels.Length) return axis._scale._textLabels[i]; else return (i + 1).ToString(); } else if (axis.Scale.IsAnyOrdinal && axis.Scale.Type != AxisType.LinearAsOrdinal && !isOverrideOrdinal) { return iPt.ToString(_pointValueFormat); } else return val.ToString(_pointValueFormat); } else return string.Empty; }
/// <summary> /// Default constructor that defines the owner <see cref="Axis" /> /// (containing object) for this new object. /// </summary> /// <param name="owner">The owner, or containing object, of this instance</param> public DateAsOrdinalScale( Axis owner ) : base(owner) { }
/// <summary> /// Handle a panning operation for the specified <see cref="Axis" />. /// </summary> /// <param name="axis">The <see cref="Axis" /> to be panned</param> /// <param name="startVal">The value where the pan started. The scale range /// will be shifted by the difference between <see paramref="startVal" /> and /// <see paramref="endVal" />. /// </param> /// <param name="endVal">The value where the pan ended. The scale range /// will be shifted by the difference between <see paramref="startVal" /> and /// <see paramref="endVal" />. /// </param> protected void PanScale(Axis axis, double startVal, double endVal) { if (axis != null) { Scale scale = axis._scale; double delta = scale.Linearize(startVal) - scale.Linearize(endVal); scale._minLinearized += delta; scale._maxLinearized += delta; scale._minAuto = false; scale._maxAuto = false; /* if ( axis.Type == AxisType.Log ) { axis._scale._min *= startVal / endVal; axis._scale._max *= startVal / endVal; } else { axis._scale._min += startVal - endVal; axis._scale._max += startVal - endVal; } */ } }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="OrdinalScale" /> object from which to copy</param> /// <param name="owner">The <see cref="Axis" /> object that will own the /// new instance of <see cref="OrdinalScale" /></param> public OrdinalScale( Scale rhs, Axis owner ) : base(rhs, owner) { }
/// <summary> /// Zoom the specified axis by the specified amount, with the center of the zoom at the /// (optionally) specified point. /// </summary> /// <remarks> /// This method is used for MouseWheel zoom operations</remarks> /// <param name="axis">The <see cref="Axis" /> to be zoomed.</param> /// <param name="zoomFraction">The zoom fraction, less than 1.0 to zoom in, greater than 1.0 to /// zoom out. That is, a value of 0.9 will zoom in such that the scale length is 90% of what /// it previously was.</param> /// <param name="centerVal">The location for the center of the zoom. This is only used if /// <see paramref="IsZoomOnMouseCenter" /> is true.</param> /// <param name="isZoomOnCenter">true if the zoom is to be centered at the /// <see paramref="centerVal" /> screen position, false for the zoom to be centered within /// the <see cref="Chart.Rect" />. /// </param> protected void ZoomScale(Axis axis, double zoomFraction, double centerVal, bool isZoomOnCenter) { if (axis != null && zoomFraction > 0.0001 && zoomFraction < 1000.0) { Scale scale = axis._scale; /* if ( axis.Scale.IsLog ) { double ratio = Math.Sqrt( axis._scale._max / axis._scale._min * zoomFraction ); if ( !isZoomOnCenter ) centerVal = Math.Sqrt( axis._scale._max * axis._scale._min ); axis._scale._min = centerVal / ratio; axis._scale._max = centerVal * ratio; } else { */ double minLin = axis._scale._minLinearized; double maxLin = axis._scale._maxLinearized; double range = (maxLin - minLin) * zoomFraction / 2.0; if (!isZoomOnCenter) centerVal = (maxLin + minLin) / 2.0; axis._scale._minLinearized = centerVal - range; axis._scale._maxLinearized = centerVal + range; // } axis._scale._minAuto = false; axis._scale._maxAuto = false; } }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The <see cref="LinearAsOrdinalScale" /> object from which to copy</param> /// <param name="owner">The <see cref="Axis" /> object that will own the /// new instance of <see cref="LinearAsOrdinalScale" /></param> public LinearAsOrdinalScale(Scale rhs, Axis owner) : base(rhs, owner) { }
/// <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="PaneBase.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, float scaleFactor ) { ValueHandler valueHandler = new ValueHandler( pane, false ); float pixBase, pixValue, pixLowValue; double scaleBase, scaleValue, scaleLowValue; if ( curve.Points != null && this.IsVisible ) { using ( Pen pen = !curve.IsSelected ? new Pen( _color, _penWidth ) : new Pen( Selection.Border.Color, Selection.Border.Width ) ) { // Loop over each defined point for ( int i = 0; i < curve.Points.Count; i++ ) { valueHandler.GetValues( 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._scale.IsLog ) && ( ( scaleValue > 0 && scaleLowValue > 0 ) || !valueAxis._scale.IsLog ) ) { pixBase = baseAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleBase ); pixValue = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleValue ); pixLowValue = valueAxis.Scale.Transform( curve.IsOverrideOrdinal, i, scaleLowValue ); //if ( this.fill.IsGradientValueType ) // brush = fill.MakeBrush( _rect, _points[i] ); this.Draw( g, pane, baseAxis is XAxis || baseAxis is X2Axis, pixBase, pixValue, pixLowValue, scaleFactor, pen, curve.IsSelected, curve.Points[i] ); } } } } }
/// <summary> /// Draw the this <see cref="Bar"/> to the specified <see cref="Graphics"/> /// device as a bar at each defined point. This method /// is normally only called by the <see cref="BarItem.Draw"/> method of the /// <see cref="BarItem"/> object /// </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="barWidth"> /// The width of each bar, in pixels. /// </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="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 DrawBars( Graphics g, GraphPane pane, CurveItem curve, Axis baseAxis, Axis valueAxis, float barWidth, int pos, double scaleFactor ) { // For Overlay and Stack bars, the position is always zero since the bars are on top // of eachother if ( pane.BarType == BarType.Overlay || pane.BarType == BarType.Stack || pane.BarType == BarType.PercentStack ) pos = 0; // Loop over each defined point for ( int i=0; i<curve.Points.Count; i++ ) DrawSingleBar( g, pane, curve, i, pos, baseAxis, valueAxis, scaleFactor ); }
/// <summary> /// Adds the data for the <paramref name="axis"/> to the <see cref="DataFrameBuilder.DataFrame"/>. /// If <paramref name="axis"/> is the <see cref="CurveItem.BaseAxis"/> then the column /// is added as the <see cref="DataFrame.RowHeader"/>, otherwise it is added /// to <see cref="DataFrame.ColumnGroups"/>. /// The X-Axis is usually the base axis, but for bar graphs that display horizontally, /// the Y-Axis is the base axis. /// </summary> protected virtual DataFrameBuilder AddColumnForAxis(DataFrameBuilder dataFrameBuilder, Axis axis) { var column = GetColumnForAxis(dataFrameBuilder, axis); if (column == null) { return dataFrameBuilder; } var dataFrame = dataFrameBuilder.DataFrame; if (dataFrame.RowHeader == null && ReferenceEquals(axis, dataFrameBuilder.BaseAxis)) { dataFrame = dataFrame.SetRowHeaders(column); } else { dataFrame = dataFrame.AddColumn(column); } return dataFrameBuilder.SetDataFrame(dataFrame); }
/// <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> /// Returns a <see cref="DataColumn"/> containing the values on the <paramref name="axis"/>. /// If <see cref="Scale.IsText"/> is true for the <see cref="Axis.Scale"/>, /// then the DataColumn will contain string values. /// </summary> protected virtual DataColumn GetColumnForAxis(DataFrameBuilder dataFrameBuilder, Axis axis) { if (axis == null) { return null; } if (axis.Scale.IsText) { var textValues = new string[dataFrameBuilder.Points.Count]; Array.Copy(axis.Scale.TextLabels, 0, textValues, 0, Math.Min(textValues.Length, axis.Scale.TextLabels.Length)); return new DataColumn<string>(axis.Title.Text, textValues); } if (axis.Scale.IsOrdinal) { return new DataColumn<int>(axis.Title.Text, Enumerable.Range(0, dataFrameBuilder.Points.Count)); } var values = new double[dataFrameBuilder.Points.Count]; var valueOfPoint = ValueOfPointFuncForAxis(dataFrameBuilder, axis); if (valueOfPoint != null) { for (int i = 0; i < dataFrameBuilder.Points.Count; i++) { values[i] = valueOfPoint(dataFrameBuilder.Points[i]); } } if (values.Any(value=>PointPairBase.Missing == value)) { var valuesWithNull = values.Select(value => PointPairBase.Missing == value ? (double?) null : value); return new DataColumn<double?>(axis.Title.Text, valuesWithNull); } return new DataColumn<double>(axis.Title.Text, values); }
private void SetSpace( Axis axis, float clientSize, ref float spaceNorm, ref float spaceAlt ) { //spaceNorm = 0; //spaceAlt = 0; float crossFrac = axis.CalcCrossFraction( this ); float crossPix = crossFrac * ( 1 + crossFrac ) * ( 1 + crossFrac * crossFrac ) * clientSize; if ( !axis.IsPrimary( this ) && axis.IsCrossShifted( this ) ) axis._tmpSpace = 0; if ( axis._tmpSpace < crossPix ) axis._tmpSpace = 0; else if ( crossPix > 0 ) axis._tmpSpace -= crossPix; if ( axis._scale._isLabelsInside && ( axis.IsPrimary( this ) || ( crossFrac != 0.0 && crossFrac != 1.0 ) ) ) spaceAlt = axis._tmpSpace; else spaceNorm = axis._tmpSpace; }
/// <summary> /// Determines whether <paramref name="axis"/> is the X-Axis or the Y-Axis, /// and returns a function that returns either <see cref="PointPair.X"/> or /// <see cref="PointPair.Y"/>. /// Returns null if the axis is neither. /// </summary> protected virtual Func<PointPair, double> ValueOfPointFuncForAxis(DataFrameBuilder dataFrameBuilder, Axis axis) { if (axis is XAxis || axis is X2Axis || ReferenceEquals(axis, dataFrameBuilder.XAxis)) { return point => point.X; } if (axis is YAxis || axis is Y2Axis || ReferenceEquals(axis, dataFrameBuilder.YAxis)) { return point => point.Y; } Trace.TraceError("Could not determine type of axis {0}", axis); // Not L10N return null; }