TeeChart DragMark Tool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

TeeChart DragMark Tool

Post by restech » Mon Feb 12, 2018 2:54 pm

I am work in Rad Studio 10.1 Berlin with c++. Teechart version 2017.21

If i use DragMark tool and trying to move chart with right click, marks moves with their points. It's normal behavior for me.
But after i dragged any mark and trying to move chart with right click, dragged mark moving wich chart, ignoring it's point.

How can i avoid this movement? I just need the same behavior as before dragging mark.
You can see described behavior in your Teechart Pro Examples(Tee9new.exe) in DragMark tool section

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart DragMark Tool

Post by Yeray » Thu Feb 15, 2018 7:33 am

Hi Stainslaw,

Here you can find a workaround suggested for this.
http://www.teechart.net/support/viewtop ... ll*#p34033

Don't hesitate to let us know if you still have problems with it.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

Re: TeeChart DragMark Tool

Post by restech » Sun Feb 18, 2018 8:03 am

Thanks for your code.
But that event i can use for changing marks position then i dragging chart with right mouse?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart DragMark Tool

Post by Yeray » Mon Feb 19, 2018 12:01 pm

Hi,

Yes, the idea is to store the marks positions manually when you modify them with the DragMark tool, and apply these positions when you scroll the chart.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

Re: TeeChart DragMark Tool

Post by restech » Tue Feb 20, 2018 8:14 am

I just tried to store coordinates of marks relatively to the axis.
I did it in OnChartAfterDrawEvent:

Code: Select all

void __fastcall OnChartAfterDraw(TObject *Sender)
{
  MarksCoordinates.clear();
	if(Chart && __PointTextSeries)
	{
		for(int i = 0; i < __PointTextSeries->XValues->Count; i++)
		{
			pair<double, double> tmp;
			tmp.first = Chart->BottomAxis->CalcPosPoint(__PointTextSeries->Marks->Positions->Position[i]->LeftTop.X);
			tmp.second = Chart->LeftAxis->CalcPosPoint(__PointTextSeries->Marks->Positions->Position[i]->LeftTop.Y);
			MarksCoordinates.push_back(tmp);
		}
  }
}
Then in OnChartZoomIn and OnChartUndoZoom i tried to repaint marks on them positions, and it works fine BEFORE you drag any point. But after dragging it's works only for UndoZoomEvent. In ZoomIn marks coordinates different everytime i zoom it.
UndoZoom event:

Code: Select all

void __fastcall OnChartUndoZoom(TObject *Sender)
{
	if(__PointTextSeries)
	{
		for(int i = 0; i < __PointTextSeries->XValues->Count; i++)
		{
			__PointTextSeries->Marks->Positions->Position[i]->LeftTop.X = Chart->BottomAxis->CalcPosValue(MarksCoordinates.at(i).first);
			__PointTextSeries->Marks->Positions->Position[i]->LeftTop.Y = Chart->LeftAxis->CalcPosValue(MarksCoordinates.at(i).second);
		}
	}
}
And ZoomIn event:

Code: Select all

void __fastcall OnChartZoomIn(TObject *Sender)
{
	if(__PointTextSeries)
	{
		for(int i = 0; i < __PointTextSeries->XValues->Count; i++)
		{
			__PointTextSeries->Marks->Positions->Position[i]->LeftTop.X = __PointTextSeries->CalcPosValue(MarksCoordinates.at(i).first);
			__PointTextSeries->Marks->Positions->Position[i]->LeftTop.Y = __PointTextSeries->CalcPosValue(MarksCoordinates.at(i).second);
		}
	}
}

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart DragMark Tool

Post by Yeray » Mon Feb 26, 2018 10:56 am

Hello,

Here it is an example in Delphi supporting marks drag, zoom and scroll:

Code: Select all

uses Series;

var Series1: TPointSeries;
var MarksCoordinates: array of TPointFloat;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Series1:=Chart1.AddSeries(TPointSeries) as TPointSeries;
  with Series1 do
  begin
    Marks.Show;
    Marks.Arrow.Color:=clRed;
    Marks.ArrowLength:=10;

    FillSampleValues(10);
  end;

  with Chart1.Tools.Add(TDragMarksTool) as TDragMarksTool do
  begin
    OnDraggedMark:=DragMarksDragged;
  end;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  ApplyMarks;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  Chart1.Draw;
  ApplyMarks;
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  Chart1.Draw;
  ApplyMarks;
end;

procedure TForm1.DragMarksDragged(Sender:TDragMarksTool; Index:Integer;
                                  Button:TMouseButton; Shift: TShiftState;
                                  X,Y: Integer);
var i: Integer;
begin
  SetLength(MarksCoordinates, Series1.Count);
  for i:=0 to Series1.Count-1 do
  begin
    with Series1.Marks.Positions[i] do
    begin
      if not Custom then
      begin
        Custom:=True;
        if Index<>i then
        begin
          LeftTop.X:=Series1.CalcXPos(i) - (Width div 2);
          LeftTop.Y:=Series1.CalcYPos(i) - Height - Series1.Marks.ArrowLength;
        end;
      end;

      MarksCoordinates[i].x:=Series1.GetHorizAxis.CalcPosPoint(LeftTop.X + (Width div 2));
      MarksCoordinates[i].y:=Series1.GetVertAxis.CalcPosPoint(LeftTop.Y);
    end;
  end;
end;

procedure TForm1.ApplyMarks;
var i: Integer;
begin
  if Length(MarksCoordinates) = Series1.Count then
     for i:=0 to Series1.Count-1 do
     begin
       with Series1.Marks.Positions[i] do
       begin
         LeftTop.X:=Series1.GetHorizAxis.CalcPosValue(MarksCoordinates[i].x) - (Series1.Marks[i].Width div 2);
         LeftTop.Y:=Series1.GetVertAxis.CalcPosValue(MarksCoordinates[i].y);
         ArrowTo.X:=LeftTop.X + (Series1.Marks[i].Width div 2);
         ArrowTo.Y:=LeftTop.Y + Series1.Marks[i].Height;
         ArrowFrom.X:=Series1.CalcXPos(i);
         ArrowFrom.Y:=Series1.CalcYPos(i);
       end;
     end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

restech
Newbie
Newbie
Posts: 7
Joined: Mon Mar 27, 2017 12:00 am

Re: TeeChart DragMark Tool

Post by restech » Tue Feb 27, 2018 3:58 pm

Thanks, it works for zoom in and out. But if i add one mark and move it, and after that add another mark, marks moves then i scroll chart with right mouse button.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart DragMark Tool

Post by Yeray » Fri Mar 02, 2018 9:47 am

Hello,
restech wrote:But if i add one mark and move it, and after that add another mark, marks moves then i scroll chart with right mouse button.
I don't understand what should I exactly do to reproduce it. Could you please add a simple example?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply