smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
smgl::GraphStyle Class Reference

Class defining a Graph's style when writing to a Dot file. More...

#include <smgl/Graphviz.hpp>

Collaboration diagram for smgl::GraphStyle:
[legend]

Public Member Functions

 GraphStyle ()
 Default constructor.
 
Default Node Style

The properties defined in the default node style are applied to all nodes.

void setDefaultStyle (const NodeStyle &style)
 Set the default node style.
 
auto defaultStyle () -> NodeStyle &
 Access the default node style.
 
auto defaultStyle () const -> const NodeStyle &
 Access the default node style.
 
Class-specific Node Styles

The properties defined in a class-specific node style are applied to all nodes of a specific class and take precedence over properties defined in the default node style.

void setClassStyle (const std::string &name, const NodeStyle &style)
 Set a class-specific node style.
 
template<class NodeT >
void setClassStyle (const NodeStyle &style)
 Set a class-specific node style.
 
auto hasClassStyle (const std::string &name) const -> bool
 Check if a class of nodes has an associated style.
 
template<class NodeT >
auto hasClassStyle () const -> bool
 Check if a class of nodes has an associated style.
 
void eraseClassStyle (const std::string &name)
 Erase the style associated with a class of nodes.
 
template<class NodeT >
void eraseClassStyle () const
 Erase the style associated with a class of nodes.
 
auto classStyle (const std::string &name) -> NodeStyle &
 Access the style for a class of nodes.
 
template<class NodeT >
auto classStyle () -> NodeStyle &
 Access the style for a class of nodes.
 
auto classStyle (const std::string &name) const -> const NodeStyle &
 Access the style for a class of nodes.
 
template<class NodeT >
auto classStyle () const -> const NodeStyle &
 Access the style for a class of nodes.
 
Instance-specific Node Styles

The properties defined in an instance-specific node style are only applied to a specific node instance as determined by its smgl::Uuid. These properties take precedence over the properties defined in the default and class-specific node styles.

void setInstanceStyle (const Node::Pointer &node, const NodeStyle &style)
 Set a instance-specific node style.
 
void setInstanceStyle (const Node *node, const NodeStyle &style)
 Set a instance-specific node style.
 
auto hasInstanceStyle (const Node::Pointer &node) const -> bool
 Check if a node has an associated instance style.
 
auto hasInstanceStyle (const Node *node) const -> bool
 Check if a node has an associated instance style.
 
void eraseInstanceStyle (const Node::Pointer &node)
 Erase the style associated with a node instance.
 
void eraseInstanceStyle (const Node *node)
 Erase the style associated with a node instance.
 
auto instanceStyle (const Node::Pointer &node) -> NodeStyle &
 Access the style for a node instance.
 
auto instanceStyle (const Node::Pointer &node) const -> const NodeStyle &
 Access the style for a node instance.
 
auto instanceStyle (const Node *node) -> NodeStyle &
 Access the style for a node instance.
 
auto instanceStyle (const Node *node) const -> const NodeStyle &
 Access the style for a node instance.
 
Evaluated Node Style

The evaluated node style represents the final style for a specific node after all property precedence relationships have been resolved. This is the style used by smgl::WriteDotFile.

auto nodeStyle (const Node::Pointer &node) const -> NodeStyle
 Get the evaluated node style for a specific node.
 
auto nodeStyle (const Node *node) const -> NodeStyle
 Get the evaluated node style for a specific node.
 
Node Placement

Allows basic placement of nodes according to manually defined rank rules. See the Graphviz rank documentation for more information.

template<typename... Args>
void setRankMin (const Args &... args)
 Assign node(s) to the minimum rank.
 
template<typename... Args>
void setRankSource (const Args &... args)
 Assign node(s) to the minimum rank and limits the minimum rank to nodes with rank=min or rank=source.
 
template<typename... Args>
void setRankMax (const Args &... args)
 Assigns node(s) to the maximum rank.
 
