TAChart: Move GetNearestPoint from TBasicChartSeries to TCustomChartSeries

git-svn-id: trunk@28536 -
This commit is contained in:
ask 2010-11-28 15:34:36 +00:00
parent 831f490467
commit e83b1a817d
3 changed files with 25 additions and 21 deletions

View File

@ -78,6 +78,10 @@ type
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetNearestPoint(
ADistFunc: TPointDistFunc; const APoint: TPoint;
out AIndex: Integer; out AImg: TPoint; out AValue: TDoublePoint): Boolean;
virtual;
function GetParentComponent: TComponent; override;
function HasParent: Boolean; override;
@ -291,6 +295,17 @@ begin
GetLegendItems(AItems);
end;
function TCustomChartSeries.GetNearestPoint(
ADistFunc: TPointDistFunc; const APoint: TPoint; out AIndex: Integer;
out AImg: TPoint; out AValue: TDoublePoint): Boolean;
begin
Unused(ADistFunc, APoint);
AIndex := 0;
AImg := Point(0, 0);
AValue := ZeroDoublePoint;
Result := false;
end;
function TCustomChartSeries.GetParentComponent: TComponent;
begin
Result := FChart;

View File

@ -79,10 +79,6 @@ type
public
procedure Draw(ACanvas: TCanvas); virtual; abstract;
function GetNearestPoint(
ADistFunc: TPointDistFunc; const APoint: TPoint;
out AIndex: Integer; out AImg: TPoint; out AValue: TDoublePoint): Boolean;
virtual;
function IsEmpty: Boolean; virtual; abstract;
procedure MovePoint(var AIndex: Integer; const ANewPos: TPoint); virtual;
@ -1154,17 +1150,6 @@ begin
inherited;
end;
function TBasicChartSeries.GetNearestPoint(
ADistFunc: TPointDistFunc; const APoint: TPoint;
out AIndex: Integer; out AImg: TPoint; out AValue: TDoublePoint): Boolean;
begin
Unused(ADistFunc, APoint);
AIndex := 0;
AImg := Point(0, 0);
AValue := ZeroDoublePoint;
Result := false;
end;
function TBasicChartSeries.GraphToAxisX(AX: Double): Double;
begin
Result := AX;

View File

@ -284,7 +284,7 @@ implementation
uses
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
TADrawUtils, TASubcomponentsEditor;
TACustomSeries, TADrawUtils, TASubcomponentsEditor;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
@ -812,7 +812,8 @@ begin
df := DIST_FUNCS[FChart.ReticuleMode];
for i := 0 to FChart.SeriesCount - 1 do
if
FChart.Series[i].GetNearestPoint(
(FChart.Series[i] is TCustomChartSeries) and
(FChart.Series[i] as TCustomChartSeries).GetNearestPoint(
df, APoint, cur.pointIndex, cur.retPos, cur.value) and
PtInRect(FChart.ClipRect, cur.retPos)
then begin
@ -1015,7 +1016,8 @@ end;
procedure TDataPointDragTool.MouseDown(APoint: TPoint);
var
i, d, bestd, idx: Integer;
s, bests: TBasicChartSeries;
bests: TBasicChartSeries;
s: TCustomChartSeries;
affected: TBooleanDynArray;
dummy: TDoublePoint;
nearest: TPoint;
@ -1024,9 +1026,11 @@ begin
bests := nil;
affected := ParseAffectedSeries;
for i := 0 to FChart.SeriesCount - 1 do begin
if not affected[i] then continue;
s := FChart.Series[i];
if not s.GetNearestPoint(@PointDist, APoint, idx, nearest, dummy) then continue;
if not affected[i] or not (FChart.Series[i] is TCustomChartSeries) then
continue;
s := FChart.Series[i] as TCustomChartSeries;
if not s.GetNearestPoint(@PointDist, APoint, idx, nearest, dummy) then
continue;
d := PointDist(APoint, nearest);
if d < bestd then begin
bestd := d;