Apache-Wyrd
view release on metacpan or search on metacpan
Wyrd/Chart.pm view on Meta::CPAN
=item nochache
Always generate the graphic, instead of checking to see if it has changed
=item percent
Convert values to percentages of total
=item rotate
Pivot the table returned by the query to make X Y and vice-versa
=item value_labels
Add the value to the label, as in "Foobars (2), Widgets (23)"
=back
=back
=over
=item IMG-style attributes:
=over
=item height, width, vspace, border, hspace
In pixels, as per IMG tag
=item src
Required - Where (document-root-relative) the graphic is to appear.
Currently must end with .png.
=back
=item GD::Graph-style attributes
See GD::Graph documentation for more details. Files are always
document-root-relative. Colors may be in GD::Graph name format or in in
HTML "#XXXXXX" format. Edge-positions are in the GD::Graph standard of UL
for Upper-Left, LL for Lower-Left, etc. 1 is the usual value for "yes" in
boolean attributes. Lists are in a whitespace-separated or comma-separated
list of items (using Apache::Wyrd::Services::SAK::token_parse). Angles are
in degrees.
=over
=item type
What type of graph, per the GD::Graph subclasses. Valid types are: lines,
hbars, bars, points, linespoints, area, or pie
=item b_margin t_margin l_margin r_margin
edge-to-graphic margins
=item transparent interlaced
PNG options
=item bgclr fgclr boxclr textclr labelclr axislabelclr legendclr valuesclr
accentclr shadowclr
Colors for the respective chart elements
=item dclrs borderclrs
Data element and border colors, in list format.
=item show_values values_vertical values_space values_format
Whether (1=yes) to show values, whether vertically, what space (pixels)
around them and what (sprintf-style) format to display them in.
=item logo logo_position logo_resize
logo file, corner for logo, and resize factor
=item legend_placement legend_spacing legend_marker_width
legend_marker_height lg_cols
Legend attributes (axestype graphs only)
=item x_label y_label box_axis two_axes zero_axis zero_axis_only
x_plot_values y_plot_values y_max_value y_min_value x_tick_number
x_min_value x_tick_number x_min_value x_max_value y_number_format
x_label_skip y_label_skip x_tick_offset x_all_ticks x_label_position
y_label_position x_labels_vertical long_ticks tick_length x_ticks
y_tick_number axis_space text_space
Axis attributes (for applicable chart types)
=item overwrite bar_width bar_spacing shadow_depth borderclrs cycle_clrs
cumulate
Bar-chart attributes, foo_clrs are lists. Cumulate is boolean, and means to
stack values within a bar
=item line_types line_type_scale line_width skip_undef
Line-chart attributes. Line types are 1: solid, 2: dashed, 3: dotted, 4:
dot-dashed. skip_undef leaves a gap for an undefined point
=item markers marker_size
Marker types (1: filled square, 2: open square, 3: horizontal cross, 4:
diagonal cross, 5: filled diamond, 6: open diamond, 7: filled circle, 8:
open circle, 9: horizontal line, 10: vertical line) and size (in pixels)
=item 3d pie_height start_angle suppress_angle
Pie chart attributes. suppress_angle is a limit below which no line is
drawn
=item legend_font title_font x_label_font y_label_font x_axis_font
y_axis_font
Wyrd/Chart.pm view on Meta::CPAN
my @values = @{$self->{'_graph_data'}->[$line - 1]};
foreach my $value (@values) {
push @filtered, $self->_filter($filter, $value);
}
$self->{'_graph_data'}->[$line - 1] = \@filtered;
}
}
}
sub _filter {
my ($self, $filter, $value) = @_;
if ($filter eq 'zero') {
return '0' unless $value;
} elsif ($filter eq 'dollar_sign') {
return '$' . $value;
} elsif ($filter eq 'percent_sign') {
return "$value%";
} elsif ($filter eq 'commify') {
1 while ($value =~ s/^([-+]?\d+)(\d{3})/$1,$2/);
return $value;
}else {
return $self->_special_filter($filter, $value);
}
}
=pod
=item (scalar) C<_special_filter> (scalar, scalar)
"Hook" for filtering data/labels. Should accept a value for the filter and
the data to perform filters upon.
=cut
sub _special_filter {
my ($self, $filter, $value) = @_;
return $value;
}
=pod
=back
=head1 BUGS/CAVEATS/RESERVED METHODS
Reserves the register_filter, _setup and _format_output methods. Also
reserves the methods _set_default_attributes, _get_data, _process_data,
_filter_labels, _filter_values, _filter. Also reserves the standard
register_query method.
Produces, by default, a second file (E<lt>graphic_nameE<gt>.tdf) in the same
directory as the graphic which has the HTML fingerprint and the data stored
in tab-delineated-text format.
=cut
sub _setup {
my ($self) = @_;
$self->{'_valid_attributes'} = {
'img' => [qw(align alt border height hspace ismap longdesc usemap vspace width src)],
'all' => [qw(b_margin t_margin l_margin r_margin transparent interlaced bgclr fgclr boxclr textclr labelclr axislabelclr legendclr valuesclr accentclr shadowclr dclrs show_values values_vertical values_space values_format logo logo_position logo_...
'axes' => [qw(x_label y_label box_axis two_axes zero_axis zero_axis_only x_plot_values y_plot_values y_max_value y_min_value x_tick_number x_min_value x_tick_number x_min_value x_max_value y_number_format x_label_skip y_label_skip x_tick_offset x...
'bars' => [qw(overwrite bar_width bar_spacing shadow_depth borderclrs cycle_clrs cumulate)],
'lines' => [qw(line_types line_type_scale line_width skip_undef)],
'points' => [qw(markers marker_size)],
'pie' => [qw(3d pie_height start_angle suppress_angle)],
'builtin_fonts' => [qw(gdTinyFont gdSmallFont gdMediumBoldFont gdLargeFont gdGiantFont)],
'font_attr' => [qw(legend_font title_font x_label_font y_label_font x_axis_font y_axis_font)],
'font_attr_pie' => [qw(legend_font title_font label_font value_font)],
'color_attr' => [qw(bgclr fgclr boxclr textclr labelclr axislabelclr legendclr valuesclr accentclr shadowclr dclrs)],
'array_attr' => [qw(dclrs markers)],
'boolean_attr' => [qw(transparent interlaced show_values values_vertical box_axis two_axes zero_axis zero_axis_only x_plot_values y_plot_values x_all_ticks x_labels_vertical long_ticks x_ticks correct_width cycle_clrs cumulate skip_undef 3d)]
};
$self->{'_chart_attributes'} = [];
$self->_set_default_attributes;
}
sub _format_output {
my ($self) = @_;
$self->_raise_exception('Chart Wyrds require Query Wyrds')
unless ($self->{'sh'});
my $file = $self->{'src'};
my $root = $self->dbl->req->document_root;
if ($file) {
$file = "$root$file";
} else {
$self->_raise_exception("Chart Wyrds require a src attribute");
}
$self->_file_problems($file);
my ($format) = $file =~ /\.(png|gif)$/i;
unless ($format) {
$self->_raise_exception('Only PNG or GIF file format is supported');
}
$self->{'_graphic_file'} = $file;
$self->{'_file_format'} = lc($format);
my $datafile = $file;
$datafile =~ s/\.$format/\.tdf/;
$self->_file_problems($datafile);
$self->{'_data_file'} = $datafile;
my $data = $self->_get_data;
my $cache = '';
$cache = $self->slurp_file($datafile) if (-f $datafile);
if (($data ne $cache)) {
$self->_info("(Re)building chart...");
$self->_process_data;
$self->_plot;
#warn $datafile;
spit_file($datafile, $data);
}
my %image_attributes = map {$_, $self->{$_}} @{$self->{'_valid_attributes'}->{'img'}};
#warn $self->_image_template;
$self->_data($self->_set(\%image_attributes, $self->_image_template));
return;
}
sub register_query {
my ($self, $query) = @_;
$self->{'sh'} = $query->sh;
}
=pod
=head1 AUTHOR
Barry King E<lt>wyrd@nospam.wyrdwright.comE<gt>
=head1 SEE ALSO
=over
=item Apache::Wyrd
( run in 1.402 second using v1.01-cache-2.11-cpan-6aa56a78535 )