template<typename... Args>
void setRankSink (const Args &... args)
 Assign node(s) to the maximum rank and limits the maximum rank to nodes with rank=max or rank=sink.
 
template<typename... Args>
auto setRankSame (const Args &... args) -> std::size_t
 Assign node(s) to a new group ranking.
 
template<typename T , typename... Args>
void appendRankSame (T idx, const Args &... args)
 Assign node(s) to an existing group ranking.
 
auto rankMin () -> std::unordered_set< Uuid > &
 Get the set of nodes assigned to the minimum rank.
 
auto rankMin () const -> const std::unordered_set< Uuid > &
 Get the set of nodes assigned to the minimum rank.
 
auto rankSource () -> std::unordered_set< Uuid > &
 Get the set of nodes assigned to the source rank.
 
auto rankSource () const -> const std::unordered_set< Uuid > &
 Get the set of nodes assigned to the source rank.
 
auto rankMax () -> std::unordered_set< Uuid > &
 Get the set of nodes assigned to the maximum rank.
 
auto rankMax () const -> const std::unordered_set< Uuid > &
 Get the set of nodes assigned to the maximum rank.
 
auto rankSink () -> std::unordered_set< Uuid > &
 Get the set of nodes assigned to the sink rank.
 
auto rankSink () const -> const std::unordered_set< Uuid > &
 Get the set of nodes assigned to the sink rank.
 
auto rankSame () -> std::vector< std::vector< Uuid > > &
 Get the set of rank groups.
 
auto rankSame () const -> const std::vector< std::vector< Uuid > > &
 Get the set of rank groups.
 

Private Attributes

NodeStyle defaultStyle_
 
std::unordered_map< std::string, NodeStyleclassStyles_
 
std::unordered_map< Uuid, NodeStyleinstanceStyles_
 
std::unordered_set< UuidrankMin_
 
std::unordered_set< UuidrankSrc_
 
std::unordered_set< UuidrankMax_
 
std::unordered_set< UuidrankSink_
 
std::vector< std::vector< Uuid > > rankSame_
 

Detailed Description

Class defining a Graph's style when writing to a Dot file.

This class enables global, class, and instance level styling of Nodes in a Dot file by setting a default style and, optionally, a class-specific or instance-specific style. When determining the final style, class-specific properties take precedence over default properties, and instance-specific properties take precedence over class-specific properties.

// Setup a graph
auto a = g.insertNode<IntNode>();
auto b = g.insertNode<IntNode>();
auto c = g.insertNode<FloatNode>();
// Global style
GraphStyle style;
style.defaultStyle().base.bgcolor = "red";
// Class-specific style
style.classStyle<IntNode>().base.bgcolor = "white";
// Instance-specific style
style.instanceStyle(a).base.bgcolor = "blue";
style.instanceStyle(a).font.color = "white";
// Write the graph
WriteDotFile("StyledGraph.gv", g, style);
Class defining a Graph's style when writing to a Dot file.
Definition Graphviz.hpp:101
auto defaultStyle() -> NodeStyle &
Access the default node style.
A collection of Nodes for managing pipeline state and serialization.
Definition Graph.hpp:32
void insertNode(const Node::Pointer &n)
Add a Node to the Graph.
void WriteDotFile(const filesystem::path &path, const Graph &g, const GraphStyle &style=GraphStyle())
Write Graph to a file in the Graphviz Dot format.
Warning
Neither this class nor smgl::WriteDotFile makes any effort to validate the values set in style properties. For more information on valid property values, see the Doxygen documentation for HTML-like labels.

Definition at line 100 of file Graphviz.hpp.

Member Function Documentation

◆ appendRankSame()

template<typename T , typename... Args>
void smgl::GraphStyle::appendRankSame ( idx,
const Args &...  args 
)

Assign node(s) to an existing group ranking.

Assign the node(s) to an existing group ranking created with setRankSame().

Definition at line 131 of file GraphvizImpl.hpp.

◆ classStyle() [1/4]

template<class NodeT >
auto smgl::GraphStyle::classStyle ( ) -> NodeStyle&

Access the style for a class of nodes.

If a style has not been set, one is created and returned.

Definition at line 25 of file GraphvizImpl.hpp.

◆ classStyle() [2/4]

template<class NodeT >
auto smgl::GraphStyle::classStyle ( ) const -> const NodeStyle&

Access the style for a class of nodes.

Exceptions
std::out_of_rangeif a style has not been set

Definition at line 31 of file GraphvizImpl.hpp.

◆ classStyle() [3/4]

auto smgl::GraphStyle::classStyle ( const std::string name) -> NodeStyle &

Access the style for a class of nodes.

If a style has not been set, one is created and returned.

◆ classStyle() [4/4]

auto smgl::GraphStyle::classStyle ( const std::string name) const -> const NodeStyle &

Access the style for a class of nodes.

Exceptions
std::out_of_rangeif a style has not been set

◆ defaultStyle()

auto smgl::GraphStyle::defaultStyle ( ) const -> const NodeStyle &

Access the default node style.

◆ eraseClassStyle()

template<class NodeT >
void smgl::GraphStyle::eraseClassStyle ( ) const

Erase the style associated with a class of nodes.

Definition at line 19 of file GraphvizImpl.hpp.

◆ eraseInstanceStyle()

void smgl::GraphStyle::eraseInstanceStyle ( const Node node)

Erase the style associated with a node instance.

◆ hasClassStyle()

template<class NodeT >
auto smgl::GraphStyle::hasClassStyle ( ) const -> bool

Check if a class of nodes has an associated style.

Definition at line 13 of file GraphvizImpl.hpp.

◆ hasInstanceStyle()

auto smgl::GraphStyle::hasInstanceStyle ( const Node node) const -> bool

Check if a node has an associated instance style.

◆ instanceStyle() [1/4]

auto smgl::GraphStyle::instanceStyle ( const Node node) -> NodeStyle &

Access the style for a node instance.

If a style has not been set, one is created and returned.

◆ instanceStyle() [2/4]

auto smgl::GraphStyle::instanceStyle ( const Node node) const -> const NodeStyle &

Access the style for a node instance.

Exceptions
std::out_of_rangeif a style has not been set

◆ instanceStyle() [3/4]

auto smgl::GraphStyle::instanceStyle ( const Node::Pointer node) -> NodeStyle &

Access the style for a node instance.

If a style has not been set, one is created and returned.

◆ instanceStyle() [4/4]

auto smgl::GraphStyle::instanceStyle ( const Node::Pointer node) const -> const NodeStyle &

Access the style for a node instance.

Exceptions
std::out_of_rangeif a style has not been set

◆ rankMax()

auto smgl::GraphStyle::rankMax ( ) const -> const std::unordered_set< Uuid > &

Get the set of nodes assigned to the maximum rank.

◆ rankMin()

auto smgl::GraphStyle::rankMin ( ) const -> const std::unordered_set< Uuid > &

Get the set of nodes assigned to the minimum rank.

◆ rankSame()

auto smgl::GraphStyle::rankSame ( ) const -> const std::vector< std::vector< Uuid > > &

Get the set of rank groups.

◆ rankSink()

auto smgl::GraphStyle::rankSink ( ) const -> const std::unordered_set< Uuid > &

Get the set of nodes assigned to the sink rank.

◆ rankSource()

auto smgl::GraphStyle::rankSource ( ) const -> const std::unordered_set< Uuid > &

Get the set of nodes assigned to the source rank.

◆ setClassStyle() [1/2]

template<class NodeT >
void smgl::GraphStyle::setClassStyle ( const NodeStyle style)

Set a class-specific node style.

