Skip to content

Commit 35ed3a9

Browse files
committed
Documented new graph drawing.
1 parent cb30294 commit 35ed3a9

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

README.md

+71-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main()
4242
tree.insert({19, 20});
4343

4444
tree.deoverlap();
45-
45+
4646
for (auto const& i : tree)
4747
{
4848
std::cout << "[" << i.low() << ", " << i.high() << "]\n";
@@ -61,10 +61,80 @@ Create a build folder, navigate there, run cmake and build the tree-tests target
6161
You might have to adapt the linker line for gtest, if you built it yourself and didn't install it into your system.
6262
If you want to generate the pretty drawings, install cairo, pull the submodule and pass INT_TREE_DRAW_EXAMPLES=on to the cmake command line to generate a drawings/make_drawings executeable.
6363

64+
## Draw Dot Graph
65+
This draws a dot graph of the tree:
66+
```c++
67+
#include <interval-tree/interval_tree.hpp>
68+
#include <interval-tree/dot_graph.hpp>
69+
70+
int main()
71+
{
72+
using namespace lib_interval_tree;
73+
interval_tree_t<int> tree;
74+
75+
tree.insert(make_safe_interval<int>(21, 16)); // make_safe_interval swaps low and high if not in right order.
76+
tree.insert({8, 9});
77+
tree.insert({25, 30});
78+
tree.insert({5, 8});
79+
tree.insert({15, 23});
80+
tree.insert({17, 19});
81+
tree.insert({26, 26});
82+
tree.insert({0, 3});
83+
tree.insert({6, 10});
84+
tree.insert({19, 20});
85+
86+
draw_dot_graph(
87+
std::cout,
88+
tree,
89+
{
90+
// digraph or graph?
91+
.digraph = true,
92+
93+
// graph name
94+
.name = "G",
95+
96+
// extra node attributes
97+
.extra_node_attributes = {"color=red"},
98+
99+
// extra graph statements
100+
.extra_statements = {"rankdir=LR"},
101+
102+
// put space after comma of interval label? (a,b) vs (a, b)
103+
.space_after_comma = false,
104+
105+
// left brace override, otherwise determined from interval kind
106+
.left_brace = std::nullopt,
107+
108+
// right brace override, otherwise determined from interval kind
109+
.right_brace = std::nullopt,
110+
111+
// edge attributes
112+
.edge_attributes = {"color=blue"},
113+
114+
// indent characters
115+
.indent = "\t",
116+
}
117+
);
118+
}
119+
```
120+
64121
## Free Functions
65122
### interval<NumericT, Kind> make_safe_interval(NumericT border1, NumericT border2)
66123
Creates an interval where the borders are sorted so the lower border is the first one.
67124

125+
### draw_dot_graph(std::ostream& os, interval_tree_t<Interval> const& tree, DrawOptions const& options)
126+
Draws a dot graph of the interval tree to the output stream.
127+
Options are:
128+
- digraph: bool
129+
- name: std::string
130+
- extra_node_attributes: std::vector<std::string>
131+
- extra_statements: std::vector<std::string>
132+
- space_after_comma: bool
133+
- left_brace: std::optional<std::string>
134+
- right_brace: std::optional<std::string>
135+
- edge_attributes: std::vector<std::string>
136+
- indent: std::string
137+
68138
## Members of IntervalTree<Interval>
69139

70140
- [Members of IntervalTree<Interval>](#members-of-intervaltreeinterval)

example/dot_graph/main.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,36 @@ int main()
1717
tree.insert({6, 10});
1818
tree.insert({19, 20});
1919

20-
draw_dot_graph(std::cout, tree);
20+
draw_dot_graph(
21+
std::cout,
22+
tree,
23+
{
24+
// digraph or graph?
25+
.digraph = true,
26+
27+
// graph name
28+
.name = "G",
29+
30+
// extra node attributes
31+
.extra_node_attributes = {"color=red"},
32+
33+
// extra graph statements
34+
.extra_statements = {"rankdir=LR"},
35+
36+
// put space after comma of interval label? (a,b) vs (a, b)
37+
.space_after_comma = false,
38+
39+
// left brace override, otherwise determined from interval kind
40+
.left_brace = std::nullopt,
41+
42+
// right brace override, otherwise determined from interval kind
43+
.right_brace = std::nullopt,
44+
45+
// edge attributes
46+
.edge_attributes = {"color=blue"},
47+
48+
// indent characters
49+
.indent = "\t",
50+
}
51+
);
2152
}

0 commit comments

Comments
 (0)