This module provides a means of converting the Graph
data type into a
valid DOT
string for visualizing your graph structure.
You can easily preview your graph by inserting the generated string into an online GraphViz tool like https://dreampuf.github.io/GraphvizOnline/.
You can also dynamically draw your graph in your application by sending the string over a port to the javascript version of the GraphViz library, https://github.com/mdaines/viz.js/ (see the examples there fore more specifics on how to embed the generated visualization).
output : (n -> Maybe String) -> (e -> Maybe String) -> Graph n e -> String
Converts a Graph
into a valid DOT string.
Note that you must supply conversion functions for node labels and edge labels
to Maybe String
s.
When a conversion function returns Nothing
, no label attribute is output.
For nodes, GraphViz falls back to displaying node ids.
For edges, no label is displayed.
GraphViz allows for customizing the graph's look via "Attrs."
{ rankdir : Rankdir
, graph : String
, node : String
, edge : String
}
A type representing the attrs to apply at the graph, node, and edge entities (subgraphs and cluster subgraphs are not supported).
Note that Styles
is made up of strings, which loses type safety, but
allows you to use any GraphViz attrs without having to model them out in
entirety in this module. It is up to you to make sure you provide valid
attr strings. See http://www.graphviz.org/content/attrs for available
options.
Values to control the direction of the graph
defaultStyles : Styles
A blank Styles
record to build from to define your own styles.
myStyles =
{ defaultStyles
| node = "shape=box, color=blue, style=\"rounded, filled\""
}
outputWithStyles : Styles -> (n -> Maybe String) -> (e -> Maybe String) -> Graph n e -> String
Same as output
, but allows you to add attrs to the graph.
These attrs will be applied to the entire graph.
outputWithStylesAndAttributes : Styles -> (n -> Dict String String) -> (e -> Dict String String) -> Graph n e -> String
Same as outputWithStyles
, but allows each node and edge to include its
own attrs. Note that you must supply a conversion function for node and edge
labels that return a Dict String String
of the attribute mappings.
Note that you have to take care of setting the appropriate node and edge labels yourself.