using MuchInfo.Chart.Data.Interfaces; using MuchInfo.Chart.Data.Models; using MuchInfo.Chart.Infrastructure.Data; using MuchInfo.Chart.Infrastructure.EventArgs; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Media; namespace MuchInfo.Chart.WPF.Primitives { /// /// 实现数据集合接口 /// public class ChartDataSet : ILineDataSet { #region Constructors /// /// Initializes a new instance of the class. /// /// The points. public ChartDataSet(List points) { DataPoints = points; } /// /// Initializes a new instance of the class. /// internal ChartDataSet() { DataPoints = new List(); } #endregion Constructors #region Events /// /// 数据改变事件 /// public event LineDataSetDataChangedEventHandler DataChanged; #endregion Events #region Properties #region Public Properties /// /// 数据点集合 /// public List DataPoints { get; set; } #endregion Public Properties #endregion Properties #region Methods #region Public Methods /// /// Adds the bar data point. /// /// The date. /// The open. /// The high. /// The low. /// The close. /// The volume. /// The turn over. /// 持仓量 /// The increase. public void AddBarDataPoint(DateTime date, float open, float high, float low, float close, float volume, float turnOver, float holdVolume, float increase) { this.DataPoints.Add(new BarDataPoint(date, open, high, low, close, volume, turnOver, holdVolume, increase)); } /// /// Inserts the bar data point. /// /// The index. /// The date. /// The open. /// The high. /// The low. /// The close. /// The volume. /// The turn over. /// The hold volume. /// The increase. public void InsertBarDataPoint(int index, DateTime date, float open, float high, float low, float close, float volume, float turnOver, float holdVolume, float increase) { this.DataPoints.Insert(index, new BarDataPoint(date, open, high, low, close, volume, turnOver, holdVolume, increase)); } /// /// Adds the color data point. /// /// The date. /// The value. /// The color. /// The increase. public void AddColorDataPoint(DateTime date, float value, Color color, float increase) { this.DataPoints.Add(new ColoredDataPoint(date, value, value, 0, value, color, increase)); } /// /// Adds the colored bar data point. /// /// The date. /// The open. /// The high. /// The low. /// The close. /// The volume. /// The color. /// The turn over. /// The hold volume. /// The increase. public void AddColoredBarDataPoint(DateTime date, float open, float high, float low, float close, float volume, Color color, float turnOver, float holdVolume, float increase) { this.DataPoints.Add(new ColoredBarDataPoint(date, open, high, low, close, volume, color, turnOver, holdVolume, increase)); } /// /// Adds the colored data point. /// /// The date. /// The open. /// The high. /// The low. /// The close. /// The color. /// The increase. public void AddColoredDataPoint(DateTime date, float open, float high, float low, float close, Color color, float increase) { this.DataPoints.Add(new ColoredDataPoint(date, open, high, low, close, color, increase)); } /// /// Adds the OHLCD data point. /// /// The date. /// The value. public void AddOHLCDDataPoint(DateTime date, float value) { this.DataPoints.Add(new OHLCDataPoint(date, value, value, 0, value)); } /// /// Adds the OHLCD data point. /// /// The date. /// The open. /// The high. /// The low. /// The close. public void AddOHLCDDataPoint(DateTime date, float open, float high, float low, float close) { this.DataPoints.Add(new OHLCDataPoint(date, open, high, low, close)); } /// /// 获取集合中的bar集合 /// public IList BarData() { if (DataPoints == null || !DataPoints.Any()) return null; try { return DataPoints.Where(z => z is IOHLCDataPoint) as IList; } catch { return null; } } /// /// 检查是否包含OHLCDataPoint /// /// 参数 public bool IsIncludeOHLCDataPoint(DataChangedArgs arg) { var current = DataPoints.FirstOrDefault(z => z is IOHLCDataPoint && DateTime.Compare(z.Date, arg.OldDate) == 0); if (current == null) return false; current.Date = arg.NewDate; OnDataChanged(arg); return true; } /// /// Called when [delete]. /// public void OnDelete() { this.DataPoints = null; } #endregion Public Methods #region Internal Methods /// /// Called when [data set data changed]. /// /// The data set. internal void OnDataSetDataChanged(ILineDataSet dataSet) { if (dataSet == null) return; this.DataPoints = dataSet.DataPoints; OnDataChanged(null); } #endregion Internal Methods #region Private Methods /// /// 触发datachanged事件 /// /// The obj. private void OnDataChanged(object obj) { if (DataChanged != null) { DataChanged(obj); } } #endregion Private Methods #endregion Methods } }