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):
- 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_code; close $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