TreeNode

class visualife.diagrams.TreeNode(id, value)

Bases: object

Creates a tree node. Leaves should be appended later :param id: (string) a string that is used to identify graphical elements of this tree. ID of a node will be created as ID-idx where ID is the ID of a layout object and idx is the index of this node :param value: value stored at this node

Attributes Summary

children Returns a reference of the list of children nodes
children_deepcopy Returns a deep copy of the list of children nodes without None elements
id
parent

Methods Summary

append(n) Appends a children node i.e.
collect_leaves(root_node[, leaves]) Collects all leaves of a given tree from the left to the right :param root_node: (TreeNode) - the root of a tree :param leaves: (list) - a list where the leaves will be appended :return: the list of leaves
count_nodes() Count all the nodes of a given tree :param root_node: (TreeNode) - the root of a tree :return: the number of nodes
is_leaf()
nodes([if_update]) Returns a list of all nodes of this tree :param if_update: (boolean) - if True, the list will be collected from scratch, otherwise a cached copy is returned :return: a list of all nodes of this tree
values()

Attributes Documentation

children

Returns a reference of the list of children nodes

children_deepcopy

Returns a deep copy of the list of children nodes without None elements

id
parent

Methods Documentation

append(n)

Appends a children node i.e. a leaf to this tree

static collect_leaves(root_node, leaves=[])

Collects all leaves of a given tree from the left to the right :param root_node: (TreeNode) - the root of a tree :param leaves: (list) - a list where the leaves will be appended :return: the list of leaves

count_nodes()

Count all the nodes of a given tree :param root_node: (TreeNode) - the root of a tree :return: the number of nodes

is_leaf()
nodes(if_update=False)

Returns a list of all nodes of this tree :param if_update: (boolean) - if True, the list will be collected from scratch,

otherwise a cached copy is returned
Returns:a list of all nodes of this tree
values()