InteractiveDiagram

class visualife.diagrams.InteractiveDiagram(viewport, id)

Bases: visualife.diagrams.Diagram

Diagram that can execute code snippets

This class is devised to draw interactive algorithm diagrams on a web page.

Parameters:
  • viewport – where to actually draw the line
  • id – (string) unique ID of this diagram

Attributes Summary

next_command Returns the text command that will be executed by this diagram

Methods Summary

add_node(node, **attrs) Adds a node to this diagram.
add_start(*location, **attrs) Add a START node of a block diagram
add_stop(*location, **attrs) Add a STOP node of a block diagram
declare_variables(**kwargs)
get_value(name)
globals_copy()
has_next() True if there is more commands to be executed
list_variables()
locals_copy()
next([if_debug]) Executes the next node of this diagram
set_value(name, value)
start()

Attributes Documentation

next_command

Returns the text command that will be executed by this diagram

Returns:(InteractiveNode) a node that will be executed by the incomming next() method call

Methods Documentation

add_node(node, **attrs)

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
add_start(*location, **attrs)

Add a START node of a block diagram

Parameters:
  • xc – (number) x coordinate
  • yc – (number) y coordinate
  • attrs – see below
Returns:

InteractiveNode

Keyword Arguments:
 
  • text_style (string) – a dictionary holding style settings for text
  • node_style (string) – a style for drawing
add_stop(*location, **attrs)

Add a STOP node of a block diagram

Parameters:
  • location – (number, number) x and y coordinates of the middle of the stop node
  • attrs – see below
Returns:

InteractiveNode

Keyword Arguments:
 
  • text_style (string) – a dictionary holding style settings for text
  • node_style (string) – a style for drawing
declare_variables(**kwargs)
get_value(name)
globals_copy()
has_next()

True if there is more commands to be executed

Returns:(boolean)
list_variables()
locals_copy()
next(if_debug=False)

Executes the next node of this diagram

The executed node will be highlighted, the previous node will be turned back to its normal color and the code snippet that is associated to the entered node will be executed by a Python interpreter

Param:if_debug (boolean) if true, this method will print debug info on the console
Returns:(boolean) True when the algorithm reached its end
set_value(name, value)
start()