added branching icons

This commit is contained in:
ari committed 2021-12-01 15:30:27 -05:00
1 parent 146a48b7c3
commit 55239e6517
4 files changed
+39 -35

No files matched your search

+15 -12
View File
@@ -11,13 +11,11 @@ import { DAGCircle } from "./DAGCircle";
export interface DAGCircleElm { export interface DAGCircleElm {
type: 'circle'; type: 'circle';
key: string;
loc: Point; loc: Point;
onClick?: () => void; onClick?: () => void;
} }
export interface DAGNodeElm { export interface DAGNodeElm {
type: 'node'; type: 'node';
key: string;
loc: Point; loc: Point;
node: AutomationNode; node: AutomationNode;
onRemove: () => void; onRemove: () => void;
@@ -25,11 +23,10 @@ export interface DAGNodeElm {
} }
export interface DAGEdgeElm { export interface DAGEdgeElm {
type: 'edge'; type: 'edge';
key: string;
p1: Point; p1: Point;
p2: Point; p2: Point;
direction: EdgeDirection; direction: EdgeDirection;
toChild?: boolean; fromCircle?: boolean;
onAdd?: () => void; onAdd?: () => void;
} }
export type DAGElement = DAGEdgeElm | DAGNodeElm | DAGCircleElm; export type DAGElement = DAGEdgeElm | DAGNodeElm | DAGCircleElm;
@@ -86,7 +83,7 @@ export function* mapDataToElements({
st.addHeight + st.addHeight / 2 st.addHeight + st.addHeight / 2
]) ])
yield <DAGNode yield <DAGNode
key={`(${elm.loc})${elm.key}-*`} key={`(${elm.loc})-*`}
height={st.nodeHeight} height={st.nodeHeight}
width={st.nodeWidth} width={st.nodeWidth}
loc={nodeLoc} loc={nodeLoc}
@@ -96,14 +93,14 @@ export function* mapDataToElements({
/> />
if (elm.onAdd) { if (elm.onAdd) {
yield <DAGEdge yield <DAGEdge
key={`${elm.key}->+`} key={`(${elm.loc})->+`}
p1={offsetPoint(nodeLoc, [st.nodeWidth, st.nodeHeight / 2])} p1={offsetPoint(nodeLoc, [st.nodeWidth, st.nodeHeight / 2])}
p2={offsetPoint(addLoc, [0, st.addHeight / 2])} p2={offsetPoint(addLoc, [0, st.addHeight / 2])}
direction="1->2" direction="1->2"
color={st.edgeNextColor} color={st.edgeNextColor}
/> />
yield <AddButton yield <AddButton
key={`${elm.key}-+`} key={`(${elm.loc})-+`}
loc={addLoc} loc={addLoc}
height={st.addHeight} height={st.addHeight}
width={st.addWidth} width={st.addWidth}
@@ -113,16 +110,22 @@ export function* mapDataToElements({
break break
case 'edge': case 'edge':
const p2 = mapWithNode(elm.p2, [0, st.nodeHeight / 2]); const p2 = mapWithNode(elm.p2, [0, st.nodeHeight / 2]);
let p1: Point;
if (elm.fromCircle) {
p1 = mapWithNode(elm.p1, [st.circleSize * 0.95, 1.3 * st.circleSize / 2])
} else {
p1 = mapWithNode(elm.p1, [st.nodeWidth, st.nodeHeight / 2])
}
yield <DAGEdge yield <DAGEdge
key={`${elm.key}->`} key={`(${elm.p1})->(${elm.p2})`}
p1={mapWithNode(elm.p1, [st.nodeWidth, st.nodeHeight / 2])} p1={p1}
p2={p2} p2={p2}
direction={elm.direction} direction={elm.direction}
color={elm.toChild ? st.edgeChildColor : st.edgeNextColor} color={st.edgeNextColor}
/> />
if (elm.onAdd) { if (elm.onAdd) {
yield <AddButton yield <AddButton
key={`${elm.key}-+`} key={`(${elm.p2})-+`}
loc={offsetPoint(p2, [0, -st.addHeight / 2])} loc={offsetPoint(p2, [0, -st.addHeight / 2])}
height={st.addHeight} height={st.addHeight}
width={st.addWidth} width={st.addWidth}
@@ -133,7 +136,7 @@ export function* mapDataToElements({
case 'circle': case 'circle':
const loc = mapWithNode(elm.loc, [0, st.nodeHeight / 2 - st.circleSize / 2]); const loc = mapWithNode(elm.loc, [0, st.nodeHeight / 2 - st.circleSize / 2]);
yield <DAGCircle yield <DAGCircle
key={`${elm.key}-o`} key={`(${elm.loc})-o`}
loc={loc} loc={loc}
size={st.circleSize} size={st.circleSize}
onClick={elm.onClick} onClick={elm.onClick}
@@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react'; import { ComponentMeta, ComponentStory } from '@storybook/react';
import { SequenceNodes } from './index'; import { SequenceNodes } from './index';
import { NODE_HEIGHT, NODE_WIDTH, DISTANCE_FACTOR, ADD_HEIGHT, ADD_WIDTH } from '../DAGSvgs/constants'; import { NODE_HEIGHT, NODE_WIDTH, DISTANCE_FACTOR, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE } from '../DAGSvgs/constants';
import { useState } from 'react'; import { useState } from 'react';
@@ -17,6 +17,7 @@ export default {
nodeWidth: NODE_WIDTH, nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT, addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH, addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR, distanceFactor: DISTANCE_FACTOR,
} }
} }
@@ -7,14 +7,6 @@ import { computeNodesEdgesPos } from './positions';
export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (props) => { export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (props) => {
const theme = useTheme(); const theme = useTheme();
// return <>
// {Array.from(computeNodesEdges({
// ...props,
// keyPrefix: "",
// edgeColor: theme.secondaryAccent,
// }))}
// </>
return <DAGBoard return <DAGBoard
zoomLevel={props.zoomLevel} zoomLevel={props.zoomLevel}
elements={computeNodesEdgesPos( elements={computeNodesEdgesPos(
@@ -6,7 +6,7 @@ import { ChooseAction } from '../../types/automations/actions';
const offsetPoint = ( const offsetPoint = (
[x, y]: Point, [x, y]: Point,
[ox, oy]: Point = [0, 0] [ox, oy]: Point = [0, 0],
): Point => [x + ox, y + oy]; ): Point => [x + ox, y + oy];
const makeOffsetMaintainer = (startPoint: Point) => { const makeOffsetMaintainer = (startPoint: Point) => {
@@ -36,22 +36,33 @@ function* inner(
nodeLoc: Point, nodeLoc: Point,
innerStartLoc: Point, innerStartLoc: Point,
updater: Updater, updater: Updater,
keyPrefix: string,
sequence: AutomationSequenceNode[], sequence: AutomationSequenceNode[],
onEdit?: () => void,
): Generator<DAGElement> { ): Generator<DAGElement> {
const np = offsetPoint(innerStartLoc, [0.5, 0]);
yield { yield {
type: 'edge', type: 'edge',
p1: nodeLoc, p1: nodeLoc,
p2: innerStartLoc, p2: innerStartLoc,
direction: '1->2', 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, onAdd: sequence.length === 0 ? updater.addNode : undefined,
fromCircle: true,
} }
for (let childNode of computeNodesEdgesPos( for (let childNode of computeNodesEdgesPos(
innerStartLoc, np,
sequence, sequence,
updater.onChange, updater.onChange,
keyPrefix,
)) { )) {
yield childNode yield childNode
} }
@@ -62,7 +73,6 @@ function* dealWithChoose(
nodeLoc: Point, nodeLoc: Point,
makeUpdater: (j: number | null) => Updater, makeUpdater: (j: number | null) => Updater,
offset: ReturnType<typeof makeOffsetMaintainer>, offset: ReturnType<typeof makeOffsetMaintainer>,
keyPrefix: string,
) { ) {
offset.resetY() offset.resetY()
for (let j = 0; j < node.action_data.choose.length; j++) { for (let j = 0; j < node.action_data.choose.length; j++) {
@@ -71,8 +81,8 @@ function* dealWithChoose(
nodeLoc, nodeLoc,
innerStartLoc , innerStartLoc ,
makeUpdater(j), makeUpdater(j),
`${keyPrefix}.${j}`, node.action_data.choose[j].sequence,
node.action_data.choose[j].sequence () => {},
)) { )) {
yield elm yield elm
if (elm.type === 'node') { 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( for (let elm of inner(
nodeLoc, nodeLoc,
innerStartLoc, innerStartLoc,
makeUpdater(null), makeUpdater(null),
`${keyPrefix}-d`,
node.action_data.default, node.action_data.default,
)) { )) {
yield elm yield elm
@@ -100,7 +112,6 @@ export function* computeNodesEdgesPos(
startPoint: Point, startPoint: Point,
sequence: AutomationSequenceNode[], sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void, onChange: (s: AutomationSequenceNode[]) => void,
keyPrefix: string = '$',
): Generator<DAGElement> { ): Generator<DAGElement> {
const rootUpdater = makeUpdater(sequence, onChange); const rootUpdater = makeUpdater(sequence, onChange);
const offset = makeOffsetMaintainer(startPoint) const offset = makeOffsetMaintainer(startPoint)
@@ -111,7 +122,6 @@ export function* computeNodesEdgesPos(
const nodeLoc = offsetPoint(startPoint, [i + offset.x, 0]); const nodeLoc = offsetPoint(startPoint, [i + offset.x, 0]);
yield { yield {
type: 'node', type: 'node',
key: `${keyPrefix}${i}`,
loc: nodeLoc, loc: nodeLoc,
node, node,
onRemove: () => rootUpdater.removeNode(i), onRemove: () => rootUpdater.removeNode(i),
@@ -120,7 +130,6 @@ export function* computeNodesEdgesPos(
if (lastNodeLoc) { if (lastNodeLoc) {
yield { yield {
type: 'edge', type: 'edge',
key: `${keyPrefix}(${i-1}->${i})`,
p1: lastNodeLoc, p1: lastNodeLoc,
p2: nodeLoc, p2: nodeLoc,
direction: '1->2', direction: '1->2',
@@ -135,7 +144,6 @@ export function* computeNodesEdgesPos(
nodeLoc, nodeLoc,
j => rootUpdater.makeChildUpdaterForChooseAction(i, j), j => rootUpdater.makeChildUpdaterForChooseAction(i, j),
offset, offset,
`${keyPrefix}.${i}`,
) )
} }
} }