|#
(in-package metabang.graph)
+(export '(
+ print-dot-key-value
+ dot-attribute-value
+ dot-attributes-mixin
+ *dot-graph-attributes*
+ ))
+
;;; ---------------------------------------------------------------------------
;
; This outputs the graph to string in accordance with the DOT file format.
|#
(defparameter *dot-graph-attributes*
- '((:size coord)
+ '((:size coordinate)
(:bb bounding-box)
(:page text)
(:ratio (:fill :compress :auto)) ;; Could actually be a float number too
:doublecircle))
(:fontsize integer)
(:fontname text)
+ (:fontcolor text)
(:color text)
(:fillcolor text)
(:style (:filled :solid :dashed :dotted :bold :invis))
- (:layer text)))
+ (:layer text)
+ (:url text)))
(defparameter *dot-edge-attributes*
'((:pos spline)
(:export-p t))
(defclass* dot-graph-mixin (dot-attributes-mixin) ()
- (:export-p t))
+ (:export-p t)
+ (:default-initargs
+ :vertex-class 'dot-vertex
+ :directed-edge-class 'dot-directed-edge
+ :undirected-edge-class 'dot-edge))
(defclass* dot-vertex-mixin (dot-attributes-mixin) ()
(:export-p t))
(defclass* dot-edge-mixin (dot-attributes-mixin) ()
(defclass* dot-graph (dot-graph-mixin graph-container)
()
- (:default-initargs
- :vertex-class 'dot-vertex
- :directed-edge-class 'dot-directed-edge
- :undirected-edge-class 'dot-edge)
(:export-p t))
(defclass* dot-vertex (dot-vertex-mixin graph-container-vertex) ()
(defmethod graph->dot-properties ((graph dot-graph-mixin) (stream t))
(loop for (name value) on (dot-attributes graph) by #'cddr
do
- (print-dot-key-value name value *dot-graph-attributes* stream)
- (format stream " ;~%")))
+ (print-dot-key-value name value *dot-graph-attributes* stream)))
(defmethod vertex->dot ((vertex dot-vertex-mixin) (stream t))
(format-dot-attributes vertex *dot-vertex-attributes* stream))
(destructuring-bind (key value-type)
(or (assoc key dot-attributes)
(error "Invalid attribute ~S" key))
- (format stream "~a=~a" (string-downcase key)
+ (write-name-for-dot key stream)
+ (format stream "=~a"
(etypecase value-type
((member coordinate)
(with-output-to-string (str)
(string-downcase value)
value))))))
+(defmethod write-name-for-dot (attribute stream)
+ (format stream "~(~A~)" attribute))
+
+(defmethod write-name-for-dot ((attribute (eql :url)) stream)
+ (format stream "URL"))
+
(defun textify (object)
(let ((string (princ-to-string object)))
(with-output-to-string (stream)