diff --git a/components/tachart/demo/tools/main.lfm b/components/tachart/demo/tools/main.lfm index a7e5ae1ff0..86dc0d9ab4 100644 --- a/components/tachart/demo/tools/main.lfm +++ b/components/tachart/demo/tools/main.lfm @@ -1,20 +1,20 @@ object Form1: TForm1 Left = 292 - Height = 475 + Height = 484 Top = 152 Width = 554 Caption = 'Form1' - ClientHeight = 475 + ClientHeight = 484 ClientWidth = 554 LCLVersion = '0.9.29' object Chart1: TChart Left = 0 - Height = 371 + Height = 368 Top = 0 Width = 554 AxisList = < item - Alignment = calLeft + Title.LabelFont.Orientation = 900 Title.Font.Orientation = 900 end item @@ -69,16 +69,16 @@ object Form1: TForm1 end object Panel1: TPanel Left = 0 - Height = 78 - Top = 371 + Height = 90 + Top = 368 Width = 554 Align = alBottom - ClientHeight = 78 + ClientHeight = 90 ClientWidth = 554 TabOrder = 1 object rgZoom: TRadioGroup Left = 1 - Height = 76 + Height = 88 Top = 1 Width = 255 Align = alLeft @@ -92,7 +92,7 @@ object Form1: TForm1 ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 1 - ClientHeight = 58 + ClientHeight = 70 ClientWidth = 251 ItemIndex = 2 Items.Strings = ( @@ -102,10 +102,19 @@ object Form1: TForm1 ) OnClick = rgZoomClick TabOrder = 0 + object cbFixedPoint: TCheckBox + Left = 6 + Height = 15 + Top = 49 + Width = 239 + Caption = 'Fixed point' + OnChange = cbFixedPointChange + TabOrder = 4 + end end object rgPan: TRadioGroup Left = 256 - Height = 76 + Height = 88 Top = 1 Width = 292 Align = alLeft @@ -119,7 +128,7 @@ object Form1: TForm1 ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 1 - ClientHeight = 58 + ClientHeight = 70 ClientWidth = 288 ItemIndex = 0 Items.Strings = ( @@ -133,7 +142,7 @@ object Form1: TForm1 object Panel2: TPanel Left = 0 Height = 26 - Top = 449 + Top = 458 Width = 554 Align = alBottom Caption = 'Press Ctrl to activate reticlue, Alt-drag to move vertical lines' diff --git a/components/tachart/demo/tools/main.pas b/components/tachart/demo/tools/main.pas index 716f5d01c6..b42359f7e5 100644 --- a/components/tachart/demo/tools/main.pas +++ b/components/tachart/demo/tools/main.pas @@ -5,7 +5,7 @@ unit main; interface uses - Classes, ExtCtrls, SysUtils, FileUtil, LResources, Forms, Controls, + Classes, ExtCtrls, StdCtrls, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Types, TAGraph, TASeries, TASources, TATools; type @@ -27,11 +27,13 @@ type ChartToolset1ZoomDragTool1: TZoomDragTool; ChartToolset1ZoomOut: TZoomClickTool; ChartToolset1ZoomIn: TZoomClickTool; + cbFixedPoint: TCheckBox; Panel1: TPanel; Panel2: TPanel; rgZoom: TRadioGroup; RandomChartSource1: TRandomChartSource; rgPan: TRadioGroup; + procedure cbFixedPointChange(Sender: TObject); procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double); procedure ChartToolset1DataPointDragTool1BeforeMouseMove(ATool: TChartTool; APoint: TPoint); @@ -48,6 +50,12 @@ implementation { TForm1 } +procedure TForm1.cbFixedPointChange(Sender: TObject); +begin + ChartToolset1ZoomIn.FixedPoint := cbFixedPoint.Checked; + ChartToolset1ZoomOut.FixedPoint := cbFixedPoint.Checked; +end; + procedure TForm1.Chart1FuncSeries1Calculate(const AX: Double; out AY: Double); begin AY := Sin(AX * 10) + 0.7 * Cos(AX * 30) + 0.3 * Sin(AX * 80); diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 445d0ec5b0..1f7993693e 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -262,6 +262,8 @@ operator -(const A, B: TPoint): TPoint; overload; inline; operator -(const A, B: TDoublePoint): TDoublePoint; overload; inline; operator div(const A: TPoint; ADivisor: Integer): TPoint; inline; operator *(const A: TPoint; AMultiplier: Integer): TPoint; inline; +operator *(const A, B: TDoublePoint): TDoublePoint; overload; inline; +operator /(const A, B: TDoublePoint): TDoublePoint; overload; inline; operator =(const A, B: TMethod): Boolean; overload; inline; operator :=(const APoint: TPoint): TSize; inline; @@ -748,6 +750,18 @@ begin Result.Y := A.Y * AMultiplier; end; +operator * (const A, B: TDoublePoint): TDoublePoint; +begin + Result.X := A.X * B.X; + Result.Y := A.Y * B.Y; +end; + +operator / (const A, B: TDoublePoint): TDoublePoint; +begin + Result.X := A.X / B.X; + Result.Y := A.Y / B.Y; +end; + operator = (const A, B: TMethod): Boolean; begin Result := (A.Code = B.Code) and (A.Data = B.Data); diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index 035773ce5c..c9e62a1423 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -723,7 +723,7 @@ end; procedure TZoomClickTool.MouseDown(APoint: TPoint); var - sz, center, ratio: TDoublePoint; + sz, center, ratio, zoom: TDoublePoint; ext: TDoubleRect; begin if ZoomFactor <= 0 then exit; @@ -731,14 +731,12 @@ begin center := FChart.ImageToGraph(APoint); sz := ext.b - ext.a; if FixedPoint then - with center - ext.a do - ratio := DoublePoint(X / sz.X, Y / sz.Y) + ratio := (center - ext.a) / sz else - ratio := DoublePoint(0.5, 0.5); - ext.a.X := center.X - sz.X * ratio.X / ZoomFactor; - ext.a.Y := center.Y - sz.Y * ratio.Y / (ZoomFactor * ZoomRatio); - ext.b.X := center.X + sz.X * (1 - ratio.X) / ZoomFactor; - ext.b.Y := center.Y + sz.Y * (1 - ratio.Y) / (ZoomFactor * ZoomRatio); + ratio := DoublePoint(0.5, 0.5); + zoom := DoublePoint(ZoomFactor, ZoomFactor * ZoomRatio); + ext.a := center - sz * ratio / zoom; + ext.b := center + sz * (DoublePoint(1, 1) - ratio) / zoom; FChart.LogicalExtent := ext; Handled; end;