TAChart: Make LogicalExtent settable property as a more general replacement for Pan method

git-svn-id: trunk@24350 -
This commit is contained in:
ask 2010-04-01 12:59:11 +00:00
parent fafe56406f
commit 8cc81d308a
2 changed files with 21 additions and 19 deletions

View File

@ -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);

View File

@ -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);