series.pas
来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 1,933 行 · 第 1/5 页
PAS
1,933 行
procedure SetExplodeBiggest(Value:Integer);
procedure SetOtherSlice(Value:TPieOtherSlice);
Procedure SetPieValues(Value:TChartValueList);
Procedure SetShadow(Value:TPieShadow);
procedure SetUsePatterns(Value:Boolean);
Function SliceBrushStyle(ValueIndex:Integer):TBrushStyle;
Procedure SwapSlice(a,b:Integer);
procedure SetDarkPen(const Value: Boolean);
protected
FAngles : TPieAngles;
IniX : Integer;
IniY : Integer;
EndX : Integer;
EndY : Integer;
IsExploded : Boolean;
Procedure AddSampleValues(NumValues:Integer); override;
Procedure CalcAngles;
Procedure CalcExplodedRadius(ValueIndex:Integer; Var AXRadius,AYRadius:Integer);
Procedure ClearLists; override;
class Procedure CreateSubGallery(AddSubChart:TChartSubGalleryProc); override;
procedure DoBeforeDrawChart; override;
procedure DrawAllValues; override;
Procedure DrawMark( ValueIndex:Integer; Const St:String;
APosition:TSeriesMarkPosition); override;
Procedure DrawPie(ValueIndex:Integer); virtual;
procedure DrawValue(ValueIndex:Integer); override;
Procedure GalleryChanged3D(Is3D:Boolean); override;
class Function GetEditorClass:String; override;
Procedure PrepareForGallery(IsEnabled:Boolean); override;
Procedure PrepareLegendCanvas( ValueIndex:Integer; Var BackColor:TColor;
Var BrushStyle:TBrushStyle); override;
procedure SetDonutPercent(Value:Integer);
Procedure SetParentChart(Const Value:TCustomAxisPanel); override;
class Procedure SetSubGallery(ASeries:TChartSeries; Index:Integer); override;
procedure WriteData(Stream: TStream); override;
public
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Function AddPie(Const AValue:Double; Const ALabel:String='';
AColor:TColor=clTeeColor):Integer;
Procedure Assign(Source:TPersistent); override;
Function BelongsToOtherSlice(ValueIndex:Integer):Boolean;
Function CalcClickedPie(x,y:Integer):Integer;
Function CalcXPos(ValueIndex:Integer):Integer; override;
Procedure CheckOrder; override;
Function Clicked(x,y:Integer):Integer; override;
Function CountLegendItems:Integer; override;
Function LegendToValueIndex(LegendIndex:Integer):Integer; override;
Function MaxXValue:Double; override;
Function MinXValue:Double; override;
Function MaxYValue:Double; override;
Function MinYValue:Double; override;
Function NumSampleValues:Integer; override;
procedure SwapValueIndex(a,b:Integer); override;
property Angles:TPieAngles read FAngles;
property DonutPercent:Integer read FDonutPercent write SetDonutPercent;
property ExplodedSlice:TExplodedSlices read FExplodedSlice;
published
property Active;
property AngleSize:Integer read FAngleSize write SetAngleSize default 360;
property AutoMarkPosition:Boolean read FAutoMarkPosition write SetAutoMarkPosition default True;
property CircleBackColor;
property ColorEachPoint default True;
property Dark3D:Boolean read FDark3D write SetDark3D default True;
property DarkPen:Boolean read FDarkPen write SetDarkPen default False;
property ExplodeBiggest:Integer read FExplodeBiggest write SetExplodeBiggest default 0;
property OtherSlice:TPieOtherSlice read FOtherSlice write SetOtherSlice;
property PiePen:TChartPen read GetPiePen write SetPen;
property PieValues:TChartValueList read GetPieValues write SetPieValues;
property RotationAngle;
property Shadow:TPieShadow read FShadow write SetShadow; { 5.02 }
property UsePatterns:Boolean read FUsePatterns write SetUsePatterns default False;
end;
TFastLineSeries=class(TCustomLineSeries)
private
FAutoRepaint : Boolean;
FDrawAll : Boolean;
FFastPen : Boolean;
FIgnoreNulls : Boolean; // 6.0
FInvertedStairs : Boolean; // 6.0
FStairs : Boolean; // 6.0
{$IFNDEF CLX}
DCPEN : HGDIOBJ;
{$ENDIF}
{ internal }
OldX : Integer;
OldY : Integer;
Procedure CalcPosition(ValueIndex:Integer; var x,y:Integer);
procedure DoMove(X,Y:Integer);
Procedure SetDrawAll(Const Value:Boolean);
procedure SetFastPen(const Value: Boolean);
procedure SetIgnoreNulls(const Value: Boolean);
procedure SetInvertedStairs(const Value: Boolean);
procedure SetStairs(const Value: Boolean);
protected
Procedure CalcHorizMargins(Var LeftMargin,RightMargin:Integer); override;
Procedure CalcVerticalMargins(Var TopMargin,BottomMargin:Integer); override;
class Procedure CreateSubGallery(AddSubChart:TChartSubGalleryProc); override;
procedure DrawAllValues; override;
Procedure DrawLegendShape(ValueIndex:Integer; Const Rect:TRect); override;
Procedure DrawMark( ValueIndex:Integer; Const St:String;
APosition:TSeriesMarkPosition); override;
procedure DrawValue(ValueIndex:Integer); override;
class Function GetEditorClass:String; override;
procedure PrepareCanvas;
Procedure PrepareLegendCanvas( ValueIndex:Integer; Var BackColor:TColor;
Var BrushStyle:TBrushStyle); override;
Procedure SetPen(Const Value:TChartPen); override;
Procedure SetSeriesColor(AColor:TColor); override;
class Procedure SetSubGallery(ASeries:TChartSeries; Index:Integer); override;
public
Constructor Create(AOwner: TComponent); override;
Procedure Assign(Source:TPersistent); override;
Function Clicked(x,y:Integer):Integer; override;
Procedure NotifyNewValue(Sender:TChartSeries; ValueIndex:Integer); override;
property FastPen:Boolean read FFastPen write SetFastPen default False;
published
property Active;
property Cursor;
property Depth;
property HorizAxis;
property Marks;
property ParentChart;
property DataSource;
property PercentFormat;
property SeriesColor;
property ShowInLegend;
property Title;
property ValueFormat;
property VertAxis;
property XLabelsSource;
{ events }
property AfterDrawValues;
property BeforeDrawValues;
property OnAfterAdd;
property OnBeforeAdd;
property OnClearValues;
property OnClick;
property OnDblClick;
property OnGetMarkText;
property OnMouseEnter;
property OnMouseLeave;
property AutoRepaint:Boolean read FAutoRepaint write FAutoRepaint default True;
property DrawAllPoints:Boolean read FDrawAll write SetDrawAll default True; { 5.02 }
property IgnoreNulls:Boolean read FIgnoreNulls write SetIgnoreNulls default True;
property InvertedStairs:Boolean read FInvertedStairs write SetInvertedStairs default False;
property LinePen;
property Stairs:Boolean read FStairs write SetStairs default False;
property XValues;
property YValues;
end;
Const
bsCylinder=bsCilinder; { <-- better spelling... }
{ calls RegisterTeeSeries for each "standard" series type
(line,bar,pie,fastline,horizbar,area,point and horizline) }
Procedure RegisterTeeStandardSeries;
Procedure TeePointerDrawLegend(Pointer:TSeriesPointer; AColor:TColor;
Const Rect:TRect; DrawPen:Boolean);
implementation
Uses Math, TeeConst;
Function GetDefaultPattern(PatternIndex:Integer):TBrushStyle;
Const MaxDefaultPatterns = 6;
PatternPalette : Array[1..MaxDefaultPatterns] of TBrushStyle=
( bsHorizontal,
bsVertical,
bsFDiagonal,
bsBDiagonal,
bsCross,
bsDiagCross
);
Begin
result:=PatternPalette[1+(PatternIndex mod MaxDefaultPatterns)];
End;
{ TCustomLineSeries }
Function TCustomLineSeries.GetLinePen:TChartPen;
Begin
result:=Pen;
end;
{ TCustomSeries }
Constructor TCustomSeries.Create(AOwner: TComponent);
Begin
inherited;
ClickableLine:=True;
FColorEachLine:=True;
DrawBetweenPoints:=True;
FPointer:=TSeriesPointer.Create(Self);
FAreaLinesPen:=CreateChartPen;
FOutLine:=TChartHiddenPen.Create(CanvasChanged);
FAreaBrush:=TChartBrush.Create(CanvasChanged);
FAreaColor:=clTeeColor;
FDark3D:=True;
FGradient:=TChartGradient.Create(CanvasChanged);
end;
Destructor TCustomSeries.Destroy;
Begin
FGradient.Free;
FAreaBrush.Free;
FAreaLinesPen.Free;
FOutLine.Free;
FreeAndNil(FPointer);
inherited;
end;
Procedure TCustomSeries.DrawMark( ValueIndex:Integer; Const St:String;
APosition:TSeriesMarkPosition);
begin
Marks.ZPosition:=StartZ;
if YMandatory then Marks.ApplyArrowLength(APosition);
inherited;
end;
Function TCustomSeries.ClickedPointer( ValueIndex,tmpX,tmpY:Integer;
x,y:Integer):Boolean;
var tmpStyle : TSeriesPointerStyle;
begin
if Assigned(FOnGetPointerStyle) then
tmpStyle:=FOnGetPointerStyle(Self,ValueIndex)
else
tmpStyle:=Pointer.Style;
result:=(tmpStyle<>psNothing) and
(Abs(tmpX-X)<FPointer.HorizSize) and
(Abs(tmpY-Y)<FPointer.VertSize);
end;
Procedure TCustomSeries.Assign(Source:TPersistent);
begin
if Source is TCustomSeries then
With TCustomSeries(Source) do
begin
Self.ClickableLine :=ClickableLine;
Self.AreaChartBrush :=FAreaBrush;
Self.FAreaColor :=FAreaColor;
Self.AreaLinesPen :=AreaLinesPen;
Self.FColorEachLine :=ColorEachLine;
Self.FDark3D :=FDark3D;
Self.FDrawArea :=FDrawArea;
Self.FDrawLine :=FDrawLine;
Self.FInvertedStairs :=FInvertedStairs;
Self.FLineHeight :=FLineHeight;
Self.Pointer :=FPointer;
Self.FStacked :=FStacked;
Self.FStairs :=FStairs;
Self.OutLine :=OutLine;
Self.FTransparency :=FTransparency;
Self.Gradient :=FGradient;
end;
inherited;
end;
Function TCustomSeries.Clicked(x,y:Integer):Integer;
var OldXPos : Integer;
OldYPos : Integer;
tmpX : Integer;
tmpY : Integer;
P : TPoint;
Function CheckPointInLine:Boolean;
Function PointInVertLine(x0,y0,y1:Integer):Boolean;
begin
result:=PointInLine(P,x0,y0,x0,y1);
end;
Function PointInHorizLine(x0,y0,x1:Integer):Boolean;
begin
result:=PointInLine(P,x0,y0,x1,y0);
end;
begin
With ParentChart do
if View3D then
result:=PointInPolygon( P,[ TeePoint(tmpX,tmpY),
TeePoint(tmpX+SeriesWidth3D,tmpY-SeriesHeight3D),
TeePoint(OldXPos+SeriesWidth3D,OldYPos-SeriesHeight3D),
TeePoint(OldXPos,OldYPos) ])
else
if Stairs then
begin
if FInvertedStairs then result:= PointInVertLine(OldXPos,OldYPos,tmpY) or
PointInHorizLine(OldXPos,tmpY,tmpX)
else result:= PointInHorizLine(OldXPos,OldYPos,tmpX) or
PointInVertLine(tmpX,OldYPos,tmpY);
end
else
result:=PointInLine(P,tmpX,tmpY,OldXPos,OldYPos)
end;
var t : Integer;
begin
if Assigned(ParentChart) then ParentChart.Canvas.Calculate2DPosition(X,Y,StartZ);
result:=inherited Clicked(x,y);
if (result=TeeNoPointClicked) and
(FirstValueIndex>-1) and (LastValueIndex>-1) then
begin
OldXPos:=0;
OldYPos:=0;
OldBottomPos:=0;
P.X:=X;
P.Y:=Y;
for t:=FirstValueIndex to LastValueIndex do
begin
if t>=Count then exit; // prevent re-entrancy if series is cleared.
tmpX:=CalcXPos(t);
tmpY:=CalcYPos(t);
if FPointer.Visible then
begin
if ClickedPointer(t,tmpX,tmpY,x,y) then
begin
if Assigned(FOnClickPointer) then FOnClickPointer(Self,t,x,y);
result:=t;
break;
end;
end;
if (tmpX=X) and (tmpY=Y) then
begin
result:=t;
break;
end;
if (t>FirstValueIndex) and ClickableLine then
if CheckPointInLine or
( FDrawArea and
PointInPolygon( P,[ TeePoint(OldXPos,OldYPos),
TeePoint(tmpX,tmpY),
TeePoint(tmpX,GetOriginPos(t)),
TeePoint(OldXPos,GetOriginPos(t-1)) ] )
) then
begin
result:=t-1;
break;
end;
OldXPos:=tmpX;
OldYPos:=tmpY;
OldBottomPos:=BottomPos;
end;
end;
end;
Procedure TCustomSeries.SetDrawArea(Value:Boolean);
Begin
SetBooleanProperty(FDrawArea,Value);
end;
Procedure TCustomSeries.SetPointer(Value:TSeriesPointer);
Begin
FPointer.Assign(Value);
end;
Procedure TCustomSeries.SetAreaLinesPen(Value:TChartPen);
Begin
FAreaLinesPen.Assign(Value);
end;
Procedure TCustomSeries.SetLineHeight(Value:Integer);
Begin
SetIntegerProperty(FLineHeight,Value);
end;
Procedure TCustomSeries.SetStairs(Value:Boolean);
Begin
SetBooleanProperty(FStairs,Value);
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?