Page 1 of 1

Editing the Line series at runtime

Posted: Tue Aug 31, 2010 2:12 pm
by 9641422
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

Re: Editing the Line series at runtime

Posted: Wed Sep 01, 2010 4:15 pm
by yeray
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();
            }   
        }

Re: Editing the Line series at runtime

Posted: Fri Sep 03, 2010 7:18 am
by 9641422
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

Re: Editing the Line series at runtime

Posted: Mon Sep 06, 2010 10:18 am
by yeray
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";
        }