- graph
- Node
- __init__
- id
- set_value
- value
- incident_edges
- incoming_edges
- outgoing_edges
- adjacent_nodes
- predecessor_nodes
- successor_nodes
- degree
- indegree
- outdegree
- set_attribute
- attribute
- set_priority
- priority
- set_position
- position
- set_label
- label
- set_size
- size
- set_color
- color
- set_value_style
- set_label_style
- highlight
- Edge
- Miscellaneous functions
graph
add_node
graph.add_node(id) # (1)
graph.add_node(id, value) # (2)
-
Adds a node to the graph with the
id
andvalue
set toid
.Argument Accepted Types id
str
,int
orfloat
-
Adds a node to the graph with the
id
andvalue
set to their corresponding arguments.Argument Accepted Types id
str
,int
orfloat
value
str
,int
orfloat
remove_node
graph.remove_node(node)
Removes the node with the specified id from the graph.
Argument | Accepted Types |
---|---|
|
|
node
graph.node(id) # (1)
graph.node(node) # (2)
-
Returns the
Node
object of the node with the specifiedid
. Raises aNodeDoesntExistError
if that node could not be found in the graph.Argument Accepted Types id
str
,int
orfloat
-
Returns the
Node
object of theNode
object given to it as long as that node is in the graph. Raises aNodeDoesntExistError
if that node could not be found in the graph.Argument Accepted Types node
Node
nodes
graph.nodes()
Returns a list of all the nodes currently in the graph as Node
objects.
add_edge
graph.add_edge(source, target, weight="", directed=False) # (1)
Adds an edge between the source
and target
nodes. To make the edge directed, set directed
to True
. weight
sets the label of the edge.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|
|
|
remove_edge
graph.remove_edge(nodeA, nodeB, directed=False)
Removes the edge(s) between nodeA
and nodeB
from the graph. If directed
is set, only edges starting at nodeA
will be removed.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|
has_node
graph.has_node(node)
Checks if a given node
exists in the graph.
Argument | Accepted Types |
---|---|
|
|
has_edge
graph.has_edge(edge)
Checks if a given edge
exists in the graph.
Argument | Accepted Types |
---|---|
|
|
add
graph.add(element)
Adds the specified element to the graph. Can either be a Node
object, or an Edge
object. Raises an error if the element has been added to the graph before.
Argument | Accepted Types |
---|---|
|
|
remove
graph.remove(element)
Removes the specified element from the graph. Can either be a Node
or an Edge
object, and will return said object.
Argument | Accepted Types |
---|---|
|
|
add_all
graph.add_all(elements)
Adds all Node
and/or Edge
objects in a list to the graph.
Argument | Accepted Types |
---|---|
|
A list (iterable) containing |
remove_all
graph.remove_all(elements)
Removes all Node
and/or Edge
objects in a list from the graph.
Argument | Accepted Types |
---|---|
|
A list (iterable) containing |
adjacent
graph.adjacent(nodeA, nodeB, directed=False)
Checks if nodeA
and nodeB
are adjacent. If directed
is set, then the edge must start from nodeA
.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|
clear
graph.clear()
Completely resets the graph by removing all edges and nodes.
set_directed
graph.set_directed(directed=True)
Sets whether the edges in the graph are directed or not.
Argument | Accepted Types |
---|---|
|
|
order
graph.order()
Returns the order of the graph. That is, it returns the number of nodes in the graph.
size
graph.size()
Returns the size of the graph. That is, it returns the number of edges in the graph.
adjacency_matrix
graph.adjacency_matrix()
Returns the adjacency matrix of the graph as a dictionary.
Node
__init__
Node(id, value=id)
Creates a node with the specified id
and value
. If value
is left blank, it defaults to the node’s id
.
Argument | Accepted Types |
---|---|
|
|
|
|
id
node.id()
Returns the id of the node.
set_value
node.set_value(value)
Sets the value of the node.
Argument | Accepted Types |
---|---|
|
|
value
node.value()
Gets the value of the node.
incident_edges
node.incident_edges()
Returns a list of the node’s incident edges.
incoming_edges
node.incoming_edges()
Returns a list of the node’s incoming edges.
outgoing_edges
node.outgoing_edges()
Returns a list of the node’s outgoing edges.
adjacent_nodes
node.adjacent_nodes()
Returns a list of the node’s adjacent nodes.
predecessor_nodes
node.predecessor_nodes()
Returns a list of the node’s predecessor nodes.
successor_nodes
node.successor_nodes()
Returns a list of the node’s successor nodes.
degree
node.degree()
Returns the node’s degree.
indegree
node.indegree()
Returns the node’s indegree.
outdegree
node.outdegree()
Returns the node’s outdegree.
set_attribute
node.set_attribute(name, value)
Sets custom attributes for the node.
Argument | Accepted Types |
---|---|
|
|
|
|
attribute
node.attribute(name)
Gets custom attributes for the node.
Argument | Accepted Types |
---|---|
|
|
set_priority
node.set_priority(value)
Sets the node’s priority value.
Argument | Accepted Types |
---|---|
|
|
priority
node.priority()
Gets the node’s priority value.
set_position
node.set_position(x, y)
Sets the node’s position on the canvas. Uses relative positions whereby (0, 0) is the bottom-left corner and (1, 1) is the top-right corner.
Argument | Accepted Types |
---|---|
|
|
|
|
position
node.position()
Returns the node’s position that was set. Note that it will not return the position of the node if it has not been set. Returns the position as a list with the format [x, y]
.
set_label
node.set_label(value, label_id=0)
Sets additional labels for the node. The labels do not override the node’s value, but instead are placed next to the node.
Argument | Accepted Types |
---|---|
|
|
|
One of either |
label
node.label(label_id)
Gets additional labels for the node. The labels do not override the node’s value, but instead are placed next to the node.
Argument | Accepted Types |
---|---|
|
One of either |
set_size
node.set_size(size=12)
Sets the radius of the node.
Argument | Accepted Types |
---|---|
|
|
size
node.size()
Gets the radius of the node.
set_color
node.set_color(color=Color.DARK_GREY)
Sets the node’s color.
Argument | Accepted Types |
---|---|
|
|
color
node.color()
Gets the node’s color.
set_value_style
node.set_value_style(size=13, color=Color.WHITE)
Sets the appearance of the node’s value text.
Argument | Accepted Types |
---|---|
|
|
|
|
set_label_style
node.set_label_style(size=10, color=Color.GREY, label_id=0)
Sets the appearance of the node’s label text.
Argument | Accepted Types |
---|---|
|
|
|
|
|
One of either |
highlight
node.highlight(color=Color.RED, size=node.size()*1.5)
Plays a highlight animation where the node’s color changes to that specified.
Argument | Accepted Types |
---|---|
|
|
|
|
Edge
__init__
Edge(source, target, weight="", directed=False)
Creates an edge between the source
and target
nodes. If weight
is set, the edge will display it as a label. If directed
is set, the edge will be directed, starting at the source
node.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|
|
|
source
edge.source()
Returns the edge’s source node.
target
edge.target()
Returns the edge’s target node.
set_weight
edge.set_weight(weight=None)
Sets the weight of the edge.
Argument | Accepted Types |
---|---|
|
|
weight
edge.weight()
Returns the weight of the edge.
set_directed
edge.set_directed(directed=True)
Sets whether the edge is directed.
Argument | Accepted Types |
---|---|
|
|
directed
edge.directed()
Returns whether the edge is directed or not.
other_node
edge.other_node(node)
Returns the node connected by the edge that isn’t the node specified.
Argument | Accepted Types |
---|---|
|
|
set_attribute
edge.set_attribute(name, value)
Sets custom attributes for the edge.
Argument | Accepted Types |
---|---|
|
|
|
|
attribute
edge.attribute(name)
Gets custom attributes for the edge.
Argument | Accepted Types |
---|---|
|
|
set_priority
edge.set_priority(value)
Sets the edge’s priority value.
priority
edge.priority()
Gets the edge’s priority value.
Argument | Accepted Types |
---|---|
|
|
set_width
edge.set_width(width=2)
Sets the edge’s width/thickness.
Argument | Accepted Types |
---|---|
|
|
width
edge.width()
Gets the edge’s width/thickness.
set_color
edge.set_color(color=Color.LIGHT_GREY)
Sets the edge’s color.
Argument | Accepted Types |
---|---|
|
|
color
edge.color()
Returns the edge’s color.
set_weight_style
edge.set_weight_style(size=10, color=Color.GREY)
Sets the appearance of the edge’s weight label.
Argument | Accepted Types |
---|---|
|
|
|
|
highlight
edge.highlight(color=edge.color(), width=edge.width()*2)
Performs a highlight animation by temporarily changing the width and color of the edge.
Argument | Accepted Types |
---|---|
|
|
|
|
traverse
edge.traverse(initial_node=edge.source(), color=Color.RED, keep_path=True)
Performs a traversal animation on the edge, beginning at initial_node
, using the specified color. If keep_path
is set, the edge will remain colored.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|
Miscellaneous functions
Color
Color(red, green, blue)
Custom colour for use in node and edge animations, using 0-255
integers for each argument.
There are some predefined colours:
Color.RED
, Color.GREEN
, Color.BLUE
, Color.YELLOW
, Color.WHITE
, Color.LIGHT_GREY
, Color.GREY
, Color.DARK_GREY
, Color.BLACK
, Color.TRANSPARENT
You can also create colours from their hex values by using the from_hex_int
method. The hex value needs to be entered as a number in python (this is what the 0x
does in the snippet below). The hex value needs to be 6 digits long.
# creates a blue colour
Color.from_hex_int(0x0055ff)
pause
pause(time)
Delays the next visual event for the specified number of milliseconds.
Note
|
This does not pause code execution. |
alert
alert(message)
Displays the message as an alert notification on the PyNode Next interface.
delay
delay(func, time, args=[], repeat=False)
Runs the function after the specified number of milliseconds, with the optional args
list of arguments for the func
. If repeat
is set to true, the function will run repeatedly (with the specified time delay) until cancelled. Returns the delay_id
of the delay.
Argument | Accepted Types |
---|---|
|
Any function |
|
|
|
A |
|
|
cancel_delay
cancel_delay(delay_id)
Cancels the specified delay.
Argument | Accepted Types |
---|---|
|
A delay ID returned from the |
register_click_listener
register_click_listener(func)
Registers a function that will be called when a node is clicked.
Argument | Accepted Types |
---|---|
|
|
begin_pynode_next
begin_pynode_next(func, open_browser=True, check_for_new_version=True)
Begins PyNode Next.
And loads the func
to run when the play button is pressed in the interface.
If open_browser
is set to true, it will automatically open the PyNode Next interface in the default browser.
If check_for_new_version
is set to true, it will check if there is a new version of PyNode Next version available.
Argument | Accepted Types |
---|---|
|
|
|
|
|
|