• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyberZHG / GraphLayout / 21153628837

19 Jan 2026 10:55PM UTC coverage: 88.187% (-0.7%) from 88.936%
21153628837

Pull #5

github

web-flow
Merge 9a31b9edf into 28e838363
Pull Request #5: Add settings for color

22 of 37 new or added lines in 2 files covered. (59.46%)

1284 of 1456 relevant lines covered (88.19%)

7312.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.14
/src/common/graph_attributes.cpp
1
#include "common/graph_attributes.h"
2

3
#include <functional>
4
#include <utility>
5
#include <ranges>
6
#include <format>
7
using namespace std;
8
using namespace graph_layout;
9

10
const string AttributeRankDir::TOP_TO_BOTTOM = "tb";
11
const string AttributeRankDir::BOTTOM_TO_TOP = "bt";
12
const string AttributeRankDir::LEFT_TO_RIGHT = "lr";
13
const string AttributeRankDir::RIGHT_TO_LEFT = "rl";
14

15
const string AttributeShape::NONE = "none";
16
const string AttributeShape::CIRCLE = "circle";
17
const string AttributeShape::DOUBLE_CIRCLE = "doublecircle";
18
const string AttributeShape::ELLIPSE = "ellipse";
19
const string AttributeShape::RECT = "rect";
20
const string AttributeShape::RECORD = "record";
21

22
const string AttributeSplines::LINE = "line";
23
const string AttributeSplines::SPLINE = "spline";
24

25
const string AttributeArrowShape::NONE = "none";
26
const string AttributeArrowShape::NORMAL = "normal";
27
const string AttributeArrowShape::EMPTY = "empty";
28

29
const string Attributes::MONOSPACE_FONT_FAMILY = R"(ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace)";
30

31
unordered_map<string_view, string> Attributes::DEFAULT_GRAPH_ATTRIBUTE_VALUES = {
32
    {ATTR_KEY_RANK_DIR, AttributeRankDir::TOP_TO_BOTTOM},
33
    {ATTR_KEY_BG_COLOR, "none"},
34
    {ATTR_KEY_FONT_NAME, "Times,serif"},
35
    {ATTR_KEY_FONT_SIZE, "14"},
36
    {ATTR_KEY_COLOR, "black"},
37
    {ATTR_KEY_FILL_COLOR, "none"},
38
    {ATTR_KEY_FONT_COLOR, "black"},
39
};
40

41
unordered_map<string_view, string> Attributes::DEFAULT_VERTEX_ATTRIBUTE_VALUES = {
42
    {ATTR_KEY_LABEL, ""},
43
    {ATTR_KEY_SHAPE, AttributeShape::CIRCLE},
44
};
45

46
unordered_map<string_view, string> Attributes::DEFAULT_EDGE_ATTRIBUTE_VALUES = {
47
    {ATTR_KEY_LABEL, ""},
48
    {ATTR_KEY_TAIL_LABEL, ""},
49
    {ATTR_KEY_HEAD_LABEL, ""},
50
    {ATTR_KEY_LABEL_DISTANCE, "2.0"},
51
    {ATTR_KEY_SPLINES, "line"},
52
    {ATTR_KEY_ARROW_HEAD, AttributeArrowShape::NORMAL},
53
    {ATTR_KEY_ARROW_TAIL, AttributeArrowShape::NONE},
54
};
55

56
Attribute::Attribute() = default;
×
57

58
Attribute::Attribute(const string& value) : _raw(value) {
×
59
}
×
60

61
void Attribute::set(const string &value) {
×
62
    _raw = value;
×
63
}
×
64

65
const string& Attribute::value() const {
×
66
    return _raw;
×
67
}
68

69
string Attributes::graphAttributes(const string_view& key) const {
2,608✔
70
    if (const auto it = _graphAttributes.find(key); it != _graphAttributes.end()) {
2,608✔
71
        return it->second;
73✔
72
    }
73
    return DEFAULT_GRAPH_ATTRIBUTE_VALUES[key];
2,535✔
74
}
75

