View Issue Details

IDProjectCategoryView StatusLast Update
0034826PackagesTAChartpublic2019-01-07 02:24
ReporterMarcin WiazowskiAssigned Towp 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.0.1 (SVN)Product Build60015 
Target Version2.2Fixed in Version 
Summary0034826: Chart's legend: added lacking functionality to control legend's width
DescriptionWhen chart's legend is located above or below the graph, legend's height can be fully controlled by using the Chart.Legend.FixedItemHeight property - so graph's height is thus also controllable.


On the contrary, for legend located on the right or left of the graph, legend's width can only be partially controlled by using the Chart.Legend.SymbolWidth property - there is no Chart.Legend.FixedItemWidth property, so width is always calculated by using text contents. As a consequence, graph's width is not controllable.


This may be a problem especially when series are dynamically made visible or hidden - in this case, they are also added to or removed from the legend, so graph's width changes (please see the animation attached).


Since I need to avoid this problem in my application, I created a simple patch, that adds the lacking Chart.Legend.FixedItemWidth property. Implementation is trivial, since it's same as for (already existing) FixedItemHeight functionality; you may wish to add the patch to TAChart.


Kind regards
TagsNo tags attached.
Fixed in Revision60022
LazTarget2.2
WidgetsetWin32/Win64
Attached Files
  • Animation.gif (23,996 bytes)
    Animation.gif (23,996 bytes)
  • Reproduce.zip (3,580 bytes)
  • patch.diff (2,397 bytes)
    Index: talegend.pas
    ===================================================================
    --- talegend.pas	(revision 60015)
    +++ talegend.pas	(working copy)
    @@ -163,6 +163,7 @@
         FAlignment: TLegendAlignment;
         FBackgroundBrush: TChartLegendBrush;
         FColumnCount: TLegendColumnCount;
    +    FFixedItemWidth: Cardinal;
         FFixedItemHeight: Cardinal;
         FFont: TFont;
         FFrame: TChartPen;
    @@ -187,6 +188,7 @@
         procedure SetAlignment(AValue: TLegendAlignment);
         procedure SetBackgroundBrush(AValue: TChartLegendBrush);
         procedure SetColumnCount(AValue: TLegendColumnCount);
    +    procedure SetFixedItemWidth(AValue: Cardinal);
         procedure SetFixedItemHeight(AValue: Cardinal);
         procedure SetFont(AValue: TFont);
         procedure SetFrame(AValue: TChartPen);
    @@ -222,6 +224,8 @@
           read FBackgroundBrush write SetBackgroundBrush;
         property ColumnCount: TLegendColumnCount
           read FColumnCount write SetColumnCount default 1;
    +    property FixedItemWidth: Cardinal
    +      read FFixedItemWidth write SetFixedItemWidth default 0;
         property FixedItemHeight: Cardinal
           read FFixedItemHeight write SetFixedItemHeight default 0;
         property Font: TFont read FFont write SetFont;
    @@ -537,6 +541,7 @@
           Self.FAlignment := Alignment;
           Self.FBackgroundBrush.Assign(BackgroundBrush);
           Self.FColumnCount := ColumnCount;
    +      Self.FFixedItemWidth := FixedItemWidth;
           Self.FFixedItemHeight := FixedItemHeight;
           Self.FFont.Assign(Font);
           Self.FFrame.Assign(Frame);
    @@ -693,6 +698,7 @@
       li: TLegendItem;
     begin
       Result := Point(0, 0);
    +  if (FixedItemWidth <= 0) or (FixedItemHeight <= 0) then
       for li in AItems do begin
         li.UpdateFont(ADrawer, prevFont);
         if li.Text = '' then
    @@ -703,6 +709,8 @@
           p.X += ADrawer.Scale(SYMBOL_TEXT_SPACING + SymbolWidth);
         Result := MaxPoint(p, Result);
       end;
    +  if FixedItemWidth > 0 then
    +    Result.X := ADrawer.Scale(FixedItemWidth);
       if FixedItemHeight > 0 then
         Result.Y := ADrawer.Scale(FixedItemHeight);
     end;
    @@ -786,6 +794,13 @@
       StyleChanged(Self);
     end;
     
    +procedure TChartLegend.SetFixedItemWidth(AValue: Cardinal);
    +begin
    +  if FFixedItemWidth = AValue then exit;
    +  FFixedItemWidth := AValue;
    +  StyleChanged(Self);
    +end;
    +
     procedure TChartLegend.SetFixedItemHeight(AValue: Cardinal);
     begin
       if FFixedItemHeight = AValue then exit;
    
    patch.diff (2,397 bytes)

Activities

Marcin Wiazowski

2019-01-06 20:25

reporter  

