Beispiel #1
0
        /// <summary>
        /// Отрисовывает скругления.
        /// GetDataMass() должен быть объявлен ранее.
        /// </summary>
        /// <param name="color">Цвет скруглений</param>
        public List <OxyPlot.Series.FunctionSeries> GetFunctionSeriesList(OxyPlot.OxyColor color)
        {
            double deg;
            double angle;
            var    FunctionSeriesList = new List <OxyPlot.Series.FunctionSeries>();
            var    S = new OxyPlot.Series.FunctionSeries();
            double r = 0;
            Func <double, double> func;

            OxyPlot.Series.FunctionSeries F;

            for (int i = 0; i < Actions.Count; i++)
            {
                if (DataMass[i] != null && Actions[i].ToUpper().Contains("ARC"))
                {
                    Double.TryParse(Regex.Replace(Actions[i], @"[^\d]+", ""), out deg);
                    r    = Math.Sqrt(Math.Pow(DataMass[i][1].X - DataMass[i][0].X, 2) + Math.Pow(DataMass[i][1].Y - DataMass[i][0].Y, 2)); //Вычисляем радиус
                    func = (x) => DataMass[i][1].Y + Math.Sqrt(Math.Pow(r, 2) - Math.Pow(x - DataMass[i][1].X, 2));                        //Формула дуги
                    F    = new OxyPlot.Series.FunctionSeries(func, DataMass[i][1].X, Math.Abs(r) + DataMass[i][1].X, 0.001)
                    {
                        Color = color
                    };
                    angle = Angle + deg;

                    for (int j = 0; j < F.Points.Count; j++)
                    {
                        F.Points[j] = RotatePoint(F.Points[j], DataMass[i][1], angle);
                    }

                    FunctionSeriesList.Add(F);
                }
            }

            return(FunctionSeriesList);
        }
Beispiel #2
0
        public void Init()
        {
            Samples = new ObservableCollection <TestData>
            {
                new TestData {
                    Time = new TimeSpan(0, 0, 0), Value = 0, Tag = "A"
                },
                new TestData {
                    Time = new TimeSpan(0, 0, 1), Value = 2, Tag = "B"
                },
                new TestData {
                    Time = new TimeSpan(0, 0, 2), Value = 4, Tag = "C"
                },
                new TestData {
                    Time = new TimeSpan(0, 0, 3), Value = 6, Tag = "D"
                },
                new TestData {
                    Time = new TimeSpan(0, 0, 4), Value = 0, Tag = "E"
                },
                new TestData {
                    Time = new TimeSpan(0, 0, 5), Value = 2, Tag = "F"
                },
            };

            Model.Title = "PlotView";

            // 軸の初期化
            X.Position = OxyPlot.Axes.AxisPosition.Bottom;
            Y.Position = OxyPlot.Axes.AxisPosition.Left;

            // 線グラフ
            LineSeries             = new OxyPlot.Series.LineSeries();
            LineSeries.Title       = "Custom";
            LineSeries.ItemsSource = Samples;
            LineSeries.DataFieldX  = nameof(TestData.Time);
            LineSeries.DataFieldY  = nameof(TestData.Value);

            var a = 1;
            var b = 2;

            // 関数グラフ
            FunctionSeries = new OxyPlot.Series.FunctionSeries
                             (
                x => a * x + b, 0, 30, 5, "Y = ax + b"
                             );

            Model.Axes.Add(X);
            Model.Axes.Add(Y);
            Model.Series.Add(LineSeries);
            Model.Series.Add(FunctionSeries);

            Model.InvalidatePlot(true);
        }
Beispiel #3
0
        private void btn_ExportPNG_Click(object sender, EventArgs e)
        {
            if (loaded.Count < 2)
            {
                Log.LogMessage("You must load all data before exporting!");
                return;
            }

            int height = 0;
            if (!int.TryParse(txt_height.Text, out height))
            {
                Log.LogMessage("Height must be an integer");
                return;
            }

            int width = 0;
            if (!int.TryParse(txt_width.Text, out width))
            {
                Log.LogMessage("Width must be an integer");
                return;
            }

            int offset = 0;
            if (!int.TryParse(txt_PlotDataOffset.Text, out offset))
            {
                Log.LogMessage("Offset must be an integer");
                return;
            }

            double pointSize = 0;
            if (!double.TryParse(txt_PlotPointSize.Text.Replace(".", ","), out pointSize))
            {
                Log.LogMessage("Point size must be a double");
                return;
            }

            int from = -1;
            if (!int.TryParse(txt_ExportFrom.Text, out from) || txt_ExportFrom.Text == "")
            {
                Log.LogMessage("Export from not valid integer, using 0");
                from = -1;
            }

            int to = -1;
            if (!int.TryParse(txt_ExportTo.Text, out to) || txt_ExportTo.Text == "")
            {
                Log.LogMessage("Export to not valid integer, using max");
                to = -1;
            }

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = ".png";
            sfd.Filter = "png|*.png";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                PngExporter pngify = new PngExporter();
                pngify.Width = width;
                pngify.Height = height;

                var xy = GetXY(from, to);

                var test = xy.Item1;
                var recall = xy.Item2;

                FitPlot(test, recall);

                var model = new PlotModel() { Title = $"Slope:{slope.ToString("0.000")} RSquared:{rsquared.ToString("0.000")}" };
                var dataSeries = new OxyPlot.Series.ScatterSeries() { MarkerType = MarkerType.Circle, MarkerStroke = OxyColors.Red };
                for (int i = 0; i < test.Count; i++)
                {
                    dataSeries.Points.Add(new OxyPlot.Series.ScatterPoint(test[i], recall[i]) { Size = pointSize });
                }

                var fitSeries = new OxyPlot.Series.FunctionSeries((x) => intercept + slope * x, test.Min(), test.Max(), 0.001) { Color = OxyColors.Blue };

                model.Series.Add(dataSeries);
                model.Series.Add(fitSeries);

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

                pngify.ExportToFile(model, sfd.FileName);
                Log.LogMessage("Saved " + sfd.FileName + "!");
            }
        }