aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
dotStyle.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
47#include <cstdint>
48
52
53namespace gum::dot {
54
55 namespace {
56 std::string _str_(std::string_view section, std::string_view key) {
57 return gum::config().get(section, key);
58 }
59
60 template < typename T >
61 T _typed_(std::string_view section, std::string_view key) {
62 return gum::config().typed< T >(section, key);
63 }
64
65 // the part of the style which comes from the section `notebook`
66 DotStyle _notebook_() {
67 DotStyle style;
68 style.size = _str_("notebook", "graphSize");
69 style.rankDir = _str_("notebook", "graphRankDir");
70 style.layout = _str_("notebook", "graphLayout");
71 style.arcColor = _str_("notebook", "arcColor");
72 style.nodeBgColor = _str_("notebook", "nodeBgColor");
73 style.nodeFgColor = configFgColor("notebook", "nodeFgColor");
74 return style;
75 }
76 } // namespace
77
78 std::string configFgColor(std::string_view section, std::string_view key) {
79 constexpr std::string_view fgSuffix = "FgColor";
80 if (!key.ends_with(fgSuffix)) {
81 GUM_ERROR(InvalidArgument, "The key '" << key << "' of a font color must end with FgColor")
82 }
83 const std::string bgKey = std::string(key.substr(0, key.size() - fgSuffix.size())) + "BgColor";
84 return resolveFgColor(_str_(section, key),
85 _str_(section, bgKey),
86 _str_("notebook", "arcColor"));
87 }
88
89 DotStyle DotStyle::read() { return _notebook_(); }
90
92 DotStyle style = _notebook_();
93 style.nodeBgColor = _str_("credalnet", "nodeBgColor");
94 style.nodeFgColor = configFgColor("credalnet", "nodeFgColor");
95 return style;
96 }
97
100 static_cast< DotStyle& >(style) = _notebook_();
101 style.size = _str_("notebook", "junctionTreeGraphSize");
102
103 style.withNames = _typed_< bool >("notebook", "junctionTreeWithNames");
104 style.separatorBgColor = _str_("notebook", "junctionTreeSeparatorBgColor");
105 style.separatorFgColor = configFgColor("notebook", "junctionTreeSeparatorFgColor");
107 = static_cast< int >(_typed_< std::int64_t >("notebook", "junctionTreeSeparatorFontSize"));
108 style.cliqueBgColor = _str_("notebook", "junctionTreeCliqueBgColor");
109 style.cliqueFgColor = configFgColor("notebook", "junctionTreeCliqueFgColor");
110 style.cliqueFontSize
111 = static_cast< int >(_typed_< std::int64_t >("notebook", "junctionTreeCliqueFontSize"));
112
113 style.mapCliqueScale = _typed_< double >("notebook", "junctionTreeMapCliqueScale");
114 style.mapSepScale = _typed_< double >("notebook", "junctionTreeMapSepScale");
115 style.mapEdgeLen = _typed_< double >("notebook", "junctionTreeMapEdgeLen");
116 style.mapSize = _str_("notebook", "junctionTreeMapSize");
117 return style;
118 }
119
122 static_cast< DotStyle& >(style) = _notebook_();
123 style.layout = _str_("factorgraph", "graphLayout");
124 style.nodeBgColor = _str_("factorgraph", "nodeBgColor");
125 style.nodeFgColor = configFgColor("factorgraph", "nodeFgColor");
126
127 style.factorBgColor = _str_("factorgraph", "factorBgColor");
129 style.edgeLength = _typed_< double >("factorgraph", "edgeLength");
130 return style;
131 }
132
135 static_cast< DotStyle& >(style) = _notebook_();
136 style.size = _str_("influenceDiagram", "graphSize");
137
138 style.chanceBgColor = _str_("influenceDiagram", "chanceBgColor");
139 style.chanceFgColor = configFgColor("influenceDiagram", "chanceFgColor");
140 style.chanceShape = _str_("influenceDiagram", "chanceShape");
141
142 style.utilityBgColor = _str_("influenceDiagram", "utilityBgColor");
143 style.utilityFgColor = configFgColor("influenceDiagram", "utilityFgColor");
144 style.utilityShape = _str_("influenceDiagram", "utilityShape");
145
146 style.decisionBgColor = _str_("influenceDiagram", "decisionBgColor");
147 style.decisionFgColor = configFgColor("influenceDiagram", "decisionFgColor");
148 style.decisionShape = _str_("influenceDiagram", "decisionShape");
149
150 style.decisionArcStyle = _str_("influenceDiagram", "decisionArcStyle");
151 style.utilityArcStyle = _str_("influenceDiagram", "utilityArcStyle");
152 return style;
153 }
154
156 CausalDotStyle style;
157 static_cast< DotStyle& >(style) = _notebook_();
158 style.size = _str_("causal", "graphSize");
159 style.nodeBgColor = _str_("causal", "nodeBgColor");
160 style.nodeFgColor = configFgColor("causal", "nodeFgColor");
161
162 style.latentBgColor = _str_("causal", "latentBgColor");
163 style.latentFgColor = configFgColor("causal", "latentFgColor");
164 style.showLatentNames = _typed_< bool >("causal", "showLatentNames");
165 return style;
166 }
167
169 DynamicBNDotStyle style;
170 static_cast< DotStyle& >(style) = _notebook_();
171 style.size = _str_("dynamicBN", "graphSize");
172
173 style.timeSliceBgColor = _str_("dynamicBN", "timeSliceBgColor");
174 style.replicatedSliceBgColor = _str_("dynamicBN", "replicatedSliceBgColor");
175 style.atemporalBgColor = _str_("dynamicBN", "atemporalBgColor");
176 return style;
177 }
178
179} // namespace gum::dot
T typed(std::string_view section, std::string_view key) const
Value of section.key converted according to its declared type.
std::string get(std::string_view section, std::string_view key) const
Value of section.key, as a string.
Exception: at least one argument passed to a function is not what was expected.
Typed, documented, sectioned configuration singleton read from an .ini content.
Colors of the graphs drawn with graphviz: reading of a color, brightness, readable text color.
Look of the graphs drawn with graphviz, read from the configuration.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
constexpr std::string_view ADAPTIVE_COLOR
the special value of a font color: black or white, according to the brightness of the background
Definition dotColor.h:68
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.
Definition dotColor.cpp:280
std::string configFgColor(std::string_view section, std::string_view key)
A font color of the configuration, resolved against the background color which goes with it.
Definition dotStyle.cpp:78
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...
The style of a causal model (section causal): nodeBgColor and nodeFgColor are the ones of the observe...
Definition dotStyle.h:153
std::string latentBgColor
Definition dotStyle.h:154
std::string latentFgColor
Definition dotStyle.h:155
static CausalDotStyle read()
Definition dotStyle.cpp:155
bool showLatentNames
show the names of the latent variables
Definition dotStyle.h:157
The look shared by all the graphs: size, direction, layout, colors of the arcs and of the nodes.
Definition dotStyle.h:76
std::string size
graphviz size of the graph, in inches (5, or 12! for an exact size)
Definition dotStyle.h:78
std::string nodeFgColor
font color of the nodes
Definition dotStyle.h:88
std::string layout
graphviz layout engine (dot, neato...)
Definition dotStyle.h:82
static DotStyle readCredalNet()
the style of the credal networks : the colors of the nodes are the ones of the section credalnet
Definition dotStyle.cpp:91
static DotStyle read()
the style of the graphs of the section notebook
Definition dotStyle.cpp:89
std::string nodeBgColor
background color of the nodes
Definition dotStyle.h:86
std::string arcColor
color of the arcs and edges, and of the border of the nodes
Definition dotStyle.h:84
The style of a dynamic Bayesian network (section dynamicBN) : the colors of its clusters.
Definition dotStyle.h:164
std::string atemporalBgColor
background color of the cluster of the atemporal variables
Definition dotStyle.h:170
static DynamicBNDotStyle read()
Definition dotStyle.cpp:168
std::string replicatedSliceBgColor
background color of the cluster of the replicated slice
Definition dotStyle.h:168
std::string timeSliceBgColor
background color of the cluster of a time slice
Definition dotStyle.h:166
The style of a factor graph (section factorgraph): layout, nodeBgColor and nodeFgColor are the ones o...
Definition dotStyle.h:122
double edgeLength
length of the edges
Definition dotStyle.h:127
std::string factorFgColor
the font color of the factors: adaptive against their background
Definition dotStyle.h:125
static FactorGraphDotStyle read()
Definition dotStyle.cpp:120
The style of an influence diagram (section influenceDiagram).
Definition dotStyle.h:133
std::string utilityArcStyle
graphviz style of the arcs pointing to a utility node
Definition dotStyle.h:146
std::string decisionArcStyle
graphviz style of the arcs pointing to a decision node
Definition dotStyle.h:144
static InfluenceDiagramDotStyle read()
Definition dotStyle.cpp:133
The style of a junction tree (section notebook): size is the size of the tree, not the one of its map...
Definition dotStyle.h:99
bool withNames
show the names of the variables in the cliques
Definition dotStyle.h:101
double mapEdgeLen
length of the edges in the map of a junction tree
Definition dotStyle.h:113
double mapCliqueScale
scale of the cliques in the map of a junction tree
Definition dotStyle.h:109
static JunctionTreeDotStyle read()
Definition dotStyle.cpp:98
double mapSepScale
scale of the separators in the map of a junction tree
Definition dotStyle.h:111
std::string mapSize
size of the map of a junction tree
Definition dotStyle.h:115