diff options
-rw-r--r-- | MANIFEST | 3 | ||||
-rw-r--r-- | Makefile.in | 9 | ||||
-rw-r--r-- | filters/graphviz/asciidoc-graphviz-sample.txt | 130 | ||||
-rw-r--r-- | filters/graphviz/graphviz-filter.conf | 39 | ||||
-rwxr-xr-x | filters/graphviz/graphviz2png.py | 154 |
5 files changed, 333 insertions, 2 deletions
@@ -56,6 +56,9 @@ filters/music/music2png.py filters/music/music-filter-test.txt filters/source/source-highlight-filter.conf filters/source/source-highlight-filter-test.txt +filters/graphviz/graphviz-filter.conf +filters/graphviz/graphviz2png.py +filters/graphviz/asciidoc-graphviz-sample.txt images/icons/callouts/*.png images/icons/*.png images/icons/README diff --git a/Makefile.in b/Makefile.in index 9361e0f..a4b5445 100644 --- a/Makefile.in +++ b/Makefile.in @@ -41,6 +41,11 @@ codefilterdir = $(filtersdir)/code codefilterconf = filters/code/code-filter.conf codefilterconfdir = $(filtersdir)/code +graphvizfilter = filters/graphviz/graphviz2png.py +graphvizfilterdir = $(filtersdir)/graphviz +graphvizfilterconf = filters/graphviz/graphviz-filter.conf +graphvizfilterconfdir = $(filtersdir)/graphviz + musicfilter = filters/music/music2png.py musicfilterdir = $(filtersdir)/music musicfilterconf = filters/music/music-filter.conf @@ -70,8 +75,8 @@ iconsdir = $(ASCIIDOCCONF)/images/icons doc = $(wildcard README*) $(wildcard BUGS*) $(wildcard INSTALL*) $(wildcard CHANGELOG*) docdir = $(datadir)/doc/asciidoc -DATATARGETS = manp conf docbook dblatex css js callouts icons codefilterconf musicfilterconf sourcefilterconf -PROGTARGETS = prog codefilter musicfilter +DATATARGETS = manp conf docbook dblatex css js callouts icons codefilterconf musicfilterconf sourcefilterconf graphvizfilterconf +PROGTARGETS = prog codefilter musicfilter graphvizfilter TARGETS = $(DATATARGETS) $(PROGTARGETS) doc INSTDIRS = $(TARGETS:%=%dir) diff --git a/filters/graphviz/asciidoc-graphviz-sample.txt b/filters/graphviz/asciidoc-graphviz-sample.txt new file mode 100644 index 0000000..b73fe43 --- /dev/null +++ b/filters/graphviz/asciidoc-graphviz-sample.txt @@ -0,0 +1,130 @@ += Graphviz filter for AsciiDoc = + +Author: Gouichi Iisaka + +Version: 1.0 + +== Introduction == + +Graph visualization is a way of representing structural information +as diagrams of abstract graphs and networks. + +AsciiDoc can external shell commands used to process Paragraph and +DelimitedBlock content by Filter. + + +== Simple Example == + +-------------------------------------------------------------------- + ["graphviz", "sample1.png"] + --------------------------------------------------------------------- + digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML} + --------------------------------------------------------------------- +-------------------------------------------------------------------- + +["graphviz", "sample1.png"] +--------------------------------------------------------------------- +digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML} +--------------------------------------------------------------------- + +--------------------------------------------------------------------- + ["graphviz", "sample2.png"] + --------------------------------------------------------------------- + digraph automata_0 { + size ="8.5, 11"; + node [shape = circle]; + 0 [ style = filled, color=lightgrey ]; + 2 [ shape = doublecircle ]; + 0 -> 2 [ label = "a " ]; + 0 -> 1 [ label = "other " ]; + 1 -> 2 [ label = "a " ]; + 1 -> 1 [ label = "other " ]; + 2 -> 2 [ label = "a " ]; + 2 -> 1 [ label = "other " ]; + "Machine: a" [ shape = plaintext ]; + } + --------------------------------------------------------------------- +--------------------------------------------------------------------- + +["graphviz", "sample3.png"] +--------------------------------------------------------------------- +digraph automata_0 { + size ="8.5, 11"; + node [shape = circle]; + 0 [ style = filled, color=lightgrey ]; + 2 [ shape = doublecircle ]; + 0 -> 2 [ label = "a " ]; + 0 -> 1 [ label = "other " ]; + 1 -> 2 [ label = "a " ]; + 1 -> 1 [ label = "other " ]; + 2 -> 2 [ label = "a " ]; + 2 -> 1 [ label = "other " ]; + "Machine: a" [ shape = plaintext ]; +} +--------------------------------------------------------------------- + + +-------------------------------------------------------------------- + ["graphviz", "sample4.png", "dot"] + --------------------------------------------------------------------- + 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)" ]; + } + --------------------------------------------------------------------- +-------------------------------------------------------------------- + +.Example for `dot': +["graphviz", "sample4.png", "dot"] +--------------------------------------------------------------------- +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)" ]; + } +--------------------------------------------------------------------- + + +== Layout == + +layout for graphviz as follows. + + * dot:: filter for drawing directed graphs + * neato:: filter for drawing undirected graphs + * twopi:: filter for radial layouts of graphs + * circo:: filter for circular layout of graphs + * fdp:: filter for drawing undirected graphs + +default is `dot'. + diff --git a/filters/graphviz/graphviz-filter.conf b/filters/graphviz/graphviz-filter.conf new file mode 100644 index 0000000..7fedb44 --- /dev/null +++ b/filters/graphviz/graphviz-filter.conf @@ -0,0 +1,39 @@ +# +# AsciiDoc Graphviz filter configuration file. +# +# Version: 1.0 +# Gouici Iisaka <iisaka51 at gmail dot com> + +[blockdef-listing] +graphviz-style=template="graphviz-block",subs=(),posattrs=("style","target","layout"),filter='graphviz2png.py {verbose?-v} -o "{outdir}/{target}" -L {layout=dot} -' + +ifdef::basebackend-html[] +[graphviz-block] +<div class="graphvizblock"> +<a id="{id}"></a> +<div class="title">{title}</div> +<div class="content"> +<a href="{link}"> +<img style="border-width: 0;" src="{target}" alt="{target}"{width? width="{width}"}{height? height="{height}"} /> +{link#}</a> +</div></div> +endif::basebackend-html[] + +ifdef::basebackend-docbook[] +[graphviz-block] +template::[image-blockmacro] +endif::basebackend-docbook[] + + +# +# DEPRECATED: Pre 8.2.7 filter definition. +# +[blockdef-graphviz] +delimiter=^graphviz~{4,}$ +template=graphviz-block +presubs=none +filter=graphviz2png.py {verbose?-v} -o "{outdir}/{target} -L {layout=dot}" - +posattrs=target,format +# +# DEPRECATED: End +# diff --git a/filters/graphviz/graphviz2png.py b/filters/graphviz/graphviz2png.py new file mode 100755 index 0000000..f39eef1 --- /dev/null +++ b/filters/graphviz/graphviz2png.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python +import os, sys +from optparse import * + +__AUTHOR__ = "Gouichi Iisaka <iisaka51@gmail.com>" +__VERSION__ = '1.1' + +class EApp(Exception): + '''Application specific exception.''' + pass + +class Struct: + '''variable contenor as C `struct'.''' + pass + +class Application(): + ''' +NAME + graphviz2png - Converts textual graphviz notation to PNG file + +SYNOPSIS + graphviz2png [options] INFILE + +DESCRIPTION + This filter reads Graphviz notation text from the input file + INFILE (or stdin if INFILE is -), converts it to a PNG image file. + + +OPTIONS + -o OUTFILE + The file name of the output file. If not specified the output file is + named like INFILE but with a .png file name extension. + + -v + Verbosely print processing information to stderr. + + --help, -h + Print this documentation. + + --version + Print program version number. + +SEE ALSO + graphviz(1) + +AUTHOR + Written by Gouichi Iisaka, <iisaka51@gmail.com> + +THANKS + Stuart Rackham, <srackham@gmail.com> + This script was inspired by his music2png.py and AsciiDoc + +LICENSE + Copyright (C) 2008 Gouichi Iisaka. + Free use of this software is granted under the terms of + the GNU General Public License (GPL). + ''' + + def __init__(self, argv=None): + if not argv: + argv = sys.argv + self.attrs = Struct() + self.usage_msg = '%prog [options] inputfile\n' + self.usage_msg += 'Version: %s\n' % __VERSION__ + self.usage_msg += 'Copyright(c) 2008: %s' % __AUTHOR__ + + self.option_list = [ + Option("-o", "--outfile", action="store", + dest="outfile", + help="Output file"), + Option("-L", "--layout", action="store", + dest="layout", default="dot", + help="Output file"), + Option("--debug", action="store_true", + dest="do_debug", + help=SUPPRESS_HELP), + Option("-v", "--verbose", action="store_true", + dest="do_verbose", default=False, + help="verbose output"), + Option("-V", "--version", action="store_true", + dest="do_version", + help="Print version"), + ] + + self.parser = OptionParser(option_list=self.option_list) + self.parser.set_usage(self.usage_msg) + (self.options, self.args) = self.parser.parse_args() + + if self.options.do_version: + self.parser.print_usage() + sys.exit(1) + + if len(self.args) != 1: + self.parser.print_help() + sys.exit(1) + + self.options.infile = self.args[0] + + def systemcmd(self, cmd): + if self.options.do_verbose: + msg = 'Execute: %s' % cmd + sys.stderr.write(msg + os.linesep) + else: + cmd += ' 2>/dev/null' + if os.system(cmd): + raise EApp, 'failed command: %s' % cmd + + def graphviz2png(self, infile, outfile): + '''Convert Graphviz notation in file infile to + PNG file named outfile.''' + + outfile = os.path.abspath(outfile) + outdir = os.path.dirname(outfile) + + if not os.path.isdir(outdir): + raise EApp, 'directory does not exist: %s' % outdir + + basefile = os.path.splitext(outfile)[0] + saved_cwd = os.getcwd() + os.chdir(outdir) + try: + cmd = '%s -Tpng "%s" > "%s"' % ( + self.options.layout, infile, outfile) + self.systemcmd(cmd) + os.unlink(infile) + finally: + os.chdir(saved_cwd) + + def run(self): + if self.options.infile == '-': + if self.options.outfile is None: + sys.stderr.write('OUTFILE must be specified') + sys.exit(1) + infile = os.path.splitext(self.options.outfile)[0] + '.txt' + lines = sys.stdin.readlines() + open(infile, 'w').writelines(lines) + + if not os.path.isfile(infile): + raise EApp, 'input file does not exist: %s' % infile + + if self.options.outfile is None: + outfile = os.path.splitext(infile)[0] + '.png' + else: + outfile = self.options.outfile + + self.graphviz2png(infile, outfile) + + # To suppress asciidoc 'no output from filter' warnings. + if self.options.infile == '-': + sys.stdout.write(' ') + +if __name__ == "__main__": + app = Application() + app.run() |