diff --git a/LogViewer/LogViewer/Controls/SimpleLineChart.xaml.cs b/LogViewer/LogViewer/Controls/SimpleLineChart.xaml.cs index 3d275ee37e..a57477e2cc 100644 --- a/LogViewer/LogViewer/Controls/SimpleLineChart.xaml.cs +++ b/LogViewer/LogViewer/Controls/SimpleLineChart.xaml.cs @@ -839,14 +839,31 @@ private void OnAddTrendLine(object sender, RoutedEventArgs e) { return; } - List points = new List(from d in this.series.Values select new Point(d.X, d.Y)); + // only do the visible points we have zoomed into. + List points = new List(); + + DataValue first = null; + DataValue last = null; + + foreach (DataValue d in this.series.Values) + { + Point point = scaleTransform.Transform(new Point(d.X, d.Y)); + point = zoomTransform.Transform(point); + if (point.X >= 0 && point.X <= this.ActualWidth) + { + // then it is a visible point. + if (first == null) first = d; + last = d; + points.Add(new Point(d.X, d.Y)); + } + } + if (first == null) + { + return; + } double a, b; // y = a + b.x MathHelpers.LinearRegression(points, out a, out b); - DataValue first = this.series.Values.First(); - DataValue last = this.series.Values.Last(); - - // now scale this line to fit the scaled graph Point start = new Point(first.X, a + (b * first.X)); Point end = new Point(last.X, a + (b * last.X)); @@ -972,12 +989,30 @@ private void OnAddMeanLine(object sender, RoutedEventArgs e) { return; } - List points = new List(from d in this.series.Values select d.Y); - double mean = MathHelpers.Mean(points); + // only do the visible points we have zoomed into. + List points = new List(); - DataValue first = this.series.Values.First(); - DataValue last = this.series.Values.Last(); + DataValue first = null; + DataValue last = null; + foreach (DataValue d in this.series.Values) + { + Point point = scaleTransform.Transform(new Point(d.X, d.Y)); + point = zoomTransform.Transform(point); + if (point.X >= 0 && point.X <= this.ActualWidth) + { + // then it is a visible point. + if (first == null) first = d; + last = d; + points.Add(d.Y); + } + } + if (first == null) + { + return; + } + double mean = MathHelpers.Mean(points); + // now scale this line to fit the scaled graph Point start = new Point(first.X, mean); Point end = new Point(last.X, mean);