-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:feat: Optimize edge center calculation and improve node addition UI
This commit includes the following improvements: 1. Moved edge center calculation logic to a separate utility function Enhanced edge selection and node addition functionality Improved UI for adding nodes to edges Refined edge and node selection behavior Updated React Flow configuration for better performance and appearance
- Loading branch information
1 parent
d7312be
commit 71bfa14
Showing
2 changed files
with
17 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
import { Node } from 'reactflow'; | ||
|
||
export const getEdgeParams = (source: Node, target: Node) => { | ||
const sourceCenter = { | ||
x: source.position.x + (source.width || 0) / 2, | ||
y: source.position.y + (source.height || 0) / 2, | ||
}; | ||
|
||
const targetCenter = { | ||
x: target.position.x + (target.width || 0) / 2, | ||
y: target.position.y + (target.height || 0) / 2, | ||
}; | ||
|
||
const sx = sourceCenter.x; | ||
const sy = sourceCenter.y; | ||
const tx = targetCenter.x; | ||
const ty = targetCenter.y; | ||
export const calculateEdgeCenter = (sourceNode: Node, targetNode: Node): { x: number, y: number } => { | ||
const sourceX = sourceNode.position.x + (sourceNode.width ?? 0) / 2; | ||
const sourceY = sourceNode.position.y + (sourceNode.height ?? 0) / 2; | ||
const targetX = targetNode.position.x + (targetNode.width ?? 0) / 2; | ||
const targetY = targetNode.position.y + (targetNode.height ?? 0) / 2; | ||
|
||
return { | ||
sx, | ||
sy, | ||
tx, | ||
ty, | ||
x: (sourceX + targetX) / 2, | ||
y: (sourceY + targetY) / 2 | ||
}; | ||
}; |