hqchart 1.1.13526 → 1.1.13531

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.13526",
3
+ "version": "1.1.13531",
4
4
  "description": "HQChart - H5, 微信小程序 沪深/港股/数字货币/期货/美股 K线图(kline),走势图,缩放,拖拽,十字光标,画图工具,截图,筹码图. 分析家语法,通达信语法,(麦语法),第3方数据对接",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -38,7 +38,7 @@ function JSReportChart(divElement)
38
38
  var element=document.createElement("canvas");
39
39
  element.className='jsreportlist-drawing-extra';
40
40
  element.id=Guid();
41
- if (name==JSChart.CorssCursorCanvasKey)
41
+ if (name==JSReportChart.CorssCursorCanvasKey)
42
42
  element.setAttribute("tabindex",5);
43
43
  else
44
44
  element.setAttribute("tabindex",1);
@@ -133,6 +133,10 @@ function JSReportChart(divElement)
133
133
  this.DivElement.JSChart=this; //div中保存一份
134
134
 
135
135
  if (option.EnablePopMenuV2===true) chart.InitalPopMenu();
136
+ if (option.EnableTooltip)
137
+ {
138
+ this.CreateExtraCanvasElement(JSReportChart.TooltipCursorCanvasKey, { ZIndex:99 });
139
+ }
136
140
 
137
141
  if (option.Symbol) chart.Symbol=option.Symbol;
138
142
  if (option.Name) chart.Name=option.Name;
@@ -154,6 +158,8 @@ function JSReportChart(divElement)
154
158
  this.CreateJSReportChartContainer=function(option)
155
159
  {
156
160
  var chart=new JSReportChartContainer(this.CanvasElement);
161
+ chart.GetExtraCanvas=(name)=>{ return this.GetExtraCanvas(name); }
162
+
157
163
  chart.Create(option);
158
164
 
159
165
  if (option.NetworkFilter) chart.NetworkFilter=option.NetworkFilter;
@@ -354,6 +360,9 @@ function JSReportChartContainer(uielement)
354
360
  this.SplashTitle={ StockList:"下载码表中.....", MemberList:"下载成分中....." } ;
355
361
 
356
362
  this.Canvas=uielement.getContext("2d"); //画布
363
+
364
+ this.TooltipCanvas;
365
+ this.ChartTooltip;
357
366
 
358
367
  this.Tooltip=document.createElement("div");
359
368
  this.Tooltip.className='jsreport-tooltip';
@@ -425,6 +434,8 @@ function JSReportChartContainer(uielement)
425
434
  this.JSPopMenu; //内置菜单
426
435
  this.IsShowRightMenu=true;
427
436
 
437
+ this.LastMouseStatus={ MoveStatus:null, TooltipStatus:null };
438
+
428
439
  this.ChartDestory=function() //销毁
429
440
  {
430
441
  this.IsDestroy=true;
@@ -575,6 +586,12 @@ function JSReportChartContainer(uielement)
575
586
 
576
587
  this.ChartPaint[0]=chart;
577
588
 
589
+ //提示信息
590
+ var chartTooltip=new ChartCellTooltip();
591
+ chartTooltip.Frame=this.Frame;
592
+ chartTooltip.ChartBorder=this.Frame.ChartBorder;
593
+ this.ChartTooltip=chartTooltip;
594
+
578
595
  //页脚
579
596
  if (option && option.PageInfo===true)
580
597
  {
@@ -686,6 +703,8 @@ function JSReportChartContainer(uielement)
686
703
  {
687
704
  this.DelayDraw(500);
688
705
  }
706
+
707
+ this.DrawTooltip(this.LastMouseStatus.TooltipStatus);
689
708
  }
690
709
 
691
710
  this.DelayDraw=function(frequency)
@@ -1452,6 +1471,7 @@ function JSReportChartContainer(uielement)
1452
1471
  console.log(`[OnWheel] wheelValue=${wheelValue}`);
1453
1472
  if (wheelValue<0) //下
1454
1473
  {
1474
+ this.LastMouseStatus.TooltipStatus=null;
1455
1475
  if (this.GotoNextItem(1))
1456
1476
  {
1457
1477
  this.Draw();
@@ -1460,6 +1480,7 @@ function JSReportChartContainer(uielement)
1460
1480
  }
1461
1481
  else if (wheelValue>0) //上
1462
1482
  {
1483
+ this.LastMouseStatus.TooltipStatus=null;
1463
1484
  if (this.GotoNextItem(-1))
1464
1485
  {
1465
1486
  this.Draw();
@@ -1471,6 +1492,7 @@ function JSReportChartContainer(uielement)
1471
1492
  {
1472
1493
  if (wheelValue<0) //下一页
1473
1494
  {
1495
+ this.LastMouseStatus.TooltipStatus=null;
1474
1496
  if (this.GotoNextPage(this.PageUpDownCycle))
1475
1497
  {
1476
1498
  this.Draw();
@@ -1479,6 +1501,7 @@ function JSReportChartContainer(uielement)
1479
1501
  }
1480
1502
  else if (wheelValue>0) //上一页
1481
1503
  {
1504
+ this.LastMouseStatus.TooltipStatus=null;
1482
1505
  if (this.GotoPreviousPage(this.PageUpDownCycle))
1483
1506
  {
1484
1507
  this.Draw();
@@ -1700,7 +1723,13 @@ function JSReportChartContainer(uielement)
1700
1723
  var pixelTatio = GetDevicePixelRatio();
1701
1724
  var x = (e.clientX-this.UIElement.getBoundingClientRect().left)*pixelTatio;
1702
1725
  var y = (e.clientY-this.UIElement.getBoundingClientRect().top)*pixelTatio;
1726
+
1727
+ this.LastMouseStatus.OnMouseMove=null;
1703
1728
 
1729
+ var bDrawTooltip=false;
1730
+ if (this.LastMouseStatus.TooltipStatus) bDrawTooltip=true;
1731
+ this.LastMouseStatus.TooltipStatus=null;
1732
+
1704
1733
  if (this.DragRow) return;
1705
1734
  if (this.DrawHeader) return;
1706
1735
  if (this.DragColumnWidth) return;
@@ -1720,10 +1749,11 @@ function JSReportChartContainer(uielement)
1720
1749
  }
1721
1750
  }
1722
1751
 
1752
+ this.LastMouseStatus.OnMouseMove={ X:x, Y:y };
1723
1753
  var mouseStatus={ Cursor:"default", Name:"Default"};; //鼠标状态
1724
1754
  var report=this.GetReportChart();
1725
- var cell=null;
1726
1755
  var bDraw=false;
1756
+
1727
1757
  if (report)
1728
1758
  {
1729
1759
  var dragHeaderWidth=report.PtInHeaderDragBorder(x,y);
@@ -1734,7 +1764,12 @@ function JSReportChartContainer(uielement)
1734
1764
  }
1735
1765
  else
1736
1766
  {
1737
- cell=report.PtInCell(x,y); //是否在单元格(EnableTooltip)
1767
+ var tooltipData=report.GetTooltipData(x,y); //单元格提示信息
1768
+ if (tooltipData)
1769
+ {
1770
+ this.LastMouseStatus.TooltipStatus={ X:x, Y:y, Data:tooltipData };
1771
+ bDrawTooltip=true;
1772
+ }
1738
1773
  }
1739
1774
 
1740
1775
  var scrollbar=report.VScrollbar;
@@ -1750,16 +1785,20 @@ function JSReportChartContainer(uielement)
1750
1785
  }
1751
1786
  }
1752
1787
 
1788
+
1789
+ /* 目前没有用到
1753
1790
  var event=this.GetEventCallback(JSCHART_EVENT_ID.ON_REPORT_MOUSE_MOVE);
1754
1791
  if (event)
1755
1792
  {
1756
1793
  var sendData={X:x, Y:y, Cell:cell };
1757
1794
  event.Callback(event,sendData,this);
1758
1795
  }
1796
+ */
1759
1797
 
1760
1798
  if (mouseStatus) this.UIElement.style.cursor=mouseStatus.Cursor;
1761
1799
 
1762
1800
  if (bDraw) this.Draw();
1801
+ else if (bDrawTooltip) this.DrawTooltip(this.LastMouseStatus.TooltipStatus);
1763
1802
  }
1764
1803
 
1765
1804
  this.UIOnMounseOut=function(e)
@@ -3328,6 +3367,28 @@ function JSReportChartContainer(uielement)
3328
3367
 
3329
3368
  return true;
3330
3369
  }
3370
+
3371
+ this.DrawTooltip=function(tooltipStatus)
3372
+ {
3373
+ if (!this.GetExtraCanvas) return;
3374
+ if (!this.TooltipCanvas)
3375
+ {
3376
+ var finder=this.GetExtraCanvas(JSReportChart.TooltipCursorCanvasKey);
3377
+ if (!finder) return;
3378
+ this.TooltipCanvas=finder.Canvas;
3379
+ }
3380
+
3381
+ if (!this.TooltipCanvas) return;
3382
+ this.ClearCanvas(this.TooltipCanvas);
3383
+ if (!this.ChartTooltip) return;
3384
+
3385
+ if (!tooltipStatus || !tooltipStatus.Data) return;
3386
+
3387
+ this.ChartTooltip.Canvas=this.TooltipCanvas;
3388
+ this.ChartTooltip.Point={ X:tooltipStatus.X, Y:tooltipStatus.Y };
3389
+ this.ChartTooltip.Data=tooltipStatus.Data.Data;
3390
+ this.ChartTooltip.Draw();
3391
+ }
3331
3392
  }
3332
3393
 
3333
3394
 
@@ -3638,6 +3699,9 @@ function ChartReport()
3638
3699
 
3639
3700
  this.RectClient={};
3640
3701
 
3702
+ //{ Rect:rtItem, Stock:stock, Index:index, Column:column, RowType:rowType, Type:drawInfo.Tooltip.Type, Data:{ AryText:[ {Text:xx} ]} };
3703
+ //Type:1=数据截断
3704
+ // { Text, Color, Title:, TitleColor, Space, Margin:{ Left, Top, Right, Bottom }}
3641
3705
  this.TooltipRect=[];
3642
3706
 
3643
3707
  this.ReloadResource=function(resource)
@@ -3736,7 +3800,6 @@ function ChartReport()
3736
3800
  if (item.FullColBGColor) colItem.FullColBGColor=item.FullColBGColor; //整列背景色
3737
3801
  if (item.HeaderBGColor) colItem.HeaderBGColor=item.HeaderBGColor; //表头背景色
3738
3802
  if (IFrameSplitOperator.IsNumber(item.Sort)) colItem.Sort=item.Sort;
3739
- if (IFrameSplitOperator.IsBool(item.EnableTooltip)) colItem.EnableTooltip=item.EnableTooltip;
3740
3803
  if (IFrameSplitOperator.IsNumber(item.FixedWidth)) colItem.FixedWidth=item.FixedWidth;
3741
3804
  if (IFrameSplitOperator.IsBool(item.EnableDragWidth)) colItem.EnableDragWidth=item.EnableDragWidth;
3742
3805
  if (IFrameSplitOperator.IsBool(item.IsDrawCallback)) colItem.IsDrawCallback=item.IsDrawCallback;
@@ -4452,7 +4515,7 @@ function ChartReport()
4452
4515
  var x=left+this.ItemMergin.Left;
4453
4516
  var textWidth=column.Width-this.ItemMergin.Left-this.ItemMergin.Right;
4454
4517
  var stock=data.Stock;
4455
- var drawInfo={ Text:null, TextColor:column.TextColor , TextAlign:column.TextAlign };
4518
+ var drawInfo={ Text:null, TextColor:column.TextColor , TextAlign:column.TextAlign, Tooltip:null };
4456
4519
  var rtItem={ Left:left, Top:top, Width:column.Width, Height:this.RowHeight };
4457
4520
  rtItem.Right=rtItem.Left+rtItem.Width;
4458
4521
  rtItem.Bottom=rtItem.Top+rtItem.Height;
@@ -4463,12 +4526,6 @@ function ChartReport()
4463
4526
  this.DrawItemBG({ Rect:rtItem, BGColor:column.FullColBGColor });
4464
4527
  }
4465
4528
 
4466
- //tooltip提示
4467
- if (column.EnableTooltip===true)
4468
- {
4469
- this.TooltipRect.push({ Rect:rtItem, Stock:stock, Index:index, Column:column, RowType:rowType })
4470
- }
4471
-
4472
4529
  if (column.Type==REPORT_COLUMN_ID.INDEX_ID)
4473
4530
  {
4474
4531
  if (rowType==1) return; //固定行序号空
@@ -4716,6 +4773,14 @@ function ChartReport()
4716
4773
  else
4717
4774
  this.DrawItemText(drawInfo.Text, drawInfo.TextColor, drawInfo.TextAlign, x, top, textWidth, drawInfo.BGColor);
4718
4775
  }
4776
+
4777
+ //tooltip提示
4778
+ if (drawInfo.Tooltip)
4779
+ {
4780
+ //Type:1=数据截断
4781
+ var tooltipData={ Rect:rtItem, Stock:stock, Index:index, Column:column, RowType:rowType, Type:drawInfo.Tooltip.Type, Data:drawInfo.Tooltip.Data };
4782
+ this.TooltipRect.push(tooltipData);
4783
+ }
4719
4784
  }
