hqchart 1.1.14862 → 1.1.14870

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.
@@ -14423,98 +14423,118 @@ function AverageWidthFrame()
14423
14423
  this.DrawDayVertical(item, x, border);
14424
14424
  }
14425
14425
 
14426
- if (this.VerticalInfo[i].Message[0]!=null && this.ChartBorder.Bottom>5*pixelRatio)
14426
+ if (item.Message[0]!=null && this.ChartBorder.Bottom>5*pixelRatio)
14427
14427
  {
14428
- if (this.VerticalInfo[i].Font) this.Canvas.font=this.VerticalInfo[i].Font;
14429
-
14430
- var textLeft=0;
14431
-
14432
- this.Canvas.strokeStyle=item.TextColor;
14433
- var testWidth=this.Canvas.measureText(this.VerticalInfo[i].Message[0]).width;
14434
- var textHeight=this.Canvas.measureText("擎").width;
14435
- if (bottomTextExtend && bottomTextExtend.Align==1)
14428
+ if (IFrameSplitOperator.IsObject(item.Message[0]))
14436
14429
  {
14437
- this.Canvas.textAlign="left";
14438
- this.Canvas.textBaseline="top";
14439
- textLeft=x;
14430
+ var textObj=item.Message[0];
14431
+ if (!textObj.Font) textObj.Font=item.Font;
14432
+ if (!textObj.TextColor) textObj.TextColor=item.TextColor;
14433
+ var drawInfo=this.GetMultiLineVTextSize(textObj);
14434
+ if (drawInfo)
14435
+ {
14436
+ drawInfo.XCenter=x;
14437
+ var rtBottom={ Left:0, Right:right, Top:bottom+2*pixelRatio, Bottom:border.Height };
14438
+ rtBottom.Width=rtBottom.Right-rtBottom.Left;
14439
+ rtBottom.Height=rtBottom.Bottom-rtBottom.Top;
14440
+ drawInfo.RectBottom=rtBottom;
14441
+ drawInfo.TextRightPrev=textRightPrev;
14442
+ this.DrawMultiLineVText(drawInfo);
14443
+ if (drawInfo.TextRight) textRightPrev=drawInfo.TextRight;
14444
+ }
14440
14445
  }
14441
14446
  else
14442
14447
  {
14443
- if (x<testWidth/2)
14448
+ if (item.Font) this.Canvas.font=item.Font;
14449
+ var textLeft=0;
14450
+
14451
+ this.Canvas.strokeStyle=item.TextColor;
14452
+ var testWidth=this.Canvas.measureText(item.Message[0]).width;
14453
+ var textHeight=this.Canvas.measureText("擎").width;
14454
+ if (bottomTextExtend && bottomTextExtend.Align==1)
14444
14455
  {
14445
14456
  this.Canvas.textAlign="left";
14446
14457
  this.Canvas.textBaseline="top";
14447
14458
  textLeft=x;
14448
14459
  }
14449
- else if ((x + testWidth / 2) >= this.ChartBorder.GetChartWidth())
14450
- {
14451
- this.Canvas.textAlign = "right";
14452
- this.Canvas.textBaseline="top";
14453
- textLeft=x-testWidth;
14454
- }
14455
14460
  else
14456
14461
  {
14457
- this.Canvas.textAlign="center";
14458
- this.Canvas.textBaseline="top";
14459
- textLeft=x-(testWidth/2);
14462
+ if (x<testWidth/2)
14463
+ {
14464
+ this.Canvas.textAlign="left";
14465
+ this.Canvas.textBaseline="top";
14466
+ textLeft=x;
14467
+ }
14468
+ else if ((x + testWidth / 2) >= this.ChartBorder.GetChartWidth())
14469
+ {
14470
+ this.Canvas.textAlign = "right";
14471
+ this.Canvas.textBaseline="top";
14472
+ textLeft=x-testWidth;
14473
+ }
14474
+ else
14475
+ {
14476
+ this.Canvas.textAlign="center";
14477
+ this.Canvas.textBaseline="top";
14478
+ textLeft=x-(testWidth/2);
14479
+ }
14460
14480
  }
14461
- }
14462
14481
 
14463
- if (textRightPrev==null || textLeft>textRightPrev)
14464
- {
14465
- var yText=bottom;
14466
- if (item.LineType==3)
14482
+ if (textRightPrev==null || textLeft>textRightPrev)
14467
14483
  {
14468
- var lineLength=this.ShortXLineLength*pixelRatio;
14469
- this.Canvas.beginPath();
14470
- this.Canvas.moveTo(xFixed,yText);
14471
- this.Canvas.lineTo(xFixed,yText+lineLength);
14472
- this.Canvas.stroke();
14484
+ var yText=bottom;
14485
+ if (item.LineType==3)
14486
+ {
14487
+ var lineLength=this.ShortXLineLength*pixelRatio;
14488
+ this.Canvas.beginPath();
14489
+ this.Canvas.moveTo(xFixed,yText);
14490
+ this.Canvas.lineTo(xFixed,yText+lineLength);
14491
+ this.Canvas.stroke();
14473
14492
 
14474
- yText+=lineLength+2*pixelRatio;
14475
- }
14493
+ yText+=lineLength+2*pixelRatio;
14494
+ }
14476
14495
 
14477
- if (bottomLineExtend)
14478
- {
14479
- if (bottomLineExtend.Mode===1)
14496
+ if (bottomLineExtend)
14480
14497
  {
14481
- if (item.Value>1)
14498
+ if (bottomLineExtend.Mode===1)
14482
14499
  {
14483
- if (bottomLineExtend.Color) this.Canvas.strokeStyle=bottomLineExtend.Color;
14484
- this.Canvas.beginPath();
14485
- this.Canvas.moveTo(xFixed,bottom);
14486
- this.Canvas.lineTo(xFixed,border.ChartHeight);
14487
- this.Canvas.stroke();
14488
- x+=1;
14500
+ if (item.Value>1)
14501
+ {
14502
+ if (bottomLineExtend.Color) this.Canvas.strokeStyle=bottomLineExtend.Color;
14503
+ this.Canvas.beginPath();
14504
+ this.Canvas.moveTo(xFixed,bottom);
14505
+ this.Canvas.lineTo(xFixed,border.ChartHeight);
14506
+ this.Canvas.stroke();
14507
+ x+=1;
14508
+ }
14489
14509
  }
14490
- }
14491
- else if (bottomLineExtend.Mode===2)
14492
- {
14493
- if (bottomLineExtend.Width>=1)
14510
+ else if (bottomLineExtend.Mode===2)
14494
14511
  {
14495
- var lineLength=bottomLineExtend.Width;
14496
- if (bottomLineExtend.Color) this.Canvas.strokeStyle=bottomLineExtend.Color;
14497
- this.Canvas.beginPath();
14498
- this.Canvas.moveTo(xFixed,yText);
14499
- this.Canvas.lineTo(xFixed,yText+lineLength);
14500
- this.Canvas.stroke();
14501
-
14502
- yText+=lineLength+2;
14512
+ if (bottomLineExtend.Width>=1)
14513
+ {
14514
+ var lineLength=bottomLineExtend.Width;
14515
+ if (bottomLineExtend.Color) this.Canvas.strokeStyle=bottomLineExtend.Color;
14516
+ this.Canvas.beginPath();
14517
+ this.Canvas.moveTo(xFixed,yText);
14518
+ this.Canvas.lineTo(xFixed,yText+lineLength);
14519
+ this.Canvas.stroke();
14520
+
14521
+ yText+=lineLength+2;
14522
+ }
14503
14523
  }
14504
14524
  }
14505
- }
14506
14525
 
14507
- //item.TextBGColor="rgb(0,255,0)";
14508
- if (item.TextBGColor) //文字背景色
14509
- {
14510
- var rtText={ Left:textLeft, Top:yText+this.XBottomOffset, Width:testWidth, Height:textHeight };
14511
- this.Canvas.fillStyle=item.TextBGColor;
14512
- this.Canvas.fillRect(rtText.Left-1, rtText.Top, rtText.Width+2, rtText.Height);
14513
- }
14526
+ //item.TextBGColor="rgb(0,255,0)";
14527
+ if (item.TextBGColor) //文字背景色
14528
+ {
14529
+ var rtText={ Left:textLeft, Top:yText+this.XBottomOffset, Width:testWidth, Height:textHeight };
14530
+ this.Canvas.fillStyle=item.TextBGColor;
14531
+ this.Canvas.fillRect(rtText.Left-1, rtText.Top, rtText.Width+2, rtText.Height);
14532
+ }
14514
14533
 
14515
- this.Canvas.fillStyle=item.TextColor;
14516
- this.Canvas.fillText(this.VerticalInfo[i].Message[0],x,yText+this.XBottomOffset);
14517
- textRightPrev=textLeft+testWidth;
14534
+ this.Canvas.fillStyle=item.TextColor;
14535
+ this.Canvas.fillText(this.VerticalInfo[i].Message[0],x,yText+this.XBottomOffset);
14536
+ textRightPrev=textLeft+testWidth;
14537
+ }
14518
14538
  }
