Implementing a "weeks" TimelineCalendarType

Jan 4, 2013 at 9:36 AM

Am having fun with this excellent control, but have come up against a stumbling block.

I find that for my application I need an intermediate secondary timeline band type between "Months" and "Days" just to make the display a little less "noisy" for larger time-windows. So I thought "Weeks" would be the obvious choice  (effectively a days*7 like the Minutes*10 or decades etc).

I've added "weeks" to the enum type and appropriate switch cases in TimelineCalendar, TimelineBand and TimelineBuilder modules, added a special DateTimeConverter so that if it's a "weeks" band it shows the Month if the date is < 8, and everything displays correctly, I get the column spacing I was hoping for, but .... it doesn't scroll correctly. The column markers just "judder" a little in place and then the column date annotations change if I scroll a week further. So the static display is actually ok once the scrolling is over, but the scrolling itself is definitely disappointing.

Could someone give me a pointer as to what I've missed - or am I trying to go a step too far?

Thanks

Ade

 

Jan 4, 2013 at 10:21 AM

OK, apologies. Once again as soon as I posted this I found the problem! I wasn't calculating the first day of each week correctly - now that I am it all scrolls perfectly.

Posting problems in a discussion forum is absolutely the best way to fix them!

Ade

May 7, 2013 at 3:14 PM
Edited May 8, 2013 at 3:02 PM
Hi, i Need the same feature, can you provide your code ?

Edit: actually i ran into the same problem. The weeknumbers are shown perfectly, but the scrolling is wrong.
Here is what i've done:


In TimelineCalendar.cs

    public enum TimelineCalendarType
    {
        //...
        Weeks,
        //...
    }


        public long IndexOf(
            DateTime                                    value
            )
        {
            //..
            switch (m_type)
            {
           
                //...
                case TimelineCalendarType.Weeks:
                    ret = (long) (span.TotalDays / 7); 
                    break;
                 //...
             }
             //...
         }


        public DateTime this[
            long                                        index
        ]
        {
            get
            {

                switch (m_type)
            {
           
                //...
                case TimelineCalendarType.Weeks:
                    ret = (long) (span.TotalDays * 7); 
                    break;
                 //...
             }
             //...
         }
        }

        public bool IsValidIndex(long index)
        {
            get
            {

                switch (m_type)
            {
           
                //...
                case TimelineCalendarType.Weeks:
                    ret = (long) (span.TotalDays * 7); 
                    break;
                 //...
             }
             //...
         }
        }

 public static string ItemToString(
            TimelineCalendar                            src,
            DateTime                                    value
            )
        {

            //..
            switch (m_type)
            {
           
                //...

                case TimelineCalendarType.Weeks:
                    ret = DateUtils.weekNumber(d).ToString(); // a method to get the week number
                    break;
                 //...
             }
             //...
        }
I hope someone can help me to figure out my the problem... thanks
May 10, 2013 at 9:51 PM
(public DateTime this[int]) method looks a bit strange to me it suppose to return DateTime, while you have long.
May 10, 2013 at 10:13 PM
Also, I was not sure how to implement this correctly for different calendars.

But...

01/01/0001 is Suturday, according to http://www.timeanddate.com/calendar/monthly.html?year=1&month=1&country=1

So, for 01/01/0001 the index should be 0, for 01/02/0001 it should be 1 (as for 01/08/0001 it also should be 1). While, for instance, for Russia,
week starts on Monday, so it should be probably different.

Also text description of week returned from ItemToString kind of unclear. For a week 1/02/0001 through 01/08/0001 it should probably be:
1-8 Jan, 0001 (for first week of year or month)
1-8 Jan (for any other week)

(If you ever implement it please let me know, I would definitely include this feature in sources)
May 15, 2013 at 3:55 PM
Gentlemen,

Apologies - I have been away for a couple of weeks, and am now catching up with all the chaos.

I will post the relevant code, which seems to be working without any problems, when I've caught up - hopefully this weekend.

Ade