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

📄 iplotlegend.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    property CaptionColumnYMin           : String                            read FCaptionColumnYMin           write SetCaptionColumnYMin;
    property CaptionColumnYMean          : String                            read FCaptionColumnYMean          write SetCaptionColumnYMean;

    property Font                        : TFont                             read FFont                        write SetFont;
    property ColumnSpacing               : Double                            read FColumnSpacing               write SetColumnSpacing;
    property RowSpacing                  : Double                            read FWrapRowSpacingMin           write SetWrapRowSpacingMin;

    property WrapColDesiredCount         : Integer                           read FWrapColDesiredCount         write SetWrapColDesiredCount;
    property WrapColAutoCountEnabled     : Boolean                           read FWrapColAutoCountEnabled     write SetWrapColAutoCountEnabled;
    property WrapColAutoCountMax         : Integer                           read FWrapColAutoCountMax         write SetWrapColAutoCountMax;
    property WrapColSpacingMin           : Double                            read FWrapColSpacingMin           write SetWrapColSpacingMin;
    property WrapColSpacingAuto          : Boolean                           read FWrapColSpacingAuto          write SetWrapColSpacingAuto;

    property WrapRowDesiredCount         : Integer                           read FWrapRowDesiredCount         write SetWrapRowDesiredCount;
    property WrapRowAutoCountEnabled     : Boolean                           read FWrapRowAutoCountEnabled     write SetWrapRowAutoCountEnabled;
    property WrapRowAutoCountMax         : Integer                           read FWrapRowAutoCountMax         write SetWrapRowAutoCountMax;
    property WrapRowSpacingMin           : Double                            read FWrapRowSpacingMin           write SetWrapRowSpacingMin;
    property WrapRowSpacingAuto          : Boolean                           read FWrapRowSpacingAuto          write SetWrapRowSpacingAuto;

    property ColumnTitlesVisible         : Boolean                           read FColumnTitlesVisible         write SetColumnTitlesVisible          default False;
    property ColumnTitlesFont            : TFont                             read FColumnTitlesFont            write SetColumnTitlesFont;
    property ChannelNameMaxWidth         : Double                            read FChannelNameMaxWidth         write SetChannelNameMaxWidth;
    property ChannelNameColorStyle       : TiPlotLegendChannelNameColorStyle read FChannelNameColorStyle       write SetChannelNameColorStyle        default iplcncsFont;
  end;

implementation

uses                                                                                      
{$ifdef iVCL} iPlotManagers,  iPlotAxis,  iPlotChannel,  iXYPlotChannel,  iPlotComponent;{$endif}
{$ifdef iCLX}QiPlotManagers, QiPlotAxis, QiPlotChannel, QiXYPlotChannel, QiPlotComponent;{$endif}

const
  LineWidth = 13;

type
  TiPlotChannelCustomAccess = class(TiPlotChannelCustom) end;
  TiPlotAxisAccess          = class(TiPlotAxis         ) end;
  TiPlotComponentAccess     = class(TiPlotComponent    )end;
//****************************************************************************************************************************************************
constructor TiPlotLegend.Create(AOwner: TObject; AOnChange, AOnInsert, AOnRemove, AOnRename: TNotifyEvent);
begin
  inherited;

  FMarginLeft    := 1;
  FMarginRight   := 1;
  FMarginBottom  := 1;
  FMarginTop     := 1;

  FBackGroundColor         := clGray;
  FBackGroundTransparent   := True;
  FColumnSpacing           := 0.5;
  FShowColumnLine          := True;

  FWrapColDesiredCount     := 1;
  FWrapRowDesiredCount     := 5;

  FWrapColAutoCountMax     := 100;
  FWrapRowAutoCountMax     := 100;

  FWrapColAutoCountEnabled := False;
  FWrapRowAutoCountEnabled := True;

  FWrapColSpacingAuto      := True;
  FWrapRowSpacingAuto      := False;

  FWrapColSpacingMin       := 2;
  FWrapRowSpacingMin       := 0.25;

  FCaptionColumnTitle      := 'Title';
  FCaptionColumnXName      := 'X-Axis';
  FCaptionColumnYName      := 'Y-Axis';
  FCaptionColumnXValue     := 'X';
  FCaptionColumnYValue     := 'Y';
  FCaptionColumnYMax       := 'Y-Max';
  FCaptionColumnYMin       := 'Y-Min';
  FCaptionColumnYMean      := 'Y-Mean';

  FSelectedItemBackGroundColor := clYellow;

  Horizontal          := False;

  FItemList           := TStringList.Create;
  FColumnList         := TStringList.Create;

  FFont             := TFont.Create; FFont.OnChange             := TriggerChange; FFont.Color             := clWhite;
  FSelectedItemFont := TFont.Create; FSelectedItemFont.OnChange := TriggerChange; FSelectedItemFont.Color := clBlack;
  FColumnTitlesFont := TFont.Create; FColumnTitlesFont.OnChange := TriggerChange; FColumnTitlesFont.Color := clAqua; FColumnTitlesFont.Style := [fsBold];

  FUpButton   := TiPlotLegendButton.Create(Owner, nil, nil, nil, nil);
  with FUpButton do
    begin
      TimerEnabled := True;
      OnClick      := UpButtonClick;
      OnInvalidate := ButtonInvalidate;
    end;

  FDownButton := TiPlotLegendButton.Create(Owner, nil, nil, nil, nil);
  with FDownButton do
    begin
      TimerEnabled := True;
      OnClick      := DownButtonClick;
      OnInvalidate := ButtonInvalidate;
    end;
end;
//****************************************************************************************************************************************************
destructor TiPlotLegend.Destroy;
begin
  ClearItemList;

  FItemList.Free;
  FColumnList.Free;

  FFont.Free;
  FSelectedItemFont.Free;
  FColumnTitlesFont.Free;

  FUpButton.Free;
  FDownButton.Free;
  inherited;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.ClearItemList;
begin
  while FItemList.Count <> 0 do
    begin
      FItemList.Objects[0].Free;
      FItemList.Delete(0);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.AddMenuItems(PopupMenu: TPopUpMenu);
begin
  inherited AddMenuItems(PopupMenu);
  AddEditMenuItems(PopupMenu);
end;
//****************************************************************************************************************************************************
function TiPlotLegend.GetMouseObject(X, Y: Integer): TiPlotObject;
var
  i        : Integer;
  iChannel : TiPlotChannelCustom;
begin
  Result := inherited GetMouseObject(X, Y);

  if      PtInRect(FUpButton.DrawRect,   Point(X, Y)) then Result := FUpButton
  else if PtInRect(FDownButton.DrawRect, Point(X, Y)) then Result := FDownButton
  else
  for i := 0 to FItemList.Count-1 do
    begin
      iChannel := (FItemList.Objects[i] as TiPlotLegendItem).Channel;
      if not iChannel.VisibleInLegend then Continue;
      if PtInRect(TiPlotChannelCustomAccess(iChannel).LegendRect, Point(X, Y)) then
        begin
          Result := iChannel;
          Break;
        end
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.SetMarginBottom               (const Value:Double );begin SetDoubleProperty (Value,FMarginBottom,               TriggerChange);end;
procedure TiPlotLegend.SetMarginLeft                 (const Value:Double );begin SetDoubleProperty (Value,FMarginLeft,                 TriggerChange);end;
procedure TiPlotLegend.SetMarginRight                (const Value:Double );begin SetDoubleProperty (Value,FMarginRight,                TriggerChange);end;
procedure TiPlotLegend.SetMarginTop                  (const Value:Double );begin SetDoubleProperty (Value,FMarginTop,                  TriggerChange);end;
procedure TiPlotLegend.SetBackGroundColor            (const Value:TColor );begin SetColorProperty  (Value,FBackGroundColor,            TriggerChange);end;
procedure TiPlotLegend.SetBackGroundTransparent      (const Value:Boolean);begin SetBooleanProperty(Value,FBackGroundTransparent,      TriggerChange);end;
procedure TiPlotLegend.SetSelectedItemBackGroundColor(const Value:TColor );begin SetColorProperty  (Value,FSelectedItemBackGroundColor,TriggerChange);end;
procedure TiPlotLegend.SetShowColumnLine             (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnLine,             TriggerChange);end;
procedure TiPlotLegend.SetShowColumnMarker           (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnMarker,           TriggerChange);end;
procedure TiPlotLegend.SetShowColumnXAxisTitle       (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnXName,            TriggerChange);end;
procedure TiPlotLegend.SetShowColumnYAxisTitle       (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnYName,            TriggerChange);end;
procedure TiPlotLegend.SetShowColumnXValue           (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnXValue,           TriggerChange);end;
procedure TiPlotLegend.SetShowColumnYValue           (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnYValue,           TriggerChange);end;
procedure TiPlotLegend.SetShowColumnYMax             (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnYMax,             TriggerChange);end;
procedure TiPlotLegend.SetShowColumnYMin             (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnYMin,             TriggerChange);end;
procedure TiPlotLegend.SetShowColumnYMean            (const Value:Boolean);begin SetBooleanProperty(Value,FShowColumnYMean,            TriggerChange);end;
procedure TiPlotLegend.SetColumnSpacing              (const Value:Double );begin SetDoubleProperty (Value,FColumnSpacing,              TriggerChange);end;
procedure TiPlotLegend.SetColumnTitlesVisible        (const Value:Boolean);begin SetBooleanProperty(Value,FColumnTitlesVisible,        TriggerChange);end;
procedure TiPlotLegend.SetChannelNameMaxWidth        (const Value:Double );begin SetDoubleProperty (Value,FChannelNameMaxWidth,        TriggerChange);end;
procedure TiPlotLegend.SetWrapColAutoCountEnabled    (const Value:Boolean);begin SetBooleanProperty(Value,FWrapColAutoCountEnabled,    TriggerChange);end;
procedure TiPlotLegend.SetWrapRowAutoCountEnabled    (const Value:Boolean);begin SetBooleanProperty(Value,FWrapRowAutoCountEnabled,    TriggerChange);end;
procedure TiPlotLegend.SetWrapColAutoCountMax        (const Value:Integer);begin SetIntegerProperty(Value,FWrapColAutoCountMax,        TriggerChange);end;
procedure TiPlotLegend.SetWrapRowAutoCountMax        (const Value:Integer);begin SetIntegerProperty(Value,FWrapRowAutoCountMax,        TriggerChange);end;
procedure TiPlotLegend.SetWrapColSpacingMin          (const Value:Double );begin SetDoubleProperty (Value,FWrapColSpacingMin,          TriggerChange);end;
procedure TiPlotLegend.SetWrapRowSpacingMin          (const Value:Double );begin SetDoubleProperty (Value,FWrapRowSpacingMin,          TriggerChange);end;
procedure TiPlotLegend.SetWrapColSpacingAuto         (const Value:Boolean);begin SetBooleanProperty(Value,FWrapColSpacingAuto,         TriggerChange);end;
procedure TiPlotLegend.SetWrapRowSpacingAuto         (const Value:Boolean);begin SetBooleanProperty(Value,FWrapRowSpacingAuto,         TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnTitle         (const Value:String );begin SetStringProperty (Value,FCaptionColumnTitle,         TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnXAxisTitle    (const Value:String );begin SetStringProperty (Value,FCaptionColumnXName,         TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnXValue        (const Value:String );begin SetStringProperty (Value,FCaptionColumnXValue,        TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnYAxisTitle    (const Value:String );begin SetStringProperty (Value,FCaptionColumnYName,         TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnYMax          (const Value:String );begin SetStringProperty (Value,FCaptionColumnYMax,          TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnYMean         (const Value:String );begin SetStringProperty (Value,FCaptionColumnYMean,         TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnYMin          (const Value:String );begin SetStringProperty (Value,FCaptionColumnYMin,          TriggerChange);end;
procedure TiPlotLegend.SetCaptionColumnYValue        (const Value:String );begin SetStringProperty (Value,FCaptionColumnYValue,        TriggerChange);end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.SetFont            (const Value:TFont);begin FFont.Assign(Value);            end;
procedure TiPlotLegend.SetSelectedItemFont(const Value:TFont);begin FSelectedItemFont.Assign(Value);end;
procedure TiPlotLegend.SetColumnTitlesFont(const Value:TFont);begin FColumnTitlesFont.Assign(Value);end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.SetChannelNameColorStyle(const Value:TiPlotLegendChannelNameColorStyle);
begin
  if FChannelNameColorStyle <> Value then
    begin
      FChannelNameColorStyle := Value;
      TriggerChange(Self);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.SetWrapColDesiredCount(const Value:Integer);
var
  TempValue : Integer;
begin
  TempValue := Value;
  if TempValue < 1 then TempValue := 1;
  if FWrapColDesiredCount <> TempValue then
    begin
      FWrapColDesiredCount := TempValue;
      TriggerChange(Self);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.SetWrapRowDesiredCount(const Value:Integer);
var
  TempValue : Integer;
begin
  TempValue := Value;
  if TempValue < 1 then TempValue := 1;
  if FWrapRowDesiredCount <> TempValue then
    begin
      FWrapRowDesiredCount := TempValue;
      TriggerChange(Self);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.GetNewMax(Value: Integer; var Max: Integer);
begin
  if Value > Max then Max := Value;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.CalcColumnChannelName(Canvas: TCanvas);
var
  ACharWidth  : Integer;
  ACharHeight : Integer;
  AText       : String;
  x           : Integer;
  LegendItem  : TiPlotLegendItem;
  iChannel    : TiPlotChannelCustom;
  MaxHeight   : Integer;
begin
  with Canvas, DrawRect do
    begin
      Font.Assign(FFont);

      if FChannelNameMaxWidth = 0 then
        begin
          ACharHeight := TextHeight('0');
          FMaxWidthChannelLabel := 0;

⌨️ 快捷键说明

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