TAChart: Sort and group TChart members. Publish AxisColor property.

git-svn-id: trunk@19599 -
This commit is contained in:
ask 2009-04-24 08:39:47 +00:00
parent ad9038a66e
commit a480ed52ae

View File

@ -72,16 +72,19 @@ type
var AXMin, AYMin, AXMax, AYMax: Double); virtual; abstract; var AXMin, AYMin, AXMax, AYMax: Double); virtual; abstract;
procedure UpdateMargins(ACanvas: TCanvas; var AMargins: TRect); virtual; procedure UpdateMargins(ACanvas: TCanvas; var AMargins: TRect); virtual;
protected
procedure ReadState(Reader: TReader); override; procedure ReadState(Reader: TReader); override;
procedure SetParentComponent(AParent: TComponent); override; procedure SetParentComponent(AParent: TComponent); override;
public public
destructor Destroy; override; destructor Destroy; override;
function GetParentComponent: TComponent; override; function GetParentComponent: TComponent; override;
function HasParent: Boolean; override; function HasParent: Boolean; override;
function IsEmpty: Boolean; virtual; abstract; public
procedure Draw(ACanvas: TCanvas); virtual; abstract; procedure Draw(ACanvas: TCanvas); virtual; abstract;
function IsEmpty: Boolean; virtual; abstract;
property Active: Boolean read FActive write SetActive; property Active: Boolean read FActive write SetActive;
property ParentChart: TChart read FChart; property ParentChart: TChart read FChart;
@ -104,10 +107,11 @@ type
function GetItem(AIndex: Integer): TBasicChartSeries; function GetItem(AIndex: Integer): TBasicChartSeries;
procedure SetItem(AIndex: Integer; const AValue: TBasicChartSeries); procedure SetItem(AIndex: Integer; const AValue: TBasicChartSeries);
public public
function Count: Integer;
constructor Create(AOwner: TChart); constructor Create(AOwner: TChart);
destructor Destroy; override; destructor Destroy; override;
function Count: Integer; public
property Chart: TChart read FChart; property Chart: TChart read FChart;
property Items[AIndex: Integer]: TBasicChartSeries property Items[AIndex: Integer]: TBasicChartSeries
read GetItem write SetItem; default; read GetItem write SetItem; default;
@ -116,146 +120,140 @@ type
{ TChart } { TChart }
TChart = class(TCustomChart) TChart = class(TCustomChart)
private private // Property fields
FExtent: TChartExtent;
FSeries: TChartSeriesList;
FMirrorX: Boolean; // From right to left ?
FXGraphMin, FYGraphMin: Double; // Graph coordinates of limits
FXGraphMax, FYGraphMax: Double;
FLegend: TChartLegend; //legend configuration
FTitle: TChartTitle; //legend configuration
FFoot: TChartTitle; //legend configuration
FLeftAxis: TChartAxis;
FBottomAxis: TChartAxis;
FAllowZoom: Boolean; FAllowZoom: Boolean;
FAxisColor: TColor;
FAxisVisible: Boolean;
FBottomAxis: TChartAxis;
FExtent: TChartExtent;
FFoot: TChartTitle;
FFrame: TChartPen;
FGraphBrush: TBrush; FGraphBrush: TBrush;
AxisColor: TColor; // Axis color FLeftAxis: TChartAxis;
FScale, FOffset: TDoublePoint; // Coordinates transformation FLegend: TChartLegend;
FMirrorX: Boolean; // From right to left ?
FOnDrawReticule: TDrawReticuleEvent;
FSeries: TChartSeriesList;
FTitle: TChartTitle;
private
FClipRect: TRect;
FCurrentExtent: TDoubleRect;
FIsMouseDown: Boolean; FIsMouseDown: Boolean;
FIsZoomed: Boolean; FIsZoomed: Boolean;
FSelectionRect: TRect; FOffset: TDoublePoint; // Coordinates transformation
FCurrentExtent: TDoubleRect;
FClipRect: TRect;
FReticuleMode: TReticuleMode; FReticuleMode: TReticuleMode;
FOnDrawReticule: TDrawReticuleEvent;
FReticulePos: TPoint; FReticulePos: TPoint;
FScale: TDoublePoint; // Coordinates transformation
FSelectionRect: TRect;
FXGraphMax, FXGraphMin: Double; // Graph coordinates of limits
FYGraphMax, FYGraphMin: Double;
FFrame: TChartPen;
FAxisVisible: Boolean;
function GetMargins(ACanvas: TCanvas): TRect;
procedure CalculateTransformationCoeffs(const AMargin: TRect); procedure CalculateTransformationCoeffs(const AMargin: TRect);
procedure PrepareXorPen;
procedure SetExtent(const AValue: TChartExtent);
procedure SetReticuleMode(const AValue: TReticuleMode);
procedure SetMirrorX(AValue: Boolean);
procedure SetGraphBrush(Value: TBrush);
procedure SetTitle(Value: TChartTitle);
procedure SetFoot(Value: TChartTitle);
function GetLegendWidth(ACanvas: TCanvas): Integer;
procedure DrawReticule(ACanvas: TCanvas); procedure DrawReticule(ACanvas: TCanvas);
procedure SetLegend(Value: TChartLegend);
procedure SetLeftAxis(Value: TChartAxis);
procedure SetBottomAxis(Value: TChartAxis);
procedure SetFrame(Value: TChartPen);
procedure SetAxisVisible(Value: Boolean);
function GetChartHeight: Integer; function GetChartHeight: Integer;
function GetChartWidth: Integer; function GetChartWidth: Integer;
function GetLegendWidth(ACanvas: TCanvas): Integer;
function GetMargins(ACanvas: TCanvas): TRect;
function GetSeriesCount: Integer; function GetSeriesCount: Integer;
function GetSeriesInZOrder: TFPList; function GetSeriesInZOrder: TFPList;
procedure PrepareXorPen;
procedure SetAxisColor(const AValue: TColor);
procedure SetAxisVisible(Value: Boolean);
procedure SetBottomAxis(Value: TChartAxis);
procedure SetExtent(const AValue: TChartExtent);
procedure SetFoot(Value: TChartTitle);
procedure SetFrame(Value: TChartPen);
procedure SetGraphBrush(Value: TBrush);
procedure SetLeftAxis(Value: TChartAxis);
procedure SetLegend(Value: TChartLegend);
procedure SetMirrorX(AValue: Boolean);
procedure SetReticuleMode(const AValue: TReticuleMode);
procedure SetTitle(Value: TChartTitle);
protected protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure Clean(ACanvas: TCanvas; ARect: TRect);
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure DisplaySeries(ACanvas: TCanvas);
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure DoDrawReticule( procedure DoDrawReticule(
ASeriesIndex, AIndex: Integer; const AImg: TPoint; ASeriesIndex, AIndex: Integer; const AImg: TPoint;
const AData: TDoublePoint); virtual; const AData: TDoublePoint); virtual;
procedure Clean(ACanvas: TCanvas; ARect: TRect);
procedure DrawTitleFoot(ACanvas: TCanvas);
procedure DrawAxis(ACanvas: TCanvas; ARect: TRect); procedure DrawAxis(ACanvas: TCanvas; ARect: TRect);
procedure DrawLegend(ACanvas: TCanvas); procedure DrawLegend(ACanvas: TCanvas);
procedure DrawTitleFoot(ACanvas: TCanvas);
procedure MouseDown(
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure StyleChanged(Sender: TObject);
procedure UpdateExtent; procedure UpdateExtent;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure Paint; override;
procedure EraseBackground(DC: HDC); override; procedure EraseBackground(DC: HDC); override;
procedure GetChildren(AProc: TGetChildProc; ARoot: TComponent); override; procedure GetChildren(AProc: TGetChildProc; ARoot: TComponent); override;
procedure Paint; override;
procedure SetChildOrder(Child: TComponent; Order: Integer); override; procedure SetChildOrder(Child: TComponent; Order: Integer); override;
procedure PaintOnCanvas(ACanvas: TCanvas; ARect: TRect); public // Helpers for series drawing
procedure AddSeries(ASeries: TBasicChartSeries);
procedure DeleteSeries(ASeries: TBasicChartSeries);
function XGraphToImage(AX: Double): Integer; inline;
function YGraphToImage(AY: Double): Integer; inline;
function GraphToImage(const AGraphPoint: TDoublePoint): TPoint;
function XImageToGraph(AX: Integer): Double; inline;
function YImageToGraph(AY: Integer): Double; inline;
function ImageToGraph(const APoint: TPoint): TDoublePoint;
procedure DisplaySeries(ACanvas: TCanvas);
procedure ZoomFull;
procedure SaveToBitmapFile(const FileName: String);
procedure CopyToClipboardBitmap;
procedure DrawOnCanvas(Rect: TRect; ACanvas: TCanvas);
procedure DrawLineHoriz(ACanvas: TCanvas; AY: Integer);
procedure DrawLineVert(ACanvas: TCanvas; AX: Integer);
function GetNewColor: TColor; function GetNewColor: TColor;
function GetRectangle: TRect; function GetRectangle: TRect;
function LineInViewPort(var AG1, AG2: TDoublePoint): Boolean;
function IsPointInViewPort(const AP: TDoublePoint): Boolean; function IsPointInViewPort(const AP: TDoublePoint): Boolean;
function LineInViewPort(var AG1, AG2: TDoublePoint): Boolean;
property Canvas; public
property ClipRect: TRect read FClipRect; procedure AddSeries(ASeries: TBasicChartSeries);
procedure CopyToClipboardBitmap;
procedure DeleteSeries(ASeries: TBasicChartSeries);
procedure DrawLineHoriz(ACanvas: TCanvas; AY: Integer);
procedure DrawLineVert(ACanvas: TCanvas; AX: Integer);
procedure DrawOnCanvas(Rect: TRect; ACanvas: TCanvas);
procedure PaintOnCanvas(ACanvas: TCanvas; ARect: TRect);
procedure SaveToBitmapFile(const FileName: String);
procedure ZoomFull;
property XGraphMin: Double read FXGraphMin; public // Coordinate conversion
property YGraphMin: Double read FYGraphMin; function GraphToImage(const AGraphPoint: TDoublePoint): TPoint;
property XGraphMax: Double read FXGraphMax; function ImageToGraph(const APoint: TPoint): TDoublePoint;
property YGraphMax: Double read FYGraphMax; function XGraphToImage(AX: Double): Integer; inline;
function XImageToGraph(AX: Integer): Double; inline;
function YGraphToImage(AY: Double): Integer; inline;
function YImageToGraph(AY: Integer): Double; inline;
property SeriesCount: Integer read GetSeriesCount; public
property ChartHeight: Integer read GetChartHeight; property ChartHeight: Integer read GetChartHeight;
property ChartWidth: Integer read GetChartWidth; property ChartWidth: Integer read GetChartWidth;
property ClipRect: TRect read FClipRect;
property SeriesCount: Integer read GetSeriesCount;
property XGraphMax: Double read FXGraphMax;
property XGraphMin: Double read FXGraphMin;
property YGraphMax: Double read FYGraphMax;
property YGraphMin: Double read FYGraphMin;
published published
procedure StyleChanged(Sender: TObject); property AllowZoom: Boolean read FAllowZoom write FAllowZoom default true;
property AxisColor: TColor read FAxisColor write SetAxisColor default clBlack;
property AxisVisible: Boolean read FAxisVisible write SetAxisVisible default true;
property BottomAxis: TChartAxis read FBottomAxis write SetBottomAxis;
property Extent: TChartExtent read FExtent write SetExtent; property Extent: TChartExtent read FExtent write SetExtent;
property MirrorX: Boolean read FMirrorX write SetMirrorX default false; property Foot: TChartTitle read FFoot write SetFoot;
property Frame: TChartPen read FFrame write SetFrame;
property GraphBrush: TBrush read FGraphBrush write SetGraphBrush; property GraphBrush: TBrush read FGraphBrush write SetGraphBrush;
property LeftAxis: TChartAxis read FLeftAxis write SetLeftAxis;
property Legend: TChartLegend read FLegend write SetLegend;
property MirrorX: Boolean read FMirrorX write SetMirrorX default false;
property ReticuleMode: TReticuleMode property ReticuleMode: TReticuleMode
read FReticuleMode write SetReticuleMode default rmNone; read FReticuleMode write SetReticuleMode default rmNone;
property Series: TChartSeriesList read FSeries; property Series: TChartSeriesList read FSeries;
property Title: TChartTitle read FTitle write SetTitle;
published
property OnDrawReticule: TDrawReticuleEvent property OnDrawReticule: TDrawReticuleEvent
read FOnDrawReticule write FOnDrawReticule; read FOnDrawReticule write FOnDrawReticule;
property Legend: TChartLegend read FLegend write SetLegend; published
property Title: TChartTitle read FTitle write SetTitle;
property Foot: TChartTitle read FFoot write SetFoot;
property AllowZoom: Boolean read FAllowZoom write FAllowZoom default true;
property LeftAxis: TChartAxis read FLeftAxis write SetLeftAxis;
property BottomAxis: TChartAxis read FBottomAxis write SetBottomAxis;
property Frame: TChartPen read FFrame write SetFrame;
property AxisVisible: Boolean read FAxisVisible write SetAxisVisible default true;
property Align; property Align;
property Anchors; property Anchors;
property Color default clBtnFace; property Color default clBtnFace;
@ -269,15 +267,16 @@ type
property ShowHint; property ShowHint;
property Visible; property Visible;
published
property OnClick; property OnClick;
property OnDblClick; property OnDblClick;
property OnDragDrop; property OnDragDrop;
property OnDragOver; property OnDragOver;
property OnEndDrag; property OnEndDrag;
property OnStartDrag;
property OnMouseDown; property OnMouseDown;
property OnMouseMove; property OnMouseMove;
property OnMouseUp; property OnMouseUp;
property OnStartDrag;
end; end;
procedure Register; procedure Register;
@ -985,6 +984,13 @@ begin
end; end;
end; end;
procedure TChart.SetAxisColor(const AValue: TColor);
begin
if FAxisColor = AValue then exit;
FAxisColor := AValue;
Invalidate;
end;
procedure TChart.CopyToClipboardBitmap; procedure TChart.CopyToClipboardBitmap;
var var
tmpBitmap: TBitmap; tmpBitmap: TBitmap;