4720
4785
 
4721
4786
  this.DrawCustomText=function(drawInfo, column, left, top, cellWidth)
@@ -4764,6 +4829,13 @@ function ChartReport()
4764
4829
  this.Canvas.rect(rtCell.Left, rtCell.Top, rtCell.Width, rtCell.Height);
4765
4830
  //this.Canvas.stroke(); //调试用
4766
4831
  this.Canvas.clip();
4832
+
4833
+ //数据截断提示信息
4834
+ drawInfo.Tooltip=
4835
+ {
4836
+ Type:1,
4837
+ Data:{ AryText:[ {Text:drawInfo.Text} ] }
4838
+ }
4767
4839
  }
4768
4840
 
4769
4841
  this.Canvas.textBaseline="middle";
@@ -6041,8 +6113,7 @@ function ChartReport()
6041
6113
 
6042
6114
  }
6043
6115
 
6044
- //坐标所在单元格
6045
- this.PtInCell=function(x,y)
6116
+ this.GetTooltipData=function(x,y)
6046
6117
  {
6047
6118
  if (!IFrameSplitOperator.IsNonEmptyArray(this.TooltipRect)) return null;
6048
6119
 
@@ -6054,9 +6125,11 @@ function ChartReport()
6054
6125
 
6055
6126
  if (x>=rt.Left && x<=rt.Right && y>=rt.Top && y<=rt.Bottom)
6056
6127
  {
6057
- return { Rect:item.Rect, Stock:item.Stock, Column:item.Column, Index:item.Index };
6128
+ return { Rect:item.Rect, Stock:item.Stock, Column:item.Column, Index:item.Index, Type:item.Type, Data:item.Data };
6058
6129
  }
6059
6130
  }
