LazStats: Inherit form of BoxPlotUnit from TBasicStatsReportAndChartForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7745 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-05 18:46:33 +00:00
parent 0b2786b7b2
commit 04db6bd5ee
2 changed files with 73 additions and 218 deletions

View File

@ -1,4 +1,4 @@
object BoxPlotFrm: TBoxPlotFrm inherited BoxPlotFrm: TBoxPlotFrm
Left = 449 Left = 449
Height = 500 Height = 500
Top = 211 Top = 211
@ -8,102 +8,36 @@ object BoxPlotFrm: TBoxPlotFrm
Caption = 'Box Plot' Caption = 'Box Plot'
ClientHeight = 500 ClientHeight = 500
ClientWidth = 1000 ClientWidth = 1000
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnCreate = FormCreate
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
object ParamsPanel: TPanel
Left = 8
Height = 484 Height = 484
Top = 8
Width = 333 Width = 333
Align = alLeft
BorderSpacing.Around = 8
BevelOuter = bvNone
ClientHeight = 484 ClientHeight = 484
ClientWidth = 333 ClientWidth = 333
TabOrder = 0 inherited CloseBtn: TButton
object CloseBtn: TButton
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 278 Left = 278
Height = 25
Top = 459 Top = 459
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
Caption = 'Close'
ModalResult = 11
OnClick = CloseBtnClick
TabOrder = 10
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 194
Height = 25
Top = 459
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 9
end
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 132
Height = 25
Top = 459
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 8
end
object HelpBtn: TButton
Tag = 108
AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 73
Height = 25
Top = 459
Width = 51
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Help'
OnClick = HelpBtnClick
TabOrder = 7 TabOrder = 7
end end
object Bevel2: TBevel inherited ComputeBtn: TButton
AnchorSideLeft.Control = ParamsPanel Left = 195
AnchorSideRight.Control = ParamsPanel Top = 459
AnchorSideRight.Side = asrBottom TabOrder = 8
AnchorSideBottom.Control = CloseBtn end
Left = 0 inherited ResetBtn: TButton
Height = 8 Left = 133
Top = 459
TabOrder = 9
end
inherited HelpBtn: TButton
Left = 74
Top = 459
TabOrder = 10
end
inherited ButtonBevel: TBevel
Top = 443 Top = 443
Width = 333 Width = 333
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
@ -113,12 +47,12 @@ object BoxPlotFrm: TBoxPlotFrm
Caption = 'Available Variables' Caption = 'Available 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 = MeasInBtn AnchorSideRight.Control = MeasInBtn
AnchorSideBottom.Control = Bevel2 AnchorSideBottom.Control = ButtonBevel
Left = 0 Left = 0
Height = 426 Height = 426
Top = 17 Top = 17
@ -132,7 +66,7 @@ object BoxPlotFrm: TBoxPlotFrm
OnSelectionChange = VarListSelectionChange OnSelectionChange = VarListSelectionChange
TabOrder = 0 TabOrder = 0
end end
object Label2: TLabel object Label2: TLabel[7]
AnchorSideLeft.Control = GrpInBtn AnchorSideLeft.Control = GrpInBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = GroupEdit AnchorSideBottom.Control = GroupEdit
@ -144,7 +78,7 @@ object BoxPlotFrm: TBoxPlotFrm
Caption = 'Group Variable' Caption = 'Group Variable'
ParentColor = False ParentColor = False
end end
object GroupEdit: TEdit object GroupEdit: TEdit[8]
AnchorSideLeft.Control = GrpInBtn AnchorSideLeft.Control = GrpInBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2 AnchorSideTop.Control = Label2
@ -163,7 +97,7 @@ object BoxPlotFrm: TBoxPlotFrm
TabOrder = 6 TabOrder = 6
Text = 'GroupEdit' Text = 'GroupEdit'
end end
object Label3: TLabel object Label3: TLabel[9]
AnchorSideLeft.Control = MeasEdit AnchorSideLeft.Control = MeasEdit
AnchorSideBottom.Control = MeasEdit AnchorSideBottom.Control = MeasEdit
Left = 187 Left = 187
@ -175,7 +109,7 @@ object BoxPlotFrm: TBoxPlotFrm
Caption = 'Meaurement Variable' Caption = 'Meaurement Variable'
ParentColor = False ParentColor = False
end end
object MeasEdit: TEdit object MeasEdit: TEdit[10]
AnchorSideLeft.Control = MeasOutBtn AnchorSideLeft.Control = MeasOutBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
@ -194,7 +128,7 @@ object BoxPlotFrm: TBoxPlotFrm
TabOrder = 3 TabOrder = 3
Text = 'MeasEdit' Text = 'MeasEdit'
end end
object GrpInBtn: TBitBtn object GrpInBtn: TBitBtn[11]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = MeasOutBtn AnchorSideTop.Control = MeasOutBtn
@ -212,7 +146,7 @@ object BoxPlotFrm: TBoxPlotFrm
Spacing = 0 Spacing = 0
TabOrder = 4 TabOrder = 4
end end
object GrpOutBtn: TBitBtn object GrpOutBtn: TBitBtn[12]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = GrpInBtn AnchorSideTop.Control = GrpInBtn
@ -228,7 +162,7 @@ object BoxPlotFrm: TBoxPlotFrm
Spacing = 0 Spacing = 0
TabOrder = 5 TabOrder = 5
end end
object MeasInBtn: TBitBtn object MeasInBtn: TBitBtn[13]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
@ -246,7 +180,7 @@ object BoxPlotFrm: TBoxPlotFrm
Spacing = 0 Spacing = 0
TabOrder = 1 TabOrder = 1
end end
object MeasOutBtn: TBitBtn object MeasOutBtn: TBitBtn[14]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = MeasInBtn AnchorSideTop.Control = MeasInBtn
@ -265,28 +199,13 @@ object BoxPlotFrm: TBoxPlotFrm
TabOrder = 2 TabOrder = 2
end end
end end
object ParamsSplitter: TSplitter inherited ParamsSplitter: TSplitter
Left = 349 Left = 345
Height = 500 Height = 500
Top = 0
Width = 5
ResizeStyle = rsPattern
end end
object PageControl1: TPageControl inherited PageControl: TPageControl
Left = 362 Left = 354
Height = 484 Height = 484
Top = 8 Width = 638
Width = 630
ActivePage = ReportPage
Align = alClient
BorderSpacing.Around = 8
TabIndex = 0
TabOrder = 2
object ReportPage: TTabSheet
Caption = 'Report'
end
object ChartPage: TTabSheet
Caption = 'Chart'
end
end end
end end

