hqchart 1.1.13516 → 1.1.13526

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hqchart",
3
- "version": "1.1.13516",
3
+ "version": "1.1.13526",
4
4
  "description": "HQChart - H5, 微信小程序 沪深/港股/数字货币/期货/美股 K线图(kline),走势图,缩放,拖拽,十字光标,画图工具,截图,筹码图. 分析家语法,通达信语法,(麦语法),第3方数据对接",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -27,6 +27,7 @@ function JSChart(divElement, bOffscreen, bCacheCanvas)
27
27
  this.DivElement=divElement;
28
28
  this.DivToolElement=null; //工具条
29
29
  this.JSChartContainer; //画图控件
30
+ this.ResizeListener;
30
31
 
31
32
  //h5 canvas
32
33
  this.CanvasElement=document.createElement("canvas");
@@ -1704,6 +1705,8 @@ function JSChart(divElement, bOffscreen, bCacheCanvas)
1704
1705
  this.JSChartContainer=chart;
1705
1706
  chart.DivElement=this.DivElement;
1706
1707
 
1708
+ if (option.EnableResize==true) this.CreateResizeListener();
1709
+
1707
1710
  if (option.DefaultCursor) chart.DefaultCursor=option.DefaultCursor;
1708
1711
  if (option.OnCreatedCallback) option.OnCreatedCallback(chart);
1709
1712
 
@@ -1746,6 +1749,19 @@ function JSChart(divElement, bOffscreen, bCacheCanvas)
1746
1749
  }
1747
1750
  }
1748
1751
 
1752
+ this.CreateResizeListener=function()
1753
+ {
1754
+ this.ResizeListener = new ResizeObserver((entries)=>{ this.OnDivResize(entries); });
1755
+ this.ResizeListener.observe(this.DivElement);
1756
+ }
1757
+
1758
+ this.OnDivResize=function(entries)
1759
+ {
1760
+ JSConsole.Chart.Log("[JSChart::OnDivResize] entries=", entries);
1761
+
1762
+ this.OnSize( {Type:1} );
1763
+ }
1764
+
1749
1765
  //创建工具条
1750
1766
  this.CreateToolbar=function(option)
1751
1767
  {
@@ -37981,6 +37997,7 @@ function ChartMultiText()
37981
37997
  {
37982
37998
  var border=this.ChartBorder.GetHScreenBorder();
37983
37999
  var chartright=border.BottomEx;
38000
+ var chartleft=border.TopEx;
37984
38001
  var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin;
37985
38002
  var left=this.ChartBorder.GetTop();
37986
38003
  var right=this.ChartBorder.GetBottom();
@@ -37992,6 +38009,7 @@ function ChartMultiText()
37992
38009
  var border=this.ChartBorder.GetBorder();
37993
38010
  var xOffset=border.LeftEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin;
37994
38011
  var chartright=border.RightEx;
38012
+ var chartleft=border.LeftEx;
37995
38013
  var left=this.ChartBorder.GetLeft();
37996
38014
  var right=this.ChartBorder.GetRight();
37997
38015
  var top=border.TopEx;
@@ -38027,16 +38045,17 @@ function ChartMultiText()
38027
38045
 
38028
38046
  var textWidth=this.Canvas.measureText(item.Text).width;
38029
38047
  this.Canvas.textAlign='center';
38030
- if (x+textWidth/2>=right)
38048
+ if (x+textWidth/2>=chartright)
38031
38049
  {
38032
38050
  this.Canvas.textAlign='right';
38033
- x=right;
38051
+ x=chartright;
38034
38052
  }
38035
- else if (x-textWidth/2<left)
38053
+ else if (x-textWidth/2<chartleft)
38036
38054
  {
38037
38055
  this.Canvas.textAlign = 'left';
38038
- x=left;
38056
+ x=chartleft;
38039
38057
  }
38058
+
38040
38059
  if (item.Baseline==1) this.Canvas.textBaseline='top';
38041
38060
  else if (item.Baseline==2) this.Canvas.textBaseline='bottom';
38042
38061
  else this.Canvas.textBaseline = 'middle';
@@ -16,18 +16,76 @@ function JSReportChart(divElement)
16
16
  this.DivElement=divElement;
17
17
  this.JSChartContainer; //表格控件
18
18
 
19
- //h5 canvas
20
- this.CanvasElement=document.createElement("canvas");
21
- this.CanvasElement.className='jsreportlist-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("[JSReportChart::JSReportChart] divElement hasChildNodes", divElement.childNodes);
28
- }
29
- divElement.appendChild(this.CanvasElement);
19
+ //h5 canvas
20
+ this.CanvasElement=document.createElement("canvas");
21
+ this.CanvasElement.className='jsreportlist-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("[JSReportChart::JSReportChart] divElement hasChildNodes", divElement.childNodes);
28
+ }
29
+ divElement.appendChild(this.CanvasElement);
30
+
31
+ //额外的画布
32
+ this.MapExtraCanvasElement=new Map(); //key=画布名字, value={ Element:, Canvas:}
33
+
34
+ this.CreateExtraCanvasElement=function(name, option)
35
+ {
36
+ if (this.MapExtraCanvasElement.has(name)) return this.MapExtraCanvasElement.get(name);
37
+
38
+ var element=document.createElement("canvas");
39
+ element.className='jsreportlist-drawing-extra';
40
+ element.id=Guid();
41
+ if (name==JSChart.CorssCursorCanvasKey)
42
+ element.setAttribute("tabindex",5);
43
+ else
44
+ element.setAttribute("tabindex",1);
45
+
46
+ if (element.style)
47
+ {
48
+ element.style.outline='none';
49
+ element.style.position="absolute";
50
+ element.style.left='0px';
51
+ element.style.top='0px';
52
+ element.style["pointer-events"]="none";
53
+ }
54
+
55
+ if (option)
56
+ {
57
+ if (IFrameSplitOperator.IsNumber(option.TabIndex)) element.setAttribute("tabindex",option.TabIndex);
58
+ if (IFrameSplitOperator.IsNumber(option.ZIndex)) element.style["z-index"]=option.ZIndex;
59
+ }
30
60
 
61
+ if (this.CanvasElement)
62
+ {
63
+ element.height=this.CanvasElement.height;
64
+ element.width=this.CanvasElement.width;
65
+ if (element.style)
66
+ {
67
+ element.style.width=this.CanvasElement.style.width;
68
+ element.style.height=this.CanvasElement.style.height
69
+ }
70
+ }
71
+
72
+ divElement.appendChild(element);
73
+
74
+ var item={ Element:element, Canvas:null };
75
+ this.MapExtraCanvasElement.set(name, item);
76
+ }
77
+
78
+ this.GetExtraCanvas=function(name)
79
+ {
80
+ if (!this.MapExtraCanvasElement.has(name)) return null;
81
+
82
+ var item=this.MapExtraCanvasElement.get(name);
83
+ if (!item.Element) return null;
84
+
85
+ if (!item.Canvas) item.Canvas=item.Element.getContext("2d");
86
+
87
+ return item;
88
+ }
31
89
 
32
90
  this.OnSize=function()
33
91
  {
@@ -42,6 +100,19 @@ function JSReportChart(divElement)
42
100
  this.CanvasElement.height*=pixelTatio;
43
101
  this.CanvasElement.width*=pixelTatio;
44
102
 
103
+ //扩展画布
104
+ for(var mapItem of this.MapExtraCanvasElement)
105
+ {
106
+ var item=mapItem[1];
107
+ var element=item.Element;
108
+ if (!element) continue;
109
+
110
+ element.height=this.CanvasElement.height;
111
+ element.width=this.CanvasElement.width;
112
+ element.style.width=this.CanvasElement.style.width;
113
+ element.style.height=this.CanvasElement.style.height;
114
+ }
115
+
45
116
  JSConsole.Chart.Log(`[JSReportChart::OnSize] devicePixelRatio=${window.devicePixelRatio}, height=${this.CanvasElement.height}, width=${this.CanvasElement.width}`);
46
117
 
47
118
  if (this.JSChartContainer && this.JSChartContainer.OnSize)
@@ -92,6 +163,9 @@ function JSReportChart(divElement)
92
163
  if (IFrameSplitOperator.IsBool(option.EnableDragRow)) chart.EnableDragRow=option.EnableDragRow;
93
164
  if (IFrameSplitOperator.IsNumber(option.DragRowType)) chart.DragRowType=option.DragRowType;
94
165
  if (IFrameSplitOperator.IsBool(option.EnableDragHeader)) chart.EnableDragHeader=option.EnableDragHeader;
166
+ if (IFrameSplitOperator.IsNumber(option.WheelPageType)) chart.WheelPageType=option.WheelPageType;
167
+ if (IFrameSplitOperator.IsBool(option.PageUpDownCycle)) chart.PageUpDownCycle=option.PageUpDownCycle;
168
+
95
169
  if (option.VScrollbar) chart.SetVScrollbar(option.VScrollbar);
96
170
  if (option.SortInfo)
97
171
  {
@@ -200,6 +274,8 @@ function JSReportChart(divElement)
200
274
  }
201
275
  }
202
276
 
277
+ JSReportChart.TooltipCursorCanvasKey="hq_report_tooltip"; //提示信息
278
+
203
279
 
204
280
  JSReportChart.Init=function(divElement)
