Completed
Last Updated: 15 Mar 2018 12:26 by Dimitar
ADMIN
Hristo
Created on: 08 Mar 2018 11:51
Category: GanttView
Type: Bug Report
0
FIX. RadGanttView - incorrect representation of the YearHalves range for leap years if the TimelineStart is set in the second half of the leap year
How to reproduce:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        new RadControlSpyForm().Show();

        this.radGanttView.GanttViewElement.GraphicalViewElement.OnePixelTime = new TimeSpan(6, 0, 0);

        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.YearHalves;

        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2016, 12, 25);
        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineEnd = new DateTime(2017, 1, 27);


        this.AddTasks();
    }

    private void AddTasks()
    {
        //Setup data items
        GanttViewDataItem item1 = new GanttViewDataItem();
        item1.Start = new DateTime(2017, 1, 1);
        item1.End = new DateTime(2017, 1, 20);
        item1.Progress = 30m;
        item1.Title = "Summary task.1. title";

        GanttViewDataItem subItem11 = new GanttViewDataItem();
        subItem11.Start = new DateTime(2017, 1, 1);
        subItem11.End = new DateTime(2017, 1, 20);
        subItem11.Progress = 10m;
        subItem11.Title = "Sub-task.1.1 title";

        GanttViewDataItem subItem12 = new GanttViewDataItem();
        subItem12.Start = new DateTime(2017, 1, 1);
        subItem12.End = new DateTime(2017, 1, 20);
        subItem12.Progress = 20m;
        subItem12.Title = "Sub-task.1.2 title";

        GanttViewDataItem subItem13 = new GanttViewDataItem();
        subItem13.Start = new DateTime(2017, 1, 5);
        subItem13.End = new DateTime(2017, 1, 20);
        subItem13.Progress = 20m;
        subItem13.Title = "Sub-task.1.3 title";

        //Add subitems
        item1.Items.Add(subItem11);
        item1.Items.Add(subItem12);
        item1.Items.Add(subItem13);

        this.radGanttView.Items.Add(item1);

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

        this.radGanttView.GanttViewElement.Columns.Add(titleColumn);
        this.radGanttView.GanttViewElement.Columns.Add(startColumn);
        this.radGanttView.GanttViewElement.Columns.Add(endColumn);
    }
}

Workaround: 

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        new RadControlSpyForm().Show();

        this.radGanttView.GanttViewElement.GraphicalViewElement.OnePixelTime = new TimeSpan(6, 0, 0);

        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.YearHalves;
        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineBehavior = new CustomTimelineBehavior();

        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2016, 12, 25);
        this.radGanttView.GanttViewElement.GraphicalViewElement.TimelineEnd = new DateTime(2017, 1, 27);


        this.AddTasks();
    }

    private void AddTasks()
    {
        //Setup data items
        GanttViewDataItem item1 = new GanttViewDataItem();
        item1.Start = new DateTime(2017, 1, 1);
        item1.End = new DateTime(2017, 1, 20);
        item1.Progress = 30m;
        item1.Title = "Summary task.1. title";

        GanttViewDataItem subItem11 = new GanttViewDataItem();
        subItem11.Start = new DateTime(2017, 1, 1);
        subItem11.End = new DateTime(2017, 1, 20);
        subItem11.Progress = 10m;
        subItem11.Title = "Sub-task.1.1 title";

        GanttViewDataItem subItem12 = new GanttViewDataItem();
        subItem12.Start = new DateTime(2017, 1, 1);
        subItem12.End = new DateTime(2017, 1, 20);
        subItem12.Progress = 20m;
        subItem12.Title = "Sub-task.1.2 title";

        GanttViewDataItem subItem13 = new GanttViewDataItem();
        subItem13.Start = new DateTime(2017, 1, 5);
        subItem13.End = new DateTime(2017, 1, 20);
        subItem13.Progress = 20m;
        subItem13.Title = "Sub-task.1.3 title";

        //Add subitems
        item1.Items.Add(subItem11);
        item1.Items.Add(subItem12);
        item1.Items.Add(subItem13);

        this.radGanttView.Items.Add(item1);

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

        this.radGanttView.GanttViewElement.Columns.Add(titleColumn);
        this.radGanttView.GanttViewElement.Columns.Add(startColumn);
        this.radGanttView.GanttViewElement.Columns.Add(endColumn);
    }
}

public class CustomTimelineBehavior : BaseGanttViewTimelineBehavior
{
    public override DateTime AdjustedTimelineStart
    {
        get
        {
            if (this.GraphicalViewElement.TimelineRange == TimeRange.YearHalves)
            {
                DateTime result = this.GraphicalViewElement.TimelineStart;
                int halfYearDay = DateTime.IsLeapYear(result.Year) ? 366 / 2 : 365 / 2;
                if (result.DayOfYear < halfYearDay)
                {
                    return new DateTime(result.Year, 1, 1);
                }
                else
                {
                    return new DateTime(result.Year, 1, 1).AddDays(halfYearDay);
                }
            }

            return base.AdjustedTimelineStart;
        }
    }

    public override DateTime AdjustedTimelineEnd
    {
        get
        {
            if (this.GraphicalViewElement.TimelineRange == TimeRange.YearHalves)
            {
                DateTime result = this.GraphicalViewElement.TimelineEnd;
                int halfYearDay = DateTime.IsLeapYear(result.Year) ? 366 / 2 : 365 / 2;
                if (result.DayOfYear < halfYearDay)
                {
                    return new DateTime(result.Year, 1, 1).AddDays(halfYearDay + 1);
                }
                else
                {
                    return new DateTime(result.Year, 1, 1).AddYears(1);
                }
            }

            return base.AdjustedTimelineEnd;
        }
    }
}
0 comments