| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- 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
- {
- /// <summary>
- /// 实现数据集合接口
- /// </summary>
- public class ChartDataSet : ILineDataSet
- {
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="ChartDataSet" /> class.
- /// </summary>
- /// <param name="points">The points.</param>
- public ChartDataSet(List<ILineDataPoint> points)
- {
- DataPoints = points;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ChartDataSet"/> class.
- /// </summary>
- internal ChartDataSet()
- {
- DataPoints = new List<ILineDataPoint>();
- }
- #endregion Constructors
- #region Events
- /// <summary>
- /// 数据改变事件
- /// </summary>
- public event LineDataSetDataChangedEventHandler DataChanged;
- #endregion Events
- #region Properties
- #region Public Properties
- /// <summary>
- /// 数据点集合
- /// </summary>
- public List<ILineDataPoint> DataPoints
- {
- get;
- set;
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- /// <summary>
- /// Adds the bar data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="open">The open.</param>
- /// <param name="high">The high.</param>
- /// <param name="low">The low.</param>
- /// <param name="close">The close.</param>
- /// <param name="volume">The volume.</param>
- /// <param name="turnOver">The turn over.</param>
- /// <param name="holdVolume">持仓量</param>
- /// <param name="increase">The increase.</param>
- 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));
- }
- /// <summary>
- /// Inserts the bar data point.
- /// </summary>
- /// <param name="index">The index.</param>
- /// <param name="date">The date.</param>
- /// <param name="open">The open.</param>
- /// <param name="high">The high.</param>
- /// <param name="low">The low.</param>
- /// <param name="close">The close.</param>
- /// <param name="volume">The volume.</param>
- /// <param name="turnOver">The turn over.</param>
- /// <param name="holdVolume">The hold volume.</param>
- /// <param name="increase">The increase.</param>
- 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));
- }
- /// <summary>
- /// Adds the color data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="value">The value.</param>
- /// <param name="color">The color.</param>
- /// <param name="increase">The increase.</param>
- public void AddColorDataPoint(DateTime date, float value, Color color, float increase)
- {
- this.DataPoints.Add(new ColoredDataPoint(date, value, value, 0, value, color, increase));
- }
- /// <summary>
- /// Adds the colored bar data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="open">The open.</param>
- /// <param name="high">The high.</param>
- /// <param name="low">The low.</param>
- /// <param name="close">The close.</param>
- /// <param name="volume">The volume.</param>
- /// <param name="color">The color.</param>
- /// <param name="turnOver">The turn over.</param>
- /// <param name="holdVolume">The hold volume.</param>
- /// <param name="increase">The increase.</param>
- 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));
- }
- /// <summary>
- /// Adds the colored data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="open">The open.</param>
- /// <param name="high">The high.</param>
- /// <param name="low">The low.</param>
- /// <param name="close">The close.</param>
- /// <param name="color">The color.</param>
- /// <param name="increase">The increase.</param>
- 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));
- }
- /// <summary>
- /// Adds the OHLCD data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="value">The value.</param>
- public void AddOHLCDDataPoint(DateTime date, float value)
- {
- this.DataPoints.Add(new OHLCDataPoint(date, value, value, 0, value));
- }
- /// <summary>
- /// Adds the OHLCD data point.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <param name="open">The open.</param>
- /// <param name="high">The high.</param>
- /// <param name="low">The low.</param>
- /// <param name="close">The close.</param>
- public void AddOHLCDDataPoint(DateTime date, float open, float high, float low, float close)
- {
- this.DataPoints.Add(new OHLCDataPoint(date, open, high, low, close));
- }
- /// <summary>
- /// 获取集合中的bar集合
- /// </summary>
- public IList<IOHLCDataPoint> BarData()
- {
- if (DataPoints == null || !DataPoints.Any()) return null;
- try
- {
- return DataPoints.Where(z => z is IOHLCDataPoint) as IList<IOHLCDataPoint>;
- }
- catch
- {
- return null;
- }
- }
- /// <summary>
- /// 检查是否包含OHLCDataPoint
- /// </summary>
- /// <param name="arg">参数</param>
- 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;
- }
- /// <summary>
- /// Called when [delete].
- /// </summary>
- public void OnDelete()
- {
- this.DataPoints = null;
- }
- #endregion Public Methods
- #region Internal Methods
- /// <summary>
- /// Called when [data set data changed].
- /// </summary>
- /// <param name="dataSet">The data set.</param>
- internal void OnDataSetDataChanged(ILineDataSet dataSet)
- {
- if (dataSet == null) return;
- this.DataPoints = dataSet.DataPoints;
- OnDataChanged(null);
- }
- #endregion Internal Methods
- #region Private Methods
- /// <summary>
- /// 触发datachanged事件
- /// </summary>
- /// <param name="obj">The obj.</param>
- private void OnDataChanged(object obj)
- {
- if (DataChanged != null)
- {
- DataChanged(obj);
- }
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|