Add image IO inspector and measured layout
This commit is contained in:
@@ -10,6 +10,7 @@ type LayoutDirection = 'LR' | 'TB'
|
||||
type LayoutOptions = {
|
||||
direction?: LayoutDirection
|
||||
useSavedPositions?: boolean
|
||||
dimensions?: Record<string, { width: number; height: number }>
|
||||
}
|
||||
|
||||
function estimatePortHeight(port: any, direction: 'in' | 'out') {
|
||||
@@ -60,9 +61,10 @@ export function layoutGraph(nodes: Node[], edges: Edge[], options: LayoutOptions
|
||||
})
|
||||
|
||||
for (const node of nodes) {
|
||||
const measured = options.dimensions?.[node.id]
|
||||
graph.setNode(node.id, {
|
||||
width: DEFAULT_NODE_WIDTH,
|
||||
height: estimateNodeHeight(node),
|
||||
width: Math.max(DEFAULT_NODE_WIDTH, measured?.width || DEFAULT_NODE_WIDTH),
|
||||
height: Math.max(estimateNodeHeight(node), measured?.height || 0),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,14 +76,16 @@ export function layoutGraph(nodes: Node[], edges: Edge[], options: LayoutOptions
|
||||
|
||||
return nodes.map((node) => {
|
||||
const graphNode = graph.node(node.id)
|
||||
const height = estimateNodeHeight(node)
|
||||
const measured = options.dimensions?.[node.id]
|
||||
const width = Math.max(DEFAULT_NODE_WIDTH, measured?.width || DEFAULT_NODE_WIDTH)
|
||||
const height = Math.max(estimateNodeHeight(node), measured?.height || 0)
|
||||
|
||||
return {
|
||||
...node,
|
||||
targetPosition: targetPosition(direction),
|
||||
sourcePosition: sourcePosition(direction),
|
||||
position: graphNode
|
||||
? { x: graphNode.x - DEFAULT_NODE_WIDTH / 2, y: graphNode.y - height / 2 }
|
||||
? { x: graphNode.x - width / 2, y: graphNode.y - height / 2 }
|
||||
: node.position,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user