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

📄 chart.pas

📁 Delphi TeeChartPro.6.01的源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  result:=Color<>DefaultColor;
end;

Procedure TCustomChartWall.Assign(Source:TPersistent);
Begin
  if Source is TCustomChartWall then
  With TCustomChartWall(Source) do
  Begin
    Self.FDark3D := FDark3D;
    Self.FSize   := FSize;
  end;
  inherited;
End;

Function TCustomChartWall.ApplyDark3D:Boolean;
begin
  result:=(Brush.Style<>bsClear) and
          ((Brush.Bitmap=nil) {$IFDEF CLX}or (Brush.Bitmap.Empty){$ENDIF}) and
          Dark3D;
end;

Function TCustomChartWall.GetPen:TChartPen;
begin
  result:=Frame;
end;

Procedure TCustomChartWall.SetPen(Value:TChartPen);
Begin
  Frame:=Value;
end;

type TTeePanelAccess=class(TCustomTeePanel);

Procedure TCustomChartWall.SetSize(Value:Integer);
Begin
  TTeePanelAccess(ParentChart).SetIntegerProperty(FSize,Value);
End;

Procedure TCustomChartWall.SetDark3D(Value:Boolean);
begin
  TTeePanelAccess(ParentChart).SetBooleanProperty(FDark3D,Value);
end;

procedure TCustomChartWall.InitColor(AColor: TColor);
begin
  Color:=AColor;
  DefaultColor:=AColor;
end;

type TTeeFontAccess=class(TTeeFont);

function TCustomChartWall.HasGradient: Boolean;
begin
  result:=Assigned(FGradient) and FGradient.Visible;
end;

Function TCustomChartWall.TryDrawWall(APos1,APos2:Integer):TTeeBlend;
var P : TFourPoints;
begin
  result:=nil;

  if not Transparent then
  begin
    with ParentChart do
    begin
      P[0]:=Canvas.Calculate3DPosition(APos1, ChartRect.Top, 0);
      P[1]:=Canvas.Calculate3DPosition(APos1, ChartRect.Top, Width3D);
      P[2]:=Canvas.Calculate3DPosition(APos1, APos2, Width3D);
      P[3]:=Canvas.Calculate3DPosition(APos1, APos2, 0);
    end;

    if Transparency>0 then // 5.03
       result:=ParentChart.Canvas.BeginBlending(RectFromPolygon(P,4),Transparency);

    if HasGradient then
    begin
      Gradient.Draw(ParentChart.Canvas,P);
      ParentChart.Canvas.Brush.Style:=bsClear;
    end;
  end;
end;

{ TChartTitle }
Constructor TChartTitle.Create(AOwner: TCustomTeePanel);
Begin
  inherited;
  IOnTop:=True;

  FAlignment:=taCenter;
  FAdjustFrame:=True;
  FText:=TStringList.Create;
  TStringList(FText).OnChange:=AOwner.CanvasChanged;
  { inherited }
  Transparent:=True;
  Font.Color:=clBlue;
  TTeeFontAccess(Font).IDefColor:=clBlue;
end;

Destructor TChartTitle.Destroy;
Begin
  FText.Free;
  inherited;
end;

Procedure TChartTitle.Assign(Source:TPersistent);
Begin
  if Source is TChartTitle then
  With TChartTitle(Source) do
  Begin
    Self.FAdjustFrame  := FAdjustFrame;
    Self.FAlignment    := FAlignment;
    Self.Text          := FText;
  end;
  inherited;
end;

Function TChartTitle.Clicked(x,y:Integer):Boolean;
begin
  result:=Visible and PointInRect(ShapeBounds,x,y);
end;

procedure TChartTitle.DrawTitle;
var tmpXPosTitle  : Integer;
    tmpMargin     : Integer;
    FontH         : Integer;
    tmpFrameWidth : Integer;

  Procedure DrawTitleLine(AIndex:Integer);
  Var St   : String;
      APos : Integer;
  Begin { draw a title text line }
    St:=Text[AIndex];
    APos:=AIndex*FontH+tmpFrameWidth;
    if IOnTop then Inc(APos,ShapeBounds.Top)
              else APos:=ShapeBounds.Bottom-FontH-APos;

    if Alignment=taRightJustify then
       tmpXPosTitle:=ShapeBounds.Right-ParentChart.Canvas.TextWidth(St)-(tmpMargin div 2)
    else
    if Alignment=taCenter then
       tmpXPosTitle:=((ShapeBounds.Left+ShapeBounds.Right) div 2)-(ParentChart.Canvas.TextWidth(St) div 2);

    With ParentChart.Canvas do
    if SupportsFullRotation then TextOut3D(tmpXPosTitle,APos,0,St)
                            else TextOut(tmpXPosTitle,APos,St);
  end;

