LazStats: Inherit form of DistribUnit from TBasicStatsChartForm. Fix TabOrders.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7751 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-06 22:35:16 +00:00
parent 43dca206b2
commit d915a7428e
8 changed files with 183 additions and 263 deletions

View File

@ -339,9 +339,6 @@ begin
);
ParamsPanel.Constraints.MinHeight := VarList.Top + VarList.Constraints.MinHeight +
ButtonBevel.Height + CloseBtn.Height + CloseBtn.BorderSpacing.Top;
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Around*2;
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 200;
end;

View File

@ -16,22 +16,22 @@ inherited BreakDownFrm: TBreakDownFrm
inherited CloseBtn: TButton
Left = 289
Top = 322
TabOrder = 8
TabOrder = 11
end
inherited ComputeBtn: TButton
Left = 206
Top = 322
TabOrder = 9
TabOrder = 10
end
inherited ResetBtn: TButton
Left = 144
Top = 322
TabOrder = 10
TabOrder = 9
end
inherited HelpBtn: TButton
Left = 85
Top = 322
TabOrder = 11
TabOrder = 8
end
inherited ButtonBevel: TBevel
Top = 306

View File

@ -527,13 +527,13 @@ inherited CompareDistFrm: TCompareDistFrm
Height = 519
Top = 8
Width = 599
ActivePage = ReportPage
ActivePage = CumFreqChartPage
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
TabIndex = 0
TabIndex = 1
TabOrder = 1
object ReportPage: TTabSheet
Caption = 'Report'

View File

@ -182,7 +182,7 @@ inherited FreqFrm: TFreqFrm
AutoSize = True
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 2
TabOrder = 4
end
object CloseBtn: TButton
AnchorSideLeft.Side = asrBottom
@ -202,7 +202,7 @@ inherited FreqFrm: TFreqFrm
Caption = 'Close'
ModalResult = 1
OnClick = CloseBtnClick
TabOrder = 3
TabOrder = 6
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
@ -219,7 +219,7 @@ inherited FreqFrm: TFreqFrm
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 4
TabOrder = 5
end
object PlotOptionsGroup: TGroupBox
AnchorSideLeft.Control = ParamsPanel
@ -237,7 +237,7 @@ inherited FreqFrm: TFreqFrm
Caption = 'Plot Options'
ClientHeight = 32
ClientWidth = 251
TabOrder = 5
TabOrder = 2
object VertBarsBtn: TSpeedButton
AnchorSideLeft.Control = PlotOptionsGroup
AnchorSideTop.Control = PlotOptionsGroup
@ -326,7 +326,7 @@ inherited FreqFrm: TFreqFrm
Caption = 'Bin Selection'
ClientHeight = 37
ClientWidth = 251
TabOrder = 6
TabOrder = 3
object Panel2: TPanel
AnchorSideLeft.Control = BinSelectionGroup
AnchorSideTop.Control = BinSelectionGroup

View File

@ -9,16 +9,20 @@ inherited GroupFreqForm: TGroupFreqForm
ClientHeight = 263
inherited CloseBtn: TButton
Top = 238
TabOrder = 8
end
inherited ComputeBtn: TButton
Top = 238
TabOrder = 3
end
inherited ResetBtn: TButton
Top = 238
TabOrder = 7
end
inherited HelpBtn: TButton
Tag = 162
Top = 238
TabOrder = 6
end
inherited ButtonBevel: TBevel
Top = 222
@ -49,7 +53,7 @@ inherited GroupFreqForm: TGroupFreqForm
ItemHeight = 0
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 4
TabOrder = 0
end
object GrpInBtn: TBitBtn[7]
AnchorSideLeft.Control = ParamsPanel
@ -63,7 +67,7 @@ inherited GroupFreqForm: TGroupFreqForm
ImageIndex = 1
OnClick = GrpInBtnClick
Spacing = 0
TabOrder = 5
TabOrder = 1
end
object GrpOutBtn: TBitBtn[8]
AnchorSideLeft.Control = ParamsPanel
@ -79,7 +83,7 @@ inherited GroupFreqForm: TGroupFreqForm
ImageIndex = 0
OnClick = GrpOutBtnClick
Spacing = 0
TabOrder = 6
TabOrder = 2
end
object Label2: TLabel[9]
AnchorSideLeft.Control = GrpVarEdit
@ -110,7 +114,7 @@ inherited GroupFreqForm: TGroupFreqForm
BorderSpacing.Top = 2
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 7
TabOrder = 4
Text = 'GrpVarEdit'
end
object PlotOptionsGroup: TGroupBox[11]
@ -126,7 +130,7 @@ inherited GroupFreqForm: TGroupFreqForm
Caption = 'Plot Options'
ClientHeight = 59
ClientWidth = 143
TabOrder = 8
TabOrder = 5
object VertBarsBtn: TSpeedButton
AnchorSideLeft.Control = PlotOptionsGroup
AnchorSideTop.Control = PlotOptionsGroup

