mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 23:39:40 +02:00
TAChart: BarSeries accepts tool hits along upper bar border (not just at center of bar border).
git-svn-id: trunk@53932 -
This commit is contained in:
parent
84f6fb1761
commit
fa280dc697
@ -267,6 +267,7 @@ type
|
|||||||
FStacked: Boolean;
|
FStacked: Boolean;
|
||||||
FUpBound: Integer;
|
FUpBound: Integer;
|
||||||
FUseReticule: Boolean;
|
FUseReticule: Boolean;
|
||||||
|
FOptimizeX: Boolean;
|
||||||
|
|
||||||
procedure AfterDrawPointer(
|
procedure AfterDrawPointer(
|
||||||
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint); virtual;
|
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint); virtual;
|
||||||
@ -281,6 +282,8 @@ type
|
|||||||
function NearestXNumber(var AIndex: Integer; ADir: Integer): Double;
|
function NearestXNumber(var AIndex: Integer; ADir: Integer): Double;
|
||||||
procedure PrepareGraphPoints(
|
procedure PrepareGraphPoints(
|
||||||
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
|
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
|
||||||
|
function ToolTargetDistance(const AParams: TNearestPointParams;
|
||||||
|
APoint: TDoublePoint; APointIndex: Integer): Integer; virtual;
|
||||||
procedure UpdateGraphPoints(AIndex: Integer; ACumulative: Boolean); overload; inline;
|
procedure UpdateGraphPoints(AIndex: Integer; ACumulative: Boolean); overload; inline;
|
||||||
procedure UpdateGraphPoints(AIndex, ALo, AUp: Integer; ACumulative: Boolean); overload;
|
procedure UpdateGraphPoints(AIndex, ALo, AUp: Integer; ACumulative: Boolean); overload;
|
||||||
procedure UpdateMinXRange;
|
procedure UpdateMinXRange;
|
||||||
@ -296,6 +299,7 @@ type
|
|||||||
read FOnGetPointerStyle write FOnGetPointerStyle;
|
read FOnGetPointerStyle write FOnGetPointerStyle;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
public
|
public
|
||||||
procedure Assign(ASource: TPersistent); override;
|
procedure Assign(ASource: TPersistent); override;
|
||||||
@ -1075,6 +1079,12 @@ begin
|
|||||||
inherited Assign(ASource);
|
inherited Assign(ASource);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TBasicPointSeries.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FOptimizeX := true;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TBasicPointSeries.Destroy;
|
destructor TBasicPointSeries.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FPointer);
|
FreeAndNil(FPointer);
|
||||||
@ -1268,17 +1278,16 @@ function TBasicPointSeries.GetNearestPoint(
|
|||||||
|
|
||||||
var
|
var
|
||||||
dist, i, j, lb, ub: Integer;
|
dist, i, j, lb, ub: Integer;
|
||||||
pt: TPoint;
|
|
||||||
sp: TDoublePoint;
|
sp: TDoublePoint;
|
||||||
tmpPt: TPoint;
|
tmpPt: TPoint;
|
||||||
tmpSP: TDoublePoint;
|
tmpSP: TDoublePoint;
|
||||||
tmpDist: Integer;
|
tmpDist: Integer;
|
||||||
begin
|
begin
|
||||||
AResults.FDist := Sqr(AParams.FRadius) + 1;
|
AResults.FDist := Sqr(AParams.FRadius) + 1; // the dist func does not calc sqrt
|
||||||
AResults.FIndex := -1;
|
AResults.FIndex := -1;
|
||||||
AResults.FXIndex := 0;
|
AResults.FXIndex := 0;
|
||||||
AResults.FYIndex := 0;
|
AResults.FYIndex := 0;
|
||||||
if AParams.FOptimizeX then
|
if FOptimizeX and AParams.FOptimizeX then
|
||||||
Source.FindBounds(
|
Source.FindBounds(
|
||||||
GetGrabBound(-AParams.FRadius),
|
GetGrabBound(-AParams.FRadius),
|
||||||
GetGrabBound( AParams.FRadius), lb, ub)
|
GetGrabBound( AParams.FRadius), lb, ub)
|
||||||
@ -1287,6 +1296,7 @@ begin
|
|||||||
ub := Count - 1;
|
ub := Count - 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
dist := AResults.FDist;
|
||||||
for i := lb to ub do begin
|
for i := lb to ub do begin
|
||||||
sp := Source[i]^.Point;
|
sp := Source[i]^.Point;
|
||||||
if IsNan(sp) then
|
if IsNan(sp) then
|
||||||
@ -1297,41 +1307,35 @@ begin
|
|||||||
// an integer overflow, so ADistFunc should use saturation arithmetics.
|
// an integer overflow, so ADistFunc should use saturation arithmetics.
|
||||||
|
|
||||||
// Find nearest point of datapoint at (x, y)
|
// Find nearest point of datapoint at (x, y)
|
||||||
if (nptPoint in AParams.FTargets) then begin
|
if (nptPoint in AParams.FTargets) then
|
||||||
pt := ParentChart.GraphToImage(AxisToGraph(sp));
|
dist := Min(dist, ToolTargetDistance(AParams, sp, i));
|
||||||
dist := AParams.FDistFunc(AParams.FPoint, pt);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Find nearest point to additional y values (at x).
|
// Find nearest point to additional y values (at x).
|
||||||
// In case of stacked data points check the stacked values.
|
// In case of stacked data points check the stacked values.
|
||||||
if (nptYList in AParams.FTargets) then begin
|
if (nptYList in AParams.FTargets) and (dist > 0) then begin
|
||||||
tmpSp := sp;
|
tmpSp := sp;
|
||||||
for j := 0 to Source.YCount - 2 do begin
|
for j := 0 to Source.YCount - 2 do begin
|
||||||
if FStacked then
|
if FStacked then
|
||||||
tmpSp.Y += Source[i]^.YList[j] else
|
tmpSp.Y += Source[i]^.YList[j] else
|
||||||
tmpSp.Y := Source[i]^.YList[j];
|
tmpSp.Y := Source[i]^.YList[j];
|
||||||
tmpPt := ParentChart.GraphToImage(AxisToGraph(tmpSp));
|
tmpDist := ToolTargetDistance(AParams, tmpSp, i);
|
||||||
tmpDist := AParams.FDistFunc(AParams.FPoint, tmpPt);
|
|
||||||
if tmpDist < dist then begin
|
if tmpDist < dist then begin
|
||||||
dist := tmpDist;
|
dist := tmpDist;
|
||||||
sp := tmpSp;
|
sp := tmpSp;
|
||||||
pt := tmpPt;
|
|
||||||
AResults.FYIndex := j + 1; // FYIndex = 0 refers to the regular y
|
AResults.FYIndex := j + 1; // FYIndex = 0 refers to the regular y
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Find nearest point of additional x values (at y)
|
// Find nearest point of additional x values (at y)
|
||||||
if (nptXList in AParams.FTargets) then begin
|
if (nptXList in AParams.FTargets) and (dist > 0) then begin
|
||||||
tmpSp := sp;
|
tmpSp := sp;
|
||||||
for j := 0 to Source.XCount - 2 do begin
|
for j := 0 to Source.XCount - 2 do begin
|
||||||
tmpSp.X := Source[i]^.XList[j];
|
tmpSp.X := Source[i]^.XList[j];
|
||||||
tmpPt := parentChart.GraphToImage(AxisToGraph(tmpSp));
|
tmpDist := ToolTargetDistance(AParams, tmpSp, i);
|
||||||
tmpDist := AParams.FDistFunc(AParams.FPoint, tmpPt);
|
|
||||||
if tmpDist < dist then begin
|
if tmpDist < dist then begin
|
||||||
dist := tmpDist;
|
dist := tmpDist;
|
||||||
sp := tmpSp;
|
sp := tmpSp;
|
||||||
pt := tmpPt;
|
|
||||||
AResults.FXIndex := j + 1; // FXindex = 0 refers to the regular x
|
AResults.FXIndex := j + 1; // FXindex = 0 refers to the regular x
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1345,8 +1349,9 @@ begin
|
|||||||
|
|
||||||
AResults.FDist := dist;
|
AResults.FDist := dist;
|
||||||
AResults.FIndex := i;
|
AResults.FIndex := i;
|
||||||
AResults.FImg := pt;
|
|
||||||
AResults.FValue := sp;
|
AResults.FValue := sp;
|
||||||
|
AResults.FImg := ParentChart.GraphToImage(AxisToGraph(sp));
|
||||||
|
if dist = 0 then break;
|
||||||
end;
|
end;
|
||||||
Result := AResults.FIndex >= 0;
|
Result := AResults.FIndex >= 0;
|
||||||
end;
|
end;
|
||||||
@ -1438,6 +1443,16 @@ begin
|
|||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBasicPointSeries.ToolTargetDistance(const AParams: TNearestPointParams;
|
||||||
|
APoint: TDoublePoint; APointIndex: Integer): Integer;
|
||||||
|
var
|
||||||
|
pt: TPoint;
|
||||||
|
begin
|
||||||
|
Unused(APointIndex);
|
||||||
|
pt := ParentChart.GraphToImage(AxisToGraph(APoint));
|
||||||
|
Result := AParams.FDistFunc(AParams.FPoint, pt);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBasicPointSeries.UpdateGraphPoints(AIndex, ALo, AUp: Integer;
|
procedure TBasicPointSeries.UpdateGraphPoints(AIndex, ALo, AUp: Integer;
|
||||||
ACumulative: Boolean);
|
ACumulative: Boolean);
|
||||||
var
|
var
|
||||||
|
@ -64,6 +64,8 @@ type
|
|||||||
procedure SetZeroLevel(AValue: Double);
|
procedure SetZeroLevel(AValue: Double);
|
||||||
strict protected
|
strict protected
|
||||||
function GetLabelDataPoint(AIndex: Integer): TDoublePoint; override;
|
function GetLabelDataPoint(AIndex: Integer): TDoublePoint; override;
|
||||||
|
function ToolTargetDistance(const AParams: TNearestPointParams;
|
||||||
|
APoint: TDoublePoint; APointIndex: Integer): Integer; override;
|
||||||
protected
|
protected
|
||||||
procedure BarOffsetWidth(
|
procedure BarOffsetWidth(
|
||||||
AX: Double; AIndex: Integer; out AOffset, AWidth: Double);
|
AX: Double; AIndex: Integer; out AOffset, AWidth: Double);
|
||||||
@ -957,6 +959,7 @@ begin
|
|||||||
FBarBrush.Color := clRed;
|
FBarBrush.Color := clRed;
|
||||||
|
|
||||||
FStacked := true;
|
FStacked := true;
|
||||||
|
FOptimizeX := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TBarSeries.Destroy;
|
destructor TBarSeries.Destroy;
|
||||||
@ -1263,6 +1266,39 @@ begin
|
|||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBarSeries.ToolTargetDistance(const AParams: TNearestPointParams;
|
||||||
|
APoint: TDoublePoint; APointIndex: Integer): Integer;
|
||||||
|
var
|
||||||
|
spt: TDoublePoint;
|
||||||
|
tpt, pt1, pt2: TPoint;
|
||||||
|
ofs, w: Double;
|
||||||
|
dist1, dist2: Integer;
|
||||||
|
begin
|
||||||
|
BarOffsetWidth(APoint.X, APointIndex, ofs, w);
|
||||||
|
spt := DoublePoint(APoint.X + ofs - w, APoint.Y);
|
||||||
|
pt1 := ParentChart.GraphToImage(AxisToGraph(spt));
|
||||||
|
|
||||||
|
spt := DoublePoint(APoint.X + ofs + w, APoint.Y);
|
||||||
|
pt2 := ParentChart.GraphToImage(AxisToGraph(spt));
|
||||||
|
|
||||||
|
tpt := AParams.FPoint;
|
||||||
|
if IsRotated then begin
|
||||||
|
Exchange(pt1.X, pt1.Y);
|
||||||
|
Exchange(pt2.X, pt2.Y);
|
||||||
|
Exchange(tpt.X, tpt.Y);
|
||||||
|
end;
|
||||||
|
if pt2.X < pt1.x then Exchange(pt2.X, pt1.X);
|
||||||
|
|
||||||
|
if InRange(tpt.X, pt1.x, pt2.x) then
|
||||||
|
Result := sqr(tpt.Y - pt1.Y) // DistFunc does not calculate sqrt!
|
||||||
|
else begin
|
||||||
|
dist1 := AParams.FDistFunc(tpt, pt1);
|
||||||
|
dist2 := AParams.FDistFunc(tpt, pt2);
|
||||||
|
Result := Min(dist1, dist2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TAreaSeries }
|
{ TAreaSeries }
|
||||||
|
|
||||||
procedure TAreaSeries.Assign(ASource: TPersistent);
|
procedure TAreaSeries.Assign(ASource: TPersistent);
|
||||||
|
Loading…
Reference in New Issue
Block a user