Page 1 of 1

Multiple Selections with selector tool

Posted: Mon Aug 09, 2010 10:31 pm
by 13051032
I like to select multiple fastline series with help of selectortool. I currently have one selector tool added to the chart and when I click on one fastline series, it correctly selects it, but when i click on the next one, it unselects the previously selected series and selects the new one. I like to have all series selected as user clicks on series (holding Ctrl key).

How can i achieve this? Any help will be greatly appreciated. :!:

Re: Multiple Selections with selector tool

Posted: Tue Aug 10, 2010 12:40 pm
by 10050769
Hello asupriya,

I think that is not possible using selector tool for do multiple selections, because you o can select only one item at the same time with one selector. If you want do multiple selections I recommend you that add a selector for each series or create your selection manually using Mouse Events.


Thanks,

Re: Multiple Selections with selector tool

Posted: Thu Aug 12, 2010 4:02 am
by 13051032
If you want do multiple selections I recommend you that add a selector for each series ..
Can you please give an example code? I know how to add one selector and set it to active mode when desired component (such as fastline series) is clicked. I do not know how to set multiple selector tools.

My requirement is as follows: In general, only one component is selectable (just as achieved by adding one selector tool). But, when user holds a Control key (Ctrl key on keyboard), user should be able to select multiple series with each series attached to a separate selector tool. I really appreciate if you can provide some example code.

Thanks

Re: Multiple Selections with selector tool

Posted: Fri Aug 13, 2010 3:52 am
by 13051032
Any thoughts/tips on how i should go about it?

Thanks

Re: Multiple Selections with selector tool

Posted: Fri Aug 13, 2010 10:42 am
by 10050769
Hello asupriya,


We haven't forgotten you. We'll answer you asap.


Thanks,

Re: Multiple Selections with selector tool

Posted: Thu Aug 19, 2010 2:09 pm
by 13051032
Hope i am not forgotten yet... I need to get this multiple selector task done next week and need some guidance on how to access multiple selectors when user holds Ctrl button and clicks on fastline series.

Any help is greatly appreciated.

Re: Multiple Selections with selector tool

Posted: Fri Aug 20, 2010 12:58 pm
by 10050769
Hello asupriya,

Sorry for delay. I have made a simple code that creates a MultiSelector manually and I think you can use it in your application:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.FastLine series1, series2,series3;
        int HandleSize = 5;
        Color oldBrushColor;
        Color oldPenColor;
        bool oldGradient;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            series1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            series2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            series3 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            series1.FillSampleValues();
            series2.FillSampleValues();
            series3.FillSampleValues();
            series1.Color= Color.Blue;
            series2.Color = Color.Orange;
            series3.Color = Color.Red;
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            Steema.TeeChart.ChartClickedPart p;
            Point pp = new Point();
            if (tChart1.Series.Count != 0)
            {
                foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
                {
                    if (s.Clicked(e.X, e.Y) != -1 && ModifierKeys == Keys.Control)
                    {
                        tChart1.AutoRepaint = false;
                        pp.X = e.X;
                        pp.Y = e.Y;
                        tChart1.Chart.CalcClickedPart(pp, out p);
                        if (p.Part == Steema.TeeChart.ChartClickedPartStyle.Series)
                        {
                            DrawSelection(p);

                        }
                    }
                    else
                    {                    
                        tChart1.AutoRepaint = true;
                       
                    }
                }
            }
        }
           private void DrawSelection(Steema.TeeChart.ChartClickedPart Part)
           {
               int t, X, Y;
               int tmpStep, tmpLast, tmpCount;
               Steema.TeeChart.Styles.Series tmpSeries = Part.ASeries;
               Steema.TeeChart.Drawing.Graphics3D g = tChart1.Chart.Graphics3D;
               
         if (Part.ASeries != null)
         {
               tmpCount = tmpSeries.LastVisibleIndex - tmpSeries.FirstVisibleIndex;
               if (tmpCount == 0) tmpCount = Part.ASeries.Count;
               if (tmpCount > 20)
               {
                   tmpStep = tmpCount/ 20;
               }
               else
               {
                   tmpStep = 1;
               }
               t = tmpSeries.FirstVisibleIndex;
               if (t == -1)t = 0;
               tmpLast = tmpSeries.LastVisibleIndex;
               if (tmpLast == -1) tmpLast = Part.ASeries.Count - 1;
               oldBrushColor = g.Brush.Color;
               oldPenColor = g.Pen.Color;
               oldGradient = g.Gradient.Visible;

               g.Gradient.Visible = false;
               g.Brush.Color = Color.Black;
               g.Pen.Color = Color.Black;
               while (t < tmpLast)
               {
                   X = tmpSeries.CalcXPos(t);
                   Y = tmpSeries.CalcYPos(t);
                   g.Rectangle(RectFormPoint1(X, Y), tmpSeries.MiddleZ);
                   t += tmpStep;
               }
               g.Brush.Color = oldBrushColor;
               oldPenColor = g.Pen.Color = oldBrushColor;
               g.Gradient.Visible = oldGradient;
               series1.Color = Color.Blue;
               series2.Color = Color.Orange;
               series3.Color = Color.Red;
         }
         
        }
           private Rectangle RectFormPoint1(int X, int Y)
           {
               //return a rectangle few pixels around XY point }
               return Steema.TeeChart.Utils.FromLTRB(X - HandleSize, Y - HandleSize, X + HandleSize, Y + HandleSize);

           }
On the other hand,I have added your suggestion as Feature request number [TF02015100] to the wish-list to be considered for inclusion in future releases.

I hope will helps.

Thanks,

Re: Multiple Selections with selector tool

Posted: Fri Aug 20, 2010 2:37 pm
by yeray
Hi asupriya,

Here it is another option more similar to the example proposed here.
I've created a FastLine derived class to add two properties to it. the boolean selected and an array of SelectedPoints so you can have a different number of rectangles showing for each series.

Code: Select all

        private class MyFastLine : Steema.TeeChart.Styles.FastLine
        {
            public bool Selected = false;
            public int[] SelectedPoints;

            public MyFastLine(Steema.TeeChart.Chart c): base(c){}
        }

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            for (int i = 0; i < 3; i++)
            {
                MyFastLine myline = new MyFastLine(tChart1.Chart);
                myline.FillSampleValues();
                if (i == 0)
                    myline.SelectedPoints = new int[10];
                else
                    myline.SelectedPoints = new int[3];
            }

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (tChart1.Series.Count > 0)
            {
                foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
                {
                    if (s.Clicked(e.X, e.Y) != -1 && ModifierKeys == Keys.Control)
                    {
                        if (s is MyFastLine)
                        {
                            MyFastLine myline = s as MyFastLine;
                            myline.Selected = !myline.Selected;

                            if (myline.Selected)
                            {
                                if (myline.SelectedPoints.Length < 2)
                                {
                                    myline.SelectedPoints = new int[1];
                                    myline.SelectedPoints[0] = myline.Count / 2;
                                }
                                else
                                {
                                    myline.SelectedPoints[0] = 0;
                                    
                                    for (int i = 1; i < myline.SelectedPoints.Length-1; i++)
                                    {
                                        myline.SelectedPoints[i] = i * myline.Count / (myline.SelectedPoints.Length-1);
                                    }

                                    myline.SelectedPoints[myline.SelectedPoints.Length - 1] = myline.Count - 1;
                                }
                            }

                            tChart1.Invalidate();
                        }
                    }
                }
            }
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            int width = 6;
            Steema.TeeChart.Drawing.Graphics3D gd = tChart1.Graphics3D;

            if (tChart1.Series.Count > 0)
            {
                foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
                {
                    if (s is MyFastLine)
                    {
                        MyFastLine myline = s as MyFastLine;

                        if (myline.Selected)
                        {
                            gd.Brush.Color = myline.Color;
                            gd.Brush.Transparency = 50;

                            for (int i = 0; i < myline.SelectedPoints.Length; i++)
                            {
                                Point p = new Point(myline.CalcXPos(myline.SelectedPoints[i]), myline.CalcYPos(myline.SelectedPoints[i]));
                                Rectangle rect = tChart1.Chart.ChartRect;
                                if ((p.X >= rect.Left) && (p.X <= rect.Right) && (p.Y >= rect.Top) && (p.Y <= rect.Bottom))
                                    gd.Rectangle(p.X - width, p.Y - width, p.X + width, p.Y + width);
                            }
                        }
                    }
                }
            }
        }