Sets the style for all nodes of a particular class. Nodes of a particular class are identified using the serialization name register. If unknown, the node's class name in the register can be determined using smgl::NodeName.

Definition at line 7 of file GraphvizImpl.hpp.

◆ setClassStyle() [2/2]

void smgl::GraphStyle::setClassStyle ( const std::string name,
const NodeStyle style 
)

Set a class-specific node style.

Sets the style for all nodes of a particular class. Nodes of a particular class are identified using the serialization name register. If unknown, the node's class name in the register can be determined using smgl::NodeName.

◆ setInstanceStyle() [1/2]

void smgl::GraphStyle::setInstanceStyle ( const Node node,
const NodeStyle style 
)

Set a instance-specific node style.

Sets the style for a single node instance. A node instance is identified using its smgl::Uuid.

◆ setInstanceStyle() [2/2]

void smgl::GraphStyle::setInstanceStyle ( const Node::Pointer node,
const NodeStyle style 
)

Set a instance-specific node style.

Sets the style for a single node instance. A node instance is identified using its smgl::Uuid.

◆ setRankMax()

template<typename... Args>
void smgl::GraphStyle::setRankMax ( const Args &...  args)

Assigns node(s) to the maximum rank.

Definition at line 73 of file GraphvizImpl.hpp.

◆ setRankMin()

template<typename... Args>
void smgl::GraphStyle::setRankMin ( const Args &...  args)

Assign node(s) to the minimum rank.

Definition at line 37 of file GraphvizImpl.hpp.

◆ setRankSame()

template<typename... Args>
auto smgl::GraphStyle::setRankSame ( const Args &...  args) -> std::size_t

Assign node(s) to a new group ranking.

Creates a new rank group and assigns the node(s) to that group. Returns the index of the group ranking so that nodes can be appended to the group with appendRankSame().

Definition at line 109 of file GraphvizImpl.hpp.

◆ setRankSink()

template<typename... Args>
void smgl::GraphStyle::setRankSink ( const Args &...  args)

Assign node(s) to the maximum rank and limits the maximum rank to nodes with rank=max or rank=sink.

Definition at line 91 of file GraphvizImpl.hpp.

◆ setRankSource()

template<typename... Args>
void smgl::GraphStyle::setRankSource ( const Args &...  args)

Assign node(s) to the minimum rank and limits the minimum rank to nodes with rank=min or rank=source.

Definition at line 55 of file GraphvizImpl.hpp.

Member Data Documentation

◆ classStyles_

std::unordered_map<std::string, NodeStyle> smgl::GraphStyle::classStyles_
private

Class-specific node styles

Definition at line 304 of file Graphviz.hpp.

◆ defaultStyle_

NodeStyle smgl::GraphStyle::defaultStyle_
private

Default node style

Definition at line 302 of file Graphviz.hpp.

◆ instanceStyles_

std::unordered_map<Uuid, NodeStyle> smgl::GraphStyle::instanceStyles_
private

Instance-specific node styles

Definition at line 306 of file Graphviz.hpp.

◆ rankMax_

std::unordered_set<Uuid> smgl::GraphStyle::rankMax_
private

rank=max nodes

Definition at line 312 of file Graphviz.hpp.

◆ rankMin_

std::unordered_set<Uuid> smgl::GraphStyle::rankMin_
private

rank=min nodes

Definition at line 308 of file Graphviz.hpp.

◆ rankSame_

std::vector<std::vector<Uuid> > smgl::GraphStyle::rankSame_
private

rank=same node groups

Definition at line 316 of file Graphviz.hpp.

◆ rankSink_

std::unordered_set<Uuid> smgl::GraphStyle::rankSink_
private

rank=sink nodes

Definition at line 314 of file Graphviz.hpp.

◆ rankSrc_

std::unordered_set<Uuid> smgl::GraphStyle::rankSrc_
private

rank=source nodes

Definition at line 310 of file Graphviz.hpp.


The documentation for this class was generated from the following files: