diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 7a84d8dd25..6417d26d94 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -192,7 +192,7 @@ procedure UpdateMinMax(AValue: Double; var AMin, AMax: Double); operator +(const A: TPoint; B: TSize): TPoint; overload; inline; operator +(const A, B: TPoint): TPoint; overload; inline; operator +(const A, B: TDoublePoint): TDoublePoint; overload; inline; -operator - (const A, B: TPoint): TPoint; overload; inline; +operator -(const A, B: TPoint): TPoint; overload; inline; operator -(const A, B: TDoublePoint): TDoublePoint; overload; inline; operator =(const A, B: TMethod): Boolean; overload; inline; diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 27d98b3c6d..90e870d6d4 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -100,9 +100,9 @@ type strict protected FChart: TChart; - function Index: Integer; virtual; abstract; procedure Activate; virtual; procedure Deactivate; virtual; + function Index: Integer; virtual; abstract; end; TChartToolEventId = (evidMouseDown, evidMouseMove, evidMouseUp); @@ -173,6 +173,7 @@ type function GetMargins(ACanvas: TCanvas): TRect; function GetSeriesCount: Integer; function GetToolset: TBasicChartToolset; + procedure HideReticule; procedure SetAxis(AIndex: Integer; AValue: TChartAxis); procedure SetAxisList(AValue: TChartAxisList); @@ -233,8 +234,6 @@ type procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String); function SaveToImage(AClass: TRasterImageClass): TRasterImage; procedure ZoomFull; - procedure ZoomToRect(const ARect: TRect); - public // Coordinate conversion function GraphToImage(const AGraphPoint: TDoublePoint): TPoint; function ImageToGraph(const APoint: TPoint): TDoublePoint; @@ -501,6 +500,12 @@ begin end; end; +procedure TChart.HideReticule; +begin + // Hide reticule - - it will be drawn again in the next MouseMove. + FReticulePos := Point( - 1, - 1); +end; + procedure TChart.CalculateTransformationCoeffs(const AMargin: TRect); type TConvFunc = function (AX: Integer): Double of object; @@ -902,6 +907,7 @@ end; procedure TChart.SetLogicalExtent(const AValue: TDoubleRect); begin + HideReticule; FLogicalExtent := AValue; FIsZoomed := true; FCurrentExtent := FLogicalExtent; @@ -1050,34 +1056,12 @@ end; procedure TChart.ZoomFull; begin + if not FIsZoomed then exit; + HideReticule; FIsZoomed := false; Invalidate; end; -procedure TChart.ZoomToRect(const ARect: TRect); -var - oldIsZoomed: Boolean; -begin - oldIsZoomed := FIsZoomed; - with ARect do - FIsZoomed := (Left < Right) and (Top < Bottom); - if FIsZoomed then - with FCurrentExtent do begin - a := ImageToGraph(ARect.TopLeft); - b := ImageToGraph(ARect.BottomRight); - if a.X > b.X then - Exchange(a.X, b.X); - if a.Y > b.Y then - Exchange(a.Y, b.Y); - end; - - if FIsZoomed or oldIsZoomed then begin - // Hide reticule -- it will be drawn again in the next MouseMove. - FReticulePos := Point(-1, -1); - Invalidate; - end; -end; - { TBasicChartSeries } procedure TBasicChartSeries.AfterAdd; diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index b90d0616f6..349e3412cb 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -523,14 +523,29 @@ begin end; procedure TZoomDragTool.MouseUp(APoint: TPoint); +var + ext: TDoubleRect; begin Unused(APoint); Deactivate; - with FChart do begin - PrepareXorPen(Canvas); - Canvas.Rectangle(FSelectionRect); - ZoomToRect(FSelectionRect); + + PrepareXorPen(FChart.Canvas); + FChart.Canvas.Rectangle(FSelectionRect); + with FSelectionRect do begin + if (Left >= Right) or (Top >= Bottom) then begin + FChart.ZoomFull; + exit; + end; + ext.a := FChart.ImageToGraph(TopLeft); + ext.b := FChart.ImageToGraph(BottomRight); end; + with ext do begin + if a.X > b.X then + Exchange(a.X, b.X); + if a.Y > b.Y then + Exchange(a.Y, b.Y); + end; + FChart.LogicalExtent := ext; end; { TReticuleTool }