Пример #1
0
        public override void Render(OxyPlot.IRenderContext rc, OxyPlot.PlotModel model, AxisLayer axisLayer, int pass)
        {
            base.Render(rc, model, axisLayer, pass);
            if (model.Series.Count == 0)
            {
                return;
            }

            var      field = rc.GetType().GetField("g", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object   o     = field.GetValue(rc);
            Graphics g     = (Graphics)o;



            LineSeries series = model.Series.First(s => { if (s is LineSeries)
                                                          {
                                                              return(true);
                                                          }
                                                          else
                                                          {
                                                              return(false);
                                                          } }) as LineSeries;

            for (int i = 0; i < series.Points.Count; i++)
            {
                ScreenPoint sp  = series.Transform(series.Points[i]);
                int         key = (int)series.Points[i].X;
                if (IsCloudVisble && Cloud.Count > 0 && (Cloud[key]) != "9999")
                {
                    if (Cloud[key] != null)
                    {
                        using (Font f = new System.Drawing.Font(_PrivateFontCollection.Families[1], 12F))
                        {
                            float x = (float)sp.X;
                            float y = (float)model.Height - 50;
                            DrawText(g, new ScreenPoint(x, y), Cloud[key],
                                     OxyColor.FromRgb(CloudColor.R, CloudColor.G, CloudColor.B), f, 0F,
                                     HorizontalAlignment.Center, VerticalAlignment.Middle);
                        }
                    }
                }

                if (IsWindVisible && WindSpeeds.Count > 0 && (WindSpeeds[key]) != "9999" /* && (WindSpeeds[key]) != "0"*/)
                {
                    if (WindDirs[key] != null)
                    {
                        using (Font f = new System.Drawing.Font(_PrivateFontCollection.Families[0], 30F))
                        {
                            float x = (float)sp.X;
                            float y = (float)model.Height - 50;
                            DrawText(g, new ScreenPoint(x, y), WindSpeeds[key],
                                     OxyColor.FromRgb(WindColor.R, WindColor.G, WindColor.B), f, float.Parse(WindDirs[key]),
                                     HorizontalAlignment.Left, VerticalAlignment.Bottom, -15, 15);
                        }
                    }
                }
            }
        }
Пример #2
0
        public static PlotModel MouseDownEvent()
        {
            var model = new PlotModel { Title = "MouseDown", Subtitle = "Left click to edit or add points.", LegendSymbolLength = 40 };

            // Add a line series
            var s1 = new LineSeries
            {
                Title = "LineSeries1",
                Color = OxyColors.SkyBlue,
                MarkerType = MarkerType.Circle,
                MarkerSize = 6,
                MarkerStroke = OxyColors.White,
                MarkerFill = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5
            };
            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
                {
                    if (indexOfPointToMove >= 0)
                    {
                        // Move the point being edited.
                        s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                        model.InvalidatePlot(false);
                        e.Handled = true;
                    }
                };

            s1.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                s1.LineStyle = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton == OxyMouseButton.Left)
                    {
                        // Add a point to the line series.
                        s1.Points.Add(s1.InverseTransform(e.Position));
                        indexOfPointToMove = s1.Points.Count - 1;

                        model.InvalidatePlot(false);
                        e.Handled = true;
                    }
                };
            return model;
        }
Пример #3
0
        public static PlotModel MouseDownEvent()
        {
            var model = new PlotModel {
                Title = "MouseDown", Subtitle = "Left click to edit or add points."
            };
            var l = new Legend
            {
                LegendSymbolLength = 40
            };

            model.Legends.Add(l);

            // Add a line series
            var s1 = new LineSeries
            {
                Title                 = "LineSeries1",
                Color                 = OxyColors.SkyBlue,
                MarkerType            = MarkerType.Circle,
                MarkerSize            = 6,
                MarkerStroke          = OxyColors.White,
                MarkerFill            = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5
            };

            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
            {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                s1.LineStyle       = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Add a point to the line series.
                    s1.Points.Add(s1.InverseTransform(e.Position));
                    indexOfPointToMove = s1.Points.Count - 1;

                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };
            return(model);
        }
