TAChart: Add MarkPositions property to point-based series

git-svn-id: trunk@30578 -
This commit is contained in:
ask 2011-05-06 10:47:34 +00:00
parent c96a1114c1
commit 4f051e1e6d
2 changed files with 38 additions and 12 deletions

View File

@ -182,10 +182,15 @@ type
TLabelDirection = (ldLeft, ldTop, ldRight, ldBottom);
TLinearMarkPositions = (lmpOutside, lmpPositive, lmpNegative, lmpInside);
{ TBasicPointSeries }
TBasicPointSeries = class(TChartSeries)
private
FMarkPositions: TLinearMarkPositions;
function GetLabelDirection(AIndex: Integer): TLabelDirection;
procedure SetMarkPositions(AValue: TLinearMarkPositions);
procedure SetUseReticule(AValue: Boolean);
protected
@ -196,9 +201,9 @@ type
FUseReticule: Boolean;
procedure DrawLabels(ADrawer: IChartDrawer);
function GetLabelDirection(AIndex: Integer): TLabelDirection; virtual;
procedure GetLegendItemsRect(AItems: TChartLegendItems; ABrush: TBrush);
function GetXRange(AX: Double; AIndex: Integer): Double;
function GetZeroLevel: Double; virtual;
procedure PrepareGraphPoints(
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
procedure UpdateGraphPoints(AIndex: Integer);
@ -212,6 +217,8 @@ type
out AIndex: Integer; out AImg: TPoint; out AValue: TDoublePoint): Boolean;
override;
procedure MovePoint(var AIndex: Integer; const ANewPos: TPoint); override;
property MarkPositions: TLinearMarkPositions
read FMarkPositions write SetMarkPositions default lmpOutside;
end;
implementation
@ -775,8 +782,16 @@ function TBasicPointSeries.GetLabelDirection(AIndex: Integer): TLabelDirection;
const
DIR: array [Boolean, Boolean] of TLabelDirection =
((ldTop, ldBottom), (ldRight, ldLeft));
var
isNeg: Boolean;
begin
Result := DIR[IsRotated, GetGraphPointY(AIndex) < 0];
case MarkPositions of
lmpOutside: isNeg := GetGraphPointY(AIndex) < GetZeroLevel;
lmpPositive: isNeg := false;
lmpNegative: isNeg := true;
lmpInside: isNeg := GetGraphPointY(AIndex) >= GetZeroLevel;
end;
Result := DIR[IsRotated, isNeg];
end;
procedure TBasicPointSeries.GetLegendItemsRect(
@ -834,6 +849,11 @@ begin
end;
end;
function TBasicPointSeries.GetZeroLevel: Double;
begin
Result := 0.0;
end;
procedure TBasicPointSeries.MovePoint(
var AIndex: Integer; const ANewPos: TPoint);
var
@ -879,6 +899,13 @@ begin
FGraphPoints[i - FLoBound] := GetGraphPoint(i);
end;
procedure TBasicPointSeries.SetMarkPositions(AValue: TLinearMarkPositions);
begin
if FMarkPositions = AValue then exit;
FMarkPositions := AValue;
UpdateParentChart;
end;
procedure TBasicPointSeries.SetUseReticule(AValue: Boolean);
begin
if FUseReticule = AValue then exit;

View File

@ -92,6 +92,7 @@ type
property BarWidthStyle: TBarWidthStyle
read FBarWidthStyle write SetBarWidthStyle default bwPercent;
property Depth;
property MarkPositions;
property SeriesColor: TColor
read GetSeriesColor write SetSeriesColor stored false default clRed;
property Source;
@ -138,9 +139,9 @@ type
procedure SetUseZeroLevel(AValue: Boolean);
procedure SetZeroLevel(AValue: Double);
protected
function GetLabelDirection(AIndex: Integer): TLabelDirection; override;
procedure GetLegendItems(AItems: TChartLegendItems); override;
function GetSeriesColor: TColor; override;
function GetZeroLevel: Double; override;
public
procedure Assign(ASource: TPersistent); override;
constructor Create(AOwner: TComponent); override;
@ -158,6 +159,7 @@ type
property ConnectType: TConnectType
read FConnectType write SetConnectType default ctLine;
property Depth;
property MarkPositions;
property SeriesColor: TColor
read GetSeriesColor write SetSeriesColor stored false default clWhite;
property Source;
@ -213,6 +215,7 @@ type
property LinePen: TPen read FLinePen write SetLinePen;
property LineType: TLineType
read FLineType write SetLineType default ltFromPrevious;
property MarkPositions;
property OnDrawPointer: TSeriesPointerDrawEvent
read FOnDrawPointer write FOnDrawPointer;
property Pointer: TSeriesPointer read FPointer write SetPointer;
@ -1098,15 +1101,6 @@ begin
UpdateMinMax(ZeroLevel, Result.a.Y, Result.b.Y);
end;
function TAreaSeries.GetLabelDirection(AIndex: Integer): TLabelDirection;
const
DIR: array [Boolean, Boolean] of TLabelDirection =
((ldTop, ldBottom), (ldRight, ldLeft));
begin
Result :=
DIR[IsRotated, UseZeroLevel and (GetGraphPointY(AIndex) < ZeroLevel)];
end;
procedure TAreaSeries.GetLegendItems(AItems: TChartLegendItems);
begin
GetLegendItemsRect(AItems, AreaBrush);
@ -1117,6 +1111,11 @@ begin
Result := FAreaBrush.Color;
end;
function TAreaSeries.GetZeroLevel: Double;
begin
Result := IfThen(UseZeroLevel, ZeroLevel, 0.0);
end;
function TAreaSeries.IsZeroLevelStored: boolean;
begin
Result := ZeroLevel <> 0.0;