@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
40 lines • 1.53 kB
JavaScript
import { graphlib, layout } from "dagre";
import { Position } from "reactflow";
const dagreGraph = new graphlib.Graph();
dagreGraph.setDefaultEdgeLabel(() => ({}));
const nodeWidth = 130;
const nodeHeight = 40;
const nodeAfterConditionalHeight = 130;
export const getLayoutedNodes = (nodes, direction = "LR") => {
const isHorizontal = direction === "LR";
dagreGraph.setGraph({ rankdir: direction });
nodes.forEach((element, index) => {
const prevNode = index > 0 ? nodes[index - 1] : undefined;
dagreGraph.setNode(element.id, {
width: nodeWidth,
height: (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === "conditional"
? nodeAfterConditionalHeight
: nodeHeight,
});
});
layout(dagreGraph);
return nodes.map((node) => {
const nodeWithPosition = dagreGraph.node(node.id);
node.targetPosition = isHorizontal ? Position.Left : Position.Top;
node.sourcePosition = isHorizontal ? Position.Right : Position.Bottom;
node.position = {
x: nodeWithPosition.x - nodeWidth / 2,
y: nodeWithPosition.y - nodeHeight / 2,
};
return node;
});
};
export const getLayoutedEdges = (edges, direction = "LR") => {
dagreGraph.setGraph({ rankdir: direction });
edges.forEach((element) => {
dagreGraph.setEdge(element.source, element.target);
});
layout(dagreGraph);
return edges;
};
//# sourceMappingURL=auto-layout.js.map