Clicked method not working on Axis when using Polar Series

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
dimitrig
Newbie
Newbie
Posts: 18
Joined: Thu Aug 17, 2006 12:00 am
Location: Belgium
Contact:

Clicked method not working on Axis when using Polar Series

Post by dimitrig » Wed Oct 04, 2006 7:49 am

Hi,

I can't get the Clicked method to return true on the horiz/vert axis of a Polar Series.

At first I thought it had something to do with the coordinates of the point I passed as an argument (offset, wrong relative reference), but even when I added code that scans for a point that returns true, this will never happen:

Code: Select all

// This will scan a grid of [1000,1000] pixels.
for (int i = 0; i < 1000; i++)
{
    for (int j = 0; j < 1000; j++)
    {
        if(tChart1.Series[0].GetHorizAxis.Clicked(i, j))
        {
            Console.WriteLine("Found: "+i+", "+j);
        }
    }
}
I simply added one polar series to the chart and I'm using a non-3D orthogonal chart.

If I replace the polar series with a line series (or sth. else), it works perfectly and the output shows all the valid pixel coordinates for the Clicked method.

Regards

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

Post by Narcís » Wed Oct 04, 2006 10:51 am

Hi dimitrig,

Thanks for reporting.

I've been able to reproduce this here and added the issue to our wish-list to be enhanced for future releases. In the meantime a workaround is using something like this:

Code: Select all

    private void tChart1_MouseMove(object sender, MouseEventArgs e)
    {
      if ((e.Y == tChart1[0].GetHorizAxis.Position) && 
          (e.X >= tChart1[0].GetHorizAxis.IStartPos) &&
          (e.X <= tChart1[0].GetHorizAxis.IEndPos))
      {
        Console.WriteLine("Found: " + e.X + ", " + e.Y);
      }
    }
Or even better this:

Code: Select all

    private void Form1_Load(object sender, EventArgs e)
    {
      polar1.FillSampleValues();
      tChart1.Axes.DrawBehind = false;
    }

    private void tChart1_MouseMove(object sender, MouseEventArgs e)
    {
      if (((e.Y == tChart1.Axes.Bottom.Position) && 
          (e.X >= tChart1.Axes.Bottom.IStartPos) &&
          (e.X <= tChart1.Axes.Bottom.IEndPos)) ||
          ((e.Y == tChart1.Axes.Top.Position) &&
          (e.X >= tChart1.Axes.Top.IStartPos) &&
          (e.X <= tChart1.Axes.Top.IEndPos))
          )
      {
        Console.WriteLine("Found: " + e.X + ", " + e.Y);
      }
    }
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

dimitrig
Newbie
Newbie
Posts: 18
Joined: Thu Aug 17, 2006 12:00 am
Location: Belgium
Contact:

Post by dimitrig » Wed Oct 04, 2006 1:06 pm

Thanks Narcís... that works.

I use it to popup a certain context menu whenever one of the axes is clicked.

Previously what I did was this:

Code: Select all

private void tChart_RightClick(object sender, MouseEventArgs e)
{
    bool searchClick = false;
    Axis[] axes = { tChart.Axes.Bottom, tChart.Axes.Left, tChart.Axes.Right, tChart.Axes.Top };
    foreach (Axis selectedAxis in axes)
    {
        // Skip axis if it is not visible
        if (!selectedAxis.Visible)
        {
            continue;
        }

        try
        {
            searchClick = selectedAxis.Clicked(e.X, e.Y);
        }
        catch (ArgumentException)
        {
            return;
        }
        if (searchClick)
        {
            // Show the context menu
            axisContextMenuStrip.Tag = selectedAxis;
            axisContextMenuStrip.Show(tChart, e.X, e.Y);
            return;
        }
    }
}
I now changed it to this (to make it work with a polar = workaround you gave me + enhanced a little bit):

Code: Select all

