Diagram

A Diagram consists of one or more elements.

class visigoth.Diagram(title='', description='', fill=None, margin_left=50, margin_right=50, margin_top=50, margin_bottom=50, spacing=20)

Represent a diagram contining one or more maps and other elements

Keyword Arguments:
 
  • title (str) – title string to add to the output document
  • description (str) – description to place in the output document
  • fill (str) – background colour for the diagram
  • margin_top (int) – margin around the top of the diagram
  • margin_bottom (int) – margin around the bottom of the diagram
  • margin_left (int) – margin around the left of the diagram
  • margin_right (int) – margin around the right of the diagram
  • spacing (int) – spacing between elements in pixels

A way you might use me is:

>>> d = Diagram(fill="white")
>>> from visigoth.common.text import Text
>>> d.add(Text("Hello World!")
>>> print(d.draw()) # print the svg to the console
add(element)

Add an element to the diagram

Parameters:element (visigoth.common.DiagramElement) – the element to add
Returns:the Diagram object

Notes:

addStyle(style)

Add CSS styles to the diagram

Parameters:style (str) –
Returns:the Diagram object
setDefaultTextAttributes(text_attributes)

Define default attributes for text displayed in the diagram

Parameters:text_attributes (dict) – dict containing SVG name,value attributes to apply to text by default
Returns:the Diagram object

Notes

default attributes are overridden by those defined on diagram elements

setFontEmbedding(embed)

Enable or disable font embedding

Parameters:embed (bool) – whether to embed fonts or link to them

Notes

By default fonts are not embedded into the output SVG but are linked from google’s servers. Fonts should be embedded if you want content to render correctly when offline or when the SVG file is to be rendered as an image. If enabled, only fonts that were used will be embedded.

connect(source, source_channel, dest, dest_channel, adapter_function='function(event) { return event; }')

Connect two elements in the diagram with a channel to allow one to receive events sent by the other

Parameters:
  • source (visigoth.common.DiagramElement) – the element emitting events
  • source_channel (str) – the name of the channel sending events from the source
  • dest (visigoth.common.DiagramElement) – the element receiving events
  • dest_channel (str) – the name of the channel recieving events to the destination
  • adapter_function (str) – a definition for a javascript function which transforms the event as it is dispatched to the destination
Returns:

the Diagram object

draw(format='svg', html_title='', include_footer=True)

Draw the diagram to create an SVG document

Keyword Arguments:
 
  • format (str) – the format of the output file, either “svg” or “html”
  • html_title (str) – the title for the document valid for format=”html”
  • include_footer (bool) – whether to include a footer with project/github repo links
Returns:

a string containing the document in the requested format