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

CyberZHG / GraphLayout / 21103632348

18 Jan 2026 01:03AM UTC coverage: 89.943% (-0.5%) from 90.404%
21103632348

push

github

web-flow
Fix head & tail labels for virtual edges (#3)

* Update SVGDiagram to 1.7.0

* Fix head & tail labels for virtual edges

* Fix font & distance

* Update self loop height

* Restore self loop height

* Add config for splines

11 of 19 new or added lines in 2 files covered. (57.89%)

1261 of 1402 relevant lines covered (89.94%)

6747.57 hits per line

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

68.97
/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 Attributes::MONOSPACE_FONT_FAMILY = R"(ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace)";
26

27
unordered_map<string_view, string> Attributes::DEFAULT_GRAPH_ATTRIBUTE_VALUES = {
28
    {ATTR_KEY_RANK_DIR, AttributeRankDir::TOP_TO_BOTTOM},
29
    {ATTR_KEY_BG_COLOR, "none"},
30
    {ATTR_KEY_FONT_NAME, "Times,serif"},
31
    {ATTR_KEY_FONT_SIZE, "14"},
32
};
33

34
unordered_map<string_view, string> Attributes::DEFAULT_VERTEX_ATTRIBUTE_VALUES = {
35
    {ATTR_KEY_LABEL, ""},
36
    {ATTR_KEY_SHAPE, AttributeShape::CIRCLE},
37
};
38

39
unordered_map<string_view, string> Attributes::DEFAULT_EDGE_ATTRIBUTE_VALUES = {
40
    {ATTR_KEY_LABEL, ""},
41
    {ATTR_KEY_TAIL_LABEL, ""},
42
    {ATTR_KEY_HEAD_LABEL, ""},
43
    {ATTR_KEY_LABEL_DISTANCE, "2.0"},
44
    {ATTR_KEY_SPLINES, "line"},
45
};
46

47
Attribute::Attribute() = default;
×
48

49
Attribute::Attribute(const string& value) : _raw(value) {
×
50
}
×
51

52
void Attribute::set(const string &value) {
×
53
    _raw = value;
×
54
}
×
55

56
const string& Attribute::value() const {
×
57
    return _raw;
×
58
}
59

60
string Attributes::graphAttributes(const string_view& key) const {
1,461✔
61
    if (const auto it = _graphAttributes.find(key); it != _graphAttributes.end()) {
1,461✔
62
        return it->second;
73✔
63
    }
64
    return DEFAULT_GRAPH_ATTRIBUTE_VALUES[key];
1,388✔
65
}
66

67
void Attributes::setGraphAttributes(const string_view& key, const string &value) {
25✔
68
    _graphAttributes[key] = value;
25✔
69
}
25✔
70

71
void Attributes::setGraphAttributes(const unordered_map<string_view, string>& attributes) {
×
72
    _graphAttributes = attributes;
×
73
}
×
74

75
string Attributes::vertexAttributes(const int u, const string_view& key) const {
1,612✔
76
    if (const auto vIt = _vertexAttributes.find(u); vIt != _vertexAttributes.end()) {
1,612✔
77
        if (const auto it = vIt->second.find(key); it != vIt->second.end()) {
1,608✔
78
            return it->second;
466✔
79
        }
80
    }
81
    if (const auto it = _vertexDefaultAttributes.find(key); it != _vertexDefaultAttributes.end()) {
1,146✔
82
        return it->second;
16✔
83
    }
84
    if (const auto it = DEFAULT_VERTEX_ATTRIBUTE_VALUES.find(key); it != DEFAULT_VERTEX_ATTRIBUTE_VALUES.end()) {
1,130✔
85
        return it->second;
332✔
86
    }
87
    return graphAttributes(key);
798✔
88
}
89

90
void Attributes::setVertexAttributes(const int u, const string_view& key, const string &value) {
233✔
91
    _vertexAttributes[u][key] = value;
233✔
92
}
233✔
93

94
void Attributes::setVertexAttributes(const int u, const unordered_map<string_view, string>& attributes) {
×
95
    _vertexAttributes[u] = attributes;
×
96
}
×
97

98
string Attributes::edgeAttributes(const int u, const string_view& key) const {
1,743✔
99
    if (const auto eIt = _edgeAttributes.find(u); eIt != _edgeAttributes.end()) {
1,743✔
100
        if (const auto it = eIt->second.find(key); it != eIt->second.end()) {
238✔
101
            return it->second;
40✔
102
        }
103
    }
104
    if (const auto it = _edgeDefaultAttributes.find(key); it != _edgeDefaultAttributes.end()) {
1,703✔
105
        return it->second;
6✔
106
    }
107
    if (const auto it = DEFAULT_EDGE_ATTRIBUTE_VALUES.find(key); it != DEFAULT_EDGE_ATTRIBUTE_VALUES.end()) {
1,697✔
108
        return it->second;
1,135✔
109
    }
110
    return graphAttributes(key);
562✔
111
}
112

113
void Attributes::setEdgeAttributes(const int u, const string_view& key, const string &value) {
39✔
114
    _edgeAttributes[u][key] = value;
39✔
115
}
39✔
116

117
void Attributes::setEdgeAttributes(const int u, const string_view& key, const double value) {
1✔
118
    _edgeAttributes[u][key] = format("{}", value);
1✔
119
}
1✔
120

121
void Attributes::setEdgeAttributes(const int u, const unordered_map<string_view, string>& mapping) {
×
122
    _edgeAttributes[u] = mapping;
×
123
}
×
124

125
void Attributes::transferEdgeAttributes(const int u, const int v) {
×
126
    if (_edgeAttributes.contains(u)) {
×
127
        _edgeAttributes[v] = _edgeAttributes[u];
×
128
    }
129
}
×
130

131
string Attributes::rankDir() const {
82✔
132
    return graphAttributes(ATTR_KEY_RANK_DIR);
82✔
133
}
134

135
void Attributes::setRankDir(const string &value) {
16✔
136
    setGraphAttributes(ATTR_KEY_RANK_DIR, value);
16✔
137
}
16✔
138

139
void Attributes::setVertexDefaultShape(const string& value) {
1✔
140
    _vertexDefaultAttributes[ATTR_KEY_SHAPE] = value;
1✔
141
}
1✔
142

NEW
143
void Attributes::setEdgeDefaultSplines(const string& value) {
×
NEW
144
    _edgeDefaultAttributes[ATTR_KEY_SPLINES] = value;
×
NEW
145
}
×
146

147
void Attributes::setVertexDefaultMonospace() {
1✔
148
    _vertexDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
149
}
1✔
150

151
void Attributes::setEdgeDefaultMonospace() {
1✔
152
    _edgeDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
153
}
1✔
154

155
void Attributes::setVertexShape(const int u, const string &value) {
6✔
156
    setVertexAttributes(u, ATTR_KEY_SHAPE, value);
6✔
157
}
6✔
158

NEW
159
void Attributes::setEdgeSplines(const int edgeId, const string& value) {
×
NEW
160
    setEdgeAttributes(edgeId, ATTR_KEY_SPLINES, value);
×
NEW
161
}
×
162

163
void Attributes::setEdgeTailLabel(const int edgeId, const string& label) {
1✔
164
    setEdgeAttributes(edgeId, ATTR_KEY_TAIL_LABEL, label);
1✔
165
}
1✔
166

167
void Attributes::setEdgeHeadLabel(const int edgeId, const string& label) {
1✔
168
    setEdgeAttributes(edgeId, ATTR_KEY_HEAD_LABEL, label);
1✔
169
}
1✔
170

171
void Attributes::setEdgeLabelDistance(const int edgeId, const double scale) {
1✔
172
    setEdgeAttributes(edgeId, ATTR_KEY_LABEL_DISTANCE, scale);
1✔
173
}
1✔
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