|  | @@ -1,20 +1,20 @@
 | 
											
												
													
														|  |  import dagre from "dagre";
 |  |  import dagre from "dagre";
 | 
											
												
													
														|  |  import { Elements, isNode, Position } from "react-flow-renderer";
 |  |  import { Elements, isNode, Position } from "react-flow-renderer";
 | 
											
												
													
														|  | 
 |  | +import { parser } from "src/utils/json-editor-parser";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  const dagreGraph = new dagre.graphlib.Graph();
 |  |  const dagreGraph = new dagre.graphlib.Graph();
 | 
											
												
													
														|  |  dagreGraph.setDefaultEdgeLabel(() => ({}));
 |  |  dagreGraph.setDefaultEdgeLabel(() => ({}));
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -export const onLayout = (
 |  | 
 | 
											
												
													
														|  | -  direction: string,
 |  | 
 | 
											
												
													
														|  | -  elements: Elements,
 |  | 
 | 
											
												
													
														|  | -  setElements: React.Dispatch<Elements>
 |  | 
 | 
											
												
													
														|  | -) => {
 |  | 
 | 
											
												
													
														|  | 
 |  | +export const getLayoutPosition = (direction: string, elements: Elements, dynamic = false) => {
 | 
											
												
													
														|  |    const isHorizontal = direction === "LR";
 |  |    const isHorizontal = direction === "LR";
 | 
											
												
													
														|  |    dagreGraph.setGraph({ rankdir: direction });
 |  |    dagreGraph.setGraph({ rankdir: direction });
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    elements.forEach((el) => {
 |  |    elements.forEach((el) => {
 | 
											
												
													
														|  |      if (isNode(el)) {
 |  |      if (isNode(el)) {
 | 
											
												
													
														|  | -      dagreGraph.setNode(el.id, { width: 175, height: 50 });
 |  | 
 | 
											
												
													
														|  | 
 |  | +      dagreGraph.setNode(el.id, {
 | 
											
												
													
														|  | 
 |  | +        width: dynamic ? el.__rf.width : 200,
 | 
											
												
													
														|  | 
 |  | +        height: dynamic ? el.__rf.height : 100,
 | 
											
												
													
														|  | 
 |  | +      });
 | 
											
												
													
														|  |      } else {
 |  |      } else {
 | 
											
												
													
														|  |        dagreGraph.setEdge(el.source, el.target);
 |  |        dagreGraph.setEdge(el.source, el.target);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -36,5 +36,28 @@ export const onLayout = (
 | 
											
												
													
														|  |      return el;
 |  |      return el;
 | 
											
												
													
														|  |    });
 |  |    });
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  setElements(layoutedElements);
 |  | 
 | 
											
												
													
														|  | -};
 |  | 
 | 
											
												
													
														|  | 
 |  | +  return layoutedElements;
 | 
											
												
													
														|  | 
 |  | +};
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +export function getNextLayout(layout: "TB" | "BT" | "RL" | "LR") {
 | 
											
												
													
														|  | 
 |  | +  switch (layout) {
 | 
											
												
													
														|  | 
 |  | +    case "TB":
 | 
											
												
													
														|  | 
 |  | +      return "BT";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    case "BT":
 | 
											
												
													
														|  | 
 |  | +      return "RL";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    case "RL":
 | 
											
												
													
														|  | 
 |  | +      return "LR";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    default:
 | 
											
												
													
														|  | 
 |  | +      return "TB";
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +export function getLayout(layout: string, json: string, dynamic = false) {
 | 
											
												
													
														|  | 
 |  | +  const jsonToGraph = parser(json);
 | 
											
												
													
														|  | 
 |  | +  const layoutedElements = getLayoutPosition(layout, jsonToGraph, dynamic);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  return layoutedElements;
 | 
											
												
													
														|  | 
 |  | +}
 |