Skip to content

Commit

Permalink
Merge pull request #404 from hol353/regression
Browse files Browse the repository at this point in the history
Fix to avoid null pointer error from regression
  • Loading branch information
hol353 committed Oct 2, 2015
2 parents c271c22 + 1e1304c commit 58bff4f
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions Models/Graph/Regression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Models.Graph
/// <summary>
/// A regression model.
/// </summary>
[Serializable]
[ViewName("UserInterface.Views.GridView")]
[PresenterName("UserInterface.Presenters.PropertyPresenter")]
[ValidParent(typeof(Series))]
Expand Down Expand Up @@ -87,26 +88,29 @@ private void PutRegressionLineOnGraph(List<SeriesDefinition> definitions, IEnume
Color colour, string title)
{
MathUtilities.RegrStats stat = MathUtilities.CalcRegressionStats(x, y);
stats.Add(stat);
double minimumX = MathUtilities.Min(x);
double maximumX = MathUtilities.Max(x);
double minimumY = MathUtilities.Min(y);
double maximumY = MathUtilities.Max(y);
double lowestAxisScale = Math.Min(minimumX, minimumY);
double largestAxisScale = Math.Max(maximumX, maximumY);
if (stat != null)
{
stats.Add(stat);
double minimumX = MathUtilities.Min(x);
double maximumX = MathUtilities.Max(x);
double minimumY = MathUtilities.Min(y);
double maximumY = MathUtilities.Max(y);
double lowestAxisScale = Math.Min(minimumX, minimumY);
double largestAxisScale = Math.Max(maximumX, maximumY);

SeriesDefinition regressionDefinition = new SeriesDefinition();
regressionDefinition.title = title;
regressionDefinition.colour = colour;
regressionDefinition.line = LineType.Solid;
regressionDefinition.marker = MarkerType.None;
regressionDefinition.showInLegend = true;
regressionDefinition.type = SeriesType.Scatter;
regressionDefinition.xAxis = Axis.AxisType.Bottom;
regressionDefinition.yAxis = Axis.AxisType.Left;
regressionDefinition.x = new double[] { minimumX, maximumX };
regressionDefinition.y = new double[] { stat.m * minimumX + stat.c, stat.m * maximumX + stat.c };
definitions.Add(regressionDefinition);
SeriesDefinition regressionDefinition = new SeriesDefinition();
regressionDefinition.title = title;
regressionDefinition.colour = colour;
regressionDefinition.line = LineType.Solid;
regressionDefinition.marker = MarkerType.None;
regressionDefinition.showInLegend = true;
regressionDefinition.type = SeriesType.Scatter;
regressionDefinition.xAxis = Axis.AxisType.Bottom;
regressionDefinition.yAxis = Axis.AxisType.Left;
regressionDefinition.x = new double[] { minimumX, maximumX };
regressionDefinition.y = new double[] { stat.m * minimumX + stat.c, stat.m * maximumX + stat.c };
definitions.Add(regressionDefinition);
}
}

/// <summary>Puts the 1:1 line on graph.</summary>
Expand Down

0 comments on commit 58bff4f

Please sign in to comment.