LazStats: Inherit form of FreqUnit from TBasicStatsReportForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7763 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-10 20:56:57 +00:00
parent 9b96b7f82f
commit 94e789f3be
3 changed files with 88 additions and 187 deletions

View File

@ -8,24 +8,36 @@ inherited FreqFrm: TFreqFrm
Caption = 'Frequency Distribution'
ClientHeight = 385
ClientWidth = 835
OnActivate = FormActivate
OnCreate = FormCreate
Position = poMainFormCenter
object ParamsPanel: TPanel[0]
Left = 8
inherited ParamsPanel: TPanel
Height = 369
Top = 8
Width = 264
Align = alLeft
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 4
BorderSpacing.Bottom = 8
BevelOuter = bvNone
ClientHeight = 369
ClientWidth = 264
TabOrder = 0
object Panel1: TPanel
inherited CloseBtn: TButton
Left = 209
Top = 344
TabOrder = 4
end
inherited ComputeBtn: TButton
Left = 125
Top = 344
TabOrder = 5
end
inherited ResetBtn: TButton
Left = 63
Top = 344
TabOrder = 6
end
inherited HelpBtn: TButton
Left = 4
Top = 344
TabOrder = 7
end
inherited ButtonBevel: TBevel
Top = 328
Width = 264
end
object Panel1: TPanel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
@ -142,7 +154,7 @@ inherited FreqFrm: TFreqFrm
TabOrder = 3
end
end
object NormPltChk: TCheckBox
object NormPltChk: TCheckBox[6]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Side = asrBottom
@ -157,76 +169,12 @@ inherited FreqFrm: TFreqFrm
Caption = 'Plot Normal Distribution'
TabOrder = 1
end
object Bevel1: TBevel
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 328
Width = 264
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end
object ResetBtn: TButton
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 63
Height = 25
Top = 344
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 4
end
object CloseBtn: TButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 209
Height = 25
Top = 344
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Close'
ModalResult = 1
OnClick = CloseBtnClick
TabOrder = 6
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 125
Height = 25
Top = 344
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 5
end
object PlotOptionsGroup: TGroupBox
object PlotOptionsGroup: TGroupBox[7]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = BinSelectionGroup
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel1
AnchorSideBottom.Control = ButtonBevel
Left = 0
Height = 52
Top = 276
@ -310,7 +258,7 @@ inherited FreqFrm: TFreqFrm
TabOrder = 0
end
end
object BinSelectionGroup: TGroupBox
object BinSelectionGroup: TGroupBox[8]
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
@ -372,12 +320,9 @@ inherited FreqFrm: TFreqFrm
end
end
end
object ParamsSplitter: TSplitter[1]
inherited ParamsSplitter: TSplitter
Left = 276
Height = 385
Top = 0
Width = 5
ResizeStyle = rsPattern
end
object PageControl: TPageControl[2]
Left = 285

View File

