ensuring everything does not magically resize
This commit is contained in:
1 parent
24f7c3c3af
commit
dd74c400d4
2 files changed
+28
-4
No files matched your search
@@ -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 & { zoomLevel: number }> = props => {
|
||||
const graphDims = useRef<BBox>([[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 <SVGBoard
|
||||
graphHeight={y1 - y0}
|
||||
minGraphWidth={Math.max(x1 - x0, props.settings.nodeWidth * 15)}
|
||||
|
||||
@@ -5,10 +5,27 @@ export const offsetPoint = (
|
||||
[ox, oy]: Point = [0, 0],
|
||||
): Point => [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];
|
||||
|
||||
Reference in new issue
Block a user