Subject: | support timeout option in addition to $iterations |
In addition to making $iterations be configurable in Graph::Layouter::Spring it would also be cool to support a "$max_wait" time option, which would allow people to say "do up to $iterations, but if $max_wait has elapsed, then whatever you've got is good enough, return ASAP.
Something like this...
my $iterations = 1000;
my $max_wait = 29; # seconds .. undef for no limit
my $max_repulsive_force_distance = 6;
my $k = 2;
my $c = 0.01;
my $max_vertex_movement = 0.5;
sub layout {
my $end = defined($max_wait) ? time + $max_wait : undef;
my $graph = shift;
Graph::Layouter::_layout_prepare($graph);
# Cache
my @vertices = $graph->vertices;
for (my $i = 0; $i < $iterations; $i++) {
last if defined($end) and $end < time;
_layout_iteration($graph, \@vertices);
}
Graph::Layouter::_layout_calc_bounds($graph);
}
...it also seems possible that some users may not care about the number of iterations, only the $max_wait .. in which case addign support for $iterations being undef would also usefull. (of course, there would need to be some check that at least one of them was defined)