@ -10,25 +10,21 @@ uses lazlogger,
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, LCLVersion,
StdCtrls, Buttons, ExtCtrls, ComCtrls, Spin,
Globals, MainUnit, DataProcs,
BasicStatsFormUnit, ReportFrameUnit, ChartFrameUnit;
BasicStatsReportFormUnit, ReportFrameUnit, ChartFrameUnit;
type
{ TFreqFrm }
TFreqFrm = class(TBasicStatsForm)
Bevel1: TBevel;
TFreqFrm = class(TBasicStatsReportForm)
BinSelectionGroup: TGroupBox;
ThreeDChk: TCheckBox;
ComputeBtn: TButton;
PlotOptionsGroup: TGroupBox;
NoIntervalsLabel: TLabel;
PageControl: TPageControl;
ReportPage: TTabSheet;
Panel1: TPanel;
Panel2: TPanel;
ParamsPanel: TPanel;
ResetBtn: TButton;
CloseBtn: TButton;
NormPltChk: TCheckBox;
InBtn: TBitBtn;
OutBtn: TBitBtn;
@ -36,8 +32,6 @@ type
Label1: TLabel;
Label2: TLabel;
SelList: TListBox;
ParamsSplitter: TSplitter;
ReportPage: TTabSheet;
NoIntervalsEdit: TSpinEdit;
HorBarsBtn: TSpeedButton;
LinePlotBtn: TSpeedButton;
@ -45,32 +39,29 @@ type
VertBarsBtn: TSpeedButton;
VarList: TListBox;
procedure AllBtnClick(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InBtnClick(Sender: TObject);
procedure OutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure SelListSelectionChange(Sender: TObject; User: boolean);
procedure SelListSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private
{ private declarations }
FReportFrame: TReportFrame;
FAutoSized: Boolean;
procedure CalcIntervals(var AMin, AMax, AIntervalSize: Double;
out ANumIntervals: Integer);
procedure ClearTabs;
function CreateOrGetChartFrame(AColIndex: Integer; AVarName: String): TChartFrame;
function GetPageCaption(AVarName: String): String;
procedure PlotFreq(AChartFrame: TChartFrame; AColIndex: Integer;
AVarName: String; const xLabels: StrDyneVec;
const Freq: DblDyneVec);
AVarName: String; const xLabels: StrDyneVec; const Freq: DblDyneVec);
procedure PlotNormalDist(AChartFrame: TChartFrame; Freq: DblDyneVec);
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
public
{ public declarations }
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
@ -78,6 +69,7 @@ var
FreqFrm: TFreqFrm;
implementation
{$R *.lfm}
@ -86,8 +78,32 @@ uses
Math, TAChartUtils, TALegend, TASources, TACustomSeries, TASeries,
Utils, MathUnit;
{ TFreqFrm }
constructor TFreqFrm.Create(AOwner: TComponent);
begin
inherited;
FReportFrame.Parent := ReportPage;
end;
procedure TFreqFrm.AdjustConstraints;
begin
Panel1.Constraints.MinHeight := AllBtn.Top + AllBtn.Height;
Panel1.Constraints.MinWidth := Max(Label1.Width, Label2.Width) + AllBtn.Width + VarList.BorderSpacing.Right*2;
ParamsPanel.Constraints.MinHeight := Panel1.Constraints.MinHeight +
NormPltChk.BorderSpacing.Top + NormPltChk.Height +
BinSelectionGroup.BorderSpacing.Top + BinSelectionGroup.Height +
PlotOptionsGroup.BorderSpacing.Top + PlotOptionsGroup.Height +
ButtonBevel.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
ParamsPanel.Constraints.MinWidth := Max(
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
Panel1.Constraints.MinWidth) + ParamsPanel.BorderSpacing.left*2;
end;
procedure TFreqFrm.AllBtnClick(Sender: TObject);
var
count, index : integer;
@ -119,23 +135,19 @@ begin
ANumIntervals := round((AMax - AMin) / AIntervalSize);
end;
procedure TFreqFrm.ClearTabs;
var
i: Integer;
begin
FReportFrame.Clear;
if Assigned(FReportFrame) then
FReportFrame.Clear;
for i := PageControl.PageCount-1 downto 1 do
PageControl.Pages[i].Free;
end;
procedure TFreqFrm.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TFreqFrm.ComputeBtnClick(Sender: TObject);
procedure TFreqFrm.Compute;
var
i, j, k: integer;
freq: DblDyneVec = nil;
@ -368,55 +380,6 @@ begin
end;
procedure TFreqFrm.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;
Panel1.Constraints.MinHeight := AllBtn.Top + AllBtn.Height;
Panel1.Constraints.MinWidth := Max(Label1.Width, Label2.Width) + AllBtn.Width + VarList.BorderSpacing.Right*2;
ParamsPanel.Constraints.MinHeight := Panel1.Constraints.MinHeight +
NormPltChk.BorderSpacing.Top + NormPltChk.Height +
BinSelectionGroup.BorderSpacing.Top + BinSelectionGroup.Height +
PlotOptionsGroup.BorderSpacing.Top + PlotOptionsGroup.Height +
Bevel1.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
ParamsPanel.Constraints.MinWidth := Max(
3*w + 2 * CloseBtn.BorderSpacing.Left,
Panel1.Constraints.MinWidth) + ParamsPanel.BorderSpacing.left*2;
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 300;
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Top*2;
if Width < Constraints.MinWidth then Width := 1; // trigger autoscaling
if Height < Constraints.MinHeight then Height := 1;
Position := poMainFormCenter;
FAutoSized := true;
end;
procedure TFreqFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
InitForm(Self);
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient;
Position := poDefault;
Reset;
end;
function TFreqFrm.GetPageCaption(AVarName: String): String;
begin
Result := 'Plot of ' + AVarName;
@ -448,6 +411,7 @@ begin
UpdateBtnStates;
end;
procedure TFreqFrm.OutBtnClick(Sender: TObject);
var
i: integer;
@ -467,6 +431,7 @@ begin
UpdateBtnStates;
end;
procedure TFreqFrm.PlotFreq(AChartFrame: TChartFrame; AColIndex: Integer;
AVarName: String; const xLabels: StrDyneVec; const Freq: DblDyneVec);
var
@ -591,6 +556,8 @@ procedure TFreqFrm.Reset;
var
i: integer;
begin
inherited;
VarList.Clear;
SelList.Clear;
for i := 1 to NoVariables do
@ -602,18 +569,14 @@ begin
end;
procedure TFreqFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
end;
procedure TFreqFrm.UpdateBtnStates;
var
lSelected: Boolean;
i: Integer;
chartFrame: TChartFrame;
begin
inherited;
lSelected := false;
for i := 0 to VarList.Items.Count-1 do
if VarList.Selected[i] then
@ -634,7 +597,6 @@ begin
AllBtn.Enabled := VarList.Items.Count > 0;
FReportFrame.UpdateBtnStates;
for i := 1 to PageControl.PageCount-1 do
begin
chartFrame := PageControl.Pages[i].Controls[0] as TChartFrame;
@ -658,7 +620,6 @@ begin
end;
procedure TFreqFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;

