initial work on dag converison
This commit is contained in:
1 parent
5ac972101a
commit
a7fda74168
5 files changed
+54
-8
No files matched your search
@@ -6,7 +6,7 @@ export interface Automation {
|
||||
id: string;
|
||||
alias: string;
|
||||
description: string;
|
||||
trigger_variables: Record<string, string>;
|
||||
trigger_variables?: Record<string, string>;
|
||||
mode: "single" | "restart" | "queued" | "parallel";
|
||||
trigger: AutomationTrigger[];
|
||||
condition: AutomationCondition[];
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function AutomationDAG({
|
||||
<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"/>
|
||||
{/* <rect x="1" y="1" height={GRAPH_HEIGHT-1} width={GRAPH_WIDTH} stroke="white" fill="none"/> */}
|
||||
<g className="automation-dag-edges">
|
||||
{edges.map(({from, to, direction}, i) => <DAGEdge
|
||||
key={i}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
export type Point = [number, number];
|
||||
export interface Node {
|
||||
loc: Point;
|
||||
text: string;
|
||||
text: JSX.Element | string;
|
||||
}
|
||||
export interface Edge {
|
||||
from: string;
|
||||
@@ -14,4 +14,7 @@ export type EdgeDirection = Edge['direction'];
|
||||
export interface DAG {
|
||||
nodes: Record<string,Node>;
|
||||
edges: Array<Edge>;
|
||||
}
|
||||
export interface NormalizedDag extends DAG {
|
||||
// overflow: boolean;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants";
|
||||
import {clip} from "./utils";
|
||||
import {clip, computeDAG} from "./utils";
|
||||
|
||||
test('it clips overflowing values', () => {
|
||||
expect(clip([GRAPH_WIDTH, GRAPH_HEIGHT])).toEqual([
|
||||
@@ -13,4 +13,21 @@ test('it clips overflowing values', () => {
|
||||
expect(clip([0, 0])).toEqual([
|
||||
0, 0
|
||||
])
|
||||
})
|
||||
|
||||
test('simple empty input dag', () => {
|
||||
expect(computeDAG({
|
||||
id: "root",
|
||||
alias: "root",
|
||||
description: 'root',
|
||||
mode: 'single',
|
||||
trigger: [],
|
||||
condition: [],
|
||||
action: [
|
||||
],
|
||||
})).toEqual({
|
||||
nodes: {},
|
||||
edges: [
|
||||
],
|
||||
})
|
||||
})
|
||||
@@ -1,15 +1,13 @@
|
||||
|
||||
import { Automation } from "../../automation/types";
|
||||
import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants";
|
||||
import {DAG, Node, Point} from "./types";
|
||||
import {DAG, Node, Point, NormalizedDag} from "./types";
|
||||
|
||||
|
||||
export const clip = (p: Point) : Point => {
|
||||
const [x,y] = p.map(c => Math.max(0, c));
|
||||
return [Math.min(GRAPH_WIDTH-NODE_WIDTH, x), Math.min(GRAPH_HEIGHT-NODE_HEIGHT, y)]
|
||||
}
|
||||
export interface NormalizedDag extends DAG {
|
||||
// overflow: boolean;
|
||||
}
|
||||
export const normalizeDAG = (dag: DAG): NormalizedDag => {
|
||||
// let overflow: bo
|
||||
const nodes = Object.keys(dag.nodes).map<[string, Node]>(nodeId => [nodeId, {
|
||||
@@ -29,4 +27,32 @@ export const normalizeDAG = (dag: DAG): NormalizedDag => {
|
||||
nodes,
|
||||
edges: dag.edges,
|
||||
}
|
||||
}
|
||||
export const computeDAG = (automation: Automation) : DAG => {
|
||||
const nodes: DAG['nodes'] = {};
|
||||
const edges: DAG['edges'] = [];
|
||||
|
||||
automation.action
|
||||
|
||||
// let currentNode: InputDagNode | null = rootNode;
|
||||
// let currLoc: Point = [0,0];
|
||||
// let idPath = '';
|
||||
// // let
|
||||
// while (currentNode) {
|
||||
// const n = {
|
||||
// text: currentNode.display,
|
||||
// loc: currLoc,
|
||||
// }
|
||||
// if(idPath) {
|
||||
// nodes[idPath + "." + currentNode.name] = n
|
||||
// edges
|
||||
// } else {
|
||||
// nodes[currentNode.name] = n
|
||||
// }
|
||||
// currentNode = currentNode.next[0]
|
||||
// }
|
||||
|
||||
return {
|
||||
nodes, edges
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user