private void SmoothScroll(DataValue newValue) { if (this.series == null) { this.series = new DataSeries() { Name = "", Values = new List<DataValue>() }; } // we do not use the data value x coordinates right now because they are timestamp values // and they bunch up and are not smooth...due to random network noise, so until we figure // out something better the graph is smoothing out the x values. double x = 0; if (this.series.Values.Count > 0) { x = this.series.Values[this.series.Values.Count - 1].X + 1; } DataValue copy = new Model.DataValue() { X = x, Y = newValue.Y }; this.series.Values.Add(copy); PathGeometry g = Graph.Data as PathGeometry; if (g == null) { UpdateChart(); return; } PathFigure f = g.Figures[0]; if (ComputeScale() || g.Bounds.Width > 2 * this.ActualWidth) { // can't do incremental, have to reset scaled values. if (this.series != null && this.series.Values.Count > 2 * this.ActualWidth) { // purge history since this is an infinite scrolling stream... this.series.Values.RemoveRange(0, this.series.Values.Count - (int)this.ActualWidth); System.Diagnostics.Debug.WriteLine("Trimming data series {0} back to {1} values", this.series.Name, this.series.Values.Count); } UpdateChart(); } else { AddScaledValues(f, updateIndex, series.Values.Count); Graph.UpdateLayout(); if (g.Bounds.Width >= this.ActualWidth) { Canvas.SetLeft(Graph, Canvas.GetLeft(Graph) - 1); } updateIndex = series.Values.Count; } }
public void SetData(DataSeries series) { this.dirty = true; this.series = series; this.UpdateLayout(); if (this.ActualWidth != 0) { UpdateChart(); } }