⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 series.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 5 页
字号:

  TPieAngles=Array of TPieAngle;

  TSliceValueList=class(TList)
  private
    Procedure Put(Index,Value:Integer);
    Function Get(Index:Integer):Integer;
  protected
    OwnerSeries : TChartSeries;
  public
    {$IFNDEF D6}
    procedure Assign(Source:TList);
    {$ENDIF}
    property Value[Index:Integer]:Integer read Get write Put; default;
  end;

  TPieOtherStyle=(poNone, poBelowPercent, poBelowValue);

  TPieOtherSlice=class(TPersistent)
  private
    FColor    : TColor;
    FLegend   : TChartLegend;
    FStyle    : TPieOtherStyle;
    FText     : String;
    FValue    : Double;
    FOwner    : TChartSeries;

    function GetLegend: TChartLegend;
    Function GetText:String;
    Function IsTextStored:Boolean;
    procedure SetColor(Value:TColor);
    procedure SetLegend(const Value: TChartLegend);
    procedure SetStyle(Value:TPieOtherStyle);
    procedure SetText(Const Value:String);
    procedure SetValue(Const Value:Double);
  public
    Constructor Create(AOwner:TChartSeries);
    Destructor Destroy; override;

    Procedure Assign(Source:TPersistent); override;
  published
    property Color:TColor read FColor write SetColor default clTeeColor;
    property Legend:TChartLegend read GetLegend write SetLegend;
    property Style:TPieOtherStyle read FStyle write SetStyle default poNone;
    property Text:String read GetText write SetText stored IsTextStored;
    property Value:Double read FValue write SetValue;
  end;

  TPieShadow=class(TTeeShadow) { 5.02 }
  published
    property Color default Tee_PieShadowColor;
  end;

  TMultiPie=(mpAutomatic, mpDisabled);

  TPieSeries=class(TCircledSeries)
  private
    FAngleSize        : Integer;
    FAutoMarkPosition : Boolean;
    FDark3D           : Boolean;
    FDarkPen          : Integer;
    FDonutPercent     : Integer;
    FExplodedSlice    : TSliceValueList; { <-- Exploded slice % storage }
    FExplodeBiggest   : Integer;
    FMultiPie         : TMultiPie;  // v7.0
    FOtherSlice       : TPieOtherSlice;
    FShadow           : TPieShadow;
    FSliceHeights     : TSliceValueList; { <-- Slice Heights % storage }
    FUsePatterns      : Boolean;

    ISortedSlice      : Array of Integer;
    IOldChartRect     : TRect;

    Procedure CalcExplodeBiggest;
    Procedure CalcExplodedOffset( ValueIndex:Integer;
                                  Var OffsetX,OffsetY:Integer);
    Function CompareSlice(A,B:Integer):Integer;
    Procedure DisableRotation;
    Function GetPiePen:TChartPen;
    Function GetPieValues:TChartValueList;
    function PieCount:Integer;
    Procedure PreparePiePen(ValueIndex:Integer);
    procedure RemoveOtherSlice;
    Procedure SetAngleSize(Value:Integer);
    Procedure SetAutoMarkPosition(Value:Boolean);
    Procedure SetDark3D(Value:Boolean);
    procedure SetDarkPen(const Value: Integer);
    procedure SetExplodeBiggest(Value:Integer);
    procedure SetMultiPie(const Value:TMultiPie);
    procedure SetOtherSlice(Value:TPieOtherSlice);
    Procedure SetPieValues(Value:TChartValueList);
    Procedure SetShadow(Value:TPieShadow);
    procedure SetUsePatterns(Value:Boolean);
    Function SliceBrushStyle(ValueIndex:Integer):TBrushStyle;
    Function SliceEndZ(ValueIndex:Integer):Integer;
    Procedure SwapSlice(a,b:Integer);
  protected
    FAngles    : TPieAngles;
    IniX       : Integer;
    IniY       : Integer;
    EndX       : Integer;
    EndY       : Integer;
    IsExploded : Boolean;

    Procedure AddSampleValues(NumValues:Integer; Sequential:Boolean=False); override;
    Procedure CalcAngles;
    Procedure CalcExplodedRadius(ValueIndex:Integer; Var AXRadius,AYRadius:Integer);
    Procedure CalcFirstLastVisibleIndex; override;
    Procedure CalcZOrder; override; // 7.0
    Procedure CheckOtherSeriesMarks; override; // 6.02
    Procedure ClearLists; override;
    class Procedure CreateSubGallery(AddSubChart:TChartSubGalleryProc); override;
    procedure DoAfterDrawValues; override;
    procedure DoBeforeDrawChart; override;
    procedure DoBeforeDrawValues; override;
    procedure DrawAllValues; override;
    Procedure DrawLegendShape(ValueIndex:Integer; Const Rect:TRect); 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 InitCustom3DOptions; override;
    Function MoreSameZOrder:Boolean; override; // 7.0
    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;
    procedure Delete(ValueIndex:Integer); override;  // 7.0
    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:TSliceValueList read FExplodedSlice;
    property SliceHeight:TSliceValueList read FSliceHeights;
  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:Integer read FDarkPen write SetDarkPen default 0;
    property ExplodeBiggest:Integer read FExplodeBiggest write SetExplodeBiggest default 0;
    property Gradient:TChartGradient read FCircleGradient write SetCircleGradient;
    property MultiPie:TMultiPie read FMultiPie write SetMultiPie default mpAutomatic;
    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;

    {$IFDEF TEEOCX}
    FExpandAxis     : Integer; // 7.01
    {$ENDIF}

    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 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 CalcPosition(ValueIndex:Integer; var x,y:Integer);
    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 NotifyNewValue(Sender:TChartSeries; ValueIndex:Integer); override;  // 7.0 moved from public
    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;
    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;

    {$IFDEF TEEOCX}
    property ExpandAxis:Integer read FExpandAxis write FExpandAxis default 25; // 7.01
    {$ENDIF}

    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;

