hqchart 1.1.12687 → 1.1.12706

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/lib/umychart.vue.js +94 -50
  2. package/package.json +15 -47
  3. package/src/jscommon/umychart.resource/js/codemirror/javascript.js +1 -1
  4. package/src/jscommon/umychart.uniapp.h5/umychart.uniapp.h5.js +409 -115
  5. package/src/jscommon/umychart.vue/umychart.vue.js +409 -115
  6. package/.babelrc +0 -6
  7. package/.vscode/settings.json +0 -4
  8. package/Makefile +0 -9
  9. package/README.md +0 -452
  10. package/index.js +0 -17
  11. package/postcss.config.js +0 -5
  12. package/src/index.html +0 -18
  13. package/src/jscommon/backup/announcement.png +0 -0
  14. package/src/jscommon/backup/announcement2.png +0 -0
  15. package/src/jscommon/backup/blocktrading.png +0 -0
  16. package/src/jscommon/backup/investor.png +0 -0
  17. package/src/jscommon/backup/pforecast.png +0 -0
  18. package/src/jscommon/backup/research.png +0 -0
  19. package/src/jscommon/backup/tradedetail.png +0 -0
  20. package/src/jscommon/backup/umychart - backup.js +0 -17631
  21. package/src/jscommon/backup/umychart.macro.js +0 -4
  22. package/src/jscommon/backup/umychart.macro.vue.js +0 -3
  23. package/src/jscommon/commonindextree.json +0 -92
  24. package/src/jscommon/index.html +0 -13
  25. package/src/jscommon/jschinamapdata.js +0 -3
  26. package/src/jscommon/umychart.NetworkFilterTest.js +0 -48803
  27. package/src/jscommon/umychart.aliYunnetwork.js +0 -47
  28. package/src/jscommon/umychart.cninfo.components/readme.txt +0 -1
  29. package/src/jscommon/umychart.complier.js +0 -25291
  30. package/src/jscommon/umychart.complier.node/umychart.complier.controller.js +0 -559
  31. package/src/jscommon/umychart.complier.node/umychart.complier.node.js +0 -7043
  32. package/src/jscommon/umychart.complier.node/umychart.data.node.js +0 -816
  33. package/src/jscommon/umychart.console.js +0 -12
  34. package/src/jscommon/umychart.deal.js +0 -1452
  35. package/src/jscommon/umychart.dragdiv.js +0 -48
  36. package/src/jscommon/umychart.index.data.js +0 -4132
  37. package/src/jscommon/umychart.js +0 -90257
  38. package/src/jscommon/umychart.keyboard.js +0 -1659
  39. package/src/jscommon/umychart.listctrl.js +0 -690
  40. package/src/jscommon/umychart.mind.js +0 -2203
  41. package/src/jscommon/umychart.network.js +0 -44
  42. package/src/jscommon/umychart.news.js +0 -823
  43. package/src/jscommon/umychart.node.build/buildall.bat +0 -1
  44. package/src/jscommon/umychart.node.build/umychart.node.bat +0 -1
  45. package/src/jscommon/umychart.node.build/umychart.node.export.js +0 -40
  46. package/src/jscommon/umychart.regressiontest.js +0 -400
  47. package/src/jscommon/umychart.report.js +0 -5803
  48. package/src/jscommon/umychart.scrollbar.js +0 -1345
  49. package/src/jscommon/umychart.stock.js +0 -4218
  50. package/src/jscommon/umychart.style.js +0 -618
  51. package/src/jscommon/umychart.testdata.js +0 -150
  52. package/src/jscommon/umychart.uniapp.build/buildall.bat +0 -1
  53. package/src/jscommon/umychart.uniapp.build/umychart.bat +0 -1
  54. package/src/jscommon/umychart.uniapp.build/umychart.export.js +0 -70
  55. package/src/jscommon/umychart.user.js +0 -137
  56. package/src/jscommon/umychart.version.js +0 -30
  57. package/src/jscommon/umychart.vue/umychart.aliYunnetwork.vue.js +0 -56
  58. package/src/jscommon/umychart.vue.build/buildall.bat +0 -4
  59. package/src/jscommon/umychart.vue.build/copy_codemirror.bat +0 -2
  60. package/src/jscommon/umychart.vue.build/umychart.aliYunnetwork.vue.export.js +0 -9
  61. package/src/jscommon/umychart.vue.build/umychart.dragdiv.bat +0 -1
  62. package/src/jscommon/umychart.vue.build/umychart.dragdiv.export.js +0 -6
  63. package/src/jscommon/umychart.vue.build/umychart.index.data.bat +0 -1
  64. package/src/jscommon/umychart.vue.build/umychart.index.data.export.js +0 -4
  65. package/src/jscommon/umychart.vue.build/umychart.listctrl.vue.export.js +0 -15
  66. package/src/jscommon/umychart.vue.build/umychart.regressiontest.vue.export.js +0 -7
  67. package/src/jscommon/umychart.vue.build/umychart.regressiontest.wechat.export.js +0 -12
  68. package/src/jscommon/umychart.vue.build/umychart.stock.bat +0 -1
  69. package/src/jscommon/umychart.vue.build/umychart.stock.vue.export.js +0 -16
  70. package/src/jscommon/umychart.vue.build/umychart.testdata.bat +0 -3
  71. package/src/jscommon/umychart.vue.build/umychart.testdata.vue.export.js +0 -7
  72. package/src/jscommon/umychart.vue.build/umychart.vue.bat +0 -8
  73. package/src/jscommon/umychart.vue.build/umychart.vue.export.js +0 -112
  74. package/src/jscommon/umychart.vue.components/empyt.vue +0 -51
  75. package/src/jscommon/umychart.vue.components/historydayline.vue +0 -240
  76. package/src/jscommon/umychart.vue.components/jsloader.adddialog.vue +0 -315
  77. package/src/jscommon/umychart.vue.components/jsloader.vue +0 -93
  78. package/src/jscommon/umychart.vue.components/jsvuecontainer.vue +0 -160
  79. package/src/jscommon/umychart.vue.components/jsvuecontainer2.0.vue +0 -391
  80. package/src/jscommon/umychart.vue.components/login.vue +0 -178
  81. package/src/jscommon/umychart.vue.components/queryContent.vue +0 -750
  82. package/src/jscommon/umychart.vue.components/readme.txt +0 -8
  83. package/src/jscommon/umychart.vue.components/searchsymbol.vue +0 -299
  84. package/src/jscommon/umychart.vue.components/simulatetrade.vue +0 -1471
  85. package/src/jscommon/umychart.vue.components/stockchart.vue +0 -343
  86. package/src/jscommon/umychart.vue.components/stockchartV2.vue +0 -195
  87. package/src/jscommon/umychart.vue.components/stockdeal.vue +0 -358
  88. package/src/jscommon/umychart.vue.components/stockdealcount.vue +0 -262
  89. package/src/jscommon/umychart.vue.components/stockdeallastest.vue +0 -316
  90. package/src/jscommon/umychart.vue.components/stockdrawtool.vue +0 -343
  91. package/src/jscommon/umychart.vue.components/stockfull.vue +0 -355
  92. package/src/jscommon/umychart.vue.components/stockinfo.demo.vue +0 -153
  93. package/src/jscommon/umychart.vue.components/stockinfo.vue +0 -685
  94. package/src/jscommon/umychart.vue.components/stockkline.demo.vue +0 -1904
  95. package/src/jscommon/umychart.vue.components/stockmultiorder.vue +0 -174
  96. package/src/jscommon/umychart.vue.components/stockmultiperiod.vue +0 -222
  97. package/src/jscommon/umychart.vue.components/stockorder.vue +0 -320
  98. package/src/jscommon/umychart.vue.components/stocktradeinfo.demo.vue +0 -250
  99. package/src/jscommon/umychart.vue.components/stocktradeinfo.vue +0 -1907
  100. package/src/jscommon/umychart.vue.components/test.vue +0 -0
  101. package/src/jscommon/umychart.wechat/getDate.wechat.js +0 -91
  102. package/src/jscommon/umychart.wechat/lighter.news.wechat.js +0 -262
  103. package/src/jscommon/umychart.wechat/readme.txt +0 -3
  104. package/src/jscommon/umychart.wechat/umychart.analyze.wechat.js +0 -551
  105. package/src/jscommon/umychart.wechat/umychart.apidraw.wechat.js +0 -126
  106. package/src/jscommon/umychart.wechat/umychart.bigV.wechat.js +0 -2510
  107. package/src/jscommon/umychart.wechat/umychart.chartframe.wechat.js +0 -2931
  108. package/src/jscommon/umychart.wechat/umychart.chartpaint.wechat.js +0 -9752
  109. package/src/jscommon/umychart.wechat/umychart.charttitle.wechat.js +0 -2023
  110. package/src/jscommon/umychart.wechat/umychart.complier.wechat.js +0 -14726
  111. package/src/jscommon/umychart.wechat/umychart.console.wechat.js +0 -8
  112. package/src/jscommon/umychart.wechat/umychart.coordinatedata.wechat.js +0 -3654
  113. package/src/jscommon/umychart.wechat/umychart.data.wechat.js +0 -2243
  114. package/src/jscommon/umychart.wechat/umychart.element.wechart.js +0 -132
  115. package/src/jscommon/umychart.wechat/umychart.explainer.wechat.js +0 -1077
  116. package/src/jscommon/umychart.wechat/umychart.extendchart.wechat.js +0 -1140
  117. package/src/jscommon/umychart.wechat/umychart.framesplit.wechat.js +0 -2247
  118. package/src/jscommon/umychart.wechat/umychart.hqIndexformula.wechat.js +0 -941
  119. package/src/jscommon/umychart.wechat/umychart.index.data.wechat.js +0 -3628
  120. package/src/jscommon/umychart.wechat/umychart.index.wechat.js +0 -4074
  121. package/src/jscommon/umychart.wechat/umychart.klineinfo.wechat.js +0 -836
  122. package/src/jscommon/umychart.wechat/umychart.markethot.js +0 -50
  123. package/src/jscommon/umychart.wechat/umychart.network.wechart.js +0 -62
  124. package/src/jscommon/umychart.wechat/umychart.news.wechat.js +0 -3568
  125. package/src/jscommon/umychart.wechat/umychart.regressiontest.wechat.js +0 -412
  126. package/src/jscommon/umychart.wechat/umychart.report.wechat.js +0 -3983
  127. package/src/jscommon/umychart.wechat/umychart.resource.wechat.js +0 -919
  128. package/src/jscommon/umychart.wechat/umychart.shareimage.wechat.js +0 -681
  129. package/src/jscommon/umychart.wechat/umychart.simulatetrade.wechat.js +0 -238
  130. package/src/jscommon/umychart.wechat/umychart.stock.wechat.js +0 -4035
  131. package/src/jscommon/umychart.wechat/umychart.style.wechat.js +0 -419
  132. package/src/jscommon/umychart.wechat/umychart.uniapp.canvas.helper.js +0 -99
  133. package/src/jscommon/umychart.wechat/umychart.user.wechat.js +0 -588
  134. package/src/jscommon/umychart.wechat/umychart.userlog.wechat.js +0 -240
  135. package/src/jscommon/umychart.wechat/umychart.vedio.wechat.js +0 -112
  136. package/src/jscommon/umychart.wechat/umychart.version.wechat.js +0 -36
  137. package/src/jscommon/umychart.wechat/umychart.wechat.3.0.js +0 -12051
  138. package/src/jscommon/umychart.wechat/umychart.wechat.js +0 -15460
  139. package/src/jscommon/umychart.worker.js +0 -114
  140. package/src/jscommon/umychart.ws.stock.js +0 -110
  141. package/src/jscommon/umychart_python/.vscode/launch.json +0 -15
  142. package/src/jscommon/umychart_python/__init__.py +0 -4
  143. package/src/jscommon/umychart_python/build.cmd +0 -2
  144. package/src/jscommon/umychart_python/setup.py +0 -25
  145. package/src/jscommon/umychart_python/umychart_cache_testcase.py +0 -165
  146. package/src/jscommon/umychart_python/umychart_complier_data.py +0 -781
  147. package/src/jscommon/umychart_python/umychart_complier_help.py +0 -175
  148. package/src/jscommon/umychart_python/umychart_complier_job.py +0 -193
  149. package/src/jscommon/umychart_python/umychart_complier_jsalgorithm.py +0 -4144
  150. package/src/jscommon/umychart_python/umychart_complier_jscomplier.py +0 -177
  151. package/src/jscommon/umychart_python/umychart_complier_jsexecute.py +0 -517
  152. package/src/jscommon/umychart_python/umychart_complier_jsparser.py +0 -864
  153. package/src/jscommon/umychart_python/umychart_complier_jssymboldata.py +0 -1238
  154. package/src/jscommon/umychart_python/umychart_complier_jssymboldata_cache.py +0 -146
  155. package/src/jscommon/umychart_python/umychart_complier_jssymboldata_json.py +0 -106
  156. package/src/jscommon/umychart_python/umychart_complier_pandas_help.py +0 -80
  157. package/src/jscommon/umychart_python/umychart_complier_scanner.py +0 -554
  158. package/src/jscommon/umychart_python/umychart_complier_testcase.py +0 -362
  159. package/src/jscommon/umychart_python/umychart_complier_util.py +0 -30
  160. package/src/jscommon/umychart_python/umychart_webtemplate.py +0 -131
  161. package/src/jscommon/umychart_python/updatehqchartweb.bat +0 -5
  162. package/src/jscommon/vendor.js +0 -2
  163. package/src/pages/block.list.demo.page/App.vue +0 -117
  164. package/src/pages/block.list.demo.page/index.js +0 -12
  165. package/src/pages/brushTool.demo.page/App.vue +0 -19
  166. package/src/pages/brushTool.demo.page/index.js +0 -12
  167. package/src/pages/container.demo.page/App.vue +0 -118
  168. package/src/pages/container.demo.page/index.js +0 -18
  169. package/src/pages/dataZoom.demo.page/App.vue +0 -265
  170. package/src/pages/dataZoom.demo.page/components/dataZoom.vue +0 -303
  171. package/src/pages/dataZoom.demo.page/index.js +0 -12
  172. package/src/pages/historydayline.demo.page/App.vue +0 -57
  173. package/src/pages/historydayline.demo.page/index.js +0 -12
  174. package/src/pages/hq.demo.page/App.vue +0 -163
  175. package/src/pages/hq.demo.page/index.js +0 -12
  176. package/src/pages/hqchart.black/App.vue +0 -90
  177. package/src/pages/hqchart.black/components/searchsymbol.vue +0 -299
  178. package/src/pages/hqchart.black/components/stockdrawtool.vue +0 -300
  179. package/src/pages/hqchart.black/components/stockfull.vue +0 -313
  180. package/src/pages/hqchart.black/components/stockinfo.vue +0 -428
  181. package/src/pages/hqchart.black/components/stockkline.demo.vue +0 -1652
  182. package/src/pages/hqchart.black/components/stocktradeinfo.vue +0 -1337
  183. package/src/pages/hqchart.black/index.js +0 -30
  184. package/src/pages/hqchart.black/router/candlestickChart.vue +0 -108
  185. package/src/pages/hqchart.black/router/pricePointsTable.vue +0 -294
  186. package/src/pages/hqchart.black/router/stockDeallas.vue +0 -417
  187. package/src/pages/hqchart.black/router/timeShareChart.vue +0 -108
  188. package/src/pages/hqchart.page/App.vue +0 -101
  189. package/src/pages/hqchart.page/index.js +0 -18
  190. package/src/pages/index/App.vue +0 -1408
  191. package/src/pages/index/index.js +0 -7
  192. package/src/pages/indexHq/App.vue +0 -110
  193. package/src/pages/indexHq/index.js +0 -18
  194. package/src/pages/login.demo.page/App.vue +0 -22
  195. package/src/pages/login.demo.page/index.js +0 -12
  196. package/src/pages/queryContent.demo.page/App.vue +0 -29
  197. package/src/pages/queryContent.demo.page/index.js +0 -18
  198. package/src/pages/ranking.black/App.vue +0 -199
  199. package/src/pages/ranking.black/index.js +0 -18
  200. package/src/pages/search.demo.page/App.vue +0 -28
  201. package/src/pages/search.demo.page/index.js +0 -12
  202. package/src/pages/simulatetrade.demo.page/app.vue +0 -121
  203. package/src/pages/simulatetrade.demo.page/index.js +0 -17
  204. package/src/pages/stockdeal.demo.page/App.vue +0 -63
  205. package/src/pages/stockdeal.demo.page/index.js +0 -19
  206. package/src/pages/stockdealcount.demo.page/App.vue +0 -37
  207. package/src/pages/stockdealcount.demo.page/index.js +0 -12
  208. package/src/pages/stockdeallastest.demo.page/App.vue +0 -74
  209. package/src/pages/stockdeallastest.demo.page/index.js +0 -18
  210. package/src/pages/stockinfo.demo.page/App.vue +0 -92
  211. package/src/pages/stockinfo.demo.page/index.html +0 -13
  212. package/src/pages/stockinfo.demo.page/index.js +0 -19
  213. package/src/pages/stockkline.demo.page/App.vue +0 -55
  214. package/src/pages/stockkline.demo.page/index.js +0 -18
  215. package/src/pages/stockmultiorder.demo.page/App.vue +0 -149
  216. package/src/pages/stockmultiorder.demo.page/index.js +0 -18
  217. package/src/pages/stockmultiperiod.demo.page/App.vue +0 -87
  218. package/src/pages/stockmultiperiod.demo.page/index.js +0 -18
  219. package/src/pages/stockorder.demo.page/App.vue +0 -69
  220. package/src/pages/stockorder.demo.page/index.js +0 -18
  221. package/src/pages/test/App.vue +0 -22
  222. package/src/pages/test/index.js +0 -7
  223. package/src/pages/tradeinfopage/app.vue +0 -40
  224. package/src/pages/tradeinfopage/index.js +0 -7
  225. package/src/pages/tradeinfopage/tradeinfo.html +0 -12
  226. package/src/utils/urlObj.js +0 -81
  227. package/src/vendor.js +0 -2
  228. package/webpack.config.js +0 -104
