addons

colorbar

This module aims to create an horizontal node colorbar that can be easily attached to a dot graph. This node is created as a HTML table of 3 rows and multiple columns. Each column contains the interpolation two color segment for the given colorscheme.

rnets.addons.colorbar.Attribute

Type synonym to define the attributes of an HTML table.

Type:

type

rnets.addons.colorbar.OPEN_MARK

Open HTML character.

Type:

str

rnets.addons.colorbar.CLOSE_MARK

Close HTML character.

Type:

str

rnets.addons.colorbar.ATTR_SEPARATOR

HTML attribute separator character.

Type:

str

rnets.addons.colorbar.ATTR_ASSIGN

HTML assignement character.

Type:

str

class rnets.addons.colorbar.ColorbarCfg(n_interp: int | None = 100, width: int = 1, height: int = 20, border: bool = False, cellspacing: int = -1, node_name: str = 'Colorbar', fillcolor: Color = (1.0, 1.0, 1.0), anchor: str | None = None)[source]

Structure representing the colorbar configuration.

n_interp

Number of color segments. Defaults to 100.

Type:

int, optional

width

Width of each color segment, in HTML table units. Defaults to 1.

Type:

int, optional

height

Height of the colorbar, in HTML table units. Defaults to 20.

Type:

int, optional

cellspacing

Space between the different color segments in HTML table units. Keep a negative value to ensure uniform perception. Defaults to -1.

Type:

int, optional

node_name

Name of the generated node. Defaults to Colorbar.

Type:

str, optional

fillcolor

Color of the node. Defaults to white.

Type:

Color, optional

anchor_node

Node to anchor the colorbar. Defaults to None

Type:

str or None

class rnets.addons.colorbar.Item(name: str, attributes: Attribute | None, contains: Sequence[Item] | str | None)[source]

HTML element.

name

Name of the HTML element.

Type:

str

attributes

Attributes of the HTML element.

Type:

Attribute or None

contains

Items or values inside the HTML element.

Type:

Sequence of item or str or None

rnets.addons.colorbar.attr_to_str(attr: Attribute, separator: str = ATTR_SEPARATOR, assign: str = ATTR_ASSIGN) str[source]

Converts the given attribute into a str.

Parameters:
  • attr (attribute) -- Attribute to be converted.

  • separator (str, optional) -- Separator between the different attribute options. Defaults to ATTR_SEPARATOR.

  • assign (str, optional) -- Assignment operator. Defaults to ATTR_ASSIGN.

Returns:

KEY:"VALUE"

Return type:

str of the attribute with the given format

rnets.addons.colorbar.build_body(color_fn: Callable[[float], Color], n_interp: int, width: int, height: int) Item[source]

Build the entire colorbar row.

Parameters:
  • color_fn (Callable[[float], Color]) -- Color interpolation function.

  • n_interp (int) -- Number of columns.

  • width (int) -- Width of the segment, in HTML table units.

  • height (int) -- Height of the segment, in HTML table units.

Returns:

Item of the generated row.

rnets.addons.colorbar.build_color_segment(cs: Color, Color, width: int, height: int) Item[source]

Given a pair of Color, build a HTML cell containing an horizontal gradient.

Parameters:
  • cs (Color, Color) -- Color pair that will be interpolated in the segment.

  • width (int) -- Width of the segment, in HTML table units.

  • height (int) -- Height of the segment, in HTML table units.

Returns:

Item of the generated segment.

rnets.addons.colorbar.build_colorbar(color_fn: Callable[[float], Color], c_ran: tuple[float, float] | None, cfg: ColorbarCfg, title: str | None = 'Energy') Node[source]

Given a ColorbarCfg build the associated graphviz Node.

Parameters:
  • color_fn (function) -- Color interpolation function. It should take a float between [0,1] and return an Color

  • c_ran (tuple of two floats, optional) -- Minimum and maximum energy values. Defaults to None

  • cfg (ColorbarCfg) -- Configuration used to build the colorbar.

  • title (str, optional) -- Title of the colorbar. Defaults to None.

Returns:

Node built from the given configuration.

rnets.addons.colorbar.build_node(item: Item, name: str, fillcolor: Color) Node[source]

Given an Item, create a dot node using the str form of the item as a the node label.

Parameters:
  • item (item) -- Item that will be converted into a Node.

  • name (str, optional) -- Name of the generated node.

  • fillcolor (Color) -- Color of the node.

Returns:

Node built node using the str form of the item as the label.

rnets.addons.colorbar.build_tail(c_min: float, c_max: float) Item[source]

Build the tail of the colorbar marking the starting, mid and final energy values. Always places 2 decimal values.

Parameters:
  • c_min (float) -- Minimum energy value.

  • c_max (float) -- Maximum energy value.

Returns:

HTML row with the start, mid and end values of the energy.

rnets.addons.colorbar.item_to_str(item: Item | None, separator: str = '\n') str[source]

Convert an item into a string.

Parameters:
  • item (Item or None) -- Item to be converted.

  • separator (str) -- Separator between the different contains.

Returns:

str with the HTML form of the item.