Example #1
0
        public override void RenderGanttElement(DrawingContext context, RectangleF rectangle, Brush backgroundBrush, Pen borderPen)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;

            if (backgroundBrush != null)
            {
                context.Graphics.FillRectangle(backgroundBrush, rectangle);
            }

            if (borderPen != null)
            {
                int n = this.Children.Count + 1;
                for (int i = 0; i < n; i++)
                {
                    float y = rectangle.Top + i * (context.HeaderItemHeight + style.BorderWidth);
                    context.Graphics.DrawLine(borderPen, rectangle.Left, y, rectangle.Right, y);
                }
            }

            _rectangle = rectangle;
        }
Example #2
0
        public virtual RectangleF CalculateRectangle(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;

            float width = this.Width;

            if (width <= 0)
            {
                width = style.Width;
            }

            float height = this.Height;

            if (height <= 0)
            {
                height = style.Height;
            }

            return(new RectangleF(context.Left, context.CurrentTop, width, height));
        }
Example #3
0
        public override RectangleF CalculateRectangle(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;

            _startX = context.DateToPixel(_value);
            float x = _startX;

            float width  = style.Width;
            float height = style.Height;

            // Make odd size
            if ((width % 2) == 0)
            {
                width--;
            }
            if ((height % 2) == 0)
            {
                height--;
            }

            float minSize = Math.Min(style.Width, style.Height);

            switch (style.ShapeStyle)
            {
            case ShapeStyle.Circle:
                width = height = minSize;
                x    -= (width - 1) / 2;
                break;

            case ShapeStyle.LeftTriangle:
                height = minSize;
                width  = (minSize + 1) / 2;
                x     += 1 - width;
                break;

            case ShapeStyle.RightTriangle:
                height = minSize;
                width  = (minSize + 1) / 2;
                break;

            default:
                x -= (width - 1) / 2;
                break;
            }

            float y = context.CurrentTop + (context.ItemHeight - height) / 2;

            return(new RectangleF(x, y, width, height));
        }
Example #4
0
        public override void RenderElement(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            DateTime leftDate     = context.PixelToDate(context.Left).Date;
            DateTime rightDate    = context.PixelToDate(context.Left + context.Width).Date;
            bool     isTopPortion = context.CurrentTop > context.Top;
            float    top          = isTopPortion ? context.CurrentTop : context.Top;
            float    width        = context.TimeSpanToPixel(new TimeSpan(1, 0, 0, 0));
            float    height       = isTopPortion ? context.FreeHeight : context.Height;

            DateTime currentDate = leftDate;

            while (currentDate <= rightDate)
            {
                bool render = false;

                if (_dayOfWeek != null)
                {
                    if (currentDate.DayOfWeek == _dayOfWeek.Value)
                    {
                        render = true;
                    }
                }

                if (_date != null)
                {
                    if (currentDate == _date.Value)
                    {
                        render = true;
                    }
                }

                if (render)
                {
                    GanttStyle style     = this.Style as GanttStyle;
                    RectangleF rectangle = new RectangleF(context.DateToPixel(currentDate), top, width, height);

                    using (Brush backgroundBrush = CreateBackgroundBrush(style))
                        using (Pen borderPen = CreateBorderPen(style))
                        {
                            RenderGanttElement(context, rectangle, backgroundBrush, borderPen);
                        }
                }

                currentDate = currentDate.AddDays(1);
            }
        }
Example #5
0
        public override void RenderElement(DrawingContext context)
        {
            GanttStyle style = this.Style as GanttStyle;

            if (style.ShapeStyle != ShapeStyle.None)
            {
                _rectangle = CalculateRectangleAndSetSize(context);

                using (Brush backgroundBrush = CreateBackgroundBrush(style))
                    using (Pen borderPen = CreateBorderPen(style))
                    {
                        RenderGanttElement(context, _rectangle, backgroundBrush, borderPen);
                    }
            }
        }
Example #6
0
        protected static Pen CreateBorderPen(GanttStyle style)
        {
            if (style == null)
            {
                throw new ArgumentNullException("style");
            }

            switch (style.BorderStyle)
            {
            case BorderStyle.Solid:
                return(new Pen(style.BorderColor, style.BorderWidth));

            default:
                return(null);
            }
        }
Example #7
0
        public override RectangleF CalculateRectangle(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;

            float height = style.Height;
            float x      = context.DateToPixel(_start);
            float x2     = context.DateToPixel(_finish);
            float width  = x2 - x;
            float y      = context.CurrentTop + (context.ItemHeight - height) / 2;

            return(new RectangleF(x, y, width, height));
        }
Example #8
0
        public void LoadStyleSheet(IXPathNavigable styles)
        {
            _styles.Clear();
            int ruleOrder = 0;

            foreach (XPathNavigator node in styles.CreateNavigator().SelectSingleNode("style").SelectChildren(XPathNodeType.Element))
            {
                switch (node.Name)
                {
                case "rule":
                    GanttStyle style = new GanttStyle();
                    style.Load(node, StyleNamespaceId, ruleOrder);
                    _styles.Add(style);
                    ruleOrder++;
                    break;
                }
            }
            _styles.Sort();
        }
Example #9
0
        private void ApplyStyle(Element element)
        {
            List <Style> styles = new List <Style>();

            foreach (Style style in _styles)
            {
                if (style.Selector.Matches(element))
                {
                    styles.Add(style);
                }
            }

            GanttStyle computedStyle = new GanttStyle();

            bool allPropertiesAreDefined = false;

            for (int i = styles.Count - 1; i >= 0; i--)
            {
                allPropertiesAreDefined = computedStyle.CopyFrom(styles[i], false);
                if (allPropertiesAreDefined)
                {
                    break;
                }
            }

            if (!allPropertiesAreDefined && element.Parent != null)
            {
                allPropertiesAreDefined = computedStyle.CopyFrom(element.Parent.Style, true);
            }

            if (!allPropertiesAreDefined)
            {
                computedStyle.ApplyDefaultValues();
            }

            computedStyle.CalculateValues();
            element.Style = computedStyle;

            foreach (Element child in element.Children)
            {
                ApplyStyle(child);
            }
        }
Example #10
0
        protected static Brush CreateBackgroundBrush(GanttStyle style)
        {
            if (style == null)
            {
                throw new ArgumentNullException("style");
            }

            switch (style.FillStyle)
            {
            case FillStyle.Hatch:
                return(new HatchBrush(style.HatchStyle, style.ForegroundColor, style.BackgroundColor));

            case FillStyle.Solid:
                return(new SolidBrush(style.BackgroundColor));

            default:
                return(null);
            }
        }
Example #11
0
        public override void RenderChildren(DrawingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            GanttStyle style = this.Style as GanttStyle;
            float      y     = context.CurrentTop;

            foreach (Element child in this.Children)
            {
                context.CurrentTop += style.BorderWidth;

                child.Render(context);

                context.CurrentTop += child.Height;
            }

            context.CurrentTop = y;

            context.Graphics.SetClip(_rectangle, CombineMode.Exclude);
        }
Example #12
0
        protected static Pen CreateBorderPen(GanttStyle style)
        {
            if (style == null)
                throw new ArgumentNullException("style");

            switch (style.BorderStyle)
            {
                case BorderStyle.Solid:
                    return new Pen(style.BorderColor, style.BorderWidth);
                default:
                    return null;
            }
        }
Example #13
0
        protected static Brush CreateBackgroundBrush(GanttStyle style)
        {
            if (style == null)
                throw new ArgumentNullException("style");

            switch (style.FillStyle)
            {
                case FillStyle.Hatch:
                    return new HatchBrush(style.HatchStyle, style.ForegroundColor, style.BackgroundColor);
                case FillStyle.Solid:
                    return new SolidBrush(style.BackgroundColor);
                default:
                    return null;
            }
        }
Example #14
0
        public float CalculateHeight(float headerItemHeight)
        {
            GanttStyle style = this.Style as GanttStyle;

            return(headerItemHeight * this.Children.Count + style.BorderWidth * (this.Children.Count + 1));
        }
Example #15
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;
        }
