mirror of
https://github.com/org-roam/org-roam
synced 2025-08-07 12:47:23 -05:00
(feat): split building and showing of the graph into two functions (#426)
This commit is contained in:
@ -182,11 +182,10 @@ into a digraph."
|
|||||||
(insert "}")
|
(insert "}")
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
|
|
||||||
(defun org-roam-graph-show (&optional prefix node-query)
|
(defun org-roam-graph-build (&optional node-query)
|
||||||
"Generate and displays the Org-roam graph using `org-roam-graph-viewer'.
|
"Generate a graph showing the relations between nodes in NODE-QUERY.
|
||||||
If PREFIX, then the graph is generated but the viewer is not invoked."
|
For building and showing the graph in a single step see `org-roam-graph-show'."
|
||||||
(interactive "P")
|
(interactive)
|
||||||
(declare (indent 0))
|
|
||||||
(unless org-roam-graph-executable
|
(unless org-roam-graph-executable
|
||||||
(user-error "Can't find %s executable. Please check if it is in your path"
|
(user-error "Can't find %s executable. Please check if it is in your path"
|
||||||
org-roam-graph-executable))
|
org-roam-graph-executable))
|
||||||
@ -199,15 +198,25 @@ If PREFIX, then the graph is generated but the viewer is not invoked."
|
|||||||
(with-temp-file temp-dot
|
(with-temp-file temp-dot
|
||||||
(insert graph))
|
(insert graph))
|
||||||
(call-process org-roam-graph-executable nil 0 nil temp-dot "-Tsvg" "-o" temp-graph)
|
(call-process org-roam-graph-executable nil 0 nil temp-dot "-Tsvg" "-o" temp-graph)
|
||||||
(unless prefix
|
temp-graph))
|
||||||
(if (and org-roam-graph-viewer (executable-find org-roam-graph-viewer))
|
|
||||||
(call-process org-roam-graph-viewer nil 0 nil temp-graph)
|
|
||||||
(view-file temp-graph)))))
|
|
||||||
|
|
||||||
(defun org-roam-graph-show-connected-component (&optional max-distance no-display)
|
(defun org-roam-graph--open (file)
|
||||||
"Like `org-roam-graph-show', but only show nodes connected to the current entry.
|
"Open FILE using `org-roam-graph-viewer', with `view-file' as a fallback."
|
||||||
If MAX-DISTANCE is non-nil, only nodes within the given number of steps are shown.
|
(if (and org-roam-graph-viewer (executable-find org-roam-graph-viewer))
|
||||||
If NO-DISPLAY is non-nil, the graph is generated but the viewer is not invoked."
|
(call-process org-roam-graph-viewer nil 0 nil file)
|
||||||
|
(view-file temp-graph)))
|
||||||
|
|
||||||
|
(defun org-roam-graph-show (&optional node-query)
|
||||||
|
"Generate and display a graph showing the relations between nodes in NODE-QUERY.
|
||||||
|
The graph is generated using `org-roam-graph-build' and subsequently displayed
|
||||||
|
using `org-roam-graph-viewer', if it refers to a valid executable, or using
|
||||||
|
`view-file' otherwise."
|
||||||
|
(interactive)
|
||||||
|
(org-roam-graph--open (org-roam-graph-build node-query)))
|
||||||
|
|
||||||
|
(defun org-roam-graph-build-connected-component (&optional max-distance)
|
||||||
|
"Like `org-roam-graph-build', but only include nodes connected to the current entry.
|
||||||
|
If MAX-DISTANCE is non-nil, only nodes within the given number of steps are shown."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(unless (org-roam--org-roam-file-p)
|
(unless (org-roam--org-roam-file-p)
|
||||||
(user-error "Not in an Org-roam file"))
|
(user-error "Not in an Org-roam file"))
|
||||||
@ -219,7 +228,13 @@ If NO-DISPLAY is non-nil, the graph is generated but the viewer is not invoked."
|
|||||||
(query `[:select [file titles]
|
(query `[:select [file titles]
|
||||||
:from titles
|
:from titles
|
||||||
:where (in file [,@files])]))
|
:where (in file [,@files])]))
|
||||||
(org-roam-graph-show no-display query)))
|
(org-roam-graph-build query)))
|
||||||
|
|
||||||
|
(defun org-roam-graph-show-connected-component (&optional max-distance)
|
||||||
|
"Like `org-roam-graph-show', but only include nodes connected to the current entry.
|
||||||
|
If MAX-DISTANCE is non-nil, only nodes within the given number of steps are shown."
|
||||||
|
(interactive "P")
|
||||||
|
(org-roam-graph--open (org-roam-graph-build-connected-component max-distance)))
|
||||||
|
|
||||||
(provide 'org-roam-graph)
|
(provide 'org-roam-graph)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user