hqchart 1.1.12733 → 1.1.12734

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.
@@ -0,0 +1,1659 @@
1
+ /*
2
+ Copyright (c) 2018 jones
3
+
4
+ http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ 开源项目 https://github.com/jones2000/HQChart
7
+
8
+ jones_2000@163.com
9
+
10
+ 封装键盘精灵控件 (页面版 不支持手机)
11
+ */
12
+
13
+
14
+
15
+ function JSKeyboardChart(divElement)
16
+ {
17
+ this.DivElement=divElement;
18
+ this.JSChartContainer; //表格控件
19
+
20
+ //h5 canvas
21
+ this.CanvasElement=document.createElement("canvas");
22
+ this.CanvasElement.className='jskeyboard-drawing';
23
+ this.CanvasElement.id=Guid();
24
+ this.CanvasElement.setAttribute("tabindex",0);
25
+ if (this.CanvasElement.style) this.CanvasElement.style.outline='none';
26
+ if(divElement.hasChildNodes())
27
+ {
28
+ JSConsole.Chart.Log("[JSKeyboardChart::JSRepoJSKeyboardChartrtChart] divElement hasChildNodes", divElement.childNodes);
29
+ }
30
+ divElement.appendChild(this.CanvasElement);
31
+
32
+
33
+ this.OnSize=function()
34
+ {
35
+ //画布大小通过div获取
36
+ var height=parseInt(this.DivElement.style.height.replace("px",""));
37
+ this.CanvasElement.height=height;
38
+ this.CanvasElement.width=parseInt(this.DivElement.style.width.replace("px",""));
39
+ this.CanvasElement.style.width=this.CanvasElement.width+'px';
40
+ this.CanvasElement.style.height=this.CanvasElement.height+'px';
41
+
42
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
43
+ this.CanvasElement.height*=pixelTatio;
44
+ this.CanvasElement.width*=pixelTatio;
45
+
46
+ JSConsole.Chart.Log(`[JSKeyboardChart::OnSize] devicePixelRatio=${window.devicePixelRatio}, height=${this.CanvasElement.height}, width=${this.CanvasElement.width}`);
47
+
48
+ if (this.JSChartContainer && this.JSChartContainer.OnSize)
49
+ {
50
+ this.JSChartContainer.OnSize();
51
+ }
52
+ }
53
+
54
+ this.SetOption=function(option)
55
+ {
56
+ var chart=this.CreateJSKeyboardChartContainer(option);
57
+
58
+ if (!chart) return false;
59
+
60
+ if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
61
+
62
+ this.JSChartContainer=chart;
63
+ this.DivElement.JSChart=this; //div中保存一份
64
+
65
+ chart.Draw();
66
+ }
67
+
68
+ this.CreateJSKeyboardChartContainer=function(option)
69
+ {
70
+ var chart=new JSKeyboardChartContainer(this.CanvasElement);
71
+ chart.Create(option);
72
+
73
+ if (option.NetworkFilter) chart.NetworkFilter=option.NetworkFilter;
74
+ if (IFrameSplitOperator.IsNonEmptyArray(option.Column)) chart.SetColumn(option.Column);
75
+ if (IFrameSplitOperator.IsNumber(option.BorderLine)) chart.Frame.BorderLine=option.BorderLine;
76
+
77
+ this.SetChartBorder(chart, option);
78
+
79
+ //注册事件
80
+ if (option.EventCallback)
81
+ {
82
+ for(var i=0;i<option.EventCallback.length;++i)
83
+ {
84
+ var item=option.EventCallback[i];
85
+ chart.AddEventCallback(item);
86
+ }
87
+ }
88
+
89
+ return chart;
90
+ }
91
+
92
+ this.SetChartBorder=function(chart, option)
93
+ {
94
+ if (!option.Border) return;
95
+
96
+ var item=option.Border;
97
+ if (IFrameSplitOperator.IsNumber(option.Border.Left)) chart.Frame.ChartBorder.Left=option.Border.Left;
98
+ if (IFrameSplitOperator.IsNumber(option.Border.Right)) chart.Frame.ChartBorder.Right=option.Border.Right;
99
+ if (IFrameSplitOperator.IsNumber(option.Border.Top)) chart.Frame.ChartBorder.Top=option.Border.Top;
100
+ if (IFrameSplitOperator.IsNumber(option.Border.Bottom)) chart.Frame.ChartBorder.Bottom=option.Border.Bottom;
101
+
102
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
103
+ chart.Frame.ChartBorder.Left*=pixelTatio;
104
+ chart.Frame.ChartBorder.Right*=pixelTatio;
105
+ chart.Frame.ChartBorder.Top*=pixelTatio;
106
+ chart.Frame.ChartBorder.Bottom*=pixelTatio;
107
+ }
108
+
109
+ /////////////////////////////////////////////////////////////////////////////
110
+ //对外接口
111
+ this.SetColumn=function(aryColumn, option)
112
+ {
113
+ if (this.JSChartContainer) this.JSChartContainer.SetColumn(aryColumn,option);
114
+ }
115
+
116
+ //事件回调
117
+ this.AddEventCallback=function(obj)
118
+ {
119
+ if(this.JSChartContainer && typeof(this.JSChartContainer.AddEventCallback)=='function')
120
+ {
121
+ JSConsole.Chart.Log('[JSKeyboardChart:AddEventCallback] obj=', obj);
122
+ this.JSChartContainer.AddEventCallback(obj);
123
+ }
124
+ }
125
+
126
+ //重新加载配置
127
+ this.ReloadResource=function(option)
128
+ {
129
+ if(this.JSChartContainer && typeof(this.JSChartContainer.ReloadResource)=='function')
130
+ {
131
+ JSConsole.Chart.Log('[JSKeyboardChart:ReloadResource] ');
132
+ this.JSChartContainer.ReloadResource(option);
133
+ }
134
+ }
135
+
136
+ this.ChartDestory=function()
137
+ {
138
+ if (this.JSChartContainer && typeof (this.JSChartContainer.ChartDestory) == 'function')
139
+ {
140
+ this.JSChartContainer.ChartDestory();
141
+ }
142
+ }
143
+
144
+ this.Draw=function()
145
+ {
146
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Draw)=='function')
147
+ {
148
+ JSConsole.Chart.Log('[JSKeyboardChart:Draw] ');
149
+ this.JSChartContainer.Draw();
150
+ }
151
+ }
152
+
153
+ this.SetSymbolData=function(arySymbol)
154
+ {
155
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Draw)=='function')
156
+ {
157
+ JSConsole.Chart.Log('[JSKeyboardChart:SetSymbolData] ', arySymbol);
158
+ this.JSChartContainer.SetSymbolData(arySymbol);
159
+ }
160
+ }
161
+
162
+ this.Search=function(strText)
163
+ {
164
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Search)=='function')
165
+ {
166
+ JSConsole.Chart.Log('[JSKeyboardChart:Search] ', strText);
167
+ this.JSChartContainer.Search(strText);
168
+ }
169
+ }
170
+
171
+ this.OnKeyDown=function(event)
172
+ {
173
+ if(this.JSChartContainer && typeof(this.JSChartContainer.OnKeyDown)=='function')
174
+ {
175
+ JSConsole.Chart.Log('[JSKeyboardChart:OnKeyDown] ', event);
176
+ this.JSChartContainer.OnKeyDown(event);
177
+ }
178
+ }
179
+
180
+ this.ClearSearch=function(option)
181
+ {
182
+ if(this.JSChartContainer && typeof(this.JSChartContainer.ClearSearch)=='function')
183
+ {
184
+ JSConsole.Chart.Log('[JSKeyboardChart:ClearSearch] ', option);
185
+ this.JSChartContainer.ClearSearch(option);
186
+ }
187
+ }
188
+ }
189
+
190
+ JSKeyboardChart.Init=function(divElement)
191
+ {
192
+ var jsChartControl=new JSKeyboardChart(divElement);
193
+ jsChartControl.OnSize();
194
+
195
+ return jsChartControl;
196
+ }
197
+
198
+ //自定义风格
199
+ JSKeyboardChart.SetStyle=function(option)
200
+ {
201
+ if (option) g_JSChartResource.SetStyle(option);
202
+ }
203
+
204
+
205
+ function JSKeyboardChartContainer(uielement)
206
+ {
207
+ this.ClassName='JSKeyboardChartContainer';
208
+ this.Frame; //框架画法
209
+ this.ChartPaint=[]; //图形画法
210
+ this.Canvas=uielement.getContext("2d"); //画布
211
+ this.ShowCanvas=null;
212
+
213
+ this.NetworkFilter; //数据回调接口
214
+ this.Data={ XOffset:0, YOffset:0, Data:[] }; //股票列表
215
+ this.MapSymbol=new Map();
216
+ this.SourceData={ Data:[] } //码表数据 Data:[ { Symbol:, Spell, Name:, Color:}]
217
+
218
+ //事件回调
219
+ this.mapEvent=new Map(); //通知外部调用 key:JSCHART_EVENT_ID value:{Callback:回调,}
220
+
221
+ this.UIElement=uielement;
222
+ this.LastPoint=new Point(); //鼠标位置
223
+
224
+ //拖拽滚动条
225
+ this.DragYScroll=null; //{Start:{x,y}, End:{x, y}}
226
+ this.IsDestroy=false; //是否已经销毁了
227
+
228
+ this.ChartDestory=function() //销毁
229
+ {
230
+ this.IsDestroy=true;
231
+ }
232
+
233
+ this.ClearSearch=function(option)
234
+ {
235
+ this.Data.Data=[];
236
+ this.Data.XOffset=0;
237
+ this.Data.YOffset=0;
238
+
239
+ if (option && option.Redraw==true) this.Draw();
240
+ }
241
+
242
+ this.Search=function(strText)
243
+ {
244
+ var aryExactQuery=[]; //精确查询
245
+ var aryFuzzyQuery=[]; //模糊查询
246
+ this.MapSymbol.clear();
247
+ this.Data.Data=[];
248
+ this.Data.XOffset=0;
249
+ this.Data.YOffset=0;
250
+
251
+ var strSearch=strText.trim();
252
+ if (strSearch.length>0)
253
+ {
254
+ for(var i=0;i<this.SourceData.Data.length;++i)
255
+ {
256
+ var item=this.SourceData.Data[i];
257
+ if (this.SearchSymbol(item, strSearch, aryExactQuery, aryFuzzyQuery)) continue;
258
+ else if (this.SearchSpell(item, strSearch, aryExactQuery, aryFuzzyQuery)) continue;
259
+ }
260
+ }
261
+
262
+ if (IFrameSplitOperator.IsNonEmptyArray(aryExactQuery) || IFrameSplitOperator.IsNonEmptyArray(aryFuzzyQuery))
263
+ this.Data.Data=aryExactQuery.concat(aryFuzzyQuery);
264
+
265
+ this.ChartPaint[0].SelectedRow=0;
266
+
267
+ JSConsole.Chart.Log(`[JSKeyboardChart:Search] search=${strSearch}, source=${this.SourceData.Data.length} match=${this.Data.Data.length}`);
268
+
269
+ this.Draw();
270
+ }
271
+
272
+ this.SearchSymbol=function(item, strText, aryExactQuery, aryFuzzyQuery)
273
+ {
274
+ var find=item.Symbol.indexOf(strText);
275
+ if (find<0) return false;
276
+
277
+ if (find==0) aryExactQuery.push(item.Symbol);
278
+ else aryFuzzyQuery.push(item.Symbol);
279
+
280
+ this.MapSymbol.set(item.Symbol, item);
281
+
282
+ return true;
283
+ }
284
+
285
+ this.SearchSpell=function(item, strText, aryExactQuery, aryFuzzyQuery)
286
+ {
287
+ if (!IFrameSplitOperator.IsString(item.Spell)) return false;
288
+
289
+ var find=item.Spell.indexOf(strText);
290
+
291
+ if (find!=0) return false;
292
+
293
+ aryExactQuery.push(item.Symbol);
294
+ this.MapSymbol.set(item.Symbol, item);
295
+
296
+ return true;
297
+ }
298
+
299
+
300
+ this.SetSymbolData=function(arySymbol)
301
+ {
302
+ this.SourceData.Data=arySymbol;
303
+
304
+ /*
305
+ //测试
306
+ this.MapSymbol.clear();
307
+ for(var i=0;i<this.SourceData.Data.length && i<3050 ;++i)
308
+ {
309
+ var item=this.SourceData.Data[i];
310
+ this.Data.Data.push(item.Symbol);
311
+ this.MapSymbol.set(item.Symbol, item);
312
+ }
313
+ this.ChartPaint[0].SelectedRow=0;
314
+ */
315
+ }
316
+
317
+ //创建
318
+ this.Create=function(option)
319
+ {
320
+ this.UIElement.JSChartContainer=this;
321
+
322
+ //创建框架
323
+ this.Frame=new JSKeyboardFrame();
324
+ this.Frame.ChartBorder=new ChartBorder();
325
+ this.Frame.ChartBorder.UIElement=this.UIElement;
326
+ this.Frame.ChartBorder.Top=30;
327
+ this.Frame.ChartBorder.Left=5;
328
+ this.Frame.ChartBorder.Bottom=20;
329
+ this.Frame.Canvas=this.Canvas;
330
+
331
+ //创建表格
332
+ var chart=new ChartSymbolList();
333
+ chart.Frame=this.Frame;
334
+ chart.ChartBorder=this.Frame.ChartBorder;
335
+ chart.Canvas=this.Canvas;
336
+ chart.UIElement=this.UIElement;
337
+ chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
338
+ chart.GetStockDataCallback=(symbol)=>{ return this.GetStockData(symbol);}
339
+ chart.Data=this.Data;
340
+ this.ChartPaint[0]=chart;
341
+
342
+ if (option)
343
+ {
344
+
345
+ }
346
+
347
+ var bRegisterKeydown=true;
348
+ var bRegisterWheel=true;
349
+
350
+ if (option)
351
+ {
352
+ if (option.KeyDown===false)
353
+ {
354
+ bRegisterKeydown=false;
355
+ JSConsole.Chart.Log('[JSKeyboardChartContainer::Create] not register keydown event.');
356
+ }
357
+
358
+ if (option.Wheel===false)
359
+ {
360
+ bRegisterWheel=false;
361
+ JSConsole.Chart.Log('[JSKeyboardChartContainer::Create] not register wheel event.');
362
+ }
363
+ }
364
+
365
+ if (bRegisterKeydown) this.UIElement.addEventListener("keydown", (e)=>{ this.OnKeyDown(e); }, true); //键盘消息
366
+ if (bRegisterWheel) this.UIElement.addEventListener("wheel", (e)=>{ this.OnWheel(e); }, true); //上下滚动消息
367
+
368
+
369
+ this.UIElement.ondblclick=(e)=>{ this.UIOnDblClick(e); }
370
+ this.UIElement.onmousedown=(e)=> { this.UIOnMouseDown(e); }
371
+ this.UIElement.oncontextmenu=(e)=> { this.UIOnContextMenu(e); }
372
+ this.UIElement.onmousemove=(e)=>{ this.UIOnMouseMove(e);}
373
+ this.UIElement.onmouseout=(e)=>{ this.UIOnMounseOut(e); }
374
+ this.UIElement.onmouseleave=(e)=>{ this.UIOnMouseleave(e); }
375
+ }
376
+
377
+ this.Draw=function()
378
+ {
379
+ if (this.UIElement.width<=0 || this.UIElement.height<=0) return;
380
+
381
+ this.Canvas.clearRect(0,0,this.UIElement.width,this.UIElement.height);
382
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
383
+ this.Canvas.lineWidth=pixelTatio; //手机端需要根据分辨率比调整线段宽度
384
+
385
+ this.Frame.Draw();
386
+ this.Frame.DrawLogo();
387
+
388
+ //框架内图形
389
+ for(var i=0;i<this.ChartPaint.length;++i)
390
+ {
391
+ var item=this.ChartPaint[i];
392
+ if (item.IsDrawFirst)
393
+ item.Draw();
394
+ }
395
+
396
+ for(var i=0; i<this.ChartPaint.length; ++i)
397
+ {
398
+ var item=this.ChartPaint[i];
399
+ if (!item.IsDrawFirst)
400
+ item.Draw();
401
+ }
402
+ }
403
+
404
+ this.GetStockData=function(symbol)
405
+ {
406
+ if (!this.MapSymbol.has(symbol)) return null;
407
+
408
+ return this.MapSymbol.get(symbol);
409
+ }
410
+
411
+
412
+ this.ResetStatus=function()
413
+ {
414
+ this.Data.XOffset=0;
415
+ this.Data.YOffset=0;
416
+ }
417
+
418
+ this.ResetSelectStatus=function()
419
+ {
420
+ var chart=this.GetReportChart();
421
+ if (chart)
422
+ {
423
+ chart.SelectedRow=-1;
424
+ chart.SelectedFixedRow=-1;
425
+ }
426
+ }
427
+
428
+ //设置事件回调
429
+ //{event:事件id, callback:回调函数}
430
+ this.AddEventCallback=function(object)
431
+ {
432
+ if (!object || !object.event || !object.callback) return;
433
+
434
+ var data={Callback:object.callback, Source:object};
435
+ this.mapEvent.set(object.event,data);
436
+ }
437
+
438
+ this.RemoveEventCallback=function(eventid)
439
+ {
440
+ if (!this.mapEvent.has(eventid)) return;
441
+
442
+ this.mapEvent.delete(eventid);
443
+ }
444
+
445
+ this.GetEventCallback=function(id) //获取事件回调
446
+ {
447
+ if (!this.mapEvent.has(id)) return null;
448
+ var item=this.mapEvent.get(id);
449
+ return item;
450
+ }
451
+
452
+ this.OnSize=function()
453
+ {
454
+ if (!this.Frame) return;
455
+
456
+ this.SetSizeChange(true);
457
+ this.Draw();
458
+ }
459
+
460
+ this.SetSizeChange=function(bChanged)
461
+ {
462
+ for(var i=0;i<this.ChartPaint.length;++i)
463
+ {
464
+ var chart=this.ChartPaint[i];
465
+ if (chart) chart.SizeChange=bChanged;
466
+ }
467
+ }
468
+
469
+
470
+ this.OnWheel=function(e) //滚轴
471
+ {
472
+ JSConsole.Chart.Log('[JSKeyboardChartContainer::OnWheel]',e);
473
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
474
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
475
+
476
+ var x = e.clientX-this.UIElement.getBoundingClientRect().left;
477
+ var y = e.clientY-this.UIElement.getBoundingClientRect().top;
478
+
479
+ var isInClient=false;
480
+ this.Canvas.beginPath();
481
+ this.Canvas.rect(this.Frame.ChartBorder.GetLeft(),this.Frame.ChartBorder.GetTop(),this.Frame.ChartBorder.GetWidth(),this.Frame.ChartBorder.GetHeight());
482
+ isInClient=this.Canvas.isPointInPath(x,y);
483
+ if (!isInClient) return;
484
+
485
+ var chart=this.ChartPaint[0];
486
+ if (!chart) return;
487
+
488
+ var wheelValue=e.wheelDelta;
489
+ if (!IFrameSplitOperator.IsObjectExist(e.wheelDelta))
490
+ wheelValue=e.deltaY* -0.01;
491
+
492
+ if (wheelValue<0) //下一页
493
+ {
494
+ if (this.GotoNextPage(this.PageUpDownCycle))
495
+ {
496
+ this.Draw();
497
+ }
498
+ }
499
+ else if (wheelValue>0) //上一页
500
+ {
501
+ if (this.GotoPreviousPage(this.PageUpDownCycle))
502
+ {
503
+ this.Draw();
504
+ }
505
+ }
506
+
507
+ if(e.preventDefault) e.preventDefault();
508
+ else e.returnValue = false;
509
+ }
510
+
511
+ this.OnKeyDown=function(e)
512
+ {
513
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
514
+ var reportChart=this.GetReportChart();
515
+ if (!reportChart) return;
516
+
517
+ var keyID = e.keyCode ? e.keyCode :e.which;
518
+ switch(keyID)
519
+ {
520
+ case 33: //page up
521
+ if (this.GotoPreviousPage(this.PageUpDownCycle))
522
+ {
523
+ this.Draw();
524
+ }
525
+ break;
526
+ case 34: //page down
527
+ if (this.GotoNextPage(this.PageUpDownCycle))
528
+ {
529
+ this.Draw();
530
+ }
531
+ break;
532
+ case 38: //up
533
+ var result=this.MoveSelectedRow(-1);
534
+ if (result)
535
+ {
536
+ if (result.Redraw) this.Draw();
537
+ }
538
+ break;
539
+ case 40: //down
540
+ var result=this.MoveSelectedRow(1)
541
+ if (result)
542
+ {
543
+ if (result.Redraw) this.Draw();
544
+ }
545
+ break;
546
+ case 37: //left
547
+ if (this.MoveXOffset(-1)) this.Draw();
548
+ break
549
+ case 39: //right
550
+ if (this.MoveXOffset(1)) this.Draw();
551
+ break;
552
+ case 13: //Enter
553
+ this.OnSelectedSymbol();
554
+ break;
555
+ }
556
+
557
+ //不让滚动条滚动
558
+ if(e.preventDefault) e.preventDefault();
559
+ else e.returnValue = false;
560
+ }
561
+
562
+ this.OnSelectedSymbol=function()
563
+ {
564
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
565
+
566
+ var chart=this.ChartPaint[0];
567
+ if (!chart) return false;
568
+
569
+ var data=chart.GetSelectedSymbol();
570
+
571
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_KEYBOARD_SELECTED)
572
+ if (event && event.Callback)
573
+ {
574
+ event.Callback(event, { Data:data }, this);
575
+ }
576
+ }
577
+
578
+ this.UIOnDblClick=function(e)
579
+ {
580
+ var pixelTatio = GetDevicePixelRatio();
581
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
582
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
583
+
584
+ var chart=this.ChartPaint[0];
585
+ if (chart)
586
+ {
587
+ if (chart.OnDblClick(x,y,e)) this.OnSelectedSymbol();
588
+ }
589
+ }
590
+
591
+ this.UIOnMouseDown=function(e)
592
+ {
593
+ this.DragXScroll=null;
594
+ this.DragMove={ Click:{ X:e.clientX, Y:e.clientY }, Move:{X:e.clientX, Y:e.clientY}, PreMove:{X:e.clientX, Y:e.clientY } };
595
+
596
+ var pixelTatio = GetDevicePixelRatio();
597
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
598
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
599
+
600
+ var chart=this.ChartPaint[0];
601
+ if (chart)
602
+ {
603
+ var clickData=chart.OnMouseDown(x,y,e);
604
+ if (!clickData) return;
605
+ //if (e.button!=0) return;
606
+
607
+ if ((clickData.Type==2) && (e.button==0 || e.button==2)) //点击行
608
+ {
609
+ if (clickData.Redraw==true)
610
+ this.Draw();
611
+ }
612
+ }
613
+
614
+ document.onmousemove=(e)=>{ this.DocOnMouseMove(e); }
615
+ document.onmouseup=(e)=> { this.DocOnMouseUp(e); }
616
+ }
617
+
618
+ //去掉右键菜单
619
+ this.UIOnContextMenu=function(e)
620
+ {
621
+ e.preventDefault();
622
+ }
623
+
624
+ this.UIOnMouseMove=function(e)
625
+ {
626
+ var pixelTatio = GetDevicePixelRatio();
627
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
628
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
629
+ }
630
+
631
+ this.UIOnMounseOut=function(e)
632
+ {
633
+
634
+ }
635
+
636
+ this.UIOnMouseleave=function(e)
637
+ {
638
+
639
+ }
640
+
641
+ this.DocOnMouseMove=function(e)
642
+ {
643
+ this.DragMove.PreMove.X=this.DragMove.Move.X;
644
+ this.DragMove.PreMove.Y=this.DragMove.Move.Y;
645
+ this.DragMove.Move.X=e.clientX;
646
+ this.DragMove.Move.Y=e.clientX;
647
+
648
+ //if (this.DragMove.Move.X!=this.DragMove.PreMove.X || this.DragMove.Move.Y!=this.DragMove.PreMove.Y)
649
+ // this.StopAutoDragScrollTimer();
650
+
651
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
652
+
653
+ var pixelTatio = GetDevicePixelRatio();
654
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
655
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
656
+
657
+ //JSConsole.Chart.Log(`[JSReportChartContainer::DocOnMouseMove] x=${x}, y=${y}`);
658
+
659
+ if (this.DragRow)
660
+ {
661
+ var drag=this.DragRow;
662
+ var moveSetpY=drag.LastMove.Y-e.clientY;
663
+ if (Math.abs(moveSetpY)<2) return;
664
+ var reportChart=this.GetReportChart();
665
+ drag.LastMove.X=e.clientX;
666
+ drag.LastMove.Y=e.clientY;
667
+ drag.Inside={X:x, Y:y};
668
+
669
+ if (reportChart)
670
+ {
671
+ var moveRow=reportChart.OnDrawgRow(x,y,e);
672
+ if (moveRow )
673
+ {
674
+ if (moveRow.Type==2)
675
+ {
676
+ if (moveRow.Data.DataIndex!=drag.Data.Row.DataIndex)
677
+ {
678
+ drag.MoveRow=moveRow;
679
+ }
680
+ }
681
+ else if (moveRow.Type==7)
682
+ {
683
+ var pageStatus=reportChart.GetCurrentPageStatus();
684
+ if (!pageStatus.IsEnd)
685
+ {
686
+ this.MoveYOffset(1, false);
687
+ drag.MoveRow=null;
688
+
689
+ this.EnablePageScroll=true;
690
+ this.AutoScrollPage(2);
691
+ }
692
+ }
693
+ else if (moveRow.Type==5)
694
+ {
695
+ if (this.Data.YOffset>0)
696
+ {
697
+ this.MoveYOffset(-1, false);
698
+ drag.MoveRow=null;
699
+
700
+ this.EnablePageScroll=true;
701
+ this.AutoScrollPage(-2);
702
+ }
703
+ }
704
+ }
705
+ reportChart.DragRow=drag;
706
+ }
707
+
708
+ this.Draw();
709
+ }
710
+ else if (this.DragXScroll)
711
+ {
712
+ var chart=this.ChartPaint[0];
713
+ if (!chart || !chart.Tab) return;
714
+
715
+ this.DragXScroll.LastMove.X=x;
716
+ this.DragXScroll.LastMove.Y=y;
717
+ var pos=chart.Tab.GetScrollPostionByPoint(x,y);
718
+ if (this.SetXOffset(pos)) this.Draw();
719
+ }
720
+ }
721
+
722
+ this.DocOnMouseUp=function(e)
723
+ {
724
+ //清空事件
725
+ document.onmousemove=null;
726
+ document.onmouseup=null;
727
+
728
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_KEYBOARD_MOUSEUP)
729
+ if (event && event.Callback)
730
+ {
731
+ event.Callback(event, { }, this);
732
+ }
733
+ }
734
+
735
+
736
+ this.GetMoveAngle=function(pt,pt2) //计算角度
737
+ {
738
+ var xMove=Math.abs(pt.X-pt2.X);
739
+ var yMove=Math.abs(pt.Y-pt2.Y);
740
+ var angle=Math.atan(xMove/yMove)*180/Math.PI;
741
+ return angle;
742
+ }
743
+
744
+ this.PreventTouchEvent=function(e)
745
+ {
746
+ if (e.cancelable) e.preventDefault();
747
+ e.stopPropagation();
748
+ }
749
+
750
+ this.OnDragYOffset=function(drag, touches, moveUpDown, e)
751
+ {
752
+ if (moveUpDown<5) return false
753
+
754
+ var isUp=true;
755
+ if (drag.LastMove.Y<touches[0].clientY) isUp=false; //Down
756
+
757
+ var oneStep=this.YStepPixel;
758
+ if (oneStep<=0) oneStep=5;
759
+
760
+ var step=parseInt(moveUpDown/oneStep);
761
+ if (step<=0) return false
762
+
763
+ if (isUp==false) step*=-1;
764
+
765
+ if (this.MoveYOffset(step, this.DragPageCycle))
766
+ {
767
+ drag.IsYMove=true;
768
+ this.Draw();
769
+ this.DelayUpdateStockData();
770
+ }
771
+
772
+ return true;
773
+ }
774
+
775
+ this.OnDragXOffset=function(drag, touches, moveLeftRight, e)
776
+ {
777
+ if (moveLeftRight<5) return false;
778
+
779
+ var isLeft=true;
780
+ if (drag.LastMove.X<touches[0].clientX) isLeft=false;//右移数据
781
+
782
+ var oneStep=this.XStepPixel;
783
+ if (oneStep<=0) oneStep=5;
784
+
785
+ var step=parseInt(moveLeftRight/oneStep); //除以4个像素
786
+ if (step<=0) return false;
787
+
788
+ if (!isLeft) step*=-1;
789
+
790
+ if (this.MoveXOffset(step))
791
+ {
792
+ drag.IsXMove=true;
793
+ this.Draw();
794
+ }
795
+
796
+ return true;
797
+ }
798
+
799
+ this.GetReportChart=function()
800
+ {
801
+ var chart=this.ChartPaint[0];
802
+ return chart;
803
+ }
804
+
805
+ this.GotoNextPage=function(bCycle) //bCycle 是否循环
806
+ {
807
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
808
+ var chart=this.ChartPaint[0];
809
+ if (!chart) return false;
810
+
811
+ var pageSize=chart.GetPageSize();
812
+ if (pageSize>this.Data.Data.length) return false;
813
+ if (this.Data.YOffset+pageSize>=this.Data.Data.length)
814
+ {
815
+ if (bCycle===true)
816
+ {
817
+ this.Data.YOffset=0; //循环到第1页
818
+ return true;
819
+ }
820
+ else
821
+ {
822
+ return false;
823
+ }
824
+ }
825
+
826
+ this.Data.YOffset+=pageSize;
827
+ var showDataCount=this.Data.Data.length-this.Data.YOffset;
828
+
829
+ chart.SelectedRow=this.Data.YOffset;
830
+ return true;
831
+ }
832
+
833
+ this.GotoPreviousPage=function(bCycle) //bCycle 是否循环
834
+ {
835
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
836
+ var chart=this.ChartPaint[0];
837
+ if (!chart) return false;
838
+ var pageSize=chart.GetPageSize();
839
+ if (pageSize>this.Data.Data.length) return false;
840
+
841
+ if (this.Data.YOffset<=0)
842
+ {
843
+ if (bCycle===true)
844
+ {
845
+ this.Data.YOffset=this.Data.Data.length-pageSize; //循环到最后一页
846
+ return true;
847
+ }
848
+ else
849
+ {
850
+ return false;
851
+ }
852
+ }
853
+
854
+ var offset=this.Data.YOffset;
855
+ offset-=pageSize;
856
+ if (offset<0) offset=0;
857
+ this.Data.YOffset=offset;
858
+ chart.SelectedRow=this.Data.YOffset;
859
+
860
+ return true;
861
+ }
862
+
863
+ this.MoveYOffset=function(setp, bCycle) //bCycle 是否循环
864
+ {
865
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
866
+ var chart=this.ChartPaint[0];
867
+ if (!chart) return false;
868
+
869
+ var pageStatus=chart.GetCurrentPageStatus();
870
+ if (pageStatus.IsSinglePage) return false;
871
+
872
+ if (setp>0) //向上
873
+ {
874
+ var count=this.Data.Data.length;
875
+ var pageSize=pageStatus.PageSize;
876
+ var offset=this.Data.YOffset;
877
+ if (bCycle)
878
+ {
879
+ for(var i=0;i<setp;++i)
880
+ {
881
+ ++offset;
882
+ if (offset+pageSize>count) offset=0;
883
+ }
884
+ }
885
+ else
886
+ {
887
+ if (offset+pageSize>=count) return false;
888
+
889
+ for(var i=0;i<setp;++i)
890
+ {
891
+ if (offset+pageSize+1>count) break;
892
+ ++offset;
893
+ }
894
+ }
895
+
896
+ this.Data.YOffset=offset;
897
+ return true;
898
+ }
899
+ else if (setp<0) //向下
900
+ {
901
+ setp=Math.abs(setp);
902
+ var offset=this.Data.YOffset;
903
+ if (bCycle)
904
+ {
905
+ var pageSize=pageStatus.PageSize;
906
+ for(var i=0;i<setp;++i)
907
+ {
908
+ --offset;
909
+ if (offset<0) offset=this.Data.Data.length-pageSize;
910
+ }
911
+ }
912
+ else
913
+ {
914
+ if (this.Data.YOffset<=0) return false;
915
+ for(var i=0;i<setp;++i)
916
+ {
917
+ if (offset-1<0) break;
918
+ --offset;
919
+ }
920
+ }
921
+
922
+ this.Data.YOffset=offset;
923
+ return true;
924
+ }
925
+
926
+ return false;
927
+ }
928
+
929
+ this.GotoLastPage=function()
930
+ {
931
+ var chart=this.ChartPaint[0];
932
+ if (!chart) return;
933
+
934
+ //显示最后一屏
935
+ var pageSize=chart.GetPageSize(true);
936
+ var offset=this.Data.Data.length-pageSize;
937
+ if (offset<0) offset=0;
938
+ this.Data.DataOffset=offset;
939
+ }
940
+
941
+ this.SetColumn=function(aryColunm, option)
942
+ {
943
+ var chart=this.ChartPaint[0];
944
+ if (!chart) return;
945
+
946
+ chart.SetColumn(aryColunm);
947
+ chart.SizeChange=true;
948
+
949
+ if (option && option.Redraw) this.Draw();
950
+ }
951
+
952
+ this.ReloadResource=function(option)
953
+ {
954
+ this.Frame.ReloadResource(option);
955
+
956
+ for(var i=0;i<this.ChartPaint.length;++i)
957
+ {
958
+ var item=this.ChartPaint[i];
959
+ if (item.ReloadResource) item.ReloadResource(option);
960
+ }
961
+
962
+ if (option && option.Redraw)
963
+ {
964
+ this.SetSizeChange(true);
965
+ this.Draw();
966
+ }
967
+ }
968
+
969
+ this.MoveSelectedRow=function(step)
970
+ {
971
+ var chart=this.ChartPaint[0];
972
+ if (!chart) return null;
973
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return null;
974
+
975
+ var result={ Redraw:false }; //Redraw=重绘
976
+
977
+ //可翻页模式
978
+ var pageStatus=chart.GetCurrentPageStatus();
979
+ var pageSize=pageStatus.PageSize;
980
+ var selected=pageStatus.SelectedRow;
981
+
982
+ if (step>0)
983
+ {
984
+ if (selected<0 || selected<pageStatus.Start || selected>pageStatus.End)
985
+ {
986
+ chart.SelectedRow=pageStatus.Start;
987
+ result.Redraw=true;
988
+ return result;
989
+ }
990
+
991
+ var offset=this.Data.YOffset;
992
+ for(var i=0;i<step;++i)
993
+ {
994
+ ++selected;
995
+ if (selected>pageStatus.End) ++offset;
996
+
997
+ if (selected>=this.Data.Data.length)
998
+ break;
999
+
1000
+ result.Redraw=true;
1001
+ chart.SelectedRow=selected;
1002
+ this.Data.YOffset=offset;
1003
+ }
1004
+
1005
+ return result;
1006
+ }
1007
+ else if (step<0)
1008
+ {
1009
+ if (selected<0 || selected<pageStatus.Start || selected>pageStatus.End)
1010
+ {
1011
+ chart.SelectedRow=pageStatus.End;
1012
+ result.Redraw=true;
1013
+ return result;
1014
+ }
1015
+
1016
+ step=Math.abs(step);
1017
+ var offset=this.Data.YOffset;
1018
+ for(var i=0;i<step;++i)
1019
+ {
1020
+ --selected;
1021
+ if (selected<pageStatus.Start) --offset;
1022
+
1023
+ if (selected<0)
1024
+ break;
1025
+
1026
+ result.Redraw=true;
1027
+ chart.SelectedRow=selected;
1028
+ this.Data.YOffset=offset;
1029
+ }
1030
+
1031
+ return result;
1032
+ }
1033
+ }
1034
+ }
1035
+
1036
+ function JSKeyboardFrame()
1037
+ {
1038
+ this.ChartBorder;
1039
+ this.Canvas; //画布
1040
+
1041
+ this.BorderLine=null; //1=上 2=下 4=左 8=右
1042
+
1043
+ this.BorderColor=g_JSChartResource.Report.BorderColor; //边框线
1044
+
1045
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
1046
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
1047
+
1048
+ this.ReloadResource=function(resource)
1049
+ {
1050
+ this.BorderColor=g_JSChartResource.Report.BorderColor; //边框线
1051
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
1052
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
1053
+ }
1054
+
1055
+ this.Draw=function()
1056
+ {
1057
+ var left=ToFixedPoint(this.ChartBorder.GetLeft());
1058
+ var top=ToFixedPoint(this.ChartBorder.GetTop());
1059
+ var right=ToFixedPoint(this.ChartBorder.GetRight());
1060
+ var bottom=ToFixedPoint(this.ChartBorder.GetBottom());
1061
+ var width=right-left;
1062
+ var height=bottom-top;
1063
+
1064
+ if (!IFrameSplitOperator.IsNumber(this.BorderLine))
1065
+ {
1066
+ this.Canvas.strokeStyle=this.BorderColor;
1067
+ this.Canvas.strokeRect(left,top,width,height);
1068
+ }
1069
+ else
1070
+ {
1071
+ this.Canvas.strokeStyle=this.BorderColor;
1072
+ this.Canvas.beginPath();
1073
+
1074
+ if ((this.BorderLine&1)>0) //上
1075
+ {
1076
+ this.Canvas.moveTo(left,top);
1077
+ this.Canvas.lineTo(right,top);
1078
+ }
1079
+
1080
+ if ((this.BorderLine&2)>0) //下
1081
+ {
1082
+ this.Canvas.moveTo(left,bottom);
1083
+ this.Canvas.lineTo(right,bottom);
1084
+ }
1085
+
1086
+ if ((this.BorderLine&4)>0) //左
1087
+ {
1088
+ this.Canvas.moveTo(left,top);
1089
+ this.Canvas.lineTo(left,bottom);
1090
+ }
1091
+
1092
+ if ((this.BorderLine&8)>0) //右
1093
+ {
1094
+ this.Canvas.moveTo(right,top);
1095
+ this.Canvas.lineTo(right,bottom);
1096
+ }
1097
+
1098
+ this.Canvas.stroke();
1099
+ }
1100
+ }
1101
+
1102
+ this.DrawLogo=function()
1103
+ {
1104
+ var text=g_JSChartResource.FrameLogo.Text;
1105
+ if (!IFrameSplitOperator.IsString(text)) return;
1106
+
1107
+ this.Canvas.fillStyle=this.LogoTextColor;
1108
+ this.Canvas.font=this.LogoTextFont;
1109
+ this.Canvas.textAlign = 'right';
1110
+ this.Canvas.textBaseline = 'bottom';
1111
+
1112
+ var x=this.ChartBorder.GetRight()-30;
1113
+ var y=this.ChartBorder.GetBottom()-5;
1114
+ this.Canvas.fillText(text,x,y);
1115
+ }
1116
+ }
1117
+
1118
+
1119
+
1120
+ var KEYBOARD_COLUMN_ID=
1121
+ {
1122
+ SHORT_SYMBOL_ID:0, //不带后缀代码
1123
+ SYMBOL_ID:1,
1124
+ NAME_ID:2, //简称
1125
+ TYPE_ID:3 //类型
1126
+ }
1127
+
1128
+
1129
+ function ChartSymbolList()
1130
+ {
1131
+ this.Canvas; //画布
1132
+ this.ChartBorder; //边框信息
1133
+ this.ChartFrame; //框架画法
1134
+ this.Name; //名称
1135
+ this.ClassName='ChartSymbolList'; //类名
1136
+ this.UIElement;
1137
+ this.IsDrawFirst=false;
1138
+ this.GetEventCallback; //获取事件
1139
+ this.Data; //数据 { XOffset:0, YOffset:0, Data:['600000.sh', '000001.sz'] }
1140
+ this.SizeChange=true;
1141
+
1142
+ this.SelectedRow=-1; //选中行ID
1143
+ this.IsDrawBorder=false; //是否绘制单元格边框
1144
+
1145
+ this.ShowSymbol=[]; //显示的股票列表 { Index:序号(排序用), Symbol:股票代码 }
1146
+
1147
+ this.BorderColor=g_JSChartResource.Keyboard.BorderColor; //边框线
1148
+ this.SelectedColor=g_JSChartResource.Keyboard.SelectedColor; //选中行
1149
+ this.TextColor=g_JSChartResource.Keyboard.TextColor; //文字颜色
1150
+
1151
+ //表格内容配置
1152
+ this.ItemFontConfig={ Size:g_JSChartResource.Keyboard.Item.Font.Size, Name:g_JSChartResource.Keyboard.Item.Font.Name };
1153
+ this.ItemMergin=
1154
+ {
1155
+ Left:g_JSChartResource.Keyboard.Item.Mergin.Left,
1156
+ Right:g_JSChartResource.Keyboard.Item.Mergin.Right,
1157
+ Top:g_JSChartResource.Keyboard.Item.Mergin.Top,
1158
+ Bottom:g_JSChartResource.Keyboard.Item.Mergin.Bottom
1159
+ };
1160
+
1161
+ //缓存
1162
+ this.ItemFont=15*GetDevicePixelRatio() +"px 微软雅黑";
1163
+ this.ItemSymbolFont=12*GetDevicePixelRatio() +"px 微软雅黑";
1164
+ this.ItemNameFont=15*GetDevicePixelRatio() +"px 微软雅黑";
1165
+ this.ItemNameHeight=0;
1166
+ this.RowCount=0; //一屏显示行数
1167
+ this.RowHeight=0; //行高度
1168
+
1169
+ this.Column= //{ Type:列id, Title:标题, TextAlign:文字对齐方式, MaxText:文字最大宽度 , TextColor:文字颜色, Sort:0=不支持排序 1=本地排序 0=远程排序 }
1170
+ [
1171
+ { Type:KEYBOARD_COLUMN_ID.SHORT_SYMBOL_ID, Title:"代码", TextAlign:"left", Width:null, MaxText:"888888" },
1172
+ { Type:KEYBOARD_COLUMN_ID.NAME_ID, Title:"名称", TextAlign:"left", Width:null, MaxText:"擎擎擎擎擎擎" },
1173
+ { Type:KEYBOARD_COLUMN_ID.TYPE_ID, Title:"类型", TextAlign:"right", Width:null, MaxText:"擎擎擎擎" },
1174
+ ];
1175
+
1176
+ this.RectClient={ };
1177
+
1178
+ this.ReloadResource=function(resource)
1179
+ {
1180
+
1181
+ }
1182
+
1183
+ this.SetColumn=function(aryColumn)
1184
+ {
1185
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryColumn)) return;
1186
+ }
1187
+
1188
+ this.Draw=function()
1189
+ {
1190
+ this.ShowSymbol=[ ];
1191
+
1192
+ if (this.SizeChange) this.CalculateSize();
1193
+ else this.UpdateCacheData();
1194
+
1195
+ this.Canvas.save();
1196
+
1197
+ this.Canvas.beginPath();
1198
+ this.Canvas.rect(this.RectClient.Left,this.RectClient.Top,(this.RectClient.Right-this.RectClient.Left),(this.RectClient.Bottom-this.RectClient.Top));
1199
+ //this.Canvas.stroke(); //调试用
1200
+ this.Canvas.clip();
1201
+
1202
+ this.DrawBody();
1203
+ this.Canvas.restore();
1204
+
1205
+ this.DrawBorder();
1206
+
1207
+ this.SizeChange=false;
1208
+ }
1209
+
1210
+ //更新缓存变量
1211
+ this.UpdateCacheData=function()
1212
+ {
1213
+ this.RectClient.Left=this.ChartBorder.GetLeft();
1214
+ this.RectClient.Right=this.ChartBorder.GetRight();
1215
+ this.RectClient.Top=this.ChartBorder.GetTop();
1216
+ this.RectClient.Bottom=this.ChartBorder.GetBottom();
1217
+ }
1218
+
1219
+ this.GetPageSize=function(recalculate) //recalculate 是否重新计算
1220
+ {
1221
+ if (recalculate) this.CalculateSize();
1222
+ var size=this.RowCount;
1223
+ return size;
1224
+ }
1225
+
1226
+ this.GetCurrentPageStatus=function() //{ Start:起始索引, End:结束索引(数据), PageSize:页面可以显示几条记录, IsEnd:是否是最后一页, IsSinglePage:是否只有一页数据}
1227
+ {
1228
+ var result={ Start:this.Data.YOffset, PageSize:this.RowCount, IsEnd:false, SelectedRow:this.SelectedRow, IsSinglePage:false, DataCount:0 };
1229
+ if (IFrameSplitOperator.IsNonEmptyArray(this.Data.Data))
1230
+ {
1231
+ result.End=this.Data.YOffset+this.RowCount-1;
1232
+ result.IsSinglePage=this.Data.Data.length<=this.RowCount;
1233
+ result.DataCount=this.Data.Data.length;
1234
+ if (result.End>=this.Data.Data.length-1) result.IsEnd=true;
1235
+ if (result.End>=this.Data.Data.length) result.End=this.Data.Data.length-1;
1236
+ }
1237
+ else
1238
+ {
1239
+ result.Star=0;
1240
+ result.End=0;
1241
+ result.IsEnd=true;
1242
+ result.IsSinglePage=true;
1243
+ }
1244
+
1245
+ return result;
1246
+ }
1247
+
1248
+ this.CalculateSize=function() //计算大小
1249
+ {
1250
+ this.UpdateCacheData();
1251
+
1252
+ var pixelRatio=GetDevicePixelRatio();
1253
+ this.ItemFont=`${this.ItemFontConfig.Size*pixelRatio}px ${ this.ItemFontConfig.Name}`;
1254
+ this.RowHeight=this.GetFontHeight(this.ItemFont,"擎")+ this.ItemMergin.Top+ this.ItemMergin.Bottom;
1255
+ var left=this.RectClient.Left;
1256
+ var right=this.RectClient.Right;
1257
+
1258
+ this.Canvas.font=this.ItemFont;
1259
+ var itemWidth=0;
1260
+ for(var i=0;i<this.Column.length;++i)
1261
+ {
1262
+ var item=this.Column[i];
1263
+ itemWidth=this.Canvas.measureText(item.MaxText).width;
1264
+ item.Width=itemWidth+4+this.ItemMergin.Left+this.ItemMergin.Right;
1265
+
1266
+ if (i==this.Column.length-1) //最后一列
1267
+ {
1268
+ if (left+item.Width<right) item.Width=right-left;
1269
+ }
1270
+
1271
+ left+=item.Width;
1272
+ }
1273
+
1274
+ this.RowCount=parseInt((this.RectClient.Bottom-this.RectClient.Top)/this.RowHeight);
1275
+ }
1276
+
1277
+ this.DrawText=function(text, textAlign, x, y, textWidth)
1278
+ {
1279
+ if (textAlign=='center')
1280
+ {
1281
+ x=x+textWidth/2;
1282
+ this.Canvas.textAlign="center";
1283
+ }
1284
+ else if (textAlign=='right')
1285
+ {
1286
+ x=x+textWidth;
1287
+ this.Canvas.textAlign="right";
1288
+ }
1289
+ else
1290
+ {
1291
+ this.Canvas.textAlign="left";
1292
+ }
1293
+
1294
+ this.Canvas.textBaseline="middle";
1295
+ this.Canvas.fillText(text,x,y);
1296
+ }
1297
+
1298
+ this.DrawBorder=function()
1299
+ {
1300
+ if (!this.IsDrawBorder) return;
1301
+
1302
+ var left=this.RectClient.Left;
1303
+ var right=this.RectClient.Right;
1304
+ var top=this.RectClient.Top;
1305
+ var bottom=this.RectClient.Bottom;
1306
+
1307
+ this.Canvas.strokeStyle=this.BorderColor;
1308
+ this.Canvas.beginPath();
1309
+
1310
+ this.Canvas.moveTo(left,ToFixedPoint(top));
1311
+ this.Canvas.lineTo(right,ToFixedPoint(top));
1312
+
1313
+ var rowTop=top+this.RowHeight;
1314
+ var rotBottom=rowTop;
1315
+ //横线
1316
+ for(var i=0;i<this.RowCount;++i)
1317
+ {
1318
+ var drawTop=ToFixedPoint(rowTop);
1319
+ this.Canvas.moveTo(left,drawTop);
1320
+ this.Canvas.lineTo(right,drawTop);
1321
+ rotBottom=rowTop;
1322
+ rowTop+=this.RowHeight;
1323
+ }
1324
+
1325
+ //竖线
1326
+ var columnLeft=left;
1327
+ for(var i=this.Data.XOffset;i<this.Column.length;++i)
1328
+ {
1329
+ var item=this.Column[i];
1330
+ var drawLeft=ToFixedPoint(columnLeft+item.Width);
1331
+ this.Canvas.moveTo(drawLeft,top);
1332
+ this.Canvas.lineTo(drawLeft,rotBottom);
1333
+
1334
+ columnLeft+=item.Width;
1335
+ }
1336
+
1337
+ this.Canvas.stroke();
1338
+ }
1339
+
1340
+ this.GetSelectedSymbol=function()
1341
+ {
1342
+ if (this.SelectedRow<0 || this.SelectedRow>=this.Data.Data.length) return null;
1343
+
1344
+ return { Symbol: this.Data.Data[this.SelectedRow], RowID: this.SelectedRow };
1345
+ }
1346
+
1347
+ this.DrawBody=function()
1348
+ {
1349
+ if (!this.Data) return;
1350
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
1351
+
1352
+ this.Canvas.font=this.ItemFont;
1353
+ var top=this.RectClient.Top;
1354
+ var left=this.RectClient.Left;
1355
+ var rowWidth=this.RectClient.Right-this.RectClient.Left;
1356
+
1357
+ var textTop=top;
1358
+ this.Canvas.font=this.ItemFont;
1359
+ for(var i=this.Data.YOffset, j=0; i<this.Data.Data.length && j<this.RowCount ;++i, ++j)
1360
+ {
1361
+ var symbol=this.Data.Data[i];
1362
+
1363
+ var bFillRow=false;
1364
+ if (i==this.SelectedRow) bFillRow=true; //选中行
1365
+
1366
+ if (bFillRow)
1367
+ {
1368
+ this.Canvas.fillStyle=this.SelectedColor;
1369
+ this.Canvas.fillRect(left+1,textTop,rowWidth,this.RowHeight);
1370
+ }
1371
+
1372
+ this.DrawRow(symbol, textTop, i);
1373
+
1374
+ this.ShowSymbol.push( { Index:i, Symbol:symbol } );
1375
+
1376
+ textTop+=this.RowHeight;
1377
+ }
1378
+ }
1379
+
1380
+ this.DrawRow=function(symbol, top, dataIndex, rowType) //rowType 0=表格行 1=顶部固定行 2=拖拽行
1381
+ {
1382
+ var left=this.RectClient.Left;
1383
+ var chartRight=this.RectClient.Right;
1384
+ var data= { Symbol:symbol , Stock:null, Block:null };
1385
+ if (this.GetStockDataCallback) data.Stock=this.GetStockDataCallback(symbol);
1386
+
1387
+ for(var i=this.Data.XOffset;i<this.Column.length;++i)
1388
+ {
1389
+ var item=this.Column[i];
1390
+ this.DrawItem(dataIndex, data, item, left, top, rowType);
1391
+ left+=item.Width;
1392
+
1393
+ if (left>=chartRight) break;
1394
+ }
1395
+ }
1396
+
1397
+ this.DrawItem=function(index, data, column, left, top, rowType)
1398
+ {
1399
+ var itemWidth=column.Width;
1400
+ var x=left+this.ItemMergin.Left;
1401
+ var textWidth=column.Width-this.ItemMergin.Left-this.ItemMergin.Right;
1402
+ var stock=data.Stock;
1403
+ var drawInfo={ Text:null, TextColor:this.TextColor , TextAlign:column.TextAlign };
1404
+ if (column.Type==KEYBOARD_COLUMN_ID.SHORT_SYMBOL_ID)
1405
+ {
1406
+ if (stock && stock.ShortSymbol) drawInfo.Text=stock.ShortSymbol;
1407
+ else drawInfo.Text=data.Symbol;
1408
+
1409
+ if (stock.Color) drawInfo.TextColor=stock.Color;
1410
+ }
1411
+ else if (column.Type==KEYBOARD_COLUMN_ID.NAME_ID)
1412
+ {
1413
+ if (stock && stock.Name)
1414
+ {
1415
+ drawInfo.Text=this.TextEllipsis(stock.Name, textWidth, column.MaxText);
1416
+ if (stock.Color) drawInfo.TextColor=stock.Color;
1417
+ }
1418
+ }
1419
+ else if (column.Type==KEYBOARD_COLUMN_ID.TYPE_ID)
1420
+ {
1421
+ if (stock && stock.Type)
1422
+ {
1423
+ drawInfo.Text=this.TextEllipsis(stock.Type, textWidth, column.MaxText);
1424
+ if (stock.Color) drawInfo.TextColor=stock.Color;
1425
+ }
1426
+ }
1427
+
1428
+ this.DrawItemText(drawInfo.Text, drawInfo.TextColor, drawInfo.TextAlign, x, top, textWidth);
1429
+ }
1430
+
1431
+ this.DrawItemText=function(text, textColor, textAlign, left, top, width)
1432
+ {
1433
+ if (!text) return;
1434
+
1435
+ var x=left;
1436
+ if (textAlign=='center')
1437
+ {
1438
+ x=left+width/2;
1439
+ this.Canvas.textAlign="center";
1440
+ }
1441
+ else if (textAlign=='right')
1442
+ {
1443
+ x=left+width-2;
1444
+ this.Canvas.textAlign="right";
1445
+ }
1446
+ else
1447
+ {
1448
+ x+=2;
1449
+ this.Canvas.textAlign="left";
1450
+ }
1451
+
1452
+ this.Canvas.textBaseline="middle";
1453
+ this.Canvas.fillStyle=textColor;
1454
+ this.Canvas.fillText(text,x,top+this.ItemMergin.Top+this.RowHeight/2);
1455
+ }
1456
+
1457
+ //字体由外面设置
1458
+ this.TextEllipsis=function(text, maxWidth, maxText)
1459
+ {
1460
+ if (!text) return null;
1461
+
1462
+ if (text.length<maxText.length) return text;
1463
+
1464
+ var start=maxText.length-3;
1465
+ if (start<0) return null;
1466
+ var newText=text.slice(0,start);
1467
+ for(var i=start;i<text.length;++i)
1468
+ {
1469
+ var value=newText + text[i] + "...";
1470
+ var width=this.Canvas.measureText(value).width;
1471
+ if (width>maxWidth)
1472
+ {
1473
+ newText+="...";
1474
+ break;
1475
+ }
1476
+ newText+=text[i];
1477
+ }
1478
+
1479
+ return newText;
1480
+ }
1481
+
1482
+ this.GetFontHeight=function(font,word)
1483
+ {
1484
+ return GetFontHeight(this.Canvas, font, word);
1485
+ }
1486
+
1487
+ this.OnMouseDown=function(x,y,e) //Type: 2=行
1488
+ {
1489
+ if (!this.Data) return null;
1490
+ var pixelTatio = GetDevicePixelRatio();
1491
+ var insidePoint={X:x/pixelTatio, Y:y/pixelTatio};
1492
+
1493
+ if (this.UIElement)
1494
+ var uiElement={Left:this.UIElement.getBoundingClientRect().left, Top:this.UIElement.getBoundingClientRect().top};
1495
+ else
1496
+ var uiElement={Left:null, Top:null};
1497
+
1498
+ var row=this.PtInBody(x,y);
1499
+ if (row)
1500
+ {
1501
+ var bRedraw=true;
1502
+ if (this.SelectedModel==0)
1503
+ {
1504
+ if (this.SelectedRow==row.Index) bRedraw=false;
1505
+ this.SelectedRow=row.Index;
1506
+ this.SelectedFixedRow=-1;
1507
+ }
1508
+ else
1509
+ {
1510
+ if (this.SelectedRow==row.DataIndex) bRedraw=false;
1511
+ this.SelectedRow=row.DataIndex;
1512
+ this.SelectedFixedRow=-1;
1513
+ }
1514
+
1515
+ var eventID=JSCHART_EVENT_ID.ON_CLICK_REPORT_ROW;
1516
+ if (e.button==2) eventID=JSCHART_EVENT_ID.ON_RCLICK_REPORT_ROW;
1517
+
1518
+ this.SendClickEvent(eventID, { Data:row, X:x, Y:y, e:e, Inside:insidePoint, UIElement:uiElement });
1519
+
1520
+ return { Type:2, Redraw:bRedraw, Row:row }; //行
1521
+ }
1522
+
1523
+ return null;
1524
+ }
1525
+
1526
+ this.OnDrawgRow=function(x, y, e) //Type: 5=顶部 6=空白行 2=行 7=底部
1527
+ {
1528
+ if (!this.Data) return null;
1529
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return null;
1530
+
1531
+ var topOffset=this.RowHeight/2;
1532
+ var top=this.RectClient.Top+this.HeaderHeight;
1533
+ var right=this.ChartBorder.GetChartWidth();
1534
+ var textTop=top;
1535
+
1536
+ if (y<textTop+topOffset) return { Type:5 };
1537
+
1538
+
1539
+ for(var i=this.Data.YOffset, j=0; i<this.Data.Data.length && j<this.RowCount ;++i, ++j)
1540
+ {
1541
+ var symbol=this.Data.Data[i];
1542
+ var rtRow={ Left:0, Top:textTop, Right:right, Bottom: textTop+this.RowHeight };
1543
+ rtRow.Top+=topOffset;
1544
+ rtRow.Bottom+=topOffset;
1545
+
1546
+ if (x>=rtRow.Left && x<=rtRow.Right && y>=rtRow.Top && y<=rtRow.Bottom)
1547
+ {
1548
+ var data={ DataIndex:i, Index:j , Symbol:symbol, Pos:0 };
1549
+ if (j==0) data.Pos=1;
1550
+ else if (j==this.RowCount-1) data.Pos=2;
1551
+ return { Type: 2, Data:data };
1552
+ }
1553
+
1554
+ textTop+=this.RowHeight;
1555
+ }
1556
+
1557
+ if (j<this.RowCount) return { Type:6 };
1558
+
1559
+ return { Type:7 };
1560
+ }
1561
+
1562
+ this.OnDblClick=function(x,y,e)
1563
+ {
1564
+ if (!this.Data) return false;
1565
+
1566
+ var row=this.PtInBody(x,y);
1567
+ if (row) return true;
1568
+
1569
+ return false;
1570
+ }
1571
+
1572
+ this.PtInBody=function(x,y)
1573
+ {
1574
+ if (!this.Data) return null;
1575
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return null;
1576
+
1577
+ var top=this.RectClient.Top;
1578
+ var left=this.RectClient.Left;
1579
+ var right=this.RectClient.Right;
1580
+ var rowWidth=this.RectClient.Right-this.RectClient.Left;
1581
+
1582
+ var textTop=top;
1583
+ for(var i=this.Data.YOffset, j=0; i<this.Data.Data.length && j<this.RowCount ;++i, ++j)
1584
+ {
1585
+ var symbol=this.Data.Data[i];
1586
+ var rtRow={ Left:left, Top:textTop, Right:right, Bottom: textTop+this.RowHeight };
1587
+
1588
+ if (x>=rtRow.Left && x<=rtRow.Right && y>=rtRow.Top && y<=rtRow.Bottom)
1589
+ {
1590
+ var data={ Rect:rtRow, DataIndex:i, Index:j , Symbol:symbol };
1591
+ data.Item=this.PtInItem(x,y, rtRow.Top, rtRow.Bottom);
1592
+ return data;
1593
+ }
1594
+
1595
+ textTop+=this.RowHeight;
1596
+ }
1597
+
1598
+ return null;
1599
+ }
1600
+
1601
+ this.PtInItem=function(x,y, top, bottom)
1602
+ {
1603
+ var left=this.RectClient.Left;
1604
+ var right=this.RectClient.Right;
1605
+
1606
+ var textLeft=left;
1607
+ //固定列
1608
+ for(var i=0;i<this.FixedColumn && i<this.Column.length;++i)
1609
+ {
1610
+ var item=this.Column[i];
1611
+ var header={Left:textLeft, Right:textLeft+item.Width, Top:top, Bottom:bottom };
1612
+
1613
+ if (x>=header.Left && x<=header.Right && y>=header.Top && y<=header.Bottom)
1614
+ {
1615
+ return { Rect:header, Column:item, Index:i };
1616
+ }
1617
+
1618
+ textLeft+=item.Width;
1619
+ }
1620
+
1621
+ for(var i=this.FixedColumn+this.Data.XOffset;i<this.Column.length;++i)
1622
+ {
1623
+ var item=this.Column[i];
1624
+ if (textLeft>=right) break;
1625
+
1626
+ var header={Left:textLeft, Right:textLeft+item.Width, Top:top, Bottom:bottom };
1627
+
1628
+ if (x>=header.Left && x<=header.Right && y>=header.Top && y<=header.Bottom)
1629
+ {
1630
+ return { Rect:header, Column:item, Index:i };
1631
+ }
1632
+ textLeft+=item.Width;
1633
+ }
1634
+
1635
+ return null;
1636
+ }
1637
+
1638
+ this.IsPtInBody=function(x,y)
1639
+ {
1640
+ var top=this.RectClient.Top;
1641
+ var left=this.RectClient.Left;
1642
+ var right=this.RectClient.Right;
1643
+ var bottom=this.RectClient.Bottom;
1644
+
1645
+ if (x>=left && x<=right && y>=top && y<=bottom) return true;
1646
+
1647
+ return false;
1648
+ }
1649
+
1650
+ this.SendClickEvent=function(id, data)
1651
+ {
1652
+ var event=this.GetEventCallback(id);
1653
+ if (event && event.Callback)
1654
+ {
1655
+ event.Callback(event,data,this);
1656
+ }
1657
+ }
1658
+ }
1659
+