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