Line movement

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

Line movement

Post by Amol » Tue May 17, 2011 12:48 pm

Hi All
I have a taken a line object to draw the lines , I want to move that line from one point to another. How can move the lines.
Please reply me as soon possible.

Thanks
Sudhir Srivastava

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

Re: Line movement

Post by Narcís » Fri May 20, 2011 11:35 am

Hi Sudhir,

Just click on a line to select it and drag it to another location in the chart. Click and drag handles to change start or end point. You can find examples at All Features\Welcome !\Tools\Draw Lines in the features demo available at TeeChart's program group.

If that's not what you are looking for please give us more details.
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

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

Re: Line movement

Post by Amol » Thu Jun 09, 2011 1:18 pm

Hi Narcís,

Thanks for the support you provide so far.
I am now able to move the line series on chart. But I have some problem which i ma explaining bellow:
I have a chart having logarithmic axes. On this chart I have two lines. Say first line is Line1 and other is Line2. We can move only Line1 by clicking it and dragging over the chart only in Y direction. I want to move Line2 at the same time with same distance (the distance line1 is moved)

Problem: Line 2 is not moving properly. It move with a varying diatance. However if we change axes to non log, it works.

For explaining it I am attaching sample project. In this project there are two forms. Form one have a chart with Logarithmic axes and Form2 have Non- Logarithmic axes. Please run both the forms. I want the movement in form1 as in form2.
I am very thankful for your kind and precious support. It will be so kind of you if you please help me as soon as possible.

Thanks and regards
Ashish Pandey
Attachments
MovementOfLineInLogAxes.rar
(31.84 KiB) Downloaded 761 times

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

Re: Line movement

Post by Yeray » Fri Jun 10, 2011 2:37 pm

Hello Ashish,

I think the project you've sent is working as expected. The deltaY variable you are calculating in the MouseMove event is the distance in pixels between the Y Position where the line was and the actual Y Position of the mouse. Note that this is a linear distance, not a logarithmic one. So it will be difficult to use it to set a regular distance in a logarithmic scale.
I'd suggest you to take the distance in pixels between the clicked line and the other line at the MouseDown event. This distance in pixels is the one you want to always maintain (if I understood correctly). So I've added a line in your MouseDown event:

Code: Select all

            if (indexOfClickedPoint != -1)
            {
                isMouseDownOnLine = true;
                distInPixels = Line1.CalcYPos(indexOfClickedPoint) - Line2.CalcYPos(indexOfClickedPoint);
            }
But, as we are talking about a logarithmic axis, this distance in pixels means different distances in values depending on the concrete position. So, we can take the position in pixels of the clicked line (CalcYPos), subtract the distance in pixels previously calculated to get the Y position in pixels we'll have to impose to the other line. And we'll have to translate this calculated position in pixels to values with the axis CalcPosPoint function.
So instead of:

Code: Select all

                Line2[0].Y += deltaY;
                Line2[1].Y += deltaY;
You could do this:

Code: Select all

                Line2[0].Y = tChart1.Axes.Left.CalcPosPoint(Line1.CalcYPos(indexOfClickedPoint) - distInPixels);
                Line2[1].Y = tChart1.Axes.Left.CalcPosPoint(Line1.CalcYPos(indexOfClickedPoint) - distInPixels);
And it seems to work as I understood you would like to. Please, make us know if it doesn't work as you expected.
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: Line movement

Post by Amol » Sat Jun 11, 2011 8:22 am

HI Yeray,

Thanks you very-very much for the precious help you provided. The code you provided is working as expected. I and my senior in management are very delightful with Steema’s support. We were using Evaluation version of Tee-Chart 2010. But now we got its licence. After now I will work on it.

I do have one other query: I want to draw a line with half (45°) slope whose end point always is on Chart’s boundaries. I can also move it along the X axis. I am able to move it in non log axes. But in log axes I am unable to draw this line, movement is so far. Once again I am attaching project which will explain my problem. This project is on same pattern as previous as it contain two forms , one with log axes and other of non log axes.

