View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0035163 | Lazarus | TAChart | public | 2019-02-27 22:56 | 2019-02-28 21:48 |
Reporter | Marcin Wiazowski | Assigned To | wp | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 2.1 (SVN) | ||||
Target Version | 2.2 | ||||
Summary | 0035163: TAChart: lack of initialization in TFitSeries.EquationText | ||||
Description | In the attached Reproduce application, there is a chart having TFitSeries. There are also two event handlers, containing same code: procedure TForm1.FormCreate(Sender: TObject); begin Caption := Chart1FitSeries.EquationText.Get; end; procedure TForm1.ButtonTestClick(Sender: TObject); begin Caption := Chart1FitSeries.EquationText.Get; end; 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. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
LazTarget | 2.2 | ||||
Widgetset | Win32/Win64 | ||||
Attached Files |
|
|
|
|
|
|
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; begin + ExecFit; if State = fpsValid then Result := TFitEquationText.Create else |
|
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. |
|
Not really a problem. ExecFit() is a public function, so everyone can call it: procedure TForm1.FormCreate(Sender: TObject); begin Chart1FitSeries.ExecFit; Caption := Chart1FitSeries.EquationText.Get; end; This solves the problem. |
|
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. |
|
|
|
Great solution. Seems to work perfectly. Thanks! |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-02-27 22:56 | Marcin Wiazowski | New Issue | |
2019-02-27 22:56 | Marcin Wiazowski | File Added: Reproduce.zip | |
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: AutoEdit.zip | |
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 |