Beispiel #1
1
        public Window4()
        {
            InitializeComponent();
            this.PlotModel = new PlotModel();
            this.PlotModel.Series.Add(new FunctionSeries());
            DataContext = this;
            var worker = new BackgroundWorker { WorkerSupportsCancellation = true };
            double x = 0;
            worker.DoWork += (s, e) =>
            {
                while (!worker.CancellationPending)
                {
                    lock (this.PlotModel.SyncRoot)
                    {
                        this.PlotModel.Title = "Plot updated: " + DateTime.Now;
                        this.PlotModel.Series[0] = new FunctionSeries(Math.Sin, x, x + 4, 0.01);
                    }
                    x += 0.1;
                    PlotModel.InvalidatePlot(true);
                    Thread.Sleep(100);
                }
            };

            worker.RunWorkerAsync();
            this.Closed += (s, e) => worker.CancelAsync();
        }
        public void ChangeText(string msg, string time)
        {
            MessageView.Text = msg;
            TimeView.Text    = "Roundtrip Time: " + time;

            DataPointsBuffer.Enqueue(new DataPoint(TimePoint++, int.Parse(msg)));             //DateTime.Now.ToUniversalTime().Millisecond
            if (DataPointsBuffer.Count > 10)
            {
                DataPoint popPoint;
                DataPointsBuffer.TryDequeue(out popPoint);
            }

            var series1 = new OxyPlot.Series.LineSeries
            {
                MarkerType   = OxyPlot.MarkerType.Circle,
                MarkerSize   = 4,
                MarkerStroke = OxyPlot.OxyColors.White
            };

            foreach (var datapoint in DataPointsBuffer)
            {
                series1.Points.Add(datapoint);
            }

            plotModel.Series.Clear();
            plotModel.Series.Add(series1);
            plotModel.InvalidatePlot(true);
        }
Beispiel #3
0
        public static PlotModel MouseEvents()
        {
            var model = new PlotModel { Title = "Mouse events", Subtitle = "Left click and drag" };
            var yaxis = new LinearAxis { Position = AxisPosition.Left, Minimum = -1, Maximum = 1 };
            var xaxis = new LinearAxis { Position = AxisPosition.Bottom, Minimum = -1, Maximum = 1 };
            model.Axes.Add(yaxis);
            model.Axes.Add(xaxis);

            LineSeries s1 = null;

            // Subscribe to the mouse down event on the line series
            model.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Add a line series
                    s1 = new LineSeries
                    {
                        Title = "LineSeries" + (model.Series.Count + 1),
                        MarkerType = MarkerType.None,
                        StrokeThickness = 2
                    };
                    s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis));
                    model.Series.Add(s1);
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            model.MouseMove += (s, e) =>
            {
                if (s1 != null)
                {
                    s1.Points.Add(xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis));
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            model.MouseUp += (s, e) =>
            {
                if (s1 != null)
                {
                    s1 = null;
                    e.Handled = true;
                }
            };
            return model;
        }
        void generateSongPlotFull(PlotModel model, PlaybackInfo info)
        {
            var songpoints = (model.Series[0] as ScatterSeries).ItemsSource as List<ScatterPoint>;
            songpoints.Clear();
            model.InvalidatePlot(true);

            var keys = new int[info.Messages.Keys.Count];
            int i = 0;
            foreach (var k in info.Messages.Keys)
            {
                keys[i++] = k;
            }

            for (i = 0; i < keys.Length - 1; i++)
            {

                foreach (PlaybackMessage message in info.Messages[keys[i]])
                {
                    if (message.Message == PlaybackMessage.PlaybackMessageType.Start)
                    {
                        double duration = Math.Log(message.Duration + 1, 2) * 2;
                        songpoints.Add(new ScatterPoint(keys[i], message.Pitch % 12, duration, message.Pitch / 12));
                    }
                }
            }

            if (model.Axes.Count > 2)
            {
                model.Axes[2].IsAxisVisible = false;
                model.Axes[2].Maximum = 14;
                model.Axes[2].Minimum = -2;
            }

            model.InvalidatePlot(true);
        }
Beispiel #5
0
        public static PlotModel MouseDownEventHitTestResult()
        {
            var model = new PlotModel { Title = "MouseDown HitTestResult", Subtitle = "Reports the index of the nearest point." };

            var s1 = new LineSeries();
            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);
            s1.MouseDown += (s, e) =>
                {
                    model.Subtitle = "Index of nearest point in LineSeries: " + Math.Round(e.HitTestResult.Index);
                    model.InvalidatePlot(false);
                };

            var s2 = new ScatterSeries();
            s2.Points.Add(new ScatterPoint(0, 15));
            s2.Points.Add(new ScatterPoint(10, 45));
            s2.Points.Add(new ScatterPoint(40, 25));
            s2.Points.Add(new ScatterPoint(60, 35));
            model.Series.Add(s2);
            s2.MouseDown += (s, e) =>
                {
                    model.Subtitle = "Index of nearest point in ScatterSeries: " + (int)e.HitTestResult.Index;
                    model.InvalidatePlot(false);
                };

            return model;
        }
Beispiel #6
0
        public static void Draw(PlotModel IncomePlot,
            ObservableCollection<Transaction> transactions)
        {
            ClearGraph(IncomePlot);

            AddAxis(IncomePlot, transactions);

            AddSeries(IncomePlot, transactions);

            IncomePlot.InvalidatePlot(true);
        }
Beispiel #7
0
 public static PlotModel TrackerChangedEvent()
 {
     var model = new PlotModel { Title = "Handling the TrackerChanged event", Subtitle = "Press the left mouse button to test the tracker." };
     model.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 100));
     model.TrackerChanged += (s, e) =>
     {
         model.Subtitle = e.HitResult != null ? "Tracker item index = " + e.HitResult.Index : "Not tracking";
         model.InvalidatePlot(false);
     };
     return model;
 }
        public static Example ClickingOnAnAnnotation()
        {
            var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" };

            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left });

            var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 };
            plotModel.Annotations.Add(annotation1);

            var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 };
            plotModel.Annotations.Add(annotation2);

            EventHandler<OxyMouseDownEventArgs> handleMouseClick = (s, e) =>
            {
                plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text;
                plotModel.InvalidatePlot(false);
            };

            annotation1.MouseDown += handleMouseClick;
            annotation2.MouseDown += handleMouseClick;

            var controller = new PlotController();
            var handleClick = new DelegatePlotCommand<OxyMouseDownEventArgs>(
                (v, c, e) =>
                {
                    var args = new HitTestArguments(e.Position, 10);
                    var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation);
                    if (firstHit != null)
                    {
                        e.Handled = true;
                        plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text;
                        plotModel.InvalidatePlot(false);
                    }
                });
            controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleClick);

            return new Example(plotModel, controller);
        }
