2023-10-23 00:03:45 +00:00
|
|
|
unit fpsChartStyles;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, fpsTypes, fpsChart;
|
|
|
|
|
|
|
|
type
|
|
|
|
TsChartStyle = class
|
|
|
|
public
|
|
|
|
procedure ApplyToChart(AChart: TsChart); virtual; abstract;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart); virtual; abstract;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartBackgroundStyle = class(TsChartStyle)
|
|
|
|
private
|
2023-10-23 09:28:05 +00:00
|
|
|
FBackground: TsChartFillRec;
|
|
|
|
FBorder: TsChartLineRec;
|
2023-10-23 00:03:45 +00:00
|
|
|
public
|
|
|
|
procedure ApplyToChart(AChart: TsChart); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart); override;
|
2023-10-23 09:28:05 +00:00
|
|
|
property Background: TsChartFillRec read FBackground;
|
|
|
|
property Border: TsChartLineRec read FBorder;
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartStyleList = class(TFPList)
|
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure Clear;
|
|
|
|
function FindChartBackgroundStyle(AChart: TsChart): Integer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TsChartBackgroundstyle }
|
|
|
|
|
|
|
|
procedure TsChartBackgroundStyle.ApplyToChart(AChart: TsChart);
|
|
|
|
begin
|
2023-10-23 09:28:05 +00:00
|
|
|
AChart.Background.FromRecord(FBackground);
|
|
|
|
AChart.Border.FromRecord(FBorder);
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartBackgroundStyle.ExtractFromChart(AChart: TsChart);
|
|
|
|
begin
|
2023-10-23 09:28:05 +00:00
|
|
|
FBackground := AChart.Background.ToRecord;
|
|
|
|
FBorder := AChart.Border.ToRecord;
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsChartStyleList }
|
|
|
|
|
|
|
|
destructor TsChartStyleList.Destroy;
|
|
|
|
begin
|
|
|
|
Clear;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartStyleList.Clear;
|
|
|
|
var
|
|
|
|
j: Integer;
|
|
|
|
begin
|
|
|
|
for j := 0 to Count-1 do
|
|
|
|
TsChartStyle(Items[j]).Free;
|
|
|
|
inherited Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Searches whether the background style of the specified chart is already in the
|
|
|
|
list. If not, a new style is created and added.
|
|
|
|
Returns the index of the style. }
|
|
|
|
function TsChartStyleList.FindChartBackgroundStyle(AChart: TsChart): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartBackgroundStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
newStyle := TsChartBackgroundStyle.Create;
|
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is TsChartBackgroundStyle) then
|
|
|
|
begin
|
|
|
|
style := TsChartBackgroundStyle(Items[i]);
|
|
|
|
if style.FBackground = newStyle.FBackground then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|