Example #1
0
        private void UpdateAnnotaion(PointF p)
        {
            _end = p;
            var rect = new RectangleF
            {
                X      = Math.Min(_start.X, _end.X),
                Y      = Math.Min(_start.Y, _end.Y),
                Width  = Math.Abs(_end.X - _start.X),
                Height = Math.Abs(_end.Y - _start.Y)
            };
            var location = new PointF(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);

            string annoToAdd = _annotationToAdd.GetType().Name;

            switch (annoToAdd)
            {
            case "Text":     //Do Nothing
                break;

            case "Line":
                var line = _annotationToAdd as Line;
                line.Start = Helpers.CoordsToAnnoPoint(Chart, line, _start);
                line.End   = Helpers.CoordsToAnnoPoint(Chart, line, _end);
                break;

            case "Circle":
                var circle = _annotationToAdd as Circle;
                circle.Location = Helpers.CoordsToAnnoPoint(Chart, circle, _start);
                circle.Radius   = Helpers.Distance(_start.X, _start.Y, _end.X, _end.Y);
                break;

            case "Ellipse":
                var ellipse = _annotationToAdd as Ellipse;
                ellipse.Location = Helpers.CoordsToAnnoPoint(Chart, ellipse, _start);
                ellipse.Height   = rect.Height * 2;
                ellipse.Width    = rect.Width * 2;
                break;

            case "Rectangle":
                var rectangle = _annotationToAdd as C1.Win.Chart.Annotation.Rectangle;
                rectangle.Location = Helpers.CoordsToAnnoPoint(Chart, rectangle, location);
                rectangle.Height   = rect.Height;
                rectangle.Width    = rect.Width;
                break;

            case "Square":
                var square = _annotationToAdd as Square;
                square.Location = Helpers.CoordsToAnnoPoint(Chart, square, location);
                square.Length   = Math.Max(rect.Height, rect.Width);
                break;

            case "Polygon":
                var polygon = _annotationToAdd as Polygon;
                PolygonResizeFunc(polygon, rect);
                break;
            }
        }
Example #2
0
 private void AddAnnotation(PointF p)
 {
     _start = p;
     try
     {
         _annotationToAdd            = (AnnotationBase)Activator.CreateInstance(NewAnnotationType);
         _annotationToAdd.Attachment = Attachment;
         _annotationToAdd.Location   = Helpers.CoordsToAnnoPoint(Chart, _annotationToAdd, _start);
         if (_annotationToAdd is Text)
         {
             ((Text)_annotationToAdd).Content = "New Text Annotation";
             ShowContentEditor(_annotationToAdd, p);
             ContentEditor.Accept = () =>
             {
                 this.Annotations.Add(_annotationToAdd);
                 SelectedAnnotation = _annotationToAdd;
                 HideContentEditor();
             };
             ContentEditor.Reject = () =>
             {
                 _annotationToAdd = null;
                 HideContentEditor();
             };
             return;
         }
         if (_annotationToAdd is Polygon)
         {
             var polygon = PolygonAddFunc(_start);
             polygon.Attachment = Attachment;
             for (int i = 0; i < polygon.Points.Count; i++)
             {
                 polygon.Points[i] = Helpers.CoordsToAnnoPoint(Chart, polygon, polygon.Points[i]);
             }
             _annotationToAdd = polygon;
         }
         this.Annotations.Add(_annotationToAdd);
         SelectedAnnotation = _annotationToAdd;
         _drawing           = true; //Start drawing on MouseMove
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        protected override void SetupChart()
        {
            var    ls = new List <Point>();
            Random r  = new Random();

            for (int i = 0; i < 100; i++)
            {
                ls.Add(new Point(i, r.Next(0, 1000)));
            }

            this.flexChart1.Header.Content    = "Annotated Data Points";
            this.flexChart1.Header.Style.Font = StyleInfo.ChartHeaderFont;

            flexChart1.DataSource     = ls;
            flexChart1.ChartType      = C1.Chart.ChartType.Scatter;
            flexChart1.ToolTip.Active = false;
            flexChart1.Series.Clear();
            flexChart1.Series.Add(new C1.Win.Chart.Series
            {
                Binding  = "Y",
                BindingX = "X"
            });
            flexChart1.MouseDown += FlexChart1_MouseDown;
            flexChart1.KeyDown   += FlexChart1_KeyDown;
            flexChart1.Rendered  += FlexChart1_Rendered;

            #region Annotation Setup
            al = new EditableAnnotationLayer(flexChart1);
            al.PolygonAddFunc = (pt) =>
            {
                return(new Polygon(string.Empty)
                {
                    Points =
                    {
                        pt, pt, pt
                    }
                });
            };

            al.PolygonResizeFunc = (poly, rectangle) =>
            {
                var top   = new PointF((float)(rectangle.Left + rectangle.Width / 2), rectangle.Y);
                var left  = new PointF(rectangle.Left, rectangle.Bottom);
                var right = new PointF(rectangle.Right, rectangle.Bottom);
                poly.Points[0] = Helpers.CoordsToAnnoPoint(flexChart1, poly, top);
                poly.Points[1] = Helpers.CoordsToAnnoPoint(flexChart1, poly, left);
                poly.Points[2] = Helpers.CoordsToAnnoPoint(flexChart1, poly, right);
            };

            al.ContentEditor = new AnnotationEditor();
            al.Annotations.Add(new C1.Win.Chart.Annotation.Rectangle
            {
                Attachment = AnnotationAttachment.Absolute,
                Content    = "Absolute",
                Location   = new PointF(700, 150),
                Width      = 100,
                Height     = 50,
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Ellipse
            {
                Attachment = AnnotationAttachment.Relative,
                Content    = "Relative",
                Width      = 70,
                Height     = 30,
                Location   = new PointF(0.4f, 0.2f),
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Square
            {
                Attachment = AnnotationAttachment.DataCoordinate,
                Content    = "DataCoordinate",
                Location   = new PointF(70, 500),
                Length     = 100,
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Text("Text Annotation")
            {
                Attachment = AnnotationAttachment.Absolute,
                Location   = new PointF(400, 50),
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Line("Slanted Line")
            {
                Attachment = AnnotationAttachment.Absolute,
                Start      = new PointF(150, 200),
                End        = new PointF(300, 300),
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Line("Horizontal Line")
            {
                Attachment = AnnotationAttachment.Relative,
                Start      = new PointF(0, 0.8f),
                End        = new PointF(1.2f, 0.8f),
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Line("Vertical Line")
            {
                Attachment = AnnotationAttachment.Relative,
                Start      = new PointF(0.7f, 0),
                End        = new PointF(0.7f, 1.2f),
            });
            al.Annotations.Add(new C1.Win.Chart.Annotation.Polygon("Polygon")
            {
                Attachment = AnnotationAttachment.Absolute,
                Points     =
                {
                    new PointF(100, 150),
                    new PointF(150, 100),
                    new PointF(200, 150),
                    new PointF(190, 200),
                    new PointF(110, 200),
                }
            });
            #endregion
        }
Example #4
0
        private void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (AllowMove && SelectedAnnotation != null && _isDragging && _flexChart.PlotRect.Contains(e.Location))
            {
                Cursor.Current = Cursors.SizeAll;
                _newPoint      = e.Location;
                var diff = new PointF
                {
                    X = _newPoint.X - _oldPoint.X,
                    Y = _newPoint.Y - _oldPoint.Y
                };

                if (SelectedAnnotation is Line)
                {
                    var line  = SelectedAnnotation as Line;
                    var start = Helpers.AnnoPointToCoords(_flexChart, line, line.Start);
                    var end   = Helpers.AnnoPointToCoords(_flexChart, line, line.End);

                    start = start.OffSet(diff);
                    end   = end.OffSet(diff);

                    line.Start = Helpers.CoordsToAnnoPoint(_flexChart, line, start);
                    line.End   = Helpers.CoordsToAnnoPoint(_flexChart, line, end);
                }
                else if (SelectedAnnotation is Polygon)
                {
                    var polygon = SelectedAnnotation as Polygon;
                    for (int i = 0; i < polygon.Points.Count; i++)
                    {
                        var pt = Helpers.AnnoPointToCoords(_flexChart, polygon, polygon.Points[i]);
                        pt = pt.OffSet(diff);
                        polygon.Points[i] = Helpers.CoordsToAnnoPoint(_flexChart, polygon, pt);
                    }
                }
                else
                {
                    var location = Helpers.AnnoPointToCoords(_flexChart, SelectedAnnotation, SelectedAnnotation.Location);
                    location = location.OffSet(diff);
                    SelectedAnnotation.Location = Helpers.CoordsToAnnoPoint(_flexChart, SelectedAnnotation, location);
                }
                _oldPoint = _newPoint;
                return;
            }

            if (this.AllowAdd && this._start != PointF.Empty)
            {
                if (_drawing)
                {
                    this.UpdateAnnotaion(e.Location);
                }
                else
                {
                    SizeF sz = new SizeF
                    {
                        Height = Math.Abs(this._start.Y - (float)e.Location.Y),
                        Width  = Math.Abs(this._start.X - (float)e.Location.X)
                    };
                    Size threshold = SystemInformation.DragSize;
                    if (sz.Width > (float)threshold.Width && sz.Height > (float)threshold.Height)
                    {
                        this.AddAnnotation(this._start);
                    }
                }
            }
        }