TAChart: Rename the new OnOwnerDrawPointer event to OnCustomDrawPointer. Add OnGetPointerStyle event (for Delphi compatibility) and add this to line demo.

git-svn-id: trunk@52104 -
This commit is contained in:
wp 2016-04-04 14:19:00 +00:00
parent e63ea5918a
commit e0199daa77
4 changed files with 113 additions and 93 deletions

View File

@ -46,6 +46,7 @@ object Form1: TForm1
)
Toolset = ChartToolset1
Align = alClient
Color = clWindow
DoubleBuffered = True
object chFastLineSeries1: TLineSeries
LinePen.Color = clTeal
@ -66,13 +67,14 @@ object Form1: TForm1
Top = 0
Width = 683
Align = alTop
BevelOuter = bvNone
ClientHeight = 38
ClientWidth = 683
TabOrder = 1
object cbLineType: TComboBox
Left = 8
Height = 23
Top = 8
Top = 6
Width = 96
ItemHeight = 15
ItemIndex = 1
@ -91,7 +93,7 @@ object Form1: TForm1
object cb3D: TCheckBox
Left = 112
Height = 19
Top = 12
Top = 8
Width = 34
Caption = '3D'
OnChange = cb3DChange
@ -100,7 +102,7 @@ object Form1: TForm1
object cbRotated: TCheckBox
Left = 152
Height = 19
Top = 12
Top = 8
Width = 61
Caption = 'Rotated'
OnChange = cbRotatedChange
@ -135,7 +137,7 @@ object Form1: TForm1
object cbSorted: TCheckBox
Left = 216
Height = 19
Top = 12
Top = 8
Width = 54
Caption = 'Sorted'
OnChange = cbSortedChange
@ -208,14 +210,14 @@ object Form1: TForm1
end
end
end
object tsOwnerDrawnPointer: TTabSheet
object tsCustomDrawPointer: TTabSheet
Caption = 'Ownerdrawn pointer'
ClientHeight = 466
ClientWidth = 683
object ChartOwnerDrawnPointer: TChart
object Chart_CustomDrawPointer: TChart
Left = 0
Height = 432
Top = 34
Height = 428
Top = 38
Width = 683
AxisList = <
item
@ -234,20 +236,21 @@ object Form1: TForm1
'TAChart'
)
Align = alClient
object lsOwnerDrawnPointer: TLineSeries
OnOwnerDrawPointer = lsOwnerDrawnPointerOwnerDrawPointer
Color = clWindow
object lsCustomDrawPointer: TLineSeries
ShowPoints = True
Source = RandomChartSource1
OnCustomDrawPointer = lsCustomDrawPointerCustomDrawPointer
end
end
object Panel2: TPanel
Left = 0
Height = 34
Height = 38
Top = 0
Width = 683
Align = alTop
BevelOuter = bvNone
ClientHeight = 34
ClientHeight = 38
ClientWidth = 683
TabOrder = 1
object cbBitmapPointer: TCheckBox
@ -267,9 +270,9 @@ object Form1: TForm1
Left = 139
Height = 19
Top = 8
Width = 115
Width = 142
BorderSpacing.Left = 16
Caption = 'Every n-th pointer'
Caption = 'Every n-th pointer, n = '
Checked = True
OnChange = cbBitmapPointerChange
State = cbChecked
@ -278,7 +281,7 @@ object Form1: TForm1
object edEveryNth: TSpinEdit
AnchorSideLeft.Control = cbDrawEveryNthPointer
AnchorSideLeft.Side = asrBottom
Left = 254
Left = 281
Height = 23
Top = 8
Width = 50
@ -294,7 +297,7 @@ object Form1: TForm1
AnchorSideLeft.Side = asrBottom
Left = 107
Height = 16
Top = 10
Top = 8
Width = 16
AutoSize = True
Picture.Data = {
@ -321,6 +324,40 @@ object Form1: TForm1
end
end
end
object tsGetPointerStyle: TTabSheet
Caption = 'OnGetPointerStyle event'
ClientHeight = 466
ClientWidth = 683
object ChartGetPointerStyleEvent: TChart
Left = 0
Height = 466
Top = 0
Width = 683
AxisList = <
item
Minors = <>
Title.LabelFont.Orientation = 900
end
item
Alignment = calBottom
Minors = <>
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWindow
object lsGetPointerStyle: TLineSeries
ShowPoints = True
Source = RandomChartSource1
OnGetPointerStyle = lsGetPointerStyleGetPointerStyle
end
end
end
object tsOscilloscope: TTabSheet
Caption = 'Oscilloscope'
ClientHeight = 466
@ -355,6 +392,7 @@ object Form1: TForm1
'TAChart'
)
Align = alClient
Color = clWindow
DoubleBuffered = True
object chOscillatorLineSeries1: TLineSeries
AxisIndexX = 1
@ -391,26 +429,6 @@ object Form1: TForm1
Shift = [ssRight]
end
end
object ccsAvg: TCalculatedChartSource
AccumulationMethod = camAverage
AccumulationRange = 5
Origin = RandomChartSource1
left = 464
top = 108
end
object ccsSum: TCalculatedChartSource
AccumulationMethod = camSum
AccumulationRange = 0
Origin = RandomChartSource1
left = 464
top = 52
end
object ccsDerivative: TCalculatedChartSource
AccumulationMethod = camDerivative
Origin = RandomChartSource1
left = 464
top = 160
end
object lcsOscillator: TListChartSource
DataPoints.Strings = (
'0|0|?|'
@ -422,7 +440,7 @@ object Form1: TForm1
Enabled = False
Interval = 150
OnTimer = timOscilloscopeTimer
left = 408
left = 376
top = 376
end
object catOscillator: TChartAxisTransformations

View File

@ -7,7 +7,7 @@ interface
uses
Classes, ComCtrls, ExtCtrls, Spin, StdCtrls, SysUtils, FileUtil, Forms,
Controls, Graphics, Dialogs, TAGraph, TASeries, TASources, TATools,
TATransformations, TACustomSeries, Types, TADrawUtils;
TATransformations, TACustomSeries, Types, TADrawUtils, TATypes;
type
@ -21,13 +21,12 @@ type
cbLineType: TComboBox;
cbRotated: TCheckBox;
cbSorted: TCheckBox;
ccsAvg: TCalculatedChartSource;
ccsDerivative: TCalculatedChartSource;
ccsSum: TCalculatedChartSource;
catOscillator: TChartAxisTransformations;
ChartOwnerDrawnPointer: TChart;
Chart_CustomDrawPointer: TChart;
ChartGetPointerStyleEvent: TChart;
lsGetPointerStyle: TLineSeries;
PointerImage: TImage;
lsOwnerDrawnPointer: TLineSeries;
lsCustomDrawPointer: TLineSeries;
cbBitmapPointer: TCheckBox;
cbDrawEveryNthPointer: TCheckBox;
chOscillator: TChart;
@ -51,6 +50,8 @@ type
RandomChartSource1: TRandomChartSource;
sePointerSize: TSpinEdit;
edEveryNth: TSpinEdit;
tsCustomDrawPointer: TTabSheet;
tsGetPointerStyle: TTabSheet;
tsOwnerDrawnPointer: TTabSheet;
timOscilloscope: TTimer;
tsOscilloscope: TTabSheet;
@ -65,7 +66,9 @@ type
procedure cbSortedChange(Sender: TObject);
procedure edEveryNthChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lsOwnerDrawnPointerOwnerDrawPointer(ASender: TChartSeries;
function lsGetPointerStyleGetPointerStyle(ASender: TChartSeries;
AValueIndex: Integer): TSeriesPointerStyle;
procedure lsCustomDrawPointerCustomDrawPointer(ASender: TChartSeries;
ADrawer: IChartDrawer; AIndex: Integer; ACenter: TPoint);
procedure PageControl1Change(Sender: TObject);
procedure sePointerSizeChange(Sender: TObject);
@ -80,7 +83,7 @@ implementation
{$R *.lfm}
uses
LCLIntf, IntfGraphics, TAChartUtils, TATypes, TAEnumerators;
LCLIntf, IntfGraphics, TAChartUtils, TAEnumerators;
type
TLineSeriesEnum =
@ -126,10 +129,10 @@ end;
procedure TForm1.cbBitmapPointerChange(Sender: TObject);
begin
if cbBitmapPointer.Checked or cbDrawEveryNthPointer.Checked then
lsOwnerDrawnPointer.OnOwnerDrawPointer := @lsOwnerDrawnPointerOwnerDrawPointer
lsCustomDrawPointer.OnCustomDrawPointer := @lsCustomDrawPointerCustomDrawPointer
else
lsOwnerDrawnPointer.OnOwnerDrawPointer := nil;
ChartOwnerDrawnPointer.Invalidate;
lsCustomDrawPointer.OnCustomDrawPointer := nil;
Chart_CustomDrawPointer.Invalidate;
end;
procedure TForm1.cbLineTypeChange(Sender: TObject);
@ -161,7 +164,7 @@ end;
procedure TForm1.edEveryNthChange(Sender: TObject);
begin
ChartOwnerDrawnPointer.Invalidate;
Chart_CustomDrawPointer.Invalidate;
end;
procedure TForm1.FormCreate(Sender: TObject);
@ -187,15 +190,20 @@ begin
end;
end;
procedure TForm1.lsOwnerDrawnPointerOwnerDrawPointer(ASender: TChartSeries;
function TForm1.lsGetPointerStyleGetPointerStyle(ASender: TChartSeries;
AValueIndex: Integer): TSeriesPointerStyle;
begin
Result := TSeriesPointerStyle(AValueIndex mod (ord(High(TSeriespointerStyle))+1));
end;
procedure TForm1.lsCustomDrawPointerCustomDrawPointer(ASender: TChartSeries;
ADrawer: IChartDrawer; AIndex: Integer; ACenter: TPoint);
var
lineser: TLineSeries;
procedure DoDrawPointer;
var
img: TLazIntfImage;
bmp: TBitmap;
ser: TLineSeries;
begin
if cbBitmapPointer.Checked then begin
img := TLazIntfImage.Create(0,0);
@ -210,12 +218,13 @@ var
finally
img.Free;
end;
end else
lineser.Pointer.Draw(ADrawer, ACenter, lineser.Pointer.Brush.Color);
end else begin
ser := TLineseries(ASender);
ser.Pointer.Draw(ADrawer, ACenter, ser.Pointer.Brush.Color);
end;
end;
begin
lineser := TLineSeries(ASender);
if not cbDrawEveryNthPointer.Checked or (AIndex mod edEveryNth.Value = 0) then
DoDrawPointer;
end;

View File

@ -231,11 +231,20 @@ type
TLinearMarkPositions = (lmpOutside, lmpPositive, lmpNegative, lmpInside);
TSeriesPointerCustomDrawEvent = procedure (
ASender: TChartSeries; ADrawer: IChartDrawer; AIndex: Integer;
ACenter: TPoint) of object;
TSeriesPointerStyleEvent = function (ASender: TChartSeries;
AValueIndex: Integer): TSeriesPointerStyle of object;
{ TBasicPointSeries }
TBasicPointSeries = class(TChartSeries)
strict private
FMarkPositions: TLinearMarkPositions;
FOnCustomDrawPointer: TSeriesPointerCustomDrawEvent;
FOnGetPointerStyle: TSeriesPointerStyleEvent;
function GetLabelDirection(AIndex: Integer): TLabelDirection;
procedure SetMarkPositions(AValue: TLinearMarkPositions);
procedure SetPointer(AValue: TSeriesPointer);
@ -259,9 +268,6 @@ type
function GetXRange(AX: Double; AIndex: Integer): Double;
function GetZeroLevel: Double; virtual;
function NearestXNumber(var AIndex: Integer; ADir: Integer): Double;
procedure OwnerDrawPointer(
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint;
var AContinue: Boolean); virtual;
procedure PrepareGraphPoints(
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
procedure UpdateGraphPoints(AIndex: Integer); overload; inline;
@ -272,6 +278,10 @@ type
protected
procedure AfterAdd; override;
procedure UpdateMargins(ADrawer: IChartDrawer; var AMargins: TRect); override;
property OnCustomDrawPointer: TSeriesPointerCustomDrawEvent
read FOnCustomDrawPointer write FOnCustomDrawPointer;
property OnGetPointerStyle: TSeriesPointerStyleEvent
read FOnGetPointerStyle write FOnGetPointerStyle;
public
destructor Destroy; override;
@ -1095,7 +1105,7 @@ var
i: Integer;
p: TDoublePoint;
ai: TPoint;
defaultdraw: Boolean;
ps: TSeriesPointerStyle;
begin
Assert(Pointer <> nil, 'Series pointer');
if not Pointer.Visible then exit;
@ -1103,11 +1113,20 @@ begin
p := FGraphPoints[i - FLoBound];
if not ParentChart.IsPointInViewPort(p) then continue;
ai := ParentChart.GraphToImage(p);
defaultdraw := true;
OwnerDrawPointer(ADrawer, i, ai, defaultdraw);
if defaultdraw then begin
if Assigned(FOnCustomDrawPointer) then
FOnCustomDrawPointer(Self, ADrawer, i, ai)
else begin
ps := Pointer.Style;
if Assigned(FOnGetPointerStyle) then begin
Pointer.SetOwner(nil); // avoid recursion
Pointer.Style := FOnGetPointerStyle(self, i);
end;
Pointer.Draw(ADrawer, ai, Source[i]^.Color);
AfterDrawPointer(ADrawer, i, ai);
if Assigned(FOnGetPointerStyle) then begin
Pointer.Style := ps;
Pointer.SetOwner(ParentChart);
end;
end;
end;
end;
@ -1266,15 +1285,6 @@ begin
Result := SafeNan;
end;
procedure TBasicPointSeries.OwnerDrawPointer(
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint;
var AContinue: Boolean);
begin
Unused(ADrawer);
Unused(AIndex, APos);
Unused(AContinue);
end;
procedure TBasicPointSeries.PrepareGraphPoints(
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
var

View File

@ -176,10 +176,6 @@ type
ASender: TChartSeries; ACanvas: TCanvas; AIndex: Integer;
ACenter: TPoint) of object;
TSeriesPointerOwnerDrawEvent = procedure (
ASender: TChartSeries; ADrawer: IChartDrawer; AIndex: Integer;
ACenter: TPoint) of object;
TLineType = (ltNone, ltFromPrevious, ltFromOrigin, ltStepXY, ltStepYX);
{ TLineSeries }
@ -189,7 +185,6 @@ type
FLinePen: TPen;
FLineType: TLineType;
FOnDrawPointer: TSeriesPointerDrawEvent;
FOnOwnerDrawPointer: TSeriesPointerOwnerDrawEvent;
FShowPoints: Boolean;
procedure DrawSingleLineInStack(ADrawer: IChartDrawer; AIndex: Integer);
@ -204,8 +199,6 @@ type
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint); override;
procedure GetLegendItems(AItems: TChartLegendItems); override;
function GetSeriesColor: TColor; override;
procedure OwnerDrawPointer(ADrawer: IChartDrawer; AIndex: Integer;
const APos: TPoint; var AContinue: Boolean); override;
public
procedure Assign(ASource: TPersistent); override;
constructor Create(AOwner: TComponent); override;
@ -222,10 +215,6 @@ type
property LineType: TLineType
read FLineType write SetLineType default ltFromPrevious;
property MarkPositions;
property OnDrawPointer: TSeriesPointerDrawEvent
read FOnDrawPointer write FOnDrawPointer; deprecated 'Use OnOwnerDrawPointer';
property OnOwnerDrawPointer: TSeriesPointerOwnerDrawEvent
read FOnOwnerDrawPointer write FOnOwnerDrawPointer;
property Pointer;
property SeriesColor: TColor
read GetSeriesColor write SetSeriesColor stored false default clBlack;
@ -236,6 +225,11 @@ type
property Source;
property Styles;
property UseReticule default true;
// Events
property OnDrawPointer: TSeriesPointerDrawEvent
read FOnDrawPointer write FOnDrawPointer; deprecated 'Use OnCustomDrawPointer';
property OnCustomDrawPointer;
property OnGetPointerStyle;
end;
// 'TSerie' alias is for compatibility with older versions of TAChart.
@ -619,17 +613,6 @@ begin
Result := FLineType <> ltNone;
end;
procedure TLineSeries.OwnerDrawPointer(
ADrawer: IChartDrawer; AIndex: Integer; const APos: TPoint;
var AContinue: Boolean);
begin
if Assigned(FOnOwnerDrawPointer) then begin
FOnOwnerDrawPointer(Self, ADrawer, AIndex, APos);
AContinue := false;
end else
AContinue := true;
end;
procedure TLineSeries.SetLinePen(AValue: TPen);
begin
FLinePen.Assign(AValue);