TAChart: Initial implementation of TLegendClickTool.

git-svn-id: trunk@60818 -
This commit is contained in:
wp 2019-04-01 22:55:53 +00:00
parent 181ba313a6
commit 43e2ae0cf6
16 changed files with 112 additions and 6 deletions

View File

@ -330,6 +330,10 @@ msgstr "Klammer links"
msgid "Left triangle"
msgstr "Dreieck nach links"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr "Klick auf Legende"
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Linear"

View File

@ -318,6 +318,10 @@ msgstr ""
msgid "Left triangle"
msgstr ""
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Lineaarinen"

View File

@ -328,6 +328,10 @@ msgstr "Parenthèse gauche"
msgid "Left triangle"
msgstr "Triangle à gauche"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Linéaire"

View File

@ -328,6 +328,10 @@ msgstr "Zárójel (bal)"
msgid "Left triangle"
msgstr "Háromszög (balra)"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Lineáris"

View File

@ -329,6 +329,10 @@ msgstr "Kairys skliaustas"
msgid "Left triangle"
msgstr "Trikampis kairėn"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Tiesinė"

View File

@ -328,6 +328,10 @@ msgstr ""
msgid "Left triangle"
msgstr ""
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Liniowy"

View File

@ -318,6 +318,10 @@ msgstr ""
msgid "Left triangle"
msgstr ""
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr ""

View File

@ -328,6 +328,10 @@ msgstr "Colchete esquerdo"
msgid "Left triangle"
msgstr "Triângulo esquerdo"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Linear"

View File

@ -328,6 +328,10 @@ msgstr "Скобка слева"
msgid "Left triangle"
msgstr "Треугольник с вершиной слева"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Линейный масштаб"

View File

@ -331,6 +331,10 @@ msgstr ""
msgid "Left triangle"
msgstr ""
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Linjär"

View File

@ -331,6 +331,10 @@ msgstr "Дужка ліворуч"
msgid "Left triangle"
msgstr "Трикутник з вершиною ліворуч"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "Лінійний масштаб"

View File

@ -329,6 +329,10 @@ msgstr "左括号"
msgid "Left triangle"
msgstr "左三角形"
#: tachartstrconsts.rslegendclicktool
msgid "Legend click"
msgstr ""
#: tachartstrconsts.rslinear
msgid "Linear"
msgstr "线性的(Linear)"

View File

@ -72,6 +72,7 @@ resourcestring
rsDistanceMeasurement = 'Distance measurement';
rsAxisClickTool = 'Axis click';
rsHeaderFooterClickTool = 'Header/footer click';
rsLegendClickTool = 'Legend click';
// Chart sources
rsSourceNotEditable = 'Editable chart source required';

View File

@ -173,6 +173,7 @@ type
FGroupTitles: TStrings;
FInverted: Boolean;
FItemFillOrder: TLegendItemFillOrder;
FLegendRect: TRect;
FMarginX: TChartDistance;
FMarginY: TChartDistance;
FSpacing: TChartDistance;
@ -214,6 +215,7 @@ type
procedure AddGroups(AItems: TChartLegendItems);
procedure Assign(Source: TPersistent); override;
procedure Draw(var AData: TChartLegendDrawingData);
function IsPointInBounds(APoint: TPoint): Boolean;
procedure Prepare(var AData: TChartLegendDrawingData; var AClipRect: TRect);
procedure SortItemsByOrder(AItems: TChartLegendItems);
procedure UpdateBidiMode;
@ -715,6 +717,11 @@ begin
Result.Y := ADrawer.Scale(FixedItemHeight);
end;
function TChartLegend.IsPointInBounds(APoint: TPoint): Boolean;
begin
Result := IsPointInRect(APoint, FLegendRect);
end;
procedure TChartLegend.Prepare(
var AData: TChartLegendDrawingData; var AClipRect: TRect);
var
@ -772,6 +779,7 @@ begin
AClipRect.Bottom -= legendSize.Y + 2 * margY;
end;
AData.FBounds := Bounds(x, y, legendSize.X, legendSize.Y);
FLegendRect := Rect(x, y, x + legendSize.X, y + legendSize.Y);
end;
procedure TChartLegend.SetAlignment(AValue: TLegendAlignment);

View File

