mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-03 17:18:13 +02:00
TAChart: Add property ToolTargets to TCustomChartSeries and publish it in most of its descendants for finer control of datapoint tool behavior.
git-svn-id: trunk@54286 -
This commit is contained in:
parent
8ab48719ee
commit
1d32c97e32
@ -50,6 +50,7 @@ type
|
||||
FAxisIndexX: TChartAxisIndex;
|
||||
FAxisIndexY: TChartAxisIndex;
|
||||
FLegend: TChartSeriesLegend;
|
||||
FToolTargets: TNearestPointTargets;
|
||||
FTitle: String;
|
||||
procedure SetAxisIndexX(AValue: TChartAxisIndex);
|
||||
procedure SetAxisIndexY(AValue: TChartAxisIndex);
|
||||
@ -83,6 +84,8 @@ type
|
||||
function LegendTextStyle(AStyle: TChartStyle): String;
|
||||
procedure SetIndex(AValue: Integer); override;
|
||||
function TitleIsStored: Boolean; virtual;
|
||||
property ToolTargets: TNearestPointTargets
|
||||
read FToolTargets write FToolTargets default [nptPoint];
|
||||
|
||||
public
|
||||
function AxisToGraph(const APoint: TDoublePoint): TDoublePoint; inline;
|
||||
@ -314,6 +317,7 @@ type
|
||||
const ANewPos: TDoublePoint); override;
|
||||
property MarkPositions: TLinearMarkPositions
|
||||
read FMarkPositions write SetMarkPositions default lmpOutside;
|
||||
property ToolTargets default [nptPoint, nptYList];
|
||||
property UseReticule: Boolean
|
||||
read FUseReticule write SetUseReticule default false;
|
||||
property ExtentPointIndexFirst: Integer read FLoBound;
|
||||
@ -354,6 +358,7 @@ begin
|
||||
Self.FAxisIndexY := FAxisIndexY;
|
||||
Self.Legend := FLegend;
|
||||
Self.FTitle := FTitle;
|
||||
Self.FToolTargets := FToolTargets;
|
||||
end;
|
||||
inherited Assign(ASource);
|
||||
end;
|
||||
@ -383,6 +388,7 @@ begin
|
||||
FAxisIndexX := DEF_AXIS_INDEX;
|
||||
FAxisIndexY := DEF_AXIS_INDEX;
|
||||
FLegend := TChartSeriesLegend.Create(FChart);
|
||||
FToolTargets := [nptPoint];
|
||||
FShadow := TChartShadow.Create(FChart);
|
||||
end;
|
||||
|
||||
@ -1099,6 +1105,7 @@ constructor TBasicPointSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
FOptimizeX := true;
|
||||
ToolTargets := [nptPoint, nptYList];
|
||||
end;
|
||||
|
||||
destructor TBasicPointSeries.Destroy;
|
||||
@ -1325,14 +1332,16 @@ begin
|
||||
// an integer overflow, so ADistFunc should use saturation arithmetics.
|
||||
|
||||
// Find nearest point of datapoint at (x, y)
|
||||
if (nptPoint in AParams.FTargets) then begin
|
||||
if (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then
|
||||
begin
|
||||
pt := AxisToGraph(sp);
|
||||
dist := Min(dist, ToolTargetDistance(AParams, pt, i, 0, 0));
|
||||
end;
|
||||
|
||||
// Find nearest point to additional y values (at x).
|
||||
// In case of stacked data points check the stacked values.
|
||||
if (nptYList in AParams.FTargets) and (dist > 0) then begin
|
||||
if (dist > 0) and (nptYList in AParams.FTargets) and (nptYList in ToolTargets)
|
||||
then begin
|
||||
tmpSp := sp;
|
||||
for j := 0 to Source.YCount - 2 do begin
|
||||
if FStacked then
|
||||
@ -1350,7 +1359,8 @@ begin
|
||||
end;
|
||||
|
||||
// Find nearest point of additional x values (at y)
|
||||
if (nptXList in AParams.FTargets) and (dist > 0) then begin
|
||||
if (dist > 0) and (nptXList in AParams.FTargets) and (nptXList in ToolTargets)
|
||||
then begin
|
||||
tmpSp := sp;
|
||||
for j := 0 to Source.XCount - 2 do begin
|
||||
tmpSp.X := Source[i]^.XList[j];
|
||||
|
@ -78,6 +78,7 @@ type
|
||||
property OverrideColor: TBubbleOverrideColors
|
||||
read FOverrideColor write SetOverrideColor default [];
|
||||
property Source;
|
||||
property ToolTargets default [nptPoint, nptYList, nptCustom];
|
||||
end;
|
||||
|
||||
TBoxAndWhiskerSeriesLegendDir = (bwlHorizontal, bwlVertical, bwlAuto);
|
||||
@ -124,6 +125,7 @@ type
|
||||
property LegendDirection: TBoxAndWhiskerSeriesLegendDir
|
||||
read FLegendDirection write SetLegendDirection default bwlHorizontal;
|
||||
property MedianPen: TPen read FMedianPen write SetMedianPen;
|
||||
property ToolTargets default [nptPoint, nptYList, nptCustom];
|
||||
property WidthStyle: TBoxAndWhiskerSeriesWidthStyle
|
||||
read FWidthStyle write FWidthStyle default bwsPercent;
|
||||
property WhiskersPen: TPen read FWhiskersPen write SetWhiskersPen;
|
||||
@ -194,6 +196,7 @@ type
|
||||
property Mode: TOHLCMode read FMode write SetOHLCMode;
|
||||
property TickWidth: integer
|
||||
read FTickWidth write SetTickWidth default DEF_OHLC_TICK_WIDTH;
|
||||
property ToolTargets default [nptPoint, nptYList, nptCustom];
|
||||
property YIndexClose: integer
|
||||
read FYIndexClose write SetYIndexClose default DEF_YINDEX_CLOSE;
|
||||
property YIndexHigh: Integer
|
||||
@ -246,6 +249,7 @@ type
|
||||
property AxisIndexY;
|
||||
property Pen: TPen read FPen write SetPen;
|
||||
property Source;
|
||||
property ToolTargets default [nptPoint, nptXList, nptYList, nptCustom];
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -466,6 +470,7 @@ end;
|
||||
constructor TBubbleSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ToolTargets := [nptPoint, nptYList, nptCustom];
|
||||
FBubblePen := TPen.Create;
|
||||
FBubblePen.OnChange := @StyleChanged;
|
||||
FBubbleBrush := TBrush.Create;
|
||||
@ -610,9 +615,11 @@ var
|
||||
begin
|
||||
Result := inherited;
|
||||
|
||||
if Result then begin
|
||||
if Result and (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then
|
||||
if (AResults.FYIndex = 0) then
|
||||
exit;
|
||||
|
||||
if Result and (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then
|
||||
if (AResults.FYIndex = 1) then begin
|
||||
item := Source[AResults.FIndex];
|
||||
GetBubbleRect(item, iRect);
|
||||
@ -624,9 +631,8 @@ begin
|
||||
AResults.FImg := p + Point(round(rx * cosPhi), round(ry * sinPhi));
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
if (nptCustom in AParams.FTargets) then begin
|
||||
if (nptCustom in AParams.FTargets) and (nptCustom in ToolTargets) then begin
|
||||
dist := MaxInt;
|
||||
for i := 0 to Count - 1 do begin
|
||||
item := Source[i];
|
||||
@ -817,6 +823,7 @@ end;
|
||||
constructor TBoxAndWhiskerSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ToolTargets := [nptPoint, nptYList, nptCustom];
|
||||
FOptimizeX := false;
|
||||
FBoxBrush := TBrush.Create;
|
||||
FBoxBrush.OnChange := @StyleChanged;
|
||||
@ -953,9 +960,15 @@ var
|
||||
begin
|
||||
Result := inherited;
|
||||
|
||||
if Result and ([nptPoint, nptYList] * AParams.FTargets = [nptPoint, nptYList]) then
|
||||
exit;
|
||||
if not (nptCustom in AParams.FTargets) then
|
||||
if Result then begin
|
||||
if (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then
|
||||
exit;
|
||||
if (nptYList in AParams.FTargets) and (nptYList in ToolTargets) then
|
||||
exit;
|
||||
end;
|
||||
|
||||
if not ((nptCustom in AParams.FTargets) and (nptCustom in ToolTargets))
|
||||
then
|
||||
exit;
|
||||
|
||||
pImg := AParams.FPoint;
|
||||
@ -1156,6 +1169,7 @@ end;
|
||||
constructor TOpenHighLowCloseSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ToolTargets := [nptPoint, nptYList, nptCustom];
|
||||
FOptimizeX := false;
|
||||
FStacked := false;
|
||||
FCandlestickDownBrush := TBrush.Create;
|
||||
@ -1326,9 +1340,14 @@ var
|
||||
begin
|
||||
Result := inherited;
|
||||
|
||||
if Result and ([nptPoint, nptYList] * AParams.FTargets = [nptPoint, nptYList]) then
|
||||
exit;
|
||||
if not (nptCustom in AParams.FTargets) then
|
||||
if Result then begin
|
||||
if (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then
|
||||
exit;
|
||||
if (nptYList in AParams.FTargets) and (nptYList in ToolTargets) then
|
||||
exit;
|
||||
end;
|
||||
if not ((nptCustom in AParams.FTargets) and (nptCustom in ToolTargets))
|
||||
then
|
||||
exit;
|
||||
|
||||
graphClickPt := ParentChart.ImageToGraph(AParams.FPoint);
|
||||
@ -1530,6 +1549,7 @@ end;
|
||||
constructor TFieldSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ToolTargets := [nptPoint, nptXList, nptYList, nptCustom];
|
||||
ListSource.XCount := 2;
|
||||
ListSource.YCount := 2;
|
||||
FArrow := TChartArrow.Create(ParentChart);
|
||||
@ -1691,13 +1711,16 @@ begin
|
||||
dist := MaxInt;
|
||||
xidx := -1;
|
||||
yidx := -1;
|
||||
if (nptPoint in AParams.FTargets) then begin
|
||||
if (nptPoint in AParams.FTargets) and (nptPoint in ToolTargets) then begin
|
||||
dist := AParams.FDistFunc(AParams.FPoint, pt1);
|
||||
xidx := 0;
|
||||
yidx := 0;
|
||||
img := pt1;
|
||||
end;
|
||||
if (AParams.FTargets * [nptXList, nptYList] <> []) then begin
|
||||
|
||||
if (AParams.FTargets * [nptXList, nptYList] <> []) and
|
||||
(ToolTargets * [nptXList, nptYList] <> [])
|
||||
then begin
|
||||
d := AParams.FDistFunc(AParams.FPoint, pt2);
|
||||
if d < dist then begin
|
||||
dist := d;
|
||||
@ -1707,7 +1730,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
// give priority to end points
|
||||
if (dist > AResults.FDist) and (nptCustom in AParams.FTargets) then begin
|
||||
if (dist > AResults.FDist) and
|
||||
(nptCustom in AParams.FTargets) and
|
||||
(nptCustom in ToolTargets)
|
||||
then begin
|
||||
d := PointLineDist(AParams.FPoint, pt1, pt2); // distance of point from line
|
||||
if d < dist then begin
|
||||
dist := d;
|
||||
|
@ -99,6 +99,7 @@ type
|
||||
read GetSeriesColor write SetSeriesColor stored false default clRed;
|
||||
property Source;
|
||||
property Styles;
|
||||
property ToolTargets default [nptPoint, nptYList, nptCustom];
|
||||
property UseReticule;
|
||||
property ZeroLevel: Double
|
||||
read FZeroLevel write SetZeroLevel stored IsZeroLevelStored;
|
||||
@ -170,6 +171,7 @@ type
|
||||
property Source;
|
||||
property Stacked default true;
|
||||
property Styles;
|
||||
property ToolTargets;
|
||||
property UseReticule;
|
||||
property UseZeroLevel: Boolean
|
||||
read FUseZeroLevel write SetUseZeroLevel default false;
|
||||
@ -227,6 +229,7 @@ type
|
||||
property Stacked default false;
|
||||
property Source;
|
||||
property Styles;
|
||||
property ToolTargets;
|
||||
property UseReticule default true;
|
||||
// Events
|
||||
property OnDrawPointer: TSeriesPointerDrawEvent
|
||||
@ -934,6 +937,8 @@ end;
|
||||
constructor TBarSeries.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ToolTargets := [nptPoint, nptYList, nptCustom];
|
||||
|
||||
FBarWidthPercent := DEF_BAR_WIDTH_PERCENT;
|
||||
|
||||
FBarBrush := TBrush.Create;
|
||||
@ -1134,7 +1139,8 @@ begin
|
||||
AResults.FXIndex := 0;
|
||||
AResults.FYIndex := 0;
|
||||
|
||||
if not (nptCustom in AParams.FTargets) then begin
|
||||
if not ((nptCustom in AParams.FTargets) and (nptCustom in ToolTargets))
|
||||
then begin
|
||||
Result := inherited;
|
||||
exit;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user