private void tChart_RightClick(object sender, MouseEventArgs e)
{
    int axisSpacing = 3;
    // Bottom axis
    if ((tChart.Axes.Bottom.Visible) &&
        (e.Y >= tChart.Axes.Bottom.Position - axisSpacing && e.Y <= tChart.Axes.Bottom.Position + axisSpacing) &&
        (e.X >= tChart.Axes.Bottom.IStartPos - axisSpacing && e.X <= tChart.Axes.Bottom.IEndPos + axisSpacing))
    {
        // Show the context menu
        axisContextMenuStrip.Tag = tChart.Axes.Bottom;
        axisContextMenuStrip.Show(tChart, e.X, e.Y);
        return;
    }
    // Left axis
    if ((tChart.Axes.Left.Visible) && 
        (e.X >= tChart.Axes.Left.Position - axisSpacing && e.X <= tChart.Axes.Left.Position + axisSpacing) &&
        (e.Y >= tChart.Axes.Left.IStartPos - axisSpacing && e.Y <= tChart.Axes.Left.IEndPos + axisSpacing))
    {
        // Show the context menu
        axisContextMenuStrip.Tag = tChart.Axes.Left;
        axisContextMenuStrip.Show(tChart, e.X, e.Y);
        return;
    }
    // Right axis
    if ((tChart.Axes.Right.Visible) &&
        (e.X >= tChart.Axes.Right.Position - axisSpacing && e.X <= tChart.Axes.Right.Position + axisSpacing) &&
        (e.Y >= tChart.Axes.Right.IStartPos - axisSpacing && e.Y <= tChart.Axes.Right.IEndPos + axisSpacing))
    {
        // Show the context menu
        axisContextMenuStrip.Tag = tChart.Axes.Right;
        axisContextMenuStrip.Show(tChart, e.X, e.Y);
        return;
    }
    // Top axis
    if ((tChart.Axes.Top.Visible) &&
        (e.Y >= tChart.Axes.Top.Position - axisSpacing && e.Y <= tChart.Axes.Top.Position + axisSpacing) &&
        (e.X >= tChart.Axes.Top.IStartPos - axisSpacing && e.X <= tChart.Axes.Top.IEndPos + axisSpacing))
    {
        // Show the context menu
        axisContextMenuStrip.Tag = tChart.Axes.Top;
        axisContextMenuStrip.Show(tChart, e.X, e.Y);
        return;
    }
}
Can you assure me that the effect of the latter is the same as the first one?
I don´t have access to the source code of the Clicked method, so I´m unable to see what factors are determining wether an axis is clicked or not. Maybe I´m forgetting something in my code here? :?

Hopefully it gets resolved in one of the future releases... the first piece of code is much compacter and cleaner. :)

Regards

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

Post by Narcís » Wed Oct 04, 2006 1:26 pm

Hi dimitrig,

Your code is fine. Also you can use Lutz Roeder's Reflector to see what Clicked method does. Anyway, it checks if given X and Y coordinates are in the rectangle determined by:

Code: Select all

		private Rectangle AxisRect() 
		{
			int tmpPos1;
			int pos1;
			int tmpPos2;
			int pos2;
				
			if (IStartPos>IEndPos) 
			{ 
				tmpPos1=IEndPos;
				tmpPos2=IStartPos; }
			else 
			{ 
				tmpPos1=IStartPos;
				tmpPos2=IEndPos; }

			if (posAxis>labels.position) 
			{
				pos1=labels.position;
				pos2=posAxis+AxisClickGap; 
			}
			else 
			{
				pos1=posAxis-AxisClickGap;
				pos2=labels.position; 
			}

			if (horizontal) 
			{ 
				return Rectangle.FromLTRB(tmpPos1,pos1,tmpPos2,pos2); 
			}
			else 
			{ 
				return Rectangle.FromLTRB(pos1,tmpPos1,pos2,tmpPos2); 
			}
		}
where AxisClickGap is a constant of value=3.
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