From 8cc81d308aa68dffc0e9a89eb836167f07667192 Mon Sep 17 00:00:00 2001 From: ask Date: Thu, 1 Apr 2010 12:59:11 +0000 Subject: [PATCH] TAChart: Make LogicalExtent settable property as a more general replacement for Pan method git-svn-id: trunk@24350 - --- components/tachart/tagraph.pas | 28 +++++++++++----------------- components/tachart/tatools.pas | 12 ++++++++++-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 1976f477c5..27d98b3c6d 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -147,6 +147,7 @@ type FFrame: TChartPen; FGraphBrush: TBrush; FLegend: TChartLegend; + FLogicalExtent: TDoubleRect; FMargins: TChartMargins; FOnDrawReticule: TDrawReticuleEvent; FSeries: TChartSeriesList; @@ -159,7 +160,6 @@ type FClipRect: TRect; FCurrentExtent: TDoubleRect; FIsZoomed: Boolean; - FLogicalExtent: TDoubleRect; FOffset: TDoublePoint; // Coordinates transformation FReticuleMode: TReticuleMode; FReticulePos: TPoint; @@ -185,6 +185,7 @@ type procedure SetFrame(Value: TChartPen); procedure SetGraphBrush(Value: TBrush); procedure SetLegend(Value: TChartLegend); + procedure SetLogicalExtent(const AValue: TDoubleRect); procedure SetMargins(AValue: TChartMargins); procedure SetReticuleMode(const AValue: TReticuleMode); procedure SetReticulePos(const AValue: TPoint); @@ -228,7 +229,6 @@ type procedure CopyToClipboardBitmap; procedure DeleteSeries(ASeries: TBasicChartSeries); procedure PaintOnCanvas(ACanvas: TCanvas; ARect: TRect); - procedure Pan(const ADelta: TPoint); procedure SaveToBitmapFile(const AFileName: String); inline; procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String); function SaveToImage(AClass: TRasterImageClass): TRasterImage; @@ -249,6 +249,7 @@ type property ChartWidth: Integer read GetChartWidth; property ClipRect: TRect read FClipRect; property CurrentExtent: TDoubleRect read FCurrentExtent; + property LogicalExtent: TDoubleRect read FLogicalExtent write SetLogicalExtent; property ReticulePos: TPoint read FReticulePos write SetReticulePos; property SeriesCount: Integer read GetSeriesCount; property XGraphMax: Double read FCurrentExtent.b.X; @@ -481,21 +482,6 @@ begin Series[i].AfterDraw; end; -procedure TChart.Pan(const ADelta: TPoint); -var - d: TDoublePoint; -begin - d.X := -ADelta.X / FScale.X; - d.Y := -ADelta.Y / FScale.Y; - with FLogicalExtent do begin - a += d; - b += d; - end; - FIsZoomed := true; - FCurrentExtent := FLogicalExtent; - Invalidate; -end; - procedure TChart.PrepareLegend( ACanvas: TCanvas; out ALegendItems: TChartLegendItems; out ARect: TRect); var @@ -914,6 +900,14 @@ begin Invalidate; end; +procedure TChart.SetLogicalExtent(const AValue: TDoubleRect); +begin + FLogicalExtent := AValue; + FIsZoomed := true; + FCurrentExtent := FLogicalExtent; + Invalidate; +end; + procedure TChart.SetMargins(AValue: TChartMargins); begin FMargins.Assign(AValue); diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index b65d6c2a22..8bdbd86dc5 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -610,14 +610,22 @@ end; procedure TPanDragTool.MouseMove(APoint: TPoint); var d: TPoint; + dd: TDoublePoint; + ext: TDoubleRect; begin d := APoint - FOrigin; + FOrigin := APoint; + if not (pdLeft in Directions) then d.X := Max(d.X, 0); if not (pdRight in Directions) then d.X := Min(d.X, 0); if not (pdUp in Directions) then d.Y := Max(d.Y, 0); if not (pdDown in Directions) then d.Y := Min(d.Y, 0); - FChart.Pan(d); - FOrigin := APoint; + + dd := FChart.ImageToGraph(d) - FChart.ImageToGraph(Point(0, 0)); + ext := FChart.LogicalExtent; + ext.a += dd; + ext.b += dd; + FChart.LogicalExtent := ext; end; procedure TPanDragTool.MouseUp(APoint: TPoint);