Var t               : Integer;
    tmpMaxWidth     : Integer;
    tmp             : Integer;
    tmpFrameVisible : Boolean;
Begin
  if Visible and (Text.Count>0) then
  begin
    { calculate title shape margin }
    tmpFrameVisible:=Frame.Visible and (Frame.Color<>clTeeColor);
    if tmpFrameVisible then tmpFrameWidth:=Frame.Width
                       else tmpFrameWidth:=0;

    if Bevel<>bvNone then tmpFrameWidth:=BevelWidth;

    { apply title margins }
    if not FCustomPosition then
    begin
      ShapeBounds:=ParentChart.ChartRect;
      if IOnTop then ShapeBounds.Top:=ShapeBounds.Top+tmpFrameWidth;
    end;

    { prepare title font }
    With ParentChart.Canvas do
    begin
      AssignFont(Self.Font);
      TextAlign:=ta_Left;
      FontH:=FontHeight;
    end;

    { autosize title height on number of text lines }
    if IOnTop or FCustomPosition then
       ShapeBounds.Bottom:=ShapeBounds.Top+Text.Count*FontH
    else
       ShapeBounds.Top   :=ShapeBounds.Bottom-Text.Count*FontH;

    { apply margins to bottom and right sides }
    if not FCustomPosition then
       InflateRect(ShapeBounds,tmpFrameWidth,tmpFrameWidth);

    tmpMargin:=ParentChart.Canvas.TextWidth('W');

    { resize Title to maximum Chart width }
    if AdjustFrame then
    Begin
      tmpMaxWidth:=0;
      for t:=0 to Text.Count-1 do
      Begin
        tmp:=ParentChart.Canvas.TextWidth(Text[t]);
        if tmp>tmpMaxWidth then tmpMaxWidth:=tmp;
      end;
      Inc(tmpMaxWidth,tmpMargin+tmpFrameWidth);
      With ShapeBounds do
      Case Alignment of
          taLeftJustify  : Right:=Left +tmpMaxWidth;
          taRightJustify : Left :=Right-tmpMaxWidth;
          taCenter       : begin
                             if FCustomPosition then Right:=Left+tmpMaxWidth;
                             tmp:=(Left+Right) div 2;
                             Left :=tmp-(tmpMaxWidth div 2);
                             Right:=tmp+(tmpMaxWidth div 2);
                           end;
      end;
    end;

    { draw title shape }
    Draw;

    if Alignment=taLeftJustify then tmpXPosTitle:=ShapeBounds.Left+(tmpMargin div 2);

    { draw all Title text lines }
    ParentChart.Canvas.BackMode:=cbmTransparent;
    for t:=0 to Text.Count-1 do DrawTitleLine(t);

    { calculate Chart positions after drawing the titles / footers }
    if not FCustomPosition then
    begin
      tmp:=TeeTitleFootDistance+tmpFrameWidth;
      if not Transparent then
         Inc(tmp,Shadow.VertSize);

      With ParentChart.ChartRect do
      if IOnTop then Top:=ShapeBounds.Bottom+tmp
                else Bottom:=ShapeBounds.Bottom-tmp-Text.Count*FontH;
      ParentChart.RecalcWidthHeight;
    end;
  end;
end;

Function TChartTitle.GetShapeBounds:TRect;
begin
  result:=ShapeBounds;
end;

Procedure TChartTitle.SetAdjustFrame(Value:Boolean);
begin
  TTeePanelAccess(ParentChart).SetBooleanProperty(FAdjustFrame,Value);
end;

Procedure TChartTitle.SetAlignment(Value:TAlignment);
Begin
  if FAlignment<>Value then
  begin
    FAlignment:=Value;
    Repaint;
  end;
end;

Procedure TChartTitle.SetText(Value:TStrings);
begin
  FText.Assign(Value);
  Repaint;
end;

{ TChartFootTitle }
Constructor TChartFootTitle.Create(AOwner: TCustomTeePanel);
Begin
  inherited;
  IOnTop:=False;
  With Font do
  Begin
    Color:=clRed;
    Style:=[fsItalic];
  end;
  With TTeeFontAccess(Font) do
  begin
    IDefColor:=clRed;
    IDefStyle:=[fsItalic];
  end;
end;

