umychart.framesplit.wechat.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  1. /*
  2. copyright (c) 2018 jones
  3. http://www.apache.org/licenses/LICENSE-2.0
  4. 开源项目 https://github.com/jones2000/HQChart
  5. jones_2000@163.com
  6. 坐标轴相关算法
  7. */
  8. import
  9. {
  10. JSCommonResource_Global_JSChartResource as g_JSChartResource,
  11. JSCommonResource_JSCHART_LANGUAGE_ID as JSCHART_LANGUAGE_ID,
  12. JSCommonResource_Global_JSChartLocalization as g_JSChartLocalization,
  13. } from './umychart.resource.wechat.js'
  14. import {
  15. JSCommon_ChartData as ChartData, JSCommon_HistoryData as HistoryData,
  16. JSCommon_SingleData as SingleData, JSCommon_MinuteData as MinuteData,
  17. JSCommon_JSCHART_EVENT_ID as JSCHART_EVENT_ID,
  18. } from "./umychart.data.wechat.js";
  19. import { JSCommonCoordinateData as JSCommonCoordinateData } from "./umychart.coordinatedata.wechat.js";
  20. var MARKET_SUFFIX_NAME = JSCommonCoordinateData.MARKET_SUFFIX_NAME;
  21. var WEEK_NAME=["日","一","二","三","四","五","六"];
  22. //坐标信息
  23. function CoordinateInfo()
  24. {
  25. this.Value; //坐标数据
  26. this.Message = new Array(); //坐标输出文字信息
  27. this.TextColor = g_JSChartResource.FrameSplitTextColor //文字颜色
  28. this.Font = g_JSChartResource.FrameSplitTextFont; //字体
  29. this.LineColor = g_JSChartResource.FrameSplitPen; //线段颜色
  30. this.LineType = 1; //线段类型 -1 不画线段
  31. }
  32. /////////////////////////////////////////////////////////////////////////////////////////////////////
  33. //坐标分割
  34. //
  35. //
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////
  37. function IFrameSplitOperator()
  38. {
  39. this.ChartBorder; //边框信息
  40. this.Frame; //框架信息
  41. this.FrameSplitData; //坐标轴分割方法
  42. this.SplitCount = 5; //刻度个数
  43. this.StringFormat = 0; //刻度字符串格式 -1 刻度文字全部不显示 -2 刻度文字右边不显示
  44. this.IsShowLeftText = true; //显示左边刻度
  45. this.IsShowRightText = true; //显示右边刻度
  46. this.LanguageID = JSCHART_LANGUAGE_ID.LANGUAGE_CHINESE_ID;
  47. this.GetEventCallback; //事件回调
  48. //////////////////////
  49. // data.Min data.Max data.Interval data.Count
  50. //
  51. this.IntegerCoordinateSplit = function (data)
  52. {
  53. var splitItem = this.FrameSplitData.Find(data.Interval);
  54. if (!splitItem) return false;
  55. if (data.Interval == splitItem.Interval) return true;
  56. var fixMax=data.Max, fixMin=data.Min;
  57. var maxValue=data.Max/splitItem.FixInterval;
  58. var minValue=data.Min/splitItem.FixInterval;
  59. //调整到整数倍数,不能整除的 +1
  60. if (IFrameSplitOperator.IsFloat(maxValue)) fixMax=parseInt((maxValue+0.5).toFixed(0))*splitItem.FixInterval;
  61. if (IFrameSplitOperator.IsFloat(minValue)) fixMin=parseInt((minValue-0.5).toFixed(0))*splitItem.FixInterval;
  62. if (data.Min == 0) fixMin = 0; //最小值是0 不用调整了.
  63. if (fixMin < 0 && data.Min > 0) fixMin = 0; //都是正数的, 最小值最小调整为0
  64. var count = 0;
  65. for (var i = fixMin; (i - fixMax) < 0.00000001; i += splitItem.FixInterval)
  66. {
  67. ++count;
  68. }
  69. data.Interval = splitItem.FixInterval;
  70. data.Max = fixMax;
  71. data.Min = fixMin;
  72. data.Count = count;
  73. return true;
  74. }
  75. this.Filter = function (aryInfo, keepZero) //keepZero 保留0轴
  76. {
  77. if (this.SplitCount <= 0 || aryInfo.length <= 0 || aryInfo.length <= this.SplitCount) return aryInfo;
  78. //分割线比预设的多, 过掉一些
  79. var filter = parseInt(aryInfo.length / this.SplitCount);
  80. if (filter <= 1) filter = 2;
  81. var data = [];
  82. for (var i = 0; i < aryInfo.length; i += filter)
  83. {
  84. if (i + filter >= aryInfo.length && i != aryInfo.length - 1) //最后一个数据放进去
  85. {
  86. data.push(aryInfo[aryInfo.length - 1]);
  87. }
  88. else {
  89. data.push(aryInfo[i]);
  90. }
  91. }
  92. if (this.SplitCount == 2 && data.length > 2) //之显示第1个和最后一个刻度
  93. {
  94. for (var i = 1; i < data.length - 1; ++i)
  95. {
  96. var item = data[i];
  97. item.Message[0] = null;
  98. item.Message[1] = null;
  99. }
  100. }
  101. if (keepZero) //如果不存在0轴,增加一个0轴,刻度信息部显示
  102. {
  103. var bExsitZero = false;
  104. for (var i = 0; i < data; ++i)
  105. {
  106. var item = data[i];
  107. if (Math.abs(item.Value) < 0.00000001)
  108. {
  109. bExsitZero = true;
  110. break;
  111. }
  112. }
  113. if (bExsitZero == false)
  114. {
  115. var zeroCoordinate = new CoordinateInfo();
  116. zeroCoordinate.Value = 0;
  117. zeroCoordinate.Message[0] = null
  118. zeroCoordinate.Message[1] = null;
  119. data.push(zeroCoordinate);
  120. }
  121. }
  122. return data;
  123. }
  124. this.RemoveZero = function (aryInfo) //移除小数后面多余的0
  125. {
  126. //所有的数字小数点后面都0,才会去掉
  127. var isAllZero = [true, true];
  128. for (var i in aryInfo) {
  129. var item = aryInfo[i];
  130. var message = item.Message[0];
  131. if (!this.IsDecimalZeroEnd(message)) isAllZero[0] = false;
  132. var message = item.Message[1];
  133. if (!this.IsDecimalZeroEnd(message)) isAllZero[1] = false;
  134. }
  135. if (isAllZero[0] == false && isAllZero[1] == false) return;
  136. for (var i in aryInfo)
  137. {
  138. var item = aryInfo[i];
  139. if (isAllZero[0])
  140. {
  141. var message = item.Message[0];
  142. if (message != null)
  143. {
  144. if (typeof (message) == 'number') message = message.toString();
  145. item.Message[0] = message.replace(/[.][0]+/g, '');
  146. }
  147. }
  148. if (isAllZero[1])
  149. {
  150. var message = item.Message[1];
  151. if (message != null)
  152. {
  153. if (typeof (message) == 'number') message = message.toString();
  154. item.Message[1] = message.replace(/[.][0]+/g, '');
  155. }
  156. }
  157. }
  158. }
  159. this.IsDecimalZeroEnd = function (text) //是否是0结尾的小数
  160. {
  161. if (text == null) return true;
  162. if (text == '0') return true;
  163. if (typeof (text) == 'number') text = text.toString();
  164. var pos = text.search(/[.]/);
  165. if (pos < 0) return false;
  166. for (var i = pos + 1; i < text.length; ++i)
  167. {
  168. var char = text.charAt(i);
  169. if (char >= '1' && char <= '9') return false;
  170. }
  171. return true;
  172. }
  173. }
  174. //字符串格式化 千分位分割
  175. IFrameSplitOperator.FormatValueThousandsString=function(value,floatPrecision)
  176. {
  177. if (value==null || isNaN(value))
  178. {
  179. if (floatPrecision>0)
  180. {
  181. var nullText='-.';
  182. for(var i=0;i<floatPrecision;++i)
  183. nullText+='-';
  184. return nullText;
  185. }
  186. return '--';
  187. }
  188. var result='';
  189. var num=value.toFixed(floatPrecision);
  190. if(floatPrecision>0){
  191. var numFloat = num.split('.')[1];
  192. var numM = num.split('.')[0];
  193. while (numM.length > 3)
  194. {
  195. result = ',' + numM.slice(-3) + result;
  196. numM = numM.slice(0, numM.length - 3);
  197. }
  198. if (numM) { result = numM + result + '.' + numFloat; }
  199. }else{
  200. while (num.length > 3)
  201. {
  202. result = ',' + num.slice(-3) + result;
  203. num = num.slice(0, num.length - 3);
  204. }
  205. if (num) { result = num + result; }
  206. }
  207. return result;
  208. }
  209. //数据输出格式化 floatPrecision=小数位数
  210. IFrameSplitOperator.FormatValueString=function(value, floatPrecision,languageID)
  211. {
  212. if (value==null || isNaN(value))
  213. {
  214. if (floatPrecision>0)
  215. {
  216. var nullText='-.';
  217. for(var i=0;i<floatPrecision;++i)
  218. nullText+='-';
  219. return nullText;
  220. }
  221. return '--';
  222. }
  223. if (value<0.00000000001 && value>-0.00000000001)
  224. {
  225. return "0";
  226. }
  227. var absValue = Math.abs(value);
  228. if (languageID===JSCHART_LANGUAGE_ID.LANGUAGE_ENGLISH_ID)
  229. {
  230. if (absValue < 10000)
  231. return value.toFixed(floatPrecision);
  232. else if (absValue < 1000000)
  233. return (value/1000).toFixed(floatPrecision)+"K";
  234. else if (absValue < 1000000000)
  235. return (value/1000000).toFixed(floatPrecision)+"M";
  236. else if (absValue < 1000000000000)
  237. return (value/1000000000).toFixed(floatPrecision)+"B";
  238. else
  239. return (value/1000000000000).toFixed(floatPrecision)+"T";
  240. }
  241. else
  242. {
  243. if (absValue < 10000)
  244. return value.toFixed(floatPrecision);
  245. else if (absValue < 100000000)
  246. return (value/10000).toFixed(floatPrecision)+"万";
  247. else if (absValue < 1000000000000)
  248. return (value/100000000).toFixed(floatPrecision)+"亿";
  249. else
  250. return (value/1000000000000).toFixed(floatPrecision)+"万亿";
  251. }
  252. return '';
  253. }
  254. //整形输出格式化 floatPrecision=小数位数
  255. IFrameSplitOperator.FromatIntegerString=function(value, floatPrecision,languageID)
  256. {
  257. if (value<10000 && IFrameSplitOperator.IsInteger(value)) floatPrecision=0; //<10000的整形 去掉小数位数
  258. return IFrameSplitOperator.FormatValueString(value, floatPrecision,languageID);
  259. }
  260. IFrameSplitOperator.NumberToString=function(value)
  261. {
  262. if (value<10) return '0'+value.toString();
  263. return value.toString();
  264. }
  265. IFrameSplitOperator.FormatDateString=function(value,format,languageID)
  266. {
  267. var year=parseInt(value/10000);
  268. var month=parseInt(value/100)%100;
  269. var day=value%100;
  270. switch(format)
  271. {
  272. case 'MM-DD':
  273. return IFrameSplitOperator.NumberToString(month) + '-' + IFrameSplitOperator.NumberToString(day);
  274. case "YYYY/MM/DD":
  275. return year.toString() + '/' + IFrameSplitOperator.NumberToString(month) + '/' + IFrameSplitOperator.NumberToString(day);
  276. case "YYYY/MM/DD/W":
  277. {
  278. var date=new Date(year,month-1,day);
  279. var week=g_JSChartLocalization.GetText(WEEK_NAME[date.getDay()],languageID);
  280. return year.toString() + '/' + IFrameSplitOperator.NumberToString(month) + '/' + IFrameSplitOperator.NumberToString(day)+"/"+ week.toString();
  281. }
  282. case "DD/MM/YYYY":
  283. return IFrameSplitOperator.NumberToString(day) + '/' + IFrameSplitOperator.NumberToString(month) + '/' + year.toString();
  284. default:
  285. return year.toString() + '-' + IFrameSplitOperator.NumberToString(month) + '-' + IFrameSplitOperator.NumberToString(day);
  286. }
  287. }
  288. IFrameSplitOperator.FormatTimeString=function(value, format) //format hh:mm:ss
  289. {
  290. if (format=='HH:MM:SS')
  291. {
  292. var hour=parseInt(value/10000);
  293. var minute=parseInt((value%10000)/100);
  294. var second=value%100;
  295. return IFrameSplitOperator.NumberToString(hour)+':'+ IFrameSplitOperator.NumberToString(minute) + ':' + IFrameSplitOperator.NumberToString(second);
  296. }
  297. else if (format == 'HH:MM')
  298. {
  299. var hour = parseInt(value / 100);
  300. var minute = value % 100;
  301. return IFrameSplitOperator.NumberToString(hour) + ':' + IFrameSplitOperator.NumberToString(minute);
  302. }
  303. else
  304. {
  305. if (value < 10000)
  306. {
  307. var hour = parseInt(value / 100);
  308. var minute = value % 100;
  309. return IFrameSplitOperator.NumberToString(hour) + ':' + IFrameSplitOperator.NumberToString(minute);
  310. }
  311. else
  312. {
  313. var hour = parseInt(value / 10000);
  314. var minute = parseInt((value % 10000) / 100);
  315. var second = value % 100;
  316. return IFrameSplitOperator.NumberToString(hour) + ':' + IFrameSplitOperator.NumberToString(minute) + ':' + IFrameSplitOperator.NumberToString(second);
  317. }
  318. }
  319. }
  320. //报告格式化
  321. IFrameSplitOperator.FormatReportDateString=function(value)
  322. {
  323. var year=parseInt(value/10000);
  324. var month=parseInt(value/100)%100;
  325. var monthText;
  326. switch(month)
  327. {
  328. case 3:
  329. monthText="一季度报";
  330. break;
  331. case 6:
  332. monthText="半年报";
  333. break;
  334. case 9:
  335. monthText="三季度报";
  336. break;
  337. case 12:
  338. monthText="年报";
  339. break;
  340. }
  341. return year.toString()+ monthText;
  342. }
  343. IFrameSplitOperator.FormatDateTimeString=function(value,isShowDate)
  344. {
  345. var aryValue=value.split(' ');
  346. if (aryValue.length<2) return "";
  347. var time=parseInt(aryValue[1]);
  348. var minute=time%100;
  349. var hour=parseInt(time/100);
  350. var text=(hour<10? ('0'+hour.toString()):hour.toString()) + ':' + (minute<10?('0'+minute.toString()):minute.toString());
  351. if (isShowDate==true)
  352. {
  353. var date=parseInt(aryValue[0]);
  354. var year=parseInt(date/10000);
  355. var month=parseInt(date%10000/100);
  356. var day=date%100;
  357. text=year.toString() +'-'+ (month<10? ('0'+month.toString()) :month.toString()) +'-'+ (day<10? ('0'+day.toString()):day.toString()) +" " +text;
  358. }
  359. return text;
  360. }
  361. //字段颜色格式化
  362. IFrameSplitOperator.FormatValueColor = function (value, value2)
  363. {
  364. if (value != null && value2 == null) //只传一个值的 就判断value正负
  365. {
  366. if (value == 0) return 'PriceNull';
  367. else if (value > 0) return 'PriceUp';
  368. else return 'PriceDown';
  369. }
  370. //2个数值对比 返回颜色
  371. if (value == null || value2 == null) return 'PriceNull';
  372. if (value == value2) return 'PriceNull';
  373. else if (value > value2) return 'PriceUp';
  374. else return 'PriceDown';
  375. }
  376. IFrameSplitOperator.IsNumber=function(value)
  377. {
  378. if (value==null) return false;
  379. if (isNaN(value)) return false;
  380. return true;
  381. }
  382. //判断是否是正数
  383. IFrameSplitOperator.IsPlusNumber=function(value)
  384. {
  385. if (value==null) return false;
  386. if (isNaN(value)) return false;
  387. return value>0;
  388. }
  389. //是否是整形
  390. IFrameSplitOperator.IsInteger=function(x)
  391. {
  392. return (typeof x === 'number') && (x % 1 === 0);
  393. }
  394. //判断字段是否存在
  395. IFrameSplitOperator.IsObjectExist=function(obj)
  396. {
  397. if (obj===undefined) return false;
  398. if (obj==null) return false;
  399. return true;
  400. }
  401. //是否时bool
  402. IFrameSplitOperator.IsBool=function(value)
  403. {
  404. if (value===true || value===false) return true;
  405. return false;
  406. }
  407. IFrameSplitOperator.IsString=function(value)
  408. {
  409. var type=typeof(value);
  410. if (type=='string') return true;
  411. return false;
  412. }
  413. IFrameSplitOperator.IsFloat=function(value)
  414. {
  415. if (value===undefined) return false;
  416. if (value==null) return false;
  417. if (isNaN(value)) return false;
  418. return value!=parseInt(value);
  419. }
  420. //是否是非空的数组
  421. IFrameSplitOperator.IsNonEmptyArray=function(ary)
  422. {
  423. if (!ary) return;
  424. if (!Array.isArray(ary)) return;
  425. return ary.length>0;
  426. }
  427. //K线Y轴分割
  428. function FrameSplitKLinePriceY()
  429. {
  430. this.newMethod = IFrameSplitOperator; //派生
  431. this.newMethod();
  432. delete this.newMethod;
  433. this.CoordinateType = 0; //坐标类型 0=普通坐标 1=百分比坐标 (右边坐标刻度)
  434. this.Symbol;
  435. this.Data; //K线数据 (计算百分比坐标)
  436. this.FrameSplitData2; //坐标轴分割方法(计算百分比刻度)
  437. this.FloatPrecision = null; //小数位数 (设置了就使用这个位数,否则使用品种对应的小数位数)
  438. this.Custom = []; //[{Type:0}]; 定制刻度 0=显示最后的价格刻度
  439. this.SplitType = 0; //0=自动分割 1=固定分割
  440. this.Operator = function ()
  441. {
  442. var splitData = {};
  443. splitData.Max = this.Frame.HorizontalMax;
  444. splitData.Min = this.Frame.HorizontalMin;
  445. splitData.Count = this.SplitCount;
  446. if (splitData.Max==splitData.Min) //如果一样上下扩大下
  447. {
  448. splitData.Max+=splitData.Max*0.01;
  449. splitData.Min-=splitData.Min*0.01
  450. }
  451. splitData.Interval = (splitData.Max - splitData.Min) / (splitData.Count - 1);
  452. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  453. if (JSCommonCoordinateData.MARKET_SUFFIX_NAME.IsSHSZIndex(this.Symbol)) defaultfloatPrecision = 0; //手机端指数不显示小数位数
  454. if (this.FloatPrecision != null) defaultfloatPrecision = this.FloatPrecision;
  455. var bFilter=true;
  456. if (FrameSplitKLinePriceY.SplitCustom)
  457. {
  458. FrameSplitKLinePriceY.SplitCustom(this,splitData,defaultfloatPrecision); //自定义分割
  459. bFilter=false;
  460. }
  461. else
  462. {
  463. switch (this.CoordinateType)
  464. {
  465. case 1:
  466. this.SplitPercentage(splitData, defaultfloatPrecision);
  467. break;
  468. default:
  469. if (this.SplitType == 1) this.SplitFixed(splitData, defaultfloatPrecision);
  470. else this.SplitDefault(splitData, defaultfloatPrecision);
  471. this.CustomCoordinate(defaultfloatPrecision);
  472. break;
  473. }
  474. }
  475. if (bFilter) this.Frame.HorizontalInfo = this.Filter(this.Frame.HorizontalInfo, false);
  476. this.Frame.HorizontalMax = splitData.Max;
  477. this.Frame.HorizontalMin = splitData.Min;
  478. if (this.GetEventCallback)
  479. {
  480. var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_SPLIT_YCOORDINATE);
  481. if (event && event.Callback)
  482. {
  483. var data={ID:this.Frame.Identify, Frame:this.Frame };
  484. event.Callback(event,data,this);
  485. }
  486. }
  487. }
  488. this.SplitDefault = function (splitData, floatPrecision) //默认坐标
  489. {
  490. this.IntegerCoordinateSplit(splitData);
  491. this.Frame.HorizontalInfo = [];
  492. for (var i = 0, value = splitData.Min; i < splitData.Count; ++i, value += splitData.Interval)
  493. {
  494. this.Frame.HorizontalInfo[i] = new CoordinateInfo();
  495. this.Frame.HorizontalInfo[i].Value = value;
  496. if (this.IsShowLeftText) this.Frame.HorizontalInfo[i].Message[0] = value.toFixed(floatPrecision);
  497. if (this.IsShowRightText) this.Frame.HorizontalInfo[i].Message[1] = value.toFixed(floatPrecision);
  498. }
  499. }
  500. this.SplitPercentage = function (splitData, floatPrecision) //百分比坐标
  501. {
  502. var firstOpenPrice = this.GetFirstOpenPrice();
  503. splitData.Max = (splitData.Max - firstOpenPrice) / firstOpenPrice;
  504. splitData.Min = (splitData.Min - firstOpenPrice) / firstOpenPrice;
  505. splitData.Interval = (splitData.Max - splitData.Min) / (splitData.Count - 1);
  506. this.IntegerCoordinateSplit2(splitData);
  507. var maxValue=(1 + splitData.Max) * firstOpenPrice;
  508. var minValue=(1 + splitData.Min) * firstOpenPrice;
  509. this.Frame.HorizontalInfo = [];
  510. for (var i = 0, value = splitData.Min; i < splitData.Count; ++i, value += splitData.Interval)
  511. {
  512. var price = (value + 1) * firstOpenPrice;
  513. if (price<minValue || price>maxValue) continue;
  514. this.Frame.HorizontalInfo[i] = new CoordinateInfo();
  515. this.Frame.HorizontalInfo[i].Value = price;
  516. if (this.IsShowLeftText) this.Frame.HorizontalInfo[i].Message[0] = price.toFixed(floatPrecision); //左边价格坐标
  517. if (this.IsShowRightText) this.Frame.HorizontalInfo[i].Message[1] = (value * 100).toFixed(2) + '%'; //右边百分比
  518. }
  519. splitData.Min = (1 + splitData.Min) * firstOpenPrice; //最大最小值调整
  520. splitData.Max = (1 + splitData.Max) * firstOpenPrice;
  521. }
  522. this.SplitFixed = function (splitData, floatPrecision) //固定分割坐标
  523. {
  524. this.Frame.HorizontalInfo = [];
  525. for (var i = 0, value = splitData.Min; i < splitData.Count; ++i, value += splitData.Interval) {
  526. this.Frame.HorizontalInfo[i] = new CoordinateInfo();
  527. this.Frame.HorizontalInfo[i].Value = value;
  528. if (this.IsShowLeftText) this.Frame.HorizontalInfo[i].Message[0] = value.toFixed(floatPrecision);
  529. if (this.IsShowRightText) this.Frame.HorizontalInfo[i].Message[1] = value.toFixed(floatPrecision);
  530. }
  531. }
  532. this.CustomCoordinate = function (floatPrecision)
  533. {
  534. this.Frame.CustomHorizontalInfo = [];
  535. for (var i in this.Custom)
  536. {
  537. var item = this.Custom[i];
  538. if (item.Type == 0) //最新价格刻度
  539. {
  540. var dec=floatPrecision;
  541. //外部设置小数位数
  542. if (IFrameSplitOperator.IsNumber(item.FloatPrecision) && item.FloatPrecision>=0) dec=item.FloatPrecision;
  543. var latestItem = this.GetLatestPrice(dec, item);
  544. if (latestItem) this.Frame.CustomHorizontalInfo.push(latestItem);
  545. }
  546. else if (item.Type == 1) //固定价格刻度
  547. {
  548. this.CustomFixedCoordinate(item);
  549. }
  550. }
  551. }
  552. this.GetLatestPrice = function (floatPrecision, option)
  553. {
  554. if (!this.Data || !this.Data.Data) return null;
  555. if (this.Data.Data.length <= 0) return null;
  556. var latestItem = this.Data.Data[this.Data.Data.length - 1];
  557. var info = new CoordinateInfo();
  558. info.Type = 0;
  559. info.Value = latestItem.Close;
  560. info.TextColor = g_JSChartResource.FrameLatestPrice.TextColor;
  561. info.LineType = 2; //虚线
  562. if (option.Position == 'left') info.Message[0] = latestItem.Close.toFixed(floatPrecision);
  563. else info.Message[1] = latestItem.Close.toFixed(floatPrecision);
  564. if (latestItem.Close > latestItem.Open) info.LineColor = g_JSChartResource.FrameLatestPrice.UpBarColor;
  565. else if (latestItem.Close < latestItem.Open) info.LineColor = g_JSChartResource.FrameLatestPrice.DownBarColor;
  566. else info.LineColor = g_JSChartResource.FrameLatestPrice.UnchagneBarColor;
  567. if (IFrameSplitOperator.IsNumber(option.LineType)) info.LineType=option.LineType;
  568. if (option.IsShowLine == false) info.LineType = -1;
  569. return info;
  570. }
  571. this.GetFirstOpenPrice = function () //获取显示第1个数据的开盘价
  572. {
  573. if (!this.Data) return null;
  574. var xPointCount = this.Frame.XPointCount;
  575. for (var i = this.Data.DataOffset, j = 0; i < this.Data.Data.length && j < xPointCount; ++i, ++j)
  576. {
  577. var data = this.Data.Data[i];
  578. if (data.Open == null || data.High == null || data.Low == null || data.Close == null) continue;
  579. return data.Open;
  580. }
  581. return null;
  582. }
  583. this.CustomFixedCoordinate = function (option) //固定坐标刻度
  584. {
  585. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  586. for (var i in option.Data)
  587. {
  588. var item = option.Data[i];
  589. var info = new CoordinateInfo();
  590. info.Type = 1;
  591. info.TextColor = item.TextColor;
  592. info.LineColor = item.Color;
  593. info.LineType = 2; //虚线
  594. if (IFrameSplitOperator.IsNumber(option.LineType)) info.LineType=option.LineType;
  595. if (option.IsShowLine == false) info.LineType = -1;
  596. info.Value = item.Value;
  597. var text;
  598. if (item.Text) text = item.Text;
  599. else text = info.Value.toFixed(defaultfloatPrecision);
  600. if (option.Position == 'left') info.Message[0] = text;
  601. else info.Message[1] = text;
  602. this.Frame.CustomHorizontalInfo.push(info);
  603. }
  604. }
  605. //////////////////////
  606. // data.Min data.Max data.Interval data.Count
  607. //
  608. this.IntegerCoordinateSplit2 = function (data)
  609. {
  610. var splitItem = this.FrameSplitData2.Find(data.Interval);
  611. if (!splitItem) return false;
  612. if (data.Interval == splitItem.FixInterval) return true;
  613. var fixMax=data.Max, fixMin=data.Min;
  614. var maxValue=data.Max/splitItem.FixInterval;
  615. var minValue=data.Min/splitItem.FixInterval;
  616. //调整到整数倍数,不能整除的 +1
  617. if (IFrameSplitOperator.IsFloat(maxValue)) fixMax=parseInt((maxValue+0.5).toFixed(0))*splitItem.FixInterval;
  618. if (IFrameSplitOperator.IsFloat(minValue)) fixMin=parseInt((minValue-0.5).toFixed(0))*splitItem.FixInterval;
  619. if (data.Min == 0) fixMin = 0; //最小值是0 不用调整了.
  620. if (fixMin < 0 && data.Min > 0) fixMin = 0; //都是正数的, 最小值最小调整为0
  621. var count = 0;
  622. for (var i = fixMin; (i - fixMax) < 0.00000001; i += splitItem.FixInterval)
  623. {
  624. ++count;
  625. }
  626. data.Interval = splitItem.FixInterval;
  627. data.Max = fixMax;
  628. data.Min = fixMin;
  629. data.Count = count;
  630. return true;
  631. }
  632. }
  633. //一般的Y轴分割
  634. function FrameSplitY()
  635. {
  636. this.newMethod = IFrameSplitOperator; //派生
  637. this.newMethod();
  638. delete this.newMethod;
  639. this.SplitType=0; //0=自动分割 1=固定分割
  640. this.FloatPrecision = 2; //坐标小数位数(默认2)
  641. this.FLOATPRECISION_RANGE = [1, 0.1, 0.01, 0.001, 0.0001];
  642. this.IgnoreYValue = null; //在这个数组里的数字不显示在刻度上
  643. this.LineType=null; //线段样式
  644. this.IsShowYZero = true;
  645. this.IntegerSplitData = null;
  646. this.Operator = function ()
  647. {
  648. var splitData = {};
  649. splitData.Max = this.Frame.HorizontalMax;
  650. splitData.Min = this.Frame.HorizontalMin;
  651. if (splitData.Max==splitData.Min) //如果一样上下扩大下
  652. {
  653. if (splitData.Max==0)
  654. {
  655. splitData.Max=1;
  656. splitData.Min=-1;
  657. }
  658. else
  659. {
  660. splitData.Max+=splitData.Max*0.01;
  661. splitData.Min-=splitData.Min*0.01;
  662. }
  663. }
  664. if (this.Frame.YSpecificMaxMin)
  665. {
  666. splitData.Count = this.Frame.YSpecificMaxMin.Count;
  667. splitData.Interval = (splitData.Max - splitData.Min) / (splitData.Count - 1);
  668. }
  669. else if (this.SplitType==1)
  670. {
  671. splitData.Count=this.SplitCount;
  672. splitData.Interval=(splitData.Max-splitData.Min)/(splitData.Count-1);
  673. }
  674. else
  675. {
  676. splitData.Count = this.SplitCount * 2; //放大两倍
  677. if (this.FloatPrecision == 0) //页面配置了纵坐标小数位数FloatPrecision=0时执行
  678. {
  679. splitData.Interval = (splitData.Max - splitData.Min) / (splitData.Count - 1);
  680. this.IntegerCoordinateSplit2(splitData);
  681. }
  682. else {
  683. splitData.Interval = (splitData.Max - splitData.Min) / (splitData.Count - 1);
  684. this.IntegerCoordinateSplit(splitData);
  685. }
  686. }
  687. this.Frame.HorizontalInfo = [];
  688. if (this.Frame.YSplitScale)
  689. {
  690. for (var i in this.Frame.YSplitScale)
  691. {
  692. var value = this.Frame.YSplitScale[i];
  693. var coordinate = new CoordinateInfo();
  694. coordinate.Value = value;
  695. if (IFrameSplitOperator.IsNumber(this.LineType)) coordinate.LineType=this.LineType;
  696. var absValue = Math.abs(value);
  697. var floatPrecision = this.FloatPrecision; //数据比小数位数还小, 调整小数位数
  698. if (absValue < 0.0000000001)
  699. coordinate.Message[1] = 0;
  700. else if (absValue < this.FLOATPRECISION_RANGE[this.FLOATPRECISION_RANGE.length - 1])
  701. coordinate.Message[1] = value.toExponential(2).toString();
  702. else
  703. {
  704. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  705. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  706. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  707. coordinate.Message[1] = IFrameSplitOperator.FormatValueString(value, floatPrecision, this.LanguageID);
  708. }
  709. coordinate.Message[0] = coordinate.Message[1];
  710. if (this.StringFormat == -2) coordinate.Message[1] = null; //刻度右边不显示
  711. else if (this.StringFormat == -3) coordinate.Message[0] = null; //刻度左边不显示
  712. else if (this.StringFormat == -1) coordinate.Message[0] = coordinate.Message[1] = null; //刻度左右都不显示
  713. this.Frame.HorizontalInfo.push(coordinate);
  714. }
  715. }
  716. else
  717. {
  718. for (var i = 0, value = splitData.Min; i < splitData.Count; ++i, value += splitData.Interval)
  719. {
  720. var coordinate=new CoordinateInfo();
  721. this.Frame.HorizontalInfo[i] = coordinate;
  722. coordinate.Value=value;
  723. if (IFrameSplitOperator.IsNumber(this.LineType)) coordinate.LineType=this.LineType;
  724. if (this.StringFormat == 1) //手机端格式 如果有万,亿单位了 去掉小数
  725. {
  726. var floatPrecision = this.FloatPrecision;
  727. if (!isNaN(value) && Math.abs(value) > 1000) floatPrecision = 0;
  728. this.Frame.HorizontalInfo[i].Message[1] = IFrameSplitOperator.FormatValueString(value, floatPrecision, this.LanguageID);
  729. }
  730. else if (this.StringFormat == -1) //刻度不显示
  731. {
  732. }
  733. else
  734. {
  735. var absValue = Math.abs(value);
  736. var floatPrecision = this.FloatPrecision; //数据比小数位数还小, 调整小数位数
  737. if (absValue < 0.0000000001)
  738. this.Frame.HorizontalInfo[i].Message[1] = 0;
  739. else if (absValue < this.FLOATPRECISION_RANGE[this.FLOATPRECISION_RANGE.length - 1])
  740. this.Frame.HorizontalInfo[i].Message[1] = value.toExponential(2).toString();
  741. else {
  742. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  743. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  744. if (floatPrecision < this.FLOATPRECISION_RANGE.length && absValue < this.FLOATPRECISION_RANGE[floatPrecision])++floatPrecision;
  745. this.Frame.HorizontalInfo[i].Message[1] = IFrameSplitOperator.FormatValueString(value, floatPrecision, this.LanguageID);
  746. }
  747. }
  748. this.Frame.HorizontalInfo[i].Message[0] = this.Frame.HorizontalInfo[i].Message[1];
  749. if (this.StringFormat == -2) this.Frame.HorizontalInfo[i].Message[1] = null; //刻度右边不显示
  750. else if (this.StringFormat == -3) this.Frame.HorizontalInfo[i].Message[0] = null; //刻度左边不显示
  751. }
  752. }
  753. this.FilterIgnoreYValue();
  754. this.Frame.HorizontalInfo = this.Filter(this.Frame.HorizontalInfo, (splitData.Max > 0 && splitData.Min < 0 && this.IsShowYZero));
  755. this.RemoveZero(this.Frame.HorizontalInfo);
  756. this.Frame.HorizontalMax = splitData.Max;
  757. this.Frame.HorizontalMin = splitData.Min;
  758. if (this.GetEventCallback)
  759. {
  760. var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_SPLIT_YCOORDINATE);
  761. if (event && event.Callback)
  762. {
  763. var data={ID:this.Frame.Identify, Frame:this.Frame };
  764. event.Callback(event,data,this);
  765. }
  766. }
  767. }
  768. this.FilterIgnoreYValue = function ()
  769. {
  770. if (!this.IgnoreYValue || this.IgnoreYValue.length <= 0) return;
  771. var setValue = new Set(this.IgnoreYValue);
  772. this.Frame.HorizontalInfo = this.Frame.HorizontalInfo.filter(item => !setValue.has(item.Value));
  773. this.IsShowYZero = !setValue.has(0); //是否显示0刻度
  774. }
  775. this.IntegerCoordinateSplit2 = function (data) //整数分割
  776. {
  777. if (this.IntegerSplitData == null) this.IntegerSplitData = new IntegerSplitData();
  778. var splitItem = this.IntegerSplitData.Find(data.Interval);
  779. if (!splitItem) return false;
  780. if (data.Interval == splitItem.FixInterval) return true;
  781. var fixMax=data.Max, fixMin=data.Min;
  782. var maxValue=data.Max/splitItem.FixInterval;
  783. var minValue=data.Min/splitItem.FixInterval;
  784. //调整到整数倍数,不能整除的 +1
  785. if (IFrameSplitOperator.IsFloat(maxValue)) fixMax=parseInt((maxValue+0.5).toFixed(0))*splitItem.FixInterval;
  786. if (IFrameSplitOperator.IsFloat(minValue)) fixMin=parseInt((minValue-0.5).toFixed(0))*splitItem.FixInterval;
  787. if (data.Min == 0) fixMin = 0; //最小值是0 不用调整了.
  788. if (fixMin < 0 && data.Min > 0) fixMin = 0; //都是正数的, 最小值最小调整为0
  789. var count = 0;
  790. for (var i = fixMin; (i - fixMax) < 0.00000001; i += splitItem.FixInterval)
  791. {
  792. ++count;
  793. }
  794. data.Interval = splitItem.FixInterval;
  795. data.Max = fixMax;
  796. data.Min = fixMin;
  797. data.Count = count;
  798. return true;
  799. }
  800. }
  801. function FrameSplitKLineX()
  802. {
  803. this.newMethod = IFrameSplitOperator; //派生
  804. this.newMethod();
  805. delete this.newMethod;
  806. this.ShowText = true; //是否显示坐标信息
  807. this.MinDistance = 12; //刻度间隔
  808. this.Period; //周期
  809. this.Symbol; //股票代码
  810. this.MinTextDistance = 50;
  811. this.SplitDateTime = function () //根据时间分割
  812. {
  813. this.Frame.VerticalInfo = [];
  814. var itemWidth = this.Frame.DistanceWidth + this.Frame.DataWidth;
  815. var xOffset = this.Frame.Data.DataOffset;
  816. var xPointCount = this.Frame.XPointCount;
  817. var lastYear = null, lastMonth = null;
  818. var textDistance = 0;
  819. for (var i = 0, index = xOffset; i < xPointCount && index < this.Frame.Data.Data.length; ++i, ++index)
  820. {
  821. textDistance += itemWidth;
  822. var infoData = null;
  823. if (i == 0)
  824. {
  825. var date = IFrameSplitOperator.FormatDateString(this.Frame.Data.Data[index].Date, 'MM-DD');
  826. infoData = { Value: index - xOffset, Text: date };
  827. }
  828. else if (textDistance > this.MinTextDistance)
  829. {
  830. var time = IFrameSplitOperator.FormatTimeString(this.Frame.Data.Data[index].Time);
  831. infoData = { Value: index - xOffset, Text: time };
  832. }
  833. if (infoData)
  834. {
  835. var info = new CoordinateInfo();
  836. info.Value = infoData.Value;
  837. if (this.ShowText) info.Message[0] = infoData.Text;
  838. if (info.Value==0) info.LineType=-1; //第1个分割线不画
  839. this.Frame.VerticalInfo.push(info);
  840. textDistance = 0;
  841. if (i == 0) textDistance = -(this.MinTextDistance / 2);
  842. }
  843. }
  844. }
  845. this.SplitSecond = function () //根据时间分割
  846. {
  847. this.Frame.VerticalInfo = [];
  848. var itemWidth = this.Frame.DistanceWidth + this.Frame.DataWidth;
  849. var xOffset = this.Frame.Data.DataOffset;
  850. var xPointCount = this.Frame.XPointCount;
  851. var lastYear = null, lastMonth = null;
  852. var textDistance = 0;
  853. for (var i = 0, index = xOffset; i < xPointCount && index < this.Frame.Data.Data.length; ++i, ++index)
  854. {
  855. textDistance += itemWidth;
  856. var infoData = null;
  857. if (i == 0)
  858. {
  859. var date = IFrameSplitOperator.FormatDateString(this.Frame.Data.Data[index].Date, 'MM-DD');
  860. infoData = { Value: index - xOffset, Text: date };
  861. }
  862. else if (textDistance > this.MinTextDistance)
  863. {
  864. var time = IFrameSplitOperator.FormatTimeString(this.Frame.Data.Data[index].Time,"HH:MM:SS");
  865. infoData = { Value: index - xOffset, Text: time };
  866. }
  867. if (infoData)
  868. {
  869. var info = new CoordinateInfo();
  870. info.Value = infoData.Value;
  871. if (this.ShowText) info.Message[0] = infoData.Text;
  872. this.Frame.VerticalInfo.push(info);
  873. textDistance = 0;
  874. if (i == 0) textDistance = -(this.MinTextDistance / 2);
  875. }
  876. }
  877. }
  878. this.SplitDate = function () //根据日期分割
  879. {
  880. this.Frame.VerticalInfo = [];
  881. var xOffset = this.Frame.Data.DataOffset;
  882. var xPointCount = this.Frame.XPointCount;
  883. var lastYear = null, lastMonth = null;
  884. var monthCount=0;
  885. for (var i = 0, index = xOffset, distance = this.MinDistance; i < xPointCount && index < this.Frame.Data.Data.length; ++i, ++index)
  886. {
  887. var year = parseInt(this.Frame.Data.Data[index].Date / 10000);
  888. var month = parseInt(this.Frame.Data.Data[index].Date / 100) % 100;
  889. if (lastMonth != month) ++monthCount;
  890. if ((distance < this.MinDistance && lastYear == year) ||
  891. (lastYear != null && lastYear == year && lastMonth != null && lastMonth == month))
  892. {
  893. lastMonth = month;
  894. ++distance;
  895. continue;
  896. }
  897. var info = new CoordinateInfo();
  898. info.Value = index - xOffset;
  899. //info.TextColor = "rgb(51,51,51)";
  900. var text;
  901. if (lastYear == null || lastYear != year)
  902. {
  903. text = year.toString();
  904. }
  905. else if (lastMonth == null || lastMonth != month)
  906. {
  907. text = month.toString() + "月";
  908. }
  909. lastYear = year;
  910. lastMonth = month;
  911. if (this.ShowText) info.Message[0] = text;
  912. if (info.Value==0) info.LineType=-1; //第1个分割线不画
  913. this.Frame.VerticalInfo.push(info);
  914. distance = 0;
  915. }
  916. if (this.Period == 0 && monthCount <= 2)
  917. this.SplitShortDate();
  918. }
  919. //分隔在2个月一下的格式
  920. this.SplitShortDate = function ()
  921. {
  922. this.Frame.VerticalInfo = [];
  923. var xOffset = this.Frame.Data.DataOffset;
  924. var xPointCount = this.Frame.XPointCount;
  925. var minDistance = 12;
  926. var isFirstYear = true;
  927. for (var i = 0, index = xOffset, distance = minDistance; i < xPointCount && index < this.Frame.Data.Data.length; ++i, ++index) {
  928. var year = parseInt(this.Frame.Data.Data[index].Date / 10000);
  929. //var month=parseInt(this.Frame.Data.Data[index].Date/100)%100;
  930. //var day=parseInt(this.Frame.Data.Data[index].Date%100);
  931. if (distance < minDistance)
  932. {
  933. ++distance;
  934. continue;
  935. }
  936. var info = new CoordinateInfo();
  937. info.Value = index - xOffset;
  938. var text;
  939. if (isFirstYear)
  940. {
  941. text = year.toString();
  942. isFirstYear = false;
  943. }
  944. else
  945. {
  946. text = IFrameSplitOperator.FormatDateString(this.Frame.Data.Data[index].Date, 'MM-DD');
  947. }
  948. if (this.ShowText) info.Message[0] = text;
  949. if (info.Value==0) info.LineType=-1; //第1个分割线不画
  950. this.Frame.VerticalInfo.push(info);
  951. distance = 0;
  952. }
  953. }
  954. this.Operator = function ()
  955. {
  956. if (this.Frame.Data == null) return;
  957. if (FrameSplitKLineX.SplitCustom) FrameSplitKLineX.SplitCustom(this); //自定义分割
  958. else if (ChartData.IsMinutePeriod(this.Period, true)) this.SplitDateTime();
  959. else if (ChartData.IsSecondPeriod(this.Period)) this.SplitSecond();
  960. else this.SplitDate();
  961. }
  962. this.CreateCoordinateInfo=function()
  963. {
  964. return new CoordinateInfo(); //创建一个节点坐标
  965. }
  966. }
  967. //FrameSplitKLineX.SplitCustom=function(split) { }
  968. function FrameSplitMinutePriceY()
  969. {
  970. this.newMethod = IFrameSplitOperator; //派生
  971. this.newMethod();
  972. delete this.newMethod;
  973. this.High = null; //最高最低价
  974. this.Low = null;
  975. this.YClose; //昨收
  976. this.Data; //分钟数据
  977. this.AverageData; //分钟均线数据
  978. this.OverlayChartPaint;
  979. this.SplitCount = 7;
  980. this.Symbol;
  981. this.SplitType=0; //0=默认根据最大最小值分割 1=涨跌停分割 2=数据最大最大值分割
  982. this.LimitPrice; //{Max: Min:} 涨跌停价
  983. this.Custom;
  984. this.Operator = function ()
  985. {
  986. this.Frame.HorizontalInfo = [];
  987. this.Frame.CustomHorizontalInfo = [];
  988. if (!this.Data) return;
  989. var range=this.GetMaxMin();
  990. if (this.Symbol && MARKET_SUFFIX_NAME.IsUSA(this.Symbol.toUpperCase()))
  991. {
  992. this.USASplit(range);
  993. }
  994. else if (this.SplitType==2)
  995. {
  996. this.USASplit(range);
  997. }
  998. else
  999. {
  1000. this.DefaultSplit(range);
  1001. }
  1002. this.CustomCoordinate();
  1003. if (this.GetEventCallback)
  1004. {
  1005. var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_SPLIT_YCOORDINATE);
  1006. if (event && event.Callback)
  1007. {
  1008. var data={ID:this.Frame.Identify, Frame:this.Frame };
  1009. event.Callback(event,data,this);
  1010. }
  1011. }
  1012. }
  1013. this.GetMaxMin = function () //计算图中所有的数据的最大最小值
  1014. {
  1015. var max = this.YClose;
  1016. var min = this.YClose;
  1017. for (var i in this.Data.Data)
  1018. {
  1019. if (!this.Data.Data[i]) continue; //价格必须大于0
  1020. if (max < this.Data.Data[i]) max = this.Data.Data[i];
  1021. if (min > this.Data.Data[i]) min = this.Data.Data[i];
  1022. }
  1023. if (this.AverageData)
  1024. {
  1025. for (var i in this.AverageData.Data)
  1026. {
  1027. if (!this.AverageData.Data[i]) continue; //价格必须大于0
  1028. if (max < this.AverageData.Data[i]) max = this.AverageData.Data[i];
  1029. if (min > this.AverageData.Data[i]) min = this.AverageData.Data[i];
  1030. }
  1031. }
  1032. if (this.OverlayChartPaint && this.OverlayChartPaint.length > 0 && this.OverlayChartPaint[0] && this.OverlayChartPaint[0].Symbol)
  1033. {
  1034. var range = this.OverlayChartPaint[0].GetMaxMin();
  1035. if (range.Max && range.Max > max) max = range.Max;
  1036. if (range.Min && range.Min < min) min = range.Min;
  1037. }
  1038. if (this.SplitType==1 && this.LimitPrice)
  1039. {
  1040. if (max<this.LimitPrice.Max) max=this.LimitPrice.Max;
  1041. if (min>this.LimitPrice.Min) min=this.LimitPrice.Min;
  1042. }
  1043. if (IFrameSplitOperator.IsNumber(this.High) && IFrameSplitOperator.IsNumber(this.Low))
  1044. {
  1045. if (max < this.High) max = this.High;
  1046. if (min > this.Low) min = this.Low;
  1047. }
  1048. return { Max: max, Min: min };
  1049. }
  1050. this.USASplit=function(range)
  1051. {
  1052. var max=range.Max;
  1053. var min=range.Min;
  1054. if (max==min)
  1055. {
  1056. max=max+max*0.1;
  1057. min=min-min*0.1;
  1058. }
  1059. else
  1060. {
  1061. var height=this.Frame.ChartBorder.GetHeight(); //画布的高度
  1062. var spacePrice=5*(max-min)/height;
  1063. max+=spacePrice;
  1064. min-=spacePrice;
  1065. if (min<0) min=range.Min;
  1066. }
  1067. var showCount=this.SplitCount;
  1068. var distance=(max-min)/(showCount-1);
  1069. const minDistance=[1, 0.1, 0.01, 0.001, 0.0001];
  1070. var defaultfloatPrecision=JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  1071. if (distance<minDistance[defaultfloatPrecision])
  1072. {
  1073. distance=minDistance[defaultfloatPrecision];
  1074. max=min+distance*showCount;
  1075. //min=this.YClose-(distance*(showCount-1)/2);
  1076. }
  1077. for(var i=0;i<showCount;++i)
  1078. {
  1079. var price=min+(distance*i);
  1080. if (this.YClose && price==this.YClose) continue;
  1081. var coordinate=new CoordinateInfo();
  1082. coordinate.Value=price;
  1083. var strPrice=price.toFixed(defaultfloatPrecision); //价格刻度字符串
  1084. if (this.IsShowLeftText) coordinate.Message[0]=strPrice;
  1085. if (this.YClose)
  1086. {
  1087. var per=(price/this.YClose-1)*100;
  1088. if (per>0) coordinate.TextColor=g_JSChartResource.UpTextColor;
  1089. else if (per<0) coordinate.TextColor=g_JSChartResource.DownTextColor;
  1090. if (this.IsShowRightText)
  1091. {
  1092. if (this.RightTextFormat==1) coordinate.Message[1]=strPrice;
  1093. else coordinate.Message[1]=IFrameSplitOperator.FormatValueString(per,2)+'%'; //百分比
  1094. }
  1095. }
  1096. this.Frame.HorizontalInfo.push(coordinate);
  1097. }
  1098. if (this.YClose>min && this.YClose<max) //前收盘线
  1099. {
  1100. var coordinate=new CoordinateInfo();
  1101. coordinate.Value=this.YClose;
  1102. coordinate.LineType=2;//中间的线画虚线
  1103. if (g_JSChartResource.FrameDotSplitPen) coordinate.LineColor=g_JSChartResource.FrameDotSplitPen;
  1104. var strPrice=this.YClose.toFixed(defaultfloatPrecision); //价格刻度字符串
  1105. if (this.IsShowLeftText) coordinate.Message[0]=strPrice;
  1106. if (this.IsShowRightText)
  1107. {
  1108. if (this.RightTextFormat==1) coordinate.Message[1]=strPrice;
  1109. else coordinate.Message[1]='0.00%'; //百分比
  1110. }
  1111. this.Frame.HorizontalInfo.push(coordinate);
  1112. }
  1113. this.Frame.HorizontalInfo.sort(function(a,b) { return a.Value-b.Value; });
  1114. this.Frame.HorizontalMax=max;
  1115. this.Frame.HorizontalMin=min;
  1116. }
  1117. this.DefaultSplit = function (range)
  1118. {
  1119. var max = range.Max;
  1120. var min = range.Min;
  1121. if (this.YClose == max && this.YClose == min)
  1122. {
  1123. max = this.YClose + this.YClose * 0.1;
  1124. min = this.YClose - this.YClose * 0.1;
  1125. }
  1126. else
  1127. {
  1128. var distanceValue = Math.max(Math.abs(this.YClose - max), Math.abs(this.YClose - min));
  1129. max = this.YClose + distanceValue;
  1130. min = this.YClose - distanceValue;
  1131. if (min<0) min=range.Min;
  1132. }
  1133. var showCount = this.SplitCount;
  1134. var distance = (max - min) / (showCount - 1);
  1135. const minDistance = [1, 0.1, 0.01, 0.001, 0.0001];
  1136. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);; //默认小数位数
  1137. if (JSCommonCoordinateData.MARKET_SUFFIX_NAME.IsSHSZIndex(this.Symbol)) defaultfloatPrecision = 0; //手机端指数不显示小数位数,太长了
  1138. if (distance < minDistance[defaultfloatPrecision])
  1139. {
  1140. distance = minDistance[defaultfloatPrecision];
  1141. max = this.YClose + (distance * (showCount - 1) / 2);
  1142. min = this.YClose - (distance * (showCount - 1) / 2);
  1143. }
  1144. for (var i = 0; i < showCount; ++i)
  1145. {
  1146. var price = min + (distance * i);
  1147. this.Frame.HorizontalInfo[i] = new CoordinateInfo();
  1148. this.Frame.HorizontalInfo[i].Value = price;
  1149. this.Frame.HorizontalInfo[i].Message[0] = price.toFixed(defaultfloatPrecision);
  1150. if (this.YClose)
  1151. {
  1152. var per = (price / this.YClose - 1) * 100;
  1153. if (per > 0) this.Frame.HorizontalInfo[i].TextColor = g_JSChartResource.UpTextColor;
  1154. else if (per < 0) this.Frame.HorizontalInfo[i].TextColor = g_JSChartResource.DownTextColor;
  1155. this.Frame.HorizontalInfo[i].Message[1] = IFrameSplitOperator.FormatValueString(per, 2) + '%'; //百分比
  1156. }
  1157. }
  1158. this.Frame.HorizontalMax = max;
  1159. this.Frame.HorizontalMin = min;
  1160. }
  1161. this.CustomCoordinate = function () //自定义刻度
  1162. {
  1163. if (!this.Custom) return;
  1164. for (var i in this.Custom)
  1165. {
  1166. var item = this.Custom[i];
  1167. if (item.Type == 1)
  1168. this.CustomFixedCoordinate(item);
  1169. else if (item.Type==0)
  1170. {
  1171. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  1172. var latestItem = this.GetLatestPrice(defaultfloatPrecision, item);
  1173. if (latestItem) this.Frame.CustomHorizontalInfo.push(latestItem);
  1174. }
  1175. }
  1176. }
  1177. this.GetLatestPrice = function (floatPrecision, option)
  1178. {
  1179. if (!this.Data || !this.Data.Data) return null;
  1180. if (this.Data.Data.length <= 0) return null;
  1181. var price = this.Data.Data[this.Data.Data.length - 1];
  1182. if (!IFrameSplitOperator.IsNumber(price) || !IFrameSplitOperator.IsNumber(this.YClose)) return null;
  1183. var info = new CoordinateInfo();
  1184. info.Type = 0;
  1185. info.Value = price;
  1186. info.TextColor = g_JSChartResource.FrameLatestPrice.TextColor;
  1187. info.LineType = 2; //虚线
  1188. if (option.Position == 'left') info.Message[0] = price.toFixed(floatPrecision);
  1189. else info.Message[1] = price.toFixed(floatPrecision);
  1190. if (price > this.YClose) info.LineColor = g_JSChartResource.FrameLatestPrice.UpBarColor;
  1191. else if (price < this.YClose) info.LineColor = g_JSChartResource.FrameLatestPrice.DownBarColor;
  1192. else info.LineColor = g_JSChartResource.FrameLatestPrice.UnchagneBarColor;
  1193. if (IFrameSplitOperator.IsNumber(option.LineType)) info.LineType=option.LineType;
  1194. if (option.IsShowLine == false) info.LineType = -1;
  1195. return info;
  1196. }
  1197. this.CustomFixedCoordinate = function (option) //固定坐标刻度
  1198. {
  1199. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  1200. for (var i in option.Data)
  1201. {
  1202. var item = option.Data[i];
  1203. var info = new CoordinateInfo();
  1204. info.Type = 1;
  1205. info.TextColor = item.TextColor;
  1206. info.LineColor = item.Color;
  1207. info.LineType = 2; //虚线
  1208. if (IFrameSplitOperator.IsNumber(option.LineType)) info.LineType=option.LineType;
  1209. if (option.IsShowLine == false) info.LineType = -1;
  1210. if (IFrameSplitOperator.IsNumber(item.Increase)) //涨幅计算价格
  1211. {
  1212. if (!IFrameSplitOperator.IsNumber(this.YClose)) conintue;
  1213. info.Value = this.YClose * (1 + item.Increase);
  1214. }
  1215. else
  1216. {
  1217. info.Value = item.Value;
  1218. }
  1219. var text;
  1220. if (item.Text) text = item.Text;
  1221. else text = info.Value.toFixed(defaultfloatPrecision);
  1222. if (option.Position == 'left') info.Message[0] = text;
  1223. else info.Message[1] = text;
  1224. this.Frame.CustomHorizontalInfo.push(info);
  1225. }
  1226. }
  1227. }
  1228. function FrameSplitMinuteX()
  1229. {
  1230. this.newMethod = IFrameSplitOperator; //派生
  1231. this.newMethod();
  1232. delete this.newMethod;
  1233. this.ShowText = true; //是否显示坐标信息
  1234. this.Symbol = null; //股票代码 x轴刻度根据股票类型来调整
  1235. this.DayCount = 1;
  1236. this.DayData;
  1237. this.Operator = function ()
  1238. {
  1239. this.Frame.VerticalInfo = [];
  1240. var xPointCount = this.Frame.XPointCount;
  1241. var width = this.Frame.ChartBorder.GetWidth();
  1242. var isHScreen = (this.Frame.IsHScreen === true);
  1243. if (isHScreen) width = this.Frame.ChartBorder.GetHeight();
  1244. const minuteCoordinate = JSCommonCoordinateData.MinuteCoordinateData;
  1245. var xcoordinateData = minuteCoordinate.GetCoordinateData(this.Symbol, width);
  1246. var minuteCount = xcoordinateData.Count;
  1247. var minuteMiddleCount = xcoordinateData.MiddleCount > 0 ? xcoordinateData.MiddleCount : parseInt(minuteCount / 2);;
  1248. var xcoordinate = xcoordinateData.Data;
  1249. this.Frame.XPointCount = 243;
  1250. this.Frame.XPointCount = minuteCount * this.DayCount;
  1251. this.Frame.MinuteCount = minuteCount;
  1252. this.Frame.VerticalInfo = [];
  1253. if (this.DayCount <= 1)
  1254. {
  1255. for (var i in xcoordinate)
  1256. {
  1257. var info = new CoordinateInfo();
  1258. //info.TextColor = "rgb(51,51,51)";
  1259. info.Value = xcoordinate[i][0];
  1260. if (this.ShowText)
  1261. info.Message[0] = xcoordinate[i][3];
  1262. this.Frame.VerticalInfo[i] = info;
  1263. }
  1264. }
  1265. else
  1266. {
  1267. for (var i = this.DayData.length - 1, j = 0; i >= 0; --i, ++j)
  1268. {
  1269. var info = new CoordinateInfo();
  1270. info.Value = j * minuteCount + minuteMiddleCount;
  1271. info.LineType = -1;
  1272. if (this.ShowText) info.Message[0] = IFrameSplitOperator.FormatDateString(this.DayData[i].Date, 'MM-DD');
  1273. this.Frame.VerticalInfo.push(info);
  1274. var info = new CoordinateInfo();
  1275. info.Value = (j + 1) * minuteCount;
  1276. this.Frame.VerticalInfo.push(info);
  1277. }
  1278. }
  1279. }
  1280. }
  1281. function FrameSplitXData()
  1282. {
  1283. this.newMethod = IFrameSplitOperator; //派生
  1284. this.newMethod();
  1285. delete this.newMethod;
  1286. this.ShowText = true; //是否显示坐标信息
  1287. this.Operator = function ()
  1288. {
  1289. if (this.Frame.Data == null || this.Frame.XData == null) return;
  1290. this.Frame.VerticalInfo = [];
  1291. var xOffset = this.Frame.Data.DataOffset;
  1292. var xPointCount = this.Frame.XPointCount;
  1293. for (var i = 0, index = xOffset; i < xPointCount && index < this.Frame.Data.Data.length; ++i, ++index)
  1294. {
  1295. var info = new CoordinateInfo();
  1296. info.Value = index - xOffset;
  1297. if (this.ShowText)
  1298. info.Message[0] = this.Frame.XData[i];
  1299. this.Frame.VerticalInfo.push(info);
  1300. }
  1301. }
  1302. }
  1303. //深度图X轴价格信息
  1304. function FrameSplitXDepth()
  1305. {
  1306. this.newMethod=IFrameSplitOperator; //派生
  1307. this.newMethod();
  1308. delete this.newMethod;
  1309. this.ShowText=true; //是否显示坐标信息
  1310. this.SplitCount=3;
  1311. this.Symbol;
  1312. this.LineType=3;
  1313. this.Operator=function()
  1314. {
  1315. var xRange=this.Frame.VerticalRange;
  1316. if (!xRange) return;
  1317. this.Frame.VerticalInfo=[];
  1318. var floatPrecision=2;
  1319. if (this.Symbol) floatPrecision=JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  1320. var xMax=xRange.Max;
  1321. var xMin=xRange.Min;
  1322. if (xRange.Bid)
  1323. {
  1324. var interval=(xRange.Bid.Max-xMin)/this.SplitCount;
  1325. for(var i=0;i<this.SplitCount;++i)
  1326. {
  1327. var info= new CoordinateInfo();
  1328. info.Value=xMin+(interval*i);
  1329. if (info.Value<=0) continue;
  1330. if (IFrameSplitOperator.IsNumber(this.LineType)) info.LineType=this.LineType;
  1331. if (this.ShowText) info.Message[0]=info.Value.toFixed(floatPrecision);
  1332. this.Frame.VerticalInfo.push(info);
  1333. }
  1334. }
  1335. var info=new CoordinateInfo();
  1336. info.Value=xRange.Center;
  1337. this.Frame.VerticalInfo.push(info);
  1338. if (xRange.Ask)
  1339. {
  1340. var interval=(xMax-xRange.Ask.Min)/this.SplitCount;
  1341. for(var i=1;i<=this.SplitCount;++i)
  1342. {
  1343. var info= new CoordinateInfo();
  1344. info.Value=xRange.Ask.Min+(interval*i);
  1345. if (IFrameSplitOperator.IsNumber(this.LineType)) info.LineType=this.LineType;
  1346. if (this.ShowText) info.Message[0]=info.Value.toFixed(floatPrecision);
  1347. this.Frame.VerticalInfo.push(info);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  1353. // 数据分割
  1354. // [0]=Start起始 [1]=End结束 [2]=FixInterval修正的间隔 [3]=Increase
  1355. //
  1356. function SplitData() {
  1357. this.Data = [
  1358. [0.000001, 0.000002, 0.000001, 0.0000001],
  1359. [0.000002, 0.000004, 0.000002, 0.0000002],
  1360. [0.000004, 0.000005, 0.000004, 0.0000001],
  1361. [0.000005, 0.00001, 0.000005, 0.0000005],
  1362. [0.00001, 0.00002, 0.00001, 0.000001],
  1363. [0.00002, 0.00004, 0.00002, 0.000002],
  1364. [0.00004, 0.00005, 0.00004, 0.000001],
  1365. [0.00005, 0.0001, 0.00005, 0.000005],
  1366. [0.0001, 0.0002, 0.0001, 0.00001],
  1367. [0.0002, 0.0004, 0.0002, 0.00002],
  1368. [0.0004, 0.0005, 0.0004, 0.00001],
  1369. [0.0005, 0.001, 0.0005, 0.00005],
  1370. [0.001, 0.002, 0.001, 0.0001],
  1371. [0.002, 0.004, 0.002, 0.0002],
  1372. [0.004, 0.005, 0.004, 0.0001],
  1373. [0.005, 0.01, 0.005, 0.0005],
  1374. [0.01, 0.02, 0.01, 0.001],
  1375. [0.02, 0.04, 0.02, 0.002],
  1376. [0.04, 0.05, 0.04, 0.001],
  1377. [0.05, 0.1, 0.05, 0.005],
  1378. [0.1, 0.2, 0.1, 0.01],
  1379. [0.2, 0.4, 0.2, 0.02],
  1380. [0.4, 0.5, 0.4, 0.01],
  1381. [0.5, 1, 0.5, 0.05],
  1382. [1, 2, 1, 0.05],
  1383. [2, 4, 2, 0.05],
  1384. [4, 5, 4, 0.05],
  1385. [5, 10, 5, 0.05],
  1386. [10, 20, 10, 2],
  1387. [20, 40, 20, 5],
  1388. [40, 50, 40, 2],
  1389. [50, 100, 50, 10],
  1390. [100, 200, 100, 10],
  1391. [200, 400, 200, 20],
  1392. [400, 500, 400, 10],
  1393. [500, 1000, 500, 50],
  1394. [1000, 2000, 1000, 50],
  1395. [2000, 4000, 2000, 50],
  1396. [4000, 5000, 4000, 50],
  1397. [5000, 10000, 5000, 100],
  1398. [10000, 20000, 10000, 1000],
  1399. [20000, 40000, 20000, 2000],
  1400. [40000, 50000, 40000, 1000],
  1401. [50000, 100000, 50000, 5000],
  1402. [100000, 200000, 100000, 10000],
  1403. [200000, 400000, 200000, 20000],
  1404. [400000, 500000, 400000, 10000],
  1405. [500000, 1000000, 500000, 50000],
  1406. [1000000, 2000000, 1000000, 100000],
  1407. [2000000, 4000000, 2000000, 200000],
  1408. [4000000, 5000000, 4000000, 100000],
  1409. [5000000, 10000000, 5000000, 500000],
  1410. [10000000, 20000000, 10000000, 1000000],
  1411. [20000000, 40000000, 20000000, 2000000],
  1412. [40000000, 50000000, 40000000, 1000000],
  1413. [50000000, 100000000, 50000000, 5000000],
  1414. [100000000, 200000000, 100000000, 10000000],
  1415. [200000000, 400000000, 100000000, 10000000],
  1416. [400000000, 500000000, 100000000, 10000000],
  1417. [500000000, 1000000000, 100000000, 10000000],
  1418. [1000000000, 2000000000, 1000000000, 100000000],
  1419. [2000000000, 4000000000, 2000000000, 200000000],
  1420. [4000000000, 5000000000, 4000000000, 100000000],
  1421. [5000000000, 10000000000, 5000000000, 500000000],
  1422. ];
  1423. this.Find = function (interval) {
  1424. for (var i in this.Data) {
  1425. var item = this.Data[i];
  1426. if (interval > item[0] && interval <= item[1]) {
  1427. var result = {};
  1428. result.FixInterval = item[2];
  1429. result.Increase = item[3];
  1430. return result;
  1431. }
  1432. }
  1433. return null;
  1434. }
  1435. }
  1436. function PriceSplitData() {
  1437. this.newMethod = SplitData; //派生
  1438. this.newMethod();
  1439. delete this.newMethod;
  1440. this.Data = [
  1441. [0.000001, 0.000002, 0.000001, 0.0000001],
  1442. [0.000002, 0.000004, 0.000002, 0.0000002],
  1443. [0.000004, 0.000005, 0.000004, 0.0000001],
  1444. [0.000005, 0.00001, 0.000005, 0.0000005],
  1445. [0.00001, 0.00002, 0.00001, 0.000001],
  1446. [0.00002, 0.00004, 0.00002, 0.000002],
  1447. [0.00004, 0.00005, 0.00004, 0.000001],
  1448. [0.00005, 0.0001, 0.00005, 0.000005],
  1449. [0.0001, 0.0002, 0.0001, 0.00001],
  1450. [0.0002, 0.0004, 0.0002, 0.00002],
  1451. [0.0004, 0.0005, 0.0004, 0.00001],
  1452. [0.0005, 0.001, 0.0005, 0.00005],
  1453. [0.001, 0.002, 0.001, 0.0001],
  1454. [0.002, 0.004, 0.002, 0.0002],
  1455. [0.004, 0.005, 0.004, 0.0001],
  1456. [0.005, 0.01, 0.005, 0.0005],
  1457. [0.01, 0.02, 0.01, 0.001],
  1458. [0.02, 0.04, 0.02, 0.002],
  1459. [0.04, 0.05, 0.04, 0.001],
  1460. [0.05, 0.1, 0.05, 0.005],
  1461. [0.1, 0.2, 0.1, 0.01],
  1462. [0.2, 0.4, 0.2, 0.02],
  1463. [0.4, 0.5, 0.2, 0.01],
  1464. [0.5, 0.8, 0.2, 0.05],
  1465. [0.8, 1, 0.5, 0.05],
  1466. [1, 2, 0.5, 0.05],
  1467. [2, 4, 0.5, 0.05],
  1468. [4, 5, 0.5, 0.05],
  1469. [5, 10, 0.5, 0.05],
  1470. [10, 12, 10, 2],
  1471. [20, 40, 20, 5],
  1472. [40, 50, 40, 2],
  1473. [50, 100, 50, 10],
  1474. [100, 200, 100, 10],
  1475. [200, 400, 200, 20],
  1476. [400, 500, 400, 10],
  1477. [500, 1000, 500, 50],
  1478. [1000, 2000, 1000, 50],
  1479. [2000, 4000, 2000, 50],
  1480. [4000, 5000, 4000, 50],
  1481. [5000, 10000, 5000, 100],
  1482. [10000, 20000, 10000, 1000],
  1483. [20000, 40000, 20000, 2000],
  1484. [40000, 50000, 40000, 1000],
  1485. [50000, 100000, 50000, 5000],
  1486. [100000, 200000, 100000, 10000],
  1487. [200000, 400000, 200000, 20000],
  1488. [400000, 500000, 400000, 10000],
  1489. [500000, 1000000, 500000, 50000],
  1490. [1000000, 2000000, 1000000, 100000],
  1491. [2000000, 4000000, 2000000, 200000],
  1492. [4000000, 5000000, 4000000, 100000],
  1493. [5000000, 10000000, 5000000, 500000],
  1494. [10000000, 20000000, 10000000, 1000000],
  1495. [20000000, 40000000, 20000000, 2000000],
  1496. [40000000, 50000000, 40000000, 1000000],
  1497. [50000000, 100000000, 50000000, 5000000],
  1498. [100000000, 200000000, 100000000, 10000000],
  1499. [200000000, 400000000, 200000000, 20000000],
  1500. [400000000, 500000000, 400000000, 10000000],
  1501. [500000000, 1000000000, 500000000, 50000000],
  1502. [1000000000, 2000000000, 1000000000, 100000000],
  1503. [2000000000, 4000000000, 2000000000, 200000000],
  1504. [4000000000, 5000000000, 4000000000, 100000000],
  1505. [5000000000, 10000000000, 5000000000, 500000000],
  1506. ];
  1507. }
  1508. //整数分割
  1509. function IntegerSplitData() {
  1510. this.newMethod = SplitData; //派生
  1511. this.newMethod();
  1512. delete this.newMethod;
  1513. this.Data =
  1514. [
  1515. [0.000001, 0.000002, 0.000001, 0.0000001],
  1516. [0.000002, 0.000004, 0.000002, 0.0000002],
  1517. [0.000004, 0.000005, 0.000004, 0.0000001],
  1518. [0.000005, 0.00001, 0.000005, 0.0000005],
  1519. [0.00001, 0.00002, 0.00001, 0.000001],
  1520. [0.00002, 0.00004, 0.00002, 0.000002],
  1521. [0.00004, 0.00005, 0.00004, 0.000001],
  1522. [0.00005, 0.0001, 0.00005, 0.000005],
  1523. [0.0001, 0.0002, 0.0001, 0.00001],
  1524. [0.0002, 0.0004, 0.0002, 0.00002],
  1525. [0.0004, 0.0005, 0.0004, 0.00001],
  1526. [0.0005, 0.001, 0.0005, 0.00005],
  1527. [0.001, 0.002, 0.001, 0.0001],
  1528. [0.002, 0.004, 0.002, 0.0002],
  1529. [0.004, 0.005, 0.004, 0.0001],
  1530. [0.005, 0.01, 0.005, 0.0005],
  1531. [0.01, 0.02, 0.01, 0.001],
  1532. [0.02, 0.04, 0.02, 0.002],
  1533. [0.04, 0.05, 0.04, 0.001],
  1534. [0.05, 0.1, 0.05, 0.005],
  1535. [0.1, 0.2, 1, 1],
  1536. [0.2, 0.4, 1, 1],
  1537. [0.4, 0.5, 1, 1],
  1538. [0.5, 0.8, 1, 1],
  1539. [0.8, 1, 1, 1],
  1540. [1, 2, 1, 1],
  1541. [2, 4, 2, 1],
  1542. [4, 5, 4, 1],
  1543. [5, 10, 5, 1],
  1544. [10, 12, 10, 2],
  1545. [20, 40, 20, 5],
  1546. [40, 50, 40, 2],
  1547. [50, 100, 50, 10],
  1548. [100, 200, 100, 10],
  1549. [200, 400, 200, 20],
  1550. [400, 500, 400, 10],
  1551. [500, 1000, 500, 50],
  1552. [1000, 2000, 1000, 50],
  1553. [2000, 4000, 2000, 50],
  1554. [4000, 5000, 4000, 50],
  1555. [5000, 10000, 5000, 100],
  1556. [10000, 20000, 10000, 1000],
  1557. [20000, 40000, 20000, 2000],
  1558. [40000, 50000, 40000, 1000],
  1559. [50000, 100000, 50000, 5000],
  1560. [100000, 200000, 100000, 10000],
  1561. [200000, 400000, 200000, 20000],
  1562. [400000, 500000, 400000, 10000],
  1563. [500000, 1000000, 500000, 50000],
  1564. [1000000, 2000000, 1000000, 100000],
  1565. [2000000, 4000000, 2000000, 200000],
  1566. [4000000, 5000000, 4000000, 100000],
  1567. [5000000, 10000000, 5000000, 500000],
  1568. [10000000, 20000000, 10000000, 1000000],
  1569. [20000000, 40000000, 20000000, 2000000],
  1570. [40000000, 50000000, 40000000, 1000000],
  1571. [50000000, 100000000, 50000000, 5000000],
  1572. [100000000, 200000000, 100000000, 10000000],
  1573. [200000000, 400000000, 200000000, 20000000],
  1574. [400000000, 500000000, 400000000, 10000000],
  1575. [500000000, 1000000000, 500000000, 50000000],
  1576. [1000000000, 2000000000, 1000000000, 100000000],
  1577. [2000000000, 4000000000, 2000000000, 200000000],
  1578. [4000000000, 5000000000, 4000000000, 100000000],
  1579. [5000000000, 10000000000, 5000000000, 500000000],
  1580. ];
  1581. }
  1582. /////////////////////////////////////////////////////////////////////////////////
  1583. //
  1584. function IChangeStringFormat() {
  1585. this.Data;
  1586. this.Value; //数据
  1587. this.Text; //输出字符串
  1588. this.Operator = function () {
  1589. return false;
  1590. }
  1591. }
  1592. function HQPriceStringFormat()
  1593. {
  1594. this.newMethod = IChangeStringFormat; //派生
  1595. this.newMethod();
  1596. delete this.newMethod;
  1597. this.Symbol;
  1598. this.FrameID;
  1599. this.LanguageID = JSCHART_LANGUAGE_ID.LANGUAGE_CHINESE_ID;
  1600. this.PercentageText; //百分比
  1601. this.RValue; //右边值
  1602. this.RText;
  1603. this.Operator = function ()
  1604. {
  1605. this.RText = null;
  1606. if (IFrameSplitOperator.IsString(this.RValue)) this.RText = this.RValue;
  1607. if (!this.Value) return false;
  1608. var defaultfloatPrecision = 2; //价格小数位数
  1609. if (this.FrameID == 0) //第1个窗口显示原始价格
  1610. {
  1611. var defaultfloatPrecision = JSCommonCoordinateData.GetfloatPrecision(this.Symbol);
  1612. this.Text = this.Value.toFixed(defaultfloatPrecision);
  1613. }
  1614. else
  1615. {
  1616. this.Text = IFrameSplitOperator.FormatValueString(this.Value, defaultfloatPrecision, this.LanguageID);
  1617. }
  1618. return true;
  1619. }
  1620. }
  1621. function HQDateStringFormat()
  1622. {
  1623. this.newMethod = IChangeStringFormat; //派生
  1624. this.newMethod();
  1625. delete this.newMethod;
  1626. this.DateFormatType=0; //0=YYYY-MM-DD 1=YYYY/MM/DD 2=YYYY/MM/DD/W 3=DD/MM/YYYY
  1627. this.LanguageID=0;
  1628. this.Operator = function ()
  1629. {
  1630. if (!IFrameSplitOperator.IsNumber(this.Value) || this.Value<0) return false;
  1631. if (!this.Data) return false;
  1632. var index = this.Value;
  1633. index = parseInt(index.toFixed(0));
  1634. if (this.Data.DataOffset + index >= this.Data.Data.length) return false;
  1635. var currentData = this.Data.Data[this.Data.DataOffset + index];
  1636. var date = currentData.Date;
  1637. var dateFormatString="YYYY-MM-DD";
  1638. if (this.DateFormatType==1) dateFormatString="YYYY/MM/DD";
  1639. else if (this.DateFormatType==2) dateFormatString="YYYY/MM/DD/W";
  1640. else if (this.DateFormatType==3) dateFormatString="DD/MM/YYYY";
  1641. this.Text = IFrameSplitOperator.FormatDateString(date,dateFormatString,this.LanguageID);
  1642. if (ChartData.IsMinutePeriod(this.Data.Period, true)) // 分钟周期
  1643. {
  1644. var time = IFrameSplitOperator.FormatTimeString(currentData.Time);
  1645. this.Text = this.Text + " " + time;
  1646. }
  1647. else if (ChartData.IsSecondPeriod(this.Data.Period))
  1648. {
  1649. var time = IFrameSplitOperator.FormatTimeString(currentData.Time,"HH:MM:SS");
  1650. this.Text = this.Text + " " + time;
  1651. }
  1652. return true;
  1653. }
  1654. }
  1655. function HQMinuteTimeStringFormat()
  1656. {
  1657. this.newMethod = IChangeStringFormat; //派生
  1658. this.newMethod();
  1659. delete this.newMethod;
  1660. this.Frame;
  1661. this.Symbol;
  1662. this.Operator = function ()
  1663. {
  1664. if (this.Value == null || isNaN(this.Value)) return false;
  1665. var index = Math.abs(this.Value);
  1666. index = parseInt(index.toFixed(0));
  1667. var showIndex = index;
  1668. if (this.Frame && this.Frame.MinuteCount) showIndex = index % this.Frame.MinuteCount;
  1669. var timeStringData = JSCommonCoordinateData.MinuteTimeStringData;
  1670. var timeData = timeStringData.GetTimeData(this.Symbol);
  1671. if (!timeData) return false;
  1672. if (showIndex < 0) showIndex = 0;
  1673. else if (showIndex > timeData.length) showIndex = timeData.length - 1;
  1674. if (this.Frame && index >= this.Frame.XPointCount)
  1675. showIndex = timeData.length - 1;
  1676. var time = timeData[showIndex];
  1677. this.Text = IFrameSplitOperator.FormatTimeString(time);
  1678. return true;
  1679. }
  1680. }
  1681. function DivTooltipDataForamt()
  1682. {
  1683. this.DataMap=new Map(
  1684. [
  1685. ["CorssCursor_XStringFormat", { Create:function() { return new HQDateStringFormat(); } }],
  1686. ["CorssCursor_YStringFormat", { Create:function() { return new HQPriceStringFormat(); } }]
  1687. ]
  1688. );
  1689. this.Create=function(name)
  1690. {
  1691. if (!this.DataMap.has(name)) return null;
  1692. var item=this.DataMap.get(name);
  1693. return item.Create();
  1694. }
  1695. }
  1696. var g_DivTooltipDataForamt=new DivTooltipDataForamt();
  1697. //导出统一使用JSCommon命名空间名
  1698. module.exports =
  1699. {
  1700. JSCommonSplit:
  1701. {
  1702. CoordinateInfo: CoordinateInfo,
  1703. IFrameSplitOperator: IFrameSplitOperator,
  1704. FrameSplitKLinePriceY: FrameSplitKLinePriceY,
  1705. FrameSplitY: FrameSplitY,
  1706. FrameSplitKLineX: FrameSplitKLineX,
  1707. FrameSplitMinutePriceY: FrameSplitMinutePriceY,
  1708. FrameSplitMinuteX: FrameSplitMinuteX,
  1709. FrameSplitXData: FrameSplitXData,
  1710. SplitData: SplitData,
  1711. PriceSplitData: PriceSplitData,
  1712. FrameSplitXDepth:FrameSplitXDepth,
  1713. IChangeStringFormat:IChangeStringFormat,
  1714. HQPriceStringFormat:HQPriceStringFormat,
  1715. HQDateStringFormat:HQDateStringFormat,
  1716. HQMinuteTimeStringFormat:HQMinuteTimeStringFormat,
  1717. },
  1718. JSCommonSplit_CoordinateInfo: CoordinateInfo,
  1719. JSCommonSplit_IFrameSplitOperator: IFrameSplitOperator,
  1720. JSCommonSplit_FrameSplitKLinePriceY: FrameSplitKLinePriceY,
  1721. JSCommonSplit_FrameSplitY: FrameSplitY,
  1722. JSCommonSplit_FrameSplitKLineX: FrameSplitKLineX,
  1723. JSCommonSplit_FrameSplitMinutePriceY: FrameSplitMinutePriceY,
  1724. JSCommonSplit_FrameSplitMinuteX: FrameSplitMinuteX,
  1725. JSCommonSplit_FrameSplitXData: FrameSplitXData,
  1726. JSCommonSplit_SplitData: SplitData,
  1727. JSCommonSplit_PriceSplitData: PriceSplitData,
  1728. JSCommonSplit_FrameSplitXDepth:FrameSplitXDepth,
  1729. JSCommonFormat_IChangeStringFormat:IChangeStringFormat,
  1730. JSCommonFormat_HQPriceStringFormat:HQPriceStringFormat,
  1731. JSCommonFormat_HQDateStringFormat:HQDateStringFormat,
  1732. JSCommonFormat_HQMinuteTimeStringFormat:HQMinuteTimeStringFormat,
  1733. JSCommonFormat_Global_DataFormat :g_DivTooltipDataForamt,
  1734. };