Completed
Last Updated: 27 Sep 2017 10:52 by ADMIN
ADMIN
Hristo
Created on: 08 Sep 2017 13:36
Category: GanttView
Type: Bug Report
1
FIX. RadGanttView - the timeline items are not correctly printed if the GraphicalViewElement.TimelineStart property is set to a value inside the range of the timeline items
How to reproduce: 
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();

            this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2010, 10, 9);
            this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineEnd = new DateTime(2010, 12, 10);

            //setup data items
            GanttViewDataItem item1 = new GanttViewDataItem();
            item1.Start = new DateTime(2010, 10, 10);
            item1.End = new DateTime(2010, 10, 15);
            item1.Progress = 30m;
            item1.Title = "Summary task.1. title";

            GanttViewDataItem subitem11 = new GanttViewDataItem();
            subitem11.Start = new DateTime(2010, 10, 10);
            subitem11.End = new DateTime(2010, 10, 12);
            subitem11.Progress = 10m;
            subitem11.Title = "Sub-task.1.1 title";

            GanttViewDataItem subitem12 = new GanttViewDataItem();
            subitem12.Start = new DateTime(2010, 10, 12);
            subitem12.End = new DateTime(2010, 10, 15);
            subitem12.Progress = 20m;
            subitem12.Title = "Sub-task.1.2 title";

            //add subitems
            item1.Items.Add(subitem11);
            item1.Items.Add(subitem12);

            this.radGanttView1.Items.Add(item1);

            GanttViewDataItem item2 = new GanttViewDataItem();
            item2.Start = new DateTime(2010, 10, 12);
            item2.End = new DateTime(2010, 10, 18);
            item2.Progress = 40m;
            item2.Title = "Summary task.2. title";

            GanttViewDataItem subitem21 = new GanttViewDataItem();
            subitem21.Start = new DateTime(2010, 10, 12);
            subitem21.End = new DateTime(2010, 10, 13);
            subitem21.Progress = 10m;
            subitem21.Title = "Sub-task.2.1 title";

            GanttViewDataItem subitem22 = new GanttViewDataItem();
            subitem22.Start = new DateTime(2010, 10, 13);
            subitem22.End = new DateTime(2010, 10, 18);
            subitem22.Progress = 30m;
            subitem22.Title = "Sub-task.2.2 title";

            GanttViewDataItem subitem23 = new GanttViewDataItem();
            subitem23.Start = new DateTime(2010, 10, 18);
            subitem23.End = new DateTime(2010, 10, 18);
            subitem23.Title = "Sub-task.2.3 title";

            //add subitems
            item2.Items.Add(subitem21);
            item2.Items.Add(subitem22);
            item2.Items.Add(subitem23);

            this.radGanttView1.Items.Add(item2);

            //add links between items
            GanttViewLinkDataItem link1 = new GanttViewLinkDataItem();
            link1.StartItem = subitem11;
            link1.EndItem = subitem12;
            link1.LinkType = TasksLinkType.FinishToStart;
            this.radGanttView1.Links.Add(link1);

            GanttViewLinkDataItem link2 = new GanttViewLinkDataItem();
            link2.StartItem = subitem21;
            link2.EndItem = subitem22;
            link2.LinkType = TasksLinkType.StartToStart;
            this.radGanttView1.Links.Add(link2);

            GanttViewLinkDataItem link3 = new GanttViewLinkDataItem();
            link3.StartItem = subitem22;
            link3.EndItem = subitem23;
            link3.LinkType = TasksLinkType.FinishToStart;
            this.radGanttView1.Links.Add(link3);

            GanttViewTextViewColumn titleColumn = new GanttViewTextViewColumn("Title");
            GanttViewTextViewColumn startColumn = new GanttViewTextViewColumn("Start");
            GanttViewTextViewColumn endColumn = new GanttViewTextViewColumn("End");

            this.radGanttView1.GanttViewElement.Columns.Add(titleColumn);
            this.radGanttView1.GanttViewElement.Columns.Add(startColumn);
            this.radGanttView1.GanttViewElement.Columns.Add(endColumn);

            this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2010, 10, 13);
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            RadPrintDocument doc = new RadPrintDocument();
            doc.Landscape = true;
            RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
            doc.AssociatedObject = this.radGanttView1;
            dialog.Document = doc;
            dialog.ShowDialog();
        }
    }

Workaround: create a custom RadGanttView
public class MyRadGanttView : RadGanttView
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadGanttView).FullName;
        }
    }

    protected override PointF[] GetElementShape(GanttViewPrintElementContext context, RectangleF rect)
    {
        if (shouldPaintStartCap)
        {
            return base.GetElementShape(context, rect);
        }

        switch (context)
        {
            case GanttViewPrintElementContext.SummaryTaskElement:
                PointF[] summaryPoints = new PointF[5];
                summaryPoints[0] = rect.Location;
                summaryPoints[1] = new PointF(rect.X, rect.Y + rect.Height / 4f);
                summaryPoints[2] = new PointF(rect.Right - 3, rect.Y + rect.Height / 4f);
                summaryPoints[3] = new PointF(rect.Right, rect.Y + rect.Height / 2f);
                summaryPoints[4] = new PointF(rect.Right, rect.Y);
                
                return summaryPoints;
            case GanttViewPrintElementContext.MilestoneElement:
                PointF[] milestonePoints = new PointF[4];
                milestonePoints[0] = new PointF(rect.X, rect.Y);
                milestonePoints[1] = new PointF(rect.X + rect.Height / 2f, rect.Y + rect.Height / 2f);
                milestonePoints[2] = new PointF(rect.X, rect.Y + rect.Height);
                milestonePoints[3] = new PointF(rect.X - rect.Height / 2f, rect.Y + rect.Height / 2f);

                return milestonePoints;
            default:
                return null;
        }
    }

    private bool shouldPaintStartCap;
    protected override RectangleF GetPrintRectangle(GanttViewDataItem item, int index)
    {
        if (index < 0)
        {
            return RectangleF.Empty;
        }
        
        float x = (float)((item.Start - this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineStart).TotalSeconds / this.GanttViewElement.GraphicalViewElement.OnePixelTime.TotalSeconds);
        this.shouldPaintStartCap = x > 0 ? true : false;
        x = Math.Max(x, 0);

        float y = index * (this.GanttViewElement.ItemHeight + this.GanttViewElement.ItemSpacing) + this.GanttViewElement.HeaderHeight;
        float width = (float)((item.End - item.Start).TotalSeconds / (float)this.GanttViewElement.GraphicalViewElement.OnePixelTime.TotalSeconds);

        return new RectangleF(x, y, width, (this.GanttViewElement.ItemHeight + this.GanttViewElement.ItemSpacing));
    }
}

0 comments