@ -151,10 +151,10 @@ type
public
procedure Assign(ASource: TPersistent); override;
procedure Draw(ADrawer: IChartDrawer);
function IsPointInBounds(APoint: TPoint): boolean;
procedure Measure(
ADrawer: IChartDrawer; ADir, ALeft, ARight: Integer; var AY: Integer);
procedure UpdateBidiMode;
property Polygon: TPointArray read FPolygon;
published
property Alignment default taCenter;
property Brush: TBrush read FBrush write SetBrush;
@ -631,6 +631,11 @@ begin
Result := Font;
end;
function TChartTitle.IsPointInBounds(APoint: TPoint): Boolean;
begin
Result := IsPointInPolygon(APoint, FPolygon);
end;
procedure TChartTitle.Measure(ADrawer: IChartDrawer;
ADir, ALeft, ARight: Integer; var AY: Integer);
var

View File

@ -21,7 +21,8 @@ uses
Controls, CustomTimer, GraphMath, Forms, LCLPlatformDef, InterfaceBase,
LCLType, LCLIntf,
// TAChart
TAChartUtils, TADrawUtils, TAChartAxis, TAGraph, TATypes, TATextElements;
TAChartUtils, TADrawUtils, TAChartAxis, TALegend, TAGraph,
TATypes, TATextElements;
type
@ -621,6 +622,21 @@ type
property OnClick: TTitleFootClickEvent read FOnClick write FOnClick;
end;
TLegendClickEvent = procedure (ASender: TChartTool;
ALegend: TChartLegend) of object;
TLegendClickTool = class(TChartTool)
private
FOnClick: TLegendClickEvent;
FLegend: TChartLegend;
public
constructor Create(AOwner: TComponent); override;
procedure MouseDown(APoint: TPoint); override;
procedure MouseUp(APoint: TPoint); override;
published
property OnClick: TLegendClickEvent read FOnClick write FOnClick;
end;
procedure Register;
@ -2077,7 +2093,7 @@ procedure TAxisClickTool.MouseUp(APoint: TPoint);
begin
if FHitTest <> [] then begin
GetHitTestInfo(APoint);
if Assigned(FOnClick) then FOnClick(Self, FAxis, FHitTest);
if Assigned(FOnClick) and (FAxis <> nil) then FOnClick(Self, FAxis, FHitTest);
end;
Deactivate;
Handled;
@ -2095,9 +2111,9 @@ end;
function TTitleFootClickTool.GetHit(APoint: TPoint): Boolean;
begin
FTitle := nil;
if IsPointInPolygon(APoint, FChart.Title.Polygon) then
if FChart.Title.IsPointInBounds(APoint) then
FTitle := FChart.Title
else if IsPointInPolygon(APoint, FChart.Foot.Polygon) then
else if FChart.Foot.IsPointInBounds(APoint) then
FTitle := FChart.Foot;
Result := FTitle <> nil;
end;
@ -2114,11 +2130,38 @@ procedure TTitleFootClickTool.MouseUp(APoint: TPoint);
begin
if IsActive then begin
GetHit(APoint);
if Assigned(FOnClick) then FOnClick(Self, FTitle);
if Assigned(FOnClick) and (FTitle <> nil) then FOnClick(Self, FTitle);
end;
end;
{ TLegendClickTool }
constructor TLegendClickTool.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FIgnoreClipRect := true; // Allow mousedown outside cliprect
end;
procedure TLegendClickTool.MouseDown(APoint: TPoint);
begin
if FChart.Legend.IsPointInBounds(APoint) then begin
Activate;
Handled;
end;
end;
procedure TLegendClickTool.MouseUp(APoint: TPoint);
begin
if IsActive and FChart.Legend.IsPointInBounds(APoint) then begin
FLegend := FChart.Legend;
if Assigned(FOnClick) and (FLegend <> nil) then FOnClick(Self, FLegend);
end else
FLegend := nil;
end;
{ -------- }
procedure SkipObsoleteProperties;
const
PROPORTIONAL_NOTE = 'Obsolete, use TZoomDragTool.RatioLimit=zlrProportional instead';
@ -2143,6 +2186,7 @@ initialization
RegisterChartToolClass(TDataPointCrosshairTool, @rsDataPointCrosshair);
RegisterChartToolClass(TAxisClickTool, @rsAxisClickTool);
RegisterChartToolClass(TTitleFootClickTool, @rsHeaderFooterClickTool);
RegisterChartToolClass(TLegendClickTool, @rsLegendClickTool);
RegisterChartToolClass(TUserDefinedTool, @rsUserDefinedTool);
SkipObsoleteProperties;