Synchronize TDrawLineTools

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Synchronize TDrawLineTools

Post by Xia » Wed Oct 21, 2009 11:45 am

Hi,

I have two TCharts displayed on the screen, each has a TDrawLineTool for drawing rectangles on the Chart. How can I synchronize two TDrawLineTools on TChart like the TeeChart demo example for synchronizing two cursors? For example, when a rectangle is added or resized on the 1st Chart, a rectangle will also be added and resized on the 2nd Chart at the same time. I tried the OnDraggedLine event to resize the rectangle on the 2nd Chart but it is only called after the rectangle on the 1st Chart has been dragged or resized. Is it possible to have the rectangle on the 2nd Chart moving or resizing at the same time when dragging the rectangle on the 1st Chart?

Thanks

Xia

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

Re: Synchronize TDrawLineTools

Post by Yeray » Wed Oct 21, 2009 2:54 pm

Hi Xia,

Here is an example that, if I understood well, is doing what you've requested:

Code: Select all

var DrawLineTool1, DrawLineTool2: TDrawLineTool;
    AllowDrag: Boolean;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TPointSeries.Create(self));
  Chart1[0].FillSampleValues();
  Chart2.AddSeries(CloneChartSeries(Chart1[0]));
  Chart2[0].ColorEachPoint := true;
  Chart1.Legend.Visible := false;
  Chart2.Legend.Visible := false;

  DrawLineTool1 := TDrawLineTool.Create(self);
  DrawLineTool1.Style := dlRectangle;
  DrawLineTool2 := CloneChartTool(DrawLineTool1, self) as TDrawLineTool;
  Chart1.Tools.Add(DrawLineTool1);
  Chart2.Tools.Add(DrawLineTool2);

  DrawLineTool1.OnNewLine := NewLine;
  DrawLineTool2.OnNewLine := NewLine;
  DrawLineTool1.OnDragLine := DragLine;
  DrawLineTool2.OnDragLine := DragLine;
  Chart1.OnMouseDown := ChartMouseDown;
  Chart2.OnMouseDown := ChartMouseDown;
end;

procedure TForm1.AssignLine(LineFrom, LineTo: TDrawLines; Index: Integer);
begin
  LineTo.Line[Index].Assign(LineFrom.Line[Index]);
end;

procedure TForm1.NewLine(Sender: TObject);
begin
  if Sender = DrawLineTool1 then
  begin
    DrawLineTool2.Lines.Add;
    AssignLine(DrawLineTool1.Lines, DrawLineTool2.Lines, DrawLineTool1.Lines.Count-1);
    Chart2.Refresh;
  end
  else //Sender = DrawLineTool2
  begin
    DrawLineTool1.Lines.Add;
    AssignLine(DrawLineTool2.Lines, DrawLineTool1.Lines, DrawLineTool1.Lines.Count-1);
    Chart1.Refresh;
  end;
end;

procedure TForm1.DragLine(Sender: TObject);
begin
  if AllowDrag then
    if Sender = DrawLineTool1 then
    begin
      AssignLine(DrawLineTool1.Lines, DrawLineTool2.Lines, DrawLineTool1.Selected.Index);
      Chart2.Refresh;
    end
    else
    begin
      AssignLine(DrawLineTool2.Lines, DrawLineTool1.Lines, DrawLineTool2.Selected.Index);
      Chart1.Refresh;
    end;
end;

procedure TForm1.ChartMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (DrawLineTool1.Clicked(X,Y) <> nil) or (DrawLineTool2.Clicked(X,Y) <> nil) then
    AllowDrag := true
  else
    AllowDrag := false;
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Thu Oct 22, 2009 8:14 am

Hi Yeray,

Thanks for the example. It is very helpful. I have added codes to my program and I can add a rectangle on the 2nd Chart. But, there are some problems
1. Rectangle on the 2nd Chart is shown until the mouse released.
2. When dragging the rectangle on the 1st Chart for resizing, the rectangle on the 2nd Chart does not change and it resizes only after releasing mouse and then clicking on the rectangle.

I check the TChart User Guide and it said that OnDragLine is called when user has clicked a line and has begin dragging it and OnDraggedLine called when a line has been dragged to a new position, so I changed the code to set AllowDrag=true in OnDragLine and set AllowDrag=false in OnDraggedLine and then call AssignLine in the ChartMouseMove() function if AllowDrag==true. But it still does not work and it doesn't seem to call AssignLine in the ChartMouseMove function. Any suggestions?

