(
tooltipModel: Model<TooltipOption>,
positionExpr: TooltipOption['position'],
x: number, // Mouse x
y: number, // Mouse y
content: TooltipHTMLContent | TooltipRichContent,
params: TooltipCallbackDataParams | TooltipCallbackDataParams[],
el?: Element
)
| 903 | } |
| 904 | |
| 905 | _updatePosition( |
| 906 | tooltipModel: Model<TooltipOption>, |
| 907 | positionExpr: TooltipOption['position'], |
| 908 | x: number, // Mouse x |
| 909 | y: number, // Mouse y |
| 910 | content: TooltipHTMLContent | TooltipRichContent, |
| 911 | params: TooltipCallbackDataParams | TooltipCallbackDataParams[], |
| 912 | el?: Element |
| 913 | ) { |
| 914 | const viewWidth = this._api.getWidth(); |
| 915 | const viewHeight = this._api.getHeight(); |
| 916 | |
| 917 | positionExpr = positionExpr || tooltipModel.get('position'); |
| 918 | |
| 919 | const contentSize = content.getSize(); |
| 920 | let align = tooltipModel.get('align'); |
| 921 | let vAlign = tooltipModel.get('verticalAlign'); |
| 922 | const rect = el && el.getBoundingRect().clone(); |
| 923 | el && rect.applyTransform(el.transform); |
| 924 | |
| 925 | if (isFunction(positionExpr)) { |
| 926 | // Callback of position can be an array or a string specify the position |
| 927 | positionExpr = positionExpr([x, y], params, content.el, rect, { |
| 928 | viewSize: [viewWidth, viewHeight], |
| 929 | contentSize: contentSize.slice() as [number, number] |
| 930 | }); |
| 931 | } |
| 932 | |
| 933 | if (isArray(positionExpr)) { |
| 934 | x = parsePercent(positionExpr[0], viewWidth); |
| 935 | y = parsePercent(positionExpr[1], viewHeight); |
| 936 | } |
| 937 | else if (isObject(positionExpr)) { |
| 938 | const boxLayoutPosition = positionExpr as BoxLayoutOptionMixin; |
| 939 | boxLayoutPosition.width = contentSize[0]; |
| 940 | boxLayoutPosition.height = contentSize[1]; |
| 941 | const layoutRect = getLayoutRect( |
| 942 | boxLayoutPosition, { width: viewWidth, height: viewHeight } |
| 943 | ); |
| 944 | x = layoutRect.x; |
| 945 | y = layoutRect.y; |
| 946 | align = null; |
| 947 | // When positionExpr is left/top/right/bottom, |
| 948 | // align and verticalAlign will not work. |
| 949 | vAlign = null; |
| 950 | } |
| 951 | // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element |
| 952 | else if (isString(positionExpr) && el) { |
| 953 | const pos = calcTooltipPosition( |
| 954 | positionExpr, rect, contentSize, tooltipModel.get('borderWidth') |
| 955 | ); |
| 956 | x = pos[0]; |
| 957 | y = pos[1]; |
| 958 | } |
| 959 | else { |
| 960 | const pos = refixTooltipPosition( |
| 961 | x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20 |
| 962 | ); |
no test coverage detected