Diagram¶
-
class
visualife.diagrams.Diagram(viewport, id, **kwargs)¶ Bases:
objectDiagrams 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,DotNodeandDiamondNodeThe 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: - viewport – (
visualife.core.HtmlViewportorvisualife.core.SvgViewport) where to draw this diagram - id – (
string) unique ID of this diagram - kwargs – see below
Keyword arguments: - autoconnect (
boolean) – if true (which is the default), nodes will be automatically connected with lines. SayFalseto globally switch autoconnect for this diagram. Connection to a particular node may be also cancelled by passingautoconnect=Falsekeyword argument toadd_node()method
Attributes Summary
idID string of this diagram. node_styleDefault style to draw nodes. text_styleDefault style to draw node text. Methods Summary
add_node(node, **kwargs)Adds a node to this diagram. connect(*what, **kwargs)Creates a Connectornode 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 drawinghighlight([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
**kwargsstyling parametersReturns: 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
**kwargsstyling parametersReturns: 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
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 – (
-
connect(*what, **kwargs)¶ Creates a
Connectornode that connects the given points.Parameters: - what – (
list(:class:`Point`)) list of points to connect - kwargs – see below
Returns: a
ConnectorinstanceKeyword Arguments: mark (
string) – a marker type; allowed parameter values are:inheritance– an arrow that marks class inheritance
- what – (
-
connect_xy(start, stop, **kwargs)¶ Adds an X-Y connector between the two given nodes.
This method connects
startandstopnodes with an X-Y connectorParameters: Returns: (
Connector) a connector instance
-
connect_yx(start, stop, **kwargs)¶ Adds an Y-X connector between the two given nodes.
This method connects
startandstopnodes with an Y-X connectorParameters: 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) ifTrue, this node will be highlighted, otherwise any highlight effectwill 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