using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; using System.Windows.Media; using System.Windows; using DataAnalysisControl.Core; namespace Aitex.UI.Charting.Converter { public class RolloverDataPointerInfoConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { DateTime time = (DateTime)values[0]; double y = (double)values[1]; var series = (Aitex.UI.Charting.View.MyLineSeries)values[2]; string stepName = ""; string recipeStepName = "PM.RecipeEngine.CurStepNo"; if (series.DataSource != null && series.DataSource.Datas != null && series.DataSource.Datas.ContainsKey(recipeStepName)) { var datas = series.DataSource.Datas[recipeStepName]; int index = datas.TimeStamp.FindIndex((t) => time.Equals(t)); if (index >= 0 && index < datas.RawData.Count) { int curStepNo = (int)(datas.RawData[index] + 0.5); //if (curStepNo > 0 && series.DataSource != null && series.DataSource.RecipeSteps != null && series.DataSource.RecipeSteps.Count > curStepNo) //{ // stepName = series.DataSource.RecipeSteps[curStepNo].StepName; //} if (curStepNo > 0 && series.DataSource != null && series.DataSource.RecipeSteps != null) { for (int m = 0; m < series.DataSource.RecipeSteps.Count - 1; m++) { if (time >= series.DataSource.RecipeSteps[m].StepTime && time < series.DataSource.RecipeSteps[m + 1].StepTime) { var sname = series.DataSource.RecipeSteps[m].StepName; if (sname.Contains(string.Format("第{0}步", curStepNo))) stepName = sname; break; } } } } } if (series.Offset == 0) 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); else 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); //if (series.Offset == 0) // 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); //else // 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); } catch (Exception ex) { CONTEXT.WriteLog(ex); } return ""; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { return null; } } }