series.pas

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

PAS
1,933
字号
             begin
               if FDark3D then Brush.Color:=ApplyDark(Brush.Color,DarkColorQuantity);

               if YMandatory then
                  RectangleZ( tmpOldP.X,tmpOldP.Y, Y,StartZ,EndZ)
               else
                  RectangleY( tmpPoint.X, tmpPoint.Y,OldX,StartZ,EndZ);

               if FDark3D then Brush.Color:=OldDarkColor;

               if YMandatory then
                  RectangleY( tmpPoint.X, tmpPoint.Y,OldX,StartZ,EndZ)
               else
                  RectangleZ( X, tmpOldP.Y, Y, StartZ, EndZ);
             end
             else
             begin
               if YMandatory then
                  RectangleY( tmpOldP.X, tmpOldP.Y, X, StartZ, EndZ)
               else
                  RectangleZ( OldX, tmpOldP.Y, Y, StartZ, EndZ);

               if FDark3D then Brush.Color:=ApplyDark(Brush.Color,DarkColorQuantity);

               if YMandatory then
                  RectangleZ( tmpPoint.X,tmpPoint.Y, OldY,StartZ,EndZ)
               else
                  RectangleY( OldX, tmpPoint.Y, X,StartZ,EndZ);

               if FDark3D then Brush.Color:=OldDarkColor;
             end;
           end
           else
           begin
             if (FLineHeight>0) and (not FDrawArea) then
             begin
               P4[0]:=tmpPoint;
               P4[1]:=tmpOldP;
               P4[2].X:=tmpOldP.X;
               P4[2].Y:=tmpOldP.Y+FLineHeight;
               P4[3].X:=tmpPoint.X;
               P4[3].Y:=tmpPoint.Y+FLineHeight;
               PlaneFour3D(P4,StartZ,StartZ);
               if IsLastValue then
                  RectangleZ(tmpPoint.X,tmpPoint.Y,tmpPoint.Y+FLineHeight,StartZ,EndZ);
             end;

             tmpDark3D:=FDark3D and (not SupportsFullRotation);
             if tmpDark3D then
             begin
               tmpDifX:=tmpPoint.X-tmpOldP.X;
               if (tmpDifX<>0) and
                  (tmpDark3DRatio<>0) and
                  ((tmpOldP.Y-tmpPoint.Y)/tmpDifX > tmpDark3DRatio) then
               begin
                 Brush.Color:=ApplyDark(Brush.Color,DarkColorQuantity);
                 if (FLineHeight>0) and (not FDrawArea) then {special case}
                 begin
                   Inc(tmpPoint.Y,FLineHeight);
                   Inc(tmpOldP.Y,FLineHeight);
                 end;
               end;
             end;

             if Monochrome then Brush.Color:=clWhite;

             Plane3D(tmpPoint,tmpOldP,StartZ,EndZ);

             if tmpDark3D then Brush.Color:=OldDarkColor;
           end;
         end;
       end;

       if DrawArea then
       Begin { area }
         Brush.Color:=GetAreaBrushColor(tmpColor);

         if (FAreaLinesPen.Color=clTeeColor) or (not FAreaLinesPen.Visible) then
            AssignVisiblePenColor(FAreaLinesPen,tmpColor)
         else
            AssignVisiblePen(FAreaLinesPen);

         InternalDrawArea(Brush.Color);
       end
       else
       if (not View3D) and FDrawLine then
       Begin { line 2D }
         if ColorEachLine then LinePrepareCanvas(Canvas,tmpColor)
                          else LinePrepareCanvas(Canvas,SeriesColor);

         if Stairs then
         begin
           if FInvertedStairs then DoVertLine(OldX,OldY,Y)
                              else DoHorizLine(OldX,X,OldY);
           LineTo(X,Y);
         end
         else Line(OldX,OldY,X,Y);
       end;
     end;

     { pointers }
     if FPointer.Visible and DrawOldPointer then
     begin
       if OldColor<>clNone then { <-- if not null }
          DrawPointer(OldX,OldY,OldColor,Pred(ValueIndex));

       if IsLastValue and (tmpColor<>clNone) then {<-- if not null }
          DrawPointer(X,Y,tmpColor,ValueIndex);
     end;
   end;

var tmpFirst : Integer;
Begin
  With ParentChart.Canvas do
  Begin
    tmpColor:=ValueColor[ValueIndex];
    X:=CalcXPos(ValueIndex);
    Y:=CalcYPos(ValueIndex);

    if Pen.Color<>clBlack then { 5.02 }
       Pen.Color:=clBlack;

    if tmpColor<>Brush.Color then { 5.02 }
       Brush.Color:=tmpColor;

    if OldColor=clNone then { if null }
    begin
      OldX:=X;
      OldY:=Y;
    end;

    BottomPos:=GetOriginPos(ValueIndex);

    if DrawValuesForward then
    begin
      tmpFirst:=FirstValueIndex;
      IsLastValue:=ValueIndex=LastValueIndex;
    end
    else
    begin
      tmpFirst:=LastValueIndex;
      IsLastValue:=ValueIndex=FirstValueIndex;
    end;

    if ValueIndex=tmpFirst then { first point }
    Begin
      if FDark3D then
      With ParentChart do
         if SeriesWidth3D<>0 then
            tmpDark3DRatio:=Abs(SeriesHeight3D/SeriesWidth3D)
         else
            tmpDark3DRatio:=1;

      if (tmpFirst=FirstValueIndex) and (ValueIndex>0) then
      Begin  { previous point outside left }
        if FDrawArea then
        begin
          OldX:=CalcXPos(Pred(ValueIndex));
          OldY:=CalcYPos(Pred(ValueIndex));
          OldBottomPos:=GetOriginPos(Pred(ValueIndex));
        end
        else
        begin
          if GetHorizAxis.Inverted then OldX:=ParentChart.ChartRect.Right
                                   else OldX:=ParentChart.ChartRect.Left;

          if Stairs Then
             OldY:=CalcYPos(Pred(ValueIndex))
          else
          // fix 6.0 (from Kayhan YAL荌N kayhan.yalcin@finnet.gen.tr)
          if not GetVertAxis.Logarithmic then
             OldY:=CalcYPosLeftRight(GetHorizAxis.CalcPosPoint(OldX),Pred(ValueIndex))
          else
          begin
            OldX:=CalcXPos(Pred(ValueIndex));
            OldY:=CalcYPos(Pred(ValueIndex));
          end;

        end;

        if not IsNull(Pred(ValueIndex)) then DrawPoint(False);
      end;

      if IsLastValue and FPointer.Visible then
         DrawPointer(X,Y,tmpColor,ValueIndex);

      if SupportsFullRotation and FDrawArea and ParentChart.View3D then
         RectangleZ(X,Y,BottomPos,StartZ,EndZ);
    end
    else DrawPoint(True);

    OldX:=X;
    OldY:=Y;
    OldBottomPos:=BottomPos;
    OldColor:=tmpColor;
  end;
end;

Procedure TCustomSeries.DrawPointer(AX,AY:Integer; AColor:TColor; ValueIndex:Integer);
var tmpStyle : TSeriesPointerStyle;
begin
  TPointerAccess(FPointer).PrepareCanvas(ParentChart.Canvas,AColor);
  if Assigned(FOnGetPointerStyle) then tmpStyle:=FOnGetPointerStyle(Self,ValueIndex)
                                  else tmpStyle:=FPointer.Style;
  FPointer.Draw(AX,AY,AColor,tmpStyle);
end;

class Function TCustomSeries.GetEditorClass:String;
Begin
  result:='TCustomSeriesEditor'; { <-- dont translate ! }
end;

Procedure TCustomSeries.InternalCalcMargin(SameSide,Horizontal:Boolean; var A,B:Integer);
var tmp : Integer;
begin
  if Horizontal then
     TPointerAccess(FPointer).CalcHorizMargins(A,B)
  else
     TPointerAccess(FPointer).CalcVerticalMargins(A,B);

  if FDrawLine then
  begin
    if Stairs then
    begin
      A:=Math.Max(A,LinePen.Width);
      B:=Math.Max(B,LinePen.Width);
    end;

    if OutLine.Visible then { 5.02 }
    begin
      A:=Math.Max(A,OutLine.Width);
      B:=Math.Max(B,OutLine.Width);
    end;
  end;

  if Marks.Visible and SameSide then
  begin
    tmp:=Marks.Callout.Length+Marks.Callout.Distance;
    if YMandatory then A:=Math.Max(B,tmp)
                  else B:=Math.Max(A,tmp);
  end;
