initial graph view
This commit is contained in:
1 parent
12d086a5c0
commit
6d4fe7749a
8 files changed
+131
-48
No files matched your search
@@ -1,6 +1,13 @@
|
||||
import { AutomationData } from "~/automations/types";
|
||||
import { AutomationCondition } from "~/automations/types/conditions";
|
||||
import { AutomationTrigger } from "~/automations/types/triggers";
|
||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||
import useWindowSize from "~/utils/useWindowSize";
|
||||
import AutoInfoBox from "./AutoInfoBox";
|
||||
import { NODE_HEIGHT, NODE_WIDTH } from "./constants";
|
||||
import DAGEdge from "./DAGEdge";
|
||||
import DAGNode from "./DAGNode";
|
||||
import { Point } from "./types";
|
||||
|
||||
interface Props {
|
||||
automation: AutomationData;
|
||||
@@ -11,11 +18,47 @@ export default function AutomationEditor({
|
||||
onUpdate,
|
||||
}: Props) {
|
||||
|
||||
// state
|
||||
const {ratioWbh} = useWindowSize();
|
||||
|
||||
// alias
|
||||
const nHDF = 1.5 // node horizontal distance factor
|
||||
const graphHeight = 300;
|
||||
const graphWidth = Math.round(graphHeight * ratioWbh);
|
||||
console.log({ratioWbh, graphHeight, graphWidth})
|
||||
const pointTrigToCond: Point = [NODE_WIDTH*nHDF, NODE_HEIGHT/2]
|
||||
|
||||
// render funcs
|
||||
const renderTrigger = (trigger: AutomationTrigger, i: number) => {
|
||||
const nodeLoc: Point = [0 ,i*NODE_HEIGHT*1.25];
|
||||
return <>
|
||||
<DAGNode key={`node.${i}`} loc={nodeLoc} text={getDescriptionFromAutomationNode(trigger)} color="red"/>
|
||||
<DAGEdge
|
||||
key={`edge.${i}`}
|
||||
p1={[NODE_WIDTH , nodeLoc[1] + 0.5 * NODE_HEIGHT]}
|
||||
p2={pointTrigToCond}
|
||||
direction="1->2"
|
||||
/>
|
||||
</>
|
||||
}
|
||||
const renderMidCondition = (condition: AutomationCondition, i: number) => {
|
||||
const nodeLoc: Point = [pointTrigToCond[0] + NODE_WIDTH/2 , 0];
|
||||
let lastNodeLoc = pointTrigToCond;
|
||||
if (i > 0) {
|
||||
lastNodeLoc = [nodeLoc[0] + NODE_WIDTH*((i - 1)*nHDF+1), nodeLoc[1] + NODE_HEIGHT/2];
|
||||
nodeLoc[0] += NODE_WIDTH*i*nHDF
|
||||
}
|
||||
return <>
|
||||
<DAGNode key={`node.${i}`} loc={nodeLoc} text={getDescriptionFromAutomationNode(condition)} color="blue"/>
|
||||
<DAGEdge
|
||||
key={`edge.${i}`}
|
||||
p1={lastNodeLoc}
|
||||
p2={[nodeLoc[0], nodeLoc[1] + NODE_HEIGHT/2]}
|
||||
direction="1->2"
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
// render
|
||||
return <div className="automation-editor" style={{
|
||||
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
|
||||
}}>
|
||||
@@ -35,13 +78,15 @@ export default function AutomationEditor({
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" />
|
||||
</marker>
|
||||
</defs>
|
||||
{/* <rect x="1" y="1" height={GRAPH_HEIGHT-1} width={GRAPH_WIDTH} stroke="white" fill="none"/> */}
|
||||
{/* <g className="automation-dag-edges">
|
||||
|
||||
</g>
|
||||
<g className="automation-dag-nodes">
|
||||
|
||||
</g> */}
|
||||
<g className="triggers">
|
||||
{automation.trigger.map(renderTrigger)}
|
||||
</g>
|
||||
<g className="conditions">
|
||||
{automation.condition.map(renderMidCondition)}
|
||||
</g>
|
||||
<circle className="blue" cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2}/>
|
||||
<g className="actions">
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user