/// <summary> /// Calculate the Minus Value of line /// </summary> /// <param name="value"></param> /// <param name="errorvalue"></param> /// <param name="axischeck"></param> /// <returns></returns> private double GetMinusValue(double value, double errorvalue, bool axischeck) { if ((ActualXAxis is DateTimeAxis) && axischeck) { var dateaxis = ActualXAxis as DateTimeAxis; DateTime verDate = Convert.ToDouble(value).FromOADate(); return(DateTimeAxisHelper.IncreaseInterval(verDate, -errorvalue, dateaxis.IntervalType).ToOADate()); } return(value - errorvalue); }
/// <summary> /// Apply padding based on interval /// </summary> /// <param name="range"></param> /// <param name="interval"></param> /// <returns></returns> protected override DoubleRange ApplyRangePadding(DoubleRange range, double interval) { if (Minimum == null && Maximum == null) // Executes when Minimum and Maximum aren't set. { return(DateTimeAxisHelper.ApplyRangePadding(this, base.ApplyRangePadding(range, interval), interval, RangePadding, ActualIntervalType)); } else if (Minimum != null && Maximum != null) // Executes when Minimum and Maximum are set. { return(range); } else { // Executes when either Minimum or Maximum is set. DoubleRange baseRange = DateTimeAxisHelper.ApplyRangePadding(this, base.ApplyRangePadding(range, interval), interval, RangePadding, ActualIntervalType); return(Minimum != null ? new DoubleRange(range.Start, baseRange.End) : new DoubleRange(baseRange.Start, range.End)); } }
internal Point DateTimeIntervalCalculation(double errorvalue, DateTimeIntervalType type) { DateTime date = Convert.ToDouble(_horLeftpoint.X).FromOADate(); DateTime date1 = Convert.ToDouble(_horRightpoint.X).FromOADate(); if (_parentSeries.HorizontalDirection == ErrorBarDirection.Plus) { _horLeftpoint.X = DateTimeAxisHelper.IncreaseInterval(date, 0, type).ToOADate(); _horRightpoint.X = DateTimeAxisHelper.IncreaseInterval(date1, errorvalue, type).ToOADate(); } else if (_parentSeries.HorizontalDirection == ErrorBarDirection.Minus) { _horLeftpoint.X = DateTimeAxisHelper.IncreaseInterval(date, -errorvalue, type).ToOADate(); _horRightpoint.X = DateTimeAxisHelper.IncreaseInterval(date1, 0, type).ToOADate(); } else { _horLeftpoint.X = DateTimeAxisHelper.IncreaseInterval(date, -errorvalue, type).ToOADate(); _horRightpoint.X = DateTimeAxisHelper.IncreaseInterval(date1, errorvalue, type).ToOADate(); } return(new Point(_horLeftpoint.X, _horRightpoint.X)); }
/// <summary> /// Method implementation for Create VisibleLabels for DateTime axis /// </summary> protected override void GenerateVisibleLabels() { SetRangeForAxisStyle(); DateTimeAxisHelper.GenerateVisibleLabels(this, Minimum, Maximum, ActualIntervalType); }
/// <summary> /// Calculates the visible range. /// </summary> protected internal override void CalculateVisibleRange(Size availableSize) { base.CalculateVisibleRange(availableSize); if (EnableBusinessHours) { var actualStart = ActualRange.Start.FromOADate(); var actualEnd = ActualRange.End.FromOADate(); // If actual range greater/less than business hours then change range start/end value as business range while (NonWorkingDays.Contains(actualStart.DayOfWeek.ToString())) { var date = actualStart.AddDays(-1); actualStart = date.AddHours(CloseTime == 24 ? 0 : CloseTime); } while (NonWorkingDays.Contains(actualEnd.DayOfWeek.ToString())) { var date = actualEnd.AddDays(-1); actualEnd = date.AddHours(CloseTime == 24 ? 0 : CloseTime); } if (actualStart.TimeOfDay.TotalHours < OpenTime) { actualStart = actualStart.AddHours(OpenTime - actualStart.TimeOfDay.TotalHours); } else if (actualStart.TimeOfDay.TotalHours > CloseTime) { actualStart = actualStart.AddHours(-(actualStart.TimeOfDay.TotalHours - CloseTime)); } if (actualEnd.TimeOfDay.TotalHours < OpenTime) { actualEnd = actualEnd.AddHours(OpenTime - actualEnd.TimeOfDay.TotalHours); } else if (actualEnd.TimeOfDay.TotalHours > CloseTime) { actualEnd = actualEnd.AddHours(-(actualEnd.TimeOfDay.TotalHours - CloseTime)); } if (ZoomPosition > 0 || ZoomFactor < 1) { var diff = CloseTime - OpenTime; // hours differce from endtime to open time var totalWorkingHours = CalcNonWorkingHours(actualStart, actualEnd, InternalWorkingDays.ToString(), nonWorkingHoursPerDay); var currentWorkingHours = ((ActualRange.Delta * 24) - totalWorkingHours) * ZoomPosition; // current working hours for zoom postion value var totalDays = currentWorkingHours / diff; // total days without nonworking hours var remainderHours = (totalDays - (int)totalDays); var startDate = actualStart.AddDays((int)totalDays).AddHours(remainderHours * diff); if (NonWorkingDays.Count > 0) { var weekEndCount = CalculateWeekEndDayCount(NonWorkingDays[0], actualStart, startDate); // find the weekend occurrence from start and end date startDate = startDate.AddDays(weekEndCount * NonWorkingDays.Count); while (NonWorkingDays.Contains(startDate.DayOfWeek.ToString())) { startDate = startDate.AddDays(1); } } var currentWorkingHours1 = ((ActualRange.Delta * 24) - totalWorkingHours) * ZoomFactor; // working hours for zoomfactor value var totalDays1 = currentWorkingHours1 / diff; var remainderHours1 = totalDays1 - (int)totalDays1; var endDate = startDate.AddDays((int)totalDays1); endDate = (remainderHours1 * diff) > (CloseTime - endDate.TimeOfDay.TotalHours) ? new DateTime(endDate.Year, endDate.Month, endDate.Day).AddDays(1).AddHours(OpenTime + ((remainderHours1 * diff) - (CloseTime - endDate.TimeOfDay.TotalHours))) : endDate.AddHours(remainderHours1 * diff); // calculate end date if (NonWorkingDays.Count > 0) { var weekEndCount = CalculateWeekEndDayCount(NonWorkingDays[0], startDate, endDate); endDate = endDate.AddDays(weekEndCount * NonWorkingDays.Count); while (NonWorkingDays.Contains(endDate.DayOfWeek.ToString())) { endDate = endDate.AddDays(1); } } VisibleRange = new DoubleRange(startDate.ToOADate(), endDate.ToOADate()); // set the visible range } else { VisibleRange = new DoubleRange(actualStart.ToOADate(), actualEnd.ToOADate()); } } DateTimeAxisHelper.CalculateVisibleRange(this, availableSize, Interval); if (EnableBusinessHours) { CalculateNonWorkingDays(VisibleRange); } }
private void OnMinMaxChanged() { DateTimeAxisHelper.OnMinMaxChanged(this, Minimum, Maximum); }
/// <summary> /// Method implementation to Create VisibleLabels for DateTime axis. /// </summary> protected override void GenerateVisibleLabels() { DateTimeAxisHelper.GenerateVisibleLabels3D(this, this.Minimum, this.Maximum, this.ActualIntervalType3D); }
protected override void GenerateVisibleLabels() { ChartSeriesBase actualSeries = Area.VisibleSeries .Where(series => series.ActualXAxis == this) .Max(filteredSeries => filteredSeries.DataCount); actualSeries = actualSeries != null ? actualSeries : Area is SfChart ? (Area as SfChart).TechnicalIndicators.Where(series => series.ActualXAxis == this) .Max(filteredSeries => filteredSeries.DataCount) : null; SetRangeForAxisStyle(); if (actualSeries != null) { var XValuesCount = actualSeries.ActualXValues as List <double>; if (XValuesCount != null && XValuesCount.Count > 0) { double interval = Interval != 0 ? Interval : ActualInterval; double position = VisibleRange.Start - (VisibleRange.Start % ActualInterval); var xValues = actualSeries.ActualXValues as List <double>; var xStartValue = xValues[0].FromOADate(); double distinctDate = 0d; int year = xStartValue.Year, month = xStartValue.Month, hour = xStartValue.Hour, mins = xStartValue.Minute, secs = xStartValue.Second, millisecs = xStartValue.Millisecond; DateTime date = xStartValue.Date; switch (ActualIntervalType) { case DateTimeIntervalType.Months: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Year > year) { year = xValue.Year; month = xValue.Month; } if (xValue.Year == year) { if (xValue.Month > month) { month = xValue.Month; } if (xValue.Month == month) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); month = xValue.AddMonths((int)interval).Month; year = xValue.AddMonths((int)interval).Year; } } } } break; case DateTimeIntervalType.Years: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Year > year) { year = xValue.Year; } if (xValue.Year == year) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); year = xValue.AddYears((int)interval).Year; } } } break; case DateTimeIntervalType.Days: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Date > date) { date = xValue.Date; } if (xValue.Date == date) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); date = xValue.AddDays((int)interval).Date; } } } break; case DateTimeIntervalType.Hours: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Date > date) { date = xValue.Date; hour = xValue.Hour; } if (xValue.Date == date) { if (xValue.Hour > hour) { hour = xValue.Hour; } if (xValue.Hour == hour) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); hour = xValue.AddHours((int)interval).Hour; date = xValue.AddHours((int)interval).Date; } } } } break; case DateTimeIntervalType.Minutes: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Date > date) { date = xValue.Date; hour = xValue.Hour; } if (xValue.Date == date) { if (xValue.Hour > hour) { hour = xValue.Hour; mins = xValue.Minute; } if (xValue.Hour == hour) { if (xValue.Minute > mins) { mins = xValue.Minute; } if (xValue.Minute == mins) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); hour = xValue.AddMinutes((int)interval).Hour; mins = xValue.AddMinutes((int)interval).Minute; date = xValue.AddMinutes((int)interval).Date; } } } } } break; case DateTimeIntervalType.Seconds: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Date > date) { date = xValue.Date; hour = xValue.Hour; } if (xValue.Date == date) { if (xValue.Hour > hour) { hour = xValue.Hour; mins = xValue.Minute; } if (xValue.Hour == hour) { if (xValue.Minute > mins) { mins = xValue.Minute; secs = xValue.Second; } if (xValue.Minute == mins) { if (xValue.Second > secs) { secs = xValue.Second; } if (xValue.Second == secs) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); hour = xValue.AddSeconds((int)interval).Hour; mins = xValue.AddSeconds((int)interval).Minute; date = xValue.AddSeconds((int)interval).Date; secs = xValue.AddSeconds((int)interval).Second; } } } } } } break; case DateTimeIntervalType.Milliseconds: for (; position <= VisibleRange.End; position++) { int pos = ((int)Math.Round(position)); if (VisibleRange.Inside(position) && pos > -1 && pos < xValues.Count) { var xValue = xValues[pos].FromOADate(); if (xValue.Date > date) { date = xValue.Date; hour = xValue.Hour; } if (xValue.Date == date) { if (xValue.Hour > hour) { hour = xValue.Hour; mins = xValue.Minute; } if (xValue.Hour == hour) { if (xValue.Minute > mins) { mins = xValue.Minute; secs = xValue.Second; } if (xValue.Minute == mins) { if (xValue.Second > secs) { secs = xValue.Second; millisecs = xValue.Millisecond; } if (xValue.Second == secs) { if (xValue.Millisecond > millisecs) { millisecs = xValue.Millisecond; } if (xValue.Millisecond == millisecs) { object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); hour = xValue.AddMilliseconds((int)interval).Hour; mins = xValue.AddMilliseconds((int)interval).Minute; date = xValue.AddMilliseconds((int)interval).Date; secs = xValue.AddMilliseconds((int)interval).Second; millisecs = xValue.AddMilliseconds((int)interval).Millisecond; } } } } } } } break; case DateTimeIntervalType.Auto: for (; position <= VisibleRange.End; position += interval) { if (VisibleRange.Inside(position) && position < actualSeries.DataCount && position > -1) { int pos = ((int)Math.Round(position)); var xValue = xValues[pos].FromOADate(); object obj = GetLabelContent(pos, actualSeries); var dateTimeAxisLabel = new DateTimeAxisLabel(pos, obj, xValues[pos]); dateTimeAxisLabel.IntervalType = ActualIntervalType; dateTimeAxisLabel.IsTransition = DateTimeAxisHelper.GetTransitionState(ref distinctDate, xValue, ActualIntervalType); VisibleLabels.Add(dateTimeAxisLabel); } } break; } } } }