using OxyPlot; using OxyPlot.Wpf; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; namespace Tango.MachineStudio.ThreadExtensions.Models { public class CalibrationPlotModel : ExtendedObject { #region Properties public Plot DataPlotControl { get; set; } public Plot LinearizationPlotControl { get; set; } private string _title; public string Title { get { return _title; } set { _title = value; RaisePropertyChangedAuto(); } } private FactorColors _color; private IList _LPoints; public IList LPoints { get { return _LPoints; } set { _LPoints = value; } } private IList _APoints; public IList APoints { get { return _APoints; } set { _APoints = value; } } private IList _BPoints; public IList BPoints { get { return _BPoints; } set { _BPoints = value; } } private IList _points; /// /// Binding to ItemsSource of line chart. /// public IList LinearizationPoints { get { return _points; } set { _points = value; RaisePropertyChangedAuto(); } } private int _step; public int XStep { get { return _step; } set { _step = value; RaisePropertyChangedAuto(); } } private double _minY; /// /// From use to binding to left axis min value /// public double MinY { get { return _minY; } set { _minY = value; RaisePropertyChangedAuto(); } } private double _maxY; /// /// To use to binding to left axis max value /// public double MaxY { get { return _maxY; } set { _maxY = value; RaisePropertyChangedAuto(); } } private int _maxX; /// /// Gets or sets the maximum lab plot X values for LinearizationGraph left part /// public int MaxX { get { return _maxX; } set { _maxX = value; RaisePropertyChangedAuto(); } } private double _linearizationMaxX; public double LinearizationMaxX { get { return _linearizationMaxX; } set { _linearizationMaxX = value; RaisePropertyChangedAuto(); } } private double _linearizationMaxY; public double LinearizationMaxY { get { return _linearizationMaxY; } set { _linearizationMaxY = value; RaisePropertyChangedAuto(); } } #endregion public CalibrationPlotModel(FactorColors color, string title) { LinearizationPoints = new List(); LPoints = new List(); APoints = new List(); BPoints = new List(); _color = color; _title = title; } public void ClearResults() { LPoints.Clear(); APoints.Clear(); BPoints.Clear(); LinearizationPoints.Clear(); } public void InitDataGraph(List items) { if (items == null || items.Count == 0) return; ClearResults(); if (DataPlotControl != null) DataPlotControl.InvalidatePlot(true); if (LinearizationPlotControl != null) LinearizationPlotControl.InvalidatePlot(true); foreach (var labItem in items) { LPoints.Add(new DataPoint(labItem.InkPercentage, labItem.L)); APoints.Add(new DataPoint(labItem.InkPercentage, labItem.A)); BPoints.Add(new DataPoint(labItem.InkPercentage, labItem.B)); } int maxValue = (int)(items.Max(x => x.InkPercentage)); MaxX = Math.Max(100, maxValue); MinY = Math.Min(0, items.Min(x => Math.Min(x.L, Math.Min(x.A, x.B)))); MaxY = Math.Max( 100, items.Max(x => Math.Max(x.L, Math.Max(x.A, x.B)))); if (DataPlotControl != null) DataPlotControl.InvalidatePlot(true); } public void InitLinearizationGraph(List items, List outputPoints) { if (outputPoints == null) return; LinearizationPoints.Clear(); foreach (var nw in items.Zip(outputPoints, Tuple.Create)) { LinearizationPoints.Add(new DataPoint(nw.Item1.InkPercentage, nw.Item2)); } LinearizationMaxX = Math.Max(100, LinearizationPoints.Count > 0? LinearizationPoints.Max(x => x.X) : 0); LinearizationMaxY = Math.Max(100, LinearizationPoints.Count > 0 ? LinearizationPoints.Max(x => x.Y) : 0); if (LinearizationPlotControl != null) { LinearizationPlotControl.InvalidatePlot(true); } } } }