One thing I want to let you know that currently I am new in Tee-Chart, so maybe I need your frequent support.

Once again I would like to say: Thank you!

Thanks and regards
Ashish Pandey
Attachments
MovementOfLineInLogAxes.rar
(36.16 KiB) Downloaded 728 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Line movement

Post by Sandra » Wed Jun 15, 2011 12:25 pm

Hello Amol,

Sorry for the delay.You need calculate position of values in the Log Axes Left if you want get correct position of Line, as do in next lines of code:

Code: Select all

        private void CreateDataForHalfSlopeLine(double KnownX, double KnownY, ref List<double> XDATA, ref List<double> YDATA)
        {
            float slope = 1; //with 1/2 slope, i.e. 45 .

            PointF pointOfIndex2 = new PointF();
            pointOfIndex2.X =(float)tChart1.Axes.Left.CalcPosPoint((int)(KnownX + (((tChart1.Axes.Left.Maximum - KnownY) / slope))));
            pointOfIndex2.Y = (float)tChart1.Axes.Left.CalcPosPoint((int)tChart1.Axes.Left.Maximum);

            slope = ((float)KnownY - pointOfIndex2.Y) / ((float)KnownX - pointOfIndex2.X);

            PointF pointOfIndex0 = new PointF();

            pointOfIndex0.X = (float)tChart1.Axes.Left.CalcPosPoint((int)(KnownX + ((tChart1.Axes.Left.Minimum - KnownY) / slope)));
            pointOfIndex0.Y = (float)tChart1.Axes.Left.CalcPosPoint((int)tChart1.Axes.Left.Minimum);

            XDATA.Add(pointOfIndex0.X);
            XDATA.Add(tChart1.Axes.Left.CalcPosValue(KnownX));
            XDATA.Add(pointOfIndex2.X);

            YDATA.Add(pointOfIndex0.Y);
            YDATA.Add(tChart1.Axes.Left.CalcPosValue(KnownY));
            YDATA.Add(pointOfIndex2.Y);
        }
Could you tell us if previous code works as you expected?

Thanks,
Best Regards,
Sandra Pazos / 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

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

Re: Line movement

Post by Amol » Fri Jun 17, 2011 12:40 pm

Hi Sandra,

Thanks for reply. I am afraid, but code you provided is not working as it is unable to draw line. In the code provided by you, the lists ‘XDATA’ and ‘YDATA’ contains its entire item with value zero. Since the values are zero, it could not draw line.

I am still unable to draw a line with half slope whose end points are always on chart axes. But I am working on it. Meanwhile you can suggest me another way to do it.

There is one more query regarding Legend in TeeChart 2010 (version 4.1.2011). Legend is not being displayed on Chart with this dll, while if we use its previous version (version 4.1.2011) it works fine.

It will be so kind of you if you please help me ASAP.

Thanks and Regards,
Ashish Pandey

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Line movement

Post by Sandra » Fri Jun 17, 2011 3:05 pm

Hello Amol,
Sorry, in previous example I have been forgotten add tChart1.Draw() because function CalcPosPoint() can calculate correctly. You can add tChart1.Draw() as in next code:

