/// <summary> /// 指定したファイルパスのファイルのテキストを解析します。 /// <para> /// 解析に失敗したときは <see cref="SelectedPath"/> を "" に変更します。 /// </para> /// </summary> /// <param name="path">ファイルパス。</param> /// <param name="type">シグナルの取得方法。</param> public void Parse(string path, SignalSelectionType type) { _Points.Clear(); try { using (var reader = new StreamReader(path, Encoding.UTF8)) { var converter = new SignalConverterV1(); var dataSelector = GetSignalSelection(type); var line = ""; int sec = 0; while ((line = reader.ReadLine()) != null) { if (string.IsNullOrEmpty(line)) { continue; } var data = line.Split(','); sec = int.Parse(data[0]); var signals = dataSelector.Select(data.Skip(1), 10); for (var i = 0; i < signals.Count(); i++) { var point = new DataPoint(sec + 0.1 * i, signals[i], converter); _Points.Add(point); } } } // 前後のデータ ポイントを設定 var points = _Points; DataPoint prevP = null; DataPoint nowP = null; DataPoint nextP = null; for (var i = 0; i < points.Count(); i++) { prevP = nowP; nowP = points.ElementAtOrDefault(i); nextP = points.ElementAtOrDefault(i + 1); nowP.Previous = prevP; nowP.Next = nextP; } SelectedPath = path; } catch { SelectedPath = ""; } DataPointUpdated?.Invoke(this, GenericEventArgs.Create(Points)); PropertyChanged.Raise(this, nameof(DataCount)); }
/// <summary> /// <see cref="PeakAreaPlot"/> クラスの新しいインスタンスを初期化します。 /// </summary> public PeakAreaPlot() { // 軸の初期化 InitializeAxisX(AXIS_X_MIN_VALUE, AXIS_X_MIN_VALUE, AXIS_X_MAX_VALUE, AXIS_X_MAX_VALUE, 20); InitializeAxisY(AXIS_Y_MIN_VALUE, AXIS_Y_MIN_VALUE, AXIS_Y_MAX_VALUE, AXIS_Y_MAX_VALUE, 50); PlotModel.Axes.Add(AxisX); PlotModel.Axes.Add(AxisY); PlotModel.Series.Add(Series); PlotModel.Series.Add(ScatterSeries); PlotModel.MouseMove += (sender, args) => { var lp = OxyPlot.Axes.Axis.InverseTransform(args.Position, AxisX, AxisY); var np = Series.GetNearestPoint(args.Position, false)?.DataPoint ?? new OxyPlot.DataPoint(0, 0); var loosePoint = new DataPoint((int)lp.X, (int)lp.Y); var nearestPoint = new DataPoint(np.X, np.Y); MouseMove?.Invoke(this, GenericEventArgs.Create(new PositionEventArgs(loosePoint, nearestPoint))); }; }