public static TimeRangeCollection Divide(TimeRange range)
        {
            TimeRangeCollection list = new TimeRangeCollection();

            list.Kind = GetKind(range);

            var currentDateTime = range.StartDateTime;
            while (currentDateTime < range.EndDateTime)
            {
                var endDate = GetRangeEndDateTime(list.Kind, currentDateTime);
                if (endDate > range.EndDateTime)
                {
                    endDate = range.EndDateTime;
                }

                list.Add(new TimeRange()
                {
                    StartDateTime = currentDateTime,
                    EndDateTime = endDate
                });
                currentDateTime = endDate;
            }

            return list;
        }
 private void MoveToTimePosition(ref double x, ref double y, TimeRange range)
 {
     y = _timePosConverter.ConvertToPos(range.StartDateTime);
     _borderHeight = _timePosConverter.ConvertToPos(range.EndDateTime) - y;
 }
        public TextBlock GetSmallTextBlock(TimeRange prevRange, TimeRange currentRange)
        {
            var smallText = GetSmallText(currentRange);
            if (prevRange == null || GetSmallText(prevRange) != smallText)
            {
                var block = GetVacanteTextBlock();
                block.FontSize = 12;
                block.Foreground = Brushes.White;
                block.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                block.Text = smallText;

                return block;
            }

            return GetVacanteTextBlock();
        }
 public string GetSmallText(TimeRange range)
 {
     switch (TimeRangeCollection.Kind)
     {
         case TimeRangeDivideKind.Sec30:
             return range.StartDateTime.ToString("ss秒");
         case TimeRangeDivideKind.Min1:
         case TimeRangeDivideKind.Min2:
         case TimeRangeDivideKind.Min5:
         case TimeRangeDivideKind.Min15:
         case TimeRangeDivideKind.Min30:
             return range.StartDateTime.ToString("mm分");
         case TimeRangeDivideKind.Hour1:
         case TimeRangeDivideKind.Hour2:
         case TimeRangeDivideKind.Hour4:
         case TimeRangeDivideKind.Hour8:
             return range.StartDateTime.ToString("HH時");
         case TimeRangeDivideKind.Day1:
         case TimeRangeDivideKind.Day2:
         case TimeRangeDivideKind.MonthHalf:
             return range.StartDateTime.ToString("dd日(ddd)");
     }
     return "";
 }
        public UIElement GenerateScaleControl(TimeRange prevRange, TimeRange currentRange)
        {
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.HorizontalAlignment = HorizontalAlignment.Right;
            panel.Children.Add(GetLargestTextBlock(prevRange, currentRange));
            panel.Children.Add(GetMiddleTextBlock(prevRange, currentRange));
            panel.Children.Add(GetSmallTextBlock(prevRange, currentRange));

            return panel;
        }
 public DateTimeAndPosConverter(double minPos, double maxPos, TimeRange range)
 {
     _minPos = minPos;
     _maxPos = maxPos;
     _range = range;
 }
        public static TimeRangeDivideKind GetKind(TimeRange range)
        {
            TimeSpan span = new TimeSpan(range.EndDateTime.Ticks - range.StartDateTime.Ticks);

            if (span.TotalDays > 62)
            {
                return TimeRangeDivideKind.MonthHalf;
            }

            if (span.TotalDays > 14)
            {
                return TimeRangeDivideKind.Day2;
            }

            if (span.TotalDays > 7)
            {
                return TimeRangeDivideKind.Day1;
            }

            if (span.TotalHours > 96)
            {
                return TimeRangeDivideKind.Hour8;
            }

            if (span.TotalHours > 48)
            {
                return TimeRangeDivideKind.Hour4;
            }

            if (span.TotalHours > 24)
            {
                return TimeRangeDivideKind.Hour2;
            }

            if (span.TotalHours > 12)
            {
                return TimeRangeDivideKind.Hour1;
            }

            if (span.TotalHours > 6)
            {
                return TimeRangeDivideKind.Min30;
            }

            if(span.TotalHours > 3)
            {
                return TimeRangeDivideKind.Min15;
            }

            if(span.TotalMinutes > 60)
            {
                return TimeRangeDivideKind.Min5;
            }

            if (span.TotalMinutes > 30)
            {
                return TimeRangeDivideKind.Min2;
            }
            if (span.TotalMinutes > 15)
            {
                return TimeRangeDivideKind.Min1;
            }

            return TimeRangeDivideKind.Sec30;
        }
        private TextBlock GetSmallTextBlock(TimeRange prevRange, TimeRange currentRange)
        {
            var smallText = GetSmallText(currentRange);
            if (prevRange == null || GetSmallText(prevRange) != smallText)
            {
                return GetSmallTextBlock(smallText);
            }

            return GetVacantTextBlock();
        }
        private TextBlock GetMiddleTextBlock(TimeRange prevRange, TimeRange currentRange)
        {
            var middleText = GetMiddleText(currentRange);
            if (prevRange == null || GetMiddleText(prevRange) != middleText)
            {
                return GetMiddleTextBlock(middleText);
            }

            return GetVacantTextBlock();
        }
        private TextBlock GetLargestTextBlock(TimeRange prevRange, TimeRange currentRange)
        {
            var largestText = GetLargestText(currentRange);
            if (prevRange == null || GetLargestText(prevRange) != largestText)
            {
                return GetLargestTextBlock(largestText);
            }

            return GetVacantTextBlock();
        }
 private string GetLargestText(TimeRange range)
 {
     switch (TimeRangeCollection.Kind)
     {
         case TimeRangeDivideKind.Sec30:
             return range.StartDateTime.ToString("HH時");
         case TimeRangeDivideKind.Min1:
         case TimeRangeDivideKind.Min2:
         case TimeRangeDivideKind.Min5:
         case TimeRangeDivideKind.Min15:
         case TimeRangeDivideKind.Min30:
             return range.StartDateTime.ToString("dd日(ddd)");
         case TimeRangeDivideKind.Hour1:
         case TimeRangeDivideKind.Hour2:
         case TimeRangeDivideKind.Hour4:
         case TimeRangeDivideKind.Hour8:
             return range.StartDateTime.ToString("MM月");
         case TimeRangeDivideKind.Day1:
         case TimeRangeDivideKind.Day2:
         case TimeRangeDivideKind.MonthHalf:
             return range.StartDateTime.ToString("yy年");
     }
     return "";
 }