virtual_knitting_machine.visualizer.visualizer_elements.visualizer_element module
Module containing the Visualizer Element class and common primitive subclasses.
- class Visualizer_Element(x, y, name, **element_kwargs)[source]
Bases:
objectSuper class for all visualizer element wrappers that support coordinate checking and transformation.
- parent
The optional parent element of this element used to find global coordinate position.
- Type:
Visualizer_Element | None
- property name: str
Returns: str: The unique name of this element. This will match the id of the svg element being wrapped.
- 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).
- property global_x: float
Returns: float: The global x coordinate of this element based on its parent’s coordinates.
- property global_y: float
Returns: float: The global y coordinate of this element based on its parent’s coordinates.
- add_to_drawing(drawing)[source]
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)[source]
Darken a hex or named color.
- Parameters:
- Returns:
The color-string of the darkened color. If “none” color is given, this will return “black”.
- Return type:
- class Text_Anchor(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of Text Anchoring options for text elements
- start = 'start'
- middle = 'middle'
- end = 'end'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Text_Baseline(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of Text Anchoring options for text elements
- baseline = 'baseline'
- middle = 'middle'
- hanging = 'hanging'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Text_Element(x, y, label, name=None, font_family='Arial', font_size=14, is_bold=False, is_italic=False, text_anchor=Text_Anchor.middle, alignment_baseline=Text_Baseline.middle, font_color='black', **element_kwargs)[source]
Bases:
Visualizer_ElementWrapper class for Text SVG elements.
- __init__(x, y, label, name=None, font_family='Arial', font_size=14, is_bold=False, is_italic=False, text_anchor=Text_Anchor.middle, alignment_baseline=Text_Baseline.middle, font_color='black', **element_kwargs)[source]
Initialize the text element. :param x: The x coordinate of this element relative to its parent (or globally). :type x: float :param y: The y coordinate of this element relative to its parent (or globally). :type y: float :param label: The value of the text label. :type label: str :param name: The id name of this element defaults to “label_<label>”. :type name: str, optional :param font_family: The font family to render the text in. Defaults to “Arial”. :type font_family: str, optional :param font_size: The font size to render the text in. Defaults to 14px height. :type font_size: int, optional :param is_bold: Whether the text is bold. Defaults to False. :type is_bold: bool, optional :param is_italic: Whether the text is italic. Defaults to False. :type is_italic: bool, optional :param text_anchor: The anchor to render the text in. Defaults to “middle”. :type text_anchor: str, optional :param **element_kwargs: Keyword arguments used to configure the svg text element. :type **element_kwargs: Any
- property approximate_label_width: float
- Returns:
The approximate width of the text label.
- Return type:
Notes
Very rough estimate: ~0.6 * font_size per character for typical fonts.
- static approximate_text_width(char_count, font_size=14)[source]
- Parameters:
- Returns:
The approximate width of the text based on the number of characters.
- Return type:
Notes
Very rough estimate: ~0.6 * font_size per character for typical fonts.
- 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:
- Returns:
The color-string of the darkened color. If “none” color is given, this will return “black”.
- Return type:
- static fill_from_stroke(stroke, lighten_factor=0.3)
- property global_x: float
Returns: float: The global x coordinate of this element based on its parent’s coordinates.
- global_x_position(x)
- property global_y: float
Returns: float: The global y coordinate of this element based on its parent’s coordinates.
- global_y_position(y)
- static lighten_color(color='none', factor=0.3)
Lighten a hex or named color.
- Parameters:
- Returns:
The color-string of the lightened color. If “none” color is given, this will return “black”.
- Return type:
- 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)