File: html.pl

package info (click to toggle)
libgraph-easy-perl 0.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,284 kB
  • sloc: perl: 24,909; makefile: 2
file content (113 lines) | stat: -rw-r--r-- 2,843 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl -w

#############################################################################
# This example is a bit outdated, please use the new bin/grapheasy script -
# which is after "make install" available in your system as simple as
# "grapheasy" on any command line prompt.

#############################################################################
# This script uses examples/common.pl to generate some example graphs and
# prints them as HTML page. Use it like:

# ewxamples/html.pl >test.html

# and then open test.html in your favourite browser.

use strict;
use warnings;

BEGIN { chdir 'examples' if -d 'examples'; }

require "common.pl";

my $graph = Graph::Easy->new();

my @toc = ();
my $html = $graph->html_page_header();

$html .= <<HTML

<style type="text/css">
 h1 { border-bottom: 1px solid black; padding-bottom: 0.2em; }
 h2 { border-bottom: 1px solid grey; padding-bottom: 0.2em; margin-bottom: 0em; }
 div { margin-left: 2em; }
 .graph { margin-left: 2em; }
</style>

<h1>Graph-Simple Test page</h1>

<p>
This page was automatically created at <small>##time##</small> by <code>examples/html.pl</code> running
<a href="http://search.cpan.org/~tels/Graph-Simple/" title="Get it from search.cpan.org">Graph::Easy</a> v##version##.
</p>

<p>
On each of the following testcases you will see a text representation of the graph on the left side,
and on the right side the automatically generated HTML+CSS code. 
</p>

<p>
Notes:
</p>

<ul>
  <li>The text representation does not yet carry node attributes, like colors or border style.
  <li>The HTML does not yet have "pretty" edges. This will be fixed later.
  <li>The limitations in <a href="http://search.cpan.org/~tels/Graph-Simple/lib/Graph/Simple.pm#LIMITATIONS">Graph::Easy</a> apply.
</ul>

<h2>Testcases:</h2>

##TOC##

HTML
;

# generate the parts and push their names into @toc
gen_graphs($graph, 'html');

$html .= $graph->html_page_footer();

my $toc = '<ul>';

for my $t (@toc)
  {
  my $n = $t; $n =~ s/\s/_/;
  $toc .= " <li><a href=\"#$n\">" . $t . "</a>\n";
  }
$toc .= "</ul>\n";

# insert the TOC
$html =~ s/##TOC##/ $toc /;
$html =~ s/##time##/ scalar localtime() /e;
$html =~ s/##version##/$Graph::Easy::VERSION/e;

print $html;

# all done;

1;

#############################################################################

sub out
  {
  my ($graph,$method) = @_;

  $method = 'as_' . $method;

  my $t = $graph->nodes() . ' Nodes, ' . $graph->edges . ' Edges';
  my $n = $t; $n =~ s/\s/_/;

  $html .= "<a name=\"$n\"><h2>$t</h2></a>\n" .
   "<div style='float: left; min-widht: 30%'>\n" . 
   "<h3>As Text</h3>\n" . 
   "<pre>" . $graph->as_txt() . "</pre></div>" . 
   "<div style='float: left;'>\n" . 
   "<h3>As HTML:</h3>\n" . 
   $graph->$method() . "</div>\n" .
   "<div style='clear: both;'>&nbsp;</div>\n\n";

  push @toc, $t;
  }