mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 11:16:09 +02:00
TAChart: Fix TBarSeries GetNearestPoint not working correctly in case of AxisTransformations
git-svn-id: trunk@53902 -
This commit is contained in:
parent
f2a9185013
commit
a11063c60e
@ -1138,7 +1138,7 @@ var
|
|||||||
sp, p: TDoublePoint;
|
sp, p: TDoublePoint;
|
||||||
ofs, w: Double;
|
ofs, w: Double;
|
||||||
heights: TDoubleDynArray;
|
heights: TDoubleDynArray;
|
||||||
y, z: Double;
|
y: Double;
|
||||||
stackindex: Integer;
|
stackindex: Integer;
|
||||||
begin
|
begin
|
||||||
if FToolTarget = bttDatapoint then
|
if FToolTarget = bttDatapoint then
|
||||||
@ -1151,13 +1151,9 @@ begin
|
|||||||
AResults.FDist := Sqr(AParams.FRadius) + 1;
|
AResults.FDist := Sqr(AParams.FRadius) + 1;
|
||||||
AResults.FIndex := -1;
|
AResults.FIndex := -1;
|
||||||
|
|
||||||
if IsRotated then
|
|
||||||
z := AxisToGraphX(ZeroLevel)
|
|
||||||
else
|
|
||||||
z := AxisToGraphY(ZeroLevel);
|
|
||||||
SetLength(heights, Source.YCount + 1);
|
SetLength(heights, Source.YCount + 1);
|
||||||
|
|
||||||
// clicked point in image coordinates
|
// clicked point in image units
|
||||||
graphClickPt := ParentChart.ImageToGraph(AParams.FPoint);
|
graphClickPt := ParentChart.ImageToGraph(AParams.FPoint);
|
||||||
if IsRotated then
|
if IsRotated then
|
||||||
Exchange(graphclickpt.X, graphclickpt.Y);
|
Exchange(graphclickpt.X, graphclickpt.Y);
|
||||||
@ -1167,16 +1163,22 @@ begin
|
|||||||
sp := Source[pointindex]^.Point;
|
sp := Source[pointindex]^.Point;
|
||||||
if IsNan(sp) then
|
if IsNan(sp) then
|
||||||
continue;
|
continue;
|
||||||
BarOffsetWidth(sp.X, pointindex, ofs, w);
|
sp.X := AxisToGraphX(sp.X);
|
||||||
|
BarOffsetWidth(sp.X, pointindex, ofs, w); // works with graph units
|
||||||
sp.X := sp.X + ofs;
|
sp.X := sp.X + ofs;
|
||||||
if not InRange(graphClickPt.X, sp.X - w, sp.X + w) then
|
if not InRange(graphClickPt.X, sp.X - w, sp.X + w) then
|
||||||
continue;
|
continue;
|
||||||
heights[0] := z;
|
// Calculate stacked bar levels (in axis units)
|
||||||
heights[1] := NumberOr(sp.Y, z);
|
heights[0] := ZeroLevel;
|
||||||
|
heights[1] := NumberOr(sp.Y, ZeroLevel);
|
||||||
for stackIndex := 1 to Source.YCount-1 do begin
|
for stackIndex := 1 to Source.YCount-1 do begin
|
||||||
y := NumberOr(Source[pointindex]^.YList[stackIndex - 1], 0);
|
y := NumberOr(Source[pointindex]^.YList[stackIndex - 1], 0);
|
||||||
heights[stackIndex + 1] := heights[stacKindex] + y;
|
heights[stackIndex + 1] := heights[stackindex] + y;
|
||||||
end;
|
end;
|
||||||
|
// Convert heights to graph units
|
||||||
|
for stackIndex := 0 to High(heights) do
|
||||||
|
heights[stackIndex] := AxisToGraphY(heights[stackIndex]);
|
||||||
|
// Check if clicked pt is inside stacked bar
|
||||||
for stackindex := 0 to High(heights)-1 do
|
for stackindex := 0 to High(heights)-1 do
|
||||||
if ((heights[stackindex] < heights[stackindex + 1]) and
|
if ((heights[stackindex] < heights[stackindex + 1]) and
|
||||||
InRange(graphClickPt.Y, heights[stackindex], heights[stackIndex + 1]))
|
InRange(graphClickPt.Y, heights[stackindex], heights[stackIndex + 1]))
|
||||||
@ -1188,8 +1190,7 @@ begin
|
|||||||
AResults.FIndex := pointindex;
|
AResults.FIndex := pointindex;
|
||||||
AResults.FYIndex := stackIndex;
|
AResults.FYIndex := stackIndex;
|
||||||
AResults.FValue := DoublePoint(Source[pointindex]^.X, Source[pointindex]^.GetY(stackIndex));
|
AResults.FValue := DoublePoint(Source[pointindex]^.X, Source[pointindex]^.GetY(stackIndex));
|
||||||
if IsRotated then
|
AResults.FValue := AxisToGraph(AResults.FValue);
|
||||||
Exchange(AResults.FValue.X, AResults.FValue.Y);
|
|
||||||
AResults.FImg := ParentChart.GraphToImage(AResults.FValue);
|
AResults.FImg := ParentChart.GraphToImage(AResults.FValue);
|
||||||
Result := true;
|
Result := true;
|
||||||
exit;
|
exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user