This is a migrated thread and some comments may be shown as answers.

Header of graphical view in 5 minute increments

3 Answers 25 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Veteran
Jason asked on 17 Sep 2018, 04:17 AM

Hello, I have tried modifying https://docs.telerik.com/devtools/winforms/ganttview/timeline/custom-timeline to have it do custom ranges, however when I run my copy I get a fully blank header. See attached for images.

My setting the custom behavior:

radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = start; // Start is a DateTime
radGanttView1.GanttViewElement.GraphicalViewElement.TimelineEnd = end; // End is a DateTime
radGanttView1.GanttViewElement.GraphicalViewElement.OnePixelTime = TimeSpan.FromMinutes(0.0025);
radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Custom;
var behavior = new WarehouseTimelineBehavior { Start = start, End = end };
radGanttView1.GanttViewElement.GraphicalViewElement.TimelineBehavior = behavior;

And my Behavior class:

001.using System;
002.using System.Collections.Generic;
003.using Telerik.WinControls.UI;
004. 
005.namespace WarehouseBuilder.LogViewer
006.{
007.    public class WarehouseTimelineBehavior : BaseGanttViewTimelineBehavior
008.    {
009.        public DateTime Start = DateTime.MinValue;
010.        public DateTime End = DateTime.MaxValue;
011. 
012.        public override DateTime AdjustedTimelineStart
013.        {
014.            get
015.            {
016.                if (GraphicalViewElement.TimelineRange != TimeRange.Custom || Start == DateTime.MinValue)
017.                {
018.                    return base.AdjustedTimelineStart;
019.                }
020.                return Start;
021.            }
022.        }
023. 
024.        public override DateTime AdjustedTimelineEnd
025.        {
026.            get
027.            {
028.                if (GraphicalViewElement.TimelineRange != TimeRange.Custom || End == DateTime.MaxValue)
029.                {
030.                    return base.AdjustedTimelineEnd;
031.                }
032.                return End;
033.            }
034.        }
035. 
036.        public override IList<GanttViewTimelineDataItem> BuildTimelineDataItems(TimeRange range)
037.        {
038.            if (range != TimeRange.Custom)
039.            {
040.                return base.BuildTimelineDataItems(range);
041.            }
042.            return this.BuildTimelineDataItemsForDecadesRange();
043.        }
044. 
045.        public IList<GanttViewTimelineDataItem> BuildTimelineDataItemsForDecadesRange()
046.        {
047.            List<GanttViewTimelineDataItem> result = new List<GanttViewTimelineDataItem>();
048.            DateTime currentDate = AdjustedTimelineStart;
049.            int currentMinuteNumber = currentDate.Minute;
050.            int newMinuteNumber = currentMinuteNumber;
051. 
052.            GanttViewTimelineDataItem item = new GanttViewTimelineDataItem(currentDate, currentDate.AddMinutes(5), GraphicalViewElement.TimelineRange, GraphicalViewElement.OnePixelTime);
053. 
054.            result.Add(item);
055. 
056.            while (currentDate < AdjustedTimelineEnd)
057.            {
058.                item.End = currentDate.AddMinutes(5);
059.                currentDate = currentDate.AddMinutes(5);
060.                newMinuteNumber = currentDate.Minute;
061. 
062.                if (newMinuteNumber != currentMinuteNumber && currentDate <= AdjustedTimelineEnd)
063.                {
064.                    currentMinuteNumber = newMinuteNumber;
065.                    item = new GanttViewTimelineDataItem(currentDate, currentDate, GraphicalViewElement.TimelineRange, GraphicalViewElement.OnePixelTime);
066.                    result.Add(item);
067.                }
068.            }
069. 
070.            return result;
071.        }
072. 
073.        public override GanttTimelineCellsInfo GetTimelineCellInfoForItem(GanttViewTimelineDataItem item, TimeRange timeRange)
074.        {
075.            if (timeRange != TimeRange.Custom)
076.            {
077.                return base.GetTimelineCellInfoForItem(item, timeRange);
078.            }
079. 
080.            return GetTimelineCellInfoForDecadeRange(item);
081.        }
082. 
083.        public GanttTimelineCellsInfo GetTimelineCellInfoForDecadeRange(GanttViewTimelineDataItem item)
084.        {
085.            int minutes = 5;
086. 
087.            if (item.Start == AdjustedTimelineStart)
088.            {
089.                if (item.Start.Minute % 5 > 0)
090.                {
091.                    minutes = 10 - (item.Start.Minute % 5);
092.                }
093.            }
094. 
095.            if (item.End == AdjustedTimelineEnd)
096.            {
097.                if (item.End.Minute % 5 > 0)
098.                {
099.                    minutes = item.End.Minute % 5;
100.                }
101.            }
102. 
103.            return new GanttTimelineCellsInfo(minutes);
104.        }
105. 
106.        public override string GetTimelineTopElementText(GanttViewTimelineDataItem item)
107.        {
108.            if (item.Range != TimeRange.Custom)
109.            {
110.                return base.GetTimelineTopElementText(item);
111.            }
112. 
113.            string format = "{0} - {1}";
114. 
115.            return string.Format(System.Threading.Thread.CurrentThread.CurrentUICulture, format, item.Start, item.End);
116.        }
117. 
118.        public override string GetTimelineBottomElementText(GanttViewTimelineDataItem item, int index)
119.        {
120.            if (item.Range != TimeRange.Custom)
121.            {
122.                return base.GetTimelineBottomElementText(item, index);
123.            }
124. 
125.            string format = "{0:hh:mm}";
126. 
127.            return string.Format(System.Threading.Thread.CurrentThread.CurrentCulture, format, new DateTime(item.Start.Minute + index, 1, 1));
128.        }
129.    }
130.}

 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 18 Sep 2018, 08:11 AM
