line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Graph::Writer::TGXML - write a directed graph out as TouchGraph LinkBrowser XML |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id$ |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Graph::Writer::TGXML; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2016868
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
9
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
758107
|
use Graph::Writer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use XML::Writer; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use vars qw(@ISA $VERSION); |
15
|
|
|
|
|
|
|
$VERSION = 0.01; |
16
|
|
|
|
|
|
|
@ISA = qw(Graph::Writer); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#======================================================================= |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# _write_graph() - perform the writing of the graph |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# This is invoked from the public write_graph() method, |
24
|
|
|
|
|
|
|
# and is where the actual writing of the graph happens. |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Basically we start a graph element then: |
27
|
|
|
|
|
|
|
# [] dump out any attributes of the graph |
28
|
|
|
|
|
|
|
# [] dump out all vertices, with any attributes of each vertex |
29
|
|
|
|
|
|
|
# [] dump out all edges, with any attributes of each edge |
30
|
|
|
|
|
|
|
# And then close the graph element. Ta da! |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
#======================================================================= |
33
|
|
|
|
|
|
|
sub _write_graph |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
my $graph = shift; |
37
|
|
|
|
|
|
|
my $FILE = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $v; |
40
|
|
|
|
|
|
|
my $from; |
41
|
|
|
|
|
|
|
my $to; |
42
|
|
|
|
|
|
|
# my %attributes; |
43
|
|
|
|
|
|
|
my $xmlwriter; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$xmlwriter = XML::Writer->new(OUTPUT => $FILE, |
47
|
|
|
|
|
|
|
DATA_MODE => 1, |
48
|
|
|
|
|
|
|
DATA_INDENT => 2); |
49
|
|
|
|
|
|
|
$xmlwriter->setOutput($FILE); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$xmlwriter->startTag('TOUCHGRAPH_LB', version => '1.20'); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$xmlwriter->startTag('NODESET'); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
56
|
|
|
|
|
|
|
# dump out vertices of the graph, including any attributes |
57
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
foreach $v ($graph->vertices) |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
my $attributes = $graph->get_vertex_attributes($v) || {}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# print ">$v<\n"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$xmlwriter->startTag('NODE', 'nodeID' => $v); |
65
|
|
|
|
|
|
|
$xmlwriter->emptyTag('NODE_LOCATION', |
66
|
|
|
|
|
|
|
x => 633, |
67
|
|
|
|
|
|
|
y => 30, |
68
|
|
|
|
|
|
|
visible => 'true' ); |
69
|
|
|
|
|
|
|
$xmlwriter->emptyTag('NODE_LABEL', |
70
|
|
|
|
|
|
|
label => $attributes->{label} || $v, |
71
|
|
|
|
|
|
|
shape => 2, |
72
|
|
|
|
|
|
|
backColor => 'FFFFFF', |
73
|
|
|
|
|
|
|
textColor => '000000', |
74
|
|
|
|
|
|
|
fontSize => 16 ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$xmlwriter->emptyTag('NODE_URL', |
77
|
|
|
|
|
|
|
url => $attributes->{URL} || '', |
78
|
|
|
|
|
|
|
urlIsLocal => 'false', |
79
|
|
|
|
|
|
|
urlIsXML =>'false' ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$attributes->{tooltip} ||= ''; |
82
|
|
|
|
|
|
|
$attributes->{tooltip} =~ s/\\74/
|
83
|
|
|
|
|
|
|
$attributes->{tooltip} =~ s/\\76/>/g; |
84
|
|
|
|
|
|
|
$xmlwriter->emptyTag('NODE_HINT', |
85
|
|
|
|
|
|
|
hint => $attributes->{tooltip} || '', |
86
|
|
|
|
|
|
|
width => 400, |
87
|
|
|
|
|
|
|
height => -1, |
88
|
|
|
|
|
|
|
isHTML => 'false' ); |
89
|
|
|
|
|
|
|
$xmlwriter->endTag('NODE'); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$xmlwriter->endTag('NODESET'); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
95
|
|
|
|
|
|
|
# dump out edges of the graph, including any attributes |
96
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$xmlwriter->startTag('EDGESET'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @edges = $graph->edges; |
101
|
|
|
|
|
|
|
while (@edges) |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
($from, $to) = splice(@edges, 0, 2); |
104
|
|
|
|
|
|
|
# my $attributes = $graph->get_edge_attributes($from, $to); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$xmlwriter->emptyTag('EDGE', |
107
|
|
|
|
|
|
|
fromID => $from, |
108
|
|
|
|
|
|
|
toID => $to, |
109
|
|
|
|
|
|
|
type => 1, |
110
|
|
|
|
|
|
|
length => 40, |
111
|
|
|
|
|
|
|
visible => 'true', |
112
|
|
|
|
|
|
|
color => 'A0A0A0' ); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$xmlwriter->endTag('EDGESET'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$xmlwriter->endTag('TOUCHGRAPH_LB'); |
119
|
|
|
|
|
|
|
$xmlwriter->end(); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return 1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |