This gallery shows many examples of figures that can be rendered using Plantweb. All these examples were taken from the website of each project.
You can check the source code of this page.
For the original source of this examples or for more information and examples please visit the website of each project as shown in each section.
This section can be seen as a display of capabilities of the individual projects, but it is mostly a medium to test Plantweb Sphinx directives.
PlantUML is a component that allows to quickly write many UML diagrams using a simple and intuitive language.
For more examples and information visit the official website:
A Sequence diagram is an interaction diagram that shows how objects operate with one another and in what order.
- Wikipedia, “Sequence Diagram”.
For detailed explanation see:
A use case diagram at its simplest is a representation of a user’s interaction with the system that shows the relationship between the user and the different use cases in which the user is involved.
- Wikipedia, “Use Case Diagram”.
For detailed explanation see:
A class diagram is a type of static structure diagram that describes the structure of a system by showing the system’s classes, their attributes, operations (or methods), and the relationships among objects.
- Wikipedia, “Use Class Diagram”.
For detailed explanation see:
Activity diagrams are graphical representations of workflows of stepwise activities and actions with support for choice, iteration and concurrency. In the Unified Modeling Language, activity diagrams are intended to model both computational and organizational processes (i.e. workflows). Activity diagrams show the overall flow of control.
- Wikipedia, “Use Activity Diagram”.
For detailed explanation see:
A component diagram depicts how components are wired together to form larger components and or software systems. They are used to illustrate the structure of arbitrarily complex systems.
- Wikipedia, “Component Diagram”.
For detailed explanation see:
A state diagram, also called a state machine diagram or statechart diagram, is an illustration of the states an object can attain as well as the transitions between those states.
- TechTarget, “State Diagram”.
For detailed explanation see:
An object diagram is a graph of instances, including objects and data values. A static object diagram is an instance of a class diagram; it shows a snapshot of the detailed state of a system at a point in time. The use of object diagrams is fairly limited, namely to show examples of data structure.
- Object Management Group (2001), “UML specification 1.4”.
Graphviz is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks.
It has important applications in networking, bioinformatics, software engineering, database and web design, machine learning, and in visual interfaces for other technical domains.
For more examples and information visit the official website:
This small example illustrates dot’s feature to draw nodes and edges in clusters or separate rectangular layout regions. Clusters are encoded as subgraphs whose names have the prefix ‘cluster’. The color attribute of a cluster is interpreted as its outline color or its background color if its style is ‘filled’. Mdiamond and Msquare are modified symbols for data flow diagrams.
The graph file was generated automatically from a session with the LDBX graphical interface to the standard DBX debugger.
Nodes are drawn with the
'record'
shape. Labels of this shape are interpreted specially as nested horizontal and vertical box lists formatted as tables. In a record label, curly braces{ }
enclose lists, vertical bar|
separates list items, and creates a port identifier for attaching edges. Edges are also labeled with'id'
attributes. Though not demonstrated in this particular file, these attributes allow referencing multiple (parallel) edges between the same node pair.
This is a drawing of a finite automaton. The rankdir and orientation request a left-to-right drawing in landscape mode. Note the use of text labels on edges.
Install pip3
and tox
:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo pip3 install tox
Configure git pre-commit hook:
sudo pip3 install flake8 pep8-naming
flake8 --install-hook
git config flake8.strict true
tox -e doc
Output will be available at .tox/doc/tmp/html
. It is recommended to install
the webdev
package:
sudo pip3 install webdev
So a development web server can serve any location like this:
$ webdev .tox/doc/tmp/html
tox -e py27,py34
tox -e coverage
plantweb
¶Plantweb module entry point.
plantweb.__main__
¶plantweb executable module entry point.
plantweb.args
¶Argument management module.
parse_args()
:
Argument parsing routine.plantweb.args.
parse_args
(argv=None)¶Argument parsing routine.
Parameters: | argv – A list of argument strings. |
---|---|
Rtype argv: | list |
Returns: | A parsed and verified arguments namespace. |
Return type: | argparse.Namespace |
plantweb.defaults
¶Plantweb main rendering module.
read_defaults()
:
Get the defaults values.plantweb.defaults.
read_defaults
(cached=True)¶Get the defaults values.
Parameters: | cached (bool) – Read cached default values or determine them from
the list of providers. See DEFAULTS_PROVIDERS . |
---|---|
Returns: | A dictionary like DEFAULT_CONFIG with the user defaults. |
Return type: | dict |
plantweb.defaults.
DEFAULT_CONFIG
¶Default configuration for plantweb.
Note
The default engine will be used only when the engine was unset and it was unable to be auto-determined.
To set a different default configuration create a JSON file .plantwebrc
in your git repository root or in your home, as defined in
DEFAULTS_PROVIDERS
.
{'cache_dir': '~/.cache/plantweb',
'engine': 'plantuml',
'format': 'svg',
'server': 'http://plantuml.com/plantuml/',
'use_cache': True}
plantweb.defaults.
DEFAULTS_PROVIDERS
¶List of defaults providers ordered by read priority.
Last items will be processed last and thus will override previous values.
Available providers are:
git://
git rev-parse --show-toplevel
and then read the specified file from
that path.file://
~
is supported.python://
Will import the given variable or function:
DEFAULT_CONFIG
.['python://plantweb.defaults.DEFAULT_CONFIG',
'file://~/.plantwebrc',
'git://.plantwebrc']
plantweb.directive
¶Sphinx directives for rendering PlantUML, Graphviz and Ditaa using Plantweb.
setup()
:
Setup function that makes this module a Sphinx extension.builder_inited_handler()
:
We use this event handler to grab user defaults for Plantweb and use themdefaults_provider()
:
Defaults provider that allows to register Sphinx user defaults.plantweb.directive.
setup
(app)¶Setup function that makes this module a Sphinx extension.
See http://www.sphinx-doc.org/en/stable/extdev/appapi.html#sphinx.application.Sphinx.add_config_value
plantweb.directive.
builder_inited_handler
(app)¶We use this event handler to grab user defaults for Plantweb and use them in Plantweb rendering.
See https://plantweb.readthedocs.io/index.html#overriding-defaults
This is the handler of the ‘builder-inited’ event emitted by Sphinx.
Emitted when the builder object has been created. It is available as app.builder.
See http://www.sphinx-doc.org/en/stable/extdev/appapi.html#event-builder-inited
Plantweb
:
FIXME: Document.UmlDirective
:
Specialized uml
directive for Plantweb Plantweb
engine.GraphDirective
:
Specialized graph
directive for Plantweb graphviz
engine.DiagramDirective
:
Specialized diagram
directive for Plantweb ditaa
engine.plantweb.directive.
Plantweb
(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)¶FIXME: Document.
Inheritance
plantweb.directive.
UmlDirective
(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)¶Specialized uml
directive for Plantweb Plantweb
engine.
See Plantweb
.
Inheritance
plantweb.main
¶Application entry point module.
plantweb.render
¶Plantweb main rendering module.
render_file()
:
Render given PlantUML, Graphviz or DITAA file.render()
:
Render given PlantUML, Graphviz or DITAA content.render_cached()
:
Render given content in the PlantUML server or fetch it from cache.determine_engine()
:
Determine the engine used in the given content.plantweb.render.
render_file
(infile, outfile=None, renderopts=None, cacheopts=None)¶Render given PlantUML, Graphviz or DITAA file.
Parameters: |
|
---|---|
Returns: | Path to output file. |
Return type: |
plantweb.render.
render
(content, engine=None, format=None, server=None, cacheopts=None)¶Render given PlantUML, Graphviz or DITAA content.
Parameters: |
|
---|---|
Returns: | A tuple of |
Return type: |
plantweb.render.
render_cached
(server, format, content, use_cache=None, cache_dir=None)¶Render given content in the PlantUML server or fetch it from cache.
Parameters: |
|
---|---|
Returns: | A tuple of |
Return type: |
plantweb.render.
determine_engine
(content)¶Determine the engine used in the given content.
The engine is determined by the @startXXX
used at the beginning of the
file. Possible values are:
@startuml --> plantuml
@startdot --> graphviz
@startditaa --> ditaa
Parameters: | content (str) – Content to analyze. |
---|---|
Returns: | The name of the engine found, or None. |
Return type: | str |
Plantweb is a project that provides a command line interface, Sphinx directives and an API that allows to render powerful plain text UML diagrams, ASCII diagrams and complex graphs.
It is a Python client for the PlantUML server and thus it can render PlantUML, Graphviz and Ditaa diagrams without the need to install them.
Check out the Examples Gallery.
Plantweb features a local cache that prevents requesting the server for previously rendered diagrams, speeding up building documentation with lots of diagrams.
Finally, being pure Python, non-local rendering, Plantweb is an excellent way to display and render PlantUML, Graphviz and Ditaa diagrams in ReadTheDocs published documentation.
In particular, Ditaa rendering is particularly usefull when using ASCII drawing tools like asciiflow.
sudo pip3 install plantweb
If the content of your file is wrapped by @startxxx
, @endxxx
then
Plantweb is capable of determining the engine to use.
Options are:
Opening | Closure | Engine |
---|---|---|
@startuml |
@enduml |
plantuml |
@startdot |
@enddot |
graphviz |
@startditaa |
@endditaa |
ditaa |
For example, the following Graphviz file mydotfile.dot
:
@startdot
digraph one_node_graph {
node1 -> node2 -> node3
}
@enddot
Can be rendered with:
user@host:~$ plantweb mydotfile.dot
Note
File extensions are irrelevant for Plantweb.
If for some reason your files lack the @startxxx/@endxxx
wrapper you can
still render the file by specifying the engine:
user@host:~$ plantweb --engine=graphviz unwrappeddotfile.dot
Complete options:
user@host:~$ plantweb --help
usage: plantweb [-h] [-v] [--version]
[--engine {auto,plantuml,graphviz,ditaa}]
[--format {auto,svg,png}] [--server SERVER] [--no-cache]
[--cache-dir CACHE_DIR]
sources [sources ...]
Python client for the PlantUML server
positional arguments:
sources source files to render
optional arguments:
-h, --help show this help message and exit
-v, --verbose increase verbosity level
--version show program's version number and exit
--engine {auto,plantuml,graphviz,ditaa}
engine to use to render diagram
--format {auto,svg,png}
diagram export format
--server SERVER server to use for rendering
--no-cache do not use cache
--cache-dir CACHE_DIR
directory to store cached renders
New in version 0.4.0.
Plantweb provides 3 Sphinx directives for rendering diagrams:
.. uml::
Allows to render the content using the PlantUML engine.
Warning
This directive overrides the one provided by sphinxcontrib.plantuml
.
.. graph::
Allows to render the content using the Graphviz engine.
Warning
This directive overrides the one provided by sphinx.ext.graphviz
.
.. diagram::
Note
When using the directives it is NOT recommended nor required to use the
@startxxx
/ @endxxx
tags.
For example:
.. uml::
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
The above will render:
See also
Check out the Examples Gallery.
New in version 1.0.0.
Directives also support specifying a path to a file to load the content.
For example:
.. uml:: my_uml_diagram.uml
The above will load the file my_uml_diagram.uml
with the content to be
rendered.
You may specify a relative path from the current document or you may specify an
absolute path from where the conf.py
like this:
.. uml:: /diagrams/my_uml_diagram.uml
The above will load the file from the Sphinx documentation root.
alt
: textalign
: “left”, “center”, or “right”The alignment of the image. It control an image’s horizontal alignment, allowing the image to float and have the text flow around it.
Warning
This behavior could be changed by your theme.
target
: text (URI or reference name)name_
).For example:
.. uml::
:alt: This is a nice UML diagram. Indeed.
:align: left
:target: #options
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
Render as:
Warning
Plantweb directives doesn’t have any height
, width
or scale
options. In this age of responsive design there shouldn’t be the need to
define presentational values in the content. Also, being diagrams, you
should always maximize viewing space.
If your images overflow, override your theme or use a theme that already supports responsive images:
/* Responsive images */
object[type="image/svg+xml"], img {
max-width: 100%;
height: auto;
}
To enable the directives add 'plantweb.directive'
to your extensions in
your Sphinx’s conf.py
:
extensions = [
# ... More extensions,
'plantweb.directive'
]
If you want to configure the extension you can create the variable
plantweb_defaults
in your Sphinx’s conf.py
:
# Plantweb configuration
plantweb_defaults = {
'server': 'http://myserver.com/plantuml/'
}
Please note that the above configuration will have the higher priority as
explained in Overriding Defaults. Nevertheless the defaults resolution mechanism
is still considered, that is, the .plantwebrc
files will still override
other keys if present.
There are 2 main functions, both Python 2.7 and 3.5 compatible:
render()
allows to render content directly.
from plantweb.render import render
CONTENT = """
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
"""
if __name__ == '__main__':
print('==> INPUT:')
print(CONTENT)
output = render(
CONTENT,
engine='plantuml',
format='svg',
cacheopts={
'use_cache': False
}
)
print('==> OUTPUT:')
print(output)
render_file()
allows to render files.
from plantweb.render import render_file
CONTENT = """
digraph finite_state_machine {
rankdir=LR;
size="8,5"
node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
node [shape = circle];
LR_0 -> LR_2 [ label = "SS(B)" ];
LR_0 -> LR_1 [ label = "SS(S)" ];
LR_1 -> LR_3 [ label = "S($end)" ];
LR_2 -> LR_6 [ label = "SS(b)" ];
LR_2 -> LR_5 [ label = "SS(a)" ];
LR_2 -> LR_4 [ label = "S(A)" ];
LR_5 -> LR_7 [ label = "S(b)" ];
LR_5 -> LR_5 [ label = "S(a)" ];
LR_6 -> LR_6 [ label = "S(b)" ];
LR_6 -> LR_5 [ label = "S(a)" ];
LR_7 -> LR_8 [ label = "S(b)" ];
LR_7 -> LR_5 [ label = "S(a)" ];
LR_8 -> LR_6 [ label = "S(b)" ];
LR_8 -> LR_5 [ label = "S(a)" ];
}
"""
if __name__ == '__main__':
infile = 'mygraph.dot'
with open(infile, 'wb') as fd:
fd.write(CONTENT.encode('utf-8'))
print('==> INPUT FILE:')
print(infile)
outfile = render_file(
infile,
renderopts={
'engine': 'graphviz',
'format': 'png'
},
cacheopts={
'use_cache': False
}
)
print('==> OUTPUT FILE:')
print(outfile)
New in version 0.3.0.
The defaults defined in DEFAULT_CONFIG
will be used unless overridden
by the user.
To set a different default configuration create a JSON file .plantwebrc
in your git repository root or in your home, as defined in
DEFAULTS_PROVIDERS
.
For example:
{
"server": "http://mydomain.com/plantuml/",
"cache_dir": "~/.cache/plantweb",
"engine": "plantuml",
"format": "svg",
"use_cache": true
}
See also
If you require:
Please consider running a PlantUML server in your local network or private server. The easiest way is to do it is using the official PlantUML Docker image:
docker pull plantuml/plantuml-server
docker run --detach --publish 8080:8080 plantuml/plantuml-server
For more information about the PlantUML server visit:
The public PlantUML server used by Plantweb by default is run by a group of volunteers for pure love.
Please consider donating to the project through Paypal, Patreon or Flattr.
sphinx.ext.inheritance_diagram
that
also uses Graphviz to use Plantweb.Copyright (C) 2016-2017 Carlos Jenkins
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Logo derived from work by VisciousSpeed under Public Domain.