ChartPane.xaml.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.EnumTypes;
  3. using MuchInfo.Chart.Data.Interfaces;
  4. using MuchInfo.Chart.Infrastructure.Helpers;
  5. using MuchInfo.Chart.WPF.Controls.DateScaling;
  6. using MuchInfo.Chart.WPF.Controls.Indicator;
  7. using MuchInfo.Chart.WPF.Controls.ValueScaling;
  8. using MuchInfo.Chart.WPF.Primitives;
  9. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Runtime.CompilerServices;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. namespace MuchInfo.Chart.WPF
  19. {
  20. /// <summary>
  21. /// ChartPane.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class ChartPane : UserControl, IDeletable
  24. {
  25. #region Fields
  26. private List<FrameworkElement> _allElements;
  27. private Border _border;
  28. private Chart _chart;
  29. private DateMarginSplitter _dataMarginSplitter;
  30. private List<FrameworkElement> _drawingPlots;
  31. private IDrawingTool _drawingTool;
  32. /// <summary>
  33. /// 鼠标按下状态
  34. /// </summary>
  35. private bool _isMouseDown;
  36. private List<FrameworkElement> _plots;
  37. private Rect _rect;
  38. private ValueScaleDisplayCollection _rightScaleControl;
  39. private ValueScaleDisplayCollection _leftScaleControl;
  40. private ScaleLayer _scaleLayer;
  41. private StackPanel _stackPanel;
  42. private double _width;
  43. private bool _isTimeSpaning = false; //是否是分时图的图表容器
  44. #endregion Fields
  45. #region Constructors
  46. public ChartPane()
  47. {
  48. base.SizeChanged += (new SizeChangedEventHandler(this.Pane_SizeChanged));
  49. this.AllScaleLayers = new List<ScaleLayer>();
  50. this._rightScaleControl = new ValueScaleDisplayCollection();
  51. this._leftScaleControl = new ValueScaleDisplayCollection();
  52. this._border = new Border();
  53. this._stackPanel = new StackPanel();
  54. this._width = 0.0;
  55. this._isMouseDown = false;
  56. this._drawingPlots = new List<FrameworkElement>();
  57. this.InitializeComponent();
  58. btnMore.Padding = new Thickness(4.0, 1.0, 4.0, 1.0);
  59. btnMore.BorderThickness = new Thickness(0.0);
  60. this.Legend.Children.Remove(this.btnMore);
  61. this._stackPanel.Orientation = Orientation.Horizontal;
  62. _border.BorderThickness = new Thickness(1.0);
  63. _border.BorderBrush = new SolidColorBrush(ColorHelper.DimGray);
  64. _border.CornerRadius = new CornerRadius(3.0);
  65. _border.Padding = new Thickness(1.0, 3.0, 1.0, 3.0);
  66. this._border.Background = (new SolidColorBrush(Colors.Gray));
  67. this._border.Child = (this._stackPanel);
  68. }
  69. public ChartPane(Chart chart)
  70. : this()
  71. {
  72. this.SetChart(chart);
  73. }
  74. public ChartPane(Chart chart, bool isTimeSpaning)
  75. : this()
  76. {
  77. this.SetChart(chart);
  78. _isTimeSpaning = isTimeSpaning;
  79. }
  80. #endregion Constructors
  81. #region Properties
  82. #region Public Properties
  83. /// <summary>
  84. /// 是否为分时图
  85. /// </summary>
  86. public bool IsTimeSpaning { get { return _isTimeSpaning; } }
  87. public List<ScaleLayer> AllScaleLayers
  88. {
  89. get;
  90. private set;
  91. }
  92. #endregion Public Properties
  93. #region Internal Properties
  94. /// <summary>
  95. /// Gets the right scale control.
  96. /// </summary>
  97. internal FrameworkElement RightScaleControl
  98. {
  99. get
  100. {
  101. return this._rightScaleControl;
  102. }
  103. }
  104. internal FrameworkElement LeftScaleControl
  105. {
  106. get
  107. {
  108. return this._leftScaleControl;
  109. }
  110. }
  111. #endregion Internal Properties
  112. #region Private Properties
  113. internal bool IsPriceHistory
  114. {
  115. get
  116. {
  117. if (this.AllScaleLayers == null || !this.AllScaleLayers.Any()) return false;
  118. //var price = from scaleLayer in AllScaleLayers
  119. // where scaleLayer != null
  120. // select scaleLayer.AllPlots() into plots
  121. // where plots != null && plots.Any()
  122. // from plot in plots
  123. // select plot.Calculation() into calc
  124. // where calc is PriceHistoryCalculation
  125. // select calc;
  126. //var first = price.FirstOrDefault() as PriceHistoryCalculation;
  127. //if (first == null) return false;
  128. //return first.IsFirstChart;
  129. bool result = false;
  130. foreach (var scaleLayer in AllScaleLayers)
  131. {
  132. foreach (var formula in scaleLayer.AllDisplayFormula)
  133. {
  134. if (formula.FormulaModel != null && formula.FormulaModel.IsMain)
  135. {
  136. result = formula.FormulaModel.IsMain;
  137. break;
  138. }
  139. }
  140. if (result) break;
  141. }
  142. return result;
  143. }
  144. }
  145. #endregion Private Properties
  146. #endregion Properties
  147. #region Methods
  148. #region Public Methods
  149. /// <summary>
  150. /// 只显示第一个图表的网格
  151. /// </summary>
  152. public void DisplayFristGrid()
  153. {
  154. if (this.AllScaleLayers == null || !this.AllScaleLayers.Any()) return;
  155. for (int i = 1; i < this.AllScaleLayers.Count; i++)
  156. {
  157. var valueScale = this.AllScaleLayers[i].GetLeftValueScaleDisplay();
  158. valueScale.DrawGridLines = false;
  159. }
  160. }
  161. public void AddScaleLayer(ScaleLayer sl)
  162. {
  163. this.AllScaleLayers.Add(sl);
  164. ValueScaleDisplay valueScaleDisplay = sl.GetRightValueScaleDisplay();
  165. if (valueScaleDisplay != null)
  166. {
  167. this._rightScaleControl.AddScale(valueScaleDisplay);
  168. }
  169. var leftValueScaleDisplay = sl.GetLeftValueScaleDisplay();
  170. if (leftValueScaleDisplay != null)
  171. {
  172. this._leftScaleControl.AddScale(leftValueScaleDisplay);
  173. }
  174. ValueScaleBufferAdjuster valueScaleBufferAdjuster = sl.GetRightValueScaleDisplay().GetTopAdjuster();
  175. if (valueScaleBufferAdjuster != null)
  176. {
  177. valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
  178. valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
  179. valueScaleBufferAdjuster.HorizontalAlignment = HorizontalAlignment.Right;
  180. this.PaintArea.Children.Add(valueScaleBufferAdjuster);
  181. valueScaleBufferAdjuster = sl.GetRightValueScaleDisplay().GetBottomAdjuster();
  182. valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
  183. valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
  184. valueScaleBufferAdjuster.HorizontalAlignment = HorizontalAlignment.Right;
  185. this.PaintArea.Children.Add(valueScaleBufferAdjuster);
  186. }
  187. }
  188. //public List<ScaleLayer> AllScaleLayers()
  189. //{
  190. // return this.AllScaleLayers;
  191. //}
  192. //public void FromXML(XElement node)
  193. //{
  194. // bool flag;
  195. // try
  196. // {
  197. // IEnumerator<XElement> enumerator = node.Elements().GetEnumerator();
  198. // while (enumerator.MoveNext())
  199. // {
  200. // XElement current = enumerator.Current;
  201. // IXmlSavable iXMLSavable = XmlTypeCreator.MakeElement(current);
  202. // flag = (iXMLSavable != null && iXMLSavable is ScaleLayer);
  203. // if (flag)
  204. // {
  205. // this.Pane_5151((ScaleLayer)iXMLSavable);
  206. // }
  207. // }
  208. // }
  209. // finally
  210. // {
  211. // //IEnumerator<XElement> enumerator;
  212. // //flag = (enumerator != null);
  213. // //if (flag)
  214. // //{
  215. // // enumerator.Dispose();
  216. // //}
  217. // }
  218. // flag = (node.Attribute("ScaleIndex") != null);
  219. // if (flag)
  220. // {
  221. // this.rightScaleControl.SelectedIndexXml = int.Parse(node.Attribute("ScaleIndex").Value);
  222. // }
  223. //}
  224. public Chart GetChart()
  225. {
  226. return this._chart;
  227. }
  228. public Rect LastDrawnRect()
  229. {
  230. return this._rect;
  231. }
  232. public void OnDelete()
  233. {
  234. try
  235. {
  236. List<ScaleLayer>.Enumerator enumerator = this.AllScaleLayers.GetEnumerator();
  237. while (enumerator.MoveNext())
  238. {
  239. ScaleLayer current = enumerator.Current;
  240. current.OnDelete();
  241. }
  242. }
  243. finally
  244. {
  245. //List<ScaleLayer>.Enumerator enumerator;
  246. //enumerator.Dispose();
  247. }
  248. }
  249. public string RootName()
  250. {
  251. return "CHARTPANE";
  252. }
  253. public void SetChart(Chart aChart)
  254. {
  255. this._chart = aChart;
  256. }
  257. #endregion Public Methods
  258. #region Internal Methods
  259. internal int AllScaleLayersCount()
  260. {
  261. return this.AllScaleLayers.Count;
  262. }
  263. /// <summary>
  264. /// 是否刷新图表
  265. /// </summary>
  266. internal bool RefreshChartFlag { get; set; }
  267. /// <summary>
  268. ///
  269. /// </summary>
  270. /// <param name="dateScale"></param>
  271. /// <param name="dateScalePlot"></param>
  272. /// <param name="isUpdateDataSet">是否更新数据集</param>
  273. internal void BuildChartPane(IDateScaler dateScale, DateScaleDisplay dateScalePlot, bool isUpdateDataSet = false)
  274. {
  275. this.btnRemovePane.Visibility = IsPriceHistory ? Visibility.Collapsed : Visibility.Visible;
  276. this.Legend.Visibility = Visibility.Visible;
  277. var list = new List<FrameworkElement>();
  278. var list2 = new List<FrameworkElement>();
  279. var height = Math.Max(this.PaintArea.ActualHeight - 6.0, 0);
  280. var width = Math.Max((float)(this.PaintArea.ActualWidth - (double)_chart.RightBuffer), 0);
  281. var rect = new Rect(0.0, 0.0, (double)width, (double)height);
  282. list.Add(dateScalePlot.BuildPath(dateScale, rect, this._chart));
  283. if (this.AllScaleLayers != null && this.AllScaleLayers.Any())
  284. {
  285. foreach (var current in AllScaleLayers)
  286. {
  287. //更新plot数据集
  288. if (isUpdateDataSet) current.UpdatePlotsDataSource(_chart.DataSet, RefreshChartFlag);
  289. if (_chart.DataSet != null && _chart.DataSet.DataPoints != null
  290. && _chart.DataSet.DataPoints.Any()
  291. || _chart.CycleType == CycleType.TimeSharing)
  292. {
  293. list.AddRange(current.BuildScaleLayer(this._chart, this, dateScale, rect));
  294. list2.AddRange(current.GetAllPlotElements());
  295. }
  296. }
  297. }
  298. this._allElements = list;
  299. this._plots = list2;
  300. this._rect = rect;
  301. this.RemoveChartPane();
  302. //指定左边数据控件的最小宽度-随字体变化
  303. this._leftScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
  304. this._leftScaleControl.DoPending();
  305. //指定右边数据控件的最小宽度-随字体变化
  306. this._rightScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
  307. this._rightScaleControl.DoPending();
  308. this.UpdateDateMarginSplitter();
  309. }
  310. /// <summary>
  311. /// 创建分时图
  312. /// </summary>
  313. /// <param name="dateScale"</param>
  314. /// <param name="dateScalePlot"></param>
  315. internal void BuildTimeShareChartPane(IDateScaler dateScale, DateScaleDisplay dateScalePlot)
  316. {
  317. this.btnRemovePane.Visibility = Visibility.Collapsed;
  318. this.Legend.Visibility = Visibility.Visible;
  319. var list = new List<FrameworkElement>();
  320. var list2 = new List<FrameworkElement>();
  321. var height = Math.Max(this.PaintArea.ActualHeight - 6.0, 0); //(double)_chart.RightBuffer
  322. var width = Math.Max((float)(this.PaintArea.ActualWidth - _chart.RightBuffer), 0);
  323. var rect = new Rect(0.0, 0.0, (double)width, (double)height);
  324. list.AddRange(dateScalePlot.BuilTimeSpandPath(dateScale, rect, this._chart));
  325. if (this.AllScaleLayers != null && this.AllScaleLayers.Any())
  326. {
  327. foreach (var current in AllScaleLayers)
  328. {
  329. list.AddRange(current.BuildScaleLayer(this._chart, this, dateScale, rect));
  330. list2.AddRange(current.GetAllPlotElements());
  331. }
  332. }
  333. this._allElements = list;
  334. this._plots = list2;
  335. this._rect = rect;
  336. this.RemoveChartPane();
  337. //指定左边数据控件的最小宽度-随字体变化
  338. this._leftScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
  339. this._leftScaleControl.DoPending();
  340. //指定右边数据控件的最小宽度-随字体变化
  341. this._rightScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
  342. this._rightScaleControl.DoPending();
  343. this.UpdateDateMarginSplitter();
  344. }
  345. /// <summary>
  346. /// 获取矩形第一行真实高度
  347. /// </summary>
  348. /// <returns></returns>
  349. internal double GetActualHeight()
  350. {
  351. return this.LayoutRoot.RowDefinitions[0].ActualHeight;
  352. }
  353. internal ScaleLayer GetScaleLayer(int index)
  354. {
  355. return this.AllScaleLayers[index];
  356. }
  357. /// <summary>
  358. /// 处理当前图例有画线工具时执行操作
  359. /// </summary>
  360. internal void OnDrawing()
  361. {
  362. if (this._chart != null && _chart.CurrentDrawingTool != null)
  363. {
  364. if (this.PaintArea.Cursor != Cursors.None)
  365. {
  366. this.PaintArea.Cursor = Cursors.None;
  367. this.PaintArea.Background = (new SolidColorBrush(Colors.Transparent));
  368. }
  369. }
  370. else
  371. {
  372. if (this.PaintArea.Cursor != Cursors.Arrow)
  373. {
  374. this.PaintArea.Cursor = Cursors.Arrow;
  375. }
  376. if (this.PaintArea.Background != null)
  377. {
  378. this.PaintArea.Background = null;
  379. }
  380. }
  381. }
  382. internal void RemoveAllScaleLayers()
  383. {
  384. var scalerLayers = AllScaleLayers;
  385. if (scalerLayers == null || !scalerLayers.Any()) return;
  386. ScaleLayer mainLayer = null;
  387. foreach (var current in scalerLayers)
  388. {
  389. if (current.HasPricePlot())
  390. {
  391. mainLayer = current;
  392. continue;
  393. }
  394. ClearScaleLayer(current);
  395. }
  396. this.AllScaleLayers.Clear();
  397. if (mainLayer != null)
  398. {
  399. this.AllScaleLayers.Add(mainLayer);
  400. }
  401. }
  402. private void ClearScaleLayer(ScaleLayer sl)
  403. {
  404. sl.RemoveAllPlots();
  405. var valueScaleDisplay = sl.GetRightValueScaleDisplay();
  406. if (valueScaleDisplay != null)
  407. {
  408. this.PaintArea.Children.Remove(valueScaleDisplay.GetTopAdjuster());
  409. this.PaintArea.Children.Remove(valueScaleDisplay.GetBottomAdjuster());
  410. this._rightScaleControl.RemoveScale(valueScaleDisplay);
  411. }
  412. var leftValueScaleDisplay = sl.GetLeftValueScaleDisplay();
  413. if (leftValueScaleDisplay != null)
  414. {
  415. this.PaintArea.Children.Remove(leftValueScaleDisplay.GetTopAdjuster());
  416. this.PaintArea.Children.Remove(leftValueScaleDisplay.GetBottomAdjuster());
  417. this._leftScaleControl.RemoveScale(leftValueScaleDisplay);
  418. }
  419. }
  420. internal void RemoveScaleLayer(ScaleLayer sl)
  421. {
  422. this.AllScaleLayers.Remove(sl);
  423. ClearScaleLayer(sl);
  424. var flag = (this.AllScaleLayers.Count == 0);
  425. if (flag)
  426. {
  427. this._chart.RemoveChartPane(this);
  428. }
  429. }
  430. internal void SimulateDrawingMouseDown(object sender, MouseButtonEventArgs e)
  431. {
  432. this.PaintArea_MouseLeftButtonDown(RuntimeHelpers.GetObjectValue(sender), e);
  433. }
  434. #endregion Internal Methods
  435. #region Private Methods
  436. private void btnMore_MouseEnter(object sender, MouseEventArgs e)
  437. {
  438. this.btnMore.Padding = new Thickness(3.0, 0.0, 3.0, 0.0);
  439. this.btnMore.BorderThickness = new Thickness(1.0);
  440. }
  441. private void btnMore_MouseLeave(object sender, MouseEventArgs e)
  442. {
  443. this.btnMore.Padding = new Thickness(4.0, 1.0, 4.0, 1.0);
  444. this.btnMore.BorderThickness = new Thickness(0.0);
  445. }
  446. private void btnMore_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  447. {
  448. //Popup popup = PopUpManager.CreateAppOverlay();
  449. //this.Pane_1692.Background = (new SolidColorBrush(this.parentContainer.BackColorTop));
  450. //popup.Child = (this.Pane_1692);
  451. //popup.IsOpen = (true);
  452. //popup.InvalidateArrange();
  453. //popup.UpdateLayout();
  454. //PopUpManager.MovePopup(popup, this.btnMore, PopUpManager.eRelativePositionHoriz.eFlushLefts, PopUpManager.eRelativePositionVert.eBelow);
  455. //MuchInfo.Chart.Utilities.Helpers.Geometry.EnsureControlInApplication(popup);
  456. }
  457. private void btnRemovePane_MouseEnter(object sender, MouseEventArgs e)
  458. {
  459. this.btnRemovePane.Background = new SolidColorBrush(Color.FromArgb(255, 50, 50, 50));
  460. this.txtRemovePane.Foreground = new SolidColorBrush(ColorHelper.Red);
  461. this.btnRemovePane.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 110, 110, 110));
  462. }
  463. private void btnRemovePane_MouseLeave(object sender, MouseEventArgs e)
  464. {
  465. this.btnRemovePane.Background = null;
  466. this.txtRemovePane.Foreground = new SolidColorBrush(ColorHelper.Gray);
  467. this.btnRemovePane.BorderBrush = new SolidColorBrush(ColorHelper.Gray);
  468. }
  469. private void btnRemovePane_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  470. {
  471. this._isMouseDown = true;
  472. }
  473. private void btnRemovePane_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  474. {
  475. if (_isMouseDown)
  476. {
  477. this._chart.RemoveChartPane(this);
  478. }
  479. }
  480. private void MoveDrawingTool(MouseEventArgs e)
  481. {
  482. bool flag = this._drawingTool != null;
  483. if (flag)
  484. {
  485. Point position = e.GetPosition(this.PaintArea);
  486. //加上左边纵坐标位移
  487. position.X += this._chart.GetChartPanelOffset();
  488. var num = (float)(this.PaintArea.ActualHeight - 6.0);
  489. flag = (num < 0f);
  490. if (flag)
  491. {
  492. num = 0f;
  493. }
  494. var num2 = (float)(this.PaintArea.ActualWidth - (double)this._chart.RightBuffer);
  495. flag = (num2 < 0f);
  496. if (flag)
  497. {
  498. num2 = 0f;
  499. }
  500. flag = (position.X < 0.0);
  501. if (flag)
  502. {
  503. position.X = (0.0);
  504. }
  505. flag = (position.Y < 0.0);
  506. if (flag)
  507. {
  508. position.Y = (0.0);
  509. }
  510. flag = (position.X > (double)num2);
  511. if (flag)
  512. {
  513. position.X = ((double)num2);
  514. }
  515. flag = (position.Y > (double)num);
  516. if (flag)
  517. {
  518. position.Y = ((double)num);
  519. }
  520. DateTime aDate = this._chart.DateScaler.OriginalDateFromX(position.X);
  521. float aVal = this._scaleLayer.GetRightValueScaler().ValueFromPercent((float)(1.0 - position.Y / this.PaintArea.ActualHeight));
  522. this._drawingTool.MoveSecondPoint(aDate, aVal, position);
  523. this.UpdateDrawingPlots();
  524. }
  525. }
  526. private void PaintArea_LostMouseCapture(object sender, MouseEventArgs e)
  527. {
  528. var symbol = this._chart.CurrentSymbol;
  529. if (string.IsNullOrWhiteSpace(symbol)) return;
  530. if (this._drawingTool != null && this._chart != null)
  531. {
  532. this._scaleLayer.AddDrawing(symbol, this._drawingTool);
  533. IDrawingTool pane_ = this._drawingTool;
  534. this._drawingTool = null;
  535. this._chart.SetDrawingTool();
  536. this._chart.Refresh();
  537. pane_.InitDone(e);
  538. this._chart.Refresh();
  539. }
  540. }
  541. private void PaintArea_MouseEnter(object sender, MouseEventArgs e)
  542. {
  543. var symbol = this._chart.CurrentSymbol;
  544. if (string.IsNullOrWhiteSpace(symbol)) return;
  545. if (_chart.PointerType == PointerType.Drawing)
  546. {
  547. this.OnDrawing();
  548. this.SetCursorImagePos(e, true);
  549. }
  550. else
  551. {
  552. this.OnDrawing();
  553. this._chart.DrawingToolExecute();
  554. }
  555. }
  556. private void PaintArea_MouseLeave(object sender, MouseEventArgs e)
  557. {
  558. var symbol = this._chart.CurrentSymbol;
  559. if (string.IsNullOrWhiteSpace(symbol)) return;
  560. this.PaintArea.Cursor = Cursors.Arrow;
  561. this.PaintArea.Background = (null);
  562. this.SetCursorImagePos(e, false);
  563. }
  564. private void PaintArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  565. {
  566. var symbol = this._chart.CurrentSymbol;
  567. if (string.IsNullOrWhiteSpace(symbol)) return;
  568. try
  569. {
  570. bool flag = _chart.CurrentDrawingTool != null && this.AllScaleLayers.Count > 0;
  571. if (flag)
  572. {
  573. this._scaleLayer = this.AllScaleLayers[0];
  574. this._drawingTool = _chart.CurrentDrawingTool.Clone();
  575. e.Handled = true;
  576. this.PaintArea.CaptureMouse();
  577. Point position = e.GetPosition(this.PaintArea);
  578. //加上左边纵坐标位移
  579. position.X += this._chart.GetChartPanelOffset();
  580. DateTime aDate = this._chart.DateScaler.OriginalDateFromX(position.X);
  581. float aVal =
  582. this._scaleLayer.GetRightValueScaler()
  583. .ValueFromPercent((float)(1.0 - position.Y / this.PaintArea.ActualHeight));
  584. this._drawingTool.InitPoint(aDate, aVal, this._scaleLayer, this._rect, position);
  585. this._drawingTool.MoveSecondPoint(aDate, aVal, position);
  586. this.UpdateDrawingPlots();
  587. }
  588. }
  589. catch (Exception ex)
  590. {
  591. }
  592. }
  593. private void PaintArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  594. {
  595. var symbol = this._chart.CurrentSymbol;
  596. if (this._drawingTool != null && !string.IsNullOrWhiteSpace(symbol) && this._chart != null)
  597. {
  598. this.MoveDrawingTool(e);
  599. this._scaleLayer.AddDrawing(this._chart.CurrentSymbol, this._drawingTool);
  600. this._drawingTool = null;
  601. this._chart.SetDrawingTool();
  602. this.PaintArea.ReleaseMouseCapture();
  603. }
  604. }
  605. private void PaintArea_MouseMove(object sender, MouseEventArgs e)
  606. {
  607. var symbol = this._chart.CurrentSymbol;
  608. if (string.IsNullOrWhiteSpace(symbol)) return;
  609. bool flag = _chart.PointerType == PointerType.Drawing;
  610. if (flag)
  611. {
  612. this.MoveDrawingTool(e);
  613. this.SetCursorImagePos(e, true);
  614. }
  615. else
  616. {
  617. this.OnDrawing();
  618. this._chart.DrawingToolExecute();
  619. }
  620. }
  621. private void PaintArea_SizeChanged(object sender, SizeChangedEventArgs e)
  622. {
  623. var symbol = this._chart.CurrentSymbol;
  624. if (string.IsNullOrWhiteSpace(symbol)) return;
  625. foreach (var current in this.PaintArea.Children)
  626. {
  627. if (current is ValueScaleBufferAdjuster)
  628. {
  629. var valueScaleBufferAdjuster = (ValueScaleBufferAdjuster)current;
  630. valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
  631. valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
  632. }
  633. }
  634. }
  635. private void Pane_SizeChanged(object sender, SizeChangedEventArgs e)
  636. {
  637. bool flag = this._chart != null;
  638. if (flag && RefreshChartFlag)
  639. {
  640. this._chart.Refresh();
  641. RefreshChartFlag = false;
  642. }
  643. }
  644. private void RemoveChartPane()
  645. {
  646. var list = new List<UIElement>();
  647. foreach (var current in this.PaintArea.Children)
  648. {
  649. var pane = current as UIElement;
  650. if (!(pane is DateMarginSplitter) && !(pane is ValueScaleBufferAdjuster))
  651. {
  652. list.Add(pane);
  653. }
  654. }
  655. foreach (var uiElement in list)
  656. {
  657. this.PaintArea.Children.Remove(uiElement);
  658. }
  659. if (this._allElements != null)
  660. {
  661. foreach (var uiElement in _allElements)
  662. {
  663. this.PaintArea.Children.Add(uiElement);
  664. }
  665. }
  666. var flag = this.Legend.Children.Contains(this.btnMore);
  667. if (flag)
  668. {
  669. this.Legend.Children.Remove(this.btnMore);
  670. }
  671. bool flag2 = false;
  672. double num = this.LayoutRoot.ActualWidth - (this.colLeft.ActualWidth + this.btnMore.Width);
  673. bool flag3;
  674. checked
  675. {
  676. flag = (this._stackPanel.Children.Count + this.Legend.Children.Count != this._plots.Count);
  677. if (flag)
  678. {
  679. flag2 = true;
  680. }
  681. else
  682. {
  683. flag = (this.LayoutRoot.ActualWidth != this._width);
  684. if (flag)
  685. {
  686. flag2 = true;
  687. }
  688. else
  689. {
  690. try
  691. {
  692. int arg_248_0 = 0;
  693. int num2 = this.Legend.Children.Count - 1;
  694. int num3 = arg_248_0;
  695. while (true)
  696. {
  697. int arg_2ED_0 = num3;
  698. int num4 = num2;
  699. if (arg_2ED_0 > num4)
  700. {
  701. goto IL_2F2;
  702. }
  703. flag = (num3 < this.Legend.Children.Count);
  704. if (flag)
  705. {
  706. flag3 = (this.Legend.Children[num3] != this._plots[num3]);
  707. if (flag3)
  708. {
  709. break;
  710. }
  711. }
  712. else
  713. {
  714. flag3 = (this._stackPanel.Children[num3 - this.Legend.Children.Count] != this._plots[num3]);
  715. if (flag3)
  716. {
  717. goto Block_27;
  718. }
  719. }
  720. num3++;
  721. }
  722. flag2 = true;
  723. goto IL_2F2;
  724. Block_27:
  725. flag2 = true;
  726. IL_2F2: ;
  727. }
  728. catch (Exception expr_2F4)
  729. {
  730. ProjectData.SetProjectError(expr_2F4);
  731. flag2 = true;
  732. ProjectData.ClearProjectError();
  733. }
  734. }
  735. }
  736. flag3 = flag2;
  737. }
  738. if (flag3)
  739. {
  740. if (this._plots != null && this._plots.Any())
  741. {
  742. foreach (var plot in this._plots)
  743. {
  744. var indicatorLegend = plot as IndicatorLegend;
  745. if (indicatorLegend == null) continue;
  746. indicatorLegend.Abbreviate = false;
  747. }
  748. }
  749. bool flag4 = false;
  750. this.Legend.Children.Clear();
  751. this._stackPanel.Children.Clear();
  752. if (this._plots != null && this._plots.Any())
  753. {
  754. foreach (var current in this._plots)
  755. {
  756. this.Legend.Children.Add(current);
  757. flag3 = (current.ActualWidth < num);
  758. if (!flag3)
  759. {
  760. flag4 = true;
  761. break;
  762. }
  763. num -= current.ActualWidth;
  764. }
  765. }
  766. flag3 = flag4;
  767. if (flag3)
  768. {
  769. this.Legend.Children.Clear();
  770. this._stackPanel.Children.Clear();
  771. num = this.LayoutRoot.ActualWidth - (this.colLeft.ActualWidth + this.btnMore.Width);
  772. if (this._plots != null && this._plots.Any())
  773. {
  774. foreach (var current in this._plots)
  775. {
  776. if (current is IndicatorLegend)
  777. {
  778. ((IndicatorLegend)current).Abbreviate = true;
  779. }
  780. this.Legend.Children.Add(current);
  781. if (current.ActualWidth < num)
  782. {
  783. num -= current.ActualWidth;
  784. }
  785. else
  786. {
  787. this.Legend.Children.Remove(current);
  788. if (current is IndicatorLegend)
  789. {
  790. ((IndicatorLegend)current).Abbreviate = false;
  791. }
  792. num = -1.0;
  793. this._stackPanel.Children.Add(current);
  794. Grid grid = new Grid();
  795. grid.Height = (4.0);
  796. this._stackPanel.Children.Add(grid);
  797. if (this.btnMore.Parent == null)
  798. {
  799. this.Legend.Children.Add(this.btnMore);
  800. }
  801. }
  802. }
  803. }
  804. }
  805. }
  806. this.UpdateDrawingPlots();
  807. this._width = this.LayoutRoot.ActualWidth;
  808. }
  809. private void SetCursorImagePos(MouseEventArgs e, bool Allow)
  810. {
  811. bool flag = Allow && this._chart != null && this._chart.CurrentDrawingTool != null;
  812. if (flag)
  813. {
  814. this._chart.SetCursorImagePos(true, e);
  815. }
  816. else
  817. {
  818. flag = (this._chart != null);
  819. if (flag)
  820. {
  821. this._chart.SetCursorImagePos(false, e);
  822. }
  823. }
  824. }
  825. private void UpdateDateMarginSplitter()
  826. {
  827. if (this.AllScaleLayers.Where(x => x.AllPlots.Where(y => y != null).Count() > 0).Count() > 0)
  828. {
  829. if (this._dataMarginSplitter == null)
  830. {
  831. this._dataMarginSplitter = new DateMarginSplitter(this.PaintArea, this._chart);
  832. this._dataMarginSplitter.VerticalAlignment = (VerticalAlignment)(2);
  833. this.PaintArea.Children.Add(this._dataMarginSplitter);
  834. }
  835. var allDateScaler = (AllDateScaler)this._chart.DateScaler;
  836. this._dataMarginSplitter.DateMarginSplitter_2672(allDateScaler);
  837. int indexOfLastDataDate = allDateScaler.IndexOfLastDataDate;
  838. if (indexOfLastDataDate <= allDateScaler.EndIndex)
  839. {
  840. float num = allDateScaler.PercentFromIndex(indexOfLastDataDate);
  841. double num2 = (double)allDateScaler.XforDate(allDateScaler.DateValue(indexOfLastDataDate));
  842. num2 += (allDateScaler.DistanceBetweenDates() * 0.3);
  843. this._dataMarginSplitter.SetValue(Canvas.LeftProperty, num2);
  844. this._dataMarginSplitter.SetValue(Canvas.TopProperty, 0.0);
  845. this._dataMarginSplitter.Visibility = Visibility.Visible;
  846. this._dataMarginSplitter.Height = (Math.Max(0.0, this.PaintArea.ActualHeight - 3.0));
  847. }
  848. else
  849. {
  850. this._dataMarginSplitter.Visibility = Visibility.Collapsed;
  851. }
  852. }
  853. else
  854. {
  855. if (this._dataMarginSplitter != null)
  856. {
  857. this.PaintArea.Children.Remove(this._dataMarginSplitter);
  858. this._dataMarginSplitter = null;
  859. }
  860. }
  861. }
  862. private void UpdateDrawingPlots()
  863. {
  864. if (_drawingPlots != null)
  865. {
  866. foreach (var plot in _drawingPlots)
  867. {
  868. if (this.PaintArea.Children.Contains(plot))
  869. {
  870. this.PaintArea.Children.Remove(plot);
  871. }
  872. }
  873. this._drawingPlots.Clear();
  874. }
  875. if (this._drawingTool != null)
  876. {
  877. float num = (float)(this.PaintArea.ActualHeight - 6.0);
  878. if (num < 0f)
  879. {
  880. num = 0f;
  881. }
  882. float num2 = (float)(this.PaintArea.ActualWidth - (double)this._chart.RightBuffer);
  883. if (num2 < 0f)
  884. {
  885. num2 = 0f;
  886. }
  887. var aRect = new Rect(0.0, 0.0, (double)num2, (double)num);
  888. this._drawingPlots = this._drawingTool.GetPlots(this._chart, this._scaleLayer, aRect, false);
  889. if (_drawingPlots != null)
  890. {
  891. foreach (var plot in _drawingPlots)
  892. {
  893. this.PaintArea.Children.Add(plot);
  894. }
  895. }
  896. }
  897. }
  898. #endregion Private Methods
  899. #endregion Methods
  900. }
  901. }