1###############################################################################
2#
3# Tests the output of Excel::Writer::XLSX against Excel generated files.
4#
5# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
6#
7
8use lib 't/lib';
9use TestFunctions qw(_compare_xlsx_files _is_deep_diff);
10use strict;
11use warnings;
12
13use Test::More tests => 1;
14
15###############################################################################
16#
17# Tests setup.
18#
19my $filename     = 'chart_format31.xlsx';
20my $dir          = 't/regression/';
21my $got_filename = $dir . "ewx_$filename";
22my $exp_filename = $dir . 'xlsx_files/' . $filename;
23
24my $ignore_members  = [];
25
26my $ignore_elements = {};
27
28
29###############################################################################
30#
31# Test the creation of an Excel::Writer::XLSX file with chart formatting.
32#
33use Excel::Writer::XLSX;
34
35my $workbook  = Excel::Writer::XLSX->new( $got_filename );
36my $worksheet = $workbook->add_worksheet();
37my $chart     = $workbook->add_chart( type => 'line', embedded => 1 );
38
39# For testing, copy the randomly generated axis ids in the target xlsx file.
40$chart->{_axis_ids} = [ 115443200, 115459200 ];
41
42my $data = [
43    [ 1, 2, 3, 4,  5 ],
44    [ 2, 4, 6, 8,  10 ],
45    [ 3, 6, 9, 12, 15 ],
46
47];
48
49$worksheet->write( 'A1', $data );
50
51$chart->add_series(
52    categories => '=Sheet1!$A$1:$A$5',
53    values     => '=Sheet1!$B$1:$B$5',
54    trendline  => {
55        type              => 'polynomial',
56        name              => 'My trend name',
57        order             => 2,
58        forward           => 0.5,
59        backward          => 0.5,
60        intercept         => 1.5,
61        display_equation  => 1,
62        display_r_squared => 1,
63        line              => {
64            color     => 'red',
65            width     => 1,
66            dash_type => 'long_dash',
67        }
68    },
69);
70
71$chart->add_series(
72    categories => '=Sheet1!$A$1:$A$5',
73    values     => '=Sheet1!$C$1:$C$5',
74);
75
76$worksheet->insert_chart( 'E9', $chart );
77
78$workbook->close();
79
80
81###############################################################################
82#
83# Compare the generated and existing Excel files.
84#
85
86my ( $got, $expected, $caption ) = _compare_xlsx_files(
87
88    $got_filename,
89    $exp_filename,
90    $ignore_members,
91    $ignore_elements,
92);
93
94_is_deep_diff( $got, $expected, $caption );
95
96
97###############################################################################
98#
99# Cleanup.
100#
101unlink $got_filename;
102
103__END__
104
105
106
107