Chart/ChartJS.pm

filter: Statementstmt 36.3% 12 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod n/a totaltotal 32.6% 16 / 49 CC 4 SCAR 21.0
CC
4
Cov
31%
render
20.0
_trigger_colour
2.0
src_html
2.0
CRAP 8.2
↑ Summary Chart/Google.pm »
1 package Wight::Chart::ChartJS;
2  
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Graphics::Color::RGB;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 extends 'Wight::Chart';
8  
9 our $VERSION = '0.003'; # VERSION
10  
11 #TODO: import roles for each type for more options
12 my $types = {
13 line => { cls => "Line" },
14 area => { cls => "Line" },
15 spark => { cls => "Line", config => {
16 scaleShowLabels => JSON::XS::false,
17 pointDot => JSON::XS::false,
18 scaleShowGridLines => JSON::XS::false,
19 }},
20 bar => { cls => "Bar" },
21 radar => { cls => "Radar" } ,
22 polararea => { cls => 'PolarArea' },
23 pie => { cls => 'Pie' },
24 doughnut => { cls => 'Doughnut' },
25 };
26  
27 has 'type' => ( is => 'rw', required => 1, isa => sub { $types->{$_[0]} } );
28  
29 has '_colour' => ( is => 'rw', default => sub {
30 Graphics::Color::RGB->new({ red => .3, blue => 1, green => .3 })
31 });
32  
33 has 'colour' => ( is => 'rw', trigger => 1 );
34 0 ▶sub _trigger_colour {
Subroutine _trigger_colour: not called CC=1 SCAR=6.9
35 0 my $self = shift;
36 0 my $value = shift;
37 0 $self->_colour(Graphics::Color::RGB->from_hex_string($value));
38 }
39  
40 0 ▶sub src_html { 'chartjs.html' }
Subroutine src_html: not called CC=1 SCAR=6.9
41 0 ▶sub rgba {
Subroutine rgba: not called CC=1 SCAR=6.9
42 0 my $self = shift;
43 0 my $alpha = shift;
44 0 $self->_colour->alpha($alpha);
45 0 return "rgba(" . $self->_colour->as_integer_string . ")";
46 }
47  
48 0 ▶sub render {
Subroutine render: not called CC=4 SCAR=30.0
49 0 my ($self, $local_config) = @_;
50 0 my $w = $self->wight;
51  
52 0 my $src = $types->{$self->type};
53  
54 my $config = {
55 animation => JSON::XS::false,
56 0 ▶ %{$src->{config} || {} },
Condition0%0/2
$src->{'config'} || {}
l!l
00
MC/DC0%0/1
$src->{'config'} || {}
$src->{'config'}
Truth table0%0/2
A
A= $src->{'config'}
Aresult
11
00
57 0 ▶ %{$local_config || {} },
Condition0%0/2
$local_config || {}
l!l
00
MC/DC0%0/1
$local_config || {}
$local_config
Truth table0%0/2
A
A= $local_config
Aresult
11
00
58 };
59  
60 #if type is spark, clear columns
61 0 ▶ if($self->type eq 'spark') { $self->columns([('') x scalar @{$self->columns}]) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq "spark") 0 0 0
62 my $args = decode_utf8(encode_json({
63 config => $config,
64 type => $src->{cls},
65 0 width => $self->width,
66 height => $self->height,
67 data => {
68 labels => $self->columns,
69 datasets => [ {
70 fillColor => $self->rgba(.5),
71 strokeColor => $self->rgba(1),
72 pointColor => $self->rgba(1),
73 pointStrokeColor => "#fff",
74 data => $self->rows,
75 } ]
76 }
77 }));
78  
79 0 $w->evaluate("drawChart($args)");
80 0 $w->sleep(.1);
81 0 $w->render($self->output);
82 }
83  
84  
85 1;
86  
87 __END__
↑ Summary Chart/Google.pm »