55 std::string_view defaultLabel) {
57 = [](
const std::string& given,
const std::string& byDefault) ->
const std::string& {
58 return given.empty() ? byDefault : given;
62 {
"size", pick(options.
size(), style.
size)},
66 const std::string label = options.
label().empty() ? std::string(defaultLabel) : options.
label();
68 graph.push_back({
"label", label});
82 std::string_view defaultLabel,
83 std::string_view defaultTooltip) {
86 const std::string label = (options !=
nullptr && !options->
label.empty())
88 : std::string(defaultLabel);
89 if (!label.empty()) attributes.push_back({
"label", label});
91 const std::string tooltip = (options !=
nullptr && !options->
tooltip.empty())
93 : std::string(defaultTooltip);
94 if (!tooltip.empty()) attributes.push_back({
"tooltip", tooltip});
96 if (options ==
nullptr)
return attributes;
98 if (!options->
bgColor.empty()) {
99 attributes.push_back({
"fillcolor", options->
bgColor});
103 }
else if (!options->
fgColor.empty()) {
104 attributes.push_back(
114 if (options ==
nullptr)
return attributes;
116 if (!options->
color.empty()) attributes.push_back({
"color", options->
color});
117 if (options->
width.has_value())
119 if (!options->
label.empty()) attributes.push_back({
"label", options->
label});
120 if (!options->
tooltip.empty()) attributes.push_back({
"tooltip", options->
tooltip});
128 for (
const auto& attribute: attributes)
129 if (attribute.key == key)
return;
130 attributes.insert(attributes.begin(), {std::string(key), std::string(value)});
The options given to a toDot(const DotOptions&).
const std::string & layout() const
direction of the layout, TB or LR
const std::string & label() const
direction of the layout, TB or LR
const std::string & size() const
direction of the layout, TB or LR
const std::string & rankDir() const
direction of the layout, TB or LR
Writes a graph in the dot language, statement after statement, in the order of the calls.
void nodeDefaults(const DotAttributes &attributes)
node [attributes];, the default attributes of the nodes that follow (none : does nothing).
void graphAttributes(const DotAttributes &attributes)
graph [attributes];, the attributes of the graph (does nothing if there is none).
void edgeDefaults(const DotAttributes &attributes)
edge [attributes];, the default attributes of the edges that follow (none : does nothing).
static std::string number(double value)
The shortest text that reads back as value (0.5, 1, 1e-05).
Colors of the graphs drawn with graphviz: reading of a color, brightness, readable text color.
The statements common to the graphs drawn with graphviz : preamble, attributes of nodes and arcs.
constexpr std::string_view ADAPTIVE_COLOR
the special value of a font color: black or white, according to the brightness of the background
std::vector< DotAttribute > DotAttributes
a list of attributes
std::string resolveFgColor(std::string_view fgColor, std::string_view bgColor, std::string_view fallback)
The font color to use on a background, once the special value adaptive is resolved.
DotAttributes nodeAttributes(const DotStyle &style, const DotNodeOptions *options, std::string_view defaultLabel, std::string_view defaultTooltip)
The attributes of a node : its label and tooltip, and its colors if the options give some.
void writePreamble(DotWriter &writer, const DotStyle &style, const DotOptions &options, std::string_view defaultLabel)
Writes the beginning of a graph, as pyAgrum displays it.
void addDefaultAttribute(DotAttributes &attributes, std::string_view key, std::string_view value)
Adds an attribute at the beginning of the list, unless the list already gives a value for this key : ...
DotAttributes arcAttributes(const DotArcOptions *options)
The attributes of an arc or an edge given by the options : color, penwidth, label,...
the options of an arc or an edge : an empty text (no value for the width) means "not given"
std::optional< double > width
DotAttributes attributes
other attributes, written after the ones above
the options of a node : an empty text means "not given", so that the value of the configuration is us...
std::string fgColor
font color (if only the background is given, the font color is adaptive against it)
std::string tooltip
text displayed when the mouse is over the node
std::string bgColor
background color
DotAttributes attributes
other attributes, written after the ones above
std::string label
text displayed in the node
The look shared by all the graphs: size, direction, layout, colors of the arcs and of the nodes.
std::string size
graphviz size of the graph, in inches (5, or 12! for an exact size)
std::string nodeFgColor
font color of the nodes
std::string layout
graphviz layout engine (dot, neato...)
std::string rankDir
direction of the layout : TB (top-bottom) or LR (left-right)
std::string nodeBgColor
background color of the nodes
std::string arcColor
color of the arcs and edges, and of the border of the nodes