InteractiveDiagram¶
-
class
visualife.diagrams.InteractiveDiagram(viewport, id)¶ Bases:
visualife.diagrams.DiagramDiagram 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_commandReturns 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()Trueif there is more commands to be executedlist_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 incommingnext()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
Connectorobject if the added node is connected to another node,NoneotherwiseKeyword 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. anotherRectNodeor aPoint. 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. aRectNodeThe 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. aRectNodeThe 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. anotherRectNodeor aPoint. 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. anotherRectNodeor aPoint - right_of (
Point) – place the argument node on the right of the given node, e.g. anotherRectNodeor aPoint - 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) – ifTrue(and this is the default), this method also create a connecting line i.e. creates an appropriateConnectorinstance. autoconnect works only if the new node is placed below, right_of or left_of another node. Sayautoconnect=Falseto switch it off for one this behavior. - connect_xy (
Point) – connect this box with a givenPointin the X-Y manner - connect_yx (
Point) – connect this box with a givenPointin the Y-X manner - shift_by (
Point) – a translation vector to be added to
- node – (
-
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: Keyword Arguments: - text_style (
string) – a dictionary holding style settings for text - node_style (
string) – a style for drawing
- xc – (
-
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: Keyword Arguments: - text_style (
string) – a dictionary holding style settings for text - node_style (
string) – a style for drawing
- location – (
-
declare_variables(**kwargs)¶
-
get_value(name)¶
-
globals_copy()¶
-
has_next()¶ Trueif there is more commands to be executedReturns: ( 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 consoleReturns: ( boolean)Truewhen the algorithm reached its end
-
set_value(name, value)¶
-
start()¶