Code Monkey home page Code Monkey logo

blockdiag's Introduction

blockdiag generate block-diagram image file from spec-text file.

GitHub Action CI build status Latest PyPI version Number of PyPI downloads

Features

  • Generate block-diagram from dot like text (basic feature).
  • Multilingualization for node-label (utf-8 only).

You can get some examples and generated images on blockdiag.com .

Setup

Use pip:

$ sudo pip install blockdiag

If you want to export as PDF format, give pdf arguments:

$ sudo pip install "blockdiag[pdf]"

Copy and modify ini file. example:

$ cp <blockdiag installed path>/blockdiag/examples/simple.diag .
$ vi simple.diag

Please refer to spec-text setting sample section for the format of the simpla.diag configuration file.

spec-text setting sample

Few examples are available. You can get more examples at blockdiag.com .

simple.diag

simple.diag is simply define nodes and transitions by dot-like text format:

diagram admin {
  top_page -> config -> config_edit -> config_confirm -> top_page;
}

screen.diag

screen.diag is more complexly sample. diaglam nodes have a alternative label and some transitions:

diagram admin {
  top_page [label = "Top page"];

  foo_index [label = "List of FOOs"];
  foo_detail [label = "Detail FOO"];
  foo_add [label = "Add FOO"];
  foo_add_confirm [label = "Add FOO (confirm)"];
  foo_edit [label = "Edit FOO"];
  foo_edit_confirm [label = "Edit FOO (confirm)"];
  foo_delete_confirm [label = "Delete FOO (confirm)"];

  bar_detail [label = "Detail of BAR"];
  bar_edit [label = "Edit BAR"];
  bar_edit_confirm [label = "Edit BAR (confirm)"];

  logout;

  top_page -> foo_index;
  top_page -> bar_detail;

  foo_index -> foo_detail;
               foo_detail -> foo_edit;
               foo_detail -> foo_delete_confirm;
  foo_index -> foo_add -> foo_add_confirm -> foo_index;
  foo_index -> foo_edit -> foo_edit_confirm -> foo_index;
  foo_index -> foo_delete_confirm -> foo_index;

  bar_detail -> bar_edit -> bar_edit_confirm -> bar_detail;
}

Usage

Execute blockdiag command:

$ blockdiag simple.diag
$ ls simple.png
simple.png

Requirements

  • Python 3.7 or later
  • Pillow 3.0 or later
  • funcparserlib 1.0.0a0 or later
  • reportlab (optional)
  • wand and imagemagick (optional)
  • setuptools

License

Apache License 2.0

blockdiag's People

Contributors

aboehm avatar adschellevis avatar cdevienne avatar dreamsorcerer avatar dridi avatar flying-foozy avatar gchriz avatar ggrossetie avatar legoktm avatar msnoigrs avatar nakamuray avatar nejch avatar rmoro avatar shimizukawa avatar shirou avatar surgo avatar tk0miya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockdiag's Issues

href attribute and LineJumpDrawFilter

groupにhref属性を付けてSVG出力したときに、リンク生成される機能が、v0.8.4の後に新しく導入された LineJumpDrawFilter のために、うまく働かなくなっています。href属性はドキュメントに書かれてはいないので、正確にはバグとは言えませんが。

{ group {href="http://www.google.co.jp"; A; }}


actdiag maxwidth directive producing blank thumbnails

I have been using actdiag to successfully create diagrams. However, when using actdiag with the :maxwidth: 700 directive the resulting pages are created with a blank thumbnail. The full diagram is still generated and is visible by clicking on the blank thumbnail. No error is shown on the command during the make, full diagram is attached.


Import PIL components from the ``PIL`` namespace instead of the global namespace

Currently the blockdiag code imports the PIL components directly from the global namespace which normally works because PIL mangles the modules there.

However, this mangling may not always work (e.g. when using zc.buildout to setup an environment) which results in import errors. Importing the PIL components explicitly from the PIL namespace allows the imports to work regardless of the mangling.

The attached patch fixes the issue.


Problem when creating diagram

I have the following text:

#!dot

diagram G { 
        comganzttuserserviceBindVillageSvc [ label = " 
                \n  
                BindVillageSvc\n
                --------------------------\n
                this is a very long text that was wroten by shekespare becuase he...
            "    
        ]    

        comganzttuserserviceBindVillageSvc -> comganzgsfserviceLocalService [label = "Extends"];
}

but when running the command:

#!bash

blockdiag pepe.diag

I get the following exception:

#!python

Traceback (most recent call last):
  File "/home/tzulberti/envs/uml/bin/blockdiag", line 9, in <module>
    load_entry_point('blockdiag==0.7.8', 'console_scripts', 'blockdiag')()
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/blockdiag.py", line 623, in main
    draw.draw()
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/DiagramDraw.py", line 105, in draw
    self.node(node, **kwargs)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/DiagramDraw.py", line 240, in node
    font=self.font, badgeFill=self.badgeFill)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/noderenderer/__init__.py", line 54, in render
    self.render_label(drawer, **kwargs)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/noderenderer/__init__.py", line 68, in render_label
    lineSpacing=self.metrix.lineSpacing)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/ImageDrawEx.py", line 251, in textarea
    lines = TextFolder(box, string, scale=self.scale_ratio, **kwargs)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/utils/PILTextFolder.py", line 23, in __init__
    TextFolder.__init__(self, box, string, **kwargs)
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/utils/TextFolder.py", line 88, in __init__
    self._result = self._lines()
  File "/home/tzulberti/envs/uml/lib/python2.6/site-packages/blockdiag-0.7.8-py2.6.egg/blockdiag/utils/TextFolder.py", line 183, in _lines
    if size[1] < height + metrics[1]:
UnboundLocalError: local variable 'metrics' referenced before assignment

"icon" is no rendered by the latest version 1.2.[034].

Here is a sample:

#!blockdiag

{
back [background="http://www.apache.org/images/feather-small.gif"];
icon [icon="http://www.apache.org/images/feather-small.gif"];
}

Interactive shell:
http://goo.gl/p5Rpv

Here is a patch:

--- __init__py- Wed Dec 19 17:59:44 2012
+++ __init__.py Fri Jan 11 16:16:26 2013
@@ -101,7 +101,7 @@
         self.render_number_badge(drawer, **kwargs)

     def render_icon(self, drawer, **kwargs):
-        if self.node.icon is not None and kwargs.get('shadow') is False:
+        if self.node.icon is not None and kwargs.get('shadow') is not True;
             drawer.image(self.iconbox, self.node.icon)

     def render_shape(self, drawer, _, **kwargs):

notes duplicated with autoreturn

if you put a note on an autoreturn item, the note appears twice, once for the request and once for the response. It would be good to either only have the note appear once, or be able to specify different notes for requests and responses.


Add setting for diagram background color

