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

📄 series.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  inherited;
end;

function TCustomSeries.DoGetPointerStyle(ValueIndex:Integer):TSeriesPointerStyle;
begin
  if Assigned(FOnGetPointerStyle) then
     result:=FOnGetPointerStyle(Self,ValueIndex)
  else
     result:=Pointer.Style;
end;

Function TCustomSeries.ClickedPointer( ValueIndex,tmpX,tmpY:Integer;
                                       x,y:Integer):Boolean;
begin
  PreparePointer(ValueIndex); // 7.0

  result:=(DoGetPointerStyle(ValueIndex)<>psNothing) and
          (Abs(tmpX-X)<FPointer.HorizSize) and
          (Abs(tmpY-Y)<FPointer.VertSize);
end;

Procedure TCustomSeries.Assign(Source:TPersistent);
begin
  if Source is TCustomSeries then
  With TCustomSeries(Source) do
  begin
    Self.ClickableLine   :=ClickableLine;
    Self.AreaChartBrush  :=FAreaBrush;
    Self.FAreaColor      :=FAreaColor;
    Self.AreaLinesPen    :=AreaLinesPen;
    Self.FColorEachLine  :=ColorEachLine;
    Self.FDark3D         :=FDark3D;
    Self.FDrawArea       :=FDrawArea;
    Self.FDrawLine       :=FDrawLine;
    Self.FInvertedStairs :=FInvertedStairs;
    Self.FLineHeight     :=FLineHeight;
    Self.Pointer         :=FPointer;
    Self.FStacked        :=FStacked;
    Self.FStairs         :=FStairs;
    Self.OutLine         :=OutLine;
    Self.Shadow          :=Shadow;
    Self.FTransparency   :=FTransparency;
    Self.Gradient        :=FGradient;
  end;

  inherited;
end;

Function TCustomSeries.Clicked(x,y:Integer):Integer;
var OldXPos  : Integer;
    OldYPos  : Integer;
    tmpX     : Integer;
    tmpY     : Integer;
    P        : TPoint;

    Function CheckPointInLine:Boolean;

      Function PointInVertLine(x0,y0,y1:Integer):Boolean;
      begin
        result:=PointInLine(P,x0,y0,x0,y1);
      end;

      Function PointInHorizLine(x0,y0,x1:Integer):Boolean;
      begin
        result:=PointInLine(P,x0,y0,x1,y0);
      end;

    begin
      With ParentChart do
      if View3D then
         result:=PointInPolygon( P,[ TeePoint(tmpX,tmpY),
                                     TeePoint(tmpX+SeriesWidth3D,tmpY-SeriesHeight3D),
                                     TeePoint(OldXPos+SeriesWidth3D,OldYPos-SeriesHeight3D),
                                     TeePoint(OldXPos,OldYPos) ])
      else
         if FStairs then
         begin
            if FInvertedStairs then result:= PointInVertLine(OldXPos,OldYPos,tmpY) or
                                             PointInHorizLine(OldXPos,tmpY,tmpX)
                               else result:= PointInHorizLine(OldXPos,OldYPos,tmpX) or
                                             PointInVertLine(tmpX,OldYPos,tmpY);
         end
         else
            result:=PointInLine(P,tmpX,tmpY,OldXPos,OldYPos)
    end;

var t        : Integer;
    tmpFirst : Integer;
begin
  if Assigned(ParentChart) then
     ParentChart.Canvas.Calculate2DPosition(X,Y,StartZ);

  result:=inherited Clicked(x,y);

  if (result=TeeNoPointClicked) and
     (FirstValueIndex>-1) and (LastValueIndex>-1) then
  begin
    OldXPos:=0;
    OldYPos:=0;
    OldBottomPos:=0;
    P.X:=X;
    P.Y:=Y;

    // Consider hidden previous segment (including non-visible leftmost part)
    // TV52010286  7.05
    if ClickableLine then
       tmpFirst:=Max(0,Pred(FirstValueIndex))
    else
       tmpFirst:=FirstValueIndex;

    for t:=tmpFirst to LastValueIndex do
    begin
      if t>=Count then exit;  // prevent re-entrancy if series is cleared.

      tmpX:=CalcXPos(t);
      tmpY:=CalcYPos(t);

      if FPointer.Visible and ClickedPointer(t,tmpX,tmpY,x,y) then
      begin
        if Assigned(FOnClickPointer) then
           FOnClickPointer(Self,t,x,y);

        result:=t;
        break;
      end;

      if (tmpX=X) and (tmpY=Y) then
      begin
        result:=t;
        break;
      end;

      if (t>tmpFirst) and ClickableLine then
         if CheckPointInLine or
            ( FDrawArea and
               PointInPolygon( P,[ TeePoint(OldXPos,OldYPos),
                                   TeePoint(tmpX,tmpY),
                                   TeePoint(tmpX,GetOriginPos(t)),
                                   TeePoint(OldXPos,GetOriginPos(t-1)) ] )
            ) then
         begin
           result:=t-1;
           break;
         end;

      OldXPos:=tmpX;
      OldYPos:=tmpY;
      OldBottomPos:=BottomPos;
    end;
  end;
end;

Procedure TCustomSeries.SetDrawArea(Value:Boolean);
Begin
  SetBooleanProperty(FDrawArea,Value);
end;

Procedure TCustomSeries.SetPointer(Value:TSeriesPointer);
Begin
  FPointer.Assign(Value);
end;

Procedure TCustomSeries.SetShadow(Value:TTeeShadow);
begin
  FShadow.Assign(Value);
end;

Procedure TCustomSeries.SetAreaLinesPen(Value:TChartPen);
Begin
  FAreaLinesPen.Assign(Value);
end;

Procedure TCustomSeries.SetLineHeight(Value:Integer);
Begin
  SetIntegerProperty(FLineHeight,Value);
end;

Procedure TCustomSeries.SetStairs(Value:Boolean);
Begin
  SetBooleanProperty(FStairs,Value);
end;

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;

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;
  end;
end;

procedure TCustomSeries.PreparePointer(ValueIndex:Integer);
begin  // empty. Overriden at BubbleSeries
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;

type TCustomAxisPanelAccess=class(TCustomAxisPanel);

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;
      tmpY          : 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];

      if MandatoryAxis.Logarithmic then // 7.0 #1225
          tmpY:=Exp(Ln(tmpPredValueY)+(YLimit-tmpPredValueX)*
                   (Ln(YValues.Value[ValueIndex])-Ln(tmpPredValueY))/tmpDif)
      else
          tmpY:=1.0*tmpPredValueY+(YLimit-tmpPredValueX)*
                (YValues.Value[ValueIndex]-tmpPredValueY)/tmpDif;

      result:=CalcYPosValue(tmpY);
    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;
       tmpZ      : Integer;
   begin
     With ParentChart do
     Begin
       tmpColor2:=FAreaBrush.Color;
       if tmpColor2=clTeeColor then tmpColor2:=SeriesColor;

       if Assigned(FAreaBrush.Image.Graphic) and (tmpColor2=BrushColor) then
          tmpColor2:=clWhite;  // 7.04 TV52010270

       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 FStairs 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);

⌨️ 快捷键说明

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