hqchart 1.1.15438 → 1.1.15449

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,1077 @@
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 JSStatusBarChart(divElement)
15
+ {
16
+ this.DivElement=divElement;
17
+ this.JSChartContainer; //表格控件
18
+ this.ResizeListener; //大小变动监听
19
+
20
+ //h5 canvas
21
+ this.CanvasElement=document.createElement("canvas");
22
+ this.CanvasElement.className='jsstatusbar-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("[JSStatusBarChart::JSStatusBarChart] divElement hasChildNodes", divElement.childNodes);
29
+ }
30
+ divElement.appendChild(this.CanvasElement);
31
+
32
+
33
+ this.OnSize=function()
34
+ {
35
+ //画布大小通过div获取 如果有style里的大小 使用style里的
36
+ var height=this.DivElement.offsetHeight;
37
+ var width=this.DivElement.offsetWidth;
38
+ if (this.DivElement.style.height && this.DivElement.style.width)
39
+ {
40
+ if (this.DivElement.style.height.includes("px"))
41
+ height=parseInt(this.DivElement.style.height.replace("px",""));
42
+ if (this.DivElement.style.width.includes("px"))
43
+ width=parseInt(this.DivElement.style.width.replace("px",""));
44
+ }
45
+
46
+ this.CanvasElement.height=height;
47
+ this.CanvasElement.width=width;
48
+ this.CanvasElement.style.width=this.CanvasElement.width+'px';
49
+ this.CanvasElement.style.height=this.CanvasElement.height+'px';
50
+
51
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
52
+ this.CanvasElement.height*=pixelTatio;
53
+ this.CanvasElement.width*=pixelTatio;
54
+
55
+ JSConsole.Chart.Log(`[JSStatusBarChart::OnSize] devicePixelRatio=${window.devicePixelRatio}, height=${this.CanvasElement.height}, width=${this.CanvasElement.width}`);
56
+
57
+ if (this.JSChartContainer && this.JSChartContainer.OnSize)
58
+ {
59
+ this.JSChartContainer.OnSize();
60
+ }
61
+ }
62
+
63
+ this.SetOption=function(option)
64
+ {
65
+ var chart=this.CreateJSStatusBarChartContainer(option);
66
+
67
+ if (!chart) return false;
68
+
69
+ if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
70
+
71
+ this.JSChartContainer=chart;
72
+ this.DivElement.JSChart=this; //div中保存一份
73
+
74
+ if (option.EnableResize==true) this.CreateResizeListener();
75
+
76
+ chart.Draw();
77
+ chart.RequestData();
78
+ }
79
+
80
+ this.CreateResizeListener=function()
81
+ {
82
+ this.ResizeListener = new ResizeObserver((entries)=>{ this.OnDivResize(entries); });
83
+ this.ResizeListener.observe(this.DivElement);
84
+ }
85
+
86
+ this.OnDivResize=function(entries)
87
+ {
88
+ JSConsole.Chart.Log("[JSStatusBarChart::OnDivResize] entries=", entries);
89
+
90
+ this.OnSize();
91
+ }
92
+
93
+ this.CreateJSStatusBarChartContainer=function(option)
94
+ {
95
+ var chart=new JSStatusBarChartContainer(this.CanvasElement);
96
+ chart.Create(option);
97
+
98
+ this.SetChartBorder(chart, option);
99
+
100
+ if (IFrameSplitOperator.IsNonEmptyArray(option.Column)) chart.SetColumn(option.Column);
101
+ if (option.RightToolbar) chart.SetRightToolbar(option.RightToolbar);
102
+
103
+ //是否自动更新
104
+ if (option.NetworkFilter) chart.NetworkFilter=option.NetworkFilter;
105
+
106
+ if (option.IsAutoUpdate!=null) chart.IsAutoUpdate=option.IsAutoUpdate;
107
+ if (option.AutoUpdateFrequency>0) chart.AutoUpdateFrequency=option.AutoUpdateFrequency;
108
+
109
+ //注册事件
110
+ if (option.EventCallback)
111
+ {
112
+ for(var i=0;i<option.EventCallback.length;++i)
113
+ {
114
+ var item=option.EventCallback[i];
115
+ chart.AddEventCallback(item);
116
+ }
117
+ }
118
+
119
+ return chart;
120
+ }
121
+
122
+ this.SetChartBorder=function(chart, option)
123
+ {
124
+ if (!option.Border) return;
125
+
126
+ var item=option.Border;
127
+ if (IFrameSplitOperator.IsNumber(option.Border.Left)) chart.Frame.ChartBorder.Left=option.Border.Left;
128
+ if (IFrameSplitOperator.IsNumber(option.Border.Right)) chart.Frame.ChartBorder.Right=option.Border.Right;
129
+ if (IFrameSplitOperator.IsNumber(option.Border.Top)) chart.Frame.ChartBorder.Top=option.Border.Top;
130
+ if (IFrameSplitOperator.IsNumber(option.Border.Bottom)) chart.Frame.ChartBorder.Bottom=option.Border.Bottom;
131
+
132
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
133
+ chart.Frame.ChartBorder.Left*=pixelTatio;
134
+ chart.Frame.ChartBorder.Right*=pixelTatio;
135
+ chart.Frame.ChartBorder.Top*=pixelTatio;
136
+ chart.Frame.ChartBorder.Bottom*=pixelTatio;
137
+ }
138
+
139
+ //事件回调
140
+ this.AddEventCallback=function(obj)
141
+ {
142
+ if(this.JSChartContainer && typeof(this.JSChartContainer.AddEventCallback)=='function')
143
+ {
144
+ JSConsole.Chart.Log('[JSStatusBarChart: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('[JSStatusBarChart:ReloadResource] ');
155
+ this.JSChartContainer.ReloadResource(option);
156
+ }
157
+ }
158
+
159
+ this.ChartDestroy=function()
160
+ {
161
+ if (this.JSChartContainer && typeof (this.JSChartContainer.ChartDestroy) == 'function')
162
+ {
163
+ this.JSChartContainer.ChartDestroy();
164
+ }
165
+ }
166
+
167
+ this.Draw=function()
168
+ {
169
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Draw)=='function')
170
+ {
171
+ JSConsole.Chart.Log('[JSStatusBarChart:Draw] ');
172
+ this.JSChartContainer.Draw();
173
+ }
174
+ }
175
+ }
176
+
177
+ JSStatusBarChart.Init=function(divElement)
178
+ {
179
+ var jsChartControl=new JSStatusBarChart(divElement);
180
+ jsChartControl.OnSize();
181
+
182
+ return jsChartControl;
183
+ }
184
+
185
+ //自定义风格
186
+ JSStatusBarChart.SetStyle=function(option)
187
+ {
188
+ if (option) g_JSChartResource.SetStyle(option);
189
+ }
190
+
191
+ //获取颜色配置 (JSStatusBarChart.Init()之前)
192
+ JSStatusBarChart.GetResource=function()
193
+ {
194
+ return g_JSChartResource;
195
+ }
196
+
197
+ JSStatusBarChart.GetfloatPrecision=function(symbol)
198
+ {
199
+ return GetfloatPrecision(symbol);
200
+ }
201
+
202
+
203
+ function JSStatusBarChartContainer(uielement)
204
+ {
205
+ this.ClassName='JSStatusBarChartContainer';
206
+ this.Frame; //框架画法
207
+ this.ChartPaint=[]; //图形画法
208
+
209
+ this.Canvas=uielement.getContext("2d"); //画布
210
+
211
+ this.NetworkFilter; //数据回调接口
212
+ this.Data=
213
+ {
214
+ MapSymbol:new Map(), //key=symbol, { Value:, Text:, } 股票数据
215
+ };
216
+
217
+ //事件回调
218
+ this.mapEvent=new Map(); //通知外部调用 key:JSCHART_EVENT_ID value:{ Callback:回调,}
219
+
220
+ this.AutoUpdateTimer=null;
221
+ this.AutoUpdateFrequency=15000; //15秒更新一次数据
222
+
223
+ this.ToolbarTimer=null;
224
+
225
+ this.UIElement=uielement;
226
+
227
+ this.IsDestroy=false; //是否已经销毁了
228
+
229
+ this.ChartDestroy=function() //销毁
230
+ {
231
+ this.IsDestroy=true;
232
+ this.StopAutoUpdate();
233
+
234
+ if (this.ToolbarTimer)
235
+ {
236
+ clearInterval(this.ToolbarTimer);
237
+ this.ToolbarTimer=null;
238
+ }
239
+ }
240
+
241
+ //设置事件回调
242
+ //{event:事件id, callback:回调函数}
243
+ this.AddEventCallback=function(object)
244
+ {
245
+ if (!object || !object.event || !object.callback) return;
246
+
247
+ var data={Callback:object.callback, Source:object};
248
+ this.mapEvent.set(object.event,data);
249
+ }
250
+
251
+ this.RemoveEventCallback=function(eventid)
252
+ {
253
+ if (!this.mapEvent.has(eventid)) return;
254
+
255
+ this.mapEvent.delete(eventid);
256
+ }
257
+
258
+ this.GetEventCallback=function(id) //获取事件回调
259
+ {
260
+ if (!this.mapEvent.has(id)) return null;
261
+ var item=this.mapEvent.get(id);
262
+ return item;
263
+ }
264
+
265
+ this.ClearData=function()
266
+ {
267
+ this.Data.MapSymbol=new Map();
268
+ }
269
+
270
+ this.RequestData=function(option)
271
+ {
272
+ this.CancelAutoUpdate();
273
+ this.ClearData();
274
+
275
+ if (option)
276
+ {
277
+ if (IFrameSplitOperator.IsNonEmptyArray(option.Column)) this.SetColumn(option.Column);
278
+ }
279
+
280
+ this.Draw();
281
+ this.RequestStockData();
282
+
283
+ if (this.IsAutoUpdate)
284
+ {
285
+ var frequency=this.AutoUpdateFrequency;
286
+ setInterval(()=>
287
+ {
288
+ var marketStatus=MARKET_SUFFIX_NAME.GetMarketStatus(this.Symbol);
289
+ if (marketStatus==0 || marketStatus==3) //闭市,盘后
290
+ return;
291
+
292
+ this.RequestStockData();
293
+ }, frequency)
294
+ }
295
+ }
296
+
297
+ this.CancelAutoUpdate=function() //关闭停止更新
298
+ {
299
+ if (this.AutoUpdateTimer)
300
+ {
301
+ clearInterval(this.AutoUpdateTimer);
302
+ this.AutoUpdateTimer = null;
303
+ }
304
+ }
305
+
306
+ this.StopAutoUpdate=function()
307
+ {
308
+ this.CancelAutoUpdate();
309
+ if (!this.IsAutoUpdate) return;
310
+ this.IsAutoUpdate=false;
311
+ }
312
+
313
+ this.RequestStockData=function()
314
+ {
315
+ if (!this.NetworkFilter) return;
316
+
317
+ var chart=this.ChartPaint[0];
318
+ if (!chart) return;
319
+ if (!IFrameSplitOperator.IsNonEmptyArray(chart.Column)) return;
320
+
321
+ var arySymbol=[];
322
+ for(var i=0;i<chart.Column.length;++i)
323
+ {
324
+ var item=chart.Column[i];
325
+ var newItem={ Symbol:item.Symbol, Fields:[] };
326
+ arySymbol.push(newItem);
327
+ }
328
+
329
+ var obj=
330
+ {
331
+ Name:'JSStatusBarChartContainer::RequestStockData', //类名::函数名
332
+ Explain:'工具栏股票数据',
333
+ Request: { Data:{ stocks:arySymbol } },
334
+ Self:this,
335
+ PreventDefault:false
336
+ };
337
+
338
+ this.NetworkFilter(obj, (data)=>
339
+ {
340
+ this.RecvStockData(data);
341
+ });
342
+
343
+ if (obj.PreventDefault==true) return; //已被上层替换,不调用默认的网络请求
344
+
345
+ }
346
+
347
+ this.RecvStockData=function(recv)
348
+ {
349
+ if (!recv) return;
350
+ if (!IFrameSplitOperator.IsNonEmptyArray(recv.data)) return;
351
+
352
+ for(var i=0;i<recv.data.length;++i)
353
+ {
354
+ var item=recv.data[i];
355
+ if (!item.Symbol) continue;
356
+
357
+ var stockItem=null;
358
+ if (this.Data.MapSymbol.has(item.Symbol))
359
+ {
360
+ stockItem=this.Data.MapSymbol.get(item.Symbol);
361
+ }
362
+ else
363
+ {
364
+ stockItem={ Symbol:item.Symbol, MapData:new Map() };
365
+ stockItem.YClose=item.YClose;
366
+ if (IFrameSplitOperator.IsNumber(item.FYClose)) stockItem.YClose=item.FYClose;
367
+ this.Data.MapSymbol.set(item.Symbol,stockItem);
368
+ }
369
+
370
+ for(var j=0;j<item.Data.length;++j)
371
+ {
372
+ var itemData=item.Data[j];
373
+ stockItem.MapData.set(itemData.Key,itemData.Value);
374
+ }
375
+ }
376
+
377
+ if (!this.ToolbarTimer) this.Draw();
378
+ }
379
+
380
+ //创建
381
+ this.Create=function(option)
382
+ {
383
+ this.UIElement.JSChartContainer=this;
384
+
385
+ //创建框架
386
+ this.Frame=new JSStatusBarFrame();
387
+ this.Frame.ChartBorder=new ChartBorder();
388
+ this.Frame.ChartBorder.UIElement=this.UIElement;
389
+ this.Frame.ChartBorder.Top=30;
390
+ this.Frame.ChartBorder.Left=5;
391
+ this.Frame.ChartBorder.Bottom=20;
392
+ this.Frame.Canvas=this.Canvas;
393
+
394
+ //创建表格
395
+ var chart=new ChartStatusBarStockData();
396
+ chart.Frame=this.Frame;
397
+ chart.ChartBorder=this.Frame.ChartBorder;
398
+ chart.Canvas=this.Canvas;
399
+ chart.UIElement=this.UIElement;
400
+ chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
401
+ chart.Data=this.Data;
402
+ chart.BorderData=this.BorderData;
403
+ chart.GlobalOption=this.GlobalOption;
404
+ chart.FixedRowData=this.FixedRowData;
405
+ chart.SortInfo=this.SortInfo;
406
+ this.ChartPaint[0]=chart;
407
+
408
+
409
+ if (option)
410
+ {
411
+
412
+ }
413
+
414
+ this.UIElement.onmousedown=(e)=> { this.UIOnMouseDown(e); }
415
+
416
+ /*
417
+ this.UIElement.ondblclick=(e)=>{ this.UIOnDblClick(e); }
418
+ this.UIElement.onmousedown=(e)=> { this.UIOnMouseDown(e); }
419
+ this.UIElement.onmousemove=(e)=>{ this.UIOnMouseMove(e);}
420
+ this.UIElement.onmouseout=(e)=>{ this.UIOnMounseOut(e); }
421
+ this.UIElement.onmouseleave=(e)=>{ this.UIOnMouseleave(e); }
422
+ this.UIElement.oncontextmenu=(e)=> { this.UIOnContextMenu(e); }
423
+ */
424
+
425
+ var frequency=500;
426
+ this.ToolbarTimer=setInterval(()=>
427
+ {
428
+ this.Draw();
429
+ }, frequency)
430
+ }
431
+
432
+ this.UIOnMouseDown=function(e)
433
+ {
434
+ var pixelTatio = GetDevicePixelRatio();
435
+ this.ClickDownPoint={ X:e.clientX, Y:e.clientY };
436
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
437
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
438
+
439
+ var ptClick={ X:this.ClickDownPoint.X, Y:this.ClickDownPoint.Y };
440
+ this.TryClickPaintEvent(JSCHART_EVENT_ID.ON_CLICK_STATUSBAR_ITEM, ptClick, e);
441
+ }
442
+
443
+ this.TryClickPaintEvent=function(eventID, ptClick, e)
444
+ {
445
+ var event=this.GetEventCallback(eventID);
446
+ if (!event) return false;
447
+
448
+ if (ptClick.X==e.clientX && ptClick.Y==e.clientY)
449
+ {
450
+ var pixelTatio = GetDevicePixelRatio();
451
+ var x = (e.clientX-uielement.getBoundingClientRect().left)*pixelTatio;
452
+ var y = (e.clientY-uielement.getBoundingClientRect().top)*pixelTatio;
453
+
454
+ var toolTip=new TooltipData();
455
+ for(var i=0;i<this.ChartPaint.length;++i)
456
+ {
457
+ var item=this.ChartPaint[i];
458
+ if (item.GetTooltipData(x,y,toolTip))
459
+ {
460
+ if (toolTip.Data)
461
+ {
462
+ var data= { X:e.clientX, Y:e.clientY, Tooltip:toolTip };
463
+ event.Callback(event, data, this);
464
+ return true;
465
+ }
466
+ }
467
+ }
468
+ }
469
+
470
+ return false;
471
+ }
472
+
473
+ this.Draw=function()
474
+ {
475
+ if (this.UIElement.width<=0 || this.UIElement.height<=0) return;
476
+
477
+ this.Canvas.clearRect(0,0,this.UIElement.width,this.UIElement.height);
478
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
479
+ this.Canvas.lineWidth=pixelTatio; //手机端需要根据分辨率比调整线段宽度
480
+
481
+ this.Frame.Draw();
482
+ this.Frame.DrawLogo();
483
+
484
+ //框架内图形
485
+ for(var i=0;i<this.ChartPaint.length;++i)
486
+ {
487
+ var item=this.ChartPaint[i];
488
+ item.Draw();
489
+ }
490
+ }
491
+
492
+ this.OnSize=function()
493
+ {
494
+ if (!this.Frame) return;
495
+
496
+ this.SetSizeChange(true);
497
+ this.Draw();
498
+ }
499
+
500
+ this.SetSizeChange=function(bChanged)
501
+ {
502
+ for(var i=0;i<this.ChartPaint.length;++i)
503
+ {
504
+ var chart=this.ChartPaint[i];
505
+ if (chart) chart.SizeChange=bChanged;
506
+ }
507
+ }
508
+
509
+ this.ReloadResource=function(option)
510
+ {
511
+ this.Frame.ReloadResource(option);
512
+
513
+ for(var i=0;i<this.ChartPaint.length;++i)
514
+ {
515
+ var item=this.ChartPaint[i];
516
+ if (item.ReloadResource) item.ReloadResource(option);
517
+ }
518
+
519
+ if (option && (option.Redraw || option.Draw))
520
+ {
521
+ this.SetSizeChange(true);
522
+ this.Draw();
523
+ }
524
+ }
525
+
526
+ this.SetColumn=function(aryColunm, option)
527
+ {
528
+ var chart=this.ChartPaint[0];
529
+ if (!chart) return;
530
+
531
+ chart.SetColumn(aryColunm);
532
+ chart.SizeChange=true;
533
+
534
+ if (option && option.Redraw) this.Draw();
535
+ }
536
+
537
+ this.SetRightToolbar=function(toolbar, option)
538
+ {
539
+ var chart=this.ChartPaint[0];
540
+ if (!chart) return;
541
+
542
+ chart.SetRightToolbar(toolbar);
543
+ chart.SizeChange=true;
544
+
545
+ if (option && option.Redraw) this.Draw();
546
+ }
547
+
548
+ this.GetStatusBarChart=function()
549
+ {
550
+ var chart=this.ChartPaint[0];
551
+ if (!chart) return null;
552
+
553
+ return chart;
554
+ }
555
+ }
556
+
557
+ function JSStatusBarFrame()
558
+ {
559
+ this.ChartBorder;
560
+ this.Canvas; //画布
561
+
562
+ this.BorderLine=null; //1=上 2=下 4=左 8=右
563
+ this.ClassName="JSStatusBarFrame";
564
+
565
+ this.BorderColor=g_JSChartResource.StatusBar.BorderColor; //边框线
566
+
567
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
568
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
569
+
570
+ this.ReloadResource=function(resource)
571
+ {
572
+ this.BorderColor=g_JSChartResource.StatusBar.BorderColor; //边框线
573
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
574
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
575
+ }
576
+
577
+ this.Draw=function()
578
+ {
579
+ var left=ToFixedPoint(this.ChartBorder.GetLeft());
580
+ var top=ToFixedPoint(this.ChartBorder.GetTop());
581
+ var right=ToFixedPoint(this.ChartBorder.GetRight());
582
+ var bottom=ToFixedPoint(this.ChartBorder.GetBottom());
583
+ var width=right-left;
584
+ var height=bottom-top;
585
+
586
+ if (!IFrameSplitOperator.IsNumber(this.BorderLine))
587
+ {
588
+ this.Canvas.strokeStyle=this.BorderColor;
589
+ this.Canvas.strokeRect(left,top,width,height);
590
+ }
591
+ else
592
+ {
593
+ this.Canvas.strokeStyle=this.BorderColor;
594
+ this.Canvas.beginPath();
595
+
596
+ if ((this.BorderLine&1)>0) //上
597
+ {
598
+ this.Canvas.moveTo(left,top);
599
+ this.Canvas.lineTo(right,top);
600
+ }
601
+
602
+ if ((this.BorderLine&2)>0) //下
603
+ {
604
+ this.Canvas.moveTo(left,bottom);
605
+ this.Canvas.lineTo(right,bottom);
606
+ }
607
+
608
+ if ((this.BorderLine&4)>0) //左
609
+ {
610
+ this.Canvas.moveTo(left,top);
611
+ this.Canvas.lineTo(left,bottom);
612
+ }
613
+
614
+ if ((this.BorderLine&8)>0) //右
615
+ {
616
+ this.Canvas.moveTo(right,top);
617
+ this.Canvas.lineTo(right,bottom);
618
+ }
619
+
620
+ this.Canvas.stroke();
621
+ }
622
+ }
623
+
624
+ this.DrawLogo=function()
625
+ {
626
+ /*
627
+ var text=g_JSChartResource.FrameLogo.Text;
628
+ if (!IFrameSplitOperator.IsString(text)) return;
629
+
630
+ this.Canvas.fillStyle=this.LogoTextColor;
631
+ this.Canvas.font=this.LogoTextFont;
632
+ this.Canvas.textAlign = 'right';
633
+ this.Canvas.textBaseline = 'bottom';
634
+
635
+ var x=this.ChartBorder.GetRight()-30;
636
+ var y=this.ChartBorder.GetBottom()-5;
637
+ this.Canvas.fillText(text,x,y);
638
+ */
639
+ }
640
+ }
641
+
642
+
643
+ function ChartStatusBarStockData()
644
+ {
645
+ this.Canvas; //画布
646
+ this.ChartBorder; //边框信息
647
+ this.ChartFrame; //框架画法
648
+ this.Name; //名称
649
+ this.ClassName='ChartStatusBarStockData'; //类名
650
+ this.UIElement;
651
+ this.GetEventCallback; //获取事件
652
+ this.Data; //数据
653
+ this.SizeChange=true;
654
+
655
+ this.UpColor=g_JSChartResource.StatusBar.UpTextColor;
656
+ this.DownColor=g_JSChartResource.StatusBar.DownTextColor;
657
+ this.UnchangeColor=g_JSChartResource.StatusBar.UnchangeTextColor;
658
+
659
+ this.TableConfig=CloneData(g_JSChartResource.StatusBar.Table);
660
+ this.DateTimeConfig=CloneData(g_JSChartResource.StatusBar.DateTime);
661
+
662
+ //显示的字段
663
+ this.Column=
664
+ [
665
+ {
666
+ Symbol:"000001.sh",
667
+ Column:
668
+ [
669
+ { Name:"名称", Key:"Name", Text:"000001", },
670
+ { Name:"现价", Key:"Price", ColorType:3, FloatPrecision:-1, MaxText:"88888.88" },
671
+ { Name:"涨幅", Key:"Increase", ColorType:1, FloatPrecision:2, StringFormat:"{Value}%", MaxText:"888.88%" },
672
+ { Name:"涨跌", Key:"UpDown",ColorType:1, FloatPrecision:-1 },
673
+ { Name:"总额", Key:"Amount", FloatPrecision:0, Format:{ Type:3, ExFloatPrecision:2 }, ColorID:1 }
674
+ ]
675
+ },
676
+
677
+ {
678
+ Symbol:"600000.sh",
679
+ Column:
680
+ [
681
+ { Name:"名称", Key:"Name", Text:"600000", },
682
+ { Name:"现价", Key:"Price", ColorType:3, FloatPrecision:-1 },
683
+ { Name:"涨幅", Key:"Increase", ColorType:1, FloatPrecision:2, StringFormat:"{Value}%" },
684
+ { Name:"涨跌", Key:"UpDown",ColorType:1, FloatPrecision:-1 },
685
+ { Name:"总额", Key:"Amount", FloatPrecision:0, Format:{ Type:3, ExFloatPrecision:2 } }
686
+ ]
687
+ }
688
+ ]
689
+
690
+ this.RightToolbarConfig=CloneData(g_JSChartResource.StatusBar.RightToolbar);
691
+ this.MapToolbarFlash=new Map(); //key=id, Value:{ Counter:, Enable: }
692
+
693
+
694
+ //右侧工具栏
695
+ this.RightToolbar=
696
+ {
697
+ /*
698
+ AryButton:
699
+ [
700
+ { ID:2, Type:1, Icon:[{ Symbol:"\ue609", Color:"rgb(180,180,180)"} ] },
701
+
702
+ {
703
+ ID:1, Type:2, Icon:[{ Symbol:"\ue6d0", Color:"rgb(180,180,180)"} ],
704
+ Flash:
705
+ {
706
+ AryIcon:
707
+ [
708
+ [{ Symbol:"\ue6cb", Color:"rgb(0,191,255)"}],
709
+ [{ Symbol:"\ue6cb", Color:"rgb(255,165,0)"}],
710
+ [{ Symbol:"\ue6cb", Color:"rgb(255,215,0)"}],
711
+ ]
712
+ }
713
+ },
714
+ ]
715
+ */
716
+ }
717
+
718
+ this.AryRectCell=[];
719
+ this.AryRectButton=[];
720
+
721
+ this.ReloadResource=function(resource)
722
+ {
723
+ this.UpColor=g_JSChartResource.StatusBar.UpTextColor;
724
+ this.DownColor=g_JSChartResource.StatusBar.DownTextColor;
725
+ this.UnchangeColor=g_JSChartResource.StatusBar.UnchangeTextColor;
726
+
727
+ this.TableConfig=CloneData(g_JSChartResource.StatusBar.Table);
728
+ this.DateTimeConfig=CloneData(g_JSChartResource.StatusBar.DateTime);
729
+ }
730
+
731
+ this.SetColumn=function(aryColumn)
732
+ {
733
+ this.Column=[];
734
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryColumn)) return;
735
+
736
+ for(var i=0;i<aryColumn.length;++i)
737
+ {
738
+ var item=aryColumn[i];
739
+ if (!item) continue;
740
+ this.Column.push(CloneData(item));
741
+ }
742
+ }
743
+
744
+ this.SetRightToolbar=function(toolbar, option)
745
+ {
746
+ if (IFrameSplitOperator.IsNonEmptyArray(toolbar.AryButton))
747
+ {
748
+ this.RightToolbar.AryButton=toolbar.AryButton.slice();
749
+ for(var i=0;i<this.RightToolbar.AryButton.length;++i)
750
+ {
751
+ var item=this.RightToolbar.AryButton[i];
752
+ if (item.Type===2)
753
+ {
754
+ var value={ Counter:1, Enable:true };
755
+ if (IFrameSplitOperator.IsBool(item.Enable)) value.Enable=item.Enable;
756
+ this.MapToolbarFlash.set(item.ID, value)
757
+ }
758
+ }
759
+
760
+ }
761
+
762
+
763
+ }
764
+
765
+ this.Draw=function()
766
+ {
767
+ this.AryRectCell=[];
768
+ this.AryRectButton=[];
769
+
770
+ var border=this.ChartBorder.GetBorder();
771
+ var position = { Left:border.Left, Right:border.Right, Top:border.Top, Bottom:border.Bottom, Width:border.Right-border.Left, Border:border };
772
+ this.DrawRightToolbar(position);
773
+ this.DrawTable(position);
774
+ }
775
+
776
+ this.DrawTable=function(position)
777
+ {
778
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.Column)) return;
779
+
780
+ var config=this.TableConfig;
781
+ var top=position.Top;
782
+ var left=position.Left+config.Margin.Left;
783
+
784
+ var yText=top+config.Margin.Top;
785
+ var xText=left;
786
+
787
+ this.Canvas.font=config.Font;
788
+ this.Canvas.textAlign = 'left';
789
+ this.Canvas.textBaseline = 'bottom';
790
+ var cellHeight=this.Canvas.measureText("擎").width+config.CellMargin.Top+config.CellMargin.Bottom;
791
+ var itemPos={ Left:xText, Right:position.Right, Top:yText, Height:cellHeight, Bottom:yText+cellHeight, IsBreak:false, CellCount:0 };
792
+
793
+ for(var i=0;i<this.Column.length;++i)
794
+ {
795
+ var item=this.Column[i];
796
+ if (!item || !item.Symbol) continue;
797
+
798
+ var rtCell={ Left:itemPos.Left, Top:itemPos.Top, Bottom:itemPos.Bottom, Right:itemPos.Left };
799
+ this.DrawCellItem(item, itemPos );
800
+ if (itemPos.CellCount>0)
801
+ {
802
+ rtCell.Right=itemPos.Left;
803
+ rtCell.Width=rtCell.Right-itemPos.Left;
804
+ rtCell.Height=rtCell.Bottom-rtCell.Top;
805
+
806
+ this.AryRectCell.push({ Rect:rtCell, Data:item, Type:1 });
807
+ }
808
+
809
+ if (itemPos.IsBreak)
810
+ {
811
+ break;
812
+ }
813
+
814
+ itemPos.Left+=config.Separator.Left;
815
+ if (config.Separator.Line && config.Separator.Line.Color) //分割线
816
+ {
817
+ if (itemPos.Left>=itemPos.Right) break;
818
+
819
+ var subConfig=config.Separator.Line;
820
+ var lineWidth=1*GetDevicePixelRatio();
821
+ if (IFrameSplitOperator.IsNumber(subConfig.Width)) lineWidth=subConfig.Width;
822
+
823
+ this.Canvas.strokeStyle=subConfig.Color;
824
+ this.Canvas.beginPath();
825
+ this.Canvas.moveTo(ToFixedPoint(itemPos.Left),itemPos.Top+subConfig.Top);
826
+ this.Canvas.lineTo(ToFixedPoint(itemPos.Left),itemPos.Bottom-subConfig.Bottom);
827
+ this.Canvas.stroke();
828
+ }
829
+
830
+ itemPos.Left+=config.Separator.Right;
831
+ }
832
+ }
833
+
834
+ this.DrawCellItem=function(cellItem, itemPos)
835
+ {
836
+ var config=this.TableConfig;
837
+ var xText=itemPos.Left;
838
+ var yBottom=itemPos.Top+itemPos.Height-config.CellMargin.Bottom+config.CellMargin.YOffset;
839
+ var text=null;
840
+
841
+ var stockItem=null;
842
+ if (this.Data.MapSymbol.has(cellItem.Symbol)) stockItem=this.Data.MapSymbol.get(cellItem.Symbol);
843
+
844
+ for(var i=0;i<cellItem.Column.length ;++i)
845
+ {
846
+ var item=cellItem.Column[i];
847
+ if (!item) continue;
848
+
849
+ var color=config.AryTextColor[0];
850
+ var text=null;
851
+ if (stockItem && stockItem.MapData.has(item.Key))
852
+ {
853
+ var dataItem=stockItem.MapData.get(item.Key);
854
+ text=this.FormatValue(item, dataItem, stockItem);
855
+
856
+ if (IFrameSplitOperator.IsNumber(item.ColorID) && item.ColorID>=0 && item.ColorID<config.AryTextColor.length)
857
+ color=config.AryTextColor[item.ColorID];
858
+
859
+ if (item.ColorType===3 && IFrameSplitOperator.IsNumber(dataItem.Value))
860
+ color=this.GetPriceColor(dataItem.Value, stockItem);
861
+ else if (item.ColorType==1 && IFrameSplitOperator.IsNumber(dataItem.Value))
862
+ color=this.GetUpDownColor(dataItem.Value,0);
863
+ else if (item.ColorType==4)
864
+ color=this.UpColor;
865
+ else if (item.ColorType==5)
866
+ color=this.DownColor;
867
+
868
+ if (item.TextColor) color=item.TextColor;
869
+ }
870
+
871
+ if (!text && item.Text) text=item.Text;
872
+
873
+ if (text)
874
+ {
875
+ var textWidth=this.Canvas.measureText(text).width;
876
+ if (xText+textWidth+config.CellMargin.Left+config.CellMargin.Right>itemPos.Right)
877
+ {
878
+ itemPos.IsBreak=true;
879
+ break;
880
+ }
881
+ this.Canvas.fillStyle=color;
882
+ this.Canvas.fillText(text,xText+config.CellMargin.Left,yBottom);
883
+ xText+=(textWidth+config.CellMargin.Left+config.CellMargin.Right);
884
+ }
885
+ else if (item.MaxText)
886
+ {
887
+ text=item.MaxText;
888
+ var textWidth=this.Canvas.measureText(text).width;
889
+ xText+=(textWidth+config.CellMargin.Left+config.CellMargin.Right);
890
+ if (xText>itemPos.Right)
891
+ {
892
+ itemPos.IsBreak=true;
893
+ break;
894
+ }
895
+ }
896
+
897
+ ++itemPos.CellCount;
898
+ }
899
+
900
+ itemPos.Left=xText;
901
+
902
+ }
903
+
904
+
905
+ this.FormatValue=function(column, data, stockItem)
906
+ {
907
+ var dec=0; //小数位数
908
+ if (IFrameSplitOperator.IsNumber(column.FloatPrecision))
909
+ {
910
+ if (column.FloatPrecision===-1) dec=GetfloatPrecision(stockItem.Symbol);
911
+ else dec=column.FloatPrecision;
912
+ }
913
+
914
+ var text=null;
915
+ if (!data) return text;
916
+
917
+ if (data.Text)
918
+ {
919
+ text=data.Text;
920
+ }
921
+ else if (IFrameSplitOperator.IsNumber(data.Value))
922
+ {
923
+ var value=data.Value;
924
+ text=value.toFixed(dec);
925
+
926
+ //格式化
927
+ if (column.Format && IFrameSplitOperator.IsNumber(column.Format.Type))
928
+ {
929
+ var format=column.Format;
930
+ switch(format.Type)
931
+ {
932
+ case 1: //原始数据
933
+ text=value.toFixed(dec);
934
+ break;
935
+ case 2: //千分位分割
936
+ text=IFrameSplitOperator.FormatValueThousandsString(value, dec);
937
+ break;
938
+ case 3:
939
+ var exfloatPrecision=1;
940
+ if (IFrameSplitOperator.IsNumber(format.ExFloatPrecision)) exfloatPrecision=format.ExFloatPrecision;
941
+ text=IFrameSplitOperator.FormatValueStringV2(value, dec,exfloatPrecision);
942
+ break;
943
+ }
944
+ }
945
+ }
946
+
947
+ if (column.StringFormat && text) text=column.StringFormat.replace('{Value}',text);
948
+
949
+ return text;
950
+ }
951
+
952
+ this.GetPriceColor=function(price, stockItem)
953
+ {
954
+ var upperSymbol=null;
955
+ if (stockItem.Symbol) upperSymbol=stockItem.Symbol.toUpperCase();
956
+ if (MARKET_SUFFIX_NAME.IsChinaFutures(upperSymbol))
957
+ {
958
+ if (!IFrameSplitOperator.IsNumber(stockItem.YFClose)) return this.UnchangeColor;
959
+ return this.GetUpDownColor(price, stockItem.YFClose);
960
+ }
961
+ else
962
+ {
963
+ if (!IFrameSplitOperator.IsNumber(stockItem.YClose)) return this.UnchangeColor;
964
+ return this.GetUpDownColor(price, stockItem.YClose);
965
+ }
966
+ }
967
+
968
+ this.GetUpDownColor=function(price, price2)
969
+ {
970
+ if (price>price2) return this.UpColor;
971
+ else if (price<price2) return this.DownColor;
972
+ else return this.UnchangeColor;
973
+ }
974
+
975
+ this.DrawRightToolbar=function(position)
976
+ {
977
+ var config=this.DateTimeConfig;
978
+ var top=position.Top;
979
+ var right=position.Right;
980
+
981
+ this.Canvas.font=config.Font;
982
+ this.Canvas.textAlign = 'left';
983
+ this.Canvas.textBaseline = 'bottom';
984
+ var cellHeight=this.Canvas.measureText("擎").width+config.Margin.Top+config.Margin.Bottom;
985
+
986
+ var yBottom=top+cellHeight-config.Margin.Bottom+config.Margin.YOffset;
987
+ var xText=right;
988
+
989
+ //时间
990
+ var datetime=new Date();
991
+ var text=IFrameSplitOperator.FormatDateTimeStringV2(datetime, config.Format);
992
+ var textWidth=this.Canvas.measureText(config.MaxText).width+config.Margin.Left+config.Margin.Right;
993
+ xText-=textWidth;
994
+ this.Canvas.fillStyle=config.TitleColor;
995
+ this.Canvas.fillText(text,xText+config.Margin.Left,yBottom);
996
+
997
+ position.Right=xText;
998
+
999
+ if (this.RightToolbar && IFrameSplitOperator.IsNonEmptyArray(this.RightToolbar.AryButton))
1000
+ {
1001
+ var config=this.RightToolbarConfig;
1002
+
1003
+ xText-=config.Margin.Right;
1004
+ for(var i=this.RightToolbar.AryButton.length-1;i>=0;--i)
1005
+ {
1006
+ var item=this.RightToolbar.AryButton[i];
1007
+ var aryItem=null;
1008
+ if (item.Type==2) aryItem=this.GetFlashToolbarItem(item);
1009
+ else aryItem=item.Icon;
1010
+ if (!IFrameSplitOperator.IsNonEmptyArray(aryItem)) continue;
1011
+ var iconFont=`${config.Icon.Size}px ${config.Icon.Family}`;
1012
+ this.Canvas.font=iconFont;
1013
+ var textWidth=config.Icon.Size+config.CellMargin.Left+config.CellMargin.Right;
1014
+ xText-=textWidth;
1015
+ yBottom=top+config.Margin.Top+(config.Icon.Size+config.CellMargin.Top+config.CellMargin.Bottom)-config.CellMargin.Bottom+config.CellMargin.YOffset;
1016
+ for(var j=0;j<aryItem.length;++j)
1017
+ {
1018
+ var iconItem=aryItem[j];
1019
+ var text=iconItem.Symbol;
1020
+ this.Canvas.fillStyle=iconItem.Color;
1021
+ this.Canvas.fillText(text,xText+config.CellMargin.Left,yBottom);
1022
+ }
1023
+
1024
+ var rtButton={ Left:xText, Bottom:yBottom, Height:config.Icon.Size, Width:config.Icon.Size };
1025
+ rtButton.Right=rtButton.Left+rtButton.Width;
1026
+ rtButton.Top=rtButton.Bottom-rtButton.Height;
1027
+ this.AryRectButton.push({ Rect:rtButton, Data:item, Type:2 });
1028
+ }
1029
+ }
1030
+
1031
+ position.Right=xText;
1032
+ }
1033
+
1034
+ this.GetFlashToolbarItem=function(btnItem)
1035
+ {
1036
+ if (!btnItem.Flash || !IFrameSplitOperator.IsNonEmptyArray(btnItem.Flash.AryIcon)) return btnItem.Icon;
1037
+ if (!this.MapToolbarFlash.has(btnItem.ID)) return btnItem.Icon;
1038
+
1039
+ var item=this.MapToolbarFlash.get(btnItem.ID);
1040
+ if (!item.Enable) return btnItem.Icon;
1041
+
1042
+ item.Counter++;
1043
+
1044
+ var index=item.Counter%btnItem.Flash.AryIcon.length;
1045
+
1046
+ return btnItem.Flash.AryIcon[index];
1047
+ }
1048
+
1049
+ this.GetTooltipData=function(x,y,tooltip)
1050
+ {
1051
+ for(var i=0;i<this.AryRectCell.length;++i)
1052
+ {
1053
+ var item=this.AryRectCell[i];
1054
+ if (Path2DHelper.PtInRect(x,y, item.Rect))
1055
+ {
1056
+ tooltip.Data=item;
1057
+ tooltip.ChartPaint=this;
1058
+ tooltip.Type=21;
1059
+ return true;
1060
+ }
1061
+ }
1062
+
1063
+ for(var i=0;i<this.AryRectButton.length;++i)
1064
+ {
1065
+ var item=this.AryRectButton[i];
1066
+ if (Path2DHelper.PtInRect(x,y, item.Rect))
1067
+ {
1068
+ tooltip.Data=item;
1069
+ tooltip.ChartPaint=this;
1070
+ tooltip.Type=22;
1071
+ return true;
1072
+ }
1073
+ }
1074
+
1075
+ return false;
1076
+ }
1077
+ }