14519
14539
  }
14520
14540
 
@@ -14522,6 +14542,113 @@ function AverageWidthFrame()
14522
14542
  }
14523
14543
  }
14524
14544
 
14545
+ //{Font:, AryText:[ { AryText:[{ Text:, Color: }], }, ] }
14546
+ this.GetMultiLineVTextSize=function(obj)
14547
+ {
14548
+ if (obj.Font) this.Canvas.font=obj.Font;
14549
+
14550
+ var lineHeight=this.Canvas.measureText('擎').width;
14551
+ var aryLine=[];
14552
+ for(var i=0;i<obj.AryText.length;++i)
14553
+ {
14554
+ var item=obj.AryText[i];
14555
+ var lineInfo={ Width:0, Height:lineHeight, AryText:[], Align:2, Margin:{ Top:1, Bottom:1 } , YOffset:-1 };
14556
+ if (item.Margin)
14557
+ {
14558
+ if (IFrameSplitOperator.IsNumber(item.Margin.Top)) lineInfo.Margin.Top=item.Margin.Top;
14559
+ if (IFrameSplitOperator.IsNumber(item.Margin.Bottom)) lineInfo.Margin.Bottom=item.Margin.Bottom;
14560
+ }
14561
+ if (IFrameSplitOperator.IsNumber(item.YOffset)) lineInfo.YOffset=item.YOffset;
14562
+ if (IFrameSplitOperator.IsNumber(item.Align)) lineInfo.Align=item.Align;
14563
+
14564
+ lineInfo.Height=lineHeight+lineInfo.Margin.Top+lineInfo.Margin.Bottom;
14565
+
14566
+ for(var j=0; j<item.AryText.length; ++j)
14567
+ {
14568
+ var subItem=item.AryText[j];
14569
+ if (!subItem || !subItem.Text) continue;
14570
+ var width=this.Canvas.measureText(subItem.Text).width;
14571
+ var textItem={ Width: width, Text:subItem.Text, Color:obj.TextColor , Margin:{Left:0, Right:0 }};
14572
+ if (subItem.Color) textItem.Color=subItem.Color;
14573
+ if (subItem.Margin)
14574
+ {
14575
+ if (IFrameSplitOperator.IsNumber(subItem.Margin.Left)) textItem.Margin.Left=subItem.Margin.Left;
14576
+ if (IFrameSplitOperator.IsNumber(subItem.Margin.Right)) textItem.Margin.Right=subItem.Margin.Right;
14577
+ }
14578
+ textItem.Width=width+textItem.Margin.Right+textItem.Margin.Left;
14579
+
14580
+ lineInfo.Width+=textItem.Width;
14581
+
14582
+ lineInfo.AryText.push(textItem);
14583
+ }
14584
+
14585
+ aryLine.push(lineInfo);
14586
+ }
14587
+
14588
+ if (aryLine.length<=0) return null;
14589
+
14590
+ var width=0, height=0;
14591
+ for(var i=0;i<aryLine.length;++i)
14592
+ {
14593
+ var item=aryLine[i];
14594
+ if (width<item.Width) width=item.Width;
14595
+ height+=item.Height;
14596
+ }
14597
+
14598
+ if (width<=0 || height<=0) return null;
14599
+
14600
+ var drawInfo={ Width:width, Height:height, AryLine:aryLine, Align:2 }; //Align 1=left 2=center 3=right
14601
+ if (IFrameSplitOperator.IsNumber(obj.Align)) drawInfo.Align=obj.Align;
14602
+
14603
+ return drawInfo;
14604
+ }
14605
+
14606
+ //X轴底部文字多行输出
14607
+ this.DrawMultiLineVText=function(drawInfo)
14608
+ {
14609
+ var xLeft=drawInfo.XCenter-drawInfo.Width/2;
14610
+ if (drawInfo.Align==1) xLeft=drawInfo.XCenter;
14611
+ if (drawInfo.TextRightPrev!=null && drawInfo.TextRightPrev>xLeft)
14612
+ return false;
14613
+
14614
+ this.Canvas.font=drawInfo.Font;
14615
+ this.Canvas.textAlign="left";
14616
+ this.Canvas.textBaseline="bottom";
14617
+ var yText=drawInfo.RectBottom.Top;
14618
+ var textRight=null;
14619
+ for(var i=0, j=0;i<drawInfo.AryLine.length;++i)
14620
+ {
14621
+ var lineItem=drawInfo.AryLine[i];
14622
+ if (drawInfo.Align==1)
14623
+ {
14624
+ var xLeft=drawInfo.XCenter-drawInfo.Width/2;
14625
+ if (lineItem.Align==1) xLeft=drawInfo.XCenter;
14626
+ else if (lineItem.Align==2) xLeft=drawInfo.XCenter+drawInfo.Width-lineItem.Width;
14627
+ }
14628
+ else
14629
+ {
14630
+ var xLeft=drawInfo.XCenter-lineItem.Width/2;
14631
+ if (lineItem.Align==1) xLeft=drawInfo.XCenter-drawInfo.Width/2;
14632
+ else if (lineItem.Align==2) xLeft=drawInfo.XCenter+drawInfo.Width/2-lineItem.Width;
14633
+ }
14634
+
14635
+ if (xLeft<1) xLeft=1;
14636
+ yText+=lineItem.Height;
14637
+ for(j=0;j<lineItem.AryText.length;++j)
14638
+ {
14639
+ var item=lineItem.AryText[j];
14640
+ this.Canvas.fillStyle=item.Color;
14641
+ this.Canvas.fillText(item.Text,xLeft+item.Margin.Left,yText+lineItem.YOffset);
14642
+ xLeft+=item.Width;
14643
+ }
14644
+
14645
+ if (textRight==null || textRight<xLeft) textRight=xLeft;
14646
+ }
14647
+
14648
+ drawInfo.TextRight=textRight;
14649
+ return true;
14650
+ }
14651
+
14525
14652
  //Y坐标转y轴数值
