util::inline_svg_from_dot (public)

 util::inline_svg_from_dot [ -css css ] dot_code

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Transform a dot source code into an inline svg image based on code from xotcl-core; should be probably made more configurable in the future.

Switches:
-css (optional)
Parameters:
dot_code (required)
grapviz dot code
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
%3 Class ::xowiki::includelet::references-graph Class ::xowiki::includelet::references-graph (public) util::inline_svg_from_dot util::inline_svg_from_dot Class ::xowiki::includelet::references-graph->util::inline_svg_from_dot api_proc_documentation api_proc_documentation (public) api_proc_documentation->util::inline_svg_from_dot packages/xotcl-core/www/show-object.tcl packages/xotcl-core/ www/show-object.tcl packages/xotcl-core/www/show-object.tcl->util::inline_svg_from_dot ad_file ad_file (public) util::inline_svg_from_dot->ad_file ad_tmpdir ad_tmpdir (public) util::inline_svg_from_dot->ad_tmpdir util::which util::which (public) util::inline_svg_from_dot->util::which

Testcases:
No testcase defined.
Source code:
        catch {set dot [::util::which dot]}
        if {$dot ne ""} {
            set dir [ad_tmpdir]/oacs-dotcode
            if {![ad_file isdirectory $dir]} {
                file mkdir $dir
            }
            #
            # Cache file in the filesystem based on an MD5 checksum
            # derived from the dot source-code, the format and the
            # styling.
            #
            # TODO: one should provide a more general - usable for
            # many applications - file cache with a cleanup of stale
            # entries (maybe based on last access time, when the
            # filesystem provides it).
            #
            set dot_signature [ns_md5 $dot_code-svg-$css]
            set stem $dir/$dot_signature
            if {![ad_file exists $stem.svg]} {
                ns_log notice "inline_svg_from_dot: generate $stem.svg"

                set dotfile $stem.dot
                set svgfile $stem.svg
                set f [open $dotfile w]; puts $f $dot_codeclose $f

                try {
                    exec $dot -Tsvg -o $svgfile $dotfile
                } on error {errorMsg} {
                    ns_log warning "inline_svg_from_dot: dot returned $errorMsg"
                } on ok {result} {
                    set f [open $stem.svg]; set svg [read $f]; close $f
                } finally {
                    file delete -- $stem.dot
                }
            } else {
                ns_log notice "inline_svg_from_dot: reuse $stem.svg"
            }
            if {[ad_file exists $stem.svg]} {
                set f [open $stem.svg]; set svg [read $f]; close $f
                #
                # Delete the first three lines generated from dot.
                #
                regsub {^[^\n]+\n[^\n]+\n[^\n]+\n} $svg "" svg
                set result ""
                if {$css ne ""} {
                    append result <style>$css</style>
                }
                append result "<div class='inner'>$svg</div>"
                return $result
            } else {
                ns_log warning "cannot create svg file"
            }
        }
        return ""
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: