All files / src/utils initGraphStyle.ts

100% Statements 15/15
62.5% Branches 5/8
100% Functions 3/3
100% Lines 13/13

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    1x 10x 10590x 10590x 10x 10x 10x 10x   10x         10x         10x 10x   10x              
import { ICanvasData } from "../components";
 
export const initGraphStyle = (data: ICanvasData): React.CSSProperties => {
  const { nodes } = data;
  const nodeXArr = nodes.map(node => node.x);
  const nodeYArr = nodes.map(node => node.y);
  const minX = Math.min(...nodeXArr);
  const minY = Math.min(...nodeYArr);
  const maxX = Math.max(...nodeXArr);
  const maxY = Math.max(...nodeYArr);
 
  const width = Math.max(
    maxX - minX + 800,
    document.documentElement.clientWidth,
    window.innerWidth || 0
  );
  const height = Math.max(
    maxY - minY + 600,
    document.documentElement.clientHeight,
    window.innerHeight || 0
  );
  const left = minX < 0 ? minX - 400 : -400;
  const top = minY < 0 ? minY - 300 : -300;
 
  return {
    width,
    height,
    left,
    top
  };
};