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,1452 @@
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
+ 封装成交明细表格控件 (H5版本)
11
+ */
12
+
13
+
14
+ function JSDealChart(divElement)
15
+ {
16
+ this.DivElement=divElement;
17
+ this.JSChartContainer; //表格控件
18
+
19
+ //h5 canvas
20
+ this.CanvasElement=document.createElement("canvas");
21
+ this.CanvasElement.className='jsdeallist-drawing';
22
+ this.CanvasElement.id=Guid();
23
+ this.CanvasElement.setAttribute("tabindex",0);
24
+ if (this.CanvasElement.style) this.CanvasElement.style.outline='none';
25
+ if(divElement.hasChildNodes())
26
+ {
27
+ JSConsole.Chart.Log("[JSDealChart::JSDealList] divElement hasChildNodes", divElement.childNodes);
28
+ }
29
+ divElement.appendChild(this.CanvasElement);
30
+
31
+
32
+ this.OnSize=function()
33
+ {
34
+ //画布大小通过div获取
35
+ var height=parseInt(this.DivElement.style.height.replace("px",""));
36
+ this.CanvasElement.height=height;
37
+ this.CanvasElement.width=parseInt(this.DivElement.style.width.replace("px",""));
38
+ this.CanvasElement.style.width=this.CanvasElement.width+'px';
39
+ this.CanvasElement.style.height=this.CanvasElement.height+'px';
40
+
41
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
42
+ this.CanvasElement.height*=pixelTatio;
43
+ this.CanvasElement.width*=pixelTatio;
44
+
45
+ JSConsole.Chart.Log(`[JSDealChart::OnSize] devicePixelRatio=${window.devicePixelRatio}, height=${this.CanvasElement.height}, width=${this.CanvasElement.width}`);
46
+
47
+ if (this.JSChartContainer && this.JSChartContainer.OnSize)
48
+ {
49
+ this.JSChartContainer.OnSize();
50
+ }
51
+ }
52
+
53
+ this.SetOption=function(option)
54
+ {
55
+ var chart=this.CreateJSDealChartContainer(option);
56
+
57
+ if (!chart) return false;
58
+
59
+ if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
60
+
61
+ this.JSChartContainer=chart;
62
+ this.DivElement.JSChart=this; //div中保存一份
63
+ if (!option.Symbol)
64
+ {
65
+ chart.Draw();
66
+ }
67
+ else
68
+ {
69
+ chart.ChangeSymbol(option.Symbol);
70
+ }
71
+ }
72
+
73
+ this.CreateJSDealChartContainer=function(option)
74
+ {
75
+ var chart=new JSDealChartContainer(this.CanvasElement);
76
+ chart.Create(option);
77
+
78
+ if (option.NetworkFilter) chart.NetworkFilter=option.NetworkFilter;
79
+ if (IFrameSplitOperator.IsNonEmptyArray(option.Column)) chart.SetColumn(option.Column);
80
+
81
+ if (IFrameSplitOperator.IsNumber(option.ShowOrder)) chart.ChartPaint[0].ShowOrder=option.ShowOrder;
82
+
83
+ this.SetChartBorder(chart, option);
84
+
85
+ //是否自动更新
86
+ if (option.IsAutoUpdate!=null) chart.IsAutoUpdate=option.IsAutoUpdate;
87
+ if (option.AutoUpdateFrequency>0) chart.AutoUpdateFrequency=option.AutoUpdateFrequency;
88
+ if (IFrameSplitOperator.IsBool(option.EnableFilter)) chart.EnableFilter=option.EnableFilter;
89
+
90
+ //注册事件
91
+ if (option.EventCallback)
92
+ {
93
+ for(var i=0;i<option.EventCallback.length;++i)
94
+ {
95
+ var item=option.EventCallback[i];
96
+ chart.AddEventCallback(item);
97
+ }
98
+ }
99
+
100
+ return chart;
101
+ }
102
+
103
+ this.SetChartBorder=function(chart, option)
104
+ {
105
+ if (!option.Border) return;
106
+
107
+ var item=option.Border;
108
+ if (IFrameSplitOperator.IsNumber(option.Border.Left)) chart.Frame.ChartBorder.Left=option.Border.Left;
109
+ if (IFrameSplitOperator.IsNumber(option.Border.Right)) chart.Frame.ChartBorder.Right=option.Border.Right;
110
+ if (IFrameSplitOperator.IsNumber(option.Border.Top)) chart.Frame.ChartBorder.Top=option.Border.Top;
111
+ if (IFrameSplitOperator.IsNumber(option.Border.Bottom)) chart.Frame.ChartBorder.Bottom=option.Border.Bottom;
112
+
113
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
114
+ chart.Frame.ChartBorder.Left*=pixelTatio;
115
+ chart.Frame.ChartBorder.Right*=pixelTatio;
116
+ chart.Frame.ChartBorder.Top*=pixelTatio;
117
+ chart.Frame.ChartBorder.Bottom*=pixelTatio;
118
+ }
119
+
120
+ /////////////////////////////////////////////////////////////////////////////
121
+ //对外接口
122
+
123
+ //切换股票代码接口
124
+ this.ChangeSymbol=function(symbol, option)
125
+ {
126
+ if (this.JSChartContainer) this.JSChartContainer.ChangeSymbol(symbol,option);
127
+ }
128
+
129
+ this.SetColumn=function(aryColumn, option)
130
+ {
131
+ if (this.JSChartContainer) this.JSChartContainer.SetColumn(aryColumn,option);
132
+ }
133
+
134
+ this.EnableFilter=function(bEnable, option) //启动|关闭筛选
135
+ {
136
+ if (this.JSChartContainer) this.JSChartContainer.EnableFilter(bEnable, option);
137
+ }
138
+
139
+ //事件回调
140
+ this.AddEventCallback=function(obj)
141
+ {
142
+ if(this.JSChartContainer && typeof(this.JSChartContainer.AddEventCallback)=='function')
143
+ {
144
+ JSConsole.Chart.Log('[JSDealChart:AddEventCallback] obj=', obj);
145
+ this.JSChartContainer.AddEventCallback(obj);
146
+ }
147
+ }
148
+
149
+ //重新加载配置
150
+ this.ReloadResource=function(option)
151
+ {
152
+ if(this.JSChartContainer && typeof(this.JSChartContainer.ReloadResource)=='function')
153
+ {
154
+ JSConsole.Chart.Log('[JSDealChart:ReloadResource] ');
155
+ this.JSChartContainer.ReloadResource(option);
156
+ }
157
+ }
158
+ }
159
+
160
+
161
+ JSDealChart.Init=function(divElement)
162
+ {
163
+ var jsChartControl=new JSDealChart(divElement);
164
+ jsChartControl.OnSize();
165
+
166
+ return jsChartControl;
167
+ }
168
+
169
+
170
+ function JSDealChartContainer(uielement)
171
+ {
172
+ this.ClassName='JSDealChartContainer';
173
+ this.Frame; //框架画法
174
+ this.ChartPaint=[]; //图形画法
175
+ this.ChartSplashPaint=null; //等待提示
176
+ this.LoadDataSplashTitle="数据加载中"; //下载数据提示信息
177
+ this.Canvas=uielement.getContext("2d"); //画布
178
+ this.ShowCanvas=null;
179
+
180
+ this.Symbol;
181
+ this.Name;
182
+ this.TradeDate;
183
+ this.NetworkFilter; //数据回调接口
184
+ this.Data={ DataOffset:0, Data:[] }; //分笔数据
185
+ this.SourceData={DataOffset:0, Data:[] }; //原始分笔数据
186
+ this.IsShowLastPage=true; //显示最后一页
187
+
188
+ //事件回调
189
+ this.mapEvent=new Map(); //通知外部调用 key:JSCHART_EVENT_ID value:{Callback:回调,}
190
+
191
+ this.AutoUpdateTimer=null;
192
+ this.AutoUpdateFrequency=15000; //更新频率
193
+
194
+ this.LoadDataSplashTitle="数据加载中"; //下载数据提示信息
195
+
196
+ this.UIElement=uielement;
197
+ this.LastPoint=new Point(); //鼠标位置
198
+
199
+ this.IsDestroy=false; //是否已经销毁了
200
+
201
+ this.ChartDestory=function() //销毁
202
+ {
203
+ this.IsDestroy=true;
204
+ this.StopAutoUpdate();
205
+ }
206
+
207
+ this.EnableFilterData=false; //是否启动筛选
208
+
209
+ //筛选数据
210
+ this.FilterData=function(aryDeal)
211
+ {
212
+ if (!this.EnableFilterData) return aryDeal;
213
+
214
+ //过滤由外部处理
215
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_FILTER_DEAL_DATA);
216
+ if (!event || !event.Callback) return aryDeal;
217
+
218
+ var sendData={ Data:aryDeal, Result:[] }; //{ Data:原始数据, Result:[] 过滤以后的数据 }
219
+ event.Callback(event,sendData,this);
220
+
221
+ return sendData.Result;
222
+ }
223
+
224
+
225
+ this.EnableFilter=function(bEnable, option) //启动|关闭筛选
226
+ {
227
+ this.EnableFilterData=bEnable;
228
+
229
+ this.Data.Data=this.FilterData(this.SourceData.Data);
230
+ this.Data.DataOffset=0;
231
+
232
+ if (option)
233
+ {
234
+ if (option.GotoLastPage==true) this.GotoLastPage();
235
+ if (option.Redraw==true) this.Draw();
236
+ }
237
+ }
238
+
239
+ this.CloneArray=function(aryData)
240
+ {
241
+ var data=[];
242
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return data;
243
+
244
+ for(var i=0;i<aryData.length;++i)
245
+ {
246
+ data.push(aryData[i]);
247
+ }
248
+
249
+ return data;
250
+ }
251
+
252
+ //创建
253
+ //windowCount 窗口个数
254
+ this.Create=function(option)
255
+ {
256
+ this.UIElement.JSChartContainer=this;
257
+
258
+ //创建等待提示
259
+ this.ChartSplashPaint = new ChartSplashPaint();
260
+ this.ChartSplashPaint.Canvas = this.Canvas;
261
+ this.ChartSplashPaint.SetTitle(this.LoadDataSplashTitle);
262
+
263
+ //创建框架
264
+ this.Frame=new JSDealFrame();
265
+ this.Frame.ChartBorder=new ChartBorder();
266
+ this.Frame.ChartBorder.UIElement=this.UIElement;
267
+ this.Frame.ChartBorder.Top=30;
268
+ this.Frame.ChartBorder.Left=5;
269
+ this.Frame.ChartBorder.Bottom=20;
270
+ this.Frame.Canvas=this.Canvas;
271
+
272
+ this.ChartSplashPaint.Frame = this.Frame;
273
+
274
+ //创建表格
275
+ var chart=new ChartDealList();
276
+ chart.Frame=this.Frame;
277
+ chart.ChartBorder=this.Frame.ChartBorder;
278
+ chart.Canvas=this.Canvas;
279
+ chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
280
+ this.ChartPaint[0]=chart;
281
+
282
+ if (option)
283
+ {
284
+ if (IFrameSplitOperator.IsBool(option.IsSingleTable)) chart.IsSingleTable=option.IsSingleTable; //单表模式
285
+ if (IFrameSplitOperator.IsBool(option.IsShowHeader)) chart.IsShowHeader=option.IsShowHeader; //是否显示表头
286
+ if (IFrameSplitOperator.IsBool(option.IsShowLastPage)) this.IsShowLastPage=option.IsShowLastPage; //是否显示最后一页
287
+ if (IFrameSplitOperator.IsNumber(option.BorderLine)) this.Frame.BorderLine=option.BorderLine; //边框
288
+ }
289
+
290
+ var bRegisterKeydown=true;
291
+ var bRegisterWheel=true;
292
+
293
+ if (option)
294
+ {
295
+ if (option.KeyDown===false)
296
+ {
297
+ bRegisterKeydown=false;
298
+ JSConsole.Chart.Log('[JSDealChartContainer::Create] not register keydown event.');
299
+ }
300
+
301
+ if (option.Wheel===false)
302
+ {
303
+ bRegisterWheel=false;
304
+ JSConsole.Chart.Log('[JSDealChartContainer::Create] not register wheel event.');
305
+ }
306
+ }
307
+
308
+ if (bRegisterKeydown) this.UIElement.addEventListener("keydown", (e)=>{ this.OnKeyDown(e); }, true); //键盘消息
309
+ if (bRegisterWheel) this.UIElement.addEventListener("wheel", (e)=>{ this.OnWheel(e); }, true); //上下滚动消息
310
+ }
311
+
312
+ this.Draw=function()
313
+ {
314
+ if (this.UIElement.width<=0 || this.UIElement.height<=0) return;
315
+
316
+ this.Canvas.clearRect(0,0,this.UIElement.width,this.UIElement.height);
317
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
318
+ this.Canvas.lineWidth=pixelTatio; //手机端需要根据分辨率比调整线段宽度
319
+
320
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash)
321
+ {
322
+ this.Frame.Draw( { IsEnableSplash:this.ChartSplashPaint.IsEnableSplash} );
323
+ this.ChartSplashPaint.Draw();
324
+ return;
325
+ }
326
+
327
+ this.Frame.Draw();
328
+ this.Frame.DrawLogo();
329
+
330
+ //框架内图形
331
+ for(var i=0;i<this.ChartPaint.length;++i)
332
+ {
333
+ var item=this.ChartPaint[i];
334
+ if (item.IsDrawFirst)
335
+ item.Draw();
336
+ }
337
+
338
+ for(var i=0; i<this.ChartPaint.length; ++i)
339
+ {
340
+ var item=this.ChartPaint[i];
341
+ if (!item.IsDrawFirst)
342
+ item.Draw();
343
+ }
344
+ }
345
+
346
+ this.ChangeSymbol=function(symbol, option)
347
+ {
348
+ this.Symbol=symbol;
349
+ this.Data=null;
350
+ this.SourceData=null;
351
+
352
+ var chart=this.ChartPaint[0];
353
+ if (chart) chart.Data=null;
354
+
355
+ if (option && IFrameSplitOperator.IsNumber(option.TradeDate))
356
+ this.TradeDate=option.TradeDate;
357
+
358
+ if (!this.Symbol)
359
+ {
360
+ this.Draw();
361
+ return;
362
+ }
363
+
364
+ this.RequestDealData();
365
+ }
366
+
367
+ this.CancelAutoUpdate=function() //关闭停止更新
368
+ {
369
+ if (typeof (this.AutoUpdateTimer) == 'number')
370
+ {
371
+ clearTimeout(this.AutoUpdateTimer);
372
+ this.AutoUpdateTimer = null;
373
+ }
374
+ }
375
+
376
+ this.AutoUpdateEvent=function(bStart, explain) //自定更新事件, 是给websocket使用
377
+ {
378
+ var eventID=bStart ? JSCHART_EVENT_ID.RECV_START_AUTOUPDATE:JSCHART_EVENT_ID.RECV_STOP_AUTOUPDATE;
379
+ if (!this.mapEvent.has(eventID)) return;
380
+
381
+ var self=this;
382
+ var event=this.mapEvent.get(eventID);
383
+ var data={ Stock:{ Symbol:this.Symbol, Name:this.Name, DayCount:this.DayCount }, Explain: explain };
384
+ if (bStart)
385
+ {
386
+ data.Callback=function(data) //数据到达更新回调
387
+ {
388
+ self.RecvDealUpdateData(data);
389
+ }
390
+ }
391
+ event.Callback(event,data,this);
392
+ }
393
+
394
+ //全量数据下载
395
+ this.RequestDealData=function()
396
+ {
397
+ this.ChartSplashPaint.SetTitle(this.LoadDataSplashTitle);
398
+ this.ChartSplashPaint.EnableSplash(true);
399
+ this.Draw();
400
+
401
+ var self=this;
402
+ if (this.NetworkFilter)
403
+ {
404
+ var obj=
405
+ {
406
+ Name:'JSDealChartContainer::RequestDealData', //类名::
407
+ Explain:'成交明细',
408
+ Request:{ Data: { symbol:self.Symbol, tradeDate:self.TradeDate } },
409
+ Self:this,
410
+ PreventDefault:false
411
+ };
412
+ this.NetworkFilter(obj, function(data)
413
+ {
414
+ self.ChartSplashPaint.EnableSplash(false);
415
+ self.RecvDealData(data);
416
+ self.AutoUpdateEvent(true,'JSDealChartContainer::RequestDealData');
417
+ self.AutoUpdate();
418
+ });
419
+
420
+ if (obj.PreventDefault==true) return; //已被上层替换,不调用默认的网络请求
421
+ }
422
+
423
+ var cacheUrl=`${g_JSChartResource.CacheDomain}/cache/dealday/today/${this.Symbol}.json`;
424
+
425
+ JSNetwork.HttpRequest({
426
+ url: cacheUrl,
427
+ type:"get",
428
+ dataType: "json",
429
+ async:true,
430
+ success: function (data)
431
+ {
432
+ self.ChartSplashPaint.EnableSplash(false);
433
+ self.RecvDealData(data);
434
+ self.AutoUpdate(1);
435
+ },
436
+ error: function(http,e)
437
+ {
438
+ self.ChartSplashPaint.EnableSplash(false);
439
+ self.AutoUpdate();
440
+ //self.RecvError(http,e,param);;
441
+ }
442
+ });
443
+ }
444
+
445
+ this.RecvDealData=function(data)
446
+ {
447
+ var aryDeal=JSDealChartContainer.JsonDataToDealData(data);
448
+ this.SourceData={ DataOffset:0, Data:aryDeal };
449
+ this.Data={ DataOffset:0, Data:this.FilterData(this.CloneArray(aryDeal)) };
450
+
451
+ this.Symbol=data.symbol;
452
+ this.Name=data.name;
453
+
454
+ var chart=this.ChartPaint[0];
455
+ chart.Data=this.Data;
456
+ chart.Symbol=this.Symbol;
457
+ chart.YClose=data.yclose;
458
+ chart.Open=data.open;
459
+
460
+ if (this.IsShowLastPage) //显示最后一屏
461
+ {
462
+ var pageSize=chart.GetPageSize(true);
463
+ var offset=aryDeal.length-pageSize;
464
+ if (offset<0) offset=0;
465
+ this.Data.DataOffset=offset;
466
+ }
467
+
468
+ this.Draw();
469
+ }
470
+
471
+ //增量数据下载
472
+ this.RequestDealUpdateData=function()
473
+ {
474
+ var self=this;
475
+
476
+ if (this.NetworkFilter)
477
+ {
478
+ var obj=
479
+ {
480
+ Name:'JSDealChartContainer::RequestDealUpdateData', //类名::函数名
481
+ Explain:'增量成交明细',
482
+ Request:{ Data: { symbol: self.Symbol } },
483
+ Self:this,
484
+ PreventDefault:false
485
+ };
486
+
487
+ if (this.Data && IFrameSplitOperator.IsNonEmptyArray(this.Data.Data))
488
+ {
489
+ var lastItem=this.Data.Data[this.Data.Data.length-1]; //最后一条数据
490
+ obj.LastItem=lastItem;
491
+ }
492
+
493
+ this.NetworkFilter(obj, function(data)
494
+ {
495
+ self.RecvDealUpdateData(data);
496
+ self.AutoUpdate();
497
+ });
498
+
499
+ if (obj.PreventDefault==true) return;
500
+ }
501
+ }
502
+
503
+ this.RecvDealUpdateData=function(data)
504
+ {
505
+ var aryDeal=JSDealChartContainer.JsonDataToDealData(data);
506
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryDeal)) return;
507
+
508
+ if (data.UpdateType===1) //全量更新
509
+ {
510
+ this.SourceData.Data=aryDeal;
511
+ this.Data.Data=this.FilterData(this.CloneArray(aryDeal));
512
+ if (this.Data.DataOffset>= this.Data.Data.length) this.Data.DataOffset=0;
513
+ }
514
+ else
515
+ {
516
+ this.AddDealData(this.SourceData, aryDeal);
517
+ this.AddDealData(this.Data,this.FilterData(aryDeal));
518
+ }
519
+
520
+ this.Draw();
521
+ }
522
+
523
+ this.AddDealData=function(dealData, aryNewData)
524
+ {
525
+ if (!dealData.Data) //原来是空的
526
+ {
527
+ dealData.Data=aryNewData;
528
+ }
529
+ else
530
+ {
531
+ var pageSize=0;
532
+ var chart=this.ChartPaint[0];
533
+ if (chart) pageSize=chart.GetPageSize();
534
+
535
+ for(var i=0;i<aryNewData.length;++i)
536
+ {
537
+ dealData.Data.push(aryNewData[i]);
538
+
539
+ if (dealData.DataOffset+pageSize<dealData.Data.length)
540
+ ++dealData.DataOffset;
541
+ }
542
+ }
543
+ }
544
+
545
+ this.AutoUpdate=function(waitTime) //waitTime 更新时间
546
+ {
547
+ this.CancelAutoUpdate();
548
+ if (!this.IsAutoUpdate) return;
549
+ if (!this.Symbol) return;
550
+
551
+ var self = this;
552
+ var marketStatus=MARKET_SUFFIX_NAME.GetMarketStatus(this.Symbol);
553
+ if (marketStatus==0 || marketStatus==3) return; //闭市,盘后
554
+
555
+ var frequency=this.AutoUpdateFrequency;
556
+ if (marketStatus==1) //盘前
557
+ {
558
+ this.AutoUpdateTimer=setTimeout(function()
559
+ {
560
+ self.AutoUpdate();
561
+ },frequency);
562
+ }
563
+ else if (marketStatus==2) //盘中
564
+ {
565
+ this.AutoUpdateTimer=setTimeout(function()
566
+ {
567
+ self.RequestDealUpdateData();
568
+ },frequency);
569
+ }
570
+ }
571
+
572
+ this.StopAutoUpdate=function()
573
+ {
574
+ this.CancelAutoUpdate();
575
+ this.AutoUpdateEvent(false,'JSDealChartContainer::StopAutoUpdate');
576
+ if (!this.IsAutoUpdate) return;
577
+ this.IsAutoUpdate=false;
578
+ }
579
+
580
+ //设置事件回调
581
+ //{event:事件id, callback:回调函数}
582
+ this.AddEventCallback=function(object)
583
+ {
584
+ if (!object || !object.event || !object.callback) return;
585
+
586
+ var data={Callback:object.callback, Source:object};
587
+ this.mapEvent.set(object.event,data);
588
+ }
589
+
590
+ this.RemoveEventCallback=function(eventid)
591
+ {
592
+ if (!this.mapEvent.has(eventid)) return;
593
+
594
+ this.mapEvent.delete(eventid);
595
+ }
596
+
597
+ this.GetEventCallback=function(id) //获取事件回调
598
+ {
599
+ if (!this.mapEvent.has(id)) return null;
600
+ var item=this.mapEvent.get(id);
601
+ return item;
602
+ }
603
+
604
+ this.OnSize=function()
605
+ {
606
+ if (!this.Frame) return;
607
+
608
+ this.SetSizeChange(true);
609
+
610
+ var chart=this.ChartPaint[0];
611
+ if (chart && this.Data && this.Data.DataOffset>0 && IFrameSplitOperator.IsNonEmptyArray(this.Data.Data))
612
+ {
613
+ var pageSize=chart.GetPageSize(true);
614
+ if (pageSize+this.Data.DataOffset>=this.Data.Data.length) //当前屏不能显示满,调整
615
+ this.GotoLastPage();
616
+ }
617
+
618
+ this.Draw();
619
+ }
620
+
621
+ this.SetSizeChange=function(bChanged)
622
+ {
623
+ var chart=this.ChartPaint[0];
624
+ if (chart) chart.SizeChange=bChanged;
625
+ }
626
+
627
+
628
+ this.OnWheel=function(e) //滚轴
629
+ {
630
+ JSConsole.Chart.Log('[JSDealChartContainer::OnWheel]',e);
631
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
632
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
633
+
634
+ var x = e.clientX-this.UIElement.getBoundingClientRect().left;
635
+ var y = e.clientY-this.UIElement.getBoundingClientRect().top;
636
+
637
+ var isInClient=false;
638
+ this.Canvas.beginPath();
639
+ this.Canvas.rect(this.Frame.ChartBorder.GetLeft(),this.Frame.ChartBorder.GetTop(),this.Frame.ChartBorder.GetWidth(),this.Frame.ChartBorder.GetHeight());
640
+ isInClient=this.Canvas.isPointInPath(x,y);
641
+ if (!isInClient) return;
642
+
643
+ var chart=this.ChartPaint[0];
644
+ if (!chart) return;
645
+
646
+ var wheelValue=e.wheelDelta;
647
+ if (!IFrameSplitOperator.IsObjectExist(e.wheelDelta))
648
+ wheelValue=e.deltaY* -0.01;
649
+
650
+ if (wheelValue<0) //下一页
651
+ {
652
+ if (this.GotoNextPage()) this.Draw();
653
+ }
654
+ else if (wheelValue>0) //上一页
655
+ {
656
+ if (this.GotoPreviousPage()) this.Draw();
657
+ }
658
+
659
+ if(e.preventDefault) e.preventDefault();
660
+ else e.returnValue = false;
661
+ }
662
+
663
+ this.OnKeyDown=function(e)
664
+ {
665
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
666
+
667
+ var keyID = e.keyCode ? e.keyCode :e.which;
668
+ switch(keyID)
669
+ {
670
+ case 38: //up
671
+ if (this.GotoPreviousPage()) this.Draw();
672
+ break;
673
+ case 40: //down
674
+ if (this.GotoNextPage()) this.Draw();
675
+ break;
676
+ }
677
+
678
+ //不让滚动条滚动
679
+ if(e.preventDefault) e.preventDefault();
680
+ else e.returnValue = false;
681
+ }
682
+
683
+ this.GotoNextPage=function()
684
+ {
685
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
686
+ var chart=this.ChartPaint[0];
687
+ if (!chart) return false;
688
+
689
+ var pageSize=chart.GetPageSize();
690
+ if (pageSize>this.Data.Data.length) return false;
691
+
692
+ var offset=this.Data.DataOffset+pageSize;
693
+ if (offset+pageSize==this.Data.Data.length-1) return false;
694
+
695
+ if (offset+pageSize>this.Data.Data.length) //最后一页不够一屏调整到满屏
696
+ {
697
+ this.Data.DataOffset=this.Data.Data.length-pageSize;
698
+ }
699
+ else
700
+ {
701
+ this.Data.DataOffset=offset;
702
+ }
703
+ return true;
704
+ }
705
+
706
+ this.GotoPreviousPage=function()
707
+ {
708
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
709
+ var chart=this.ChartPaint[0];
710
+ if (!chart) return false;
711
+ if (this.Data.DataOffset<=0) return false;
712
+
713
+ var pageSize=chart.GetPageSize();
714
+ var offset=this.Data.DataOffset;
715
+ offset-=pageSize;
716
+ if (offset<0) offset=0;
717
+ this.Data.DataOffset=offset;
718
+ return true;
719
+ }
720
+
721
+ this.GotoLastPage=function()
722
+ {
723
+ var chart=this.ChartPaint[0];
724
+ if (!chart) return;
725
+
726
+ //显示最后一屏
727
+ var pageSize=chart.GetPageSize(true);
728
+ var offset=this.Data.Data.length-pageSize;
729
+ if (offset<0) offset=0;
730
+ this.Data.DataOffset=offset;
731
+ }
732
+
733
+ this.SetColumn=function(aryColunm, option)
734
+ {
735
+ var chart=this.ChartPaint[0];
736
+ if (chart)
737
+ {
738
+ chart.SetColumn(aryColunm);
739
+ chart.SizeChange=true;
740
+
741
+ if (option && option.Redraw) this.Draw();
742
+ }
743
+ }
744
+
745
+ this.ReloadResource=function(option)
746
+ {
747
+ this.Frame.ReloadResource(option);
748
+
749
+ for(var i=0;i<this.ChartPaint.length;++i)
750
+ {
751
+ var item=this.ChartPaint[i];
752
+ if (item.ReloadResource) item.ReloadResource(option);
753
+ }
754
+
755
+ if (option && option.Redraw)
756
+ {
757
+ this.SetSizeChange(true);
758
+ this.Draw();
759
+ }
760
+ }
761
+
762
+ }
763
+
764
+
765
+ JSDealChartContainer.JsonDataToDealData=function(data)
766
+ {
767
+ var symbol=data.symbol;
768
+ var result=[];
769
+ if (!IFrameSplitOperator.IsNonEmptyArray(data.detail)) return result;
770
+
771
+ //0=时间 1=价格 2=成交量 3=成交金额 4=BS 5=字符串时间 6=ID
772
+ for(var i=0;i<data.detail.length;++i)
773
+ {
774
+ var item=data.detail[i];
775
+
776
+ var dealItem={ Time:item[0], Price:item[1], Vol:item[2], BS:item[4], Amount:item[3] };
777
+ dealItem.Source=item;
778
+
779
+ if (item[5]) dealItem.StrTime=item[5];
780
+ if (item[6]) dealItem.ID=item[6];
781
+
782
+ result.push(dealItem);
783
+ }
784
+
785
+ return result;
786
+ }
787
+
788
+
789
+ function JSDealFrame()
790
+ {
791
+ this.ChartBorder;
792
+ this.Canvas; //画布
793
+
794
+ this.BorderColor=g_JSChartResource.DealList.BorderColor; //边框线
795
+
796
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
797
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
798
+
799
+ this.ReloadResource=function(resource)
800
+ {
801
+ this.BorderColor=g_JSChartResource.DealList.BorderColor; //边框线
802
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
803
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
804
+ }
805
+
806
+ this.Draw=function(option)
807
+ {
808
+ var left=ToFixedPoint(this.ChartBorder.GetLeft());
809
+ var top=ToFixedPoint(this.ChartBorder.GetTop());
810
+ var right=ToFixedPoint(this.ChartBorder.GetRight());
811
+ var bottom=ToFixedPoint(this.ChartBorder.GetBottom());
812
+ var width=right-left;
813
+ var height=bottom-top;
814
+
815
+ if (!IFrameSplitOperator.IsNumber(this.BorderLine))
816
+ {
817
+ this.Canvas.strokeStyle=this.BorderColor;
818
+ this.Canvas.strokeRect(left,top,width,height);
819
+ }
820
+ else
821
+ {
822
+ this.Canvas.strokeStyle=this.BorderColor;
823
+ this.Canvas.beginPath();
824
+
825
+ if ((this.BorderLine&1)>0) //上
826
+ {
827
+ this.Canvas.moveTo(left,top);
828
+ this.Canvas.lineTo(right,top);
829
+ }
830
+
831
+ if ((this.BorderLine&2)>0) //下
832
+ {
833
+ this.Canvas.moveTo(left,bottom);
834
+ this.Canvas.lineTo(right,bottom);
835
+ }
836
+
837
+ if ((this.BorderLine&4)>0) //左
838
+ {
839
+ this.Canvas.moveTo(left,top);
840
+ this.Canvas.lineTo(left,bottom);
841
+ }
842
+
843
+ if ((this.BorderLine&8)>0) //右
844
+ {
845
+ this.Canvas.moveTo(right,top);
846
+ this.Canvas.lineTo(right,bottom);
847
+ }
848
+
849
+ this.Canvas.stroke();
850
+ }
851
+ }
852
+
853
+ this.DrawLogo=function()
854
+ {
855
+ var text=g_JSChartResource.FrameLogo.Text;
856
+ if (!IFrameSplitOperator.IsString(text)) return;
857
+
858
+ this.Canvas.fillStyle=this.LogoTextColor;
859
+ this.Canvas.font=this.LogoTextFont;
860
+ this.Canvas.textAlign = 'left';
861
+ this.Canvas.textBaseline = 'bottom';
862
+
863
+ var x=this.ChartBorder.GetLeft()+5;
864
+ var y=this.ChartBorder.GetBottom()-5;
865
+ this.Canvas.fillText(text,x,y);
866
+ }
867
+ }
868
+
869
+ var DEAL_COLUMN_ID=
870
+ {
871
+ TIME_ID:0, //时间
872
+ PRICE_ID:1, //成交价格
873
+ VOL_ID:2, //成交量
874
+ DEAL_ID:3, //成交笔数
875
+ BS_ID:4,
876
+ UPDOWN_ID:5, //涨跌
877
+ STRING_TIME_ID:6, //字符串时间
878
+ INDEX_ID:7, //序号 从1开始
879
+ MULTI_BAR_ID:8, //多颜色柱子
880
+ CENTER_BAR_ID:9, //中心柱子
881
+ CUSTOM_TEXT_ID:10 //自定义文本
882
+ }
883
+
884
+ function ChartDealList()
885
+ {
886
+ this.Canvas; //画布
887
+ this.ChartBorder; //边框信息
888
+ this.ChartFrame; //框架画法
889
+ this.Name; //名称
890
+ this.ClassName='ChartDealList'; //类名
891
+ this.IsDrawFirst=false;
892
+ this.GetEventCallback;
893
+ this.Data; //数据 { Data:[ { Time:, Price:, Vol:, BS:, StrTime } ], Offset: }
894
+ //this.Data={Offset:0, Data:[ {Time:925, Price:20.1, Vol:10000050, BS:1, Deal:45 }, {Time:925, Price:18.2, Vol:1150, BS:1, Deal:5 }] };
895
+ this.Symbol;
896
+ this.YClose; //昨收
897
+ this.Open; //开盘价
898
+ this.Decimal=2; //小数位数
899
+ this.IsSingleTable=false; //单表模式
900
+ this.IsShowHeader=true; //是否显示表头
901
+ this.ShowOrder=1; //0=顺序 1=倒序
902
+
903
+ this.SizeChange=true;
904
+
905
+ //涨跌颜色
906
+ this.UpColor=g_JSChartResource.DealList.UpTextColor;
907
+ this.DownColor=g_JSChartResource.DealList.DownTextColor;
908
+ this.UnchagneColor=g_JSChartResource.DealList.UnchagneTextColor;
909
+
910
+ this.BorderColor=g_JSChartResource.DealList.BorderColor; //边框线
911
+
912
+ //表头配置
913
+ this.HeaderFontConfig={ Size:g_JSChartResource.DealList.Header.Font.Size, Name:g_JSChartResource.DealList.Header.Font.Name };
914
+ this.HeaderColor=g_JSChartResource.DealList.Header.Color;
915
+ this.HeaderMergin=
916
+ {
917
+ Left:g_JSChartResource.DealList.Header.Mergin.Left,
918
+ Right:g_JSChartResource.DealList.Header.Mergin.Right,
919
+ Top:g_JSChartResource.DealList.Header.Mergin.Top,
920
+ Bottom:g_JSChartResource.DealList.Header.Mergin.Bottom
921
+ };
922
+
923
+ //表格内容配置
924
+ this.ItemFontConfig={ Size:g_JSChartResource.DealList.Row.Font.Size, Name:g_JSChartResource.DealList.Row.Font.Name };
925
+ this.RowMergin={ Top:g_JSChartResource.DealList.Row.Mergin.Top, Bottom:g_JSChartResource.DealList.Row.Mergin.Bottom };
926
+ this.BarMergin=
927
+ {
928
+ Top:g_JSChartResource.DealList.Row.BarMergin.Top,
929
+ Left:g_JSChartResource.DealList.Row.BarMergin.Left,
930
+ Right:g_JSChartResource.DealList.Row.BarMergin.Right,
931
+ Bottom:g_JSChartResource.DealList.Row.BarMergin.Bottom
932
+ };
933
+
934
+ //缓存
935
+ this.HeaderFont=12*GetDevicePixelRatio() +"px 微软雅黑";
936
+ this.ItemFont=15*GetDevicePixelRatio() +"px 微软雅黑";
937
+ this.RowCount=0;
938
+ this.TableWidth=0;
939
+ this.TableCount=0;
940
+ this.HeaderHeight=0;
941
+
942
+ this.Column=
943
+ [
944
+ { Type:DEAL_COLUMN_ID.TIME_ID, Title:"时间", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Time, MaxText:"88:88:88" , Foramt:"HH:MM:SS"},
945
+ { Type:DEAL_COLUMN_ID.PRICE_ID, Title:"价格", TextAlign:"center", Width:null, MaxText:"888888.88"},
946
+ { Type:DEAL_COLUMN_ID.VOL_ID, Title:"成交", TextAlign:"right", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Vol, MaxText:"888888"},
947
+ { Type:DEAL_COLUMN_ID.BS_ID, Title:"", TextAlign:"right", Width:null, MaxText:"擎" }
948
+ ];
949
+
950
+ this.RectClient={};
951
+
952
+ this.ReloadResource=function(resource)
953
+ {
954
+ this.UpColor=g_JSChartResource.DealList.UpTextColor;
955
+ this.DownColor=g_JSChartResource.DealList.DownTextColor;
956
+ this.UnchagneColor=g_JSChartResource.DealList.UnchagneTextColor;
957
+
958
+ this.BorderColor=g_JSChartResource.DealList.BorderColor; //边框线
959
+
960
+ //表头配置
961
+ this.HeaderFontConfig={ Size:g_JSChartResource.DealList.Header.Font.Size, Name:g_JSChartResource.DealList.Header.Font.Name };
962
+ this.HeaderColor=g_JSChartResource.DealList.Header.Color;
963
+ this.HeaderMergin=
964
+ {
965
+ Left:g_JSChartResource.DealList.Header.Mergin.Left,
966
+ Right:g_JSChartResource.DealList.Header.Mergin.Right,
967
+ Top:g_JSChartResource.DealList.Header.Mergin.Top,
968
+ Bottom:g_JSChartResource.DealList.Header.Mergin.Bottom
969
+ };
970
+
971
+ //表格内容配置
972
+ this.ItemFontConfig={ Size:g_JSChartResource.DealList.Row.Font.Size, Name:g_JSChartResource.DealList.Row.Font.Name };
973
+ this.RowMergin={ Top:g_JSChartResource.DealList.Row.Mergin.Top, Bottom:g_JSChartResource.DealList.Row.Mergin.Bottom };
974
+
975
+ for(var i=0;i<this.Column.length;++i)
976
+ {
977
+ var item=this.Column[i];
978
+ if (item.Type==DEAL_COLUMN_ID.TIME_ID || item.Type==DEAL_COLUMN_ID.STRING_TIME_ID)
979
+ item.TextColor=g_JSChartResource.DealList.FieldColor.Time;
980
+ else if (item.Type==DEAL_COLUMN_ID.VOL_ID)
981
+ item.TextColor=g_JSChartResource.DealList.FieldColor.Vol;
982
+ else if (item.Type==DEAL_COLUMN_ID.DEAL_ID)
983
+ item.TextColor=g_JSChartResource.DealList.FieldColor.Deal;
984
+ else if (item.Type==DEAL_COLUMN_ID.INDEX_ID)
985
+ item.TextColor=g_JSChartResource.DealList.FieldColor.Index;
986
+ }
987
+ }
988
+
989
+
990
+ this.SetColumn=function(aryColumn)
991
+ {
992
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryColumn)) return;
993
+
994
+ this.Column=[];
995
+ for(var i=0;i<aryColumn.length;++i)
996
+ {
997
+ var item=aryColumn[i];
998
+ var colItem=this.GetDefaultColunm(item.Type);
999
+ if (!colItem) continue;
1000
+
1001
+ if (item.Title) colItem.Title=item.Title;
1002
+ if (item.TextAlign) colItem.TextAlign=item.TextAlign;
1003
+ if (item.TextColor) colItem.TextColor=item.TextColor;
1004
+ if (item.MaxText) colItem.MaxText=item.MaxText;
1005
+
1006
+ if (item.Type==DEAL_COLUMN_ID.MULTI_BAR_ID || item.Type==DEAL_COLUMN_ID.CENTER_BAR_ID)
1007
+ {
1008
+ if (!IFrameSplitOperator.IsNumber(item.DataIndex)) continue;
1009
+ colItem.DataIndex=item.DataIndex; //柱子数据所在原始数据索引列
1010
+ }
1011
+
1012
+ this.Column.push(colItem);
1013
+ }
1014
+ }
1015
+
1016
+ this.GetDefaultColunm=function(id)
1017
+ {
1018
+ var DEFAULT_COLUMN=
1019
+ [
1020
+ { Type:DEAL_COLUMN_ID.TIME_ID, Title:"时间", TextAlign:"center", Width:null , TextColor:g_JSChartResource.DealList.FieldColor.Time, MaxText:"88:88:88", Foramt:"HH:MM:SS" },
1021
+ { Type:DEAL_COLUMN_ID.PRICE_ID, Title:"价格", TextAlign:"center", Width:null, MaxText:"888888.88"},
1022
+ { Type:DEAL_COLUMN_ID.VOL_ID, Title:"成交", TextAlign:"right", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Vol, MaxText:"888888"},
1023
+ { Type:DEAL_COLUMN_ID.BS_ID, Title:"", TextAlign:"right", Width:null,MaxText:"擎" },
1024
+ { Type:DEAL_COLUMN_ID.DEAL_ID, Title:"笔数", TextAlign:"right", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Deal , MaxText:"8888"},
1025
+ { Type:DEAL_COLUMN_ID.UPDOWN_ID, Title:"涨跌", TextAlign:"right", Width:null, MaxText:"-8888.88"},
1026
+ { Type:DEAL_COLUMN_ID.STRING_TIME_ID, Title:"时间", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Time, MaxText:"88:88:88" },
1027
+ { Type:DEAL_COLUMN_ID.INDEX_ID, Title:"序号", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Index, MaxText:"88888" },
1028
+
1029
+ { Type:DEAL_COLUMN_ID.MULTI_BAR_ID, Title:"柱子", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.BarTitle, MaxText:"888888" },
1030
+ { Type:DEAL_COLUMN_ID.CENTER_BAR_ID, Title:"柱子2", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.BarTitle, MaxText:"888888" },
1031
+ { Type:DEAL_COLUMN_ID.CUSTOM_TEXT_ID, Title:"自定义", TextAlign:"center", Width:null, TextColor:g_JSChartResource.DealList.FieldColor.Text, MaxText:"擎擎擎擎擎" },
1032
+
1033
+ ];
1034
+
1035
+ for(var i=0;i<DEFAULT_COLUMN.length;++i)
1036
+ {
1037
+ var item=DEFAULT_COLUMN[i];
1038
+ if (item.Type==id) return item;
1039
+ }
1040
+
1041
+ return null;
1042
+ }
1043
+
1044
+
1045
+ this.Draw=function()
1046
+ {
1047
+ if (this.SizeChange) this.CalculateSize();
1048
+ else this.UpdateCacheData();
1049
+
1050
+ this.DrawBorder();
1051
+ this.DrawHeader();
1052
+ this.DrawBody();
1053
+
1054
+ this.SizeChange=false;
1055
+ }
1056
+
1057
+ //更新缓存变量
1058
+ this.UpdateCacheData=function()
1059
+ {
1060
+ this.RectClient.Left=this.ChartBorder.GetLeft();
1061
+ this.RectClient.Right=this.ChartBorder.GetRight();
1062
+ this.RectClient.Top=this.ChartBorder.GetTop();
1063
+ this.RectClient.Bottom=this.ChartBorder.GetBottom();
1064
+ this.Decimal=GetfloatPrecision(this.Symbol);
1065
+ }
1066
+
1067
+ this.GetPageSize=function(recalculate) //recalculate 是否重新计算
1068
+ {
1069
+ if (recalculate) this.CalculateSize();
1070
+
1071
+ var size=this.TableCount*this.RowCount;
1072
+
1073
+ return size;
1074
+ }
1075
+
1076
+ this.CalculateSize=function() //计算大小
1077
+ {
1078
+ this.UpdateCacheData();
1079
+
1080
+ var pixelRatio=GetDevicePixelRatio();
1081
+ this.HeaderFont=`${this.HeaderFontConfig.Size*pixelRatio}px ${ this.HeaderFontConfig.Name}`;
1082
+ this.ItemFont=`${this.ItemFontConfig.Size*pixelRatio}px ${ this.ItemFontConfig.Name}`;
1083
+
1084
+ this.Canvas.font=this.ItemFont;
1085
+
1086
+ var sumWidth=0, itemWidth=0;
1087
+ for(var i=0;i<this.Column.length;++i)
1088
+ {
1089
+ var item=this.Column[i];
1090
+ itemWidth=this.Canvas.measureText(item.MaxText).width;
1091
+ item.Width=itemWidth+4;
1092
+ sumWidth+=item.Width;
1093
+ }
1094
+
1095
+ var clientWidth=this.RectClient.Right-this.RectClient.Left;
1096
+ this.TableCount=parseInt(clientWidth/sumWidth);
1097
+ if (this.IsSingleTable) this.TableCount=1;
1098
+ this.TableWidth=clientWidth/this.TableCount;
1099
+
1100
+ this.HeaderHeight=this.GetFontHeight(this.HeaderFont,"擎")+ this.HeaderMergin.Top+ this.HeaderMergin.Bottom;
1101
+ if (!this.IsShowHeader) this.HeaderHeight=0;
1102
+ this.RowHeight=this.GetFontHeight(this.ItemFont,"擎")+ this.HeaderMergin.Top+ this.HeaderMergin.Bottom;
1103
+ this.RowCount=parseInt((this.RectClient.Bottom-this.RectClient.Top-this.HeaderHeight)/this.RowHeight);
1104
+ }
1105
+
1106
+ this.DrawHeader=function()
1107
+ {
1108
+ if (!this.IsShowHeader) return;
1109
+
1110
+ var left=this.RectClient.Left+this.HeaderMergin.Left;
1111
+ var top=this.RectClient.Top;
1112
+ var y=top+this.HeaderMergin.Top+(this.HeaderHeight-this.HeaderMergin.Top-this.HeaderMergin.Bottom)/2;
1113
+
1114
+ this.Canvas.font=this.HeaderFont;
1115
+ this.Canvas.fillStyle=this.HeaderColor;
1116
+ for(var i=0, j=0;i<this.TableCount;++i)
1117
+ {
1118
+ var tableLeft=left+(this.TableWidth*i);
1119
+ var textLeft=tableLeft;
1120
+ for(j=0;j<this.Column.length;++j)
1121
+ {
1122
+ var item=this.Column[j];
1123
+ var itemWidth=item.Width;
1124
+ if (j==this.Column.length-1) itemWidth=this.TableWidth-(textLeft-tableLeft)-this.HeaderMergin.Right-this.HeaderMergin.Left;
1125
+ var x=textLeft;
1126
+ if (item.TextAlign=='center')
1127
+ {
1128
+ x=textLeft+itemWidth/2;
1129
+ this.Canvas.textAlign="center";
1130
+ }
1131
+ else if (item.TextAlign=='right')
1132
+ {
1133
+ x=textLeft+itemWidth;
1134
+ this.Canvas.textAlign="right";
1135
+ }
1136
+ else
1137
+ {
1138
+ this.Canvas.textAlign="left";
1139
+ }
1140
+
1141
+
1142
+ this.Canvas.textBaseline="middle";
1143
+ this.Canvas.fillText(item.Title,x,y);
1144
+
1145
+ textLeft+=item.Width;
1146
+ }
1147
+ }
1148
+ }
1149
+
1150
+ this.DrawBorder=function()
1151
+ {
1152
+ var left=ToFixedPoint(this.RectClient.Left);
1153
+ var right=ToFixedPoint(this.RectClient.Right);
1154
+ var top=ToFixedPoint(this.RectClient.Top);
1155
+ var bottom=ToFixedPoint(this.RectClient.Bottom);
1156
+
1157
+ this.Canvas.strokeStyle=this.BorderColor;
1158
+ this.Canvas.beginPath();
1159
+
1160
+ if (this.IsShowHeader)
1161
+ {
1162
+ this.Canvas.moveTo(left,top+this.HeaderHeight);
1163
+ this.Canvas.lineTo(right,top+this.HeaderHeight);
1164
+ }
1165
+
1166
+ var tableLeft=ToFixedPoint(left+this.TableWidth);
1167
+ for(var i=1;i<this.TableCount;++i)
1168
+ {
1169
+ this.Canvas.moveTo(tableLeft,top);
1170
+ this.Canvas.lineTo(tableLeft,bottom);
1171
+
1172
+ tableLeft=ToFixedPoint(tableLeft+this.TableWidth);
1173
+ }
1174
+
1175
+ this.Canvas.stroke();
1176
+ }
1177
+
1178
+ this.DrawBody=function()
1179
+ {
1180
+ if (!this.Data) return;
1181
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
1182
+
1183
+ this.Canvas.font=this.ItemFont;
1184
+ var top=this.RectClient.Top+this.HeaderHeight;
1185
+ var left=this.RectClient.Left+this.HeaderMergin.Left;
1186
+ var dataCount=this.Data.Data.length;
1187
+ var index=this.Data.DataOffset;
1188
+
1189
+ if (this.ShowOrder==1)
1190
+ {
1191
+ var index=this.Data.DataOffset+(this.TableCount*this.RowCount);
1192
+ if (index>=dataCount) index=dataCount-1;
1193
+ for(var i=0,j=0;i<this.TableCount;++i)
1194
+ {
1195
+ var tableLeft=left+(this.TableWidth*i);
1196
+ var textLeft=tableLeft;
1197
+ var textTop=top;
1198
+
1199
+ for(j=0;j<this.RowCount && index>=0;++j, --index)
1200
+ {
1201
+ var dataItem=this.Data.Data[index];
1202
+
1203
+ this.DrawRow(dataItem, textLeft, textTop, index);
1204
+
1205
+ textTop+=this.RowHeight;
1206
+ }
1207
+ }
1208
+ }
1209
+ else
1210
+ {
1211
+ for(var i=0,j=0;i<this.TableCount;++i)
1212
+ {
1213
+ var tableLeft=left+(this.TableWidth*i);
1214
+ var textLeft=tableLeft;
1215
+ var textTop=top;
1216
+ for(j=0;j<this.RowCount && index<dataCount;++j, ++index)
1217
+ {
1218
+ var dataItem=this.Data.Data[index];
1219
+
1220
+ this.DrawRow(dataItem, textLeft, textTop, index);
1221
+
1222
+ textTop+=this.RowHeight;
1223
+ }
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ this.DrawRow=function(data, left, top, dataIndex, colIndex)
1229
+ {
1230
+ var tableLeft=left;
1231
+ var tableRight=left+this.TableWidth;
1232
+ for(var i=0;i<this.Column.length;++i)
1233
+ {
1234
+ var item=this.Column[i];
1235
+ var textColor=item.TextColor;
1236
+ var text=null;
1237
+ var itemWidth=item.Width;
1238
+ var textAlign=item.TextAlign;
1239
+
1240
+ if (left+itemWidth>tableRight) break;
1241
+
1242
+ if (i==this.Column.length-1) itemWidth=this.TableWidth-(left-tableLeft)-this.HeaderMergin.Right-this.HeaderMergin.Left;
1243
+
1244
+ if (item.Type==DEAL_COLUMN_ID.TIME_ID)
1245
+ {
1246
+ text=IFrameSplitOperator.FormatTimeString(data.Time,item.Foramt);
1247
+ }
1248
+ else if (item.Type==DEAL_COLUMN_ID.STRING_TIME_ID)
1249
+ {
1250
+ text=data.StrTime;
1251
+ }
1252
+ else if (item.Type==DEAL_COLUMN_ID.PRICE_ID)
1253
+ {
1254
+ if (data.Price>this.YClose) textColor=this.UpColor;
1255
+ else if (data.Price<this.YClose) textColor=this.DownColor;
1256
+ else textColor=this.UnchagneColor;
1257
+
1258
+ text=data.Price.toFixed(this.Decimal);
1259
+ }
1260
+ else if (item.Type==DEAL_COLUMN_ID.VOL_ID)
1261
+ {
1262
+ text=IFrameSplitOperator.FormatValueString(data.Vol,0);
1263
+ textColor=this.GetVolColor(item, data);
1264
+ }
1265
+ else if (item.Type==DEAL_COLUMN_ID.DEAL_ID)
1266
+ {
1267
+ text=IFrameSplitOperator.FormatValueString(data.Deal,0);
1268
+ }
1269
+ else if (item.Type==DEAL_COLUMN_ID.BS_ID)
1270
+ {
1271
+ if (data.BS==1)
1272
+ {
1273
+ text="B";
1274
+ textColor=this.UpColor;
1275
+ }
1276
+ else if (data.BS==2)
1277
+ {
1278
+ text="S";
1279
+ textColor=this.DownColor;
1280
+ }
1281
+ }
1282
+ else if (item.Type==DEAL_COLUMN_ID.UPDOWN_ID)
1283
+ {
1284
+ if (IFrameSplitOperator.IsNumber(this.YClose))
1285
+ {
1286
+ var value=data.Price-this.YClose;
1287
+ text=value.toFixed(2);
1288
+
1289
+ if (value>0) textColor=this.UpColor;
1290
+ else if (value<0) textColor=this.DownColor;
1291
+ else textColor=this.UnchagneColor;
1292
+ }
1293
+ }
1294
+ else if (item.Type==DEAL_COLUMN_ID.INDEX_ID)
1295
+ {
1296
+ text=(dataIndex+1).toString();
1297
+ }
1298
+ else if (item.Type==DEAL_COLUMN_ID.MULTI_BAR_ID)
1299
+ {
1300
+ var rtItem={Left:left, Top:top, Width:itemWidth, Height:this.RowHeight};
1301
+ this.DrawMultiBar(item, data, rtItem);
1302
+ }
1303
+ else if (item.Type==DEAL_COLUMN_ID.CENTER_BAR_ID)
1304
+ {
1305
+ var rtItem={Left:left, Top:top, Width:itemWidth, Height:this.RowHeight};
1306
+ this.DrawCenterBar(item, data, rtItem);
1307
+ }
1308
+ else if (item.Type==DEAL_COLUMN_ID.CUSTOM_TEXT_ID)
1309
+ {
1310
+ var out={ Text:null, TextColor:null, TextAlign:null }; //输出
1311
+ var rtItem={Left:left, Top:top, Width:itemWidth, Height:this.RowHeight};
1312
+ if (this.DrawCustomText(item, data, rtItem, dataIndex, i, out))
1313
+ {
1314
+ if (out.Text) text=out.Text;
1315
+ if (out.TextColor) textColor=out.TextColor;
1316
+ if (out.TextAlign) textAlign=out.TextAlign;
1317
+ }
1318
+ }
1319
+
1320
+ this.DrawItemText(text, textColor, textAlign, left, top, itemWidth);
1321
+
1322
+ left+=item.Width;
1323
+ }
1324
+ }
1325
+
1326
+ this.DrawItemText=function(text, textColor, textAlign, left, top, width)
1327
+ {
1328
+ var x=left;
1329
+ if (textAlign=='center')
1330
+ {
1331
+ x=left+width/2;
1332
+ this.Canvas.textAlign="center";
1333
+ }
1334
+ else if (textAlign=='right')
1335
+ {
1336
+ x=left+width;
1337
+ this.Canvas.textAlign="right";
1338
+ }
1339
+ else
1340
+ {
1341
+ this.Canvas.textAlign="left";
1342
+ }
1343
+
1344
+ this.Canvas.textBaseline="middle";
1345
+ this.Canvas.fillStyle=textColor;
1346
+ if (text) this.Canvas.fillText(text,x,top+this.RowHeight/2);
1347
+ }
1348
+
1349
+ this.DrawMultiBar=function(colunmInfo, data, rtItem)
1350
+ {
1351
+ if (!data.Source || !IFrameSplitOperator.IsNonEmptyArray(data.Source)) return false;
1352
+ var barData=data.Source[colunmInfo.DataIndex]; //{ Value:[0.4,0,2], Color:[0,1] };
1353
+ if (!barData) return false;
1354
+ if (!IFrameSplitOperator.IsNonEmptyArray(barData.Value)) return false;
1355
+
1356
+ var width=rtItem.Width-this.BarMergin.Left-this.BarMergin.Right;
1357
+ var left=rtItem.Left+this.BarMergin.Left;
1358
+ var top=rtItem.Top+this.RowMergin.Top+this.BarMergin.Top;
1359
+ var height=rtItem.Height-this.RowMergin.Top-this.RowMergin.Bottom-this.BarMergin.Top-this.BarMergin.Bottom;
1360
+ var right=left+width;
1361
+ for(var i=0;i<barData.Value.length;++i)
1362
+ {
1363
+ var value=barData.Value[i];
1364
+ if (value<=0) continue;
1365
+ if (left>=right) break;
1366
+
1367
+ var barWidth=width*value;
1368
+ if (barWidth<1) barWidth=1;
1369
+ if (left+barWidth>right) barWidth=right-left;
1370
+
1371
+ var colorIndex=i;
1372
+ if (IFrameSplitOperator.IsNonEmptyArray(barData.Color) && i<barData.Color.length) colorIndex= barData.Color[i];
1373
+
1374
+ this.Canvas.fillStyle=g_JSChartResource.DealList.FieldColor.Bar[colorIndex];
1375
+ this.Canvas.fillRect(left,top,barWidth,height);
1376
+
1377
+ left+=barWidth;
1378
+ }
1379
+ return true;
1380
+ }
1381
+
1382
+ this.DrawCenterBar=function(colunmInfo, data, rtItem)
1383
+ {
1384
+ if (!data.Source || !IFrameSplitOperator.IsNonEmptyArray(data.Source)) return false;
1385
+ var barData=data.Source[colunmInfo.DataIndex]; //{ Value:[0.4,0,2], Color:[0,1] };
1386
+ if (!barData) return false;
1387
+ if (!IFrameSplitOperator.IsNonEmptyArray(barData.Value)) return false;
1388
+
1389
+ var width=(rtItem.Width-this.BarMergin.Left-this.BarMergin.Right)/2;
1390
+ var left=rtItem.Left+this.BarMergin.Left;
1391
+ var center=left+width;
1392
+ var top=rtItem.Top+this.RowMergin.Top+this.BarMergin.Top;
1393
+ var height=rtItem.Height-this.RowMergin.Top-this.RowMergin.Bottom-this.BarMergin.Top-this.BarMergin.Bottom;
1394
+ var right=left+width;
1395
+
1396
+ for(var i=0;i<barData.Value.length && i<2;++i)
1397
+ {
1398
+ var value=barData.Value[i];
1399
+ if (value<=0) continue;
1400
+
1401
+ if (value>1) value=1;
1402
+ var barWidth=width*value;
1403
+ if (barWidth<1) barWidth=1;
1404
+
1405
+ var colorIndex=i;
1406
+ if (IFrameSplitOperator.IsNonEmptyArray(barData.Color) && i<barData.Color.length) colorIndex= barData.Color[i];
1407
+ this.Canvas.fillStyle=g_JSChartResource.DealList.FieldColor.Bar[colorIndex];
1408
+
1409
+ if (i==0) //左边
1410
+ {
1411
+ this.Canvas.fillRect(center,top,-barWidth,height);
1412
+ }
1413
+ else //右边
1414
+ {
1415
+ this.Canvas.fillRect(center,top,barWidth,height);
1416
+ }
1417
+ }
1418
+ }
1419
+
1420
+ this.DrawCustomText=function(columnInfo, data, rtItem, dataIndex, colid, out)
1421
+ {
1422
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_DRAW_DEAL_TEXT);
1423
+ if (!event || !event.Callback) return false;
1424
+
1425
+ var sendData={ Data:data, DataIndex:dataIndex, ColumnIndex:colid, ColumnInfo: columnInfo , Out:{ Text:null, TextColor:null,TextAlign:null } };
1426
+ event.Callback(event,sendData,this);
1427
+ if (!sendData.Out.Text) return false;
1428
+
1429
+ out.Text=sendData.Out.Text;
1430
+ if (sendData.Out.TextColor) out.TextColor=sendData.Out.TextColor;
1431
+ if (sendData.Out.TextAlign) out.TextAlign=sendData.Out.TextAlign;
1432
+ return true;
1433
+ }
1434
+
1435
+ this.GetVolColor=function(colunmInfo, data)
1436
+ {
1437
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_DRAW_DEAL_VOL_COLOR);
1438
+ if (event && event.Callback)
1439
+ {
1440
+ var sendData={ Data:data, TextColor:null };
1441
+ event.Callback(event,sendData,this);
1442
+ if (sendData.TextColor) return sendData.TextColor;
1443
+ }
1444
+
1445
+ return colunmInfo.TextColor;
1446
+ }
1447
+
1448
+ this.GetFontHeight=function(font,word)
1449
+ {
1450
+ return GetFontHeight(this.Canvas, font, word);
1451
+ }
1452
+ }