Beispiel #9
0
        public static PlotModel AnnotationLayers()
        {
            var model = new PlotModel { Title = "AnnotationLayers" };

            var a1 = new RectangleAnnotation { MinimumX = 10, MaximumX = 20, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowAxes };
            var a2 = new RectangleAnnotation { MinimumX = 30, MaximumX = 40, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowSeries };
            var a3 = new RectangleAnnotation { MinimumX = 50, MaximumX = 60, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.AboveSeries };
            model.Annotations.Add(a1);
            model.Annotations.Add(a2);
            model.Annotations.Add(a3);
            var s1 = new FunctionSeries(Math.Sin, 0, 100, 0.01);
            model.Series.Add(s1);
            a1.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation below axes";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            a2.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation below series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            a3.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked annotation above series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };
            s1.MouseDown += (s, e) =>
            {
                model.Subtitle = "Clicked series";
                model.InvalidatePlot(true);
                e.Handled = true;
            };

            return model;
        }
        public static PlotModel AddAnnotations()
        {
            var model = new PlotModel { Title = "Add arrow annotations", Subtitle = "Press and drag the left mouse button" };
            var xaxis = new LinearAxis { Position = AxisPosition.Bottom };
            var yaxis = new LinearAxis { Position = AxisPosition.Left };
            model.Axes.Add(xaxis);
            model.Axes.Add(yaxis);
            model.Series.Add(new FunctionSeries(x => Math.Sin(x / 4) * Math.Acos(Math.Sin(x)), 0, Math.PI * 8, 2000, "sin(x/4)*acos(sin(x))"));

            ArrowAnnotation tmp = null;

            // Add handlers to the PlotModel's mouse events
            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Create a new arrow annotation
                    tmp = new ArrowAnnotation();
                    tmp.StartPoint = tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis);
                    model.Annotations.Add(tmp);
                    e.Handled = true;
                }
            };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            model.MouseMove += (s, e) =>
            {
                if (tmp != null)
                {
                    // Modify the end point
                    tmp.EndPoint = xaxis.InverseTransform(e.Position.X, e.Position.Y, yaxis);
                    tmp.Text = string.Format("Y = {0:0.###}", tmp.EndPoint.Y);

                    // Redraw the plot
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            model.MouseUp += (s, e) =>
                {
                    if (tmp != null)
                    {
                        tmp = null;
                        e.Handled = true;
                    }
                };

            return model;
        }
Beispiel #11
0
        public MainWindow()
        {
            ThePlotModel = new PlotModel("Plot");
            ObsFunctionList = new ObservableCollection<FunctionList>();

            SetupPlot();

            XLogarithmCheck = false;
            YLogarithmCheck = false;

            DataContext = this;
            InitializeComponent();
            ItemList.ItemsSource = ObsFunctionList;
            ThePlotModel.InvalidatePlot(true);
        }
        public static PlotModel AddSeriesByMouseDownEvent()
        {
            var model = new PlotModel { Title = "MouseDown", Subtitle = "Left click to add series.", LegendSymbolLength = 40 };

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    double a = model.Series.Count + 1;
                    model.Series.Add(new FunctionSeries(x => Math.Sin(a * x), 0, 10, 1000));
                    model.InvalidatePlot(true);
                    e.Handled = true;
                }
            };

            return model;
        }
Beispiel #13
0
        public void drawStepResponse(double[] RespTime, double[] Resp, UInt32 RespLen)
        {
            //Mag
            seriesBodeMag.Points.Clear();
            for (int k = 0; k < RespLen; k++)
            {
                seriesBodeMag.Points.Add(new DataPoint(RespTime[k], Resp[k]));
            }
            m_PlotModelBodeMag.Axes[0].Minimum = 0; m_PlotModelBodeMag.Axes[0].Maximum = 3e-3;
            m_PlotModelBodeMag.Axes[1].Minimum = -0.1; m_PlotModelBodeMag.Axes[1].Maximum = 3;

            m_PlotModelBodeMag.Axes[0].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[0].MinorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MinorGridlineStyle = LineStyle.Dash;

            m_PlotModelBodeMag.Series.Clear();
            m_PlotModelBodeMag.Series.Add(seriesBodeMag);
            m_PlotModelBodeMag.InvalidatePlot(true);
        }
Beispiel #14
0
        public void drawNichols(double[] OL_Mag, double[] OL_Ph, UInt32 FreqLen)
        {
            //nic
            seriesBodeMag.Points.Clear();
            for (int k = 0; k < FreqLen; k++)
            {
                seriesBodeMag.Points.Add(new DataPoint(OL_Ph[k], OL_Mag[k]));
            }
            m_PlotModelBodeMag.Axes[0].Minimum = -360; m_PlotModelBodeMag.Axes[0].Maximum = 0;
            m_PlotModelBodeMag.Axes[1].Minimum = -30; m_PlotModelBodeMag.Axes[1].Maximum = 10;

            m_PlotModelBodeMag.Axes[0].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[0].MinorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MinorGridlineStyle = LineStyle.Dash;

            m_PlotModelBodeMag.Series.Clear();
            m_PlotModelBodeMag.Series.Add(seriesBodeMag);
            m_PlotModelBodeMag.InvalidatePlot(true);
        }
        public static Example MouseHandlingExample()
        {
            var model = new PlotModel { Title = "Mouse handling example" };
            var series = new ScatterSeries();
            model.Series.Add(series);

            // Create a command that adds points to the scatter series
            var command = new DelegatePlotCommand<OxyMouseEventArgs>(
                (v, c, a) =>
                {
                    var point = series.InverseTransform(a.Position);
                    series.Points.Add(new ScatterPoint(point.X, point.Y));
                    model.InvalidatePlot(true);
                });

            var controller = new PlotController();
            controller.BindMouseDown(OxyMouseButton.Left, command);

            return new Example(model, controller);
        }
