diff --git a/components/tachart/languages/tachartstrconsts.de.po b/components/tachart/languages/tachartstrconsts.de.po index 5f89f3797c..cc1b84fa85 100644 --- a/components/tachart/languages/tachartstrconsts.de.po +++ b/components/tachart/languages/tachartstrconsts.de.po @@ -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" diff --git a/components/tachart/languages/tachartstrconsts.fi.po b/components/tachart/languages/tachartstrconsts.fi.po index 4614cdbb1b..c479cf6c8d 100644 --- a/components/tachart/languages/tachartstrconsts.fi.po +++ b/components/tachart/languages/tachartstrconsts.fi.po @@ -318,6 +318,10 @@ msgstr "" msgid "Left triangle" msgstr "" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "Lineaarinen" diff --git a/components/tachart/languages/tachartstrconsts.fr.po b/components/tachart/languages/tachartstrconsts.fr.po index 6aac02c37a..959c5eb7b2 100644 --- a/components/tachart/languages/tachartstrconsts.fr.po +++ b/components/tachart/languages/tachartstrconsts.fr.po @@ -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" diff --git a/components/tachart/languages/tachartstrconsts.hu.po b/components/tachart/languages/tachartstrconsts.hu.po index 103740b21f..a19032b1e5 100644 --- a/components/tachart/languages/tachartstrconsts.hu.po +++ b/components/tachart/languages/tachartstrconsts.hu.po @@ -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" diff --git a/components/tachart/languages/tachartstrconsts.lt.po b/components/tachart/languages/tachartstrconsts.lt.po index 0699f88701..e2ecdd01bd 100644 --- a/components/tachart/languages/tachartstrconsts.lt.po +++ b/components/tachart/languages/tachartstrconsts.lt.po @@ -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ė" diff --git a/components/tachart/languages/tachartstrconsts.pl.po b/components/tachart/languages/tachartstrconsts.pl.po index ba88721e18..a99924c84c 100644 --- a/components/tachart/languages/tachartstrconsts.pl.po +++ b/components/tachart/languages/tachartstrconsts.pl.po @@ -328,6 +328,10 @@ msgstr "" msgid "Left triangle" msgstr "" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "Liniowy" diff --git a/components/tachart/languages/tachartstrconsts.pot b/components/tachart/languages/tachartstrconsts.pot index caa4780fdd..b1ca782c26 100644 --- a/components/tachart/languages/tachartstrconsts.pot +++ b/components/tachart/languages/tachartstrconsts.pot @@ -318,6 +318,10 @@ msgstr "" msgid "Left triangle" msgstr "" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "" diff --git a/components/tachart/languages/tachartstrconsts.pt_BR.po b/components/tachart/languages/tachartstrconsts.pt_BR.po index 227dfbf730..fe3b75d762 100644 --- a/components/tachart/languages/tachartstrconsts.pt_BR.po +++ b/components/tachart/languages/tachartstrconsts.pt_BR.po @@ -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" diff --git a/components/tachart/languages/tachartstrconsts.ru.po b/components/tachart/languages/tachartstrconsts.ru.po index b5c24f49bd..d8c75d9e10 100644 --- a/components/tachart/languages/tachartstrconsts.ru.po +++ b/components/tachart/languages/tachartstrconsts.ru.po @@ -328,6 +328,10 @@ msgstr "Скобка слева" msgid "Left triangle" msgstr "Треугольник с вершиной слева" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "Линейный масштаб" diff --git a/components/tachart/languages/tachartstrconsts.se.po b/components/tachart/languages/tachartstrconsts.se.po index bfe63fe76d..2192b0857d 100644 --- a/components/tachart/languages/tachartstrconsts.se.po +++ b/components/tachart/languages/tachartstrconsts.se.po @@ -331,6 +331,10 @@ msgstr "" msgid "Left triangle" msgstr "" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "Linjär" diff --git a/components/tachart/languages/tachartstrconsts.uk.po b/components/tachart/languages/tachartstrconsts.uk.po index 73040ada2c..27dd5127b8 100644 --- a/components/tachart/languages/tachartstrconsts.uk.po +++ b/components/tachart/languages/tachartstrconsts.uk.po @@ -331,6 +331,10 @@ msgstr "Дужка ліворуч" msgid "Left triangle" msgstr "Трикутник з вершиною ліворуч" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "Лінійний масштаб" diff --git a/components/tachart/languages/tachartstrconsts.zh_CN.po b/components/tachart/languages/tachartstrconsts.zh_CN.po index feb447bf94..510d417ed2 100644 --- a/components/tachart/languages/tachartstrconsts.zh_CN.po +++ b/components/tachart/languages/tachartstrconsts.zh_CN.po @@ -329,6 +329,10 @@ msgstr "左括号" msgid "Left triangle" msgstr "左三角形" +#: tachartstrconsts.rslegendclicktool +msgid "Legend click" +msgstr "" + #: tachartstrconsts.rslinear msgid "Linear" msgstr "线性的(Linear)" diff --git a/components/tachart/tachartstrconsts.pas b/components/tachart/tachartstrconsts.pas index 2e9bf62418..3830aa8192 100644 --- a/components/tachart/tachartstrconsts.pas +++ b/components/tachart/tachartstrconsts.pas @@ -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'; diff --git a/components/tachart/talegend.pas b/components/tachart/talegend.pas index f2d4e1a6f8..7433d869eb 100644 --- a/components/tachart/talegend.pas +++ b/components/tachart/talegend.pas @@ -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); diff --git a/components/tachart/tatextelements.pas b/components/tachart/tatextelements.pas index 0799bc197d..c0bde34ada 100644 --- a/components/tachart/tatextelements.pas +++ b/components/tachart/tatextelements.pas @@ -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 diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index 603bff678a..fdf3f608a7 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -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;