build_graph/
build_graph.rs1use jellyflow_core::{
2 CanvasPoint, CanvasSize, Graph, GraphId, GraphOp, GraphTransaction, Node, NodeId, NodeKindKey,
3};
4
5fn make_node(kind: &str, x: f32, y: f32) -> Node {
6 Node {
7 kind: NodeKindKey::new(kind),
8 kind_version: 1,
9 pos: CanvasPoint { x, y },
10 origin: None,
11 selectable: None,
12 focusable: None,
13 draggable: None,
14 connectable: None,
15 deletable: None,
16 parent: None,
17 extent: None,
18 expand_parent: None,
19 size: Some(CanvasSize {
20 width: 160.0,
21 height: 80.0,
22 }),
23 hidden: false,
24 collapsed: false,
25 ports: Vec::new(),
26 data: serde_json::json!({
27 "label": kind,
28 }),
29 }
30}
31
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes.len(), 1);
44 assert_eq!(graph.nodes[&node_id].kind, NodeKindKey::new("demo.source"));
45}