TAChart: Add TConstantLineDragTool.AffectedSeries property

git-svn-id: trunk@25758 -
This commit is contained in:
ask 2010-05-30 06:27:12 +00:00
parent 0b718f0db3
commit 5aaca35cb8

View File

@ -22,7 +22,7 @@ interface
{$H+} {$H+}
uses uses
Classes, Controls, Classes, Controls, Types,
TAGraph, TASeries; TAGraph, TASeries;
type type
@ -161,14 +161,18 @@ type
TConstantLineDragTool = class(TChartTool) TConstantLineDragTool = class(TChartTool)
private private
FAffectedSeries: String;
FGrabRadius: Integer; FGrabRadius: Integer;
FLine: TConstantLine; FLine: TConstantLine;
function ParseAffectedSeries: TBooleanDynArray;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure MouseDown(APoint: TPoint); override; procedure MouseDown(APoint: TPoint); override;
procedure MouseMove(APoint: TPoint); override; procedure MouseMove(APoint: TPoint); override;
procedure MouseUp(APoint: TPoint); override; procedure MouseUp(APoint: TPoint); override;
published published
property AffectedSeries: String
read FAffectedSeries write FAffectedSeries;
property GrabRadius: Integer property GrabRadius: Integer
read FGrabRadius write FGrabRadius default DEF_GRAB_RADIUS; read FGrabRadius write FGrabRadius default DEF_GRAB_RADIUS;
end; end;
@ -190,7 +194,7 @@ resourcestring
implementation implementation
uses uses
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils, Types, ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
TAChartUtils, TASubcomponentsEditor; TAChartUtils, TASubcomponentsEditor;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF} {$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
@ -749,11 +753,13 @@ procedure TConstantLineDragTool.MouseDown(APoint: TPoint);
var var
i, d, bestd: Integer; i, d, bestd: Integer;
c, bestc: TConstantLine; c, bestc: TConstantLine;
affected: TBooleanDynArray;
begin begin
bestd := MaxInt; bestd := MaxInt;
bestc := nil; bestc := nil;
affected := ParseAffectedSeries;
for i := 0 to FChart.SeriesCount - 1 do begin for i := 0 to FChart.SeriesCount - 1 do begin
if not (FChart.Series[i] is TConstantLine) then continue; if not affected[i] or not (FChart.Series[i] is TConstantLine) then continue;
c := FChart.Series[i] as TConstantLine; c := FChart.Series[i] as TConstantLine;
if c.LineStyle = lsVertical then if c.LineStyle = lsVertical then
d := FChart.XGraphToImage(c.Position) - APoint.X d := FChart.XGraphToImage(c.Position) - APoint.X
@ -793,6 +799,30 @@ begin
Handled; Handled;
end; end;
function TConstantLineDragTool.ParseAffectedSeries: TBooleanDynArray;
var
s: TStringList;
i, p: Integer;
begin
SetLength(Result, FChart.SeriesCount);
if AffectedSeries = '' then begin
FillChar(Result[0], Length(Result), true);
exit;
end;
s := TStringList.Create;
try
s.CommaText := AffectedSeries;
FillChar(Result[0], Length(Result), false);
for i := 0 to s.Count - 1 do begin
p := StrToIntDef(s[i], -1);
if InRange(p, 0, High(Result)) then
Result[p] := true;
end;
finally
s.Free;
end;
end;
initialization initialization
ToolsClassRegistry := TStringList.Create; ToolsClassRegistry := TStringList.Create;