Skip to content

fix overlapping nodes #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 9, 2025
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
86bd8b1
bump all available dependencies
Anchel123 Feb 12, 2025
7e00636
bump lucide-react react-slot
Anchel123 Feb 13, 2025
ef8f189
Merge branch 'staging' into update-dependencies-version
Anchel123 Feb 16, 2025
322e7e1
Merge branch 'staging' into update-dependencies-version
Anchel123 Feb 17, 2025
31a2089
fix overlapping nodes
Naseem77 Feb 27, 2025
a59dacb
Merge branch 'staging' into fix-overlapping-nodes
Naseem77 Feb 27, 2025
5e66aea
update overlap
Naseem77 Mar 2, 2025
035c09e
fix tests
Naseem77 Mar 3, 2025
62042a8
add tests (#397, #398)
Naseem77 Mar 3, 2025
bb5b613
Merge branch 'update-dependencies-version' into fix-overlapping-nodes
Naseem77 Mar 4, 2025
baa1e78
fix tests
Naseem77 Mar 4, 2025
33265f1
fix tests
Naseem77 Mar 4, 2025
0036e81
test without tooltip
Naseem77 Mar 4, 2025
9cbae93
add logging
Naseem77 Mar 4, 2025
9c9d9a0
fix search node
Anchel123 Mar 4, 2025
5c336c1
add logging
Naseem77 Mar 4, 2025
0f096b3
Update codeGraph.ts
Naseem77 Mar 4, 2025
505ffd1
Update codeGraph.ts
Naseem77 Mar 4, 2025
dc7b340
fix tests
Naseem77 Mar 4, 2025
21a7bd5
update nodeClick
Naseem77 Mar 4, 2025
d75147f
add test (#402)
Naseem77 Mar 4, 2025
bc8d998
fix #402
Naseem77 Mar 4, 2025
d83b591
update tooltip visibility
Naseem77 Mar 4, 2025
e1c463f
update test
Naseem77 Mar 4, 2025
08d899d
update locators
Naseem77 Mar 5, 2025
1b63639
update locators
Naseem77 Mar 5, 2025
6d2d286
Update codeGraph.ts
Naseem77 Mar 5, 2025
2ac1435
update test
Naseem77 Mar 5, 2025
ddf1bc6
update test
Naseem77 Mar 5, 2025
1f0ec50
add delay
Naseem77 Mar 5, 2025
32d13b5
Merge branch 'update-dependencies-version' into fix-overlapping-nodes
Naseem77 Mar 5, 2025
5cdf983
update test
Naseem77 Mar 5, 2025
f79852e
update locator
Naseem77 Mar 5, 2025
07b5c4f
update tests
Naseem77 Mar 5, 2025
09ec36c
Update codeGraph.ts
Naseem77 Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions app/components/graphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,9 @@ export default function GraphView({
const parentRef = useRef<HTMLDivElement>(null)

useEffect(() => {
setCooldownTime(4000)
setCooldownTime(2000)
setCooldownTicks(undefined)
}, [graph.Id])

useEffect(() => {
setCooldownTime(1000)
setCooldownTicks(undefined)
}, [graph.getElements().length])
}, [graph.Id, graph.getElements().length])

const unsetSelectedObjects = (evt?: MouseEvent) => {
if (evt?.ctrlKey || (!selectedObj && selectedObjects.length === 0)) return
Expand Down Expand Up @@ -133,13 +128,41 @@ export default function GraphView({
setData({ ...graph.Elements })
}

const avoidOverlap = (nodes: Array<{ x?: number; y?: number }>) => {
const spacing = NODE_SIZE * 2.5;
const validNodes = nodes.filter(node => node.x !== undefined && node.y !== undefined) as Array<{ x: number; y: number }>;

for (let i = 0; i < validNodes.length; i++) {
for (let j = i + 1; j < validNodes.length; j++) {
const nodeA = validNodes[i];
const nodeB = validNodes[j];

const dx = nodeA.x - nodeB.x;
const dy = nodeA.y - nodeB.y;
const distance = Math.sqrt(dx * dx + dy * dy) || 1;

if (distance < spacing) {
const pushStrength = (spacing - distance) / distance * 0.5;
const moveX = dx * pushStrength;
const moveY = dy * pushStrength;

nodeA.x += moveX;
nodeA.y += moveY;
nodeB.x -= moveX;
nodeB.y -= moveY;
}
}
}
};

return (
<div ref={parentRef} className="relative w-fill h-full">
<ForceGraph2D
ref={chartRef}
height={parentRef.current?.clientHeight || 0}
width={parentRef.current?.clientWidth || 0}
graphData={data}
onEngineTick={() => avoidOverlap(data.nodes)}
nodeVisibility="visible"
linkVisibility="visible"
linkCurvature="curve"
Expand Down
Loading