Chart
view release on metacpan or search on metacpan
lib/Chart/Composite.pm view on Meta::CPAN
# replace the gd_obj fields
$self->{'sub_0'}->{'gd_obj'} = $self->{'gd_obj'};
$self->{'sub_1'}->{'gd_obj'} = $self->{'gd_obj'};
# let the sub-objects know they're sub-objects
$self->{'sub_0'}->{'component'} = 'true';
$self->{'sub_1'}->{'component'} = 'true';
# give each sub-object its data
$self->{'component_datasets'} = [];
for $i ( 0 .. 1 )
{
$ref = [];
$self->{'component_datasets'}[$i] = $self->{'composite_info'}[$i][1];
push @{$ref}, $self->{'dataref'}[0];
for $j ( @{ $self->{'composite_info'}[$i][1] } )
{
$self->_color_role_to_index( 'dataset' . ( $j - 1 ) ); # allocate color index
push @{$ref}, $self->{'dataref'}[$j];
}
$self->{ 'sub_' . $i }->_copy_data($ref);
}
# and let them check it
$self->{'sub_0'}->_check_data;
$self->{'sub_1'}->_check_data;
# realign the y-axes if they want
if ( $self->true( $self->{'same_y_axes'} ) )
{
if ( $self->{'sub_0'}{'min_val'} < $self->{'sub_1'}{'min_val'} )
{
$self->{'sub_1'}{'min_val'} = $self->{'sub_0'}{'min_val'};
}
else
{
$self->{'sub_0'}{'min_val'} = $self->{'sub_1'}{'min_val'};
}
if ( $self->{'sub_0'}{'max_val'} > $self->{'sub_1'}{'max_val'} )
{
$self->{'sub_1'}{'max_val'} = $self->{'sub_0'}{'max_val'};
}
else
{
$self->{'sub_0'}{'max_val'} = $self->{'sub_1'}{'max_val'};
}
$self->{'sub_0'}->_check_data;
$self->{'sub_1'}->_check_data;
}
# find out how big the y-tick labels will be from sub_0 and sub_1
$self->{'y_tick_label_length1'} = $self->{'sub_0'}->{'y_tick_label_length'};
$self->{'y_tick_label_length2'} = $self->{'sub_1'}->{'y_tick_label_length'};
# now return
return;
}
## @fn private int _draw_legend()
# let the user know what all the pretty colors mean
# @return status
#
sub _draw_legend
{
my $self = shift;
my ($length);
# check to see if they have as many labels as datasets,
# warn them if not
if ( ( $#{ $self->{'legend_labels'} } >= 0 )
&& ( ( scalar( @{ $self->{'legend_labels'} } ) ) != $self->{'num_datasets'} ) )
{
carp "The number of legend labels and datasets doesn\'t match";
}
# init a field to store the length of the longest legend label
unless ( $self->{'max_legend_label'} )
{
$self->{'max_legend_label'} = 0;
}
# fill in the legend labels, find the longest one
for ( 1 .. $self->{'num_datasets'} )
{
unless ( $self->{'legend_labels'}[ $_ - 1 ] )
{
$self->{'legend_labels'}[ $_ - 1 ] = "Dataset $_";
}
$length = length( $self->{'legend_labels'}[ $_ - 1 ] );
if ( $length > $self->{'max_legend_label'} )
{
$self->{'max_legend_label'} = $length;
}
}
# different legend types
if ( $self->{'legend'} eq 'bottom' )
{
$self->_draw_bottom_legend;
}
elsif ( $self->{'legend'} eq 'right' )
{
$self->_draw_right_legend;
}
elsif ( $self->{'legend'} eq 'left' )
{
$self->_draw_left_legend;
}
elsif ( $self->{'legend'} eq 'top' )
{
$self->_draw_top_legend;
}
elsif ( $self->{'legend'} eq 'none' )
{
$self->_draw_none_legend;
}
else
{
carp "I can't put a legend there\n";
}
# and return
return 1;
}
## @fn private int _draw_top_legend()
# put the legend on the top of the data plot
#
# Overwrite the base class _draw_top_legend
#
# @return status
sub _draw_top_legend
{
my $self = shift;
my @labels = @{ $self->{'legend_labels'} };
my ( $x1, $y1, $x2, $y2, $empty_width, $max_label_width );
my ( $cols, $rows, $color );
my ( $col_width, $row_height, $i, $j, $r, $c, $index, $x, $y, $sub, $w, $h );
my ( $yh, $yi ); # for boxing legends
my $font = $self->{'legend_font'};
my ( %colors, @datasets );
my $max_legend_example = 0;
$yh = 0;
# copy the current boundaries into the sub-objects
$self->_sub_update;
# init the legend_example_height
$self->_legend_example_height_init;
## Make datasetI numbers match indexes of @{ $self->{'dataref'} }[1.....].
# # modify the dataset color table entries to avoid duplicating
# # dataset colors (this limits the number of possible data sets
# # for each component to 8)
# for (0..7) {
# $self->{'sub_1'}{'color_table'}{'dataset'.$_}
# = $self->{'color_table'}{'dataset'.($_+8)};
# }
# modify the dataset color table entries to avoid duplicating
# dataset colors.
my ( $n0, $n1 ) = map { scalar @{ $self->{'composite_info'}[$_][1] } } 0 .. 1;
for ( 0 .. $n1 - 1 )
{
$self->{'sub_1'}{'color_table'}{ 'dataset' . $_ } = $self->{'color_table'}{ 'dataset' . ( $_ + $n0 ) };
}
# make sure we use the right colors for the legend
@datasets = @{ $self->{'composite_info'}[0][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ($i) };
$i++;
}
@datasets = @{ $self->{'composite_info'}[1][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ( $i + $n0 ) };
$i++;
}
# make sure we're using a real font
unless ( ( ref($font) ) eq 'GD::Font' )
{
croak "The subtitle font you specified isn\'t a GD Font object";
}
# get the size of the font
( $h, $w ) = ( $font->height, $font->width );
# get some base x coordinates
$x1 =
$self->{'curr_x_min'} +
$self->{'graph_border'} +
$self->{'y_tick_label_length1'} * $self->{'tick_label_font'}->width +
$self->{'tick_len'} +
( 3 * $self->{'text_space'} );
$x2 =
$self->{'curr_x_max'} -
$self->{'graph_border'} -
$self->{'y_tick_label_length2'} * $self->{'tick_label_font'}->width -
$self->{'tick_len'} -
( 3 * $self->{'text_space'} );
if ( $self->{'y_label'} )
{
$x1 += $self->{'label_font'}->height + 2 * $self->{'text_space'};
}
if ( $self->{'y_label2'} )
{
$x2 -= $self->{'label_font'}->height + 2 * $self->{'text_space'};
}
# figure out how wide the widest label is, then figure out how many
# columns we can fit into the allotted space
$empty_width = $x2 - $x1 - ( 2 * $self->{'legend_space'} );
$max_label_width =
$self->{'max_legend_label'} * $self->{'legend_font'}->width + 4 * $self->{'text_space'} + $self->{'legend_example_size'};
$cols = int( $empty_width / $max_label_width );
unless ($cols)
{
$cols = 1;
}
$col_width = $empty_width / $cols;
# figure out how many rows we need and how tall they are
$rows = int( $self->{'num_datasets'} / $cols );
unless ( ( $self->{'num_datasets'} % $cols ) == 0 )
{
$rows++;
}
unless ($rows)
{
$rows = 1;
}
$row_height = $h + $self->{'text_space'};
# box the legend off
$y1 = $self->{'curr_y_min'};
$y2 = $self->{'curr_y_min'} + $self->{'text_space'} + ( $rows * $row_height ) + ( 2 * $self->{'legend_space'} );
$self->{'gd_obj'}->rectangle( $x1, $y1, $x2, $y2, $self->_color_role_to_index('misc') );
$max_legend_example = $y2 - $y1;
# leave some space inside the legend
$x1 += $self->{'legend_space'} + $self->{'text_space'};
$x2 -= $self->{'legend_space'};
$y1 += $self->{'legend_space'} + $self->{'text_space'};
$y2 -= $self->{'legend_space'} + $self->{'text_space'};
# draw in the actual legend
$r = 0; # current row
$c = 0; # current column
$yi = 0; # current dataset
for $i ( 0 .. 1 )
{
for $j ( 0 .. $#{ $self->{'component_datasets'}[$i] } )
{
# get the color
$color = $self->{ 'sub_' . $i }->{'color_table'}{ 'dataset' . $j };
$index = $self->{'component_datasets'}[$i][$j] - 1; # index in label list
# find the x-y coordinates for the beginning of the example line
$x = $x1 + ( $col_width * $c );
$y = $y1 + ( $row_height * $r ) + $h / 2;
# draw the example line if legend_example_height==1 or ==0
if ( $rows == 1 )
{
if ( $self->{ 'legend_example_height' . $yi } < $max_legend_example )
{
$yh = $self->{ 'legend_example_height' . $yi };
}
else
{
$yh = $max_legend_example;
}
}
else
{
if ( $self->{ 'legend_example_height' . $yi } < $row_height )
{
$yh = $self->{ 'legend_example_height' . $yi };
}
else
{
$yh = $row_height;
}
}
$yi++;
if ( $yh <= 1 )
{
$self->{'gd_obj'}->line( $x, $y, $x + $self->{'legend_example_size'}, $y, $color );
}
else
{
# draw the example bar if legend_example_height > 1
$yh = int( $yh / 2 );
$self->{'gd_obj'}->filledRectangle( $x, $y - $yh, $x + $self->{'legend_example_size'}, $y + $yh, $color );
}
# find the x-y coordinates for the beginning of the label
$x += $self->{'legend_example_size'} + 2 * $self->{'text_space'};
$y -= $h / 2;
# now draw the label
$self->{'gd_obj'}->string( $font, $x, $y, $labels[$index], $color );
# keep track of which row/column we're using
$r = ( $r + 1 ) % $rows;
if ( $r == 0 )
{
$c++;
}
}
}
# mark of the space used
$self->{'curr_y_min'} += $rows * $row_height + $self->{'text_space'} + 2 * $self->{'legend_space'};
return;
}
## @fn private int _draw_right_legend()
# put the legend on the right of the chart
#
# Overwrite the base class _draw_right_legend
#
# @return status
sub _draw_right_legend
{
my $self = shift;
my @labels = @{ $self->{'legend_labels'} };
my ( $x1, $x2, $x3, $y1, $y2, $width, $color, $misccolor, $w, $h );
my ($yh) = 0; # for boxing legend
my $font = $self->{'legend_font'};
my ( %colors, @datasets, $i );
my $max_legend_example = 0;
# copy the current boundaries and colors into the sub-objects
$self->_sub_update;
# init the legend exapmle height
$self->_legend_example_height_init;
# # modify the dataset color table entries to avoid duplicating
# # dataset colors (this limits the number of possible data sets
# # for each component to 8)
# for (0..7) {
# $self->{'sub_1'}{'color_table'}{'dataset'.$_}
# = $self->{'color_table'}{'dataset'.($_+8)};
# }
# modify the dataset color table entries to avoid duplicating
# dataset colors.
my ( $n0, $n1 ) = map { scalar @{ $self->{'composite_info'}[$_][1] } } 0 .. 1;
for ( 0 .. $n1 - 1 )
{
$self->{'sub_1'}{'color_table'}{ 'dataset' . $_ } = $self->{'color_table'}{ 'dataset' . ( $_ + $n0 ) };
}
# make sure we use the right colors for the legend
@datasets = @{ $self->{'composite_info'}[0][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ($_) };
$i++;
}
@datasets = @{ $self->{'composite_info'}[1][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ( $i + $n0 ) };
$i++;
}
# make sure we're using a real font
unless ( ( ref($font) ) eq 'GD::Font' )
{
croak "The subtitle font you specified isn\'t a GD Font object";
}
# get the size of the font
( $h, $w ) = ( $font->height, $font->width );
# get the miscellaneous color
$misccolor = $self->_color_role_to_index('misc');
# find out how wide the largest label is
$width =
( 2 * $self->{'text_space'} ) +
( $self->{'max_legend_label'} * $w ) +
$self->{'legend_example_size'} +
( 2 * $self->{'legend_space'} );
# box the thing off
$x1 = $self->{'curr_x_max'} - $width;
$x2 = $self->{'curr_x_max'};
$y1 = $self->{'curr_y_min'} + $self->{'graph_border'};
$y2 =
$self->{'curr_y_min'} +
$self->{'graph_border'} +
$self->{'text_space'} +
( $self->{'num_datasets'} * ( $h + $self->{'text_space'} ) ) +
( 2 * $self->{'legend_space'} );
$self->{'gd_obj'}->rectangle( $x1, $y1, $x2, $y2, $misccolor );
# leave that nice space inside the legend box
$x1 += $self->{'legend_space'};
$y1 += $self->{'legend_space'} + $self->{'text_space'};
# now draw the actual legend
for ( 0 .. $#labels )
{
# get the color
$color = $colors{$_};
# find the max_legend_example
$max_legend_example = $self->{'legend_space'} + $h;
# find the x-y coords
$x2 = $x1;
$x3 = $x2 + $self->{'legend_example_size'};
$y2 = $y1 + ( $_ * ( $self->{'text_space'} + $h ) ) + $h / 2;
# draw the example line if legend_example_height==1 or ==0
if ( $self->{ 'legend_example_height' . $_ } < $max_legend_example )
{
$yh = $self->{ 'legend_example_height' . $_ };
}
else
{
$yh = $max_legend_example;
}
if ( $yh <= 1 )
{
$self->{'gd_obj'}->line( $x2, $y2, $x3, $y2, $color );
}
else
{
$yh = int( $yh / 2 );
$self->{'gd_obj'}->filledRectangle( $x2, $y2 - $yh, $x3, $y2 + $yh, $color );
}
# now the label
$x2 = $x3 + ( 2 * $self->{'text_space'} );
$y2 -= $h / 2;
$self->{'gd_obj'}->string( $font, $x2, $y2, $labels[$_], $color );
}
# mark off the used space
$self->{'curr_x_max'} -= $width;
# and return
return;
}
## @fn private int _draw_left_legend()
# draw the legend at the left of the data plot
#
# Overwrite the base class _draw_left_legend
#
# @return status
sub _draw_left_legend
{
my $self = shift;
my @labels = @{ $self->{'legend_labels'} };
my ( $x1, $x2, $x3, $y1, $y2, $width, $color, $misccolor, $w, $h );
my $yh; # for boxing legend
my $font = $self->{'legend_font'};
my ( %colors, @datasets, $i );
my $max_legend_example = 0;
# copy the current boundaries and colors into the sub-objects
$self->_sub_update;
# init the legend_example height
$self->_legend_example_height_init;
# # modify the dataset color table entries to avoid duplicating
# # dataset colors (this limits the number of possible data sets
# # for each component to 8)
# for (0..7) {
# $self->{'sub_1'}{'color_table'}{'dataset'.$_}
# = $self->{'color_table'}{'dataset'.($_+8)};
# }
# modify the dataset color table entries to avoid duplicating
# dataset colors.
my ( $n0, $n1 ) = map { scalar @{ $self->{'composite_info'}[$_][1] } } 0 .. 1;
for ( 0 .. $n1 - 1 )
{
$self->{'sub_1'}{'color_table'}{ 'dataset' . $_ } = $self->{'color_table'}{ 'dataset' . ( $_ + $n0 ) };
}
# make sure we use the right colors for the legend
@datasets = @{ $self->{'composite_info'}[0][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ($i) };
$i++;
}
@datasets = @{ $self->{'composite_info'}[1][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ( $i + $n0 ) };
$i++;
}
# make sure we're using a real font
unless ( ( ref($font) ) eq 'GD::Font' )
{
croak "The subtitle font you specified isn\'t a GD Font object";
}
# get the size of the font
( $h, $w ) = ( $font->height, $font->width );
# get the miscellaneous color
$misccolor = $self->_color_role_to_index('misc');
# find out how wide the largest label is
$width =
( 2 * $self->{'text_space'} ) +
( $self->{'max_legend_label'} * $w ) +
$self->{'legend_example_size'} +
( 2 * $self->{'legend_space'} );
# get some base x-y coordinates
$x1 = $self->{'curr_x_min'};
$x2 = $self->{'curr_x_min'} + $width;
$y1 = $self->{'curr_y_min'} + $self->{'graph_border'};
$y2 =
$self->{'curr_y_min'} +
$self->{'graph_border'} +
$self->{'text_space'} +
( $self->{'num_datasets'} * ( $h + $self->{'text_space'} ) ) +
( 2 * $self->{'legend_space'} );
# box the legend off
$self->{'gd_obj'}->rectangle( $x1, $y1, $x2, $y2, $misccolor );
# leave that nice space inside the legend box
$x1 += $self->{'legend_space'};
$y1 += $self->{'legend_space'} + $self->{'text_space'};
# now draw the actual legend
for ( 0 .. $#labels )
{
# get the color
$color = $colors{$_};
# find the max_legend_example
$max_legend_example = $self->{'legend_space'} + $h;
# find the x-y coords
$x2 = $x1;
$x3 = $x2 + $self->{'legend_example_size'};
$y2 = $y1 + ( $_ * ( $self->{'text_space'} + $h ) ) + $h / 2;
# draw the example line if legend_example_height==1 or ==0
if ( $self->{ 'legend_example_height' . $_ } < $max_legend_example )
{
$yh = $self->{ 'legend_example_height' . $_ };
}
else
{
$yh = $max_legend_example;
}
if ( $yh <= 1 )
{
$self->{'gd_obj'}->line( $x2, $y2, $x3, $y2, $color );
}
else
{
# draw the example bar if legend_example_height > 1
$yh = int( $yh / 2 );
$self->{'gd_obj'}->filledRectangle( $x2, $y2 - $yh, $x3, $y2 + $yh, $color );
}
# now the label
$x2 = $x3 + ( 2 * $self->{'text_space'} );
$y2 -= $h / 2;
$self->{'gd_obj'}->string( $font, $x2, $y2, $labels[$_], $color );
}
# mark off the used space
$self->{'curr_x_min'} += $width;
# and return
return 1;
}
## @fn private int _draw_bottom_legend()
# put the legend on the bottom of the chart
#
# Overwrite the base class _draw_bottom_legend
#
# @return status
sub _draw_bottom_legend
{
my $self = shift;
my @labels = @{ $self->{'legend_labels'} };
my ( $x1, $y1, $x2, $y2, $empty_width, $max_label_width, $cols, $rows, $color );
my ( $col_width, $row_height, $i, $j, $r, $c, $index, $x, $y, $sub, $w, $h );
my ( $yh, $yi ); # for boxing legend
my $font = $self->{'legend_font'};
my ( %colors, @datasets );
my $max_legend_example = 0;
$yh = 0;
# copy the current boundaries and colors into the sub-objects
$self->_sub_update;
# init the legend example height
$self->_legend_example_height_init;
# # modify the dataset color table entries to avoid duplicating
# # dataset colors (this limits the number of possible data sets
# # for each component to 8)
# for (0..7) {
# $self->{'sub_1'}{'color_table'}{'dataset'.$_}
# = $self->{'color_table'}{'dataset'.($_+8)};
# }
# modify the dataset color table entries to avoid duplicating
# dataset colors.
my ( $n0, $n1 ) = map { scalar @{ $self->{'composite_info'}[$_][1] } } 0 .. 1;
for ( 0 .. $n1 - 1 )
{
$self->{'sub_1'}{'color_table'}{ 'dataset' . $_ } = $self->{'color_table'}{ 'dataset' . ( $_ + $n0 ) };
}
@datasets = @{ $self->{'composite_info'}[0][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ($i) };
$i++;
}
@datasets = @{ $self->{'composite_info'}[1][1] };
$i = 0;
for ( 0 .. $#datasets )
{
$colors{ $datasets[$_] - 1 } = $self->{'color_table'}{ 'dataset' . ( $i + $n0 ) };
$i++;
}
# make sure we're using a real font
unless ( ( ref($font) ) eq 'GD::Font' )
{
croak "The subtitle font you specified isn\'t a GD Font object";
}
# get the size of the font
( $h, $w ) = ( $font->height, $font->width );
# figure out how many columns we can fit
$x1 =
$self->{'curr_x_min'} +
$self->{'graph_border'} +
$self->{'y_tick_label_length1'} * $self->{'tick_label_font'}->width +
$self->{'tick_len'} +
( 3 * $self->{'text_space'} );
$x2 =
$self->{'curr_x_max'} -
$self->{'graph_border'} -
$self->{'y_tick_label_length2'} * $self->{'tick_label_font'}->width -
$self->{'tick_len'} -
( 3 * $self->{'text_space'} );
if ( $self->{'y_label'} )
{
$x1 += $self->{'label_font'}->height + 2 * $self->{'text_space'};
}
if ( $self->{'y_label2'} )
{
$x2 -= $self->{'label_font'}->height + 2 * $self->{'text_space'};
}
$empty_width = $x2 - $x1 - ( 2 * $self->{'legend_space'} );
$max_label_width =
$self->{'max_legend_label'} * $self->{'legend_font'}->width + 4 * $self->{'text_space'} + $self->{'legend_example_size'};
$cols = int( $empty_width / $max_label_width );
unless ($cols)
{
$cols = 1;
}
$col_width = $empty_width / $cols;
# figure out how many rows we need
$rows = int( $self->{'num_datasets'} / $cols );
unless ( ( $self->{'num_datasets'} % $cols ) == 0 )
{
$rows++;
}
unless ($rows)
{
$rows = 1;
}
$row_height = $h + $self->{'text_space'};
# box it off
$y1 = $self->{'curr_y_max'} - $self->{'text_space'} - ( $rows * $row_height ) - ( 2 * $self->{'legend_space'} );
$y2 = $self->{'curr_y_max'};
$self->{'gd_obj'}->rectangle( $x1, $y1, $x2, $y2, $self->_color_role_to_index('misc') );
# get the max_legend_example_height
$max_legend_example = $y2 - $y1;
$x1 += $self->{'legend_space'} + $self->{'text_space'};
$x2 -= $self->{'legend_space'};
$y1 += $self->{'legend_space'} + $self->{'text_space'};
$y2 -= $self->{'legend_space'} + $self->{'text_space'};
# draw in the actual legend
$r = 0;
$c = 0;
$yi = 0; # current dataset
for $i ( 0 .. 1 )
{
for $j ( 0 .. $#{ $self->{'component_datasets'}[$i] } )
{
$color = $self->{ 'sub_' . $i }->{'color_table'}{ 'dataset' . $j };
$index = $self->{'component_datasets'}[$i][$j] - 1;
$x = $x1 + ( $col_width * $c );
$y = $y1 + ( $row_height * $r ) + $h / 2;
# draw the example line if legend_example_height==1 or ==0
if ( $rows == 1 )
{
if ( $self->{ 'legend_example_height' . $yi } < $max_legend_example )
{
$yh = $self->{ 'legend_example_height' . $yi };
}
else
{
$yh = $max_legend_example;
}
}
else
{
if ( $self->{ 'legend_example_height' . $yi } < $row_height )
{
$yh = $self->{ 'legend_example_height' . $yi };
}
else
{
$yh = $row_height;
}
}
$yi++;
if ( $yh <= 1 )
{
$self->{'gd_obj'}->line( $x, $y, $x + $self->{'legend_example_size'}, $y, $color );
}
else
{
# draw the example bar if legend_example_height > 1
$yh = int( $yh / 2 );
$self->{'gd_obj'}->filledRectangle( $x, $y - $yh, $x + $self->{'legend_example_size'}, $y + $yh, $color );
}
$x += $self->{'legend_example_size'} + 2 * $self->{'text_space'};
$y -= $h / 2;
$self->{'gd_obj'}->string( $font, $x, $y, $labels[$index], $color );
# keep track of which row/column we're using
$r = ( $r + 1 ) % $rows;
if ( $r == 0 )
{
$c++;
}
}
}
# mark of the space used
$self->{'curr_y_max'} -= ( $rows * $row_height ) + 2 * $self->{'text_space'} + 2 * $self->{'legend_space'};
return;
}
## @fn private int _draw_none_legend()
# no legend to draw.. just update the color tables for subs
#
# This routine overwrites this function of the Base class
#
# @return status
sub _draw_none_legend
{
my $self = shift;
my $status = 1;
$self->_sub_update();
# for (0..7) {
# $self->{'sub_1'}{'color_table'}{'dataset'.$_}
# = $self->{'color_table'}{'dataset'.($_+8)};
# }
# modify the dataset color table entries to avoid duplicating
# dataset colors.
my ( $n0, $n1 ) = map { scalar @{ $self->{'composite_info'}[$_][1] } } 0 .. 1;
for ( 0 .. $n1 - 1 )
{
$self->{'sub_1'}{'color_table'}{ 'dataset' . $_ } = $self->{'color_table'}{ 'dataset' . ( $_ + $n0 ) };
}
return $status;
}
## @fn private int _draw_ticks()
# draw the ticks and tick labels
#
# Overwrites function _draw_ticks() of base class
#
# @return status
sub _draw_ticks
{
my $self = shift;
#draw the x ticks again
if ( $self->true( $self->{'xy_plot'} ) )
{
$self->_find_x_scale;
# The following statement is necessary as the
# _draw_x_number_ticks() located in Base.pm does nothing know
# about different y_tick_label_length variables!
# This is a hack here
$self->{'y_tick_label_length'} = $self->{'y_tick_label_length1'};
$self->_draw_x_number_ticks;
}
else
{
$self->_draw_x_ticks;
}
# update the boundaries in the sub-objects
$self->_boundary_update( $self, $self->{'sub_0'} );
$self->_boundary_update( $self, $self->{'sub_1'} );
# now the y ticks
$self->_draw_y_ticks;
# then return
return;
}
## @fn private int _draw_x_ticks()
lib/Chart/Composite.pm view on Meta::CPAN
#
# Only for Chart::Composite
sub _sub_update
{
my $self = shift;
my $sub0 = $self->{'sub_0'};
my $sub1 = $self->{'sub_1'};
# update the boundaries
$self->_boundary_update( $self, $sub0 );
$self->_boundary_update( $self, $sub1 );
# copy the color tables
$sub0->{'color_table'} = { %{ $self->{'color_table'} } };
$sub1->{'color_table'} = { %{ $self->{'color_table'} } };
# now return
return;
}
## @fn private _boundary_update()
# copy the current gd_obj boundaries from one object to another
#
# Only for Chart::Composite
sub _boundary_update
{
my $self = shift;
my $from = shift;
my $to = shift;
$to->{'curr_x_min'} = $from->{'curr_x_min'};
$to->{'curr_x_max'} = $from->{'curr_x_max'};
$to->{'curr_y_min'} = $from->{'curr_y_min'};
$to->{'curr_y_max'} = $from->{'curr_y_max'};
return;
}
## @fn private int _draw_y_grid_lines()
# draw grid_lines for y
#
# Overwrites this function of Base
sub _draw_y_grid_lines
{
my ($self) = shift;
$self->{'sub_0'}->_draw_y_grid_lines();
return;
}
## @fn private int _draw_y2_grid_lines()
# draw grid_lines for y
#
# Overwrites this function of Base
sub _draw_y2_grid_lines
{
my ($self) = shift;
$self->{'sub_1'}->_draw_y2_grid_lines();
return;
}
## @fn private _legend_example_height_values
# init the legend_example_height_values
#
sub _legend_example_height_init
{
my $self = shift;
my $a = $self->{'num_datasets'};
my ( $b, $e ) = ( 0, 0 );
my $bis = '..';
if ( $self->false( $self->{'legend_example_height'} ) )
{
for my $i ( 0 .. $a )
{
$self->{ 'legend_example_height' . $i } = 1;
}
}
if ( $self->true( $self->{'legend_example_height'} ) )
{
for my $i ( 0 .. $a )
{
if ( defined( $self->{ 'legend_example_height' . $i } ) ) { }
else
{
( $self->{ 'legend_example_height' . $i } ) = 1;
}
}
for $b ( 0 .. $a )
{
for $e ( 0 .. $a )
{
my $anh = sprintf( $b . $bis . $e );
if ( defined( $self->{ 'legend_example_height' . $anh } ) )
{
if ( $b > $e )
{
croak "Please reverse the datasetnumber in legend_example_height\n";
}
for ( my $n = $b ; $n <= $e ; $n++ )
{
$self->{ 'legend_example_height' . $n } = $self->{ 'legend_example_height' . $anh };
}
}
}
}
}
}
## be a good module and return 1
1;
( run in 0.934 second using v1.01-cache-2.11-cpan-5837b0d9d2c )