added branching icons
This commit is contained in:
1 parent
146a48b7c3
commit
55239e6517
4 files changed
+39
-35
No files matched your search
@@ -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 <DAGNode
|
||||
key={`(${elm.loc})${elm.key}-*`}
|
||||
key={`(${elm.loc})-*`}
|
||||
height={st.nodeHeight}
|
||||
width={st.nodeWidth}
|
||||
loc={nodeLoc}
|
||||
@@ -96,14 +93,14 @@ export function* mapDataToElements({
|
||||
/>
|
||||
if (elm.onAdd) {
|
||||
yield <DAGEdge
|
||||
key={`${elm.key}->+`}
|
||||
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 <AddButton
|
||||
key={`${elm.key}-+`}
|
||||
key={`(${elm.loc})-+`}
|
||||
loc={addLoc}
|
||||
height={st.addHeight}
|
||||
width={st.addWidth}
|
||||
@@ -113,16 +110,22 @@ export function* mapDataToElements({
|
||||
break
|
||||
case 'edge':
|
||||
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
|
||||
key={`${elm.key}->`}
|
||||
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 <AddButton
|
||||
key={`${elm.key}-+`}
|
||||
key={`(${elm.p2})-+`}
|
||||
loc={offsetPoint(p2, [0, -st.addHeight / 2])}
|
||||
height={st.addHeight}
|
||||
width={st.addWidth}
|
||||
@@ -133,7 +136,7 @@ export function* mapDataToElements({
|
||||
case 'circle':
|
||||
const loc = mapWithNode(elm.loc, [0, st.nodeHeight / 2 - st.circleSize / 2]);
|
||||
yield <DAGCircle
|
||||
key={`${elm.key}-o`}
|
||||
key={`(${elm.loc})-o`}
|
||||
loc={loc}
|
||||
size={st.circleSize}
|
||||
onClick={elm.onClick}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
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';
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ export default {
|
||||
nodeWidth: NODE_WIDTH,
|
||||
addHeight: ADD_HEIGHT,
|
||||
addWidth: ADD_WIDTH,
|
||||
circleSize: CIRCLE_SIZE,
|
||||
distanceFactor: DISTANCE_FACTOR,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,6 @@ import { computeNodesEdgesPos } from './positions';
|
||||
|
||||
export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (props) => {
|
||||
const theme = useTheme();
|
||||
|
||||
// return <>
|
||||
// {Array.from(computeNodesEdges({
|
||||
// ...props,
|
||||
// keyPrefix: "",
|
||||
// edgeColor: theme.secondaryAccent,
|
||||
// }))}
|
||||
// </>
|
||||
return <DAGBoard
|
||||
zoomLevel={props.zoomLevel}
|
||||
elements={computeNodesEdgesPos(
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ChooseAction } from '../../types/automations/actions';
|
||||
|
||||
const offsetPoint = (
|
||||
[x, y]: Point,
|
||||
[ox, oy]: Point = [0, 0]
|
||||
[ox, oy]: Point = [0, 0],
|
||||
): Point => [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<DAGElement> {
|
||||
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<typeof makeOffsetMaintainer>,
|
||||
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<DAGElement> {
|
||||
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}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user