private void InterpolatePosition(IMarkerViewModel mvm, ref PointAnnotation annotation) { foreach (OxyPlot.Series.ScatterSeries series in PlotModel.Series) { List <DataPoint> seriesData = series.ItemsSource as List <DataPoint>; for (int i = 0; i < seriesData.Count; i++) { if (seriesData[i].T >= mvm.Time) { var lastIndex = i > 0 ? i - 1 : i; var nextData = seriesData[i]; var lastData = seriesData[lastIndex]; var t = mvm.Time.Ticks; var t_0 = lastData.T.Ticks; var t_1 = nextData.T.Ticks; double frac = (t - t_0) / (double)(t_1 - t_0); // Do backward linear interpolation // d = d_0 + (d_1-d_0)\frac{t - t_0}{t_1-t_0} annotation.Y = lastData.Y + (nextData.Y - lastData.Y) * frac; annotation.X = lastData.X + (nextData.X - lastData.X) * frac; break; } } } }
public override void AddAnnotation(IMarkerViewModel mvm) { var annotation = new PointAnnotation(); annotation.Text = mvm.Title; annotation.Tag = mvm; InterpolatePosition(mvm, ref annotation); mvm.PropertyChanged += (a, b) => { var annotations = (from anno in this.PlotModel.Annotations where anno.Tag == a select anno).ToList(); for (int i = 0; i < annotations.Count; i++) { annotation.Text = mvm.Title; InterpolatePosition(mvm, ref annotation); } this.PlotModel.InvalidatePlot(false); }; this.PlotModel.Annotations.Add(annotation); this.PlotModel.InvalidatePlot(false); }
public virtual void AddAnnotation(IMarkerViewModel mvm) { mvm.PropertyChanged += (a, b) => { foreach (LineAnnotation item in this.PlotModel.Annotations) { if (item.Tag == a) { item.X = OxyPlot.Axes.DateTimeAxis.ToDouble(mvm.Time); item.Text = mvm.Title; this.PlotModel.InvalidatePlot(false); } } }; var vline = new LineAnnotation(); vline.Type = LineAnnotationType.Vertical; vline.X = OxyPlot.Axes.DateTimeAxis.ToDouble(mvm.Time); vline.Text = mvm.Title; vline.Tag = mvm; this.PlotModel.Annotations.Add(vline); this.PlotModel.InvalidatePlot(false); }
private void Execute_RemoveMarkerCommand(IMarkerViewModel marker) { MarkerViewModel vm = marker as MarkerViewModel; this.ProjectModel.Markers.Remove(vm?.markerModel); }