Merge pull request #7 from jethrokuan/feat/graph

Add graph rendering
This commit is contained in:
Jethro Kuan 2020-02-04 11:40:18 +08:00 committed by GitHub
commit 273e5a026e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -235,6 +235,37 @@ displaying information for the correct file."
(member (buffer-file-name (current-buffer)) deft-all-files))
(org-roam-update (file-name-nondirectory (buffer-file-name (current-buffer))))))
(defun org-roam-build-graph ()
"Build graphviz graph output."
(with-temp-buffer
(insert "digraph {\n")
(maphash
(lambda (link backlinks)
(maphash
(lambda (backlink content)
(insert (format " %s -> %s;\n" (file-name-sans-extension link) (file-name-sans-extension backlink))))
backlinks))
org-roam-hash-backlinks)
(insert "}")
(buffer-string)))
(defun org-roam-show-graph (&rest body)
(interactive)
(declare (indent 0))
(let ((buffer (get-buffer-create "*org-roam-graph*"))
(temp-dot (expand-file-name "graph.dot" temporary-file-directory))
(temp-graph (expand-file-name "graph.png" temporary-file-directory))
(graph (org-roam-build-graph)))
(with-temp-file temp-dot
(insert graph))
(shell-command (format "dot %s -Tpng -o %s" temp-dot temp-graph))
(with-current-buffer buffer
(let ((inhibit-read-only t))
(erase-buffer)
(insert-image-file temp-graph)
(image-mode)))
(switch-to-buffer-other-window buffer)))
(provide 'org-roam)
;;; org-roam.el ends here