using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data.Interfaces; using MuchInfo.Chart.Data.Models; using MuchInfo.Chart.Infrastructure.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows; using System.Xml.Linq; namespace MuchInfo.Chart.WPF.Primitives { public class ValueScalerArithmetic : IValueScaler { #region Fields private const float c_HightPrecent = 0.2f; //显示分时图最大的百分比 private Dictionary _dictionary; private float _diffInverse; private bool _flag; private float _high; private bool _inverse; private float _logDiffInverse; private float _logMax; private float _logMin; private float _low; private float _max; private float _maxValue; private float _min; private float _minValue; private float _percentBaseline; private bool _percentScale; private ValueScalerArithmetic.enumScaleMethod _scaleMode; private ValueScalerArithmetic.enumScaleMethod _scaleMode2; #endregion Fields #region Constructors public ValueScalerArithmetic(bool showPercentScale) { _high = 0f; _low = 0f; _maxValue = 0f; _minValue = 0f; _flag = false; _inverse = false; _dictionary = new Dictionary(); _scaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic; _scaleMode2 = ValueScalerArithmetic.enumScaleMethod.eArithmetic; //右边显示百分比 _percentScale = showPercentScale;//true; } #endregion Constructors #region Enumerations public enum enumCenteredHeight { eAuto, eManual } public enum enumCenteredValueMode { eMedian, eManual } public enum enumMaxMinValueMode { eMaxMin, eManual } public enum enumScaleBounding { eMaxMin, eCentered } public enum enumScaleMethod { eArithmetic, eLog, ePChangeFromBeginning, } public enum enumScaleMode { AutoScale, Manual, CenteredAuto, CenteredManual, AutoMinimum, AutoMaximum } #endregion Enumerations #region Events public event ScalePropertiesChangedEventHandler ScalePropertiesChanged; #endregion Events #region Properties #region Public Properties /// /// Gets or sets the bounding method. /// public ValueScalerArithmetic.enumScaleBounding BoundingMethod { get { string property = GetProperty(GetScaleModeString() + "BoundMethod"); bool flag = property == null; ValueScalerArithmetic.enumScaleBounding result; if (flag) { result = ValueScalerArithmetic.enumScaleBounding.eMaxMin; } else { ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property); result = enumScaleBounding; } return result; } set { string arg_5E_1 = GetScaleModeString() + "BoundMethod"; int num = (int)value; SetProperty(arg_5E_1, num.ToString()); OnScalePropertiesChanged(); } } /// /// Gets or sets the center mode. /// public ValueScalerArithmetic.enumCenteredValueMode CenterMode { get { string property = GetProperty(GetScaleModeString() + "CenterMode"); bool flag = property == null; ValueScalerArithmetic.enumCenteredValueMode result; if (flag) { result = ValueScalerArithmetic.enumCenteredValueMode.eMedian; } else { ValueScalerArithmetic.enumCenteredValueMode enumCenteredValueMode = (ValueScalerArithmetic.enumCenteredValueMode)Conversions.ToInteger(property); result = enumCenteredValueMode; } return result; } set { string arg_5E_1 = GetScaleModeString() + "CenterMode"; int num = (int)value; SetProperty(arg_5E_1, num.ToString()); OnScalePropertiesChanged(); } } /// /// Gets or sets the height mode. /// public ValueScalerArithmetic.enumCenteredHeight HeightMode { get { string property = GetProperty(GetScaleModeString() + "HeightMode"); bool flag = property == null; ValueScalerArithmetic.enumCenteredHeight result; if (flag) { result = ValueScalerArithmetic.enumCenteredHeight.eAuto; } else { ValueScalerArithmetic.enumCenteredHeight enumCenteredHeight = (ValueScalerArithmetic.enumCenteredHeight)Conversions.ToInteger(property); result = enumCenteredHeight; } return result; } set { string arg_5E_1 = GetScaleModeString() + "HeightMode"; int num = (int)value; SetProperty(arg_5E_1, num.ToString()); OnScalePropertiesChanged(); } } /// /// Gets or sets a value indicating whether this is inverse. /// public bool Inverse { get { return _inverse; } set { _inverse = value; OnScalePropertiesChanged(); } } /// /// Gets or sets the manual center. /// public float ManualCenter { get { string property = GetProperty(GetScaleModeString() + "ManualCenter"); bool flag = property == null; float result; if (flag) { result = 50f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { SetProperty(GetScaleModeString() + "ManualCenter", value.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the height of the manual. /// public float ManualHeight { get { string property = GetProperty(GetScaleModeString() + "ManualHeight"); bool flag = property == null; float result; if (flag) { result = 50f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { SetProperty(GetScaleModeString() + "ManualHeight", value.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the manual max. /// public float ManualMax { get { string property = GetProperty(GetScaleModeString() + "ManualMax"); bool flag = property == null; float result; if (flag) { result = 100f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { SetProperty(GetScaleModeString() + "ManualMax", value.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the manual min. /// public float ManualMin { get { string property = GetProperty(GetScaleModeString() + "ManualMin"); bool flag = property == null; float result; if (flag) { result = 0f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { SetProperty(GetScaleModeString() + "ManualMin", value.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the max add percent. /// public float MaxAddPercent { get { string property = GetProperty("eArithmeticMaxAddPercent"); bool flag = property == null; float result; if (flag) { result = 2f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { float num = value; bool flag = num + MinAddPercent > 97f; if (flag) { num = 97f - MinAddPercent; } else { flag = (num < 0f); if (flag) { num = 0f; } } SetProperty("eArithmeticMaxAddPercent", num.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the max mode. /// public ValueScalerArithmetic.enumMaxMinValueMode MaxMode { get { string property = GetProperty(GetScaleModeString() + "MaxMode"); bool flag = property == null; ValueScalerArithmetic.enumMaxMinValueMode result; if (flag) { result = ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin; } else { ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property); flag = (enumScaleBounding == (ValueScalerArithmetic.enumScaleBounding)2); if (flag) { enumScaleBounding = ValueScalerArithmetic.enumScaleBounding.eMaxMin; } result = (ValueScalerArithmetic.enumMaxMinValueMode)enumScaleBounding; } return result; } set { string arg_5E_1 = GetScaleModeString() + "MaxMode"; int num = (int)value; SetProperty(arg_5E_1, num.ToString()); OnScalePropertiesChanged(); } } /// /// Gets or sets the min add percent. /// public float MinAddPercent { get { string property = GetProperty("eArithmeticMinAddPercent"); bool flag = property == null; float result; if (flag) { result = 2f; } else { result = ConvertHelper.ParseSingle(property); } return result; } set { float num = value; if (num + MaxAddPercent > 97f) { num = 97f - MaxAddPercent; } else { if (num < 0f) { num = 0f; } } SetProperty("eArithmeticMinAddPercent", num.ToString(CultureInfo.InvariantCulture.NumberFormat)); OnScalePropertiesChanged(); } } /// /// Gets or sets the min mode. /// public ValueScalerArithmetic.enumMaxMinValueMode MinMode { get { string property = GetProperty(GetScaleModeString() + "MinMode"); bool flag = property == null; ValueScalerArithmetic.enumMaxMinValueMode result; if (flag) { result = ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin; } else { ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property); flag = (enumScaleBounding == (ValueScalerArithmetic.enumScaleBounding)2); if (flag) { enumScaleBounding = ValueScalerArithmetic.enumScaleBounding.eMaxMin; } result = (ValueScalerArithmetic.enumMaxMinValueMode)enumScaleBounding; } return result; } set { string arg_5E_1 = GetScaleModeString() + "MinMode"; int num = (int)value; SetProperty(arg_5E_1, num.ToString()); OnScalePropertiesChanged(); } } /// /// Gets or sets the scale mode. /// public ValueScalerArithmetic.enumScaleMethod ScaleMode { get { return _scaleMode; } set { bool flag = _scaleMode != value; if (flag) { _scaleMode = value; OnScalePropertiesChanged(); } } } /// /// Gets or sets a value indicating whether [show scale as percent]. /// public bool ShowScaleAsPercent { get { return _percentScale; } set { bool flag = _percentScale != value; if (flag) { _percentScale = value; // OnScalePropertiesChanged(); //只有更新图表时刷新时使用,可以不重新刷新 } } } #endregion Public Properties #endregion Properties #region Methods #region Public Methods /// /// Calculates the scale. /// /// The plots. /// The scaler. public void CalculateScale(List plots, IDateScaler scaler, bool isTimeSpaning) { _flag = false; _high = 0f; _low = 0f; _maxValue = 0f; _minValue = 0f; bool flag = HasPriceHistory(plots, scaler, isTimeSpaning); if (flag) { _scaleMode2 = ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning; } else { _scaleMode2 = _scaleMode; } bool flag2 = ScaleOnlyPrice(plots); try { List.Enumerator enumerator = plots.GetEnumerator(); while (enumerator.MoveNext()) { PlotBase current = enumerator.Current; flag = (current is ComparisonPlot); if (flag) { var dat = ((LinePlot)current).GetDataSet(); flag = ((ComparisonPlot)current).IsActive; if (flag) { UpdateMaxAndMin(dat, scaler); } } else { flag = (current.Indicator != null && current.Indicator.ParentFormula.IsMain && isTimeSpaning); if (flag) { var dat = ((LinePlot)current).GetDataSet(); UpdateHighAndLow(dat, scaler, true); } else { var dat = ((LinePlot)current).GetDataSet(); UpdateHighAndLow(dat, scaler, false); } } } } finally { //List.Enumerator enumerator; //enumerator.Dispose(); } flag = (_high == _low); if (flag) { _high = (float)((double)_high + 0.1); flag = ((double)_low - 0.1 > 1.0); if (flag) { _low = (float)((double)_low - 0.1); } } try { switch (_scaleMode2) { case ValueScalerArithmetic.enumScaleMethod.eArithmetic: //if (cycleType == CycleType.TimeSharing) //{ // var maxAbs = Math.Max(Math.Abs(_high - _percentBaseline), Math.Abs(_low - _percentBaseline)); // _high = maxAbs + _percentBaseline; // _low = _percentBaseline - maxAbs; //} SetMinMaxArithmetic(); break; case ValueScalerArithmetic.enumScaleMethod.eLog: SetMinMaxLog(); break; case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning: if (isTimeSpaning) { var maxAbs = Math.Max(Math.Abs(_high - _percentBaseline), Math.Abs(_low - _percentBaseline)); _high =(maxAbs *1.1f)/ _percentBaseline; // c_HightPrecent; //上限加10% _low = -_high; //SetMinMaxComparison(); SetMinMaxTimeSpaning(); } else { _high = (_high - _percentBaseline) / _percentBaseline; _low = (_low - _percentBaseline) / _percentBaseline; _high = Math.Max(_high, _maxValue); _low = Math.Min(_low, _minValue); SetMinMaxComparison(); } break; } } catch (Exception expr_347) { ProjectData.SetProjectError(expr_347); ProjectData.ClearProjectError(); } } /// /// Froms the XML. /// /// The node. public void FromXML(XElement node) { bool flag = node.Attribute("Inverse") != null; if (flag) { _inverse = bool.Parse(node.Attribute("Inverse").Value); } flag = (node.Attribute("ComparisonScaleAsPercent") != null); if (flag) { _percentScale = bool.Parse(node.Attribute("ComparisonScaleAsPercent").Value); } flag = (node.Attribute("ScaleMode") != null); if (flag) { string value = node.Attribute("ScaleMode").Value; string text = value.ToLower(); flag = (Operators.CompareString(text, "earithmetic", false) == 0); if (flag) { _scaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic; } else { flag = (Operators.CompareString(text, "elog", false) == 0); if (flag) { _scaleMode = ValueScalerArithmetic.enumScaleMethod.eLog; } } } _dictionary.Clear(); try { IEnumerator enumerator = node.Elements().GetEnumerator(); while (enumerator.MoveNext()) { XElement current = enumerator.Current; flag = (current.Name == "Arg"); if (flag) { bool flag2 = current.Attribute("Name") != null && current.Attribute("Val") != null; if (flag2) { _dictionary[current.Attribute("Name").Value] = current.Attribute("Val").Value; } } } } finally { //IEnumerator enumerator; //bool flag2 = enumerator != null; //if (flag2) //{ // enumerator.Dispose(); //} } } /// /// Gets the max value. /// /// System.Single. public float GetMaxValue() { if (_scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning) { var value = (_max + 1) * _percentBaseline; return value; } return _max; } /// /// Gets the min value. /// /// System.Single. public float GetMinValue() { if (_scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning) { var value = (_min + 1) * _percentBaseline; return value; } return _min; } /// /// Gets the percent baseline. /// /// System.Single. public float GetPercentBaseline() { return _percentBaseline; } /// /// Percents from value. /// /// A val. /// System.Single. public float PercentFromValue(float aVal) { float result = 0f; switch (_scaleMode2) { case ValueScalerArithmetic.enumScaleMethod.eArithmetic: result = PercentFromValueArithmetic(aVal); break; case ValueScalerArithmetic.enumScaleMethod.eLog: result = PercentFromValueLog(aVal); break; case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning: result = PercentFromValueComparison(aVal); break; } return result; } /// /// Percents from value arithmetic. /// /// A value. /// System.Single. public float PercentFromValueArithmetic(float aValue) { bool flag = float.IsInfinity(aValue) || float.IsNaN(aValue); float result = 0f; if (flag) { result = 0f; } else { flag = (_min != _max); if (flag) { bool flag2 = _inverse; float num; if (flag2) { num = 1f - (aValue - _min) * _diffInverse; } else { num = (aValue - _min) * _diffInverse; } flag2 = (num > 500000f); if (flag2) { num = 500000f; } else { flag2 = (num < -500000f); if (flag2) { num = -500000f; } } result = num; } } return result; } /// /// Percents from value comparison. /// /// The in value. /// System.Single. public float PercentFromValueComparison(float inValue) { float num = (inValue - _percentBaseline) / _percentBaseline; bool flag = float.IsInfinity(num) || float.IsNaN(num); float result = 0f; if (flag) { result = 0f; } else { flag = (_min != _max); if (flag) { bool flag2 = _inverse; float num2; if (flag2) { num2 = 1f - (num - _min) * _diffInverse; } else { num2 = (num - _min) * _diffInverse; } flag2 = (num2 > 500000f); if (flag2) { num2 = 500000f; } else { flag2 = (num2 < -500000f); if (flag2) { num2 = -500000f; } } result = num2; } } return result; } /// /// Percents from value display. /// /// A val. /// System.Single. public float PercentFromValueDisplay(float aVal) { bool flag = _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning && _percentScale; float result; if (flag) { result = PercentFromValueArithmetic(aVal / 100f); } else { result = PercentFromValue(aVal); } return result; } /// /// Percents from value log. /// /// A value. /// System.Single. public float PercentFromValueLog(float aValue) { bool flag = aValue <= 0f; float result = 0f; if (flag) { result = -500000f; } else { float num = (float)Math.Log10((double)aValue); flag = (_logMin != _logMax); if (flag) { bool flag2 = _inverse; float num2; if (flag2) { num2 = 1f - (num - _logMin) * _logDiffInverse; } else { num2 = (num - _logMin) * _logDiffInverse; } flag2 = (num2 > 500000f); if (flag2) { num2 = 500000f; } else { flag2 = (num2 < -500000f); if (flag2) { num2 = -500000f; } } result = num2; } } return result; } /// /// Roots the name. /// /// System.String. public string RootName() { return "VALSCALER"; } /// /// Scaleds the Y. /// /// A val. /// A rect. /// System.Single. public float ScaledY(float aVal, Rect aRect) { bool flag = _high.Equals(_low); float result; if (flag) { result = (float)aRect.Bottom; } else { float num = (float)(aRect.Height - 1.0); flag = (num <= 0f); if (flag) { num = 1E-05f; } result = (float)checked((int)Math.Round(unchecked(aRect.Top + (double)((1f - PercentFromValue(aVal)) * num)))); } return result; } public float Spread() { return _high - _low; } /// /// To the XML. /// /// The args. /// XElement. public XElement ToXML(List args) { XElement xElement = new XElement(RootName()); xElement.Add(new XAttribute("Inverse", _inverse.ToString())); xElement.Add(new XAttribute("ScaleMode", _scaleMode.ToString())); xElement.Add(new XAttribute("ComparisonScaleAsPercent", _percentScale.ToString())); try { Dictionary.KeyCollection.Enumerator enumerator = _dictionary.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string current = enumerator.Current; XElement xElement2 = new XElement("Arg"); xElement2.Add(new XAttribute("Name", current)); xElement2.Add(new XAttribute("Val", _dictionary[current])); xElement.Add(xElement2); } } finally { //Dictionary.KeyCollection.Enumerator enumerator; //enumerator.Dispose(); } return xElement; } /// /// Values from percent. /// /// A percent. /// System.Single. public float ValueFromPercent(float aPercent) { float result = 0f; switch (_scaleMode2) { case ValueScalerArithmetic.enumScaleMethod.eArithmetic: result = ValueFromPercentArithmetic(aPercent); break; case ValueScalerArithmetic.enumScaleMethod.eLog: result = ValueFromPercentLog(aPercent); break; case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning: result = ValueFromPercentComparison(aPercent); break; } return result; } /// /// Values from percent arithmetic. /// /// A percent. /// System.Single. public float ValueFromPercentArithmetic(float aPercent) { bool flag = aPercent == 0f; float result = 0f; if (flag) { bool flag2 = _inverse; if (flag2) { result = _max; } else { result = _min; } } else { bool flag2 = _inverse; if (flag2) { result = (_max - _min) * (1f - aPercent) + _min; } else { result = (_max - _min) * aPercent + _min; } } return result; } /// /// Values from percent comparison. /// /// A percent. /// System.Single. public float ValueFromPercentComparison(float aPercent) { bool flag = aPercent == 0f; float num; if (flag) { bool flag2 = _inverse; if (flag2) { num = _max; } else { num = _min; } } else { bool flag2 = _inverse; if (flag2) { num = (_max - _min) * (1f - aPercent) + _min; } else { num = (_max - _min) * aPercent + _min; } } return _percentBaseline + _percentBaseline * num; } /// /// 分时图中的刻度线 /// /// 百分比 /// public float ValueFromTimeSpaningPercent(float aPercent) { return _percentBaseline + _percentBaseline * aPercent; } /// /// Values from percent display. /// /// A percent. /// System.Single. public float ValueFromPercentDisplay(float aPercent) { bool flag = _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning && _percentScale; float result; if (flag) { result = ValueFromPercentArithmetic(aPercent) * 100f; } else { result = ValueFromPercent(aPercent); } return result; } /// /// Values from percent log. /// /// A percent. /// System.Single. public float ValueFromPercentLog(float aPercent) { float result = 0f; try { bool flag = _inverse; if (flag) { result = (float)Math.Pow(10.0, (double)((_logMax - _logMin) * (1f - aPercent) + _logMin)); } else { result = (float)Math.Pow(10.0, (double)((_logMax - _logMin) * aPercent + _logMin)); } } catch (Exception expr_8E) { ProjectData.SetProjectError(expr_8E); ProjectData.ClearProjectError(); } return result; } /// /// Values from Y. /// /// A Y. /// A rect. /// System.Single. public float ValueFromY(float aY, Rect aRect) { float aPercent = (float)(((double)aY - aRect.Bottom) / (aRect.Top - aRect.Bottom)); return ValueFromPercent(aPercent); } /// /// Ys from percent. /// /// A percent. /// A rect. /// System.Single. public float YFromPercent(float aPercent, Rect aRect) { float num = (float)(aRect.Height - 1.0); bool flag = num <= 0f; if (flag) { num = 1E-05f; } return (float)checked((int)Math.Round(unchecked(aRect.Top + (double)((1f - aPercent) * num)))); } #endregion Public Methods #region Internal Methods /// /// Determines whether [is P change from beginning]. /// /// true if [is P change from beginning]; otherwise, false. internal bool IsPChangeFromBeginning() { return _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning; } #endregion Internal Methods #region Protected Methods /// /// Gets the property. /// /// A name. /// System.String. protected string GetProperty(string aName) { string result = null; bool flag = _dictionary.ContainsKey(aName); if (flag) { result = _dictionary[aName]; } return result; } /// /// Sets the min max arithmetic. /// protected void SetMinMaxArithmetic() { bool flag; switch (BoundingMethod) { case enumScaleBounding.eMaxMin: switch (MaxMode) { case enumMaxMinValueMode.eMaxMin: _max = _high; break; case enumMaxMinValueMode.eManual: _max = ManualMax; break; } switch (MinMode) { case enumMaxMinValueMode.eMaxMin: _min = _low; break; case enumMaxMinValueMode.eManual: _min = ManualMin; break; } flag = (MaxAddPercent > 0f || MinAddPercent > 0f); if (flag) { double num = (double)(MaxAddPercent / 100f); double num2 = (double)(MinAddPercent / 100f); double num3 = 1.0 - (num + num2); double num4 = (double)(_max - _min); flag = (num3 > 0.0); if (flag) { _max = (float)((double)_max + num4 * (num / num3)); _min = (float)((double)_min - num4 * (num2 / num3)); } } break; case enumScaleBounding.eCentered: { _max = _high; _min = _low; float num5 = ManualCenter; flag = (CenterMode == enumCenteredValueMode.eMedian); if (flag) { num5 = _max / 2f + _min / 2f; } switch (HeightMode) { case enumCenteredHeight.eAuto: { float num6 = Math.Max(Math.Abs(_max - num5), Math.Abs(num5 - _min)); _max = num5 + num6; _min = num5 - num6; break; } case enumCenteredHeight.eManual: _max = num5 + ManualHeight / 2f; _min = num5 - ManualHeight / 2f; break; } break; } } bool arg_24E_0; if (!float.IsNaN(_min) && !float.IsInfinity(_min)) { if (!float.IsNaN(_min)) { if (!float.IsInfinity(_min)) { arg_24E_0 = false; goto IL_24E; } } } //IL_24D: arg_24E_0 = true; //goto IL_24E; //goto IL_24D; IL_24E: flag = arg_24E_0; if (flag) { _min = 0f; _max = 0f; } flag = (_max != _min); if (flag) { _diffInverse = 1f / (_max - _min); } else { _diffInverse = 0f; } } /// /// Sets the min max comparison. /// protected void SetMinMaxComparison() { _max = _high; _min = _low; bool flag = MaxAddPercent > 0f || MinAddPercent > 0f; if (flag) { double num = (double)(MaxAddPercent / 100f); double num2 = (double)(MinAddPercent / 100f); double num3 = 1.0 - (num + num2); double num4 = (double)(_max - _min); flag = (num3 > 0.0); if (flag) { _max = (float)((double)_max + num4 * (num / num3)); _min = (float)((double)_min - num4 * (num2 / num3)); } } float num5 = _max - _min; _max += num5 * 3f / 100f; _min -= num5 * 3f / 100f; bool arg_14F_0; if (!float.IsNaN(_min) && !float.IsInfinity(_min)) { if (!float.IsNaN(_min)) { if (!float.IsInfinity(_min)) { arg_14F_0 = false; goto IL_14F; } } } arg_14F_0 = true; IL_14F: flag = arg_14F_0; if (flag) { _min = 0f; _max = 0f; } flag = (_max != _min); if (flag) { _diffInverse = 1f / (_max - _min); } else { _diffInverse = 0f; } } /// /// 设置分时图最大最小值 /// private void SetMinMaxTimeSpaning() { _max = _high; _min = _low; bool flag = MaxAddPercent > 0f || MinAddPercent > 0f; //if (flag) //{ // double num = (double)(MaxAddPercent / 100f); // double num2 = (double)(MinAddPercent / 100f); // double num3 = 1.0 - (num + num2); // double num4 = (double)(_max - _min); // flag = (num3 > 0.0); // if (flag) // { // _max = (float)((double)_max + num4 * (num / num3)); // _min = (float)((double)_min - num4 * (num2 / num3)); // } //} //float num5 = _max - _min; //_max += num5 * 3f / 100f; //_min -= num5 * 3f / 100f; bool arg_14F_0; if (!float.IsNaN(_min) && !float.IsInfinity(_min)) { if (!float.IsNaN(_min)) { if (!float.IsInfinity(_min)) { arg_14F_0 = false; goto IL_14F; } } } arg_14F_0 = true; IL_14F: flag = arg_14F_0; if (flag) { _min = 0f; _max = 0f; } flag = (_max != _min); if (flag) { _diffInverse = 1f / (_max - _min); } else { _diffInverse = 0f; } } /// /// Sets the min max log. /// protected void SetMinMaxLog() { bool flag = _high <= 0f; float num; if (flag) { num = (float)Math.Log10(0.01); } else { num = (float)Math.Log10((double)_high); } flag = (_low <= 0f); float num2; if (flag) { num2 = (float)Math.Log10(0.01); } else { num2 = (float)Math.Log10((double)_low); } switch (BoundingMethod) { case ValueScalerArithmetic.enumScaleBounding.eMaxMin: switch (MaxMode) { case ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin: _max = num; break; case ValueScalerArithmetic.enumMaxMinValueMode.eManual: flag = (ManualMax <= 0f); if (flag) { _max = (float)Math.Log10(0.01); } else { _max = (float)Math.Log10((double)ManualMax); } break; } switch (MinMode) { case ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin: _min = num2; break; case ValueScalerArithmetic.enumMaxMinValueMode.eManual: flag = (ManualMin <= 0f); if (flag) { _min = (float)Math.Log10(0.01); } else { _min = (float)Math.Log10((double)ManualMin); } break; } flag = (MaxAddPercent > 0f || MinAddPercent > 0f); if (flag) { double num3 = (double)(MaxAddPercent / 100f); double num4 = (double)(MinAddPercent / 100f); double num5 = 1.0 - (num3 + num4); double num6 = (double)(_max - _min); flag = (num5 > 0.0); if (flag) { _max = (float)((double)_max + num6 * (num3 / num5)); _min = (float)((double)_min - num6 * (num4 / num5)); } } break; case ValueScalerArithmetic.enumScaleBounding.eCentered: { flag = (ManualCenter <= 0f); float num7; if (flag) { num7 = (float)Math.Log10(0.01); } else { num7 = (float)Math.Log10((double)ManualCenter); } _max = num; _min = num2; flag = (CenterMode == ValueScalerArithmetic.enumCenteredValueMode.eMedian); if (flag) { num7 = _max / 2f + _min / 2f; } switch (HeightMode) { case ValueScalerArithmetic.enumCenteredHeight.eAuto: { float num8 = Math.Max(Math.Abs(_max - num7), Math.Abs(num7 - _min)); _max = num7 + num8; _min = num7 - num8; break; } case ValueScalerArithmetic.enumCenteredHeight.eManual: { flag = (ManualHeight <= 0f); float num9; if (flag) { num9 = (float)Math.Log10(0.01); } else { num9 = (float)Math.Log10((double)ManualHeight); } float num10 = (float)((double)ManualHeight / Math.Pow(10.0, (double)num7)); float num11 = (float)(((double)(-1f * num10) + Math.Sqrt(Math.Pow((double)num10, 2.0) + 4.0)) / 2.0); float num12 = (float)((double)ManualHeight / Math.Pow(10.0, (double)num7)); num9 = (float)(-1.0 * (Math.Log10((double)num12) / 2.0)); num9 = (float)Math.Log10((double)num11); _max = num7 - num9; _min = num7 + num9; break; } } break; } } _logMax = _max; _logMin = _min; flag = (_logMax != _logMin); if (flag) { _logDiffInverse = 1f / (_logMax - _logMin); } else { _logDiffInverse = 0f; } } /// /// Sets the property. /// /// A name. /// The new val. protected void SetProperty(string aName, string newVal) { _dictionary[aName] = newVal; } #endregion Protected Methods #region Private Methods /// /// Gets the scale mode string. /// /// System.String. private string GetScaleModeString() { return _scaleMode.ToString(); } /// /// Determines whether [has price history] [the specified plots]. /// /// The plots. /// The scaler. /// if set to true [is time spaning]. /// true if [has price history] [the specified plots]; otherwise, false. private bool HasPriceHistory(List plots, IDateScaler scaler, bool isTimeSpaning) { if (plots == null || !plots.Any()) return false; foreach (var plot in plots) { if (plot == null || plot.Indicator == null || plot.Indicator.ParentFormula == null) continue; bool flag = plot.Indicator.ParentFormula.IsMain || isTimeSpaning; if (flag) { UpdatePercentBaseline((LinePlot)plot, scaler); return true; } } return false; } /// /// Called when [scale properties changed]. /// private void OnScalePropertiesChanged() { if (ScalePropertiesChanged != null) { ScalePropertiesChanged(); } } /// /// Scales the only price. /// /// The plots. /// true if XXXX, false otherwise private bool ScaleOnlyPrice(List plots) { if (plots == null || !plots.Any()) return false; return true; //return (from current in plots // let flag = current.Calculation() is PriceHistoryCalculation // where flag // select ((PriceHistoryCalculation)current.Calculation()).ScaleOnlyPrice).Any(scaleOnlyPrice => scaleOnlyPrice); } /// /// Updates the high and low. /// /// The dat. /// The scaler. /// if set to true [allow OHLC]. private void UpdateHighAndLow(IndicatorModel dat, IDateScaler scaler, bool allowOhlc) { if (dat == null || dat.CalculateDataPoints == null || !dat.CalculateDataPoints.Any()) return; foreach (var current in dat.CalculateDataPoints) { var visible = scaler.DateVisible(current.Date); if (!visible) continue; if (allowOhlc && (current is IOHLCDataPoint)) { var iohlcDataPoint = (IOHLCDataPoint)current; if (_flag) { if (!float.IsNaN(iohlcDataPoint.High)) _high = Math.Max(_high, iohlcDataPoint.High); if (!float.IsNaN(iohlcDataPoint.Low)) _low = Math.Min(_low, iohlcDataPoint.Low); } else { _low = iohlcDataPoint.Low; _high = iohlcDataPoint.High; _flag = true; } } else { float value = current.Value; if (float.IsNaN(value)) continue; if (_flag) { _high = Math.Max(_high, value); _low = Math.Min(_low, value); } else { _low = value; _high = value; _flag = true; } } } } /// /// Updates the max and min. /// /// The dat. /// The scaler. private void UpdateMaxAndMin(IndicatorModel dat, IDateScaler scaler) { bool flag = false; float num = 0f; bool flag2 = dat != null && dat.CalculateDataPoints != null; checked { if (flag2) { var list = dat.CalculateDataPoints; int num2 = list.Count - 1; int num3 = 0; while (true) { int num4 = num2; if (num3 > num4) { break; } flag2 = scaler.DateVisible(list[num3].Date); if (flag2) { bool flag3 = !flag; if (flag3) { num = list[num3].Value; flag = true; } float num5 = unchecked(list[num3].Value - num) / num; _maxValue = Math.Max(_maxValue, num5); _minValue = Math.Min(_minValue, num5); } num3++; } } } } /// /// Updates the percent baseline. /// /// A plot. /// The scaler. private void UpdatePercentBaseline(LinePlot aPlot, IDateScaler scaler) { if (IsTimeSpaning) { _percentBaseline = TimeSpaningLast; } else { _percentBaseline = 0f; var lineDataSet = aPlot.GetDataSet(); if (lineDataSet == null || lineDataSet.CalculateDataPoints == null || !lineDataSet.CalculateDataPoints.Any()) return; //var firstIndex = scaler.FirstVisibleIndexFromData(lineDataSet.CalculateDataPoints); //var first = lineDataSet.CalculateDataPoints[firstIndex]; //if (first == null) return; //var dataPoint = first as IOHLCDataPoint; //_percentBaseline = dataPoint == null ? first.Value : dataPoint.Close; //使用最后一点做现价线 var endIndex = scaler.LastVisibleIndexFromData(lineDataSet.CalculateDataPoints); var end = lineDataSet.CalculateDataPoints[endIndex]; if (end == null) return; var dataPoint = end as IOHLCDataPoint; _percentBaseline = dataPoint == null ? end.Value : dataPoint.Close; } } #endregion Private Methods #endregion Methods public bool IsTimeSpaning { get; set; } public float TimeSpaningLast { get; set; } } }