MAJOR=4
MINOR=32
DEVNAME=tty32
 ?÷     # charts composed of several types

use v5.12;

package Chart::Composite;
our @ISA     = qw(Chart::Base);
our $VERSION = 'v2.403.9';

use Chart::Base;
use GD;
use Carp;

#>>>>>>>>>>>>>>>>>>>>>>>>>>#
#  public methods go here  #
#<<<<<<<<<<<<<<<<<<<<<<<<<<#

## @method int set(%opts)
# @param[in] %opts Hash of options to the Chart
# @return ok or croak
#
# @brief
# Set all options
#
# @details
# Overwrite the set function of class Base to pass
# options to the sub-objects later
sub set
{
    my $self = shift;
    my %opts = @_;

    # basic error checking on the options, just warn 'em
    unless ( $#_ % 2 )
    {
        carp "Whoops, some option to be set didn't have a value.\n", "You might want to look at that.\n";
    }

    # store the options they gave us
    unless ( $self->{'opts'} )
    {
        $self->{'opts'} = {};
    }

    # now set 'em
    for ( keys %opts )
    {
        $self->{$_} = $opts{$_};
        $self->{'opts'}{$_} = $opts{$_};
    }

    # now return
    return;
}

## @fn imagemap_dump()
# @brief
# Overwrite function imagemap_dump of base class
#
# @details
# Get the information to turn the chart into an imagemap
# had to override it to reassemble the \@data array correctly
#
# @return Reference to an array of the image
sub imagemap_dump {
    my $self = shift;
    my ( $i, $j );
    my @map;
    my $dataset_count = 0;

    # croak if they didn't ask me to remember the data, or if they're asking
    # for the data before I generate it
    unless ( ( $self->true( $self->{'imagemap'} ) ) && $self->{'imagemap_data'} )
    {
        croak "You need to set the imagemap option to true, and then call the png method, before you can get the imagemap data";
    }

    #make a copy of the imagemap data
    #this is the data of the first component
    for $i ( 1 .. $#{ $self->{'sub_0'}->{'imagemap_data'} } )
    {
        for $j ( 0 .. $#{ $self->{'sub_0'}->{'imagemap_data'}->[$i] } )
        {
            $map[$i][$j] = \@{ $self->{'sub_0'}->{'imagemap_data'}->[$i][$j] };
        }
        $dataset_count++;
    }

    #and add the data of the second component
    for $i ( 1 .. $#{ $self->{'sub_1'}->{'imagemap_data'} } )
    {
        for $j ( 0 .. $#{ $self->{'sub_1'}->{'imagemap_data'}->[$i] } )
        {
            $map[ $i + $dataset_count ][$j] = \@{ $self->{'sub_1'}->{'imagemap_data'}->[$i][$j] };
        }
    }

    # return their copy
    return \@map;

}

# private routine
sub __print_array
{
    my @a = @_;
    my $i;

    my $li = $#a;

    $li++;
    print STDERR "Anzahl der Elemente = $li\n";
    $li--;

    for ( $i = 0 ; $i <= $li ; $i++ )
    {
        print STDERR "\t$i\t$a[$i]\n";
    }
}

#>>>>>>>>>>>>>>>>>>>>>>>>>>>#
#  private methods go here  #
#<<<<<<<<<<<<<<<<<<<<<<<<<<<#

## @fn private int _check_data
# Overwrite _check_data of Chart::Base and check the internal data to be displayed.
#
# Make sure the data isn't really weird
#  and collect some basic info about it\n
# @return status of check
sub _check_data
{
    my $self   = shift;
    my $length = 0;

    # first things first, make sure we got the composite_info
    unless ( ( $self->{'composite_info'} ) && ( $#{ $self->{'composite_info'} } == 1 ) )
    {
        croak "Chart::Composite needs to be told what kind of components to use";
    }

    # make sure we don't end up dividing by zero if they ask for
    # just one y_tick
    if ( $self->{'y_ticks'} == 1 )
    {
        $self->{'y_ticks'} = 2;
        carp "The number of y_ticks displayed must be at least 2";
    }

    # remember the number of datasets
    $self->{'num_datasets'} = $#{ $self->{'dataref'} };

    # remember the number of points in the largest dataset
    $self->{'num_datapoints'} = 0;
    for ( 0 .. $self->{'num_datasets'} )
    {
        if ( scalar( @{ $self->{'dataref'}[$_] } ) > $self->{'num_datapoints'} )
        {
            $self->{'num_datapoints'} = scalar( @{ $self->{'dataref'}[$_] } );
        }
    }

    # find the longest x-tick label, and remember how long it is
    for ( @{ $self->{'dataref'}[0] } )
 