private string GetTimeString(TimelineResolution resolution, double time) { switch (resolution) { case TimelineResolution.Hours: return(TimeSpan.FromTicks((long)time).TotalHours.ToString() + "hrs"); case TimelineResolution.Minutes: return(TimeSpan.FromTicks((long)time).TotalMinutes.ToString() + "m"); case TimelineResolution.Seconds: return(Math.Round(TimeSpan.FromTicks((long)time).TotalSeconds, 3).ToString() + "s"); case TimelineResolution.Milliseconds: return(Math.Round(TimeSpan.FromTicks((long)time).TotalMilliseconds, 3).ToString() + "ms"); } throw new InvalidOperationException(); }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { if (this.TickFrequency <= 1) { return; } dc.DrawLine(Timelineborder, new Point(0, 0), new Point(this.ActualWidth, 0)); double totalCount = this.Maximum - this.Minimum; double y = this.ReservedSpace * 0.5; FormattedText formattedText = null; double x = 0; double pixelDelta = this.ActualWidth / (totalCount / this.TickFrequency); double innerDelta = pixelDelta / 10; TimelineResolution resolution = this.GetMinResolution(totalCount); for (double i = 0; i <= totalCount; i += this.TickFrequency, x += pixelDelta) { string time = i == 0 ? this.GetDateTimeString(this.Minimum) : "+" + this.GetTimeString(resolution, i); formattedText = new FormattedText(time, CultureInfo.CurrentUICulture, System.Windows.FlowDirection.LeftToRight, Verdana, 8, Brushes.Black); dc.DrawText(formattedText, new Point(x, 10)); //base.OnRender(dc); dc.DrawLine(Timelineborder, new Point(x, 0), new Point(x, 10)); //Draw innter intervals; if (i < this.Maximum) { for (double k = innerDelta; k < pixelDelta; k += innerDelta) { dc.DrawLine(Timelineborder, new Point(x + k, 0), new Point(x + k, 5)); } } } }
private string GetTimeString(TimelineResolution resolution, double time) { switch (resolution) { case TimelineResolution.Hours: return TimeSpan.FromTicks((long)time).TotalHours.ToString() + "hrs"; case TimelineResolution.Minutes: return TimeSpan.FromTicks((long)time).TotalMinutes.ToString() + "m"; case TimelineResolution.Seconds: return Math.Round(TimeSpan.FromTicks((long)time).TotalSeconds, 3).ToString() +"s"; case TimelineResolution.Milliseconds: return Math.Round(TimeSpan.FromTicks((long)time).TotalMilliseconds, 3).ToString() + "ms"; } throw new InvalidOperationException(); }