@@ -1,2931 +0,0 @@
1
- /*
2
- copyright (c) 2018 jones
3
-
4
- http://www.apache.org/licenses/LICENSE-2.0
5
-
6
- 开源项目 https://github.com/jones2000/HQChart
7
-
8
- jones_2000@163.com
9
-
10
- 指标窗口
11
- */
12
-
13
- //日志
14
- import { JSConsole } from "./umychart.console.wechat.js"
15
-
16
- import
17
- {
18
- g_JSChartResource,
19
- JSCHART_LANGUAGE_ID,
20
- g_JSChartLocalization,
21
- } from './umychart.resource.wechat.js'
22
-
23
- import
24
- {
25
- Guid,
26
- JSCHART_EVENT_ID,
27
- ToFixedPoint,
28
- ToFixedRect,
29
- } from "./umychart.data.wechat.js";
30
-
31
- import
32
- {
33
- CoordinateInfo,
34
- IFrameSplitOperator,
35
- FrameSplitKLinePriceY,
36
- FrameSplitY,
37
- FrameSplitKLineX,
38
- FrameSplitMinutePriceY,
39
- FrameSplitMinuteX,
40
- FrameSplitXData,
41
- SplitData,
42
- PriceSplitData,
43
- FrameSplitXDepth,
44
-
45
- IChangeStringFormat,
46
- HQPriceStringFormat,
47
- HQDateStringFormat,
48
- HQMinuteTimeStringFormat,
49
- g_DivTooltipDataForamt,
50
- } from './umychart.framesplit.wechat.js'
51
-
52
-
53
- function IChartFramePainting()
54
- {
55
- this.HorizontalInfo = new Array(); //Y轴
56
- this.VerticalInfo = new Array(); //X轴
57
- this.ClassName='IChartFramePainting';
58
- this.Canvas; //画布
59
-
60
- this.Identify; //窗口标识
61
-
62
- this.ChartBorder;
63
- this.PenBorder = g_JSChartResource.FrameBorderPen; //边框颜色
64
- this.TitleBGColor = g_JSChartResource.FrameTitleBGColor; //标题背景色
65
- this.IsShow = true; //是否显示
66
- this.SizeChange = true; //大小是否改变
67
- this.XYSplit = true; //XY轴坐标信息改变
68
-
69
- this.HorizontalMax; //Y轴最大值
70
- this.HorizontalMin; //Y轴最小值
71
- this.XPointCount = 10; //X轴数据个数
72
- this.YMaxMin={ Max:null, Min:null }; //Y轴原始的最大值 最小值
73
-
74
- this.YSplitOperator; //Y轴分割
75
- this.XSplitOperator; //X轴分割
76
- this.Data; //主数据
77
-
78
- this.YSpecificMaxMin = null; //指定Y轴最大最小值
79
- this.YSplitScale=null; //固定分割刻度数组 [2,5,8]
80
-
81
- this.IsShowBorder = true; //是否显示边框
82
- this.IsShowIndexName = true; //是否显示指标名字
83
- this.IndexParamSpace = 2; //指标参数数值显示间距
84
- this.IndexTitleSpace=0; //指标标题到参数之间的间距
85
-
86
- //上锁信息
87
- this.IsLocked = false; //是否上锁
88
- this.LockPaint = null;
89
-
90
- this.BorderLine=null; //1=上 2=下 4=左 8=右
91
- this.IsMinSize=false; //窗口是否最小化
92
-
93
- this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
94
- this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
95
-
96
- this.Draw = function ()
97
- {
98
- this.DrawFrame();
99
- this.DrawBorder();
100
-
101
- this.SizeChange = false;
102
- this.XYSplit = false;
103
- }
104
-
105
- this.DrawFrame = function () { }
106
-
107
- this.GetBorder=function()
108
- {
109
- if (this.IsHScreen) return this.ChartBorder.GetHScreenBorder();
110
- else return this.ChartBorder.GetBorder();
111
- }
112
-
113
- this.ClearCoordinateText=function(option)
114
- {
115
- if (IFrameSplitOperator.IsNonEmptyArray(this.HorizontalInfo))
116
- {
117
- for(var i=0;i<this.HorizontalInfo.length;++i)
118
- {
119
- var item=this.HorizontalInfo[i];
120
- item.Message[0]=item.Message[1]=null;
121
- }
122
- }
123
-
124
- if (IFrameSplitOperator.IsNonEmptyArray(this.VerticalInfo))
125
- {
126
- for(var i=0;i<this.VerticalInfo.length;++i)
127
- {
128
- var item=this.VerticalInfo[i];
129
- item.Message[0]=item.Message[1]=null;
130
- }
131
- }
132
- }
133
-
134
- //画边框
135
- this.DrawBorder = function ()
136
- {
137
- if (!this.IsShowBorder) return;
138
- if (this.IsMinSize) return;
139
-
140
- var left = ToFixedPoint(this.ChartBorder.GetLeft());
141
- var top = ToFixedPoint(this.ChartBorder.GetTop());
142
- var right = ToFixedPoint(this.ChartBorder.GetRight());
143
- var bottom = ToFixedPoint(this.ChartBorder.GetBottom());
144
- var width = right - left;
145
- var height = bottom - top;
146
- if (this.BorderLine==null)
147
- {
148
- this.Canvas.strokeStyle = this.PenBorder;
149
- this.Canvas.strokeRect(left, top, width, height);
150
- }
151
- else if (IFrameSplitOperator.IsNumber(this.BorderLine))
152
- {
153
- this.Canvas.strokeStyle=this.PenBorder;
154
- this.Canvas.beginPath();
155
-
156
- if ((this.BorderLine&1)>0) //上
157
- {
158
- this.Canvas.moveTo(left,top);
159
- this.Canvas.lineTo(right,top);
160
- }
161
-
162
- if ((this.BorderLine&2)>0) //下
163
- {
164
- this.Canvas.moveTo(left,bottom);
165
- this.Canvas.lineTo(right,bottom);
166
- }
167
-
168
- if ((this.BorderLine&4)>0) //左
169
- {
170
- this.Canvas.moveTo(left,top);
171
- this.Canvas.lineTo(left,bottom);
172
- }
173
-
174
- if ((this.BorderLine&8)>0) //右
175
- {
176
- this.Canvas.moveTo(right,top);
177
- this.Canvas.lineTo(right,bottom);
178
- }
179
-
180
- this.Canvas.stroke();
181
- }
182
- }
183
-
184
- //左右刻度文字宽度
185
- this.GetScaleTextWidth=function() { }
186
-
187
- //画标题背景色
188
- this.DrawTitleBG = function ()
189
- {
190
- /* 指标信息背景色不画,画了感觉框架变小了
191
- if (this.ChartBorder.TitleHeight<=0) return;
192
-
193
- var left=ToFixedPoint(this.ChartBorder.GetLeft());
194
- var top=ToFixedPoint(this.ChartBorder.GetTop());
195
- var right=ToFixedPoint(this.ChartBorder.GetRight());
196
- var bottom=ToFixedPoint(this.ChartBorder.GetTopEx());
197
- var width=right-left;
198
- var height=bottom-top;
199
-
200
- this.Canvas.fillStyle=this.TitleBGColor;
201
- this.Canvas.fillRect(left,top,width,height);
202
- */
203
- }
204
-
205
- this.DrawLock = function ()
206
- {
207
- if (this.IsLocked)
208
- {
209
- if (this.LockPaint == null) this.LockPaint = new ChartLock();
210
-
211
- this.LockPaint.Canvas = this.Canvas;
212
- this.LockPaint.ChartBorder = this.ChartBorder;
213
- this.LockPaint.ChartFrame = this;
214
- this.LockPaint.Draw();
215
- }
216
- }
217
-
218
- this.DrawLogo=function()
219
- {
220
- var border=this.GetBorder();
221
- var text=g_JSChartResource.FrameLogo.Text;
222
- if (!text) return;
223
-
224
- this.Canvas.fillStyle=this.LogoTextColor;
225
- this.Canvas.font=this.LogoTextFont;
226
- this.Canvas.textAlign = 'left';
227
- this.Canvas.textBaseline = 'bottom';
228
- if (this.IsHScreen)
229
- {
230
- var x=border.Left+5;
231
- var y=border.Top+5;
232
- this.Canvas.save();
233
- this.Canvas.translate(x,y);
234
- this.Canvas.rotate(90 * Math.PI / 180);
235
- this.Canvas.fillText(text,0,0);
236
- this.Canvas.restore();
237
- }
238
- else
239
- {
240
- var x=border.Left+5;
241
- var y=border.Bottom-5;
242
- this.Canvas.fillText(text,x,y);
243
- }
244
- }
245
-
246
- //设施上锁
247
- this.SetLock = function (lockData)
248
- {
249
- if (!lockData) //空数据不上锁
250
- {
251
- this.IsLocked = false;
252
- return;
253
- }
254
-
255
- this.IsLocked = true;
256
- if (!this.LockPaint) this.LockPaint = new ChartLock(); //创建锁
257
- if (lockData.Callback) this.LockPaint.Callback = lockData.Callback; //回调
258
- if (lockData.IndexName) this.LockPaint.IndexName = lockData.IndexName; //指标名字
259
- if (lockData.ID) this.LockPaint.LockID = lockData.ID; //锁ID
260
- if (lockData.BG) this.LockPaint.BGColor = lockData.BG; //背景色
261
- if (lockData.Text) this.LockPaint.Title = lockData.Text;
262
- if (lockData.TextColor) this.LockPaint.TextColor = lockData.TextColor;
263
- if (lockData.Font) this.LockPaint.Font = lockData.Font;
264
- if (lockData.Count) this.LockPaint.LockCount = lockData.Count;
265
- }
266
-
267
- this.GetLockRect=function()
268
- {
269
- if (!this.IsLocked) return null;
270
- if (!this.LockPaint) return null;
271
- return this.LockPaint.LockRect;
272
- }
273
-
274
- this.GetFontHeight=function(font)
275
- {
276
- if (font) this.Canvas.font=font;
277
- return this.Canvas.measureText("擎").width;
278
- }
279
- }
280
-
281
-
282
- //空框架只画边框
283
- function NoneFrame()
284
- {
285
- this.newMethod = IChartFramePainting; //派生
286
- this.newMethod();
287
- delete this.newMethod;
288
- this.ClassName='NoneFrame';
289
-
290
- this.Snapshot = function () { }
291
-
292
- this.DrawInsideHorizontal = function () { }
293
-
294
- this.SetSizeChage = function (sizeChange)
295
- {
296
- this.SizeChange = sizeChange;
297
-
298
- //画布的位置
299
- this.Position =
300
- {
301
- X: this.ChartBorder.UIElement.offsetLeft,
302
- Y: this.ChartBorder.UIElement.offsetTop,
303
- W: this.ChartBorder.UIElement.clientWidth,
304
- H: this.ChartBorder.UIElement.clientHeight
305
- };
306
- }
307
- }
308
-
309
- function AverageWidthFrame()
310
- {
311
- this.newMethod = IChartFramePainting; //派生
312
- this.newMethod();
313
- delete this.newMethod;
314
- this.ClassName='AverageWidthFrame';
315
-
316
- this.DataWidth = 50;
317
- this.DistanceWidth = 10;
318
- this.MinXDistance = 30; //X轴刻度最小间距
319
- this.MinYDistance=10;
320
- this.XMessageAlign = 'top'; //X轴刻度文字上下对齐方式
321
- this.IsShowTitle = true; //是否显示动态标题
322
- this.IsShowYText = [true, true]; //是否显示Y轴坐标坐标 [0=左侧] [1=右侧]
323
- this.XBottomOffset = g_JSChartResource.Frame.XBottomOffset; //X轴文字显示向下偏移
324
- this.YTextTopOffset=g_JSChartResource.Frame.YTopOffset; //Y轴顶部文字向下偏移
325
- this.YTextPosition=[0,0], //是坐标否强制画在内部 [0=左侧] [1=右侧] 1=OUT" , 2=INSIDE
326
- this.YTextPadding=[g_JSChartResource.Frame.YTextPadding[0], g_JSChartResource.Frame.YTextPadding[1]], //Y轴文字和边框间距 [0=左侧] [1=右侧]
327
- this.IsShowXLine=true; //是否显示X轴刻度线
328
- this.IsShowYLine=true;
329
- this.YTextBaseline=0; //0=居中 1=上部 (目前就支持内部刻度)
330
-
331
- this.ShortYLineLength=5;
332
- this.ShortXLineLength=5;
333
-
334
- this.DrawOtherChart; //其他画法调用
335
- this.GetEventCallback; //事件回调
336
-
337
- this.DrawFrame = function ()
338
- {
339
- if (this.XPointCount > 0)
340
- {
341
- this.DistanceWidth = this.ChartBorder.GetWidth() / (4 * this.XPointCount);
342
- this.DataWidth = 2 * this.DistanceWidth;
343
- }
344
-
345
- this.DrawHorizontal();
346
- this.DrawVertical();
347
- }
348
-
349
- this.GetYFromData = function (value)
350
- {
351
- if (value <= this.HorizontalMin) return this.ChartBorder.GetBottomEx();
352
- if (value >= this.HorizontalMax) return this.ChartBorder.GetTopEx();
353
-
354
- var height = this.ChartBorder.GetHeightEx() * (value - this.HorizontalMin) / (this.HorizontalMax - this.HorizontalMin);
355
- return this.ChartBorder.GetBottomEx() - height;
356
- }
357
-
358
- //Y刻度画在内部
359
- this.DrawInsideHorizontal = function ()
360
- {
361
- if (this.IsHScreen === true) return; //横屏不画
362
- if (this.IsMinSize) return;
363
- if (this.IsShowYText[0] === false && this.IsShowYText[1] === false) return;
364
-
365
- var left = this.ChartBorder.GetLeft();
366
- var right = this.ChartBorder.GetRight();
367
- var bottom = this.ChartBorder.GetBottom();
368
- var top = this.ChartBorder.GetTopTitle();
369
- var borderRight = this.ChartBorder.Right;
370
- var borderLeft = this.ChartBorder.Left;
371
- var titleHeight = this.ChartBorder.TitleHeight;
372
- if (borderLeft >= 10) return;
373
-
374
- if ((borderLeft < 10 && this.IsShowYText[0] === true) || (borderRight < 10 && this.IsShowYText[1] === true))
375
- {
376
- var yPrev = null; //上一个坐标y的值
377
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从上往下画分割线
378
- {
379
- var item = this.HorizontalInfo[i];
380
- if (!item) continue;
381
- var y = this.GetYFromData(item.Value);
382
- if (y != null && yPrev !=null && Math.abs(y - yPrev) < this.MinYDistance) continue; //两个坐标在近了 就不画了
383
-
384
- //坐标信息 左边 间距小于10 画在内部
385
- if (item.Message[0] != null && borderLeft < 10 && this.IsShowYText[0] === true)
386
- {
387
- if (item.Font != null) this.Canvas.font = item.Font;
388
- this.Canvas.fillStyle = item.TextColor;
389
- this.Canvas.textAlign = "left";
390
- var yText=y;
391
- if (y >= bottom - 2)
392
- {
393
- this.Canvas.textBaseline = 'bottom';
394
- }
395
- else if (y <= top + 2)
396
- {
397
- this.Canvas.textBaseline = 'top';
398
- yText+=this.YTextTopOffset;
399
- }
400
- else
401
- {
402
- if (this.YTextBaseline==1) this.Canvas.textBaseline = "bottom";
403
- else this.Canvas.textBaseline = "middle";
404
- }
405
- var textObj = { X: left, Y: yText, Text: { BaseLine: this.Canvas.textBaseline, Font: this.Canvas.font, Value: item.Message[0] } };
406
- if (!this.IsOverlayMaxMin || !this.IsOverlayMaxMin(textObj)) this.Canvas.fillText(item.Message[0], left + 1, yText);
407
- }
408
-
409
- if (item.Message[1] != null && borderRight < 10 && this.IsShowYText[1] === true)
410
- {
411
- if (item.Font != null) this.Canvas.font = item.Font;
412
- this.Canvas.fillStyle = item.TextColor;
413
- this.Canvas.textAlign = "right";
414
- var yText=y;
415
- if (y >= bottom - 2)
416
- {
417
- this.Canvas.textBaseline = 'bottom';
418
- }
419
- else if (y <= top + 2)
420
- {
421
- this.Canvas.textBaseline = 'top';
422
- yText+=this.YTextTopOffset;
423
- }
424
- else
425
- {
426
- if (this.YTextBaseline==1) this.Canvas.textBaseline = "bottom";
427
- else this.Canvas.textBaseline = "middle";
428
- }
429
- var textWidth = this.Canvas.measureText(item.Message[1]).width;
430
- var textObj = { X: right - textWidth, Y: yText, Text: { BaseLine: this.Canvas.textBaseline, TextAlign: this.Canvas.textAlign, Font: this.Canvas.font, Value: item.Message[1] } };
431
- if (!this.IsOverlayMaxMin || !this.IsOverlayMaxMin(textObj))
432
- this.Canvas.fillText(item.Message[1], right - 1, yText);
433
- }
434
-
435
- yPrev = y;
436
- }
437
- }
438
- }
439
-
440
- //画Y轴
441
- this.DrawHorizontal = function ()
442
- {
443
- var left = this.ChartBorder.GetLeft();
444
- var right = this.ChartBorder.GetRight();
445
- var bottom = this.ChartBorder.GetBottom();
446
- var top = this.ChartBorder.GetTopTitle();
447
- var borderRight = this.ChartBorder.Right;
448
- var borderLeft = this.ChartBorder.Left;
449
- var titleHeight = this.ChartBorder.TitleHeight;
450
-
451
- this.Canvas.save();
452
- var yPrev = null; //上一个坐标y的值
453
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从上往下画分割线
454
- {
455
- var item = this.HorizontalInfo[i];
456
- var y = this.GetYFromData(item.Value);
457
- if (y != null && yPrev != null && Math.abs(y - yPrev) <this.MinYDistance) continue; //两个坐标在近了 就不画了
458
-
459
- var yFixed=ToFixedPoint(y);
460
- if (bottom!=y && this.IsShowYLine) //和底部线段重叠了就不绘制
461
- {
462
- if (item.LineType==2)
463
- {
464
- this.Canvas.strokeStyle = item.LineColor;
465
- if (item.LineDash) this.Canvas.setLineDash(item.LineDash);
466
- else this.Canvas.setLineDash([5,5]);
467
- this.Canvas.beginPath();
468
- this.Canvas.moveTo(left, yFixed);
469
- this.Canvas.lineTo(right,yFixed);
470
- this.Canvas.stroke();
471
- this.Canvas.setLineDash([]);
472
- }
473
- else if (item.LineType==3) //只在刻度边上画一个短横线
474
- {
475
-
476
- }
477
- else if (item.LineType>0)
478
- {
479
- this.Canvas.strokeStyle = item.LineColor;
480
- if(g_JSChartResource.FrameYLineDash)
481
- {
482
- this.Canvas.setLineDash(g_JSChartResource.FrameYLineDash); //虚线
483
- this.Canvas.beginPath();
484
- this.Canvas.moveTo(left, yFixed);
485
- this.Canvas.lineTo(right, yFixed);
486
- this.Canvas.stroke();
487
- this.Canvas.setLineDash([]);
488
- }
489
- else
490
- {
491
- this.Canvas.beginPath();
492
- this.Canvas.moveTo(left, yFixed);
493
- this.Canvas.lineTo(right, yFixed);
494
- this.Canvas.stroke();
495
- }
496
- }
497
- }
498
- var yText=y;
499
- if (y >= bottom - 2)
500
- {
501
- this.Canvas.textBaseline = 'bottom';
502
- }
503
- else if (y <= top + 2)
504
- {
505
- this.Canvas.textBaseline = 'top';
506
- yText+=this.YTextTopOffset;
507
- }
508
- else
509
- {
510
- this.Canvas.textBaseline = "middle";
511
- }
512
-
513
- //坐标信息 左边 间距小于10 不画坐标
514
- this.Canvas.fillStyle = item.TextColor;
515
- this.Canvas.strokeStyle = item.TextColor;
516
- if (item.Message[0] != null && borderLeft > 10 && this.IsShowYText[0] === true)
517
- {
518
- if (item.Font != null) this.Canvas.font = item.Font;
519
-
520
- this.Canvas.textAlign = "right";
521
- this.Canvas.fillText(item.Message[0], left - this.YTextPadding[0], yText);
522
- }
523
-
524
- //坐标信息 右边 间距小于10 不画坐标
525
- if (item.Message[1] != null && borderRight > 10 && this.IsShowYText[1] === true)
526
- {
527
- if (item.Font != null) this.Canvas.font = item.Font;
528
-
529
- var xText=right;
530
- if (item.LineType==3)
531
- {
532
- var lineLength=this.ShortYLineLength;
533
- this.Canvas.beginPath();
534
- this.Canvas.moveTo(xText,yFixed);
535
- this.Canvas.lineTo(xText+lineLength,yFixed);
536
- this.Canvas.stroke();
537
-
538
- xText+=lineLength;
539
- }
540
-
541
- this.Canvas.textAlign = "left";
542
- this.Canvas.fillText(item.Message[1], xText + this.YTextPadding[1], yText);
543
- }
544
-
545
- yPrev = y;
546
- }
547
-
548
- this.Canvas.restore();
549
- }
550
-
551
- this.GetXFromIndex = function (index)
552
- {
553
- var count = this.XPointCount;
554
-
555
- if (count == 1)
556
- {
557
- if (index == 0) return this.ChartBorder.GetLeft();
558
- else return this.ChartBorder.GetRight();
559
- }
560
- else if (count <= 0)
561
- {
562
- return this.ChartBorder.GetLeft();
563
- }
564
- else if (index >= count)
565
- {
566
- return this.ChartBorder.GetRight();
567
- }
568
- else
569
- {
570
- var offset = this.ChartBorder.GetLeft() + this.ChartBorder.GetWidth() * index / count;
571
- return offset;
572
- }
573
- }
574
-
575
- //画X轴
576
- this.DrawVertical = function ()
577
- {
578
- var top = this.ChartBorder.GetTopTitle();
579
- var bottom = this.ChartBorder.GetBottom();
580
- var right = this.ChartBorder.GetRight();
581
-
582
- if (this.ChartBorder.Bottom<=5) return; //高度不够 不显示
583
-
584
- var yText = bottom;
585
- if (this.XMessageAlign == 'bottom') yText = this.ChartBorder.GetChartHeight();
586
- else this.XMessageAlign = 'top';
587
-
588
- var xPrev = null; //上一个坐标x的值
589
- let xPrevTextRight = null;
590
- for (var i in this.VerticalInfo)
591
- {
592
- var x = this.GetXFromIndex(this.VerticalInfo[i].Value);
593
- if (x > right) break;
594
- if (xPrev != null && Math.abs(x - xPrev) < this.MinXDistance) continue;
595
-
596
- var item=this.VerticalInfo[i];
597
- var xFixed=ToFixedPoint(x);
598
- if (this.IsShowXLine && item.LineType > 0)
599
- {
600
- if (item.LineType==2)
601
- {
602
- this.Canvas.strokeStyle = item.LineColor;
603
- if (item.LineDash) this.Canvas.setLineDash(item.LineDash);
604
- else this.Canvas.setLineDash([5,5]);
605
- this.Canvas.beginPath();
606
- this.Canvas.moveTo(xFixed, top);
607
- this.Canvas.lineTo(xFixed, bottom);
608
- this.Canvas.stroke();
609
- this.Canvas.setLineDash([]);
610
- }
611
- else if (item.LineType==3)
612
- {
613
-
614
- }
615
- else if (item.LineType>0)
616
- {
617
- if(g_JSChartResource.FrameXLineDash)
618
- {
619
- this.Canvas.strokeStyle = item.LineColor;
620
- this.Canvas.beginPath();
621
- this.Canvas.setLineDash(g_JSChartResource.FrameXLineDash);
622
- this.Canvas.moveTo(xFixed, top);
623
- this.Canvas.lineTo(xFixed, bottom);
624
- this.Canvas.stroke();
625
- this.Canvas.setLineDash([]);
626
- }
627
- else
628
- {
629
- this.Canvas.strokeStyle = item.LineColor;
630
- this.Canvas.beginPath();
631
- this.Canvas.moveTo(xFixed, top);
632
- this.Canvas.lineTo(xFixed, bottom);
633
- this.Canvas.stroke();
634
- }
635
- }
636
-
637
- }
638
-
639
- if (this.VerticalInfo[i].Message[0] != null && this.ChartBorder.Bottom > 5)
640
- {
641
- let xTextRight = null;
642
- let xTextLeft = null;
643
- if (this.VerticalInfo[i].Font != null)
644
- this.Canvas.font = this.VerticalInfo[i].Font;
645
- this.Canvas.fillStyle=item.TextColor;
646
- this.Canvas.strokeStyle=item.TextColor;
647
-
648
- var testWidth = this.Canvas.measureText(this.VerticalInfo[i].Message[0]).width;
649
- if (x < testWidth / 2)
650
- {
651
- this.Canvas.textAlign = "left";
652
- this.Canvas.textBaseline = this.XMessageAlign;
653
- xTextRight = x + testWidth;
654
- xTextLeft = x;
655
- }
656
- else if ((x + testWidth / 2) >= this.ChartBorder.GetChartWidth())
657
- {
658
- this.Canvas.textAlign = "right";
659
- this.Canvas.textBaseline = this.XMessageAlign;
660
- xTextRight = x + testWidth;
661
- xTextLeft = x;
662
- }
663
- else
664
- {
665
- this.Canvas.textAlign = "center";
666
- this.Canvas.textBaseline = this.XMessageAlign;
667
- xTextRight = x + testWidth / 2;
668
- xTextLeft = x - testWidth / 2;
669
- }
670
-
671
- if (xPrevTextRight != null && xPrevTextRight > xTextLeft) continue;
672
-
673
- var yText=bottom;
674
- if (item.LineType==3)
675
- {
676
- var lineLength=this.ShortXLineLength;
677
- this.Canvas.beginPath();
678
- this.Canvas.moveTo(xFixed,yText);
679
- this.Canvas.lineTo(xFixed,yText+lineLength);
680
- this.Canvas.stroke();
681
-
682
- yText+=lineLength+2;
683
- }
684
-
685
- this.Canvas.fillText(this.VerticalInfo[i].Message[0], x, yText + this.XBottomOffset);
686
- xPrevTextRight = xTextRight;
687
- }
688
-
689
- xPrev = x;
690
- }
691
- }
692
-
693
- this.GetYData = function (y) //Y坐标转y轴数值
694
- {
695
- if (y < this.ChartBorder.GetTopEx()) return this.HorizontalMax;
696
- if (y > this.ChartBorder.GetBottomEx()) return this.HorizontalMin;
697
-
698
- return (this.ChartBorder.GetBottomEx() - y) / this.ChartBorder.GetHeightEx() * (this.HorizontalMax - this.HorizontalMin) + this.HorizontalMin;
699
- }
700
-
701
- this.GetXData = function (x) //X坐标转x轴数值
702
- {
703
- if (x <= this.ChartBorder.GetLeft()) return 0;
704
- if (x >= this.ChartBorder.GetRight()) return this.XPointCount;
705
-
706
- return (x - this.ChartBorder.GetLeft()) * (this.XPointCount * 1.0 / this.ChartBorder.GetWidth());
707
- }
708
-
709
- this.DrawCustomItem = function (item) //显示自定义刻度
710
- {
711
- //if (this.IsHScreen === true) return; //横屏不画
712
- if (!item.Message[1] && !item.Message[0]) return;
713
- if (item.Value > this.HorizontalMax || item.Value < this.HorizontalMin)
714
- {
715
- if (item.CountDown===true) this.SendDrawCountDownEvent( { IsShow:false } );
716
- return;
717
- }
718
-
719
- var left = this.ChartBorder.GetLeft();
720
- var right = this.ChartBorder.GetRight();
721
- var bottom = this.ChartBorder.GetBottom();
722
- var top = this.ChartBorder.GetTopTitle();
723
- var borderRight = this.ChartBorder.Right;
724
- var borderLeft = this.ChartBorder.Left;
725
- var titleHeight = this.ChartBorder.TitleHeight;
726
-
727
- if (this.IsHScreen)
728
- {
729
- borderLeft = this.ChartBorder.Top;
730
- borderRight = this.ChartBorder.Bottom;
731
- top = this.ChartBorder.GetTop();
732
- bottom = this.ChartBorder.GetBottom();
733
- }
734
-
735
- var defaultTextHeight=16
736
- var textHeight = defaultTextHeight;
737
- var y = this.GetYFromData(item.Value);
738
- var position=0;
739
-
740
- if (item.ExtendData && item.ExtendData.Custom)
741
- {
742
- var customItem=item.ExtendData.Custom;
743
- if (IFrameSplitOperator.IsNumber(customItem.Position)) position=customItem.Position;
744
- }
745
-
746
- if (item.Message[0])
747
- {
748
- if (borderLeft < 10 || position==1) //左边
749
- {
750
- if (item.Font != null) this.Canvas.font = item.Font;
751
- this.Canvas.textAlign = "left";
752
- this.Canvas.textBaseline = "middle";
753
- var textInfo=this.GetCustomItemTextInfo(item,true);
754
- var textWidth = textInfo.MaxWidth;
755
- var fontHeight=this.GetFontHeight();
756
- textHeight=fontHeight>defaultTextHeight? fontHeight:defaultTextHeight;
757
- var bgColor = item.LineColor;
758
- var rgb = this.RGBToStruct(item.LineColor);
759
- if (rgb) bgColor = `rgba(${rgb.R}, ${rgb.G}, ${rgb.B}, ${g_JSChartResource.FrameLatestPrice.BGAlpha})`; //内部刻度 背景增加透明度
760
-
761
- var yText=y;
762
- for(var i=0;i<textInfo.Text.length;++i)
763
- {
764
- var itemText=textInfo.Text[i];
765
- if (this.IsHScreen)
766
- {
767
- var bgTop = top;
768
- var textLeft = yText - textHeight / 2 - 1;
769
- this.Canvas.fillStyle = bgColor;
770
- this.Canvas.fillRect(textLeft, bgTop, textHeight, textWidth);
771
- this.DrawHScreenText({ X: yText, Y: bgTop }, { Text: itemText.Text, Color: item.TextColor, XOffset: 1, YOffset: 2 });
772
- if (i==0) this.DrawLine(bgTop + itemText.Width, bottom, yText, item.LineColor,item.LineType);
773
-
774
- yText-=textHeight+1;
775
- }
776
- else
777
- {
778
- var bgTop = yText - textHeight / 2 - 1;
779
- var textLeft = left + 1;
780
- this.Canvas.fillStyle = bgColor;
781
- this.Canvas.fillRect(textLeft, bgTop, itemText.Width, textHeight);
782
- this.Canvas.fillStyle = item.TextColor;
783
- this.Canvas.fillText(itemText.Text, textLeft + 1, yText);
784
- if (i==0) this.DrawLine(textLeft + itemText.Width, right, yText, item.LineColor,item.LineType);
785
-
786
- yText+=textHeight+1;
787
- }
788
- }
789
- }
790
- else
791
- {
792
- if (item.Font != null) this.Canvas.font = item.Font;
793
- this.Canvas.textAlign = "right";
794
- this.Canvas.textBaseline = "middle";
795
- var textInfo=this.GetCustomItemTextInfo(item,true);
796
- var textWidth=textInfo.MaxWidth;
797
- var fontHeight=this.GetFontHeight();
798
- textHeight=fontHeight>defaultTextHeight? fontHeight:defaultTextHeight;
799
-
800
- var yText=y;
801
- for(var i=0;i<textInfo.Text.length;++i)
802
- {
803
- var itemText=textInfo.Text[i];
804
- if (this.IsHScreen)
805
- {
806
- if (i==0) var bgTop=top-itemText.Width;
807
- else var bgTop=top-textWidth;
808
- var textLeft=yText-textHeight/2-1;
809
- this.Canvas.fillStyle=item.LineColor;
810
- this.Canvas.fillRect(textLeft,bgTop,textHeight,itemText.Width);
811
- this.DrawHScreenText({ X: yText, Y: bgTop }, { Text: itemText.Text, Color: item.TextColor, XOffset: 1, YOffset: 2 });
812
- if (i==0) this.DrawLine(bgTop + itemText.Width, bottom, yText, item.LineColor,item.LineType);
813
-
814
- yText-=textHeight+1;
815
- }
816
- else
817
- {
818
- var bgTop = yText - textHeight / 2 - 1;
819
- if (i==0)
820
- {
821
- var rectLeft=left-itemText.Width;
822
- var textLeft=left;
823
- }
824
- else
825
- {
826
- var rectLeft=left-textWidth;
827
- var textLeft=left-(textWidth-itemText.Width);
828
- }
829
-
830
- this.Canvas.fillStyle = item.LineColor;
831
- this.Canvas.fillRect(rectLeft,bgTop,itemText.Width,textHeight);
832
- this.Canvas.fillStyle = item.TextColor;
833
- this.Canvas.fillText(itemText.Text, textLeft - 1, yText);
834
- if (i==0) this.DrawLine(left, right, yText, item.LineColor,item.LineType);
835
-
836
- yText+=textHeight+1;
837
- }
838
- }
839
- }
840
- }
841
- else if (item.Message[1]) //右边
842
- {
843
- if (borderRight < 10 || position==1)
844
- {
845
- if (item.Font != null) this.Canvas.font = item.Font;
846
- this.Canvas.textAlign = "left";
847
- this.Canvas.textBaseline = "middle";
848
- var textInfo=this.GetCustomItemTextInfo(item,false);
849
- var textWidth=textInfo.MaxWidth;
850
- var fontHeight=this.GetFontHeight();
851
- textHeight=fontHeight>defaultTextHeight? fontHeight:defaultTextHeight;
852
- var bgColor = item.LineColor;
853
- var rgb = this.RGBToStruct(item.LineColor);
854
- if (rgb) bgColor = `rgba(${rgb.R}, ${rgb.G}, ${rgb.B}, ${g_JSChartResource.FrameLatestPrice.BGAlpha})`; //内部刻度 背景增加透明度
855
-
856
- var yText=y;
857
- for(var i=0;i<textInfo.Text.length;++i)
858
- {
859
- var itemText=textInfo.Text[i];
860
- if (this.IsHScreen)
861
- {
862
- var bgTop=bottom-itemText.Width;
863
- var textLeft=yText-textHeight/2-1;
864
- this.Canvas.fillStyle=bgColor;
865
- this.Canvas.fillRect(textLeft,bgTop,textHeight,itemText.Width);
866
- this.DrawHScreenText({X:yText, Y:bgTop}, {Text:itemText.Text, Color:item.TextColor, XOffset:1, YOffset:2});
867
- if (i==0) this.DrawLine(top, bgTop, yText, item.LineColor,item.LineType);
868
-
869
- yText-=textHeight+1;
870
- }
871
- else
872
- {
873
- var bgTop=yText-textHeight/2-1;
874
- var textLeft=right-itemText.Width;
875
- this.Canvas.fillStyle=bgColor;
876
- this.Canvas.fillRect(textLeft, bgTop, itemText.Width, textHeight);
877
- this.Canvas.fillStyle = item.TextColor;
878
- this.Canvas.fillText(itemText.Text, textLeft + 1, yText);
879
- if (i==0) this.DrawLine(left, textLeft,yText , item.LineColor,item.LineType);
880
-
881
- if (item.CountDown===true)
882
- {
883
- if (this.GetEventCallback)
884
- {
885
- var bgTop=yText + textHeight / 2 + 1;
886
- var sendData=
887
- {
888
- Top:bgTop, Right:right, Height:null,
889
- IsShow:true, BGColor:bgColor, TextColor:item.TextColor, Position:"Right", IsInside:true
890
- };
891
- this.SendDrawCountDownEvent(sendData);
892
- }
893
- }
894
-
895
- yText+=textHeight+1;
896
- }
897
- }
898
-
899
- if (item.Type==3 || item.Type==4)
900
- {
901
- if (item.Title)
902
- {
903
- var width=this.Canvas.measureText(item.Title).width+2;
904
- if (this.IsHScreen)
905
- {
906
- var bgTop=bottom-itemText.Width-width;
907
- var textLeft=y-textHeight/2-1;
908
- this.Canvas.fillStyle=bgColor;
909
- this.Canvas.fillRect(textLeft,bgTop,textHeight,width);
910
- this.DrawHScreenText({X:y, Y:bgTop}, {Text:item.Title, Color:item.TextColor, XOffset:1, YOffset:2});
911
- }
912
- else
913
- {
914
- var bgTop=y-textHeight/2-1;
915
- var textLeft=right-textWidth-width-1;
916
- this.Canvas.fillStyle=bgColor;
917
- this.Canvas.fillRect(textLeft,bgTop,width,textHeight);
918
- this.Canvas.fillStyle = item.TextColor;
919
- this.Canvas.fillText(item.Title, textLeft + 1, y);
920
- }
921
- }
922
- }
923
- }
924
- else
925
- {
926
- if (item.Font != null) this.Canvas.font = item.Font;
927
- this.Canvas.textAlign = "left";
928
- this.Canvas.textBaseline = "middle";
929
- var textInfo=this.GetCustomItemTextInfo(item,false);
930
- var textWidth=textInfo.MaxWidth;
931
- var fontHeight=this.GetFontHeight();
932
- textHeight=fontHeight>defaultTextHeight? fontHeight:defaultTextHeight;
933
-
934
- var yText=y;
935
- for(var i=0;i<textInfo.Text.length;++i)
936
- {
937
- var itemText=textInfo.Text[i];
938
-
939
- if (this.IsHScreen)
940
- {
941
- var bgTop = bottom;
942
- var textLeft=yText-textHeight/2-1;
943
- this.Canvas.fillStyle=item.LineColor;
944
- this.Canvas.fillRect(textLeft, bgTop, textHeight, itemText.Width);
945
- this.DrawHScreenText({ X: yText, Y: bgTop }, { Text: itemText.Text, Color: item.TextColor, XOffset: 1 , YOffset: 2 });
946
- if (i==0) this.DrawLine(top, bgTop, yText, item.LineColor,item.LineType);
947
-
948
- yText-=textHeight+1;
949
- }
950
- else
951
- {
952
- var bgTop=yText-textHeight/2-1;
953
- if (i==0)
954
- {
955
- var textLeft=right;
956
- }
957
- else
958
- {
959
- var textLeft=right+textWidth-itemText.Width;
960
- }
961
-
962
- this.Canvas.fillStyle = item.LineColor;
963
- this.Canvas.fillRect(textLeft,bgTop,itemText.Width,textHeight);
964
- this.Canvas.fillStyle = item.TextColor;
965
- this.Canvas.fillText(itemText.Text, textLeft+1, yText);
966
- if (i==0) this.DrawLine(left, right, yText, item.LineColor,item.LineType);
967
-
968
- if (item.CountDown===true)
969
- {
970
- if (this.GetEventCallback)
971
- {
972
- var bgTop=yText-textHeight/2-1;
973
- var sendData=
974
- {
975
- Top:bgTop, Left:right, Right:this.ChartBorder.GetChartWidth(), Height:null,
976
- IsShow:true, BGColor:item.LineColor, TextColor:item.TextColor, Position:"Right", IsInside:false
977
- };
978
- this.SendDrawCountDownEvent(sendData);
979
- }
980
- }
981
-
982
- yText+=textHeight+1;
983
- }
984
- }
985
-
986
- if (item.Type==3 || item.Type==4)
987
- {
988
- if (item.Title)
989
- {
990
- var bgColor=item.LineColor;
991
- var rgb=this.RGBToStruct(item.LineColor);
992
- if (rgb) bgColor=`rgba(${rgb.R}, ${rgb.G}, ${rgb.B}, ${g_JSChartResource.FrameLatestPrice.BGAlpha})`; //内部刻度 背景增加透明度
993
- var width=this.Canvas.measureText(item.Title).width+2;
994
- if (this.IsHScreen)
995
- {
996
- var bgTop=bottom-width;
997
- var textLeft=y-textHeight/2-1;
998
- this.Canvas.fillStyle=bgColor;
999
- this.Canvas.fillRect(textLeft,bgTop,textHeight,width);
1000
- this.DrawHScreenText({X:y, Y:bgTop}, {Text:item.Title, Color:item.TextColor, XOffset:1, YOffset:2});
1001
- }
1002
- else
1003
- {
1004
- var bgTop=y-textHeight/2-1;
1005
- var textLeft=right-width-1;
1006
- this.Canvas.fillStyle=bgColor;
1007
- this.Canvas.fillRect(textLeft,bgTop,width,textHeight);
1008
- this.Canvas.fillStyle = item.TextColor;
1009
- this.Canvas.fillText(item.Title, textLeft + 1, y);
1010
- }
1011
- }
1012
- }
1013
- }
1014
- }
1015
- }
1016
-
1017
- this.GetCustomItemTextInfo=function(item, bLeft)
1018
- {
1019
- var text=bLeft?item.Message[0]:item.Message[1];
1020
- var aryText=[];
1021
- var width=0;
1022
- if (Array.isArray(text))
1023
- {
1024
- for(var i=0;i<text.length;++i)
1025
- {
1026
- var item=text[i];
1027
- if (item.Type===1)
1028
- {
1029
- aryText.push({ Type: item.Type });
1030
- }
1031
- else
1032
- {
1033
- var value=this.Canvas.measureText(item.Text).width;
1034
- if (value>width) width=value;
1035
- aryText.push({Text:item.Text, Width:value+3});
1036
- }
1037
- }
1038
-
1039
- if (width>0) width+=3;
1040
- }
1041
- else
1042
- {
1043
- width=this.Canvas.measureText(text).width+3;
1044
- aryText.push( {Text:text, Width:width} );
1045
- }
1046
-
1047
- return { MaxWidth:width, Text:aryText };
1048
- }
1049
-
1050
- this.SendDrawCountDownEvent=function(sendData)
1051
- {
1052
- if (!this.GetEventCallback) return false;
1053
- var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_DRAW_COUNTDOWN);
1054
- if (!event || !event.Callback) return false;
1055
-
1056
- event.Callback(event,sendData,this);
1057
- return true;
1058
- }
1059
-
1060
- this.DrawLine=function(left, right, y, color, lineType)
1061
- {
1062
- if (lineType==-1) return;
1063
-
1064
- if (lineType==0)
1065
- {
1066
- this.Canvas.strokeStyle = color;
1067
- this.Canvas.beginPath();
1068
- if (this.IsHScreen)
1069
- {
1070
- this.Canvas.moveTo(ToFixedPoint(y), left);
1071
- this.Canvas.lineTo(ToFixedPoint(y), right);
1072
- }
1073
- else
1074
- {
1075
- this.Canvas.moveTo(left, ToFixedPoint(y));
1076
- this.Canvas.lineTo(right, ToFixedPoint(y));
1077
- }
1078
- this.Canvas.stroke();
1079
- }
1080
- else
1081
- {
1082
- this.DrawDotLine(left, right, y, color);
1083
- }
1084
- }
1085
-
1086
- this.DrawDotLine = function (left, right, y, color)
1087
- {
1088
- this.Canvas.save();
1089
- this.Canvas.strokeStyle = color;
1090
- this.Canvas.setLineDash([5, 5]); //虚线
1091
- this.Canvas.beginPath();
1092
- if (this.IsHScreen)
1093
- {
1094
- this.Canvas.moveTo(ToFixedPoint(y), left);
1095
- this.Canvas.lineTo(ToFixedPoint(y), right);
1096
- }
1097
- else
1098
- {
1099
- this.Canvas.moveTo(left, ToFixedPoint(y));
1100
- this.Canvas.lineTo(right, ToFixedPoint(y));
1101
- }
1102
- this.Canvas.stroke();
1103
- this.Canvas.restore();
1104
- }
1105
-
1106
- this.RGBToStruct = function (rgb)
1107
- {
1108
- if (/^(rgb|RGB)/.test(rgb))
1109
- {
1110
- var aColor = rgb.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
1111
- var result = {};
1112
- if (aColor.length != 3) return null;
1113
-
1114
- result.R = Number(aColor[0]);
1115
- result.G = Number(aColor[1]);
1116
- result.B = Number(aColor[2]);
1117
- return result;
1118
- }
1119
- return null;
1120
- }
1121
-
1122
- this.DrawHScreenText = function (center, data)
1123
- {
1124
- this.Canvas.textAlign = "left";
1125
- this.Canvas.textBaseline = "middle";
1126
- this.Canvas.fillStyle = data.Color;
1127
-
1128
- this.Canvas.save();
1129
- this.Canvas.translate(center.X, center.Y);
1130
- this.Canvas.rotate(90 * Math.PI / 180);
1131
- this.Canvas.fillText(data.Text, data.XOffset, data.YOffset);
1132
- this.Canvas.restore();
1133
- }
1134
-
1135
- this.GetScaleTextWidth=function()
1136
- {
1137
- var border=this.ChartBorder.GetBorder();
1138
- if (this.IsHScreen)
1139
- {
1140
- var borderTop = this.ChartBorder.Top;
1141
- var borderBottom = this.ChartBorder.Bottom;
1142
- var isDrawLeft=borderTop>10 && this.IsShowYText[0]===true;
1143
- var isDrawRight=borderBottom>10 && this.IsShowYText[1]===true;
1144
- }
1145
- else
1146
- {
1147
- var borderRight=this.ChartBorder.Right;
1148
- var borderLeft=this.ChartBorder.Left;
1149
- var isDrawLeft=borderLeft>10 && this.IsShowYText[0]===true;
1150
- var isDrawRight=borderRight>10 && this.IsShowYText[1]===true;
1151
- }
1152
-
1153
- var width={ Left:null, Right:null };
1154
- if (!isDrawRight && !isDrawLeft) return width;
1155
-
1156
- for(var i=0;i<this.HorizontalInfo.length;++i)
1157
- {
1158
- var textWidth=null;
1159
- var item=this.HorizontalInfo[i];
1160
- if (!item) continue;
1161
- if (item.Font!=null) this.Canvas.font=item.Font;
1162
-
1163
- if (item.Message[0]!=null && isDrawLeft)
1164
- {
1165
- textWidth=this.Canvas.measureText(item.Message[0]).width;
1166
- if (width.Left==null || width.Left<textWidth)
1167
- width.Left=textWidth;
1168
- }
1169
-
1170
- if (item.Message[1]!=null && isDrawRight)
1171
- {
1172
- textWidth=this.Canvas.measureText(item.Message[1]).width;
1173
- if (width.Right==null || width.Right<textWidth)
1174
- width.Right=textWidth;
1175
- }
1176
- }
1177
-
1178
- if (IFrameSplitOperator.IsNumber(width.Left)) width.Left+=this.YTextPadding[0];
1179
- if (IFrameSplitOperator.IsNumber(width.Right)) width.Right+=this.YTextPadding[1];
1180
-
1181
- return { TextWidth:width };
1182
- }
1183
- }
1184
-
1185
- function MinuteFrame()
1186
- {
1187
- this.newMethod = AverageWidthFrame; //派生
1188
- this.newMethod();
1189
- delete this.newMethod;
1190
- this.ClassName='MinuteFrame';
1191
-
1192
- this.DataWidth=1;
1193
- this.DistanceWidth=1;
1194
- this.MinXDistance = 10;
1195
- this.CustomHorizontalInfo = [];
1196
-
1197
- this.DrawFrame = function ()
1198
- {
1199
- if (this.IsMinSize) return;
1200
-
1201
- this.SplitXYCoordinate();
1202
-
1203
- this.DrawTitleBG();
1204
- this.DrawHorizontal();
1205
- this.DrawVertical();
1206
- }
1207
-
1208
- //分割x,y轴坐标信息
1209
- this.SplitXYCoordinate = function ()
1210
- {
1211
- if (this.XYSplit == false) return;
1212
- if (this.YSplitOperator != null) this.YSplitOperator.Operator();
1213
- if (this.XSplitOperator != null) this.XSplitOperator.Operator();
1214
- }
1215
-
1216
- this.GetXFromIndex = function (index)
1217
- {
1218
- var count = this.XPointCount - 1;
1219
-
1220
- if (count == 1)
1221
- {
1222
- if (index == 0) return this.ChartBorder.GetLeft();
1223
- else return this.ChartBorder.GetRight();
1224
- }
1225
- else if (count <= 0)
1226
- {
1227
- return this.ChartBorder.GetLeft();
1228
- }
1229
- else if (index >= count)
1230
- {
1231
- return this.ChartBorder.GetRight();
1232
- }
1233
- else
1234
- {
1235
- var offset = this.ChartBorder.GetLeft() + this.ChartBorder.GetWidth() * index / count;
1236
- return offset;
1237
- }
1238
- }
1239
-
1240
- //X坐标转x轴数值
1241
- this.GetXData = function (x)
1242
- {
1243
- if (x <= this.ChartBorder.GetLeft()) return 0;
1244
- if (x >= this.ChartBorder.GetRight()) return this.XPointCount;
1245
-
1246
- return (x - this.ChartBorder.GetLeft()) * (this.XPointCount * 1.0 / this.ChartBorder.GetWidth());
1247
- }
1248
-
1249
- this.DrawCustomHorizontal = function () //Y轴刻度定制显示
1250
- {
1251
- if (this.IsMinSize) return;
1252
- for (var i in this.CustomHorizontalInfo)
1253
- {
1254
- var item = this.CustomHorizontalInfo[i];
1255
- switch (item.Type)
1256
- {
1257
- case 0:
1258
- case 1:
1259
- this.DrawCustomItem(item); //自定义刻度
1260
- break;
1261
- }
1262
- }
1263
- }
1264
- }
1265
-
1266
- function MinuteHScreenFrame()
1267
- {
1268
- this.newMethod = MinuteFrame; //派生
1269
- this.newMethod();
1270
- delete this.newMethod;
1271
-
1272
- this.ClassName='MinuteHScreenFrame';
1273
- this.IsHScreen = true; //是否是横屏
1274
-
1275
- //画标题背景色
1276
- this.DrawTitleBG = function ()
1277
- {
1278
- /*
1279
- if (this.ChartBorder.TitleHeight <= 0) return;
1280
-
1281
- var left = ToFixedPoint(this.ChartBorder.GetRightEx());
1282
- var top = ToFixedPoint(this.ChartBorder.GetTop());
1283
- var bottom = ToFixedPoint(this.ChartBorder.GetBottom());
1284
- var width = this.ChartBorder.TitleHeight;
1285
- var height = bottom - top;
1286
-
1287
- this.Canvas.fillStyle = this.TitleBGColor;
1288
- this.Canvas.fillRect(left, top, width, height);
1289
- */
1290
- }
1291
-
1292
- this.DrawInsideHorizontal = function ()
1293
- {
1294
- if (this.IsMinSize) return;
1295
- if (this.IsShowYText[0] === false && this.IsShowYText[1] === false) return;
1296
-
1297
- var left = this.ChartBorder.GetLeft();
1298
- var right = this.ChartBorder.GetRightEx();
1299
- var top = this.ChartBorder.GetTop();
1300
- var bottom = this.ChartBorder.GetBottom();
1301
- var borderTop = this.ChartBorder.Top;
1302
- var borderBottom = this.ChartBorder.Bottom;
1303
- var titleHeight = this.ChartBorder.TitleHeight;
1304
- var pixelTatio = 1;
1305
-
1306
- var isDrawLeft = (borderTop < 10 * pixelTatio || this.YTextPosition[0] == 2) && this.IsShowYText[0] === true;
1307
- var isDrawRight = (borderBottom < 10 * pixelTatio || this.YTextPosition[1] == 2) && this.IsShowYText[1] === true;
1308
-
1309
- if (isDrawLeft || isDrawRight)
1310
- {
1311
- var yPrev = null; //上一个坐标y的值
1312
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从上往下画分割线
1313
- {
1314
- var item = this.HorizontalInfo[i];
1315
- var y = this.GetYFromData(item.Value);
1316
- if (y != null && yPrev != null && Math.abs(y - yPrev) < this.MinYDistance) continue; //两个坐标在近了 就不画了
1317
-
1318
- //坐标信息 左边 间距小于10 画在内部
1319
- if (item.Message[0] != null && isDrawLeft)
1320
- {
1321
- if (item.Font != null) this.Canvas.font = item.Font;
1322
- this.Canvas.fillStyle = item.TextColor;
1323
- this.Canvas.textAlign = "left";
1324
- if (y >= right - 2) this.Canvas.textBaseline = 'top';
1325
- else if (y <= left + 2) this.Canvas.textBaseline = 'bottom';
1326
- else this.Canvas.textBaseline = "middle";
1327
-
1328
- var textObj = { X: left, Y: y, Text: { BaseLine: this.Canvas.textBaseline, TextAlign: this.Canvas.textAlign, Font: this.Canvas.font, Value: item.Message[0] } };
1329
- var xText = y, yText = top;
1330
- this.Canvas.save();
1331
- this.Canvas.translate(xText, yText);
1332
- this.Canvas.rotate(90 * Math.PI / 180);
1333
- this.Canvas.fillText(item.Message[0], 2, 0);
1334
- this.Canvas.restore();
1335
- }
1336
-
1337
- if (item.Message[1] != null && isDrawRight)
1338
- {
1339
- if (item.Font != null) this.Canvas.font = item.Font;
1340
- this.Canvas.fillStyle = item.TextColor;
1341
- this.Canvas.textAlign = "right";
1342
- if (y >= right - 2) this.Canvas.textBaseline = 'top';
1343
- else if (y <= left + 2) this.Canvas.textBaseline = 'bottom';
1344
- else this.Canvas.textBaseline = "middle";
1345
- var textWidth = this.Canvas.measureText(item.Message[1]).width;
1346
- var textObj = { X: right - textWidth, Y: y, Text: { BaseLine: this.Canvas.textBaseline, TextAlign: this.Canvas.textAlign, Font: this.Canvas.font, Value: item.Message[1] } };
1347
-
1348
- var xText = y, yText = bottom;
1349
- this.Canvas.save();
1350
- this.Canvas.translate(xText, yText);
1351
- this.Canvas.rotate(90 * Math.PI / 180);
1352
- this.Canvas.fillText(item.Message[1], -2, 0);
1353
- this.Canvas.restore();
1354
- }
1355
- yPrev = y;
1356
- }
1357
- }
1358
- }
1359
-
1360
- //Y坐标转y轴数值
1361
- this.GetYData = function (x)
1362
- {
1363
- if (x < this.ChartBorder.GetLeftEx()) return this.HorizontalMin;
1364
- if (x > this.ChartBorder.GetRightEx()) return this.HorizontalMax;
1365
-
1366
- return (x - this.ChartBorder.GetLeftEx()) / this.ChartBorder.GetWidthEx() * (this.HorizontalMax - this.HorizontalMin) + this.HorizontalMin;
1367
- }
1368
-
1369
- //X坐标转x轴数值
1370
- this.GetXData = function (y)
1371
- {
1372
- if (y <= this.ChartBorder.GetTop()) return 0;
1373
- if (y >= this.ChartBorder.GetBottom()) return this.XPointCount;
1374
-
1375
- var count=this.XPointCount-1;
1376
- return (y - this.ChartBorder.GetTop()) * (count * 1.0 / this.ChartBorder.GetHeight());
1377
- }
1378
-
1379
- this.GetXFromIndex = function (index)
1380
- {
1381
- var count = this.XPointCount - 1;
1382
-
1383
- if (count == 1)
1384
- {
1385
- if (index == 0) return this.ChartBorder.GetTop();
1386
- else return this.ChartBorder.GetBottom();
1387
- }
1388
- else if (count <= 0)
1389
- {
1390
- return this.ChartBorder.GetTop();
1391
- }
1392
- else if (index >= count)
1393
- {
1394
- return this.ChartBorder.GetBottom();
1395
- }
1396
- else
1397
- {
1398
- var offset = this.ChartBorder.GetTop() + this.ChartBorder.GetHeight() * index / count;
1399
- return offset;
1400
- }
1401
- }
1402
-
1403
-
1404
- this.GetYFromData = function (value)
1405
- {
1406
- if (value <= this.HorizontalMin) return this.ChartBorder.GetLeft();
1407
- if (value >= this.HorizontalMax) return this.ChartBorder.GetRightEx();
1408
-
1409
- var width = this.ChartBorder.GetWidthEx() * (value - this.HorizontalMin) / (this.HorizontalMax - this.HorizontalMin);
1410
- return this.ChartBorder.GetLeft() + width;
1411
- }
1412
-
1413
- //画Y轴
1414
- this.DrawHorizontal = function ()
1415
- {
1416
- var top = this.ChartBorder.GetTop();
1417
- var bottom = this.ChartBorder.GetBottom();
1418
- var left=this.ChartBorder.GetLeft();
1419
- var right=this.ChartBorder.GetRight();
1420
- var borderTop = this.ChartBorder.Top;
1421
- var borderBottom = this.ChartBorder.Bottom;
1422
-
1423
- var yPrev = null; //上一个坐标y的值
1424
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从左往右画分割线
1425
- {
1426
- var item = this.HorizontalInfo[i];
1427
- var y = this.GetYFromData(item.Value);
1428
- if (y != null && Math.abs(y - yPrev) < this.MinYDistance) continue; //两个坐标在近了 就不画了
1429
-
1430
- this.Canvas.strokeStyle = item.LineColor;
1431
- this.Canvas.beginPath();
1432
- this.Canvas.moveTo(ToFixedPoint(y), top);
1433
- this.Canvas.lineTo(ToFixedPoint(y), bottom);
1434
- this.Canvas.stroke();
1435
-
1436
- if (y >= right - 2)
1437
- {
1438
- this.Canvas.textBaseline = 'top';
1439
- y = right;
1440
- }
1441
- else if (y <= left + 2)
1442
- {
1443
- this.Canvas.textBaseline = 'bottom';
1444
- y=left;
1445
- if (y != null && Math.abs(y - yPrev) < 2*this.MinYDistance) continue; //两个坐标在近了 就不画了
1446
- }
1447
- else
1448
- {
1449
- this.Canvas.textBaseline = "middle";
1450
- }
1451
-
1452
- //坐标信息 左边 间距小于10 不画坐标
1453
- if (item.Message[0] != null && borderTop > 10)
1454
- {
1455
- if (item.Font != null) this.Canvas.font = item.Font;
1456
-
1457
- this.Canvas.fillStyle = item.TextColor;
1458
- this.Canvas.textAlign = "right";
1459
- //this.Canvas.textBaseline = "middle";
1460
-
1461
- var xText = y, yText = top;
1462
- this.Canvas.save();
1463
- this.Canvas.translate(xText, yText);
1464
- this.Canvas.rotate(90 * Math.PI / 180);
1465
- this.Canvas.fillText(item.Message[0], -2, 0);
1466
- this.Canvas.restore();
1467
- }
1468
-
1469
- //坐标信息 右边 间距小于10 不画坐标
1470
- if (item.Message[1] != null && borderBottom > 10)
1471
- {
1472
- if (item.Font != null) this.Canvas.font = item.Font;
1473
-
1474
- this.Canvas.fillStyle = item.TextColor;
1475
- this.Canvas.textAlign = "left";
1476
- //this.Canvas.textBaseline = "middle";
1477
- var xText = y, yText = bottom;
1478
- this.Canvas.save();
1479
- this.Canvas.translate(xText, yText);
1480
- this.Canvas.rotate(90 * Math.PI / 180);
1481
- this.Canvas.fillText(item.Message[1], 2, 0);
1482
- this.Canvas.restore();
1483
- }
1484
-
1485
- yPrev = y;
1486
- }
1487
- }
1488
-
1489
- //画X轴
1490
- this.DrawVertical = function () {
1491
- var left = this.ChartBorder.GetLeft();
1492
- var right = this.ChartBorder.GetRightEx();
1493
- var bottom = this.ChartBorder.GetBottom();
1494
-
1495
- var xPrev = null; //上一个坐标x的值
1496
- for (var i in this.VerticalInfo) {
1497
- var x = this.GetXFromIndex(this.VerticalInfo[i].Value);
1498
- if (x > bottom) break;
1499
- if (xPrev != null && Math.abs(x - xPrev) < this.MinXDistance) continue;
1500
-
1501
- this.Canvas.strokeStyle = this.VerticalInfo[i].LineColor;
1502
- this.Canvas.beginPath();
1503
- this.Canvas.moveTo(left, ToFixedPoint(x));
1504
- this.Canvas.lineTo(right, ToFixedPoint(x));
1505
- this.Canvas.stroke();
1506
-
1507
- if (this.VerticalInfo[i].Message[0] != null) {
1508
- if (this.VerticalInfo[i].Font != null)
1509
- this.Canvas.font = this.VerticalInfo[i].Font;
1510
-
1511
- this.Canvas.fillStyle = this.VerticalInfo[i].TextColor;
1512
- var testWidth = this.Canvas.measureText(this.VerticalInfo[i].Message[0]).width;
1513
- if (x < testWidth / 2) {
1514
- this.Canvas.textAlign = "left";
1515
- this.Canvas.textBaseline = "top";
1516
- }
1517
- else if ((x + testWidth / 2) >= this.ChartBorder.GetChartHeight()) {
1518
- this.Canvas.textAlign = "right";
1519
- this.Canvas.textBaseline = "top";
1520
- }
1521
- else {
1522
- this.Canvas.textAlign = "center";
1523
- this.Canvas.textBaseline = "top";
1524
- }
1525
-
1526
- var xText = left, yText = x;
1527
- this.Canvas.save();
1528
- this.Canvas.translate(xText, yText);
1529
- this.Canvas.rotate(90 * Math.PI / 180);
1530
- this.Canvas.fillText(this.VerticalInfo[i].Message[0], 0, 0);
1531
- this.Canvas.restore();
1532
- }
1533
-
1534
- xPrev = x;
1535
- }
1536
- }
1537
- }
1538
-
1539
- function OverlayMinuteFrame()
1540
- {
1541
- this.newMethod=MinuteFrame; //派生
1542
- this.newMethod();
1543
- delete this.newMethod;
1544
-
1545
- this.ClassName="OverlayMinuteFrame";
1546
- this.IsShow=true; //坐标是否显示
1547
- this.IsShareY=false; //使用和主框架公用Y轴
1548
- this.IsCalculateYMaxMin=true; //是否计算Y最大最小值
1549
-
1550
- this.Draw=function()
1551
- {
1552
- this.SplitXYCoordinate();
1553
- if (this.IsShow)
1554
- {
1555
-
1556
- }
1557
-
1558
- this.SizeChange=false;
1559
- this.XYSplit=false;
1560
- }
1561
-
1562
- this.GetScaleTextWidth=function()
1563
- {
1564
- return { TextWidth:0 };
1565
- }
1566
-
1567
- //分割x,y轴坐标信息
1568
- this.SplitXYCoordinate=function()
1569
- {
1570
- if (this.XYSplit==false) return;
1571
-
1572
- if (this.IsShareY) //和主图指标共享Y轴坐标
1573
- {
1574
- this.HorizontalMax=this.MainFrame.HorizontalMax;
1575
- this.HorizontalMin=this.MainFrame.HorizontalMin;
1576
- this.HorizontalInfo=[];
1577
- for(var i=0; i<this.MainFrame.HorizontalInfo.length; ++i)
1578
- {
1579
- var item=this.MainFrame.HorizontalInfo[i];
1580
- this.HorizontalInfo.push(item);
1581
- }
1582
- }
1583
- else //独立Y轴坐标
1584
- {
1585
- if (this.YSplitOperator!=null) this.YSplitOperator.Operator();
1586
- }
1587
- }
1588
- }
1589
-
1590
- function OverlayMinuteHScreenFrame()
1591
- {
1592
- this.newMethod=MinuteHScreenFrame; //派生
1593
- this.newMethod();
1594
- delete this.newMethod;
1595
-
1596
- this.ClassName="OverlayMinuteHScreenFrame";
1597
- this.IsShow=true; //坐标是否显示
1598
-
1599
- this.Draw=function()
1600
- {
1601
- this.SplitXYCoordinate();
1602
- if (this.IsShow)
1603
- {
1604
-
1605
- }
1606
-
1607
- this.SizeChange=false;
1608
- this.XYSplit=false;
1609
- }
1610
-
1611
- //分割x,y轴坐标信息
1612
- this.SplitXYCoordinate=function()
1613
- {
1614
- if (this.XYSplit==false) return;
1615
-
1616
- if (this.IsShareY) //和主图指标共享Y轴坐标
1617
- {
1618
- this.HorizontalMax=this.MainFrame.HorizontalMax;
1619
- this.HorizontalMin=this.MainFrame.HorizontalMin;
1620
- this.HorizontalInfo=[];
1621
- for(var i=0; i<this.MainFrame.HorizontalInfo.length; ++i)
1622
- {
1623
- var item=this.MainFrame.HorizontalInfo[i];
1624
- this.HorizontalInfo.push(item);
1625
- }
1626
- }
1627
- else //独立Y轴坐标
1628
- {
1629
- if (this.YSplitOperator!=null) this.YSplitOperator.Operator();
1630
- }
1631
- }
1632
- }
1633
-
1634
-
1635
- //缩放因子
1636
- var ZOOM_SEED = //0=柱子宽度 1=间距
1637
- [
1638
- [48, 10], [44, 10],
1639
- [40, 9], [36, 9],
1640
- [32, 8], [28, 8],
1641
- [24, 7], [20, 7],
1642
- [18, 6], [17, 6],
1643
- [15, 5], [13, 5],
1644
- [9, 4], [5, 4], [3, 3],
1645
- [3, 1], [2,1], [1,1], [1,0]
1646
- /*
1647
- [49, 10], [46, 9], [43, 8],
1648
- [41, 7.5], [39, 7], [37, 6],
1649
- [31, 5.5], [27, 5], [23, 4.5],
1650
- [21, 4], [18, 3.5], [16, 3],
1651
- [13, 2.5], [11, 2], [8, 1.5],
1652
- [6, 1], [3, 0.6], [2.2, 0.5],
1653
- */
1654
- //太多了卡,
1655
- //[1.1,0.3],
1656
- //[0.9,0.2], [0.7,0.15],
1657
- //[0.6,0.12], [0.5,0.1], [0.4,0.08],
1658
- //[0.3,0.06], [0.2,0.04], [0.1,0.02]
1659
- ];
1660
-
1661
- //K线框架
1662
- function KLineFrame()
1663
- {
1664
- this.newMethod = AverageWidthFrame; //派生
1665
- this.newMethod();
1666
- delete this.newMethod;
1667
-
1668
- this.ClassName='KLineFrame';
1669
- this.ToolbarID = Guid(); //工具条Div id
1670
- this.ModifyIndex = true; //是否显示'改参数'菜单
1671
- this.ChangeIndex = true; //是否显示'换指标'菜单
1672
- this.CustomHorizontalInfo = [];
1673
-
1674
- this.LastCalculateStatus = { Width: 0, XPointCount: 0 }; //最后一次计算宽度的状态
1675
-
1676
- //定制X轴刻度
1677
- //Type:0, Date:, Time: , Name:名字, Line:{ Color:线段颜色, Type:线段类型 0 直线 1 虚线 }
1678
- //Type: 1, Space: 第几个空白间距, Name:名字, Line: { Color: 线段颜色, Type: 线段类型 0 直线 1 虚线 }
1679
- this.CustomVerticalInfo = [];
1680
- this.DrawCustomVerticalEvent;
1681
- this.RightSpaceCount = 0;
1682
-
1683
- this.DrawFrame = function ()
1684
- {
1685
- if (this.IsMinSize) return;
1686
-
1687
- this.SplitXYCoordinate();
1688
- if (this.SizeChange == true) this.CalculateDataWidth();
1689
- if (this.DrawOtherChart) this.DrawOtherChart();
1690
-
1691
- this.DrawTitleBG();
1692
- this.DrawHorizontal();
1693
- this.DrawVertical();
1694
- }
1695
-
1696
- this.GetXFromIndex = function (index)
1697
- {
1698
- if (index < 0) index = 0;
1699
- if (index > this.xPointCount - 1) index = this.xPointCount - 1;
1700
-
1701
- var offset = this.ChartBorder.GetLeft() + g_JSChartResource.FrameLeftMargin + this.DistanceWidth / 2 + this.DataWidth / 2;
1702
- for (var i = 1; i <= index; ++i) { offset += this.DistanceWidth + this.DataWidth; }
1703
- return offset;
1704
- }
1705
-
1706
- //X坐标转x轴数值
1707
- this.GetXData = function (x)
1708
- {
1709
- if (x <= this.ChartBorder.GetLeft()) return 0;
1710
- if (x >= this.ChartBorder.GetRight()) return this.XPointCount-1;
1711
-
1712
- var left=this.ChartBorder.GetLeft()+g_JSChartResource.FrameLeftMargin;
1713
- var right=this.ChartBorder.GetRight()-g_JSChartResource.FrameRightMargin;
1714
- var distanceWidth = this.DistanceWidth;
1715
- var dataWidth = this.DataWidth;
1716
-
1717
- var index = 0;
1718
- var xPoint = left + distanceWidth/2 + dataWidth + distanceWidth;
1719
- while (xPoint < right && index < 10000 && index+1<this.XPointCount ) //自己算x的数值
1720
- {
1721
- if (xPoint > x) break;
1722
- xPoint += (dataWidth + distanceWidth);
1723
- ++index;
1724
- }
1725
-
1726
- //var test=(x-this.ChartBorder.GetLeft())*(this.XPointCount*1.0/this.ChartBorder.GetWidth());
1727
- return index;
1728
- }
1729
-
1730
- this.DrawCustomHorizontal = function () //Y轴刻度定制显示
1731
- {
1732
- if (this.IsMinSize) return;
1733
- for (var i=0; i<this.CustomHorizontalInfo.length; ++i)
1734
- {
1735
- var item = this.CustomHorizontalInfo[i];
1736
- switch (item.Type)
1737
- {
1738
- case 0: //最新价格刻度
1739
- case 1: //固定价格刻度
1740
- this.DrawCustomItem(item);
1741
- break;
1742
- case 2: //当前屏最后一个K线价格刻度
1743
- case 3: //主图K线涨幅刻度
1744
- case 4: //叠加K线涨幅刻度
1745
- this.DrawCustomItem(item);
1746
- }
1747
- }
1748
- }
1749
-
1750
- this.DrawCustomVerticalItem = function (item) {
1751
- this.Canvas.save();
1752
- if (item.Data.Line.Type == 1) this.Canvas.setLineDash([5, 5]); //虚线
1753
- this.Canvas.strokeStyle = item.Data.Line.Color;
1754
- this.Canvas.beginPath();
1755
- if (item.IsHScreen) {
1756
- this.Canvas.moveTo(item.Top, ToFixedPoint(item.X));
1757
- this.Canvas.lineTo(item.Bottom, ToFixedPoint(item.X));
1758
- }
1759
- else {
1760
- this.Canvas.moveTo(ToFixedPoint(item.X), item.Top);
1761
- this.Canvas.lineTo(ToFixedPoint(item.X), item.Bottom);
1762
- }
1763
- this.Canvas.stroke();
1764
- this.Canvas.restore();
1765
- }
1766
-
1767
- this.DrawCustomVertical = function () //X轴定制刻度显示
1768
- {
1769
- if (!this.CustomVerticalInfo) return;
1770
- if (this.CustomVerticalInfo.length <= 0) return;
1771
- if (!this.Data) return;
1772
-
1773
- var isHScreen = this.IsHScreen;
1774
- var top = this.ChartBorder.GetTopEx();
1775
- var bottom = this.ChartBorder.GetBottomEx();
1776
-
1777
- var dataWidth = this.DataWidth;
1778
- var distanceWidth = this.DistanceWidth;
1779
- var xOffset = this.ChartBorder.GetLeft() + distanceWidth / 2.0 + 2.0;
1780
-
1781
- if (isHScreen)
1782
- {
1783
- xOffset = this.ChartBorder.GetTop() + distanceWidth / 2.0 + 2.0;
1784
- top = this.ChartBorder.GetLeftEx();
1785
- bottom = this.ChartBorder.GetRightEx();
1786
- }
1787
-
1788
- var j = 0;
1789
- for (var i = this.Data.DataOffset; i < this.Data.Data.length && j < this.XPointCount; ++i, ++j, xOffset += (dataWidth + distanceWidth))
1790
- {
1791
- var kItem = this.Data.Data[i];
1792
- for (var k in this.CustomVerticalInfo)
1793
- {
1794
- var item = this.CustomVerticalInfo[k];
1795
- if (item.Type != 0) continue;
1796
-
1797
- if (IFrameSplitOperator.IsNumber(item.Time))
1798
- {
1799
- if (kItem.Date != item.Date || kItem.Time != item.Time) continue;
1800
- }
1801
- else
1802
- {
1803
- if (kItem.Date != item.Date) continue;
1804
- }
1805
-
1806
- var left = xOffset;
1807
- var right = xOffset + dataWidth;
1808
- var x = left + (right - left) / 2;
1809
-
1810
- var DrawData = { X: x, Top: top, Bottom: bottom, Data: item, IsHScreen: isHScreen };
1811
- this.DrawCustomVerticalItem(DrawData);
1812
- if (this.DrawCustomVerticalEvent)
1813
- this.DrawCustomVerticalEvent.Callback(this.DrawCustomVerticalEvent, DrawData, this);
1814
-
1815
- break;
1816
- }
1817
- }
1818
-
1819
- for (var i = 1; j < this.XPointCount; ++i, ++j, xOffset += (dataWidth + distanceWidth))
1820
- {
1821
- for (var k in this.CustomVerticalInfo)
1822
- {
1823
- var item = this.CustomVerticalInfo[k];
1824
- if (item.Type != 1) continue;
1825
- if (item.Space != i) continue;
1826
-
1827
- var left = xOffset;
1828
- var right = xOffset + dataWidth;
1829
- var x = left + (right - left) / 2;
1830
-
1831
- var DrawData = { X: x, Top: top, Bottom: bottom, Data: item, IsHScreen: isHScreen };
1832
- this.DrawCustomVerticalItem(DrawData);
1833
- if (this.DrawCustomVerticalEvent)
1834
- this.DrawCustomVerticalEvent.Callback(this.DrawCustomVerticalEvent, DrawData, this);
1835
-
1836
- break;
1837
- }
1838
- }
1839
- }
1840
-
1841
- this.CalculateDataWidth = function () //计算数据宽度
1842
- {
1843
- if (this.XPointCount < 2) return;
1844
- var width = this.GetFrameWidth() - g_JSChartResource.FrameMargin; //预留4个像素 防止最后1个柱子不够画
1845
-
1846
- if (this.ZoomIndex>=0 && this.LastCalculateStatus.Width==width && this.LastCalculateStatus.XPointCount==this.XPointCount) //宽度没变 尝试使用原来的柱子宽度
1847
- {
1848
- var caclWidth=(this.DistanceWidth/2+g_JSChartResource.FrameLeftMargin)+(this.DataWidth + this.DistanceWidth)*(this.XPointCount-1);
1849
- var caclWidth2=(this.DataWidth + this.DistanceWidth) * this.XPointCount;
1850
- if (caclWidth<= width) //当前的柱子宽度够用 就不调整了
1851
- return;
1852
- }
1853
-
1854
- this.LastCalculateStatus.Width=width;
1855
- this.LastCalculateStatus.XPointCount=this.XPointCount;
1856
-
1857
- for (var i = 0; i < ZOOM_SEED.length; ++i)
1858
- {
1859
- let barWidth = ZOOM_SEED[i][0]; //数据宽度
1860
- let distanceWidth = ZOOM_SEED[i][1]; //间距宽度
1861
- if ((ZOOM_SEED[i][0] + ZOOM_SEED[i][1]) * this.XPointCount < width)
1862
- {
1863
- this.ZoomIndex = i;
1864
- this.DataWidth = ZOOM_SEED[i][0];
1865
- this.DistanceWidth = ZOOM_SEED[i][1];
1866
- this.TrimKLineDataWidth(width);
1867
-
1868
- JSConsole.Chart.Log(`[KLineFrame::CalculateDataWidth] ZoomIndex=${this.ZoomIndex} DataWidth=${this.DataWidth} DistanceWidth=${this.DistanceWidth}` );
1869
- return;
1870
- }
1871
- }
1872
-
1873
- //太多了 就平均分了
1874
- this.ZoomIndex = ZOOM_SEED.length - 1;
1875
- this.DataWidth = width / this.XPointCount;
1876
- this.DistanceWidth = 0;
1877
- }
1878
-
1879
- this.OnSize=function(obj)
1880
- {
1881
- var width=this.GetFrameWidth()-g_JSChartResource.FrameMargin;
1882
- var xPointCount=0;
1883
- var y=this.DistanceWidth/2+g_JSChartResource.FrameLeftMargin+(this.DataWidth+this.DistanceWidth);
1884
- for(;y<width; y+=(this.DataWidth+this.DistanceWidth), ++xPointCount) { }
1885
-
1886
- obj.CurCount=this.XPointCount;
1887
- obj.CalcCount=xPointCount;
1888
- obj.DataWidth=this.DataWidth;
1889
- obj.DistanceWidth=this.DistanceWidth;
1890
- obj.Changed=false;
1891
-
1892
- this.LastCalculateStatus.Width=width;
1893
- if (obj.CurCount==obj.CalcCount) return obj;
1894
-
1895
- this.XPointCount=xPointCount;
1896
- this.LastCalculateStatus.XPointCount=this.XPointCount;
1897
- if (this.Data)
1898
- {
1899
- this.Data.DataOffset+=(obj.CurCount-obj.CalcCount);
1900
- if (this.Data.DataOffset<0) this.Data.DataOffset=0;
1901
- obj.Changed=true;
1902
- }
1903
- return obj;
1904
- }
1905
-
1906
- this.SetDataWidth=function(dataWidth)
1907
- {
1908
- var zoomIndex=ZOOM_SEED.length-1;
1909
- for(var i in ZOOM_SEED)
1910
- {
1911
- var item=ZOOM_SEED[i];
1912
- if (item[0]<=dataWidth)
1913
- {
1914
- zoomIndex=parseInt(i)-1;
1915
- break;
1916
- }
1917
- }
1918
-
1919
- this.ZoomIndex=zoomIndex;
1920
- this.DataWidth=ZOOM_SEED[this.ZoomIndex][0];
1921
- this.DistanceWidth=ZOOM_SEED[this.ZoomIndex][1];
1922
- var width=this.GetFrameWidth()-g_JSChartResource.FrameMargin;
1923
- var xPointCount=0;
1924
- var y=this.DistanceWidth/2+g_JSChartResource.FrameLeftMargin+(this.DataWidth+this.DistanceWidth);
1925
- for(;y<=width; y+=(this.DataWidth+this.DistanceWidth), ++xPointCount) { }
1926
-
1927
- this.XPointCount=xPointCount;
1928
- this.LastCalculateStatus.XPointCount=this.XPointCount;
1929
- this.LastCalculateStatus.Width=width;
1930
-
1931
- var obj={ XPointCount:this.XPointCount, DataWidth:this.DataWidth, DistanceWidth:this.DistanceWidth };
1932
- return obj;
1933
- }
1934
-
1935
- this.TrimKLineDataWidth = function (width)
1936
- {
1937
- var zoom = ZOOM_SEED[this.ZoomIndex];
1938
- var dataWidth = ZOOM_SEED[this.ZoomIndex][0];
1939
- var distanceWidth = ZOOM_SEED[this.ZoomIndex][1];
1940
- if (dataWidth == 1 && distanceWidth == 0)
1941
- {
1942
- this.DataWidth = width / this.XPointCount;
1943
- return;
1944
- }
1945
-
1946
- while(true)
1947
- {
1948
- if((this.DistanceWidth + this.DataWidth) * this.XPointCount + this.DistanceWidth > width)
1949
- {
1950
- this.DistanceWidth -= 0.01;
1951
- break;
1952
- }
1953
- this.DistanceWidth += 0.01;
1954
- }
1955
- /*
1956
- if (zoom[0]<4) //最后2个缩放,调整间距不调整数据宽度, 数据都是画竖线的
1957
- {
1958
- while (true)
1959
- {
1960
- if ((this.DistanceWidth + this.DataWidth) * this.XPointCount + this.DistanceWidth > width)
1961
- {
1962
- this.DistanceWidth -= 0.01;
1963
- break;
1964
- }
1965
- this.DistanceWidth += 0.01;
1966
- }
1967
- }
1968
- else
1969
- {
1970
- while (true)
1971
- {
1972
- if ((this.DistanceWidth + this.DataWidth) * this.XPointCount + this.DistanceWidth > width)
1973
- {
1974
- this.DataWidth -= 0.01;
1975
- break;
1976
- }
1977
- this.DataWidth += 0.01;
1978
- }
1979
- }
1980
- */
1981
- }
1982
-
1983
- this.IsOverlayMaxMin = function (obj) //当前坐标信息 是否覆盖最大 最小值输出
1984
- {
1985
- if (!this.ChartKLine) return false;
1986
- if (!this.ChartKLine.Max || !this.ChartKLine.Min) return false;
1987
-
1988
- var textWidth = this.Canvas.measureText(obj.Text.Value).width + 4; //刻度文字宽度
1989
- var max = this.ChartKLine.Max, min = this.ChartKLine.Min;
1990
- var isOverlayMax = false, isOverlayMin = false;
1991
- const textHeight = 20; //字体高度
1992
- if (max.X >= obj.X && max.X <= obj.X + textWidth)
1993
- {
1994
- var y1 = max.Y + textHeight, y2 = max.Y - textHeight;
1995
- if ((y1 >= obj.Y - textHeight && y1 <= obj.Y + textHeight) || (y2 >= obj.Y - textHeight && y2 <= obj.Y + textHeight))
1996
- isOverlayMax = true;
1997
- }
1998
-
1999
- if (isOverlayMax == true) return true;
2000
-
2001
- if (min.X >= obj.X && min.X <= obj.X + textWidth) //最小值X 坐标不在 刻度文字范围内
2002
- {
2003
- var y1 = min.Y + textHeight, y2 = min.Y - textHeight;
2004
- if ((y1 >= obj.Y - textHeight && y1 <= obj.Y + textHeight) || (y2 >= obj.Y - textHeight && y2 <= obj.Y + textHeight))
2005
- isOverlayMin = true;
2006
- }
2007
-
2008
- return isOverlayMax || isOverlayMin;
2009
- }
2010
-
2011
- //分割x,y轴坐标信息
2012
- this.SplitXYCoordinate = function ()
2013
- {
2014
- if (this.XYSplit == false) return;
2015
- if (this.YSplitOperator != null) this.YSplitOperator.Operator();
2016
- if (this.XSplitOperator != null) this.XSplitOperator.Operator();
2017
- }
2018
-
2019
- this.CalculateCount = function (zoomIndex)
2020
- {
2021
- var width = this.GetFrameWidth() - g_JSChartResource.FrameMargin;
2022
- return parseInt(width / (ZOOM_SEED[zoomIndex][0] + ZOOM_SEED[zoomIndex][1]));
2023
- }
2024
-
2025
- this.ZoomUp = function (cursorIndex)
2026
- {
2027
- if (this.ZoomIndex <= 0) return false;
2028
- if (this.Data.DataOffset < 0) return false;
2029
- var dataCount = this.Data.Data.length;
2030
- var maxDataCount = dataCount + this.RightSpaceCount;
2031
-
2032
- var rightSpaceCount = 0;
2033
- var lastDataIndex = this.Data.DataOffset + this.XPointCount - 1; //最右边的数据索引
2034
- var lastCursorIndex = this.Data.DataOffset + cursorIndex.Index;
2035
-
2036
- if (lastDataIndex >= dataCount)
2037
- {
2038
- rightSpaceCount = lastDataIndex - (this.Data.Data.length - 1); //计算右边预留空间
2039
- lastDataIndex = this.Data.Data.length - 1;
2040
- if (rightSpaceCount > this.RightSpaceCount) rightSpaceCount = this.RightSpaceCount;
2041
- }
2042
-
2043
- var xPointCount = this.CalculateCount(this.ZoomIndex-1);
2044
-
2045
- --this.ZoomIndex;
2046
- this.XPointCount = xPointCount;
2047
- if (cursorIndex.IsLockRight==true) //固定右边
2048
- {
2049
- var rightDataIndex=this.Data.DataOffset + this.XPointCount; //最右边的数据索引
2050
- if (xPointCount>rightDataIndex)
2051
- {
2052
- xPointCount=rightDataIndex;
2053
- this.XPointCount=xPointCount;
2054
- this.Data.DataOffset=0;
2055
- }
2056
- else
2057
- {
2058
- var dataOffset=lastDataIndex - (xPointCount-rightSpaceCount)+1;
2059
- this.XPointCount=xPointCount;
2060
- this.Data.DataOffset=dataOffset;
2061
- if (this.Data.DataOffset<0) this.Data.DataOffset=0;
2062
- }
2063
- }
2064
- else if (xPointCount >= maxDataCount)
2065
- {
2066
- xPointCount = maxDataCount;
2067
- this.XPointCount = xPointCount;
2068
- this.Data.DataOffset = 0;
2069
- }
2070
- else
2071
- {
2072
- this.XPointCount = xPointCount;
2073
- this.Data.DataOffset = lastDataIndex - (this.XPointCount - rightSpaceCount) + 1;
2074
- if (this.Data.DataOffset<0)
2075
- {
2076
- JSConsole.Chart.Log(`[KLineFrame::ZoomDown] this.Data.DataOffset=${this.Data.DataOffset}, reset this.Data.DataOffset=0`);
2077
- this.Data.DataOffset=0;
2078
- }
2079
- }
2080
-
2081
- this.DataWidth = ZOOM_SEED[this.ZoomIndex][0];
2082
- this.DistanceWidth = ZOOM_SEED[this.ZoomIndex][1];
2083
- var width = this.GetFrameWidth() - g_JSChartResource.FrameMargin;
2084
- this.TrimKLineDataWidth(width);
2085
-
2086
- this.LastCalculateStatus.XPointCount = this.XPointCount;
2087
- cursorIndex.Index = lastCursorIndex - this.Data.DataOffset;
2088
-
2089
- return true;
2090
- }
2091
-
2092
- this.ZoomDown = function (cursorIndex)
2093
- {
2094
- if (this.ZoomIndex + 1 >= ZOOM_SEED.length) return false;
2095
- if (this.Data.DataOffset < 0) return false;
2096
- if (this.Data.DataOffset<=0 && cursorIndex.IsLockRight==true) return false;
2097
- var dataCount = this.Data.Data.length;
2098
- var maxDataCount = dataCount + this.RightSpaceCount;
2099
- //if (this.XPointCount >= dataCount) return false;
2100
-
2101
- var rightSpaceCount = 0;
2102
- var lastDataIndex = this.Data.DataOffset + this.XPointCount - 1; //最右边的数据索引
2103
- if (lastDataIndex >= this.Data.Data.length)
2104
- {
2105
- rightSpaceCount = lastDataIndex - (this.Data.Data.length - 1); //计算右边预留空间
2106
- lastDataIndex = this.Data.Data.length - 1;
2107
- if (rightSpaceCount > this.RightSpaceCount) rightSpaceCount = this.RightSpaceCount;
2108
- }
2109
-
2110
- var xPointCount = this.CalculateCount(this.ZoomIndex + 1);
2111
- var lastCursorIndex = this.Data.DataOffset + cursorIndex.Index;
2112
-
2113
- ++this.ZoomIndex;
2114
- if (cursorIndex.IsLockRight==true) //固定右边
2115
- {
2116
- var rightDataIndex=this.Data.DataOffset + this.XPointCount; //最右边的数据索引
2117
- if (xPointCount>rightDataIndex)
2118
- {
2119
- xPointCount=rightDataIndex;
2120
- this.XPointCount=xPointCount;
2121
- this.Data.DataOffset=0;
2122
- }
2123
- else
2124
- {
2125
- var dataOffset=lastDataIndex - (xPointCount-rightSpaceCount)+1;
2126
- this.XPointCount=xPointCount;
2127
- this.Data.DataOffset=dataOffset;
2128
- if (this.Data.DataOffset<0) this.Data.DataOffset=0;
2129
- }
2130
- }
2131
- else if (xPointCount >= maxDataCount)
2132
- {
2133
- //xPointCount = maxDataCount;
2134
- this.XPointCount = xPointCount;
2135
- this.Data.DataOffset = 0;
2136
- }
2137
- else
2138
- {
2139
- this.XPointCount = xPointCount;
2140
- this.Data.DataOffset = lastDataIndex - (this.XPointCount - rightSpaceCount) + 1;
2141
- if (this.Data.DataOffset<0)
2142
- {
2143
- JSConsole.Chart.Log(`[KLineFrame::ZoomDown] this.Data.DataOffset=${this.Data.DataOffset}, reset this.Data.DataOffset=0`);
2144
- this.Data.DataOffset=0;
2145
- }
2146
-
2147
- }
2148
-
2149
- this.DataWidth = ZOOM_SEED[this.ZoomIndex][0];
2150
- this.DistanceWidth = ZOOM_SEED[this.ZoomIndex][1];
2151
- var width = this.GetFrameWidth() - g_JSChartResource.FrameMargin;
2152
- this.TrimKLineDataWidth(width);
2153
-
2154
- this.LastCalculateStatus.XPointCount = this.XPointCount;
2155
- cursorIndex.Index = lastCursorIndex - this.Data.DataOffset;
2156
-
2157
- return true;
2158
- }
2159
-
2160
- this.GetFrameWidth = function ()
2161
- {
2162
- if (this.IsHScreen) return this.ChartBorder.GetHeight();
2163
- return this.ChartBorder.GetWidth();
2164
- }
2165
-
2166
- this.SetXShowCount=function(showCount)
2167
- {
2168
- var index=-1;
2169
- var width=this.GetFrameWidth()-g_JSChartResource.FrameMargin;
2170
- for(var i=0; i<ZOOM_SEED.length; ++i)
2171
- {
2172
- var item=ZOOM_SEED[i];
2173
- var dataWidth=item[0];
2174
- var distanceWidth=item[1];
2175
- var width=this.GetFrameWidth()-g_JSChartResource.FrameMargin-distanceWidth/2;
2176
-
2177
- var value=parseInt((width-distanceWidth/2)/(dataWidth + distanceWidth));
2178
- if (value>=showCount)
2179
- {
2180
- index=i;
2181
- this.XPointCount=showCount;
2182
- this.ZoomIndex=index;
2183
- this.DataWidth=dataWidth;
2184
- this.DistanceWidth=distanceWidth;
2185
- if (dataWidth==1 && distanceWidth==0)
2186
- this.DataWidth=width/this.XPointCount;
2187
- this.LastCalculateStatus.XPointCount=this.XPointCount;
2188
- this.LastCalculateStatus.Width=width;
2189
-
2190
- return;
2191
- }
2192
- }
2193
-
2194
- //太多了 就平均分了
2195
- this.XPointCount=showCount;
2196
- this.ZoomIndex=ZOOM_SEED.length-1;
2197
- this.DataWidth=width/this.XPointCount;
2198
- this.DistanceWidth=0;
2199
- this.LastCalculateStatus.XPointCount=this.XPointCount;
2200
- this.LastCalculateStatus.Width=width;
2201
- }
2202
- }
2203
-
2204
- //K线横屏框架
2205
- function KLineHScreenFrame()
2206
- {
2207
- this.newMethod = KLineFrame; //派生
2208
- this.newMethod();
2209
- delete this.newMethod;
2210
-
2211
- this.ClassName='KLineHScreenFrame';
2212
- this.IsHScreen = true; //是否是横屏
2213
-
2214
- this.DrawInsideHorizontal = function ()
2215
- {
2216
- if (this.IsMinSize) return;
2217
- if (this.IsShowYText[0] === false && this.IsShowYText[1] === false) return;
2218
-
2219
- var left = this.ChartBorder.GetLeft();
2220
- var right = this.ChartBorder.GetRightEx();
2221
- var top = this.ChartBorder.GetTop();
2222
- var bottom = this.ChartBorder.GetBottom();
2223
- var borderTop = this.ChartBorder.Top;
2224
- var borderBottom = this.ChartBorder.Bottom;
2225
- var titleHeight = this.ChartBorder.TitleHeight;
2226
- var pixelTatio = 1;
2227
-
2228
- var isDrawLeft = (borderTop < 10 * pixelTatio || this.YTextPosition[0] == 2) && this.IsShowYText[0] === true;
2229
- var isDrawRight = (borderBottom < 10 * pixelTatio || this.YTextPosition[1] == 2) && this.IsShowYText[1] === true;
2230
-
2231
- if (isDrawLeft || isDrawRight)
2232
- {
2233
- var yPrev = null; //上一个坐标y的值
2234
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从上往下画分割线
2235
- {
2236
- var item = this.HorizontalInfo[i];
2237
- var y = this.GetYFromData(item.Value);
2238
- if (y != null && yPrev != null && Math.abs(y - yPrev) < this.MinYDistance) continue; //两个坐标在近了 就不画了
2239
-
2240
- //坐标信息 左边 间距小于10 画在内部
2241
- if (item.Message[0] != null && isDrawLeft)
2242
- {
2243
- if (item.Font != null) this.Canvas.font = item.Font;
2244
- this.Canvas.fillStyle = item.TextColor;
2245
- this.Canvas.textAlign = "left";
2246
- if (y >= right - 2) this.Canvas.textBaseline = 'top';
2247
- else if (y <= left + 2) this.Canvas.textBaseline = 'bottom';
2248
- else this.Canvas.textBaseline = "middle";
2249
-
2250
- var textObj = { X: left, Y: y, Text: { BaseLine: this.Canvas.textBaseline, TextAlign: this.Canvas.textAlign, Font: this.Canvas.font, Value: item.Message[0] } };
2251
- var xText = y, yText = top;
2252
- this.Canvas.save();
2253
- this.Canvas.translate(xText, yText);
2254
- this.Canvas.rotate(90 * Math.PI / 180);
2255
- this.Canvas.fillText(item.Message[0], 2, 0);
2256
- this.Canvas.restore();
2257
- }
2258
-
2259
- if (item.Message[1] != null && isDrawRight)
2260
- {
2261
- if (item.Font != null) this.Canvas.font = item.Font;
2262
- this.Canvas.fillStyle = item.TextColor;
2263
- this.Canvas.textAlign = "right";
2264
- if (y >= right - 2) this.Canvas.textBaseline = 'top';
2265
- else if (y <= left + 2) this.Canvas.textBaseline = 'bottom';
2266
- else this.Canvas.textBaseline = "middle";
2267
- var textWidth = this.Canvas.measureText(item.Message[1]).width;
2268
- var textObj = { X: right - textWidth, Y: y, Text: { BaseLine: this.Canvas.textBaseline, TextAlign: this.Canvas.textAlign, Font: this.Canvas.font, Value: item.Message[1] } };
2269
-
2270
- var xText = y, yText = bottom;
2271
- this.Canvas.save();
2272
- this.Canvas.translate(xText, yText);
2273
- this.Canvas.rotate(90 * Math.PI / 180);
2274
- this.Canvas.fillText(item.Message[1], -2, 0);
2275
- this.Canvas.restore();
2276
- }
2277
- yPrev = y;
2278
- }
2279
- }
2280
- }
2281
-
2282
- //画标题背景色
2283
- this.DrawTitleBG = function ()
2284
- {
2285
- /*
2286
- if (this.ChartBorder.TitleHeight <= 0) return;
2287
-
2288
- var left = ToFixedPoint(this.ChartBorder.GetRightEx());
2289
- var top = ToFixedPoint(this.ChartBorder.GetTop());
2290
- var bottom = ToFixedPoint(this.ChartBorder.GetBottom());
2291
- var width = this.ChartBorder.TitleHeight;
2292
- var height = bottom - top;
2293
-
2294
- this.Canvas.fillStyle = this.TitleBGColor;
2295
- this.Canvas.fillRect(left, top, width, height);
2296
- */
2297
- }
2298
-
2299
- this.GetYFromData = function (value)
2300
- {
2301
- if (value <= this.HorizontalMin) return this.ChartBorder.GetLeftEx();
2302
- if (value >= this.HorizontalMax) return this.ChartBorder.GetRightEx();
2303
-
2304
- var width = this.ChartBorder.GetWidthEx() * (value - this.HorizontalMin) / (this.HorizontalMax - this.HorizontalMin);
2305
- return this.ChartBorder.GetLeftEx() + width;
2306
- }
2307
-
2308
- //画Y轴
2309
- this.DrawHorizontal = function ()
2310
- {
2311
- var top = this.ChartBorder.GetTop();
2312
- var bottom = this.ChartBorder.GetBottom();
2313
- var borderTop = this.ChartBorder.Top;
2314
- var borderBottom = this.ChartBorder.Bottom;
2315
- var left=this.ChartBorder.GetLeft();
2316
-
2317
- var yPrev = null; //上一个坐标y的值
2318
- for (var i = this.HorizontalInfo.length - 1; i >= 0; --i) //从左往右画分割线
2319
- {
2320
- var item = this.HorizontalInfo[i];
2321
- var y = this.GetYFromData(item.Value);
2322
- if (y != null && Math.abs(y - yPrev) < 15) continue; //两个坐标在近了 就不画了
2323
-
2324
- if (y!=left)
2325
- {
2326
- if (item.LineType==2)
2327
- {
2328
- this.Canvas.strokeStyle = item.LineColor;
2329
- this.Canvas.setLineDash([5,5]); //虚线
2330
- this.Canvas.beginPath();
2331
- this.Canvas.moveTo(ToFixedPoint(y),top);
2332
- this.Canvas.lineTo(ToFixedPoint(y),bottom);
2333
- this.Canvas.stroke();
2334
- this.Canvas.setLineDash([]);
2335
- }
2336
- else if (item.LineType>0)
2337
- {
2338
- this.Canvas.strokeStyle = item.LineColor;
2339
- if (g_JSChartResource.FrameYLineDash)
2340
- {
2341
- this.Canvas.setLineDash(g_JSChartResource.FrameYLineDash); //虚线
2342
- this.Canvas.beginPath();
2343
- this.Canvas.moveTo(ToFixedPoint(y),top);
2344
- this.Canvas.lineTo(ToFixedPoint(y),bottom);
2345
- this.Canvas.stroke();
2346
- this.Canvas.setLineDash([]);
2347
- }
2348
- else
2349
- {
2350
- this.Canvas.beginPath();
2351
- this.Canvas.moveTo(ToFixedPoint(y), top);
2352
- this.Canvas.lineTo(ToFixedPoint(y), bottom);
2353
- this.Canvas.stroke();
2354
- }
2355
- }
2356
- }
2357
-
2358
- //坐标信息 左边 间距小于10 不画坐标
2359
- if (item.Message[0] != null && borderTop > 10 && this.IsShowYText[0] === true)
2360
- {
2361
- if (item.Font != null) this.Canvas.font = item.Font;
2362
-
2363
- this.Canvas.fillStyle = item.TextColor;
2364
- this.Canvas.textAlign = "right";
2365
- this.Canvas.textBaseline = "middle";
2366
-
2367
- var xText = y, yText = top;
2368
- this.Canvas.save();
2369
- this.Canvas.translate(xText, yText);
2370
- this.Canvas.rotate(90 * Math.PI / 180);
2371
- this.Canvas.fillText(item.Message[0], -2, 0);
2372
- this.Canvas.restore();
2373
- }
2374
-
2375
- //坐标信息 右边 间距小于10 不画坐标
2376
- if (item.Message[1] != null && borderBottom > 10 && this.IsShowYText[1] === true)
2377
- {
2378
- if (item.Font != null) this.Canvas.font = item.Font;
2379
-
2380
- this.Canvas.fillStyle = item.TextColor;
2381
- this.Canvas.textAlign = "left";
2382
- this.Canvas.textBaseline = "middle";
2383
- var xText = y, yText = bottom;
2384
- this.Canvas.save();
2385
- this.Canvas.translate(xText, yText);
2386
- this.Canvas.rotate(90 * Math.PI / 180);
2387
- this.Canvas.fillText(item.Message[1], 2, 0);
2388
- this.Canvas.restore();
2389
- }
2390
-
2391
- yPrev = y;
2392
- }
2393
- }
2394
-
2395
- this.GetXFromIndex = function (index)
2396
- {
2397
- if (index < 0) index = 0;
2398
- if (index > this.xPointCount - 1) index = this.xPointCount - 1;
2399
-
2400
- var offset = this.ChartBorder.GetTop() + g_JSChartResource.FrameLeftMargin + this.DistanceWidth / 2 + this.DataWidth / 2;
2401
- for (var i = 1; i <= index; ++i)
2402
- {
2403
- offset += this.DistanceWidth + this.DataWidth;
2404
- }
2405
-
2406
- return offset;
2407
- }
2408
-
2409
- //画X轴
2410
- this.DrawVertical = function ()
2411
- {
2412
- var left = this.ChartBorder.GetLeft();
2413
- var right = this.ChartBorder.GetRightTitle();
2414
- var bottom = this.ChartBorder.GetBottom();
2415
-
2416
- var xPrev = null; //上一个坐标x的值
2417
- for (var i in this.VerticalInfo)
2418
- {
2419
- var x = this.GetXFromIndex(this.VerticalInfo[i].Value);
2420
- if (x >= bottom) break;
2421
- if (xPrev != null && Math.abs(x - xPrev) < 80) continue;
2422
- var item=this.VerticalInfo[i];
2423
- if (item.LineType==2)
2424
- {
2425
- this.Canvas.setLineDash([5,5]);
2426
- this.Canvas.beginPath();
2427
- this.Canvas.moveTo(left, ToFixedPoint(x));
2428
- this.Canvas.lineTo(right, ToFixedPoint(x));
2429
- this.Canvas.stroke();
2430
- this.Canvas.setLineDash([]);
2431
- }
2432
- else if (item.LineType>0)
2433
- {
2434
- this.Canvas.strokeStyle = item.LineColor;
2435
- if (g_JSChartResource.FrameXLineDash)
2436
- {
2437
- this.Canvas.setLineDash(g_JSChartResource.FrameXLineDash);
2438
- this.Canvas.beginPath();
2439
- this.Canvas.moveTo(left, ToFixedPoint(x));
2440
- this.Canvas.lineTo(right, ToFixedPoint(x));
2441
- this.Canvas.stroke();
2442
- this.Canvas.setLineDash([]);
2443
- }
2444
- else
2445
- {
2446
- this.Canvas.beginPath();
2447
- this.Canvas.moveTo(left, ToFixedPoint(x));
2448
- this.Canvas.lineTo(right, ToFixedPoint(x));
2449
- this.Canvas.stroke();
2450
- }
2451
- }
2452
-
2453
- if (this.VerticalInfo[i].Message[0] != null)
2454
- {
2455
- if (this.VerticalInfo[i].Font != null)
2456
- this.Canvas.font = this.VerticalInfo[i].Font;
2457
-
2458
- this.Canvas.fillStyle = this.VerticalInfo[i].TextColor;
2459
- var testWidth = this.Canvas.measureText(this.VerticalInfo[i].Message[0]).width;
2460
- if (x < testWidth / 2)
2461
- {
2462
- this.Canvas.textAlign = "left";
2463
- this.Canvas.textBaseline = "top";
2464
- }
2465
- else
2466
- {
2467
- this.Canvas.textAlign = "center";
2468
- this.Canvas.textBaseline = "top";
2469
- }
2470
-
2471
- var xText = left, yText = x;
2472
- this.Canvas.save();
2473
- this.Canvas.translate(xText, yText);
2474
- this.Canvas.rotate(90 * Math.PI / 180);
2475
- this.Canvas.fillText(this.VerticalInfo[i].Message[0], 0, this.XBottomOffset);
2476
- this.Canvas.restore();
2477
- }
2478
-
2479
- xPrev = x;
2480
- }
2481
- }
2482
-
2483
- //Y坐标转y轴数值
2484
- this.GetYData = function (x)
2485
- {
2486
- if (x < this.ChartBorder.GetLeftEx()) return this.HorizontalMin;
2487
- if (x > this.ChartBorder.GetRightEx()) return this.HorizontalMax;
2488
-
2489
- return (x - this.ChartBorder.GetLeftEx()) / this.ChartBorder.GetWidthEx() * (this.HorizontalMax - this.HorizontalMin) + this.HorizontalMin;
2490
- }
2491
-
2492
- //X坐标转x轴数值
2493
- this.GetXData = function (y)
2494
- {
2495
- if (y <= this.ChartBorder.GetTop()) return 0;
2496
- if (y >= this.ChartBorder.GetBottom()) return this.XPointCount-1;
2497
-
2498
- var distanceWidth=this.DistanceWidth;
2499
- var dataWidth=this.DataWidth;
2500
- var left=this.ChartBorder.GetTop()+g_JSChartResource.FrameLeftMargin;
2501
- var right=this.ChartBorder.GetBottom()-g_JSChartResource.FrameRightMargin;
2502
-
2503
- var index=0;
2504
- var xPoint=left+distanceWidth/2+dataWidth+distanceWidth;
2505
- while(xPoint<right && index<10000 && index+1<this.XPointCount) //自己算x的数值
2506
- {
2507
- if (xPoint>=y) break;
2508
- xPoint+=(dataWidth+distanceWidth);
2509
- ++index;
2510
- }
2511
-
2512
- return index;
2513
- }
2514
-
2515
- }
2516
-
2517
-
2518
- function OverlayKLineFrame()
2519
- {
2520
- this.newMethod=KLineFrame; //派生
2521
- this.newMethod();
2522
- delete this.newMethod;
2523
-
2524
- this.ClassName='OverlayKLineFrame';
2525
-
2526
- this.MainFrame=null; //主框架
2527
- this.IsShareY=false; //使用和主框架公用Y轴
2528
- this.IsCalculateYMaxMin=true; //是否计算Y最大最小值
2529
- this.RightOffset=50;
2530
- this.PenBorder=g_JSChartResource.OverlayFrame.BolderPen; //'rgb(0,0,0)'
2531
- this.IsShow=false; //坐标是否显示
2532
- this.IsShowToolbar=true; //是否显示工具条
2533
- this.Title=null;
2534
- this.TitleColor=g_JSChartResource.OverlayFrame.TitleColor;
2535
- this.TitleFont=g_JSChartResource.OverlayFrame.TitleFont;
2536
-
2537
- this.KLineFrame_ReloadResource=this.ReloadResource;
2538
- this.ReloadResource=function(resource)
2539
- {
2540
- this.KLineFrame_ReloadResource(resource);
2541
-
2542
- if (!resource)
2543
- {
2544
- this.PenBorder=g_JSChartResource.OverlayFrame.BolderPen; //'rgb(0,0,0)'
2545
- this.TitleColor=g_JSChartResource.OverlayFrame.TitleColor;
2546
- this.TitleFont=g_JSChartResource.OverlayFrame.TitleFont;
2547
- }
2548
- }
2549
-
2550
- this.Draw=function()
2551
- {
2552
- this.Buttons=[];
2553
- if (this.ChartBorder.IsShowTitleOnly) return;
2554
- this.SplitXYCoordinate();
2555
-
2556
- if (this.IsShow)
2557
- {
2558
- this.DrawVertical();
2559
- this.DrawHorizontal();
2560
- }
2561
-
2562
- this.SizeChange=false;
2563
- this.XYSplit=false;
2564
- }
2565
-
2566
- this.GetScaleTextWidth=function()
2567
- {
2568
- return { TextWidth:0 };
2569
- }
2570
-
2571
- //分割x,y轴坐标信息
2572
- this.SplitXYCoordinate=function()
2573
- {
2574
- if (this.XYSplit==false) return;
2575
-
2576
- if (this.IsShareY) //和主图指标共享Y轴坐标
2577
- {
2578
- this.HorizontalMax=this.MainFrame.HorizontalMax;
2579
- this.HorizontalMin=this.MainFrame.HorizontalMin;
2580
- this.HorizontalInfo=[];
2581
- for(var i in this.MainFrame.HorizontalInfo)
2582
- {
2583
- var item=this.MainFrame.HorizontalInfo[i];
2584
- this.HorizontalInfo.push(item);
2585
- }
2586
-
2587
- this.CoordinateType=this.MainFrame.CoordinateType;
2588
- }
2589
- else //独立Y轴坐标
2590
- {
2591
- if (this.YSplitOperator!=null) this.YSplitOperator.Operator();
2592
- }
2593
- }
2594
-
2595
- //画Y轴
2596
- this.DrawHorizontal=function()
2597
- {
2598
- var border=this.ChartBorder.GetBorder();
2599
- var left=border.Left;
2600
- var right=border.Right;
2601
- var bottom = border.Bottom;
2602
- var top = this.ChartBorder.GetTopTitle();
2603
- var borderRight=this.ChartBorder.Right;
2604
- right+=this.RightOffset;
2605
-
2606
- var yPrev=null; //上一个坐标y的值
2607
- for(var i=this.HorizontalInfo.length-1; i>=0; --i) //从上往下画分割线
2608
- {
2609
- var item=this.HorizontalInfo[i];
2610
- var y=this.GetYFromData(item.Value);
2611
- if (y!=null && Math.abs(y-yPrev)<this.MinYDistance) continue; //两个坐标在近了 就不画了
2612
-
2613
- if (y >= bottom - 2) this.Canvas.textBaseline = 'bottom';
2614
- else if (y <= top + 2) this.Canvas.textBaseline = 'top';
2615
- else this.Canvas.textBaseline = "middle";
2616
-
2617
- this.Canvas.strokeStyle=this.PenBorder;
2618
- this.Canvas.beginPath();
2619
- this.Canvas.moveTo(right-2,ToFixedPoint(y));
2620
- this.Canvas.lineTo(right,ToFixedPoint(y));
2621
- this.Canvas.stroke();
2622
-
2623
- //坐标信息 右边 间距小于10 不画坐标
2624
- if (item.Message[1]!=null && borderRight>10)
2625
- {
2626
- if (item.Font!=null) this.Canvas.font=item.Font;
2627
-
2628
- var text=item.Message[1];
2629
- if (Array.isArray(item.Message[1])) text=item.Message[1][0];
2630
-
2631
- this.Canvas.fillStyle=item.TextColor;
2632
- this.Canvas.textAlign="left";
2633
- this.Canvas.fillText(text,right+2,y);
2634
- }
2635
-
2636
- yPrev=y;
2637
- }
2638
- }
2639
-
2640
- //画X轴
2641
- this.DrawVertical=function()
2642
- {
2643
- var border=this.ChartBorder.GetBorder();
2644
- var top=border.TopEx;
2645
- //var left=this.ChartBorder.GetLeft();
2646
- var right=border.Right;
2647
- var bottom=border.BottomEx;
2648
- right+=this.RightOffset;
2649
-
2650
- this.Canvas.strokeStyle=this.PenBorder;
2651
- this.Canvas.beginPath();
2652
- this.Canvas.moveTo(ToFixedPoint(right),ToFixedPoint(top));
2653
- this.Canvas.lineTo(ToFixedPoint(right),ToFixedPoint(bottom));
2654
- this.Canvas.stroke();
2655
- }
2656
- }
2657
-
2658
-
2659
- function OverlayKLineHScreenFrame()
2660
- {
2661
- this.newMethod=KLineHScreenFrame; //派生
2662
- this.newMethod();
2663
- delete this.newMethod;
2664
-
2665
- this.ClassName='OverlayKLineHScreenFrame';
2666
- this.MainFrame=null; //主框架
2667
- this.IsShareY=false; //使用和主框架公用Y轴
2668
- this.IsCalculateYMaxMin=true; //是否计算Y最大最小值
2669
- this.RightOffset=50;
2670
- this.PenBorder=g_JSChartResource.OverlayFrame.BolderPen; //'rgb(0,0,0)'
2671
- this.IsShow=true; //坐标是否显示
2672
- this.Title=null;
2673
- this.TitleColor=g_JSChartResource.OverlayFrame.TitleColor;
2674
- this.TitleFont=g_JSChartResource.OverlayFrame.TitleFont;
2675
-
2676
- this.Draw=function()
2677
- {
2678
- this.SplitXYCoordinate();
2679
-
2680
- if (this.IsShow)
2681
- {
2682
- this.DrawVertical();
2683
- this.DrawHorizontal();
2684
- }
2685
-
2686
- this.SizeChange=false;
2687
- this.XYSplit=false;
2688
- }
2689
-
2690
- //分割x,y轴坐标信息
2691
- this.SplitXYCoordinate=function()
2692
- {
2693
- if (this.XYSplit==false) return;
2694
- if (this.IsShareY) //和主图指标共享Y轴坐标
2695
- {
2696
- this.HorizontalMax=this.MainFrame.HorizontalMax;
2697
- this.HorizontalMin=this.MainFrame.HorizontalMin;
2698
- this.HorizontalInfo=[];
2699
- for(var i=0; i<this.MainFrame.HorizontalInfo.length; ++i)
2700
- {
2701
- var item=this.MainFrame.HorizontalInfo[i];
2702
- this.HorizontalInfo.push(item);
2703
- }
2704
- }
2705
- else
2706
- {
2707
- if (this.YSplitOperator!=null) this.YSplitOperator.Operator();
2708
- }
2709
- }
2710
-
2711
- //画Y轴
2712
- this.DrawHorizontal=function()
2713
- {
2714
-
2715
- }
2716
-
2717
- //画X轴
2718
- this.DrawVertical=function()
2719
- {
2720
-
2721
- }
2722
-
2723
- this.GetScaleTextWidth=function()
2724
- {
2725
- return { TextWidth:0 };
2726
- }
2727
- }
2728
-
2729
-
2730
-
2731
- //深度图框架
2732
- function DepthChartFrame()
2733
- {
2734
- this.newMethod=AverageWidthFrame; //派生
2735
- this.newMethod();
2736
- delete this.newMethod;
2737
-
2738
- this.ScreenImageData; //截图
2739
- this.Position; //画布的位置
2740
- this.ClassName="DepthChartFrame";
2741
-
2742
- //X轴价格 最大,最小
2743
- this.VerticalRange={ Max:null, Min:null, Center:null, MaxDiffer:null, Differ:null, Step:0.05 };
2744
- this.AskPrice;
2745
- this.BidPrice;
2746
- this.MinZoom=0.05; //最小缩放
2747
-
2748
- this.SetPriceList=function(aryAskPrice, aryBidPrice)
2749
- {
2750
- this.AskPrice=aryAskPrice;
2751
- this.BidPrice=aryBidPrice;
2752
- }
2753
-
2754
- this.SetDrawOtherChart = function (callback) //在画完框架以后调用的扩展画法
2755
- {
2756
-
2757
- }
2758
-
2759
- this.DrawFrame=function()
2760
- {
2761
- this.SplitXYCoordinate();
2762
- this.DrawHorizontal();
2763
- this.DrawVertical();
2764
- }
2765
-
2766
- this.GetXFromIndex=function(value)
2767
- {
2768
- var left=this.ChartBorder.GetLeft();
2769
- var right=this.ChartBorder.GetRight();
2770
- var width=this.ChartBorder.GetWidth();
2771
- var offset=width*(value-this.VerticalRange.Min)/(this.VerticalRange.Max-this.VerticalRange.Min);
2772
- return left+offset;
2773
- }
2774
-
2775
- this.GetXData=function(x)
2776
- {
2777
- var left=this.ChartBorder.GetLeft();
2778
- var right=this.ChartBorder.GetRight();
2779
- var width=this.ChartBorder.GetWidth();
2780
-
2781
- return (x-left)/width*(this.VerticalRange.Max-this.VerticalRange.Min)+this.VerticalRange.Min;
2782
- }
2783
-
2784
- this.GetXFromPrice=function(price)
2785
- {
2786
- var isAskPrice=false;
2787
- var find=this.GetPrice(this.BidPrice, price);
2788
- if (find==null)
2789
- {
2790
- find=this.GetPrice(this.AskPrice, price);
2791
- isAskPrice=true;
2792
- }
2793
-
2794
- if (find==null)
2795
- {
2796
- if (this.BidPrice && Array.isArray(this.BidPrice) && this.BidPrice.length>0)
2797
- {
2798
- var minPrice=this.BidPrice[0];
2799
- if (price<minPrice)
2800
- {
2801
- isAskPrice=false;
2802
- find= minPrice;
2803
- }
2804
- }
2805
- }
2806
-
2807
- if (find==null)
2808
- {
2809
- if (this.AskPrice && Array.isArray(this.AskPrice) && this.AskPrice.length>0)
2810
- {
2811
- var maxPrice=this.AskPrice[this.AskPrice.length-1];
2812
- if (price>maxPrice)
2813
- {
2814
- isAskPrice=true;
2815
- find=maxPrice;
2816
- }
2817
- }
2818
- }
2819
-
2820
- if (find==null) return null;
2821
-
2822
- var x=this.GetXFromIndex(find);
2823
-
2824
- return { X:x, Price:find, IsAsk:isAskPrice };
2825
- }
2826
-
2827
- this.GetPrice=function(aryPrice, price)
2828
- {
2829
- if (!aryPrice || !Array.isArray(aryPrice) || aryPrice.length<=0) return null;
2830
-
2831
- if (price<aryPrice[0] || price>aryPrice[aryPrice.length-1]) return null;
2832
-
2833
- var lastPrice=null;
2834
- for(var i in aryPrice)
2835
- {
2836
- var item=aryPrice[i];
2837
- if (price==item)
2838
- {
2839
- return item;
2840
- }
2841
-
2842
- if (price<item)
2843
- return lastPrice;
2844
-
2845
- lastPrice=item;
2846
- }
2847
- }
2848
-
2849
- //分割x,y轴坐标信息
2850
- this.SplitXYCoordinate=function()
2851
- {
2852
- if (this.XYSplit==false) return;
2853
- if (this.YSplitOperator!=null) this.YSplitOperator.Operator();
2854
- if (this.XSplitOperator!=null) this.XSplitOperator.Operator();
2855
- }
2856
-
2857
- //图形快照
2858
- this.Snapshot=function()
2859
- {
2860
- this.ScreenImageData=this.Canvas.getImageData(0,0,this.ChartBorder.GetChartWidth(),this.ChartBorder.GetChartHeight());
2861
- }
2862
-
2863
- this.SetSizeChage=function(sizeChange)
2864
- {
2865
- this.SizeChange=sizeChange;
2866
-
2867
- //画布的位置
2868
- this.Position={
2869
- X:this.ChartBorder.UIElement.offsetLeft,
2870
- Y:this.ChartBorder.UIElement.offsetTop,
2871
- W:this.ChartBorder.UIElement.clientWidth,
2872
- H:this.ChartBorder.UIElement.clientHeight
2873
- };
2874
- }
2875
-
2876
- this.ZoomUp=function() //放大
2877
- {
2878
- var xRange=this.VerticalRange;
2879
- var differ=xRange.Differ;
2880
- var minDiffer=xRange.MaxDiffer*this.MinZoom;
2881
- if (differ<minDiffer) return false;
2882
-
2883
- var offsetDiffer=xRange.Differ*xRange.Step;
2884
- differ-=offsetDiffer;
2885
- xRange.Differ=differ;
2886
- xRange.Min=xRange.Center-xRange.Differ;
2887
- xRange.Max=xRange.Center+xRange.Differ;
2888
-
2889
- return true;
2890
- }
2891
-
2892
- this.ZoomDown=function() //缩小
2893
- {
2894
- var xRange=this.VerticalRange;
2895
- var differ=xRange.Differ;
2896
- if (differ==xRange.MaxDiffer) return false;
2897
-
2898
- var offsetDiffer=xRange.Differ*xRange.Step;
2899
- differ+=offsetDiffer;
2900
- if (differ>xRange.MaxDiffer) differ=xRange.MaxDiffer;
2901
-
2902
- xRange.Differ=differ;
2903
- xRange.Min=xRange.Center-xRange.Differ;
2904
- xRange.Max=xRange.Center+xRange.Differ;
2905
-
2906
- return true;
2907
- }
2908
- }
2909
-
2910
-
2911
- //导出统一使用JSCommon命名空间名
2912
- export
2913
- {
2914
- IChartFramePainting,
2915
- AverageWidthFrame,
2916
-
2917
- MinuteFrame,
2918
- MinuteHScreenFrame,
2919
-
2920
- OverlayMinuteFrame,
2921
- OverlayMinuteHScreenFrame,
2922
-
2923
- OverlayKLineFrame,
2924
- OverlayKLineHScreenFrame,
2925
-
2926
- ZOOM_SEED,
2927
- KLineFrame,
2928
- KLineHScreenFrame,
2929
-
2930
- DepthChartFrame,
2931
- };