RolloverDataPointerInfoConverter.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. using System.Windows;
  8. using DataAnalysisControl.Core;
  9. namespace Aitex.UI.Charting.Converter
  10. {
  11. public class RolloverDataPointerInfoConverter : IMultiValueConverter
  12. {
  13. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  14. {
  15. try
  16. {
  17. DateTime time = (DateTime)values[0];
  18. double y = (double)values[1];
  19. var series = (Aitex.UI.Charting.View.MyLineSeries)values[2];
  20. string stepName = "";
  21. string recipeStepName = "PM.RecipeEngine.CurStepNo";
  22. if (series.DataSource != null && series.DataSource.Datas != null && series.DataSource.Datas.ContainsKey(recipeStepName))
  23. {
  24. var datas = series.DataSource.Datas[recipeStepName];
  25. int index = datas.TimeStamp.FindIndex((t) => time.Equals(t));
  26. if (index >= 0 && index < datas.RawData.Count)
  27. {
  28. int curStepNo = (int)(datas.RawData[index] + 0.5);
  29. //if (curStepNo > 0 && series.DataSource != null && series.DataSource.RecipeSteps != null && series.DataSource.RecipeSteps.Count > curStepNo)
  30. //{
  31. // stepName = series.DataSource.RecipeSteps[curStepNo].StepName;
  32. //}
  33. if (curStepNo > 0 && series.DataSource != null && series.DataSource.RecipeSteps != null)
  34. {
  35. for (int m = 0; m < series.DataSource.RecipeSteps.Count - 1; m++)
  36. {
  37. if (time >= series.DataSource.RecipeSteps[m].StepTime &&
  38. time < series.DataSource.RecipeSteps[m + 1].StepTime)
  39. {
  40. var sname = series.DataSource.RecipeSteps[m].StepName;
  41. if (sname.Contains(string.Format("第{0}步", curStepNo)))
  42. stepName = sname;
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. if (series.Offset == 0)
  50. return string.Format("【{0}】 {1} {2}(x{3}) {4}", time.ToString("yyyy/MM/dd HH:mm:ss"), ((y - series.Offset) / series.Factor).ToString("f3"), y.ToString("f3"), series.Factor, stepName);
  51. else
  52. return string.Format("【{0}】 {1} {2}(x{3}+{4}) {5}", time.ToString("yyyy/MM/dd HH:mm:ss"), ((y - series.Offset) / series.Factor).ToString("f3"), y.ToString("f3"), series.Factor, series.Offset, stepName);
  53. //if (series.Offset == 0)
  54. // return string.Format("【{0}】 {1} {2}(x{3}) {4}", time.ToString("yyyy/MM/dd HH:mm:ss"), (y - series.Offset) / series.Factor, y, series.Factor, stepName);
  55. //else
  56. // return string.Format("【{0}】 {1} {2}(x{3}+{4}) {5}", time.ToString("yyyy/MM/dd HH:mm:ss"), (y - series.Offset) / series.Factor, y, series.Factor, series.Offset, stepName);
  57. }
  58. catch (Exception ex)
  59. {
  60. CONTEXT.WriteLog(ex);
  61. }
  62. return "";
  63. }
  64. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  65. {
  66. return null;
  67. }
  68. }
  69. }