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

📄 iplotchannel.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 5 页
字号:
{*******************************************************}
{                                                       }
{       TiPlotChannel                                   }
{                                                       }
{       Copyright (c) 1997,2003 Iocomp Software         }
{                                                       }
{*******************************************************}
{$I iInclude.inc}

{$ifdef iVCL}unit  iPlotChannel;{$endif}
{$ifdef iCLX}unit QiPlotChannel;{$endif}

interface

uses
  {$I iIncludeUses.inc}
  {$IFDEF iVCL} iTypes,  iGPFunctions,  iMath,  iClasses,  iPlotObjects,  iPlotDataNullList,  iPlotChannelCustom,  iPlotAxis, iOPCItem;{$ENDIF}
  {$IFDEF iCLX}QiTypes, QiGPFunctions, QiMath, QiClasses, QiPlotObjects, QiPlotDataNullList, QiPlotChannelCustom, QiPlotAxis;          {$ENDIF}

type
  TiPlotDigitalReferenceStyle = (ipdrScale, ipdrPercent);
  TiPlotInterpolationStyle    = (ipistStraightLine, ipistCubicSpline, ipistPolynomial, ipistRational, ipistDifferential, ipistDifferentialTerminated);
  TiPlotHighLowStyle          = (iphlsOpenClose, iphlsCandleStick);
  TiOPCXValueSourceStyle      = (iopcxvsOPCServerTimeStamp, iopcxvsSystemTimeStamp, iopcxvsElapsedTime, iopcxvsElapsedSeconds);

  TiPlotPixelPoint = class(TObject)
  public
    Null   : Boolean;
    XPixel : Integer;
    YValue : Double;
  end;

  TiPlotChannel = class(TiPlotChannelCustom)
  private
    FPixelList               : TStringList;
    FPixelListStart          : Integer;
    FPixelListStop           : Integer;

    FPixelsHigh              : Integer;
    FPixelsLow               : Integer;

    FXIncreasing             : Boolean;

    FFastDrawEnabled         : Boolean;
    FInterpolationStyle      : TiPlotInterpolationStyle;
    FElapsedStartTime        : Double;

    FFillEnabled             : Boolean;
    FFillReference           : Double;
    FFillUseChannelColor     : Boolean;
    FFillStyle               : TBrushStyle;
    FFillColor               : TColor;

    FHighLowStyle            : TiPlotHighLowStyle;
    FHighLowEnabled          : Boolean;
    FHighLowBarColor         : TColor;
    FHighLowBarWidth         : Double;
    FHighLowOpenShow         : Boolean;
    FHighLowOpenColor        : TColor;
    FHighLowOpenWidth        : Double;
    FHighLowOpenHeight       : Double;
    FHighLowCloseShow        : Boolean;
    FHighLowCloseColor       : TColor;
    FHighLowCloseWidth       : Double;
    FHighLowCloseHeight      : Double;
    FHighLowShadowColor      : TColor;
    FHighLowBullishColor     : TColor;
    FHighLowBearishColor     : TColor;

    FDigitalEnabled          : Boolean;
    FDigitalReferenceLow     : Double;
    FDigitalReferenceHigh    : Double;
    FDigitalReferenceStyle   : TiPlotDigitalReferenceStyle;

    {$IFDEF iVCL}
    FOPCXValueSource         : TiOPCXValueSourceStyle;
    {$endif}

    FBarEnabled              : Boolean;
    FBarPenUseChannelColor   : Boolean;
    FBarBrushUseChannelColor : Boolean;
  protected
    procedure SetFastDrawEnabled        (const Value: Boolean);
    procedure SetInterpolationStyle     (const Value: TiPlotInterpolationStyle);

    procedure SetFillEnabled            (const Value: Boolean);
    procedure SetFillReference          (const Value: Double);
    procedure SetFillStyle              (const Value: TBrushStyle);
    procedure SetFillColor              (const Value: TColor);
    procedure SetFillUseChannelColor    (const Value: Boolean);

    procedure SetDigitalEnabled         (const Value: Boolean);
    procedure SetDigitalReferenceStyle  (const Value: TiPlotDigitalReferenceStyle);
    procedure SetDigitalReferenceHigh   (const Value: Double);
    procedure SetDigitalReferenceLow    (const Value: Double);

    procedure SetBarEnabled             (const Value: Boolean);
    procedure SetBarWidth               (const Value: Double);
    procedure SetBarReference           (const Value: Double);
    procedure SetBarPenColor            (const Value: TColor);
    procedure SetBarPenUseChannelColor  (const Value: Boolean);
    procedure SetBarPenStyle            (const Value: TPenStyle);
    procedure SetBarPenWidth            (const Value: Integer);
    procedure SetBarBrushColor          (const Value: TColor);
    procedure SetBarBrushUseChannelColor(const Value: Boolean);
    procedure SetBarBrushStyle          (const Value: TBrushStyle);

    procedure SetHighLowStyle           (const Value: TiPlotHighLowStyle);
    procedure SetHighLowEnabled         (const Value: Boolean);
    procedure SetHighLowBarColor        (const Value: TColor);
    procedure SetHighLowBarWidth        (const Value: Double);
    procedure SetHighLowOpenShow        (const Value: Boolean);
    procedure SetHighLowOpenColor       (const Value: TColor);
    procedure SetHighLowOpenWidth       (const Value: Double);
    procedure SetHighLowOpenHeight      (const Value: Double);
    procedure SetHighLowCloseShow       (const Value: Boolean);
    procedure SetHighLowCloseColor      (const Value: TColor);
    procedure SetHighLowCloseWidth      (const Value: Double);
    procedure SetHighLowCloseHeight     (const Value: Double);
    procedure SetHighLowShadowColor     (const Value: TColor);
    procedure SetHighLowBullishColor    (const Value: TColor);
    procedure SetHighLowBearishColor    (const Value: TColor);

    function  GetBarReference : Double;
    function  GetBarWidth     : Double;
    function  GetBarPenColor  : TColor;
    function  GetBarPenWidth  : Integer;
    function  GetBarPenStyle  : TPenStyle;
    function  GetBarBrushColor: TColor;
    function  GetBarBrushStyle: TBrushStyle;

    function  GetDataHigh               (const Index: Integer): Double;
    function  GetDataLow                (const Index: Integer): Double;
    function  GetDataOpen               (const Index: Integer): Double;
    function  GetDataClose              (const Index: Integer): Double;

    function  GetDataBarVisible         (const Index: Integer): Boolean;
    function  GetDataBarReference       (const Index: Integer): Double;
    function  GetDataBarWidth           (const Index: Integer): Double;
    function  GetDataBarPenColor        (const Index: Integer): TColor;
    function  GetDataBarPenWidth        (const Index: Integer): Integer;
    function  GetDataBarPenStyle        (const Index: Integer): TPenStyle;
    function  GetDataBarBrushColor      (const Index: Integer): TColor;
    function  GetDataBarBrushStyle      (const Index: Integer): TBrushStyle;

    procedure SetDataHigh               (const Index: Integer; const Value: Double);
    procedure SetDataLow                (const Index: Integer; const Value: Double);
    procedure SetDataOpen               (const Index: Integer; const Value: Double);
    procedure SetDataClose              (const Index: Integer; const Value: Double);

    procedure SetDataBarVisible         (const Index: Integer; const Value: Boolean);
    procedure SetDataBarReference       (const Index: Integer; const Value: Double);
    procedure SetDataBarWidth           (const Index: Integer; const Value: Double);
    procedure SetDataBarPenColor        (const Index: Integer; const Value: TColor);
    procedure SetDataBarPenWidth        (const Index: Integer; const Value: Integer);
    procedure SetDataBarPenStyle        (const Index: Integer; const Value: TPenStyle);
    procedure SetDataBarBrushColor      (const Index: Integer; const Value: TColor);
    procedure SetDataBarBrushStyle      (const Index: Integer; const Value: TBrushStyle);

    procedure CalcStartXIndex; override;
    procedure CalcStopXIndex;  override;

    function CalcIndex           (TargetValue: Double): Integer;
    function CalcXIndexIncreasing(TargetValue: Double): Integer;
    function CalcXIndexDecreasing(TargetValue: Double): Integer;

    function  GetVisibleMaxX : Double; override;
    function  GetVisibleMinX : Double; override;
    function  GetVisibleMaxY : Double; override;
    function  GetVisibleMinY : Double; override;

    procedure DataCursorUpate(Sender: TObject); override;

    function  GetDataCursorDisplayText(Style: TiPlotDataCursorStyle; XValue, YValue: Double; Status: TiPlotDataPointStatus): String;

    procedure DrawSetup             (const Canvas: TCanvas);                                override;
    procedure Draw                  (const Canvas: TCanvas; const BackGroundColor: TColor); override;
    procedure DrawFill              (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawBar               (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawHighLow           (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawHighLowCandleStick(Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawConnectPoints     (Canvas: TCanvas; XYAxisReverse: Boolean); override;
    procedure DrawMarkers           (Canvas: TCanvas; XYAxisReverse: Boolean); override;
    procedure DrawDigital           (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawFast              (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawDigitalSequence   (Canvas: TCanvas; XYAxisReverse: Boolean; SequenceData: TDigitalSequenceData);
    procedure DrawCubicSpline       (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawCubicSplineSet    (Canvas: TCanvas; XYAxisReverse: Boolean; XArray, YArray, Y2Array: DoubleDynamicArray; Size: Integer);
    procedure DrawPolynomial        (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawRational          (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawDifferential      (Canvas: TCanvas; XYAxisReverse: Boolean);
    procedure DrawPointSet          (const Canvas: TCanvas; const XYAxisReverse: Boolean; const Point1, Point2, Point3: TiPlotMinMaxPoint);

    function  iMouseHitTest(MouseData: TiPlotMouseData): Boolean;                                               override;

    {$IFDEF iVCL}
    procedure OPCNewData(Sender: TObject); override;
    {$endif}

    procedure AddPixelListValue(XPixel: Integer; YValue: Double);
  public
    constructor Create(AOwner: TObject; AOnChange, AOnInsert, AOnRemove, AOnRename: TNotifyEvent); override;
    destructor  Destroy;                                                                               override;
    function GetYInterpolated(XValue : Double; var YValue : Double): Boolean;

    function AddXNull          (X                          : Double): Integer;
    function AddXEmpty         (X                          : Double): Integer;
    function AddHighLow        (X,   High, Low, Open, Close: Double): Integer;
    function AddYNow           (   Y                       : Double): Integer;
    function AddYElapsedTime   (   Y                       : Double): Integer;
    function AddYElapsedSeconds(   Y                       : Double): Integer;

    procedure AddYArray(XInterval: Double; YData: Variant);

    procedure ResetElapsedStartTime;

    property DataHigh         [const Index: Integer]: Double      read GetDataHigh          write SetDataHigh;
    property DataLow          [const Index: Integer]: Double      read GetDataLow           write SetDataLow;
    property DataOpen         [const Index: Integer]: Double      read GetDataOpen          write SetDataOpen;
    property DataClose        [const Index: Integer]: Double      read GetDataClose         write SetDataClose;

    property DataBarVisible   [const Index: Integer]: Boolean     read GetDataBarVisible    write SetDataBarVisible;
    property DataBarReference [const Index: Integer]: Double      read GetDataBarReference  write SetDataBarReference;
    property DataBarWidth     [const Index: Integer]: Double      read GetDataBarWidth      write SetDataBarWidth;
    property DataBarPenColor  [const Index: Integer]: TColor      read GetDataBarPenColor   write SetDataBarPenColor;
    property DataBarPenWidth  [const Index: Integer]: Integer     read GetDataBarPenWidth   write SetDataBarPenWidth;
    property DataBarPenStyle  [const Index: Integer]: TPenStyle   read GetDataBarPenStyle   write SetDataBarPenStyle;
    property DataBarBrushColor[const Index: Integer]: TColor      read GetDataBarBrushColor write SetDataBarBrushColor;
    property DataBarBrushStyle[const Index: Integer]: TBrushStyle read GetDataBarBrushStyle write SetDataBarBrushStyle;

    property ElapsedStartTime        : Double                      read FElapsedStartTime        write FElapsedStartTime;
  published
    property FastDrawEnabled       : Boolean                       read FFastDrawEnabled         write SetFastDrawEnabled          default True;
    property InterpolationStyle    : TiPlotInterpolationStyle      read FInterpolationStyle      write SetInterpolationStyle       default ipistStraightLine;

    property FillEnabled             : Boolean                     read FFillEnabled             write SetFillEnabled              default False;
    property FillReference           : Double                      read FFillReference           write SetFillReference;
    property FillStyle               : TBrushStyle                 read FFillStyle               write SetFillStyle                default bsSolid;
    property FillColor               : TColor                      read FFillColor               write SetFillColor                default clBlack;
    property FillUseChannelColor     : Boolean                     read FFillUseChannelColor     write SetFillUseChannelColor      default True;

    property DigitalEnabled          : Boolean                     read FDigitalEnabled          write SetDigitalEnabled           default False;
    property DigitalReferenceStyle   : TiPlotDigitalReferenceStyle read FDigitalReferenceStyle   write SetDigitalReferenceStyle    default ipdrScale;
    property DigitalReferenceLow     : Double                      read FDigitalReferenceLow     write SetDigitalReferenceLow;
    property DigitalReferenceHigh    : Double                      read FDigitalReferenceHigh    write SetDigitalReferenceHigh;

    property HighLowStyle            : TiPlotHighLowStyle          read FHighLowStyle            write SetHighLowStyle             default iphlsOpenClose;
    property HighLowEnabled          : Boolean                     read FHighLowEnabled          write SetHighLowEnabled           default False;
    property HighLowBarColor         : TColor                      read FHighLowBarColor         write SetHighLowBarColor          default clBlue;
    property HighLowBarWidth         : Double                      read FHighLowBarWidth         write SetHighLowBarWidth;
    property HighLowOpenShow         : Boolean                     read FHighLowOpenShow         write SetHighLowOpenShow          default True;
    property HighLowOpenColor        : TColor                      read FHighLowOpenColor        write SetHighLowOpenColor         default clGreen;
    property HighLowOpenWidth        : Double                      read FHighLowOpenWidth        write SetHighLowOpenWidth;
    property HighLowOpenHeight       : Double                      read FHighLowOpenHeight       write SetHighLowOpenHeight;
    property HighLowCloseShow        : Boolean                     read FHighLowCloseShow        write SetHighLowCloseShow         default True;
    property HighLowCloseColor       : TColor                      read FHighLowCloseColor       write SetHighLowCloseColor        default clRed;
    property HighLowCloseWidth       : Double                      read FHighLowCloseWidth       write SetHighLowCloseWidth;
    property HighLowCloseHeight      : Double                      read FHighLowCloseHeight      write SetHighLowCloseHeight;
    property HighLowShadowColor      : TColor                      read FHighLowShadowColor      write SetHighLowShadowColor       default clGray;
    property HighLowBullishColor     : TColor                      read FHighLowBullishColor     write SetHighLowBullishColor      default clWhite;
    property HighLowBearishColor     : TColor                      read FHighLowBearishColor     write SetHighLowBearishColor      default clGray;

    property BarEnabled              : Boolean                     read FBarEnabled              write SetBarEnabled               default False;
    property BarPenUseChannelColor   : Boolean                     read FBarPenUseChannelColor   write SetBarPenUseChannelColor    default True;
    property BarBrushUseChannelColor : Boolean                     read FBarBrushUseChannelColor write SetBarBrushUseChannelColor  default True;

    property BarReference            : Double                      read GetBarReference          write SetBarReference;
    property BarWidth                : Double                      read GetBarWidth              write SetBarWidth;
    property BarPenColor             : TColor                      read GetBarPenColor           write SetBarPenColor              default clRed;
    property BarPenWidth             : Integer                     read GetBarPenWidth           write SetBarPenWidth              default 0;
    property BarPenStyle             : TPenStyle                   read GetBarPenStyle           write SetBarPenStyle              default psSolid;
    property BarBrushColor           : TColor                      read GetBarBrushColor         write SetBarBrushColor            default clRed;
    property BarBrushStyle           : TBrushStyle                 read GetBarBrushStyle         write SetBarBrushStyle            default bsSolid;

    {$IFDEF iVCL}
    property OPCXValueSource         : TiOPCXValueSourceStyle      read FOPCXValueSource         write FOPCXValueSource            default iopcxvsOPCServerTimeStamp;
   {$endif}
  end;

implementation

uses
{$ifdef iVCL} iPlotDataCursor,  iPlotDataCustomList;{$endif}
{$ifdef iCLX}QiPlotDataCursor, QiPlotDataCustomList;{$endif}

type
  TiPlotDataCursorAccess = class(TiPlotDataCursor)end;
  TiPlotAxisAccess       = class(TiPlotAxis      )end;
//****************************************************************************************************************************************************
constructor TiPlotChannel.Create(AOwner: TObject; AOnChange, AOnInsert, AOnRemove, AOnRename: TNotifyEvent);
begin
  inherited;
  FFillUseChannelColor     := True;
  FElapsedStartTime        := Now;

  FDigitalReferenceHigh    := 90;
  FDigitalReferenceLow     := 10;

  FBarPenUseChannelColor   := True;

⌨️ 快捷键说明

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