Code: Select all

  private void CreateDataForHalfSlopeLine(double KnownX, double KnownY, ref List<double> XDATA, ref List<double> YDATA)
            {
                tChart1.Draw();
                float slope = 1; //with 1/2 slope, i.e. 45 .

                PointF pointOfIndex2 = new PointF();
                pointOfIndex2.X =(float)tChart1.Axes.Left.CalcPosPoint((int)(KnownX + (((tChart1.Axes.Left.Maximum - KnownY) / slope))));
                pointOfIndex2.Y = (float)tChart1.Axes.Left.CalcPosPoint((int)tChart1.Axes.Left.Maximum);

                slope = ((float)KnownY - pointOfIndex2.Y) / ((float)KnownX - pointOfIndex2.X);

                PointF pointOfIndex0 = new PointF();

                pointOfIndex0.X = (float)tChart1.Axes.Left.CalcPosPoint((int)(KnownX + ((tChart1.Axes.Left.Minimum - KnownY) / slope)));
                pointOfIndex0.Y = (float)tChart1.Axes.Left.CalcPosPoint((int)tChart1.Axes.Left.Minimum);

                XDATA.Add(pointOfIndex0.X);
                XDATA.Add(tChart1.Axes.Left.CalcPosValue(KnownX));
                XDATA.Add(pointOfIndex2.X);

                YDATA.Add(pointOfIndex0.Y);
                YDATA.Add(tChart1.Axes.Left.CalcPosValue(KnownY));
                YDATA.Add(pointOfIndex2.Y);
            }
On the other hand, I am not sure that this is a right solution for logarithmic axes and how you want behave exactly line as you want draw. Please, could you attach us and image where appears line in the correct position to you (you can draw it) and explain exactly as you want achieve line behave in logarithmic axes?

Thanks,
Best Regards,
Sandra Pazos / 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

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

Re: Line movement

Post by Amol » Mon Jun 20, 2011 7:33 am

Hi Sandra,

Yes, you are right code you provided in last post was not working as expected. But after adding tChart1.Draw() it works fine. Thanks for making correction.

Sandra says:
Please, could you attach us and image where appears line in the correct position to you (you can draw it) and explain exactly as you want achieve line behave in logarithmic axes?

To know what I am trying to do, you can see fifth post. You can also see the project attached. Anyways I am explaining it once again:
I have a chart with logarithmic axes. In this chart we need a line which will be on half slope (45°) and its end points always touches the boundaries of the chart (We have done this by your help provided in last post). But the major part of the requirement is that we can move this line along X- axis by just clicking it and moving mouse over the chart. While moving the line, its end points should always be boundaries. I have successfully made this type of chart for linear axes, but for logarithmic axes I am still grappling.
The project attached in fifth post may be helpful for you to understand. In this project there are two forms. Form1 have a chart with Logarithmic axes and Form2 have Non- Logarithmic axes. Please run both the forms. I want the movement of half slope line in form1 as in form2.

There is one more query regarding Legend in TeeChart 2010 (version 4.1.2011). Legend is not being displayed on Chart with this dll, while if we use its previous version (version 4.0.2010) it works fine.

We will appreciate your suggestions.

Thanks and Regards,
Ashish Pandey

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Line movement

Post by Sandra » Mon Jun 20, 2011 12:17 pm

Hello Amol,
Sandra says:
Please, could you attach us and image where appears line in the correct position to you (you can draw it) and explain exactly as you want achieve line behave in logarithmic axes?

To know what I am trying to do, you can see fifth post. You can also see the project attached. Anyways I am explaining it once again:
I have a chart with logarithmic axes. In this chart we need a line which will be on half slope (45°) and its end points always touches the boundaries of the chart (We have done this by your help provided in last post). But the major part of the requirement is that we can move this line along X- axis by just clicking it and moving mouse over the chart. While moving the line, its end points should always be boundaries. I have successfully made this type of chart for linear axes, but for logarithmic axes I am still grappling.
The project attached in fifth post may be helpful for you to understand. In this project there are two forms. Form1 have a chart with Logarithmic axes and Form2 have Non- Logarithmic axes. Please run both the forms. I want the movement of half slope line in form1 as in form2.
I think that would be helpful to you, use a drawline tool, as do in next thread : http://www.teechart.net/support/viewtop ... t=0#p52763 where explain as you do to draw the drawline in all of chart and it works fine in Logarithmic axes. I think is a easy way to achieve as you want.
There is one more query regarding Legend in TeeChart 2010 (version 4.1.2011). Legend is not being displayed on Chart with this dll, while if we use its previous version (version 4.0.2010) it works fine.
Sorry I forgot answer this question. I have checked it with source code and it works fine so it will be solved to next maintenance release of TeeChart.Net

Thanks,
Best Regards,
Sandra Pazos / 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

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

Re: Line movement

Post by Amol » Mon Jun 20, 2011 1:26 pm

Hi Sandra,

Thanks for your quick response. There are some restraints so I cannot use DrawLine tool. I had a long discussion about this in the posts available at the link you provided. At last I found that Draw Line cannot help me.

It will be so kind of you if you please provide the solution using Line series.

Thanks in advance

Thanks and Regards,
Ashish Pandey

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

Re: Line movement

Post by Yeray » Tue Jun 21, 2011 7:57 am

Hello Ashish,
Amol wrote:There are some restraints so I cannot use DrawLine tool. I had a long discussion about this in the posts available at the link you provided. At last I found that Draw Line cannot help me.
In the last post of the mentioned discussion I suggested you a way to achieve the last problematic you exposed. If you found any other problem with the workaround or anything else we'll be pleased to hear about it (please, do it in the according thread if you want us to take a look at it).
Amol wrote:It will be so kind of you if you please provide the solution using Line series.
I think the problem in your code is regarding the relation and transformation from screen pixels to axes values and vicevesa. I'd suggest you to take a look at the following thread to understand the purpose of CalcPosValue and CalcPosPoint functions.

Back to your application, I see you try to draw a line with a given slope. And you want that line to be draggable in a logarithmic axis maintaining the sople or angle.
- First of all note that you have to calculate the coordinates of the dragged line and, as more points in the series, more points you'll need to calculate. I mean, since a line is drawn with two points, why to have three?
- You use the clicked method at MouseDown event to check if the line is clicked. Then, at MouseMove event, you try to recalculate the coordinates of the points. As these points will cut the ChartRect, I see this problematic pretty similar to the problematic in the other thread, where you try to do exactly the same but with a DrawLine tool. So the code should look very similar to the code in there. The main difference is that the DrawLine tool takes pixels as coordinates, while a Line series has to be set with axes values. So you'll have to transform the coordinates calculated in the DrawLine example, and transform them to axes values with CalcPosPoint function.

Taking your example and the code from the DrawLine tool thread, with some little modifications, it seems to work fine for me here. This is the code I use to calculate the two Line points:

Code: Select all

                int X0, Y0, X1, Y1;

                double slope = 1;
                double alfa = Math.Atan2(1, 1*slope);
                double alfad = (alfa * (180.0 / Math.PI)) % 360;

                X0 = Math.Max(e.X - (int)(Math.Abs(tChart1.Axes.Left.IEndPos - e.Y) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos);
                Y0 = Math.Min(e.Y + (int)(Math.Tan(alfa) * Math.Abs(e.X - tChart1.Axes.Bottom.IStartPos)), tChart1.Axes.Left.IEndPos);
                X1 = Math.Min(e.X + (int)(Math.Abs(tChart1.Axes.Left.IStartPos - e.Y) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos);
                Y1 = Math.Max(e.Y - (int)(Math.Tan(alfa) * Math.Abs(e.X - tChart1.Axes.Bottom.IEndPos)), tChart1.Axes.Left.IStartPos);

                m_lnHalfSlope.XValues[0] = tChart1.Axes.Bottom.CalcPosPoint(X0);
                m_lnHalfSlope.YValues[0] = tChart1.Axes.Left.CalcPosPoint(Y0);
                m_lnHalfSlope.XValues[1] = tChart1.Axes.Bottom.CalcPosPoint(X1);
                m_lnHalfSlope.YValues[1] = tChart1.Axes.Left.CalcPosPoint(Y1);
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: Line movement

Post by Amol » Tue Jun 21, 2011 10:41 am

HI Yeray,

Thanks you very much for giving your precious time. I told you earlier some reason why I cannot use ‘DrawLine’ tool. Now our project is growing huge. We have created lots of this type of graph in our project using Line Series (but with non logarithmic axes). There are some dependencies of those plots with each other. As we are continuously using line series, it will be difficult to have Draw Line in some plot and in some Line Series. Also there are some synchronisations which could be lost by using DrawLine tool. One more thing was also there, as discussed that we could not find it in legend. If we create custom legend then it will be very difficult to maintain real-time synchronization as already present in default legend of Tee chart.
I'd suggest you to take a look at the following thread to understand the purpose of CalcPosValue and CalcPosPoint functions.
As you suggested, for understanding CalcPosValue and CalcPosPoint functions, I am trying to get it correctly.

Once again I am explaining what I am trying to do(as attached figure): I want to draw a line series at a slope of 45° on logarithmic axes whose end points should always be on the boundaries. It should also have a pointer inside chart which would be used for calculation. After plotting it I could move it over the chart along the X axis by just clicking and dragging it by mouse. I am still working on it using Line series but meanwhile if you get anything :idea: for me then please let me know.
2011-06-21_160507.jpg
2011-06-21_160507.jpg (97.7 KiB) Viewed 21132 times
Please help me.

Thanks and regards
Ashish Pandey

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

Re: Line movement

Post by Yeray » Wed Jun 22, 2011 8:09 am

Hello Ashish,
Amol wrote:Once again I am explaining what I am trying to do(as attached figure): I want to draw a line series at a slope of 45° on logarithmic axes whose end points should always be on the boundaries. It should also have a pointer inside chart which would be used for calculation. After plotting it I could move it over the chart along the X axis by just clicking and dragging it by mouse. I am still working on it using Line series but meanwhile if you get anything :idea: for me then please let me know.
I see, since you want a line with a central pointer visible, this line has to have minimum 3 points. You could use the line series GetPointerStyle event to show the pointer with index=1 and hide the pointers with index=0 and index=2.
A part from this, the concepts explained above should be enough to calculate the line values to draw your 45º slope. Here it is the complete Form1 that does it for me. The only thing I'm not sure why it isn't working as I'd expect is how the line looks the first time it is drawn. Maybe you can find what I'm missing.
But it seems to work as I'd expect when you drag it, isn't it?

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart.Styles;

namespace MovementOfLineInLogAxes
{
    internal class PointD
    {
        public double X, Y;
    }

    public partial class Form1 : Form
    {
        Line Line1 = new Line();
        Line Line2 = new Line();
        PointF m_pCurrent, m_pOrigin;
        bool isMouseDownOnLine = false;
        bool isMouseDownOnHalfSlopeLine = false;

        int indexOfClickedPoint = -1;
        int indexOfHalfSlopeLine = -1;

        Line m_lnHalfSlope = new Line();

        Point CentralPointPix;

        public Form1()
        {
            InitializeComponent();
            CreateChart();
        }

        private void CreateChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            tChart1.Panel.Color = Color.White;
            tChart1.Panel.Gradient.Visible = false;
            tChart1.BackColor = Color.White;
            tChart1.Walls.Back.Gradient.Visible = false;
            tChart1.Axes.Left.Automatic = false;
            tChart1.Axes.Left.Logarithmic = true;
            tChart1.Axes.Bottom.Automatic = false;
            tChart1.Axes.Bottom.Logarithmic = true;
            tChart1.Walls.Back.Color = Color.White;
            tChart1.Walls.Back.Transparency = 0;
            tChart1.Legend.CustomPosition = true;
            tChart1.Chart.Panning.Allow = Steema.TeeChart.ScrollModes.None;
            tChart1.Legend.Top = 14;
            tChart1.Legend.Left = 824;
            tChart1.Legend.Visible = true;
            tChart1.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series;
            tChart1.Zoom.Allow = false;

            tChart1.Axes.Left.Minimum = 1;
            tChart1.Axes.Left.Maximum = 1000;

            tChart1.Axes.Bottom.Minimum = 0.0001;
            tChart1.Axes.Bottom.Maximum = 1000;

            Line1.Add(tChart1.Axes.Bottom.Minimum, 14.1456);
            //Line1.Add(96.0, 14.1456);
            Line1.Add(tChart1.Axes.Bottom.Maximum, 14.1456);

            Line1.Pointer.Visible = false;
            Line1.Color = Color.Blue;
            tChart1.Series.Add(Line1);

            Line2.Add(tChart1.Axes.Bottom.Minimum, 5.0992);
            //Line2.Add(0.001, 5.0992);
            Line2.Add(tChart1.Axes.Bottom.Maximum, 5.0992);

            Line2.Pointer.Visible = false;
            Line2.Color = Color.Red;
            tChart1.Series.Add(Line2);

            List<double> XDATA = new List<double>();
            List<double> YDATA = new List<double>();
            CreateDataForHalfSlopeLine(80, 30, ref XDATA, ref YDATA);
            m_lnHalfSlope.Add(XDATA.ToArray(), YDATA.ToArray());
            m_lnHalfSlope.Title = "Half Slope Line";
            m_lnHalfSlope.Pointer.Visible = false;
            m_lnHalfSlope.Pointer.Visible = true;
            m_lnHalfSlope.Color = Color.Red;
            m_lnHalfSlope.ZOrder = 1;
            tChart1.Series.Add(m_lnHalfSlope);

            CentralPointPix = new Point();

            m_lnHalfSlope.GetPointerStyle += new CustomPoint.GetPointerStyleEventHandler(m_lnHalfSlope_GetPointerStyle);
        }

        void m_lnHalfSlope_GetPointerStyle(CustomPoint series, GetPointerStyleEventArgs e)
        {
            switch (e.ValueIndex)
            {
                case 0:
                case 2: e.Style = PointerStyles.Nothing;
                    break;
                case 1: e.Style = series.Pointer.Style;
                    break;
            }
        }

        int distInPixels = 0;
        private void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            m_pOrigin = new PointF(Convert.ToSingle(getPositionX(e.X)), Convert.ToSingle(getPositionYl(e.Y)));
            originY = m_pOrigin.Y;
            indexOfClickedPoint = Line1.Clicked(e.X, e.Y);
            indexOfHalfSlopeLine = m_lnHalfSlope.Clicked(e.X, e.Y);

            if (indexOfClickedPoint != -1)
            {
                isMouseDownOnLine = true;
                distInPixels = Line1.CalcYPos(indexOfClickedPoint) - Line2.CalcYPos(indexOfClickedPoint);
            }
            if (indexOfHalfSlopeLine != -1)
            {
                isMouseDownOnHalfSlopeLine = true;
            }
        }

        double currentY = 0, originY = 0;

        private void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            m_pCurrent = new PointF(Convert.ToSingle(getPositionX(e.X)), Convert.ToSingle(getPositionYl(e.Y)));
            
            if (isMouseDownOnLine)
            {
                double deltaY = currentY - originY;

                if (indexOfClickedPoint != -1)
                {
                    Line1[indexOfClickedPoint].Y = m_pCurrent.Y;
                    Line1[1].Y = m_pCurrent.Y;
                }

                Line2[0].Y = tChart1.Axes.Left.CalcPosPoint(Line1.CalcYPos(indexOfClickedPoint) - distInPixels);
                Line2[1].Y = tChart1.Axes.Left.CalcPosPoint(Line1.CalcYPos(indexOfClickedPoint) - distInPixels);

                originY = currentY;
            }

            if (isMouseDownOnHalfSlopeLine)
            {
                CentralPointPix.X = e.X;
                CentralPointPix.Y = e.Y;

                for (int i = 0; i < 3; i++)
                {
                    PointD tmpPoint = FindPointOfGivenIndex(i);
                    m_lnHalfSlope.XValues[i] = tmpPoint.X;
                    m_lnHalfSlope.YValues[i] = tmpPoint.Y;
                }

                m_lnHalfSlope.Repaint();
            }
        }

        private void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            m_pOrigin = m_pCurrent;
            isMouseDownOnLine = false;
            isMouseDownOnHalfSlopeLine = false;
        }

        /// <summary>
        /// To convert the absolute X value of cursor into value corresponding to Bottom axis
        /// </summary>
        /// <returns>Bottom axes values for given pixel value in horizontal direction</returns>
        public double getPositionX(float X)
        {
            return Line1.ScreenPointToValuePoint(Convert.ToInt32(X), 0).X;
        }

        /// <summary>
        /// To convert the absolute Y value of cursor into value corresponding to Left axis
        /// </summary>
        /// <returns>Left axes values for given pixel value in vertical direction</returns>
        double getPositionYl(float Yl)
        {
            return Line1.ScreenPointToValuePoint(0, Convert.ToInt32(Yl)).Y;
        }

        private void CreateDataForHalfSlopeLine(double KnownX, double KnownY, ref List<double> XDATA, ref List<double> YDATA)
        {
            tChart1.Draw();

            CentralPointPix.X = tChart1.Axes.Bottom.CalcPosValue(KnownX);
            CentralPointPix.Y = tChart1.Axes.Left.CalcPosValue(KnownY);

            PointD tmpPoint;
            tmpPoint = FindPointOfGivenIndex(0);
            XDATA.Add(tmpPoint.X);
            YDATA.Add(tmpPoint.Y);

            XDATA.Add(KnownX);
            YDATA.Add(KnownY);

            tmpPoint = FindPointOfGivenIndex(2);
            XDATA.Add(tmpPoint.X);
            YDATA.Add(tmpPoint.Y);
        }

        private PointD FindPointOfGivenIndex(int index)
        {
            double slope = 1;
            double alfa = Math.Atan2(1, 1 * slope);
            double alfad = (alfa * (180.0 / Math.PI)) % 360;

            PointD pointOfGiveIndex = new PointD();

            switch (index)
            {
                case 1:
                    pointOfGiveIndex.X = tChart1.Axes.Bottom.CalcPosPoint(CentralPointPix.X);
                    pointOfGiveIndex.Y = tChart1.Axes.Left.CalcPosPoint(CentralPointPix.Y);
                    break;

                case 0:
                    pointOfGiveIndex.X = tChart1.Axes.Bottom.CalcPosPoint(Math.Max(CentralPointPix.X - (int)(Math.Abs(tChart1.Axes.Left.IEndPos - CentralPointPix.Y) / Math.Tan(alfa)), tChart1.Axes.Bottom.IStartPos));
                    pointOfGiveIndex.Y = tChart1.Axes.Left.CalcPosPoint(Math.Min(CentralPointPix.Y + (int)(Math.Tan(alfa) * Math.Abs(CentralPointPix.X - tChart1.Axes.Bottom.IStartPos)), tChart1.Axes.Left.IEndPos));
                    break;

                case 2:
                    pointOfGiveIndex.X = tChart1.Axes.Bottom.CalcPosPoint(Math.Min(CentralPointPix.X + (int)(Math.Abs(tChart1.Axes.Left.IStartPos - CentralPointPix.Y) / Math.Tan(alfa)), tChart1.Axes.Bottom.IEndPos));
                    pointOfGiveIndex.Y = tChart1.Axes.Left.CalcPosPoint(Math.Max(CentralPointPix.Y - (int)(Math.Tan(alfa) * Math.Abs(CentralPointPix.X - tChart1.Axes.Bottom.IEndPos)), tChart1.Axes.Left.IStartPos));
                    break;
            }
            return pointOfGiveIndex;
        }
    }
}
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: Line movement

Post by Amol » Wed Jun 22, 2011 9:54 am

Hi Yeray,

Thank you very much for the code you provided in above post. I have no words to explain how you helped me. Your support has been tremendous. :D

As an independent project it is working fine. Now we will incorporate it in out project and let you know the status. Hope it’ll work same here.

Thanks and regards
Ashish Pandey

Post Reply