LazStats: Inherit form of PlotXYUnit from TBasicStatsReportAndChartForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7740 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-04 12:16:47 +00:00
parent 6f5659920f
commit 7edc03ffc8
3 changed files with 76 additions and 186 deletions

View File

@ -8,82 +8,33 @@ inherited PlotXYFrm: TPlotXYFrm
Caption = 'Plot X versus Y' Caption = 'Plot X versus Y'
ClientHeight = 500 ClientHeight = 500
ClientWidth = 1000 ClientWidth = 1000
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnCreate = FormCreate
Position = poMainFormCenter
object ParamsPanel: TPanel[0]
Left = 8
Height = 484 Height = 484
Top = 8
Width = 376 Width = 376
Align = alLeft
BorderSpacing.Around = 8
BevelOuter = bvNone
ClientHeight = 484 ClientHeight = 484
ClientWidth = 376 ClientWidth = 376
TabOrder = 0 inherited CloseBtn: TButton
object CloseBtn: TButton Left = 321
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 314
Height = 25
Top = 459 Top = 459
Width = 62
Anchors = [akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Close'
ModalResult = 11
OnClick = CloseBtnClick
TabOrder = 0
end end
object ComputeBtn: TButton inherited ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn Left = 238
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 230
Height = 25
Top = 459 Top = 459
Width = 76
Anchors = [akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 1
end end
object ResetBtn: TButton inherited ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn Left = 176
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 168
Height = 25
Top = 459 Top = 459
Width = 54
Anchors = [akRight, akBottom]
BorderSpacing.Left = 12
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 2
end end
object Bevel1: TBevel inherited HelpBtn: TButton
AnchorSideLeft.Control = ParamsPanel Left = 117
AnchorSideRight.Control = ParamsPanel Top = 459
AnchorSideRight.Side = asrBottom TabOrder = 11
AnchorSideBottom.Control = CloseBtn end
Left = 0 inherited ButtonBevel: TBevel
Height = 8
Top = 443 Top = 443
Width = 376 Width = 376
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end end
object Label1: TLabel object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel AnchorSideTop.Control = ParamsPanel
Left = 0 Left = 0
@ -93,12 +44,12 @@ inherited PlotXYFrm: TPlotXYFrm
Caption = 'Variables' Caption = 'Variables'
ParentColor = False ParentColor = False
end end
object VarList: TListBox object VarList: TListBox[6]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1 AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = XinBtn AnchorSideRight.Control = XinBtn
AnchorSideBottom.Control = Bevel1 AnchorSideBottom.Control = ButtonBevel
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 0 Left = 0
Height = 426 Height = 426
@ -112,7 +63,7 @@ inherited PlotXYFrm: TPlotXYFrm
OnSelectionChange = VarListSelectionChange OnSelectionChange = VarListSelectionChange
TabOrder = 3 TabOrder = 3
end end
object Label2: TLabel object Label2: TLabel[7]
AnchorSideLeft.Control = XEdit AnchorSideLeft.Control = XEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = XEdit AnchorSideBottom.Control = XEdit
@ -125,7 +76,7 @@ inherited PlotXYFrm: TPlotXYFrm
Caption = 'X Axis Variable' Caption = 'X Axis Variable'
ParentColor = False ParentColor = False
end end
object Label3: TLabel object Label3: TLabel[8]
AnchorSideLeft.Control = YEdit AnchorSideLeft.Control = YEdit
AnchorSideBottom.Control = YEdit AnchorSideBottom.Control = YEdit
Left = 209 Left = 209
@ -137,7 +88,7 @@ inherited PlotXYFrm: TPlotXYFrm
Caption = 'Y Axis Variable' Caption = 'Y Axis Variable'
ParentColor = False ParentColor = False
end end
object XinBtn: TBitBtn object XinBtn: TBitBtn[9]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
@ -153,7 +104,7 @@ inherited PlotXYFrm: TPlotXYFrm
Spacing = 0 Spacing = 0
TabOrder = 4 TabOrder = 4
end end
object XOutBtn: TBitBtn object XOutBtn: TBitBtn[10]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = XinBtn AnchorSideTop.Control = XinBtn
@ -169,7 +120,7 @@ inherited PlotXYFrm: TPlotXYFrm
Spacing = 0 Spacing = 0
TabOrder = 5 TabOrder = 5
end end
object YInBtn: TBitBtn object YInBtn: TBitBtn[11]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = XOutBtn AnchorSideTop.Control = XOutBtn
@ -187,7 +138,7 @@ inherited PlotXYFrm: TPlotXYFrm
Spacing = 0 Spacing = 0
TabOrder = 6 TabOrder = 6
end end
object YOutBtn: TBitBtn object YOutBtn: TBitBtn[12]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = YInBtn AnchorSideTop.Control = YInBtn
@ -205,7 +156,7 @@ inherited PlotXYFrm: TPlotXYFrm
Spacing = 0 Spacing = 0
TabOrder = 7 TabOrder = 7
end end
object XEdit: TEdit object XEdit: TEdit[13]
AnchorSideLeft.Control = XinBtn AnchorSideLeft.Control = XinBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = ParamsPanel AnchorSideRight.Control = ParamsPanel
@ -225,7 +176,7 @@ inherited PlotXYFrm: TPlotXYFrm
TabOrder = 8 TabOrder = 8
Text = 'XEdit' Text = 'XEdit'
end end
object YEdit: TEdit object YEdit: TEdit[14]
AnchorSideLeft.Control = XEdit AnchorSideLeft.Control = XEdit
AnchorSideRight.Control = ParamsPanel AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
@ -241,7 +192,7 @@ inherited PlotXYFrm: TPlotXYFrm
TabOrder = 9 TabOrder = 9
Text = 'YEdit' Text = 'YEdit'
end end
object OptionsGroup: TGroupBox object OptionsGroup: TGroupBox[15]
AnchorSideLeft.Control = XinBtn AnchorSideLeft.Control = XinBtn
AnchorSideTop.Control = YEdit AnchorSideTop.Control = YEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
@ -323,28 +274,13 @@ inherited PlotXYFrm: TPlotXYFrm
end end
end end
end end
object ParamsSplitter: TSplitter[1] inherited ParamsSplitter: TSplitter
Left = 392 Left = 388
Height = 500 Height = 500
Top = 0
Width = 5
ResizeStyle = rsPattern
end end
object PageControl1: TPageControl[2] inherited PageControl: TPageControl
Left = 405 Left = 397
Height = 484 Height = 484
Top = 8 Width = 595
Width = 587
ActivePage = ChartPage
Align = alClient
BorderSpacing.Around = 8
TabIndex = 1
TabOrder = 2
object ReportPage: TTabSheet
Caption = 'Report'
end
object ChartPage: TTabSheet
Caption = 'Chart'
end
end end
end end

View File

@ -9,29 +9,20 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Buttons, ComCtrls, StdCtrls, ExtCtrls, Buttons, ComCtrls,
MainUnit, Globals, FunctionsLib, DataProcs, BasicStatsFormUnit, MainUnit, Globals, FunctionsLib, DataProcs, BasicStatsReportAndChartFormUnit,
ReportFrameUnit, ChartFrameUnit; ReportFrameUnit, ChartFrameUnit;
type type
{ TPlotXYFrm } { TPlotXYFrm }
TPlotXYFrm = class(TBasicStatsForm) TPlotXYFrm = class(TBasicStatsReportAndChartForm)
Bevel1: TBevel;
ConfEdit: TEdit; ConfEdit: TEdit;
Label4: TLabel; Label4: TLabel;
PageControl1: TPageControl;
ParamsPanel: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
LineChk: TCheckBox; LineChk: TCheckBox;
MeansChk: TCheckBox; MeansChk: TCheckBox;
ConfChk: TCheckBox; ConfChk: TCheckBox;
OptionsGroup: TGroupBox; OptionsGroup: TGroupBox;
ParamsSplitter: TSplitter;
ReportPage: TTabSheet;
ChartPage: TTabSheet;
YEdit: TEdit; YEdit: TEdit;
Label3: TLabel; Label3: TLabel;
XEdit: TEdit; XEdit: TEdit;
@ -42,11 +33,6 @@ type
YOutBtn: TBitBtn; YOutBtn: TBitBtn;
Label1: TLabel; Label1: TLabel;
VarList: TListBox; VarList: TListBox;
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject); procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean); procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure XinBtnClick(Sender: TObject); procedure XinBtnClick(Sender: TObject);
@ -55,16 +41,17 @@ type
procedure YOutBtnClick(Sender: TObject); procedure YOutBtnClick(Sender: TObject);
private private
{ private declarations } { private declarations }
FAutoSized: Boolean;
FReportFrame: TReportFrame;
FChartFrame: TChartFrame;
procedure PlotXY(XPoints, YPoints, UpConf, LowConf: DblDyneVec; procedure PlotXY(XPoints, YPoints, UpConf, LowConf: DblDyneVec;
XMean, YMean, R, Slope, Intercept: Double); XMean, YMean, R, Slope, Intercept: Double);
procedure UpdateBtnStates; protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl; function Validate(out AMsg: String; out AControl: TWinControl;
Xcol,Ycol: Integer): Boolean; Xcol,Ycol: Integer): Boolean; reintroduce;
public public
{ public declarations } { public declarations }
constructor Create(AOwner: TComponent); override;
procedure Reset; override; procedure Reset; override;
end; end;
@ -82,6 +69,30 @@ uses
{ TPlotXYFrm } { TPlotXYFrm }
constructor TPlotXYFrm.Create(AOwner: TComponent);
begin
inherited;
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
FChartFrame.Chart.Legend.ColumnCount := 3;
FChartFrame.Chart.Legend.TextFormat := tfHTML;
with FChartFrame.Chart.AxisList.Add do
begin
Alignment := calRight;
Marks.Source := TListChartSource.Create(self);
Marks.Style := smsLabel;
Grid.Visible := false;
end;
with FChartFrame.Chart.AxisList.Add do
begin
Alignment := calTop;
Marks.Source := TListChartSource.Create(self);
Marks.Style := smsLabel;
Grid.Visible := false;
end;
end;
procedure TPlotXYfrm.Reset; procedure TPlotXYfrm.Reset;
var var
i: integer; i: integer;
@ -95,18 +106,16 @@ begin
VarList.Items.Clear; VarList.Items.Clear;
for i := 1 to NoVariables do for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
FChartFrame.Clear;
FReportFrame.Clear; if Assigned(FChartFrame) then
FChartFrame.Clear;
if Assigned(FReportFrame) then
FReportFrame.Clear;
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TPlotXYFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
end;
procedure TPlotXYFrm.VarListDblClick(Sender: TObject); procedure TPlotXYFrm.VarListDblClick(Sender: TObject);
var var
index: integer; index: integer;
@ -170,7 +179,7 @@ begin
end; end;
end; end;
procedure TPlotXYFrm.ComputeBtnClick(Sender: TObject); procedure TPlotXYFrm.Compute;
var var
Xmin, Xmax, Ymin, Ymax, SSx, SSY, t, DF: double; Xmin, Xmax, Ymin, Ymax, SSx, SSY, t, DF: double;
Xmean, Ymean, Xvariance, Yvariance, Xstddev, Ystddev, ConfBand: double; Xmean, Ymean, Xvariance, Yvariance, Xstddev, Ystddev, ConfBand: double;
@ -341,73 +350,15 @@ begin
end; end;
procedure TPlotXYFrm.CloseBtnClick(Sender: TObject); procedure TPlotXYFrm.AdjustConstraints;
begin begin
Close;
end;
procedure TPlotXYFrm.FormActivate(Sender: TObject);
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
ParamsPanel.Constraints.MinHeight := OptionsGroup.Top + OptionsGroup.Height + ParamsPanel.Constraints.MinHeight := OptionsGroup.Top + OptionsGroup.Height +
OptionsGroup.BorderSpacing.Bottom + Bevel1.Height + OptionsGroup.BorderSpacing.Bottom + ButtonBevel.Height +
CloseBtn.Height + CloseBtn.BorderSpacing.Top; CloseBtn.Height + CloseBtn.BorderSpacing.Top;
ParamsPanel.Constraints.MinWidth := OptionsGroup.Width * 2 - XInBtn.Width div 2 - XInBtn.BorderSpacing.Left; ParamsPanel.Constraints.MinWidth := OptionsGroup.Width * 2 - XInBtn.Width div 2 - XInBtn.BorderSpacing.Left;
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Around*2; Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Around*2;
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 200; Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 200;
if Height < Constraints.MinHeight then Height := 1;
if Width < Constraints.MinWidth then Width := 1;
Position := poDesigned;
FAutoSized := True;
end;
procedure TPlotXYFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
InitForm(self);
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient;
FChartFrame := TChartFrame.Create(self);
FChartFrame.Parent := ChartPage;
FChartFrame.Align := alClient;
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
FChartFrame.Chart.Legend.ColumnCount := 3;
FChartFrame.Chart.Legend.TextFormat := tfHTML;
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
with FChartFrame.Chart.AxisList.Add do
begin
Alignment := calRight;
Marks.Source := TListChartSource.Create(self);
Marks.Style := smsLabel;
Grid.Visible := false;
end;
with FChartFrame.Chart.AxisList.Add do
begin
Alignment := calTop;
Marks.Source := TListChartSource.Create(self);
Marks.Style := smsLabel;
Grid.Visible := false;
end;
Reset;
end; end;
@ -486,8 +437,10 @@ begin
YinBtn.Enabled := (VarList.ItemIndex > -1) and (YEdit.Text = ''); YinBtn.Enabled := (VarList.ItemIndex > -1) and (YEdit.Text = '');
YoutBtn.Enabled := (YEdit.Text <> ''); YoutBtn.Enabled := (YEdit.Text <> '');
FReportFrame.UpdateBtnStates; if Assigned(FReportFrame) then
FChartFrame.UpdateBtnStates; FReportFrame.UpdateBtnStates;
if Assigned(FChartFrame) then
FChartFrame.UpdateBtnStates;
end; end;

View File

@ -21,6 +21,7 @@ type
protected protected
FReportFrame: TReportFrame; FReportFrame: TReportFrame;
FChartFrame: TChartFrame; FChartFrame: TChartFrame;
procedure InitForm; override;
procedure UpdateBtnStates; override; procedure UpdateBtnStates; override;
public public