TAChart: Move TCustomChartSeries.DefaultFormattedMark to TCustomChartSource.FormatItem

git-svn-id: trunk@24141 -
This commit is contained in:
ask 2010-03-21 13:42:52 +00:00
parent bb59f395e3
commit 85eb77d20d
2 changed files with 19 additions and 18 deletions

View File

@ -116,7 +116,6 @@ type
function AddXY(X, Y: Double): Integer; overload; inline;
procedure Clear; inline;
function Count: Integer; inline;
function DefaultFormattedMark(AIndex: integer): String;
procedure Delete(AIndex: Integer); virtual;
function Extent: TDoubleRect; virtual;
function FormattedMark(AIndex: integer): String;
@ -351,22 +350,6 @@ begin
FMarks := TChartMarks.Create(FChart);
end;
function TChartSeries.DefaultFormattedMark(AIndex: integer): String;
const
TO_PERCENT = 100;
var
total, percent: Double;
begin
total := Source.ValuesTotal;
with Source[AIndex]^ do begin
if total = 0 then
percent := 0
else
percent := Y / total * TO_PERCENT;
Result := Format(FMarks.Format, [y, percent, Text, total, X]);
end;
end;
procedure TChartSeries.Delete(AIndex: Integer);
begin
ListSource.Delete(AIndex);
@ -393,7 +376,7 @@ begin
if Assigned(FOnGetMark) then
FOnGetMark(Result, AIndex)
else
Result := DefaultFormattedMark(AIndex);
Result := Source.FormatItem(Marks.Format, AIndex);
end;
procedure TChartSeries.GetBounds(out ABounds: TDoubleRect);

View File

@ -74,6 +74,7 @@ type
procedure Unsubscribe(AListener: TListener);
public
function Extent: TDoubleRect; virtual;
function FormatItem(const AFormat: String; AIndex: Integer): String;
function ValuesTotal: Double; virtual;
function XOfMax: Double;
function XOfMin: Double;
@ -289,6 +290,23 @@ begin
Result := -1;
end;
function TCustomChartSource.FormatItem(
const AFormat: String; AIndex: Integer): String;
const
TO_PERCENT = 100;
var
total, percent: Double;
begin
total := ValuesTotal;
with Item[AIndex]^ do begin
if total = 0 then
percent := 0
else
percent := Y / total * TO_PERCENT;
Result := Format(AFormat, [y, percent, Text, total, X]);
end;
end;
procedure TCustomChartSource.InvalidateCaches;
begin
FExtentIsValid := false;