205
281
  {
@@ -337,6 +413,7 @@ function JSReportChartContainer(uielement)
337
413
 
338
414
  this.PageUpDownCycle=true; //翻页循环
339
415
  this.DragPageCycle=true; //手机翻页循环
416
+ this.WheelPageType=0; //鼠标滚轴翻页模式 0=一页一页翻 1=一条一条翻
340
417
 
341
418
  //拖拽滚动条
342
419
  this.DragXScroll=null; //{Start:{x,y}, End:{x, y}}
@@ -417,6 +494,15 @@ function JSReportChartContainer(uielement)
417
494
  }
418
495
 
419
496
 
497
+ //清空画布
498
+ this.ClearCanvas=function(canvas)
499
+ {
500
+ if (!canvas) return;
501
+ if (!this.UIElement) return;
502
+
503
+ canvas.clearRect(0,0,this.UIElement.width,this.UIElement.height);
504
+ }
505
+
420
506
  //清空固定行数据
421
507
  this.ClearFixedRowData=function()
422
508
  {
@@ -1361,20 +1447,43 @@ function JSReportChartContainer(uielement)
1361
1447
  if (!IFrameSplitOperator.IsObjectExist(e.wheelDelta))
1362
1448
  wheelValue=e.deltaY* -0.01;
1363
1449
 
1364
- if (wheelValue<0) //下一页
1450
+ if (this.WheelPageType==1)
1365
1451
  {
1366
- if (this.GotoNextPage(this.PageUpDownCycle))
1452
+ console.log(`[OnWheel] wheelValue=${wheelValue}`);
1453
+ if (wheelValue<0) //下
1367
1454
  {
1368
- this.Draw();
1369
- this.DelayUpdateStockData();
1455
+ if (this.GotoNextItem(1))
1456
+ {
1457
+ this.Draw();
1458
+ this.DelayUpdateStockData();
1459
+ }
1460
+ }
1461
+ else if (wheelValue>0) //上
1462
+ {
1463
+ if (this.GotoNextItem(-1))
1464
+ {
1465
+ this.Draw();
1466
+ this.DelayUpdateStockData();
1467
+ }
1370
1468
  }
1371
1469
  }
1372
- else if (wheelValue>0) //上一页
1470
+ else
1373
1471
  {
1374
- if (this.GotoPreviousPage(this.PageUpDownCycle))
1472
+ if (wheelValue<0) //下一页
1375
1473
  {
1376
- this.Draw();
1377
- this.DelayUpdateStockData();
1474
+ if (this.GotoNextPage(this.PageUpDownCycle))
1475
+ {
1476
+ this.Draw();
1477
+ this.DelayUpdateStockData();
1478
+ }
1479
+ }
1480
+ else if (wheelValue>0) //上一页
1481
+ {
1482
+ if (this.GotoPreviousPage(this.PageUpDownCycle))
1483
+ {
1484
+ this.Draw();
1485
+ this.DelayUpdateStockData();
1486
+ }
1378
1487
  }
1379
1488
  }
1380
1489
 
@@ -2250,6 +2359,43 @@ function JSReportChartContainer(uielement)
2250
2359
  return chart;
2251
2360
  }
2252
2361
 
2362
+ this.GotoNextItem=function(step)
2363
+ {
2364
+ if (step==0) return false;
2365
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
2366
+ var chart=this.ChartPaint[0];
2367
+ if (!chart) return false;
2368
+ var pageSize=chart.GetPageSize();
2369
+ if (pageSize>this.Data.Data.length) return false;
2370
+
2371
+ var moveCount=0;
2372
+ if (step>0)
2373
+ {
2374
+ for(var i=0;i<step;++i)
2375
+ {
2376
+ if (this.Data.YOffset+pageSize>=this.Data.Data.length)
2377
+ break;
2378
+
2379
+ ++this.Data.YOffset;
2380
+ ++moveCount;
2381
+ }
2382
+ }
2383
+ else if (step<0)
2384
+ {
2385
+ step=Math.abs(step);
2386
+ for(var i=0;i<step;++i)
2387
+ {
2388
+ if (this.Data.YOffset<=0)
2389
+ break;
2390
+
2391
+ --this.Data.YOffset;
2392
+ ++moveCount;
2393
+ }
2394
+ }
2395
+
2396
+ return moveCount>0
2397
+ }
2398
+
2253
2399
  this.GotoNextPage=function(bCycle) //bCycle 是否循环
2254
2400
  {
2255
2401
  if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.Data)) return false;
@@ -3605,8 +3751,10 @@ function ChartReport()
3605
3751
  if (item.Type==REPORT_COLUMN_ID.CUSTOM_STRING_TEXT_ID)
