SVG-Template-Graph

 view release on metacpan or  search on metacpan

lib/SVG/Template/Graph.pm  view on Meta::CPAN

             'style' => {
                  'right' => '10'
              },
             'position' => [
                  '150',
                  '100',
                  '0',
                  '-75'
              ],
             'label' => [
                  'Much',
                  'Some',
                  'None',
                  'Lost'
              ]
         },
         'x_ticks' => {}
     };

=cut

sub getTick($$$) {
    my $self = shift;
    my $l    = shift;
    my $o    = shift;
    $o = lc($o);
    $o = 'x' unless $o eq 'y';

    my $extender = [ 0, 0 ];

    return undef unless defined $l->{"${o}_ticks"}->{style};

    my %map = (
        x => [ 'top',  'bottom' ],
        y => [ 'left', 'right' ]
    );

    my $one = $map{$o}->[0];
    my $two = $map{$o}->[1];

    #handle constant-x (vertical) gridlines
    $extender->[0] =
      defined $l->{"${o}_ticks"}->{style}->{$one}
      ? $l->{"${o}_ticks"}->{style}->{$one}
      : 0;
    $extender->[1] =
      defined $l->{"${o}_ticks"}->{style}->{$two}
      ? $l->{"${o}_ticks"}->{style}->{$two}
      : 0;
    return $extender;
}

=head2 D

$self->D()

returns the SVG Document object

=cut

sub D ($) {
    my $self = shift;
    return $self->{_svgTree_};
}

=head2 T($name)

$self->T($name)

returns the currently invoked transformation object. Returns transformation object $name if requested by name

=cut

sub T ($;$) {
    my $self = shift;
    my $name = shift;
    return $self->{maps}->{$name} if defined $name;
    return $self->{map};
}

=head2 setGraphTarget $targetid, $elementType <rect>, %element_attributes

define the graph target (currently only rectangles are accepted) on top of which the data will be drawn

=cut

sub setGraphTarget ($$;@) {
    my $self = shift;
    $self->{graphTarget} = shift || $self->mapTemplateId('rectangle.graph.data.space');
    my $type = shift || 'rect';
    return $self->_gg( $self->{graphTarget}, $type, @_ );
}

=head2 getGraphTarget

returns the current graph target

=cut

sub getGraphTarget ($) {
    my $self = shift;
    return $self->{graphTarget};
}

=head2 autoGrid (int $min, int $max, int $count)

generates a reference to an array of $count+1 evenly distributed values ranging between $min and $max  

	$tt->autoGrid(0,100,10);

=cut

sub autoGrid ($$$) {
    my $self = shift;
    my ( $min, $max, $count ) = @_;
    my @array = ( 0 .. $count );
    map { $_ = ( $max - $min ) / ($count) * $_ } @array;

    #print STDERR Dumper \@array;
    return \@array;
}

=head2 Format

format an array of values according to formatting rules

 $tt->Format \@array,$format,$format_attribute[,@more_format_attributes]

 $format can be 'time' or 'printf'

for 'time', uses the Time::localtime 

example 1: formatting to print the verbose date



( run in 1.493 second using v1.01-cache-2.11-cpan-524268b4103 )