Files
Shortumation/webapp/src/components/DAGSvgs/Board.tsx
T
ari 1efb04fe68 added root styles
added auto editor
cleaned up styles for dagboard
2021-12-16 16:41:33 -05:00

54 lines
1.4 KiB
TypeScript

import "./Board.css";
import { FC } from 'react';
import useWindowSize from "utils/useWindowSize";
import { useBoardStyles } from "./styles";
import { NODE_HEIGHT, NODE_WIDTH } from './constants';
export const SVGBoard: FC<{
graphHeight?: number,
minGraphWidth?: number,
nodeHeight?: number,
nodeWidth?: number,
zoomLevel?: number,
}> = ({
children,
graphHeight = 300,
minGraphWidth = 300,
nodeHeight = NODE_HEIGHT,
nodeWidth = NODE_WIDTH,
zoomLevel = 1,
}) => {
// state
const { ratioWbh } = useWindowSize();
// alias
const graphWidth = Math.max(
Math.round(graphHeight * ratioWbh),
minGraphWidth
);
const { classes, theme } = useBoardStyles({
boardHeight: Math.max(nodeHeight, graphHeight) * zoomLevel,
boardWidth: Math.max(5 * nodeWidth, graphWidth) * zoomLevel,
});
// render
return <div className={classes.dag}>
<svg
className={classes.svg}
viewBox={[0, 0, graphWidth, graphHeight].join(" ")}
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
markerWidth="6" markerHeight="6"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
</marker>
</defs>
{children}
</svg>
</div>
}