Graph-Chart

 view release on metacpan or  search on metacpan

Graph-Chart_example.pl  view on Meta::CPAN

#    }
#);
my @alarm;
for ( 90 .. 180 )
{
    $alarm[$_] = 1;

}

#
#$graph->overlay(
#{
#	layer => 1,
#	set   => \@alarm,
#	color => '0xFFFECE',
##	color => '0xFFD2D2',
#	opacity => 100,
#	type => 'pie',
#	merge  => 1,
##	debord => 50,
#}
#);
#
#my @alarm1;
#for ( 100 .. 250 )
#{
#$alarm1[ $_  ] = 1;
#
#}
#
#
#$graph->overlay(
#{
#	layer => 0,
#	set   => \@alarm1,
#	color => '0xFFD2D2',
#	opacity => 100,
#	merge  => 0,
#	type => 'pie',
#}
#);

README  view on Meta::CPAN

                            kerning_correction => 0.85,                             # a kerning correcting to correct align of text when rotated ( default 0.91 ) 
                            color => '0xff0000',                                    # the text color
                            size  => 10,                                            # the font size to use
            #               space => 10,                                            # an extra space between the division and the text
            #               rotate => 'follow',                                     # rotate the text to be following the division direction
                            rotate => 'perpendicular',                              # rotate the the to be perpendicular to the division
                                                                                    # if missing write the text without rotation
                            text => [700031220,45,90,135,180,225,270,31500 , 1 ,2], #  the text to render ( a undef element is not ploted, this allow to skip some label )
            #               },      

                    overlay=> {                                                     # add an overlay to the graph (useful to show an alert period )
                      layer => 10,                                                  # the layer where the data is plotted ( the lowest number is the deepest layer ) If missing, the layer is created by call order of the method data 
                      set   => \@alarm,                                             # a array ref with the data ( the number of dot plotted is the number  W provided by the size parameter/method
                      type  => 'pie',                                               # the type of graph ( dot, line, bar, up_dot, up_bar, up_line , down_dot,down_line, down_bar, pie, target, radial )
                      color => '0xFFD2D2',                                          # color of the plotted element
                      type => 'pie',                                                # if missing normal overlay are used, if present use a polar structure ( data are in the range of 0 to 360 ° ) 
                      merge  => 1,                                                  # if present and not = 0 all overlay are overwrited by the overlay from a higer layer
                      opacity => 100,                                               # when merge is missing, the overlay % of opacity copied on the chart
                      debord => 50,                                                 # the debord of the overlay. if missing use the full graph height and in polar ( pie ) use the smallest vertical border ( top or bottom ) 
                      },
          
                      glyph => {                                                    # add some ornament on the graph like line, text or polygon
                    x     => $graph->{x}{min}+200,                                          # the origin of the glyph, all other position are relative to this origin
                    y     => $graph->{x}{max} ,                                             # either in pixel  x =>0 , y=> 0 = corner lower left
                                                                                    # see the active method
                    type  => 'filled',                                              # type of glyph ( missing = open polygyn, 'filled' = filled polygon, 'text' = text )
                    color => '0x00FFff',                                            # color of the glyph
                    data  => [                                                      # if one of the polygon type, the data is a set of point to plot ( value relative to the origin )
                        [ 0,  0 ],

README  view on Meta::CPAN

                push @{ $self->{ data } }, clone( $object );
            }
        }
        return $self->{ data };
    }

    ########################################################################
    ###

    ########################################################################
    ### ### method to put an overlay on top of the graph ###
    ########################################################################
    ###

  overlay
            method to put an overlay on top of the graph ( to show alarm period ... )

      use the same parameter as the new()
      if the same layer is already present, overwrite this layer

  overlay
            method to put a glyph on the graph ( to show the latest data polled, or a trend value, ... )

      use the same parameter as the new()
      if the same layer is already present, overwrite this layer

  png_zEXt
            method to add a png data TAG 
            This tag is not a PNG standard, but allowed by the RFC
            see code in img_info.pl 
        

lib/Graph/Chart.pm  view on Meta::CPAN

		kerning_correction => 0.85,				# a kerning correcting to correct align of text when rotated ( default 0.91 ) 
		color => '0xff0000',					# the text color
                size  => 10,						# the font size to use
#		space => 10,						# an extra space between the division and the text
#		rotate => 'follow',					# rotate the text to be following the division direction
		rotate => 'perpendicular',				# rotate the the to be perpendicular to the division
									# if missing write the text without rotation
                text => [700031220,45,90,135,180,225,270,31500 , 1 ,2], #  the text to render ( a undef element is not ploted, this allow to skip some label )
#		},	

	overlay=> {							# add an overlay to the graph (useful to show an alert period )
	  layer => 10, 							# the layer where the data is plotted ( the lowest number is the deepest layer ) If missing, the layer is created by call order of the method data 
	  set   => \@alarm,						# a array ref with the data ( the number of dot plotted is the number  W provided by the size parameter/method
	  type  => 'pie',						# the type of graph ( dot, line, bar, up_dot, up_bar, up_line , down_dot,down_line, down_bar, pie, target, radial )
	  color => '0xFFD2D2',						# color of the plotted element
	  type => 'pie',						# if missing normal overlay are used, if present use a polar structure ( data are in the range of 0 to 360 ° ) 
	  merge  => 1,							# if present and not = 0 all overlay are overwrited by the overlay from a higer layer
	  opacity => 100,						# when merge is missing, the overlay % of opacity copied on the chart
	  debord => 50,							# the debord of the overlay. if missing use the full graph height and in polar ( pie ) use the smallest vertical border ( top or bottom ) 
	  },
	  
	  glyph => {							# add some ornament on the graph like line, text or polygon
        x     => $graph->{x}{min}+200,						# the origin of the glyph, all other position are relative to this origin
	y     => $graph->{x}{max} ,						# either in pixel  x =>0 , y=> 0 = corner lower left
									# see the active method
        type  => 'filled',						# type of glyph ( missing = open polygyn, 'filled' = filled polygon, 'text' = text )
        color => '0x00FFff',						# color of the glyph
        data  => [							# if one of the polygon type, the data is a set of point to plot ( value relative to the origin )
            [ 0,  0 ],

lib/Graph/Chart.pm  view on Meta::CPAN

        if ( !exists { @_ }->{ reticle }->{ debord } )
        {
            $self->{ reticle }{ debord } = 0;
        }
        if ( !exists $self->{ reticle }{ number } )
        {
            $self->{ reticle }->{ number } = 2;
        }
    }

    if ( exists { @_ }->{ overlay } )
    {
        if ( exists { @_ }->{ overlay }{ layer } )
        {
            $self->{ overlay }[ { @_ }->{ overlay }{ layer } ] = clone( { @_ }->{ overlay } );
        }
        else
        {
            push @{ $self->{ overlay } }, clone( { @_ }->{ overlay } );
        }
    }
    if ( exists { @_ }->{ glyph } )
    {
        if ( exists { @_ }->{ glyph }{ layer } )
        {
            $self->{ glyph }[ { @_ }->{ glyph }{ layer } ] = clone( { @_ }->{ glyph } );
        }
        else
        {

lib/Graph/Chart.pm  view on Meta::CPAN

        {
            push @{ $self->{ data } }, clone( $object );
        }
    }
    return $self->{ data };
}

###########################################################################

###########################################################################
### 		method to put an overlay on top of the graph  		###
###########################################################################

=head2 overlay

	method to put an overlay on top of the graph ( to show alarm period ... )


  use the same parameter as the new()
  if the same layer is already present, overwrite this layer

=cut

sub overlay
{
    my $self   = shift;
    my $object = shift;

    if ( $object )
    {
        if ( exists $object->{ layer } )
        {
            $self->{ overlay }[ $object->{ layer } ] = clone( $object );
        }
        else
        {
            push @{ $self->{ overlay } }, clone( $object );
        }
    }
    return $self->{ overlay };
}
###########################################################################

###########################################################################
### 		method to put a glyph on the graph  		###
###########################################################################

=head2 overlay

	method to put a glyph on the graph ( to show the latest data polled, or a trend value, ... )


  use the same parameter as the new()
  if the same layer is already present, overwrite this layer

=cut

sub glyph

lib/Graph/Chart.pm  view on Meta::CPAN

{
    my $self   = shift;
    my $object = shift;

    my $frame = new GD::Image( $self->{ size }->[0] + $self->{ border }->[0] + $self->{ border }->[1], $self->{ size }->[1] + $self->{ border }->[2] + $self->{ border }->[3] );
    my $bg_color = _color_allocate( $self->{ bg_color }, 'ffffffff', $frame );
    my $bg_color = _color_allocate( $self->{ bg_color }, 'ffffffff', $frame );
    $frame->transparent( $bg_color );
    $frame->interlaced( 'true' );

### plot overlay
    if ( exists $self->{ overlay } )
    {
        foreach my $layer ( @{ $self->{ overlay } } )
        {
            next unless ( ref $layer eq 'HASH' );
            my $col_graph;
            my $frame_over;
            if ( exists $layer->{ merge } && $layer->{ merge } )
            {
                $col_graph = _color_allocate( $layer->{ color }, '00000000', $frame );
            }
            else
            {

lib/Graph/Chart.pm  view on Meta::CPAN

            {
            }
            else
            {
                my $trans = $layer->{ opacity } || 20;
                $frame->copyMerge( $frame_over, 0, 0, 0, 0, $self->{ size }->[0] + $self->{ border }->[0] + $self->{ border }->[1], $self->{ size }->[1] + $self->{ border }->[2] + $self->{ border }->[3], $trans );
            }

        }
    }
### end plot overlay

### plot data
    if ( exists $self->{ data } )
    {
        my $last_pie;
        foreach my $layer ( @{ $self->{ data } } )
        {
            next unless ( ref $layer eq 'HASH' );
            my $max       = max( @{ $layer->{ set } } );
            my $min       = min( @{ $layer->{ set } } );



( run in 0.500 second using v1.01-cache-2.11-cpan-49f99fa48dc )