(feat): graph: add cite links to graph (#439)
This commit is contained in:
parent
0e79bbb75a
commit
580a320c66
3 changed files with 41 additions and 5 deletions
|
@ -12,6 +12,7 @@
|
|||
* [#380][gh-380] Allow `org-roam-buffer-position` to also be `top` or `bottom`
|
||||
* [#385][gh-385] Add `org-roam-graph-node-extra-config` to configure Graphviz nodes
|
||||
* [#435][gh-435] Add `org-roam-graph-edge-extra-config` to configure Graphviz edges
|
||||
* [#439][gh-439] Add support for `org-ref` citations to display as edges in graph. Add `org-roam-graph-edge-cites-extra-config` to configure these edges
|
||||
|
||||
## 1.0.0 (23-03-2020)
|
||||
|
||||
|
|
|
@ -253,8 +253,14 @@ This is equivalent to removing the node from the graph."
|
|||
If the file does not have any connections, nil is returned."
|
||||
(let* ((query "WITH RECURSIVE
|
||||
links_of(file, link) AS
|
||||
(SELECT \"from\", \"to\" FROM links UNION
|
||||
SELECT \"to\", \"from\" FROM links),
|
||||
(WITH roamlinks AS (SELECT * FROM links WHERE \"type\" = '\"roam\"'),
|
||||
citelinks AS (SELECT * FROM links
|
||||
JOIN refs ON links.\"to\" = refs.\"ref\"
|
||||
AND links.\"type\" = '\"cite\"')
|
||||
SELECT \"from\", \"to\" FROM roamlinks UNION
|
||||
SELECT \"to\", \"from\" FROM roamlinks UNION
|
||||
SELECT \"file\", \"from\" FROM citelinks UNION
|
||||
SELECT \"from\", \"file\" FROM citelinks),
|
||||
connected_component(file) AS
|
||||
(SELECT link FROM links_of WHERE file = $s1
|
||||
UNION
|
||||
|
@ -268,8 +274,14 @@ If the file does not have any connections, nil is returned."
|
|||
including the file itself. If the file does not have any connections, nil is returned."
|
||||
(let* ((query "WITH RECURSIVE
|
||||
links_of(file, link) AS
|
||||
(SELECT \"from\", \"to\" FROM links UNION
|
||||
SELECT \"to\", \"from\" FROM links),
|
||||
(WITH roamlinks AS (SELECT * FROM links WHERE \"type\" = '\"roam\"'),
|
||||
citelinks AS (SELECT * FROM links
|
||||
JOIN refs ON links.\"to\" = refs.\"ref\"
|
||||
AND links.\"type\" = '\"cite\"')
|
||||
SELECT \"from\", \"to\" FROM roamlinks UNION
|
||||
SELECT \"to\", \"from\" FROM roamlinks UNION
|
||||
SELECT \"file\", \"from\" FROM citelinks UNION
|
||||
SELECT \"from\", \"file\" FROM citelinks),
|
||||
-- Links are traversed in a breadth-first search. In order to calculate the
|
||||
-- distance of nodes and to avoid following cyclic links, the visited nodes
|
||||
-- are tracked in 'trace'.
|
||||
|
|
|
@ -74,6 +74,13 @@ Example:
|
|||
:type '(alist)
|
||||
:group 'org-roam)
|
||||
|
||||
(defcustom org-roam-graph-edge-cites-extra-config '(("color" . "red"))
|
||||
"Extra options for graphviz edges for citation links.
|
||||
Example:
|
||||
'((\"dir\" . \"back\"))"
|
||||
:type '(alist)
|
||||
:group 'org-roam)
|
||||
|
||||
(defcustom org-roam-graph-max-title-length 100
|
||||
"Maximum length of titles in graph nodes."
|
||||
:type 'number
|
||||
|
@ -139,7 +146,13 @@ into a digraph."
|
|||
`[:with selected :as [:select [file] :from ,node-query]
|
||||
:select :distinct [to from] :from links
|
||||
:where (and (in to selected) (in from selected))])
|
||||
(edges (org-roam-db-query edges-query)))
|
||||
(edges-cites-query
|
||||
`[:with selected :as [:select [file] :from ,node-query]
|
||||
:select :distinct [file from]
|
||||
:from links :inner :join refs :on (and (= links:to refs:ref) (= links:type "cite"))
|
||||
:where (and (in file selected) (in from selected))])
|
||||
(edges (org-roam-db-query edges-query))
|
||||
(edges-cites (org-roam-db-query edges-cites-query)))
|
||||
(insert "digraph \"org-roam\" {\n")
|
||||
|
||||
(dolist (option org-roam-graph-extra-config)
|
||||
|
@ -179,6 +192,16 @@ into a digraph."
|
|||
(insert (format " \"%s\" -> \"%s\";\n"
|
||||
(xml-escape-string (car edge))
|
||||
(xml-escape-string (cadr edge)))))
|
||||
|
||||
(insert (format " edge [%s];\n"
|
||||
(->> org-roam-graph-edge-cites-extra-config
|
||||
(mapcar (lambda (n)
|
||||
(concat (car n) "=" (cdr n))))
|
||||
(s-join ","))))
|
||||
(dolist (edge edges-cites)
|
||||
(insert (format " \"%s\" -> \"%s\";\n"
|
||||
(xml-escape-string (car edge))
|
||||
(xml-escape-string (cadr edge)))))
|
||||
(insert "}")
|
||||
(buffer-string))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue