smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Graphviz.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstdint>
6#include <string>
7#include <unordered_map>
8#include <unordered_set>
9
10#include "smgl/Graph.hpp"
11#include "smgl/Utilities.hpp"
12#include "smgl/filesystem.hpp"
13
14namespace smgl
15{
16
28
38
40struct FontStyle {
46 auto empty() const -> bool { return color.empty() and face.empty(); }
47};
48
62
101{
102public:
105
113 void setDefaultStyle(const NodeStyle& style);
117 auto defaultStyle() const -> const NodeStyle&;
135 void setClassStyle(const std::string& name, const NodeStyle& style);
137 template <class NodeT>
138 void setClassStyle(const NodeStyle& style);
140 auto hasClassStyle(const std::string& name) const -> bool;
142 template <class NodeT>
143 auto hasClassStyle() const -> bool;
145 void eraseClassStyle(const std::string& name);
147 template <class NodeT>
148 void eraseClassStyle() const;
154 auto classStyle(const std::string& name) -> NodeStyle&;
156 template <class NodeT>
157 auto classStyle() -> NodeStyle&;
163 auto classStyle(const std::string& name) const -> const NodeStyle&;
165 template <class NodeT>
166 auto classStyle() const -> const NodeStyle&;
183 void setInstanceStyle(const Node::Pointer& node, const NodeStyle& style);
185 void setInstanceStyle(const Node* node, const NodeStyle& style);
187 auto hasInstanceStyle(const Node::Pointer& node) const -> bool;
189 auto hasInstanceStyle(const Node* node) const -> bool;
191 void eraseInstanceStyle(const Node::Pointer& node);
193 void eraseInstanceStyle(const Node* node);
199 auto instanceStyle(const Node::Pointer& node) -> NodeStyle&;
205 auto instanceStyle(const Node::Pointer& node) const -> const NodeStyle&;
207 auto instanceStyle(const Node* node) -> NodeStyle&;
209 auto instanceStyle(const Node* node) const -> const NodeStyle&;
220 auto nodeStyle(const Node::Pointer& node) const -> NodeStyle;
222 auto nodeStyle(const Node* node) const -> NodeStyle;
234 template <typename... Args>
235 void setRankMin(const Args&... args);
236
241 template <typename... Args>
242 void setRankSource(const Args&... args);
243
245 template <typename... Args>
246 void setRankMax(const Args&... args);
247
252 template <typename... Args>
253 void setRankSink(const Args&... args);
254
262 template <typename... Args>
263 auto setRankSame(const Args&... args) -> std::size_t;
264
271 template <typename T, typename... Args>
272 void appendRankSame(T idx, const Args&... args);
273
275 auto rankMin() -> std::unordered_set<Uuid>&;
277 auto rankMin() const -> const std::unordered_set<Uuid>&;
278
280 auto rankSource() -> std::unordered_set<Uuid>&;
282 auto rankSource() const -> const std::unordered_set<Uuid>&;
283
285 auto rankMax() -> std::unordered_set<Uuid>&;
287 auto rankMax() const -> const std::unordered_set<Uuid>&;
288
290 auto rankSink() -> std::unordered_set<Uuid>&;
292 auto rankSink() const -> const std::unordered_set<Uuid>&;
293
295 auto rankSame() -> std::vector<std::vector<Uuid>>&;
297 auto rankSame() const -> const std::vector<std::vector<Uuid>>&;
300private:
304 std::unordered_map<std::string, NodeStyle> classStyles_;
308 std::unordered_set<Uuid> rankMin_;
310 std::unordered_set<Uuid> rankSrc_;
312 std::unordered_set<Uuid> rankMax_;
314 std::unordered_set<Uuid> rankSink_;
316 std::vector<std::vector<Uuid>> rankSame_;
317};
318
321 const filesystem::path& path,
322 const Graph& g,
323 const GraphStyle& style = GraphStyle());
324
325} // namespace smgl
326
327#include "smgl/GraphvizImpl.hpp"
Class defining a Graph's style when writing to a Dot file.
Definition Graphviz.hpp:101
void setRankMin(const Args &... args)
Assign node(s) to the minimum rank.
auto defaultStyle() const -> const NodeStyle &
Access the default node style.
auto hasClassStyle(const std::string &name) const -> bool
Check if a class of nodes has an associated style.
void appendRankSame(T idx, const Args &... args)
Assign node(s) to an existing group ranking.
void setRankMax(const Args &... args)
Assigns node(s) to the maximum rank.
void setInstanceStyle(const Node::Pointer &node, const NodeStyle &style)
Set a instance-specific node style.
auto rankSource() -> std::unordered_set< Uuid > &
Get the set of nodes assigned to the source rank.
void eraseInstanceStyle(const Node::Pointer &node)
Erase the style associated with a node instance.
std::unordered_map< std::string, NodeStyle > classStyles_
Definition Graphviz.hpp:304
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.
auto rankMax() -> std::unordered_set< Uuid > &
Get the set of nodes assigned to the maximum rank.
auto setRankSame(const Args &... args) -> std::size_t
Assign node(s) to a new group ranking.
std::unordered_set< Uuid > rankMax_
Definition Graphviz.hpp:312
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.
auto defaultStyle() -> NodeStyle &
Access the default node style.
GraphStyle()
Default constructor.
auto rankMin() -> std::unordered_set< Uuid > &
Get the set of nodes assigned to the minimum rank.
std::unordered_set< Uuid > rankMin_
Definition Graphviz.hpp:308
std::unordered_set< Uuid > rankSink_
Definition Graphviz.hpp:314
std::unordered_set< Uuid > rankSrc_
Definition Graphviz.hpp:310
void eraseClassStyle(const std::string &name)
Erase the style associated with a class of nodes.
auto hasInstanceStyle(const Node::Pointer &node) const -> bool
Check if a node has an associated instance style.
void setDefaultStyle(const NodeStyle &style)
Set the default node style.
std::vector< std::vector< Uuid > > rankSame_
Definition Graphviz.hpp:316
auto classStyle() -> NodeStyle &
Access the style for a class of nodes.
auto rankSame() -> std::vector< std::vector< Uuid > > &
Get the set of rank groups.
auto nodeStyle(const Node::Pointer &node) const -> NodeStyle
Get the evaluated node style for a specific node.
auto rankSink() -> std::unordered_set< Uuid > &
Get the set of nodes assigned to the sink rank.
auto instanceStyle(const Node::Pointer &node) -> NodeStyle &
Access the style for a node instance.
void setClassStyle(const std::string &name, const NodeStyle &style)
Set a class-specific node style.
std::unordered_map< Uuid, NodeStyle > instanceStyles_
Definition Graphviz.hpp:306
NodeStyle defaultStyle_
Definition Graphviz.hpp:302
A collection of Nodes for managing pipeline state and serialization.
Definition Graph.hpp:32
Generic Node class.
Definition Node.hpp:70
Universally unique identifier class.
Definition Uuid.hpp:18
T empty(T... args)
Project top-level namespace.
void WriteDotFile(const filesystem::path &path, const Graph &g, const GraphStyle &style=GraphStyle())
Write Graph to a file in the Graphviz Dot format.
ISO C++ top-level namespace.
Style struct for a node's base style.
Definition Graphviz.hpp:30
std::uint8_t cellspacing
Sub-element border spacing [0, 255].
Definition Graphviz.hpp:36
std::uint8_t cellpadding
Sub-element border padding [0, 255].
Definition Graphviz.hpp:34
std::uint8_t cellborder
Sub-element border thickness [0, 255].
Definition Graphviz.hpp:32
Style struct for ports and labels.
Definition Graphviz.hpp:18
std::string align
Text alignment.
Definition Graphviz.hpp:20
std::string color
Element border color.
Definition Graphviz.hpp:26
std::string bgcolor
Element background color.
Definition Graphviz.hpp:22
std::uint8_t border
Element border thickness [0, 255].
Definition Graphviz.hpp:24
Style struct for a node's overall font style.
Definition Graphviz.hpp:40
std::string face
Font typeface.
Definition Graphviz.hpp:44
std::string color
Font color.
Definition Graphviz.hpp:42
auto empty() const -> bool
Returns whether or not this style has an values set.
Definition Graphviz.hpp:46
Style struct containing all sub-styles for a node.
Definition Graphviz.hpp:50
ElementStyle label
Label-specific style.
Definition Graphviz.hpp:58
BaseStyle base
Base style for the node.
Definition Graphviz.hpp:52
ElementStyle inputPorts
InputPort-specific style.
Definition Graphviz.hpp:56
FontStyle font
Base font style for this node.
Definition Graphviz.hpp:54
ElementStyle outputPorts
OutputPort-specific style.
Definition Graphviz.hpp:60