line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chart::OFC::Pie; |
2
|
|
|
|
|
|
|
$Chart::OFC::Pie::VERSION = '0.12'; |
3
|
16
|
|
|
16
|
|
1018
|
use strict; |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
716
|
|
4
|
16
|
|
|
16
|
|
103
|
use warnings; |
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
534
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
100
|
use Moose; |
|
16
|
|
|
|
|
36
|
|
|
16
|
|
|
|
|
142
|
|
7
|
16
|
|
|
16
|
|
116296
|
use MooseX::StrictConstructor; |
|
16
|
|
|
|
|
43
|
|
|
16
|
|
|
|
|
169
|
|
8
|
16
|
|
|
16
|
|
57064
|
use Chart::OFC::Types; |
|
16
|
|
|
|
|
44
|
|
|
16
|
|
|
|
|
6630
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Chart::OFC'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has dataset => |
13
|
|
|
|
|
|
|
( is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'Chart::OFC::Dataset', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has slice_colors => |
19
|
|
|
|
|
|
|
( is => 'ro', |
20
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::NonEmptyArrayRefOfColors', |
21
|
|
|
|
|
|
|
coerce => 1, |
22
|
|
|
|
|
|
|
lazy => 1, |
23
|
|
|
|
|
|
|
default => sub { [ qw( red blue green yellow orange purple black ) ] }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has line_color => |
27
|
|
|
|
|
|
|
( is => 'ro', |
28
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::Color', |
29
|
|
|
|
|
|
|
coerce => 1, |
30
|
|
|
|
|
|
|
default => '#000000', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has labels => |
34
|
|
|
|
|
|
|
( is => 'ro', |
35
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::NonEmptyArrayRef', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
auto_deref => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has label_style => |
41
|
|
|
|
|
|
|
( is => 'ro', |
42
|
|
|
|
|
|
|
isa => 'Str', |
43
|
|
|
|
|
|
|
default => 'color: #000000', |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has opacity => |
47
|
|
|
|
|
|
|
( is => 'ro', |
48
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::Opacity', |
49
|
|
|
|
|
|
|
default => '80', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub BUILD |
53
|
|
|
|
|
|
|
{ |
54
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
65
|
my @l = $self->labels(); |
57
|
2
|
|
|
|
|
66
|
my @v = $self->dataset()->values(); |
58
|
|
|
|
|
|
|
|
59
|
2
|
50
|
|
|
|
14
|
die 'You must have the same number of labels and values.' |
60
|
|
|
|
|
|
|
unless @l == @v; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
52
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
override _ofc_data_lines => sub |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return |
70
|
|
|
|
|
|
|
( super(), |
71
|
|
|
|
|
|
|
$self->_data_line( 'pie', |
72
|
|
|
|
|
|
|
$self->opacity(), |
73
|
|
|
|
|
|
|
$self->line_color(), |
74
|
|
|
|
|
|
|
$self->_formatted_label_style(), |
75
|
|
|
|
|
|
|
), |
76
|
|
|
|
|
|
|
$self->_data_line( 'pie_labels', $self->labels() ), |
77
|
|
|
|
|
|
|
$self->_data_line( 'colours', @{ $self->slice_colors() } ), |
78
|
|
|
|
|
|
|
$self->dataset()->_ofc_data_lines(), |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _formatted_label_style |
83
|
|
|
|
|
|
|
{ |
84
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
59
|
my $style = $self->label_style(); |
87
|
|
|
|
|
|
|
|
88
|
2
|
50
|
|
|
|
8
|
return unless length $style; |
89
|
|
|
|
|
|
|
|
90
|
2
|
|
|
|
|
52
|
return '{ ' . $self->label_style() . ' }'; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
16
|
|
|
16
|
|
120
|
no Moose; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
109
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# ABSTRACT: A pie chart |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Chart::OFC::Pie - A pie chart |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 VERSION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
version 0.12 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $dataset = Chart::OFC::Dataset->new( values => [ 1 .. 5 ] ); |
116
|
|
|
|
|
|
|
my $pie = Chart::OFC::Pie->new( |
117
|
|
|
|
|
|
|
title => 'My Pie Chart', |
118
|
|
|
|
|
|
|
dataset => $dataset, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 DESCRIPTION |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This class represents a pie chart. A pie chart displays a single |
124
|
|
|
|
|
|
|
dataset as a set of pie slices. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=for Pod::Coverage BUILD |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This class is a subclass of C<Chart::OFC> and accepts all of that |
131
|
|
|
|
|
|
|
class's attribute. It has several attributes of its own which may be |
132
|
|
|
|
|
|
|
passed to the C<new()> method. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 dataset |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This should be a single dataset of the C<Chart::OFC::Dataset> |
137
|
|
|
|
|
|
|
class. (It could be any Dataset subclass, but all the subclass's |
138
|
|
|
|
|
|
|
attributes will be ignored). |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This attribute is required. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 slice_colors |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This should an array of colors. If you give fewer colors than there |
145
|
|
|
|
|
|
|
are in your dataset then colors will be reused (in order). |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This defaults to "red, blue, green, yellow, orange, purple, black". |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 line_color |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The colors of the lines which define slices. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Defaults to #000000 (black). |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 labels |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This should be an array reference containing one or more labels for |
158
|
|
|
|
|
|
|
the slices. This should contain one label per valuable in the dataset. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 label_style |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
A snippet of CSS that will be applied to the labels. The default is |
163
|
|
|
|
|
|
|
"color: #000000". If you change this you should probably make sure to |
164
|
|
|
|
|
|
|
include a color. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 opacity |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This defines how opaque the slices are. When they are moused over, they |
169
|
|
|
|
|
|
|
become fully opaque. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Defaults to 80 (percent). |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 ROLES |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This class does the C<Chart::OFC::Role::OFCDataLines> role. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Dave Rolsky. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This is free software, licensed under: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |