Graphvix.DotHelpers (graphvix v1.1.0)
This module contains a set of helper methods for converting Elixir graph data into its DOT representation.
Link to this section Summary
Functions
Convert a single atribute to DOT format for inclusion in a list of attributes.
Converts a list of attributes into a properly formatted list of DOT attributes.
Removes all nil
elements from an list.
Maps a collection of vertices or nodes to their correct DOT format.
Convert top-level node and edge properties for a graph or subgraph into correct DOT notation.
Indent a single line or block of text.
Returns nil if an empty list is passed in. Returns the elements of the list
joined by the optional second parameter (defaults to otherwise.
Takes a list of elements returned from the vertex or edge table and sorts them by their ID.
Link to this section Functions
attribute_to_dot(key, value)
Convert a single atribute to DOT format for inclusion in a list of attributes.
examples
Examples
iex> DotHelpers.attribute_to_dot(:color, "blue")
~S(color="blue")
There is one special case this function handles, which is the label for a record
using HTML to build a table. In this case the generated HTML label must be
surrounded by a set of angle brackets < ... >
instead of double quotes.
iex> DotHelpers.attribute_to_dot(:label, "<table></table>")
"label=<<table></table>>"
attributes_to_dot(attributes)
Converts a list of attributes into a properly formatted list of DOT attributes.
examples
Examples
iex> DotHelpers.attributes_to_dot(color: "blue", shape: "circle")
~S([color="blue",shape="circle"])
compact(enum)
Removes all nil
elements from an list.
examples
Examples
iex> DotHelpers.compact([])
[]
iex> DotHelpers.compact(["a", nil, "b", nil, 1])
["a", "b", 1]
elements_to_dot(table, formatting_func)
Maps a collection of vertices or nodes to their correct DOT format.
The first argument is a reference to an ETS table or the list of results from an ETS table. The second argument is the function used to format each element in the collection.
global_properties_to_dot(graph)
Convert top-level node and edge properties for a graph or subgraph into correct DOT notation.
example
Example
iex> graph = Graph.new(edge: [color: "green", style: "dotted"], node: [color: "blue"])
iex> DotHelpers.global_properties_to_dot(graph)
~S( node [color="blue"]
edge [color="green",style="dotted"])
indent(string, depth \\ 1)
Indent a single line or block of text.
An optional second argument can be provided to tell the function how deep to indent (defaults to one level).
examples
Examples
iex> DotHelpers.indent("hello")
" hello"
iex> DotHelpers.indent("hello", 3)
" hello"
iex> DotHelpers.indent("line one\n line two\nline three")
" line one\n line two\n line three"
return_joined_list_or_nil(list, joiner \\ "\n")
Returns nil if an empty list is passed in. Returns the elements of the list
joined by the optional second parameter (defaults to otherwise.
examples
Examples
iex> DotHelpers.return_joined_list_or_nil([])
nil
iex> DotHelpers.return_joined_list_or_nil([], "-")
nil
iex> DotHelpers.return_joined_list_or_nil(["a", "b", "c"])
"a\nb\nc"
iex> DotHelpers.return_joined_list_or_nil(["a", "b", "c"], "-")
"a-b-c"
sort_elements_by_id(elements)
Takes a list of elements returned from the vertex or edge table and sorts them by their ID.
This ensures that vertices and edges are written into the .dot
file in the
same order they were added to the ETS tables. This is important as the order
of vertices and edges in a .dot
file can ultimately affect the final
layout of the graph.