virtual_knitting_machine.visualizer.visualizer_elements.visualizer_group module

Module containing the Visualizer_Group class.

class Visualizer_Group(x, y, name)[source]

Bases: Visualizer_Element

A wrapper for SVG Groups. The coordinate position of the group is used to set each of its children to a relative position.

children

A list of Visualizer_Element objects that are children of the group.

Type:

set[Visualizer_Element]

__init__(x, y, name)[source]
add_child(child)[source]

Add the given child element as a sub element to this element. :param child: The child element to add. :type child: Visualizer_Element

__getitem__(element_id)[source]
Parameters:

element_id (str) – The id of the element to retrieve.

Returns:

The retrieved element.

Return type:

Visualizer_Element

Raises:

KeyError – The element does not exist in this group.

__contains__(element_id)[source]
Parameters:

element_id (str) – The id of a sub-element to this element.

Returns:

True if this element contains a sub element with the given id. False otherwise.

Return type:

bool

add_to_drawing(drawing)

Adds this element to the given svg drawing. :param drawing: The drawing to add. :type drawing: Drawing

static darken_color(color='none', factor=0.7)

Darken a hex or named color.

Parameters:
  • color (str) – The color to darken. Either a named color or a hex representation of the color.

  • factor (float, optional) –

    A factor to darken. Defaults to 0.7.

    • 0.0 = No change.

    • 1.0 = black.

Returns:

The color-string of the darkened color. If “none” color is given, this will return “black”.

Return type:

str

static fill_from_stroke(stroke, lighten_factor=0.3)
Parameters:
  • stroke (str) – The color string of the stroke to be lightened for infill.

  • lighten_factor (float, optional) – The factor to lighten the stroke color by. Defaults to 0.3.

Returns:

The fill color string created by lightening the stroke color.

Return type:

str

property global_x: float

Returns: float: The global x coordinate of this element based on its parent’s coordinates.

global_x_position(x)
Parameters:

x (float) – An X-coordinate position relative to this element’s coordinate system.

Returns:

The x-coordinate adjusted to the global coordinate system.

Return type:

float

property global_y: float

Returns: float: The global y coordinate of this element based on its parent’s coordinates.

global_y_position(y)
Parameters:

y (float) – An Y-coordinate position relative to this element’s coordinate system.

Returns:

The y-coordinate adjusted to the global coordinate system.

Return type:

float

static lighten_color(color='none', factor=0.3)

Lighten a hex or named color.

Parameters:
  • color (str, optional) – The color to lighten. Either a named color or a hex representation of the color. Defaults to transparent (“none”).

  • factor (float, optional) –

    A factor to lighten (0.0 to 1.0). Defaults to 0.3.

    • 0.0 = no change.

    • 1.0 = white.

Returns:

The color-string of the lightened color. If “none” color is given, this will return “black”.

Return type:

str

property name: str

Returns: str: The unique name of this element. This will match the id of the svg element being wrapped.

static stroke_from_fill(fill, darken_factor=0.7)
Parameters:
  • fill (str) – The color string of the fill to be darkened for an outline.

  • darken_factor (float, optional) – The factor to darken the fill color by. Defaults to 0.7.

Returns:

The stroke color string created by darkening the fill color.

Return type:

str

property x: float

Returns: float: The x coordinate of this element relative to its parent (or globally).

property y: float

Returns: float: The y coordinate of this element relative to its parent (or globally).