| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use Graph::Writer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use XML::Writer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | $VERSION = 0.03; | |||||||||||||||||||
| 16 | 2 | @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 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
_write_graph: called CC=8 SCAR=21.4
| |||||||||||||||||||||
| 35 | 1 | my $self = shift; | |||||||||||||||||||
| 36 | 1 | my $graph = shift; | |||||||||||||||||||
| 37 | 1 | my $FILE = shift; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 1 | my $v; | |||||||||||||||||||
| 40 | my $from; | ||||||||||||||||||||
| 41 | 1 | my $to; | |||||||||||||||||||
| 42 | # my %attributes; | ||||||||||||||||||||
| 43 | 1 | my $xmlwriter; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | $xmlwriter = XML::Writer->new(OUTPUT => $FILE, | |||||||||||||||||||
| 47 | DATA_MODE => 1, | ||||||||||||||||||||
| 48 | DATA_INDENT => 2); | ||||||||||||||||||||
| 49 | 1 | $xmlwriter->setOutput($FILE); | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | $xmlwriter->startTag('TOUCHGRAPH_LB', version => '1.20'); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1 | $xmlwriter->startTag('NODESET'); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | #------------------------------------------------------------------- | ||||||||||||||||||||
| 56 | # dump out vertices of the graph, including any attributes | ||||||||||||||||||||
| 57 | #------------------------------------------------------------------- | ||||||||||||||||||||
| 58 | 1 | foreach $v (sort { $a cmp $b } ($graph->vertices)) | |||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | 4 | ▶ | my $attributes = $graph->get_vertex_attributes($v) || {}; | ||||||||||||||||||
|
Condition50%1/2
$graph->get_vertex_attributes($v) || {}
MC/DC0%0/1
$graph->get_vertex_attributes($v) || {}
$graph->get_vertex_attributes($v)
Truth table50%1/2
A
A= $graph->get_vertex_attributes($v)
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # print ">$v<\n"; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 4 | $xmlwriter->startTag('NODE', 'nodeID' => $v); | |||||||||||||||||||
| 65 | 4 | $xmlwriter->emptyTag('NODE_LOCATION', | |||||||||||||||||||
| 66 | x => 633, | ||||||||||||||||||||
| 67 | y => 30, | ||||||||||||||||||||
| 68 | visible => 'true' ); | ||||||||||||||||||||
| 69 | $xmlwriter->emptyTag('NODE_LABEL', | ||||||||||||||||||||
| 70 | 4 | ▶ | label => $attributes->{label} || $v, | ||||||||||||||||||
|
Condition33%1/3
$attributes->{'label'} || $v
MC/DC0%0/2
$attributes->{'label'} || $v
$attributes->{'label'}
$v
Truth table33%1/3
A || B
A= $attributes->{'label'}B= $v
| |||||||||||||||||||||
| 71 | shape => 2, | ||||||||||||||||||||
| 72 | backColor => 'FFFFFF', | ||||||||||||||||||||
| 73 | textColor => '000000', | ||||||||||||||||||||
| 74 | fontSize => 16 ); | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | $xmlwriter->emptyTag('NODE_URL', | ||||||||||||||||||||
| 77 | 4 | ▶ | url => $attributes->{URL} || '', | ||||||||||||||||||
|
Condition50%1/2
$attributes->{'URL'} || ''
MC/DC0%0/1
$attributes->{'URL'} || ''
$attributes->{'URL'}
Truth table50%1/2
A
A= $attributes->{'URL'}
| |||||||||||||||||||||
| 78 | urlIsLocal => 'false', | ||||||||||||||||||||
| 79 | urlIsXML =>'false' ); | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 4 | ▶ | $attributes->{tooltip} ||= ''; | ||||||||||||||||||
|
Condition50%1/2
$attributes->{"tooltip"} ||= ""
MC/DC0%0/1
$attributes->{"tooltip"} ||= ""
$attributes->{"tooltip"}
Truth table50%1/2
A
A= $attributes->{"tooltip"}
| |||||||||||||||||||||
| 82 | 4 | $attributes->{tooltip} =~ s/\\74/</g; | |||||||||||||||||||
| 83 | 4 | $attributes->{tooltip} =~ s/\\76/>/g; | |||||||||||||||||||
| 84 | $xmlwriter->emptyTag('NODE_HINT', | ||||||||||||||||||||
| 85 | 4 | ▶ | hint => $attributes->{tooltip} || '', | ||||||||||||||||||
|
Condition50%1/2
$attributes->{'tooltip'} || ''
MC/DC0%0/1
$attributes->{'tooltip'} || ''
$attributes->{'tooltip'}
Truth table50%1/2
A
A= $attributes->{'tooltip'}
| |||||||||||||||||||||
| 86 | width => 400, | ||||||||||||||||||||
| 87 | height => -1, | ||||||||||||||||||||
| 88 | isHTML => 'false' ); | ||||||||||||||||||||
| 89 | 4 | $xmlwriter->endTag('NODE'); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | $xmlwriter->endTag('NODESET'); | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | #------------------------------------------------------------------- | ||||||||||||||||||||
| 95 | # dump out edges of the graph, including any attributes | ||||||||||||||||||||
| 96 | #------------------------------------------------------------------- | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 1 | $xmlwriter->startTag('EDGESET'); | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 1 | my @edges = $graph->edges; | |||||||||||||||||||
| 101 | 1 | ▶ | while (@edges) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | { | ||||||||||||||||||||
| 103 | 0 | ($from, $to) = splice(@edges, 0, 2); | |||||||||||||||||||
| 104 | # my $attributes = $graph->get_edge_attributes($from, $to); | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | $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 | 1 | $xmlwriter->endTag('EDGESET'); | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 1 | $xmlwriter->endTag('TOUCHGRAPH_LB'); | |||||||||||||||||||
| 119 | 1 | $xmlwriter->end(); | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 1 | return 1; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||