From 08bb26f6b0f0acaef41aebc745c356cdb7f0bab9 Mon Sep 17 00:00:00 2001 From: ask Date: Thu, 18 Mar 2010 13:22:55 +0000 Subject: [PATCH] TAChart: Initial support for rotated series. Works correctly for point/line series only. git-svn-id: trunk@24080 - --- components/tachart/tacustomseries.pas | 29 +++++++++++++++++++++++++++ components/tachart/tagraph.pas | 9 ++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index 779df158de..301bc9f3fd 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -40,6 +40,7 @@ type procedure SetAxisIndexY(AValue: Integer); protected + procedure GetGraphBounds(out ABounds: TDoubleRect); override; procedure SetActive(AValue: Boolean); override; procedure SetDepth(AValue: TChartDistance); override; procedure SetShowInLegend(AValue: Boolean); override; @@ -53,6 +54,8 @@ type function GraphToAxisX(AX: Double): Double; override; function GraphToAxisY(AY: Double): Double; override; + function IsRotated: Boolean; + public constructor Create(AOwner: TComponent); override; property AxisIndexX: Integer read FAxisIndexX write SetAxisIndexX default DEF_AXIS_INDEX; @@ -199,6 +202,21 @@ begin FAxisIndexY := DEF_AXIS_INDEX; end; +procedure TCustomChartSeries.GetGraphBounds(out ABounds: TDoubleRect); +begin + GetBounds(ABounds); + with ABounds do begin + a.X := AxisToGraphX(a.X); + a.Y := AxisToGraphY(a.Y); + b.X := AxisToGraphX(b.X); + b.Y := AxisToGraphY(b.Y); + if IsRotated then begin + Exchange(a.X, a.Y); + Exchange(b.X, b.Y); + end; + end; +end; + function TCustomChartSeries.GraphToAxisX(AX: Double): Double; begin Result := TransformationByAxis(FChart, AxisIndexX).GraphToAxis(AX) @@ -209,6 +227,15 @@ begin Result := TransformationByAxis(FChart, AxisIndexY).GraphToAxis(AY) end; +function TCustomChartSeries.IsRotated: Boolean; +const + VERTICAL = [calLeft, calRight]; +begin + Result := + (AxisIndexX >= 0) and (FChart.AxisList[AxisIndexX].Alignment in VERTICAL) and + (AxisIndexY >= 0) and not (FChart.AxisList[AxisIndexY].Alignment in VERTICAL); +end; + procedure TCustomChartSeries.SetActive(AValue: Boolean); begin if FActive = AValue then exit; @@ -387,6 +414,8 @@ begin Result.X := AxisToGraphX(X); Result.Y := AxisToGraphY(Y); end; + if IsRotated then + Exchange(Result.X, Result.Y); end; function TChartSeries.GetGraphPointX(AIndex: Integer): Double; diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 2dbb893151..d5984150f2 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -56,6 +56,7 @@ type procedure AfterDraw; virtual; procedure BeforeDraw; virtual; procedure GetBounds(out ABounds: TDoubleRect); virtual; abstract; + procedure GetGraphBounds(out ABounds: TDoubleRect); virtual; abstract; procedure GetLegendItems(AItems: TChartLegendItems); virtual; abstract; function GetNearestPoint( ADistFunc: TPointDistFunc; const APoint: TPoint; @@ -1074,13 +1075,7 @@ begin s := Series[i]; if not s.Active then continue; seriesBounds := EmptyExtent; - s.GetBounds(seriesBounds); - with seriesBounds do begin - a.X := s.AxisToGraphX(a.X); - a.Y := s.AxisToGraphY(a.Y); - b.X := s.AxisToGraphX(b.X); - b.Y := s.AxisToGraphY(b.Y); - end; + s.GetGraphBounds(seriesBounds); with FCurrentExtent do begin a.X := Min(a.X, seriesBounds.a.X); b.X := Max(b.X, seriesBounds.b.X);