TAChart: Extract TCustomChartSource.ValuesInInterval procedure

git-svn-id: trunk@24570 -
This commit is contained in:
ask 2010-04-11 08:41:41 +00:00
parent b60616fe5a
commit 7f95e20e9c
2 changed files with 29 additions and 18 deletions

View File

@ -478,8 +478,7 @@ end;
procedure TChartAxis.GetMarkValues(AMin, AMax: Double);
var
i, count: Integer;
v: Double;
i: Integer;
begin
AMin := GetTransform.GraphToAxis(AMin);
AMax := GetTransform.GraphToAxis(AMax);
@ -491,21 +490,9 @@ begin
for i := 0 to High(FMarkValues) do
FMarkTexts[i] := Format(Marks.Format, [FMarkValues[i]]);
end
else begin
count := 0;
SetLength(FMarkValues, Marks.Source.Count);
SetLength(FMarkTexts, Marks.Source.Count);
for i := 0 to Marks.Source.Count - 1 do begin
with Marks.Source[i]^ do
v := IfThen(IsVertical, Y, X);
if not InRange(v, AMin, AMax) then continue;
FMarkValues[count] := v;
FMarkTexts[count] := Marks.Source.FormatItem(Marks.Format, i);
count += 1;
end;
SetLength(FMarkValues, count);
SetLength(FMarkTexts, count);
end;
else
Marks.Source.ValuesInInterval(
AMin, AMax, Marks.Format, IsVertical, FMarkValues, FMarkTexts);
if Assigned(FOnMarkToText) then
for i := 0 to High(FMarkTexts) do

View File

@ -22,7 +22,7 @@ unit TASources;
interface
uses
Classes, Graphics, SysUtils, TAChartUtils;
Classes, Graphics, SysUtils, Types, TAChartUtils;
type
EEditableSourceRequired = class(EChartError);
@ -61,6 +61,9 @@ type
public
function Extent: TDoubleRect; virtual;
function FormatItem(const AFormat: String; AIndex: Integer): String;
procedure ValuesInInterval(
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
out AValues: TDoubleDynArray; out ATexts: TStringDynArray);
function ValuesTotal: Double; virtual;
function XOfMax: Double;
function XOfMin: Double;
@ -306,6 +309,27 @@ begin
FBroadcaster.Broadcast;
end;
procedure TCustomChartSource.ValuesInInterval(
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
out AValues: TDoubleDynArray; out ATexts: TStringDynArray);
var
i, cnt: Integer;
v: Double;
begin
cnt := 0;
SetLength(AValues, Count);
SetLength(ATexts, Count);
for i := 0 to Count - 1 do begin
v := IfThen(AUseY, Item[i]^.Y, Item[i]^.X);
if not InRange(v, AMin, AMax) then continue;
AValues[cnt] := v;
ATexts[cnt] := FormatItem(AFormat, i);
cnt += 1;
end;
SetLength(AValues, cnt);
SetLength(ATexts, cnt);
end;
function TCustomChartSource.ValuesTotal: Double;
var
i: Integer;