76
void Attributes::setGraphAttributes(const string_view& key, const string &value) {
25✔
77
    _graphAttributes[key] = value;
25✔
78
}
25✔
79

80
void Attributes::setGraphAttributes(const unordered_map<string_view, string>& attributes) {
×
81
    _graphAttributes = attributes;
×
82
}
×
83

84
string Attributes::vertexAttributes(const int u, const string_view& key) const {
2,215✔
85
    if (const auto vIt = _vertexAttributes.find(u); vIt != _vertexAttributes.end()) {
2,215✔
86
        if (const auto it = vIt->second.find(key); it != vIt->second.end()) {
2,211✔
87
            return it->second;
466✔
88
        }
89
    }
90
    if (const auto it = _vertexDefaultAttributes.find(key); it != _vertexDefaultAttributes.end()) {
1,749✔
91
        return it->second;
28✔
92
    }
93
    if (const auto it = DEFAULT_VERTEX_ATTRIBUTE_VALUES.find(key); it != DEFAULT_VERTEX_ATTRIBUTE_VALUES.end()) {
1,721✔
94
        return it->second;
332✔
95
    }
96
    return graphAttributes(key);
1,389✔
97
}
98

99
void Attributes::setVertexAttributes(const int u, const string_view& key, const string &value) {
233✔
100
    _vertexAttributes[u][key] = value;
233✔
101
}
233✔
102

103
void Attributes::setVertexAttributes(const int u, const unordered_map<string_view, string>& attributes) {
×
104
    _vertexAttributes[u] = attributes;
×
105
}
×
106

107
string Attributes::edgeAttributes(const int u, const string_view& key) const {
2,883✔
108
    if (const auto eIt = _edgeAttributes.find(u); eIt != _edgeAttributes.end()) {
2,883✔
109
        if (const auto it = eIt->second.find(key); it != eIt->second.end()) {
394✔
110
            return it->second;
40✔
111
        }
112
    }
113
    if (const auto it = _edgeDefaultAttributes.find(key); it != _edgeDefaultAttributes.end()) {
2,843✔
114
        return it->second;
18✔
115
    }
116
    if (const auto it = DEFAULT_EDGE_ATTRIBUTE_VALUES.find(key); it != DEFAULT_EDGE_ATTRIBUTE_VALUES.end()) {
2,825✔
117
        return it->second;
1,707✔
118
    }
119
    return graphAttributes(key);
1,118✔
120
}
121

122
void Attributes::setEdgeAttributes(const int u, const string_view& key, const string &value) {
39✔
123
    _edgeAttributes[u][key] = value;
39✔
124
}
39✔
125

126
void Attributes::setEdgeAttributes(const int u, const string_view& key, const double value) {
1✔
127
    _edgeAttributes[u][key] = format("{}", value);
1✔
128
}
1✔
129

130
void Attributes::setEdgeAttributes(const int u, const unordered_map<string_view, string>& mapping) {
×
131
    _edgeAttributes[u] = mapping;
×
132
}
×
133

134
void Attributes::transferEdgeAttributes(const int u, const int v) {
×
135
    if (_edgeAttributes.contains(u)) {
×
136
        _edgeAttributes[v] = _edgeAttributes[u];
×
137
    }
138
}
×
139

140
string Attributes::rankDir() const {
82✔
141
    return graphAttributes(ATTR_KEY_RANK_DIR);
82✔
142
}
143

144
void Attributes::setRankDir(const string &value) {
16✔
145
    setGraphAttributes(ATTR_KEY_RANK_DIR, value);
16✔
146
}
16✔
147

148
void Attributes::setVertexDefaultShape(const string& value) {
1✔
149
    _vertexDefaultAttributes[ATTR_KEY_SHAPE] = value;
1✔
150
}
1✔
151

152
void Attributes::setEdgeDefaultSplines(const string& value) {
×
153
    _edgeDefaultAttributes[ATTR_KEY_SPLINES] = value;
×
154
}
×
155

156
void Attributes::setVertexDefaultMonospace() {
1✔
157
    _vertexDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
158
}
1✔
159

160
void Attributes::setEdgeDefaultMonospace() {
1✔
161
    _edgeDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
162
}
1✔
163

