From 55239e6517b20d04169d290e2a7c77d6fea81ebe Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 1 Dec 2021 15:30:27 -0500 Subject: [PATCH] added branching icons --- webapp/src/components/DAGSvgs/DAGBoard.tsx | 27 +++++++------- .../SequenceNodes/index.stories.tsx | 3 +- webapp/src/components/SequenceNodes/index.tsx | 8 ----- .../src/components/SequenceNodes/positions.ts | 36 +++++++++++-------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/webapp/src/components/DAGSvgs/DAGBoard.tsx b/webapp/src/components/DAGSvgs/DAGBoard.tsx index 127afee..a08f7af 100644 --- a/webapp/src/components/DAGSvgs/DAGBoard.tsx +++ b/webapp/src/components/DAGSvgs/DAGBoard.tsx @@ -11,13 +11,11 @@ import { DAGCircle } from "./DAGCircle"; export interface DAGCircleElm { type: 'circle'; - key: string; loc: Point; onClick?: () => void; } export interface DAGNodeElm { type: 'node'; - key: string; loc: Point; node: AutomationNode; onRemove: () => void; @@ -25,11 +23,10 @@ export interface DAGNodeElm { } export interface DAGEdgeElm { type: 'edge'; - key: string; p1: Point; p2: Point; direction: EdgeDirection; - toChild?: boolean; + fromCircle?: boolean; onAdd?: () => void; } export type DAGElement = DAGEdgeElm | DAGNodeElm | DAGCircleElm; @@ -86,7 +83,7 @@ export function* mapDataToElements({ st.addHeight + st.addHeight / 2 ]) yield if (elm.onAdd) { yield +`} + key={`(${elm.loc})->+`} p1={offsetPoint(nodeLoc, [st.nodeWidth, st.nodeHeight / 2])} p2={offsetPoint(addLoc, [0, st.addHeight / 2])} direction="1->2" color={st.edgeNextColor} /> yield `} - p1={mapWithNode(elm.p1, [st.nodeWidth, st.nodeHeight / 2])} + key={`(${elm.p1})->(${elm.p2})`} + p1={p1} p2={p2} direction={elm.direction} - color={elm.toChild ? st.edgeChildColor : st.edgeNextColor} + color={st.edgeNextColor} /> if (elm.onAdd) { yield = (props) => { const theme = useTheme(); - - // return <> - // {Array.from(computeNodesEdges({ - // ...props, - // keyPrefix: "", - // edgeColor: theme.secondaryAccent, - // }))} - // return [x + ox, y + oy]; const makeOffsetMaintainer = (startPoint: Point) => { @@ -36,22 +36,33 @@ function* inner( nodeLoc: Point, innerStartLoc: Point, updater: Updater, - keyPrefix: string, sequence: AutomationSequenceNode[], + onEdit?: () => void, ): Generator { + const np = offsetPoint(innerStartLoc, [0.5, 0]); yield { type: 'edge', p1: nodeLoc, p2: innerStartLoc, direction: '1->2', - key: `${keyPrefix}-${nodeLoc}:${innerStartLoc}`, + } + yield { + type: 'circle', + loc: innerStartLoc, + onClick: onEdit + } + yield { + type: 'edge', + p1: innerStartLoc, + p2: np, + direction: '1->2', onAdd: sequence.length === 0 ? updater.addNode : undefined, + fromCircle: true, } for (let childNode of computeNodesEdgesPos( - innerStartLoc, + np, sequence, updater.onChange, - keyPrefix, )) { yield childNode } @@ -62,7 +73,6 @@ function* dealWithChoose( nodeLoc: Point, makeUpdater: (j: number | null) => Updater, offset: ReturnType, - keyPrefix: string, ) { offset.resetY() for (let j = 0; j < node.action_data.choose.length; j++) { @@ -71,8 +81,8 @@ function* dealWithChoose( nodeLoc, innerStartLoc , makeUpdater(j), - `${keyPrefix}.${j}`, - node.action_data.choose[j].sequence + node.action_data.choose[j].sequence, + () => {}, )) { yield elm if (elm.type === 'node') { @@ -80,12 +90,14 @@ function* dealWithChoose( } } } - const innerStartLoc = offsetPoint(nodeLoc, [1, node.action_data.choose.length + 1 + offset.y]); + const innerStartLoc = offsetPoint( + nodeLoc, + [1, node.action_data.choose.length + 1 + offset.y], + ); for (let elm of inner( nodeLoc, innerStartLoc, makeUpdater(null), - `${keyPrefix}-d`, node.action_data.default, )) { yield elm @@ -100,7 +112,6 @@ export function* computeNodesEdgesPos( startPoint: Point, sequence: AutomationSequenceNode[], onChange: (s: AutomationSequenceNode[]) => void, - keyPrefix: string = '$', ): Generator { const rootUpdater = makeUpdater(sequence, onChange); const offset = makeOffsetMaintainer(startPoint) @@ -111,7 +122,6 @@ export function* computeNodesEdgesPos( const nodeLoc = offsetPoint(startPoint, [i + offset.x, 0]); yield { type: 'node', - key: `${keyPrefix}${i}`, loc: nodeLoc, node, onRemove: () => rootUpdater.removeNode(i), @@ -120,7 +130,6 @@ export function* computeNodesEdgesPos( if (lastNodeLoc) { yield { type: 'edge', - key: `${keyPrefix}(${i-1}->${i})`, p1: lastNodeLoc, p2: nodeLoc, direction: '1->2', @@ -135,7 +144,6 @@ export function* computeNodesEdgesPos( nodeLoc, j => rootUpdater.makeChildUpdaterForChooseAction(i, j), offset, - `${keyPrefix}.${i}`, ) } }