{ TChartWalls }
constructor TChartWalls.Create(Chart: TCustomChart);
begin
  inherited Create;
  FChart:=Chart;
  FBack:=TChartBackWall.Create(FChart);
  With FBack do
  begin
    InitColor(clSilver);
    Transparent:=True;
  end;

  FLeft:=TChartWall.Create(FChart);
  FLeft.InitColor($80FFFF); { ChartMarkColor }

  FBottom:=TChartWall.Create(FChart);
  FBottom.InitColor(clWhite);

  FRight:=TChartRightWall.Create(FChart);
  With FRight do
  begin
    Visible:=False;
    InitColor(clSilver);
  end;
end;

procedure TChartWalls.Assign(Source: TPersistent);
begin
  if Source is TChartWalls then
  with TChartWalls(Source) do
  begin
    Self.Back   :=Back;
    Self.Bottom :=Bottom;
    Self.Left   :=Left;
    Self.Right  :=Right;
  end
  else inherited;
end;

destructor TChartWalls.Destroy;
begin
  FBack.Free;
  FBottom.Free;
  FLeft.Free;
  FRight.Free;
  inherited;
end;

procedure TChartWalls.SetBack(const Value: TChartBackWall);
begin
  Back.Assign(Value);
end;

procedure TChartWalls.SetBottom(const Value: TChartWall);
begin
  Bottom.Assign(Value);
end;

procedure TChartWalls.SetLeft(const Value: TChartWall);
begin
  Left.Assign(Value);
end;

procedure TChartWalls.SetRight(const Value: TChartRightWall);
begin
  Right.Assign(Value);
end;

function TChartWalls.GetVisible: Boolean;
begin
  result:=FChart.View3DWalls;
end;

procedure TChartWalls.SetVisible(const Value: Boolean);
begin
  FChart.View3DWalls:=Value;
end;

{ TCustomChart }
Constructor TCustomChart.Create(AOwner: TComponent);
Begin
  inherited;
  AutoRepaint:=False;
  FTitle   :=TChartTitle.Create(Self);
  if csDesigning in ComponentState then FTitle.FText.Add(ClassName);

  FScrollMouse:=mbRight;

  FSubTitle:=TChartTitle.Create(Self);
  FFoot    :=TChartFootTitle.Create(Self);
  FSubFoot :=TChartFootTitle.Create(Self);

  FWalls:=TChartWalls.Create(Self);
  FLegend:=TChartLegend.Create(Self);

  RestoredAxisScales:=True;
  AutoRepaint :=True;
end;

Destructor TCustomChart.Destroy;
Begin
  FSavedScales:=nil;
  AutoRepaint:=False;  { 5.01 }
  FSubTitle.Free;
  FTitle.Free;
  FSubFoot.Free;
  FFoot.Free;
  FWalls.Free;
  FLegend.Free;
  inherited;
end;

type TSeriesAccess=class(TChartSeries);

Function TCustomChart.FormattedValueLegend(ASeries:TChartSeries; ValueIndex:Integer):String;
var tmp : TCustomChartLegend;
Begin
  if Assigned(ASeries) then
  begin
    tmp:=TCustomChartLegend(TSeriesAccess(ASeries).ILegend);
    if not Assigned(tmp) then tmp:=Legend;
    result:=tmp.FormattedValue(ASeries,ValueIndex);
  end
  else
     result:='';
end;

Function TCustomChart.InternalFormattedLegend( ALegend:TCustomChartLegend;
                                               SeriesOrValueIndex:Integer):String;
begin
  result:=ALegend.FormattedLegend(SeriesOrValueIndex);
  if Assigned(FOnGetLegendText) then
     FOnGetLegendText(Self,ALegend.InternalLegendStyle,SeriesOrValueIndex,result);
end;

Function TCustomChart.FormattedLegend(SeriesOrValueIndex:Integer):String;
Begin
  result:=InternalFormattedLegend(Legend,SeriesOrValueIndex);
end;

procedure TCustomChart.SetLegend(Value:TChartLegend);
begin
  FLegend.Assign(Value);
end;

// "remember" the axis scales when zooming, to restore when unzooming
Function TCustomChart.SaveScales:TAllAxisSavedScales;
var t : Integer;
begin
  SetLength(result,Axes.Count);
  for t:=0 to Axes.Count-1 do
  with Axes[t] do
    if not IsDepthAxis then
    begin
      result[t].Auto:=Automatic;
      result[t].AutoMin:=AutomaticMinimum;
      result[t].AutoMax:=AutomaticMaximum;
      result[t].Min:=Minimum;
      result[t].Max:=Maximum;
    end;
end;

// restore the "remembered" axis scales when unzooming
Procedure TCustomChart.RestoreScales(var Saved:TAllAxisSavedScales);
var t : Integer;
begin
  for t:=0 to Axes.Count-1 do
  with Axes[t] do
    if not IsDepthAxis then
    begin
      Automatic:=Saved[t].Auto;

⌨️ 快捷键说明

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