View File

@ -10,59 +10,43 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Printers, ComCtrls, Buttons, StdCtrls, ExtCtrls, Printers, ComCtrls, Buttons,
MainUnit, Globals, DataProcs, ContextHelpUnit, MainUnit, Globals, DataProcs, ContextHelpUnit,
BasicStatsFormUnit, ReportFrameUnit, ChartFrameUnit; BasicStatsReportAndChartFormUnit, ReportFrameUnit, ChartFrameUnit;
type type
{ TBoxPlotFrm } { TBoxPlotFrm }
TBoxPlotFrm = class(TBasicStatsForm) TBoxPlotFrm = class(TBasicStatsReportAndChartForm)
Bevel2: TBevel;
HelpBtn: TButton;
PageControl1: TPageControl;
ParamsPanel: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
MeasEdit: TEdit; MeasEdit: TEdit;
GroupEdit: TEdit; GroupEdit: TEdit;
Label1: TLabel; Label1: TLabel;
Label2: TLabel; Label2: TLabel;
Label3: TLabel; Label3: TLabel;
ParamsSplitter: TSplitter;
ReportPage: TTabSheet;
ChartPage: TTabSheet;
VarList: TListBox; VarList: TListBox;
GrpInBtn: TBitBtn; GrpInBtn: TBitBtn;
GrpOutBtn: TBitBtn; GrpOutBtn: TBitBtn;
MeasInBtn: TBitBtn; MeasInBtn: TBitBtn;
MeasOutBtn: TBitBtn; MeasOutBtn: TBitBtn;
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure GrpOutBtnClick(Sender: TObject); procedure GrpOutBtnClick(Sender: TObject);
procedure GrpInBtnClick(Sender: TObject); procedure GrpInBtnClick(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure MeasInBtnClick(Sender: TObject); procedure MeasInBtnClick(Sender: TObject);
procedure MeasOutBtnClick(Sender: TObject); procedure MeasOutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject); procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private private
{ private declarations }
FAutoSized: Boolean;
FReportFrame: TReportFrame;
FChartFrame: TChartFrame;
procedure BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec); procedure BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec);
function Percentile(nScoreGrps: integer; APercentile: Double; function Percentile(nScoreGrps: integer; APercentile: Double;
const Freq, CumFreq, Scores: DblDyneVec): double; const Freq, CumFreq, Scores: DblDyneVec): double;
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
public public
{ public declarations } constructor Create(AOwner: TComponent); override;
procedure Reset; override; procedure Reset; override;
end; end;
@ -83,6 +67,16 @@ const
{ TBoxPlotFrm } { TBoxPlotFrm }
constructor TBoxPlotFrm.Create(AOwner: TComponent);
begin
inherited;
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
FChartFrame.Chart.Legend.ColumnCount := 3;
FChartFrame.Chart.Legend.TextFormat := tfHTML;
end;
procedure TBoxPlotFrm.BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec); procedure TBoxPlotFrm.BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec);
var var
i: Integer; i: Integer;
@ -120,13 +114,7 @@ begin
end; end;
procedure TBoxPlotFrm.CloseBtnClick(Sender: TObject); procedure TBoxPlotFrm.Compute;
begin
Close;
end;
procedure TBoxPlotFrm.ComputeBtnClick(Sender: TObject);
var var
lReport: TStrings; lReport: TStrings;
i, j, k, GrpVar, MeasVar, mingrp, maxgrp, G, NoGrps, cnt: integer; i, j, k, GrpVar, MeasVar, mingrp, maxgrp, G, NoGrps, cnt: integer;
@ -146,7 +134,7 @@ var
TenPcntile: DblDyneVec = nil; TenPcntile: DblDyneVec = nil;
NinetyPcntile: DblDyneVec = nil; NinetyPcntile: DblDyneVec = nil;
Median: DblDyneVec = nil; Median: DblDyneVec = nil;
ColNoSelected: IntDyneVec; ColNoSelected: IntDyneVec = nil;
begin begin
lReport := TStringList.Create; lReport := TStringList.Create;
try try
@ -337,73 +325,23 @@ begin
BoxPlot(LowQrtl, HiQrtl, TenPcntile, NinetyPcntile, Median); BoxPlot(LowQrtl, HiQrtl, TenPcntile, NinetyPcntile, Median);
finally finally
lReport.Free; lReport.Free;
// Clean up
Median := nil;
NinetyPcntile := nil;
TenPcntile := nil;
HiQrtl := nil;
LowQrtl := nil;
Means := nil;
GrpSize := nil;
CumFreq := nil;
Scores := nil;
Freq := nil;
ColNoSelected := nil;
end; end;
end; end;
procedure TBoxPlotFrm.FormActivate(Sender: TObject); procedure TBoxPlotFrm.AdjustConstraints;
var
w: Integer;
begin begin
if FAutoSized then inherited;
exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
HelpBtn.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
ParamsPanel.Constraints.MinWidth := Max( ParamsPanel.Constraints.MinWidth := Max(
4*w + 3*HelpBtn.BorderSpacing.Right, 4*CloseBtn.Width + 3*HelpBtn.BorderSpacing.Right,
Max(Label1.Width, Label3.Width) * 2 + MeasInBtn.Width + 2 * MeasInBtn.BorderSpacing.Left Max(Label1.Width, Label3.Width) * 2 + MeasInBtn.Width + 2 * MeasInBtn.BorderSpacing.Left
); );
ParamsPanel.Constraints.MinHeight := VarList.Top + VarList.Constraints.MinHeight + ParamsPanel.Constraints.MinHeight := VarList.Top + VarList.Constraints.MinHeight +
Bevel2.Height + CloseBtn.Height + CloseBtn.BorderSpacing.Top; ButtonBevel.Height + CloseBtn.Height + CloseBtn.BorderSpacing.Top;
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; // enforce auto-sizing
if Width < Constraints.MiNWidth then Width := 1;
Position := poDesigned;
FAutoSized := true;
end;
procedure TBoxPlotFrm.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;
Reset;
end; end;
@ -432,14 +370,6 @@ begin
end; end;
procedure TBoxPlotFrm.HelpBtnClick(Sender: TObject);
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).Tag);
end;
procedure TBoxPlotFrm.MeasInBtnClick(Sender: TObject); procedure TBoxPlotFrm.MeasInBtnClick(Sender: TObject);
var var
index: integer; index: integer;
@ -453,6 +383,7 @@ begin
end; end;
end; end;
procedure TBoxPlotFrm.MeasOutBtnClick(Sender: TObject); procedure TBoxPlotFrm.MeasOutBtnClick(Sender: TObject);
begin begin
if MeasEdit.Text <> '' then if MeasEdit.Text <> '' then
@ -505,31 +436,36 @@ procedure TBoxPlotFrm.Reset;
var var
i: integer; i: integer;
begin begin
inherited;
VarList.Clear; VarList.Clear;
GroupEdit.Text := ''; GroupEdit.Text := '';
MeasEdit.Text := ''; MeasEdit.Text := '';
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]);
UpdateBtnStates; UpdateBtnStates;
end;
if Assigned(FReportFrame) then
procedure TBoxPlotFrm.ResetBtnClick(Sender: TObject); FReportFrame.Clear;
begin if Assigned(FChartFrame) then
Reset; FChartFrame.Clear;
end; end;
procedure TBoxPlotFrm.UpdateBtnStates; procedure TBoxPlotFrm.UpdateBtnStates;
begin begin
inherited;
MeasinBtn.Enabled := (VarList.ItemIndex > -1) and (MeasEdit.Text = ''); MeasinBtn.Enabled := (VarList.ItemIndex > -1) and (MeasEdit.Text = '');
MeasoutBtn.Enabled := (MeasEdit.Text <> ''); MeasoutBtn.Enabled := (MeasEdit.Text <> '');
GrpinBtn.Enabled := (VarList.ItemIndex > -1) and (GroupEdit.Text = ''); GrpinBtn.Enabled := (VarList.ItemIndex > -1) and (GroupEdit.Text = '');
grpoutBtn.Enabled := (GroupEdit.Text <> ''); grpoutBtn.Enabled := (GroupEdit.Text <> '');
FReportFrame.UpdateBtnStates; if Assigned(FReportFrame) then
FChartFrame.UpdateBtnStates; FReportFrame.UpdateBtnStates;
if Assigned(FChartFrame) then
FChartFrame.UpdateBtnStates;
end; end;