| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016 |
- using Microsoft.VisualBasic.CompilerServices;
- using MuchInfo.Chart.Data.EnumTypes;
- using MuchInfo.Chart.Data.Interfaces;
- using MuchInfo.Chart.Infrastructure.Helpers;
- using MuchInfo.Chart.WPF.Controls.DateScaling;
- using MuchInfo.Chart.WPF.Controls.Indicator;
- using MuchInfo.Chart.WPF.Controls.ValueScaling;
- using MuchInfo.Chart.WPF.Primitives;
- using MuchInfo.Chart.WPF.Primitives.Interfaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace MuchInfo.Chart.WPF
- {
- /// <summary>
- /// ChartPane.xaml 的交互逻辑
- /// </summary>
- public partial class ChartPane : UserControl, IDeletable
- {
- #region Fields
- private List<FrameworkElement> _allElements;
- private Border _border;
- private Chart _chart;
- private DateMarginSplitter _dataMarginSplitter;
- private List<FrameworkElement> _drawingPlots;
- private IDrawingTool _drawingTool;
- /// <summary>
- /// 鼠标按下状态
- /// </summary>
- private bool _isMouseDown;
- private List<FrameworkElement> _plots;
- private Rect _rect;
- private ValueScaleDisplayCollection _rightScaleControl;
- private ValueScaleDisplayCollection _leftScaleControl;
- private ScaleLayer _scaleLayer;
- private StackPanel _stackPanel;
- private double _width;
- private bool _isTimeSpaning = false; //是否是分时图的图表容器
- #endregion Fields
- #region Constructors
- public ChartPane()
- {
- base.SizeChanged += (new SizeChangedEventHandler(this.Pane_SizeChanged));
- this.AllScaleLayers = new List<ScaleLayer>();
- this._rightScaleControl = new ValueScaleDisplayCollection();
- this._leftScaleControl = new ValueScaleDisplayCollection();
- this._border = new Border();
- this._stackPanel = new StackPanel();
- this._width = 0.0;
- this._isMouseDown = false;
- this._drawingPlots = new List<FrameworkElement>();
- this.InitializeComponent();
- btnMore.Padding = new Thickness(4.0, 1.0, 4.0, 1.0);
- btnMore.BorderThickness = new Thickness(0.0);
- this.Legend.Children.Remove(this.btnMore);
- this._stackPanel.Orientation = Orientation.Horizontal;
- _border.BorderThickness = new Thickness(1.0);
- _border.BorderBrush = new SolidColorBrush(ColorHelper.DimGray);
- _border.CornerRadius = new CornerRadius(3.0);
- _border.Padding = new Thickness(1.0, 3.0, 1.0, 3.0);
- this._border.Background = (new SolidColorBrush(Colors.Gray));
- this._border.Child = (this._stackPanel);
- }
- public ChartPane(Chart chart)
- : this()
- {
- this.SetChart(chart);
- }
- public ChartPane(Chart chart, bool isTimeSpaning)
- : this()
- {
- this.SetChart(chart);
- _isTimeSpaning = isTimeSpaning;
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- /// <summary>
- /// 是否为分时图
- /// </summary>
- public bool IsTimeSpaning { get { return _isTimeSpaning; } }
- public List<ScaleLayer> AllScaleLayers
- {
- get;
- private set;
- }
- #endregion Public Properties
- #region Internal Properties
- /// <summary>
- /// Gets the right scale control.
- /// </summary>
- internal FrameworkElement RightScaleControl
- {
- get
- {
- return this._rightScaleControl;
- }
- }
- internal FrameworkElement LeftScaleControl
- {
- get
- {
- return this._leftScaleControl;
- }
- }
- #endregion Internal Properties
- #region Private Properties
- internal bool IsPriceHistory
- {
- get
- {
- if (this.AllScaleLayers == null || !this.AllScaleLayers.Any()) return false;
- //var price = from scaleLayer in AllScaleLayers
- // where scaleLayer != null
- // select scaleLayer.AllPlots() into plots
- // where plots != null && plots.Any()
- // from plot in plots
- // select plot.Calculation() into calc
- // where calc is PriceHistoryCalculation
- // select calc;
- //var first = price.FirstOrDefault() as PriceHistoryCalculation;
- //if (first == null) return false;
- //return first.IsFirstChart;
- bool result = false;
- foreach (var scaleLayer in AllScaleLayers)
- {
- foreach (var formula in scaleLayer.AllDisplayFormula)
- {
- if (formula.FormulaModel != null && formula.FormulaModel.IsMain)
- {
- result = formula.FormulaModel.IsMain;
- break;
- }
- }
- if (result) break;
- }
- return result;
- }
- }
- #endregion Private Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- /// <summary>
- /// 只显示第一个图表的网格
- /// </summary>
- public void DisplayFristGrid()
- {
- if (this.AllScaleLayers == null || !this.AllScaleLayers.Any()) return;
- for (int i = 1; i < this.AllScaleLayers.Count; i++)
- {
- var valueScale = this.AllScaleLayers[i].GetLeftValueScaleDisplay();
- valueScale.DrawGridLines = false;
- }
- }
- public void AddScaleLayer(ScaleLayer sl)
- {
- this.AllScaleLayers.Add(sl);
- ValueScaleDisplay valueScaleDisplay = sl.GetRightValueScaleDisplay();
- if (valueScaleDisplay != null)
- {
- this._rightScaleControl.AddScale(valueScaleDisplay);
- }
- var leftValueScaleDisplay = sl.GetLeftValueScaleDisplay();
- if (leftValueScaleDisplay != null)
- {
- this._leftScaleControl.AddScale(leftValueScaleDisplay);
- }
- ValueScaleBufferAdjuster valueScaleBufferAdjuster = sl.GetRightValueScaleDisplay().GetTopAdjuster();
- if (valueScaleBufferAdjuster != null)
- {
- valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
- valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
- valueScaleBufferAdjuster.HorizontalAlignment = HorizontalAlignment.Right;
- this.PaintArea.Children.Add(valueScaleBufferAdjuster);
- valueScaleBufferAdjuster = sl.GetRightValueScaleDisplay().GetBottomAdjuster();
- valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
- valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
- valueScaleBufferAdjuster.HorizontalAlignment = HorizontalAlignment.Right;
- this.PaintArea.Children.Add(valueScaleBufferAdjuster);
- }
- }
- //public List<ScaleLayer> AllScaleLayers()
- //{
- // return this.AllScaleLayers;
- //}
- //public void FromXML(XElement node)
- //{
- // bool flag;
- // try
- // {
- // IEnumerator<XElement> enumerator = node.Elements().GetEnumerator();
- // while (enumerator.MoveNext())
- // {
- // XElement current = enumerator.Current;
- // IXmlSavable iXMLSavable = XmlTypeCreator.MakeElement(current);
- // flag = (iXMLSavable != null && iXMLSavable is ScaleLayer);
- // if (flag)
- // {
- // this.Pane_5151((ScaleLayer)iXMLSavable);
- // }
- // }
- // }
- // finally
- // {
- // //IEnumerator<XElement> enumerator;
- // //flag = (enumerator != null);
- // //if (flag)
- // //{
- // // enumerator.Dispose();
- // //}
- // }
- // flag = (node.Attribute("ScaleIndex") != null);
- // if (flag)
- // {
- // this.rightScaleControl.SelectedIndexXml = int.Parse(node.Attribute("ScaleIndex").Value);
- // }
- //}
- public Chart GetChart()
- {
- return this._chart;
- }
- public Rect LastDrawnRect()
- {
- return this._rect;
- }
- public void OnDelete()
- {
- try
- {
- List<ScaleLayer>.Enumerator enumerator = this.AllScaleLayers.GetEnumerator();
- while (enumerator.MoveNext())
- {
- ScaleLayer current = enumerator.Current;
- current.OnDelete();
- }
- }
- finally
- {
- //List<ScaleLayer>.Enumerator enumerator;
- //enumerator.Dispose();
- }
- }
- public string RootName()
- {
- return "CHARTPANE";
- }
- public void SetChart(Chart aChart)
- {
- this._chart = aChart;
- }
- #endregion Public Methods
- #region Internal Methods
- internal int AllScaleLayersCount()
- {
- return this.AllScaleLayers.Count;
- }
- /// <summary>
- /// 是否刷新图表
- /// </summary>
- internal bool RefreshChartFlag { get; set; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="dateScale"></param>
- /// <param name="dateScalePlot"></param>
- /// <param name="isUpdateDataSet">是否更新数据集</param>
- internal void BuildChartPane(IDateScaler dateScale, DateScaleDisplay dateScalePlot, bool isUpdateDataSet = false)
- {
- this.btnRemovePane.Visibility = IsPriceHistory ? Visibility.Collapsed : Visibility.Visible;
- this.Legend.Visibility = Visibility.Visible;
- var list = new List<FrameworkElement>();
- var list2 = new List<FrameworkElement>();
- var height = Math.Max(this.PaintArea.ActualHeight - 6.0, 0);
- var width = Math.Max((float)(this.PaintArea.ActualWidth - (double)_chart.RightBuffer), 0);
- var rect = new Rect(0.0, 0.0, (double)width, (double)height);
- list.Add(dateScalePlot.BuildPath(dateScale, rect, this._chart));
- if (this.AllScaleLayers != null && this.AllScaleLayers.Any())
- {
- foreach (var current in AllScaleLayers)
- {
- //更新plot数据集
- if (isUpdateDataSet) current.UpdatePlotsDataSource(_chart.DataSet, RefreshChartFlag);
- if (_chart.DataSet != null && _chart.DataSet.DataPoints != null
- && _chart.DataSet.DataPoints.Any()
- || _chart.CycleType == CycleType.TimeSharing)
- {
- list.AddRange(current.BuildScaleLayer(this._chart, this, dateScale, rect));
- list2.AddRange(current.GetAllPlotElements());
- }
- }
- }
- this._allElements = list;
- this._plots = list2;
- this._rect = rect;
- this.RemoveChartPane();
- //指定左边数据控件的最小宽度-随字体变化
- this._leftScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
- this._leftScaleControl.DoPending();
- //指定右边数据控件的最小宽度-随字体变化
- this._rightScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
- this._rightScaleControl.DoPending();
- this.UpdateDateMarginSplitter();
- }
- /// <summary>
- /// 创建分时图
- /// </summary>
- /// <param name="dateScale"</param>
- /// <param name="dateScalePlot"></param>
- internal void BuildTimeShareChartPane(IDateScaler dateScale, DateScaleDisplay dateScalePlot)
- {
- this.btnRemovePane.Visibility = Visibility.Collapsed;
- this.Legend.Visibility = Visibility.Visible;
- var list = new List<FrameworkElement>();
- var list2 = new List<FrameworkElement>();
- var height = Math.Max(this.PaintArea.ActualHeight - 6.0, 0); //(double)_chart.RightBuffer
- var width = Math.Max((float)(this.PaintArea.ActualWidth - _chart.RightBuffer), 0);
- var rect = new Rect(0.0, 0.0, (double)width, (double)height);
- list.AddRange(dateScalePlot.BuilTimeSpandPath(dateScale, rect, this._chart));
- if (this.AllScaleLayers != null && this.AllScaleLayers.Any())
- {
- foreach (var current in AllScaleLayers)
- {
- list.AddRange(current.BuildScaleLayer(this._chart, this, dateScale, rect));
- list2.AddRange(current.GetAllPlotElements());
- }
- }
- this._allElements = list;
- this._plots = list2;
- this._rect = rect;
- this.RemoveChartPane();
- //指定左边数据控件的最小宽度-随字体变化
- this._leftScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
- this._leftScaleControl.DoPending();
- //指定右边数据控件的最小宽度-随字体变化
- this._rightScaleControl.MinWidth = this._chart.ChartFontSize * 3 + 10;
- this._rightScaleControl.DoPending();
- this.UpdateDateMarginSplitter();
- }
- /// <summary>
- /// 获取矩形第一行真实高度
- /// </summary>
- /// <returns></returns>
- internal double GetActualHeight()
- {
- return this.LayoutRoot.RowDefinitions[0].ActualHeight;
- }
- internal ScaleLayer GetScaleLayer(int index)
- {
- return this.AllScaleLayers[index];
- }
- /// <summary>
- /// 处理当前图例有画线工具时执行操作
- /// </summary>
- internal void OnDrawing()
- {
- if (this._chart != null && _chart.CurrentDrawingTool != null)
- {
- if (this.PaintArea.Cursor != Cursors.None)
- {
- this.PaintArea.Cursor = Cursors.None;
- this.PaintArea.Background = (new SolidColorBrush(Colors.Transparent));
- }
- }
- else
- {
- if (this.PaintArea.Cursor != Cursors.Arrow)
- {
- this.PaintArea.Cursor = Cursors.Arrow;
- }
- if (this.PaintArea.Background != null)
- {
- this.PaintArea.Background = null;
- }
- }
- }
- internal void RemoveAllScaleLayers()
- {
- var scalerLayers = AllScaleLayers;
- if (scalerLayers == null || !scalerLayers.Any()) return;
- ScaleLayer mainLayer = null;
- foreach (var current in scalerLayers)
- {
- if (current.HasPricePlot())
- {
- mainLayer = current;
- continue;
- }
- ClearScaleLayer(current);
- }
- this.AllScaleLayers.Clear();
- if (mainLayer != null)
- {
- this.AllScaleLayers.Add(mainLayer);
- }
- }
- private void ClearScaleLayer(ScaleLayer sl)
- {
- sl.RemoveAllPlots();
- var valueScaleDisplay = sl.GetRightValueScaleDisplay();
- if (valueScaleDisplay != null)
- {
- this.PaintArea.Children.Remove(valueScaleDisplay.GetTopAdjuster());
- this.PaintArea.Children.Remove(valueScaleDisplay.GetBottomAdjuster());
- this._rightScaleControl.RemoveScale(valueScaleDisplay);
- }
- var leftValueScaleDisplay = sl.GetLeftValueScaleDisplay();
- if (leftValueScaleDisplay != null)
- {
- this.PaintArea.Children.Remove(leftValueScaleDisplay.GetTopAdjuster());
- this.PaintArea.Children.Remove(leftValueScaleDisplay.GetBottomAdjuster());
- this._leftScaleControl.RemoveScale(leftValueScaleDisplay);
- }
- }
- internal void RemoveScaleLayer(ScaleLayer sl)
- {
- this.AllScaleLayers.Remove(sl);
- ClearScaleLayer(sl);
- var flag = (this.AllScaleLayers.Count == 0);
- if (flag)
- {
- this._chart.RemoveChartPane(this);
- }
- }
- internal void SimulateDrawingMouseDown(object sender, MouseButtonEventArgs e)
- {
- this.PaintArea_MouseLeftButtonDown(RuntimeHelpers.GetObjectValue(sender), e);
- }
- #endregion Internal Methods
- #region Private Methods
- private void btnMore_MouseEnter(object sender, MouseEventArgs e)
- {
- this.btnMore.Padding = new Thickness(3.0, 0.0, 3.0, 0.0);
- this.btnMore.BorderThickness = new Thickness(1.0);
- }
- private void btnMore_MouseLeave(object sender, MouseEventArgs e)
- {
- this.btnMore.Padding = new Thickness(4.0, 1.0, 4.0, 1.0);
- this.btnMore.BorderThickness = new Thickness(0.0);
- }
- private void btnMore_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- //Popup popup = PopUpManager.CreateAppOverlay();
- //this.Pane_1692.Background = (new SolidColorBrush(this.parentContainer.BackColorTop));
- //popup.Child = (this.Pane_1692);
- //popup.IsOpen = (true);
- //popup.InvalidateArrange();
- //popup.UpdateLayout();
- //PopUpManager.MovePopup(popup, this.btnMore, PopUpManager.eRelativePositionHoriz.eFlushLefts, PopUpManager.eRelativePositionVert.eBelow);
- //MuchInfo.Chart.Utilities.Helpers.Geometry.EnsureControlInApplication(popup);
- }
- private void btnRemovePane_MouseEnter(object sender, MouseEventArgs e)
- {
- this.btnRemovePane.Background = new SolidColorBrush(Color.FromArgb(255, 50, 50, 50));
- this.txtRemovePane.Foreground = new SolidColorBrush(ColorHelper.Red);
- this.btnRemovePane.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 110, 110, 110));
- }
- private void btnRemovePane_MouseLeave(object sender, MouseEventArgs e)
- {
- this.btnRemovePane.Background = null;
- this.txtRemovePane.Foreground = new SolidColorBrush(ColorHelper.Gray);
- this.btnRemovePane.BorderBrush = new SolidColorBrush(ColorHelper.Gray);
- }
- private void btnRemovePane_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- this._isMouseDown = true;
- }
- private void btnRemovePane_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if (_isMouseDown)
- {
- this._chart.RemoveChartPane(this);
- }
- }
- private void MoveDrawingTool(MouseEventArgs e)
- {
- bool flag = this._drawingTool != null;
- if (flag)
- {
- Point position = e.GetPosition(this.PaintArea);
- //加上左边纵坐标位移
- position.X += this._chart.GetChartPanelOffset();
- var num = (float)(this.PaintArea.ActualHeight - 6.0);
- flag = (num < 0f);
- if (flag)
- {
- num = 0f;
- }
- var num2 = (float)(this.PaintArea.ActualWidth - (double)this._chart.RightBuffer);
- flag = (num2 < 0f);
- if (flag)
- {
- num2 = 0f;
- }
- flag = (position.X < 0.0);
- if (flag)
- {
- position.X = (0.0);
- }
- flag = (position.Y < 0.0);
- if (flag)
- {
- position.Y = (0.0);
- }
- flag = (position.X > (double)num2);
- if (flag)
- {
- position.X = ((double)num2);
- }
- flag = (position.Y > (double)num);
- if (flag)
- {
- position.Y = ((double)num);
- }
- DateTime aDate = this._chart.DateScaler.OriginalDateFromX(position.X);
- float aVal = this._scaleLayer.GetRightValueScaler().ValueFromPercent((float)(1.0 - position.Y / this.PaintArea.ActualHeight));
- this._drawingTool.MoveSecondPoint(aDate, aVal, position);
- this.UpdateDrawingPlots();
- }
- }
- private void PaintArea_LostMouseCapture(object sender, MouseEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- if (this._drawingTool != null && this._chart != null)
- {
- this._scaleLayer.AddDrawing(symbol, this._drawingTool);
- IDrawingTool pane_ = this._drawingTool;
- this._drawingTool = null;
- this._chart.SetDrawingTool();
- this._chart.Refresh();
- pane_.InitDone(e);
- this._chart.Refresh();
- }
- }
- private void PaintArea_MouseEnter(object sender, MouseEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- if (_chart.PointerType == PointerType.Drawing)
- {
- this.OnDrawing();
- this.SetCursorImagePos(e, true);
- }
- else
- {
- this.OnDrawing();
- this._chart.DrawingToolExecute();
- }
- }
- private void PaintArea_MouseLeave(object sender, MouseEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- this.PaintArea.Cursor = Cursors.Arrow;
- this.PaintArea.Background = (null);
- this.SetCursorImagePos(e, false);
- }
- private void PaintArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- try
- {
- bool flag = _chart.CurrentDrawingTool != null && this.AllScaleLayers.Count > 0;
- if (flag)
- {
- this._scaleLayer = this.AllScaleLayers[0];
- this._drawingTool = _chart.CurrentDrawingTool.Clone();
- e.Handled = true;
- this.PaintArea.CaptureMouse();
- Point position = e.GetPosition(this.PaintArea);
- //加上左边纵坐标位移
- position.X += this._chart.GetChartPanelOffset();
- DateTime aDate = this._chart.DateScaler.OriginalDateFromX(position.X);
- float aVal =
- this._scaleLayer.GetRightValueScaler()
- .ValueFromPercent((float)(1.0 - position.Y / this.PaintArea.ActualHeight));
- this._drawingTool.InitPoint(aDate, aVal, this._scaleLayer, this._rect, position);
- this._drawingTool.MoveSecondPoint(aDate, aVal, position);
- this.UpdateDrawingPlots();
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void PaintArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (this._drawingTool != null && !string.IsNullOrWhiteSpace(symbol) && this._chart != null)
- {
- this.MoveDrawingTool(e);
- this._scaleLayer.AddDrawing(this._chart.CurrentSymbol, this._drawingTool);
- this._drawingTool = null;
- this._chart.SetDrawingTool();
- this.PaintArea.ReleaseMouseCapture();
- }
- }
- private void PaintArea_MouseMove(object sender, MouseEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- bool flag = _chart.PointerType == PointerType.Drawing;
- if (flag)
- {
- this.MoveDrawingTool(e);
- this.SetCursorImagePos(e, true);
- }
- else
- {
- this.OnDrawing();
- this._chart.DrawingToolExecute();
- }
- }
- private void PaintArea_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- var symbol = this._chart.CurrentSymbol;
- if (string.IsNullOrWhiteSpace(symbol)) return;
- foreach (var current in this.PaintArea.Children)
- {
- if (current is ValueScaleBufferAdjuster)
- {
- var valueScaleBufferAdjuster = (ValueScaleBufferAdjuster)current;
- valueScaleBufferAdjuster.SetValue(Canvas.LeftProperty, this.PaintArea.ActualWidth * 0.75);
- valueScaleBufferAdjuster.Width = (this.PaintArea.ActualWidth * 0.25);
- }
- }
- }
- private void Pane_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- bool flag = this._chart != null;
- if (flag && RefreshChartFlag)
- {
- this._chart.Refresh();
- RefreshChartFlag = false;
- }
- }
- private void RemoveChartPane()
- {
- var list = new List<UIElement>();
- foreach (var current in this.PaintArea.Children)
- {
- var pane = current as UIElement;
- if (!(pane is DateMarginSplitter) && !(pane is ValueScaleBufferAdjuster))
- {
- list.Add(pane);
- }
- }
- foreach (var uiElement in list)
- {
- this.PaintArea.Children.Remove(uiElement);
- }
- if (this._allElements != null)
- {
- foreach (var uiElement in _allElements)
- {
- this.PaintArea.Children.Add(uiElement);
- }
- }
- var flag = this.Legend.Children.Contains(this.btnMore);
- if (flag)
- {
- this.Legend.Children.Remove(this.btnMore);
- }
- bool flag2 = false;
- double num = this.LayoutRoot.ActualWidth - (this.colLeft.ActualWidth + this.btnMore.Width);
- bool flag3;
- checked
- {
- flag = (this._stackPanel.Children.Count + this.Legend.Children.Count != this._plots.Count);
- if (flag)
- {
- flag2 = true;
- }
- else
- {
- flag = (this.LayoutRoot.ActualWidth != this._width);
- if (flag)
- {
- flag2 = true;
- }
- else
- {
- try
- {
- int arg_248_0 = 0;
- int num2 = this.Legend.Children.Count - 1;
- int num3 = arg_248_0;
- while (true)
- {
- int arg_2ED_0 = num3;
- int num4 = num2;
- if (arg_2ED_0 > num4)
- {
- goto IL_2F2;
- }
- flag = (num3 < this.Legend.Children.Count);
- if (flag)
- {
- flag3 = (this.Legend.Children[num3] != this._plots[num3]);
- if (flag3)
- {
- break;
- }
- }
- else
- {
- flag3 = (this._stackPanel.Children[num3 - this.Legend.Children.Count] != this._plots[num3]);
- if (flag3)
- {
- goto Block_27;
- }
- }
- num3++;
- }
- flag2 = true;
- goto IL_2F2;
- Block_27:
- flag2 = true;
- IL_2F2: ;
- }
- catch (Exception expr_2F4)
- {
- ProjectData.SetProjectError(expr_2F4);
- flag2 = true;
- ProjectData.ClearProjectError();
- }
- }
- }
- flag3 = flag2;
- }
- if (flag3)
- {
- if (this._plots != null && this._plots.Any())
- {
- foreach (var plot in this._plots)
- {
- var indicatorLegend = plot as IndicatorLegend;
- if (indicatorLegend == null) continue;
- indicatorLegend.Abbreviate = false;
- }
- }
- bool flag4 = false;
- this.Legend.Children.Clear();
- this._stackPanel.Children.Clear();
- if (this._plots != null && this._plots.Any())
- {
- foreach (var current in this._plots)
- {
- this.Legend.Children.Add(current);
- flag3 = (current.ActualWidth < num);
- if (!flag3)
- {
- flag4 = true;
- break;
- }
- num -= current.ActualWidth;
- }
- }
- flag3 = flag4;
- if (flag3)
- {
- this.Legend.Children.Clear();
- this._stackPanel.Children.Clear();
- num = this.LayoutRoot.ActualWidth - (this.colLeft.ActualWidth + this.btnMore.Width);
- if (this._plots != null && this._plots.Any())
- {
- foreach (var current in this._plots)
- {
- if (current is IndicatorLegend)
- {
- ((IndicatorLegend)current).Abbreviate = true;
- }
- this.Legend.Children.Add(current);
- if (current.ActualWidth < num)
- {
- num -= current.ActualWidth;
- }
- else
- {
- this.Legend.Children.Remove(current);
- if (current is IndicatorLegend)
- {
- ((IndicatorLegend)current).Abbreviate = false;
- }
- num = -1.0;
- this._stackPanel.Children.Add(current);
- Grid grid = new Grid();
- grid.Height = (4.0);
- this._stackPanel.Children.Add(grid);
- if (this.btnMore.Parent == null)
- {
- this.Legend.Children.Add(this.btnMore);
- }
- }
- }
- }
- }
- }
- this.UpdateDrawingPlots();
- this._width = this.LayoutRoot.ActualWidth;
- }
- private void SetCursorImagePos(MouseEventArgs e, bool Allow)
- {
- bool flag = Allow && this._chart != null && this._chart.CurrentDrawingTool != null;
- if (flag)
- {
- this._chart.SetCursorImagePos(true, e);
- }
- else
- {
- flag = (this._chart != null);
- if (flag)
- {
- this._chart.SetCursorImagePos(false, e);
- }
- }
- }
- private void UpdateDateMarginSplitter()
- {
- if (this.AllScaleLayers.Where(x => x.AllPlots.Where(y => y != null).Count() > 0).Count() > 0)
- {
- if (this._dataMarginSplitter == null)
- {
- this._dataMarginSplitter = new DateMarginSplitter(this.PaintArea, this._chart);
- this._dataMarginSplitter.VerticalAlignment = (VerticalAlignment)(2);
- this.PaintArea.Children.Add(this._dataMarginSplitter);
- }
- var allDateScaler = (AllDateScaler)this._chart.DateScaler;
- this._dataMarginSplitter.DateMarginSplitter_2672(allDateScaler);
- int indexOfLastDataDate = allDateScaler.IndexOfLastDataDate;
- if (indexOfLastDataDate <= allDateScaler.EndIndex)
- {
- float num = allDateScaler.PercentFromIndex(indexOfLastDataDate);
- double num2 = (double)allDateScaler.XforDate(allDateScaler.DateValue(indexOfLastDataDate));
- num2 += (allDateScaler.DistanceBetweenDates() * 0.3);
- this._dataMarginSplitter.SetValue(Canvas.LeftProperty, num2);
- this._dataMarginSplitter.SetValue(Canvas.TopProperty, 0.0);
- this._dataMarginSplitter.Visibility = Visibility.Visible;
- this._dataMarginSplitter.Height = (Math.Max(0.0, this.PaintArea.ActualHeight - 3.0));
- }
- else
- {
- this._dataMarginSplitter.Visibility = Visibility.Collapsed;
- }
- }
- else
- {
- if (this._dataMarginSplitter != null)
- {
- this.PaintArea.Children.Remove(this._dataMarginSplitter);
- this._dataMarginSplitter = null;
- }
- }
- }
- private void UpdateDrawingPlots()
- {
- if (_drawingPlots != null)
- {
- foreach (var plot in _drawingPlots)
- {
- if (this.PaintArea.Children.Contains(plot))
- {
- this.PaintArea.Children.Remove(plot);
- }
- }
- this._drawingPlots.Clear();
- }
- if (this._drawingTool != null)
- {
- float num = (float)(this.PaintArea.ActualHeight - 6.0);
- if (num < 0f)
- {
- num = 0f;
- }
- float num2 = (float)(this.PaintArea.ActualWidth - (double)this._chart.RightBuffer);
- if (num2 < 0f)
- {
- num2 = 0f;
- }
- var aRect = new Rect(0.0, 0.0, (double)num2, (double)num);
- this._drawingPlots = this._drawingTool.GetPlots(this._chart, this._scaleLayer, aRect, false);
- if (_drawingPlots != null)
- {
- foreach (var plot in _drawingPlots)
- {
- this.PaintArea.Children.Add(plot);
- }
- }
- }
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|