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

Improve performance of graph_draw() and draw_hierarchy()

parent 83186f00
...@@ -1040,7 +1040,7 @@ public: ...@@ -1040,7 +1040,7 @@ public:
_attrs.template get<vector<double> >(EDGE_CONTROL_POINTS); _attrs.template get<vector<double> >(EDGE_CONTROL_POINTS);
vector<double> gradient = vector<double> gradient =
_attrs.template get<vector<double> >(EDGE_GRADIENT); _attrs.template get<vector<double> >(EDGE_GRADIENT);
if (gradient.size() == 1) if (gradient.size() == 2)
{ {
auto e_color = _attrs.template get<color_t>(EDGE_COLOR); auto e_color = _attrs.template get<color_t>(EDGE_COLOR);
auto s_color = _s._attrs.template get<color_t>(VERTEX_FILL_COLOR); auto s_color = _s._attrs.template get<color_t>(VERTEX_FILL_COLOR);
...@@ -1109,10 +1109,8 @@ public: ...@@ -1109,10 +1109,8 @@ public:
color_t color = _attrs.template get<color_t>(EDGE_COLOR); color_t color = _attrs.template get<color_t>(EDGE_COLOR);
double pw; double pw = _attrs.template get<double>(EDGE_PENWIDTH);
pw = _attrs.template get<double>(EDGE_PENWIDTH);
pw = get_user_dist(cr, pw); pw = get_user_dist(cr, pw);
cr.set_line_width(pw);
pos_t pos_begin_marker = pos_begin; pos_t pos_begin_marker = pos_begin;
pos_t pos_end_marker = pos_end; pos_t pos_end_marker = pos_end;
...@@ -1155,6 +1153,7 @@ public: ...@@ -1155,6 +1153,7 @@ public:
double sx1, sy1, sx2, sy2; double sx1, sy1, sx2, sy2;
draw_edge_markers(pos_begin_marker, pos_begin_d, pos_end_marker, draw_edge_markers(pos_begin_marker, pos_begin_d, pos_end_marker,
pos_end_d, controls, marker_size, cr); pos_end_d, controls, marker_size, cr);
cr.set_line_width(pw);
draw_edge_line(pos_begin, pos_end, controls, cr); draw_edge_line(pos_begin, pos_end, controls, cr);
cr.get_stroke_extents(sx1, sy1, sx2, sy2); cr.get_stroke_extents(sx1, sy1, sx2, sy2);
cr.begin_new_path(); cr.begin_new_path();
...@@ -1282,6 +1281,7 @@ public: ...@@ -1282,6 +1281,7 @@ public:
} }
draw_edge_line(pos_begin, pos_end, controls, cr); draw_edge_line(pos_begin, pos_end, controls, cr);
cr.set_line_width(pw);
cr.stroke(); cr.stroke();
cr.reset_clip(); cr.reset_clip();
draw_edge_markers(pos_begin_marker, pos_begin_d, pos_end_marker, draw_edge_markers(pos_begin_marker, pos_begin_d, pos_end_marker,
...@@ -1531,14 +1531,17 @@ void draw_vertices(Graph&, pair<VertexIterator, VertexIterator> v_range, ...@@ -1531,14 +1531,17 @@ void draw_vertices(Graph&, pair<VertexIterator, VertexIterator> v_range,
Cairo::Context& cr) Cairo::Context& cr)
{ {
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t; typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
for(VertexIterator v = v_range.first; v != v_range.second; ++v)
if (offset > count)
{ {
if (count < offset) size_t dist = std::distance(v_range.first, v_range.second);
{ size_t skip = std::min(offset - count, dist);
count++; std::advance(v_range.first, skip);
continue; count += skip;
} }
for(VertexIterator v = v_range.first; v != v_range.second; ++v)
{
pos_t pos; pos_t pos;
if (pos_map[*v].size() >= 2) if (pos_map[*v].size() >= 2)
{ {
...@@ -1562,14 +1565,23 @@ void draw_edges(Graph& g, pair<EdgeIterator, EdgeIterator> e_range, ...@@ -1562,14 +1565,23 @@ void draw_edges(Graph& g, pair<EdgeIterator, EdgeIterator> e_range,
{ {
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t; typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t; typedef typename graph_traits<Graph>::edge_descriptor edge_t;
for(EdgeIterator e = e_range.first; e != e_range.second; ++e) if (offset > count)
{ {
if (count < offset) size_t E = num_edges(g);
if (offset - count >= E)
{ {
count++; count += E;
continue; return;
} }
size_t dist = std::distance(e_range.first, e_range.second);
size_t skip = std::min(offset - count, dist);
std::advance(e_range.first, skip);
count += skip;
}
for(EdgeIterator e = e_range.first; e != e_range.second; ++e)
{
vertex_t s, t; vertex_t s, t;
s = source(*e, g); s = source(*e, g);
t = target(*e, g); t = target(*e, g);
......
...@@ -761,7 +761,7 @@ class PropertyMap(object): ...@@ -761,7 +761,7 @@ class PropertyMap(object):
return numpy.array(self.fa) return numpy.array(self.fa)
except ValueError: except ValueError:
p = ungroup_vector_property(self, pos) p = ungroup_vector_property(self, pos)
return numpy.array([x.a for x in p]) return numpy.array([x.fa for x in p])
def set_2d_array(self, a, pos=None): def set_2d_array(self, a, pos=None):
r"""Set the entries of the vector-valued property map from a r"""Set the entries of the vector-valued property map from a
......
This diff is collapsed.
...@@ -265,7 +265,7 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -265,7 +265,7 @@ class GraphWidget(Gtk.DrawingArea):
self.smatrix = cairo.Matrix() # surface to screen self.smatrix = cairo.Matrix() # surface to screen
self.pointer = [0, 0] self.pointer = [0, 0]
self.picked = False self.picked = False
self.selected = g.new_vertex_property("bool") self.selected = g.new_vertex_property("bool", False)
self.sel_edge_filt = g.new_edge_property("bool", False) self.sel_edge_filt = g.new_edge_property("bool", False)
self.srect = None self.srect = None
self.drag_begin = None self.drag_begin = None
......
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