14526
14653
  this.GetYData=function(y,isLimit)
14527
14654
  {
@@ -19816,7 +19943,7 @@ function OverlayKLineFrame()
19816
19943
 
19817
19944
  var text=item.Message[1];
19818
19945
  if (Array.isArray(item.Message[1])) text=item.Message[1][0];
19819
-
19946
+ this.Canvas.fillStyle=item.TextColor;
19820
19947
  if (rightExtendText && rightExtendText.Align)
19821
19948
  {
19822
19949
  var textWidth=rightWidth;
@@ -19828,7 +19955,6 @@ function OverlayKLineFrame()
19828
19955
  {
19829
19956
  var xText=right+2;
19830
19957
  if (rightLine && rightLine.Width>0) xText+=rightLine.Width;
19831
- this.Canvas.fillStyle=item.TextColor;
19832
19958
  this.Canvas.textAlign="left";
19833
19959
  this.Canvas.fillText(text,xText,y);
19834
19960
  }
@@ -64192,9 +64318,14 @@ function IChartDrawPicture()
64192
64318
  pt.X=this.Frame.GetXFromIndex(item.XValue-data.DataOffset);
64193
64319
  pt.Y=this.Frame.GetYFromData(item.YValue);
64194
64320
  }
64321
+
64322
+ if (Path2DHelper.PtInPoint(x,y,pt,radius))
64323
+ return i;
64324
+ /*
64195
64325
  this.Canvas.beginPath();
64196
64326
  this.Canvas.arc(pt.X,pt.Y,radius,0,360);
64197
64327
  if (this.Canvas.isPointInPath(x,y)) return i;
64328
+ */
64198
64329
  }
