TAChart: Move ShowInLegend property into TBasicChartSeries class.

Rearrange some declarations alphabetically.

git-svn-id: trunk@19166 -
This commit is contained in:
ask 2009-03-31 05:31:25 +00:00
parent f251f2caf1
commit 834c9f9146
2 changed files with 43 additions and 45 deletions

View File

@ -52,22 +52,23 @@ type
FTitle: String;
FChart: TChart;
FActive: Boolean;
FShowInLegend: Boolean;
procedure AfterAdd; virtual; abstract;
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); virtual; abstract;
function GetLegendCount: Integer; virtual; abstract;
function GetLegendWidth(ACanvas: TCanvas): Integer; virtual; abstract;
function IsInLegend: Boolean; virtual; abstract;
procedure UpdateMargins(ACanvas: TCanvas; var AMargins: TRect); virtual;
procedure UpdateBounds(
var AXMin, AYMin, AXMax, AYMax: Double); virtual; abstract;
procedure AfterAdd; virtual; abstract;
function GetNearestPoint(
ADistFunc: TPointDistFunc; const APoint: TPoint;
out AIndex: Integer; out AImg: TPoint; out AValue: TDoublePoint): Boolean;
virtual;
function GetSeriesColor: TColor; virtual; abstract;
procedure SetSeriesColor(const AValue: TColor); virtual; abstract;
procedure UpdateBounds(
var AXMin, AYMin, AXMax, AYMax: Double); virtual; abstract;
procedure UpdateMargins(ACanvas: TCanvas; var AMargins: TRect); virtual;
procedure SetActive(AValue: Boolean); virtual; abstract;
procedure SetSeriesColor(const AValue: TColor); virtual; abstract;
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
procedure ReadState(Reader: TReader); override;
procedure SetParentComponent(AParent: TComponent); override;
@ -84,6 +85,8 @@ type
property ParentChart: TChart read FChart;
property SeriesColor: TColor
read GetSeriesColor write SetSeriesColor default clTAColor;
property ShowInLegend: Boolean
read FShowInLegend write SetShowInLegend default true;
property Title: String read FTitle write FTitle;
end;
@ -309,6 +312,19 @@ const
MinDouble = -1.7e308;
MaxDouble = 1.7e308;
procedure Register;
var
i: Integer;
sc: TSeriesClass;
begin
RegisterComponents('Additional', [TChart]);
for i := 0 to SeriesClassRegistry.Count - 1 do begin
sc := TSeriesClass(SeriesClassRegistry.Objects[i]);
RegisterClass(sc);
RegisterNoIcon([sc]);
end;
end;
procedure RegisterSeriesClass(ASeriesClass: TSeriesClass; const ACaption: string);
begin
if SeriesClassRegistry.IndexOfObject(TObject(ASeriesClass)) < 0 then
@ -767,8 +783,9 @@ begin
TH := ACanvas.TextHeight('I');
h := 0;
for i := 0 to SeriesCount - 1 do
if Series[i].IsInLegend then
Inc(h, Series[i].GetLegendCount);
with Series[i] do
if Active and ShowInLegend then
Inc(h, GetLegendCount);
x1 := ARect.Right - w - 5;
y1 := YImageMax;
x2 := x1 + w;
@ -783,7 +800,7 @@ begin
r := Bounds(x1 + LEGEND_SPACING, y1 + LEGEND_SPACING, 17, TH);
for i := 0 to SeriesCount - 1 do
with Series[i] do
if IsInLegend then begin
if Active and ShowInLegend then begin
ACanvas.Pen.Color := FLegend.Frame.Color;
ACanvas.Brush.Assign(FGraphBrush);
DrawLegend(ACanvas, r);
@ -884,8 +901,9 @@ begin
exit;
for i := 0 to SeriesCount - 1 do
if Series[i].IsInLegend then
Result := Max(Series[i].GetLegendWidth(ACanvas), Result);
with Series[i] do
if Active and ShowInLegend then
Result := Max(GetLegendWidth(ACanvas), Result);
if Result > 0 then
Result += 20 + 10;
end;
@ -1431,19 +1449,6 @@ begin
// nothing
end;
procedure Register;
var
i: Integer;
sc: TSeriesClass;
begin
RegisterComponents('Additional', [TChart]);
for i := 0 to SeriesClassRegistry.Count - 1 do begin
sc := TSeriesClass(SeriesClassRegistry.Objects[i]);
RegisterClass(sc);
RegisterNoIcon([sc]);
end;
end;
{ TChartSeriesList }
function TChartSeriesList.Count: Integer;

View File

@ -44,28 +44,27 @@ type
FXGraphMax, FYGraphMax: Double;
FCoordList: TList;
FMarks: TChartMarks;
FShowInLegend: Boolean;
FValuesTotal: Double;
FValuesTotalValid: Boolean;
function GetXMinVal: Integer;
procedure SetMarks(const AValue: TChartMarks);
procedure SetShowInLegend(Value: Boolean);
procedure InitBounds(out XMin, YMin, XMax, YMax: Integer);
procedure SetMarks(const AValue: TChartMarks);
protected
procedure AfterAdd; override;
procedure StyleChanged(Sender: TObject);
property Coord: TList read FCoordList;
function ColorOrDefault(AColor: TColor; ADefault: TColor = clTAColor): TColor;
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override;
function GetLegendWidth(ACanvas: TCanvas): Integer; override;
procedure GetCoords(AIndex: Integer; out AG: TDoublePoint; out AI: TPoint);
function GetLegendCount: Integer; override;
function IsInLegend: Boolean; override;
function GetLegendWidth(ACanvas: TCanvas): Integer; override;
function GetValuesTotal: Double;
procedure SetActive(AValue: Boolean); override;
procedure SetShowInLegend(Value: Boolean); override;
procedure StyleChanged(Sender: TObject);
procedure UpdateBounds(var AXMin, AYMin, AXMax, AYMax: Double); override;
procedure UpdateParentChart;
function GetValuesTotal: Double;
procedure GetCoords(AIndex: Integer; out AG: TDoublePoint; out AI: TPoint);
function ColorOrDefault(AColor: TColor; ADefault: TColor = clTAColor): TColor;
procedure SetActive(AValue: Boolean); override;
property Coord: TList read FCoordList;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -75,19 +74,18 @@ type
property XGraphMax: Double read FXGraphMax write FXGraphMax;
property YGraphMax: Double read FYGraphMax write FYGraphMax;
function Count: Integer; override;
function Add(AValue: Double; XLabel: String; Color: TColor): Longint; virtual;
function AddXY(X, Y: Double; XLabel: String; Color: TColor): Longint; virtual; overload;
function AddXY(X, Y: Double): Longint; virtual; overload;
function Add(AValue: Double; XLabel: String; Color: TColor): Longint; virtual;
procedure Delete(AIndex: Integer); virtual;
procedure Clear;
function Count: Integer; override;
procedure Delete(AIndex: Integer); virtual;
function FormattedMark(AIndex: integer): String;
published
property Active default true;
property Marks: TChartMarks read FMarks write SetMarks;
property ShowInLegend: Boolean
read FShowInLegend write SetShowInLegend default true;
property ShowInLegend;
property Title;
end;
@ -396,11 +394,6 @@ begin
Exchange(YMin, YMax);
end;
function TChartSeries.IsInLegend: Boolean;
begin
Result := Active and ShowInLegend;
end;
function TChartSeries.AddXY(X, Y: Double; XLabel: String; Color: TColor): Longint;
var
pcc: PChartCoord;