3606
3752
  {
3607
3753
  if (!IFrameSplitOperator.IsNumber(item.DataIndex) && !IFrameSplitOperator.IsNumber(item.BlockIndex)) continue;
3754
+ colItem.FormatType=0; //0=默认格式 1=长度不够使用...
3608
3755
  if (IFrameSplitOperator.IsNumber(item.DataIndex)) colItem.DataIndex=item.DataIndex; //数据在扩展数据索引列
3609
3756
  if (IFrameSplitOperator.IsNumber(item.BlockIndex)) colItem.BlockIndex=item.BlockIndex;
3757
+ if (IFrameSplitOperator.IsNumber(item.FormatType)) colItem.FormatType=item.FormatType; //输出样式
3610
3758
  }
3611
3759
  else if (item.Type==REPORT_COLUMN_ID.CUSTOM_NUMBER_TEXT_ID)
3612
3760
  {
@@ -4562,10 +4710,69 @@ function ChartReport()
4562
4710
  }
4563
4711
 
4564
4712
  this.DrawItemBG(drawInfo);
4565
- this.DrawItemText(drawInfo.Text, drawInfo.TextColor, drawInfo.TextAlign, x, top, textWidth, drawInfo.BGColor);
4713
+
4714
+ if (column.Type==REPORT_COLUMN_ID.CUSTOM_STRING_TEXT_ID)
4715
+ this.DrawCustomText(drawInfo,column, x, top, textWidth);
4716
+ else
4717
+ this.DrawItemText(drawInfo.Text, drawInfo.TextColor, drawInfo.TextAlign, x, top, textWidth, drawInfo.BGColor);
4566
4718
  }
4567
4719
  }
4568
4720
 
4721
+ this.DrawCustomText=function(drawInfo, column, left, top, cellWidth)
4722
+ {
4723
+ if (!drawInfo.Text) return;
4724
+
4725
+ var text=drawInfo.Text;
4726
+ var x=left;
4727
+ if (drawInfo.TextAlign=='center')
4728
+ {
4729
+ x=left+cellWidth/2;
4730
+ this.Canvas.textAlign="center";
4731
+ }
4732
+ else if (drawInfo.TextAlign=='right')
4733
+ {
4734
+ x=left+cellWidth-2;
4735
+ this.Canvas.textAlign="right";
4736
+ }
4737
+ else
4738
+ {
4739
+ x+=2;
4740
+ this.Canvas.textAlign="left";
4741
+ }
4742
+
4743
+ var textWidth=this.Canvas.measureText(text).width+1;
4744
+ var bClip=false;
4745
+ if (textWidth>=cellWidth) //长度超过单元格 裁剪
4746
+ {
4747
+ if (column.FormatType==2)
4748
+ {
4749
+ var count=text.length+5;
4750
+ text="";
4751
+ for(var i=0;i<count;++i)
4752
+ text+="#";
4753
+ }
4754
+ else if (column.FormatType==1)
4755
+ {
4756
+ text=this.TextEllipsis(text, cellWidth, column.MaxText);
4757
+ }
4758
+
4759
+ this.Canvas.save();
4760
+ bClip=true;
4761
+
4762
+ var rtCell={ Left:left, Top:top+this.ItemMergin.Top, Width:cellWidth, Height:this.RowHeight };
4763
+ this.Canvas.beginPath();
4764
+ this.Canvas.rect(rtCell.Left, rtCell.Top, rtCell.Width, rtCell.Height);
4765
+ //this.Canvas.stroke(); //调试用
4766
+ this.Canvas.clip();
4767
+ }
4768
+
4769
+ this.Canvas.textBaseline="middle";
4770
+ this.Canvas.fillStyle=drawInfo.TextColor;
4771
+ this.Canvas.fillText(text,x,top+this.ItemMergin.Top+this.RowHeight/2);
4772
+
4773
+ if (bClip) this.Canvas.restore();
4774
+ }
4775
+
4569
4776
  this.DrawSymbolName=function(data, column, left, top, rowType)
4570
4777
  {
4571
4778
  var stock=data.Stock;
@@ -6362,6 +6569,11 @@ function ChartVScrollbar()
6362
6569
  var rtBar = {Right:right-this.Mergin.Right, Top:y, Width:buttonSize, Height: this.ScrollBarHeight };
6363
6570
  rtBar.Left=rtBar.Right-buttonSize;
6364
6571
  rtBar.Bottom=rtBar.Top+rtBar.Height;
6572
+ if (rtBar.Bottom>rtBottom.Top-2)
6573
+ {
6574
+ rtBar.Bottom=rtBottom.Top-2;
6575
+ rtBar.Top=rtBar.Bottom-rtBar.Height;
6576
+ }
6365
6577
 
6366
6578
  this.RectScroll.Top=rtTop;
6367
6579
  this.RectScroll.Bottom=rtBottom;