MCPcopy Create free account
hub / github.com/microsoft/SandDance / _positionBeak

Function _positionBeak

docs/app/js/sanddance-app.js:32056–32072  ·  view source on GitHub ↗
(beakWidth, elementPosition)

Source from the content-addressed store, hash-verified

32054 };
32055}
32056function _positionBeak(beakWidth, elementPosition) {
32057 var target = elementPosition.targetRectangle;
32058 /**
32059 * Note about beak positioning: The actual beak width only matters for getting the gap between the callout and
32060 * target, it does not impact the beak placement within the callout. For example example, if the beakWidth is 8,
32061 * then the actual beakWidth is sqrroot(8^2 + 8^2) = 11.31x11.31. So the callout will need to be an extra 3 pixels
32062 * away from its target. While the beak is being positioned in the callout it still acts as though it were 8x8.
32063 */ var _a2 = _getFlankingEdges(elementPosition.targetEdge), positiveEdge = _a2.positiveEdge, negativeEdge = _a2.negativeEdge;
32064 var beakTargetPoint = _getCenterValue(target, elementPosition.targetEdge);
32065 var elementBounds = new (0, _utilities.Rectangle)(beakWidth / 2, elementPosition.elementRectangle.width - beakWidth / 2, beakWidth / 2, elementPosition.elementRectangle.height - beakWidth / 2);
32066 var beakPosition = new (0, _utilities.Rectangle)(0, beakWidth, 0, beakWidth);
32067 beakPosition = _moveEdge(beakPosition, elementPosition.targetEdge * -1, -beakWidth / 2);
32068 beakPosition = _centerEdgeToPoint(beakPosition, elementPosition.targetEdge * -1, beakTargetPoint - _getRelativeRectEdgeValue(positiveEdge, elementPosition.elementRectangle));
32069 if (!_isEdgeInBounds(beakPosition, elementBounds, positiveEdge)) beakPosition = _alignEdges(beakPosition, elementBounds, positiveEdge);
32070 else if (!_isEdgeInBounds(beakPosition, elementBounds, negativeEdge)) beakPosition = _alignEdges(beakPosition, elementBounds, negativeEdge);
32071 return beakPosition;
32072}
32073function _getRectangleFromElement(element) {
32074 var clientRect = element.getBoundingClientRect();
32075 return new (0, _utilities.Rectangle)(clientRect.left, clientRect.right, clientRect.top, clientRect.bottom);

Callers 1

_positionCalloutFunction · 0.85

Calls 7

_getFlankingEdgesFunction · 0.85
_getCenterValueFunction · 0.85
_moveEdgeFunction · 0.85
_centerEdgeToPointFunction · 0.85
_isEdgeInBoundsFunction · 0.85
_alignEdgesFunction · 0.85

Tested by

no test coverage detected