line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chart::OFC; |
2
|
|
|
|
|
|
|
$Chart::OFC::VERSION = '0.12'; |
3
|
16
|
|
|
16
|
|
355952
|
use strict; |
|
16
|
|
|
|
|
42
|
|
|
16
|
|
|
|
|
643
|
|
4
|
16
|
|
|
16
|
|
82
|
use warnings; |
|
16
|
|
|
|
|
30
|
|
|
16
|
|
|
|
|
526
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
16
|
|
|
16
|
|
14362
|
use Moose 0.56; |
|
16
|
|
|
|
|
7763989
|
|
|
16
|
|
|
|
|
187
|
|
8
|
16
|
|
|
16
|
|
148678
|
use MooseX::StrictConstructor; |
|
16
|
|
|
|
|
465088
|
|
|
16
|
|
|
|
|
121
|
|
9
|
16
|
|
|
16
|
|
160214
|
use Chart::OFC::Types; |
|
16
|
|
|
|
|
57
|
|
|
16
|
|
|
|
|
7175
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Chart::OFC::Role::OFCDataLines'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has title => |
14
|
|
|
|
|
|
|
( is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'Str', |
16
|
|
|
|
|
|
|
predicate => '_has_title', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has title_style => |
20
|
|
|
|
|
|
|
( is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
default => 'font-size: 25px', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has tool_tip => |
26
|
|
|
|
|
|
|
( is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'Str', |
28
|
|
|
|
|
|
|
predicate => '_has_tool_tip', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has bg_color => |
32
|
|
|
|
|
|
|
( is => 'ro', |
33
|
|
|
|
|
|
|
isa => 'Chart::OFC::Type::Color', |
34
|
|
|
|
|
|
|
coerce => 1, |
35
|
|
|
|
|
|
|
predicate => '_has_bg_color', |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
my $CRLF = "\r\n"; |
40
|
|
|
|
|
|
|
sub as_ofc_data |
41
|
|
|
|
|
|
|
{ |
42
|
8
|
|
|
8
|
1
|
834
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
48
|
my @lines = $self->_ofc_data_lines(); |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
|
|
25
|
return join '', map { $_ . $CRLF } @lines; |
|
62
|
|
|
|
|
174
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _ofc_data_lines |
51
|
|
|
|
|
|
|
{ |
52
|
8
|
|
|
8
|
|
75
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
8
|
|
|
|
|
260
|
my @lines; |
55
|
|
|
|
|
|
|
|
56
|
8
|
50
|
|
|
|
332
|
push @lines, $self->_data_line( 'title', $self->title(), '{ ' . $self->title_style() . ' }' ) |
57
|
|
|
|
|
|
|
if $self->_has_title(); |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
37
|
for my $key ( qw( tool_tip bg_color ) ) |
60
|
|
|
|
|
|
|
{ |
61
|
16
|
|
|
|
|
34
|
my $pred = '_has_' . $key; |
62
|
|
|
|
|
|
|
|
63
|
16
|
100
|
|
|
|
698
|
push @lines, $self->_data_line( $key, $self->$key() ) |
64
|
|
|
|
|
|
|
if $self->$pred(); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
8
|
|
|
|
|
109
|
return @lines; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Moose gets weird if these things are loaded before various subs are |
71
|
|
|
|
|
|
|
# defined. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# If these requires are changed to a use some tests start failing in |
74
|
|
|
|
|
|
|
# weird ways. WTF? |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
require Chart::OFC::Grid; |
77
|
|
|
|
|
|
|
require Chart::OFC::Pie; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
require Chart::OFC::AxisLabel; |
80
|
|
|
|
|
|
|
require Chart::OFC::XAxis; |
81
|
|
|
|
|
|
|
require Chart::OFC::YAxis; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
require Chart::OFC::Dataset::3DBar; |
84
|
|
|
|
|
|
|
require Chart::OFC::Dataset::Area; |
85
|
|
|
|
|
|
|
require Chart::OFC::Dataset::Bar; |
86
|
|
|
|
|
|
|
require Chart::OFC::Dataset::Candle; |
87
|
|
|
|
|
|
|
require Chart::OFC::Dataset::FadeBar; |
88
|
|
|
|
|
|
|
require Chart::OFC::Dataset::OutlinedBar; |
89
|
|
|
|
|
|
|
require Chart::OFC::Dataset::GlassBar; |
90
|
|
|
|
|
|
|
require Chart::OFC::Dataset::HighLowClose; |
91
|
|
|
|
|
|
|
require Chart::OFC::Dataset::Line; |
92
|
|
|
|
|
|
|
require Chart::OFC::Dataset::LineWithDots; |
93
|
|
|
|
|
|
|
require Chart::OFC::Dataset::Scatter; |
94
|
|
|
|
|
|
|
require Chart::OFC::Dataset::SketchBar; |
95
|
|
|
|
|
|
|
|
96
|
16
|
|
|
16
|
|
156
|
no Moose; |
|
16
|
|
|
|
|
55
|
|
|
16
|
|
|
|
|
200
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# ABSTRACT: Generate data files for use with Open Flash Chart |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Chart::OFC - Generate data files for use with Open Flash Chart |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 0.12 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SYNOPSIS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
use Chart::OFC; # loads all the other classes |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $set = Chart::OFC::Dataset->new( values => [ 1 .. 10 ] ); |
121
|
|
|
|
|
|
|
my $pie = Chart::OFC::Pie->new( |
122
|
|
|
|
|
|
|
title => 'Pie!', |
123
|
|
|
|
|
|
|
dataset => $set, |
124
|
|
|
|
|
|
|
labels => [ 'a' .. 'j' ], |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
print $pie->as_ofc_data(); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 DESCRIPTION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
B<NOTE: You probably want to use L<Chart::OFC2> instead, or maybe just use |
132
|
|
|
|
|
|
|
some client-side JS library and skip the flash entirely.> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This class lets you generate data for the Open Flash Chart |
135
|
|
|
|
|
|
|
library. OFC produces very attractive charts, but it's data format is |
136
|
|
|
|
|
|
|
byzantine and hard to understand. This library lets you generate that |
137
|
|
|
|
|
|
|
data with a high level API. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
OFC can display pie charts, lines and/or bars on a grid, and area |
140
|
|
|
|
|
|
|
charts on a grid. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
If you haven't explored OFC yet, you might want to stop now and go the |
143
|
|
|
|
|
|
|
OFC home page at http://teethgrinder.co.uk/open-flash-chart/. There |
144
|
|
|
|
|
|
|
are many examples of what it can do with OFC there, and seeing them |
145
|
|
|
|
|
|
|
will help you understand exactly what kind of charts you want to |
146
|
|
|
|
|
|
|
generate with this library. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Also note that this library simply generates data for OFC. You still |
149
|
|
|
|
|
|
|
need to embed the OFC flash in something and feed it the data to |
150
|
|
|
|
|
|
|
actually make a chart. This library does not generate Flash or HTML or |
151
|
|
|
|
|
|
|
anything like that. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This library was tested with OFC 1.9.7, and follows the format defined |
154
|
|
|
|
|
|
|
for that version. The OFC zip file is included in this distribution's |
155
|
|
|
|
|
|
|
tarball, under the F<ofc> directory. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 Classes |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The functionality for generating charts is split across a number of |
160
|
|
|
|
|
|
|
classes, each of which encapsulates one piece of a chart. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head3 Datasets |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Each data set represents one chunk of data to be displayed on your |
165
|
|
|
|
|
|
|
chart. There are a number of dataset subclasses for representing data |
166
|
|
|
|
|
|
|
in different formats (lines, bars, etc). You can also use the dataset |
167
|
|
|
|
|
|
|
base class, C<Chart::OFC::Dataset>, when creating a pie chart. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The dataset classes provided are: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The base class for all datasets. It has no formatting, and can only be |
176
|
|
|
|
|
|
|
used with pie charts. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::Bar |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::FadeBar |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::OutlinedBar |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::GlassBar |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::3DBar |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::SketchBar |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Formats your data as a set of bars. There are many different styles of |
191
|
|
|
|
|
|
|
bars. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::Line |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::LineWithDots |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Formats your data as a line, with optional dots marking each value. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * Chart::OFC::Dataset::Area |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Like a line with dots, but this dataset also fills in the area between |
202
|
|
|
|
|
|
|
the line and the X axis with a color. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head3 Axes and Axis Labels |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
When you are creating a non-pie chart, you will want to create an X |
209
|
|
|
|
|
|
|
and Y axis for the chart. These are represented by the |
210
|
|
|
|
|
|
|
C<Chart::OFC::XAxis> and C<Chart::OFC::YAxis> classes. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
These classes in turn can take a C<Chart::OFC::AxisLabel> class to |
213
|
|
|
|
|
|
|
define the label for the entire label. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 Grid Charts |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
A grid chart can contain any number of datasets, in any combination of |
218
|
|
|
|
|
|
|
bars and lines. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head3 Pie Charts |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
A pie chart displays a single dataset, with each value as a pie slice. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 Colors |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Many attributes in different classes expect a color. Colors can be |
227
|
|
|
|
|
|
|
provided as an RGB hex string with a leading "#" symbol, or as color |
228
|
|
|
|
|
|
|
names. Names are translated into RGB by use of the |
229
|
|
|
|
|
|
|
C<Graphics::ColorNames> module, using the "X" scheme. See that |
230
|
|
|
|
|
|
|
module's docs for more details. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 Opacity |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Several classes accept an opacity value for an attribute. This should |
235
|
|
|
|
|
|
|
be a value from 0 (completely transparent) to 100 (completely opaque). |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This class has a number of attributes which may be passed to the |
240
|
|
|
|
|
|
|
C<new()> method. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 title |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This is shown as the title of the chart. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This attribute is optional. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 title_style |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This should be a chunk of CSS specifying attributes that apply to |
251
|
|
|
|
|
|
|
text, such as "font-size", "color", etc. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
This defaults to the string "font-size: 25px". Without a default |
254
|
|
|
|
|
|
|
specifying a sane size, the default size OFC uses seems to 1px or so. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 tool_tip |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
This defines how tool tips are generated for data points. It uses a |
259
|
|
|
|
|
|
|
simple templating language. See |
260
|
|
|
|
|
|
|
http://teethgrinder.co.uk/open-flash-chart/gallery-tool-tip.php for |
261
|
|
|
|
|
|
|
details. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This attribute is optional. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 bg_color |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
The background color for the chart and surrounding text. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
This attribute is optional. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 METHODS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
All of the above named may be accessed as read-only accessors on an |
274
|
|
|
|
|
|
|
object. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This class also provide several additional methods. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head2 as_ofc_data |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Returns a textual representation of the chart suitable for delivering |
281
|
|
|
|
|
|
|
to OFC. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 ROLES |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
This class does the C<Chart::OFC::Role::OFCDataLines> role. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 TODO |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
This distribution does not yet support all of the features of OFC. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
There are a few items left to do, notably grid charts with 2 Y axes, |
292
|
|
|
|
|
|
|
and background images. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
It would also be nice to generate embeddable Javascript for populating |
295
|
|
|
|
|
|
|
charts, since this lets you create a chart without making an |
296
|
|
|
|
|
|
|
additional server request for the data. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Patches are welcome. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 DONATIONS |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
If you'd like to thank me for the work I've done on this module, |
303
|
|
|
|
|
|
|
please consider making a "donation" to me via PayPal. I spend a lot of |
304
|
|
|
|
|
|
|
free time creating free software, and would appreciate any support |
305
|
|
|
|
|
|
|
you'd care to offer. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Please note that B<I am not suggesting that you must do this> in order |
308
|
|
|
|
|
|
|
for me to continue working on this particular software. I will |
309
|
|
|
|
|
|
|
continue to do so, inasmuch as I have in the past, for as long as it |
310
|
|
|
|
|
|
|
interests me. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Similarly, a donation made in this way will probably not make me work |
313
|
|
|
|
|
|
|
on this software much more, unless I get so many donations that I can |
314
|
|
|
|
|
|
|
consider working on free software full time, which seems unlikely at |
315
|
|
|
|
|
|
|
best. |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
To donate, log into PayPal and send money to autarch@urth.org or use |
318
|
|
|
|
|
|
|
the button on this page: |
319
|
|
|
|
|
|
|
L<http://www.urth.org/~autarch/fs-donation.html> |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 BUGS |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
324
|
|
|
|
|
|
|
C<bug-chart-ofc@rt.cpan.org>, or through the web interface at |
325
|
|
|
|
|
|
|
L<http://rt.cpan.org>. I will be notified, and then you'll |
326
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head1 AUTHOR |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Dave Rolsky. |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
This is free software, licensed under: |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=cut |