Skip to content

Rank syntax support #17

Description

@dkarvik

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions