示例#1
0
        //---------------------------------------------------------------------------------------------------------------------------------------
        void OnRender_TimeAndDay(DrawingContext drawingContext, Pen pen)
        {
            int  time_csi    = -1;
            bool isHourStart = false;

            int  date_csi = -1;
            bool isMonthStart = false, isYearStart = false;
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            double topTimePanelY    = RenderSize.Height - TimeAxisHeight;
            double centerTimePanelY = RenderSize.Height - TimeAxisHeight / 2.0;
            double smallMarkLineY   = topTimePanelY + TimeAxisHeight / 8.0;

            void DrawTimeTick()
            {
                //double timeTickRightMargin = CandleWidth/2.0 +  (day_csi - VisibleCandlesRange.Start_i) * (CandleWidth + GapBetweenCandles);
                string        timeTickText          = TimeTick.ConvertDateTimeToTimeTickText(isHourStart, CandlesSource[time_csi].t);
                FormattedText timeTickFormattedText = new FormattedText(timeTickText, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), TimeTickFontSize, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip);
                double        x = CandleWidth / 2.0 + (time_csi - VisibleCandlesRange.Start_i) * (CandleWidth + GapBetweenCandles);

                drawingContext.DrawText(timeTickFormattedText, new Point(x + 2, topTimePanelY));
                drawingContext.DrawLine(pen, new Point(x, topTimePanelY), new Point(x, isHourStart ? centerTimePanelY : smallMarkLineY));

                if (IsGridlinesEnabled && GridlinesPen != null && isHourStart)
                {
                    drawingContext.DrawLine(GridlinesPen, new Point(x, 0), new Point(x, topTimePanelY));
                }
            }

            void DrawDateTick()
            {
                string        dateTickText          = TimeTick.ConvertDateTimeToDateTickText(isYearStart, isMonthStart, CandlesSource[date_csi].t);
                FormattedText dateTickFormattedText = new FormattedText(dateTickText, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), TimeTickFontSize, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip);
                double        x = CandleWidth / 2.0 + (date_csi - VisibleCandlesRange.Start_i) * (CandleWidth + GapBetweenCandles);

                drawingContext.DrawText(dateTickFormattedText, new Point(x + 2, centerTimePanelY));
                drawingContext.DrawLine(pen, new Point(x, centerTimePanelY), new Point(x, RenderSize.Height));
            }

            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            int time_LabelWidthInCandles = Convert.ToInt32(Math.Ceiling(Time_TickWidth / (CandleWidth + GapBetweenCandles)));
            int date_LabelWidthInCandles = Convert.ToInt32(Math.Ceiling(DayOrMonthOrYear_TickWidth / (CandleWidth + GapBetweenCandles)));

            for (int i = VisibleCandlesRange.Start_i + VisibleCandlesRange.Count - 1; i >= VisibleCandlesRange.Start_i; i--)
            {
                ICandle cndl      = CandlesSource[i];
                ICandle prev_cndl = i > 0 ? CandlesSource[i - 1] : CandlesSource[0];

                // Если cndl - это начало нового дня:
                if (i > 0 && cndl.t.Date != prev_cndl.t.Date)
                {
                    // Если cndl - это начало нового месяца:
                    if (cndl.t.Month != prev_cndl.t.Month)
                    {
                        if ((date_csi - i) >= date_LabelWidthInCandles)
                        {
                            DrawDateTick();
                            date_csi     = i;
                            isMonthStart = true;
                            isYearStart  = cndl.t.Year != prev_cndl.t.Year;
                        }
                        else if (date_csi == -1 || !isMonthStart || (!isYearStart && cndl.t.Year != prev_cndl.t.Year))
                        {
                            date_csi     = i;
                            isMonthStart = true;
                            isYearStart  = cndl.t.Year != prev_cndl.t.Year;
                        }
                    }
                    // Если cndl - это НЕ начало нового месяца:
                    else
                    {
                        if (date_csi == -1)
                        {
                            date_csi     = i;
                            isMonthStart = isYearStart = false;
                        }
                        else if ((date_csi - i) >= date_LabelWidthInCandles)
                        {
                            DrawDateTick();
                            date_csi     = i;
                            isMonthStart = isYearStart = false;
                        }
                    }
                }

                // Если cndl - это начало нового часа:
                if (MyDateAndTime.IsTimeMultipleOf(cndl.t, 60) || (i > 0 && !MyDateAndTime.IsInSameHour(cndl.t, prev_cndl.t)))
                {
                    if ((time_csi - i) >= time_LabelWidthInCandles)
                    {
                        DrawTimeTick();
                        time_csi    = i;
                        isHourStart = true;
                    }
                    else if (time_csi == -1 || !isHourStart)
                    {
                        time_csi    = i;
                        isHourStart = true;
                    }
                }
                // Если cndl внутри часа:
                else if (MyDateAndTime.IsTimeMultipleOf(cndl.t, TimeTicksTimeFrame))
                {
                    if (time_csi == -1)
                    {
                        time_csi    = i;
                        isHourStart = false;
                    }
                    else if ((time_csi - i) >= time_LabelWidthInCandles)
                    {
                        DrawTimeTick();
                        time_csi    = i;
                        isHourStart = false;
                    }
                }
            }

            // И не забудем нарисовать последний таймтик из "кэша", если он там есть:
            if (time_csi != -1)
            {
                DrawTimeTick();
            }
            if (date_csi != -1)
            {
                DrawDateTick();
            }
        }