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

View File

@ -10,59 +10,43 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Printers, ComCtrls, Buttons,
MainUnit, Globals, DataProcs, ContextHelpUnit,
BasicStatsFormUnit, ReportFrameUnit, ChartFrameUnit;
BasicStatsReportAndChartFormUnit, ReportFrameUnit, ChartFrameUnit;
type
{ TBoxPlotFrm }
TBoxPlotFrm = class(TBasicStatsForm)
Bevel2: TBevel;
HelpBtn: TButton;
PageControl1: TPageControl;
ParamsPanel: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
TBoxPlotFrm = class(TBasicStatsReportAndChartForm)
MeasEdit: TEdit;
GroupEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ParamsSplitter: TSplitter;
ReportPage: TTabSheet;
ChartPage: TTabSheet;
VarList: TListBox;
GrpInBtn: TBitBtn;
GrpOutBtn: TBitBtn;
MeasInBtn: TBitBtn;
MeasOutBtn: TBitBtn;
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure GrpOutBtnClick(Sender: TObject);
procedure GrpInBtnClick(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure MeasInBtnClick(Sender: TObject);
procedure MeasOutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private
{ private declarations }
FAutoSized: Boolean;
FReportFrame: TReportFrame;
FChartFrame: TChartFrame;
procedure BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec);
function Percentile(nScoreGrps: integer; APercentile: Double;
const Freq, CumFreq, Scores: DblDyneVec): double;
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
public
{ public declarations }
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
@ -83,6 +67,16 @@ const
{ 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);
var
i: Integer;
@ -120,13 +114,7 @@ begin
end;
procedure TBoxPlotFrm.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TBoxPlotFrm.ComputeBtnClick(Sender: TObject);
procedure TBoxPlotFrm.Compute;
var
lReport: TStrings;
i, j, k, GrpVar, MeasVar, mingrp, maxgrp, G, NoGrps, cnt: integer;
@ -146,7 +134,7 @@ var
TenPcntile: DblDyneVec = nil;
NinetyPcntile: DblDyneVec = nil;
Median: DblDyneVec = nil;
ColNoSelected: IntDyneVec;
ColNoSelected: IntDyneVec = nil;
begin
lReport := TStringList.Create;
try
@ -337,73 +325,23 @@ begin
BoxPlot(LowQrtl, HiQrtl, TenPcntile, NinetyPcntile, Median);
finally
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;
procedure TBoxPlotFrm.FormActivate(Sender: TObject);
var
w: Integer;
procedure TBoxPlotFrm.AdjustConstraints;
begin
if FAutoSized then
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;
inherited;
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
);
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.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;
@ -432,14 +370,6 @@ begin
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);
var
index: integer;
@ -453,6 +383,7 @@ begin
end;
end;
procedure TBoxPlotFrm.MeasOutBtnClick(Sender: TObject);
begin
if MeasEdit.Text <> '' then
@ -505,31 +436,36 @@ procedure TBoxPlotFrm.Reset;
var
i: integer;
begin
inherited;
VarList.Clear;
GroupEdit.Text := '';
MeasEdit.Text := '';
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
procedure TBoxPlotFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
if Assigned(FReportFrame) then
FReportFrame.Clear;
if Assigned(FChartFrame) then
FChartFrame.Clear;
end;
procedure TBoxPlotFrm.UpdateBtnStates;
begin
inherited;
MeasinBtn.Enabled := (VarList.ItemIndex > -1) and (MeasEdit.Text = '');
MeasoutBtn.Enabled := (MeasEdit.Text <> '');
GrpinBtn.Enabled := (VarList.ItemIndex > -1) and (GroupEdit.Text = '');
grpoutBtn.Enabled := (GroupEdit.Text <> '');
FReportFrame.UpdateBtnStates;
FChartFrame.UpdateBtnStates;
if Assigned(FReportFrame) then
FReportFrame.UpdateBtnStates;
if Assigned(FChartFrame) then
FChartFrame.UpdateBtnStates;
end;