Hi Jason,

Thank you for writing.

It will be necessary to apply the custom timeline behavior to the Gantt View before setting the TimelineStart and TimelineEnd properties. I also noticed that you might also create an invalid DateTime object in the GetTimelineBottomElementText method in the custom class, you can consider changing the format. To test this I have also increased the OnePixelTime property: 
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
 
        this.radGanttView1.Ratio = 0.35f;
 
        DateTime start = new DateTime(2010, 10, 10, 10, 0, 0);
        DateTime end = start.AddSeconds(100);
 
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Custom;
        var behavior = new WarehouseTimelineBehavior { Start = start, End = end };
        radGanttView1.GanttViewElement.GraphicalViewElement.TimelineBehavior = behavior;
         
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = start; // Start is a DateTime
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineEnd = end; // End is a DateTime
        this.radGanttView1.GanttViewElement.GraphicalViewElement.OnePixelTime = TimeSpan.FromMinutes(0.025);
 
        //setup data items
        GanttViewDataItem item1 = new GanttViewDataItem();
        item1.Start = start.AddMinutes(2);
        item1.End = start.AddMinutes(6);
        item1.Progress = 30m;
        item1.Title = "Summary task.1. title";
 
        GanttViewDataItem subitem11 = new GanttViewDataItem();
        subitem11.Start = start.AddMinutes(3);
        subitem11.End = start.AddMinutes(5);
        subitem11.Progress = 10m;
        subitem11.Title = "Sub-task.1.1 title";
 
        GanttViewDataItem subitem12 = new GanttViewDataItem();
        subitem12.Start = start.AddMinutes(4);
        subitem12.End = start.AddMinutes(01);
        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);
 
        GanttViewTextViewColumn titleColumn = new GanttViewTextViewColumn("Title");
        GanttViewTextViewColumn startColumn = new GanttViewTextViewColumn("Start");
        startColumn.FormatString = "{0:MM/dd/yyy HH:mm:ss.fff}";
        GanttViewTextViewColumn endColumn = new GanttViewTextViewColumn("End");
        endColumn.FormatString = "{0:MM/dd/yyy HH:mm:ss.fff}";
 
        this.radGanttView1.GanttViewElement.Columns.Add(titleColumn);
        this.radGanttView1.GanttViewElement.Columns.Add(startColumn);
        this.radGanttView1.GanttViewElement.Columns.Add(endColumn);
    }
}
 
public class WarehouseTimelineBehavior : BaseGanttViewTimelineBehavior
{
    public DateTime Start = DateTime.MinValue;
    public DateTime End = DateTime.MaxValue;
 
    public override DateTime AdjustedTimelineStart
    {
        get
        {
            if (GraphicalViewElement.TimelineRange != TimeRange.Custom || Start == DateTime.MinValue)
            {
                return base.AdjustedTimelineStart;
            }
            return Start;
        }
    }
 
    public override DateTime AdjustedTimelineEnd
    {
        get
        {
            if (GraphicalViewElement.TimelineRange != TimeRange.Custom || End == DateTime.MaxValue)
            {
                return base.AdjustedTimelineEnd;
            }
            return End;
        }
    }
 
    public override IList<GanttViewTimelineDataItem> BuildTimelineDataItems(TimeRange range)
    {
        if (range != TimeRange.Custom)
        {
            return base.BuildTimelineDataItems(range);
        }
        return this.BuildTimelineDataItemsForDecadesRange();
    }
 
