mirror of
https://github.com/Quodatum/graphxq.git
synced 2025-01-18 07:48:53 +00:00
use expkg-zone58
This commit is contained in:
parent
1080533e6c
commit
04a35a677d
@ -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
|
||||
|
||||
|
@ -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()
|
||||
};
|
||||
|
@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:dotml="http://www.martin-loetzsch.de/DOTML">
|
||||
<!--
|
||||
File dotml2dot.xsl
|
||||
Copyright 2002 - 2006 Martin Loetzsch
|
||||
Translates dotml documents into the native dot syntax.
|
||||
-->
|
||||
<xsl:variable xml:space="preserve" name="graph-attributes">bgcolor fontcolor fontname fontsize label margin nodesep rankdir ranksep ratio size</xsl:variable>
|
||||
<xsl:variable xml:space="preserve" name="cluster-attributes">bgcolor color fillcolor fontcolor fontname fontsize label labeljust labelloc style</xsl:variable>
|
||||
<xsl:variable xml:space="preserve" name="node-attributes">color fillcolor fixedsize fontcolor fontname fontsize height shape style URL width</xsl:variable>
|
||||
<xsl:variable xml:space="preserve" name="record-attributes">color fillcolor fontcolor fontname fontsize height style URL width</xsl:variable>
|
||||
<xsl:variable xml:space="preserve" name="edge-attributes">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</xsl:variable>
|
||||
<xsl:key name="nodes" match="//dotml:node" use="concat(@id,ancestor::dotml:graph/@file-name)"/>
|
||||
<xsl:template match="*" priority="-1000">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
<xsl:template match="text()"/>
|
||||
<xsl:template match="dotml:graph"><dummy>digraph g {compound="true";<xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="separator" select="';'"/>
|
||||
<xsl:with-param name="attributes" select="$graph-attributes"/>
|
||||
</xsl:call-template>
|
||||
<xsl:apply-templates/>}</dummy>
|
||||
</xsl:template>
|
||||
<xsl:template match="dotml:sub-graph">subgraph sub_graph_<xsl:value-of select="count(preceding::dotml:sub-graph)"/>{rank="<xsl:value-of select="@rank"/>";<xsl:apply-templates/>}</xsl:template>
|
||||
<xsl:template match="dotml:cluster">subgraph cluster_<xsl:value-of select="@id"/>{<xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="separator" select="';'"/>
|
||||
<xsl:with-param name="attributes" select="$cluster-attributes"/>
|
||||
</xsl:call-template>
|
||||
<xsl:apply-templates/>}</xsl:template>
|
||||
<xsl:template match="dotml:node">node[label="<xsl:choose>
|
||||
<xsl:when test="@label">
|
||||
<xsl:value-of select="@label"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="@id"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>", <xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="separator" select="','"/>
|
||||
<xsl:with-param name="attributes" select="$node-attributes"/>
|
||||
</xsl:call-template>] {<xsl:value-of select="@id"/>};</xsl:template>
|
||||
<xsl:template match="dotml:edge">edge[<xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="separator" select="','"/>
|
||||
<xsl:with-param name="attributes" select="$edge-attributes"/>
|
||||
</xsl:call-template>lhead="<xsl:if test="@lhead">cluster_<xsl:value-of select="@lhead"/>
|
||||
</xsl:if>",ltail="<xsl:if test="@ltail">cluster_<xsl:value-of select="@ltail"/>
|
||||
</xsl:if>"] <xsl:if test="key('nodes',concat(@from,ancestor::dotml:graph/@file-name))/ancestor::dotml:record">struct<xsl:value-of select="count(key('nodes',concat(@from,ancestor::dotml:graph/@file-name))/preceding::dotml:record[local-name(..)!='record'])"/>:</xsl:if>
|
||||
<xsl:value-of select="@from"/> -> <xsl:if test="key('nodes',concat(@to,ancestor::dotml:graph/@file-name))/ancestor::dotml:record">struct<xsl:value-of select="count(key('nodes',concat(@to,ancestor::dotml:graph/@file-name))/preceding::dotml:record[local-name(..)!='record'])"/>:</xsl:if>
|
||||
<xsl:value-of select="@to"/>;</xsl:template>
|
||||
<xsl:template match="dotml:record">node[shape="record",label="<xsl:apply-templates select="dotml:*" mode="record-label"/>",<xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="separator" select="','"/>
|
||||
<xsl:with-param name="attributes" select="$record-attributes"/>
|
||||
</xsl:call-template>]{struct<xsl:value-of select="count(preceding::dotml:record[local-name(..)!='record'])"/>};</xsl:template>
|
||||
<xsl:template match="dotml:record" mode="record-label">{<xsl:apply-templates select="dotml:*" mode="record-label"/>}<xsl:if test="position()!=last()"> | </xsl:if>
|
||||
</xsl:template>
|
||||
<xsl:template match="dotml:node" mode="record-label"><<xsl:value-of select="@id"/>> <xsl:choose>
|
||||
<xsl:when test="@label">
|
||||
<xsl:value-of select="@label"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="@id"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:if test="position()!=last()"> | </xsl:if>
|
||||
</xsl:template>
|
||||
<xsl:template name="copy-attributes">
|
||||
<xsl:param name="attributes"/>
|
||||
<xsl:param name="separator"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length(substring-after($attributes,' '))=0">
|
||||
<xsl:value-of select="$attributes"/>="<xsl:value-of select="@*[local-name()=$attributes]"/>"<xsl:value-of select="$separator"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="substring-before($attributes,' ')"/>="<xsl:value-of select="@*[local-name()=substring-before($attributes,' ')]"/>"<xsl:value-of select="$separator"/>
|
||||
<xsl:call-template name="copy-attributes">
|
||||
<xsl:with-param name="attributes" select="substring-after($attributes,' ')"/>
|
||||
<xsl:with-param name="separator" select="$separator"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
@ -1,9 +1,11 @@
|
||||
<package abbrev="graphxq" name="https://github.com/apb2006/graphxq"
|
||||
version="0.7.2" spec="1.0" xmlns="http://expath.org/ns/pkg">
|
||||
version="0.8.0" spec="1.0" xmlns="http://expath.org/ns/pkg">
|
||||
<title>Graphxq</title>
|
||||
<dependency name="twitter-bootstrap" version="3.3.6" />
|
||||
<dependency name="svg-pan-zoom" version="3.2.8" />
|
||||
<dependency name="jquery" version="2.0.2" />
|
||||
<dependency name="ace" version="1.2.3" />
|
||||
<dependency name="d3" version="4" />
|
||||
<dependency name="ex-dotml" version="0.3.0" />
|
||||
<dependency name="ex-graphviz" version="0.3.1" />
|
||||
</package>
|
@ -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:=
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 20" version="1.1"
|
||||
width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
|
||||
<text x="150" y="10" text-anchor="middle">Empty.</text>
|
||||
</svg>;
|
||||
|
||||
(:~
|
||||
: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 xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" >
|
||||
{$svg/@* ,
|
||||
<metadata>
|
||||
<rdf:RDF
|
||||
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:dc = "http://purl.org/dc/elements/1.1/" >
|
||||
<rdf:Description about="https://github.com/apb2006/graphxq"
|
||||
dc:title="{$title}"
|
||||
dc:description="A graph visualization"
|
||||
dc:date="{fn:current-dateTime()}"
|
||||
dc:format="image/svg+xml">
|
||||
<dc:creator>
|
||||
<rdf:Bag>
|
||||
<rdf:li>{$ver}</rdf:li>
|
||||
<rdf:li resource="https://github.com/apb2006/graphxq"/>
|
||||
</rdf:Bag>
|
||||
</dc:creator>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</metadata>,
|
||||
$svg/*}
|
||||
</svg>
|
||||
|
||||
};
|
||||
|
||||
|
||||
(:~
|
||||
: set svg to autosize 100%
|
||||
:)
|
||||
declare function autosize($svg as node()) as node(){
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
|
||||
{$svg/@* except ($svg/@width,$svg/@height,$svg/@preserveAspectRatio),
|
||||
$svg/*}
|
||||
</svg>
|
||||
};
|
||||
|
||||
(:~
|
||||
: set svg to autosize 100%
|
||||
:)
|
||||
declare function autosize-old($svg as node()) as node(){
|
||||
xslt:transform($svg , fn:resolve-uri("dotml/dotpatch.xsl"))
|
||||
};
|
||||
|
@ -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 :)
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user