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 );
|
nodeA:attractTo( attractionPoint );
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, nodeB in pairs( nodes ) do
|
if not nodeA:isAnchor() then
|
||||||
if nodeA ~= nodeB then
|
for _, nodeB in pairs( nodes ) do
|
||||||
nodeA:repelFrom( nodeB );
|
if nodeA ~= nodeB then
|
||||||
|
nodeA:repelFrom( nodeB );
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
nodeA:move( dt );
|
||||||
end
|
end
|
||||||
nodeA:move( dt );
|
|
||||||
|
|
||||||
minX, maxX, minY, maxY = updateBoundaries( minX, maxX, minY, maxY, nodeA:getPosition() );
|
minX, maxX, minY, maxY = updateBoundaries( minX, maxX, minY, maxY, nodeA:getPosition() );
|
||||||
end
|
end
|
||||||
@ -213,6 +215,11 @@ function Graph.new()
|
|||||||
return ( ( maxX - minX ) * 0.5 ) + minX, ( ( maxY - minY ) * 0.5 ) + minY;
|
return ( ( maxX - minX ) * 0.5 ) + minX, ( ( maxY - minY ) * 0.5 ) + minY;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function self:setAnchor( id, x, y )
|
||||||
|
nodes[id]:setPosition( x, y );
|
||||||
|
nodes[id]:setAnchor( true );
|
||||||
|
end
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ function Node.new( id, name, x, y )
|
|||||||
local self = {};
|
local self = {};
|
||||||
|
|
||||||
local name = name or id;
|
local name = name or id;
|
||||||
|
local anchor = false;
|
||||||
local px, py = x or 0, y or 0;
|
local px, py = x or 0, y or 0;
|
||||||
local ax, ay = 0, 0;
|
local ax, ay = 0, 0;
|
||||||
local vx, vy = 0, 0;
|
local vx, vy = 0, 0;
|
||||||
@ -100,6 +101,14 @@ function Node.new( id, name, x, y )
|
|||||||
px, py = nx, ny;
|
px, py = nx, ny;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function self:setAnchor( nanchor )
|
||||||
|
anchor = nanchor;
|
||||||
|
end
|
||||||
|
|
||||||
|
function self:isAnchor()
|
||||||
|
return anchor;
|
||||||
|
end
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user