Regards

Xia

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

Re: Synchronize TDrawLineTools

Post by Yeray » Thu Oct 22, 2009 11:46 am

Hi Xia,

Excuse me, in the test application I assigned the OnMouseDown events at design time. Please, add the following at the end of OnCreate (I've modified the code above too):

Code: Select all

  Chart1.OnMouseDown := ChartMouseDown;
  Chart2.OnMouseDown := ChartMouseDown;
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Thu Oct 22, 2009 12:43 pm

Hi Yeray,

I have already added the OnMouseDown event at design time. If I understand correctly, the OnDragLine event is only called at the beginning of dragging (i.e when pressing the mouse down) and it will not response to mouse move with the left button pressed for resizing the rectangle.

Regards

Xia

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

Re: Synchronize TDrawLineTools

Post by Yeray » Thu Oct 22, 2009 1:20 pm

Hi Xia,

I'm not sure to understand what problem do you have. Could you please try the attached application and tell me the exact steps I should do to reproduce the problem and/or what do you expect the application should do?

Thanks in advance.
Attachments
SynchronDrawLine.zip
(1.93 KiB) Downloaded 555 times
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Thu Oct 22, 2009 4:22 pm

Hi Yeary,

Thanks for the application code. I have created a project using your code, but I have to change accordingly since I am using CodeGear C++ Builder. I have the same problems.
1. When you resize the rectangle on the Chart1 by dragging the corner of the rectangle, the rectangle on the Chart2 does not resize until you release mouse button, and click and drag the rectangle1 again.
2. During resizing the rectangle on the Chart1, the shape of rectangle1 changes when dragging the mouse, but the rectangle on the Chart 2 does not change at all. I would like to see both rectangles change size when dragging the mouse.

Let me know if need further clarification.

Regards

Xiabing

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

Re: Synchronize TDrawLineTools

Post by Yeray » Fri Oct 23, 2009 2:39 pm

Hi Xiabing,

Maybe you forgot something because I can't see this effect. Please find attached the example project made in C++Builder 2010 & TeeChart Pro 8.06.
Attachments
SynchronDrawLine2.zip
(6.91 KiB) Downloaded 547 times
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Tue Oct 27, 2009 9:26 am

Hi Yeary,

Thanks for the example files. It has the same problems with TChart V8.02. But after upgrading to TChart V8.06, the program works fine, i.e. both Rectangles can be resized at the same time. So I think the problem is related to TChart V8.02.

However, I have two other projects which worked fine with TChart V8.02. After upgrading to V8.06, they both have some problems. One of the project uses TPointSeries, the program gives an error message "Invalid floating point operation" at the code below
Series1->YValue[0] = Series2->YValue[2];

The other project uses TColorGridSeries, the program gives an error message "Access violation at address ..." when filling in data using Dynamic array as below
void __fastcall TMDIChild::FillSeries()
{
DynamicArray<double> X, Y, Z;
int x, y, TotalCount;

try
{
TotalCount = 100;
X.Length = TotalCount;
Z.Length = TotalCount;
Y.Length = TotalCount;
for (y=0; y<10; y++ )
for ( x=0; x<10; x++ )
{
// fill in data
X[y*10+x] = x+1;
Z[y*10+x] = y+1;
Y[y*10+x] = x+y; // test data
}
}
__finally
{
Series->XValues->Value = (TChartValues)(X);
Series->XValues->Count = TotalCount;
Series->XValues->Modified = true;
Series->ZValues->Value = (TChartValues)(Z); //error message shown here
Series->ZValues->Count = TotalCount;
Series->ZValues->Modified = true;
Series->YValues->Value = (TChartValues)(Y);
Series->YValues->Count = TotalCount;
Series->YValues->Modified = true;
}
}

Both problems seem to do with TChartValues. Are there any known issues with TChartValue when upgrading to V8.06? Your help is very much appreciated.

Regards

Xia

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

Re: Synchronize TDrawLineTools

Post by Yeray » Tue Oct 27, 2009 10:49 am

Hi Xia,

1. PointSeries. I've made a new application, dropped a chart on the form, two point series in it and the following code and everything works as expected:

Code: Select all

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Chart1->View3D = false;

  Series1->FillSampleValues(5);
  Series2->FillSampleValues(5);

  Series1->YValue[0] = Series2->YValue[2];
}
2. Similar to 1, I've created the ColorGrid series at design time and your code seems to work fine.

Code: Select all