Animation.gif (23,996 bytes)
Animation.gif (23,996 bytes)

Marcin Wiazowski

2019-01-06 20:26

reporter  

Reproduce.zip (3,580 bytes)

Marcin Wiazowski

2019-01-06 20:26

reporter  

patch.diff (2,397 bytes)
Index: talegend.pas
===================================================================
--- talegend.pas	(revision 60015)
+++ talegend.pas	(working copy)
@@ -163,6 +163,7 @@
     FAlignment: TLegendAlignment;
     FBackgroundBrush: TChartLegendBrush;
     FColumnCount: TLegendColumnCount;
+    FFixedItemWidth: Cardinal;
     FFixedItemHeight: Cardinal;
     FFont: TFont;
     FFrame: TChartPen;
@@ -187,6 +188,7 @@
     procedure SetAlignment(AValue: TLegendAlignment);
     procedure SetBackgroundBrush(AValue: TChartLegendBrush);
     procedure SetColumnCount(AValue: TLegendColumnCount);
+    procedure SetFixedItemWidth(AValue: Cardinal);
     procedure SetFixedItemHeight(AValue: Cardinal);
     procedure SetFont(AValue: TFont);
     procedure SetFrame(AValue: TChartPen);
@@ -222,6 +224,8 @@
       read FBackgroundBrush write SetBackgroundBrush;
     property ColumnCount: TLegendColumnCount
       read FColumnCount write SetColumnCount default 1;
+    property FixedItemWidth: Cardinal
+      read FFixedItemWidth write SetFixedItemWidth default 0;
     property FixedItemHeight: Cardinal
       read FFixedItemHeight write SetFixedItemHeight default 0;
     property Font: TFont read FFont write SetFont;
@@ -537,6 +541,7 @@
       Self.FAlignment := Alignment;
       Self.FBackgroundBrush.Assign(BackgroundBrush);
       Self.FColumnCount := ColumnCount;
+      Self.FFixedItemWidth := FixedItemWidth;
       Self.FFixedItemHeight := FixedItemHeight;
       Self.FFont.Assign(Font);
       Self.FFrame.Assign(Frame);
@@ -693,6 +698,7 @@
   li: TLegendItem;
 begin
   Result := Point(0, 0);
+  if (FixedItemWidth <= 0) or (FixedItemHeight <= 0) then
   for li in AItems do begin
     li.UpdateFont(ADrawer, prevFont);
     if li.Text = '' then
@@ -703,6 +709,8 @@
       p.X += ADrawer.Scale(SYMBOL_TEXT_SPACING + SymbolWidth);
     Result := MaxPoint(p, Result);
   end;
+  if FixedItemWidth > 0 then
+    Result.X := ADrawer.Scale(FixedItemWidth);
   if FixedItemHeight > 0 then
     Result.Y := ADrawer.Scale(FixedItemHeight);
 end;
@@ -786,6 +794,13 @@
   StyleChanged(Self);
 end;
 
+procedure TChartLegend.SetFixedItemWidth(AValue: Cardinal);
+begin
+  if FFixedItemWidth = AValue then exit;
+  FFixedItemWidth := AValue;
+  StyleChanged(Self);
+end;
+
 procedure TChartLegend.SetFixedItemHeight(AValue: Cardinal);
 begin
   if FFixedItemHeight = AValue then exit;
patch.diff (2,397 bytes)

wp

2019-01-06 23:33

developer   ~0113226

Applied. Thank you. Please test and close if OK.

Marcin Wiazowski

2019-01-07 02:24

reporter   ~0113229

Seems to be OK. Thanks!

Issue History

Date Modified Username Field Change
2019-01-06 20:25 Marcin Wiazowski New Issue
2019-01-06 20:25 Marcin Wiazowski Status new => assigned
2019-01-06 20:25 Marcin Wiazowski Assigned To => Alexander S. Klenin
2019-01-06 20:25 Marcin Wiazowski File Added: Animation.gif
2019-01-06 20:26 Marcin Wiazowski File Added: Reproduce.zip
2019-01-06 20:26 Marcin Wiazowski File Added: patch.diff
2019-01-06 22:34 wp Assigned To Alexander S. Klenin => wp
2019-01-06 23:33 wp Fixed in Revision => 60022
2019-01-06 23:33 wp LazTarget => 2.2
2019-01-06 23:33 wp Note Added: 0113226
2019-01-06 23:33 wp Status assigned => resolved
2019-01-06 23:33 wp Resolution open => fixed
2019-01-06 23:33 wp Target Version => 2.2
2019-01-07 02:24 Marcin Wiazowski Note Added: 0113229
2019-01-07 02:24 Marcin Wiazowski Status resolved => closed