Example #16
0
        public override void RenderGanttElement(DrawingContext context, RectangleF rectangle, Brush backgroundBrush, Pen borderPen)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            float height = rectangle.Height;

            // Make even size
            if ((height % 2) != 0)
            {
                height++;
            }

            float halfHeight = rectangle.Height / 2;

            GanttStyle style = this.Style as GanttStyle;

            PointF[] points = null;

            switch (style.ShapeStyle)
            {
            case ShapeStyle.Height50PercentUp:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Top + halfHeight),
                    new PointF(rectangle.Left, rectangle.Top + halfHeight),
                };
                break;

            case ShapeStyle.Height50PercentDown:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Bottom - halfHeight),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - halfHeight),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, rectangle.Bottom - 1),
                };
                break;

            default:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, rectangle.Bottom - 1),
                };
                break;
            }

            if (points != null)
            {
                if (backgroundBrush != null)
                {
                    context.Graphics.FillPolygon(backgroundBrush, points);
                }

                if (borderPen != null)
                {
                    if (style.ShapeStyle == ShapeStyle.Interval)
                    {
                        context.Graphics.DrawLine(borderPen, rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom - 1);
                        context.Graphics.DrawLine(borderPen, rectangle.Right - 1, rectangle.Top, rectangle.Right - 1, rectangle.Bottom - 1);
                    }
                    else
                    {
                        context.Graphics.DrawPolygon(borderPen, points);
                    }
                }
            }
        }
Example #17
0
        public override void RenderGanttElement(DrawingContext context, RectangleF rectangle, Brush backgroundBrush, Pen borderPen)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            float halfWidth  = (rectangle.Width - 1) / 2;
            float halfHeight = (rectangle.Height - 1) / 2;

            float centerX = rectangle.Left + halfWidth;
            float centerY = rectangle.Top + halfHeight;

            GanttStyle style = this.Style as GanttStyle;

            PointF[]   points  = null;
            RectangleF ellipse = RectangleF.Empty;

            switch (style.ShapeStyle)
            {
            case ShapeStyle.Circle:
            case ShapeStyle.Ellipse:
                ellipse = rectangle;
                ellipse.Width--;
                ellipse.Height--;
                break;

            case ShapeStyle.LeftTriangle:
                points = new PointF[]
                {
                    new PointF(rectangle.Right - 1, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, centerY),
                };
                break;

            case ShapeStyle.RightTriangle:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(rectangle.Left, rectangle.Bottom - 1),
                    new PointF(rectangle.Right - 1, centerY),
                };
                break;

            case ShapeStyle.Rhombus:
                points = new PointF[]
                {
                    new PointF(centerX, rectangle.Top),
                    new PointF(rectangle.Right - 1, centerY),
                    new PointF(centerX, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, centerY),
                };
                break;

            case ShapeStyle.PentagonDown:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Top),
                    new PointF(rectangle.Right - 1, centerY),
                    new PointF(centerX, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, centerY),
                };
                break;

            case ShapeStyle.PentagonUp:
                points = new PointF[]
                {
                    new PointF(centerX, rectangle.Top),
                    new PointF(rectangle.Right - 1, centerY),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, centerY),
                };
                break;

            case ShapeStyle.PentagonRight:
                points = new PointF[]
                {
                    new PointF(rectangle.Right - 1, centerY),
                    new PointF(centerX, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, rectangle.Bottom - 1),
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(centerX, rectangle.Top),
                };
                break;

            case ShapeStyle.PentagonLeft:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, centerY),
                    new PointF(centerX, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Top),
                    new PointF(rectangle.Right - 1, rectangle.Bottom - 1),
                    new PointF(centerX, rectangle.Bottom - 1),
                };
                break;

            default:
                points = new PointF[]
                {
                    new PointF(rectangle.Left, rectangle.Top),
                    new PointF(rectangle.Right, rectangle.Top),
                    new PointF(rectangle.Right, rectangle.Bottom),
                    new PointF(rectangle.Left, rectangle.Bottom),
                };
                break;
            }

            if (ellipse != RectangleF.Empty)
            {
                if (backgroundBrush != null)
                {
                    context.Graphics.FillEllipse(backgroundBrush, ellipse);
                }
                if (borderPen != null)
                {
                    context.Graphics.DrawEllipse(borderPen, ellipse);
                }
            }

            if (points != null)
            {
                if (backgroundBrush != null)
                {
                    context.Graphics.FillPolygon(backgroundBrush, points);
                }
                if (borderPen != null)
                {
                    context.Graphics.DrawPolygon(borderPen, points);
                }
            }
        }