64199
64330
 
64200
64331
  return -1;
@@ -64212,6 +64343,20 @@ function IChartDrawPicture()
64212
64343
  var pixel=GetDevicePixelRatio();
64213
64344
  lineWidth*=pixel;
64214
64345
  for(var i=0;i<this.LinePoint.length; ++i)
64346
+ {
64347
+ var item=this.LinePoint[i];
64348
+ var ptStart=item.Start;
64349
+ var ptEnd=item.End;
64350
+
64351
+ if (Path2DHelper.PtInLine(x, y, ptStart, ptEnd, lineWidth))
64352
+ {
64353
+ return i;
64354
+ }
64355
+ }
64356
+ return -1;
64357
+
64358
+ /*
64359
+ for(var i=0;i<this.LinePoint.length; ++i)
64215
64360
  {
64216
64361
  var item=this.LinePoint[i];
64217
64362
  var ptStart=item.Start;
@@ -64240,6 +64385,7 @@ function IChartDrawPicture()
64240
64385
  }
64241
64386
 
64242
64387
  return -1;
64388
+ */
64243
64389
  }
64244
64390
 
64245
64391
  //0-10 鼠标对应的点索引 100=鼠标在正个图形上 -1 鼠标不在图形上
@@ -66933,6 +67079,18 @@ function ChartDrawPictureRect()
66933
67079
  //点是否在线段上 水平线段