Beispiel #16
0
        public void drawBode(double[] FreqHz, double[] CL_Mag, double[] CL_Ph, UInt32 FreqLen)
        {
            //Mag
            seriesBodeMag.Points.Clear();
            for (int k = 0; k < FreqLen; k++)
            {
                seriesBodeMag.Points.Add(new DataPoint(FreqHz[k], CL_Mag[k]));
            }
            m_PlotModelBodeMag.Axes[0].Minimum = 0; m_PlotModelBodeMag.Axes[0].Maximum = FreqHz[FreqLen - 1];
            m_PlotModelBodeMag.Axes[1].Minimum = -20; m_PlotModelBodeMag.Axes[1].Maximum = 10;

            m_PlotModelBodeMag.Axes[0].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[0].MinorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodeMag.Axes[1].MinorGridlineStyle = LineStyle.Dash;

            m_PlotModelBodeMag.Series.Clear();
            m_PlotModelBodeMag.Series.Add(seriesBodeMag);
            m_PlotModelBodeMag.InvalidatePlot(true);

            //Phase
            seriesBodePh.Points.Clear();
            for (int k = 0; k < FreqLen; k++)
            {
                seriesBodePh.Points.Add(new DataPoint(FreqHz[k], CL_Ph[k]));
            }
            m_PlotModelBodePh.Axes[0].Minimum            = 0; m_PlotModelBodePh.Axes[0].Maximum = FreqHz[FreqLen - 1];
            m_PlotModelBodePh.Axes[1].Minimum            = -360; m_PlotModelBodePh.Axes[1].Maximum = 360;
            m_PlotModelBodePh.Axes[0].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodePh.Axes[0].MinorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodePh.Axes[1].MajorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodePh.Axes[1].MinorGridlineStyle = LineStyle.Dash;
            m_PlotModelBodePh.Series.Clear();
            m_PlotModelBodePh.Series.Add(seriesBodePh);
            m_PlotModelBodePh.InvalidatePlot(true);
        }
Beispiel #17
0
        public static PlotModel RectangleAnnotationClick()
        {
            var plotModel = new PlotModel { Title = "RectangleAnnotation click" };

            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left });

            var annotation = new RectangleAnnotation() { MinimumX = 10, MaximumX = 60, MinimumY = 10, MaximumY = 20 };
            plotModel.Annotations.Add(annotation);

            int i = 0;
            annotation.MouseDown += (s, e) =>
            {
                annotation.Text = "Clicked " + (++i) + " times.";
                plotModel.InvalidatePlot(false);
            };

            return plotModel;
        }
Beispiel #18
0
        public static PlotModel TouchSeries()
        {
            var model = new PlotModel { Title = "Touch on a LineSeries" };
            var series = new LineSeries();
            series.Points.Add(new DataPoint(0, 0));
            series.Points.Add(new DataPoint(10, 10));
            model.Series.Add(series);

            series.TouchStarted += (s, e) =>
            {
                model.Subtitle = "The touch gesture started on the LineSeries";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            series.TouchDelta += (s, e) =>
            {
                series.Points.Add(series.InverseTransform(e.Position));
                model.InvalidatePlot(false);
            };

            series.TouchCompleted += (s, e) =>
            {
                model.Subtitle = "The touch gesture completed";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return model;
        }
Beispiel #19
0
        public static PlotModel Hover()
        {
            var model = new PlotModel { Title = "Hover" };
            LineSeries series = null;

            model.MouseEnter += (s, e) =>
            {
                model.Subtitle = "The mouse entered";
                series = new LineSeries();
                model.Series.Add(series);
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseMove += (s, e) =>
            {
                if (series != null && series.XAxis != null)
                {
                    series.Points.Add(series.InverseTransform(e.Position));
                    model.InvalidatePlot(false);
                }
            };

            model.MouseLeave += (s, e) =>
            {
                model.Subtitle = "The mouse left";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return model;
        }
Beispiel #20
0
        public static PlotModel SelectRange()
        {
            var model = new PlotModel { Title = "Select range", Subtitle = "Left click and drag to select a range." };
            model.Series.Add(new FunctionSeries(Math.Cos, 0, 40, 0.1));

            var range = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue), MinimumX = 0, MaximumX = 0 };
            model.Annotations.Add(range);

            double startx = double.NaN;

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    startx = range.InverseTransform(e.Position).X;
                    range.MinimumX = startx;
                    range.MaximumX = startx;
                    model.InvalidatePlot(true);
                    e.Handled = true;
                }
            };
            model.MouseMove += (s, e) =>
                {
                    if (!double.IsNaN(startx))
                    {
                        var x = range.InverseTransform(e.Position).X;
                        range.MinimumX = Math.Min(x, startx);
                        range.MaximumX = Math.Max(x, startx);
                        range.Text = string.Format("∫ cos(x) dx =  {0:0.00}", Math.Sin(range.MaximumX) - Math.Sin(range.MinimumX));
                        model.Subtitle = string.Format("Integrating from {0:0.00} to {1:0.00}", range.MinimumX, range.MaximumX);
                        model.InvalidatePlot(true);
                        e.Handled = true;
                    }
                };

            model.MouseUp += (s, e) =>
            {
                startx = double.NaN;
            };

            return model;
        }
        public static PlotModel PolygonAnnotation()
        {
            var model = new PlotModel("PolygonAnnotation", "Click the polygon");
            model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -20, 20));
            model.Axes.Add(new LinearAxis(AxisPosition.Left, -10, 10));
            var pa = new PolygonAnnotation
                {
                    Points =
                        new[]
                            {
                                new DataPoint(4, -2), new DataPoint(8, -4), new DataPoint(17, 7), new DataPoint(5, 8),
                                new DataPoint(2, 5)
                            },
                    Text = "Polygon 1"
                };

            // Handle left mouse clicks
            int hitCount = 1;
            pa.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton != OxyMouseButton.Left)
                    {
                        return;
                    }

                    pa.Text = "Hit # " + hitCount++;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };

            model.Annotations.Add(pa);
            return model;
        }
Beispiel #22
0
        public static PlotModel ArrowAnnotation()
        {
            var model = new PlotModel { Title = "ArrowAnnotation", Subtitle = "Click and drag the arrow." };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -40, Maximum = 60 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });

            var arrow = new ArrowAnnotation { StartPoint = new DataPoint(8, 4), EndPoint = new DataPoint(0, 0), Text = "Move me!" };

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

            // Handle left mouse clicks
            arrow.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                lastPoint = arrow.InverseTransform(e.Position);
                moveStartPoint = e.HitTestResult.Index != 2;
                moveEndPoint = e.HitTestResult.Index != 1;
                originalColor = arrow.Color;
                arrow.Color = OxyColors.Red;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            arrow.MouseMove += (s, e) =>
                {
                    var thisPoint = arrow.InverseTransform(e.Position);
                    double dx = thisPoint.X - lastPoint.X;
                    double dy = thisPoint.Y - lastPoint.Y;
                    if (moveStartPoint)
                    {
                        arrow.StartPoint = new DataPoint(arrow.StartPoint.X + dx, arrow.StartPoint.Y + dy);
                    }

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

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

            // Handle mouse up (note: this is only called when the mousedown event was handled)
            arrow.MouseUp += (s, e) =>
            {
                arrow.Color = originalColor;
            };
            model.Annotations.Add(arrow);
            return model;
        }
Beispiel #23
0
        public static PlotModel LineAnnotation()
        {
            var model = new PlotModel { Title = "LineAnnotation", Subtitle = "Click and drag the annotation line." };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
            var la = new LineAnnotation { Type = LineAnnotationType.Vertical, X = 4 };
            la.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton != OxyMouseButton.Left)
                    {
                        return;
                    }

                    la.StrokeThickness *= 5;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            la.MouseMove += (s, e) =>
                {
                    la.X = la.InverseTransform(e.Position).X;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };
            la.MouseUp += (s, e) =>
                {
                    la.StrokeThickness /= 5;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };
            model.Annotations.Add(la);
            return model;
        }
