Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rank syntax support #17

Open
SevereOverfl0w opened this issue Dec 20, 2019 · 1 comment
Open

Rank syntax support #17

SevereOverfl0w opened this issue Dec 20, 2019 · 1 comment

Comments

@SevereOverfl0w
Copy link

I was unable to generate the syntax for {rank = same; X; Y; Z} without using some dorothy internals.

Here's a small example of what I'd like to do: https://stackoverflow.com/a/44274606/1481316

This is also mentioned in the Dot User's Manual https://www.graphviz.org/pdf/dotguide.pdf on page 16.

Here's how I achieved the syntax, which as far as I can tell is called "Rank":

(defn rank
  [attrs statements]
  {:type ::rank
   :statements (map #'dot/to-ast statements)
   :attrs attrs})

(defmethod dot/dot* ::rank
  [this]
  (let [{:keys [attrs statements]} this]
    (str "{\n"
         (apply
           str
           (for [[k v] attrs]
             (str (#'dot/escape-id k) \= (#'dot/escape-id v) ";\n")))
         (apply str (interleave
                      (map dot/dot* statements)
                      (repeat ";\n")))
         "} ")))

It's a lot like a graph, but without a name, and with the ability to set inline attrs. I decided to front-load the attrs, but ordering might matter, so that might not be ideal.

@handerpeder
Copy link

Was wondering how to do this myself. Turns out this is just a subgraph (the keyword subgraph is optional).

The following two statements are equivalent:

subgraph { 
  rank = same; A; B; C; 
} 
{ rank = same; A; B; C; } 

Having sugar for subgraphs would be nice though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants