lib/Graph/D3.pm

filter: Statementstmt 100% 44 / 44 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.3% 61 / 64 CC 9 SCAR 12.9
CC
9
Cov
94%
force_directed_graph
6.0
hierarchical_edge_bundling
4.0
BEGIN
1.0
CRAP 3.6
↑ Summary
1 package Graph::D3;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.03';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has graph => (
12 is => 'ro',
13 required => 1
14 );
15  
16 has type => (
17 is => 'ro',
18 1 ▶ default => sub { 'ref' },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 );
20  
21 # https://gist.github.com/mbostock/4062045
22 # http://bl.ocks.org/mbostock/4062045
23 2 ▶sub force_directed_graph {
Subroutine force_directed_graph: called CC=6 SCAR=18.0
Pod documented
24 2 my $self = shift;
25 2 my @nodes;
26 my %nodes;
27 2 my $counter = 0;
28 2 for my $vertex ($self->graph->vertices) {
29 10 my $group = $self->graph->get_vertex_attribute($vertex, 'group');
30 10 ▶ $group = 1 unless (defined $group);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group 10 0 10
31 10 push @nodes, { name => $vertex, group => $group };
32 10 $nodes{$vertex} = $counter;
33 10 $counter++;
34 }
35 2 my @links;
36 2 for my $edges ($self->graph->edges) {
37 8 my ($n1, $n2) = @$edges;
38 8 my $value = $self->graph->get_edge_attribute($n1, $n2, 'value');
39 8 ▶ $value = 1 unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 8 0 8
40 8 push @links, {source => $nodes{$n1}, target => $nodes{$n2}, value => $value};
41 }
42 2 my $output = { nodes => \@nodes, links => \@links };
43 2 ▶ return $self->type eq 'json' ? encode_json $output : $output;
Branch: 1 branch
BranchTrueFalseTotal
$self->type eq 'json' ? : 1 1 2
44 }
45  
46 # http://mbostock.github.io/d3/talk/20111116/bundle.html
47 2 ▶sub hierarchical_edge_bundling {
Subroutine hierarchical_edge_bundling: called CC=4 SCAR=13.9
Pod documented
48 2 my $self = shift;
49 2 my @bundle;
50 2 for my $vertex ($self->graph->vertices) {
51 10 my $size = $self->graph->get_vertex_attribute($vertex, 'size');
52 10 ▶ $size = 1 unless (defined $size);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 10 0 10
53 10 my @imports = $self->graph->predecessors($vertex);
54 10 push @bundle, {name => $vertex, size => $size, imports => \@imports };
55 }
56 2 ▶ return $self->type eq 'json' ? encode_json \@bundle : \@bundle;
Branch: 1 branch
BranchTrueFalseTotal
$self->type eq 'json' ? : 1 1 2
57 }
58  
59  
60 1 1;
61 __END__
↑ Summary