virtual_knitting_machine.visualizer.knitting_machine_state_visualizer module

Contains the Knitting Visualizer class.

format_svg(svg_file)[source]

Processes a given svg file and adds whitespace to make it human-readable. White space includes new lines for every tag and tabs to show which tags are within other tags. :param svg_file: The name of the svg file to reformat :type svg_file: str

class Knitting_Machine_State_Visualizer(machine_state, diagram_settings=None)[source]

Bases: object

Renders a given knitting machine state in an SVG format similar to diagrams used ACT Lab publications.

__init__(machine_state, diagram_settings=None)[source]
Parameters:
  • machine_state (Knitting_Machine_State) – The machine state to render. Should be a Knitting_Machine or a snapshot.

  • diagram_settings (Diagram_Settings) – The diagram settings for this rendering.

property needle_count: int

Returns: int: The number of needle slots rendered on this diagram.

property size: tuple[float, float]

Returns: tuple[float, float]: The size of this diagram by its width and height.

render()[source]

Render the complete visualization by building all layers.

save(filename)[source]

Save the rendered visualization to an SVG file.

Parameters:

filename (str) – Path to save the SVG file.

property min_x: float

Returns: float: The minimum x-coordinate of the viewport.