diff --git a/fd/Graph.lua b/fd/Graph.lua index 11d1ab0..0a2f024 100644 --- a/fd/Graph.lua +++ b/fd/Graph.lua @@ -148,12 +148,14 @@ function Graph.new() nodeA:attractTo( attractionPoint ); end - for _, nodeB in pairs( nodes ) do - if nodeA ~= nodeB then - nodeA:repelFrom( nodeB ); + if not nodeA:isAnchor() then + for _, nodeB in pairs( nodes ) do + if nodeA ~= nodeB then + nodeA:repelFrom( nodeB ); + end end + nodeA:move( dt ); end - nodeA:move( dt ); minX, maxX, minY, maxY = updateBoundaries( minX, maxX, minY, maxY, nodeA:getPosition() ); end @@ -213,6 +215,11 @@ function Graph.new() return ( ( maxX - minX ) * 0.5 ) + minX, ( ( maxY - minY ) * 0.5 ) + minY; end + function self:setAnchor( id, x, y ) + nodes[id]:setPosition( x, y ); + nodes[id]:setAnchor( true ); + end + return self; end diff --git a/fd/Node.lua b/fd/Node.lua index 2af1235..b1ae6e7 100644 --- a/fd/Node.lua +++ b/fd/Node.lua @@ -16,6 +16,7 @@ function Node.new( id, name, x, y ) local self = {}; local name = name or id; + local anchor = false; local px, py = x or 0, y or 0; local ax, ay = 0, 0; local vx, vy = 0, 0; @@ -100,6 +101,14 @@ function Node.new( id, name, x, y ) px, py = nx, ny; end + function self:setAnchor( nanchor ) + anchor = nanchor; + end + + function self:isAnchor() + return anchor; + end + return self; end