Commit c2c359ba authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Include support for relative ordering of nodes in radial_layout()

parent 618b019e
......@@ -31,9 +31,9 @@ using namespace graph_tool;
struct do_get_radial
{
template <class Graph, class PosProp, class LevelMap>
void operator()(Graph& g, PosProp tpos, LevelMap level, size_t root,
bool weighted, double r) const
template <class Graph, class PosProp, class LevelMap, class OrderMap>
void operator()(Graph& g, PosProp tpos, LevelMap level, OrderMap order,
size_t root, bool weighted, double r) const
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef property_map_type::apply<int, GraphInterface::vertex_index_map_t>::type
......@@ -102,9 +102,14 @@ struct do_get_radial
if (int(layers.size()) - 1 == int(level[w]))
last = false;
}
std::sort(new_layer.end() - out_degree(v, g), new_layer.end(),
[&] (vertex_t u, vertex_t v) -> bool { return order[u] < order[v]; });
if (out_degree(v, g) == 0)
new_layer.push_back(v);
}
if (last)
layers.pop_back();
}
......@@ -149,13 +154,19 @@ struct do_get_radial
};
void get_radial(GraphInterface& gi, boost::any otpos, boost::any olevels,
size_t root, bool weighted, double r)
boost::any oorder, size_t root, bool weighted, double r)
{
typedef property_map_type::apply<int32_t,
GraphInterface::vertex_index_map_t>::type
vmap_t;
vmap_t levels = boost::any_cast<vmap_t>(olevels);
run_action<graph_tool::detail::always_directed>()
(gi, std::bind(do_get_radial(), placeholders::_1, placeholders::_2,
placeholders::_3, root, weighted, r),
levels, placeholders::_3, root, weighted, r),
vertex_scalar_vector_properties(),
vertex_scalar_properties())(otpos, olevels);
vertex_properties())(otpos, oorder);
}
#include <boost/python.hpp>
......
......@@ -702,7 +702,7 @@ def sfdp_layout(g, vweight=None, eweight=None, pin=None, groups=None, C=0.2,
verbose, _get_rng())
return pos
def radial_tree_layout(g, root, weighted=False, r=1.):
def radial_tree_layout(g, root, rel_order=None, weighted=False, r=1.):
r"""Computes a radial layout of the graph according to the minimum spanning
tree centered at the ``root`` vertex.
......@@ -712,6 +712,8 @@ def radial_tree_layout(g, root, weighted=False, r=1.):
Graph to be used.
root : :class:`~graph_tool.Vertex` or ``int``
The root of the radial tree.
rel_order : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
Relative order of the nodes at the lowest branch.
weighted : ``bool`` (optional, default: ``False``)
If true, the angle between the child branches will be computed according
to weight of the entire sub-branches.
......@@ -758,10 +760,13 @@ def radial_tree_layout(g, root, weighted=False, r=1.):
t = predecessor_tree(g, pred_map)
pos = t.new_vertex_property("vector<double>")
levels = t.own_property(levels)
if rel_order is None:
rel_order = g.vertex_index.copy("int")
libgraph_tool_layout.get_radial(t._Graph__graph,
_prop("v", g, pos),
_prop("v", g, levels),
_prop("v", g, rel_order),
int(root), weighted, r)
return g.own_property(pos)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment