diff --git a/components/tachart/demo/axis/main.lfm b/components/tachart/demo/axis/main.lfm index 22e9bae4be..99800ece6f 100644 --- a/components/tachart/demo/axis/main.lfm +++ b/components/tachart/demo/axis/main.lfm @@ -136,6 +136,8 @@ object Form1: TForm1 Marks.Distance = 4 Marks.LabelFont.Height = -9 Marks.LabelFont.Orientation = 900 + Marks.Format = '%0:.9g' + Marks.Style = smsValue end> end item diff --git a/components/tachart/tachartaxis.pas b/components/tachart/tachartaxis.pas index a6e24f5585..b6903fa73d 100644 --- a/components/tachart/tachartaxis.pas +++ b/components/tachart/tachartaxis.pas @@ -38,7 +38,9 @@ type TChartMinorAxis = class(TChartBasicAxis) strict private FIntervalsCount: Cardinal; + function GetMarks: TChartMinorAxisMarks; inline; procedure SetIntervalsCount(AValue: Cardinal); + procedure SetMarks(AValue: TChartMinorAxisMarks); protected function GetDisplayName: String; override; strict protected @@ -51,7 +53,7 @@ type published property IntervalsCount: Cardinal 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; end; @@ -112,10 +114,12 @@ type FTransformations: TChartAxisTransformations; FZPosition: TChartDistance; + function GetMarks: TChartAxisMarks; inline; function GetTransform: TChartAxisTransformations; procedure SetAxisPen(AValue: TChartAxisPen); procedure SetGroup(AValue: Integer); procedure SetInverted(AValue: Boolean); + procedure SetMarks(AValue: TChartAxisMarks); procedure SetMinors(AValue: TChartMinorAxisList); procedure SetOnMarkToText(AValue: TChartAxisMarkToTextEvent); procedure SetTitle(AValue: TChartAxisTitle); @@ -149,7 +153,7 @@ type property Group: Integer read FGroup write SetGroup default 0; // Inverts the axis scale from increasing to decreasing. 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 TickLength default DEF_TICK_LENGTH; property Title: TChartAxisTitle read FTitle write SetTitle; @@ -286,6 +290,8 @@ constructor TChartMinorAxis.Create(ACollection: TCollection); begin inherited Create(ACollection, (ACollection as TChartMinorAxisList).GetChart); FIntervalsCount := DEF_INTERVALS_COUNT; + FMarks := TChartMinorAxisMarks.Create( + (ACollection as TChartMinorAxisList).GetChart); TickLength := DEF_TICK_LENGTH div 2; end; @@ -299,6 +305,11 @@ begin Result := 'M'; end; +function TChartMinorAxis.GetMarks: TChartMinorAxisMarks; +begin + Result := TChartMinorAxisMarks(inherited Marks); +end; + function TChartMinorAxis.GetMarkValues(AMin, AMax: Double): TChartValueTextArray; var c, ic: Integer; @@ -327,6 +338,11 @@ begin StyleChanged(Self); end; +procedure TChartMinorAxis.SetMarks(AValue: TChartMinorAxisMarks); +begin + inherited Marks := AValue; +end; + procedure TChartMinorAxis.StyleChanged(ASender: TObject); begin (Collection.Owner as TChartAxis).StyleChanged(ASender); @@ -389,6 +405,7 @@ begin FAxisPen.OnChange := @StyleChanged; FAxisPen.Visible := false; FListener := TListener.Create(@FTransformations, @StyleChanged); + FMarks := TChartAxisMarks.Create(ACollection.Owner as TCustomChart); FMinors := TChartMinorAxisList.Create(Self); TickLength := DEF_TICK_LENGTH; FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart); @@ -494,6 +511,11 @@ begin Result += Format(CAPTION_FMT, [Title.Caption]); end; +function TChartAxis.GetMarks: TChartAxisMarks; +begin + Result := TChartAxisMarks(inherited Marks); +end; + procedure TChartAxis.GetMarkValues(AMin, AMax: Double); var i: Integer; @@ -667,6 +689,11 @@ begin StyleChanged(Self); end; +procedure TChartAxis.SetMarks(AValue: TChartAxisMarks); +begin + inherited Marks := AValue; +end; + procedure TChartAxis.SetMinors(AValue: TChartMinorAxisList); begin FMinors.Assign(AValue); diff --git a/components/tachart/tachartaxisutils.pas b/components/tachart/tachartaxisutils.pas index fc9067e235..fb43f5a4f1 100644 --- a/components/tachart/tachartaxisutils.pas +++ b/components/tachart/tachartaxisutils.pas @@ -84,31 +84,51 @@ type end; {$IFNDEF fpdoc} // Workaround for issue #18549. - TCustomChartAxisMarks = + TBasicChartAxisMarks = specialize TGenericChartMarks; {$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 = class(TCustomChartAxisMarks) - private + strict private FAtDataOnly: Boolean; FDefaultSource: TCustomChartSource; FListener: TListener; FSource: TCustomChartSource; - FStripes: TChartStyles; - function IsFormatStored: Boolean; procedure SetAtDataOnly(AValue: Boolean); procedure SetSource(AValue: TCustomChartSource); - procedure SetStripes(AValue: TChartStyles); public constructor Create(AOwner: TCustomChart); destructor Destroy; override; - function Measure( - ADrawer: IChartDrawer; AIsVertical: Boolean; ATickLength: Integer; - AValues: TChartValueTextArray): Integer; function SourceDef: TCustomChartSource; published property AtDataOnly: Boolean @@ -119,7 +139,7 @@ type property LabelBrush; property OverlapPolicy; property Source: TCustomChartSource read FSource write SetSource; - property Stripes: TChartStyles read FStripes write SetStripes; + property Stripes; property Style default smsValue; property YIndex; end; @@ -130,19 +150,19 @@ type strict private FArrow: TChartArrow; FGrid: TChartAxisGridPen; - FMarks: TChartAxisMarks; FTickColor: TColor; FTickLength: Integer; FVisible: Boolean; procedure SetArrow(AValue: TChartArrow); procedure SetGrid(AValue: TChartAxisGridPen); - procedure SetMarks(AValue: TChartAxisMarks); procedure SetTickColor(AValue: TColor); procedure SetTickLength(AValue: Integer); procedure SetVisible(AValue: Boolean); strict protected + FMarks: TCustomChartAxisMarks; function GetAlignment: TChartAxisAlignment; virtual; abstract; procedure SetAlignment(AValue: TChartAxisAlignment); virtual; abstract; + procedure SetMarks(AValue: TCustomChartAxisMarks); procedure StyleChanged(ASender: TObject); virtual; abstract; public constructor Create(ACollection: TCollection; AChart: TCustomChart); overload; @@ -155,7 +175,7 @@ type property Alignment: TChartAxisAlignment read GetAlignment write SetAlignment; property Arrow: TChartArrow read FArrow write SetArrow; - property Marks: TChartAxisMarks read FMarks write SetMarks; + property Marks: TCustomChartAxisMarks read FMarks write SetMarks; published property Grid: TChartAxisGridPen read FGrid write SetGrid; property TickColor: TColor read FTickColor write SetTickColor default clBlack; @@ -239,6 +259,15 @@ uses Math, SysUtils, TAGeometry, TAIntervalSources; +{ TChartMinorAxisMarks } + +constructor TChartMinorAxisMarks.Create(AOwner: TCustomChart); +begin + inherited Create(AOwner); + FStyle := smsNone; + FFormat := SERIES_MARK_FORMATS[FStyle]; +end; + { TAxisDrawHelper } procedure TAxisDrawHelper.BarZ(AX1, AY1, AX2, AY2: Integer); @@ -477,34 +506,23 @@ begin LabelFont := AValue; end; -{ TChartAxisMarks } +{ TCustomChartAxisMarks } -constructor TChartAxisMarks.Create(AOwner: TCustomChart); +constructor TCustomChartAxisMarks.Create(AOwner: TCustomChart); begin inherited Create(AOwner); - FDefaultSource := TIntervalChartSource.Create(AOwner); FDistance := 1; Frame.Style := psClear; FLabelBrush.Style := bsClear; - FListener := TListener.Create(@FSource, @StyleChanged); - FStyle := smsValue; - FFormat := SERIES_MARK_FORMATS[FStyle]; end; -destructor TChartAxisMarks.Destroy; -begin - FreeAndNil(FListener); - FreeAndNil(FDefaultSource); - inherited; -end; - -function TChartAxisMarks.IsFormatStored: Boolean; +function TCustomChartAxisMarks.IsFormatStored: Boolean; begin Result := FStyle <> smsValue; end; -function TChartAxisMarks.Measure( - ADrawer: IChartDrawer; AIsVertical: Boolean; ATickLength: Integer; +function TCustomChartAxisMarks.Measure(ADrawer: IChartDrawer; + AIsVertical: Boolean; ATickLength: Integer; AValues: TChartValueTextArray): Integer; var t: TChartValueText; @@ -520,6 +538,31 @@ begin Result += ADrawer.Scale(ATickLength) + ADrawer.Scale(Distance); 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); begin if FAtDataOnly = AValue then exit; @@ -538,13 +581,6 @@ begin StyleChanged(Self); end; -procedure TChartAxisMarks.SetStripes(AValue: TChartStyles); -begin - if FStripes = AValue then exit; - FStripes := AValue; - StyleChanged(Self); -end; - function TChartAxisMarks.SourceDef: TCustomChartSource; begin Result := FSource; @@ -576,7 +612,7 @@ begin FGrid := TChartAxisGridPen.Create; FGrid.OnChange := @StyleChanged; FGrid.Style := psDot; - FMarks := TChartAxisMarks.Create(AChart); + // FMarks must be created in descendants. FTickColor := clBlack; FVisible := true; end; @@ -601,7 +637,7 @@ begin StyleChanged(Self); end; -procedure TChartBasicAxis.SetMarks(AValue: TChartAxisMarks); +procedure TChartBasicAxis.SetMarks(AValue: TCustomChartAxisMarks); begin FMarks.Assign(AValue); StyleChanged(Self);