2023-10-23 00:03:45 +00:00
|
|
|
unit fpsChartStyles;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
2023-10-23 18:21:54 +00:00
|
|
|
{$modeswitch advancedrecords}
|
2023-10-23 00:03:45 +00:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, fpsTypes, fpsChart;
|
|
|
|
|
|
|
|
type
|
2023-10-25 17:15:57 +00:00
|
|
|
// Identifiers for what is stored in a style
|
|
|
|
TsChartStyleElement = (
|
|
|
|
ceBackground, ceWall, ceFloor, ceLegend, ceTitle, ceSubTitle, cePlotArea,
|
|
|
|
ceXAxis, ceXAxisCaption, ceXAxisMajorGrid, ceXAxisMinorGrid,
|
|
|
|
ceX2Axis, ceX2AxisCaption, ceX2AxisMajorGrid, ceX2AxisMinorGrid,
|
|
|
|
ceYAxis, ceYAxisCaption, ceYAxisMajorGrid, ceYAxisMinorGrid,
|
|
|
|
ceY2Axis, ceY2AxisCaption, ceY2AxisMajorGrid, ceY2AxisMinorGrid,
|
|
|
|
ceSeries, ceSeriesBorder, ceSeriesFill, ceSeriesLine
|
|
|
|
);
|
2023-10-23 18:21:54 +00:00
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
type
|
2023-10-23 18:21:54 +00:00
|
|
|
TsChartLineRec = record
|
|
|
|
Style: Integer; // index into chart's LineStyle list or predefined clsSolid/clsNoLine
|
|
|
|
Width: Double; // mm
|
|
|
|
Color: TsColor; // in hex: $00bbggrr, r=red, g=green, b=blue
|
|
|
|
Transparency: Double; // in percent
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
|
|
|
function GetChartLine(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer): TsChartLine;
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
class operator = (A, B: TsChartLineRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartFillRec = record
|
|
|
|
Style: TsFillStyle;
|
|
|
|
FgColor: TsColor;
|
|
|
|
BgColor: TsColor;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
|
|
|
function GetChartFill(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer): TsChartFill;
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
class operator = (A, B: TsChartFillRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartFontRec = record
|
|
|
|
FontName: String;
|
|
|
|
Size: Double;
|
|
|
|
Style: TsFontStyles;
|
|
|
|
Color: TsColor;
|
|
|
|
Position: TsFontPosition;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
function GetChartFont(AChart: TsChart; AElement: TsChartStyleElement): TsFont;
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 18:21:54 +00:00
|
|
|
procedure ToFont(AFont: TsFont);
|
|
|
|
class operator = (A, B: TsChartFontRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartAxisRec = record
|
|
|
|
AutomaticMax: Boolean;
|
|
|
|
AutomaticMin: Boolean;
|
|
|
|
AutomaticMajorInterval: Boolean;
|
|
|
|
AutomaticMinorInterval: Boolean;
|
|
|
|
AxisLine: TsChartLineRec;
|
|
|
|
MajorGridLines: TsChartLineRec;
|
|
|
|
MinorGridLines: TsChartLineRec;
|
|
|
|
MajorTickLines: TsChartLineRec;
|
|
|
|
MinorTickLines: TsChartLineRec;
|
|
|
|
Inverted: Boolean;
|
|
|
|
// CaptionFont: TsChartFontRec;
|
|
|
|
LabelFont: TsChartFontRec;
|
|
|
|
LabelFormat: String;
|
|
|
|
LabelRotation: Integer;
|
|
|
|
Logarithmic: Boolean;
|
|
|
|
MajorInterval: Double;
|
|
|
|
MinorInterval: Double;
|
|
|
|
Position: TsChartAxisPosition;
|
|
|
|
// ShowCaption: Boolean;
|
|
|
|
ShowLabels: Boolean;
|
|
|
|
Visible: Boolean;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
function GetChartAxis(AChart: TsChart; AElement: TsChartStyleElement): TsChartAxis;
|
|
|
|
function GetChartLine(AChart: TsChart; AElement: TsChartStyleElement): TsChartLine;
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 18:21:54 +00:00
|
|
|
class operator = (A, B: TsChartAxisRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
TsChartTextRec = record
|
2023-10-23 18:21:54 +00:00
|
|
|
Font: TsChartFontRec;
|
|
|
|
Rotation: Integer;
|
|
|
|
Visible: Boolean;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
class operator = (A, B: TsChartTextRec): Boolean;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-23 22:18:31 +00:00
|
|
|
TsChartLegendRec = record
|
2023-10-26 11:30:36 +00:00
|
|
|
CanOverlapPlotArea: Boolean;
|
2023-10-23 22:18:31 +00:00
|
|
|
Font: TsChartFontRec;
|
|
|
|
Border: TsChartLineRec;
|
|
|
|
Fill: TsChartFillRec;
|
2023-10-26 21:21:51 +00:00
|
|
|
Position: TsChartLegendPosition;
|
2023-10-23 22:18:31 +00:00
|
|
|
Visible: Boolean;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 22:18:31 +00:00
|
|
|
class operator = (A, B: TsChartLegendRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
TsChartPlotAreaRec = record
|
|
|
|
FChart: TsChart;
|
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
class operator = (A, B: TsChartPlotAreaRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsChartSeriesRec = record
|
|
|
|
Line: TsChartLineRec;
|
|
|
|
Fill: TsChartFillRec;
|
|
|
|
Border: TsChartFillRec;
|
|
|
|
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
|
|
|
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement; AIndex: Integer);
|
|
|
|
class operator = (A, B: TsChartSeriesRec): Boolean;
|
|
|
|
end;
|
|
|
|
|
2023-10-23 18:21:54 +00:00
|
|
|
{----------------------------------------------------------------------------}
|
2023-10-23 10:58:15 +00:00
|
|
|
|
2023-10-23 00:03:45 +00:00
|
|
|
TsChartStyle = class
|
2023-10-25 17:15:57 +00:00
|
|
|
private
|
2023-10-26 11:07:05 +00:00
|
|
|
FName: String;
|
2023-10-25 17:15:57 +00:00
|
|
|
FElement: TsChartStyleElement;
|
2023-10-23 00:03:45 +00:00
|
|
|
public
|
2023-10-25 17:15:57 +00:00
|
|
|
constructor Create(AElement: TsChartStyleElement); virtual;
|
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); virtual; abstract;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); virtual; abstract;
|
|
|
|
property Element: TsChartStyleElement read FElement;
|
2023-10-26 11:07:05 +00:00
|
|
|
property Name: String read FName;
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
TsChartStyleClass = class of TsChartStyle;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Background = class(TsChartStyle)
|
2023-10-23 00:03:45 +00:00
|
|
|
private
|
2023-10-23 09:28:05 +00:00
|
|
|
FBackground: TsChartFillRec;
|
|
|
|
FBorder: TsChartLineRec;
|
2023-10-23 00:03:45 +00:00
|
|
|
public
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); 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;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Line = class(TsChartStyle)
|
2023-10-25 17:15:57 +00:00
|
|
|
private
|
|
|
|
FLine: TsChartLineRec;
|
|
|
|
public
|
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
property Line: TsChartLineRec read FLine;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Axis = class(TsChartStyle)
|
2023-10-23 18:21:54 +00:00
|
|
|
private
|
|
|
|
FAxis: TsChartAxisRec;
|
|
|
|
public
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
2023-10-23 18:21:54 +00:00
|
|
|
property Axis: TsChartAxisRec read FAxis write FAxis;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Caption = class(TsChartStyle)
|
2023-10-23 18:21:54 +00:00
|
|
|
private
|
2023-10-25 17:15:57 +00:00
|
|
|
FCaption: TsChartTextRec;
|
2023-10-23 18:21:54 +00:00
|
|
|
public
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
property Caption: TsChartTextRec read FCaption write FCaption;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Legend = class(TsChartStyle)
|
2023-10-23 22:18:31 +00:00
|
|
|
private
|
|
|
|
FLegend: TsChartLegendRec;
|
|
|
|
public
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
2023-10-23 22:18:31 +00:00
|
|
|
property Legend: TsChartLegendRec read FLegend write FLegend;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_PlotArea = class(TsChartStyle)
|
2023-10-25 17:15:57 +00:00
|
|
|
private
|
|
|
|
FPlotArea: TsChartPlotAreaRec;
|
|
|
|
public
|
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
TsChartStyle_Series = class(TsChartStyle)
|
2023-10-25 17:15:57 +00:00
|
|
|
private
|
|
|
|
// for all series types
|
|
|
|
FLine: TsChartLineRec;
|
|
|
|
FFill: TsChartFillRec;
|
|
|
|
FBorder: TsChartLineRec;
|
|
|
|
// for TsLineSeries
|
|
|
|
FSymbol: TsChartSeriesSymbol;
|
|
|
|
FSymbolHeight: Double; // in mm
|
|
|
|
FSymbolWidth: Double; // in mm
|
|
|
|
FShowSymbols: Boolean;
|
|
|
|
public
|
|
|
|
procedure ApplyToChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
procedure ExtractFromChart(AChart: TsChart; AIndex: Integer); override;
|
|
|
|
property Line: TsChartLineRec read FLine write FLine; // lineseries lines
|
|
|
|
property Fill: TsChartFillRec read FFill write FFill; // symbol fill, bar fill, area border
|
|
|
|
property Border: TsChartLineRec read FBorder write FBorder; // symbol border, bar border, area border
|
|
|
|
// for line series only
|
|
|
|
property ShowSymbols: Boolean read FShowSymbols write FShowSymbols;
|
|
|
|
property Symbol: TsChartSeriesSymbol read FSymbol write FSymbol;
|
|
|
|
property SymbolHeight: Double read FSymbolHeight write FSymbolHeight;
|
|
|
|
property SymbolWidth: Double read FSymbolWidth write FSymbolWidth;
|
|
|
|
end;
|
|
|
|
|
2023-10-23 18:21:54 +00:00
|
|
|
{ ---------------------------------------------------------------------------}
|
|
|
|
|
2023-10-23 00:03:45 +00:00
|
|
|
TsChartStyleList = class(TFPList)
|
2023-10-23 10:58:15 +00:00
|
|
|
protected
|
|
|
|
|
2023-10-23 00:03:45 +00:00
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
2023-10-26 11:07:05 +00:00
|
|
|
function AddChartStyle(AName: String; AChart: TsChart;
|
|
|
|
AStyleClass: TsChartStyleClass; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer = -1): Integer;
|
2023-10-23 00:03:45 +00:00
|
|
|
procedure Clear;
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure Delete(AIndex: Integer);
|
2023-10-26 11:07:05 +00:00
|
|
|
function FindStyleIndexByName(const AName: String): Integer;
|
|
|
|
{
|
2023-10-25 17:15:57 +00:00
|
|
|
function FindChartStyle(AChart: TsChart; AStyleClass: TsChartStyleClass;
|
|
|
|
AElement: TsChartStyleElement; AIndex: Integer = -1): Integer;
|
2023-10-26 11:07:05 +00:00
|
|
|
}
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2023-10-23 18:21:54 +00:00
|
|
|
{==============================================================================}
|
|
|
|
{ Style records }
|
2023-10-25 17:15:57 +00:00
|
|
|
{ Copies of the chart properties to simplify handling in the style. }
|
2023-10-23 18:21:54 +00:00
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
{ TsFontRec }
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartFontRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
var
|
|
|
|
fnt: TsFont;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
fnt := GetChartFont(AChart, AElement);
|
|
|
|
FontName := fnt.FontName;
|
|
|
|
Size := fnt.Size;
|
|
|
|
Style := fnt.Style;
|
|
|
|
Color := fnt.Color;
|
|
|
|
Position := fnt.Position;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsChartFontRec.GetChartFont(AChart: TsChart; AElement: TsChartStyleElement): TsFont;
|
|
|
|
begin
|
|
|
|
case AElement of
|
|
|
|
ceXAxis: Result := AChart.XAxis.LabelFont;
|
|
|
|
ceYAxis: Result := AChart.YAxis.LabelFont;
|
|
|
|
ceX2Axis: Result := AChart.X2Axis.LabelFont;
|
|
|
|
ceY2Axis: Result := AChart.Y2Axis.LabelFont;
|
|
|
|
ceXAxisCaption: Result := AChart.XAxis.CaptionFont;
|
|
|
|
ceYAxisCaption: Result := AChart.YAxis.CaptionFont;
|
|
|
|
ceX2AxisCaption: Result := AChart.X2Axis.CaptionFont;
|
|
|
|
ceY2AxisCaption: Result := AChart.Y2Axis.CaptionFont;
|
|
|
|
ceTitle: Result := AChart.Title.Font;
|
|
|
|
ceSubtitle: Result := AChart.Subtitle.Font;
|
|
|
|
ceLegend: Result := AChart.Legend.Font;
|
|
|
|
else
|
|
|
|
raise Exception.Create('[TsChartFontRec] Font not supported.');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartFontRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
var
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
fnt := GetChartFont(AChart, AElement);
|
|
|
|
fnt.FontName := FontName;
|
|
|
|
fnt.Size := Size;
|
|
|
|
fnt.Style := Style;
|
|
|
|
fnt.Color := Color;
|
|
|
|
fnt.Position := Position;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartFontRec.ToFont(AFont: TsFont);
|
|
|
|
begin
|
|
|
|
AFont.FontName := FontName;
|
|
|
|
AFont.Size := Size;
|
|
|
|
AFont.Style := Style;
|
|
|
|
AFont.Color := Color;
|
|
|
|
AFont.Position := Position;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartFontRec.= (A, B: TsChartFontRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (A.FontName = B.FontName) and (A.Size = B.Size) and
|
|
|
|
(A.Style = B.Style) and (A.Color = B.Color) and
|
|
|
|
(A.Position = B.Position);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsChartLineRec }
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartLineRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer);
|
|
|
|
var
|
|
|
|
L: TsChartLine;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
L := GetChartLine(AChart, AElement, AIndex);
|
|
|
|
Style := L.Style;
|
|
|
|
Width := L.Width;
|
|
|
|
Color := L.Color;
|
|
|
|
Transparency := L.Transparency;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
function TsChartLineRec.GetChartLine(AChart: TsChart;
|
|
|
|
AElement: TsChartStyleElement; AIndex: Integer): TsChartline;
|
|
|
|
begin
|
|
|
|
case AElement of
|
|
|
|
ceBackground: Result := AChart.Border;
|
|
|
|
ceWall: Result := AChart.PlotArea.Border;
|
|
|
|
ceFloor: Result := AChart.Floor.Border;
|
|
|
|
ceTitle: Result := AChart.Title.Border;
|
|
|
|
ceSubTitle: Result := AChart.SubTitle.Border;
|
|
|
|
ceLegend: Result := AChart.Legend.Border;
|
|
|
|
ceXAxis: Result := AChart.XAxis.AxisLine;
|
|
|
|
ceYAxis: Result := AChart.YAxis.AxisLine;
|
|
|
|
ceX2Axis: Result := AChart.X2Axis.AxisLine;
|
|
|
|
ceY2Axis: Result := AChart.Y2Axis.AxisLine;
|
|
|
|
ceXAxisMajorGrid: Result := AChart.XAxis.MajorGridLines;
|
|
|
|
ceXAxisMinorGrid: Result := AChart.XAxis.MinorGridLines;
|
|
|
|
ceYAxisMajorGrid: Result := AChart.YAxis.MajorGridLines;
|
|
|
|
ceYAxisMinorGrid: Result := AChart.YAxis.MinorGridLines;
|
|
|
|
ceX2AxisMajorGrid: Result := AChart.X2Axis.MajorGridLines;
|
|
|
|
ceX2AxisMinorGrid: Result := AChart.X2Axis.MinorGridLines;
|
|
|
|
ceY2AxisMajorGrid: Result := AChart.Y2Axis.MajorGridLines;
|
|
|
|
ceY2AxisMinorGrid: Result := AChart.Y2Axis.MinorGridLines;
|
|
|
|
ceSeriesBorder: Result := AChart.Series[AIndex].Border;
|
|
|
|
ceSeriesLine: Result := AChart.Series[AIndex].Line;
|
|
|
|
else
|
|
|
|
raise Exception.Create('[TsChartLineRec.GetChartLine] Line not supported.');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartLineRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer);
|
|
|
|
var
|
|
|
|
L: TsChartLine;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
L := GetChartLine(AChart, AElement, AIndex);
|
|
|
|
L.Style := Style;
|
|
|
|
L.Width := Width;
|
|
|
|
L.Color := Color;
|
|
|
|
L.Transparency := Transparency;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartLineRec.= (A, B: TsChartLineRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (A.Style = B.Style) and (A.Width = B.Width) and
|
|
|
|
(A.Color = B.Color) and (A.Transparency = B.Transparency);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsChartFillRec }
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartFillRec.FromChart(AChart: TsChart;
|
|
|
|
AElement: TsChartStyleElement; AIndex: Integer);
|
|
|
|
var
|
|
|
|
f: TsChartFill;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
f := GetChartFill(AChart, AElement, AIndex);
|
|
|
|
Style := f.Style;
|
|
|
|
FgColor := f.FgColor;
|
|
|
|
BgColor := f.BgColor;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
function TsChartFillRec.GetChartFill(AChart: TsChart;
|
|
|
|
AElement: TsChartStyleElement; AIndex: Integer): TsChartFill;
|
|
|
|
begin
|
|
|
|
case AElement of
|
|
|
|
ceBackground: Result := AChart.Background;
|
|
|
|
ceWall: Result := AChart.PlotArea.Background;
|
|
|
|
ceFloor: Result := AChart.Floor.Background;
|
|
|
|
ceLegend: Result := AChart.Legend.Background;
|
|
|
|
ceTitle: Result := AChart.Title.Background;
|
|
|
|
ceSubTitle: Result := AChart.SubTitle.Background;
|
|
|
|
ceSeriesFill: Result := AChart.Series[AIndex].Fill;
|
|
|
|
else
|
|
|
|
raise Exception.Create('[TsChartFillRec.GetChartFill] Fill not supported.');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartFillRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer);
|
|
|
|
var
|
|
|
|
f: TsChartFill;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
f := GetChartFill(AChart, AElement, AIndex);
|
|
|
|
f.Style := Style;
|
|
|
|
f.FgColor := FgColor;
|
|
|
|
f.BgColor := BgColor;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartFillRec.= (A, B: TsChartFillRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (A.Style = B.Style) and (A.FgColor = B.FgColor) and (A.BgColor = B.BgColor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsChartAxisRec }
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartAxisRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
var
|
|
|
|
axis: TsChartAxis;
|
|
|
|
begin
|
|
|
|
axis := GetChartAxis(AChart, AElement);
|
|
|
|
AutomaticMax := axis.AutomaticMax;
|
|
|
|
AutomaticMin := axis.AutomaticMin;
|
|
|
|
AutomaticMajorInterval := axis.AutomaticMajorInterval;
|
|
|
|
AutomaticMinorInterval := axis.AutomaticMinorSteps;
|
|
|
|
//AxisLine.FromChart(axis.AxisLine);
|
|
|
|
//MajorGridLines.FromChart(axis.MajorGridLines);
|
|
|
|
//MinorGridLines.FromChart(axis.MinorGridLines);
|
|
|
|
//MajorTickLines.FromChart(axis.MajorTickLines);
|
|
|
|
//MinorTickLines.FromChart(axis.MinorTickLines);
|
|
|
|
Inverted := axis.Inverted;
|
2023-10-23 18:21:54 +00:00
|
|
|
// CaptionFont.FromFont(Axis.Font);
|
2023-10-25 17:15:57 +00:00
|
|
|
//LabelFont.FromFont(axis.LabelFont);
|
|
|
|
LabelFormat := axis.LabelFormat;
|
|
|
|
LabelRotation := axis.LabelRotation;
|
|
|
|
Logarithmic := axis.Logarithmic;
|
|
|
|
MajorInterval := axis.MajorInterval;
|
|
|
|
MinorInterval := axis.MinorSteps;
|
|
|
|
Position := axis.Position;
|
2023-10-23 18:21:54 +00:00
|
|
|
// ShowCaption := Axis.ShowCaption;
|
2023-10-25 17:15:57 +00:00
|
|
|
ShowLabels := axis.ShowLabels;
|
|
|
|
Visible := axis.Visible;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsChartAxisRec.GetChartAxis(AChart: TsChart; AElement: TsChartStyleElement): TsChartAxis;
|
|
|
|
begin
|
|
|
|
case AElement of
|
|
|
|
ceXAxis, ceXAxisCaption, ceXAxisMajorGrid, ceXAxisMinorGrid:
|
|
|
|
Result := AChart.XAxis;
|
|
|
|
ceYAxis, ceYAxisCaption, ceYAxisMajorGrid, ceYAxisMinorGrid:
|
|
|
|
Result := AChart.YAxis;
|
|
|
|
ceX2Axis, ceX2AxisCaption, ceX2AxisMajorGrid, ceX2AxisMinorGrid:
|
|
|
|
Result := AChart.X2Axis;
|
|
|
|
ceY2Axis, ceY2AxisCaption, ceY2AxisMajorGrid, ceY2AxisMinorGrid:
|
|
|
|
Result := AChart.Y2Axis;
|
|
|
|
else
|
|
|
|
raise Exception.Create('[TsChartAxisRec.GetChartAxis] Element not supported.');
|
|
|
|
end;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
function TsChartAxisRec.GetChartLine(AChart: TsChart; AElement: TsChartStyleElement): TsChartLine;
|
|
|
|
var
|
|
|
|
axis: TsChartAxis;
|
|
|
|
begin
|
|
|
|
axis := GetChartAxis(AChart, AElement);
|
|
|
|
case AElement of
|
|
|
|
ceXAxis, ceX2Axis, ceYAxis, ceY2Axis:
|
|
|
|
Result := axis.AxisLine;
|
|
|
|
ceXAxisMajorGrid, ceX2AxisMajorGrid, ceYAxisMajorGrid, ceY2AxisMajorGrid:
|
|
|
|
Result := axis.MajorGridLines;
|
|
|
|
ceXAxisMinorGrid, ceX2AxisMinorGrid, ceYAxisMinorGrid, ceY2AxisMinorGrid:
|
|
|
|
Result := axis.MinorGridLines;
|
|
|
|
else
|
|
|
|
raise Exception.Create('[TsChartAxisRec.GetChartLine] Element not supported.');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartAxisRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
var
|
|
|
|
axis: TsChartAxis;
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
axis := GetChartAxis(AChart, AElement);
|
|
|
|
axis.AutomaticMax := AutomaticMax;
|
|
|
|
axis.AutomaticMin := AutomaticMin;
|
|
|
|
axis.AutomaticMajorInterval := AutomaticMajorInterval;
|
|
|
|
axis.AutomaticMinorSteps := AutomaticMinorInterval;
|
|
|
|
//AxisLine.ToChart(Axis.AxisLine);
|
|
|
|
//MajorGridLines.ToChart(Axis.MajorGridLines);
|
|
|
|
//MinorGridLines.ToChart(Axis.MinorGridLines);
|
|
|
|
//MajorTickLines.ToChart(Axis.MajorTickLines);
|
|
|
|
//MinorTickLines.ToChart(Axis.MinorTickLines);
|
2023-10-23 18:21:54 +00:00
|
|
|
Axis.Inverted := Inverted;
|
|
|
|
// CaptionFont.ToFont(Axis.Font);
|
2023-10-25 17:15:57 +00:00
|
|
|
//LabelFont.ToFont(Axis.LabelFont);
|
2023-10-23 18:21:54 +00:00
|
|
|
Axis.LabelFormat := LabelFormat;
|
|
|
|
Axis.LabelRotation := LabelRotation;
|
|
|
|
Axis.Logarithmic := Logarithmic;
|
|
|
|
Axis.MajorInterval := MajorInterval;
|
|
|
|
Axis.MinorSteps := MinorInterval;
|
|
|
|
Axis.Position := Position;
|
|
|
|
// Axis.ShowCaption := ShowCaption;
|
|
|
|
Axis.Visible := Visible;
|
|
|
|
Axis.ShowLabels := ShowLabels;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartAxisRec.= (A, B: TsChartAxisRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (A.AutomaticMax = B.AutomaticMax) and (A.AutomaticMin = B.AutomaticMin) and
|
|
|
|
(A.AutomaticMajorInterval = B.AutomaticMajorInterval) and
|
|
|
|
(A.AutomaticMinorInterval = B.AutomaticMinorInterval) and
|
|
|
|
(A.AxisLine = B.AxisLine) and
|
|
|
|
(A.MajorGridLines = B.MajorGridLines) and
|
|
|
|
(A.MinorGridLines = B.MinorGridLines) and
|
|
|
|
(A.MajorTickLines = B.MajorTickLines) and
|
|
|
|
(A.MinorTickLines = B.MinorTickLines) and
|
|
|
|
(A.Inverted = B.Inverted) and
|
|
|
|
// (A.CaptionFont = B.CaptionFont) and
|
|
|
|
(A.LabelFont = B.LabelFont) and
|
|
|
|
(A.LabelFormat = B.LabelFormat) and
|
|
|
|
(A.LabelRotation = B.LabelRotation) and
|
|
|
|
(A.Logarithmic = B.Logarithmic) and
|
|
|
|
(A.MajorInterval = B.MajorInterval) and
|
|
|
|
(A.MinorInterval = B.MinorInterval) and
|
|
|
|
(A.Position = B.Position) and
|
|
|
|
// (A.ShowCaption = B.ShowCaption) and
|
|
|
|
(A.ShowLabels = B.ShowLabels) and
|
|
|
|
(A.Visible = B.Visible);
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
{ TsChartTextRec }
|
2023-10-23 18:21:54 +00:00
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartTextRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
case AElement of
|
|
|
|
ceTitle:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceTitle);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.Title.ShowCaption;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceSubtitle:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceSubTitle);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.Subtitle.ShowCaption;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceXAxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceXAxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.XAxis.ShowCaption;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceYAxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceYAxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.YAxis.ShowCaption;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceX2AxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceX2AxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.X2Axis.ShowCaption;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceY2AxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceY2AxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
Visible := AChart.Y2Axis.ShowCaption;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartTextRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
case AElement of
|
|
|
|
ceTitle:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceTitle);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.Title.ShowCaption := Visible;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceSubtitle:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceSubtitle);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.Subtitle.ShowCaption := Visible;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceXAxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceXAxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.XAxis.ShowCaption := Visible;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceYAxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceYAxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.YAxis.ShowCaption := Visible;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceX2AxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceX2AxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.X2Axis.ShowCaption := Visible;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
ceY2AxisCaption:
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceY2AxisCaption);
|
2023-10-23 18:21:54 +00:00
|
|
|
AChart.Y2Axis.ShowCaption := Visible;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2023-10-23 10:58:15 +00:00
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
class operator TsChartTextRec.= (A, B: TsChartTextRec): Boolean;
|
2023-10-23 10:58:15 +00:00
|
|
|
begin
|
2023-10-23 18:21:54 +00:00
|
|
|
Result := (A.Font = B.Font) and (A.Visible = B.Visible);
|
2023-10-23 10:58:15 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-23 22:18:31 +00:00
|
|
|
{ TsChartLegendRec }
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartLegendRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 22:18:31 +00:00
|
|
|
begin
|
2023-10-26 11:30:36 +00:00
|
|
|
CanOverlapPlotArea := AChart.Legend.CanOverlapPlotArea;
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.FromChart(AChart, ceLegend);
|
|
|
|
Border.FromChart(AChart, ceLegend, 0);
|
|
|
|
Fill.FromChart(AChart, ceLegend, 0);
|
2023-10-23 22:18:31 +00:00
|
|
|
Visible := AChart.Legend.Visible;
|
2023-10-26 21:21:51 +00:00
|
|
|
Position := AChart.Legend.Position;
|
2023-10-23 22:18:31 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartLegendRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
2023-10-23 22:18:31 +00:00
|
|
|
begin
|
2023-10-26 11:30:36 +00:00
|
|
|
AChart.Legend.CanOverlapPlotArea := CanOverlapPlotArea;
|
2023-10-25 17:15:57 +00:00
|
|
|
Font.ToChart(AChart, ceLegend);
|
|
|
|
Border.ToChart(AChart, ceLegend, 0);
|
|
|
|
Fill.ToChart(AChart, ceLegend, 0);
|
2023-10-23 22:18:31 +00:00
|
|
|
AChart.Legend.Visible := Visible;
|
2023-10-26 21:21:51 +00:00
|
|
|
AChart.Legend.Position := Position;
|
2023-10-23 22:18:31 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartLegendRec.= (A, B: TsChartLegendRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (A.Font = B.Font) and (A.Border = B.Border) and (A.Fill = B.Fill) and
|
2023-10-26 21:21:51 +00:00
|
|
|
(A.Visible = B.Visible) and (A.CanOverlapPlotArea = B.CanOverlapPlotArea) and
|
|
|
|
(A.Position = B.Position);
|
2023-10-23 22:18:31 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
{ TsChartPlotAreaRec }
|
|
|
|
procedure TsChartPlotAreaRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
begin
|
|
|
|
FChart := AChart;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSChartPlotAreaRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartPlotAreaRec.= (A, B: TsChartPlotAreaRec): Boolean;
|
|
|
|
begin
|
|
|
|
Result := A.FChart = B.FChart;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsChartSeriesRec }
|
|
|
|
procedure TsChartSeriesRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer);
|
|
|
|
begin
|
|
|
|
Line.FromChart(AChart, AElement, AIndex);
|
|
|
|
Fill.FromChart(AChart, AElement, AIndex);
|
|
|
|
Border.FromChart(AChart, AElement, AIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsChartSeriesRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer);
|
|
|
|
begin
|
|
|
|
Line.ToChart(AChart, ceSeriesLine, AIndex);
|
|
|
|
Fill.ToChart(AChart, ceSeriesFill, AIndex);
|
|
|
|
Border.ToChart(AChart, ceSeriesBorder, AIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class operator TsChartSeriesRec.= (A, B: TsChartSeriesRec): Boolean;
|
|
|
|
begin
|
2023-10-27 20:09:03 +00:00
|
|
|
Result := (A.Line = B.Line) and (A.Fill = B.Fill) and (A.Border = B.Border);
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-23 22:18:31 +00:00
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{ Style classes to be listed in ChartStyleList }
|
|
|
|
{==============================================================================}
|
2023-10-23 18:21:54 +00:00
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
{ TsChartStyle }
|
2023-10-23 00:03:45 +00:00
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
constructor TsChartStyle.Create(AElement: TsChartStyleElement);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2023-10-25 17:15:57 +00:00
|
|
|
FElement := AElement;
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Background }
|
2023-10-25 17:15:57 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Background.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 00:03:45 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
if (FElement in [ceBackground, ceWall, ceFloor]) then
|
|
|
|
begin
|
|
|
|
FBackground.ToChart(AChart, FElement, AIndex);
|
|
|
|
FBorder.ToChart(AChart, FElement, AIndex);
|
|
|
|
end else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartStyle_Background.ApplyToChart] Unknown background style.');
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Background.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
if (FElement in [ceBackground, ceWall, ceFloor]) then
|
|
|
|
begin
|
|
|
|
FBackground.FromChart(AChart, FElement, AIndex);
|
|
|
|
FBorder.FromChart(AChart, FElement, AIndex);
|
|
|
|
end else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartStyle_Background.ExtractFromChart] Unknown background style.');
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Line }
|
2023-10-25 17:15:57 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
ALLOWED_LS = [
|
|
|
|
ceXAxisMajorGrid, ceXAxisMinorGrid, ceX2AxisMajorGrid, ceX2AxisMinorGrid,
|
|
|
|
ceYAxisMajorGrid, ceYAxisMinorGrid, ceY2AxisMajorGrid, ceY2AxisMinorGrid
|
|
|
|
];
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Line.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
if (FElement in ALLOWED_LS) then
|
|
|
|
Line.ToChart(AChart, FElement, AIndex)
|
|
|
|
else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartStyle_Line.ApplytoGrid] Unknown line');
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Line.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
if (FElement in ALLOWED_LS) then
|
|
|
|
Line.FromChart(AChart, FElement, AIndex)
|
|
|
|
else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartStyle_Line.ExtractFromChart] Unknown line');
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Axis }
|
2023-10-23 00:03:45 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Axis.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 00:03:45 +00:00
|
|
|
begin
|
2023-10-26 11:07:05 +00:00
|
|
|
Axis.ToChart(AChart, FElement);
|
|
|
|
Axis.AxisLine.ToChart(AChart, FElement, -1);
|
|
|
|
Axis.LabelFont.ToChart(AChart, FElement);
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Axis.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
2023-10-26 11:07:05 +00:00
|
|
|
Axis.FromChart(AChart, FElement);
|
|
|
|
Axis.AxisLine.FromChart(AChart, FElement, -1);
|
|
|
|
Axis.LabelFont.FromChart(AChart, FElement);
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-23 18:21:54 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Caption }
|
2023-10-25 17:15:57 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
ALLOWED_CAPTIONS = [ceXAxisCaption, ceX2AxisCaption, ceYAxisCaption, ceY2AxisCaption, ceTitle, ceSubTitle];
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Caption.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
if (FElement in ALLOWED_CAPTIONS) then
|
|
|
|
Caption.ToChart(AChart, FElement)
|
|
|
|
else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartstyle_Caption.ApplyToChart] Unknown caption');
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Caption.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
if (FElement in ALLOWED_CAPTIONS) then
|
|
|
|
Caption.FromChart(AChart, FElement)
|
|
|
|
else
|
2023-10-26 11:07:05 +00:00
|
|
|
raise Exception.Create('[TsChartStyle_Caption.ExtractFromChart] Unknown caption');
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Legend }
|
2023-10-23 18:21:54 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Legend.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
FLegend.ToChart(AChart, ceLegend);
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Legend.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 18:21:54 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
FLegend.FromChart(AChart, ceLegend);
|
2023-10-23 18:21:54 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_PlotArea }
|
2023-10-25 17:15:57 +00:00
|
|
|
{ For the moment, this is a dummy style because I don't know how the plotarea
|
|
|
|
parameters are changed in ODS. }
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_PlotArea.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
FPlotArea.ToChart(AChart, cePlotArea);
|
|
|
|
end;
|
2023-10-23 22:18:31 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_PlotArea.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-23 22:18:31 +00:00
|
|
|
begin
|
2023-10-25 17:15:57 +00:00
|
|
|
FPlotArea.FromChart(AChart, cePlotArea);
|
2023-10-23 22:18:31 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ TsChartStyle_Series }
|
2023-10-25 17:15:57 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Series.ApplyToChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
Line.ToChart(AChart, ceSeriesLine, AIndex);
|
|
|
|
Fill.ToChart(AChart, ceSeriesFill, AIndex);
|
|
|
|
Border.ToChart(AChart, ceSeriesBorder, AIndex);
|
|
|
|
|
|
|
|
if (AChart.Series[AIndex] is TsLineSeries) then
|
|
|
|
begin
|
|
|
|
TsLineSeries(AChart.Series[AIndex]).Symbol := FSymbol;
|
|
|
|
TsLineSeries(AChart.Series[AIndex]).SymbolHeight := FSymbolHeight;
|
|
|
|
TsLineSeries(AChart.Series[AIndex]).SymbolWidth := FSymbolWidth;
|
|
|
|
TsLineSeries(AChart.Series[AIndex]).ShowSymbols := FShowSymbols;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
procedure TsChartStyle_Series.ExtractFromChart(AChart: TsChart; AIndex: Integer);
|
2023-10-25 17:15:57 +00:00
|
|
|
begin
|
|
|
|
Line.FromChart(AChart, ceSeriesLine, AIndex);
|
|
|
|
Fill.FromChart(AChart, ceSeriesFill, AIndex);
|
|
|
|
Border.FromChart(AChart, ceSeriesBorder, AIndex);
|
|
|
|
|
|
|
|
if (AChart.Series[AIndex] is TsLineSeries) then
|
|
|
|
begin
|
|
|
|
FSymbol := TsLineSeries(AChart.Series[AIndex]).Symbol;
|
|
|
|
FSymbolHeight := TsLineSeries(AChart.Series[AIndex]).SymbolHeight;
|
|
|
|
FSymbolWidth := TsLineSeries(AChart.Series[AIndex]).SymbolWidth;
|
|
|
|
FShowSymbols := TsLineSeries(AChart.Series[AIndex]).ShowSymbols;
|
|
|
|
end else
|
|
|
|
FShowSymbols := false;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{ TsChartStyleList }
|
|
|
|
{==============================================================================}
|
2023-10-23 00:03:45 +00:00
|
|
|
|
|
|
|
destructor TsChartStyleList.Destroy;
|
|
|
|
begin
|
|
|
|
Clear;
|
|
|
|
inherited;
|
|
|
|
end;
|
2023-10-23 22:18:31 +00:00
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
{ Adds a new style to the style list. The style is created as the given style
|
|
|
|
class. Which piece of chart formatting is included in the style, is determined
|
|
|
|
by the AElement parameter. In case of series styles, the index of the series
|
|
|
|
must be provided as parameter AIndex. }
|
|
|
|
function TsChartStyleList.AddChartStyle(AName: String; AChart: TsChart;
|
|
|
|
AStyleClass: TsChartStyleClass; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer = -1): Integer;
|
|
|
|
var
|
|
|
|
newStyle: TsChartStyle;
|
2023-10-23 10:58:15 +00:00
|
|
|
begin
|
2023-10-26 11:07:05 +00:00
|
|
|
newStyle := AStyleClass.Create(AElement);
|
|
|
|
newStyle.ExtractFromChart(AChart, AIndex);
|
|
|
|
newStyle.FName := AName;
|
|
|
|
Result := Add(newStyle);
|
2023-10-23 10:58:15 +00:00
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
{ Clears the chart style list. Destroys the individual items. }
|
2023-10-23 00:03:45 +00:00
|
|
|
procedure TsChartStyleList.Clear;
|
|
|
|
var
|
|
|
|
j: Integer;
|
|
|
|
begin
|
|
|
|
for j := 0 to Count-1 do
|
|
|
|
TsChartStyle(Items[j]).Free;
|
|
|
|
inherited Clear;
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
procedure TsChartStyleList.Delete(AIndex: Integer);
|
|
|
|
begin
|
|
|
|
TsChartStyle(Items[AIndex]).Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2023-10-26 11:07:05 +00:00
|
|
|
function TsChartStyleList.FindStyleIndexByName(const AName: String): Integer;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if TsChartStyle(Items[i]).Name = AName then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
(*
|
2023-10-25 17:15:57 +00:00
|
|
|
{ Adds a new style to the style list. The style is created as the given style
|
|
|
|
class. Which piece of chart formattting is included in the style, is determined
|
|
|
|
by the AElement parameter. In case of series styles, the index of the series
|
|
|
|
must be provided as parameter AIndex. }
|
|
|
|
function TsChartStyleList.AddChartStyle(AChart: TsChart;
|
|
|
|
AStyleClass: TsChartStyleClass; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer = -1): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
2023-10-26 11:07:05 +00:00
|
|
|
// Result := -1;
|
2023-10-25 17:15:57 +00:00
|
|
|
|
|
|
|
newStyle := AStyleClass.Create(AElement);
|
|
|
|
newStyle.ExtractFromChart(AChart, AIndex);
|
2023-10-26 11:07:05 +00:00
|
|
|
Result := Add(newStyle);
|
|
|
|
newStyle.FStyleID := Result;
|
|
|
|
{
|
2023-10-25 17:15:57 +00:00
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is AStyleClass) then
|
|
|
|
begin
|
|
|
|
style := TsChartStyle(Items[i]);
|
|
|
|
if style.EqualTo(newStyle) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
2023-10-26 11:07:05 +00:00
|
|
|
}
|
2023-10-25 17:15:57 +00:00
|
|
|
end;
|
2023-10-26 11:07:05 +00:00
|
|
|
*)
|
|
|
|
(*
|
2023-10-25 17:15:57 +00:00
|
|
|
{ Finds the index of the style matching the formatting of the given
|
|
|
|
chart element (AElement); in case of series styles the series index must be
|
|
|
|
provided as AIndex.
|
|
|
|
Returns -1 if there is no such style. }
|
|
|
|
function TsChartStyleList.FindChartStyle(AChart: TsChart;
|
|
|
|
AStyleClass: TsChartStyleClass; AElement: TsChartStyleElement;
|
|
|
|
AIndex: Integer = -1): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
|
|
|
|
newStyle := AStyleClass.Create(AElement);
|
|
|
|
try
|
|
|
|
newStyle.ExtractFromChart(AChart, AIndex);
|
|
|
|
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is AStyleClass) then
|
|
|
|
begin
|
|
|
|
style := TsChartStyle(Items[i]);
|
|
|
|
if style.EqualTo(newStyle) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
end;
|
2023-10-26 11:07:05 +00:00
|
|
|
*)
|
2023-10-25 17:15:57 +00:00
|
|
|
(*
|
2023-10-23 18:21:54 +00:00
|
|
|
{ Searches whether the style of the specified axis is already in the
|
|
|
|
list. If not, a new style is created and added.
|
|
|
|
The type of the requested axis must be provided as parameter.
|
|
|
|
Returns the index of the style. }
|
|
|
|
function TsChartStyleList.FindChartAxisStyle(AChart: TsChart;
|
|
|
|
AType: TsChartAxisType): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartAxisStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
newStyle := TsChartAxisStyle.Create(AType);
|
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is TsChartAxisStyle) then
|
|
|
|
begin
|
|
|
|
style := TsChartAxisStyle(Items[i]);
|
|
|
|
if (style.AxisType = AType) and (style.Axis = newStyle.Axis) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
|
2023-10-25 17:15:57 +00:00
|
|
|
{ Searches whether the style of the specified line is already in the
|
|
|
|
list. If not, a new style is created and added.
|
|
|
|
Returns the index of the style. }
|
|
|
|
function TsChartStyleList.FindChartLineStyle(AChart: TsChart): Integer;
|
|
|
|
// AType: TsChartLineType): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartLineStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
newStyle := TsChartLineStyle.Create; //(AType);
|
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
if newStyle.Line.Style = clsNoLine then
|
|
|
|
exit;
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is TsChartLineStyle) then
|
|
|
|
begin
|
|
|
|
style := TsChartLineStyle(Items[i]);
|
|
|
|
if (style.Line = newStyle.Line) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
|
2023-10-23 00:03:45 +00:00
|
|
|
{ Searches whether the background style of the specified chart is already in the
|
|
|
|
list. If not, a new style is created and added.
|
2023-10-23 10:58:15 +00:00
|
|
|
The type of the requested background must be provided as parameter.
|
2023-10-23 00:03:45 +00:00
|
|
|
Returns the index of the style. }
|
2023-10-23 10:58:15 +00:00
|
|
|
function TsChartStyleList.FindChartBackgroundStyle(AChart: TsChart;
|
2023-10-23 18:21:54 +00:00
|
|
|
AType: TsChartBackgroundType): Integer;
|
2023-10-23 00:03:45 +00:00
|
|
|
var
|
|
|
|
newStyle, style: TsChartBackgroundStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
2023-10-23 18:21:54 +00:00
|
|
|
newStyle := TsChartBackgroundStyle.Create(AType);
|
2023-10-23 00:03:45 +00:00
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
2023-10-23 18:21:54 +00:00
|
|
|
if (TsChartStyle(Items[i]) is TsChartBackgroundStyle) then
|
2023-10-23 00:03:45 +00:00
|
|
|
begin
|
2023-10-23 10:58:15 +00:00
|
|
|
style := TsChartBackgroundStyle(Items[i]);
|
2023-10-23 18:21:54 +00:00
|
|
|
if (style.BackgroundType = AType) and (style.Background = newStyle.Background) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Searches whether the style of the specified caption is already in the
|
|
|
|
list. If not, a new style is created and added.
|
|
|
|
The type of the requested axis must be provided as parameter.
|
|
|
|
Returns the index of the style. }
|
|
|
|
function TsChartStyleList.FindChartCaptionStyle(AChart: TsChart;
|
|
|
|
AType: TsChartCaptionType): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartCaptionStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
newStyle := TsChartCaptionStyle.Create(AType);
|
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is TsChartCaptionStyle) then
|
|
|
|
begin
|
|
|
|
style := TsChartCaptionStyle(Items[i]);
|
|
|
|
if {(style.AxisType = AType) and} (style.Caption = newStyle.Caption) then
|
2023-10-23 10:58:15 +00:00
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
2023-10-23 00:03:45 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
|
|
|
|
2023-10-23 22:18:31 +00:00
|
|
|
{ Searches whether the legend style of the given chart is already in the
|
|
|
|
list. If not, a new style is created and added.
|
|
|
|
The type of the requested axis must be provided as parameter.
|
|
|
|
Returns the index of the style. }
|
|
|
|
function TsChartStyleList.FindChartLegendStyle(AChart: TsChart): Integer;
|
|
|
|
var
|
|
|
|
newStyle, style: TsChartLegendStyle;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
newStyle := TsChartLegendStyle.Create;
|
|
|
|
newStyle.ExtractFromChart(AChart);
|
|
|
|
for i := 0 to Count-1 do
|
|
|
|
begin
|
|
|
|
if (TsChartStyle(Items[i]) is TsChartLegendStyle) then
|
|
|
|
begin
|
|
|
|
style := TsChartLegendStyle(Items[i]);
|
|
|
|
if (style.Legend = newStyle.Legend) then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result = -1 then
|
|
|
|
Result := Add(newStyle)
|
|
|
|
else
|
|
|
|
newStyle.Free;
|
|
|
|
end;
|
2023-10-25 17:15:57 +00:00
|
|
|
*)
|
2023-10-23 00:03:45 +00:00
|
|
|
end.
|
|
|
|
|