1###############################################################################
2#
3# Tests for Excel::Writer::XLSX::Chart methods.
4#
5# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
6#
7
8use lib 't/lib';
9use TestFunctions qw(_new_object _is_deep_diff);
10use strict;
11use warnings;
12use Excel::Writer::XLSX::Chart;
13
14use Test::More tests => 5;
15
16
17###############################################################################
18#
19# Tests setup.
20#
21my $expected;
22my $got;
23my $caption;
24my $chart;
25
26
27###############################################################################
28#
29# Test the add_series() method.
30#
31$caption  = " \tChart: add_series()";
32$expected = {
33    _categories    => undef,
34    _values        => '=Sheet1!$A$1:$A$5',
35    _name          => undef,
36    _name_formula  => undef,
37    _name_id       => undef,
38    _cat_data_id   => undef,
39    _val_data_id   => 0,
40    _line          => { _defined => 0 },
41    _fill          => { _defined => 0 },
42    _pattern       => undef,
43    _gradient      => undef,
44    _marker        => undef,
45    _trendline     => undef,
46    _smooth        => undef,
47    _error_bars    => { _x_error_bars => undef, _y_error_bars => undef },
48    _points        => undef,
49    _labels        => undef,
50    _invert_if_neg => undef,
51    _x2_axis       => undef,
52    _y2_axis       => undef,
53};
54
55$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
56
57$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
58
59$got = $chart->{_series}->[0];
60
61_is_deep_diff( $got, $expected, $caption );
62
63
64###############################################################################
65#
66# Test the add_series() method.
67#
68$caption  = " \tChart: add_series()";
69$expected = [
70    {
71        _categories    => '=Sheet1!$A$1:$A$5',
72        _values        => '=Sheet1!$B$1:$B$5',
73        _name          => 'Text',
74        _name_formula  => undef,
75        _name_id       => undef,
76        _cat_data_id   => 0,
77        _val_data_id   => 1,
78        _line          => { _defined => 0 },
79        _fill          => { _defined => 0 },
80        _gradient      => undef,
81        _pattern       => undef,
82        _marker        => undef,
83        _trendline     => undef,
84        _smooth        => undef,
85        _error_bars    => { _x_error_bars => undef, _y_error_bars => undef },
86        _points        => undef,
87        _labels        => undef,
88        _invert_if_neg => undef,
89        _x2_axis       => undef,
90        _y2_axis       => undef,
91    }
92];
93
94$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
95
96$chart->add_series(
97    categories => '=Sheet1!$A$1:$A$5',
98    values     => '=Sheet1!$B$1:$B$5',
99    name       => 'Text'
100);
101
102$got = $chart->{_series};
103
104_is_deep_diff( $got, $expected, $caption );
105
106
107###############################################################################
108#
109# Test the add_series() method.
110#
111$caption  = " \tChart: add_series()";
112$expected = [
113    {
114        _categories    => undef,
115        _values        => '=Sheet1!$A$1:$A$5',
116        _name          => undef,
117        _name_formula  => undef,
118        _name_id       => undef,
119        _cat_data_id   => undef,
120        _val_data_id   => 0,
121        _line          => { _defined => 0 },
122        _fill          => { _defined => 0 },
123        _gradient      => undef,
124        _pattern       => undef,
125        _marker        => undef,
126        _trendline     => undef,
127        _smooth        => undef,
128        _error_bars    => { _x_error_bars => undef, _y_error_bars => undef },
129        _points        => undef,
130        _labels        => undef,
131        _invert_if_neg => undef,
132        _x2_axis       => undef,
133        _y2_axis       => undef,
134    }
135];
136
137$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
138
139$chart->add_series( values => [ 'Sheet1', 0, 4, 0, 0 ] );
140
141$got = $chart->{_series};
142
143_is_deep_diff( $got, $expected, $caption );
144
145
146###############################################################################
147#
148# Test the add_series() method.
149#
150$caption  = " \tChart: add_series()";
151$expected = {
152    _categories    => '=Sheet1!$A$1:$A$5',
153    _values        => '=Sheet1!$B$1:$B$5',
154    _name          => 'Text',
155    _name_formula  => undef,
156    _name_id       => undef,
157    _cat_data_id   => 0,
158    _val_data_id   => 1,
159    _line          => { _defined => 0 },
160    _fill          => { _defined => 0 },
161    _gradient      => undef,
162    _pattern       => undef,
163    _marker        => undef,
164    _trendline     => undef,
165    _smooth        => undef,
166    _error_bars    => { _x_error_bars => undef, _y_error_bars => undef },
167    _points        => undef,
168    _labels        => undef,
169    _invert_if_neg => undef,
170    _x2_axis       => undef,
171    _y2_axis       => undef,
172};
173
174$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
175
176$chart->add_series(
177    categories => [ 'Sheet1', 0, 4, 0, 0 ],
178    values     => [ 'Sheet1', 0, 4, 1, 1 ],
179    name       => 'Text'
180);
181
182$got = $chart->{_series}->[0];
183
184_is_deep_diff( $got, $expected, $caption );
185
186
187###############################################################################
188#
189# Test the add_series() method.
190#
191$caption  = " \tChart: add_series()";
192$expected = {
193    _categories    => '=Sheet1!$A$1:$A$5',
194    _values        => '=Sheet1!$B$1:$B$5',
195    _name          => 'Text',
196    _name_formula  => undef,
197    _name_id       => undef,
198    _cat_data_id   => 0,
199    _val_data_id   => 1,
200    _line          => { _defined => 0 },
201    _fill          => { _defined => 0 },
202    _gradient      => undef,
203    _pattern       => undef,
204    _marker        => undef,
205    _trendline     => undef,
206    _smooth        => undef,
207    _error_bars    => { _x_error_bars => undef, _y_error_bars => undef },
208    _points        => undef,
209    _labels        => undef,
210    _invert_if_neg => undef,
211    _x2_axis       => 1,
212    _y2_axis       => 1,
213};
214
215$chart = _new_object( \$got, 'Excel::Writer::XLSX::Chart' );
216
217$chart->add_series(
218    categories => [ 'Sheet1', 0, 4, 0, 0 ],
219    values     => [ 'Sheet1', 0, 4, 1, 1 ],
220    name       => 'Text',
221    x2_axis    => 1,
222    y2_axis    => 1,
223);
224
225$got = $chart->{_series}->[0];
226
227_is_deep_diff( $got, $expected, $caption );
228
229
230__END__
231
232
233