mirror of
https://github.com/rm-code/Graphoon.git
synced 2025-01-02 14:54:20 +00:00
Extend graph constructor to handle node tables
The nodes can either be a sequence of strings or a sequence of tables containing id, name, x and y values.
This commit is contained in:
parent
2a258a96d5
commit
47b7624261
@ -54,9 +54,13 @@ function Graph.new()
|
|||||||
function self:create( table, x, y, w, h )
|
function self:create( table, x, y, w, h )
|
||||||
math.randomseed( os.time() );
|
math.randomseed( os.time() );
|
||||||
|
|
||||||
for _, id in pairs( table.nodes ) do
|
for _, node in pairs( table.nodes ) do
|
||||||
local rx, ry = math.random( x, w ), math.random( y, h );
|
local rx, ry = math.random( x, w ), math.random( y, h );
|
||||||
self:addNode( id, nil, rx, ry );
|
if type( node ) == 'string' then
|
||||||
|
self:addNode( node, nil, rx, ry );
|
||||||
|
elseif type( node ) == 'table' then
|
||||||
|
self:addNode( node.id, node.name, node.x or rx, node.y or ry );
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, edge in pairs( table.edges ) do
|
for _, edge in pairs( table.edges ) do
|
||||||
|
Loading…
Reference in New Issue
Block a user