View File

@ -84,6 +84,9 @@ begin
AdjustConstraints;
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Around*2;
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 300;
if Width < Constraints.MinWidth then Width := 1; // enforce constraints
if Height < Constraints.MinHeight then Height := 1;

View File

@ -1,4 +1,4 @@
object DistribFrm: TDistribFrm
inherited DistribFrm: TDistribFrm
Left = 398
Height = 428
Top = 241
@ -8,63 +8,48 @@ object DistribFrm: TDistribFrm
Caption = 'Distributions'
ClientHeight = 428
ClientWidth = 948
OnActivate = FormActivate
OnCreate = FormCreate
Position = poMainFormCenter
ShowHint = True
LCLVersion = '2.1.0.0'
object ChartPanel: TPanel
AnchorSideLeft.Control = ParameterPanel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 235
Height = 411
Top = 8
Width = 705
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 9
BevelOuter = bvNone
BorderStyle = bsSingle
Color = clWhite
ParentColor = False
TabOrder = 0
end
object ParameterPanel: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 420
Top = 8
Width = 227
Anchors = [akTop, akLeft, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BevelOuter = bvNone
ClientHeight = 420
ClientWidth = 227
inherited ParamsPanel: TPanel
Height = 412
Width = 208
ClientHeight = 412
ClientWidth = 208
TabOrder = 1
object GroupBox1: TGroupBox
AnchorSideLeft.Control = ParameterPanel
AnchorSideTop.Control = ParameterPanel
AnchorSideRight.Control = ParameterPanel
AnchorSideRight.Side = asrBottom
inherited CloseBtn: TButton
Left = 153
Top = 387
TabOrder = 6
end
inherited ComputeBtn: TButton
Left = 70
Top = 387
TabOrder = 5
end
inherited ResetBtn: TButton
Left = 8
Top = 387
TabOrder = 4
end
inherited HelpBtn: TButton
Left = -51
Top = 387
Visible = False
end
inherited ButtonBevel: TBevel
Top = 371
Width = 208
end
object GroupBox1: TGroupBox[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 175
Top = 0
Width = 219
Width = 208
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Left = 8
Caption = 'Plot Distribution'
ChildSizing.LeftRightSpacing = 16
ChildSizing.TopBottomSpacing = 8
@ -74,7 +59,7 @@ object DistribFrm: TDistribFrm
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 155
ClientWidth = 215
ClientWidth = 204
TabOrder = 0
object NDChk: TRadioButton
Left = 16
@ -92,7 +77,7 @@ object DistribFrm: TDistribFrm
Width = 183
Caption = 'Student t Distribution (1-sided)'
OnClick = DistributionClick
TabOrder = 3
TabOrder = 1
end
object FChk: TRadioButton
Left = 16
@ -110,7 +95,7 @@ object DistribFrm: TDistribFrm
Width = 183
Caption = 'Chi-Square Distribution'
OnClick = DistributionClick
TabOrder = 1
TabOrder = 3
end
object Bevel2: TBevel
AnchorSideRight.Side = asrBottom
@ -131,29 +116,29 @@ object DistribFrm: TDistribFrm
TabOrder = 4
end
end
object GroupBox2: TGroupBox
AnchorSideLeft.Control = GroupBox1
object GroupBox2: TGroupBox[6]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = GroupBox1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Side = asrBottom
Left = 8
Left = 0
Height = 107
Top = 191
Width = 219
Width = 208
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 16
BorderSpacing.Bottom = 12
Caption = 'Parameters'
ClientHeight = 87
ClientWidth = 215
ClientWidth = 204
TabOrder = 1
object AlphaLabel: TLabel
AnchorSideTop.Control = AlphaEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AlphaEdit
Left = 68
Left = 57
Height = 15
Top = 6
Width = 84
@ -166,7 +151,7 @@ object DistribFrm: TDistribFrm
AnchorSideTop.Control = DF1Edit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = DF1Edit
Left = 61
Left = 50
Height = 15
Top = 33
Width = 91
@ -180,7 +165,7 @@ object DistribFrm: TDistribFrm
AnchorSideTop.Control = DF2Edit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = DF2Edit
Left = 61
Left = 50
Height = 15
Top = 60
Width = 91
@ -194,7 +179,7 @@ object DistribFrm: TDistribFrm
AnchorSideTop.Control = GroupBox2
AnchorSideRight.Control = GroupBox2
AnchorSideRight.Side = asrBottom
Left = 160
Left = 149
Height = 23
Top = 2
Width = 43
@ -210,7 +195,7 @@ object DistribFrm: TDistribFrm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AlphaEdit
AnchorSideRight.Side = asrBottom
Left = 160
Left = 149
Height = 23
Top = 29
Width = 43
@ -225,7 +210,7 @@ object DistribFrm: TDistribFrm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AlphaEdit
AnchorSideRight.Side = asrBottom
Left = 160
Left = 149
Height = 23
Top = 56
Width = 43
@ -237,8 +222,7 @@ object DistribFrm: TDistribFrm
Text = 'DF2Edit'
end
end
object ShowCriticalValuesChk: TCheckBox
AnchorSideLeft.Control = ParameterPanel
object ShowCriticalValuesChk: TCheckBox[7]
AnchorSideTop.Control = GroupBox2
AnchorSideTop.Side = asrBottom
Left = 16
@ -246,63 +230,32 @@ object DistribFrm: TDistribFrm
Top = 310
Width = 123
BorderSpacing.Left = 16
BorderSpacing.Bottom = 16
Caption = 'Show critical values'
Checked = True
OnChange = ShowCriticalValuesChkChange
State = cbChecked
TabOrder = 2
end
object CloseBtn: TButton
AnchorSideRight.Control = ParameterPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParameterPanel
AnchorSideBottom.Side = asrBottom
Left = 172
Height = 25
Hint = 'Close the form'
Top = 387
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
OnClick = CloseBtnClick
TabOrder = 3
end
object ComputeBtn: TButton
AnchorSideTop.Control = CloseBtn
AnchorSideRight.Control = CloseBtn
Left = 88
Height = 25
Hint = 'Perform the calculation'
Top = 387
Width = 76
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 4
end
object ResetBtn: TButton
AnchorSideTop.Control = CloseBtn
AnchorSideRight.Control = ComputeBtn
Left = 26
Height = 25
Hint = 'Reset all parameters to default'
Top = 387
Width = 54
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 5
end
end
inherited ParamsSplitter: TSplitter
Left = 220
Height = 428
end
object ChartPanel: TPanel[2]
Left = 229
Height = 412
Top = 8
Width = 711
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
BevelOuter = bvNone
BorderStyle = bsSingle
Color = clWhite
ParentColor = False
TabOrder = 0
end
end

View File

@ -3,8 +3,6 @@
// Test input parameters:
// - F distribution: DF1 = 3, DF2 = 20
// ToDo: Fix calculation of t distribution
unit DistribUnit;
{$mode objfpc}{$H+}
@ -15,37 +13,29 @@ uses
Classes, SysUtils, FileUtil, LCLVersion,
Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Math,
TAFuncSeries,
Globals, FunctionsLib, ChartFrameUnit;
Globals, FunctionsLib, ChartFrameUnit, BasicStatsChartFormUnit;
type
{ TDistribFrm }
TDistribFrm = class(TForm)
TDistribFrm = class(TBasicStatsChartForm)
AlphaEdit: TEdit;
Bevel2: TBevel;
ShowCriticalValuesChk: TCheckBox;
CumulativeChk: TCheckBox;
tChk: TRadioButton;
ParameterPanel: TPanel;
ChiChk: TRadioButton;
DF1Edit: TEdit;
DF2Edit: TEdit;
FChk: TRadioButton;
NDChk: TRadioButton;
ChartPanel: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
GroupBox2: TGroupBox;
AlphaLabel: TLabel;
DF1Label: TLabel;
DF2Label: TLabel;
GroupBox1: TGroupBox;
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CalcChi2(const AX: Double; out AY: Double);
procedure CalcChi2_Cumulative(const AX: Double; out AY: Double);
procedure CalcF(const AX: Double; out AY: Double);
@ -55,14 +45,10 @@ type
procedure CalcT(const AX: Double; out AY: Double);
procedure CalcT_Cumulative(const AX: Double; out AY: Double);
procedure DistributionClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure ShowCriticalValuesChkChange(Sender: TObject);
procedure tbEraseClick(Sender: TObject);
private
{ private declarations }
FAutoSized: Boolean;
FChartFrame: TChartFrame;
Alpha: Double;
DF1: Integer;
DF2: Integer;
@ -73,11 +59,15 @@ type
procedure Chi2Plot;
procedure FPlot;
procedure tPlot;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public
{ public declarations }
procedure Reset;
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
var
@ -97,6 +87,26 @@ const
{ TDistribFrm }
constructor TDistribFrm.Create(AOwner: TComponent);
begin
inherited;
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
FChartFrame.Chart.Legend.ColumnCount := 3;
FChartFrame.Chart.Legend.TextFormat := tfHTML;
// InitToolbar(FChartFrame.ChartToolbar, tpTop);
tbErase := TToolButton.Create(self);
tbErase.ImageIndex := 6;
tbErase.Caption := 'Erase';
tbErase.Hint := 'Clear chart';
tbErase.OnClick := @tbEraseClick;
AddButtonToToolbar(tbErase, FChartFrame.ChartToolBar);
Reset;
end;
procedure TDistribFrm.AddSeries(ATitle: string; XMin, XMax: Double;
xCrit, yCrit: Double; Cumulative: Boolean; ACalcFunc: TFuncCalculateEvent);
var
@ -183,8 +193,60 @@ begin
end;
procedure TDistribFrm.AdjustConstraints;
begin
inherited;
paramsPanel.Constraints.MinWidth := 3*CloseBtn.Width + 2*CloseBtn.BorderSpacing.Left;
ParamsPanel.Constraints.MinHeight :=
ShowCriticalValuesChk.Top + ShowCriticalValuesChk.Height + ShowCriticalValuesChk.BorderSpacing.Bottom +
ButtonBevel.Height + CloseBtn.Height;
end;
procedure TDistribFrm.Compute;
var
msg: String;
C: TWinControl;
ok: Boolean;
begin
inherited;
ok := false;
if NDChk.Checked then
begin
NormalDistPlot();
ok := true;
end;
if tChk.Checked then
begin
tPlot();
ok := true;
end;
if ChiChk.Checked then
begin
Chi2Plot();
ok := true;
end;
if FChk.Checked then
begin
FPlot();
ok := true;
end;
if not ok then
MessageDlg('Please select a distribution.', mtError, [mbOK], 0);
end;
procedure TDistribFrm.Reset;
begin
inherited;
NDChk.Checked := false;
tChk.Checked := false;
FChk.Checked := false;
@ -193,16 +255,14 @@ begin
DF1Edit.Text := '';
DF2Edit.Text := '';
GroupBox2.Enabled := false;
FChartFrame.Clear;
tbErase.Enabled := false;
if FChartFrame <> nil then
FChartFrame.Clear;
if tbErase <> nil then
tbErase.Enabled := false;
end;
procedure TDistribFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
end;
procedure TDistribFrm.ShowCriticalValuesChkChange(Sender: TObject);
var
i: Integer;
@ -298,55 +358,6 @@ begin
end;
procedure TDistribFrm.ComputeBtnClick(Sender: TObject);
var
msg: String;
C: TWinControl;
ok: Boolean;
begin
if not Validate(msg, C) then
begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0);
exit;
end;
ok := false;
if NDChk.Checked then
begin
NormalDistPlot();
ok := true;
end;
if tChk.Checked then
begin
tPlot();
ok := true;
end;
if ChiChk.Checked then
begin
Chi2Plot();
ok := true;
end;
if FChk.Checked then
begin
FPlot();
ok := true;
end;
if not ok then
MessageDlg('Please select a distribution.', mtError, [mbOK], 0);
end;
procedure TDistribFrm.CloseBtnClick(Sender: TObject);
begin
Close;
end;
// Plots the normal distribution
procedure TDistribFrm.NormalDistPlot;
var
@ -429,55 +440,10 @@ begin
end;
procedure TDistribFrm.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;
Constraints.MinHeight :=
ShowCriticalValuesChk.Top + ShowCriticalValuesChk.Height + 16 +
CloseBtn.Height + CloseBtn.BorderSpacing.Bottom;
Constraints.MinWidth := ParameterPanel.Width * 2;
Position := poDefault;
FAutoSized := true;
end;
procedure TDistribFrm.FormCreate(Sender: TObject);
begin
InitForm(self);
FChartFrame := TChartFrame.Create(self);
FChartFrame.Parent := ChartPanel;
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;
InitToolbar(FChartFrame.ChartToolbar, tpTop);
tbErase := TToolButton.Create(self);
tbErase.ImageIndex := 6;
tbErase.Caption := 'Erase';
tbErase.Hint := 'Clear chart';
tbErase.OnClick := @tbEraseClick;
AddButtonToToolbar(tbErase, FChartFrame.ChartToolBar);
Reset;
end;
procedure TDistribFrm.tbEraseClick(Sender: TObject);
begin
FChartFrame.Clear;
if FChartFrame <> nil then
FChartFrame.Clear;
tbErase.Enabled := false;
end;
@ -539,8 +505,5 @@ begin
Result := true;
end;
//initialization
// {$I distribunit.lrs}
end.