private void scaleCouple() { if (isCouple.IsChecked && lstYxis.SelectedItem != null) { var axise = graph.Axes[SelectedIndex]; foreach (Plot plot in graph.Plots) { plot.VerticalScale = axise; } coupleIndex = SelectedIndex; } else if (isCouple.IsChecked == false && lstYxis.SelectedItem != null) { for (int k = 0; k < graph.Axes.Count; k++) { int limitCount = Traces[SelectedIndex].LimitLineList.Count(); graph.Plots[k].VerticalScale = graph.Axes[k]; for (int i = 0; i < graph.Plots.Count - limitCount; i++) { if (i == SelectedIndex) { graph.Axes[i].Visibility = Visibility.Visible; AxisDouble axis = graph.Axes[i] as AxisDouble; } else { graph.Axes[i].Visibility = Visibility.Collapsed; AxisDouble axis = graph.Axes[i] as AxisDouble; } } } } }
private void Axis_RangeChanged(object sender, ValueChangedEventArgs <Range <double> > e) { AxisDouble yAxis = sender as AxisDouble; if (lstYxis.SelectedItem != null) { Trace trace = lstYxis.SelectedItem as Trace; if (yAxis.Range.Minimum == trace.ReferenceLevel - trace.Scale * trace.ReferencePosition && yAxis.Range.Maximum == trace.ReferenceLevel + trace.Scale * (trace.DivisionCount - trace.ReferencePosition)) { } else { if (trace.DivisionCount != 0) { trace.Scale = (yAxis.Range.Maximum - yAxis.Range.Minimum) / trace.DivisionCount; trace.ReferenceLevel = yAxis.Range.Minimum + (yAxis.Range.Maximum - yAxis.Range.Minimum) * trace.ReferencePosition / trace.DivisionCount; } } } }
/// <summary> /// 获取每个trace对应的纵坐标 /// </summary> /// <param name="str"></param> /// <returns></returns> private AxisDouble getAxis(string traceTitle) { AxisDouble axis = new AxisDouble() { Orientation = Orientation.Vertical, MajorGridLines = new GridLines() { Stroke = new SolidColorBrush(Colors.White), Visibility = Visibility.Collapsed }, MinorGridLines = new GridLines() { Visibility = Visibility.Collapsed }, Name = traceTitle, Adjuster = RangeAdjuster.FitLoosely, Visibility = Visibility.Collapsed }; axis.RangeChanged += Axis_RangeChanged; return(axis); }
private void lstYxis_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (lstYxis.SelectedItem != null) { SelectedIndex = lstYxis.SelectedIndex; Trace trace = lstYxis.SelectedItem as Trace; if (_LastSelectedTrace == null) { return; } if (_LastSelectedTrace != null) { for (int i = 0; i < _LastSelectedTrace.LimitLineList.Count; i++) { graph.Plots.RemoveAt(graph.Plots.Count - 1); } } _LastSelectedTrace = trace; AxisDouble yAxis = new AxisDouble(); int index = Traces.IndexOf(trace); if (isCouple.IsChecked == false) { for (int i = 0; i < graph.Plots.Count; i++) { if (i == index) { graph.Axes[i].Visibility = Visibility.Visible; yAxis = graph.Axes[i] as AxisDouble; } else { graph.Axes[i].Visibility = Visibility.Collapsed; AxisDouble axis = graph.Axes[i] as AxisDouble; axis.MinorGridLines = new GridLines() { Visibility = Visibility.Hidden }; axis.MajorGridLines = new GridLines() { Visibility = Visibility.Hidden }; } } } else { if (coupleIndex >= Traces.Count) { for (int i = 0; i < graph.Plots.Count; i++) { if (i == index) { graph.Axes[i].Visibility = Visibility.Visible; yAxis = graph.Axes[i] as AxisDouble; foreach (Plot plot in graph.Plots) { plot.VerticalScale = graph.Axes[i]; } coupleIndex = index; } else { graph.Axes[i].Visibility = Visibility.Collapsed; } } } } int axisIndex = trace.AxisIndex; for (int i = 0; i < XAxisList.Count; i++) { if (i == axisIndex) { XAxisList[i].ToolTip = ">"; } else { XAxisList[i].ToolTip = ""; } } lstAxis.ItemsSource = null; lstAxis.ItemsSource = XAxisList; this.lstAxis.SelectedIndex = axisIndex; UpdateDataSource(); yAxis.MajorDivisions = new RangeLabeledDivisions() { LabelVisibility = Visibility.Visible, Mode = RangeDivisionsMode.CreateCountMode(trace.DivisionCount + 1) }; yAxis.MinorGridLines = new GridLines() { Stroke = new SolidColorBrush(Colors.White), Visibility = Visibility.Collapsed, StrokeThickness = 0.5 }; yAxis.MajorGridLines = new GridLines() { Stroke = new SolidColorBrush(Colors.White), Visibility = Visibility.Visible, StrokeThickness = 0.5 }; double X = trace.ReferenceLevel - trace.Scale * trace.ReferencePosition; double Y = trace.ReferenceLevel + trace.Scale * (trace.DivisionCount - trace.ReferencePosition); if (X != Y) { yAxis.Range = new Range <double>(X, Y); graph.Axes[index].Adjuster = RangeAdjuster.None; } _SelectedPlot = graph.Plots[SelectedIndex]; foreach (Plot p in graph.Plots) { ((LinePlotRenderer)p.Renderer).StrokeThickness = 1.0; } ((LinePlotRenderer)_SelectedPlot.Renderer).StrokeThickness = 2.0; } }
/// <summary> /// 更新trace中的数据 /// </summary> public void UpdateData() { if (Traces.Count == 0) { return; } isCouple.IsChecked = false; graph.RenderMode = RenderMode.Hardware; this.lstYxis.ItemsSource = Traces; List <Point[]> dataSource = new List <Point[]>(); List <AxisDouble> axisDouble = new List <AxisDouble>(); int i = 0; foreach (var tr in Traces) { if (i > 7) { i = 0; } dataSource.Add(ProcessData(tr.TraceData)); Plot p = new Plot() { Renderer = new LinePlotRenderer() { Stroke = Brushes[i], StrokeThickness = 1.5 } }; tr.Color = (SolidColorBrush)(p.Renderer as LinePlotRenderer).Stroke; AxisDouble axis = getAxis(tr.Title); graph.Axes.Add(axis); p.VerticalScale = axis; graph.Plots.Add(p); foreach (Marker marker in tr.Markers) { NationalInstruments.Controls.Cursor cursor = GetCursor(); cursor.Plot = p; graph.Children.Add(cursor); double x1 = tr.TraceData.Select(x => x.X).Min(); double x2 = tr.TraceData.Select(x => x.X).Max(); cursor.SetDataPosition(new List <double>() { (marker.X - x1) / (x2 - x1), marker.Y }); cursor.Tag = marker.DisplayName; cursor.Label = new Label() { Content = tr.Markers.Count, Foreground = (p.Renderer as LinePlotRenderer).Stroke }; cursor.CrosshairBrush = (p.Renderer as LinePlotRenderer).Stroke; } i++; } listMarker.ItemsSource = graph.Children; getlimitPoint(Traces[SelectedIndex]); _LastSelectedTrace = Traces[SelectedIndex]; if (_limitPointlist.Count() > 0) { foreach (var points in _limitPointlist) { dataSource.Add(ProcessData(points)); Plot p = new Plot() { Renderer = new LinePlotRenderer() { Stroke = new SolidColorBrush(Colors.Red) } }; graph.Plots.Add(p); } } graph.DataSource = dataSource; //for (int traceIndex = 0; traceIndex < Traces.Count; traceIndex++) //{ // lstYxis.SelectedIndex = traceIndex; //} _LastSelectedTrace = Traces[SelectedIndex]; lstYxis.SelectedIndex = SelectedIndex; graph.AllScales.Last().Visibility = Visibility.Collapsed; this.lstAxis.ItemsSource = XAxisList; isCouple.IsChecked = true; scaleCouple(); }