How to keep TRectangleTool staying at the old position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

How to keep TRectangleTool staying at the old position

Post by elmec » Thu Nov 07, 2013 1:48 am

We have a question about TRectangleTool.
When we scroll chart, we want to keep the TRectangleTool stay at the old position.
It works well when scroll at one direction,
but when we change the scroll direction, it seems working strangely.

Code: Select all

__fastcall TForm7::TForm7(TComponent* Owner)
	: TForm(Owner)
{

	Series1->FillSampleValues(100);

	ChartToolRect->Left = 100;
	ChartToolRect->Width = 100;
	ChartToolRect->Top = Chart1->MarginTop;
	ChartToolRect->Height = Chart1->Height - Chart1->MarginTop - Chart1->MarginBottom;
	ChartToolRect->AllowDrag = false;
	ChartToolRect->AllowResize = false;
}

void __fastcall TForm7::Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
		  float X, float Y)
{
	if (Y > Chart1->Height * 1 / 2)
		return;

	// Move to the cusor position
	ChartToolRect->Left = X;

	// Remember the axes position of ChartToolRect
	ChartToolRect->Tag = Chart1->BottomAxis->InternalCalcPosPoint(X);
}

void __fastcall TForm7::Chart1Scroll(TObject *Sender)
{
	ChartToolRect->Left = Series1->CalcXPos(ChartToolRect->Tag);
}


Please find the attachment for example project.

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Thu Nov 07, 2013 1:49 am

The example project
Attachments
testTRectangleTool.zip
(96.52 KiB) Downloaded 730 times

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

Re: How to keep TRectangleTool staying at the old position

Post by Narcís » Fri Nov 08, 2013 10:46 am

Hi elmec,

There are some mistakes converting screen coordinates to axis values and viceversa. Also, some TChart1->Draw() calls are necessary in order to have the chart repainted and therefore properties updated before assigning them to the values which will be later used for saving the Rectangle tool position. You should do something like this:

Code: Select all

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Unit7.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FMXTee.Tools"
#pragma resource "*.fmx"
TForm7 *Form7;
double XVal;

__fastcall TForm7::TForm7(TComponent* Owner)
	: TForm(Owner)
{

	Series1->FillSampleValues(100);

	ChartToolRect->Left = 100;
	ChartToolRect->Width = 100;
	ChartToolRect->Top = cht1->MarginTop;
	ChartToolRect->Height = cht1->Height - cht1->MarginTop - cht1->MarginBottom;
	ChartToolRect->AllowDrag = false;
	ChartToolRect->AllowResize = false;

	cht1->Draw();
	XVal=cht1->Axes->Bottom->InternalCalcPosPoint(ChartToolRect->Left);
}

void __fastcall TForm7::cht1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          float X, float Y)
{
	if (Y > cht1->Height * 1 / 2)
		return;

	// Move to the cusor position
	ChartToolRect->Left = X;
	cht1->Draw();
	XVal=cht1->Axes->Bottom->CalcPosPoint(ChartToolRect->Left);

	// Remember the axes position of ChartToolRect
	XVal = cht1->BottomAxis->InternalCalcPosPoint(X);

}

void __fastcall TForm7::cht1Scroll(TObject *Sender)
{
	cht1->Draw();
	ChartToolRect->Left = Series1->CalcXPosValue(XVal);
}
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

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Sat Nov 09, 2013 12:48 am

Firstly, the "Draw()" in the construct of form makes the App. crashed.
Secondly, the "Draw()" in the Chart1Scroll makes the the scroll disabled...

Could you please take a look at it again?

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Sat Nov 09, 2013 1:03 am

The attachment for the example project.
Attachments
testTRectangleTool.zip
(109.08 KiB) Downloaded 694 times

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

Re: How to keep TRectangleTool staying at the old position

Post by Narcís » Mon Nov 11, 2013 9:43 am

Hi elmec,

Ok, looks like this approach gives problems in Firemonkey. It worked fine in a Delphi VCL project. Draw() call is necessary to have some properties updated and the values for the rectangle tool are correct. I've found the code below works fine in a C++ Builder Firemonkey project. Find attached the modified project as well.

Code: Select all

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Unit10.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FMXTee.Tools"
#pragma resource "*.fmx"
TForm10 *Form10;

double XVal;
Boolean DirtyX;
Boolean DirtyRect;
//---------------------------------------------------------------------------
__fastcall TForm10::TForm10(TComponent* Owner)
	: TForm(Owner)
{
   Series1->FillSampleValues(100);

   ChartToolRect->Left = 100;
   ChartToolRect->Width = 100;
   ChartToolRect->Top = Chart1->MarginTop;
   ChartToolRect->Height = Chart1->Height - Chart1->MarginTop - Chart1->MarginBottom;
   ChartToolRect->AllowDrag = false;
   ChartToolRect->AllowResize = false;

   DirtyX=True;
   DirtyRect=False;

   //Chart1->Draw();
   //XVal=Chart1->Axes->Bottom->InternalCalcPosPoint(ChartToolRect->Left);
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
		  float X, float Y)
{
   if (Y > Chart1->Height * 1 / 2)
	  return;

   // Move to the cusor position
   ChartToolRect->Left = X;
   DirtyX=True;
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Chart1Scroll(TObject *Sender)
{
	DirtyRect=True;
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Chart1AfterDraw(TObject *Sender)
{
	if (DirtyX)
	{
		XVal=Chart1->Axes->Bottom->InternalCalcPosPoint(ChartToolRect->Left);
		DirtyX=False;
	}
}
//---------------------------------------------------------------------------

void __fastcall TForm10::ChartToolRectAfterDraw(TObject *Sender)
{
	if (DirtyRect)
	{
		DirtyRect=False;
		ChartToolRect->Left = Series1->CalcXPosValue(XVal);
		Chart1->Draw();
	}
}
//---------------------------------------------------------------------------
Attachments
testTRectangleTool.zip
(74.33 KiB) Downloaded 671 times
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

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Mon Nov 11, 2013 10:12 am

Hello Narcís,
Thank you so much!
So it is a bug and will be modified in next release?

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

Re: How to keep TRectangleTool staying at the old position

Post by Narcís » Mon Nov 11, 2013 10:23 am

Hi elmec,

Can not confirm it for now. We are investigating the issue. Did my last solution suggestion work fine at your end?
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

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Mon Nov 11, 2013 11:17 am

Hello Narcís,
Yes , we have just tried that and it worked!
Thanks so much!

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

Re: How to keep TRectangleTool staying at the old position

Post by Narcís » Mon Nov 11, 2013 11:41 am

Hi elmec,

Thinking about your requirements, a ColorBand tool might be more suitable instead of a Rectangle tool. ColorBand is defined with Axis values (Start and End) so that you don't need to do anything with chart mouse events. When Zooming and scrolling it also preserves its original position.
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

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Mon Nov 11, 2013 12:07 pm

Hello Narcís,
Thanks for your advice.
We'll have a try of ColorBand tool!.

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: How to keep TRectangleTool staying at the old position

Post by elmec » Mon Nov 11, 2013 12:16 pm

Hello Narcís,
BTW, how to show some text on a ColorBand tool like TRectangleTool ?

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

Re: How to keep TRectangleTool staying at the old position

Post by Narcís » Mon Nov 11, 2013 12:23 pm

Hi elmec,

It lacks this functionality. You could either use an Annotation tool on top of it, custom draw the text on TeeChart's canvas or continue using a rectangle tool.
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

Post Reply