/// <summary> /// Creates the date tick values. /// </summary> /// <param name="min"> /// The min. /// </param> /// <param name="max"> /// The max. /// </param> /// <param name="step"> /// The step. /// </param> /// <param name="intervalType"> /// Type of the interval. /// </param> /// <returns> /// Date tick values. /// </returns> private IList <double> CreateDateTickValues( double min, double max, double step, DateTimeIntervalType intervalType) { DateTime start = ToDateTime(min); switch (intervalType) { case DateTimeIntervalType.Weeks: // make sure the first tick is at the 1st day of a week start = start.AddDays(-(int)start.DayOfWeek + (int)this.FirstDayOfWeek); break; case DateTimeIntervalType.Months: // make sure the first tick is at the 1st of a month start = new DateTime(start.Year, start.Month, 1); break; case DateTimeIntervalType.Years: // make sure the first tick is at Jan 1st start = new DateTime(start.Year, 1, 1); break; } // Adds a tick to the end time to make sure the end DateTime is included. DateTime end = ToDateTime(max).AddTicks(1); DateTime current = start; var values = new Collection <double>(); double eps = step * 1e-3; DateTime minDateTime = ToDateTime(min - eps); DateTime maxDateTime = ToDateTime(max + eps); while (current < end) { if (current > minDateTime && current < maxDateTime) { values.Add(ToDouble(current)); } switch (intervalType) { case DateTimeIntervalType.Months: current = current.AddMonths((int)Math.Ceiling(step)); break; case DateTimeIntervalType.Years: current = current.AddYears((int)Math.Ceiling(step)); break; default: current = current.AddDays(step); break; } } return(values); }
/// <summary> /// IntervalTypeProperty property changed handler. /// </summary> /// <param name="d">DateTimeAxis that changed its InternalIntervalType.</param> /// <param name="e">Event arguments.</param> private static void OnIntervalTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DateTimeAxis source = (DateTimeAxis)d; DateTimeIntervalType newValue = (DateTimeIntervalType)e.NewValue; source.OnIntervalTypePropertyChanged(newValue); }
public void SetTempAxisScaleAndInterval() { if (this.oldAxisSettings.Count == 0) { this.oldAxisSettings.Push(this.axis.maximum); this.oldAxisSettings.Push(this.axis.minimum); this.oldAxisSettings.Push(this.axis.majorGrid.interval); this.oldAxisSettings.Push(this.axis.majorGrid.intervalType); this.oldAxisSettings.Push(this.axis.majorGrid.intervalOffset); this.oldAxisSettings.Push(this.axis.majorGrid.intervalOffsetType); this.oldAxisSettings.Push(this.axis.majorTickMark.interval); this.oldAxisSettings.Push(this.axis.majorTickMark.intervalType); this.oldAxisSettings.Push(this.axis.majorTickMark.intervalOffset); this.oldAxisSettings.Push(this.axis.majorTickMark.intervalOffsetType); this.oldAxisSettings.Push(this.axis.LabelStyle.interval); this.oldAxisSettings.Push(this.axis.LabelStyle.intervalType); this.oldAxisSettings.Push(this.axis.LabelStyle.intervalOffset); this.oldAxisSettings.Push(this.axis.LabelStyle.intervalOffsetType); } this.axis.maximum = this.ScaleMaximum; this.axis.minimum = this.ScaleMinimum; this.axis.majorGrid.interval = this.Interval; this.axis.majorGrid.intervalType = this.IntervalType; this.axis.majorGrid.intervalOffset = this.IntervalOffset; this.axis.majorGrid.intervalOffsetType = this.IntervalOffsetType; this.axis.majorTickMark.interval = this.Interval; this.axis.majorTickMark.intervalType = this.IntervalType; this.axis.majorTickMark.intervalOffset = this.IntervalOffset; this.axis.majorTickMark.intervalOffsetType = this.IntervalOffsetType; this.axis.LabelStyle.interval = this.Interval; this.axis.LabelStyle.intervalType = this.IntervalType; this.axis.LabelStyle.intervalOffset = this.IntervalOffset; this.axis.LabelStyle.intervalOffsetType = this.IntervalOffsetType; }
/// <summary> /// ViewEventArgs constructor. /// </summary> /// <param name="axis">Axis of the scale view.</param> /// <param name="newPosition">New scale view start position.</param> /// <param name="newSize">New scale view size.</param> /// <param name="newSizeType">New unit of measurement of the size.</param> public ViewEventArgs(Axis axis, double newPosition, double newSize, DateTimeIntervalType newSizeType) { _axis = axis; NewPosition = newPosition; NewSize = newSize; _newSizeType = newSizeType; }
/// <summary> /// Initialize internal scrolling line size variables for later use. /// This size is used in to scroll chart one line up or down. /// </summary> private void GetCurrentViewSmallScrollSize() { //************************************************************************** //** Check if current scrolling line size was not already calculated //************************************************************************** if (double.IsNaN(_currentSmallScrollSize)) { //************************************************************************** //** Calculate line size depending on the current scaleView size //************************************************************************** if (SizeType == DateTimeIntervalType.Auto || SizeType == DateTimeIntervalType.Number) { // Set line size type _currentSmallScrollSizeType = DateTimeIntervalType.Number; // Devide scaleView by 20 to find the scrolling line size double newSize = Size / 20.0; // Make sure that current line size is even with minimum value if (!double.IsNaN(SmallScrollMinSize) && SmallScrollMinSize != 0.0) { double rounder = (Math.Round(newSize / SmallScrollMinSize)); if (rounder < 0) { rounder = 1; } newSize = rounder * SmallScrollMinSize; } // Set new current line size _currentSmallScrollSize = newSize; } else { // Calculate line size for date/time double viewEndPosition = Position + ChartHelper.GetIntervalSize(Position, Size, SizeType); _currentSmallScrollSize = axis.CalcInterval( Position, viewEndPosition, true, out _currentSmallScrollSizeType, ChartValueType.Auto); } //************************************************************************** //** Make sure calculated scroll line size is not smaller than the minimum //************************************************************************** if (!double.IsNaN(SmallScrollMinSize) && SmallScrollMinSize != 0.0) { double newLineSize = ChartHelper.GetIntervalSize(Position, _currentSmallScrollSize, _currentSmallScrollSizeType); double minLineSize = ChartHelper.GetIntervalSize(Position, SmallScrollMinSize, SmallScrollMinSizeType); if (newLineSize < minLineSize) { _currentSmallScrollSize = SmallScrollMinSize; _currentSmallScrollSizeType = SmallScrollMinSizeType; } } } }
/// <summary> /// Sets interval properties for the axis. /// Note that we use the Axis object's interval properties, and not the properties of its label, /// and major tick mark and grid line objects /// </summary> public void SetAxisInterval(Axis axis, double interval, DateTimeIntervalType intervalType, double intervalOffset, DateTimeIntervalType intervalOffsetType) { // Set interval-related properties axis.Interval = interval; axis.IntervalType = intervalType; axis.IntervalOffset = intervalOffset; axis.IntervalOffsetType = intervalOffsetType; }
/// <summary> /// Sets interval properties for the axis. /// Note that we use the Axis object's interval properties, and not the properties of its label, /// and major tick mark and grid line objects /// </summary> public void SetAxisInterval(Axis axis, double interval, DateTimeIntervalType intervalType, double intervalOffset, DateTimeIntervalType intervalOffsetType ) { // Set interval-related properties axis.Interval = interval; axis.IntervalType = intervalType; axis.IntervalOffset = intervalOffset; axis.IntervalOffsetType = intervalOffsetType; }
/// <summary> /// 图表区X轴游标设置 /// </summary> /// <param name="chart">图表对象</param> /// <param name="enable">启用/禁用游标用户界面和图表区范围选择用户界面</param> /// <param name="Interval">游标移动间隔</param> /// <param name="Intervaltype">游标移动间隔类型</param> public static void SetCursorX(Chart chart, bool enable, int Interval, DateTimeIntervalType Intervaltype) { chart.ChartAreas[0].CursorX.IsUserEnabled = enable; chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = enable; chart.ChartAreas[0].CursorX.Interval = Interval; chart.ChartAreas[0].CursorX.IntervalOffset = Interval; chart.ChartAreas[0].CursorX.IntervalType = Intervaltype; }
/// <summary> /// IntervalTypeProperty property changed handler. /// </summary> /// <param name="d">DateTimeAxisLabel that changed its IntervalType.</param> /// <param name="e">Event arguments.</param> private static void OnIntervalTypePropertyChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) { DateTimeAxisLabel source = (DateTimeAxisLabel)d; DateTimeIntervalType oldValue = (DateTimeIntervalType)e.OldValue; DateTimeIntervalType newValue = (DateTimeIntervalType)e.NewValue; source.OnIntervalTypePropertyChanged(oldValue, newValue); }
/// <summary> /// Sets interval properties for the axis. /// Note that we use the Axis object's interval properties, and not the properties of its label, /// and major tick mark and grid line objects /// </summary> public void SetAxisInterval(System.Web.UI.DataVisualization.Charting.Axis axis, double interval, DateTimeIntervalType intervalType, double intervalOffset, DateTimeIntervalType intervalOffsetType ) { // Set interval-related properties axis.Interval = interval; axis.IntervalType = intervalType; axis.IntervalOffset = intervalOffset; axis.IntervalOffsetType = intervalOffsetType; }
/// <summary> /// This method accepts a date time and increments it. /// </summary> /// <param name="date">A date time.</param> /// <param name="interval"> /// The interval used to increment the date time. /// </param> /// <returns>The new date time.</returns> private DateTime IncrementDateTime(DateTime date, double interval) { DateTimeIntervalType intervalType = ActualIntervalType; var span = new TimeSpan(0); if (intervalType == DateTimeIntervalType.Days) { span = TimeSpan.FromDays(interval); } else if (intervalType == DateTimeIntervalType.Hours) { span = TimeSpan.FromHours(interval); } else if (intervalType == DateTimeIntervalType.Milliseconds) { span = TimeSpan.FromMilliseconds(interval); } else if (intervalType == DateTimeIntervalType.Seconds) { span = TimeSpan.FromSeconds(interval); } else if (intervalType == DateTimeIntervalType.Minutes) { span = TimeSpan.FromMinutes(interval); } else if (intervalType == DateTimeIntervalType.Weeks) { span = TimeSpan.FromDays(7.0 * interval); } else if (intervalType == DateTimeIntervalType.Months) { // Special case handling when current date point // to the last day of the month bool lastMonthDay = date.Day == DateTime.DaysInMonth(date.Year, date.Month); // Add specified amount of months date = date.AddMonths((int)Math.Floor(interval)); span = TimeSpan.FromDays(30.0 * (interval - Math.Floor(interval))); // Check if last month of the day was used if (lastMonthDay && span.Ticks == 0) { // Make sure the last day of the month is selected int daysInMobth = DateTime.DaysInMonth(date.Year, date.Month); date = date.AddDays(daysInMobth - date.Day); } } else if (intervalType == DateTimeIntervalType.Years) { date = date.AddYears((int)Math.Floor(interval)); span = TimeSpan.FromDays(365.0 * (interval - Math.Floor(interval))); } DateTime result = date.Add(span); return(result); }
/// <summary> /// Internal helper zooming method. /// </summary> /// <param name="viewPosition">New data scaleView start posiion.</param> /// <param name="viewSize">New data scaleView size.</param> /// <param name="viewSizeType">New data scaleView size units type.</param> /// <param name="fireChangeEvents">Fire scaleView position events from this method.</param> /// <param name="saveState">Indicates that current scaleView size/position must be save, so it can be restored later.</param> /// <returns>True if zoom operation was made.</returns> internal bool Zoom( double viewPosition, double viewSize, DateTimeIntervalType viewSizeType, bool fireChangeEvents, bool saveState) { // Validate new scaleView position and size ValidateViewPositionSize(ref viewPosition, ref viewSize, ref viewSizeType); // Fire scaleView position/size changing events ViewEventArgs arguments = new(axis, viewPosition, viewSize, viewSizeType); if (fireChangeEvents && GetChartObject() != null) { GetChartObject().OnAxisViewChanging(arguments); viewPosition = arguments.NewPosition; viewSize = arguments.NewSize; viewSizeType = arguments.NewSizeType; } // Check if data scaleView position and size is different from current if (viewPosition == Position && viewSize == Size && viewSizeType == SizeType) { return(false); } // Save current data scaleView state, so it can be restored if (saveState) { SaveDataViewState(); } // Change scaleView position/size _ignoreValidation = true; Position = viewPosition; Size = viewSize; SizeType = viewSizeType; _ignoreValidation = false; // Reset current scrolling line size _currentSmallScrollSize = double.NaN; // Invalidate chart axis.Invalidate(); // Fire scaleView position/size changed events if (fireChangeEvents && GetChartObject() != null) { GetChartObject().OnAxisViewChanged(arguments); } return(true); }
private double GetLogMinimum(double current, Series axisSeries) { double num = axis.GetViewMinimum(); DateTimeIntervalType type = (IntervalOffsetType == DateTimeIntervalType.Auto) ? IntervalType : IntervalOffsetType; if (IntervalOffset != 0.0 && !double.IsNaN(IntervalOffset) && axisSeries == null) { num += axis.GetIntervalSize(num, IntervalOffset, type, axisSeries, 0.0, DateTimeIntervalType.Number, forceIntIndex: true, forceAbsInterval: false); } return(num + Math.Floor(current - num)); }
private double GetLogMinimum(double current, Series axisSeries) { double num = this.axis.GetViewMinimum(); DateTimeIntervalType type = (this.IntervalOffsetType == DateTimeIntervalType.Auto) ? this.IntervalType : this.IntervalOffsetType; if (this.IntervalOffset != 0.0 && !double.IsNaN(this.IntervalOffset) && axisSeries == null) { num += this.axis.GetIntervalSize(num, this.IntervalOffset, type, axisSeries, 0.0, DateTimeIntervalType.Number, true, false); } return(num + Math.Floor(current - num)); }
/// <summary> /// Gets interval size as double number. /// </summary> /// <param name="current">Current value.</param> /// <param name="interval">Interval size.</param> /// <param name="type">AxisName of the interval (Month, Year, ...).</param> /// <returns>Interval size as double.</returns> internal static double GetIntervalSize(double current, double interval, DateTimeIntervalType type) { return(GetIntervalSize( current, interval, type, null, 0, DateTimeIntervalType.Number, true, true)); }
public DateTimeAxis( AxisPosition position, DateTime firstDateTime, DateTime lastDateTime, string title = null, string format = null, DateTimeIntervalType intervalType = DateTimeIntervalType.Auto) : this(position, title, format, intervalType) { this.Minimum = ToDouble(firstDateTime); this.Maximum = ToDouble(lastDateTime); }
/// <summary> /// Creates <see cref="DateTime" /> tick values. /// </summary> /// <param name="min">The min.</param> /// <param name="max">The max.</param> /// <param name="interval">The interval.</param> /// <param name="intervalType">The interval type.</param> /// <returns>A list of <see cref="DateTime" /> tick values.</returns> private IList <double> CreateDateTimeTickValues( double min, double max, double interval, DateTimeIntervalType intervalType) { // If the step size is more than 7 days (e.g. months or years) we use a specialized tick generation method that adds tick values with uneven spacing... if (intervalType > DateTimeIntervalType.Days) { return(this.CreateDateTickValues(min, max, interval, intervalType)); } // For shorter step sizes we use the method from Axis return(this.CreateTickValues(min, max, interval)); }
public DateTimeAxis( AxisPosition position, string title = null, string format = null, DateTimeIntervalType intervalType = DateTimeIntervalType.Auto) : base(position, title) { this.FirstDayOfWeek = DayOfWeek.Monday; this.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek; this.StringFormat = format; this.IntervalType = intervalType; }
/// <summary> /// Returns the actual interval to use to determine which values are /// displayed in the axis. /// </summary> /// <param name="availableSize">The available size.</param> /// <returns>The actual interval to use to determine which values are /// displayed in the axis. /// </returns> private double CalculateActualInterval(Size availableSize) { if (Interval != null) { return(Interval.Value); } DateTimeIntervalType intervalType = new DateTimeIntervalType(); double interval = CalculateDateTimeInterval(ActualDateTimeRange.Minimum, ActualDateTimeRange.Maximum, out intervalType, availableSize); ActualIntervalType = intervalType; return(interval); }
internal void HScrollerScroll(DateTime viewTimeBegin, DateTime viewTimeEnd, DateTimeIntervalType scaleType, DateTime curViewTimeBegin, DateTime curViewTimeEnd) { var pz = new List <object> { viewTimeBegin, viewTimeEnd, scaleType }; var cpz = new List <object> { curViewTimeBegin, curViewTimeEnd, scaleType }; var cmd = new UserCommand(EUserCommand.SetTimeView, null, pz, cpz); AddCommand(cmd, false); }
public ChartHelp(Chart chart) { this.chart = chart; chart.AxisViewChanged += new EventHandler <ViewEventArgs>(Chart_AxisViewChanged); CheckBoxTag.Chart = chart; CheckBoxTag.ChartHelp = this; ChartArea chartArea1 = chart.ChartAreas["ChartArea1"]; resetZoomAxisInterval = chartArea1.AxisX.Interval; resetZoomAxisIntervalType = chartArea1.AxisX.IntervalType; resetZoomLabelInterval = chartArea1.AxisX.LabelStyle.Interval; resetZoomLabelIntervalType = chartArea1.AxisX.LabelStyle.IntervalType; chart.PrePaint += new EventHandler <ChartPaintEventArgs>(chartMain_PrePaint); }
public void SetIntervals(TimeSpan delta) { chart.SuspendLayout(); Axis axisX1 = chart.ChartAreas["ChartArea1"].AxisX; if (delta <= new TimeSpan(0, 5, 0, 0)) { if (delta <= new TimeSpan(0, 0, 30, 0)) { axisX1.MajorGrid.Interval = 1D; axisX1.MajorGrid.IntervalType = DateTimeIntervalType.Minutes; axisX1.LabelStyle.Interval = 1D; axisX1.LabelStyle.IntervalType = DateTimeIntervalType.Minutes; axisX1.Interval = 1D; axisX1.IntervalType = DateTimeIntervalType.Minutes; resetZoomLabelInterval = 1D; resetZoomLabelIntervalType = DateTimeIntervalType.Minutes; resetZoomAxisInterval = 1D; resetZoomAxisIntervalType = DateTimeIntervalType.Minutes; } else { axisX1.MajorGrid.Interval = 15D; axisX1.MajorGrid.IntervalType = DateTimeIntervalType.Minutes; axisX1.LabelStyle.Interval = 15D; axisX1.LabelStyle.IntervalType = DateTimeIntervalType.Minutes; axisX1.Interval = 15D; axisX1.IntervalType = DateTimeIntervalType.Minutes; resetZoomLabelInterval = 15D; resetZoomLabelIntervalType = DateTimeIntervalType.Minutes; resetZoomAxisInterval = 15D; resetZoomAxisIntervalType = DateTimeIntervalType.Minutes; } } else { axisX1.MajorGrid.Interval = 1D; axisX1.MajorGrid.IntervalType = DateTimeIntervalType.Hours; axisX1.LabelStyle.Interval = 1D; axisX1.LabelStyle.IntervalType = DateTimeIntervalType.Hours; axisX1.Interval = 1D; axisX1.IntervalType = DateTimeIntervalType.Hours; resetZoomLabelInterval = 1D; resetZoomLabelIntervalType = DateTimeIntervalType.Hours; resetZoomAxisInterval = 1D; resetZoomAxisIntervalType = DateTimeIntervalType.Hours; } chart.ResumeLayout(); }
internal bool VizirChanged(DateTime vizirTime, DateTime curVizirTime, DateTime curViewMin, DateTime curViewMax, DateTimeIntervalType curViewTimeIntervalType) { if (curVizirTime != vizirTime) { var cpz = new List <object> { curVizirTime, curViewMin, curViewMax, curViewTimeIntervalType }; var cmd = new UserCommand(EUserCommand.SetVizir, null, vizirTime, cpz); AddCommand(cmd, false); return(true); } return(false); }
/// <summary> /// Returns the actual interval to use to determine which values are /// displayed in the axis. /// </summary> /// <returns>The actual interval to use to determine which values are /// displayed in the axis. /// </returns> private double CalculateActualInterval() { if (Interval != null) { return(Interval.Value); } Range <DateTime> actualDateTimeRange = ToDateTimeRange(this.ActualRange); DateTimeIntervalType intervalType; double interval = CalculateDateTimeInterval(actualDateTimeRange.Minimum, actualDateTimeRange.Maximum, out intervalType); ActualIntervalType = intervalType; return(interval); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (context != null && context.Instance != null && destinationType == typeof(string)) { DateTimeIntervalType dateTimeIntervalType = DateTimeIntervalType.Auto; double num = 0.0; PropertyInfo property = context.Instance.GetType().GetProperty("IntervalType"); if (property != null) { dateTimeIntervalType = (DateTimeIntervalType)property.GetValue(context.Instance, null); } property = context.Instance.GetType().GetProperty("Interval"); if (property != null) { num = (double)property.GetValue(context.Instance, null); } if (dateTimeIntervalType == DateTimeIntervalType.Auto) { Axis axis = null; if (context.Instance is Axis) { axis = (Axis)context.Instance; } else { MethodInfo method = context.Instance.GetType().GetMethod("GetAxis"); if (method != null) { axis = (Axis)method.Invoke(context.Instance, null); } } if (axis != null) { dateTimeIntervalType = axis.GetAxisIntervalType(); } } if ((context.Instance.GetType() != typeof(StripLine) || num == 0.0) && dateTimeIntervalType != DateTimeIntervalType.Number && dateTimeIntervalType != 0) { if (dateTimeIntervalType < DateTimeIntervalType.Hours) { return(DateTime.FromOADate((double)value).ToShortDateString()); } return(DateTime.FromOADate((double)value).ToString("g", CultureInfo.CurrentCulture)); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public DateTime GetMinDate(DateTime maxDate, DateTimeIntervalType dtintType, int dtOffset) { if (DateTimeIntervalType.Minutes == dtintType) { return(maxDate.AddMinutes(-dtOffset)); } else if (DateTimeIntervalType.Hours == dtintType) { return(maxDate.AddHours(-dtOffset)); } else if (DateTimeIntervalType.Days == dtintType) { return(maxDate.AddHours(-dtOffset)); } return(maxDate); }
//Если viewTimeIntervalType = DateTimeIntervalType.NotSet - автоопределение _axisXIntervalType internal bool SetTimeView(DateTime viewTimeBegin, DateTime viewTimeEnd, DateTimeIntervalType scaleType, DateTime curViewTimeBegin, DateTime curViewTimeEnd, DateTimeIntervalType curScaleType) { if ((viewTimeBegin != curViewTimeBegin) || (viewTimeEnd != curViewTimeEnd) || (scaleType != curScaleType)) { var pz = new List <object> { viewTimeBegin, viewTimeEnd, scaleType }; var cpz = new List <object> { curViewTimeBegin, curViewTimeEnd, curScaleType }; var cmd = new UserCommand(EUserCommand.SetTimeView, null, pz, cpz); AddCommand(cmd); return(true); } return(false); }
private void CorrectMinMax(DateTimeIntervalType dtintType, int interv, ref DateTime dtMinCorr, ref DateTime dtMaxCorr) { if (DateTimeIntervalType.Minutes == dtintType) { dtMinCorr = dtMinCorr.AddMinutes(-interv); dtMaxCorr = dtMaxCorr.AddMinutes(interv); } else if (DateTimeIntervalType.Hours == dtintType) { dtMinCorr = dtMinCorr.AddHours(-interv); dtMaxCorr = dtMaxCorr.AddHours(interv); } else if (DateTimeIntervalType.Days == dtintType) { dtMinCorr = dtMinCorr.AddDays(-interv); dtMaxCorr = dtMaxCorr.AddDays(interv); } }
/// <summary> /// Gets interval size as double number. /// </summary> /// <param name="current">Current value.</param> /// <param name="interval">Interval size.</param> /// <param name="type">AxisName of the interval (Month, Year, ...).</param> /// <param name="series">First series connected to the axis.</param> /// <param name="intervalOffset">Offset size.</param> /// <param name="intervalOffsetType">Offset type(Month, Year, ...).</param> /// <param name="forceIntIndex">Force Integer indexed</param> /// <returns>Interval size as double.</returns> internal static double GetIntervalSize( double current, double interval, DateTimeIntervalType type, Series series, double intervalOffset, DateTimeIntervalType intervalOffsetType, bool forceIntIndex) { return(GetIntervalSize( current, interval, type, series, intervalOffset, intervalOffsetType, forceIntIndex, true)); }
private void SetXAxisForDate(Axis axis, DateTimeIntervalType t) { axis.LabelStyle.Angle = int.Parse(LocalizedChartControl.XAxisLabelAngle); axis.LabelStyle.Format = GraphInformation.XAxisDateFormat; axis.LabelStyle.Interval = 1; axis.LabelStyle.IntervalType = t; axis.MajorTickMark.Interval = 1; axis.MajorTickMark.IntervalType = t; axis.MajorTickMark.Size = 1; axis.MajorGrid.Interval = 1; axis.MajorGrid.IntervalType = t; axis.MajorGrid.LineWidth = 1; if (t == DateTimeIntervalType.Weeks) { axis.MajorGrid.LineColor = GraphInformation.DarkXAxisLineColour; axis.MinorGrid.Enabled = true; axis.MinorGrid.LineWidth = 1; axis.MinorGrid.LineColor = GraphInformation.LightXAxisLineColour; axis.MinorGrid.Interval = 1; axis.MinorGrid.IntervalType = DateTimeIntervalType.Days; //Offsets axis.MajorGrid.IntervalOffset = 1; axis.MajorGrid.IntervalOffsetType = DateTimeIntervalType.Days; axis.MajorTickMark.IntervalOffset = 1; axis.MajorTickMark.IntervalOffsetType = DateTimeIntervalType.Days; axis.LabelStyle.IntervalOffset = 1; axis.LabelStyle.IntervalOffsetType = DateTimeIntervalType.Days; } else { axis.MajorGrid.LineColor = GraphInformation.LightXAxisLineColour; } }
public void RestoreAxisScaleAndInterval() { if (this.oldAxisSettings.Count > 0) { this.axis.LabelStyle.intervalOffsetType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.LabelStyle.intervalOffset = (double)this.oldAxisSettings.Pop(); this.axis.LabelStyle.intervalType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.LabelStyle.interval = (double)this.oldAxisSettings.Pop(); this.axis.majorTickMark.intervalOffsetType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.majorTickMark.intervalOffset = (double)this.oldAxisSettings.Pop(); this.axis.majorTickMark.intervalType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.majorTickMark.interval = (double)this.oldAxisSettings.Pop(); this.axis.majorGrid.intervalOffsetType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.majorGrid.intervalOffset = (double)this.oldAxisSettings.Pop(); this.axis.majorGrid.intervalType = (DateTimeIntervalType)this.oldAxisSettings.Pop(); this.axis.majorGrid.interval = (double)this.oldAxisSettings.Pop(); this.axis.minimum = (double)this.oldAxisSettings.Pop(); this.axis.maximum = (double)this.oldAxisSettings.Pop(); } }
internal static DateTime IncreaseInterval(DateTime date, double interval, DateTimeIntervalType intervalType) { TimeSpan span = new TimeSpan(0); DateTime result; if (intervalType == DateTimeIntervalType.Days) { span = TimeSpan.FromDays(interval); } else if (intervalType == DateTimeIntervalType.Hours) { span = TimeSpan.FromHours(interval); } else if (intervalType == DateTimeIntervalType.Milliseconds) { span = TimeSpan.FromMilliseconds(interval); } else if (intervalType == DateTimeIntervalType.Seconds) { span = TimeSpan.FromSeconds(interval); } else if (intervalType == DateTimeIntervalType.Minutes) { span = TimeSpan.FromMinutes(interval); } else if (intervalType == DateTimeIntervalType.Months) { date = date.AddMonths((int)Math.Floor(interval)); span = TimeSpan.FromDays(30.0 * (interval - Math.Floor(interval))); } else if (intervalType == DateTimeIntervalType.Years) { date = date.AddYears((int)Math.Floor(interval)); span = TimeSpan.FromDays(365.0 * (interval - Math.Floor(interval))); } result = date.Add(span); return(result); }
/// <summary> /// Updates the intervals. /// </summary> /// <param name="plotArea">The plot area.</param> internal override void UpdateIntervals(OxyRect plotArea) { base.UpdateIntervals(plotArea); switch (this.actualIntervalType) { case DateTimeIntervalType.Years: this.ActualMinorStep = 31; this.actualMinorIntervalType = DateTimeIntervalType.Years; if (this.StringFormat == null) { this.ActualStringFormat = "yyyy"; } break; case DateTimeIntervalType.Months: this.actualMinorIntervalType = DateTimeIntervalType.Months; if (this.StringFormat == null) { this.ActualStringFormat = "yyyy-MM-dd"; } break; case DateTimeIntervalType.Weeks: this.actualMinorIntervalType = DateTimeIntervalType.Days; this.ActualMajorStep = 7; this.ActualMinorStep = 1; if (this.StringFormat == null) { this.ActualStringFormat = "yyyy/ww"; } break; case DateTimeIntervalType.Days: this.ActualMinorStep = this.ActualMajorStep; if (this.StringFormat == null) { this.ActualStringFormat = "yyyy-MM-dd"; } break; case DateTimeIntervalType.Hours: this.ActualMinorStep = this.ActualMajorStep; if (this.StringFormat == null) { this.ActualStringFormat = "HH:mm"; } break; case DateTimeIntervalType.Minutes: this.ActualMinorStep = this.ActualMajorStep; if (this.StringFormat == null) { this.ActualStringFormat = "HH:mm"; } break; case DateTimeIntervalType.Seconds: this.ActualMinorStep = this.ActualMajorStep; if (this.StringFormat == null) { this.ActualStringFormat = "HH:mm:ss"; } break; case DateTimeIntervalType.Manual: break; case DateTimeIntervalType.Auto: break; } }
private IEnumerable<KeyValuePair<double, DateTime>> GetHorisontalAxesMarkers( DateTime leftTime, DateTime rightTime, double left, double right, out DateTimeIntervalType intervalType, out int interval) { var deltaX = Math.Abs(right - left); var gridLinesNumber = (int) deltaX/MinimumXAxesStep + 1; interval = 0; intervalType = DateTimeIntervalType.Years; var markers = new List<KeyValuePair<double, DateTime>>(); if (gridLinesNumber > 1) { var leftTimeTicks = leftTime.Ticks; var rightTimeTicks = rightTime.Ticks; var xKoefficient = (right - left)/(rightTimeTicks - leftTimeTicks); var step = new TimeSpan((rightTimeTicks - leftTimeTicks)/(gridLinesNumber - 1)); GetDateTimeInterval(step, out intervalType, out interval); var currentDateTime = GetStartDateTime(leftTime, intervalType, interval); while (currentDateTime <= rightTime) { if (currentDateTime >= leftTime) { var xKoordinate = left + (currentDateTime.Ticks - leftTimeTicks)*xKoefficient; markers.Add(new KeyValuePair<double, DateTime>(xKoordinate, currentDateTime)); } currentDateTime = AddIntervalToDateTime(currentDateTime, intervalType, interval); } } return markers; }
/// <summary> /// Creates the date tick values. /// </summary> /// <param name="min"> /// The min. /// </param> /// <param name="max"> /// The max. /// </param> /// <param name="step"> /// The step. /// </param> /// <param name="intervalType"> /// Type of the interval. /// </param> /// <returns> /// Date tick values. /// </returns> private IList<double> CreateDateTickValues( double min, double max, double step, DateTimeIntervalType intervalType) { DateTime start = ToDateTime(min); switch (intervalType) { case DateTimeIntervalType.Weeks: // make sure the first tick is at the 1st day of a week start = start.AddDays(-(int)start.DayOfWeek + (int)this.FirstDayOfWeek); break; case DateTimeIntervalType.Months: // make sure the first tick is at the 1st of a month start = new DateTime(start.Year, start.Month, 1); break; case DateTimeIntervalType.Years: // make sure the first tick is at Jan 1st start = new DateTime(start.Year, 1, 1); break; } // Adds a tick to the end time to make sure the end DateTime is included. DateTime end = ToDateTime(max).AddTicks(1); DateTime current = start; var values = new Collection<double>(); double eps = step * 1e-3; DateTime minDateTime = ToDateTime(min - eps); DateTime maxDateTime = ToDateTime(max + eps); while (current < end) { if (current > minDateTime && current < maxDateTime) { values.Add(ToDouble(current)); } switch (intervalType) { case DateTimeIntervalType.Months: current = current.AddMonths((int)Math.Ceiling(step)); break; case DateTimeIntervalType.Years: current = current.AddYears((int)Math.Ceiling(step)); break; default: current = current.AddDays(step); break; } } return values; }
/// <summary> /// Initializes a new instance of the <see cref="DateTimeAxis" /> class. /// </summary> /// <param name="pos">The position of the axis.</param> /// <param name="firstDateTime">The first date/time on the axis.</param> /// <param name="lastDateTime">The last date/time on the axis.</param> /// <param name="title">The axis title.</param> /// <param name="format">The string format for the axis values.</param> /// <param name="intervalType">The interval type.</param> public DateTimeAxis( AxisPosition pos, DateTime firstDateTime, DateTime lastDateTime, string title = null, string format = null, DateTimeIntervalType intervalType = DateTimeIntervalType.Auto) : this(pos, title, format, intervalType) { this.Minimum = ToDouble(firstDateTime); this.Maximum = ToDouble(lastDateTime); }
private static DateTime GetStartDateTime(DateTime leftDateTime, DateTimeIntervalType intervalType, int interval) { switch (intervalType) { case DateTimeIntervalType.Years: return new DateTime( leftDateTime.Year, 1, 1); case DateTimeIntervalType.Months: return new DateTime( leftDateTime.Year, leftDateTime.Month, 1); case DateTimeIntervalType.Days: return new DateTime( leftDateTime.Year, leftDateTime.Month, leftDateTime.Day); case DateTimeIntervalType.Hours: return new DateTime( leftDateTime.Year, leftDateTime.Month, leftDateTime.Day, leftDateTime.Hour/interval*interval, 0, 0); case DateTimeIntervalType.Minutes: return new DateTime( leftDateTime.Year, leftDateTime.Month, leftDateTime.Day, leftDateTime.Hour, leftDateTime.Minute/interval*interval, 0); case DateTimeIntervalType.Seconds: return new DateTime( leftDateTime.Year, leftDateTime.Month, leftDateTime.Day, leftDateTime.Hour, leftDateTime.Minute, leftDateTime.Second/interval*interval); case DateTimeIntervalType.Milliseconds: return new DateTime( leftDateTime.Year, leftDateTime.Month, leftDateTime.Day, leftDateTime.Hour, leftDateTime.Minute, leftDateTime.Second, leftDateTime.Millisecond/interval*interval); default: return leftDateTime; } }
/// <summary> /// IntervalTypeProperty property changed handler. /// </summary> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> protected virtual void OnIntervalTypePropertyChanged(DateTimeIntervalType oldValue, DateTimeIntervalType newValue) { UpdateFormattedContent(); }
/// <summary> /// Creates <see cref="DateTime" /> tick values. /// </summary> /// <param name="min">The min.</param> /// <param name="max">The max.</param> /// <param name="interval">The interval.</param> /// <param name="intervalType">The interval type.</param> /// <returns>A list of <see cref="DateTime" /> tick values.</returns> private IList<double> CreateDateTimeTickValues( double min, double max, double interval, DateTimeIntervalType intervalType) { // If the step size is more than 7 days (e.g. months or years) we use a specialized tick generation method that adds tick values with uneven spacing... if (intervalType > DateTimeIntervalType.Days) { return this.CreateDateTickValues(min, max, interval, intervalType); } // For shorter step sizes we use the method from Axis return this.CreateTickValues(min, max, interval); }
/// <summary> /// Returns the actual interval to use to determine which values are /// displayed in the axis. /// </summary> /// <param name="availableSize">The available size.</param> /// <returns>The actual interval to use to determine which values are /// displayed in the axis. /// </returns> private double CalculateActualInterval(Size availableSize) { if (Interval != null) { return Interval.Value; } Range<DateTime> actualDateTimeRange = ToDateTimeRange(this.ActualRange); DateTimeIntervalType intervalType; double interval = CalculateDateTimeInterval(actualDateTimeRange.Minimum, actualDateTimeRange.Maximum, out intervalType, availableSize); ActualIntervalType = intervalType; return interval; }
private static string GetFirstDateTimeLabelFormat(DateTimeIntervalType intervalType) { switch (intervalType) { case DateTimeIntervalType.Years: return "yyyy"; case DateTimeIntervalType.Months: return "yyyy"; case DateTimeIntervalType.Days: return "yyyy"; case DateTimeIntervalType.Hours: return "dd.MM.yyyy"; case DateTimeIntervalType.Minutes: return "dd.MM.yyyy"; case DateTimeIntervalType.Seconds: return "dd.MM.yyyy"; case DateTimeIntervalType.Milliseconds: return "dd.MM.yyyy HH:mm"; default: return null; } }
/// <summary> /// Calculates the actual interval. /// </summary> /// <param name="availableSize">Size of the available area.</param> /// <param name="maxIntervalSize">Maximum length of the intervals.</param> /// <returns>The calculate actual interval.</returns> protected override double CalculateActualInterval(double availableSize, double maxIntervalSize) { const double Year = 365.25; const double Month = 30.5; const double Week = 7; const double Day = 1.0; const double Hour = Day / 24; const double Minute = Hour / 60; const double Second = Minute / 60; double range = Math.Abs(this.ActualMinimum - this.ActualMaximum); var goodIntervals = new[] { Second, 2 * Second, 5 * Second, 10 * Second, 30 * Second, Minute, 2 * Minute, 5 * Minute, 10 * Minute, 30 * Minute, Hour, 4 * Hour, 8 * Hour, 12 * Hour, Day, 2 * Day, 5 * Day, Week, 2 * Week, Month, 2 * Month, 3 * Month, 4 * Month, 6 * Month, Year }; double interval = goodIntervals[0]; int maxNumberOfIntervals = Math.Max((int)(availableSize / maxIntervalSize), 2); while (true) { if (range / interval < maxNumberOfIntervals) { break; } double nextInterval = goodIntervals.FirstOrDefault(i => i > interval); if (Math.Abs(nextInterval) <= double.Epsilon) { nextInterval = interval * 2; } interval = nextInterval; } this.actualIntervalType = this.IntervalType; this.actualMinorIntervalType = this.MinorIntervalType; if (this.IntervalType == DateTimeIntervalType.Auto) { this.actualIntervalType = DateTimeIntervalType.Seconds; if (interval >= 1.0 / 24 / 60) { this.actualIntervalType = DateTimeIntervalType.Minutes; } if (interval >= 1.0 / 24) { this.actualIntervalType = DateTimeIntervalType.Hours; } if (interval >= 1) { this.actualIntervalType = DateTimeIntervalType.Days; } if (interval >= 30) { this.actualIntervalType = DateTimeIntervalType.Months; } if (range >= 365.25) { this.actualIntervalType = DateTimeIntervalType.Years; } } if (this.actualIntervalType == DateTimeIntervalType.Months) { double monthsRange = range / 30.5; interval = this.CalculateActualInterval(availableSize, maxIntervalSize, monthsRange); } if (this.actualIntervalType == DateTimeIntervalType.Years) { double yearsRange = range / 365.25; interval = this.CalculateActualInterval(availableSize, maxIntervalSize, yearsRange); } if (this.actualMinorIntervalType == DateTimeIntervalType.Auto) { switch (this.actualIntervalType) { case DateTimeIntervalType.Years: this.actualMinorIntervalType = DateTimeIntervalType.Months; break; case DateTimeIntervalType.Months: this.actualMinorIntervalType = DateTimeIntervalType.Days; break; case DateTimeIntervalType.Weeks: this.actualMinorIntervalType = DateTimeIntervalType.Days; break; case DateTimeIntervalType.Days: this.actualMinorIntervalType = DateTimeIntervalType.Hours; break; case DateTimeIntervalType.Hours: this.actualMinorIntervalType = DateTimeIntervalType.Minutes; break; default: this.actualMinorIntervalType = DateTimeIntervalType.Days; break; } } return interval; }
/// <summary> /// Creates the date tick values. /// </summary> /// <param name="min">The min.</param> /// <param name="max">The max.</param> /// <param name="step">The step.</param> /// <param name="intervalType">Type of the interval.</param> /// <returns>Date tick values.</returns> private IList<double> CreateDateTickValues( double min, double max, double step, DateTimeIntervalType intervalType) { var values = new Collection<double>(); var start = ToDateTime(min); if (start.Ticks == 0) { // Invalid start time return values; } switch (intervalType) { case DateTimeIntervalType.Weeks: // make sure the first tick is at the 1st day of a week start = start.AddDays(-(int)start.DayOfWeek + (int)this.FirstDayOfWeek); break; case DateTimeIntervalType.Months: // make sure the first tick is at the 1st of a month start = new DateTime(start.Year, start.Month, 1); break; case DateTimeIntervalType.Years: // make sure the first tick is at Jan 1st start = new DateTime(start.Year, 1, 1); break; } // Adds a tick to the end time to make sure the end DateTime is included. var end = ToDateTime(max).AddTicks(1); if (end.Ticks == 0) { // Invalid end time return values; } var current = start; double eps = step * 1e-3; var minDateTime = ToDateTime(min - eps); var maxDateTime = ToDateTime(max + eps); if (minDateTime.Ticks == 0 || maxDateTime.Ticks == 0) { // Invalid min/max time return values; } while (current < end) { if (current > minDateTime && current < maxDateTime) { values.Add(ToDouble(current)); } try { switch (intervalType) { case DateTimeIntervalType.Months: current = current.AddMonths((int)Math.Ceiling(step)); break; case DateTimeIntervalType.Years: current = current.AddYears((int)Math.Ceiling(step)); break; default: current = current.AddDays(step); break; } } catch (ArgumentOutOfRangeException) { // AddMonths/AddYears/AddDays can throw an exception // We could test this by comparing to MaxDayValue/MinDayValue, but it is easier to catch the exception... break; } } return values; }
/// <summary> /// IntervalTypeProperty property changed handler. /// </summary> /// <param name="newValue">New value.</param> private void OnIntervalTypePropertyChanged(DateTimeIntervalType newValue) { this.ActualIntervalType = newValue; Invalidate(); }
private static void GetDateTimeInterval(TimeSpan step, out DateTimeIntervalType intervalType, out int interval) { const int daysInYear = 365; const int daysInMonth = 31; intervalType = DateTimeIntervalType.Years; interval = 0; if (step.TotalDays >= daysInYear) { intervalType = DateTimeIntervalType.Years; interval = (int) GetNormalValue(step.TotalDays/daysInYear); } else if (step.TotalDays >= daysInMonth) { intervalType = DateTimeIntervalType.Months; interval = (int) GetNormalValue(step.TotalDays/daysInMonth); } else if ((int) step.TotalDays > 0) { intervalType = DateTimeIntervalType.Days; interval = (int) GetNormalValue(step.TotalDays); } else if ((int) step.TotalHours > 0) { intervalType = DateTimeIntervalType.Hours; interval = (int) GetNormalValue(step.TotalHours); } else if ((int) step.TotalMinutes > 0) { intervalType = DateTimeIntervalType.Minutes; interval = (int) GetNormalValue(step.TotalMinutes); } else if ((int) step.TotalSeconds > 0) { intervalType = DateTimeIntervalType.Seconds; interval = (int) GetNormalValue(step.TotalSeconds); } else if ((int) step.TotalMilliseconds > 0) { intervalType = DateTimeIntervalType.Milliseconds; interval = (int) GetNormalValue(step.TotalMilliseconds); } if (interval == 0) interval = 1; }
private double CalculateDateTimeInterval(DateTime minimum, DateTime maximum, out DateTimeIntervalType type, Size availableSize) { DateTime dateTimeMin = minimum; DateTime dateTimeMax = maximum; TimeSpan timeSpan = dateTimeMax.Subtract(dateTimeMin); // this algorithm is designed to return close to 10 intervals. // we need to align the time span for PrefferedNumberOfIntervals double maxIntervals = Orientation == AxisOrientation.X ? MaximumAxisIntervalsPer200Pixels * 0.8 : MaximumAxisIntervalsPer200Pixels; double rangeMultiplicator = GetLength(availableSize) / (200 * 10 / maxIntervals); timeSpan = new TimeSpan((long)((double)timeSpan.Ticks / rangeMultiplicator)); // Minutes double inter = timeSpan.TotalMinutes; // For Range less than 60 seconds interval is 5 sec if (inter <= 1.0) { // Milli Seconds double milliSeconds = timeSpan.TotalMilliseconds; if (milliSeconds <= 10) { type = DateTimeIntervalType.Milliseconds; return 1; } if (milliSeconds <= 50) { type = DateTimeIntervalType.Milliseconds; return 4; } if (milliSeconds <= 200) { type = DateTimeIntervalType.Milliseconds; return 20; } if (milliSeconds <= 500) { type = DateTimeIntervalType.Milliseconds; return 50; } // Seconds double seconds = timeSpan.TotalSeconds; if (seconds <= 7) { type = DateTimeIntervalType.Seconds; return 1; } else if (seconds <= 15) { type = DateTimeIntervalType.Seconds; return 2; } else if (seconds <= 30) { type = DateTimeIntervalType.Seconds; return 5; } else if (seconds <= 60) { type = DateTimeIntervalType.Seconds; return 10; } } else if (inter <= 2.0) { // For Range less than 120 seconds interval is 10 sec type = DateTimeIntervalType.Seconds; return 20; } else if (inter <= 3.0) { // For Range less than 180 seconds interval is 30 sec type = DateTimeIntervalType.Seconds; return 30; } else if (inter <= 10) { // For Range less than 10 minutes interval is 1 min type = DateTimeIntervalType.Minutes; return 1; } else if (inter <= 20) { // For Range less than 20 minutes interval is 1 min type = DateTimeIntervalType.Minutes; return 2; } else if (inter <= 60) { // For Range less than 60 minutes interval is 5 min type = DateTimeIntervalType.Minutes; return 5; } else if (inter <= 120) { // For Range less than 120 minutes interval is 10 min type = DateTimeIntervalType.Minutes; return 10; } else if (inter <= 180) { // For Range less than 180 minutes interval is 30 min type = DateTimeIntervalType.Minutes; return 30; } else if (inter <= 60 * 12) { // For Range less than 12 hours interval is 1 hour type = DateTimeIntervalType.Hours; return 1; } else if (inter <= 60 * 24) { // For Range less than 24 hours interval is 4 hour type = DateTimeIntervalType.Hours; return 4; } else if (inter <= 60 * 24 * 2) { // For Range less than 2 days interval is 6 hour type = DateTimeIntervalType.Hours; return 6; } else if (inter <= 60 * 24 * 3) { // For Range less than 3 days interval is 12 hour type = DateTimeIntervalType.Hours; return 12; } else if (inter <= 60 * 24 * 10) { // For Range less than 10 days interval is 1 day type = DateTimeIntervalType.Days; return 1; } else if (inter <= 60 * 24 * 20) { // For Range less than 20 days interval is 2 day type = DateTimeIntervalType.Days; return 2; } else if (inter <= 60 * 24 * 30) { // For Range less than 30 days interval is 3 day type = DateTimeIntervalType.Days; return 3; } else if (inter <= 60 * 24 * 30.5 * 2) { // For Range less than 2 months interval is 1 week type = DateTimeIntervalType.Weeks; return 1; } else if (inter <= 60 * 24 * 30.5 * 5) { // For Range less than 5 months interval is 2weeks type = DateTimeIntervalType.Weeks; return 2; } else if (inter <= 60 * 24 * 30.5 * 12) { // For Range less than 12 months interval is 1 month type = DateTimeIntervalType.Months; return 1; } else if (inter <= 60 * 24 * 30.5 * 24) { // For Range less than 24 months interval is 3 month type = DateTimeIntervalType.Months; return 3; } else if (inter <= 60 * 24 * 30.5 * 48) { // For Range less than 48 months interval is 6 months type = DateTimeIntervalType.Months; return 6; } // For Range more than 48 months interval is year type = DateTimeIntervalType.Years; double years = inter / 60 / 24 / 365; if (years < 5) { return 1; } else if (years < 10) { return 2; } // Make a correction of the interval return Math.Floor(years / 5); }
public void Zoom (double viewPosition, double viewSize, DateTimeIntervalType viewSizeType, bool saveState) { throw new NotImplementedException(); }
/// <summary> /// Sets interval properties for the axis. /// Note that we use the Axis object's interval properties, and not the properties of its label, /// and major tick mark and grid line objects /// </summary> public void SetAxisInterval(Axis axis, double interval, DateTimeIntervalType intervalType) { SetAxisInterval(axis, interval, intervalType, 0, DateTimeIntervalType.Auto); }
/// <summary> /// Adjusts the beginning of the first interval depending on the type and size. /// </summary> /// <param name="start">Original start point.</param> /// <param name="intervalSize">Interval size.</param> /// <param name="type">Type of the interval (Month, Year, ...).</param> /// <returns> /// Adjusted interval start position. /// </returns> private static DateTime AlignIntervalStart(DateTime start, double intervalSize, DateTimeIntervalType type) { // Do not adjust start position for these interval type if (type == DateTimeIntervalType.Auto) { return start; } // Get the beginning of the interval depending on type DateTime newStartDate = start; // Adjust the months interval depending on size if (intervalSize > 0.0 && intervalSize != 1.0) { if (type == DateTimeIntervalType.Months && intervalSize <= 12.0 && intervalSize > 1) { // Make sure that the beginning is aligned correctly for cases // like quarters and half years DateTime resultDate = newStartDate; DateTime sizeAdjustedDate = new DateTime(newStartDate.Year, 1, 1, 0, 0, 0); while (sizeAdjustedDate < newStartDate) { resultDate = sizeAdjustedDate; sizeAdjustedDate = sizeAdjustedDate.AddMonths((int)intervalSize); } newStartDate = resultDate; return newStartDate; } } // Check interval type switch (type) { case DateTimeIntervalType.Years: int year = (int)((int)(newStartDate.Year / intervalSize) * intervalSize); if (year <= 0) { year = 1; } newStartDate = new DateTime(year, 1, 1, 0, 0, 0); break; case DateTimeIntervalType.Months: int month = (int)((int)(newStartDate.Month / intervalSize) * intervalSize); if (month <= 0) { month = 1; } newStartDate = new DateTime(newStartDate.Year, month, 1, 0, 0, 0); break; case DateTimeIntervalType.Days: int day = (int)((int)(newStartDate.Day / intervalSize) * intervalSize); if (day <= 0) { day = 1; } newStartDate = new DateTime(newStartDate.Year, newStartDate.Month, day, 0, 0, 0); break; case DateTimeIntervalType.Hours: int hour = (int)((int)(newStartDate.Hour / intervalSize) * intervalSize); newStartDate = new DateTime( newStartDate.Year, newStartDate.Month, newStartDate.Day, hour, 0, 0); break; case DateTimeIntervalType.Minutes: int minute = (int)((int)(newStartDate.Minute / intervalSize) * intervalSize); newStartDate = new DateTime( newStartDate.Year, newStartDate.Month, newStartDate.Day, newStartDate.Hour, minute, 0); break; case DateTimeIntervalType.Seconds: int second = (int)((int)(newStartDate.Second / intervalSize) * intervalSize); newStartDate = new DateTime( newStartDate.Year, newStartDate.Month, newStartDate.Day, newStartDate.Hour, newStartDate.Minute, second, 0); break; case DateTimeIntervalType.Milliseconds: int milliseconds = (int)((int)(newStartDate.Millisecond / intervalSize) * intervalSize); newStartDate = new DateTime( newStartDate.Year, newStartDate.Month, newStartDate.Day, newStartDate.Hour, newStartDate.Minute, newStartDate.Second, milliseconds); break; case DateTimeIntervalType.Weeks: // Elements that have interval set to weeks should be aligned to the // nearest start of week no matter how many weeks is the interval. newStartDate = new DateTime( newStartDate.Year, newStartDate.Month, newStartDate.Day, 0, 0, 0); newStartDate = newStartDate.AddDays(-((int)newStartDate.DayOfWeek)); break; } return newStartDate; }
/// <summary> /// Sets interval properties for the axis. /// Note that we use the Axis object's interval properties, and not the properties of its label, /// and major tick mark and grid line objects /// </summary> public void SetAxisInterval(System.Web.UI.DataVisualization.Charting.Axis axis, double interval, DateTimeIntervalType intervalType) { SetAxisInterval(axis, interval, intervalType, 0, DateTimeIntervalType.Auto); }
private static DateTime AddIntervalToDateTime(DateTime dateTime, DateTimeIntervalType intervalType, int interval) { switch (intervalType) { case DateTimeIntervalType.Years: return dateTime.AddYears(interval); case DateTimeIntervalType.Months: return dateTime.AddMonths(interval); case DateTimeIntervalType.Days: return dateTime.AddDays(interval); case DateTimeIntervalType.Hours: return dateTime.AddHours(interval); case DateTimeIntervalType.Minutes: return dateTime.AddMinutes(interval); case DateTimeIntervalType.Seconds: return dateTime.AddSeconds(interval); case DateTimeIntervalType.Milliseconds: return dateTime.AddMilliseconds(interval); default: return dateTime.AddYears(1); } }
/// <summary> /// Returns the actual interval to use to determine which values are /// displayed in the axis. /// </summary> /// <param name="availableSize">The available size.</param> /// <returns>The actual interval to use to determine which values are /// displayed in the axis. /// </returns> private double CalculateActualInterval(Size availableSize) { if (Interval != null) { return Interval.Value; } DateTimeIntervalType intervalType = new DateTimeIntervalType(); double interval = CalculateDateTimeInterval(ActualDateTimeRange.Minimum, ActualDateTimeRange.Maximum, out intervalType, availableSize); ActualIntervalType = intervalType; return interval; }