private void ResetGraphics() { graphics.Clear(BackgroundColor); graphics.TranslateTransform(this.autoScrollPosition.X, this.autoScrollPosition.Y); DayXLocations.Clear(); TimeXLocations.Clear(); }
private void PopulateDateTimeXLocs(int startX, int endX) { int dayDivision = (int)Math.Round((double)(endX - startX) / (EndDate - StartDate).Days); int dayXLoc = startX; DateTime curDay = StartDate; while (curDay < EndDate) { int dayStart = dayXLoc; int dayEnd = dayXLoc + dayDivision; int timeDivision = (int)Math.Round((double)(dayEnd - dayStart) / (EndHourInDay - StartHourInDay)); int xLoc = dayStart; int curHour = StartHourInDay; while (curHour <= EndHourInDay) { DateTime dateWithHour = curDay.AddHours(curHour); if (curHour == StartHourInDay) { StringFormat startFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far }; TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, dayStart, startFormat)); } else if (curHour == EndHourInDay) { StringFormat endFormat = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far }; TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, dayEnd, endFormat)); } else { xLoc += timeDivision; StringFormat otherFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }; TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, xLoc, otherFormat)); } curHour++; } DayXLocations.Add(new Tuple <DateTime, int, int>(curDay, dayStart, dayEnd)); dayXLoc = dayEnd; curDay = curDay.AddDays(1); } }
private int GetXLocationForTime(DateTime dateAndTime) { Tuple <DateTime, int, StringFormat> foundGroup = TimeXLocations.Find(p => p.Item1 == dateAndTime); if (foundGroup != null) { return(foundGroup.Item2); } else { return(-1); } }
private void DrawNowIndicator(int startY, int endY) { if (!ShowNowIndicator || Rows.Count == 0 || //No rows !Rows.Any(p => p.TimeBlocks.Count > 0 && p.IsVisible)) //No timeblocks (and isn't invisible) { return; } DateTime now = DateTime.Now; now = now.AddHours(NowIndicatorHourOffset); //Ensure that "now" should be visible on chart if (now.Hour < StartHourInDay || now.Hour > EndHourInDay || now < StartDate || now > EndDate) { return; } Tuple <DateTime, int, StringFormat> timeBehind = TimeXLocations.LastOrDefault(p => p.Item1 <= now); Tuple <DateTime, int, StringFormat> timeAhead = TimeXLocations.FirstOrDefault(p => p.Item1 >= now); double percentageOfTimeBlock = (double)(now.Ticks - timeBehind.Item1.Ticks) / (timeAhead.Item1.Ticks - timeBehind.Item1.Ticks); int nowXLoc = (int)Math.Round(percentageOfTimeBlock * (timeAhead.Item2 - timeBehind.Item2) + timeBehind.Item2); //Draw line Point topPoint = new Point(nowXLoc, startY); Point bottomPoint = new Point(nowXLoc, endY); graphics.DrawLine(new Pen(Color.Red), topPoint, bottomPoint); //Draw top triangle Point t1 = new Point(topPoint.X - 5, topPoint.Y); Point t2 = new Point(topPoint.X + 5, topPoint.Y); Point t3 = new Point(topPoint.X, topPoint.Y + 10); graphics.FillPolygon(new SolidBrush(Color.Red), new[] { t1, t2, t3 }); //Draw bottom triangle Point b1 = new Point(bottomPoint.X - 5, bottomPoint.Y); Point b2 = new Point(bottomPoint.X + 5, bottomPoint.Y); Point b3 = new Point(bottomPoint.X, bottomPoint.Y - 10); graphics.FillPolygon(new SolidBrush(Color.Red), new[] { b1, b2, b3 }); }