using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.Infrastructure.Helpers; using MuchInfo.Chart.WPF.Controls.ValueScaling; using MuchInfo.Chart.WPF.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace MuchInfo.Chart.WPF.Primitives { public class ValueScaleDisplay : Canvas { #region Fields //private const int c_TimeSpaning = 3; //设置分时图显示网络是图表字体的多少倍,控制网格数量 private const int c_TimeSpaningGridCount = 8; //设置显示分时图显示图表风格数量 protected ValueScaleDisplay.ValueScaleMode mArithScaleMode; protected Color mBorderColor; protected List mDivisors; protected bool mDrawGridLines; protected ValueScaleDisplay.ValueScaleMode mExpScaleMode; private Brush _upBrush = Brushes.Red; /// /// 设置涨时的图表的颜色 /// public Brush UpBrush { get { return _upBrush; } set { _upBrush = value; } } private Brush _downBrush = Brushes.SeaGreen; /// /// 设置下跌里图表的颜色 /// public Brush DownBrush { get { return _downBrush; } set { _downBrush = value; } } private Brush _lastBrush = Brushes.White; public Brush LastBrush { get { return _lastBrush; } set { _lastBrush = value; } } /// /// 小数位数 /// protected int mFormatSigDigits; protected int mLineOpacity; protected DoubleCollection mLineStyle; protected ValueScaleDisplay.ValueScaleMode mLogScaleMode; protected Color mPercentColor; protected bool mShowScaleControls; protected bool mTextAlignLeft; protected ValueScaleDisplay.LRPlacement mTextPos; protected float _curNet; protected float _curPercent; protected float _divisor; protected float _fixedPercent; protected int _lineCount; private bool _allowAbbreviate; private ValueScaleBufferAdjuster _bottomAdjuster; private Chart _chart; private ChartPane _chartPane; private bool _flag2; private bool _flag3; private Color _lineColor; private Rect _rect; private ScaleLayer _scalelayer; private ValueScaleBufferAdjuster _topAdjuster; /// /// Y轴面板 /// private Canvas _yCanvas; private List _yList; private float _yValue; #endregion Fields #region Constructors public ValueScaleDisplay(IValueScaler valueScaler) { base.SizeChanged -= (new SizeChangedEventHandler(this.ValueScaleDisplay_SizeChanged)); base.SizeChanged += (new SizeChangedEventHandler(this.ValueScaleDisplay_SizeChanged)); this._scalelayer = null; this._lineCount = 5; this._divisor = 1f; this._fixedPercent = 1f; this.mFormatSigDigits = 2; this.mArithScaleMode = ValueScaleDisplay.ValueScaleMode.Auto; this.mLogScaleMode = ValueScaleDisplay.ValueScaleMode.Auto; this.mExpScaleMode = ValueScaleDisplay.ValueScaleMode.Auto; this.mTextPos = ValueScaleDisplay.LRPlacement.Right; this._lineColor = Colors.LightGray; this.mBorderColor = Colors.LightGray; this.mPercentColor = Colors.Red; this.mDrawGridLines = true; this.mTextAlignLeft = true; this.mShowScaleControls = false; this.mLineStyle = new DoubleCollection(); this.mLineOpacity = 10; this.mDivisors = new List(); this._flag2 = false; this._yValue = 0f; this._flag3 = false; this._allowAbbreviate = false; this.InitializeDivisors(); this._topAdjuster = new ValueScaleBufferAdjuster(); this._bottomAdjuster = new ValueScaleBufferAdjuster(); this._yCanvas = new Canvas(); this.Children.Add(this._yCanvas); this.CurrentValueScaler = valueScaler; } #endregion Constructors #region Enumerations public enum LRPlacement { Right, Left, None } public enum ValueScaleMode { Auto, Manual, LineCount, MaxLines, AutoPercent } public enum ValueScalePaintMode { AutoScale, AutoDivisor, AutoPercentScale, Divisor, FixedPercent, LineCount, } #endregion Enumerations #region Properties #region Public Properties public Color BorderColor { get { return this.mBorderColor; } set { this.mBorderColor = value; this.RefreshChart(); } } public float Divisor { get { return this._divisor; } set { bool flag = this._divisor != value; if (flag) { this._divisor = value; this.RefreshChart(); } } } public bool DrawGridLines { get { return this.mDrawGridLines; } set { this.mDrawGridLines = value; this.RefreshChart(); } } public float FixedPercent { get { return this._fixedPercent; } set { bool flag = this._fixedPercent != value; if (flag) { this._fixedPercent = value; this.RefreshChart(); } } } /// /// 小数位数 /// public int FormatSignificantDigits { get { return this.mFormatSigDigits; } set { this.mFormatSigDigits = value; } } public DoubleCollection GridLineStyle { get { return this.mLineStyle; } set { this.mLineStyle = value; this.RefreshChart(); } } public Color LineColor { get { return this._lineColor; } set { this._lineColor = value; this.RefreshChart(); } } public int LineCount { get { return this._lineCount; } set { bool flag = this._lineCount != value; if (flag) { this._lineCount = value; this.RefreshChart(); } } } public Color PercentColor { get { return this.mPercentColor; } set { this.mPercentColor = value; this.RefreshChart(); } } public ScaleLayer ScaleLayer { get { return this._scalelayer; } set { this._scalelayer = value; } } public ValueScaleDisplay.ValueScaleMode ScaleMode { get { bool flag = CurrentValueScaler is ValueScalerArithmetic; ValueScaleDisplay.ValueScaleMode result; if (flag) { result = this.mArithScaleMode; } else { result = ValueScaleDisplay.ValueScaleMode.Auto; } return result; } set { bool flag = CurrentValueScaler is ValueScalerArithmetic; if (flag) { this.mArithScaleMode = value; } this.RefreshChart(); } } public bool ShowScaleControls { get { return this.mShowScaleControls; } set { this.mShowScaleControls = value; this.RefreshChart(); } } public bool TextAlignLeft { get { return this.mTextAlignLeft; } set { this.mTextAlignLeft = value; this.RefreshChart(); } } public ValueScaleDisplay.LRPlacement ValueOrientation { get { return this.mTextPos; } set { this.mTextPos = value; this.RefreshChart(); } } #endregion Public Properties #region Internal Properties internal IValueScaler CurrentValueScaler { get; set; } #endregion Internal Properties #region Private Properties private ValueScaleDisplay.ValueScalePaintMode TextMode { get { bool flag = CurrentValueScaler is ValueScalerArithmetic; var result = new ValueScalePaintMode(); if (flag) { switch (this.mArithScaleMode) { case ValueScaleDisplay.ValueScaleMode.Auto: result = ValueScaleDisplay.ValueScalePaintMode.AutoDivisor; break; case ValueScaleDisplay.ValueScaleMode.Manual: result = ValueScaleDisplay.ValueScalePaintMode.Divisor; break; case ValueScaleDisplay.ValueScaleMode.LineCount: result = ValueScaleDisplay.ValueScalePaintMode.LineCount; break; case ValueScaleDisplay.ValueScaleMode.MaxLines: result = ValueScaleDisplay.ValueScalePaintMode.AutoScale; break; } } return result; } } #endregion Private Properties #endregion Properties #region Methods #region Internal Methods internal void BuildYList(ChartPane aPane, Rect theRect) { this._chartPane = aPane; bool flag = aPane == null; if (!flag) { var aRect = new Rect(theRect.X, theRect.Y + aPane.GetActualHeight(), theRect.Width, theRect.Height); this._rect = theRect; flag = this.CurrentValueScaler.Spread().Equals(0f); if (flag) { this._yCanvas.Children.Clear(); } else { Color color = Colors.White; flag = (this._scalelayer != null && this._scalelayer.AllPlots.Count > 0); if (flag) { color = this._scalelayer.AllPlots[0].GetPlotColor(); } this._allowAbbreviate = true; // if (aPane.IsPriceHistory) this._allowAbbreviate = false; if (aPane.IsPriceHistory) this._allowAbbreviate = false; var height = (float)this.ActualHeight; var list = new List(); var list2 = this._yList ?? this.GetYList(height, CurrentValueScaler, aPane.IsTimeSpaning); var fontFamily = new FontFamily("Verdana"); var foreground = new SolidColorBrush(color); if (list2 != null && list2.Any()) { if (!aPane.IsTimeSpaning) { foreach (var current in list2) { if (!current.Value.Equals(float.NaN)) { float num = CurrentValueScaler.YFromPercent(current.Value, aRect); var textBlock = new TextBlock { Text = current.Text, FontSize = ((double)this.FontSize()), FontFamily = (fontFamily), Foreground = (foreground), //Width = this.FontSize()*current.Text.Length*0.7 //固定长度,否则绘图区大小写会变动 Width = this.FontSize() * 7 * 0.7 }; //根据字符长度计算控件宽度 textBlock.SetValue(Canvas.LeftProperty, 3.0); textBlock.SetValue(Canvas.TopProperty, (double)num - (double)this.FontSize() * 0.6); list.Add(textBlock); } } } else //设置分时图刻度颜色 { foreach (var current in list2) { if (!current.Value.Equals(float.NaN)) { float num = CurrentValueScaler.YFromPercent(current.Value, aRect); var textBlock = new TextBlock { Text = current.Text, FontSize = ((double)this.FontSize()), FontFamily = (fontFamily), Width = TreeHelper.GetTextWidth(fontFamily, this.FontSize(), current.Text) //this.FontSize()*current.Text.Length*0.7 }; float valueNum = CurrentValueScaler.ValueFromPercent(current.Value); if (CurrentValueScaler.GetPercentBaseline() > valueNum) //设置红涨绿跌 { textBlock.Foreground = this.DownBrush; } else if (CurrentValueScaler.GetPercentBaseline() < valueNum) { textBlock.Foreground = this.UpBrush; } else { textBlock.Foreground = LastBrush; } //根据字符长度计算控件宽度 textBlock.SetValue(Canvas.LeftProperty, 3.0); textBlock.SetValue(Canvas.TopProperty, (double)num - (double)this.FontSize() * 0.6); list.Add(textBlock); } } } } this._flag3 = false; var flag2 = (this._scalelayer != null && this._scalelayer.AllPlots.Count > 0); //不添加默认数据显示 //if (flag2) //{ // PlotBase plotBase = this._scalelayer.AllPlots()[0]; // flag2 = (plotBase is LinePlot); // if (flag2) // { // var linePlot = (LinePlot)plotBase; // flag2 = (linePlot.GetDataSet() != null && linePlot.GetDataSet().DataPoints != null && linePlot.GetDataSet().DataPoints.Count > 0); // if (flag2) // { // float num2 = linePlot.GetDataSet().DataPoints[linePlot.GetDataSet().DataPoints.Count - 1].Value; // float valY = CurrentValueScaler.ScaledY(num2, aRect); // //超出范围不添加 // if (valY > 0 && valY < aRect.Height) list.Add(this.BuildDisplayBorder(valY, num2)); // } // } //} this._flag3 = this.IsPChangeFromBeginning(); if (_flag2) { float txtVal = CurrentValueScaler.ValueFromPercentDisplay((float)((aRect.Bottom - (double)this._yValue) / aRect.Height)); list.Add(this.BuildDisplayBorder(this._yValue, txtVal)); } this._yCanvas.Children.Clear(); if (list.Any()) { foreach (var current in list) { this._yCanvas.Children.Add(current); } } //计算rightcontrol 宽度 double width = 0; if (_yCanvas.Children != null && _yCanvas.Children.Count > 0) { var textBlocks = _yCanvas.Children.OfType().Where(z => !z.Width.Equals(0)); var enumerable = textBlocks as IList ?? textBlocks.ToList(); if (enumerable.Any()) { width = enumerable.Max(z => z.Width); } } this.Width = Math.Max(width, 50); bool flag3 = true; flag2 = (CurrentValueScaler is ValueScalerArithmetic); if (flag2) { flag = (((ValueScalerArithmetic)CurrentValueScaler).BoundingMethod == ValueScalerArithmetic.enumScaleBounding.eCentered); if (flag) { flag3 = false; } } else { flag3 = false; } flag2 = flag3;// && this.chartContainer.ShowMarginGrabs); if (flag2) { var valueScalerArithmetic = (ValueScalerArithmetic)CurrentValueScaler; this._topAdjuster.SetValues(this._chart, this._scalelayer.GetLeftValueScaleDisplay(), this._scalelayer.GetRightValueScaleDisplay(), true); var num8 = (double)(1f - valueScalerArithmetic.MaxAddPercent / 100f); this._topAdjuster.SetValue(Canvas.TopProperty, (double)valueScalerArithmetic.YFromPercent((float)num8, theRect)); this._bottomAdjuster.SetValues(this._chart, this._scalelayer.GetLeftValueScaleDisplay(), this._scalelayer.GetRightValueScaleDisplay(), false); num8 = (double)(valueScalerArithmetic.MinAddPercent / 100f); var num9 = (double)valueScalerArithmetic.YFromPercent((float)num8, theRect); flag2 = (num9 + 4.0 > theRect.Bottom); if (flag2) { num9 = theRect.Bottom - 4.0; } this._bottomAdjuster.SetValue(Canvas.TopProperty, num9); this._topAdjuster.Visibility = Visibility.Visible; this._bottomAdjuster.Visibility = Visibility.Visible; } else { this._topAdjuster.Visibility = Visibility.Collapsed; this._bottomAdjuster.Visibility = Visibility.Collapsed; } } } } internal void BuildYList(float aY) { this._flag2 = true; this._yValue = aY; try { this.BuildYList(this._chartPane, this._rect); } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } } internal void BuildYList() { this._flag2 = false; try { this.BuildYList(this._chartPane, this._rect); } catch (Exception expr_3F) { ProjectData.SetProjectError(expr_3F); ProjectData.ClearProjectError(); } } internal double FontSize() { bool flag = this._chart != null; double result; if (flag) { result = this._chart.ChartFontSize; } else { result = 12f; } return result; } internal ValueScaleBufferAdjuster GetBottomAdjuster() { return this._bottomAdjuster; } internal ValueScaleBufferAdjuster GetTopAdjuster() { return this._topAdjuster; } internal double GetValuePercent(double aY) { bool flag = this._chartPane != null; double result; if (flag) { Rect rect = new Rect(this._rect.X, this._rect.Y + this._chartPane.GetActualHeight(), this._rect.Width, this._rect.Height); flag = (rect.Height != 0.0); if (flag) { result = 1.0 - (aY - rect.Top) / rect.Height; return result; } } result = 0.0; return result; } internal List GetValueScaleDisplay(Chart theChart, IDateScaler dateScale, Rect aRect, List ylist, bool drawGridLines, bool isTimeSpaning) { var list = new List(); this._chart = theChart; var path = new Path { IsHitTestVisible = (false) }; list.Add(path); this._flag3 = this.IsPChangeFromBeginning(); bool flag = CurrentValueScaler.Spread().Equals(0); List result; if (flag) { result = list; } else { path.UseLayoutRounding = true; var geometryGroup = new GeometryGroup(); if (theChart.CycleType == CycleType.TimeSharing) { path.Stroke = theChart.TimeSharingGridBrush.Clone(); path.Stroke.Opacity = theChart.GridOpacity; } else { var solidColorBrush = new SolidColorBrush { Color = this._lineColor, Opacity = theChart.GridOpacity }; path.Stroke = solidColorBrush; path.StrokeThickness = 1.0; } var list2 = ylist == null ? this.GetYList((float)aRect.Height, CurrentValueScaler, isTimeSpaning) : UpdateYList(ylist); this._yList = list2; if (list2 != null && list2.Any()) { foreach (var current in list2) { if (!current.Value.Equals(float.NaN)) { float num = CurrentValueScaler.YFromPercent(current.Value, aRect); num = (float)((double)checked((int)Math.Round((double)num)) + 0.5); if (this.mDrawGridLines && drawGridLines) { var lineGeometry = new LineGeometry { StartPoint = new Point(aRect.Left, (double)num), EndPoint = new Point(aRect.Width, (double)num) }; geometryGroup.Children.Add(lineGeometry); } } } } if (this._flag3 && this.mDrawGridLines) { //显示百分比,画基准线 var line = new Line { IsHitTestVisible = (false), Stroke = new SolidColorBrush { Color =Colors.Blue, Opacity = (theChart.GridOpacity * 1.5) }, StrokeThickness = (3.0), X1 = (aRect.Left), X2 = (aRect.Right) }; if (isTimeSpaning) { line.Stroke = theChart.TimeSharingGridBrush.Clone(); line.Stroke.Opacity = (theChart.GridOpacity * 1.5); } float num = CurrentValueScaler.ScaledY(((ValueScalerArithmetic)CurrentValueScaler).GetPercentBaseline(), aRect); var y = Math.Round(num) + 0.5; line.Y1 = y; line.Y2 = y; list.Add(line); } path.Data = (geometryGroup); result = list; } return result; } internal List GetYList(float height, IValueScaler ValScale, bool isTimeSpaning) { if (this._chart == null || this._chart.DataSet == null || this._chart.DataSet.DataPoints == null || !this._chart.DataSet.DataPoints.Any()) return null; bool flag = true; List result; if (isTimeSpaning) //分时图显示网络线数量 { result = GetTimeSpaningScaleValues(height, ValScale); return result; } if (flag) { switch (this.TextMode) { case ValueScaleDisplay.ValueScalePaintMode.AutoScale: result = this.GetAAutoScaleValues(height, ValScale); break; case ValueScaleDisplay.ValueScalePaintMode.AutoDivisor: result = this.GetAutoDivisorValues(height, ValScale); break; case ValueScaleDisplay.ValueScalePaintMode.AutoPercentScale: result = this.GetAutoPercentScaleValues(height, ValScale); break; case ValueScaleDisplay.ValueScalePaintMode.Divisor: result = this.GetDivisorValues(height, ValScale); break; case ValueScaleDisplay.ValueScalePaintMode.FixedPercent: result = this.GetFixedPercentValues(height, ValScale); break; case ValueScaleDisplay.ValueScalePaintMode.LineCount: result = this.GetLineCountValues(height, ValScale); break; default: result = new List(); break; } } else { List list = new List(); ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = 0.01f; valueScaleDisplay_.SetText(ValScale.ValueFromPercentDisplay(0f), this); list.Add(valueScaleDisplay_); result = list; } return result; } #endregion Internal Methods #region Private Methods private Border BuildDisplayBorder(float valY, float txtVal) { var border = new Border { BorderThickness = new Thickness(1.0), CornerRadius = new CornerRadius(3.0), Padding = new Thickness(1.0, 0.0, 1.0, 1.0), BorderBrush = new SolidColorBrush(Colors.White), Background = new SolidColorBrush(Colors.Black) }; border.SetValue(Canvas.LeftProperty, 3.0); border.SetValue(Canvas.TopProperty, (double)valY - (double)this.FontSize() * 0.6); var textBlock = new TextBlock { Text = this.ConvertToString(txtVal), FontSize = (double)this.FontSize(), FontFamily = new FontFamily("Verdana"), Foreground = new SolidColorBrush(Colors.White), }; if (_chart.IsDarkBackground) { textBlock.Foreground = (new SolidColorBrush(Colors.White)); border.BorderBrush = (new SolidColorBrush(Colors.White)); border.Background = (new SolidColorBrush(Colors.Black)); } else { textBlock.Foreground = (new SolidColorBrush(Colors.Black)); border.BorderBrush = (new SolidColorBrush(Colors.Black)); border.Background = (new SolidColorBrush(Colors.White)); } border.Child = textBlock; return border; } /// /// 把数值转换为指点格式字符串(加% 或者转换成保留2位的小数) /// /// /// private string ConvertToString(float aVal) { if (_flag3) { return Strings.Format(aVal, "0.00") + "%"; } else { return Conversions.ToString(TextFormatting.FormatNumber(aVal, this.mFormatSigDigits, this._allowAbbreviate)); } } private List GetTimeSpaningScaleValues(float height, IValueScaler valScale) { var list = new List(); try { int num; checked { // num = (int)Math.Round((double)height / unchecked((double)this.GetFontSizeLength() * c_TimeSpaning)); // num = num % 2 == 0 ? num : num - 1; // 取偶数 num = c_TimeSpaningGridCount; int num2 = 0; while (true) { if (num2 > num) { break; } ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = (float)((double)num2 / (double)num); valueScaleDisplay_.SetText(valScale.ValueFromPercentDisplay(valueScaleDisplay_.Value), this); list.Add(valueScaleDisplay_); num2++; } } this._curNet = valScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - valScale.ValueFromPercentDisplay(0f); this._curPercent = (valScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - valScale.ValueFromPercentDisplay(0f)) / valScale.ValueFromPercentDisplay(0f); } catch (Exception expr_10D) { ProjectData.SetProjectError(expr_10D); ProjectData.ClearProjectError(); } return list; } private List GetAAutoScaleValues(float height, IValueScaler valScale) { var list = new List(); try { int num; checked { num = (int)Math.Round((double)height / unchecked((double)this.GetFontSizeLength() * 1.1)); int num2 = 0; while (true) { if (num2 > num) { break; } ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = (float)((double)num2 / (double)num); valueScaleDisplay_.SetText(valScale.ValueFromPercentDisplay(valueScaleDisplay_.Value), this); list.Add(valueScaleDisplay_); num2++; } } this._curNet = valScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - valScale.ValueFromPercentDisplay(0f); this._curPercent = (valScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - valScale.ValueFromPercentDisplay(0f)) / valScale.ValueFromPercentDisplay(0f); } catch (Exception expr_10D) { ProjectData.SetProjectError(expr_10D); ProjectData.ClearProjectError(); } return list; } private List GetAutoDivisorValues(float height, IValueScaler ValScale) { var list = new List(); List result; try { float num = ValScale.ValueFromPercentDisplay(1f); float num2 = ValScale.ValueFromPercentDisplay(0f); bool flag = ValScale.Inverse; if (flag) { num = ValScale.ValueFromPercentDisplay(0f); num2 = ValScale.ValueFromPercentDisplay(1f); } flag = (float.IsInfinity(num) || float.IsNaN(num)); if (flag) { result = list; return result; } int num3 = 0; int num4 = 0; int num6 = 0; bool flag2 = false; float num8 = 0f; checked { num3 = (int)Math.Round((double)unchecked(this.GetFontSizeLength() + 4f)); num4 = -1; int num5 = this.mDivisors.Count - 1; num6 = 0; while (true) { if (num6 > num5) { goto IL_1A8; } unchecked { float aVal = num - this.mDivisors[num6]; flag = ValScale.Inverse; if (flag) { flag2 = (Math.Abs(0f - ValScale.PercentFromValueDisplay(aVal)) * height >= (float)num3); if (flag2) { break; } } else { flag2 = (Math.Abs(1f - ValScale.PercentFromValueDisplay(aVal)) * height >= (float)num3); if (flag2) { goto Block_10; } } } num6++; } num8 = this.mDivisors[num6]; } flag2 = ((double)Math.Abs(1f - ValScale.PercentFromValueDisplay(num2 + num8)) > 0.25); if (flag2) { num4 = num6; goto IL_12A; } goto IL_12A; Block_10: num8 = this.mDivisors[num6]; flag2 = ((double)Math.Abs(0f - ValScale.PercentFromValueDisplay(num2 + num8)) > 0.25); if (flag2) { num4 = num6; } IL_1A8: flag2 = (num8 == 0f); if (flag2) { num8 = 10000f; } int num9 = 0; num = (float)checked((int)Math.Round((double)(num / num8))); num += 1f; num *= num8; while (true) { float num10 = ValScale.PercentFromValueDisplay(num); flag2 = (num10 <= 1f & num10 >= 0f); if (flag2) { ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = num10; valueScaleDisplay_.SetText(num, this); list.Add(valueScaleDisplay_); } flag2 = (num4 > 0 && (double)(Math.Abs(ValScale.PercentFromValueDisplay(num - num8) - ValScale.PercentFromValueDisplay(num)) * height) >= 1.5 * (double)num3); if (flag2) { while (num4 > 0 && Math.Abs(ValScale.PercentFromValueDisplay(num - this.mDivisors[checked(num4 - 1)]) - ValScale.PercentFromValueDisplay(num)) * height >= (float)num3) { checked { num4--; num8 = this.mDivisors[num4]; } } } num -= num8; checked { num9++; if (!ValScale.Inverse && num10 >= 0f) { goto IL_2F2; } if (ValScale.Inverse && num10 <= 100f) { goto IL_2F2; } goto IL_2FB; IL_2FF: bool arg_2FF_0; if (!arg_2FF_0) { break; } continue; IL_2FB: arg_2FF_0 = false; goto IL_2FF; IL_2F2: if (num9 >= 1000) { goto IL_2FB; } arg_2FF_0 = true; goto IL_2FF; } } this._curNet = num8; goto IL_356; IL_12A: goto IL_1A8; } catch (Exception expr_346) { ProjectData.SetProjectError(expr_346); ProjectData.ClearProjectError(); } IL_356: result = list; return result; } private List GetAutoPercentScaleValues(float height, IValueScaler ValScale) { List list = new List(); List result; try { int num = 0; float num2 = ValScale.ValueFromPercentDisplay(1f); float num3 = ValScale.ValueFromPercentDisplay(0f); bool flag = ValScale.Inverse; if (flag) { num2 = ValScale.ValueFromPercentDisplay(0f); num3 = ValScale.ValueFromPercentDisplay(1f); } flag = (float.IsInfinity(num2) || float.IsNaN(num2)); if (flag) { result = list; return result; } flag = (float.IsInfinity(num3) || float.IsNaN(num3)); if (flag) { result = list; return result; } int num4 = checked((int)Math.Round((double)height / unchecked((double)this.GetFontSizeLength() * 1.1))); this._curPercent = (num2 - num3) / (float)num4; this._curPercent = (num3 + this._curPercent) / num3; this._curPercent -= 1f; checked { int num5 = (int)Math.Round((double)unchecked(this.GetFontSizeLength() + 4f)); int arg_11A_0 = 0; int num6 = this.mDivisors.Count - 1; int num7 = arg_11A_0; float num9; bool flag2; while (true) { int arg_1BD_0 = num7; int num8 = num6; if (arg_1BD_0 > num8) { goto IL_1C2; } num9 = this.mDivisors[num7]; unchecked { float aVal = num2 * (1f / (1f + num9)); flag = ValScale.Inverse; if (flag) { flag2 = (Math.Abs(0f - ValScale.PercentFromValueDisplay(aVal)) * height >= (float)num5); if (flag2) { break; } } else { flag2 = (Math.Abs(1f - ValScale.PercentFromValueDisplay(aVal)) * height >= (float)num5); if (flag2) { goto Block_12; } } } num7++; } this._curPercent = num9; goto IL_1C2; Block_12: this._curPercent = num9; IL_1C2: flag2 = (this._curPercent < 0f); if (flag2) { result = list; return result; } flag2 = ValScale.Inverse; if (flag2) { num2 = num3; } float num10; do { num10 = ValScale.PercentFromValueDisplay(num2); flag2 = (num10 <= 1f & num10 >= 0f); if (flag2) { ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = num10; valueScaleDisplay_.SetText(num2, this); list.Add(valueScaleDisplay_); } flag2 = ValScale.Inverse; unchecked { if (flag2) { num2 *= 1f + this._curPercent; } else { num2 /= 1f + this._curPercent; } } num++; } while (num10 >= 0f && num < 1000); } } catch (Exception expr_2CA) { ProjectData.SetProjectError(expr_2CA); ProjectData.ClearProjectError(); } result = list; return result; } private List GetDivisorValues(float height, IValueScaler ValScale) { var list = new List(); List result; try { int num = 0; float num2 = ValScale.ValueFromPercentDisplay(1f); bool flag = ValScale.Inverse; if (flag) { num2 = ValScale.ValueFromPercentDisplay(0f); } flag = (float.IsInfinity(num2) || float.IsNaN(num2)); if (flag) { result = list; return result; } flag = (this._divisor == 0f); if (flag) { result = list; return result; } num2 = (float)checked((int)Math.Round((double)(num2 / this._divisor))); num2 += 1f; num2 *= this._divisor; while (true) { float num3 = ValScale.PercentFromValueDisplay(num2); flag = (num3 <= 1f & num3 >= 0f); if (flag) { ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = num3; valueScaleDisplay_.SetText(num2, this); list.Add(valueScaleDisplay_); } num2 -= this._divisor; checked { num++; if (!ValScale.Inverse && num3 >= 0f) { goto IL_129; } if (ValScale.Inverse && num3 <= 100f) { goto IL_129; } goto IL_131; IL_135: bool arg_135_0; if (!arg_135_0) { break; } continue; IL_131: arg_135_0 = false; goto IL_135; IL_129: if (num >= 1000) { goto IL_131; } arg_135_0 = true; goto IL_135; } } this._curNet = this._divisor; } catch (Exception expr_180) { ProjectData.SetProjectError(expr_180); ProjectData.ClearProjectError(); } result = list; return result; } private List GetFixedPercentValues(float height, IValueScaler ValScale) { List list = new List(); try { int num = 0; float num2 = ValScale.ValueFromPercentDisplay(1f); bool flag = ValScale.Inverse; if (flag) { num2 = ValScale.ValueFromPercentDisplay(0f); } this._curPercent = this._fixedPercent / 100f; while (true) { float num3 = ValScale.PercentFromValueDisplay(num2); flag = (num3 <= 1f & num3 >= 0f); if (flag) { ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = num3; valueScaleDisplay_.SetText(num2, this); list.Add(valueScaleDisplay_); } num2 /= 1f + this._fixedPercent / 100f; checked { num++; if (!ValScale.Inverse && num3 >= 0f) { goto IL_E1; } if (ValScale.Inverse && num3 <= 100f) { goto IL_E1; } goto IL_E9; IL_ED: bool arg_ED_0; if (!arg_ED_0) { break; } continue; IL_E9: arg_ED_0 = false; goto IL_ED; IL_E1: if (num >= 1000) { goto IL_E9; } arg_ED_0 = true; goto IL_ED; } } } catch (Exception expr_12C) { ProjectData.SetProjectError(expr_12C); ProjectData.ClearProjectError(); } return list; } private float GetFontSizeLength() { return (float)((double)this.FontSize() * 1.1); } private List GetLineCountValues(float height, IValueScaler ValScale) { List list = new List(); try { int num; checked { num = this.LineCount - 1; int arg_EB_0 = 0; int num2 = num; int num3 = arg_EB_0; while (true) { int arg_6E_0 = num3; int num4 = num2; if (arg_6E_0 > num4) { break; } ValueScaleDisplay.ValueScaleDisplay_Y valueScaleDisplay_ = new ValueScaleDisplay.ValueScaleDisplay_Y(); valueScaleDisplay_.Value = (float)((double)num3 / (double)num); valueScaleDisplay_.SetText(ValScale.ValueFromPercentDisplay(valueScaleDisplay_.Value), this); list.Add(valueScaleDisplay_); num3++; } } this._curNet = ValScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - ValScale.ValueFromPercentDisplay(0f); this._curPercent = (ValScale.ValueFromPercentDisplay((float)(1.0 / (double)num)) - ValScale.ValueFromPercentDisplay(0f)) / ValScale.ValueFromPercentDisplay(0f); } catch (Exception expr_FB) { ProjectData.SetProjectError(expr_FB); ProjectData.ClearProjectError(); } return list; } private void InitializeDivisors() { this.mDivisors.Add(1E-05f); this.mDivisors.Add(5E-05f); this.mDivisors.Add(0.0001f); this.mDivisors.Add(0.0005f); this.mDivisors.Add(0.001f); this.mDivisors.Add(0.005f); this.mDivisors.Add(0.01f); this.mDivisors.Add(0.02f); this.mDivisors.Add(0.03f); this.mDivisors.Add(0.04f); this.mDivisors.Add(0.05f); this.mDivisors.Add(0.1f); this.mDivisors.Add(0.25f); this.mDivisors.Add(0.3f); this.mDivisors.Add(0.4f); this.mDivisors.Add(0.5f); this.mDivisors.Add(0.6f); this.mDivisors.Add(0.7f); this.mDivisors.Add(0.8f); this.mDivisors.Add(0.9f); this.mDivisors.Add(1f); this.mDivisors.Add(1.5f); this.mDivisors.Add(2f); this.mDivisors.Add(2.5f); this.mDivisors.Add(3f); this.mDivisors.Add(4f); this.mDivisors.Add(5f); this.mDivisors.Add(6f); this.mDivisors.Add(7f); this.mDivisors.Add(8f); this.mDivisors.Add(9f); this.mDivisors.Add(10f); this.mDivisors.Add(20f); this.mDivisors.Add(25f); this.mDivisors.Add(50f); this.mDivisors.Add(100f); this.mDivisors.Add(250f); this.mDivisors.Add(500f); this.mDivisors.Add(1000f); this.mDivisors.Add(2500f); this.mDivisors.Add(5000f); this.mDivisors.Add(10000f); this.mDivisors.Add(25000f); this.mDivisors.Add(50000f); this.mDivisors.Add(100000f); this.mDivisors.Add(250000f); this.mDivisors.Add(500000f); this.mDivisors.Add(1000000f); this.mDivisors.Add(2500000f); this.mDivisors.Add(5000000f); this.mDivisors.Add(1E+07f); this.mDivisors.Add(2.5E+07f); this.mDivisors.Add(5E+07f); this.mDivisors.Add(1E+08f); this.mDivisors.Add(2.5E+08f); this.mDivisors.Add(5E+08f); this.mDivisors.Add(1E+09f); this.mDivisors.Add(2.5E+09f); this.mDivisors.Add(5E+09f); this.mDivisors.Add(1E+10f); this.mDivisors.Add(2.5E+10f); this.mDivisors.Add(5E+10f); this.mDivisors.Add(1E+11f); this.mDivisors.Add(2.5E+11f); this.mDivisors.Add(5E+11f); this.mDivisors.Add(1E+12f); this.mDivisors.Add(2.5E+12f); this.mDivisors.Add(5E+12f); this.mDivisors.Add(1E+13f); this.mDivisors.Add(2.5E+13f); this.mDivisors.Add(5E+13f); } private bool IsPChangeFromBeginning() { var valueScaler = this.CurrentValueScaler; if (valueScaler == null) return false; return (valueScaler is ValueScalerArithmetic && ((ValueScalerArithmetic)valueScaler).IsPChangeFromBeginning() && ((ValueScalerArithmetic)valueScaler).ShowScaleAsPercent); } private void RefreshChart() { if (this._chart == null) return; this._chart.Refresh(); } /// /// Shows the percent scale. /// /// true if XXXX, false otherwise private bool ShowPercentScale() { var scale = CurrentValueScaler as ValueScalerArithmetic; if (scale == null) return false; return scale.ShowScaleAsPercent; } /// /// Updates the Y list. /// /// The ylist. /// List{ValueScaleDisplay.ValueScaleDisplay_Y}. private List UpdateYList(List ylist) { //更新y轴数据,只针对左边显示数据,右边显示百分比。 try { if (!this.CurrentValueScaler.ShowScaleAsPercent) return ylist; var result = new List(); var baseline = CurrentValueScaler.GetPercentBaseline(); foreach (var y in ylist) { var val = float.Parse(y.Text); result.Add(new ValueScaleDisplay_Y() { Text = ConvertToString(((val - baseline) / baseline) * 100), Value = y.Value }); } return result; } catch { return ylist; } } private void ValueScaleDisplay_SizeChanged(object sender, SizeChangedEventArgs e) { this._yCanvas.Width = (this.ActualWidth); this._yCanvas.Height = (this.ActualHeight); } #endregion Private Methods #endregion Methods #region Nested Types /// /// 存储Y轴坐标值 /// internal class ValueScaleDisplay_Y { #region Constructors public ValueScaleDisplay_Y() { } #endregion Constructors #region Properties #region Public Properties /// /// 处理后的Y轴数值文本 /// public string Text { get; set; } /// /// Y轴坐标值 /// public float Value { get; set; } #endregion Public Properties #endregion Properties #region Methods #region Internal Methods internal void SetText(float aVal, ValueScaleDisplay aValScaleDisp) { this.Text = aValScaleDisp.ConvertToString(aVal); } #endregion Internal Methods #endregion Methods } #endregion Nested Types } }