drawing.DrawBackend

class rewalt.drawing.DrawBackend(**params)

Bases: ABC

Abstract drawing backend for placing nodes, wires, arrows, and labels on a canvas.

The purpose of this class is simply to describe the signature of methods that subclasses have to implement.

Keyword Arguments
  • bgcolor (multiple types) – The background colour (default is 'white').

  • fgcolor (multiple types) – The foreground colour (default is 'black').

  • orientation (str) – Orientation: one of 'bt' (bottom-to-top), 'lr' (left-to-right), 'tb' (top-to-bottom), 'rl' (right-to-left) (default is 'bt').

Notes

All coordinates should be passed to the backend as if the orientation was bottom-to-top; the backend will then make rotations and adjustments according to the chosen orientation.

Methods

draw_arrow(xy0, xy1, **params)

Draws an arrow on the canvas.

draw_label(label, xy, offset, **params)

Draws a label next to a location on the canvas.

draw_node(xy, **params)

Draws a node on the canvas.

draw_wire(wire_xy, node_xy, **params)

Draws a wire from a wire vertex to a node vertex on the canvas.

output(**params)

Output the picture.

rotate(xy)

Returns coordinates rotated according to the orientation of the picture.

draw_wire(wire_xy, node_xy, **params)

Draws a wire from a wire vertex to a node vertex on the canvas.

Parameters
  • wire_xy (tuple[float]) – The coordinates of the wire vertex.

  • node_xy (tuple[float]) – The coordinates of the node vertex.

Keyword Arguments
  • color (multiple types) – The colour of the wire (default is self.fgcolor).

  • alpha (float) – Alpha factor of the wire (default is 1).

  • depth (bool) – Whether to draw the wire with a contour, to simulate “crossing over” objects that are already on the canvas (default is True).

draw_label(label, xy, offset, **params)

Draws a label next to a location on the canvas.

Parameters
  • label (str) – The label.

  • xy (tuple[float]) – The coordinates of the object to be labelled.

  • offset (tuple[float]) – Point offset of the label relative to the object.

Keyword Arguments

color (multiple types) – The colour of the label (default is self.fgcolor).

draw_node(xy, **params)

Draws a node on the canvas.

Parameters

xy (tuple[float]) – The coordinates of the node.

Keyword Arguments
  • color (multiple types) – Fill colour of the node (default is self.fgcolor).

  • stroke (multiple types) – Stroke colour of the node (default is same as color).

draw_arrow(xy0, xy1, **params)

Draws an arrow on the canvas.

Parameters
  • xy0 (tuple[float]) – The coordinates of the starting point.

  • xy1 (tuple[float]) – The coordinates of the ending point.

Keyword Arguments
  • color (multiple types) – Colour of the arrow (default is self.fgcolor).

  • shorten (float) – Factor by which to scale the length (default is 1).

output(**params)

Output the picture.

Keyword Arguments
  • show (bool) – Whether to show the output (default is True).

  • path (str) – Path where to save the output (default is None).

  • scale (float) – (TikZ only) Scale factor to apply to output (default is 3).

  • xscale (float) – (TikZ only) Scale factor to apply to x axis in output (default is same as scale)

  • yscale (float) – (TikZ only) Scale factor to apply to y axis in output (default is same as scale)

rotate(xy)

Returns coordinates rotated according to the orientation of the picture.

Parameters

xy (tuple[float]) – The coordinates to rotate.

Returns

rotate – The rotated coordinates.

Return type

tuple[float]