private List <Header> GetFullHeaderList() { List <Header> result = new List <Header>(); DateTime newFromTime = new DateTime(FromDate.Year, FromDate.Month, FromDate.Day); string item = null; TimeSpan interval = ToDate - FromDate; if (interval.TotalDays < 1) { DateTime tmpTime = newFromTime; newFromTime = tmpTime.AddHours(FromDate.Hour); if (headerFromDate.Minute < 59 & headerFromDate.Minute > 29) { tmpTime = newFromTime; newFromTime = tmpTime.AddMinutes(30); } else { tmpTime = newFromTime; newFromTime = tmpTime.AddMinutes(0); } while (newFromTime <= ToDate) { item = newFromTime.Hour + ":"; if (newFromTime.Minute < 10) { item += "0" + newFromTime.Minute; } else { item += "" + newFromTime.Minute; } Header header = new Header(); header.HeaderText = item; header.HeaderTextInsteadOfTime = ""; header.Time = new DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, newFromTime.Hour, newFromTime.Minute, 0); result.Add(header); newFromTime = newFromTime.AddMinutes(5); // The minimum interval of time between the headers } } else if (interval.TotalDays < 60) { while (newFromTime <= ToDate) { Header header = new Header(); header.HeaderText = ""; header.HeaderTextInsteadOfTime = ""; header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); result.Add(header); newFromTime = newFromTime.AddDays(1); // The minimum interval of time between the headers } } else { while (newFromTime <= ToDate) { Header header = new Header(); header.HeaderText = ""; header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); header.HeaderTextInsteadOfTime = newFromTime.ToString("MMM"); result.Add(header); newFromTime = newFromTime.AddMonths(1); // The minimum interval of time between the headers } } return(result); }
private void DrawHeader(Graphics gfx, List <Header> headerList) { if (headerList == null) { headerList = GetFullHeaderList(); } if (headerList.Count == 0) { return; } dynamic availableWidth = Width - 10 - barStartLeft - barStartRight; widthPerItem = availableWidth / headerList.Count; if (widthPerItem < 40) { List <Header> newHeaderList = new List <Header>(); bool showNext = true; // If there's not enough room for all headers remove 50% foreach (Header header in headerList) { if (showNext == true) { newHeaderList.Add(header); showNext = false; } else { showNext = true; } } DrawHeader(gfx, newHeaderList); return; } int index = 0; Header lastHeader = null; foreach (Header header in headerList) { int startPos = barStartLeft + (index * widthPerItem); bool showDateHeader = false; header.StartLocation = startPos; // Checks whether to show the date or not if (lastHeader == null) { showDateHeader = true; } else if (header.Time.Hour < lastHeader.Time.Hour) { showDateHeader = true; } else if (header.Time.Minute == lastHeader.Time.Minute) { showDateHeader = true; } // Show date if (showDateHeader == true) { string str = ""; if (header.HeaderTextInsteadOfTime.Length > 0) { str = header.HeaderTextInsteadOfTime; } else { str = header.Time.ToString("d-MMM"); } gfx.DrawString(str, dateTextFont, Brushes.Black, startPos, 0); } // Show time gfx.DrawString(header.HeaderText, timeTextFont, Brushes.Black, startPos, headerTimeStartTop); index += 1; lastHeader = header; } shownHeaderList = headerList; widthPerItem = (Width - 10 - barStartLeft - barStartRight) / shownHeaderList.Count; }