Procedure TeePointerDrawLegend(Pointer:TSeriesPointer; AColor:TColor;
                               Const Rect:TRect; DrawPen:Boolean);
var tmpHoriz : Integer;
    tmpVert  : Integer;
begin
  if Assigned(Pointer.ParentChart) then
  begin
    Pointer.PrepareCanvas(Pointer.ParentChart.Canvas,AColor);

    with TCustomChart(Pointer.ParentChart) do
    if not Legend.Symbol.DefaultPen then
    begin
      Canvas.AssignVisiblePen(Legend.Symbol.Pen); { use custom legend pen }
      DrawPen:=Legend.Symbol.Pen.Visible;
    end;

    With Rect do
    begin
      if DrawPen then
      begin
        tmpHoriz:=(Right-Left) div 3;
        tmpVert :=(Bottom-Top) div 3;
      end
      else
      begin
        tmpHoriz:=1+((Right-Left) div 2);
        tmpVert :=1+((Bottom-Top) div 2);
      end;

      Pointer.DrawPointer(Pointer.ParentChart.Canvas,
                          False, (Left+Right) div 2,(Top+Bottom) div 2,
                          Math.Min(Pointer.HorizSize,tmpHoriz),
                          Math.Min(Pointer.VertSize,tmpVert),AColor,Pointer.Style);
    end;
  end;
end;

{ TCustomLineSeries }
Function TCustomLineSeries.GetLinePen:TChartPen;
Begin
  result:=Pen;
end;

{ TCustomSeries }
Constructor TCustomSeries.Create(AOwner: TComponent);
Begin
  inherited;
  FClickableLine:=True;
  FColorEachLine:=True;
  DrawBetweenPoints:=True;
  FPointer:=TSeriesPointer.Create(Self);

  FAreaLinesPen:=CreateChartPen;
  FOutLine:=TChartHiddenPen.Create(CanvasChanged);
  FShadow:=TTeeShadow.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;
  FShadow.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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -