Quantcast
Channel: OxyPlot (moved to GitHub)
Viewing all articles
Browse latest Browse all 2061

New Post: Movable (drag-able) Annotation

$
0
0
Found one solution without changing original source.
made an new annotation that inherits from arrow annotation, and override mouse even in "new annotation" class.
In this way, don't need to use external tool class to modify annotation's properties.
publicclass SelectableArrowAnnotation:ArrowAnnotation { // any better name?

        DataPoint lastPoint = DataPoint.Undefined;
        bool moveStartPoint = false;
        bool moveEndPoint = false;
        OxyColor originalColor = OxyColors.White;

        protectedoverridevoid OnMouseDown(object sender, OxyPlot.OxyMouseEventArgs e) {
            if (e.ChangedButton != OxyMouseButton.Left) {
                return;
            }
            
            lastPoint = this.InverseTransform(e.Position);
            moveStartPoint = e.HitTestResult.Index != 2;
            moveEndPoint = e.HitTestResult.Index != 1;
            originalColor = this.Color;
            this.Color = OxyColors.Red;
            var model = this.PlotModel;
            model.InvalidatePlot(false);
            e.Handled = true;
        }
        protectedoverridevoid OnMouseMove(object sender, OxyPlot.OxyMouseEventArgs e) {
            var thisPoint = this.InverseTransform(e.Position);
            double dx = thisPoint.X - lastPoint.X;
            double dy = thisPoint.Y - lastPoint.Y;
            if (moveStartPoint) {
                this.StartPoint = new DataPoint(this.StartPoint.X + dx, this.StartPoint.Y + dy);
            }

            if (moveEndPoint) {
                this.EndPoint = new DataPoint(this.EndPoint.X + dx, this.EndPoint.Y + dy);
            }

            lastPoint = thisPoint;
            var model = this.PlotModel;
            model.InvalidatePlot(false);
            e.Handled = true;
        }
        protectedoverridevoid OnMouseUp(object sender, OxyPlot.OxyMouseEventArgs e) {
            this.Color = originalColor;
        }
    }

Viewing all articles
Browse latest Browse all 2061

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>