summaryrefslogtreecommitdiff
path: root/lib/GitHub/Collector/Role/Graph/Gexf.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-06-13 16:33:23 +0200
committerfranck cuny <franck@lumberjaph.net>2011-06-13 16:33:23 +0200
commit871336c030209b46ae6b124a702677363487f9a8 (patch)
tree86f234d42c68b26a7aeb9cc373667127ad661e19 /lib/GitHub/Collector/Role/Graph/Gexf.pm
parentuse template_toolkit and add infos about colors (diff)
downloadstargit-871336c030209b46ae6b124a702677363487f9a8.tar.gz
import github::collector
Signed-off-by: franck cuny <franck@lumberjaph.net>
Diffstat (limited to 'lib/GitHub/Collector/Role/Graph/Gexf.pm')
-rw-r--r--lib/GitHub/Collector/Role/Graph/Gexf.pm47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/GitHub/Collector/Role/Graph/Gexf.pm b/lib/GitHub/Collector/Role/Graph/Gexf.pm
new file mode 100644
index 0000000..ab83dd4
--- /dev/null
+++ b/lib/GitHub/Collector/Role/Graph/Gexf.pm
@@ -0,0 +1,47 @@
+package GitHub::Collector::Role::Graph::Gexf;
+
+use Moose::Role;
+use Graph::GEXF;
+
+has output => (
+ is => 'ro',
+ isa => 'Int',
+ predicate => 'should_export',
+);
+
+sub export {
+ my ($self, ) = @_;
+
+ my $gexf = Graph::GEXF->new();
+ $gexf->add_node_attribute( name => 'string' );
+ $gexf->add_node_attribute( lang => 'string' );
+ $gexf->add_node_attribute( size => 'int' );
+ $gexf->add_node_attribute( country => 'string' );
+ $gexf->add_node_attribute( indegree => 'int' );
+
+ my $nodes = {};
+ foreach my $node ( keys %{ $self->nodes } ) {
+ my $n = $gexf->add_node( $self->nodes->{$node}->{id} );
+ $n->label($node);
+ $n->attribute( name => $node );
+ $n->attribute( size => $self->nodes->{$node}->{size} );
+ $n->attribute( lang => $self->nodes->{$node}->{language} || '' );
+ $n->attribute( country => $self->nodes->{$node}->{country} || '' );
+ $n->attribute( indegree => $self->nodes->{$node}->{indegree} );
+ $nodes->{$node} = $n;
+ }
+
+ foreach my $edge (keys %{$self->edges}){
+ $nodes->{ $self->edges->{$edge}->{sourceId} }->link_to(
+ {
+ target => $self->edges->{$edge}->{targetId},
+ weight => $self->edges->{$edge}->{weight}
+ }
+ );
+ }
+
+ my $xml = $gexf->to_xml();
+ print $xml;
+}
+
+1;