Beispiel #24
0
        private void setupPlot()
        {
            tempModel = new PlotModel("Graph Zahl");

            //Axes
            LinearAxis la = new LinearAxis();
            la.Position = AxisPosition.Left;
            la.StringFormat = "#°";

            tempModel.Axes.Add(la);
            tempModel.Axes.Add(new DateTimeAxis(AxisPosition.Bottom));

            foreach (string prop in _plotProperties)
            {
                //Data Series
                LineSeries ls = new LineSeries(prop);
                _plotData.Add(prop, ls);

                tempModel.Series.Add(ls);
            }

            tempModel.InvalidatePlot(true);
        }
        private void CreatePlotModel()
        {
            UnrealizedPnLChartModel = new PlotModel { Title = "Unrealized Profit/Loss" };

            var linearAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                StringFormat = "c0",
                MajorGridlineStyle = LineStyle.Dash
            };
            
            UnrealizedPnLChartModel.Axes.Add(linearAxis);

            var categoryAxis = new CategoryAxis
            {
                Position = AxisPosition.Left,
                MinorStep = 1,
                ItemsSource = UnrealizedPnL,
                LabelField = "Item1",
                GapWidth = 0.5,
                Minimum = -1
            };
            UnrealizedPnLChartModel.Axes.Add(categoryAxis);

            var series = new BarSeries
            {
                FillColor = OxyColors.DodgerBlue,
                StrokeColor = OxyColor.FromRgb(67, 110, 160),
                StrokeThickness = 1,
                ItemsSource = UnrealizedPnL,
                ValueField = "Item2",
                LabelFormatString = "{0:c0}",
                LabelPlacement = LabelPlacement.Inside
            };

            UnrealizedPnLChartModel.Series.Add(series);
            
            UnrealizedPnLChartModel.InvalidatePlot(true);
        }
        /// <summary>
        /// Function that sets up the <see cref="TimePlotModel"/>.
        /// </summary>
        public void SetUpTimePlotModel()
        {
            TimePlotModel = new PlotModel();

            var xAxis = new DateTimeAxis() { Position = AxisPosition.Bottom, IntervalLength = 40, StringFormat = "HH:mm" };
            var yAxis = new LinearAxis() { Position = AxisPosition.Left, IntervalLength = 30 };

            TimePlotModel.Axes.Add(xAxis);
            TimePlotModel.Axes.Add(yAxis);

            var lineSeries = new LineSeries { TrackerFormatString = "Time: {2:HH:mm}\n{3}: {4:0.###}" };

            TimePlotModel.Series.Add(lineSeries);

            TimePlotModel.InvalidatePlot(true);
        }
        public static PlotModel IsVisibleFalse()
        {
            var model = new PlotModel { Title = "LineSeries with IsVisible = false", Subtitle = "Click to change the IsVisible property for LineSeries 2" };

            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0, Maximum = 50 });

            var s1 = CreateExampleLineSeries(38);
            s1.Title = "LineSeries 1";
            model.Series.Add(s1);

            var s2 = CreateExampleLineSeries(39);
            s2.Title = "LineSeries 2";
            s2.IsVisible = false;
            model.Series.Add(s2);

            // handle mouse clicks to change visibility
            model.MouseDown += (s, e) => { s2.IsVisible = !s2.IsVisible; model.InvalidatePlot(true); };

            return model;
        }
Beispiel #28
0
        public static PlotModel ClickingOnAnAnnotation()
        {
            var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" };

            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
            plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left });

            var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 };
            plotModel.Annotations.Add(annotation1);

            var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 };
            plotModel.Annotations.Add(annotation2);

            EventHandler<OxyMouseDownEventArgs> handleMouseClick = (s, e) =>
            {
                plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text;
                plotModel.InvalidatePlot(false);
            };

            annotation1.MouseDown += handleMouseClick;
            annotation2.MouseDown += handleMouseClick;

            return plotModel;
        }
        public static PlotModel ImageAnnotation()
        {
            var model = new PlotModel("ImageAnnotation", "Click the image");
            model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -20, 20));
            model.Axes.Add(new LinearAxis(AxisPosition.Left, -10, 10));

            OxyImage image;
            var assembly = Assembly.GetExecutingAssembly();
            using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png"))
            {
                image = new OxyImage(stream);
            }

            var ia = new ImageAnnotation(image, new DataPoint(4, 2), HorizontalAlignment.Right);
            model.Annotations.Add(ia);

            // Handle left mouse clicks
            ia.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return model;
        }
Beispiel #30
0
        public static PlotModel PolygonAnnotation()
        {
            var model = new PlotModel { Title = "PolygonAnnotation", Subtitle = "Click the polygon" };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -20, Maximum = 20 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 });
            var pa = new PolygonAnnotation
                {
                    Text = "Polygon 1"
                };
            pa.Points.AddRange(new[]
                            {
                                new DataPoint(4, -2), new DataPoint(8, -4), new DataPoint(17, 7), new DataPoint(5, 8),
                                new DataPoint(2, 5)
                            });

            // Handle left mouse clicks
            int hitCount = 1;
            pa.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton != OxyMouseButton.Left)
                    {
                        return;
                    }

                    pa.Text = "Hit # " + hitCount++;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };

            model.Annotations.Add(pa);
            return model;
        }
Beispiel #31
0
        public static PlotModel TextAnnotation()
        {
            var model = new PlotModel { Title = "TextAnnotation", Subtitle = "Click the text" };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
            var ta = new TextAnnotation
            {
                TextPosition = new DataPoint(4, -2),
                Text = "Click here"
            };

            // Handle left mouse clicks
            ta.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                ta.Background = ta.Background.IsUndefined() ? OxyColors.LightGreen : OxyColors.Undefined;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.Annotations.Add(ta);
            return model;
        }
Beispiel #32
0
        public static PlotModel ImageAnnotation()
        {
            var model = new PlotModel { Title = "ImageAnnotation", Subtitle = "Click the image" };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });

            OxyImage image;
#if UNIVERSAL
            var assembly = typeof(PlotModel).GetTypeInfo().Assembly;
#else
            var assembly = Assembly.GetExecutingAssembly();
#endif
            using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png"))
            {
                image = new OxyImage(stream);
            }

            var ia = new ImageAnnotation { ImageSource = image, X = new PlotLength(4, PlotLengthUnit.Data), Y = new PlotLength(2, PlotLengthUnit.Data), HorizontalAlignment = HorizontalAlignment.Right };
            model.Annotations.Add(ia);

            // Handle left mouse clicks
            ia.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return model;
        }
Beispiel #33
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;
        }
        public static PlotModel OffsetAngles()
        {
            var model = new PlotModel
            {
                Title = "Offset angle axis",
                PlotType = PlotType.Polar,
                PlotAreaBorderThickness = new OxyThickness(0),
                PlotMargins = new OxyThickness(60, 20, 4, 40)
            };

            var angleAxis = new AngleAxis
            {
                Minimum = 0,
                Maximum = Math.PI * 2,
                MajorStep = Math.PI / 4,
                MinorStep = Math.PI / 16,
                StringFormat = "0.00",
                StartAngle = 30,
                EndAngle = 390
            };
            model.Axes.Add(angleAxis);
            model.Axes.Add(new MagnitudeAxis());
            model.Series.Add(new FunctionSeries(t => t, t => t, 0, Math.PI * 6, 0.01));

            // Subscribe to the mouse down event on the line series.
            model.MouseDown += (s, e) =>
            {
                var increment = 0d;

                // Increment and decrement must be in degrees (corresponds to the StartAngle and EndAngle properties).
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    increment = 15;
                }

                if (e.ChangedButton == OxyMouseButton.Right)
                {
                    increment = -15;
                }

                if (Math.Abs(increment) > double.Epsilon)
                {
                    angleAxis.StartAngle += increment;
                    angleAxis.EndAngle += increment;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            return model;
        }