line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Google::Chart::Data; |
3
|
3
|
|
|
3
|
|
401729
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Google::Chart::DataSet; |
5
|
|
|
|
|
|
|
use Google::Chart::Encoding::Extended; |
6
|
|
|
|
|
|
|
use Google::Chart::Encoding::Simple; |
7
|
|
|
|
|
|
|
use Google::Chart::Encoding::Text; |
8
|
|
|
|
|
|
|
use Google::Chart::Types; |
9
|
|
|
|
|
|
|
use namespace::clean -except => qw(meta); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has datasets => ( |
12
|
|
|
|
|
|
|
traits => ['Array'], |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef[Google::Chart::DataSet]', |
15
|
|
|
|
|
|
|
lazy_build => 1, |
16
|
|
|
|
|
|
|
handles => { |
17
|
|
|
|
|
|
|
add_dataset => 'push', |
18
|
|
|
|
|
|
|
dataset_count => 'count', |
19
|
|
|
|
|
|
|
get_dataset_at => 'get', |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has encoding => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
does => 'Google::Chart::Encoding', |
26
|
|
|
|
|
|
|
lazy_build => 1, |
27
|
|
|
|
|
|
|
writer => 'set_encoding' |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build_datasets { [] } |
31
|
|
|
|
|
|
|
sub _build_encoding { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
if (! Class::MOP::is_class_loaded('Google::Chart::Encoding::Text')) { |
34
|
|
|
|
|
|
|
Class::MOP::load_class( 'Google::Chart::Encoding::Text' ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
Google::Chart::Encoding::Text->new(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
around BUILDARGS => sub { |
40
|
|
|
|
|
|
|
my $next = shift; |
41
|
|
|
|
|
|
|
my $class = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# A dataset must be an array of arrays or array of values |
44
|
|
|
|
|
|
|
my @dataset; |
45
|
|
|
|
|
|
|
my %args; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if (@_ == 1 && ref $_[0] eq 'ARRAY') { |
48
|
|
|
|
|
|
|
@dataset = @{$_[0]}; |
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
%args = @_; |
51
|
|
|
|
|
|
|
@dataset = @{ delete $args{data} || [] }; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if (! ref $dataset[0] ) { |
55
|
|
|
|
|
|
|
@dataset = ([ @dataset]); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
foreach (@dataset) { |
59
|
|
|
|
|
|
|
if ( ! blessed $_ ) { |
60
|
|
|
|
|
|
|
$_ = Google::Chart::DataSet->new(data => $_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $args = $class->$next( %args, data => \@dataset ); |
65
|
|
|
|
|
|
|
return $args; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub prepare_query { |
69
|
|
|
|
|
|
|
my ($self, $chart) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Data delimiter *DIFFERS* between chart types (can you believe it?) |
72
|
|
|
|
|
|
|
my $data; |
73
|
|
|
|
|
|
|
my $encoding = $self->encoding; |
74
|
|
|
|
|
|
|
if ( $encoding->isa('Google::Chart::Encoding::Text') && |
75
|
|
|
|
|
|
|
$chart->isa('Google::Chart::Type::Pie') ) { |
76
|
|
|
|
|
|
|
$data = $encoding->encode( $self->datasets, ',' ); |
77
|
|
|
|
|
|
|
} else { |
78
|
|
|
|
|
|
|
$data = $encoding->encode( $self->datasets ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my @query = (chd => $data); |
82
|
|
|
|
|
|
|
my (@chco, @chdl, @chds); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $datasets = $self->datasets; |
85
|
|
|
|
|
|
|
my $max = $self->dataset_count - 1; |
86
|
|
|
|
|
|
|
my $is_text_encoding = $encoding->isa('Google::Chart::Encoding::Text'); |
87
|
|
|
|
|
|
|
for my $i (0..$max) { |
88
|
|
|
|
|
|
|
my $dataset = $datasets->[$i]; |
89
|
|
|
|
|
|
|
if ($dataset->has_legend) { |
90
|
|
|
|
|
|
|
$chdl[$i] = $dataset->legend; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
if ($dataset->has_color) { |
93
|
|
|
|
|
|
|
$chco[$i] = $dataset->color; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
if ($dataset->has_min_value || $dataset->has_max_value) { |
96
|
|
|
|
|
|
|
$chds[$i] = join(',', $dataset->min_value, $dataset->max_value); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
if (@chds > 0) { |
100
|
|
|
|
|
|
|
push @query, (chds => join(",", map { defined $_ ? $_ : "," } @chds)); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if (@chdl) { |
104
|
|
|
|
|
|
|
push @query, (chdl => join('|', map { defined $_ ? $_ : '' } @chdl)); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
if (@chco) { |
107
|
|
|
|
|
|
|
push @query, (chco => join(',', map { defined $_ ? $_ : '' } @chco)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
return @query; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Google::Chart::Data - Google::Chart Data |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SYNOPSIS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use Google::Chart::Data; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# simple, text encoding |
127
|
|
|
|
|
|
|
Google::Chart::Data->new( |
128
|
|
|
|
|
|
|
[ 1.0, 2.0, undef, 50.0, -1, 100.0 ] |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Explicity encoding specification, with legend |
132
|
|
|
|
|
|
|
Google::Chart::Data->new( |
133
|
|
|
|
|
|
|
encoding => Google::Chart::Encoding::Extended->new( |
134
|
|
|
|
|
|
|
max_value => 150, |
135
|
|
|
|
|
|
|
), |
136
|
|
|
|
|
|
|
data => [ |
137
|
|
|
|
|
|
|
Google::Chart::DataSet->new( |
138
|
|
|
|
|
|
|
legend => "Data set 1", |
139
|
|
|
|
|
|
|
data => [ 1.0, 2.0, undef, 50.0, -1, 100.0 ] |
140
|
|
|
|
|
|
|
), |
141
|
|
|
|
|
|
|
Google::Chart::DataSet->new( |
142
|
|
|
|
|
|
|
legend => "Data set 2", |
143
|
|
|
|
|
|
|
data => [ 1, 400, 500, 100] |
144
|
|
|
|
|
|
|
) |
145
|
|
|
|
|
|
|
] |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |