feat: extract graph-interface into seperate package
This commit is contained in:
42
app/src/lib/graph-templates/grid.ts
Normal file
42
app/src/lib/graph-templates/grid.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { Graph } from "@nodes/types";
|
||||
|
||||
export function grid(width: number, height: number) {
|
||||
|
||||
const graph: Graph = {
|
||||
id: Math.floor(Math.random() * 100000),
|
||||
edges: [],
|
||||
nodes: [],
|
||||
};
|
||||
|
||||
const amount = width * height;
|
||||
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const x = i % width;
|
||||
const y = Math.floor(i / height);
|
||||
|
||||
graph.nodes.push({
|
||||
id: i,
|
||||
tmp: {
|
||||
visible: false,
|
||||
},
|
||||
position: [x * 30, y * 40],
|
||||
props: i == 0 ? { value: 0 } : { op_type: 2, a: 2, b: 2 },
|
||||
type: i == 0 ? "max/plantarium/float" : "max/plantarium/math",
|
||||
});
|
||||
|
||||
graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]);
|
||||
}
|
||||
|
||||
graph.nodes.push({
|
||||
id: amount,
|
||||
tmp: {
|
||||
visible: false,
|
||||
},
|
||||
position: [width * 30, (height - 1) * 40],
|
||||
type: "max/plantarium/output",
|
||||
props: {},
|
||||
});
|
||||
|
||||
return graph;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user