示例#1
0
        internal void SetEndDate(DrawingContext context)
        {
            float visibleRight = context.Left + context.Width;
            int   leftIndex    = GetIndexByPoint(context.Left);
            int   rightIndex   = GetIndexByPoint(visibleRight);

            TimeSpan axisInterval = new TimeSpan();

            for (int cellIndex = leftIndex; cellIndex <= rightIndex; cellIndex++)
            {
                TimeCell   cell      = GetCell(cellIndex);
                RectangleF rectangle = new RectangleF(cell.Left, context.CurrentTop, cell.Width, this.Height);

                if (rectangle.Left >= context.Left && rectangle.Right <= visibleRight)
                {
                    axisInterval += cell.Interval;
                }
                else if (rectangle.Left < context.Left && rectangle.Right <= visibleRight)
                {
                    axisInterval += cell.GetTimeInterval(rectangle.Right - context.Left);
                }
                else if (rectangle.Left >= context.Left && rectangle.Right > visibleRight)
                {
                    axisInterval += cell.GetTimeInterval(visibleRight - rectangle.Left);
                }
            }

            context.EndDate = _viewStartDate + axisInterval;
        }
示例#2
0
        private int GetIndexByPoint(float left)
        {
            int index = 0;

            TimeCell cell = GetCell(index);

            // Step 1. First approximation
            index = Convert.ToInt32(left / cell.Width);

            // Step 2. Calibration
            bool next     = false;
            bool previous = false;

            while (true)
            {
                if (next && previous)
                {
                    throw new GanttControlException(string.Format(CultureInfo.CurrentUICulture, "CalibrateIndex deadlock. Index = '{0}', Point X = '{1}'", index, left));
                }

                cell = GetCell(index);

                if ((cell.Left + cell.Width) < left)
                {
                    index++;
                    next = true;
                    continue;
                }

                if (cell.Left > left)
                {
                    index--;
                    previous = true;
                    continue;
                }

                break;
            }

            return(index);
        }
示例#3
0
        public override void RenderElement(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;

            this.Height = context.HeaderItemHeight;
            float visibleRight = context.Left + context.Width;

            int leftIndex  = GetIndexByPoint(context.Left);
            int rightIndex = GetIndexByPoint(visibleRight);

            TimeSpan axisInterval = new TimeSpan();

            for (int cellIndex = leftIndex; cellIndex <= rightIndex; cellIndex++)
            {
                TimeCell   cell      = GetCell(cellIndex);
                RectangleF rectangle = new RectangleF(cell.Left, context.CurrentTop, cell.Width, this.Height);

                if (rectangle.Left >= context.Left && rectangle.Right <= visibleRight)
                {
                    axisInterval += cell.Interval;
                }
                else if (rectangle.Left < context.Left && rectangle.Right <= visibleRight)
                {
                    axisInterval += cell.GetTimeInterval(rectangle.Right - context.Left);
                }
                else if (rectangle.Left >= context.Left && rectangle.Right > visibleRight)
                {
                    axisInterval += cell.GetTimeInterval(visibleRight - rectangle.Left);
                }

                using (SolidBrush backgroundBrush = new SolidBrush(style.BackgroundColor))
                {
                    context.Graphics.FillRectangle(backgroundBrush, rectangle);
                }

                StringBuilder text = new StringBuilder();

                switch (_titleType)
                {
                case TitleType.Start:
                    text.Append(GetDateText(cell.StartDate, _format, context.Provider));
                    break;

                case TitleType.StartEnd:
                    text.Append(GetDateText(cell.StartDate, _format, context.Provider));
                    text.Append(" - ");
                    text.Append(GetDateText(cell.StartDate.AddTicks(cell.Interval.Ticks - 1), _format, context.Provider));
                    break;
                }

                if (text.Length > 0)
                {
                    if (_scale == ScaleLevel.Week)
                    {
                        string weekNumber = string.Format(CultureInfo.InvariantCulture, " (#{0})", Iso8601WeekNumber.GetWeekNumber(cell.StartDate));
                        text.Append(weekNumber);
                    }

                    using (SolidBrush textBrush = new SolidBrush(style.ForegroundColor))
                    {
                        // TODO: Load font style from style sheet.
                        Font font = new Font("Arial", 8, FontStyle.Regular);

                        StringFormat stringFormat = new StringFormat();
                        stringFormat.Alignment     = StringAlignment.Center;
                        stringFormat.LineAlignment = StringAlignment.Center;

                        context.Graphics.DrawString(text.ToString(), font, textBrush, rectangle, stringFormat);
                    }
                }

                rectangle.Width--;
                rectangle.Height--;
                using (Pen borderPen = new Pen(style.BorderColor, style.BorderWidth))
                {
                    context.Graphics.DrawLine(borderPen, rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom);
                }
            }

            context.EndDate = _viewStartDate + axisInterval;
        }