barryd

TeeCharts (Delphi) Selection Tool

Sep 6th, 2016
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 18.11 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. {$IFDEF MSWINDOWS}
  7.   WinApi.Windows, WinApi.Messages,
  8. {$ENDIF}
  9.   System.SysUtils, System.Types, System.UITypes, System.UIConsts, System.Classes,
  10.   System.Variants, System.JSON, System.IOUtils, System.Math, System.Rtti,
  11.   FMX.Types, FMX.Controls, FMX.Objects, FMX.Forms, FMX.Layouts, FMX.Menus,
  12.   FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Styles.Objects,
  13.   FMX.Controls.Presentation, FMX.Edit, FMX.ScrollBox, FMX.Memo,
  14.   FMXTee.Engine, FMXTee.Procs, FMXTee.Chart, FMXTee.Series, FMXTee.Tools,
  15.   FMXTee.Tools.SubChart, unFileMapping;
  16.  
  17. type
  18.   TDataStruct = Record
  19.     deviceId : Integer;
  20.     datetime : TDateTime;
  21.     field0 : Integer;
  22.     field1 : Single;
  23.     field2 : Single;
  24.     field3 : Single;
  25.     field4 : SmallInt;
  26.   end;
  27.  
  28. type
  29.   TDataStructArray = array[0..MaxInt div SizeOf(TDataStruct) - 1] of TDataStruct;
  30.   PDataStructArray = ^TDataStructArray;
  31.  
  32. type
  33.   TForm1 = class(TForm)
  34.     FramedVertScrollBox1: TFramedVertScrollBox;
  35.  
  36.     Chart1: TChart;
  37.     Chart1Series0: TFastLineSeries;
  38.     Chart1Series1: TFastLineSeries;
  39.     Chart1Series2: TFastLineSeries;
  40.  
  41.     Chart2: TChart;
  42.     Chart2Series0: TFastLineSeries;
  43.     Chart2Series1: TFastLineSeries;
  44.  
  45.     Chart3: TChart;
  46.     Chart3Series0: TFastLineSeries;
  47.     Chart3Series1: TFastLineSeries;
  48.  
  49.     Chart4: TChart;
  50.     Chart4Series0: TFastLineSeries;
  51.  
  52.     Chart5: TChart;
  53.     Series1b: TFastLineSeries;
  54.     Series2b: TFastLineSeries;
  55.     Series3b: TFastLineSeries;
  56.  
  57.     Label1: TLabel;
  58.     Label2: TLabel;
  59.     Label3: TLabel;
  60.     Label4: TLabel;
  61.     Label5: TLabel;
  62.     Label6: TLabel;
  63.     Label7: TLabel;
  64.     ScrollBar1: TScrollBar;
  65.     Button1: TButton;
  66.     Button2: TButton;
  67.     Button3: TButton;
  68.     Button4: TButton;
  69.  
  70.     procedure FormCreate(Sender: TObject);
  71.  
  72.     procedure RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
  73.  
  74.     procedure Chart1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
  75.       Shift: TShiftState);
  76.  
  77.     procedure ScrollBar1Change(Sender: TObject);
  78.  
  79.     procedure Chart1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
  80.  
  81.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  82.       Y: Single);
  83.     procedure Chart5MouseMove(Sender: TObject; Shift: TShiftState; X,
  84.       Y: Single);
  85.     procedure Chart5MouseDown(Sender: TObject; Button: TMouseButton;
  86.       Shift: TShiftState; X, Y: Single);
  87.  
  88.   private
  89.     { Private declarations }
  90.     sbIncremental: Single;
  91.     FDragging: boolean;
  92.   public
  93.     { Public declarations }
  94.   end;
  95.  
  96. var
  97.   Form1: TForm1;
  98.   seleRectChart1 : TRectangleTool;
  99.   seleRectChart2 : TRectangleTool;
  100.   seleRectChart3 : TRectangleTool;
  101.   seleRectChart4 : TRectangleTool;
  102.   seleRectChart5 : TRectangleTool;
  103.   DataFile : TMappedFile;
  104.   Datas: PDataStructArray;
  105.  
  106.   FDragging: boolean;
  107.   DifX, DifY: Integer;
  108.   OrigXPos: Integer;
  109.  
  110. implementation
  111.  
  112. {$R *.fmx}
  113.  
  114. procedure TForm1.FormCreate(Sender: TObject);
  115. begin
  116.   DataFile := TMappedFile.Create(ExpandFileName(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + '..\..')) + 'TeeChart.dat');
  117.   sbIncremental := -256;
  118.   Form1.Position := TFormPosition.ScreenCenter; //poScreenCenter
  119.   ScrollBar1.Max := 10;
  120.   ScrollBar1.Min := -10;
  121.   ScrollBar1.Value := 0;
  122.  
  123.   With Chart1 do begin
  124.     Color := TAlphaColors.Black;
  125.     Title.Caption := ''; //.Text.Strings
  126.     AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
  127.     Axes.Bottom.Automatic := False;
  128.     Axes.Bottom.Maximum := 250;
  129.     Axes.Bottom.Minimum := 2;
  130.     LeftAxis.Automatic := True;
  131.     LeftAxis.AutomaticMaximum := True;
  132.     LeftAxis.AutomaticMinimum := True;
  133.     LeftAxis.AxisValuesFormat := '#,##0.#';
  134.     LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Red; //xFFCF3F3F;
  135.     LeftAxis.Maximum := 42.500000000000000000;
  136.     LeftAxis.Minimum := -0.500000000000000000;
  137.     LeftAxis.Title.Caption := 'Chart1';
  138.     LeftAxis.Title.Font.Color := TAlphaColors.Red; //claRed RGB(256, 0, 0)
  139.     LeftAxis.Title.Font.Brush.Color := TAlphaColors.Red; //TColor($FFFFFF) claRed
  140.     Zoom.Allow := True;
  141.   end;
  142.  
  143.   seleRectChart1 := TRectangleTool.Create(self);
  144.   Chart1.Tools.Add(seleRectChart1);
  145.   with (Chart1.Tools[0] as TRectangleTool) do //
  146.   begin
  147.     Text := 'Rectangle Tool 1';
  148.     AllowDrag := False;
  149.     AutoSize := True;
  150.     Shape.Color := $00FFFFFF;
  151.     Shape.Font.Color := TAlphaColors.Green;
  152.     Shape.Pen.Color := TAlphaColors.Red;
  153.     Shape.Transparency := 0;
  154.     Left := 100; // 55 (Sender as TChart).Zoom.X0  100;
  155.     Top := 5; //   (Sender as TChart).Zoom.Y0  75;
  156.     Width := 50; //Round((Sender as TChart).Zoom.X1 - (Sender as TChart).Zoom.X0 )  Chart5.Width Zoom.X1
  157.     Height := Round(Chart1.Height - 10);  //Zoom.Y1
  158.     OnClick := RectClick;
  159.     OnKeyDown := Chart1KeyDown;
  160.   end;
  161.  
  162.   With Chart2 do begin
  163.     Color := TAlphaColors.Black;
  164.     Title.Caption := '';
  165.     AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
  166.     Axes.Bottom.Automatic := False;
  167.     Axes.Bottom.Maximum := 250;
  168.     Axes.Bottom.Minimum := 2;
  169.     LeftAxis.Automatic := True;
  170.     LeftAxis.AutomaticMaximum := True;
  171.     LeftAxis.AutomaticMinimum := True;
  172.     LeftAxis.AxisValuesFormat := '#,##0.#';
  173.     LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Blue;
  174.     LeftAxis.Maximum := 99.500000000000000000;
  175.     LeftAxis.Minimum := -0.500000000000000000;
  176.     LeftAxis.Title.Caption := 'Chart2'; // ยตS / uS
  177.     LeftAxis.Title.Font.Color := TAlphaColors.Blue; //00FACE87 claLightskyblue RGB(256, 0, 0)
  178.     LeftAxis.Title.Font.Brush.Color := TAlphaColors.Blue; //claLightskyblue
  179.     Zoom.Allow := True;
  180.   end;
  181.  
  182.   seleRectChart2 := TRectangleTool.Create(self);
  183.   Chart2.Tools.Add(seleRectChart2);
  184.   with (Chart2.Tools[0] as TRectangleTool) do
  185.   begin
  186.     Text := 'Rectangle Tool 2';
  187.     AllowDrag := False;
  188.     AutoSize := True;
  189.     Shape.Color := $00FFFFFF;
  190.     Shape.Font.Color := TAlphaColors.Green;
  191.     Shape.Pen.Color := TAlphaColors.Blue;
  192.     Shape.Transparency := 0;
  193.     Left := 100; // Chart2.Zoom.X0  100;
  194.     Top := 5; // Chart2.Zoom.Y0 75;
  195.     Width := 50; //Round(Chart2.Width - 76); // Chart2.Zoom.X1
  196.     Height := Round(Chart2.Height - 10); // Chart2.Zoom.Y1
  197.     //Shape.Brush.Style := bsClear;
  198.     OnClick := RectClick;
  199.     OnKeyDown := Chart1KeyDown;
  200.   end;
  201.  
  202.   With Chart3 do begin
  203.     Color := TAlphaColors.Black;
  204.     Title.Caption := '';
  205.     AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
  206.     Axes.Bottom.Automatic := False;
  207.     Axes.Bottom.Maximum := 250;
  208.     Axes.Bottom.Minimum := 2;
  209.     LeftAxis.Automatic := True;
  210.     LeftAxis.AutomaticMaximum := True;
  211.     LeftAxis.AutomaticMinimum := True;
  212.     LeftAxis.AxisValuesFormat := '#,##0.#';
  213.     LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Green;
  214.     LeftAxis.Maximum := 12.500000000000000000;
  215.     LeftAxis.Minimum := -0.500000000000000000;
  216.     LeftAxis.Title.Caption := 'Chart3'; // lb
  217.     LeftAxis.Title.Font.Color := TAlphaColors.Green; //00FACE87 claLightskyblue RGB(256, 0, 0)
  218.     LeftAxis.Title.Font.Brush.Color := TAlphaColors.Green; //claLightskyblue
  219.     Zoom.Allow := True;
  220.   end;
  221.  
  222.   seleRectChart3 := TRectangleTool.Create(self);
  223.   Chart3.Tools.Add(seleRectChart3);
  224.   with (Chart3.Tools[0] as TRectangleTool) do
  225.   begin
  226.     Text := 'Rectangle Tool 3';
  227.     AllowDrag := False;
  228.     AutoSize := True;
  229.     Shape.Color := $00FFFFFF;
  230.     Shape.Font.Color := TAlphaColors.Green;
  231.     Shape.Pen.Color := TAlphaColors.Green;
  232.     Shape.Transparency := 0;
  233.     Left := 100; //  (Sender as TChart).Zoom.X0  100;
  234.     Top := 5; //   (Sender as TChart).Zoom.Y0  75;
  235.     Width := 50; // Round(Chart3.Width - 76); //Zoom.X1
  236.     Height := Round(Chart3.Height - 10);  //Zoom.Y1
  237.     //Shape.Brush.Style := bsClear;
  238.     OnClick := RectClick;
  239.     OnKeyDown := Chart1KeyDown;
  240.   end;
  241.  
  242.   With Chart4 do begin
  243.     Color := TAlphaColors.Black;
  244.     Title.Caption := '';
  245.     AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
  246.     Axes.Bottom.Automatic := False;
  247.     Axes.Bottom.Maximum := 250;
  248.     Axes.Bottom.Minimum := 2;
  249.     LeftAxis.Automatic := True;
  250.     LeftAxis.AutomaticMaximum := True;
  251.     LeftAxis.AutomaticMinimum := True;
  252.     LeftAxis.AxisValuesFormat := '#,##0.#';
  253.     LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Purple;
  254.     LeftAxis.Maximum := 12.500000000000000000;
  255.     LeftAxis.Minimum := -0.500000000000000000;
  256.     LeftAxis.Title.Caption := 'Chart4';
  257.     LeftAxis.Title.Font.Color := TAlphaColors.Purple; //00FACE87 claLightskyblue RGB(256, 0, 0)
  258.     LeftAxis.Title.Font.Brush.Color := TAlphaColors.Purple; //claLightskyblue
  259.     Zoom.Allow := True;
  260.   end;
  261.  
  262.   seleRectChart4 := TRectangleTool.Create(self);
  263.   Chart4.Tools.Add(seleRectChart4);
  264.   with (Chart4.Tools[0] as TRectangleTool) do
  265.   begin
  266.     Text := 'Rectangle Tool 4';
  267.     AllowDrag := False;
  268.     AutoSize := True;
  269.     Shape.Color := $00FFFFFF;
  270.     Shape.Font.Color := TAlphaColors.Green;
  271.     Shape.Pen.Color := TAlphaColors.Purple;
  272.     Shape.Transparency := 0;
  273.     Left := 100; //  (Sender as TChart).Zoom.X0  100;
  274.     Top := 5; //   (Sender as TChart).Zoom.Y0  75;
  275.     Width := 50; //Round(Chart4.Width - 76); //Zoom.X1
  276.     Height := Round(Chart4.Height - 10);  //Zoom.Y1
  277.     OnClick := RectClick;
  278.     OnKeyDown := Chart1KeyDown;
  279.   end;
  280.  
  281.   With Chart5 do begin
  282.     Color := TAlphaColors.White;
  283.     Title.Caption := '';
  284.     AllowPanning := pmHorizontal; //permit manual scrolling horizontally only.
  285.     Axes.Bottom.Automatic := True;
  286.     Axes.Bottom.Maximum := 250;
  287.     Axes.Bottom.Minimum := 2;
  288.     LeftAxis.Automatic := True;
  289.     LeftAxis.AutomaticMaximum := True;
  290.     LeftAxis.AutomaticMinimum := True;
  291.     LeftAxis.AxisValuesFormat := '#,##0.#';
  292.     LeftAxis.LabelsFormat.Font.Color := TAlphaColors.Black;
  293.     LeftAxis.Maximum := 12.500000000000000000;
  294.     LeftAxis.Minimum := -0.500000000000000000;
  295.     LeftAxis.Title.Caption := 'Chart5';
  296.     LeftAxis.Title.Font.Color := TAlphaColors.Black; //00FACE87 claLightskyblue RGB(256, 0, 0)
  297.     LeftAxis.Title.Font.Brush.Color := TAlphaColors.Black; //claLightskyblue
  298.     Zoom.Allow := True;
  299.   end;
  300.  
  301.   ScrollBar1.BeginUpdate;
  302.   ScrollBar1.Value := -1;
  303.   ScrollBar1.EndUpdate;
  304.   ScrollBar1.Repaint;
  305. end;
  306.  
  307. procedure TForm1.RectClick(Sender:TAnnotationTool; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  308. begin
  309.   if Button=TMouseButton.mbRight then
  310.   begin
  311.     with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  312.     begin
  313.       Text:=Sender.Text + ' (twin)';
  314.  
  315.       AutoSize:=Sender.AutoSize;
  316.       Shape.Color := Sender.Shape.Color;
  317.       Shape.Transparency:=Sender.Shape.Transparency;
  318.       Top:=Sender.Top+Sender.Height;
  319.       Left:=Sender.Left;
  320.       OnClick:=RectClick;
  321.     end;
  322.   end else if Button=TMouseButton.mbLeft then
  323.   begin
  324. {
  325.     if Assigned(selectedRect) then
  326.        selectedRect.Shape.Pen.Color:=TAlphaColors.Black;
  327.  
  328.     selectedRect:=Sender as TRectangleTool;
  329.     selectedRect.Shape.Pen.Color:=TAlphaColors.Red;
  330. }
  331.   end;
  332. end;
  333.  
  334. procedure TForm1.Chart1KeyDown(Sender: TObject; var Key: Word;
  335.   var KeyChar: Char; Shift: TShiftState);
  336. begin
  337.   if Key=VK_DELETE then
  338.     if seleRectChart1 <> nil then
  339.     begin
  340.       Chart1.Tools.Remove(seleRectChart1);
  341.       Chart1.Repaint;
  342.     end;
  343. end;
  344.  
  345. procedure TForm1.ScrollBar1Change(Sender: TObject);
  346. var
  347.   sb: TScrollBar;
  348.   sbOnChange: TNotifyEvent;
  349.   i: Integer;
  350. begin
  351.   sb := (Sender as TScrollBar);
  352.  
  353.   Chart1Series0.Clear;
  354.   Chart1Series1.Clear;
  355.   Chart1Series2.Clear;
  356.  
  357.   Chart2Series0.Clear;
  358.   Chart2Series1.Clear;
  359.  
  360.   Chart3Series0.Clear;
  361.   Chart3Series1.Clear;
  362.  
  363.   Chart4Series0.Clear;
  364.   Series1b.Clear;
  365.   Series2b.Clear;
  366.   Series3b.Clear;
  367.  
  368.   Chart1.UndoZoom;
  369.   Chart2.UndoZoom;
  370.   Chart3.UndoZoom;
  371.   Chart4.UndoZoom;
  372.   Chart5.UndoZoom;
  373.  
  374.   try
  375.  
  376.     if DataFile = nil then
  377.       DataFile := TMappedFile.Create(ExpandFileName(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)) + '..\..')) + 'TeeChart.dat');
  378.  
  379.     Datas := PDataStructArray(DataFile.Content); // not needed, but handy
  380.  
  381.     if (DataFile.Size div SizeOf(TDataStruct) - 1 + Round(sbIncremental)) >= 0 then begin
  382.       for i := (DataFile.Size div SizeOf(TDataStruct) - 1 + Round(sbIncremental)) to DataFile.Size div SizeOf(TDataStruct) - 1 do begin
  383.         if (DataFile.Size div SizeOf(TDataStruct) - 1) <> 1 then begin
  384.  
  385.           Chart1Series0.AddY(Datas[i].field1);
  386.           Series1b.AddY(Round(Datas[i].field1));
  387.           Chart2Series0.AddY(Round(Datas[i].field2));
  388.           Series2b.AddY(Round(Datas[i].field2));
  389.           Chart3Series0.AddY(Round(Datas[i].field3));
  390.           Series3b.AddY(Round(Datas[i].field3));
  391.           Chart4Series0.AddY(Datas[i].field4);
  392.  
  393.         end;
  394.       end;
  395.       sbIncremental := sbIncremental + sb.Value;
  396.     end else
  397.       sbIncremental := -abs(DataFile.Size div SizeOf(TDataStruct) - 1);
  398.  
  399.   finally
  400.     //DataFile.Free;
  401.   end;
  402.  
  403.   sbOnChange := sb.OnChange; // Disable OnChange event
  404.   sb.OnChange := nil;         // -"-
  405. //  sb.Value := (sb.Min + sb.Max) / 2; // Reset position
  406.   sb.OnChange := sbOnChange; // Re-enable OnChange event
  407.  
  408.   Label2.Text := FloatToStr(sbIncremental);
  409.  
  410.   Label4.Text := IntToStr(Round(sbIncremental));
  411.  
  412.   FDragging := True;
  413.  
  414.   if sbIncremental < 0 then
  415.   begin
  416.     if FDragging then
  417.     begin
  418.       with (Chart1.Tools[0] as TRectangleTool) do
  419.       begin
  420.         Shape.Left := Round(DifX) - 1; //X-
  421.         Shape.Top := 0;
  422.         Shape.Width := Round(DifX) - 1;
  423.       end;
  424.  
  425.       with (Chart2.Tools[0] as TRectangleTool) do
  426.       begin
  427.         Shape.Left := Round(DifX) - 1; //X-
  428.         Shape.Top := 0;
  429.         Shape.Width := Round(DifX) - 1;
  430.       end;
  431.  
  432.       with (Chart3.Tools[0] as TRectangleTool) do
  433.       begin
  434.         Shape.Left := Round(DifX) - 1; //X-
  435.         Shape.Top := 0;
  436.         Shape.Width := Round(DifX) - 1;
  437.       end;
  438.  
  439.       with (Chart4.Tools[0] as TRectangleTool) do
  440.       begin
  441.         Shape.Left := Round(DifX) - 1; //X-
  442.         Shape.Top := 0;
  443.         Shape.Width := Round(DifX) - 1;
  444.       end;
  445.     end;
  446.   end;
  447.  
  448.   //FDragging := False;
  449.  
  450. end;
  451.  
  452. procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  453.   Shift: TShiftState; X, Y: Single);
  454. begin
  455.   FDragging := False;
  456. end;
  457.  
  458. procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  459.   Y: Single);
  460. var
  461.   SeriesIndex: Integer;
  462. begin
  463.   SeriesIndex := Chart1Series0.Clicked(X, Y);
  464.   Chart1.ShowHint := SeriesIndex <> -1;
  465.   if Chart1.ShowHint = True then  begin
  466.     Chart1.Hint := 'Y Axis: ' + FloatToStr(Chart1.LeftAxis.CalcPosPoint(Round(Y))); // SeriesIndex
  467.   end;
  468. end;
  469.  
  470. procedure TForm1.Chart5MouseMove(Sender: TObject; Shift: TShiftState; X,
  471.   Y: Single);
  472.  
  473. begin
  474.   if FDragging then
  475.   begin
  476.     with (Chart1.Tools[0] as TRectangleTool) do
  477.     begin
  478.       Shape.Top := 0+5;
  479.       //Was the Button is preesed
  480.       if GetKeyState(VK_LBUTTON) < 0 then
  481.       begin
  482.         DifX := Round(X-Shape.Left);
  483.         DifY := Round(Y-Shape.Top);
  484.         Shape.Left := OrigXPos; //Round(DifX)
  485.         Shape.Width := Round(DifX); //-X
  486.         Label5.Text := 'DifX: ' + IntToStr(Round(DifX));
  487.         Label6.Text := 'OrigXPos: ' + IntToStr(OrigXPos);
  488.         Label7.Text := 'X: ' + IntToStr(Round(X));
  489.         Repaint;
  490.       end;
  491.     end;
  492.  
  493.     with (Chart2.Tools[0] as TRectangleTool) do
  494.     begin
  495.       Shape.Top := 0+5;
  496.       //Was the Button is preesed
  497.       if GetKeyState(VK_LBUTTON) < 0 then
  498.       begin
  499.         DifX := Round(X-Shape.Left);
  500.         DifY := Round(Y-Shape.Top);
  501.         Shape.Left := OrigXPos; //Round(DifX)
  502.         Shape.Width := Round(DifX); //-X
  503.         Repaint;
  504.       end;
  505.     end;
  506.  
  507.     with (Chart3.Tools[0] as TRectangleTool) do
  508.     begin
  509.       Shape.Top := 0+5;
  510.       //Was the Button is preesed
  511.       if GetKeyState(VK_LBUTTON) < 0 then
  512.       begin
  513.         DifX := Round(X-Shape.Left);
  514.         DifY := Round(Y-Shape.Top);
  515.         Shape.Left := OrigXPos; //Round(DifX)
  516.         Shape.Width := Round(DifX); //-X
  517.         Repaint;
  518.       end;
  519.     end;
  520.  
  521.     with (Chart4.Tools[0] as TRectangleTool) do
  522.     begin
  523.       Shape.Top := 0+5;
  524.       //Was the Button is preesed
  525.       if GetKeyState(VK_LBUTTON) < 0 then
  526.       begin
  527.         DifX := Round(X-Shape.Left);
  528.         DifY := Round(Y-Shape.Top);
  529.         Shape.Left := OrigXPos; //Round(DifX)
  530.         Shape.Width := Round(DifX); //-X
  531.         Repaint;
  532.       end;
  533.     end;
  534.   end;
  535.  
  536. end;
  537.  
  538. procedure TForm1.Chart5MouseDown(Sender: TObject; Button: TMouseButton;
  539.   Shift: TShiftState; X, Y: Single);
  540. begin
  541. {
  542.   The following code disables the OnZoom event from executing the
  543.   function code. H/e it still continues to execute the zooming
  544.   feature through teecharts, making it pointless and useless,
  545.   unless the intent is to disable user-defined functions
  546.   for Chart5OnZoom(), then it works great!
  547. }
  548. //  cz: FMXTee.Chart.TChart; // TCustomChart  TTeeChart  FMXTee.Procs  TChart.Zoom
  549. //  czOnZoom: TNotifyEvent;
  550. //  ------
  551. //  cz := (Sender as FMXTee.Chart.TChart); //TChart  TCustomChart
  552. //  czOnZoom := cz.OnZoom; // Disable OnZoom event
  553. //  cz.OnZoom := nil;
  554. //  cz.OnZoom := czOnZoom; // Re-enable OnZoom event
  555.   with (Chart1.Tools[0] as TRectangleTool) do
  556.   //if Clicked(Round(X),Round(Y)) = True then
  557.   begin
  558.     DifX := Round(X-Shape.Left);
  559.     DifY := Round(Y-Shape.Top);
  560.     OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
  561.     //ShowMessage('OrigXPos: ' + IntToStr(OrigXPos));
  562.   end;
  563.  
  564.   with (Chart2.Tools[0] as TRectangleTool) do
  565.   //if Clicked(Round(X),Round(Y)) = True then
  566.   begin
  567.     DifX := Round(X-Shape.Left);
  568.     DifY := Round(Y-Shape.Top);
  569.     OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
  570.   end;
  571.  
  572.   with (Chart3.Tools[0] as TRectangleTool) do
  573.   //if Clicked(Round(X),Round(Y)) = True then
  574.   begin
  575.     DifX := Round(X-Shape.Left);
  576.     DifY := Round(Y-Shape.Top);
  577.     OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
  578.   end;
  579.  
  580.   with (Chart4.Tools[0] as TRectangleTool) do
  581.   //if Clicked(Round(X),Round(Y)) = True then
  582.   begin
  583.     DifX := Round(X-Shape.Left);
  584.     DifY := Round(Y-Shape.Top);
  585.     OrigXPos := Round(X); //Round(Chart1.Axes.Bottom.CalcPosPoint(Round(X)));
  586.   end;
  587.   FDragging := True;
  588. end;
  589. end.
Add Comment
Please, Sign In to add comment