void __fastcall TForm1::FormCreate(TObject *Sender)
{
	DynamicArray<double> X, Y, Z;
	int x, y, TotalCount;

	try
	{
		TotalCount = 100;
		X.Length = TotalCount;
		Z.Length = TotalCount;
		Y.Length = TotalCount;
		for (y=0; y<10; y++ )
			for ( x=0; x<10; x++ )
			{
				// fill in data
				X[y*10+x] = x+1;
				Z[y*10+x] = y+1;
				Y[y*10+x] = x+y; // test data
			}
	}
	__finally
	{
		Series1->XValues->Value = (TChartValues)(X);
		Series1->XValues->Count = TotalCount;
		Series1->XValues->Modified = true;
		Series1->ZValues->Value = (TChartValues)(Z); //error message shown here
		Series1->ZValues->Count = TotalCount;
		Series1->ZValues->Modified = true;
		Series1->YValues->Value = (TChartValues)(Y);
		Series1->YValues->Count = TotalCount;
		Series1->YValues->Modified = true;
	}
}
Could you please check that your IDE and your project don't have old TeeChart references at library and search paths?
If you still have problems with it, please attach a simple example project we can run as-is to reproduce the problem here.
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Thu Oct 29, 2009 12:08 pm

Hi Yeary,

Thanks. You are right that I need to change the include and lib paths to new version.

TDrawLineTools synchronisation works nicely for two TCharts. A drawback of this synchronisation when dragging the rectangle is that it is a bit slow for TColorGridSeries when having over 500x500 pixels. How can I improve plot speed for TColorGridSeries? I read the article for real-time plotting but it didn't mention TColourGridSeries.

One other issue is that horizontal Grid function seems not working for TColorGridSeries in the new version 8.06. I tried ColorGrid example in New Feature Demo software. It only plots vertical grid but not horizontal grid.

Regards

Xia

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Synchronize TDrawLineTools

Post by Narcís » Mon Nov 02, 2009 12:49 pm

Hi Xia,
A drawback of this synchronisation when dragging the rectangle is that it is a bit slow for TColorGridSeries when having over 500x500 pixels. How can I improve plot speed for TColorGridSeries? I read the article for real-time plotting but it didn't mention TColourGridSeries.
A 500x500 grid is quite a big grid it doesn't surprise me that it is slow. For optimizing speed in such series I recommend you to avoid setting IrregularGrid=True whenever it's possible. For more information on how this property works please read this thread.
One other issue is that horizontal Grid function seems not working for TColorGridSeries in the new version 8.06. I tried ColorGrid example in New Feature
Demo software. It only plots vertical grid but not horizontal grid.
I could reproduce this here and added the defect to the list (TV52014524) to be fixed for future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Mon Nov 02, 2009 2:00 pm

Hi Narcis,

Thanks for your reply.

I have already set IrregularGrid=false. TColorGridSeries is very powerful data series for 2D image display and it is just a bit slow for a higher resolution image.

For the TDrawLineTool, I would like to handle differently when dragging the entire rectangle for reposition or dragging the corners of the rectangle for resizing. Is there anyway to know whether the start or end point is dragged or the entire shape is dragged for reposition.

Regards

Xia

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

Re: Synchronize TDrawLineTools

Post by Yeray » Mon Nov 02, 2009 4:34 pm

Hi Xia,

Yes, you could use the DrawLineTool rectangles "StartHandle" and "EndHandle" to see if the mouse was clicked in the resizing points or not:

Code: Select all

procedure TForm1.ChartMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var tmpTool: TDrawLine;
begin
  tmpTool:=DrawLineTool1.Clicked(X,Y);
  if tmpTool = nil then
    tmpTool:=DrawLineTool2.Clicked(X,Y);

  if (tmpTool <> nil) then
    if PtInRect(tmpTool.StartHandle,Point(X,Y)) or PtInRect(tmpTool.EndHandle,Point(X,Y)) then
    begin
      AllowDrag := true;
      AllowMove := false;
    end
    else
    begin
      AllowDrag := false;
      AllowMove := true;
    end
  else
  begin
    AllowDrag := false;
    AllowMove := false;
  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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Re: Synchronize TDrawLineTools

Post by Xia » Wed Nov 04, 2009 9:22 am

Hi Yeary,

Thanks. It works.

Regarding the grid on/off bug for TColorGridSeries, will this be fixed in next 3-6 months? If not, do you have a work-around solution?

Regards

Xiabing

Post Reply