Recent

Author Topic: info for case that chart editor demo is used with LiveView  (Read 1540 times)

Muso

  • Full Member
  • ***
  • Posts: 244
info for case that chart editor demo is used with LiveView
« on: July 23, 2021, 03:17:31 am »
When the chart editor demo is used for projects using also TChartLiveView (https://wiki.freepascal.org/TAChart_documentation#Live_View), the following patch is necessary for the procedure FormCloseQuery in ceAxisDlg.pas:

Code: Pascal  [Select][+][-]
  1. procedure TChartAxisEditor.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  2. begin
  3.   if not CanClose then exit;
  4.   if not FOKClicked then begin
  5.     RestoreAxisParams;
  6.     GetChart.Invalidate;
  7.   end
  8.   else
  9.   // when LiveView is used LiveView can have set the min/max values of axis
  10.   // because new data points might have been set while the axis dialog was open
  11.   // therefore check if the min/max set in the dialog are the ones in the axis
  12.   // and if not set them
  13.   begin
  14.     if FAxis.Range.Max <> FAxisFrame.seMaximum.Value then
  15.       FAxis.Range.Max := FAxisFrame.seMaximum.Value;
  16.     if FAxis.Range.Min <> FAxisFrame.seMinimum.Value then
  17.       FAxis.Range.Min := FAxisFrame.seMinimum.Value;
  18.   end;
  19. end;

The problem is that the chart editor demo dialog applies the changes made in the dialog immediately. This is per se a good idea since the user sees the changes immediately.
However one needs some time to make all changes in the dialog and meanwhile new data points can have arrived so that LiveView changes the Max before the dialog is closed.
Therefore one must assure that really the values from the dialog are used when the dialog is closed.

------------

Another info: When LiveView is used one must in procedure TMainForm.EditAxis (in ceMain.pas) inform LiveView about the changes made via the chart editor dialog by using the LiveView procedure StoreAxisRange. So TMainForm.EditAxis becomes

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.EditAxis(AAxis: TChartAxis; APage: TChartAxisEditorPage);
  2. var
  3.   F: TChartAxisEditor;
  4. begin
  5.   if cbUseAllInOneDialog.Checked then
  6.     EditChartAxis(AAxis, APage)
  7.   else
  8.   begin
  9.     F := TChartAxisEditor.Create(nil);
  10.     try
  11.       F.Prepare(AAxis, 'Edit chart axis "%s"');
  12.       F.Page := APage;
  13.       F.ShowModal;
  14.       // update the axis settings for the LiveView
  15.       ChartLiveView.StoreAxisRange(AAxis);
  16.     finally
  17.       F.Free;
  18.     end;
  19.   end;
  20. end;

 

TinyPortal © 2005-2018