164
void Attributes::setVertexShape(const int u, const string &value) {
6✔
165
    setVertexAttributes(u, ATTR_KEY_SHAPE, value);
6✔
166
}
6✔
167

168
void Attributes::setEdgeSplines(const int edgeId, const string& value) {
×
169
    setEdgeAttributes(edgeId, ATTR_KEY_SPLINES, value);
×
170
}
×
171

172
void Attributes::setEdgeTailLabel(const int edgeId, const string& label) {
1✔
173
    setEdgeAttributes(edgeId, ATTR_KEY_TAIL_LABEL, label);
1✔
174
}
1✔
175

176
void Attributes::setEdgeHeadLabel(const int edgeId, const string& label) {
1✔
177
    setEdgeAttributes(edgeId, ATTR_KEY_HEAD_LABEL, label);
1✔
178
}
1✔
179

180
void Attributes::setEdgeLabelDistance(const int edgeId, const double scale) {
1✔
181
    setEdgeAttributes(edgeId, ATTR_KEY_LABEL_DISTANCE, scale);
1✔
182
}
1✔
183

184
void Attributes::setEdgeDefaultArrowHead(const string& value) {
×
185
    _edgeDefaultAttributes[ATTR_KEY_ARROW_HEAD] = value;
×
186
}
×
187

188
void Attributes::setEdgeDefaultArrowTail(const string& value) {
×
189
    _edgeDefaultAttributes[ATTR_KEY_ARROW_TAIL] = value;
×
190
}
×
191

192
void Attributes::setEdgeArrowHead(const int edgeId, const string& value) {
×
193
    setEdgeAttributes(edgeId, ATTR_KEY_ARROW_HEAD, value);
×
194
}
×
195

196
void Attributes::setEdgeArrowTail(const int edgeId, const string& value) {
×
197
    setEdgeAttributes(edgeId, ATTR_KEY_ARROW_TAIL, value);
×
198
}
×
199

200
void Attributes::setVertexDefaultColor(const string& value) {
1✔
201
    _vertexDefaultAttributes[ATTR_KEY_COLOR] = value;
1✔
202
}
1✔
203

204
void Attributes::setVertexDefaultFillColor(const string& value) {
1✔
205
    _vertexDefaultAttributes[ATTR_KEY_FILL_COLOR] = value;
1✔
206
}
1✔
207

208
void Attributes::setVertexDefaultFontColor(const string& value) {
1✔
209
    _vertexDefaultAttributes[ATTR_KEY_FONT_COLOR] = value;
1✔
210
}
1✔
211

212
void Attributes::setEdgeDefaultColor(const string& value) {
1✔
213
    _edgeDefaultAttributes[ATTR_KEY_COLOR] = value;
1✔
214
}
1✔
215

216
void Attributes::setEdgeDefaultFontColor(const string& value) {
1✔
217
    _edgeDefaultAttributes[ATTR_KEY_FONT_COLOR] = value;
1✔
218
}
1✔
219

NEW
220
void Attributes::setVertexColor(const int u, const string& value) {
×
NEW
221
    setVertexAttributes(u, ATTR_KEY_COLOR, value);
×
NEW
222
}
×
223

NEW
224
void Attributes::setVertexFillColor(const int u, const string& value) {
×
NEW
225
    setVertexAttributes(u, ATTR_KEY_FILL_COLOR, value);
×
NEW
226
}
×
227

NEW
228
void Attributes::setVertexFontColor(const int u, const string& value) {
×
NEW
229
    setVertexAttributes(u, ATTR_KEY_FONT_COLOR, value);
×
NEW
230
}
×
231

NEW
232
void Attributes::setEdgeColor(const int edgeId, const string& value) {
×
NEW
233
    setEdgeAttributes(edgeId, ATTR_KEY_COLOR, value);
×
NEW
234
}
×
235

NEW
236
void Attributes::setEdgeFontColor(const int edgeId, const string& value) {
×
NEW
237
    setEdgeAttributes(edgeId, ATTR_KEY_FONT_COLOR, value);
×
NEW
238
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc