snowleopard / alga

Algebraic graphs
MIT License
715 stars 68 forks source link

Export.Dot: Extend Style to define Quoting styles #273

Closed jmtd closed 3 years ago

jmtd commented 3 years ago

GraphViz supports different types of label. The type is determined by the delimiters used to quote the label's value. Double-quotes denote a literal string. Pairs of angle brackets ("<>") denote a "HTML-like" string, which permits the use of (some) HTML mark-up in the graph.

Extend the Style record type to include a quoting field, to signal whether or not attribute values should be double-quoted. A user wishing to use another quote style must define their style's quoting attribute as NoQuote and then ensure their attribute values contain embedded quote characters of their choice.

Adjust defaultStyle and the attributes function accordingly and add a test.

Fixes #272.


Here's an example of the above in use. Note that I have to take responsibility for wrapping all values, and I vary what delimiter I use. Here's what the result looks like:

λ> putStrLn $ jacksonGraphToDot mergeEx
digraph 
{
  graph [bgcolor="white"]
  node [shape="box" fillcolor="white" style="filled"]
  edge [weight="10" color="black" fontcolor="black"]
  "1" [label="streamSource (do {let {x'_0 = \"foo\"};
    threadDelay (1000 * 1000);
    putStrLn \"sending '\" ++ (x'_0 ++ \"'\");
    return x'_0})" xlabel=<<SUP>0.0</SUP>/<SUB>s</SUB>> fillcolor="#ffffff"]
  "2" [label="streamMap (id)" xlabel=<<SUP>1.0</SUP>/<SUB>s</SUB>> fillcolor="#ffffff"]
  "3" [label="streamSource (do {let {x'_0 = \"bar\"};
    threadDelay (1000 * 1000);
    putStrLn \"sending '\" ++ (x'_0 ++ \"'\");
    return x'_0})" xlabel=<<SUP>2.0</SUP>/<SUB>s</SUB>> fillcolor="#ffcccc"]
  "4" [label="streamMap (id)" xlabel=<<SUP>3.0</SUP>/<SUB>s</SUB>> fillcolor="#ffcccc"]
  "5" [label="streamMerge" xlabel=<<SUP>4.0</SUP>/<SUB>s</SUB>> fillcolor="#ffcccc"]
  "6" [label="streamSink (mapM_ print)" xlabel=<<SUP>5.0</SUP>/<SUB>s</SUB>> fillcolor="#ffcccc"]
  "1" -> "2" [label=<<SUP>1.0</SUP>/<SUB>s</SUB> <I>:: String</I>>]
  "2" -> "5" [label=<<SUP>2.0</SUP>/<SUB>s</SUB> <I>:: [String]</I>>]
  "3" -> "4" [label=<<SUP>1.0</SUP>/<SUB>s</SUB> <I>:: String</I>>]
  "4" -> "5" [label=<<SUP>2.0</SUP>/<SUB>s</SUB> <I>:: [String]</I>>]
  "5" -> "6" [label=<<SUP>2.0</SUP>/<SUB>s</SUB> <I>:: String</I>>]
}

alga

snowleopard commented 3 years ago

@jmtd Many thanks, the PR looks good! I left a couple of comments.

jmtd commented 3 years ago

Thanks for the quick review! I've addressed your comments and force-pushed an update.

snowleopard commented 3 years ago

Merged, thank you!