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

📄 iplotlegend.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 5 页
字号:

          for x := 0 to FItemList.Count - 1 do
            begin
              LegendItem := FItemList.Objects[x] as TiPlotLegendItem;
              iChannel   := LegendItem.Channel;
              LegendItem.MaxHeight := ACharHeight;
              if Trim(iChannel.TitleText) <> '' then AText := iChannel.TitleText else AText := iChannel.Name;

              Font.Assign(FFont);             GetNewMax(TextWidth(AText), FMaxWidthChannelLabel);
              Font.Assign(FSelectedItemFont); GetNewMax(TextWidth(AText), FMaxWidthChannelLabel);
            end;
        end
      else
        begin
          ACharWidth := TextWidth ('0');
          FMaxWidthChannelLabel := Round(FChannelNameMaxWidth * ACharWidth);
          for x := 0 to FItemList.Count - 1 do
            begin
              MaxHeight := 0;

              LegendItem := FItemList.Objects[x] as TiPlotLegendItem;
              iChannel   := LegendItem.Channel;

              Font.Assign(FFont);             GetNewMax(iTextHeightFixedWidth(Canvas, iChannel.TitleText, FMaxWidthChannelLabel), MaxHeight);
              Font.Assign(FSelectedItemFont); GetNewMax(iTextHeightFixedWidth(Canvas, iChannel.TitleText, FMaxWidthChannelLabel), MaxHeight);

              LegendItem.MaxHeight := MaxHeight;
            end;
        end;
    end;

  for x := 0 to FItemList.Count - 1 do
    begin
      LegendItem := FItemList.Objects[x] as TiPlotLegendItem;
      GetNewMax(LegendItem.MaxHeight, FMaxItemHeight);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.CalcColumnTitles(Canvas: TCanvas);
begin
  with Canvas, DrawRect do
    begin
      if FColumnTitlesVisible then
        begin
          Font.Assign(FColumnTitlesFont);
          FColumnTitlesHeightPixels := TextHeight('0');
          FColumnTitlesMarginPixels := FColumnTitlesHeightPixels div 4;

                                     GetNewMax(TextWidth(GetTranslation(FCaptionColumnTitle )), FMaxWidthChannelLabel);
          if FShowColumnXName   then GetNewMax(TextWidth(GetTranslation(FCaptionColumnXName )), FMaxWidthXName);
          if FShowColumnYName   then GetNewMax(TextWidth(GetTranslation(FCaptionColumnYName )), FMaxWidthYName);
          if FShowColumnXValue2 then GetNewMax(TextWidth(GetTranslation(FCaptionColumnXValue)), FMaxWidthXValue);
          if FShowColumnYValue2 then GetNewMax(TextWidth(GetTranslation(FCaptionColumnYValue)), FMaxWidthYValue);
          if FShowColumnYMax    then GetNewMax(TextWidth(GetTranslation(FCaptionColumnYMax  )), FMaxWidthYMax);
          if FShowColumnYMin    then GetNewMax(TextWidth(GetTranslation(FCaptionColumnYMin  )), FMaxWidthYMin);
          if FShowColumnYMean   then GetNewMax(TextWidth(GetTranslation(FCaptionColumnYMean )), FMaxWidthYMean);
        end
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.CalcRects(Canvas: TCanvas);
var
  x                   : Integer;
  ACharWidth          : Integer;
  ACharHeight         : Integer;
  iChannel            : TiPlotChannelCustom;
  CurrentX            : Integer;
  LegendItem          : TiPlotLegendItem;
  ItemCount           : Integer;

  CurrentTop          : Integer;

  RowCount            : Integer;
  MaxRowHeight        : Integer;
  MaxCurrentRowHeight : Integer;

  ColumnIndex         : Integer;
  RowIndex            : Integer;

  MarginTopPixels     : Integer;
  MarginBottomPixels  : Integer;
  MarginLeftPixels    : Integer;
  MarginRightPixels   : Integer;

  MaxColCount         : Integer;
  MaxRowCount         : Integer;
  MaxWidth            : Integer;
  MaxHeight           : Integer;

  ActualWidth         : Integer;
  ActualHeight        : Integer;
  ActualColSpacing    : Integer;
  ActualRowCount      : Integer;
begin
  with Canvas, DrawRect do
    begin
      Font.Assign(FFont);

      FColumnList.Clear;

      ACharWidth                := TextWidth ('0');
      ACharHeight               := TextHeight('0');

      ActualRowCount            := 0;

      MarginTopPixels           := Round(FMarginTop   *ACharHeight);
      MarginBottomPixels        := Round(FMarginBottom*ACharHeight);
      MarginLeftPixels          := Round(FMarginLeft  *ACharWidth);
      MarginRightPixels         := Round(FMarginRight *ACharWidth);

      FInnerRect                := Rect(Left + MarginLeftPixels, Top + MarginTopPixels, Right - MarginRightPixels, Bottom - MarginBottomPixels);

      FColumnSpacingPixels      := Round(ACharWidth * FColumnSpacing);
      FRowSpacingPixels         := Round(ACharHeight*FWrapRowSpacingMin);
      FWrapSpacingPixels        := Round(ACharHeight*FWrapColSpacingMin);

      FItemHeight               := ACharHeight;
      FMaxItemHeight            := 0;

      FColumnWidth              := 0;

      FColumnTitlesHeightPixels := 0;
      FColumnTitlesMarginPixels := 0;

      FMaxWidthLine             := 0;
      FMaxWidthMarker           := 0;
      FMaxWidthChannelLabel     := 0;
      FMaxWidthXName            := 0;
      FMaxWidthYName            := 0;
      FMaxWidthXValue           := 0;
      FMaxWidthYValue           := 0;
      FMaxWidthYMax             := 0;
      FMaxWidthYMin             := 0;
      FMaxWidthYMean            := 0;

      FShowColumnXValue2        := FShowColumnXValue or FCursorAllChannels;
      FShowColumnYValue2        := FShowColumnYValue or FCursorAllChannels;

      ClearItemList;
      for x := 0 to TiPlotComponentAccess(Owner).ChannelCount - 1 do
        begin
          iChannel := TiPlotComponentAccess(Owner).Channel[x] as TiPlotChannelCustom;
          if iChannel.VisibleInLegend then
            begin
              LegendItem := TiPlotLegendItem.Create;
              LegendItem.Channel := iChannel;
              FItemList.AddObject('', LegendItem);
            end;
        end;

      ItemCount := FItemList.Count;

      if FItemViewStartIndex < 0           then FItemViewStartIndex := 0;
      if FItemViewStartIndex > ItemCount-1 then FItemViewStartIndex := ItemCount-1;

      CalcColumnChannelName(Canvas);
      CalcColumnTitles     (Canvas);

      if FShowColumnLine    then GetNewMax(LineWidth + 3, FMaxWidthLine);
      if FShowColumnMarker  then GetNewMax(LineWidth + 3, FMaxWidthMarker);
      //----------------------------------------------------------------------------------------------------------------
      Font.Assign(FFont);
      for x := 0 to ItemCount - 1 do
        begin
          LegendItem := (FItemList.Objects[x] as TiPlotLegendItem);

          if FShowColumnXName   then GetNewMax(TextWidth(GetXAxisNameText (LegendItem.Channel)), FMaxWidthXName);
          if FShowColumnYName   then GetNewMax(TextWidth(GetYAxisNameText (LegendItem.Channel)), FMaxWidthYName);

          if FCursorAllChannels then
            begin
              if Assigned(LegendItem.Channel.XAxis) then GetNewMax(TiPlotAxisAccess(LegendItem.Channel.XAxis).GetRequiredCursorLength(Canvas, FFont), FMaxWidthXValue);
              if Assigned(LegendItem.Channel.YAxis) then GetNewMax(TiPlotAxisAccess(LegendItem.Channel.YAxis).GetRequiredCursorLength(Canvas, FFont), FMaxWidthYValue);

              GetNewMax(Round(Length(LegendItem.Channel.DataCursorXText)*ACharWidth), FMaxWidthXValue);
              GetNewMax(Round(Length(LegendItem.Channel.DataCursorYText)*ACharWidth), FMaxWidthYValue);
            end
          else
            begin
              if Assigned(LegendItem.Channel.XAxis) then GetNewMax(TiPlotAxisAccess(LegendItem.Channel.XAxis).GetRequiredLegendLength(Canvas, FFont), FMaxWidthXValue);
              if Assigned(LegendItem.Channel.YAxis) then GetNewMax(TiPlotAxisAccess(LegendItem.Channel.YAxis).GetRequiredLegendLength(Canvas, FFont), FMaxWidthYValue);

              if FShowColumnXValue2 then GetNewMax(TextWidth(GetXAxisValueText(LegendItem.Channel)), FMaxWidthXValue);
              if FShowColumnYValue2 then GetNewMax(TextWidth(GetYAxisValueText(LegendItem.Channel)), FMaxWidthYValue);
            end;

          if FShowColumnYMax    then GetNewMax(TextWidth(GetYAxisMaxText  (LegendItem.Channel)), FMaxWidthYMax);
          if FShowColumnYMin    then GetNewMax(TextWidth(GetYAxisMinText  (LegendItem.Channel)), FMaxWidthYMin);
          if FShowColumnYMean   then GetNewMax(TextWidth(GetYAxisMeanText (LegendItem.Channel)), FMaxWidthYMean);
        end;

      CurrentX := 0;

      FColumnStartLine    := CurrentX; if FShowColumnLine    then CurrentX := CurrentX + FMaxWidthLine         + FColumnSpacingPixels;
      FColumnStartMarker  := CurrentX; if FShowColumnMarker  then CurrentX := CurrentX + FMaxWidthMarker       + FColumnSpacingPixels;
      FColumnStartChannel := CurrentX;                            CurrentX := CurrentX + FMaxWidthChannelLabel + FColumnSpacingPixels;
      FColumnStartXName   := CurrentX; if FShowColumnXName   then CurrentX := CurrentX + FMaxWidthXName        + FColumnSpacingPixels;
      FColumnStartYName   := CurrentX; if FShowColumnYName   then CurrentX := CurrentX + FMaxWidthYName        + FColumnSpacingPixels;
      FColumnStartXValue  := CurrentX; if FShowColumnXValue2 then CurrentX := CurrentX + FMaxWidthXValue       + FColumnSpacingPixels;
      FColumnStartYValue  := CurrentX; if FShowColumnYValue2 then CurrentX := CurrentX + FMaxWidthYValue       + FColumnSpacingPixels;
      FColumnStartYMax    := CurrentX; if FShowColumnYMax    then CurrentX := CurrentX + FMaxWidthYMax         + FColumnSpacingPixels;
      FColumnStartYMin    := CurrentX; if FShowColumnYMin    then CurrentX := CurrentX + FMaxWidthYMin         + FColumnSpacingPixels;
      FColumnStartYMean   := CurrentX; if FShowColumnYMean   then CurrentX := CurrentX + FMaxWidthYMean        + FColumnSpacingPixels;

      FItemWidth := CurrentX - FColumnSpacingPixels;

      FColumnTitlesRect  := Rect(FInnerRect.Left,  FInnerRect.Top,                                       FInnerRect.Right, FInnerRect.Top + FColumnTitlesHeightPixels);
      FItemsRect         := Rect(FInnerRect.Left,  FColumnTitlesRect.Bottom + FColumnTitlesMarginPixels, FInnerRect.Right, FInnerRect.Bottom);

      MaxWidth  := FItemsRect.Right  - FItemsRect.Left;
      MaxHeight := FItemsRect.Bottom - FItemsRect.Top;

      if Horizontal then MaxWidth := MaxWidth - 25;

      MaxColCount := (MaxWidth  + FWrapSpacingPixels) div (FItemWidth     + FWrapSpacingPixels);
      MaxRowCount := (MaxHeight + FRowSpacingPixels ) div (FMaxItemHeight + FRowSpacingPixels);

      if MaxColCount < 1 then MaxColCount := 1;
      if MaxRowCount < 1 then MaxRowCount := 1;

      if FWrapColAutoCountEnabled then                   FActualWrapColCount := FWrapColAutoCountMax
        else                                             FActualWrapColCount := FWrapColDesiredCount;

      if FWrapRowAutoCountEnabled  then                  FActualWrapRowCount := FWrapRowAutoCountMax
        else                                             FActualWrapRowCount := FWrapRowDesiredCount;
      //---------------------------------------------------------------------------------------------------------
      if Horizontal then
        begin                                                                                           
          if FActualWrapColCount > MaxColCount          then FActualWrapColCount := MaxColCount;

          if FWrapRowAutoCountEnabled then RowCount := (ItemCount + FActualWrapColCount -1) div FActualWrapColCount
            else                           RowCount := FActualWrapRowCount;

          if RowCount            > FActualWrapRowCount                       then RowCount := FActualWrapRowCount;
          if (RowCount < 3) and ((RowCount*FActualWrapColCount) < ItemCount) then RowCount := 3;

          if FWrapColAutoCountEnabled then if FActualWrapColCount > (ItemCount + RowCount -1) div RowCount then
            FActualWrapColCount := (ItemCount + RowCount -1) div RowCount
        end
      else
        begin
          if FWrapColAutoCountEnabled then FActualWrapColCount := (ItemCount + MaxRowCount -1) div MaxRowCount;
          if FActualWrapColCount > FWrapColAutoCountMax then FActualWrapColCount := FWrapColAutoCountMax;

          RowCount := MaxRowCount;

          if RowCount > ItemCount                                            then RowCount := ItemCount;
          if RowCount > FActualWrapRowCount                                  then RowCount := FActualWrapRowCount;
          if (RowCount < 3) and ((RowCount*FActualWrapColCount) < ItemCount) then RowCount := 3;
        end;
      //---------------------------------------------------------------------------------------------------------
      ColumnIndex        := 1;
      RowIndex           := 1;
      CurrentTop         := FItemsRect.Top;
      FItemViewStopIndex := ItemCount-1;

⌨️ 快捷键说明

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