/// <summary> /// /// </summary> /// <param name="majorTic"></param> private void SetMajorTicStyle(ZedGraph.MajorTic majorTic) { majorTic.IsAllTics = false; majorTic.IsBetweenLabels = false; majorTic.IsCrossInside = false; majorTic.IsCrossOutside = false; majorTic.IsInside = true; majorTic.IsOpposite = false; majorTic.IsOutside = false; }
/// <summary> /// Constructor for deserializing objects /// </summary> /// <param name="info">A <see cref="SerializationInfo"/> instance that defines the serialized data /// </param> /// <param name="context">A <see cref="StreamingContext"/> instance that contains the serialized data /// </param> protected Axis( SerializationInfo info, StreamingContext context ) { // The schema value is just a file version parameter. You can use it to make future versions // backwards compatible as new member variables are added to classes int sch = info.GetInt32( "schema" ); _cross = info.GetDouble( "cross" ); _crossAuto = info.GetBoolean( "crossAuto" ); _majorTic = (MajorTic)info.GetValue( "MajorTic", typeof( MajorTic ) ); _minorTic = (MinorTic)info.GetValue( "MinorTic", typeof( MinorTic ) ); _majorGrid = (MajorGrid)info.GetValue( "majorGrid", typeof( MajorGrid ) ); _minorGrid = (MinorGrid)info.GetValue( "minorGrid", typeof( MinorGrid ) ); _isVisible = info.GetBoolean( "isVisible" ); _title = (AxisLabel) info.GetValue( "title", typeof( AxisLabel ) ); _minSpace = info.GetSingle( "minSpace" ); _color = (Color)info.GetValue( "color", typeof( Color ) ); _isAxisSegmentVisible = info.GetBoolean( "isAxisSegmentVisible" ); _axisGap = info.GetSingle( "axisGap" ); _scale = (Scale)info.GetValue( "scale", typeof( Scale ) ); _scale._ownerAxis = this; }
/// <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; }
/// <summary> /// Default constructor for <see cref="Axis"/> that sets all axis properties /// to default values as defined in the <see cref="Default"/> class. /// </summary> public Axis() { _scale = new LinearScale( this ); _cross = 0.0; _crossAuto = true; _majorTic = new MajorTic(); _minorTic = new MinorTic(); _majorGrid = new MajorGrid(); _minorGrid = new MinorGrid(); _axisGap = Default.AxisGap; _minSpace = Default.MinSpace; _isVisible = true; _isAxisSegmentVisible = Default.IsAxisSegmentVisible; _title = new AxisLabel( "", Default.TitleFontFamily, Default.TitleFontSize, Default.TitleFontColor, Default.TitleFontBold, Default.TitleFontUnderline, Default.TitleFontItalic ); _title.FontSpec.Fill = new Fill( Default.TitleFillColor, Default.TitleFillBrush, Default.TitleFillType ); _title.FontSpec.Border.IsVisible = false; _color = Default.Color; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="rhs">The <see cref="MajorTic" /> that is to be copied.</param> public MajorTic(MajorTic rhs) : base(rhs) { _isBetweenLabels = rhs._isBetweenLabels; }
internal void Draw(Graphics g, GraphPane pane, float scaleFactor, float shiftPos, bool drawGrid) { float rightPix, topPix; if (_ownerAxis is XAxis) { rightPix = pane.Chart._rect.Width; topPix = -pane.Chart._rect.Height; } else { rightPix = pane.Chart._rect.Height; topPix = -pane.Chart._rect.Width; } // sanity check if (_min >= _max) { return; } MajorGrid majorGrid = _ownerAxis._majorGrid; MajorTic majorTic = _ownerAxis._majorTic; MinorTic tic = _ownerAxis._minorTic; MinorGrid grid = _ownerAxis._minorGrid; if (!drawGrid) { 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); } _ownerAxis.DrawTitle(g, pane, 0, scaleFactor); } // draw the time scales that fit best bool[] drawThese = DrawWhich((_maxLinTemp - _minLinTemp)); // Note: the Draw*Labels routines draw tics or grids too if (drawThese[(int)DateUnit.Hour]) { DrawHourMinuteLabels(g, pane, tic, grid, drawGrid, topPix, rightPix, shiftPos, scaleFactor); shiftPos += _fontSpec.GetHeight(scaleFactor) * 1.1F; tic = majorTic; grid = majorGrid; } if (drawThese[(int)DateUnit.Day]) { DrawDayLabels(g, pane, tic, grid, drawGrid, topPix, rightPix, shiftPos, scaleFactor, !drawThese[(int)DateUnit.Month]); shiftPos += _fontSpec.GetHeight(scaleFactor) * 1.1F; tic = majorTic; grid = majorGrid; } if (drawThese[(int)DateUnit.Month]) { DrawMonthLabels(g, pane, tic, grid, drawGrid, topPix, rightPix, shiftPos, scaleFactor, !drawThese[(int)DateUnit.Year]); shiftPos += _fontSpec.GetHeight(scaleFactor) * 1.1F; } if (drawThese[(int)DateUnit.Year]) { DrawYearLabels(g, pane, majorTic, majorGrid, drawGrid, topPix, rightPix, shiftPos, scaleFactor); shiftPos += _fontSpec.GetHeight(scaleFactor) * 1.1F; } }
/// <summary> /// Draw the value labels, tic marks, 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="baseVal"> /// The first major tic value for the axis /// </param> /// <param name="nTics"> /// The total number of major tics for the axis /// </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> /// <param name="shift">The number of pixels to shift this axis, based on the /// value of <see cref="Axis.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> internal override void DrawLabels(Graphics g, GraphPane pane, double baseVal, int nTics, float topPix, float shift, float scaleFactor) { int lNtics = Percentages.Length; MajorTic tic = _ownerAxis._majorTic; // MajorGrid grid = _ownerAxis._majorGrid; double dVal; float pixVal; float scaledTic = tic.ScaledTic(scaleFactor); using (Pen ticPen = tic.GetPen(pane, scaleFactor)) // using ( Pen gridPen = grid.GetPen( pane, scaleFactor ) ) { // get the Y position of the center of the axis labels // (the axis itself is referenced at zero) SizeF maxLabelSize = GetScaleMaxSpace(g, pane, scaleFactor, true); float charHeight = _fontSpec.GetHeight(scaleFactor); float maxSpace = maxLabelSize.Height; float edgeTolerance = Default.EdgeTolerance * scaleFactor; double rangeTol = (_maxLinTemp - _minLinTemp) * 0.001; int firstTic = 0; // save the position of the previous tic float lastPixVal = -10000; // loop for each major tic for (int i = firstTic; i < lNtics + firstTic; i++) { dVal = CalcMajorTicValue(baseVal, i); double linVal = dVal; // Linearize(dVal); // If we're before the start of the scale, just go to the next tic if (linVal < _minLinTemp) { continue; } // if we've already past the end of the scale, then we're done if (linVal > _maxLinTemp + rangeTol) { break; } // convert the value to a pixel position pixVal = LocalTransform(linVal); tic.Draw(g, pane, ticPen, pixVal, topPix, shift, scaledTic); // draw the grid // grid.Draw( g, gridPen, pixVal2, topPix ); bool isMaxValueAtMaxPix = ((_ownerAxis is XAxis || _ownerAxis is Y2Axis) && !IsReverse) || (_ownerAxis is Y2Axis && IsReverse); bool isSkipZone = (((_isSkipFirstLabel && isMaxValueAtMaxPix) || (_isSkipLastLabel && !isMaxValueAtMaxPix)) && pixVal < edgeTolerance) || (((_isSkipLastLabel && isMaxValueAtMaxPix) || (_isSkipFirstLabel && !isMaxValueAtMaxPix)) && pixVal > _maxPix - _minPix - edgeTolerance); bool isSkipCross = _isSkipCrossLabel && !_ownerAxis._crossAuto && Math.Abs(_ownerAxis._cross - dVal) < rangeTol * 10.0; isSkipZone = isSkipZone || isSkipCross; if (_isVisible && !isSkipZone) { // For exponential scales, just skip any label that would overlap with the previous one // This is because exponential scales have varying label spacing if (IsPreventLabelOverlap && Math.Abs(pixVal - lastPixVal) < maxLabelSize.Width) { continue; } DrawLabel(g, pane, i, dVal, pixVal, shift, maxSpace, scaledTic, charHeight, scaleFactor); lastPixVal = pixVal; } } } }