From cba8c1c7c17cc60c6cd2c929172597105d595f39 Mon Sep 17 00:00:00 2001 From: jones2000 Date: Mon, 26 Aug 2024 16:33:36 +0800 Subject: [PATCH] ver 13760 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 13759 修改ChartDrawHLine右侧标签页显示样式 13756 ChartDrawHLine 代码重构,增加限制只显示在对应的窗口范围内 13752 小程序指标脚本增加函数LINEDASH() 13751 指标脚本增加函数LINEDASH() 13750 修改DOTLINE代码逻辑 13749 小程序增加DOTLINE虚线设置 13748 小程序修正黑色风格下指标数值箭头颜色配置错误 13747 ChartClipColorStick修正没有获取当前屏第1个数据的,上一条数据。 13745 ChartClipColorStick上下增加数值显示 13744 ChartClipColorStick增加差值同向显示 --- umychart_uniapp_h5/umychart.uniapp.h5.js | 523 +++++++++++++----- vuehqchart/src/jscommon/umychart.complier.js | 28 +- vuehqchart/src/jscommon/umychart.js | 493 ++++++++++++----- vuehqchart/src/jscommon/umychart.version.js | 2 +- .../src/jscommon/umychart.vue/umychart.vue.js | 523 +++++++++++++----- webhqchart.demo/jscommon/umychart.complier.js | 28 +- webhqchart.demo/jscommon/umychart.js | 493 ++++++++++++----- webhqchart.demo/jscommon/umychart.version.js | 2 +- webhqchart/umychart.complier.js | 28 +- webhqchart/umychart.js | 493 ++++++++++++----- webhqchart/umychart.version.js | 2 +- wechathqchart/umychart.chartpaint.wechat.js | 3 +- wechathqchart/umychart.complier.wechat.js | 17 + wechathqchart/umychart.index.wechat.js | 10 +- wechathqchart/umychart.resource.wechat.js | 11 + wechathqchart/umychart.style.wechat.js | 14 +- .../umychart.uniapp.canvas.helper.js | 4 + wechathqchart/umychart.version.wechat.js | 2 +- 18 files changed, 2042 insertions(+), 634 deletions(-) diff --git a/umychart_uniapp_h5/umychart.uniapp.h5.js b/umychart_uniapp_h5/umychart.uniapp.h5.js index 3dae0ebf3..fbe018697 100644 --- a/umychart_uniapp_h5/umychart.uniapp.h5.js +++ b/umychart_uniapp_h5/umychart.uniapp.h5.js @@ -34590,6 +34590,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType=0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine=false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.BreakPoint; //断开的点索引 Set(); @@ -34635,7 +34636,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var drawCount=0; for(var i=this.Data.DataOffset,j=0;i0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -34799,7 +34800,7 @@ function ChartLine() this.ClipClient(bHScreen); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -39971,16 +39972,38 @@ function ChartClipColorStick() this.UpColor=g_JSChartResource.UpBarColor; this.DownColor=g_JSChartResource.DownBarColor; this.LineWidth=1; + this.Style=0; //1=同方向 0=上下两个方向 + //差值线 this.DownDiffColor=g_JSChartResource.DownBarColor; this.UpDiffColor=g_JSChartResource.UpBarColor; + //文字 + this.TextLabelConfig= + { + Font:`${12*GetDevicePixelRatio()}px 微软雅黑`, + TextMargin:{ Left:2, Right:2, Bottom:2, Top:2 }, + TextColor:"rgb(230,230,230)", + UpColor:"rgb(137,16,19)", + DownColor:"rgb(44,104,57)", + UnchangeColor:"rgb(111,112,115)", + BorderColor:"rgb(0,0,0)", + + //缓存 + LabelWidth:0, + TextHeight:0, + MaxTextWidth:0, + } + this.BaseLineColor; //基准线 this.BaseValue=0; this.Super_GetMaxMin=this.GetMaxMin; //父类的方法 this.ValueRange; //{ Max:, Min: } //固定最大最小值 + this.IsShowText=false; + + this.SetOption=function(option) { if (!option) return; @@ -39991,11 +40014,18 @@ function ChartClipColorStick() if (option.UpDiffColor) this.UpDiffColor=option.UpDiffColor; if (option.BaseLineColor) this.BaseLineColor=option.BaseLineColor; if (IFrameSplitOperator.IsNumber(option.BaseValue)) this.BaseValue=option.BaseValue; + if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style; if (option.ValueRange) this.ValueRange=option.ValueRange; + } this.Draw=function() { + this.IsShowText=false; + this.TextLabelConfig.LabelWidth=0; + this.TextLabelConfig.TextHeight=0; + this.TextLabelConfig.MaxTextWidth=0; + if (!this.IsShow || this.ChartFrame.IsMinSize || !this.IsVisible) return; if (this.IsShowIndexTitleOnly()) return; if (this.IsHideScriptIndex()) return; @@ -40006,23 +40036,44 @@ function ChartClipColorStick() return; } - this.Canvas.save(); var dataWidth=this.ChartFrame.DataWidth; + var distanceWidth=this.ChartFrame.DistanceWidth; + var xPointCount=this.ChartFrame.XPointCount; + var bHScreen=this.ChartFrame.IsHScreen===true; + var lineWidth=this.LineWidth*GetDevicePixelRatio(); if (this.LineWidth==50) lineWidth=dataWidth; else if (lineWidth>dataWidth) lineWidth=dataWidth; - + + if (!bHScreen) + { + var itemWidth=dataWidth+distanceWidth; + var bMinute=this.IsMinuteFrame(); + if (bMinute) + { + var border=this.ChartBorder.GetBorder(); + itemWidth=(border.Right-border.Left)/(xPointCount-1); + } + + this.Canvas.font=this.TextLabelConfig.Font; + this.TextLabelConfig.MaxTextWidth=this.Canvas.measureText("-888").width; + this.TextLabelConfig.LabelWidth=this.TextLabelConfig.MaxTextWidth+this.TextLabelConfig.TextMargin.Left+this.TextLabelConfig.TextMargin.Right; + this.IsShowText=itemWidth>this.TextLabelConfig.LabelWidth; + this.TextLabelConfig.TextHeight=this.Canvas.measureText("擎").width; + } + + this.Canvas.save(); if (IFrameSplitOperator.IsNumber(this.BaseValue) && this.BaseValue!=0) { this.DrawBaseLine(); - if (this.BaseValue>0) this.DrawBars(lineWidth, true); - else this.DrawBars(lineWidth, false); + if (this.BaseValue>0) this.DrawBars(lineWidth, true, true); + else this.DrawBars(lineWidth, false, true); } else { //上下分开画 - this.DrawBars(lineWidth, true); + this.DrawBars(lineWidth, true, true); this.DrawBars(lineWidth, false); } @@ -40030,15 +40081,15 @@ function ChartClipColorStick() this.Canvas.restore(); } - this.DrawBars=function(lineWidth, bUpBar) + this.DrawBars=function(lineWidth, bUpBar, bDrawLabel) { var isMinute=this.IsMinuteFrame(); var dataWidth=this.ChartFrame.DataWidth; var distanceWidth=this.ChartFrame.DistanceWidth; var xPointCount=this.ChartFrame.XPointCount; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; - if (isHSCreen) + if (bHScreen) { var border=this.ChartBorder.GetHScreenBorder(); var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin; @@ -40057,19 +40108,14 @@ function ChartClipColorStick() } var yBottom=this.ChartFrame.GetYFromData(this.BaseValue); - var aryBar=[], aryDiffBar=[]; - for(var i=this.Data.DataOffset,j=0;i0) preValue=this.Data.Data[start-1]; //上一个数值 + for(var i=start,j=0;i=0) continue; - } if (isMinute) { @@ -40085,6 +40131,21 @@ function ChartClipColorStick() if (x>chartright) break; + var textItem={ X:x, Value:value }; + if (IFrameSplitOperator.IsNumber(preValue)) textItem.DiffValue=value-preValue; + aryText.push(textItem); + + preValue=value; + + if (bUpBar) + { + if (value<0) continue; + } + else + { + if (value>=0) continue; + } + var bDiffBar=false; var diffValue=null; if (this.BaseValue>0) @@ -40092,7 +40153,10 @@ function ChartClipColorStick() if (valuethis.BaseValue) { bDiffBar=true; - diffValue=this.BaseValue+(value-this.BaseValue) + if (this.Style==1) + diffValue=this.BaseValue-(value-this.BaseValue); + else + diffValue=this.BaseValue+(value-this.BaseValue) } } if (!bDiffBar) { var y=this.ChartFrame.GetYFromData(value); - aryBar.push({X:x, Y:y}); + aryBar.push({X:x, Y:y }); } else { var y=this.ChartFrame.GetYFromData(diffValue); - aryDiffBar.push({X:x, Y:y}); + aryDiffBar.push({X:x, Y:y }); } } @@ -40121,6 +40188,7 @@ function ChartClipColorStick() else this.Canvas.strokeStyle=this.DownColor; this.DrawStick(aryBar,lineWidth,yBottom); + if (this.BaseValue>0) { @@ -40133,13 +40201,14 @@ function ChartClipColorStick() this.DrawStick(aryDiffBar,lineWidth,yBottom); } + if (this.IsShowText && bDrawLabel) this.DrawStickText(aryText); } this.DrawStick=function(aryData, lineWidth, yBottom) { if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; var drawCount=0; this.Canvas.beginPath(); for(var i=0; i0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + + var value=item.DiffValue; + var rtDraw={ Left:xLeft, Width:config.LabelWidth, Bottom:border.TopEx-1, Height:itemHeight }; + rtDraw.Right=rtDraw.Left+rtDraw.Width; + rtDraw.Top=rtDraw.Bottom-rtDraw.Height; + if (IFrameSplitOperator.IsNumber(value)) + { + var bgColor=config.UnchangeColor; + if (value>0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + } + } + + //数值标签 + this.DrawTextLabel=function(value, clrGB, clrBorder, clrText, rtDraw, textHeight, textWidth, textMargin) + { + if (clrGB) + { + this.Canvas.fillStyle=clrGB; + this.Canvas.fillRect(rtDraw.Left ,rtDraw.Top, (rtDraw.Width), (rtDraw.Height)); + } + + if (clrBorder) + { + this.Canvas.lineWidth=2; + this.Canvas.strokeStyle=clrBorder; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + else + { + this.Canvas.lineWidth=1; + this.Canvas.strokeStyle="rgb(0,0,0)"; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + + var aryText=[null, null]; //大于3位数的 2行输出 + var sign=""; //负数 + if (value<0) + { + value=Math.abs(value); + sign='-'; + } + + if (value>999) + { + var thousand=parseInt(value/1000); + var hundred=parseInt(value%1000); + + aryText[0]=`${sign}${thousand}`; + aryText[1]=`${hundred}`; + if (hundred<10) aryText[1]=`00${hundred}`; + else if (hundred<100) aryText[1]=`0${hundred}`; + } + else + { + aryText[1]=`${sign}${value.toFixed(0)}`; + } + + this.Canvas.textAlign="right"; + this.Canvas.textBaseline="top"; + var xRight=rtDraw.Right-(rtDraw.Right-rtDraw.Left-textWidth)/2; + + this.Canvas.fillStyle=clrText; + var yText=textMargin.Top+rtDraw.Top; + for(var i=0;i0) { - if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Min)) - range.Min-=maxDiffValue; + if (this.Style==1) + { + if (IFrameSplitOperator.IsNumber(maxDiffValue)) + { + var value=this.BaseValue+maxDiffValue; + if (IFrameSplitOperator.IsNumber(range.Max) || range.Maxvalue) range.Min=value; + } + } + else + { + if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Max)) + range.Max+=maxDiffValue; + } } return range; @@ -62283,7 +62476,7 @@ function ChartDrawHLine() this.ButtonBGColor='rgb(190,190,190)'; this.ButtonSpace=3; - this.TextMargin={ Left:0, Right:0 }; + this.TextMargin={ Left:0, Right:0, Top:0, Bottom:0, YOffset:4*GetDevicePixelRatio() }; this.AlwaysShowLab=false; //总是显示标签 @@ -62307,7 +62500,9 @@ function ChartDrawHLine() `${12*GetDevicePixelRatio()}px 微软雅黑`, `${12*GetDevicePixelRatio()}px 微软雅黑`, ], - }; + }; + + this.LableInfo; //{ Position:2=右侧外部 } //内部变量 this.ColseButtonSize=0; @@ -62315,7 +62510,7 @@ function ChartDrawHLine() this.ButtonBGWidth=0; this.VerticalButtonInfo={ Width:0, Height:0 }; //垂直按钮信息 - + this.IsPointIn=this.IsPointIn_XYValue_Line; this.SetOption=function(option) { @@ -62376,6 +62571,9 @@ function ChartDrawHLine() var item=option.TextMargin; if (IFrameSplitOperator.IsNumber(item.Left)) this.TextMargin.Left=item.Left; if (IFrameSplitOperator.IsNumber(item.Right)) this.TextMargin.Right=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) this.TextMargin.Top=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) this.TextMargin.Bottom=item.Bottom; + if (IFrameSplitOperator.IsNumber(item.YOffset)) this.TextMargin.YOffset=item.YOffset; } } } @@ -62392,10 +62590,6 @@ function ChartDrawHLine() return storageData; } - - this.IsPointIn=this.IsPointIn_XYValue_Line; - - /* this.GetXYCoordinate=function() { @@ -62452,7 +62646,7 @@ function ChartDrawHLine() this.ColseButtonSize=0; this.SettingButtonSize=0; this.ButtonBGWidth=0; - + this.LableInfo=null; this.VerticalButtonInfo.Width=0; this.VerticalButtonInfo.Height=0; @@ -62515,7 +62709,7 @@ function ChartDrawHLine() } this.LinePoint.push(line); - if (bVisibleRange) + if (bVisibleRange) //在可视范围内 { var yValue=this.Frame.GetYData(drawPoint[0].Y, false); var strPrice=yValue.toFixed(this.Precision); @@ -62529,15 +62723,11 @@ function ChartDrawHLine() this.DrawPriceText(strPrice, line.Start, line.End, 1); } } - - var labInfo; - if (this.GetLabelCallback) labInfo=this.GetLabelCallback(this); + + if (this.GetLabelCallback) this.LableInfo=this.GetLabelCallback(this); this.AryShowButton=this.GetShowButton(); //获取按钮 - - //框架内的描述信息 - if (labInfo && bVisibleRange) - this.DrawLab(labInfo, drawPoint[0].Y); + if (bVisibleRange) this.DrawInternalLabel(drawPoint[0].Y); //内部价格标签 //画中心点 if (bVisibleRange) @@ -62554,11 +62744,11 @@ function ChartDrawHLine() { var rtDraw={ }; this.CalculateButtonSize(); - this.DrawValueText(drawPoint[0].Y, rtDraw, labInfo); - if (labInfo) this.DrawRightLab(labInfo, rtDraw); - if (labInfo && bVisibleRange) this.DrawCustomHLine(labInfo, drawPoint[0].Y); + this.DrawRightLabel(drawPoint[0].Y); + if (bVisibleRange) this.DrawCustomHLine(drawPoint[0].Y); } + //鼠标是否在按钮上 if (moveonPoint && mouseStatus) { @@ -62606,113 +62796,141 @@ function ChartDrawHLine() ++lineCount; } - var size={ Width:maxWidth, Height: lineCount*(lineHeight+lineSpace)+lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + var size={ Width:maxWidth, Height:lineCount*lineHeight+(lineCount-1)*lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + if (labInfo.LabelMargin) + { + var item=labInfo.LabelMargin; + if (IFrameSplitOperator.IsNumber(item.Left)) size.Width+=item.Left; + if (IFrameSplitOperator.IsNumber(item.Right)) size.Width+=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) size.Height+=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) size.Height+=item.Bottom; + } return size; } - this.DrawLab=function(labInfo, y) + //绘制窗口内部标签 + this.DrawInternalLabel=function(y) { - if (!labInfo) return; - if (!IFrameSplitOperator.IsNonEmptyArray(labInfo.AryText)) return; - if (labInfo.Position===2) return; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText)) return; + if (this.LableInfo.Position==2) return; - var left=this.Frame.ChartBorder.GetLeft(); - var right=this.Frame.ChartBorder.GetRight(); - var labSize=this.CalculateLabSize(labInfo); + var border=this.Frame.GetBorder(); + var left=border.Left; + var right=border.Right; + var labSize=this.CalculateLabSize(this.LableInfo); var drawLeft=right-labSize.Width; + var drawRight=drawLeft+labSize.Width; var drawTop=y-labSize.Height-1; + if (drawTop<=border.TopEx) drawTop=y+1; - //背景色 - if (labInfo.BGColor) - { - this.Canvas.fillStyle=labInfo.BGColor; - var rtTop=y-labSize.Height-4; - this.Canvas.fillRect(ToFixedRect(drawLeft),ToFixedRect(rtTop),ToFixedRect(right+drawLeft),ToFixedRect(y-rtTop)); - } + var rtLabel={ Left:drawLeft, Right:drawRight, Top:drawTop, Width:labSize.Width, Height:labSize.Height }; + rtLabel.Bottom=rtLabel.Top+rtLabel.Height; - var yText=drawTop; - for(var i=0;i0) yText+=lineSpace; + var item=labelInfo.AryText[i]; if (item.Name) { this.Canvas.textAlign="left"; this.Canvas.fillStyle=item.NameColor; - this.Canvas.fillText(item.Name,drawLeft+1,yText+1); + this.Canvas.fillText(item.Name,xText,yText); } if (item.Text) { this.Canvas.textAlign="right"; this.Canvas.fillStyle=item.TextColor; - this.Canvas.fillText(item.Text,drawRight-1,yText+1); + this.Canvas.fillText(item.Text,yRightText,yText); } - yText+=labSize.LineHeight+lineSpace; + yText+=labelSize.LineHeight; } + } - this.DrawVerticalButton(rtLab); + this.DrawRightLabel=function(y) + { + var rtDraw={ }; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText) || this.LableInfo.Position!=2) + { + this.DrawValueText(y, rtDraw); + return; + } + + var priceSize=this.CalculateValueText(y); + var labSize=this.CalculateLabSize(this.LableInfo); + var border=this.Frame.GetBorder(); + var yTop=y-priceSize.Height/2; + var totalHeight=priceSize.Height+labSize.Height; + var yBottom=yTop+totalHeight; + var option={ }; + if (yBottom>border.Bottom) //超过窗口底部, 标签位置不动 + { + yBottom=border.Bottom; + yTop=yBottom-totalHeight; + option.Top=yTop; + } + + this.DrawValueText(y, rtDraw, option); + + var drawLeft=rtDraw.Right-labSize.Width; + if (drawLeftyFixed) yMin=yFixed; } - if (yMax!=yMin && labInfo.VLine) + if (yMax!=yMin && this.LableInfo.VLine) { - var item=labInfo.VLine; + var item=this.LableInfo.VLine; var x=left+20*pixelRatio; if (IFrameSplitOperator.IsNumber(item.XOffset)) x=left+item.XOffset*pixelRatio; x=ToFixedPoint(x); @@ -62753,14 +62971,14 @@ function ChartDrawHLine() } } - this.DrawValueText=function(y, rtDraw, labInfo) + this.DrawValueText=function(y, rtDraw, option) { var left=this.Frame.ChartBorder.GetLeft(); var right=this.Frame.ChartBorder.GetRight(); var top=this.Frame.ChartBorder.GetTopEx(); var bottom=this.Frame.ChartBorder.GetBottomEx(); var pixelTatio = GetDevicePixelRatio(); - + var labInfo=this.LabelInfo; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.TopOffset)) top-=labInfo.TopOffset; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.BottomOffset)) bottom+=labInfo.BottomOffset; @@ -62795,12 +63013,21 @@ function ChartDrawHLine() this.Canvas.font=this.Font; var textWidth=this.Canvas.measureText(strValue).width; var lineHeight=this.GetFontHeight(); - var rtBG={ Left:right+this.RightSpaceWidth, Top:y- lineHeight/2, Width:textWidth+4, Height:lineHeight }; - //rtBG.Right=rtBG.Left+rtBG.Width; - rtBG.Bottom=rtBG.Top+rtBG.Height; + var rtBG={ Left:right+this.RightSpaceWidth, YCenter:y, Width:textWidth, Height:lineHeight }; + rtBG.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); rtBG.Width+=(this.TextMargin.Left+this.TextMargin.Right); rtBG.Right=rtBG.Left+rtBG.Width; - var xText=rtBG.Left+this.TextMargin.Left+2; + rtBG.Top=rtBG.YCenter-rtBG.Height/2; + rtBG.Bottom=rtBG.Top+rtBG.Height; + + if (option && IFrameSplitOperator.IsNumber(option.Top)) + { + rtBG.Top=option.Top; + rtBG.Bottom=rtBG.Top+rtBG.Height; + } + + var xText=rtBG.Left+this.TextMargin.Left; + var yText=rtBG.Top+this.TextMargin.Top+this.TextMargin.YOffset; if (this.ButtonPosition==1) { @@ -62813,8 +63040,8 @@ function ChartDrawHLine() this.Canvas.fillStyle=this.ValueTextColor this.Canvas.textAlign="left"; - this.Canvas.textBaseline="middle"; - this.Canvas.fillText(strValue,xText,y); + this.Canvas.textBaseline="top"; + this.Canvas.fillText(strValue,xText,yText); rtDraw.Left=rtBG.Left; rtDraw.Top=rtBG.Top; @@ -62824,6 +63051,24 @@ function ChartDrawHLine() this.DrawButton(rtBG.Top, rtBG.Right, lineHeight, rtDraw); } + //计算右侧价格标签大小 + this.CalculateValueText=function(y) + { + var yValue=this.Frame.GetYData(y,false); + var strValue=yValue.toFixed(this.Precision); + if (this.LableInfo &&this.LableInfo.PriceSuffixText) strValue+=this.LableInfo.PriceSuffixText; + + this.Canvas.font=this.Font; + var textWidth=this.Canvas.measureText(strValue).width; + var lineHeight=this.GetFontHeight(); + + var size={ Width:textWidth, Height:lineHeight }; + size.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); + size.Width+=(this.TextMargin.Left+this.TextMargin.Right); + + return size; + } + this.DrawPriceText=function(text, ptStart, ptEnd, position) { if (position!=1 && position!=0) return; @@ -108900,6 +109145,12 @@ function JSDraw(errorHandler,symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + this.KLINETYPE=function(type) { return type; @@ -115771,6 +116022,7 @@ function JSExecute(ast,option) var isFirstDraw=null; let xOffset=null, yOffset=null; var klineType=null; + var lineDash=null; for(let j=0; j0) line.LineWidth=width; } - if (varItem.IsDotLine) line.IsDotLine=true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine=true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow==false) line.IsShow=false; let titleIndex=windowIndex+1; @@ -138395,7 +138666,7 @@ function ScrollBarBGChart() -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13759"; function PrintHQChartVersion() { diff --git a/vuehqchart/src/jscommon/umychart.complier.js b/vuehqchart/src/jscommon/umychart.complier.js index f28478d9f..eb58d8275 100644 --- a/vuehqchart/src/jscommon/umychart.complier.js +++ b/vuehqchart/src/jscommon/umychart.complier.js @@ -10528,6 +10528,12 @@ function JSDraw(errorHandler,symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + this.KLINETYPE=function(type) { return type; @@ -17399,6 +17405,7 @@ function JSExecute(ast,option) var isFirstDraw=null; let xOffset=null, yOffset=null; var klineType=null; + var lineDash=null; for(let j=0; j0) line.LineWidth=width; } - if (varItem.IsDotLine) line.IsDotLine=true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine=true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow==false) line.IsShow=false; let titleIndex=windowIndex+1; diff --git a/vuehqchart/src/jscommon/umychart.js b/vuehqchart/src/jscommon/umychart.js index d4009ab11..eca611e9e 100644 --- a/vuehqchart/src/jscommon/umychart.js +++ b/vuehqchart/src/jscommon/umychart.js @@ -30665,6 +30665,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType=0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine=false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.BreakPoint; //断开的点索引 Set(); @@ -30710,7 +30711,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var drawCount=0; for(var i=this.Data.DataOffset,j=0;i0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -30874,7 +30875,7 @@ function ChartLine() this.ClipClient(bHScreen); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -36046,16 +36047,38 @@ function ChartClipColorStick() this.UpColor=g_JSChartResource.UpBarColor; this.DownColor=g_JSChartResource.DownBarColor; this.LineWidth=1; + this.Style=0; //1=同方向 0=上下两个方向 + //差值线 this.DownDiffColor=g_JSChartResource.DownBarColor; this.UpDiffColor=g_JSChartResource.UpBarColor; + //文字 + this.TextLabelConfig= + { + Font:`${12*GetDevicePixelRatio()}px 微软雅黑`, + TextMargin:{ Left:2, Right:2, Bottom:2, Top:2 }, + TextColor:"rgb(230,230,230)", + UpColor:"rgb(137,16,19)", + DownColor:"rgb(44,104,57)", + UnchangeColor:"rgb(111,112,115)", + BorderColor:"rgb(0,0,0)", + + //缓存 + LabelWidth:0, + TextHeight:0, + MaxTextWidth:0, + } + this.BaseLineColor; //基准线 this.BaseValue=0; this.Super_GetMaxMin=this.GetMaxMin; //父类的方法 this.ValueRange; //{ Max:, Min: } //固定最大最小值 + this.IsShowText=false; + + this.SetOption=function(option) { if (!option) return; @@ -36066,11 +36089,18 @@ function ChartClipColorStick() if (option.UpDiffColor) this.UpDiffColor=option.UpDiffColor; if (option.BaseLineColor) this.BaseLineColor=option.BaseLineColor; if (IFrameSplitOperator.IsNumber(option.BaseValue)) this.BaseValue=option.BaseValue; + if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style; if (option.ValueRange) this.ValueRange=option.ValueRange; + } this.Draw=function() { + this.IsShowText=false; + this.TextLabelConfig.LabelWidth=0; + this.TextLabelConfig.TextHeight=0; + this.TextLabelConfig.MaxTextWidth=0; + if (!this.IsShow || this.ChartFrame.IsMinSize || !this.IsVisible) return; if (this.IsShowIndexTitleOnly()) return; if (this.IsHideScriptIndex()) return; @@ -36081,23 +36111,44 @@ function ChartClipColorStick() return; } - this.Canvas.save(); var dataWidth=this.ChartFrame.DataWidth; + var distanceWidth=this.ChartFrame.DistanceWidth; + var xPointCount=this.ChartFrame.XPointCount; + var bHScreen=this.ChartFrame.IsHScreen===true; + var lineWidth=this.LineWidth*GetDevicePixelRatio(); if (this.LineWidth==50) lineWidth=dataWidth; else if (lineWidth>dataWidth) lineWidth=dataWidth; - + + if (!bHScreen) + { + var itemWidth=dataWidth+distanceWidth; + var bMinute=this.IsMinuteFrame(); + if (bMinute) + { + var border=this.ChartBorder.GetBorder(); + itemWidth=(border.Right-border.Left)/(xPointCount-1); + } + + this.Canvas.font=this.TextLabelConfig.Font; + this.TextLabelConfig.MaxTextWidth=this.Canvas.measureText("-888").width; + this.TextLabelConfig.LabelWidth=this.TextLabelConfig.MaxTextWidth+this.TextLabelConfig.TextMargin.Left+this.TextLabelConfig.TextMargin.Right; + this.IsShowText=itemWidth>this.TextLabelConfig.LabelWidth; + this.TextLabelConfig.TextHeight=this.Canvas.measureText("擎").width; + } + + this.Canvas.save(); if (IFrameSplitOperator.IsNumber(this.BaseValue) && this.BaseValue!=0) { this.DrawBaseLine(); - if (this.BaseValue>0) this.DrawBars(lineWidth, true); - else this.DrawBars(lineWidth, false); + if (this.BaseValue>0) this.DrawBars(lineWidth, true, true); + else this.DrawBars(lineWidth, false, true); } else { //上下分开画 - this.DrawBars(lineWidth, true); + this.DrawBars(lineWidth, true, true); this.DrawBars(lineWidth, false); } @@ -36105,15 +36156,15 @@ function ChartClipColorStick() this.Canvas.restore(); } - this.DrawBars=function(lineWidth, bUpBar) + this.DrawBars=function(lineWidth, bUpBar, bDrawLabel) { var isMinute=this.IsMinuteFrame(); var dataWidth=this.ChartFrame.DataWidth; var distanceWidth=this.ChartFrame.DistanceWidth; var xPointCount=this.ChartFrame.XPointCount; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; - if (isHSCreen) + if (bHScreen) { var border=this.ChartBorder.GetHScreenBorder(); var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin; @@ -36132,19 +36183,14 @@ function ChartClipColorStick() } var yBottom=this.ChartFrame.GetYFromData(this.BaseValue); - var aryBar=[], aryDiffBar=[]; - for(var i=this.Data.DataOffset,j=0;i0) preValue=this.Data.Data[start-1]; //上一个数值 + for(var i=start,j=0;i=0) continue; - } if (isMinute) { @@ -36160,6 +36206,21 @@ function ChartClipColorStick() if (x>chartright) break; + var textItem={ X:x, Value:value }; + if (IFrameSplitOperator.IsNumber(preValue)) textItem.DiffValue=value-preValue; + aryText.push(textItem); + + preValue=value; + + if (bUpBar) + { + if (value<0) continue; + } + else + { + if (value>=0) continue; + } + var bDiffBar=false; var diffValue=null; if (this.BaseValue>0) @@ -36167,7 +36228,10 @@ function ChartClipColorStick() if (valuethis.BaseValue) { bDiffBar=true; - diffValue=this.BaseValue+(value-this.BaseValue) + if (this.Style==1) + diffValue=this.BaseValue-(value-this.BaseValue); + else + diffValue=this.BaseValue+(value-this.BaseValue) } } if (!bDiffBar) { var y=this.ChartFrame.GetYFromData(value); - aryBar.push({X:x, Y:y}); + aryBar.push({X:x, Y:y }); } else { var y=this.ChartFrame.GetYFromData(diffValue); - aryDiffBar.push({X:x, Y:y}); + aryDiffBar.push({X:x, Y:y }); } } @@ -36196,6 +36263,7 @@ function ChartClipColorStick() else this.Canvas.strokeStyle=this.DownColor; this.DrawStick(aryBar,lineWidth,yBottom); + if (this.BaseValue>0) { @@ -36208,13 +36276,14 @@ function ChartClipColorStick() this.DrawStick(aryDiffBar,lineWidth,yBottom); } + if (this.IsShowText && bDrawLabel) this.DrawStickText(aryText); } this.DrawStick=function(aryData, lineWidth, yBottom) { if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; var drawCount=0; this.Canvas.beginPath(); for(var i=0; i0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + + var value=item.DiffValue; + var rtDraw={ Left:xLeft, Width:config.LabelWidth, Bottom:border.TopEx-1, Height:itemHeight }; + rtDraw.Right=rtDraw.Left+rtDraw.Width; + rtDraw.Top=rtDraw.Bottom-rtDraw.Height; + if (IFrameSplitOperator.IsNumber(value)) + { + var bgColor=config.UnchangeColor; + if (value>0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + } + } + + //数值标签 + this.DrawTextLabel=function(value, clrGB, clrBorder, clrText, rtDraw, textHeight, textWidth, textMargin) + { + if (clrGB) + { + this.Canvas.fillStyle=clrGB; + this.Canvas.fillRect(rtDraw.Left ,rtDraw.Top, (rtDraw.Width), (rtDraw.Height)); + } + + if (clrBorder) + { + this.Canvas.lineWidth=2; + this.Canvas.strokeStyle=clrBorder; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + else + { + this.Canvas.lineWidth=1; + this.Canvas.strokeStyle="rgb(0,0,0)"; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + + var aryText=[null, null]; //大于3位数的 2行输出 + var sign=""; //负数 + if (value<0) + { + value=Math.abs(value); + sign='-'; + } + + if (value>999) + { + var thousand=parseInt(value/1000); + var hundred=parseInt(value%1000); + + aryText[0]=`${sign}${thousand}`; + aryText[1]=`${hundred}`; + if (hundred<10) aryText[1]=`00${hundred}`; + else if (hundred<100) aryText[1]=`0${hundred}`; + } + else + { + aryText[1]=`${sign}${value.toFixed(0)}`; + } + + this.Canvas.textAlign="right"; + this.Canvas.textBaseline="top"; + var xRight=rtDraw.Right-(rtDraw.Right-rtDraw.Left-textWidth)/2; + + this.Canvas.fillStyle=clrText; + var yText=textMargin.Top+rtDraw.Top; + for(var i=0;i0) { - if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Min)) - range.Min-=maxDiffValue; + if (this.Style==1) + { + if (IFrameSplitOperator.IsNumber(maxDiffValue)) + { + var value=this.BaseValue+maxDiffValue; + if (IFrameSplitOperator.IsNumber(range.Max) || range.Maxvalue) range.Min=value; + } + } + else + { + if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Max)) + range.Max+=maxDiffValue; + } } return range; @@ -58358,7 +58551,7 @@ function ChartDrawHLine() this.ButtonBGColor='rgb(190,190,190)'; this.ButtonSpace=3; - this.TextMargin={ Left:0, Right:0 }; + this.TextMargin={ Left:0, Right:0, Top:0, Bottom:0, YOffset:4*GetDevicePixelRatio() }; this.AlwaysShowLab=false; //总是显示标签 @@ -58382,7 +58575,9 @@ function ChartDrawHLine() `${12*GetDevicePixelRatio()}px 微软雅黑`, `${12*GetDevicePixelRatio()}px 微软雅黑`, ], - }; + }; + + this.LableInfo; //{ Position:2=右侧外部 } //内部变量 this.ColseButtonSize=0; @@ -58390,7 +58585,7 @@ function ChartDrawHLine() this.ButtonBGWidth=0; this.VerticalButtonInfo={ Width:0, Height:0 }; //垂直按钮信息 - + this.IsPointIn=this.IsPointIn_XYValue_Line; this.SetOption=function(option) { @@ -58451,6 +58646,9 @@ function ChartDrawHLine() var item=option.TextMargin; if (IFrameSplitOperator.IsNumber(item.Left)) this.TextMargin.Left=item.Left; if (IFrameSplitOperator.IsNumber(item.Right)) this.TextMargin.Right=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) this.TextMargin.Top=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) this.TextMargin.Bottom=item.Bottom; + if (IFrameSplitOperator.IsNumber(item.YOffset)) this.TextMargin.YOffset=item.YOffset; } } } @@ -58467,10 +58665,6 @@ function ChartDrawHLine() return storageData; } - - this.IsPointIn=this.IsPointIn_XYValue_Line; - - /* this.GetXYCoordinate=function() { @@ -58527,7 +58721,7 @@ function ChartDrawHLine() this.ColseButtonSize=0; this.SettingButtonSize=0; this.ButtonBGWidth=0; - + this.LableInfo=null; this.VerticalButtonInfo.Width=0; this.VerticalButtonInfo.Height=0; @@ -58590,7 +58784,7 @@ function ChartDrawHLine() } this.LinePoint.push(line); - if (bVisibleRange) + if (bVisibleRange) //在可视范围内 { var yValue=this.Frame.GetYData(drawPoint[0].Y, false); var strPrice=yValue.toFixed(this.Precision); @@ -58604,15 +58798,11 @@ function ChartDrawHLine() this.DrawPriceText(strPrice, line.Start, line.End, 1); } } - - var labInfo; - if (this.GetLabelCallback) labInfo=this.GetLabelCallback(this); + + if (this.GetLabelCallback) this.LableInfo=this.GetLabelCallback(this); this.AryShowButton=this.GetShowButton(); //获取按钮 - - //框架内的描述信息 - if (labInfo && bVisibleRange) - this.DrawLab(labInfo, drawPoint[0].Y); + if (bVisibleRange) this.DrawInternalLabel(drawPoint[0].Y); //内部价格标签 //画中心点 if (bVisibleRange) @@ -58629,11 +58819,11 @@ function ChartDrawHLine() { var rtDraw={ }; this.CalculateButtonSize(); - this.DrawValueText(drawPoint[0].Y, rtDraw, labInfo); - if (labInfo) this.DrawRightLab(labInfo, rtDraw); - if (labInfo && bVisibleRange) this.DrawCustomHLine(labInfo, drawPoint[0].Y); + this.DrawRightLabel(drawPoint[0].Y); + if (bVisibleRange) this.DrawCustomHLine(drawPoint[0].Y); } + //鼠标是否在按钮上 if (moveonPoint && mouseStatus) { @@ -58681,113 +58871,141 @@ function ChartDrawHLine() ++lineCount; } - var size={ Width:maxWidth, Height: lineCount*(lineHeight+lineSpace)+lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + var size={ Width:maxWidth, Height:lineCount*lineHeight+(lineCount-1)*lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + if (labInfo.LabelMargin) + { + var item=labInfo.LabelMargin; + if (IFrameSplitOperator.IsNumber(item.Left)) size.Width+=item.Left; + if (IFrameSplitOperator.IsNumber(item.Right)) size.Width+=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) size.Height+=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) size.Height+=item.Bottom; + } return size; } - this.DrawLab=function(labInfo, y) + //绘制窗口内部标签 + this.DrawInternalLabel=function(y) { - if (!labInfo) return; - if (!IFrameSplitOperator.IsNonEmptyArray(labInfo.AryText)) return; - if (labInfo.Position===2) return; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText)) return; + if (this.LableInfo.Position==2) return; - var left=this.Frame.ChartBorder.GetLeft(); - var right=this.Frame.ChartBorder.GetRight(); - var labSize=this.CalculateLabSize(labInfo); + var border=this.Frame.GetBorder(); + var left=border.Left; + var right=border.Right; + var labSize=this.CalculateLabSize(this.LableInfo); var drawLeft=right-labSize.Width; + var drawRight=drawLeft+labSize.Width; var drawTop=y-labSize.Height-1; + if (drawTop<=border.TopEx) drawTop=y+1; - //背景色 - if (labInfo.BGColor) - { - this.Canvas.fillStyle=labInfo.BGColor; - var rtTop=y-labSize.Height-4; - this.Canvas.fillRect(ToFixedRect(drawLeft),ToFixedRect(rtTop),ToFixedRect(right+drawLeft),ToFixedRect(y-rtTop)); - } - - var yText=drawTop; - for(var i=0;i0) yText+=lineSpace; + var item=labelInfo.AryText[i]; if (item.Name) { this.Canvas.textAlign="left"; this.Canvas.fillStyle=item.NameColor; - this.Canvas.fillText(item.Name,drawLeft+1,yText+1); + this.Canvas.fillText(item.Name,xText,yText); } if (item.Text) { this.Canvas.textAlign="right"; this.Canvas.fillStyle=item.TextColor; - this.Canvas.fillText(item.Text,drawRight-1,yText+1); + this.Canvas.fillText(item.Text,yRightText,yText); } - yText+=labSize.LineHeight+lineSpace; + yText+=labelSize.LineHeight; + } + } + + this.DrawRightLabel=function(y) + { + var rtDraw={ }; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText) || this.LableInfo.Position!=2) + { + this.DrawValueText(y, rtDraw); + return; + } + + var priceSize=this.CalculateValueText(y); + var labSize=this.CalculateLabSize(this.LableInfo); + var border=this.Frame.GetBorder(); + var yTop=y-priceSize.Height/2; + var totalHeight=priceSize.Height+labSize.Height; + var yBottom=yTop+totalHeight; + var option={ }; + if (yBottom>border.Bottom) //超过窗口底部, 标签位置不动 + { + yBottom=border.Bottom; + yTop=yBottom-totalHeight; + option.Top=yTop; } - this.DrawVerticalButton(rtLab); + this.DrawValueText(y, rtDraw, option); + + var drawLeft=rtDraw.Right-labSize.Width; + if (drawLeftyFixed) yMin=yFixed; } - if (yMax!=yMin && labInfo.VLine) + if (yMax!=yMin && this.LableInfo.VLine) { - var item=labInfo.VLine; + var item=this.LableInfo.VLine; var x=left+20*pixelRatio; if (IFrameSplitOperator.IsNumber(item.XOffset)) x=left+item.XOffset*pixelRatio; x=ToFixedPoint(x); @@ -58828,14 +59046,14 @@ function ChartDrawHLine() } } - this.DrawValueText=function(y, rtDraw, labInfo) + this.DrawValueText=function(y, rtDraw, option) { var left=this.Frame.ChartBorder.GetLeft(); var right=this.Frame.ChartBorder.GetRight(); var top=this.Frame.ChartBorder.GetTopEx(); var bottom=this.Frame.ChartBorder.GetBottomEx(); var pixelTatio = GetDevicePixelRatio(); - + var labInfo=this.LabelInfo; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.TopOffset)) top-=labInfo.TopOffset; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.BottomOffset)) bottom+=labInfo.BottomOffset; @@ -58870,12 +59088,21 @@ function ChartDrawHLine() this.Canvas.font=this.Font; var textWidth=this.Canvas.measureText(strValue).width; var lineHeight=this.GetFontHeight(); - var rtBG={ Left:right+this.RightSpaceWidth, Top:y- lineHeight/2, Width:textWidth+4, Height:lineHeight }; - //rtBG.Right=rtBG.Left+rtBG.Width; - rtBG.Bottom=rtBG.Top+rtBG.Height; + var rtBG={ Left:right+this.RightSpaceWidth, YCenter:y, Width:textWidth, Height:lineHeight }; + rtBG.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); rtBG.Width+=(this.TextMargin.Left+this.TextMargin.Right); rtBG.Right=rtBG.Left+rtBG.Width; - var xText=rtBG.Left+this.TextMargin.Left+2; + rtBG.Top=rtBG.YCenter-rtBG.Height/2; + rtBG.Bottom=rtBG.Top+rtBG.Height; + + if (option && IFrameSplitOperator.IsNumber(option.Top)) + { + rtBG.Top=option.Top; + rtBG.Bottom=rtBG.Top+rtBG.Height; + } + + var xText=rtBG.Left+this.TextMargin.Left; + var yText=rtBG.Top+this.TextMargin.Top+this.TextMargin.YOffset; if (this.ButtonPosition==1) { @@ -58888,8 +59115,8 @@ function ChartDrawHLine() this.Canvas.fillStyle=this.ValueTextColor this.Canvas.textAlign="left"; - this.Canvas.textBaseline="middle"; - this.Canvas.fillText(strValue,xText,y); + this.Canvas.textBaseline="top"; + this.Canvas.fillText(strValue,xText,yText); rtDraw.Left=rtBG.Left; rtDraw.Top=rtBG.Top; @@ -58899,6 +59126,24 @@ function ChartDrawHLine() this.DrawButton(rtBG.Top, rtBG.Right, lineHeight, rtDraw); } + //计算右侧价格标签大小 + this.CalculateValueText=function(y) + { + var yValue=this.Frame.GetYData(y,false); + var strValue=yValue.toFixed(this.Precision); + if (this.LableInfo &&this.LableInfo.PriceSuffixText) strValue+=this.LableInfo.PriceSuffixText; + + this.Canvas.font=this.Font; + var textWidth=this.Canvas.measureText(strValue).width; + var lineHeight=this.GetFontHeight(); + + var size={ Width:textWidth, Height:lineHeight }; + size.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); + size.Width+=(this.TextMargin.Left+this.TextMargin.Right); + + return size; + } + this.DrawPriceText=function(text, ptStart, ptEnd, position) { if (position!=1 && position!=0) return; diff --git a/vuehqchart/src/jscommon/umychart.version.js b/vuehqchart/src/jscommon/umychart.version.js index d295089ad..549b0c8a6 100644 --- a/vuehqchart/src/jscommon/umychart.version.js +++ b/vuehqchart/src/jscommon/umychart.version.js @@ -5,7 +5,7 @@ -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13759"; function PrintHQChartVersion() { diff --git a/vuehqchart/src/jscommon/umychart.vue/umychart.vue.js b/vuehqchart/src/jscommon/umychart.vue/umychart.vue.js index 66676a541..c7169b956 100644 --- a/vuehqchart/src/jscommon/umychart.vue/umychart.vue.js +++ b/vuehqchart/src/jscommon/umychart.vue/umychart.vue.js @@ -34634,6 +34634,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType=0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine=false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.BreakPoint; //断开的点索引 Set(); @@ -34679,7 +34680,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var drawCount=0; for(var i=this.Data.DataOffset,j=0;i0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -34843,7 +34844,7 @@ function ChartLine() this.ClipClient(bHScreen); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -40015,16 +40016,38 @@ function ChartClipColorStick() this.UpColor=g_JSChartResource.UpBarColor; this.DownColor=g_JSChartResource.DownBarColor; this.LineWidth=1; + this.Style=0; //1=同方向 0=上下两个方向 + //差值线 this.DownDiffColor=g_JSChartResource.DownBarColor; this.UpDiffColor=g_JSChartResource.UpBarColor; + //文字 + this.TextLabelConfig= + { + Font:`${12*GetDevicePixelRatio()}px 微软雅黑`, + TextMargin:{ Left:2, Right:2, Bottom:2, Top:2 }, + TextColor:"rgb(230,230,230)", + UpColor:"rgb(137,16,19)", + DownColor:"rgb(44,104,57)", + UnchangeColor:"rgb(111,112,115)", + BorderColor:"rgb(0,0,0)", + + //缓存 + LabelWidth:0, + TextHeight:0, + MaxTextWidth:0, + } + this.BaseLineColor; //基准线 this.BaseValue=0; this.Super_GetMaxMin=this.GetMaxMin; //父类的方法 this.ValueRange; //{ Max:, Min: } //固定最大最小值 + this.IsShowText=false; + + this.SetOption=function(option) { if (!option) return; @@ -40035,11 +40058,18 @@ function ChartClipColorStick() if (option.UpDiffColor) this.UpDiffColor=option.UpDiffColor; if (option.BaseLineColor) this.BaseLineColor=option.BaseLineColor; if (IFrameSplitOperator.IsNumber(option.BaseValue)) this.BaseValue=option.BaseValue; + if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style; if (option.ValueRange) this.ValueRange=option.ValueRange; + } this.Draw=function() { + this.IsShowText=false; + this.TextLabelConfig.LabelWidth=0; + this.TextLabelConfig.TextHeight=0; + this.TextLabelConfig.MaxTextWidth=0; + if (!this.IsShow || this.ChartFrame.IsMinSize || !this.IsVisible) return; if (this.IsShowIndexTitleOnly()) return; if (this.IsHideScriptIndex()) return; @@ -40050,23 +40080,44 @@ function ChartClipColorStick() return; } - this.Canvas.save(); var dataWidth=this.ChartFrame.DataWidth; + var distanceWidth=this.ChartFrame.DistanceWidth; + var xPointCount=this.ChartFrame.XPointCount; + var bHScreen=this.ChartFrame.IsHScreen===true; + var lineWidth=this.LineWidth*GetDevicePixelRatio(); if (this.LineWidth==50) lineWidth=dataWidth; else if (lineWidth>dataWidth) lineWidth=dataWidth; - + + if (!bHScreen) + { + var itemWidth=dataWidth+distanceWidth; + var bMinute=this.IsMinuteFrame(); + if (bMinute) + { + var border=this.ChartBorder.GetBorder(); + itemWidth=(border.Right-border.Left)/(xPointCount-1); + } + + this.Canvas.font=this.TextLabelConfig.Font; + this.TextLabelConfig.MaxTextWidth=this.Canvas.measureText("-888").width; + this.TextLabelConfig.LabelWidth=this.TextLabelConfig.MaxTextWidth+this.TextLabelConfig.TextMargin.Left+this.TextLabelConfig.TextMargin.Right; + this.IsShowText=itemWidth>this.TextLabelConfig.LabelWidth; + this.TextLabelConfig.TextHeight=this.Canvas.measureText("擎").width; + } + + this.Canvas.save(); if (IFrameSplitOperator.IsNumber(this.BaseValue) && this.BaseValue!=0) { this.DrawBaseLine(); - if (this.BaseValue>0) this.DrawBars(lineWidth, true); - else this.DrawBars(lineWidth, false); + if (this.BaseValue>0) this.DrawBars(lineWidth, true, true); + else this.DrawBars(lineWidth, false, true); } else { //上下分开画 - this.DrawBars(lineWidth, true); + this.DrawBars(lineWidth, true, true); this.DrawBars(lineWidth, false); } @@ -40074,15 +40125,15 @@ function ChartClipColorStick() this.Canvas.restore(); } - this.DrawBars=function(lineWidth, bUpBar) + this.DrawBars=function(lineWidth, bUpBar, bDrawLabel) { var isMinute=this.IsMinuteFrame(); var dataWidth=this.ChartFrame.DataWidth; var distanceWidth=this.ChartFrame.DistanceWidth; var xPointCount=this.ChartFrame.XPointCount; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; - if (isHSCreen) + if (bHScreen) { var border=this.ChartBorder.GetHScreenBorder(); var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin; @@ -40101,19 +40152,14 @@ function ChartClipColorStick() } var yBottom=this.ChartFrame.GetYFromData(this.BaseValue); - var aryBar=[], aryDiffBar=[]; - for(var i=this.Data.DataOffset,j=0;i0) preValue=this.Data.Data[start-1]; //上一个数值 + for(var i=start,j=0;i=0) continue; - } if (isMinute) { @@ -40129,6 +40175,21 @@ function ChartClipColorStick() if (x>chartright) break; + var textItem={ X:x, Value:value }; + if (IFrameSplitOperator.IsNumber(preValue)) textItem.DiffValue=value-preValue; + aryText.push(textItem); + + preValue=value; + + if (bUpBar) + { + if (value<0) continue; + } + else + { + if (value>=0) continue; + } + var bDiffBar=false; var diffValue=null; if (this.BaseValue>0) @@ -40136,7 +40197,10 @@ function ChartClipColorStick() if (valuethis.BaseValue) { bDiffBar=true; - diffValue=this.BaseValue+(value-this.BaseValue) + if (this.Style==1) + diffValue=this.BaseValue-(value-this.BaseValue); + else + diffValue=this.BaseValue+(value-this.BaseValue) } } if (!bDiffBar) { var y=this.ChartFrame.GetYFromData(value); - aryBar.push({X:x, Y:y}); + aryBar.push({X:x, Y:y }); } else { var y=this.ChartFrame.GetYFromData(diffValue); - aryDiffBar.push({X:x, Y:y}); + aryDiffBar.push({X:x, Y:y }); } } @@ -40165,6 +40232,7 @@ function ChartClipColorStick() else this.Canvas.strokeStyle=this.DownColor; this.DrawStick(aryBar,lineWidth,yBottom); + if (this.BaseValue>0) { @@ -40177,13 +40245,14 @@ function ChartClipColorStick() this.DrawStick(aryDiffBar,lineWidth,yBottom); } + if (this.IsShowText && bDrawLabel) this.DrawStickText(aryText); } this.DrawStick=function(aryData, lineWidth, yBottom) { if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; var drawCount=0; this.Canvas.beginPath(); for(var i=0; i0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + + var value=item.DiffValue; + var rtDraw={ Left:xLeft, Width:config.LabelWidth, Bottom:border.TopEx-1, Height:itemHeight }; + rtDraw.Right=rtDraw.Left+rtDraw.Width; + rtDraw.Top=rtDraw.Bottom-rtDraw.Height; + if (IFrameSplitOperator.IsNumber(value)) + { + var bgColor=config.UnchangeColor; + if (value>0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + } + } + + //数值标签 + this.DrawTextLabel=function(value, clrGB, clrBorder, clrText, rtDraw, textHeight, textWidth, textMargin) + { + if (clrGB) + { + this.Canvas.fillStyle=clrGB; + this.Canvas.fillRect(rtDraw.Left ,rtDraw.Top, (rtDraw.Width), (rtDraw.Height)); + } + + if (clrBorder) + { + this.Canvas.lineWidth=2; + this.Canvas.strokeStyle=clrBorder; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + else + { + this.Canvas.lineWidth=1; + this.Canvas.strokeStyle="rgb(0,0,0)"; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + + var aryText=[null, null]; //大于3位数的 2行输出 + var sign=""; //负数 + if (value<0) + { + value=Math.abs(value); + sign='-'; + } + + if (value>999) + { + var thousand=parseInt(value/1000); + var hundred=parseInt(value%1000); + + aryText[0]=`${sign}${thousand}`; + aryText[1]=`${hundred}`; + if (hundred<10) aryText[1]=`00${hundred}`; + else if (hundred<100) aryText[1]=`0${hundred}`; + } + else + { + aryText[1]=`${sign}${value.toFixed(0)}`; + } + + this.Canvas.textAlign="right"; + this.Canvas.textBaseline="top"; + var xRight=rtDraw.Right-(rtDraw.Right-rtDraw.Left-textWidth)/2; + + this.Canvas.fillStyle=clrText; + var yText=textMargin.Top+rtDraw.Top; + for(var i=0;i0) { - if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Min)) - range.Min-=maxDiffValue; + if (this.Style==1) + { + if (IFrameSplitOperator.IsNumber(maxDiffValue)) + { + var value=this.BaseValue+maxDiffValue; + if (IFrameSplitOperator.IsNumber(range.Max) || range.Maxvalue) range.Min=value; + } + } + else + { + if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Max)) + range.Max+=maxDiffValue; + } } return range; @@ -62327,7 +62520,7 @@ function ChartDrawHLine() this.ButtonBGColor='rgb(190,190,190)'; this.ButtonSpace=3; - this.TextMargin={ Left:0, Right:0 }; + this.TextMargin={ Left:0, Right:0, Top:0, Bottom:0, YOffset:4*GetDevicePixelRatio() }; this.AlwaysShowLab=false; //总是显示标签 @@ -62351,7 +62544,9 @@ function ChartDrawHLine() `${12*GetDevicePixelRatio()}px 微软雅黑`, `${12*GetDevicePixelRatio()}px 微软雅黑`, ], - }; + }; + + this.LableInfo; //{ Position:2=右侧外部 } //内部变量 this.ColseButtonSize=0; @@ -62359,7 +62554,7 @@ function ChartDrawHLine() this.ButtonBGWidth=0; this.VerticalButtonInfo={ Width:0, Height:0 }; //垂直按钮信息 - + this.IsPointIn=this.IsPointIn_XYValue_Line; this.SetOption=function(option) { @@ -62420,6 +62615,9 @@ function ChartDrawHLine() var item=option.TextMargin; if (IFrameSplitOperator.IsNumber(item.Left)) this.TextMargin.Left=item.Left; if (IFrameSplitOperator.IsNumber(item.Right)) this.TextMargin.Right=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) this.TextMargin.Top=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) this.TextMargin.Bottom=item.Bottom; + if (IFrameSplitOperator.IsNumber(item.YOffset)) this.TextMargin.YOffset=item.YOffset; } } } @@ -62436,10 +62634,6 @@ function ChartDrawHLine() return storageData; } - - this.IsPointIn=this.IsPointIn_XYValue_Line; - - /* this.GetXYCoordinate=function() { @@ -62496,7 +62690,7 @@ function ChartDrawHLine() this.ColseButtonSize=0; this.SettingButtonSize=0; this.ButtonBGWidth=0; - + this.LableInfo=null; this.VerticalButtonInfo.Width=0; this.VerticalButtonInfo.Height=0; @@ -62559,7 +62753,7 @@ function ChartDrawHLine() } this.LinePoint.push(line); - if (bVisibleRange) + if (bVisibleRange) //在可视范围内 { var yValue=this.Frame.GetYData(drawPoint[0].Y, false); var strPrice=yValue.toFixed(this.Precision); @@ -62573,15 +62767,11 @@ function ChartDrawHLine() this.DrawPriceText(strPrice, line.Start, line.End, 1); } } - - var labInfo; - if (this.GetLabelCallback) labInfo=this.GetLabelCallback(this); + + if (this.GetLabelCallback) this.LableInfo=this.GetLabelCallback(this); this.AryShowButton=this.GetShowButton(); //获取按钮 - - //框架内的描述信息 - if (labInfo && bVisibleRange) - this.DrawLab(labInfo, drawPoint[0].Y); + if (bVisibleRange) this.DrawInternalLabel(drawPoint[0].Y); //内部价格标签 //画中心点 if (bVisibleRange) @@ -62598,11 +62788,11 @@ function ChartDrawHLine() { var rtDraw={ }; this.CalculateButtonSize(); - this.DrawValueText(drawPoint[0].Y, rtDraw, labInfo); - if (labInfo) this.DrawRightLab(labInfo, rtDraw); - if (labInfo && bVisibleRange) this.DrawCustomHLine(labInfo, drawPoint[0].Y); + this.DrawRightLabel(drawPoint[0].Y); + if (bVisibleRange) this.DrawCustomHLine(drawPoint[0].Y); } + //鼠标是否在按钮上 if (moveonPoint && mouseStatus) { @@ -62650,113 +62840,141 @@ function ChartDrawHLine() ++lineCount; } - var size={ Width:maxWidth, Height: lineCount*(lineHeight+lineSpace)+lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + var size={ Width:maxWidth, Height:lineCount*lineHeight+(lineCount-1)*lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + if (labInfo.LabelMargin) + { + var item=labInfo.LabelMargin; + if (IFrameSplitOperator.IsNumber(item.Left)) size.Width+=item.Left; + if (IFrameSplitOperator.IsNumber(item.Right)) size.Width+=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) size.Height+=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) size.Height+=item.Bottom; + } return size; } - this.DrawLab=function(labInfo, y) + //绘制窗口内部标签 + this.DrawInternalLabel=function(y) { - if (!labInfo) return; - if (!IFrameSplitOperator.IsNonEmptyArray(labInfo.AryText)) return; - if (labInfo.Position===2) return; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText)) return; + if (this.LableInfo.Position==2) return; - var left=this.Frame.ChartBorder.GetLeft(); - var right=this.Frame.ChartBorder.GetRight(); - var labSize=this.CalculateLabSize(labInfo); + var border=this.Frame.GetBorder(); + var left=border.Left; + var right=border.Right; + var labSize=this.CalculateLabSize(this.LableInfo); var drawLeft=right-labSize.Width; + var drawRight=drawLeft+labSize.Width; var drawTop=y-labSize.Height-1; + if (drawTop<=border.TopEx) drawTop=y+1; - //背景色 - if (labInfo.BGColor) - { - this.Canvas.fillStyle=labInfo.BGColor; - var rtTop=y-labSize.Height-4; - this.Canvas.fillRect(ToFixedRect(drawLeft),ToFixedRect(rtTop),ToFixedRect(right+drawLeft),ToFixedRect(y-rtTop)); - } + var rtLabel={ Left:drawLeft, Right:drawRight, Top:drawTop, Width:labSize.Width, Height:labSize.Height }; + rtLabel.Bottom=rtLabel.Top+rtLabel.Height; - var yText=drawTop; - for(var i=0;i0) yText+=lineSpace; + var item=labelInfo.AryText[i]; if (item.Name) { this.Canvas.textAlign="left"; this.Canvas.fillStyle=item.NameColor; - this.Canvas.fillText(item.Name,drawLeft+1,yText+1); + this.Canvas.fillText(item.Name,xText,yText); } if (item.Text) { this.Canvas.textAlign="right"; this.Canvas.fillStyle=item.TextColor; - this.Canvas.fillText(item.Text,drawRight-1,yText+1); + this.Canvas.fillText(item.Text,yRightText,yText); } - yText+=labSize.LineHeight+lineSpace; + yText+=labelSize.LineHeight; } + } - this.DrawVerticalButton(rtLab); + this.DrawRightLabel=function(y) + { + var rtDraw={ }; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText) || this.LableInfo.Position!=2) + { + this.DrawValueText(y, rtDraw); + return; + } + + var priceSize=this.CalculateValueText(y); + var labSize=this.CalculateLabSize(this.LableInfo); + var border=this.Frame.GetBorder(); + var yTop=y-priceSize.Height/2; + var totalHeight=priceSize.Height+labSize.Height; + var yBottom=yTop+totalHeight; + var option={ }; + if (yBottom>border.Bottom) //超过窗口底部, 标签位置不动 + { + yBottom=border.Bottom; + yTop=yBottom-totalHeight; + option.Top=yTop; + } + + this.DrawValueText(y, rtDraw, option); + + var drawLeft=rtDraw.Right-labSize.Width; + if (drawLeftyFixed) yMin=yFixed; } - if (yMax!=yMin && labInfo.VLine) + if (yMax!=yMin && this.LableInfo.VLine) { - var item=labInfo.VLine; + var item=this.LableInfo.VLine; var x=left+20*pixelRatio; if (IFrameSplitOperator.IsNumber(item.XOffset)) x=left+item.XOffset*pixelRatio; x=ToFixedPoint(x); @@ -62797,14 +63015,14 @@ function ChartDrawHLine() } } - this.DrawValueText=function(y, rtDraw, labInfo) + this.DrawValueText=function(y, rtDraw, option) { var left=this.Frame.ChartBorder.GetLeft(); var right=this.Frame.ChartBorder.GetRight(); var top=this.Frame.ChartBorder.GetTopEx(); var bottom=this.Frame.ChartBorder.GetBottomEx(); var pixelTatio = GetDevicePixelRatio(); - + var labInfo=this.LabelInfo; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.TopOffset)) top-=labInfo.TopOffset; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.BottomOffset)) bottom+=labInfo.BottomOffset; @@ -62839,12 +63057,21 @@ function ChartDrawHLine() this.Canvas.font=this.Font; var textWidth=this.Canvas.measureText(strValue).width; var lineHeight=this.GetFontHeight(); - var rtBG={ Left:right+this.RightSpaceWidth, Top:y- lineHeight/2, Width:textWidth+4, Height:lineHeight }; - //rtBG.Right=rtBG.Left+rtBG.Width; - rtBG.Bottom=rtBG.Top+rtBG.Height; + var rtBG={ Left:right+this.RightSpaceWidth, YCenter:y, Width:textWidth, Height:lineHeight }; + rtBG.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); rtBG.Width+=(this.TextMargin.Left+this.TextMargin.Right); rtBG.Right=rtBG.Left+rtBG.Width; - var xText=rtBG.Left+this.TextMargin.Left+2; + rtBG.Top=rtBG.YCenter-rtBG.Height/2; + rtBG.Bottom=rtBG.Top+rtBG.Height; + + if (option && IFrameSplitOperator.IsNumber(option.Top)) + { + rtBG.Top=option.Top; + rtBG.Bottom=rtBG.Top+rtBG.Height; + } + + var xText=rtBG.Left+this.TextMargin.Left; + var yText=rtBG.Top+this.TextMargin.Top+this.TextMargin.YOffset; if (this.ButtonPosition==1) { @@ -62857,8 +63084,8 @@ function ChartDrawHLine() this.Canvas.fillStyle=this.ValueTextColor this.Canvas.textAlign="left"; - this.Canvas.textBaseline="middle"; - this.Canvas.fillText(strValue,xText,y); + this.Canvas.textBaseline="top"; + this.Canvas.fillText(strValue,xText,yText); rtDraw.Left=rtBG.Left; rtDraw.Top=rtBG.Top; @@ -62868,6 +63095,24 @@ function ChartDrawHLine() this.DrawButton(rtBG.Top, rtBG.Right, lineHeight, rtDraw); } + //计算右侧价格标签大小 + this.CalculateValueText=function(y) + { + var yValue=this.Frame.GetYData(y,false); + var strValue=yValue.toFixed(this.Precision); + if (this.LableInfo &&this.LableInfo.PriceSuffixText) strValue+=this.LableInfo.PriceSuffixText; + + this.Canvas.font=this.Font; + var textWidth=this.Canvas.measureText(strValue).width; + var lineHeight=this.GetFontHeight(); + + var size={ Width:textWidth, Height:lineHeight }; + size.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); + size.Width+=(this.TextMargin.Left+this.TextMargin.Right); + + return size; + } + this.DrawPriceText=function(text, ptStart, ptEnd, position) { if (position!=1 && position!=0) return; @@ -108944,6 +109189,12 @@ function JSDraw(errorHandler,symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + this.KLINETYPE=function(type) { return type; @@ -115815,6 +116066,7 @@ function JSExecute(ast,option) var isFirstDraw=null; let xOffset=null, yOffset=null; var klineType=null; + var lineDash=null; for(let j=0; j0) line.LineWidth=width; } - if (varItem.IsDotLine) line.IsDotLine=true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine=true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow==false) line.IsShow=false; let titleIndex=windowIndex+1; @@ -142951,7 +143222,7 @@ function HQChartScriptWorker() -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13759"; function PrintHQChartVersion() { diff --git a/webhqchart.demo/jscommon/umychart.complier.js b/webhqchart.demo/jscommon/umychart.complier.js index f28478d9f..eb58d8275 100644 --- a/webhqchart.demo/jscommon/umychart.complier.js +++ b/webhqchart.demo/jscommon/umychart.complier.js @@ -10528,6 +10528,12 @@ function JSDraw(errorHandler,symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + this.KLINETYPE=function(type) { return type; @@ -17399,6 +17405,7 @@ function JSExecute(ast,option) var isFirstDraw=null; let xOffset=null, yOffset=null; var klineType=null; + var lineDash=null; for(let j=0; j0) line.LineWidth=width; } - if (varItem.IsDotLine) line.IsDotLine=true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine=true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow==false) line.IsShow=false; let titleIndex=windowIndex+1; diff --git a/webhqchart.demo/jscommon/umychart.js b/webhqchart.demo/jscommon/umychart.js index d4009ab11..eca611e9e 100644 --- a/webhqchart.demo/jscommon/umychart.js +++ b/webhqchart.demo/jscommon/umychart.js @@ -30665,6 +30665,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType=0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine=false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.BreakPoint; //断开的点索引 Set(); @@ -30710,7 +30711,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var drawCount=0; for(var i=this.Data.DataOffset,j=0;i0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -30874,7 +30875,7 @@ function ChartLine() this.ClipClient(bHScreen); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -36046,16 +36047,38 @@ function ChartClipColorStick() this.UpColor=g_JSChartResource.UpBarColor; this.DownColor=g_JSChartResource.DownBarColor; this.LineWidth=1; + this.Style=0; //1=同方向 0=上下两个方向 + //差值线 this.DownDiffColor=g_JSChartResource.DownBarColor; this.UpDiffColor=g_JSChartResource.UpBarColor; + //文字 + this.TextLabelConfig= + { + Font:`${12*GetDevicePixelRatio()}px 微软雅黑`, + TextMargin:{ Left:2, Right:2, Bottom:2, Top:2 }, + TextColor:"rgb(230,230,230)", + UpColor:"rgb(137,16,19)", + DownColor:"rgb(44,104,57)", + UnchangeColor:"rgb(111,112,115)", + BorderColor:"rgb(0,0,0)", + + //缓存 + LabelWidth:0, + TextHeight:0, + MaxTextWidth:0, + } + this.BaseLineColor; //基准线 this.BaseValue=0; this.Super_GetMaxMin=this.GetMaxMin; //父类的方法 this.ValueRange; //{ Max:, Min: } //固定最大最小值 + this.IsShowText=false; + + this.SetOption=function(option) { if (!option) return; @@ -36066,11 +36089,18 @@ function ChartClipColorStick() if (option.UpDiffColor) this.UpDiffColor=option.UpDiffColor; if (option.BaseLineColor) this.BaseLineColor=option.BaseLineColor; if (IFrameSplitOperator.IsNumber(option.BaseValue)) this.BaseValue=option.BaseValue; + if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style; if (option.ValueRange) this.ValueRange=option.ValueRange; + } this.Draw=function() { + this.IsShowText=false; + this.TextLabelConfig.LabelWidth=0; + this.TextLabelConfig.TextHeight=0; + this.TextLabelConfig.MaxTextWidth=0; + if (!this.IsShow || this.ChartFrame.IsMinSize || !this.IsVisible) return; if (this.IsShowIndexTitleOnly()) return; if (this.IsHideScriptIndex()) return; @@ -36081,23 +36111,44 @@ function ChartClipColorStick() return; } - this.Canvas.save(); var dataWidth=this.ChartFrame.DataWidth; + var distanceWidth=this.ChartFrame.DistanceWidth; + var xPointCount=this.ChartFrame.XPointCount; + var bHScreen=this.ChartFrame.IsHScreen===true; + var lineWidth=this.LineWidth*GetDevicePixelRatio(); if (this.LineWidth==50) lineWidth=dataWidth; else if (lineWidth>dataWidth) lineWidth=dataWidth; - + + if (!bHScreen) + { + var itemWidth=dataWidth+distanceWidth; + var bMinute=this.IsMinuteFrame(); + if (bMinute) + { + var border=this.ChartBorder.GetBorder(); + itemWidth=(border.Right-border.Left)/(xPointCount-1); + } + + this.Canvas.font=this.TextLabelConfig.Font; + this.TextLabelConfig.MaxTextWidth=this.Canvas.measureText("-888").width; + this.TextLabelConfig.LabelWidth=this.TextLabelConfig.MaxTextWidth+this.TextLabelConfig.TextMargin.Left+this.TextLabelConfig.TextMargin.Right; + this.IsShowText=itemWidth>this.TextLabelConfig.LabelWidth; + this.TextLabelConfig.TextHeight=this.Canvas.measureText("擎").width; + } + + this.Canvas.save(); if (IFrameSplitOperator.IsNumber(this.BaseValue) && this.BaseValue!=0) { this.DrawBaseLine(); - if (this.BaseValue>0) this.DrawBars(lineWidth, true); - else this.DrawBars(lineWidth, false); + if (this.BaseValue>0) this.DrawBars(lineWidth, true, true); + else this.DrawBars(lineWidth, false, true); } else { //上下分开画 - this.DrawBars(lineWidth, true); + this.DrawBars(lineWidth, true, true); this.DrawBars(lineWidth, false); } @@ -36105,15 +36156,15 @@ function ChartClipColorStick() this.Canvas.restore(); } - this.DrawBars=function(lineWidth, bUpBar) + this.DrawBars=function(lineWidth, bUpBar, bDrawLabel) { var isMinute=this.IsMinuteFrame(); var dataWidth=this.ChartFrame.DataWidth; var distanceWidth=this.ChartFrame.DistanceWidth; var xPointCount=this.ChartFrame.XPointCount; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; - if (isHSCreen) + if (bHScreen) { var border=this.ChartBorder.GetHScreenBorder(); var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin; @@ -36132,19 +36183,14 @@ function ChartClipColorStick() } var yBottom=this.ChartFrame.GetYFromData(this.BaseValue); - var aryBar=[], aryDiffBar=[]; - for(var i=this.Data.DataOffset,j=0;i0) preValue=this.Data.Data[start-1]; //上一个数值 + for(var i=start,j=0;i=0) continue; - } if (isMinute) { @@ -36160,6 +36206,21 @@ function ChartClipColorStick() if (x>chartright) break; + var textItem={ X:x, Value:value }; + if (IFrameSplitOperator.IsNumber(preValue)) textItem.DiffValue=value-preValue; + aryText.push(textItem); + + preValue=value; + + if (bUpBar) + { + if (value<0) continue; + } + else + { + if (value>=0) continue; + } + var bDiffBar=false; var diffValue=null; if (this.BaseValue>0) @@ -36167,7 +36228,10 @@ function ChartClipColorStick() if (valuethis.BaseValue) { bDiffBar=true; - diffValue=this.BaseValue+(value-this.BaseValue) + if (this.Style==1) + diffValue=this.BaseValue-(value-this.BaseValue); + else + diffValue=this.BaseValue+(value-this.BaseValue) } } if (!bDiffBar) { var y=this.ChartFrame.GetYFromData(value); - aryBar.push({X:x, Y:y}); + aryBar.push({X:x, Y:y }); } else { var y=this.ChartFrame.GetYFromData(diffValue); - aryDiffBar.push({X:x, Y:y}); + aryDiffBar.push({X:x, Y:y }); } } @@ -36196,6 +36263,7 @@ function ChartClipColorStick() else this.Canvas.strokeStyle=this.DownColor; this.DrawStick(aryBar,lineWidth,yBottom); + if (this.BaseValue>0) { @@ -36208,13 +36276,14 @@ function ChartClipColorStick() this.DrawStick(aryDiffBar,lineWidth,yBottom); } + if (this.IsShowText && bDrawLabel) this.DrawStickText(aryText); } this.DrawStick=function(aryData, lineWidth, yBottom) { if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; var drawCount=0; this.Canvas.beginPath(); for(var i=0; i0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + + var value=item.DiffValue; + var rtDraw={ Left:xLeft, Width:config.LabelWidth, Bottom:border.TopEx-1, Height:itemHeight }; + rtDraw.Right=rtDraw.Left+rtDraw.Width; + rtDraw.Top=rtDraw.Bottom-rtDraw.Height; + if (IFrameSplitOperator.IsNumber(value)) + { + var bgColor=config.UnchangeColor; + if (value>0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + } + } + + //数值标签 + this.DrawTextLabel=function(value, clrGB, clrBorder, clrText, rtDraw, textHeight, textWidth, textMargin) + { + if (clrGB) + { + this.Canvas.fillStyle=clrGB; + this.Canvas.fillRect(rtDraw.Left ,rtDraw.Top, (rtDraw.Width), (rtDraw.Height)); + } + + if (clrBorder) + { + this.Canvas.lineWidth=2; + this.Canvas.strokeStyle=clrBorder; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + else + { + this.Canvas.lineWidth=1; + this.Canvas.strokeStyle="rgb(0,0,0)"; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + + var aryText=[null, null]; //大于3位数的 2行输出 + var sign=""; //负数 + if (value<0) + { + value=Math.abs(value); + sign='-'; + } + + if (value>999) + { + var thousand=parseInt(value/1000); + var hundred=parseInt(value%1000); + + aryText[0]=`${sign}${thousand}`; + aryText[1]=`${hundred}`; + if (hundred<10) aryText[1]=`00${hundred}`; + else if (hundred<100) aryText[1]=`0${hundred}`; + } + else + { + aryText[1]=`${sign}${value.toFixed(0)}`; + } + + this.Canvas.textAlign="right"; + this.Canvas.textBaseline="top"; + var xRight=rtDraw.Right-(rtDraw.Right-rtDraw.Left-textWidth)/2; + + this.Canvas.fillStyle=clrText; + var yText=textMargin.Top+rtDraw.Top; + for(var i=0;i0) { - if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Min)) - range.Min-=maxDiffValue; + if (this.Style==1) + { + if (IFrameSplitOperator.IsNumber(maxDiffValue)) + { + var value=this.BaseValue+maxDiffValue; + if (IFrameSplitOperator.IsNumber(range.Max) || range.Maxvalue) range.Min=value; + } + } + else + { + if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Max)) + range.Max+=maxDiffValue; + } } return range; @@ -58358,7 +58551,7 @@ function ChartDrawHLine() this.ButtonBGColor='rgb(190,190,190)'; this.ButtonSpace=3; - this.TextMargin={ Left:0, Right:0 }; + this.TextMargin={ Left:0, Right:0, Top:0, Bottom:0, YOffset:4*GetDevicePixelRatio() }; this.AlwaysShowLab=false; //总是显示标签 @@ -58382,7 +58575,9 @@ function ChartDrawHLine() `${12*GetDevicePixelRatio()}px 微软雅黑`, `${12*GetDevicePixelRatio()}px 微软雅黑`, ], - }; + }; + + this.LableInfo; //{ Position:2=右侧外部 } //内部变量 this.ColseButtonSize=0; @@ -58390,7 +58585,7 @@ function ChartDrawHLine() this.ButtonBGWidth=0; this.VerticalButtonInfo={ Width:0, Height:0 }; //垂直按钮信息 - + this.IsPointIn=this.IsPointIn_XYValue_Line; this.SetOption=function(option) { @@ -58451,6 +58646,9 @@ function ChartDrawHLine() var item=option.TextMargin; if (IFrameSplitOperator.IsNumber(item.Left)) this.TextMargin.Left=item.Left; if (IFrameSplitOperator.IsNumber(item.Right)) this.TextMargin.Right=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) this.TextMargin.Top=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) this.TextMargin.Bottom=item.Bottom; + if (IFrameSplitOperator.IsNumber(item.YOffset)) this.TextMargin.YOffset=item.YOffset; } } } @@ -58467,10 +58665,6 @@ function ChartDrawHLine() return storageData; } - - this.IsPointIn=this.IsPointIn_XYValue_Line; - - /* this.GetXYCoordinate=function() { @@ -58527,7 +58721,7 @@ function ChartDrawHLine() this.ColseButtonSize=0; this.SettingButtonSize=0; this.ButtonBGWidth=0; - + this.LableInfo=null; this.VerticalButtonInfo.Width=0; this.VerticalButtonInfo.Height=0; @@ -58590,7 +58784,7 @@ function ChartDrawHLine() } this.LinePoint.push(line); - if (bVisibleRange) + if (bVisibleRange) //在可视范围内 { var yValue=this.Frame.GetYData(drawPoint[0].Y, false); var strPrice=yValue.toFixed(this.Precision); @@ -58604,15 +58798,11 @@ function ChartDrawHLine() this.DrawPriceText(strPrice, line.Start, line.End, 1); } } - - var labInfo; - if (this.GetLabelCallback) labInfo=this.GetLabelCallback(this); + + if (this.GetLabelCallback) this.LableInfo=this.GetLabelCallback(this); this.AryShowButton=this.GetShowButton(); //获取按钮 - - //框架内的描述信息 - if (labInfo && bVisibleRange) - this.DrawLab(labInfo, drawPoint[0].Y); + if (bVisibleRange) this.DrawInternalLabel(drawPoint[0].Y); //内部价格标签 //画中心点 if (bVisibleRange) @@ -58629,11 +58819,11 @@ function ChartDrawHLine() { var rtDraw={ }; this.CalculateButtonSize(); - this.DrawValueText(drawPoint[0].Y, rtDraw, labInfo); - if (labInfo) this.DrawRightLab(labInfo, rtDraw); - if (labInfo && bVisibleRange) this.DrawCustomHLine(labInfo, drawPoint[0].Y); + this.DrawRightLabel(drawPoint[0].Y); + if (bVisibleRange) this.DrawCustomHLine(drawPoint[0].Y); } + //鼠标是否在按钮上 if (moveonPoint && mouseStatus) { @@ -58681,113 +58871,141 @@ function ChartDrawHLine() ++lineCount; } - var size={ Width:maxWidth, Height: lineCount*(lineHeight+lineSpace)+lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + var size={ Width:maxWidth, Height:lineCount*lineHeight+(lineCount-1)*lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + if (labInfo.LabelMargin) + { + var item=labInfo.LabelMargin; + if (IFrameSplitOperator.IsNumber(item.Left)) size.Width+=item.Left; + if (IFrameSplitOperator.IsNumber(item.Right)) size.Width+=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) size.Height+=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) size.Height+=item.Bottom; + } return size; } - this.DrawLab=function(labInfo, y) + //绘制窗口内部标签 + this.DrawInternalLabel=function(y) { - if (!labInfo) return; - if (!IFrameSplitOperator.IsNonEmptyArray(labInfo.AryText)) return; - if (labInfo.Position===2) return; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText)) return; + if (this.LableInfo.Position==2) return; - var left=this.Frame.ChartBorder.GetLeft(); - var right=this.Frame.ChartBorder.GetRight(); - var labSize=this.CalculateLabSize(labInfo); + var border=this.Frame.GetBorder(); + var left=border.Left; + var right=border.Right; + var labSize=this.CalculateLabSize(this.LableInfo); var drawLeft=right-labSize.Width; + var drawRight=drawLeft+labSize.Width; var drawTop=y-labSize.Height-1; + if (drawTop<=border.TopEx) drawTop=y+1; - //背景色 - if (labInfo.BGColor) - { - this.Canvas.fillStyle=labInfo.BGColor; - var rtTop=y-labSize.Height-4; - this.Canvas.fillRect(ToFixedRect(drawLeft),ToFixedRect(rtTop),ToFixedRect(right+drawLeft),ToFixedRect(y-rtTop)); - } - - var yText=drawTop; - for(var i=0;i0) yText+=lineSpace; + var item=labelInfo.AryText[i]; if (item.Name) { this.Canvas.textAlign="left"; this.Canvas.fillStyle=item.NameColor; - this.Canvas.fillText(item.Name,drawLeft+1,yText+1); + this.Canvas.fillText(item.Name,xText,yText); } if (item.Text) { this.Canvas.textAlign="right"; this.Canvas.fillStyle=item.TextColor; - this.Canvas.fillText(item.Text,drawRight-1,yText+1); + this.Canvas.fillText(item.Text,yRightText,yText); } - yText+=labSize.LineHeight+lineSpace; + yText+=labelSize.LineHeight; + } + } + + this.DrawRightLabel=function(y) + { + var rtDraw={ }; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText) || this.LableInfo.Position!=2) + { + this.DrawValueText(y, rtDraw); + return; + } + + var priceSize=this.CalculateValueText(y); + var labSize=this.CalculateLabSize(this.LableInfo); + var border=this.Frame.GetBorder(); + var yTop=y-priceSize.Height/2; + var totalHeight=priceSize.Height+labSize.Height; + var yBottom=yTop+totalHeight; + var option={ }; + if (yBottom>border.Bottom) //超过窗口底部, 标签位置不动 + { + yBottom=border.Bottom; + yTop=yBottom-totalHeight; + option.Top=yTop; } - this.DrawVerticalButton(rtLab); + this.DrawValueText(y, rtDraw, option); + + var drawLeft=rtDraw.Right-labSize.Width; + if (drawLeftyFixed) yMin=yFixed; } - if (yMax!=yMin && labInfo.VLine) + if (yMax!=yMin && this.LableInfo.VLine) { - var item=labInfo.VLine; + var item=this.LableInfo.VLine; var x=left+20*pixelRatio; if (IFrameSplitOperator.IsNumber(item.XOffset)) x=left+item.XOffset*pixelRatio; x=ToFixedPoint(x); @@ -58828,14 +59046,14 @@ function ChartDrawHLine() } } - this.DrawValueText=function(y, rtDraw, labInfo) + this.DrawValueText=function(y, rtDraw, option) { var left=this.Frame.ChartBorder.GetLeft(); var right=this.Frame.ChartBorder.GetRight(); var top=this.Frame.ChartBorder.GetTopEx(); var bottom=this.Frame.ChartBorder.GetBottomEx(); var pixelTatio = GetDevicePixelRatio(); - + var labInfo=this.LabelInfo; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.TopOffset)) top-=labInfo.TopOffset; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.BottomOffset)) bottom+=labInfo.BottomOffset; @@ -58870,12 +59088,21 @@ function ChartDrawHLine() this.Canvas.font=this.Font; var textWidth=this.Canvas.measureText(strValue).width; var lineHeight=this.GetFontHeight(); - var rtBG={ Left:right+this.RightSpaceWidth, Top:y- lineHeight/2, Width:textWidth+4, Height:lineHeight }; - //rtBG.Right=rtBG.Left+rtBG.Width; - rtBG.Bottom=rtBG.Top+rtBG.Height; + var rtBG={ Left:right+this.RightSpaceWidth, YCenter:y, Width:textWidth, Height:lineHeight }; + rtBG.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); rtBG.Width+=(this.TextMargin.Left+this.TextMargin.Right); rtBG.Right=rtBG.Left+rtBG.Width; - var xText=rtBG.Left+this.TextMargin.Left+2; + rtBG.Top=rtBG.YCenter-rtBG.Height/2; + rtBG.Bottom=rtBG.Top+rtBG.Height; + + if (option && IFrameSplitOperator.IsNumber(option.Top)) + { + rtBG.Top=option.Top; + rtBG.Bottom=rtBG.Top+rtBG.Height; + } + + var xText=rtBG.Left+this.TextMargin.Left; + var yText=rtBG.Top+this.TextMargin.Top+this.TextMargin.YOffset; if (this.ButtonPosition==1) { @@ -58888,8 +59115,8 @@ function ChartDrawHLine() this.Canvas.fillStyle=this.ValueTextColor this.Canvas.textAlign="left"; - this.Canvas.textBaseline="middle"; - this.Canvas.fillText(strValue,xText,y); + this.Canvas.textBaseline="top"; + this.Canvas.fillText(strValue,xText,yText); rtDraw.Left=rtBG.Left; rtDraw.Top=rtBG.Top; @@ -58899,6 +59126,24 @@ function ChartDrawHLine() this.DrawButton(rtBG.Top, rtBG.Right, lineHeight, rtDraw); } + //计算右侧价格标签大小 + this.CalculateValueText=function(y) + { + var yValue=this.Frame.GetYData(y,false); + var strValue=yValue.toFixed(this.Precision); + if (this.LableInfo &&this.LableInfo.PriceSuffixText) strValue+=this.LableInfo.PriceSuffixText; + + this.Canvas.font=this.Font; + var textWidth=this.Canvas.measureText(strValue).width; + var lineHeight=this.GetFontHeight(); + + var size={ Width:textWidth, Height:lineHeight }; + size.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); + size.Width+=(this.TextMargin.Left+this.TextMargin.Right); + + return size; + } + this.DrawPriceText=function(text, ptStart, ptEnd, position) { if (position!=1 && position!=0) return; diff --git a/webhqchart.demo/jscommon/umychart.version.js b/webhqchart.demo/jscommon/umychart.version.js index d295089ad..549b0c8a6 100644 --- a/webhqchart.demo/jscommon/umychart.version.js +++ b/webhqchart.demo/jscommon/umychart.version.js @@ -5,7 +5,7 @@ -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13759"; function PrintHQChartVersion() { diff --git a/webhqchart/umychart.complier.js b/webhqchart/umychart.complier.js index f28478d9f..eb58d8275 100644 --- a/webhqchart/umychart.complier.js +++ b/webhqchart/umychart.complier.js @@ -10528,6 +10528,12 @@ function JSDraw(errorHandler,symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + this.KLINETYPE=function(type) { return type; @@ -17399,6 +17405,7 @@ function JSExecute(ast,option) var isFirstDraw=null; let xOffset=null, yOffset=null; var klineType=null; + var lineDash=null; for(let j=0; j0) line.LineWidth=width; } - if (varItem.IsDotLine) line.IsDotLine=true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine=true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow==false) line.IsShow=false; let titleIndex=windowIndex+1; diff --git a/webhqchart/umychart.js b/webhqchart/umychart.js index d4009ab11..eca611e9e 100644 --- a/webhqchart/umychart.js +++ b/webhqchart/umychart.js @@ -30665,6 +30665,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType=0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine=false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.BreakPoint; //断开的点索引 Set(); @@ -30710,7 +30711,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var drawCount=0; for(var i=this.Data.DataOffset,j=0;i0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -30874,7 +30875,7 @@ function ChartLine() this.ClipClient(bHScreen); if (this.LineWidth>0) this.Canvas.lineWidth=this.LineWidth * GetDevicePixelRatio(); this.Canvas.strokeStyle=this.Color; - if (this.IsDotLine) this.Canvas.setLineDash(g_JSChartResource.DOTLINE.LineDash); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint=true; var ptFirst=null;; //第1个点 @@ -36046,16 +36047,38 @@ function ChartClipColorStick() this.UpColor=g_JSChartResource.UpBarColor; this.DownColor=g_JSChartResource.DownBarColor; this.LineWidth=1; + this.Style=0; //1=同方向 0=上下两个方向 + //差值线 this.DownDiffColor=g_JSChartResource.DownBarColor; this.UpDiffColor=g_JSChartResource.UpBarColor; + //文字 + this.TextLabelConfig= + { + Font:`${12*GetDevicePixelRatio()}px 微软雅黑`, + TextMargin:{ Left:2, Right:2, Bottom:2, Top:2 }, + TextColor:"rgb(230,230,230)", + UpColor:"rgb(137,16,19)", + DownColor:"rgb(44,104,57)", + UnchangeColor:"rgb(111,112,115)", + BorderColor:"rgb(0,0,0)", + + //缓存 + LabelWidth:0, + TextHeight:0, + MaxTextWidth:0, + } + this.BaseLineColor; //基准线 this.BaseValue=0; this.Super_GetMaxMin=this.GetMaxMin; //父类的方法 this.ValueRange; //{ Max:, Min: } //固定最大最小值 + this.IsShowText=false; + + this.SetOption=function(option) { if (!option) return; @@ -36066,11 +36089,18 @@ function ChartClipColorStick() if (option.UpDiffColor) this.UpDiffColor=option.UpDiffColor; if (option.BaseLineColor) this.BaseLineColor=option.BaseLineColor; if (IFrameSplitOperator.IsNumber(option.BaseValue)) this.BaseValue=option.BaseValue; + if (IFrameSplitOperator.IsNumber(option.Style)) this.Style=option.Style; if (option.ValueRange) this.ValueRange=option.ValueRange; + } this.Draw=function() { + this.IsShowText=false; + this.TextLabelConfig.LabelWidth=0; + this.TextLabelConfig.TextHeight=0; + this.TextLabelConfig.MaxTextWidth=0; + if (!this.IsShow || this.ChartFrame.IsMinSize || !this.IsVisible) return; if (this.IsShowIndexTitleOnly()) return; if (this.IsHideScriptIndex()) return; @@ -36081,23 +36111,44 @@ function ChartClipColorStick() return; } - this.Canvas.save(); var dataWidth=this.ChartFrame.DataWidth; + var distanceWidth=this.ChartFrame.DistanceWidth; + var xPointCount=this.ChartFrame.XPointCount; + var bHScreen=this.ChartFrame.IsHScreen===true; + var lineWidth=this.LineWidth*GetDevicePixelRatio(); if (this.LineWidth==50) lineWidth=dataWidth; else if (lineWidth>dataWidth) lineWidth=dataWidth; - + + if (!bHScreen) + { + var itemWidth=dataWidth+distanceWidth; + var bMinute=this.IsMinuteFrame(); + if (bMinute) + { + var border=this.ChartBorder.GetBorder(); + itemWidth=(border.Right-border.Left)/(xPointCount-1); + } + + this.Canvas.font=this.TextLabelConfig.Font; + this.TextLabelConfig.MaxTextWidth=this.Canvas.measureText("-888").width; + this.TextLabelConfig.LabelWidth=this.TextLabelConfig.MaxTextWidth+this.TextLabelConfig.TextMargin.Left+this.TextLabelConfig.TextMargin.Right; + this.IsShowText=itemWidth>this.TextLabelConfig.LabelWidth; + this.TextLabelConfig.TextHeight=this.Canvas.measureText("擎").width; + } + + this.Canvas.save(); if (IFrameSplitOperator.IsNumber(this.BaseValue) && this.BaseValue!=0) { this.DrawBaseLine(); - if (this.BaseValue>0) this.DrawBars(lineWidth, true); - else this.DrawBars(lineWidth, false); + if (this.BaseValue>0) this.DrawBars(lineWidth, true, true); + else this.DrawBars(lineWidth, false, true); } else { //上下分开画 - this.DrawBars(lineWidth, true); + this.DrawBars(lineWidth, true, true); this.DrawBars(lineWidth, false); } @@ -36105,15 +36156,15 @@ function ChartClipColorStick() this.Canvas.restore(); } - this.DrawBars=function(lineWidth, bUpBar) + this.DrawBars=function(lineWidth, bUpBar, bDrawLabel) { var isMinute=this.IsMinuteFrame(); var dataWidth=this.ChartFrame.DataWidth; var distanceWidth=this.ChartFrame.DistanceWidth; var xPointCount=this.ChartFrame.XPointCount; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; - if (isHSCreen) + if (bHScreen) { var border=this.ChartBorder.GetHScreenBorder(); var xOffset=border.TopEx+distanceWidth/2.0+g_JSChartResource.FrameLeftMargin; @@ -36132,19 +36183,14 @@ function ChartClipColorStick() } var yBottom=this.ChartFrame.GetYFromData(this.BaseValue); - var aryBar=[], aryDiffBar=[]; - for(var i=this.Data.DataOffset,j=0;i0) preValue=this.Data.Data[start-1]; //上一个数值 + for(var i=start,j=0;i=0) continue; - } if (isMinute) { @@ -36160,6 +36206,21 @@ function ChartClipColorStick() if (x>chartright) break; + var textItem={ X:x, Value:value }; + if (IFrameSplitOperator.IsNumber(preValue)) textItem.DiffValue=value-preValue; + aryText.push(textItem); + + preValue=value; + + if (bUpBar) + { + if (value<0) continue; + } + else + { + if (value>=0) continue; + } + var bDiffBar=false; var diffValue=null; if (this.BaseValue>0) @@ -36167,7 +36228,10 @@ function ChartClipColorStick() if (valuethis.BaseValue) { bDiffBar=true; - diffValue=this.BaseValue+(value-this.BaseValue) + if (this.Style==1) + diffValue=this.BaseValue-(value-this.BaseValue); + else + diffValue=this.BaseValue+(value-this.BaseValue) } } if (!bDiffBar) { var y=this.ChartFrame.GetYFromData(value); - aryBar.push({X:x, Y:y}); + aryBar.push({X:x, Y:y }); } else { var y=this.ChartFrame.GetYFromData(diffValue); - aryDiffBar.push({X:x, Y:y}); + aryDiffBar.push({X:x, Y:y }); } } @@ -36196,6 +36263,7 @@ function ChartClipColorStick() else this.Canvas.strokeStyle=this.DownColor; this.DrawStick(aryBar,lineWidth,yBottom); + if (this.BaseValue>0) { @@ -36208,13 +36276,14 @@ function ChartClipColorStick() this.DrawStick(aryDiffBar,lineWidth,yBottom); } + if (this.IsShowText && bDrawLabel) this.DrawStickText(aryText); } this.DrawStick=function(aryData, lineWidth, yBottom) { if (!IFrameSplitOperator.IsNonEmptyArray(aryData)) return; - var isHSCreen=this.ChartFrame.IsHScreen===true; + var bHScreen=this.ChartFrame.IsHScreen===true; var drawCount=0; this.Canvas.beginPath(); for(var i=0; i0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + + var value=item.DiffValue; + var rtDraw={ Left:xLeft, Width:config.LabelWidth, Bottom:border.TopEx-1, Height:itemHeight }; + rtDraw.Right=rtDraw.Left+rtDraw.Width; + rtDraw.Top=rtDraw.Bottom-rtDraw.Height; + if (IFrameSplitOperator.IsNumber(value)) + { + var bgColor=config.UnchangeColor; + if (value>0) bgColor=config.UpColor; + else if (value<0) bgColor=config.DownColor; + this.DrawTextLabel(value, bgColor, config.BorderColor, config.TextColor, rtDraw, config.TextHeight, config.MaxTextWidth, config.TextMargin); + } + } + } + + //数值标签 + this.DrawTextLabel=function(value, clrGB, clrBorder, clrText, rtDraw, textHeight, textWidth, textMargin) + { + if (clrGB) + { + this.Canvas.fillStyle=clrGB; + this.Canvas.fillRect(rtDraw.Left ,rtDraw.Top, (rtDraw.Width), (rtDraw.Height)); + } + + if (clrBorder) + { + this.Canvas.lineWidth=2; + this.Canvas.strokeStyle=clrBorder; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + else + { + this.Canvas.lineWidth=1; + this.Canvas.strokeStyle="rgb(0,0,0)"; + this.Canvas.strokeRect(rtDraw.Left, rtDraw.Top, rtDraw.Width, rtDraw.Height); + } + + var aryText=[null, null]; //大于3位数的 2行输出 + var sign=""; //负数 + if (value<0) + { + value=Math.abs(value); + sign='-'; + } + + if (value>999) + { + var thousand=parseInt(value/1000); + var hundred=parseInt(value%1000); + + aryText[0]=`${sign}${thousand}`; + aryText[1]=`${hundred}`; + if (hundred<10) aryText[1]=`00${hundred}`; + else if (hundred<100) aryText[1]=`0${hundred}`; + } + else + { + aryText[1]=`${sign}${value.toFixed(0)}`; + } + + this.Canvas.textAlign="right"; + this.Canvas.textBaseline="top"; + var xRight=rtDraw.Right-(rtDraw.Right-rtDraw.Left-textWidth)/2; + + this.Canvas.fillStyle=clrText; + var yText=textMargin.Top+rtDraw.Top; + for(var i=0;i0) { - if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Min)) - range.Min-=maxDiffValue; + if (this.Style==1) + { + if (IFrameSplitOperator.IsNumber(maxDiffValue)) + { + var value=this.BaseValue+maxDiffValue; + if (IFrameSplitOperator.IsNumber(range.Max) || range.Maxvalue) range.Min=value; + } + } + else + { + if (IFrameSplitOperator.IsNumber(maxDiffValue) && IFrameSplitOperator.IsNumber(range.Max)) + range.Max+=maxDiffValue; + } } return range; @@ -58358,7 +58551,7 @@ function ChartDrawHLine() this.ButtonBGColor='rgb(190,190,190)'; this.ButtonSpace=3; - this.TextMargin={ Left:0, Right:0 }; + this.TextMargin={ Left:0, Right:0, Top:0, Bottom:0, YOffset:4*GetDevicePixelRatio() }; this.AlwaysShowLab=false; //总是显示标签 @@ -58382,7 +58575,9 @@ function ChartDrawHLine() `${12*GetDevicePixelRatio()}px 微软雅黑`, `${12*GetDevicePixelRatio()}px 微软雅黑`, ], - }; + }; + + this.LableInfo; //{ Position:2=右侧外部 } //内部变量 this.ColseButtonSize=0; @@ -58390,7 +58585,7 @@ function ChartDrawHLine() this.ButtonBGWidth=0; this.VerticalButtonInfo={ Width:0, Height:0 }; //垂直按钮信息 - + this.IsPointIn=this.IsPointIn_XYValue_Line; this.SetOption=function(option) { @@ -58451,6 +58646,9 @@ function ChartDrawHLine() var item=option.TextMargin; if (IFrameSplitOperator.IsNumber(item.Left)) this.TextMargin.Left=item.Left; if (IFrameSplitOperator.IsNumber(item.Right)) this.TextMargin.Right=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) this.TextMargin.Top=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) this.TextMargin.Bottom=item.Bottom; + if (IFrameSplitOperator.IsNumber(item.YOffset)) this.TextMargin.YOffset=item.YOffset; } } } @@ -58467,10 +58665,6 @@ function ChartDrawHLine() return storageData; } - - this.IsPointIn=this.IsPointIn_XYValue_Line; - - /* this.GetXYCoordinate=function() { @@ -58527,7 +58721,7 @@ function ChartDrawHLine() this.ColseButtonSize=0; this.SettingButtonSize=0; this.ButtonBGWidth=0; - + this.LableInfo=null; this.VerticalButtonInfo.Width=0; this.VerticalButtonInfo.Height=0; @@ -58590,7 +58784,7 @@ function ChartDrawHLine() } this.LinePoint.push(line); - if (bVisibleRange) + if (bVisibleRange) //在可视范围内 { var yValue=this.Frame.GetYData(drawPoint[0].Y, false); var strPrice=yValue.toFixed(this.Precision); @@ -58604,15 +58798,11 @@ function ChartDrawHLine() this.DrawPriceText(strPrice, line.Start, line.End, 1); } } - - var labInfo; - if (this.GetLabelCallback) labInfo=this.GetLabelCallback(this); + + if (this.GetLabelCallback) this.LableInfo=this.GetLabelCallback(this); this.AryShowButton=this.GetShowButton(); //获取按钮 - - //框架内的描述信息 - if (labInfo && bVisibleRange) - this.DrawLab(labInfo, drawPoint[0].Y); + if (bVisibleRange) this.DrawInternalLabel(drawPoint[0].Y); //内部价格标签 //画中心点 if (bVisibleRange) @@ -58629,11 +58819,11 @@ function ChartDrawHLine() { var rtDraw={ }; this.CalculateButtonSize(); - this.DrawValueText(drawPoint[0].Y, rtDraw, labInfo); - if (labInfo) this.DrawRightLab(labInfo, rtDraw); - if (labInfo && bVisibleRange) this.DrawCustomHLine(labInfo, drawPoint[0].Y); + this.DrawRightLabel(drawPoint[0].Y); + if (bVisibleRange) this.DrawCustomHLine(drawPoint[0].Y); } + //鼠标是否在按钮上 if (moveonPoint && mouseStatus) { @@ -58681,113 +58871,141 @@ function ChartDrawHLine() ++lineCount; } - var size={ Width:maxWidth, Height: lineCount*(lineHeight+lineSpace)+lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + var size={ Width:maxWidth, Height:lineCount*lineHeight+(lineCount-1)*lineSpace, NameWidth:maxNameWidth, TextWidth:maxTextWidth, LineHeight:lineHeight }; + if (labInfo.LabelMargin) + { + var item=labInfo.LabelMargin; + if (IFrameSplitOperator.IsNumber(item.Left)) size.Width+=item.Left; + if (IFrameSplitOperator.IsNumber(item.Right)) size.Width+=item.Right; + if (IFrameSplitOperator.IsNumber(item.Top)) size.Height+=item.Top; + if (IFrameSplitOperator.IsNumber(item.Bottom)) size.Height+=item.Bottom; + } return size; } - this.DrawLab=function(labInfo, y) + //绘制窗口内部标签 + this.DrawInternalLabel=function(y) { - if (!labInfo) return; - if (!IFrameSplitOperator.IsNonEmptyArray(labInfo.AryText)) return; - if (labInfo.Position===2) return; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText)) return; + if (this.LableInfo.Position==2) return; - var left=this.Frame.ChartBorder.GetLeft(); - var right=this.Frame.ChartBorder.GetRight(); - var labSize=this.CalculateLabSize(labInfo); + var border=this.Frame.GetBorder(); + var left=border.Left; + var right=border.Right; + var labSize=this.CalculateLabSize(this.LableInfo); var drawLeft=right-labSize.Width; + var drawRight=drawLeft+labSize.Width; var drawTop=y-labSize.Height-1; + if (drawTop<=border.TopEx) drawTop=y+1; - //背景色 - if (labInfo.BGColor) - { - this.Canvas.fillStyle=labInfo.BGColor; - var rtTop=y-labSize.Height-4; - this.Canvas.fillRect(ToFixedRect(drawLeft),ToFixedRect(rtTop),ToFixedRect(right+drawLeft),ToFixedRect(y-rtTop)); - } - - var yText=drawTop; - for(var i=0;i0) yText+=lineSpace; + var item=labelInfo.AryText[i]; if (item.Name) { this.Canvas.textAlign="left"; this.Canvas.fillStyle=item.NameColor; - this.Canvas.fillText(item.Name,drawLeft+1,yText+1); + this.Canvas.fillText(item.Name,xText,yText); } if (item.Text) { this.Canvas.textAlign="right"; this.Canvas.fillStyle=item.TextColor; - this.Canvas.fillText(item.Text,drawRight-1,yText+1); + this.Canvas.fillText(item.Text,yRightText,yText); } - yText+=labSize.LineHeight+lineSpace; + yText+=labelSize.LineHeight; + } + } + + this.DrawRightLabel=function(y) + { + var rtDraw={ }; + if (!this.LableInfo || !IFrameSplitOperator.IsNonEmptyArray(this.LableInfo.AryText) || this.LableInfo.Position!=2) + { + this.DrawValueText(y, rtDraw); + return; + } + + var priceSize=this.CalculateValueText(y); + var labSize=this.CalculateLabSize(this.LableInfo); + var border=this.Frame.GetBorder(); + var yTop=y-priceSize.Height/2; + var totalHeight=priceSize.Height+labSize.Height; + var yBottom=yTop+totalHeight; + var option={ }; + if (yBottom>border.Bottom) //超过窗口底部, 标签位置不动 + { + yBottom=border.Bottom; + yTop=yBottom-totalHeight; + option.Top=yTop; } - this.DrawVerticalButton(rtLab); + this.DrawValueText(y, rtDraw, option); + + var drawLeft=rtDraw.Right-labSize.Width; + if (drawLeftyFixed) yMin=yFixed; } - if (yMax!=yMin && labInfo.VLine) + if (yMax!=yMin && this.LableInfo.VLine) { - var item=labInfo.VLine; + var item=this.LableInfo.VLine; var x=left+20*pixelRatio; if (IFrameSplitOperator.IsNumber(item.XOffset)) x=left+item.XOffset*pixelRatio; x=ToFixedPoint(x); @@ -58828,14 +59046,14 @@ function ChartDrawHLine() } } - this.DrawValueText=function(y, rtDraw, labInfo) + this.DrawValueText=function(y, rtDraw, option) { var left=this.Frame.ChartBorder.GetLeft(); var right=this.Frame.ChartBorder.GetRight(); var top=this.Frame.ChartBorder.GetTopEx(); var bottom=this.Frame.ChartBorder.GetBottomEx(); var pixelTatio = GetDevicePixelRatio(); - + var labInfo=this.LabelInfo; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.TopOffset)) top-=labInfo.TopOffset; if (labInfo && IFrameSplitOperator.IsNumber(labInfo.BottomOffset)) bottom+=labInfo.BottomOffset; @@ -58870,12 +59088,21 @@ function ChartDrawHLine() this.Canvas.font=this.Font; var textWidth=this.Canvas.measureText(strValue).width; var lineHeight=this.GetFontHeight(); - var rtBG={ Left:right+this.RightSpaceWidth, Top:y- lineHeight/2, Width:textWidth+4, Height:lineHeight }; - //rtBG.Right=rtBG.Left+rtBG.Width; - rtBG.Bottom=rtBG.Top+rtBG.Height; + var rtBG={ Left:right+this.RightSpaceWidth, YCenter:y, Width:textWidth, Height:lineHeight }; + rtBG.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); rtBG.Width+=(this.TextMargin.Left+this.TextMargin.Right); rtBG.Right=rtBG.Left+rtBG.Width; - var xText=rtBG.Left+this.TextMargin.Left+2; + rtBG.Top=rtBG.YCenter-rtBG.Height/2; + rtBG.Bottom=rtBG.Top+rtBG.Height; + + if (option && IFrameSplitOperator.IsNumber(option.Top)) + { + rtBG.Top=option.Top; + rtBG.Bottom=rtBG.Top+rtBG.Height; + } + + var xText=rtBG.Left+this.TextMargin.Left; + var yText=rtBG.Top+this.TextMargin.Top+this.TextMargin.YOffset; if (this.ButtonPosition==1) { @@ -58888,8 +59115,8 @@ function ChartDrawHLine() this.Canvas.fillStyle=this.ValueTextColor this.Canvas.textAlign="left"; - this.Canvas.textBaseline="middle"; - this.Canvas.fillText(strValue,xText,y); + this.Canvas.textBaseline="top"; + this.Canvas.fillText(strValue,xText,yText); rtDraw.Left=rtBG.Left; rtDraw.Top=rtBG.Top; @@ -58899,6 +59126,24 @@ function ChartDrawHLine() this.DrawButton(rtBG.Top, rtBG.Right, lineHeight, rtDraw); } + //计算右侧价格标签大小 + this.CalculateValueText=function(y) + { + var yValue=this.Frame.GetYData(y,false); + var strValue=yValue.toFixed(this.Precision); + if (this.LableInfo &&this.LableInfo.PriceSuffixText) strValue+=this.LableInfo.PriceSuffixText; + + this.Canvas.font=this.Font; + var textWidth=this.Canvas.measureText(strValue).width; + var lineHeight=this.GetFontHeight(); + + var size={ Width:textWidth, Height:lineHeight }; + size.Height+=(this.TextMargin.Top+this.TextMargin.Bottom); + size.Width+=(this.TextMargin.Left+this.TextMargin.Right); + + return size; + } + this.DrawPriceText=function(text, ptStart, ptEnd, position) { if (position!=1 && position!=0) return; diff --git a/webhqchart/umychart.version.js b/webhqchart/umychart.version.js index d295089ad..549b0c8a6 100644 --- a/webhqchart/umychart.version.js +++ b/webhqchart/umychart.version.js @@ -5,7 +5,7 @@ -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13759"; function PrintHQChartVersion() { diff --git a/wechathqchart/umychart.chartpaint.wechat.js b/wechathqchart/umychart.chartpaint.wechat.js index b24c73725..4eeacb143 100644 --- a/wechathqchart/umychart.chartpaint.wechat.js +++ b/wechathqchart/umychart.chartpaint.wechat.js @@ -3615,6 +3615,7 @@ function ChartLine() this.LineWidth; //线段宽度 this.DrawType = 0; //画图方式 0=无效数平滑 1=无效数不画断开 this.IsDotLine = false; //虚线 + this.LineDash=g_JSChartResource.DOTLINE.LineDash; this.Draw = function () { @@ -3697,7 +3698,7 @@ function ChartLine() this.Canvas.save(); if (this.LineWidth > 0) this.Canvas.lineWidth = this.LineWidth; this.Canvas.strokeStyle = this.Color; - if (this.IsDotLine) this.Canvas.setLineDash([3, 5]); //画虚线 + if (this.IsDotLine) this.Canvas.setLineDash(this.LineDash); //画虚线 var bFirstPoint = true; var drawCount = 0; diff --git a/wechathqchart/umychart.complier.wechat.js b/wechathqchart/umychart.complier.wechat.js index 3c4c8ef8c..340658c11 100644 --- a/wechathqchart/umychart.complier.wechat.js +++ b/wechathqchart/umychart.complier.wechat.js @@ -8985,6 +8985,12 @@ function JSDraw(errorHandler, symbolData) return offset; } + this.LINEDASH=function(aryData) + { + if (IFrameSplitOperator.IsNonEmptyArray(aryData)) return aryData.slice(); + return []; + } + //该函数和DRAWTEXT连用 //{ Color:背景色, Border:边框颜色, Margin=[上,下,左, 右] } this.BACKGROUND=function(color, borderColor, left, right, top, bottom) @@ -13239,6 +13245,7 @@ function JSExecute(ast,option) var bgConfig=null; var vLineConfig=null; var xOffset=null, yOffset=null; + var lineDash=null; for(var j=0 ; j 0) line.LineWidth = width; } - if (varItem.IsDotLine) line.IsDotLine = true; //虚线 + if (varItem.IsDotLine) + { + line.IsDotLine = true; //虚线 + line.LineDash=g_JSChartResource.DOTLINE.LineDash.slice(); + } + + //虚线设置 + if (IFrameSplitOperator.IsNonEmptyArray(varItem.LineDash)) line.LineDash=varItem.LineDash; + if (varItem.IsShow == false) line.IsShow = false; let titleIndex = windowIndex + 1; diff --git a/wechathqchart/umychart.resource.wechat.js b/wechathqchart/umychart.resource.wechat.js index bb445aeae..3d7c2d43e 100644 --- a/wechathqchart/umychart.resource.wechat.js +++ b/wechathqchart/umychart.resource.wechat.js @@ -359,6 +359,11 @@ function JSChartResource() Radius:2 } + this.DOTLINE= + { + LineDash:[3,5] + } + //深度图 this.DepthChart= { @@ -714,6 +719,12 @@ function JSChartResource() if (this.IsNumber(item.Radius)) this.POINTDOT.Radius=item.Radius; } + if (style.DOTLINE) + { + var item=style.DOTLINE; + if (IFrameSplitOperator.IsNonEmptyArray(item.LineDash)) this.DOTLINE.LineDash=item.LineDash.slice(); + } + if (style.Report) { var item=style.Report; diff --git a/wechathqchart/umychart.style.wechat.js b/wechathqchart/umychart.style.wechat.js index 3da2c90e2..ca361c682 100644 --- a/wechathqchart/umychart.style.wechat.js +++ b/wechathqchart/umychart.style.wechat.js @@ -45,6 +45,18 @@ function GetBlackStyle() UnchagneTextColor: "rgb(101,104,112)", CloseLineColor: 'rgb(178,34,34)', + IndexTitle: + { + UpDownArrow: //数值涨跌箭头 + { + //UpColor:"rgb(238,21,21)", //上涨 + //DownColor:"rgb(25,158,0)", //下跌 + UnchangeColor:"rgb(190, 190 ,190)" //不变 + }, + + //NameArrow:{ Color:"rgb(190, 190 ,190)", Space:2, Symbol:'▼' }, + }, + Title: { TradeIndexColor:'rgb(105,105,105)', //交易指标颜色 @@ -311,7 +323,7 @@ function GetWhiteStyle() { UpColor:"rgb(238,21,21)", //上涨 DownColor:"rgb(25,158,0)", //下跌 - UnchangeColor:"rgb(190, 190 ,190)" //不变 + UnchangeColor:"rgb(0, 0 ,0)" //不变 }, NameArrow:{ Color:"rgb(190, 190 ,190)", Space:2, Symbol:'▼' }, diff --git a/wechathqchart/umychart.uniapp.canvas.helper.js b/wechathqchart/umychart.uniapp.canvas.helper.js index fe4719f97..2150a9e16 100644 --- a/wechathqchart/umychart.uniapp.canvas.helper.js +++ b/wechathqchart/umychart.uniapp.canvas.helper.js @@ -52,6 +52,10 @@ JSUniAppCanvasHelper.MeasureText=function(text, canvas) else if (/-/.test(item)) { width += 3.25; + } + else if (/_/.test(item)) + { + width += 4.5; } else if (/[\u4e00-\u9fa5]/.test(item)) { diff --git a/wechathqchart/umychart.version.wechat.js b/wechathqchart/umychart.version.wechat.js index 9d5f27d08..dd5902275 100644 --- a/wechathqchart/umychart.version.wechat.js +++ b/wechathqchart/umychart.version.wechat.js @@ -5,7 +5,7 @@ -var HQCHART_VERSION="1.1.13742"; +var HQCHART_VERSION="1.1.13752"; function PrintHQChartVersion() {