View File

@ -9,7 +9,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls,
MainUnit, Globals, FunctionsLib, DataProcs, BasicStatsReportAndChartFormUnit,
MainUnit, Globals, FunctionsLib, BasicStatsReportAndChartFormUnit,
ReportFrameUnit, ChartFrameUnit;
@ -57,7 +57,7 @@ uses
Math, MathUnit,
TAChartUtils, TATextElements, TACustomSeries, TATransformations,
TAChartAxisUtils, TAChartAxis, TASources,
Utils;
Utils, GridProcs;
function PopulateLeftMarks(AOwner: TComponent): TListChartSource;
@ -379,18 +379,13 @@ var
selCol: Integer;
i, n: Integer;
begin
Result := nil;
// Find data column in the grid
selcol := 0;
for i := 1 to NoVariables do
if OS3MainFrm.DataGrid.Cells[i, 0] = VarName then
begin
selcol := i;
break;
end;
if selCol = 0 then
selCol := GetVariableIndex(OS3MainFrm.DataGrid, VarName);
if selCol <= 0 then
begin
Result := nil;
MessageDlg('No variable selected.', mtError, [mbOK], 0);
ErrorMsg('No variable selected.');
exit;
end;
@ -400,7 +395,7 @@ begin
n := 0;
for i := 1 to NoCases do
begin
if not ValidValue(i, selcol) then
if not ValidValue(OS3MainFrm.DataGrid, i, selcol) then
continue;
inc(n);
if not TryStrToFloat(OS3MainFrm.DataGrid.Cells[selcol, i], Result[n]) then