PlotBase.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.Interfaces;
  3. using MuchInfo.Chart.Data.Models;
  4. using MuchInfo.Chart.Infrastructure.Utilities;
  5. using MuchInfo.Chart.WPF.Controls.Indicator;
  6. using MuchInfo.Chart.WPF.Helpers;
  7. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Runtime.CompilerServices;
  11. using System.Windows;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Xml.Linq;
  15. namespace MuchInfo.Chart.WPF.Primitives
  16. {
  17. public abstract class PlotBase : IToolTipControlProvider
  18. {
  19. #region Fields
  20. protected Chart mChart;
  21. protected string mPendingSourceUID;
  22. protected ScaleLayer mScale;
  23. private IndicatorModel _indicatorModel;
  24. /// <summary>
  25. /// 指标编辑器转换后绘图数据
  26. /// </summary>
  27. public IndicatorModel Indicator
  28. {
  29. get { return _indicatorModel; }
  30. set { _indicatorModel = value; }
  31. }
  32. /// <summary>
  33. /// mSource
  34. /// </summary>
  35. // private ILineDataSet _outPutSource;
  36. private double _plotOpacity;
  37. private string _savedAsName;
  38. #endregion Fields
  39. #region Constructors
  40. protected PlotBase()
  41. {
  42. this.mPendingSourceUID = "";
  43. this._plotOpacity = 1.0;
  44. }
  45. protected PlotBase(IndicatorModel indicatorModel, Chart parentchart)
  46. : this()
  47. {
  48. this.mChart = parentchart;
  49. // _outPutSource = new ChartDataSet(indicatorModel.CalculateDataPoints);
  50. this._indicatorModel = indicatorModel;
  51. }
  52. #endregion Constructors
  53. #region Properties
  54. #region Public Properties
  55. public double PlotOpacity
  56. {
  57. get
  58. {
  59. return this._plotOpacity;
  60. }
  61. set
  62. {
  63. bool flag = value != this._plotOpacity;
  64. if (flag)
  65. {
  66. this._plotOpacity = value;
  67. flag = (this.mChart != null);
  68. if (flag)
  69. {
  70. this.mChart.Refresh();
  71. }
  72. }
  73. }
  74. }
  75. public string SavedAsName
  76. {
  77. get
  78. {
  79. return this._savedAsName;
  80. }
  81. set
  82. {
  83. this._savedAsName = value;
  84. }
  85. }
  86. public ScaleLayer ScaleLayer
  87. {
  88. get
  89. {
  90. return this.mScale;
  91. }
  92. set
  93. {
  94. this.mScale = value;
  95. }
  96. }
  97. #endregion Public Properties
  98. #region Protected Properties
  99. ///// <summary>
  100. ///// 数据源
  101. ///// </summary>
  102. //protected virtual ILineDataSet mSource
  103. //{
  104. // get
  105. // {
  106. // return this._outPutSource;
  107. // }
  108. // set
  109. // {
  110. // var dataChangedEventHandler = new LineDataSetDataChangedEventHandler(this.OnDataChanged);
  111. // bool flag = this._outPutSource != null;
  112. // if (flag)
  113. // {
  114. // this._outPutSource.DataChanged -= (dataChangedEventHandler);
  115. // }
  116. // this._outPutSource = value;
  117. // flag = (this._outPutSource != null);
  118. // if (flag)
  119. // {
  120. // this._outPutSource.DataChanged += (dataChangedEventHandler);
  121. // }
  122. // }
  123. //}
  124. //public ILineDataSet OutputSource
  125. //{
  126. // get { return _outPutSource; }
  127. // // set { _outPutSource = value; }
  128. //}
  129. public IndicatorModel OutputSource
  130. {
  131. get { return Indicator; }
  132. // set { _outPutSource = value; }
  133. }
  134. #endregion Protected Properties
  135. #endregion Properties
  136. #region Methods
  137. #region Public Methods
  138. public TimeSpan CurrentTimeFrame()
  139. {
  140. bool flag = this.mChart != null;
  141. TimeSpan currentTimeFrame = TimeSpan.Zero;
  142. if (flag)
  143. {
  144. currentTimeFrame = this.mChart.CurrentTimeFrame;
  145. }
  146. return currentTimeFrame;
  147. }
  148. public Chart GetChart()
  149. {
  150. return this.mChart;
  151. }
  152. public object GetControl()
  153. {
  154. return new IndicatorHierarchyDisplay(this);
  155. }
  156. public List<FrameworkElement> GetElements(Chart owner, ScaleLayer aScale, IDateScaler dateScale, IValueScaler valScale, Rect aRect)
  157. {
  158. //bool flag = this.PlotBase_1655.Count == 0;
  159. List<FrameworkElement> list;
  160. list = this.BuildPlot(owner, aScale, dateScale, valScale, aRect);
  161. //if (flag)
  162. //{
  163. // list = this.PlotBase_5028(owner, aScale, dateScale, ValScale, aRect);
  164. //}
  165. //else
  166. //{
  167. // list = new List<FrameworkElement>();
  168. // try
  169. // {
  170. // List<IPlotAddition>.Enumerator enumerator = this.PlotBase_1655.GetEnumerator();
  171. // while (enumerator.MoveNext())
  172. // {
  173. // IPlotAddition current = enumerator.Current;
  174. // list.AddRange(current.GetPlots(owner, this, aScale, dateScale, ValScale, aRect));
  175. // }
  176. // }
  177. // finally
  178. // {
  179. // //List<IPlotAddition>.Enumerator enumerator;
  180. // //enumerator.Dispose();
  181. // }
  182. // list.AddRange(this.PlotBase_5028(owner, aScale, dateScale, ValScale, aRect));
  183. //}
  184. if (list != null)
  185. {
  186. foreach (var current in list)
  187. {
  188. current.Opacity = this._plotOpacity;
  189. }
  190. }
  191. return list;
  192. }
  193. public abstract void InitAsNew();
  194. public abstract void ReInstanceSources();
  195. public void RemovedFromChart()
  196. {
  197. this.DeleteData();
  198. this.mChart = null;
  199. this.mScale = null;
  200. // this.mLegendBtn = null;
  201. }
  202. //public void RemovePlotAddition(IPlotAddition aAdd)
  203. //{
  204. // this.PlotBase_1655.Remove(aAdd);
  205. // bool flag = this.mChart != null;
  206. // if (flag)
  207. // {
  208. // this.mChart.Invalidate();
  209. // }
  210. //}
  211. //public void ScanConditionCreated(baseCondition mCondition, Color aColor)
  212. //{
  213. // IMQLScanHost currentIndicatorScanHost = MQLMain.CurrentIndicatorScanHost;
  214. // bool flag = currentIndicatorScanHost != null;
  215. // if (flag)
  216. // {
  217. // currentIndicatorScanHost.NewIndicatorScanCreated(mCondition, aColor);
  218. // }
  219. //}
  220. //public List<IScannablePlot> SiblingPlots()
  221. //{
  222. // List<IScannablePlot> list = new List<IScannablePlot>();
  223. // bool flag = this.mScale != null;
  224. // if (flag)
  225. // {
  226. // try
  227. // {
  228. // List<PlotBase>.Enumerator enumerator = this.mScale.AllPlots().GetEnumerator();
  229. // while (enumerator.MoveNext())
  230. // {
  231. // PlotBase current = enumerator.Current;
  232. // bool flag2 = current != this;
  233. // if (flag2)
  234. // {
  235. // list.Add(current);
  236. // }
  237. // }
  238. // }
  239. // finally
  240. // {
  241. // //List<PlotBase>.Enumerator enumerator;
  242. // //enumerator.Dispose();
  243. // }
  244. // }
  245. // return list;
  246. //}
  247. public abstract void SourceDataChange(object change);
  248. #endregion Public Methods
  249. #region Internal Methods
  250. /// <summary>
  251. /// 创建图表
  252. /// </summary>
  253. internal abstract List<FrameworkElement> BuildPlot(Chart owner, ScaleLayer aScale, IDateScaler dateScale, IValueScaler valScale, Rect aRect);
  254. /// <summary>
  255. ///
  256. /// </summary>
  257. internal abstract void Calculate();
  258. internal void Delete()
  259. {
  260. this.DeleteData();
  261. var webChart = this.mChart;
  262. bool flag = this.mScale != null;
  263. if (flag)
  264. {
  265. this.mScale.RemoveFromChartPane(this);
  266. }
  267. flag = (webChart != null);
  268. if (flag)
  269. {
  270. webChart.Refresh();
  271. }
  272. //this.ClearPlotAdditions();
  273. }
  274. /// <summary>
  275. /// ָ 显示在顶部的标题,弹出框的标题
  276. /// </summary>
  277. /// <returns></returns>
  278. internal string Description()
  279. {
  280. string result = "";
  281. return result;
  282. }
  283. internal abstract Color GetColor();
  284. /// <summary>
  285. /// 添加显示到面板中指标数据
  286. /// </summary>
  287. /// <param name="aDate">日期</param>
  288. /// <param name="isDarkBackground"></param>
  289. /// <param name="isForex"></param>
  290. /// <returns></returns>
  291. internal abstract List<ControlPair> GetControlPairs(DateTime aDate, bool isDarkBackground, bool isForex);
  292. /// <summary>
  293. /// Gets the control pairs.
  294. /// </summary>
  295. /// <param name="aDate">A date.</param>
  296. /// <param name="isDarkBackground">if set to <c>true</c> [is dark background].</param>
  297. /// <param name="digites">The digites.</param>
  298. /// <returns>List{ControlPair}.</returns>
  299. internal abstract List<ControlPair> GetControlPairs(DateTime aDate, bool isDarkBackground, int digites);
  300. internal abstract Color GetPlotColor();
  301. internal void SetDataSource(List<ILineDataSet> sources)
  302. {
  303. bool flag = Operators.CompareString(this.mPendingSourceUID, "", false) == 0;
  304. if (!flag)
  305. {
  306. try
  307. {
  308. List<ILineDataSet>.Enumerator enumerator = sources.GetEnumerator();
  309. while (enumerator.MoveNext())
  310. {
  311. ILineDataSet current = enumerator.Current;
  312. flag = true;// (Operators.CompareString(current.UID(), this.mPendingSourceUID, false) == 0);
  313. if (flag)
  314. {
  315. // this.mSource = current;
  316. break;
  317. }
  318. }
  319. }
  320. finally
  321. {
  322. //List<ILineDataSetWithUID>.Enumerator enumerator;
  323. //enumerator.Dispose();
  324. }
  325. }
  326. }
  327. internal abstract void ShowPlotEdit(FrameworkElement relativeTo);
  328. /// <summary>
  329. /// 添加指标
  330. /// </summary>
  331. //internal abstract void AddIndicators();
  332. #endregion Internal Methods
  333. #region Protected Methods
  334. protected void AddToXML(XElement xml, List<object> args)
  335. {
  336. //bool flag = this.PlotBase_1655.Count > 0;
  337. //if (flag)
  338. //{
  339. // XElement xElement = new XElement("PLOTADDITIONS");
  340. // try
  341. // {
  342. // List<IPlotAddition>.Enumerator enumerator = this.PlotBase_1655.GetEnumerator();
  343. // while (enumerator.MoveNext())
  344. // {
  345. // IPlotAddition current = enumerator.Current;
  346. // xElement.Add(current.ToXML(args));
  347. // }
  348. // }
  349. // finally
  350. // {
  351. // //List<IPlotAddition>.Enumerator enumerator;
  352. // //enumerator.Dispose();
  353. // }
  354. // xml.Add(xElement);
  355. //}
  356. var flag = (Operators.CompareString(this._savedAsName, "", false) != 0);
  357. if (flag)
  358. {
  359. xml.Add(new XAttribute("SavedName", this._savedAsName));
  360. }
  361. xml.Add(new XAttribute("Opacity", this._plotOpacity.ToString()));
  362. }
  363. protected abstract void DeleteData();
  364. #endregion Protected Methods
  365. #region Private Methods
  366. private void AddRemoveIndicators(MouseButtonEventArgs e)
  367. {
  368. //bool flag = this.mChart != null && this.mChart.AllowAddRemoveIndicators;
  369. //if (flag)
  370. //{
  371. // PopUpMenu popUpMenu = new PopUpMenu();
  372. // popUpMenu.AddItem("Edit", ImageMan.GetImage("PropertiesHS.png"), new EventHandler(this.PlotBase_5065));
  373. // flag = (this is LinePlot && !(this.Calculation() is calcPivotPoints) && !(this.Calculation() is calcIchimoku));
  374. // if (flag)
  375. // {
  376. // popUpMenu.AddItem("Add Indicator", ImageMan.GetImage("add2.png"), new EventHandler(this.PlotBase_5071));
  377. // }
  378. // flag = (this == this.mChart.GetPricePlot());
  379. // if (flag)
  380. // {
  381. // popUpMenu.AddItem("Comparisons", ImageMan.GetImage("line-chart.png"), new EventHandler(this.PlotBase_5070));
  382. // }
  383. // flag = (this.Calculation().DefaultAddMode == eIndicatorAddMode.eRegular);
  384. // if (flag)
  385. // {
  386. // popUpMenu.AddItem("Edit Plot Guides", ImageMan.GetImage("Ruler.png"), new EventHandler(this.PlotBase_5066));
  387. // }
  388. // popUpMenu.AddSeperator();
  389. // flag = (FSCServices.ServiceLevelAllowed(FSCServices.enumAlmostFSCServiceLevels.eMassiveScansAndSorts) && this is LinePlot && this.mCalculation != null && MQLSocketMan.IndicatorKeyAllowed(this.mCalculation.RootName()));
  390. // if (flag)
  391. // {
  392. // popUpMenu.AddItem("Scan", ImageMan.GetImage("flash.png"), new EventHandler(this.PlotBase_5078));
  393. // popUpMenu.AddItem("Add Column", ImageMan.GetImage("AddColumn.png"), new EventHandler(this.PlotBase_5079));
  394. // popUpMenu.AddSeperator();
  395. // }
  396. // flag = (this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic);
  397. // bool flag2;
  398. // if (flag)
  399. // {
  400. // ValueScalerArithmetic valueScalerArithmetic = (ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525();
  401. // flag = (this.DataSource() is _125 && this.Calculation() is calcPriceHistory);
  402. // if (flag)
  403. // {
  404. // flag2 = (valueScalerArithmetic.ScaleMode == ValueScalerArithmetic.enumScaleMethod.eArithmetic);
  405. // if (flag2)
  406. // {
  407. // popUpMenu.AddItem("Arithmetic", ImageMan.GetImage("MenuCheck.png"), null);
  408. // popUpMenu.AddItem("Log", null, new EventHandler(this.PlotBase_5069));
  409. // }
  410. // else
  411. // {
  412. // popUpMenu.AddItem("Arithmetic", null, new EventHandler(this.PlotBase_5068));
  413. // popUpMenu.AddItem("Log", ImageMan.GetImage("MenuCheck.png"), null);
  414. // }
  415. // popUpMenu.AddItem("More Scaling...", null, new EventHandler(this.PlotBase_5067));
  416. // }
  417. // else
  418. // {
  419. // popUpMenu.AddItem("Scaling...", null, new EventHandler(this.PlotBase_5067));
  420. // }
  421. // }
  422. // flag2 = (this != this.mChart.GetPricePlot());
  423. // if (flag2)
  424. // {
  425. // popUpMenu.AddSeperator();
  426. // popUpMenu.AddItem("Save", ImageMan.GetImage("Save24.png"), new EventHandler(this.PlotBase_5072));
  427. // popUpMenu.AddSeperator();
  428. // popUpMenu.AddItem("Remove", ImageMan.GetImage("DeleteHS.png"), new EventHandler(this.PlotBase_5073));
  429. // }
  430. // PopUpMenu arg_3BB_0 = popUpMenu;
  431. // Point offset = new Point(-3.0, -5.0);
  432. // arg_3BB_0.Show(e, offset);
  433. //}
  434. }
  435. private void OnDataChanged(object change)
  436. {
  437. bool flag = change is PlotDeletingDataChange;
  438. if (flag)
  439. {
  440. this.Delete();
  441. }
  442. else
  443. {
  444. this.SourceDataChange(RuntimeHelpers.GetObjectValue(change));
  445. }
  446. }
  447. //private void PlotBase_5066(object sender, EventArgs e)
  448. //{
  449. // PlotGuideLineEditor plotGuideLineEditor = new PlotGuideLineEditor();
  450. // plotGuideLineEditor.Show(this);
  451. //}
  452. //private void PlotBase_5067(object sender, EventArgs e)
  453. //{
  454. // bool flag = e is MouseEventArgs;
  455. // if (flag)
  456. // {
  457. // ValueScaleEditor valueScaleEditor = new ValueScaleEditor(this.ScaleLayer);
  458. // valueScaleEditor.Show((MouseEventArgs)e);
  459. // }
  460. //}
  461. //private void PlotBase_5068(object sender, EventArgs e)
  462. //{
  463. // bool flag = this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic;
  464. // if (flag)
  465. // {
  466. // ((ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525()).ScaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic;
  467. // }
  468. //}
  469. //private void PlotBase_5069(object sender, EventArgs e)
  470. //{
  471. // bool flag = this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic;
  472. // if (flag)
  473. // {
  474. // ((ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525()).ScaleMode = ValueScalerArithmetic.enumScaleMethod.eLog;
  475. // }
  476. //}
  477. //private void PlotBase_5070(object sender, EventArgs e)
  478. //{
  479. // bool flag = e is MouseEventArgs;
  480. // if (flag)
  481. // {
  482. // WebChartEditor webChartEditor = new WebChartEditor(this.mChart, WebChartEditor.DialogStyle.eCompare);
  483. // webChartEditor.DoWhiteBackground();
  484. // webChartEditor.Show((MouseEventArgs)e);
  485. // }
  486. //}
  487. //private void PlotBase_5071(object sender, EventArgs e)
  488. //{
  489. // bool flag = e is MouseEventArgs;
  490. // if (flag)
  491. // {
  492. // AddIndicatorDialog addIndicatorDialog = new AddIndicatorDialog();
  493. // addIndicatorDialog.Show(this.mChart, this, (MouseEventArgs)e);
  494. // }
  495. //}
  496. //private void PlotBase_5072(object sender, EventArgs e)
  497. //{
  498. // SaveIndicatorDialog saveIndicatorDialog = new SaveIndicatorDialog();
  499. // saveIndicatorDialog.ShowDialog((MouseEventArgs)e, this);
  500. //}
  501. private void OnDelete(object sender, EventArgs e)
  502. {
  503. this.Delete();
  504. }
  505. private void RefreshChart()
  506. {
  507. this.Calculate();
  508. bool flag = this.mChart != null;
  509. if (flag)
  510. {
  511. this.mChart.Refresh();
  512. }
  513. }
  514. private void ShowPlotEdit(object sender, EventArgs e)
  515. {
  516. // this.ShowPlotEdit(this.mLegendBtn);
  517. }
  518. #endregion Private Methods
  519. #endregion Methods
  520. #region Nested Types
  521. private class PlotBase_260
  522. {
  523. #region Fields
  524. public List<IBarDataPoint> PlotBase_260_1661;
  525. public List<IBarDataPoint> PlotBase_260_1662;
  526. #endregion Fields
  527. #region Constructors
  528. public PlotBase_260()
  529. {
  530. this.PlotBase_260_1661 = new List<IBarDataPoint>();
  531. this.PlotBase_260_1662 = new List<IBarDataPoint>();
  532. }
  533. #endregion Constructors
  534. #region Other
  535. //public void PlotBase_260_5092()
  536. //{
  537. // dlgTestMQL dlgTestMQL = new dlgTestMQL();
  538. // dlgTestMQL.Show(this.PlotBase_260_1663, this.PlotBase_260_1664, this.PlotBase_260_1661, this.PlotBase_260_1662);
  539. //}
  540. #endregion Other
  541. }
  542. #endregion Nested Types
  543. #region Other
  544. //public abstract XElement ToXML(List<object> args);
  545. #endregion Other
  546. }
  547. }