graphvix v1.0.0 Graphvix.HTMLRecord

Models a graph vertex that uses HTML to generate a table-shaped record.

Table structure

The Graphviz API allows the basic table-related HTML elements:

  • <table>
  • <tr>
  • <th>

and the Graphvix API provides the parallel functions:

Example

iex> import Graphvix.HTMLRecord, only: [tr: 1, td: 1, td: 2]
iex> record = HTMLRecord.new([
iex>   tr([
...>     td("a"),
...>     td("b")
...>   ]),
...>   tr([
...>     td("c"),
...>     td("d")
...>   ]),
...> ])
iex> HTMLRecord.to_label(record)
~S(<table>
  <tr>
    <td>a</td>
    <td>b</td>
  </tr>
  <tr>
    <td>c</td>
    <td>d</td>
  </tr>
</table>)

Ports

As with Graphvix.Record vertices, port names can be attached to cells. With HTMLRecord vertices, this is done by passing a :port key as one of the attributes in the second argument keyword list for td/2.

iex> import Graphvix.HTMLRecord, only: [tr: 1, td: 1, td: 2]
iex> record = HTMLRecord.new([
iex>   tr([td("a"), td("b")]),
...>   tr([td("c", port: "port_c"), td("d")]),
...> ])
iex> HTMLRecord.to_label(record)
~S(<table>
  <tr>
    <td>a</td>
    <td>b</td>
  </tr>
  <tr>
    <td port="port_c">c</td>
    <td>d</td>
  </tr>
</table>)

In addition to :port, values for existing HTML keys

  • border
  • cellpadding
  • cellspacing

can be added to cells, and

  • border
  • cellborder
  • cellpadding
  • cellspacing

can be added to the table at the top-level to style the table and cells.

Text formatting

Aside from structuring the table, two elements are available for formatting the content of the cells

  • <font>
  • <br/>

with corresponding Graphvix.HTMLRecord functions

In addition to contents as its first argument, font/2 can take a keyword list of properties as its optional second argument.

iex> import Graphvix.HTMLRecord, only: [tr: 1, td: 1, td: 2, br: 0, font: 2]
iex> record = HTMLRecord.new([
iex>   tr([td("a"), td(["b", br(), font("B", color: "red", point_size: 100)])]),
...>   tr([td("c"), td("d")]),
...> ])
iex> HTMLRecord.to_label(record)
~S(<table>
  <tr>
    <td>a</td>
    <td>b<br/><font color="red" point-size="100">B</font></td>
  </tr>
  <tr>
    <td>c</td>
    <td>d</td>
  </tr>
</table>)

While maintaining proper nesting (each element contains both opening and closing tags within its enclosing element), these elements may be nested as desired, including nesting entire tables inside of cells.

Link to this section Summary

Functions

Creates a <br/> element as part of a cell in an HTMLRecord

Creates a <font/> element as part of a cell in an HTMLRecord

Returns a new HTMLRecord which can be turned into an HTML table vertex

A helper method to generate a single cell of a table

Converts an HTMLRecord struct into a valid HTML-like string

A helper method to generate a row of a table

Link to this section Types

Link to this type br()
br() :: %{tag: :br}
Link to this type font()
font() :: %{
  tag: :font,
  cell: Graphvix.HTMLRecord.one_or_more_cells(),
  attributes: keyword()
}
Link to this type one_or_more_cells()
one_or_more_cells() :: Graphvix.HTMLRecord.cell() | [Graphvix.HTMLRecord.cell()]
Link to this type t()
t() :: %Graphvix.HTMLRecord{
  attributes: keyword(),
  rows: [Graphvix.HTMLRecord.tr()]
}
Link to this type td()
td() :: %{label: Graphvix.HTMLRecord.one_or_more_cells(), attributes: keyword()}

Link to this section Functions

Creates a <br/> element as part of a cell in an HTMLRecord

A helper method that creates a <br/> HTML element as part of a table cell.

See the module documentation for Graphvix.HTMLRecord for usage examples in context.

Link to this function font(cell, attributes \\ [])

Creates a <font/> element as part of a cell in an HTMLRecord

A helper method that creates a <br/> HTML element as part of a table cell.

The first argument to font/2 is the contents of the cell, which can itself be a plain string or a list of nested element functions.

The second, optional argument is a keyword list of attributes to determine the formatting of the contents of the <tag>. Valid keys for this list are

  • color
  • face
  • point_size

Example

iex> HTMLRecord.font("a", color: "blue", face: "Arial", point_size: 10)
%{tag: :font, cell: "a", attributes: [color: "blue", face: "Arial", point_size: 10]}
Link to this function new(rows, attributes \\ [])

Returns a new HTMLRecord which can be turned into an HTML table vertex.

It takes two arguments. The first is a list of table rows all returned from the tr/1 function.

The second is an optional keyword list of attributes to apply to the table as a whole. Valid keys for this list are:

  • align
  • bgcolor
  • border
  • cellborder
  • cellpadding
  • cellspacing
  • color
  • columns
  • fixedsize
  • gradientangle
  • height
  • href
  • id
  • port
  • rows
  • sides
  • style
  • target
  • title
  • tooltip
  • valign
  • width

Example

iex> import HTMLRecord, only: [tr: 1, td: 1]
iex> HTMLRecord.new([
...>   tr([
...>     td("a"),
...>     td("b")
...>   ]),
...>   tr([
...>     td("c"),
...>     td("d")
...>   ])
...> ], border: 1, cellspacing: 0, cellborder: 1)
%HTMLRecord{
  rows: [
    %{cells: [
      %{label: "a", attributes: []},
      %{label: "b", attributes: []},
    ]},
    %{cells: [
      %{label: "c", attributes: []},
      %{label: "d", attributes: []},
    ]}
  ],
  attributes: [
    border: 1,
    cellspacing: 0,
    cellborder: 1
  ]
}
Link to this function td(label, attributes \\ [])

A helper method to generate a single cell of a table.

The first argument is the contents of the cell. It can be a plain string or a list of other elements.

The second argument is an optional keyword list of attributes to apply to the cell. Valid keys include:

  • align
  • balign
  • bgcolor
  • border
  • cellpadding
  • cellspacing
  • color
  • colspan
  • fixedsize
  • gradientangle
  • height
  • href
  • id
  • port
  • rowspan
  • sides
  • style
  • target
  • title
  • tooltip
  • valign
  • width

See the module documentation for Graphvix.HTMLRecord for usage examples in context.

Link to this function to_label(html_record)

Converts an HTMLRecord struct into a valid HTML-like string.

The resulting string can be passed to Graphvix.Graph.add_vertex/3 as a label for a vertex.

Example

iex> import HTMLRecord, only: [tr: 1, td: 1]
iex> record = HTMLRecord.new([
...>   tr([
...>     td("a"),
...>     td("b")
...>   ]),
...>   tr([
...>     td("c"),
...>     td("d")
...>   ])
...> ], border: 1, cellspacing: 0, cellborder: 1)
iex> HTMLRecord.to_label(record)
~S(<table border="1" cellspacing="0" cellborder="1">
  <tr>
    <td>a</td>
    <td>b</td>
  </tr>
  <tr>
    <td>c</td>
    <td>d</td>
  </tr>
</table>)

A helper method to generate a row of a table.

It takes a single argument, which is a list of cells returned by the td/2 helper function.