diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index d072abc2bb..c35ba6b70c 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -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; diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index 23085d997e..67ffc8059d 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -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;