MCPcopy
hub / github.com/apache/echarts / calcTooltipPosition

Function calcTooltipPosition

src/component/tooltip/TooltipView.ts:1168–1203  ·  view source on GitHub ↗
(
    position: TooltipOption['position'],
    rect: ZRRectLike,
    contentSize: number[],
    borderWidth: number
)

Source from the content-addressed store, hash-verified

1166}
1167
1168function calcTooltipPosition(
1169 position: TooltipOption['position'],
1170 rect: ZRRectLike,
1171 contentSize: number[],
1172 borderWidth: number
1173): [number, number] {
1174 const domWidth = contentSize[0];
1175 const domHeight = contentSize[1];
1176 const offset = Math.ceil(Math.SQRT2 * borderWidth) + 8;
1177 let x = 0;
1178 let y = 0;
1179 const rectWidth = rect.width;
1180 const rectHeight = rect.height;
1181 switch (position) {
1182 case 'inside':
1183 x = rect.x + rectWidth / 2 - domWidth / 2;
1184 y = rect.y + rectHeight / 2 - domHeight / 2;
1185 break;
1186 case 'top':
1187 x = rect.x + rectWidth / 2 - domWidth / 2;
1188 y = rect.y - domHeight - offset;
1189 break;
1190 case 'bottom':
1191 x = rect.x + rectWidth / 2 - domWidth / 2;
1192 y = rect.y + rectHeight + offset;
1193 break;
1194 case 'left':
1195 x = rect.x - domWidth - offset;
1196 y = rect.y + rectHeight / 2 - domHeight / 2;
1197 break;
1198 case 'right':
1199 x = rect.x + rectWidth + offset;
1200 y = rect.y + rectHeight / 2 - domHeight / 2;
1201 }
1202 return [x, y];
1203}
1204
1205function isCenterAlign(align: HorizontalAlign | VerticalAlign) {
1206 return align === 'center' || align === 'middle';

Callers 1

_updatePositionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…