ValueScalerArithmetic.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.Interfaces;
  3. using MuchInfo.Chart.Data.Models;
  4. using MuchInfo.Chart.Infrastructure.Helpers;
  5. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Globalization;
  9. using System.Linq;
  10. using System.Windows;
  11. using System.Xml.Linq;
  12. namespace MuchInfo.Chart.WPF.Primitives
  13. {
  14. public class ValueScalerArithmetic : IValueScaler
  15. {
  16. #region Fields
  17. private const float c_HightPrecent = 0.2f; //显示分时图最大的百分比
  18. private Dictionary<string, string> _dictionary;
  19. private float _diffInverse;
  20. private bool _flag;
  21. private float _high;
  22. private bool _inverse;
  23. private float _logDiffInverse;
  24. private float _logMax;
  25. private float _logMin;
  26. private float _low;
  27. private float _max;
  28. private float _maxValue;
  29. private float _min;
  30. private float _minValue;
  31. private float _percentBaseline;
  32. private bool _percentScale;
  33. private ValueScalerArithmetic.enumScaleMethod _scaleMode;
  34. private ValueScalerArithmetic.enumScaleMethod _scaleMode2;
  35. #endregion Fields
  36. #region Constructors
  37. public ValueScalerArithmetic(bool showPercentScale)
  38. {
  39. _high = 0f;
  40. _low = 0f;
  41. _maxValue = 0f;
  42. _minValue = 0f;
  43. _flag = false;
  44. _inverse = false;
  45. _dictionary = new Dictionary<string, string>();
  46. _scaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic;
  47. _scaleMode2 = ValueScalerArithmetic.enumScaleMethod.eArithmetic;
  48. //右边显示百分比
  49. _percentScale = showPercentScale;//true;
  50. }
  51. #endregion Constructors
  52. #region Enumerations
  53. public enum enumCenteredHeight
  54. {
  55. eAuto,
  56. eManual
  57. }
  58. public enum enumCenteredValueMode
  59. {
  60. eMedian,
  61. eManual
  62. }
  63. public enum enumMaxMinValueMode
  64. {
  65. eMaxMin,
  66. eManual
  67. }
  68. public enum enumScaleBounding
  69. {
  70. eMaxMin,
  71. eCentered
  72. }
  73. public enum enumScaleMethod
  74. {
  75. eArithmetic,
  76. eLog,
  77. ePChangeFromBeginning,
  78. }
  79. public enum enumScaleMode
  80. {
  81. AutoScale,
  82. Manual,
  83. CenteredAuto,
  84. CenteredManual,
  85. AutoMinimum,
  86. AutoMaximum
  87. }
  88. #endregion Enumerations
  89. #region Events
  90. public event ScalePropertiesChangedEventHandler ScalePropertiesChanged;
  91. #endregion Events
  92. #region Properties
  93. #region Public Properties
  94. /// <summary>
  95. /// Gets or sets the bounding method.
  96. /// </summary>
  97. public ValueScalerArithmetic.enumScaleBounding BoundingMethod
  98. {
  99. get
  100. {
  101. string property = GetProperty(GetScaleModeString() + "BoundMethod");
  102. bool flag = property == null;
  103. ValueScalerArithmetic.enumScaleBounding result;
  104. if (flag)
  105. {
  106. result = ValueScalerArithmetic.enumScaleBounding.eMaxMin;
  107. }
  108. else
  109. {
  110. ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property);
  111. result = enumScaleBounding;
  112. }
  113. return result;
  114. }
  115. set
  116. {
  117. string arg_5E_1 = GetScaleModeString() + "BoundMethod";
  118. int num = (int)value;
  119. SetProperty(arg_5E_1, num.ToString());
  120. OnScalePropertiesChanged();
  121. }
  122. }
  123. /// <summary>
  124. /// Gets or sets the center mode.
  125. /// </summary>
  126. public ValueScalerArithmetic.enumCenteredValueMode CenterMode
  127. {
  128. get
  129. {
  130. string property = GetProperty(GetScaleModeString() + "CenterMode");
  131. bool flag = property == null;
  132. ValueScalerArithmetic.enumCenteredValueMode result;
  133. if (flag)
  134. {
  135. result = ValueScalerArithmetic.enumCenteredValueMode.eMedian;
  136. }
  137. else
  138. {
  139. ValueScalerArithmetic.enumCenteredValueMode enumCenteredValueMode = (ValueScalerArithmetic.enumCenteredValueMode)Conversions.ToInteger(property);
  140. result = enumCenteredValueMode;
  141. }
  142. return result;
  143. }
  144. set
  145. {
  146. string arg_5E_1 = GetScaleModeString() + "CenterMode";
  147. int num = (int)value;
  148. SetProperty(arg_5E_1, num.ToString());
  149. OnScalePropertiesChanged();
  150. }
  151. }
  152. /// <summary>
  153. /// Gets or sets the height mode.
  154. /// </summary>
  155. public ValueScalerArithmetic.enumCenteredHeight HeightMode
  156. {
  157. get
  158. {
  159. string property = GetProperty(GetScaleModeString() + "HeightMode");
  160. bool flag = property == null;
  161. ValueScalerArithmetic.enumCenteredHeight result;
  162. if (flag)
  163. {
  164. result = ValueScalerArithmetic.enumCenteredHeight.eAuto;
  165. }
  166. else
  167. {
  168. ValueScalerArithmetic.enumCenteredHeight enumCenteredHeight = (ValueScalerArithmetic.enumCenteredHeight)Conversions.ToInteger(property);
  169. result = enumCenteredHeight;
  170. }
  171. return result;
  172. }
  173. set
  174. {
  175. string arg_5E_1 = GetScaleModeString() + "HeightMode";
  176. int num = (int)value;
  177. SetProperty(arg_5E_1, num.ToString());
  178. OnScalePropertiesChanged();
  179. }
  180. }
  181. /// <summary>
  182. /// Gets or sets a value indicating whether this <see cref="ValueScalerArithmetic"/> is inverse.
  183. /// </summary>
  184. public bool Inverse
  185. {
  186. get
  187. {
  188. return _inverse;
  189. }
  190. set
  191. {
  192. _inverse = value;
  193. OnScalePropertiesChanged();
  194. }
  195. }
  196. /// <summary>
  197. /// Gets or sets the manual center.
  198. /// </summary>
  199. public float ManualCenter
  200. {
  201. get
  202. {
  203. string property = GetProperty(GetScaleModeString() + "ManualCenter");
  204. bool flag = property == null;
  205. float result;
  206. if (flag)
  207. {
  208. result = 50f;
  209. }
  210. else
  211. {
  212. result = ConvertHelper.ParseSingle(property);
  213. }
  214. return result;
  215. }
  216. set
  217. {
  218. SetProperty(GetScaleModeString() + "ManualCenter", value.ToString(CultureInfo.InvariantCulture.NumberFormat));
  219. OnScalePropertiesChanged();
  220. }
  221. }
  222. /// <summary>
  223. /// Gets or sets the height of the manual.
  224. /// </summary>
  225. public float ManualHeight
  226. {
  227. get
  228. {
  229. string property = GetProperty(GetScaleModeString() + "ManualHeight");
  230. bool flag = property == null;
  231. float result;
  232. if (flag)
  233. {
  234. result = 50f;
  235. }
  236. else
  237. {
  238. result = ConvertHelper.ParseSingle(property);
  239. }
  240. return result;
  241. }
  242. set
  243. {
  244. SetProperty(GetScaleModeString() + "ManualHeight", value.ToString(CultureInfo.InvariantCulture.NumberFormat));
  245. OnScalePropertiesChanged();
  246. }
  247. }
  248. /// <summary>
  249. /// Gets or sets the manual max.
  250. /// </summary>
  251. public float ManualMax
  252. {
  253. get
  254. {
  255. string property = GetProperty(GetScaleModeString() + "ManualMax");
  256. bool flag = property == null;
  257. float result;
  258. if (flag)
  259. {
  260. result = 100f;
  261. }
  262. else
  263. {
  264. result = ConvertHelper.ParseSingle(property);
  265. }
  266. return result;
  267. }
  268. set
  269. {
  270. SetProperty(GetScaleModeString() + "ManualMax", value.ToString(CultureInfo.InvariantCulture.NumberFormat));
  271. OnScalePropertiesChanged();
  272. }
  273. }
  274. /// <summary>
  275. /// Gets or sets the manual min.
  276. /// </summary>
  277. public float ManualMin
  278. {
  279. get
  280. {
  281. string property = GetProperty(GetScaleModeString() + "ManualMin");
  282. bool flag = property == null;
  283. float result;
  284. if (flag)
  285. {
  286. result = 0f;
  287. }
  288. else
  289. {
  290. result = ConvertHelper.ParseSingle(property);
  291. }
  292. return result;
  293. }
  294. set
  295. {
  296. SetProperty(GetScaleModeString() + "ManualMin", value.ToString(CultureInfo.InvariantCulture.NumberFormat));
  297. OnScalePropertiesChanged();
  298. }
  299. }
  300. /// <summary>
  301. /// Gets or sets the max add percent.
  302. /// </summary>
  303. public float MaxAddPercent
  304. {
  305. get
  306. {
  307. string property = GetProperty("eArithmeticMaxAddPercent");
  308. bool flag = property == null;
  309. float result;
  310. if (flag)
  311. {
  312. result = 2f;
  313. }
  314. else
  315. {
  316. result = ConvertHelper.ParseSingle(property);
  317. }
  318. return result;
  319. }
  320. set
  321. {
  322. float num = value;
  323. bool flag = num + MinAddPercent > 97f;
  324. if (flag)
  325. {
  326. num = 97f - MinAddPercent;
  327. }
  328. else
  329. {
  330. flag = (num < 0f);
  331. if (flag)
  332. {
  333. num = 0f;
  334. }
  335. }
  336. SetProperty("eArithmeticMaxAddPercent", num.ToString(CultureInfo.InvariantCulture.NumberFormat));
  337. OnScalePropertiesChanged();
  338. }
  339. }
  340. /// <summary>
  341. /// Gets or sets the max mode.
  342. /// </summary>
  343. public ValueScalerArithmetic.enumMaxMinValueMode MaxMode
  344. {
  345. get
  346. {
  347. string property = GetProperty(GetScaleModeString() + "MaxMode");
  348. bool flag = property == null;
  349. ValueScalerArithmetic.enumMaxMinValueMode result;
  350. if (flag)
  351. {
  352. result = ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin;
  353. }
  354. else
  355. {
  356. ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property);
  357. flag = (enumScaleBounding == (ValueScalerArithmetic.enumScaleBounding)2);
  358. if (flag)
  359. {
  360. enumScaleBounding = ValueScalerArithmetic.enumScaleBounding.eMaxMin;
  361. }
  362. result = (ValueScalerArithmetic.enumMaxMinValueMode)enumScaleBounding;
  363. }
  364. return result;
  365. }
  366. set
  367. {
  368. string arg_5E_1 = GetScaleModeString() + "MaxMode";
  369. int num = (int)value;
  370. SetProperty(arg_5E_1, num.ToString());
  371. OnScalePropertiesChanged();
  372. }
  373. }
  374. /// <summary>
  375. /// Gets or sets the min add percent.
  376. /// </summary>
  377. public float MinAddPercent
  378. {
  379. get
  380. {
  381. string property = GetProperty("eArithmeticMinAddPercent");
  382. bool flag = property == null;
  383. float result;
  384. if (flag)
  385. {
  386. result = 2f;
  387. }
  388. else
  389. {
  390. result = ConvertHelper.ParseSingle(property);
  391. }
  392. return result;
  393. }
  394. set
  395. {
  396. float num = value;
  397. if (num + MaxAddPercent > 97f)
  398. {
  399. num = 97f - MaxAddPercent;
  400. }
  401. else
  402. {
  403. if (num < 0f)
  404. {
  405. num = 0f;
  406. }
  407. }
  408. SetProperty("eArithmeticMinAddPercent", num.ToString(CultureInfo.InvariantCulture.NumberFormat));
  409. OnScalePropertiesChanged();
  410. }
  411. }
  412. /// <summary>
  413. /// Gets or sets the min mode.
  414. /// </summary>
  415. public ValueScalerArithmetic.enumMaxMinValueMode MinMode
  416. {
  417. get
  418. {
  419. string property = GetProperty(GetScaleModeString() + "MinMode");
  420. bool flag = property == null;
  421. ValueScalerArithmetic.enumMaxMinValueMode result;
  422. if (flag)
  423. {
  424. result = ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin;
  425. }
  426. else
  427. {
  428. ValueScalerArithmetic.enumScaleBounding enumScaleBounding = (ValueScalerArithmetic.enumScaleBounding)Conversions.ToInteger(property);
  429. flag = (enumScaleBounding == (ValueScalerArithmetic.enumScaleBounding)2);
  430. if (flag)
  431. {
  432. enumScaleBounding = ValueScalerArithmetic.enumScaleBounding.eMaxMin;
  433. }
  434. result = (ValueScalerArithmetic.enumMaxMinValueMode)enumScaleBounding;
  435. }
  436. return result;
  437. }
  438. set
  439. {
  440. string arg_5E_1 = GetScaleModeString() + "MinMode";
  441. int num = (int)value;
  442. SetProperty(arg_5E_1, num.ToString());
  443. OnScalePropertiesChanged();
  444. }
  445. }
  446. /// <summary>
  447. /// Gets or sets the scale mode.
  448. /// </summary>
  449. public ValueScalerArithmetic.enumScaleMethod ScaleMode
  450. {
  451. get
  452. {
  453. return _scaleMode;
  454. }
  455. set
  456. {
  457. bool flag = _scaleMode != value;
  458. if (flag)
  459. {
  460. _scaleMode = value;
  461. OnScalePropertiesChanged();
  462. }
  463. }
  464. }
  465. /// <summary>
  466. /// Gets or sets a value indicating whether [show scale as percent].
  467. /// </summary>
  468. public bool ShowScaleAsPercent
  469. {
  470. get
  471. {
  472. return _percentScale;
  473. }
  474. set
  475. {
  476. bool flag = _percentScale != value;
  477. if (flag)
  478. {
  479. _percentScale = value;
  480. // OnScalePropertiesChanged(); //只有更新图表时刷新时使用,可以不重新刷新
  481. }
  482. }
  483. }
  484. #endregion Public Properties
  485. #endregion Properties
  486. #region Methods
  487. #region Public Methods
  488. /// <summary>
  489. /// Calculates the scale.
  490. /// </summary>
  491. /// <param name="plots">The plots.</param>
  492. /// <param name="scaler">The scaler.</param>
  493. public void CalculateScale(List<PlotBase> plots, IDateScaler scaler, bool isTimeSpaning)
  494. {
  495. _flag = false;
  496. _high = 0f;
  497. _low = 0f;
  498. _maxValue = 0f;
  499. _minValue = 0f;
  500. bool flag = HasPriceHistory(plots, scaler, isTimeSpaning);
  501. if (flag)
  502. {
  503. _scaleMode2 = ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning;
  504. }
  505. else
  506. {
  507. _scaleMode2 = _scaleMode;
  508. }
  509. bool flag2 = ScaleOnlyPrice(plots);
  510. try
  511. {
  512. List<PlotBase>.Enumerator enumerator = plots.GetEnumerator();
  513. while (enumerator.MoveNext())
  514. {
  515. PlotBase current = enumerator.Current;
  516. flag = (current is ComparisonPlot);
  517. if (flag)
  518. {
  519. var dat = ((LinePlot)current).GetDataSet();
  520. flag = ((ComparisonPlot)current).IsActive;
  521. if (flag)
  522. {
  523. UpdateMaxAndMin(dat, scaler);
  524. }
  525. }
  526. else
  527. {
  528. flag = (current.Indicator != null && current.Indicator.ParentFormula.IsMain && isTimeSpaning);
  529. if (flag)
  530. {
  531. var dat = ((LinePlot)current).GetDataSet();
  532. UpdateHighAndLow(dat, scaler, true);
  533. }
  534. else
  535. {
  536. var dat = ((LinePlot)current).GetDataSet();
  537. UpdateHighAndLow(dat, scaler, false);
  538. }
  539. }
  540. }
  541. }
  542. finally
  543. {
  544. //List<PlotBase>.Enumerator enumerator;
  545. //enumerator.Dispose();
  546. }
  547. flag = (_high == _low);
  548. if (flag)
  549. {
  550. _high = (float)((double)_high + 0.1);
  551. flag = ((double)_low - 0.1 > 1.0);
  552. if (flag)
  553. {
  554. _low = (float)((double)_low - 0.1);
  555. }
  556. }
  557. try
  558. {
  559. switch (_scaleMode2)
  560. {
  561. case ValueScalerArithmetic.enumScaleMethod.eArithmetic:
  562. //if (cycleType == CycleType.TimeSharing)
  563. //{
  564. // var maxAbs = Math.Max(Math.Abs(_high - _percentBaseline), Math.Abs(_low - _percentBaseline));
  565. // _high = maxAbs + _percentBaseline;
  566. // _low = _percentBaseline - maxAbs;
  567. //}
  568. SetMinMaxArithmetic();
  569. break;
  570. case ValueScalerArithmetic.enumScaleMethod.eLog:
  571. SetMinMaxLog();
  572. break;
  573. case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning:
  574. if (isTimeSpaning)
  575. {
  576. var maxAbs = Math.Max(Math.Abs(_high - _percentBaseline), Math.Abs(_low - _percentBaseline));
  577. _high =(maxAbs *1.1f)/ _percentBaseline; // c_HightPrecent; //上限加10%
  578. _low = -_high;
  579. //SetMinMaxComparison();
  580. SetMinMaxTimeSpaning();
  581. }
  582. else
  583. {
  584. _high = (_high - _percentBaseline) / _percentBaseline;
  585. _low = (_low - _percentBaseline) / _percentBaseline;
  586. _high = Math.Max(_high, _maxValue);
  587. _low = Math.Min(_low, _minValue);
  588. SetMinMaxComparison();
  589. }
  590. break;
  591. }
  592. }
  593. catch (Exception expr_347)
  594. {
  595. ProjectData.SetProjectError(expr_347);
  596. ProjectData.ClearProjectError();
  597. }
  598. }
  599. /// <summary>
  600. /// Froms the XML.
  601. /// </summary>
  602. /// <param name="node">The node.</param>
  603. public void FromXML(XElement node)
  604. {
  605. bool flag = node.Attribute("Inverse") != null;
  606. if (flag)
  607. {
  608. _inverse = bool.Parse(node.Attribute("Inverse").Value);
  609. }
  610. flag = (node.Attribute("ComparisonScaleAsPercent") != null);
  611. if (flag)
  612. {
  613. _percentScale = bool.Parse(node.Attribute("ComparisonScaleAsPercent").Value);
  614. }
  615. flag = (node.Attribute("ScaleMode") != null);
  616. if (flag)
  617. {
  618. string value = node.Attribute("ScaleMode").Value;
  619. string text = value.ToLower();
  620. flag = (Operators.CompareString(text, "earithmetic", false) == 0);
  621. if (flag)
  622. {
  623. _scaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic;
  624. }
  625. else
  626. {
  627. flag = (Operators.CompareString(text, "elog", false) == 0);
  628. if (flag)
  629. {
  630. _scaleMode = ValueScalerArithmetic.enumScaleMethod.eLog;
  631. }
  632. }
  633. }
  634. _dictionary.Clear();
  635. try
  636. {
  637. IEnumerator<XElement> enumerator = node.Elements().GetEnumerator();
  638. while (enumerator.MoveNext())
  639. {
  640. XElement current = enumerator.Current;
  641. flag = (current.Name == "Arg");
  642. if (flag)
  643. {
  644. bool flag2 = current.Attribute("Name") != null && current.Attribute("Val") != null;
  645. if (flag2)
  646. {
  647. _dictionary[current.Attribute("Name").Value] = current.Attribute("Val").Value;
  648. }
  649. }
  650. }
  651. }
  652. finally
  653. {
  654. //IEnumerator<XElement> enumerator;
  655. //bool flag2 = enumerator != null;
  656. //if (flag2)
  657. //{
  658. // enumerator.Dispose();
  659. //}
  660. }
  661. }
  662. /// <summary>
  663. /// Gets the max value.
  664. /// </summary>
  665. /// <returns>System.Single.</returns>
  666. public float GetMaxValue()
  667. {
  668. if (_scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning)
  669. {
  670. var value = (_max + 1) * _percentBaseline;
  671. return value;
  672. }
  673. return _max;
  674. }
  675. /// <summary>
  676. /// Gets the min value.
  677. /// </summary>
  678. /// <returns>System.Single.</returns>
  679. public float GetMinValue()
  680. {
  681. if (_scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning)
  682. {
  683. var value = (_min + 1) * _percentBaseline;
  684. return value;
  685. }
  686. return _min;
  687. }
  688. /// <summary>
  689. /// Gets the percent baseline.
  690. /// </summary>
  691. /// <returns>System.Single.</returns>
  692. public float GetPercentBaseline()
  693. {
  694. return _percentBaseline;
  695. }
  696. /// <summary>
  697. /// Percents from value.
  698. /// </summary>
  699. /// <param name="aVal">A val.</param>
  700. /// <returns>System.Single.</returns>
  701. public float PercentFromValue(float aVal)
  702. {
  703. float result = 0f;
  704. switch (_scaleMode2)
  705. {
  706. case ValueScalerArithmetic.enumScaleMethod.eArithmetic:
  707. result = PercentFromValueArithmetic(aVal);
  708. break;
  709. case ValueScalerArithmetic.enumScaleMethod.eLog:
  710. result = PercentFromValueLog(aVal);
  711. break;
  712. case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning:
  713. result = PercentFromValueComparison(aVal);
  714. break;
  715. }
  716. return result;
  717. }
  718. /// <summary>
  719. /// Percents from value arithmetic.
  720. /// </summary>
  721. /// <param name="aValue">A value.</param>
  722. /// <returns>System.Single.</returns>
  723. public float PercentFromValueArithmetic(float aValue)
  724. {
  725. bool flag = float.IsInfinity(aValue) || float.IsNaN(aValue);
  726. float result = 0f;
  727. if (flag)
  728. {
  729. result = 0f;
  730. }
  731. else
  732. {
  733. flag = (_min != _max);
  734. if (flag)
  735. {
  736. bool flag2 = _inverse;
  737. float num;
  738. if (flag2)
  739. {
  740. num = 1f - (aValue - _min) * _diffInverse;
  741. }
  742. else
  743. {
  744. num = (aValue - _min) * _diffInverse;
  745. }
  746. flag2 = (num > 500000f);
  747. if (flag2)
  748. {
  749. num = 500000f;
  750. }
  751. else
  752. {
  753. flag2 = (num < -500000f);
  754. if (flag2)
  755. {
  756. num = -500000f;
  757. }
  758. }
  759. result = num;
  760. }
  761. }
  762. return result;
  763. }
  764. /// <summary>
  765. /// Percents from value comparison.
  766. /// </summary>
  767. /// <param name="inValue">The in value.</param>
  768. /// <returns>System.Single.</returns>
  769. public float PercentFromValueComparison(float inValue)
  770. {
  771. float num = (inValue - _percentBaseline) / _percentBaseline;
  772. bool flag = float.IsInfinity(num) || float.IsNaN(num);
  773. float result = 0f;
  774. if (flag)
  775. {
  776. result = 0f;
  777. }
  778. else
  779. {
  780. flag = (_min != _max);
  781. if (flag)
  782. {
  783. bool flag2 = _inverse;
  784. float num2;
  785. if (flag2)
  786. {
  787. num2 = 1f - (num - _min) * _diffInverse;
  788. }
  789. else
  790. {
  791. num2 = (num - _min) * _diffInverse;
  792. }
  793. flag2 = (num2 > 500000f);
  794. if (flag2)
  795. {
  796. num2 = 500000f;
  797. }
  798. else
  799. {
  800. flag2 = (num2 < -500000f);
  801. if (flag2)
  802. {
  803. num2 = -500000f;
  804. }
  805. }
  806. result = num2;
  807. }
  808. }
  809. return result;
  810. }
  811. /// <summary>
  812. /// Percents from value display.
  813. /// </summary>
  814. /// <param name="aVal">A val.</param>
  815. /// <returns>System.Single.</returns>
  816. public float PercentFromValueDisplay(float aVal)
  817. {
  818. bool flag = _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning && _percentScale;
  819. float result;
  820. if (flag)
  821. {
  822. result = PercentFromValueArithmetic(aVal / 100f);
  823. }
  824. else
  825. {
  826. result = PercentFromValue(aVal);
  827. }
  828. return result;
  829. }
  830. /// <summary>
  831. /// Percents from value log.
  832. /// </summary>
  833. /// <param name="aValue">A value.</param>
  834. /// <returns>System.Single.</returns>
  835. public float PercentFromValueLog(float aValue)
  836. {
  837. bool flag = aValue <= 0f;
  838. float result = 0f;
  839. if (flag)
  840. {
  841. result = -500000f;
  842. }
  843. else
  844. {
  845. float num = (float)Math.Log10((double)aValue);
  846. flag = (_logMin != _logMax);
  847. if (flag)
  848. {
  849. bool flag2 = _inverse;
  850. float num2;
  851. if (flag2)
  852. {
  853. num2 = 1f - (num - _logMin) * _logDiffInverse;
  854. }
  855. else
  856. {
  857. num2 = (num - _logMin) * _logDiffInverse;
  858. }
  859. flag2 = (num2 > 500000f);
  860. if (flag2)
  861. {
  862. num2 = 500000f;
  863. }
  864. else
  865. {
  866. flag2 = (num2 < -500000f);
  867. if (flag2)
  868. {
  869. num2 = -500000f;
  870. }
  871. }
  872. result = num2;
  873. }
  874. }
  875. return result;
  876. }
  877. /// <summary>
  878. /// Roots the name.
  879. /// </summary>
  880. /// <returns>System.String.</returns>
  881. public string RootName()
  882. {
  883. return "VALSCALER";
  884. }
  885. /// <summary>
  886. /// Scaleds the Y.
  887. /// </summary>
  888. /// <param name="aVal">A val.</param>
  889. /// <param name="aRect">A rect.</param>
  890. /// <returns>System.Single.</returns>
  891. public float ScaledY(float aVal, Rect aRect)
  892. {
  893. bool flag = _high.Equals(_low);
  894. float result;
  895. if (flag)
  896. {
  897. result = (float)aRect.Bottom;
  898. }
  899. else
  900. {
  901. float num = (float)(aRect.Height - 1.0);
  902. flag = (num <= 0f);
  903. if (flag)
  904. {
  905. num = 1E-05f;
  906. }
  907. result = (float)checked((int)Math.Round(unchecked(aRect.Top + (double)((1f - PercentFromValue(aVal)) * num))));
  908. }
  909. return result;
  910. }
  911. public float Spread()
  912. {
  913. return _high - _low;
  914. }
  915. /// <summary>
  916. /// To the XML.
  917. /// </summary>
  918. /// <param name="args">The args.</param>
  919. /// <returns>XElement.</returns>
  920. public XElement ToXML(List<object> args)
  921. {
  922. XElement xElement = new XElement(RootName());
  923. xElement.Add(new XAttribute("Inverse", _inverse.ToString()));
  924. xElement.Add(new XAttribute("ScaleMode", _scaleMode.ToString()));
  925. xElement.Add(new XAttribute("ComparisonScaleAsPercent", _percentScale.ToString()));
  926. try
  927. {
  928. Dictionary<string, string>.KeyCollection.Enumerator enumerator = _dictionary.Keys.GetEnumerator();
  929. while (enumerator.MoveNext())
  930. {
  931. string current = enumerator.Current;
  932. XElement xElement2 = new XElement("Arg");
  933. xElement2.Add(new XAttribute("Name", current));
  934. xElement2.Add(new XAttribute("Val", _dictionary[current]));
  935. xElement.Add(xElement2);
  936. }
  937. }
  938. finally
  939. {
  940. //Dictionary<string, string>.KeyCollection.Enumerator enumerator;
  941. //enumerator.Dispose();
  942. }
  943. return xElement;
  944. }
  945. /// <summary>
  946. /// Values from percent.
  947. /// </summary>
  948. /// <param name="aPercent">A percent.</param>
  949. /// <returns>System.Single.</returns>
  950. public float ValueFromPercent(float aPercent)
  951. {
  952. float result = 0f;
  953. switch (_scaleMode2)
  954. {
  955. case ValueScalerArithmetic.enumScaleMethod.eArithmetic:
  956. result = ValueFromPercentArithmetic(aPercent);
  957. break;
  958. case ValueScalerArithmetic.enumScaleMethod.eLog:
  959. result = ValueFromPercentLog(aPercent);
  960. break;
  961. case ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning:
  962. result = ValueFromPercentComparison(aPercent);
  963. break;
  964. }
  965. return result;
  966. }
  967. /// <summary>
  968. /// Values from percent arithmetic.
  969. /// </summary>
  970. /// <param name="aPercent">A percent.</param>
  971. /// <returns>System.Single.</returns>
  972. public float ValueFromPercentArithmetic(float aPercent)
  973. {
  974. bool flag = aPercent == 0f;
  975. float result = 0f;
  976. if (flag)
  977. {
  978. bool flag2 = _inverse;
  979. if (flag2)
  980. {
  981. result = _max;
  982. }
  983. else
  984. {
  985. result = _min;
  986. }
  987. }
  988. else
  989. {
  990. bool flag2 = _inverse;
  991. if (flag2)
  992. {
  993. result = (_max - _min) * (1f - aPercent) + _min;
  994. }
  995. else
  996. {
  997. result = (_max - _min) * aPercent + _min;
  998. }
  999. }
  1000. return result;
  1001. }
  1002. /// <summary>
  1003. /// Values from percent comparison.
  1004. /// </summary>
  1005. /// <param name="aPercent">A percent.</param>
  1006. /// <returns>System.Single.</returns>
  1007. public float ValueFromPercentComparison(float aPercent)
  1008. {
  1009. bool flag = aPercent == 0f;
  1010. float num;
  1011. if (flag)
  1012. {
  1013. bool flag2 = _inverse;
  1014. if (flag2)
  1015. {
  1016. num = _max;
  1017. }
  1018. else
  1019. {
  1020. num = _min;
  1021. }
  1022. }
  1023. else
  1024. {
  1025. bool flag2 = _inverse;
  1026. if (flag2)
  1027. {
  1028. num = (_max - _min) * (1f - aPercent) + _min;
  1029. }
  1030. else
  1031. {
  1032. num = (_max - _min) * aPercent + _min;
  1033. }
  1034. }
  1035. return _percentBaseline + _percentBaseline * num;
  1036. }
  1037. /// <summary>
  1038. /// 分时图中的刻度线
  1039. /// </summary>
  1040. /// <param name="aPercent">百分比</param>
  1041. /// <returns></returns>
  1042. public float ValueFromTimeSpaningPercent(float aPercent)
  1043. {
  1044. return _percentBaseline + _percentBaseline * aPercent;
  1045. }
  1046. /// <summary>
  1047. /// Values from percent display.
  1048. /// </summary>
  1049. /// <param name="aPercent">A percent.</param>
  1050. /// <returns>System.Single.</returns>
  1051. public float ValueFromPercentDisplay(float aPercent)
  1052. {
  1053. bool flag = _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning
  1054. && _percentScale;
  1055. float result;
  1056. if (flag)
  1057. {
  1058. result = ValueFromPercentArithmetic(aPercent) * 100f;
  1059. }
  1060. else
  1061. {
  1062. result = ValueFromPercent(aPercent);
  1063. }
  1064. return result;
  1065. }
  1066. /// <summary>
  1067. /// Values from percent log.
  1068. /// </summary>
  1069. /// <param name="aPercent">A percent.</param>
  1070. /// <returns>System.Single.</returns>
  1071. public float ValueFromPercentLog(float aPercent)
  1072. {
  1073. float result = 0f;
  1074. try
  1075. {
  1076. bool flag = _inverse;
  1077. if (flag)
  1078. {
  1079. result = (float)Math.Pow(10.0, (double)((_logMax - _logMin) * (1f - aPercent) + _logMin));
  1080. }
  1081. else
  1082. {
  1083. result = (float)Math.Pow(10.0, (double)((_logMax - _logMin) * aPercent + _logMin));
  1084. }
  1085. }
  1086. catch (Exception expr_8E)
  1087. {
  1088. ProjectData.SetProjectError(expr_8E);
  1089. ProjectData.ClearProjectError();
  1090. }
  1091. return result;
  1092. }
  1093. /// <summary>
  1094. /// Values from Y.
  1095. /// </summary>
  1096. /// <param name="aY">A Y.</param>
  1097. /// <param name="aRect">A rect.</param>
  1098. /// <returns>System.Single.</returns>
  1099. public float ValueFromY(float aY, Rect aRect)
  1100. {
  1101. float aPercent = (float)(((double)aY - aRect.Bottom) / (aRect.Top - aRect.Bottom));
  1102. return ValueFromPercent(aPercent);
  1103. }
  1104. /// <summary>
  1105. /// Ys from percent.
  1106. /// </summary>
  1107. /// <param name="aPercent">A percent.</param>
  1108. /// <param name="aRect">A rect.</param>
  1109. /// <returns>System.Single.</returns>
  1110. public float YFromPercent(float aPercent, Rect aRect)
  1111. {
  1112. float num = (float)(aRect.Height - 1.0);
  1113. bool flag = num <= 0f;
  1114. if (flag)
  1115. {
  1116. num = 1E-05f;
  1117. }
  1118. return (float)checked((int)Math.Round(unchecked(aRect.Top + (double)((1f - aPercent) * num))));
  1119. }
  1120. #endregion Public Methods
  1121. #region Internal Methods
  1122. /// <summary>
  1123. /// Determines whether [is P change from beginning].
  1124. /// </summary>
  1125. /// <returns><c>true</c> if [is P change from beginning]; otherwise, <c>false</c>.</returns>
  1126. internal bool IsPChangeFromBeginning()
  1127. {
  1128. return _scaleMode2 == ValueScalerArithmetic.enumScaleMethod.ePChangeFromBeginning;
  1129. }
  1130. #endregion Internal Methods
  1131. #region Protected Methods
  1132. /// <summary>
  1133. /// Gets the property.
  1134. /// </summary>
  1135. /// <param name="aName">A name.</param>
  1136. /// <returns>System.String.</returns>
  1137. protected string GetProperty(string aName)
  1138. {
  1139. string result = null;
  1140. bool flag = _dictionary.ContainsKey(aName);
  1141. if (flag)
  1142. {
  1143. result = _dictionary[aName];
  1144. }
  1145. return result;
  1146. }
  1147. /// <summary>
  1148. /// Sets the min max arithmetic.
  1149. /// </summary>
  1150. protected void SetMinMaxArithmetic()
  1151. {
  1152. bool flag;
  1153. switch (BoundingMethod)
  1154. {
  1155. case enumScaleBounding.eMaxMin:
  1156. switch (MaxMode)
  1157. {
  1158. case enumMaxMinValueMode.eMaxMin:
  1159. _max = _high;
  1160. break;
  1161. case enumMaxMinValueMode.eManual:
  1162. _max = ManualMax;
  1163. break;
  1164. }
  1165. switch (MinMode)
  1166. {
  1167. case enumMaxMinValueMode.eMaxMin:
  1168. _min = _low;
  1169. break;
  1170. case enumMaxMinValueMode.eManual:
  1171. _min = ManualMin;
  1172. break;
  1173. }
  1174. flag = (MaxAddPercent > 0f || MinAddPercent > 0f);
  1175. if (flag)
  1176. {
  1177. double num = (double)(MaxAddPercent / 100f);
  1178. double num2 = (double)(MinAddPercent / 100f);
  1179. double num3 = 1.0 - (num + num2);
  1180. double num4 = (double)(_max - _min);
  1181. flag = (num3 > 0.0);
  1182. if (flag)
  1183. {
  1184. _max = (float)((double)_max + num4 * (num / num3));
  1185. _min = (float)((double)_min - num4 * (num2 / num3));
  1186. }
  1187. }
  1188. break;
  1189. case enumScaleBounding.eCentered:
  1190. {
  1191. _max = _high;
  1192. _min = _low;
  1193. float num5 = ManualCenter;
  1194. flag = (CenterMode == enumCenteredValueMode.eMedian);
  1195. if (flag)
  1196. {
  1197. num5 = _max / 2f + _min / 2f;
  1198. }
  1199. switch (HeightMode)
  1200. {
  1201. case enumCenteredHeight.eAuto:
  1202. {
  1203. float num6 = Math.Max(Math.Abs(_max - num5), Math.Abs(num5 - _min));
  1204. _max = num5 + num6;
  1205. _min = num5 - num6;
  1206. break;
  1207. }
  1208. case enumCenteredHeight.eManual:
  1209. _max = num5 + ManualHeight / 2f;
  1210. _min = num5 - ManualHeight / 2f;
  1211. break;
  1212. }
  1213. break;
  1214. }
  1215. }
  1216. bool arg_24E_0;
  1217. if (!float.IsNaN(_min) && !float.IsInfinity(_min))
  1218. {
  1219. if (!float.IsNaN(_min))
  1220. {
  1221. if (!float.IsInfinity(_min))
  1222. {
  1223. arg_24E_0 = false;
  1224. goto IL_24E;
  1225. }
  1226. }
  1227. }
  1228. //IL_24D:
  1229. arg_24E_0 = true;
  1230. //goto IL_24E;
  1231. //goto IL_24D;
  1232. IL_24E:
  1233. flag = arg_24E_0;
  1234. if (flag)
  1235. {
  1236. _min = 0f;
  1237. _max = 0f;
  1238. }
  1239. flag = (_max != _min);
  1240. if (flag)
  1241. {
  1242. _diffInverse = 1f / (_max - _min);
  1243. }
  1244. else
  1245. {
  1246. _diffInverse = 0f;
  1247. }
  1248. }
  1249. /// <summary>
  1250. /// Sets the min max comparison.
  1251. /// </summary>
  1252. protected void SetMinMaxComparison()
  1253. {
  1254. _max = _high;
  1255. _min = _low;
  1256. bool flag = MaxAddPercent > 0f || MinAddPercent > 0f;
  1257. if (flag)
  1258. {
  1259. double num = (double)(MaxAddPercent / 100f);
  1260. double num2 = (double)(MinAddPercent / 100f);
  1261. double num3 = 1.0 - (num + num2);
  1262. double num4 = (double)(_max - _min);
  1263. flag = (num3 > 0.0);
  1264. if (flag)
  1265. {
  1266. _max = (float)((double)_max + num4 * (num / num3));
  1267. _min = (float)((double)_min - num4 * (num2 / num3));
  1268. }
  1269. }
  1270. float num5 = _max - _min;
  1271. _max += num5 * 3f / 100f;
  1272. _min -= num5 * 3f / 100f;
  1273. bool arg_14F_0;
  1274. if (!float.IsNaN(_min) && !float.IsInfinity(_min))
  1275. {
  1276. if (!float.IsNaN(_min))
  1277. {
  1278. if (!float.IsInfinity(_min))
  1279. {
  1280. arg_14F_0 = false;
  1281. goto IL_14F;
  1282. }
  1283. }
  1284. }
  1285. arg_14F_0 = true;
  1286. IL_14F:
  1287. flag = arg_14F_0;
  1288. if (flag)
  1289. {
  1290. _min = 0f;
  1291. _max = 0f;
  1292. }
  1293. flag = (_max != _min);
  1294. if (flag)
  1295. {
  1296. _diffInverse = 1f / (_max - _min);
  1297. }
  1298. else
  1299. {
  1300. _diffInverse = 0f;
  1301. }
  1302. }
  1303. /// <summary>
  1304. /// 设置分时图最大最小值
  1305. /// </summary>
  1306. private void SetMinMaxTimeSpaning()
  1307. {
  1308. _max = _high;
  1309. _min = _low;
  1310. bool flag = MaxAddPercent > 0f || MinAddPercent > 0f;
  1311. //if (flag)
  1312. //{
  1313. // double num = (double)(MaxAddPercent / 100f);
  1314. // double num2 = (double)(MinAddPercent / 100f);
  1315. // double num3 = 1.0 - (num + num2);
  1316. // double num4 = (double)(_max - _min);
  1317. // flag = (num3 > 0.0);
  1318. // if (flag)
  1319. // {
  1320. // _max = (float)((double)_max + num4 * (num / num3));
  1321. // _min = (float)((double)_min - num4 * (num2 / num3));
  1322. // }
  1323. //}
  1324. //float num5 = _max - _min;
  1325. //_max += num5 * 3f / 100f;
  1326. //_min -= num5 * 3f / 100f;
  1327. bool arg_14F_0;
  1328. if (!float.IsNaN(_min) && !float.IsInfinity(_min))
  1329. {
  1330. if (!float.IsNaN(_min))
  1331. {
  1332. if (!float.IsInfinity(_min))
  1333. {
  1334. arg_14F_0 = false;
  1335. goto IL_14F;
  1336. }
  1337. }
  1338. }
  1339. arg_14F_0 = true;
  1340. IL_14F:
  1341. flag = arg_14F_0;
  1342. if (flag)
  1343. {
  1344. _min = 0f;
  1345. _max = 0f;
  1346. }
  1347. flag = (_max != _min);
  1348. if (flag)
  1349. {
  1350. _diffInverse = 1f / (_max - _min);
  1351. }
  1352. else
  1353. {
  1354. _diffInverse = 0f;
  1355. }
  1356. }
  1357. /// <summary>
  1358. /// Sets the min max log.
  1359. /// </summary>
  1360. protected void SetMinMaxLog()
  1361. {
  1362. bool flag = _high <= 0f;
  1363. float num;
  1364. if (flag)
  1365. {
  1366. num = (float)Math.Log10(0.01);
  1367. }
  1368. else
  1369. {
  1370. num = (float)Math.Log10((double)_high);
  1371. }
  1372. flag = (_low <= 0f);
  1373. float num2;
  1374. if (flag)
  1375. {
  1376. num2 = (float)Math.Log10(0.01);
  1377. }
  1378. else
  1379. {
  1380. num2 = (float)Math.Log10((double)_low);
  1381. }
  1382. switch (BoundingMethod)
  1383. {
  1384. case ValueScalerArithmetic.enumScaleBounding.eMaxMin:
  1385. switch (MaxMode)
  1386. {
  1387. case ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin:
  1388. _max = num;
  1389. break;
  1390. case ValueScalerArithmetic.enumMaxMinValueMode.eManual:
  1391. flag = (ManualMax <= 0f);
  1392. if (flag)
  1393. {
  1394. _max = (float)Math.Log10(0.01);
  1395. }
  1396. else
  1397. {
  1398. _max = (float)Math.Log10((double)ManualMax);
  1399. }
  1400. break;
  1401. }
  1402. switch (MinMode)
  1403. {
  1404. case ValueScalerArithmetic.enumMaxMinValueMode.eMaxMin:
  1405. _min = num2;
  1406. break;
  1407. case ValueScalerArithmetic.enumMaxMinValueMode.eManual:
  1408. flag = (ManualMin <= 0f);
  1409. if (flag)
  1410. {
  1411. _min = (float)Math.Log10(0.01);
  1412. }
  1413. else
  1414. {
  1415. _min = (float)Math.Log10((double)ManualMin);
  1416. }
  1417. break;
  1418. }
  1419. flag = (MaxAddPercent > 0f || MinAddPercent > 0f);
  1420. if (flag)
  1421. {
  1422. double num3 = (double)(MaxAddPercent / 100f);
  1423. double num4 = (double)(MinAddPercent / 100f);
  1424. double num5 = 1.0 - (num3 + num4);
  1425. double num6 = (double)(_max - _min);
  1426. flag = (num5 > 0.0);
  1427. if (flag)
  1428. {
  1429. _max = (float)((double)_max + num6 * (num3 / num5));
  1430. _min = (float)((double)_min - num6 * (num4 / num5));
  1431. }
  1432. }
  1433. break;
  1434. case ValueScalerArithmetic.enumScaleBounding.eCentered:
  1435. {
  1436. flag = (ManualCenter <= 0f);
  1437. float num7;
  1438. if (flag)
  1439. {
  1440. num7 = (float)Math.Log10(0.01);
  1441. }
  1442. else
  1443. {
  1444. num7 = (float)Math.Log10((double)ManualCenter);
  1445. }
  1446. _max = num;
  1447. _min = num2;
  1448. flag = (CenterMode == ValueScalerArithmetic.enumCenteredValueMode.eMedian);
  1449. if (flag)
  1450. {
  1451. num7 = _max / 2f + _min / 2f;
  1452. }
  1453. switch (HeightMode)
  1454. {
  1455. case ValueScalerArithmetic.enumCenteredHeight.eAuto:
  1456. {
  1457. float num8 = Math.Max(Math.Abs(_max - num7), Math.Abs(num7 - _min));
  1458. _max = num7 + num8;
  1459. _min = num7 - num8;
  1460. break;
  1461. }
  1462. case ValueScalerArithmetic.enumCenteredHeight.eManual:
  1463. {
  1464. flag = (ManualHeight <= 0f);
  1465. float num9;
  1466. if (flag)
  1467. {
  1468. num9 = (float)Math.Log10(0.01);
  1469. }
  1470. else
  1471. {
  1472. num9 = (float)Math.Log10((double)ManualHeight);
  1473. }
  1474. float num10 = (float)((double)ManualHeight / Math.Pow(10.0, (double)num7));
  1475. float num11 = (float)(((double)(-1f * num10) + Math.Sqrt(Math.Pow((double)num10, 2.0) + 4.0)) / 2.0);
  1476. float num12 = (float)((double)ManualHeight / Math.Pow(10.0, (double)num7));
  1477. num9 = (float)(-1.0 * (Math.Log10((double)num12) / 2.0));
  1478. num9 = (float)Math.Log10((double)num11);
  1479. _max = num7 - num9;
  1480. _min = num7 + num9;
  1481. break;
  1482. }
  1483. }
  1484. break;
  1485. }
  1486. }
  1487. _logMax = _max;
  1488. _logMin = _min;
  1489. flag = (_logMax != _logMin);
  1490. if (flag)
  1491. {
  1492. _logDiffInverse = 1f / (_logMax - _logMin);
  1493. }
  1494. else
  1495. {
  1496. _logDiffInverse = 0f;
  1497. }
  1498. }
  1499. /// <summary>
  1500. /// Sets the property.
  1501. /// </summary>
  1502. /// <param name="aName">A name.</param>
  1503. /// <param name="newVal">The new val.</param>
  1504. protected void SetProperty(string aName, string newVal)
  1505. {
  1506. _dictionary[aName] = newVal;
  1507. }
  1508. #endregion Protected Methods
  1509. #region Private Methods
  1510. /// <summary>
  1511. /// Gets the scale mode string.
  1512. /// </summary>
  1513. /// <returns>System.String.</returns>
  1514. private string GetScaleModeString()
  1515. {
  1516. return _scaleMode.ToString();
  1517. }
  1518. /// <summary>
  1519. /// Determines whether [has price history] [the specified plots].
  1520. /// </summary>
  1521. /// <param name="plots">The plots.</param>
  1522. /// <param name="scaler">The scaler.</param>
  1523. /// <param name="isTimeSpaning">if set to <c>true</c> [is time spaning].</param>
  1524. /// <returns><c>true</c> if [has price history] [the specified plots]; otherwise, <c>false</c>.</returns>
  1525. private bool HasPriceHistory(List<PlotBase> plots, IDateScaler scaler, bool isTimeSpaning)
  1526. {
  1527. if (plots == null || !plots.Any()) return false;
  1528. foreach (var plot in plots)
  1529. {
  1530. if (plot == null || plot.Indicator == null || plot.Indicator.ParentFormula == null) continue;
  1531. bool flag = plot.Indicator.ParentFormula.IsMain || isTimeSpaning;
  1532. if (flag)
  1533. {
  1534. UpdatePercentBaseline((LinePlot)plot, scaler);
  1535. return true;
  1536. }
  1537. }
  1538. return false;
  1539. }
  1540. /// <summary>
  1541. /// Called when [scale properties changed].
  1542. /// </summary>
  1543. private void OnScalePropertiesChanged()
  1544. {
  1545. if (ScalePropertiesChanged != null)
  1546. {
  1547. ScalePropertiesChanged();
  1548. }
  1549. }
  1550. /// <summary>
  1551. /// Scales the only price.
  1552. /// </summary>
  1553. /// <param name="plots">The plots.</param>
  1554. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  1555. private bool ScaleOnlyPrice(List<PlotBase> plots)
  1556. {
  1557. if (plots == null || !plots.Any()) return false;
  1558. return true;
  1559. //return (from current in plots
  1560. // let flag = current.Calculation() is PriceHistoryCalculation
  1561. // where flag
  1562. // select ((PriceHistoryCalculation)current.Calculation()).ScaleOnlyPrice).Any(scaleOnlyPrice => scaleOnlyPrice);
  1563. }
  1564. /// <summary>
  1565. /// Updates the high and low.
  1566. /// </summary>
  1567. /// <param name="dat">The dat.</param>
  1568. /// <param name="scaler">The scaler.</param>
  1569. /// <param name="allowOhlc">if set to <c>true</c> [allow OHLC].</param>
  1570. private void UpdateHighAndLow(IndicatorModel dat, IDateScaler scaler, bool allowOhlc)
  1571. {
  1572. if (dat == null || dat.CalculateDataPoints == null || !dat.CalculateDataPoints.Any()) return;
  1573. foreach (var current in dat.CalculateDataPoints)
  1574. {
  1575. var visible = scaler.DateVisible(current.Date);
  1576. if (!visible) continue;
  1577. if (allowOhlc && (current is IOHLCDataPoint))
  1578. {
  1579. var iohlcDataPoint = (IOHLCDataPoint)current;
  1580. if (_flag)
  1581. {
  1582. if (!float.IsNaN(iohlcDataPoint.High)) _high = Math.Max(_high, iohlcDataPoint.High);
  1583. if (!float.IsNaN(iohlcDataPoint.Low)) _low = Math.Min(_low, iohlcDataPoint.Low);
  1584. }
  1585. else
  1586. {
  1587. _low = iohlcDataPoint.Low;
  1588. _high = iohlcDataPoint.High;
  1589. _flag = true;
  1590. }
  1591. }
  1592. else
  1593. {
  1594. float value = current.Value;
  1595. if (float.IsNaN(value)) continue;
  1596. if (_flag)
  1597. {
  1598. _high = Math.Max(_high, value);
  1599. _low = Math.Min(_low, value);
  1600. }
  1601. else
  1602. {
  1603. _low = value;
  1604. _high = value;
  1605. _flag = true;
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /// <summary>
  1611. /// Updates the max and min.
  1612. /// </summary>
  1613. /// <param name="dat">The dat.</param>
  1614. /// <param name="scaler">The scaler.</param>
  1615. private void UpdateMaxAndMin(IndicatorModel dat, IDateScaler scaler)
  1616. {
  1617. bool flag = false;
  1618. float num = 0f;
  1619. bool flag2 = dat != null && dat.CalculateDataPoints != null;
  1620. checked
  1621. {
  1622. if (flag2)
  1623. {
  1624. var list = dat.CalculateDataPoints;
  1625. int num2 = list.Count - 1;
  1626. int num3 = 0;
  1627. while (true)
  1628. {
  1629. int num4 = num2;
  1630. if (num3 > num4)
  1631. {
  1632. break;
  1633. }
  1634. flag2 = scaler.DateVisible(list[num3].Date);
  1635. if (flag2)
  1636. {
  1637. bool flag3 = !flag;
  1638. if (flag3)
  1639. {
  1640. num = list[num3].Value;
  1641. flag = true;
  1642. }
  1643. float num5 = unchecked(list[num3].Value - num) / num;
  1644. _maxValue = Math.Max(_maxValue, num5);
  1645. _minValue = Math.Min(_minValue, num5);
  1646. }
  1647. num3++;
  1648. }
  1649. }
  1650. }
  1651. }
  1652. /// <summary>
  1653. /// Updates the percent baseline.
  1654. /// </summary>
  1655. /// <param name="aPlot">A plot.</param>
  1656. /// <param name="scaler">The scaler.</param>
  1657. private void UpdatePercentBaseline(LinePlot aPlot, IDateScaler scaler)
  1658. {
  1659. if (IsTimeSpaning)
  1660. {
  1661. _percentBaseline = TimeSpaningLast;
  1662. }
  1663. else
  1664. {
  1665. _percentBaseline = 0f;
  1666. var lineDataSet = aPlot.GetDataSet();
  1667. if (lineDataSet == null || lineDataSet.CalculateDataPoints == null ||
  1668. !lineDataSet.CalculateDataPoints.Any()) return;
  1669. //var firstIndex = scaler.FirstVisibleIndexFromData(lineDataSet.CalculateDataPoints);
  1670. //var first = lineDataSet.CalculateDataPoints[firstIndex];
  1671. //if (first == null) return;
  1672. //var dataPoint = first as IOHLCDataPoint;
  1673. //_percentBaseline = dataPoint == null ? first.Value : dataPoint.Close;
  1674. //使用最后一点做现价线
  1675. var endIndex = scaler.LastVisibleIndexFromData(lineDataSet.CalculateDataPoints);
  1676. var end = lineDataSet.CalculateDataPoints[endIndex];
  1677. if (end == null) return;
  1678. var dataPoint = end as IOHLCDataPoint;
  1679. _percentBaseline = dataPoint == null ? end.Value : dataPoint.Close;
  1680. }
  1681. }
  1682. #endregion Private Methods
  1683. #endregion Methods
  1684. public bool IsTimeSpaning
  1685. {
  1686. get;
  1687. set;
  1688. }
  1689. public float TimeSpaningLast
  1690. {
  1691. get;
  1692. set;
  1693. }
  1694. }
  1695. }