hqchart 1.1.14056 → 1.1.14072

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hqchart",
3
- "version": "1.1.14056",
3
+ "version": "1.1.14072",
4
4
  "description": "HQChart - H5, 微信小程序 沪深/港股/数字货币/期货/美股 K线图(kline),走势图,缩放,拖拽,十字光标,画图工具,截图,筹码图. 分析家语法,通达信语法,(麦语法),第3方数据对接",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -0,0 +1,603 @@
1
+
2
+ /*
3
+ Copyright (c) 2018 jones
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ 开源项目 https://github.com/jones2000/HQChart
8
+
9
+ jones_2000@163.com
10
+
11
+ 内置指标搜索对话框
12
+ */
13
+
14
+
15
+ function JSDialogSearchIndex()
16
+ {
17
+ this.DivDialog=null;
18
+ this.DragTitle=null;
19
+ this.TitleBox=null; //{ DivTitle, DivName, DivName }
20
+ this.InputDom=null;
21
+ this.Style=0; //样式 预留
22
+
23
+ this.HQChart=null;
24
+
25
+ //{ WindowIndex:窗口索引, OpType:1=切换主图指标 2=添加叠加指标, Title: };
26
+ this.OpData=null;
27
+
28
+ this.TitleColor=g_JSChartResource.DialogSearchIndex.TitleColor;
29
+ this.TitleBGColor=g_JSChartResource.DialogSearchIndex.TitleBGColor;
30
+ this.BGColor=g_JSChartResource.DialogSearchIndex.BGColor;
31
+ this.BorderColor=g_JSChartResource.DialogSearchIndex.BorderColor;
32
+ this.IndexNameColor=g_JSChartResource.DialogSearchIndex.IndexNameColor;
33
+ this.GroupNameColor=g_JSChartResource.DialogSearchIndex.GroupNameColor;
34
+ this.InputTextColor=g_JSChartResource.DialogSearchIndex.InputTextColor;
35
+
36
+ this.MaxRowCount=30; //行
37
+ this.ColCount=3; //列
38
+ this.MaxGroupCount=10; //分类最多个数
39
+
40
+ this.AryData=[];
41
+ this.AryGroup=[]; //分类
42
+ this.IndexData=JSDialogSearchIndex.GetDefaultIndexData();
43
+
44
+ this.Inital=function(hqchart, option)
45
+ {
46
+ this.HQChart=hqchart;
47
+ if (option)
48
+ {
49
+ if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style;
50
+ if (option.IndexData) this.IndexData=option.IndexData;
51
+ }
52
+ }
53
+
54
+ this.Destroy=function()
55
+ {
56
+ this.AryData=[];
57
+ this.AryGroup=[];
58
+ this.IndexData=null;
59
+ this.InputDom=null;
60
+
61
+ if (this.DivDialog)
62
+ {
63
+ document.body.removeChild(this.DivDialog);
64
+ this.DivDialog=null;
65
+ }
66
+ }
67
+
68
+ this.OnClickColseButton=function(e)
69
+ {
70
+ this.Close(e);
71
+ }
72
+
73
+ //设置当前窗口数据
74
+ this.SetOpData=function(data)
75
+ {
76
+ this.OpData=data;
77
+ }
78
+
79
+ this.Close=function(e)
80
+ {
81
+ this.OpData=null;
82
+ if (!this.DivDialog) return;
83
+
84
+ this.DivDialog.style.visibility='hidden';
85
+ }
86
+
87
+ this.OnMouseDownTitle=function(e)
88
+ {
89
+ if (!this.DivDialog) return;
90
+
91
+ var dragData={ X:e.clientX, Y:e.clientY };
92
+ dragData.YOffset=e.clientX - this.DivDialog.offsetLeft;
93
+ dragData.XOffset=e.clientY - this.DivDialog.offsetTop;
94
+ this.DragTitle=dragData;
95
+
96
+ document.onmousemove=(e)=>{ this.DocOnMouseMoveTitle(e); }
97
+ document.onmouseup=(e)=>{ this.DocOnMouseUpTitle(e); }
98
+ }
99
+
100
+ this.DocOnMouseMoveTitle=function(e)
101
+ {
102
+ if (!this.DragTitle) return;
103
+
104
+ var left = e.clientX - this.DragTitle.YOffset;
105
+ var top = e.clientY - this.DragTitle.XOffset;
106
+
107
+ var right=left+this.DivDialog.offsetWidth;
108
+ var bottom=top+ this.DivDialog.offsetHeight;
109
+
110
+ if ((right+5)>=window.innerWidth) left=window.innerWidth-this.DivDialog.offsetWidth-5;
111
+ if ((bottom+5)>=window.innerHeight) top=window.innerHeight-this.DivDialog.offsetHeight-5;
112
+
113
+ this.DivDialog.style.left = left + 'px';
114
+ this.DivDialog.style.top = top + 'px';
115
+
116
+ if(e.preventDefault) e.preventDefault();
117
+ }
118
+
119
+ this.DocOnMouseUpTitle=function(e)
120
+ {
121
+ this.DragTitle=null;
122
+ this.onmousemove = null;
123
+ this.onmouseup = null;
124
+ }
125
+
126
+ this.Show=function(x, y, groupID)
127
+ {
128
+ if (!this.DivDialog) return;
129
+
130
+ if (!groupID) groupID=this.IndexData.Data[0].Group.ID;
131
+
132
+ this.UpdateGroupData();
133
+ this.ChangeGroup(groupID);
134
+
135
+ if (this.OpData && this.OpData.Title) this.TitleBox.DivName.innerText=this.OpData.Title;
136
+
137
+ if (!IFrameSplitOperator.IsNumber(x) || !IFrameSplitOperator.IsNumber(y)) //默认居中显示
138
+ {
139
+ var rtClient=this.HQChart.UIElement.getBoundingClientRect();
140
+ x=rtClient.left+(rtClient.right-rtClient.left-this.DivDialog.offsetWidth)/2;
141
+ y=rtClient.top+(rtClient.bottom-rtClient.top-this.DivDialog.offsetHeight)/2;
142
+ }
143
+
144
+ this.InputDom.value="";
145
+
146
+ this.DivDialog.style.visibility='visible';
147
+ this.DivDialog.style.top = y + "px";
148
+ this.DivDialog.style.left = x + "px";
149
+ }
150
+
151
+ this.Create=function()
152
+ {
153
+ var divDom=document.createElement("div");
154
+ divDom.className='UMyChart_SearchIndex_Dialog_Div';
155
+
156
+ //对话框标题栏
157
+ var divTitle=document.createElement("div");
158
+ divTitle.className='UMyChart_SearchIndex_Title_Div';
159
+ divTitle.onmousedown=(e)=>{ this.OnMouseDownTitle(e);}
160
+ divDom.appendChild(divTitle);
161
+
162
+ var divName=document.createElement("div");
163
+ divName.className='UMyChart_SearchIndex_Name_Div';
164
+ divName.innerText="指标搜索";
165
+ divTitle.appendChild(divName);
166
+
167
+ var divClose=document.createElement("div");
168
+ divClose.className='UMyChart_SearchIndex_Close_Div';
169
+ divClose.innerText="x";
170
+ divClose.onmousedown=(e)=>{ this.OnClickColseButton(e); }
171
+ divTitle.appendChild(divClose);
172
+
173
+ //整个框子
174
+ var divFrame=document.createElement("div");
175
+ divFrame.className="UMyChart_SearchIndex_Frome_Div";
176
+ divDom.appendChild(divFrame);
177
+
178
+ //搜索框
179
+ var divInput=document.createElement("div");
180
+ divInput.className="UMyChart_SearchIndex_Input_Div";
181
+ divFrame.appendChild(divInput);
182
+
183
+ var input=document.createElement("input");
184
+ input.className='UMyChart_SearchIndex_Input';
185
+ input.type="text";
186
+ input.placeholder="输入指标名称"
187
+ input.addEventListener("input", (e)=>{this.OnInputSearch(e); })
188
+ divInput.appendChild(input);
189
+ this.InputDom=input;
190
+
191
+ //分类+指标内容
192
+ var divContainer=document.createElement("div");
193
+ divContainer.className="UMyChart_SearchIndex_Container_Div";
194
+ divDom.appendChild(divContainer);
195
+
196
+ //分类
197
+ var divGroup=document.createElement("div");
198
+ divGroup.className="UMyChart_SearchIndex_GroupList_Div";
199
+ divContainer.appendChild(divGroup);
200
+
201
+ for(var i=0, j=0;i<this.MaxGroupCount;++i)
202
+ {
203
+ var groupItem={ Div:null, Span:null };
204
+ var divItem=document.createElement("div");
205
+ divItem.className="UMyChart_SearchIndex_Group_Div";
206
+ divGroup.appendChild(divItem);
207
+ groupItem.Div=divItem;
208
+
209
+ var spanDom=document.createElement("span");
210
+ spanDom.className='UMyChart_SearchIndex_Group_Span';
211
+ spanDom.innerText='分类名称';
212
+ divItem.appendChild(spanDom);
213
+ groupItem.Span=spanDom;
214
+
215
+ spanDom.onmousedown=(e)=>{ this.OnClickGroup(e); }
216
+
217
+ this.AryGroup.push(groupItem);
218
+ }
219
+
220
+
221
+ //表格
222
+ var divTable=document.createElement("div");
223
+ divTable.className='UMyChart_SearchIndex_Table_Div';
224
+ divContainer.appendChild(divTable);
225
+
226
+ var table=document.createElement("table");
227
+ table.className="UMyChart_SearchIndex_Table";
228
+ divTable.appendChild(table);
229
+
230
+ var tbody=document.createElement("tbody");
231
+ tbody.className="UMyChart_SearchIndex_Tbody";
232
+ table.appendChild(tbody);
233
+
234
+ this.AryData=[];
235
+
236
+ for(var i=0, j=0;i<this.MaxRowCount;++i)
237
+ {
238
+ var rowItem={ Tr:null, AryCell:[] };
239
+
240
+ var trDom=document.createElement("tr");
241
+ trDom.className='UMyChart_SearchIndex_Group_Tr';
242
+ tbody.appendChild(trDom);
243
+ rowItem.Tr=trDom;
244
+
245
+ for(j=0; j<this.ColCount;++j)
246
+ {
247
+ var cellItem=this.CreateCellDOM(i,j,trDom);
248
+ rowItem.AryCell.push(cellItem);
249
+ }
250
+
251
+ this.AryData.push(rowItem);
252
+ }
253
+
254
+ document.body.appendChild(divDom);
255
+
256
+ this.DivName=divName;
257
+ this.DivDialog=divDom;
258
+ this.TitleBox={ DivTitle:divTitle, DivName:divName, DivColor:divClose };
259
+
260
+ this.UpdateStyle();
261
+ }
262
+
263
+ this.CreateCellDOM=function(rowID, colID, trDom)
264
+ {
265
+ var cellItem={ Td:null, Span:null, RowID:rowID, ColID:colID, IndexItem:null };
266
+ var tdDom=document.createElement("td");
267
+ tdDom.className="UMyChart_SearchIndex_Text_Td"; //指标名称
268
+ trDom.appendChild(tdDom);
269
+ cellItem.Td=tdDom;
270
+
271
+ var spanDom=document.createElement("span");
272
+ spanDom.className='UMyChart_SearchIndex_Text_Span';
273
+ spanDom.innerText='指标名称';
274
+ spanDom.onmousedown=(e)=>{ this.OnClickIndex(e, cellItem); }
275
+ tdDom.appendChild(spanDom);
276
+ cellItem.Span=spanDom;
277
+
278
+ return cellItem;
279
+ }
280
+
281
+
282
+ this.OnClickIndex=function(e, cellItem)
283
+ {
284
+ if (!this.OpData) return;
285
+ if (!cellItem || !cellItem.IndexItem) return;
286
+
287
+ if (this.OpData.OpType==1)
288
+ {
289
+ if (!IFrameSplitOperator.IsNumber(this.OpData.WindowIndex)) return;
290
+ var indexItem=cellItem.IndexItem;
291
+ if (indexItem.Type==0) //系统指标
292
+ {
293
+ this.HQChart.ChangeIndex(this.OpData.WindowIndex, indexItem.ID );
294
+ }
295
+ else if (indexItem.Type==1) //自定义通达性
296
+ {
297
+
298
+ }
299
+ else if (indexItem.Type==2) //api指标
300
+ {
301
+
302
+ }
303
+ }
304
+ else if (this.OpData.OpType==2)
305
+ {
306
+ if (!IFrameSplitOperator.IsNumber(this.OpData.WindowIndex)) return;
307
+ var indexItem=cellItem.IndexItem;
308
+
309
+ if (indexItem.Type==0) //系统指标
310
+ {
311
+ var obj={ WindowIndex:this.OpData.WindowIndex, IndexName:indexItem.ID };
312
+ this.HQChart.AddOverlayIndex(obj);
313
+ }
314
+ else if (indexItem.Type==1) //自定义通达性
315
+ {
316
+
317
+ }
318
+ else if (indexItem.Type==2) //api指标
319
+ {
320
+
321
+ }
322
+ }
323
+
324
+ }
325
+
326
+ this.OnClickGroup=function(e)
327
+ {
328
+ if (!e.target) return false;
329
+ var groupID=e.target.dataset.groupid;
330
+ if (!groupID) return false;
331
+
332
+ this.ChangeGroup(groupID);
333
+ }
334
+
335
+ this.UpdateStyle=function()
336
+ {
337
+ if (!this.DivDialog) return;
338
+
339
+ if (this.BGColor) this.DivDialog.style['background-color']=this.BGColor;
340
+ if (this.BorderColor) this.DivDialog.style['border-color']=this.BorderColor;
341
+
342
+ if (this.TitleBGColor) this.TitleBox.DivTitle.style['background-color']=this.TitleBGColor;
343
+ if (this.TitleColor) this.TitleBox.DivName.style['color']=this.TitleColor;
344
+
345
+ if (this.InputTextColor) this.InputDom.style['color']=this.InputTextColor;
346
+ };
347
+
348
+ this.ChangeGroup=function(groupID)
349
+ {
350
+ if (!this.IndexData) return;
351
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.IndexData.Data)) return;
352
+
353
+ var findItem=null;
354
+ for(var i=0; i<this.IndexData.Data.length; ++i)
355
+ {
356
+ var item=this.IndexData.Data[i];
357
+ if (item.Group.ID==groupID)
358
+ {
359
+ findItem=item;
360
+ break;
361
+ }
362
+ }
363
+
364
+ if (!findItem) return;
365
+
366
+ this.UpdateTableData(findItem);
367
+ }
368
+
369
+ //左侧分类
370
+ this.UpdateGroupData=function()
371
+ {
372
+ var index=0;
373
+ for(index=0; index<this.IndexData.Data.length && index<this.AryGroup.length; ++index)
374
+ {
375
+ var item=this.IndexData.Data[index];
376
+ var cell=this.AryGroup[index];
377
+ cell.Span.innerText=item.Group.Name;
378
+ cell.Span.dataset.groupid=item.Group.ID;
379
+ cell.Span.dataset.groupname=item.Group.Name;
380
+ cell.Span.style.color=this.GroupNameColor;
381
+
382
+ if (cell.Div.style.display=="none") cell.Div.style.display="";
383
+ }
384
+
385
+ for(; index<this.AryGroup.length; ++index)
386
+ {
387
+ var cell=this.AryGroup[index];
388
+ cell.Div.style.display="none";
389
+ }
390
+ }
391
+
392
+ this.UpdateTableData=function(data)
393
+ {
394
+ var rowIndex=0;
395
+ for(var j=0, index=0;rowIndex<this.AryData.length && index<data.AryIndex.length ;++rowIndex)
396
+ {
397
+ var row=this.AryData[rowIndex];
398
+ var cellCount=0;
399
+ for(j=0;j<row.AryCell.length;++j)
400
+ {
401
+ var cell=row.AryCell[j];
402
+ if (index<data.AryIndex.length)
403
+ {
404
+ var indexItem=data.AryIndex[index];
405
+ cell.Span.innerText=indexItem.Name;
406
+ cell.Span.style.color=this.IndexNameColor;
407
+ if (cell.Td.style.display=="none") cell.Td.style.display="";
408
+ cell.IndexItem=indexItem;
409
+ ++index;
410
+ ++cellCount;
411
+ }
412
+ else
413
+ {
414
+ cell.Td.style.display="none";
415
+ }
416
+ }
417
+
418
+ if (cellCount>0)
419
+ {
420
+ if (row.Tr.style.display=="none") row.Tr.style.display="";
421
+ }
422
+ else
423
+ {
424
+ row.Tr.style.display=="none";
425
+ }
426
+ }
427
+
428
+ for(; rowIndex<this.AryData.length; ++rowIndex)
429
+ {
430
+ var row=this.AryData[rowIndex];
431
+ row.Tr.style.display="none";
432
+ }
433
+ }
434
+
435
+ //搜索
436
+ this.OnInputSearch=function(e)
437
+ {
438
+ var strSearh=e.target.value;
439
+ var aryIndex=[];
440
+
441
+ var aryData=this.SeachIndex(strSearh);
442
+ var setIndex=new Set();
443
+ for(var i=0;i<aryData.length;++i)
444
+ {
445
+ var item=aryData[i];
446
+ var key=`${item.ID}-${item.Type}`;
447
+ setIndex.add(key);
448
+ aryIndex.push(item);
449
+ }
450
+
451
+ //内置指标
452
+ var scriptData = new JSIndexScript();
453
+ var result=scriptData.Search(strSearh);
454
+ if (IFrameSplitOperator.IsNonEmptyArray(result))
455
+ {
456
+ for(var i=0;i<result.length;++i)
457
+ {
458
+ var id=result[i];
459
+ var key=`${id}-0`;
460
+ if (setIndex.has(key)) continue;
461
+
462
+ var item={Name:id, ID:id, Type:0 };
463
+ aryIndex.push(item);
464
+ }
465
+ }
466
+
467
+ this.UpdateTableData({ AryIndex:aryIndex })
468
+ }
469
+
470
+ this.SeachIndex=function(strSearch)
471
+ {
472
+ if (!this.IndexData || !IFrameSplitOperator.IsNonEmptyArray(this.IndexData.Data)) return [];
473
+
474
+ var aryData=[];
475
+ var upperSearch=strSearch.toUpperCase();
476
+ for(var i=0,j=0;i<this.IndexData.Data.length;++i)
477
+ {
478
+ var groupItem=this.IndexData.Data[i];
479
+ for(j=0;j<groupItem.AryIndex.length;++j)
480
+ {
481
+ var item=groupItem.AryIndex[j];
482
+ if (item.Name.indexOf(strSearch)>=0 || item.Name.indexOf(upperSearch)>=0)
483
+ {
484
+ aryData.push(item);
485
+ }
486
+ }
487
+ }
488
+
489
+ return aryData;
490
+ }
491
+
492
+ //配色修改
493
+ this.ReloadResource=function(option)
494
+ {
495
+ this.TitleColor=g_JSChartResource.DialogSearchIndex.TitleColor;
496
+ this.TitleBGColor=g_JSChartResource.DialogSearchIndex.TitleBGColor;
497
+ this.BGColor=g_JSChartResource.DialogSearchIndex.BGColor;
498
+ this.BorderColor=g_JSChartResource.DialogSearchIndex.BorderColor;
499
+ this.IndexNameColor=g_JSChartResource.DialogSearchIndex.IndexNameColor;
500
+ this.GroupNameColor=g_JSChartResource.DialogSearchIndex.GroupNameColor;
501
+ this.InputTextColor=g_JSChartResource.DialogSearchIndex.InputTextColor;
502
+
503
+ if (!this.DivDialog) return;
504
+
505
+ this.UpdateStyle();
506
+ }
507
+
508
+ }
509
+
510
+
511
+ JSDialogSearchIndex.GetDefaultIndexData=function()
512
+ {
513
+ var data=
514
+ {
515
+ Name:"内置指标分类",
516
+ Data:
517
+ [
518
+ {
519
+ Group:{ ID:"超买超卖型", Name:"超买超卖型"} ,
520
+ AryIndex:
521
+ [
522
+ {Name:"ADTM 动态买卖气指标", ID:"ADTM", Type:0 }, //Type:0=系统指标 1=自定义通达信脚本 2=api指标
523
+ {Name:"BIAS 乖离率", ID:"BIAS", Type:0},
524
+ {Name:"BIAS36 三六乖离", ID:"BIAS36", Type:0 },
525
+ {Name:"BIAS_QL 乖离率-传统版", ID:"BIAS_QL", Type:0 },
526
+ {Name:"CCI 商品路径指标",ID:"CCI", Type:0 },
527
+ {Name:"FSL 分水岭",ID:"FSL", Type:0},
528
+ {Name:"KDJ 随机指标",ID:"KDJ", Type:0},
529
+ {Name:"MTM 动量线", ID:"MTM", Type:0},
530
+ {Name:"OSC 变动速率线", ID:"OSC", Type:0},
531
+ {Name:"RSI 相对强弱指标", ID:"RSI", Type:0},
532
+ {Name:"ROC 变动率指标", ID:"ROC", Type:0},
533
+ {Name:"WR 威廉指标", ID:"WR", Type:0}
534
+ ]
535
+ },
536
+
537
+ {
538
+ Group:{ ID:"趋势型", Name:"趋势型"},
539
+ AryIndex:
540
+ [
541
+ {Name:"CHO 济坚指数", ID:"CHO", Type:0 },
542
+ {Name:"DMA 平均差", ID:"DMA", Type:0 },
543
+ {Name:"DMI 趋向指标", ID:"DMI", Type:0 },
544
+ {Name:"EMV 简易波动指标", ID:"EMV", Type:0 },
545
+ {Name:"MACD 平滑异同平均", ID:"MACD", Type:0 },
546
+ {Name:"TRIX 三重指数平均线", ID:"TRIX", Type:0 },
547
+ {Name:"UOS 终极指标", ID:"UOS", Type:0 },
548
+ {Name:"TRIX 三重指数平均线", ID:"TRIX", Type:0 }
549
+ ]
550
+ },
551
+
552
+ {
553
+ Group:{ ID:"成交量型", Name:"成交量型"},
554
+ AryIndex:
555
+ [
556
+ {Name:"HSL 换手率", ID:"HSL", Type:0},
557
+ {Name:"OBV 累积能量线", ID:"OBV", Type:0},
558
+ {Name:"NVI 负成交量", ID:"NVI", Type:0},
559
+ {Name:"PVI 正成交量", ID:"PVI", Type:0},
560
+ {Name:"VOL 成交量", ID:"VOL", Type:0}
561
+ ]
562
+ },
563
+ {
564
+ Group:{ ID:"均线型", Name:"均线型"} ,
565
+ AryIndex:
566
+ [
567
+ {Name:"MA 均线", ID:"MA", Type:0},
568
+ {Name:"BBI 多空线", ID:"BBI", Type:0}
569
+ ]
570
+ },
571
+ {
572
+ Group:{ ID:"路径型", Name:"路径型"} ,
573
+ AryIndex:
574
+ [
575
+ {Name:"BOLL 布林线", ID:"BOLL", Type:0},
576
+ {Name:"BOLL副图 布林线", ID:"BOLL副图", Type:0},
577
+ {Name:"MIKE 麦克支撑压力", ID:"MIKE", Type:0},
578
+ {Name:"ENE 轨道线", ID:"ENE", Type:0}
579
+ ]
580
+ },
581
+ {
582
+ Group:{ ID:"能量型", Name:"能量型"} ,
583
+ AryIndex:
584
+ [
585
+ {Name:"BRAR 情绪指标", ID:"BRAR", Type:0},
586
+ {Name:"CYR 市场强弱", ID:"CYR", Type:0},
587
+ {Name:"MASS 梅斯线", ID:"MASS", Type:0},
588
+ {Name:"PSY 心理线", ID:"PSY", Type:0},
589
+ {Name:"CR 带状能量线", ID:"CR", Type:0},
590
+ {Name:"VR 成交量变异率", ID:"VR", Type:0},
591
+ {Name:"WAD 威廉多空力度线", ID:"WAD", Type:0}
592
+ ]
593
+ }
594
+ ]
595
+
596
+ }
597
+
598
+ return data;
599
+ }
600
+
601
+
602
+
603
+