shop-planner / shop3

SHOP3 Git repository
https://shop-planner.github.io
144 stars 14 forks source link

Proposed modification of cl-dot:dot-graph #113

Closed ko56 closed 2 years ago

ko56 commented 2 years ago

This modification automatically assigns to the output file a suffix dictated by the format, as indicated in the last line of the comment. So you can simply say (dot-graph g "g.pdf") or (dot-graph g "g.svg").

(defun dot-graph (graph outfile &key (format :ps) (directed t))
  "Renders GRAPH to OUTFILE by running the program in \*DOT-PATH* or
*NEATO-PATH* depending on the value of the DIRECTED keyword
argument.  The default is a directed graph.  The default
FORMAT is Postscript. 
The output file is assigned a suffix based on the FORMAT."
  (when (null format) (setf format :ps))
  (setf outfile (uiop:strcat (namestring outfile) "." (string-downcase format)))
  (let ((dot-path (if directed *dot-path* *neato-path*))
         (format (format nil "-T~(~a~)" format))
         (dot-string (with-output-to-string (stream)
               (print-graph graph :stream stream :directed directed))))
    (uiop:run-program (list dot-path format "-o" outfile)
      :input (make-string-input-stream dot-string) :output *standard-output*))) 
rpgoldman commented 2 years ago

Hi @ko56 -- we shouldn't make this fix here. Instead, it should go into the upstream library, which you can find here: https://github.com/michaelw/cl-dot

I think it's a good idea, though.

ko56 commented 2 years ago

OK, I will post it to the upstream library.