From dd74c400d4d6408637eea14681c7ca2b1e3a4098 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 21 Dec 2021 22:51:07 -0500 Subject: [PATCH] ensuring everything does not magically resize --- webapp/src/components/DAGSvgs/DAGBoard.tsx | 11 +++++++++-- webapp/src/utils/graph.ts | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/DAGSvgs/DAGBoard.tsx b/webapp/src/components/DAGSvgs/DAGBoard.tsx index 1d1667d..0868386 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, useRef } from "react"; import { SVGBoard } from "./Board"; import { AutomationNode } from '../../types/automations/index'; import { Point, EdgeDirection, BBox } from 'types/graphs'; @@ -8,6 +8,8 @@ import { AddButton } from "./AddButton"; import { IteratorWrap } from "utils/iter"; import { DAGCircle, AddProps } from "./DAGCircle"; import { getDescriptionFromAutomationNode } from "utils/formatting"; +import { minPoints } from "utils/graph"; +import { maxPoints } from '../../utils/graph'; export type DAGCircleElm = { @@ -182,9 +184,14 @@ export function* mapDataToElements({ export const DAGBoard: FC = props => { + const graphDims = useRef([[0, 0], [0, 0]]); const it = new IteratorWrap(mapDataToElements(props)); const el = it.toArray(); - const [[x0, y0], [x1, y1]] = it.returnValue as BBox; + const [p0, p1] = it.returnValue as BBox; + const [[x0, y0], [x1, y1]] = graphDims.current = [ + minPoints(p0, graphDims.current[0]), + maxPoints(p1, graphDims.current[1]) + ]; return [x + ox, y + oy]; -export const avgPoints = ( +export const applyPoints = ( [x1, y1]: Point, [x2, y2]: Point, -): Point => [(x1 + x2)/2, (y1 + y2)/2]; + fun: (a: number, b: number) => number, +): Point => [fun(x1, x2), fun(y1, y2)]; + +export const avgPoints = ( + p1: Point, + p2: Point, +): Point => applyPoints(p1, p2, (a,b) => (a+b)/2); + + +export const minPoints = ( + p1: Point, + p2: Point, +): Point => applyPoints(p1, p2, Math.min); + +export const maxPoints = ( + p1: Point, + p2: Point, +): Point => applyPoints(p1, p2, Math.max); export const makeOffsetMaintainer = (startPoint: Point) => { let offset: Point = [0, 0];