コード例 #1
0
 public SeriesDefinitionViewModel(IList <AxisDefinitionModel> axisDefinitions)
 {
     AvailableAxis         = axisDefinitions;
     SeriesDefinitionModel = new SeriesDefinitionModel();
 }
コード例 #2
0
 public SeriesDefinitionViewModel(IList <AxisDefinitionModel> axisDefinitions, SeriesDefinitionModel series)
 {
     AvailableAxis         = axisDefinitions;
     SeriesDefinitionModel = series;
 }
コード例 #3
0
        /// <summary>
        /// Method to invoke when the Edit command is executed.
        /// </summary>
        private async Task OnSaveCommandExecuteAsync()
        {
            var saveFileService = ServiceLocator.Default.ResolveType <ISaveFileService>();

            try
            {
                saveFileService.Filter = "Plot Data|*.csv";
                if (!string.IsNullOrEmpty(PlotModel.SaveCsvPath))
                {
                    saveFileService.InitialDirectory = Path.GetDirectoryName(PlotModel.SaveCsvPath);
                    if (!Directory.Exists(saveFileService.InitialDirectory))
                    {
                        saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                    }
                    saveFileService.FileName = Path.GetFileNameWithoutExtension(PlotModel.SaveCsvPath);
                }
                else
                {
                    saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                }
                if (saveFileService.DetermineFile())
                {
                    lock (_lockObject)
                    {
                        using (var w = new StreamWriter(saveFileService.FileName))
                        {
                            int shortestlength = int.MaxValue;
                            //Dictionary<int, string> headerDict = new Dictionary<int, string>();
                            //headerDict.Add(0, "Time");
                            var header = new StringBuilder("Time");
                            for (int i = 2; i < _data.Format.LogDelimitCount; i++)//skip first, time
                            {
                                header.Append(",");
                                //see if there is a series unquie for this result index
                                SeriesDefinitionModel series = PlotModel.PlotConfiguration.Series.FirstOrDefault(x => x.ResultIndex1 == i && x.ResultIndex2 == null);
                                if (series != null)
                                {
                                    //headerDict.Add(i, series.SeriesTitle);
                                    header.Append(series.SeriesTitle);
                                }
                                else
                                {
                                    //default header
                                    //headerDict.Add(i, string.Format("data{0}", i.ToString()));
                                    header.Append(string.Format("data{0}", i.ToString()));
                                }
                            }
                            w.WriteLine(header);
                            foreach (string[] datapoint in _dataLog)
                            {
                                ArraySegment <string> realdata = new ArraySegment <string>(datapoint, 1, datapoint.Count() - 1);
                                string msg = String.Join(",", realdata);
                                w.WriteLine(msg);
                            }
                            //foreach (OxyPlot.Series.LineSeries series in OxyPlotModel.Series)
                            //{
                            //    header.Append(",");
                            //    header.Append(series.Title);
                            //    if (series.Points.Count() < shortestlength)
                            //    {
                            //        //should all be same length... but just in case
                            //        shortestlength = series.Points.Count();
                            //    }
                            //}
                            //w.WriteLine(header);
                            //for (int i = 0; i < shortestlength; i++)
                            //{
                            //    var points = new StringBuilder(((OxyPlot.Series.LineSeries)(OxyPlotModel.Series[0])).Points[i].X.ToString());

                            //    foreach (OxyPlot.Series.LineSeries series in OxyPlotModel.Series)
                            //    {
                            //        points.Append(",");
                            //        points.Append(series.Points[i].Y);
                            //    }
                            //}

                            w.Flush();
                            LogTo.Info("Wrote {0} points to CSV file.", shortestlength.ToString());
                        }
                    }
                    if (PlotModel.SaveCsvPath != saveFileService.FileName)
                    {
                        PlotModel.SaveCsvPath = saveFileService.FileName;
                    }
                    LogTo.Info("Saved Plot data to: {0}", PlotModel.SaveCsvPath);
                }
            }
            catch (Exception ex)
            {
                string errmsg = string.Format("Error saving Plot data: {0}", ex.Message);
                LogTo.Error(errmsg);
                await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
            }
        }