コピペ: OmegaChart Fibonacciリトレースメント Fibonacci.cs 新規追加 ※差し替え その8 修正ポイントには //☆Fibonacci 20190207

形式
Plain text
投稿日時
2019-02-07 22:20
公開期間
無期限
  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. using System.Text;
  5. using Zanetti.Data;
  6. using Travis.Storage;
  7. namespace Zanetti.UI
  8. {
  9. /// <summary>
  10. /// Fibonacci の概要の説明です。
  11. /// </summary>
  12. internal class Fibonacci
  13. {
  14. private PointF _pivot;
  15. private PointF _destination;
  16. private int _id; //SolidFibonacciからの作成時のみセット、それ以外は-1
  17. private LineDrawMode _mode;
  18. public enum LineDrawMode
  19. {
  20. Normal,
  21. Hilight,//☆Fibonacci 20180816 カンマ「,」追加
  22. Move//☆Fibonacci 20180816 追加
  23. }
  24. public Fibonacci(PointF p)
  25. {
  26. _pivot = p;
  27. _destination = p;
  28. _id = -1;
  29. }
  30. public Fibonacci(PointF p1, PointF p2)
  31. {
  32. _pivot = p1;
  33. _destination = p2;
  34. _id = -1;
  35. }
  36. //リサイズしたときなどの再計算
  37. public Fibonacci(DataFarm farm, int firstdateindex, SolidFibonacci fl, Trans value_to_y)
  38. {
  39. int p = Env.Layout.DatePitch;
  40. _pivot = new PointF((farm.DateToIndex(fl._date1) - firstdateindex) * p + p / 2, (float)value_to_y.TransValue(fl._value1));
  41. _destination = new PointF((farm.DateToIndex(fl._date2) - firstdateindex) * p + p / 2, (float)value_to_y.TransValue(fl._value2));
  42. _id = fl._id;
  43. }
  44. public PointF Pivot
  45. {
  46. get
  47. {
  48. return _pivot;
  49. }
  50. //☆Fibonacci 20180816 setは不要
  51. }
  52. public PointF Destination
  53. {
  54. get
  55. {
  56. return _destination;
  57. }
  58. set
  59. {
  60. _destination = value;
  61. }
  62. }
  63. public LineDrawMode DrawMode
  64. {
  65. get
  66. {
  67. return _mode;
  68. }
  69. set
  70. {
  71. _mode = value;
  72. }
  73. }
  74. public int ID
  75. {
  76. get
  77. {
  78. return _id;
  79. }
  80. }
  81. public void SetHighPriceAndLowPrice(DataFarm farm, Trans pricetrans, float x1, float x2, int FirstDateIndex)
  82. {
  83. var range_max = double.MinValue;//☆Fibonacci 20180816 新規追加
  84. var range_min = double.MaxValue;//☆Fibonacci 20180816 新規追加
  85. var y1 = double.MinValue;//☆Fibonacci 20180816 新規追加
  86. var y2 = double.MinValue;//☆Fibonacci 20180816 新規追加
  87. if (x1 > Env.Layout.ChartAreaWidth || x2 > Env.Layout.ChartAreaWidth)
  88. return;
  89. int ind1 = FirstDateIndex + (int)Math.Floor((double)Math.Min(x1, x2) / Env.Layout.DatePitch);
  90. int ind2 = FirstDateIndex + (int)Math.Floor((double)Math.Max(x1, x2) / Env.Layout.DatePitch);
  91. if (ind1 < 0) ind1 = 0;
  92. if (ind2 < 0) ind2 = 0;
  93. if (ind1 >= farm.FilledLength) ind1 = farm.FilledLength - 1;//☆Fibonacci 20180816 修正
  94. if (ind2 >= farm.FilledLength) ind2 = farm.FilledLength - 1;//☆Fibonacci 20180816 修正
  95. //最高値と最安値の株価
  96. range_max = Max(farm, ind1, ind2);//☆Fibonacci 20180816 修正
  97. range_min = Min(farm, ind1, ind2);//☆Fibonacci 20180816 修正
  98. //最高値と最安値の画面上の位置
  99. //var y1 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_max : range_min : Env.Preference.InverseChart ? range_min : range_max);//☆Fibonacci 20180816 コメントアウト
  100. //var y2 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_min : range_max : Env.Preference.InverseChart ? range_max : range_min);//☆Fibonacci 20180816 コメントアウト
  101. //☆Fibonacci 20180816 新規追加ここから
  102. if (_mode != Fibonacci.LineDrawMode.Move && _id < 0)//モードが移動モード、かつ引いたばかりのフィボナッチラインではない
  103. {
  104. //_pivot.Y > _destination.Y は下から上に引いた線の意味
  105. y1 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_max : range_min : Env.Preference.InverseChart ? range_min : range_max);//☆Fibonacci 20180816 変更
  106. y2 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_min : range_max : Env.Preference.InverseChart ? range_max : range_min);//☆Fibonacci 20180816 変更
  107. }
  108. else
  109. {
  110. y1 = _pivot.Y < _destination.Y ? Env.Preference.InverseChart ? _pivot.Y : _destination.Y : Env.Preference.InverseChart ? _destination.Y : _pivot.Y;
  111. y2 = _pivot.Y < _destination.Y ? Env.Preference.InverseChart ? _destination.Y : _pivot.Y : Env.Preference.InverseChart ? _pivot.Y : _destination.Y;
  112. }
  113. //ここまで
  114. //_pivot = new PointF(x1, (float)y1);//☆Fibonacci 20180816 コメントアウト
  115. //_destination = new PointF(x2, (float)y2);//☆Fibonacci 20180816 コメントアウト
  116. _pivot = new PointF(_pivot.X < _destination.X ? Math.Min(x1, x2) : Math.Max(x1, x2), _pivot.Y < _destination.Y ? (float)Math.Min(y1, y2) : (float)Math.Max(y1, y2));//☆Fibonacci 20180816 新規追加
  117. _destination = new PointF(_pivot.X < _destination.X ? Math.Max(x1, x2) : Math.Min(x1, x2), _pivot.Y < _destination.Y ? (float)Math.Max(y1, y2) : (float)Math.Min(y1, y2));//☆Fibonacci 20180816 新規追加
  118. }
  119. private double Max(DataFarm farm, int ind1, int ind2)
  120. {
  121. var pos = ind1;
  122. var max = double.MinValue;
  123. var last = ind2 > farm.FilledLength ? farm.FilledLength - 1 : ind2;
  124. try
  125. {
  126. while (pos <= last)
  127. {
  128. var a = BitConverter.ToInt32(farm.RawDataImage, pos * 32 + 4 * 2) * farm.Brand.PriceScale / (Env.Preference.AdjustSplit ? farm.CalcSplitRatio(BitConverter.ToInt32(farm.RawDataImage, pos * 32)) : 1);
  129. //Console.WriteLine(pos);
  130. if (max < a) max = a;
  131. pos++;
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. Console.WriteLine(ex.Message);
  137. }
  138. return max;
  139. }
  140. private double Min(DataFarm farm, int ind1, int ind2)
  141. {
  142. var pos = ind1;
  143. var min = double.MaxValue;
  144. var last = ind2 > farm.FilledLength ? farm.FilledLength - 1 : ind2;
  145. while (pos <= last)
  146. {
  147. var a = BitConverter.ToInt32(farm.RawDataImage, pos * 32 + 4 * 3) * farm.Brand.PriceScale / (Env.Preference.AdjustSplit ? farm.CalcSplitRatio(BitConverter.ToInt32(farm.RawDataImage, pos * 32)) : 1);
  148. if (min > a) min = a;
  149. pos++;
  150. }
  151. return min;
  152. }
  153. public Rectangle GetInclusion(Rectangle rect)
  154. {
  155. if (_pivot == _destination)
  156. return new Rectangle(new Point((int)_pivot.X, (int)_pivot.Y), new Size(0, 0));
  157. Point[] es = GetEdge(rect, new Point((int)_pivot.X, (int)_pivot.Y), new Point((int)_destination.X, (int)_destination.Y));
  158. return new Rectangle(Math.Min(es[0].X, es[1].X), Math.Min(es[0].Y, es[1].Y), Math.Abs(es[0].X - es[1].X), Math.Abs(es[0].Y - es[1].Y));
  159. }
  160. //十分に離した位置でないと線を確定させないようにする
  161. public bool PivotHasEnoughDistanceTo(PointF pt)
  162. {
  163. return Math.Abs(_pivot.X - pt.X) > 10 || Math.Abs(_pivot.Y - pt.Y) > 10;
  164. }
  165. //☆Fibonacci 20180816 Drawはまるまる書き直し ここから
  166. public void Draw(Trans pricetrans, Rectangle rect, IntPtr hdc)
  167. {
  168. Win32.POINT pt = new Win32.POINT();
  169. //Win32.SelectObject(hdc, _mode == LineDrawMode.Normal ? Env.Preference.FibonacciPen.Handle : Env.Preference.FibonacciBoldPen.Handle);//☆Fibonacci 20180816 コメントアウト
  170. var fibo = new double[] { -2.618, -1.618, 0, .236, .382, .5, .618, .764, 1, 1.618, 2.618 };
  171. //var fibo = new double[] { -2.618, 0, .236, .5, .618, 1, 1.618 };
  172. //var fibo = new double[] { 0, .236, .382, .5, .618, .764, 1 };
  173. //var fibo = new double[] { 0, .382, .5, .618, 1 };
  174. foreach (var f in fibo)
  175. {
  176. Win32.SelectObject(hdc, f == 0 ? Env.Preference.FibonacciBoldPen.Handle : f == 1 ? Env.Preference.FibonacciPen.Handle : f == .5 ? Env.Preference.FibonacciPen.Handle : Env.Preference.FibonacciDottedPen.Handle);//☆Fibonacci 20180816 追加
  177. FibonacciDrawLines fdl = new FibonacciDrawLines(_pivot, _destination, f, fibo);
  178. fdl.Draw(pricetrans, rect, hdc, out pt);
  179. }
  180. }//ここまで
  181. //☆Fibonacci 20180816 追加
  182. private void DrawTheLine(IntPtr hdc, float px1, float px2, float py, double kabuka, string text, out Win32.POINT pt)
  183. {
  184. Win32.MoveToEx(hdc, (int)px1, (int)py, out pt);
  185. Win32.LineTo(hdc, (int)px2, (int)py);
  186. DrawText(hdc, (int)px2, (int)py, kabuka);
  187. DrawText(hdc, (int)px1 - 30, (int)py, text);
  188. }
  189. private void DrawText(IntPtr hdc, int x, int y, string s)
  190. {
  191. //☆Fibonacci 20190207
  192. //Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  193. Win32.SetTextColor(hdc, Util.ToCOLORREF(Env.Preference.TextColor));
  194. ChartUtil.DrawText(hdc, x + 3, y - 6, s);
  195. }
  196. private void DrawTheLine(IntPtr hdc, float px1, float px2, float py, double kabuka, out Win32.POINT pt)
  197. {
  198. Win32.MoveToEx(hdc, (int)px1, (int)py, out pt);
  199. Win32.LineTo(hdc, (int)px2, (int)py);
  200. DrawText(hdc, (int)px2, (int)py, kabuka);
  201. }
  202. private void DrawText(IntPtr hdc, int x, int y, double d)
  203. {
  204. //☆Fibonacci 20190207
  205. //Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  206. Win32.SetTextColor(hdc, Util.ToCOLORREF(Env.Preference.TextColor));
  207. ChartUtil.DrawText(hdc, x + 3, y - 6, string.Format("{0:N}", d));
  208. }
  209. //p1,p2がrectに入っているとき、p1からp2に伸ばした線とp2からp1に伸ばした線がそれぞれrectと交差するところを返す
  210. private static Point[] GetEdge(Rectangle rect, Point p1, Point p2)
  211. {
  212. Point[] result = new Point[2];
  213. ArrayList ar = GetAllEdges(rect, p1, p2);
  214. if (ar.Count == 2) return (Point[])ar.ToArray(typeof(Point));
  215. result[0] = (Point)(p1.X > p2.X ? ar[1] : ar[2]);
  216. result[1] = (Point)(p1.X > p2.X ? ar[2] : ar[1]);
  217. return result;
  218. }
  219. //p1とp2を結ぶ線がrectを構成する4直線と交差する点を返す。水平・垂直のときは2個になる
  220. private static ArrayList GetAllEdges(Rectangle rect, Point p1, Point p2)
  221. {
  222. ArrayList ar = new ArrayList();
  223. if (p1.X == p2.X)
  224. {
  225. ar.Add(new Point(p1.X, p1.Y < p2.Y ? rect.Bottom : rect.Top));
  226. ar.Add(new Point(p1.X, p1.Y > p2.Y ? rect.Bottom : rect.Top));
  227. return ar;
  228. }
  229. else if (p1.Y == p2.Y)
  230. {
  231. ar.Add(new Point(p1.X < p2.X ? rect.Right : rect.Left, p1.Y));
  232. ar.Add(new Point(p1.X > p2.X ? rect.Right : rect.Left, p1.Y));
  233. return ar;
  234. }
  235. LinearTrans lt = LinearTrans.Solve(p1.X, p1.Y, p2.X, p2.Y);
  236. ar.Add(new Point(rect.Left, (int)lt.TransValue(rect.Left)));
  237. ar.Add(new Point(rect.Right, (int)lt.TransValue(rect.Right)));
  238. ar.Add(new Point((int)lt.Inverse(rect.Top), rect.Top));
  239. ar.Add(new Point((int)lt.Inverse(rect.Bottom), rect.Bottom));
  240. //この4点をX座標の順に並べ、2番目と3番目が答え
  241. ar.Sort(new PointComparer());
  242. return ar;
  243. }
  244. private class PointComparer : IComparer
  245. {
  246. public int Compare(object x, object y)
  247. {
  248. return ((Point)x).X - ((Point)y).X;
  249. }
  250. }
  251. public SolidFibonacci ToSolid(DataFarm farm, int firstdateindex, Trans value_to_y)
  252. {
  253. SolidFibonacci fl = new SolidFibonacci();
  254. int ind1 = firstdateindex + (int)Math.Floor((double)_pivot.X / Env.Layout.DatePitch);
  255. int ind2 = firstdateindex + (int)Math.Floor((double)_destination.X / Env.Layout.DatePitch);
  256. LinearTrans tr = LinearTrans.Solve(ind1, _pivot.Y, ind2, _destination.Y);
  257. double y1 = _pivot.Y;
  258. if (ind1 >= farm.FilledLength)
  259. {
  260. ind1 = farm.FilledLength - 1;
  261. //y1 = tr.TransValue(ind1);//☆Fibonacci 20180816 コメントアウト freelineと違ってy軸、つまり株価は移動しなくていい
  262. }
  263. else if (ind1 < 0)
  264. {
  265. ind1 = 0;
  266. y1 = tr.TransValue(ind1);
  267. }
  268. fl._date1 = farm.GetByIndex(ind1).Date;
  269. fl._value1 = value_to_y.Inverse(y1);
  270. double y2 = _destination.Y;
  271. if (ind2 >= farm.FilledLength)
  272. {
  273. ind2 = farm.FilledLength - 1;
  274. //y2 = tr.TransValue(ind2);//☆Fibonacci 20180816 コメントアウト freelineと違ってy軸、つまり株価は移動しなくていい
  275. }
  276. else if (ind2 < 0)
  277. {
  278. ind2 = 0;
  279. y2 = tr.TransValue(0);
  280. }
  281. fl._date2 = farm.GetByIndex(ind2).Date;
  282. fl._value2 = value_to_y.Inverse(y2);
  283. //_id==-1は作ったばかりのフィボナッチで、0以上は既存フィボナッチ
  284. if (_id == -1)
  285. {
  286. fl._id = SolidFibonacci.NextID++;
  287. _id = fl._id;
  288. }
  289. else
  290. {
  291. fl._id = _id;
  292. }
  293. return fl;
  294. }
  295. //☆Fibonacci 20180816 変更 GetDistanceは全面的に書き直し
  296. public double GetDistance(Point p)
  297. {
  298. return Math.Min(GetDistanceUpside(p), GetDistanceDownside(p));
  299. }
  300. //☆Fibonacci 20180816 新規
  301. //最上部のフィボナッチラインとマウスカーソルとの直線距離
  302. //マウスカーソルがフィボナッチラインの幅内にあった場合のみ、マウスカーソルと最上部フィボナッチラインの縦幅を計測して返す
  303. public double GetDistanceUpside(Point p)
  304. {
  305. var y = Math.Min(_pivot.Y, _destination.Y);
  306. var xl = Math.Min(_pivot.X, _destination.X);
  307. var xr = Math.Max(_pivot.X, _destination.X);
  308. return (p.X < xl || xr < p.X) ? double.MaxValue : Math.Abs(y - p.Y);
  309. }
  310. //☆Fibonacci 20180816 新規
  311. //最下部のフィボナッチラインとマウスカーソルとの直線距離
  312. //マウスカーソルがフィボナッチラインの幅内にあった場合のみ、マウスカーソルと最下部フィボナッチラインの縦幅を計測して返す
  313. public double GetDistanceDownside(Point p)
  314. {
  315. var y = Math.Max(_pivot.Y, _destination.Y);
  316. var xl = Math.Min(_pivot.X, _destination.X);
  317. var xr = Math.Max(_pivot.X, _destination.X);
  318. return (p.X < xl || xr < p.X) ? double.MaxValue : Math.Abs(y - p.Y);
  319. }
  320. //両端を通る直線を ax+by+c=0, a^2+b^2=1 となる形式でa,b,cの配列で返す
  321. private double[] GetNormalizedParam()
  322. {
  323. double a, b, c;
  324. if (_pivot.X == _destination.X)
  325. {
  326. a = 1;
  327. b = 0;
  328. }
  329. else
  330. {
  331. double d = -(_pivot.Y - _destination.Y) / (double)(_pivot.X - _destination.X);
  332. b = Math.Sqrt(1 / (1 + d * d));
  333. a = b * d;
  334. }
  335. c = -(a * _pivot.X + b * _pivot.Y);
  336. return new double[] { a, b, c };
  337. }
  338. }
  339. internal class SolidFibonacci
  340. {
  341. public int _id;
  342. public int _code;
  343. public ChartFormat _targetFormat;
  344. public bool _logScale;
  345. public int _date1;
  346. public double _value1;
  347. public int _date2;
  348. public double _value2;
  349. private static int _nextID;
  350. public static int NextID
  351. {
  352. get
  353. {
  354. return _nextID;
  355. }
  356. set
  357. {
  358. _nextID = value;
  359. }
  360. }
  361. }
  362. internal class FibonacciCollection
  363. {
  364. private ArrayList _data;
  365. public FibonacciCollection()
  366. {
  367. _data = new ArrayList();
  368. }
  369. public int Count
  370. {
  371. get
  372. {
  373. return _data.Count;
  374. }
  375. }
  376. public void Add(AbstractBrand br, ChartFormat format, bool logScale, SolidFibonacci fl)
  377. {
  378. fl._code = br.Code;
  379. fl._targetFormat = format;
  380. fl._logScale = logScale;
  381. _data.Add(fl);
  382. }
  383. public SolidFibonacci[] Find(AbstractBrand br, ChartFormat format, bool logScale)
  384. {
  385. ArrayList t = new ArrayList();
  386. foreach (SolidFibonacci fl in _data)
  387. {
  388. if (fl._code == br.Code && fl._targetFormat == format && fl._logScale == logScale)
  389. t.Add(fl);
  390. }
  391. return (SolidFibonacci[])t.ToArray(typeof(SolidFibonacci));
  392. }
  393. public void ClearAll()
  394. {
  395. _data.Clear();
  396. }
  397. public void Clear(AbstractBrand br, ChartFormat format, bool logScale)
  398. {
  399. ArrayList temp = new ArrayList();
  400. IEnumerator ie = _data.GetEnumerator();
  401. while (ie.MoveNext())
  402. {
  403. SolidFibonacci fl = (SolidFibonacci)ie.Current;
  404. if (!(fl._code == br.Code && fl._targetFormat == format && fl._logScale == logScale))
  405. temp.Add(fl);
  406. }
  407. _data = temp;
  408. }
  409. public void Remove(int id)
  410. {
  411. for (int i = 0; i < _data.Count; i++)
  412. {
  413. SolidFibonacci l = (SolidFibonacci)_data[i];
  414. if (l._id == id)
  415. {
  416. _data.RemoveAt(i);
  417. break;
  418. }
  419. }
  420. }
  421. public void Load(StorageNode parent)
  422. {
  423. string t = parent["fibonacci-lines"];
  424. if (t == null) return;
  425. foreach (string ee in t.Split(','))
  426. {
  427. if (ee == null) continue;
  428. if (ee.Trim() == string.Empty) continue;
  429. SolidFibonacci fl = new SolidFibonacci();
  430. string[] e = ee.Split(':');
  431. fl._code = Int32.Parse(e[0]);
  432. switch (e[1])
  433. {
  434. case "D":
  435. fl._targetFormat = ChartFormat.Daily;
  436. fl._logScale = false;
  437. break;
  438. case "W":
  439. fl._targetFormat = ChartFormat.Weekly;
  440. fl._logScale = false;
  441. break;
  442. case "M":
  443. fl._targetFormat = ChartFormat.Monthly;
  444. fl._logScale = false;
  445. break;
  446. case "Y":
  447. fl._targetFormat = ChartFormat.Yearly;
  448. fl._logScale = false;
  449. break;
  450. case "DL":
  451. fl._targetFormat = ChartFormat.Daily;
  452. fl._logScale = true;
  453. break;
  454. case "WL":
  455. fl._targetFormat = ChartFormat.Weekly;
  456. fl._logScale = true;
  457. break;
  458. case "ML":
  459. fl._targetFormat = ChartFormat.Monthly;
  460. fl._logScale = true;
  461. break;
  462. case "YL":
  463. fl._targetFormat = ChartFormat.Yearly;
  464. fl._logScale = true;
  465. break;
  466. }
  467. fl._date1 = Int32.Parse(e[2]);
  468. fl._value1 = Double.Parse(e[3]);
  469. fl._date2 = Int32.Parse(e[4]);
  470. fl._value2 = Double.Parse(e[5]);
  471. fl._id = SolidFibonacci.NextID++;
  472. _data.Add(fl);
  473. }
  474. }
  475. public void SaveTo(StorageNode parent)
  476. {
  477. StringBuilder bld = new StringBuilder();
  478. foreach (SolidFibonacci sl in _data)
  479. {
  480. if (bld.Length > 0) bld.Append(",");
  481. String format;
  482. switch (sl._targetFormat)
  483. {
  484. case ChartFormat.Daily:
  485. default:
  486. format = "D";
  487. break;
  488. case ChartFormat.Weekly:
  489. format = "W";
  490. break;
  491. case ChartFormat.Monthly:
  492. format = "M";
  493. break;
  494. case ChartFormat.Yearly:
  495. format = "Y";
  496. break;
  497. }
  498. if (sl._logScale)
  499. {
  500. format += "L";
  501. }
  502. bld.Append(String.Format("{0}:{1}:{2}:{3:F2}:{4}:{5:F2}", sl._code, format, sl._date1, sl._value1, sl._date2, sl._value2));
  503. }
  504. parent["fibonacci-lines"] = bld.ToString();
  505. }
  506. }
  507. //☆Fibonacci 20180816 新規追加
  508. internal class FibonacciDrawLines
  509. {
  510. //☆Fibonacci 20190207
  511. const bool SORTING = true;//起点ラインを100%終点ラインを0%と表示⇒true、起点ラインを0%終点ラインを100%と表示⇒false
  512. PointF _pivot;
  513. PointF _dest;
  514. double _fibopos = .0;
  515. double[] _fibonacci;
  516. string _text = string.Empty;
  517. public FibonacciDrawLines(PointF pivot, PointF dest, double fibopos, double[] fibonacci)
  518. {
  519. _pivot = pivot;
  520. _dest = dest;
  521. _fibopos = fibopos;
  522. _fibonacci = fibonacci;
  523. }
  524. public void Draw(Trans pricetrans, Rectangle rect, IntPtr hdc, out Win32.POINT pt)
  525. {
  526. var k = retKabuka(pricetrans);
  527. var y = (int)pricetrans.TransValue(k);//☆Fibonacci 20190207
  528. Win32.MoveToEx(hdc, (int)Math.Min(_pivot.X, _dest.X), y, out pt);
  529. Win32.LineTo(hdc, (int)Math.Max(_pivot.X, _dest.X), y);
  530. DrawText(hdc, (int)Math.Max(_pivot.X, _dest.X), y, k);
  531. DrawText(hdc, (int)Math.Min(_pivot.X, _dest.X) - 30, y, retText());
  532. }
  533. //☆Fibonacci 20190207 丸々書き換え
  534. private string retText()
  535. {
  536. //var per = "%";//%を付けたい人はここに書き込む
  537. var per = "";//%を付けたい人はここに書き込む
  538. return
  539. SORTING ?//起点ラインが100%終点ラインが0%表示
  540. _fibopos == 0 ?
  541. _pivot.Y < _dest.Y ?
  542. "100" + per : "0" + per
  543. : _fibopos == 1 ?
  544. _pivot.Y < _dest.Y ?
  545. "0" + per : "100" + per
  546. : string.Format("{0:00.0}{1}", _fibopos * 100, per)//天底以外の数値(0.618とか)はretKabukaでハンドリングするのでここでは逆転させない
  547. //起点ラインが0%終点ラインが100%表示
  548. : _fibopos == 0 ?
  549. _pivot.Y < _dest.Y ?
  550. "0" + per : "100" + per
  551. : _fibopos == 1 ?
  552. _pivot.Y < _dest.Y ?
  553. "100" + per : "0" + per
  554. : string.Format("{0:00.0}", _fibopos * 100);//天底以外の数値(0.618とか)はretKabukaでハンドリングするのでここでは逆転させない
  555. }
  556. //☆Fibonacci 20190207 丸々書き換え
  557. private double retKabuka(Trans pricetrans)
  558. {
  559. if (_fibopos == 0)
  560. return pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y));
  561. else if (_fibopos == 1)
  562. return pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y));
  563. else if (_fibopos < 0)
  564. return pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y) + Math.Abs(_pivot.Y - _dest.Y) * _fibopos);
  565. else
  566. return pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y) + Math.Abs(_pivot.Y - _dest.Y) * _fibopos);
  567. }
  568. private void DrawText(IntPtr hdc, int x, int y, string s)
  569. {
  570. //☆Fibonacci 20190207
  571. //Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  572. Win32.SetTextColor(hdc, Util.ToCOLORREF(Env.Preference.TextColor));
  573. ChartUtil.DrawText(hdc, x + 3, y - 6, s);
  574. }
  575. private void DrawText(IntPtr hdc, int x, int y, double d)
  576. {
  577. //☆Fibonacci 20190207
  578. //Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  579. Win32.SetTextColor(hdc, Util.ToCOLORREF(Env.Preference.TextColor));
  580. ChartUtil.DrawText(hdc, x + 3, y - 6, string.Format("{0:N}", d));
  581. }
  582. }
  583. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト