colour.utilities.Node#

class colour.utilities.Node(*args: Any, **kwargs: Any)[source]#

Bases: object

Represent a basic node supporting the creation of basic node trees.

Parameters:
  • name – Node name.

  • parent – Parent of the node.

  • children – Children of the node.

  • data – The data belonging to this node.

  • args (Any) –

  • kwargs (Any) –

Return type:

Node

Attributes

Methods

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_a)
>>> node_d = Node("Node D", node_b)
>>> node_e = Node("Node E", node_b)
>>> node_f = Node("Node F", node_d)
>>> node_g = Node("Node G", node_f)
>>> node_h = Node("Node H", node_g)
>>> [node.name for node in node_a.leaves]
['Node H', 'Node E', 'Node C']
>>> print(node_h.root.name)
Node A
>>> len(node_a)
7

Return a new instance of the colour.utilities.Node class.

Parameters:
  • args (Any) – Arguments.

  • kwargs (Any) – Keywords arguments.

Return type:

Node

static __new__(cls, *args: Any, **kwargs: Any) Node[source]#

Return a new instance of the colour.utilities.Node class.

Parameters:
  • args (Any) – Arguments.

  • kwargs (Any) – Keywords arguments.

Return type:

Node

__init__(name: Optional[str] = None, parent: Optional[Node] = None, children: Optional[List[Node]] = None, data: Optional[Any] = None) None[source]#
Parameters:
Return type:

None

property name: str#

Getter and setter property for the name.

Parameters:

value – Value to set the name with.

Returns:

Node name.

Return type:

str

property parent: Optional[Node]#

Getter and setter property for the node parent.

Parameters:

value – Parent to set the node with.

Returns:

Node parent.

Return type:

Node or None

property children: List[Node]#

Getter and setter property for the node children.

Parameters:

value – Children to set the node with.

Returns:

Node children.

Return type:

list

property id: int#

Getter property for the node id.

Returns:

Node id.

Return type:

numpy.integer

property root: Node#

Getter property for the node tree.

Returns:

Node root.

Return type:

Node

property leaves: Generator#

Getter property for the node leaves.

Yields:

Generator – Node leaves.

property siblings: Generator#

Getter property for the node siblings.

Returns:

Node siblings.

Return type:

Generator

__weakref__#

list of weak references to the object (if defined)

property data: Any#

Getter property for the node data.

Returns:

Node data.

Return type:

object

__str__() str[source]#

Return a formatted string representation of the node.

Returns:

Formatted string representation.

Return type:

class`str`

__len__() int[source]#

Return the number of children of the node.

Returns:

Number of children of the node.

Return type:

numpy.integer

is_root() bool[source]#

Return whether the node is a root node.

Returns:

Whether the node is a root node.

Return type:

bool

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_b)
>>> node_a.is_root()
True
>>> node_b.is_root()
False
is_inner() bool[source]#

Return whether the node is an inner node.

Returns:

Whether the node is an inner node.

Return type:

bool

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_b)
>>> node_a.is_inner()
False
>>> node_b.is_inner()
True
is_leaf() bool[source]#

Return whether the node is a leaf node.

Returns:

Whether the node is a leaf node.

Return type:

bool

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_b)
>>> node_a.is_leaf()
False
>>> node_c.is_leaf()
True
walk(ascendants: bool = False) Generator[source]#

Return a generator used to walk into colour.utilities.Node trees.

Parameters:

ascendants (bool) – Whether to walk up the node tree.

Yields:

Generator – Node tree walker.

Return type:

Generator

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_a)
>>> node_d = Node("Node D", node_b)
>>> node_e = Node("Node E", node_b)
>>> node_f = Node("Node F", node_d)
>>> node_g = Node("Node G", node_f)
>>> node_h = Node("Node H", node_g)
>>> for node in node_a.walk():
...     print(node.name)
...
Node B
Node D
Node F
Node G
Node H
Node E
Node C
render(tab_level: int = 0)[source]#

Render the current node and its children as a string.

Parameters:

tab_level (int) – Initial indentation level

Returns:

Rendered node tree.

Return type:

str

Examples

>>> node_a = Node("Node A")
>>> node_b = Node("Node B", node_a)
>>> node_c = Node("Node C", node_a)
>>> print(node_a.render())
|----"Node A"
    |----"Node B"
    |----"Node C"