Diagram

class visualife.diagrams.Diagram(viewport, id, **kwargs)

Bases: object

Diagrams made out of rectangular shapes, possibly connected with lines.

This class is intended to draw algorithm, UML or flow diagrams. Its methods allow easy placement of a few kinds of nodes: RectNode, DotNode and DiamondNode

The nodes may be connected by the following connector types:

  • directly
  • X-Y – connecting line goes first along X axis and then along Y axis to reach the end point
  • Y-X – connecting line goes first along Y axis and then along X axis to reach the end point
Parameters:
Keyword arguments:
 
  • autoconnect (boolean) – if true (which is the default), nodes will be automatically connected with lines. Say False to globally switch autoconnect for this diagram. Connection to a particular node may be also cancelled by passing autoconnect=False keyword argument to add_node() method

Attributes Summary

id ID string of this diagram.
node_style Default style to draw nodes.
text_style Default style to draw node text.

Methods Summary

add_node(node, **kwargs) Adds a node to this diagram.
connect(*what, **kwargs) Creates a Connector node that connects the given points.
connect_xy(start, stop, **kwargs) Adds an X-Y connector between the two given nodes.
connect_yx(start, stop, **kwargs) Adds an Y-X connector between the two given nodes.
draw(viewport, **kwargs) Draws all nodes of this diagram :param viewport: a viewport to draw nodes of this diagram :param kwargs: keyword arguments passed to visualife.diagrams.NodeBase.draw() method to style the drawing
highlight([state]) Removes or set highlight effect on all nodes of this diagram.
max_x() Returns maximum X coordinate of all elements of this diagram
max_y() Returns maximum Y coordinate of all elements of this diagram

Attributes Documentation

id

ID string of this diagram.

This string is used e.g. to create unique IDs for this diagram’s connectors :return: string

node_style

Default style to draw nodes.

A change to this dictionary will affect any nodes drawn after this call unless a node style has been overridden with **kwargs styling parameters

Returns:dict
text_style

Default style to draw node text.

A change to this dictionary will affect any nodes drawn after this call unless a node style has been overridden with **kwargs styling parameters

Returns:dict

Methods Documentation

add_node(node, **kwargs)

Adds a node to this diagram.

This method can also connect the newly added node to the reference node

Parameters:
  • node – (NodeBase) a node to be added to this diagram
  • kwargs – see below
Returns:

a Connector object if the added node is connected to another node, None otherwise

Keyword arguments:
 
  • center_at (Point) – where to place the center of the node (x, y coordinates)
  • below (Point) – place the node argument below the given node, e.g. another RectNode or a Point. The placed node will be centered in respect to the reference node
  • right_below (NodeBase) – place the node argument below the given node, e.g. a RectNode The placed node will be right-justified in respect to the reference node
  • left_below (NodeBase) – place the node argument below the given node, e.g. a RectNode The placed node will be left-justified in respect to the reference node
  • above (Point) – place the newly created box above the given node, e.g. another RectNode or a Point. The placed node will be centered in respect to the reference node
  • left_of (Point) – place the argument node on the left of the given node, e.g. another RectNode or a Point
  • right_of (Point) – place the argument node on the right of the given node, e.g. another RectNode or a Point
  • dx (number) – a horizontal space left between two nodes when a relative placement is used; also the length of a linker for horizontal connections (right_of=, left_of=)
  • dy (number) – a vertical space left between two nodes when a relative placement is used; length of a linker for vertical connections such as (below=, above=)
  • autoconnect (bool) – if True (and this is the default), this method also create a connecting line i.e. creates an appropriate Connector instance. autoconnect works only if the new node is placed below, right_of or left_of another node. Say autoconnect=False to switch it off for one this behavior.
  • connect_xy (Point) – connect this box with a given Point in the X-Y manner
  • connect_yx (Point) – connect this box with a given Point in the Y-X manner
  • shift_by (Point) – a translation vector to be added to
connect(*what, **kwargs)

Creates a Connector node that connects the given points.

Parameters:
  • what – (list(:class:`Point`)) list of points to connect
  • kwargs – see below
Returns:

a Connector instance

Keyword Arguments:
 
  • mark (string) – a marker type; allowed parameter values are:

    • inheritance – an arrow that marks class inheritance
connect_xy(start, stop, **kwargs)

Adds an X-Y connector between the two given nodes.

This method connects start and stop nodes with an X-Y connector

Parameters:
  • start – (Point) start point of the connector
  • stop – (Point) end point of the connector
Returns:

(Connector) a connector instance

connect_yx(start, stop, **kwargs)

Adds an Y-X connector between the two given nodes.

This method connects start and stop nodes with an Y-X connector

Parameters:
  • start – (Point) start point of the connector
  • stop – (Point) end point of the connector
Returns:

(Connector) a connector instance

draw(viewport, **kwargs)

Draws all nodes of this diagram :param viewport: a viewport to draw nodes of this diagram :param kwargs: keyword arguments passed to visualife.diagrams.NodeBase.draw() method to style the drawing

highlight(state=True)

Removes or set highlight effect on all nodes of this diagram.

Parameters:state – (boolean) if True, this node will be highlighted, otherwise any highlight effect

will be cancelled

max_x()

Returns maximum X coordinate of all elements of this diagram

Returns:maximum X coordinate of any element of this diagram
max_y()

Returns maximum Y coordinate of all elements of this diagram

Returns:maximum Y coordinate of any element of this diagram