All files groupSizing.js

97.14% Statements 34/35
35.71% Branches 5/14
100% Functions 2/2
97.14% Lines 34/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x   4x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
const DEFAULT_CHILD_WIDTH = 200;
const DEFAULT_CHILD_HEIGHT = 120;
 
function getNodeSize(node, axis) {
  const fallback = axis === 'width' ? DEFAULT_CHILD_WIDTH : DEFAULT_CHILD_HEIGHT;
  const measured = Number(node?.measured?.[axis]);
  if (Number.isFinite(measured) && measured > 0) return measured;
  const direct = Number(node?.[axis]);
  if (Number.isFinite(direct) && direct > 0) return direct;
  const styled = Number(node?.style?.[axis]);
  if (Number.isFinite(styled) && styled > 0) return styled;
  return fallback;
}
 
export function getGroupMinimumSize(memberNodes, {
  minWidth = 260,
  minHeight = 180,
  paddingX = 24,
  paddingY = 24,
} = {}) {
  let maxRight = 0;
  let maxBottom = 0;
 
  for (const node of memberNodes || []) {
    const x = Number(node?.position?.x) || 0;
    const y = Number(node?.position?.y) || 0;
    maxRight = Math.max(maxRight, x + getNodeSize(node, 'width'));
    maxBottom = Math.max(maxBottom, y + getNodeSize(node, 'height'));
  }
 
  return {
    width: Math.max(minWidth, Math.ceil(maxRight + paddingX)),
    height: Math.max(minHeight, Math.ceil(maxBottom + paddingY)),
  };
}