Пример #4
0
        public LineSeries GetSeries4Model2(string title, OxyColor color, int index)
        {
            var s1 = new LineSeries {
                Title = title,
                Color = color,
                //MarkerType = MarkerType.Circle,
                //MarkerSize = 6,
                //MarkerStroke = OxyColors.White,
                //MarkerFill = color,
                //MarkerStrokeThickness = 1.5
            };

            IndOfPointToMove.Add(index, -1);
            Annot.Add(index, new List <PointAnnotation>());


            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) => {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        IndOfPointToMove[index] = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        //int i = (int)e.HitTestResult.Index + 1;
                        //s1.Points.Insert(i,s1.InverseTransform(e.Position));
                        //IndOfPointToMove[index] = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    Model2.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
            {
                if (IndOfPointToMove[index] >= 0)
                {
                    // Move the point being edited.
                    s1.Points[IndOfPointToMove[index]]      = s1.InverseTransform(e.Position);
                    Annot[index][IndOfPointToMove[index]].X = s1.InverseTransform(e.Position).X;
                    Annot[index][IndOfPointToMove[index]].Y = s1.InverseTransform(e.Position).Y;
                    Model2.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) => {
                // Stop editing
                IndOfPointToMove[index] = -1;
                s1.LineStyle            = LineStyle.Solid;
                Model2.InvalidatePlot(false);
                e.Handled = true;
            };



            return(s1);
        }
Пример #5
0
        public PlotModel CreatePlotModel()
        {
            var model = new PlotModel()
            {
                LegendSymbolLength = 6
            };

            // Add a line series
            data = new LineSeries()
            {
                Color                 = OxyColors.SkyBlue,
                MarkerType            = MarkerType.Square,
                MarkerSize            = 5,
                MarkerStroke          = OxyColors.White,
                MarkerFill            = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5,
            };
            //data.
            bot  = new LinearAxis(AxisPosition.Bottom, control.Curve.Min, control.Curve.Max, 5, 1, "Value");
            left = new LinearAxis(AxisPosition.Left, minY - 1, maxY + 1, 10, 5, "Fan duty");
            bot.MajorGridlineStyle  = LineStyle.Dot;
            left.MajorGridlineStyle = LineStyle.Dot;
            bot.IsZoomEnabled       = false;
            left.IsZoomEnabled      = false;
            model.Axes.Add(bot);
            model.Axes.Add(left);
            model.PlotMargins     = new OxyThickness(0);
            model.IsLegendVisible = false;

            if (control.Controlled.UseCalibrated)
            {
                right = new LinearAxis(AxisPosition.Right, 0, control.Controlled.MaxRPM, 300, 100, "RPM");
                model.Axes.Add(right);
            }
            //series.Points.
            for (int i = 0; i < control.Curve.Count; i++)
            {
                data.Points.Add(new DataPoint(control.Curve[i].X, control.Curve[i].Y));
            }
            model.Series.Add(data);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            data.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = data.Transform(data.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;

                        // Show tracker label
                        UpdatePlotTracker(e, data.Points[indexOfPointToMove].X, data.Points[indexOfPointToMove].Y);
                        plotLabel.Visible = true;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        data.Points.Insert(i, data.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                        //control.Curve.AddOrdered(new PointF((float)data.Points[i].X, (float)data.Points[i].Y));
                        control.Curve.Insert(i, new PointF((float)data.Points[i].X, (float)data.Points[i].Y));

                        // Show tracker label
                        UpdatePlotTracker(e, data.Points[i].X, data.Points[i].Y);
                        plotLabel.Visible = true;
                    }

                    // Change the linestyle while editing
                    data.LineStyle = LineStyle.DashDot;
                    UpdateCurveTracker();
                    // Remember to refresh/invalidate of the plot
                    model.RefreshPlot(false);

                    control.OverrideHysteresis = true;
                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
                else
                if (e.ChangedButton == OxyMouseButton.Right)
                {
                    if (data.Points.Count == 1)
                    {
                        // Cant remove the last point
                        e.Handled = true;
                        return;
                    }

                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = data.Transform(data.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        data.Points.Remove(data.Points[indexOfNearestPoint]);
                        control.Curve.RemoveAt(indexOfNearestPoint);

                        // Change the linestyle while editing
                        data.LineStyle = LineStyle.DashDot;
                        UpdateCurveTracker();
                        // Remember to refresh/invalidate of the plot
                        model.RefreshPlot(false);

                        control.OverrideHysteresis = true;
                        // Set the event arguments to handled - no other handlers will be called.
                        e.Handled = true;
                    }
                }
            };

            data.MouseMove += (s, e) =>
            {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    var p = data.InverseTransform(e.Position);
                    if (p.X > bot.Maximum)
                    {
                        p.X = bot.Maximum;
                    }
                    if (p.Y > maxY)
                    {
                        p.Y = maxY;
                    }
                    if (p.X < bot.Minimum)
                    {
                        p.X = bot.Minimum;
                    }
                    if (p.Y < minY)
                    {
                        p.Y = minY;
                    }
                    if ((indexOfPointToMove > 0 && p.X <= data.Points[indexOfPointToMove - 1].X))
                    {
                        p.X = data.Points[indexOfPointToMove - 1].X + 1;
                    }
                    if (indexOfPointToMove < data.Points.Count - 1 && p.X >= data.Points[indexOfPointToMove + 1].X)
                    {
                        p.X = data.Points[indexOfPointToMove + 1].X - 1;
                    }
                    control.Curve[indexOfPointToMove] = new PointF((float)p.X, (float)p.Y);
                    data.Points[indexOfPointToMove]   = p;

                    UpdateCurveTracker();
                    UpdatePlotTracker(e, p.X, p.Y);

                    model.RefreshPlot(false);
                    control.OverrideHysteresis = true;
                    e.Handled = true;
                }
            };

            data.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                data.LineStyle     = LineStyle.Solid;
                plotLabel.Visible  = false;
                model.RefreshPlot(false);
                e.Handled = true;
            };

            TransformMode transformMode  = TransformMode.None;
            ScreenPoint   transformStart = new ScreenPoint();

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    var t = data.InverseTransform(e.Position);
                    // Add a point to the line series.

                    // Check for max values
                    if (t.X <= bot.Maximum && t.X >= bot.Minimum && t.Y <= maxY && t.Y >= minY)
                    {
                        // Check for x-collisions
                        if (data.Points.Count > 0 && (t.X > data.Points[data.Points.Count - 1].X || t.X < data.Points[0].X))
                        {
                            if (data.Points[0].X > t.X)
                            {
                                data.Points.Insert(0, t);
                                indexOfPointToMove = 0;
                                control.Curve.Insert(0, new PointF((float)t.X, (float)t.Y));
                            }
                            else
                            {
                                data.Points.Add(t);
                                indexOfPointToMove = data.Points.Count - 1;
                                control.Curve.Add(new PointF((float)t.X, (float)t.Y));
                            }
                        }
                    }
                    UpdateCurveTracker();
                    model.RefreshPlot(false);
                    e.Handled = true;
                }
                else if (e.ChangedButton == OxyMouseButton.Middle)
                {
                    transformStart = e.Position;
                    if (Control.ModifierKeys == Keys.Alt)
                    {
                        plot.SetCursorType(CursorType.ZoomVertical);
                        transformMode = TransformMode.Scale_LeftMost;
                    }
                    else if (Control.ModifierKeys == Keys.Control)
                    {
                        plot.SetCursorType(CursorType.ZoomVertical);
                        transformMode = TransformMode.Scale_RightMost;
                    }
                    else
                    {
                        plot.SetCursorType(CursorType.Pan);
                        transformMode = TransformMode.Pan;
                    }
                    e.Handled = true;
                }
            };

            model.MouseUp += (s, e) =>
            {
                transformMode = TransformMode.None;
                plot.SetCursorType(CursorType.Default);
                e.Handled = true;
            };

            model.MouseMove += (s, e) =>
            {
                if (transformMode == TransformMode.Pan)
                {
                    float shiftAmount = (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y);
                    // Up/Down shift transformation
                    // Check if any point would leave bounds
                    foreach (PointF p in control.Curve)
                    {
                        if ((p.Y + shiftAmount > 100) || (p.Y + shiftAmount < 0))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the shift
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y += shiftAmount;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else if (transformMode == TransformMode.Scale_RightMost)
                {
                    float scaleAmount = 1f - (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y) / 200f;
                    float constValue  = 100f - control.Curve[control.Curve.Count - 1].Y;

                    foreach (PointF p in control.Curve)
                    {
                        if ((100f - (100f - p.Y - constValue) * scaleAmount - constValue > 100f) ||
                            (100f - (100f - p.Y - constValue) * scaleAmount - constValue < 0f))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the scaling
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y = 100f - (100f - p.Y - constValue) * scaleAmount - constValue;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else if (transformMode == TransformMode.Scale_LeftMost)
                {
                    float scaleAmount = 1f + (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y) / 200f;
                    float constValue  = control.Curve[0].Y;

                    foreach (PointF p in control.Curve)
                    {
                        if (((p.Y - constValue) * scaleAmount + constValue > 100f) ||
                            ((p.Y - constValue) * scaleAmount + constValue < 0f))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the scaling
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y = (p.Y - constValue) * scaleAmount + constValue;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else
                {
                    return;
                }

                InvalidatePlot();
                transformStart = e.Position;
                e.Handled      = true;
            };
            return(model);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel" /> class.
        /// </summary>
        public MainViewModel()
        {
            // Create the plot model
            var model = new PlotModel {
                Title = "Pump RPM by Temperature"
            };

            model.IsLegendVisible = false;


            // Create two line series (markers are hidden by default)
            var s1 = new LineSeries {
                Title                 = "Series 1",
                MarkerType            = MarkerType.Circle,
                MarkerFill            = OxyColor.FromArgb(0, 15, 35, 100),
                MarkerStroke          = OxyColor.FromArgb(255, 15, 35, 100),
                MarkerStrokeThickness = 2,
                MarkerSize            = 4,
                Color                 = OxyColor.FromArgb(255, 15, 35, 100)
            };

            s1.Points.Add(new DataPoint(00, 00));
            s1.Points.Add(new DataPoint(10, 10));
            s1.Points.Add(new DataPoint(20, 20));
            s1.Points.Add(new DataPoint(30, 30));
            s1.Points.Add(new DataPoint(40, 40));
            s1.Points.Add(new DataPoint(50, 50));
            s1.Points.Add(new DataPoint(60, 60));
            s1.Points.Add(new DataPoint(70, 70));
            s1.Points.Add(new DataPoint(80, 80));
            s1.Points.Add(new DataPoint(90, 90));
            s1.Points.Add(new DataPoint(100, 100));
            // Add the series to the plot model
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) => {
                if (e.HitTestResult == null)
                {
                    return;
                }

                if (e.ChangedButton == OxyMouseButton.Right)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        s1.Points.RemoveAt(indexOfNearestPoint);
                    }

                    indexOfPointToMove = -1;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }

                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else if (s1.Points.Count <= 64)
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) => {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) => {
                // Stop editing
                if (indexOfPointToMove >= 0)
                {
                    var pt = s1.Points[indexOfPointToMove];
                    var x  = Math.Round(pt.X);
                    var y  = Math.Round(pt.Y);
                    s1.Points[indexOfPointToMove] = new DataPoint(x, y);
                }

                s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                indexOfPointToMove = -1;
                s1.LineStyle       = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) => {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Add a point to the line series.
                    s1.Points.Add(s1.InverseTransform(e.Position));
                    s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                    indexOfPointToMove = s1.Points.Count - 1;

                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            // Axes are created automatically if they are not defined

            // Set the Model property, the INotifyPropertyChanged event will make the WPF Plot control update its content
            this.Model = model;
        }