Пример #1
0
        private void drawChart()
        {
            if (!isDrawing)
            {
                Console.WriteLine("Drawing...");
                isDrawing = true; // To disable multiple click event



                // Map points to one-dimensional list
                List <double> points = new List <double>();
                for (int i = 0; i < chartInputModelView.numberOfRows; i++)
                {
                    for (int j = 0; j < chartInputModelView.numberOfColumns; j++)
                    {
                        points.Add(chartInputModelView.matrixValues[i, j]);
                    }
                }


                // Getting bitmap out of 2d array
                System.Drawing.Bitmap bitmapImage = Drawer.Array2DToBitmap(chartInputModelView.matrixValues);
                var bitmapSource = Drawer.getBitmapSource(bitmapImage);

                // Creating brush for plot to be rendered
                var brush = new System.Windows.Media.ImageBrush(bitmapSource);
                oxyPlot2.PlotAreaBackground = brush;



                // Assign series of points to plot
                data2plot(points);


                // Sort axes ticks arrays so we can determine the max and min value
                chartInputModelView.xResValues.Sort();
                chartInputModelView.yResValues.Sort();

                // Get axes
                OxyPlot.Axes.Axis xAxis = Drawer.getAxisByKey(plotModelUIElement.Model, "XAxis");
                OxyPlot.Axes.Axis yAxis = Drawer.getAxisByKey(plotModelUIElement.Model, "YAxis");


                // Modify axes based on new data
                // Remove below comments to update axes according to data
                // Drawer.modifyAxisData(ref xAxis, xResValues[xResValues.Count - 1], xResValues[0], chartInputModelView.xRes, OxyColor.FromRgb(100, 10, 10));
                // Drawer.modifyAxisData(ref yAxis, yResValues[yResValues.Count - 1], yResValues[0], chartInputModelView.yRes, OxyColor.FromRgb(0, 0, 100));

                double w = chartInputModelView.numberOfRows * chartInputModelView.xRes;
                double h = chartInputModelView.numberOfColumns * chartInputModelView.yRes;

                // double widthAdjustment = Math.Abs(plotModelUIElement.Model.PlotArea.Width - plotModelUIElement.Model.PlotArea.Height);
                plotModelUIElement.Width  = w != 0 ? w : plotModelUIElement.Width;
                plotModelUIElement.Height = h != 0 ? h : plotModelUIElement.Height;

                plotModelUIElement.Model.InvalidatePlot(true); // To refresh the UI chart

                isDrawing = false;                             // You're now able to draw another chart
            }
        }
Пример #2
0
        private void ActualModel_MouseMove(object sender, OxyMouseEventArgs e)
        {
            if (mousedown)
            {
                PlotModel plot = PolynomialDiagramModel;
                ElementCollection <OxyPlot.Axes.Axis> axisList = plot.Axes;
                OxyPlot.Axes.Axis xAxis = null, yAxis = null;

                foreach (OxyPlot.Axes.Axis ax in axisList)
                {
                    if (ax.Position == OxyPlot.Axes.AxisPosition.Bottom)
                    {
                        xAxis = ax;
                    }
                    else if (ax.Position == OxyPlot.Axes.AxisPosition.Left)
                    {
                        yAxis = ax;
                    }
                }

                DataPoint p = OxyPlot.Axes.Axis.InverseTransform(e.Position, xAxis, yAxis);
                if (p.X > PlotXRange)
                {
                    PlotXRange = (int)p.X;
                    UpdatePolynomDiagram();
                }
                else if (p.X < -PlotXRange)
                {
                    PlotXRange = (int)-p.X;
                    UpdatePolynomDiagram();
                }
            }
        }
Пример #3
0
        private void UpdateXAxis()
        {
            try
            {
                //Find the SCaling
                double min = DB.GetTimeMs() / 1000 - XAxisLength;
                if (min < 0)
                {
                    min = 0;
                }

                //Find the Bottom Axis
                OxyPlot.Axes.Axis Ax = null;
                for (int i = 0; i < DataPlot.Axes.Count; i++)
                {
                    if (DataPlot.Axes[i].Position == OxyPlot.Axes.AxisPosition.Bottom)
                    {
                        Ax = DataPlot.Axes[i];
                    }
                    Double NewMin = DataPlot.Axes[0].Maximum - XAxisScale;
                }
                if (!(Ax == null))
                {
                    Ax.Minimum = min;
                    Ax.Maximum = min + XAxisLength;
                }
                DataPlot.InvalidatePlot(true);
            }
            catch (Exception ex)
            {
            }
        }
Пример #4
0
        private void PlotChart_Loaded(object sender, RoutedEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            if (PlotChart.Model == null)
            {
                PlotChart.Model = ModelCache;
            }

            DateAxis  = PlotChart.Model.Axes[0];
            PriceAxis = PlotChart.Model.Axes[1];

            // Emulates OxyPlot's internal logic of ActualMinimum / ActualMaximum calculation with padding.
            // Maximum needs to be calculated first since Minumum requires it.
            DateAxisDefaultMaximum  = CalculateActualMaximum(DateAxis);
            DateAxisDefaultMinimum  = CalculateActualMinimum(DateAxis, DateAxisDefaultMaximum);
            PriceAxisDefaultMaximum = CalculateActualMaximum(PriceAxis);
            PriceAxisDefaultMinimum = 0;

            DateAxisFullRange  = DateAxisDefaultMaximum - DateAxisDefaultMinimum;
            PriceAxisFullRange = PriceAxisDefaultMaximum - PriceAxisDefaultMinimum;

            // Reassign key bindings.
            PlotChart.Controller = new PlotController();
            PlotChart.Controller.UnbindMouseDown(OxyMouseButton.Left, OxyModifierKeys.Alt);
            PlotChart.Controller.BindMouseDown(OxyMouseButton.Left, OxyModifierKeys.Control, OxyPlot.PlotCommands.PanAt);
        }
Пример #5
0
        private void plot_MouseDown(object sender, OxyMouseDownEventArgs e)
        {
            OxyPlot.ElementCollection <OxyPlot.Axes.Axis> axisList = myModel.Axes;
            OxyPlot.Axes.Axis X_Axis = null, Y_Axis = null;


            foreach (OxyPlot.Axes.Axis ax in axisList)
            {
                if (ax.Position == OxyPlot.Axes.AxisPosition.Bottom)
                {
                    X_Axis = ax;
                }
                else if (ax.Position == OxyPlot.Axes.AxisPosition.Left)
                {
                    Y_Axis = ax;
                }
            }

            DataPoint p = OxyPlot.Axes.Axis.InverseTransform(e.Position, X_Axis, Y_Axis);

            polynomialPoints?.Add(p);

            string toAddToListView = string.Empty;

            toAddToListView += "X: " + (int)p.X + " ; Y: " + (int)p.Y;
            toAddToListView += Environment.NewLine;

            polynomialPointsListView.Items.Add(toAddToListView);
        }
Пример #6
0
        private void InitPlotterAxes()
        {
            var plotModel = new OxyPlot.PlotModel
            {
                PlotType = OxyPlot.PlotType.XY,
            };
            var X = new OxyPlot.Axes.LinearAxis
            {
                Position = OxyPlot.Axes.AxisPosition.Bottom,
                Minimum  = 0,
                Maximum  = 5.0
            };

            _filteredAxis = new OxyPlot.Axes.LinearAxis
            {
                Key      = "Filtered",
                Position = OxyPlot.Axes.AxisPosition.Left,
                Minimum  = -600,
                Maximum  = 600
            };

            _unfilteredAxis = new OxyPlot.Axes.LinearAxis
            {
                Key      = "Unfiltered",
                Position = OxyPlot.Axes.AxisPosition.Right,
                Minimum  = -40000,
                Maximum  = -20000
            };

            plotModel.Axes.Add(X);
            plotModel.Axes.Add(_filteredAxis);
            plotModel.Axes.Add(_unfilteredAxis);

            _filteredSeries = new OxyPlot.Series.LineSeries
            {
                XAxisKey = X.Key,
                YAxisKey = _filteredAxis.Key,
                Color    = OxyPlot.OxyColor.FromRgb(0, 0, 255)
            };

            _unfilteredSeries = new OxyPlot.Series.LineSeries
            {
                XAxisKey = X.Key,
                YAxisKey = _unfilteredAxis.Key,
                Color    = OxyPlot.OxyColor.FromRgb(255, 0, 0)
            };


            plotModel.Series.Add(_unfilteredSeries);
            plotModel.Series.Add(_filteredSeries);
            plotView1.Model = plotModel;
        }
Пример #7
0
        // Oxyplot's internal logic. It is needed to calculate initial graph's padding on render.
        private double CalculateActualMaximum(OxyPlot.Axes.Axis axis)
        {
            var    actualMaximum = axis.DataMaximum;
            double range         = axis.DataMaximum - axis.DataMinimum;

            if (range < double.Epsilon)
            {
                double zeroRange = axis.DataMaximum > 0 ? axis.DataMaximum : 1;
                actualMaximum += zeroRange * 0.5;
            }

            if (!double.IsNaN(axis.DataMinimum) && !double.IsNaN(actualMaximum))
            {
                double x1 = actualMaximum;
                double x0 = axis.DataMinimum;
                double dx = axis.MaximumPadding * (x1 - x0);
                return(x1 + dx);
            }

            return(actualMaximum);
        }