66934
67080
  this.IsPointInLine=function(aryPoint,x,y,option)
66935
67081
  {
67082
+ var lineWidth=5;
67083
+ var pixel=GetDevicePixelRatio();
67084
+ if (IFrameSplitOperator.IsPlusNumber(this.LineWidth) && this.LineWidth>lineWidth) lineWidth=this.LineWidth;
67085
+ if (option && IFrameSplitOperator.IsNumber(option.Zoom)) lineWidth+=option.Zoom;
67086
+ else if (this.Option && IFrameSplitOperator.IsNumber(this.Option.Zoom)) lineWidth+=this.Option.Zoom;
67087
+ lineWidth*=pixel;
67088
+ if (Path2DHelper.PtInLine(x,y,aryPoint[0], aryPoint[1], lineWidth))
67089
+ return true;
67090
+
67091
+ return false;
67092
+
67093
+ /*
66936
67094
  var radius=5;
66937
67095
  if (option && IFrameSplitOperator.IsNumber(option.Zoom)) radius+=option.Zoom;
66938
67096
  else if (this.Option && IFrameSplitOperator.IsNumber(this.Option.Zoom)) radius+=this.Option.Zoom;
@@ -66947,11 +67105,14 @@ function ChartDrawPictureRect()
66947
67105
  this.Canvas.closePath();
66948
67106
  if (this.Canvas.isPointInPath(x,y))
66949
67107
  return true;
67108
+ */
66950
67109
  }
66951
67110
 
66952
67111
  //垂直线段
66953
67112
  this.IsPointInLine2=function(aryPoint,x,y,option)
66954
67113
  {
67114
+ return this.IsPointInLine(aryPoint,x,y,option);
67115
+ /*
66955
67116
  var radius=5;
66956
67117
  if (option && IFrameSplitOperator.IsNumber(option.Zoom)) radius+=option.Zoom;
66957
67118
  else if (this.Option && IFrameSplitOperator.IsNumber(this.Option.Zoom)) radius+=this.Option.Zoom;
@@ -66966,6 +67127,7 @@ function ChartDrawPictureRect()
66966
67127
  this.Canvas.closePath();
66967
67128
  if (this.Canvas.isPointInPath(x,y))
66968
67129
  return true;
67130
+ */
66969
67131
  }
66970
67132
  }
66971
67133
 
@@ -103004,6 +103166,117 @@ function GetLocalTime(i) //得到标准时区的时间的函数
103004
103166
  return new Date(utcTime + 3600000 * i);
