From 86788b748d477bfa9dca26277875639afe31b3b8 Mon Sep 17 00:00:00 2001 From: Robert Machmer Date: Sat, 9 Jan 2016 11:27:02 +0100 Subject: [PATCH] Rewrite the drawing function to take two functions as parameters These function will be called on each edge and node in the graph and allow the user to determine how the graph is drawn. --- fd/Graph.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fd/Graph.lua b/fd/Graph.lua index db157c6..75e3104 100644 --- a/fd/Graph.lua +++ b/fd/Graph.lua @@ -151,13 +151,21 @@ function Graph.new() end --- - -- This function receives a single parameter of type function to which it - -- will pass the edges and nodes tables. This means the user has to provide - -- his own drawing function. - -- @param func - The function to pass the tables to. + -- Draws the graph. + -- Takes two callback functions as a parameter. These will be called + -- on each edge and node in the graph and will be used to wite a custom + -- drawing function. + -- @param nodeCallback - A callback called on every node. + -- @param edgeCallback - A callback called on every edge. -- - function self:draw( func ) - func( edges, nodes ); + function self:draw( nodeCallback, edgeCallback ) + for _, edge in pairs( edges ) do + edgeCallback( edge ); + end + + for _, node in pairs( nodes ) do + nodeCallback( node ); + end end ---