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

CyberZHG / GraphLayout / 20945568875

13 Jan 2026 05:14AM UTC coverage: 90.274% (+0.5%) from 89.729%
20945568875

Pull #1

github

web-flow
Merge 9e0a13a77 into e0694bd89
Pull Request #1: Enable tail and head labels

53 of 56 new or added lines in 2 files covered. (94.64%)

1253 of 1388 relevant lines covered (90.27%)

7416.11 hits per line

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

71.6
/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 Attributes::MONOSPACE_FONT_FAMILY = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace";
23

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

31
unordered_map<string_view, string> Attributes::DEFAULT_VERTEX_ATTRIBUTE_VALUES = {
32
    {ATTR_KEY_LABEL, ""},
33
    {ATTR_KEY_SHAPE, AttributeShape::CIRCLE},
34
};
35

36
unordered_map<string_view, string> Attributes::DEFAULT_EDGE_ATTRIBUTE_VALUES = {
37
    {ATTR_KEY_LABEL, ""},
38
    {ATTR_KEY_TAIL_LABEL, ""},
39
    {ATTR_KEY_HEAD_LABEL, ""},
40
    {ATTR_KEY_LABEL_DISTANCE, "2.0"},
41
};
42

43
Attribute::Attribute() = default;
×
44

45
Attribute::Attribute(const string& value) : _raw(value) {
×
46
}
×
47

48
void Attribute::set(const string &value) {
×
49
    _raw = value;
×
50
}
×
51

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

56
string Attributes::graphAttributes(const string_view& key) const {
501✔
57
    if (const auto it = _graphAttributes.find(key); it != _graphAttributes.end()) {
501✔
58
        return it->second;
73✔
59
    }
60
    return DEFAULT_GRAPH_ATTRIBUTE_VALUES[key];
428✔
61
}
62

63
void Attributes::setGraphAttributes(const string_view& key, const string &value) {
25✔
64
    _graphAttributes[key] = value;
25✔
65
}
25✔
66

NEW
67
void Attributes::setGraphAttributes(const unordered_map<string_view, string>& attributes) {
×
68
    _graphAttributes = attributes;
×
69
}
×
70

71
string Attributes::vertexAttributes(const int u, const string_view& key) const {
1,210✔
72
    if (const auto vIt = _vertexAttributes.find(u); vIt != _vertexAttributes.end()) {
1,210✔
73
        if (const auto it = vIt->second.find(key); it != vIt->second.end()) {
1,206✔
74
            return it->second;
466✔
75
        }
76
    }
77
    if (const auto it = _vertexDefaultAttributes.find(key); it != _vertexDefaultAttributes.end()) {
744✔
78
        return it->second;
12✔
79
    }
80
    if (const auto it = DEFAULT_VERTEX_ATTRIBUTE_VALUES.find(key); it != DEFAULT_VERTEX_ATTRIBUTE_VALUES.end()) {
732✔
81
        return it->second;
332✔
82
    }
83
    return graphAttributes(key);
400✔
84
}
85

86
void Attributes::setVertexAttributes(const int u, const string_view& key, const string &value) {
233✔
87
    _vertexAttributes[u][key] = value;
233✔
88
}
233✔
89

NEW
90
void Attributes::setVertexAttributes(const int u, const unordered_map<string_view, string>& attributes) {
×
91
    _vertexAttributes[u] = attributes;
×
92
}
×
93

94
string Attributes::edgeAttributes(const int u, const string_view& key) const {
1,019✔
95
    if (const auto eIt = _edgeAttributes.find(u); eIt != _edgeAttributes.end()) {
1,019✔
96
        if (const auto it = eIt->second.find(key); it != eIt->second.end()) {
144✔
97
            return it->second;
40✔
98
        }
99
    }
100
    if (const auto it = _edgeDefaultAttributes.find(key); it != _edgeDefaultAttributes.end()) {
979✔
101
        return it->second;
×
102
    }
103
    if (const auto it = DEFAULT_EDGE_ATTRIBUTE_VALUES.find(key); it != DEFAULT_EDGE_ATTRIBUTE_VALUES.end()) {
979✔
104
        return it->second;
979✔
105
    }
106
    return edgeAttributes(u, key);
×
107
}
108

109
void Attributes::setEdgeAttributes(const int u, const string_view& key, const string &value) {
39✔
110
    _edgeAttributes[u][key] = value;
39✔
111
}
39✔
112

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

NEW
117
void Attributes::setEdgeAttributes(const int u, const unordered_map<string_view, string>& mapping) {
×
118
    _edgeAttributes[u] = mapping;
×
119
}
×
120

121
void Attributes::transferEdgeAttributes(const int u, const int v) {
×
122
    if (_edgeAttributes.contains(u)) {
×
123
        _edgeAttributes[v] = _edgeAttributes[u];
×
124
    }
125
}
×
126

127
string Attributes::rankDir() const {
82✔
128
    return graphAttributes(ATTR_KEY_RANK_DIR);
82✔
129
}
130

131
void Attributes::setRankDir(const string &value) {
16✔
132
    setGraphAttributes(ATTR_KEY_RANK_DIR, value);
16✔
133
}
16✔
134

135
void Attributes::setVertexDefaultShape(const string& value) {
1✔
136
    _vertexDefaultAttributes[ATTR_KEY_SHAPE] = value;
1✔
137
}
1✔
138

139
void Attributes::setVertexDefaultMonospace() {
1✔
140
    _vertexDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
141
}
1✔
142

143
void Attributes::setEdgeDefaultMonospace() {
1✔
144
    _edgeDefaultAttributes[ATTR_KEY_FONT_NAME] = MONOSPACE_FONT_FAMILY;
1✔
145
}
1✔
146

147
void Attributes::setVertexShape(const int u, const string &value) {
6✔
148
    setVertexAttributes(u, ATTR_KEY_SHAPE, value);
6✔
149
}
6✔
150

151
void Attributes::setEdgeTailLabel(const int edgeId, const string& label) {
1✔
152
    setEdgeAttributes(edgeId, ATTR_KEY_TAIL_LABEL, label);
1✔
153
}
1✔
154

155
void Attributes::setEdgeHeadLabel(const int edgeId, const string& label) {
1✔
156
    setEdgeAttributes(edgeId, ATTR_KEY_HEAD_LABEL, label);
1✔
157
}
1✔
158

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