series.pas

来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 1,933 行 · 第 1/5 页

PAS
1,933
字号

Procedure TCustomSeries.SetInvertedStairs(Value:Boolean);
Begin
  SetBooleanProperty(FInvertedStairs,Value);
end;

Procedure TCustomSeries.SetAreaColor(Value:TColor);
Begin
  SetColorProperty(FAreaColor,Value);
end;

Procedure TCustomSeries.SetAreaBrushStyle(Value:TBrushStyle);
Begin
  FAreaBrush.Style:=Value;
end;

Function TCustomSeries.GetLineBrush:TBrushStyle;
Begin
  result:=Brush.Style;
end;

Procedure TCustomSeries.SetLineBrush(Value:TBrushStyle);
Begin
  Brush.Style:=Value;
end;

type TPointerAccess=class(TSeriesPointer);

Procedure TeePointerDrawLegend(Pointer:TSeriesPointer; AColor:TColor;
                               Const Rect:TRect; DrawPen:Boolean);
var tmpHoriz : Integer;
    tmpVert  : Integer;
begin
  if Assigned(Pointer.ParentChart) then
  begin
    TPointerAccess(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;

Procedure TCustomSeries.DrawLegendShape(ValueIndex:Integer; Const Rect:TRect);
Var tmpColor : TColor;

  Procedure DrawLine(DrawRectangle:Boolean);
  begin
    if TCustomChart(ParentChart).Legend.Symbol.DefaultPen then
       LinePrepareCanvas(ParentChart.Canvas,tmpColor);
    With ParentChart.Canvas do
    if DrawRectangle then Rectangle(Rect)
    else
    With Rect do DoHorizLine(Left,Right,(Top+Bottom) div 2);
  end;

begin
  if ValueIndex=TeeAllValues then tmpColor:=SeriesColor
                             else tmpColor:=LegendItemColor(ValueIndex); // 6.0

  if FPointer.Visible then
  begin
    if FDrawLine then DrawLine(False);
    TeePointerDrawLegend(Pointer,tmpColor,Rect,LinePen.Visible);
  end
  else
  if FDrawLine and (not FDrawArea) then
     DrawLine(ParentChart.View3D)
  else
     inherited
end;

procedure TCustomSeries.LinePrepareCanvas(tmpCanvas:TCanvas3D; tmpColor:TColor);
begin
  with tmpCanvas do
  begin
    if MonoChrome then tmpColor:=clWhite;

    if ParentChart.View3D then
    begin
      if Assigned(Self.Brush.Image.Graphic) then
         Brush.Bitmap:=Self.Brush.Image.Bitmap
      else
      begin
        Brush.Style:=LineBrush;
        Brush.Color:=tmpColor;
      end;

      AssignVisiblePen(LinePen);
    end
    else
    begin
      Brush.Style:=bsClear;
      AssignVisiblePenColor(LinePen,tmpColor);
    end;

    ParentChart.CheckPenWidth(tmpCanvas.Pen);
  end;
end;

Procedure TCustomSeries.SetParentChart(Const Value:TCustomAxisPanel);
begin
  inherited;
  if Assigned(FPointer) then FPointer.ParentChart:=Value;
end;

Function TCustomSeries.GetAreaBrushColor(AColor:TColor):TColor;
begin
  if ColorEachPoint or (FAreaColor=clTeeColor) then
     result:=AColor
  else
     result:=FAreaColor;
end;

procedure TCustomSeries.DrawValue(ValueIndex:Integer);
Var x : Integer;
    y : Integer;

  { calculate vertical pixel }
  Function CalcYPosLeftRight(Const YLimit:Double; AnotherIndex:Integer):Integer;
  var tmpPredValueX : Double;
      tmpPredValueY : Double;
      tmpDif        : Double;
  begin
    tmpPredValueX:=XValues.Value[AnotherIndex];
    tmpDif:=XValues.Value[ValueIndex]-tmpPredValueX;
    With ParentChart do
    if tmpDif=0 then result:=CalcYPos(AnotherIndex)
    else
    begin
      tmpPredValueY:=YValues.Value[AnotherIndex];
      result:=CalcYPosValue( 1.0*tmpPredValueY+(YLimit-tmpPredValueX)*
                             (YValues.Value[ValueIndex]-tmpPredValueY)/tmpDif );
    end;
  end;

var tmpColor    : TColor;
    IsLastValue : Boolean;

   Procedure InternalDrawArea(BrushColor:TColor);

     Function RectFromPoints(const P:TFourPoints):TRect;
     begin
       with result do
       begin
         Left  :=Math.Min(P[3].X,Math.Min(P[2].X,Math.Min(P[0].X,P[1].X)));
         Top   :=Math.Min(P[3].Y,Math.Min(P[2].Y,Math.Min(P[0].Y,P[1].Y)));
         Right :=Math.Max(P[3].X,Math.Max(P[2].X,Math.Max(P[0].X,P[1].X)));
         Bottom:=Math.Max(P[3].Y,Math.Max(P[2].Y,Math.Max(P[0].Y,P[1].Y)));
       end;

       if ParentChart.View3D then
          result:=ParentChart.Canvas.CalcRect3D(result,StartZ); { 5.03 }
     end;

   var tmpY      : Integer;
       tmpBottom : Integer;
       tmpR      : TRect;
       tmpBlend  : TTeeBlend;
       tmpP      : TFourPoints;
       tmpMax    : Integer;
       tmpMin    : Integer;
       tmpColor2 : TColor;
   begin
     With ParentChart do
     Begin
       tmpColor2:=AreaChartBrush.Color;
       if AreaChartBrush.Color=clTeeColor then tmpColor2:=SeriesColor;
       SetBrushCanvas(BrushColor,FAreaBrush,tmpColor2);

       if View3D and IsLastValue then { to-do: not always ! }
          if YMandatory then
             Canvas.RectangleZ(X,Y,BottomPos,StartZ,EndZ)
          else
             Canvas.RectangleY(X,Y,BottomPos,StartZ,EndZ);

       if Stairs then
       begin
         if FInvertedStairs then
         begin
           if YMandatory then tmpY:=Y
                         else tmpY:=X;
           tmpBottom:=BottomPos;
         end
         else
         begin
           if YMandatory then tmpY:=OldY
                         else tmpY:=OldX;
           tmpBottom:=OldBottomPos;
         end;

         if YMandatory then tmpR:=TeeRect(OldX,tmpBottom,X+1,tmpY)
                       else tmpR:=TeeRect(tmpBottom,OldY+1,tmpY+1,Y);

         With Canvas do
         begin
           if Transparency>0 then
              if View3D then
                 tmpBlend:=BeginBlending(RectFromRectZ(tmpR,StartZ),Transparency)  // 6.01
              else
                 tmpBlend:=BeginBlending(tmpR,Transparency)  // 6.01
           else
              tmpBlend:=nil;

           if View3D then
           begin
             RectangleWithZ(tmpR,StartZ);
             if SupportsFullRotation then RectangleWithZ(tmpR,EndZ);
           end
           else
           begin
             if FGradient.Visible then
             begin
               FGradient.Draw(Canvas,tmpR);  // 5.03
               if Pen.Style<>psClear then
               begin
                 Brush.Style:=bsClear;
                 Rectangle(tmpR);
               end;
             end
             else Rectangle(tmpR);
           end;

           if Transparency>0 then
              EndBlending(tmpBlend);
         end;


         if LinePen.Visible and (not AreaLinesPen.Visible) then
         begin
           Canvas.AssignVisiblePen(LinePen);
           if YMandatory then
              if InvertedStairs then
              begin
                Canvas.LineWithZ(OldX,Y,X,Y,StartZ);
                Canvas.LineWithZ(OldX,OldY,OldX,Y,StartZ);
              end
              else
              begin
                Canvas.LineWithZ(OldX,OldY,X,OldY,StartZ);
                Canvas.LineWithZ(X-1,OldY,X-1,Y,StartZ);
              end
           else
              if InvertedStairs then
              begin
                Canvas.LineWithZ(X,OldY,X,Y,StartZ);
                Canvas.LineWithZ(OldX,OldY,X,OldY,StartZ);
              end
              else
              begin
                Canvas.LineWithZ(OldX,OldY,OldX,Y,StartZ);
                Canvas.LineWithZ(OldX,Y,X,Y,StartZ);
              end;
         end;

       end
       else // not in "stairs" mode...
       With Canvas do
       begin

         if YMandatory then
         begin
           tmpP[0]:=TeePoint(OldX,OldBottomPos);
           tmpP[3]:=TeePoint(X,BottomPos);
         end
         else
         begin
           tmpP[0]:=TeePoint(OldBottomPos,OldY);
           tmpP[3]:=TeePoint(BottomPos,Y);
         end;

         tmpP[1]:=TeePoint(OldX,OldY);
         tmpP[2]:=TeePoint(X,Y);

         if Transparency>0 then
            tmpBlend:=Canvas.BeginBlending(RectFromPoints(tmpP),Transparency)
         else
            tmpBlend:=nil;

         if View3D then
         begin
           if FGradient.Visible then FGradient.Draw(Canvas,tmpP,StartZ)
                                else PlaneWithZ(tmpP,StartZ);
         end
         else // 5.02
         begin
           if FGradient.Visible then { 5.03 }
           begin
             ClipPolygon(Canvas,tmpP,4);

             tmpMax:=CalcPosValue(MandatoryValueList.MaxValue);
             tmpMin:=CalcPosValue(MandatoryValueList.MinValue);

             if YMandatory then tmpR:=TeeRect(OldX,tmpMax,X,tmpMin)
                           else tmpR:=TeeRect(tmpMin,OldY,tmpMax,Y);

             FGradient.Draw(Canvas,tmpR);
             UnClipRectangle;

             Brush.Style:=bsClear;

             if Pen.Style<>psClear then
                if YMandatory then DoVertLine(OldX,OldY,OldBottomPos)
                              else DoHorizLine(OldBottomPos,OldX,OldY);

           end
           else Polygon(tmpP);
         end;

         if Transparency>0 then
            Canvas.EndBlending(tmpBlend);

         if SupportsFullRotation then PlaneWithZ(tmpP,EndZ);

         if LinePen.Visible then
         begin
           AssignVisiblePen(LinePen);
           LineWithZ(OldX,OldY,X,Y,StartZ);
         end;
       end;
     end;
   end;

   Procedure DrawPoint(DrawOldPointer:Boolean);
   var tmpPoint     : TPoint;
       tmpOldP      : TPoint;
       tmpDifX      : Integer;
       P4           : TFourPoints;
       OldDarkColor : TColor;
       tmpDark3D    : Boolean;
   begin
     if ((x<>OldX) or (y<>OldY)) and (tmpColor<>clNone) then { <-- if not null }
     with ParentChart,Canvas do
     begin
       if View3D then
       Begin
         { 3D }
         if DrawArea or FDrawLine then
         Begin

           AssignVisiblePen(LinePen);
           if LinePen.Visible then CheckPenWidth(Pen);

           if ColorEachLine or DrawArea then
              OldDarkColor:=GetAreaBrushColor(tmpColor)
           else
              OldDarkColor:=SeriesColor;  // 6.01

           if Brush.Color<>OldDarkColor then
              Brush.Color:=OldDarkColor;

           if Brush.Style<>LineBrush then
              Brush.Style:=LineBrush;

           if Assigned(Self.Brush.Image.Graphic) then
              Brush.Bitmap:=Self.Brush.Image.Bitmap;

           tmpPoint.X:=X;
           tmpPoint.Y:=Y;
           tmpOldP.X :=OldX;
           tmpOldP.Y :=OldY;

           if Stairs then
           Begin
             if FInvertedStairs then { or LastValue=FirstValueIndex }

⌨️ 快捷键说明

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