Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) ResourceView: Show calendar weeks in a timeline? (Read 9447 times)
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
ResourceView: Show calendar weeks in a timeline?
Oct 16th, 2012 at 10:42am
Print Post  
Hi there,

is there any way to show calendar weeks in the timeline? I thought there must be a way to achieve this because it is possible to set the Unit to "Week".

Or is there a way to display custom texts in the timeline e.g. using a callback method? This would be very helpful when using a UnitCount > 1 to indicate a range (e.g. "Jan - Mar" for Unit "Month" and UnitCount "4").

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #1 - Oct 16th, 2012 at 11:58am
Print Post  
The ResourceSchedule sample (the one I was referring to in this post) demonstrates exactly how to display week numbers in the timeline (in addition to demonstrating how to rotate texts). The sample relies on custom drawing in order to achieve this. Check the contents of the Calendar.Draw event handler, more specifically the CustomDrawElements.ResourceViewTimelineCell part.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #2 - Oct 17th, 2012 at 8:33am
Print Post  
Ahhh, thank you very much - I haven't seen the forest between the trees Smiley

Regards
Achim
  
Back to top
WWW  
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #3 - Oct 17th, 2012 at 8:46am
Print Post  
Hi again,

I have one thing left: as far as I can see it is only possible to draw the graphics in the calendar_Draw() handler. But it would be very easy and reliable (i.e. Theme-safe) to only change the Text based on the calendar week calculation.

Is there a possibility to only change the text based on a callback method?

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #4 - Oct 17th, 2012 at 10:16am
Print Post  
Hi,

Unfortunately the timeline texts are currently not customizable except by setting the Format property in the corresponding settings.

However, you can use custom drawing and still retain the theme context, by drawing only the cell text (and leave the background and border of the cell as it is). To do this, hide the default cell text by setting the Format property of the timeline to the following string: " ". (Note that the string contains two spaces - a single space appears to be an invalid format for the DateTime.ToString method.) Then, in the Calendar.Draw event handler check the Index property of the event argument to ensure that you are drawing the cells of the appropriate timeline. The possible values are 0, 1, and 2 indicating the top, middle, and bottom timelines respectively. Make sure that you are drawing the text with the HeaderTextColor of the Style provided in the event argument.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #5 - Oct 17th, 2012 at 1:21pm
Print Post  
Hi Meppy,

unfortunately this does not really help at all. I am trying to implement something like "Custom Format Strings" where I can use my own format definitions to inject Week Numbers or Quarter Numbers to show in the timeline header.

I'm using the following code to find out whether custom formats are being used and register the draw event handler:

Code (C++)
Select All
            //If any custom format definitions are found, enable the handling of them
            if (Regex.Match(tlBottom.Format + tlMiddle.Format + tlTop.Format, @"\[\w\w\]").Success)
            {
                // Add the ResourceViewTimelineCell flag
                calendarControl.CustomDraw |= CustomDrawElements.ResourceViewTimelineCell;
                calendarControl.Draw += delegate(object sender, DrawEventArgs e)
                                            {
                                                e.Graphics.DrawString("TXT", e.Style.HeaderFont,
                                                    new SolidBrush(e.Style.HeaderTextColor),
                                                    new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
                                            };
            }
 



To make this really easy usable and in fact make only a text replacement i have to copy all attributes for rendering the text. What I have at the moment are the Font information and the Color (i.e. Brush). But I don't know how to get the same position and text alignment as it would be without my custom drawing. Perhaps the attached screenshot make this more clear.

Thanks for any help
Achim
  

Bildschirmfoto_2012-10-17_um_15_20_25.png (Attachment deleted)
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #6 - Oct 17th, 2012 at 3:00pm
Print Post  
Hi,

In order to honor the alignment of the text, you need to set up a StringFormat object according to the value of the Style.HeaderTextAlignment and pass this StringFormat object to the DrawString method. The initialization of the StringFormat object should look like this:

Code
Select All
StringFormat ff = new StringFormat();
switch (e.Style.HeaderTextAlignment)
{
	case MindFusion.Drawing.TextAlignment.TopLeft:
		ff.Alignment = StringAlignment.Near;
		ff.LineAlignment = StringAlignment.Near;
		break;
	case MindFusion.Drawing.TextAlignment.TopCenter:
		ff.Alignment = StringAlignment.Center;
		ff.LineAlignment = StringAlignment.Near;
		break;
	case MindFusion.Drawing.TextAlignment.TopRight:
		ff.Alignment = StringAlignment.Far;
		ff.LineAlignment = StringAlignment.Near;
		break;
	// etc...
} 


You can also use hard-coded values if the text alignment does not change during the application execution to avoid having to handle all nine cases.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #7 - Oct 19th, 2012 at 7:15am
Print Post  
Hi Meppy,

thank you for this. The text alignment works fine now (see attached screenshot).

There's one problem left: how can I prevent the Calendar-Control from rendering the default text? I know a concept from other control libraries, to return a value from the Draw event handler that indicates "I have done the work for you", just like: e.Drawn = true; or something.

Is there a way in the Calendar-Control too?

Best regards
Achim
  

Bildschirmfoto_2012-10-19_um_09_12_41.png (Attachment deleted)
Back to top
WWW  
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #8 - Oct 19th, 2012 at 7:42am
Print Post  
For all here who may have a similar problem I want to share my implementation of the alignment mapping with you:

Code (C++)
Select All
// Define the alignment table
                var alTable = new Dictionary<TextAlignment, StringAlignment[]>
                                                             {
                                                                 {TextAlignment.TopLeft, new [] { StringAlignment.Near, StringAlignment.Near }},
                                                                 {TextAlignment.TopCenter, new [] { StringAlignment.Center, StringAlignment.Near }},
                                                                 {TextAlignment.TopRight, new [] { StringAlignment.Far, StringAlignment.Near }},
                                                                 {TextAlignment.MiddleLeft, new [] { StringAlignment.Near, StringAlignment.Center }},
                                                                 {TextAlignment.MiddleCenter, new [] { StringAlignment.Center, StringAlignment.Center }},
                                                                 {TextAlignment.MiddleRight, new [] { StringAlignment.Far, StringAlignment.Center }},
                                                                 {TextAlignment.BottomLeft, new [] { StringAlignment.Near, StringAlignment.Far }},
                                                                 {TextAlignment.BottomCenter, new [] { StringAlignment.Center, StringAlignment.Far }},
                                                                 {TextAlignment.BottomRight, new [] { StringAlignment.Far, StringAlignment.Far }}
                                                             };
                // Add the ResourceViewTimelineCell flag
                calendarControl.CustomDraw |= CustomDrawElements.ResourceViewTimelineCell;
                calendarControl.Draw += delegate(object sender, DrawEventArgs e)
                                            {
                                                var ff = new StringFormat
                                                             {
                                                                 Alignment = alTable[e.Style.HeaderTextAlignment][0],
                                                                 LineAlignment = alTable[e.Style.HeaderTextAlignment][1]
                                                             };

                                                e.Graphics.DrawString("TXT", e.Style.HeaderFont,
                                                    new SolidBrush(e.Style.HeaderTextColor),
                                                    new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), ff);
                                            };
 



Creating a Dictionary is much more efficient than mapping with a switch/case block.

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #9 - Oct 19th, 2012 at 9:01am
Print Post  
Hi,

Quote:
how can I prevent the Calendar-Control from rendering the default text?


One way to do this is by setting the TimelineSettings.Format property to a value that will produce an empty string, for example "  " (not the double space - a single space is not a valid formatting specifier for DateTime.ToString). Alternatively, you can set the Style.HeaderTextColor to Transparent. This way you have to use another color when performing the custom drawing or the custom drawn text will be transparent too.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #10 - Oct 19th, 2012 at 11:18am
Print Post  
Hi Meppy,

ok, setting the format string to "  " (double-space) has done the job for me. But I wanted to provide a way for the developer to provide a "custom format string". So I created some extension methods for the TimelineSettings to manage this. After all this is not a really elegant solution and I would appreciate it when the calendar control would support the cancellation of draw sequences in one of the future versions.

Best regards and thanks
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #11 - Oct 19th, 2012 at 3:05pm
Print Post  
Hi Achim,

Thank you for your suggestion. Unfortunately the custom drawing code is executed after the default drawing has taken place. Therefore canceling the default drawing from the Draw event handler will not be possible. However, we will add a technique (probably a new event), which will enable timeline texts customization. I hope this will help.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #12 - Oct 22nd, 2012 at 8:16am
Print Post  
Hi Meppy,

yes, I think this would be great. Thanks again for the great support!

Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Show calendar weeks in a timeline?
Reply #13 - Oct 24th, 2012 at 8:20am
Print Post  
Hi,

Check out the new version of the control form the following link:

https://mindfusion.eu/_temp/MindFusion.Scheduling.5.4.2.trial.zip

The new Calendar.CustomizeText event lets you customize any text throughout the control. The event provides information such as type and index that can help you identify the element being customized, as well as the related date, the original text value, and a list with the associated resources. For example, the following event handler can be used to customize the texts in the bottom timeline of a Resource view:

Code
Select All
if (e.Element == CalendarTextElements.ResourceViewTimeline && e.Index == 2)
{
	e.Text = "week " + calendar.DateTimeFormat.Calendar.GetWeekOfYear(e.Date,
		System.Globalization.CalendarWeekRule.FirstDay,
		calendar.DateTimeFormat.FirstDayOfWeek).ToString();
} 



Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Show calendar weeks in a timeline?
Reply #14 - Oct 26th, 2012 at 8:00am
Print Post  
Hi Meppy,

thank you very much for this! I'll have a try on it next week.

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint