LazStats: Beginning to use TAChart inside FreqUnit. Trying to avoid annoying FreqSpecs dialogs. Not complete, yet. Some simplifications in other units (InitForm)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7688 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-09-23 11:19:08 +00:00
parent 3395fc8847
commit 202d0b5559
9 changed files with 700 additions and 420 deletions

View File

@ -387,8 +387,7 @@ procedure TBoxPlotFrm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
Width := Scale96ToFont(DEFAULT_WIDTH); InitForm(self);
Height := Scale96ToFont(DEFAULT_HEIGHT);
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;

View File

@ -400,8 +400,7 @@ begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm); if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm);
Width := Scale96ToFont(DEFAULT_WIDTH); InitForm(self);
Height := Scale96ToFont(DEFAULT_HEIGHT);
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;

View File

@ -1,27 +1,158 @@
object FreqFrm: TFreqFrm object FreqFrm: TFreqFrm
Left = 490 Left = 490
Height = 388 Height = 543
Top = 228 Top = 228
Width = 502 Width = 889
HelpType = htKeyword HelpType = htKeyword
HelpKeyword = 'html/FrequencyAnalysis.htm' HelpKeyword = 'html/FrequencyAnalysis.htm'
Caption = 'Frequency Distribution' Caption = 'Frequency Distribution'
ClientHeight = 388 ClientHeight = 543
ClientWidth = 502 ClientWidth = 889
OnActivate = FormActivate OnActivate = FormActivate
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object PlotOptionsGroup: TRadioGroup object ParamsPanel: TPanel
AnchorSideTop.Control = Owner Left = 8
AnchorSideRight.Control = Owner Height = 527
AnchorSideRight.Side = asrBottom
Left = 346
Height = 222
Top = 8 Top = 8
Width = 148 Width = 288
Anchors = [akTop, akRight] Align = alLeft
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 4
BorderSpacing.Bottom = 8
BevelOuter = bvNone
ClientHeight = 527
ClientWidth = 288
TabOrder = 0
object Panel1: TPanel
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = PlotOptionsGroup
Left = 0
Height = 217
Top = 0
Width = 288
Anchors = [akTop, akLeft, akRight]
BevelOuter = bvNone
ClientHeight = 217
ClientWidth = 288
TabOrder = 0
object Label1: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
Left = 0
Height = 15
Top = 0
Width = 97
Caption = 'Available Variables'
ParentColor = False
end
object Label2: TLabel
AnchorSideLeft.Control = SelList
AnchorSideTop.Control = Panel1
Left = 175
Height = 15
Top = 0
Width = 104
Caption = 'Variables to Analyze'
ParentColor = False
end
object VarList: TListBox
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AllBtn
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 200
Top = 17
Width = 113
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 8
ItemHeight = 0
MultiSelect = True
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object SelList: TListBox
AnchorSideLeft.Control = AllBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 175
Height = 200
Top = 17
Width = 113
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
ItemHeight = 0
OnSelectionChange = SelListSelectionChange
TabOrder = 4
end
object InBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
Left = 131
Height = 26
Top = 23
Width = 26
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1
end
object OutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
Left = 131
Height = 26
Top = 56
Width = 26
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object AllBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = OutBtn
AnchorSideTop.Side = asrBottom
Left = 121
Height = 25
Top = 106
Width = 46
AutoSize = True
BorderSpacing.Top = 24
Caption = 'ALL'
OnClick = AllBtnClick
TabOrder = 3
end
end
object PlotOptionsGroup: TRadioGroup
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = BarTypeGroup
Left = 0
Height = 127
Top = 273
Width = 277
Anchors = [akLeft, akBottom]
AutoFill = True AutoFill = True
AutoSize = True AutoSize = True
BorderSpacing.Top = 8 BorderSpacing.Top = 8
@ -29,14 +160,16 @@ object FreqFrm: TFreqFrm
Caption = 'Plot Options' Caption = 'Plot Options'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 2
ClientHeight = 202 ClientHeight = 107
ClientWidth = 144 ClientWidth = 273
Columns = 2
ItemIndex = 0 ItemIndex = 0
Items.Strings = ( Items.Strings = (
'2D Vertical Bars' '2D Vertical Bars'
@ -53,20 +186,98 @@ object FreqFrm: TFreqFrm
OnSelectionChanged = PlotOptionsGroupSelectionChanged OnSelectionChanged = PlotOptionsGroupSelectionChanged
TabOrder = 1 TabOrder = 1
end end
object BarTypeGroup: TRadioGroup object NormPltChk: TCheckBox
AnchorSideLeft.Control = PlotOptionsGroup AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = PlotOptionsGroup
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = PlotOptionsGroup
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 346 AnchorSideBottom.Control = Bevel1
Height = 70 Left = 0
Top = 242 Height = 19
Width = 148 Top = 467
Anchors = [akTop, akLeft, akRight] Width = 149
Anchors = [akLeft, akBottom]
BorderSpacing.Top = 8
Caption = 'Plot Normal Distribution'
TabOrder = 2
end
object Bevel1: TBevel
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 486
Width = 288
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end
object ResetBtn: TButton
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 87
Height = 25
Top = 502
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 3
end
object CloseBtn: TButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 233
Height = 25
Top = 502
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Close'
ModalResult = 1
OnClick = CloseBtnClick
TabOrder = 4
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = ParamsPanel
AnchorSideBottom.Side = asrBottom
Left = 149
Height = 25
Top = 502
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 5
end
object BarTypeGroup: TRadioGroup
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NormPltChk
Left = 0
Height = 51
Top = 408
Width = 182
Anchors = [akLeft, akBottom]
AutoFill = True AutoFill = True
AutoSize = True AutoSize = True
BorderSpacing.Top = 12 BorderSpacing.Top = 8
Caption = 'Bar Type' Caption = 'Bar Type'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
@ -75,211 +286,82 @@ object FreqFrm: TFreqFrm
ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 2
ClientHeight = 50 ClientHeight = 31
ClientWidth = 144 ClientWidth = 178
Columns = 2
Enabled = False Enabled = False
ItemIndex = 0 ItemIndex = 0
Items.Strings = ( Items.Strings = (
'Separated' 'Separated'
'Contiguous' 'Contiguous'
) )
TabOrder = 2
end
object NormPltChk: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel1
Left = 8
Height = 19
Top = 320
Width = 149
Anchors = [akLeft, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Plot Normal Distribution'
TabOrder = 3
end
object Panel1: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideRight.Control = PlotOptionsGroup
AnchorSideBottom.Control = NormPltChk
Left = 8
Height = 304
Top = 8
Width = 330
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 8
BevelOuter = bvNone
ClientHeight = 304
ClientWidth = 330
TabOrder = 0
object Label1: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
Left = 0
Height = 15
Top = 0
Width = 97
Caption = 'Available Variables'
ParentColor = False
end
object Label2: TLabel
AnchorSideLeft.Control = SelList
AnchorSideTop.Control = Panel1
Left = 196
Height = 15
Top = 0
Width = 104
Caption = 'Variables to Analyze'
ParentColor = False
end
object VarList: TListBox
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AllBtn
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 287
Top = 17
Width = 134
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 8
ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object SelList: TListBox
AnchorSideLeft.Control = AllBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 196
Height = 287
Top = 17
Width = 134
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
ItemHeight = 0
OnSelectionChange = SelListSelectionChange
TabOrder = 4
end
object InBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
Left = 151
Height = 28
Top = 23
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1
end
object OutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
Left = 151
Height = 28
Top = 56
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object AllBtn: TBitBtn
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrCenter
Left = 142
Height = 25
Top = 136
Width = 46
AutoSize = True
Caption = 'ALL'
OnClick = AllBtnClick
TabOrder = 3
end
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 339
Width = 502
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end
object ResetBtn: TButton
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 289
Height = 25
Top = 355
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 4
end
object CloseBtn: TButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 435
Height = 25
Top = 355
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 1
TabOrder = 5
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 351
Height = 25
Top = 355
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 6 TabOrder = 6
end end
object Panel2: TPanel
AnchorSideLeft.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = PlotOptionsGroup
Left = 0
Height = 23
Top = 236
Width = 288
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BevelOuter = bvNone
ClientHeight = 23
ClientWidth = 288
TabOrder = 7
object NoIntervalsEdit: TSpinEdit
AnchorSideLeft.Control = NoIntervalsLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel2
Left = 121
Height = 23
Top = 0
Width = 74
Alignment = taRightJustify
BorderSpacing.Left = 16
MinValue = 1
TabOrder = 0
Value = 10
end
object NoIntervalsLabel: TLabel
AnchorSideLeft.Control = Panel2
AnchorSideTop.Control = NoIntervalsEdit
AnchorSideTop.Side = asrCenter
Left = 0
Height = 15
Top = 4
Width = 105
Caption = 'Number of intervals'
ParentColor = False
end
end
end
object ParamsSplitter: TSplitter
Left = 300
Height = 543
Top = 0
Width = 5
ResizeStyle = rsPattern
end
object PageControl: TPageControl
Left = 309
Height = 527
Top = 8
Width = 572
ActivePage = ReportPage
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
TabIndex = 0
TabOrder = 2
object ReportPage: TTabSheet
Caption = 'Report'
end
end
end end

View File

@ -7,9 +7,9 @@ unit FreqUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, StdCtrls, Buttons, ExtCtrls, ComCtrls, Spin,
Globals, MainUnit, OutputUnit, FunctionsLib, GraphLib, DataProcs; Globals, MainUnit, FunctionsLib, GraphLib, DataProcs, ReportFrameUnit, ChartFrameUnit;
type type
@ -18,7 +18,11 @@ type
TFreqFrm = class(TForm) TFreqFrm = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
ComputeBtn: TButton; ComputeBtn: TButton;
NoIntervalsLabel: TLabel;
PageControl: TPageControl;
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel;
ParamsPanel: TPanel;
ResetBtn: TButton; ResetBtn: TButton;
CloseBtn: TButton; CloseBtn: TButton;
NormPltChk: TCheckBox; NormPltChk: TCheckBox;
@ -30,86 +34,51 @@ type
SelList: TListBox; SelList: TListBox;
PlotOptionsGroup: TRadioGroup; PlotOptionsGroup: TRadioGroup;
BarTypeGroup: TRadioGroup; BarTypeGroup: TRadioGroup;
ParamsSplitter: TSplitter;
ReportPage: TTabSheet;
NoIntervalsEdit: TSpinEdit;
VarList: TListBox; VarList: TListBox;
procedure AllBtnClick(Sender: TObject); procedure AllBtnClick(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure InBtnClick(Sender: TObject); procedure InBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure PlotOptionsGroupSelectionChanged(Sender: TObject);
procedure SelListSelectionChange(Sender: TObject; User: boolean);
procedure OutBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject);
procedure PlotOptionsGroupSelectionChanged(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
procedure SelListSelectionChange(Sender: TObject; User: boolean);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
{ private declarations } { private declarations }
FReportFrame: TReportFrame;
FAutoSized: Boolean; FAutoSized: Boolean;
procedure ClearTabs;
function CreateChartFrame(AColIndex: Integer; AVarName: String): TChartFrame;
function GetPageCaption(AVarName: String): String;
procedure PlotFreq(AColIndex: Integer; AVarName: String; const xLabels: StrDyneVec;
const Freq: DblDyneVec);
procedure UpdateBtnStates; procedure UpdateBtnStates;
public public
{ public declarations } { public declarations }
procedure Reset;
end; end;
var var
FreqFrm: TFreqFrm; FreqFrm: TFreqFrm;
implementation implementation
{$R *.lfm}
uses uses
Math, Math, TAChartUtils, TALegend, TASeries,
FreqSpecsUnit; Utils, FreqSpecsUnit;
{ TFreqFrm } { TFreqFrm }
procedure TFreqFrm.ResetBtnClick(Sender: TObject);
var
i: integer;
begin
VarList.Clear;
SelList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
BarTypeGroup.ItemIndex := 0;
PlotOptionsGroup.ItemIndex := 0;
NormPltChk.Checked := false;
UpdateBtnStates;
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 := BarTypeGroup.Top + BarTypeGroup.Height - Panel1.Top;
Panel1.Constraints.MinWidth := Label2.Width * 2 + AllBtn.Width + 2 * VarList.BorderSpacing.Right;
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
FAutoSized := true;
end;
procedure TFreqFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
if FreqSpecsFrm = nil then
Application.CreateForm(TFreqSpecsFrm, FreqSpecsFrm);
if GraphFrm = nil then
Application.CreateForm(TGraphFrm, GraphFrm);
end;
procedure TFreqFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TFreqFrm.AllBtnClick(Sender: TObject); procedure TFreqFrm.AllBtnClick(Sender: TObject);
var var
count, index : integer; count, index : integer;
@ -118,69 +87,75 @@ begin
for index := 0 to count-1 do for index := 0 to count-1 do
SelList.Items.Add(VarList.Items[index]); SelList.Items.Add(VarList.Items[index]);
VarList.Clear; VarList.Clear;
ClearTabs;
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TFreqFrm.InBtnClick(Sender: TObject);
procedure TFreqFrm.ClearTabs;
var var
i: integer; i: Integer;
begin begin
i := 0; FReportFrame.Clear;
while i < VarList.Items.Count do for i := PageControl.PageCount-1 downto 1 do
begin PageControl.Pages[i].Free;
if (VarList.Selected[i]) then
begin
SelList.Items.Add(VarList.Items[i]);
VarList.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
UpdateBtnStates;
end; end;
procedure TFreqFrm.SelListSelectionChange(Sender: TObject; User: boolean);
procedure TFreqFrm.CloseBtnClick(Sender: TObject);
begin begin
UpdateBtnStates; Close;
end; end;
procedure TFreqFrm.ComputeBtnClick(Sender: TObject); procedure TFreqFrm.ComputeBtnClick(Sender: TObject);
var var
i, j, k : integer; i, j, k: integer;
freq : DblDyneVec; freq: DblDyneVec = nil;
pcnt : DblDyneVec; pcnt: DblDyneVec = nil;
cumpcnt : DblDyneVec; cumpcnt: DblDyneVec = nil;
pcntilerank : DblDyneVec; pcntilerank: DblDyneVec = nil;
cumfreq : DblDyneVec; cumfreq: DblDyneVec = nil;
XValue : DblDyneVec; XLabels: StrDyneVec = nil;
value : double; XValue: DblDyneVec = nil;
NoVars : integer; value: double;
plottype : integer; NoVars: integer;
cellval : string; plottype: integer;
col : integer; cellval: string;
min, max : double; col: integer;
range : double; min, max, range: double;
incrsize : double; incrsize: double;
nointervals : double; nointervals: double;
nints : integer; nInts: integer;
// ColNoSelected : IntDyneVec; NormDist: boolean;
NormDist : boolean; Sumx, Sumx2, Mean, Variance, StdDev, zlow, zhi: double;
Histogram : boolean; X, zproplow, zprophi, zfreq: double;
Sumx, Sumx2, Mean, Variance, StdDev, zlow, zhi : double; nCases: integer;
X, zproplow, zprophi, zfreq : double; oldPageIndex: Integer;
Ncases : integer; found: Boolean;
lReport: TStrings; lReport: TStrings;
begin begin
if BarTypeGroup.ItemIndex = 1 then Histogram := true else Histogram := false; if SelList.Count = 0 then
if NormPltChk.Checked = true then NormDist := true else NormDist := false; begin
ErrorMsg('No variable(s) selected.');
exit;
end;
SetLength(freq,NoCases); NormDist := NormPltChk.Checked;
SetLength(pcnt,NoCases);
SetLength(cumpcnt,NoCases); SetLength(freq, NoCases);
SetLength(pcntilerank,NoCases); SetLength(pcnt, NoCases);
SetLength(cumfreq,NoCases); SetLength(cumpcnt, NoCases);
SetLength(XValue,NoCases); SetLength(pcntilerank, NoCases);
SetLength(cumfreq, NoCases);
SetLength(XValue, NoCases);
(* ---------------> causes flicker
// Remove already existing chart pages
oldPageIndex := PageControl.PageIndex;
for i := PageControl.PageCount-1 downto 1 do
PageControl.Pages[i].Free;
*)
lReport := TStringList.Create; lReport := TStringList.Create;
try try
@ -193,27 +168,29 @@ begin
begin begin
{ get column no. of variable } { get column no. of variable }
col := 1; col := 1;
cellval := SelList.Items.Strings[i-1]; cellval := SelList.Items[i-1];
for j := 1 to NoVariables do for j := 1 to NoVariables do
begin begin
if OS3MainFrm.DataGrid.Cells[j,0] = cellval then if OS3MainFrm.DataGrid.Cells[j,0] = cellval then
begin begin
col := j; col := j;
lReport.Add('Frequency Analysis for Variable "%s"', [cellval]); if i > 1 then lReport.Add('');
lReport.Add('Frequency analysis for variable "%s"', [cellval]);
break; break;
end; end;
end; end;
{ get min and max values for variable in col } { get min and max values for variable in col }
min := 1.0e32; min := Infinity;
max := -1.0e32; max := -Infinity;
for j := 1 to NoCases do for j := 1 to NoCases do
begin begin
if not ValidValue(j,col) then continue; if not ValidValue(j, col) then continue;
value := StrToFloat(OS3MainFrm.DataGrid.Cells[col,j]); value := StrToFloat(OS3MainFrm.DataGrid.Cells[col,j]);
if value > max then max := value; if value > max then max := value;
if value < min then min := value; if value < min then min := value;
end; end;
(*
range := max - min + 1.0; range := max - min + 1.0;
incrsize := 1.0; incrsize := 1.0;
{ if too many increments, set increment size for 15 increments } { if too many increments, set increment size for 15 increments }
@ -236,52 +213,59 @@ begin
nints := StrToInt(FreqSpecsFrm.NoInts.Text); nints := StrToInt(FreqSpecsFrm.NoInts.Text);
if nints > 200 then if nints > 200 then
nints := 200; nints := 200;
*)
{Now, get frequency of cases in each interval } nInts := NoIntervalsEdit.Value;
for j := 1 to nints+1 do incrSize := (max - min) / nInts;
freq[j-1] := 0;
Ncases := 0; SetLength(freq, nInts);
SetLength(XValue, nInts);
SetLength(XLabels, nInts);
{ Get frequency of cases in each interval }
nCases := 0;
for j := 1 to NoCases do for j := 1 to NoCases do
begin begin
if not ValidValue(j,col) then continue; if not ValidValue(j, col) then continue;
inc(Ncases); inc(nCases);
value := StrToFloat(OS3MainFrm.DataGrid.Cells[col,j]); value := StrToFloat(OS3MainFrm.DataGrid.Cells[col, j]);
for k := 1 to nints do for k := 0 to nints-1 do
begin if (value >= min + k * incrSize) and (value < min + ((k+1) * incrSize)) then
if (value >= min + ((k-1) * incrsize)) and freq[k] := freq[k] + 1.0;
(value < min + (k * incrsize)) then freq[k-1] := freq[k-1] + 1;
end; end;
end; for j := 0 to nInts-1 do
for j := 1 to nints+1 do
XValue[j-1] := min + (j-1) * incrsize;
{ get cumulative frequencies and percents to midpoints }
cumfreq[0] := freq[0];
pcnt[0] := freq[0] / Ncases;
cumpcnt[0] := cumfreq[0] / Ncases;
pcntilerank[0] := (freq[0] / 2.0) / Ncases;
for k := 2 to nints do
begin begin
cumfreq[k-1] := cumfreq[k-2] + freq[k-1]; XValue[j] := min + j * incrSize;
pcnt[k-1] := freq[k-1] / Ncases; XLabels[j] := Format('%.2f'+LineEnding+'to'+LineEnding+'%.2f', [XValue[j], XValue[j] + incrSize]);
cumpcnt[k-1] := cumfreq[k-1] / Ncases;
pcntilerank[k-1] := (cumfreq[k-2] + freq[k-1] / 2.0) / Ncases;
end; end;
{ Now, print results to report } { Get cumulative frequencies and percents to midpoints }
cumFreq[0] := freq[0];
pcnt[0] := freq[0] / nCases;
cumPcnt[0] := cumFreq[0] / nCases;
pcntileRank[0] := (freq[0] * 0.5) / nCases;
for k := 1 to nInts - 1do
begin
cumfreq[k] := cumfreq[k-1] + freq[k];
pcnt[k] := freq[k] / nCases;
cumPcnt[k] := cumFreq[k] / nCases;
pcntileRank[k] := (cumFreq[k-1] + freq[k] * 0.5) / nCases;
end;
{ Print results to report }
lReport.Add(' FROM TO FREQ. PCNT CUM.FREQ. CUM.PCNT. %ILE RANK'); lReport.Add(' FROM TO FREQ. PCNT CUM.FREQ. CUM.PCNT. %ILE RANK');
lReport.Add(''); lReport.Add('');
for k := 1 to nints do for k := 0 to nInts - 1 do
lReport.Add('%8.2f%8.2f%8.0f%8.2f %8.2f %8.2f %8.2f', [ lReport.Add('%8.2f%8.2f%8.0f%8.2f %8.2f %8.2f %8.2f', [
min+(k-1)*incrsize, // from min + k*incrSize, // from
min+k*incrsize, // to min + (k+1)*incrSize, // to
freq[k-1], // freq freq[k], // freq
pcnt[k-1], // pcnt pcnt[k], // pcnt
cumfreq[k-1], // cum.freq. cumFreq[k], // cum.freq.
cumpcnt[k-1], // cum.pcnt. cumPcnt[k], // cum.pcnt.
pcntilerank[k-1] // %ile rank pcntileRank[k] // %ile rank
]); ]);
(*
{ Now, prepare plot values as indicated in options list } { Now, prepare plot values as indicated in options list }
if NormDist = false then if NormDist = false then
SetLength(GraphFrm.Ypoints,1,nints+1) SetLength(GraphFrm.Ypoints,1,nints+1)
@ -292,7 +276,7 @@ begin
begin begin
GraphFrm.Ypoints[0,k-1] := freq[k-1]; GraphFrm.Ypoints[0,k-1] := freq[k-1];
GraphFrm.Xpoints[0,k-1] := XValue[k-1]; GraphFrm.Xpoints[0,k-1] := XValue[k-1];
end; end; *)
// Create ND plot if checked. // Create ND plot if checked.
// BUT: Only 3D-vertical plots when normal curve is desired // BUT: Only 3D-vertical plots when normal curve is desired
@ -332,15 +316,20 @@ begin
zproplow := probz(zlow); zproplow := probz(zlow);
zprophi := probz(zhi); zprophi := probz(zhi);
zfreq := NoCases * abs(zprophi - zproplow); zfreq := NoCases * abs(zprophi - zproplow);
(* !!!!!!!!!!!!!!!!!!!
GraphFrm.Ypoints[1,k-1] := zfreq; GraphFrm.Ypoints[1,k-1] := zfreq;
lReport.Add(' %2d %6.2f', [k, GraphFrm.Ypoints[1,k-1]]); lReport.Add(' %2d %6.2f', [k, GraphFrm.Ypoints[1,k-1]]);
*)
end; end;
end; end;
// Show report in form // Show report in form
DisplayReport(lReport); FReportFrame.DisplayReport(lReport);
// Plot data // Plot data
PlotFreq(col, cellVal, xLabels, freq);
end;
(*
plottype := PlotOptionsGroup.ItemIndex + 1; plottype := PlotOptionsGroup.ItemIndex + 1;
if Histogram then if Histogram then
GraphFrm.barwideprop := 1.0 GraphFrm.barwideprop := 1.0
@ -370,18 +359,143 @@ begin
GraphFrm.Xpoints := nil; GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil; GraphFrm.Ypoints := nil;
end; // for novars list end; // for novars list
*)
{
for j := PageControl.PageCount-1 downto 1 do
begin
found := false;
for i := 0 to SelList.Count-1 do
if GetPageCaption(SelList.Items[i]) = PageControl.Pages[j].Caption then
begin
found := true;
break;
end;
if not found then
PageControl.Pages[j].Free;
end;
}
finally finally
lReport.Free; lReport.Free;
(*
XValue := nil; XValue := nil;
cumfreq := nil; cumfreq := nil;
pcntilerank := nil; pcntilerank := nil;
cumpcnt := nil; cumpcnt := nil;
pcnt := nil; pcnt := nil;
freq := nil; freq := nil;
*)
end; end;
end; end;
function TFreqFrm.CreateChartFrame(AColIndex: Integer; AVarName: String): TChartFrame;
var
sheetTitle: String;
tabSheet: TTabSheet;
i: Integer;
begin
sheetTitle := GetPageCaption(AVarName);
// Find existing sheet first.
for i := 1 to PageControl.PageCount-1 do
if PageControl.Pages[i].Caption = sheetTitle then begin
tabSheet := PageControl.Pages[i];
Result := tabSheet.Controls[0] as TChartFrame;
exit;
end;
// Not found: create new sheet ...
tabSheet := PageControl.AddTabSheet;
tabSheet.Caption := sheetTitle;
tabSheet.Tag := AColIndex;
// ... and add ChartFrame
Result := TChartFrame.Create(tabSheet);
Result.Parent := tabSheet;
Result.Align := alClient;
Result.Chart.Legend.Alignment := laBottomCenter;
Result.Chart.Legend.ColumnCount := 3;
Result.Chart.Legend.TextFormat := tfHTML;
Result.Chart.BottomAxis.Intervals.MaxLength := 80;
Result.Chart.BottomAxis.Intervals.MinLength := 30;
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 := BarTypeGroup.Top + BarTypeGroup.Height - Panel1.Top;
Panel1.Constraints.MinWidth := Label2.Width * 2 + AllBtn.Width + 2 * VarList.BorderSpacing.Right;
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
*)
Position := poMainFormCenter;
FAutoSized := true;
end;
procedure TFreqFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
if FreqSpecsFrm = nil then
Application.CreateForm(TFreqSpecsFrm, FreqSpecsFrm);
if GraphFrm = nil then
Application.CreateForm(TGraphFrm, GraphFrm);
InitForm(Self);
FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient;
Reset;
end;
function TFreqFrm.GetPageCaption(AVarName: String): String;
begin
Result := 'Plot of ' + AVarName;
end;
procedure TFreqFrm.InBtnClick(Sender: TObject);
var
i: integer;
begin
i := 0;
while i < VarList.Items.Count do
begin
if (VarList.Selected[i]) then
begin
SelList.Items.Add(VarList.Items[i]);
VarList.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
ClearTabs;
UpdateBtnStates;
end;
procedure TFreqFrm.SelListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
procedure TFreqFrm.OutBtnClick(Sender: TObject); procedure TFreqFrm.OutBtnClick(Sender: TObject);
var var
i: integer; i: integer;
@ -395,20 +509,75 @@ begin
SelList.Items.Delete(i); SelList.Items.Delete(i);
i := 0; i := 0;
end else end else
i := i + 1; inc(i);
end; end;
ClearTabs;
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TFreqFrm.PlotFreq(AColIndex: Integer; AVarName: String;
const xLabels: StrDyneVec; const Freq: DblDyneVec);
var
ser: TBarSeries;
chartFrame: TChartFrame;
begin
chartFrame := CreateChartFrame(AColIndex, AVarName);
chartFrame.Clear;
ser := chartFrame.PlotXY(ptVertBars, nil, Freq, xLabels, nil, '', clDefault) as TBarSeries;
ser.BarBrush.Color := DATA_COLORS[(AColIndex-1) mod Length(DATA_COLORS)];
if BarTypeGroup.ItemIndex = 1 then
begin
ser.BarWidthPercent := 100;
ser.BarPen.Color := ser.BarBrush.Color;
end;
chartFrame.Chart.Margins.Bottom := 0;
chartFrame.Chart.BottomAxis.Marks.Source := ser.Source;
chartFrame.Chart.BottomAxis.Marks.Style := smsLabel;
chartFrame.Chart.BottomAxis.Marks.Alignment := taCenter;
chartFrame.SetTitle('Frequency distribution');
chartFrame.SetXTitle(AVarName + ' categories');
chartFrame.SetYTitle('Frequency');
chartFrame.Chart.Legend.Visible := false;
end;
procedure TFreqFrm.PlotOptionsGroupSelectionChanged(Sender: TObject); procedure TFreqFrm.PlotOptionsGroupSelectionChanged(Sender: TObject);
begin begin
BarTypeGroup.Enabled := PlotOptionsGroup.ItemIndex in [0, 1, 8, 9]; // Bar series only BarTypeGroup.Enabled := PlotOptionsGroup.ItemIndex in [0, 1, 8, 9]; // Bar series only
end; end;
procedure TFreqFrm.Reset;
var
i: integer;
begin
VarList.Clear;
SelList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
BarTypeGroup.ItemIndex := 0;
PlotOptionsGroup.ItemIndex := 0;
NormPltChk.Checked := false;
ClearTabs;
UpdateBtnStates;
end;
procedure TFreqFrm.ResetBtnClick(Sender: TObject);
begin
Reset;
end;
procedure TFreqFrm.UpdateBtnStates; procedure TFreqFrm.UpdateBtnStates;
var var
lSelected: Boolean; lSelected: Boolean;
i: Integer; i: Integer;
chartFrame: TChartFrame;
begin begin
lSelected := false; lSelected := false;
for i := 0 to VarList.Items.Count-1 do for i := 0 to VarList.Items.Count-1 do
@ -429,15 +598,39 @@ begin
OutBtn.Enabled := lSelected; OutBtn.Enabled := lSelected;
AllBtn.Enabled := VarList.Items.Count > 0; AllBtn.Enabled := VarList.Items.Count > 0;
BarTypeGroup.Enabled := PlotOptionsGroup.ItemIndex in [0, 1, 8, 9]; // Bar series only
FReportFrame.UpdateBtnStates;
for i := 1 to PageControl.PageCount-1 do
begin
chartFrame := PageControl.Pages[i].Controls[0] as TChartFrame;
chartFrame.UpdateBtnStates;
end;
end; end;
procedure TFreqFrm.VarListDblClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
SelList.Items.Add(VarList.Items[index]);
VarList.Items.Delete(index);
ClearTabs;
UpdateBtnStates;
end;
end;
procedure TFreqFrm.VarListSelectionChange(Sender: TObject; User: boolean); procedure TFreqFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin begin
UpdateBtnStates; UpdateBtnStates;
end; end;
initialization
{$I frequnit.lrs}
end. end.

View File

@ -377,8 +377,7 @@ procedure TPlotXYFrm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
Width := Scale96ToFont(DEFAULT_WIDTH); InitForm(self);
Height := Scale96ToFont(DEFAULT_HEIGHT);
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;

View File

@ -263,8 +263,7 @@ procedure TXvsMultYForm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
Width := Scale96ToFont(DEFAULT_WIDTH); InitForm(self);
Height := Scale96ToFont(DEFAULT_HEIGHT);
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;

View File

@ -171,8 +171,7 @@ procedure TBasicSPCForm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
Width := Scale96ToFont(DEFAULT_WIDTH); InitForm(Self);
Height := Scale96ToFont(DEFAULT_HEIGHT);
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;

View File

@ -452,6 +452,8 @@ end;
procedure TDistribFrm.FormCreate(Sender: TObject); procedure TDistribFrm.FormCreate(Sender: TObject);
begin begin
InitForm(self);
FChartFrame := TChartFrame.Create(self); FChartFrame := TChartFrame.Create(self);
FChartFrame.Parent := ChartPanel; FChartFrame.Parent := ChartPanel;
FChartFrame.Align := alClient; FChartFrame.Align := alClient;
@ -460,9 +462,8 @@ begin
FChartFrame.Chart.Legend.TextFormat := tfHTML; FChartFrame.Chart.Legend.TextFormat := tfHTML;
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80; FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30; FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
FChartFrame.ChartToolbar.Transparent := false;
FChartFrame.ChartToolbar.Color := clForm;
InitToolbar(FChartFrame.ChartToolbar, tpTop);
tbErase := TToolButton.Create(self); tbErase := TToolButton.Create(self);
tbErase.ImageIndex := 6; tbErase.ImageIndex := 6;
tbErase.Caption := 'Erase'; tbErase.Caption := 'Erase';

View File

@ -5,12 +5,14 @@ unit Utils;
interface interface
uses uses
Classes, SysUtils, Graphics, Controls, StdCtrls, ComCtrls, Dialogs, Classes, SysUtils, Graphics, Controls, StdCtrls, ComCtrls, Dialogs, Forms,
Globals; Globals;
type type
TToolbarPosition = (tpTop, tpLeft, tpRight); TToolbarPosition = (tpTop, tpLeft, tpRight);
procedure InitForm(AForm: TForm);
procedure AddButtonToToolbar(AToolButton: TToolButton; AToolBar: TToolBar); procedure AddButtonToToolbar(AToolButton: TToolButton; AToolBar: TToolBar);
procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition); procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition);
@ -48,6 +50,13 @@ begin
end; end;
procedure InitForm(AForm: TForm);
begin
AForm.Width := AForm.Scale96ToFont(DEFAULT_WIDTH);
AForm.Height := AForm.Scale96ToFont(DEFAULT_HEIGHT);
end;
procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition); procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition);
begin begin
// AToolbar.Transparent := false; // AToolbar.Transparent := false;