private void SetupPlot() { CompositionTarget.Rendering += CompositionTarget_Rendering; PlotModel = new PlotModel(); BottomAxis = new BottomLinearAxis(this); PlotModel.Axes.Add(BottomAxis); LeftAxis = new LeftLinearAxis(this); PlotModel.Axes.Add(LeftAxis); PlotModel.MouseDown += PlotMouseDown; PlotModel.MouseMove += PlotMouseMove; PlotModel.MouseUp += PlotMouseUp; SeriesNames = new Dictionary <int, string>(); IsRealTime = true; IsYZoom = true; IsGrid = false; IsNormalise = false; NumSeries = 0; NumPointsPerPlot = 200; CurrentRelativeCacheIndex = 0; CurrentFileName = null; BaseTitle = ""; MovingSeries = null; PointCache = null; Task = new Thread(new ThreadStart(Run)); Task.Name = "PlotServiceThread:" + OwnerShellId; Task.Priority = ThreadPriority.Normal; // XXX was AboveNormal. Task.Start(); }
private void PlotMouseUp(object sender, OxyMouseEventArgs e) { if (MovingSeries != null) { MovingSeries = null; // e.Handled = true; } }
private void PlotMouseDown(object sender, OxyMouseEventArgs e) { // if (e.ChangedButton == OxyMouseButton.Left) { MovingSeries = PlotModel.GetSeriesFromPoint(e.Position) as MapLineSeries; MoveLastPosition = BottomAxis.InverseTransform(e.Position.X, e.Position.Y, LeftAxis); //e.Handled = true; // } }
public void ResetSeries() { for (int i = 0; i < NumSeries; i++) { MapLineSeries s = PlotModel.Series[i] as MapLineSeries; s.Points.Clear(); s.ResetMinMax(); } }
void ToggleNormalise() { IsNormalise = !IsNormalise; for (int i = 0; i < NumSeries; i++) { MapLineSeries s = PlotModel.Series[i] as MapLineSeries; s.AutoNormalise = IsNormalise; } RefreshPoints(); }
public void RefreshPoints() { if (PointCache != null) { int k = PointCache.FindRelativeXCoordinateInCache(BottomAxis.ActualMinimum); if (k < 0) { k = ~k; } ResetSeries(); CurrentRelativeCacheIndex = k + NumPointsPerPlot; if (CurrentRelativeCacheIndex > PointCache.RelativeCount) { CurrentRelativeCacheIndex = PointCache.RelativeCount; } if (k < PointCache.RelativeCount) { List <double> q = PointCache.RelativeGetAt(k); if (q != null) { int maxDataSeries = q.Count - 1; if (q == null) { return; } if (NumSeries == 0) { SetSeries(maxDataSeries); } int maxNumSeries = NumSeries < maxDataSeries ? NumSeries : maxDataSeries; PointCache.RefreshMinMax(); for (int h = 0; h < maxNumSeries; h++) { MapLineSeries s = PlotModel.Series[h] as MapLineSeries; s.RefreshMinMax(); for (int i = k; i < CurrentRelativeCacheIndex; i++) { List <double> p = PointCache.RelativeGetAt(i); if (p == null) { return; } s.Points.Add(new DataPoint(p[0], s.Map(p[1 + h]))); } } } } } }
public void SetSeries(int numSeries) { NumSeries = numSeries; for (int i = 0; i < NumSeries; i++) { MapLineSeries s = new MapLineSeries(PointCache, i + 1); s.LineStyle = LineStyle.Solid; string t = null; SeriesNames.TryGetValue(i, out t); if (t == null) { t = "Series " + (1 + i); } s.Title = t; PlotModel.Series.Add(s); } }
public void SetSeriesName(int index, string name) { if (index >= 0 && index < 16) { try { if (String.IsNullOrWhiteSpace(name)) { name = ""; } SeriesNames[index] = name; if (PlotModel.Series.Count > index) { MapLineSeries s = PlotModel.Series[index] as MapLineSeries; s.Title = name; } } catch (Exception) { } } }
public override void Close() { base.Close(); if (Task != null) { Primitives.Interrupt(Task); Task = null; } if (PointCache != null) { PointCache.Close(); PointCache = null; } PlotModel = null; BottomAxis = null; LeftAxis = null; MovingSeries = null; SeriesNames = null; }
public void UpdatePlot() { if (PointCache != null) { if (Dispatcher.CheckAccess()) { while (IsRealTime && PointCache.RelativeCount > CurrentRelativeCacheIndex) { List <double> p = PointCache.RelativeGetAt(CurrentRelativeCacheIndex++); if (p == null) { break; } int maxDataSeries = p.Count - 1; if (NumSeries == 0) { SetSeries(maxDataSeries); } int numPlotableSeries = NumSeries < maxDataSeries ? NumSeries : maxDataSeries; for (int h = 0; h < numPlotableSeries; h++) { MapLineSeries s = PlotModel.Series[h] as MapLineSeries; if (s.Points.Count >= NumPointsPerPlot) { s.Points.RemoveAt(0); } s.Points.Add(new DataPoint(p[0], s.Map(p[1 + h]))); } } } else { Dispatcher.Invoke((Action)(() => { UpdatePlot(); })); } } }