?? sgr_data.pas
字號:
if Not(ValidMinMax) then FindMinMax;
V:=XMin;
end;
end;
function Tsp_XYDataSeries.GetXMax;
begin
Result:=Count>0;
if Result then
begin
if Not(ValidMinMax) then FindMinMax;
V:=XMax;
end;
end;
function Tsp_XYDataSeries.GetYMin;
begin
Result:=Count>0;
if Result then
begin
if Not(ValidMinMax) then FindMinMax;
V:=YMin;
end;
end;
function Tsp_XYDataSeries.GetYMax;
begin
Result:=Count>0;
if Result then
begin
if Not(ValidMinMax) then FindMinMax;
V:=YMax;
end;
end;
procedure Tsp_XYDataSeries.Clear;
begin
if Active and (fPN>0) then
begin
fPN:=0;
if CanPlot then InvalidatePlot(rsDataChanged)
end
else fPN:=0;
end;
procedure Tsp_XYDataSeries.AdjustCapacity;
var n:integer;
begin
n:=((fPN div fInc) +1)*fInc;
if n<>fCapacity then
begin
VarArrayRedim(XV, n);
VarArrayRedim(YV, n);
fCapacity:=VarArrayHighBound(XV,1);
end;
end;
procedure Tsp_XYDataSeries.SetCapacity(C:integer);
var n:integer;
begin
if C<fPN then //truncate data if Capacity less then Count
begin
fPN:=C;
AdjustCapacity;
ValidMinMax:=False; //added 28.10.1999
if CanPlot then InvalidatePlot(rsDataChanged);
end
else
begin
n:=((C div fInc) +1)*fInc;
if n<>fCapacity then begin
VarArrayRedim(XV, n);
VarArrayRedim(YV, n);
fCapacity:=VarArrayHighBound(XV,1);
end;
end;
end;
procedure Tsp_XYDataSeries.AddXY(aX,aY:double);
begin
if fPN >= fCapacity then Expand;
XV[fPN]:=aX; YV[fPN]:=aY;
TryUpdateMinMax(aX,aY);
inc(fPN);
TryUpdatePlot; //try to redraw changes immediately
end;
procedure Tsp_XYDataSeries.AddXYArrays(pX,pY:pointer; n:integer);
var pdX, pdY:pDbls; j:integer;
begin
if n<=0 then Exit;
if (fPN+n) >= fCapacity then ExpandBy(n);
j:=n*SizeOf(Double);
pdX:=VarArrayLock(XV);
pdY:=VarArrayLock(YV);
try
System.Move(pX^,pdX^[fPN],j);
System.Move(pY^,pdY^[fPN],j);
j:=fPN;
inc(fPN,n); //do not win essential time if n>old_fPN
if ValidMinMax and (n<2*j) then //rewrite at 27.10.1999
for j:=j to fPN-1 do begin
if pdX[j]<XMin then XMin:=pdX[j]
else if pdX[j]>XMax then XMax:=pdX[j];
if pdY[j]<YMin then YMin:=pdY[j]
else if pdY[j]>YMax then YMax:=pdY[j];
end
else ValidMinMax:=False;
finally
VarArrayUnlock(YV);
VarArrayUnlock(XV);
end;
if CanPlot then InvalidatePlot(rsDataChanged); //? may be update immediately
end;
procedure Tsp_XYDataSeries.InsertXY(i:integer; aX,aY:double);
var pdX, pdY:pDbls; j:integer;
begin
if (i>fPN) or (i<0) then Exit; //Exception
if i=fPN then AddXY(ax,ay)
else begin
j:=(fPN-i)*SizeOf(Double);
if fPN >= fCapacity then Expand;
pdX:=VarArrayLock(XV);
pdY:=VarArrayLock(YV);
try
System.Move(pdX^[i],pdX^[i+1],j);
System.Move(pdY^[i],pdY^[i+1],j);
pdX[i]:=aX; pdY[i]:=aY;
TryUpdateMinMax(aX,aY);
inc(fPN);
finally
VarArrayUnlock(YV);
VarArrayUnlock(XV);
end;
end;
TryUpdatePlot; //try to redraw changes immediately
end;
procedure Tsp_XYDataSeries.ReplaceXY(i:integer; aX,aY:double);
begin
if (i>=fPN) or (i<0) then Exit; //Exception //? may be raise Exception
XV[i]:=aX; YV[i]:=aY;
ValidMinMax:=False;
TryUpdatePlot; //try to redraw changes immediately
end;
procedure Tsp_XYDataSeries.Delete(i:integer);
var pdX, pdY:pDbls; j:integer;
begin
if (i>=fPN) or (i<0) then Exit; //Exception
ValidMinMax:=False;
if i=fPN-1 then dec(fPN)
else begin
j:=(fPN-i-1)*SizeOf(Double);
//if fPN >= fCapacity then Expand;
pdX:=VarArrayLock(XV);
pdY:=VarArrayLock(YV);
try
System.Move(pdX^[i+1],pdX^[i],j);
System.Move(pdY^[i+1],pdY^[i],j);
dec(fPN);
finally
VarArrayUnlock(YV);
VarArrayUnlock(XV);
end;
end;
TryUpdatePlot; //try to redraw changes immediately
end;
procedure Tsp_XYDataSeries.DeleteRange(fromi, toi:integer);
var pdX, pdY:pDbls; j:integer;
begin
if fromi>toi then begin //swap if need
j:=fromi; fromi:=toi; toi:=j;
end;
if (fromi>=fPN) or (fromi<0) then Exit; //Exception
ValidMinMax:=False;
if toi>=fPN-1 then begin
fPN:=fromi;
Exit;
end;
j:=(fPN-toi)*SizeOf(Double);
dec(fPN,(toi-fromi+1));
pdX:=VarArrayLock(XV);
pdY:=VarArrayLock(YV);
try
System.Move(pdX^[toi+1],pdX^[fromi],j);
System.Move(pdY^[toi+1],pdY^[fromi],j);
finally
VarArrayUnlock(YV);
VarArrayUnlock(XV);
end;
TryUpdatePlot; //try to redraw changes immediately
end;
{*** Tsp_PointAttr ***}
constructor Tsp_PointAttr.Create;
begin
inherited;
fVSize:=2; fVSize1:=3;
fHSize:=2; fHSize1:=3;
fBorderColor:=clBlack;
fBorderWidth:=1;
end;
procedure Tsp_PointAttr.SetPenAttr(const APen:TPen);
begin
with APen do begin
Color:=fBorderColor;
Width:=fBorderWidth;
Style:=psSolid;
Mode:=pmCopy;
end;
end;
procedure Tsp_PointAttr.SetType(const V:TPointKind);
begin
if fPointType<>V then
begin
fPointType:=V;
Changed;
end;
end;
procedure Tsp_PointAttr.SetVisible(const V:boolean);
begin
if fVisible<>V then
begin
fVisible:=V;
Changed;
end;
end;
procedure Tsp_PointAttr.Assign(Source: TPersistent);
var ss: Tsp_PointAttr;
begin
if Source is Tsp_PointAttr then begin
ss:=Source as Tsp_PointAttr;
fPointType:=ss.fPointType; fVisible:=ss.fVisible;
HSize:=ss.HSize; VSize:=ss.VSize;
end;
inherited Assign(Source);
end;
procedure Tsp_PointAttr.SetHSize(V:integer);
begin
if V<0 then V:=1;
V:=V div 2;
if eHSize<>V then begin
fHSize:=V; fHSize1:=V+1;
Changed;
end;
end;
procedure Tsp_PointAttr.SetVSize(V:integer);
begin
if V<0 then V:=1;
V:=V div 2;
if eVSize<>V then begin
fVSize:=V; fVSize1:=V+1;
Changed;
end;
end;
function Tsp_PointAttr.GetHSize:integer;
begin
Result:=fHSize+fHSize1;
end;
function Tsp_PointAttr.GetVSize:integer;
begin
Result:=fVSize+fVSize1;
end;
procedure Tsp_PointAttr.SetBorderWidth(V:integer);
begin
if V<0 then V:=1;
if V>fHSize then V:=fHSize;
if V>fVSize then V:=fVSize;
if fBorderWidth<>V then begin
fBorderWidth:=V;
Changed;
end;
end;
procedure Tsp_PointAttr.SetBorderColor(const V:TColor);
begin
if fBorderColor<>V then begin
fBorderColor:=V;
Changed;
end;
end;
{*** Tsp_XYLine ***}
constructor Tsp_XYLine.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
DrawPointProc:=DrawRect;
fOnDrawCustomPoint:=nil;
fPA:=Tsp_PointAttr.Create;
fPA.OnChange:=AtrributeChanged;
end;
destructor Tsp_XYLine.Destroy;
begin
if Assigned(FPA) then begin
FPA.OnChange:=nil;
FPA.Free;
end;
inherited;
end;
procedure Tsp_XYLine.SetPointAttr(const V:Tsp_PointAttr);
begin
fPA.Assign(V);
end;
procedure Tsp_XYLine.AtrributeChanged(V:TObject);
begin
if V=fPA then
case fPA.Kind of
ptRectangle: DrawPointProc:=DrawRect;
ptEllipse: DrawPointProc:=DrawEllipse;
ptDiamond: DrawPointProc:=DrawDiamond;
ptCross: DrawPointProc:=DrawCross;
ptCustom: DrawPointProc:=DrawRect; //DrawCustom;
ptTriangle: DrawPointProc:=DrawTriangle;
ptDownTriangle: DrawPointProc:=DrawDownTriangle;
else DrawPointProc:=DrawRect;
end;
inherited AtrributeChanged(fPA);
end;
procedure Tsp_XYLine.DrawRect(const x, y: Integer);
begin
with fPA do
fCanvas.Rectangle(x-eHSize, y-eVSize, x+oHSize, y+eVSize+1);
end;
procedure Tsp_XYLine.DrawEllipse(const x, y: Integer);
begin
with fPA do
fCanvas.Ellipse(x-eHSize, y-eVSize, x+oHSize, y+oVSize);
end;
procedure Tsp_XYLine.DrawDiamond(const x, y: Integer);
begin
with fPA do
fCanvas.Polygon([Point(x, y - eVSize), Point(x + eHSize, y),
Point(x, y + eVSize), Point(x - eHSize, y)]);
end;
procedure Tsp_XYLine.DrawCross(const x, y: Integer);
begin
with fCanvas, fPA do
begin
MoveTo(x - eHSize, y);
LineTo(x + oHSize, y);
MoveTo(x, y - eVSize);
LineTo(x, y + oVSize);
end;
end;
procedure Tsp_XYLine.DrawTriangle(const x, y: Integer);
begin
with fPA do
fCanvas.Polygon([Point(x, y - eVSize), Point(x + eHSize, y + eVSize),
Point(x - eHSize, y + eVSize)]);
end;
procedure Tsp_XYLine.DrawDownTriangle(const x, y: Integer);
begin
with fPA do
fCanvas.Polygon([Point(x-eHSize, y-eVSize), Point(x+eHSize, y-eVSize),
Point(x, y + eVSize)]);
end;
procedure Tsp_XYLine.Draw;
const
ep_Out=1; op_Out=2; Both_Out=op_Out or ep_Out;
var
pdx, pdy : pDbls; i,a : double;
XA, YA : Tsp_Axis;
procedure DrawLines(const pxa, pya : pDbls; const XA, YA : Tsp_Axis);
var
j:integer; pa:array [0..1] of TPoint; is_out:word;
begin
with fCanvas, YA do
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -