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

📄 teepoin3.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*****************************************}
{   TeeChart Pro                          }
{   TPoint3DSeries                        }
{   Copyright (c) 1995-2004 David Berneda }
{*****************************************}
unit TeePoin3;
{$I TeeDefs.inc}

interface

Uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,
     {$IFDEF CLX}
     QGraphics, Types,
     {$ELSE}
     Graphics,
     {$ENDIF}
     TeEngine, TeeSurfa, Series, TeCanvas;

type
  TPoint3DSeries=class;

  TSeriesClickPointer3DEvent=Procedure( Sender:TPoint3DSeries;
                                        ValueIndex:Integer;
                                        X, Y: Integer) of object;

  TPoint3DSeries = class(TCustom3DSeries)
  private
    FBaseLine  : TChartHiddenPen;
    FDepthSize : Double;
    FPointer   : TSeriesPointer;

    { events }
    FOnClickPointer    : TSeriesClickPointer3DEvent;
    FOnGetPointerStyle : TOnGetPointerStyle;

    { internal }
    IOldX     : Integer;
    IOldY     : Integer;
    IOldZ     : Integer;

    Function GetLinePen:TChartPen;
    procedure SetBaseLine(const Value: TChartHiddenPen);
    Procedure SetDepthSize(Const Value:Double);
    Procedure SetPointer(Value:TSeriesPointer);
  protected
    Procedure AddSampleValues(NumValues:Integer; OnlyMandatory:Boolean=False); override;
    Procedure CalcHorizMargins(Var LeftMargin,RightMargin:Integer); override;
    Procedure CalcVerticalMargins(Var TopMargin,BottomMargin:Integer); override;
    Procedure CalcZPositions(ValueIndex:Integer); virtual;
    class Procedure CreateSubGallery(AddSubChart:TChartSubGalleryProc); override;
    Procedure DrawLegendShape(ValueIndex:Integer; Const Rect:TRect); override;
    Procedure DrawMark( ValueIndex:Integer; Const St:String;
                        APosition:TSeriesMarkPosition); override;
    Procedure DrawValue(ValueIndex:Integer); override;  // 7.0 moved from public
    Function GetDepthSize(ValueIndex:Integer):Integer; virtual;
    class Function GetEditorClass:String; override;
    Procedure PrepareForGallery(IsEnabled:Boolean); override;
    Procedure SetParentChart(Const Value:TCustomAxisPanel); override;
    class Procedure SetSubGallery(ASeries:TChartSeries; Index:Integer); override;
    class Function SubGalleryStyles:Boolean; virtual;
  public
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;

    Procedure Assign(Source:TPersistent); override;
    Function Clicked(x,y:Integer):Integer; override;
    Function MaxZValue:Double; override;
  published
    property Active;
    property ColorEachPoint;
    property ColorSource;
    property Cursor;
    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 BaseLine:TChartHiddenPen read FBaseLine write SetBaseLine; // 6.02
    property DepthSize:Double read FDepthSize write SetDepthSize;
    property LinePen:TChartPen read GetLinePen write SetPen;
    property Pointer:TSeriesPointer read FPointer write SetPointer;
    property TimesZOrder;
    property XValues;
    property YValues;
    property ZValues;

    { events }
    property OnClickPointer:TSeriesClickPointer3DEvent read FOnClickPointer
                                                       write FOnClickPointer;
    property OnGetPointerStyle:TOnGetPointerStyle read FOnGetPointerStyle
                                                  write FOnGetPointerStyle;
  end;

  TBubble3DSeries = class(TPoint3DSeries)
  private
    FRadiusValues : TChartValueList; { <-- Bubble's radius storage }
    Function ApplyRadius( Const Value:Double;
                          AList:TChartValueList;
                          Increment:Boolean):Double;
    Procedure SetRadiusValues(Value:TChartValueList);
  protected
    Procedure AddSampleValues(NumValues:Integer; OnlyMandatory:Boolean=False); override; { <-- to add random radius values }
    Procedure CalcZPositions(ValueIndex:Integer); override;
    procedure DrawValue(ValueIndex:Integer); override; { <-- main draw method }
    Function GetDepthSize(ValueIndex:Integer):Integer; override;
    Procedure PrepareForGallery(IsEnabled:Boolean); override;
    class Function SubGalleryStyles:Boolean; override;
  public
    Constructor Create(AOwner: TComponent); override;

    Function AddBubble(Const AX,AY,AZ,ARadius:Double; Const AXLabel:String='';
                       AColor:TColor=clTeeColor):Integer;
    Function IsValidSourceOf(Value:TChartSeries):Boolean; override;

    Function MaxYValue:Double; override;  // adds radius
    Function MinYValue:Double; override;  // substracts radius
    Function MaxZValue:Double; override;
    Function MinZValue:Double; override;
  published
    property ColorEachPoint default True;
    property RadiusValues:TChartValueList read FRadiusValues write SetRadiusValues;
  end;

implementation

Uses Math, Chart, TeeConst, TeeProCo;

{ TPoint3DSeries }
Constructor TPoint3DSeries.Create(AOwner: TComponent);
begin
  inherited;
  FPointer:=TSeriesPointer.Create(Self);
  FBaseLine:=TChartHiddenPen.Create(CanvasChanged);
end;

Destructor TPoint3DSeries.Destroy;
begin
  FBaseLine.Free;
  FPointer.Free;
  inherited;
end;

class Function TPoint3DSeries.SubGalleryStyles:Boolean;
begin
  result:=True;
end;

Procedure TPoint3DSeries.SetPointer(Value:TSeriesPointer);
Begin
  FPointer.Assign(Value);
end;

Procedure TPoint3DSeries.CalcZPositions(ValueIndex:Integer);
var tmp : Integer;
begin
  // do not call inherited here
  MiddleZ:=CalcZPos(ValueIndex);
  tmp:=Math.Max(1,GetDepthSize(ValueIndex));
  StartZ:=MiddleZ-tmp;
  EndZ:=MiddleZ+tmp;
end;

Function TPoint3DSeries.GetLinePen:TChartPen;
begin
  result:=Pen;
end;

type TPointerAccess=class(TSeriesPointer);

Procedure TPoint3DSeries.CalcHorizMargins(Var LeftMargin,RightMargin:Integer);
begin
  inherited;
  TPointerAccess(FPointer).CalcHorizMargins(LeftMargin,RightMargin);
end;

Procedure TPoint3DSeries.CalcVerticalMargins(Var TopMargin,BottomMargin:Integer);
begin
  inherited;
  TPointerAccess(FPointer).CalcVerticalMargins(TopMargin,BottomMargin);
end;

Procedure TPoint3DSeries.DrawValue(ValueIndex:Integer);
var tmpColor : TColor;
    tmpStyle : TSeriesPointerStyle;
    tmpX     : Integer;
    tmpY     : Integer;
    tmpZ     : Integer;
    tmpFirst : Integer;
begin
  tmpColor:=ValueColor[ValueIndex];

  if tmpColor<clNone then // 7.0
  begin
    CalcZPositions(ValueIndex);

    With Pointer do
    begin
      tmpX:=CalcXPos(ValueIndex);
      tmpY:=CalcYPos(ValueIndex);

      if Visible then
      begin { emulate TCustomSeries.DrawPointer method }

        PrepareCanvas(ParentChart.Canvas,tmpColor);
        if Assigned(FOnGetPointerStyle) then
           tmpStyle:=FOnGetPointerStyle(Self,ValueIndex)
        else
           tmpStyle:=FPointer.Style;

        DrawPointer( ParentChart.Canvas,ParentChart.View3D,
                     tmpX,tmpY,HorizSize,VertSize,tmpColor,tmpStyle);
      end;

      if BaseLine.Visible then
      begin
        tmpZ:=CalcZPos(ValueIndex);
        ParentChart.Canvas.AssignVisiblePen(BaseLine);
        ParentChart.Canvas.MoveTo3D(tmpX,tmpY+VertSize,tmpZ);
        ParentChart.Canvas.LineTo3D(tmpX,GetVertAxis.IEndPos,tmpZ);
      end;

      tmpFirst:=FirstDisplayedIndex; // Problem when ValueColor[First] is clNone (null point)

      if (ValueIndex<>tmpFirst) and LinePen.Visible then
      With ParentChart.Canvas do
      begin
        AssignVisiblePen(LinePen);
        BackMode:=cbmTransparent;
        MoveTo3D(IOldX,IOldY,IOldZ);
        LineTo3D(tmpX,tmpY,MiddleZ);
      end;

      IOldX:=tmpX;
      IOldY:=tmpY;
      IOldZ:=MiddleZ;
    end;
  end;
end;

Procedure TPoint3DSeries.DrawLegendShape(ValueIndex:Integer; Const Rect:TRect);
var tmpColor : TColor;
begin
  if FPointer.Visible then
  begin
    if ValueIndex=TeeAllValues then tmpColor:=SeriesColor
                               else tmpColor:=ValueColor[ValueIndex];
    TeePointerDrawLegend(Pointer,tmpColor,Rect,LinePen.Visible);
  end
  else inherited;
end;

Procedure TPoint3DSeries.AddSampleValues(NumValues:Integer; OnlyMandatory:Boolean=False);

⌨️ 快捷键说明

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