6131
+
6132
+ return null;
6060
6133
  }
6061
6134
 
6062
6135
  this.PtInHeaderDragBorder=function(x, y)
@@ -6648,3 +6721,166 @@ function ChartVScrollbar()
6648
6721
  return pos;
6649
6722
  }
6650
6723
  }
6724
+
6725
+
6726
+ function ChartCellTooltip()
6727
+ {
6728
+ this.Canvas; //画布
6729
+ this.ChartBorder; //边框信息
6730
+ this.ChartFrame; //框架画法
6731
+ this.Name; //名称
6732
+ this.ClassName='ChartCellTooltip'; //类名
6733
+
6734
+ this.BGColor="rgba(255,255,225, 0.9)";
6735
+ this.BorderColor="rgb(0,0,0)";
6736
+ this.Margin={ Left:5, Right:5, Top:4, Bottom:5 };
6737
+ this.Font=`${13*GetDevicePixelRatio()}px 微软雅黑`;
6738
+ this.TextColor="rgb(0,0,0)";
6739
+ this.YOffset=20;
6740
+ this.XOffset=5;
6741
+
6742
+ this.Point; //{ X, Y}
6743
+ this.Data; //{ AryText:[ { Text, Color, Title:, TitleColor, Space, Margin:{ Left, Top, Right, Bottom }} ]}
6744
+
6745
+
6746
+ this.Draw=function()
6747
+ {
6748
+ if (!this.Canvas) return;
6749
+ if (!this.Data || !IFrameSplitOperator.IsNonEmptyArray(this.Data.AryText)) return;
6750
+ if (!this.Point) return;
6751
+
6752
+ var size={ Width:0, Height:0, Text:[] };
6753
+ this.CalculateTextSize(this.Data.AryText, size);
6754
+ if (!IFrameSplitOperator.IsNonEmptyArray(size.Text)) return;
6755
+
6756
+ this.DrawTooltip(this.Data.AryText, size);
6757
+ }
6758
+
6759
+ this.CalculateTextSize=function(aryText, size)
6760
+ {
6761
+ var width=0, height=0;
6762
+ for(var i=0;i<aryText.length;++i)
6763
+ {
6764
+ var item=aryText[i];
6765
+ var titleHeight=0, titleWidth=0;
6766
+ if (!item.Title && !item.Text) continue;
6767
+
6768
+ if (item.Title)
6769
+ {
6770
+ if (item.TitleFont) this.Canvas.font=item.TitleFont;
6771
+ else this.Canvas.font=this.Font;
6772
+
6773
+ titleWidth=this.Canvas.measureText(item.Title).width;
6774
+ titleHeight=this.Canvas.measureText("擎").width;
6775
+ }
6776
+
6777
+ var textWidth=0, textHeight=0;
6778
+ if (item.Text)
6779
+ {
6780
+ if (item.Font) this.Canvas.font=item.Font;
6781
+ else this.Canvas.font=this.Font;
6782
+
6783
+ textWidth=this.Canvas.measureText(item.Text).width;
6784
+ textHeight=this.Canvas.measureText("擎").width;
6785
+ }
6786
+
6787
+ var itemWidth=titleWidth+textWidth;
6788
+ var itemHeight=Math.max(textHeight,titleHeight);
6789
+
6790
+ if (IFrameSplitOperator.IsNumber(item.Space)) itemWidth+=item.Space;
6791
+
6792
+ if (item.Margin)
6793
+ {
6794
+ var margin=item.Margin;
6795
+ if (IFrameSplitOperator.IsNumber(margin.Left)) itemWidth+=margin.Left;
6796
+ if (IFrameSplitOperator.IsNumber(margin.Right)) itemWidth+=margin.Right;
6797
+ if (IFrameSplitOperator.IsNumber(margin.Top)) itemHeight+=margin.Top;
6798
+ if (IFrameSplitOperator.IsNumber(margin.Bottom)) itemHeight+=margin.Bottom;
6799
+ }
6800
+
6801
+ if (width<itemWidth) width=itemWidth;
6802
+ height+=itemHeight;
6803
+
6804
+ size.Text[i]={ Width: itemWidth, Height:itemHeight, TitleWidth:titleWidth, TextWidth:textWidth };
6805
+ }
6806
+
6807
+ if (this.Margin)
6808
+ {
6809
+ var margin=this.Margin;
6810
+ if (IFrameSplitOperator.IsNumber(margin.Left)) width+=margin.Left;
6811
+ if (IFrameSplitOperator.IsNumber(margin.Right)) width+=margin.Right;
6812
+ if (IFrameSplitOperator.IsNumber(margin.Top)) height+=margin.Top;
6813
+ if (IFrameSplitOperator.IsNumber(margin.Bottom)) height+=margin.Bottom;
6814
+ }
6815
+
6816
+ size.Width=width;
6817
+ size.Height=height;
6818
+ }
6819
+
6820
+ this.DrawTooltip=function(aryText, size)
6821
+ {
6822
+ var rtBG={ Left:this.Point.X+this.XOffset, Top:this.Point.Y+this.YOffset, Width:size.Width, Height:size.Height };
6823
+ rtBG.Right=rtBG.Left+rtBG.Width;
6824
+ rtBG.Bottom=rtBG.Top+rtBG.Height;
6825
+
6826
+ var border=this.ChartBorder.GetBorder();
6827
+ if (rtBG.Bottom>border.ChartHeight)
6828
+ {
6829
+ rtBG.Bottom=this.Point.Y;
6830
+ rtBG.Top=rtBG.Bottom-rtBG.Height;
6831
+ }
6832
+
6833
+ if (rtBG.Right>border.ChartWidth)
6834
+ {
6835
+ rtBG.Right=this.Point.X;
6836
+ rtBG.Left=rtBG.Right-rtBG.Width;
6837
+ }
6838
+
6839
+ if (this.BGColor)
6840
+ {
6841
+ this.Canvas.fillStyle=this.BGColor;
6842
+ this.Canvas.fillRect(ToFixedPoint(rtBG.Left),ToFixedPoint(rtBG.Top),ToFixedRect(rtBG.Width),ToFixedRect(rtBG.Height));
6843
+ }
6844
+
6845
+ if (this.BorderColor)
6846
+ {
6847
+ this.Canvas.strokeStyle=this.BorderColor;
6848
+ this.Canvas.strokeRect(ToFixedPoint(rtBG.Left),ToFixedPoint(rtBG.Top),ToFixedRect(rtBG.Width),ToFixedRect(rtBG.Height));
6849
+ }
6850
+
6851
+ var left=rtBG.Left;
6852
+ var top=rtBG.Top;
6853
+ if (this.Margin && IFrameSplitOperator.IsNumber(this.Margin.Left)) left+=this.Margin.Left;
6854
+ if (this.Margin && IFrameSplitOperator.IsNumber(this.Margin.Top)) top+=this.Margin.Top;
6855
+
6856
+ var xText, yText=top;
6857
+ for(var i=0;i<aryText.length;++i)
6858
+ {
6859
+ var item=aryText[i];
6860
+ if (!item.Title && !item.Text) continue;
6861
+ var itemSize=size.Text[i];
6862
+
6863
+ xText=left;
6864
+ yText+=itemSize.Height;
6865
+
6866
+ if (item.Margin && IFrameSplitOperator.IsNumber(item.Margin.Left)) xText+=item.Margin.Left;
6867
+ if (item.Margin && IFrameSplitOperator.IsNumber(item.Margin.Bottom)) yText-=item.Margin.Bottom;
6868
+ if (item.Title)
6869
+ {
6870
+ if (item.TitleColor) this.Canvas.fillStyle=item.TitleColor;
6871
+ else this.Canvas.fillStyle=this.TextColor;
6872
+ this.Canvas.fillText(item.Title,xText,yText,itemSize.TitleWidth);
6873
+ xText+=itemSize.titleWidth;
6874
+ if (IFrameSplitOperator.IsNumber(item.Space)) xText+=item.Space;
6875
+ }
6876
+
6877
+ if (item.Text)
6878
+ {
6879
+ if (item.Color) this.Canvas.fillStyle=item.Color;
6880
+ else this.Canvas.fillStyle=this.TextColor;
6881
+ this.Canvas.fillText(item.Text,xText,yText,itemSize.TextWidth);
6882
+ }
6883
+
6884
+ }
6885
+ }
6886
+ }