end;

Procedure TCustomSeries.CalcHorizMargins(Var LeftMargin,RightMargin:Integer);
begin
  inherited;
  InternalCalcMargin(not YMandatory,True,LeftMargin,RightMargin);
end;

Procedure TCustomSeries.CalcVerticalMargins(Var TopMargin,BottomMargin:Integer);
begin
  inherited;
  InternalCalcMargin(YMandatory,False,TopMargin,BottomMargin);

  if (LineHeight>0) and (not DrawArea) and ParentChart.View3D then
     if LineHeight>BottomMargin then BottomMargin:=LineHeight;
end;

Procedure TCustomSeries.SetDark3D(Value:Boolean);
begin
  SetBooleanProperty(FDark3D,Value);
end;

Procedure TCustomSeries.CalcZOrder;
Begin
  if FStacked=cssNone then inherited
                      else IZOrder:=ParentChart.MaxZOrder;
End;

Function TCustomSeries.PointOrigin(ValueIndex:Integer; SumAll:Boolean):Double;
var t         : Integer;
    tmpSeries : TChartSeries;
    tmp       : Double;
Begin
  result:=0;
  if Assigned(ParentChart) then
  with ParentChart do
  for t:=0 to SeriesCount-1 do
  Begin
    tmpSeries:=Series[t];
    if (not SumAll) and (tmpSeries=Self) then Break
    else
    With tmpSeries do
    if Active and SameClass(Self) and (Count>ValueIndex) then
    begin
      tmp:=GetOriginValue(ValueIndex);
      if tmp>0 then result:=result+tmp;
    end;
  end;
end;

Function TCustomSeries.CalcStackedPos(ValueIndex:Integer; Value:Double):Integer;

  Function AxisPosition:Integer;
  begin
    if YMandatory then result:=GetVertAxis.IEndPos
                  else result:=GetHorizAxis.IEndPos
  end;

var tmp : Double;
begin
  Value:=Value+PointOrigin(ValueIndex,False);
  if FStacked=cssStack then
     result:=Math.Min(AxisPosition,CalcPosValue(Value))
  else
  begin
    tmp:=PointOrigin(ValueIndex,True);
    if tmp<>0 then result:=CalcPosValue(Value*100.0/tmp)
              else result:=AxisPosition;
  end;
end;

Function TCustomSeries.GetOriginPos(ValueIndex:Integer):Integer;
Begin
  if (FStacked=cssNone) or (FStacked=cssOverlap) then
     if YMandatory then
     begin
       with GetVertAxis do
       if Inverted then result:=IStartPos else result:=IEndPos;
     end
     else
     begin
       with GetHorizAxis do
       if Inverted then result:=IEndPos else result:=IStartPos;
     end
  else
     result:=CalcStackedPos(ValueIndex,0);
end;

Function TCustomSeries.MaxXValue:Double;
var t : Integer;
Begin
  if YMandatory then result:=inherited MaxXValue
  else
  begin
    if FStacked=cssStack100 then result:=100
    else
    begin
      result:=inherited MaxXValue;
      if FStacked=cssStack then
      for t:=0 to Count-1 do
          result:=Math.Max(result,PointOrigin(t,False)+XValues.Value[t]);
    end;
  end;
end;

Function TCustomSeries.MinXValue:Double;
Begin
  if (not YMandatory) and (FStacked=cssStack100) then
     result:=0
  else
     result:=inherited MinXValue;
end;

Function TCustomSeries.MaxYValue:Double;
var t : Integer;
Begin
  if not YMandatory then result:=inherited MaxYValue
  else
  begin
    if FStacked=cssStack100 then result:=100
    else
    begin
      result:=inherited MaxYValue;
      if FStacked=cssStack then
      for t:=0 to Count-1 do
          result:=Math.Max(result,PointOrigin(t,False)+YValues.Value[t]);
    end;
  end;
end;

Function TCustomSeries.MinYValue:Double;
Begin
  if YMandatory and (FStacked=cssStack100) then
     result:=0
  else
     result:=inherited MinYValue;
end;

Function TCustomSeries.CalcXPos(ValueIndex:Integer):Integer;
Begin
  if (YMandatory) or (FStacked=cssNone) or (FStacked=cssOverlap) then
     result:=inherited CalcXPos(ValueIndex)
  else
 

⌨️ 快捷键说明

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