📄 chart.pas
字号:
$31DD95,
$01009E,
$74F7DC,
$FDFD45,
$748ED1,
$91D8A0,
$657AD5,
$D99596
);
GrayScalePalette:Array[0..14] of TColor=
(
$f0f0f0,
$e0e0e0,
$d0d0d0,
$c0c0c0,
$b0b0b0,
$a0a0a0,
$909090,
$808080,
$707070,
$606060,
$505050,
$404040,
$303030,
$202020,
$101010
);
OperaPalette:Array[0..11] of TColor=
(
$a36644,
$359cf3,
$144cf1,
$a8974e,
$6b402b,
$637b1d,
$0e08b3,
$5dc0f2,
$9eb75d,
$707070,
$8deaf3,
$b4b4b4
);
WarmPalette:Array[0..7] of TColor=
(
$8deaf3,
$5dc0f2,
$359cf3,
$1c81f5,
$156bf3,
$144cf1,
$0a18e6,
$0e08b3
);
CoolPalette:Array[0..7] of TColor=
(
$6b402b,
$8c543b,
$a36644,
$a8974e,
$9eb75d,
$8aa041,
$7d922b,
$637b1d
);
implementation
Uses {$IFNDEF D5}
{$IFNDEF LCL}
DsgnIntf,
{$ENDIF}
{$ENDIF}
{$IFDEF LCL}
GraphType,
{$ENDIF}
Math, TeeHtml, TeeConst;
{ TCustomChartWall }
Constructor TCustomChartWall.Create(AOwner:TCustomTeePanel);
Begin
inherited;
FDark3D:=True;
FEnd:=100;
Color:=clTeeColor;
DefaultColor:=clTeeColor;
End;
Function TCustomChartWall.IsColorStored:Boolean;
begin
result:=Color<>DefaultColor;
end;
Procedure TCustomChartWall.Assign(Source:TPersistent);
Begin
if Source is TCustomChartWall then
With TCustomChartWall(Source) do
Begin
Self.FAutoHide:=AutoHide;
Self.FDark3D:=Dark3D;
Self.FEnd:=EndPosition;
Self.FSize:=Size;
Self.FStart:=StartPosition;
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;
type
TTeePanelAccess=class(TCustomTeePanel);
Procedure TCustomChartWall.SetDark3D(const Value:Boolean);
begin
TTeePanelAccess(ParentChart).SetBooleanProperty(FDark3D,Value);
end;
Procedure TCustomChartWall.SetEnd(const Value:Integer);
begin
TTeePanelAccess(ParentChart).SetIntegerProperty(FEnd,Value);
end;
Procedure TCustomChartWall.SetPen(const Value:TChartPen);
Begin
Frame:=Value;
end;
Procedure TCustomChartWall.SetSize(const Value:Integer);
Begin
TTeePanelAccess(ParentChart).SetIntegerProperty(FSize,Value);
End;
Procedure TCustomChartWall.SetStart(const Value:Integer);
begin
TTeePanelAccess(ParentChart).SetIntegerProperty(FStart,Value);
end;
procedure TCustomChartWall.InitColor(const AColor: TColor);
begin
Color:=AColor;
DefaultColor:=AColor;
end;
function TCustomChartWall.HasGradient: Boolean;
begin
result:=Assigned(FGradient) and FGradient.Visible;
end;
procedure TCustomChartWall.CalcPositions(out ATop,ABottom:Integer);
begin
with TCustomChart(ParentChart) do
ABottom:=ChartRect.Bottom+CalcWallSize(BottomAxis);
if EndPosition<>100 then
Dec(ABottom,Round((ABottom-ParentChart.ChartRect.Top)*(100-EndPosition)*0.01));
ATop:=ParentChart.ChartRect.Top;
if StartPosition<>0 then
Inc(ATop,Round((ParentChart.ChartRect.Bottom-ATop)*StartPosition*0.01));
end;
Function TCustomChartWall.TryDrawWall(const APos1,APos2:Integer):TTeeBlend;
var P : TFourPoints;
tmpTop : Integer;
tmpBottom : Integer;
begin
result:=nil;
if (not Transparent) and ((Transparency>0) or HasGradient) then
begin
CalcPositions(tmpTop,tmpBottom);
with ParentChart.Canvas do
begin
P[0]:=Calculate3DPosition(APos1, tmpTop, 0);
P[1]:=Calculate3DPosition(APos1, tmpTop, ParentChart.Width3D);
P[2]:=Calculate3DPosition(APos1, APos2, ParentChart.Width3D);
P[3]:=Calculate3DPosition(APos1, APos2, 0);
end;
if Transparency>0 then
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;
procedure TCustomChartWall.SetAutoHide(const Value: Boolean);
begin
TTeePanelAccess(ParentChart).SetBooleanProperty(FAutoHide,Value);
end;
procedure TCustomChartWall.DoEndBlending(Blend:TTeeBlend);
begin
if Assigned(Blend) then
begin
if (Picture.Filters.Count>0) and (not Assigned(Picture.Graphic)) then
Picture.Filters.ApplyTo(Blend.Bitmap);
ParentChart.Canvas.EndBlending(Blend);
end;
end;
function TCustomChartWall.ShouldDraw: Boolean;
begin
result:=TCustomChart(ParentChart).View3DWalls and Visible and (not AutoHide);
end;
{$IFNDEF CLR}
type
TShadowAccess=class(TTeeShadow);
{$ENDIF}
{ TChartBackWall }
Constructor TChartBackWall.Create(AOwner: TCustomTeePanel);
begin
inherited;
InitColor(clSilver);
DefaultTransparent:=True;
Transparent:=True;
Shadow.Visible:=False;
{$IFNDEF CLR}TShadowAccess{$ENDIF}(Shadow).DefaultVisible:=Shadow.Visible;
Shadow.Color:=clDkGray;
{$IFNDEF CLR}TShadowAccess{$ENDIF}(Shadow).DefaultColor:=Shadow.Color;
end;
{ TChartTitle }
type
TTeeFontAccess=class(TTeeFont);
Constructor TChartTitle.Create(AOwner: TCustomTeePanel);
Begin
inherited;
IOnTop:=True;
FAlignment:=taCenter;
FAdjustFrame:=True;
FText:=TStringList.Create;
TStringList(FText).OnChange:=AOwner.CanvasChanged;
FVertMargin:=TeeTitleFootDistance;
{ inherited }
Transparent:=True;
DefaultTransparent:=Transparent;
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;
Self.FVertMargin:=FVertMargin;
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;
function CalculateYPos(APos:Integer):Integer;
begin
if IOnTop then result:=APos+ShapeBounds.Top
else result:=ShapeBounds.Bottom-FontH-APos;
end;
// Draws a line of title/footer text }
procedure DrawTitleLine(AIndex:Integer);
var St : String;
APos : Integer;
begin
St:=Text[AIndex];
APos:=CalculateYPos(AIndex*FontH+tmpFrameWidth);
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);
ParentChart.Canvas.TextOut(tmpXPosTitle,APos,St);
end;
procedure ResizeChartRect(VertMargin:Integer);
var tmpR : TRect;
begin
tmpR:=ParentChart.ChartRect;
if IOnTop then
tmpR.Top:=ShapeBounds.Bottom+VertMargin
else
tmpR.Bottom:=ShapeBounds.Bottom-VertMargin-Text.Count*FontH;
ParentChart.ChartRect:=tmpR;
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(TeeCharForHeight);
{ 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;
tmpXPosTitle:=ShapeBounds.Left+(tmpMargin div 2);
{ draw all Title text lines }
ParentChart.Canvas.BackMode:=cbmTransparent;
if TextFormat=ttfNormal then
for t:=0 to Text.Count-1 do DrawTitleLine(t)
else
ParentChart.Canvas.TextOut(tmpXPosTitle,CalculateYPos(tmpFrameWidth),
Text.Text,True);
{ calculate Chart positions after drawing the titles / footers }
if not FCustomPosition then
begin
tmp:=FVertMargin+tmpFrameWidth;
if (not Transparent) and Shadow.Visible then
Inc(tmp,Shadow.VertSize);
if not {$IFNDEF CLR}TTeePanelAccess{$ENDIF}(ParentChart).CustomChartRect then
ResizeChartRect(tmp);
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -