diff --git a/webapp/src/components/DAGSvgs/Board.tsx b/webapp/src/components/DAGSvgs/Board.tsx index 710d8fc..936271e 100644 --- a/webapp/src/components/DAGSvgs/Board.tsx +++ b/webapp/src/components/DAGSvgs/Board.tsx @@ -3,27 +3,36 @@ import { FC, useState } from 'react'; import { Point } from 'types/graphs'; 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(); - const { classes, theme } = useBoardStyles({}); - const [[offX, offY], setOffset] = useState([0, 0]) - // 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
diff --git a/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx b/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx index 58bfbf0..fb8f7d0 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.stories.tsx @@ -1,7 +1,7 @@ import React from "react"; import { ComponentMeta, ComponentStory } from '@storybook/react'; import { DAGBoard, DAGElement, DAGNodeElm } from "./DAGBoard"; -import { NODE_HEIGHT, NODE_WIDTH } from './constants'; +import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, DISTANCE_FACTOR } from './constants'; export default { @@ -9,12 +9,13 @@ export default { component: DAGBoard, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { + zoomLevel: 1, settings: { nodeHeight: NODE_HEIGHT, nodeWidth: NODE_WIDTH, - addHeight: 10, - addWidth: 10, - distanceFactor: 1.5, + addHeight: ADD_HEIGHT, + addWidth: ADD_WIDTH, + distanceFactor: DISTANCE_FACTOR, edgeChildColor: 'blue', edgeNextColor: 'white', }, @@ -38,9 +39,28 @@ const nodeFromPoint = ([x, y, add = true]: any): DAGNodeElm => ({ } }) -export const Basic: ComponentStory = args => -Basic.args = { - ...Basic.args, +export const Simple: ComponentStory = args => +Simple.args = { + ...Simple.args, + elements: [ + [0, 0, false], + [1, 0, false], + [2, 1, false], + ].map(nodeFromPoint).concat([ + { + type: 'edge', + key: 'e1', + p1: [0, 0], + p2: [1, 0], + direction: '1->2' + }, + ]) +} + + +export const Complex: ComponentStory = args => +Complex.args = { + ...Complex.args, elements: [ [0, 0, false], [1, 0, false], diff --git a/webapp/src/components/DAGSvgs/DAGBoard.tsx b/webapp/src/components/DAGSvgs/DAGBoard.tsx index afab49a..6ac1f0c 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.tsx @@ -25,18 +25,20 @@ export interface DAGEdgeElm { toChild?: boolean; } export type DAGElement = DAGEdgeElm | DAGNodeElm; -export interface DAGBoardSettings { +export interface DAGBoardSettings extends DAGBoardElmDims { + edgeChildColor: string; + edgeNextColor: string; +} +export interface DAGBoardElmDims { nodeHeight: number; nodeWidth: number; addHeight: number; addWidth: number; distanceFactor: number; - edgeChildColor: string; - edgeNextColor: string; } export interface Props { - elements: DAGElement[]; + elements: Generator; settings: DAGBoardSettings; } @@ -67,6 +69,7 @@ export function* mapDataToElements({ y * st.nodeHeight * st.distanceFactor + oy, ]) for (let elm of elements) { + console.log({ elm }) switch (elm.type) { case 'node': const nodeLoc = mapWithNode(elm.loc); @@ -117,14 +120,17 @@ export function* mapDataToElements({ } -export const DAGBoard: FC<{ - elements: DAGElement[]; - settings: DAGBoardSettings; -}> = props => { +export const DAGBoard: FC = props => { const it = new IteratorWrap(mapDataToElements(props)); const el = it.toArray(); const [[x0, y0], [x1, y1]] = it.returnValue as BBox; - return + return {el} } diff --git a/webapp/src/components/DAGSvgs/constants.ts b/webapp/src/components/DAGSvgs/constants.ts index f7485fe..aa0dd9e 100644 --- a/webapp/src/components/DAGSvgs/constants.ts +++ b/webapp/src/components/DAGSvgs/constants.ts @@ -3,3 +3,6 @@ export const NODE_WIDTH = 100 as const; export const NODE_HEIGHT = 40 as const; +export const ADD_HEIGHT = 10 as const; +export const ADD_WIDTH = 10 as const; +export const DISTANCE_FACTOR = 1.5 as const; diff --git a/webapp/src/components/DAGSvgs/styles.ts b/webapp/src/components/DAGSvgs/styles.ts index 18a4b14..cbb7eb5 100644 --- a/webapp/src/components/DAGSvgs/styles.ts +++ b/webapp/src/components/DAGSvgs/styles.ts @@ -4,7 +4,10 @@ import { createAppUseStyles } from "styles/theme"; import { Node } from "types/graphs"; -export const useBoardStyles = createAppUseStyles(theme => ({ +export const useBoardStyles = createAppUseStyles<{ + boardHeight: number, + boardWidth: number, +}>(theme => ({ root: { height: '99%', width: '99%', @@ -21,12 +24,12 @@ export const useBoardStyles = createAppUseStyles(theme => ({ height: '100%', overflow: 'scroll' }, - svg: { - minHeight: '800px', - minWidth: '800px', + svg: ({boardHeight, boardWidth}) => ({ + minHeight: `${boardHeight}px`, + minWidth: `${boardWidth}px`, padding: 0, margin: 0, - }, + }), circle: { fill: Color(theme.secondary).set('rgb.b', 125).hex(), },