Hi there I face a bug to display nodes and edges from left to right #4223
Unanswered
Muhammad1Siddique
asked this question in
Layouting
Replies: 1 comment
-
If you're using custom nodes you can specify the positions on the <Handle type="source" position={Position.Right} />
<Handle type="target" position={Position.Left} /> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
import { useMemo } from "react";
import { Node, Edge, Position } from "reactflow";
import { type NodeData } from "../../../../types/reactflowType";
import Dagre from "@dagrejs/dagre";
export type UseExpandCollapseOptions = {
layoutNodes?: boolean;
treeWidth?: number;
treeHeight?: number;
};
function filterCollapsedChildren(
dagre: Dagre.graphlib.Graph,
node: Node
) {
const children = dagre.successors(node.id) as string[] | undefined;
node.data.expandable = !!children?.length;
if (!node.data.expanded && children) {
while (children.length) {
const child = children.pop()!;
const childSuccessors = dagre.successors(child) as string[] | undefined;
if (childSuccessors) {
children.push(...childSuccessors);
}
dagre.removeNode(child);
}
}
}
function useExpandCollapse(
nodes: Node[],
edges: Edge[],
{
layoutNodes = true,
treeWidth = 220,
treeHeight = 100,
}: UseExpandCollapseOptions = {}
): { nodes: Node[]; edges: Edge[] } {
return useMemo(() => {
if (!layoutNodes || !Array.isArray(nodes) || nodes.length === 0) {
return { nodes, edges };
}
}, [nodes, edges, layoutNodes, treeWidth, treeHeight]);
}
export default useExpandCollapse;
Beta Was this translation helpful? Give feedback.
All reactions