Files
lazarus-ccr/applications/lazstats/source_orig/plotxyunit.pas

693 lines
24 KiB
ObjectPascal
Raw Normal View History

unit PlotXYUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, MainUnit, Globals, Math, OutPutUnit,
FunctionsLib, DataProcs, BlankFrmUnit, Printers;
type
{ TPlotXYFrm }
TPlotXYFrm = class(TForm)
ConfEdit: TEdit;
Label4: TLabel;
ResetBtn: TButton;
CancelBtn: TButton;
ComputeBtn: TButton;
ReturnBtn: TButton;
DescChk: TCheckBox;
LineChk: TCheckBox;
MeansChk: TCheckBox;
ConfChk: TCheckBox;
PrintChk: TCheckBox;
GroupBox1: TGroupBox;
YEdit: TEdit;
Label3: TLabel;
XEdit: TEdit;
Label2: TLabel;
XinBtn: TBitBtn;
XOutBtn: TBitBtn;
YInBtn: TBitBtn;
YOutBtn: TBitBtn;
Label1: TLabel;
VarList: TListBox;
procedure CancelBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure ReturnBtnClick(Sender: TObject);
procedure XinBtnClick(Sender: TObject);
procedure XOutBtnClick(Sender: TObject);
procedure YInBtnClick(Sender: TObject);
procedure YOutBtnClick(Sender: TObject);
private
{ private declarations }
procedure plotxy(VAR Xpoints : DblDyneVec;
VAR Ypoints : DblDyneVec;
VAR UpConf : DblDyneVec;
VAR LowConf : DblDyneVec;
ConfBand : double;
Xmean, Ymean , R : double;
Slope, Intercept : double;
Xmax, Xmin, Ymax, Ymin : double;
N : integer);
procedure pplotxy(VAR Xpoints : DblDyneVec;
VAR Ypoints : DblDyneVec;
VAR UpConf : DblDyneVec;
VAR LowConf : DblDyneVec;
ConfBand : double;
Xmean, Ymean , R : double;
Slope, Intercept : double;
Xmax, Xmin, Ymax, Ymin : double;
N : integer);
public
{ public declarations }
end;
var
PlotXYFrm: TPlotXYFrm;
implementation
{ TPlotXYFrm }
procedure TPlotXYFrm.ResetBtnClick(Sender: TObject);
var i : integer;
begin
XEdit.Text := '';
YEdit.Text := '';
ConfEdit.Text := '95.0';
DescChk.Checked := false;
LineChk.Checked := false;
MeansChk.Checked := false;
ConfChk.Checked := false;
PrintChk.Checked := false;
XInBtn.Visible := true;
XOutBtn.Visible := false;
YInBtn.Visible := true;
YOutBtn.Visible := false;
VarList.Items.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end;
procedure TPlotXYFrm.ReturnBtnClick(Sender: TObject);
begin
PlotXYFrm.Hide;
end;
procedure TPlotXYFrm.XinBtnClick(Sender: TObject);
var index : integer;
begin
index := VarList.ItemIndex;
XEdit.Text := VarList.Items.Strings[index];
VarList.Items.Delete(index);
XInBtn.Visible := false;
XOutBtn.Visible := true;
end;
procedure TPlotXYFrm.XOutBtnClick(Sender: TObject);
begin
VarList.Items.Add(XEdit.Text);
XEdit.Text := '';
XInBtn.Visible := true;
XOutBtn.Visible := false;
end;
procedure TPlotXYFrm.YInBtnClick(Sender: TObject);
var index : integer;
begin
index := VarList.ItemIndex;
YEdit.Text := VarList.Items.Strings[index];
VarList.Items.Delete(index);
YInBtn.Visible := false;
YOutBtn.Visible := true;
end;
procedure TPlotXYFrm.YOutBtnClick(Sender: TObject);
begin
VarList.Items.Add(YEdit.Text);
YEdit.Text := '';
YInBtn.Visible := true;
YOutBtn.Visible := false;
end;
procedure TPlotXYFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TPlotXYFrm.CancelBtnClick(Sender: TObject);
begin
PlotXYFrm.Hide;
end;
procedure TPlotXYFrm.ComputeBtnClick(Sender: TObject);
var
Xmin, Xmax, Ymin, Ymax, SSx, t, DF : double;
Xmean, Ymean, Xvariance, Yvariance, Xstddev, Ystddev, ConfBand : double;
X, Y, R, temp, SEPred, Slope, Intercept, predicted, sedata : double;
i, j : integer;
Xcol, Ycol, N, NoSelected : integer;
Xpoints : DblDyneVec;
Ypoints : DblDyneVec;
UpConf : DblDyneVec;
lowConf : DblDyneVec;
cellstring, outline : string;
ColNoSelected : IntDyneVec;
begin
SetLength(Xpoints,NoCases + 1);
SetLength(Ypoints,NoCases + 1);
SetLength(UpConf,NoCases + 1);
SetLength(lowConf,NoCases + 1);
SetLength(ColNoSelected,NoVariables);
Xcol := 0;
Ycol := 0;
for i := 1 to Novariables do
begin
cellstring := OS3MainFrm.DataGrid.Cells[i,0];
if cellstring = XEdit.Text then Xcol := i;
if cellstring = YEdit.Text then Ycol := i;
end;
NoSelected := 2;
ColNoSelected[0] := Xcol;
ColNoSelected[1] := Ycol;
N := 0;
Xmax := -1.0e20;
Xmin := 1.0e20;
Ymax := -1.0e20;
Ymin := 1.0e20;
Xmean := 0.0;
Ymean := 0.0;
Xvariance := 0.0;
Yvariance := 0.0;
R := 0.0;
for i := 1 to NoCases do
begin
if Not GoodRecord(i,NoSelected,ColNoSelected) then continue;
N := N + 1;
X := StrToFloat(OS3MainFrm.DataGrid.Cells[Xcol,i]);
Y := StrToFloat(OS3MainFrm.DataGrid.Cells[Ycol,i]);
Xpoints[N] := X;
Ypoints[N] := Y;
if X > Xmax then Xmax := X;
if X < Xmin then Xmin := X;
if Y > Ymax then Ymax := Y;
if Y < Ymin then Ymin := Y;
Xmean := Xmean + X;
Ymean := Ymean + Y;
Xvariance := Xvariance + (X * X);
Yvariance := Yvariance + (Y * Y);
R := R + (X * Y);
end;
// sort on X
for i := 1 to N - 1 do
begin
for j := i + 1 to N do
begin
if Xpoints[i] > Xpoints[j] then //swap
begin
temp := Xpoints[i];
Xpoints[i] := Xpoints[j];
Xpoints[j] := temp;
temp := Ypoints[i];
Ypoints[i] := Ypoints[j];
Ypoints[j] := temp;
end;
end;
end;
// calculate statistics
Xvariance := Xvariance - (Xmean * Xmean / N);
SSx := Xvariance;
Xvariance := Xvariance / (N - 1);
Xstddev := sqrt(Xvariance);
Yvariance := Yvariance - (Ymean * Ymean / N);
Yvariance := Yvariance / (N - 1);
Ystddev := sqrt(Yvariance);
R := R - (Xmean * Ymean / N);
R := R / (N - 1);
R := R / (Xstddev * Ystddev);
SEPred := sqrt(1.0 - (R * R)) * Ystddev;
SEPred := SEPred * sqrt((N - 1) / (N - 2));
Xmean := Xmean / N;
Ymean := Ymean / N;
Slope := R * Ystddev / Xstddev;
Intercept := Ymean - Slope * Xmean;
// Now, print the descriptive statistics if requested
if DescChk.Checked then
begin
OutPutFrm.RichEdit.Lines.Add('X versus Y Plot');
OutPutFrm.RichEdit.Lines.Add('');
outline := format('X = %s, Y = %s from file: %s',[Xedit.Text,
YEdit.Text,OS3MainFrm.FileNameEdit.Text]);
OutPutFrm.RichEdit.Lines.Add(outline);
OutPutFrm.RichEdit.Lines.Add('');
OutPutFrm.RichEdit.Lines.Add('Variable Mean Variance Std.Dev.');
outline := format('%-10s%8.2f %8.2f %8.2f',
[XEdit.Text,Xmean,Xvariance,Xstddev]);
OutPutFrm.RichEdit.Lines.Add(outline);
outline := format('%-10s%8.2f %8.2f %8.2f',
[YEdit.Text,Ymean,Yvariance,Ystddev]);
OutPutFrm.RichEdit.Lines.Add(outline);
outline := format('Correlation = %6.4f, Slope = %8.2f, Intercept = %8.2f',
[R, Slope, Intercept]);
OutPutFrm.RichEdit.Lines.Add(outline);
outline := format('Standard Error of Estimate = %8.2f',[SEPred]);
OutPutFrm.RichEdit.Lines.Add(outline);
outline := format('Number of good cases = %d',[N]);
OutPutFrm.RichEdit.Lines.Add(outline);
OutPutFrm.ShowModal;
end;
// get upper and lower confidence points for each X value
if ConfChk.Checked then
begin
ConfBand := StrToFloat(ConfEdit.Text) / 100.0;
DF := N - 2;
t := inverset(ConfBand,DF);
for i := 1 to N do
begin
X := Xpoints[i];
predicted := slope * X + intercept;
sedata := SEPred * sqrt(1.0 + (1.0 / N) + (sqr(X - Xmean) / SSx));
UpConf[i] := predicted + (t * sedata);
lowConf[i] := predicted - (t * sedata);
if UpConf[i] > Ymax then Ymax := UpConf[i];
if lowConf[i] < Ymin then Ymin := lowConf[i];
end;
end
else ConfBand := 0.0;
// plot the values (and optional line and confidence band if elected)
plotxy(Xpoints, Ypoints, UpConf, LowConf, ConfBand, Xmean, Ymean, R,
Slope, Intercept, Xmax, Xmin, Ymax, Ymin, N);
// print the same if elected
if PrintChk.Checked then
pplotxy(Xpoints, Ypoints, UpConf, LowConf, ConfBand, Xmean, Ymean,
R, Slope, Intercept, Xmax, Xmin, Ymax, Ymin, N);
// cleanup
ColNoSelected := nil;
lowConf := nil;
UpConf := nil;
Ypoints := nil;
Xpoints := nil;
end;
procedure TPlotXYFrm.plotxy(VAR Xpoints : DblDyneVec;
VAR Ypoints : DblDyneVec;
VAR UpConf : DblDyneVec;
VAR LowConf : DblDyneVec;
ConfBand : double;
Xmean, Ymean , R : double;
Slope, Intercept : double;
Xmax, Xmin, Ymax, Ymin : double;
N : integer);
var
i, xpos, ypos, hleft, hright, vtop, vbottom, imagewide : integer;
vhi, hwide, offset, strhi, imagehi : integer;
maxval, minval, valincr, Yvalue, Xvalue : double;
Title : string;
begin
BlankFrm.Image1.Canvas.Clear;
BlankFrm.Show;
Title := 'X versus Y PLOT Using File: ' + OS3MainFrm.FileNameEdit.Text;
BlankFrm.Caption := Title;
imagewide := BlankFrm.Image1.Width;
imagehi := BlankFrm.Image1.Height;
vtop := 20;
vbottom := round(imagehi) - 80;
vhi := vbottom - vtop;
hleft := 100;
hright := imagewide - 80;
hwide := hright - hleft;
BlankFrm.Image1.Canvas.Pen.Color := clBlack;
BlankFrm.Image1.Canvas.Brush.Color := clWhite;
// Draw chart border
BlankFrm.Image1.Canvas.Rectangle(0,0,imagewide,imagehi);
// draw Means
if MeansChk.Checked then
begin
ypos := round(vhi * ( (Ymax - Ymean) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
xpos := hright;
BlankFrm.Image1.Canvas.Pen.Color := clGreen;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
Title := 'MEAN ';
Title := Title + YEdit.Text;
strhi := BlankFrm.Image1.Canvas.TextHeight(Title);
ypos := ypos - strhi div 2;
BlankFrm.Image1.Canvas.Brush.Color := clWhite;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,Title);
xpos := round(hwide * ( (Xmean - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
ypos := vtop;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
ypos := vbottom;
BlankFrm.Image1.Canvas.Pen.Color := clGreen;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
Title := 'MEAN ';
Title := Title + XEdit.Text;
strhi := BlankFrm.Image1.Canvas.TextWidth(Title);
xpos := xpos - strhi div 2;
ypos := vtop - BlankFrm.Image1.Canvas.TextHeight(Title);
BlankFrm.Image1.Canvas.Brush.Color := clWhite;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,Title);
end;
// draw slope line
if LineChk.Checked then
begin
BlankFrm.Image1.Canvas.Pen.Color := clBlack;
Yvalue := (Xpoints[1] * slope) + intercept; // predicted score
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1]- Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
Yvalue := (Xpoints[N] * slope) + intercept; // predicted score
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[N] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
end;
// draw horizontal axis
BlankFrm.Image1.Canvas.Pen.Color := clBlack;
BlankFrm.Image1.Canvas.MoveTo(hleft,vbottom);
BlankFrm.Image1.Canvas.LineTo(hright,vbottom);
valincr := (Xmax - Xmin) / 10.0;
for i := 1 to 11 do
begin
ypos := vbottom;
Xvalue := Xmin + valincr * (i - 1);
xpos := round(hwide * ((Xvalue - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
ypos := ypos + 10;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
Title := format('%6.2f',[Xvalue]);
offset := BlankFrm.Image1.Canvas.TextWidth(Title) div 2;
xpos := xpos - offset;
BlankFrm.Image1.Canvas.Pen.Color := clBlack;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,Title);
end;
xpos := hleft + (hwide div 2) - (BlankFrm.Image1.Canvas.TextWidth(XEdit.Text) div 2);
ypos := vbottom + 20;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,XEdit.Text);
Title := format('R(X,Y) = %5.3f, Slope = %6.2f, Intercept = %6.2f',
[R,Slope,Intercept]);
xpos := hleft + (hwide div 2) - (BlankFrm.Image1.Canvas.TextWidth(Title) div 2);
ypos := ypos + 15;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,Title);
// Draw vertical axis
Title := YEdit.Text;
xpos := hleft - BlankFrm.Image1.Canvas.TextWidth(Title) div 2;
ypos := vtop - BlankFrm.Image1.Canvas.TextHeight(Title);
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,YEdit.Text);
xpos := hleft;
ypos := vtop;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
ypos := vbottom;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
valincr := (Ymax - Ymin) / 10.0;
for i := 1 to 11 do
begin
Title := format('%8.2f',[Ymax - ((i-1)*valincr)]);
strhi := BlankFrm.Image1.Canvas.TextHeight(Title);
xpos := 10;
Yvalue := Ymax - (valincr * (i-1));
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop - strhi div 2;
BlankFrm.Image1.Canvas.TextOut(xpos,ypos,Title);
xpos := hleft;
ypos := ypos + strhi div 2;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
xpos := hleft - 10;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
end;
// draw points for x and y pairs
for i := 1 to N do
begin
ypos := round(vhi * ( (Ymax - Ypoints[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.Brush.Color := clNavy;
BlankFrm.Image1.Canvas.Brush.Style := bsSolid;
BlankFrm.Image1.Canvas.Pen.Color := clNavy;
BlankFrm.Image1.Canvas.Ellipse(xpos,ypos,xpos+5,ypos+5);
end;
// draw confidence bands if requested
if ConfBand <> 0.0 then
begin
BlankFrm.Image1.Canvas.Pen.Color := clRed;
ypos := round(vhi * ((Ymax - UpConf[1]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do
begin
ypos := round(vhi * ((Ymax - UpConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
end;
ypos := round(vhi * ((Ymax - lowConf[1]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do
begin
ypos := round(vhi * ((Ymax - lowConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
end;
end;
end;
//-------------------------------------------------------------------
procedure TPlotXYFrm.pplotxy(VAR Xpoints : DblDyneVec;
VAR Ypoints : DblDyneVec;
VAR UpConf : DblDyneVec;
VAR LowConf : DblDyneVec;
ConfBand : double;
Xmean, Ymean , R : double;
Slope, Intercept : double;
Xmax, Xmin, Ymax, Ymin : double;
N : integer);
var
i, xpos, ypos, hleft, hright, vtop, vbottom, imagewide : integer;
vhi, hwide, offset, strhi : integer;
imagehi, maxval, minval, valincr, Yvalue, Xvalue : double;
Title : string;
begin
Printer.Orientation := poLandscape;
Printer.BeginDoc;
Title := 'X versus Y PLOT Using File: ' + OS3MainFrm.FileNameEdit.Text;
strhi := Printer.Canvas.TextWidth(Title) div 2;
Printer.Canvas.TextOut(strhi,5,Title);
imagewide := Printer.PageWidth - 100;
imagehi := Printer.PageHeight - 100;
vtop := 120;
vbottom := round(imagehi) - 100;
vhi := vbottom - vtop;
hleft := 300;
hright := imagewide - 200;
hwide := hright - hleft;
Printer.Canvas.Pen.Color := clBlack;
Printer.Canvas.Brush.Color := clWhite;
// draw Means
if MeansChk.Checked then
begin
ypos := round(vhi * ( (Ymax - Ymean) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := hleft;
Printer.Canvas.MoveTo(xpos,ypos);
xpos := hright;
Printer.Canvas.Pen.Color := clGreen;
Printer.Canvas.LineTo(xpos,ypos);
Title := 'MEAN ';
Title := Title + YEdit.Text;
strhi := Printer.Canvas.TextHeight(Title);
ypos := ypos - strhi div 2;
Printer.Canvas.Brush.Color := clWhite;
Printer.Canvas.TextOut(xpos,ypos,Title);
xpos := round(hwide * ( (Xmean - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
ypos := vtop;
Printer.Canvas.MoveTo(xpos,ypos);
ypos := vbottom;
Printer.Canvas.Pen.Color := clGreen;
Printer.Canvas.LineTo(xpos,ypos);
Title := 'MEAN ';
Title := Title + XEdit.Text;
strhi := Printer.Canvas.TextWidth(Title);
xpos := xpos - strhi div 2;
ypos := vtop - Printer.Canvas.TextHeight(Title);
Printer.Canvas.Brush.Color := clWhite;
Printer.Canvas.TextOut(xpos,ypos,Title);
end;
// draw slope line
if LineChk.Checked then
begin
Printer.Canvas.Pen.Color := clBlack;
Yvalue := (Xpoints[1] * slope) + intercept; // predicted score
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1]- Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.MoveTo(xpos,ypos);
Yvalue := (Xpoints[N] * slope) + intercept; // predicted score
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[N] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.LineTo(xpos,ypos);
end;
// draw horizontal axis
Printer.Canvas.Pen.Color := clBlack;
Printer.Canvas.MoveTo(hleft,vbottom);
Printer.Canvas.LineTo(hright,vbottom);
valincr := (Xmax - Xmin) / 10.0;
for i := 1 to 11 do
begin
ypos := vbottom;
Xvalue := Xmin + valincr * (i - 1);
xpos := round(hwide * ((Xvalue - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.MoveTo(xpos,ypos);
ypos := ypos + 10;
Printer.Canvas.LineTo(xpos,ypos);
Title := format('%6.2f',[Xvalue]);
offset := Printer.Canvas.TextWidth(Title) div 2;
xpos := xpos - offset;
Printer.Canvas.Pen.Color := clBlack;
Printer.Canvas.TextOut(xpos,ypos,Title);
end;
xpos := hleft + (hwide div 2) - (Printer.Canvas.TextWidth(XEdit.Text) div 2);
ypos := vbottom + 40;
Printer.Canvas.TextOut(xpos,ypos,XEdit.Text);
Title := format('R(X,Y) = %5.3f, Slope = %6.2f, Intercept = %6.2f',
[R,Slope,Intercept]);
xpos := hleft + (hwide div 2) - (Printer.Canvas.TextWidth(Title) div 2);
ypos := ypos + 40;
Printer.Canvas.TextOut(xpos,ypos,Title);
// Draw vertical axis
Title := YEdit.Text;
xpos := hleft - Printer.Canvas.TextWidth(Title) div 2;
ypos := vtop - Printer.Canvas.TextHeight(Title);
Printer.Canvas.TextOut(xpos,ypos,YEdit.Text);
xpos := hleft;
ypos := vtop;
Printer.Canvas.MoveTo(xpos,ypos);
ypos := vbottom;
Printer.Canvas.LineTo(xpos,ypos);
valincr := (Ymax - Ymin) / 10.0;
for i := 1 to 11 do
begin
Title := format('%8.2f',[Ymax - ((i-1)*valincr)]);
strhi := Printer.Canvas.TextHeight(Title);
xpos := 10;
Yvalue := Ymax - (valincr * (i-1));
ypos := round(vhi * ( (Ymax - Yvalue) / (Ymax - Ymin)));
ypos := ypos + vtop - strhi div 2;
Printer.Canvas.TextOut(xpos,ypos,Title);
xpos := hleft;
ypos := ypos + strhi div 2;
Printer.Canvas.MoveTo(xpos,ypos);
xpos := hleft - 10;
Printer.Canvas.LineTo(xpos,ypos);
end;
// draw points for x and y pairs
for i := 1 to N do
begin
ypos := round(vhi * ( (Ymax - Ypoints[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.Pen.Color := clBlack;
Printer.Canvas.Ellipse(xpos,ypos,xpos+15,ypos+15);
end;
// draw confidence bands if requested
if ConfBand <> 0.0 then
begin
Printer.Canvas.Pen.Color := clRed;
ypos := round(vhi * ((Ymax - UpConf[1]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do
begin
ypos := round(vhi * ((Ymax - UpConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.LineTo(xpos,ypos);
end;
ypos := round(vhi * ((Ymax - lowConf[1]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do
begin
ypos := round(vhi * ((Ymax - lowConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[i] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft;
Printer.Canvas.LineTo(xpos,ypos);
end;
end;
Printer.EndDoc;
Printer.Orientation := poPortrait;
end;
//-------------------------------------------------------------------
initialization
{$I plotxyunit.lrs}
end.