aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-10-07 21:22:25 +0200
committerHarald Welte <laforge@gnumonks.org>2011-10-07 21:22:25 +0200
commit3c185e97f186492d800f29941316a3033834b388 (patch)
tree9162a6fd8d8c9c612176b59ecd7879b3494ca498
parent259678c908b17d5e10547e43f92c3f7821b72abb (diff)
add support for printing a title on top of the picture
-rwxr-xr-xOsmoLadder.pm19
-rwxr-xr-xgen_ladder.pl7
2 files changed, 23 insertions, 3 deletions
diff --git a/OsmoLadder.pm b/OsmoLadder.pm
index 13be608..ddb3c34 100755
--- a/OsmoLadder.pm
+++ b/OsmoLadder.pm
@@ -24,6 +24,7 @@ use GD::Arrow;
my $ROW_SIZE = 50;
my $HEAD_SIZE = 70;
+my $TITLE_SIZE = 20;
my $FOOT_SIZE = 50;
my $COL_SIZE_MIN = 200;
my $MARGIN_LR = 50;
@@ -31,11 +32,14 @@ my $NODELINE_OVERLAP = 30;
my $FONT = "/usr/share/fonts/truetype/freefont/FreeSansBold.ttf";
+my $graph_title;
+
sub compute_img_size($$)
{
my ($num_nodes, $num_msgs) = @_;
- my $height = (($num_msgs-1) * $ROW_SIZE) + $HEAD_SIZE + $FOOT_SIZE;
+ my $height = (($num_msgs-1) * $ROW_SIZE) +
+ $HEAD_SIZE + $TITLE_SIZE + $FOOT_SIZE;
my $width = 2*$MARGIN_LR + ($num_nodes-1)*$COL_SIZE_MIN;
return ($width, $height);
@@ -52,7 +56,7 @@ sub compute_msg_y($)
{
my $msg_num = shift;
- return $HEAD_SIZE + $msg_num * $ROW_SIZE;
+ return $HEAD_SIZE + $TITLE_SIZE + $msg_num * $ROW_SIZE;
}
my %nodes;
@@ -136,6 +140,11 @@ sub draw_msg_label($$$$$)
draw_scaled_label($im, $text, $line_y, $start_x, $end_x);
}
+sub set_title($)
+{
+ $graph_title = shift;
+}
+
sub draw_graph($)
{
my $outfile_name = shift;
@@ -148,6 +157,12 @@ sub draw_graph($)
$im->transparent($white);
my $black = $im->colorAllocate(0, 0, 0);
+ if ($graph_title) {
+ my $gap_oneside = ($x/2) * 0.8;
+ draw_scaled_label($im, $graph_title, $TITLE_SIZE,
+ $x/2-$gap_oneside, $x/2+$gap_oneside);
+ }
+
# vertical lines for each of the nodes in the graph
foreach my $n (values %nodes) {
printf("node %s (%s)\n", $$n{'name'}, $$n{'label'});
diff --git a/gen_ladder.pl b/gen_ladder.pl
index 924e254..7408c98 100755
--- a/gen_ladder.pl
+++ b/gen_ladder.pl
@@ -41,7 +41,12 @@ sub parse_cfg_line($)
($cfg_parse_section) = $line =~ /^\[(.*)\]/;
return;
}
- if ($cfg_parse_section eq 'entities') {
+ if ($cfg_parse_section eq 'global') {
+ if ($line =~ /^title/) {
+ my ($title) = $line =~ /^title\s+"(.*)"/;
+ OsmoLadder::set_title($title);
+ }
+ } elsif ($cfg_parse_section eq 'entities') {
if (my ($entity, $label) = $line =~ /^(\S+)\s+"(.+)"/) {
OsmoLadder::new_node($entity, $label);
} else {