PocketProcessDataChart.xaml.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using SciChart.Charting.Visuals.Axes;
  15. using Aitex.Core.UI.View.Smart;
  16. using Aitex.Core.UI.ControlDataContext;
  17. namespace Aitex.Core.UI.Control
  18. {
  19. /// <summary>
  20. /// Interaction logic for PocketProcessDataChart.xaml
  21. /// </summary>
  22. public partial class PocketProcessDataChart : UserControl
  23. {
  24. public PocketProcessDataChart()
  25. {
  26. InitializeComponent();
  27. }
  28. private void sciChart_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  29. {
  30. if (e.ChangedButton == MouseButton.Right)
  31. {
  32. //右键双击,恢复1:1的视图
  33. this.sciChart.ZoomExtents();
  34. }
  35. }
  36. private void NumericAxis_Pyro_MouseEnter(object sender, MouseEventArgs e)
  37. {
  38. pyroAxisTopDown.Visibility = System.Windows.Visibility.Visible;
  39. pyroAxisTopUp.Visibility = System.Windows.Visibility.Visible;
  40. pyroAxisBottomUp.Visibility = System.Windows.Visibility.Visible;
  41. pyroAxisBottomDown.Visibility = System.Windows.Visibility.Visible;
  42. }
  43. private void NumericAxis_Pyro_MouseLeave(object sender, MouseEventArgs e)
  44. {
  45. if (pyroAxisTopDown.IsMouseOver || pyroAxisTopUp.IsMouseOver ||
  46. pyroAxisBottomDown.IsMouseOver || pyroAxisBottomUp.IsMouseOver)
  47. return;
  48. pyroAxisTopDown.Visibility = System.Windows.Visibility.Hidden;
  49. pyroAxisTopUp.Visibility = System.Windows.Visibility.Hidden;
  50. pyroAxisBottomDown.Visibility = System.Windows.Visibility.Hidden;
  51. pyroAxisBottomUp.Visibility = System.Windows.Visibility.Hidden;
  52. }
  53. private void NumericAxis_Wrap_MouseEnter(object sender, MouseEventArgs e)
  54. {
  55. warpAxisTopDown.Visibility = System.Windows.Visibility.Visible;
  56. warpAxisTopUp.Visibility = System.Windows.Visibility.Visible;
  57. warpAxisBottomUp.Visibility = System.Windows.Visibility.Visible;
  58. warpAxisBottomDown.Visibility = System.Windows.Visibility.Visible;
  59. }
  60. private void NumericAxis_Wrap_MouseLeave(object sender, MouseEventArgs e)
  61. {
  62. if (warpAxisTopDown.IsMouseOver || warpAxisTopUp.IsMouseOver ||
  63. warpAxisBottomDown.IsMouseOver || warpAxisBottomUp.IsMouseOver)
  64. return;
  65. warpAxisTopDown.Visibility = System.Windows.Visibility.Hidden;
  66. warpAxisTopUp.Visibility = System.Windows.Visibility.Hidden;
  67. warpAxisBottomDown.Visibility = System.Windows.Visibility.Hidden;
  68. warpAxisBottomUp.Visibility = System.Windows.Visibility.Hidden;
  69. }
  70. private void NumericAxis_Reflect_MouseEnter(object sender, MouseEventArgs e)
  71. {
  72. ReflectAxisTopDown.Visibility = System.Windows.Visibility.Visible;
  73. ReflectAxisTopUp.Visibility = System.Windows.Visibility.Visible;
  74. ReflectAxisBottomUp.Visibility = System.Windows.Visibility.Visible;
  75. ReflectAxisBottomDown.Visibility = System.Windows.Visibility.Visible;
  76. }
  77. private void NumericAxis_Reflect_MouseLeave(object sender, MouseEventArgs e)
  78. {
  79. if (ReflectAxisTopDown.IsMouseOver || ReflectAxisTopUp.IsMouseOver ||
  80. ReflectAxisBottomDown.IsMouseOver || ReflectAxisBottomUp.IsMouseOver)
  81. return;
  82. ReflectAxisTopDown.Visibility = System.Windows.Visibility.Hidden;
  83. ReflectAxisTopUp.Visibility = System.Windows.Visibility.Hidden;
  84. ReflectAxisBottomDown.Visibility = System.Windows.Visibility.Hidden;
  85. ReflectAxisBottomUp.Visibility = System.Windows.Visibility.Hidden;
  86. }
  87. private void YAxisTopUp_Click(object sender, MouseButtonEventArgs e)
  88. {
  89. var l = sender as Label;
  90. NumericAxis axis = sciChart.YAxes[1 + int.Parse(l.Tag.ToString())] as NumericAxis;
  91. double min = (double)axis.VisibleRange.Min;
  92. double max = (double)axis.VisibleRange.Max;
  93. axis.VisibleRange.Max = max + 0.1 * (max - min);
  94. }
  95. private void YAxisTopDown_Click(object sender, MouseButtonEventArgs e)
  96. {
  97. var l = sender as Label;
  98. NumericAxis axis = sciChart.YAxes[1 + int.Parse(l.Tag.ToString())] as NumericAxis;
  99. double min = (double)axis.VisibleRange.Min;
  100. double max = (double)axis.VisibleRange.Max;
  101. axis.VisibleRange.Max = max - 0.1 * (max - min);
  102. }
  103. private void YAxisBottomUp_Click(object sender, MouseButtonEventArgs e)
  104. {
  105. var l = sender as Label;
  106. NumericAxis axis = sciChart.YAxes[1 + int.Parse(l.Tag.ToString())] as NumericAxis;
  107. double min = (double)axis.VisibleRange.Min;
  108. double max = (double)axis.VisibleRange.Max;
  109. axis.VisibleRange.Min = min + 0.1 * (max - min);
  110. }
  111. private void YAxisBottomDown_Click(object sender, MouseButtonEventArgs e)
  112. {
  113. var l = sender as Label;
  114. NumericAxis axis = sciChart.YAxes[1 + int.Parse(l.Tag.ToString())] as NumericAxis;
  115. double min = (double)axis.VisibleRange.Min;
  116. double max = (double)axis.VisibleRange.Max;
  117. axis.VisibleRange.Min = min - 0.1 * (max - min);
  118. }
  119. private void checkAutoRange_Checked(object sender, RoutedEventArgs e)
  120. {
  121. CheckBox ck = sender as CheckBox;
  122. AutoRange value = ck.IsChecked.Value ? AutoRange.Always : AutoRange.Never;
  123. sciChart.XAxis.AutoRange = value;
  124. foreach (var yaxis in sciChart.YAxes)
  125. yaxis.AutoRange = value;
  126. }
  127. private void OnChangeLineColor(object sender, RoutedEventArgs e)
  128. {
  129. var btn = (Button)sender;
  130. if (btn != null)
  131. {
  132. string dataId = (string)btn.Tag;
  133. var dlg = new System.Windows.Forms.ColorDialog();
  134. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  135. {
  136. var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
  137. var vm = (ProcessDataChartDataItem)DataContext;
  138. var line = vm.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  139. if (line != null) line.Stroke = newColor;
  140. }
  141. }
  142. }
  143. private void OnChangeDrawingItemVisibility(object sender, RoutedEventArgs e)
  144. {
  145. var checkbox = (CheckBox)sender;
  146. if (checkbox != null && checkbox.IsChecked.HasValue)
  147. {
  148. string dataId = (string)checkbox.Tag;
  149. var vm = (ProcessDataChartDataItem)DataContext;
  150. var line = vm.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  151. if (line != null)
  152. {
  153. line.IsVisible = checkbox.IsChecked.Value;
  154. //vm.InvokePropertyChanged("ReflectionDataSeries");
  155. }
  156. }
  157. }
  158. private void checkConfigPanel_Checked(object sender, RoutedEventArgs e)
  159. {
  160. dataConfigPanelColumn.Width = new GridLength((sender as CheckBox).IsChecked.Value ? 300 : 0, GridUnitType.Pixel);
  161. }
  162. }
  163. }