Recent

Author Topic: TFitSeries issues with TUserDefinedChartSource  (Read 3109 times)

wp

  • Hero Member
  • *****
  • Posts: 11922
TFitSeries issues with TUserDefinedChartSource
« on: August 05, 2012, 11:49:21 pm »
While preparing a new tutorial I came across a situation that a TFitSeries getting its data from a UserDefinedChartSource tries to redraw before the fit is performed. As a consequence, the DrawFuncHelper crashes becauses of the NaNs produced along the way.

A workaround would be to exit the Draw method if the fit had not yet beein performed or was not successful.

The new TFitSeries.Draw method, therefore, should be like this:
Code: [Select]
procedure TFitSeries.Draw(ADrawer: IChartDrawer);
var
  de : TIntervalList;
begin
  if IsEmpty or (not FValidFitParams) then exit;  // wp: added FValidFitParams

  ADrawer.Pen := Pen;
  de := PrepareIntervals;
  try
    with TDrawFuncHelper.Create(Self, de, @Calculate, Step) do
      try
        DrawFunction(ADrawer);
      finally
        Free;
      end;
  finally
    de.Free;
  end;
end;


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TFitSeries issues with TUserDefinedChartSource
« Reply #1 on: August 06, 2012, 03:02:03 pm »
Applied in r38179.
A couple of notes:
  • NaNs should not crash drawing of function series, I already know of the problem, but did not fix it yet -- this will be rather complex. Anyway, even without crash, this change would be an optimization, so it is good.
  • I suspect that you forgot to call Reset to notify the chart about changes in the source. I have added a note about it to the documentation.

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: TFitSeries issues with TUserDefinedChartSource
« Reply #2 on: August 06, 2012, 11:13:10 pm »
Thank you.

Quote
NaNs should not crash drawing of function series
The fit series had crashed in TDrawFuncHelper.CalcAt after FCalc(AXa) (calling TFitFunction.Calculate) returned a NaN because the fit had not yet been done.

Quote
I suspect that you forgot to call Reset
Good guess, yes I did not call Reset. After calling Reset, the project runs fine, even without yesterday's patch.

 

TinyPortal © 2005-2018