Edge direction in graph

I’d like to visualize high-level structure for my notes by assigning direction to a few of the edges. There seems to be two possible methods for doing this:

  1. "org-roam-server-network-arrows can be used to add arrows to the network, available options are “from”, “to”, “middle”, and any mix of the three." (https://github.com/org-roam/org-roam-server/releases/tag/v1.0.3)

  2. "org-roam-graph-edge-extra-config to configure Graphviz edges" (https://github.com/org-roam/org-roam/pull/435/commits/d8f4cf9d0f7e656da80e0eb397f7670a920cc18c)

I’ve tried each separately and both together in my Doom Emacs config.el without success. Either I have misconfigured the feature(s) or I’m failing to see how to use them them to assign a direction to an edge. Or both!

This is what I have in my config.el for the first method above:
(setq org-roam-server-network-arrows '(“from” “to” “middle”))

And this is what I have for the second method:
(setq org-roam-graph-edge-extra-config '((“dir” . “forward”)))

My questions:

  1. Will one or are both of these methods allow me to assign a direction to an edge in my graph?
  2. If so, do I have one or both of them correctly configured?
  3. And if one or both are correctly configured, how to I proceed to use the feature to assign a direction to an edge in my graph?

Hi @Sub,
I wonder if the values need to be defined as a symbol, instead of a string, like this:
(setq org-roam-server-network-arrows '('from 'to 'middle))

Sorry, I can’t test this; perhaps you’ve already tried it?

Thank, nobiot (again!).

Looking again at the source, I think you’re right about using symbols instead of strings for the server-network-arrows option. I believe I tried that but can’t say for sure as I’ve regretfully not documented all my experiments.

In any case, I’ve commented out both of the above mentioned configuration file lines and added your suggestion in their place. It gets evaluated successfully (as do the other two setqs), but then I cannot see what if anything has changed that would allow me to assign a direction to an edge in my graph.

If correctly configured, what should I be looking for to use the feature? If there is a command I should issue to return a choice of direction, I’m not finding it in Emacs help or in org-roam docs or code (not that I’d necessarily recognize it in the code even if I were staring right at it…).

It’s probably best to ask a “how-to” question on their GiHub, but I guess the value needs to be provided for the type, by the looks of the documentation (of viz-network).

So… in the config, something using this syntax to specify a value of the type (to, from, middle)?

   "Options to be passed directly to vis.Network, in JSON format.
e.g. (json-encode (list (cons 'physics (list (cons 'enabled json-false)))))
or { \"physics\": { \"enabled\": false } }"

Thanks for pointing to that possible solution. It might be the right one, but it’s a bit above my elisp/json skill levels. I gave it a try, replacing “physics” with “edges” and adding type “forward,” but that did not successfully evaluate. “Wrong number of arguments: cons, 4”

Running in background is my confusion about different org-roam-server-network option for graph. Reading the vis.js docs you point me to makes me wonder if the org-roam-server-network-vis-options function, which I believe is what you refer to above, is for “physics” vis.js settings that I think govern how the graph unfurls and stabilizes. There seem to be other ways of handing other aspects of the graph, like arrows. That possibility arises again for me when I look at org-roam-server.el (https://github.com/org-roam/org-roam-server/blob/master/org-roam-server.el). The section below (lines 104-116) seems to handle arrows differently from how it handles whatever it is that vis-options handles.

(defcustom org-roam-server-network-arrows nil
“If the type is given, enable arrows in the network.
Available types are to, middle, and from.
Types can be concatanated using commas.”
:group 'org-roam-server
:type 'string)

(defcustom org-roam-server-network-vis-options nil
“Options to be passed directly to vis.Network, in JSON format.
e.g. (json-encode (list (cons 'physics (list (cons 'enabled json-false)))))
or { “physics”: { “enabled”: false } }”
:group 'org-roam-server
:type 'string)

From the first block, the one re: arrows, I get the feeling that something like the following should work:
(setq org-roam-server-network-arrows '('to))
But as I mentioned, while it gets successfully evaluated, it doesn’t seem to do anything that will allow me to assign a forward-pointing arrow to an edge.

Another point of background confusion for me is the difference between what the “org-roam-server-network-arrows” function does and what “org-roam-graph-edge-extra-config” might accomplish. There are a handful of option-configuring blocks of code seen in lines 64-96 in org-roam-graph.el (https://github.com/org-roam/org-roam/blob/master/org-roam-graph.el). One of them is for edge options, including, I believe, arrow direction:
(defcustom org-roam-graph-edge-extra-config
'((“color” . “#333333”))
“Extra options for graphviz edges.
Example:
'((“dir” . “back”))”
:type '(alist)
:group 'org-roam)

The example makes me feel like the following should work:
(setq org-roam-graph-edge-extra-config '((“dir” . “forward”)))
But as mentioned, no dice. Or I don’t see what to do with it after making the change and restarting everything.

Getting back to your idea about passing JSON to vis.js and asking that community for advice, I’m preparing a question for them. My difficulty has been that my question seems to boil down to “how do I configure org-roam to allow me to assign arrow directions to nodes in my vis.js network?,” and I worry that won’t get me very far unless someone there is familiar with emacs/org-mode/org-roam. I’m trying to take the respondent’s need to know about emacs/org-mode/org-roam out of the picture, but so far, I’m not succeeding at that.

For Org-roam-server, I would try something like blow:

(setq org-roam-server-network-arrows
   (json-encode (list (cons 'to (list (cons 'type "arrow"))))))

or

(setq org-roam-server-network-arrows
   "{ \"to\": { \"type\": \"arrow\" } }"
;; you may need to escpate all the double quotations
(setq org-roam-server-network-arrows
   (json-encode (list (cons 'to (list (cons 'type \"arrow\"))))))

I am assuming your question for Org-roam-server is “How do I make edges to be arrows with using org-roam-server-network-arrows variable?” (along these lines).

I don’t know how the other option with org-roam-graph-edge-extra-config works, but I guess you would prefer Org-roam-server to work? (if so, for now you can disregard it).

@Sub
This works on my machine.

(setq org-roam-server-network-arrows
   (json-encode (list (cons 'to (list (cons 'type "arrow"))))))

1 Like

As it does on mine!

Very grateful, nobiot.

Again.

1 Like