mirror of
https://github.com/rm-code/Graphoon.git
synced 2024-11-16 18:24:22 +00:00
Add anchor nodes
Nodes set as anchors won't be affected by the force directed layout. They can be used to fixate the graph to a certain area.
This commit is contained in:
parent
47b7624261
commit
78050c9af7
15
fd/Graph.lua
15
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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user