mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 07:39:22 +02:00
TAChart: Add Legend.Format property, implement it for single item per series multiplicity
git-svn-id: trunk@34009 -
This commit is contained in:
parent
924256986a
commit
38f0b9b911
@ -76,6 +76,7 @@ type
|
|||||||
|
|
||||||
strict protected
|
strict protected
|
||||||
function GetIndex: Integer; override;
|
function GetIndex: Integer; override;
|
||||||
|
function LegendTextSingle: String;
|
||||||
procedure SetIndex(AValue: Integer); override;
|
procedure SetIndex(AValue: Integer); override;
|
||||||
function TitleIsStored: Boolean; virtual;
|
function TitleIsStored: Boolean; virtual;
|
||||||
|
|
||||||
@ -353,7 +354,7 @@ begin
|
|||||||
oldCount := AItems.Count;
|
oldCount := AItems.Count;
|
||||||
if Assigned(Legend.OnDraw) then
|
if Assigned(Legend.OnDraw) then
|
||||||
for i := 0 to Legend.UserItemsCount - 1 do
|
for i := 0 to Legend.UserItemsCount - 1 do
|
||||||
AItems.Add(TLegendItemUserDrawn.Create(i, Legend.OnDraw, Title))
|
AItems.Add(TLegendItemUserDrawn.Create(i, Legend.OnDraw, LegendTextSingle))
|
||||||
else
|
else
|
||||||
GetLegendItems(AItems);
|
GetLegendItems(AItems);
|
||||||
for i := oldCount to AItems.Count - 1 do begin
|
for i := oldCount to AItems.Count - 1 do begin
|
||||||
@ -428,6 +429,14 @@ begin
|
|||||||
(AxisIndexY >= 0) and not FChart.AxisList[AxisIndexY].IsVertical;
|
(AxisIndexY >= 0) and not FChart.AxisList[AxisIndexY].IsVertical;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomChartSeries.LegendTextSingle: String;
|
||||||
|
begin
|
||||||
|
if Legend.Format = '' then
|
||||||
|
Result := Title
|
||||||
|
else
|
||||||
|
Result := Format(Legend.Format, [Title, Index]);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomChartSeries.ReadState(Reader: TReader);
|
procedure TCustomChartSeries.ReadState(Reader: TReader);
|
||||||
begin
|
begin
|
||||||
inherited ReadState(Reader);
|
inherited ReadState(Reader);
|
||||||
@ -918,7 +927,7 @@ var
|
|||||||
begin
|
begin
|
||||||
case Legend.Multiplicity of
|
case Legend.Multiplicity of
|
||||||
lmSingle:
|
lmSingle:
|
||||||
AItems.Add(TLegendItemBrushRect.Create(ABrush, Title));
|
AItems.Add(TLegendItemBrushRect.Create(ABrush, LegendTextSingle));
|
||||||
lmPoint:
|
lmPoint:
|
||||||
for i := 0 to Count - 1 do begin
|
for i := 0 to Count - 1 do begin
|
||||||
li := TLegendItemBrushRect.Create(ABrush, FormattedMark(i));
|
li := TLegendItemBrushRect.Create(ABrush, FormattedMark(i));
|
||||||
|
@ -677,7 +677,7 @@ end;
|
|||||||
|
|
||||||
procedure TFuncSeries.GetLegendItems(AItems: TChartLegendItems);
|
procedure TFuncSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
begin
|
begin
|
||||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFuncSeries.GetNearestPoint(
|
function TFuncSeries.GetNearestPoint(
|
||||||
@ -828,7 +828,7 @@ end;
|
|||||||
|
|
||||||
procedure TBSplineSeries.GetLegendItems(AItems: TChartLegendItems);
|
procedure TBSplineSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
begin
|
begin
|
||||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBSplineSeries.SetDegree(AValue: TSplineDegree);
|
procedure TBSplineSeries.SetDegree(AValue: TSplineDegree);
|
||||||
@ -973,7 +973,7 @@ end;
|
|||||||
|
|
||||||
procedure TCubicSplineSeries.GetLegendItems(AItems: TChartLegendItems);
|
procedure TCubicSplineSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
begin
|
begin
|
||||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCubicSplineSeries.GetNearestPoint(
|
function TCubicSplineSeries.GetNearestPoint(
|
||||||
@ -1496,7 +1496,7 @@ var
|
|||||||
li: TLegendItemBrushRect;
|
li: TLegendItemBrushRect;
|
||||||
begin
|
begin
|
||||||
case Legend.Multiplicity of
|
case Legend.Multiplicity of
|
||||||
lmSingle: AItems.Add(TLegendItemBrushRect.Create(Brush, Title));
|
lmSingle: AItems.Add(TLegendItemBrushRect.Create(Brush, LegendTextSingle));
|
||||||
lmPoint:
|
lmPoint:
|
||||||
if ColorSource <> nil then begin
|
if ColorSource <> nil then begin
|
||||||
prev := 0.0;
|
prev := 0.0;
|
||||||
|
@ -70,7 +70,7 @@ type
|
|||||||
{ TLegendItemUserDrawn }
|
{ TLegendItemUserDrawn }
|
||||||
|
|
||||||
TLegendItemUserDrawn = class(TLegendItem)
|
TLegendItemUserDrawn = class(TLegendItem)
|
||||||
private
|
strict private
|
||||||
FIndex: Integer;
|
FIndex: Integer;
|
||||||
FOnDraw: TLegendItemDrawEvent;
|
FOnDraw: TLegendItemDrawEvent;
|
||||||
public
|
public
|
||||||
@ -83,7 +83,7 @@ type
|
|||||||
{ TLegendItemLine }
|
{ TLegendItemLine }
|
||||||
|
|
||||||
TLegendItemLine = class(TLegendItem)
|
TLegendItemLine = class(TLegendItem)
|
||||||
private
|
strict private
|
||||||
FPen: TFPCustomPen;
|
FPen: TFPCustomPen;
|
||||||
public
|
public
|
||||||
constructor Create(APen: TFPCustomPen; const AText: String);
|
constructor Create(APen: TFPCustomPen; const AText: String);
|
||||||
@ -93,7 +93,7 @@ type
|
|||||||
{ TLegendItemLinePointer }
|
{ TLegendItemLinePointer }
|
||||||
|
|
||||||
TLegendItemLinePointer = class(TLegendItemLine)
|
TLegendItemLinePointer = class(TLegendItemLine)
|
||||||
protected
|
strict protected
|
||||||
FPointer: TSeriesPointer;
|
FPointer: TSeriesPointer;
|
||||||
public
|
public
|
||||||
constructor Create(
|
constructor Create(
|
||||||
@ -104,7 +104,7 @@ type
|
|||||||
{ TLegendItemBrushRect }
|
{ TLegendItemBrushRect }
|
||||||
|
|
||||||
TLegendItemBrushRect = class(TLegendItem)
|
TLegendItemBrushRect = class(TLegendItem)
|
||||||
private
|
strict private
|
||||||
FBrush: TFPCustomBrush;
|
FBrush: TFPCustomBrush;
|
||||||
public
|
public
|
||||||
constructor Create(ABrush: TFPCustomBrush; const AText: String);
|
constructor Create(ABrush: TFPCustomBrush; const AText: String);
|
||||||
@ -120,7 +120,7 @@ type
|
|||||||
{ TChartLegendItems }
|
{ TChartLegendItems }
|
||||||
|
|
||||||
TChartLegendItems = class(TObjectList)
|
TChartLegendItems = class(TObjectList)
|
||||||
private
|
strict private
|
||||||
function GetItem(AIndex: Integer): TLegendItem;
|
function GetItem(AIndex: Integer): TLegendItem;
|
||||||
procedure SetItem(AIndex: Integer; AValue: TLegendItem);
|
procedure SetItem(AIndex: Integer; AValue: TLegendItem);
|
||||||
public
|
public
|
||||||
@ -234,13 +234,15 @@ type
|
|||||||
{ TChartSeriesLegend }
|
{ TChartSeriesLegend }
|
||||||
|
|
||||||
TChartSeriesLegend = class(TChartElement)
|
TChartSeriesLegend = class(TChartElement)
|
||||||
private
|
strict private
|
||||||
|
FFormat: String;
|
||||||
FGroupIndex: Integer;
|
FGroupIndex: Integer;
|
||||||
FMultiplicity: TLegendMultiplicity;
|
FMultiplicity: TLegendMultiplicity;
|
||||||
FOnCreate: TLegendItemCreateEvent;
|
FOnCreate: TLegendItemCreateEvent;
|
||||||
FOnDraw: TLegendItemDrawEvent;
|
FOnDraw: TLegendItemDrawEvent;
|
||||||
FOrder: Integer;
|
FOrder: Integer;
|
||||||
FUserItemsCount: Integer;
|
FUserItemsCount: Integer;
|
||||||
|
procedure SetFormat(AValue: String);
|
||||||
procedure SetGroupIndex(AValue: Integer);
|
procedure SetGroupIndex(AValue: Integer);
|
||||||
procedure SetMultiplicity(AValue: TLegendMultiplicity);
|
procedure SetMultiplicity(AValue: TLegendMultiplicity);
|
||||||
procedure SetOnCreate(AValue: TLegendItemCreateEvent);
|
procedure SetOnCreate(AValue: TLegendItemCreateEvent);
|
||||||
@ -254,6 +256,7 @@ type
|
|||||||
procedure InitItem(
|
procedure InitItem(
|
||||||
AItem: TLegendItem; AIndex: Integer; ALegend: TChartLegend);
|
AItem: TLegendItem; AIndex: Integer; ALegend: TChartLegend);
|
||||||
published
|
published
|
||||||
|
property Format: String read FFormat write SetFormat;
|
||||||
property GroupIndex: Integer
|
property GroupIndex: Integer
|
||||||
read FGroupIndex write SetGroupIndex default LEGEND_ITEM_NO_GROUP;
|
read FGroupIndex write SetGroupIndex default LEGEND_ITEM_NO_GROUP;
|
||||||
property Multiplicity: TLegendMultiplicity
|
property Multiplicity: TLegendMultiplicity
|
||||||
@ -763,6 +766,13 @@ begin
|
|||||||
AItem.Order := Order;
|
AItem.Order := Order;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartSeriesLegend.SetFormat(AValue: String);
|
||||||
|
begin
|
||||||
|
if FFormat = AValue then exit;
|
||||||
|
FFormat := AValue;
|
||||||
|
StyleChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartSeriesLegend.SetGroupIndex(AValue: Integer);
|
procedure TChartSeriesLegend.SetGroupIndex(AValue: Integer);
|
||||||
begin
|
begin
|
||||||
if FGroupIndex = AValue then exit;
|
if FGroupIndex = AValue then exit;
|
||||||
|
@ -551,7 +551,7 @@ end;
|
|||||||
|
|
||||||
procedure TOpenHighLowCloseSeries.GetLegendItems(AItems: TChartLegendItems);
|
procedure TOpenHighLowCloseSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
begin
|
begin
|
||||||
AItems.Add(TLegendItemOHLCLine.Create(LinePen, Title));
|
AItems.Add(TLegendItemOHLCLine.Create(LinePen, LegendTextSingle));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TOpenHighLowCloseSeries.GetSeriesColor: TColor;
|
function TOpenHighLowCloseSeries.GetSeriesColor: TColor;
|
||||||
|
@ -261,7 +261,7 @@ var
|
|||||||
begin
|
begin
|
||||||
case Legend.Multiplicity of
|
case Legend.Multiplicity of
|
||||||
lmSingle: begin
|
lmSingle: begin
|
||||||
p := TLegendItemPie.Create(Title);
|
p := TLegendItemPie.Create(LegendTextSingle);
|
||||||
for i := 0 to 2 do
|
for i := 0 to 2 do
|
||||||
p.Colors[i] := SliceColor(i);
|
p.Colors[i] := SliceColor(i);
|
||||||
AItems.Add(p);
|
AItems.Add(p);
|
||||||
|
@ -542,7 +542,7 @@ begin
|
|||||||
p := nil;
|
p := nil;
|
||||||
case Legend.Multiplicity of
|
case Legend.Multiplicity of
|
||||||
lmSingle:
|
lmSingle:
|
||||||
AItems.Add(TLegendItemLinePointer.Create(lp, p, Title));
|
AItems.Add(TLegendItemLinePointer.Create(lp, p, LegendTextSingle));
|
||||||
lmPoint: begin
|
lmPoint: begin
|
||||||
for i := 0 to Count - 1 do begin
|
for i := 0 to Count - 1 do begin
|
||||||
li := TLegendItemLinePointer.Create(lp, p, FormattedMark(i));
|
li := TLegendItemLinePointer.Create(lp, p, FormattedMark(i));
|
||||||
@ -667,7 +667,7 @@ end;
|
|||||||
|
|
||||||
procedure TConstantLine.GetLegendItems(AItems: TChartLegendItems);
|
procedure TConstantLine.GetLegendItems(AItems: TChartLegendItems);
|
||||||
begin
|
begin
|
||||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConstantLine.GetNearestPoint(
|
function TConstantLine.GetNearestPoint(
|
||||||
|
Loading…
Reference in New Issue
Block a user