forked from jones2000/HQChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathumychart.report.wechat.js
More file actions
4044 lines (3391 loc) · 135 KB
/
Copy pathumychart.report.wechat.js
File metadata and controls
4044 lines (3391 loc) · 135 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2018 jones
http://www.apache.org/licenses/LICENSE-2.0
开源项目 https://github.com/jones2000/HQChart
jones_2000@163.com
封装股票列表控件 (小程序版本)
不提供内置测试数据
*/
//日志
import { JSConsole } from "./umychart.console.wechat.js"
//画布DOM
import { JSCanvasElement } from "./umychart.element.wechart.js";
import{
g_JSChartResource,
JSCHART_LANGUAGE_ID,
g_JSChartLocalization,
} from './umychart.resource.wechat.js'
import
{
IFrameSplitOperator,
} from './umychart.framesplit.wechat.js'
import
{
GetfloatPrecision,
} from "./umychart.coordinatedata.wechat.js";
//图形库
import {
ChartSplashPaint,
GetFontHeight,
} from "./umychart.chartpaint.wechat.js";
//行情数据结构体 及涉及到的行情算法(复权,周期等)
import {
JSCHART_EVENT_ID,
PhoneDBClick,
} from "./umychart.data.wechat.js";
//边框信息
function ChartBorder()
{
this.UIElement;
//四周间距
this.Left = 50;
this.Right = 80;
this.Top = 50;
this.Bottom = 50;
this.GetChartWidth = function ()
{
return this.UIElement.Width;
}
this.GetChartHeight = function ()
{
return this.UIElement.Height;
}
this.GetLeft = function ()
{
return this.Left;
}
this.GetRight = function ()
{
return this.UIElement.Width - this.Right;
}
this.GetTop = function ()
{
return this.Top;
}
this.GetBottom = function ()
{
return this.UIElement.Height - this.Bottom;
}
this.GetWidth = function ()
{
return this.UIElement.Width - this.Left - this.Right;
}
this.GetHeight = function ()
{
return this.UIElement.Height - this.Top - this.Bottom;
}
}
function JSReportChart(element)
{
this.CanvasElement=element;
this.JSChartContainer; //表格控件
this.OnSize=function(option)
{
if (option)
{
if (IFrameSplitOperator.IsNumber(option.Width)) this.CanvasElement.Width=option.Width;
if (IFrameSplitOperator.IsNumber(option.Height)) this.CanvasElement.Height=option.Height;
}
if (option && option.Redraw==false) return;
if (this.JSChartContainer && this.JSChartContainer.OnSize)
{
this.JSChartContainer.OnSize();
}
}
this.SetOption=function(option)
{
var chart=this.CreateJSReportChartContainer(option);
if (!chart) return false;
if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
this.JSChartContainer=chart;
if (option.Symbol) chart.Symbol=option.Symbol;
if (option.Name) chart.Name=option.Name;
var requestOption={ Callback:null };
if (chart.Symbol) requestOption.Callback=function() { chart.RequestMemberListData(); };
chart.RequestStockListData(requestOption); //下载码表
}
this.CreateJSReportChartContainer=function(option)
{
var chart=new JSReportChartContainer(this.CanvasElement);
chart.Create(option);
if (option.NetworkFilter) chart.NetworkFilter=option.NetworkFilter;
if (IFrameSplitOperator.IsNonEmptyArray(option.Column)) chart.SetColumn(option.Column);
if (IFrameSplitOperator.IsNonEmptyArray(option.Tab)) chart.SetTab(option.Tab);
if (IFrameSplitOperator.IsNumber(option.TabSelected)) chart.SetSelectedTab(option.TabSelected);
if (option.SortInfo)
{
var item=option.SortInfo;
if (IFrameSplitOperator.IsNumber(item.Field)) chart.SortInfo.Field=item.Field;
if (IFrameSplitOperator.IsNumber(item.Sort)) chart.SortInfo.Sort=item.Sort;
}
this.SetChartBorder(chart, option);
//是否自动更新
if (option.IsAutoUpdate!=null) chart.IsAutoUpdate=option.IsAutoUpdate;
if (option.AutoUpdateFrequency>0) chart.AutoUpdateFrequency=option.AutoUpdateFrequency;
if (IFrameSplitOperator.IsBool(option.EnableFilter)) chart.EnableFilter=option.EnableFilter;
//注册事件
if (option.EventCallback)
{
for(var i=0;i<option.EventCallback.length;++i)
{
var item=option.EventCallback[i];
chart.AddEventCallback(item);
}
}
return chart;
}
this.SetChartBorder=function(chart, option)
{
if (!option.Border) return;
var item=option.Border;
if (IFrameSplitOperator.IsNumber(option.Border.Left)) chart.Frame.ChartBorder.Left=option.Border.Left;
if (IFrameSplitOperator.IsNumber(option.Border.Right)) chart.Frame.ChartBorder.Right=option.Border.Right;
if (IFrameSplitOperator.IsNumber(option.Border.Top)) chart.Frame.ChartBorder.Top=option.Border.Top;
if (IFrameSplitOperator.IsNumber(option.Border.Bottom)) chart.Frame.ChartBorder.Bottom=option.Border.Bottom;
}
/////////////////////////////////////////////////////////////////////////////
//对外接口
//切换股票代码接口
this.ChangeSymbol=function(symbol, option)
{
if (this.JSChartContainer) this.JSChartContainer.ChangeSymbol(symbol,option);
}
this.SetColumn=function(aryColumn, option)
{
if (this.JSChartContainer) this.JSChartContainer.SetColumn(aryColumn,option);
}
//事件回调
this.AddEventCallback=function(obj)
{
if(this.JSChartContainer && typeof(this.JSChartContainer.AddEventCallback)=='function')
{
JSConsole.Chart.Log('[JSReportChart:AddEventCallback] obj=', obj);
this.JSChartContainer.AddEventCallback(obj);
}
}
//重新加载配置
this.ReloadResource=function(option)
{
if(this.JSChartContainer && typeof(this.JSChartContainer.ReloadResource)=='function')
{
JSConsole.Chart.Log('[JSReportChart:ReloadResource] ');
this.JSChartContainer.ReloadResource(option);
}
}
this.ChartDestory=function()
{
if (this.JSChartContainer && typeof (this.JSChartContainer.ChartDestory) == 'function')
{
JSConsole.Chart.Log("[JSReportChart::ChartDestory]");
this.JSChartContainer.ChartDestory();
}
}
this.OnTouchStart = function (e)
{
if (this.JSChartContainer) this.JSChartContainer.OnTouchStart(e);
}
this.OnTouchMove = function (e)
{
if (this.JSChartContainer) this.JSChartContainer.OnTouchMove(e);
}
this.OnTouchEnd = function (e)
{
if (this.JSChartContainer) this.JSChartContainer.OnTouchEnd(e);
}
}
JSReportChart.Init=function(uielement)
{
var jsChartControl=new JSReportChart(uielement);
jsChartControl.OnSize();
return jsChartControl;
}
//自定义风格
JSReportChart.SetStyle = function (style)
{
if (style) g_JSChartResource.SetStyle(style);
}
//获取颜色配置 (设置配必须啊在JSChart.Init()之前)
JSReportChart.GetResource = function ()
{
return g_JSChartResource;
}
//修正线段有毛刺
function ToFixedPoint(value)
{
//return value;
return parseInt(value) + 0.5;
}
function ToFixedRect(value)
{
var rounded;
return rounded = (0.5 + value) << 0;
}
function HQReportItem()
{
this.OriginalSymbol; //原始代码
this.Symbol;
this.Name;
this.YClose;
this.Open;
this.Price;
this.High;
this.Low;
this.Amount;
this.Vol;
this.Increase; //涨幅
this.UpDown; //涨跌
this.Exchange; //换手
this.Amplitude; //振幅
this.BuyPrice; //买价/量
this.BuyVol;
this.SellPrice; //卖价/量
this.SellVol;
this.AvPrice; //均价
this.LimitHigh; //涨停价
this.LimitLow; //跌停价
this.VolIn; //内盘
this.VolOut; //外盘
this.DealNum; //现量
this.OutShares; //流通股本
this.TotalShares; //总股本
this.MarketValue; //总市值
this.CircMarketValue;//流通市值
this.CloseLine; //{Data:[], Max:, Min:, Count: }
this.ExtendData; //扩展数据
}
function JSReportChartContainer(uielement)
{
this.ClassName='JSReportChartContainer';
this.Frame; //框架画法
this.ChartPaint=[]; //图形画法
this.ChartSplashPaint=null; //等待提示
this.LoadDataSplashTitle="数据加载中"; //下载数据提示信息
this.SplashTitle={ StockList:"下载码表中.....", MemberList:"下载成分中....." } ;
this.Canvas=uielement.GetContext("2d"); //画布
this.ShowCanvas=null;
this.Symbol; //板块代码
this.Name; //板块名称
this.NetworkFilter; //数据回调接口
this.Data={ XOffset:0, YOffset:0, Data:[] }; //股票列表
this.SourceData={ Data:[] } ; //原始股票顺序(排序还原用)
this.BlockData=new Map(); //当前板块数据
this.MapStockData=new Map(); //原始股票数据
this.FixedRowData={ Data:[], Type:0, Symbol:[] }; //顶部固定行Data:[{ Value:, Text:, Color:, TextAgiln: }], Type:0=自定义数据, 1 =(股票数据) Symbol:[],
//this.FixedRowData.Data=[ [null, {Value:11, Text:"11" }], [null, null, null, {Value:12, Text:"ddddd", Color:"rgb(45,200,4)"}]];
this.SortInfo={ Field:-1, Sort:0 }; //排序信息 {Field:排序字段id, Sort:0 不排序 1升序 2降序 }
//事件回调
this.mapEvent=new Map(); //通知外部调用 key:JSCHART_EVENT_ID value:{Callback:回调,}
this.AutoUpdateTimer=null;
this.AutoUpdateFrequency=15000; //15秒更新一次数据
this.DelayUpdateTimer=null; //延迟更新
this.DelayUpdateFrequency=500; //延迟更新时间
this.UIElement=uielement;
this.LastPoint=null; //鼠标位置
this.IsOnTouch=false;
this.TouchDrag;
this.TouchMoveMinAngle=70; //左右移动最小角度
this.YStepPixel=5;
this.XStepPixel=10;
this.PageUpDownCycle=true; //翻页循环
this.DragPageCycle=true; //手机翻页循环
//拖拽滚动条
this.DragXScroll=null; //{Start:{x,y}, End:{x, y}}
this.IsDestroy=false; //是否已经销毁了
this.ChartDestory=function() //销毁
{
this.IsDestroy=true;
this.StopAutoUpdate();
}
//清空固定行数据
this.ClearFixedRowData=function()
{
this.FixedRowData.Data=[];
this.FixedRowData.Symbol=[];
}
//设置固定行
this.SetFixedRowCount=function(value)
{
var chart=this.GetReportChart();
if (!chart) return;
chart.FixedRowCount=value;
}
//创建
this.Create=function(option)
{
this.UIElement.JSChartContainer=this;
//创建等待提示
this.ChartSplashPaint = new ChartSplashPaint();
this.ChartSplashPaint.Canvas = this.Canvas;
this.ChartSplashPaint.SetTitle(this.LoadDataSplashTitle);
this.ChartSplashPaint.IsEnableSplash=true;
//创建框架
this.Frame=new JSReportFrame();
this.Frame.ChartBorder=new ChartBorder();
this.Frame.ChartBorder.UIElement=this.UIElement;
this.Frame.ChartBorder.Top=30;
this.Frame.ChartBorder.Left=5;
this.Frame.ChartBorder.Bottom=20;
this.Frame.Canvas=this.Canvas;
this.ChartSplashPaint.Frame = this.Frame;
//创建表格
var chart=new ChartReport();
chart.Frame=this.Frame;
chart.ChartBorder=this.Frame.ChartBorder;
chart.Canvas=this.Canvas;
chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
chart.GetStockDataCallback=(symbol)=>{ return this.GetStockData(symbol);}
chart.GetBlockDataCallback=(symbol)=>{ return this.GetBlockData(symbol);}
chart.Data=this.Data;
chart.FixedRowData=this.FixedRowData;
chart.SortInfo=this.SortInfo;
this.ChartPaint[0]=chart;
//页脚
if (option && option.PageInfo===true)
{
var pageInfoChart=new ChartReportPageInfo();
pageInfoChart.Frame=this.Frame;
pageInfoChart.ChartBorder=this.Frame.ChartBorder;
pageInfoChart.Canvas=this.Canvas;
pageInfoChart.Report=chart;
this.ChartPaint[1]=pageInfoChart;
}
if (option)
{
if (IFrameSplitOperator.IsBool(option.IsShowHeader)) chart.IsShowHeader=option.IsShowHeader; //是否显示表头
if (IFrameSplitOperator.IsNumber(option.FixedColumn)) chart.FixedColumn=option.FixedColumn; //固定列
if (IFrameSplitOperator.IsNumber(option.BorderLine)) this.Frame.BorderLine=option.BorderLine; //边框
if (IFrameSplitOperator.IsNumber(option.FixedRowCount)) chart.FixedRowCount=option.FixedRowCount; //固定行
if (IFrameSplitOperator.IsBool(option.ItemBorder)) chart.IsDrawBorder=option.ItemBorder; //单元格边框
if (IFrameSplitOperator.IsNonEmptyArray(option.FixedSymbol))
{
chart.FixedRowCount=0;
this.FixedRowData.Type=1;
this.FixedRowData.Symbol=[];
var aryData=option.FixedSymbol;
for(var i=0; i<aryData.length; ++i)
{
var item=aryData[i];
this.FixedRowData.Symbol.push(item.Symbol);
++chart.FixedRowCount;
}
}
}
}
this.Draw=function()
{
if (this.UIElement.Width<=0 || this.UIElement.Height<=0) return;
this.Canvas.clearRect(0,0,this.UIElement.Width,this.UIElement.Height);
if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash)
{
this.Frame.Draw( { IsEnableSplash:this.ChartSplashPaint.IsEnableSplash} );
this.ChartSplashPaint.Draw();
return;
}
this.Frame.Draw();
this.Frame.DrawLogo();
//框架内图形
for(var i=0;i<this.ChartPaint.length;++i)
{
var item=this.ChartPaint[i];
if (item.IsDrawFirst)
item.Draw();
}
for(var i=0; i<this.ChartPaint.length; ++i)
{
var item=this.ChartPaint[i];
if (!item.IsDrawFirst)
item.Draw();
}
this.Canvas.draw(false);
}
this.ResetReportStatus=function()
{
this.Data.XOffset=0;
this.Data.YOffset=0;
}
this.ResetReportSelectStatus=function()
{
var chart=this.GetReportChart();
if (chart)
{
chart.SelectedRow=-1;
chart.SelectedFixedRow=-1;
}
}
this.ClearData=function()
{
this.SourceData.Data=[];
this.Data.Data=[];
}
this.ResetSortStatus=function()
{
this.SortInfo.Field=-1;
this.SortInfo.Sort=0;
}
//设置股票列表
this.SetSymbolList=function(arySymbol, option)
{
this.ClearData();
this.ResetReportStatus();
this.ResetSortStatus();
if (IFrameSplitOperator.IsNonEmptyArray(arySymbol))
{
for(var i=0;i<arySymbol.length;++i)
{
this.Data.Data.push(arySymbol[i]);
}
}
var chart=this.ChartPaint[0];
if (chart) chart.Data=this.Data;
this.Draw();
}
this.ChangeSymbol=function(symbol, option)
{
this.Symbol=symbol;
this.ClearData();
this.ResetReportStatus();
this.ResetSortStatus();
this.ResetReportSelectStatus();
if (option)
{
if (IFrameSplitOperator.IsNumber(option.TabSelected))
{
var chartTab=this.GetTabChart();
if (chartTab) chartTab.SelectedTabIndex=option.TabSelected;
}
if (Array.isArray(option.FixedSymbol))
{
var chart=this.GetReportChart();
if (chart)
{
chart.FixedRowCount=0;
this.FixedRowData.Type=1;
this.FixedRowData.Symbol=[];
var aryData=option.FixedSymbol;
for(var i=0; i<aryData.length; ++i)
{
var item=aryData[i];
this.FixedRowData.Symbol.push(item.Symbol);
++chart.FixedRowCount;
}
this.SetSizeChange(true);
}
}
if (option.SortInfo)
{
var item=option.SortInfo;
if (IFrameSplitOperator.IsNumber(item.Field)) this.SortInfo.Field=item.Field;
if (IFrameSplitOperator.IsNumber(item.Sort)) this.SortInfo.Sort=item.Sort;
}
}
this.RequestMemberListData();
}
this.RequestMemberListData=function()
{
//this.ChartSplashPaint.SetTitle(this.SplashTitle.MemberList);
//this.ChartSplashPaint.EnableSplash(true);
//this.Draw();
var self=this;
if (this.NetworkFilter)
{
var obj=
{
Name:'JSReportChartContainer::RequestMemberListData', //类名::
Explain:'板块成分数据',
Request:{ Data: { symbol: this.Symbol } },
Self:this,
PreventDefault:false
};
if (this.SortInfo.Field>=0 && this.SortInfo.Sort>0)
{
var reportChart=this.GetReportChart();
if (reportChart)
{
var column=reportChart.Column[this.SortInfo.Field];
obj.Sort={ Column:column, Field:this.SortInfo.Field, Sort:this.SortInfo.Sort} ;
}
}
this.NetworkFilter(obj, function(data)
{
self.ChartSplashPaint.EnableSplash(false);
self.RecvMemberListData(data);
});
if (obj.PreventDefault==true) return; //已被上层替换,不调用默认的网络请求
}
throw { Name:'JSReportChartContainer::RequestMemberListData', Error:'(板块成分数据)不提供内置测试数据' };
}
this.RecvMemberListData=function(recvData)
{
this.ClearData();
if (IFrameSplitOperator.IsNonEmptyArray(recvData.data))
{
for(var i=0;i<recvData.data.length;++i)
{
this.Data.Data.push(recvData.data[i]);
this.SourceData.Data.push(recvData.data[i]);
}
}
this.Draw();
this.UpdateStockData();
}
this.AutoUpdateEvent=function(bStart, explain) //自定更新事件, 是给websocket使用
{
var eventID=bStart ? JSCHART_EVENT_ID.RECV_START_AUTOUPDATE:JSCHART_EVENT_ID.RECV_STOP_AUTOUPDATE;
if (!this.mapEvent.has(eventID)) return;
var self=this;
var event=this.mapEvent.get(eventID);
var data={ Stock:{ Symbol:this.Symbol, Name:this.Name, DayCount:this.DayCount }, Explain: explain };
if (bStart)
{
data.Callback=function(data) //数据到达更新回调
{
self.RecvDealUpdateData(data);
}
}
event.Callback(event,data,this);
}
//下载码表
this.RequestStockListData=function(option)
{
this.ChartSplashPaint.SetTitle(this.SplashTitle.StockList);
this.ChartSplashPaint.EnableSplash(true);
this.Draw();
var self=this;
if (this.NetworkFilter)
{
var obj=
{
Name:'JSReportChartContainer::RequestStockListData', //类名::
Explain:'码表数据',
Self:this,
PreventDefault:false
};
this.NetworkFilter(obj, function(data)
{
self.ChartSplashPaint.EnableSplash(false);
self.RecvStockListData(data,option);
});
if (obj.PreventDefault==true) return; //已被上层替换,不调用默认的网络请求
}
throw { Name:'JSReportChartContainer::RequestStockListData', Error:'(码表数据)不提供内置测试数据' };
}
this.RecvStockListData=function(data, option)
{
if (IFrameSplitOperator.IsNonEmptyArray(data.data))
{
//0=证券代码 1=股票名称
for(var i=0;i<data.data.length;++i)
{
var item=data.data[i];
var symbol=item[0];
var stock=null;
if (this.MapStockData.has(symbol))
{
stock=this.MapStockData.get(symbol);
}
else
{
stock=new HQReportItem();
stock.OriginalSymbol=symbol;
this.MapStockData.set(symbol, stock);
}
stock.Symbol=this.GetSymbolNoSuffix(symbol);
stock.Name=item[1];
this.ReadStockJsonData(stock, item);
}
}
if (option && option.Callback)
{
option.Callback();
return;
}
this.Draw();
this.UpdateStockData();
}
//更新股票数据
this.UpdateMapStockData=function(data)
{
if (!data || !IFrameSplitOperator.IsNonEmptyArray(data.data)) return;
//0=证券代码 1=股票名称
for(var i=0;i<data.data.length;++i)
{
var item=data.data[i];
var symbol=item[0];
var stock=null;
if (this.MapStockData.has(symbol))
{
stock=this.MapStockData.get(symbol);
}
else
{
stock=new HQReportItem();
this.MapStockData.set(symbol, stock);
}
stock.Symbol=this.GetSymbolNoSuffix(symbol);
stock.Name=item[1];
this.ReadStockJsonData(stock, item);
}
}
//获取个股数据
this.GetStockData=function(symbol)
{
if (!this.MapStockData) return null;
if (!this.MapStockData.has(symbol)) return null;
return this.MapStockData.get(symbol);
}
this.GetBlockData=function(symbol)
{
if (!this.BlockData) return null;
if (!this.BlockData.has(symbol)) return null;
return this.BlockData.get(symbol);
}
//delay=是否延迟
this.DelayUpdateStockData=function()
{
if (this.DelayUpdateTimer!=null)
{
clearTimeout(this.DelayUpdateTimer);
this.DelayUpdateTimer = null;
}
var frequency=this.DelayUpdateFrequency;
this.DelayUpdateTimer=setTimeout(()=>
{
this.UpdateStockData();
},frequency);
}
this.UpdateStockData=function()
{
if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
var chart=this.ChartPaint[0];
if (!chart) return;
if (this.SortInfo && this.SortInfo.Field>=0 && this.SortInfo.Sort>0)
{
var column=chart.Column[this.SortInfo.Field];
if (column.Sort==2)
{
this.RequestStockSortData(column, this.SortInfo.Field, this.SortInfo.Sort); //远程排序
return;
}
}
var arySymbol=chart.ShowSymbol;
if (!IFrameSplitOperator.IsNonEmptyArray(arySymbol)) return;
this.RequestStockData(arySymbol);
}
//下载股票数据
this.RequestStockData=function(arySymbol)
{
var self=this;
if (this.NetworkFilter)
{
var obj=
{
Name:'JSDealChartContainer::RequestStockData', //类名::函数名
Explain:'报价列表股票数据',
Request:{ Data: { stocks: arySymbol } },
Self:this,
PreventDefault:false
};
this.NetworkFilter(obj, function(data)
{
self.RecvStockData(data);
self.AutoUpdate();
});
if (obj.PreventDefault==true) return;
}
throw { Name:'JSReportChartContainer::RequestStockData', Error:'(报价列表股票数据)不提供内置测试数据' };
}
this.RecvStockData=function(data)
{
var setUpdateSymbol=new Set(); //更新的股票列表
if (IFrameSplitOperator.IsNonEmptyArray(data.data))
{
//0=证券代码 1=股票名称 2=昨收 3=开 4=高 5=低 6=收 7=成交量 8=成交金额, 9=买价 10=买量 11=卖价 12=卖量 13=均价 14=流通股 15=总股本
for(var i=0;i<data.data.length;++i)
{
var item=data.data[i];
var symbol=item[0];
if (!symbol) continue;
var stock=null;
if (this.MapStockData.has(symbol))
{
stock=this.MapStockData.get(symbol);
}
else
{
stock=new HQReportItem();
stock.OriginalSymbol=symbol;
stock.Symbol=this.GetSymbolNoSuffix(symbol);
this.MapStockData.set(symbol, stock);
}
this.ReadStockJsonData(stock, item);
if (!setUpdateSymbol.has(symbol)) setUpdateSymbol.add(symbol);
}
}
var chart=this.ChartPaint[0];
if (!chart) return;
//更新的股票在当前页面,需要重绘
var bUpdate=false;
var aryStock=chart.ShowSymbol;
for(var i=0;i<aryStock.length;++i)
{
if (setUpdateSymbol.has(aryStock[i].Symbol))
{
bUpdate=true;
break;
}
}
if (bUpdate) this.Draw();
}
//读取单条股票json数据
this.ReadStockJsonData=function(stock, item)
{
//0=证券代码 1=股票名称 2=昨收 3=开 4=高 5=低 6=收 7=成交量 8=成交金额, 9=买价 10=买量 11=卖价 12=卖量 13=均价 14=流通股 15=总股本 16=涨停价 17=跌停价
//18=内盘 19=外盘 20=现量 21=涨幅% 22=涨跌 23=换手率% 24=振幅% 25=流通市值 26=总市值
//30=全局扩展数据 31=当前板块扩展数据
if (IFrameSplitOperator.IsString(item[1])) stock.Name=item[1];
if (IFrameSplitOperator.IsNumber(item[2])) stock.YClose=item[2];
if (IFrameSplitOperator.IsNumber(item[3])) stock.Open=item[3];
if (IFrameSplitOperator.IsNumber(item[4])) stock.High=item[4];
if (IFrameSplitOperator.IsNumber(item[5])) stock.Low=item[5];
if (IFrameSplitOperator.IsNumber(item[6])) stock.Price=item[6];
if (IFrameSplitOperator.IsNumber(item[7])) stock.Vol=item[7];
if (IFrameSplitOperator.IsNumber(item[8])) stock.Amount=item[8];
if (IFrameSplitOperator.IsNumber(item[9])) stock.BuyPrice=item[9];
if (IFrameSplitOperator.IsNumber(item[10])) stock.BuyVol=item[10];
if (IFrameSplitOperator.IsNumber(item[11])) stock.SellPrice=item[11];
if (IFrameSplitOperator.IsNumber(item[12])) stock.SellVol=item[12];
if (IFrameSplitOperator.IsNumber(item[13])) stock.AvPrice=item[13]; //均价
if (IFrameSplitOperator.IsNumber(item[14])) stock.OutShares=item[14]; //流通股
if (IFrameSplitOperator.IsNumber(item[15])) stock.TotalShares=item[15]; //总股本
if (IFrameSplitOperator.IsNumber(item[16])) stock.LimitHigh=item[16]; //涨停价
if (IFrameSplitOperator.IsNumber(item[17])) stock.LimitLow=item[17]; //跌停价
if (IFrameSplitOperator.IsNumber(item[18])) stock.VolIn=item[18]; //内盘
if (IFrameSplitOperator.IsNumber(item[19])) stock.VolOut=item[19]; //外盘
if (IFrameSplitOperator.IsNumber(item[20])) stock.DealNum=item[20]; //现量
if (IFrameSplitOperator.IsNumber(item[21])) stock.Increase=item[21]; //涨幅%
if (IFrameSplitOperator.IsNumber(item[22])) stock.UpDown=item[22]; //涨跌
if (IFrameSplitOperator.IsNumber(item[23])) stock.Exchange=item[23]; //换手率%
if (IFrameSplitOperator.IsNumber(item[24])) stock.Amplitude=item[24]; //振幅%
if (IFrameSplitOperator.IsNumber(item[25])) stock.CircMarketValue=item[25]; //流通市值
if (IFrameSplitOperator.IsNumber(item[26])) stock.MarketValue=item[26]; //总市值
//衍生数据计算
if (!IFrameSplitOperator.IsNumber(item[21])) //涨幅%
{
if (IFrameSplitOperator.IsNumber(stock.Price) && IFrameSplitOperator.IsNumber(stock.YClose) && stock.YClose!=0)
stock.Increase=(stock.Price-stock.YClose)/stock.YClose*100;
}
if (!IFrameSplitOperator.IsNumber(item[22])) //涨跌
{
if (IFrameSplitOperator.IsNumber(stock.Price) && IFrameSplitOperator.IsNumber(stock.YClose))
stock.UpDown=stock.Price-stock.YClose;
}
if (!IFrameSplitOperator.IsNumber(item[23])) //换手率%
{
if (IFrameSplitOperator.IsNumber(stock.Vol) && IFrameSplitOperator.IsNumber(stock.OutShares) && stock.OutShares>0)
stock.Exchange=stock.Vol/stock.OutShares*100;
}
if (!IFrameSplitOperator.IsNumber(item[24])) //振幅%
{
if (IFrameSplitOperator.IsNumber(stock.High) && IFrameSplitOperator.IsNumber(stock.Low) && IFrameSplitOperator.IsNumber(stock.YClose) && stock.YClose!=0)
stock.Amplitude=(stock.High-stock.Low)/stock.YClose*100;
}
if (!IFrameSplitOperator.IsNumber(item[25])) //流通市值
{
if (IFrameSplitOperator.IsNumber(stock.OutShares) && IFrameSplitOperator.IsNumber(stock.Price))
stock.CircMarketValue=stock.OutShares*stock.Price;
}
if (!IFrameSplitOperator.IsNumber(item[26])) //总市值
{
if (IFrameSplitOperator.IsNumber(stock.TotalShares) && IFrameSplitOperator.IsNumber(stock.Price))
stock.MarketValue=stock.TotalShares*stock.Price;
}
if (item[30]) stock.ExtendData=item[30]; //30扩展数据
if (item[31]) this.BlockData.set(stock.OriginalSymbol,item[31]); //31=当前板块数据
if (item[32]) stock.CloseLine=item[32]; //32=收盘价线
}
this.GetSymbolNoSuffix=function(symbol)
{
var index=symbol.lastIndexOf(".");
if (index>0)
return symbol.substring(0,index);
else
return symbol;
}
this.CancelAutoUpdate=function() //关闭停止更新
{
if (this.AutoUpdateTimer)
{
clearTimeout(this.AutoUpdateTimer);
this.AutoUpdateTimer = null;
}
}
this.AutoUpdate=function(waitTime) //waitTime 更新时间
{
this.CancelAutoUpdate();