View Issue Details

IDProjectCategoryView StatusLast Update
0035163LazarusTAChartpublic2019-02-28 21:48
ReporterMarcin Wiazowski Assigned Towp  
Status closedResolutionfixed 
Product Version2.1 (SVN) 
Target Version2.2 
Summary0035163: TAChart: lack of initialization in TFitSeries.EquationText
DescriptionIn the attached Reproduce application, there is a chart having TFitSeries. There are also two event handlers, containing same code:

  procedure TForm1.FormCreate(Sender: TObject);
    Caption := Chart1FitSeries.EquationText.Get;

  procedure TForm1.ButtonTestClick(Sender: TObject);
    Caption := Chart1FitSeries.EquationText.Get;

TFitSeries calculates its interpolation parameters, so the interpolated equation can be obtained (as a string) by calling EquationText.Get(): in case of the Reproduce application, the string will be:

  'y = -0,125 + 1,025*x + 0,125*x^2'

The problem is that, after the Reproduce application is launched, window's caption is empty. After pressing the "Test" button - which executes same code as FormCreate() - window's caption is properly set.

This is because interpolation parameters are initialized in a TFitSeries.ExecFit() method, which is called in various places - in particular in TFitSeries.Draw(). So drawing the chart makes the parameters initialized - so pressing the "Test" button makes the "EquationText.Get" call succeeded. On the contrary, in the FormCreate() handler, interpolation parameters are not yet initialized - so the "EquationText.Get" call returns an empty string.

A solution is trivial: a call to "ExecFit()" should be also added to the TFitSeries.EquationText() method. The attached patch solves the problem. After applying the patch and launching the Reproduce application, window's caption shows the proper equation string from the beginning - there is no need to use the "Test" button.
TagsNo tags attached.
Fixed in Revision
Attached Files


Marcin Wiazowski

2019-02-27 22:56

reporter (2,446 bytes)

Marcin Wiazowski

2019-02-27 22:56


Reproduce.png (6,073 bytes)   
Reproduce.png (6,073 bytes)   

Marcin Wiazowski

2019-02-27 22:57


patch.diff (386 bytes)   
Index: components/tachart/tafuncseries.pas
--- components/tachart/tafuncseries.pas	(revision 60526)
+++ components/tachart/tafuncseries.pas	(working copy)
@@ -1680,6 +1680,7 @@
   basis: Array of string;
   i: Integer;
+  ExecFit;
   if State = fpsValid then
     Result := TFitEquationText.Create
patch.diff (386 bytes)   


2019-02-28 00:53

developer   ~0114493

I don't think that this patch is needed.

Basically when I wrote this series I did not plan to make the fit results available at any time. Maybe in future versions we have non-linear fits which are not completed immediately, and there should be control of when the fit is executed. Executing the fit when results are queried makes this impossible. Therefore, an event OnFitComplete was added in which you should query the EquationText. With such a handler the fit results will be displayed immediately when the program starts.

Furthermore, your patch only addresses EquationText, but not the other fit result properties. Following your idea I would have to add "ExecFit" to the getters of all these properties.

Marcin Wiazowski

2019-02-28 01:02

reporter   ~0114494

Not really a problem. ExecFit() is a public function, so everyone can call it:

  procedure TForm1.FormCreate(Sender: TObject);
    Caption := Chart1FitSeries.EquationText.Get;

This solves the problem.


2019-02-28 15:20

developer   ~0114505

Reopening just to be able to add some comment, please close again afterwards:

Added a new property AutoFit which calculates the fit automatically whenever something relevant changes; there's no need to call ExecFit explicitly any more. The first calculation (if successful) sets the Status variable to "valid" to avoid multiple calls to ExecFit once a result is available. When needing more control, AutoFit should be set to false and ExecFit should be called manually. I also looked through the methods with return fit results and fixed them to return NaN as long as an invalidated fit has not yet been calculated.


2019-02-28 15:21

developer (3,314 bytes)

Marcin Wiazowski

2019-02-28 21:48

reporter   ~0114524

Great solution. Seems to work perfectly. Thanks!

Issue History

Date Modified Username Field Change
2019-02-27 22:56 Marcin Wiazowski New Issue
2019-02-27 22:56 Marcin Wiazowski File Added:
2019-02-27 22:56 Marcin Wiazowski File Added: Reproduce.png
2019-02-27 22:57 Marcin Wiazowski File Added: patch.diff
2019-02-27 23:55 Maxim Ganetsky Assigned To => wp
2019-02-27 23:55 Maxim Ganetsky Status new => assigned
2019-02-28 00:49 wp LazTarget => -
2019-02-28 00:49 wp Status assigned => resolved
2019-02-28 00:49 wp Resolution open => no change required
2019-02-28 00:50 wp Status resolved => assigned
2019-02-28 00:50 wp Resolution no change required => reopened
2019-02-28 00:53 wp Note Added: 0114493
2019-02-28 00:54 wp Status assigned => resolved
2019-02-28 00:54 wp Resolution reopened => no change required
2019-02-28 01:02 Marcin Wiazowski Note Added: 0114494
2019-02-28 01:02 Marcin Wiazowski Status resolved => closed
2019-02-28 15:20 wp Note Added: 0114505
2019-02-28 15:20 wp Status closed => assigned
2019-02-28 15:20 wp Resolution no change required => reopened
2019-02-28 15:21 wp File Added:
2019-02-28 15:22 wp LazTarget - => 2.2
2019-02-28 15:22 wp Status assigned => resolved
2019-02-28 15:22 wp Resolution reopened => fixed
2019-02-28 15:22 wp Target Version => 2.2
2019-02-28 21:48 Marcin Wiazowski Note Added: 0114524
2019-02-28 21:48 Marcin Wiazowski Status resolved => closed