CodeCompass

Форк
0
/
legendbuilder.cpp 
121 строка · 3.4 Кб
1
#include <util/legendbuilder.h>
2

3
namespace cc
4
{
5
namespace util
6
{
7

8
LegendBuilder::LegendBuilder(const std::string& title_)
9
{
10
  _graph.setAttribute("rankdir", "LR");
11
  _graph.setAttribute("nodesep", "0.25");
12
  _root = _graph.createNode();
13
  _graph.setNodeAttribute(_root, "label", "");
14
  _graph.setNodeAttribute(_root, "shape", "none");
15
  _graph.setNodeAttribute(_root, "width", "0.1");
16
  _graph.setAttribute("label", title_);
17
}
18

19
Graph::Node LegendBuilder::registerSubgraph(const Graph::Subgraph& sub_)
20
{
21
  Graph::Node first = _graph.createNode(sub_);
22
  Graph::Edge invis = _graph.createEdge(_root, first);
23
  _graph.setEdgeAttribute(invis, "style", "invis");
24

25
  _graph.setNodeAttribute(first, "label", "");
26
  _graph.setNodeAttribute(first, "shape", "none");
27
  _graph.setNodeAttribute(first, "width", "0.01");
28

29
  return first;
30
}
31

32
std::string LegendBuilder::getOutput() const
33
{
34
  return _graph.output(Graph::SVG);
35
}
36

37
void LegendBuilder::addNode(
38
  const std::string& label_,
39
  const std::vector<std::pair<std::string, std::string>>& attrs_,
40
  bool html_)
41
{
42
  Graph::Subgraph sub = _graph.getOrCreateSubgraph(label_);
43

44
  Graph::Node ref1 = registerSubgraph(sub); // padding node
45
  _graph.setSubgraphAttribute(sub, "rankdir", "LR");
46

47
  Graph::Node node = _graph.createNode(sub);
48
  _graph.setNodeAttribute(node, "label", "");
49
  Graph::Edge edge = _graph.createEdge(ref1, node); // padding edge
50
  _graph.setEdgeAttribute(edge, "style", "invis");
51

52
  Graph::Node desc = _graph.createNode(sub);
53
  _graph.setNodeAttribute(desc, "shape", "none");
54
  _graph.setNodeAttribute(desc, "label", label_);
55

56
  Graph::Edge invis = _graph.createEdge(node, desc);
57
  _graph.setEdgeAttribute(invis, "style", "invis");
58

59
  for (const auto& attr : attrs_)
60
    _graph.setNodeAttribute(node, attr.first, attr.second, html_);
61
}
62

63
void LegendBuilder::addEdge(
64
  const std::string& label_,
65
  const std::vector<std::pair<std::string, std::string>>& attrs_,
66
  bool html_)
67
{
68
  Graph::Subgraph sub = _graph.getOrCreateSubgraph(label_);
69
  _graph.setSubgraphAttribute(sub, "rankdir", "LR");
70

71
  Graph::Node ref1 = registerSubgraph(sub);
72

73
  Graph::Node ref2 = _graph.createNode(sub);
74
  _graph.setNodeAttribute(ref2, "label", "");
75
  _graph.setNodeAttribute(ref2, "shape", "none");
76
  _graph.setNodeAttribute(ref2, "width", "0.01");
77
  Graph::Edge edge = _graph.createEdge(ref1, ref2);
78

79
  Graph::Node desc = _graph.createNode(sub);
80
  _graph.setNodeAttribute(desc, "shape", "none");
81
  _graph.setNodeAttribute(desc, "label", label_);
82

83
  Graph::Edge invis = _graph.createEdge(ref2, desc);
84
  _graph.setEdgeAttribute(invis, "style", "invis");
85

86
  for (const auto& attr : attrs_)
87
    _graph.setEdgeAttribute(edge, attr.first, attr.second, html_);
88
}
89

90
Graph::Subgraph LegendBuilder::addSubgraph(
91
  const std::string& label_,
92
  Graph::Node& hook_)
93
{
94
  Graph::Subgraph sub = _graph.getOrCreateSubgraph(label_);
95
  _graph.setSubgraphAttribute(sub, "rankdir", "LR");
96
  Graph::Node ref = registerSubgraph(sub); // padding node
97

98
  hook_ = ref;
99
  return sub;
100
}
101

102
void LegendBuilder::setNodeStyle(
103
  const Graph::Node& node_,
104
  const std::vector<std::pair<std::string, std::string>>& attrs_,
105
  bool html_)
106
{
107
  for (const auto& attr : attrs_)
108
    _graph.setNodeAttribute(node_, attr.first, attr.second, html_);
109
}
110

111
void LegendBuilder::setEdgeStyle(
112
  const Graph::Edge& edge_,
113
  const std::vector<std::pair<std::string, std::string>>& attrs_,
114
  bool html_)
115
{
116
  for (const auto& attr : attrs_)
117
    _graph.setEdgeAttribute(edge_, attr.first, attr.second, html_);
118
}
119

120
} // util
121
} // cc
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.