Currently it appears to be only possible to set the background color for nodes. It would be nice to be able to set the background color of the image itself. This is particularly helpful when the image is to be embedded elsewhere and where the normally-transparent background does not render properly (e.g. the blurry drop-shadows don't look good when overlaid on a color background).


Multiple node labels

We have some hosts which are known by multiple names. Currently we have to use something like:

hostname [address=1.2.3.4,label="hostname\nalternative1\nalternative2"]}}}
{{{hostname [address=1.2.3.4,label="hostname\nalternative1\nalternative2"]

This difficult to read, and violates DRY. Something like:

hostname [address=1.2.3.4,alternative_names="alternative1,alternative2"]}}}
{{{hostname [address=1.2.3.4,alternative_names="alternative1,alternative2"]

Buildout ends with both PIL and Pillow installed

On GNU/Linux-systems, I have a buildout-part that fetches Pillow, since I don't want to use PIL:


[extra]
recipe = zc.recipe.egg
dependent-scripts = true
interpreter = py

eggs =
Pillow
sphinxcontrib-blockdiag


This buildout ends having both

  • PIL-1.1.7-py2.6-linux-i686.egg
  • Pillow-1.7.6-py2.6-linux-i686.egg/

Pillow should be pulled in before sphinxcontrib-blockdiag.
I see the setup.py already tries to take Pillow into account.
But Pillow is available when the buildout is finished running.


文字化け:WindowsでのPILのFontの取り扱いによる文字化け

http://d.hatena.ne.jp/tanakahisateru/20081008/1223450159

"PIL(Python Image Libraly)で日本語フォント使おうとすると、ラスタライズ結果がぐちゃぐちゃになることがある。これはハマった。

つぶれる条件はどうやら、ビットマップを持つフォントのビットマップが適用される場合のようだ。ビットマップが適用されないぐらい十分大きいサイズで描いて、それを目的のサイズに縮小して問題を回避。アンチエイリアスされた文字を得るのが目的ならこれでOK。"

scaleを3倍に設定すれば化けずに描画されることを確認しました。ひどいパッチを添付します。


Fonts not rendering properly in PNG output

Recently, I have noticed that all my PNG diagrams are not rendering the fonts properly; they are cropping the fonts so that only the top parts of all the characters are visible. SVG output is fine. I have attached three files: a test actdiag source, and the PNG and SVG output from it.

Here is details of my environment:

  • Mac OSX 10.8.5

  • Python 2.7.6

  • actdiag 0.5.1

  • Pillow 2.2.2

  • freetype 2.5.2

  • graphviz 2.34.0

  • Sphinx 1.2

  • sphinxcontrib-actdiag 0.6.0 (not used for test; used actdiag directly)

What other information can I provide to help solve this problem?


collapsing groups

It would be nice to be able to flag a group to be collapsed.

This could be done in creating the config file, but in very complex diagrams, having to figure out what connections elsewhere in the config file need to be re-pointed to the group is non-trivial

This is especially useful on network diagrams as it allows you to have the full network in the configuration and then 'zoom out' to get a higher level view without having to craft a different config file.


Poor PNG image quality

There is no control for png image output quality. The default Windows output png quality is very poor.

Proposal:

  • Increase the output resolution (DPI), posible as an option in configuration

blockdiag-0.8.9: AttributeError: 'ImageDrawEx' object has no attribute 'textsize'

with
blockdiag-0.8.9-py2.7.egg
sphinxcontrib_blockdiag-0.9.0-py2.7.egg

using the example in the sphinx-docs
.. blockdiag::

diagram admin {
  top_page -> config -> config_edit -> config_confirm  -> top_page;
}

results in following traceback:

Sphinx version: 1.0.7

Python version: 2.7.2

Docutils version: 0.8 release

Jinja2 version: 2.6

Traceback (most recent call last):
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/cmdline.py", line 188, in main
app.build(force_all, filenames)
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/application.py", line 207, in build
self.builder.build_update()
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/builders/init.py", line 198, in build_update
'out of date' % len(to_build))
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/builders/init.py", line 254, in build
self.write(docnames, list(updated_docnames), method)
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/builders/init.py", line 294, in write
self.write_doc(docname, doctree)
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/builders/html.py", line 408, in write_doc
self.docwriter.write(doctree, destination)
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/writers/init.py", line 77, in write
self.translate()
File "/opt/dev/sphinx/lib/python2.7/site-packages/Sphinx-1.0.7-py2.7.egg/sphinx/writers/html.py", line 38, in translate
self.document.walkabout(visitor)
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/nodes.py", line 173, in walkabout
if child.walkabout(visitor):
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/nodes.py", line 173, in walkabout
if child.walkabout(visitor):
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/nodes.py", line 173, in walkabout
if child.walkabout(visitor):
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/nodes.py", line 165, in walkabout
visitor.dispatch_visit(self)
File "/opt/dev/sphinx/lib/python2.7/site-packages/docutils-0.8-py2.7.egg/docutils/nodes.py", line 1604, in dispatch_visit
return method(node)
File "/opt/dev/sphinx/lib/python2.7/site-packages/sphinxcontrib_blockdiag-0.9.0-py2.7.egg/sphinxcontrib/blockdiag.py", line 298, in html_visit_blockdiag
render_dot_html(self, node, node['code'], node['options'])
File "/opt/dev/sphinx/lib/python2.7/site-packages/sphinxcontrib_blockdiag-0.9.0-py2.7.egg/sphinxcontrib/blockdiag.py", line 196, in render_dot_html
image.save()
File "/opt/dev/sphinx/lib/python2.7/site-packages/blockdiag-0.8.9-py2.7.egg/blockdiag/DiagramDraw.py", line 283, in save
return self.drawer.save(self.filename, size, self.format)
File "/opt/dev/sphinx/lib/python2.7/site-packages/blockdiag-0.8.9-py2.7.egg/blockdiag/imagedraw/filters/linejump.py", line 158, in save
self._run()
File "/opt/dev/sphinx/lib/python2.7/site-packages/blockdiag-0.8.9-py2.7.egg/blockdiag/imagedraw/filters/linejump.py", line 89, in _run
method(self.target, *args, **kwargs)
File "/opt/dev/sphinx/lib/python2.7/site-packages/blockdiag-0.8.9-py2.7.egg/blockdiag/imagedraw/png.py", line 280, in textarea
self.text(xy, string, **kwargs)
File "/opt/dev/sphinx/lib/python2.7/site-packages/blockdiag-0.8.9-py2.7.egg/blockdiag/imagedraw/png.py", line 251, in text
size = self.textsize(string)
AttributeError: 'ImageDrawEx' object has no attribute 'textsize'


Implement legend syntax to describe styles and notations

Implement legend syntax to describe styes and notations.
For example::

legend {
  standard;
  popup [style = dashed, color = pink];
  A -> B [label = "standard link"];
  C -> D [label = "popup", style = dashed];
}

FYI; an example for describe using normal blockdiag syntax::

{
  A [label = "from page"];
  B [label = "to page"];
  C [label = "from page"];
  D [label = "popup page", style=dashed, color=pink];

  group {
    label = "legends";
    color = "#77FF77";
    A -> B [label="standard link"];
    C -> D [label="popup", style=dashed];
  }
}

This issue is proposaled from @RenoIV .
http://twitter.com/renoiv/statuses/95783378695098368


It is possible to adjust size of png generated ?

Hi,

In next scheme there are ips which are not shown completly, is there any configuration option (I didn't find in your examples) to make bigger the background ?

Look up at net2 => ip of fwdes01 ( I attach png associated):

{

network net1 {
address = "10.189.247.128/26"

  fwdes01 [address = "10.189.247.129"];

}
network net2 {
address = "10.189.247.0/26";

  fwdes01 [address = "10.189.247.100"];

}
network net3 {
address = "10.188.6.224/27";

  fwdes01 [ address = "10.188.6.228" ];

}
network net4 {
address = "192.168.4.0/25";
fwdes01 [ address = "192.168.4.51" ];
}
network net5 {
address = "192.168.4.0/26";
fwdes01 [ address = "192.168.4.55" ];
}
}

Thank you!


Direct edges?

Hi,

Sometimes is confuse read which node goes to which node through edge.

I'm thinking if it is possible to add a new syntax which generate a "direct edge" (a straight line)

A --> B (with two dashes)

See this diagram where is dificult to know which nodes are connected E node:

{
A -> B;
A -> C;
D -> C;
D -> B;
E -> B;
E -> C;
}

Thanks !


seqdiag, label and -T pdf

Hi,

it seems there is a problem with seqdiag 0.8.2 and the usage of label. I can create png file without problem, but if I try to create a pdf file, I get:

ERROR: 'NoneType' object has no attribute 'stringWidth'

I have no clue, what is going wrong. With blockdiag there are no problems...

It happens even with this:

setdiag {
browser -> server [ label = "GET / HTTP/1.0" ];
}

The png is ok, the pdf shows the above error message and no file is created.

Best regards

Dirk


blockdiag.imagedraw.png.ImageDrawExBase: Cannot use image attribute together with image() method

The class above has an image attribute and an image() method. The later defined one overrides the earlier one in the classes dict. Therefore, attributes must have a different name compared to methods. You need to rename one of the two, for example rename image attribute to image_ (and hunt for all the used places outside the class).

In addition, the image() method has another problem. It uses an unknown variable name in its exception handling (OOPS, handled exception leads to another unintended exception):

#!python
...
def image(self):
    ...
    msg = "WARNING: Could not retrieve: &#37;s\n" &#37; filename
    # SHOULD-BE: filename parameter is undefined.
    msg = "WARNING: Could not retrieve: &#37;s\n" &#37; url

Note that I stumbled over the same problem in other files, too. You should basically check for the filename pattern above or use the background hint from below to detect all places.

BACKGROUND:
After providing seqdiag issue #12, I applied pychecker and pylint to blockdiag. This was one of the issues.


specific fonts hard-coded in detectfont

I changes hard-coded font path to the glob pattern paths for Debian.

"/usr/local/share/font-ipa/ipagp.otf" is include ttf-ipafont-gothic that is old package, this package was changed fonts-ipafont-gothic, the path was changed "/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf", too.

And fonts-ipafont-gothic is not necessarily to be installed.

Fix path ipagp.ttf, change detect glob pattern.
Because the package has changed ttf-ipafont-gothic to fonts-ipafont-gochic,
and not case installed fonts-ipafont-gothic.
Index: blockdiag-1.1.4/src/blockdiag/utils/bootstrap.py
===================================================================
--- blockdiag-1.1.4.orig/src/blockdiag/utils/bootstrap.py	2012-02-13 18:59:29.000000000 +0900
+++ blockdiag-1.1.4/src/blockdiag/utils/bootstrap.py	2012-04-14 13:17:48.066795947 +0900
@@ -181,13 +181,21 @@
 
 
 def detectfont(options):
-    fonts = ['c:/windows/fonts/VL-Gothic-Regular.ttf',  # for Windows
-             'c:/windows/fonts/msgothic.ttf',  # for Windows
-             'c:/windows/fonts/msgoth04.ttc',  # for Windows
-             '/usr/share/fonts/truetype/ipafont/ipagp.ttf',  # for Debian
-             '/usr/local/share/font-ipa/ipagp.otf',  # for FreeBSD
-             '/Library/Fonts/Hiragino Sans GB W3.otf',  # for MacOS
-             '/System/Library/Fonts/AppleGothic.ttf']  # for MacOS
+    fonts = [
+             # for Windows
+             'c:/windows/fonts/VL-Gothic-Regular.ttf',
+             'c:/windows/fonts/msgothic.ttf',
+             'c:/windows/fonts/msgoth04.ttc',
+             # for FreeBSD
+             '/usr/local/share/font-ipa/ipagp.otf',
+             # for MacOS
+             '/Library/Fonts/Hiragino Sans GB W3.otf',
+             '/System/Library/Fonts/AppleGothic.ttf']
+
+    # fot Debian
+    import glob
+    for f in glob.glob('/usr/share/fonts/truetype/*/*.ttf'):
+        fonts.append(f)
 
     fontpath = None
     if options.font:

regards,


sphinxcontrib-seqdiag has issues with font loading

Used Versions:

sphinxcontrib-seqdiag: 0.5.0
seqdiag: 0.8.1

When sphinxcontrib-seqdiag calls command.detectfont an AttributeError is raised, since seqdiag.command does not import blockdiag.utils.bootstrap.detectfont. The Exception is immediately caught by the mechanism used to handle problems during font loading and a "cannot load font warning" is issued. Of course the font isn't set and the default is used.


Size limit on http://interactive.blockdiag.com/seqdiag/

arrows collisions

Hi,

I have an issue with diagrams like this one :

{
b -> c -> d;
b <- d [style=dashed] ;
}

You can test it here : http://interactive.blockdiag.com/

In the text I have no arrow from c to b but in the resulting diagram, it seems there is one because the arrow from d to b is "merged" with the arrow from b to c.

Have you any advise to avoid this "fake" arrow ? I tried to fold an arrow, change the shape, etc. but withou any luck.

Thank you for your help,
Pascal.


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.