/// <summary> /// /// </summary> private void SetMinorTicStyle(ZedGraph.MinorTic minorTic) { minorTic.IsAllTics = false; minorTic.IsCrossInside = false; minorTic.IsCrossOutside = false; minorTic.IsInside = true; minorTic.IsOpposite = false; minorTic.IsOutside = false; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="rhs">The <see cref="MinorTic" /> that is to be copied.</param> public MinorTic(MinorTic rhs) { _size = rhs._size; _color = rhs._color; _penWidth = rhs._penWidth; this.IsOutside = rhs.IsOutside; this.IsInside = rhs.IsInside; this.IsOpposite = rhs.IsOpposite; _isCrossOutside = rhs._isCrossOutside; _isCrossInside = rhs._isCrossInside; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="rhs">The <see cref="MinorTic" /> that is to be copied.</param> public MinorTic( MinorTic rhs ) { _size = rhs._size; _color = rhs._color; _penWidth = rhs._penWidth; this.IsOutside = rhs.IsOutside; this.IsInside = rhs.IsInside; this.IsOpposite = rhs.IsOpposite; _isCrossOutside = rhs._isCrossOutside; _isCrossInside = rhs._isCrossInside; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="rhs">The <see cref="MinorTic" /> that is to be copied.</param> public MinorTic(MinorTic rhs) { Size = rhs.Size; Color = rhs.Color; PenWidth = rhs.PenWidth; IsOutside = rhs.IsOutside; IsInside = rhs.IsInside; IsOpposite = rhs.IsOpposite; IsCrossOutside = rhs.IsCrossOutside; IsCrossInside = rhs.IsCrossInside; }
/// <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; }
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; } }
internal void DrawHourMinuteLabels(Graphics g, GraphPane pane, MinorTic tic, MinorGrid grid, bool drawGrid, float topPix, float rightPix, float shift, float scaleFactor) { XDate xStartInterval = new XDate(_minLinTemp); DateTime dtStartInterval = xStartInterval.DateTime; DateTime dtEndInterval; string labelText = "24:00"; SizeF labelBox = _fontSpec.BoundingBox(g, labelText, scaleFactor); float labelWidth = labelBox.Width + 4; float labelWidthHalf = labelWidth / 2; float scaledTic = tic.ScaledTic(scaleFactor); float textVerticalCenter = GetTextVerticalCenter(g, pane, scaledTic, labelBox.Height, shift, scaleFactor); double dStartInterval, dEndInterval; float pStartInterval, pEndInterval, pIntervalWidth; int year = dtStartInterval.Year; int month = dtStartInterval.Month; int day = dtStartInterval.Day; int hour = dtStartInterval.Hour; int minute = dtStartInterval.Minute; int second = dtStartInterval.Second; dtStartInterval = new DateTime(year, month, day, 0, 0, 0); dStartInterval = dtStartInterval.ToOADate(); pStartInterval = LocalTransform(dStartInterval); dtEndInterval = dtStartInterval.AddMinutes(1); dEndInterval = dtEndInterval.ToOADate(); pEndInterval = LocalTransform(dEndInterval); pIntervalWidth = pEndInterval - pStartInterval; int minutesPerLabel = RoundNumber((int)Math.Ceiling(labelWidth / pIntervalWidth), roundMinutes); dtEndInterval = dtStartInterval.AddMinutes(minutesPerLabel); dEndInterval = dtEndInterval.ToOADate(); while (dStartInterval < _maxLinTemp) { int minutesHours = hour * 60 + minute; dtEndInterval = dtStartInterval.AddMinutes(minutesPerLabel); dEndInterval = dtEndInterval.ToOADate(); TruncateIntervalDrawTicGrid(g, pane, topPix, tic, grid, drawGrid, shift, scaleFactor, scaledTic, ref dStartInterval, ref dEndInterval, out pStartInterval, out pEndInterval, out pIntervalWidth); //if label will not extend beyond left or right edge of this axis, draw it if (!drawGrid && this.IsVisible && (pStartInterval - labelWidthHalf > 0) && (pStartInterval + labelWidthHalf) < rightPix) { labelText = hour.ToString() + ":" + ((minute < 10) ? "0" : "") + minute.ToString(); _fontSpec.Draw(g, pane, labelText, pStartInterval, textVerticalCenter, AlignH.Center, AlignV.Center, scaleFactor); } dtStartInterval = dtStartInterval.AddMinutes(minutesPerLabel); hour = dtStartInterval.Hour; minute = dtStartInterval.Minute; dStartInterval = dtStartInterval.ToOADate(); } }
internal void DrawDayLabels(Graphics g, GraphPane pane, MinorTic tic, MinorGrid grid, bool drawGrid, float topPix, float rightPix, float shift, float scaleFactor, bool includeMonthYear) { int year; int month; int day; XDate xStartInterval = new XDate(_minLinTemp); XDate xEndInterval; string labelText = "28"; if (includeMonthYear) { labelText = "2000 " + MonthNamesAbbreviated[1] + " 28"; } SizeF labelBox = _fontSpec.BoundingBox(g, labelText, scaleFactor); float labelWidth = labelBox.Width + 4; float labelWidthHalf = labelWidth / 2; float ticShift = (includeMonthYear ? (shift + labelBox.Height / 2) : shift); float scaledTic = tic.ScaledTic(scaleFactor); float textVerticalCenter = GetTextVerticalCenter(g, pane, scaledTic, labelBox.Height, shift, scaleFactor); float textHorizontalCenter; double dStartInterval, dEndInterval; float pStartInterval, pEndInterval, pIntervalWidth; xStartInterval.GetDate(out year, out month, out day); xStartInterval.SetDate(year, month, 1); xEndInterval = new XDate(year, month, 2); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; pStartInterval = LocalTransform(dStartInterval); pEndInterval = LocalTransform(dEndInterval); pIntervalWidth = pEndInterval - pStartInterval; int daysPerLabel = RoundNumber((int)Math.Ceiling(labelWidth / pIntervalWidth), roundNumbers); while (dStartInterval < _maxLinTemp) { TruncateIntervalDrawTicGrid(g, pane, topPix, tic, grid, drawGrid, ticShift + (includeMonthYear ? scaledTic : 0), scaleFactor, scaledTic, ref dStartInterval, ref dEndInterval, out pStartInterval, out pEndInterval, out pIntervalWidth); if (!drawGrid && this.IsVisible && pIntervalWidth > 1) { if (((int)(day / daysPerLabel)) * daysPerLabel == day) { textHorizontalCenter = (pStartInterval + pEndInterval) / 2; //if label will not extend beyond left or right edge of this axis, draw it if ((textHorizontalCenter - labelWidthHalf > 0) && (textHorizontalCenter + labelWidthHalf) < rightPix) { labelText = day.ToString(); if (includeMonthYear) { labelText = year + " " + MonthNamesAbbreviated[month - 1] + " " + labelText; } _fontSpec.Draw(g, pane, labelText, textHorizontalCenter, textVerticalCenter, AlignH.Center, AlignV.Center, scaleFactor); } } } xStartInterval.AddDays(1); xStartInterval.GetDate(out year, out month, out day); // = new XDate(endInterval); dStartInterval = xStartInterval.XLDate; xEndInterval.AddDays(1); dEndInterval = xEndInterval.XLDate; } }
private int WhichMonthLabels(Graphics g, GraphPane pane, float topPix, float rightPix, float shift, float scaleFactor, bool includeYear) { bool FullFit = true; bool AbbrevFit = true; bool CharFit = true; int year; int month; int day; string yearText = ""; XDate xStartInterval = new XDate(_minLinTemp); XDate xEndInterval; string labelText = "0"; SizeF labelBox = _fontSpec.BoundingBox(g, labelText, scaleFactor); float ticShift = (includeYear ? (shift + labelBox.Height / 2) : shift); float charWidth = labelBox.Width; MinorGrid grid = _ownerAxis._minorGrid; MinorTic tic = _ownerAxis._minorTic; float scaledTic = tic.ScaledTic(scaleFactor); float textVerticalCenter = GetTextVerticalCenter(g, pane, scaledTic, labelBox.Height, shift, scaleFactor); double dStartInterval, dEndInterval; float pStartInterval, pEndInterval, pIntervalWidth; xStartInterval.GetDate(out year, out month, out day); if (day != 1) { xStartInterval.SetDate(year, month, 1); } xEndInterval = new XDate(xStartInterval); xEndInterval.AddMonths(1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; while (dStartInterval < _maxLinTemp) { TruncateIntervalDrawTicGrid(g, pane, topPix, tic, grid, false, ticShift, scaleFactor, scaledTic, ref dStartInterval, ref dEndInterval, out pStartInterval, out pEndInterval, out pIntervalWidth); // If the width of the interval is at least wide enough for a character // and we have more than 27 days, try displaying a month label if (pIntervalWidth > charWidth && (dEndInterval - dStartInterval > 27)) { if (includeYear) { yearText = " " + year; } if (FullFit) // First try to fit whole month name { FullFit = LabelFits(g, scaleFactor, MonthNamesFull[month - 1] + yearText, pIntervalWidth); } if (AbbrevFit) // Next try to fit abbreviated month name { AbbrevFit = LabelFits(g, scaleFactor, MonthNamesAbbreviated[month - 1] + yearText, pIntervalWidth); } if (CharFit) // Finally try to fit first letter of month name { CharFit = LabelFits(g, scaleFactor, labelText.Substring(0, 1) + yearText, pIntervalWidth); } } xStartInterval.AddMonths(1); // = new XDate(endInterval); xEndInterval.AddMonths(1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; xStartInterval.GetDate(out year, out month, out day); } if (FullFit) { return(3); } if (AbbrevFit) { return(2); } if (CharFit) { return(1); } return(0); }
internal void DrawMonthLabels(Graphics g, GraphPane pane, MinorTic tic, MinorGrid grid, bool drawGrid, float topPix, float rightPix, float shift, float scaleFactor, bool includeYear) { int year; int month; int day; int MonthLabelType = WhichMonthLabels(g, pane, topPix, rightPix, shift, scaleFactor, includeYear); XDate xStartInterval = new XDate(_minLinTemp); XDate xEndInterval; string labelText = "0"; SizeF labelBox = _fontSpec.BoundingBox(g, labelText, scaleFactor); float ticShift = (includeYear ? (shift + labelBox.Height / 2) : shift); float charWidth = labelBox.Width; float scaledTic = tic.ScaledTic(scaleFactor); float textVerticalCenter = GetTextVerticalCenter(g, pane, scaledTic, labelBox.Height, shift, scaleFactor); double dStartInterval, dEndInterval; float pStartInterval, pEndInterval, pIntervalWidth; SizeF labelSize; xStartInterval.GetDate(out year, out month, out day); if (day != 1) { xStartInterval.SetDate(year, month, 1); } xEndInterval = new XDate(xStartInterval); xEndInterval.AddMonths(1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; // draw tics and labels dStartInterval = xStartInterval.XLDate; while (dStartInterval < _maxLinTemp) { TruncateIntervalDrawTicGrid(g, pane, topPix, tic, grid, drawGrid, ticShift, scaleFactor, scaledTic, ref dStartInterval, ref dEndInterval, out pStartInterval, out pEndInterval, out pIntervalWidth); // If the width of the interval is at least wide enough for a character, // try displaying a month label if (!drawGrid && this.IsVisible && pIntervalWidth > charWidth) { labelText = ""; switch (MonthLabelType) { case 3: labelText = MonthNamesFull[month - 1]; break; case 2: labelText = MonthNamesAbbreviated[month - 1]; break; case 1: labelText = MonthNamesAbbreviated[month - 1].Substring(0, 1); break; } if (includeYear) { labelText += " " + year; } labelSize = _fontSpec.BoundingBox(g, labelText, scaleFactor); if (labelSize.Width >= pIntervalWidth) { labelText = ""; } if (labelText.Length > 0) { _fontSpec.Draw(g, pane, labelText, (pStartInterval + pEndInterval) / 2, textVerticalCenter, AlignH.Center, AlignV.Center, scaleFactor); } } xStartInterval.AddMonths(1); // = new XDate(endInterval); xEndInterval.AddMonths(1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; xStartInterval.GetDate(out year, out month, out day); } }
internal void DrawYearLabels(Graphics g, GraphPane pane, MinorTic tic, MinorGrid grid, bool drawGrid, float topPix, float rightPix, float shift, float scaleFactor) { int year; int month; int day; XDate xStartInterval = new XDate(_minLinTemp); XDate xEndInterval; string labelText = "2000"; SizeF labelBox = _fontSpec.BoundingBox(g, labelText, scaleFactor); float labelWidth = labelBox.Width + 4; float labelWidthHalf = labelWidth / 2; float scaledTic = tic.ScaledTic(scaleFactor); float textVerticalCenter = GetTextVerticalCenter(g, pane, scaledTic, labelBox.Height, shift, scaleFactor); float textHorizontalCenter; double dStartInterval, dEndInterval; float pStartInterval, pEndInterval, pIntervalWidth; xStartInterval.GetDate(out year, out month, out day); xStartInterval.SetDate(year, 1, 1); xEndInterval = new XDate(year + 1, 1, 1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; pStartInterval = LocalTransform(dStartInterval); pEndInterval = LocalTransform(dEndInterval); pIntervalWidth = pEndInterval - pStartInterval; int yearsPerLabel = RoundNumber((int)Math.Ceiling(labelWidth / pIntervalWidth), roundNumbers); int yearsPerTic = RoundNumber((int)Math.Ceiling(10 / pIntervalWidth), roundNumbers); while (dStartInterval < _maxLinTemp) { bool labelThisYear = ((year / yearsPerLabel) * yearsPerLabel == year); if (labelThisYear || ((year / yearsPerTic) * yearsPerTic == year)) { TruncateIntervalDrawTicGrid(g, pane, topPix, tic, grid, drawGrid, shift, scaleFactor, scaledTic, ref dStartInterval, ref dEndInterval, out pStartInterval, out pEndInterval, out pIntervalWidth); if (!drawGrid && this.IsVisible && labelThisYear) { textHorizontalCenter = (pStartInterval + pEndInterval) / 2; //if label will not extend beyond left or right edge of this axis, draw it if ((textHorizontalCenter - labelWidthHalf > 0) && (textHorizontalCenter + labelWidthHalf) < rightPix) { labelText = year.ToString(); _fontSpec.Draw(g, pane, labelText, textHorizontalCenter, textVerticalCenter, AlignH.Center, AlignV.Center, scaleFactor); } } } year += 1; xStartInterval.SetDate(year, 1, 1); // = new XDate(endInterval); xEndInterval.SetDate(year + 1, 1, 1); dStartInterval = xStartInterval.XLDate; dEndInterval = xEndInterval.XLDate; } }
private void TruncateIntervalDrawTicGrid(Graphics g, GraphPane pane, float topPix, MinorTic tic, MinorGrid grid, bool drawGrid, float shift, float scaleFactor, float scaledTic, ref double dStartInterval, ref double dEndInterval, out float pStartInterval, out float pEndInterval, out float pIntervalWidth) { bool movedStart = false; bool movedEnd = false; if (dStartInterval < _minLinTemp) { dStartInterval = _minLinTemp; movedStart = true; } if (dEndInterval > _maxLinTemp) { dEndInterval = _maxLinTemp; movedEnd = true; } pStartInterval = LocalTransform(dStartInterval); pEndInterval = LocalTransform(dEndInterval); pIntervalWidth = pEndInterval - pStartInterval; if (pIntervalWidth > 0) { Pen lPen; if (drawGrid) { lPen = grid.GetPen(pane, scaleFactor); } else { lPen = tic.GetPen(pane, scaleFactor); } if (!movedStart) { if (drawGrid) { grid.Draw(g, lPen, pStartInterval, topPix); } else { tic.Draw(g, pane, lPen, pStartInterval, topPix, shift, scaledTic); } } if (!movedEnd && pIntervalWidth > 2) { if (drawGrid) { grid.Draw(g, lPen, pEndInterval, topPix); } else { tic.Draw(g, pane, lPen, pEndInterval, topPix, shift, scaledTic); } } } }