hqchart 1.1.12729 → 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,1345 @@
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 JSScrollBarChart(divElement)
15
+ {
16
+ this.DivElement=divElement;
17
+ this.JSChartContainer; //表格控件
18
+
19
+ //h5 canvas
20
+ this.CanvasElement=document.createElement("canvas");
21
+ this.CanvasElement.className='jsscrollbar-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("[JSScrollBarChart::JSScrollBarChart] 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(`[JSScrollBarChart::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.CreateJSScrollBarChartContainer(option);
56
+
57
+ if (!chart) return false;
58
+
59
+ if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
60
+
61
+ chart.Draw();
62
+
63
+ this.JSChartContainer=chart;
64
+ this.DivElement.JSChart=this; //div中保存一份
65
+ }
66
+
67
+ this.CreateJSScrollBarChartContainer=function(option)
68
+ {
69
+ var chart=new JSScrollBarChartContainer(this.CanvasElement);
70
+ chart.Create(option);
71
+
72
+ if (IFrameSplitOperator.IsNumber(option.DelayDragFrequency)) chart.DelayDragFrequency=option.DelayDragFrequency;
73
+
74
+ this.SetChartBorder(chart, option);
75
+
76
+ //注册事件
77
+ if (option.EventCallback)
78
+ {
79
+ for(var i=0;i<option.EventCallback.length;++i)
80
+ {
81
+ var item=option.EventCallback[i];
82
+ chart.AddEventCallback(item);
83
+ }
84
+ }
85
+
86
+ return chart;
87
+ }
88
+
89
+ this.SetChartBorder=function(chart, option)
90
+ {
91
+ if (!option.Border) return;
92
+
93
+ var item=option.Border;
94
+ if (IFrameSplitOperator.IsNumber(option.Border.Left)) chart.Frame.ChartBorder.Left=option.Border.Left;
95
+ if (IFrameSplitOperator.IsNumber(option.Border.Right)) chart.Frame.ChartBorder.Right=option.Border.Right;
96
+ if (IFrameSplitOperator.IsNumber(option.Border.Top)) chart.Frame.ChartBorder.Top=option.Border.Top;
97
+ if (IFrameSplitOperator.IsNumber(option.Border.Bottom)) chart.Frame.ChartBorder.Bottom=option.Border.Bottom;
98
+
99
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
100
+ chart.Frame.ChartBorder.Left*=pixelTatio;
101
+ chart.Frame.ChartBorder.Right*=pixelTatio;
102
+ chart.Frame.ChartBorder.Top*=pixelTatio;
103
+ chart.Frame.ChartBorder.Bottom*=pixelTatio;
104
+
105
+ if (IFrameSplitOperator.IsBool(item.AutoLeft)) chart.AutoMargin.Left=item.AutoLeft;
106
+ if (IFrameSplitOperator.IsBool(item.AutoRight)) chart.AutoMargin.Right=item.AutoRight;
107
+ }
108
+
109
+ /////////////////////////////////////////////////////////////////////////////
110
+ //对外接口
111
+
112
+ //事件回调
113
+ this.AddEventCallback=function(obj)
114
+ {
115
+ if(this.JSChartContainer && typeof(this.JSChartContainer.AddEventCallback)=='function')
116
+ {
117
+ JSConsole.Chart.Log('[JSScrollBarChart:AddEventCallback] obj=', obj);
118
+ this.JSChartContainer.AddEventCallback(obj);
119
+ }
120
+ }
121
+
122
+ //重新加载配置
123
+ this.ReloadResource=function(option)
124
+ {
125
+ if(this.JSChartContainer && typeof(this.JSChartContainer.ReloadResource)=='function')
126
+ {
127
+ JSConsole.Chart.Log('[JSScrollBarChart:ReloadResource] ');
128
+ this.JSChartContainer.ReloadResource(option);
129
+ }
130
+ }
131
+
132
+ this.ChartDestory=function()
133
+ {
134
+ if (this.JSChartContainer && typeof (this.JSChartContainer.ChartDestory) == 'function')
135
+ {
136
+ this.JSChartContainer.ChartDestory();
137
+ }
138
+ }
139
+
140
+ this.Draw=function()
141
+ {
142
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Draw)=='function')
143
+ {
144
+ JSConsole.Chart.Log('[JSScrollBarChart:Draw] ');
145
+ this.JSChartContainer.Draw();
146
+ }
147
+ }
148
+
149
+ this.RecvData=function(data, option)
150
+ {
151
+ if(this.JSChartContainer && typeof(this.JSChartContainer.RecvData)=='function')
152
+ {
153
+ JSConsole.Chart.Log('[JSScrollBarChart:RecvData] ');
154
+ this.JSChartContainer.RecvData(data,option);
155
+ }
156
+ }
157
+
158
+ this.UpdateSlider=function(obj)
159
+ {
160
+ if(this.JSChartContainer && typeof(this.JSChartContainer.UpdateSlider)=='function')
161
+ {
162
+ JSConsole.Chart.Log('[JSScrollBarChart:UpdateSlider] ');
163
+ this.JSChartContainer.UpdateSlider(obj);
164
+ }
165
+ }
166
+
167
+ this.Reset=function(option)
168
+ {
169
+ if(this.JSChartContainer && typeof(this.JSChartContainer.Reset)=='function')
170
+ {
171
+ JSConsole.Chart.Log('[JSScrollBarChart:Reset] ');
172
+ this.JSChartContainer.Reset(option);
173
+ }
174
+ }
175
+
176
+ //重新加载配置
177
+ this.ReloadResource=function(option)
178
+ {
179
+ if(this.JSChartContainer && typeof(this.JSChartContainer.ReloadResource)=='function')
180
+ {
181
+ JSConsole.Chart.Log('[JSScrollBarChart:ReloadResource] ');
182
+ this.JSChartContainer.ReloadResource(option);
183
+ }
184
+ }
185
+ }
186
+
187
+
188
+ JSScrollBarChart.Init=function(divElement)
189
+ {
190
+ var jsChartControl=new JSScrollBarChart(divElement);
191
+ jsChartControl.OnSize();
192
+
193
+ return jsChartControl;
194
+ }
195
+
196
+ //自定义风格
197
+ JSScrollBarChart.SetStyle=function(option)
198
+ {
199
+ if (option) g_JSChartResource.SetStyle(option);
200
+ }
201
+
202
+ //获取颜色配置 (设置配必须啊在JSChart.Init()之前)
203
+ JSScrollBarChart.GetResource=function()
204
+ {
205
+ return g_JSChartResource;
206
+ }
207
+
208
+
209
+
210
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////
211
+ //
212
+ //
213
+ //
214
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////
215
+ function JSScrollBarChartContainer(uielement)
216
+ {
217
+ this.ClassName='JSScrollBarChartContainer';
218
+ this.Frame; //框架画法
219
+ this.ChartPaint=[]; //图形画法
220
+ this.ChartSplashPaint=null; //等待提示
221
+ this.LoadDataSplashTitle="无数据"; //下载数据提示信息
222
+
223
+ this.Canvas=uielement.getContext("2d"); //画布
224
+ this.ShowCanvas=null;
225
+
226
+ this.XOffsetData={ Start:-1, End:-1, Count:0 }; //Count:一共的数据个数
227
+ this.SourceData// new ChartData(); //K线数据
228
+
229
+ this.SliderChart; //滑块
230
+
231
+ this.DragMove; //={ Click:{ 点击的点}, Move:{最后移动的点}, PreMove:{上一个点的位置} };
232
+ this.DragSlider;
233
+ this.DragTimer; //拖拽延迟定时器
234
+ this.DelayDragFrequency=150;
235
+
236
+ this.AutoMargin={ Left:false, Right:false }; //左右2边间距是否跟K线一致
237
+
238
+ //事件回调
239
+ this.mapEvent=new Map(); //通知外部调用 key:JSCHART_EVENT_ID value:{Callback:回调,}
240
+
241
+ this.UIElement=uielement;
242
+ this.LastPoint=new Point(); //鼠标位置
243
+
244
+ //this.XStepPixel=10*GetDevicePixelRatio();
245
+ this.IsDestroy=false; //是否已经销毁了
246
+
247
+ this.HQChart=null;
248
+
249
+ this.ChartDestory=function() //销毁
250
+ {
251
+ this.IsDestroy=true;
252
+ }
253
+
254
+ //设置事件回调
255
+ //{event:事件id, callback:回调函数}
256
+ this.AddEventCallback=function(object)
257
+ {
258
+ if (!object || !object.event || !object.callback) return;
259
+
260
+ var data={Callback:object.callback, Source:object};
261
+ this.mapEvent.set(object.event,data);
262
+ }
263
+
264
+ this.RemoveEventCallback=function(eventid)
265
+ {
266
+ if (!this.mapEvent.has(eventid)) return;
267
+
268
+ this.mapEvent.delete(eventid);
269
+ }
270
+
271
+ this.GetEventCallback=function(id) //获取事件回调
272
+ {
273
+ if (!this.mapEvent.has(id)) return null;
274
+ var item=this.mapEvent.get(id);
275
+ return item;
276
+ }
277
+
278
+ //创建
279
+ this.Create=function(option)
280
+ {
281
+ this.UIElement.JSChartContainer=this;
282
+
283
+ //创建等待提示
284
+ this.ChartSplashPaint = new ChartSplashPaint();
285
+ this.ChartSplashPaint.Canvas = this.Canvas;
286
+ this.ChartSplashPaint.SetTitle(this.LoadDataSplashTitle);
287
+ this.ChartSplashPaint.IsEnableSplash=true;
288
+
289
+ //创建框架
290
+ this.Frame=new JSScrollBarFrame();
291
+ this.Frame.ChartBorder=new ChartBorder();
292
+ this.Frame.ChartBorder.UIElement=this.UIElement;
293
+ this.Frame.ChartBorder.Top=30;
294
+ this.Frame.ChartBorder.Left=5;
295
+ this.Frame.ChartBorder.Bottom=20;
296
+ this.Frame.Canvas=this.Canvas;
297
+
298
+ this.ChartSplashPaint.Frame = this.Frame;
299
+
300
+ //背景
301
+ var chart=new ScrollBarBGChart();
302
+ chart.ChartFrame=this.Frame;
303
+ chart.ChartBorder=this.Frame.ChartBorder;
304
+ chart.Canvas=this.Canvas;
305
+ chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
306
+ this.ChartPaint.push(chart);
307
+
308
+ //创建滑块
309
+ var chart=new SliderChart();
310
+ chart.ChartFrame=this.Frame;
311
+ chart.ChartBorder=this.Frame.ChartBorder;
312
+ chart.Canvas=this.Canvas;
313
+ chart.OffsetData=this.XOffsetData;
314
+ chart.GetEventCallback=(id)=> { return this.GetEventCallback(id); }
315
+ this.SliderChart=chart;
316
+ this.ChartPaint.push(chart);
317
+
318
+ //this.UIElement.ondblclick=(e)=>{ this.UIOnDblClick(e); }
319
+ this.UIElement.onmousedown=(e)=> { this.UIOnMouseDown(e); }
320
+ this.UIElement.oncontextmenu=(e)=> { this.UIOnContextMenu(e); }
321
+ this.UIElement.onmousemove=(e)=>{ this.UIOnMouseMove(e);}
322
+ this.UIElement.onmouseout=(e)=>{ this.UIOnMounseOut(e); }
323
+ this.UIElement.onmouseleave=(e)=>{ this.UIOnMouseleave(e); }
324
+
325
+
326
+ //手机拖拽
327
+ //this.UIElement.ontouchstart=(e)=> { this.OnTouchStart(e); }
328
+ //this.UIElement.ontouchmove=(e)=> {this.OnTouchMove(e); }
329
+ //this.UIElement.ontouchend=(e)=> {this.OnTouchEnd(e); }
330
+ }
331
+
332
+ this.Draw=function()
333
+ {
334
+ if (this.UIElement.width<=0 || this.UIElement.height<=0) return;
335
+
336
+ this.Canvas.clearRect(0,0,this.UIElement.width,this.UIElement.height);
337
+ var pixelTatio = GetDevicePixelRatio(); //获取设备的分辨率
338
+ this.Canvas.lineWidth=pixelTatio; //手机端需要根据分辨率比调整线段宽度
339
+
340
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash)
341
+ {
342
+ this.Frame.Draw( { IsEnableSplash:this.ChartSplashPaint.IsEnableSplash} );
343
+ this.ChartSplashPaint.Draw();
344
+ return;
345
+ }
346
+
347
+ this.Frame.Draw();
348
+ this.Frame.DrawLogo();
349
+
350
+ //框架内图形
351
+ for(var i=0;i<this.ChartPaint.length;++i)
352
+ {
353
+ var item=this.ChartPaint[i];
354
+ if (item.IsDrawFirst)
355
+ item.Draw();
356
+ }
357
+
358
+ for(var i=0; i<this.ChartPaint.length; ++i)
359
+ {
360
+ var item=this.ChartPaint[i];
361
+ if (!item.IsDrawFirst)
362
+ item.Draw();
363
+ }
364
+ }
365
+
366
+
367
+ this.OnSize=function()
368
+ {
369
+ if (!this.Frame) return;
370
+
371
+ this.SetSizeChange(true);
372
+ this.Draw();
373
+ }
374
+
375
+ this.SetSizeChange=function(bChanged)
376
+ {
377
+ for(var i=0;i<this.ChartPaint.length;++i)
378
+ {
379
+ var chart=this.ChartPaint[i];
380
+ if (chart) chart.SizeChange=bChanged;
381
+ }
382
+ }
383
+
384
+ this.UpdateFrameMaxMin=function()
385
+ {
386
+ var max=null, min=null;
387
+ for(var i=0;i<this.ChartPaint.length;++i)
388
+ {
389
+ var item=this.ChartPaint[i];
390
+ if (!item.GetMaxMin) continue;
391
+
392
+ var range=item.GetMaxMin();
393
+ if (range==null || range.Max==null || range.Min==null) continue;
394
+
395
+ if (max==null || max<range.Max) max=range.Max;
396
+ if (min==null || min>range.Min) min=range.Min;
397
+ }
398
+
399
+ if (IFrameSplitOperator.IsNumber(max) && IFrameSplitOperator.IsNumber(min))
400
+ {
401
+ this.Frame.HorizontalMax=max;
402
+ this.Frame.HorizontalMin=min;
403
+ }
404
+ }
405
+
406
+ //未启动
407
+ this.UIOnDblClick=function(e)
408
+ {
409
+
410
+ }
411
+
412
+ this.CancelDragTimer=function()
413
+ {
414
+ if (this.DragTimer)
415
+ {
416
+ clearTimeout(this.DragTimer);
417
+ this.DragTimer=null;
418
+ }
419
+ }
420
+
421
+ this.UIOnMouseDown=function(e)
422
+ {
423
+ this.CancelDragTimer();
424
+ this.DragSlider=null;
425
+ this.DragMove={ Click:{ X:e.clientX, Y:e.clientY }, Move:{X:e.clientX, Y:e.clientY}, PreMove:{X:e.clientX, Y:e.clientY } };
426
+
427
+ var pixelTatio = GetDevicePixelRatio();
428
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
429
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
430
+
431
+ if (this.SliderChart)
432
+ {
433
+ var clickData=this.SliderChart.PtInChart(x,y);
434
+ if (!clickData) return;
435
+
436
+ this.DragSlider={ Click:{ X:e.clientX, Y:e.clientY }, LastMove:{X:e.clientX, Y:e.clientY}, Data:clickData };
437
+ this.DragSlider.DrawCount=0; //重绘次数
438
+ }
439
+
440
+ document.onmousemove=(e)=>{ this.DocOnMouseMove(e); }
441
+ document.onmouseup=(e)=> { this.DocOnMouseUp(e); }
442
+ }
443
+
444
+ //去掉右键菜单
445
+ this.UIOnContextMenu=function(e)
446
+ {
447
+ e.preventDefault();
448
+ }
449
+
450
+ this.UIOnMouseMove=function(e)
451
+ {
452
+ var pixelTatio = GetDevicePixelRatio();
453
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
454
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
455
+
456
+ if (this.DragSlider) return;
457
+
458
+ var mouseStatus= mouseStatus={ Cursor:"default" };; //鼠标状态
459
+ var item=this.SliderChart.PtInChart(x,y);
460
+ if (item)
461
+ {
462
+ switch(item.Data.Type)
463
+ {
464
+ case 0:
465
+ mouseStatus={ Cursor:"move", Name:"SliderChart"};
466
+ break;
467
+ case 1:
468
+ case 2:
469
+ mouseStatus={ Cursor:"ew-resize", Name:"SliderChart"};
470
+ break;
471
+ }
472
+ }
473
+
474
+ if (mouseStatus)
475
+ this.UIElement.style.cursor=mouseStatus.Cursor;
476
+ }
477
+
478
+ this.UIOnMounseOut=function(e)
479
+ {
480
+
481
+ }
482
+
483
+ this.UIOnMouseleave=function(e)
484
+ {
485
+
486
+ }
487
+
488
+ this.DocOnMouseMove=function(e)
489
+ {
490
+ this.DragMove.PreMove.X=this.DragMove.Move.X;
491
+ this.DragMove.PreMove.Y=this.DragMove.Move.Y;
492
+ this.DragMove.Move.X=e.clientX;
493
+ this.DragMove.Move.Y=e.clientX;
494
+
495
+ if (this.ChartSplashPaint && this.ChartSplashPaint.IsEnableSplash == true) return;
496
+
497
+ var pixelTatio = GetDevicePixelRatio();
498
+ var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
499
+ var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
500
+
501
+ JSConsole.Chart.Log(`[JSScrollBarChartContainer::DocOnMouseMove] x=${x}, y=${y}`);
502
+
503
+ if (this.DragSlider)
504
+ {
505
+ var drag=this.DragSlider;
506
+ var moveSetp=(e.clientX-drag.LastMove.X)*pixelTatio;
507
+ if (Math.abs(moveSetp)<1) return;
508
+
509
+ var pageRange=this.GetPageRange();
510
+ var left=this.Frame.ChartBorder.GetLeft();
511
+ var right=this.Frame.ChartBorder.GetRight();
512
+ this.SliderChart.DragMode=true;
513
+ var type=drag.Data.Data.Type;
514
+ var xStart=this.SliderChart.XStart+moveSetp;
515
+ var xEnd=this.SliderChart.XEnd+moveSetp;
516
+
517
+ if (type==0) //整体移动
518
+ {
519
+ if (xStart<left) //第1页
520
+ {
521
+ xStart=pageRange.First.XStart;
522
+ xEnd=pageRange.First.XEnd;
523
+ }
524
+ else if (xEnd>=right)
525
+ {
526
+ xStart=pageRange.Last.XStart;
527
+ xEnd=pageRange.Last.XEnd;
528
+ }
529
+
530
+ this.SliderChart.XStart=xStart;
531
+ this.SliderChart.XEnd=xEnd;
532
+ }
533
+ else if (type==1) //左移动
534
+ {
535
+ if (xStart<=left)
536
+ {
537
+ xStart=pageRange.First.XStart;
538
+ }
539
+
540
+ this.SliderChart.XStart=xStart;
541
+ }
542
+ else if (type==2)
543
+ {
544
+ if (xEnd>=right)
545
+ {
546
+ xEnd=pageRange.Last.XEnd;
547
+ }
548
+
549
+ this.SliderChart.XEnd=xEnd;
550
+ }
551
+
552
+ drag.UpdateData={ XStart:xStart, XEnd:xEnd, Type:type };
553
+ drag.LastMove.X=e.clientX;
554
+ drag.LastMove.Y=e.clientY;
555
+
556
+ if (drag.DrawCount==0)
557
+ {
558
+ this.DragUpdate(drag);
559
+ }
560
+ else
561
+ {
562
+ this.DragTimer=setTimeout(()=>
563
+ {
564
+ this.DragUpdate(this.DragSlider);
565
+ }, this.DelayDragFrequency);
566
+ }
567
+ }
568
+ }
569
+
570
+ this.DocOnMouseUp=function(e)
571
+ {
572
+ //清空事件
573
+ document.onmousemove=null;
574
+ document.onmouseup=null;
575
+
576
+ this.CancelDragTimer();
577
+ var dragSlider=this.DragSlider;
578
+ this.DragMove=null;
579
+ this.DragSlider=null;
580
+ this.SliderChart.DragMode=false;
581
+
582
+ this.DragUpdate(dragSlider);
583
+ }
584
+
585
+ this.DragUpdate=function(dragData)
586
+ {
587
+ if (!dragData || !dragData.UpdateData) return;
588
+
589
+ this.UpdateXDataOffset(dragData.UpdateData);
590
+ this.Draw();
591
+ ++dragData.DrawCount;
592
+ }
593
+
594
+ this.Reset=function(option)
595
+ {
596
+ this.SourceData=null;
597
+ this.XOffsetData.Start=-1;
598
+ this.XOffsetData.End=-1;
599
+ this.XOffsetData.Count=0;
600
+
601
+ this.Frame.Data=null;
602
+ for(var i=0;i<this.ChartPaint.length;++i)
603
+ {
604
+ var item=this.ChartPaint[i];
605
+ item.Data=null;
606
+ }
607
+
608
+ if (this.ChartSplashPaint)
609
+ this.ChartSplashPaint.IsEnableSplash=true;
610
+
611
+ if (option.Draw) this.Draw();
612
+ }
613
+
614
+ //外部更新滑块 obj={ Start: , End: }
615
+ this.UpdateSlider=function(obj)
616
+ {
617
+ if (this.SliderChart.DragMode) return;
618
+
619
+ var bSizeChange=false;
620
+ if ((this.AutoMargin.Left || this.AutoMargin.Right) && obj.Border)
621
+ {
622
+ if (this.AutoMargin.Left)
623
+ {
624
+ if (this.Frame.ChartBorder.Left!=obj.Border.Left) bSizeChange=true;
625
+ }
626
+
627
+ if (this.AutoMargin.Right)
628
+ {
629
+ if (this.Frame.ChartBorder.Right!=obj.Border.Right) bSizeChange=true;
630
+ }
631
+ }
632
+
633
+ var data=obj.Data;
634
+ if (this.XOffsetData.Start==obj.Start && this.XOffsetData.End==obj.End && this.SourceData==data && !bSizeChange) return;
635
+
636
+ this.SourceData=data;
637
+ var count=data.Data.length;
638
+ if (IFrameSplitOperator.IsNumber(obj.RightSpaceCount)) count+=obj.RightSpaceCount;
639
+ this.Frame.XPointCount=count;
640
+ this.Frame.Data=data;
641
+ this.XOffsetData.Count=count;
642
+ this.XOffsetData.Start=obj.Start;
643
+ this.XOffsetData.End=obj.End;
644
+
645
+ for(var i=0;i<this.ChartPaint.length;++i)
646
+ {
647
+ var item=this.ChartPaint[i];
648
+ item.Data=data;
649
+ }
650
+
651
+ if (this.AutoMargin.Left && obj.Border)
652
+ {
653
+ if (IFrameSplitOperator.IsNumber(obj.Border.Left))
654
+ this.Frame.ChartBorder.Left=obj.Border.Left;
655
+ }
656
+
657
+ if (this.AutoMargin.Right && obj.Border)
658
+ {
659
+ if (IFrameSplitOperator.IsNumber(obj.Border.Right))
660
+ this.Frame.ChartBorder.Right=obj.Border.Right;
661
+ }
662
+
663
+ this.UpdateFrameMaxMin();
664
+
665
+ if (this.ChartSplashPaint)
666
+ this.ChartSplashPaint.IsEnableSplash=false;
667
+
668
+ if (obj.Draw) this.Draw();
669
+ }
670
+
671
+ //移动滑块
672
+ this.UpdateXDataOffset=function(obj)
673
+ {
674
+ if (obj.Type==0)
675
+ {
676
+ var start=this.Frame.GetXData(obj.XStart);
677
+ start=parseInt(start);
678
+ var moveSetp=start-this.XOffsetData.Start;
679
+
680
+ this.XOffsetData.Start=start;
681
+ this.XOffsetData.End+=moveSetp;
682
+ }
683
+ else if (obj.Type==1)
684
+ {
685
+ var start=this.Frame.GetXData(obj.XStart);
686
+ start=parseInt(start);
687
+ this.XOffsetData.Start=start;
688
+ }
689
+ else if (obj.Type==2)
690
+ {
691
+ var end=this.Frame.GetXData(obj.XEnd);
692
+ end=parseInt(end);
693
+ this.XOffsetData.End=end;
694
+ }
695
+
696
+ var endItem=this.SourceData.Data[this.XOffsetData.End];
697
+ var startItem=this.SourceData.Data[this.XOffsetData.Start];
698
+
699
+ var sendData={ Type:obj.Type, Count:this.XOffsetData.Count };
700
+ if (this.XOffsetData.End>this.XOffsetData.Start)
701
+ {
702
+ sendData.Start={ Index:this.XOffsetData.Start, Item:startItem};
703
+ sendData.End={ Index:this.XOffsetData.End, Item:endItem};
704
+ }
705
+ else
706
+ {
707
+ sendData.Start={ Index:this.XOffsetData.End, Item:endItem };
708
+ sendData.End={ Index:this.XOffsetData.Start, Item:startItem };
709
+ }
710
+
711
+ if (this.HQChart && this.HQChart.JSChartContainer)
712
+ {
713
+ var internalChart=this.HQChart.JSChartContainer;
714
+ if (internalChart.ChartOperator)
715
+ {
716
+ var obj={ ID:JSCHART_OPERATOR_ID.OP_SCROOLBAR_SLIDER_CHANGED, Start:sendData.Start, End:sendData.End, Type:sendData.Type };
717
+ internalChart.ChartOperator(obj);
718
+ }
719
+ }
720
+
721
+ var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_SCROLLBAR_SLIDER_CHANGED);
722
+ if (event)
723
+ {
724
+ event.Callback(event,sendData,this);
725
+ }
726
+ }
727
+
728
+
729
+ this.ReloadResource=function(option)
730
+ {
731
+ this.Frame.ReloadResource(option);
732
+
733
+ for(var i=0;i<this.ChartPaint.length;++i)
734
+ {
735
+ var item=this.ChartPaint[i];
736
+ if (item.ReloadResource) item.ReloadResource(option);
737
+ }
738
+
739
+ if (option && option.Redraw)
740
+ {
741
+ this.SetSizeChange(true);
742
+ this.Draw();
743
+ }
744
+ }
745
+
746
+ this.GetPageRange=function()
747
+ {
748
+ var result={};
749
+ var showCount=Math.abs(this.XOffsetData.Start-this.XOffsetData.End);
750
+ result.ShowCount=showCount;
751
+
752
+ //第1页
753
+ var xStart=this.Frame.GetXFromIndex(0);
754
+ var xEnd=this.Frame.GetXFromIndex(showCount);
755
+ result.First={ XStart:xStart, XEnd:xEnd };
756
+
757
+ //最后一页
758
+ var end=this.Frame.XPointCount-1;
759
+ var xEnd=this.Frame.GetXFromIndex(end);
760
+ var xStart=this.Frame.GetXFromIndex(end-showCount);
761
+ result.Last={ XStart:xStart, XEnd:xEnd };
762
+
763
+ return result;
764
+ }
765
+
766
+ this.ReloadResource=function(option)
767
+ {
768
+ this.Frame.ReloadResource(option);
769
+ for(var i=0; i<this.ChartPaint.length; ++i)
770
+ {
771
+ var item=this.ChartPaint[i];
772
+ if (item.ReloadResource) item.ReloadResource(option);
773
+ }
774
+
775
+ if (option.Draw==true) this.Draw(); //是否立即重绘
776
+ }
777
+ }
778
+
779
+ /////////////////////////////////////////////////////////////////////////////////////////
780
+ // 框子
781
+ //
782
+ //
783
+ /////////////////////////////////////////////////////////////////////////////////////////
784
+
785
+ function JSScrollBarFrame()
786
+ {
787
+ this.ChartBorder;
788
+ this.Canvas; //画布
789
+ this.BorderLine=null; //1=上 2=下 4=左 8=右
790
+ this.Data;
791
+ this.Count=0;
792
+ this.ClassName='JSScrollBarFrame'; //类名
793
+
794
+ this.HorizontalMax=10; //Y轴最大值
795
+ this.HorizontalMin=5; //Y轴最小值
796
+ this.XPointCount=0;
797
+
798
+ this.XSplitTextFont=g_JSChartResource.ScrollBar.XSplitTextFont;
799
+ this.XSplitTextColor=g_JSChartResource.ScrollBar.XSplitTextColor;
800
+ this.XSplitLineColor=g_JSChartResource.ScrollBar.XSplitLineColor;
801
+
802
+ this.BorderColor=g_JSChartResource.ScrollBar.BorderColor; //边框线
803
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
804
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
805
+
806
+ this.ReloadResource=function(resource)
807
+ {
808
+ this.BorderColor=g_JSChartResource.ScrollBar.BorderColor; //边框线
809
+ this.LogoTextColor=g_JSChartResource.FrameLogo.TextColor;
810
+ this.LogoTextFont=g_JSChartResource.FrameLogo.Font;
811
+ }
812
+
813
+ this.Draw=function()
814
+ {
815
+ this.DrawBorder();
816
+ this.DrawLogo();
817
+ this.DrawVertical();
818
+ }
819
+
820
+ this.DrawLogo=function()
821
+ {
822
+ var text=g_JSChartResource.FrameLogo.Text;
823
+ if (!IFrameSplitOperator.IsString(text)) return;
824
+
825
+ this.Canvas.fillStyle=this.LogoTextColor;
826
+ this.Canvas.font=this.LogoTextFont;
827
+ this.Canvas.textAlign = 'left';
828
+ this.Canvas.textBaseline = 'top';
829
+
830
+ var x=this.ChartBorder.GetLeft()+2;
831
+ var y=this.ChartBorder.GetTop()+2;
832
+ this.Canvas.fillText(text,x,y);
833
+ }
834
+
835
+ this.DrawBorder=function()
836
+ {
837
+ var left=ToFixedPoint(this.ChartBorder.GetLeft());
838
+ var top=ToFixedPoint(this.ChartBorder.GetTop());
839
+ var right=ToFixedPoint(this.ChartBorder.GetRight());
840
+ var bottom=ToFixedPoint(this.ChartBorder.GetBottom());
841
+ var width=right-left;
842
+ var height=bottom-top;
843
+
844
+ //JSConsole.Chart.Log(`[JSScrollBarFrame.DrawBorder] left=${left} `);
845
+ if (!IFrameSplitOperator.IsNumber(this.BorderLine))
846
+ {
847
+ this.Canvas.strokeStyle=this.BorderColor;
848
+ this.Canvas.strokeRect(left,top,width,height);
849
+ }
850
+ else
851
+ {
852
+ this.Canvas.strokeStyle=this.BorderColor;
853
+ this.Canvas.beginPath();
854
+
855
+ if ((this.BorderLine&1)>0) //上
856
+ {
857
+ this.Canvas.moveTo(left,top);
858
+ this.Canvas.lineTo(right,top);
859
+ }
860
+
861
+ if ((this.BorderLine&2)>0) //下
862
+ {
863
+ this.Canvas.moveTo(left,bottom);
864
+ this.Canvas.lineTo(right,bottom);
865
+ }
866
+
867
+ if ((this.BorderLine&4)>0) //左
868
+ {
869
+ this.Canvas.moveTo(left,top);
870
+ this.Canvas.lineTo(left,bottom);
871
+ }
872
+
873
+ if ((this.BorderLine&8)>0) //右
874
+ {
875
+ this.Canvas.moveTo(right,top);
876
+ this.Canvas.lineTo(right,bottom);
877
+ }
878
+
879
+ this.Canvas.stroke();
880
+ }
881
+ }
882
+
883
+ this.GetXFromIndex=function(index)
884
+ {
885
+ var count=this.XPointCount;
886
+ if (count==1)
887
+ {
888
+ if (index==0) return this.ChartBorder.GetLeft();
889
+ else return this.ChartBorder.GetRight();
890
+ }
891
+ else if (count<=0)
892
+ {
893
+ return this.ChartBorder.GetLeft();
894
+ }
895
+ else if (index>=count)
896
+ {
897
+ return this.ChartBorder.GetRight();
898
+ }
899
+ else
900
+ {
901
+ var offset=this.ChartBorder.GetLeft()+this.ChartBorder.GetWidth()*index/count;
902
+ return offset;
903
+ }
904
+ }
905
+
906
+ this.GetYFromData=function(value)
907
+ {
908
+ if(value<=this.HorizontalMin) return this.ChartBorder.GetBottomEx();
909
+ if(value>=this.HorizontalMax) return this.ChartBorder.GetTopEx();
910
+
911
+ var height=this.ChartBorder.GetHeightEx()*(value-this.HorizontalMin)/(this.HorizontalMax-this.HorizontalMin);
912
+ return this.ChartBorder.GetBottomEx()-height;
913
+ }
914
+
915
+ //X坐标转x轴数值
916
+ this.GetXData=function(x)
917
+ {
918
+ if (x<=this.ChartBorder.GetLeft()) return 0;
919
+ if (x>=this.ChartBorder.GetRight()) return this.XPointCount;
920
+
921
+ return (x-this.ChartBorder.GetLeft())*(this.XPointCount*1.0/this.ChartBorder.GetWidth());
922
+ }
923
+
924
+ this.GetPreSetpWidth=function()
925
+ {
926
+ return this.XPointCount*1.0/this.ChartBorder.GetWidth();
927
+ }
928
+
929
+ this.DrawVertical=function()
930
+ {
931
+ if (this.ChartBorder.Bottom<=5) return;
932
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return
933
+
934
+ var item=this.Data.Data[0];
935
+ var preYear=parseInt(item.Date/10000);
936
+ var preDay=item.Date%10000;
937
+
938
+ this.Canvas.font=this.XSplitTextFont;
939
+ this.Canvas.fillStyle=this.XSplitTextColor;
940
+ this.Canvas.textBaseline="top";
941
+ var yText=this.ChartBorder.GetBottom()+2;
942
+ var top=this.ChartBorder.GetTop();
943
+ var bottom=this.ChartBorder.GetBottom();
944
+ var preXText=0;
945
+
946
+ if (ChartData.IsMilliSecondPeriod(this.Data.Period))
947
+ {
948
+ var preHour=null;
949
+ for(var i=0;i<this.Data.Data.length;++i)
950
+ {
951
+ var item=this.Data.Data[i];
952
+ var day=item.Date%10000;
953
+ var time=parseInt(item.Time/1000);
954
+ var hour=parseInt(time/10000);
955
+ if (i==0)
956
+ {
957
+ var text=IFrameSplitOperator.FormatDateString(item.Date, "MM-DD");
958
+ var x=this.ChartBorder.GetLeft();
959
+ this.Canvas.textAlign="left";
960
+ this.Canvas.fillText(text,x,yText);
961
+ var textWidth=this.Canvas.measureText(text).width+2;
962
+ preXText=x+textWidth;
963
+ preDay=day;
964
+ preHour=hour;
965
+ continue;
966
+ }
967
+
968
+ if (hour!=preHour)
969
+ {
970
+ var text=IFrameSplitOperator.FormatTimeString(item.Time, "HH:MM:SS.fff");
971
+ var x=this.GetXFromIndex(i);
972
+ var textWidth=this.Canvas.measureText(text).width+2;
973
+ if (x-textWidth/2>preXText)
974
+ {
975
+ this.Canvas.textAlign="center";
976
+ this.Canvas.fillText(text,x,yText);
977
+ preXText=x+textWidth/2;
978
+ }
979
+
980
+ x=ToFixedPoint(x);
981
+ this.Canvas.strokeStyle=this.XSplitLineColor;
982
+ this.Canvas.beginPath();
983
+ this.Canvas.moveTo(x,top);
984
+ this.Canvas.lineTo(x,bottom);
985
+ this.Canvas.stroke();
986
+
987
+ preHour=hour;
988
+ }
989
+ }
990
+ }
991
+ else if (ChartData.IsMinutePeriod(this.Data.Period,true))
992
+ {
993
+ for(var i=0;i<this.Data.Data.length;++i)
994
+ {
995
+ var item=this.Data.Data[i];
996
+ var day=item.Date%10000;
997
+ if (i==0)
998
+ {
999
+ var text=IFrameSplitOperator.FormatDateString(item.Date, "MM-DD");
1000
+ var x=this.ChartBorder.GetLeft();
1001
+ this.Canvas.textAlign="left";
1002
+ this.Canvas.fillText(text,x,yText);
1003
+ var textWidth=this.Canvas.measureText(text).width+2;
1004
+ preXText=x+textWidth;
1005
+ preDay=day;
1006
+ continue;
1007
+ }
1008
+
1009
+ if (day!=preDay)
1010
+ {
1011
+ var text=IFrameSplitOperator.FormatDateString(item.Date, "MM-DD");
1012
+ var x=this.GetXFromIndex(i);
1013
+ var textWidth=this.Canvas.measureText(text).width+2;
1014
+ if (x-textWidth/2>preXText)
1015
+ {
1016
+ this.Canvas.textAlign="center";
1017
+ this.Canvas.fillText(text,x,yText);
1018
+ preXText=x+textWidth/2;
1019
+ }
1020
+
1021
+ x=ToFixedPoint(x);
1022
+ this.Canvas.strokeStyle=this.XSplitLineColor;
1023
+ this.Canvas.beginPath();
1024
+ this.Canvas.moveTo(x,top);
1025
+ this.Canvas.lineTo(x,bottom);
1026
+ this.Canvas.stroke();
1027
+
1028
+ preDay=day;
1029
+ }
1030
+ }
1031
+ }
1032
+ else
1033
+ {
1034
+ for(var i=0;i<this.Data.Data.length;++i)
1035
+ {
1036
+ var item=this.Data.Data[i];
1037
+ var year=parseInt(item.Date/10000);
1038
+ if (i==0)
1039
+ {
1040
+ var text=`${year}`;
1041
+ var x=this.ChartBorder.GetLeft();
1042
+ var textWidth=this.Canvas.measureText(text).width+2;
1043
+ this.Canvas.textAlign="left";
1044
+ this.Canvas.fillText(text,x,yText);
1045
+ preXText=x+textWidth;
1046
+ preYear=year;
1047
+ continue;
1048
+ }
1049
+
1050
+ if (year!=preYear)
1051
+ {
1052
+ var text=`${year}`;
1053
+ var x=this.GetXFromIndex(i);
1054
+ var textWidth=this.Canvas.measureText(text).width+2;
1055
+ if (x-textWidth/2>preXText)
1056
+ {
1057
+ this.Canvas.textAlign="center";
1058
+ this.Canvas.fillText(text,x,yText);
1059
+ preXText=x+textWidth/2;
1060
+ }
1061
+
1062
+ x=ToFixedPoint(x);
1063
+ this.Canvas.strokeStyle=this.XSplitLineColor;
1064
+ this.Canvas.beginPath();
1065
+ this.Canvas.moveTo(x,top);
1066
+ this.Canvas.lineTo(x,bottom);
1067
+ this.Canvas.stroke();
1068
+
1069
+ preYear=year;
1070
+ }
1071
+ }
1072
+ }
1073
+ }
1074
+ }
1075
+
1076
+
1077
+ /////////////////////////////////////////////////////////////////////////////////////////////////
1078
+ // 滑块
1079
+ //
1080
+ /////////////////////////////////////////////////////////////////////////////////////////////////
1081
+ function SliderChart()
1082
+ {
1083
+ this.Canvas; //画布
1084
+ this.ChartBorder; //边框信息
1085
+ this.ChartFrame; //框架画法
1086
+ this.Name; //名称
1087
+ this.ClassName='SliderChart'; //类名
1088
+ this.OffsetData;
1089
+ this.Color=g_JSChartResource.ScrollBar.Slider.BarAreaColor;
1090
+
1091
+ this.BarColor=g_JSChartResource.ScrollBar.Slider.BarColor;
1092
+ this.BarWidth=10;
1093
+ this.BarPadding=10; //上下留白
1094
+
1095
+ this.DateFont=g_JSChartResource.ScrollBar.Slider.DateFont;
1096
+ this.DateColor=g_JSChartResource.ScrollBar.Slider.DateColor;
1097
+
1098
+ this.AryRect=[]; //[{ Rect:{Left, Top, Right:, Bottom:, Width, Height:}, Type:0中间 1=左 2=右 }]
1099
+ this.XStart;
1100
+ this.XEnd;
1101
+
1102
+ this.SizeChange=true;
1103
+ this.DragMode=false;
1104
+
1105
+ this.ReloadResource=function(resource)
1106
+ {
1107
+ this.Color=g_JSChartResource.ScrollBar.Slider.BarAreaColor;
1108
+ this.BarColor=g_JSChartResource.ScrollBar.Slider.BarColor;
1109
+
1110
+ this.DateFont=g_JSChartResource.ScrollBar.Slider.DateFont;
1111
+ this.DateColor=g_JSChartResource.ScrollBar.Slider.DateColor;
1112
+ }
1113
+
1114
+ this.Draw=function()
1115
+ {
1116
+ this.AryRect=[];
1117
+
1118
+ if (!this.OffsetData || !IFrameSplitOperator.IsPlusNumber(this.OffsetData.Count)) return;
1119
+ if (!IFrameSplitOperator.IsNumber(this.OffsetData.Start) || !IFrameSplitOperator.IsNumber(this.OffsetData.End)) return;
1120
+
1121
+ var top=this.ChartBorder.GetTop();
1122
+ var bottom=this.ChartBorder.GetBottom();
1123
+ var startData, endData;
1124
+ if (this.DragMode)
1125
+ {
1126
+ var xStart=this.XStart;
1127
+ var xEnd=this.XEnd;
1128
+
1129
+ var startIndex=this.ChartFrame.GetXData(xStart);
1130
+ var endIndx=this.ChartFrame.GetXData(xEnd);
1131
+
1132
+ startIndex=parseInt(startIndex);
1133
+ endIndx=parseInt(endIndx);
1134
+
1135
+ startData={ Data:this.Data.Data[this.OffsetData.Start], X:xStart, Type:startIndex<endIndx?0:1 };
1136
+ endData={Data:this.Data.Data[this.OffsetData.End], X:xEnd, Type:endIndx>startIndex?1:0 };
1137
+ }
1138
+ else
1139
+ {
1140
+ var start=this.OffsetData.Start, end=this.OffsetData.End;
1141
+ var xStart=this.ChartFrame.GetXFromIndex(start);
1142
+ var xEnd=this.ChartFrame.GetXFromIndex(end);
1143
+ this.XStart=xStart;
1144
+ this.XEnd=xEnd;
1145
+ startData={ Data:this.Data.Data[this.OffsetData.Start], X:xStart, Type:xStart<xEnd?0:1 };
1146
+ endData={Data:this.Data.Data[this.OffsetData.End], X:xEnd, Type:xEnd>xStart?1:0 };
1147
+ }
1148
+
1149
+ this.Canvas.fillStyle=this.Color;
1150
+ var rtBar={ Left:Math.min(xStart,xEnd), Top:top, Width:Math.abs(xEnd-xStart), Height: bottom-top};
1151
+ rtBar.Right=rtBar.Left+rtBar.Width;
1152
+ rtBar.Bottom=rtBar.Top+rtBar.Height;
1153
+ this.Canvas.fillRect(rtBar.Left, rtBar.Top, rtBar.Width, rtBar.Height);
1154
+ this.AryRect.push({ Rect:rtBar, Type:0});
1155
+
1156
+
1157
+ //左右拖拽块
1158
+ var pixelRatio=GetDevicePixelRatio();
1159
+ var barWidth=this.BarWidth*pixelRatio;
1160
+ var barHeight=bottom-top-(this.BarPadding*2)*pixelRatio;
1161
+ var xBar=xStart-this.BarWidth/2;
1162
+ var yBar=top+this.BarPadding*pixelRatio;
1163
+
1164
+ this.Canvas.fillStyle=this.BarColor;
1165
+ var rtBar={Left:xBar, Top:yBar, Width:barWidth, Height:barHeight};
1166
+ rtBar.Right=rtBar.Left+rtBar.Width;
1167
+ rtBar.Bottom=rtBar.Top+rtBar.Height;
1168
+ this.Canvas.fillRect(rtBar.Left, rtBar.Top, rtBar.Width, rtBar.Height);
1169
+ this.AryRect.push({ Rect:rtBar, Type:1});
1170
+
1171
+ var xBar=xEnd-this.BarWidth/2;
1172
+ var rtBar={Left:xBar, Top:yBar, Width:barWidth, Height:barHeight};
1173
+ rtBar.Right=rtBar.Left+rtBar.Width;
1174
+ rtBar.Bottom=rtBar.Top+rtBar.Height;
1175
+ this.Canvas.fillRect(rtBar.Left, rtBar.Top, rtBar.Width, rtBar.Height);
1176
+ this.AryRect.push({ Rect:rtBar, Type:2});
1177
+
1178
+ this.DrawDateTime(startData);
1179
+ this.DrawDateTime(endData);
1180
+ }
1181
+
1182
+ this.DrawDateTime=function(data)
1183
+ {
1184
+ if (!data || !data.Data) return;
1185
+ var text=IFrameSplitOperator.FormatDateString(data.Data.Date);
1186
+ var top=this.ChartBorder.GetTop();
1187
+ var bottom=this.ChartBorder.GetBottom();
1188
+ var timeText=null;
1189
+
1190
+ if (ChartData.IsMilliSecondPeriod(this.Data.Period))
1191
+ {
1192
+ var time=parseInt(data.Data.Time/1000);
1193
+ text=IFrameSplitOperator.FormatTimeString(time,"HH:MM:SS");
1194
+ }
1195
+ else if (ChartData.IsMinutePeriod(this.Data.Period, true))
1196
+ {
1197
+ timeText=IFrameSplitOperator.FormatTimeString(data.Data.Time,"HH:MM");
1198
+ }
1199
+
1200
+ if (data.Type==0)
1201
+ {
1202
+ this.Canvas.textAlign="right";
1203
+ var x=data.X-this.BarWidth/2;
1204
+ }
1205
+ else if (data.Type==1)
1206
+ {
1207
+ this.Canvas.textAlign="left";
1208
+ var x=data.X+this.BarWidth/2;
1209
+ }
1210
+
1211
+ this.Canvas.font=this.DateFont;
1212
+ var fontHeight=this.Canvas.measureText("擎").width;
1213
+ this.Canvas.textBaseline="middle";
1214
+ this.Canvas.fillStyle=this.DateColor;
1215
+
1216
+ var yText=top+(bottom-top)/2;
1217
+ this.Canvas.fillText(text,x,yText);
1218
+
1219
+ if (timeText)
1220
+ {
1221
+ yText+=fontHeight;
1222
+ this.Canvas.fillText(timeText,x,yText);
1223
+ }
1224
+ }
1225
+
1226
+ this.PtInChart=function(x,y)
1227
+ {
1228
+ if (!IFrameSplitOperator.IsNonEmptyArray(this.AryRect)) return null;
1229
+
1230
+ for(var i=this.AryRect.length-1; i>=0; --i)
1231
+ {
1232
+ var item=this.AryRect[i];
1233
+ var rt=item.Rect;
1234
+ if (x>=rt.Left && x<=rt.Right && y>=rt.Top && y<=rt.Bottom)
1235
+ {
1236
+ return { Data:item };
1237
+ }
1238
+ }
1239
+
1240
+ return null;
1241
+ }
1242
+ }
1243
+
1244
+ ///////////////////////////////////////////////////////////////////////////////////////////////
1245
+ // 滚动条K线背景色
1246
+ //
1247
+ //
1248
+ /////////////////////////////////////////////////////////////////////////////////////////////////
1249
+ function ScrollBarBGChart()
1250
+ {
1251
+ this.Canvas; //画布
1252
+ this.ChartBorder; //边框信息
1253
+ this.ChartFrame; //框架画法
1254
+ this.Name; //名称
1255
+ this.ClassName='ScrollBarBGChart'; //类名
1256
+
1257
+ this.SizeChange=true;
1258
+ this.Data;
1259
+
1260
+ this.Color=g_JSChartResource.ScrollBar.BGChart.Color; //线段颜色
1261
+ this.LineWidth=g_JSChartResource.ScrollBar.BGChart.LineWidth; //线段宽度
1262
+ this.AreaColor=g_JSChartResource.ScrollBar.BGChart.AreaColor; //面积图颜色
1263
+
1264
+ this.ReloadResource=function(resource)
1265
+ {
1266
+ this.Color=g_JSChartResource.ScrollBar.BGChart.Color; //线段颜色
1267
+ this.LineWidth=g_JSChartResource.ScrollBar.BGChart.LineWidth; //线段宽度
1268
+ this.AreaColor=g_JSChartResource.ScrollBar.BGChart.AreaColor; //面积图颜色
1269
+ }
1270
+
1271
+ this.Draw=function()
1272
+ {
1273
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return;
1274
+
1275
+ this.Canvas.save();
1276
+ if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio();
1277
+
1278
+ var bottom=this.ChartBorder.GetBottom();
1279
+ this.Canvas.strokeStyle=this.Color;
1280
+ var bFirstPoint=true;
1281
+ var drawCount=0,x,y;
1282
+ var firstPoint={ };
1283
+ for(var i=0;i<this.Data.Data.length;++i)
1284
+ {
1285
+ var item=this.Data.Data[i];
1286
+ var value=item.Close;
1287
+ if (!IFrameSplitOperator.IsNumber(value)) continue;
1288
+
1289
+ x=this.ChartFrame.GetXFromIndex(i);
1290
+ y=this.ChartFrame.GetYFromData(value);
1291
+
1292
+ if (bFirstPoint)
1293
+ {
1294
+ this.Canvas.beginPath();
1295
+ this.Canvas.moveTo(x,y);
1296
+ bFirstPoint=false;
1297
+ firstPoint={ X:x, Y:y };
1298
+ }
1299
+ else
1300
+ {
1301
+ this.Canvas.lineTo(x,y);
1302
+ }
1303
+
1304
+ ++drawCount;
1305
+ }
1306
+
1307
+ if (drawCount>0)
1308
+ {
1309
+ this.Canvas.stroke();
1310
+
1311
+
1312
+ this.Canvas.lineTo(x,bottom);
1313
+ this.Canvas.lineTo(firstPoint.X,bottom);
1314
+ this.Canvas.closePath();
1315
+
1316
+ this.Canvas.fillStyle=this.AreaColor;
1317
+ this.Canvas.fill();
1318
+
1319
+ }
1320
+
1321
+
1322
+ this.Canvas.restore();
1323
+ }
1324
+
1325
+ this.GetMaxMin=function()
1326
+ {
1327
+ var range={ Max:null, Min:null };
1328
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return range;
1329
+
1330
+ for(var i=0;i<this.Data.Data.length;++i)
1331
+ {
1332
+ var item=this.Data.Data[i];
1333
+ var value=item.Close;
1334
+
1335
+ if (!IFrameSplitOperator.IsNumber(value)) continue;
1336
+
1337
+ if (range.Max==null || range.Max<value) range.Max=value;
1338
+ if (range.Min==null || range.Min>value) range.Min=value;
1339
+ }
1340
+
1341
+ return range;
1342
+ }
1343
+ }
1344
+
1345
+