sequence node drawing v1
This commit is contained in:
1 parent
1d7b6e96c1
commit
edb3dafe12
7 files changed
+70
-58
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import { DAGDims } from "./types";
|
||||
|
||||
export const NODE_WIDTH = 170 as const;
|
||||
export const NODE_HEIGHT = 70 as const;
|
||||
export const NODE_WIDTH = 200 as const;
|
||||
export const NODE_HEIGHT = 80 as const;
|
||||
export const CIRCLE_SIZE = 40 as const;
|
||||
export const DISTANCE_FACTOR = 1.25 as const;
|
||||
|
||||
export const DEFAULT_DIMS: DAGDims = {
|
||||
trigger: {
|
||||
@@ -22,7 +21,10 @@ export const DEFAULT_DIMS: DAGDims = {
|
||||
height: CIRCLE_SIZE,
|
||||
width: CIRCLE_SIZE,
|
||||
},
|
||||
distanceFactor: DISTANCE_FACTOR,
|
||||
distanceFactor: {
|
||||
node: 2,
|
||||
collection: 1.25,
|
||||
},
|
||||
position: {
|
||||
x: 50,
|
||||
y: 50,
|
||||
|
||||
@@ -5,22 +5,17 @@ export const moveAlong = (
|
||||
by: keyof DAGEntities,
|
||||
startPoint: XYPosition,
|
||||
increment: number,
|
||||
dims: DAGDims,
|
||||
direction: "under" | "next" = "next"
|
||||
dims: DAGDims
|
||||
): XYPosition => {
|
||||
const moveOnY = {
|
||||
y: startPoint.y + dims[by].height * dims.distanceFactor * increment,
|
||||
y: startPoint.y + dims[by].height * dims.distanceFactor.node * increment,
|
||||
x: startPoint.x,
|
||||
};
|
||||
const moveOnX = {
|
||||
x: startPoint.x + dims[by].width * dims.distanceFactor * increment,
|
||||
x: startPoint.x + dims[by].width * dims.distanceFactor.node * increment,
|
||||
y: startPoint.y,
|
||||
};
|
||||
if (direction === "next") {
|
||||
return dims.flipped ? moveOnX : moveOnY;
|
||||
} else {
|
||||
return !dims.flipped ? moveOnX : moveOnY;
|
||||
}
|
||||
return !dims.flipped ? moveOnX : moveOnY;
|
||||
};
|
||||
|
||||
export const moveFromTo = (
|
||||
@@ -31,34 +26,13 @@ export const moveFromTo = (
|
||||
): XYPosition => {
|
||||
if (!dims.flipped) {
|
||||
return {
|
||||
x: startPoint.x + dims[from].width * dims.distanceFactor,
|
||||
x: startPoint.x + dims[from].width * dims.distanceFactor.collection,
|
||||
y: startPoint.y + (dims[from].height - dims[to].height) / 2,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
y: startPoint.y + dims[from].height * dims.distanceFactor,
|
||||
y: startPoint.y + dims[from].height * dims.distanceFactor.collection,
|
||||
x: startPoint.x + (dims[from].width - dims[to].width) / 2,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const computeSize = (
|
||||
by: keyof DAGEntities,
|
||||
dims: DAGDims,
|
||||
count: number,
|
||||
direction: "under" | "next" = "next"
|
||||
): Size => {
|
||||
const moveOnY = {
|
||||
height: dims[by].height * count,
|
||||
width: dims[by].width * dims.distanceFactor,
|
||||
};
|
||||
const moveOnX = {
|
||||
width: dims[by].width * count,
|
||||
height: dims[by].height * dims.distanceFactor,
|
||||
};
|
||||
if (direction === "next") {
|
||||
return dims.flipped ? moveOnX : moveOnY;
|
||||
} else {
|
||||
return !dims.flipped ? moveOnX : moveOnY;
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ElementMaker,
|
||||
ElementMakerBaseProps,
|
||||
ElementMakerOutput,
|
||||
LastNode,
|
||||
} from "./types";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import * as distance from "./distance";
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
} from "types/automations";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
||||
import { SequenceNodeMaker } from "../nodes/SequenceNode";
|
||||
|
||||
export const makeAutomationNodes = (
|
||||
automation: AutomationActionData,
|
||||
@@ -72,9 +74,7 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
nodes: nodes.map((node, index) => ({
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("trigger", index, {
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
})),
|
||||
})
|
||||
);
|
||||
@@ -101,9 +101,7 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
nodes: nodes.map((node, index) => ({
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("condition", index, {
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
})),
|
||||
})
|
||||
);
|
||||
@@ -129,14 +127,46 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
|
||||
export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
nodes,
|
||||
{ nodeId, elementData, dims }
|
||||
{ nodeId, lastNodeId, elementData, dims, position, namer, stateUpdater }
|
||||
) => {
|
||||
let lastNode: LastNode = {
|
||||
nodeId: lastNodeId ?? nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.node,
|
||||
};
|
||||
nodes.forEach((node, nodeIndex) => {
|
||||
const element = SequenceNodeMaker.makeElement(
|
||||
{
|
||||
id: `${nodeId}-${nodeIndex}`,
|
||||
position: distance.moveAlong("node", position, nodeIndex, dims),
|
||||
},
|
||||
dims,
|
||||
{
|
||||
color: "green",
|
||||
enabled: node.enabled ?? true,
|
||||
hasInput: true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("sequence", nodeIndex, {
|
||||
includeAdd: true,
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
}
|
||||
);
|
||||
elementData.nodes.push(element);
|
||||
elementData.edges.push({
|
||||
id: `${lastNode.nodeId}->${element.id}`,
|
||||
target: element.id,
|
||||
source: lastNode.nodeId,
|
||||
});
|
||||
lastNode = {
|
||||
nodeId: element.id,
|
||||
pos: element.position,
|
||||
size: dims.node,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
elementData,
|
||||
lastNode: {
|
||||
nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.node,
|
||||
},
|
||||
lastNode,
|
||||
};
|
||||
};
|
||||
@@ -20,7 +20,10 @@ export type DAGEntities = {
|
||||
};
|
||||
export type DAGDims = DAGEntities & {
|
||||
position: XYPosition;
|
||||
distanceFactor: number;
|
||||
distanceFactor: {
|
||||
node: number;
|
||||
collection: number;
|
||||
};
|
||||
flipped: boolean;
|
||||
};
|
||||
export type ElementMakerBaseProps = {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
.collection-nodes--wrap {
|
||||
--padding: 1.5em;
|
||||
--child-height: calc(var(--node-height) - 2*var(--padding));
|
||||
--child-width: calc(var(--node-width) - 2*var(--padding));
|
||||
|
||||
min-width: var(--node-width);
|
||||
min-height: var(--node-height);
|
||||
@@ -10,6 +12,8 @@
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
/* outline: 1px dotted white; */
|
||||
}
|
||||
|
||||
.collection-nodes {
|
||||
@@ -18,11 +22,11 @@
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 1.5em;
|
||||
max-width: var(--node-width);
|
||||
max-height: var(--node-height);
|
||||
gap: 0em 1em;
|
||||
max-width: var(--child-width);
|
||||
max-height: var(--child-height);
|
||||
|
||||
border-color: var(--node-color);
|
||||
border-color: var(--child-color);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 10px;
|
||||
|
||||
@@ -26,8 +26,8 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
"--node-height": `calc(${height}px - 2*var(--padding))`,
|
||||
"--node-width": `calc(${width}px - 2*var(--padding))`,
|
||||
"--node-height": `${height}px`,
|
||||
"--node-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: default;
|
||||
/* outline-width: 1px;
|
||||
outline-style: dotted;
|
||||
outline-color: white; */
|
||||
|
||||
/* outline: 1px dotted white; */
|
||||
}
|
||||
|
||||
.sequence-node--inner {
|
||||
|
||||
Reference in new issue
Block a user