The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
import dagre from "@dagrejs/dagre";
import type { Edge } from "@xyflow/react";
import type { NodeType } from "../types";
export function getNodesWithPositions(
nodes: NodeType[],
edges: Edge[],
): NodeType[] {
const dagreGraph = new dagre.graphlib.Graph();
dagreGraph.setGraph({ rankdir: "LR" });
dagreGraph.setDefaultEdgeLabel(() => ({}));
nodes.forEach((node) => {
dagreGraph.setNode(node.id, {
width: node.measured?.width,
height: node.measured?.height,
});
});
edges.forEach((edge) => {
dagreGraph.setEdge(edge.target, edge.source);
});
dagre.layout(dagreGraph);
return nodes.map((node) => {
const { x, y, width, height } = dagreGraph.node(node.id);
return {
...node,
position: {
x: x - width / 2,
y: y - height / 2,
},
};
});
}