X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=dev%2Fgraphviz%2Fgraphviz-support.lisp;h=aec3b994ab5297c1d27fc97637c3e29a0be80cda;hb=967f37e2d82bf3bcf47a644686eed00e293b50aa;hp=f82f2b0344dd27058732a164d621fb90b38d8580;hpb=a4a389d3e6bf65538f6e6115a1aa30fb50c9f562;p=cl-graph.git diff --git a/dev/graphviz/graphviz-support.lisp b/dev/graphviz/graphviz-support.lisp index f82f2b0..aec3b99 100644 --- a/dev/graphviz/graphviz-support.lisp +++ b/dev/graphviz/graphviz-support.lisp @@ -2,16 +2,14 @@ #| simple-header -$Id: graphviz-support.lisp,v 1.7 2005/06/21 20:51:51 moody Exp $ - -Author: Gary King, Levente Mészáros, Attila Lendvai +Author: Gary King, Levente Mészáros, Attila Lendvai DISCUSSION This file contains the stuff that does not depend on cl-graphviz. |# -(in-package metabang.graph) +(in-package #:metabang.graph) ;;; --------------------------------------------------------------------------- ; @@ -19,16 +17,17 @@ This file contains the stuff that does not depend on cl-graphviz. ; For more information about DOT file format, search the web for "DOTTY" and ; "GRAPHVIZ". ; - graph->dot ((g basic-graph) (stream stream) - &key +(defmethod graph->dot ((g basic-graph) (stream stream) + &key (graph-formatter 'graph->dot-properties) (vertex-key 'vertex-id) (vertex-labeler nil) (vertex-formatter 'vertex->dot) - (edge-key nil) (edge-labeler 'princ) - (edge-formatter 'edge->dot)) - (format stream "~A G {~%graph " (if (contains-undirected-edge-p g) "graph" "digraph")) + (edge-formatter 'edge->dot) + &allow-other-keys) + (format stream "~A G {~%graph " + (if (contains-undirected-edge-p g) "graph" "digraph")) (format stream "[") (funcall graph-formatter g stream) (format stream "];") @@ -61,7 +60,7 @@ This file contains the stuff that does not depend on cl-graphviz. (princ " [" stream) (when (and directed? directed-edge-tag) (princ directed-edge-tag stream)) - (when edge-key + (when edge-labeler (princ "label=\"" stream) (funcall edge-labeler e stream) (princ "\"," stream)) @@ -244,11 +243,13 @@ B--D [] '((:size coordinate) (:bb bounding-box) (:page text) + (:dpi float) (:ratio (:fill :compress :auto)) ;; Could actually be a float number too (:margin float) (:nodesep float) (:ranksep float) (:ordering (:out)) + (:overlap text) (:rankdir ("LR" "RL" "BT")) (:pagedir text) (:rank (:same :min :max)) @@ -258,12 +259,14 @@ B--D [] (:mclimit float) (:layers text) (:color text) - (:bgcolor text))) + (:bgcolor text) + (:fontname text))) (defparameter *dot-vertex-attributes* '((:pos coordinate) (:height float) (:width float) + (:margin float) (:fixed-size boolean) (:label text) (:shape (:record :plaintext :ellipse :circle :egg :triangle :box @@ -276,7 +279,8 @@ B--D [] (:fillcolor text) (:style (:filled :solid :dashed :dotted :bold :invis)) (:layer text) - (:url text))) + (:url text) + (:peripheries integer))) (defparameter *dot-edge-attributes* '((:pos spline) @@ -347,6 +351,23 @@ B--D [] (defmethod dot-attribute-value ((attr symbol) (thing dot-attributes-mixin)) (getf (dot-attributes thing) attr)) +(defmacro defpixel-inch-accessors (name attr type) + (bind ((actual-name (form-symbol name "-IN-PIXELS"))) + `(progn + (export ',actual-name) + (defmethod ,actual-name ((thing ,type)) + "Return the attribute in pixels assuming 72 dpi" + (awhen (dot-attribute-value ,attr thing) + (* 72 it))) + (defmethod (setf ,actual-name) (value (thing ,type)) + "Set the attribute in pixels assuming 72 dpi" + (setf (dot-attribute-value ,attr thing) + (coerce (/ value 72) 'double-float)))))) + +(defpixel-inch-accessors width :width dot-vertex-mixin) +(defpixel-inch-accessors height :height dot-vertex-mixin) + + (defmethod graph->dot-properties ((graph dot-graph-mixin) (stream t)) (loop for (name value) on (dot-attributes graph) by #'cddr do @@ -429,7 +450,9 @@ B--D [] ((member text) (textify value)) ((member float) - (coerce value 'single-float)) + ;; graphviz does not support the 1.2e-3 format + (with-output-to-string (str) + (format str "~,f" (coerce value 'single-float)))) (list (unless (member value value-type :test 'equal) (error "Invalid value for ~S: ~S is not one of ~S" @@ -476,6 +499,7 @@ B--D [] the program in *dot-path*." (let ((dot-string (graph->dot g nil)) (dot-type (concatenate 'string "-T" (string-downcase (symbol-name type))))) + (declare (ignorable dot-string dot-type file-name)) #+lispworks (with-open-stream (s (sys:open-pipe (concatenate 'string *dot-path* " -Tpng -o" file-name) :direction :input))