Skip to content

Commit

Permalink
zoom the trend and mean lines to just the values that are visible.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Mar 28, 2017
1 parent 87558c5 commit bcb2f46
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions LogViewer/LogViewer/Controls/SimpleLineChart.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,14 +839,31 @@ private void OnAddTrendLine(object sender, RoutedEventArgs e)
{
return;
}
List<Point> points = new List<Point>(from d in this.series.Values select new Point(d.X, d.Y));
// only do the visible points we have zoomed into.
List<Point> points = new List<Point>();

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));

Expand Down Expand Up @@ -972,12 +989,30 @@ private void OnAddMeanLine(object sender, RoutedEventArgs e)
{
return;
}
List<double> points = new List<double>(from d in this.series.Values select d.Y);
double mean = MathHelpers.Mean(points);
// only do the visible points we have zoomed into.
List<double> points = new List<double>();

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);
Expand Down

0 comments on commit bcb2f46

Please sign in to comment.