UNPKG

schyma

Version:

JSON Schemas Visualizer React component

35 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLayoutedElements = void 0; const tslib_1 = require("tslib"); const reactflow_1 = require("reactflow"); const node_1 = require("../constants/node"); const dagre_1 = tslib_1.__importDefault(require("@dagrejs/dagre")); const getLayoutedElements = (nodes, edges, direction = 'LR') => { const dagreGraph = new dagre_1.default.graphlib.Graph(); dagreGraph.setDefaultEdgeLabel(() => ({})); dagreGraph.setGraph({ rankdir: direction }); nodes.forEach((node) => { dagreGraph.setNode(node.id, { width: node_1.nodeWidth, height: node_1.nodeHeight }); }); edges.forEach((edge) => { dagreGraph.setEdge(edge.source, edge.target); }); dagre_1.default.layout(dagreGraph, { disableOptimalOrderHeuristic: true, }); nodes.forEach((node) => { const nodeId = node.id; const nodeWithPosition = dagreGraph.node(nodeId); node.sourcePosition = reactflow_1.Position.Right; node.targetPosition = reactflow_1.Position.Left; node.position = { x: nodeWithPosition.x - node_1.nodeWidth / 3, y: nodeWithPosition.y - node_1.nodeHeight / 3, }; return node; }); return { nodes, edges }; }; exports.getLayoutedElements = getLayoutedElements; //# sourceMappingURL=dagreUtils.js.map