From 04a35a677d803ed71961c63909a706cef478417b Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 10 Apr 2017 21:32:31 +0100 Subject: [PATCH] use expkg-zone58 --- README.md | 9 ++- src/graphxq/dotml.xqm | 20 ------ src/graphxq/dotml/dotml2dot.xsl | 81 ---------------------- src/graphxq/expath-pkg.xml | 4 +- src/graphxq/graphviz.xqm | 119 -------------------------------- src/graphxq/graphxq.xqm | 10 +-- src/graphxq/thumbnails.xq | 6 +- 7 files changed, 18 insertions(+), 231 deletions(-) delete mode 100644 src/graphxq/dotml.xqm delete mode 100644 src/graphxq/dotml/dotml2dot.xsl delete mode 100644 src/graphxq/graphviz.xqm diff --git a/README.md b/README.md index 7ae7897..b303e42 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,14 @@ An interface to Graphviz for BaseX 8.0 copy the contents of the `src` folder to your `webapp` folder ## Requires -1. Graphviz intallation with `dot` on the path +1. Graphviz installation with `dot` on the path 1. restxq default config with (static) +1. https://expkg-zone58.github.io #ex-graphviz and #ex-dotml ## other -* includes dotML + * BaseX RestXQ interface + +## History +* v0.8 use expkg-zone58 + diff --git a/src/graphxq/dotml.xqm b/src/graphxq/dotml.xqm deleted file mode 100644 index 92b8fe6..0000000 --- a/src/graphxq/dotml.xqm +++ /dev/null @@ -1,20 +0,0 @@ -(:~ -: dotml module -: @see http://www.martin-loetzsch.de/DOTML/ -:) - -module namespace dotml="http://www.martin-loetzsch.de/DOTML"; -declare default function namespace 'http://www.martin-loetzsch.de/DOTML'; - -import module namespace xslt="http://basex.org/modules/xslt"; - -(:~ -: @return graphviz dot string -: note xslt:transform can not return output text so result is wrapped -:) -declare function generate($dotml) as xs:string -{ - let $d:=xslt:transform($dotml, fn:resolve-uri( "dotml/dotml2dot.xsl")) - return $d/fn:string() -}; - diff --git a/src/graphxq/dotml/dotml2dot.xsl b/src/graphxq/dotml/dotml2dot.xsl deleted file mode 100644 index c5aef7c..0000000 --- a/src/graphxq/dotml/dotml2dot.xsl +++ /dev/null @@ -1,81 +0,0 @@ - - - - bgcolor fontcolor fontname fontsize label margin nodesep rankdir ranksep ratio size - bgcolor color fillcolor fontcolor fontname fontsize label labeljust labelloc style - color fillcolor fixedsize fontcolor fontname fontsize height shape style URL width - color fillcolor fontcolor fontname fontsize height style URL width - arrowhead arrowsize arrowtail constraint color decorate dir fontcolor fontname fontsize headlabel headport label labeldistance labelfloat labelfontcolor labelfontname labelfontsize minlen samehead sametail style taillabel tailport URL - - - - - - digraph g {compound="true"; - - - - } - - subgraph sub_graph_{rank="";} - subgraph cluster_{ - - - - } - node[label=" - - - - - - - ", - - - ] {}; - edge[ - - - lhead="cluster_ - ",ltail="cluster_ - "] struct: - -> struct: - ; - node[shape="record",label="", - - - ]{struct}; - {} | - - <> - - - - - - - - | - - - - - - - ="" - - - ="" - - - - - - - - diff --git a/src/graphxq/expath-pkg.xml b/src/graphxq/expath-pkg.xml index ddb8ca1..00a1ab9 100644 --- a/src/graphxq/expath-pkg.xml +++ b/src/graphxq/expath-pkg.xml @@ -1,9 +1,11 @@ + version="0.8.0" spec="1.0" xmlns="http://expath.org/ns/pkg"> Graphxq + + \ No newline at end of file diff --git a/src/graphxq/graphviz.xqm b/src/graphxq/graphviz.xqm deleted file mode 100644 index 8a1cc9c..0000000 --- a/src/graphxq/graphviz.xqm +++ /dev/null @@ -1,119 +0,0 @@ -(:~ -: graphviz module -: based on http://www.zorba-xquery.com/html/modules/zorba/image/graphviz -:) - -module namespace gr="apb.graphviz"; -declare default function namespace 'apb.graphviz'; -import module namespace proc="http://basex.org/modules/proc"; -import module namespace file="http://expath.org/ns/file"; -import module namespace xslt="http://basex.org/modules/xslt"; - -declare namespace svg= "http://www.w3.org/2000/svg"; -declare namespace xlink="http://www.w3.org/1999/xlink"; - -declare %private variable $gr:dotpath:=if(fn:environment-variable("DOTPATH")) - then fn:environment-variable("DOTPATH") - else "dot"; -(:~ -: folder for temp files \=windows -:) -declare %private variable $gr:tmpdir:=if(file:dir-separator()="\") - then fn:environment-variable("TEMP") || "\" - else "/tmp/"; - -declare %private variable $gr:empty:= - - Empty. -; - -(:~ -:Layout one or more graphs given in the DOT language and render them as SVG. -:) -declare function dot( $dot as xs:string*, $params as xs:string*) as node()*{ - let $params:=("-Tsvg") - for $d in $dot - return if(fn:not($d)) - then $gr:empty - else let $r:=dot-execute($d,$params) - return dot-svg($r) -}; - -(:~ run dot command :) -declare %private function dot-execute( $dot as xs:string, $params as xs:string*) as element(result){ - let $fname:=$gr:tmpdir || random:uuid() - let $junk:=file:write-text($fname,$dot) - let $r:=proc:execute($gr:dotpath , ($params,$fname)) - let $junk:=file:delete($fname) - return if($r/code!="0") - then fn:error(xs:QName('gr:dot1'),$r/error) - else $r -}; - -(:~ run dot command returning binary :) -declare function dot-executeb( $dot as xs:string, $params as xs:string*) as xs:base64Binary{ - let $fname:=$gr:tmpdir || random:uuid() - let $oname:=$fname || ".o" - let $junk:=file:write-text($fname,$dot) - let $r:=proc:execute($gr:dotpath , ($params,"-o"|| $oname,$fname)) - let $junk:=file:delete($fname) - return if($r/code!="0") - then fn:error(xs:QName('gr:dot1'),$r/error) - else let $d:=file:read-binary($oname) - (: let $junk:=file:delete($oname) :) - return $d -}; - -(:~ cleanup dot svg result :) -declare %private function dot-svg( $r as element(result)) as element(svg:svg){ - let $s:=fn:parse-xml($r/output) (: o/p has comment nodes :) - let $ver:=$s/comment()[1]/fn:normalize-space() - let $title:=$s/comment()[2]/fn:normalize-space() - let $svg:=$s/* - return - {$svg/@* , - - - - - - {$ver} - - - - - - , - $svg/*} - - -}; - - -(:~ -: set svg to autosize 100% -:) -declare function autosize($svg as node()) as node(){ - - {$svg/@* except ($svg/@width,$svg/@height,$svg/@preserveAspectRatio), - $svg/*} - -}; - -(:~ -: set svg to autosize 100% -:) -declare function autosize-old($svg as node()) as node(){ - xslt:transform($svg , fn:resolve-uri("dotml/dotpatch.xsl")) -}; - diff --git a/src/graphxq/graphxq.xqm b/src/graphxq/graphxq.xqm index 7058a30..4346664 100644 --- a/src/graphxq/graphxq.xqm +++ b/src/graphxq/graphxq.xqm @@ -7,8 +7,8 @@ module namespace grxq = 'apb.graphviz.web'; declare default function namespace 'apb.graphviz.web'; -import module namespace gr = 'apb.graphviz' at "graphviz.xqm"; -import module namespace dotml = 'http://www.martin-loetzsch.de/DOTML' at "dotml.xqm"; +import module namespace gr = 'expkg-zone58:image.graphviz' ; +import module namespace dotml = 'http://www.martin-loetzsch.de/DOTML' ; import module namespace dotui = 'apb.graphxq.dotui' at "dotui.xqm"; import module namespace txq = 'quodatum.txq' at "lib/txq.xqm"; import module namespace request = "http://exquery.org/ns/request"; @@ -165,7 +165,7 @@ declare function api-dotml($dotml,$dl ) { let $dotml:=fn:trace($dotml,"dot: ") let $dotml:=fn:parse-xml($dotml) - let $x:=dotml:generate($dotml) + let $x:=dotml:to-dot($dotml) let $svg:=dot2svg($x) let $fname:=if($dl)then "dotml.svg" else () return (headers($fname),$svg) @@ -206,8 +206,8 @@ declare function headers($attachment){ (:~ Generate svg from dot :) declare %private function dot2svg($dot as xs:string) as node(){ - let $svgx:=gr:dot($dot,()) - return gr:autosize($svgx) + let $svgx:=gr:to-svg($dot,()) + return gr:autosize($svgx/*) }; (:~ css class to highlight current page :) diff --git a/src/graphxq/thumbnails.xq b/src/graphxq/thumbnails.xq index 21e1e93..ae82472 100644 --- a/src/graphxq/thumbnails.xq +++ b/src/graphxq/thumbnails.xq @@ -1,6 +1,6 @@ (: generate thumbnail :) -import module namespace gr = 'apb.graphviz' at "graphviz.xqm" ; -import module namespace dotml = 'http://www.martin-loetzsch.de/DOTML' at "dotml.xqm"; +import module namespace gr = 'expkg-zone58:image.graphviz' ; +import module namespace dotml = 'http://www.martin-loetzsch.de/DOTML' ; declare variable $src:=resolve-uri("data/samples/"); declare variable $dest:=resolve-uri("data/thumbs/"); declare variable $opts:=("-Tgif","-Gsize=1.2,1.2",'-Gfill=auto'); @@ -17,5 +17,5 @@ let $ext:=substring-after($f,".") where $ext=('dot','gv','xml') return let $g:= if($ext=('gv','dot')) then file:read-text($src || $f) - else dotml:generate(doc($src || $f)) + else dotml:to-dot(doc($src || $f)) return local:thumb($g,$dest || $f ||".gif")