TAChart: Do not display mark labels by default for minor axis.

+ Remove unusable properties from minor axis marks 
+ Update axis demo

git-svn-id: trunk@31776 -
This commit is contained in:
ask 2011-07-21 16:18:49 +00:00
parent 6a07320422
commit 411ec72db8
3 changed files with 104 additions and 39 deletions

View File

@ -136,6 +136,8 @@ object Form1: TForm1
Marks.Distance = 4 Marks.Distance = 4
Marks.LabelFont.Height = -9 Marks.LabelFont.Height = -9
Marks.LabelFont.Orientation = 900 Marks.LabelFont.Orientation = 900
Marks.Format = '%0:.9g'
Marks.Style = smsValue
end> end>
end end
item item

View File

@ -38,7 +38,9 @@ type
TChartMinorAxis = class(TChartBasicAxis) TChartMinorAxis = class(TChartBasicAxis)
strict private strict private
FIntervalsCount: Cardinal; FIntervalsCount: Cardinal;
function GetMarks: TChartMinorAxisMarks; inline;
procedure SetIntervalsCount(AValue: Cardinal); procedure SetIntervalsCount(AValue: Cardinal);
procedure SetMarks(AValue: TChartMinorAxisMarks);
protected protected
function GetDisplayName: String; override; function GetDisplayName: String; override;
strict protected strict protected
@ -51,7 +53,7 @@ type
published published
property IntervalsCount: Cardinal property IntervalsCount: Cardinal
read FIntervalsCount write SetIntervalsCount default DEF_INTERVALS_COUNT; read FIntervalsCount write SetIntervalsCount default DEF_INTERVALS_COUNT;
property Marks; property Marks: TChartMinorAxisMarks read GetMarks write SetMarks;
property TickLength default DEF_TICK_LENGTH div 2; property TickLength default DEF_TICK_LENGTH div 2;
end; end;
@ -112,10 +114,12 @@ type
FTransformations: TChartAxisTransformations; FTransformations: TChartAxisTransformations;
FZPosition: TChartDistance; FZPosition: TChartDistance;
function GetMarks: TChartAxisMarks; inline;
function GetTransform: TChartAxisTransformations; function GetTransform: TChartAxisTransformations;
procedure SetAxisPen(AValue: TChartAxisPen); procedure SetAxisPen(AValue: TChartAxisPen);
procedure SetGroup(AValue: Integer); procedure SetGroup(AValue: Integer);
procedure SetInverted(AValue: Boolean); procedure SetInverted(AValue: Boolean);
procedure SetMarks(AValue: TChartAxisMarks);
procedure SetMinors(AValue: TChartMinorAxisList); procedure SetMinors(AValue: TChartMinorAxisList);
procedure SetOnMarkToText(AValue: TChartAxisMarkToTextEvent); procedure SetOnMarkToText(AValue: TChartAxisMarkToTextEvent);
procedure SetTitle(AValue: TChartAxisTitle); procedure SetTitle(AValue: TChartAxisTitle);
@ -149,7 +153,7 @@ type
property Group: Integer read FGroup write SetGroup default 0; property Group: Integer read FGroup write SetGroup default 0;
// Inverts the axis scale from increasing to decreasing. // Inverts the axis scale from increasing to decreasing.
property Inverted: boolean read FInverted write SetInverted default false; property Inverted: boolean read FInverted write SetInverted default false;
property Marks; property Marks: TChartAxisMarks read GetMarks write SetMarks;
property Minors: TChartMinorAxisList read FMinors write SetMinors; property Minors: TChartMinorAxisList read FMinors write SetMinors;
property TickLength default DEF_TICK_LENGTH; property TickLength default DEF_TICK_LENGTH;
property Title: TChartAxisTitle read FTitle write SetTitle; property Title: TChartAxisTitle read FTitle write SetTitle;
@ -286,6 +290,8 @@ constructor TChartMinorAxis.Create(ACollection: TCollection);
begin begin
inherited Create(ACollection, (ACollection as TChartMinorAxisList).GetChart); inherited Create(ACollection, (ACollection as TChartMinorAxisList).GetChart);
FIntervalsCount := DEF_INTERVALS_COUNT; FIntervalsCount := DEF_INTERVALS_COUNT;
FMarks := TChartMinorAxisMarks.Create(
(ACollection as TChartMinorAxisList).GetChart);
TickLength := DEF_TICK_LENGTH div 2; TickLength := DEF_TICK_LENGTH div 2;
end; end;
@ -299,6 +305,11 @@ begin
Result := 'M'; Result := 'M';
end; end;
function TChartMinorAxis.GetMarks: TChartMinorAxisMarks;
begin
Result := TChartMinorAxisMarks(inherited Marks);
end;
function TChartMinorAxis.GetMarkValues(AMin, AMax: Double): TChartValueTextArray; function TChartMinorAxis.GetMarkValues(AMin, AMax: Double): TChartValueTextArray;
var var
c, ic: Integer; c, ic: Integer;
@ -327,6 +338,11 @@ begin
StyleChanged(Self); StyleChanged(Self);
end; end;
procedure TChartMinorAxis.SetMarks(AValue: TChartMinorAxisMarks);
begin
inherited Marks := AValue;
end;
procedure TChartMinorAxis.StyleChanged(ASender: TObject); procedure TChartMinorAxis.StyleChanged(ASender: TObject);
begin begin
(Collection.Owner as TChartAxis).StyleChanged(ASender); (Collection.Owner as TChartAxis).StyleChanged(ASender);
@ -389,6 +405,7 @@ begin
FAxisPen.OnChange := @StyleChanged; FAxisPen.OnChange := @StyleChanged;
FAxisPen.Visible := false; FAxisPen.Visible := false;
FListener := TListener.Create(@FTransformations, @StyleChanged); FListener := TListener.Create(@FTransformations, @StyleChanged);
FMarks := TChartAxisMarks.Create(ACollection.Owner as TCustomChart);
FMinors := TChartMinorAxisList.Create(Self); FMinors := TChartMinorAxisList.Create(Self);
TickLength := DEF_TICK_LENGTH; TickLength := DEF_TICK_LENGTH;
FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart); FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart);
@ -494,6 +511,11 @@ begin
Result += Format(CAPTION_FMT, [Title.Caption]); Result += Format(CAPTION_FMT, [Title.Caption]);
end; end;
function TChartAxis.GetMarks: TChartAxisMarks;
begin
Result := TChartAxisMarks(inherited Marks);
end;
procedure TChartAxis.GetMarkValues(AMin, AMax: Double); procedure TChartAxis.GetMarkValues(AMin, AMax: Double);
var var
i: Integer; i: Integer;
@ -667,6 +689,11 @@ begin
StyleChanged(Self); StyleChanged(Self);
end; end;
procedure TChartAxis.SetMarks(AValue: TChartAxisMarks);
begin
inherited Marks := AValue;
end;
procedure TChartAxis.SetMinors(AValue: TChartMinorAxisList); procedure TChartAxis.SetMinors(AValue: TChartMinorAxisList);
begin begin
FMinors.Assign(AValue); FMinors.Assign(AValue);

View File

@ -84,31 +84,51 @@ type
end; end;
{$IFNDEF fpdoc} // Workaround for issue #18549. {$IFNDEF fpdoc} // Workaround for issue #18549.
TCustomChartAxisMarks = TBasicChartAxisMarks =
specialize TGenericChartMarks<TChartAxisBrush, TChartPen, TChartAxisFramePen>; specialize TGenericChartMarks<TChartAxisBrush, TChartPen, TChartAxisFramePen>;
{$ENDIF} {$ENDIF}
TCustomChartAxisMarks = class(TBasicChartAxisMarks)
strict private
FStripes: TChartStyles;
procedure SetStripes(AValue: TChartStyles);
strict protected
function IsFormatStored: Boolean;
public
constructor Create(AOwner: TCustomChart);
function Measure(
ADrawer: IChartDrawer; AIsVertical: Boolean; ATickLength: Integer;
AValues: TChartValueTextArray): Integer;
property Stripes: TChartStyles read FStripes write SetStripes;
end;
TChartMinorAxisMarks = class(TCustomChartAxisMarks)
public
constructor Create(AOwner: TCustomChart);
published
property Distance default 1;
property Format;
property Frame;
property LabelBrush;
property OverlapPolicy;
property Style default smsNone;
end;
{ TChartAxisMarks } { TChartAxisMarks }
TChartAxisMarks = class(TCustomChartAxisMarks) TChartAxisMarks = class(TCustomChartAxisMarks)
private strict private
FAtDataOnly: Boolean; FAtDataOnly: Boolean;
FDefaultSource: TCustomChartSource; FDefaultSource: TCustomChartSource;
FListener: TListener; FListener: TListener;
FSource: TCustomChartSource; FSource: TCustomChartSource;
FStripes: TChartStyles;
function IsFormatStored: Boolean;
procedure SetAtDataOnly(AValue: Boolean); procedure SetAtDataOnly(AValue: Boolean);
procedure SetSource(AValue: TCustomChartSource); procedure SetSource(AValue: TCustomChartSource);
procedure SetStripes(AValue: TChartStyles);
public public
constructor Create(AOwner: TCustomChart); constructor Create(AOwner: TCustomChart);
destructor Destroy; override; destructor Destroy; override;
function Measure(
ADrawer: IChartDrawer; AIsVertical: Boolean; ATickLength: Integer;
AValues: TChartValueTextArray): Integer;
function SourceDef: TCustomChartSource; function SourceDef: TCustomChartSource;
published published
property AtDataOnly: Boolean property AtDataOnly: Boolean
@ -119,7 +139,7 @@ type
property LabelBrush; property LabelBrush;
property OverlapPolicy; property OverlapPolicy;
property Source: TCustomChartSource read FSource write SetSource; property Source: TCustomChartSource read FSource write SetSource;
property Stripes: TChartStyles read FStripes write SetStripes; property Stripes;
property Style default smsValue; property Style default smsValue;
property YIndex; property YIndex;
end; end;
@ -130,19 +150,19 @@ type
strict private strict private
FArrow: TChartArrow; FArrow: TChartArrow;
FGrid: TChartAxisGridPen; FGrid: TChartAxisGridPen;
FMarks: TChartAxisMarks;
FTickColor: TColor; FTickColor: TColor;
FTickLength: Integer; FTickLength: Integer;
FVisible: Boolean; FVisible: Boolean;
procedure SetArrow(AValue: TChartArrow); procedure SetArrow(AValue: TChartArrow);
procedure SetGrid(AValue: TChartAxisGridPen); procedure SetGrid(AValue: TChartAxisGridPen);
procedure SetMarks(AValue: TChartAxisMarks);
procedure SetTickColor(AValue: TColor); procedure SetTickColor(AValue: TColor);
procedure SetTickLength(AValue: Integer); procedure SetTickLength(AValue: Integer);
procedure SetVisible(AValue: Boolean); procedure SetVisible(AValue: Boolean);
strict protected strict protected
FMarks: TCustomChartAxisMarks;
function GetAlignment: TChartAxisAlignment; virtual; abstract; function GetAlignment: TChartAxisAlignment; virtual; abstract;
procedure SetAlignment(AValue: TChartAxisAlignment); virtual; abstract; procedure SetAlignment(AValue: TChartAxisAlignment); virtual; abstract;
procedure SetMarks(AValue: TCustomChartAxisMarks);
procedure StyleChanged(ASender: TObject); virtual; abstract; procedure StyleChanged(ASender: TObject); virtual; abstract;
public public
constructor Create(ACollection: TCollection; AChart: TCustomChart); overload; constructor Create(ACollection: TCollection; AChart: TCustomChart); overload;
@ -155,7 +175,7 @@ type
property Alignment: TChartAxisAlignment property Alignment: TChartAxisAlignment
read GetAlignment write SetAlignment; read GetAlignment write SetAlignment;
property Arrow: TChartArrow read FArrow write SetArrow; property Arrow: TChartArrow read FArrow write SetArrow;
property Marks: TChartAxisMarks read FMarks write SetMarks; property Marks: TCustomChartAxisMarks read FMarks write SetMarks;
published published
property Grid: TChartAxisGridPen read FGrid write SetGrid; property Grid: TChartAxisGridPen read FGrid write SetGrid;
property TickColor: TColor read FTickColor write SetTickColor default clBlack; property TickColor: TColor read FTickColor write SetTickColor default clBlack;
@ -239,6 +259,15 @@ uses
Math, SysUtils, Math, SysUtils,
TAGeometry, TAIntervalSources; TAGeometry, TAIntervalSources;
{ TChartMinorAxisMarks }
constructor TChartMinorAxisMarks.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FStyle := smsNone;
FFormat := SERIES_MARK_FORMATS[FStyle];
end;
{ TAxisDrawHelper } { TAxisDrawHelper }
procedure TAxisDrawHelper.BarZ(AX1, AY1, AX2, AY2: Integer); procedure TAxisDrawHelper.BarZ(AX1, AY1, AX2, AY2: Integer);
@ -477,34 +506,23 @@ begin
LabelFont := AValue; LabelFont := AValue;
end; end;
{ TChartAxisMarks } { TCustomChartAxisMarks }
constructor TChartAxisMarks.Create(AOwner: TCustomChart); constructor TCustomChartAxisMarks.Create(AOwner: TCustomChart);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FDefaultSource := TIntervalChartSource.Create(AOwner);
FDistance := 1; FDistance := 1;
Frame.Style := psClear; Frame.Style := psClear;
FLabelBrush.Style := bsClear; FLabelBrush.Style := bsClear;
FListener := TListener.Create(@FSource, @StyleChanged);
FStyle := smsValue;
FFormat := SERIES_MARK_FORMATS[FStyle];
end; end;
destructor TChartAxisMarks.Destroy; function TCustomChartAxisMarks.IsFormatStored: Boolean;
begin
FreeAndNil(FListener);
FreeAndNil(FDefaultSource);
inherited;
end;
function TChartAxisMarks.IsFormatStored: Boolean;
begin begin
Result := FStyle <> smsValue; Result := FStyle <> smsValue;
end; end;
function TChartAxisMarks.Measure( function TCustomChartAxisMarks.Measure(ADrawer: IChartDrawer;
ADrawer: IChartDrawer; AIsVertical: Boolean; ATickLength: Integer; AIsVertical: Boolean; ATickLength: Integer;
AValues: TChartValueTextArray): Integer; AValues: TChartValueTextArray): Integer;
var var
t: TChartValueText; t: TChartValueText;
@ -520,6 +538,31 @@ begin
Result += ADrawer.Scale(ATickLength) + ADrawer.Scale(Distance); Result += ADrawer.Scale(ATickLength) + ADrawer.Scale(Distance);
end; end;
procedure TCustomChartAxisMarks.SetStripes(AValue: TChartStyles);
begin
if FStripes = AValue then exit;
FStripes := AValue;
StyleChanged(Self);
end;
{ TChartAxisMarks }
constructor TChartAxisMarks.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FDefaultSource := TIntervalChartSource.Create(AOwner);
FListener := TListener.Create(@FSource, @StyleChanged);
FStyle := smsValue;
FFormat := SERIES_MARK_FORMATS[FStyle];
end;
destructor TChartAxisMarks.Destroy;
begin
FreeAndNil(FListener);
FreeAndNil(FDefaultSource);
inherited;
end;
procedure TChartAxisMarks.SetAtDataOnly(AValue: Boolean); procedure TChartAxisMarks.SetAtDataOnly(AValue: Boolean);
begin begin
if FAtDataOnly = AValue then exit; if FAtDataOnly = AValue then exit;
@ -538,13 +581,6 @@ begin
StyleChanged(Self); StyleChanged(Self);
end; end;
procedure TChartAxisMarks.SetStripes(AValue: TChartStyles);
begin
if FStripes = AValue then exit;
FStripes := AValue;
StyleChanged(Self);
end;
function TChartAxisMarks.SourceDef: TCustomChartSource; function TChartAxisMarks.SourceDef: TCustomChartSource;
begin begin
Result := FSource; Result := FSource;
@ -576,7 +612,7 @@ begin
FGrid := TChartAxisGridPen.Create; FGrid := TChartAxisGridPen.Create;
FGrid.OnChange := @StyleChanged; FGrid.OnChange := @StyleChanged;
FGrid.Style := psDot; FGrid.Style := psDot;
FMarks := TChartAxisMarks.Create(AChart); // FMarks must be created in descendants.
FTickColor := clBlack; FTickColor := clBlack;
FVisible := true; FVisible := true;
end; end;
@ -601,7 +637,7 @@ begin
StyleChanged(Self); StyleChanged(Self);
end; end;
procedure TChartBasicAxis.SetMarks(AValue: TChartAxisMarks); procedure TChartBasicAxis.SetMarks(AValue: TCustomChartAxisMarks);
begin begin
FMarks.Assign(AValue); FMarks.Assign(AValue);
StyleChanged(Self); StyleChanged(Self);