Editing the Line series at runtime

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Editing the Line series at runtime

Post by Amol » Tue Aug 31, 2010 2:12 pm

Hi,

I am trying to implement editing of editing of line series(with stairs enablied) at run time, i.e. user can add new points to the line series and can edit the value of existing point by dragging them. The whole functionality can be explained as follows:
1. If user clicks mouse somewhere on chart (not on series), a new point at the clicked location is added to the series.
2. To edit the value of particular point, user presses mouse on the pointer of that point and then drags the mouse. The point changes its location with changing position of mouse pointer.

I am using Series.Clicked(point) method on mouse down event of chart to get the index of the point on which mouse is pressed to drag the point.

The problem is, Series.Cicked(point) method returns the index even if the mouse is pressed down on the connecting line between two pointers. I want that, it should return index only when mouse is pressed on pointer of series not on the connecting line. I want this because of one more functionality explained below:

When user presses mouse on the connecting line between two pointers, he/she can drag the line horizontally if the line is vertical or vertically if the line is horizontal, that in turn will change the X value or Y value of the associated point.

Kindly provide some solution to this problem.
Waiting for your reply.

Thanks & Regards
Yatendra

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

Re: Editing the Line series at runtime

Post by Yeray » Wed Sep 01, 2010 4:15 pm

Hi Yatendra,

First note that the DragPoint tool can be useful here and may do some work for you.
Regarding the clicked problem, known the pointer size, the position clicked and the position of the pointer, you can check if the mouse click has been done in a pointer or not. For example:

Code: Select all

        Steema.TeeChart.Styles.Line line1;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
            line1.Pointer.Visible = true;
            line1.Pointer.HorizSize = 10;
            line1.Pointer.VertSize = 10;

            Steema.TeeChart.Tools.DragPoint drag1 = new Steema.TeeChart.Tools.DragPoint(tChart1.Chart);
            drag1.Series = line1;

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            int ValueIndex = line1.Clicked(e.X, e.Y);

            if ((ValueIndex == -1) || (!(new Rectangle(line1.CalcXPos(ValueIndex) - line1.Pointer.HorizSize / 2, line1.CalcYPos(ValueIndex) - line1.Pointer.VertSize / 2, line1.Pointer.HorizSize, line1.Pointer.VertSize)).Contains(e.X, e.Y)))
            {
                line1.Add(tChart1.Axes.Bottom.CalcPosPoint(e.X), tChart1.Axes.Left.CalcPosPoint(e.Y));
                line1.CheckOrder();
            }   
        }
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

Amol
Advanced
Posts: 176
Joined: Mon May 29, 2006 12:00 am

Re: Editing the Line series at runtime

Post by Amol » Fri Sep 03, 2010 7:18 am

Hi Yeray,

Thank you very much for the solution.

I have one more query. I just want to know that, if I am using line series with staircase enabled, then is it possible to know that whether the mouse pointer is currently on some vertical line segment of the line series or on some horizontal line segment? Please note that the staircase property is true.

Thanks for the support once again.

Best Regards
Yatendra

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

Re: Editing the Line series at runtime

Post by Yeray » Mon Sep 06, 2010 10:18 am

Hi Yatendra,

You could calculate the vertical line coordinates and check if the mouse is over it at MouseMove event:

Code: Select all

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            int ValueIndex = line1.Clicked(e.X, e.Y);

            if (ValueIndex != -1)
            {
                if (Steema.TeeChart.Drawing.Graphics3D.PointInLineTolerance(new Point(e.X, e.Y), line1.CalcXPos(ValueIndex + 1), line1.CalcYPos(ValueIndex), line1.CalcXPos(ValueIndex + 1), line1.CalcYPos(ValueIndex + 1), 3))
                    tChart1.Header.Text = "Vertical";
                else
                    tChart1.Header.Text = "Horizontal";
            }
            else
                tChart1.Header.Text = "Nothing clicked";
        }
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