Example #18
0
        private void ApplyStyle(Element element)
        {
            List<Style> styles = new List<Style>();
            foreach (Style style in _styles)
            {
                if (style.Selector.Matches(element))
                    styles.Add(style);
            }

            GanttStyle computedStyle = new GanttStyle();

            bool allPropertiesAreDefined = false;
            for (int i = styles.Count - 1; i >= 0; i--)
            {
                allPropertiesAreDefined = computedStyle.CopyFrom(styles[i], false);
                if (allPropertiesAreDefined)
                    break;
            }

            if(!allPropertiesAreDefined && element.Parent != null)
                allPropertiesAreDefined = computedStyle.CopyFrom(element.Parent.Style, true);

            if (!allPropertiesAreDefined)
                computedStyle.ApplyDefaultValues();

            computedStyle.CalculateValues();
            element.Style = computedStyle;

            foreach (Element child in element.Children)
            {
                ApplyStyle(child);
            }
        }
Example #19
0
        public override void RenderGanttElement(DrawingContext context, RectangleF rectangle, Brush backgroundBrush, Pen borderPen)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Calculate arrow size
            GanttStyle style = this.Style as GanttStyle;

            _arrowSize = Math.Min(style.Width, style.Height);

            GanttElement originElement = _origin as GanttElement;
            GanttElement targetElement = _target as GanttElement;

            RectangleF origin = originElement.Rectangle;
            RectangleF target = targetElement.Rectangle;

            PointF originEnd   = new PointF(origin.Right, Convert.ToSingle(Math.Ceiling(origin.Top - 1 + origin.Height / 2)));
            PointF targetStart = new PointF(targetElement.StartX, Convert.ToSingle(Math.Ceiling(target.Top - 1 + target.Height / 2)));

            PointF[] linePoints  = null;
            PointF[] arrowPoints = null;

            bool  riseY           = target.Y > origin.Y;
            float doubleArrowSize = _arrowSize * 2;

            if (targetStart.X - originEnd.X > doubleArrowSize)
            {
                PointF pointer = new PointF(targetStart.X, riseY ? target.Top - 1 : target.Bottom);

                // Direct arrow: 3 points
                linePoints = new PointF[3]
                {
                    originEnd,
                    new PointF(pointer.X, originEnd.Y),
                    new PointF(pointer.X, riseY ? pointer.Y - _arrowSize - 1 : pointer.Y + _arrowSize + 1)
                };

                arrowPoints = CreateArrow(pointer, false, riseY);
            }
            else
            {
                PointF pointer = new PointF(target.Left - 1, targetStart.Y);

                // Back arrow: 6 points
                float intermediateY = riseY ? origin.Bottom + 1 : origin.Top - 2;

                linePoints = new PointF[6]
                {
                    originEnd,
                    new PointF(originEnd.X + doubleArrowSize, originEnd.Y),
                    new PointF(originEnd.X + doubleArrowSize, intermediateY),
                    new PointF(pointer.X - doubleArrowSize - 1, intermediateY),
                    new PointF(pointer.X - doubleArrowSize - 1, pointer.Y),
                    new PointF(pointer.X - _arrowSize - 1, pointer.Y)
                };

                arrowPoints = CreateArrow(pointer, true, true);
            }

            if (linePoints != null)
            {
                if (borderPen != null)
                {
                    context.Graphics.DrawLines(borderPen, linePoints);
                }
            }

            if (arrowPoints != null)
            {
                if (backgroundBrush != null)
                {
                    context.Graphics.FillPolygon(backgroundBrush, arrowPoints);
                }
                if (borderPen != null)
                {
                    context.Graphics.DrawPolygon(borderPen, arrowPoints);
                }
            }
        }
Example #20
0
 public void LoadStyleSheet(IXPathNavigable styles)
 {
     _styles.Clear();
     int ruleOrder = 0;
     foreach (XPathNavigator node in styles.CreateNavigator().SelectSingleNode("style").SelectChildren(XPathNodeType.Element))
     {
         switch (node.Name)
         {
             case "rule":
                 GanttStyle style = new GanttStyle();
                 style.Load(node, StyleNamespaceId, ruleOrder);
                 _styles.Add(style);
                 ruleOrder++;
                 break;
         }
     }
     _styles.Sort();
 }