LazStats: Inherit form of CompareDistUnit from TBasicStatsReportAndChartFormUnit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7753 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-07 21:01:01 +00:00
parent 167189ab8c
commit 1fda53b1eb
2 changed files with 92 additions and 254 deletions

View File

@ -8,89 +8,32 @@ inherited CompareDistFrm: TCompareDistFrm
Caption = 'Compare Cumulative Distributions'
ClientHeight = 535
ClientWidth = 924
OnActivate = FormActivate
OnCreate = FormCreate
Position = poMainFormCenter
object ParamsPanel: TPanel[0]
Left = 8
inherited ParamsPanel: TPanel
Height = 519
Top = 8
Width = 296
Align = alLeft
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 4
BorderSpacing.Bottom = 8
BevelOuter = bvNone
ClientHeight = 519
ClientWidth = 296
TabOrder = 0
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 95
Height = 25
inherited CloseBtn: TButton
Top = 494
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 7
TabOrder = 10
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 157
Height = 25
inherited ComputeBtn: TButton
Top = 494
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 8
end
object CloseBtn: TButton
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 241
Height = 25
Top = 494
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Close'
ModalResult = 11
OnClick = CloseBtnClick
TabOrder = 9
end
object Bevel1: TBevel
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ResetBtn
Left = 0
Height = 8
Top = 478
Width = 296
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
inherited ResetBtn: TButton
Top = 494
TabOrder = 8
end
object OptionsGroup: TGroupBox
inherited HelpBtn: TButton
Top = 494
TabOrder = 7
Visible = False
end
inherited ButtonBevel: TBevel
Top = 478
end
object OptionsGroup: TGroupBox[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideBottom.Control = Bevel1
AnchorSideBottom.Control = ButtonBevel
Left = 0
Height = 110
Top = 368
@ -178,7 +121,7 @@ inherited CompareDistFrm: TCompareDistFrm
ParentColor = False
end
end
object Label1: TLabel
object Label1: TLabel[6]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
@ -188,7 +131,7 @@ inherited CompareDistFrm: TCompareDistFrm
Caption = 'Variables:'
ParentColor = False
end
object VarList: TListBox
object VarList: TListBox[7]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
@ -197,7 +140,7 @@ inherited CompareDistFrm: TCompareDistFrm
Left = 0
Height = 343
Top = 17
Width = 107
Width = 102
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 6
@ -207,11 +150,11 @@ inherited CompareDistFrm: TCompareDistFrm
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object Var1InBtn: TBitBtn
object Var1InBtn: TBitBtn[8]
AnchorSideLeft.Control = CompareGroup
AnchorSideTop.Control = VarList
AnchorSideRight.Control = VarOneEdit
Left = 113
Left = 108
Height = 26
Top = 17
Width = 26
@ -223,11 +166,11 @@ inherited CompareDistFrm: TCompareDistFrm
Spacing = 0
TabOrder = 1
end
object Var1OutBtn: TBitBtn
object Var1OutBtn: TBitBtn[9]
AnchorSideLeft.Control = Var1InBtn
AnchorSideTop.Control = Var1InBtn
AnchorSideTop.Side = asrBottom
Left = 113
Left = 108
Height = 26
Top = 47
Width = 26
@ -237,10 +180,10 @@ inherited CompareDistFrm: TCompareDistFrm
Spacing = 0
TabOrder = 2
end
object Label2: TLabel
object Label2: TLabel[10]
AnchorSideLeft.Control = VarOneEdit
AnchorSideBottom.Control = VarOneEdit
Left = 147
Left = 142
Height = 15
Top = 21
Width = 66
@ -249,14 +192,14 @@ inherited CompareDistFrm: TCompareDistFrm
Caption = 'Variable One'
ParentColor = False
end
object VarOneEdit: TEdit
object VarOneEdit: TEdit[11]
AnchorSideLeft.Control = Var1InBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Var1OutBtn
AnchorSideBottom.Side = asrBottom
Left = 147
Left = 142
Height = 23
Top = 38
Width = 149
@ -267,13 +210,13 @@ inherited CompareDistFrm: TCompareDistFrm
TabOrder = 3
Text = 'VarOneEdit'
end
object CompareGroup: TRadioGroup
object CompareGroup: TRadioGroup[12]
AnchorSideLeft.Control = Var1InBtn
AnchorSideTop.Control = Var1OutBtn
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 113
Left = 108
Height = 76
Top = 81
Width = 183
@ -302,13 +245,13 @@ inherited CompareDistFrm: TCompareDistFrm
OnClick = CompareGroupClick
TabOrder = 4
end
object Notebook: TNotebook
object Notebook: TNotebook[13]
AnchorSideLeft.Control = CompareGroup
AnchorSideTop.Control = CompareGroup
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CompareGroup
AnchorSideRight.Side = asrBottom
Left = 113
Left = 108
Height = 191
Top = 165
Width = 183
@ -522,34 +465,14 @@ inherited CompareDistFrm: TCompareDistFrm
end
end
end
object PageControl1: TPageControl[1]
Left = 317
inherited ParamsSplitter: TSplitter
Height = 535
end
inherited PageControl: TPageControl
Height = 519
Top = 8
Width = 599
ActivePage = CumFreqChartPage
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
TabIndex = 1
TabOrder = 1
object ReportPage: TTabSheet
Caption = 'Report'
end
object CumFreqChartPage: TTabSheet
Caption = 'Cumulative frequency plot'
end
object FreqChartPage: TTabSheet
Width = 604
object FreqChartPage: TTabSheet[2]
Caption = 'Frequency plot'
end
end
object ParamsSplitter: TSplitter[2]
Left = 308
Height = 535
Top = 0
Width = 5
ResizeStyle = rsPattern
end
end

View File

@ -10,7 +10,7 @@ uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls, Spin,
FunctionsLib, Globals, GraphLib, DataProcs, MainDM, MainUnit,
BasicStatsFormUnit, ReportFrameUnit, ChartFrameUnit;
BasicStatsReportAndChartFormUnit, ReportFrameUnit, ChartFrameUnit;
type
TCompareTo = (ctTheoreticalDistrib, ctVariable);
@ -18,8 +18,7 @@ type
{ TCompareDistFrm }
TCompareDistFrm = class(TBasicStatsForm)
Bevel1: TBevel;
TCompareDistFrm = class(TBasicStatsReportAndChartForm)
DF1Edit: TEdit;
DF2Edit: TEdit;
DistGroup: TGroupBox;
@ -27,27 +26,19 @@ type
DF2Label: TLabel;
NoIntervalsEdit: TSpinEdit;
NoIntervalsLabel: TLabel;
PageControl1: TPageControl;
ParamsSplitter: TSplitter;
NormalDistChk: TRadioButton;
FreqChartPage: TTabSheet;
tDistChk: TRadioButton;
ChiSqDistChk: TRadioButton;
FDistChk: TRadioButton;
PoissonDistChk: TRadioButton;
ReportPage: TTabSheet;
CumFreqChartPage: TTabSheet;
Notebook: TNotebook;
BarPlotBtn: TSpeedButton;
LinePlotBtn: TSpeedButton;
TheoreticalDistPage: TPage;
VariablePage: TPage;
ParamsPanel: TPanel;
BothChk: TCheckBox;
OptionsGroup: TGroupBox;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
CompareGroup: TRadioGroup;
VarOneEdit: TEdit;
VarTwoEdit: TEdit;
@ -59,13 +50,8 @@ type
Var2OutBtn: TBitBtn;
Label1: TLabel;
VarList: TListBox;
procedure CloseBtnClick(Sender: TObject);
procedure CompareGroupClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DistChange(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure Var1InBtnClick(Sender: TObject);
procedure Var1OutBtnClick(Sender: TObject);
procedure Var2InBtnClick(Sender: TObject);
@ -74,10 +60,7 @@ type
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private
FReportFrame: TReportFrame;
FCumFreqChartFrame: TChartFrame;
FFreqChartFrame: TChartFrame;
FAutoSized: Boolean;
CompareTo: TCompareTo;
CompareDist: TCompareDist;
@ -88,7 +71,7 @@ type
AMin, AMax: Double; ANumIntervals, ANumCases: Integer;
ACompareDist: TCompareDist; DF1: Integer = -1; DF2: Integer = -1);
procedure CalcIntervals(var AMin, AMax, AIntervalsize: Double;
procedure CalcIntervals(var AMin, AMax, AIntervalSize: Double;
out ANumIntervals: Integer);
function CalcMinMax(out AMin, AMax: Double; AColIndex: Integer): Integer;
@ -103,14 +86,17 @@ type
procedure Plot(AChartFrame: TChartFrame; Y1Values, Y2Values: DblDyneVec;
ASeriesTitle1, ASeriesTitle2, AYTitle, ATitle: String);
procedure UpdateBtnStates;
procedure UpdateDF1;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(ANumCases: Integer;
out AMsg: String; out AControl: TWinControl): Boolean;
out AMsg: String; out AControl: TWinControl): Boolean; reintroduce;
public
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
@ -132,6 +118,39 @@ uses
{ TCompareDistFrm }
constructor TCompareDistFrm.Create(AOwner: TComponent);
begin
inherited;
ChartPage.Caption := 'Cumulative frequency plot';
FChartFrame.SetYTitle('Cumulative frequency');
FChartFrame.SetTitle('Plot of Cumulative Distributions');
FFreqChartFrame := TChartFrame.Create(self);
FFreqChartFrame.Parent := FreqChartPage;
FFreqChartFrame.Align := alClient;
FFreqChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FFreqChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
FFreqChartFrame.SetYTitle('Frequency');
FFreqChartFrame.SetTitle('Plot of Distributions');
end;
procedure TCompareDistFrm.AdjustConstraints;
begin
Notebook.AutoSize := true;
ParamsPanel.Constraints.MinWidth := Max(
3*CloseBtn.Width + 2*CloseBtn.BorderSpacing.Left,
Min(
CompareGroup.Width * 2 - Var1InBtn.Width + VarList.BorderSpacing.Right,
OptionsGroup.Width)
);
ParamsPanel.Constraints.MinHeight := Notebook.Top + Notebook.Height +
OptionsGroup.BorderSpacing.Top + OptionsGroup.Height + ButtonBevel.Height +
CloseBtn.Height + CloseBtn.BorderSpacing.Top;
end;
{ Get frequency and cumulative frequency of cases in each interval }
procedure TCompareDistFrm.CalcFreq(XValues, FreqValues, CumFreqValues: DblDyneVec;
AMin, AIncrement: Double; ANumIntervals, AColIndex: Integer);
@ -199,7 +218,7 @@ begin
end;
procedure TCompareDistFrm.CalcIntervals(var AMin, AMax, AIntervalsize: Double;
procedure TCompareDistFrm.CalcIntervals(var AMin, AMax, AIntervalSize: Double;
out ANumIntervals: Integer);
var
intervalSize: Double;
@ -286,12 +305,6 @@ begin
end;
procedure TCompareDistFrm.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TCompareDistFrm.CompareGroupClick(Sender: TObject);
begin
CompareTo := TCompareTo(CompareGroup.ItemIndex);
@ -299,7 +312,7 @@ begin
end;
procedure TCompareDistFrm.ComputeBtnClick(Sender: TObject);
procedure TCompareDistFrm.Compute;
var
var1Freq: DblDyneVec = nil; // could be IntDyneVec, but simpler charting this way
var2Freq: DblDyneVec = nil;
@ -395,7 +408,7 @@ begin
DisplayReport(xValue1, xValue2, var1Freq, var2Freq, cumfreq1, cumFreq2, name1, name2, noInts);
// Plot the cumulative distributions
Plot(FCumFreqChartFrame, cumFreq1, cumFreq2, VarOneEdit.Text, name2,
Plot(FChartFrame, cumFreq1, cumFreq2, VarOneEdit.Text, name2,
'Cumulative Frequency', 'Plot of Cumulative Distributions');
// Plot the frequency distrigutions, if requested.
@ -404,36 +417,6 @@ begin
'Frequency', 'Plot of Distributions');
FreqChartPage.TabVisible := BothChk.Checked;
(*
// Print distributions to report
name1 := CenterString(name1, 12);
name2 := CenterString(name2, 12);
lReport := TStringList.Create;
try
lReport.Add('DISTRIBUTION COMPARISON by Bill Miller');
lReport.Add('');
lReport.Add('%12s %12s %12s %12s %12s %12s', [
name1, name1, name1, name2, name2, name2
]);
lReport.Add('%12s %12s %12s %12s %12s %12s', [
CenterString('X1 Value', 12), CenterString('Frequency', 12), CenterString('Cum. Freq.', 12),
CenterString('X2 Value', 12), CenterString('Frequency', 12), CenterString('Cum. Freq.', 12)
]);
lReport.Add('------------ ------------ ------------ ------------ ------------ ------------');
for i := 1 to noints do
lReport.Add('%12.3f %12.0f %12.3f %12.3f %12.0f %12.3f', [
XValue1[i-1], Var1Freq[i-1], Cumfreq1[i-1], XValue2[i-1], Var2Freq[i-1], Cumfreq2[i-1]
]);
lReport.Add('');
KS := KolmogorovTest(noInts, Cumfreq1, noInts, Cumfreq2, '', lReport);
lReport.Add('Kolmogorov-Smirnov statistic: %5.3f', [KS]);
FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
end;
*)
end;
@ -509,71 +492,6 @@ begin
end;
procedure TCompareDistFrm.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;
Notebook.AutoSize := true;
ParamsPanel.Constraints.MinWidth := Max(
3*w + 2*CloseBtn.BorderSpacing.Left,
Min(
CompareGroup.Width * 2 - Var1InBtn.Width + VarList.BorderSpacing.Right,
OptionsGroup.Width)
);
ParamsPanel.Constraints.MinHeight := Notebook.Top + Notebook.Height +
OptionsGroup.BorderSpacing.Top + OptionsGroup.Height + Bevel1.Height +
CloseBtn.Height + CloseBtn.BorderSpacing.Top;
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 300;
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Top * 2;
if Width < Constraints.MinWidth then Width := 1;
if Height < Constraints.MinHeight then Height := 1;
// Notebook.AutoSize := false;
Position := poDesigned;
FAutoSized := true;
end;
procedure TCompareDistFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
if GraphFrm = nil then Application.CreateForm(TGraphFrm, GraphFrm);
InitForm(self);
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient;
FCumFreqChartFrame := TChartFrame.Create(self);
FCumFreqChartFrame.Parent := CumFreqChartPage;
FCumFreqChartFrame.Align := alClient;
FCumFreqChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FCumFreqChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
FCumFreqChartFrame.SetYTitle('Cumulative frequency');
FCumFreqChartFrame.SetTitle('Plot of Cumulative Distributions');
FFreqChartFrame := TChartFrame.Create(self);
FFreqChartFrame.Parent := FreqChartPage;
FFreqChartFrame.Align := alClient;
FFreqChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FFreqChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
FFreqChartFrame.SetYTitle('Frequency');
FFreqChartFrame.SetTitle('Plot of Distributions');
Reset;
end;
procedure TCompareDistFrm.Plot(AChartFrame: TChartFrame; Y1Values, Y2Values: DblDyneVec;
ASeriesTitle1, ASeriesTitle2, AYTitle, ATitle: String);
var
@ -614,6 +532,8 @@ procedure TCompareDistFrm.Reset;
var
i: integer;
begin
inherited;
VarList.Clear;
VarOneEdit.Text := '';
@ -629,19 +549,14 @@ begin
NormalDistChk.Checked := true;
DistChange(nil);
FReportFrame.Clear;
FCumFreqChartFrame.Clear;
FFreqChartFrame.Clear;
if FReportFrame <> nil then FReportFrame.Clear;
if FChartFrame <> nil then FChartFrame.Clear;
if FFreqChartFrame <> nil then FFreqChartFrame.Clear;
FreqChartPage.TabVisible := false;
end;
procedure TCompareDistFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
end;
procedure TCompareDistFrm.UpdateBtnStates;
begin
Var1InBtn.Enabled := (VarList.ItemIndex > -1) and (VarOneEdit.Text = '');
@ -649,9 +564,9 @@ begin
Var1OutBtn.Enabled := VarOneEdit.Text <> '';
Var2OutBtn.Enabled := VarTwoEdit.Text <> '';
FReportFrame.UpdateBtnStates;
FCumFreqChartFrame.UpdateBtnStates;
FFreqChartFrame.UpdateBtnStates;
if FReportFrame <> nil then FReportFrame.UpdateBtnStates;
if FChartFrame <> nil then FChartFrame.UpdateBtnStates;
if FFreqChartFrame <> nil then FFreqChartFrame.UpdateBtnStates;
end;