    public IList<GanttViewTimelineDataItem> BuildTimelineDataItemsForDecadesRange()
    {
        List<GanttViewTimelineDataItem> result = new List<GanttViewTimelineDataItem>();
        DateTime currentDate = AdjustedTimelineStart;
        int currentMinuteNumber = currentDate.Minute;
        int newMinuteNumber = currentMinuteNumber;
 
        GanttViewTimelineDataItem item = new GanttViewTimelineDataItem(currentDate, currentDate.AddMinutes(5), GraphicalViewElement.TimelineRange, GraphicalViewElement.OnePixelTime);
 
        result.Add(item);
 
        while (currentDate < AdjustedTimelineEnd)
        {
            item.End = currentDate.AddMinutes(5);
            currentDate = currentDate.AddMinutes(5);
            newMinuteNumber = currentDate.Minute;
 
            if (newMinuteNumber != currentMinuteNumber && currentDate <= AdjustedTimelineEnd)
            {
                currentMinuteNumber = newMinuteNumber;
                item = new GanttViewTimelineDataItem(currentDate, currentDate, GraphicalViewElement.TimelineRange, GraphicalViewElement.OnePixelTime);
                result.Add(item);
            }
        }
 
        return result;
    }
 
    public override GanttTimelineCellsInfo GetTimelineCellInfoForItem(GanttViewTimelineDataItem item, TimeRange timeRange)
    {
        if (timeRange != TimeRange.Custom)
        {
            return base.GetTimelineCellInfoForItem(item, timeRange);
        }
 
        return GetTimelineCellInfoForDecadeRange(item);
    }
 
    public GanttTimelineCellsInfo GetTimelineCellInfoForDecadeRange(GanttViewTimelineDataItem item)
    {
        int minutes = 5;
 
        if (item.Start == AdjustedTimelineStart)
        {
            if (item.Start.Minute % 5 > 0)
            {
                minutes = 10 - (item.Start.Minute % 5);
            }
        }
 
        if (item.End == AdjustedTimelineEnd)
        {
            if (item.End.Minute % 5 > 0)
            {
                minutes = item.End.Minute % 5;
            }
        }
 
        return new GanttTimelineCellsInfo(minutes);
    }
 
    public override string GetTimelineTopElementText(GanttViewTimelineDataItem item)
    {
        if (item.Range != TimeRange.Custom)
        {
            return base.GetTimelineTopElementText(item);
        }
 
        string format = "{0} - {1}";
 
        return string.Format(System.Threading.Thread.CurrentThread.CurrentUICulture, format, item.Start, item.End);
    }
 
    public override string GetTimelineBottomElementText(GanttViewTimelineDataItem item, int index)
    {
        if (item.Range != TimeRange.Custom)
        {
            return base.GetTimelineBottomElementText(item, index);
        }
 
        string format = "{0} m";
 
        //return string.Format(System.Threading.Thread.CurrentThread.CurrentCulture, format, new DateTime(item.Start.Minute + index, 1, 1));
 
        return string.Format(System.Threading.Thread.CurrentThread.CurrentCulture, format, item.Start.Minute + index);
    }
}

I hope this will help. Lert me know if you needf ruther assistance.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jason
Top achievements
Rank 1
Veteran
answered on 18 Sep 2018, 03:18 PM
Thanks, I will be giving that a try this week. Also, is it possible to change behaviors on the fly? Ie if I had a trackbar for zooming, start limiting how many items are shown in the time line as you zoom out? 
0
Hristo
Telerik team
answered on 19 Sep 2018, 06:19 AM
Hello Jason,

Yes, that would be possible, however, it should be handled manually. Once you change the zoom level in the control and depending on your actual scenario and data you may want to assign a different timeline behavior class. In order to have the new timeline applied at run-time, it will be necessary to update the layout and recreate the task and the links. This can be achieved by changing the TimelineRange to any of the default ranges, e.g. like this: 
private void ChangeTimelineBehavior()
{
    this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Day;
    this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Custom;
    var behavior = new SecondsGanttViewTimelineBehavior();
    radGanttView1.GanttViewElement.GraphicalViewElement.TimelineBehavior = behavior;
    this.radGanttView1.GanttViewElement.GraphicalViewElement.UpdateTimelineZoom();
    this.radGanttView1.GanttViewElement.GraphicalViewElement.OnePixelTime = TimeSpan.FromSeconds(.5);
}

I hope this helps. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GanttView
Asked by
Jason
Top achievements
Rank 1
Veteran
Answers by
Hristo
Telerik team
Jason
Top achievements
Rank 1
Veteran
Share this question
or