103005
103167
  }
103006
103168
 
103169
+ //图形路径方法
103170
+ function Path2DHelper() { }
103171
+ const PI2 = Math.PI * 2;
103172
+
103173
+ //点是否在线段上
103174
+ Path2DHelper.PtInLine=function(x, y, pt, pt2, lineWidth)
103175
+ {
103176
+ if (lineWidth<=0) return false;
103177
+
103178
+ var x0=pt.X, y0=pt.Y;
103179
+ var x1=pt2.X, y1=pt2.Y;
103180
+
103181
+ const _l = lineWidth;
103182
+ let _a = 0;
103183
+ let _b = x0;
103184
+
103185
+ // Quick reject
103186
+ if (
103187
+ (y > y0 + _l && y > y1 + _l)
103188
+ || (y < y0 - _l && y < y1 - _l)
103189
+ || (x > x0 + _l && x > x1 + _l)
103190
+ || (x < x0 - _l && x < x1 - _l)
103191
+ )
103192
+ {
103193
+ return false;
103194
+ }
103195
+
103196
+ if (x0 !== x1)
103197
+ {
103198
+ _a = (y0 - y1) / (x0 - x1);
103199
+ _b = (x0 * y1 - x1 * y0) / (x0 - x1);
103200
+ }
103201
+ else
103202
+ {
103203
+ return Math.abs(x - x0) <= _l / 2;
103204
+ }
103205
+
103206
+ const tmp = _a * x - y + _b;
103207
+ const _s = tmp * tmp / (_a * _a + 1);
103208
+ return _s <= _l / 2 * _l / 2;
103209
+ }
103210
+
103211
+ //点是否在圆点上
103212
+ Path2DHelper.PtInPoint=function(x,y, ptCenter, radius)
103213
+ {
103214
+ if (radius<=0) return false;
103215
+
103216
+ var cx=ptCenter.X;
103217
+ var cy=ptCenter.Y;
103218
+
103219
+ x -= cx;
103220
+ y -= cy;
103221
+ const d = Math.sqrt(x * x + y * y); //到圆心的距离
103222
+
103223
+ if (d>radius) return false;
103224
+
103225
+ return true;
103226
+ }
103227
+
103228
+ Path2DHelper.PtInArc=function(x, y, ptCenter, radius, startAngle, endAngle,lineWidth, anticlockwise)
103229
+ {
103230
+ if (lineWidth<=0) return false;
103231
+
103232
+ const _l = lineWidth;
103233
+ var cx=ptCenter.X;
103234
+ var cy=ptCenter.Y;
103235
+
103236
+ x -= cx;
103237
+ y -= cy;
103238
+ const d = Math.sqrt(x * x + y * y);
103239
+
103240
+ if ((d - _l > r) || (d + _l < r))
103241
+ return false;
103242
+
103243
+ // TODO
103244
+ if (Math.abs(startAngle - endAngle) % PI2 < 1e-4)
103245
+ {
103246
+ // Is a circle
103247
+ return true;
103248
+ }
103249
+
103250
+ if (anticlockwise)
103251
+ {
103252
+ const tmp = startAngle;
103253
+ startAngle = Path2DHelper.FormatRadian(endAngle);
103254
+ endAngle = Path2DHelper.FormatRadian(tmp);
103255
+ }
103256
+ else
103257
+ {
103258
+ startAngle = Path2DHelper.FormatRadian(startAngle);
103259
+ endAngle = Path2DHelper.FormatRadian(endAngle);
103260
+ }
103261
+
103262
+ if (startAngle > endAngle)
103263
+ endAngle += PI2;
103264
+
103265
+ var angle = Math.atan2(y, x);
103266
+ if (angle < 0)
103267
+ angle += PI2;
103268
+
103269
+ return (angle >= startAngle && angle <= endAngle) || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
103270
+ }
103271
+
103272
+ //统一弧度方向
103273
+ Path2DHelper.FormatRadian=function(angle)
103274
+ {
103275
+ angle%= PI2;
103276
+ if (angle<0) angle += PI2;
103277
+ return angle;
103278
+ }
103279
+
103007
103280
 
103008
103281
 
103009
103282