hqchart 1.1.13909 → 1.1.13911

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.13909",
3
+ "version": "1.1.13911",
4
4
  "description": "HQChart - H5, 微信小程序 沪深/港股/数字货币/期货/美股 K线图(kline),走势图,缩放,拖拽,十字光标,画图工具,截图,筹码图. 分析家语法,通达信语法,(麦语法),第3方数据对接",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -0,0 +1,422 @@
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
+ 内置K线提示信息
11
+ */
12
+
13
+
14
+ function JSDialogTooltip()
15
+ {
16
+ this.DivDialog=null;
17
+ this.DragTitle=null;
18
+ this.TitleBox=null; //{ DivTitle, DivName, DivName }
19
+
20
+ this.HQChart=null;
21
+
22
+ this.UpColor=g_JSChartResource.UpTextColor;
23
+ this.DownColor=g_JSChartResource.DownTextColor;
24
+ this.UnchangeColor=g_JSChartResource.UnchagneTextColor;
25
+
26
+ this.TitleColor=g_JSChartResource.DialogTooltip.TitleColor;
27
+ this.TitleBGColor=g_JSChartResource.DialogTooltip.TitleBGColor;
28
+ this.BGColor=g_JSChartResource.DialogTooltip.BGColor;
29
+ this.BorderColor=g_JSChartResource.DialogTooltip.BorderColor;
30
+
31
+ this.VolColor=g_JSChartResource.DialogTooltip.VolColor;
32
+ this.AmountColor=g_JSChartResource.DialogTooltip.AmountColor;
33
+ this.TurnoverRateColor=g_JSChartResource.DialogTooltip.TurnoverRateColor;
34
+ this.PositionColor=g_JSChartResource.DialogTooltip.PositionColor;
35
+ this.DateTimeColor=g_JSChartResource.DialogTooltip.DateTimeColor;
36
+ this.LanguageID=JSCHART_LANGUAGE_ID.LANGUAGE_CHINESE_ID;
37
+ this.MaxRowCount=10;
38
+
39
+ this.AryData=[];
40
+ this.AryText=[];
41
+
42
+ this.KItemCache=null;
43
+ this.KItemCacheID=null;
44
+
45
+ this.Inital=function(hqchart)
46
+ {
47
+ this.HQChart=hqchart;
48
+ }
49
+
50
+ this.Destroy=function()
51
+ {
52
+ this.AryData=[];
53
+ this.AryText=[];
54
+ this.KItemCache=null;
55
+ this.KItemCacheID=null;
56
+
57
+ if (this.DivDialog)
58
+ {
59
+ document.body.removeChild(this.DivDialog);
60
+ this.DivDialog=null;
61
+ }
62
+ }
63
+
64
+ this.OnClickColseButton=function(e)
65
+ {
66
+ this.Close(e);
67
+
68
+ if (this.HQChart && this.HQChart.ChartCorssCursor)
69
+ {
70
+ var chart=this.HQChart.ChartCorssCursor;
71
+ if (!chart.IsShowCorss) return;
72
+
73
+ chart.IsShowCorss=false;
74
+ this.HQChart.Draw();
75
+ this.HQChart.SetFocus();
76
+ }
77
+ }
78
+
79
+ this.Create=function()
80
+ {
81
+ var divDom=document.createElement("div");
82
+ divDom.className='UMyChart_Tooltip_Dialog_Div';
83
+
84
+ var divTitle=document.createElement("div");
85
+ divTitle.className='UMyChart_Tooltip_Title_Div';
86
+ divTitle.onmousedown=(e)=>{ this.OnMouseDownTitle(e);}
87
+
88
+ var divName=document.createElement("div");
89
+ divName.className='UMyChart_Tooltip_Name_Div';
90
+ divName.innerText="----";
91
+ divTitle.appendChild(divName);
92
+
93
+ var divClose=document.createElement("div");
94
+ divClose.className='UMyChart_Tooltip_Close_Div';
95
+ divClose.innerText="x";
96
+ divClose.onmousedown=(e)=>{ this.OnClickColseButton(e); }
97
+ divTitle.appendChild(divClose);
98
+
99
+ divDom.appendChild(divTitle);
100
+
101
+ var table=document.createElement("table");
102
+ table.className="UMyChart_Tooltip_Table";
103
+ divDom.appendChild(table);
104
+
105
+ var tbody=document.createElement("tbody");
106
+ tbody.className="UMyChart_Tooltip_Tbody";
107
+ table.appendChild(tbody);
108
+
109
+ this.AryData=[];
110
+ for(var i=0;i<this.MaxRowCount;++i)
111
+ {
112
+ var rowItem={ Tr:null, TitleSpan:null, TextSpan:null };
113
+
114
+ var trDom=document.createElement("tr");
115
+ trDom.className='UMyChart_Tooltip_Group_Tr';
116
+ tbody.appendChild(trDom);
117
+ rowItem.Tr=trDom;
118
+
119
+ var tdDom=document.createElement("td");
120
+ tdDom.className="UMyChart_Tooltip_Title_Td"; //标题
121
+ trDom.appendChild(tdDom);
122
+
123
+ var spanDom=document.createElement("span");
124
+ spanDom.className='UMyChart_Tooltip_Title_Span';
125
+ spanDom.innerText='标题';
126
+ tdDom.appendChild(spanDom);
127
+ rowItem.TitleSpan=spanDom;
128
+
129
+ var tdDom=document.createElement("td");
130
+ tdDom.className="UMyChart_Tooltip_Text_Td"; //数值
131
+ trDom.appendChild(tdDom);
132
+
133
+ var spanDom=document.createElement("span");
134
+ spanDom.className='UMyChart_Tooltip_Text_Span';
135
+ spanDom.innerText='数值';
136
+ tdDom.appendChild(spanDom);
137
+ rowItem.TextSpan=spanDom;
138
+
139
+ this.AryData.push(rowItem);
140
+ }
141
+
142
+
143
+ document.body.appendChild(divDom);
144
+
145
+ this.DivName=divName;
146
+ this.DivDialog=divDom;
147
+ this.TitleBox={ DivTitle:divTitle, DivName:divName, DivColor:divClose };
148
+
149
+ this.UpdateStyle();
150
+ }
151
+
152
+ this.Update=function(data)
153
+ {
154
+ if (!this.DivDialog || !this.TitleBox) return;
155
+ if (!data.KItem || !data.IsShowCorss || data.ClientPos<0) return;
156
+
157
+ this.LanguageID=this.HQChart.LanguageID;
158
+ this.TitleBox.DivName.innerText=data.Name;
159
+
160
+ var strKItem=JSON.stringify(data.KItem);
161
+ if (this.KItemCacheID!=strKItem) //数据变动的才更新
162
+ {
163
+ this.KItemCache= JSON.parse(strKItem);
164
+ this.KItemCacheID=strKItem;
165
+ this.UpdateTableDOM();
166
+ }
167
+ else
168
+ {
169
+ //JSConsole.Chart.Log(`[JSDialogTooltip::Update] save as KItemCache and KItem`);
170
+ }
171
+
172
+ if (!this.IsShow()) this.Show();
173
+ }
174
+
175
+ this.UpdateTableDOM=function()
176
+ {
177
+ if (!this.KItemCache) return;
178
+
179
+ this.AryText=this.GetFormatKlineTooltipText(this.KItemCache);
180
+
181
+ var index=0;
182
+ for(index=0;index<this.AryText.length && index<this.MaxRowCount;++index)
183
+ {
184
+ var outItem=this.AryText[index];
185
+ var item=this.AryData[index];
186
+
187
+ item.TitleSpan.innerText=outItem.Title;
188
+ item.TitleSpan.style.color=this.TitleColor;
189
+ item.TextSpan.innerText=outItem.Text;
190
+ item.TextSpan.style.color=outItem.Color;
191
+ item.Tr.style.display="";
192
+ }
193
+
194
+ for( ; index<this.MaxRowCount; ++index)
195
+ {
196
+ var item=this.AryData[index];
197
+ item.Tr.style.display="none";
198
+ }
199
+ }
200
+
201
+ this.Close=function(e)
202
+ {
203
+ if (!this.DivDialog) return;
204
+
205
+ this.DivDialog.style.visibility='hidden';
206
+ }
207
+
208
+ this.OnMouseDownTitle=function(e)
209
+ {
210
+ if (!this.DivDialog) return;
211
+
212
+ var dragData={ X:e.clientX, Y:e.clientY };
213
+ dragData.YOffset=e.clientX - this.DivDialog.offsetLeft;
214
+ dragData.XOffset=e.clientY - this.DivDialog.offsetTop;
215
+ this.DragTitle=dragData;
216
+
217
+ document.onmousemove=(e)=>{ this.DocOnMouseMoveTitle(e); }
218
+ document.onmouseup=(e)=>{ this.DocOnMouseUpTitle(e); }
219
+ }
220
+
221
+ this.DocOnMouseMoveTitle=function(e)
222
+ {
223
+ if (!this.DragTitle) return;
224
+
225
+ var left = e.clientX - this.DragTitle.YOffset;
226
+ var top = e.clientY - this.DragTitle.XOffset;
227
+
228
+ var right=left+this.DivDialog.offsetWidth;
229
+ var bottom=top+ this.DivDialog.offsetHeight;
230
+
231
+ if ((right+5)>=window.innerWidth) left=window.innerWidth-this.DivDialog.offsetWidth-5;
232
+ if ((bottom+5)>=window.innerHeight) top=window.innerHeight-this.DivDialog.offsetHeight-5;
233
+
234
+ this.DivDialog.style.left = left + 'px';
235
+ this.DivDialog.style.top = top + 'px';
236
+
237
+ if(e.preventDefault) e.preventDefault();
238
+ }
239
+
240
+ this.DocOnMouseUpTitle=function(e)
241
+ {
242
+ this.DragTitle=null;
243
+ this.onmousemove = null;
244
+ this.onmouseup = null;
245
+ }
246
+
247
+ this.Show=function()
248
+ {
249
+ if (!this.DivDialog) return;
250
+ if (!this.HQChart) return;
251
+
252
+ if (!this.DivDialog.style.top || !this.DivDialog.style.left) //上一次显示的位置
253
+ {
254
+ var top=this.HQChart.Frame.ChartBorder.GetTop();
255
+ var left=this.HQChart.Frame.ChartBorder.GetLeft();
256
+ var rtClient=this.HQChart.UIElement.getBoundingClientRect();
257
+
258
+ var x=left+rtClient.left+5;
259
+ var y=top+rtClient.top+10;
260
+ this.DivDialog.style.top = y + "px";
261
+ this.DivDialog.style.left = x + "px";
262
+ }
263
+
264
+ this.DivDialog.style.visibility='visible';
265
+ }
266
+
267
+ this.IsShow=function()
268
+ {
269
+ if (!this.DivDialog) return false;
270
+
271
+ return this.DivDialog.style.visibility==='visible';
272
+ }
273
+
274
+
275
+ this.GetFormatKlineTooltipText=function(data)
276
+ {
277
+ var defaultfloatPrecision=GetfloatPrecision(this.HQChart.Symbol);//价格小数位数
278
+
279
+ //日期
280
+ var dateItem=
281
+ {
282
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Date',this.LanguageID),
283
+ Text:IFrameSplitOperator.FormatDateString(data.Date,"YYYY/MM/DD/W"),
284
+ Color:this.DateTimeColor
285
+ }
286
+
287
+ //时间
288
+ var timeItem=null;
289
+ var timeFormat=null;
290
+ if (ChartData.IsMinutePeriod(this.HQChart.Period,true)) timeFormat='HH:MM'; // 分钟周期
291
+ else if (ChartData.IsSecondPeriod(this.HQChart.Period)) timeFormat='HH:MM:SS';
292
+ else if (ChartData.IsMilliSecondPeriod(this.HQChart.Period)) timeFormat='HH:MM:SS.fff';
293
+
294
+ if (timeFormat)
295
+ {
296
+ timeItem=
297
+ {
298
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Time',this.LanguageID),
299
+ Text:IFrameSplitOperator.FormatTimeString(data.Time,timeFormat),
300
+ Color:this.DateTimeColor
301
+ }
302
+ }
303
+
304
+ //涨幅
305
+ var increaseItem=
306
+ {
307
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Increase',this.LanguageID),
308
+ Text:"--.--",
309
+ Color:this.TitleColor
310
+ };
311
+ if (IFrameSplitOperator.IsNumber(data.YClose) && IFrameSplitOperator.IsNumber(data.Close))
312
+ {
313
+ var value=(data.Close-data.YClose)/data.YClose;
314
+ increaseItem.Text=`${(value*100).toFixed(2)}%`;
315
+ increaseItem.Color=this.GetColor(value,0);
316
+ }
317
+
318
+ //涨幅
319
+ var amplitudeItem=
320
+ {
321
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Amplitude',this.LanguageID),
322
+ Text:"--.--",
323
+ Color:this.TitleColor
324
+ }
325
+ if (IFrameSplitOperator.IsNumber(data.YClose) && IFrameSplitOperator.IsNumber(data.High) && IFrameSplitOperator.IsNumber(data.Low))
326
+ {
327
+ var value=(data.High-data.Low)/data.YClose;
328
+ amplitudeItem.Text=`${(value*100).toFixed(2)}%`;
329
+ amplitudeItem.Color=this.GetColor(value,0);
330
+ }
331
+
332
+ var aryText=
333
+ [
334
+ {
335
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Open',this.LanguageID),
336
+ Text:IFrameSplitOperator.IsNumber(data.Open)? data.Open.toFixed(defaultfloatPrecision):'--',
337
+ Color:this.GetPriceColor(data.Open,data.YClose),
338
+ },
339
+ {
340
+ Title:g_JSChartLocalization.GetText('DialogTooltip-High',this.LanguageID),
341
+ Text:IFrameSplitOperator.IsNumber(data.High)? data.High.toFixed(defaultfloatPrecision):'--',
342
+ Color:this.GetPriceColor(data.High,data.YClose)
343
+ },
344
+ {
345
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Low',this.LanguageID),
346
+ Text:IFrameSplitOperator.IsNumber(data.Low)? data.Low.toFixed(defaultfloatPrecision):'--',
347
+ Color:this.GetPriceColor(data.Low,data.YClose)
348
+ },
349
+ {
350
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Close',this.LanguageID),
351
+ Text:IFrameSplitOperator.IsNumber(data.Close)? data.Close.toFixed(defaultfloatPrecision):'--',
352
+ Color:this.GetPriceColor(data.Close,data.YClose)
353
+ },
354
+ {
355
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Vol',this.LanguageID),
356
+ Text:IFrameSplitOperator.IsNumber(data.Vol)? IFrameSplitOperator.FormatValueString(data.Vol,2,this.LanguageID):'--',
357
+ Color:this.VolColor
358
+ },
359
+ {
360
+ Title:g_JSChartLocalization.GetText('DialogTooltip-Amount',this.LanguageID),
361
+ Text:IFrameSplitOperator.IsNumber(data.Amount)? IFrameSplitOperator.FormatValueString(data.Amount,2,this.LanguageID):'--',
362
+ Color:this.AmountColor
363
+ },
364
+ increaseItem,
365
+ amplitudeItem
366
+ ];
367
+
368
+ if (timeItem) aryText.unshift(timeItem);
369
+ aryText.unshift(dateItem);
370
+
371
+ return aryText;
372
+ },
373
+
374
+ this.GetColor=function(price,yClose)
375
+ {
376
+ if(price>yClose) return this.UpColor;
377
+ else if (price<yClose) return this.DownColor;
378
+ else return this.UnchangeColor;
379
+ }
380
+
381
+ this.GetPriceColor=function(price, yClose)
382
+ {
383
+ var color=this.GetColor(price, yClose);
384
+ return color;
385
+ }
386
+
387
+ //配色修改
388
+ this.ReloadResource=function(option)
389
+ {
390
+ this.UpColor=g_JSChartResource.UpTextColor;
391
+ this.DownColor=g_JSChartResource.DownTextColor;
392
+ this.UnchangeColor=g_JSChartResource.UnchagneTextColor;
393
+
394
+ this.TitleColor=g_JSChartResource.DialogTooltip.TitleColor;
395
+ this.TitleBGColor=g_JSChartResource.DialogTooltip.TitleBGColor;
396
+ this.BGColor=g_JSChartResource.DialogTooltip.BGColor;
397
+ this.BorderColor=g_JSChartResource.DialogTooltip.BorderColor;
398
+
399
+ this.VolColor=g_JSChartResource.DialogTooltip.VolColor;
400
+ this.AmountColor=g_JSChartResource.DialogTooltip.AmountColor;
401
+ this.TurnoverRateColor=g_JSChartResource.DialogTooltip.TurnoverRateColor;
402
+ this.PositionColor=g_JSChartResource.DialogTooltip.PositionColor;
403
+ this.DateTimeColor=g_JSChartResource.DialogTooltip.DateTimeColor;
404
+
405
+ if (!this.DivDialog) return;
406
+
407
+ this.UpdateStyle();
408
+ }
409
+
410
+ this.UpdateStyle=function()
411
+ {
412
+ if (!this.DivDialog) return;
413
+
414
+ if (this.BGColor) this.DivDialog.style['background-color']=this.BGColor;
415
+ if (this.BorderColor) this.DivDialog.style['border-color']=this.BorderColor;
416
+
417
+ if (this.TitleBGColor) this.TitleBox.DivTitle.style['background-color']=this.TitleBGColor;
418
+
419
+ this.UpdateTableDOM();
420
+ }
421
+
422
+ }