TAChart: add properties "Font" and "UseFont" to TChartStyle

git-svn-id: trunk@44486 -
This commit is contained in:
wp 2014-03-21 20:13:56 +00:00
parent 04d3f25da3
commit 5e9c4964ce
2 changed files with 64 additions and 17 deletions

View File

@ -965,25 +965,46 @@ var
g: TDoublePoint; g: TDoublePoint;
i, si: Integer; i, si: Integer;
ld: TLabelDirection; ld: TLabelDirection;
style: TChartStyle;
lfont: TFont;
begin begin
if not Marks.IsMarkLabelsVisible then exit; if not Marks.IsMarkLabelsVisible then exit;
for i := 0 to Count - 1 do begin
if IsNan(Source[i]^.Point) then continue; lfont := TFont.Create;
g := GetLabelDataPoint(i); try
ld := GetLabelDirection(i); lfont.Assign(Marks.LabelFont);
for si := 0 to Source.YCount - 1 do begin ParentChart.DisableRedrawing;
if si > 0 then
if IsRotated then for i := 0 to Count - 1 do begin
g.X += AxisToGraphY(Source[i]^.YList[si - 1]) if IsNan(Source[i]^.Point) then continue;
else g := GetLabelDataPoint(i);
g.Y += AxisToGraphY(Source[i]^.YList[si - 1]); ld := GetLabelDirection(i);
with ParentChart do for si := 0 to Source.YCount - 1 do begin
if if Styles <> nil then begin
(Marks.YIndex = MARKS_YINDEX_ALL) or (Marks.YIndex = si) and style := Styles.StyleByIndex(si);
IsPointInViewPort(g) if style.UseFont then
then Marks.LabelFont.Assign(style.Font)
DrawLabel(FormattedMark(i, '', si), GraphToImage(g), ld); else
Marks.LabelFont.Assign(lfont);
end;
if si > 0 then
if IsRotated then
g.X += AxisToGraphY(Source[i]^.YList[si - 1])
else
g.Y += AxisToGraphY(Source[i]^.YList[si - 1]);
with ParentChart do
if
(Marks.YIndex = MARKS_YINDEX_ALL) or (Marks.YIndex = si) and
IsPointInViewPort(g)
then
DrawLabel(FormattedMark(i, '', si), GraphToImage(g), ld);
end;
end; end;
finally
Marks.LabelFont.Assign(lfont);
ParentChart.EnableRedrawing;
lfont.Free;
end; end;
end; end;

View File

@ -24,15 +24,19 @@ type
private private
FBrush: TBrush; FBrush: TBrush;
FPen: TPen; FPen: TPen;
FFont: TFont;
FRepeatCount: Cardinal; FRepeatCount: Cardinal;
FText: String; FText: String;
FUseBrush: Boolean; FUseBrush: Boolean;
FUsePen: Boolean; FUsePen: Boolean;
FUseFont: Boolean;
procedure SetBrush(AValue: TBrush); procedure SetBrush(AValue: TBrush);
procedure SetFont(AValue: TFont);
procedure SetPen(AValue: TPen); procedure SetPen(AValue: TPen);
procedure SetRepeatCount(AValue: Cardinal); procedure SetRepeatCount(AValue: Cardinal);
procedure SetText(AValue: String); procedure SetText(AValue: String);
procedure SetUseBrush(AValue: Boolean); procedure SetUseBrush(AValue: Boolean);
procedure SetUseFont(AValue: Boolean);
procedure SetUsePen(AValue: Boolean); procedure SetUsePen(AValue: Boolean);
procedure StyleChanged(ASender: TObject); procedure StyleChanged(ASender: TObject);
protected protected
@ -45,11 +49,13 @@ type
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
published published
property Brush: TBrush read FBrush write SetBrush; property Brush: TBrush read FBrush write SetBrush;
property Font: TFont read FFont write SetFont;
property Pen: TPen read FPen write SetPen; property Pen: TPen read FPen write SetPen;
property RepeatCount: Cardinal property RepeatCount: Cardinal
read FRepeatCount write SetRepeatCount default 1; read FRepeatCount write SetRepeatCount default 1;
property Text: String read FText write SetText; property Text: String read FText write SetText;
property UseBrush: Boolean read FUseBrush write SetUseBrush default true; property UseBrush: Boolean read FUseBrush write SetUseBrush default true;
property UseFont: Boolean read FUseFont write SetUseFont default true;
property UsePen: Boolean read FUsePen write SetUsePen default true; property UsePen: Boolean read FUsePen write SetUsePen default true;
end; end;
@ -83,12 +89,12 @@ type
FBroadcaster: TBroadcaster; FBroadcaster: TBroadcaster;
FStyles: TChartStyleList; FStyles: TChartStyleList;
procedure SetStyles(AValue: TChartStyleList); procedure SetStyles(AValue: TChartStyleList);
function StyleByIndex(AIndex: Cardinal): TChartStyle;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
public public
procedure Apply(ADrawer: IChartDrawer; AIndex: Cardinal); overload; procedure Apply(ADrawer: IChartDrawer; AIndex: Cardinal); overload;
function StyleByIndex(AIndex: Cardinal): TChartStyle;
property Broadcaster: TBroadcaster read FBroadcaster; property Broadcaster: TBroadcaster read FBroadcaster;
published published
property Styles: TChartStyleList read FStyles write SetStyles; property Styles: TChartStyleList read FStyles write SetStyles;
@ -116,6 +122,8 @@ procedure TChartStyle.Apply(ADrawer: IChartDrawer);
begin begin
if UseBrush then if UseBrush then
ADrawer.Brush := Brush; ADrawer.Brush := Brush;
if UseFont then
ADrawer.Font := Font;
if UsePen then if UsePen then
ADrawer.Pen := Pen; ADrawer.Pen := Pen;
end; end;
@ -125,6 +133,7 @@ begin
if Source is TChartStyle then if Source is TChartStyle then
with Source as TChartStyle do begin with Source as TChartStyle do begin
Self.Brush := Brush; Self.Brush := Brush;
Self.Font := Font;
Self.Pen := Pen; Self.Pen := Pen;
end; end;
inherited Assign(Source); inherited Assign(Source);
@ -135,16 +144,20 @@ begin
inherited Create(ACollection); inherited Create(ACollection);
FBrush := TBrush.Create; FBrush := TBrush.Create;
FBrush.OnChange := @StyleChanged; FBrush.OnChange := @StyleChanged;
FFont := TFont.Create;
FFont.OnChange := @StyleChanged;
FPen := TPen.Create; FPen := TPen.Create;
FPen.OnChange := @StyleChanged; FPen.OnChange := @StyleChanged;
FRepeatCount := 1; FRepeatCount := 1;
FUseBrush := true; FUseBrush := true;
FUseFont := true;
FUsePen := true; FUsePen := true;
end; end;
destructor TChartStyle.Destroy; destructor TChartStyle.Destroy;
begin begin
FreeAndNil(FBrush); FreeAndNil(FBrush);
FreeAndNil(FFont);
FreeAndNil(FPen); FreeAndNil(FPen);
inherited Destroy; inherited Destroy;
end; end;
@ -160,6 +173,12 @@ begin
FBrush := AValue; FBrush := AValue;
end; end;
procedure TChartStyle.SetFont(AValue: TFont);
begin
if FFont = AValue then exit;
FFont := AValue;
end;
procedure TChartStyle.SetPen(AValue: TPen); procedure TChartStyle.SetPen(AValue: TPen);
begin begin
if FPen = AValue then exit; if FPen = AValue then exit;
@ -187,6 +206,13 @@ begin
StyleChanged(Self); StyleChanged(Self);
end; end;
procedure TChartStyle.SetUseFont(AValue: Boolean);
begin
if FUseFont = AValue then exit;
FUseFont := AValue;
StyleChanged(Self);
end;
procedure TChartStyle.SetUsePen(AValue: Boolean); procedure TChartStyle.SetUsePen(AValue: Boolean);
begin begin
if FUsePen = AValue then exit; if FUsePen = AValue then exit;