position function

Last updated: 2026-03-05T10:53:28.862Z

Metrics

LOC: 22 Complexity: 7 Params: 4

Signature

position( el: HTMLElement, rect: DOMRect, pos: LabelEffect["position"] = "above", ): : void

Summary

Positions the label relative to the target element.

Source Code

function position(
  el: HTMLElement,
  rect: DOMRect,
  pos: LabelEffect["position"] = "above",
): void {
  const gap = 8;
  const elRect = el.getBoundingClientRect();

  if (pos === "above") {
    el.style.top = `${rect.top - elRect.height - gap}px`;
    el.style.left = `${rect.left + rect.width / 2 - elRect.width / 2}px`;
  } else if (pos === "below") {
    el.style.top = `${rect.bottom + gap}px`;
    el.style.left = `${rect.left + rect.width / 2 - elRect.width / 2}px`;
  } else if (pos === "left") {
    el.style.top = `${rect.top + rect.height / 2 - elRect.height / 2}px`;
    el.style.left = `${rect.left - elRect.width - gap}px`;
  } else {
    el.style.top = `${rect.top + rect.height / 2 - elRect.height / 2}px`;
    el.style.left = `${rect.right + gap}px`;
  }
}

No outgoing dependencies.

Impact (Incoming)

graph LR position["position"] applyLabelEffect["applyLabelEffect"] applyLabelEffect -->|calls| position style position fill:#dbeafe,stroke:#2563eb,stroke-width:2px click position "3d3f1333e7b896b2.html" click applyLabelEffect "cb3df1e3c180daee.html"
SourceType
applyLabelEffect calls