You've already forked lazarus-ccr
LazStats: Integrate report and chart into form of BubblePlotUnit.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7685 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -3,14 +3,13 @@
|
||||
unit BubblePlotUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$I ../../../LazStats.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Clipbrd, Buttons, ExtCtrls, Math,
|
||||
MainUnit, Globals, DataProcs, DictionaryUnit, ContextHelpUnit;
|
||||
StdCtrls, Clipbrd, Buttons, ExtCtrls, ComCtrls, Math,
|
||||
MainUnit, Globals, DataProcs, DictionaryUnit, ContextHelpUnit, ChartFrameUnit, ReportFrameUnit;
|
||||
|
||||
|
||||
type
|
||||
@ -20,7 +19,12 @@ type
|
||||
TBubbleForm = class(TForm)
|
||||
Bevel1: TBevel;
|
||||
HelpBtn: TButton;
|
||||
PageControl: TPageControl;
|
||||
Panel1: TPanel;
|
||||
ParamsPanel: TPanel;
|
||||
ParamsSplitter: TSplitter;
|
||||
ReportPage: TTabSheet;
|
||||
ChartPage: TTabSheet;
|
||||
TransformChk: TCheckBox;
|
||||
YLabelEdit: TEdit;
|
||||
Label8: TLabel;
|
||||
@ -59,6 +63,7 @@ type
|
||||
procedure CloseBtnClick(Sender: TObject);
|
||||
procedure SizeInBtnClick(Sender: TObject);
|
||||
procedure SizeOutBtnClick(Sender: TObject);
|
||||
procedure VarListDblClick(Sender: TObject);
|
||||
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
|
||||
procedure XInBtnClick(Sender: TObject);
|
||||
procedure XOutBtnClick(Sender: TObject);
|
||||
@ -68,9 +73,9 @@ type
|
||||
{ private declarations }
|
||||
BubbleCol, XCol, YCol, SizeCol: Integer;
|
||||
FAutoSized: boolean;
|
||||
procedure PlotBubbles(
|
||||
{$IFNDEF USE_TACHART}NoReplications: Integer; XMax, XMin: Integer;{$ENDIF}
|
||||
YMax, YMin, BubMax, BubMin: Double);
|
||||
FReportFrame: TReportFrame;
|
||||
FChartFrame: TChartFrame;
|
||||
procedure PlotBubbles(YMax, YMin, BubMax, BubMin: Double);
|
||||
procedure UpdateBtnStates;
|
||||
public
|
||||
{ public declarations }
|
||||
@ -85,13 +90,8 @@ implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
{$IFDEF USE_TACHART}
|
||||
TAMultiSeries,
|
||||
ChartUnit,
|
||||
{$ELSE}
|
||||
BlankFrmUnit,
|
||||
{$ENDIF}
|
||||
OutputUnit;
|
||||
TAChartUtils, TALegend, TAMultiSeries,
|
||||
Utils;
|
||||
|
||||
{ TBubbleForm }
|
||||
|
||||
@ -255,12 +255,10 @@ begin
|
||||
lReport.Add(' Object %5d Mean: %8.3f', [i+1, CaseSizeMeans[i]]);
|
||||
|
||||
// Show the report
|
||||
if DisplayReport(lReport) then
|
||||
// Plot the bubbles
|
||||
PlotBubbles(
|
||||
{$IFNDEF USE_TACHART}NoReplications, XMax, XMin, {$ENDIF}
|
||||
YMax, YMin, BubMax, BubMin
|
||||
);
|
||||
FReportFrame.DisplayReport(lReport);
|
||||
|
||||
// Plot the bubbles
|
||||
PlotBubbles(YMax, YMin, BubMax, BubMin);
|
||||
|
||||
finally
|
||||
lReport.Free;
|
||||
@ -380,10 +378,17 @@ begin
|
||||
CloseBtn.Constraints.MinWidth := w;
|
||||
|
||||
Panel1.Constraints.MinHeight := SizeOutBtn.Top + SizeOutBtn.Height;
|
||||
Panel1.Constraints.MinWidth := 2*Label2.Width + IDInBtn.Width + 2*VarList.BorderSpacing.Right;
|
||||
ParamsPanel.Constraints.MinHeight := Panel1.Height + Panel1.BorderSpacing.Bottom +
|
||||
3*TitleEdit.Height + 2*XLabelEdit.BorderSpacing.Top +
|
||||
TransformChk.BorderSpacing.Top + TransformChk.Height + TransformChk.BorderSpacing.Bottom +
|
||||
Bevel1.Height +
|
||||
CloseBtn.Height + CloseBtn.BorderSpacing.Top;
|
||||
ParamsPanel.Constraints.MinWidth := Max(TransformChk.Width, 4*w + 3*HelpBtn.BorderSpacing.Right);
|
||||
|
||||
Constraints.MinWidth := Width;
|
||||
Constraints.MinHeight := Height;
|
||||
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 200;
|
||||
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + 2*ParamsPanel.BorderSpacing.Top;
|
||||
if Height < Constraints.MinHeight then Height := 1; // enforce auto-sizing
|
||||
if Width < Constraints.MiNWidth then Width := 1;
|
||||
|
||||
Position := poDesigned;
|
||||
FAutoSized := True;
|
||||
@ -394,6 +399,17 @@ procedure TBubbleForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Assert(OS3MainFrm <> nil);
|
||||
if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm);
|
||||
|
||||
FReportFrame := TReportFrame.Create(self);
|
||||
FReportFrame.Parent := ReportPage;
|
||||
FReportFrame.Align := alClient;
|
||||
|
||||
FChartFrame := TChartFrame.Create(self);
|
||||
FChartFrame.Parent := ChartPage;
|
||||
FChartFrame.Align := alClient;
|
||||
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
|
||||
FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
|
||||
|
||||
Reset;
|
||||
end;
|
||||
|
||||
@ -433,7 +449,6 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{$IFDEF USE_TACHART}
|
||||
procedure TBubbleForm.PlotBubbles(YMax, YMin, BubMax, BubMin: Double);
|
||||
var
|
||||
ser: TBubbleSeries;
|
||||
@ -447,22 +462,19 @@ begin
|
||||
yRange := YMax - YMin;
|
||||
BubRange := BubMax - BubMin;
|
||||
|
||||
if ChartForm = nil then
|
||||
ChartForm := TChartForm.Create(Application)
|
||||
else
|
||||
ChartForm.Clear;
|
||||
FChartFrame.Clear;
|
||||
|
||||
// Titles
|
||||
ChartForm.Caption := 'Bubble Plot of ' + OS3MainFrm.FileNameEdit.Text + LineEnding + TitleEdit.Text;
|
||||
ChartForm.SetTitle(TitleEdit.Text);
|
||||
FChartFrame.Caption := 'Bubble Plot of ' + OS3MainFrm.FileNameEdit.Text + LineEnding + TitleEdit.Text;
|
||||
FChartFrame.SetTitle(TitleEdit.Text);
|
||||
if XLabelEdit.Text <> '' then
|
||||
ChartForm.SetXTitle(XLabelEdit.Text)
|
||||
FChartFrame.SetXTitle(XLabelEdit.Text)
|
||||
else
|
||||
ChartForm.SetXTitle(XEdit.Text);
|
||||
FChartFrame.SetXTitle(XEdit.Text);
|
||||
if YLabelEdit.Text <> '' then
|
||||
ChartForm.SetYTitle(YLabelEdit.Text)
|
||||
FChartFrame.SetYTitle(YLabelEdit.Text)
|
||||
else
|
||||
ChartForm.SetYTitle(YEdit.Text);
|
||||
FChartFrame.SetYTitle(YEdit.Text);
|
||||
|
||||
// Collect bubble IDs and create a bubble series for each unique ID.
|
||||
bubbleIDs := TStringList.Create;
|
||||
@ -475,12 +487,12 @@ begin
|
||||
end;
|
||||
for i := 0 to bubbleIDs.Count-1 do
|
||||
begin
|
||||
ser := TBubbleSeries.Create(ChartForm);
|
||||
ser := TBubbleSeries.Create(FChartFrame.Chart);
|
||||
ser.BubbleBrush.Color := DATA_COLORS[i mod Length(DATA_COLORS)];
|
||||
ser.BubbleRadiusUnits := bruY;
|
||||
ser.Title := bubbleIDs[i];
|
||||
ser.Tag := StrToInt(bubbleIDs[i]);
|
||||
ChartForm.Chart.AddSeries(ser);
|
||||
FChartFrame.Chart.AddSeries(ser);
|
||||
end;
|
||||
finally
|
||||
bubbleIDs.Free;
|
||||
@ -489,11 +501,11 @@ begin
|
||||
for i := 1 to NoCases do begin
|
||||
id := StrToInt(OS3MainFrm.DataGrid.Cells[BubbleCol, i]);
|
||||
// Find the series having this ID
|
||||
for j := 0 to ChartForm.Chart.SeriesCount-1 do
|
||||
if (ChartForm.Chart.Series[j] is TBubbleSeries) and
|
||||
(TBubbleSeries(ChartForm.Chart.Series[j]).Tag = id) then
|
||||
for j := 0 to FChartFrame.Chart.SeriesCount-1 do
|
||||
if (FChartFrame.Chart.Series[j] is TBubbleSeries) and
|
||||
(TBubbleSeries(FChartFrame.Chart.Series[j]).Tag = id) then
|
||||
begin
|
||||
ser := TBubbleSeries(ChartForm.Chart.Series[j]);
|
||||
ser := TBubbleSeries(FChartFrame.Chart.Series[j]);
|
||||
break;
|
||||
end;
|
||||
|
||||
@ -507,113 +519,8 @@ begin
|
||||
ser.AddXY(xValue, yValue, sizeValue);
|
||||
end;
|
||||
|
||||
ChartForm.Chart.Legend.Visible := true;
|
||||
ChartForm.Show;
|
||||
FChartFrame.Chart.Legend.Visible := true;
|
||||
end;
|
||||
{$ELSE}
|
||||
procedure TBubbleForm.PlotBubbles(NoReplications: Integer;
|
||||
XMax, XMin: Integer; YMax, YMin, BubMax, BubMin: Double);
|
||||
var
|
||||
i, j: Integer;
|
||||
XLabel, YLabel, Title, valStr, aString: String;
|
||||
ImageWide, ImageHi, Xstart, Xend, Ystart, Yend, Yincr: integer;
|
||||
LabelWide, TextHi, Xpos: Integer;
|
||||
BubColor, place: integer;
|
||||
X1, Y1, X2, Y2: integer;
|
||||
dx, dy: Integer;
|
||||
XRange, XStep: Integer;
|
||||
YRange, YStep, BubRange: Double;
|
||||
ratio, value: Double;
|
||||
intCell: Integer;
|
||||
xValue, cellvalue: Double;
|
||||
yProp: Integer;
|
||||
begin
|
||||
if BlankFrm = nil then
|
||||
BlankFrm := TBlankFrm.Create(Application);
|
||||
|
||||
XRange := Xmax - Xmin;
|
||||
XStep := XRange div (NoReplications - 1);
|
||||
YRange := Ymax - Ymin;
|
||||
YStep := Yrange / 10;
|
||||
BubRange := BubMax - BubMin;
|
||||
|
||||
BlankFrm.Show;
|
||||
BlankFrm.Caption := 'BUBBLE PLOT of ' + OS3MainFrm.FileNameEdit.Text;
|
||||
Xlabel := XlabelEdit.Text;
|
||||
Ylabel := YlabelEdit.Text;
|
||||
Title := TitleEdit.Text;
|
||||
ImageHi := BlankFrm.Image1.Height;
|
||||
ImageWide := BlankFrm.Image1.Width;
|
||||
Xstart := ImageWide div 10;
|
||||
Xend := (ImageWide * 9) div 10;
|
||||
Ystart := ImageHi div 10;
|
||||
Yend := (ImageHi * 8) div 10;
|
||||
BlankFrm.Image1.Canvas.Pen.Color := clBlack;
|
||||
BlankFrm.Image1.Canvas.Brush.Color := clWhite;
|
||||
BlankFrm.Image1.Canvas.Rectangle(0,0,ImageWide,ImageHi);
|
||||
BlankFrm.Image1.Canvas.FloodFill(0,0,clWhite,fsBorder);
|
||||
BlankFrm.Image1.Canvas.TextOut(Xstart-10,Ystart-30,Ylabel);
|
||||
LabelWide := BlankFrm.Image1.Canvas.TextWidth(Xlabel);
|
||||
BlankFrm.Image1.Canvas.TextOut((Xend-Xstart) div 2 - LabelWide,Yend + 40,Xlabel);
|
||||
LabelWide := BlankFrm.Image1.Canvas.TextWidth(Title);
|
||||
BlankFrm.Image1.Canvas.TextOut((Xend-Xstart) div 2 - LabelWide div 2, Ystart - 40,Title);
|
||||
|
||||
// draw axis lines
|
||||
BlankFrm.Image1.Canvas.MoveTo(Xstart,Yend);
|
||||
BlankFrm.Image1.Canvas.LineTo(Xend,Yend);
|
||||
BlankFrm.Image1.Canvas.MoveTo(Xstart,Yend);
|
||||
BlankFrm.Image1.Canvas.LineTo(Xstart,Ystart);
|
||||
|
||||
// create y axis values
|
||||
Yincr := (Yend - Ystart) div 10;
|
||||
for i := 0 to 10 do // print Y axis values
|
||||
begin
|
||||
place := Yend - Yincr * i;
|
||||
value := Ymin + Ystep * i;
|
||||
valStr := Format('%.2f', [value]);
|
||||
TextHi := BlankFrm.Image1.Canvas.TextHeight(valStr);
|
||||
BlankFrm.Image1.Canvas.TextOut(Xstart-30,place-TextHi, valStr);
|
||||
end;
|
||||
|
||||
// create x axis values
|
||||
for i := 1 to NoReplications do // print x axis
|
||||
begin
|
||||
value := Xmin + ((i-1) * Xstep);
|
||||
ratio := i / NoReplications;
|
||||
Xpos := round(ratio * (Xend - Xstart));
|
||||
valStr := Format('%.0f',[value]);
|
||||
BlankFrm.Image1.Canvas.TextOut(Xpos,Yend + 20, valStr);
|
||||
end;
|
||||
|
||||
// Plot the bubbles
|
||||
for i := 1 to NoCases do
|
||||
begin
|
||||
intcell := StrToInt(OS3MainFrm.DataGrid.Cells[BubbleCol,i]);
|
||||
xvalue := StrToFloat(OS3MainFrm.DataGrid.Cells[XCol,i]);
|
||||
cellvalue := StrToFloat(OS3MainFrm.DataGrid.Cells[YCol,i]);
|
||||
yprop := Yend - round(((cellvalue-Ymin) / Yrange) * (Yend - Ystart));
|
||||
cellvalue := StrToFloat(OS3MainFrm.DataGrid.Cells[SizeCol,i]);
|
||||
astring := Trim(OS3MainFrm.DataGrid.Cells[BubbleCol,i]);
|
||||
cellvalue := ((cellvalue - BubMin) / BubRange) * 20;
|
||||
cellvalue := cellvalue + 10;
|
||||
ratio := ((xvalue - Xmin) / Xstep) + 1;
|
||||
ratio := (ratio / noreplications) * (Xend - Xstart);
|
||||
Xpos := ceil(ratio);
|
||||
BubColor := intcell - 1;
|
||||
while (Bubcolor > 11) do Bubcolor := 12 - Bubcolor;
|
||||
BlankFrm.Image1.Canvas.Brush.Color := DATA_COLORS[Bubcolor];
|
||||
X1 := Xpos - ceil(cellvalue);
|
||||
Y1 := yprop - ceil(cellvalue);
|
||||
X2 := Xpos + ceil(cellvalue);
|
||||
Y2 := yprop + ceil(cellvalue);
|
||||
BlankFrm.Image1.Canvas.Ellipse(X1,Y1,X2,Y2);
|
||||
BlankFrm.Image1.Canvas.Brush.Color := clWhite;
|
||||
dx := BlankFrm.Image1.Canvas.TextWidth(astring) div 2;
|
||||
dy := BlankFrm.Image1.Canvas.TextHeight(astring) div 2;
|
||||
BlankFrm.Image1.Canvas.TextOut(Xpos-dx, yprop-dy, astring);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
procedure TBubbleForm.Reset;
|
||||
@ -668,6 +575,26 @@ begin
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
|
||||
procedure TBubbleForm.VarListDblClick(Sender: TObject);
|
||||
var
|
||||
index: integer;
|
||||
begin
|
||||
index := VarList.ItemIndex;
|
||||
if index > -1 then
|
||||
begin
|
||||
if BubbleEdit.Text = '' then
|
||||
BubbleEdit.Text := VarList.Items[index]
|
||||
else if XEdit.Text = '' then
|
||||
XEdit.Text := VarList.Items[index]
|
||||
else if YEdit.Text = '' then
|
||||
YEdit.Text := VarList.Items[index]
|
||||
else
|
||||
SizeEdit.Text := VarList.Items[index];
|
||||
VarList.Items.Delete(index);
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TBubbleForm.UpdateBtnStates;
|
||||
var
|
||||
|
Reference in New Issue
Block a user