/usr/share/perl5/Jifty/Plugin/Chart.pm is in libjifty-plugin-chart-perl 1.01+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | use strict;
use warnings;
package Jifty::Plugin::Chart;
use base qw/ Jifty::Plugin Class::Accessor::Fast /;
our $VERSION = '1.01';
use Jifty::Plugin::Chart::Web;
use Scalar::Util qw/ blessed /;
__PACKAGE__->mk_accessors(qw/ renderer renderers plugin_args _prereq_plugins/);
=head1 NAME
Jifty::Plugin::Chart - A charting API for Jifty
=head1 SYNOPSIS
In your F<config.yml>:
Plugins:
- Chart: {}
In your Mason templates:
<% Jifty->web->chart(
type => 'Bar',
width => 400,
height => 300,
data => [
[ '2004', '2005', '2006', '2007' ], # labels
[ 14, 15, 17, 22 ], # first data set
[ 22, 25, 20, 21 ], # second data set
],
) %>
=head1 DESCRIPTION
B<CAUTION:> This plugin is experimental. The API I<will> change.
This plugin provides a charting API that can be used by Jifty applications to build data visualizations without regard to the underlying rendering mechanism.
As of this writing, the API is a barely veiled interface over L<Chart>. However, I intend to expand the interface to apply to something like Maani's XML/SWF Charts or Imprise Javascript charts or even something like OpenLaszlo (or something Open Source and Perl if I can find or build such a thing in time).
=head1 INTERFACE
By adding this method to the plugin configuration for your Jifty application, you will cause L<Jifty::Web> to inherit a new method, C<chart>, which is the cornerstone of this API.
This method is described in L<Jifty::Plugin::Chart::Web> and an example is shown in the L</SYNOPSIS> above.
=head1 CONFIGURATION
Here is an example configuration for F<config.yml>:
Plugins:
- Chart:
DefaultRenderer: PlotKit
PreloadRenderers:
- XMLSWF
- SimpleBars
- App::Renderer::Custom
The available options are:
=over
=item DefaultRenderer
This is the name of the class to use as the default renderer. L<Jifty::Plugin::Chart::Renderer::Chart> is the current default, but that could change in the future. It's recommended that you set this to your preference.
=item PreloadRenderers
This is a list of other render classes to load during initialization. If they are not loaded during initialization some renderers may not work correctly the first time they are run because they are not able to inform Jifty of the CSS or JS files they need before that part of the page is already rendered. If you use the "renderer" option of L<Jifty::Plugin::Chart::Web/chart>, then you should make sure any value you use is set here in the configuration to make sure it works properly.
=back
=head1 METHODS
=head2 init
Adds the L<Jifty::Plugin::Chart::Web/chart> method to L<Jifty::Web>.
=cut
sub init {
my $self = shift;
my %args = (
DefaultRenderer => 'Chart',
@_,
);
# Save the arguments for use in init_renderer() later
$self->plugin_args( \%args );
$self->_prereq_plugins( [] );
# Deprecating the old form
if (defined $args{renderer}) {
warn 'DEPRECATED: renderer argument to Chart plugin is deprecated.'
.' Use DefaultRenderer instead.';
$args{DefaultRenderer} = delete $args{renderer};
}
# Create the empty renderers list
$self->renderers({});
# Pre-load any renderers they plan to use
if (defined $args{PreloadRenderers}) {
$args{PreloadRenderers} = [ $args{PreloadRenderers} ]
unless ref $args{PreloadRenderers};
for my $renderer (@{ $args{PreloadRenderers} }) {
$self->init_renderer( $renderer );
}
}
# Load the default renderer
$self->renderer( $self->init_renderer( $args{DefaultRenderer}, %args ) );
push @Jifty::Web::ISA, 'Jifty::Plugin::Chart::Web';
}
=head2 init_renderer
my $renderer = $chart_plugin->init_renderer($renderer_class)
This is a helper method that is used by the API to initialize the renderer class. This is handled automatically so you probably shouldn't use this.
=cut
sub init_renderer {
my ( $self, $renderer_class ) = ( shift, shift );
# If it's already an object, just return that
if ( blessed($renderer_class)
and $renderer_class->isa(__PACKAGE__.'::Renderer') ) {
return $renderer_class;
}
# Prepend Jifty::Plugin::Chart::Renderer:: if we think we need to
my @renderer_classes = (
$renderer_class,
__PACKAGE__ . '::Renderer::' . $renderer_class,
);
for my $renderer_class (@renderer_classes) {
# Check to see if we already loaded this one
my $renderer = $self->renderers->{ $renderer_class };
return $renderer if defined $renderer;
# Tell perl to load the class
unless ($renderer_class->require) {
warn $@ unless $@ =~ /^Can't locate /;
next;
}
# Initialize the renderer
$renderer = $renderer_class->new( %{ $self->plugin_args } );
if( $renderer->can('prereq_plugins') ) {
my @prereq_plugins = $renderer->prereq_plugins ;
push @{ $self->{_prereq_plugins} } , @prereq_plugins ;
}
# Remember it
$self->renderers->{ $renderer_class } = $renderer;
# Return it!
return $renderer;
}
}
sub prereq_plugins {
my $self = shift;
return @{ $self->_prereq_plugins };
}
=head1 SEE ALSO
L<Jifty::Plugin>, L<Jifty::Web>, L<Jifty::Plugin::Chart::Renderer>, L<Jifty::Plugin::Chart::Renderer::Chart>, L<Jifty::Plugin::Chart::View>
=head1 AUTHOR
Andrew Sterling Hanenkamp C<< <andrew.hanenkamp@boomer.com> >>
=head1 COPYRIGHT AND LICENSE
Copyright 2007 Boomer Consulting, Inc.
This is free software and may be modified and redistributed under the same terms as Perl itself.
=cut
1;
|