Excel-Writer-XLSX

 view release on metacpan or  search on metacpan

lib/Excel/Writer/XLSX/Chart/Pie.pm  view on Meta::CPAN


    # Write the c:firstSliceAng element.
    $self->_write_first_slice_ang();

    $self->xml_end_tag( 'c:pieChart' );
}


##############################################################################
#
# _write_plot_area().
#
# Over-ridden method to remove the cat_axis() and val_axis() code since
# Pie/Doughnut charts don't require those axes.
#
# Write the <c:plotArea> element.
#
sub _write_plot_area {

    my $self = shift;
    my $second_chart = $self->{_combined};

    $self->xml_start_tag( 'c:plotArea' );

    # Write the c:layout element.
    $self->_write_layout( $self->{_plotarea}->{_layout}, 'plot' );

    # Write the subclass chart type element.
    $self->_write_chart_type();

    # Configure a combined chart if present.
    if ( $second_chart ) {

        # Secondary axis has unique id otherwise use same as primary.
        if ( $second_chart->{_is_secondary} ) {
            $second_chart->{_id} = 1000 + $self->{_id};
        }
        else {
            $second_chart->{_id} = $self->{_id};
        }

        # Shart the same filehandle for writing.
        $second_chart->{_fh} = $self->{_fh};

        # Share series index with primary chart.
        $second_chart->{_series_index} = $self->{_series_index};

        # Write the subclass chart type elements for combined chart.
        $second_chart->_write_chart_type();
    }

    # Write the c:spPr element for the plotarea formatting.
    $self->_write_sp_pr( $self->{_plotarea} );

    $self->xml_end_tag( 'c:plotArea' );
}


##############################################################################
#
# _write_legend().
#
# Over-ridden method to add <c:txPr> to legend.
#
# Write the <c:legend> element.
#
sub _write_legend {

    my $self          = shift;
    my $legend        = $self->{_legend};
    my $position      = $legend->{_position} || 'right';
    my $font          = $legend->{_font};
    my @delete_series = ();
    my $overlay       = 0;

    if ( defined $legend->{_delete_series}
        && ref $legend->{_delete_series} eq 'ARRAY' )
    {
        @delete_series = @{ $legend->{_delete_series} };
    }

    if ( $position =~ s/^overlay_// ) {
        $overlay = 1;
    }

    my %allowed = (
        right     => 'r',
        left      => 'l',
        top       => 't',
        bottom    => 'b',
        top_right => 'tr',
    );

    return if $position eq 'none';
    return unless exists $allowed{$position};

    $position = $allowed{$position};

    $self->xml_start_tag( 'c:legend' );

    # Write the c:legendPos element.
    $self->_write_legend_pos( $position );

    # Remove series labels from the legend.
    for my $index ( @delete_series ) {

        # Write the c:legendEntry element.
        $self->_write_legend_entry( $index );
    }

    # Write the c:layout element.
    $self->_write_layout( $legend->{_layout}, 'legend' );

    # Write the c:overlay element.
    $self->_write_overlay() if $overlay;

    # Write the c:spPr element.
    $self->_write_sp_pr( $legend );

    # Write the c:txPr element. Over-ridden.
    $self->_write_tx_pr_legend( 0, $font );

    $self->xml_end_tag( 'c:legend' );
}


##############################################################################
#
# _write_tx_pr_legend()
#
# Write the <c:txPr> element for legends.
#
sub _write_tx_pr_legend {

    my $self     = shift;
    my $horiz    = shift;
    my $font     = shift;
    my $rotation = undef;

    if ( $font && exists $font->{_rotation} ) {
        $rotation = $font->{_rotation};
    }

    $self->xml_start_tag( 'c:txPr' );

    # Write the a:bodyPr element.
    $self->_write_a_body_pr( $rotation, $horiz );

    # Write the a:lstStyle element.
    $self->_write_a_lst_style();

    # Write the a:p element.
    $self->_write_a_p_legend( $font );

    $self->xml_end_tag( 'c:txPr' );
}


##############################################################################
#
# _write_a_p_legend()
#
# Write the <a:p> element for legends.
#
sub _write_a_p_legend {

    my $self = shift;
    my $font = shift;

    $self->xml_start_tag( 'a:p' );

    # Write the a:pPr element.
    $self->_write_a_p_pr_legend( $font );

    # Write the a:endParaRPr element.
    $self->_write_a_end_para_rpr();

    $self->xml_end_tag( 'a:p' );
}


##############################################################################
#
# _write_a_p_pr_legend()
#
# Write the <a:pPr> element for legends.
#
sub _write_a_p_pr_legend {

    my $self = shift;
    my $font = shift;
    my $rtl  = 0;

    my @attributes = ( 'rtl' => $rtl );

    $self->xml_start_tag( 'a:pPr', @attributes );

    # Write the a:defRPr element.
    $self->_write_a_def_rpr( $font );

    $self->xml_end_tag( 'a:pPr' );
}


##############################################################################
#
# _write_vary_colors()
#
# Write the <c:varyColors> element.
#
sub _write_vary_colors {

    my $self = shift;
    my $val  = 1;

    my @attributes = ( 'val' => $val );

    $self->xml_empty_tag( 'c:varyColors', @attributes );
}


##############################################################################
#
# _write_first_slice_ang()
#
# Write the <c:firstSliceAng> element.
#
sub _write_first_slice_ang {

    my $self = shift;
    my $val  = $self->{_rotation};

    my @attributes = ( 'val' => $val );

    $self->xml_empty_tag( 'c:firstSliceAng', @attributes );
}

1;


##############################################################################
#
# _write_show_leader_lines()
#
# Write the <c:showLeaderLines> element. This is for Pie/Doughnut charts.
# Other chart types only supported leader lines after Excel 2015 via an
# extension element.
#



( run in 0.829 second using v1.01-cache-2.11-cpan-39bf76dae61 )